1996 lines
99 KiB
JavaScript
1996 lines
99 KiB
JavaScript
#!/usr/bin/env node
|
|
import { Runtime } from "./runtime.js";
|
|
const runtime = new Runtime("compile.phi");
|
|
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("stdlib.phi", 7), runtime.opGte(_i37, _list_len35)))) {
|
|
break};
|
|
(runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinPush(...args))(_elems36, (runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinAt(...args))(_list33, _i37))));
|
|
(_i37 = runtime.opAdd(_i37, ({ type: "int", value: 1 })));
|
|
};
|
|
runtime.popCall();
|
|
return _elems36;
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
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("stdlib.phi", 19), runtime.opGte(_i43, _substr_len42)))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: true })};
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 21), runtime.opGte((runtime.info("stdlib.phi", 21), runtime.opAdd(_slice_idx39, _i43)), _str_len41)))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: false })};
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 23), runtime.opNe((runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_str38, (runtime.info("stdlib.phi", 23), runtime.opAdd(_slice_idx39, _i43)))), (runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_substr40, _i43)))))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: false })};
|
|
(_i43 = runtime.opAdd(_i43, ({ type: "int", value: 1 })));
|
|
};
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: true });
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
function _contains31(_text44, _ch45) {
|
|
runtime.pushCall("contains", "stdlib.phi");
|
|
const r_6 = (runtime.info("stdlib.phi", 32), ((...args) => runtime.builtinLen(...args))(_text44));
|
|
let _text_len46 = r_6;
|
|
const r_7 = ({ type: "int", value: 0 });
|
|
let _i47 = r_7;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 35), runtime.opGte(_i47, _text_len46)))) {
|
|
break};
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 36), runtime.opEq((runtime.info("stdlib.phi", 36), ((...args) => runtime.builtinAt(...args))(_text44, _i47)), _ch45)))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: true });
|
|
};
|
|
(_i47 = runtime.opAdd(_i47, ({ type: "int", value: 1 })));
|
|
};
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: false });
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
function _indent32(_depth48) {
|
|
runtime.pushCall("indent", "stdlib.phi");
|
|
const r_8 = ({ type: "string", value: "" });
|
|
let _space49 = r_8;
|
|
const r_9 = ({ type: "int", value: 0 });
|
|
let _i50 = r_9;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 48), runtime.opGte(_i50, _depth48)))) {
|
|
break};
|
|
(_space49 = runtime.opAdd(_space49, ({ type: "string", value: " " })));
|
|
(_i50 = runtime.opAdd(_i50, ({ type: "int", value: 1 })));
|
|
};
|
|
runtime.popCall();
|
|
return _space49;
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
runtime.setFile("compile.phi");
|
|
;
|
|
runtime.setFile("compiler/parse.phi");
|
|
runtime.setFile("stdlib.phi");
|
|
function _slice81(_list85, _idx86) {
|
|
runtime.pushCall("slice", "stdlib.phi");
|
|
const r_10 = (runtime.info("stdlib.phi", 3), ((...args) => runtime.builtinLen(...args))(_list85));
|
|
let _list_len87 = r_10;
|
|
const r_11 = ({ type: "list", values: [] });
|
|
let _elems88 = r_11;
|
|
const r_12 = _idx86;
|
|
let _i89 = r_12;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 7), runtime.opGte(_i89, _list_len87)))) {
|
|
break};
|
|
(runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinPush(...args))(_elems88, (runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinAt(...args))(_list85, _i89))));
|
|
(_i89 = runtime.opAdd(_i89, ({ type: "int", value: 1 })));
|
|
};
|
|
runtime.popCall();
|
|
return _elems88;
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
function _slice_eq82(_str90, _slice_idx91, _substr92) {
|
|
runtime.pushCall("slice_eq", "stdlib.phi");
|
|
const r_13 = (runtime.info("stdlib.phi", 15), ((...args) => runtime.builtinLen(...args))(_str90));
|
|
let _str_len93 = r_13;
|
|
const r_14 = (runtime.info("stdlib.phi", 16), ((...args) => runtime.builtinLen(...args))(_substr92));
|
|
let _substr_len94 = r_14;
|
|
const r_15 = ({ type: "int", value: 0 });
|
|
let _i95 = r_15;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 19), runtime.opGte(_i95, _substr_len94)))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: true })};
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 21), runtime.opGte((runtime.info("stdlib.phi", 21), runtime.opAdd(_slice_idx91, _i95)), _str_len93)))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: false })};
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 23), runtime.opNe((runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_str90, (runtime.info("stdlib.phi", 23), runtime.opAdd(_slice_idx91, _i95)))), (runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_substr92, _i95)))))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: false })};
|
|
(_i95 = runtime.opAdd(_i95, ({ type: "int", value: 1 })));
|
|
};
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: true });
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
function _contains83(_text96, _ch97) {
|
|
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 });
|
|
};
|
|
(_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 {
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 28), _eat106(({ type: "string", value: "string" }))))) {
|
|
runtime.popCall();
|
|
return ({ type: "list", values: [({ type: "string", value: "string" }), _line114, _value115] });
|
|
} else {
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 30), _eat106(({ type: "string", value: "int" }))))) {
|
|
runtime.popCall();
|
|
return ({ type: "list", values: [({ type: "string", value: "int" }), _line114, (runtime.info("compiler/parse.phi", 31), ((...args) => runtime.builtinStringToInt(...args))(_value115))] });
|
|
} else {
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 32), _eat106(({ type: "string", value: "ident" }))))) {
|
|
runtime.popCall();
|
|
return ({ type: "list", values: [({ type: "string", value: "ident" }), _line114, _value115] });
|
|
} else {
|
|
(runtime.info("compiler/parse.phi", 35), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "expected expression, got '%' on line %" }), _ty113, _line114));
|
|
}}}};
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
function _eat106(_pat117) {
|
|
runtime.pushCall("eat", "compiler/parse.phi");
|
|
if (runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 40), _test108(_pat117))))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: false })};
|
|
(runtime.info("compiler/parse.phi", 41), _step107());
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: true });
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
function _step107() {
|
|
runtime.pushCall("step", "compiler/parse.phi");
|
|
(_i110 = runtime.opAdd(_i110, ({ type: "int", value: 1 })));
|
|
if (runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 47), _done109())))) {
|
|
const r_28 = (runtime.info("compiler/parse.phi", 48), ((...args) => runtime.builtinAt(...args))(_tokens103, _i110));
|
|
let _new_tok118 = r_28;
|
|
(_tok111 = _new_tok118);
|
|
};
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
function _test108(_pat119) {
|
|
runtime.pushCall("test", "compiler/parse.phi");
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 54), _done109()))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: false })};
|
|
const r_29 = _tok111;
|
|
const r_30 = r_29.values[0] ?? { type: "null"};
|
|
let _ty120 = r_30;
|
|
runtime.popCall();
|
|
return (runtime.info("compiler/parse.phi", 56), runtime.opEq(_pat119, _ty120));
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
function _done109() {
|
|
runtime.pushCall("done", "compiler/parse.phi");
|
|
runtime.popCall();
|
|
return (runtime.info("compiler/parse.phi", 60), runtime.opGte(_i110, (runtime.info("compiler/parse.phi", 60), ((...args) => runtime.builtinLen(...args))(_tokens103))));
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
runtime.popCall();
|
|
return ({ type: "list", values: [_parse104] });
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
function _tokenize66(_text121) {
|
|
runtime.pushCall("tokenize", "compiler/parse.phi");
|
|
const r_31 = (runtime.info("compiler/parse.phi", 67), ((...args) => runtime.builtinLen(...args))(_text121));
|
|
let _text_len122 = r_31;
|
|
const r_32 = ({ type: "list", values: [] });
|
|
let _tokens123 = r_32;
|
|
const r_33 = ({ type: "int", value: 0 });
|
|
let _i124 = r_33;
|
|
const r_34 = ({ type: "int", value: 1 });
|
|
let _line125 = r_34;
|
|
const r_35 = (runtime.info("compiler/parse.phi", 73), runtime.opAdd(({ type: "string", value: "abcdefghijklmnopqrstuvwxyz" }), ({ type: "string", value: "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+-*/%&|=?!<>'_" })));
|
|
let _ident_chars126 = r_35;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 77), runtime.opGte(_i124, _text_len122)))) {
|
|
break};
|
|
const r_36 = (runtime.info("compiler/parse.phi", 79), ((...args) => runtime.builtinAt(...args))(_text121, _i124));
|
|
let _ch127 = r_36;
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 81), _contains83(({ type: "string", value: " \t\r\n" }), _ch127)))) {
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 82), runtime.opEq(_ch127, ({ type: "string", value: "\n" }))))) {
|
|
(_line125 = runtime.opAdd(_line125, ({ type: "int", value: 1 })));
|
|
};
|
|
(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 })));
|
|
} else {
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 86), _slice_eq82(_text121, _i124, ({ type: "string", value: "//" }))))) {
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 88), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 88), runtime.opGte(_i124, _text_len122))) || runtime.truthy((runtime.info("compiler/parse.phi", 88), runtime.opEq((runtime.info("compiler/parse.phi", 88), ((...args) => runtime.builtinAt(...args))(_text121, _i124)), ({ type: "string", value: "\n" })))) }))) {
|
|
break;
|
|
};
|
|
(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 })));
|
|
};
|
|
} else {
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 93), _contains83(({ type: "string", value: "()" }), _ch127)))) {
|
|
(runtime.info("compiler/parse.phi", 94), ((...args) => runtime.builtinPush(...args))(_tokens123, ({ type: "list", values: [_ch127, _line125] })));
|
|
(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 })));
|
|
} else {
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 96), runtime.opEq(_ch127, ({ type: "string", value: "\"" }))))) {
|
|
const r_37 = ({ type: "string", value: "" });
|
|
let _value128 = r_37;
|
|
(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 })));
|
|
(_ch127 = (runtime.info("compiler/parse.phi", 99), ((...args) => runtime.builtinAt(...args))(_text121, _i124)));
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 101), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 101), runtime.opGte(_i124, _text_len122))) || runtime.truthy((runtime.info("compiler/parse.phi", 101), runtime.opEq(_ch127, ({ type: "string", value: "\"" })))) }))) {
|
|
break;
|
|
};
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 104), runtime.opEq(_ch127, ({ type: "string", value: "\\" }))))) {
|
|
(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 })));
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 106), runtime.opGte(_i124, _text_len122)))) {
|
|
break;
|
|
};
|
|
(_ch127 = (runtime.info("compiler/parse.phi", 109), ((...args) => runtime.builtinAt(...args))(_text121, _i124)));
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 110), runtime.opEq(_ch127, ({ type: "string", value: "t" }))))) {
|
|
(_value128 = runtime.opAdd(_value128, ({ type: "string", value: "\t" })));
|
|
} else {
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 112), runtime.opEq(_ch127, ({ type: "string", value: "r" }))))) {
|
|
(_value128 = runtime.opAdd(_value128, ({ type: "string", value: "\r" })));
|
|
} else {
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 114), runtime.opEq(_ch127, ({ type: "string", value: "n" }))))) {
|
|
(_value128 = runtime.opAdd(_value128, ({ type: "string", value: "\n" })));
|
|
} else {
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 116), runtime.opEq(_ch127, ({ type: "string", value: "0" }))))) {
|
|
(_value128 = runtime.opAdd(_value128, ({ type: "string", value: "\n" })));
|
|
} else {
|
|
(_value128 = runtime.opAdd(_value128, _ch127));
|
|
}}}};
|
|
} else {
|
|
(_value128 = runtime.opAdd(_value128, _ch127));
|
|
};
|
|
(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 })));
|
|
(_ch127 = (runtime.info("compiler/parse.phi", 125), ((...args) => runtime.builtinAt(...args))(_text121, _i124)));
|
|
};
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 127), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 127), runtime.opGte(_i124, _text_len122))) || runtime.truthy((runtime.info("compiler/parse.phi", 127), runtime.opNe(_ch127, ({ type: "string", value: "\"" })))) }))) {
|
|
(runtime.info("compiler/parse.phi", 128), ((...args) => runtime.builtinPanic(...args))(({ type: "string", value: "expected '\"' on line %" }), _line125));
|
|
};
|
|
(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 })));
|
|
(runtime.info("compiler/parse.phi", 131), ((...args) => runtime.builtinPush(...args))(_tokens123, ({ type: "list", values: [({ type: "string", value: "string" }), _line125, _value128] })));
|
|
} else {
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 132), _contains83(({ type: "string", value: "0123456789" }), _ch127)))) {
|
|
const r_38 = ({ type: "string", value: "" });
|
|
let _value129 = r_38;
|
|
while (true) {
|
|
(_ch127 = (runtime.info("compiler/parse.phi", 135), ((...args) => runtime.builtinAt(...args))(_text121, _i124)));
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 136), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 136), runtime.opGte(_i124, _text_len122))) || runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 136), _contains83(({ type: "string", value: "0123456789" }), _ch127)))) }))) {
|
|
break;
|
|
};
|
|
(_value129 = runtime.opAdd(_value129, _ch127));
|
|
(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 })));
|
|
};
|
|
(runtime.info("compiler/parse.phi", 142), ((...args) => runtime.builtinPush(...args))(_tokens123, ({ type: "list", values: [({ type: "string", value: "int" }), _line125, _value129] })));
|
|
} else {
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 143), _contains83(_ident_chars126, _ch127)))) {
|
|
const r_39 = ({ type: "string", value: "" });
|
|
let _value130 = r_39;
|
|
while (true) {
|
|
(_ch127 = (runtime.info("compiler/parse.phi", 146), ((...args) => runtime.builtinAt(...args))(_text121, _i124)));
|
|
if (runtime.truthy((runtime.info("compiler/parse.phi", 147), { type: "bool", value: runtime.truthy((runtime.info("compiler/parse.phi", 147), runtime.opGte(_i124, _text_len122))) || runtime.truthy(runtime.opNot((runtime.info("compiler/parse.phi", 147), _contains83(_ident_chars126, _ch127)))) }))) {
|
|
break;
|
|
};
|
|
(_value130 = runtime.opAdd(_value130, _ch127));
|
|
(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 })));
|
|
};
|
|
(runtime.info("compiler/parse.phi", 153), ((...args) => runtime.builtinPush(...args))(_tokens123, ({ type: "list", values: [({ type: "string", value: "ident" }), _line125, _value130] })));
|
|
} else {
|
|
(runtime.info("compiler/parse.phi", 155), ((...args) => runtime.builtinPrintln(...args))(({ type: "string", value: "illegal char '%'" }), _ch127));
|
|
(_i124 = runtime.opAdd(_i124, ({ type: "int", value: 1 })));
|
|
}}}}}};
|
|
};
|
|
runtime.popCall();
|
|
return _tokens123;
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
runtime.setFile("compile.phi");
|
|
;
|
|
runtime.setFile("compiler/emit_js.phi");
|
|
runtime.setFile("stdlib.phi");
|
|
function _slice162(_list166, _idx167) {
|
|
runtime.pushCall("slice", "stdlib.phi");
|
|
const r_40 = (runtime.info("stdlib.phi", 3), ((...args) => runtime.builtinLen(...args))(_list166));
|
|
let _list_len168 = r_40;
|
|
const r_41 = ({ type: "list", values: [] });
|
|
let _elems169 = r_41;
|
|
const r_42 = _idx167;
|
|
let _i170 = r_42;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 7), runtime.opGte(_i170, _list_len168)))) {
|
|
break};
|
|
(runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinPush(...args))(_elems169, (runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinAt(...args))(_list166, _i170))));
|
|
(_i170 = runtime.opAdd(_i170, ({ type: "int", value: 1 })));
|
|
};
|
|
runtime.popCall();
|
|
return _elems169;
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
function _slice_eq163(_str171, _slice_idx172, _substr173) {
|
|
runtime.pushCall("slice_eq", "stdlib.phi");
|
|
const r_43 = (runtime.info("stdlib.phi", 15), ((...args) => runtime.builtinLen(...args))(_str171));
|
|
let _str_len174 = r_43;
|
|
const r_44 = (runtime.info("stdlib.phi", 16), ((...args) => runtime.builtinLen(...args))(_substr173));
|
|
let _substr_len175 = r_44;
|
|
const r_45 = ({ type: "int", value: 0 });
|
|
let _i176 = r_45;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 19), runtime.opGte(_i176, _substr_len175)))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: true })};
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 21), runtime.opGte((runtime.info("stdlib.phi", 21), runtime.opAdd(_slice_idx172, _i176)), _str_len174)))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: false })};
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 23), runtime.opNe((runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_str171, (runtime.info("stdlib.phi", 23), runtime.opAdd(_slice_idx172, _i176)))), (runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_substr173, _i176)))))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: false })};
|
|
(_i176 = runtime.opAdd(_i176, ({ type: "int", value: 1 })));
|
|
};
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: true });
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
function _contains164(_text177, _ch178) {
|
|
runtime.pushCall("contains", "stdlib.phi");
|
|
const r_46 = (runtime.info("stdlib.phi", 32), ((...args) => runtime.builtinLen(...args))(_text177));
|
|
let _text_len179 = r_46;
|
|
const r_47 = ({ type: "int", value: 0 });
|
|
let _i180 = r_47;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 35), runtime.opGte(_i180, _text_len179)))) {
|
|
break};
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 36), runtime.opEq((runtime.info("stdlib.phi", 36), ((...args) => runtime.builtinAt(...args))(_text177, _i180)), _ch178)))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: true });
|
|
};
|
|
(_i180 = runtime.opAdd(_i180, ({ type: "int", value: 1 })));
|
|
};
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: false });
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
function _indent165(_depth181) {
|
|
runtime.pushCall("indent", "stdlib.phi");
|
|
const r_48 = ({ type: "string", value: "" });
|
|
let _space182 = r_48;
|
|
const r_49 = ({ type: "int", value: 0 });
|
|
let _i183 = r_49;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 48), runtime.opGte(_i183, _depth181)))) {
|
|
break};
|
|
(_space182 = runtime.opAdd(_space182, ({ type: "string", value: " " })));
|
|
(_i183 = runtime.opAdd(_i183, ({ type: "int", value: 1 })));
|
|
};
|
|
runtime.popCall();
|
|
return _space182;
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
runtime.setFile("compiler/emit_js.phi");
|
|
;
|
|
runtime.setFile("compiler/parse.phi");
|
|
runtime.setFile("stdlib.phi");
|
|
function _slice214(_list218, _idx219) {
|
|
runtime.pushCall("slice", "stdlib.phi");
|
|
const r_50 = (runtime.info("stdlib.phi", 3), ((...args) => runtime.builtinLen(...args))(_list218));
|
|
let _list_len220 = r_50;
|
|
const r_51 = ({ type: "list", values: [] });
|
|
let _elems221 = r_51;
|
|
const r_52 = _idx219;
|
|
let _i222 = r_52;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 7), runtime.opGte(_i222, _list_len220)))) {
|
|
break};
|
|
(runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinPush(...args))(_elems221, (runtime.info("stdlib.phi", 8), ((...args) => runtime.builtinAt(...args))(_list218, _i222))));
|
|
(_i222 = runtime.opAdd(_i222, ({ type: "int", value: 1 })));
|
|
};
|
|
runtime.popCall();
|
|
return _elems221;
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
function _slice_eq215(_str223, _slice_idx224, _substr225) {
|
|
runtime.pushCall("slice_eq", "stdlib.phi");
|
|
const r_53 = (runtime.info("stdlib.phi", 15), ((...args) => runtime.builtinLen(...args))(_str223));
|
|
let _str_len226 = r_53;
|
|
const r_54 = (runtime.info("stdlib.phi", 16), ((...args) => runtime.builtinLen(...args))(_substr225));
|
|
let _substr_len227 = r_54;
|
|
const r_55 = ({ type: "int", value: 0 });
|
|
let _i228 = r_55;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 19), runtime.opGte(_i228, _substr_len227)))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: true })};
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 21), runtime.opGte((runtime.info("stdlib.phi", 21), runtime.opAdd(_slice_idx224, _i228)), _str_len226)))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: false })};
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 23), runtime.opNe((runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_str223, (runtime.info("stdlib.phi", 23), runtime.opAdd(_slice_idx224, _i228)))), (runtime.info("stdlib.phi", 23), ((...args) => runtime.builtinAt(...args))(_substr225, _i228)))))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: false })};
|
|
(_i228 = runtime.opAdd(_i228, ({ type: "int", value: 1 })));
|
|
};
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: true });
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
function _contains216(_text229, _ch230) {
|
|
runtime.pushCall("contains", "stdlib.phi");
|
|
const r_56 = (runtime.info("stdlib.phi", 32), ((...args) => runtime.builtinLen(...args))(_text229));
|
|
let _text_len231 = r_56;
|
|
const r_57 = ({ type: "int", value: 0 });
|
|
let _i232 = r_57;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 35), runtime.opGte(_i232, _text_len231)))) {
|
|
break};
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 36), runtime.opEq((runtime.info("stdlib.phi", 36), ((...args) => runtime.builtinAt(...args))(_text229, _i232)), _ch230)))) {
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: true });
|
|
};
|
|
(_i232 = runtime.opAdd(_i232, ({ type: "int", value: 1 })));
|
|
};
|
|
runtime.popCall();
|
|
return ({ type: "bool", value: false });
|
|
;
|
|
runtime.popCall();
|
|
return { type: "null" };
|
|
};
|
|
function _indent217(_depth233) {
|
|
runtime.pushCall("indent", "stdlib.phi");
|
|
const r_58 = ({ type: "string", value: "" });
|
|
let _space234 = r_58;
|
|
const r_59 = ({ type: "int", value: 0 });
|
|
let _i235 = r_59;
|
|
while (true) {
|
|
if (runtime.truthy((runtime.info("stdlib.phi", 48), runtime.opGte(_i235, _depth233)))) {
|
|
break};
|
|
(_space234 = runtime.opAdd(_space234, ({ type: "string", value: " " })));
|
|
(_i235 = runtime.opAdd(_i235, ({ type: "int", value: 1 })));
|
|
};
|
|
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));
|