mitra42 / webForth

Forth for the web - implemented in JS and other web technologies
https://www.mitra.biz/forth/console.html
GNU Affero General Public License v3.0
27 stars 1 forks source link

CREATE> DOES and VOCABULARY #29

Closed mitra42 closed 3 years ago

mitra42 commented 4 years ago
mitra42 commented 3 years ago

References https://www.taygeta.com/forth/dpans6.htm#6.1.1250 DOES> https://www.taygeta.com/forth/dpansa6.htm#A.6.1.1250

mitra42 commented 3 years ago

This is hard lets take two (artifiically simple) examples.

: VARIABLE CREATE 1 CELLS ALLOT ;   VARIABLE foo
: CONSTANT CREATE , DOES> @ ; 10 CONSTANT ten

This isn't so hard if direct code is being used, a call to the "CREATE" routine is replaced with a call to the DOES> code, but with indirect or token threaded code the problem is where to specifiy where that code is.

I see two possibilities a: For each DOES> create a new function which encapsulates the address of the DOES in the function, store it in jsFunctions.

The con for this is that the number of jsFunctions grows with each defining word and that we have addresses of dictionary appearing in Javascript functions.

b: Have create always compile two cells, the first being a token for CREATE and second being the address (xt) of the definition. So the definition : VARIABLE CREATE 1 CELLS ALLOT becomes identical to : VARIABLE CREATE 1 CELLS ALLOT DOES> ;

I'm going to go with that 2nd definition even though it breaks with the eForth model, (which is strangely missing DOES>)

mitra42 commented 3 years ago

Above is working - still need to do Vocabulary