ridulfo / nino-lang

A minimalistic functional programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nino-lang

Run Tests

Minimal functional programming language

(Development is currently on hold)

Like the Whippet, this language [will have] the highest running speed of any [language] of its [size].

The goal is to create a small language that only has the essential features needed to be able to do pretty much anything. No bloat. This will make self-hosting easier and faster.

In this spirit, the under the hood type system is minimal. There are only 5 types:

  • num - 64 bit floating point number - this is used for numbers
  • char - 8 bit number - used to represent characters
  • bool - used to represent true and false
  • fn - functions are first-class citizens, this is their type
  • array - an array of any type (even arrays)

The language is chill with side effects. There is no need to wrap anything in monads.

At the moment the language is interpreted, but the goal is to create a self-hosting compiler. TBD whether to compile directly to assembly, LLVM IR or QBE IL. There is no garbage collector at the moment (TBD 🤨).

Finally, here is a blog-post about some design decisions: Designing a functional programming language.

Quick start

Compile the interpreter

cargo build --release && mv target/release/ninoi .

Run a example program

./ninoi examples/is-prime.ni
Output
Let's calculate primes!
10000019
10000079
10000103
10000121
10000139
10000141
10000169
10000189
Time in milliseconds:
47
    

More examples can be found in /examples!

Bonus

There is an expression-to-AST-diagram program too!

cargo run --bin mermaid "1+2+3 + 1+2/3 + x mod y" > mermaid.md
Output View this using a mermaid viewer.

Documentation

Documentation can be found in the docs.

There you can find the language specification (WIP) and the grammar specification.

Examples

let is_prime_helper:fn = (x:num, i:num):bool => true ? {
    x==i => true,
    x mod i == 0 => false,
    is_prime_helper(x, i + 1)
};

let is_prime:fn = (x:num):bool => x ? {
    1 => false,
    2 => true,
    is_prime_helper(x, 2)
};

print(is_prime(2));
print(is_prime(3));
print(is_prime(4));
print(is_prime(5));
print(is_prime(6));
print(is_prime(7));

Progress

Click to expand
  • 2023-10-13: Just finished defining the initial complete syntax. Next is to rewrite the lexer, parser and code generator to support the new syntax.
  • 2023-10-15: Syntax has been reworked and a grammar definition can be found in [docs](docs/grammar.md). The lexer has been updated to support the new syntax and the parser has been completely rewritten as a recursive descent parser. A code generated has been implemented that can generate LLVM IR. The next steps are to implement more language features. See [milestones](#milestones) for more details.
  • 2023-10-17: Created compiler program
  • 2023-10-22: Implemented declaring and calling functions. Function calls can be used as values in an expression. The next steps will need to be refactoring and adding unit tests.
  • 2023-10-28: Re-wrote the lexer and parser to rust. Added tons of unit tests. Created an interpreter to run `.ni` files.
  • 2023-10-29: Any programming language's most important features is correctness and safety. No need for more justification.
  • 2023-10-04: Added tail-call optimization. More complex computations are now possible.
  • 2024-01-13: Simplified type system to only have 5 types.
  • 2024-01-14: Finished expression-to-AST-diagram, added more tests, added more support for arrays and improved printing.
  • 2024-02-12: Interpreter now keeps symbols in [scoped-symbols](src/scoped_symbols.rs) leading to a 10x speed improvement compared to the initial symbol table.
  • 2024-05-21: The parser has been refactored to use Results, allowing for some basic error reporting during parsing. A lot of unit and end to end tests have been added in order to ensure the correctness.
    I will take a break from this project (in order to focus on other projects) and may come back to it in the future.

Milestones

  • Define complete syntax
  • numbers
  • characters
  • booleans
  • function declaration and call
  • arrays and strings
  • built-in functions
    • print
    • matching
    • map
    • filter
    • reduce
  • importing
  • anonymous functions
  • self-host compiler
  • SOLVE ADVENT OF CODE

Tests

In order to run the tests, simply run:

cargo test

Limitations

What is this it, and what is it not? The goal is not to create the next big language that everybody should use. This is more of an experiment in making a minimal compiled functional programming language.

I will work on this in my spare time. No guarantees can be made.

Misc

C Compiler

The initial version of this language was written in C. This code has now been removed from the main branch, but can be found here.

About

A minimalistic functional programming language

License:MIT License


Languages

Language:Rust 98.4%Language:Inform 7 1.6%