Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #42032 > unrolled thread
| Started by | AndrewHolt <andrewtholt60@gmail.com> |
|---|---|
| First post | 2015-09-16 03:44 -0700 |
| Last post | 2015-09-17 19:48 -0700 |
| Articles | 8 — 6 participants |
Back to article view | Back to comp.lang.forth
C structures into forth AndrewHolt <andrewtholt60@gmail.com> - 2015-09-16 03:44 -0700
Re: C structures into forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-09-16 11:38 +0000
Re: C structures into forth Lars Brinkhoff <lars.spam@nocrew.org> - 2015-09-16 14:14 +0200
Re: C structures into forth hughaguilar96@gmail.com - 2015-09-16 12:45 -0700
Re: C structures into forth "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-17 07:09 -0400
Re: C structures into forth JUERGEN <epldfpga@aol.com> - 2015-09-17 07:37 -0700
Re: C structures into forth hughaguilar96@gmail.com - 2015-09-17 15:10 -0700
Re: C structures into forth hughaguilar96@gmail.com - 2015-09-17 19:48 -0700
| From | AndrewHolt <andrewtholt60@gmail.com> |
|---|---|
| Date | 2015-09-16 03:44 -0700 |
| Subject | C structures into forth |
| Message-ID | <aa37442f-9279-4699-a671-c70b2f667ce2@googlegroups.com> |
Hi All, Simple question :) Anybody know of a tool to take a C structure and convert it into Forth. I've fiddled around with a, very, basic and limited script but I was wondering if there was something more robust out there. TIA, Andrew
[toc] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2015-09-16 11:38 +0000 |
| Message-ID | <2015Sep16.133817@mips.complang.tuwien.ac.at> |
| In reply to | #42032 |
AndrewHolt <andrewtholt60@gmail.com> writes:
>Hi All,
>
>Simple question :)
>
>Anybody know of a tool to take a C structure and convert it into Forth.
>
>I've fiddled around with a, very, basic and limited script but I was wondering if there was something more robust out there.
Gerald Wodni has extended SWIG to produce Forth source code, but I do
not find a link to this tool at the moment.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2015: http://www.rigwit.co.uk/EuroForth2015/
[toc] | [prev] | [next] | [standalone]
| From | Lars Brinkhoff <lars.spam@nocrew.org> |
|---|---|
| Date | 2015-09-16 14:14 +0200 |
| Message-ID | <86zj0msgrx.fsf@vps34351.public.cloudvps.com> |
| In reply to | #42033 |
Anton Ertl wrote: > Gerald Wodni has extended SWIG to produce Forth source code, but I do > not find a link to this tool at the moment. Probably here? https://github.com/GeraldWodni/swig
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2015-09-16 12:45 -0700 |
| Message-ID | <d7f083b1-4e86-4b56-87f4-2097ce4a3701@googlegroups.com> |
| In reply to | #42032 |
On Wednesday, September 16, 2015 at 3:44:44 AM UTC-7, AndrewHolt wrote:
> Hi All,
>
> Simple question :)
>
> Anybody know of a tool to take a C structure and convert it into Forth.
>
> I've fiddled around with a, very, basic and limited script but I was wondering if there was something more robust out there.
>
> TIA,
> Andrew
C structs are quite limited in that they don't allow for inheritance --- converting C directly into Forth will result in C's weaknesses being carried over to Forth, making Forth appear to be worse than it is.
Here is a an example from my novice-package of the SEQ data-type inheriting from the LIST data-type:
list
w field .line
constant seq
: init-seq ( str node -- node )
init-list >r
hstr r@ .line !
r> ;
: new-seq ( str -- node )
seq alloc
init-seq ;
: <kill-seq> ( node -- )
dup .line @ dealloc
dealloc ;
: kill-seq ( head -- )
each[ <kill-seq> ]each ;
: <clone-seq> ( node -- new-node )
clone-node
dup .line @ hstr over .line ! ;
: clone-seq ( head -- new-head )
nil
swap each[ <clone-seq> link ]each ;
[toc] | [prev] | [next] | [standalone]
| From | "Rod Pemberton" <boo@fasdfrewar.cdm> |
|---|---|
| Date | 2015-09-17 07:09 -0400 |
| Message-ID | <op.x43tajgcyfako5@localhost> |
| In reply to | #42032 |
On Wed, 16 Sep 2015 06:44:41 -0400, AndrewHolt <andrewtholt60@gmail.com> wrote: > Simple question :) Is that foreshadowing of a problems ahead? ;-) > Anybody know of a tool to take a C structure > and convert it into Forth. > > I've fiddled around with a, very, basic and > limited script but I was wondering if there > was something more robust out there. MPE claims to have "C to Forth compiler" (bottom) http://www.mpeforth.com/arena.htm Rob Chapman, know for Forth-to-C translation via Timbre and C-without-C projects, also has a "C Parser" in Forth and "C-Inside rules" which allows C code to execute with Forth kernel: http://clubweb.interbaun.com/~rc/Timbre/ContentPages/frameworks.html Rod Pemberton -- Just how many texting and calendar apps does humanity need?
[toc] | [prev] | [next] | [standalone]
| From | JUERGEN <epldfpga@aol.com> |
|---|---|
| Date | 2015-09-17 07:37 -0700 |
| Message-ID | <58a6b428-7073-4520-aeca-54671811ae5c@googlegroups.com> |
| In reply to | #42058 |
On Thursday, September 17, 2015 at 12:09:39 PM UTC+1, Rod Pemberton wrote: > On Wed, 16 Sep 2015 06:44:41 -0400, AndrewHolt <andrewtholt60@gmail.com> wrote: > > > Simple question :) > > Is that foreshadowing of a problems ahead? ;-) > > > Anybody know of a tool to take a C structure > > and convert it into Forth. > > > > I've fiddled around with a, very, basic and > > limited script but I was wondering if there > > was something more robust out there. > > MPE claims to have "C to Forth compiler" (bottom) > http://www.mpeforth.com/arena.htm > > Rob Chapman, know for Forth-to-C translation via > Timbre and C-without-C projects, also has a "C Parser" > in Forth and "C-Inside rules" which allows C code to > execute with Forth kernel: > http://clubweb.interbaun.com/~rc/Timbre/ContentPages/frameworks.html > > > Rod Pemberton > > > -- > Just how many texting and calendar apps does humanity need? MPE does NOT claim this - please quote correctly, you might have missed the Reasearch Project part: C to Forth Compiler: This is a complete C to Forth compiler with sources. It is an MPE research project which we believe will grow better as a Forth community project. The project is dual-licensed. Non-commercial use is free of charge. For commercial use you must buy a commercial license. V1.20 has been tested on Windows XP and Windows 7/64. The documentation has been overhauled. Sample build scripts for Windows are provided.
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2015-09-17 15:10 -0700 |
| Message-ID | <b6a75621-25bc-414e-9a01-eafefc983310@googlegroups.com> |
| In reply to | #42060 |
On Thursday, September 17, 2015 at 7:37:50 AM UTC-7, JUERGEN wrote:
> C to Forth Compiler: This is a complete C to Forth compiler with sources. It is an MPE research project which we believe will grow better as a Forth community project. The project is dual-licensed. Non-commercial use is free of charge. For commercial use you must buy a commercial license.
>
> V1.20 has been tested on Windows XP and Windows 7/64. The documentation has been overhauled. Sample build scripts for Windows are provided.
MPE is wasting their time with this misguided effort.
I would expect anybody armed with my novice package to be able to rewrite any C program to be more readable and more robust --- by comparison, a line-by-line translation of C into Forth is going to result in some awful ugly code --- then the C enthusiasts will say: "Forth is so ugly! We should have stuck with C! Twisting all the code to be rpn didn't improve readability at all!"
The following is an excerpt from this file (http://www.forth.org/FMITE.txt):
The manual for ISYS Forth (for the Apple-IIc) gave us this example of good Forth style:
: par \ r1 r2 -- r \ calculate parallel resistance of two resistors
ddup + */ ;
: par3 \ r1 r2 r3 -- r \ calculate parallel resistance of three resistors
par par ;
The high-functioning C'diot may avoid stack-juggling (the DDUP in PAR above) like this:
: par local{ r1 r2 -- r } \ calculate parallel resistance of two resistors
r1 @ r2 @
r1 @ r2 @ + */ ;
: par3 local{ r1 r2 r3 -- r } \ calculate parallel resistance of three resistors
r1 @ r2 @ par
r3 @ par ;
The low-functioning C'diot will do even worse. For one thing, he may fail to understand */ because he can't translate it into C code --- so he will use * and / instead, resulting in an overflow bug. Or, he may fail to understand */ but will understand that overflow is an issue --- so he will use D* and D/ instead, resulting in abysmally slow code. Also, he may fail to understand that one of the purposes of factoring is so that sub-functions can be reused (PAR was reused in PAR3) because factoring is not considered to be a virtue in the C world. A collision of not understanding */ and not understanding reusability, would result in this:
: par local{ r1 r2 r3 -- r }
\ calculate parallel resistance of two resistors (WARNING: overflow is possible!)
r1 @ r2 @ *
r1 @ r2 @ + / ;
: par3 local{ r1 r2 r3 | t1 -- r }
\ calculate parallel resistance of three resistors (WARNING: overflow is possible!)
r1 @ r2 @ *
r1 @ r2 @ + / t1 !
t1 @ r3 @ *
t1 @ r3 @ + / ;
The Stundurd code above appears to have been written in C first, and then translated line-by-line into Stundurd; it is pretty much just an rpn-version of C. It is typical for C'diots to have a function such as PAR3 that obviously contains cut-and-paste code from another function (the PAR function just above it). It is also typical for C'diots to comment their bugs (as done above, with the comments warning that overflow is possible). Of course, the true C'diot would put a comment on every line in a vain effort at improving readability --- and then criticize the good-style version of PAR and PAR3 for not being adequately commented!
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2015-09-17 19:48 -0700 |
| Message-ID | <7936ce8a-0135-40e7-9db8-d709021e4491@googlegroups.com> |
| In reply to | #42065 |
On Thursday, September 17, 2015 at 3:10:31 PM UTC-7, hughag...@gmail.com wrote: > The following is an excerpt from this file (http://www.forth.org/FMITE.txt): > ... > The Stundurd code above... This is actually an excerpt from the STUNDURD.TXT file which is the upgrade to FMITE.TXT with a name change. This is the description: ------------------------------------------------------------------------------ The Stundurd Forth processor is an updated version of the obsoleted FMITE processor. It has better support for higher-order functions, as they can now be written in Forth rather than assembly-language. Efficiency has also been improved for locals, I/O access, comparisons, iteration, and double-precision arithmetic. There is now 32KB of RAM and 32KB of non-volatile memory. There is support for a multi-core implementation now as we have a primitive to exchange data that can be used for semaphores as it locks out common-memory (it can also be used for sorting arrays). None of this is Standard Forth, of course --- it is Stundurd Forth! ------------------------------------------------------------------------------ This isn't on http://www.forth.org/literature.html page yet. I don't know yet if it will be accepted --- FMITE.TXT might get pulled also --- everybody hates this stuff and asks for it to be removed.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web