UNPKG

@fink/loxia

Version:

A fink to JavaScript compiler.

55 lines (46 loc) 1.84 kB
import { throw_err as throw_err_0 } from "@fink/js-interop/errors.js"; import { transform_error as transform_error_0 } from "./errors.js"; import { get_transformer as get_transformer_0 } from "./context.js"; import { unique_or_id as unique_or_id_0 } from "./context.js"; import { ir_fn as ir_fn_0 } from "./context.js"; const transform_0 = (expr_0, name_or_id_0, ctx_0) => { const dlst_0 = unique_or_id_0(name_or_id_0, expr_0, ctx_0); const id_0 = dlst_0[0]; const next_ctx_0 = dlst_0[1]; const transform_expr_0 = get_transformer_0(expr_0, next_ctx_0); let ret_0; ret_0: { /* istanbul ignore else */ if (undefined !== transform_expr_0) { const result_4 = transform_expr_0(expr_0, id_0, next_ctx_0); ret_0 = result_4; /* istanbul ignore next */ break ret_0; } const arg_5 = transform_error_0(`Unknown expression.`, expr_0, next_ctx_0); const result_3 = throw_err_0(arg_5); ret_0 = result_3; /* istanbul ignore next */ break ret_0; } const dlst_1 = ret_0; return [dlst_1[0], id_0, dlst_1[1]]; }; const transform_binary_0 = (op_0, left_0, right_0, res_id_0, drec_0, ctx_1) => { const dlst_2 = transform_0(left_0, `left`, ctx_1); const dlst_3 = transform_0(right_0, `right`, dlst_2[2]); const dlst_4 = ir_fn_0(op_0, [dlst_2[1], dlst_3[1]], res_id_0, { loc: drec_0.loc }, dlst_3[2]); return [[...dlst_2[0], ...dlst_3[0], ...dlst_4[0]], dlst_4[2]]; }; const transform_unary_0 = (op_1, right_1, res_id_1, drec_1, ctx_2) => { const dlst_5 = transform_0(right_1, `right`, ctx_2); const dlst_6 = ir_fn_0(op_1, [dlst_5[1]], res_id_1, { loc: drec_1.loc }, dlst_5[2]); return [[...dlst_5[0], ...dlst_6[0]], dlst_6[2]]; }; export const transform = transform_0, transform_binary = transform_binary_0, transform_unary = transform_unary_0;