Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kofigumbs/codec-beam
Generate Erlang VM byte code from Haskell
https://github.com/kofigumbs/codec-beam
assembly beam bytes codegen compiler elixir erlang
Last synced: 4 days ago
JSON representation
Generate Erlang VM byte code from Haskell
- Host: GitHub
- URL: https://github.com/kofigumbs/codec-beam
- Owner: kofigumbs
- License: bsd-3-clause
- Created: 2017-04-29T23:20:33.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-06T07:31:08.000Z (about 1 year ago)
- Last Synced: 2024-05-23T07:02:22.296Z (6 months ago)
- Topics: assembly, beam, bytes, codegen, compiler, elixir, erlang
- Language: Haskell
- Homepage: https://hackage.haskell.org/package/codec-beam
- Size: 251 KB
- Stars: 172
- Watchers: 8
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/hkgumbs/codec-beam.svg?branch=master)](https://travis-ci.org/hkgumbs/codec-beam)
[![Erlant/OTP Release](https://img.shields.io/badge/Erlang-OTP--20.3-red.svg)](https://github.com/erlang/otp/releases/tag/OTP-20.3)Erlang VM byte code assembler for implementing compile-to-beam languages.
The goal is to a provide delightful API for generating BEAM instructions from pure Haskell.### Usage
This example writes a simple module to a file:
```haskell
{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified Data.ByteString.Lazy as LBSimport Codec.Beam.Instructions (func_info, label, move, return')
import qualified Codec.Beam as Beammain :: IO ()
main =
LBS.writeFile "test_module.beam" $
Beam.encode "test_module"
[ Beam.export "tuple_of_one" 0
]
[ label (Beam.Label 1)
, func_info "tuple_of_one" 0
, label (Beam.Label 2)
, move (Beam.Tuple [Beam.Integer 1]) (Beam.X 0)
, return'
]
```After you run that program, you can load the resulting module from the Erlang shell!
```
$ erl
1> l(test_module).
2> test_module:tuple_of_one().
{1}
```You can find [a small example on GitHub](https://github.com/hkgumbs/codec-beam/tree/master/example) and a larger one in [my `elm-beam` project](https://github.com/kofigumbs/elm-beam).
### Build
Use [Stack](https://www.haskellstack.org):
```bash
stack build --test
```### Acknowledgements
Thanks to the following projects, which helped me understand the BEAM file format:
- https://github.com/happi/theBeamBook
- https://github.com/jerlang/jerlang
- https://github.com/kolmodin/herl
- https://github.com/mbrock/HBEAM
- https://github.com/erlang/otp