🎨 merge flag of immutable type

This commit is contained in:
ValKmjolnir 2024-11-01 00:44:16 +08:00
parent 95f3225c69
commit 4077a0a7fb
5 changed files with 19 additions and 19 deletions

View File

@ -381,7 +381,7 @@ type semantic::resolve_array_literal(array_literal* node) {
const auto type_infer = tr.resolve(node->get_type());
node->set_resolve_type(type_infer.get_pointer_copy());
auto result_type = type_infer.get_pointer_copy();
result_type.is_immutable_array_address = true;
result_type.is_immutable = true;
return result_type;
}
@ -679,10 +679,9 @@ type semantic::resolve_call_index(const type& prev, call_index* node) {
return type::error_type();
}
resolve_expression(node->get_index());
auto result = prev;
result.pointer_depth--;
if (result.is_immutable_array_address) {
result.is_immutable_array_address = false;
auto result = prev.get_ref_copy();
if (result.is_immutable) {
result.is_immutable = false;
}
node->set_resolve_type(result);
return result;
@ -956,11 +955,7 @@ bool semantic::check_valid_left_value(expr* node) {
}
void semantic::check_mutable_left_value(expr* node, const type& lt) {
if (lt.is_immutable_array_address) {
rp.report(node, "cannot assign to immutable array address.");
return;
}
if (lt.is_constant_type) {
if (lt.is_immutable) {
rp.report(node, "cannot assign to \"const " + lt.to_string() + "\".");
return;
}
@ -1095,7 +1090,7 @@ void semantic::resolve_definition(definition* node, const colgm_func& func_self)
}
// if immutable, make sure the type is correct
if (real_type.is_constant_type || real_type.is_immutable_array_address) {
if (real_type.is_immutable) {
node->set_resolve_type(real_type);
ctx.add_local(name, real_type);
check_defined_variable_is_void(node, real_type);

View File

@ -33,12 +33,11 @@ struct type {
std::string name;
std::string loc_file;
i64 pointer_depth = 0;
bool is_global = false;
bool is_global_func = false;
bool is_enum = false;
bool is_immutable_array_address = false;
bool is_constant_type = false;
bool is_generic_placeholder = false;
bool is_global = false; // global symbol
bool is_global_func = false; // global func
bool is_enum = false; // enum
bool is_immutable = false; // immutable
bool is_generic_placeholder = false; // generic placeholder
struct_method_info stm_info; // struct methods
struct_method_info prm_info; // primitive methods

View File

@ -41,7 +41,7 @@ type type_resolver::resolve(ast::type_def* node) {
// if node has const flag, set it
if (node->is_constant()) {
res.is_constant_type = true;
res.is_immutable = true;
}
// if node has generics and we can find it, set it as the place holder

View File

@ -1,4 +1,4 @@
use data::{ A, B, Test, EmbedTest, test_i32 };
use data::{ A, B, Test, EmbedTest, PublicStruct, test_i32 };
use libc::{ puts, malloc, free };
struct Vec<T> {
@ -104,6 +104,9 @@ func main() -> i64 {
var embed_test = EmbedTest<i32> { test: test };
embed_test.test.get_test();
// FIXME
// var pub_stct = PublicStruct<i32>::instance();
test_i32();
add_test<i8>('a', '\0');

View File

@ -40,6 +40,9 @@ pub struct PublicStruct<T> {
}
impl PublicStruct<T> {
pub func instance() -> PublicStruct<T> {
return PublicStruct<T> { field: PrivateStruct<T> { field: 42 => T } };
}
pub func get_field(self) -> T {
puts("[test_lib/data.colgm] get_field called");
return self->field.field;