archSeer

archSeer

Hi! I’m usually a lurker, but I wanted to show you what I’ve been working on for a while. About a month ago, I started working on an Erlang VM in Rust. My goal was to learn more about OTP internals so I’d be able to work on some contributions to BEAM. It’s been a ton of fun, and I’ve quickly progressed to implementing most of the opcodes (but not all of the native functions) – I’m currently working on getting the application bootstrap to run (:init.start).

It’s an interesting look into how BEAM might look like if it was built from scratch today. I’m also planning to experiment with a few different ideas (alternative GC implementations, cross compiling to WebAssembly, different ETS backends, map structures, etc.), as well as writing a bit more information on how BEAM works internally (The BEAM Book is a wonderful resource, but incomplete in some parts).

Because of the scale of work, I’m looking for more contributors! If all this sounds exciting, or you’d like to learn more about OTP or low-level programming, please reach out :slight_smile:

Also, a shoutout to @bettio ! I’ve seen the AtomVM announcement around the time I started working on Enigma, hopefully we can share notes on a few things :slight_smile:

Link to repository: GitHub - archseer/enigma: An Erlang VM implementation in Rust · GitHub

Showing Posts 1 to 8

OvermindDL1

OvermindDL1

Ooooo, this looks fascinating!

hauleth

hauleth

For supporting “GC-ish” functionality you can use per-proces arena. As Erlang always copy data between processes and most of the processes are short-lived then you do not need highly sophisticated algorithms and just free whole arena at once when process dies.

Project seems very interesting and when I will have some time I will try to contribute to it.

hauleth

hauleth

Also as binary pattern matches can match only beginning of the binary it is better to use something like fst or just finite automata, as even in multi pattern case you can build such machine and it should then work in linear time. It will be much easier and simpler rather than using Aho-Corasick. Bit patterns can be a little PITA, but even then you can just build N nodes for each combination that will match given bit pattern and match against it.

OvermindDL1

OvermindDL1

I wonder if this is worth posting at Redirecting to Google Groups or if not now perhaps when a bit more developed as it would gain a lot more visibility especially from core devs who might find this interesting. :slight_smile:

bettio

bettio

Sure, I would be glad to answer to any question :slight_smile: Also let me know if you have any doubt about undocumented stuff :slight_smile:

archSeer

archSeer OP

So I sort of do that at the moment, unintentionally so :slight_smile: Using a global allocator, I allocate a block of memory for each process to then bump allocate into (a process can always request more blocks). When the process dies, the block list is dropped, which then mass drops everything (in theory, I think the block just drops at the moment which means reference counts will be borked). So I definitely think arenas will be able to carry us for a while; given that I’m not at a point where we can continuously run larger programs.

Please do! (Also hi from /r/vim, I’ve copied a bunch of settings from your vimrc in the past :slight_smile: Most things are in flux now (for example value/term implementation will change further, I don’t do much in terms of immediate vs boxed value packing. I brought it down today to 2 words/128 bits – enum discriminant + pointer/immediate, but I got a couple of interesting ideas from @michalmuskala yesterday if we tried JVM-style 32 bit sized pointers), but it’s always good to get more contributors with fresh ideas into the mix.

Yeah sorry, that README section is mislabeled, s/matching/searching/: Erlang uses aho-corasick + boyer-moore for binary:match/2,3 otp/erts/emulator/beam/erl_bif_binary.c at 9009934d56625249503210298e102d8e5744f546 · erlang/otp · GitHub

fst looks promising for binary matching/parsing though, I was also considering using nom since I already use it for the loader, and it can do bit level matching. (It’s also macro based so should be pretty efficient).

I think using rust’s regex which is basically PCRE without lookahead and some other features to make it linear time would be an interesting experiment – since it’s linear time, we’d be able to estimate reductions based on the string & pattern length. (OTP at the moment manually patches PCRE to be re-entrant, which is a very complicated mess to update to a new PCRE version. We’d drop some compatibility to make the implementation a bit simpler.

Looks promising once I get things a bit more sketched out! :slight_smile: It seems to mainly be related to GSoC though?

Joined your slack channel! Maybe we could start a general #low-level or #vm/#beam Slack channel?

hauleth

hauleth

I would <3 to see unikernel built on top of that, as I am still trying to write my app in that form, so I will just upload AMI and run that directly. It is sad that LING died and this can be basis for building similar solution without worrying about the VM itself (as this is both - binary and library at once).

archSeer

archSeer OP

Quick update: I’m making progress, currently about 30k instructions into the OTP boot-up. There’s binary and map support, process links and monitors, some limited file I/O, and I’m currently working on a minimal ETS implementation. It doesn’t work just out of the box yet, but I’ll have some preview builds soon I hope :slight_smile:

I’ve also set up a channel on the Elixir Slack, #enigma for anyone interested.

13
Post #8
— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 91898 914
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews