Step 5p6 lazy loading + Step 6b VM transpilation prep

Lazy module loading (Step 5 piece 6 completion):
- Add define-library wrappers + import declarations to 13 source .sx files
- compile-modules.js generates module-manifest.json with dependency graph
- compile-modules.js strips define-library/import before bytecode compilation
  (VM doesn't handle these as special forms)
- sx-platform.js replaces hardcoded 24-file loadWebStack() with manifest-driven
  recursive loader — only downloads modules the page needs
- Result: 12 modules loaded (was 24), zero errors, zero warnings
- Fallback to full load if manifest missing

VM transpilation prep (Step 6b):
- Refactor lib/vm.sx: 20 accessor functions replace raw dict access
- Factor out collect-n-from-stack, collect-n-pairs, pad-n-nils helpers
- bootstrap_vm.py: transpiles 9 VM logic functions to OCaml
- sx_vm_ref.ml: proof that vm.sx transpiles (preamble has stubs)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-04 12:18:41 +00:00
parent 7b4c918773
commit fc2b5e502f
59 changed files with 2739 additions and 1198 deletions

View File

@@ -1,3 +1,3 @@
(sxbc 1 "71e91d776cc0a108"
(code
:constants ("define-library" "sx" "bytecode" "export" "OP_CONST" "OP_NIL" "OP_TRUE" "OP_FALSE" "OP_POP" "OP_DUP" "OP_LOCAL_GET" "OP_LOCAL_SET" "OP_UPVALUE_GET" "OP_UPVALUE_SET" "OP_GLOBAL_GET" "OP_GLOBAL_SET" "OP_JUMP" "OP_JUMP_IF_FALSE" "OP_JUMP_IF_TRUE" "OP_CALL" "OP_TAIL_CALL" "OP_RETURN" "OP_CLOSURE" "OP_CALL_PRIM" "OP_APPLY" "OP_LIST" "OP_DICT" "OP_APPEND_BANG" "OP_ITER_INIT" "OP_ITER_NEXT" "OP_MAP_OPEN" "OP_MAP_APPEND" "OP_MAP_CLOSE" "OP_FILTER_TEST" "OP_HO_MAP" "OP_HO_FILTER" "OP_HO_REDUCE" "OP_HO_FOR_EACH" "OP_HO_SOME" "OP_HO_EVERY" "OP_SCOPE_PUSH" "OP_SCOPE_POP" "OP_PROVIDE_PUSH" "OP_PROVIDE_POP" "OP_CONTEXT" "OP_EMIT" "OP_EMITTED" "OP_RESET" "OP_SHIFT" "OP_DEFINE" "OP_DEFCOMP" "OP_DEFISLAND" "OP_DEFMACRO" "OP_EXPAND_MACRO" "OP_STR_CONCAT" "OP_STR_JOIN" "OP_SERIALIZE" "OP_ADD" "OP_SUB" "OP_MUL" "OP_DIV" "OP_EQ" "OP_LT" "OP_GT" "OP_NOT" "OP_LEN" "OP_FIRST" "OP_REST" "OP_NTH" "OP_CONS" "OP_NEG" "OP_INC" "OP_DEC" "OP_ASER_TAG" "OP_ASER_FRAG" "BYTECODE_MAGIC" "BYTECODE_VERSION" "CONST_NUMBER" "CONST_STRING" "CONST_BOOL" "CONST_NIL" "CONST_SYMBOL" "CONST_KEYWORD" "CONST_LIST" "CONST_DICT" "CONST_CODE" "opcode-name" 1 2 3 4 5 6 16 17 18 19 20 21 32 33 34 48 49 50 51 52 53 64 65 66 80 81 82 83 84 85 88 89 90 91 92 93 96 97 98 99 100 101 102 112 113 128 129 130 131 132 144 145 146 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 224 225 "SXBC" 7 8 9 {:upvalue-count 0 :arity 1 :constants ("=" 1 "CONST" 2 "NIL" 3 "TRUE" 4 "FALSE" 5 "POP" 6 "DUP" 16 "LOCAL_GET" 17 "LOCAL_SET" 20 "GLOBAL_GET" 21 "GLOBAL_SET" 32 "JUMP" 33 "JUMP_IF_FALSE" 48 "CALL" 49 "TAIL_CALL" 50 "RETURN" 52 "CALL_PRIM" 128 "DEFINE" 144 "STR_CONCAT" "str" "OP_") :bytecode (16 0 1 1 0 52 0 0 2 33 6 0 1 2 0 32 59 1 16 0 1 3 0 52 0 0 2 33 6 0 1 4 0 32 41 1 16 0 1 5 0 52 0 0 2 33 6 0 1 6 0 32 23 1 16 0 1 7 0 52 0 0 2 33 6 0 1 8 0 32 5 1 16 0 1 9 0 52 0 0 2 33 6 0 1 10 0 32 243 0 16 0 1 11 0 52 0 0 2 33 6 0 1 12 0 32 225 0 16 0 1 13 0 52 0 0 2 33 6 0 1 14 0 32 207 0 16 0 1 15 0 52 0 0 2 33 6 0 1 16 0 32 189 0 16 0 1 17 0 52 0 0 2 33 6 0 1 18 0 32 171 0 16 0 1 19 0 52 0 0 2 33 6 0 1 20 0 32 153 0 16 0 1 21 0 52 0 0 2 33 6 0 1 22 0 32 135 0 16 0 1 23 0 52 0 0 2 33 6 0 1 24 0 32 117 0 16 0 1 25 0 52 0 0 2 33 6 0 1 26 0 32 99 0 16 0 1 27 0 52 0 0 2 33 6 0 1 28 0 32 81 0 16 0 1 29 0 52 0 0 2 33 6 0 1 30 0 32 63 0 16 0 1 31 0 52 0 0 2 33 6 0 1 32 0 32 45 0 16 0 1 33 0 52 0 0 2 33 6 0 1 34 0 32 27 0 16 0 1 35 0 52 0 0 2 33 6 0 1 36 0 32 9 0 1 38 0 16 0 52 37 0 2 50)} "import") :bytecode (20 0 0 20 1 0 20 2 0 48 1 20 3 0 20 4 0 20 5 0 20 6 0 20 7 0 20 8 0 20 9 0 20 10 0 20 11 0 20 12 0 20 13 0 20 14 0 20 15 0 20 16 0 20 17 0 20 18 0 20 19 0 20 20 0 20 21 0 20 22 0 20 23 0 20 24 0 20 25 0 20 26 0 20 27 0 20 28 0 20 29 0 20 30 0 20 31 0 20 32 0 20 33 0 20 34 0 20 35 0 20 36 0 20 37 0 20 38 0 20 39 0 20 40 0 20 41 0 20 42 0 20 43 0 20 44 0 20 45 0 20 46 0 20 47 0 20 48 0 20 49 0 20 50 0 20 51 0 20 52 0 20 53 0 20 54 0 20 55 0 20 56 0 20 57 0 20 58 0 20 59 0 20 60 0 20 61 0 20 62 0 20 63 0 20 64 0 20 65 0 20 66 0 20 67 0 20 68 0 20 69 0 20 70 0 20 71 0 20 72 0 20 73 0 20 74 0 20 75 0 20 76 0 20 77 0 20 78 0 20 79 0 20 80 0 20 81 0 20 82 0 20 83 0 20 84 0 20 85 0 20 86 0 48 83 1 87 0 128 4 0 5 1 88 0 128 5 0 5 1 89 0 128 6 0 5 1 90 0 128 7 0 5 1 91 0 128 8 0 5 1 92 0 128 9 0 5 1 93 0 128 10 0 5 1 94 0 128 11 0 5 1 95 0 128 12 0 5 1 96 0 128 13 0 5 1 97 0 128 14 0 5 1 98 0 128 15 0 5 1 99 0 128 16 0 5 1 100 0 128 17 0 5 1 101 0 128 18 0 5 1 102 0 128 19 0 5 1 103 0 128 20 0 5 1 104 0 128 21 0 5 1 105 0 128 22 0 5 1 106 0 128 23 0 5 1 107 0 128 24 0 5 1 108 0 128 25 0 5 1 109 0 128 26 0 5 1 110 0 128 27 0 5 1 111 0 128 28 0 5 1 112 0 128 29 0 5 1 113 0 128 30 0 5 1 114 0 128 31 0 5 1 115 0 128 32 0 5 1 116 0 128 33 0 5 1 117 0 128 34 0 5 1 118 0 128 35 0 5 1 119 0 128 36 0 5 1 120 0 128 37 0 5 1 121 0 128 38 0 5 1 122 0 128 39 0 5 1 123 0 128 40 0 5 1 124 0 128 41 0 5 1 125 0 128 42 0 5 1 126 0 128 43 0 5 1 127 0 128 44 0 5 1 128 0 128 45 0 5 1 129 0 128 46 0 5 1 130 0 128 47 0 5 1 131 0 128 48 0 5 1 132 0 128 49 0 5 1 133 0 128 50 0 5 1 134 0 128 51 0 5 1 135 0 128 52 0 5 1 136 0 128 53 0 5 1 137 0 128 54 0 5 1 138 0 128 55 0 5 1 139 0 128 56 0 5 1 140 0 128 57 0 5 1 141 0 128 58 0 5 1 142 0 128 59 0 5 1 143 0 128 60 0 5 1 144 0 128 61 0 5 1 145 0 128 62 0 5 1 146 0 128 63 0 5 1 147 0 128 64 0 5 1 148 0 128 65 0 5 1 149 0 128 66 0 5 1 150 0 128 67 0 5 1 151 0 128 68 0 5 1 152 0 128 69 0 5 1 153 0 128 70 0 5 1 154 0 128 71 0 5 1 155 0 128 72 0 5 1 156 0 128 73 0 5 1 157 0 128 74 0 5 1 158 0 128 75 0 5 1 87 0 128 76 0 5 1 87 0 128 77 0 5 1 88 0 128 78 0 5 1 89 0 128 79 0 5 1 90 0 128 80 0 5 1 91 0 128 81 0 5 1 92 0 128 82 0 5 1 159 0 128 83 0 5 1 160 0 128 84 0 5 1 161 0 128 85 0 5 51 162 0 128 86 0 48 3 5 20 163 0 20 1 0 20 2 0 48 1 48 1 50)))
:constants ("OP_CONST" 1 "OP_NIL" 2 "OP_TRUE" 3 "OP_FALSE" 4 "OP_POP" 5 "OP_DUP" 6 "OP_LOCAL_GET" 16 "OP_LOCAL_SET" 17 "OP_UPVALUE_GET" 18 "OP_UPVALUE_SET" 19 "OP_GLOBAL_GET" 20 "OP_GLOBAL_SET" 21 "OP_JUMP" 32 "OP_JUMP_IF_FALSE" 33 "OP_JUMP_IF_TRUE" 34 "OP_CALL" 48 "OP_TAIL_CALL" 49 "OP_RETURN" 50 "OP_CLOSURE" 51 "OP_CALL_PRIM" 52 "OP_APPLY" 53 "OP_LIST" 64 "OP_DICT" 65 "OP_APPEND_BANG" 66 "OP_ITER_INIT" 80 "OP_ITER_NEXT" 81 "OP_MAP_OPEN" 82 "OP_MAP_APPEND" 83 "OP_MAP_CLOSE" 84 "OP_FILTER_TEST" 85 "OP_HO_MAP" 88 "OP_HO_FILTER" 89 "OP_HO_REDUCE" 90 "OP_HO_FOR_EACH" 91 "OP_HO_SOME" 92 "OP_HO_EVERY" 93 "OP_SCOPE_PUSH" 96 "OP_SCOPE_POP" 97 "OP_PROVIDE_PUSH" 98 "OP_PROVIDE_POP" 99 "OP_CONTEXT" 100 "OP_EMIT" 101 "OP_EMITTED" 102 "OP_RESET" 112 "OP_SHIFT" 113 "OP_DEFINE" 128 "OP_DEFCOMP" 129 "OP_DEFISLAND" 130 "OP_DEFMACRO" 131 "OP_EXPAND_MACRO" 132 "OP_STR_CONCAT" 144 "OP_STR_JOIN" 145 "OP_SERIALIZE" 146 "OP_ADD" 160 "OP_SUB" 161 "OP_MUL" 162 "OP_DIV" 163 "OP_EQ" 164 "OP_LT" 165 "OP_GT" 166 "OP_NOT" 167 "OP_LEN" 168 "OP_FIRST" 169 "OP_REST" 170 "OP_NTH" 171 "OP_CONS" 172 "OP_NEG" 173 "OP_INC" 174 "OP_DEC" 175 "OP_ASER_TAG" 224 "OP_ASER_FRAG" 225 "BYTECODE_MAGIC" "SXBC" "BYTECODE_VERSION" "CONST_NUMBER" "CONST_STRING" "CONST_BOOL" "CONST_NIL" "CONST_SYMBOL" "CONST_KEYWORD" "CONST_LIST" 7 "CONST_DICT" 8 "CONST_CODE" 9 "opcode-name" {:upvalue-count 0 :arity 1 :constants ("=" 1 "CONST" 2 "NIL" 3 "TRUE" 4 "FALSE" 5 "POP" 6 "DUP" 16 "LOCAL_GET" 17 "LOCAL_SET" 20 "GLOBAL_GET" 21 "GLOBAL_SET" 32 "JUMP" 33 "JUMP_IF_FALSE" 48 "CALL" 49 "TAIL_CALL" 50 "RETURN" 52 "CALL_PRIM" 128 "DEFINE" 144 "STR_CONCAT" "str" "OP_") :bytecode (16 0 1 1 0 52 0 0 2 33 6 0 1 2 0 32 59 1 16 0 1 3 0 52 0 0 2 33 6 0 1 4 0 32 41 1 16 0 1 5 0 52 0 0 2 33 6 0 1 6 0 32 23 1 16 0 1 7 0 52 0 0 2 33 6 0 1 8 0 32 5 1 16 0 1 9 0 52 0 0 2 33 6 0 1 10 0 32 243 0 16 0 1 11 0 52 0 0 2 33 6 0 1 12 0 32 225 0 16 0 1 13 0 52 0 0 2 33 6 0 1 14 0 32 207 0 16 0 1 15 0 52 0 0 2 33 6 0 1 16 0 32 189 0 16 0 1 17 0 52 0 0 2 33 6 0 1 18 0 32 171 0 16 0 1 19 0 52 0 0 2 33 6 0 1 20 0 32 153 0 16 0 1 21 0 52 0 0 2 33 6 0 1 22 0 32 135 0 16 0 1 23 0 52 0 0 2 33 6 0 1 24 0 32 117 0 16 0 1 25 0 52 0 0 2 33 6 0 1 26 0 32 99 0 16 0 1 27 0 52 0 0 2 33 6 0 1 28 0 32 81 0 16 0 1 29 0 52 0 0 2 33 6 0 1 30 0 32 63 0 16 0 1 31 0 52 0 0 2 33 6 0 1 32 0 32 45 0 16 0 1 33 0 52 0 0 2 33 6 0 1 34 0 32 27 0 16 0 1 35 0 52 0 0 2 33 6 0 1 36 0 32 9 0 1 38 0 16 0 52 37 0 2 50)}) :bytecode (1 1 0 128 0 0 5 1 3 0 128 2 0 5 1 5 0 128 4 0 5 1 7 0 128 6 0 5 1 9 0 128 8 0 5 1 11 0 128 10 0 5 1 13 0 128 12 0 5 1 15 0 128 14 0 5 1 17 0 128 16 0 5 1 19 0 128 18 0 5 1 21 0 128 20 0 5 1 23 0 128 22 0 5 1 25 0 128 24 0 5 1 27 0 128 26 0 5 1 29 0 128 28 0 5 1 31 0 128 30 0 5 1 33 0 128 32 0 5 1 35 0 128 34 0 5 1 37 0 128 36 0 5 1 39 0 128 38 0 5 1 41 0 128 40 0 5 1 43 0 128 42 0 5 1 45 0 128 44 0 5 1 47 0 128 46 0 5 1 49 0 128 48 0 5 1 51 0 128 50 0 5 1 53 0 128 52 0 5 1 55 0 128 54 0 5 1 57 0 128 56 0 5 1 59 0 128 58 0 5 1 61 0 128 60 0 5 1 63 0 128 62 0 5 1 65 0 128 64 0 5 1 67 0 128 66 0 5 1 69 0 128 68 0 5 1 71 0 128 70 0 5 1 73 0 128 72 0 5 1 75 0 128 74 0 5 1 77 0 128 76 0 5 1 79 0 128 78 0 5 1 81 0 128 80 0 5 1 83 0 128 82 0 5 1 85 0 128 84 0 5 1 87 0 128 86 0 5 1 89 0 128 88 0 5 1 91 0 128 90 0 5 1 93 0 128 92 0 5 1 95 0 128 94 0 5 1 97 0 128 96 0 5 1 99 0 128 98 0 5 1 101 0 128 100 0 5 1 103 0 128 102 0 5 1 105 0 128 104 0 5 1 107 0 128 106 0 5 1 109 0 128 108 0 5 1 111 0 128 110 0 5 1 113 0 128 112 0 5 1 115 0 128 114 0 5 1 117 0 128 116 0 5 1 119 0 128 118 0 5 1 121 0 128 120 0 5 1 123 0 128 122 0 5 1 125 0 128 124 0 5 1 127 0 128 126 0 5 1 129 0 128 128 0 5 1 131 0 128 130 0 5 1 133 0 128 132 0 5 1 135 0 128 134 0 5 1 137 0 128 136 0 5 1 139 0 128 138 0 5 1 141 0 128 140 0 5 1 143 0 128 142 0 5 1 1 0 128 144 0 5 1 1 0 128 145 0 5 1 3 0 128 146 0 5 1 5 0 128 147 0 5 1 7 0 128 148 0 5 1 9 0 128 149 0 5 1 11 0 128 150 0 5 1 152 0 128 151 0 5 1 154 0 128 153 0 5 1 156 0 128 155 0 5 51 158 0 128 157 0 50)))