Jump to page: 1 2
Thread overview
D for projects similar to Forth Interpreters?
Feb 28, 2009
JohnZ
Feb 28, 2009
Tim M
OT: Re: D for projects similar to Forth Interpreters?
Feb 28, 2009
Daniel Keep
Feb 28, 2009
bearophile
Mar 01, 2009
JohnZ
Mar 01, 2009
JohnZ
Mar 01, 2009
johnZ
Feb 28, 2009
Walter Bright
Mar 01, 2009
JohnZ
February 28, 2009
In this case what would be the pros and cons if any of D compared with C or asm?
February 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?
February 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
    .

February 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
February 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.
February 28, 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.
March 01, 2009
== 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
March 01, 2009
sorry I emailed you...twice..first time I clicked reply to author by accident..

JohnZ
March 01, 2009
== 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..
March 01, 2009
> 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
« First   ‹ Prev
1 2