hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 696e57b2dbf9376d4be889cef45731fec9745012
parent 5af9e06de4d00f9a619670ee2f4e6a62bb434066
Author: Bor Grošelj Simić <bgs@turminal.net>
Date:   Wed,  8 Feb 2023 00:56:56 +0100

s/align/_align/ before introduction of align builtin

Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>

Diffstat:
Mcmd/harec/qbe.ha | 2+-
Mhare/types/+test.ha | 40++++++++++++++++++++--------------------
Mhare/types/builtins.ha | 30+++++++++++++++---------------
Mhare/types/store.ha | 102++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mhare/types/types.ha | 2+-
5 files changed, 88 insertions(+), 88 deletions(-)

diff --git a/cmd/harec/qbe.ha b/cmd/harec/qbe.ha @@ -251,7 +251,7 @@ fn qval_emit(to: io::handle, qv: qval) void = { }; fn qinstr_alloc(ty: *types::_type) qinstr = { - switch (ty.align) { + switch (ty._align) { case 4 => return qinstr::ALLOC4; case 8 => diff --git a/hare/types/+test.ha b/hare/types/+test.ha @@ -27,7 +27,7 @@ fn parse_type(in: str) ast::_type = { defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.repr as builtin == builtin::INT); - assert(htype.sz == x86_64._int && htype.align == x86_64._int); + assert(htype.sz == x86_64._int && htype._align == x86_64._int); let type2 = lookup(st, &atype)!; assert(htype == type2, "types should be singletons"); @@ -35,7 +35,7 @@ fn parse_type(in: str) ast::_type = { let atype = parse_type("*int"); defer ast::type_finish(atype); let htype = lookup(st, &atype)!; - assert(htype.sz == x86_64._pointer && htype.align == x86_64._pointer); + assert(htype.sz == x86_64._pointer && htype._align == x86_64._pointer); let htype = htype.repr as pointer; assert(htype.referent.repr as builtin == builtin::INT); }; @@ -61,7 +61,7 @@ fn resolve( defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.sz == 8); - assert(htype.align == 4); + assert(htype._align == 4); let stype = htype.repr as _struct; assert(stype.kind == struct_union::STRUCT); assert(len(stype.fields) == 2); @@ -81,7 +81,7 @@ fn resolve( defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.sz == 4); - assert(htype.align == 4); + assert(htype._align == 4); let stype = htype.repr as _struct; assert(stype.kind == struct_union::UNION); assert(len(stype.fields) == 2); @@ -101,7 +101,7 @@ fn resolve( defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.sz == 24); - assert(htype.align == 8); + assert(htype._align == 8); let stype = htype.repr as _struct; assert(stype.kind == struct_union::STRUCT); @@ -142,7 +142,7 @@ fn resolve( defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.sz == 20); - assert(htype.align == 4); + assert(htype._align == 4); let stype = htype.repr as _struct; assert(stype.fields[0].name == "p"); assert(stype.fields[0].offs == 16); @@ -168,7 +168,7 @@ fn resolve( defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.sz == 16); - assert(htype.align == 4); + assert(htype._align == 4); let stype = htype.repr as _struct; assert(stype.fields[0].name == "p"); assert(stype.fields[0].offs == 12); @@ -196,7 +196,7 @@ fn resolve( defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.sz == 36); - assert(htype.align == 4); + assert(htype._align == 4); let stype = htype.repr as _struct; assert(stype.fields[0].name == "x"); assert(stype.fields[0].offs == 8); @@ -215,7 +215,7 @@ fn resolve( defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.sz == 8); - assert(htype.align == 4); + assert(htype._align == 4); let tup = htype.repr as tuple; assert(len(tup) == 2); @@ -229,7 +229,7 @@ fn resolve( defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.sz == 24); - assert(htype.align == 8); + assert(htype._align == 8); let tup = htype.repr as tuple; assert(tup[0].offs == 0); @@ -247,7 +247,7 @@ fn resolve( defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.sz == 24); - assert(htype.align == 8); + assert(htype._align == 8); let slice = htype.repr as slice; assert(slice.repr as builtin == builtin::INT); @@ -256,7 +256,7 @@ fn resolve( defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.sz == 4 * 5); - assert(htype.align == 4); + assert(htype._align == 4); let arr = htype.repr as array; assert(arr.member.repr as builtin == builtin::I32); assert(arr.length == 5); @@ -266,7 +266,7 @@ fn resolve( defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.sz == SIZE_UNDEFINED); - assert(htype.align == 4); + assert(htype._align == 4); let arr = htype.repr as array; assert(arr.member.repr as builtin == builtin::I32); assert(arr.length == SIZE_UNDEFINED); @@ -276,7 +276,7 @@ fn resolve( defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.sz == SIZE_UNDEFINED); - assert(htype.align == 4); + assert(htype._align == 4); let arr = htype.repr as array; assert(arr.member.repr as builtin == builtin::I32); assert(arr.length == SIZE_UNDEFINED); @@ -290,7 +290,7 @@ fn resolve( defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.sz == SIZE_UNDEFINED); - assert(htype.align == SIZE_UNDEFINED); + assert(htype._align == SIZE_UNDEFINED); let f = htype.repr as func; assert(f.result.repr as builtin == builtin::VOID); assert(f.variadism == variadism::NONE); @@ -301,7 +301,7 @@ fn resolve( defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.sz == SIZE_UNDEFINED); - assert(htype.align == SIZE_UNDEFINED); + assert(htype._align == SIZE_UNDEFINED); let f = htype.repr as func; assert(f.result.repr as builtin == builtin::INT); assert(f.variadism == variadism::HARE); @@ -319,7 +319,7 @@ fn resolve( defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.sz == st.arch._int * 2); - assert(htype.align == st.arch._int); + assert(htype._align == st.arch._int); let t = htype.repr as tagged; assert(len(t) == 2); assert(t[0].repr as builtin == builtin::INT); @@ -329,7 +329,7 @@ fn resolve( defer ast::type_finish(atype); let htype = lookup(st, &atype)!; assert(htype.sz == 32); - assert(htype.align == 8); + assert(htype._align == 8); let t = htype.repr as tagged; assert(len(t) == 3); assert(t[0].repr as builtin == builtin::INT); @@ -344,7 +344,7 @@ fn resolve( const of = lookup_builtin(st, ast::builtin_type::U64); const al = newalias(st, ["myalias"], of); assert(al.sz == 8); - assert(al.align == 8); + assert(al._align == 8); assert(al.flags == 0); assert((al.repr as alias).secondary == of); @@ -366,7 +366,7 @@ fn resolve( const of = lookup_builtin(st, ast::builtin_type::U64); const al = newalias(st, ["myalias"], of); assert(htype.sz == 8); - assert(htype.align == 8); + assert(htype._align == 8); assert(htype.flags == 0); assert((htype.repr as alias).secondary == of); }; diff --git a/hare/types/builtins.ha b/hare/types/builtins.ha @@ -4,105 +4,105 @@ // [[_type]] representation of bool. export const builtin_bool: _type = _type { repr = builtin::BOOL, - sz = 1, align = 1, + sz = 1, _align = 1, ... }; // [[_type]] representation of char. export const builtin_char: _type = _type { repr = builtin::CHAR, - sz = 1, align = 1, + sz = 1, _align = 1, ... }; // [[_type]] representation of f32. export const builtin_f32: _type = _type { repr = builtin::F32, - sz = 4, align = 4, + sz = 4, _align = 4, ... }; // [[_type]] representation of f64. export const builtin_f64: _type = _type { repr = builtin::F64, - sz = 8, align = 8, + sz = 8, _align = 8, ... }; // [[_type]] representation of i8. export const builtin_i8: _type = _type { repr = builtin::I8, - sz = 1, align = 1, + sz = 1, _align = 1, ... }; // [[_type]] representation of i16. export const builtin_i16: _type = _type { repr = builtin::I16, - sz = 2, align = 2, + sz = 2, _align = 2, ... }; // [[_type]] representation of i32. export const builtin_i32: _type = _type { repr = builtin::I32, - sz = 4, align = 4, + sz = 4, _align = 4, ... }; // [[_type]] representation of i64. export const builtin_i64: _type = _type { repr = builtin::I64, - sz = 8, align = 8, + sz = 8, _align = 8, ... }; // [[_type]] representation of null. export const builtin_null: _type = _type { repr = builtin::NULL, - sz = 0, align = 0, + sz = 0, _align = 0, ... }; // [[_type]] representation of rune. export const builtin_rune: _type = _type { repr = builtin::RUNE, - sz = 4, align = 4, + sz = 4, _align = 4, ... }; // [[_type]] representation of u8. export const builtin_u8: _type = _type { repr = builtin::U8, - sz = 1, align = 1, + sz = 1, _align = 1, ... }; // [[_type]] representation of u16. export const builtin_u16: _type = _type { repr = builtin::U16, - sz = 2, align = 2, + sz = 2, _align = 2, ... }; // [[_type]] representation of u32. export const builtin_u32: _type = _type { repr = builtin::U32, - sz = 4, align = 4, + sz = 4, _align = 4, ... }; // [[_type]] representation of u64. export const builtin_u64: _type = _type { repr = builtin::U64, - sz = 8, align = 8, + sz = 8, _align = 8, ... }; // [[_type]] representation of void. export const builtin_void: _type = _type { repr = builtin::VOID, - sz = 0, align = 0, + sz = 0, _align = 0, ... }; diff --git a/hare/types/store.ha b/hare/types/store.ha @@ -68,7 +68,7 @@ export fn newalias( }, id = 0, sz = of.sz, - align = of.align, + _align = of._align, }; const id = hash(&atype); atype.id = id; @@ -171,7 +171,7 @@ export fn lookup( }; fn fromast(store: *typestore, atype: *ast::_type) (_type | deferred | error) = { - let sz = SIZE_UNDEFINED, align = SIZE_UNDEFINED; + let sz = SIZE_UNDEFINED, _align = SIZE_UNDEFINED; const repr = match (atype.repr) { case let a: ast::alias_type => // TODO: This is incomplete @@ -185,75 +185,75 @@ fn fromast(store: *typestore, atype: *ast::_type) (_type | deferred | error) = { yield switch (b) { case ast::builtin_type::BOOL => sz = store.arch._int; - align = store.arch._int; + _align = store.arch._int; yield builtin::BOOL; case ast::builtin_type::CHAR => - sz = 1; align = 1; + sz = 1; _align = 1; yield builtin::CHAR; case ast::builtin_type::F32 => - sz = 4; align = 4; + sz = 4; _align = 4; yield builtin::F32; case ast::builtin_type::F64 => - sz = 8; align = 8; + sz = 8; _align = 8; yield builtin::F64; case ast::builtin_type::I16 => - sz = 2; align = 2; + sz = 2; _align = 2; yield builtin::I16; case ast::builtin_type::I32 => - sz = 4; align = 4; + sz = 4; _align = 4; yield builtin::I32; case ast::builtin_type::I64 => - sz = 8; align = 8; + sz = 8; _align = 8; yield builtin::I64; case ast::builtin_type::I8 => - sz = 1; align = 1; + sz = 1; _align = 1; yield builtin::I8; case ast::builtin_type::INT => sz = store.arch._int; - align = store.arch._int; + _align = store.arch._int; yield builtin::INT; case ast::builtin_type::RUNE => - sz = 4; align = 4; + sz = 4; _align = 4; yield builtin::RUNE; case ast::builtin_type::SIZE => sz = store.arch._size; - align = store.arch._size; + _align = store.arch._size; yield builtin::SIZE; case ast::builtin_type::STR => sz = store.arch._pointer; sz += sz % store.arch._size + store.arch._size; sz += store.arch._size; - align = if (store.arch._size > store.arch._pointer) + _align = if (store.arch._size > store.arch._pointer) store.arch._size else store.arch._pointer; yield builtin::STR; case ast::builtin_type::U16 => - sz = 2; align = 2; + sz = 2; _align = 2; yield builtin::U16; case ast::builtin_type::U32 => - sz = 4; align = 4; + sz = 4; _align = 4; yield builtin::U32; case ast::builtin_type::U64 => - sz = 8; align = 8; + sz = 8; _align = 8; yield builtin::U64; case ast::builtin_type::U8 => - sz = 1; align = 1; + sz = 1; _align = 1; yield builtin::U8; case ast::builtin_type::UINT => sz = store.arch._int; - align = store.arch._int; + _align = store.arch._int; yield builtin::UINT; case ast::builtin_type::UINTPTR => sz = store.arch._pointer; - align = store.arch._pointer; + _align = store.arch._pointer; yield builtin::UINTPTR; case ast::builtin_type::VOID => - sz = 0; align = 0; + sz = 0; _align = 0; yield builtin::VOID; case ast::builtin_type::NULL => sz = store.arch._pointer; - align = store.arch._pointer; + _align = store.arch._pointer; yield builtin::NULL; case ast::builtin_type::ICONST, ast::builtin_type::FCONST => abort(); // TODO? @@ -262,83 +262,83 @@ fn fromast(store: *typestore, atype: *ast::_type) (_type | deferred | error) = { yield func_from_ast(store, &f)?; case let p: ast::pointer_type => sz = store.arch._pointer; - align = store.arch._pointer; + _align = store.arch._pointer; yield pointer { referent = lookup(store, p.referent)?, flags = p.flags: pointer_flags, }; case let st: ast::struct_type => let st = struct_from_ast(store, st, false)?; - sz = 0; align = 0; + sz = 0; _align = 0; for (let i = 0z; i < len(st.fields); i += 1) { const field = st.fields[i]; if (field.offs + field._type.sz > sz) { sz = field.offs + field._type.sz; }; - if (field._type.align > align) { - align = field._type.align; + if (field._type._align > _align) { + _align = field._type._align; }; }; yield st; case let un: ast::union_type => let st = struct_from_ast(store, un, true)?; - sz = 0; align = 0; + sz = 0; _align = 0; for (let i = 0z; i < len(st.fields); i += 1) { const field = st.fields[i]; if (field.offs + field._type.sz > sz) { sz = field.offs + field._type.sz; }; - if (field._type.align > align) { - align = field._type.align; + if (field._type._align > _align) { + _align = field._type._align; }; }; yield st; case let ta: ast::tagged_type => let ta = tagged_from_ast(store, ta)?; - sz = 0; align = 0; + sz = 0; _align = 0; for (let i = 0z; i < len(ta); i += 1) { if (ta[i].sz > sz) { sz = ta[i].sz; }; - if (ta[i].align > align) { - align = ta[i].align; + if (ta[i]._align > _align) { + _align = ta[i]._align; }; }; - if (store.arch._int > align) { - align = store.arch._int; + if (store.arch._int > _align) { + _align = store.arch._int; }; - sz += store.arch._int % align + store.arch._int; + sz += store.arch._int % _align + store.arch._int; yield ta; case let tu: ast::tuple_type => let tu = tuple_from_ast(store, tu)?; - sz = 0; align = 0; + sz = 0; _align = 0; for (let i = 0z; i < len(tu); i += 1) { const value = tu[i]; if (value.offs + value._type.sz > sz) { sz = value.offs + value._type.sz; }; - if (value._type.align > align) { - align = value._type.align; + if (value._type._align > _align) { + _align = value._type._align; }; }; yield tu; case let lt: ast::list_type => let r = list_from_ast(store, &lt)?; sz = r.0; - align = r.1; + _align = r.1; yield r.2; case let et: ast::enum_type => abort(); // TODO }; - if (sz != SIZE_UNDEFINED && sz != 0 && sz % align != 0) { - sz += align - (sz - align) % align; + if (sz != SIZE_UNDEFINED && sz != 0 && sz % _align != 0) { + sz += _align - (sz - _align) % _align; }; return _type { id = 0, // filled in later flags = atype.flags: flags, repr = repr, sz = sz, - align = align, + _align = _align, }; }; @@ -372,7 +372,7 @@ fn list_from_ast( store: *typestore, lt: *ast::list_type ) ((size, size, (slice | array)) | deferred | error) = { - let sz = SIZE_UNDEFINED, align = SIZE_UNDEFINED; + let sz = SIZE_UNDEFINED, _align = SIZE_UNDEFINED; let memb = lookup(store, lt.members)?; let t = match (lt.length) { case ast::len_slice => @@ -381,7 +381,7 @@ fn list_from_ast( sz += store.arch._size - (sz % store.arch._size); }; sz += store.arch._size * 2; - align = if (store.arch._pointer > store.arch._size) + _align = if (store.arch._pointer > store.arch._size) store.arch._pointer else store.arch._size; yield memb: slice; @@ -389,7 +389,7 @@ fn list_from_ast( // Note: contextual length is handled by hare::unit when // initializing bindings. We treat it like unbounded here and // it's fixed up later on. - align = memb.align; + _align = memb._align; yield array { length = SIZE_UNDEFINED, member = memb, @@ -404,13 +404,13 @@ fn list_from_ast( const length = resolv(store.rstate, store, ex)?; sz = memb.sz * length; assert(sz / length == memb.sz, "overflow"); - align = memb.align; + _align = memb._align; yield array { length = length, member = memb, }; }; - return (sz, align, t); + return (sz, _align, t); }; fn _struct_from_ast( @@ -461,8 +461,8 @@ fn _struct_from_ast( }; const _type = lookup(store, memb._type)?; - if (*offs % _type.align != 0) { - *offs += _type.align - (*offs % _type.align); + if (*offs % _type._align != 0) { + *offs += _type._align - (*offs % _type._align); }; append(fields, struct_field { @@ -549,8 +549,8 @@ fn tuple_from_ast( const val = membs[i]; const vtype = lookup(store, val)?; - if (offs % vtype.align != 0) { - offs += vtype.align - (offs % vtype.align); + if (offs % vtype._align != 0) { + offs += vtype._align - (offs % vtype._align); }; append(values, tuple_value { diff --git a/hare/types/types.ha b/hare/types/types.ha @@ -125,5 +125,5 @@ export type _type = struct { | pointer | slice | _struct | tagged | tuple), id: u32, sz: size, - align: size, + _align: size, };