diff options
| -rw-r--r-- | jefs.fs | 1 | ||||
| -rw-r--r-- | jefs.s | 83 | ||||
| -rw-r--r-- | readme.md | 2 |
3 files changed, 85 insertions, 1 deletions
@@ -13,7 +13,6 @@ : [compile] parse find drop >cfa compile, ; immediate : ' parse find drop >cfa [compile] lit ; immediate \ note: no error handling (yet) : constant create [compile] lit 195 ( ret ) c, ; -65 constant TESTING : begin here @ ; immediate : again branch here @ 4 + - d, ; immediate \ add 4 to get to beginning of the next instruction @@ -84,6 +84,7 @@ defword "bye", bye, 0 syscall ret ; will not be reached +; mem access {{{ defword "@", fetch, 0 pspop r11 mov r12, qword [r11] @@ -186,6 +187,7 @@ defword "cmove,", _cmove_comma, 0 ; ( c-addr u -- ) add r12, r9 mov qword [here], r12 ret +; }}} ; note: this puts the _address it itself pushes_ on the stack ; maybe this is not the correct approach? @@ -579,6 +581,7 @@ defword "syscall3", syscall3, 0 ; ( rdx rsi rdi id -- rax ) pspush rax ret +; stack {{{ ; these stack wrangling words are dreadfully inefficient right now ; i will come back and make these less terrible later defword "dup", dup, 0 @@ -637,7 +640,9 @@ defword "2drop", twodrop, 0 defword "rdrop", rdrop, 0 pop r11 ret +; }}} +; math {{{ defword "+", plus, 0 pspop r11 pspop r12 @@ -668,6 +673,84 @@ defword "/mod", divmod, 0 pspush rax ret +defword "and", _and, 0 + pspop r11 + and [r14], r11 + ret + +defword "or", _or, 0 + pspop r11 + or [r14], r11 + ret + +defword "xor", _xor, 0 + pspop r11 + xor [r14], r11 + ret + +defword "invert", invert, 0 + not qword [r14] + ret +; }}} + +; comparison {{{ +; the 'neg' converts the sete 0x1 into 0xffff (-1) which is this forth's +; truth value +defword "=", equals, 0 + pspop r11 + pspop r12 + cmp r11, r12 + sete r13b + movzx r11, r13b + neg r11 + ret + +defword "<>", less_greater, 0 + pspop r11 + pspop r12 + cmp r11, r12 + setne r13b + movzx r11, r13b + neg r11 + ret + +defword "<", less, 0 + pspop r11 + pspop r12 + cmp r11, r12 + setl r13b + movzx r11, r13b + neg r11 + ret + +defword ">", greater, 0 + pspop r11 + pspop r12 + cmp r11, r12 + setg r13b + movzx r11, r13b + neg r11 + ret + +defword "<=", lesseq, 0 + pspop r11 + pspop r12 + cmp r11, r12 + setle r13b + movzx r11, r13b + neg r11 + ret + +defword ">=", greatereq, 0 + pspop r11 + pspop r12 + cmp r11, r12 + setge r13b + movzx r11, r13b + neg r11 + ret +; }}} + defword "[", lbrac, immediate_mask mov qword [state], interpreting ret @@ -40,6 +40,8 @@ so a wonky but hopefully not too slow solution is to compile ### Some Links - starting forth part 1: http://www.bradrodriguez.com/papers/moving1.htm +- jonesforth, public domain forth tutorial implementation which was significantly cribbed from and studied: http://git.annexia.org/?p=jonesforth.git;a=tree +- jonesforth nasm port: http://ratfactor.com/repos/nasmjf/ ## silly little plans |
