All Projects → ioanluca → real-world-idris

ioanluca / real-world-idris

Licence: BSD-3-Clause License
Malfunction backend for Idris with a FFI to OCaml

Programming Languages

TeX
3793 projects
haskell
3896 projects
Idris
72 projects

Projects that are alternatives of or similar to real-world-idris

compiler
My first attempt to create a compiler
Stars: ✭ 16 (-38.46%)
Mutual labels:  compilers
pegasus
A parser generator for C and Crystal.
Stars: ✭ 50 (+92.31%)
Mutual labels:  compilers
ciforth
A generic system for creating i86 implementations of the language Forth.
Stars: ✭ 38 (+46.15%)
Mutual labels:  compilers
nmodl
Code Generation Framework For NEURON MODeling Language
Stars: ✭ 42 (+61.54%)
Mutual labels:  compilers
librxvm
non-backtracking NFA-based regular expression library, for C and Python
Stars: ✭ 57 (+119.23%)
Mutual labels:  compilers
kolasu
Kotlin Language Support – AST Library
Stars: ✭ 45 (+73.08%)
Mutual labels:  compilers
compilers-lectures
Lectures for the class on [email protected]
Stars: ✭ 67 (+157.69%)
Mutual labels:  compilers
cs-resources
Curated Computer Science and Programming Resource Guide
Stars: ✭ 42 (+61.54%)
Mutual labels:  compilers
beast-dragon
Beast language compiler & reference
Stars: ✭ 13 (-50%)
Mutual labels:  compilers
ck-env
CK repository with components and automation actions to enable portable workflows across diverse platforms including Linux, Windows, MacOS and Android. It includes software detection plugins and meta packages (code, data sets, models, scripts, etc) with the possibility of multiple versions to co-exist in a user or system environment:
Stars: ✭ 67 (+157.69%)
Mutual labels:  compilers
tiny-lang
tiny-lang — A different programming language. Supports a bunch of spoken languages.
Stars: ✭ 26 (+0%)
Mutual labels:  compilers
pymlir
Python interface for MLIR - the Multi-Level Intermediate Representation
Stars: ✭ 84 (+223.08%)
Mutual labels:  compilers
CompilersCourse
Theory of compilation course, MIPT
Stars: ✭ 32 (+23.08%)
Mutual labels:  compilers
open-ops
Open Optimizing Parallelizing System
Stars: ✭ 21 (-19.23%)
Mutual labels:  compilers
awesome-internals
A curated list of awesome resources and learning materials in the field of X internals
Stars: ✭ 78 (+200%)
Mutual labels:  compilers
comp
Disciplina de Compiladores (INF01147) - INF/UFRGS
Stars: ✭ 28 (+7.69%)
Mutual labels:  compilers
hascal
Hascal is a general purpose and open source programming language designed to build optimal, maintainable, reliable and efficient software.
Stars: ✭ 56 (+115.38%)
Mutual labels:  compiler-backend
regal86
Register Allocator for 8086
Stars: ✭ 62 (+138.46%)
Mutual labels:  compiler-backend
3bc-lang
Low level language, tiny virtual machine that works on computers and microcontrollers. (Friendly Punched cards)
Stars: ✭ 155 (+496.15%)
Mutual labels:  compilers
specdris
A test framework for Idris
Stars: ✭ 55 (+111.54%)
Mutual labels:  idris-ecosystem

Real World Idris

This is an experimental code generation backend for Idris that compiles it to a slightly modified version of Malfunction that has basic support for accessing identifiers outside the OCaml standard library.

This project also represents work in progress towards allowing Idris and OCaml to interoperate by implementing a ''Foreign Function Interface'' between the two languages using Idris' New FFI (described in Edwin Brady's paper and documented here).

Installation

Requirements

Clone this repository:

$ git clone --recurse-submodules https://github.com/ioanluca/real-world-idris.git
$ cd real-world-idris/

Using Stack

$ stack build 

or, if you want to install the binaries globally:

$ stack install 
$ stack install idris 

All idris commands can be executed in the Stack sandbox by prepending them with stack exec --

Install Malfunction using Opam

In the root of the repository:

$ cd malfunction/
$ opam install .

Install the ocaml Idris package

In the root of the repository:

$ cd lib/
$ idris --install ocaml.ipkg

This needs to be used in Idris programs to access the FFI to OCaml.

Install the idrisobj OCaml package

In the root of the repository:

$ cd rts/
$ opam install .  

This is a runtime support library. It is a wrapper around the OCaml Obj module. The plan is to get rid of it and implement the required functions from Obj using Idris primitives.

Usage

$ idris Source.idr --codegen malfunction -p ocaml --cg-opt '-op ocamllib1 -op ocamllib2' -o a.out
$ ./a.out

-op is short for --ocamlpackage

Alternatively, %lib malfunction "ocamllib" can be used in an Idris file to link an OCaml library.

Examples

Some test programs can be found in test-idris.

To compile the graphics example:

$ cd test-idris/
$ cd graphics/
$ idris IdrCamlGrphics.idr --codegen malfunction -p ocaml --cg-opt '-op graphics' -o CamlGraphics.out
$ ./CamlGraphics.out

Note that the above example is linking the OCaml graphics module using the --cg-opt '-op graphics' flags.

Alternatively, graphics could also be linked by having the following line in IdrCamlGraphics.idr:

%lib malfunction "graphics"

Benchmarking

Some example programs can be found in benchmark.

It seems to go pretty fast compared to the default C backend:

$ idris pythag.idr -o pythag-idris
$ idris pythag.idr --codegen malfunction -o pythag-malfunction
    
$ time ./pythag-idris  > /dev/null
   
real    0m4.548s
user    0m4.528s
sys     0m0.016s
    
$ time ./pythag-malfunction  > /dev/null
    
real    0m0.654s
user    0m0.652s
sys     0m0.000s

Tested on:

  • Ubuntu 16.04.4 LTS 64-bit
  • Intel® Core™ i5-2500 CPU @ 3.30GHz × 4
  • 8 GB RAM
  • Idris 1.2.0
  • Malfunction v0.2.1
  • OCaml 4.05.0+flambda

Todo

  • unicode, cannot just show KStrs, ocaml 8bit, overflow safety?
  • implement all primitives
  • use ocaml gc optimizations through env vars
  • tail calls
  • squeeze multiple lets together? let x = let y = 3 in
  • squeeze multiple lambdas together?
  • --interface flag?
  • dead code elimination (extra care with inlined definitions)
  • maybe get lang decls without liftings (if possible)
  • use state with a record for code generation monad?
  • use writerT and ReaderT instead of the Translate monad?
  • polymorphism (at the moment it is not possible to export polymorphic functions from Idris)
  • ADTs (separate from Idris' ADTs?)
  • User friendly modules (no way to name definitions right now)
  • Generating Idris type definitions from .cmi files
  • this Todo list

Contributing

Contributions are welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].