Treat assignment like other operators
This commit is contained in:
22
k.krak
22
k.krak
@@ -131,6 +131,23 @@ fun main(argc: int, argv: **char): int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// cute hack for getting plain =
|
||||||
|
math.add(str(""))
|
||||||
|
for (var i = 0; i < math.size; i++;) {
|
||||||
|
primitive_ops["op" + math[i] + "="] = vec<*tree<ast>>()
|
||||||
|
for (var j = 0; j < number_tower.size; j++;) {
|
||||||
|
for (var k = 0; k <= j; k++;) {
|
||||||
|
var return_type = null<binding<type>>()
|
||||||
|
primitive_ops["op" + math[i] + "="].add(_compiler_intrinsic(math[i] + "=", binding(type(base_type::_fun(make_triple(make_pair(vec(
|
||||||
|
number_tower[j],
|
||||||
|
number_tower[k]
|
||||||
|
),
|
||||||
|
binding(type(base_type::_void(), 0, false))
|
||||||
|
), false, false)), 0, false)), vec<*binding<type>>()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
math.remove(math.size-1)
|
||||||
|
|
||||||
// resolves all binding possibilities for one top level item
|
// resolves all binding possibilities for one top level item
|
||||||
passes[str("name_possibility_resolve")] = fun(item: *tree<ast>) {
|
passes[str("name_possibility_resolve")] = fun(item: *tree<ast>) {
|
||||||
@@ -253,7 +270,6 @@ fun main(argc: int, argv: **char): int {
|
|||||||
}
|
}
|
||||||
error("Trying to get type of call where type of first child is not function, but " + t->bound_to->to_string())
|
error("Trying to get type of call where type of first child is not function, but " + t->bound_to->to_string())
|
||||||
}
|
}
|
||||||
/*ast::_compiler_intrinsic(b) return str("_compiler_intrinsic(") + b.first + ")"*/
|
|
||||||
ast::_cast(b) return b
|
ast::_cast(b) return b
|
||||||
ast::_value(b) return b.second
|
ast::_value(b) return b.second
|
||||||
}
|
}
|
||||||
@@ -283,7 +299,6 @@ fun main(argc: int, argv: **char): int {
|
|||||||
match (t->data) {
|
match (t->data) {
|
||||||
ast::_declaration() if (t->children.size > 1)
|
ast::_declaration() if (t->children.size > 1)
|
||||||
unify(get_type(t->children[0]), get_type(t->children[1]))
|
unify(get_type(t->children[0]), get_type(t->children[1]))
|
||||||
/*ast::_assignment() unify(get_type(t->children[0]), get_type(t->children[1]))*/
|
|
||||||
ast::_call() {
|
ast::_call() {
|
||||||
// we call get type to make sure if it is unknown it is transformed into a function version
|
// we call get type to make sure if it is unknown it is transformed into a function version
|
||||||
get_type(t)
|
get_type(t)
|
||||||
@@ -542,7 +557,6 @@ fun main(argc: int, argv: **char): int {
|
|||||||
C_declaration_str += idt + to_c_type(t->children[0]->data._identifier.second) + " " + get_c_name(t->children[0]) + ";\n"
|
C_declaration_str += idt + to_c_type(t->children[0]->data._identifier.second) + " " + get_c_name(t->children[0]) + ";\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::_assignment() { error("assignment gen unimplemented"); }
|
|
||||||
ast::_block() {
|
ast::_block() {
|
||||||
C_str += idt + "{\n"
|
C_str += idt + "{\n"
|
||||||
t->children.for_each(fun(c: *tree<ast>) {
|
t->children.for_each(fun(c: *tree<ast>) {
|
||||||
@@ -805,7 +819,7 @@ fun syntax_to_ast(file_name: str, syntax: *tree<symbol>, import_paths: ref vec<s
|
|||||||
children += get_nodes("boolean_expression", syntax).map(syntax_to_ast_helper)
|
children += get_nodes("boolean_expression", syntax).map(syntax_to_ast_helper)
|
||||||
return _declaration(children)
|
return _declaration(children)
|
||||||
} else if (syntax->data.name == "assignment_statement")
|
} else if (syntax->data.name == "assignment_statement")
|
||||||
return _assignment(vec(make_ast_binding(concat(syntax->children[1])),
|
return _call(vec(make_ast_binding("op" + concat(syntax->children[1])),
|
||||||
syntax_to_ast_helper(syntax->children[0]),
|
syntax_to_ast_helper(syntax->children[0]),
|
||||||
syntax_to_ast_helper(syntax->children[2])))
|
syntax_to_ast_helper(syntax->children[2])))
|
||||||
else if (syntax->data.name == "function_call")
|
else if (syntax->data.name == "function_call")
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ adt ast {
|
|||||||
_function: triple<str, *binding<type>, bool>,
|
_function: triple<str, *binding<type>, bool>,
|
||||||
_template: pair<str, set<str>>,
|
_template: pair<str, set<str>>,
|
||||||
_declaration,
|
_declaration,
|
||||||
_assignment,
|
|
||||||
_block,
|
_block,
|
||||||
_if,
|
_if,
|
||||||
_match,
|
_match,
|
||||||
@@ -43,7 +42,6 @@ fun to_string(a: ref ast): str {
|
|||||||
ast::_function(b) return str("_function(") + b.first + ": " + deref_to_string(b.second->bound_to) + ", ext?:" + to_string(b.third) + ")"
|
ast::_function(b) return str("_function(") + b.first + ": " + deref_to_string(b.second->bound_to) + ", ext?:" + to_string(b.third) + ")"
|
||||||
ast::_template(b) return str("_template(") + b.first + "[" + str(",").join(b.second.data) + "])"
|
ast::_template(b) return str("_template(") + b.first + "[" + str(",").join(b.second.data) + "])"
|
||||||
ast::_declaration() return str("_declaration")
|
ast::_declaration() return str("_declaration")
|
||||||
ast::_assignment() return str("_assignment")
|
|
||||||
ast::_block() return str("_block")
|
ast::_block() return str("_block")
|
||||||
ast::_if() return str("_if")
|
ast::_if() return str("_if")
|
||||||
ast::_match() return str("_match")
|
ast::_match() return str("_match")
|
||||||
@@ -96,9 +94,6 @@ fun _value(p1: str, p2: *binding<type>): *tree<ast> {
|
|||||||
fun _declaration(): *tree<ast> {
|
fun _declaration(): *tree<ast> {
|
||||||
return new<tree<ast>>()->construct(ast::_declaration())
|
return new<tree<ast>>()->construct(ast::_declaration())
|
||||||
}
|
}
|
||||||
fun _assignment(): *tree<ast> {
|
|
||||||
return new<tree<ast>>()->construct(ast::_assignment())
|
|
||||||
}
|
|
||||||
fun _block(): *tree<ast> {
|
fun _block(): *tree<ast> {
|
||||||
return new<tree<ast>>()->construct(ast::_block())
|
return new<tree<ast>>()->construct(ast::_block())
|
||||||
}
|
}
|
||||||
@@ -171,9 +166,6 @@ fun _value(p1: str, p2: *binding<type>, c: ref vec<*tree<ast>>): *tree<ast> {
|
|||||||
fun _declaration(c: ref vec<*tree<ast>>): *tree<ast> {
|
fun _declaration(c: ref vec<*tree<ast>>): *tree<ast> {
|
||||||
return new<tree<ast>>()->construct(ast::_declaration(), c)
|
return new<tree<ast>>()->construct(ast::_declaration(), c)
|
||||||
}
|
}
|
||||||
fun _assignment(c: ref vec<*tree<ast>>): *tree<ast> {
|
|
||||||
return new<tree<ast>>()->construct(ast::_assignment(), c)
|
|
||||||
}
|
|
||||||
fun _block(c: ref vec<*tree<ast>>): *tree<ast> {
|
fun _block(c: ref vec<*tree<ast>>): *tree<ast> {
|
||||||
return new<tree<ast>>()->construct(ast::_block(), c)
|
return new<tree<ast>>()->construct(ast::_block(), c)
|
||||||
}
|
}
|
||||||
@@ -219,7 +211,6 @@ fun is_adt_def(i: *tree<ast>): bool { match(i->data) { ast::_adt_def(b) return t
|
|||||||
fun is_function(i: *tree<ast>): bool { match(i->data) { ast::_function(b) return true; } return false; }
|
fun is_function(i: *tree<ast>): bool { match(i->data) { ast::_function(b) return true; } return false; }
|
||||||
fun is_template(i: *tree<ast>): bool { match(i->data) { ast::_template(b) return true; } return false; }
|
fun is_template(i: *tree<ast>): bool { match(i->data) { ast::_template(b) return true; } return false; }
|
||||||
fun is_declaration(i: *tree<ast>): bool { match(i->data) { ast::_declaration() return true; } return false; }
|
fun is_declaration(i: *tree<ast>): bool { match(i->data) { ast::_declaration() return true; } return false; }
|
||||||
fun is_assignment(i: *tree<ast>): bool { match(i->data) { ast::_assignment() return true; } return false; }
|
|
||||||
fun is_block(i: *tree<ast>): bool { match(i->data) { ast::_block() return true; } return false; }
|
fun is_block(i: *tree<ast>): bool { match(i->data) { ast::_block() return true; } return false; }
|
||||||
fun is_if(i: *tree<ast>): bool { match(i->data) { ast::_if() return true; } return false; }
|
fun is_if(i: *tree<ast>): bool { match(i->data) { ast::_if() return true; } return false; }
|
||||||
fun is_match(i: *tree<ast>): bool { match(i->data) { ast::_match() return true; } return false; }
|
fun is_match(i: *tree<ast>): bool { match(i->data) { ast::_match() return true; } return false; }
|
||||||
|
|||||||
Reference in New Issue
Block a user