Fix character value handling. String stuff appears to work correctly in bytecode now
This commit is contained in:
@@ -549,9 +549,10 @@ obj ast_transformation (Object) {
|
||||
}
|
||||
value_str = new_str
|
||||
}
|
||||
} else if (value_str[0] == '\'') //'// lol, comment hack for vim syntax highlighting (my fault, of course)
|
||||
} else if (value_str[0] == '\'') { //'// lol, comment hack for vim syntax highlighting (my fault, of course)
|
||||
value_type = type_ptr(base_type::character())
|
||||
else if (value_str == "true" || value_str == "false")
|
||||
value_str = value_str.slice(1,-2)
|
||||
} else if (value_str == "true" || value_str == "false")
|
||||
value_type = type_ptr(base_type::boolean())
|
||||
else {
|
||||
// should differentiate between float and double...
|
||||
|
||||
@@ -617,6 +617,8 @@ obj bytecode_generator (Object) {
|
||||
return emit_imm((node->value.string_value == "true") cast long)
|
||||
else if (node->value.value_type->base == base_type::character() && node->value.value_type->indirection == 1)
|
||||
return emit_imm((node->value.string_value.toCharArray()) cast long)
|
||||
else if (node->value.value_type->base == base_type::character() && node->value.value_type->indirection == 0)
|
||||
return emit_imm((node->value.string_value[0]) cast long)
|
||||
else
|
||||
return emit_imm(string_to_num<int>(node->value.string_value))
|
||||
}
|
||||
|
||||
@@ -291,6 +291,8 @@ obj c_generator (Object) {
|
||||
}
|
||||
fun generate_value(node: *ast_node): string {
|
||||
var value = node->value.string_value
|
||||
if (node->value.value_type->base == base_type::character() && node->value.value_type->indirection == 0)
|
||||
return "'" + value + "'"
|
||||
if (node->value.value_type->base != base_type::character() || node->value.value_type->indirection != 1)
|
||||
return value
|
||||
|
||||
|
||||
@@ -191,6 +191,11 @@ obj string (Object, Serializable, Hashable) {
|
||||
return *this == str
|
||||
}
|
||||
|
||||
fun operator+(c: char): string {
|
||||
var to_ret = *this
|
||||
to_ret += c
|
||||
return to_ret
|
||||
}
|
||||
fun operator+(integer: int): string return *this + to_string(integer);
|
||||
fun operator+(integer: long): string return *this + to_string(integer);
|
||||
fun operator+(integer: ulong): string return *this + to_string(integer);
|
||||
|
||||
Reference in New Issue
Block a user