Skip to content

Commit

Permalink
Fix support for native functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpy committed Mar 25, 2024
1 parent 58b7d22 commit f161773
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
19 changes: 14 additions & 5 deletions src/grammar/__snapshots__/grammar.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,21 @@ Line 6, col 14:
`;
exports[`grammar should fail case-23 1`] = `
"<unknown>:7:31: Empty parameter list should not have a dangling comma.
Line 7, col 31:
6 |
> 7 | abstract fun testFuncAbstract(,);
"<unknown>:2:23: Empty parameter list should not have a dangling comma.
Line 2, col 23:
1 | @name(native_name_1)
> 2 | native testNativeFunc(,);
^
3 |
"
`;
exports[`grammar should fail case-24 1`] = `
"<unknown>:1:31: Empty parameter list should not have a dangling comma.
Line 1, col 31:
> 1 | abstract fun testFuncAbstract(,);
^
8 |
2 |
"
`;
Expand Down
14 changes: 10 additions & 4 deletions src/grammar/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,6 @@ semantics.addOperation<ASTNode>('resolve_declaration', {
}

const attributes = arg0.children.map((v) => v.resolve_attributes()) as ASTFunctionAttribute[];
checkVariableName(arg2.sourceString, createRef(arg2));
checkFunctionAttributes(true, attributes, createRef(this));
return createNode({
kind: 'def_function',
origin: ctx!.origin,
Expand All @@ -358,7 +356,11 @@ semantics.addOperation<ASTNode>('resolve_declaration', {
ref: createRef(this)
})
},
NativeFunction_withType(_arg0, _arg1, arg2, _arg3, arg4, arg5, arg6, _arg7, arg8, _arg9, _arg10, _arg11, arg12, _arg13) {
NativeFunction_withType(_arg0, _arg1, arg2, _arg3, arg4, arg5, arg6, _arg7, arg8, arg9, _arg10, _arg11, arg12, _arg13) {
if (arg8.source.contents === '' && arg9.sourceString === ',') {
throwError('Empty parameter list should not have a dangling comma.', createRef(arg9));
}

checkVariableName(arg5.sourceString, createRef(arg5));
return createNode({
kind: 'def_native_function',
Expand All @@ -371,7 +373,11 @@ semantics.addOperation<ASTNode>('resolve_declaration', {
ref: createRef(this)
})
},
NativeFunction_withVoid(_arg0, _arg1, arg2, _arg3, arg4, arg5, arg6, _arg7, arg8, _arg9, _arg10, _arg11) {
NativeFunction_withVoid(_arg0, _arg1, arg2, _arg3, arg4, arg5, arg6, _arg7, arg8, arg9, _arg10, _arg11) {
if (arg8.source.contents === '' && arg9.sourceString === ',') {
throwError('Empty parameter list should not have a dangling comma.', createRef(arg9));
}

checkVariableName(arg5.sourceString, createRef(arg5));
return createNode({
kind: 'def_native_function',
Expand Down
4 changes: 0 additions & 4 deletions src/grammar/test-failed/case-23.tact
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@ native testNativeFunc(,);

@name(native_name_2)
native testNativeFuncWithType(,): Int;

abstract fun testFuncAbstract(,);

abstract fun testFuncAbstractWithType(,): Int;
3 changes: 3 additions & 0 deletions src/grammar/test-failed/case-24.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
abstract fun testFuncAbstract(,);

abstract fun testFuncAbstractWithType(,): Int;

0 comments on commit f161773

Please sign in to comment.