Added type to values

This commit is contained in:
Nathan Braswell
2016-01-09 22:37:43 -05:00
parent 16aa01a76e
commit 7f20a42178
3 changed files with 33 additions and 8 deletions

View File

@@ -816,8 +816,8 @@ obj function_call (Object) {
return true
}
}
fun ast_value_ptr(string_value: string): *ast_node {
var to_ret.construct(string_value): value
fun ast_value_ptr(string_value: string, value_type: *type): *ast_node {
var to_ret.construct(string_value, value_type): value
var ptr = new<ast_node>()
ptr->copy_construct(&ast_node::value(to_ret))
return ptr
@@ -830,15 +830,18 @@ fun is_value(node: *ast_node): bool {
}
obj value (Object) {
var string_value: string
var value_type: *type
var scope: map<string, vector<*ast_node>>
fun construct(string_value_in: string): *value {
fun construct(string_value_in: string, value_type_in: *type): *value {
scope.construct()
string_value.copy_construct(&string_value_in)
value_type = value_type_in
return this
}
fun copy_construct(old: *value) {
scope.copy_construct(&old->scope)
string_value.copy_construct(&old->string_value)
value_type = old->value_type
}
fun destruct() {
scope.destruct()
@@ -849,7 +852,7 @@ obj value (Object) {
copy_construct(&other)
}
fun operator==(other: ref value): bool {
return string_value == other.string_value
return string_value == other.string_value && value_type == other.value_type
}
}
@@ -868,7 +871,7 @@ fun get_ast_children(node: *ast_node): vector<*ast_node> {
ast_node::case_statement(backing) return vector<*ast_node>()
ast_node::while_loop(backing) return vector<*ast_node>()
ast_node::for_loop(backing) return vector<*ast_node>()
ast_node::return_statement(backing) return vector<*ast_node>()
ast_node::return_statement(backing) return vector(backing.return_value)
ast_node::break_statement(backing) return vector<*ast_node>()
ast_node::continue_statement(backing) return vector<*ast_node>()
ast_node::defer_statement(backing) return vector<*ast_node>()
@@ -904,7 +907,7 @@ fun get_ast_name(node: *ast_node): string {
ast_node::if_comp(backing) return string("if_comp: ") + backing.wanted_generator
ast_node::simple_passthrough(backing) return string("simple_passthrough: , string:") + backing.passthrough_str
ast_node::function_call(backing) return string("function_call")
ast_node::value(backing) return string("value")
ast_node::value(backing) return string("value: ") + backing.string_value + ": " + backing.value_type->to_string()
}
}
fun get_ast_scope(node: *ast_node): *map<string,vector<*ast_node>> {

View File

@@ -204,7 +204,29 @@ obj ast_transformation (Object) {
var name = concat_symbol_tree(node)
return ast_identifier_ptr(name, type_ptr(base_type::void_return()))
}
fun transform_value(node: *tree<symbol>, scope: *ast_node): *ast_node return ast_value_ptr(concat_symbol_tree(node))
fun transform_value(node: *tree<symbol>, scope: *ast_node): *ast_node {
var value_str = concat_symbol_tree(node)
var value_type = null<type>()
if (value_str[0] == '"')
value_type = type_ptr(base_type::character()) // and indirection, sigh
else if (value_str[0] == '\'')
value_type = type_ptr(base_type::character())
else {
// should differentiate between float and double...
var contains_dot = false
for (var i = 0; i < value_str.length(); i++;) {
if (value_str[i] == '.') {
contains_dot = true
break
}
}
if (contains_dot)
value_type = type_ptr(base_type::floating())
else
value_type = type_ptr(base_type::integer())
}
return ast_value_ptr(value_str, value_type)
}
fun transform_expression(node: *tree<symbol>, scope: *ast_node): *ast_node {
// figure out what the expression is, handle overloads, or you know
// ignore everything and do a passthrough