All Projects → vain0x → milone-lang

vain0x / milone-lang

Licence: Apache-2.0 license
Self-hosting F#-subset compiler

Programming Languages

F#
602 projects
shell
77523 projects
c
50402 projects - #5 most used programming language
Makefile
30231 projects
C++
36643 projects - #6 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to milone-lang

Feminist-Chatbot
chatbots can easily reinforce harmful gender stereotypes or promote discriminatory behaviour if their designers aren't careful.
Stars: ✭ 18 (-53.85%)
Mutual labels:  hobby
AhnTri
Super-simple OS
Stars: ✭ 54 (+38.46%)
Mutual labels:  hobby
ShawnOS
A Basic x86 Operating System/Kernel
Stars: ✭ 39 (+0%)
Mutual labels:  hobby
MeetixOS
An hobby OS written in modern C++20 which aims to be Unix-like. Currently based on EvangelionNG, a GhostOS derived kernel
Stars: ✭ 179 (+358.97%)
Mutual labels:  hobby

milone-lang

milone-lang is an F#-subset programming language.

About

History: The initial goal of the project was self-hosting. That is, I just wanted to write a compiler that can compile the compiler itself. I achieved the goal at v0.1.0.

Current: I'm working toward initial release.

Remarks: This is a hobby project. Don't use in production. Issues and pull requests are welcome. Feel free to ask anything in discussions or something.

Install

Install from sources on Linux

Prerequisites:

  • Ubuntu 18.04 (or similar platform)
  • Install .NET SDK 5
  • Install GNU make
  • Install GCC 7.5.0
  • Install busybox, which is likely pre-installed, by: apt install -y busybox-static

Do:

# Download the source code.
git clone 'https://github.com/vain0x/milone-lang' --filter=blob:none

# Build and install.
cd milone-lang
make install
  • To uninstall, do make uninstall.

Install from binary package on Windows

Prerequisites:

  • Windows 10
  • Install MSBuild.exe in some way:

Instructions:

See also docs/binary_package.md.

Install VSCode Extension

See ./vscode_ext


How It Works

Currently the target language is C. That is, the milone-lang compiler reads a source code and translates to a C code. For example, assume the following code is given.

let main _ =
  let rec factorial x =
    if x = 0 then 1 else x * factorial (x - 1)
  factorial 5 - 120 // exit code

Then the output is a C code that looks like the following.

int factorial(int x) {
    if (x == 0) {
        return 1;
    } else {
        return x * factorial(x - 1);
    }
}

int main() {
    return factorial(5) - 120;
}

The actual output is available at factorial.c.

The diagram below illustrates how it does self-host finally.

    <milone-lang compiler>.fs
        |                | Compile with F# compiler
        |                v
        | Compile with <milone-lang compiler>.exe
        v                           ^ an executable on .NET runtime
    <milone-lang compiler>.c
        | Compile with C compiler
        v
    <milone-lang compiler>.exe
                 ^ a native executable

Features

Not all of F# features are supported. Features for functional-style programming are selected to write a compiler easily.

  • Compile a CLI application (no libraries)
  • Expressions
    • Literals: 42, 3.14, "str", """raw str"""
    • Operations: a + b, s.[i], h :: t, (x, y), etc.
    • Function calls: f x y and y |> f x
    • Function definitions: let f x y = .. and fun x y -> ..
    • Pattern matching
  • Functions
    • Mutual recursion
    • Local variable capturing
    • Partial applications
    • Function objects
  • Types
    • Polymorphic type inference
    • Primitive types: int, float, string, tuples, lists, functions, etc.
    • Discriminated unions (non-generic ones only)
    • Records (non-generic ones only)
  • IO
    • printfn (%s, %d, %f only)

See also:

License

Milone-lang tools (compiler and LSP server) are distributed under either:

  • the Apache 2.0 license, or
  • the MIT license.

Others including documentation, examples, libraries, runtime code, scripts, tests, etc. are distributed under CC0-1.0.

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].