diff options
| author | Marc Vertes <marc.vertes@tendermint.com> | 2023-10-12 10:51:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-12 10:51:58 +0200 |
| commit | 37b9da32d3b911091deb254f6cba2a137c471287 (patch) | |
| tree | b4451de0fa0473a937a77d39fd1f8a4f87c8f60d /_samples | |
| parent | a21b9b12ad865a19ff687645082f9093c4101039 (diff) | |
move to a direct byte code compiler (#8)
* chore: refactor to keep only the new parser and bytecode vm
* scanner: remove Token.value field
* scanner: remove scanner.kind field
* chore: move language specification in lang package
This avoid a cyclic dependency in scanner_test which can now use
the golang/GoSpec language specification for Go.
* clean code
* scanner: export scanner fields
Also parser now generate function calls, including externals.
* chore: fix lint issues
* parser: handle strings
* wip
* parser: implement support for 'if, else, else if' statements
Resolving labels in the compiler still in progress.
* parser: support if statements, improve compiler
* improve handling of functions
* improve support of local variables
* scanner: trim leading and trailing spaces
* fixes to make fibonacci work
* parser: improve README, fix function parameters parsing
Diffstat (limited to '_samples')
| -rw-r--r-- | _samples/add | 2 | ||||
| -rw-r--r-- | _samples/fib | 6 | ||||
| -rw-r--r-- | _samples/p00 | 1 | ||||
| -rw-r--r-- | _samples/p01 | 2 | ||||
| -rw-r--r-- | _samples/p02 | 7 | ||||
| -rw-r--r-- | _samples/p03 | 3 | ||||
| -rw-r--r-- | _samples/p04 | 4 | ||||
| -rw-r--r-- | _samples/p05 | 10 | ||||
| -rw-r--r-- | _samples/p06 | 7 | ||||
| -rw-r--r-- | _samples/p07 | 5 |
10 files changed, 47 insertions, 0 deletions
diff --git a/_samples/add b/_samples/add new file mode 100644 index 0000000..a403485 --- /dev/null +++ b/_samples/add @@ -0,0 +1,2 @@ +func add(a int, b int) int { return a + b } +add(4, 3) diff --git a/_samples/fib b/_samples/fib new file mode 100644 index 0000000..654c5c0 --- /dev/null +++ b/_samples/fib @@ -0,0 +1,6 @@ +func fib(i int) int { + if i < 2 { return i } + return fib(i-2) + fib(i-1) +} + +println(fib(6)) diff --git a/_samples/p00 b/_samples/p00 new file mode 100644 index 0000000..19f5084 --- /dev/null +++ b/_samples/p00 @@ -0,0 +1 @@ +1+2 diff --git a/_samples/p01 b/_samples/p01 new file mode 100644 index 0000000..baafaa9 --- /dev/null +++ b/_samples/p01 @@ -0,0 +1,2 @@ +s := "Hello" +println(s, 5+2) diff --git a/_samples/p02 b/_samples/p02 new file mode 100644 index 0000000..1aeb4a9 --- /dev/null +++ b/_samples/p02 @@ -0,0 +1,7 @@ +a := 1 + +if a < 2 { + println("yep") +} + +println("ok") diff --git a/_samples/p03 b/_samples/p03 new file mode 100644 index 0000000..39a3cda --- /dev/null +++ b/_samples/p03 @@ -0,0 +1,3 @@ +func f(a int, b int) int { return a + b } + +println("f:", f(3, 4), f(5, 6)) diff --git a/_samples/p04 b/_samples/p04 new file mode 100644 index 0000000..f2a85c8 --- /dev/null +++ b/_samples/p04 @@ -0,0 +1,4 @@ +func f() int { println(a) } + +a := 4 +f() diff --git a/_samples/p05 b/_samples/p05 new file mode 100644 index 0000000..51c2c9b --- /dev/null +++ b/_samples/p05 @@ -0,0 +1,10 @@ +func f(i int) int { + if i < 2 { + if i == 1 { + return + } } + println("i", i) +} + +f(1) +println("bye") diff --git a/_samples/p06 b/_samples/p06 new file mode 100644 index 0000000..88029cc --- /dev/null +++ b/_samples/p06 @@ -0,0 +1,7 @@ +func f(i int) { + if i < 2 { return } + println("i > 1:", i) +} + +f(1) +println("bye") diff --git a/_samples/p07 b/_samples/p07 new file mode 100644 index 0000000..2fa7ee0 --- /dev/null +++ b/_samples/p07 @@ -0,0 +1,5 @@ +func f1() { println("in f1") } + +func f2() { println("in f2"); f1() } + +f2() |
