Arc Forumnew | comments | leaders | submitlogin
An idea for Arc in Arc
3 points by eds 6117 days ago | 8 comments
This is somewhat related to my previous post about CL-Arc (http://arclanguage.org/item?id=5396). I had an idea, inspired by kens (http://arclanguage.org/item?id=5481), and I'd like to know whether it is possible, difficult, or if I am out of my mind.

My idea basically sets the foundation for a metacircular Arc compiler in two steps:

Step 1: Port a Scheme compiler to Arc

Step 2: Modify the compiler to compile Arc instead

Arc can actually be mostly metacircular after only the first step. If we can successfully port a Scheme compiler to Arc, then we can run it under the current MzScheme Arc, and use it to compile ac.scm (or a version edited to be compatible with our new compiler). This Arc executable can then be used to load the compiler and recompile ad infinitum.

However, this kind of metacircularity via Scheme is not entire what we want, so to get a true Arc in Arc compiler we would want to modify the Scheme compiler to compile Arc directly instead of through Scheme. This may be easy or extremely difficult depending on how similar Arc is to Scheme. On the surface it doesn't look too dificult but maybe I am overlooking something.

So what follows is a three part poll:

* Do you think doing this would be easy, moderate, difficult, or impossible?

* Should this be how we implement Arc in Arc (assuming it is at least possible)?

* If it is possible and the right thing, which Scheme implementation should be used as the base?

(I won't start the third section until I get suggestions.)

Feedback would be appreciated.

easy
0 points
moderate (difficulty)
2 points
difficult
10 points
impossible
0 points
this is the right way to implement Arc in Arc
2 points
this is NOT the way to implement Arc in Arc
1 point


2 points by sacado 6117 days ago | link

mzscheme has a rather good C API. I was thinking about using it to generate C code for Arco that would less rely on mzscheme after each release, before both are totally independant.

However, after my last experiences, it is much harder than directly writing an Arc compiler generating C code, from scratch. I gave a pointer earlier : http://www.iro.umontreal.ca/~boucherd/mslug/meetings/2004102... This might also be useful (that's where I got the link from ) : http://www.canonical.org/~kragen/sw/urscheme/.

I am currently working on the one at the first address. I translated it to Arc. In other words, I have a scheme compiler written in Arc that can hardly do anything but compile the fib function to C.

Pretty soon, I'll have something compiling a poor subset of Arc (only fixnums and symbols, no list, no bignum, no GC, no special syntax, but with closures and call/cc fully operational).

-----

2 points by cchooper 6117 days ago | link

The Stalin Scheme compiler is 33000 lines long. That's an aggressively optimising compiler, so nothing will be much more complicated than that.

To translate something like that 'easily', you'd have to use automatic translation to Arc for most of it. Looking at the code, I think that'll be quite easy, and you'll get say 90% of the code converted that way. That leaves about 3300 lines. So I'm guessing this is of moderate difficulty.

-----

1 point by eds 6117 days ago | link

Do you think this would be a realistic amount of work for one summer?

What about part two (converting the compiler to compile Arc instead)? I suppose I would gain something on an understanding of the operation of the compiler while doing part one, but this seems rather intimidating to me.

And I'm not really sure Stalin is the right compiler to base an Arc in Arc on. (Although I suppose that wasn't really the point of your post.)

Can you suggest any other Scheme compilers I might try to port?

-----

1 point by cchooper 6117 days ago | link

I don't know much about Scheme compilers (or Scheme for that matter, I'm a Lisp guy), so I can't really say.

For the conversion to an Arc compiler, it's similar enough to Scheme that I don't think it'll be a big issue, especially as it's implemented on MzScheme. Quite a few tricky Arc functions are just MzScheme functions under a different name (e.g. threading, I/O stuff). That brings up a point: you really want a compiler for the subset of MzScheme that Arc uses, not Scheme itself (although a Scheme->Arc compiler would be cool too).

Is it too much work for a summer? Depends on what you want to achieve. A completely non-optimising Arc compiler, based on code ripped from other projects, would probably be really easy to implement. Writing a Scheme compiler in one semester is standard coursework on some CS courses. So I guess the important questions are:

1. What good Scheme compilers written in Scheme already exist?

2. How much actually needs to be converted? (Most of the runtime will probably be implemented in C anyway, so no conversion necessary).

3. Given the spread of possible compilers you could convert, do any of them look like a summer's worth of work?

So I'm basically saying: maybe.

-----

1 point by almkglor 6117 days ago | link

I like how Chicken implements Scheme ^^;

-----

1 point by stefano 6117 days ago | link

Some compilers are not metacircular, so you could skip the first part and pass directly to the second. The difficulty depends on the knowledge of the compiler you want to modify. Anyway, this seems a rather difficult task.

-----

1 point by eds 6117 days ago | link

> The difficulty depends on the knowledge of the compiler you want to modify.

And since I don't know Scheme implementations that well, I'd appreciate any advice on which compilers might be suitable for this project.

-----

1 point by stefano 6116 days ago | link

Ikarus seems to be self-hosting.

-----