| go | ||
| draft.txt | ||
| README.md | ||
festive: A Constrained Size Output Virtual Machine
An attempt at defining a small VM to create a stack machine for size-constrained clients and servers.
Original motivation was to create a simple templating renderer for USSD clients, combined with an agnostic data-retrieval reference that may conceal any level of complexity.
Opcodes
The VM defines the following opcode symbols:
BACK- Return to the previous execution frame (will fail if at top frame). It leaves to the state of the execution layer to define what "previous" means.CATCH <symbol> <signal>- Jump to symbol if signal is set (seesignalbelow).CROAK <signal>- Clear state and restart execution from tip if signal is set (seesignalbelow).LOAD <symbol> <size>- Execute the code symbolsymboland cache the data, constrained to the givensize.RELOAD <symbol>- Execute a code symbol already loaded byLOADand cache the data, constrained to the givensize.MAP <symbol>- Expose a code symbol previously loaded byLOAD. Roughly corresponds to theglobaldirective in Python.MOVE <symbol>- Create a new execution frame, invalidating all previousMAPcalls.
Rendering
The fixed-size output is generated using a templating language, and a combination of one or more max size properties, and an optional sink property that will attempt to consume all remaining capacity of the rendered template.
For example, in this example
maxOutputSizeis 256 bytes long.templateis 120 bytes long.- param
onehas max size 10 but uses 5. - param
twohas max size 20 but uses 12. - param
threeis a sink.
The renderer may use up to 256 - 120 - 5 - 12 = 119 bytes from the sink when rendering the output.