1 \ seedForth - seed it, feed it, grow it - i386 (32 bit) ITC flavour uho 2018-04-13
2 \ ----------------------------------------------------------------------------------
5 \ EAX, EDX general purpose
6 \ ESI instruction pointer
7 \ EBP return stack pointer
8 \ ESP data stack pointer
11 ;;; This is seedForth - a small, potentially interactive Forth, that dynamically
12 ;;; bootstraps from a minimal kernel.
14 ;;; cat seedForth.seed - | ./seedForth
16 ;;; .seed-files are in byte-tokenized source code format.
18 ;;; Use the seedForth tokenizer to convert human readable source code to byte-token form.
24 section '.bss' executable writable
32 _dp: DD _start ; dictionary pointer: points to next free location in memory
33 ; free memory starts at _start
35 _hp: DD 0 ; head pointer: points to first unused head
36 _head: DD 10000 dup (0)
39 section '.text' executable writable align 4096
59 ; make section writable
64 mov dword [esp+8], 7 ; rwx
67 mov dword [esp+4], eax
68 mov dword [esp], origin
78 ; call __error ; get error code on Mac OS
80 ; call __errno_location ; get error on Linux
91 _nest: lea ebp, [ebp-4]
96 _dodoes: ; ( -- addr ) \ call me
97 lea ebp, [ebp-4] ; push IP
99 pop esi ; set IP to caller
100 _dovar: ; ( -- addr )
101 lea eax,[eax+4] ; to parameter field
132 call fflush ; flush all output streams
154 code dup ( x -- x x )
161 code swap ( x y -- y x )
174 code 0< ( x -- flag )
193 code >r ( x -- ) ( R -- x )
200 code r> ( R x -- ) ( -- x )
207 code - ( x1 x2 -- x3 )
234 code c@ ( c-addr -- c )
249 code c! ( c c-addr -- )
256 code execute ( xt -- ) \ native code: >r :
261 code branch ( -- ) \ threaded code: r> @ >r ;
267 code ?branch ( f -- ) \ threaded code: ?exit r> @ >r ;
275 : negate ( n1 -- n2 )
282 0 swap ?exit drop -1 ;
284 : ?dup ( x -- x x | 0 )
291 swap >r dup @ r> + swap ! ;
300 lit hp @ h! 1 lit hp +! ;
309 here 1 cells allot ! ;
315 key h@ execute tail interpreter ;
318 key ?dup 0= ?exit h@ , tail compiler ;
321 here h, lit nest , compiler ;
325 here h, lit dovar , ;
328 232 c, here >r 0 , here - r> ! ; \ call near 32bit
331 r> lit hp @ 1 - h@ ! ; \ set code field of last defined word
339 's' emit 'e' dup emit emit 'd' emit 10 emit
351 lit unnest h, \ 11 0B
357 lit execute h, \ 17 11
358 lit branch h, \ 18 12
359 lit ?branch h, \ 19 13
360 lit negate h, \ 20 14
373 lit interpreter h, \ 33 21
374 lit compiler h, \ 34 22
375 lit create h, \ 35 23