Skip to content

Commit 5653679

Browse files
committed
update README
1 parent 624acac commit 5653679

File tree

1 file changed

+55
-10
lines changed

1 file changed

+55
-10
lines changed

README.md

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,27 @@ Targeting compatibility with [Lazy wspace](https://github.com/thaliaarchi/lazy-w
1212

1313
- Each memory position can store up to a u128 number
1414
- Memory is addressable within 32 bit, from 0 to 4_294_967_294
15+
- Mod operation works as the original implementation in haskell (5%-3 = -1, -5%3 = 1)
16+
- Supports up to whitespace 0.3 instructions (copy, slide)
1517

1618
## Memory layout convention
1719

1820
The stdlib defined by this repo sets a couple of conventions to perform calls and manage the heap.
1921

20-
To start off, the default convention for calls is pass arguments through the stack, pushing them in the original order. The call will consume all of the arguments, removing them from the stack, and optionally it will push a value for the return value.
22+
To start off, the default convention for calls is pass arguments through the stack, pushing them in the original order. The call will consume all of the arguments, removing them from the stack, and it will push as many return values as defined for that function (0-infinite).
2123

2224
Strings, vectors, etc. Must be allocated in the heap, and are always passed by reference.
2325

2426
The heap is split in 2 pieces: A stack, used to store local variables, and a heap, where blocks can be allocated or freed.
2527

2628
The heap stack helps storing temporary values. Usually, the native stack will suffice, but it has a few disadvantages:
2729

28-
- It can only peek past values.
29-
- It can't reorganise values.
30-
- It's the only way of performing any operation.
30+
- It can only peek values below the stack pointer.
31+
- It can't rearrange values.
32+
- It's the only way of performing any operation (i.e. there are no registers).
3133
- This makes the offset for peeking also not stable.
3234

33-
With the heap stack, each function can assume that their stack is empty, and then use as much space as they need with something that the offsets will remain stable while performing operations.
35+
With the heap stack, each function can assume that their stack is empty, and then use as much space as they need with something that the offsets will remain stable while performing operations. There's a tradeoff with a small performance hit though, since reading and writing from the heap stack requires multiple operations.
3436

3537
The memory layout is as follows:
3638

@@ -44,10 +46,12 @@ The standard library on memory provides a few methods to deal with heap stack:
4446

4547
- `stack_freeze(n)`: Removes `n` from the native stack and pushes them onto the native stack, in the same order.
4648
- `stack_restore(n)`: Removes `n` from the heap stack and pushes them onto the native stack, in the same order.
49+
- `stack_reserve(n)`: Moves the stack pointer `n` positions to the front.
4750
- `stack_discard(n)`: Removes `n` from the heap stack.
4851
- `stack_get(offset)`: Gets the nth element from the stack (starting at 0).
4952
- `stack_get_head()`: Sugar for `stack_get(0)`.
5053
- `stack_set(offset, value)`: Sets the nth element of the stack (starting at 0) to `value`.
54+
- `stack_set_head(value)`: Sugar for `stack_get(0, value)`.
5155

5256
### Heap
5357

@@ -61,34 +65,75 @@ The standard library on memory provides few methods to deal with heap:
6165

6266
- malloc(size): Creates a new block.
6367
- It will try to put it as close to the end of the memory as possible.
64-
- If no gaps are found, it will put it as the new first element.
68+
- If no gaps are found, it will put it as the last block of the list.
6569
- If gaps are found, then it will get in between.
6670
- Returns pointer to start of data.
6771
- mfree(data_pointer): Frees up a block.
6872
- It will update the linked list accordingly.
69-
- No need for the blocks to be double-linked, I can always search from the start.
73+
- It will find the neighbouring blocks by traversing the block list from the start.
7074
- realloc(data_pointer, size): Reallocates a block.
7175
- Shrinking will not move it.
7276
- Expanding will try to not move it if possible.
7377
- If not, it will allocate a new block, move everything, and delete.
7478
- Returns pointer to start of data.
7579
- memcpy(source, dest, size): Copies data from one side to the other.
76-
- Doesn't handle overlaps
80+
- Doesn't handle overlaps (so it is the same behaviour as C's lib memcpy as opposed to memmove)
7781
- memset(dest, value, size): Sets all the values of block to `value`.
7882

7983
## Assembly language
8084

81-
It reuses [Burghard's WSA](https://github.com/wspace/burghard-wsa) as assembly language, but with a few modifications:
85+
It's based on [Burghard's WSA](https://github.com/wspace/burghard-wsa) as assembly language, but with a few modifications:
8286

8387
- Removes `pushs`, `ifoption`, `elseoption`, `endoption`, `elseifoption`, `debug_printstack`, `debug_printheap`
8488
- Adds:
8589
- `copy n`: Copy the nth element from the stack to the top of the stack (operation added in whitespace v0.3)
8690
- `slide n`: Slide n items off the stack, keeping the top one (operation added in whitespace v0.3)
8791
- `storestr str`: Stores `str` in the heap using the address defined in the top of the stack (and consuming it).
88-
- `debugger`: Signals the interpreter to pause execution at that point.
8992
- Modifies:
9093
- Strings (labels, string literals) don't need to be wrapped between ""
9194
- `retrive` renamed to `retrieve`.
9295
- `doub` renamed to `dup`.
9396
- `inc` renamed to `readc`.
9497
- `inn` renamed to `readn`.
98+
99+
## Extensions
100+
101+
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:
102+
103+
- `debugger`: "LLS" Signals the interpreter to pause execution at that point.
104+
- `and`: "TSLL" Performs the bitwise and operation of the top 2 values of the stack.
105+
- `or`: "TSLS" Performs the bitwise or operation of the top 2 values of the stack.
106+
- `not`: "TSLT" Performs the bitwise not operation to the top value of the stack.
107+
108+
As these are not whitespace standard, the assembler will omit the `debugger` instruction if the extension is not enabled, and throw an Error for the bitwise operations.
109+
110+
## STD lib
111+
112+
This assembler has a few (WIP) std libraries with common operations. The ones dealing with the memory convention explained above can be imported with `include memory`.
113+
114+
The source of these libraries can be found in `src/wsa/lib`
115+
116+
### Memory
117+
118+
See [Memory layout convention](#memory-layout-convention)
119+
120+
### Bitwise
121+
122+
- `bitwise_and(a,b)`
123+
- `bitwise_or(a,b)`
124+
- `bitwise_not(a)`
125+
- `bitwise_not_mod(a, m)`: Performs a bitwise not operation but only for the low `m` bytes.
126+
- `bitwise_mask(m)`: Creates a mask with `m` 1s (essentially 2^m-1)
127+
128+
This library uses the language extensions if they are enabled, otherwise uses the standard 0.3 WS opcodes.
129+
130+
### IO
131+
132+
- `prints(&s)`: Outputs the null-terminated string at address `s`.
133+
- `printsln(&s)`: Outputs the null-terminated string at address `s`, with a `\n` at the end.
134+
- `print_byte_hex(v)`: Prints the 8-bit value `v` as hex.
135+
- `print_char_hex(v)`: Prints the 4-bit value `v` as hex.
136+
137+
### Math
138+
139+
- `math_exp_2(v)`: Performs the operation 2^v

0 commit comments

Comments
 (0)