Ptr instance offset_const can be negative + use i64_type()

This commit is contained in:
lyken 2024-08-28 13:02:03 +08:00
parent fe851f7ccd
commit 236032b888
No known key found for this signature in database
GPG Key ID: 3BD5FC6AC8325DD8

View File

@ -123,9 +123,9 @@ impl<'ctx, Item: Model<'ctx>> Instance<'ctx, Ptr<Item>> {
pub fn offset_const( pub fn offset_const(
&self, &self,
ctx: &CodeGenContext<'ctx, '_>, ctx: &CodeGenContext<'ctx, '_>,
offset: u64, offset: i64,
) -> Instance<'ctx, Ptr<Item>> { ) -> Instance<'ctx, Ptr<Item>> {
let offset = ctx.ctx.i32_type().const_int(offset, false); let offset = ctx.ctx.i64_type().const_int(offset as u64, true);
self.offset(ctx, offset) self.offset(ctx, offset)
} }
@ -141,7 +141,7 @@ impl<'ctx, Item: Model<'ctx>> Instance<'ctx, Ptr<Item>> {
pub fn set_index_const( pub fn set_index_const(
&self, &self,
ctx: &CodeGenContext<'ctx, '_>, ctx: &CodeGenContext<'ctx, '_>,
index: u64, index: i64,
value: Instance<'ctx, Item>, value: Instance<'ctx, Item>,
) { ) {
self.offset_const(ctx, index).store(ctx, value); self.offset_const(ctx, index).store(ctx, value);
@ -160,7 +160,7 @@ impl<'ctx, Item: Model<'ctx>> Instance<'ctx, Ptr<Item>> {
&self, &self,
generator: &mut G, generator: &mut G,
ctx: &CodeGenContext<'ctx, '_>, ctx: &CodeGenContext<'ctx, '_>,
index: u64, index: i64,
) -> Instance<'ctx, Item> { ) -> Instance<'ctx, Item> {
self.offset_const(ctx, index).load(generator, ctx) self.offset_const(ctx, index).load(generator, ctx)
} }