diff options
| author | Mel <einebeere@gmail.com> | 2022-07-11 11:07:51 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-07-11 11:07:51 +0200 |
| commit | 74dd678dfd1aae9e655fd13cb65278ea9ba307e2 (patch) | |
| tree | 6dc757259edb4f7163e0563c9acec2a239f56d80 /pkg/lang/compiler/compiler.go | |
| parent | 7a60e91c8c45663127cfa3aa31a14c930f717aeb (diff) | |
| download | jinx-74dd678dfd1aae9e655fd13cb65278ea9ba307e2.tar.zst jinx-74dd678dfd1aae9e655fd13cb65278ea9ba307e2.zip | |
Reimplement argument counts
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)) } |
