Basic CTCE working! In between commit because #link(a) syntax changed to #link(a)
This commit is contained in:
30
stdlib/ctce_lower.krak
Normal file
30
stdlib/ctce_lower.krak
Normal file
@@ -0,0 +1,30 @@
|
||||
import symbol:*
|
||||
import tree:*
|
||||
import vector:*
|
||||
import map:*
|
||||
import util:*
|
||||
import string:*
|
||||
import mem:*
|
||||
import io:*
|
||||
import ast_nodes:*
|
||||
import ast_transformation:*
|
||||
import interpreter:*
|
||||
|
||||
import pass_common:*
|
||||
|
||||
fun ctce_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to_syntax: *map<*ast_node, *tree<symbol>>) {
|
||||
name_ast_map->for_each(fun(name: string, syntax_ast_pair: pair<*tree<symbol>,*ast_node>) {
|
||||
var helper_before = fun(node: *ast_node, parent_chain: *stack<*ast_node>) {
|
||||
match(*node) {
|
||||
ast_node::compiler_intrinsic(backing) {
|
||||
if (backing.intrinsic == "ctce") {
|
||||
var result = evaluate_constant_expression(backing.parameters[0])
|
||||
*node = *unwrap_value(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
run_on_tree(helper_before, empty_pass_second_half, syntax_ast_pair.second)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user