diff options
| author | Mel <einebeere@gmail.com> | 2022-06-01 19:51:40 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-01 19:51:40 +0000 |
| commit | edca72c160967f1918b65c91a40de89ecd8badda (patch) | |
| tree | b79feabc0889a3f6cfddf09906a486d09e5c60a1 /pkg/lang/vm/vm_test.go | |
| parent | 33671436680e7922001df9921ee582c486c7c3f4 (diff) | |
| download | jinx-edca72c160967f1918b65c91a40de89ecd8badda.tar.zst jinx-edca72c160967f1918b65c91a40de89ecd8badda.zip | |
Implement proper object types
Diffstat (limited to 'pkg/lang/vm/vm_test.go')
| -rw-r--r-- | pkg/lang/vm/vm_test.go | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/pkg/lang/vm/vm_test.go b/pkg/lang/vm/vm_test.go index c0b5c2e..325f200 100644 --- a/pkg/lang/vm/vm_test.go +++ b/pkg/lang/vm/vm_test.go @@ -229,6 +229,83 @@ func TestObject(t *testing.T) { test(t, src, "\"Petronij\"") } +func TestTypeConstruct(t *testing.T) { + /* + type Cat { + (name, age) { + this.name = name + this.age = age + } + + fn meow(this) { + return this.name + " says Meow!" + } + } + + var cat = Cat("Kitty", 3) + cat.meow() + */ + + src := ` + # Create a new type Cat + push_type "Cat" + + push_function @Cat:$init + push_string "$init" + + get_local 0 + get_member "$add_method" + + call 2 + + push_function @Cat:meow + push_string "meow" + + get_local 0 + get_member "$add_method" + + call 2 + + # Create a new instance of Cat + push_string "Kitty" + push_int 3 + get_local 0 + get_member "$init" + call 2 + + # Call the meow method + get_local 1 + get_member "meow" + call 0 + halt + + @Cat:$init: + get_env 0 + push_object + anchor_type + + get_local 0 + get_local 2 + set_member "name" + + get_local 1 + get_local 2 + set_member "age" + + ret + @Cat:meow: + push_string " says Meow!" + + get_env 0 + get_member "name" + + add + ret + ` + + test(t, src, "\"Kitty says Meow!\"") +} + func test(t *testing.T, src string, expected string) { bc := compile(t, src) vm := vm.New(&bc) |
