diff options
| author | Mel <einebeere@gmail.com> | 2022-05-31 01:10:45 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-31 01:10:45 +0000 |
| commit | c45c0d9f00e56abf51155e984675d7d12500ecfe (patch) | |
| tree | f0d8e76feac3b3197a20706c2c9050143016ab0a /pkg/lang/vm | |
| parent | 338744d066704e48e22d8ec56a43acb4b20da7f1 (diff) | |
| download | jinx-c45c0d9f00e56abf51155e984675d7d12500ecfe.tar.zst jinx-c45c0d9f00e56abf51155e984675d7d12500ecfe.zip | |
Call args fix in tests and better error message
Diffstat (limited to 'pkg/lang/vm')
| -rw-r--r-- | pkg/lang/vm/errors.go | 6 | ||||
| -rw-r--r-- | pkg/lang/vm/exec.go | 2 | ||||
| -rw-r--r-- | pkg/lang/vm/vm_test.go | 14 |
3 files changed, 11 insertions, 11 deletions
diff --git a/pkg/lang/vm/errors.go b/pkg/lang/vm/errors.go index 640ab21..4781179 100644 --- a/pkg/lang/vm/errors.go +++ b/pkg/lang/vm/errors.go @@ -92,11 +92,11 @@ func (e ErrArrayIndexOutOfBounds) Error() string { return fmt.Sprintf("array index out of bounds: %d (len: %d)", e.Index, e.Len) } -type ErrNotEnoughArguments struct { +type ErrWrongNumberOfArguments struct { Needed uint Got uint } -func (e ErrNotEnoughArguments) Error() string { - return fmt.Sprintf("not enough arguments: needed %d, got %d", e.Needed, e.Got) +func (e ErrWrongNumberOfArguments) Error() string { + return fmt.Sprintf("wrong number of arguments: needed %d, got %d", e.Needed, e.Got) } diff --git a/pkg/lang/vm/exec.go b/pkg/lang/vm/exec.go index d4426e1..c8b4fb3 100644 --- a/pkg/lang/vm/exec.go +++ b/pkg/lang/vm/exec.go @@ -593,7 +593,7 @@ func (vm *VM) execCall(argCount uint) error { fn := f.Data().(value.FunctionData) if argCount != fn.Args() { - return ErrNotEnoughArguments{ + return ErrWrongNumberOfArguments{ Got: argCount, Needed: fn.Args(), } diff --git a/pkg/lang/vm/vm_test.go b/pkg/lang/vm/vm_test.go index 287e7a8..c0b5c2e 100644 --- a/pkg/lang/vm/vm_test.go +++ b/pkg/lang/vm/vm_test.go @@ -96,7 +96,7 @@ func TestFunction(t *testing.T) { src := ` push_int 44 push_function @subtract_two - call + call 1 halt @subtract_two: @@ -119,7 +119,7 @@ func TestSimpleEnv(t *testing.T) { push_function @test # Add the local 1 to the environment. add_to_env 1 - call + call 0 halt @test: @@ -148,22 +148,22 @@ func TestEscapedEnv(t *testing.T) { src := ` push_function @create - call + call 0 push_array get_local 0 - call + call 0 get_local 1 temp_arr_push get_local 0 - call + call 0 get_local 1 temp_arr_push get_local 0 - call + call 0 get_local 1 temp_arr_push halt @@ -204,7 +204,7 @@ func TestMember(t *testing.T) { temp_arr_push get_member "length" - call + call 0 ` test(t, src, "3") |
