diff --git a/README.md b/README.md index eb36cfb..0e8f6ca 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # PlanckForth: Bootstrapping Forth from Handwritten ELF Binary -This project aims to bootstrap a Forth interpreter from hand-written tiny ELF binary, for fun. -No practical use. +This project aims to bootstrap a Forth interpreter from hand-written tiny ELF binary. +This is just for fun. No practical use. ## How to build @@ -50,45 +50,45 @@ $ ./planck < bootstrap.fs runtests.fs # Builtin Words -| code | name | stack effect | semantics | -|:----:|:----------|:----------------|:-----------------------------| -| Q | quit | ( n -- ) | Exit the process | -| C | cell | ( -- n ) | The size of Cells | -| h | &here | ( -- a-addr ) | The address of 'here' cell | -| l | &latest | ( -- a-addr ) | The address of 'latest' cell | -| k | key | ( -- c ) | Read character | -| t | type | ( c -- ) | Print character | -| j | jump | ( -- ) | Unconditional branch | -| J | 0jump | ( n -- ) | Jump if a == 0 | -| f | find | ( c -- xt ) | Get execution token of c | -| x | execute | ( xt -- ... ) | Run the execution token | -| @ | fetch | ( a-addr -- w ) | Load value from addr | -| ! | store | ( w a-addr -- ) | Store value to addr | -| ? | cfetch | ( c-addr -- c ) | Load byte from addr | -| $ | cstore | ( c c-addr -- ) | Store byte to addr | -| d | dfetch | ( -- a-addr ) | Get data stack pointer | -| D | dstore | ( a-addr -- ) | Set data stack pointer | -| r | rfetch | ( -- a-addr ) | Get return stack pointer | -| R | rstore | ( a-addr -- ) | Set return stack pointer | -| i | docol | ( -- a-addr ) | Get the interpreter function | -| e | exit | ( -- ) | Exit current function | -| L | lit | ( -- n ) | Load immediate | -| S | litstring | ( -- c-addr ) | Load string literal | -| + | add | ( a b -- c ) | c = (a + b) | -| - | sub | ( a b -- c ) | c = (a - b) | -| * | mul | ( a b -- c ) | c = (a * b) | -| / | divmod | ( a b -- c d ) | c = (a mod b), d = (a / b) | -| & | and | ( a b -- c ) | c = (a & b) | -| \| | or | ( a b -- c ) | c = (a \| b) | -| ^ | xor | ( a b -- c ) | c = (a ^ b) | -| < | less | ( a b -- c ) | c = (a < b) | -| u | uless | ( a b -- c ) | c = (a unsigned< b) | -| = | equal | ( a b -- c ) | c = (a == b) | -| { | shl | ( a b -- c ) | c = a << b (logical) | -| } | shr | ( a b -- c ) | c = a >> b (logical) | -| ) | sar | ( a b -- c ) | c = a >> b (arithmetic) | -| v | argv | ( -- a-addr u ) | argv and argc | -| V | version | ( -- c-addr ) | Runtime infomation string | +| code | name | stack effect | semantics | +|:----:|:----------|:----------------|:----------------------------------------| +| Q | quit | ( n -- ) | Exit the process | +| C | cell | ( -- n ) | The size of Cells | +| h | &here | ( -- a-addr ) | The address of 'here' cell | +| l | &latest | ( -- a-addr ) | The address of 'latest' cell | +| k | key | ( -- c ) | Read character | +| t | type | ( c -- ) | Print character | +| j | jump | ( -- ) | Unconditional branch | +| J | 0jump | ( n -- ) | Jump if a == 0 | +| f | find | ( c -- xt ) | Get execution token of c | +| x | execute | ( xt -- ... ) | Run the execution token | +| @ | fetch | ( a-addr -- w ) | Load value from addr | +| ! | store | ( w a-addr -- ) | Store value to addr | +| ? | cfetch | ( c-addr -- c ) | Load byte from addr with sign extension | +| $ | cstore | ( c c-addr -- ) | Store byte to addr | +| d | dfetch | ( -- a-addr ) | Get data stack pointer | +| D | dstore | ( a-addr -- ) | Set data stack pointer | +| r | rfetch | ( -- a-addr ) | Get return stack pointer | +| R | rstore | ( a-addr -- ) | Set return stack pointer | +| i | docol | ( -- a-addr ) | Get the code pointer of interpreter | +| e | exit | ( -- ) | Exit current function | +| L | lit | ( -- n ) | Load immediate | +| S | litstring | ( -- c-addr ) | Load string literal | +| + | add | ( a b -- c ) | c = (a + b) | +| - | sub | ( a b -- c ) | c = (a - b) | +| * | mul | ( a b -- c ) | c = (a * b) | +| / | divmod | ( a b -- c d ) | c = (a mod b), d = (a / b) | +| & | and | ( a b -- c ) | c = (a & b) | +| \| | or | ( a b -- c ) | c = (a \| b) | +| ^ | xor | ( a b -- c ) | c = (a ^ b) | +| < | less | ( a b -- c ) | c = (a < b) | +| u | uless | ( a b -- c ) | c = (a unsigned< b) | +| = | equal | ( a b -- c ) | c = (a == b) | +| { | shl | ( a b -- c ) | c = a << b (logical) | +| } | shr | ( a b -- c ) | c = a >> b (logical) | +| ) | sar | ( a b -- c ) | c = a >> b (arithmetic) | +| v | argv | ( -- a-addr u ) | argv and argc | +| V | version | ( -- c-addr ) | Runtime infomation string | # Implementations