-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadme.txt
155 lines (110 loc) · 3.87 KB
/
readme.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
------------
|Metasubleq|
------------
-----------------------------
|Designed by DivergentClouds|
-----------------------------
Subleq:
Subleq is a computer architecture with only one instruction
Due to the fact that there is only one instruction opcodes are not needed
There is no distinction between code and data
Code can self modify
An instruction takes the form:
A B C
Where the contents of address A are subtracted from the contents of address B
and the result is stored in address B, if the result is less than or equal
to 0 then branch to address C
That is:
*B = *B - *A;
if (*B <= 0) {
goto C;
}
Macros:
Square brackets indicate a macro
A colon after the parameters indicates macro definition
A macro may take an arbitary number of arguments
The format for defining a macro is [name param1 param2 ...: code]
To access an argument use its name in the code section
The format for using a macro is [name arg1 arg2 ...]
The content of a macro is in its own namespace
Macros may be called from within other macros
Note that macros are inserted directly into your code and are not jumped to
Labels:
A label marks the address it was defined at
To define a label type the label name followed by a colon
For example:
name:
Referencing the address of a label is done by using its name
For example:
name
Variables:
Variables are a special case of label that are defined in curly brackets
Variables are stored in memory directly after code
Variables take the form of a name followed by a colon followed by 1 or more
values
For example:
{name: value1 value2 ...}
Referencing the address of a variable is done by using its name
Variables may only be accessed within the namespace they were defined in
Variables may be overwritten from within the namespace in which they were
defined
Special Characters:
#
Word size in bytes
.
The location of the start of the current instruction in memory
>
The location of the start of the next instruction in memory
<
The location of the start of the previous instruction in memory
Expressions:
Expressions are compiletime mathematical operations
Expressions are contained within parentheses
Expressions follow regular order of operations:
Parentheses
Exponentiation
Multiplication/Division
Addition/Subtraction
In case of ambiguity expressions are evaluated left to right
Expressions may contain any value
Valid operations are:
^
Exponentiation
*
Multiplication
/
Integer Division (Floored)
+
Addition
-
Subtraction
Example:
(> + # * 3)
This is equal to the address of the start of the instruction after the next
instruction
Location Editing:
An expression or number followed by a colon means that further code is
stored starting at that location
Comments:
Comments are started by a semicolon and last until the end of the line
Imports:
Additional files may be imported via the ! symbol at the start of a line
For example:
!name path/to/file
Anything after the name on that line is counted as part of the file path
Macros and global variables from that file can then be accessed as
[name!macro arg1 arg2 ...] or name!variable
Imports may not be accessed outside of the file that imported them
Notes:
Metasubleq is mostly whitespace insensitive
Imports and comments last until the end of a line and tabs are not allowed
Metasubleq is case sensitive
Names are of the form [_a-zA-Z][_a-zA-Z0-9]*
A value is a number, label reference, variable, expression or special character
Names may not collide with any other name in their own namespace
or the global namespace
(aside from variable redefinition)
Macros are part of the global namespace
Parameters are part of the namespace of the relevant macro
Variables are part of the namespace they were defined in
Label names are part of the namespace they were defined in