1404 lines
69 KiB
JavaScript
1404 lines
69 KiB
JavaScript
#!/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;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("compile.phi", 534), runtime.opGte(_i205, (runtime.info("compile.phi", 534), ((...args) => runtime.builtinLen(...args))(_map204)))))) {
|
|
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.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] })));
|
|
;
|
|
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;
|
|
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)))) {
|
|
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))))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: false })};
|
|
(runtime.info("compile.phi", 661), _step231());
|
|
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;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("compile.phi", 697), runtime.opGte(_i248, _text_len246)))) {
|
|
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)))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: true });
|
|
};
|
|
(_i258 = runtime.opAdd(_i258, ({ type: "int", value: 1 })));
|
|
};
|
|
runtime.popCall();
|
|
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;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("compile.phi", 800), runtime.opGte(_i264, _substr_len263)))) {
|
|
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)))) {
|
|
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)))))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: false })};
|
|
(_i264 = runtime.opAdd(_i264, ({ type: "int", value: 1 })));
|
|
};
|
|
runtime.popCall();
|
|
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 })))));
|
|
};
|
|
(runtime.info("compile.phi", 818), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "%)" }), (runtime.info("compile.phi", 818), _indent23(_depth266))));
|
|
} else {
|
|
(runtime.info("compile.phi", 820), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "%%" }), (runtime.info("compile.phi", 820), _indent23(_depth266)), _expr265));
|
|
};
|
|
;
|
|
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;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("compile.phi", 828), runtime.opGte(_i273, _depth271)))) {
|
|
break};
|
|
(_space272 = runtime.opAdd(_space272, ({ type: "string", value: " " })));
|
|
(_i273 = runtime.opAdd(_i273, ({ 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;
|
|
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 })));
|
|
};
|
|
runtime.popCall();
|
|
return _elems277;
|
|
;
|
|
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));
|