Giter VIP home page Giter VIP logo

idris-cil's Introduction

idris-cil Build Status

A Common Intermediate Language backend for Idris.

Why

Because programmers targeting the CLR deserve a modern pure functional language with dependent types.

Usage

Given a Main.idr file:

module Main

main : IO ()
main = putStrLn "Hello, Idris!"

Compile it to cil and execute it with .NET Core:

idris --codegen cil Main.idr -o HelloWorld.exe \
  && dotnet HelloWorld.exe

The resulting assemblies can also be used with Mono or Unity.

Installing

It's important that the version of the Idris executable matches the version used to build idris-cil:

git clone [email protected]:bamboo/idris-cil
cd idris-cil
stack install idris
stack install

Contributing

Issue reports and PRs are welcome.

Brought to you by @bamboo, @sangamon and contributors.

License

BSD3

Requirements

.NET Core 1.1 with ilasm

Install ilasm using nuget:

dotnet new console -o ilasm-setup
cd ilasm-setup
dotnet add package runtime.osx.10.10-x64.Microsoft.NETCore.ILAsm
cd .. && rm -fr ilasm-setup

Replace the runtime.osx.10.10-x64 prefix above with the right value for your system, for instance, ubuntu.14.04-x64.

Add ilasm to your PATH with something like:

export PATH=$(find $HOME/.nuget/packages -name ilasm | xargs dirname):$PATH

If you get an error from ilasm saying it cannot load libcoreclr.dylib, add the dotnet/shared dir to DYLD_LIBRARY_PATH:

export DYLD_LIBRARY_PATH=/usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.1.2:$DYLD_LIBRARY_PATH

idris-cil's People

Contributors

bamboo avatar bartadv avatar simoncropp avatar xran-deex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

idris-cil's Issues

purity of show -- show implementation is culture-sensitive at the moment

printLn $ show 4.2

might lead to 4.2 or 4,2, depending on the current culture on which the dotnet code is executed. While this is .net default behavior of .ToString(), I'm not sure if this should be fixed with CultureInfo.InvariantCulture; maybe some code would already expect the .net default here; while on the other hand from an Idris point of view show should be pure.

FFI: efficient array API

  • Provide a more convenient CIL.FFI.Array.get accessor function which doesn't require the element type to be passed in
  • Support all primitive types
  • Provide efficient conversion functions between primitive arrays and Data.Vect
  • Provide efficient conversion functions between primitive arrays and Lists
  • Unify CIL.FFI.ObjectArray and CIL.FFI.Array.TypedArray
  • Support native int arrays
  • Support value types
  • Provide efficient indexed accessors

Integer support

System.Numerics.BigInteger is the obvious choice but we should also consider alternative solutions that would work on lesser frameworks such as Unity's.

add support for Double without removing support for Single

Currently, Double as handled as System.Single (float32) which violates Idris semantics.

Double needs to be handled as System.Double but support for float32 must be preserved.

This can probably be achieved by introducing a CIL type for "System.Single" and implementing all required type classes efficiently via %externs.

Implement missing Double primitives

exp : Double -> Double
exp x = prim__floatExp x

log : Double -> Double
log x = prim__floatLog x

sin : Double -> Double
sin x = prim__floatSin x

cos : Double -> Double
cos x = prim__floatCos x

tan : Double -> Double
tan x = prim__floatTan x

asin : Double -> Double
asin x = prim__floatASin x

acos : Double -> Double
acos x = prim__floatACos x

atan : Double -> Double
atan x = prim__floatATan x

atan2 : Double -> Double -> Double
atan2 y x = atan (y/x)

sinh : Double -> Double
sinh x = (exp x - exp (-x)) / 2

cosh : Double -> Double
cosh x = (exp x + exp (-x)) / 2

tanh : Double -> Double
tanh x = sinh x / cosh x

sqrt : Double -> Double
sqrt x = prim__floatSqrt x

floor : Double -> Double
floor x = prim__floatFloor x

ceiling : Double -> Double
ceiling x = prim__floatCeil x

optimisation: infer types of local variables to reduce boxing

Currently, a function such as:

f : Double -> Double
f d = 3.0 + d * 42

Compiles down to the following boxing-heavy bytecode (nevermind the fact that Double is currently mapped to float32 which is a separate issue - #8):

.method static assembly object 'Main.f'(object 'e0') cil managed {
    .locals init (
            object l0,
            object l1)
    ldc.r4 3.0
    box float32
    stloc.0 
    ldc.r4 42.0
    box float32
    stloc.1 
    ldarg.0 
    unbox.any float32
    ldloc.1 
    unbox.any float32
    mul
    box float32
    stloc.1 
    ldloc.0 
    unbox.any float32
    ldloc.1 
    unbox.any float32
    add
    box float32
    ret
}

The type for both local variables could be inferred thus allowing all unnecessary boxing operations to be removed leaving only the unboxing of the argument and the final boxing of the return value.

support for .NET 3.5?

Is there anyway to get this to emit something that targets .NET 3.5?, the Unity Editor still doesnt support .NET 4.x

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.