diff options
Diffstat (limited to 'pkg/lang/compiler/compiler.go')
| -rw-r--r-- | pkg/lang/compiler/compiler.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/pkg/lang/compiler/compiler.go b/pkg/lang/compiler/compiler.go index ae2a71c..728dec1 100644 --- a/pkg/lang/compiler/compiler.go +++ b/pkg/lang/compiler/compiler.go @@ -50,7 +50,7 @@ func (comp *Compiler) Compile() (code.Code, error) { } func (comp *Compiler) preDeclareFunction(fnDeclStmt ast.StmtFnDecl) error { - if _, ok := comp.scopes.DeclareFunction(fnDeclStmt.Name.Value); !ok { + if _, ok := comp.scopes.DeclareFunction(fnDeclStmt.Name.Value, uint(len(fnDeclStmt.Args))); !ok { return fmt.Errorf("function %s already declared", fnDeclStmt.Name.Value) } @@ -103,7 +103,7 @@ func (comp *Compiler) compileStmt(t *code.Builder, stmt ast.Stmt) error { } func (comp *Compiler) compileFnDeclStmt(t *code.Builder, fnDeclStmt ast.StmtFnDecl) error { - marker, ok := comp.scopes.DeclareFunction(fnDeclStmt.Name.Value) + marker, ok := comp.scopes.DeclareFunction(fnDeclStmt.Name.Value, uint(len(fnDeclStmt.Args))) if !ok { // If we are in the root scope, the function was simply predeclared :) if comp.scopes.IsRootScope() { @@ -598,6 +598,11 @@ func (comp *Compiler) compileIdentExpr(t *code.Builder, expr ast.ExprIdent) erro t.AppendOp(code.OpPushFunction) t.AppendMarkerReference(symbol.data.marker) + + if symbol.data.args != 0 { + t.AppendOp(code.OpSetArgCount) + t.AppendInt(int64(symbol.data.args)) + } default: panic(fmt.Errorf("unknown symbol kind: %v", symbolId.symbolKind)) } |
