Starting a language implementation in Rust ("Lisp" like)

Hello All,

I am completely new to Rust, but I do know quite well several other languages (Ocaml, Lisp, C++, C, ...). And I even have implemented some DSL, notably GCC MELT (Google for it, with my name also) which is now a dead project, and was a Lisp dialect to customize the GCC compiler.

These days, I am working on Bismon and I am very familiar with Linux. A draft technical report is available (but with only two links permitted, I cannot give it here).

I am considering (mostly during my retirement, in a few years) to reimplement Bismon (as some improved project) in Rust.

I absolutely need to have a multi-threaded garbage collector. I want to use Ravenbrook MPS

I would be happy if there is some well written Rust implementation of some Lisp like language. I'll be happy to study the Rust source code of some simple Scheme-like interpreter, SIOD-like (or SCM-like).

I need basic things, such as my own memory allocation (MPS based). I am not sure of how to express that in Rust.

I'm sorry to ask such naive questions, but I never coded in Rust. However, I feel the language very interesting. It seems that for using my own allocation routines, I need unsafe facilities.

I do have time to learn Rust, and I do know I will learn it slowly.

Regards.

PS. It is really annoying that only two links are permitted in new topic.

Basile Starynkevitch

2 Likes

Well, as far as I know, the only languages written in rust are Rust,

and Dyon,
https://github.com/PistonDevelopers/dyon
I don't know very much about Lisp but as far as I know, neither are similar to Lisp, but they might server as a starting point for learning about language design in Rust. Either way, I'd recommend you start with reading the Rust Book, and if you're still abit insecure, you try some things out, like trying to implement a linked list (Which is... interesting...) and a simple algorithm; the borrowing rules are pretty weird to newcomers. Also, the biggest selling point for rust is its lifetime rules, and borrowing/ownership, which disappear when using unsafe so I'd recommend trying to minimize the unsafe code.

PS. Stay active on here, and you will be able to post more than one link in a post, it's not too difficult to get a basic rank.

You just wrote:

the biggest selling point for rust is its lifetime rules, and borrowing/ownership

My thinking is that the biggest selling point for Rust in my particular case is its powerful macro system and type inference. I've read several things about Rust, and I am not so sure that borrowing is important, even if certainly it will be useful to me.

In my project, the only mutable values I have are objects, each containing its own lock. Most of the values of my project are immutable. And all values (both mutable objects and the immutable values such as set of pointers to objects) are garbage collected by MPS.

(Yes, I do have particular constraints and ideas).

I'm finding several Rust implementations of small dialects of Scheme. Sadly, GitHub - fitzgen/oxischeme: A Scheme implementation, in Rust. looks having very readable code, but I cannot compile it on Rust 1.32

While it's macro system is hygienic and is apt to procedural macros, I wouldn't take it as it's biggest selling point; that's only a compile time benefit. It's borrowing/ownership/lifetime rules prevent undefined behaviour, remove the need for a GC, or user-frees and a thread-safe system for concurrent applications, which in turn makes it fast, safe, and unlikely to crash due to a segfault.

I absolutely need to implement a GC in my language (but I am willing to glue Ravenbrook MPS to Rust). I know well enough why.

Notice that all Scheme implementations have a GC.

I never meant that you couldn't implement a GC into your language, just that rust itself doesn't have a GC, and therefore the benefit of added performance

Of course, and I do know that quite well. Neither C nor C++ provide a GC, but I am today able to implement a GC in C or in C++, but not in Rust.
What is the way to implement a GC in Rust? (I believe I know GC techniques quite well, and I did implement myself several GCs). I also know that implementing a good GC takes years of work. I decided to use Ravenbrook MPS (and will glue it to Rust).

NB. The Bismon system that I might begin to re-implement in Rust is free software (on github) and has a draft technical report describing it on http://starynkevitch.net/Basile/bismon-chariot-doc.pdf (it is a draft H2020 report; feel free to skip the first few pages, required by H2020 bureaucracy and the CHARIOT consortium funding my work)

PS. I have 40 years of programming experience, and a PhD (gotten in 1990) in symbolic AI
PPS. When will I be allowed to put more than 2 links in a post here. I usually give links to help readers.

1 Like

I don't know if you could just use shifgrethor, in any case withoutboats wrote a series of interesting blog posts about implementing a GC in Rust. Maybe it could be a good starting point.

1 Like

If these are of interest,

Gluon is a garbage collected Haskell-like language implemented in Rust. It uses per-thread GC.

This reddit post lists a number of other smaller languages written in Rust as of January 2018, many of them hobby projects.

shifgrethor is a recent experiment for implementing GC in rust code. See also the blog series detailing its design. (also just mentioned by @dodomorandi!)

rust-gc is a simpler GC in Rust, also with related blogs.

The two blogs for shifgrethor and rust-gc are probably the best starting place I know.

I'm unfamiliar with Raven MPS, but if you are interested in using an existing implementation with a C interface, Rust can definitely call into that. The bindgen book is a good place to start for building Rust code which calls into C interfaces.

PPS. When will I be allowed to put more than 2 links in a post here. I usually give links to help readers.

I'm not sure about this, unfortunately. I know this forum software is untrustworthy of newer users but I don't know at what point that goes away.

1 Like

Scheme from Scratch is a blog post series that walks through implementing a Scheme in C. I find most of the principles fairly easy to translate to Rust, in some cases significantly easier, in some cases slightly harder.

I know a bit of it. But I much prefer Queinnec's Lisp In Small Pieces book (which I actually have in its original, French, version).

There is also this list, although it's no longer maintained:

https://github.com/ruse-lang/langs-in-rust

Mssr Starynkevitch, welcome to Rust!

There are many interesting examples of languages implemented in Rust. They can

I recommend Rhai, which aims to be be embedded within Rust projects.

There is a Lisp implementation called Ketos

If you wish to explore, perhaps start with investigating the scripting, dsl, lisp keywords on crates.io. If you have less time,awesome-rust is an excellent curated list of resources implemented in Rust for various applications.

1 Like