Skip to content

Commit

Permalink
Fix ci.
Browse files Browse the repository at this point in the history
  • Loading branch information
fubark committed Jul 10, 2024
1 parent 1d68786 commit 0a37853
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/builtins/builtins.zig
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,12 @@ pub fn queueTask(vm: *cy.VM) anyerror!Value {

pub fn sizeof(vm: *cy.VM) Value {
const type_id: cy.TypeId = @intCast(vm.getInt(0));
_ = type_id;
return Value.initInt(8);
const type_e = vm.c.types[type_id];
if (type_e.kind == .struct_t) {
return Value.initInt(8 * type_e.data.struct_t.nfields);
} else {
return Value.initInt(8);
}
}

pub fn typeof(vm: *cy.VM) Value {
Expand Down
3 changes: 3 additions & 0 deletions test/memory/default_memory.cy
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ type Foo cstruct:
a int
b float

test.eq(sizeof(int), 8)
test.eq(sizeof(Foo), 16)

-- Memory.new primitive
var intp = mem.new(int)
intp.* = 123
Expand Down

0 comments on commit 0a37853

Please sign in to comment.