aboutsummaryrefslogtreecommitdiff
path: root/pkg/lang/vm/value
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/lang/vm/value')
-rw-r--r--pkg/lang/vm/value/cells.go2
-rw-r--r--pkg/lang/vm/value/data.go11
-rw-r--r--pkg/lang/vm/value/value.go8
3 files changed, 13 insertions, 8 deletions
diff --git a/pkg/lang/vm/value/cells.go b/pkg/lang/vm/value/cells.go
index 146402d..a700940 100644
--- a/pkg/lang/vm/value/cells.go
+++ b/pkg/lang/vm/value/cells.go
@@ -37,7 +37,7 @@ func (t TypeCell) DropCell(m mem.Mem) {
typ := t.Get()
for _, f := range typ.Methods {
// Wrap data in a Value to drop it.
- val := NewFunction(0).WithData(f)
+ val := NewFunction(0, 0).WithData(f)
val.Drop(m)
}
diff --git a/pkg/lang/vm/value/data.go b/pkg/lang/vm/value/data.go
index c0e5e9a..13716fd 100644
--- a/pkg/lang/vm/value/data.go
+++ b/pkg/lang/vm/value/data.go
@@ -116,6 +116,7 @@ type NullData struct{}
type FunctionData struct {
pc int
+ args uint
env mem.Ptr
native NativeFunc
}
@@ -126,6 +127,10 @@ func (f FunctionData) Pc() int {
return f.pc
}
+func (f FunctionData) Args() uint {
+ return f.args
+}
+
func (f FunctionData) Env() mem.Ptr {
return f.env
}
@@ -135,14 +140,14 @@ func (f FunctionData) Native() NativeFunc {
}
func (f FunctionData) WithEnv(env mem.Ptr) FunctionData {
- return FunctionData{pc: f.pc, env: env, native: f.native}
+ return FunctionData{pc: f.pc, args: f.args, env: env, native: f.native}
}
func (f FunctionData) String(_ mem.Mem) (string, error) {
if f.native != nil {
- return "<fn native>", nil
+ return fmt.Sprintf("<fn(%d) native>", f.args), nil
} else {
- return fmt.Sprintf("<fn %d>", f.pc), nil
+ return fmt.Sprintf("<fn(%d) %d>", f.args, f.pc), nil
}
}
}
diff --git a/pkg/lang/vm/value/value.go b/pkg/lang/vm/value/value.go
index eb63503..05d3f09 100644
--- a/pkg/lang/vm/value/value.go
+++ b/pkg/lang/vm/value/value.go
@@ -48,12 +48,12 @@ func NewNull() Value {
return Value{t: CORE_TYPE_NULL}
}
-func NewFunction(pc int) Value {
- return Value{t: CORE_TYPE_FUNCTION, d: FunctionData{pc: pc}}
+func NewFunction(pc int, args uint) Value {
+ return Value{t: CORE_TYPE_FUNCTION, d: FunctionData{pc: pc, args: args}}
}
-func NewNativeFunction(f NativeFunc) Value {
- return Value{t: CORE_TYPE_FUNCTION, d: FunctionData{native: f}}
+func NewNativeFunction(f NativeFunc, args uint) Value {
+ return Value{t: CORE_TYPE_FUNCTION, d: FunctionData{native: f, args: args}}
}
func NewObject() Value {