about summary refs log tree commit diff
path: root/pkg/lang/vm/exec.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/lang/vm/exec.go')
-rw-r--r--pkg/lang/vm/exec.go31
1 files changed, 26 insertions, 5 deletions
diff --git a/pkg/lang/vm/exec.go b/pkg/lang/vm/exec.go
index 32b1013..f92e486 100644
--- a/pkg/lang/vm/exec.go
+++ b/pkg/lang/vm/exec.go
@@ -433,6 +433,28 @@ func (vm *VM) execAnchorType() error {
 	return nil
 }
 
+func (vm *VM) execSetArgCount(argCount uint) error {
+	f, err := vm.stack.Pop()
+	if err != nil {
+		return err
+	}
+
+	if f.Type() != value.FunctionType {
+		return ErrInvalidOperandType{
+			Op: code.OpSetArgCount,
+			X:  f.Type(),
+		}
+	}
+
+	fn := f.Data().(value.FunctionData)
+
+	fn = fn.WithArgs(argCount)
+	f = f.WithData(fn)
+
+	vm.stack.Push(f)
+	return nil
+}
+
 type binaryOperation = func(value.Value, value.Value) (value.Value, error)
 type typesToBinaryOperation = map[value.TypeKind]map[value.TypeKind]binaryOperation
 
@@ -747,11 +769,10 @@ func (vm *VM) execCall(argCount uint) error {
 	fn := f.Data().(value.FunctionData)
 
 	if argCount != fn.Args() {
-		// TODO: Uncomment when push_function can set fn.Args()
-		// return ErrWrongNumberOfArguments{
-		// 	Got:    argCount,
-		// 	Needed: fn.Args(),
-		// }
+		return ErrWrongNumberOfArguments{
+			Got:    argCount,
+			Needed: fn.Args(),
+		}
 	}
 
 	if err = vm.stack.PushCall(fn.Pc(), vm.pc, fn.Env()); err != nil {