Skip to content

Commit

Permalink
feat(call): remove () as empty ar for calls
Browse files Browse the repository at this point in the history
BREAKING CHANGE: use `foo _` instead of `foo ()` for call without arguments
  • Loading branch information
kollhof committed Aug 2, 2021
1 parent e14073d commit 18b72dc
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 85 deletions.
4 changes: 4 additions & 0 deletions src/js/types.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ not_nullish = fn value:
binaryExpression '!=', value, nullLiteral _


not_undefiend = fn value:
binaryExpression '!==', value, undef _



ident = fn name, ctx:
identifier escape_ident name, ctx
Expand Down
1 change: 0 additions & 1 deletion src/lang/async/init.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ describe 'await', fn:
task2 = fn foo: await (foo + 4)

task3 = fn foo:
bar = await foo ()
spam = await foo _
bar + 123

Expand Down
1 change: 0 additions & 1 deletion src/lang/async/init.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ exports[`await compiles 1`] = `
"export const task1 = async foo => -(await foo);
export const task2 = async foo => await (foo + 4);
export const task3 = async foo => {
const bar = await foo();
const spam = await foo();
return bar + 123;
};
Expand Down
5 changes: 1 addition & 4 deletions src/lang/call/call.fnk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
babel_types = import '@babel/types'
{callExpression, identifier} = babel_types

{map, filter, zip, is_empty, length} = import '@fink/std-lib/iter.fnk'
{map, filter, zip, length} = import '@fink/std-lib/iter.fnk'

{transform, map_with_ctx, collect_with_ctx} = import '../transform.fnk'
{transform_with_partial, partial_wrapper, no_wrapper} = import '../partial/init.fnk'
Expand All @@ -24,9 +24,6 @@ transform_single_arg = fn [expr], ctx:
match expr:
{type: 'empty'}:
[[], ctx]
# TODO: remove in favour of using _ as empty?
{type: 'group', exprs: is_empty ?}:
[[], ctx]
else:
transform_multiple_args [expr], ctx

Expand Down
7 changes: 3 additions & 4 deletions src/lang/call/call.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ describe 'call', fn:
fink2js '
call1 = a ni, x=123, ...x
call2 = a ni
call3 = a ()
call4 = a _
call5 = a fn x: x * 2
call6 = a foo, , bar
call3 = a _
call4 = a fn x: x * 2
call5 = a foo, , bar
'
to_match_snapshot

Expand Down
5 changes: 2 additions & 3 deletions src/lang/call/call.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ exports[`call compiles 1`] = `
"export const call1 = a(ni, x = 123, ...x);
export const call2 = a(ni);
export const call3 = a();
export const call4 = a();
export const call5 = a(x => x * 2);
export const call6 = a(foo, undefined, bar);"
export const call4 = a(x => x * 2);
export const call5 = a(foo, undefined, bar);"
`;

exports[`call compiles as partial 1`] = `
Expand Down
19 changes: 12 additions & 7 deletions src/lang/conditionals/match.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ babel_types = import '@babel/types'
} = babel_types
{map, filter, length, is_empty} = import '@fink/std-lib/iter.fnk'

{eq, not_nullish, typof, consts, unique_ident} = import '../../js/types.fnk'
{eq, not_nullish, not_undefiend, typof, consts, unique_ident} = import '../../js/types.fnk'

{get_key} = import '../literals/record.fnk'
{wrap_with_comment_loc} = import '../comments/init.fnk'
Expand All @@ -31,14 +31,19 @@ is_iterable = fn value:


comp = fn id, expected, ctx:
value_ctx = {...ctx, partial_ident: id}
[wrap_with_partial, value, {partial_ident: _, ...next_ctx}] = transform_with_partial expected, value_ctx, false
match expected:
{type: 'partial'}:
cond = not_undefiend id
[cond, ctx]
else:
value_ctx = {...ctx, partial_ident: id}
[wrap_with_partial, value, {partial_ident: _, ...next_ctx}] = transform_with_partial expected, value_ctx, false

cond = match wrap_with_partial:
false: eq id, value
else: value
cond = match wrap_with_partial:
false: eq id, value
else: value

[cond, next_ctx]
[cond, next_ctx]



Expand Down
17 changes: 12 additions & 5 deletions src/lang/conditionals/match.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ describe 'match', fn:
? > 123: ni

# simple call
? (): ni
? _: ni

# simple as call arg
shrub ?: ni

# any value
?: true
'
to_match_snapshot

Expand Down Expand Up @@ -69,6 +71,7 @@ describe 'match iterables', fn:
match shrub:
# deep iterable comparison
[1, 2, [ni]]: ni
# TODO: fix semantics for matching [], {}
[1, 2, [], {}]: foo
[1, [2, 3], 4]: bar
[1, [2, [3, 4]], [5, 6], 7]: spam
Expand Down Expand Up @@ -96,15 +99,16 @@ describe 'match iterables', fn:
# nested unary
[not ?]: ni

# any value
[?]: true

# nested binary
[? > 123]: ni

# nested call
[? ()]: ni
[? _]: ni

# nested member call
[?.is_foo ()]: ni
[?.is_foo _]: ni

# nested as call arg
Expand All @@ -122,7 +126,9 @@ describe 'match records', fn:
expect
fink2js "
match shrub:
# TODO: fix semantics for matching {}
{foo: {}}: spam + ni
# TODO: fix semantics for matching []
{foo: []}: spam + ni
{foo: 4, ni: {na, nu}}: spam + ni
{foo: 1, foo: {bar: 'spam'}, shrub: {na: 'nu'}}: ni
Expand Down Expand Up @@ -178,18 +184,19 @@ describe 'match records', fn:
{spam: ? > 123}: ni

# nested call
{spam: ? ()}: ni
{spam: ? _}: ni

# nested member call
{spam: ?.is_foo ()}: ni
{spam: ?.is_foo _}: ni

# nested as call arg
{spam: is_foo ?}: ni

{spam, ...is_empty ?}: ni
{spam, ...("foo" in ?)}: ni

# any value
{spam: ?}: true
'
to_match_snapshot

Expand Down
Loading

0 comments on commit 18b72dc

Please sign in to comment.