Re: What's lacking: a good intermediate form



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

.



Relevant Pages

  • Re: Survey: Do you use the "2" in Lisp-2?
    ... Why You should Not Use The Jargon Lisp1 and Lisp2 ... Graham's On Lisp, I'm wondering what the advantages of a Lisp-2 ... For another example, consider today's PHP language. ... Now, the question is, why do Lisps before Common Lisp have this multi- ...
    (comp.lang.lisp)
  • Re: Program compression
    ... problems to be solved much more concisely than with Lisp. ... In Common Lisp, it's another one line of code: ... My point is that different languages are based on different things ... it would be impossible for the author of a macro (in the Lisp ...
    (comp.programming)
  • Re: Program compression
    ... In Common Lisp it's just one line of code: ... In OCaml with OCaml's notation: ... In Common Lisp, it's another one line of code: ... Consider parsing Mathematica expressions including lists, rules, sums, ...
    (comp.programming)
  • Re: How Common Lisp sucks
    ... Note that the title of this post is *HOW* CL sucks, ... I would like to embed a language that is very similar to Common Lisp, but which differs in how it handles global variable references and arguments) syntax. ... And if it were done it would result in strictly greater expressive power. ...
    (comp.lang.lisp)
  • Re: Popularity of programming languages
    ... >> achieve portability across many CL implementations in your own code, ... > standard simply doesn't provide what writers of portable code need. ... > - Lisp is a rich language with a standard ... The Common Lisp standard provides a lot more stuff than the Scheme ...
    (comp.lang.lisp)