Logo

0x5a.live

for different kinds of informations and explorations.

GitHub - kofigumbs/codec-beam: Generate Erlang VM byte code from Haskell

Generate Erlang VM byte code from Haskell. Contribute to kofigumbs/codec-beam development by creating an account on GitHub.

Visit SiteGitHub - kofigumbs/codec-beam: Generate Erlang VM byte code from Haskell

GitHub - kofigumbs/codec-beam: Generate Erlang VM byte code from Haskell

Generate Erlang VM byte code from Haskell. Contribute to kofigumbs/codec-beam development by creating an account on GitHub.

Powered by 0x5a.live 💗

Build Status Erlant/OTP Release

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:

{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified Data.ByteString.Lazy as LBS

import Codec.Beam.Instructions (func_info, label, move, return')
import qualified Codec.Beam as Beam

main :: 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 and a larger one in my elm-beam project.

Build

Use Stack:

stack build --test

Acknowledgements

Thanks to the following projects, which helped me understand the BEAM file format:

Elixir Resources

are all listed below.

Resources

listed to get explored on!!

Made with ❤️

to provide different kinds of informations and resources.