@fink/loxia
Version:
A fink to JavaScript compiler.
296 lines (253 loc) • 7.16 kB
JavaScript
import { _in_ } from "@fink/js-interop/runtime.js";
import { is_fn as is_fn_0 } from "@fink/std-lib/fn.js";
import hamt_0 from "hamt";
const set_0 = hamt_0.set;
const add_0 = (type_0, op_0, transformer_0) => {
return ctx_0 => {
return { ...ctx_0,
transformers: { ...ctx_0.transformers,
[type_0 || op_0]: transformer_0
}
};
};
};
const get_transformer_0 = (drec_1, drec_2) => {
const op_1 = drec_1.op;
const type_1 = drec_1.type;
const transformers_0 = drec_2.transformers;
/* istanbul ignore else */
if (null != transformers_0) {
const val_3 = is_fn_0(transformers_0[op_1]);
/* istanbul ignore else */
if (true === val_3) {
return transformers_0[op_1];
}
}
/* istanbul ignore else */
if (null != transformers_0) {
const val_2 = is_fn_0(transformers_0[type_1]);
/* istanbul ignore else */
if (true === val_2) {
return transformers_0[type_1];
}
}
/* istanbul ignore next */
return;
};
const unique_name_0 = (prefix_0, drec_5, ctx_1) => {
const unique_ids_0 = ctx_1.unique_ids;
const hdm_0 = unique_ids_0[prefix_0];
const cntr_0 = undefined === hdm_0 ? 0 : hdm_0;
return [{
i: `${prefix_0}_${cntr_0}`,
loc: drec_5.loc
}, { ...ctx_1,
unique_ids: { ...unique_ids_0,
[prefix_0]: cntr_0 + 1
}
}];
};
const unique_or_id_0 = (prefix_or_id_0, drec_8, ctx_2) => {
/* istanbul ignore else */
if (null != prefix_or_id_0) {
/* istanbul ignore else */
if (undefined !== prefix_or_id_0.i) {
return [prefix_or_id_0, ctx_2];
}
}
/* istanbul ignore else */
if (prefix_or_id_0 === false) {
return [prefix_or_id_0, ctx_2];
}
const result_13 = unique_name_0(prefix_or_id_0, {
loc: drec_8.loc
}, ctx_2);
return result_13;
};
const ir_fn_0 = (fn_name_0, args_6, hdm_1, drec_9, ctx_3) => {
const name_or_id_0 = undefined === hdm_1 ? false : hdm_1;
const loc_2 = drec_9.loc;
const dlst_0 = unique_or_id_0(name_or_id_0, {
loc: loc_2
}, ctx_3);
const res_id_0 = dlst_0[0];
const next_ctx_0 = dlst_0[1];
const expr_0 = {
f: fn_name_0,
args: args_6,
loc: loc_2
};
/* istanbul ignore else */
if (name_or_id_0 === false) {
return [[[expr_0, []]],, next_ctx_0];
}
return [[[expr_0, [res_id_0]]], res_id_0, next_ctx_0];
};
const get_value_0 = (drec_10, drec_11) => {
const result_21 = hamt_0.tryGet({}, drec_10.i, drec_11.values);
return result_21;
};
const update_value_0 = (id_2, updates_0, ctx_4) => {
const curr_0 = get_value_0(id_2, ctx_4);
const values_1 = set_0(id_2.i, { ...curr_0,
...updates_0
}, ctx_4.values);
return { ...ctx_4,
values: values_1
};
};
const get_refs_0 = (id_3, ctx_5) => {
const drec_12 = get_value_0(id_3, ctx_5);
const hdm_2 = drec_12.refs;
return undefined === hdm_2 ? 0 : hdm_2;
};
const inc_ref_0 = (id_4, ctx_6) => {
const val_16 = get_value_0(id_4, ctx_6);
const hdm_3 = val_16.refs;
const values_2 = set_0(id_4.i, { ...val_16,
refs: (undefined === hdm_3 ? 0 : hdm_3) + 1
}, ctx_6.values);
return { ...ctx_6,
values: values_2
};
};
const inc_refs_0 = (...args_11) => {
inc_refs_0: do {
const dlst_1 = args_11[0];
const hdm_4 = dlst_1[0];
const id_5 = undefined === hdm_4 ? false : hdm_4;
const ctx_7 = args_11[1];
/* istanbul ignore else */
if (id_5 === false) {
return ctx_7;
}
const arg_22 = inc_ref_0(id_5, ctx_7);
args_11 = [dlst_1.slice(1), arg_22];
continue inc_refs_0;
} while (true);
};
const dec_ref_0 = (id_6, ctx_8) => {
const val_20 = get_value_0(id_6, ctx_8);
const hdm_5 = val_20.refs;
const values_3 = set_0(id_6.i, { ...val_20,
refs: (undefined === hdm_5 ? 0 : hdm_5) - 1
}, ctx_8.values);
return { ...ctx_8,
values: values_3
};
};
const dec_refs_0 = (...args_13) => {
dec_refs_0: do {
const dlst_2 = args_13[0];
const hdm_6 = dlst_2[0];
const id_7 = undefined === hdm_6 ? false : hdm_6;
const ctx_9 = args_13[1];
/* istanbul ignore else */
if (id_7 === false) {
return ctx_9;
}
const arg_31 = dec_ref_0(id_7, ctx_9);
args_13 = [dlst_2.slice(1), arg_31];
continue dec_refs_0;
} while (true);
};
const init_ref_0 = (id_8, ctx_10) => {
const val_24 = get_value_0(id_8, ctx_10);
const values_4 = set_0(id_8.i, { ...val_24,
refs: 0
}, ctx_10.values);
return { ...ctx_10,
values: values_4
};
};
const init_refs_0 = (...args_15) => {
init_refs_0: do {
const dlst_3 = args_15[0];
const hdm_7 = dlst_3[0];
const id_9 = undefined === hdm_7 ? false : hdm_7;
const ctx_11 = args_15[1];
/* istanbul ignore else */
if (id_9 === false) {
return ctx_11;
}
const arg_40 = init_ref_0(id_9, ctx_11);
args_15 = [dlst_3.slice(1), arg_40];
continue init_refs_0;
} while (true);
};
const is_unused_0 = (id_10, ctx_12) => {
const right_4 = get_refs_0(id_10, ctx_12);
return 0 === right_4;
};
const init_ref_counts_0 = (...args_17) => {
init_ref_counts_0: do {
const dlst_4 = args_17[0];
const hdm_8 = dlst_4[0];
const expr_1 = undefined === hdm_8 ? false : hdm_8;
const ctx_13 = args_17[1];
/* istanbul ignore else */
if (expr_1 === false) {
return ctx_13;
}
const drec_15 = expr_1[0];
const op_2 = drec_15.f;
const args_18 = drec_15.args;
const res_0 = expr_1[1];
let ret_23;
ret_23: {
/* istanbul ignore else */
if (true === _in_(op_2, [`fn`, `cn`])) {
const arg_52 = init_refs_0([...args_18[0], ...res_0], ctx_13);
const result_54 = init_ref_counts_0(args_18[1], arg_52);
ret_23 = result_54;
/* istanbul ignore next */
break ret_23;
}
/* istanbul ignore else */
if (true === _in_(op_2, [`int`, `float`, `str`])) {
const result_52 = init_refs_0(res_0, ctx_13);
ret_23 = result_52;
/* istanbul ignore next */
break ret_23;
}
const arg_46 = inc_refs_0(args_18, ctx_13);
const result_51 = init_refs_0(res_0, arg_46);
ret_23 = result_51;
/* istanbul ignore next */
break ret_23;
}
const rest_ctx_0 = ret_23;
args_17 = [dlst_4.slice(1), rest_ctx_0];
continue init_ref_counts_0;
} while (true);
};
const init_ctx_0 = (exprs_1, hdm_9) => {
const ppr_0 = (prtl_0 => {
const pfn_1 = init_ref_counts_0(exprs_1, prtl_0);
return pfn_1;
})({ ...(undefined === hdm_9 ? {} : hdm_9),
transformers: {},
runtime: {},
unique_ids: {},
values: hamt_0.empty
});
return ppr_0;
};
export const any = false,
add = add_0,
get_transformer = get_transformer_0,
unique_name = unique_name_0,
unique_or_id = unique_or_id_0,
ir_fn = ir_fn_0,
get_value = get_value_0,
update_value = update_value_0,
get_refs = get_refs_0,
inc_ref = inc_ref_0,
inc_refs = inc_refs_0,
dec_ref = dec_ref_0,
dec_refs = dec_refs_0,
init_ref = init_ref_0,
init_refs = init_refs_0,
is_unused = is_unused_0,
init_ref_counts = init_ref_counts_0,
init_ctx = init_ctx_0;