Shop OBEX P1 Docs P2 Docs Learn Events
Propellisp - A Scheme compiler for the Propeller — Parallax Forums

Propellisp - A Scheme compiler for the Propeller

toroidalcodetoroidalcode Posts: 4
edited 2013-06-29 08:54 in Propeller 1
Hi there! This is my first real forum post ever for anything so I'm a little nervous, but here goes:

I'm writing a Scheme compiler that targets Propeller 1 and (hopefully/eventually) Propeller 2. I've been working on this for about two weeks now, on again - off again sort of work due to school, but progressing nonetheless. It's nowhere near useful (doesn't even have a heap yet), but it's usable for small computations and interesting math.

I'm curious what sort of responses the community has. Would people be interested in seeing a compliant Scheme running on the Propeller? Even if I could only support a small subset of the spec due to space or computation limitations, would there still be interest?

If you'd like more info, I recommend looking at the repo here: https://github.com/toroidal-code/propellisp , as it has much more than I'm putting here.

Also, if people are interested in assisting in development, the project is open-source and MIT-licensed, and pull-requests/patches are always more than welcome.

Thanks!

Comments

  • BeanBean Posts: 8,129
    edited 2013-06-27 05:01
    Toroidalcode,
    I know nothing about lisp, but it sounds like a great project.
    I hope others that are able will help you in the development.

    Bean
  • David BetzDavid Betz Posts: 14,516
    edited 2013-06-27 05:20
    This sounds like an exciting project. I've thought it would be interesting to implement a Scheme or Lisp on the Propeller and take advantage one or more COGs to do realtime garbage collection but have never had the time. I'll be interested to follow your progress.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-06-27 06:12
    Lisp on a Propeller? Exotic, and interesting.

    For new learners, small is beautiful. These days, entering programing on a PC often buries the new learn in the vast resources available.

    So this may be a very useful presentation for Lisp.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-06-27 06:25
    Thanks for doing this. I have no time to help, but I'll be following along.
  • Martin_HMartin_H Posts: 4,051
    edited 2013-06-27 07:00
    I've been a Lisp fan since I learned Logo and then Lisp back in the 80's. The first environment I used was Inter Lisp for the 6502 when 48 KB was a lot of RAM. So you should be able to get something fairly usable in the Propeller's 32 KB.

    It will be interesting to see what sort of projects people will come up with for Lisp on the Propeller. With Algol family languages you are always dealing with numeric data types. Everything is ultimately a number. The first time I wrote a Lisp program was mind blowing because it didn't have a single number in it! Instead it was all about symbolic problem solving without any concerns for a numeric value for the symbols. Certainly you can deal with numbers with Lisp, but you don't have to.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-06-27 07:10
    I just looked over your source code and notice that you seem to be using some PC-based Scheme to run your compiler and that only the Scheme runtime is running on the Propeller. Do you expect to eventually be able to run the compiler on the Propeller as well?
  • toroidalcodetoroidalcode Posts: 4
    edited 2013-06-27 09:23
    All:
    Thanks for the support! I'll keep working on the this summer, as time allows. We'll see if I have anything good done by the time school rolls around again. I'll keep posting updates on this thread, if people are interested in that sort of thing.

    David:
    Right now, there aren't any plans to have the compiler be able to run on the Propeller itself, though it would be very interesting to see something like that happen. I could imagine eventually having a dedicated cog for emission, but at that point it wouldn't be emitting ASM anymore, it would have to be pure bytecode for the Prop. There's are some complexities in trying to get it running on that level, because I'd have to emulate a lot of what propgcc's GCC/AS is doing. Currently Petite Chez actually does all the really heavy lifting for me. Since it's a Lisp, evaluating Lisp, there's next to no lexing or parsing to be done. Abstract Syntax Tree-ish nodes are determined based on simple predicate testing and then the assembly is put together using a recursive-descent system. Though, if I got this compiler to be able to handle the full R6RS spec (the one I'm using for assembly emission code), one could theoretically compile the compiler source (with the modified bytecode emission) and run it on the Propeller. There's a lot of theoretical in there, so I wouldn't count on it happening for at least a while, if ever, haha.

    So for now the compilation is going to happen all on the computer side, the way GCC and other compilers work, because with a microcontroller, that's the easiest model to use.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-06-27 11:47
    So for now the compilation is going to happen all on the computer side, the way GCC and other compilers work, because with a microcontroller, that's the easiest model to use.
    Makes sense I guess except that you lose one of the really nice features of Lisp/Scheme, it's interactivity.
  • toroidalcodetoroidalcode Posts: 4
    edited 2013-06-27 12:36
    David Betz wrote: »
    Makes sense I guess except that you lose one of the really nice features of Lisp/Scheme, it's interactivity.

    Yeah, having a working REPL running on the processor isn't really an immediate goal. Scheme is actually less interpreted than Common Lisp is, with compilers like Chicken, Stalin, and Ikarus, which don't always have an interpreter. The paper I'm working with is actually by the same person who wrote Ikarus, which compiles directly to x86/x86_64 assembly, similar to what I'm doing here. Petite Chez, and I think Racket, on the other hand, are both interpreted. Chicken also has an interpreter. It's just a choice of backend. It's much easier to deal with separate compile/assemble/link steps in this project, where some of those are managed by existing tools.

    If I really wanted to write a super-robust compiler, I'd go about doing it completely differently, with a Flex lexer and a Bison-based parser, building up the AST and then mapping the AST nodes to emitted Intermediate Representation, and then transforming the IR to ASM using the LLVM or GCC backends, and then assembling and linking the binary. But I'm not nearly that skilled or knowledgable yet, and this is a first attempt at writing a simplistic compiler.

    Eventually though, one might be able to implement a REPL on the Propeller, since, if I remember correctly, a REPL is just
    (define (top-level) (do () ('()) (display "> ") (display (eval (read)))))
    
    where read would take from a serial connection, and display would send to the same. Eval is where it would be tricky, since that would have to execute the commands on the Propeller.
    We'll have to see. I'm still new to all this :)
  • jazzedjazzed Posts: 11,803
    edited 2013-06-27 12:44
    David is an old school Lisper.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-06-27 12:59
    Yeah, having a working REPL running on the processor isn't really an immediate goal. Scheme is actually less interpreted than Common Lisp is, with compilers like Chicken, Stalin, and Ikarus, which don't always have an interpreter. The paper I'm working with is actually by the same person who wrote Ikarus, which compiles directly to x86/x86_64 assembly, similar to what I'm doing here. Petite Chez, and I think Racket, on the other hand, are both interpreted. Chicken also has an interpreter. It's just a choice of backend. It's much easier to deal with separate compile/assemble/link steps in this project, where some of those are managed by existing tools.

    If I really wanted to write a super-robust compiler, I'd go about doing it completely differently, with a Flex lexer and a Bison-based parser, building up the AST and then mapping the AST nodes to emitted Intermediate Representation, and then transforming the IR to ASM using the LLVM or GCC backends, and then assembling and linking the binary. But I'm not nearly that skilled or knowledgable yet, and this is a first attempt at writing a simplistic compiler.

    Eventually though, one might be able to implement a REPL on the Propeller, since, if I remember correctly, a REPL is just
    (define (top-level) (do () ('()) (display "> ") (display (eval (read)))))
    
    where read would take from a serial connection, and display would send to the same. Eval is where it would be tricky, since that would have to execute the commands on the Propeller.
    We'll have to see. I'm still new to all this :)
    I don't think that compiling to assembly code and having a REPL need to be mutually exclusive. You would, however, need to have an assembler that runs on the target machine. Assembling Propeller code especially for Propeller 1 isn't that hard though. I think most of the Forth systems for the Propeller include an assembler.
  • toroidalcodetoroidalcode Posts: 4
    edited 2013-06-27 14:36
    David Betz wrote: »
    I don't think that compiling to assembly code and having a REPL need to be mutually exclusive. You would, however, need to have an assembler that runs on the target machine. Assembling Propeller code especially for Propeller 1 isn't that hard though. I think most of the Forth systems for the Propeller include an assembler.

    Yeah, it's certainly possible, it's just not something I'm going to focus on right now. I'm having trouble enough dealing with basic features like stack allocation. There's not even proper vector/pair support because of that. I'll have to see how the basic stuff goes before I get to the complex, haha.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-06-27 15:02
    Yeah, it's certainly possible, it's just not something I'm going to focus on right now. I'm having trouble enough dealing with basic features like stack allocation. There's not even proper vector/pair support because of that. I'll have to see how the basic stuff goes before I get to the complex, haha.
    That sounds like an excellent plan! Let us know you things go.
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-06-29 08:46
    Very cool stuff. I know a couple folks that are interested in interactive environments on the prop, I'll point them your way. They may have some techniques that might be useful to you.
  • KC_RobKC_Rob Posts: 465
    edited 2013-06-29 08:54
    Pretty sure I've pointed this out before, but it might be of interest/help in this thread. There is a fairly complete Scheme for ARM called Armpit Scheme.
Sign In or Register to comment.