|
| 1 | +# Description |
| 2 | +soil or Stack Oriented Interpreted Language |
| 3 | +is a project of mine that I did in python |
| 4 | +to challenge myself to dive into the world of |
| 5 | +language design despite my 0 knowledge in the field. |
| 6 | + |
| 7 | +# Basic Syntax and Tutorial |
| 8 | +soil's syntax is a mix between assembly and python's bytecode |
| 9 | +with the usual format of **[opname] [arg1] [arg2]** and so on.... |
| 10 | + |
| 11 | +* ### Hello World in soil |
| 12 | +``` |
| 13 | + print "Hello World" |
| 14 | +``` |
| 15 | + |
| 16 | +* ### Variables |
| 17 | +To create a variable in soil, you have to load two things onto the stack: **the value**, |
| 18 | +and **the name of the variable**. and then after that you can spawn a variable. |
| 19 | + |
| 20 | +``` |
| 21 | + load int 5 # load the value 5 onto the stack |
| 22 | + load string x # load the name of the variable (no quotes needed if the string has no spaces) |
| 23 | + spawn var # spawn the variable |
| 24 | +``` |
| 25 | + |
| 26 | +and now we have a variable called "x" with the value of 5. and now we can print the variable: |
| 27 | + |
| 28 | +``` |
| 29 | + print var x |
| 30 | +``` |
| 31 | + |
| 32 | +to reassign value to a variable, you can load a value onto the stack and then |
| 33 | +use the keyword `assign` and then followed |
| 34 | +by the variable name: |
| 35 | + |
| 36 | +``` |
| 37 | + load int 10 |
| 38 | + assign x |
| 39 | +``` |
| 40 | + |
| 41 | +and now the variable "x" contains the number 10. |
| 42 | + |
| 43 | +# Arithmetic Operations |
| 44 | + |
| 45 | +| OPERATOR | Description | |
| 46 | +|---------- |---------------------------------------------------------------------- | |
| 47 | +| add | add two numbers previously loaded on the stack | |
| 48 | +| sub | subtract two numbers previously loaded onto the stack | |
| 49 | +| mul | multiply two numbers previously loaded onto the stack | |
| 50 | +| div | perform division on the two numbers previously loaded onto the stack | |
| 51 | +| mod | perform modulo on the two numbers previously loaded onto the stack | |
| 52 | + |
| 53 | +Arithmetic operations can be done in soil by |
| 54 | +1. Loading the first operand |
| 55 | +2. Loading the second operand |
| 56 | +3. And then perform arithmetic operations on those two numbers |
| 57 | + |
| 58 | +Like this: |
| 59 | + |
| 60 | +``` |
| 61 | + load int 10 |
| 62 | + load int 5 |
| 63 | + add inplace |
| 64 | +``` |
| 65 | + |
| 66 | +storing the result of the arithmetic operation can be done in two ways: either store them inplace, |
| 67 | +or adjacent to the loaded operands. Let's visualize the stack! |
| 68 | + |
| 69 | +``` |
| 70 | + load int 10 |
| 71 | +``` |
| 72 | + |
| 73 | +**stack: [10]** |
| 74 | + |
| 75 | +``` |
| 76 | + load int 5 |
| 77 | +``` |
| 78 | + |
| 79 | +**stack: [10, 5]** |
| 80 | + |
| 81 | +if you use the inplace mode, it will pop the two operands, add them, and then push result |
| 82 | +onto the stack: |
| 83 | + |
| 84 | +``` |
| 85 | + add inplace |
| 86 | +``` |
| 87 | + |
| 88 | +**stack: [15]** |
| 89 | + |
| 90 | +if you use adjacent mode, it will copy the two operands, add them, and then push the result |
| 91 | +onto the stack: |
| 92 | + |
| 93 | +``` |
| 94 | + add adjacent |
| 95 | +``` |
| 96 | + |
| 97 | +**stack: [10, 5, 15]** |
0 commit comments