From a72790476cf922a59349d66196a646476a18e553 Mon Sep 17 00:00:00 2001 From: sfja Date: Tue, 23 Sep 2025 19:47:35 +0200 Subject: [PATCH] split up compiler --- compile.phi | 835 +---------- compiler/emit_js.phi | 545 +++++++ compiler/parse.phi | 160 +++ compiler/syms.phi | 79 + runtime.js | 4 - stage2.js | 3272 +++++++++++++++++++++++++----------------- stdlib.phi | 54 + 7 files changed, 2773 insertions(+), 2176 deletions(-) create mode 100644 compiler/emit_js.phi create mode 100644 compiler/parse.phi create mode 100644 compiler/syms.phi create mode 100644 stdlib.phi diff --git a/compile.phi b/compile.phi index 8b978df..667ea8e 100644 --- a/compile.phi +++ b/compile.phi @@ -1,812 +1,6 @@ - -(fn Emitter (ast initial_filename) (do - (let output (list)) - (let filename initial_filename) - - (let syms (Syms)) - - (let (sym_id_count sym_id_increment) (Counter)) - (let (let_node_reg_count let_node_reg_increment) (Counter)) - - (let builtin_syms (list - (list "format" "builtinFormat") - (list "print" "builtinPrint") - (list "println" "builtinPrintln") - (list "panic" "builtinPanic") - (list "read_text_file" "builtinReadTextFile") - (list "write_text_file" "builtinWriteTextFile") - (list "push" "builtinPush") - (list "at" "builtinAt") - (list "set" "builtinSet") - (list "len" "builtinLen") - (list "string_to_int" "builtinStringToInt") - (list "char_code" "builtinCharCode") - (list "strings_join" "builtinStringsJoin") - (list "get_args" "builtinGetArgs") - )) - - (fn generate () (do - (emit "#!/usr/bin/env node\n") - (emit "import { Runtime } from \"./runtime.js\";\n") - (emit (format "const runtime = new Runtime(\"%\");\n" filename)) - - (for (ident builtin_id) builtin_syms (do - (define_builtin ident builtin_id) - )) - - (enter_scope) - (discover_syms ast) - (emit_exprs ast) - (return (strings_join output)) - )) - - (fn emit_exprs (exprs) (do - (for expr exprs (do - (emit_expr expr) - (emit ";\n") - )) - )) - - (fn discover_syms (exprs) (do - (for expr exprs (do - (let (ty line) expr) - (if (!= ty "list") (return)) - (let (_ _ s) expr) - (if (== (len s) 0) (return)) - (let ((_ _ id)) s) - (if (== id "fn") (do - (let (_ (_ _ ident) (_ _ params) body) s) - (define_fn ident line) - )) - )) - )) - - (fn emit_expr (expr) (do - (let (ty line) expr) - (if (== ty "list") (do - (emit_list expr) - ) (if (== ty "int") (do - (let (_ _ value) expr) - (emit (format "({ type: \"int\", value: % })" value)) - ) (if (== ty "string") (do - (let (_ _ value) expr) - (emit (format "({ type: \"string\", value: \"%\" })" (string_escape value))) - ) (if (== ty "ident") (do - (let (_ _ value) expr) - - (if (== value "null") (do - (emit "({ type: \"null\" })") - (return) - ) (if (== value "false") (do - (emit "({ type: \"bool\", value: false })") - (return) - ) (if (== value "true") (do - (emit "({ type: \"bool\", value: true })") - (return) - )))) - - (let sym (get_sym value)) - (if (== sym null) (do - (panic "undefined symbol '%' on line %" value line) - )) - - (let (sym_id sym_ty) sym) - (if (== sym_ty "builtin") (do - (let (_ _ id) sym) - (emit (format "((...args) => runtime.%(...args))" id)) - ) (if (== sym_ty "fn") (do - (emit (format "_%%" value sym_id)) - ) (if (== sym_ty "param") (do - (emit (format "_%%" value sym_id)) - ) (if (== sym_ty "let") (do - (emit (format "_%%" value sym_id)) - ) (if (== sym_ty "imported") (do - // this might give problems in the future. - // the solution is to feed the imported symbol - // back into this code, so that stuff gets - // handled appropriately. - (emit (format "_%%" value sym_id)) - ) (do - (panic "not implemented '%'" sym_ty) - )))))) - ) (do - (panic "unknown expr type '%' on line %" ty line) - ))))) - )) - - (fn emit_list (expr) (do - (let (ty line s) expr) - (if (== (len s) 0) (do - (panic "illegal function on line %" line) - )) - (let ((id_ty _ id)) s) - (if (!= id_ty "ident") (do - (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) - )) - - (enter_scope) - (discover_syms ast) - (emit_exprs ast) - (let sym_map (get_current_map)) - - (= syms outer_syms) - (= filename outer_filename) - - (emit (format "runtime.setFile(\"%\");\n" outer_filename)) - - (for (_ _ ident) idents (do - (let sym null) - (for (sym_ident found_sym) sym_map (do - (if (== sym_ident ident) (do - (= sym found_sym) - (break) - )) - )) - (if (== sym null) (do - (println "sym_map = %" sym_map) - (panic "no symbol '%' from imported '%'" ident filename) - )) - (let (_ sym_type) sym) - (if (== sym_type "imported") (do - (define_sym ident sym) - ) (do - (let (sym_id) sym) - (define_sym ident (list sym_id "imported" sym)) - )) - )) - ) (if (== id "fn") (do - (let (_ (_ _ ident) (_ _ params) body) s) - - (let sym (get_sym ident)) - (let (sym_id) sym) - - (emit (format "function _%%(" ident sym_id)) - - (enter_scope) - - (let first true) - (for (_ _ ident) params (do - (if (not first) (do - (emit ", ") - )) - (= first false) - - (let sym_id (define_param ident line)) - (emit (format "_%%" ident sym_id)) - )) - - - (emit ") {\n") - (emit (format "runtime.pushCall(\"%\", \"%\");\n" ident filename)) - - (emit_expr body) - (emit ";\nruntime.popCall();\nreturn { type: \"null\" };\n}") - - (leave_scope) - ) (if (== id "let") (do - (let (_ pat expr) s) - (let reg (let_node_reg_count)) - (let_node_reg_increment) - (emit (format "const r_% = " reg)) - (emit_expr expr) - (emit_let_node pat reg) - ) (if (== id "do") (do - (enter_scope) - (discover_syms (slice s 1)) - (emit_exprs (slice s 1)) - (leave_scope) - ) (if (== id "for") (do - (let (_ pat expr body) s) - - (let reg (let_node_reg_count)) - (let_node_reg_increment) - (emit (format "for (const r_% of " reg)) - (emit_expr expr) - (emit ".values) {") - - (enter_scope) - (emit_let_node pat reg) - (enter_scope) - - (emit ";\n") - (emit_expr body) - (emit "}") - - (leave_scope) - (leave_scope) - ) (if (== id "loop") (do - (let (_ body) s) - (emit "while (true) {\n") - (emit_expr body) - (emit "}") - ) (if (== id "if") (do - (let (_ cond truthy falsy) s) - (emit "if (runtime.truthy(") - (emit_expr cond) - (emit ")) {\n") - (emit_expr truthy) - (emit "}") - (if (!= falsy null) (do - (emit " else {\n") - (emit_expr falsy) - (emit "}") - )) - ) (if (== id "return") (do - (let (_ value) s) - (emit "runtime.popCall();\n") - (emit "return ") - (if (!= value null) (do - (emit_expr value) - ) (do - (emit "{ type: \"null\" }") - )) - ) (if (== id "break") (do - (let (_ value) s) - (emit "break") - (if (!= value null) (do - (panic "not implemented") - )) - ) (if (== id "call") (do - (let (_ callee) s) - (let args (slice s 2)) - (emit (format "(%, " (rt_info line))) - (emit_expr callee) - (emit "(") - - (let first true) - (for arg args (do - (if (not first) (do - (emit ", ") - )) - (= first false) - - (emit_expr arg) - )) - - (emit "))") - ) (if (== id "list") (do - (emit_list_literal (slice s 1)) - ) (if (== id "=") (do - (emit_assign_expr s line "=") - ) (if (== id "+=") (do - (emit_assign_expr s line "+") - ) (if (== id "-=") (do - (emit_assign_expr s line "-") - ) (if (== id "or") (do - (let (_ left right) s) - (emit (format "(%" (rt_info line) line)) - (emit ", { type: \"bool\", value: runtime.truthy(") - (emit_expr left) - (emit ") || runtime.truthy(") - (emit_expr right) - (emit ") })") - ) (if (== id "and") (do - (let (_ left right) s) - (emit (format "(%" (rt_info line) line)) - (emit ", { type: \"bool\", value: runtime.truthy(") - (emit_expr left) - (emit ") && runtime.truthy(") - (emit_expr right) - (emit ") })") - ) (if (== id "==") (do - (emit_binary_op s "opEq") - ) (if (== id "!=") (do - (emit_binary_op s "opNe") - ) (if (== id "<") (do - (emit_binary_op s "opLt") - ) (if (== id ">") (do - (emit_binary_op s "opGt") - ) (if (== id "<=") (do - (emit_binary_op s "opLte") - ) (if (== id ">=") (do - (emit_binary_op s "opGte") - ) (if (== id "+") (do - (emit_binary_op s "opAdd") - ) (if (== id "-") (do - (emit_binary_op s "opSub") - ) (if (== id "not") (do - (let (_ expr) s) - (emit "runtime.opNot(") - (emit_expr expr) - (emit ")") - ) (do - (let (callee) s) - (let args (slice s 1)) - (emit (format "(%, " (rt_info line) line)) - (emit_expr callee) - (emit "(") - - (let first true) - (for arg args (do - (if (not first) (do - (emit ", ") - )) - (= first false) - - (emit_expr arg) - )) - - (emit "))") - )))))))))))))))))))))))))) - )) - - (fn emit_list_literal (s) (do - (emit "({ type: \"list\", values: [") - (let first true) - (for e s (do - (if (not first) (do - (emit ", ") - )) - (= first false) - - (emit_expr e) - )) - (emit "] })") - )) - - (fn emit_let_node (pat base_reg) (do - (let (pat_ty line) pat) - (if (== pat_ty "ident") (do - (let (_ _ ident) pat) - - (if (== ident "_") (return)) - - (let sym_id (define_let ident line)) - (emit (format ";\nlet _%% = r_%" ident sym_id base_reg)) - ) (if (== pat_ty "list") (do - (let (_ _ pats) pat) - - (let i 0) - (for pat pats (do - (let reg (let_node_reg_count)) - (let_node_reg_increment) - (emit (format - ";\nconst r_% = r_%.values[%] ?? { type: \"null\"}" - reg base_reg i - )) - (emit_let_node pat reg) - (+= i 1) - )) - ) (do - (panic "malformed pattern on line %" line) - ))) - )) - - (fn emit_binary_op (s id) (do - (let ((_ line _) left right) s) - (emit (format "(%, runtime.%(" (rt_info line) id)) - (emit_expr left) - (emit ", ") - (emit_expr right) - (emit "))") - )) - - (fn rt_info (line) (do - (return (format "runtime.info(\"%\", %)" filename line)) - )) - - (fn emit_assign_expr (s line id) (do - (let (_ (target_type) expr) s) - (if (!= target_type "ident") (do - (panic "cannot assign to expression on line %" line) - )) - (let (_ (_ _ ident)) s) - (let sym (get_sym ident)) - (if (== sym null) (do - (panic "could not find symbol '%' on line %" ident line) - )) - (let (sym_id sym_type sym_ident _) sym) - (if (== sym_type "let") (do - (emit (format "(_%% = " sym_ident sym_id)) - (if (== id "=") (do - (emit_expr expr) - ) (if (== id "+") (do - (emit (format "runtime.opAdd(_%%, " sym_ident sym_id)) - (emit_expr expr) - (emit ")") - ) (if (== id "-") (do - (emit (format "runtime.opSub(_%%, " sym_ident sym_id)) - (emit_expr expr) - (emit ")") - ) (do - (panic "not implemented") - )))) - (emit ")") - ) (do - (panic "cannot assign to symbol '%' on line %" sym_ident line) - )) - )) - - (fn emit (str) (do - (push output str) - )) - - (fn define_builtin (ident builtin_id) (do - (let sym_id (sym_id_count)) - (sym_id_increment) - - (define_sym ident (list sym_id "builtin" builtin_id)) - (return sym_id) - )) - - (fn define_fn (ident line) (do - (let sym_id (sym_id_count)) - (sym_id_increment) - - (define_sym ident (list sym_id "fn" ident line)) - (return sym_id) - )) - - (fn define_param (ident line) (do - (let sym_id (sym_id_count)) - (sym_id_increment) - - (define_sym ident (list sym_id "param" ident line)) - (return sym_id) - )) - - (fn define_let (ident line) (do - (let sym_id (sym_id_count)) - (sym_id_increment) - - (define_sym ident (list sym_id "let" ident line)) - (return sym_id) - )) - - // indirection for syms - (fn enter_scope () (do - (let (enter_scope) syms) - (enter_scope) - )) - (fn leave_scope () (do - (let (_ leave_scope) syms) - (leave_scope) - )) - (fn define_sym (ident sym) (do - (let (_ _ define_sym) syms) - (return (define_sym ident sym)) - )) - (fn get_sym (ident) (do - (let (_ _ _ get_sym) syms) - (return (get_sym ident)) - )) - (fn get_current_map () (do - (let (_ _ _ _ get_current_map) syms) - (return (get_current_map)) - )) - (fn print_syms () (do - (let (_ _ _ _ _ print_syms) syms) - (print_syms) - )) - - (return (list generate)) -)) - -(fn Counter () (do - (let counter 0) - - (fn count () (do - (return counter) - )) - - (fn increment () (do - (+= counter 1) - )) - - (return (list count increment)) -)) - -(fn Syms () (do - (let syms (list null (list))) - - (fn enter_scope () (do - (= syms (list syms (list))) - )) - - (fn leave_scope () (do - (let (parent _) syms) - (= syms parent) - )) - - (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)) - )) - - (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 (!= parent null) (do - (return (find_sym parent ident)) - )) - (return null) - )) - - (fn get_sym (ident) (do - (return (find_sym syms ident)) - )) - - (fn get_current_map () (do - (let (_ map) syms) - (return map) - )) - - (fn print_syms_node (syms depth) (do - (let (parent map) syms) - (for (ident sym) map (do - (println "%- %: %" (indent depth) ident sym) - )) - (if (!= parent null) (do - (print_syms_node parent (+ depth 1)) - )) - )) - - (fn print_syms () (do - (print_syms_node syms 0) - )) - - (return (list - enter_scope - leave_scope - define_sym - get_sym - get_current_map - print_syms - )) -)) - - -(fn string_escape (str) (do - (let str_len (len str)) - (let i 0) - (let result "") - (loop (do - (if (>= i str_len) (break)) - (let ch (at str i)) - (if (== ch "\\") (do - (+= result "\\\\") - ) (if (== ch "\"") (do - (+= result "\\\"") - ) (if (== ch "\t") (do - (+= result "\\t") - ) (if (== ch "\r") (do - (+= result "\\r") - ) (if (== ch "\n") (do - (+= result "\\n") - ) (if (== ch "\0") (do - (+= result "\\0") - ) (do - (+= result ch) - ))))))) - (+= i 1) - )) - (return result) -)) - -(fn Parser (tokens) (do - (let i 0) - (let tok (at tokens i)) - - (fn parse () (do - (let exprs (list)) - (loop (do - (if (done) (break)) - (push exprs (parse_expr)) - )) - (return exprs) - )) - - (fn parse_expr () (do - (let (ty line value) tok) - (if (eat "(") (do - (let values (list)) - (loop (do - (if (test ")") (break)) - (push values (parse_expr)) - )) - (if (not (eat ")")) (do - (panic "expected ')' on line %" (at tok 1)) - )) - (return (list "list" line values)) - ) (if (eat "string") (do - (return (list "string" line value)) - ) (if (eat "int") (do - (return (list "int" line (string_to_int value))) - ) (if (eat "ident") (do - (return (list "ident" line value)) - ) (do - (panic "expected expression, got '%' on line %" ty line) - ))))) - )) - - (fn eat (pat) (do - (if (not (test pat)) (return false)) - (step) - (return true) - )) - - (fn step () (do - (+= i 1) - (if (not (done)) (do - (let new_tok (at tokens i)) - (= tok new_tok) - )) - )) - - (fn test (pat) (do - (if (done) (return false)) - (let (ty) tok) - (return (== pat ty)) - )) - - (fn done () (do - (return (>= i (len tokens))) - )) - - (return (list parse)) -)) - -(fn tokenize (text) (do - (let text_len (len text)) - - (let tokens (list)) - (let i 0) - (let line 1) - - (let ident_chars (+ "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+-*/%&|=?!<>'_")) - - (loop (do - (if (>= i text_len) (break)) - - (let ch (at text i)) - - (if (contains " \t\r\n" ch) (do - (if (== ch "\n") (do - (+= line 1) - )) - (+= i 1) - ) (if (slice_eq text i "//") (do - (loop (do - (if (or (>= i text_len) (== (at text i) "\n")) (do - (break) - )) - (+= i 1) - )) - ) (if (contains "()" ch) (do - (push tokens (list ch line)) - (+= i 1) - ) (if (== ch "\"") (do - (let value "") - (+= i 1) - (= ch (at text i)) - (loop (do - (if (or (>= i text_len) (== ch "\"")) (do - (break) - )) - (if (== ch "\\") (do - (+= i 1) - (if (>= i text_len) (do - (break) - )) - (= ch (at text i)) - (if (== ch "t") (do - (+= value "\t") - ) (if (== ch "r") (do - (+= value "\r") - ) (if (== ch "n") (do - (+= value "\n") - ) (if (== ch "0") (do - (+= value "\n") - ) (do - (+= value ch) - ))))) - ) (do - (+= value ch) - )) - (+= i 1) - (= ch (at text i)) - )) - (if (or (>= i text_len) (!= ch "\"")) (do - (panic "expected '\"' on line %" line) - )) - (+= i 1) - (push tokens (list "string" line value)) - ) (if (contains "0123456789" ch) (do - (let value "") - (loop (do - (= ch (at text i)) - (if (or (>= i text_len) (not (contains "0123456789" ch))) (do - (break) - )) - (+= value ch) - (+= i 1) - )) - (push tokens (list "int" line value)) - ) (if (contains ident_chars ch) (do - (let value "") - (loop (do - (= ch (at text i)) - (if (or (>= i text_len) (not (contains ident_chars ch))) (do - (break) - )) - (+= value ch) - (+= i 1) - )) - (push tokens (list "ident" line value)) - ) (do - (println "illegal char '%'" ch) - (+= i 1) - ))))))) - )) - (return tokens) -)) - -(fn contains (text ch) (do - (let text_len (len text)) - (let i 0) - (loop (do - (if (>= i text_len) (break)) - (if (== (at text i) ch) (do - (return true) - )) - (+= i 1) - )) - (return false) -)) - -(fn slice_eq (str slice_idx substr) (do - (let str_len (len str)) - (let substr_len (len substr)) - (let i 0) - (loop (do - (if (>= i substr_len) - (return true)) - (if (>= (+ slice_idx i) str_len) - (return false)) - (if (!= (at str (+ slice_idx i)) (at substr i)) - (return false)) - (+= i 1) - )) - (return true) -)) +(import "stdlib.phi" (slice contains indent)) +(import "compiler/parse.phi" (Parser tokenize)) +(import "compiler/emit_js.phi" (Emitter)) (fn print_expr (expr depth) (do (let (ty line value) expr) @@ -821,29 +15,6 @@ )) )) -(fn indent (depth) (do - (let space "") - (let i 0) - (loop (do - (if (>= i depth) (break)) - (+= space " ") - (+= i 1) - )) - (return space) -)) - -(fn slice (list idx) (do - (let list_len (len list)) - (let elems (list)) - (let i idx) - (loop (do - (if (>= i list_len) (break)) - (push elems (at list i)) - (+= i 1) - )) - (return elems) -)) - (let (input_filename output_filename) (get_args)) (println "compiling '%'..." input_filename) diff --git a/compiler/emit_js.phi b/compiler/emit_js.phi new file mode 100644 index 0000000..ef2cd6e --- /dev/null +++ b/compiler/emit_js.phi @@ -0,0 +1,545 @@ +(import "stdlib.phi" (slice contains)) +(import "compiler/parse.phi" (Parser tokenize)) +(import "compiler/syms.phi" (Syms)) + +(fn Emitter (ast initial_filename) (do + (let output (list)) + (let filename initial_filename) + + (let syms (Syms)) + + (let (sym_id_count sym_id_increment) (Counter)) + (let (let_node_reg_count let_node_reg_increment) (Counter)) + + (let builtin_syms (list + (list "format" "builtinFormat") + (list "print" "builtinPrint") + (list "println" "builtinPrintln") + (list "panic" "builtinPanic") + (list "read_text_file" "builtinReadTextFile") + (list "write_text_file" "builtinWriteTextFile") + (list "push" "builtinPush") + (list "at" "builtinAt") + (list "set" "builtinSet") + (list "len" "builtinLen") + (list "string_to_int" "builtinStringToInt") + (list "char_code" "builtinCharCode") + (list "strings_join" "builtinStringsJoin") + (list "get_args" "builtinGetArgs") + )) + + (fn generate () (do + (emit "#!/usr/bin/env node\n") + (emit "import { Runtime } from \"./runtime.js\";\n") + (emit (format "const runtime = new Runtime(\"%\");\n" filename)) + + (for (ident builtin_id) builtin_syms (do + (define_builtin ident builtin_id) + )) + + (enter_scope) + (discover_syms ast) + (emit_exprs ast) + (return (strings_join output)) + )) + + (fn emit_exprs (exprs) (do + (for expr exprs (do + (emit_expr expr) + (emit ";\n") + )) + )) + + (fn discover_syms (exprs) (do + (for expr exprs (do + (let (ty line) expr) + (if (!= ty "list") (return)) + (let (_ _ s) expr) + (if (== (len s) 0) (return)) + (let ((_ _ id)) s) + (if (== id "fn") (do + (let (_ (_ _ ident) (_ _ params) body) s) + (define_fn ident line) + )) + )) + )) + + (fn emit_expr (expr) (do + (let (ty line) expr) + (if (== ty "list") (do + (emit_list expr) + ) (if (== ty "int") (do + (let (_ _ value) expr) + (emit (format "({ type: \"int\", value: % })" value)) + ) (if (== ty "string") (do + (let (_ _ value) expr) + (emit (format "({ type: \"string\", value: \"%\" })" (string_escape value))) + ) (if (== ty "ident") (do + (let (_ _ value) expr) + + (if (== value "null") (do + (emit "({ type: \"null\" })") + (return) + ) (if (== value "false") (do + (emit "({ type: \"bool\", value: false })") + (return) + ) (if (== value "true") (do + (emit "({ type: \"bool\", value: true })") + (return) + )))) + + (let sym (get_sym value)) + (if (== sym null) (do + (panic "undefined symbol '%' on line %" value line) + )) + + (let (sym_id sym_ty) sym) + (if (== sym_ty "builtin") (do + (let (_ _ id) sym) + (emit (format "((...args) => runtime.%(...args))" id)) + ) (if (== sym_ty "fn") (do + (emit (format "_%%" value sym_id)) + ) (if (== sym_ty "param") (do + (emit (format "_%%" value sym_id)) + ) (if (== sym_ty "let") (do + (emit (format "_%%" value sym_id)) + ) (if (== sym_ty "imported") (do + // this might give problems in the future. + // the solution is to feed the imported symbol + // back into this code, so that stuff gets + // handled appropriately. + (emit (format "_%%" value sym_id)) + ) (do + (panic "not implemented '%'" sym_ty) + )))))) + ) (do + (panic "unknown expr type '%' on line %" ty line) + ))))) + )) + + (fn emit_list (expr) (do + (let (ty line s) expr) + (if (== (len s) 0) (do + (panic "illegal function on line %" line) + )) + (let ((id_ty _ id)) s) + (if (!= id_ty "ident") (do + (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) + )) + + (enter_scope) + (discover_syms ast) + (emit_exprs ast) + (let sym_map (get_current_map)) + + (= syms outer_syms) + (= filename outer_filename) + + (emit (format "runtime.setFile(\"%\");\n" outer_filename)) + + (for (_ _ ident) idents (do + (let sym null) + (for (sym_ident found_sym) sym_map (do + (if (== sym_ident ident) (do + (= sym found_sym) + (break) + )) + )) + (if (== sym null) (do + (panic "no symbol '%' from imported '%'" ident filename) + )) + (let (_ sym_type) sym) + (if (== sym_type "imported") (do + (define_sym ident sym) + ) (do + (let (sym_id) sym) + (define_sym ident (list sym_id "imported" sym)) + )) + )) + ) (if (== id "fn") (do + (let (_ (_ _ ident) (_ _ params) body) s) + + (let sym (get_sym ident)) + (let (sym_id) sym) + + (emit (format "function _%%(" ident sym_id)) + + (enter_scope) + + (let first true) + (for (_ _ ident) params (do + (if (not first) (do + (emit ", ") + )) + (= first false) + + (let sym_id (define_param ident line)) + (emit (format "_%%" ident sym_id)) + )) + + + (emit ") {\n") + (emit (format "runtime.pushCall(\"%\", \"%\");\n" ident filename)) + + (emit_expr body) + (emit ";\nruntime.popCall();\nreturn { type: \"null\" };\n}") + + (leave_scope) + ) (if (== id "let") (do + (let (_ pat expr) s) + (let reg (let_node_reg_count)) + (let_node_reg_increment) + (emit (format "const r_% = " reg)) + (emit_expr expr) + (emit_let_node pat reg) + ) (if (== id "do") (do + (enter_scope) + (discover_syms (slice s 1)) + (emit_exprs (slice s 1)) + (leave_scope) + ) (if (== id "for") (do + (let (_ pat expr body) s) + + (let reg (let_node_reg_count)) + (let_node_reg_increment) + (emit (format "for (const r_% of " reg)) + (emit_expr expr) + (emit ".values) {") + + (enter_scope) + (emit_let_node pat reg) + (enter_scope) + + (emit ";\n") + (emit_expr body) + (emit "}") + + (leave_scope) + (leave_scope) + ) (if (== id "loop") (do + (let (_ body) s) + (emit "while (true) {\n") + (emit_expr body) + (emit "}") + ) (if (== id "if") (do + (let (_ cond truthy falsy) s) + (emit "if (runtime.truthy(") + (emit_expr cond) + (emit ")) {\n") + (emit_expr truthy) + (emit "}") + (if (!= falsy null) (do + (emit " else {\n") + (emit_expr falsy) + (emit "}") + )) + ) (if (== id "return") (do + (let (_ value) s) + (emit "runtime.popCall();\n") + (emit "return ") + (if (!= value null) (do + (emit_expr value) + ) (do + (emit "{ type: \"null\" }") + )) + ) (if (== id "break") (do + (let (_ value) s) + (emit "break") + (if (!= value null) (do + (panic "not implemented") + )) + ) (if (== id "call") (do + (let (_ callee) s) + (let args (slice s 2)) + (emit (format "(%, " (rt_info line))) + (emit_expr callee) + (emit "(") + + (let first true) + (for arg args (do + (if (not first) (do + (emit ", ") + )) + (= first false) + + (emit_expr arg) + )) + + (emit "))") + ) (if (== id "list") (do + (emit_list_literal (slice s 1)) + ) (if (== id "=") (do + (emit_assign_expr s line "=") + ) (if (== id "+=") (do + (emit_assign_expr s line "+") + ) (if (== id "-=") (do + (emit_assign_expr s line "-") + ) (if (== id "or") (do + (let (_ left right) s) + (emit (format "(%" (rt_info line) line)) + (emit ", { type: \"bool\", value: runtime.truthy(") + (emit_expr left) + (emit ") || runtime.truthy(") + (emit_expr right) + (emit ") })") + ) (if (== id "and") (do + (let (_ left right) s) + (emit (format "(%" (rt_info line) line)) + (emit ", { type: \"bool\", value: runtime.truthy(") + (emit_expr left) + (emit ") && runtime.truthy(") + (emit_expr right) + (emit ") })") + ) (if (== id "==") (do + (emit_binary_op s "opEq") + ) (if (== id "!=") (do + (emit_binary_op s "opNe") + ) (if (== id "<") (do + (emit_binary_op s "opLt") + ) (if (== id ">") (do + (emit_binary_op s "opGt") + ) (if (== id "<=") (do + (emit_binary_op s "opLte") + ) (if (== id ">=") (do + (emit_binary_op s "opGte") + ) (if (== id "+") (do + (emit_binary_op s "opAdd") + ) (if (== id "-") (do + (emit_binary_op s "opSub") + ) (if (== id "not") (do + (let (_ expr) s) + (emit "runtime.opNot(") + (emit_expr expr) + (emit ")") + ) (do + (let (callee) s) + (let args (slice s 1)) + (emit (format "(%, " (rt_info line) line)) + (emit_expr callee) + (emit "(") + + (let first true) + (for arg args (do + (if (not first) (do + (emit ", ") + )) + (= first false) + + (emit_expr arg) + )) + + (emit "))") + )))))))))))))))))))))))))) + )) + + (fn emit_list_literal (s) (do + (emit "({ type: \"list\", values: [") + (let first true) + (for e s (do + (if (not first) (do + (emit ", ") + )) + (= first false) + + (emit_expr e) + )) + (emit "] })") + )) + + (fn emit_let_node (pat base_reg) (do + (let (pat_ty line) pat) + (if (== pat_ty "ident") (do + (let (_ _ ident) pat) + + (if (== ident "_") (return)) + + (let sym_id (define_let ident line)) + (emit (format ";\nlet _%% = r_%" ident sym_id base_reg)) + ) (if (== pat_ty "list") (do + (let (_ _ pats) pat) + + (let i 0) + (for pat pats (do + (let reg (let_node_reg_count)) + (let_node_reg_increment) + (emit (format + ";\nconst r_% = r_%.values[%] ?? { type: \"null\"}" + reg base_reg i + )) + (emit_let_node pat reg) + (+= i 1) + )) + ) (do + (panic "malformed pattern on line %" line) + ))) + )) + + (fn emit_binary_op (s id) (do + (let ((_ line _) left right) s) + (emit (format "(%, runtime.%(" (rt_info line) id)) + (emit_expr left) + (emit ", ") + (emit_expr right) + (emit "))") + )) + + (fn rt_info (line) (do + (return (format "runtime.info(\"%\", %)" filename line)) + )) + + (fn emit_assign_expr (s line id) (do + (let (_ (target_type) expr) s) + (if (!= target_type "ident") (do + (panic "cannot assign to expression on line %" line) + )) + (let (_ (_ _ ident)) s) + (let sym (get_sym ident)) + (if (== sym null) (do + (panic "could not find symbol '%' on line %" ident line) + )) + (let (sym_id sym_type sym_ident _) sym) + (if (== sym_type "let") (do + (emit (format "(_%% = " sym_ident sym_id)) + (if (== id "=") (do + (emit_expr expr) + ) (if (== id "+") (do + (emit (format "runtime.opAdd(_%%, " sym_ident sym_id)) + (emit_expr expr) + (emit ")") + ) (if (== id "-") (do + (emit (format "runtime.opSub(_%%, " sym_ident sym_id)) + (emit_expr expr) + (emit ")") + ) (do + (panic "not implemented") + )))) + (emit ")") + ) (do + (panic "cannot assign to symbol '%' on line %" sym_ident line) + )) + )) + + (fn emit (str) (do + (push output str) + )) + + (fn define_builtin (ident builtin_id) (do + (let sym_id (sym_id_count)) + (sym_id_increment) + + (define_sym ident (list sym_id "builtin" builtin_id)) + (return sym_id) + )) + + (fn define_fn (ident line) (do + (let sym_id (sym_id_count)) + (sym_id_increment) + + (define_sym ident (list sym_id "fn" ident line)) + (return sym_id) + )) + + (fn define_param (ident line) (do + (let sym_id (sym_id_count)) + (sym_id_increment) + + (define_sym ident (list sym_id "param" ident line)) + (return sym_id) + )) + + (fn define_let (ident line) (do + (let sym_id (sym_id_count)) + (sym_id_increment) + + (define_sym ident (list sym_id "let" ident line)) + (return sym_id) + )) + + // indirection for syms + (fn enter_scope () (do + (let (enter_scope) syms) + (enter_scope) + )) + (fn leave_scope () (do + (let (_ leave_scope) syms) + (leave_scope) + )) + (fn define_sym (ident sym) (do + (let (_ _ define_sym) syms) + (return (define_sym ident sym)) + )) + (fn get_sym (ident) (do + (let (_ _ _ get_sym) syms) + (return (get_sym ident)) + )) + (fn get_current_map () (do + (let (_ _ _ _ get_current_map) syms) + (return (get_current_map)) + )) + (fn print_syms () (do + (let (_ _ _ _ _ print_syms) syms) + (print_syms) + )) + + (return (list generate)) +)) + +(fn Counter () (do + (let counter 0) + + (fn count () (do + (return counter) + )) + + (fn increment () (do + (+= counter 1) + )) + + (return (list count increment)) +)) + +(fn string_escape (str) (do + (let str_len (len str)) + (let i 0) + (let result "") + (loop (do + (if (>= i str_len) (break)) + (let ch (at str i)) + (if (== ch "\\") (do + (+= result "\\\\") + ) (if (== ch "\"") (do + (+= result "\\\"") + ) (if (== ch "\t") (do + (+= result "\\t") + ) (if (== ch "\r") (do + (+= result "\\r") + ) (if (== ch "\n") (do + (+= result "\\n") + ) (if (== ch "\0") (do + (+= result "\\0") + ) (do + (+= result ch) + ))))))) + (+= i 1) + )) + (return result) +)) diff --git a/compiler/parse.phi b/compiler/parse.phi new file mode 100644 index 0000000..e470b0f --- /dev/null +++ b/compiler/parse.phi @@ -0,0 +1,160 @@ +(import "stdlib.phi" (slice slice_eq contains)) + +(fn Parser (tokens) (do + (let i 0) + (let tok (at tokens i)) + + (fn parse () (do + (let exprs (list)) + (loop (do + (if (done) (break)) + (push exprs (parse_expr)) + )) + (return exprs) + )) + + (fn parse_expr () (do + (let (ty line value) tok) + (if (eat "(") (do + (let values (list)) + (loop (do + (if (test ")") (break)) + (push values (parse_expr)) + )) + (if (not (eat ")")) (do + (panic "expected ')' on line %" (at tok 1)) + )) + (return (list "list" line values)) + ) (if (eat "string") (do + (return (list "string" line value)) + ) (if (eat "int") (do + (return (list "int" line (string_to_int value))) + ) (if (eat "ident") (do + (return (list "ident" line value)) + ) (do + (panic "expected expression, got '%' on line %" ty line) + ))))) + )) + + (fn eat (pat) (do + (if (not (test pat)) (return false)) + (step) + (return true) + )) + + (fn step () (do + (+= i 1) + (if (not (done)) (do + (let new_tok (at tokens i)) + (= tok new_tok) + )) + )) + + (fn test (pat) (do + (if (done) (return false)) + (let (ty) tok) + (return (== pat ty)) + )) + + (fn done () (do + (return (>= i (len tokens))) + )) + + (return (list parse)) +)) + +(fn tokenize (text) (do + (let text_len (len text)) + + (let tokens (list)) + (let i 0) + (let line 1) + + (let ident_chars (+ "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+-*/%&|=?!<>'_")) + + (loop (do + (if (>= i text_len) (break)) + + (let ch (at text i)) + + (if (contains " \t\r\n" ch) (do + (if (== ch "\n") (do + (+= line 1) + )) + (+= i 1) + ) (if (slice_eq text i "//") (do + (loop (do + (if (or (>= i text_len) (== (at text i) "\n")) (do + (break) + )) + (+= i 1) + )) + ) (if (contains "()" ch) (do + (push tokens (list ch line)) + (+= i 1) + ) (if (== ch "\"") (do + (let value "") + (+= i 1) + (= ch (at text i)) + (loop (do + (if (or (>= i text_len) (== ch "\"")) (do + (break) + )) + (if (== ch "\\") (do + (+= i 1) + (if (>= i text_len) (do + (break) + )) + (= ch (at text i)) + (if (== ch "t") (do + (+= value "\t") + ) (if (== ch "r") (do + (+= value "\r") + ) (if (== ch "n") (do + (+= value "\n") + ) (if (== ch "0") (do + (+= value "\n") + ) (do + (+= value ch) + ))))) + ) (do + (+= value ch) + )) + (+= i 1) + (= ch (at text i)) + )) + (if (or (>= i text_len) (!= ch "\"")) (do + (panic "expected '\"' on line %" line) + )) + (+= i 1) + (push tokens (list "string" line value)) + ) (if (contains "0123456789" ch) (do + (let value "") + (loop (do + (= ch (at text i)) + (if (or (>= i text_len) (not (contains "0123456789" ch))) (do + (break) + )) + (+= value ch) + (+= i 1) + )) + (push tokens (list "int" line value)) + ) (if (contains ident_chars ch) (do + (let value "") + (loop (do + (= ch (at text i)) + (if (or (>= i text_len) (not (contains ident_chars ch))) (do + (break) + )) + (+= value ch) + (+= i 1) + )) + (push tokens (list "ident" line value)) + ) (do + (println "illegal char '%'" ch) + (+= i 1) + ))))))) + )) + (return tokens) +)) diff --git a/compiler/syms.phi b/compiler/syms.phi new file mode 100644 index 0000000..6ec155f --- /dev/null +++ b/compiler/syms.phi @@ -0,0 +1,79 @@ +(import "stdlib.phi" (indent)) + +(fn Syms () (do + (let syms (list null (list))) + + (fn enter_scope () (do + (= syms (list syms (list))) + )) + + (fn leave_scope () (do + (let (parent _) syms) + (= syms parent) + )) + + (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)) + )) + + (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 (!= parent null) (do + (return (find_sym parent ident)) + )) + (return null) + )) + + (fn get_sym (ident) (do + (return (find_sym syms ident)) + )) + + (fn get_current_map () (do + (let (_ map) syms) + (return map) + )) + + (fn print_syms_node (syms depth) (do + (let (parent map) syms) + (for (ident sym) map (do + (println "%- %: %" (indent depth) ident sym) + )) + (if (!= parent null) (do + (print_syms_node parent (+ depth 1)) + )) + )) + + (fn print_syms () (do + (print_syms_node syms 0) + )) + + (return (list + enter_scope + leave_scope + define_sym + get_sym + get_current_map + print_syms + )) +)) + diff --git a/runtime.js b/runtime.js index 1b809df..c38653e 100644 --- a/runtime.js +++ b/runtime.js @@ -12,10 +12,6 @@ export class Runtime { this.currentFilename = filename; } - setLine(line) { - this.currentLine = line; - } - info(filename, line) { this.currentFilename = filename; this.currentLine = line; diff --git a/stage2.js b/stage2.js index fb6734e..9d53008 100644 --- a/stage2.js +++ b/stage2.js @@ -1,1286 +1,67 @@ #!/usr/bin/env node import { Runtime } from "./runtime.js"; const runtime = new Runtime("compile.phi"); -function _Emitter14(_ast25, _initial_filename26) { -runtime.pushCall("Emitter", "compile.phi"); -const r_0 = ({ type: "list", values: [] }); -let _output48 = r_0; -const r_1 = _initial_filename26; -let _filename49 = r_1; -const r_2 = (runtime.info("compile.phi", 6), _Syms16()); -let _syms50 = r_2; -const r_3 = (runtime.info("compile.phi", 8), _Counter15()); -const r_4 = r_3.values[0] ?? { type: "null"}; -let _sym_id_count51 = r_4; -const r_5 = r_3.values[1] ?? { type: "null"}; -let _sym_id_increment52 = r_5; -const r_6 = (runtime.info("compile.phi", 9), _Counter15()); -const r_7 = r_6.values[0] ?? { type: "null"}; -let _let_node_reg_count53 = r_7; -const r_8 = r_6.values[1] ?? { type: "null"}; -let _let_node_reg_increment54 = r_8; -const r_9 = ({ 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_syms55 = r_9; -function _generate27() { -runtime.pushCall("generate", "compile.phi"); -(runtime.info("compile.phi", 29), _emit37(({ type: "string", value: "#!/usr/bin/env node\n" }))); -(runtime.info("compile.phi", 30), _emit37(({ type: "string", value: "import { Runtime } from \"./runtime.js\";\n" }))); -(runtime.info("compile.phi", 31), _emit37((runtime.info("compile.phi", 31), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "const runtime = new Runtime(\"%\");\n" }), _filename49)))); -for (const r_10 of _builtin_syms55.values) {; -const r_11 = r_10.values[0] ?? { type: "null"}; -let _ident56 = r_11; -const r_12 = r_10.values[1] ?? { type: "null"}; -let _builtin_id57 = r_12; -(runtime.info("compile.phi", 34), _define_builtin38(_ident56, _builtin_id57)); -}; -(runtime.info("compile.phi", 37), _enter_scope42()); -(runtime.info("compile.phi", 38), _discover_syms29(_ast25)); -(runtime.info("compile.phi", 39), _emit_exprs28(_ast25)); -runtime.popCall(); -return (runtime.info("compile.phi", 40), ((...args) => runtime.builtinStringsJoin(...args))(_output48)); -; -runtime.popCall(); -return { type: "null" }; -}; -function _emit_exprs28(_exprs58) { -runtime.pushCall("emit_exprs", "compile.phi"); -for (const r_13 of _exprs58.values) {; -let _expr59 = r_13; -(runtime.info("compile.phi", 45), _emit_expr30(_expr59)); -(runtime.info("compile.phi", 46), _emit37(({ type: "string", value: ";\n" }))); -}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _discover_syms29(_exprs60) { -runtime.pushCall("discover_syms", "compile.phi"); -for (const r_14 of _exprs60.values) {; -let _expr61 = r_14; -const r_15 = _expr61; -const r_16 = r_15.values[0] ?? { type: "null"}; -let _ty62 = r_16; -const r_17 = r_15.values[1] ?? { type: "null"}; -let _line63 = r_17; -if (runtime.truthy((runtime.info("compile.phi", 53), runtime.opNe(_ty62, ({ type: "string", value: "list" }))))) { -runtime.popCall(); -return { type: "null" }}; -const r_18 = _expr61; -const r_19 = r_18.values[0] ?? { type: "null"}; -const r_20 = r_18.values[1] ?? { type: "null"}; -const r_21 = r_18.values[2] ?? { type: "null"}; -let _s64 = r_21; -if (runtime.truthy((runtime.info("compile.phi", 55), runtime.opEq((runtime.info("compile.phi", 55), ((...args) => runtime.builtinLen(...args))(_s64)), ({ type: "int", value: 0 }))))) { -runtime.popCall(); -return { type: "null" }}; -const r_22 = _s64; -const r_23 = r_22.values[0] ?? { type: "null"}; -const r_24 = r_23.values[0] ?? { type: "null"}; -const r_25 = r_23.values[1] ?? { type: "null"}; -const r_26 = r_23.values[2] ?? { type: "null"}; -let _id65 = r_26; -if (runtime.truthy((runtime.info("compile.phi", 57), runtime.opEq(_id65, ({ type: "string", value: "fn" }))))) { -const r_27 = _s64; -const r_28 = r_27.values[0] ?? { type: "null"}; -const r_29 = r_27.values[1] ?? { type: "null"}; -const r_30 = r_29.values[0] ?? { type: "null"}; -const r_31 = r_29.values[1] ?? { type: "null"}; -const r_32 = r_29.values[2] ?? { type: "null"}; -let _ident66 = r_32; -const r_33 = r_27.values[2] ?? { type: "null"}; -const r_34 = r_33.values[0] ?? { type: "null"}; -const r_35 = r_33.values[1] ?? { type: "null"}; -const r_36 = r_33.values[2] ?? { type: "null"}; -let _params67 = r_36; -const r_37 = r_27.values[3] ?? { type: "null"}; -let _body68 = r_37; -(runtime.info("compile.phi", 59), _define_fn39(_ident66, _line63)); -}; -}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _emit_expr30(_expr69) { -runtime.pushCall("emit_expr", "compile.phi"); -const r_38 = _expr69; -const r_39 = r_38.values[0] ?? { type: "null"}; -let _ty70 = r_39; -const r_40 = r_38.values[1] ?? { type: "null"}; -let _line71 = r_40; -if (runtime.truthy((runtime.info("compile.phi", 66), runtime.opEq(_ty70, ({ type: "string", value: "list" }))))) { -(runtime.info("compile.phi", 67), _emit_list31(_expr69)); -} else { -if (runtime.truthy((runtime.info("compile.phi", 68), runtime.opEq(_ty70, ({ type: "string", value: "int" }))))) { -const r_41 = _expr69; -const r_42 = r_41.values[0] ?? { type: "null"}; -const r_43 = r_41.values[1] ?? { type: "null"}; -const r_44 = r_41.values[2] ?? { type: "null"}; -let _value72 = r_44; -(runtime.info("compile.phi", 70), _emit37((runtime.info("compile.phi", 70), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "({ type: \"int\", value: % })" }), _value72)))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 71), runtime.opEq(_ty70, ({ type: "string", value: "string" }))))) { -const r_45 = _expr69; -const r_46 = r_45.values[0] ?? { type: "null"}; -const r_47 = r_45.values[1] ?? { type: "null"}; -const r_48 = r_45.values[2] ?? { type: "null"}; -let _value73 = r_48; -(runtime.info("compile.phi", 73), _emit37((runtime.info("compile.phi", 73), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "({ type: \"string\", value: \"%\" })" }), (runtime.info("compile.phi", 73), _string_escape17(_value73)))))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 74), runtime.opEq(_ty70, ({ type: "string", value: "ident" }))))) { -const r_49 = _expr69; -const r_50 = r_49.values[0] ?? { type: "null"}; -const r_51 = r_49.values[1] ?? { type: "null"}; -const r_52 = r_49.values[2] ?? { type: "null"}; -let _value74 = r_52; -if (runtime.truthy((runtime.info("compile.phi", 77), runtime.opEq(_value74, ({ type: "string", value: "null" }))))) { -(runtime.info("compile.phi", 78), _emit37(({ type: "string", value: "({ type: \"null\" })" }))); -runtime.popCall(); -return { type: "null" }; -} else { -if (runtime.truthy((runtime.info("compile.phi", 80), runtime.opEq(_value74, ({ type: "string", value: "false" }))))) { -(runtime.info("compile.phi", 81), _emit37(({ type: "string", value: "({ type: \"bool\", value: false })" }))); -runtime.popCall(); -return { type: "null" }; -} else { -if (runtime.truthy((runtime.info("compile.phi", 83), runtime.opEq(_value74, ({ type: "string", value: "true" }))))) { -(runtime.info("compile.phi", 84), _emit37(({ type: "string", value: "({ type: \"bool\", value: true })" }))); -runtime.popCall(); -return { type: "null" }; -}}}; -const r_53 = (runtime.info("compile.phi", 88), _get_sym45(_value74)); -let _sym75 = r_53; -if (runtime.truthy((runtime.info("compile.phi", 89), runtime.opEq(_sym75, ({ type: "null" }))))) { -(runtime.info("compile.phi", 90), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "undefined symbol '%' on line %" }), _value74, _line71)); -}; -const r_54 = _sym75; -const r_55 = r_54.values[0] ?? { type: "null"}; -let _sym_id76 = r_55; -const r_56 = r_54.values[1] ?? { type: "null"}; -let _sym_ty77 = r_56; -if (runtime.truthy((runtime.info("compile.phi", 94), runtime.opEq(_sym_ty77, ({ type: "string", value: "builtin" }))))) { -const r_57 = _sym75; -const r_58 = r_57.values[0] ?? { type: "null"}; -const r_59 = r_57.values[1] ?? { type: "null"}; -const r_60 = r_57.values[2] ?? { type: "null"}; -let _id78 = r_60; -(runtime.info("compile.phi", 96), _emit37((runtime.info("compile.phi", 96), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "((...args) => runtime.%(...args))" }), _id78)))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 97), runtime.opEq(_sym_ty77, ({ type: "string", value: "fn" }))))) { -(runtime.info("compile.phi", 98), _emit37((runtime.info("compile.phi", 98), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "_%%" }), _value74, _sym_id76)))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 99), runtime.opEq(_sym_ty77, ({ type: "string", value: "param" }))))) { -(runtime.info("compile.phi", 100), _emit37((runtime.info("compile.phi", 100), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "_%%" }), _value74, _sym_id76)))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 101), runtime.opEq(_sym_ty77, ({ type: "string", value: "let" }))))) { -(runtime.info("compile.phi", 102), _emit37((runtime.info("compile.phi", 102), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "_%%" }), _value74, _sym_id76)))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 103), runtime.opEq(_sym_ty77, ({ type: "string", value: "imported" }))))) { -(runtime.info("compile.phi", 108), _emit37((runtime.info("compile.phi", 108), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "_%%" }), _value74, _sym_id76)))); -} else { -(runtime.info("compile.phi", 110), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "not implemented '%'" }), _sym_ty77)); -}}}}}; -} else { -(runtime.info("compile.phi", 113), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "unknown expr type '%' on line %" }), _ty70, _line71)); -}}}}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _emit_list31(_expr79) { -runtime.pushCall("emit_list", "compile.phi"); -const r_61 = _expr79; -const r_62 = r_61.values[0] ?? { type: "null"}; -let _ty80 = r_62; -const r_63 = r_61.values[1] ?? { type: "null"}; -let _line81 = r_63; -const r_64 = r_61.values[2] ?? { type: "null"}; -let _s82 = r_64; -if (runtime.truthy((runtime.info("compile.phi", 119), runtime.opEq((runtime.info("compile.phi", 119), ((...args) => runtime.builtinLen(...args))(_s82)), ({ type: "int", value: 0 }))))) { -(runtime.info("compile.phi", 120), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "illegal function on line %" }), _line81)); -}; -const r_65 = _s82; -const r_66 = r_65.values[0] ?? { type: "null"}; -const r_67 = r_66.values[0] ?? { type: "null"}; -let _id_ty83 = r_67; -const r_68 = r_66.values[1] ?? { type: "null"}; -const r_69 = r_66.values[2] ?? { type: "null"}; -let _id84 = r_69; -if (runtime.truthy((runtime.info("compile.phi", 123), runtime.opNe(_id_ty83, ({ type: "string", value: "ident" }))))) { -(runtime.info("compile.phi", 124), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "illegal function on line %" }), _line81)); -}; -if (runtime.truthy((runtime.info("compile.phi", 126), runtime.opEq(_id84, ({ type: "string", value: "import" }))))) { -const r_70 = _filename49; -let _outer_filename85 = r_70; -const r_71 = _s82; -const r_72 = r_71.values[0] ?? { type: "null"}; -const r_73 = r_71.values[1] ?? { type: "null"}; -const r_74 = r_73.values[0] ?? { type: "null"}; -const r_75 = r_73.values[1] ?? { type: "null"}; -const r_76 = r_73.values[2] ?? { type: "null"}; -let _inner_filename86 = r_76; -const r_77 = r_71.values[2] ?? { type: "null"}; -const r_78 = r_77.values[0] ?? { type: "null"}; -const r_79 = r_77.values[1] ?? { type: "null"}; -const r_80 = r_77.values[2] ?? { type: "null"}; -let _idents87 = r_80; -(_filename49 = _inner_filename86); -const r_81 = (runtime.info("compile.phi", 131), ((...args) => runtime.builtinReadTextFile(...args))(_filename49)); -let _text88 = r_81; -const r_82 = (runtime.info("compile.phi", 132), _tokenize19(_text88)); -let _tokens89 = r_82; -const r_83 = (runtime.info("compile.phi", 133), _Parser18(_tokens89)); -let _parser90 = r_83; -const r_84 = _parser90; -const r_85 = r_84.values[0] ?? { type: "null"}; -let _parse91 = r_85; -const r_86 = (runtime.info("compile.phi", 135), _parse91()); -let _ast92 = r_86; -const r_87 = (runtime.info("compile.phi", 136), _Emitter14(_ast92, _filename49)); -const r_88 = r_87.values[0] ?? { type: "null"}; -const r_89 = r_87.values[1] ?? { type: "null"}; -let _generate_imported93 = r_89; -(runtime.info("compile.phi", 138), _emit37((runtime.info("compile.phi", 138), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.setFile(\"%\");\n" }), _filename49)))); -const r_90 = _syms50; -let _outer_syms94 = r_90; -(_syms50 = (runtime.info("compile.phi", 141), _Syms16())); -for (const r_91 of _builtin_syms55.values) {; -const r_92 = r_91.values[0] ?? { type: "null"}; -let _ident95 = r_92; -const r_93 = r_91.values[1] ?? { type: "null"}; -let _builtin_id96 = r_93; -(runtime.info("compile.phi", 143), _define_builtin38(_ident95, _builtin_id96)); -}; -(runtime.info("compile.phi", 146), _enter_scope42()); -(runtime.info("compile.phi", 147), _discover_syms29(_ast92)); -(runtime.info("compile.phi", 148), _emit_exprs28(_ast92)); -const r_94 = (runtime.info("compile.phi", 149), _get_current_map46()); -let _sym_map97 = r_94; -(_syms50 = _outer_syms94); -(_filename49 = _outer_filename85); -(runtime.info("compile.phi", 154), _emit37((runtime.info("compile.phi", 154), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.setFile(\"%\");\n" }), _outer_filename85)))); -for (const r_95 of _idents87.values) {; -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 _ident98 = r_98; -const r_99 = ({ type: "null" }); -let _sym99 = r_99; -for (const r_100 of _sym_map97.values) {; -const r_101 = r_100.values[0] ?? { type: "null"}; -let _sym_ident100 = r_101; -const r_102 = r_100.values[1] ?? { type: "null"}; -let _found_sym101 = r_102; -if (runtime.truthy((runtime.info("compile.phi", 159), runtime.opEq(_sym_ident100, _ident98)))) { -(_sym99 = _found_sym101); -break; -}; -}; -if (runtime.truthy((runtime.info("compile.phi", 164), runtime.opEq(_sym99, ({ type: "null" }))))) { -(runtime.info("compile.phi", 165), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "sym_map = %" }), _sym_map97)); -(runtime.info("compile.phi", 166), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "no symbol '%' from imported '%'" }), _ident98, _filename49)); -}; -const r_103 = _sym99; -const r_104 = r_103.values[0] ?? { type: "null"}; -const r_105 = r_103.values[1] ?? { type: "null"}; -let _sym_type102 = r_105; -if (runtime.truthy((runtime.info("compile.phi", 169), runtime.opEq(_sym_type102, ({ type: "string", value: "imported" }))))) { -(runtime.info("compile.phi", 170), _define_sym44(_ident98, _sym99)); -} else { -const r_106 = _sym99; -const r_107 = r_106.values[0] ?? { type: "null"}; -let _sym_id103 = r_107; -(runtime.info("compile.phi", 173), _define_sym44(_ident98, ({ type: "list", values: [_sym_id103, ({ type: "string", value: "imported" }), _sym99] }))); -}; -}; -} else { -if (runtime.truthy((runtime.info("compile.phi", 176), runtime.opEq(_id84, ({ type: "string", value: "fn" }))))) { -const r_108 = _s82; -const r_109 = r_108.values[0] ?? { type: "null"}; -const r_110 = r_108.values[1] ?? { type: "null"}; -const r_111 = r_110.values[0] ?? { type: "null"}; -const r_112 = r_110.values[1] ?? { type: "null"}; -const r_113 = r_110.values[2] ?? { type: "null"}; -let _ident104 = r_113; -const r_114 = r_108.values[2] ?? { type: "null"}; -const r_115 = r_114.values[0] ?? { type: "null"}; -const r_116 = r_114.values[1] ?? { type: "null"}; -const r_117 = r_114.values[2] ?? { type: "null"}; -let _params105 = r_117; -const r_118 = r_108.values[3] ?? { type: "null"}; -let _body106 = r_118; -const r_119 = (runtime.info("compile.phi", 179), _get_sym45(_ident104)); -let _sym107 = r_119; -const r_120 = _sym107; -const r_121 = r_120.values[0] ?? { type: "null"}; -let _sym_id108 = r_121; -(runtime.info("compile.phi", 182), _emit37((runtime.info("compile.phi", 182), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "function _%%(" }), _ident104, _sym_id108)))); -(runtime.info("compile.phi", 184), _enter_scope42()); -const r_122 = ({ type: "bool", value: true }); -let _first109 = r_122; -for (const r_123 of _params105.values) {; -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 _ident110 = r_126; -if (runtime.truthy(runtime.opNot(_first109))) { -(runtime.info("compile.phi", 189), _emit37(({ type: "string", value: ", " }))); -}; -(_first109 = ({ type: "bool", value: false })); -const r_127 = (runtime.info("compile.phi", 193), _define_param40(_ident110, _line81)); -let _sym_id111 = r_127; -(runtime.info("compile.phi", 194), _emit37((runtime.info("compile.phi", 194), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "_%%" }), _ident110, _sym_id111)))); -}; -(runtime.info("compile.phi", 198), _emit37(({ type: "string", value: ") {\n" }))); -(runtime.info("compile.phi", 199), _emit37((runtime.info("compile.phi", 199), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.pushCall(\"%\", \"%\");\n" }), _ident104, _filename49)))); -(runtime.info("compile.phi", 201), _emit_expr30(_body106)); -(runtime.info("compile.phi", 202), _emit37(({ type: "string", value: ";\nruntime.popCall();\nreturn { type: \"null\" };\n}" }))); -(runtime.info("compile.phi", 204), _leave_scope43()); -} else { -if (runtime.truthy((runtime.info("compile.phi", 205), runtime.opEq(_id84, ({ type: "string", value: "let" }))))) { -const r_128 = _s82; -const r_129 = r_128.values[0] ?? { type: "null"}; -const r_130 = r_128.values[1] ?? { type: "null"}; -let _pat112 = r_130; -const r_131 = r_128.values[2] ?? { type: "null"}; -let _expr113 = r_131; -const r_132 = (runtime.info("compile.phi", 207), _let_node_reg_count53()); -let _reg114 = r_132; -(runtime.info("compile.phi", 208), _let_node_reg_increment54()); -(runtime.info("compile.phi", 209), _emit37((runtime.info("compile.phi", 209), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "const r_% = " }), _reg114)))); -(runtime.info("compile.phi", 210), _emit_expr30(_expr113)); -(runtime.info("compile.phi", 211), _emit_let_node33(_pat112, _reg114)); -} else { -if (runtime.truthy((runtime.info("compile.phi", 212), runtime.opEq(_id84, ({ type: "string", value: "do" }))))) { -(runtime.info("compile.phi", 213), _enter_scope42()); -(runtime.info("compile.phi", 214), _discover_syms29((runtime.info("compile.phi", 214), _slice24(_s82, ({ type: "int", value: 1 }))))); -(runtime.info("compile.phi", 215), _emit_exprs28((runtime.info("compile.phi", 215), _slice24(_s82, ({ type: "int", value: 1 }))))); -(runtime.info("compile.phi", 216), _leave_scope43()); -} else { -if (runtime.truthy((runtime.info("compile.phi", 217), runtime.opEq(_id84, ({ type: "string", value: "for" }))))) { -const r_133 = _s82; -const r_134 = r_133.values[0] ?? { type: "null"}; -const r_135 = r_133.values[1] ?? { type: "null"}; -let _pat115 = r_135; -const r_136 = r_133.values[2] ?? { type: "null"}; -let _expr116 = r_136; -const r_137 = r_133.values[3] ?? { type: "null"}; -let _body117 = r_137; -const r_138 = (runtime.info("compile.phi", 220), _let_node_reg_count53()); -let _reg118 = r_138; -(runtime.info("compile.phi", 221), _let_node_reg_increment54()); -(runtime.info("compile.phi", 222), _emit37((runtime.info("compile.phi", 222), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "for (const r_% of " }), _reg118)))); -(runtime.info("compile.phi", 223), _emit_expr30(_expr116)); -(runtime.info("compile.phi", 224), _emit37(({ type: "string", value: ".values) {" }))); -(runtime.info("compile.phi", 226), _enter_scope42()); -(runtime.info("compile.phi", 227), _emit_let_node33(_pat115, _reg118)); -(runtime.info("compile.phi", 228), _enter_scope42()); -(runtime.info("compile.phi", 230), _emit37(({ type: "string", value: ";\n" }))); -(runtime.info("compile.phi", 231), _emit_expr30(_body117)); -(runtime.info("compile.phi", 232), _emit37(({ type: "string", value: "}" }))); -(runtime.info("compile.phi", 234), _leave_scope43()); -(runtime.info("compile.phi", 235), _leave_scope43()); -} else { -if (runtime.truthy((runtime.info("compile.phi", 236), runtime.opEq(_id84, ({ type: "string", value: "loop" }))))) { -const r_139 = _s82; -const r_140 = r_139.values[0] ?? { type: "null"}; -const r_141 = r_139.values[1] ?? { type: "null"}; -let _body119 = r_141; -(runtime.info("compile.phi", 238), _emit37(({ type: "string", value: "while (true) {\n" }))); -(runtime.info("compile.phi", 239), _emit_expr30(_body119)); -(runtime.info("compile.phi", 240), _emit37(({ type: "string", value: "}" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 241), runtime.opEq(_id84, ({ type: "string", value: "if" }))))) { -const r_142 = _s82; -const r_143 = r_142.values[0] ?? { type: "null"}; -const r_144 = r_142.values[1] ?? { type: "null"}; -let _cond120 = r_144; -const r_145 = r_142.values[2] ?? { type: "null"}; -let _truthy121 = r_145; -const r_146 = r_142.values[3] ?? { type: "null"}; -let _falsy122 = r_146; -(runtime.info("compile.phi", 243), _emit37(({ type: "string", value: "if (runtime.truthy(" }))); -(runtime.info("compile.phi", 244), _emit_expr30(_cond120)); -(runtime.info("compile.phi", 245), _emit37(({ type: "string", value: ")) {\n" }))); -(runtime.info("compile.phi", 246), _emit_expr30(_truthy121)); -(runtime.info("compile.phi", 247), _emit37(({ type: "string", value: "}" }))); -if (runtime.truthy((runtime.info("compile.phi", 248), runtime.opNe(_falsy122, ({ type: "null" }))))) { -(runtime.info("compile.phi", 249), _emit37(({ type: "string", value: " else {\n" }))); -(runtime.info("compile.phi", 250), _emit_expr30(_falsy122)); -(runtime.info("compile.phi", 251), _emit37(({ type: "string", value: "}" }))); -}; -} else { -if (runtime.truthy((runtime.info("compile.phi", 253), runtime.opEq(_id84, ({ type: "string", value: "return" }))))) { -const r_147 = _s82; -const r_148 = r_147.values[0] ?? { type: "null"}; -const r_149 = r_147.values[1] ?? { type: "null"}; -let _value123 = r_149; -(runtime.info("compile.phi", 255), _emit37(({ type: "string", value: "runtime.popCall();\n" }))); -(runtime.info("compile.phi", 256), _emit37(({ type: "string", value: "return " }))); -if (runtime.truthy((runtime.info("compile.phi", 257), runtime.opNe(_value123, ({ type: "null" }))))) { -(runtime.info("compile.phi", 258), _emit_expr30(_value123)); -} else { -(runtime.info("compile.phi", 260), _emit37(({ type: "string", value: "{ type: \"null\" }" }))); -}; -} else { -if (runtime.truthy((runtime.info("compile.phi", 262), runtime.opEq(_id84, ({ type: "string", value: "break" }))))) { -const r_150 = _s82; -const r_151 = r_150.values[0] ?? { type: "null"}; -const r_152 = r_150.values[1] ?? { type: "null"}; -let _value124 = r_152; -(runtime.info("compile.phi", 264), _emit37(({ type: "string", value: "break" }))); -if (runtime.truthy((runtime.info("compile.phi", 265), runtime.opNe(_value124, ({ type: "null" }))))) { -(runtime.info("compile.phi", 266), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "not implemented" }))); -}; -} else { -if (runtime.truthy((runtime.info("compile.phi", 268), runtime.opEq(_id84, ({ type: "string", value: "call" }))))) { -const r_153 = _s82; -const r_154 = r_153.values[0] ?? { type: "null"}; -const r_155 = r_153.values[1] ?? { type: "null"}; -let _callee125 = r_155; -const r_156 = (runtime.info("compile.phi", 270), _slice24(_s82, ({ type: "int", value: 2 }))); -let _args126 = r_156; -(runtime.info("compile.phi", 271), _emit37((runtime.info("compile.phi", 271), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(%, " }), (runtime.info("compile.phi", 271), _rt_info35(_line81)))))); -(runtime.info("compile.phi", 272), _emit_expr30(_callee125)); -(runtime.info("compile.phi", 273), _emit37(({ type: "string", value: "(" }))); -const r_157 = ({ type: "bool", value: true }); -let _first127 = r_157; -for (const r_158 of _args126.values) {; -let _arg128 = r_158; -if (runtime.truthy(runtime.opNot(_first127))) { -(runtime.info("compile.phi", 278), _emit37(({ type: "string", value: ", " }))); -}; -(_first127 = ({ type: "bool", value: false })); -(runtime.info("compile.phi", 282), _emit_expr30(_arg128)); -}; -(runtime.info("compile.phi", 285), _emit37(({ type: "string", value: "))" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 286), runtime.opEq(_id84, ({ type: "string", value: "list" }))))) { -(runtime.info("compile.phi", 287), _emit_list_literal32((runtime.info("compile.phi", 287), _slice24(_s82, ({ type: "int", value: 1 }))))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 288), runtime.opEq(_id84, ({ type: "string", value: "=" }))))) { -(runtime.info("compile.phi", 289), _emit_assign_expr36(_s82, _line81, ({ type: "string", value: "=" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 290), runtime.opEq(_id84, ({ type: "string", value: "+=" }))))) { -(runtime.info("compile.phi", 291), _emit_assign_expr36(_s82, _line81, ({ type: "string", value: "+" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 292), runtime.opEq(_id84, ({ type: "string", value: "-=" }))))) { -(runtime.info("compile.phi", 293), _emit_assign_expr36(_s82, _line81, ({ type: "string", value: "-" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 294), runtime.opEq(_id84, ({ type: "string", value: "or" }))))) { -const r_159 = _s82; -const r_160 = r_159.values[0] ?? { type: "null"}; -const r_161 = r_159.values[1] ?? { type: "null"}; -let _left129 = r_161; -const r_162 = r_159.values[2] ?? { type: "null"}; -let _right130 = r_162; -(runtime.info("compile.phi", 296), _emit37((runtime.info("compile.phi", 296), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(%" }), (runtime.info("compile.phi", 296), _rt_info35(_line81)), _line81)))); -(runtime.info("compile.phi", 297), _emit37(({ type: "string", value: ", { type: \"bool\", value: runtime.truthy(" }))); -(runtime.info("compile.phi", 298), _emit_expr30(_left129)); -(runtime.info("compile.phi", 299), _emit37(({ type: "string", value: ") || runtime.truthy(" }))); -(runtime.info("compile.phi", 300), _emit_expr30(_right130)); -(runtime.info("compile.phi", 301), _emit37(({ type: "string", value: ") })" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 302), runtime.opEq(_id84, ({ type: "string", value: "and" }))))) { -const r_163 = _s82; -const r_164 = r_163.values[0] ?? { type: "null"}; -const r_165 = r_163.values[1] ?? { type: "null"}; -let _left131 = r_165; -const r_166 = r_163.values[2] ?? { type: "null"}; -let _right132 = r_166; -(runtime.info("compile.phi", 304), _emit37((runtime.info("compile.phi", 304), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(%" }), (runtime.info("compile.phi", 304), _rt_info35(_line81)), _line81)))); -(runtime.info("compile.phi", 305), _emit37(({ type: "string", value: ", { type: \"bool\", value: runtime.truthy(" }))); -(runtime.info("compile.phi", 306), _emit_expr30(_left131)); -(runtime.info("compile.phi", 307), _emit37(({ type: "string", value: ") && runtime.truthy(" }))); -(runtime.info("compile.phi", 308), _emit_expr30(_right132)); -(runtime.info("compile.phi", 309), _emit37(({ type: "string", value: ") })" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 310), runtime.opEq(_id84, ({ type: "string", value: "==" }))))) { -(runtime.info("compile.phi", 311), _emit_binary_op34(_s82, ({ type: "string", value: "opEq" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 312), runtime.opEq(_id84, ({ type: "string", value: "!=" }))))) { -(runtime.info("compile.phi", 313), _emit_binary_op34(_s82, ({ type: "string", value: "opNe" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 314), runtime.opEq(_id84, ({ type: "string", value: "<" }))))) { -(runtime.info("compile.phi", 315), _emit_binary_op34(_s82, ({ type: "string", value: "opLt" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 316), runtime.opEq(_id84, ({ type: "string", value: ">" }))))) { -(runtime.info("compile.phi", 317), _emit_binary_op34(_s82, ({ type: "string", value: "opGt" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 318), runtime.opEq(_id84, ({ type: "string", value: "<=" }))))) { -(runtime.info("compile.phi", 319), _emit_binary_op34(_s82, ({ type: "string", value: "opLte" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 320), runtime.opEq(_id84, ({ type: "string", value: ">=" }))))) { -(runtime.info("compile.phi", 321), _emit_binary_op34(_s82, ({ type: "string", value: "opGte" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 322), runtime.opEq(_id84, ({ type: "string", value: "+" }))))) { -(runtime.info("compile.phi", 323), _emit_binary_op34(_s82, ({ type: "string", value: "opAdd" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 324), runtime.opEq(_id84, ({ type: "string", value: "-" }))))) { -(runtime.info("compile.phi", 325), _emit_binary_op34(_s82, ({ type: "string", value: "opSub" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 326), runtime.opEq(_id84, ({ type: "string", value: "not" }))))) { -const r_167 = _s82; -const r_168 = r_167.values[0] ?? { type: "null"}; -const r_169 = r_167.values[1] ?? { type: "null"}; -let _expr133 = r_169; -(runtime.info("compile.phi", 328), _emit37(({ type: "string", value: "runtime.opNot(" }))); -(runtime.info("compile.phi", 329), _emit_expr30(_expr133)); -(runtime.info("compile.phi", 330), _emit37(({ type: "string", value: ")" }))); -} else { -const r_170 = _s82; -const r_171 = r_170.values[0] ?? { type: "null"}; -let _callee134 = r_171; -const r_172 = (runtime.info("compile.phi", 333), _slice24(_s82, ({ type: "int", value: 1 }))); -let _args135 = r_172; -(runtime.info("compile.phi", 334), _emit37((runtime.info("compile.phi", 334), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(%, " }), (runtime.info("compile.phi", 334), _rt_info35(_line81)), _line81)))); -(runtime.info("compile.phi", 335), _emit_expr30(_callee134)); -(runtime.info("compile.phi", 336), _emit37(({ type: "string", value: "(" }))); -const r_173 = ({ type: "bool", value: true }); -let _first136 = r_173; -for (const r_174 of _args135.values) {; -let _arg137 = r_174; -if (runtime.truthy(runtime.opNot(_first136))) { -(runtime.info("compile.phi", 341), _emit37(({ type: "string", value: ", " }))); -}; -(_first136 = ({ type: "bool", value: false })); -(runtime.info("compile.phi", 345), _emit_expr30(_arg137)); -}; -(runtime.info("compile.phi", 348), _emit37(({ type: "string", value: "))" }))); -}}}}}}}}}}}}}}}}}}}}}}}}}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _emit_list_literal32(_s138) { -runtime.pushCall("emit_list_literal", "compile.phi"); -(runtime.info("compile.phi", 353), _emit37(({ type: "string", value: "({ type: \"list\", values: [" }))); -const r_175 = ({ type: "bool", value: true }); -let _first139 = r_175; -for (const r_176 of _s138.values) {; -let _e140 = r_176; -if (runtime.truthy(runtime.opNot(_first139))) { -(runtime.info("compile.phi", 357), _emit37(({ type: "string", value: ", " }))); -}; -(_first139 = ({ type: "bool", value: false })); -(runtime.info("compile.phi", 361), _emit_expr30(_e140)); -}; -(runtime.info("compile.phi", 363), _emit37(({ type: "string", value: "] })" }))); -; -runtime.popCall(); -return { type: "null" }; -}; -function _emit_let_node33(_pat141, _base_reg142) { -runtime.pushCall("emit_let_node", "compile.phi"); -const r_177 = _pat141; -const r_178 = r_177.values[0] ?? { type: "null"}; -let _pat_ty143 = r_178; -const r_179 = r_177.values[1] ?? { type: "null"}; -let _line144 = r_179; -if (runtime.truthy((runtime.info("compile.phi", 368), runtime.opEq(_pat_ty143, ({ type: "string", value: "ident" }))))) { -const r_180 = _pat141; -const r_181 = r_180.values[0] ?? { type: "null"}; -const r_182 = r_180.values[1] ?? { type: "null"}; -const r_183 = r_180.values[2] ?? { type: "null"}; -let _ident145 = r_183; -if (runtime.truthy((runtime.info("compile.phi", 371), runtime.opEq(_ident145, ({ type: "string", value: "_" }))))) { -runtime.popCall(); -return { type: "null" }}; -const r_184 = (runtime.info("compile.phi", 373), _define_let41(_ident145, _line144)); -let _sym_id146 = r_184; -(runtime.info("compile.phi", 374), _emit37((runtime.info("compile.phi", 374), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: ";\nlet _%% = r_%" }), _ident145, _sym_id146, _base_reg142)))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 375), runtime.opEq(_pat_ty143, ({ type: "string", value: "list" }))))) { -const r_185 = _pat141; -const r_186 = r_185.values[0] ?? { type: "null"}; -const r_187 = r_185.values[1] ?? { type: "null"}; -const r_188 = r_185.values[2] ?? { type: "null"}; -let _pats147 = r_188; -const r_189 = ({ type: "int", value: 0 }); -let _i148 = r_189; -for (const r_190 of _pats147.values) {; -let _pat149 = r_190; -const r_191 = (runtime.info("compile.phi", 380), _let_node_reg_count53()); -let _reg150 = r_191; -(runtime.info("compile.phi", 381), _let_node_reg_increment54()); -(runtime.info("compile.phi", 382), _emit37((runtime.info("compile.phi", 382), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: ";\nconst r_% = r_%.values[%] ?? { type: \"null\"}" }), _reg150, _base_reg142, _i148)))); -(runtime.info("compile.phi", 386), _emit_let_node33(_pat149, _reg150)); -(_i148 = runtime.opAdd(_i148, ({ type: "int", value: 1 }))); -}; -} else { -(runtime.info("compile.phi", 390), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "malformed pattern on line %" }), _line144)); -}}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _emit_binary_op34(_s151, _id152) { -runtime.pushCall("emit_binary_op", "compile.phi"); -const r_192 = _s151; -const r_193 = r_192.values[0] ?? { type: "null"}; -const r_194 = r_193.values[0] ?? { type: "null"}; -const r_195 = r_193.values[1] ?? { type: "null"}; -let _line153 = r_195; -const r_196 = r_193.values[2] ?? { type: "null"}; -const r_197 = r_192.values[1] ?? { type: "null"}; -let _left154 = r_197; -const r_198 = r_192.values[2] ?? { type: "null"}; -let _right155 = r_198; -(runtime.info("compile.phi", 396), _emit37((runtime.info("compile.phi", 396), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(%, runtime.%(" }), (runtime.info("compile.phi", 396), _rt_info35(_line153)), _id152)))); -(runtime.info("compile.phi", 397), _emit_expr30(_left154)); -(runtime.info("compile.phi", 398), _emit37(({ type: "string", value: ", " }))); -(runtime.info("compile.phi", 399), _emit_expr30(_right155)); -(runtime.info("compile.phi", 400), _emit37(({ type: "string", value: "))" }))); -; -runtime.popCall(); -return { type: "null" }; -}; -function _rt_info35(_line156) { -runtime.pushCall("rt_info", "compile.phi"); -runtime.popCall(); -return (runtime.info("compile.phi", 404), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.info(\"%\", %)" }), _filename49, _line156)); -; -runtime.popCall(); -return { type: "null" }; -}; -function _emit_assign_expr36(_s157, _line158, _id159) { -runtime.pushCall("emit_assign_expr", "compile.phi"); -const r_199 = _s157; -const r_200 = r_199.values[0] ?? { type: "null"}; -const r_201 = r_199.values[1] ?? { type: "null"}; -const r_202 = r_201.values[0] ?? { type: "null"}; -let _target_type160 = r_202; -const r_203 = r_199.values[2] ?? { type: "null"}; -let _expr161 = r_203; -if (runtime.truthy((runtime.info("compile.phi", 409), runtime.opNe(_target_type160, ({ type: "string", value: "ident" }))))) { -(runtime.info("compile.phi", 410), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "cannot assign to expression on line %" }), _line158)); -}; -const r_204 = _s157; -const r_205 = r_204.values[0] ?? { type: "null"}; -const r_206 = r_204.values[1] ?? { type: "null"}; -const r_207 = r_206.values[0] ?? { type: "null"}; -const r_208 = r_206.values[1] ?? { type: "null"}; -const r_209 = r_206.values[2] ?? { type: "null"}; -let _ident162 = r_209; -const r_210 = (runtime.info("compile.phi", 413), _get_sym45(_ident162)); -let _sym163 = r_210; -if (runtime.truthy((runtime.info("compile.phi", 414), runtime.opEq(_sym163, ({ type: "null" }))))) { -(runtime.info("compile.phi", 415), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "could not find symbol '%' on line %" }), _ident162, _line158)); -}; -const r_211 = _sym163; -const r_212 = r_211.values[0] ?? { type: "null"}; -let _sym_id164 = r_212; -const r_213 = r_211.values[1] ?? { type: "null"}; -let _sym_type165 = r_213; -const r_214 = r_211.values[2] ?? { type: "null"}; -let _sym_ident166 = r_214; -const r_215 = r_211.values[3] ?? { type: "null"}; -if (runtime.truthy((runtime.info("compile.phi", 418), runtime.opEq(_sym_type165, ({ type: "string", value: "let" }))))) { -(runtime.info("compile.phi", 419), _emit37((runtime.info("compile.phi", 419), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "(_%% = " }), _sym_ident166, _sym_id164)))); -if (runtime.truthy((runtime.info("compile.phi", 420), runtime.opEq(_id159, ({ type: "string", value: "=" }))))) { -(runtime.info("compile.phi", 421), _emit_expr30(_expr161)); -} else { -if (runtime.truthy((runtime.info("compile.phi", 422), runtime.opEq(_id159, ({ type: "string", value: "+" }))))) { -(runtime.info("compile.phi", 423), _emit37((runtime.info("compile.phi", 423), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.opAdd(_%%, " }), _sym_ident166, _sym_id164)))); -(runtime.info("compile.phi", 424), _emit_expr30(_expr161)); -(runtime.info("compile.phi", 425), _emit37(({ type: "string", value: ")" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 426), runtime.opEq(_id159, ({ type: "string", value: "-" }))))) { -(runtime.info("compile.phi", 427), _emit37((runtime.info("compile.phi", 427), ((...args) => runtime.builtinFormat(...args))(({ type: "string", value: "runtime.opSub(_%%, " }), _sym_ident166, _sym_id164)))); -(runtime.info("compile.phi", 428), _emit_expr30(_expr161)); -(runtime.info("compile.phi", 429), _emit37(({ type: "string", value: ")" }))); -} else { -(runtime.info("compile.phi", 431), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "not implemented" }))); -}}}; -(runtime.info("compile.phi", 433), _emit37(({ type: "string", value: ")" }))); -} else { -(runtime.info("compile.phi", 435), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "cannot assign to symbol '%' on line %" }), _sym_ident166, _line158)); -}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _emit37(_str167) { -runtime.pushCall("emit", "compile.phi"); -(runtime.info("compile.phi", 440), ((...args) => runtime.builtinPush(...args))(_output48, _str167)); -; -runtime.popCall(); -return { type: "null" }; -}; -function _define_builtin38(_ident168, _builtin_id169) { -runtime.pushCall("define_builtin", "compile.phi"); -const r_216 = (runtime.info("compile.phi", 444), _sym_id_count51()); -let _sym_id170 = r_216; -(runtime.info("compile.phi", 445), _sym_id_increment52()); -(runtime.info("compile.phi", 447), _define_sym44(_ident168, ({ type: "list", values: [_sym_id170, ({ type: "string", value: "builtin" }), _builtin_id169] }))); -runtime.popCall(); -return _sym_id170; -; -runtime.popCall(); -return { type: "null" }; -}; -function _define_fn39(_ident171, _line172) { -runtime.pushCall("define_fn", "compile.phi"); -const r_217 = (runtime.info("compile.phi", 452), _sym_id_count51()); -let _sym_id173 = r_217; -(runtime.info("compile.phi", 453), _sym_id_increment52()); -(runtime.info("compile.phi", 455), _define_sym44(_ident171, ({ type: "list", values: [_sym_id173, ({ type: "string", value: "fn" }), _ident171, _line172] }))); -runtime.popCall(); -return _sym_id173; -; -runtime.popCall(); -return { type: "null" }; -}; -function _define_param40(_ident174, _line175) { -runtime.pushCall("define_param", "compile.phi"); -const r_218 = (runtime.info("compile.phi", 460), _sym_id_count51()); -let _sym_id176 = r_218; -(runtime.info("compile.phi", 461), _sym_id_increment52()); -(runtime.info("compile.phi", 463), _define_sym44(_ident174, ({ type: "list", values: [_sym_id176, ({ type: "string", value: "param" }), _ident174, _line175] }))); -runtime.popCall(); -return _sym_id176; -; -runtime.popCall(); -return { type: "null" }; -}; -function _define_let41(_ident177, _line178) { -runtime.pushCall("define_let", "compile.phi"); -const r_219 = (runtime.info("compile.phi", 468), _sym_id_count51()); -let _sym_id179 = r_219; -(runtime.info("compile.phi", 469), _sym_id_increment52()); -(runtime.info("compile.phi", 471), _define_sym44(_ident177, ({ type: "list", values: [_sym_id179, ({ type: "string", value: "let" }), _ident177, _line178] }))); -runtime.popCall(); -return _sym_id179; -; -runtime.popCall(); -return { type: "null" }; -}; -function _enter_scope42() { -runtime.pushCall("enter_scope", "compile.phi"); -const r_220 = _syms50; -const r_221 = r_220.values[0] ?? { type: "null"}; -let _enter_scope180 = r_221; -(runtime.info("compile.phi", 478), _enter_scope180()); -; -runtime.popCall(); -return { type: "null" }; -}; -function _leave_scope43() { -runtime.pushCall("leave_scope", "compile.phi"); -const r_222 = _syms50; -const r_223 = r_222.values[0] ?? { type: "null"}; -const r_224 = r_222.values[1] ?? { type: "null"}; -let _leave_scope181 = r_224; -(runtime.info("compile.phi", 482), _leave_scope181()); -; -runtime.popCall(); -return { type: "null" }; -}; -function _define_sym44(_ident182, _sym183) { -runtime.pushCall("define_sym", "compile.phi"); -const r_225 = _syms50; -const r_226 = r_225.values[0] ?? { type: "null"}; -const r_227 = r_225.values[1] ?? { type: "null"}; -const r_228 = r_225.values[2] ?? { type: "null"}; -let _define_sym184 = r_228; -runtime.popCall(); -return (runtime.info("compile.phi", 486), _define_sym184(_ident182, _sym183)); -; -runtime.popCall(); -return { type: "null" }; -}; -function _get_sym45(_ident185) { -runtime.pushCall("get_sym", "compile.phi"); -const r_229 = _syms50; -const r_230 = r_229.values[0] ?? { type: "null"}; -const r_231 = r_229.values[1] ?? { type: "null"}; -const r_232 = r_229.values[2] ?? { type: "null"}; -const r_233 = r_229.values[3] ?? { type: "null"}; -let _get_sym186 = r_233; -runtime.popCall(); -return (runtime.info("compile.phi", 490), _get_sym186(_ident185)); -; -runtime.popCall(); -return { type: "null" }; -}; -function _get_current_map46() { -runtime.pushCall("get_current_map", "compile.phi"); -const r_234 = _syms50; -const r_235 = r_234.values[0] ?? { type: "null"}; -const r_236 = r_234.values[1] ?? { type: "null"}; -const r_237 = r_234.values[2] ?? { type: "null"}; -const r_238 = r_234.values[3] ?? { type: "null"}; -const r_239 = r_234.values[4] ?? { type: "null"}; -let _get_current_map187 = r_239; -runtime.popCall(); -return (runtime.info("compile.phi", 494), _get_current_map187()); -; -runtime.popCall(); -return { type: "null" }; -}; -function _print_syms47() { -runtime.pushCall("print_syms", "compile.phi"); -const r_240 = _syms50; -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"}; -const r_244 = r_240.values[3] ?? { type: "null"}; -const r_245 = r_240.values[4] ?? { type: "null"}; -const r_246 = r_240.values[5] ?? { type: "null"}; -let _print_syms188 = r_246; -(runtime.info("compile.phi", 498), _print_syms188()); -; -runtime.popCall(); -return { type: "null" }; -}; -runtime.popCall(); -return ({ type: "list", values: [_generate27] }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _Counter15() { -runtime.pushCall("Counter", "compile.phi"); -const r_247 = ({ type: "int", value: 0 }); -let _counter191 = r_247; -function _count189() { -runtime.pushCall("count", "compile.phi"); -runtime.popCall(); -return _counter191; -; -runtime.popCall(); -return { type: "null" }; -}; -function _increment190() { -runtime.pushCall("increment", "compile.phi"); -(_counter191 = runtime.opAdd(_counter191, ({ type: "int", value: 1 }))); -; -runtime.popCall(); -return { type: "null" }; -}; -runtime.popCall(); -return ({ type: "list", values: [_count189, _increment190] }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _Syms16() { -runtime.pushCall("Syms", "compile.phi"); -const r_248 = ({ type: "list", values: [({ type: "null" }), ({ type: "list", values: [] })] }); -let _syms200 = r_248; -function _enter_scope192() { -runtime.pushCall("enter_scope", "compile.phi"); -(_syms200 = ({ type: "list", values: [_syms200, ({ type: "list", values: [] })] })); -; -runtime.popCall(); -return { type: "null" }; -}; -function _leave_scope193() { -runtime.pushCall("leave_scope", "compile.phi"); -const r_249 = _syms200; -const r_250 = r_249.values[0] ?? { type: "null"}; -let _parent201 = r_250; -const r_251 = r_249.values[1] ?? { type: "null"}; -(_syms200 = _parent201); -; -runtime.popCall(); -return { type: "null" }; -}; -function _define_sym194(_ident202, _sym203) { -runtime.pushCall("define_sym", "compile.phi"); -const r_252 = _syms200; -const r_253 = r_252.values[0] ?? { type: "null"}; -const r_254 = r_252.values[1] ?? { type: "null"}; -let _map204 = r_254; -const r_255 = ({ type: "int", value: 0 }); -let _i205 = r_255; +runtime.setFile("stdlib.phi"); +function _slice29(_list33, _idx34) { +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_1 = ({ type: "list", values: [] }); +let _elems36 = r_1; +const r_2 = _idx34; +let _i37 = r_2; while (true) { -if (runtime.truthy((runtime.info("compile.phi", 534), runtime.opGte(_i205, (runtime.info("compile.phi", 534), ((...args) => runtime.builtinLen(...args))(_map204)))))) { +if (runtime.truthy((runtime.info("stdlib.phi", 7), runtime.opGte(_i37, _list_len35)))) { break}; -const r_256 = (runtime.info("compile.phi", 535), ((...args) => runtime.builtinAt(...args))(_map204, _i205)); -const r_257 = r_256.values[0] ?? { type: "null"}; -let _s_ident206 = r_257; -const r_258 = r_256.values[1] ?? { type: "null"}; -if (runtime.truthy((runtime.info("compile.phi", 536), runtime.opEq(_ident202, _s_ident206)))) { -(runtime.info("compile.phi", 537), ((...args) => runtime.builtinSet(...args))(_map204, _i205, ({ type: "list", values: [_ident202, _sym203] }))); +(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.popCall(); -return { type: "null" }; -}; -(_i205 = runtime.opAdd(_i205, ({ type: "int", value: 1 }))); -}; -(runtime.info("compile.phi", 542), ((...args) => runtime.builtinPush(...args))(_map204, ({ type: "list", values: [_ident202, _sym203] }))); +return _elems36; ; runtime.popCall(); return { type: "null" }; }; -function _find_sym195(_syms207, _ident208) { -runtime.pushCall("find_sym", "compile.phi"); -const r_259 = _syms207; -const r_260 = r_259.values[0] ?? { type: "null"}; -let _parent209 = r_260; -const r_261 = r_259.values[1] ?? { type: "null"}; -let _map210 = r_261; -const r_262 = ({ type: "int", value: 0 }); -let _i211 = r_262; +function _slice_eq30(_str38, _slice_idx39, _substr40) { +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_5 = ({ type: "int", value: 0 }); +let _i43 = r_5; while (true) { -if (runtime.truthy((runtime.info("compile.phi", 549), runtime.opGte(_i211, (runtime.info("compile.phi", 549), ((...args) => runtime.builtinLen(...args))(_map210)))))) { -break}; -const r_263 = (runtime.info("compile.phi", 550), ((...args) => runtime.builtinAt(...args))(_map210, _i211)); -const r_264 = r_263.values[0] ?? { type: "null"}; -let _s_ident212 = r_264; -const r_265 = r_263.values[1] ?? { type: "null"}; -let _s_sym213 = r_265; -if (runtime.truthy((runtime.info("compile.phi", 551), runtime.opEq(_ident208, _s_ident212)))) { +if (runtime.truthy((runtime.info("stdlib.phi", 19), runtime.opGte(_i43, _substr_len42)))) { runtime.popCall(); -return _s_sym213; -}; -(_i211 = runtime.opAdd(_i211, ({ type: "int", value: 1 }))); -}; -if (runtime.truthy((runtime.info("compile.phi", 556), runtime.opNe(_parent209, ({ type: "null" }))))) { -runtime.popCall(); -return (runtime.info("compile.phi", 557), _find_sym195(_parent209, _ident208)); -}; -runtime.popCall(); -return ({ type: "null" }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _get_sym196(_ident214) { -runtime.pushCall("get_sym", "compile.phi"); -runtime.popCall(); -return (runtime.info("compile.phi", 563), _find_sym195(_syms200, _ident214)); -; -runtime.popCall(); -return { type: "null" }; -}; -function _get_current_map197() { -runtime.pushCall("get_current_map", "compile.phi"); -const r_266 = _syms200; -const r_267 = r_266.values[0] ?? { type: "null"}; -const r_268 = r_266.values[1] ?? { type: "null"}; -let _map215 = r_268; -runtime.popCall(); -return _map215; -; -runtime.popCall(); -return { type: "null" }; -}; -function _print_syms_node198(_syms216, _depth217) { -runtime.pushCall("print_syms_node", "compile.phi"); -const r_269 = _syms216; -const r_270 = r_269.values[0] ?? { type: "null"}; -let _parent218 = r_270; -const r_271 = r_269.values[1] ?? { type: "null"}; -let _map219 = r_271; -for (const r_272 of _map219.values) {; -const r_273 = r_272.values[0] ?? { type: "null"}; -let _ident220 = r_273; -const r_274 = r_272.values[1] ?? { type: "null"}; -let _sym221 = r_274; -(runtime.info("compile.phi", 574), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "%- %: %" }), (runtime.info("compile.phi", 574), _indent23(_depth217)), _ident220, _sym221)); -}; -if (runtime.truthy((runtime.info("compile.phi", 576), runtime.opNe(_parent218, ({ type: "null" }))))) { -(runtime.info("compile.phi", 577), _print_syms_node198(_parent218, (runtime.info("compile.phi", 577), runtime.opAdd(_depth217, ({ type: "int", value: 1 }))))); -}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _print_syms199() { -runtime.pushCall("print_syms", "compile.phi"); -(runtime.info("compile.phi", 582), _print_syms_node198(_syms200, ({ type: "int", value: 0 }))); -; -runtime.popCall(); -return { type: "null" }; -}; -runtime.popCall(); -return ({ type: "list", values: [_enter_scope192, _leave_scope193, _define_sym194, _get_sym196, _get_current_map197, _print_syms199] }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _string_escape17(_str222) { -runtime.pushCall("string_escape", "compile.phi"); -const r_275 = (runtime.info("compile.phi", 597), ((...args) => runtime.builtinLen(...args))(_str222)); -let _str_len223 = r_275; -const r_276 = ({ type: "int", value: 0 }); -let _i224 = r_276; -const r_277 = ({ type: "string", value: "" }); -let _result225 = r_277; -while (true) { -if (runtime.truthy((runtime.info("compile.phi", 601), runtime.opGte(_i224, _str_len223)))) { -break}; -const r_278 = (runtime.info("compile.phi", 602), ((...args) => runtime.builtinAt(...args))(_str222, _i224)); -let _ch226 = r_278; -if (runtime.truthy((runtime.info("compile.phi", 603), runtime.opEq(_ch226, ({ type: "string", value: "\\" }))))) { -(_result225 = runtime.opAdd(_result225, ({ type: "string", value: "\\\\" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 605), runtime.opEq(_ch226, ({ type: "string", value: "\"" }))))) { -(_result225 = runtime.opAdd(_result225, ({ type: "string", value: "\\\"" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 607), runtime.opEq(_ch226, ({ type: "string", value: "\t" }))))) { -(_result225 = runtime.opAdd(_result225, ({ type: "string", value: "\\t" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 609), runtime.opEq(_ch226, ({ type: "string", value: "\r" }))))) { -(_result225 = runtime.opAdd(_result225, ({ type: "string", value: "\\r" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 611), runtime.opEq(_ch226, ({ type: "string", value: "\n" }))))) { -(_result225 = runtime.opAdd(_result225, ({ type: "string", value: "\\n" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 613), runtime.opEq(_ch226, ({ type: "string", value: "\n" }))))) { -(_result225 = runtime.opAdd(_result225, ({ type: "string", value: "\\0" }))); -} else { -(_result225 = runtime.opAdd(_result225, _ch226)); -}}}}}}; -(_i224 = runtime.opAdd(_i224, ({ type: "int", value: 1 }))); -}; -runtime.popCall(); -return _result225; -; -runtime.popCall(); -return { type: "null" }; -}; -function _Parser18(_tokens227) { -runtime.pushCall("Parser", "compile.phi"); -const r_279 = ({ type: "int", value: 0 }); -let _i234 = r_279; -const r_280 = (runtime.info("compile.phi", 625), ((...args) => runtime.builtinAt(...args))(_tokens227, _i234)); -let _tok235 = r_280; -function _parse228() { -runtime.pushCall("parse", "compile.phi"); -const r_281 = ({ type: "list", values: [] }); -let _exprs236 = r_281; -while (true) { -if (runtime.truthy((runtime.info("compile.phi", 630), _done233()))) { -break}; -(runtime.info("compile.phi", 631), ((...args) => runtime.builtinPush(...args))(_exprs236, (runtime.info("compile.phi", 631), _parse_expr229()))); -}; -runtime.popCall(); -return _exprs236; -; -runtime.popCall(); -return { type: "null" }; -}; -function _parse_expr229() { -runtime.pushCall("parse_expr", "compile.phi"); -const r_282 = _tok235; -const r_283 = r_282.values[0] ?? { type: "null"}; -let _ty237 = r_283; -const r_284 = r_282.values[1] ?? { type: "null"}; -let _line238 = r_284; -const r_285 = r_282.values[2] ?? { type: "null"}; -let _value239 = r_285; -if (runtime.truthy((runtime.info("compile.phi", 638), _eat230(({ type: "string", value: "(" }))))) { -const r_286 = ({ type: "list", values: [] }); -let _values240 = r_286; -while (true) { -if (runtime.truthy((runtime.info("compile.phi", 641), _test232(({ type: "string", value: ")" }))))) { -break}; -(runtime.info("compile.phi", 642), ((...args) => runtime.builtinPush(...args))(_values240, (runtime.info("compile.phi", 642), _parse_expr229()))); -}; -if (runtime.truthy(runtime.opNot((runtime.info("compile.phi", 644), _eat230(({ type: "string", value: ")" })))))) { -(runtime.info("compile.phi", 645), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "expected ')' on line %" }), (runtime.info("compile.phi", 645), ((...args) => runtime.builtinAt(...args))(_tok235, ({ type: "int", value: 1 }))))); -}; -runtime.popCall(); -return ({ type: "list", values: [({ type: "string", value: "list" }), _line238, _values240] }); -} else { -if (runtime.truthy((runtime.info("compile.phi", 648), _eat230(({ type: "string", value: "string" }))))) { -runtime.popCall(); -return ({ type: "list", values: [({ type: "string", value: "string" }), _line238, _value239] }); -} else { -if (runtime.truthy((runtime.info("compile.phi", 650), _eat230(({ type: "string", value: "int" }))))) { -runtime.popCall(); -return ({ type: "list", values: [({ type: "string", value: "int" }), _line238, (runtime.info("compile.phi", 651), ((...args) => runtime.builtinStringToInt(...args))(_value239))] }); -} else { -if (runtime.truthy((runtime.info("compile.phi", 652), _eat230(({ type: "string", value: "ident" }))))) { -runtime.popCall(); -return ({ type: "list", values: [({ type: "string", value: "ident" }), _line238, _value239] }); -} else { -(runtime.info("compile.phi", 655), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "expected expression, got '%' on line %" }), _ty237, _line238)); -}}}}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _eat230(_pat241) { -runtime.pushCall("eat", "compile.phi"); -if (runtime.truthy(runtime.opNot((runtime.info("compile.phi", 660), _test232(_pat241))))) { +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)))) { runtime.popCall(); return ({ type: "bool", value: false })}; -(runtime.info("compile.phi", 661), _step231()); +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)))))) { +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 _step231() { -runtime.pushCall("step", "compile.phi"); -(_i234 = runtime.opAdd(_i234, ({ type: "int", value: 1 }))); -if (runtime.truthy(runtime.opNot((runtime.info("compile.phi", 667), _done233())))) { -const r_287 = (runtime.info("compile.phi", 668), ((...args) => runtime.builtinAt(...args))(_tokens227, _i234)); -let _new_tok242 = r_287; -(_tok235 = _new_tok242); -}; -; -runtime.popCall(); -return { type: "null" }; -}; -function _test232(_pat243) { -runtime.pushCall("test", "compile.phi"); -if (runtime.truthy((runtime.info("compile.phi", 674), _done233()))) { -runtime.popCall(); -return ({ type: "bool", value: false })}; -const r_288 = _tok235; -const r_289 = r_288.values[0] ?? { type: "null"}; -let _ty244 = r_289; -runtime.popCall(); -return (runtime.info("compile.phi", 676), runtime.opEq(_pat243, _ty244)); -; -runtime.popCall(); -return { type: "null" }; -}; -function _done233() { -runtime.pushCall("done", "compile.phi"); -runtime.popCall(); -return (runtime.info("compile.phi", 680), runtime.opGte(_i234, (runtime.info("compile.phi", 680), ((...args) => runtime.builtinLen(...args))(_tokens227)))); -; -runtime.popCall(); -return { type: "null" }; -}; -runtime.popCall(); -return ({ type: "list", values: [_parse228] }); -; -runtime.popCall(); -return { type: "null" }; -}; -function _tokenize19(_text245) { -runtime.pushCall("tokenize", "compile.phi"); -const r_290 = (runtime.info("compile.phi", 687), ((...args) => runtime.builtinLen(...args))(_text245)); -let _text_len246 = r_290; -const r_291 = ({ type: "list", values: [] }); -let _tokens247 = r_291; -const r_292 = ({ type: "int", value: 0 }); -let _i248 = r_292; -const r_293 = ({ type: "int", value: 1 }); -let _line249 = r_293; -const r_294 = (runtime.info("compile.phi", 693), runtime.opAdd(({ type: "string", value: "abcdefghijklmnopqrstuvwxyz" }), ({ type: "string", value: "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+-*/%&|=?!<>'_" }))); -let _ident_chars250 = r_294; +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("compile.phi", 697), runtime.opGte(_i248, _text_len246)))) { +if (runtime.truthy((runtime.info("stdlib.phi", 35), runtime.opGte(_i47, _text_len46)))) { break}; -const r_295 = (runtime.info("compile.phi", 699), ((...args) => runtime.builtinAt(...args))(_text245, _i248)); -let _ch251 = r_295; -if (runtime.truthy((runtime.info("compile.phi", 701), _contains20(({ type: "string", value: " \t\r\n" }), _ch251)))) { -if (runtime.truthy((runtime.info("compile.phi", 702), runtime.opEq(_ch251, ({ type: "string", value: "\n" }))))) { -(_line249 = runtime.opAdd(_line249, ({ type: "int", value: 1 }))); -}; -(_i248 = runtime.opAdd(_i248, ({ type: "int", value: 1 }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 706), _slice_eq21(_text245, _i248, ({ type: "string", value: "//" }))))) { -while (true) { -if (runtime.truthy((runtime.info("compile.phi", 708), { type: "bool", value: runtime.truthy((runtime.info("compile.phi", 708), runtime.opGte(_i248, _text_len246))) || runtime.truthy((runtime.info("compile.phi", 708), runtime.opEq((runtime.info("compile.phi", 708), ((...args) => runtime.builtinAt(...args))(_text245, _i248)), ({ type: "string", value: "\n" })))) }))) { -break; -}; -(_i248 = runtime.opAdd(_i248, ({ type: "int", value: 1 }))); -}; -} else { -if (runtime.truthy((runtime.info("compile.phi", 713), _contains20(({ type: "string", value: "()" }), _ch251)))) { -(runtime.info("compile.phi", 714), ((...args) => runtime.builtinPush(...args))(_tokens247, ({ type: "list", values: [_ch251, _line249] }))); -(_i248 = runtime.opAdd(_i248, ({ type: "int", value: 1 }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 716), runtime.opEq(_ch251, ({ type: "string", value: "\"" }))))) { -const r_296 = ({ type: "string", value: "" }); -let _value252 = r_296; -(_i248 = runtime.opAdd(_i248, ({ type: "int", value: 1 }))); -(_ch251 = (runtime.info("compile.phi", 719), ((...args) => runtime.builtinAt(...args))(_text245, _i248))); -while (true) { -if (runtime.truthy((runtime.info("compile.phi", 721), { type: "bool", value: runtime.truthy((runtime.info("compile.phi", 721), runtime.opGte(_i248, _text_len246))) || runtime.truthy((runtime.info("compile.phi", 721), runtime.opEq(_ch251, ({ type: "string", value: "\"" })))) }))) { -break; -}; -if (runtime.truthy((runtime.info("compile.phi", 724), runtime.opEq(_ch251, ({ type: "string", value: "\\" }))))) { -(_i248 = runtime.opAdd(_i248, ({ type: "int", value: 1 }))); -if (runtime.truthy((runtime.info("compile.phi", 726), runtime.opGte(_i248, _text_len246)))) { -break; -}; -(_ch251 = (runtime.info("compile.phi", 729), ((...args) => runtime.builtinAt(...args))(_text245, _i248))); -if (runtime.truthy((runtime.info("compile.phi", 730), runtime.opEq(_ch251, ({ type: "string", value: "t" }))))) { -(_value252 = runtime.opAdd(_value252, ({ type: "string", value: "\t" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 732), runtime.opEq(_ch251, ({ type: "string", value: "r" }))))) { -(_value252 = runtime.opAdd(_value252, ({ type: "string", value: "\r" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 734), runtime.opEq(_ch251, ({ type: "string", value: "n" }))))) { -(_value252 = runtime.opAdd(_value252, ({ type: "string", value: "\n" }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 736), runtime.opEq(_ch251, ({ type: "string", value: "0" }))))) { -(_value252 = runtime.opAdd(_value252, ({ type: "string", value: "\n" }))); -} else { -(_value252 = runtime.opAdd(_value252, _ch251)); -}}}}; -} else { -(_value252 = runtime.opAdd(_value252, _ch251)); -}; -(_i248 = runtime.opAdd(_i248, ({ type: "int", value: 1 }))); -(_ch251 = (runtime.info("compile.phi", 745), ((...args) => runtime.builtinAt(...args))(_text245, _i248))); -}; -if (runtime.truthy((runtime.info("compile.phi", 747), { type: "bool", value: runtime.truthy((runtime.info("compile.phi", 747), runtime.opGte(_i248, _text_len246))) || runtime.truthy((runtime.info("compile.phi", 747), runtime.opNe(_ch251, ({ type: "string", value: "\"" })))) }))) { -(runtime.info("compile.phi", 748), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "expected '\"' on line %" }), _line249)); -}; -(_i248 = runtime.opAdd(_i248, ({ type: "int", value: 1 }))); -(runtime.info("compile.phi", 751), ((...args) => runtime.builtinPush(...args))(_tokens247, ({ type: "list", values: [({ type: "string", value: "string" }), _line249, _value252] }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 752), _contains20(({ type: "string", value: "0123456789" }), _ch251)))) { -const r_297 = ({ type: "string", value: "" }); -let _value253 = r_297; -while (true) { -(_ch251 = (runtime.info("compile.phi", 755), ((...args) => runtime.builtinAt(...args))(_text245, _i248))); -if (runtime.truthy((runtime.info("compile.phi", 756), { type: "bool", value: runtime.truthy((runtime.info("compile.phi", 756), runtime.opGte(_i248, _text_len246))) || runtime.truthy(runtime.opNot((runtime.info("compile.phi", 756), _contains20(({ type: "string", value: "0123456789" }), _ch251)))) }))) { -break; -}; -(_value253 = runtime.opAdd(_value253, _ch251)); -(_i248 = runtime.opAdd(_i248, ({ type: "int", value: 1 }))); -}; -(runtime.info("compile.phi", 762), ((...args) => runtime.builtinPush(...args))(_tokens247, ({ type: "list", values: [({ type: "string", value: "int" }), _line249, _value253] }))); -} else { -if (runtime.truthy((runtime.info("compile.phi", 763), _contains20(_ident_chars250, _ch251)))) { -const r_298 = ({ type: "string", value: "" }); -let _value254 = r_298; -while (true) { -(_ch251 = (runtime.info("compile.phi", 766), ((...args) => runtime.builtinAt(...args))(_text245, _i248))); -if (runtime.truthy((runtime.info("compile.phi", 767), { type: "bool", value: runtime.truthy((runtime.info("compile.phi", 767), runtime.opGte(_i248, _text_len246))) || runtime.truthy(runtime.opNot((runtime.info("compile.phi", 767), _contains20(_ident_chars250, _ch251)))) }))) { -break; -}; -(_value254 = runtime.opAdd(_value254, _ch251)); -(_i248 = runtime.opAdd(_i248, ({ type: "int", value: 1 }))); -}; -(runtime.info("compile.phi", 773), ((...args) => runtime.builtinPush(...args))(_tokens247, ({ type: "list", values: [({ type: "string", value: "ident" }), _line249, _value254] }))); -} else { -(runtime.info("compile.phi", 775), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "illegal char '%'" }), _ch251)); -(_i248 = runtime.opAdd(_i248, ({ type: "int", value: 1 }))); -}}}}}}; -}; -runtime.popCall(); -return _tokens247; -; -runtime.popCall(); -return { type: "null" }; -}; -function _contains20(_text255, _ch256) { -runtime.pushCall("contains", "compile.phi"); -const r_299 = (runtime.info("compile.phi", 783), ((...args) => runtime.builtinLen(...args))(_text255)); -let _text_len257 = r_299; -const r_300 = ({ type: "int", value: 0 }); -let _i258 = r_300; -while (true) { -if (runtime.truthy((runtime.info("compile.phi", 786), runtime.opGte(_i258, _text_len257)))) { -break}; -if (runtime.truthy((runtime.info("compile.phi", 787), runtime.opEq((runtime.info("compile.phi", 787), ((...args) => runtime.builtinAt(...args))(_text255, _i258)), _ch256)))) { +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 }); }; -(_i258 = runtime.opAdd(_i258, ({ type: "int", value: 1 }))); +(_i47 = runtime.opAdd(_i47, ({ type: "int", value: 1 }))); }; runtime.popCall(); return ({ type: "bool", value: false }); @@ -1288,25 +69,67 @@ return ({ type: "bool", value: false }); runtime.popCall(); return { type: "null" }; }; -function _slice_eq21(_str259, _slice_idx260, _substr261) { -runtime.pushCall("slice_eq", "compile.phi"); -const r_301 = (runtime.info("compile.phi", 796), ((...args) => runtime.builtinLen(...args))(_str259)); -let _str_len262 = r_301; -const r_302 = (runtime.info("compile.phi", 797), ((...args) => runtime.builtinLen(...args))(_substr261)); -let _substr_len263 = r_302; -const r_303 = ({ type: "int", value: 0 }); -let _i264 = r_303; +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("compile.phi", 800), runtime.opGte(_i264, _substr_len263)))) { +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("compile.phi", 802), runtime.opGte((runtime.info("compile.phi", 802), runtime.opAdd(_slice_idx260, _i264)), _str_len262)))) { +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("compile.phi", 804), runtime.opNe((runtime.info("compile.phi", 804), ((...args) => runtime.builtinAt(...args))(_str259, (runtime.info("compile.phi", 804), runtime.opAdd(_slice_idx260, _i264)))), (runtime.info("compile.phi", 804), ((...args) => runtime.builtinAt(...args))(_substr261, _i264)))))) { +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 })}; -(_i264 = runtime.opAdd(_i264, ({ type: "int", value: 1 }))); +(_i95 = runtime.opAdd(_i95, ({ type: "int", value: 1 }))); }; runtime.popCall(); return ({ type: "bool", value: true }); @@ -1314,90 +137,1859 @@ return ({ type: "bool", value: true }); runtime.popCall(); return { type: "null" }; }; -function _print_expr22(_expr265, _depth266) { -runtime.pushCall("print_expr", "compile.phi"); -const r_304 = _expr265; -const r_305 = r_304.values[0] ?? { type: "null"}; -let _ty267 = r_305; -const r_306 = r_304.values[1] ?? { type: "null"}; -let _line268 = r_306; -const r_307 = r_304.values[2] ?? { type: "null"}; -let _value269 = r_307; -if (runtime.truthy((runtime.info("compile.phi", 813), runtime.opEq(_ty267, ({ type: "string", value: "list" }))))) { -(runtime.info("compile.phi", 814), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "%(% %" }), (runtime.info("compile.phi", 814), _indent23(_depth266)), _ty267, _line268)); -for (const r_308 of _value269.values) {; -let _e270 = r_308; -(runtime.info("compile.phi", 816), _print_expr22(_e270, (runtime.info("compile.phi", 816), runtime.opAdd(_depth266, ({ type: "int", value: 1 }))))); +function _contains83(_text96, _ch97) { +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; +while (true) { +if (runtime.truthy((runtime.info("stdlib.phi", 35), runtime.opGte(_i99, _text_len98)))) { +break}; +if (runtime.truthy((runtime.info("stdlib.phi", 36), runtime.opEq((runtime.info("stdlib.phi", 36), ((...args) => runtime.builtinAt(...args))(_text96, _i99)), _ch97)))) { +runtime.popCall(); +return ({ type: "bool", value: true }); }; -(runtime.info("compile.phi", 818), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "%)" }), (runtime.info("compile.phi", 818), _indent23(_depth266)))); +(_i99 = runtime.opAdd(_i99, ({ type: "int", value: 1 }))); +}; +runtime.popCall(); +return ({ type: "bool", value: false }); +; +runtime.popCall(); +return { type: "null" }; +}; +function _indent84(_depth100) { +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; +while (true) { +if (runtime.truthy((runtime.info("stdlib.phi", 48), runtime.opGte(_i102, _depth100)))) { +break}; +(_space101 = runtime.opAdd(_space101, ({ type: "string", value: " " }))); +(_i102 = runtime.opAdd(_i102, ({ type: "int", value: 1 }))); +}; +runtime.popCall(); +return _space101; +; +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; +while (true) { +if (runtime.truthy((runtime.info("compiler/parse.phi", 10), _done109()))) { +break}; +(runtime.info("compiler/parse.phi", 11), ((...args) => runtime.builtinPush(...args))(_exprs112, (runtime.info("compiler/parse.phi", 11), _parse_expr105()))); +}; +runtime.popCall(); +return _exprs112; +; +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; +while (true) { +if (runtime.truthy((runtime.info("compiler/parse.phi", 21), _test108(({ type: "string", value: ")" }))))) { +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 { -(runtime.info("compile.phi", 820), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "%%" }), (runtime.info("compile.phi", 820), _indent23(_depth266)), _expr265)); +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 _indent23(_depth271) { -runtime.pushCall("indent", "compile.phi"); -const r_309 = ({ type: "string", value: "" }); -let _space272 = r_309; -const r_310 = ({ type: "int", value: 0 }); -let _i273 = r_310; +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("compile.phi", 828), runtime.opGte(_i273, _depth271)))) { +if (runtime.truthy((runtime.info("compiler/parse.phi", 77), runtime.opGte(_i124, _text_len122)))) { break}; -(_space272 = runtime.opAdd(_space272, ({ type: "string", value: " " }))); -(_i273 = runtime.opAdd(_i273, ({ type: "int", value: 1 }))); +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 }))); }; -runtime.popCall(); -return _space272; -; -runtime.popCall(); -return { type: "null" }; -}; -function _slice24(_list274, _idx275) { -runtime.pushCall("slice", "compile.phi"); -const r_311 = (runtime.info("compile.phi", 836), ((...args) => runtime.builtinLen(...args))(_list274)); -let _list_len276 = r_311; -const r_312 = ({ type: "list", values: [] }); -let _elems277 = r_312; -const r_313 = _idx275; -let _i278 = r_313; +(_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("compile.phi", 840), runtime.opGte(_i278, _list_len276)))) { -break}; -(runtime.info("compile.phi", 841), ((...args) => runtime.builtinPush(...args))(_elems277, (runtime.info("compile.phi", 841), ((...args) => runtime.builtinAt(...args))(_list274, _i278)))); -(_i278 = runtime.opAdd(_i278, ({ type: "int", value: 1 }))); +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 _elems277; +return _tokens123; ; runtime.popCall(); return { type: "null" }; }; -const r_314 = (runtime.info("compile.phi", 847), ((...args) => runtime.builtinGetArgs(...args))()); -const r_315 = r_314.values[0] ?? { type: "null"}; -let _input_filename279 = r_315; -const r_316 = r_314.values[1] ?? { type: "null"}; -let _output_filename280 = r_316; -(runtime.info("compile.phi", 849), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "compiling '%'..." }), _input_filename279)); -const r_317 = (runtime.info("compile.phi", 850), ((...args) => runtime.builtinReadTextFile(...args))(_input_filename279)); -let _text281 = r_317; -const r_318 = (runtime.info("compile.phi", 852), _tokenize19(_text281)); -let _tokens282 = r_318; -const r_319 = (runtime.info("compile.phi", 853), _Parser18(_tokens282)); -let _parser283 = r_319; -const r_320 = _parser283; -const r_321 = r_320.values[0] ?? { type: "null"}; -let _parse284 = r_321; -const r_322 = (runtime.info("compile.phi", 855), _parse284()); -let _ast285 = r_322; -const r_323 = (runtime.info("compile.phi", 856), _Emitter14(_ast285, _input_filename279)); -let _emitter286 = r_323; -const r_324 = _emitter286; -const r_325 = r_324.values[0] ?? { type: "null"}; -let _emit287 = r_325; -const r_326 = (runtime.info("compile.phi", 858), _emit287()); -let _js_code288 = r_326; -(runtime.info("compile.phi", 863), ((...args) => runtime.builtinWriteTextFile(...args))(_output_filename280, _js_code288)); -(runtime.info("compile.phi", 864), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "written '%'!" }), _output_filename280)); +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 }))); +}; +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 }))); +}; +(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)); +}; +runtime.popCall(); +return ({ type: "null" }); +; +runtime.popCall(); +return { type: "null" }; +}; +function _get_sym319(_ident337) { +runtime.pushCall("get_sym", "compiler/syms.phi"); +runtime.popCall(); +return (runtime.info("compiler/syms.phi", 48), _find_sym318(_syms323, _ident337)); +; +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; +runtime.popCall(); +return _map338; +; +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)); +}; +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: "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 }))); +; +runtime.popCall(); +return { type: "null" }; +}; +runtime.popCall(); +return ({ type: "list", values: [_enter_scope315, _leave_scope316, _define_sym317, _get_sym319, _get_current_map320, _print_syms322] }); +; +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.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.info("compile.phi", 12), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "%)" }), (runtime.info("compile.phi", 12), _indent32(_depth518)))); +} else { +(runtime.info("compile.phi", 14), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "%%" }), (runtime.info("compile.phi", 14), _indent32(_depth518)), _expr517)); +}; +; +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)); diff --git a/stdlib.phi b/stdlib.phi new file mode 100644 index 0000000..6b232b1 --- /dev/null +++ b/stdlib.phi @@ -0,0 +1,54 @@ + +(fn slice (list idx) (do + (let list_len (len list)) + (let elems (list)) + (let i idx) + (loop (do + (if (>= i list_len) (break)) + (push elems (at list i)) + (+= i 1) + )) + (return elems) +)) + +(fn slice_eq (str slice_idx substr) (do + (let str_len (len str)) + (let substr_len (len substr)) + (let i 0) + (loop (do + (if (>= i substr_len) + (return true)) + (if (>= (+ slice_idx i) str_len) + (return false)) + (if (!= (at str (+ slice_idx i)) (at substr i)) + (return false)) + (+= i 1) + )) + (return true) +)) + + +(fn contains (text ch) (do + (let text_len (len text)) + (let i 0) + (loop (do + (if (>= i text_len) (break)) + (if (== (at text i) ch) (do + (return true) + )) + (+= i 1) + )) + (return false) +)) + +(fn indent (depth) (do + (let space "") + (let i 0) + (loop (do + (if (>= i depth) (break)) + (+= space " ") + (+= i 1) + )) + (return space) +)) +