Added automatic distructor calling for going out of scope, found out that += is broken (and just comes through as =)
This commit is contained in:
1 parent
da38ae03ed
commit
6f1f31a212
5 files changed
+85
-63
No files matched your search
@@ -338,8 +338,8 @@ obj code_block (Object) {
|
|||||||
return children == other.children && scope == other.scope
|
return children == other.children && scope == other.scope
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun ast_statement_ptr(): *ast_node {
|
fun ast_statement_ptr(child: *ast_node): *ast_node {
|
||||||
var to_ret.construct(): statement
|
var to_ret.construct(child): statement
|
||||||
var ptr = new<ast_node>()
|
var ptr = new<ast_node>()
|
||||||
ptr->copy_construct(&ast_node::statement(to_ret))
|
ptr->copy_construct(&ast_node::statement(to_ret))
|
||||||
return ptr
|
return ptr
|
||||||
@@ -353,9 +353,10 @@ fun is_statement(node: *ast_node): bool {
|
|||||||
obj statement (Object) {
|
obj statement (Object) {
|
||||||
var scope: map<string, vector<*ast_node>>
|
var scope: map<string, vector<*ast_node>>
|
||||||
var child: *ast_node
|
var child: *ast_node
|
||||||
fun construct(): *statement {
|
fun construct(child_in: *ast_node): *statement {
|
||||||
child = null<ast_node>()
|
child = null<ast_node>()
|
||||||
scope.construct()
|
scope.construct()
|
||||||
|
child = child_in
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
fun copy_construct(old: *statement) {
|
fun copy_construct(old: *statement) {
|
||||||
|
|||||||
@@ -160,7 +160,9 @@ obj ast_transformation (Object) {
|
|||||||
fun fourth_pass(parse_tree: *tree<symbol>, translation_unit: *ast_node) {
|
fun fourth_pass(parse_tree: *tree<symbol>, translation_unit: *ast_node) {
|
||||||
println(string("Fourth Pass for ") + translation_unit->translation_unit.name)
|
println(string("Fourth Pass for ") + translation_unit->translation_unit.name)
|
||||||
}
|
}
|
||||||
fun transform_type(node: *tree<symbol>, scope: *ast_node, template_replacements: map<string, *type>): *type {
|
}
|
||||||
|
|
||||||
|
fun transform_type(node: *tree<symbol>, scope: *ast_node, template_replacements: map<string, *type>): *type {
|
||||||
// check for references and step down
|
// check for references and step down
|
||||||
// always get to pre-reffed level
|
// always get to pre-reffed level
|
||||||
var real_node = get_node("pre_reffed", node)
|
var real_node = get_node("pre_reffed", node)
|
||||||
@@ -199,11 +201,9 @@ obj ast_transformation (Object) {
|
|||||||
println("No objects in lookup, returning none")
|
println("No objects in lookup, returning none")
|
||||||
return type_ptr(base_type::none(), indirection)
|
return type_ptr(base_type::none(), indirection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree<ASTData>* scope, std::vector<Type> types, bool limitToFunction, std::map<std::string, Type*> templateTypeReplacements) {*/
|
fun transform(node: *tree<symbol>, scope: *ast_node): *ast_node return transform(node, scope, search_type::none())
|
||||||
fun transform(node: *tree<symbol>, scope: *ast_node): *ast_node return transform(node, scope, search_type::none())
|
fun transform(node: *tree<symbol>, scope: *ast_node, searching_for: search_type): *ast_node {
|
||||||
|
|
||||||
fun transform(node: *tree<symbol>, scope: *ast_node, searching_for: search_type): *ast_node {
|
|
||||||
var name = node->data.name
|
var name = node->data.name
|
||||||
if (name == "identifier" || name == "scoped_identifier") {
|
if (name == "identifier" || name == "scoped_identifier") {
|
||||||
return transform_identifier(node, scope, searching_for)
|
return transform_identifier(node, scope, searching_for)
|
||||||
@@ -249,11 +249,11 @@ obj ast_transformation (Object) {
|
|||||||
}
|
}
|
||||||
print("FAILED TO TRANSFORM: "); print(name + ": "); println(concat_symbol_tree(node))
|
print("FAILED TO TRANSFORM: "); print(name + ": "); println(concat_symbol_tree(node))
|
||||||
return null<ast_node>()
|
return null<ast_node>()
|
||||||
}
|
}
|
||||||
fun transform_all(nodes: vector<*tree<symbol>>, scope: *ast_node): vector<*ast_node> {
|
fun transform_all(nodes: vector<*tree<symbol>>, scope: *ast_node): vector<*ast_node> {
|
||||||
return nodes.map(fun(node: *tree<symbol>): *ast_node return transform(node, scope);)
|
return nodes.map(fun(node: *tree<symbol>): *ast_node return transform(node, scope);)
|
||||||
}
|
}
|
||||||
fun transform_identifier(node: *tree<symbol>, scope: *ast_node, searching_for: search_type): *ast_node {
|
fun transform_identifier(node: *tree<symbol>, scope: *ast_node, searching_for: search_type): *ast_node {
|
||||||
// first, we check for and generate this
|
// first, we check for and generate this
|
||||||
var name = concat_symbol_tree(node)
|
var name = concat_symbol_tree(node)
|
||||||
if (name == "this") {
|
if (name == "this") {
|
||||||
@@ -266,8 +266,8 @@ obj ast_transformation (Object) {
|
|||||||
}
|
}
|
||||||
println("FAILED SEARCH FOR")
|
println("FAILED SEARCH FOR")
|
||||||
return null<ast_node>()
|
return null<ast_node>()
|
||||||
}
|
}
|
||||||
fun transform_value(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
fun transform_value(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||||
var value_str = concat_symbol_tree(node)
|
var value_str = concat_symbol_tree(node)
|
||||||
var value_type = null<type>()
|
var value_type = null<type>()
|
||||||
if (value_str[0] == '"')
|
if (value_str[0] == '"')
|
||||||
@@ -289,31 +289,27 @@ obj ast_transformation (Object) {
|
|||||||
value_type = type_ptr(base_type::integer())
|
value_type = type_ptr(base_type::integer())
|
||||||
}
|
}
|
||||||
return ast_value_ptr(value_str, value_type)
|
return ast_value_ptr(value_str, value_type)
|
||||||
}
|
}
|
||||||
fun transform_code_block(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
fun transform_code_block(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||||
var new_block = ast_code_block_ptr()
|
var new_block = ast_code_block_ptr()
|
||||||
add_to_scope("~enclosing_scope", scope, new_block)
|
add_to_scope("~enclosing_scope", scope, new_block)
|
||||||
new_block->code_block.children = transform_all(node->children, new_block)
|
new_block->code_block.children = transform_all(node->children, new_block)
|
||||||
return new_block
|
return new_block
|
||||||
}
|
}
|
||||||
fun transform_if_comp(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
fun transform_if_comp(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||||
var new_if_comp = ast_if_comp_ptr()
|
var new_if_comp = ast_if_comp_ptr()
|
||||||
new_if_comp->if_comp.wanted_generator = concat_symbol_tree(get_node("identifier", node))
|
new_if_comp->if_comp.wanted_generator = concat_symbol_tree(get_node("identifier", node))
|
||||||
new_if_comp->if_comp.statement = transform_statement(get_node("statement", node), scope)
|
new_if_comp->if_comp.statement = transform_statement(get_node("statement", node), scope)
|
||||||
return new_if_comp
|
return new_if_comp
|
||||||
}
|
}
|
||||||
fun transform_simple_passthrough(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
fun transform_simple_passthrough(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||||
var new_passthrough = ast_simple_passthrough_ptr()
|
var new_passthrough = ast_simple_passthrough_ptr()
|
||||||
// setup passthrough params and string
|
// setup passthrough params and string
|
||||||
new_passthrough->simple_passthrough.passthrough_str = concat_symbol_tree(get_node("triple_quoted_string", node)).slice(3,-4)
|
new_passthrough->simple_passthrough.passthrough_str = concat_symbol_tree(get_node("triple_quoted_string", node)).slice(3,-4)
|
||||||
return new_passthrough
|
return new_passthrough
|
||||||
}
|
}
|
||||||
fun transform_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
fun transform_statement(node: *tree<symbol>, scope: *ast_node): *ast_node return ast_statement_ptr(transform(node->children[0], scope));
|
||||||
var new_statement = ast_statement_ptr()
|
fun transform_declaration_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||||
new_statement->statement.child = transform(node->children[0], scope)
|
|
||||||
return new_statement
|
|
||||||
}
|
|
||||||
fun transform_declaration_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
||||||
// this might have an init position method call
|
// this might have an init position method call
|
||||||
var identifiers = get_nodes("identifier", node)
|
var identifiers = get_nodes("identifier", node)
|
||||||
var name = concat_symbol_tree(identifiers[0])
|
var name = concat_symbol_tree(identifiers[0])
|
||||||
@@ -335,17 +331,31 @@ obj ast_transformation (Object) {
|
|||||||
if (identifiers.size == 2) {
|
if (identifiers.size == 2) {
|
||||||
var method = transform(identifiers[1], ident_type->type_def)
|
var method = transform(identifiers[1], ident_type->type_def)
|
||||||
var parameters = get_nodes("parameter", node).map(fun(child: *tree<symbol>): *ast_node return transform(get_node("boolean_expression", child), scope);)
|
var parameters = get_nodes("parameter", node).map(fun(child: *tree<symbol>): *ast_node return transform(get_node("boolean_expression", child), scope);)
|
||||||
var method_access = ast_function_call_ptr(get_builtin_function(string("."), vector(ident_type, get_ast_type(method))), vector(identifier, method))
|
declaration->declaration_statement.init_method_call = make_method_call(identifier, method, parameters)
|
||||||
declaration->declaration_statement.init_method_call = ast_function_call_ptr(method_access, parameters)
|
|
||||||
}
|
}
|
||||||
add_to_scope(name, identifier, scope)
|
add_to_scope(name, identifier, scope)
|
||||||
return declaration
|
return declaration
|
||||||
}
|
}
|
||||||
fun transform_assignment_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
fun has_method(object: *ast_node, name: *char, parameter_types: vector<*type>): bool return has_method(object, string(name), parameter_types);
|
||||||
|
fun has_method(object: *ast_node, name: string, parameter_types: vector<*type>): bool {
|
||||||
|
return function_lookup(name, object, parameter_types) || false
|
||||||
|
}
|
||||||
|
fun make_method_call(object_ident: *ast_node, name: *char, parameters: vector<*ast_node>): *ast_node return make_method_call(object_ident, string(name), parameters);
|
||||||
|
fun make_method_call(object_ident: *ast_node, name: string, parameters: vector<*ast_node>): *ast_node {
|
||||||
|
var method = function_lookup(name, get_ast_type(object_ident)->type_def, parameters.map(fun(param: *ast_node): *type return get_ast_type(param);))
|
||||||
|
print("Here is the Method: ")
|
||||||
|
println(method)
|
||||||
|
return make_method_call(object_ident, method, parameters)
|
||||||
|
}
|
||||||
|
fun make_method_call(object_ident: *ast_node, method: *ast_node, parameters: vector<*ast_node>): *ast_node {
|
||||||
|
var method_access = ast_function_call_ptr(get_builtin_function(string("."), vector(get_ast_type(object_ident), get_ast_type(method))), vector(object_ident, method))
|
||||||
|
return ast_function_call_ptr(method_access, parameters)
|
||||||
|
}
|
||||||
|
fun transform_assignment_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||||
var assignment = ast_assignment_statement_ptr(transform(get_node("factor", node), scope), transform(get_node("boolean_expression", node), scope))
|
var assignment = ast_assignment_statement_ptr(transform(get_node("factor", node), scope), transform(get_node("boolean_expression", node), scope))
|
||||||
return assignment
|
return assignment
|
||||||
}
|
}
|
||||||
fun transform_if_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
fun transform_if_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||||
var if_statement = ast_if_statement_ptr(transform_expression(get_node("boolean_expression", node), scope))
|
var if_statement = ast_if_statement_ptr(transform_expression(get_node("boolean_expression", node), scope))
|
||||||
// one variable declarations might be in a code_block-less if statement
|
// one variable declarations might be in a code_block-less if statement
|
||||||
add_to_scope("~enclosing_scope", scope, if_statement)
|
add_to_scope("~enclosing_scope", scope, if_statement)
|
||||||
@@ -355,14 +365,14 @@ obj ast_transformation (Object) {
|
|||||||
if (statements.size == 2)
|
if (statements.size == 2)
|
||||||
if_statement->if_statement.else_part = statements[1]
|
if_statement->if_statement.else_part = statements[1]
|
||||||
return if_statement
|
return if_statement
|
||||||
}
|
}
|
||||||
fun transform_while_loop(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
fun transform_while_loop(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||||
var while_loop = ast_while_loop_ptr(transform_expression(get_node("boolean_expression", node), scope))
|
var while_loop = ast_while_loop_ptr(transform_expression(get_node("boolean_expression", node), scope))
|
||||||
add_to_scope("~enclosing_scope", scope, while_loop)
|
add_to_scope("~enclosing_scope", scope, while_loop)
|
||||||
while_loop->while_loop.statement = transform(get_node("statement", node), while_loop)
|
while_loop->while_loop.statement = transform(get_node("statement", node), while_loop)
|
||||||
return while_loop
|
return while_loop
|
||||||
}
|
}
|
||||||
fun transform_for_loop(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
fun transform_for_loop(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||||
var for_loop = ast_for_loop_ptr()
|
var for_loop = ast_for_loop_ptr()
|
||||||
add_to_scope("~enclosing_scope", scope, for_loop)
|
add_to_scope("~enclosing_scope", scope, for_loop)
|
||||||
var statements = get_nodes("statement", node)
|
var statements = get_nodes("statement", node)
|
||||||
@@ -371,19 +381,19 @@ obj ast_transformation (Object) {
|
|||||||
for_loop->for_loop.update = transform(statements[1], for_loop)
|
for_loop->for_loop.update = transform(statements[1], for_loop)
|
||||||
for_loop->for_loop.body = transform(statements[2], for_loop)
|
for_loop->for_loop.body = transform(statements[2], for_loop)
|
||||||
return for_loop
|
return for_loop
|
||||||
}
|
}
|
||||||
fun transform_return_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
fun transform_return_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||||
return ast_return_statement_ptr(transform(node->children[0], scope))
|
return ast_return_statement_ptr(transform(node->children[0], scope))
|
||||||
}
|
}
|
||||||
fun transform_branching_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
fun transform_branching_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||||
if (node->data.name == "break_statement")
|
if (node->data.name == "break_statement")
|
||||||
return ast_branching_statement_ptr(branching_type::break_stmt())
|
return ast_branching_statement_ptr(branching_type::break_stmt())
|
||||||
return ast_branching_statement_ptr(branching_type::continue_stmt())
|
return ast_branching_statement_ptr(branching_type::continue_stmt())
|
||||||
}
|
}
|
||||||
fun transform_defer_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
fun transform_defer_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||||
return ast_defer_statement_ptr(transform(node->children[0], scope))
|
return ast_defer_statement_ptr(transform(node->children[0], scope))
|
||||||
}
|
}
|
||||||
fun transform_function_call(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
fun transform_function_call(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||||
// don't bother with a full transform for parameters with their own function, just get the boolean expression and transform it
|
// don't bother with a full transform for parameters with their own function, just get the boolean expression and transform it
|
||||||
var parameters = get_nodes("parameter", node).map(fun(child: *tree<symbol>): *ast_node return transform(get_node("boolean_expression", child), scope);)
|
var parameters = get_nodes("parameter", node).map(fun(child: *tree<symbol>): *ast_node return transform(get_node("boolean_expression", child), scope);)
|
||||||
var parameter_types = parameters.map(fun(param: *ast_node): *type return get_ast_type(param);)
|
var parameter_types = parameters.map(fun(param: *ast_node): *type return get_ast_type(param);)
|
||||||
@@ -393,9 +403,9 @@ obj ast_transformation (Object) {
|
|||||||
/*print("function call parameters ")*/
|
/*print("function call parameters ")*/
|
||||||
/*f->function_call.parameters.for_each(fun(param: *ast_node) print(param);)*/
|
/*f->function_call.parameters.for_each(fun(param: *ast_node) print(param);)*/
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
fun transform_expression(node: *tree<symbol>, scope: *ast_node): *ast_node return transform_expression(node, scope, search_type::none())
|
fun transform_expression(node: *tree<symbol>, scope: *ast_node): *ast_node return transform_expression(node, scope, search_type::none())
|
||||||
fun transform_expression(node: *tree<symbol>, scope: *ast_node, searching_for: search_type): *ast_node {
|
fun transform_expression(node: *tree<symbol>, scope: *ast_node, searching_for: search_type): *ast_node {
|
||||||
// figure out what the expression is, handle overloads, or you know
|
// figure out what the expression is, handle overloads, or you know
|
||||||
// ignore everything and do a passthrough
|
// ignore everything and do a passthrough
|
||||||
var func_name = string()
|
var func_name = string()
|
||||||
@@ -427,13 +437,13 @@ obj ast_transformation (Object) {
|
|||||||
}
|
}
|
||||||
var parameter_types = parameters.map(fun(param: *ast_node): *type return get_ast_type(param);)
|
var parameter_types = parameters.map(fun(param: *ast_node): *type return get_ast_type(param);)
|
||||||
return ast_function_call_ptr(get_builtin_function(func_name, parameter_types), parameters)
|
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 {
|
fun get_builtin_function(name: string, param_types: vector<*type>): *ast_node {
|
||||||
if (name == "." || name == "->")
|
if (name == "." || name == "->")
|
||||||
return ast_function_ptr(name, type_ptr(param_types, param_types[1]), vector<*ast_node>())
|
return ast_function_ptr(name, type_ptr(param_types, param_types[1]), vector<*ast_node>())
|
||||||
return ast_function_ptr(name, type_ptr(param_types, param_types[0]), vector<*ast_node>())
|
return ast_function_ptr(name, type_ptr(param_types, param_types[0]), vector<*ast_node>())
|
||||||
}
|
}
|
||||||
fun function_lookup(name: string, scope: *ast_node, param_types: vector<*type>): *ast_node {
|
fun function_lookup(name: string, scope: *ast_node, param_types: vector<*type>): *ast_node {
|
||||||
println(string("doing function lookup for: ") + name)
|
println(string("doing function lookup for: ") + name)
|
||||||
var param_string = string()
|
var param_string = string()
|
||||||
param_types.for_each(fun(t: *type) param_string += t->to_string() + ", ";)
|
param_types.for_each(fun(t: *type) param_string += t->to_string() + ", ";)
|
||||||
@@ -460,8 +470,8 @@ obj ast_transformation (Object) {
|
|||||||
}
|
}
|
||||||
println(string("function lookup failed for ") + name)
|
println(string("function lookup failed for ") + name)
|
||||||
return null<ast_node>()
|
return null<ast_node>()
|
||||||
}
|
}
|
||||||
fun identifier_lookup(name: string, scope: *ast_node): *ast_node {
|
fun identifier_lookup(name: string, scope: *ast_node): *ast_node {
|
||||||
println(string("doing identifier lookup for: ") + name)
|
println(string("doing identifier lookup for: ") + name)
|
||||||
var results = scope_lookup(name, scope)
|
var results = scope_lookup(name, scope)
|
||||||
if (!results.size) {
|
if (!results.size) {
|
||||||
@@ -469,13 +479,13 @@ obj ast_transformation (Object) {
|
|||||||
return null<ast_node>()
|
return null<ast_node>()
|
||||||
}
|
}
|
||||||
return results[0]
|
return results[0]
|
||||||
}
|
}
|
||||||
fun scope_lookup(name: string, scope: *ast_node): vector<*ast_node> {
|
fun scope_lookup(name: string, scope: *ast_node): vector<*ast_node> {
|
||||||
println("*****Doing a name lookup for*****")
|
println("*****Doing a name lookup for*****")
|
||||||
println(name)
|
println(name)
|
||||||
return scope_lookup_helper(name, scope)
|
return scope_lookup_helper(name, scope)
|
||||||
}
|
}
|
||||||
fun scope_lookup_helper(name: string, scope: *ast_node): vector<*ast_node> {
|
fun scope_lookup_helper(name: string, scope: *ast_node): vector<*ast_node> {
|
||||||
// need to do properly scopded lookups
|
// need to do properly scopded lookups
|
||||||
// prevent re-checking the same one...
|
// prevent re-checking the same one...
|
||||||
print("scope is: ")
|
print("scope is: ")
|
||||||
@@ -497,7 +507,6 @@ obj ast_transformation (Object) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun concat_symbol_tree(node: *tree<symbol>): string {
|
fun concat_symbol_tree(node: *tree<symbol>): string {
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import tree:*
|
|||||||
import symbol:*
|
import symbol:*
|
||||||
import ast_nodes:*
|
import ast_nodes:*
|
||||||
import poset:*
|
import poset:*
|
||||||
|
// we import ast_transformation for its make_method_call function
|
||||||
|
import ast_transformation:*
|
||||||
|
|
||||||
fun code_triple(): code_triple return code_triple(string(), string(), string());
|
fun code_triple(): code_triple return code_triple(string(), string(), string());
|
||||||
fun code_triple(only: *char): code_triple return code_triple(string(), string(only), string());
|
fun code_triple(only: *char): code_triple return code_triple(string(), string(only), string());
|
||||||
@@ -172,11 +174,14 @@ obj c_generator (Object) {
|
|||||||
}
|
}
|
||||||
fun generate_statement(node: *ast_node, enclosing_object: *ast_node, defer_stack: *stack<pair<bool,stack<*ast_node>>>): code_triple return generate(node->statement.child, enclosing_object, defer_stack) + ";\n";
|
fun generate_statement(node: *ast_node, enclosing_object: *ast_node, defer_stack: *stack<pair<bool,stack<*ast_node>>>): code_triple return generate(node->statement.child, enclosing_object, defer_stack) + ";\n";
|
||||||
fun generate_declaration_statement(node: *ast_node, enclosing_object: *ast_node, defer_stack: *stack<pair<bool,stack<*ast_node>>>): code_triple {
|
fun generate_declaration_statement(node: *ast_node, enclosing_object: *ast_node, defer_stack: *stack<pair<bool,stack<*ast_node>>>): code_triple {
|
||||||
// add destruct to defer_stac
|
// add destruct to defer_stack
|
||||||
var identifier = node->declaration_statement.identifier
|
var identifier = node->declaration_statement.identifier
|
||||||
|
var ident_type = identifier->identifier.type
|
||||||
var to_ret = code_triple() + type_to_c(identifier->identifier.type) + " " + identifier->identifier.name
|
var to_ret = code_triple() + type_to_c(identifier->identifier.type) + " " + identifier->identifier.name
|
||||||
if (node->declaration_statement.expression) to_ret += code_triple(" = ") + generate(node->declaration_statement.expression, enclosing_object, null<stack<pair<bool,stack<*ast_node>>>>())
|
if (node->declaration_statement.expression) to_ret += code_triple(" = ") + generate(node->declaration_statement.expression, enclosing_object, null<stack<pair<bool,stack<*ast_node>>>>())
|
||||||
if (node->declaration_statement.init_method_call) to_ret += code_triple(";\n") + generate(node->declaration_statement.init_method_call, enclosing_object, null<stack<pair<bool,stack<*ast_node>>>>())
|
if (node->declaration_statement.init_method_call) to_ret += code_triple(";\n") + generate(node->declaration_statement.init_method_call, enclosing_object, null<stack<pair<bool,stack<*ast_node>>>>())
|
||||||
|
if (ident_type->is_object() && has_method(ident_type->type_def, "destruct", vector<*type>()))
|
||||||
|
defer_stack->top().second.push(ast_statement_ptr(make_method_call(identifier, "destruct", vector<*ast_node>())))
|
||||||
return to_ret
|
return to_ret
|
||||||
}
|
}
|
||||||
fun generate_assignment_statement(node: *ast_node, enclosing_object: *ast_node): code_triple {
|
fun generate_assignment_statement(node: *ast_node, enclosing_object: *ast_node): code_triple {
|
||||||
|
|||||||
@@ -121,5 +121,11 @@ obj type (Object) {
|
|||||||
to_ret->indirection = ind
|
to_ret->indirection = ind
|
||||||
return to_ret
|
return to_ret
|
||||||
}
|
}
|
||||||
|
fun is_object(): bool {
|
||||||
|
match (base) {
|
||||||
|
base_type::object() return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+3
-2
@@ -17,8 +17,8 @@ obj Something (ObjectTrait) {
|
|||||||
member = old->member
|
member = old->member
|
||||||
}
|
}
|
||||||
fun destruct() {
|
fun destruct() {
|
||||||
simple_println("Destructing a Something")
|
simple_print("Destructing a Something: ")
|
||||||
member = -800
|
simple_println(member)
|
||||||
}
|
}
|
||||||
fun method(a: int):int {
|
fun method(a: int):int {
|
||||||
return 5+a+member + other_method()
|
return 5+a+member + other_method()
|
||||||
@@ -107,6 +107,7 @@ fun main(): int {
|
|||||||
simple_println(test_methods.member)
|
simple_println(test_methods.member)
|
||||||
simple_println(test_methods_param.member)
|
simple_println(test_methods_param.member)
|
||||||
var second_obj = test_methods
|
var second_obj = test_methods
|
||||||
|
second_obj.member += 5
|
||||||
simple_println(second_obj.member)
|
simple_println(second_obj.member)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user