Make alignment be a u32

This commit is contained in:
Richard Feldman 2021-05-23 11:04:35 -04:00
parent 24e22bc31b
commit 18df7fd24f
13 changed files with 45 additions and 46 deletions

View file

@ -29,15 +29,15 @@ extern fn malloc(size: usize) callconv(.C) ?*c_void;
extern fn realloc(c_ptr: [*]align(@alignOf(u128)) u8, size: usize) callconv(.C) ?*c_void; extern fn realloc(c_ptr: [*]align(@alignOf(u128)) u8, size: usize) callconv(.C) ?*c_void;
extern fn free(c_ptr: [*]align(@alignOf(u128)) u8) callconv(.C) void; extern fn free(c_ptr: [*]align(@alignOf(u128)) u8) callconv(.C) void;
export fn roc_alloc(alignment: usize, size: usize) callconv(.C) ?*c_void { export fn roc_alloc(alignment: u32, size: usize) callconv(.C) ?*c_void {
return malloc(size); return malloc(size);
} }
export fn roc_realloc(alignment: usize, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void { export fn roc_realloc(alignment: u32, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void {
return realloc(@alignCast(16, @ptrCast([*]u8, c_ptr)), new_size); return realloc(@alignCast(16, @ptrCast([*]u8, c_ptr)), new_size);
} }
export fn roc_dealloc(alignment: usize, c_ptr: *c_void) callconv(.C) void { export fn roc_dealloc(alignment: u32, c_ptr: *c_void) callconv(.C) void {
free(@alignCast(16, @ptrCast([*]u8, c_ptr))); free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
} }

View file

@ -28,19 +28,18 @@ extern fn malloc(size: usize) callconv(.C) ?*c_void;
extern fn realloc(c_ptr: [*]align(@alignOf(u128)) u8, size: usize) callconv(.C) ?*c_void; extern fn realloc(c_ptr: [*]align(@alignOf(u128)) u8, size: usize) callconv(.C) ?*c_void;
extern fn free(c_ptr: [*]align(@alignOf(u128)) u8) callconv(.C) void; extern fn free(c_ptr: [*]align(@alignOf(u128)) u8) callconv(.C) void;
export fn roc_alloc(alignment: usize, size: usize) callconv(.C) ?*c_void { export fn roc_alloc(alignment: u32, size: usize) callconv(.C) ?*c_void {
return malloc(size); return malloc(size);
} }
export fn roc_realloc(alignment: usize, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void { export fn roc_realloc(alignment: u32, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void {
return realloc(@alignCast(16, @ptrCast([*]u8, c_ptr)), new_size); return realloc(@alignCast(16, @ptrCast([*]u8, c_ptr)), new_size);
} }
export fn roc_dealloc(alignment: usize, c_ptr: *c_void) callconv(.C) void { export fn roc_dealloc(alignment: u32, c_ptr: *c_void) callconv(.C) void {
free(@alignCast(16, @ptrCast([*]u8, c_ptr))); free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
} }
const RocCallResult = extern struct { flag: usize, content: RocStr }; const RocCallResult = extern struct { flag: usize, content: RocStr };
const Unit = extern struct {}; const Unit = extern struct {};

View file

@ -363,8 +363,8 @@ fn add_intrinsics<'ctx>(ctx: &'ctx Context, module: &Module<'ctx>) {
ROC_ALLOC_64, ROC_ALLOC_64,
i8_ptr_type.fn_type( i8_ptr_type.fn_type(
&[ &[
// alignment: usize // alignment: u32
i64_type.into(), i32_type.into(),
// size: usize // size: usize
i64_type.into(), i64_type.into(),
], ],
@ -377,7 +377,7 @@ fn add_intrinsics<'ctx>(ctx: &'ctx Context, module: &Module<'ctx>) {
ROC_ALLOC_32, ROC_ALLOC_32,
i8_ptr_type.fn_type( i8_ptr_type.fn_type(
&[ &[
// alignment: usize // alignment: u32
i32_type.into(), i32_type.into(),
// size: usize // size: usize
i32_type.into(), i32_type.into(),
@ -391,8 +391,8 @@ fn add_intrinsics<'ctx>(ctx: &'ctx Context, module: &Module<'ctx>) {
ROC_REALLOC_64, ROC_REALLOC_64,
i8_ptr_type.fn_type( i8_ptr_type.fn_type(
&[ &[
// alignment: usize // alignment: u32
i64_type.into(), i32_type.into(),
// ptr: *c_void // ptr: *c_void
i8_ptr_type.into(), i8_ptr_type.into(),
// old_size: usize // old_size: usize
@ -409,7 +409,7 @@ fn add_intrinsics<'ctx>(ctx: &'ctx Context, module: &Module<'ctx>) {
ROC_REALLOC_32, ROC_REALLOC_32,
i8_ptr_type.fn_type( i8_ptr_type.fn_type(
&[ &[
// alignment: usize // alignment: u32
i32_type.into(), i32_type.into(),
// ptr: *c_void // ptr: *c_void
i8_ptr_type.into(), i8_ptr_type.into(),
@ -427,8 +427,8 @@ fn add_intrinsics<'ctx>(ctx: &'ctx Context, module: &Module<'ctx>) {
ROC_DEALLOC_64, ROC_DEALLOC_64,
void_type.fn_type( void_type.fn_type(
&[ &[
// alignment: usize // alignment: u32
i64_type.into(), i32_type.into(),
// ptr: *c_void // ptr: *c_void
i8_ptr_type.into(), i8_ptr_type.into(),
], ],
@ -441,7 +441,7 @@ fn add_intrinsics<'ctx>(ctx: &'ctx Context, module: &Module<'ctx>) {
ROC_DEALLOC_32, ROC_DEALLOC_32,
void_type.fn_type( void_type.fn_type(
&[ &[
// alignment: usize // alignment: u32
i32_type.into(), i32_type.into(),
// ptr: *c_void // ptr: *c_void
i8_ptr_type.into(), i8_ptr_type.into(),

View file

@ -26,13 +26,13 @@ extern "C" {
} }
#[no_mangle] #[no_mangle]
pub unsafe fn roc_alloc(_alignment: usize, size: usize) -> *mut c_void { pub unsafe fn roc_alloc(_alignment: u32, size: usize) -> *mut c_void {
return malloc(size); return malloc(size);
} }
#[no_mangle] #[no_mangle]
pub unsafe fn roc_realloc( pub unsafe fn roc_realloc(
_alignment: usize, _alignment: u32,
c_ptr: *mut c_void, c_ptr: *mut c_void,
_old_size: usize, _old_size: usize,
new_size: usize, new_size: usize,
@ -41,7 +41,7 @@ pub unsafe fn roc_realloc(
} }
#[no_mangle] #[no_mangle]
pub unsafe fn roc_dealloc(_alignment: usize, c_ptr: *mut c_void) { pub unsafe fn roc_dealloc(_alignment: u32, c_ptr: *mut c_void) {
return free(c_ptr); return free(c_ptr);
} }

View file

@ -33,15 +33,15 @@ extern fn malloc(size: usize) callconv(.C) ?*c_void;
extern fn realloc(c_ptr: [*]align(@alignOf(u128)) u8, size: usize) callconv(.C) ?*c_void; extern fn realloc(c_ptr: [*]align(@alignOf(u128)) u8, size: usize) callconv(.C) ?*c_void;
extern fn free(c_ptr: [*]align(@alignOf(u128)) u8) callconv(.C) void; extern fn free(c_ptr: [*]align(@alignOf(u128)) u8) callconv(.C) void;
export fn roc_alloc(alignment: usize, size: usize) callconv(.C) ?*c_void { export fn roc_alloc(alignment: u32, size: usize) callconv(.C) ?*c_void {
return malloc(size); return malloc(size);
} }
export fn roc_realloc(alignment: usize, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void { export fn roc_realloc(alignment: u32, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void {
return realloc(@alignCast(16, @ptrCast([*]u8, c_ptr)), new_size); return realloc(@alignCast(16, @ptrCast([*]u8, c_ptr)), new_size);
} }
export fn roc_dealloc(alignment: usize, c_ptr: *c_void) callconv(.C) void { export fn roc_dealloc(alignment: u32, c_ptr: *c_void) callconv(.C) void {
free(@alignCast(16, @ptrCast([*]u8, c_ptr))); free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
} }

View file

@ -32,13 +32,13 @@ extern "C" {
} }
#[no_mangle] #[no_mangle]
pub unsafe fn roc_alloc(_alignment: usize, size: usize) -> *mut c_void { pub unsafe fn roc_alloc(_alignment: u32, size: usize) -> *mut c_void {
return malloc(size); return malloc(size);
} }
#[no_mangle] #[no_mangle]
pub unsafe fn roc_realloc( pub unsafe fn roc_realloc(
_alignment: usize, _alignment: u32,
c_ptr: *mut c_void, c_ptr: *mut c_void,
_old_size: usize, _old_size: usize,
new_size: usize, new_size: usize,
@ -47,7 +47,7 @@ pub unsafe fn roc_realloc(
} }
#[no_mangle] #[no_mangle]
pub unsafe fn roc_dealloc(_alignment: usize, c_ptr: *mut c_void) { pub unsafe fn roc_dealloc(_alignment: u32, c_ptr: *mut c_void) {
return free(c_ptr); return free(c_ptr);
} }

View file

@ -64,7 +64,7 @@ pub export fn main() u8 {
return 0; return 0;
} }
export fn roc_alloc(alignment: usize, size: usize) callconv(.C) ?*c_void { export fn roc_alloc(alignment: u32, size: usize) callconv(.C) ?*c_void {
const stdout = std.io.getStdOut().writer(); const stdout = std.io.getStdOut().writer();
const allocator = testing.allocator; const allocator = testing.allocator;
@ -80,11 +80,11 @@ export fn roc_alloc(alignment: usize, size: usize) callconv(.C) ?*c_void {
return ptr; return ptr;
} }
export fn roc_realloc(alignment: usize, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void { export fn roc_realloc(alignment: u32, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void {
return realloc(@alignCast(16, @ptrCast([*]u8, c_ptr)), new_size); return realloc(@alignCast(16, @ptrCast([*]u8, c_ptr)), new_size);
} }
export fn roc_dealloc(alignment: usize, c_ptr: *c_void) callconv(.C) void { export fn roc_dealloc(alignment: u32, c_ptr: *c_void) callconv(.C) void {
const stdout = std.io.getStdOut().writer(); const stdout = std.io.getStdOut().writer();
const allocator = testing.allocator; const allocator = testing.allocator;

View file

@ -34,13 +34,13 @@ extern "C" {
} }
#[no_mangle] #[no_mangle]
pub unsafe fn roc_alloc(_alignment: usize, size: usize) -> *mut c_void { pub unsafe fn roc_alloc(_alignment: u32, size: usize) -> *mut c_void {
return malloc(size); return malloc(size);
} }
#[no_mangle] #[no_mangle]
pub unsafe fn roc_realloc( pub unsafe fn roc_realloc(
_alignment: usize, _alignment: u32,
c_ptr: *mut c_void, c_ptr: *mut c_void,
_old_size: usize, _old_size: usize,
new_size: usize, new_size: usize,
@ -49,7 +49,7 @@ pub unsafe fn roc_realloc(
} }
#[no_mangle] #[no_mangle]
pub unsafe fn roc_dealloc(_alignment: usize, c_ptr: *mut c_void) { pub unsafe fn roc_dealloc(_alignment: u32, c_ptr: *mut c_void) {
return free(c_ptr); return free(c_ptr);
} }

View file

@ -23,15 +23,15 @@ extern fn malloc(size: usize) callconv(.C) ?*c_void;
extern fn realloc(c_ptr: [*]align(@alignOf(u128)) u8, size: usize) callconv(.C) ?*c_void; extern fn realloc(c_ptr: [*]align(@alignOf(u128)) u8, size: usize) callconv(.C) ?*c_void;
extern fn free(c_ptr: [*]align(@alignOf(u128)) u8) callconv(.C) void; extern fn free(c_ptr: [*]align(@alignOf(u128)) u8) callconv(.C) void;
export fn roc_alloc(alignment: usize, size: usize) callconv(.C) ?*c_void { export fn roc_alloc(alignment: u32, size: usize) callconv(.C) ?*c_void {
return malloc(size); return malloc(size);
} }
export fn roc_realloc(alignment: usize, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void { export fn roc_realloc(alignment: u32, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void {
return realloc(@alignCast(16, @ptrCast([*]u8, c_ptr)), new_size); return realloc(@alignCast(16, @ptrCast([*]u8, c_ptr)), new_size);
} }
export fn roc_dealloc(alignment: usize, c_ptr: *c_void) callconv(.C) void { export fn roc_dealloc(alignment: u32, c_ptr: *c_void) callconv(.C) void {
free(@alignCast(16, @ptrCast([*]u8, c_ptr))); free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
} }

View file

@ -26,15 +26,15 @@ extern fn malloc(size: usize) callconv(.C) ?*c_void;
extern fn realloc(c_ptr: [*]align(@alignOf(u128)) u8, size: usize) callconv(.C) ?*c_void; extern fn realloc(c_ptr: [*]align(@alignOf(u128)) u8, size: usize) callconv(.C) ?*c_void;
extern fn free(c_ptr: [*]align(@alignOf(u128)) u8) callconv(.C) void; extern fn free(c_ptr: [*]align(@alignOf(u128)) u8) callconv(.C) void;
export fn roc_alloc(alignment: usize, size: usize) callconv(.C) ?*c_void { export fn roc_alloc(alignment: u32, size: usize) callconv(.C) ?*c_void {
return malloc(size); return malloc(size);
} }
export fn roc_realloc(alignment: usize, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void { export fn roc_realloc(alignment: u32, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void {
return realloc(@alignCast(16, @ptrCast([*]u8, c_ptr)), new_size); return realloc(@alignCast(16, @ptrCast([*]u8, c_ptr)), new_size);
} }
export fn roc_dealloc(alignment: usize, c_ptr: *c_void) callconv(.C) void { export fn roc_dealloc(alignment: u32, c_ptr: *c_void) callconv(.C) void {
free(@alignCast(16, @ptrCast([*]u8, c_ptr))); free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
} }

View file

@ -15,13 +15,13 @@ extern "C" {
} }
#[no_mangle] #[no_mangle]
pub unsafe fn roc_alloc(_alignment: usize, size: usize) -> *mut c_void { pub unsafe fn roc_alloc(_alignment: u32, size: usize) -> *mut c_void {
return malloc(size); return malloc(size);
} }
#[no_mangle] #[no_mangle]
pub unsafe fn roc_realloc( pub unsafe fn roc_realloc(
_alignment: usize, _alignment: u32,
c_ptr: *mut c_void, c_ptr: *mut c_void,
_old_size: usize, _old_size: usize,
new_size: usize, new_size: usize,
@ -30,7 +30,7 @@ pub unsafe fn roc_realloc(
} }
#[no_mangle] #[no_mangle]
pub unsafe fn roc_dealloc(_alignment: usize, c_ptr: *mut c_void) { pub unsafe fn roc_dealloc(_alignment: u32, c_ptr: *mut c_void) {
return free(c_ptr); return free(c_ptr);
} }

View file

@ -32,15 +32,15 @@ extern fn malloc(size: usize) callconv(.C) ?*c_void;
extern fn realloc(c_ptr: [*]align(@alignOf(u128)) u8, size: usize) callconv(.C) ?*c_void; extern fn realloc(c_ptr: [*]align(@alignOf(u128)) u8, size: usize) callconv(.C) ?*c_void;
extern fn free(c_ptr: [*]align(@alignOf(u128)) u8) callconv(.C) void; extern fn free(c_ptr: [*]align(@alignOf(u128)) u8) callconv(.C) void;
export fn roc_alloc(alignment: usize, size: usize) callconv(.C) ?*c_void { export fn roc_alloc(alignment: u32, size: usize) callconv(.C) ?*c_void {
return malloc(size); return malloc(size);
} }
export fn roc_realloc(alignment: usize, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void { export fn roc_realloc(alignment: u32, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void {
return realloc(@alignCast(16, @ptrCast([*]u8, c_ptr)), new_size); return realloc(@alignCast(16, @ptrCast([*]u8, c_ptr)), new_size);
} }
export fn roc_dealloc(alignment: usize, c_ptr: *c_void) callconv(.C) void { export fn roc_dealloc(alignment: u32, c_ptr: *c_void) callconv(.C) void {
free(@alignCast(16, @ptrCast([*]u8, c_ptr))); free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
} }

View file

@ -67,13 +67,13 @@ extern "C" {
} }
#[no_mangle] #[no_mangle]
pub unsafe fn roc_alloc(_alignment: usize, size: usize) -> *mut c_void { pub unsafe fn roc_alloc(_alignment: u32, size: usize) -> *mut c_void {
return malloc(size); return malloc(size);
} }
#[no_mangle] #[no_mangle]
pub unsafe fn roc_realloc( pub unsafe fn roc_realloc(
_alignment: usize, _alignment: u32,
c_ptr: *mut c_void, c_ptr: *mut c_void,
_old_size: usize, _old_size: usize,
new_size: usize, new_size: usize,
@ -82,7 +82,7 @@ pub unsafe fn roc_realloc(
} }
#[no_mangle] #[no_mangle]
pub unsafe fn roc_dealloc(_alignment: usize, c_ptr: *mut c_void) { pub unsafe fn roc_dealloc(_alignment: u32, c_ptr: *mut c_void) {
return free(c_ptr); return free(c_ptr);
} }