Enigma: Erlang VM Implementation in Rust

栏目: IT技术 · 发布时间: 12个月前

来源: github.com

内容简介:An implementation of the Erlang VM in Rust. We aim to be complete, correct and fast, in that order of importance.OTP 22+ compatible (sans the distributed bits for now) — all your code should eventually run on Enigma unchanged. Deprecated opcodes won't be s

本文转载自:https://github.com/archseer/enigma,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有。

Enigma VM

An implementation of the Erlang VM in Rust. We aim to be complete, correct and fast, in that order of importance.

OTP 22+ compatible (sans the distributed bits for now) — all your code should eventually run on Enigma unchanged. Deprecated opcodes won't be supported.

Why?

Because it's fun and I've been learning a lot. BEAM and HiPE are awesome, but they're massive (~300k SLOC). A small implementation makes it easier for new people to learn Erlang internals. We also get a platform to quickly iterate on ideas for inclusion into BEAM.

Installation

Only prerequisite to building Enigma is Rust. Use rustup to install the latest nightly rust. At this time we don't support stable / beta anymore, because we're relying on async/await, which is scheduled to run in stable some time in Q3 2019.

To boot up OTP you will also need to compile the standard library. At the moment, that relies on the BEAM build system:

git submodule update --init --depth 1
cd otp
/otp_build setup -a
make libs
make local_setup

We hope to simplify this step in the future (once enigma can run the compiler).

Run cargo run to install dependencies, build and run the VM. By default, it will boot up the erlang shell ( iex also works, but has some rendering bugs ).

Expect crashes, but a lot of the functionality is already available.

Pre-built binaries for various platforms will be available, once we reach a certain level of stability.

Feature status

We implement most of the opcodes, and about half of all BIFs. You can view a detailed progress breakdown on opcodes or BIFs .

Roadmap

  • Get the full OTP kernel/stdlib to boot ( init:start ).
  • Get the Eshell to run.
  • Get OTP tests to run (works with a custom runner currently).
  • Get the erlang compiler to work.
  • Get IEx to run.
  • Get OTP tests to pass.

Features

  • Floating point math
  • Spawn & message sending
  • Lambdas / anonymous functions
  • Exceptions & stack traces
  • Process dictionary
  • Signal queue
  • Links & monitors
  • Timers
  • Maps
  • Binaries
  • File IO
    • open/read/close/read_file/write
    • Filesystem interaction
  • External NIFs
  • Ports (might never be fully supported, we provide a few boot-critical ones as builtins: tty, fd)
  • External Term representation
    • Decoding
    • Encoding
  • ETS
    • PAM implementation
    • All table types partially, but we do not provide any concurrency guarantees
  • Regex (some support exists for basic matching)
  • Garbage Collection (arena-based per-process at the moment)
  • inet via socket nifs
  • Code reloading
  • Tracing/debugging support
  • Load-time instruction transform
  • Load-time instruction specialization engine

Goals, ideas & experiments

Process scheduling is implemented on top of rust futures:

  • A process is simply a long running future, scheduled on top of tokio-threadpool work-stealing queue
  • A timer is a delay/timeout future relying on tokio-timer time-wheel
  • Ports are futures we can await on
  • File I/O is AsyncRead/AsyncWrite awaitable
  • NIF/BIFs are futures that yield at certain points to play nice with reductions (allows a much simpler yielding implementation)

Future possibilities:

  • Write more documentation about more sparsely documented BEAM aspects (binary matching, time wheel, process monitors, ...)
  • Explore using immix as a GC for Erlang
  • Eir runtime
  • JIT via Eir
  • BIF as a generator function (yield to suspend/on reduce)
  • Provide built-in adapter modules for hyper as a Plug Adapter / HTTP client.
  • Cross-compile to WebAssembly ( runtime )

Initial non-goals

Until the VM doesn't reach a certain level of completeness, it doesn't make sense to consider these.

  • Distributed Erlang nodes
  • Tracing / debugging support
  • BEAM compatible NIFs / FFI

Note: NIF/FFI ABI compatibility with OTP is going to be quite some work. But, a rust-style NIF interface will be available. It would also probably be possible to make an adapter compatible with rustler .

Contributing

Contributors are very welcome!

The easiest way to get started is to look at the notes folder and pick a BIF or an opcode to implement. Take a look at src/bif.rs and the bif folder on how other BIFs are implemented. There's also a few issues open with the good first issue tag, which would also be a good introduction to the internals.

Alternatively, search the codebase for TODO , FIXME or unimplemented! , those mark various places where a partial implementation exists, but a bit more work needs to be done.

Test coverage is currently lacking, and there's varying levels of documentation; I will be addressing these soon.

We also have a #enigma channel on the Elixir Slack .


以上所述就是小编给大家介绍的《Enigma: Erlang VM Implementation in Rust》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

关注码农网公众号

关注我们,获取更多IT资讯^_^


查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

像程序员一样思考

像程序员一样思考

V. Anton Spraul / 徐波 / 人民邮电出版社 / 2013-6 / 49.00元

编程的真正挑战不是学习一种语言的语法,而是学习创造性地解决问题,从而构建美妙的应用。《像程序员一样思考》分析了程序员解决问题的方法,并且教授你其他图书所忽略的一种能力,即如何像程序员一样思考。全书分为8章。第1章通对几个经典的算法问题切入,概括了问题解决的基本技巧和步骤。第2章通过实际编写C++代码来解决几个简单的问题,从而让读者进一步体会到问题解决的思路和应用。第3到7章是书中的主体部分,分别探......一起来看看 《像程序员一样思考》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器