Directory: lib/skc_hir
AST is converted into HIR (High-level Intermediate Representation) and then turns into LLVM IR (Low-level IR of Shiika).
The structure of HIR resembles to AST, but most important difference is that HIR has type information.
File: skc_ast2hir
This crate converts AST into HIR.
Instances of Fn
are called "lambda" in Shiika. There are two ways to create a lambda:
fn(){ ...}
(called "fn")do ... end
,{ ... }
(called "block")
A lambda can capture outer variables.
var a = 1
f = fn(){ p a }
a = 2
f() #=> prints `2`
HirLambdaExpr
contains captures
, a list of HirLambdaCapture
. To make this:
- When referring/updating a local variable defined in outer scope, save a
LambdaCapture
tocaptures
ofLambdaCtx
. - Once all exprs in a lambda are processed, convert each
LambdaCapture
toHirLambdaCapture
.