aforth

FORTH for Linux x86-64, written in assembly.
git clone git://henryandlizzy.uk/aforth
Log | Files | Refs | README

interpreter.s (1069B)


      1 #	Interpreter
      2 
      3 verb	forth	MODE
      4 	variable
      5 	endword
      6 
      7 verb	forth	INTERPRET
      8 	set	numin	0
      9 	3:	const	' '
     10 		do	WORD
     11 		do	DUP
     12 		do	fetch
     13 		if	0f
     14 			do	DROP
     15 			goto	2f
     16 	0:	do	FIND
     17 		if	1f
     18 			const	0
     19 			do	SWAP
     20 			do	DUP
     21 			const	8
     22 			do	plus
     23 			do	SWAP
     24 			do	fetch
     25 			do	CONVERT
     26 			do	drop2
     27 			test	greater	0	5f
     28 				do	HERE
     29 				escape	91
     30 				say	"Unknown token: "
     31 				do	PRINT
     32 				do	CR
     33 				do	ABORT
     34 		5:	get MODE
     35 			unless	2f
     36 				do	LITERAL
     37 				goto	2f
     38 		1:	do	DUP
     39 			do	fetch
     40 			const	0x8000000000000000
     41 			do	AND
     42 			do	iszero
     43 			get	MODE
     44 			do	AND
     45 			if	1f
     46 				do	EXECUTE
     47 				goto	2f
     48 		1:	do	comma
     49 	2:	get	numin
     50 		get	numtib
     51 		do	less
     52 		if	3b
     53 	escape	92
     54 	do	DEPTH
     55 	test	equal	0	4f
     56 	say	" ok "
     57 	test	equal	1	5f
     58 	do	DUP
     59 	do	dot
     60 5:	do	DROP
     61 	say	"["
     62 	do	DUP
     63 	do	dot
     64 	saycr	"]"
     65 	endword
     66 4:	do	DROP
     67 	saycr	" ok."
     68 	endword
     69 
     70 verb	forth	CONVERT
     71 2:	test	equal	0	1f
     72 	do	pushret
     73 	do	DUP
     74 	do	pushret
     75 	do	fetchb
     76 	const	'0'
     77 	do	minus
     78 	test	greater	9	0f
     79 		do	SWAP
     80 		const	10
     81 		do	mult
     82 		do	plus
     83 		do	popret
     84 		do	inc
     85 		do	popret
     86 		do	dec
     87 		goto	2b
     88 0:	do	DROP
     89 	do	popret
     90 	do	popret
     91 1:	endword