You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54-5Lines changed: 54 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,20 +13,37 @@ Ee.E.e!eeeeee!.Ee.E.e!
13
13
```
14
14
Disgustingly beautiful right?
15
15
16
+
## migraine interpreter internals
17
+
- 2 Immediate integer registers
18
+
- Where you'll be storing immediate values from functions
19
+
- The current usable register can be swapped with ``E``
20
+
- Function index
21
+
- Accesses all functions
22
+
- Can be traversed with ``e`` and, when the index is odd, ``! or .`` will execute a goto function
23
+
- Resets to 0 if the index is larger than the function list
24
+
- Program counter
25
+
- Keeps track of how far it is within the program
26
+
- Can be traversed through the branch function
27
+
- """Unlimited""" integer stack
28
+
- Lets you store values from registers. Basically makes this whole language functional
29
+
- Can be accessed through sevaral stack functions
30
+
16
31
## How do I use this nightmare?
17
32
migraine has only 4 operation characters, but it lets you do everything you need.
18
33
| Character | Operation | Purpose |
19
34
| --- | --- | --- |
20
35
|``e``| Function index increment | Iterates through the function list |
21
-
|``.``| Execute function | Executes the current function determined by the function index. Passes through the current register |
36
+
|``.``| Execute function | Executes the current function determined by the function index. Passes the current register to the function as a parameter|
22
37
|``!``| Execute function pass 0 | Very similar to ``.`` however this purposefuly passes 0 to the function instead of a register |
23
38
|``E``| Swap register | Swap the current register |
24
39
25
-
migraine uses a function list that you iterate through using these operators in order to create logic. You might notice, you can only increment!
26
-
27
-
How do you decrement? This function list has a special function when the function index is odd, it has a goto function that allows you to traverse the function list however you fancy. ``e!`` is used quite a bit in programs as it sets the function index back to 0.
40
+
The interpreter has *also* been setup to ignore all characters following a ``#`` character, this allows for comments in code files. Yipee! Documentation!
28
41
29
42
### The function list
43
+
migraine uses a function list that you iterate through using the operators above in order to create logic. You might notice, you can only increment!
44
+
45
+
How do you decrement? This function list has a special function when the function index is an odd number, it has a goto function that allows you to traverse the function list however you fancy. ``e!`` is used quite a bit in programs as it sets the function index back to 0.
46
+
30
47
| Index | Function | Purpose |
31
48
| --- | --- | --- |
32
49
| 0 | number_0 | Sets the rightmost digit in the current register to 0 |
@@ -40,11 +57,43 @@ How do you decrement? This function list has a special function when the functio
40
57
| 16 | number_8 | Sets the rightmost digit in the current register to 8 |
41
58
| 18 | number_9 | Sets the rightmost digit in the current register to 9 |
42
59
43
-
Woah woah, okay before we continue. This number function is pretty versatile. You can chain them using ``.`` to assemble numbers.
60
+
Okay before we continue. This number function is pretty versatile. You can chain them using ``.`` to assemble numbers.
44
61
45
62
``ee ee ee!`` would set the current register to 3. If we were to then do ``ee.`` immediately afterwards, the current register would now be 34.
46
63
47
64
Say we want to reset the current register back to 0, we can do ``e!`` to reset the function index to 0, and then ``!`` which would set the current register to 0
48
65
66
+
This works because the number function internally looks something like this:
67
+
```
68
+
int number(int intRegister, int digit)
69
+
{
70
+
return (intRegister * 10) + digit;
71
+
}
72
+
```
73
+
It will always shift to the left to allow for a new digit, however when you pass 0 through (instead of a register) it resets.
74
+
| Index | Function | Purpose |
75
+
| --- | --- | --- |
76
+
| 20 | add | Adds the non-current register to the current register |
77
+
| 22 | subtract | Subtracts the current register from the non-current register |
78
+
| 24 | multiply | Multiplies the non-current register to the current register |
79
+
| 26 | divide | Divides the current register from the non-current register |
80
+
| 28 | input | Gets input from stdin through the console, copies to the current register |
81
+
| 30 | output_int | Output the current register as an integer to the console |
82
+
| 32 | output_char | Output the current register as a character to the console |
83
+
| 34 | compare_equals | Check if the current register is equal to the non-current register, the current register will be overriden with the result |
84
+
| 36 | compare_greater | Check if the current register is greater than the non-current register, the current register will be overriden with the result |
85
+
| 38 | branch | If the current register has a value greater than 0, it will set the program counter to the non-current register |
86
+
| 40 | stack_push | Push the current register to the stack |
87
+
| 42 | stack_pop | Pop from the top of the stack and override the current register with the popped value |
88
+
| 44 | stack_read | Read the stack by accessing at an index provided by the current register, the current register will be overriden with the read value |
89
+
| 46 | stack_write | Write to the stack by accessing at an index provided by the current register, overrites the stack entry with a new value from the non-current register |
90
+
91
+
Annnndd, that's all of them! That's the official function list however due to migraine being structured this way, it is completely possible to amend more functions to it. *The only issue is, the higher the index, the more ``e``'s are required to access them!!!*
49
92
93
+
All functions listed in the table (notice goto is left out, it's a special little guy) follow this pattern:
94
+
```cpp
95
+
currentRegister = function(EITHER currentRegister OR 0);
96
+
```
97
+
The result will always be given back to the current register.
50
98
99
+
I recommend checking out the ./Examples folder as I've included a few usable code demos with documentation!
0 commit comments