Re: What's lacking: a good intermediate form
- From: Ray Dillinger <bear@xxxxxxxxx>
- Date: Wed, 25 Mar 2009 20:24:44 -0700
Tony wrote:
So does that mean, then, that, as far as you are concerned, that
abstract syntax trees are a good intermediate forrm, and nothing is
really lacking?
The concept of AST is good but their doesn't appear to be any
implementation of such a beast that is useful in getting to an exe or
useful in being used in a "higher level manipulation" scenario. So far, I
have found AST and IL, but I'm all ears for some other alternative if
there is one/some.
Okay, here's a thought. You take your AST and output it using a
preorder traversal, with parens at the beginning and end of each
subtree. When outputting tokens, you will need to munge tokens
here and there so they don't happen to be the same as predefined
Common Lisp keywords that mean something else. You can do this,
if you like, by just prepending the name of your language, so the
token "if" gets represented as "langname_if" for example.
Then you call the result Common Lisp code, and go develop (in Lisp)
the functions and macros that implement the semantics of your
language.
Common Lisp is a pretty good API for this sort of thing, in my
opinion. Lisp programs (including Common Lisp and Scheme) are
really nothing but abstract syntax trees, and Lisp macros are
a really good way to write AST-to-AST code transformations.
With Lisp macros and function definitions, you can give the features
of your language arbitrary semantics in a very general way. Plus,
there are already various kinds of code walkers and transformers
out there that already do things to lisp code like static type
checking if you're into bondage & discipline, but if you prefer
the latent typing typical of Lisp, you don't have to use them.
Finally, lots of people have already spent lots of time developing
bindings for Lisp code to standard operating system libraries, so
you won't be completely stuck for that.
Run the result through SBCL, which is a free, public-domain lisp
system with a fairly sophisticated back-end and compiler, and you
get a machine-code executable. It will depend on the SBCL runtime
library (which is a large-ish DLL) unless you static-link it, but
that was to be expected, right?
If you want a compiler that takes a long time to run but produces
much faster code, you may do essentially the same trick using
the STALIN Scheme compiler, which applies just about every trick
in the book for optimization. You'll probably have to implement
more code to define your semantics though, and the interface to
the native operating system functions isn't really as good in most
Schemes as it is in Common Lisp.
Bear
.
- Follow-Ups:
- Re: What's lacking: a good intermediate form
- From: Robbert Haarman
- Re: What's lacking: a good intermediate form
- References:
- Re: What's lacking: a good intermediate form
- From: Aaron Gray
- Re: What's lacking: a good intermediate form
- From: cr88192
- Re: What's lacking: a good intermediate form
- From: Tony
- Re: What's lacking: a good intermediate form
- From: Bartc
- Re: What's lacking: a good intermediate form
- From: Bartc
- Re: What's lacking: a good intermediate form
- From: Tony
- Re: What's lacking: a good intermediate form
- From: Robbert Haarman
- Re: What's lacking: a good intermediate form
- From: Tony
- Re: What's lacking: a good intermediate form
- From: Robbert Haarman
- Re: What's lacking: a good intermediate form
- From: Tony
- Re: What's lacking: a good intermediate form
- From: Robbert Haarman
- Re: What's lacking: a good intermediate form
- From: Tony
- Re: What's lacking: a good intermediate form
- Prev by Date: Re: (Boehm) gc question
- Next by Date: Re: What's lacking: a good intermediate form
- Previous by thread: Re: What's lacking: a good intermediate form
- Next by thread: Re: What's lacking: a good intermediate form
- Index(es):
Relevant Pages
|