digitalmars.D - D for projects similar to Forth Interpreters?
- JohnZ <nospam myip.tks> Feb 28 2009
- "Tim M" <a b.com> Feb 28 2009
- Daniel Keep <daniel.keep.lists gmail.com> Feb 28 2009
- bearophile <bearophileHUGS lycos.com> Feb 28 2009
- Jarrett Billingsley <jarrett.billingsley gmail.com> Feb 28 2009
- JohnZ <not here.net> Mar 01 2009
- JohnZ <not here.net> Mar 01 2009
- johnZ <not here.net> Mar 01 2009
- Walter Bright <newshound1 digitalmars.com> Feb 28 2009
- JohnZ <not here.net> Mar 01 2009
In this case what would be the pros and cons if any of D compared with C or asm?
Feb 28 2009
On Sat, 28 Feb 2009 22:53:25 +1300, JohnZ <nospam myip.tks> wrote:In this case what would be the pros and cons if any of D compared with C or asm?
C probably optimizes well based on its age. Asm will make some routines a few microseconds faster. But D will ensure whole project not be delayed by a few years. Profile the d for the slow spots, optimize those and maybe include inline asm there. Have the ability to link to existing c (and some C++) libraries if needed. Profit :) D is well suited to interpreters. PS: any thing unique about forth interpreters compared to other interpreted languages?
Feb 28 2009
Tim M wrote:PS: any thing unique about forth interpreters compared to other interpreted languages?
Forth (actually, postfix languages in general) are awesome fun, and they're incredibly simple to play with. I made a simple Forth-like language interpreter in Python to play around with the idea of a postscript-style language for cairo rendering. I managed to get it to the point where if and subroutines were implemented as functions, which I thought was just hilarious. :D -- Daniel P.S. Here's an old fib subroutine I made in it. Anything in ( parens ) is a comment. ( Defines a fib word that computes the nth Fibonacci number. ) `fib ( n -- n' ) : dup 1 <= not if-then 1- dup fib swap 1- fib + end-if .
Feb 28 2009
JohnZ Wrote:In this case what would be the pros and cons if any of D compared with C or asm?<
If you use C with GCC you can use the computed goto, that is really useful to speed up an interpreter like a Forth one. D misses still such feature because it was thought as not useful enough. Bye, bearophile
Feb 28 2009
On Sat, Feb 28, 2009 at 6:10 AM, bearophile <bearophileHUGS lycos.com> wrote:JohnZ Wrote:In this case what would be the pros and cons if any of D compared with C or asm?<
If you use C with GCC you can use the computed goto, that is really useful to speed up an interpreter like a Forth one. D misses still such feature because it was thought as not useful enough.
D turns many switch statements into computed gotos. It's a compiler optimization.
Feb 28 2009
== Quote from Jarrett Billingsley (jarrett.billingsley gmail.com)'s articleOn Sat, Feb 28, 2009 at 6:10 AM, bearophile
JohnZ Wrote:In this case what would be the pros and cons if any of D compared
If you use C with GCC you can use the computed goto, that is
still such feature because it was thought as not useful enough.D turns many switch statements into computed gotos. It's a compiler optimization.
ah that might be useful..
Mar 01 2009
== Quote from bearophile (bearophileHUGS lycos.com)'s articleJohnZ Wrote:In this case what would be the pros and cons if any of D compared
If you use C with GCC you can use the computed goto, that is really
such feature because it was thought as not useful enough.Bye, bearophile
ah....project similar to forth interpreter was an easy way of saying an attempt at an interaction machine emulator. if any of you know who Peter Wegner is you'll get the joke here :D
Mar 01 2009
sorry I emailed you...twice..first time I clicked reply to author by accident.. JohnZ
Mar 01 2009
JohnZ wrote:In this case what would be the pros and cons if any of D compared with C or asm?
You can compare C++ for an interpreter with the same code translated to D with Digital Mars' javascript engine http://www.digitalmars.com/dscript/index.html The D version is about 30% less source code and runs slightly faster.
Feb 28 2009
You can compare C++ for an interpreter with the same code translated
D with Digital Mars' javascript engine http://www.digitalmars.com/dscript/index.html The D version is about 30% less source code and runs slightly faster.
Thanks I'll take a look at the source code
Mar 01 2009









Daniel Keep <daniel.keep.lists gmail.com> 