SCRIPTING
WormSurf Scripting Framework ("WSX") provides a reverse-injectable scripting environment for websites which (usually out of necessity) target themselves specifically as BRTP-capable POD/PADs on the temporally agnostic internet. While the syntax will be familiar to anyone used to BCOMPILE's alterpiled constructs, some facilities are specific to WSX and indeed, to WormSurf itself.
For example, the following reverse-injection binds the parent client to itself (rather than, as is typical, binding itself to the parent client), anticipating various pitfalls inherent to WormSurf scripting in an R-2/R-compatible environment (note that in this example, invoking "callnative" in fact causes an emulator within the parent client to PODify the invocation and pass it to the overlying PAD tier, but that the effect is virtually identical to a "traditional" "callnative" call) :
LABEL "loadproc"
PROC beforeload:
DF foreignRef AS false;
PROBE {wsEvent AS trigged{false, true}}:
IF {"theavocadopapers.com" NOTIS priorhost@wsEvent}:
# we could go do the initx anyway, but we're not coming from a bloc
# we can glean{}, so there isn't much upside (except for SwalLOW
# args which we would care about only if we were trying to be
# Jove-friendly)
ESTAB foreignRef AS true
:IFEND
:PROBEEND
# NB: foreignRef can equal notfalse without being true, or nottrue
# without being false (if we get unlucky and an INTERVENE or SCORCH
# happens or if any of the interrogator threads attempt a PUMP (or
# close an UNPUMP), which is out of our control but likely to happen
# in production and not elsewhere); thus we do a straight IS check
# rather than being all cute:
IF { {foreignRef IS true} AND {TYPE{wsloc} IS "sbuffer"} }:
DF pid AS glean{"unload-buf", true, true, 0}
wsx:callnative{"initx", |wsloc, 4, 0, 0, false|}
# unglean not strictly necessary; here for clarity (x-ws-evacuate hdr
# effectively handles ungleaning):
CALL unglean{pid, true}
:IFEND
# ...else nothing; vomit-b handles glean/unglean in one atomic
# operation regardless of anything else, we're ready to jump:
CALL wsx:callnative{"pounce", 9, wsloc}
:PROCEND
CALL beforeload
RETCH
On the other hand, standard UNEVAC/UNPOUNCE calls, assuming the goal is to be complaint with all bridges, including G-types, must be handled differently...
LABEL "unloadproc"
PROC beforeunload:
IF {TYPE{wsloc} IS "sbuffer"}:
DF upid AS unglean{"unload-buf", 2000}
wsx:callnative{"unp", "Rf", upid}
ELSE:
# LOGF{"No wsloc so nothing to do here", "debug"};
:IFEND
# unevac (WS-native) resources and de-pounce:
CALL wsx:callnative{"unevac", 9, wsloc}
CALL wsx:callnative{"unpounce", false}
:PROCEND
CALL beforeunload
EVAC # Ruppert hangs otherwise...
...or else Ruppert PAD/PODding (v53.x and higher) results in an aborted RETCH.
All of which is not an issue for EXECs, which, given their simpler control flow, tend to play nice with all sub-clients (assuming P5/R certification, which for other reasons should be a given anyway):
# using LOCKB/UNLOCKB instead of a LOCK:/:LOCKEND block because the
# interceptor call to go-pnf "automatically" releases the LOCK and doesn't
# leave us deeper than we think we are or should be, which doing go-pnf
# would do from within a block for Oregano presumers (fixed as of 9.6.*,
# which doesn't really help for now).
#
# ***Please*** don't mess with this structure unless you know what you're
# doing (or ask S.S.). Control can fall all the way to the wsxcode sphere and
# for unshielded or pseudo-shielded spheres we're in a literally fatal state
# if the core sphere is also not shielded (NOT A HYPOTHETICAL: the
# Willis/R4-C fiasco is a perfect example).
DF lock
LOCKB{lock}
NEGLECT "Liam"
NEGLECTF "../*liam*"
PAVE "r3r,kerbd,bismarck" # just in case
# att/int not really needed here but without it, Zurich-style deprocessors
# pollute the logs (PDP-33028); also see note about ARG/RG impls below.
ATTEMPT:
CATALOG loadproc
CATALOG unloadproc
WAIT[200]:
# For R-flag re-parsers (race condition if static unvomit flags set, see
# PDRR-2306); all others will of course ignore this:
CATALOG loadproc;
:WAITEND
INTERCEPT:
# Annoying to have to re-implement this *basic* client functionality when
# it should be happening properly (without miles of unnecessary logging
# statements) at a much lower level; the culprit is (some) un-patched
# ARG/RG implementations (Mitosis is fine; Supper is not, nor are SlimJiM
# or pre-5.x Hoodie flavors). Use of go-pnf as opposed to go-err{404} or
# taking some non-native approach (or not att/inting at all) is discussed
# here:
# https://stackoverflow.com/questions/1292101359/go-pnf-or-go-err-404-wtf
wsx:callnative{"go-pnf", lock, "Even tried multi :( :( :("}
:ATTEMPTEND
UNLOCKB{lock} # See note above re LOCKB/UNLOCKB vs a block.
WSX is supported by a community of developers who effectively have no choice but to use it.