Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Here's a native FORTH for MacOS X

Here's a native FORTH for MacOS X
Thread Tools
Mac Enthusiast
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jan 3, 2002, 01:23 PM
 
I've been writing a FORTH-compiler called D. FORTH is a stack-based, interactively compiling language.

I'd be glad if you would have a look at it and tell me what you think.

D is a work in progress, if I get enough feedback I'll continue to document it.

Thank you,
Daniel
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Sacramento, CA, US
Status: Offline
Reply With Quote
Jan 3, 2002, 09:01 PM
 
I love (and miss) Forth...this looks like fun. Guess that makes me a geek! Thanks.

Mark
TiBook 667MHz/512Mb/30Gb/DVD
Macs for work and play; Windows for...work and play. Oh. Never mind. Whatever.
     
Mac Enthusiast
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jan 4, 2002, 05:42 PM
 
mrtaber, how do you came to FORTH? Could you tell about your experience with FORTH? I'm interested because most people never heard about FORTH -- to bad.
     
Mac Enthusiast
Join Date: Sep 2000
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jan 4, 2002, 06:02 PM
 
Originally posted by danengel:
<STRONG>I've been writing a FORTH-compiler called D. FORTH is a stack-based, interactively compiling language.

I'd be glad if you would have a look at it and tell me what you think.

D is a work in progress, if I get enough feedback I'll continue to document it.

Thank you,
Daniel</STRONG>
I actually was just playing with it last night, it seems work quite nicely.

I wanted to add a primitive (roll) that is part of the IEEE1275 spec, but not ANSI forth. I implemented what I thought was correct on kernel.s, but I think I might have malformed the function header. I assume the first entry is a chain to other primtive words, and the scf (? I don't have the source near me) refers to the cache states. Roll moves a lot of the stack, so for the time being I had planed on just implementing the assembly to deal with the actual stack, and not the cache values. I assume I would use scf00 and the first function subroutine pointer, is that correct? I could probably also use scf10 since the first value is destroyed (the stack count drops by one), but the semantics are implicit and I did not really feel like digging through the dispatch code when I was doing this at 3 AM ;-)

Louis

Louis
Louis Gerbarg
Darwin Developer
These are my views, and not the views of my employer.
     
Mac Enthusiast
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jan 5, 2002, 04:59 AM
 
Igerbarg,

The header would look like this (freehand composition, not tested):
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
.data
roll_l: .long &lt;word before roll&gt;_l
.byte explained | leaf, <font color = blue>0</font>, <font color = blue>0</font>, scf10
.long <font color = blue>0</font>, roll_1, <font color = blue>0</font>, <font color = blue>0</font>
.asciz <font color = red>"roll"</font>
.align <font color = blue>2</font>
.asciz <font color = red>"( xu xu-<font color = blue>1</font> ... x0 u -- xu-<font color = blue>1</font> ... x0 xu )"</font>
.align <font color = blue>2</font>

.text
roll_1: ; code starts here
; ...
blr
</font>[/code]

It's a good idea not to include the cache because that would be horribly complicated.

I didn't include 'roll' in the first place because 1) it looked shuffles a lot of memory cells around and 2) I have no use for it. Can you tell me where it's necessary? Anyway, it's a good exercise to implement it

-- Daniel
     
Mac Enthusiast
Join Date: Sep 2000
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jan 5, 2002, 06:31 AM
 
Originally posted by danengel:
<STRONG>Igerbarg,

The header would look like this (freehand composition, not tested):
&lt;BLOCKQUOTE&gt;&lt;font size="1"face="Geneva, Verdana, Arial"&gt;code:&lt;/font&gt;&lt;HR&gt;&lt;pre&gt;& amp;lt;font size=1 face=courier&gt;
.data
roll_l: .long &lt;word before roll&gt;_l
.byte explained | leaf, &lt;font color = blue&gt;0&lt;/font&gt;, &lt;font color = blue&gt;0&lt;/font&gt;, scf10
.long &lt;font color = blue&gt;0&lt;/font&gt;, roll_1, &lt;font color = blue&gt;0&lt;/font&gt;, &lt;font color = blue&gt;0&lt;/font&gt;
.asciz &lt;font color = red&gt;"roll"&lt;/font&gt;
.align &lt;font color = blue&gt;2&lt;/font&gt;
.asciz &lt;font color = red&gt;"( xu xu-&lt;font color = blue&gt;1&lt;/font&gt; ... x0 u -- xu-&lt;font color = blue&gt;1&lt;/font&gt; ... x0 xu )"&lt;/font&gt;
.align &lt;font color = blue&gt;2&lt;/font&gt;

.text
roll_1: ; code starts here
; ...
blr
&lt;/font&gt;&lt;/pre&gt;&lt;HR&gt;&lt;/BLOCKQUOTE&gt;

It's a good idea not to include the cache because that would be horribly complicated.

I didn't include 'roll' in the first place because 1) it looked shuffles a lot of memory cells around and 2) I have no use for it. Can you tell me where it's necessary? Anyway, it's a good exercise to implement it

-- Daniel</STRONG>
Yeah, the cached versions are hideous, since you have to in essence special case for whether or not the are of affect is entirely within the cache or not. You can probably implement it through a small common subroutine you share amoune all version that basicly does the noncached version on a given range of the stack, and then have the cached version call that once they pass outside their area of effect (with a special case subroutine for when the roll is entirely cached, you can actually have it jump into swap and rot's code with some slight refactoring, but it is almost certainly not worth it).

I actually have what I think is a complete implementation, there was an error with my header based on what you did. I'll take a look at it when I am back at my machine.

As to why one would want it... well you can make the argument that it is the only convenient stack mangling function thats range of effect is more than 6 or so away from top, and even at 6 their effectiveness is significantly impaired. I don't really buy into that two much though, because in practice I have never needed for those reasons.

The reason I want it is that I have some code that uses it.. It almost certainly simpler to implement the word than to refactor the code.

Louis
Louis Gerbarg
Darwin Developer
These are my views, and not the views of my employer.
     
Mac Enthusiast
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jan 7, 2002, 01:47 AM
 
Louis,

I'd like to see your version of 'roll'. Although I don't think it's a frequently used word, building it into D doesn't hurt.

-- Daniel
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:28 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2