Something went wrong. Try again.
my personal programming language!
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990= Sparkle Overview== HIRThe high-level intermediate representation (HIR) is the first pass your source code goes through.Sparkle's HIR is a direct in-memory translation of your source code to known valid structures within the compiler.This section will go over the basic grammar, and how it gets parsed into HIR.
=== ExpressionsPrimary expressions are the main expression types.It includes expressions such as tuples, functions, blocks, bindings, intrinsics, values, and references.
/ Value: Values are the simplest expressions, and can be created by a value literal, which can currently either be an unsigned integer or a string. Note that string are not currently implemented, and will fail the compilation during later stages. *Example*: `123`, `1337`, `42`, `"hello world"`, `"goodbye world"`/ Mapping: Mappings are not representable in source code on their own, but they are technically expressions, and are required for defining other expressions like bindings and tuples. Mappings are created by an identifier as a name, a `:`, and an expression as a value. There is no example provided here, as mappings are not directly constructable. See tuples or bindings for examples of mappings./ Tuple: Tuples are named aggregates of of expressions, allowing complex and arbitrary data structures to be expressed. Tuples are created by using `<`, followed by any amount of mappings, then followed by `>`. *Example*: `<>`, `<my_name: 123>`, `<my_first_name: <nested: 456> my_second_name: "hello!">`/ Binding: Bindings, or "variables" assign a name to a value, allowing the value to be used later. Bindings are created by a kind (either `local` or `global`), followed by a mapping. *Example*: `local my_name: 123`, `global my_global: "goodbye!"`/ Block: Blocks are a group of expressions, followed by a final expression as a result. They're usually used to isolate lexical scopes, and as a visual and semantic separator (similar to parentheses in mathematics). Blocks can be created with a `{`, followed by at least one expression, followed by a `}`. *Example*: `{ 123 }`, `{ 123 456 "final value" }`/ Function: Functions are delayed computations that consume a single parameter and return a single expression. Functions are created by using the `fn` keyword, followed by `(`, a identifier as a parameter, a `)`, and finally the function body expression. *Example*: `fn(x) x`, `fn(_) 456`/ Application: Function applications invoke (or "call") function expressions with a single parameter. Applications can be created by an expression as the function, followed by `(`, followed by an expression as the argument, and finally a `)`. *Example*: `{ fn(_) 123 }(<>)`/ Intrinsic: Intrinsics are special functions defined by the compiler itself. Intrinsics cannot be defined by users, and cannot be used as values. Intrinsics can be created by a `~`, followed by an identifier as the intrinsic to be called, and finally an application. *Example*: `~add(<left: 123 right: 456>)`, `~trap(<>)`/ Reference: References fetch the value stored within a binding. References can be created simply by an identifier. *Example*: `{ local x: 123 x }`, `{ global x: 456 global y: x y }`/ Projection: Projections fetch (or project) the value stored in a mapping out of a tuple. Projections can be created by an expression as the tuple, a `.`, followed by an identifier as the name of the mapping to project. *Example*: `<a: 1 b: 2 c: 3>.a`, `<x: "string">.x`
=== Symbols & ScopesSymbols are abstract identifiers that map bindings to memory locations. They are created via *binding expressions* or *parameter expressions*, where the identifier serves as the lookup key for the symbol.Scopes are organized into a hierarchical tree.A new scope is pushed onto the stack either explicitly from a block expression,or implicitly within the body of a function, or during initialization of a binding's value.
Symbols are categorized into two kinds, determining their visibility within the scope, and how they interact with other symbols.- *Local*: Local symbols are created by either a `local` binding or a function parameter. They're visible from the declaration point onwards, until either the end of the scope or the symbol name is shadowed.- *Global*: Global symbols are created from `global` bindings, and are visible throughout their entire enclosing scope. This allows for references to globals that don't follow lexical order, and mutual recursion between globals. Global names cannot be shadowed under any circumstances, they must be unique within all scopes where the symbol is visible.
The following visualization shows the iteractions between local/global symbols, scopes, and references:```{ # scope 1 # { # scope 2 # local b # local symbol named b # a # reference to a from scope 1 # b # reference to b from scope 2 #
{ # scope 3 # local b # local symbol named b, shadows the previous b # b # reference to b from scope 3 # c # reference to c from scope 2 # }
{ # scope 4 # b # reference to b from scope 2 # }
global c # global symbol named c, visible across the entire scope # }
global a # global symbol named c, visible across the entire scope #}```
=== Types// TODO
== MIR// TODO
== WASM// TODO