work in progress
This commit is contained in:
@@ -132,7 +132,7 @@ fun adt_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to_
|
||||
}
|
||||
}
|
||||
}
|
||||
run_on_tree(helper_before, empty_pass_second_half, syntax_ast_pair.second, &visited1)
|
||||
run_on_tree(helper_before, empty_pass_second_half(), syntax_ast_pair.second, &visited1)
|
||||
})
|
||||
name_ast_map->for_each(fun(name: string, syntax_ast_pair: pair<*tree<symbol>,*ast_node>) {
|
||||
var second_helper = fun(node: *ast_node, parent_chain: *stack<*ast_node>) {
|
||||
@@ -185,7 +185,7 @@ fun adt_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to_
|
||||
}
|
||||
}
|
||||
}
|
||||
run_on_tree(second_helper, empty_pass_second_half, syntax_ast_pair.second, &visited2)
|
||||
run_on_tree(second_helper, empty_pass_second_half(), syntax_ast_pair.second, &visited2)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ fun c_line_control(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, as
|
||||
/*}*/
|
||||
/*}*/
|
||||
/*if (first)*/
|
||||
/*run_on_tree(helper, empty_pass_second_half, syntax_ast_pair.second)*/
|
||||
/*run_on_tree(helper, empty_pass_second_half(), syntax_ast_pair.second)*/
|
||||
first = false
|
||||
})
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ fun ctce_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to
|
||||
}
|
||||
}
|
||||
}
|
||||
run_on_tree(helper_before, empty_pass_second_half, syntax_ast_pair.second, &visited)
|
||||
run_on_tree(helper_before, empty_pass_second_half(), syntax_ast_pair.second, &visited)
|
||||
})
|
||||
ctce_passes.for_each(fun(func: *ast_node) {
|
||||
// don't want to pick up the ast_node::value
|
||||
|
||||
@@ -78,7 +78,7 @@ fun function_value_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node
|
||||
}
|
||||
}
|
||||
}
|
||||
run_on_tree(helper_before, empty_pass_second_half, syntax_ast_pair.second, &visited)
|
||||
run_on_tree(helper_before, empty_pass_second_half(), syntax_ast_pair.second, &visited)
|
||||
})
|
||||
println(string("there are ") + function_value_creation_points.size + " function value creation points in the program.")
|
||||
println(string("there are ") + all_types.size() + " all types in the program.")
|
||||
|
||||
@@ -27,7 +27,7 @@ fun node_counter_helper(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>
|
||||
var helper = fun(node: *ast_node, parent_chain: *stack<*ast_node>) {
|
||||
counter++
|
||||
}
|
||||
run_on_tree(helper, empty_pass_second_half, syntax_ast_pair.second, &visited)
|
||||
run_on_tree(helper, empty_pass_second_half(), syntax_ast_pair.second, &visited)
|
||||
})
|
||||
return counter
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ fun obj_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to_
|
||||
}
|
||||
}
|
||||
}
|
||||
run_on_tree(ensure_block_and_munge, empty_pass_second_half, syntax_ast_pair.second, &visited1)
|
||||
run_on_tree(ensure_block_and_munge, empty_pass_second_half(), syntax_ast_pair.second, &visited1)
|
||||
// Pass 2
|
||||
var short_circut_op: fun(*ast_node,*stack<*ast_node>,*hash_set<*ast_node>): bool = fun(node: *ast_node, parent_chain: *stack<*ast_node>, visited: *hash_set<*ast_node>): bool {
|
||||
match(*node) {
|
||||
@@ -103,15 +103,15 @@ fun obj_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to_
|
||||
add_before_in(short_circuit_if, parent_chain->from_top(enclosing_block_idx-1), parent_chain->from_top(enclosing_block_idx))
|
||||
replace_with_in(node, short_circuit_result, parent_chain)
|
||||
var shorter_tree = stack_from_vector( parent_chain->data.slice(0, parent_chain->size()-enclosing_block_idx))
|
||||
run_on_tree_helper(short_circut_op, empty_pass_second_half, short_circuit_declaration, &shorter_tree, visited)
|
||||
run_on_tree_helper(short_circut_op, empty_pass_second_half, short_circuit_if, &shorter_tree, visited)
|
||||
run_on_tree_helper(short_circut_op, empty_pass_second_half(), short_circuit_declaration, &shorter_tree, visited)
|
||||
run_on_tree_helper(short_circut_op, empty_pass_second_half(), short_circuit_if, &shorter_tree, visited)
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
run_on_tree(short_circut_op, empty_pass_second_half, syntax_ast_pair.second, &visited2)
|
||||
run_on_tree(short_circut_op, empty_pass_second_half(), syntax_ast_pair.second, &visited2)
|
||||
// Pass 3
|
||||
var construct_in_destruct_out = fun(node: *ast_node, parent_chain: *stack<*ast_node>) {
|
||||
match(*node) {
|
||||
@@ -204,7 +204,7 @@ fun obj_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to_
|
||||
}
|
||||
}
|
||||
}
|
||||
run_on_tree(empty_pass_first_half, construct_in_destruct_out, syntax_ast_pair.second, &visited3)
|
||||
run_on_tree(empty_pass_first_half(), construct_in_destruct_out, syntax_ast_pair.second, &visited3)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -418,8 +418,12 @@ fun add_after_in(to_add: *ast_node, before: *ast_node, in: *ast_node) {
|
||||
error(string("cannot add_after_in to ") + get_ast_name(in))
|
||||
}
|
||||
|
||||
fun empty_pass_first_half(node: *ast_node, parent_chain: *stack<*ast_node>, visited: *hash_set<*ast_node>): bool { return true; }
|
||||
fun empty_pass_second_half(node: *ast_node, parent_chain: *stack<*ast_node>) {}
|
||||
fun empty_pass_first_half(): fun(*ast_node, *stack<*ast_node>, *hash_set<*ast_node>): bool {
|
||||
return fun(node: *ast_node, parent_chain: *stack<*ast_node>, visited: *hash_set<*ast_node>): bool { return true; }
|
||||
}
|
||||
fun empty_pass_second_half(): fun(*ast_node, *stack<*ast_node>): void {
|
||||
return fun(node: *ast_node, parent_chain: *stack<*ast_node>) {}
|
||||
}
|
||||
fun run_on_tree(func_before: fun(*ast_node,*stack<*ast_node>):void, func_after: fun(*ast_node,*stack<*ast_node>):void, tree: *ast_node, visited: *hash_set<*ast_node>)
|
||||
run_on_tree(fun(n: *ast_node, s: *stack<*ast_node>, v: *hash_set<*ast_node>): bool {func_before(n, s);return true;}, func_after, tree, visited)
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ fun ref_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to_
|
||||
}
|
||||
}
|
||||
}
|
||||
run_on_tree(helper_before, empty_pass_second_half, syntax_ast_pair.second, &visited)
|
||||
run_on_tree(helper_before, empty_pass_second_half(), syntax_ast_pair.second, &visited)
|
||||
})
|
||||
remove_ref_type_set.for_each(fun(p: pair<string, *type>) {
|
||||
var t = p.second
|
||||
|
||||
@@ -89,6 +89,10 @@ obj stack<T> (Object, Serializable) {
|
||||
return i
|
||||
return -1
|
||||
}
|
||||
fun item_from_top_satisfying(func_raw: run(T):bool): T {
|
||||
var temp_lambda = fun(i: T):bool { return func_raw(i); }
|
||||
return item_from_top_satisfying(temp_lambda);
|
||||
}
|
||||
fun item_from_top_satisfying(func: fun(T):bool): T {
|
||||
return from_top(index_from_top_satisfying(func))
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
|
||||
fun call(f: fun(int, int):int):int {
|
||||
return f(1,2)
|
||||
}
|
||||
fun main(argc: int, argv: **char): int {
|
||||
var y = 20
|
||||
var a = fun(i: int, x: int): int { return i+x+y; }
|
||||
return a(12, 11)
|
||||
/*return a(12, 11)*/
|
||||
return call(a)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user