wslib
September 20, 2023 ยท View on GitHub
wslib is a library of utilities written in Whitespace, intended to become the standard library for an upcoming compiler.
Modules
arrayboolcharcryptohashintmapmathmatrixmemstringvm/deadfishvm/intcode
Style
Functions are documented with a prose description similarly to godoc, as
opposed to Javadoc. Labels prefixed with . are not exported.
Parameters and return values are specified with Forth-style
# (x y -- z) comments and preconditions are specified with
# Requires comments. These will hopefully become checked by the
compiler at every call site.
Using the heap for local variables is avoided when possible until the compiler has sufficient dataflow analysis that can allocate non-conflicting addresses and registerize most heap operations. Until then, and on most interpreters, stack operations are significantly faster than heap operations.
Syntax
wslib uses Whitelips/Nebula
instruction names, with extended arguments and shorthands. assemble.sh
converts the wslib dialect to a format recognizable by whitespace-rs.
Instruction shorthands
n->push n^->dup^n->copy nnslide->slide n+->add-->sub*->mul/->div%->mod
Instruction macros
2dup->^1 ^13dup->^2 ^2 ^24dup->^3 ^3 ^3 ^35dup->^4 ^4 ^4 ^4 ^46dup->^5 ^5 ^5 ^5 ^5 ^57dup->^6 ^6 ^6 ^6 ^6 ^6 ^68dup->^7 ^7 ^7 ^7 ^7 ^7 ^7 ^79dup->^8 ^8 ^8 ^8 ^8 ^8 ^8 ^8 ^810dup->^9 ^9 ^9 ^9 ^9 ^9 ^9 ^9 ^9 ^92drop->drop drop3drop->drop drop drop4drop->3slide drop5drop->4slide drop6drop->5slide drop7drop->6slide drop8drop->7slide drop9drop->8slide drop10drop->9slide dropn+->n +n-->n -n*->n *n/->n /n%->n %neg->-1 *j=->- jzj<->- jnj>->swap - jnj<=->1 + - jnj>=->swap 1 + - jnjeof->jn,jz, or1 - jn(depending on desired EOF behavior)
Imports
"module" import- import module"module" export- import module under the exporting module's name
Tokens
#line comments'X'ASCII characters'\a''\b''\t''\n''\v''\f''\r''\e'escapes'\xXX'hex escapes0xXXand-0xXXhex numbers
Contributing
If you'd like to help, get in touch by filing an issue, pull request, or sending me an email. There's lots of useful and interesting library APIs to implement!
TODO
-
io:prints_quoteprints_escapereadi_base- Unicode codepoint quoting
- Space-padded integers
-
math:gcdextended_gcdmodexpcrtprint_matrix_padded
-
cipher:rsa_encrsa_dec
-
wsparseinterpret
-
Tooling:
- Test driver that runs tests independently to simplify debugging and check for uncleared stack values
License
This project is made available under the Mozilla Public License, v. 2.0.