blob: 92039072458ad9d9ea424c6c0fe79b0acc1348b1 (
plain)
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
|
# Numeric types
Instead of "number", integer:
* i8, i16: signed
* u8, u16: unsigned
Operations:
* x.lo and x.hi are r/w properties to get/set low/high bytes in 16-bit numbers
* i8(x), u8(x), i16(x), u16(x) for conversions (there are no implicit conversions)
Consequences:
* array index is either u8 or u16
# Strings
Strings are zero ended arrays of u8 that can be represented as a literal using double quotes.
```micro
// 6 characters plus a 0 at the end
var s [7]u8 = "string";
// change value; length <= array size
s = "value";
s = "another";
// error: string is too long for [7]u8
```
Notes:
* "xxx" + 0 to initialize an array of u8
* can be used to change the value
* the string can be shorter than the array space, but length + 1 must fit in the array
The interpreter built-in `println` will print literals as strings, but in order to output an array of u8 as a string, use `str` property:
The following escape sequences are supported in both strings and character literals:
* In string literals `\"` for a double quote.
* In character literals `\'` for a single quote.
* `\n` for end of line.
* `\t` for tab.
* `\x00` for a 2 digits hex number (8-bit).
* `\\` for the backslash itself.
```micro
// the array is initialized to zeroes
var s [10]u8;
s[0] = 'H';
s[1] = 'e';
s[2] = 'l';
s[3] = 'l';
s[4] = 'o';
println(s.str);
// output: Hello
```
# Constants and expression evaluation
The parser should resolve most constants and expression evaluation.
e.g. `a = 1 + 2` -> `a = 3`
Constant as literal replacement (constants MUST be literals after expression evaluation).
Built-in `len` should be resolved at parsing time (applies to array size and that is static).
# Remove closures
* why: they are dynamic
* can we have a limited closure?
# Directives
Include a file in current source and it will interpreted / compiled.
```micro
include "file.micro"
```
Include a binary file as an expression list to initialize an array.
```micro
var arr [64]number = incbin "file.micro";
```
|