Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge my work around CREATE...;CODE and CREATE...DOES> #8

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

andreiw
Copy link

@andreiw andreiw commented Oct 26, 2015

A little while ago I ended up implementing fairly normal-behavior ;CODE and DOES>. Initially I ported ;CODE from the original x86 Jonesforth, but it was useless with a CREATE and did not match Forth. There are a few other cleanups, which I hope you will find useful, like SEE and improvements around how machine words are defined.

I'm happy to say that contrary to Jonesforth documentation, DOES> really is possible 馃憤

annexia/jonesforth.s.txt uses LITSTRING, while jonesforth.s/f use LITS.

There's no real reason why this should be different from the original.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
The ARM Jonesforth is version 47, while the prelude
and x86 version under annexia were version 42.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
It's error-prone and doesn't quite help the readability, so
implicitly calculate the length within the macro.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
Now we can make machine code definitions in Forth. I've
decided to make all machine code emitters start with $
(such as $NEXT), although this may change in the future.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
putchar may buffer after all.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
Make ;CODE behave like the gforth variant, i.e. usable
inside a level 2 (word defining) word (i.e. after CREATE).

Before (see x86 jonesforth 47):

: FOO ;CODE

Now:

CODE FOO END-CODE

Or with CREATE:

: MKNOTHING WORD CREATE 0 , ;CODE END-CODE
MKNOTHING FOO

More examples... so now we could do something like:

defword "$DOCON",F_IMM,ASMDOCON
	.int LIT            @ r0 points to DFA
	ldr r12, [r0, #4]   @ read cell from DFA
	.int COMMA
	.int LIT
	PUSHDSP r12         @ push to stack
	.int COMMA
	.int EXIT

: MKCON
   WORD CREATE
   0 ,        ( push dummy codeword, rewritten by (;CODE))
   ,          ( actual constant )
;CODE
   $DOCON
END-CODE

5 MKCON CON5
CON5 . CR

CODE ... ENDCODE instead can be used to make `defcode'
definitions in Forth instead of jonesforth.s.

So now we could do something like:

@ push r0 to stack
defword "$<R0",F_IMM,ASMFROMR0
	.int LIT
	PUSHDSP r0
	.int COMMA
	.int EXIT

@ push r7 to stack
defword "$<R7",F_IMM,ASMFROMR7
	.int LIT
	PUSHDSP r7
	.int COMMA
	.int EXIT

@ pop stack to r0
defword "$>R0",F_IMM,ASMTOR0
	.int LIT
	POPDSP r0
	.int COMMA
	.int EXIT
@ pop stack to r7
defword "$>R7",F_IMM,ASMTOR7
	.int LIT
	POPDSP r7
	.int COMMA
 	.int EXIT

CODE SWAP $>R0 $>R7 $<R0 $<R7 END-CODE

HEX 1337 FOOF SWAP . . CR

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
DICT signature is changed.
   On success: ( -- dictionary_address )
   On failure ( -- word_addr word_len 0 )

Introduce DICT-CHECKED wrapper around DICT to log error about
unknown word and throws an ABORT.

Fix all words using DICT to instead use DICT-CHECKED.

As an unfortunate side effect, the exception handling code
had to travel upwards somewhat.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
[instead of segfaulting or printing nothing, of course]

Now:
   CODE FOO END-CODE
   SEE
...gives
   CODE FOO ( CODEWORD FOO+0 ) E49A0004 E5901000 E12FFF11 (END-CODE)

...where the hex stuff is the $NEXT macro.

CREATE ... ;CODE words:
   : MKNOTHING WORD CREATE 0 , 3 , ;CODE END-CODE
   MKNOTHING BAR
   SEE MKNOTHING
   SEE BAR
...gives
   : MKNOTHING WORD CREATE 0 , 3 , ;CODE ( MKNOTHING+9 ) E49A0004 E5901000 E12FFF11 (END-CODE)
   CODE BAR ( CODEWORD MKNOTHING+9 ) 3 (END-CODE)

...which shows you that BAR is a word created with MKNOTHING.

Native words:
   SEE 2SWAP
...gives
   CODE 2SWAP ( CODEWORD 85BC ) (END-CODE)

...since length isn't encoded defcode definitions, this is the best we can do.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
See my blog post for details.

http://osdevnotes.blogspot.com/2015/07/does-in-jonesforth.html

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
I really just want this to be a bunch of useful
stuff built around a generic jonesforth.s.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
Be more explicit about arch.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
This is still a wip. Some basic things seem to work, but a lot more
is to be done.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant