Download envelope/bytecode-envelope.js from Snapkitty/apple-ii-universal-machine: direct link, hf CLI and curl.
- Browser
- Download file 4.55 kB
-
https://huggingface.co/Snapkitty/apple-ii-universal-machine/resolve/main/envelope/bytecode-envelope.js
- Command line
-
hf download hf://Snapkitty/apple-ii-universal-machine/envelope/bytecode-envelope.js
-
curl -L -o bytecode-envelope.js https://huggingface.co/Snapkitty/apple-ii-universal-machine/resolve/main/envelope/bytecode-envelope.js
4.55 kB
| var BytecodeEnvelope = { | |
| compileLispToBytecode: function(lispExpr) { | |
| if (!lispExpr) return ['PUSH_UNKNOWN', 'HALT']; | |
| var tokens = lispExpr.replace(/[()]/g, ' ').trim().split(/\s+/).filter(function(t) { return t.length > 0; }); | |
| var bytecode = []; | |
| bytecode.push('PUSH_EVENT'); | |
| tokens.forEach(function(token) { | |
| var lower = token.toLowerCase(); | |
| if (lower === 'event') bytecode.push('DEFINE_EVENT'); | |
| else if (lower === 'schema') bytecode.push('DEFINE_SCHEMA'); | |
| else if (lower === 'entities') bytecode.push('LOAD_ENTITIES'); | |
| else if (lower === 'pipeline') bytecode.push('START_PIPELINE'); | |
| else if (lower === 'agent') bytecode.push('LOAD_AGENT'); | |
| else if (lower === 'trust') bytecode.push('CHECK_TRUST'); | |
| else if (lower === 'seal') bytecode.push('SEAL'); | |
| else if (lower === 'audit') bytecode.push('AUDIT_WRITE'); | |
| else if (lower === 'deploy') bytecode.push('DEPLOY'); | |
| else if (lower === 'create') bytecode.push('CREATE'); | |
| else if (lower === 'delete') bytecode.push('DELETE'); | |
| else if (lower === 'run') bytecode.push('EXECUTE'); | |
| else bytecode.push('PUSH "' + token + '"'); | |
| }); | |
| bytecode.push('VERIFY'); | |
| bytecode.push('SEAL'); | |
| bytecode.push('AUDIT_WRITE'); | |
| bytecode.push('HALT'); | |
| return bytecode; | |
| }, | |
| run: function(bytecode) { | |
| if (!bytecode || bytecode.length === 0) return { output: [], steps: 0, error: 'Empty bytecode' }; | |
| var stack = []; | |
| var output = []; | |
| var steps = 0; | |
| var maxSteps = 100; | |
| for (var i = 0; i < bytecode.length && steps < maxSteps; i++) { | |
| var op = bytecode[i]; | |
| steps++; | |
| if (op.startsWith('PUSH ')) { | |
| var val = op.substring(5).replace(/"/g, ''); | |
| stack.push(val); | |
| output.push('PUSH ' + val); | |
| } else if (op === 'DEFINE_EVENT') { | |
| output.push('DEFINE_EVENT β'); | |
| } else if (op === 'DEFINE_SCHEMA') { | |
| output.push('DEFINE_SCHEMA β'); | |
| } else if (op === 'LOAD_ENTITIES') { | |
| output.push('LOAD_ENTITIES β'); | |
| } else if (op === 'START_PIPELINE') { | |
| output.push('START_PIPELINE β'); | |
| } else if (op === 'LOAD_AGENT') { | |
| output.push('LOAD_AGENT β'); | |
| } else if (op === 'CHECK_TRUST') { | |
| output.push('CHECK_TRUST β'); | |
| } else if (op === 'SEAL') { | |
| output.push('SEAL β'); | |
| } else if (op === 'AUDIT_WRITE') { | |
| output.push('AUDIT_WRITE β'); | |
| } else if (op === 'DEPLOY') { | |
| output.push('DEPLOY β'); | |
| } else if (op === 'CREATE') { | |
| output.push('CREATE β'); | |
| } else if (op === 'DELETE') { | |
| output.push('DELETE β'); | |
| } else if (op === 'EXECUTE') { | |
| output.push('EXECUTE β'); | |
| } else if (op === 'VERIFY') { | |
| output.push('VERIFY β'); | |
| } else if (op === 'HALT') { | |
| output.push('HALT'); | |
| break; | |
| } else { | |
| output.push('OP: ' + op); | |
| } | |
| } | |
| return { | |
| output: output, | |
| steps: steps, | |
| halted: steps < maxSteps | |
| }; | |
| }, | |
| render: function(bytecode, result) { | |
| return [ | |
| 'ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ', | |
| 'β BYTECODE EXECUTION β', | |
| 'β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£', | |
| 'β PROGRAM: ' + bytecode.join(' β ').substring(0, 47).padEnd(47) + 'β', | |
| 'β STEPS: ' + String(result.steps).padEnd(47) + 'β', | |
| 'β STATUS: ' + (result.halted ? 'HALTED β' : 'MAX STEPS').padEnd(47) + 'β', | |
| 'β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£', | |
| 'β TRACE: β' | |
| ].concat(result.output.map(function(o) { return 'β ' + o.substring(0, 53).padEnd(53) + 'β'; })) | |
| .concat(['ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ']) | |
| .join('\n'); | |
| } | |
| }; | |