-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLANGSPEC
More file actions
200 lines (149 loc) · 8.01 KB
/
LANGSPEC
File metadata and controls
200 lines (149 loc) · 8.01 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
Cute BASIC uses all uppercase keywords.
Cute BASIC files are all uppercase with the *.CB extension.
Variable names can use both cases, plus numerals and underscores.
Must start with a letter or underscore.
Variable scope is:
-Global if defined outside of START ... END or DEFINE ... ENDFUNCTION block
-Local to block (or function) they're declared inside, plus blocks (loop or if) contained within that block
-Static to function if declared as static (not sure how to yet)
Literals:
-Default to decimal
-CHAR (character) evaluates to ASCII (or UTF-8) binary representation of char - 'A' or '#'
-0x causes evaluation as hexadecimal - 0x0BADF00D
-0b causes evaluation as binary - 0b00110101
Literal TRUE => any non-zero variable (written as literal, evaluates to b0001)
Literal FALSE => zero
Precedence: assignment = evaluates last. Comparisons evaluate after math/bitwise, and logical after comparison.
Unary operators evaluate before binary ones of same type. Otherwise, parens must be used -> compiler complains if not present.
so, overall: parens => calls => unary math/bitwise/pointer => binary math/bitwise => Comparison => unary logical => binary logical => assignment/control
SIGNED and UNSIGNED keywords - maybe apply broadly? (without specifying at on other keywords)
If a variable is unspecified then it is automatically set to UNSIGNED
From here on: Any variables, other than when assigned to, can also be a literal or another valid expression.
Declaration and initialization:
LET (variable name) : Creates a variable called (variable name)
LET (variable name) BE (number) : Creates a variable called (variable name) and assigns (number) to it
LET (variable name) AS (size in nibbles) : Creates a variable called (variable name) with a size in nibbles of (size in nibbles)
/*LET (variable name) AS (size in nibbles) BE (number) : Creates a variable called (variable name) with a size in nibbles of (size in nibbles) and assigns (number) to it */
Note: Size in nibbles must be 4, 8, 16, 32 or 64
Assignment:
(var1) BE (var2) : Assigns value of var2 to var1. UNSIGNED keyword is implied. var2 can be a literal.
(var1) BE (var2) UNSIGNED : assigns value of var2 to var1. Truncates or zero-extends
(var1) BE (var2) SIGNED : assigns value of var2 to var1. Truncates (maintaining value of MSB) or sign-extends
/May not be accurate any more
Values are stored big-endian
Values are stored in 4 bit int chunks, so for example lets try to store 268 (0000 0001 0000 1100) in a 4 nibble chunk:
LET A AS 4 BE 268
Will store values:
A[0].data = 0
A[1].data = 1
A[2].data = 0
A[3].data = 12
Unary mathematical operators:
(var0) BE NEGATE (var1) : var(0) evaluates to -(var1). In 2's complement, so (COMPLEMENT var1) ADD 1
(var0) BE INCREMENT (var1) : var(0) evaluates to (var1 + 1)
(var0) BE DECREMENT (var1) : var(0) evaluates to (var1 - 1)
Binary mathematical operators:
(var0) BE (var1) ADD (var2) : var(0) evaluates to sum of var1+var2
(var0) BE (var1) SUBTRACT (var2) : var(0) evaluates to difference of var1-var2
(var0) BE (var1) MODULUS (var2) : var(0) evaluates to remainder of var1/var2
(var0) BE (var1) MULTIPLY (var2) : var(0) evaluates to product of var1*var2
(var0) BE (var1) DIVIDE (var2) : var(0) evaluates to product of var1/var2
Unary logical operators:
(var0) BE NOT (var1) : var(0) evaluates to logical negation of var1
Binary logical operators:
-Consider safe ("lazy") execution - i.e. AND doesn't evaluate second expression if first expression is false
(var0) BE (var1) ALSO (var2) : var(0) evaluates to TRUE if both var1 and var2 are TRUE
(var0) BE (var1) EITHER (var2) : var(0) evaluates to TRUE if either var1 or var2 are TRUE
Unary bitwise operators:
(var0) BE COMPLEMENT (var1) : var(0) evaluates to bitwise complement of var1
Binary bitwise operators:
(var0) BE (var1) AND (var2) : var(0) evaluates to bitwise AND of variables
(var0) BE (var1) OR (var2) : var(0) evaluates to bitwise OR of variables
(var0) BE (var1) XOR (var2) : var(0) evaluates to bitwise XOR of variables
(var0) BE (var1) NAND (var2)
(var0) BE (var1) NOR (var2)
(var0) BE (var1) XNOR (var2)
Binary rotation:
(var0) BE (var1) LSHIFT (var2) : var(0) var2 should be small; left-shifts by var2, fills right with zeros, truncates anything that falls off left
(var0) BE (var1) RSHIFT (var2)
(var0) BE (var1) LROTATE (var2) : var(0) var2 should be small; left-rotates by var2, anything that falls off left gets put back on right
(var0) BE (var1) RROTATE (var2)
Pointers:
(var0) BE CONTENTOF (var1) : var(0) evaluates to dereferenced value pointed at by var1
(var0) BE ADDRESSOF (var1) : var(0) evaluates to (16-bit) address of var1
FUNCTIONS must go directly after START at the top of the program
Control:
START : The entry hook of the program
END : The exit hook of the program
IF...ENDIF
Conditionals:
IF (var1) COMPARATOR (var2)
ELSEIF (var1) COMPARATOR (var2)
ELSE
ENDIF
LOOP ... ENDLOOP
LOOPWHILE (var1) CONDITIONAL (var2)
ENDLOOP
Logical comparators:
EQUALS
NOTEQUALS
GREATER
GREATEREQUALS
LESS
LESSEQUALS
GOTO derivatives:
LOOPAGAIN : return to top of loop, as "continue"
EXITLOOP : exit innermost loop, as "break"
EXITLOOP (number) : exit (number) of loops. Compile error if number too high
EXITIF : exit innermost "if" block, as "break"
EXITIF (number) : exit (number) of if blocks. Compile error if number too high
EARLYEND : goto "END", as C "return" in main()
Probably include GOTO and labels, even though they make Naomi sad :(
LABEL (name)
GOTO (name)
Functions:
Declaration (probably c-like, in the old declare-before-first-use way):
/*: RETURNS and TAKES both optional, [] part can be repeated (comma-separated), funcName must be unique
FUNCTION (funcName) RETURNS (size in nibbles) TAKES [(size in nibbles) (paramName)] ASWELL...
FUNCTION (funcName) TAKES [(size in nibbles) (paramName)]
FUNCTION (funcName) RETURNS (size in nibbles)
FUNCTION (funcName)
for example,
FUNCTION simpleVoid TAKES 4 firstPointer ASWELL 4 secondPointer
FUNCTION getSysTime RETURNS 32*/
Definition:
FUNCTION (funcName) RETURNS ... TAKES ... ASWELL .... //RETURNS and TAKES are optional, but must match declaration signature
Code goes here
ENDFUNCTION (funcName);
Return:
RETURN (var1) : exits function, returns var1
Calls:
CALL (funcName) (var1) ASWELL (var2)... : var1, var2, are parameters. Evaluates to return type of funcName; evaluates to TRUE if nothing returned
(var0) BE CALL ... : Call witha return value
I/O:
NOHEADER: Remove CUTE BASIC header output
FILESIZE (variable) (file name): Get the size of (file name) and store it in (variable)
//ATs still needs work
CALL GETCHAR (variable) [AT (index)] (file name or STDIN if blank) [AT (index)] [FOR #]: Gets a character from file or STDIN(keyboard) for # chars
CALL PUTCHAR (variable) [AT (index)] (file name or STDOUT if blank) [AT (index)] [FOR #]: Writes a character to file or STDOUT(screen) for # chars
GETCHAR and PUTCHAR use nib indexes of 0 and number of 1 by default
GETCHAR returns FF as the cahracter if the file is ended
IMPORTANT:
When using GETCHAR for stdin it counts each "enter" as a newline char (including "enters" from previous input values)
If you try to FOR X in PUTCHAR where X is grater than the number of chars you have stored it breaks the file
Remeber that chars need two nibs each! (Otherwise you get munmap chunk errors that take to long to figure out...)
FOR PUTCHAR FILENAME AT X if X is greater than # of chars in the file it breaks the file
#: Single line comment indicator
/#: Start of multi line comment
#/: End of multi line comment
#goal is use non standard asm functions - function param is same set up as normal functions
ASM FUNCTION (Funcname) RETURNS (size in nibbles) TAKES [(size in nibbles) (paramName)] ASWELL...
body is asm (with fallthrough)
if label is normal param then make $param1 (special vals)
special value for return addr
C pointer style? No return?
ASM ENDFUNCTION (Funcname)
INCLUDE CUTEBASIC filename - label repalcer does stuff
INCLUDE ASM filename
INF BASEADRRESS_NUMBER (check out label replacer for standard)
Think of a pointer method - directly print memory value - determines base address in code