aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-09-01 12:33:52 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-09-01 12:33:52 +0100
commit476b0d2d6c27b9ec326b465480795582a3b22f4c (patch)
tree169b5500a5b4688349aac77f1bf7bd9be63b655b
parent1788a581c9533c9231f7d5d44e2631a36dc92e47 (diff)
downloadmicro-lang-hs-476b0d2d6c27b9ec326b465480795582a3b22f4c.tar.gz
micro-lang-hs-476b0d2d6c27b9ec326b465480795582a3b22f4c.zip
Refinement, formatting
-rw-r--r--language.md51
1 files changed, 28 insertions, 23 deletions
diff --git a/language.md b/language.md
index 1092a57..9adb6f6 100644
--- a/language.md
+++ b/language.md
@@ -76,9 +76,13 @@ p = 0; # byte at 0x8000 is now 0 (poke)
### Constants
-Constant are immutable values and no memory is allocated for them:
+Constant are immutable values and may not have memory allocated to them:
```
+# won't allocate memory
const K: u8 = 10;
+
+# will allocate 10 bytes
+const V: [10]u8 = 255;
```
Group declaration:
@@ -100,19 +104,19 @@ const A: u8 = a + 1; # error: unresolved value
### Integers
-| Type | Description | Samples |
-| --- | --- | --- |
-| u8 | unsigned 8-bit | `123; 0xce; 0b10000;` |
-| s8 | signed 8-bit | `-123;` |
-| u16 | unsigned 16-bit | `65535; 0xffff;` |
-| s16 | signed 16-bit | `-4096;` |
+| Type | Description | Samples |
+| --- | --- | --- |
+| u8 | unsigned 8-bit | `123; 0xce; 0b10000;` |
+| s8 | signed 8-bit | `-123;` |
+| u16 | unsigned 16-bit | `65535; 0xffff;` |
+| s16 | signed 16-bit | `-4096;` |
Built-in functions:
-| Function | Description | Samples |
-| --- | --- | --- |
-| hi | Get the MSB on a 16-bit number | `hi(0xaabb); # 0xaa`|
-| lo | Get the LSB on a 16-bit number | `lo(0xaabb); # 0xbb`|
+| Function | Description | Samples |
+| --- | --- | --- |
+| hi | Get the MSB on a 16-bit number | `hi(0xaabb); # 0xaa` |
+| lo | Get the LSB on a 16-bit number | `lo(0xaabb); # 0xbb` |
`hi` and `lo` can also be used with references (functions, structures and arrays):
```
@@ -134,16 +138,16 @@ u16(a) + b; # 20: u16
Logic operators result on a boolean type.
-| Type | Description | Samples |
-| --- | --- | --- |
-| bool | boolean | `true; false; 1 == 1;` |
+| Type | Description | Samples |
+| --- | --- | --- |
+| bool | boolean | `true; false; 1 == 1;` |
### Functions
-| Type | Description | Samples |
-| --- | --- | --- |
-| ([parameters]) -> [return] | functions | `(a: u8) -> u8 { return a + 1; }` |
-| ([parameters]) | functions (no return value) | `() { return; }` |
+| Type | Description | Samples |
+| --- | --- | --- |
+| ([parameters]) -> [return] | function | `(a: u8) -> u8 { return a + 1; }` |
+| ([parameters]) | function (no return value) | `() { return; }` |
Functions can be declared with `def` when they have a name, or as anonymous using the lambda syntax.
@@ -204,7 +208,7 @@ private def dec(a: u8): u8 {
}
```
-Function variables use references:
+Variables of type function use references:
```
def fn() { return; }
@@ -252,7 +256,7 @@ def A {
}
}
-# instantiate structure A
+# allocate memory for structure A
var a: A;
a.n; # 100
@@ -334,9 +338,10 @@ def fn(): [5]u8 {
Built-in functions:
-| Function | Description | Samples |
-| --- | --- | --- |
-| len | get the length of an array as u16 | `len(arr); # 5`|
+| Function | Description | Samples |
+| --- | --- | --- |
+| len | get the length of an array as u16 | `len(arr); # 5` |
+| incbin | load a binary file as []u8 | `const f: []u8 = incbin("file.bin");` |
### Strings