Make this varaiable/keyword work

This commit is contained in:
Nathan Braswell
2016-01-24 01:02:56 -05:00
parent 23cad3ad1b
commit c022758b9c
5 changed files with 30 additions and 9 deletions

View File

@@ -151,7 +151,7 @@ obj ast_transformation (Object) {
// make sure not a template
// huh, I guess I can't actually assign to the backing.
// This is actually a little bit of a problem, maybe these should be pointers also. All the pointers!
node->function.body_statement = transform_statement(get_node("statement", ast_to_syntax[node]), translation_unit)
node->function.body_statement = transform_statement(get_node("statement", ast_to_syntax[node]), node)
}
}
})
@@ -193,7 +193,7 @@ obj ast_transformation (Object) {
print("There are "); print(possibilities.size); println(" possibilites for this object type lookup")
for (var i = 0; i < possibilities.size; i++;) {
match(*possibilities[i]) {
ast_node::type_def(backing) return backing.self_type
ast_node::type_def(backing) return backing.self_type->clone_with_indirection(indirection)
}
}
println("No objects in lookup, returning none")
@@ -250,9 +250,12 @@ obj ast_transformation (Object) {
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 {
// for identifier we have to do scope lookup, etc, and maybe limit to function
// NOT THIS
// first, we check for and generate this
var name = concat_symbol_tree(node)
if (name == "this") {
while (!is_type_def(scope)) scope = get_ast_scope(scope)->get(string("~enclosing_scope"))[0]
return ast_identifier_ptr("this", scope->type_def.self_type->clone_with_indirection(1))
}
/*return ast_identifier_ptr(name, type_ptr(base_type::void_return()))*/
match (searching_for) {
search_type::none() return identifier_lookup(name, scope)

View File

@@ -158,7 +158,10 @@ obj c_generator (Object) {
is_type_def(get_ast_scope(node->function_call.func->function_call.parameters[1])->get(string("~enclosing_scope"))[0])
) {
func_name = generate(node->function_call.func->function_call.parameters[1], enclosing_object)
call_string = string("&") + generate(node->function_call.func->function_call.parameters[0], enclosing_object)
// don't add & if it was ->
if (node->function_call.func->function_call.func->function.name == ".")
call_string += string("&")
call_string += generate(node->function_call.func->function_call.parameters[0], enclosing_object)
} else {
func_name = generate(node->function_call.func, enclosing_object)
}
@@ -243,7 +246,7 @@ obj c_generator (Object) {
base_type::floating() return string("float") + indirection
base_type::double_precision() return string("double") + indirection
base_type::object() {
return type->type_def->type_def.name
return type->type_def->type_def.name + indirection
}
base_type::function() {
var temp = indirection + string("function: (")

View File

@@ -98,7 +98,7 @@ obj type (Object) {
for (var i = 0; i < indirection; i++;) indirection_str += "*"
match (base) {
base_type::none() return indirection_str + string("none")
base_type::object() return indirection_str + string("obj:") + type_def->type_def.name
base_type::object() return indirection_str + type_def->type_def.name
base_type::template() return indirection_str + string("template")
base_type::template_type() return indirection_str + string("template_type")
base_type::void_return() return indirection_str + string("void_return")
@@ -115,6 +115,11 @@ obj type (Object) {
}
return string("impossible type, indirection:") + indirection
}
fun clone_with_indirection(ind: int): *type {
var to_ret = new<type>()
to_ret->copy_construct(this)
to_ret->indirection = ind
return to_ret
}
}

View File

@@ -9,6 +9,9 @@ fun simple_print(to_print: int) {
printf("%d", to_print);
"""
}
fun string_id(it: *char): *char {
return it;
}
var a = 1
var b:int

View File

@@ -1,10 +1,13 @@
import to_import: simple_print, a, b
import to_import: simple_print, a, b, string_id
obj Something (ObjectTrait) {
var member: int
fun method(a: int):int {
return 5+a+member
}
fun return_this(): *Something {
return this;
}
}
/*fun some_function(): int return 0;*/
@@ -46,6 +49,10 @@ fun main(): int {
simple_print("\n")
simple_print(an_obj.method(1))
simple_print("\n")
simple_print(string_id("WoooopsEee\n"))
var with_ptr = an_obj.return_this()
simple_print(with_ptr->method(2))
simple_print("\n")
return 0
}