X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;ds=sidebyside;f=jonesforth.f;h=3641fa18f5a77708122aa43b0e2f899c4b68f149;hb=6a3c61c79594897f2328e0e3f85aeca093c200b7;hp=3a7612e2c6ab2b67da00f66d9d21182ba5d14d53;hpb=6c050b5e0db668e80d66b1bbb8e4c3d190bc28d2;p=rrq%2Fjonesforth.git diff --git a/jonesforth.f b/jonesforth.f index 3a7612e..3641fa1 100644 --- a/jonesforth.f +++ b/jonesforth.f @@ -2,7 +2,7 @@ \ A sometimes minimal FORTH compiler and tutorial for Linux / i386 systems. -*- asm -*- \ By Richard W.M. Jones http://annexia.org/forth \ This is PUBLIC DOMAIN (see public domain release statement below). -\ $Id: jonesforth.f,v 1.7 2007-09-28 18:55:10 rich Exp $ +\ $Id: jonesforth.f,v 1.9 2007-09-28 20:22:41 rich Exp $ \ \ The first part of this tutorial is in jonesforth.S. Get if from http://annexia.org/forth \ @@ -991,7 +991,8 @@ : SEE WORD FIND ( find the dictionary entry to decompile ) - ( now we search again, looking for the next word ) + ( Now we search again, looking for the next word in the dictionary. This gives us + the length of the word that we will be decompiling. (Well, mostly it does). ) HERE @ ( address of the end of the last compiled word ) LATEST @ ( word last curr ) BEGIN @@ -1013,7 +1014,6 @@ >DFA ( get the data address, ie. points after DOCOL | end-of-word start-of-data ) ( now we start decompiling until we hit the end of the word ) - ( XXX we should ignore the final codeword if it is EXIT ) BEGIN ( end start ) 2DUP > WHILE @@ -1021,40 +1021,50 @@ CASE ' LIT OF ( is it LIT ? ) - 4 + DUP @ ( get next word which is the integer constant ) - . ( and print it ) + 4 + DUP @ ( get next word which is the integer constant ) + . ( and print it ) ENDOF ' LITSTRING OF ( is it LITSTRING ? ) [ CHAR S ] LITERAL EMIT '"' EMIT SPACE ( print S" ) - 4 + DUP @ ( get the length word ) - SWAP 4 + SWAP ( end start+4 length ) - 2DUP TELL ( print the string ) - '"' EMIT SPACE ( finish the string with a final quote ) - + ALIGNED ( end start+4+len, aligned ) - 4 - ( because we're about to add 4 below ) + 4 + DUP @ ( get the length word ) + SWAP 4 + SWAP ( end start+4 length ) + 2DUP TELL ( print the string ) + '"' EMIT SPACE ( finish the string with a final quote ) + + ALIGNED ( end start+4+len, aligned ) + 4 - ( because we're about to add 4 below ) ENDOF ' 0BRANCH OF ( is it 0BRANCH ? ) ." 0BRANCH ( " - 4 + DUP @ ( print the offset ) + 4 + DUP @ ( print the offset ) . ')' EMIT SPACE ENDOF ' BRANCH OF ( is it BRANCH ? ) ." BRANCH ( " - 4 + DUP @ ( print the offset ) + 4 + DUP @ ( print the offset ) . ')' EMIT SPACE ENDOF ' ' OF ( is it ' (TICK) ? ) [ CHAR ' ] LITERAL EMIT SPACE - 4 + DUP @ ( get the next codeword ) - CFA> ( and force it to be printed as a dictionary entry ) + 4 + DUP @ ( get the next codeword ) + CFA> ( and force it to be printed as a dictionary entry ) ID. SPACE ENDOF - ( default case: ) - DUP ( in the default case we always need to DUP before using ) - CFA> ( look up the codeword to get the dictionary entry ) - ID. SPACE ( and print it ) + ' EXIT OF ( is it EXIT? ) + ( We expect the last word to be EXIT, and if it is then we don't print it + because EXIT is normally implied by ;. EXIT can also appear in the middle + of words, and then it needs to be printed. ) + 2DUP ( end start end start ) + 4 + ( end start end start+4 ) + <> IF ( end start | we're not at the end ) + ." EXIT " + THEN + ENDOF + ( default case: ) + DUP ( in the default case we always need to DUP before using ) + CFA> ( look up the codeword to get the dictionary entry ) + ID. SPACE ( and print it ) ENDCASE 4 + ( end start+4 )