finn-assembler

Crates.iofinn-assembler
lib.rsfinn-assembler
version0.2.2
sourcesrc
created_at2019-03-18 05:50:22.875262
updated_at2019-04-05 15:19:49.140524
descriptionThe Finn IR Assembler
homepage
repositoryhttps://github.com/adam-mcdaniel/finn-assembler
max_upload_size
id121918
size2,440,353
adam mcdaniel (adam-mcdaniel)

documentation

https://docs.rs/finn-assembler

README

Finn-Assembler

The assembler for the Finn IR implemented using HLVM v0.9.0

Finn IR

Finn IR is a minimal language that is meant to be targetted by other languages.

It compiles to Rust, which is then compiled to a binary.

Features

  • Dynamic Typing - Finn IR allows you to use dynamic typing without having to sacrifice too much speed.
  • 128 bit Decimal Numbers - We use 128 bit decimal numbers to get very large and precise values while maintaining speed during mathematical operations.
  • Foreign Function Interface - Finn IR can access objects directly from included crates using the @ operator after an identifier.
  • Object Oriented Programming - The :, >, and < operators allow for simple object oriented programming.
  • Functional Programming - Finn IR can use the lambda calculus, but not efficiently. Also, because it is not garbage collected, it does not have an infinite recursion depth. However, this is great for closures, and other things.

Examples

Factorial

Calculates n factorial.

./fn examples/factorial.fn

{ 
    n=
    1 total=
    {
        total n* total=

        1 n- n=
    } {1 n greater!} &

    total
} factorial=


1500 factorial! println!

Lambda Calculus

Demonstrates use of Lambda Calculus in Finn IR.

./fn examples/lambda.fn

{a= {b= a}} True = 
{a= {b= b}} False = 

{p= {q= p q p!!}} And=


{ "is false!" println! } { "is true!" println! } True True And!!!!!

User Input

Gets user input from the command line, and prints out the result.

./fn examples/input.fn --crates include/input

">> " input@! user_input=

"You said: \"" print! user_input print! "\"" println!

FFI 'macro'

Automates a lot of the syntax required to define a constructor function. It also demonstrates how you can use a Rust FFI to simulate 'macros' (they're not really macros).

./fn examples/struct.fn --crates include/structs

[
    0 "x"
    
    {
        self=

        self x: > 1 + self x: < self =
        "im a method!" println!
        self
    }    "method"

    {
        "im a static method!" println!
    }    "static_method"
] strukt@! s=


s x: > println!
s s method: > ! s=
s x: > println!
s static_method: > !

Fibonacci

Calculates the fibonacci sequence. ./fn examples/fibonacci.fn

{
    n=
    1 a=
    0 b=
    0 c=

    {
        a b+ c=
        b a=
        c b=

        "iteration " print! n print! "  " print! c println!
        1 n-n=
    } {0 n greater!} &

    c
} fib=


29404 fib!

Object Oriented Programming

Demonstrates Object Oriented Programming in Finn IR. ./fn examples/object.fn

{
    $ self=

    x= y=
    x self x: < self=
    y self y: < self=

    {
        self= dx= dy=

        self x: > dx + self x: < self=
        self y: > dy + self y: < self=

        self
    } self move: < self=

    {
        self=

        "self:x " print! self x: > println!
        "self:y " print! self y: > println!

        self
    } self println: < self=

    self

} Sprite=


0 20.5 Sprite ! s=
s s println: > !


1 5 0- s s move: > ! s=
s s println: > !

Install

To install the Finn-assembler, clone the Finn-assembler repo, and run the install.sh file.

Commit count: 59

cargo fmt