From b286f9dca018a77f6a3a372b2e0665e5825d02ff Mon Sep 17 00:00:00 2001 From: sfja Date: Tue, 23 Sep 2025 23:54:07 +0200 Subject: [PATCH] import files once --- compile.phi | 6 +- compiler/emit_js.phi | 71 +- compiler/syms.phi | 28 +- stage2.js | 3301 ++++++++++++++++++------------------------ stdlib.phi | 72 + 5 files changed, 1541 insertions(+), 1937 deletions(-) diff --git a/compile.phi b/compile.phi index 667ea8e..d17fe9c 100644 --- a/compile.phi +++ b/compile.phi @@ -1,6 +1,6 @@ (import "stdlib.phi" (slice contains indent)) (import "compiler/parse.phi" (Parser tokenize)) -(import "compiler/emit_js.phi" (Emitter)) +(import "compiler/emit_js.phi" (JsEmitter)) (fn print_expr (expr depth) (do (let (ty line value) expr) @@ -24,7 +24,7 @@ (let parser (Parser tokens)) (let (parse) parser) (let ast (parse)) -(let emitter (Emitter ast input_filename)) +(let emitter (JsEmitter ast input_filename)) (let (emit) emitter) (let js_code (emit)) @@ -32,7 +32,7 @@ // (println js_code) (write_text_file output_filename js_code) -(println "written '%'!" output_filename) +(println "writing '%'" output_filename) diff --git a/compiler/emit_js.phi b/compiler/emit_js.phi index ef2cd6e..48a3db7 100644 --- a/compiler/emit_js.phi +++ b/compiler/emit_js.phi @@ -1,8 +1,12 @@ -(import "stdlib.phi" (slice contains)) +(import "stdlib.phi" ( + slice contains + list_push list_pop list_contains + map map_has map_get map_set +)) (import "compiler/parse.phi" (Parser tokenize)) (import "compiler/syms.phi" (Syms)) -(fn Emitter (ast initial_filename) (do +(fn JsEmitter (ast initial_filename) (do (let output (list)) (let filename initial_filename) @@ -11,6 +15,9 @@ (let (sym_id_count sym_id_increment) (Counter)) (let (let_node_reg_count let_node_reg_increment) (Counter)) + (let import_stack (list filename)) + (let imported_files (map)) + (let builtin_syms (list (list "format" "builtinFormat") (list "print" "builtinPrint") @@ -127,34 +134,48 @@ (panic "illegal function on line %" line) )) (if (== id "import") (do - (let outer_filename filename) (let (_ (_ _ inner_filename) (_ _ idents)) s) - (= filename inner_filename) - (let text (read_text_file filename)) - (let tokens (tokenize text)) - (let parser (Parser tokens)) - (let (parse) parser) - (let ast (parse)) - (let (_ generate_imported) (Emitter ast filename)) - - (emit (format "runtime.setFile(\"%\");\n" filename)) - - (let outer_syms syms) - (= syms (Syms)) - (for (ident builtin_id) builtin_syms (do - (define_builtin ident builtin_id) + (if (list_contains import_stack inner_filename) (do + (panic "circular dependendy: '%' imports '%'" filename inner_filename) )) + (list_push import_stack inner_filename) - (enter_scope) - (discover_syms ast) - (emit_exprs ast) - (let sym_map (get_current_map)) + (let sym_map null) - (= syms outer_syms) - (= filename outer_filename) + (if (map_has imported_files inner_filename) (do + (= sym_map (map_get imported_files inner_filename)) + ) (do + (println "compiling '%'" inner_filename) + (let outer_filename filename) + (= filename inner_filename) - (emit (format "runtime.setFile(\"%\");\n" outer_filename)) + (let text (read_text_file filename)) + (let tokens (tokenize text)) + (let parser (Parser tokens)) + (let (parse) parser) + (let ast (parse)) + + (emit (format "runtime.setFile(\"%\");\n" filename)) + + (let outer_syms syms) + (= syms (Syms)) + (for (ident builtin_id) builtin_syms (do + (define_builtin ident builtin_id) + )) + + (enter_scope) + (discover_syms ast) + (emit_exprs ast) + (= sym_map (get_current_map)) + (map_set imported_files filename sym_map) + + (= syms outer_syms) + (= filename outer_filename) + + (emit (format "runtime.setFile(\"%\");\n" outer_filename)) + )) + (list_pop import_stack) (for (_ _ ident) idents (do (let sym null) @@ -165,7 +186,7 @@ )) )) (if (== sym null) (do - (panic "no symbol '%' from imported '%'" ident filename) + (panic "no symbol '%' from imported '%'" ident inner_filename) )) (let (_ sym_type) sym) (if (== sym_type "imported") (do diff --git a/compiler/syms.phi b/compiler/syms.phi index 6ec155f..3ca77ed 100644 --- a/compiler/syms.phi +++ b/compiler/syms.phi @@ -1,10 +1,10 @@ -(import "stdlib.phi" (indent)) +(import "stdlib.phi" (indent map map_has map_get map_set)) (fn Syms () (do - (let syms (list null (list))) + (let syms (list null (map))) (fn enter_scope () (do - (= syms (list syms (list))) + (= syms (list syms (map))) )) (fn leave_scope () (do @@ -14,29 +14,13 @@ (fn define_sym (ident sym) (do (let (_ map) syms) - (let i 0) - (loop (do - (if (>= i (len map)) (break)) - (let (s_ident _) (at map i)) - (if (== ident s_ident) (do - (set map i (list ident sym)) - (return) - )) - (+= i 1) - )) - (push map (list ident sym)) + (map_set map ident sym) )) (fn find_sym (syms ident) (do (let (parent map) syms) - (let i 0) - (loop (do - (if (>= i (len map)) (break)) - (let (s_ident s_sym) (at map i)) - (if (== ident s_ident) (do - (return s_sym) - )) - (+= i 1) + (if (map_has map ident) (do + (return (map_get map ident)) )) (if (!= parent null) (do (return (find_sym parent ident)) diff --git a/stage2.js b/stage2.js index 9d53008..5aa0b29 100644 --- a/stage2.js +++ b/stage2.js @@ -2,155 +2,66 @@ import { Runtime } from "./runtime.js"; const runtime = new Runtime("compile.phi"); runtime.setFile("stdlib.phi"); -function _slice29(_list33, _idx34) { +function _slice29(_list40, _idx41) { runtime.pushCall("slice", "stdlib.phi"); -const r_0 = (runtime.info("stdlib.phi", 3), ((...args) => runtime.builtinLen(...args))(_list33)); -let _list_len35 = r_0; +const r_0 = (runtime.info("stdlib.phi", 3), ((...args) => runtime.builtinLen(...args))(_list40)); +let _list_len42 = r_0; const r_1 = ({ type: "list", values: [] }); -let _elems36 = r_1; -const r_2 = _idx34; -let _i37 = r_2; +let _elems43 = r_1; +const r_2 = _idx41; +let _i44 = r_2; while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 7), runtime.opGte(_i37, _list_len35)))) { +if (runtime.truthy((runtime.info("stdlib.phi", 7), runtime.opGte(_i44, _list_len42)))) { break}; -(runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinPush(...args))(_elems36, (runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinAt(...args))(_list33, _i37)))); -(_i37 = runtime.opAdd(_i37, ({ type: "int", value: 1 }))); +(runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinPush(...args))(_elems43, (runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinAt(...args))(_list40, _i44)))); +(_i44 = runtime.opAdd(_i44, ({ type: "int", value: 1 }))); }; runtime.popCall(); -return _elems36; +return _elems43; ; runtime.popCall(); return { type: "null" }; }; -function _slice_eq30(_str38, _slice_idx39, _substr40) { +function _slice_eq30(_str45, _slice_idx46, _substr47) { runtime.pushCall("slice_eq", "stdlib.phi"); -const r_3 = (runtime.info("stdlib.phi", 15), ((...args) => runtime.builtinLen(...args))(_str38)); -let _str_len41 = r_3; -const r_4 = (runtime.info("stdlib.phi", 16), ((...args) => runtime.builtinLen(...args))(_substr40)); -let _substr_len42 = r_4; +const r_3 = (runtime.info("stdlib.phi", 15), ((...args) => runtime.builtinLen(...args))(_str45)); +let _str_len48 = r_3; +const r_4 = (runtime.info("stdlib.phi", 16), ((...args) => runtime.builtinLen(...args))(_substr47)); +let _substr_len49 = r_4; const r_5 = ({ type: "int", value: 0 }); -let _i43 = r_5; +let _i50 = r_5; while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 19), runtime.opGte(_i43, _substr_len42)))) { +if (runtime.truthy((runtime.info("stdlib.phi", 19), runtime.opGte(_i50, _substr_len49)))) { runtime.popCall(); return ({ type: "bool", value: true })}; -if (runtime.truthy((runtime.info("stdlib.phi", 21), runtime.opGte((runtime.info("stdlib.phi", 21), runtime.opAdd(_slice_idx39, _i43)), _str_len41)))) { +if (runtime.truthy((runtime.info("stdlib.phi", 21), runtime.opGte((runtime.info("stdlib.phi", 21), runtime.opAdd(_slice_idx46, _i50)), _str_len48)))) { runtime.popCall(); return ({ type: "bool", value: false })}; -if (runtime.truthy((runtime.info("stdlib.phi", 23), runtime.opNe((runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_str38, (runtime.info("stdlib.phi", 23), runtime.opAdd(_slice_idx39, _i43)))), (runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_substr40, _i43)))))) { +if (runtime.truthy((runtime.info("stdlib.phi", 23), runtime.opNe((runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_str45, (runtime.info("stdlib.phi", 23), runtime.opAdd(_slice_idx46, _i50)))), (runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_substr47, _i50)))))) { runtime.popCall(); return ({ type: "bool", value: false })}; -(_i43 = runtime.opAdd(_i43, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); -return ({ type: "bool", value: true }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _contains31(_text44, _ch45) { -runtime.pushCall("contains", "stdlib.phi"); -const r_6 = (runtime.info("stdlib.phi", 32), ((...args) => runtime.builtinLen(...args))(_text44)); -let _text_len46 = r_6; -const r_7 = ({ type: "int", value: 0 }); -let _i47 = r_7; -while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 35), runtime.opGte(_i47, _text_len46)))) { -break}; -if (runtime.truthy((runtime.info("stdlib.phi", 36), runtime.opEq((runtime.info("stdlib.phi", 36), ((...args) => runtime.builtinAt(...args))(_text44, _i47)), _ch45)))) { -runtime.popCall(); -return ({ type: "bool", value: true }); -}; -(_i47 = runtime.opAdd(_i47, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); -return ({ type: "bool", value: false }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _indent32(_depth48) { -runtime.pushCall("indent", "stdlib.phi"); -const r_8 = ({ type: "string", value: "" }); -let _space49 = r_8; -const r_9 = ({ type: "int", value: 0 }); -let _i50 = r_9; -while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 48), runtime.opGte(_i50, _depth48)))) { -break}; -(_space49 = runtime.opAdd(_space49, ({ type: "string", value: " " }))); (_i50 = runtime.opAdd(_i50, ({ type: "int", value: 1 }))); }; runtime.popCall(); -return _space49; -; -runtime.popCall(); -return { type: "null" }; -}; -runtime.setFile("compile.phi"); -; -runtime.setFile("compiler/parse.phi"); -runtime.setFile("stdlib.phi"); -function _slice81(_list85, _idx86) { -runtime.pushCall("slice", "stdlib.phi"); -const r_10 = (runtime.info("stdlib.phi", 3), ((...args) => runtime.builtinLen(...args))(_list85)); -let _list_len87 = r_10; -const r_11 = ({ type: "list", values: [] }); -let _elems88 = r_11; -const r_12 = _idx86; -let _i89 = r_12; -while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 7), runtime.opGte(_i89, _list_len87)))) { -break}; -(runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinPush(...args))(_elems88, (runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinAt(...args))(_list85, _i89)))); -(_i89 = runtime.opAdd(_i89, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); -return _elems88; -; -runtime.popCall(); -return { type: "null" }; -}; -function _slice_eq82(_str90, _slice_idx91, _substr92) { -runtime.pushCall("slice_eq", "stdlib.phi"); -const r_13 = (runtime.info("stdlib.phi", 15), ((...args) => runtime.builtinLen(...args))(_str90)); -let _str_len93 = r_13; -const r_14 = (runtime.info("stdlib.phi", 16), ((...args) => runtime.builtinLen(...args))(_substr92)); -let _substr_len94 = r_14; -const r_15 = ({ type: "int", value: 0 }); -let _i95 = r_15; -while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 19), runtime.opGte(_i95, _substr_len94)))) { -runtime.popCall(); -return ({ type: "bool", value: true })}; -if (runtime.truthy((runtime.info("stdlib.phi", 21), runtime.opGte((runtime.info("stdlib.phi", 21), runtime.opAdd(_slice_idx91, _i95)), _str_len93)))) { -runtime.popCall(); -return ({ type: "bool", value: false })}; -if (runtime.truthy((runtime.info("stdlib.phi", 23), runtime.opNe((runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_str90, (runtime.info("stdlib.phi", 23), runtime.opAdd(_slice_idx91, _i95)))), (runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_substr92, _i95)))))) { -runtime.popCall(); -return ({ type: "bool", value: false })}; -(_i95 = runtime.opAdd(_i95, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); return ({ type: "bool", value: true }); ; runtime.popCall(); return { type: "null" }; }; -function _contains83(_text96, _ch97) { +function _contains31(_text51, _ch52) { runtime.pushCall("contains", "stdlib.phi"); -const r_16 = (runtime.info("stdlib.phi", 32), ((...args) => runtime.builtinLen(...args))(_text96)); -let _text_len98 = r_16; -const r_17 = ({ type: "int", value: 0 }); -let _i99 = r_17; +const r_6 = (runtime.info("stdlib.phi", 32), ((...args) => runtime.builtinLen(...args))(_text51)); +let _text_len53 = r_6; +const r_7 = ({ type: "int", value: 0 }); +let _i54 = r_7; while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 35), runtime.opGte(_i99, _text_len98)))) { +if (runtime.truthy((runtime.info("stdlib.phi", 35), runtime.opGte(_i54, _text_len53)))) { break}; -if (runtime.truthy((runtime.info("stdlib.phi", 36), runtime.opEq((runtime.info("stdlib.phi", 36), ((...args) => runtime.builtinAt(...args))(_text96, _i99)), _ch97)))) { +if (runtime.truthy((runtime.info("stdlib.phi", 36), runtime.opEq((runtime.info("stdlib.phi", 36), ((...args) => runtime.builtinAt(...args))(_text51, _i54)), _ch52)))) { runtime.popCall(); return ({ type: "bool", value: true }); }; -(_i99 = runtime.opAdd(_i99, ({ type: "int", value: 1 }))); +(_i54 = runtime.opAdd(_i54, ({ type: "int", value: 1 }))); }; runtime.popCall(); return ({ type: "bool", value: false }); @@ -158,824 +69,60 @@ return ({ type: "bool", value: false }); runtime.popCall(); return { type: "null" }; }; -function _indent84(_depth100) { +function _indent32(_depth55) { runtime.pushCall("indent", "stdlib.phi"); -const r_18 = ({ type: "string", value: "" }); -let _space101 = r_18; -const r_19 = ({ type: "int", value: 0 }); -let _i102 = r_19; +const r_8 = ({ type: "string", value: "" }); +let _space56 = r_8; +const r_9 = ({ type: "int", value: 0 }); +let _i57 = r_9; while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 48), runtime.opGte(_i102, _depth100)))) { +if (runtime.truthy((runtime.info("stdlib.phi", 48), runtime.opGte(_i57, _depth55)))) { break}; -(_space101 = runtime.opAdd(_space101, ({ type: "string", value: " " }))); -(_i102 = runtime.opAdd(_i102, ({ type: "int", value: 1 }))); +(_space56 = runtime.opAdd(_space56, ({ type: "string", value: " " }))); +(_i57 = runtime.opAdd(_i57, ({ type: "int", value: 1 }))); }; runtime.popCall(); -return _space101; +return _space56; ; runtime.popCall(); return { type: "null" }; }; -runtime.setFile("compiler/parse.phi"); -; -function _Parser65(_tokens103) { -runtime.pushCall("Parser", "compiler/parse.phi"); -const r_20 = ({ type: "int", value: 0 }); -let _i110 = r_20; -const r_21 = (runtime.info("compiler/parse.phi", 5), ((...args) => runtime.builtinAt(...args))(_tokens103, _i110)); -let _tok111 = r_21; -function _parse104() { -runtime.pushCall("parse", "compiler/parse.phi"); -const r_22 = ({ type: "list", values: [] }); -let _exprs112 = r_22; +function _list_push33(_list_58, _value59) { +runtime.pushCall("list_push", "stdlib.phi"); +const r_10 = (runtime.info("stdlib.phi", 56), ((...args) => runtime.builtinLen(...args))(_list_58)); +let _list_len60 = r_10; +const r_11 = ({ type: "int", value: 0 }); +let _i61 = r_11; while (true) { -if (runtime.truthy((runtime.info("compiler/parse.phi", 10), _done109()))) { +if (runtime.truthy((runtime.info("stdlib.phi", 59), runtime.opGte(_i61, _list_len60)))) { break}; -(runtime.info("compiler/parse.phi", 11), ((...args) => runtime.builtinPush(...args))(_exprs112, (runtime.info("compiler/parse.phi", 11), _parse_expr105()))); -}; +if (runtime.truthy((runtime.info("stdlib.phi", 60), runtime.opEq((runtime.info("stdlib.phi", 60), ((...args) => runtime.builtinAt(...args))(_list_58, _i61)), ({ type: "null" }))))) { +(runtime.info("stdlib.phi", 61), ((...args) => runtime.builtinSet(...args))(_list_58, _i61, _value59)); runtime.popCall(); -return _exprs112; +return { type: "null" }; +}; +(_i61 = runtime.opAdd(_i61, ({ type: "int", value: 1 }))); +}; +(runtime.info("stdlib.phi", 66), ((...args) => runtime.builtinPush(...args))(_list_58, _value59)); ; runtime.popCall(); return { type: "null" }; }; -function _parse_expr105() { -runtime.pushCall("parse_expr", "compiler/parse.phi"); -const r_23 = _tok111; -const r_24 = r_23.values[0] ?? { type: "null"}; -let _ty113 = r_24; -const r_25 = r_23.values[1] ?? { type: "null"}; -let _line114 = r_25; -const r_26 = r_23.values[2] ?? { type: "null"}; -let _value115 = r_26; -if (runtime.truthy((runtime.info("compiler/parse.phi", 18), _eat106(({ type: "string", value: "(" }))))) { -const r_27 = ({ type: "list", values: [] }); -let _values116 = r_27; +function _list_pop34(_list_62) { +runtime.pushCall("list_pop", "stdlib.phi"); +const r_12 = (runtime.info("stdlib.phi", 70), runtime.opSub((runtime.info("stdlib.phi", 70), ((...args) => runtime.builtinLen(...args))(_list_62)), ({ type: "int", value: 1 }))); +let _i63 = r_12; while (true) { -if (runtime.truthy((runtime.info("compiler/parse.phi", 21), _test108(({ type: "string", value: ")" }))))) { +if (runtime.truthy((runtime.info("stdlib.phi", 72), runtime.opLt(_i63, ({ type: "int", value: 0 }))))) { break}; -(runtime.info("compiler/parse.phi", 22), ((...args) => runtime.builtinPush(...args))(_values116, (runtime.info("compiler/parse.phi", 22), _parse_expr105()))); -}; -if (runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 24), _eat106(({ type: "string", value: ")" })))))) { -(runtime.info("compiler/parse.phi", 25), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "expected ')' on line %" }), (runtime.info("compiler/parse.phi", 25), ((...args) => runtime.builtinAt(...args))(_tok111, ({ type: "int", value: 1 }))))); -}; -runtime.popCall(); -return ({ type: "list", values: [({ type: "string", value: "list" }), _line114, _values116] }); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 28), _eat106(({ type: "string", value: "string" }))))) { -runtime.popCall(); -return ({ type: "list", values: [({ type: "string", value: "string" }), _line114, _value115] }); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 30), _eat106(({ type: "string", value: "int" }))))) { -runtime.popCall(); -return ({ type: "list", values: [({ type: "string", value: "int" }), _line114, (runtime.info("compiler/parse.phi", 31), ((...args) => runtime.builtinStringToInt(...args))(_value115))] }); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 32), _eat106(({ type: "string", value: "ident" }))))) { -runtime.popCall(); -return ({ type: "list", values: [({ type: "string", value: "ident" }), _line114, _value115] }); -} else { -(runtime.info("compiler/parse.phi", 35), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "expected expression, got '%' on line %" }), _ty113, _line114)); -}}}}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _eat106(_pat117) { -runtime.pushCall("eat", "compiler/parse.phi"); -if (runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 40), _test108(_pat117))))) { -runtime.popCall(); -return ({ type: "bool", value: false })}; -(runtime.info("compiler/parse.phi", 41), _step107()); -runtime.popCall(); -return ({ type: "bool", value: true }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _step107() { -runtime.pushCall("step", "compiler/parse.phi"); -(_i110 = runtime.opAdd(_i110, ({ type: "int", value: 1 }))); -if (runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 47), _done109())))) { -const r_28 = (runtime.info("compiler/parse.phi", 48), ((...args) => runtime.builtinAt(...args))(_tokens103, _i110)); -let _new_tok118 = r_28; -(_tok111 = _new_tok118); -}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _test108(_pat119) { -runtime.pushCall("test", "compiler/parse.phi"); -if (runtime.truthy((runtime.info("compiler/parse.phi", 54), _done109()))) { -runtime.popCall(); -return ({ type: "bool", value: false })}; -const r_29 = _tok111; -const r_30 = r_29.values[0] ?? { type: "null"}; -let _ty120 = r_30; -runtime.popCall(); -return (runtime.info("compiler/parse.phi", 56), runtime.opEq(_pat119, _ty120)); -; -runtime.popCall(); -return { type: "null" }; -}; -function _done109() { -runtime.pushCall("done", "compiler/parse.phi"); -runtime.popCall(); -return (runtime.info("compiler/parse.phi", 60), runtime.opGte(_i110, (runtime.info("compiler/parse.phi", 60), ((...args) => runtime.builtinLen(...args))(_tokens103)))); -; -runtime.popCall(); -return { type: "null" }; -}; -runtime.popCall(); -return ({ type: "list", values: [_parse104] }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _tokenize66(_text121) { -runtime.pushCall("tokenize", "compiler/parse.phi"); -const r_31 = (runtime.info("compiler/parse.phi", 67), ((...args) => runtime.builtinLen(...args))(_text121)); -let _text_len122 = r_31; -const r_32 = ({ type: "list", values: [] }); -let _tokens123 = r_32; -const r_33 = ({ type: "int", value: 0 }); -let _i124 = r_33; -const r_34 = ({ type: "int", value: 1 }); -let _line125 = r_34; -const r_35 = (runtime.info("compiler/parse.phi", 73), runtime.opAdd(({ type: "string", value: "abcdefghijklmnopqrstuvwxyz" }), ({ type: "string", value: "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+-*/%&|=?!<>'_" }))); -let _ident_chars126 = r_35; -while (true) { -if (runtime.truthy((runtime.info("compiler/parse.phi", 77), runtime.opGte(_i124, _text_len122)))) { -break}; -const r_36 = (runtime.info("compiler/parse.phi", 79), ((...args) => runtime.builtinAt(...args))(_text121, _i124)); -let _ch127 = r_36; -if (runtime.truthy((runtime.info("compiler/parse.phi", 81), _contains83(({ type: "string", value: " \t\r\n" }), _ch127)))) { -if (runtime.truthy((runtime.info("compiler/parse.phi", 82), runtime.opEq(_ch127, ({ type: "string", value: "\n" }))))) { -(_line125 = runtime.opAdd(_line125, ({ type: "int", value: 1 }))); -}; -(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 }))); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 86), _slice_eq82(_text121, _i124, ({ type: "string", value: "//" }))))) { -while (true) { -if (runtime.truthy((runtime.info("compiler/parse.phi", 88), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 88), runtime.opGte(_i124, _text_len122))) || runtime.truthy((runtime.info("compiler/parse.phi", 88), runtime.opEq((runtime.info("compiler/parse.phi", 88), ((...args) => runtime.builtinAt(...args))(_text121, _i124)), ({ type: "string", value: "\n" })))) }))) { -break; -}; -(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 }))); -}; -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 93), _contains83(({ type: "string", value: "()" }), _ch127)))) { -(runtime.info("compiler/parse.phi", 94), ((...args) => runtime.builtinPush(...args))(_tokens123, ({ type: "list", values: [_ch127, _line125] }))); -(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 }))); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 96), runtime.opEq(_ch127, ({ type: "string", value: "\"" }))))) { -const r_37 = ({ type: "string", value: "" }); -let _value128 = r_37; -(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 }))); -(_ch127 = (runtime.info("compiler/parse.phi", 99), ((...args) => runtime.builtinAt(...args))(_text121, _i124))); -while (true) { -if (runtime.truthy((runtime.info("compiler/parse.phi", 101), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 101), runtime.opGte(_i124, _text_len122))) || runtime.truthy((runtime.info("compiler/parse.phi", 101), runtime.opEq(_ch127, ({ type: "string", value: "\"" })))) }))) { -break; -}; -if (runtime.truthy((runtime.info("compiler/parse.phi", 104), runtime.opEq(_ch127, ({ type: "string", value: "\\" }))))) { -(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 }))); -if (runtime.truthy((runtime.info("compiler/parse.phi", 106), runtime.opGte(_i124, _text_len122)))) { -break; -}; -(_ch127 = (runtime.info("compiler/parse.phi", 109), ((...args) => runtime.builtinAt(...args))(_text121, _i124))); -if (runtime.truthy((runtime.info("compiler/parse.phi", 110), runtime.opEq(_ch127, ({ type: "string", value: "t" }))))) { -(_value128 = runtime.opAdd(_value128, ({ type: "string", value: "\t" }))); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 112), runtime.opEq(_ch127, ({ type: "string", value: "r" }))))) { -(_value128 = runtime.opAdd(_value128, ({ type: "string", value: "\r" }))); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 114), runtime.opEq(_ch127, ({ type: "string", value: "n" }))))) { -(_value128 = runtime.opAdd(_value128, ({ type: "string", value: "\n" }))); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 116), runtime.opEq(_ch127, ({ type: "string", value: "0" }))))) { -(_value128 = runtime.opAdd(_value128, ({ type: "string", value: "\n" }))); -} else { -(_value128 = runtime.opAdd(_value128, _ch127)); -}}}}; -} else { -(_value128 = runtime.opAdd(_value128, _ch127)); -}; -(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 }))); -(_ch127 = (runtime.info("compiler/parse.phi", 125), ((...args) => runtime.builtinAt(...args))(_text121, _i124))); -}; -if (runtime.truthy((runtime.info("compiler/parse.phi", 127), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 127), runtime.opGte(_i124, _text_len122))) || runtime.truthy((runtime.info("compiler/parse.phi", 127), runtime.opNe(_ch127, ({ type: "string", value: "\"" })))) }))) { -(runtime.info("compiler/parse.phi", 128), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "expected '\"' on line %" }), _line125)); -}; -(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 }))); -(runtime.info("compiler/parse.phi", 131), ((...args) => runtime.builtinPush(...args))(_tokens123, ({ type: "list", values: [({ type: "string", value: "string" }), _line125, _value128] }))); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 132), _contains83(({ type: "string", value: "0123456789" }), _ch127)))) { -const r_38 = ({ type: "string", value: "" }); -let _value129 = r_38; -while (true) { -(_ch127 = (runtime.info("compiler/parse.phi", 135), ((...args) => runtime.builtinAt(...args))(_text121, _i124))); -if (runtime.truthy((runtime.info("compiler/parse.phi", 136), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 136), runtime.opGte(_i124, _text_len122))) || runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 136), _contains83(({ type: "string", value: "0123456789" }), _ch127)))) }))) { -break; -}; -(_value129 = runtime.opAdd(_value129, _ch127)); -(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 }))); -}; -(runtime.info("compiler/parse.phi", 142), ((...args) => runtime.builtinPush(...args))(_tokens123, ({ type: "list", values: [({ type: "string", value: "int" }), _line125, _value129] }))); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 143), _contains83(_ident_chars126, _ch127)))) { -const r_39 = ({ type: "string", value: "" }); -let _value130 = r_39; -while (true) { -(_ch127 = (runtime.info("compiler/parse.phi", 146), ((...args) => runtime.builtinAt(...args))(_text121, _i124))); -if (runtime.truthy((runtime.info("compiler/parse.phi", 147), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 147), runtime.opGte(_i124, _text_len122))) || runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 147), _contains83(_ident_chars126, _ch127)))) }))) { -break; -}; -(_value130 = runtime.opAdd(_value130, _ch127)); -(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 }))); -}; -(runtime.info("compiler/parse.phi", 153), ((...args) => runtime.builtinPush(...args))(_tokens123, ({ type: "list", values: [({ type: "string", value: "ident" }), _line125, _value130] }))); -} else { -(runtime.info("compiler/parse.phi", 155), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "illegal char '%'" }), _ch127)); -(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 }))); -}}}}}}; -}; -runtime.popCall(); -return _tokens123; -; -runtime.popCall(); -return { type: "null" }; -}; -runtime.setFile("compile.phi"); -; -runtime.setFile("compiler/emit_js.phi"); -runtime.setFile("stdlib.phi"); -function _slice162(_list166, _idx167) { -runtime.pushCall("slice", "stdlib.phi"); -const r_40 = (runtime.info("stdlib.phi", 3), ((...args) => runtime.builtinLen(...args))(_list166)); -let _list_len168 = r_40; -const r_41 = ({ type: "list", values: [] }); -let _elems169 = r_41; -const r_42 = _idx167; -let _i170 = r_42; -while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 7), runtime.opGte(_i170, _list_len168)))) { -break}; -(runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinPush(...args))(_elems169, (runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinAt(...args))(_list166, _i170)))); -(_i170 = runtime.opAdd(_i170, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); -return _elems169; -; -runtime.popCall(); -return { type: "null" }; -}; -function _slice_eq163(_str171, _slice_idx172, _substr173) { -runtime.pushCall("slice_eq", "stdlib.phi"); -const r_43 = (runtime.info("stdlib.phi", 15), ((...args) => runtime.builtinLen(...args))(_str171)); -let _str_len174 = r_43; -const r_44 = (runtime.info("stdlib.phi", 16), ((...args) => runtime.builtinLen(...args))(_substr173)); -let _substr_len175 = r_44; -const r_45 = ({ type: "int", value: 0 }); -let _i176 = r_45; -while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 19), runtime.opGte(_i176, _substr_len175)))) { -runtime.popCall(); -return ({ type: "bool", value: true })}; -if (runtime.truthy((runtime.info("stdlib.phi", 21), runtime.opGte((runtime.info("stdlib.phi", 21), runtime.opAdd(_slice_idx172, _i176)), _str_len174)))) { -runtime.popCall(); -return ({ type: "bool", value: false })}; -if (runtime.truthy((runtime.info("stdlib.phi", 23), runtime.opNe((runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_str171, (runtime.info("stdlib.phi", 23), runtime.opAdd(_slice_idx172, _i176)))), (runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_substr173, _i176)))))) { -runtime.popCall(); -return ({ type: "bool", value: false })}; -(_i176 = runtime.opAdd(_i176, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); -return ({ type: "bool", value: true }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _contains164(_text177, _ch178) { -runtime.pushCall("contains", "stdlib.phi"); -const r_46 = (runtime.info("stdlib.phi", 32), ((...args) => runtime.builtinLen(...args))(_text177)); -let _text_len179 = r_46; -const r_47 = ({ type: "int", value: 0 }); -let _i180 = r_47; -while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 35), runtime.opGte(_i180, _text_len179)))) { -break}; -if (runtime.truthy((runtime.info("stdlib.phi", 36), runtime.opEq((runtime.info("stdlib.phi", 36), ((...args) => runtime.builtinAt(...args))(_text177, _i180)), _ch178)))) { -runtime.popCall(); -return ({ type: "bool", value: true }); -}; -(_i180 = runtime.opAdd(_i180, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); -return ({ type: "bool", value: false }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _indent165(_depth181) { -runtime.pushCall("indent", "stdlib.phi"); -const r_48 = ({ type: "string", value: "" }); -let _space182 = r_48; -const r_49 = ({ type: "int", value: 0 }); -let _i183 = r_49; -while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 48), runtime.opGte(_i183, _depth181)))) { -break}; -(_space182 = runtime.opAdd(_space182, ({ type: "string", value: " " }))); -(_i183 = runtime.opAdd(_i183, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); -return _space182; -; -runtime.popCall(); -return { type: "null" }; -}; -runtime.setFile("compiler/emit_js.phi"); -; -runtime.setFile("compiler/parse.phi"); -runtime.setFile("stdlib.phi"); -function _slice214(_list218, _idx219) { -runtime.pushCall("slice", "stdlib.phi"); -const r_50 = (runtime.info("stdlib.phi", 3), ((...args) => runtime.builtinLen(...args))(_list218)); -let _list_len220 = r_50; -const r_51 = ({ type: "list", values: [] }); -let _elems221 = r_51; -const r_52 = _idx219; -let _i222 = r_52; -while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 7), runtime.opGte(_i222, _list_len220)))) { -break}; -(runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinPush(...args))(_elems221, (runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinAt(...args))(_list218, _i222)))); -(_i222 = runtime.opAdd(_i222, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); -return _elems221; -; -runtime.popCall(); -return { type: "null" }; -}; -function _slice_eq215(_str223, _slice_idx224, _substr225) { -runtime.pushCall("slice_eq", "stdlib.phi"); -const r_53 = (runtime.info("stdlib.phi", 15), ((...args) => runtime.builtinLen(...args))(_str223)); -let _str_len226 = r_53; -const r_54 = (runtime.info("stdlib.phi", 16), ((...args) => runtime.builtinLen(...args))(_substr225)); -let _substr_len227 = r_54; -const r_55 = ({ type: "int", value: 0 }); -let _i228 = r_55; -while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 19), runtime.opGte(_i228, _substr_len227)))) { -runtime.popCall(); -return ({ type: "bool", value: true })}; -if (runtime.truthy((runtime.info("stdlib.phi", 21), runtime.opGte((runtime.info("stdlib.phi", 21), runtime.opAdd(_slice_idx224, _i228)), _str_len226)))) { -runtime.popCall(); -return ({ type: "bool", value: false })}; -if (runtime.truthy((runtime.info("stdlib.phi", 23), runtime.opNe((runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_str223, (runtime.info("stdlib.phi", 23), runtime.opAdd(_slice_idx224, _i228)))), (runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_substr225, _i228)))))) { -runtime.popCall(); -return ({ type: "bool", value: false })}; -(_i228 = runtime.opAdd(_i228, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); -return ({ type: "bool", value: true }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _contains216(_text229, _ch230) { -runtime.pushCall("contains", "stdlib.phi"); -const r_56 = (runtime.info("stdlib.phi", 32), ((...args) => runtime.builtinLen(...args))(_text229)); -let _text_len231 = r_56; -const r_57 = ({ type: "int", value: 0 }); -let _i232 = r_57; -while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 35), runtime.opGte(_i232, _text_len231)))) { -break}; -if (runtime.truthy((runtime.info("stdlib.phi", 36), runtime.opEq((runtime.info("stdlib.phi", 36), ((...args) => runtime.builtinAt(...args))(_text229, _i232)), _ch230)))) { -runtime.popCall(); -return ({ type: "bool", value: true }); -}; -(_i232 = runtime.opAdd(_i232, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); -return ({ type: "bool", value: false }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _indent217(_depth233) { -runtime.pushCall("indent", "stdlib.phi"); -const r_58 = ({ type: "string", value: "" }); -let _space234 = r_58; -const r_59 = ({ type: "int", value: 0 }); -let _i235 = r_59; -while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 48), runtime.opGte(_i235, _depth233)))) { -break}; -(_space234 = runtime.opAdd(_space234, ({ type: "string", value: " " }))); -(_i235 = runtime.opAdd(_i235, ({ type: "int", value: 1 }))); -}; +const r_13 = (runtime.info("stdlib.phi", 73), ((...args) => runtime.builtinAt(...args))(_list_62, _i63)); +let _value64 = r_13; +if (runtime.truthy((runtime.info("stdlib.phi", 74), runtime.opNe(_value64, ({ type: "null" }))))) { +(runtime.info("stdlib.phi", 75), ((...args) => runtime.builtinSet(...args))(_list_62, _i63, ({ type: "null" }))); runtime.popCall(); -return _space234; -; -runtime.popCall(); -return { type: "null" }; -}; -runtime.setFile("compiler/parse.phi"); -; -function _Parser198(_tokens236) { -runtime.pushCall("Parser", "compiler/parse.phi"); -const r_60 = ({ type: "int", value: 0 }); -let _i243 = r_60; -const r_61 = (runtime.info("compiler/parse.phi", 5), ((...args) => runtime.builtinAt(...args))(_tokens236, _i243)); -let _tok244 = r_61; -function _parse237() { -runtime.pushCall("parse", "compiler/parse.phi"); -const r_62 = ({ type: "list", values: [] }); -let _exprs245 = r_62; -while (true) { -if (runtime.truthy((runtime.info("compiler/parse.phi", 10), _done242()))) { -break}; -(runtime.info("compiler/parse.phi", 11), ((...args) => runtime.builtinPush(...args))(_exprs245, (runtime.info("compiler/parse.phi", 11), _parse_expr238()))); -}; -runtime.popCall(); -return _exprs245; -; -runtime.popCall(); -return { type: "null" }; -}; -function _parse_expr238() { -runtime.pushCall("parse_expr", "compiler/parse.phi"); -const r_63 = _tok244; -const r_64 = r_63.values[0] ?? { type: "null"}; -let _ty246 = r_64; -const r_65 = r_63.values[1] ?? { type: "null"}; -let _line247 = r_65; -const r_66 = r_63.values[2] ?? { type: "null"}; -let _value248 = r_66; -if (runtime.truthy((runtime.info("compiler/parse.phi", 18), _eat239(({ type: "string", value: "(" }))))) { -const r_67 = ({ type: "list", values: [] }); -let _values249 = r_67; -while (true) { -if (runtime.truthy((runtime.info("compiler/parse.phi", 21), _test241(({ type: "string", value: ")" }))))) { -break}; -(runtime.info("compiler/parse.phi", 22), ((...args) => runtime.builtinPush(...args))(_values249, (runtime.info("compiler/parse.phi", 22), _parse_expr238()))); -}; -if (runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 24), _eat239(({ type: "string", value: ")" })))))) { -(runtime.info("compiler/parse.phi", 25), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "expected ')' on line %" }), (runtime.info("compiler/parse.phi", 25), ((...args) => runtime.builtinAt(...args))(_tok244, ({ type: "int", value: 1 }))))); -}; -runtime.popCall(); -return ({ type: "list", values: [({ type: "string", value: "list" }), _line247, _values249] }); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 28), _eat239(({ type: "string", value: "string" }))))) { -runtime.popCall(); -return ({ type: "list", values: [({ type: "string", value: "string" }), _line247, _value248] }); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 30), _eat239(({ type: "string", value: "int" }))))) { -runtime.popCall(); -return ({ type: "list", values: [({ type: "string", value: "int" }), _line247, (runtime.info("compiler/parse.phi", 31), ((...args) => runtime.builtinStringToInt(...args))(_value248))] }); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 32), _eat239(({ type: "string", value: "ident" }))))) { -runtime.popCall(); -return ({ type: "list", values: [({ type: "string", value: "ident" }), _line247, _value248] }); -} else { -(runtime.info("compiler/parse.phi", 35), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "expected expression, got '%' on line %" }), _ty246, _line247)); -}}}}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _eat239(_pat250) { -runtime.pushCall("eat", "compiler/parse.phi"); -if (runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 40), _test241(_pat250))))) { -runtime.popCall(); -return ({ type: "bool", value: false })}; -(runtime.info("compiler/parse.phi", 41), _step240()); -runtime.popCall(); -return ({ type: "bool", value: true }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _step240() { -runtime.pushCall("step", "compiler/parse.phi"); -(_i243 = runtime.opAdd(_i243, ({ type: "int", value: 1 }))); -if (runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 47), _done242())))) { -const r_68 = (runtime.info("compiler/parse.phi", 48), ((...args) => runtime.builtinAt(...args))(_tokens236, _i243)); -let _new_tok251 = r_68; -(_tok244 = _new_tok251); -}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _test241(_pat252) { -runtime.pushCall("test", "compiler/parse.phi"); -if (runtime.truthy((runtime.info("compiler/parse.phi", 54), _done242()))) { -runtime.popCall(); -return ({ type: "bool", value: false })}; -const r_69 = _tok244; -const r_70 = r_69.values[0] ?? { type: "null"}; -let _ty253 = r_70; -runtime.popCall(); -return (runtime.info("compiler/parse.phi", 56), runtime.opEq(_pat252, _ty253)); -; -runtime.popCall(); -return { type: "null" }; -}; -function _done242() { -runtime.pushCall("done", "compiler/parse.phi"); -runtime.popCall(); -return (runtime.info("compiler/parse.phi", 60), runtime.opGte(_i243, (runtime.info("compiler/parse.phi", 60), ((...args) => runtime.builtinLen(...args))(_tokens236)))); -; -runtime.popCall(); -return { type: "null" }; -}; -runtime.popCall(); -return ({ type: "list", values: [_parse237] }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _tokenize199(_text254) { -runtime.pushCall("tokenize", "compiler/parse.phi"); -const r_71 = (runtime.info("compiler/parse.phi", 67), ((...args) => runtime.builtinLen(...args))(_text254)); -let _text_len255 = r_71; -const r_72 = ({ type: "list", values: [] }); -let _tokens256 = r_72; -const r_73 = ({ type: "int", value: 0 }); -let _i257 = r_73; -const r_74 = ({ type: "int", value: 1 }); -let _line258 = r_74; -const r_75 = (runtime.info("compiler/parse.phi", 73), runtime.opAdd(({ type: "string", value: "abcdefghijklmnopqrstuvwxyz" }), ({ type: "string", value: "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+-*/%&|=?!<>'_" }))); -let _ident_chars259 = r_75; -while (true) { -if (runtime.truthy((runtime.info("compiler/parse.phi", 77), runtime.opGte(_i257, _text_len255)))) { -break}; -const r_76 = (runtime.info("compiler/parse.phi", 79), ((...args) => runtime.builtinAt(...args))(_text254, _i257)); -let _ch260 = r_76; -if (runtime.truthy((runtime.info("compiler/parse.phi", 81), _contains216(({ type: "string", value: " \t\r\n" }), _ch260)))) { -if (runtime.truthy((runtime.info("compiler/parse.phi", 82), runtime.opEq(_ch260, ({ type: "string", value: "\n" }))))) { -(_line258 = runtime.opAdd(_line258, ({ type: "int", value: 1 }))); -}; -(_i257 = runtime.opAdd(_i257, ({ type: "int", value: 1 }))); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 86), _slice_eq215(_text254, _i257, ({ type: "string", value: "//" }))))) { -while (true) { -if (runtime.truthy((runtime.info("compiler/parse.phi", 88), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 88), runtime.opGte(_i257, _text_len255))) || runtime.truthy((runtime.info("compiler/parse.phi", 88), runtime.opEq((runtime.info("compiler/parse.phi", 88), ((...args) => runtime.builtinAt(...args))(_text254, _i257)), ({ type: "string", value: "\n" })))) }))) { -break; -}; -(_i257 = runtime.opAdd(_i257, ({ type: "int", value: 1 }))); -}; -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 93), _contains216(({ type: "string", value: "()" }), _ch260)))) { -(runtime.info("compiler/parse.phi", 94), ((...args) => runtime.builtinPush(...args))(_tokens256, ({ type: "list", values: [_ch260, _line258] }))); -(_i257 = runtime.opAdd(_i257, ({ type: "int", value: 1 }))); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 96), runtime.opEq(_ch260, ({ type: "string", value: "\"" }))))) { -const r_77 = ({ type: "string", value: "" }); -let _value261 = r_77; -(_i257 = runtime.opAdd(_i257, ({ type: "int", value: 1 }))); -(_ch260 = (runtime.info("compiler/parse.phi", 99), ((...args) => runtime.builtinAt(...args))(_text254, _i257))); -while (true) { -if (runtime.truthy((runtime.info("compiler/parse.phi", 101), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 101), runtime.opGte(_i257, _text_len255))) || runtime.truthy((runtime.info("compiler/parse.phi", 101), runtime.opEq(_ch260, ({ type: "string", value: "\"" })))) }))) { -break; -}; -if (runtime.truthy((runtime.info("compiler/parse.phi", 104), runtime.opEq(_ch260, ({ type: "string", value: "\\" }))))) { -(_i257 = runtime.opAdd(_i257, ({ type: "int", value: 1 }))); -if (runtime.truthy((runtime.info("compiler/parse.phi", 106), runtime.opGte(_i257, _text_len255)))) { -break; -}; -(_ch260 = (runtime.info("compiler/parse.phi", 109), ((...args) => runtime.builtinAt(...args))(_text254, _i257))); -if (runtime.truthy((runtime.info("compiler/parse.phi", 110), runtime.opEq(_ch260, ({ type: "string", value: "t" }))))) { -(_value261 = runtime.opAdd(_value261, ({ type: "string", value: "\t" }))); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 112), runtime.opEq(_ch260, ({ type: "string", value: "r" }))))) { -(_value261 = runtime.opAdd(_value261, ({ type: "string", value: "\r" }))); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 114), runtime.opEq(_ch260, ({ type: "string", value: "n" }))))) { -(_value261 = runtime.opAdd(_value261, ({ type: "string", value: "\n" }))); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 116), runtime.opEq(_ch260, ({ type: "string", value: "0" }))))) { -(_value261 = runtime.opAdd(_value261, ({ type: "string", value: "\n" }))); -} else { -(_value261 = runtime.opAdd(_value261, _ch260)); -}}}}; -} else { -(_value261 = runtime.opAdd(_value261, _ch260)); -}; -(_i257 = runtime.opAdd(_i257, ({ type: "int", value: 1 }))); -(_ch260 = (runtime.info("compiler/parse.phi", 125), ((...args) => runtime.builtinAt(...args))(_text254, _i257))); -}; -if (runtime.truthy((runtime.info("compiler/parse.phi", 127), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 127), runtime.opGte(_i257, _text_len255))) || runtime.truthy((runtime.info("compiler/parse.phi", 127), runtime.opNe(_ch260, ({ type: "string", value: "\"" })))) }))) { -(runtime.info("compiler/parse.phi", 128), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "expected '\"' on line %" }), _line258)); -}; -(_i257 = runtime.opAdd(_i257, ({ type: "int", value: 1 }))); -(runtime.info("compiler/parse.phi", 131), ((...args) => runtime.builtinPush(...args))(_tokens256, ({ type: "list", values: [({ type: "string", value: "string" }), _line258, _value261] }))); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 132), _contains216(({ type: "string", value: "0123456789" }), _ch260)))) { -const r_78 = ({ type: "string", value: "" }); -let _value262 = r_78; -while (true) { -(_ch260 = (runtime.info("compiler/parse.phi", 135), ((...args) => runtime.builtinAt(...args))(_text254, _i257))); -if (runtime.truthy((runtime.info("compiler/parse.phi", 136), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 136), runtime.opGte(_i257, _text_len255))) || runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 136), _contains216(({ type: "string", value: "0123456789" }), _ch260)))) }))) { -break; -}; -(_value262 = runtime.opAdd(_value262, _ch260)); -(_i257 = runtime.opAdd(_i257, ({ type: "int", value: 1 }))); +return _value64; }; -(runtime.info("compiler/parse.phi", 142), ((...args) => runtime.builtinPush(...args))(_tokens256, ({ type: "list", values: [({ type: "string", value: "int" }), _line258, _value262] }))); -} else { -if (runtime.truthy((runtime.info("compiler/parse.phi", 143), _contains216(_ident_chars259, _ch260)))) { -const r_79 = ({ type: "string", value: "" }); -let _value263 = r_79; -while (true) { -(_ch260 = (runtime.info("compiler/parse.phi", 146), ((...args) => runtime.builtinAt(...args))(_text254, _i257))); -if (runtime.truthy((runtime.info("compiler/parse.phi", 147), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 147), runtime.opGte(_i257, _text_len255))) || runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 147), _contains216(_ident_chars259, _ch260)))) }))) { -break; -}; -(_value263 = runtime.opAdd(_value263, _ch260)); -(_i257 = runtime.opAdd(_i257, ({ type: "int", value: 1 }))); -}; -(runtime.info("compiler/parse.phi", 153), ((...args) => runtime.builtinPush(...args))(_tokens256, ({ type: "list", values: [({ type: "string", value: "ident" }), _line258, _value263] }))); -} else { -(runtime.info("compiler/parse.phi", 155), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "illegal char '%'" }), _ch260)); -(_i257 = runtime.opAdd(_i257, ({ type: "int", value: 1 }))); -}}}}}}; -}; -runtime.popCall(); -return _tokens256; -; -runtime.popCall(); -return { type: "null" }; -}; -runtime.setFile("compiler/emit_js.phi"); -; -runtime.setFile("compiler/syms.phi"); -runtime.setFile("stdlib.phi"); -function _slice293(_list297, _idx298) { -runtime.pushCall("slice", "stdlib.phi"); -const r_80 = (runtime.info("stdlib.phi", 3), ((...args) => runtime.builtinLen(...args))(_list297)); -let _list_len299 = r_80; -const r_81 = ({ type: "list", values: [] }); -let _elems300 = r_81; -const r_82 = _idx298; -let _i301 = r_82; -while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 7), runtime.opGte(_i301, _list_len299)))) { -break}; -(runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinPush(...args))(_elems300, (runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinAt(...args))(_list297, _i301)))); -(_i301 = runtime.opAdd(_i301, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); -return _elems300; -; -runtime.popCall(); -return { type: "null" }; -}; -function _slice_eq294(_str302, _slice_idx303, _substr304) { -runtime.pushCall("slice_eq", "stdlib.phi"); -const r_83 = (runtime.info("stdlib.phi", 15), ((...args) => runtime.builtinLen(...args))(_str302)); -let _str_len305 = r_83; -const r_84 = (runtime.info("stdlib.phi", 16), ((...args) => runtime.builtinLen(...args))(_substr304)); -let _substr_len306 = r_84; -const r_85 = ({ type: "int", value: 0 }); -let _i307 = r_85; -while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 19), runtime.opGte(_i307, _substr_len306)))) { -runtime.popCall(); -return ({ type: "bool", value: true })}; -if (runtime.truthy((runtime.info("stdlib.phi", 21), runtime.opGte((runtime.info("stdlib.phi", 21), runtime.opAdd(_slice_idx303, _i307)), _str_len305)))) { -runtime.popCall(); -return ({ type: "bool", value: false })}; -if (runtime.truthy((runtime.info("stdlib.phi", 23), runtime.opNe((runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_str302, (runtime.info("stdlib.phi", 23), runtime.opAdd(_slice_idx303, _i307)))), (runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_substr304, _i307)))))) { -runtime.popCall(); -return ({ type: "bool", value: false })}; -(_i307 = runtime.opAdd(_i307, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); -return ({ type: "bool", value: true }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _contains295(_text308, _ch309) { -runtime.pushCall("contains", "stdlib.phi"); -const r_86 = (runtime.info("stdlib.phi", 32), ((...args) => runtime.builtinLen(...args))(_text308)); -let _text_len310 = r_86; -const r_87 = ({ type: "int", value: 0 }); -let _i311 = r_87; -while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 35), runtime.opGte(_i311, _text_len310)))) { -break}; -if (runtime.truthy((runtime.info("stdlib.phi", 36), runtime.opEq((runtime.info("stdlib.phi", 36), ((...args) => runtime.builtinAt(...args))(_text308, _i311)), _ch309)))) { -runtime.popCall(); -return ({ type: "bool", value: true }); -}; -(_i311 = runtime.opAdd(_i311, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); -return ({ type: "bool", value: false }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _indent296(_depth312) { -runtime.pushCall("indent", "stdlib.phi"); -const r_88 = ({ type: "string", value: "" }); -let _space313 = r_88; -const r_89 = ({ type: "int", value: 0 }); -let _i314 = r_89; -while (true) { -if (runtime.truthy((runtime.info("stdlib.phi", 48), runtime.opGte(_i314, _depth312)))) { -break}; -(_space313 = runtime.opAdd(_space313, ({ type: "string", value: " " }))); -(_i314 = runtime.opAdd(_i314, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); -return _space313; -; -runtime.popCall(); -return { type: "null" }; -}; -runtime.setFile("compiler/syms.phi"); -; -function _Syms278() { -runtime.pushCall("Syms", "compiler/syms.phi"); -const r_90 = ({ type: "list", values: [({ type: "null" }), ({ type: "list", values: [] })] }); -let _syms323 = r_90; -function _enter_scope315() { -runtime.pushCall("enter_scope", "compiler/syms.phi"); -(_syms323 = ({ type: "list", values: [_syms323, ({ type: "list", values: [] })] })); -; -runtime.popCall(); -return { type: "null" }; -}; -function _leave_scope316() { -runtime.pushCall("leave_scope", "compiler/syms.phi"); -const r_91 = _syms323; -const r_92 = r_91.values[0] ?? { type: "null"}; -let _parent324 = r_92; -const r_93 = r_91.values[1] ?? { type: "null"}; -(_syms323 = _parent324); -; -runtime.popCall(); -return { type: "null" }; -}; -function _define_sym317(_ident325, _sym326) { -runtime.pushCall("define_sym", "compiler/syms.phi"); -const r_94 = _syms323; -const r_95 = r_94.values[0] ?? { type: "null"}; -const r_96 = r_94.values[1] ?? { type: "null"}; -let _map327 = r_96; -const r_97 = ({ type: "int", value: 0 }); -let _i328 = r_97; -while (true) { -if (runtime.truthy((runtime.info("compiler/syms.phi", 19), runtime.opGte(_i328, (runtime.info("compiler/syms.phi", 19), ((...args) => runtime.builtinLen(...args))(_map327)))))) { -break}; -const r_98 = (runtime.info("compiler/syms.phi", 20), ((...args) => runtime.builtinAt(...args))(_map327, _i328)); -const r_99 = r_98.values[0] ?? { type: "null"}; -let _s_ident329 = r_99; -const r_100 = r_98.values[1] ?? { type: "null"}; -if (runtime.truthy((runtime.info("compiler/syms.phi", 21), runtime.opEq(_ident325, _s_ident329)))) { -(runtime.info("compiler/syms.phi", 22), ((...args) => runtime.builtinSet(...args))(_map327, _i328, ({ type: "list", values: [_ident325, _sym326] }))); -runtime.popCall(); -return { type: "null" }; -}; -(_i328 = runtime.opAdd(_i328, ({ type: "int", value: 1 }))); -}; -(runtime.info("compiler/syms.phi", 27), ((...args) => runtime.builtinPush(...args))(_map327, ({ type: "list", values: [_ident325, _sym326] }))); -; -runtime.popCall(); -return { type: "null" }; -}; -function _find_sym318(_syms330, _ident331) { -runtime.pushCall("find_sym", "compiler/syms.phi"); -const r_101 = _syms330; -const r_102 = r_101.values[0] ?? { type: "null"}; -let _parent332 = r_102; -const r_103 = r_101.values[1] ?? { type: "null"}; -let _map333 = r_103; -const r_104 = ({ type: "int", value: 0 }); -let _i334 = r_104; -while (true) { -if (runtime.truthy((runtime.info("compiler/syms.phi", 34), runtime.opGte(_i334, (runtime.info("compiler/syms.phi", 34), ((...args) => runtime.builtinLen(...args))(_map333)))))) { -break}; -const r_105 = (runtime.info("compiler/syms.phi", 35), ((...args) => runtime.builtinAt(...args))(_map333, _i334)); -const r_106 = r_105.values[0] ?? { type: "null"}; -let _s_ident335 = r_106; -const r_107 = r_105.values[1] ?? { type: "null"}; -let _s_sym336 = r_107; -if (runtime.truthy((runtime.info("compiler/syms.phi", 36), runtime.opEq(_ident331, _s_ident335)))) { -runtime.popCall(); -return _s_sym336; -}; -(_i334 = runtime.opAdd(_i334, ({ type: "int", value: 1 }))); -}; -if (runtime.truthy((runtime.info("compiler/syms.phi", 41), runtime.opNe(_parent332, ({ type: "null" }))))) { -runtime.popCall(); -return (runtime.info("compiler/syms.phi", 42), _find_sym318(_parent332, _ident331)); +(_i63 = runtime.opSub(_i63, ({ type: "int", value: 1 }))); }; runtime.popCall(); return ({ type: "null" }); @@ -983,1013 +130,1393 @@ return ({ type: "null" }); runtime.popCall(); return { type: "null" }; }; -function _get_sym319(_ident337) { -runtime.pushCall("get_sym", "compiler/syms.phi"); +function _list_contains35(_list_65, _value66) { +runtime.pushCall("list_contains", "stdlib.phi"); +for (const r_14 of _list_65.values) {; +let _elem67 = r_14; +if (runtime.truthy((runtime.info("stdlib.phi", 85), runtime.opEq(_elem67, _value66)))) { runtime.popCall(); -return (runtime.info("compiler/syms.phi", 48), _find_sym318(_syms323, _ident337)); +return ({ type: "bool", value: true }); +}; +}; +runtime.popCall(); +return ({ type: "bool", value: false }); ; runtime.popCall(); return { type: "null" }; }; -function _get_current_map320() { -runtime.pushCall("get_current_map", "compiler/syms.phi"); -const r_108 = _syms323; -const r_109 = r_108.values[0] ?? { type: "null"}; -const r_110 = r_108.values[1] ?? { type: "null"}; -let _map338 = r_110; +function _map36() { +runtime.pushCall("map", "stdlib.phi"); runtime.popCall(); -return _map338; +return ({ type: "list", values: [] }); ; runtime.popCall(); return { type: "null" }; }; -function _print_syms_node321(_syms339, _depth340) { -runtime.pushCall("print_syms_node", "compiler/syms.phi"); -const r_111 = _syms339; -const r_112 = r_111.values[0] ?? { type: "null"}; -let _parent341 = r_112; -const r_113 = r_111.values[1] ?? { type: "null"}; -let _map342 = r_113; -for (const r_114 of _map342.values) {; -const r_115 = r_114.values[0] ?? { type: "null"}; -let _ident343 = r_115; -const r_116 = r_114.values[1] ?? { type: "null"}; -let _sym344 = r_116; -(runtime.info("compiler/syms.phi", 59), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "%- %: %" }), (runtime.info("compiler/syms.phi", 59), _indent296(_depth340)), _ident343, _sym344)); +function _map_has37(_map68, _key69) { +runtime.pushCall("map_has", "stdlib.phi"); +for (const r_15 of _map68.values) {; +const r_16 = r_15.values[0] ?? { type: "null"}; +let _m_key70 = r_16; +const r_17 = r_15.values[1] ?? { type: "null"}; +if (runtime.truthy((runtime.info("stdlib.phi", 98), runtime.opEq(_m_key70, _key69)))) { +runtime.popCall(); +return ({ type: "bool", value: true }); }; -if (runtime.truthy((runtime.info("compiler/syms.phi", 61), runtime.opNe(_parent341, ({ type: "null" }))))) { -(runtime.info("compiler/syms.phi", 62), _print_syms_node321(_parent341, (runtime.info("compiler/syms.phi", 62), runtime.opAdd(_depth340, ({ type: "int", value: 1 }))))); }; +runtime.popCall(); +return ({ type: "bool", value: false }); ; runtime.popCall(); return { type: "null" }; }; -function _print_syms322() { -runtime.pushCall("print_syms", "compiler/syms.phi"); -(runtime.info("compiler/syms.phi", 67), _print_syms_node321(_syms323, ({ type: "int", value: 0 }))); +function _map_get38(_map71, _key72) { +runtime.pushCall("map_get", "stdlib.phi"); +for (const r_18 of _map71.values) {; +const r_19 = r_18.values[0] ?? { type: "null"}; +let _m_key73 = r_19; +const r_20 = r_18.values[1] ?? { type: "null"}; +let _value74 = r_20; +if (runtime.truthy((runtime.info("stdlib.phi", 107), runtime.opEq(_m_key73, _key72)))) { +runtime.popCall(); +return _value74; +}; +}; +runtime.popCall(); +return ({ type: "null" }); ; runtime.popCall(); return { type: "null" }; }; -runtime.popCall(); -return ({ type: "list", values: [_enter_scope315, _leave_scope316, _define_sym317, _get_sym319, _get_current_map320, _print_syms322] }); -; +function _map_set39(_map75, _key76, _value77) { +runtime.pushCall("map_set", "stdlib.phi"); +for (const r_21 of _map75.values) {; +let _entry78 = r_21; +const r_22 = _entry78; +const r_23 = r_22.values[0] ?? { type: "null"}; +let _entry_key79 = r_23; +const r_24 = r_22.values[1] ?? { type: "null"}; +if (runtime.truthy((runtime.info("stdlib.phi", 117), runtime.opEq(_entry_key79, _key76)))) { +(runtime.info("stdlib.phi", 118), ((...args) => runtime.builtinSet(...args))(_entry78, ({ type: "int", value: 1 }), _value77)); runtime.popCall(); return { type: "null" }; }; -runtime.setFile("compiler/emit_js.phi"); -; -function _Emitter145(_ast345, _initial_filename346) { -runtime.pushCall("Emitter", "compiler/emit_js.phi"); -const r_117 = ({ type: "list", values: [] }); -let _output368 = r_117; -const r_118 = _initial_filename346; -let _filename369 = r_118; -const r_119 = (runtime.info("compiler/emit_js.phi", 9), _Syms278()); -let _syms370 = r_119; -const r_120 = (runtime.info("compiler/emit_js.phi", 11), _Counter146()); -const r_121 = r_120.values[0] ?? { type: "null"}; -let _sym_id_count371 = r_121; -const r_122 = r_120.values[1] ?? { type: "null"}; -let _sym_id_increment372 = r_122; -const r_123 = (runtime.info("compiler/emit_js.phi", 12), _Counter146()); -const r_124 = r_123.values[0] ?? { type: "null"}; -let _let_node_reg_count373 = r_124; -const r_125 = r_123.values[1] ?? { type: "null"}; -let _let_node_reg_increment374 = r_125; -const r_126 = ({ type: "list", values: [({ type: "list", values: [({ type: "string", value: "format" }), ({ type: "string", value: "builtinFormat" })] }), ({ type: "list", values: [({ type: "string", value: "print" }), ({ type: "string", value: "builtinPrint" })] }), ({ type: "list", values: [({ type: "string", value: "println" }), ({ type: "string", value: "builtinPrintln" })] }), ({ type: "list", values: [({ type: "string", value: "panic" }), ({ type: "string", value: "builtinPanic" })] }), ({ type: "list", values: [({ type: "string", value: "read_text_file" }), ({ type: "string", value: "builtinReadTextFile" })] }), ({ type: "list", values: [({ type: "string", value: "write_text_file" }), ({ type: "string", value: "builtinWriteTextFile" })] }), ({ type: "list", values: [({ type: "string", value: "push" }), ({ type: "string", value: "builtinPush" })] }), ({ type: "list", values: [({ type: "string", value: "at" }), ({ type: "string", value: "builtinAt" })] }), ({ type: "list", values: [({ type: "string", value: "set" }), ({ type: "string", value: "builtinSet" })] }), ({ type: "list", values: [({ type: "string", value: "len" }), ({ type: "string", value: "builtinLen" })] }), ({ type: "list", values: [({ type: "string", value: "string_to_int" }), ({ type: "string", value: "builtinStringToInt" })] }), ({ type: "list", values: [({ type: "string", value: "char_code" }), ({ type: "string", value: "builtinCharCode" })] }), ({ type: "list", values: [({ type: "string", value: "strings_join" }), ({ type: "string", value: "builtinStringsJoin" })] }), ({ type: "list", values: [({ type: "string", value: "get_args" }), ({ type: "string", value: "builtinGetArgs" })] })] }); -let _builtin_syms375 = r_126; -function _generate347() { -runtime.pushCall("generate", "compiler/emit_js.phi"); -(runtime.info("compiler/emit_js.phi", 32), _emit357(({ type: "string", value: "#!/usr/bin/env node\n" }))); -(runtime.info("compiler/emit_js.phi", 33), _emit357(({ type: "string", value: "import { Runtime } from \"./runtime.js\";\n" }))); -(runtime.info("compiler/emit_js.phi", 34), _emit357((runtime.info("compiler/emit_js.phi", 34), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "const runtime = new Runtime(\"%\");\n" }), _filename369)))); -for (const r_127 of _builtin_syms375.values) {; -const r_128 = r_127.values[0] ?? { type: "null"}; -let _ident376 = r_128; -const r_129 = r_127.values[1] ?? { type: "null"}; -let _builtin_id377 = r_129; -(runtime.info("compiler/emit_js.phi", 37), _define_builtin358(_ident376, _builtin_id377)); }; -(runtime.info("compiler/emit_js.phi", 40), _enter_scope362()); -(runtime.info("compiler/emit_js.phi", 41), _discover_syms349(_ast345)); -(runtime.info("compiler/emit_js.phi", 42), _emit_exprs348(_ast345)); -runtime.popCall(); -return (runtime.info("compiler/emit_js.phi", 43), ((...args) => runtime.builtinStringsJoin(...args))(_output368)); -; -runtime.popCall(); -return { type: "null" }; -}; -function _emit_exprs348(_exprs378) { -runtime.pushCall("emit_exprs", "compiler/emit_js.phi"); -for (const r_130 of _exprs378.values) {; -let _expr379 = r_130; -(runtime.info("compiler/emit_js.phi", 48), _emit_expr350(_expr379)); -(runtime.info("compiler/emit_js.phi", 49), _emit357(({ type: "string", value: ";\n" }))); -}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _discover_syms349(_exprs380) { -runtime.pushCall("discover_syms", "compiler/emit_js.phi"); -for (const r_131 of _exprs380.values) {; -let _expr381 = r_131; -const r_132 = _expr381; -const r_133 = r_132.values[0] ?? { type: "null"}; -let _ty382 = r_133; -const r_134 = r_132.values[1] ?? { type: "null"}; -let _line383 = r_134; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 56), runtime.opNe(_ty382, ({ type: "string", value: "list" }))))) { -runtime.popCall(); -return { type: "null" }}; -const r_135 = _expr381; -const r_136 = r_135.values[0] ?? { type: "null"}; -const r_137 = r_135.values[1] ?? { type: "null"}; -const r_138 = r_135.values[2] ?? { type: "null"}; -let _s384 = r_138; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 58), runtime.opEq((runtime.info("compiler/emit_js.phi", 58), ((...args) => runtime.builtinLen(...args))(_s384)), ({ type: "int", value: 0 }))))) { -runtime.popCall(); -return { type: "null" }}; -const r_139 = _s384; -const r_140 = r_139.values[0] ?? { type: "null"}; -const r_141 = r_140.values[0] ?? { type: "null"}; -const r_142 = r_140.values[1] ?? { type: "null"}; -const r_143 = r_140.values[2] ?? { type: "null"}; -let _id385 = r_143; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 60), runtime.opEq(_id385, ({ type: "string", value: "fn" }))))) { -const r_144 = _s384; -const r_145 = r_144.values[0] ?? { type: "null"}; -const r_146 = r_144.values[1] ?? { type: "null"}; -const r_147 = r_146.values[0] ?? { type: "null"}; -const r_148 = r_146.values[1] ?? { type: "null"}; -const r_149 = r_146.values[2] ?? { type: "null"}; -let _ident386 = r_149; -const r_150 = r_144.values[2] ?? { type: "null"}; -const r_151 = r_150.values[0] ?? { type: "null"}; -const r_152 = r_150.values[1] ?? { type: "null"}; -const r_153 = r_150.values[2] ?? { type: "null"}; -let _params387 = r_153; -const r_154 = r_144.values[3] ?? { type: "null"}; -let _body388 = r_154; -(runtime.info("compiler/emit_js.phi", 62), _define_fn359(_ident386, _line383)); -}; -}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _emit_expr350(_expr389) { -runtime.pushCall("emit_expr", "compiler/emit_js.phi"); -const r_155 = _expr389; -const r_156 = r_155.values[0] ?? { type: "null"}; -let _ty390 = r_156; -const r_157 = r_155.values[1] ?? { type: "null"}; -let _line391 = r_157; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 69), runtime.opEq(_ty390, ({ type: "string", value: "list" }))))) { -(runtime.info("compiler/emit_js.phi", 70), _emit_list351(_expr389)); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 71), runtime.opEq(_ty390, ({ type: "string", value: "int" }))))) { -const r_158 = _expr389; -const r_159 = r_158.values[0] ?? { type: "null"}; -const r_160 = r_158.values[1] ?? { type: "null"}; -const r_161 = r_158.values[2] ?? { type: "null"}; -let _value392 = r_161; -(runtime.info("compiler/emit_js.phi", 73), _emit357((runtime.info("compiler/emit_js.phi", 73), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "({ type: \"int\", value: % })" }), _value392)))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 74), runtime.opEq(_ty390, ({ type: "string", value: "string" }))))) { -const r_162 = _expr389; -const r_163 = r_162.values[0] ?? { type: "null"}; -const r_164 = r_162.values[1] ?? { type: "null"}; -const r_165 = r_162.values[2] ?? { type: "null"}; -let _value393 = r_165; -(runtime.info("compiler/emit_js.phi", 76), _emit357((runtime.info("compiler/emit_js.phi", 76), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "({ type: \"string\", value: \"%\" })" }), (runtime.info("compiler/emit_js.phi", 76), _string_escape147(_value393)))))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 77), runtime.opEq(_ty390, ({ type: "string", value: "ident" }))))) { -const r_166 = _expr389; -const r_167 = r_166.values[0] ?? { type: "null"}; -const r_168 = r_166.values[1] ?? { type: "null"}; -const r_169 = r_166.values[2] ?? { type: "null"}; -let _value394 = r_169; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 80), runtime.opEq(_value394, ({ type: "string", value: "null" }))))) { -(runtime.info("compiler/emit_js.phi", 81), _emit357(({ type: "string", value: "({ type: \"null\" })" }))); -runtime.popCall(); -return { type: "null" }; -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 83), runtime.opEq(_value394, ({ type: "string", value: "false" }))))) { -(runtime.info("compiler/emit_js.phi", 84), _emit357(({ type: "string", value: "({ type: \"bool\", value: false })" }))); -runtime.popCall(); -return { type: "null" }; -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 86), runtime.opEq(_value394, ({ type: "string", value: "true" }))))) { -(runtime.info("compiler/emit_js.phi", 87), _emit357(({ type: "string", value: "({ type: \"bool\", value: true })" }))); -runtime.popCall(); -return { type: "null" }; -}}}; -const r_170 = (runtime.info("compiler/emit_js.phi", 91), _get_sym365(_value394)); -let _sym395 = r_170; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 92), runtime.opEq(_sym395, ({ type: "null" }))))) { -(runtime.info("compiler/emit_js.phi", 93), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "undefined symbol '%' on line %" }), _value394, _line391)); -}; -const r_171 = _sym395; -const r_172 = r_171.values[0] ?? { type: "null"}; -let _sym_id396 = r_172; -const r_173 = r_171.values[1] ?? { type: "null"}; -let _sym_ty397 = r_173; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 97), runtime.opEq(_sym_ty397, ({ type: "string", value: "builtin" }))))) { -const r_174 = _sym395; -const r_175 = r_174.values[0] ?? { type: "null"}; -const r_176 = r_174.values[1] ?? { type: "null"}; -const r_177 = r_174.values[2] ?? { type: "null"}; -let _id398 = r_177; -(runtime.info("compiler/emit_js.phi", 99), _emit357((runtime.info("compiler/emit_js.phi", 99), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "((...args) => runtime.%(...args))" }), _id398)))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 100), runtime.opEq(_sym_ty397, ({ type: "string", value: "fn" }))))) { -(runtime.info("compiler/emit_js.phi", 101), _emit357((runtime.info("compiler/emit_js.phi", 101), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "_%%" }), _value394, _sym_id396)))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 102), runtime.opEq(_sym_ty397, ({ type: "string", value: "param" }))))) { -(runtime.info("compiler/emit_js.phi", 103), _emit357((runtime.info("compiler/emit_js.phi", 103), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "_%%" }), _value394, _sym_id396)))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 104), runtime.opEq(_sym_ty397, ({ type: "string", value: "let" }))))) { -(runtime.info("compiler/emit_js.phi", 105), _emit357((runtime.info("compiler/emit_js.phi", 105), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "_%%" }), _value394, _sym_id396)))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 106), runtime.opEq(_sym_ty397, ({ type: "string", value: "imported" }))))) { -(runtime.info("compiler/emit_js.phi", 111), _emit357((runtime.info("compiler/emit_js.phi", 111), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "_%%" }), _value394, _sym_id396)))); -} else { -(runtime.info("compiler/emit_js.phi", 113), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "not implemented '%'" }), _sym_ty397)); -}}}}}; -} else { -(runtime.info("compiler/emit_js.phi", 116), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "unknown expr type '%' on line %" }), _ty390, _line391)); -}}}}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _emit_list351(_expr399) { -runtime.pushCall("emit_list", "compiler/emit_js.phi"); -const r_178 = _expr399; -const r_179 = r_178.values[0] ?? { type: "null"}; -let _ty400 = r_179; -const r_180 = r_178.values[1] ?? { type: "null"}; -let _line401 = r_180; -const r_181 = r_178.values[2] ?? { type: "null"}; -let _s402 = r_181; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 122), runtime.opEq((runtime.info("compiler/emit_js.phi", 122), ((...args) => runtime.builtinLen(...args))(_s402)), ({ type: "int", value: 0 }))))) { -(runtime.info("compiler/emit_js.phi", 123), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "illegal function on line %" }), _line401)); -}; -const r_182 = _s402; -const r_183 = r_182.values[0] ?? { type: "null"}; -const r_184 = r_183.values[0] ?? { type: "null"}; -let _id_ty403 = r_184; -const r_185 = r_183.values[1] ?? { type: "null"}; -const r_186 = r_183.values[2] ?? { type: "null"}; -let _id404 = r_186; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 126), runtime.opNe(_id_ty403, ({ type: "string", value: "ident" }))))) { -(runtime.info("compiler/emit_js.phi", 127), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "illegal function on line %" }), _line401)); -}; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 129), runtime.opEq(_id404, ({ type: "string", value: "import" }))))) { -const r_187 = _filename369; -let _outer_filename405 = r_187; -const r_188 = _s402; -const r_189 = r_188.values[0] ?? { type: "null"}; -const r_190 = r_188.values[1] ?? { type: "null"}; -const r_191 = r_190.values[0] ?? { type: "null"}; -const r_192 = r_190.values[1] ?? { type: "null"}; -const r_193 = r_190.values[2] ?? { type: "null"}; -let _inner_filename406 = r_193; -const r_194 = r_188.values[2] ?? { type: "null"}; -const r_195 = r_194.values[0] ?? { type: "null"}; -const r_196 = r_194.values[1] ?? { type: "null"}; -const r_197 = r_194.values[2] ?? { type: "null"}; -let _idents407 = r_197; -(_filename369 = _inner_filename406); -const r_198 = (runtime.info("compiler/emit_js.phi", 134), ((...args) => runtime.builtinReadTextFile(...args))(_filename369)); -let _text408 = r_198; -const r_199 = (runtime.info("compiler/emit_js.phi", 135), _tokenize199(_text408)); -let _tokens409 = r_199; -const r_200 = (runtime.info("compiler/emit_js.phi", 136), _Parser198(_tokens409)); -let _parser410 = r_200; -const r_201 = _parser410; -const r_202 = r_201.values[0] ?? { type: "null"}; -let _parse411 = r_202; -const r_203 = (runtime.info("compiler/emit_js.phi", 138), _parse411()); -let _ast412 = r_203; -const r_204 = (runtime.info("compiler/emit_js.phi", 139), _Emitter145(_ast412, _filename369)); -const r_205 = r_204.values[0] ?? { type: "null"}; -const r_206 = r_204.values[1] ?? { type: "null"}; -let _generate_imported413 = r_206; -(runtime.info("compiler/emit_js.phi", 141), _emit357((runtime.info("compiler/emit_js.phi", 141), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.setFile(\"%\");\n" }), _filename369)))); -const r_207 = _syms370; -let _outer_syms414 = r_207; -(_syms370 = (runtime.info("compiler/emit_js.phi", 144), _Syms278())); -for (const r_208 of _builtin_syms375.values) {; -const r_209 = r_208.values[0] ?? { type: "null"}; -let _ident415 = r_209; -const r_210 = r_208.values[1] ?? { type: "null"}; -let _builtin_id416 = r_210; -(runtime.info("compiler/emit_js.phi", 146), _define_builtin358(_ident415, _builtin_id416)); -}; -(runtime.info("compiler/emit_js.phi", 149), _enter_scope362()); -(runtime.info("compiler/emit_js.phi", 150), _discover_syms349(_ast412)); -(runtime.info("compiler/emit_js.phi", 151), _emit_exprs348(_ast412)); -const r_211 = (runtime.info("compiler/emit_js.phi", 152), _get_current_map366()); -let _sym_map417 = r_211; -(_syms370 = _outer_syms414); -(_filename369 = _outer_filename405); -(runtime.info("compiler/emit_js.phi", 157), _emit357((runtime.info("compiler/emit_js.phi", 157), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.setFile(\"%\");\n" }), _outer_filename405)))); -for (const r_212 of _idents407.values) {; -const r_213 = r_212.values[0] ?? { type: "null"}; -const r_214 = r_212.values[1] ?? { type: "null"}; -const r_215 = r_212.values[2] ?? { type: "null"}; -let _ident418 = r_215; -const r_216 = ({ type: "null" }); -let _sym419 = r_216; -for (const r_217 of _sym_map417.values) {; -const r_218 = r_217.values[0] ?? { type: "null"}; -let _sym_ident420 = r_218; -const r_219 = r_217.values[1] ?? { type: "null"}; -let _found_sym421 = r_219; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 162), runtime.opEq(_sym_ident420, _ident418)))) { -(_sym419 = _found_sym421); -break; -}; -}; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 167), runtime.opEq(_sym419, ({ type: "null" }))))) { -(runtime.info("compiler/emit_js.phi", 168), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "no symbol '%' from imported '%'" }), _ident418, _filename369)); -}; -const r_220 = _sym419; -const r_221 = r_220.values[0] ?? { type: "null"}; -const r_222 = r_220.values[1] ?? { type: "null"}; -let _sym_type422 = r_222; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 171), runtime.opEq(_sym_type422, ({ type: "string", value: "imported" }))))) { -(runtime.info("compiler/emit_js.phi", 172), _define_sym364(_ident418, _sym419)); -} else { -const r_223 = _sym419; -const r_224 = r_223.values[0] ?? { type: "null"}; -let _sym_id423 = r_224; -(runtime.info("compiler/emit_js.phi", 175), _define_sym364(_ident418, ({ type: "list", values: [_sym_id423, ({ type: "string", value: "imported" }), _sym419] }))); -}; -}; -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 178), runtime.opEq(_id404, ({ type: "string", value: "fn" }))))) { -const r_225 = _s402; -const r_226 = r_225.values[0] ?? { type: "null"}; -const r_227 = r_225.values[1] ?? { type: "null"}; -const r_228 = r_227.values[0] ?? { type: "null"}; -const r_229 = r_227.values[1] ?? { type: "null"}; -const r_230 = r_227.values[2] ?? { type: "null"}; -let _ident424 = r_230; -const r_231 = r_225.values[2] ?? { type: "null"}; -const r_232 = r_231.values[0] ?? { type: "null"}; -const r_233 = r_231.values[1] ?? { type: "null"}; -const r_234 = r_231.values[2] ?? { type: "null"}; -let _params425 = r_234; -const r_235 = r_225.values[3] ?? { type: "null"}; -let _body426 = r_235; -const r_236 = (runtime.info("compiler/emit_js.phi", 181), _get_sym365(_ident424)); -let _sym427 = r_236; -const r_237 = _sym427; -const r_238 = r_237.values[0] ?? { type: "null"}; -let _sym_id428 = r_238; -(runtime.info("compiler/emit_js.phi", 184), _emit357((runtime.info("compiler/emit_js.phi", 184), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "function _%%(" }), _ident424, _sym_id428)))); -(runtime.info("compiler/emit_js.phi", 186), _enter_scope362()); -const r_239 = ({ type: "bool", value: true }); -let _first429 = r_239; -for (const r_240 of _params425.values) {; -const r_241 = r_240.values[0] ?? { type: "null"}; -const r_242 = r_240.values[1] ?? { type: "null"}; -const r_243 = r_240.values[2] ?? { type: "null"}; -let _ident430 = r_243; -if (runtime.truthy(runtime.opNot(_first429))) { -(runtime.info("compiler/emit_js.phi", 191), _emit357(({ type: "string", value: ", " }))); -}; -(_first429 = ({ type: "bool", value: false })); -const r_244 = (runtime.info("compiler/emit_js.phi", 195), _define_param360(_ident430, _line401)); -let _sym_id431 = r_244; -(runtime.info("compiler/emit_js.phi", 196), _emit357((runtime.info("compiler/emit_js.phi", 196), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "_%%" }), _ident430, _sym_id431)))); -}; -(runtime.info("compiler/emit_js.phi", 200), _emit357(({ type: "string", value: ") {\n" }))); -(runtime.info("compiler/emit_js.phi", 201), _emit357((runtime.info("compiler/emit_js.phi", 201), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.pushCall(\"%\", \"%\");\n" }), _ident424, _filename369)))); -(runtime.info("compiler/emit_js.phi", 203), _emit_expr350(_body426)); -(runtime.info("compiler/emit_js.phi", 204), _emit357(({ type: "string", value: ";\nruntime.popCall();\nreturn { type: \"null\" };\n}" }))); -(runtime.info("compiler/emit_js.phi", 206), _leave_scope363()); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 207), runtime.opEq(_id404, ({ type: "string", value: "let" }))))) { -const r_245 = _s402; -const r_246 = r_245.values[0] ?? { type: "null"}; -const r_247 = r_245.values[1] ?? { type: "null"}; -let _pat432 = r_247; -const r_248 = r_245.values[2] ?? { type: "null"}; -let _expr433 = r_248; -const r_249 = (runtime.info("compiler/emit_js.phi", 209), _let_node_reg_count373()); -let _reg434 = r_249; -(runtime.info("compiler/emit_js.phi", 210), _let_node_reg_increment374()); -(runtime.info("compiler/emit_js.phi", 211), _emit357((runtime.info("compiler/emit_js.phi", 211), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "const r_% = " }), _reg434)))); -(runtime.info("compiler/emit_js.phi", 212), _emit_expr350(_expr433)); -(runtime.info("compiler/emit_js.phi", 213), _emit_let_node353(_pat432, _reg434)); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 214), runtime.opEq(_id404, ({ type: "string", value: "do" }))))) { -(runtime.info("compiler/emit_js.phi", 215), _enter_scope362()); -(runtime.info("compiler/emit_js.phi", 216), _discover_syms349((runtime.info("compiler/emit_js.phi", 216), _slice162(_s402, ({ type: "int", value: 1 }))))); -(runtime.info("compiler/emit_js.phi", 217), _emit_exprs348((runtime.info("compiler/emit_js.phi", 217), _slice162(_s402, ({ type: "int", value: 1 }))))); -(runtime.info("compiler/emit_js.phi", 218), _leave_scope363()); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 219), runtime.opEq(_id404, ({ type: "string", value: "for" }))))) { -const r_250 = _s402; -const r_251 = r_250.values[0] ?? { type: "null"}; -const r_252 = r_250.values[1] ?? { type: "null"}; -let _pat435 = r_252; -const r_253 = r_250.values[2] ?? { type: "null"}; -let _expr436 = r_253; -const r_254 = r_250.values[3] ?? { type: "null"}; -let _body437 = r_254; -const r_255 = (runtime.info("compiler/emit_js.phi", 222), _let_node_reg_count373()); -let _reg438 = r_255; -(runtime.info("compiler/emit_js.phi", 223), _let_node_reg_increment374()); -(runtime.info("compiler/emit_js.phi", 224), _emit357((runtime.info("compiler/emit_js.phi", 224), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "for (const r_% of " }), _reg438)))); -(runtime.info("compiler/emit_js.phi", 225), _emit_expr350(_expr436)); -(runtime.info("compiler/emit_js.phi", 226), _emit357(({ type: "string", value: ".values) {" }))); -(runtime.info("compiler/emit_js.phi", 228), _enter_scope362()); -(runtime.info("compiler/emit_js.phi", 229), _emit_let_node353(_pat435, _reg438)); -(runtime.info("compiler/emit_js.phi", 230), _enter_scope362()); -(runtime.info("compiler/emit_js.phi", 232), _emit357(({ type: "string", value: ";\n" }))); -(runtime.info("compiler/emit_js.phi", 233), _emit_expr350(_body437)); -(runtime.info("compiler/emit_js.phi", 234), _emit357(({ type: "string", value: "}" }))); -(runtime.info("compiler/emit_js.phi", 236), _leave_scope363()); -(runtime.info("compiler/emit_js.phi", 237), _leave_scope363()); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 238), runtime.opEq(_id404, ({ type: "string", value: "loop" }))))) { -const r_256 = _s402; -const r_257 = r_256.values[0] ?? { type: "null"}; -const r_258 = r_256.values[1] ?? { type: "null"}; -let _body439 = r_258; -(runtime.info("compiler/emit_js.phi", 240), _emit357(({ type: "string", value: "while (true) {\n" }))); -(runtime.info("compiler/emit_js.phi", 241), _emit_expr350(_body439)); -(runtime.info("compiler/emit_js.phi", 242), _emit357(({ type: "string", value: "}" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 243), runtime.opEq(_id404, ({ type: "string", value: "if" }))))) { -const r_259 = _s402; -const r_260 = r_259.values[0] ?? { type: "null"}; -const r_261 = r_259.values[1] ?? { type: "null"}; -let _cond440 = r_261; -const r_262 = r_259.values[2] ?? { type: "null"}; -let _truthy441 = r_262; -const r_263 = r_259.values[3] ?? { type: "null"}; -let _falsy442 = r_263; -(runtime.info("compiler/emit_js.phi", 245), _emit357(({ type: "string", value: "if (runtime.truthy(" }))); -(runtime.info("compiler/emit_js.phi", 246), _emit_expr350(_cond440)); -(runtime.info("compiler/emit_js.phi", 247), _emit357(({ type: "string", value: ")) {\n" }))); -(runtime.info("compiler/emit_js.phi", 248), _emit_expr350(_truthy441)); -(runtime.info("compiler/emit_js.phi", 249), _emit357(({ type: "string", value: "}" }))); -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 250), runtime.opNe(_falsy442, ({ type: "null" }))))) { -(runtime.info("compiler/emit_js.phi", 251), _emit357(({ type: "string", value: " else {\n" }))); -(runtime.info("compiler/emit_js.phi", 252), _emit_expr350(_falsy442)); -(runtime.info("compiler/emit_js.phi", 253), _emit357(({ type: "string", value: "}" }))); -}; -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 255), runtime.opEq(_id404, ({ type: "string", value: "return" }))))) { -const r_264 = _s402; -const r_265 = r_264.values[0] ?? { type: "null"}; -const r_266 = r_264.values[1] ?? { type: "null"}; -let _value443 = r_266; -(runtime.info("compiler/emit_js.phi", 257), _emit357(({ type: "string", value: "runtime.popCall();\n" }))); -(runtime.info("compiler/emit_js.phi", 258), _emit357(({ type: "string", value: "return " }))); -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 259), runtime.opNe(_value443, ({ type: "null" }))))) { -(runtime.info("compiler/emit_js.phi", 260), _emit_expr350(_value443)); -} else { -(runtime.info("compiler/emit_js.phi", 262), _emit357(({ type: "string", value: "{ type: \"null\" }" }))); -}; -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 264), runtime.opEq(_id404, ({ type: "string", value: "break" }))))) { -const r_267 = _s402; -const r_268 = r_267.values[0] ?? { type: "null"}; -const r_269 = r_267.values[1] ?? { type: "null"}; -let _value444 = r_269; -(runtime.info("compiler/emit_js.phi", 266), _emit357(({ type: "string", value: "break" }))); -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 267), runtime.opNe(_value444, ({ type: "null" }))))) { -(runtime.info("compiler/emit_js.phi", 268), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "not implemented" }))); -}; -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 270), runtime.opEq(_id404, ({ type: "string", value: "call" }))))) { -const r_270 = _s402; -const r_271 = r_270.values[0] ?? { type: "null"}; -const r_272 = r_270.values[1] ?? { type: "null"}; -let _callee445 = r_272; -const r_273 = (runtime.info("compiler/emit_js.phi", 272), _slice162(_s402, ({ type: "int", value: 2 }))); -let _args446 = r_273; -(runtime.info("compiler/emit_js.phi", 273), _emit357((runtime.info("compiler/emit_js.phi", 273), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(%, " }), (runtime.info("compiler/emit_js.phi", 273), _rt_info355(_line401)))))); -(runtime.info("compiler/emit_js.phi", 274), _emit_expr350(_callee445)); -(runtime.info("compiler/emit_js.phi", 275), _emit357(({ type: "string", value: "(" }))); -const r_274 = ({ type: "bool", value: true }); -let _first447 = r_274; -for (const r_275 of _args446.values) {; -let _arg448 = r_275; -if (runtime.truthy(runtime.opNot(_first447))) { -(runtime.info("compiler/emit_js.phi", 280), _emit357(({ type: "string", value: ", " }))); -}; -(_first447 = ({ type: "bool", value: false })); -(runtime.info("compiler/emit_js.phi", 284), _emit_expr350(_arg448)); -}; -(runtime.info("compiler/emit_js.phi", 287), _emit357(({ type: "string", value: "))" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 288), runtime.opEq(_id404, ({ type: "string", value: "list" }))))) { -(runtime.info("compiler/emit_js.phi", 289), _emit_list_literal352((runtime.info("compiler/emit_js.phi", 289), _slice162(_s402, ({ type: "int", value: 1 }))))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 290), runtime.opEq(_id404, ({ type: "string", value: "=" }))))) { -(runtime.info("compiler/emit_js.phi", 291), _emit_assign_expr356(_s402, _line401, ({ type: "string", value: "=" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 292), runtime.opEq(_id404, ({ type: "string", value: "+=" }))))) { -(runtime.info("compiler/emit_js.phi", 293), _emit_assign_expr356(_s402, _line401, ({ type: "string", value: "+" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 294), runtime.opEq(_id404, ({ type: "string", value: "-=" }))))) { -(runtime.info("compiler/emit_js.phi", 295), _emit_assign_expr356(_s402, _line401, ({ type: "string", value: "-" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 296), runtime.opEq(_id404, ({ type: "string", value: "or" }))))) { -const r_276 = _s402; -const r_277 = r_276.values[0] ?? { type: "null"}; -const r_278 = r_276.values[1] ?? { type: "null"}; -let _left449 = r_278; -const r_279 = r_276.values[2] ?? { type: "null"}; -let _right450 = r_279; -(runtime.info("compiler/emit_js.phi", 298), _emit357((runtime.info("compiler/emit_js.phi", 298), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(%" }), (runtime.info("compiler/emit_js.phi", 298), _rt_info355(_line401)), _line401)))); -(runtime.info("compiler/emit_js.phi", 299), _emit357(({ type: "string", value: ", { type: \"bool\", value: runtime.truthy(" }))); -(runtime.info("compiler/emit_js.phi", 300), _emit_expr350(_left449)); -(runtime.info("compiler/emit_js.phi", 301), _emit357(({ type: "string", value: ") || runtime.truthy(" }))); -(runtime.info("compiler/emit_js.phi", 302), _emit_expr350(_right450)); -(runtime.info("compiler/emit_js.phi", 303), _emit357(({ type: "string", value: ") })" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 304), runtime.opEq(_id404, ({ type: "string", value: "and" }))))) { -const r_280 = _s402; -const r_281 = r_280.values[0] ?? { type: "null"}; -const r_282 = r_280.values[1] ?? { type: "null"}; -let _left451 = r_282; -const r_283 = r_280.values[2] ?? { type: "null"}; -let _right452 = r_283; -(runtime.info("compiler/emit_js.phi", 306), _emit357((runtime.info("compiler/emit_js.phi", 306), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(%" }), (runtime.info("compiler/emit_js.phi", 306), _rt_info355(_line401)), _line401)))); -(runtime.info("compiler/emit_js.phi", 307), _emit357(({ type: "string", value: ", { type: \"bool\", value: runtime.truthy(" }))); -(runtime.info("compiler/emit_js.phi", 308), _emit_expr350(_left451)); -(runtime.info("compiler/emit_js.phi", 309), _emit357(({ type: "string", value: ") && runtime.truthy(" }))); -(runtime.info("compiler/emit_js.phi", 310), _emit_expr350(_right452)); -(runtime.info("compiler/emit_js.phi", 311), _emit357(({ type: "string", value: ") })" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 312), runtime.opEq(_id404, ({ type: "string", value: "==" }))))) { -(runtime.info("compiler/emit_js.phi", 313), _emit_binary_op354(_s402, ({ type: "string", value: "opEq" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 314), runtime.opEq(_id404, ({ type: "string", value: "!=" }))))) { -(runtime.info("compiler/emit_js.phi", 315), _emit_binary_op354(_s402, ({ type: "string", value: "opNe" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 316), runtime.opEq(_id404, ({ type: "string", value: "<" }))))) { -(runtime.info("compiler/emit_js.phi", 317), _emit_binary_op354(_s402, ({ type: "string", value: "opLt" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 318), runtime.opEq(_id404, ({ type: "string", value: ">" }))))) { -(runtime.info("compiler/emit_js.phi", 319), _emit_binary_op354(_s402, ({ type: "string", value: "opGt" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 320), runtime.opEq(_id404, ({ type: "string", value: "<=" }))))) { -(runtime.info("compiler/emit_js.phi", 321), _emit_binary_op354(_s402, ({ type: "string", value: "opLte" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 322), runtime.opEq(_id404, ({ type: "string", value: ">=" }))))) { -(runtime.info("compiler/emit_js.phi", 323), _emit_binary_op354(_s402, ({ type: "string", value: "opGte" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 324), runtime.opEq(_id404, ({ type: "string", value: "+" }))))) { -(runtime.info("compiler/emit_js.phi", 325), _emit_binary_op354(_s402, ({ type: "string", value: "opAdd" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 326), runtime.opEq(_id404, ({ type: "string", value: "-" }))))) { -(runtime.info("compiler/emit_js.phi", 327), _emit_binary_op354(_s402, ({ type: "string", value: "opSub" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 328), runtime.opEq(_id404, ({ type: "string", value: "not" }))))) { -const r_284 = _s402; -const r_285 = r_284.values[0] ?? { type: "null"}; -const r_286 = r_284.values[1] ?? { type: "null"}; -let _expr453 = r_286; -(runtime.info("compiler/emit_js.phi", 330), _emit357(({ type: "string", value: "runtime.opNot(" }))); -(runtime.info("compiler/emit_js.phi", 331), _emit_expr350(_expr453)); -(runtime.info("compiler/emit_js.phi", 332), _emit357(({ type: "string", value: ")" }))); -} else { -const r_287 = _s402; -const r_288 = r_287.values[0] ?? { type: "null"}; -let _callee454 = r_288; -const r_289 = (runtime.info("compiler/emit_js.phi", 335), _slice162(_s402, ({ type: "int", value: 1 }))); -let _args455 = r_289; -(runtime.info("compiler/emit_js.phi", 336), _emit357((runtime.info("compiler/emit_js.phi", 336), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(%, " }), (runtime.info("compiler/emit_js.phi", 336), _rt_info355(_line401)), _line401)))); -(runtime.info("compiler/emit_js.phi", 337), _emit_expr350(_callee454)); -(runtime.info("compiler/emit_js.phi", 338), _emit357(({ type: "string", value: "(" }))); -const r_290 = ({ type: "bool", value: true }); -let _first456 = r_290; -for (const r_291 of _args455.values) {; -let _arg457 = r_291; -if (runtime.truthy(runtime.opNot(_first456))) { -(runtime.info("compiler/emit_js.phi", 343), _emit357(({ type: "string", value: ", " }))); -}; -(_first456 = ({ type: "bool", value: false })); -(runtime.info("compiler/emit_js.phi", 347), _emit_expr350(_arg457)); -}; -(runtime.info("compiler/emit_js.phi", 350), _emit357(({ type: "string", value: "))" }))); -}}}}}}}}}}}}}}}}}}}}}}}}}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _emit_list_literal352(_s458) { -runtime.pushCall("emit_list_literal", "compiler/emit_js.phi"); -(runtime.info("compiler/emit_js.phi", 355), _emit357(({ type: "string", value: "({ type: \"list\", values: [" }))); -const r_292 = ({ type: "bool", value: true }); -let _first459 = r_292; -for (const r_293 of _s458.values) {; -let _e460 = r_293; -if (runtime.truthy(runtime.opNot(_first459))) { -(runtime.info("compiler/emit_js.phi", 359), _emit357(({ type: "string", value: ", " }))); -}; -(_first459 = ({ type: "bool", value: false })); -(runtime.info("compiler/emit_js.phi", 363), _emit_expr350(_e460)); -}; -(runtime.info("compiler/emit_js.phi", 365), _emit357(({ type: "string", value: "] })" }))); -; -runtime.popCall(); -return { type: "null" }; -}; -function _emit_let_node353(_pat461, _base_reg462) { -runtime.pushCall("emit_let_node", "compiler/emit_js.phi"); -const r_294 = _pat461; -const r_295 = r_294.values[0] ?? { type: "null"}; -let _pat_ty463 = r_295; -const r_296 = r_294.values[1] ?? { type: "null"}; -let _line464 = r_296; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 370), runtime.opEq(_pat_ty463, ({ type: "string", value: "ident" }))))) { -const r_297 = _pat461; -const r_298 = r_297.values[0] ?? { type: "null"}; -const r_299 = r_297.values[1] ?? { type: "null"}; -const r_300 = r_297.values[2] ?? { type: "null"}; -let _ident465 = r_300; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 373), runtime.opEq(_ident465, ({ type: "string", value: "_" }))))) { -runtime.popCall(); -return { type: "null" }}; -const r_301 = (runtime.info("compiler/emit_js.phi", 375), _define_let361(_ident465, _line464)); -let _sym_id466 = r_301; -(runtime.info("compiler/emit_js.phi", 376), _emit357((runtime.info("compiler/emit_js.phi", 376), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: ";\nlet _%% = r_%" }), _ident465, _sym_id466, _base_reg462)))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 377), runtime.opEq(_pat_ty463, ({ type: "string", value: "list" }))))) { -const r_302 = _pat461; -const r_303 = r_302.values[0] ?? { type: "null"}; -const r_304 = r_302.values[1] ?? { type: "null"}; -const r_305 = r_302.values[2] ?? { type: "null"}; -let _pats467 = r_305; -const r_306 = ({ type: "int", value: 0 }); -let _i468 = r_306; -for (const r_307 of _pats467.values) {; -let _pat469 = r_307; -const r_308 = (runtime.info("compiler/emit_js.phi", 382), _let_node_reg_count373()); -let _reg470 = r_308; -(runtime.info("compiler/emit_js.phi", 383), _let_node_reg_increment374()); -(runtime.info("compiler/emit_js.phi", 384), _emit357((runtime.info("compiler/emit_js.phi", 384), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: ";\nconst r_% = r_%.values[%] ?? { type: \"null\"}" }), _reg470, _base_reg462, _i468)))); -(runtime.info("compiler/emit_js.phi", 388), _emit_let_node353(_pat469, _reg470)); -(_i468 = runtime.opAdd(_i468, ({ type: "int", value: 1 }))); -}; -} else { -(runtime.info("compiler/emit_js.phi", 392), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "malformed pattern on line %" }), _line464)); -}}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _emit_binary_op354(_s471, _id472) { -runtime.pushCall("emit_binary_op", "compiler/emit_js.phi"); -const r_309 = _s471; -const r_310 = r_309.values[0] ?? { type: "null"}; -const r_311 = r_310.values[0] ?? { type: "null"}; -const r_312 = r_310.values[1] ?? { type: "null"}; -let _line473 = r_312; -const r_313 = r_310.values[2] ?? { type: "null"}; -const r_314 = r_309.values[1] ?? { type: "null"}; -let _left474 = r_314; -const r_315 = r_309.values[2] ?? { type: "null"}; -let _right475 = r_315; -(runtime.info("compiler/emit_js.phi", 398), _emit357((runtime.info("compiler/emit_js.phi", 398), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(%, runtime.%(" }), (runtime.info("compiler/emit_js.phi", 398), _rt_info355(_line473)), _id472)))); -(runtime.info("compiler/emit_js.phi", 399), _emit_expr350(_left474)); -(runtime.info("compiler/emit_js.phi", 400), _emit357(({ type: "string", value: ", " }))); -(runtime.info("compiler/emit_js.phi", 401), _emit_expr350(_right475)); -(runtime.info("compiler/emit_js.phi", 402), _emit357(({ type: "string", value: "))" }))); -; -runtime.popCall(); -return { type: "null" }; -}; -function _rt_info355(_line476) { -runtime.pushCall("rt_info", "compiler/emit_js.phi"); -runtime.popCall(); -return (runtime.info("compiler/emit_js.phi", 406), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.info(\"%\", %)" }), _filename369, _line476)); -; -runtime.popCall(); -return { type: "null" }; -}; -function _emit_assign_expr356(_s477, _line478, _id479) { -runtime.pushCall("emit_assign_expr", "compiler/emit_js.phi"); -const r_316 = _s477; -const r_317 = r_316.values[0] ?? { type: "null"}; -const r_318 = r_316.values[1] ?? { type: "null"}; -const r_319 = r_318.values[0] ?? { type: "null"}; -let _target_type480 = r_319; -const r_320 = r_316.values[2] ?? { type: "null"}; -let _expr481 = r_320; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 411), runtime.opNe(_target_type480, ({ type: "string", value: "ident" }))))) { -(runtime.info("compiler/emit_js.phi", 412), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "cannot assign to expression on line %" }), _line478)); -}; -const r_321 = _s477; -const r_322 = r_321.values[0] ?? { type: "null"}; -const r_323 = r_321.values[1] ?? { type: "null"}; -const r_324 = r_323.values[0] ?? { type: "null"}; -const r_325 = r_323.values[1] ?? { type: "null"}; -const r_326 = r_323.values[2] ?? { type: "null"}; -let _ident482 = r_326; -const r_327 = (runtime.info("compiler/emit_js.phi", 415), _get_sym365(_ident482)); -let _sym483 = r_327; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 416), runtime.opEq(_sym483, ({ type: "null" }))))) { -(runtime.info("compiler/emit_js.phi", 417), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "could not find symbol '%' on line %" }), _ident482, _line478)); -}; -const r_328 = _sym483; -const r_329 = r_328.values[0] ?? { type: "null"}; -let _sym_id484 = r_329; -const r_330 = r_328.values[1] ?? { type: "null"}; -let _sym_type485 = r_330; -const r_331 = r_328.values[2] ?? { type: "null"}; -let _sym_ident486 = r_331; -const r_332 = r_328.values[3] ?? { type: "null"}; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 420), runtime.opEq(_sym_type485, ({ type: "string", value: "let" }))))) { -(runtime.info("compiler/emit_js.phi", 421), _emit357((runtime.info("compiler/emit_js.phi", 421), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(_%% = " }), _sym_ident486, _sym_id484)))); -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 422), runtime.opEq(_id479, ({ type: "string", value: "=" }))))) { -(runtime.info("compiler/emit_js.phi", 423), _emit_expr350(_expr481)); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 424), runtime.opEq(_id479, ({ type: "string", value: "+" }))))) { -(runtime.info("compiler/emit_js.phi", 425), _emit357((runtime.info("compiler/emit_js.phi", 425), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.opAdd(_%%, " }), _sym_ident486, _sym_id484)))); -(runtime.info("compiler/emit_js.phi", 426), _emit_expr350(_expr481)); -(runtime.info("compiler/emit_js.phi", 427), _emit357(({ type: "string", value: ")" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 428), runtime.opEq(_id479, ({ type: "string", value: "-" }))))) { -(runtime.info("compiler/emit_js.phi", 429), _emit357((runtime.info("compiler/emit_js.phi", 429), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.opSub(_%%, " }), _sym_ident486, _sym_id484)))); -(runtime.info("compiler/emit_js.phi", 430), _emit_expr350(_expr481)); -(runtime.info("compiler/emit_js.phi", 431), _emit357(({ type: "string", value: ")" }))); -} else { -(runtime.info("compiler/emit_js.phi", 433), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "not implemented" }))); -}}}; -(runtime.info("compiler/emit_js.phi", 435), _emit357(({ type: "string", value: ")" }))); -} else { -(runtime.info("compiler/emit_js.phi", 437), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "cannot assign to symbol '%' on line %" }), _sym_ident486, _line478)); -}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _emit357(_str487) { -runtime.pushCall("emit", "compiler/emit_js.phi"); -(runtime.info("compiler/emit_js.phi", 442), ((...args) => runtime.builtinPush(...args))(_output368, _str487)); -; -runtime.popCall(); -return { type: "null" }; -}; -function _define_builtin358(_ident488, _builtin_id489) { -runtime.pushCall("define_builtin", "compiler/emit_js.phi"); -const r_333 = (runtime.info("compiler/emit_js.phi", 446), _sym_id_count371()); -let _sym_id490 = r_333; -(runtime.info("compiler/emit_js.phi", 447), _sym_id_increment372()); -(runtime.info("compiler/emit_js.phi", 449), _define_sym364(_ident488, ({ type: "list", values: [_sym_id490, ({ type: "string", value: "builtin" }), _builtin_id489] }))); -runtime.popCall(); -return _sym_id490; -; -runtime.popCall(); -return { type: "null" }; -}; -function _define_fn359(_ident491, _line492) { -runtime.pushCall("define_fn", "compiler/emit_js.phi"); -const r_334 = (runtime.info("compiler/emit_js.phi", 454), _sym_id_count371()); -let _sym_id493 = r_334; -(runtime.info("compiler/emit_js.phi", 455), _sym_id_increment372()); -(runtime.info("compiler/emit_js.phi", 457), _define_sym364(_ident491, ({ type: "list", values: [_sym_id493, ({ type: "string", value: "fn" }), _ident491, _line492] }))); -runtime.popCall(); -return _sym_id493; -; -runtime.popCall(); -return { type: "null" }; -}; -function _define_param360(_ident494, _line495) { -runtime.pushCall("define_param", "compiler/emit_js.phi"); -const r_335 = (runtime.info("compiler/emit_js.phi", 462), _sym_id_count371()); -let _sym_id496 = r_335; -(runtime.info("compiler/emit_js.phi", 463), _sym_id_increment372()); -(runtime.info("compiler/emit_js.phi", 465), _define_sym364(_ident494, ({ type: "list", values: [_sym_id496, ({ type: "string", value: "param" }), _ident494, _line495] }))); -runtime.popCall(); -return _sym_id496; -; -runtime.popCall(); -return { type: "null" }; -}; -function _define_let361(_ident497, _line498) { -runtime.pushCall("define_let", "compiler/emit_js.phi"); -const r_336 = (runtime.info("compiler/emit_js.phi", 470), _sym_id_count371()); -let _sym_id499 = r_336; -(runtime.info("compiler/emit_js.phi", 471), _sym_id_increment372()); -(runtime.info("compiler/emit_js.phi", 473), _define_sym364(_ident497, ({ type: "list", values: [_sym_id499, ({ type: "string", value: "let" }), _ident497, _line498] }))); -runtime.popCall(); -return _sym_id499; -; -runtime.popCall(); -return { type: "null" }; -}; -function _enter_scope362() { -runtime.pushCall("enter_scope", "compiler/emit_js.phi"); -const r_337 = _syms370; -const r_338 = r_337.values[0] ?? { type: "null"}; -let _enter_scope500 = r_338; -(runtime.info("compiler/emit_js.phi", 480), _enter_scope500()); -; -runtime.popCall(); -return { type: "null" }; -}; -function _leave_scope363() { -runtime.pushCall("leave_scope", "compiler/emit_js.phi"); -const r_339 = _syms370; -const r_340 = r_339.values[0] ?? { type: "null"}; -const r_341 = r_339.values[1] ?? { type: "null"}; -let _leave_scope501 = r_341; -(runtime.info("compiler/emit_js.phi", 484), _leave_scope501()); -; -runtime.popCall(); -return { type: "null" }; -}; -function _define_sym364(_ident502, _sym503) { -runtime.pushCall("define_sym", "compiler/emit_js.phi"); -const r_342 = _syms370; -const r_343 = r_342.values[0] ?? { type: "null"}; -const r_344 = r_342.values[1] ?? { type: "null"}; -const r_345 = r_342.values[2] ?? { type: "null"}; -let _define_sym504 = r_345; -runtime.popCall(); -return (runtime.info("compiler/emit_js.phi", 488), _define_sym504(_ident502, _sym503)); -; -runtime.popCall(); -return { type: "null" }; -}; -function _get_sym365(_ident505) { -runtime.pushCall("get_sym", "compiler/emit_js.phi"); -const r_346 = _syms370; -const r_347 = r_346.values[0] ?? { type: "null"}; -const r_348 = r_346.values[1] ?? { type: "null"}; -const r_349 = r_346.values[2] ?? { type: "null"}; -const r_350 = r_346.values[3] ?? { type: "null"}; -let _get_sym506 = r_350; -runtime.popCall(); -return (runtime.info("compiler/emit_js.phi", 492), _get_sym506(_ident505)); -; -runtime.popCall(); -return { type: "null" }; -}; -function _get_current_map366() { -runtime.pushCall("get_current_map", "compiler/emit_js.phi"); -const r_351 = _syms370; -const r_352 = r_351.values[0] ?? { type: "null"}; -const r_353 = r_351.values[1] ?? { type: "null"}; -const r_354 = r_351.values[2] ?? { type: "null"}; -const r_355 = r_351.values[3] ?? { type: "null"}; -const r_356 = r_351.values[4] ?? { type: "null"}; -let _get_current_map507 = r_356; -runtime.popCall(); -return (runtime.info("compiler/emit_js.phi", 496), _get_current_map507()); -; -runtime.popCall(); -return { type: "null" }; -}; -function _print_syms367() { -runtime.pushCall("print_syms", "compiler/emit_js.phi"); -const r_357 = _syms370; -const r_358 = r_357.values[0] ?? { type: "null"}; -const r_359 = r_357.values[1] ?? { type: "null"}; -const r_360 = r_357.values[2] ?? { type: "null"}; -const r_361 = r_357.values[3] ?? { type: "null"}; -const r_362 = r_357.values[4] ?? { type: "null"}; -const r_363 = r_357.values[5] ?? { type: "null"}; -let _print_syms508 = r_363; -(runtime.info("compiler/emit_js.phi", 500), _print_syms508()); -; -runtime.popCall(); -return { type: "null" }; -}; -runtime.popCall(); -return ({ type: "list", values: [_generate347] }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _Counter146() { -runtime.pushCall("Counter", "compiler/emit_js.phi"); -const r_364 = ({ type: "int", value: 0 }); -let _counter511 = r_364; -function _count509() { -runtime.pushCall("count", "compiler/emit_js.phi"); -runtime.popCall(); -return _counter511; -; -runtime.popCall(); -return { type: "null" }; -}; -function _increment510() { -runtime.pushCall("increment", "compiler/emit_js.phi"); -(_counter511 = runtime.opAdd(_counter511, ({ type: "int", value: 1 }))); -; -runtime.popCall(); -return { type: "null" }; -}; -runtime.popCall(); -return ({ type: "list", values: [_count509, _increment510] }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _string_escape147(_str512) { -runtime.pushCall("string_escape", "compiler/emit_js.phi"); -const r_365 = (runtime.info("compiler/emit_js.phi", 521), ((...args) => runtime.builtinLen(...args))(_str512)); -let _str_len513 = r_365; -const r_366 = ({ type: "int", value: 0 }); -let _i514 = r_366; -const r_367 = ({ type: "string", value: "" }); -let _result515 = r_367; -while (true) { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 525), runtime.opGte(_i514, _str_len513)))) { -break}; -const r_368 = (runtime.info("compiler/emit_js.phi", 526), ((...args) => runtime.builtinAt(...args))(_str512, _i514)); -let _ch516 = r_368; -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 527), runtime.opEq(_ch516, ({ type: "string", value: "\\" }))))) { -(_result515 = runtime.opAdd(_result515, ({ type: "string", value: "\\\\" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 529), runtime.opEq(_ch516, ({ type: "string", value: "\"" }))))) { -(_result515 = runtime.opAdd(_result515, ({ type: "string", value: "\\\"" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 531), runtime.opEq(_ch516, ({ type: "string", value: "\t" }))))) { -(_result515 = runtime.opAdd(_result515, ({ type: "string", value: "\\t" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 533), runtime.opEq(_ch516, ({ type: "string", value: "\r" }))))) { -(_result515 = runtime.opAdd(_result515, ({ type: "string", value: "\\r" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 535), runtime.opEq(_ch516, ({ type: "string", value: "\n" }))))) { -(_result515 = runtime.opAdd(_result515, ({ type: "string", value: "\\n" }))); -} else { -if (runtime.truthy((runtime.info("compiler/emit_js.phi", 537), runtime.opEq(_ch516, ({ type: "string", value: "\n" }))))) { -(_result515 = runtime.opAdd(_result515, ({ type: "string", value: "\\0" }))); -} else { -(_result515 = runtime.opAdd(_result515, _ch516)); -}}}}}}; -(_i514 = runtime.opAdd(_i514, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); -return _result515; +(runtime.info("stdlib.phi", 122), ((...args) => runtime.builtinPush(...args))(_map75, ({ type: "list", values: [_key76, _value77] }))); ; runtime.popCall(); return { type: "null" }; }; runtime.setFile("compile.phi"); ; -function _print_expr14(_expr517, _depth518) { -runtime.pushCall("print_expr", "compile.phi"); -const r_369 = _expr517; -const r_370 = r_369.values[0] ?? { type: "null"}; -let _ty519 = r_370; -const r_371 = r_369.values[1] ?? { type: "null"}; -let _line520 = r_371; -const r_372 = r_369.values[2] ?? { type: "null"}; -let _value521 = r_372; -if (runtime.truthy((runtime.info("compile.phi", 7), runtime.opEq(_ty519, ({ type: "string", value: "list" }))))) { -(runtime.info("compile.phi", 8), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "%(% %" }), (runtime.info("compile.phi", 8), _indent32(_depth518)), _ty519, _line520)); -for (const r_373 of _value521.values) {; -let _e522 = r_373; -(runtime.info("compile.phi", 10), _print_expr14(_e522, (runtime.info("compile.phi", 10), runtime.opAdd(_depth518, ({ type: "int", value: 1 }))))); +runtime.setFile("compiler/parse.phi"); +; +function _Parser94(_tokens96) { +runtime.pushCall("Parser", "compiler/parse.phi"); +const r_25 = ({ type: "int", value: 0 }); +let _i103 = r_25; +const r_26 = (runtime.info("compiler/parse.phi", 5), ((...args) => runtime.builtinAt(...args))(_tokens96, _i103)); +let _tok104 = r_26; +function _parse97() { +runtime.pushCall("parse", "compiler/parse.phi"); +const r_27 = ({ type: "list", values: [] }); +let _exprs105 = r_27; +while (true) { +if (runtime.truthy((runtime.info("compiler/parse.phi", 10), _done102()))) { +break}; +(runtime.info("compiler/parse.phi", 11), ((...args) => runtime.builtinPush(...args))(_exprs105, (runtime.info("compiler/parse.phi", 11), _parse_expr98()))); }; -(runtime.info("compile.phi", 12), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "%)" }), (runtime.info("compile.phi", 12), _indent32(_depth518)))); +runtime.popCall(); +return _exprs105; +; +runtime.popCall(); +return { type: "null" }; +}; +function _parse_expr98() { +runtime.pushCall("parse_expr", "compiler/parse.phi"); +const r_28 = _tok104; +const r_29 = r_28.values[0] ?? { type: "null"}; +let _ty106 = r_29; +const r_30 = r_28.values[1] ?? { type: "null"}; +let _line107 = r_30; +const r_31 = r_28.values[2] ?? { type: "null"}; +let _value108 = r_31; +if (runtime.truthy((runtime.info("compiler/parse.phi", 18), _eat99(({ type: "string", value: "(" }))))) { +const r_32 = ({ type: "list", values: [] }); +let _values109 = r_32; +while (true) { +if (runtime.truthy((runtime.info("compiler/parse.phi", 21), _test101(({ type: "string", value: ")" }))))) { +break}; +(runtime.info("compiler/parse.phi", 22), ((...args) => runtime.builtinPush(...args))(_values109, (runtime.info("compiler/parse.phi", 22), _parse_expr98()))); +}; +if (runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 24), _eat99(({ type: "string", value: ")" })))))) { +(runtime.info("compiler/parse.phi", 25), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "expected ')' on line %" }), (runtime.info("compiler/parse.phi", 25), ((...args) => runtime.builtinAt(...args))(_tok104, ({ type: "int", value: 1 }))))); +}; +runtime.popCall(); +return ({ type: "list", values: [({ type: "string", value: "list" }), _line107, _values109] }); } else { -(runtime.info("compile.phi", 14), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "%%" }), (runtime.info("compile.phi", 14), _indent32(_depth518)), _expr517)); +if (runtime.truthy((runtime.info("compiler/parse.phi", 28), _eat99(({ type: "string", value: "string" }))))) { +runtime.popCall(); +return ({ type: "list", values: [({ type: "string", value: "string" }), _line107, _value108] }); +} else { +if (runtime.truthy((runtime.info("compiler/parse.phi", 30), _eat99(({ type: "string", value: "int" }))))) { +runtime.popCall(); +return ({ type: "list", values: [({ type: "string", value: "int" }), _line107, (runtime.info("compiler/parse.phi", 31), ((...args) => runtime.builtinStringToInt(...args))(_value108))] }); +} else { +if (runtime.truthy((runtime.info("compiler/parse.phi", 32), _eat99(({ type: "string", value: "ident" }))))) { +runtime.popCall(); +return ({ type: "list", values: [({ type: "string", value: "ident" }), _line107, _value108] }); +} else { +(runtime.info("compiler/parse.phi", 35), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "expected expression, got '%' on line %" }), _ty106, _line107)); +}}}}; +; +runtime.popCall(); +return { type: "null" }; +}; +function _eat99(_pat110) { +runtime.pushCall("eat", "compiler/parse.phi"); +if (runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 40), _test101(_pat110))))) { +runtime.popCall(); +return ({ type: "bool", value: false })}; +(runtime.info("compiler/parse.phi", 41), _step100()); +runtime.popCall(); +return ({ type: "bool", value: true }); +; +runtime.popCall(); +return { type: "null" }; +}; +function _step100() { +runtime.pushCall("step", "compiler/parse.phi"); +(_i103 = runtime.opAdd(_i103, ({ type: "int", value: 1 }))); +if (runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 47), _done102())))) { +const r_33 = (runtime.info("compiler/parse.phi", 48), ((...args) => runtime.builtinAt(...args))(_tokens96, _i103)); +let _new_tok111 = r_33; +(_tok104 = _new_tok111); }; ; runtime.popCall(); return { type: "null" }; }; -const r_374 = (runtime.info("compile.phi", 18), ((...args) => runtime.builtinGetArgs(...args))()); -const r_375 = r_374.values[0] ?? { type: "null"}; -let _input_filename523 = r_375; -const r_376 = r_374.values[1] ?? { type: "null"}; -let _output_filename524 = r_376; -(runtime.info("compile.phi", 20), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "compiling '%'..." }), _input_filename523)); -const r_377 = (runtime.info("compile.phi", 21), ((...args) => runtime.builtinReadTextFile(...args))(_input_filename523)); -let _text525 = r_377; -const r_378 = (runtime.info("compile.phi", 23), _tokenize66(_text525)); -let _tokens526 = r_378; -const r_379 = (runtime.info("compile.phi", 24), _Parser65(_tokens526)); -let _parser527 = r_379; -const r_380 = _parser527; -const r_381 = r_380.values[0] ?? { type: "null"}; -let _parse528 = r_381; -const r_382 = (runtime.info("compile.phi", 26), _parse528()); -let _ast529 = r_382; -const r_383 = (runtime.info("compile.phi", 27), _Emitter145(_ast529, _input_filename523)); -let _emitter530 = r_383; -const r_384 = _emitter530; -const r_385 = r_384.values[0] ?? { type: "null"}; -let _emit531 = r_385; -const r_386 = (runtime.info("compile.phi", 29), _emit531()); -let _js_code532 = r_386; -(runtime.info("compile.phi", 34), ((...args) => runtime.builtinWriteTextFile(...args))(_output_filename524, _js_code532)); -(runtime.info("compile.phi", 35), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "written '%'!" }), _output_filename524)); +function _test101(_pat112) { +runtime.pushCall("test", "compiler/parse.phi"); +if (runtime.truthy((runtime.info("compiler/parse.phi", 54), _done102()))) { +runtime.popCall(); +return ({ type: "bool", value: false })}; +const r_34 = _tok104; +const r_35 = r_34.values[0] ?? { type: "null"}; +let _ty113 = r_35; +runtime.popCall(); +return (runtime.info("compiler/parse.phi", 56), runtime.opEq(_pat112, _ty113)); +; +runtime.popCall(); +return { type: "null" }; +}; +function _done102() { +runtime.pushCall("done", "compiler/parse.phi"); +runtime.popCall(); +return (runtime.info("compiler/parse.phi", 60), runtime.opGte(_i103, (runtime.info("compiler/parse.phi", 60), ((...args) => runtime.builtinLen(...args))(_tokens96)))); +; +runtime.popCall(); +return { type: "null" }; +}; +runtime.popCall(); +return ({ type: "list", values: [_parse97] }); +; +runtime.popCall(); +return { type: "null" }; +}; +function _tokenize95(_text114) { +runtime.pushCall("tokenize", "compiler/parse.phi"); +const r_36 = (runtime.info("compiler/parse.phi", 67), ((...args) => runtime.builtinLen(...args))(_text114)); +let _text_len115 = r_36; +const r_37 = ({ type: "list", values: [] }); +let _tokens116 = r_37; +const r_38 = ({ type: "int", value: 0 }); +let _i117 = r_38; +const r_39 = ({ type: "int", value: 1 }); +let _line118 = r_39; +const r_40 = (runtime.info("compiler/parse.phi", 73), runtime.opAdd(({ type: "string", value: "abcdefghijklmnopqrstuvwxyz" }), ({ type: "string", value: "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+-*/%&|=?!<>'_" }))); +let _ident_chars119 = r_40; +while (true) { +if (runtime.truthy((runtime.info("compiler/parse.phi", 77), runtime.opGte(_i117, _text_len115)))) { +break}; +const r_41 = (runtime.info("compiler/parse.phi", 79), ((...args) => runtime.builtinAt(...args))(_text114, _i117)); +let _ch120 = r_41; +if (runtime.truthy((runtime.info("compiler/parse.phi", 81), _contains31(({ type: "string", value: " \t\r\n" }), _ch120)))) { +if (runtime.truthy((runtime.info("compiler/parse.phi", 82), runtime.opEq(_ch120, ({ type: "string", value: "\n" }))))) { +(_line118 = runtime.opAdd(_line118, ({ type: "int", value: 1 }))); +}; +(_i117 = runtime.opAdd(_i117, ({ type: "int", value: 1 }))); +} else { +if (runtime.truthy((runtime.info("compiler/parse.phi", 86), _slice_eq30(_text114, _i117, ({ type: "string", value: "//" }))))) { +while (true) { +if (runtime.truthy((runtime.info("compiler/parse.phi", 88), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 88), runtime.opGte(_i117, _text_len115))) || runtime.truthy((runtime.info("compiler/parse.phi", 88), runtime.opEq((runtime.info("compiler/parse.phi", 88), ((...args) => runtime.builtinAt(...args))(_text114, _i117)), ({ type: "string", value: "\n" })))) }))) { +break; +}; +(_i117 = runtime.opAdd(_i117, ({ type: "int", value: 1 }))); +}; +} else { +if (runtime.truthy((runtime.info("compiler/parse.phi", 93), _contains31(({ type: "string", value: "()" }), _ch120)))) { +(runtime.info("compiler/parse.phi", 94), ((...args) => runtime.builtinPush(...args))(_tokens116, ({ type: "list", values: [_ch120, _line118] }))); +(_i117 = runtime.opAdd(_i117, ({ type: "int", value: 1 }))); +} else { +if (runtime.truthy((runtime.info("compiler/parse.phi", 96), runtime.opEq(_ch120, ({ type: "string", value: "\"" }))))) { +const r_42 = ({ type: "string", value: "" }); +let _value121 = r_42; +(_i117 = runtime.opAdd(_i117, ({ type: "int", value: 1 }))); +(_ch120 = (runtime.info("compiler/parse.phi", 99), ((...args) => runtime.builtinAt(...args))(_text114, _i117))); +while (true) { +if (runtime.truthy((runtime.info("compiler/parse.phi", 101), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 101), runtime.opGte(_i117, _text_len115))) || runtime.truthy((runtime.info("compiler/parse.phi", 101), runtime.opEq(_ch120, ({ type: "string", value: "\"" })))) }))) { +break; +}; +if (runtime.truthy((runtime.info("compiler/parse.phi", 104), runtime.opEq(_ch120, ({ type: "string", value: "\\" }))))) { +(_i117 = runtime.opAdd(_i117, ({ type: "int", value: 1 }))); +if (runtime.truthy((runtime.info("compiler/parse.phi", 106), runtime.opGte(_i117, _text_len115)))) { +break; +}; +(_ch120 = (runtime.info("compiler/parse.phi", 109), ((...args) => runtime.builtinAt(...args))(_text114, _i117))); +if (runtime.truthy((runtime.info("compiler/parse.phi", 110), runtime.opEq(_ch120, ({ type: "string", value: "t" }))))) { +(_value121 = runtime.opAdd(_value121, ({ type: "string", value: "\t" }))); +} else { +if (runtime.truthy((runtime.info("compiler/parse.phi", 112), runtime.opEq(_ch120, ({ type: "string", value: "r" }))))) { +(_value121 = runtime.opAdd(_value121, ({ type: "string", value: "\r" }))); +} else { +if (runtime.truthy((runtime.info("compiler/parse.phi", 114), runtime.opEq(_ch120, ({ type: "string", value: "n" }))))) { +(_value121 = runtime.opAdd(_value121, ({ type: "string", value: "\n" }))); +} else { +if (runtime.truthy((runtime.info("compiler/parse.phi", 116), runtime.opEq(_ch120, ({ type: "string", value: "0" }))))) { +(_value121 = runtime.opAdd(_value121, ({ type: "string", value: "\n" }))); +} else { +(_value121 = runtime.opAdd(_value121, _ch120)); +}}}}; +} else { +(_value121 = runtime.opAdd(_value121, _ch120)); +}; +(_i117 = runtime.opAdd(_i117, ({ type: "int", value: 1 }))); +(_ch120 = (runtime.info("compiler/parse.phi", 125), ((...args) => runtime.builtinAt(...args))(_text114, _i117))); +}; +if (runtime.truthy((runtime.info("compiler/parse.phi", 127), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 127), runtime.opGte(_i117, _text_len115))) || runtime.truthy((runtime.info("compiler/parse.phi", 127), runtime.opNe(_ch120, ({ type: "string", value: "\"" })))) }))) { +(runtime.info("compiler/parse.phi", 128), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "expected '\"' on line %" }), _line118)); +}; +(_i117 = runtime.opAdd(_i117, ({ type: "int", value: 1 }))); +(runtime.info("compiler/parse.phi", 131), ((...args) => runtime.builtinPush(...args))(_tokens116, ({ type: "list", values: [({ type: "string", value: "string" }), _line118, _value121] }))); +} else { +if (runtime.truthy((runtime.info("compiler/parse.phi", 132), _contains31(({ type: "string", value: "0123456789" }), _ch120)))) { +const r_43 = ({ type: "string", value: "" }); +let _value122 = r_43; +while (true) { +(_ch120 = (runtime.info("compiler/parse.phi", 135), ((...args) => runtime.builtinAt(...args))(_text114, _i117))); +if (runtime.truthy((runtime.info("compiler/parse.phi", 136), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 136), runtime.opGte(_i117, _text_len115))) || runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 136), _contains31(({ type: "string", value: "0123456789" }), _ch120)))) }))) { +break; +}; +(_value122 = runtime.opAdd(_value122, _ch120)); +(_i117 = runtime.opAdd(_i117, ({ type: "int", value: 1 }))); +}; +(runtime.info("compiler/parse.phi", 142), ((...args) => runtime.builtinPush(...args))(_tokens116, ({ type: "list", values: [({ type: "string", value: "int" }), _line118, _value122] }))); +} else { +if (runtime.truthy((runtime.info("compiler/parse.phi", 143), _contains31(_ident_chars119, _ch120)))) { +const r_44 = ({ type: "string", value: "" }); +let _value123 = r_44; +while (true) { +(_ch120 = (runtime.info("compiler/parse.phi", 146), ((...args) => runtime.builtinAt(...args))(_text114, _i117))); +if (runtime.truthy((runtime.info("compiler/parse.phi", 147), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 147), runtime.opGte(_i117, _text_len115))) || runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 147), _contains31(_ident_chars119, _ch120)))) }))) { +break; +}; +(_value123 = runtime.opAdd(_value123, _ch120)); +(_i117 = runtime.opAdd(_i117, ({ type: "int", value: 1 }))); +}; +(runtime.info("compiler/parse.phi", 153), ((...args) => runtime.builtinPush(...args))(_tokens116, ({ type: "list", values: [({ type: "string", value: "ident" }), _line118, _value123] }))); +} else { +(runtime.info("compiler/parse.phi", 155), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "illegal char '%'" }), _ch120)); +(_i117 = runtime.opAdd(_i117, ({ type: "int", value: 1 }))); +}}}}}}; +}; +runtime.popCall(); +return _tokens116; +; +runtime.popCall(); +return { type: "null" }; +}; +runtime.setFile("compile.phi"); +; +runtime.setFile("compiler/emit_js.phi"); +; +; +runtime.setFile("compiler/syms.phi"); +; +function _Syms155() { +runtime.pushCall("Syms", "compiler/syms.phi"); +const r_45 = ({ type: "list", values: [({ type: "null" }), (runtime.info("compiler/syms.phi", 4), _map36())] }); +let _syms164 = r_45; +function _enter_scope156() { +runtime.pushCall("enter_scope", "compiler/syms.phi"); +(_syms164 = ({ type: "list", values: [_syms164, (runtime.info("compiler/syms.phi", 7), _map36())] })); +; +runtime.popCall(); +return { type: "null" }; +}; +function _leave_scope157() { +runtime.pushCall("leave_scope", "compiler/syms.phi"); +const r_46 = _syms164; +const r_47 = r_46.values[0] ?? { type: "null"}; +let _parent165 = r_47; +const r_48 = r_46.values[1] ?? { type: "null"}; +(_syms164 = _parent165); +; +runtime.popCall(); +return { type: "null" }; +}; +function _define_sym158(_ident166, _sym167) { +runtime.pushCall("define_sym", "compiler/syms.phi"); +const r_49 = _syms164; +const r_50 = r_49.values[0] ?? { type: "null"}; +const r_51 = r_49.values[1] ?? { type: "null"}; +let _map168 = r_51; +(runtime.info("compiler/syms.phi", 17), _map_set39(_map168, _ident166, _sym167)); +; +runtime.popCall(); +return { type: "null" }; +}; +function _find_sym159(_syms169, _ident170) { +runtime.pushCall("find_sym", "compiler/syms.phi"); +const r_52 = _syms169; +const r_53 = r_52.values[0] ?? { type: "null"}; +let _parent171 = r_53; +const r_54 = r_52.values[1] ?? { type: "null"}; +let _map172 = r_54; +if (runtime.truthy((runtime.info("compiler/syms.phi", 22), _map_has37(_map172, _ident170)))) { +runtime.popCall(); +return (runtime.info("compiler/syms.phi", 23), _map_get38(_map172, _ident170)); +}; +if (runtime.truthy((runtime.info("compiler/syms.phi", 25), runtime.opNe(_parent171, ({ type: "null" }))))) { +runtime.popCall(); +return (runtime.info("compiler/syms.phi", 26), _find_sym159(_parent171, _ident170)); +}; +runtime.popCall(); +return ({ type: "null" }); +; +runtime.popCall(); +return { type: "null" }; +}; +function _get_sym160(_ident173) { +runtime.pushCall("get_sym", "compiler/syms.phi"); +runtime.popCall(); +return (runtime.info("compiler/syms.phi", 32), _find_sym159(_syms164, _ident173)); +; +runtime.popCall(); +return { type: "null" }; +}; +function _get_current_map161() { +runtime.pushCall("get_current_map", "compiler/syms.phi"); +const r_55 = _syms164; +const r_56 = r_55.values[0] ?? { type: "null"}; +const r_57 = r_55.values[1] ?? { type: "null"}; +let _map174 = r_57; +runtime.popCall(); +return _map174; +; +runtime.popCall(); +return { type: "null" }; +}; +function _print_syms_node162(_syms175, _depth176) { +runtime.pushCall("print_syms_node", "compiler/syms.phi"); +const r_58 = _syms175; +const r_59 = r_58.values[0] ?? { type: "null"}; +let _parent177 = r_59; +const r_60 = r_58.values[1] ?? { type: "null"}; +let _map178 = r_60; +for (const r_61 of _map178.values) {; +const r_62 = r_61.values[0] ?? { type: "null"}; +let _ident179 = r_62; +const r_63 = r_61.values[1] ?? { type: "null"}; +let _sym180 = r_63; +(runtime.info("compiler/syms.phi", 43), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "%- %: %" }), (runtime.info("compiler/syms.phi", 43), _indent32(_depth176)), _ident179, _sym180)); +}; +if (runtime.truthy((runtime.info("compiler/syms.phi", 45), runtime.opNe(_parent177, ({ type: "null" }))))) { +(runtime.info("compiler/syms.phi", 46), _print_syms_node162(_parent177, (runtime.info("compiler/syms.phi", 46), runtime.opAdd(_depth176, ({ type: "int", value: 1 }))))); +}; +; +runtime.popCall(); +return { type: "null" }; +}; +function _print_syms163() { +runtime.pushCall("print_syms", "compiler/syms.phi"); +(runtime.info("compiler/syms.phi", 51), _print_syms_node162(_syms164, ({ type: "int", value: 0 }))); +; +runtime.popCall(); +return { type: "null" }; +}; +runtime.popCall(); +return ({ type: "list", values: [_enter_scope156, _leave_scope157, _define_sym158, _get_sym160, _get_current_map161, _print_syms163] }); +; +runtime.popCall(); +return { type: "null" }; +}; +runtime.setFile("compiler/emit_js.phi"); +; +function _JsEmitter138(_ast181, _initial_filename182) { +runtime.pushCall("JsEmitter", "compiler/emit_js.phi"); +const r_64 = ({ type: "list", values: [] }); +let _output204 = r_64; +const r_65 = _initial_filename182; +let _filename205 = r_65; +const r_66 = (runtime.info("compiler/emit_js.phi", 13), _Syms155()); +let _syms206 = r_66; +const r_67 = (runtime.info("compiler/emit_js.phi", 15), _Counter139()); +const r_68 = r_67.values[0] ?? { type: "null"}; +let _sym_id_count207 = r_68; +const r_69 = r_67.values[1] ?? { type: "null"}; +let _sym_id_increment208 = r_69; +const r_70 = (runtime.info("compiler/emit_js.phi", 16), _Counter139()); +const r_71 = r_70.values[0] ?? { type: "null"}; +let _let_node_reg_count209 = r_71; +const r_72 = r_70.values[1] ?? { type: "null"}; +let _let_node_reg_increment210 = r_72; +const r_73 = ({ type: "list", values: [_filename205] }); +let _import_stack211 = r_73; +const r_74 = (runtime.info("compiler/emit_js.phi", 19), _map36()); +let _imported_files212 = r_74; +const r_75 = ({ type: "list", values: [({ type: "list", values: [({ type: "string", value: "format" }), ({ type: "string", value: "builtinFormat" })] }), ({ type: "list", values: [({ type: "string", value: "print" }), ({ type: "string", value: "builtinPrint" })] }), ({ type: "list", values: [({ type: "string", value: "println" }), ({ type: "string", value: "builtinPrintln" })] }), ({ type: "list", values: [({ type: "string", value: "panic" }), ({ type: "string", value: "builtinPanic" })] }), ({ type: "list", values: [({ type: "string", value: "read_text_file" }), ({ type: "string", value: "builtinReadTextFile" })] }), ({ type: "list", values: [({ type: "string", value: "write_text_file" }), ({ type: "string", value: "builtinWriteTextFile" })] }), ({ type: "list", values: [({ type: "string", value: "push" }), ({ type: "string", value: "builtinPush" })] }), ({ type: "list", values: [({ type: "string", value: "at" }), ({ type: "string", value: "builtinAt" })] }), ({ type: "list", values: [({ type: "string", value: "set" }), ({ type: "string", value: "builtinSet" })] }), ({ type: "list", values: [({ type: "string", value: "len" }), ({ type: "string", value: "builtinLen" })] }), ({ type: "list", values: [({ type: "string", value: "string_to_int" }), ({ type: "string", value: "builtinStringToInt" })] }), ({ type: "list", values: [({ type: "string", value: "char_code" }), ({ type: "string", value: "builtinCharCode" })] }), ({ type: "list", values: [({ type: "string", value: "strings_join" }), ({ type: "string", value: "builtinStringsJoin" })] }), ({ type: "list", values: [({ type: "string", value: "get_args" }), ({ type: "string", value: "builtinGetArgs" })] })] }); +let _builtin_syms213 = r_75; +function _generate183() { +runtime.pushCall("generate", "compiler/emit_js.phi"); +(runtime.info("compiler/emit_js.phi", 39), _emit193(({ type: "string", value: "#!/usr/bin/env node\n" }))); +(runtime.info("compiler/emit_js.phi", 40), _emit193(({ type: "string", value: "import { Runtime } from \"./runtime.js\";\n" }))); +(runtime.info("compiler/emit_js.phi", 41), _emit193((runtime.info("compiler/emit_js.phi", 41), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "const runtime = new Runtime(\"%\");\n" }), _filename205)))); +for (const r_76 of _builtin_syms213.values) {; +const r_77 = r_76.values[0] ?? { type: "null"}; +let _ident214 = r_77; +const r_78 = r_76.values[1] ?? { type: "null"}; +let _builtin_id215 = r_78; +(runtime.info("compiler/emit_js.phi", 44), _define_builtin194(_ident214, _builtin_id215)); +}; +(runtime.info("compiler/emit_js.phi", 47), _enter_scope198()); +(runtime.info("compiler/emit_js.phi", 48), _discover_syms185(_ast181)); +(runtime.info("compiler/emit_js.phi", 49), _emit_exprs184(_ast181)); +runtime.popCall(); +return (runtime.info("compiler/emit_js.phi", 50), ((...args) => runtime.builtinStringsJoin(...args))(_output204)); +; +runtime.popCall(); +return { type: "null" }; +}; +function _emit_exprs184(_exprs216) { +runtime.pushCall("emit_exprs", "compiler/emit_js.phi"); +for (const r_79 of _exprs216.values) {; +let _expr217 = r_79; +(runtime.info("compiler/emit_js.phi", 55), _emit_expr186(_expr217)); +(runtime.info("compiler/emit_js.phi", 56), _emit193(({ type: "string", value: ";\n" }))); +}; +; +runtime.popCall(); +return { type: "null" }; +}; +function _discover_syms185(_exprs218) { +runtime.pushCall("discover_syms", "compiler/emit_js.phi"); +for (const r_80 of _exprs218.values) {; +let _expr219 = r_80; +const r_81 = _expr219; +const r_82 = r_81.values[0] ?? { type: "null"}; +let _ty220 = r_82; +const r_83 = r_81.values[1] ?? { type: "null"}; +let _line221 = r_83; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 63), runtime.opNe(_ty220, ({ type: "string", value: "list" }))))) { +runtime.popCall(); +return { type: "null" }}; +const r_84 = _expr219; +const r_85 = r_84.values[0] ?? { type: "null"}; +const r_86 = r_84.values[1] ?? { type: "null"}; +const r_87 = r_84.values[2] ?? { type: "null"}; +let _s222 = r_87; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 65), runtime.opEq((runtime.info("compiler/emit_js.phi", 65), ((...args) => runtime.builtinLen(...args))(_s222)), ({ type: "int", value: 0 }))))) { +runtime.popCall(); +return { type: "null" }}; +const r_88 = _s222; +const r_89 = r_88.values[0] ?? { type: "null"}; +const r_90 = r_89.values[0] ?? { type: "null"}; +const r_91 = r_89.values[1] ?? { type: "null"}; +const r_92 = r_89.values[2] ?? { type: "null"}; +let _id223 = r_92; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 67), runtime.opEq(_id223, ({ type: "string", value: "fn" }))))) { +const r_93 = _s222; +const r_94 = r_93.values[0] ?? { type: "null"}; +const r_95 = r_93.values[1] ?? { type: "null"}; +const r_96 = r_95.values[0] ?? { type: "null"}; +const r_97 = r_95.values[1] ?? { type: "null"}; +const r_98 = r_95.values[2] ?? { type: "null"}; +let _ident224 = r_98; +const r_99 = r_93.values[2] ?? { type: "null"}; +const r_100 = r_99.values[0] ?? { type: "null"}; +const r_101 = r_99.values[1] ?? { type: "null"}; +const r_102 = r_99.values[2] ?? { type: "null"}; +let _params225 = r_102; +const r_103 = r_93.values[3] ?? { type: "null"}; +let _body226 = r_103; +(runtime.info("compiler/emit_js.phi", 69), _define_fn195(_ident224, _line221)); +}; +}; +; +runtime.popCall(); +return { type: "null" }; +}; +function _emit_expr186(_expr227) { +runtime.pushCall("emit_expr", "compiler/emit_js.phi"); +const r_104 = _expr227; +const r_105 = r_104.values[0] ?? { type: "null"}; +let _ty228 = r_105; +const r_106 = r_104.values[1] ?? { type: "null"}; +let _line229 = r_106; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 76), runtime.opEq(_ty228, ({ type: "string", value: "list" }))))) { +(runtime.info("compiler/emit_js.phi", 77), _emit_list187(_expr227)); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 78), runtime.opEq(_ty228, ({ type: "string", value: "int" }))))) { +const r_107 = _expr227; +const r_108 = r_107.values[0] ?? { type: "null"}; +const r_109 = r_107.values[1] ?? { type: "null"}; +const r_110 = r_107.values[2] ?? { type: "null"}; +let _value230 = r_110; +(runtime.info("compiler/emit_js.phi", 80), _emit193((runtime.info("compiler/emit_js.phi", 80), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "({ type: \"int\", value: % })" }), _value230)))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 81), runtime.opEq(_ty228, ({ type: "string", value: "string" }))))) { +const r_111 = _expr227; +const r_112 = r_111.values[0] ?? { type: "null"}; +const r_113 = r_111.values[1] ?? { type: "null"}; +const r_114 = r_111.values[2] ?? { type: "null"}; +let _value231 = r_114; +(runtime.info("compiler/emit_js.phi", 83), _emit193((runtime.info("compiler/emit_js.phi", 83), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "({ type: \"string\", value: \"%\" })" }), (runtime.info("compiler/emit_js.phi", 83), _string_escape140(_value231)))))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 84), runtime.opEq(_ty228, ({ type: "string", value: "ident" }))))) { +const r_115 = _expr227; +const r_116 = r_115.values[0] ?? { type: "null"}; +const r_117 = r_115.values[1] ?? { type: "null"}; +const r_118 = r_115.values[2] ?? { type: "null"}; +let _value232 = r_118; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 87), runtime.opEq(_value232, ({ type: "string", value: "null" }))))) { +(runtime.info("compiler/emit_js.phi", 88), _emit193(({ type: "string", value: "({ type: \"null\" })" }))); +runtime.popCall(); +return { type: "null" }; +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 90), runtime.opEq(_value232, ({ type: "string", value: "false" }))))) { +(runtime.info("compiler/emit_js.phi", 91), _emit193(({ type: "string", value: "({ type: \"bool\", value: false })" }))); +runtime.popCall(); +return { type: "null" }; +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 93), runtime.opEq(_value232, ({ type: "string", value: "true" }))))) { +(runtime.info("compiler/emit_js.phi", 94), _emit193(({ type: "string", value: "({ type: \"bool\", value: true })" }))); +runtime.popCall(); +return { type: "null" }; +}}}; +const r_119 = (runtime.info("compiler/emit_js.phi", 98), _get_sym201(_value232)); +let _sym233 = r_119; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 99), runtime.opEq(_sym233, ({ type: "null" }))))) { +(runtime.info("compiler/emit_js.phi", 100), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "undefined symbol '%' on line %" }), _value232, _line229)); +}; +const r_120 = _sym233; +const r_121 = r_120.values[0] ?? { type: "null"}; +let _sym_id234 = r_121; +const r_122 = r_120.values[1] ?? { type: "null"}; +let _sym_ty235 = r_122; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 104), runtime.opEq(_sym_ty235, ({ type: "string", value: "builtin" }))))) { +const r_123 = _sym233; +const r_124 = r_123.values[0] ?? { type: "null"}; +const r_125 = r_123.values[1] ?? { type: "null"}; +const r_126 = r_123.values[2] ?? { type: "null"}; +let _id236 = r_126; +(runtime.info("compiler/emit_js.phi", 106), _emit193((runtime.info("compiler/emit_js.phi", 106), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "((...args) => runtime.%(...args))" }), _id236)))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 107), runtime.opEq(_sym_ty235, ({ type: "string", value: "fn" }))))) { +(runtime.info("compiler/emit_js.phi", 108), _emit193((runtime.info("compiler/emit_js.phi", 108), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "_%%" }), _value232, _sym_id234)))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 109), runtime.opEq(_sym_ty235, ({ type: "string", value: "param" }))))) { +(runtime.info("compiler/emit_js.phi", 110), _emit193((runtime.info("compiler/emit_js.phi", 110), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "_%%" }), _value232, _sym_id234)))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 111), runtime.opEq(_sym_ty235, ({ type: "string", value: "let" }))))) { +(runtime.info("compiler/emit_js.phi", 112), _emit193((runtime.info("compiler/emit_js.phi", 112), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "_%%" }), _value232, _sym_id234)))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 113), runtime.opEq(_sym_ty235, ({ type: "string", value: "imported" }))))) { +(runtime.info("compiler/emit_js.phi", 118), _emit193((runtime.info("compiler/emit_js.phi", 118), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "_%%" }), _value232, _sym_id234)))); +} else { +(runtime.info("compiler/emit_js.phi", 120), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "not implemented '%'" }), _sym_ty235)); +}}}}}; +} else { +(runtime.info("compiler/emit_js.phi", 123), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "unknown expr type '%' on line %" }), _ty228, _line229)); +}}}}; +; +runtime.popCall(); +return { type: "null" }; +}; +function _emit_list187(_expr237) { +runtime.pushCall("emit_list", "compiler/emit_js.phi"); +const r_127 = _expr237; +const r_128 = r_127.values[0] ?? { type: "null"}; +let _ty238 = r_128; +const r_129 = r_127.values[1] ?? { type: "null"}; +let _line239 = r_129; +const r_130 = r_127.values[2] ?? { type: "null"}; +let _s240 = r_130; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 129), runtime.opEq((runtime.info("compiler/emit_js.phi", 129), ((...args) => runtime.builtinLen(...args))(_s240)), ({ type: "int", value: 0 }))))) { +(runtime.info("compiler/emit_js.phi", 130), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "illegal function on line %" }), _line239)); +}; +const r_131 = _s240; +const r_132 = r_131.values[0] ?? { type: "null"}; +const r_133 = r_132.values[0] ?? { type: "null"}; +let _id_ty241 = r_133; +const r_134 = r_132.values[1] ?? { type: "null"}; +const r_135 = r_132.values[2] ?? { type: "null"}; +let _id242 = r_135; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 133), runtime.opNe(_id_ty241, ({ type: "string", value: "ident" }))))) { +(runtime.info("compiler/emit_js.phi", 134), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "illegal function on line %" }), _line239)); +}; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 136), runtime.opEq(_id242, ({ type: "string", value: "import" }))))) { +const r_136 = _s240; +const r_137 = r_136.values[0] ?? { type: "null"}; +const r_138 = r_136.values[1] ?? { type: "null"}; +const r_139 = r_138.values[0] ?? { type: "null"}; +const r_140 = r_138.values[1] ?? { type: "null"}; +const r_141 = r_138.values[2] ?? { type: "null"}; +let _inner_filename243 = r_141; +const r_142 = r_136.values[2] ?? { type: "null"}; +const r_143 = r_142.values[0] ?? { type: "null"}; +const r_144 = r_142.values[1] ?? { type: "null"}; +const r_145 = r_142.values[2] ?? { type: "null"}; +let _idents244 = r_145; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 139), _list_contains35(_import_stack211, _inner_filename243)))) { +(runtime.info("compiler/emit_js.phi", 140), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "circular dependendy: '%' imports '%'" }), _filename205, _inner_filename243)); +}; +(runtime.info("compiler/emit_js.phi", 142), _list_push33(_import_stack211, _inner_filename243)); +const r_146 = ({ type: "null" }); +let _sym_map245 = r_146; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 146), _map_has37(_imported_files212, _inner_filename243)))) { +(_sym_map245 = (runtime.info("compiler/emit_js.phi", 147), _map_get38(_imported_files212, _inner_filename243))); +} else { +(runtime.info("compiler/emit_js.phi", 149), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "compiling '%'" }), _inner_filename243)); +const r_147 = _filename205; +let _outer_filename246 = r_147; +(_filename205 = _inner_filename243); +const r_148 = (runtime.info("compiler/emit_js.phi", 153), ((...args) => runtime.builtinReadTextFile(...args))(_filename205)); +let _text247 = r_148; +const r_149 = (runtime.info("compiler/emit_js.phi", 154), _tokenize95(_text247)); +let _tokens248 = r_149; +const r_150 = (runtime.info("compiler/emit_js.phi", 155), _Parser94(_tokens248)); +let _parser249 = r_150; +const r_151 = _parser249; +const r_152 = r_151.values[0] ?? { type: "null"}; +let _parse250 = r_152; +const r_153 = (runtime.info("compiler/emit_js.phi", 157), _parse250()); +let _ast251 = r_153; +(runtime.info("compiler/emit_js.phi", 159), _emit193((runtime.info("compiler/emit_js.phi", 159), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.setFile(\"%\");\n" }), _filename205)))); +const r_154 = _syms206; +let _outer_syms252 = r_154; +(_syms206 = (runtime.info("compiler/emit_js.phi", 162), _Syms155())); +for (const r_155 of _builtin_syms213.values) {; +const r_156 = r_155.values[0] ?? { type: "null"}; +let _ident253 = r_156; +const r_157 = r_155.values[1] ?? { type: "null"}; +let _builtin_id254 = r_157; +(runtime.info("compiler/emit_js.phi", 164), _define_builtin194(_ident253, _builtin_id254)); +}; +(runtime.info("compiler/emit_js.phi", 167), _enter_scope198()); +(runtime.info("compiler/emit_js.phi", 168), _discover_syms185(_ast251)); +(runtime.info("compiler/emit_js.phi", 169), _emit_exprs184(_ast251)); +(_sym_map245 = (runtime.info("compiler/emit_js.phi", 170), _get_current_map202())); +(runtime.info("compiler/emit_js.phi", 171), _map_set39(_imported_files212, _filename205, _sym_map245)); +(_syms206 = _outer_syms252); +(_filename205 = _outer_filename246); +(runtime.info("compiler/emit_js.phi", 176), _emit193((runtime.info("compiler/emit_js.phi", 176), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.setFile(\"%\");\n" }), _outer_filename246)))); +}; +(runtime.info("compiler/emit_js.phi", 178), _list_pop34(_import_stack211)); +for (const r_158 of _idents244.values) {; +const r_159 = r_158.values[0] ?? { type: "null"}; +const r_160 = r_158.values[1] ?? { type: "null"}; +const r_161 = r_158.values[2] ?? { type: "null"}; +let _ident255 = r_161; +const r_162 = ({ type: "null" }); +let _sym256 = r_162; +for (const r_163 of _sym_map245.values) {; +const r_164 = r_163.values[0] ?? { type: "null"}; +let _sym_ident257 = r_164; +const r_165 = r_163.values[1] ?? { type: "null"}; +let _found_sym258 = r_165; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 183), runtime.opEq(_sym_ident257, _ident255)))) { +(_sym256 = _found_sym258); +break; +}; +}; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 188), runtime.opEq(_sym256, ({ type: "null" }))))) { +(runtime.info("compiler/emit_js.phi", 189), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "no symbol '%' from imported '%'" }), _ident255, _inner_filename243)); +}; +const r_166 = _sym256; +const r_167 = r_166.values[0] ?? { type: "null"}; +const r_168 = r_166.values[1] ?? { type: "null"}; +let _sym_type259 = r_168; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 192), runtime.opEq(_sym_type259, ({ type: "string", value: "imported" }))))) { +(runtime.info("compiler/emit_js.phi", 193), _define_sym200(_ident255, _sym256)); +} else { +const r_169 = _sym256; +const r_170 = r_169.values[0] ?? { type: "null"}; +let _sym_id260 = r_170; +(runtime.info("compiler/emit_js.phi", 196), _define_sym200(_ident255, ({ type: "list", values: [_sym_id260, ({ type: "string", value: "imported" }), _sym256] }))); +}; +}; +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 199), runtime.opEq(_id242, ({ type: "string", value: "fn" }))))) { +const r_171 = _s240; +const r_172 = r_171.values[0] ?? { type: "null"}; +const r_173 = r_171.values[1] ?? { type: "null"}; +const r_174 = r_173.values[0] ?? { type: "null"}; +const r_175 = r_173.values[1] ?? { type: "null"}; +const r_176 = r_173.values[2] ?? { type: "null"}; +let _ident261 = r_176; +const r_177 = r_171.values[2] ?? { type: "null"}; +const r_178 = r_177.values[0] ?? { type: "null"}; +const r_179 = r_177.values[1] ?? { type: "null"}; +const r_180 = r_177.values[2] ?? { type: "null"}; +let _params262 = r_180; +const r_181 = r_171.values[3] ?? { type: "null"}; +let _body263 = r_181; +const r_182 = (runtime.info("compiler/emit_js.phi", 202), _get_sym201(_ident261)); +let _sym264 = r_182; +const r_183 = _sym264; +const r_184 = r_183.values[0] ?? { type: "null"}; +let _sym_id265 = r_184; +(runtime.info("compiler/emit_js.phi", 205), _emit193((runtime.info("compiler/emit_js.phi", 205), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "function _%%(" }), _ident261, _sym_id265)))); +(runtime.info("compiler/emit_js.phi", 207), _enter_scope198()); +const r_185 = ({ type: "bool", value: true }); +let _first266 = r_185; +for (const r_186 of _params262.values) {; +const r_187 = r_186.values[0] ?? { type: "null"}; +const r_188 = r_186.values[1] ?? { type: "null"}; +const r_189 = r_186.values[2] ?? { type: "null"}; +let _ident267 = r_189; +if (runtime.truthy(runtime.opNot(_first266))) { +(runtime.info("compiler/emit_js.phi", 212), _emit193(({ type: "string", value: ", " }))); +}; +(_first266 = ({ type: "bool", value: false })); +const r_190 = (runtime.info("compiler/emit_js.phi", 216), _define_param196(_ident267, _line239)); +let _sym_id268 = r_190; +(runtime.info("compiler/emit_js.phi", 217), _emit193((runtime.info("compiler/emit_js.phi", 217), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "_%%" }), _ident267, _sym_id268)))); +}; +(runtime.info("compiler/emit_js.phi", 221), _emit193(({ type: "string", value: ") {\n" }))); +(runtime.info("compiler/emit_js.phi", 222), _emit193((runtime.info("compiler/emit_js.phi", 222), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.pushCall(\"%\", \"%\");\n" }), _ident261, _filename205)))); +(runtime.info("compiler/emit_js.phi", 224), _emit_expr186(_body263)); +(runtime.info("compiler/emit_js.phi", 225), _emit193(({ type: "string", value: ";\nruntime.popCall();\nreturn { type: \"null\" };\n}" }))); +(runtime.info("compiler/emit_js.phi", 227), _leave_scope199()); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 228), runtime.opEq(_id242, ({ type: "string", value: "let" }))))) { +const r_191 = _s240; +const r_192 = r_191.values[0] ?? { type: "null"}; +const r_193 = r_191.values[1] ?? { type: "null"}; +let _pat269 = r_193; +const r_194 = r_191.values[2] ?? { type: "null"}; +let _expr270 = r_194; +const r_195 = (runtime.info("compiler/emit_js.phi", 230), _let_node_reg_count209()); +let _reg271 = r_195; +(runtime.info("compiler/emit_js.phi", 231), _let_node_reg_increment210()); +(runtime.info("compiler/emit_js.phi", 232), _emit193((runtime.info("compiler/emit_js.phi", 232), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "const r_% = " }), _reg271)))); +(runtime.info("compiler/emit_js.phi", 233), _emit_expr186(_expr270)); +(runtime.info("compiler/emit_js.phi", 234), _emit_let_node189(_pat269, _reg271)); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 235), runtime.opEq(_id242, ({ type: "string", value: "do" }))))) { +(runtime.info("compiler/emit_js.phi", 236), _enter_scope198()); +(runtime.info("compiler/emit_js.phi", 237), _discover_syms185((runtime.info("compiler/emit_js.phi", 237), _slice29(_s240, ({ type: "int", value: 1 }))))); +(runtime.info("compiler/emit_js.phi", 238), _emit_exprs184((runtime.info("compiler/emit_js.phi", 238), _slice29(_s240, ({ type: "int", value: 1 }))))); +(runtime.info("compiler/emit_js.phi", 239), _leave_scope199()); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 240), runtime.opEq(_id242, ({ type: "string", value: "for" }))))) { +const r_196 = _s240; +const r_197 = r_196.values[0] ?? { type: "null"}; +const r_198 = r_196.values[1] ?? { type: "null"}; +let _pat272 = r_198; +const r_199 = r_196.values[2] ?? { type: "null"}; +let _expr273 = r_199; +const r_200 = r_196.values[3] ?? { type: "null"}; +let _body274 = r_200; +const r_201 = (runtime.info("compiler/emit_js.phi", 243), _let_node_reg_count209()); +let _reg275 = r_201; +(runtime.info("compiler/emit_js.phi", 244), _let_node_reg_increment210()); +(runtime.info("compiler/emit_js.phi", 245), _emit193((runtime.info("compiler/emit_js.phi", 245), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "for (const r_% of " }), _reg275)))); +(runtime.info("compiler/emit_js.phi", 246), _emit_expr186(_expr273)); +(runtime.info("compiler/emit_js.phi", 247), _emit193(({ type: "string", value: ".values) {" }))); +(runtime.info("compiler/emit_js.phi", 249), _enter_scope198()); +(runtime.info("compiler/emit_js.phi", 250), _emit_let_node189(_pat272, _reg275)); +(runtime.info("compiler/emit_js.phi", 251), _enter_scope198()); +(runtime.info("compiler/emit_js.phi", 253), _emit193(({ type: "string", value: ";\n" }))); +(runtime.info("compiler/emit_js.phi", 254), _emit_expr186(_body274)); +(runtime.info("compiler/emit_js.phi", 255), _emit193(({ type: "string", value: "}" }))); +(runtime.info("compiler/emit_js.phi", 257), _leave_scope199()); +(runtime.info("compiler/emit_js.phi", 258), _leave_scope199()); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 259), runtime.opEq(_id242, ({ type: "string", value: "loop" }))))) { +const r_202 = _s240; +const r_203 = r_202.values[0] ?? { type: "null"}; +const r_204 = r_202.values[1] ?? { type: "null"}; +let _body276 = r_204; +(runtime.info("compiler/emit_js.phi", 261), _emit193(({ type: "string", value: "while (true) {\n" }))); +(runtime.info("compiler/emit_js.phi", 262), _emit_expr186(_body276)); +(runtime.info("compiler/emit_js.phi", 263), _emit193(({ type: "string", value: "}" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 264), runtime.opEq(_id242, ({ type: "string", value: "if" }))))) { +const r_205 = _s240; +const r_206 = r_205.values[0] ?? { type: "null"}; +const r_207 = r_205.values[1] ?? { type: "null"}; +let _cond277 = r_207; +const r_208 = r_205.values[2] ?? { type: "null"}; +let _truthy278 = r_208; +const r_209 = r_205.values[3] ?? { type: "null"}; +let _falsy279 = r_209; +(runtime.info("compiler/emit_js.phi", 266), _emit193(({ type: "string", value: "if (runtime.truthy(" }))); +(runtime.info("compiler/emit_js.phi", 267), _emit_expr186(_cond277)); +(runtime.info("compiler/emit_js.phi", 268), _emit193(({ type: "string", value: ")) {\n" }))); +(runtime.info("compiler/emit_js.phi", 269), _emit_expr186(_truthy278)); +(runtime.info("compiler/emit_js.phi", 270), _emit193(({ type: "string", value: "}" }))); +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 271), runtime.opNe(_falsy279, ({ type: "null" }))))) { +(runtime.info("compiler/emit_js.phi", 272), _emit193(({ type: "string", value: " else {\n" }))); +(runtime.info("compiler/emit_js.phi", 273), _emit_expr186(_falsy279)); +(runtime.info("compiler/emit_js.phi", 274), _emit193(({ type: "string", value: "}" }))); +}; +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 276), runtime.opEq(_id242, ({ type: "string", value: "return" }))))) { +const r_210 = _s240; +const r_211 = r_210.values[0] ?? { type: "null"}; +const r_212 = r_210.values[1] ?? { type: "null"}; +let _value280 = r_212; +(runtime.info("compiler/emit_js.phi", 278), _emit193(({ type: "string", value: "runtime.popCall();\n" }))); +(runtime.info("compiler/emit_js.phi", 279), _emit193(({ type: "string", value: "return " }))); +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 280), runtime.opNe(_value280, ({ type: "null" }))))) { +(runtime.info("compiler/emit_js.phi", 281), _emit_expr186(_value280)); +} else { +(runtime.info("compiler/emit_js.phi", 283), _emit193(({ type: "string", value: "{ type: \"null\" }" }))); +}; +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 285), runtime.opEq(_id242, ({ type: "string", value: "break" }))))) { +const r_213 = _s240; +const r_214 = r_213.values[0] ?? { type: "null"}; +const r_215 = r_213.values[1] ?? { type: "null"}; +let _value281 = r_215; +(runtime.info("compiler/emit_js.phi", 287), _emit193(({ type: "string", value: "break" }))); +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 288), runtime.opNe(_value281, ({ type: "null" }))))) { +(runtime.info("compiler/emit_js.phi", 289), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "not implemented" }))); +}; +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 291), runtime.opEq(_id242, ({ type: "string", value: "call" }))))) { +const r_216 = _s240; +const r_217 = r_216.values[0] ?? { type: "null"}; +const r_218 = r_216.values[1] ?? { type: "null"}; +let _callee282 = r_218; +const r_219 = (runtime.info("compiler/emit_js.phi", 293), _slice29(_s240, ({ type: "int", value: 2 }))); +let _args283 = r_219; +(runtime.info("compiler/emit_js.phi", 294), _emit193((runtime.info("compiler/emit_js.phi", 294), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(%, " }), (runtime.info("compiler/emit_js.phi", 294), _rt_info191(_line239)))))); +(runtime.info("compiler/emit_js.phi", 295), _emit_expr186(_callee282)); +(runtime.info("compiler/emit_js.phi", 296), _emit193(({ type: "string", value: "(" }))); +const r_220 = ({ type: "bool", value: true }); +let _first284 = r_220; +for (const r_221 of _args283.values) {; +let _arg285 = r_221; +if (runtime.truthy(runtime.opNot(_first284))) { +(runtime.info("compiler/emit_js.phi", 301), _emit193(({ type: "string", value: ", " }))); +}; +(_first284 = ({ type: "bool", value: false })); +(runtime.info("compiler/emit_js.phi", 305), _emit_expr186(_arg285)); +}; +(runtime.info("compiler/emit_js.phi", 308), _emit193(({ type: "string", value: "))" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 309), runtime.opEq(_id242, ({ type: "string", value: "list" }))))) { +(runtime.info("compiler/emit_js.phi", 310), _emit_list_literal188((runtime.info("compiler/emit_js.phi", 310), _slice29(_s240, ({ type: "int", value: 1 }))))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 311), runtime.opEq(_id242, ({ type: "string", value: "=" }))))) { +(runtime.info("compiler/emit_js.phi", 312), _emit_assign_expr192(_s240, _line239, ({ type: "string", value: "=" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 313), runtime.opEq(_id242, ({ type: "string", value: "+=" }))))) { +(runtime.info("compiler/emit_js.phi", 314), _emit_assign_expr192(_s240, _line239, ({ type: "string", value: "+" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 315), runtime.opEq(_id242, ({ type: "string", value: "-=" }))))) { +(runtime.info("compiler/emit_js.phi", 316), _emit_assign_expr192(_s240, _line239, ({ type: "string", value: "-" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 317), runtime.opEq(_id242, ({ type: "string", value: "or" }))))) { +const r_222 = _s240; +const r_223 = r_222.values[0] ?? { type: "null"}; +const r_224 = r_222.values[1] ?? { type: "null"}; +let _left286 = r_224; +const r_225 = r_222.values[2] ?? { type: "null"}; +let _right287 = r_225; +(runtime.info("compiler/emit_js.phi", 319), _emit193((runtime.info("compiler/emit_js.phi", 319), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(%" }), (runtime.info("compiler/emit_js.phi", 319), _rt_info191(_line239)), _line239)))); +(runtime.info("compiler/emit_js.phi", 320), _emit193(({ type: "string", value: ", { type: \"bool\", value: runtime.truthy(" }))); +(runtime.info("compiler/emit_js.phi", 321), _emit_expr186(_left286)); +(runtime.info("compiler/emit_js.phi", 322), _emit193(({ type: "string", value: ") || runtime.truthy(" }))); +(runtime.info("compiler/emit_js.phi", 323), _emit_expr186(_right287)); +(runtime.info("compiler/emit_js.phi", 324), _emit193(({ type: "string", value: ") })" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 325), runtime.opEq(_id242, ({ type: "string", value: "and" }))))) { +const r_226 = _s240; +const r_227 = r_226.values[0] ?? { type: "null"}; +const r_228 = r_226.values[1] ?? { type: "null"}; +let _left288 = r_228; +const r_229 = r_226.values[2] ?? { type: "null"}; +let _right289 = r_229; +(runtime.info("compiler/emit_js.phi", 327), _emit193((runtime.info("compiler/emit_js.phi", 327), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(%" }), (runtime.info("compiler/emit_js.phi", 327), _rt_info191(_line239)), _line239)))); +(runtime.info("compiler/emit_js.phi", 328), _emit193(({ type: "string", value: ", { type: \"bool\", value: runtime.truthy(" }))); +(runtime.info("compiler/emit_js.phi", 329), _emit_expr186(_left288)); +(runtime.info("compiler/emit_js.phi", 330), _emit193(({ type: "string", value: ") && runtime.truthy(" }))); +(runtime.info("compiler/emit_js.phi", 331), _emit_expr186(_right289)); +(runtime.info("compiler/emit_js.phi", 332), _emit193(({ type: "string", value: ") })" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 333), runtime.opEq(_id242, ({ type: "string", value: "==" }))))) { +(runtime.info("compiler/emit_js.phi", 334), _emit_binary_op190(_s240, ({ type: "string", value: "opEq" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 335), runtime.opEq(_id242, ({ type: "string", value: "!=" }))))) { +(runtime.info("compiler/emit_js.phi", 336), _emit_binary_op190(_s240, ({ type: "string", value: "opNe" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 337), runtime.opEq(_id242, ({ type: "string", value: "<" }))))) { +(runtime.info("compiler/emit_js.phi", 338), _emit_binary_op190(_s240, ({ type: "string", value: "opLt" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 339), runtime.opEq(_id242, ({ type: "string", value: ">" }))))) { +(runtime.info("compiler/emit_js.phi", 340), _emit_binary_op190(_s240, ({ type: "string", value: "opGt" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 341), runtime.opEq(_id242, ({ type: "string", value: "<=" }))))) { +(runtime.info("compiler/emit_js.phi", 342), _emit_binary_op190(_s240, ({ type: "string", value: "opLte" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 343), runtime.opEq(_id242, ({ type: "string", value: ">=" }))))) { +(runtime.info("compiler/emit_js.phi", 344), _emit_binary_op190(_s240, ({ type: "string", value: "opGte" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 345), runtime.opEq(_id242, ({ type: "string", value: "+" }))))) { +(runtime.info("compiler/emit_js.phi", 346), _emit_binary_op190(_s240, ({ type: "string", value: "opAdd" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 347), runtime.opEq(_id242, ({ type: "string", value: "-" }))))) { +(runtime.info("compiler/emit_js.phi", 348), _emit_binary_op190(_s240, ({ type: "string", value: "opSub" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 349), runtime.opEq(_id242, ({ type: "string", value: "not" }))))) { +const r_230 = _s240; +const r_231 = r_230.values[0] ?? { type: "null"}; +const r_232 = r_230.values[1] ?? { type: "null"}; +let _expr290 = r_232; +(runtime.info("compiler/emit_js.phi", 351), _emit193(({ type: "string", value: "runtime.opNot(" }))); +(runtime.info("compiler/emit_js.phi", 352), _emit_expr186(_expr290)); +(runtime.info("compiler/emit_js.phi", 353), _emit193(({ type: "string", value: ")" }))); +} else { +const r_233 = _s240; +const r_234 = r_233.values[0] ?? { type: "null"}; +let _callee291 = r_234; +const r_235 = (runtime.info("compiler/emit_js.phi", 356), _slice29(_s240, ({ type: "int", value: 1 }))); +let _args292 = r_235; +(runtime.info("compiler/emit_js.phi", 357), _emit193((runtime.info("compiler/emit_js.phi", 357), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(%, " }), (runtime.info("compiler/emit_js.phi", 357), _rt_info191(_line239)), _line239)))); +(runtime.info("compiler/emit_js.phi", 358), _emit_expr186(_callee291)); +(runtime.info("compiler/emit_js.phi", 359), _emit193(({ type: "string", value: "(" }))); +const r_236 = ({ type: "bool", value: true }); +let _first293 = r_236; +for (const r_237 of _args292.values) {; +let _arg294 = r_237; +if (runtime.truthy(runtime.opNot(_first293))) { +(runtime.info("compiler/emit_js.phi", 364), _emit193(({ type: "string", value: ", " }))); +}; +(_first293 = ({ type: "bool", value: false })); +(runtime.info("compiler/emit_js.phi", 368), _emit_expr186(_arg294)); +}; +(runtime.info("compiler/emit_js.phi", 371), _emit193(({ type: "string", value: "))" }))); +}}}}}}}}}}}}}}}}}}}}}}}}}; +; +runtime.popCall(); +return { type: "null" }; +}; +function _emit_list_literal188(_s295) { +runtime.pushCall("emit_list_literal", "compiler/emit_js.phi"); +(runtime.info("compiler/emit_js.phi", 376), _emit193(({ type: "string", value: "({ type: \"list\", values: [" }))); +const r_238 = ({ type: "bool", value: true }); +let _first296 = r_238; +for (const r_239 of _s295.values) {; +let _e297 = r_239; +if (runtime.truthy(runtime.opNot(_first296))) { +(runtime.info("compiler/emit_js.phi", 380), _emit193(({ type: "string", value: ", " }))); +}; +(_first296 = ({ type: "bool", value: false })); +(runtime.info("compiler/emit_js.phi", 384), _emit_expr186(_e297)); +}; +(runtime.info("compiler/emit_js.phi", 386), _emit193(({ type: "string", value: "] })" }))); +; +runtime.popCall(); +return { type: "null" }; +}; +function _emit_let_node189(_pat298, _base_reg299) { +runtime.pushCall("emit_let_node", "compiler/emit_js.phi"); +const r_240 = _pat298; +const r_241 = r_240.values[0] ?? { type: "null"}; +let _pat_ty300 = r_241; +const r_242 = r_240.values[1] ?? { type: "null"}; +let _line301 = r_242; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 391), runtime.opEq(_pat_ty300, ({ type: "string", value: "ident" }))))) { +const r_243 = _pat298; +const r_244 = r_243.values[0] ?? { type: "null"}; +const r_245 = r_243.values[1] ?? { type: "null"}; +const r_246 = r_243.values[2] ?? { type: "null"}; +let _ident302 = r_246; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 394), runtime.opEq(_ident302, ({ type: "string", value: "_" }))))) { +runtime.popCall(); +return { type: "null" }}; +const r_247 = (runtime.info("compiler/emit_js.phi", 396), _define_let197(_ident302, _line301)); +let _sym_id303 = r_247; +(runtime.info("compiler/emit_js.phi", 397), _emit193((runtime.info("compiler/emit_js.phi", 397), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: ";\nlet _%% = r_%" }), _ident302, _sym_id303, _base_reg299)))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 398), runtime.opEq(_pat_ty300, ({ type: "string", value: "list" }))))) { +const r_248 = _pat298; +const r_249 = r_248.values[0] ?? { type: "null"}; +const r_250 = r_248.values[1] ?? { type: "null"}; +const r_251 = r_248.values[2] ?? { type: "null"}; +let _pats304 = r_251; +const r_252 = ({ type: "int", value: 0 }); +let _i305 = r_252; +for (const r_253 of _pats304.values) {; +let _pat306 = r_253; +const r_254 = (runtime.info("compiler/emit_js.phi", 403), _let_node_reg_count209()); +let _reg307 = r_254; +(runtime.info("compiler/emit_js.phi", 404), _let_node_reg_increment210()); +(runtime.info("compiler/emit_js.phi", 405), _emit193((runtime.info("compiler/emit_js.phi", 405), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: ";\nconst r_% = r_%.values[%] ?? { type: \"null\"}" }), _reg307, _base_reg299, _i305)))); +(runtime.info("compiler/emit_js.phi", 409), _emit_let_node189(_pat306, _reg307)); +(_i305 = runtime.opAdd(_i305, ({ type: "int", value: 1 }))); +}; +} else { +(runtime.info("compiler/emit_js.phi", 413), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "malformed pattern on line %" }), _line301)); +}}; +; +runtime.popCall(); +return { type: "null" }; +}; +function _emit_binary_op190(_s308, _id309) { +runtime.pushCall("emit_binary_op", "compiler/emit_js.phi"); +const r_255 = _s308; +const r_256 = r_255.values[0] ?? { type: "null"}; +const r_257 = r_256.values[0] ?? { type: "null"}; +const r_258 = r_256.values[1] ?? { type: "null"}; +let _line310 = r_258; +const r_259 = r_256.values[2] ?? { type: "null"}; +const r_260 = r_255.values[1] ?? { type: "null"}; +let _left311 = r_260; +const r_261 = r_255.values[2] ?? { type: "null"}; +let _right312 = r_261; +(runtime.info("compiler/emit_js.phi", 419), _emit193((runtime.info("compiler/emit_js.phi", 419), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(%, runtime.%(" }), (runtime.info("compiler/emit_js.phi", 419), _rt_info191(_line310)), _id309)))); +(runtime.info("compiler/emit_js.phi", 420), _emit_expr186(_left311)); +(runtime.info("compiler/emit_js.phi", 421), _emit193(({ type: "string", value: ", " }))); +(runtime.info("compiler/emit_js.phi", 422), _emit_expr186(_right312)); +(runtime.info("compiler/emit_js.phi", 423), _emit193(({ type: "string", value: "))" }))); +; +runtime.popCall(); +return { type: "null" }; +}; +function _rt_info191(_line313) { +runtime.pushCall("rt_info", "compiler/emit_js.phi"); +runtime.popCall(); +return (runtime.info("compiler/emit_js.phi", 427), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.info(\"%\", %)" }), _filename205, _line313)); +; +runtime.popCall(); +return { type: "null" }; +}; +function _emit_assign_expr192(_s314, _line315, _id316) { +runtime.pushCall("emit_assign_expr", "compiler/emit_js.phi"); +const r_262 = _s314; +const r_263 = r_262.values[0] ?? { type: "null"}; +const r_264 = r_262.values[1] ?? { type: "null"}; +const r_265 = r_264.values[0] ?? { type: "null"}; +let _target_type317 = r_265; +const r_266 = r_262.values[2] ?? { type: "null"}; +let _expr318 = r_266; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 432), runtime.opNe(_target_type317, ({ type: "string", value: "ident" }))))) { +(runtime.info("compiler/emit_js.phi", 433), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "cannot assign to expression on line %" }), _line315)); +}; +const r_267 = _s314; +const r_268 = r_267.values[0] ?? { type: "null"}; +const r_269 = r_267.values[1] ?? { type: "null"}; +const r_270 = r_269.values[0] ?? { type: "null"}; +const r_271 = r_269.values[1] ?? { type: "null"}; +const r_272 = r_269.values[2] ?? { type: "null"}; +let _ident319 = r_272; +const r_273 = (runtime.info("compiler/emit_js.phi", 436), _get_sym201(_ident319)); +let _sym320 = r_273; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 437), runtime.opEq(_sym320, ({ type: "null" }))))) { +(runtime.info("compiler/emit_js.phi", 438), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "could not find symbol '%' on line %" }), _ident319, _line315)); +}; +const r_274 = _sym320; +const r_275 = r_274.values[0] ?? { type: "null"}; +let _sym_id321 = r_275; +const r_276 = r_274.values[1] ?? { type: "null"}; +let _sym_type322 = r_276; +const r_277 = r_274.values[2] ?? { type: "null"}; +let _sym_ident323 = r_277; +const r_278 = r_274.values[3] ?? { type: "null"}; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 441), runtime.opEq(_sym_type322, ({ type: "string", value: "let" }))))) { +(runtime.info("compiler/emit_js.phi", 442), _emit193((runtime.info("compiler/emit_js.phi", 442), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(_%% = " }), _sym_ident323, _sym_id321)))); +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 443), runtime.opEq(_id316, ({ type: "string", value: "=" }))))) { +(runtime.info("compiler/emit_js.phi", 444), _emit_expr186(_expr318)); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 445), runtime.opEq(_id316, ({ type: "string", value: "+" }))))) { +(runtime.info("compiler/emit_js.phi", 446), _emit193((runtime.info("compiler/emit_js.phi", 446), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.opAdd(_%%, " }), _sym_ident323, _sym_id321)))); +(runtime.info("compiler/emit_js.phi", 447), _emit_expr186(_expr318)); +(runtime.info("compiler/emit_js.phi", 448), _emit193(({ type: "string", value: ")" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 449), runtime.opEq(_id316, ({ type: "string", value: "-" }))))) { +(runtime.info("compiler/emit_js.phi", 450), _emit193((runtime.info("compiler/emit_js.phi", 450), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.opSub(_%%, " }), _sym_ident323, _sym_id321)))); +(runtime.info("compiler/emit_js.phi", 451), _emit_expr186(_expr318)); +(runtime.info("compiler/emit_js.phi", 452), _emit193(({ type: "string", value: ")" }))); +} else { +(runtime.info("compiler/emit_js.phi", 454), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "not implemented" }))); +}}}; +(runtime.info("compiler/emit_js.phi", 456), _emit193(({ type: "string", value: ")" }))); +} else { +(runtime.info("compiler/emit_js.phi", 458), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "cannot assign to symbol '%' on line %" }), _sym_ident323, _line315)); +}; +; +runtime.popCall(); +return { type: "null" }; +}; +function _emit193(_str324) { +runtime.pushCall("emit", "compiler/emit_js.phi"); +(runtime.info("compiler/emit_js.phi", 463), ((...args) => runtime.builtinPush(...args))(_output204, _str324)); +; +runtime.popCall(); +return { type: "null" }; +}; +function _define_builtin194(_ident325, _builtin_id326) { +runtime.pushCall("define_builtin", "compiler/emit_js.phi"); +const r_279 = (runtime.info("compiler/emit_js.phi", 467), _sym_id_count207()); +let _sym_id327 = r_279; +(runtime.info("compiler/emit_js.phi", 468), _sym_id_increment208()); +(runtime.info("compiler/emit_js.phi", 470), _define_sym200(_ident325, ({ type: "list", values: [_sym_id327, ({ type: "string", value: "builtin" }), _builtin_id326] }))); +runtime.popCall(); +return _sym_id327; +; +runtime.popCall(); +return { type: "null" }; +}; +function _define_fn195(_ident328, _line329) { +runtime.pushCall("define_fn", "compiler/emit_js.phi"); +const r_280 = (runtime.info("compiler/emit_js.phi", 475), _sym_id_count207()); +let _sym_id330 = r_280; +(runtime.info("compiler/emit_js.phi", 476), _sym_id_increment208()); +(runtime.info("compiler/emit_js.phi", 478), _define_sym200(_ident328, ({ type: "list", values: [_sym_id330, ({ type: "string", value: "fn" }), _ident328, _line329] }))); +runtime.popCall(); +return _sym_id330; +; +runtime.popCall(); +return { type: "null" }; +}; +function _define_param196(_ident331, _line332) { +runtime.pushCall("define_param", "compiler/emit_js.phi"); +const r_281 = (runtime.info("compiler/emit_js.phi", 483), _sym_id_count207()); +let _sym_id333 = r_281; +(runtime.info("compiler/emit_js.phi", 484), _sym_id_increment208()); +(runtime.info("compiler/emit_js.phi", 486), _define_sym200(_ident331, ({ type: "list", values: [_sym_id333, ({ type: "string", value: "param" }), _ident331, _line332] }))); +runtime.popCall(); +return _sym_id333; +; +runtime.popCall(); +return { type: "null" }; +}; +function _define_let197(_ident334, _line335) { +runtime.pushCall("define_let", "compiler/emit_js.phi"); +const r_282 = (runtime.info("compiler/emit_js.phi", 491), _sym_id_count207()); +let _sym_id336 = r_282; +(runtime.info("compiler/emit_js.phi", 492), _sym_id_increment208()); +(runtime.info("compiler/emit_js.phi", 494), _define_sym200(_ident334, ({ type: "list", values: [_sym_id336, ({ type: "string", value: "let" }), _ident334, _line335] }))); +runtime.popCall(); +return _sym_id336; +; +runtime.popCall(); +return { type: "null" }; +}; +function _enter_scope198() { +runtime.pushCall("enter_scope", "compiler/emit_js.phi"); +const r_283 = _syms206; +const r_284 = r_283.values[0] ?? { type: "null"}; +let _enter_scope337 = r_284; +(runtime.info("compiler/emit_js.phi", 501), _enter_scope337()); +; +runtime.popCall(); +return { type: "null" }; +}; +function _leave_scope199() { +runtime.pushCall("leave_scope", "compiler/emit_js.phi"); +const r_285 = _syms206; +const r_286 = r_285.values[0] ?? { type: "null"}; +const r_287 = r_285.values[1] ?? { type: "null"}; +let _leave_scope338 = r_287; +(runtime.info("compiler/emit_js.phi", 505), _leave_scope338()); +; +runtime.popCall(); +return { type: "null" }; +}; +function _define_sym200(_ident339, _sym340) { +runtime.pushCall("define_sym", "compiler/emit_js.phi"); +const r_288 = _syms206; +const r_289 = r_288.values[0] ?? { type: "null"}; +const r_290 = r_288.values[1] ?? { type: "null"}; +const r_291 = r_288.values[2] ?? { type: "null"}; +let _define_sym341 = r_291; +runtime.popCall(); +return (runtime.info("compiler/emit_js.phi", 509), _define_sym341(_ident339, _sym340)); +; +runtime.popCall(); +return { type: "null" }; +}; +function _get_sym201(_ident342) { +runtime.pushCall("get_sym", "compiler/emit_js.phi"); +const r_292 = _syms206; +const r_293 = r_292.values[0] ?? { type: "null"}; +const r_294 = r_292.values[1] ?? { type: "null"}; +const r_295 = r_292.values[2] ?? { type: "null"}; +const r_296 = r_292.values[3] ?? { type: "null"}; +let _get_sym343 = r_296; +runtime.popCall(); +return (runtime.info("compiler/emit_js.phi", 513), _get_sym343(_ident342)); +; +runtime.popCall(); +return { type: "null" }; +}; +function _get_current_map202() { +runtime.pushCall("get_current_map", "compiler/emit_js.phi"); +const r_297 = _syms206; +const r_298 = r_297.values[0] ?? { type: "null"}; +const r_299 = r_297.values[1] ?? { type: "null"}; +const r_300 = r_297.values[2] ?? { type: "null"}; +const r_301 = r_297.values[3] ?? { type: "null"}; +const r_302 = r_297.values[4] ?? { type: "null"}; +let _get_current_map344 = r_302; +runtime.popCall(); +return (runtime.info("compiler/emit_js.phi", 517), _get_current_map344()); +; +runtime.popCall(); +return { type: "null" }; +}; +function _print_syms203() { +runtime.pushCall("print_syms", "compiler/emit_js.phi"); +const r_303 = _syms206; +const r_304 = r_303.values[0] ?? { type: "null"}; +const r_305 = r_303.values[1] ?? { type: "null"}; +const r_306 = r_303.values[2] ?? { type: "null"}; +const r_307 = r_303.values[3] ?? { type: "null"}; +const r_308 = r_303.values[4] ?? { type: "null"}; +const r_309 = r_303.values[5] ?? { type: "null"}; +let _print_syms345 = r_309; +(runtime.info("compiler/emit_js.phi", 521), _print_syms345()); +; +runtime.popCall(); +return { type: "null" }; +}; +runtime.popCall(); +return ({ type: "list", values: [_generate183] }); +; +runtime.popCall(); +return { type: "null" }; +}; +function _Counter139() { +runtime.pushCall("Counter", "compiler/emit_js.phi"); +const r_310 = ({ type: "int", value: 0 }); +let _counter348 = r_310; +function _count346() { +runtime.pushCall("count", "compiler/emit_js.phi"); +runtime.popCall(); +return _counter348; +; +runtime.popCall(); +return { type: "null" }; +}; +function _increment347() { +runtime.pushCall("increment", "compiler/emit_js.phi"); +(_counter348 = runtime.opAdd(_counter348, ({ type: "int", value: 1 }))); +; +runtime.popCall(); +return { type: "null" }; +}; +runtime.popCall(); +return ({ type: "list", values: [_count346, _increment347] }); +; +runtime.popCall(); +return { type: "null" }; +}; +function _string_escape140(_str349) { +runtime.pushCall("string_escape", "compiler/emit_js.phi"); +const r_311 = (runtime.info("compiler/emit_js.phi", 542), ((...args) => runtime.builtinLen(...args))(_str349)); +let _str_len350 = r_311; +const r_312 = ({ type: "int", value: 0 }); +let _i351 = r_312; +const r_313 = ({ type: "string", value: "" }); +let _result352 = r_313; +while (true) { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 546), runtime.opGte(_i351, _str_len350)))) { +break}; +const r_314 = (runtime.info("compiler/emit_js.phi", 547), ((...args) => runtime.builtinAt(...args))(_str349, _i351)); +let _ch353 = r_314; +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 548), runtime.opEq(_ch353, ({ type: "string", value: "\\" }))))) { +(_result352 = runtime.opAdd(_result352, ({ type: "string", value: "\\\\" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 550), runtime.opEq(_ch353, ({ type: "string", value: "\"" }))))) { +(_result352 = runtime.opAdd(_result352, ({ type: "string", value: "\\\"" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 552), runtime.opEq(_ch353, ({ type: "string", value: "\t" }))))) { +(_result352 = runtime.opAdd(_result352, ({ type: "string", value: "\\t" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 554), runtime.opEq(_ch353, ({ type: "string", value: "\r" }))))) { +(_result352 = runtime.opAdd(_result352, ({ type: "string", value: "\\r" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 556), runtime.opEq(_ch353, ({ type: "string", value: "\n" }))))) { +(_result352 = runtime.opAdd(_result352, ({ type: "string", value: "\\n" }))); +} else { +if (runtime.truthy((runtime.info("compiler/emit_js.phi", 558), runtime.opEq(_ch353, ({ type: "string", value: "\n" }))))) { +(_result352 = runtime.opAdd(_result352, ({ type: "string", value: "\\0" }))); +} else { +(_result352 = runtime.opAdd(_result352, _ch353)); +}}}}}}; +(_i351 = runtime.opAdd(_i351, ({ type: "int", value: 1 }))); +}; +runtime.popCall(); +return _result352; +; +runtime.popCall(); +return { type: "null" }; +}; +runtime.setFile("compile.phi"); +; +function _print_expr14(_expr354, _depth355) { +runtime.pushCall("print_expr", "compile.phi"); +const r_315 = _expr354; +const r_316 = r_315.values[0] ?? { type: "null"}; +let _ty356 = r_316; +const r_317 = r_315.values[1] ?? { type: "null"}; +let _line357 = r_317; +const r_318 = r_315.values[2] ?? { type: "null"}; +let _value358 = r_318; +if (runtime.truthy((runtime.info("compile.phi", 7), runtime.opEq(_ty356, ({ type: "string", value: "list" }))))) { +(runtime.info("compile.phi", 8), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "%(% %" }), (runtime.info("compile.phi", 8), _indent32(_depth355)), _ty356, _line357)); +for (const r_319 of _value358.values) {; +let _e359 = r_319; +(runtime.info("compile.phi", 10), _print_expr14(_e359, (runtime.info("compile.phi", 10), runtime.opAdd(_depth355, ({ type: "int", value: 1 }))))); +}; +(runtime.info("compile.phi", 12), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "%)" }), (runtime.info("compile.phi", 12), _indent32(_depth355)))); +} else { +(runtime.info("compile.phi", 14), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "%%" }), (runtime.info("compile.phi", 14), _indent32(_depth355)), _expr354)); +}; +; +runtime.popCall(); +return { type: "null" }; +}; +const r_320 = (runtime.info("compile.phi", 18), ((...args) => runtime.builtinGetArgs(...args))()); +const r_321 = r_320.values[0] ?? { type: "null"}; +let _input_filename360 = r_321; +const r_322 = r_320.values[1] ?? { type: "null"}; +let _output_filename361 = r_322; +(runtime.info("compile.phi", 20), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "compiling '%'..." }), _input_filename360)); +const r_323 = (runtime.info("compile.phi", 21), ((...args) => runtime.builtinReadTextFile(...args))(_input_filename360)); +let _text362 = r_323; +const r_324 = (runtime.info("compile.phi", 23), _tokenize95(_text362)); +let _tokens363 = r_324; +const r_325 = (runtime.info("compile.phi", 24), _Parser94(_tokens363)); +let _parser364 = r_325; +const r_326 = _parser364; +const r_327 = r_326.values[0] ?? { type: "null"}; +let _parse365 = r_327; +const r_328 = (runtime.info("compile.phi", 26), _parse365()); +let _ast366 = r_328; +const r_329 = (runtime.info("compile.phi", 27), _JsEmitter138(_ast366, _input_filename360)); +let _emitter367 = r_329; +const r_330 = _emitter367; +const r_331 = r_330.values[0] ?? { type: "null"}; +let _emit368 = r_331; +const r_332 = (runtime.info("compile.phi", 29), _emit368()); +let _js_code369 = r_332; +(runtime.info("compile.phi", 34), ((...args) => runtime.builtinWriteTextFile(...args))(_output_filename361, _js_code369)); +(runtime.info("compile.phi", 35), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "writing '%'" }), _output_filename361)); diff --git a/stdlib.phi b/stdlib.phi index 6b232b1..f01926c 100644 --- a/stdlib.phi +++ b/stdlib.phi @@ -52,3 +52,75 @@ (return space) )) +(fn list_push (list_ value) (do + (let list_len (len list_)) + (let i 0) + (loop (do + (if (>= i list_len) (break)) + (if (== (at list_ i) null) (do + (set list_ i value) + (return) + )) + (+= i 1) + )) + (push list_ value) +)) + +(fn list_pop (list_) (do + (let i (- (len list_) 1)) + (loop (do + (if (< i 0) (break)) + (let value (at list_ i)) + (if (!= value null) (do + (set list_ i null) + (return value) + )) + (-= i 1) + )) + (return null) +)) + +(fn list_contains (list_ value) (do + (for elem list_ (do + (if (== elem value) (do + (return true) + )) + )) + (return false) +)) + +(fn map () (do + (return (list)) +)) + +(fn map_has (map key) (do + (for (m_key _) map (do + (if (== m_key key) (do + (return true) + )) + )) + (return false) +)) + +(fn map_get (map key) (do + (for (m_key value) map (do + (if (== m_key key) (do + (return value) + )) + )) + (return null) +)) + +(fn map_set (map key value) (do + (for entry map (do + (let (entry_key _) entry) + (if (== entry_key key) (do + (set entry 1 value) + (return) + )) + )) + (push map (list key value)) +)) + + +