-
Influenced by:
-
run:
v run . -c -i examples/arithmetic.vorth
-c
is to compile the code. That means you can run the test:./examples/arithmetic
-
or with debug logs:
v run . -c -i -d 5 examples/arithmetic.vorth
-
The language is case insensitive
Operators | stack state | Description |
---|---|---|
+ |
a b -- (a + b) | |
* |
a b -- (a * b) | |
- |
a b -- (a - b) | |
= |
a b -- Flag | True if a == b, False otherwise |
!= |
a b -- Flag | True if a != b, False otherwise |
< |
a b -- Flag | True if a < b, False otherwise |
> |
a b -- Flag | True if a > b, False otherwise |
. |
a -- | |
divmod | a b -- (a / b) (a % b) | |
dup | a -- a a | |
integer | -- a | integer is i64 |
load | a -- mem[a] | Put on the stack the value at mem[a] |
not | Flag -- not Flag | Inverse True and False |
store | v a -- | Store v in mem[a] |
swap | a b -- b a |
Operators | stack state | Description |
---|---|---|
if | flag -- | If True then it continues, otherwise |
else | -- | it jumps to execute the then. If then |
end | -- | is reached it jumps to end. |
Operators | stack state | Description |
---|---|---|
while | -- | If True then do continues, otherwise |
do | flag -- | it jumps right after the done. Done |
done | -- | jumps to while. |
~/devel/vlang-forth master*
❯ v run . -c -i -d 5 examples/arithmetic.vorth
log level is set to 5
2024-03-08 22:05:41.692216 [DEBUG] ==== LOADING PROGRAM
2024-03-08 22:05:41.692242 [DEBUG] // arithmetic.vorth
2024-03-08 22:05:41.692245 [DEBUG]
2024-03-08 22:05:41.692249 [DEBUG] 12 30 + . // should print 42
2024-03-08 22:05:41.692251 [DEBUG] 6 9 - . // should print -3
2024-03-08 22:05:41.692254 [DEBUG] 12 dup + . // should print 24
2024-03-08 22:05:41.692256 [DEBUG] 15 10 - . // should print 5
2024-03-08 22:05:41.692258 [DEBUG] 15 10 swap - . // should print -5
2024-03-08 22:05:41.692261 [DEBUG] 5 dup mul . // it is the square operation, 25
2024-03-08 22:05:41.692264 [DEBUG] 8 0 3 - * . // should print -24
2024-03-08 22:05:41.692267 [DEBUG] 117 17 divmod . . // 117 17 -- 6 15
2024-03-08 22:05:41.692270 [DEBUG] // where 6 is the quotient and 15 the reminder
2024-03-08 22:05:41.692275 [DEBUG] // So should print 15 6
2024-03-08 22:05:41.692278 [DEBUG]
2024-03-08 22:05:41.692287 [DEBUG] ==== PROGRAM LOADED
42
-3
24
5
-5
25
-24
15
6
~/devel/vlang-forth master*
❯ ./examples/arithmetic
42
-3
24
5
-5
25
-24
15
6
- others examples are not all ready. Check comments in the files.
- start with simples instructions to do arithmetic
- compile code
- update lexer to recognize
true
,false
,eq
,neq
- implement new tokens ^^
- allow comments
- add conditionnal if
- add while loop
- manage memory
- what else to be Turing complete?
- Run Game Of Life to prove the Turing completeness
- Implement Load and Store in memory
- memory is 1024 bytes
- Conditionnal and loop are now compiled
- Introduce the interpreted version of the while loop
- all tests are now running in interpreted mode
- blocks are not yet available in compiled mode
- Adding conditionnal block
if ... else ... end
- Report
filename:line:col:<error msg>
in case of error
- Add
Eq
,Neq
,Dup
,Swap
,Mul
,Divmod
,Gth
,Lth
,Not
- Add
False
andTrue
- Update lexer to recognize identifiers
- Generate code for
+
,-
,.
.- So we can print result of addition and substraction
- Compile an hello world program
- Add a minimal help
- Read the code from
arithmetic.vorth
and print the result - Replace
Pop
byDot
to be more like Forth and translate string to ops - Add operations:
Add
,Sub
,Push
andPop
- First implement a stack in V