diff options
| -rw-r--r-- | ast.c | 4 | ||||
| -rw-r--r-- | ast.h | 2 | ||||
| -rw-r--r-- | compile.c | 4 | ||||
| -rw-r--r-- | parse.c | 4 | ||||
| -rw-r--r-- | repl.c | 1 | ||||
| -rw-r--r-- | test/arrays.tm | 6 | ||||
| -rw-r--r-- | typecheck.c | 19 | ||||
| -rw-r--r-- | types.c | 4 | ||||
| -rw-r--r-- | types.h | 2 |
9 files changed, 17 insertions, 29 deletions
@@ -171,8 +171,8 @@ CORD type_ast_to_xml(type_ast_t *t) #define T(type, ...) case type: { auto data = t->__data.type; (void)data; return CORD_asprintf(__VA_ARGS__); } T(UnknownTypeAST, "<UnknownType/>") T(VarTypeAST, "%s", data.name) - T(PointerTypeAST, "<PointerType is_stack=\"%s\" is_readonly=\"%s\">%r</PointerType>", - data.is_stack ? "yes" : "no", data.is_readonly ? "yes" : "no", type_ast_to_xml(data.pointed)) + T(PointerTypeAST, "<PointerType is_stack=\"%s\">%r</PointerType>", + data.is_stack ? "yes" : "no", type_ast_to_xml(data.pointed)) T(ArrayTypeAST, "<ArrayType>%r</ArrayType>", type_ast_to_xml(data.item)) T(SetTypeAST, "<TableType>%r</TableType>", type_ast_to_xml(data.item)) T(ChannelTypeAST, "<ChannelType>%r</ChannelType>", type_ast_to_xml(data.item)) @@ -100,7 +100,7 @@ struct type_ast_s { } VarTypeAST; struct { type_ast_t *pointed; - bool is_stack:1, is_readonly:1; + bool is_stack:1; } PointerTypeAST; struct { type_ast_t *item; @@ -2581,7 +2581,6 @@ CORD compile(env_t *env, ast_t *ast) type_t *self_value_t = value_type(self_t); switch (self_value_t->tag) { case ArrayType: { - // TODO: check for readonly type_t *item_t = Match(self_value_t, ArrayType)->item_type; CORD padded_item_size = CORD_asprintf("%ld", padded_type_size(item_t)); if (streq(call->name, "insert")) { @@ -2637,7 +2636,7 @@ CORD compile(env_t *env, ast_t *ast) CORD self = compile_to_pointer_depth(env, call->self, streq(call->name, "sort") ? 1 : 0, false); CORD comparison; if (call->args) { - type_t *item_ptr = Type(PointerType, .pointed=item_t, .is_stack=true, .is_readonly=true); + type_t *item_ptr = Type(PointerType, .pointed=item_t, .is_stack=true); type_t *fn_t = Type(FunctionType, .args=new(arg_t, .name="x", .type=item_ptr, .next=new(arg_t, .name="y", .type=item_ptr)), .ret=Type(IntType, .bits=TYPE_IBITS32)); arg_t *arg_spec = new(arg_t, .name="by", .type=Type(ClosureType, .fn=fn_t)); @@ -3454,7 +3453,6 @@ CORD compile_type_info(env_t *env, type_t *t) case PointerType: { auto ptr = Match(t, PointerType); CORD sigil = ptr->is_stack ? "&" : "@"; - if (ptr->is_readonly) sigil = CORD_cat(sigil, "%"); return CORD_asprintf("Pointer$info(%r, %r)", CORD_quoted(sigil), compile_type_info(env, ptr->pointed)); @@ -637,11 +637,9 @@ type_ast_t *parse_pointer_type(parse_ctx_t *ctx, const char *pos) { return NULL; spaces(&pos); - bool is_readonly = match(&pos, "%"); - spaces(&pos); type_ast_t *type = expect(ctx, start, &pos, parse_non_optional_type, "I couldn't parse a pointer type after this point"); - type_ast_t *ptr_type = NewTypeAST(ctx->file, start, pos, PointerTypeAST, .pointed=type, .is_stack=is_stack, .is_readonly=is_readonly); + type_ast_t *ptr_type = NewTypeAST(ctx->file, start, pos, PointerTypeAST, .pointed=type, .is_stack=is_stack); spaces(&pos); if (match(&pos, "?")) return NewTypeAST(ctx->file, start, pos, OptionalTypeAST, .type=ptr_type); @@ -136,7 +136,6 @@ const TypeInfo_t *type_to_type_info(type_t *t) case PointerType: { auto ptr = Match(t, PointerType); CORD sigil = ptr->is_stack ? "&" : "@"; - if (ptr->is_readonly) sigil = CORD_cat(sigil, "%"); const TypeInfo_t *pointed_info = type_to_type_info(ptr->pointed); const TypeInfo_t pointer_info = {.size=sizeof(void*), .align=__alignof__(void*), .tag=PointerInfo, .PointerInfo={.sigil=sigil, .pointed=pointed_info}}; diff --git a/test/arrays.tm b/test/arrays.tm index 0618a2fc..e1c31cf6 100644 --- a/test/arrays.tm +++ b/test/arrays.tm @@ -95,10 +95,10 @@ func main(): >> nums = [-20, 10, 30] # Custom sort functions: - >> nums:sort(func(x:&%Int,y:&%Int): x:abs() <> y:abs()) + >> nums:sort(func(x,y:&Int): x:abs() <> y:abs()) >> nums = [10, -20, 30] - >> nums:sort(func(x:&%Int,y:&%Int): y[] <> x[]) + >> nums:sort(func(x,y:&Int): y[] <> x[]) >> nums = [30, 10, -20] @@ -159,7 +159,7 @@ func main(): >> nums:sort() >> [nums:binary_search(i) for i in nums] = [1, 2, 3, 4, 5] - >> nums:sort(func(a,b:&%Int): a:abs() <> b:abs()) + >> nums:sort(func(a,b:&Int): a:abs() <> b:abs()) >> [nums:binary_search(i, func(a,b:&Int): a:abs() <> b:abs()) for i in nums] = [1, 2, 3, 4, 5] diff --git a/typecheck.c b/typecheck.c index 6eab7363..c50e01be 100644 --- a/typecheck.c +++ b/typecheck.c @@ -46,7 +46,7 @@ type_t *parse_type_ast(env_t *env, type_ast_t *ast) type_t *pointed_t = parse_type_ast(env, ptr->pointed); if (pointed_t->tag == VoidType) code_err(ast, "Void pointers are not supported. You probably meant 'Memory' instead of 'Void'"); - return Type(PointerType, .pointed=pointed_t, .is_stack=ptr->is_stack, .is_readonly=ptr->is_readonly); + return Type(PointerType, .pointed=pointed_t, .is_stack=ptr->is_stack); } case ArrayTypeAST: { type_ast_t *item_type = Match(ast, ArrayTypeAST)->item; @@ -545,7 +545,7 @@ type_t *get_type(env_t *env, ast_t *ast) code_err(base, "This value might be null, so it can't be safely dereferenced"); } else if (base_type->tag == PointerType) { auto ptr = Match(base_type, PointerType); - return Type(PointerType, .pointed=ref_type, .is_stack=ptr->is_stack, .is_readonly=ptr->is_readonly); + return Type(PointerType, .pointed=ref_type, .is_stack=ptr->is_stack); } else if (base->tag == Var) { return Type(PointerType, .pointed=ref_type, .is_stack=true); } @@ -991,7 +991,7 @@ type_t *get_type(env_t *env, ast_t *ast) auto lhs_ptr = Match(lhs_t, PointerType); auto rhs_ptr = Match(rhs_t, PointerType); if (type_eq(lhs_ptr->pointed, rhs_ptr->pointed)) - return Type(PointerType, .pointed=lhs_ptr->pointed, .is_readonly=lhs_ptr->is_readonly || rhs_ptr->is_readonly); + return Type(PointerType, .pointed=lhs_ptr->pointed); } else if ((is_int_type(lhs_t) && is_int_type(rhs_t)) || (lhs_t->tag == ByteType && rhs_t->tag == ByteType)) { return get_math_type(env, ast, lhs_t, rhs_t); @@ -1015,11 +1015,11 @@ type_t *get_type(env_t *env, ast_t *ast) } else if (lhs_t->tag == PointerType) { auto lhs_ptr = Match(lhs_t, PointerType); if (rhs_t->tag == AbortType || rhs_t->tag == ReturnType) { - return Type(PointerType, .pointed=lhs_ptr->pointed, .is_readonly=lhs_ptr->is_readonly); + return Type(PointerType, .pointed=lhs_ptr->pointed); } else if (rhs_t->tag == PointerType) { auto rhs_ptr = Match(rhs_t, PointerType); if (type_eq(rhs_ptr->pointed, lhs_ptr->pointed)) - return Type(PointerType, .pointed=lhs_ptr->pointed, .is_readonly=lhs_ptr->is_readonly || rhs_ptr->is_readonly); + return Type(PointerType, .pointed=lhs_ptr->pointed); } } code_err(ast, "I can't figure out the type of this `or` expression because the left side is a %T, but the right side is a %T", @@ -1311,8 +1311,7 @@ PUREFUNC bool can_be_mutated(env_t *env, ast_t *ast) auto access = Match(ast, FieldAccess); type_t *fielded_type = get_type(env, access->fielded); if (fielded_type->tag == PointerType) { - auto ptr = Match(fielded_type, PointerType); - return !ptr->is_readonly; + return true; } else if (fielded_type->tag == StructType) { return can_be_mutated(env, access->fielded); } else { @@ -1322,10 +1321,8 @@ PUREFUNC bool can_be_mutated(env_t *env, ast_t *ast) case Index: { auto index = Match(ast, Index); type_t *indexed_type = get_type(env, index->indexed); - if (indexed_type->tag == PointerType) { - auto ptr = Match(indexed_type, PointerType); - return !ptr->is_readonly; - } + if (indexed_type->tag == PointerType) + return true; return can_be_mutated(env, index->indexed); } default: return false; @@ -69,7 +69,6 @@ CORD type_to_cord(type_t *t) { case PointerType: { auto ptr = Match(t, PointerType); CORD sigil = ptr->is_stack ? "&" : "@"; - if (ptr->is_readonly) sigil = CORD_cat(sigil, "%"); return CORD_all(sigil, type_to_cord(ptr->pointed)); } case EnumType: { @@ -350,9 +349,6 @@ PUREFUNC bool can_promote(type_t *actual, type_t *needed) else if (actual_ptr->is_stack && !needed_ptr->is_stack) // Can't use &x for a function that wants a @Foo or ?Foo return false; - else if (actual_ptr->is_readonly && !needed_ptr->is_readonly) - // Can't use pointer to readonly data when we need a pointer that can write to the data - return false; else return true; } @@ -101,7 +101,7 @@ struct type_s { } ClosureType; struct { type_t *pointed; - bool is_stack:1, is_readonly:1; + bool is_stack:1; } PointerType; struct { const char *name; |
