aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-30 19:07:05 +0200
committerlemon <lsof@mailbox.org>2022-08-30 19:07:05 +0200
commitdd3b12d8114176d8433f961a11b7f53c1083ade0 (patch)
treee4f88b460a0e3193922d0fb04566f484b5007576 /src
parent25987b70e70713213a9ea91bf753130fd051ce33 (diff)
interntype by ref
Diffstat (limited to 'src')
-rw-r--r--src/cffc.hff10
-rw-r--r--src/parse.cff16
-rw-r--r--src/type.cff10
3 files changed, 18 insertions, 18 deletions
diff --git a/src/cffc.hff b/src/cffc.hff
index 06e87fb..4d57d3d 100644
--- a/src/cffc.hff
+++ b/src/cffc.hff
@@ -441,7 +441,7 @@ extern static ty_void *const Type,
ty_c_llong *const Type,
ty_c_ullong *const Type,
ty_c_valist *const Type;
-extern fn interntype(Type) *const Type;
+extern fn interntype(*Type) *const Type;
extern fn putprimtypes(env *Env) void;
fn constify(ty *const Type) *const Type {
if ty.konst or ty.u.#tag == :Fn {
@@ -449,7 +449,7 @@ fn constify(ty *const Type) *const Type {
}
let ty2 = *ty;
ty2.konst = #t;
- return interntype(ty2);
+ return interntype(&ty2);
}
fn unconstify(ty *const Type) *const Type {
if !ty.konst {
@@ -457,17 +457,17 @@ fn unconstify(ty *const Type) *const Type {
}
let ty2 = *ty;
ty2.konst = #f;
- return interntype(ty2);
+ return interntype(&ty2);
}
fn mkarrtype(len i64, konst bool, child *const Type) *const Type {
- return interntype({
+ return interntype(&Type {
len * child.size,
child.align,
.u: :Arr { konst ? constify(child) : child, len }
});
}
fn mkptrtype(child *const Type) *const Type {
- return interntype({
+ return interntype(&Type {
g_targ.ptrsize,
.u: :Ptr(child)
});
diff --git a/src/parse.cff b/src/parse.cff
index b758061..46d71d8 100644
--- a/src/parse.cff
+++ b/src/parse.cff
@@ -689,7 +689,7 @@ fn parseenum(P *Parser, name *const u8, lax bool) *const Type {
: max < 1i64 << 31 ? ty_i32
: ty_i64);
static id int = 0;
- return interntype({ .u: :Enum { intty, name, lax, id++, vals->move(P.alloc) }});
+ return interntype(&Type{ .u: :Enum { intty, name, lax, id++, vals->move(P.alloc) }});
}
fn isdecltokt(t TokT) bool {
@@ -715,7 +715,7 @@ fn parseagg(P *Parser, loc Loc, kind AggKind, name *const u8, retdecl **Decl) *c
decl = #null;
}
}
- let ty = decl ? decl.u.Ty : interntype({ .u: :Agg { kind, name, id++ }});
+ let ty = decl ? decl.u.Ty : interntype(&Type{ .u: :Agg { kind, name, id++ }});
let ty = as(*Type)ty;
let constty = as(*Type)constify(ty);
let agg = &ty.u.Agg;
@@ -791,7 +791,7 @@ fn parseagg(P *Parser, loc Loc, kind AggKind, name *const u8, retdecl **Decl) *c
ev.name = fld.name;
ev.i = i;
}
- agg.enumty = interntype(enumty);
+ agg.enumty = interntype(&enumty);
let off = f0align < 0 ? 0z : ALIGNUP(enumty.size, f0align);
ty.size += off;
@@ -889,7 +889,7 @@ fn parsebitfield(P *Parser, name *const u8) *const Type {
lex(P);
let signedty = *bitf.intty;
signedty.u.Int.sgn = #t;
- ty = interntype(signedty);
+ ty = interntype(&signedty);
}
iota += size;
@@ -906,7 +906,7 @@ fn parsebitfield(P *Parser, name *const u8) *const Type {
}
bitf.flds = flds->move(P.alloc);
- return interntype(ty);
+ return interntype(&ty);
}
fn typematchestarg(targ *const Type, ty *const Type) bool {
@@ -1100,7 +1100,7 @@ fn parsefntype(P *Parser) *const Type {
let paramtys Vec<*const Type> = {};
parsefnparams(P, &variadic, #null, &paramtys);
let ret = parsetype(P);
- return interntype({ .u: :Fn {
+ return interntype(&Type{ .u: :Fn {
paramtys->move(P.alloc),
variadic,
ret,
@@ -1989,7 +1989,7 @@ fn pexprefix(P *Parser) Expr {
case lexmatch(P, &tok, '&');
let ex = pexprefix(P);
- let ty2 = interntype({ g_targ.ptrsize, .u: :Ptr(ex.ty) });
+ let ty2 = interntype(&Type{ g_targ.ptrsize, .u: :Ptr(ex.ty) });
if !islvalue(&ex) and !(ex.u.#tag == :Symbol and ex.u.Symbol.u.#tag == :Fn)
and !(ex.u.#tag == :ZeroIni or ex.u.#tag == :AggIni or ex.u.#tag == :ArrIni) {
err(P, ex.loc, "invalid operand to `&': not an lvalue");
@@ -2780,7 +2780,7 @@ fn parsefn(P *Parser, loc Loc, toplevel bool, externp bool, name *const u8) *Dec
parsefnparams(P, &Fn.variadic, &paramnames, &paramtys);
Fn.paramnames = paramnames->move(P.alloc);
let retty = parsetype(P);
- Fn.ty = interntype({ .size: 0, .align: 1, .u: :Fn {
+ Fn.ty = interntype(&Type{ .size: 0, .align: 1, .u: :Fn {
paramtys->move(P.alloc), Fn.variadic, retty
}});
static id int = 0;
diff --git a/src/type.cff b/src/type.cff
index 2a23717..a17205e 100644
--- a/src/type.cff
+++ b/src/type.cff
@@ -123,12 +123,12 @@ struct TypeTraits {
}
static types_set Set<*const Type, TypeTraits> = {};
-extern fn interntype(ty0 Type) *const Type {
+extern fn interntype(ty0 *Type) *const Type {
if ty0.align == 0 {
ty0.align = ty0.size == 0 ? 1 : ty0.size;
}
- return *types_set->intern(&ty0);
+ return *types_set->intern(ty0);
}
extern fn completetype(ty *const Type) bool {
@@ -234,14 +234,14 @@ extern fn putprimtypes(env *Env) void {
ty.size = g_targ.valistsize;
ty.align = g_targ.valistalign;
}
- envput(env, { type.name, .u: :Ty(*gty = interntype(*ty)) }, #null);
+ envput(env, { type.name, .u: :Ty(*gty = interntype(ty)) }, #null);
}
- ty_voidptr = interntype({ .size: g_targ.ptrsize, .u: :Ptr(ty_void) });
+ ty_voidptr = interntype(&Type{ .size: g_targ.ptrsize, .u: :Ptr(ty_void) });
}
extern fn mkslicetype(child *const Type) *const Type {
let align = MAX(g_targ.ptrsize, g_targ.sizesize);
- return interntype({
+ return interntype(&Type{
ALIGNUP(g_targ.ptrsize + g_targ.sizesize, align), align,
.u: :Slice(child)
});