Loki, God of Mischief

Overview

Loki

Loki is an experimental programming language that I am building both to learn more about compilers and test ideas about language design.

Compiler Flow

graph TD
    A[Tokenize] -->|Produces Token Stream| B[Parser]
    B --> |Produces AST| C[Semantic Analyzer]
    C -->|Produces AST| D[IR Gen]
    D --> |IR| X[Semantic Analysis again]
    X --> |Produces IR| E[Target Code Generator]
    E --> |Target Project| F[Target Toolchain]
                    

Language Spec

Ideas

  • Loki code is ALWAYS just set of expressions that evaluate to a value and ALL expressions output must be captured.
  • Error handling is done through sum types, each failable function should return a union type of the output type and error type.
  • Compile time code execution is a must, both types and also values that can be evaluated at compile time.
  • Types are first class values, basically compile time constants, so types are treated just like other values.
  • Interface implementaions are implicit and will be check during semantic analysis.

Platforms

Loki tries to give same experience on all supported platforms but it's not always possible, so in the standard library and any other loki code there can be checks(comptime if) so if a certain code cannot be compiled against target compiler just removes it and if you use a code which can not be used in your target compiler will emit an error.

Interopability

Loki has a direct interface to it's host programming languages so you can call directly to their libraries and apis. Both standard library and third party ones

Build tool

Loki has it's own build tool which is a wrapper and generator for it's target build tools. It will generate necessary files and set necessary env values from your loki.yml file.

author: "amirrezaask"
name: "sample loki project"
deps:
  loki:
    - github.com/a1/lib1
  go:
    - github.com/lib/pq
You might also like...
Comments
  • 0.2

    0.2

    This branch contains a rewrite and re work of the compiler from scratch for a simpler and more robust code base. Changes:

    • State machine based parser and tokenizer
    • cleaner code base
    • applies some Data-Driven-Design concepts for less memory usage

    It's not completely implemented both in parser level and c backend.

    opened by amirrezaask 0
Owner
Amirreza Askarpour
Software Enginner, #gopher, #ziglang
Amirreza Askarpour
Rust port of the Terry Davis' (RIP) "god says" program

RIP Terry A. Davis 1969-2018 god says Rust port of the programmer Terry Davis' "god says" (AKA GodSpeaks) program. Terrence Andrew Davis (December 15,

Orhun Parmaksız 54 Dec 26, 2022
A top-down arena shooter roguelite in which you're a mythical marshmallow god fighting against peasant munchies such as chocolates, jellies, or candies!

Mythmellow A top-down arena shooter roguelite in which you're a mythical marshmallow god fighting against peasant munchies such as chocolates, jellies

Umut 3 Oct 16, 2023
A top-down arena shooter roguelite in which you're a mythical marshmallow god fighting against peasant munchies such as chocolates, jellies, or candies!

Mythmallow A top-down arena shooter roguelite in which you're a mythical marshmallow god fighting against peasant munchies such as chocolates, jellies

Umut 3 Oct 29, 2023