diff --git a/asm.jrt b/asm.jrt index b0f5b1f..229e564 100755 --- a/asm.jrt +++ b/asm.jrt @@ -56,7 +56,6 @@ array oparg2 3 cells allot target @ >r encode-op short-jmp* ; 1 :op JCXZ 0xe3 >short-jmp* ; 1 :op JMP - dbg" JMP!" 0xe9 >near-reljmp* 0xeb >short-jmp* 0xea >far-jmp* diff --git a/build.bat b/build.bat index 1e0a872..e9fa757 100755 --- a/build.bat +++ b/build.bat @@ -1,2 +1,2 @@ -minijort < tinyjort.jrt +jort.com < tinyjort.jrt copy tinyjort.com jort.com diff --git a/debug.jrt b/debug.jrt deleted file mode 100755 index b3000f2..0000000 --- a/debug.jrt +++ /dev/null @@ -1,3 +0,0 @@ -s" defs.jrt" loadfile -dbg" debugging!" - diff --git a/jort.com b/jort.com index 5075528..8d5ea91 100755 Binary files a/jort.com and b/jort.com differ diff --git a/tinyjort.com b/tinyjort.com index 5075528..8d5ea91 100755 Binary files a/tinyjort.com and b/tinyjort.com differ diff --git a/tinyjort.jrt b/tinyjort.jrt index e2933f4..d0cad17 100755 --- a/tinyjort.jrt +++ b/tinyjort.jrt @@ -14,8 +14,8 @@ dbg" assembling..." increment the instruction pointer. ) -JMP dbg" JMP" 9 @> -dbg" first jmp" +JMP 9 @> + : NEXT LODSW MOV BX AX @@ -42,7 +42,7 @@ L: LATEST 0 w>t 0x0f const BUCKETMASK : savelabel ( word -- ) - dup type s" : " type + ( dup type s" : " type ) here swap begin dup b@ dup while b, 1+ repeat b, drop lastlabel ! ; : DICTLIST ( word -- tptr ) b@ BUCKETMASK & cells [ L@ DICTIONARY lit ] + ; : strlen ( word -- len ) 0 swap begin dup b@ while swap 1+ swap 1+ repeat drop ; @@ -52,7 +52,7 @@ L: LATEST 0 w>t : link>t ( tptr-head -- ) dup @t swap patch!t w>t ; : DEF target @ [ L@ LATEST lit ] !t word dup savelabel dup DICTLIST link>t dup strlen w>t str>t - target @ cell + .hex cr ; + ( target @ cell + .hex cr ) ; : WORD= ( word len tptr -- f ) cell + dup b@t t t' w>t ; @@ -523,10 +526,9 @@ dbg" i/o" -1 CONST EOF 0 VAR, fbuffer -: skip>t 1+ cells target @ + w>t ; :t fgetc ( fp -- c ) 1 fbuffer t ] drop EOF ; + fcount @ not BZ_ [ patchpt ] drop EOF [ patch!t ] ; :t fputc ( c fp -- ) swap fbuffer b! 1 fbuffer t ] return drop + buf-key dup BZ_ [ patchpt ] return [ patch!t ] drop ( if buffer is empty, refresh from file ) INBUFSIZE inbuf 0 fread ( if there's any more data, start returning it ) @@ -728,7 +730,7 @@ L: write-next-digit 0 [ target @ ] drop key dup whitespace? not BZ_ [ w>t ] ( consume non-whitespace / eoi characters ) [ target @ ] dup whitespace? over eoi? or - ( if whitespace or eoi, end ) BZ_ [ 5 skip>t ] drop 0 b, return + ( if whitespace or eoi, end ) BZ_ [ patchpt ] drop 0 b, return [ patch!t ] ( otherwise, write byte and continue ) b, key GOTO_ [ w>t ] ; ARRAY wordbuf 48 ALLOT :t redir-, ( cp buf -- buf ) here >r dup >r here! execute t ] - 2inc GOTO_ [ w>t ] drop ; + 0 swap [ target @ ] dup b@ BZ_ [ patchpt ] + 2inc GOTO_ [ swap w>t patch!t ] drop ; :ASM dict-lookup ( name dict -- cp meta | name 0 ) MOV AX DS @@ -828,13 +830,31 @@ L: check-next-entry :t ?err ( word -- ) type LIT_ [ key ? w>t ] emit cr ; DEFERRED err ?err +:ASM sp+ss + PUSH SP + PUSH SS + NEXT + +:ASM underflow? + CMP SP 0x100 # + JLE 0 @> + MOV SP 0x100 # + PUSH TRUE + NEXT +0 <: + PUSH FALSE + NEXT + +:t checkstack underflow? BZ_ [ patchpt ] + INLINEDATA_ [ patchpt t" underflow!" patch!t ] type cr [ patch!t ] ; :t compileword ( word -- ) lookup dup BZ_ [ patchpt ] interpretword return [ patch!t ] drop number BZ_ [ patchpt ] interpretnumber return [ patch!t ] err ; :t interpreter - [ target @ ] word dup b@ BZ_ [ patchpt ] compileword GOTO_ [ swap w>t ] - [ patch!t ] drop ; + [ target @ ] noop ( f28 ) word noop ( f2c ) dup b@ BZ_ + [ patchpt ] noop ( f36 ) compileword checkstack + GOTO_ [ swap w>t patch!t ] noop ( f40 ) drop ; dbg" flow control words and misc." :t if LIT_ BZ_ , here 0 , ; IMMEDIATE @@ -857,7 +877,7 @@ dbg" flow control words and misc." :t |; LIT_ return , |inline ; IMMEDIATE :t s", [ target @ ] key dup LIT_ [ key " w>t ] != over 0 != and - BZ_ [ 3 skip>t ] b, GOTO_ [ w>t ] + BZ_ [ patchpt ] b, GOTO_ [ swap w>t patch!t ] drop 0 b, ; :t s" state BZ_ [ patchpt ] inline| s", |inline return [ patch!t ] LIT_ s", tmp-, ; IMMEDIATE @@ -871,22 +891,15 @@ dbg" flow control words and misc." r 0x100 [ target @ ] 2 - dup r@ < BZ_ - ( past top of stack ) [ 4 skip>t ] drop drop rdrop return + ( past top of stack ) [ patchpt ] drop drop rdrop return [ patch!t ] 2dup swap @far . GOTO_ [ w>t ] ; dbg" boot stub" -:ASM debug NEXT :t tinyjort interpreter terminate ; 9 <: ( actual entry point )