Skip to content

Commit

Permalink
fix: ident scoping
Browse files Browse the repository at this point in the history
  • Loading branch information
kollhof committed Sep 30, 2021
1 parent 2055ad7 commit 8289324
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 165 deletions.
29 changes: 0 additions & 29 deletions src/generate.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,6 @@ describe 'source maps', fn:
js
to_match_snapshot

it 'compiles to mjs', fn:
expect
fink2js_sm "
remove_unused = fn [expr=false, ...exprs], ctx, out:
match expr:
false:
[out, ctx]

[? in ['mod', 'imp', 'af', 'ac', 'cc', 'cif', 'cf']]:
remove_unused exprs, ctx, [expr, ...out]

[, , [is_unused ?, ctx]]:
args = get_ref_args expr
next_ctx = dec_refs args, ctx
remove_unused exprs, next_ctx, out

[? in ['fn', 'fnr', 'cn']]:
[op, [args, body], ...rest] = expr
rbody = reverse body
[obody, next_ctx] = remove_unused rbody, ctx, []
oexpr = [op, [args, obody], ...rest]
remove_unused exprs, next_ctx, [oexpr, ...out]

else:
remove_unused exprs, ctx, [expr, ...out]
"
to_match_snapshot




describe 'errors', fn:
Expand Down
69 changes: 1 addition & 68 deletions src/generate.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -75,72 +75,5 @@ export const nanu = nanu_0,
out = out_0,
func = func_0,
y = y_1;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QuZm5rIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFPLE1BQUEsTUFBRyxHQUFIO0FBQ0QsTUFBQSxLQUFtQyxHQUFMO0FBQTdCLEVBQUEsR0FBNkIsRUFBeEIsS0FBd0I7QUFBakIsV0FBaUIsRUFBTixNQUFNO0FBQUEsRUFBQSxJQUFJLEVBQUo7QUFBQSxDQUE5QjtBQUNDLE1BQUEsS0FBRyxHQUFIO0FBQ0QsTUFBQSxLQUF3QixHQUF2QixRQUFPLEtBQUksUUFBTyxLQ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Gb28+XG5uaSA9IHNwYW0gKyBmb28tYmFyXG5hID0gWzEsICduaSddXG5bYiwgY10gPSBhXG5vdXQgPSBbYSwgYiwgY11cbmZ1bmMgPSBmbiB4LCB5OlxuICB4ICsgeSArIGJcbnkgPSBmdW5jIGJhciwgYSwgYlxuIl19"
`;

exports[`source maps compiles to mjs 2`] = `
"import { _in_ } from \\"@fink/js-interop/runtime.js\\";
const remove_unused_0 = (...args_0) => {
remove_unused_0: do {
const dlst_0 = args_0[0];
const tail_0 = args_0.slice(1);
const hdm_0 = dlst_0[0];
const expr_0 = undefined === hdm_0 ? false : hdm_0;
const tail_1 = dlst_0.slice(1);
const ctx_0 = args_0[1];
const out_0 = args_0[2];
/* istanbul ignore else */
if (expr_0 === false) {
return [out_0, ctx_0];
}
/* istanbul ignore else */
if (null != expr_0) {
/* istanbul ignore else */
if (true === _in_(expr_0[0], [\`mod\`, \`imp\`, \`af\`, \`ac\`, \`cc\`, \`cif\`, \`cf\`])) {
args_0 = [tail_1, ctx_0, [expr_0, ...out_0]];
continue remove_unused_0;
}
}
/* istanbul ignore else */
if (null != expr_0) {
const itm_1 = expr_0[2];
/* istanbul ignore else */
if (null != itm_1) {
const val_1 = is_unused(itm_1[0], ctx_0);
/* istanbul ignore else */
if (true === val_1) {
const args_2 = get_ref_args(expr_0);
const next_ctx_1 = dec_refs(args_2, ctx_0);
args_0 = [tail_1, next_ctx_1, out_0];
continue remove_unused_0;
}
}
}
/* istanbul ignore else */
if (null != expr_0) {
/* istanbul ignore else */
if (true === _in_(expr_0[0], [\`fn\`, \`fnr\`, \`cn\`])) {
const tail_5 = expr_0.slice(1);
const dlst_2 = expr_0[1];
const rbody_0 = reverse(dlst_2[1]);
const dlst_3 = remove_unused_0(rbody_0, ctx_0, []);
args_0 = [tail_1, dlst_3[1], [[expr_0[0], [dlst_2[0], dlst_3[0]], ...tail_5.slice(1)], ...out_0]];
continue remove_unused_0;
}
}
args_0 = [tail_1, ctx_0, [expr_0, ...out_0]];
continue remove_unused_0;
} while (true);
};
export const remove_unused = remove_unused_0;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QuZm5rIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQWdCLE1BQUEsZUFzQmhCLEdBdEJnQixJQUFBLE1Bc0JoQjtBQXRCZ0IsRUFBQSxlQXNCaEI7QUF0Qm1CLFVBQUEsTUFBc0IsR0FBekIsTUFBRztBQUFBLFVBQUEsTUFBc0IsR0FBekIsTUFBRztBQUFDLFVBQUEsS0FBSSxHQUFMLE1BQUM7QUFBQSxVQUFBLE1BQUksR0FBSixjQUFBLEtBQUksR0FBQyxLQUFELEdBQUo7QUFBQSxVQUFBLE1BQUksR0FBTCxNQUFDO0FBQXVCLFVBQUEsS0FBRyxHQUE5QixNQUEyQjtBQUFLLFVBQUEsS0FBRyxHQUFuQyxNQUFnQzs7QUFzQmhEO0FBcEJJLFFBREksTUFDSixLQUFBLEtBQUs7QUFDSCxjQUFDLEtBQUQsRUFBTSxLQUFOO0FBQVU7O0FBbUJoQjtBQWpCSSxnQkFKSSxNQUlKLEVBQUM7QUFBQTtBQUFBLHdCQUpHLE1BSUgsS0FBSyxDQUFFLEtBQUYsRUFBUyxLQUFULEVBQWdCLElBQWhCLEVBQXNCLElBQXRCLEVBQTRCLElBQTVCLEVBQWtDLEtBQWxDLEVBQXlDLElBQXpDLENBQUwsR0FBbUQ7QUFMeEMsUUFBQSxNQUt3QyxHQUN4QixDQUFaLE1BQVksRUFBTCxLQUFLLEdBQUMsTUFBRCxFQUFVLEdBQUEsS0FBVixFQUR3QjtBQUFBLGlCQUx4QyxlQUt3QztBQUNWO0FBRFM7O0FBaUJ2RDtBQWRJLGdCQVBJLE1BT0osRUFBSztBQUFBLFlBQUEsS0FBa0IsR0FQbkIsTUFPQzs7QUFBQTtBQUFBLGtCQUFBLEtBQWtCLEVBQWpCO0FBQUEsY0FBQSxLQUFnQixH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UFBQTtBQUFBLENBdEJnQjs7YUFBaEIsYUFBYSxHQUFHLGUiLCJzb3VyY2VzQ29udGVudCI6WyJyZW1vdmVfdW51c2VkID0gZm4gW2V4cHI9ZmFsc2UsIC4uLmV4cHJzXSwgY3R4LCBvdXQ6XG4gIG1hdGNoIGV4cHI6XG4gICAgZmFsc2U6XG4gICAgICBbb3V0LCBjdHhdXG5cbiAgICBbPyBpbiBbJ21vZCcsICdpbXAnLCAnYWYnLCAnYWMnLCAnY2MnLCAnY2lmJywgJ2NmJ11dOlxuICAgICAgcmVtb3ZlX3VudXNlZCBleHBycywgY3R4LCBbZXhwciwgLi4ub3V0XVxuXG4gICAgWywgLCBbaXNfdW51c2VkID8sIGN0eF1dOlxuICAgICAgYXJncyA9IGdldF9yZWZfYXJncyBleHByXG4gICAgICBuZXh0X2N0eCA9IGRlY19yZWZzIGFyZ3MsIGN0eFxuICAgICAgcmVtb3ZlX3VudXNlZCBleHBycywgbmV4dF9jdHgsIG91dFxuXG4gICAgWz8gaW4gWydmbicsICdmbnInLCAnY24nXV06XG4gICAgICBbb3AsIFthcmdzLCBib2R5XSwgLi4ucmVzdF0gPSBleHByXG4gICAgICByYm9keSA9IHJldmVyc2UgYm9keVxuICAgICAgW29ib2R5LCBuZXh0X2N0eF0gPSByZW1vdmVfdW51c2VkIHJib2R5LCBjdHgsIFtdXG4gICAgICBvZXhwciA9IFtvcCwgW2FyZ3MsIG9ib2R5XSwgLi4ucmVzdF1cbiAgICAgIHJlbW92ZV91bnVzZWQgZXhwcnMsIG5leHRfY3R4LCBbb2V4cHIsIC4uLm91dF1cblxuICAgIGVsc2U6XG4gICAgICByZW1vdmVfdW51c2VkIGV4cHJzLCBjdHgsIFtleHByLCAuLi5vdXRdXG4iXX0="
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QuZm5rIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFPLE1BQUEsT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sSUFBSSxHQUFHLE07TUFFUCxDQUFDLEdBQUcsRyIsInNvdXJjZXNDb250ZW50IjpbIm5hbnUgPSAzNDVcbmZvbyA9IHtiYXI6IDEyMzQ1LCAnc3BhbSBuaSc6IG5hbnUsIG5hbnV9XG5iYXIgPSAnZm9vJ1xuaGFtID0gJ2ZvbzogJHtmb299IGJhcjoke2Jhcn0nXG5lbCA9IDxGb28+YmFyIHsxMjN9IDxkaXYgZm9vPTEzNCBiYXIgc3BhbT1uYW51PjwvZGl2PjwvRm9vPlxubmkgPSBzcGFtICsgZm9vLWJhclxuYSA9IFsxLCAnbmknXVxuW2IsIGNdID0gYVxub3V0ID0gW2EsIGIsIGNdXG5mdW5jID0gZm4geCwgeTpcbiAgeCArIHkgKyBiXG55ID0gZnVuYyBiYXIsIGEsIGJcbiJdfQ=="
`;
15 changes: 1 addition & 14 deletions src/ir/context.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,6 @@ ir_fn = fn fn_name, args, name_or_id=false, {loc}, ctx:





# get_value = fn id, {values}:
# {(id): val={}} = values
# val



# update_value = fn id, updates, ctx:
# {(id): curr={}} = ctx.values
# {...ctx, values: {...ctx.values, (id): {...curr, ...updates}}}


get_value = fn {i: id}, {values}:
tryGet {}, id, values

Expand Down Expand Up @@ -130,7 +117,7 @@ init_ref_counts = fn [expr=false, ...rest], ctx:
else:
[{f: op, args}, res] = expr
rest_ctx = match op:
? in ['fn', 'cn', 'fnr']:
? in ['fn', 'cn']:
[fn_args, body] = args
init_ref_counts body, init_refs [...fn_args, ...res], ctx

Expand Down
20 changes: 15 additions & 5 deletions src/ir/func/init.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{transform} = import '../transform.fnk'
{unique_or_id, ir_fn, get_refs} = import '../context.fnk'
{transform_dl} = import '../assignment/init.fnk'
{bind_x} = import '../identifier/init.fnk'



Expand All @@ -28,6 +29,9 @@ transform_exprs = fn [expr=false, ...rest], ctx, out, last_id:
match expr:
false:
[out, last_id, ctx]
{value: 'undefined'}:
[foo, id, next_ctx] = transform expr, 'result', ctx
transform_exprs rest, next_ctx, [...out, ...foo], id
else:
[foo, id, next_ctx] = transform expr, 'result', ctx
transform_exprs rest, next_ctx, [...out, ...foo], id
Expand All @@ -41,16 +45,22 @@ transform_args = fn {args: exprs, loc}, ctx:



transform_func = fn expr, res_id, {scopes=[], self_name, ...ctx}:
[self_id, x_ctx] = unique_or_id '${res_id.i}', expr, ctx
args_ctx = {...x_ctx, scopes: [{(self_name): self_id}, ...scopes]}
transform_func = fn expr, res_id, {scopes, self_name=false, ...ctx}:
func_ctx = {...ctx, scopes: [{}, ...scopes]}

[self_id, args_ctx] = match self_name:
false:
[false, func_ctx ]
else:
[self_id, bind_ctx] = unique_or_id '${res_id.i}', expr, func_ctx
[self_id, bind_x {value: self_name}, self_id, bind_ctx]

[args, args_id, body_ctx] = transform_args expr, args_ctx
[exprs, fn_res_id, fn_ctx] = transform_exprs expr.exprs, body_ctx, []
body = [...args, ...exprs]

[fun, , end_ctx] = match get_refs self_id, fn_ctx:
? > 0 :
[fun, , end_ctx] = match self_id:
? != false and 0 < get_refs ?, fn_ctx:
zfnc args_id, self_id, fn_res_id, body, res_id, expr, fn_ctx
else:
fnc args_id, fn_res_id, body, res_id, expr, fn_ctx
Expand Down
9 changes: 9 additions & 0 deletions src/ir/func/init.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ describe 'func', fn:
to_match_snapshot


it 'handles self-ref scoping', fn:
expect
fink2lir "
undefined = foo
bar = fn: fn: undefined
"
to_match_snapshot



describe 'recursive funcs', fn:
it 'compiles recursive calls', fn:
Expand Down
19 changes: 19 additions & 0 deletions src/ir/func/init.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,25 @@ rec_e fn exports_0:
mod exports_1, drctvs_0, fn mod_0:"
`;

exports[`func handles self-ref scoping 1`] = `
"
rec_e fn exports_0:
id foo, fn undefined_0:
str 'undefined', fn key_0:
rec_s exports_0, key_0, undefined_0, fn exports_1:
id (fn args_0, ret_1: #fn
id (fn args_1, ret_0: #fn
id undefined_0, fn result_1:
cc ret_0, result_1
), fn result_0:
cc ret_1, result_0
), fn bar_0:
str 'bar', fn key_1:
rec_s exports_1, key_1, bar_0, fn exports_2:
lst_e fn drctvs_0:
mod exports_2, drctvs_0, fn mod_0:"
`;

exports[`recursive funcs compiles recursive calls 1`] = `
"
rec_e fn exports_0:
Expand Down
6 changes: 3 additions & 3 deletions src/ir/identifier/init.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


bind = fn {value, loc}, ctx:
{scopes: [scope, ...scopes]=[]} = ctx
{scopes: [scope, ...scopes]} = ctx
[id, next_ctx] = unique_or_id value, {loc}, ctx

end_ctx = rec:
Expand All @@ -18,7 +18,7 @@ bind = fn {value, loc}, ctx:

# TODO rename
bind_x = fn {value}, id, ctx:
{scopes: [scope, ...scopes]=[]} = ctx
{scopes: [scope, ...scopes]} = ctx

end_ctx = rec:
...ctx
Expand All @@ -30,7 +30,7 @@ bind_x = fn {value}, id, ctx:



get_ident = fn name, [scope, ...scopes]=[], ctx:
get_ident = fn name, [scope, ...scopes], ctx:
match scope:
{(name): ?}:
id = scope.(name)
Expand Down
1 change: 1 addition & 0 deletions src/ir/init.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ init_ctx = fn code, filename, options:
unique_ids: {}
errors: []
values: empty
scopes: [{}]

pipe ctx:
add_transformers
Expand Down
3 changes: 1 addition & 2 deletions src/ir/serialize.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ serialize = fn [curr=false, ...rest], out='', indent='':
${indent}), fn${a2s ids}:'
' ${indent}'


[{f: ? in ['cn', 'fn', 'fnr']}]:
[{f: ? in ['cn', 'fn']}]:
[{f: op, args: [args, body]}, ids] = curr
serialize
rest
Expand Down
3 changes: 1 addition & 2 deletions src/js/identifier/init.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ safe_names = fn [curr=false, ...exprs], renames={}, out=[]:
[nres, next_ren] = rename res, renames
safe_names exprs, next_ren, [...out, [expr, nres]]


[{f: ? in ['fn', 'fnr', 'cn']}]:
[{f: ? in ['fn', 'cn']}]:
[expr, res] = curr
{args: [args, body]} = expr
[nargs, bod_ren] = rename args, renames
Expand Down
15 changes: 12 additions & 3 deletions src/js/init.fnk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{reverse} = import '@fink/std-lib/iter.fnk'

{init_ctx, update_value} = import '../ir/context.fnk'
{init_ctx, update_value, get_value} = import '../ir/context.fnk'

{replace_idents} = import './identifier/init.fnk'

Expand Down Expand Up @@ -111,9 +111,18 @@ prepare_non_inlinable = fn [expr=false, ...exprs], ctx:
next_ctx = update_value res_id, {inline: false}, ctx
prepare_non_inlinable exprs, next_ctx

[{f: 'str'}]:
[, [res_id]] = expr
next_ctx = update_value res_id, {tp: 'str'}, ctx
prepare_non_inlinable exprs, next_ctx

[{f: 'jxe'}]:
[{args: [elem_id]}] = expr
next_ctx = update_value elem_id, {inline: false}, ctx

next_ctx = match get_value elem_id, ctx:
{tp: 'str'}: ctx
else: update_value elem_id, {inline: false}, ctx

prepare_non_inlinable exprs, next_ctx

[{f: ? in ['fn', 'cn']}]:
Expand All @@ -134,7 +143,7 @@ transform_ir = fn input_exprs, options:
prepare_rets rev_expr, ?
prepare_imports rev_expr, ?
prepare_exports rev_expr, ?
prepare_non_inlinable rev_expr, ?
prepare_non_inlinable exprs, ?
add_transformers ?

transfrom_module exprs, ctx
Expand Down
4 changes: 2 additions & 2 deletions src/js/module/init.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ exports.ˆdefault = default_0;"
`;

exports[`module handles side effects 1`] = `
"const mex_0 = foo(bar);
const mex_1 = shrub.ni(foo);
"foo(bar);
shrub.ni(foo);
export const spam = ni;"
`;
Loading

0 comments on commit 8289324

Please sign in to comment.