Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > Re: Is interpre...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 20 of 21 Topic 3960 of 4053
Post > Topic >>

Re: Is interpret/compile the wrong distinction?

by Albert van der Horst <albert@[EMAIL PROTECTED] > Mar 24, 2008 at 03:40 PM

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




 21 Posts in Topic:
Is interpret/compile the wrong distinction?
Josh Grams <josh@[EMAI  2008-03-23 14:50:35 
Re: Is interpret/compile the wrong distinction?
Elizabeth D Rather <er  2008-03-23 15:06:31 
Re: Is interpret/compile the wrong distinction?
Bruce McFarling <agila  2008-03-23 14:09:50 
Re: Is interpret/compile the wrong distinction?
Jonah Thomas <jethomas  2008-03-23 19:23:48 
Re: Is interpret/compile the wrong distinction?
pablo reda <pabloreda@  2008-03-23 16:50:53 
Re: Is interpret/compile the wrong distinction?
Albert van der Horst <  2008-03-24 03:20:31 
Re: Is interpret/compile the wrong distinction?
John Doty <jpd@[EMAIL   2008-03-23 22:18:20 
Re: Is interpret/compile the wrong distinction?
Albert van der Horst <  2008-03-24 15:07:47 
Re: Is interpret/compile the wrong distinction?
John Doty <jpd@[EMAIL   2008-03-24 12:36:00 
Re: Is interpret/compile the wrong distinction?
Josh Grams <josh@[EMAI  2008-03-24 01:11:03 
Re: Is interpret/compile the wrong distinction?
Bruce McFarling <agila  2008-03-23 19:34:40 
Re: Is interpret/compile the wrong distinction?
John Doty <jpd@[EMAIL   2008-03-23 22:48:04 
Re: Is interpret/compile the wrong distinction?
Bruce McFarling <agila  2008-03-24 00:06:20 
Re: Is interpret/compile the wrong distinction?
Bruce McFarling <agila  2008-03-24 08:21:38 
Re: Is interpret/compile the wrong distinction?
Bruce McFarling <agila  2008-03-24 09:21:32 
Re: Is interpret/compile the wrong distinction?
Jonah Thomas <jethomas  2008-03-23 20:08:31 
Re: Is interpret/compile the wrong distinction?
Jonah Thomas <jethomas  2008-03-23 22:16:20 
Re: Is interpret/compile the wrong distinction?
Josh Grams <josh@[EMAI  2008-03-24 13:00:48 
Re: Is interpret/compile the wrong distinction?
Jonah Thomas <jethomas  2008-03-24 09:36:52 
Re: Is interpret/compile the wrong distinction?
Albert van der Horst <  2008-03-24 15:40:20 
Re: Is interpret/compile the wrong distinction?
anton@[EMAIL PROTECTED]   2008-03-24 13:41:05 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 7:26:19 CDT 2008.