| 1 | # Overview # |
| 2 | |
| 3 | This folder contains a library of useful functions written in VVhitespace. |
| 4 | Standard include guards are used with `cpp` to include the stdlib in user |
| 5 | programs. For an example, see `examples/hello-stdlib`. |
| 6 | |
| 7 | # Reservations # |
| 8 | |
| 9 | Since all labels share a global namespace, the standard library makes the |
| 10 | following reservations: |
| 11 | |
| 12 | ## Label ## |
| 13 | |
| 14 | 00000000 0xxxxxxx - reserved for stdlib function entry points |
| 15 | 00000000 1xxxxxxx - unassigned |
| 16 | 0xxxxxxx xxxxxxxx - reserved for private use by stdlib |
| 17 | 1xxxxxxx xxxxxxxx - available for use in user programs |
| 18 | |
| 19 | ## Heap and Pointers ## |
| 20 | |
| 21 | The first 16 heap addresses (`0-15`) are reserved when using the stdlib. |
| 22 | Within that reservation, heap[0] is used by `random` and heap[15] is used |
| 23 | by `spewreg`. The remaining 14 locations, heap[1]-heap[14] are used as |
| 24 | general-purpose registers. |
| 25 | |
| 26 | By convention, functions which return a pointer will use the address `0` to |
| 27 | represent a `NULL` pointer. |
| 28 | |
| 29 | # Entry Points # |
| 30 | |
| 31 | The following labels are entry points to stdlib functions. Read the |
| 32 | header comment for each function to learn the call and return stack. |
| 33 | |
| 34 | 000xxx - reserved |
| 35 | 001xxx - core functions |
| 36 | 1000 ----- printf (stdio.pvvs) |
| 37 | 1001 ----- print number from stack (stdio.pvvs) |
| 38 | 1010 ----- stackrotate (stack.pvvs) |
| 39 | 010xxx - math functions |
| 40 | 10000 ----- random (math.pvvs) |
| 41 | 10001 ----- absolute value (math.pvvs) |
| 42 | 011xxx - heap functions |
| 43 | 11000 ----- memset (heap.pvvs) |
| 44 | 11001 ----- memcpy (heap.pvvs) |
| 45 | 11010 ----- memrand (heap.pvvs) |
| 46 | 11011 ----- memcmp (heap.pvvs) |
| 47 | 11100 ----- memsrch (heap.pvvs) |
| 48 | 11101 ----- <empty> |
| 49 | 11110 ----- slurp (heap.pvvs) |
| 50 | 11111 ----- spew (heap.pvvs) |
| 51 | 100xxx - string functions |
| 52 | 100000 ----- strlen (string.pvvs) |
| 53 | 101xxx - unassigned |
| 54 | 110xxx - conversion functions |
| 55 | 111xxx - debug functions |
| 56 | 111000 ----- dump heap (debug.pvvs) |
| 57 | 111001 ----- dump stack (debug.pvvs) |
| 58 | 1xxxxxx - reserved for less common entry points |
| 59 | 1000000 ----- slurp registers (heap.pvvs) |
| 60 | 1000001 ----- spew registers (heap.pvvs) |
| 61 | 1000010 ----- print sign of number (stdio.pvvs) |
| 62 | 1000011 ----- print magnitude of number (stdio.pvvs) |
| 63 | 1000100 ----- print string from stack (stdio.pvvs) |
| 64 | 1000101 ----- print string from heap (stdio.pvvs) |
| 65 | |
| 66 | # Misc # |
| 67 | |
| 68 | By convention, each public stdlib label will have 8 bits of |
| 69 | private label space associated with it, formed as follows: |
| 70 | |
| 71 | 00001000 xxxxxxxx - for use by 1000 |
| 72 | 00001001 xxxxxxxx - for use by 1001 |
| 73 | ...etc |