2016-01-06 02:46:42 -05:00
|
|
|
import mem:*
|
|
|
|
|
import string:*
|
|
|
|
|
import vector:*
|
2016-01-05 21:40:00 -05:00
|
|
|
|
|
|
|
|
// hmm, like the ast_node, this is another candadate for being fully an ADT
|
|
|
|
|
// one issue is that there are properties shared between most of the options (indirection, say)
|
|
|
|
|
adt base_type {
|
|
|
|
|
none,
|
|
|
|
|
template,
|
|
|
|
|
template_type,
|
|
|
|
|
void_return,
|
|
|
|
|
boolean,
|
|
|
|
|
character,
|
|
|
|
|
integer,
|
|
|
|
|
floating,
|
|
|
|
|
double_precision,
|
|
|
|
|
function
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 02:46:42 -05:00
|
|
|
fun type_ptr(): *type {
|
|
|
|
|
return new<type>()->construct()
|
|
|
|
|
}
|
|
|
|
|
fun type_ptr(base: base_type): *type {
|
|
|
|
|
return new<type>()->construct(base)
|
2016-01-05 21:40:00 -05:00
|
|
|
}
|
2016-01-06 02:46:42 -05:00
|
|
|
fun type_ptr(parameters: vector<*type>, return_type: *type): *type {
|
|
|
|
|
return new<type>()->construct(parameters, return_type)
|
2016-01-05 21:40:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
obj type (Object) {
|
|
|
|
|
var base: base_type
|
2016-01-06 02:46:42 -05:00
|
|
|
var parameter_types: vector<*type>
|
|
|
|
|
var return_type: *type
|
2016-01-05 21:40:00 -05:00
|
|
|
fun construct(): *type {
|
|
|
|
|
base.copy_construct(&base_type::none())
|
2016-01-06 02:46:42 -05:00
|
|
|
parameter_types.construct()
|
2016-01-05 21:40:00 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun construct(base_in: base_type): *type {
|
|
|
|
|
base.copy_construct(&base_in)
|
2016-01-06 02:46:42 -05:00
|
|
|
parameter_types.construct()
|
|
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun construct(parameter_types_in: vector<*type>, return_type_in: *type): *type {
|
|
|
|
|
base.copy_construct(&base_type::function())
|
|
|
|
|
parameter_types.copy_construct(¶meter_types)
|
|
|
|
|
return_type = return_type_in
|
2016-01-05 21:40:00 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *type) {
|
2016-01-06 02:46:42 -05:00
|
|
|
base.copy_construct(&old->base)
|
|
|
|
|
parameter_types.copy_construct(&old->parameter_types)
|
|
|
|
|
return_type = old->return_type
|
2016-01-05 21:40:00 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref type) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun destruct() {
|
|
|
|
|
base.destruct()
|
2016-01-06 02:46:42 -05:00
|
|
|
parameter_types.destruct()
|
|
|
|
|
}
|
|
|
|
|
fun to_string(): string {
|
|
|
|
|
match (base) {
|
|
|
|
|
base_type::none() return string("none")
|
|
|
|
|
base_type::template() return string("template")
|
|
|
|
|
base_type::template_type() return string("template_type")
|
|
|
|
|
base_type::void_return() return string("void_return")
|
|
|
|
|
base_type::boolean() return string("boolean")
|
|
|
|
|
base_type::character() return string("character")
|
|
|
|
|
base_type::integer() return string("integer")
|
|
|
|
|
base_type::floating() return string("floating")
|
|
|
|
|
base_type::double_precision() return string("double_precision")
|
|
|
|
|
base_type::function() {
|
|
|
|
|
var temp = string("function: (")
|
|
|
|
|
parameter_types.for_each(fun(parameter_type: *type) temp += parameter_type->to_string() + " ";)
|
|
|
|
|
return temp + ")" + return_type->to_string()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return string("impossible type")
|
2016-01-05 21:40:00 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|