{
.date=
.title=
Secret Project
For the last few weeks I've been working on a "secret" project. I'm doing a best effort port of quickjs from C into Rust. Why? A few reasons:
- the author of quickjs is obviously a very talented programmer, and I hope to learn a lot going over the code
- to learn Rust better
- to learn the spec of Javascript better
I decided to go about it in a very mechanical way, straight translation of C to Rust, starting with the header file, then working from top to bottom. Most of the first ~2000 lines have just been translating struct
s, but I have had to make some interesting choices. I'll be detailing them in later posts, but here's a brief list:
JSValue
in QuickJS is a tagged enum stored as a 64bit int. I decided I can use a regular Rust enum- Choosing whether pointer types are
Option<T>
,&T
, orRc<T>
- Deciding what to do with the various
void *
- How to translate the "X-macro" idiom from C
- How to represent the GC layer.
The last one is what I'm currently working through. In qjs each gc-able object is part of a linked list and so contains a "klist" style entry (a prev and next node pointer). I believe that I could copy the direct implementation into rust, using the associated pointer arithmatic, but I also believe that it would be unidiomatic.
I'll follow up with more details in later posts
}