Slightly tangential to your post, but I thought I would share it nevertheless. My system has DATA[ and ]DATA
Both are immediate words. They work like this:
: someWord data[ 9 5 6 3 5 9 ]data ;
The data is compiled inline within the colon definition. Executing the word causes the address of the beginning of the data, and the number of data items to be pushed to the stack. Very forthy. No need for RESTORE - just execute the word again to get the address and count.
I've found it very handy indeed over the years. I use it to define graphics characters. It's much more convenient than "comma-ing" (with C,) data into memory.
Mark
--
You received this message because you are subscribed to the Google Groups "FIGnition" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fignition+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Mark,
it's a nice idea, very forthy and would work on FIGnition too.
-cheers Julz
Nice. Have you seen the BASIC compiler Charles Moore wrote way back in (IIRC) 1981? It's written in FIG Forth in blocks. It allows BASIC code (with line numbers) to be written inside colon definitions. Infix notation with operator precedence is supported so one can write complex expressions with lots of parenthesis, as we're used to seeing in BASIC and other Infix languages!
A follow up article which includes the compiler is in one of the Forth Dimensions issues. I can dig it up if you're interested.
It's the perfect illustration of the power of the Forth language; that a BASIC compiler can be implemented in Forth, allowing Forth code and BASIC code to be freely mixed within an application.
Mark
Hi Mark,
Yes I think I have seen it in a scan of forth dimensions online.
Did his version still require separators between BASIC tokens (keywords/variables/separators)?
In my concept of figgybasic, there would be no line numbers & consequently no goto nor gosub. Instead it'd be a sort of BBC / ZX basic hybrid with defproc .. Endproc + deffn .. Endfn support, along with structured control flow and the main program at the end.
At the moment I'd probably implement it in (shock-horror) java so that I can integrate it with figgytape and also support syntax checking.
The output would be FIGnition forth as text.
I would need to deal with differences between BASIC semantics & forth (e.g. for .. Next with variable names vs do .. Loop with implicit loop variable names).
I think it's good to be able to switch to forth though:
BBC style *forth and *BASIC commands I think :-)
Cheers Julz
No GOTO required to implement state machines in my experience. Can you elaborate?
Mark
Hi Julian
AFAIR separators are still required, yes, because words such as LET (to assign something to a variable) are just immediate words in the dictionary that compile their own code when encountered in the colon definition. Consequently you can't say LET AREA=WIDTH*HEIGHT - you have to say LET AREA = WIDTH * HEIGHT
One benefit is that you can literally mix forth and basic side-by-side, as both pass through the inner interpreter. No need to explicitly switch from one mode to another. It's all forth, even the basic code ;-)
Gotta love Forth!
Mark
Hi David,
FIGnition forth suffers from a similar problem, since (branch) / (branch0) only have 8-bit displacements and you can't assign to IP because that won't affect the address counter & FIGnition would still end up executing the following token.
In FIGnition forth I can think of two ways to execute a jump. Firstly, by assigning to IP and then doing (branch) 0, causing a jump to IP .
Secondly, definitions that start:
: myExampleState0 r> drop ..... ;
Can be used to implement states. How would we do this in figgybasic? The answer is that Figgybasic will support vectored execution. It will be possible to have code like:
Deffn myExampleState()
*forth
r> drop
*basic
...
Return 1
EndFn
Rem initialize states
Dim gStates(5)
gState(0)=myExampleState
Rem Execute state
LET state=gState(state)()
Not quite as fast as in forth of course!
Cheers Julz
One clarification: figgybasic would adopt traditional BASIC notation for simple variable types: append % for 16-bit integers, %% for 32-bit integers; $ for string variables and nothing for floats.
It will be possible to take the address of a simple variable by preceding it with '@' (the result is a16-bit value). Constants can be preceded by '&' to denote hexadecimal.
The pervious example code could transform into:
: myExampleState r> drop 1 ;
5 arr gStates
0 var state
: run
myExampleState 0 gStates !
state @ gStates @ exec state !
;
There are some ambiguities i need to sort out in my figgybasic model particularly in differentiating between declarations and execution. E.g. BASIC can allocate runtime arrays, but that's not possible with the above model. One solution is to differentiate between compile-time and run time variables.
Cheers Julz