From 74dd678dfd1aae9e655fd13cb65278ea9ba307e2 Mon Sep 17 00:00:00 2001 From: Mel Date: Mon, 11 Jul 2022 11:07:51 +0200 Subject: Reimplement argument counts --- pkg/lang/compiler/compiler.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'pkg/lang/compiler/compiler.go') 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)) } -- cgit 1.4.1