diff options
-rw-r--r-- | cgen.c | 8 | ||||
-rw-r--r-- | eval.c | 28 | ||||
-rw-r--r-- | instance_table.c | 6 | ||||
-rw-r--r-- | types.c | 22 | ||||
-rw-r--r-- | types.h | 2 |
5 files changed, 33 insertions, 33 deletions
@@ -505,14 +505,14 @@ static void cgen_val_ptr_pre(CGenerator *g, void *v, Type *t) { switch (t->kind) { case TYPE_SLICE: { Slice *s = (Slice *)v; - for (I64 i = 0; i < s->n; ++i) { + for (I64 i = 0; i < s->len; ++i) { cgen_val_ptr_pre(g, (char *)s->data + (U64)i * compiler_sizeof(t->slice), t->slice); } cgen_type_pre(g, t->slice); cgen_write(g, "(d%p_[])", v); /* TODO: improve this somehow? */ cgen_type_post(g, t->slice); cgen_write(g, " = {"); - for (I64 i = 0; i < s->n; ++i) { + for (I64 i = 0; i < s->len; ++i) { if (i) cgen_write(g, ", "); cgen_val_ptr(g, (char *)s->data + (U64)i * compiler_sizeof(t->slice), t->slice); } @@ -557,7 +557,7 @@ static void cgen_val_ptr(CGenerator *g, void *v, Type *t) { cgen_write(g, "}"); break; case TYPE_SLICE: - cgen_write(g, "{d%p_, %lu}", v, ((Slice *)v)->n); + cgen_write(g, "{d%p_, %lu}", v, ((Slice *)v)->len); break; case TYPE_STRUCT: cgen_write(g, "{"); @@ -1651,7 +1651,7 @@ static void cgen_expr(CGenerator *g, Expression *e) { Expression *code = e->c.code; assert(code->kind == EXPR_VAL); cgen_indent(g); - fwrite(code->val.slice.data, 1, (size_t)code->val.slice.n, cgen_writing_to(g)); + fwrite(code->val.slice.data, 1, (size_t)code->val.slice.len, cgen_writing_to(g)); } break; case EXPR_BUILTIN: switch (e->builtin.which.val) { @@ -57,8 +57,8 @@ static bool val_truthiness(Value v, Type *t) { case TYPE_BUILTIN: return builtin_truthiness(v, t->builtin); case TYPE_PTR: return v.ptr != NULL; case TYPE_FN: return v.fn != NULL; - case TYPE_ARR: return t->arr.n > 0; - case TYPE_SLICE: return v.slice.n > 0; + case TYPE_ARR: return t->arr.n != 0; + case TYPE_SLICE: return v.slice.len != 0; case TYPE_TUPLE: case TYPE_STRUCT: case TYPE_EXPR: @@ -227,13 +227,13 @@ static void fprint_val_ptr(FILE *f, void *p, Type *t) { case TYPE_SLICE: { fprintf(f, "["); /* TODO: change? when slice initializers are added */ Slice slice = *(Slice *)p; - I64 n = slice.n; + I64 n = slice.len; if (n > 5) n = 5; for (I64 i = 0; i < n; ++i) { if (i) fprintf(f, ", "); fprint_val_ptr(f, (char *)slice.data + i * (I64)compiler_sizeof(t->arr.of), t->arr.of); } - if (slice.n > n) { + if (slice.len > n) { fprintf(f, ", ..."); } fprintf(f, "]"); @@ -603,7 +603,7 @@ static Status eval_val_ptr_at_index(Location where, Value *arr, U64 i, Type *arr if (type) *type = arr_type->arr.of; } break; case TYPE_SLICE: { - U64 slice_sz = (U64)arr->slice.n; + U64 slice_sz = (U64)arr->slice.len; if (i >= slice_sz) { err_print(where, "Slice out of bounds (index = %lu, slice size = %lu)\n", (unsigned long)i, (unsigned long)slice_sz); return false; @@ -772,7 +772,7 @@ static Status eval_address_of(Evaluator *ev, Expression *e, void **ptr) { case UNARY_LEN: { Value slice; if (!eval_expr(ev, e, &slice)) return false; - *ptr = &slice.slice.n; + *ptr = &slice.slice.len; } break; default: assert(0); return false; } @@ -824,13 +824,13 @@ static Status eval_set(Evaluator *ev, Expression *set, Value *to) { /* if it's a pointer, we can just eval it and set its length */ Value of; if (!eval_expr(ev, set->unary.of, &of)) return false; - ((Slice *)of.ptr)->n = to->i64; + ((Slice *)of.ptr)->len = to->i64; } else { /* otherwise, we need a pointer to the slice */ void *p; if (!eval_address_of(ev, set->unary.of, &p)) return false; - ((Slice *)p)->n = to->i64; + ((Slice *)p)->len = to->i64; } } break; default: assert(0); break; @@ -1139,7 +1139,7 @@ static Status eval_expr(Evaluator *ev, Expression *e, Value *v) { } switch (of_type->kind) { case TYPE_SLICE: - v->i64 = of.slice.n; + v->i64 = of.slice.len; break; case TYPE_ARR: v->i64 = (I64)of_type->arr.n; @@ -1356,7 +1356,7 @@ static Status eval_expr(Evaluator *ev, Expression *e, Value *v) { if (uses_ptr) { of.slice = *(Slice *)of.ptr; } - len = of.slice.n; + len = of.slice.len; break; default: assert(0); return false; } @@ -1399,7 +1399,7 @@ static Status eval_expr(Evaluator *ev, Expression *e, Value *v) { break; case EXPR_LITERAL_STR: v->slice.data = e->strl.str; - v->slice.n = (I64)e->strl.len; + v->slice.len = (I64)e->strl.len; break; case EXPR_CAST: { Value casted; @@ -1556,7 +1556,7 @@ static Status eval_expr(Evaluator *ev, Expression *e, Value *v) { Type *of_type = &s->of->type; if (!eval_expr(ev, s->of, &ofv)) return false; - U64 n = of_type->kind == TYPE_ARR ? of_type->arr.n : (U64)ofv.slice.n; + U64 n = of_type->kind == TYPE_ARR ? of_type->arr.n : (U64)ofv.slice.len; U64 from, to; if (s->from) { Value fromv; @@ -1586,10 +1586,10 @@ static Status eval_expr(Evaluator *ev, Expression *e, Value *v) { if (!eval_val_ptr_at_index(e->where, &ofv, from, of_type, &ptr_start, NULL)) return false; v->slice.data = ptr_start; - v->slice.n = (I64)(to - from); + v->slice.len = (I64)(to - from); } else { v->slice.data = NULL; - v->slice.n = 0; + v->slice.len = 0; } } break; case EXPR_TYPE: diff --git a/instance_table.c b/instance_table.c index 125c2cf..665fd9c 100644 --- a/instance_table.c +++ b/instance_table.c @@ -182,7 +182,7 @@ static U64 val_ptr_hash(void *v, Type *t) { U64 hash = 0; Slice *s = v; U64 size = (U64)compiler_sizeof(t->slice); - for (U64 i = 0; i < (U64)s->n; ++i) { + for (U64 i = 0; i < (U64)s->len; ++i) { hash += (U64)x * val_ptr_hash((char *)s->data + i * size, t->slice); x = rand_u32(x); } @@ -275,9 +275,9 @@ static bool val_ptr_eq(void *u, void *v, Type *t) { U64 size = (U64)compiler_sizeof(t->arr.of); Slice *r = u; Slice *s = v; - if (r->n != s->n) return false; + if (r->len != s->len) return false; char *sptr = r->data, *tptr = s->data; - for (U64 i = 0; i < (U64)s->n; ++i) { + for (I64 i = 0; i < s->len; ++i) { if (!val_ptr_eq(sptr, tptr, t->slice)) return false; sptr += size; @@ -382,16 +382,16 @@ static char *eval_expr_as_cstr(Typer *tr, Expression *e, const char *what_is_thi if (!eval_expr(tr->evalr, e, &e_val)) return NULL; Slice e_slice = e_val.slice; - char *str = typer_malloc(tr, (size_t)e_slice.n + 1); - str[e_slice.n] = 0; - memcpy(str, e_slice.data, (size_t)e_slice.n); + char *str = typer_malloc(tr, (size_t)e_slice.len + 1); + str[e_slice.len] = 0; + memcpy(str, e_slice.data, (size_t)e_slice.len); return str; } static char *slice_to_cstr(Slice s) { - char *ret = malloc((size_t)s.n + 1); - memcpy(ret, s.data, (size_t)s.n); - ret[s.n] = 0; + char *ret = err_malloc((size_t)s.len + 1); + memcpy(ret, s.data, (size_t)s.len); + ret[s.len] = 0; return ret; } @@ -2884,7 +2884,7 @@ static Status types_expr(Typer *tr, Expression *e) { /* get the field, if it exists */ Identifier ident = ident_get_with_len(&lhs_type->struc->body.idents, - field_name.slice.data, (size_t)field_name.slice.n); + field_name.slice.data, (size_t)field_name.slice.len); if (ident_is_declared(ident)) { assert(ident->decl_kind == IDECL_DECL); Declaration *decl = ident->decl; @@ -2903,9 +2903,9 @@ static Status types_expr(Typer *tr, Expression *e) { *t = *f->type; } } else { - char *fstr = err_malloc((size_t)(field_name.slice.n + 1)); - memcpy(fstr, field_name.slice.data, (size_t)field_name.slice.n); - fstr[field_name.slice.n] = 0; /* null-terminate */ + char *fstr = err_malloc((size_t)(field_name.slice.len + 1)); + memcpy(fstr, field_name.slice.data, (size_t)field_name.slice.len); + fstr[field_name.slice.len] = 0; /* null-terminate */ char *typestr = type_to_str(lhs_type); err_print(e->where, "%s is not a field of structure %s.", fstr, typestr); free(fstr); free(typestr); @@ -2932,7 +2932,7 @@ static Status types_expr(Typer *tr, Expression *e) { if (!eval_expr(tr->evalr, rhs, &member_name)) return false; e->binary.op = BINARY_DOT; e->binary.rhs->kind = EXPR_IDENT; - e->binary.rhs->ident = ident_get_with_len(&nms->body.idents, member_name.slice.data, (size_t)member_name.slice.n); + e->binary.rhs->ident = ident_get_with_len(&nms->body.idents, member_name.slice.data, (size_t)member_name.slice.len); if (!ident_is_declared(e->binary.rhs->ident)) { char *s = slice_to_cstr(member_name.slice); err_print(e->where, "\"%s\" is not a member of this namespace.", s); @@ -148,7 +148,7 @@ typedef struct HashTable { } HashTable; typedef struct Slice { - I64 n; + I64 len; void *data; } Slice; |