-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix(vm): Jump bug + Add(docs): Specs
* Fix the invalid jumps and read too much * Create another example better * Add spacs examples on how does it work
- Loading branch information
1 parent
b88781b
commit 6dc87f8
Showing
8 changed files
with
217 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
class Object is | ||
let foo | ||
constructor toto = 3 | ||
|
||
constructor func new(idk) | ||
self.foo = idk | ||
end | ||
func bar() | ||
end | ||
end | ||
let a = Object.new(42) | ||
a.bar() | ||
print(a.foo) | ||
|
||
<instructions:3> | ||
|
||
[0] | ||
ret | ||
[1] | ||
unload 1 // [ 42, {...} ] line 5 | ||
super // [ {...}, 42 ] | ||
impl "foo" // [ {...} ] | ||
ret | ||
[2] | ||
pushtable // [ {} ] __constructor | ||
pushinst 1 // [ {}, function ] | ||
pushnumber 3 // [ {}, function, 3 ] | ||
impl "new" // [ {...}, 3] | ||
impl "toto" // [ {...} ] | ||
load 0 // [ ] | ||
pushtable // [ {} ] __emptyself | ||
pushinst 2 // [ {}, function ] | ||
impl "bar" // [ {...} ] | ||
load 1 // [ ] | ||
unload 0 // [ {...} ] line 12 | ||
querry "new" // [ function ] | ||
pushnumber 42 // [ function, 42 ] | ||
call // [ {...} ] | ||
load 2 // [ ] | ||
unload 2 // [ {...} ] line 13 | ||
querry "bar" // [ function ] | ||
unloadref 2 // [ function, abstract ] | ||
call // [ ] | ||
unload 2 // [ {...} ] line 14 | ||
querry "foo" // [ any ] | ||
pushdef "print" // [ any, function ] | ||
supercall // [ ] | ||
halt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
func Max(a, b) | ||
if a < b then return b else return a end | ||
end | ||
|
||
let a = Max(42, 69) | ||
print(a) | ||
|
||
<instructions:2> | ||
|
||
[0] | ||
evalnice sm // [ false, 42, 69 ] | ||
jtr 2 // [ false, 42, 69 ] | ||
popkr 2 // [ 69 ] | ||
ret | ||
popk // [ 42, 69 ] | ||
popkn 1 // [ 42 ] | ||
ret | ||
[1] | ||
pushnumber 42 // [ 42 ] | ||
pushnumber 69 // [ 42, 69 ] | ||
pushinst 0 // [ 42, 69, function ] | ||
supercall // [ 69 ] | ||
pushdef "print" // [ 69, function ] | ||
supercall // [ ] | ||
halt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
print("Hello", "world") | ||
|
||
<instructions:1> | ||
|
||
[0] | ||
pushstr "Hello" // [ "Hello" ] | ||
pushstr "world" // [ "Hello", "world" ] | ||
pushdef "print" // [ "Hello", "world", function ] | ||
supercall // [ ] | ||
halt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
if "Foo" == "Foo" then | ||
print("Same") | ||
else | ||
print("Different") | ||
end | ||
|
||
<instructions:1> | ||
|
||
[0] | ||
pushstr "Foo" // [ "Foo" ] line 1 | ||
pushstr "Foo" // [ "Foo", "Foo" ] | ||
eval eq // [ true ] | ||
jfa 3 // [ true ] -> line 3 | ||
stackclose // [ ] | ||
pushstr "Same" // [ "Same" ] line 2 | ||
pushdef "print" // [ "Same", function ] | ||
supercall // [ ] | ||
jmp 5 // [ ] -> line 5 | ||
stackclose // [ ] line 3 | ||
pushstr "Different" // [ "Different" ] line 4 | ||
pushdef "print" // [ "Different", function ] | ||
supercall // [ ] | ||
halt line 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
func Inc(a) | ||
return a + 1 | ||
end | ||
|
||
func Sum(a, b) | ||
return a + b | ||
end | ||
|
||
print(1, Sum(2, Inc(0)), 2, Inc(1), 3) | ||
|
||
<instructions:3> | ||
|
||
[0] | ||
pushnumber 1 // [ any, 1 ] | ||
sumstack // [ any ] | ||
ret | ||
[1] | ||
sumstack // [ any ] | ||
ret | ||
[2] | ||
pushnumber 0 // [ 0 ] | ||
pushinst 1 // [ 0, function ] | ||
supercall // [ 1 ] | ||
tpush // [ ] | ||
pushnumber 2 // [ 2 ] | ||
tpop // [ 2, 1 ] | ||
pushinst 2 // [ 2, 1, function ] | ||
supercall // [ 3 ] | ||
tpush // [ ] | ||
pushnumber 1 // [ 1 ] | ||
pushinst 1 // [ 1, function ] | ||
supercall // [ 2 ] | ||
tpush // [ ] | ||
pushnumber 1 // [ 1 ] | ||
tpop // [ 1, 3 ] | ||
pushnumber 2 // [ 1, 3, 2 ] | ||
tpop // [ 1, 3, 2, 2 ] | ||
pushnumber 3 // [ 1, 3, 2, 2, 3 ] | ||
pushdef "print" // [ 1, 3, 2, 2, 3, function ] | ||
supercall // [ ] | ||
halt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
let a = { bar = "foo" } | ||
a.toto = 42 | ||
print(a.bar, 69, a.toto) | ||
|
||
<instructions:1> | ||
|
||
[0] | ||
pushtable // [ {} ] line 1 | ||
pushstr "foo" // [ {}, "foo" ] | ||
impl "bar" // [ {...} ] | ||
load 0 // [ ] | ||
unload 0 // [ {...} ] line 2 | ||
pushnumber 42 // [ {...}, 42 ] | ||
impl "toto" // [ {...} ] | ||
load 0 // [ ] | ||
unload 0 // [ {...} ] line 3 | ||
querry "bar" // [ "foo" ] | ||
pushnumber 69 // [ "foo", 69 ] | ||
unload 0 // [ "foo", 69, {...} ] | ||
super // [ {...}, "foo", 69 ] | ||
querry "toto" // [ "foo", 69, 42 ] | ||
pushdef "print" // [ "foo", 69, 42, function ] | ||
supercall // [ ] |