www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D for projects similar to Forth Interpreters?

reply JohnZ <nospam myip.tks> writes:
In this case what would be the pros and cons if any of D compared with
C or asm?
Feb 28 2009
next sibling parent reply "Tim M" <a b.com> writes:
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
parent Daniel Keep <daniel.keep.lists gmail.com> writes:
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
prev sibling next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
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
next sibling parent reply Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
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
parent JohnZ <not here.net> writes:
== Quote from Jarrett Billingsley (jarrett.billingsley gmail.com)'s
article
 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.
ah that might be useful..
Mar 01 2009
prev sibling next sibling parent JohnZ <not here.net> writes:
== Quote from bearophile (bearophileHUGS lycos.com)'s article
 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
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
prev sibling parent johnZ <not here.net> writes:
sorry I emailed you...twice..first time I clicked reply to author by
accident..

JohnZ
Mar 01 2009
prev sibling parent reply Walter Bright <newshound1 digitalmars.com> writes:
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
parent JohnZ <not here.net> writes:
 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.
Thanks I'll take a look at the source code
Mar 01 2009