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
+61-2Lines changed: 61 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ The heap is split in 2 pieces: A stack, used to store local variables, and a hea
28
28
The heap stack helps storing temporary values. Usually, the native stack will suffice, but it has a few disadvantages:
29
29
30
30
- It can only peek values below the stack pointer.
31
-
- It can't rearrange values.
31
+
- It can't rearrange values except for the top 2 (`swap`).
32
32
- It's the only way of performing any operation (i.e. there are no registers).
33
33
- This makes the offset for peeking also not stable.
34
34
@@ -96,6 +96,8 @@ It's based on [Burghard's WSA](https://github.com/wspace/burghard-wsa) as assemb
96
96
-`inc` renamed to `readc`.
97
97
-`inn` renamed to `readn`.
98
98
99
+
The compiler also performs tree shaking: it won't include unreachable parts of the code (unused labels).
100
+
99
101
## Extensions
100
102
101
103
While on debug mode, this interpreter adds some language extensions to debug or increase performance. For this, a few more operations are added, both to the assembler and the whitespace code ops:
@@ -120,10 +122,12 @@ See [Memory layout convention](#memory-layout-convention)
120
122
### Bitwise
121
123
122
124
-`bitwise_and(a,b)`
125
+
-`bitwise_xor(a,b)`
123
126
-`bitwise_or(a,b)`
124
127
-`bitwise_not(a)`
125
-
-`bitwise_not_mod(a, m)`: Performs a bitwise not operation but only for the low `m`bytes.
128
+
-`bitwise_not_mod(a, m)`: Performs a bitwise not operation but only for the low `m`bits.
126
129
-`bitwise_mask(m)`: Creates a mask with `m` 1s (essentially 2^m-1)
130
+
-`bitwise_rotl(n,m,bits)`: Rotates the number `n`, `m` positions to the left, with a mask of `bits` bits.
127
131
128
132
This library uses the language extensions if they are enabled, otherwise uses the standard 0.3 WS opcodes.
129
133
@@ -137,3 +141,58 @@ This library uses the language extensions if they are enabled, otherwise uses th
137
141
### Math
138
142
139
143
-`math_exp_2(v)`: Performs the operation 2^v
144
+
145
+
### Memcontainer
146
+
147
+
Small data structure to have a stable reference on other data structures that can get reallocated.
148
+
149
+
It basically allocates 2 blocks: The container that can grow in size (and maybe reallocated), and a 1-byte one that just has the pointer to the container. This way the fixed one will keep the same reference across reallocations.
150
+
151
+
To get the actual address, just `retrieve` to read the pointer value.
152
+
153
+
-`memcontainer_new(capacity)`: Initializes a new container with an initial `capacity`
154
+
-`memcontainer_destroy(&container)`: Frees up the reference `&container`
155
+
-`memcontainer_get_capacity(&container)`: Returns the current capacity of the container.
156
+
-`memcontainer_ensure_capacity(&container, capacity)`: If the container has less than `capacity` capacity, it resizes it.
157
+
158
+
### Vector
159
+
160
+
Resizable data structure to add / remove items to a list. It keeps a stable reference through `memcontainer`.
161
+
162
+
-`vector_new(capacity)`: Creates a new vector
163
+
-`vector_destroy(&vector)`: Frees up the reference `&vector`
164
+
-`vector_fill(&vector, length, value)`: Fills in the vector with `value` for `length` (resizing the vector if needed).
165
+
-`vector_get_addr(&vector)`: Returns the current base address of the vector.
166
+
-`vector_get_capacity(&vector)`: Returns the capacity of the vector.
167
+
-`vector_get_length(&vector)`: Returns the length of the vector.
168
+
-`vector_set_length(&vector, length)`: Sets the length of the vector (truncating or resizing as needed).
169
+
-`vector_push(&vector, value)`: Pushes the value to the vector.
170
+
-`vector_pop(&vector)`: Pops the last element from the vector.
171
+
-`vector_slice(&vector, offset, length)`: Returns a new vector with a copy from offset for `length` bytes.
172
+
-`vector_splice(&vector, offset, length)`: Returns a new vector without the values from offset for `length` bytes.
173
+
-`vector_push_all(&vector, &other_vec)`: Pushes all the elements of `&other_vec` to `&vector`
174
+
175
+
### Slotmap
176
+
177
+
Data structure to allocate and free fixed-size blocks a bit more efficiently than through the heap. Meant to build other data structures on top that perform a lot of small allocations (e.g. trees, linked lists, etc.).
178
+
179
+
-`slotmap_new(element_size)`: Creates a new slotmap for elements of `element_size` bytes.
180
+
-`slotmap_destroy(&slotmap)`: Frees up the reference `&slotmap`.
181
+
-`slotmap_allocate(&slotmap)`: Allocates a new block, returns its id.
182
+
-`slotmap_free(&slotmap, id)`: Frees up the space for the block `id`.
183
+
-`slotmap_get_addr(&slotmap, id)`: Returns the base address for the block `id`.
184
+
185
+
### RBTree
186
+
187
+
Key-value data structure using a simplified implementation of a red-black tree. Deletion doesn't guarantee to keep the tree balanced.
188
+
189
+
-`rbtree_new()`: Creates a new RBTree-
190
+
-`rbtree_destroy(&RB)`: Frees up the reference `&RB`.
191
+
-`rbtree_insert(&RB, key, value)`: Inserts a new entry with `key` and `value`.
192
+
-`rbtree_get(&RB, key)`: Finds the entry by `key`, returns `[value,found]`, where found is 1 or 0 indicating if the value was found. If not found, `value` may have any random value.
193
+
-`rbtree_remove(&RB, key)`: Removes the entry by `key`.
194
+
-`rbtree_print(&RB)`: Prints the tree to the console (for debugging).
195
+
-`rbtree_get_sorted(&RB)`: returns the entries [key,value] into a vector, sorted by key ascending.
196
+
-`rbtree_is_empty(&RB)`: returns whether the tree is empty.
197
+
-`rbtree_get_smallest(&RB)`: returns the entry with smallest key.
198
+
-`rbtree_get_biggest(&RB)`: returns the entry with biggest key.
0 commit comments