digitalmars.D - D for projects similar to Forth Interpreters?
- JohnZ (2/2) Feb 28 2009 In this case what would be the pros and cons if any of D compared with
- Tim M (10/12) Feb 28 2009 C probably optimizes well based on its age. Asm will make some routines ...
- Daniel Keep (21/23) Feb 28 2009 Forth (actually, postfix languages in general) are awesome fun, and
- bearophile (4/5) Feb 28 2009 If you use C with GCC you can use the computed goto, that is really usef...
- Jarrett Billingsley (3/6) Feb 28 2009 D turns many switch statements into computed gotos. It's a compiler
-
JohnZ
(7/14)
Mar 01 2009
wrote: - JohnZ (7/12) Mar 01 2009 useful to speed up an interpreter like a Forth one. D misses still
- johnZ (3/3) Mar 01 2009 sorry I emailed you...twice..first time I clicked reply to author by
- Walter Bright (5/7) Feb 28 2009 You can compare C++ for an interpreter with the same code translated to
- JohnZ (2/6) Mar 01 2009 Thanks I'll take a look at the source code
- Dmitry Ponyatov (13/15) Apr 06 If you're not chasing for speed, using objects, types stack and
- Nicholas Wilson (2/18) Apr 06 Why did you reply to this thread? it is 15 years old.
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:D turns many switch statements into computed gotos. It's a compiler optimization.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.
Feb 28 2009
== Quote from Jarrett Billingsley (jarrett.billingsley gmail.com)'s articleOn Sat, Feb 28, 2009 at 6:10 AM, bearophile<bearophileHUGS lycos.com> wrote:with C or asm?<JohnZ Wrote:In this case what would be the pros and cons if any of D comparedreally useful to speed up an interpreter like a Forth one. D misses still such feature because it was thought as not useful enough.If you use C with GCC you can use the computed goto, that isD 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:with C or asm?<In this case what would be the pros and cons if any of D comparedIf you use C with GCC you can use the computed goto, that is reallyuseful to speed up an interpreter like a Forth one. D misses still such feature because it was thought as not useful enough.Bye, bearophileah....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 translatedtoD 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
In this case what would be the pros and cons if any of D compared with C or asm?If you're not chasing for speed, using objects, types stack and `Object*[string] W` vocabulary and symbolic string-addressed memory looks more fun than classical raw machine numbers and bytes. I did this with Python version earlier (and tried C++ also), so having `[ <int:123> <point:45 67> <window:hello> ]` on data stack looks much handy than dumb integers. Interpreter tracks all typed operations, and parser allows you to use inline arithmetics and pushes executable ASTs on top of stack. So, D has its own gc, and you don't need to bother about refrecounting and manual memory management across all the code as you must do it in C++.
Apr 06
On Saturday, 6 April 2024 at 08:43:36 UTC, Dmitry Ponyatov wrote:Why did you reply to this thread? it is 15 years old.In this case what would be the pros and cons if any of D compared with C or asm?If you're not chasing for speed, using objects, types stack and `Object*[string] W` vocabulary and symbolic string-addressed memory looks more fun than classical raw machine numbers and bytes. I did this with Python version earlier (and tried C++ also), so having `[ <int:123> <point:45 67> <window:hello> ]` on data stack looks much handy than dumb integers. Interpreter tracks all typed operations, and parser allows you to use inline arithmetics and pushes executable ASTs on top of stack. So, D has its own gc, and you don't need to bother about refrecounting and manual memory management across all the code as you must do it in C++.
Apr 06