How to determine VALUE and TO

I want to implement the words Forth VALUE and TO on RPC / 8 (emulated computer in Minecraft mod ). My best attempts give me a bunch of words that work great until I use them at compile time. More specifically, VALUE works, but TO does not work.

 : VALUE CREATE , DOES> @ ; : TO ' 3 + ! ; 

I tried everything I could think of to make it work, and my best attempt allows me this:

 ['] NameOfAValue + 3 ! 

Please note that the processor is not a clean 6502, but 65EL02 , a custom version of 65816 .

EDIT # 1: Somehow I forgot to call CREATE in the value. It should have been all the time. EDIT # 2: I also got 3 and + included in TO ... oops. Everything had to be different.

+8
forth 6502
source share
3 answers

Ok After a lot of trial and error, as well as a lot of searching, I found something that should work, but due to two errors in redFORTH does not work.

VALUE

 \ Works fine, now to reset the value. : VALUE \ n <name> -- CREATE , DOES> @ ; 

TO

 \ Works if not compiling, LITERAL and POSTPONE are broken. : TO TIBWORD FIND 3 + STATE @ IF POSTPONE LITERAL POSTPONE ! ELSE ! THEN ; IMMEDIATE 

Demonstration of an error in LITERAL

 \ fails, very wierd error. : TESTLIT [ 42 ] LITERAL ; \ TESTLIT Unknown Token: TESTLIT \ FORGET TESTLIT Unknown Token: TESTLIT \ WORDS TESTLIT COLD SORTMATCH ... 

POSTPONE error demonstration

 \ fails, postpone is directly equivelent to ['] : TESTPOST POSTPONE + ; IMMEDIATE : TEST 2 2 TESTPOST . ; \ . 1935 \ ' + . 1935 

I want to write an error report ....

EDIT # 1: After some trial and error and a lot of swearing (I'm not very good with FORTH), I found a way to make it work.

 : TO TIBWORD FIND 3 + STATE @ IF (lit) (lit) , , \ store address (lit) ! , ELSE ! THEN ; IMMEDIATE 
+2
source share

I'm not sure how your Forth handles the interpretation compared to compilation time, but the TO definition is trying to save the value for address 3. It seems suspicious.

0
source share

The simplest solution is

 VARIABLE TO-MESSAGE \ 0 : FROM , 1 : TO . : TO 1 TO-MESSAGE ! ; : VALUE CREATE , DOES> TO-MESSAGE @ IF ! ELSE @ THEN 0 TO_MESSAGE ! ; 
0
source share

All Articles