In article <20080324093652.72bf7e00.jethomas5@[EMAIL PROTECTED]
>,
Jonah Thomas <jethomas5@[EMAIL PROTECTED]
> wrote:
>Josh Grams <josh@[EMAIL PROTECTED]
> wrote:
>> Jonah Thomas <jethomas5@[EMAIL PROTECTED]
> wrote:
>
>> > I think we're on the same wavelength here but I've been fooled
>> > before sometimes when I thought that about others.
>>
>> Ditto. :)
>>
>> > Let's see. Compile-only. You compile each line and then either
>> > execute it and discard it, or you leave it added to the dictionary.
>>
>> I think you need to compile to a temporary buffer if you're going to
>> execute and discard it. e.g. what if the code adds stuff to the
>> dictionary?
>
>This is tricky, but maybe that would work out. If your literals etc put
>addresses and such on the stack, and then you act on them afterward,
>then by the time you add stuff to the dictionary you've already executed
>it. Say you had a string literal and you want to compile that. You move
>the string literal to the left, and everything it overwrites has already
>executed. You should be fine as long as you don't try to execute it
>again after it's clobbered. Tricky. There could be a gotcha I haven't
>thought of.
I use a far PAD, halfway between HERE and the stack, as a temporary
compile buffer. This pad is half a gigabyte away with the -g 1024M
option, but it remains tricky.
The switch code takes two half screens. All interpreted control
words together takes another screen.
This is also used to temporarily build data structures for
classes to find field offsets, for having a discardable assembler
etc.
I might as well show the code:
80386 ciforth beta $RCSfile: ci86.gnr,v $ $Revision: 5.34 $
108 TRIAD
SCR # 108
0 ( FAR-DP SWAP-DP scratch_dictionary_area ) \ AvdH A1oct21
1 VARIABLE FAR-DP \ Alternative DP
2 DSP@[EMAIL PROTECTED]
1 RSHIFT HERE 1 RSHIFT + ALIGNED FAR-DP !
3 \ Use alternative dictionary area or back.
4 : SWAP-DP DP @[EMAIL PROTECTED]
FAR-DP @[EMAIL PROTECTED]
DP ! FAR-DP ! ;
5 \ Remove all words from the scratch area.
6 : TRIM HERE 'FORGET-VOC FOR-VOCS DROP ;
7
8
9
10
11
12
13
14
15
SCR # 109
0 ( T] T[ ) \ AvdH A1oct04
1 WANT SWAP-DP
2
3 \ Compile at temporary place : remember old HERE and STATE.
4 : T] STATE @[EMAIL PROTECTED]
0= IF SWAP-DP HERE THEN STATE @[EMAIL PROTECTED]
] ;
5
6 \ Execute code at old HERE , restore STATE and dictionary.
7 : T[ 0= IF POSTPONE (;) SWAP-DP POSTPONE [ >R THEN ; IMMEDIATE
8
9
10
11
12
13
14
15
SCR # 110
0 ( NEW-IF interpreting__control_words ) \ AvdH A1oct04
1 : NEW-IF ;
2 WANT T[
3 : IF T] POSTPONE IF ; IMMEDIATE
4 : DO T] POSTPONE DO ; IMMEDIATE
5 : ?DO T] POSTPONE ?DO ; IMMEDIATE
6 : BEGIN T] POSTPONE BEGIN ; IMMEDIATE
7 : THEN POSTPONE THEN POSTPONE T[ ; IMMEDIATE
8 : LOOP POSTPONE LOOP POSTPONE T[ ; IMMEDIATE
9 : +LOOP POSTPONE +LOOP POSTPONE T[ ; IMMEDIATE
10 : REPEAT POSTPONE REPEAT POSTPONE T[ ; IMMEDIATE
11 : UNTIL POSTPONE UNTIL POSTPONE T[ ; IMMEDIATE
12
13
14
15
OK
Note that I have carefully designed the Forth internals to
be extendable. Using STATE doesn't weight on my conscience.
The return stack is usable. etc.
Groetjes Albert
--
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
albert@[EMAIL PROTECTED]
&=n http://home.hccnet.nl/a.w.m.van.der.horst


|