mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
Rearrange arg order for roc_alloc etc
This commit is contained in:
parent
7d7588ca19
commit
0b3715ebee
22 changed files with 166 additions and 161 deletions
|
@ -28,15 +28,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: u32, size: usize) callconv(.C) ?*c_void {
|
export fn roc_alloc(size: usize, alignment: u32) callconv(.C) ?*c_void {
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn roc_realloc(alignment: u32, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void {
|
export fn roc_realloc(c_ptr: *c_void, new_size: usize, old_size: usize, alignment: u32) 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: u32, c_ptr: *c_void) callconv(.C) void {
|
export fn roc_dealloc(c_ptr: *c_void, alignment: u32) callconv(.C) void {
|
||||||
free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
|
free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,15 +28,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: u32, size: usize) callconv(.C) ?*c_void {
|
export fn roc_alloc(size: usize, alignment: u32) callconv(.C) ?*c_void {
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn roc_realloc(alignment: u32, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void {
|
export fn roc_realloc(c_ptr: *c_void, new_size: usize, old_size: usize, alignment: u32) 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: u32, c_ptr: *c_void) callconv(.C) void {
|
export fn roc_dealloc(c_ptr: *c_void, alignment: u32) callconv(.C) void {
|
||||||
free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
|
free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ const Alignment = packed enum(u8) {
|
||||||
Align8KeyFirst,
|
Align8KeyFirst,
|
||||||
Align8ValueFirst,
|
Align8ValueFirst,
|
||||||
|
|
||||||
fn toUsize(self: Alignment) usize {
|
fn toU32(self: Alignment) u32 {
|
||||||
switch (self) {
|
switch (self) {
|
||||||
.Align16KeyFirst => return 16,
|
.Align16KeyFirst => return 16,
|
||||||
.Align16ValueFirst => return 16,
|
.Align16ValueFirst => return 16,
|
||||||
|
@ -97,14 +97,14 @@ pub fn decref(
|
||||||
bytes_or_null: ?[*]u8,
|
bytes_or_null: ?[*]u8,
|
||||||
data_bytes: usize,
|
data_bytes: usize,
|
||||||
) void {
|
) void {
|
||||||
return utils.decref(alignment.toUsize(), bytes_or_null, data_bytes);
|
return utils.decref(alignment.toU32(), bytes_or_null, data_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn allocateWithRefcount(
|
pub fn allocateWithRefcount(
|
||||||
alignment: Alignment,
|
|
||||||
data_bytes: usize,
|
data_bytes: usize,
|
||||||
|
alignment: Alignment,
|
||||||
) [*]u8 {
|
) [*]u8 {
|
||||||
return utils.allocateWithRefcount(alignment.toUsize(), data_bytes);
|
return utils.allocateWithRefcount(data_bytes, alignment.toU32());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const RocDict = extern struct {
|
pub const RocDict = extern struct {
|
||||||
|
@ -132,7 +132,7 @@ pub const RocDict = extern struct {
|
||||||
const data_bytes = number_of_slots * slot_size;
|
const data_bytes = number_of_slots * slot_size;
|
||||||
|
|
||||||
return RocDict{
|
return RocDict{
|
||||||
.dict_bytes = allocateWithRefcount(alignment, data_bytes),
|
.dict_bytes = allocateWithRefcount(data_bytes, alignment),
|
||||||
.number_of_levels = number_of_levels,
|
.number_of_levels = number_of_levels,
|
||||||
.dict_entries_len = number_of_entries,
|
.dict_entries_len = number_of_entries,
|
||||||
};
|
};
|
||||||
|
@ -152,7 +152,7 @@ pub const RocDict = extern struct {
|
||||||
const delta_capacity = new_capacity - old_capacity;
|
const delta_capacity = new_capacity - old_capacity;
|
||||||
|
|
||||||
const data_bytes = new_capacity * slot_size;
|
const data_bytes = new_capacity * slot_size;
|
||||||
const first_slot = allocateWithRefcount(alignment, data_bytes);
|
const first_slot = allocateWithRefcount(data_bytes, alignment);
|
||||||
|
|
||||||
// transfer the memory
|
// transfer the memory
|
||||||
|
|
||||||
|
@ -570,7 +570,7 @@ pub fn dictKeys(dict: RocDict, alignment: Alignment, key_width: usize, value_wid
|
||||||
}
|
}
|
||||||
|
|
||||||
const data_bytes = length * key_width;
|
const data_bytes = length * key_width;
|
||||||
var ptr = allocateWithRefcount(alignment, data_bytes);
|
var ptr = allocateWithRefcount(data_bytes, alignment);
|
||||||
|
|
||||||
var offset = blk: {
|
var offset = blk: {
|
||||||
if (alignment.keyFirst()) {
|
if (alignment.keyFirst()) {
|
||||||
|
@ -619,7 +619,7 @@ pub fn dictValues(dict: RocDict, alignment: Alignment, key_width: usize, value_w
|
||||||
}
|
}
|
||||||
|
|
||||||
const data_bytes = length * value_width;
|
const data_bytes = length * value_width;
|
||||||
var ptr = allocateWithRefcount(alignment, data_bytes);
|
var ptr = allocateWithRefcount(data_bytes, alignment);
|
||||||
|
|
||||||
var offset = blk: {
|
var offset = blk: {
|
||||||
if (alignment.keyFirst()) {
|
if (alignment.keyFirst()) {
|
||||||
|
@ -772,10 +772,10 @@ pub fn dictWalk(
|
||||||
inc_value: Inc,
|
inc_value: Inc,
|
||||||
output: Opaque,
|
output: Opaque,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const alignment_usize = alignment.toUsize();
|
const alignment_u32 = alignment.toU32();
|
||||||
// allocate space to write the result of the stepper into
|
// allocate space to write the result of the stepper into
|
||||||
// experimentally aliasing the accum and output pointers is not a good idea
|
// experimentally aliasing the accum and output pointers is not a good idea
|
||||||
const bytes_ptr: [*]u8 = utils.alloc(alignment_usize, accum_width);
|
const bytes_ptr: [*]u8 = utils.alloc(accum_width, alignment_u32);
|
||||||
var b1 = output orelse unreachable;
|
var b1 = output orelse unreachable;
|
||||||
var b2 = bytes_ptr;
|
var b2 = bytes_ptr;
|
||||||
|
|
||||||
|
@ -804,5 +804,5 @@ pub fn dictWalk(
|
||||||
}
|
}
|
||||||
|
|
||||||
@memcpy(output orelse unreachable, b2, accum_width);
|
@memcpy(output orelse unreachable, b2, accum_width);
|
||||||
utils.dealloc(alignment_usize, bytes_ptr);
|
utils.dealloc(bytes_ptr, alignment_u32);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,19 +41,19 @@ pub const RocList = extern struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn allocate(
|
pub fn allocate(
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
length: usize,
|
length: usize,
|
||||||
element_size: usize,
|
element_size: usize,
|
||||||
) RocList {
|
) RocList {
|
||||||
const data_bytes = length * element_size;
|
const data_bytes = length * element_size;
|
||||||
|
|
||||||
return RocList{
|
return RocList{
|
||||||
.bytes = utils.allocateWithRefcount(alignment, data_bytes),
|
.bytes = utils.allocateWithRefcount(data_bytes, alignment),
|
||||||
.length = length,
|
.length = length,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn makeUnique(self: RocList, alignment: usize, element_width: usize) RocList {
|
pub fn makeUnique(self: RocList, alignment: u32, element_width: usize) RocList {
|
||||||
if (self.isEmpty()) {
|
if (self.isEmpty()) {
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ pub const RocList = extern struct {
|
||||||
|
|
||||||
pub fn reallocate(
|
pub fn reallocate(
|
||||||
self: RocList,
|
self: RocList,
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
new_length: usize,
|
new_length: usize,
|
||||||
element_width: usize,
|
element_width: usize,
|
||||||
) RocList {
|
) RocList {
|
||||||
|
@ -98,7 +98,7 @@ pub const RocList = extern struct {
|
||||||
/// reallocate by explicitly making a new allocation and copying elements over
|
/// reallocate by explicitly making a new allocation and copying elements over
|
||||||
fn reallocateFresh(
|
fn reallocateFresh(
|
||||||
self: RocList,
|
self: RocList,
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
new_length: usize,
|
new_length: usize,
|
||||||
element_width: usize,
|
element_width: usize,
|
||||||
) RocList {
|
) RocList {
|
||||||
|
@ -106,7 +106,7 @@ pub const RocList = extern struct {
|
||||||
const delta_length = new_length - old_length;
|
const delta_length = new_length - old_length;
|
||||||
|
|
||||||
const data_bytes = new_length * element_width;
|
const data_bytes = new_length * element_width;
|
||||||
const first_slot = utils.allocateWithRefcount(alignment, data_bytes);
|
const first_slot = utils.allocateWithRefcount(data_bytes, alignment);
|
||||||
|
|
||||||
// transfer the memory
|
// transfer the memory
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ const Caller1 = fn (?[*]u8, ?[*]u8, ?[*]u8) callconv(.C) void;
|
||||||
const Caller2 = fn (?[*]u8, ?[*]u8, ?[*]u8, ?[*]u8) callconv(.C) void;
|
const Caller2 = fn (?[*]u8, ?[*]u8, ?[*]u8, ?[*]u8) callconv(.C) void;
|
||||||
const Caller3 = fn (?[*]u8, ?[*]u8, ?[*]u8, ?[*]u8, ?[*]u8) callconv(.C) void;
|
const Caller3 = fn (?[*]u8, ?[*]u8, ?[*]u8, ?[*]u8, ?[*]u8) callconv(.C) void;
|
||||||
|
|
||||||
pub fn listReverse(list: RocList, alignment: usize, element_width: usize) callconv(.C) RocList {
|
pub fn listReverse(list: RocList, alignment: u32, element_width: usize) callconv(.C) RocList {
|
||||||
if (list.bytes) |source_ptr| {
|
if (list.bytes) |source_ptr| {
|
||||||
const size = list.len();
|
const size = list.len();
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ pub fn listMap(
|
||||||
data: Opaque,
|
data: Opaque,
|
||||||
inc_n_data: IncN,
|
inc_n_data: IncN,
|
||||||
data_is_owned: bool,
|
data_is_owned: bool,
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
old_element_width: usize,
|
old_element_width: usize,
|
||||||
new_element_width: usize,
|
new_element_width: usize,
|
||||||
) callconv(.C) RocList {
|
) callconv(.C) RocList {
|
||||||
|
@ -207,7 +207,7 @@ pub fn listMapWithIndex(
|
||||||
data: Opaque,
|
data: Opaque,
|
||||||
inc_n_data: IncN,
|
inc_n_data: IncN,
|
||||||
data_is_owned: bool,
|
data_is_owned: bool,
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
old_element_width: usize,
|
old_element_width: usize,
|
||||||
new_element_width: usize,
|
new_element_width: usize,
|
||||||
) callconv(.C) RocList {
|
) callconv(.C) RocList {
|
||||||
|
@ -248,7 +248,7 @@ pub fn listMap2(
|
||||||
data: Opaque,
|
data: Opaque,
|
||||||
inc_n_data: IncN,
|
inc_n_data: IncN,
|
||||||
data_is_owned: bool,
|
data_is_owned: bool,
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
a_width: usize,
|
a_width: usize,
|
||||||
b_width: usize,
|
b_width: usize,
|
||||||
c_width: usize,
|
c_width: usize,
|
||||||
|
@ -296,7 +296,7 @@ pub fn listMap3(
|
||||||
data: Opaque,
|
data: Opaque,
|
||||||
inc_n_data: IncN,
|
inc_n_data: IncN,
|
||||||
data_is_owned: bool,
|
data_is_owned: bool,
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
a_width: usize,
|
a_width: usize,
|
||||||
b_width: usize,
|
b_width: usize,
|
||||||
c_width: usize,
|
c_width: usize,
|
||||||
|
@ -350,7 +350,7 @@ pub fn listKeepIf(
|
||||||
data: Opaque,
|
data: Opaque,
|
||||||
inc_n_data: IncN,
|
inc_n_data: IncN,
|
||||||
data_is_owned: bool,
|
data_is_owned: bool,
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
element_width: usize,
|
element_width: usize,
|
||||||
inc: Inc,
|
inc: Inc,
|
||||||
dec: Dec,
|
dec: Dec,
|
||||||
|
@ -401,7 +401,7 @@ pub fn listKeepOks(
|
||||||
data: Opaque,
|
data: Opaque,
|
||||||
inc_n_data: IncN,
|
inc_n_data: IncN,
|
||||||
data_is_owned: bool,
|
data_is_owned: bool,
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
before_width: usize,
|
before_width: usize,
|
||||||
result_width: usize,
|
result_width: usize,
|
||||||
after_width: usize,
|
after_width: usize,
|
||||||
|
@ -428,7 +428,7 @@ pub fn listKeepErrs(
|
||||||
data: Opaque,
|
data: Opaque,
|
||||||
inc_n_data: IncN,
|
inc_n_data: IncN,
|
||||||
data_is_owned: bool,
|
data_is_owned: bool,
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
before_width: usize,
|
before_width: usize,
|
||||||
result_width: usize,
|
result_width: usize,
|
||||||
after_width: usize,
|
after_width: usize,
|
||||||
|
@ -456,7 +456,7 @@ pub fn listKeepResult(
|
||||||
data: Opaque,
|
data: Opaque,
|
||||||
inc_n_data: IncN,
|
inc_n_data: IncN,
|
||||||
data_is_owned: bool,
|
data_is_owned: bool,
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
before_width: usize,
|
before_width: usize,
|
||||||
result_width: usize,
|
result_width: usize,
|
||||||
after_width: usize,
|
after_width: usize,
|
||||||
|
@ -468,7 +468,7 @@ pub fn listKeepResult(
|
||||||
var output = RocList.allocate(alignment, list.len(), list.len() * after_width);
|
var output = RocList.allocate(alignment, list.len(), list.len() * after_width);
|
||||||
const target_ptr = output.bytes orelse unreachable;
|
const target_ptr = output.bytes orelse unreachable;
|
||||||
|
|
||||||
var temporary = @ptrCast([*]u8, utils.alloc(alignment, result_width));
|
var temporary = @ptrCast([*]u8, utils.alloc(result_width, alignment));
|
||||||
|
|
||||||
if (data_is_owned) {
|
if (data_is_owned) {
|
||||||
inc_n_data(data, size);
|
inc_n_data(data, size);
|
||||||
|
@ -490,7 +490,7 @@ pub fn listKeepResult(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.dealloc(alignment, temporary);
|
utils.dealloc(temporary, alignment);
|
||||||
|
|
||||||
if (kept == 0) {
|
if (kept == 0) {
|
||||||
utils.decref(alignment, output.bytes, size * after_width);
|
utils.decref(alignment, output.bytes, size * after_width);
|
||||||
|
@ -511,7 +511,7 @@ pub fn listWalk(
|
||||||
inc_n_data: IncN,
|
inc_n_data: IncN,
|
||||||
data_is_owned: bool,
|
data_is_owned: bool,
|
||||||
accum: Opaque,
|
accum: Opaque,
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
element_width: usize,
|
element_width: usize,
|
||||||
accum_width: usize,
|
accum_width: usize,
|
||||||
output: Opaque,
|
output: Opaque,
|
||||||
|
@ -529,7 +529,7 @@ pub fn listWalk(
|
||||||
inc_n_data(data, list.len());
|
inc_n_data(data, list.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
const bytes_ptr: [*]u8 = utils.alloc(alignment, accum_width);
|
const bytes_ptr: [*]u8 = utils.alloc(accum_width, alignment);
|
||||||
var b1 = output orelse unreachable;
|
var b1 = output orelse unreachable;
|
||||||
var b2 = bytes_ptr;
|
var b2 = bytes_ptr;
|
||||||
|
|
||||||
|
@ -549,7 +549,7 @@ pub fn listWalk(
|
||||||
}
|
}
|
||||||
|
|
||||||
@memcpy(output orelse unreachable, b2, accum_width);
|
@memcpy(output orelse unreachable, b2, accum_width);
|
||||||
utils.dealloc(alignment, bytes_ptr);
|
utils.dealloc(bytes_ptr, alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn listWalkBackwards(
|
pub fn listWalkBackwards(
|
||||||
|
@ -559,7 +559,7 @@ pub fn listWalkBackwards(
|
||||||
inc_n_data: IncN,
|
inc_n_data: IncN,
|
||||||
data_is_owned: bool,
|
data_is_owned: bool,
|
||||||
accum: Opaque,
|
accum: Opaque,
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
element_width: usize,
|
element_width: usize,
|
||||||
accum_width: usize,
|
accum_width: usize,
|
||||||
output: Opaque,
|
output: Opaque,
|
||||||
|
@ -577,7 +577,7 @@ pub fn listWalkBackwards(
|
||||||
inc_n_data(data, list.len());
|
inc_n_data(data, list.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
const bytes_ptr: [*]u8 = utils.alloc(alignment, accum_width);
|
const bytes_ptr: [*]u8 = utils.alloc(accum_width, alignment);
|
||||||
var b1 = output orelse unreachable;
|
var b1 = output orelse unreachable;
|
||||||
var b2 = bytes_ptr;
|
var b2 = bytes_ptr;
|
||||||
|
|
||||||
|
@ -598,7 +598,7 @@ pub fn listWalkBackwards(
|
||||||
}
|
}
|
||||||
|
|
||||||
@memcpy(output orelse unreachable, b2, accum_width);
|
@memcpy(output orelse unreachable, b2, accum_width);
|
||||||
utils.dealloc(alignment, bytes_ptr);
|
utils.dealloc(bytes_ptr, alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn listWalkUntil(
|
pub fn listWalkUntil(
|
||||||
|
@ -608,7 +608,7 @@ pub fn listWalkUntil(
|
||||||
inc_n_data: IncN,
|
inc_n_data: IncN,
|
||||||
data_is_owned: bool,
|
data_is_owned: bool,
|
||||||
accum: Opaque,
|
accum: Opaque,
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
element_width: usize,
|
element_width: usize,
|
||||||
accum_width: usize,
|
accum_width: usize,
|
||||||
dec: Dec,
|
dec: Dec,
|
||||||
|
@ -626,7 +626,7 @@ pub fn listWalkUntil(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bytes_ptr: [*]u8 = utils.alloc(alignment, TAG_WIDTH + accum_width);
|
const bytes_ptr: [*]u8 = utils.alloc(TAG_WIDTH + accum_width, alignment);
|
||||||
|
|
||||||
@memcpy(bytes_ptr + TAG_WIDTH, accum orelse unreachable, accum_width);
|
@memcpy(bytes_ptr + TAG_WIDTH, accum orelse unreachable, accum_width);
|
||||||
|
|
||||||
|
@ -655,7 +655,7 @@ pub fn listWalkUntil(
|
||||||
}
|
}
|
||||||
|
|
||||||
@memcpy(output orelse unreachable, bytes_ptr + TAG_WIDTH, accum_width);
|
@memcpy(output orelse unreachable, bytes_ptr + TAG_WIDTH, accum_width);
|
||||||
utils.dealloc(alignment, bytes_ptr);
|
utils.dealloc(bytes_ptr, alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
// List.contains : List k, k -> Bool
|
// List.contains : List k, k -> Bool
|
||||||
|
@ -674,7 +674,7 @@ pub fn listContains(list: RocList, key: Opaque, key_width: usize, is_eq: EqFn) c
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn listRepeat(count: usize, alignment: usize, element: Opaque, element_width: usize, inc_n_element: IncN) callconv(.C) RocList {
|
pub fn listRepeat(count: usize, alignment: u32, element: Opaque, element_width: usize, inc_n_element: IncN) callconv(.C) RocList {
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
return RocList.empty();
|
return RocList.empty();
|
||||||
}
|
}
|
||||||
|
@ -697,7 +697,7 @@ pub fn listRepeat(count: usize, alignment: usize, element: Opaque, element_width
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn listSingle(alignment: usize, element: Opaque, element_width: usize) callconv(.C) RocList {
|
pub fn listSingle(alignment: u32, element: Opaque, element_width: usize) callconv(.C) RocList {
|
||||||
var output = RocList.allocate(alignment, 1, element_width);
|
var output = RocList.allocate(alignment, 1, element_width);
|
||||||
|
|
||||||
if (output.bytes) |target| {
|
if (output.bytes) |target| {
|
||||||
|
@ -709,7 +709,7 @@ pub fn listSingle(alignment: usize, element: Opaque, element_width: usize) callc
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn listAppend(list: RocList, alignment: usize, element: Opaque, element_width: usize) callconv(.C) RocList {
|
pub fn listAppend(list: RocList, alignment: u32, element: Opaque, element_width: usize) callconv(.C) RocList {
|
||||||
const old_length = list.len();
|
const old_length = list.len();
|
||||||
var output = list.reallocate(alignment, old_length + 1, element_width);
|
var output = list.reallocate(alignment, old_length + 1, element_width);
|
||||||
|
|
||||||
|
@ -724,7 +724,7 @@ pub fn listAppend(list: RocList, alignment: usize, element: Opaque, element_widt
|
||||||
|
|
||||||
pub fn listDrop(
|
pub fn listDrop(
|
||||||
list: RocList,
|
list: RocList,
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
element_width: usize,
|
element_width: usize,
|
||||||
drop_count: usize,
|
drop_count: usize,
|
||||||
dec: Dec,
|
dec: Dec,
|
||||||
|
@ -883,7 +883,7 @@ pub fn listSortWith(
|
||||||
data: Opaque,
|
data: Opaque,
|
||||||
inc_n_data: IncN,
|
inc_n_data: IncN,
|
||||||
data_is_owned: bool,
|
data_is_owned: bool,
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
element_width: usize,
|
element_width: usize,
|
||||||
) callconv(.C) RocList {
|
) callconv(.C) RocList {
|
||||||
var list = input.makeUnique(alignment, element_width);
|
var list = input.makeUnique(alignment, element_width);
|
||||||
|
@ -947,7 +947,7 @@ fn swapElements(source_ptr: [*]u8, element_width: usize, index_1: usize, index_2
|
||||||
return swap(element_width, element_at_i, element_at_j);
|
return swap(element_width, element_at_i, element_at_j);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn listJoin(list_of_lists: RocList, alignment: usize, element_width: usize) callconv(.C) RocList {
|
pub fn listJoin(list_of_lists: RocList, alignment: u32, element_width: usize) callconv(.C) RocList {
|
||||||
var total_length: usize = 0;
|
var total_length: usize = 0;
|
||||||
|
|
||||||
const slice_of_lists = @ptrCast([*]RocList, @alignCast(@alignOf(RocList), list_of_lists.bytes));
|
const slice_of_lists = @ptrCast([*]RocList, @alignCast(@alignOf(RocList), list_of_lists.bytes));
|
||||||
|
@ -975,7 +975,7 @@ pub fn listJoin(list_of_lists: RocList, alignment: usize, element_width: usize)
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn listConcat(list_a: RocList, list_b: RocList, alignment: usize, element_width: usize) callconv(.C) RocList {
|
pub fn listConcat(list_a: RocList, list_b: RocList, alignment: u32, element_width: usize) callconv(.C) RocList {
|
||||||
if (list_a.isEmpty()) {
|
if (list_a.isEmpty()) {
|
||||||
return list_b;
|
return list_b;
|
||||||
} else if (list_b.isEmpty()) {
|
} else if (list_b.isEmpty()) {
|
||||||
|
|
|
@ -53,7 +53,7 @@ pub const RocStr = extern struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initBig(in_place: InPlace, number_of_chars: u64) RocStr {
|
pub fn initBig(in_place: InPlace, number_of_chars: u64) RocStr {
|
||||||
const first_element = utils.allocateWithRefcount(@sizeOf(usize), number_of_chars);
|
const first_element = utils.allocateWithRefcount(number_of_chars, @sizeOf(usize));
|
||||||
|
|
||||||
return RocStr{
|
return RocStr{
|
||||||
.str_bytes = first_element,
|
.str_bytes = first_element,
|
||||||
|
@ -99,7 +99,7 @@ pub const RocStr = extern struct {
|
||||||
if (length < roc_str_size) {
|
if (length < roc_str_size) {
|
||||||
return RocStr.empty();
|
return RocStr.empty();
|
||||||
} else {
|
} else {
|
||||||
var new_bytes: []T = utils.alloc(RocStr.alignment, length) catch unreachable;
|
var new_bytes: []T = utils.alloc(length, RocStr.alignment) catch unreachable;
|
||||||
|
|
||||||
var new_bytes_ptr: [*]u8 = @ptrCast([*]u8, &new_bytes);
|
var new_bytes_ptr: [*]u8 = @ptrCast([*]u8, &new_bytes);
|
||||||
|
|
||||||
|
@ -1070,7 +1070,7 @@ fn strToBytes(arg: RocStr) RocList {
|
||||||
return RocList.empty();
|
return RocList.empty();
|
||||||
} else if (arg.isSmallStr()) {
|
} else if (arg.isSmallStr()) {
|
||||||
const length = arg.len();
|
const length = arg.len();
|
||||||
const ptr = utils.allocateWithRefcount(RocStr.alignment, length);
|
const ptr = utils.allocateWithRefcount(length, RocStr.alignment);
|
||||||
|
|
||||||
@memcpy(ptr, arg.asU8ptr(), length);
|
@memcpy(ptr, arg.asU8ptr(), length);
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,14 @@ const std = @import("std");
|
||||||
const always_inline = std.builtin.CallOptions.Modifier.always_inline;
|
const always_inline = std.builtin.CallOptions.Modifier.always_inline;
|
||||||
|
|
||||||
// If allocation fails, this must cxa_throw - it must not return a null pointer!
|
// If allocation fails, this must cxa_throw - it must not return a null pointer!
|
||||||
extern fn roc_alloc(alignment: usize, size: usize) callconv(.C) *c_void;
|
extern fn roc_alloc(size: usize, alignment: u32) callconv(.C) *c_void;
|
||||||
|
|
||||||
// This should never be passed a null pointer.
|
// This should never be passed a null pointer.
|
||||||
// If allocation fails, this must cxa_throw - it must not return a null pointer!
|
// If allocation fails, this must cxa_throw - it must not return a null pointer!
|
||||||
extern fn roc_realloc(alignment: usize, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) *c_void;
|
extern fn roc_realloc(c_ptr: *c_void, new_size: usize, old_size: usize, alignment: u32) callconv(.C) *c_void;
|
||||||
|
|
||||||
// This should never be passed a null pointer.
|
// This should never be passed a null pointer.
|
||||||
extern fn roc_dealloc(alignment: usize, c_ptr: *c_void) callconv(.C) void;
|
extern fn roc_dealloc(c_ptr: *c_void, alignment: u32) callconv(.C) void;
|
||||||
|
|
||||||
comptime {
|
comptime {
|
||||||
// During tetsts, use the testing allocators to satisfy these functions.
|
// During tetsts, use the testing allocators to satisfy these functions.
|
||||||
|
@ -20,33 +20,33 @@ comptime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn testing_roc_alloc(alignment: usize, size: usize) callconv(.C) *c_void {
|
fn testing_roc_alloc(size: usize, alignment: u32) callconv(.C) *c_void {
|
||||||
return @ptrCast(*c_void, std.testing.allocator.alloc(u8, size) catch unreachable);
|
return @ptrCast(*c_void, std.testing.allocator.alloc(u8, size) catch unreachable);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn testing_roc_realloc(alignment: usize, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) *c_void {
|
fn testing_roc_realloc(c_ptr: *c_void, new_size: usize, old_size: usize, alignment: u32) callconv(.C) *c_void {
|
||||||
const ptr = @ptrCast([*]u8, @alignCast(16, c_ptr));
|
const ptr = @ptrCast([*]u8, @alignCast(16, c_ptr));
|
||||||
const slice = ptr[0..old_size];
|
const slice = ptr[0..old_size];
|
||||||
|
|
||||||
return @ptrCast(*c_void, std.testing.allocator.realloc(slice, new_size) catch unreachable);
|
return @ptrCast(*c_void, std.testing.allocator.realloc(slice, new_size) catch unreachable);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn testing_roc_dealloc(alignment: usize, c_ptr: *c_void) callconv(.C) void {
|
fn testing_roc_dealloc(c_ptr: *c_void, alignment: u32) callconv(.C) void {
|
||||||
const ptr = @ptrCast([*]u8, @alignCast(16, c_ptr));
|
const ptr = @ptrCast([*]u8, @alignCast(16, c_ptr));
|
||||||
|
|
||||||
std.testing.allocator.destroy(ptr);
|
std.testing.allocator.destroy(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn alloc(alignment: usize, size: usize) [*]u8 {
|
pub fn alloc(size: usize, alignment: u32) [*]u8 {
|
||||||
return @ptrCast([*]u8, @call(.{ .modifier = always_inline }, roc_alloc, .{ alignment, size }));
|
return @ptrCast([*]u8, @call(.{ .modifier = always_inline }, roc_alloc, .{ size, alignment }));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn realloc(alignment: usize, c_ptr: [*]u8, old_size: usize, new_size: usize) [*]u8 {
|
pub fn realloc(c_ptr: [*]u8, new_size: usize, old_size: usize, alignment: u32) [*]u8 {
|
||||||
return @ptrCast([*]u8, @call(.{ .modifier = always_inline }, roc_realloc, .{ alignment, c_ptr, old_size, new_size }));
|
return @ptrCast([*]u8, @call(.{ .modifier = always_inline }, roc_realloc, .{ c_ptr, new_size, old_size, alignment }));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dealloc(alignment: usize, c_ptr: [*]u8) void {
|
pub fn dealloc(c_ptr: [*]u8, alignment: u32) void {
|
||||||
return @call(.{ .modifier = always_inline }, roc_dealloc, .{ alignment, c_ptr });
|
return @call(.{ .modifier = always_inline }, roc_dealloc, .{ c_ptr, alignment });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const Inc = fn (?[*]u8) callconv(.C) void;
|
pub const Inc = fn (?[*]u8) callconv(.C) void;
|
||||||
|
@ -110,7 +110,7 @@ pub fn intWidth(width: IntWidth) anytype {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decref(
|
pub fn decref(
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
bytes_or_null: ?[*]u8,
|
bytes_or_null: ?[*]u8,
|
||||||
data_bytes: usize,
|
data_bytes: usize,
|
||||||
) void {
|
) void {
|
||||||
|
@ -128,7 +128,7 @@ pub fn decref(
|
||||||
switch (alignment) {
|
switch (alignment) {
|
||||||
16 => {
|
16 => {
|
||||||
if (refcount == REFCOUNT_ONE_ISIZE) {
|
if (refcount == REFCOUNT_ONE_ISIZE) {
|
||||||
dealloc(alignment, bytes - 16);
|
dealloc(bytes - 16, alignment);
|
||||||
} else if (refcount_isize < 0) {
|
} else if (refcount_isize < 0) {
|
||||||
(isizes - 1)[0] = refcount - 1;
|
(isizes - 1)[0] = refcount - 1;
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ pub fn decref(
|
||||||
else => {
|
else => {
|
||||||
// NOTE enums can currently have an alignment of < 8
|
// NOTE enums can currently have an alignment of < 8
|
||||||
if (refcount == REFCOUNT_ONE_ISIZE) {
|
if (refcount == REFCOUNT_ONE_ISIZE) {
|
||||||
dealloc(alignment, bytes - 8);
|
dealloc(bytes - 8, alignment);
|
||||||
} else if (refcount_isize < 0) {
|
} else if (refcount_isize < 0) {
|
||||||
(isizes - 1)[0] = refcount - 1;
|
(isizes - 1)[0] = refcount - 1;
|
||||||
}
|
}
|
||||||
|
@ -145,8 +145,8 @@ pub fn decref(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn allocateWithRefcount(
|
pub fn allocateWithRefcount(
|
||||||
alignment: usize,
|
|
||||||
data_bytes: usize,
|
data_bytes: usize,
|
||||||
|
alignment: u32,
|
||||||
) [*]u8 {
|
) [*]u8 {
|
||||||
comptime const result_in_place = false;
|
comptime const result_in_place = false;
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ pub fn allocateWithRefcount(
|
||||||
16 => {
|
16 => {
|
||||||
const length = 2 * @sizeOf(usize) + data_bytes;
|
const length = 2 * @sizeOf(usize) + data_bytes;
|
||||||
|
|
||||||
var new_bytes: [*]align(16) u8 = @alignCast(16, alloc(alignment, length));
|
var new_bytes: [*]align(16) u8 = @alignCast(16, alloc(length, alignment));
|
||||||
|
|
||||||
var as_usize_array = @ptrCast([*]usize, new_bytes);
|
var as_usize_array = @ptrCast([*]usize, new_bytes);
|
||||||
if (result_in_place) {
|
if (result_in_place) {
|
||||||
|
@ -173,7 +173,7 @@ pub fn allocateWithRefcount(
|
||||||
else => {
|
else => {
|
||||||
const length = @sizeOf(usize) + data_bytes;
|
const length = @sizeOf(usize) + data_bytes;
|
||||||
|
|
||||||
var new_bytes: [*]align(8) u8 = @alignCast(8, alloc(alignment, length));
|
var new_bytes: [*]align(8) u8 = @alignCast(8, alloc(length, alignment));
|
||||||
|
|
||||||
var as_isize_array = @ptrCast([*]isize, new_bytes);
|
var as_isize_array = @ptrCast([*]isize, new_bytes);
|
||||||
if (result_in_place) {
|
if (result_in_place) {
|
||||||
|
@ -192,7 +192,7 @@ pub fn allocateWithRefcount(
|
||||||
|
|
||||||
pub fn unsafeReallocate(
|
pub fn unsafeReallocate(
|
||||||
source_ptr: [*]u8,
|
source_ptr: [*]u8,
|
||||||
alignment: usize,
|
alignment: u32,
|
||||||
old_length: usize,
|
old_length: usize,
|
||||||
new_length: usize,
|
new_length: usize,
|
||||||
element_width: usize,
|
element_width: usize,
|
||||||
|
@ -211,7 +211,7 @@ pub fn unsafeReallocate(
|
||||||
// TODO handle out of memory
|
// TODO handle out of memory
|
||||||
// NOTE realloc will dealloc the original allocation
|
// NOTE realloc will dealloc the original allocation
|
||||||
const old_allocation = source_ptr - align_width;
|
const old_allocation = source_ptr - align_width;
|
||||||
const new_allocation = realloc(alignment, old_allocation, old_width, new_width);
|
const new_allocation = realloc(old_allocation, new_width, old_width, alignment);
|
||||||
|
|
||||||
const new_source = @ptrCast([*]u8, new_allocation) + align_width;
|
const new_source = @ptrCast([*]u8, new_allocation) + align_width;
|
||||||
return new_source;
|
return new_source;
|
||||||
|
|
|
@ -223,16 +223,31 @@ impl<'a, 'ctx, 'env> Env<'a, 'ctx, 'env> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn alignment_type(&self) -> IntType<'ctx> {
|
||||||
|
self.context.i32_type()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn alignment_const(&self, alignment: u32) -> IntValue<'ctx> {
|
||||||
|
self.alignment_type().const_int(alignment as u64, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn alignment_intvalue(&self, element_layout: &Layout<'a>) -> BasicValueEnum<'ctx> {
|
||||||
|
let alignment = element_layout.alignment_bytes(self.ptr_bytes);
|
||||||
|
let alignment_iv = self.alignment_const(alignment);
|
||||||
|
|
||||||
|
alignment_iv.into()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn call_alloc(
|
pub fn call_alloc(
|
||||||
&self,
|
&self,
|
||||||
alignment: u32,
|
|
||||||
number_of_bytes: IntValue<'ctx>,
|
number_of_bytes: IntValue<'ctx>,
|
||||||
|
alignment: u32,
|
||||||
) -> PointerValue<'ctx> {
|
) -> PointerValue<'ctx> {
|
||||||
let function = self.module.get_function("roc_alloc").unwrap();
|
let function = self.module.get_function("roc_alloc").unwrap();
|
||||||
let alignment = self.ptr_int().const_int(alignment as u64, false);
|
let alignment = self.alignment_const(alignment);
|
||||||
let call = self.builder.build_call(
|
let call = self.builder.build_call(
|
||||||
function,
|
function,
|
||||||
&[alignment.into(), number_of_bytes.into()],
|
&[number_of_bytes.into(), alignment.into()],
|
||||||
"roc_alloc",
|
"roc_alloc",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -245,12 +260,12 @@ impl<'a, 'ctx, 'env> Env<'a, 'ctx, 'env> {
|
||||||
// TODO check if alloc returned null; if so, runtime error for OOM!
|
// TODO check if alloc returned null; if so, runtime error for OOM!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn call_dealloc(&self, alignment: u32, ptr: PointerValue<'ctx>) -> InstructionValue<'ctx> {
|
pub fn call_dealloc(&self, ptr: PointerValue<'ctx>, alignment: u32) -> InstructionValue<'ctx> {
|
||||||
let function = self.module.get_function("roc_dealloc").unwrap();
|
let function = self.module.get_function("roc_dealloc").unwrap();
|
||||||
let alignment = self.ptr_int().const_int(alignment as u64, false);
|
let alignment = self.alignment_const(alignment);
|
||||||
let call =
|
let call =
|
||||||
self.builder
|
self.builder
|
||||||
.build_call(function, &[alignment.into(), ptr.into()], "roc_dealloc");
|
.build_call(function, &[ptr.into(), alignment.into()], "roc_dealloc");
|
||||||
|
|
||||||
call.set_call_convention(C_CALL_CONV);
|
call.set_call_convention(C_CALL_CONV);
|
||||||
|
|
||||||
|
@ -1698,7 +1713,7 @@ pub fn allocate_with_refcount_help<'a, 'ctx, 'env>(
|
||||||
"add_extra_bytes",
|
"add_extra_bytes",
|
||||||
);
|
);
|
||||||
|
|
||||||
env.call_alloc(layout.alignment_bytes(env.ptr_bytes), number_of_bytes)
|
env.call_alloc(number_of_bytes, layout.alignment_bytes(env.ptr_bytes))
|
||||||
};
|
};
|
||||||
|
|
||||||
// We must return a pointer to the first element:
|
// We must return a pointer to the first element:
|
||||||
|
|
|
@ -18,16 +18,6 @@ use inkwell::{AddressSpace, IntPredicate};
|
||||||
use roc_builtins::bitcode;
|
use roc_builtins::bitcode;
|
||||||
use roc_mono::layout::{Builtin, Layout, LayoutIds, MemoryMode};
|
use roc_mono::layout::{Builtin, Layout, LayoutIds, MemoryMode};
|
||||||
|
|
||||||
fn alignment_intvalue<'a, 'ctx, 'env>(
|
|
||||||
env: &Env<'a, 'ctx, 'env>,
|
|
||||||
element_layout: &Layout<'a>,
|
|
||||||
) -> BasicValueEnum<'ctx> {
|
|
||||||
let alignment = element_layout.alignment_bytes(env.ptr_bytes);
|
|
||||||
let alignment_iv = env.ptr_int().const_int(alignment as u64, false);
|
|
||||||
|
|
||||||
alignment_iv.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn list_returned_from_zig<'a, 'ctx, 'env>(
|
fn list_returned_from_zig<'a, 'ctx, 'env>(
|
||||||
env: &Env<'a, 'ctx, 'env>,
|
env: &Env<'a, 'ctx, 'env>,
|
||||||
output: BasicValueEnum<'ctx>,
|
output: BasicValueEnum<'ctx>,
|
||||||
|
@ -102,7 +92,7 @@ pub fn list_single<'a, 'ctx, 'env>(
|
||||||
call_bitcode_fn_returns_list(
|
call_bitcode_fn_returns_list(
|
||||||
env,
|
env,
|
||||||
&[
|
&[
|
||||||
alignment_intvalue(env, element_layout),
|
env.alignment_intvalue(element_layout),
|
||||||
pass_element_as_opaque(env, element),
|
pass_element_as_opaque(env, element),
|
||||||
layout_width(env, element_layout),
|
layout_width(env, element_layout),
|
||||||
],
|
],
|
||||||
|
@ -124,7 +114,7 @@ pub fn list_repeat<'a, 'ctx, 'env>(
|
||||||
env,
|
env,
|
||||||
&[
|
&[
|
||||||
list_len.into(),
|
list_len.into(),
|
||||||
alignment_intvalue(env, element_layout),
|
env.alignment_intvalue(element_layout),
|
||||||
pass_element_as_opaque(env, element),
|
pass_element_as_opaque(env, element),
|
||||||
layout_width(env, element_layout),
|
layout_width(env, element_layout),
|
||||||
inc_element_fn.as_global_value().as_pointer_value().into(),
|
inc_element_fn.as_global_value().as_pointer_value().into(),
|
||||||
|
@ -218,7 +208,7 @@ pub fn list_join<'a, 'ctx, 'env>(
|
||||||
env,
|
env,
|
||||||
&[
|
&[
|
||||||
pass_list_as_i128(env, outer_list),
|
pass_list_as_i128(env, outer_list),
|
||||||
alignment_intvalue(env, element_layout),
|
env.alignment_intvalue(element_layout),
|
||||||
layout_width(env, element_layout),
|
layout_width(env, element_layout),
|
||||||
],
|
],
|
||||||
&bitcode::LIST_JOIN,
|
&bitcode::LIST_JOIN,
|
||||||
|
@ -258,7 +248,7 @@ pub fn list_reverse<'a, 'ctx, 'env>(
|
||||||
env,
|
env,
|
||||||
&[
|
&[
|
||||||
pass_list_as_i128(env, list),
|
pass_list_as_i128(env, list),
|
||||||
alignment_intvalue(env, &element_layout),
|
env.alignment_intvalue(&element_layout),
|
||||||
layout_width(env, &element_layout),
|
layout_width(env, &element_layout),
|
||||||
],
|
],
|
||||||
&bitcode::LIST_REVERSE,
|
&bitcode::LIST_REVERSE,
|
||||||
|
@ -314,7 +304,7 @@ pub fn list_append<'a, 'ctx, 'env>(
|
||||||
env,
|
env,
|
||||||
&[
|
&[
|
||||||
pass_list_as_i128(env, original_wrapper.into()),
|
pass_list_as_i128(env, original_wrapper.into()),
|
||||||
alignment_intvalue(env, &element_layout),
|
env.alignment_intvalue(&element_layout),
|
||||||
pass_element_as_opaque(env, element),
|
pass_element_as_opaque(env, element),
|
||||||
layout_width(env, element_layout),
|
layout_width(env, element_layout),
|
||||||
],
|
],
|
||||||
|
@ -335,7 +325,7 @@ pub fn list_drop<'a, 'ctx, 'env>(
|
||||||
env,
|
env,
|
||||||
&[
|
&[
|
||||||
pass_list_as_i128(env, original_wrapper.into()),
|
pass_list_as_i128(env, original_wrapper.into()),
|
||||||
alignment_intvalue(env, &element_layout),
|
env.alignment_intvalue(&element_layout),
|
||||||
layout_width(env, &element_layout),
|
layout_width(env, &element_layout),
|
||||||
count.into(),
|
count.into(),
|
||||||
dec_element_fn.as_global_value().as_pointer_value().into(),
|
dec_element_fn.as_global_value().as_pointer_value().into(),
|
||||||
|
@ -344,7 +334,7 @@ pub fn list_drop<'a, 'ctx, 'env>(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// List.set : List elem, Int, elem -> List elem
|
/// List.set : List elem, Nat, elem -> List elem
|
||||||
pub fn list_set<'a, 'ctx, 'env>(
|
pub fn list_set<'a, 'ctx, 'env>(
|
||||||
parent: FunctionValue<'ctx>,
|
parent: FunctionValue<'ctx>,
|
||||||
args: &[(BasicValueEnum<'ctx>, &'a Layout<'a>)],
|
args: &[(BasicValueEnum<'ctx>, &'a Layout<'a>)],
|
||||||
|
@ -501,7 +491,7 @@ pub fn list_walk_generic<'a, 'ctx, 'env>(
|
||||||
roc_function_call.inc_n_data.into(),
|
roc_function_call.inc_n_data.into(),
|
||||||
roc_function_call.data_is_owned.into(),
|
roc_function_call.data_is_owned.into(),
|
||||||
pass_as_opaque(env, default_ptr),
|
pass_as_opaque(env, default_ptr),
|
||||||
alignment_intvalue(env, &element_layout),
|
env.alignment_intvalue(&element_layout),
|
||||||
layout_width(env, element_layout),
|
layout_width(env, element_layout),
|
||||||
layout_width(env, default_layout),
|
layout_width(env, default_layout),
|
||||||
pass_as_opaque(env, result_ptr),
|
pass_as_opaque(env, result_ptr),
|
||||||
|
@ -520,7 +510,7 @@ pub fn list_walk_generic<'a, 'ctx, 'env>(
|
||||||
roc_function_call.inc_n_data.into(),
|
roc_function_call.inc_n_data.into(),
|
||||||
roc_function_call.data_is_owned.into(),
|
roc_function_call.data_is_owned.into(),
|
||||||
pass_as_opaque(env, default_ptr),
|
pass_as_opaque(env, default_ptr),
|
||||||
alignment_intvalue(env, &element_layout),
|
env.alignment_intvalue(&element_layout),
|
||||||
layout_width(env, element_layout),
|
layout_width(env, element_layout),
|
||||||
layout_width(env, default_layout),
|
layout_width(env, default_layout),
|
||||||
dec_element_fn.as_global_value().as_pointer_value().into(),
|
dec_element_fn.as_global_value().as_pointer_value().into(),
|
||||||
|
@ -642,7 +632,7 @@ pub fn list_keep_if<'a, 'ctx, 'env>(
|
||||||
pass_as_opaque(env, roc_function_call.data),
|
pass_as_opaque(env, roc_function_call.data),
|
||||||
roc_function_call.inc_n_data.into(),
|
roc_function_call.inc_n_data.into(),
|
||||||
roc_function_call.data_is_owned.into(),
|
roc_function_call.data_is_owned.into(),
|
||||||
alignment_intvalue(env, &element_layout),
|
env.alignment_intvalue(&element_layout),
|
||||||
layout_width(env, element_layout),
|
layout_width(env, element_layout),
|
||||||
inc_element_fn.as_global_value().as_pointer_value().into(),
|
inc_element_fn.as_global_value().as_pointer_value().into(),
|
||||||
dec_element_fn.as_global_value().as_pointer_value().into(),
|
dec_element_fn.as_global_value().as_pointer_value().into(),
|
||||||
|
@ -678,7 +668,7 @@ pub fn list_keep_oks<'a, 'ctx, 'env>(
|
||||||
pass_as_opaque(env, roc_function_call.data),
|
pass_as_opaque(env, roc_function_call.data),
|
||||||
roc_function_call.inc_n_data.into(),
|
roc_function_call.inc_n_data.into(),
|
||||||
roc_function_call.data_is_owned.into(),
|
roc_function_call.data_is_owned.into(),
|
||||||
alignment_intvalue(env, &before_layout),
|
env.alignment_intvalue(&before_layout),
|
||||||
layout_width(env, before_layout),
|
layout_width(env, before_layout),
|
||||||
layout_width(env, result_layout),
|
layout_width(env, result_layout),
|
||||||
layout_width(env, after_layout),
|
layout_width(env, after_layout),
|
||||||
|
@ -715,7 +705,7 @@ pub fn list_keep_errs<'a, 'ctx, 'env>(
|
||||||
pass_as_opaque(env, roc_function_call.data),
|
pass_as_opaque(env, roc_function_call.data),
|
||||||
roc_function_call.inc_n_data.into(),
|
roc_function_call.inc_n_data.into(),
|
||||||
roc_function_call.data_is_owned.into(),
|
roc_function_call.data_is_owned.into(),
|
||||||
alignment_intvalue(env, &before_layout),
|
env.alignment_intvalue(&before_layout),
|
||||||
layout_width(env, before_layout),
|
layout_width(env, before_layout),
|
||||||
layout_width(env, result_layout),
|
layout_width(env, result_layout),
|
||||||
layout_width(env, after_layout),
|
layout_width(env, after_layout),
|
||||||
|
@ -762,7 +752,7 @@ pub fn list_keep_result<'a, 'ctx, 'env>(
|
||||||
pass_list_as_i128(env, list),
|
pass_list_as_i128(env, list),
|
||||||
pass_as_opaque(env, closure_data_ptr),
|
pass_as_opaque(env, closure_data_ptr),
|
||||||
stepper_caller.into(),
|
stepper_caller.into(),
|
||||||
alignment_intvalue(env, &before_layout),
|
env.alignment_intvalue(&before_layout),
|
||||||
layout_width(env, before_layout),
|
layout_width(env, before_layout),
|
||||||
layout_width(env, after_layout),
|
layout_width(env, after_layout),
|
||||||
layout_width(env, result_layout),
|
layout_width(env, result_layout),
|
||||||
|
@ -789,7 +779,7 @@ pub fn list_sort_with<'a, 'ctx, 'env>(
|
||||||
pass_as_opaque(env, roc_function_call.data),
|
pass_as_opaque(env, roc_function_call.data),
|
||||||
roc_function_call.inc_n_data.into(),
|
roc_function_call.inc_n_data.into(),
|
||||||
roc_function_call.data_is_owned.into(),
|
roc_function_call.data_is_owned.into(),
|
||||||
alignment_intvalue(env, &element_layout),
|
env.alignment_intvalue(&element_layout),
|
||||||
layout_width(env, element_layout),
|
layout_width(env, element_layout),
|
||||||
],
|
],
|
||||||
bitcode::LIST_SORT_WITH,
|
bitcode::LIST_SORT_WITH,
|
||||||
|
@ -812,7 +802,7 @@ pub fn list_map_with_index<'a, 'ctx, 'env>(
|
||||||
pass_as_opaque(env, roc_function_call.data),
|
pass_as_opaque(env, roc_function_call.data),
|
||||||
roc_function_call.inc_n_data.into(),
|
roc_function_call.inc_n_data.into(),
|
||||||
roc_function_call.data_is_owned.into(),
|
roc_function_call.data_is_owned.into(),
|
||||||
alignment_intvalue(env, &element_layout),
|
env.alignment_intvalue(&element_layout),
|
||||||
layout_width(env, element_layout),
|
layout_width(env, element_layout),
|
||||||
layout_width(env, return_layout),
|
layout_width(env, return_layout),
|
||||||
],
|
],
|
||||||
|
@ -836,7 +826,7 @@ pub fn list_map<'a, 'ctx, 'env>(
|
||||||
pass_as_opaque(env, roc_function_call.data),
|
pass_as_opaque(env, roc_function_call.data),
|
||||||
roc_function_call.inc_n_data.into(),
|
roc_function_call.inc_n_data.into(),
|
||||||
roc_function_call.data_is_owned.into(),
|
roc_function_call.data_is_owned.into(),
|
||||||
alignment_intvalue(env, &element_layout),
|
env.alignment_intvalue(&element_layout),
|
||||||
layout_width(env, element_layout),
|
layout_width(env, element_layout),
|
||||||
layout_width(env, return_layout),
|
layout_width(env, return_layout),
|
||||||
],
|
],
|
||||||
|
@ -866,7 +856,7 @@ pub fn list_map2<'a, 'ctx, 'env>(
|
||||||
pass_as_opaque(env, roc_function_call.data),
|
pass_as_opaque(env, roc_function_call.data),
|
||||||
roc_function_call.inc_n_data.into(),
|
roc_function_call.inc_n_data.into(),
|
||||||
roc_function_call.data_is_owned.into(),
|
roc_function_call.data_is_owned.into(),
|
||||||
alignment_intvalue(env, return_layout),
|
env.alignment_intvalue(return_layout),
|
||||||
layout_width(env, element1_layout),
|
layout_width(env, element1_layout),
|
||||||
layout_width(env, element2_layout),
|
layout_width(env, element2_layout),
|
||||||
layout_width(env, return_layout),
|
layout_width(env, return_layout),
|
||||||
|
@ -903,7 +893,7 @@ pub fn list_map3<'a, 'ctx, 'env>(
|
||||||
pass_as_opaque(env, roc_function_call.data),
|
pass_as_opaque(env, roc_function_call.data),
|
||||||
roc_function_call.inc_n_data.into(),
|
roc_function_call.inc_n_data.into(),
|
||||||
roc_function_call.data_is_owned.into(),
|
roc_function_call.data_is_owned.into(),
|
||||||
alignment_intvalue(env, result_layout),
|
env.alignment_intvalue(result_layout),
|
||||||
layout_width(env, element1_layout),
|
layout_width(env, element1_layout),
|
||||||
layout_width(env, element2_layout),
|
layout_width(env, element2_layout),
|
||||||
layout_width(env, element3_layout),
|
layout_width(env, element3_layout),
|
||||||
|
@ -936,7 +926,7 @@ pub fn list_concat<'a, 'ctx, 'env>(
|
||||||
&[
|
&[
|
||||||
pass_list_as_i128(env, first_list),
|
pass_list_as_i128(env, first_list),
|
||||||
pass_list_as_i128(env, second_list),
|
pass_list_as_i128(env, second_list),
|
||||||
alignment_intvalue(env, elem_layout),
|
env.alignment_intvalue(elem_layout),
|
||||||
layout_width(env, elem_layout),
|
layout_width(env, elem_layout),
|
||||||
],
|
],
|
||||||
&bitcode::LIST_CONCAT,
|
&bitcode::LIST_CONCAT,
|
||||||
|
|
|
@ -22,8 +22,8 @@ pub fn add_default_roc_externs<'ctx>(
|
||||||
// already been defined by the builtins, which rely on it.
|
// already been defined by the builtins, which rely on it.
|
||||||
let fn_val = module.get_function("roc_alloc").unwrap();
|
let fn_val = module.get_function("roc_alloc").unwrap();
|
||||||
let mut params = fn_val.get_param_iter();
|
let mut params = fn_val.get_param_iter();
|
||||||
let _alignment_arg = params.next().unwrap();
|
|
||||||
let size_arg = params.next().unwrap();
|
let size_arg = params.next().unwrap();
|
||||||
|
let _alignment_arg = params.next().unwrap();
|
||||||
|
|
||||||
debug_assert!(params.next().is_none());
|
debug_assert!(params.next().is_none());
|
||||||
|
|
||||||
|
@ -83,10 +83,10 @@ pub fn add_default_roc_externs<'ctx>(
|
||||||
// already been defined by the builtins, which rely on it.
|
// already been defined by the builtins, which rely on it.
|
||||||
let fn_val = module.get_function("roc_realloc").unwrap();
|
let fn_val = module.get_function("roc_realloc").unwrap();
|
||||||
let mut params = fn_val.get_param_iter();
|
let mut params = fn_val.get_param_iter();
|
||||||
let _alignment_arg = params.next().unwrap();
|
|
||||||
let ptr_arg = params.next().unwrap();
|
let ptr_arg = params.next().unwrap();
|
||||||
let _old_size_arg = params.next().unwrap();
|
|
||||||
let new_size_arg = params.next().unwrap();
|
let new_size_arg = params.next().unwrap();
|
||||||
|
let _old_size_arg = params.next().unwrap();
|
||||||
|
let _alignment_arg = params.next().unwrap();
|
||||||
|
|
||||||
debug_assert!(params.next().is_none());
|
debug_assert!(params.next().is_none());
|
||||||
|
|
||||||
|
@ -119,8 +119,8 @@ pub fn add_default_roc_externs<'ctx>(
|
||||||
// already been defined by the builtins, which rely on it.
|
// already been defined by the builtins, which rely on it.
|
||||||
let fn_val = module.get_function("roc_dealloc").unwrap();
|
let fn_val = module.get_function("roc_dealloc").unwrap();
|
||||||
let mut params = fn_val.get_param_iter();
|
let mut params = fn_val.get_param_iter();
|
||||||
let _alignment_arg = params.next().unwrap();
|
|
||||||
let ptr_arg = params.next().unwrap();
|
let ptr_arg = params.next().unwrap();
|
||||||
|
let _alignment_arg = params.next().unwrap();
|
||||||
|
|
||||||
debug_assert!(params.next().is_none());
|
debug_assert!(params.next().is_none());
|
||||||
|
|
||||||
|
|
|
@ -279,12 +279,12 @@ impl<'ctx> PointerToRefcount<'ctx> {
|
||||||
match alignment {
|
match alignment {
|
||||||
n if env.ptr_bytes == n => {
|
n if env.ptr_bytes == n => {
|
||||||
// the refcount ptr is also the ptr to the allocated region
|
// the refcount ptr is also the ptr to the allocated region
|
||||||
env.call_dealloc(alignment, ptr);
|
env.call_dealloc(ptr, alignment);
|
||||||
}
|
}
|
||||||
n if 2 * env.ptr_bytes == n => {
|
n if 2 * env.ptr_bytes == n => {
|
||||||
// we need to step back another ptr_bytes to get the allocated ptr
|
// we need to step back another ptr_bytes to get the allocated ptr
|
||||||
let allocated = Self::from_ptr_to_data(env, ptr);
|
let allocated = Self::from_ptr_to_data(env, ptr);
|
||||||
env.call_dealloc(alignment, allocated.value);
|
env.call_dealloc(allocated.value, alignment);
|
||||||
}
|
}
|
||||||
n => unreachable!("invalid extra_bytes {:?}", n),
|
n => unreachable!("invalid extra_bytes {:?}", n),
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,22 +8,22 @@ use indoc::indoc;
|
||||||
use roc_std::{RocList, RocStr};
|
use roc_std::{RocList, RocStr};
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_alloc(_alignment: u32, size: usize) -> *mut c_void {
|
pub unsafe fn roc_alloc(size: usize, _alignment: u32) -> *mut c_void {
|
||||||
libc::malloc(size)
|
libc::malloc(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_realloc(
|
pub unsafe fn roc_realloc(
|
||||||
_alignment: u32,
|
|
||||||
c_ptr: *mut c_void,
|
c_ptr: *mut c_void,
|
||||||
_old_size: usize,
|
|
||||||
new_size: usize,
|
new_size: usize,
|
||||||
|
_old_size: usize,
|
||||||
|
_alignment: u32,
|
||||||
) -> *mut c_void {
|
) -> *mut c_void {
|
||||||
libc::realloc(c_ptr, new_size)
|
libc::realloc(c_ptr, new_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_dealloc(_alignment: u32, c_ptr: *mut c_void) {
|
pub unsafe fn roc_dealloc(c_ptr: *mut c_void, _alignment: u32) {
|
||||||
libc::free(c_ptr)
|
libc::free(c_ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,22 +26,22 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_alloc(_alignment: u32, size: usize) -> *mut c_void {
|
pub unsafe fn roc_alloc(size: usize, _alignment: u32) -> *mut c_void {
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_realloc(
|
pub unsafe fn roc_realloc(
|
||||||
_alignment: u32,
|
|
||||||
c_ptr: *mut c_void,
|
c_ptr: *mut c_void,
|
||||||
_old_size: usize,
|
|
||||||
new_size: usize,
|
new_size: usize,
|
||||||
|
_old_size: usize,
|
||||||
|
_alignment: u32,
|
||||||
) -> *mut c_void {
|
) -> *mut c_void {
|
||||||
return realloc(c_ptr, new_size);
|
return realloc(c_ptr, new_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_dealloc(_alignment: u32, c_ptr: *mut c_void) {
|
pub unsafe fn roc_dealloc(c_ptr: *mut c_void, _alignment: u32) {
|
||||||
return free(c_ptr);
|
return free(c_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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: u32, size: usize) callconv(.C) ?*c_void {
|
export fn roc_alloc(size: usize, alignment: u32) callconv(.C) ?*c_void {
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn roc_realloc(alignment: u32, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void {
|
export fn roc_realloc(c_ptr: *c_void, new_size: usize, old_size: usize, alignment: u32) 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: u32, c_ptr: *c_void) callconv(.C) void {
|
export fn roc_dealloc(c_ptr: *c_void, alignment: u32) callconv(.C) void {
|
||||||
free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
|
free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,22 +32,22 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_alloc(_alignment: u32, size: usize) -> *mut c_void {
|
pub unsafe fn roc_alloc(size: usize, _alignment: u32) -> *mut c_void {
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_realloc(
|
pub unsafe fn roc_realloc(
|
||||||
_alignment: u32,
|
|
||||||
c_ptr: *mut c_void,
|
c_ptr: *mut c_void,
|
||||||
_old_size: usize,
|
|
||||||
new_size: usize,
|
new_size: usize,
|
||||||
|
_old_size: usize,
|
||||||
|
_alignment: u32,
|
||||||
) -> *mut c_void {
|
) -> *mut c_void {
|
||||||
return realloc(c_ptr, new_size);
|
return realloc(c_ptr, new_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_dealloc(_alignment: u32, c_ptr: *mut c_void) {
|
pub unsafe fn roc_dealloc(c_ptr: *mut c_void, _alignment: u32) {
|
||||||
return free(c_ptr);
|
return free(c_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ pub export fn main() u8 {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn roc_alloc(alignment: u32, size: usize) callconv(.C) ?*c_void {
|
export fn roc_alloc(size: usize, alignment: u32) 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: u32, size: usize) callconv(.C) ?*c_void {
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn roc_realloc(alignment: u32, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void {
|
export fn roc_realloc(c_ptr: *c_void, new_size: usize, old_size: usize, alignment: u32) 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: u32, c_ptr: *c_void) callconv(.C) void {
|
export fn roc_dealloc(c_ptr: *c_void, alignment: u32) callconv(.C) void {
|
||||||
const stdout = std.io.getStdOut().writer();
|
const stdout = std.io.getStdOut().writer();
|
||||||
const allocator = testing.allocator;
|
const allocator = testing.allocator;
|
||||||
|
|
||||||
|
|
|
@ -34,22 +34,22 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_alloc(_alignment: u32, size: usize) -> *mut c_void {
|
pub unsafe fn roc_alloc(size: usize, _alignment: u32) -> *mut c_void {
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_realloc(
|
pub unsafe fn roc_realloc(
|
||||||
_alignment: u32,
|
|
||||||
c_ptr: *mut c_void,
|
c_ptr: *mut c_void,
|
||||||
_old_size: usize,
|
|
||||||
new_size: usize,
|
new_size: usize,
|
||||||
|
_old_size: usize,
|
||||||
|
_alignment: u32,
|
||||||
) -> *mut c_void {
|
) -> *mut c_void {
|
||||||
return realloc(c_ptr, new_size);
|
return realloc(c_ptr, new_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_dealloc(_alignment: u32, c_ptr: *mut c_void) {
|
pub unsafe fn roc_dealloc(c_ptr: *mut c_void, _alignment: u32) {
|
||||||
return free(c_ptr);
|
return free(c_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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: u32, size: usize) callconv(.C) ?*c_void {
|
export fn roc_alloc(size: usize, alignment: u32) callconv(.C) ?*c_void {
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn roc_realloc(alignment: u32, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void {
|
export fn roc_realloc(c_ptr: *c_void, old_size: usize, new_size: usize, alignment: u32) 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: u32, c_ptr: *c_void) callconv(.C) void {
|
export fn roc_dealloc(c_ptr: *c_void, alignment: u32) callconv(.C) void {
|
||||||
free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
|
free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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: u32, size: usize) callconv(.C) ?*c_void {
|
export fn roc_alloc(size: usize, alignment: u32) callconv(.C) ?*c_void {
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn roc_realloc(alignment: u32, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void {
|
export fn roc_realloc(c_ptr: *c_void, new_size: usize, old_size: usize, alignment: u32) 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: u32, c_ptr: *c_void) callconv(.C) void {
|
export fn roc_dealloc(c_ptr: *c_void, alignment: u32) callconv(.C) void {
|
||||||
free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
|
free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,22 +15,22 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_alloc(_alignment: u32, size: usize) -> *mut c_void {
|
pub unsafe fn roc_alloc(size: usize, _alignment: u32) -> *mut c_void {
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_realloc(
|
pub unsafe fn roc_realloc(
|
||||||
_alignment: u32,
|
|
||||||
c_ptr: *mut c_void,
|
c_ptr: *mut c_void,
|
||||||
_old_size: usize,
|
|
||||||
new_size: usize,
|
new_size: usize,
|
||||||
|
_old_size: usize,
|
||||||
|
_alignment: u32,
|
||||||
) -> *mut c_void {
|
) -> *mut c_void {
|
||||||
return realloc(c_ptr, new_size);
|
return realloc(c_ptr, new_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_dealloc(_alignment: u32, c_ptr: *mut c_void) {
|
pub unsafe fn roc_dealloc(c_ptr: *mut c_void, _alignment: u32) {
|
||||||
return free(c_ptr);
|
return free(c_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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: u32, size: usize) callconv(.C) ?*c_void {
|
export fn roc_alloc(size: usize, alignment: u32) callconv(.C) ?*c_void {
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn roc_realloc(alignment: u32, c_ptr: *c_void, old_size: usize, new_size: usize) callconv(.C) ?*c_void {
|
export fn roc_realloc(c_ptr: *c_void, new_size: usize, old_size: usize, alignment: u32) 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: u32, c_ptr: *c_void) callconv(.C) void {
|
export fn roc_dealloc(c_ptr: *c_void, alignment: u32) callconv(.C) void {
|
||||||
free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
|
free(@alignCast(16, @ptrCast([*]u8, c_ptr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,22 +67,22 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_alloc(_alignment: u32, size: usize) -> *mut c_void {
|
pub unsafe fn roc_alloc(size: usize, _alignment: u32) -> *mut c_void {
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_realloc(
|
pub unsafe fn roc_realloc(
|
||||||
_alignment: u32,
|
|
||||||
c_ptr: *mut c_void,
|
c_ptr: *mut c_void,
|
||||||
_old_size: usize,
|
|
||||||
new_size: usize,
|
new_size: usize,
|
||||||
|
_old_size: usize,
|
||||||
|
_alignment: u32,
|
||||||
) -> *mut c_void {
|
) -> *mut c_void {
|
||||||
return realloc(c_ptr, new_size);
|
return realloc(c_ptr, new_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn roc_dealloc(_alignment: u32, c_ptr: *mut c_void) {
|
pub unsafe fn roc_dealloc(c_ptr: *mut c_void, _alignment: u32) {
|
||||||
return free(c_ptr);
|
return free(c_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,14 @@ pub mod alloca;
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn printf(format: *const u8, ...) -> i32;
|
pub fn printf(format: *const u8, ...) -> i32;
|
||||||
|
|
||||||
pub fn roc_alloc(alignment: usize, size: usize) -> *mut c_void;
|
pub fn roc_alloc(size: usize, alignment: u32) -> *mut c_void;
|
||||||
pub fn roc_realloc(
|
pub fn roc_realloc(
|
||||||
alignment: usize,
|
|
||||||
ptr: *mut c_void,
|
ptr: *mut c_void,
|
||||||
old_size: usize,
|
|
||||||
new_size: usize,
|
new_size: usize,
|
||||||
|
old_size: usize,
|
||||||
|
alignment: u32,
|
||||||
) -> *mut c_void;
|
) -> *mut c_void;
|
||||||
pub fn roc_dealloc(alignment: usize, ptr: *mut c_void);
|
pub fn roc_dealloc(ptr: *mut c_void, alignment: u32);
|
||||||
}
|
}
|
||||||
|
|
||||||
const REFCOUNT_1: usize = isize::MIN as usize;
|
const REFCOUNT_1: usize = isize::MIN as usize;
|
||||||
|
@ -148,7 +148,7 @@ impl<T> RocList<T> {
|
||||||
let num_bytes = core::mem::size_of::<usize>() + padding + element_bytes;
|
let num_bytes = core::mem::size_of::<usize>() + padding + element_bytes;
|
||||||
|
|
||||||
let elements = unsafe {
|
let elements = unsafe {
|
||||||
let raw_ptr = roc_alloc(core::mem::size_of::<usize>(), num_bytes) as *mut u8;
|
let raw_ptr = roc_alloc(num_bytes, core::mem::size_of::<usize>() as u32) as *mut u8;
|
||||||
|
|
||||||
// pointer to the first element
|
// pointer to the first element
|
||||||
let raw_ptr = Self::get_element_ptr(raw_ptr as *mut T) as *mut T;
|
let raw_ptr = Self::get_element_ptr(raw_ptr as *mut T) as *mut T;
|
||||||
|
@ -379,7 +379,7 @@ impl RocStr {
|
||||||
let num_bytes = core::mem::size_of::<usize>() + element_bytes;
|
let num_bytes = core::mem::size_of::<usize>() + element_bytes;
|
||||||
|
|
||||||
let elements = unsafe {
|
let elements = unsafe {
|
||||||
let raw_ptr = roc_alloc(core::mem::size_of::<usize>(), num_bytes) as *mut u8;
|
let raw_ptr = roc_alloc(num_bytes, core::mem::size_of::<usize>() as u32) as *mut u8;
|
||||||
// write the capacity
|
// write the capacity
|
||||||
let capacity_ptr = raw_ptr as *mut usize;
|
let capacity_ptr = raw_ptr as *mut usize;
|
||||||
*capacity_ptr = capacity;
|
*capacity_ptr = capacity;
|
||||||
|
@ -461,7 +461,7 @@ impl Clone for RocStr {
|
||||||
let capacity_size = core::mem::size_of::<usize>();
|
let capacity_size = core::mem::size_of::<usize>();
|
||||||
let copy_length = self.length + capacity_size;
|
let copy_length = self.length + capacity_size;
|
||||||
let elements = unsafe {
|
let elements = unsafe {
|
||||||
let raw = roc_alloc(core::mem::size_of::<usize>(), copy_length);
|
let raw = roc_alloc(copy_length, core::mem::size_of::<usize>() as u32);
|
||||||
|
|
||||||
libc::memcpy(
|
libc::memcpy(
|
||||||
raw,
|
raw,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue