Port many tests and fix small bugs revealed in Kalypso (passes 24/72) - tests have also revealed more extensive features not yet implemented, and I seem to have messed up a test or two so that the C++ version also fails a couple more (it's at 59/71 now). Will investigate
This commit is contained in:
@@ -309,7 +309,10 @@ fun transform_value(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||
}
|
||||
}
|
||||
if (contains_dot)
|
||||
value_type = type_ptr(base_type::double_precision()) //value_type = type_ptr(base_type::floating())
|
||||
if (value_str[value_str.length()-1] == 'f')
|
||||
value_type = type_ptr(base_type::floating()) //value_type = type_ptr(base_type::floating())
|
||||
else
|
||||
value_type = type_ptr(base_type::double_precision()) //value_type = type_ptr(base_type::floating())
|
||||
else
|
||||
value_type = type_ptr(base_type::integer())
|
||||
}
|
||||
@@ -418,7 +421,10 @@ fun transform_for_loop(node: *tree<symbol>, scope: *ast_node, template_replaceme
|
||||
return for_loop
|
||||
}
|
||||
fun transform_return_statement(node: *tree<symbol>, scope: *ast_node, template_replacements: map<string, *type>): *ast_node {
|
||||
return ast_return_statement_ptr(transform(node->children[0], scope, template_replacements))
|
||||
var return_value = get_node("boolean_expression", node)
|
||||
if (return_value)
|
||||
return ast_return_statement_ptr(transform(return_value, scope, template_replacements))
|
||||
return ast_return_statement_ptr(null<ast_node>())
|
||||
}
|
||||
fun transform_branching_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||
if (node->data.name == "break_statement")
|
||||
@@ -485,11 +491,13 @@ fun transform_expression(node: *tree<symbol>, scope: *ast_node, searching_for: s
|
||||
return ast_function_call_ptr(get_builtin_function(func_name, parameter_types), parameters)
|
||||
}
|
||||
fun get_builtin_function(name: string, param_types: vector<*type>): *ast_node {
|
||||
if (name == "." || name == "->")
|
||||
if (name == "==" || name == "!=" || name == ">" || name == "<" || name == "<=" || name == ">" || name == ">=" || name == "&&" || name == "||" || name == "!")
|
||||
return ast_function_ptr(name, type_ptr(param_types, type_ptr(base_type::boolean())), vector<*ast_node>())
|
||||
if (name == "." || name == "->" || name == "[")
|
||||
return ast_function_ptr(name, type_ptr(param_types, param_types[1]), vector<*ast_node>())
|
||||
if (name == "&")
|
||||
return ast_function_ptr(name, type_ptr(param_types, param_types[0]->clone_with_increased_indirection()), vector<*ast_node>())
|
||||
if (name == "\\*")
|
||||
if (name == "\*")
|
||||
return ast_function_ptr(name, type_ptr(param_types, param_types[0]->clone_with_decreased_indirection()), vector<*ast_node>())
|
||||
if (param_types.size > 1 && param_types[1]->rank() > param_types[0]->rank())
|
||||
return ast_function_ptr(name, type_ptr(param_types, param_types[1]), vector<*ast_node>())
|
||||
|
||||
@@ -88,7 +88,7 @@ obj c_generator (Object) {
|
||||
}
|
||||
fun destruct() {
|
||||
}
|
||||
fun get_id(): string return to_string(id_counter++);
|
||||
fun get_id(): string return to_string(id_counter++);
|
||||
fun generate_c(name_ast_map: map<string, pair<*tree<symbol>,*ast_node>>): pair<string,string> {
|
||||
var linker_string:string = ""
|
||||
var prequal: string = "#include <stdbool.h>\n#include <stdlib.h>\n#include <stdio.h>\n"
|
||||
@@ -164,6 +164,11 @@ obj c_generator (Object) {
|
||||
}
|
||||
ast_node::type_def(backing) {
|
||||
type_poset.add_vertex(child)
|
||||
backing.variables.for_each(fun(i: *ast_node) {
|
||||
var var_type = get_ast_type(i->declaration_statement.identifier)
|
||||
if (!var_type->indirection && var_type->type_def)
|
||||
type_poset.add_relationship(child, var_type->type_def)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -244,6 +249,8 @@ obj c_generator (Object) {
|
||||
}
|
||||
fun generate_return_statement(node: *ast_node, enclosing_object: *ast_node, defer_stack: *stack<pair<bool,stack<*ast_node>>>): code_triple {
|
||||
var return_value = node->return_statement.return_value
|
||||
if (!return_value)
|
||||
return code_triple("return")
|
||||
var return_value_type = get_ast_type(return_value)
|
||||
var to_ret = code_triple()
|
||||
// if we're returning an object, copy_construct a new one to return
|
||||
@@ -333,12 +340,14 @@ obj c_generator (Object) {
|
||||
var parameters = node->function_call.parameters
|
||||
if ( parameters.size == 2 && (func_name == "+" || func_name == "-" || func_name == "*" || func_name == "/" || func_name == "||"
|
||||
|| func_name == "&&" || func_name == "<" || func_name == ">" || func_name == "<=" || func_name == ">="
|
||||
|| func_name == "==" || func_name == "%"
|
||||
|| func_name == "==" || func_name == "!=" || func_name == "%"
|
||||
))
|
||||
return code_triple("(") + generate(parameters[0], enclosing_object, null<stack<pair<bool,stack<*ast_node>>>>()) + func_name + generate(parameters[1], enclosing_object, null<stack<pair<bool,stack<*ast_node>>>>()) + string(")")
|
||||
// don't propegate enclosing function down right of access
|
||||
if (func_name == "." || func_name == "->")
|
||||
return code_triple("(") + generate(parameters[0], enclosing_object, null<stack<pair<bool,stack<*ast_node>>>>()) + func_name + generate(parameters[1], null<ast_node>(), null<stack<pair<bool,stack<*ast_node>>>>()) + string(")")
|
||||
if (func_name == "[")
|
||||
return code_triple("(") + generate(parameters[0], enclosing_object, null<stack<pair<bool,stack<*ast_node>>>>()) + "[" + generate(parameters[1], null<ast_node>(), null<stack<pair<bool,stack<*ast_node>>>>()) + string("])")
|
||||
// the post ones need to be post-ed specifically, and take the p off
|
||||
if (func_name == "++p" || func_name == "--p")
|
||||
return code_triple("(") + generate(parameters[0], enclosing_object, null<stack<pair<bool,stack<*ast_node>>>>()) + ")" + func_name.slice(0,-2)
|
||||
@@ -368,7 +377,7 @@ obj c_generator (Object) {
|
||||
}
|
||||
})
|
||||
if (func_return_type->is_object() && func_return_type->indirection == 0 && has_method(func_return_type->type_def, "destruct", vector<*type>())) {
|
||||
// kind of ugly combo here of
|
||||
// kind of ugly combo here of
|
||||
var temp_ident = ast_identifier_ptr(string("temporary_return")+get_id(), func_return_type)
|
||||
var declaration = ast_declaration_statement_ptr(temp_ident, null<ast_node>())
|
||||
// have to pass false to the declaration generator, so can't do it through generate_statement
|
||||
|
||||
@@ -50,10 +50,12 @@ obj importer (Object) {
|
||||
println("**Fourth Pass**")
|
||||
name_ast_map.for_each(fun(name: string, tree_pair: pair<*tree<symbol>, *ast_node>) ast_pass.fourth_pass(tree_pair.first, tree_pair.second);)
|
||||
|
||||
/*
|
||||
name_ast_map.for_each(fun(name: string, tree_pair: pair<*tree<symbol>, *ast_node>) {
|
||||
print("writing ast for: "); println(name)
|
||||
write_file(name + ".ast.dot", ast_to_dot(tree_pair.second))
|
||||
})
|
||||
*/
|
||||
|
||||
return to_ret
|
||||
}
|
||||
@@ -74,11 +76,11 @@ obj importer (Object) {
|
||||
})
|
||||
var parse_tree = parse.parse_input(file, file_name)
|
||||
print("post-parse: "); println(file_name)
|
||||
write_file(file_name + ".parse.dot", syntax_tree_to_dot(parse_tree))
|
||||
/*write_file(file_name + ".parse.dot", syntax_tree_to_dot(parse_tree))*/
|
||||
print("pre-trim: "); println(file_name)
|
||||
trim(parse_tree)
|
||||
print("post-trim: "); println(file_name)
|
||||
write_file(file_name + ".trimmed_parse.dot", syntax_tree_to_dot(parse_tree))
|
||||
/*write_file(file_name + ".trimmed_parse.dot", syntax_tree_to_dot(parse_tree))*/
|
||||
print("pre-first-ast: "); println(file_name)
|
||||
var ast = ast_pass.first_pass(file_name, parse_tree, this)
|
||||
print("post-first-ast: "); println(file_name)
|
||||
|
||||
Reference in New Issue
Block a user