mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-10 10:02:38 +03:00
standardize on decref instead of deinit for name
This commit is contained in:
parent
440c0518f1
commit
e32c5f6514
@ -115,7 +115,7 @@ pub export fn main() i32 {
|
||||
// stdout the result
|
||||
stdout.print("{s}\n", .{callresult.asSlice()}) catch unreachable;
|
||||
|
||||
callresult.deinit();
|
||||
callresult.decref();
|
||||
|
||||
stderr.print("runtime: {d:.3}ms\n", .{seconds * 1000}) catch unreachable;
|
||||
|
||||
|
@ -114,7 +114,7 @@ pub export fn main() i32 {
|
||||
// stdout the result
|
||||
stdout.print("{s}\n", .{callresult.asSlice()}) catch unreachable;
|
||||
|
||||
callresult.deinit();
|
||||
callresult.decref();
|
||||
|
||||
stderr.print("runtime: {d:.3}ms\n", .{seconds * 1000}) catch unreachable;
|
||||
|
||||
|
@ -115,7 +115,7 @@ pub export fn main() i32 {
|
||||
// stdout the result
|
||||
stdout.print("{s}\n", .{callresult.asSlice()}) catch unreachable;
|
||||
|
||||
callresult.deinit();
|
||||
callresult.decref();
|
||||
|
||||
stderr.print("runtime: {d:.3}ms\n", .{seconds * 1000}) catch unreachable;
|
||||
|
||||
|
@ -134,7 +134,7 @@ pub fn main() u8 {
|
||||
// stdout the result
|
||||
stdout.print("{s}", .{callresult.asSlice()}) catch unreachable;
|
||||
|
||||
callresult.deinit();
|
||||
callresult.decref();
|
||||
|
||||
stderr.print("runtime: {d:.3}ms\n", .{seconds * 1000}) catch unreachable;
|
||||
|
||||
|
@ -921,8 +921,8 @@ test "toStr: 123.1111111" {
|
||||
test "toStr: 123.1111111111111 (big str)" {
|
||||
var dec: RocDec = .{ .num = 123111111111111000000 };
|
||||
var res_roc_str = dec.toStr();
|
||||
errdefer res_roc_str.deinit();
|
||||
defer res_roc_str.deinit();
|
||||
errdefer res_roc_str.decref();
|
||||
defer res_roc_str.decref();
|
||||
|
||||
const res_slice: []const u8 = "123.111111111111"[0..];
|
||||
try expectEqualSlices(u8, res_slice, res_roc_str.asSlice());
|
||||
@ -931,8 +931,8 @@ test "toStr: 123.1111111111111 (big str)" {
|
||||
test "toStr: 123.111111111111444444 (max number of decimal places)" {
|
||||
var dec: RocDec = .{ .num = 123111111111111444444 };
|
||||
var res_roc_str = dec.toStr();
|
||||
errdefer res_roc_str.deinit();
|
||||
defer res_roc_str.deinit();
|
||||
errdefer res_roc_str.decref();
|
||||
defer res_roc_str.decref();
|
||||
|
||||
const res_slice: []const u8 = "123.111111111111444444"[0..];
|
||||
try expectEqualSlices(u8, res_slice, res_roc_str.asSlice());
|
||||
@ -941,8 +941,8 @@ test "toStr: 123.111111111111444444 (max number of decimal places)" {
|
||||
test "toStr: 12345678912345678912.111111111111111111 (max number of digits)" {
|
||||
var dec: RocDec = .{ .num = 12345678912345678912111111111111111111 };
|
||||
var res_roc_str = dec.toStr();
|
||||
errdefer res_roc_str.deinit();
|
||||
defer res_roc_str.deinit();
|
||||
errdefer res_roc_str.decref();
|
||||
defer res_roc_str.decref();
|
||||
|
||||
const res_slice: []const u8 = "12345678912345678912.111111111111111111"[0..];
|
||||
try expectEqualSlices(u8, res_slice, res_roc_str.asSlice());
|
||||
@ -951,8 +951,8 @@ test "toStr: 12345678912345678912.111111111111111111 (max number of digits)" {
|
||||
test "toStr: std.math.maxInt" {
|
||||
var dec: RocDec = .{ .num = std.math.maxInt(i128) };
|
||||
var res_roc_str = dec.toStr();
|
||||
errdefer res_roc_str.deinit();
|
||||
defer res_roc_str.deinit();
|
||||
errdefer res_roc_str.decref();
|
||||
defer res_roc_str.decref();
|
||||
|
||||
const res_slice: []const u8 = "170141183460469231731.687303715884105727"[0..];
|
||||
try expectEqualSlices(u8, res_slice, res_roc_str.asSlice());
|
||||
@ -961,8 +961,8 @@ test "toStr: std.math.maxInt" {
|
||||
test "toStr: std.math.minInt" {
|
||||
var dec: RocDec = .{ .num = std.math.minInt(i128) };
|
||||
var res_roc_str = dec.toStr();
|
||||
errdefer res_roc_str.deinit();
|
||||
defer res_roc_str.deinit();
|
||||
errdefer res_roc_str.decref();
|
||||
defer res_roc_str.decref();
|
||||
|
||||
const res_slice: []const u8 = "-170141183460469231731.687303715884105728"[0..];
|
||||
try expectEqualSlices(u8, res_slice, res_roc_str.asSlice());
|
||||
@ -1047,8 +1047,8 @@ test "div: 10 / 3" {
|
||||
var denom: RocDec = RocDec.fromU64(3);
|
||||
|
||||
var roc_str = RocStr.init("3.333333333333333333", 20);
|
||||
errdefer roc_str.deinit();
|
||||
defer roc_str.deinit();
|
||||
errdefer roc_str.decref();
|
||||
defer roc_str.decref();
|
||||
|
||||
var res: RocDec = RocDec.fromStr(roc_str).?;
|
||||
|
||||
|
@ -75,8 +75,8 @@ pub const RocList = extern struct {
|
||||
return list;
|
||||
}
|
||||
|
||||
pub fn deinit(self: RocList, alignment: u32) void {
|
||||
utils.decref(self.bytes, self.capacity, alignment);
|
||||
pub fn decref(self: RocList, alignment: u32) void {
|
||||
utils.decref(self.bytes, self.capacity(), alignment);
|
||||
}
|
||||
|
||||
pub fn elements(self: RocList, comptime T: type) ?[*]T {
|
||||
@ -128,7 +128,7 @@ pub const RocList = extern struct {
|
||||
@memcpy(new_bytes, old_bytes, number_of_bytes);
|
||||
|
||||
// NOTE we fuse an increment of all keys/values with a decrement of the input list.
|
||||
self.deinit(alignment);
|
||||
self.decref(alignment);
|
||||
|
||||
return new_list;
|
||||
}
|
||||
@ -192,7 +192,7 @@ pub const RocList = extern struct {
|
||||
@memset(dest_ptr + old_length * element_width, 0, delta_length * element_width);
|
||||
}
|
||||
|
||||
self.deinit(alignment);
|
||||
self.decref(alignment);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -573,7 +573,7 @@ pub fn listSublist(
|
||||
|
||||
@memcpy(target_ptr, source_ptr + start * element_width, keep_len * element_width);
|
||||
|
||||
list.deinit(alignment);
|
||||
list.decref(alignment);
|
||||
|
||||
return output;
|
||||
}
|
||||
@ -606,7 +606,7 @@ pub fn listDropAt(
|
||||
// because we rely on the pointer field being null if the list is empty
|
||||
// which also requires duplicating the utils.decref call to spend the RC token
|
||||
if (size < 2) {
|
||||
list.deinit(alignment);
|
||||
list.decref(alignment);
|
||||
return RocList.empty();
|
||||
}
|
||||
|
||||
@ -636,7 +636,7 @@ pub fn listDropAt(
|
||||
const tail_size = (size - drop_index - 1) * element_width;
|
||||
@memcpy(tail_target, tail_source, tail_size);
|
||||
|
||||
list.deinit(alignment);
|
||||
list.decref(alignment);
|
||||
|
||||
return output;
|
||||
} else {
|
||||
@ -750,7 +750,7 @@ pub fn listConcat(list_a: RocList, list_b: RocList, alignment: u32, element_widt
|
||||
return list_b;
|
||||
} else {
|
||||
// we must consume this list. Even though it has no elements, it could still have capacity
|
||||
list_b.deinit(alignment);
|
||||
list_b.decref(alignment);
|
||||
|
||||
return list_a;
|
||||
}
|
||||
@ -765,7 +765,7 @@ pub fn listConcat(list_a: RocList, list_b: RocList, alignment: u32, element_widt
|
||||
@memcpy(source_a + list_a.len() * element_width, source_b, list_b.len() * element_width);
|
||||
|
||||
// decrement list b.
|
||||
list_b.deinit(alignment);
|
||||
list_b.decref(alignment);
|
||||
|
||||
return resized_list_a;
|
||||
} else if (list_b.isUnique()) {
|
||||
@ -786,7 +786,7 @@ pub fn listConcat(list_a: RocList, list_b: RocList, alignment: u32, element_widt
|
||||
@memcpy(source_b, source_a, byte_count_a);
|
||||
|
||||
// decrement list a.
|
||||
list_a.deinit(alignment);
|
||||
list_a.decref(alignment);
|
||||
|
||||
return resized_list_b;
|
||||
}
|
||||
@ -803,8 +803,8 @@ pub fn listConcat(list_a: RocList, list_b: RocList, alignment: u32, element_widt
|
||||
@memcpy(target + list_a.len() * element_width, source_b, list_b.len() * element_width);
|
||||
|
||||
// decrement list a and b.
|
||||
list_a.deinit(alignment);
|
||||
list_b.deinit(alignment);
|
||||
list_a.decref(alignment);
|
||||
list_b.decref(alignment);
|
||||
|
||||
return output;
|
||||
}
|
||||
@ -873,14 +873,14 @@ test "listConcat: non-unique with unique overlapping" {
|
||||
const ptr_width = @sizeOf(usize);
|
||||
const refcount_ptr = @ptrCast([*]isize, @alignCast(ptr_width, bytes) - ptr_width);
|
||||
utils.increfC(&refcount_ptr[0], 1);
|
||||
defer nonUnique.deinit(@sizeOf(u8)); // listConcat will dec the other refcount
|
||||
defer nonUnique.decref(@sizeOf(u8)); // listConcat will dec the other refcount
|
||||
|
||||
var unique = RocList.fromSlice(u8, ([_]u8{ 2, 3, 4 })[0..]);
|
||||
defer unique.deinit(@sizeOf(u8));
|
||||
defer unique.decref(@sizeOf(u8));
|
||||
|
||||
var concatted = listConcat(nonUnique, unique, 1, 1);
|
||||
var wanted = RocList.fromSlice(u8, ([_]u8{ 1, 2, 3, 4 })[0..]);
|
||||
defer wanted.deinit(@sizeOf(u8));
|
||||
defer wanted.decref(@sizeOf(u8));
|
||||
|
||||
try expect(concatted.eql(wanted));
|
||||
}
|
||||
|
@ -89,11 +89,7 @@ pub const RocStr = extern struct {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deinit(self: RocStr) void {
|
||||
self.decref();
|
||||
}
|
||||
|
||||
fn decref(self: RocStr) void {
|
||||
pub fn decref(self: RocStr) void {
|
||||
if (!self.isSmallStr()) {
|
||||
utils.decref(self.str_bytes, self.str_capacity, RocStr.alignment);
|
||||
}
|
||||
@ -388,8 +384,8 @@ pub const RocStr = extern struct {
|
||||
|
||||
try expect(roc_str1.eq(roc_str2));
|
||||
|
||||
roc_str1.deinit();
|
||||
roc_str2.deinit();
|
||||
roc_str1.decref();
|
||||
roc_str2.decref();
|
||||
}
|
||||
|
||||
test "RocStr.eq: small, not equal, different length" {
|
||||
@ -404,8 +400,8 @@ pub const RocStr = extern struct {
|
||||
var roc_str2 = RocStr.init(str2_ptr, str2_len);
|
||||
|
||||
defer {
|
||||
roc_str1.deinit();
|
||||
roc_str2.deinit();
|
||||
roc_str1.decref();
|
||||
roc_str2.decref();
|
||||
}
|
||||
|
||||
try expect(!roc_str1.eq(roc_str2));
|
||||
@ -423,8 +419,8 @@ pub const RocStr = extern struct {
|
||||
var roc_str2 = RocStr.init(str2_ptr, str2_len);
|
||||
|
||||
defer {
|
||||
roc_str1.deinit();
|
||||
roc_str2.deinit();
|
||||
roc_str1.decref();
|
||||
roc_str2.decref();
|
||||
}
|
||||
|
||||
try expect(!roc_str1.eq(roc_str2));
|
||||
@ -436,8 +432,8 @@ pub const RocStr = extern struct {
|
||||
const roc_str2 = RocStr.init(content, content.len);
|
||||
|
||||
defer {
|
||||
roc_str1.deinit();
|
||||
roc_str2.deinit();
|
||||
roc_str1.decref();
|
||||
roc_str2.decref();
|
||||
}
|
||||
|
||||
try expect(roc_str1.eq(roc_str2));
|
||||
@ -450,8 +446,8 @@ pub const RocStr = extern struct {
|
||||
const roc_str2 = RocStr.init(content2, content2.len);
|
||||
|
||||
defer {
|
||||
roc_str1.deinit();
|
||||
roc_str2.deinit();
|
||||
roc_str1.decref();
|
||||
roc_str2.decref();
|
||||
}
|
||||
|
||||
try expect(!roc_str1.eq(roc_str2));
|
||||
@ -464,8 +460,8 @@ pub const RocStr = extern struct {
|
||||
const roc_str2 = RocStr.init(content2, content2.len);
|
||||
|
||||
defer {
|
||||
roc_str1.deinit();
|
||||
roc_str2.deinit();
|
||||
roc_str1.decref();
|
||||
roc_str2.decref();
|
||||
}
|
||||
|
||||
try expect(!roc_str1.eq(roc_str2));
|
||||
@ -484,8 +480,8 @@ pub const RocStr = extern struct {
|
||||
roc_str2.str_bytes.?[31] = '-';
|
||||
|
||||
defer {
|
||||
roc_str1.deinit();
|
||||
roc_str2.deinit();
|
||||
roc_str1.decref();
|
||||
roc_str2.decref();
|
||||
}
|
||||
|
||||
try expect(roc_str1.eq(roc_str2));
|
||||
@ -619,95 +615,95 @@ inline fn writeNextScalar(non_empty_string: RocStr, src_index: usize, dest: [*]u
|
||||
|
||||
test "strToScalars: empty string" {
|
||||
const str = RocStr.fromSlice("");
|
||||
defer RocStr.deinit(str);
|
||||
defer RocStr.decref(str);
|
||||
|
||||
const expected = RocList.empty();
|
||||
const actual = strToScalars(str);
|
||||
defer actual.deinit(@sizeOf(u32));
|
||||
defer actual.decref(@sizeOf(u32));
|
||||
|
||||
try expect(RocList.eql(actual, expected));
|
||||
}
|
||||
|
||||
test "strToScalars: One ASCII char" {
|
||||
const str = RocStr.fromSlice("R");
|
||||
defer RocStr.deinit(str);
|
||||
defer RocStr.decref(str);
|
||||
|
||||
const expected_array = [_]u32{82};
|
||||
const expected = RocList.fromSlice(u32, expected_array[0..expected_array.len]);
|
||||
defer expected.deinit(@sizeOf(u32));
|
||||
defer expected.decref(@sizeOf(u32));
|
||||
|
||||
const actual = strToScalars(str);
|
||||
defer actual.deinit(@sizeOf(u32));
|
||||
defer actual.decref(@sizeOf(u32));
|
||||
|
||||
try expect(RocList.eql(actual, expected));
|
||||
}
|
||||
|
||||
test "strToScalars: Multiple ASCII chars" {
|
||||
const str = RocStr.fromSlice("Roc!");
|
||||
defer RocStr.deinit(str);
|
||||
defer RocStr.decref(str);
|
||||
|
||||
const expected_array = [_]u32{ 82, 111, 99, 33 };
|
||||
const expected = RocList.fromSlice(u32, expected_array[0..expected_array.len]);
|
||||
defer expected.deinit(@sizeOf(u32));
|
||||
defer expected.decref(@sizeOf(u32));
|
||||
|
||||
const actual = strToScalars(str);
|
||||
defer actual.deinit(@sizeOf(u32));
|
||||
defer actual.decref(@sizeOf(u32));
|
||||
|
||||
try expect(RocList.eql(actual, expected));
|
||||
}
|
||||
|
||||
test "strToScalars: One 2-byte UTF-8 character" {
|
||||
const str = RocStr.fromSlice("é");
|
||||
defer RocStr.deinit(str);
|
||||
defer RocStr.decref(str);
|
||||
|
||||
const expected_array = [_]u32{233};
|
||||
const expected = RocList.fromSlice(u32, expected_array[0..expected_array.len]);
|
||||
defer expected.deinit(@sizeOf(u32));
|
||||
defer expected.decref(@sizeOf(u32));
|
||||
|
||||
const actual = strToScalars(str);
|
||||
defer actual.deinit(@sizeOf(u32));
|
||||
defer actual.decref(@sizeOf(u32));
|
||||
|
||||
try expect(RocList.eql(actual, expected));
|
||||
}
|
||||
|
||||
test "strToScalars: Multiple 2-byte UTF-8 characters" {
|
||||
const str = RocStr.fromSlice("Cäfés");
|
||||
defer RocStr.deinit(str);
|
||||
defer RocStr.decref(str);
|
||||
|
||||
const expected_array = [_]u32{ 67, 228, 102, 233, 115 };
|
||||
const expected = RocList.fromSlice(u32, expected_array[0..expected_array.len]);
|
||||
defer expected.deinit(@sizeOf(u32));
|
||||
defer expected.decref(@sizeOf(u32));
|
||||
|
||||
const actual = strToScalars(str);
|
||||
defer actual.deinit(@sizeOf(u32));
|
||||
defer actual.decref(@sizeOf(u32));
|
||||
|
||||
try expect(RocList.eql(actual, expected));
|
||||
}
|
||||
|
||||
test "strToScalars: One 3-byte UTF-8 character" {
|
||||
const str = RocStr.fromSlice("鹏");
|
||||
defer RocStr.deinit(str);
|
||||
defer RocStr.decref(str);
|
||||
|
||||
const expected_array = [_]u32{40527};
|
||||
const expected = RocList.fromSlice(u32, expected_array[0..expected_array.len]);
|
||||
defer expected.deinit(@sizeOf(u32));
|
||||
defer expected.decref(@sizeOf(u32));
|
||||
|
||||
const actual = strToScalars(str);
|
||||
defer actual.deinit(@sizeOf(u32));
|
||||
defer actual.decref(@sizeOf(u32));
|
||||
|
||||
try expect(RocList.eql(actual, expected));
|
||||
}
|
||||
|
||||
test "strToScalars: Multiple 3-byte UTF-8 characters" {
|
||||
const str = RocStr.fromSlice("鹏很有趣");
|
||||
defer RocStr.deinit(str);
|
||||
defer RocStr.decref(str);
|
||||
|
||||
const expected_array = [_]u32{ 40527, 24456, 26377, 36259 };
|
||||
const expected = RocList.fromSlice(u32, expected_array[0..expected_array.len]);
|
||||
defer expected.deinit(@sizeOf(u32));
|
||||
defer expected.decref(@sizeOf(u32));
|
||||
|
||||
const actual = strToScalars(str);
|
||||
defer actual.deinit(@sizeOf(u32));
|
||||
defer actual.decref(@sizeOf(u32));
|
||||
|
||||
try expect(RocList.eql(actual, expected));
|
||||
}
|
||||
@ -715,14 +711,14 @@ test "strToScalars: Multiple 3-byte UTF-8 characters" {
|
||||
test "strToScalars: One 4-byte UTF-8 character" {
|
||||
// from https://design215.com/toolbox/utf8-4byte-characters.php
|
||||
const str = RocStr.fromSlice("𒀀");
|
||||
defer RocStr.deinit(str);
|
||||
defer RocStr.decref(str);
|
||||
|
||||
const expected_array = [_]u32{73728};
|
||||
const expected = RocList.fromSlice(u32, expected_array[0..expected_array.len]);
|
||||
defer expected.deinit(@sizeOf(u32));
|
||||
defer expected.decref(@sizeOf(u32));
|
||||
|
||||
const actual = strToScalars(str);
|
||||
defer actual.deinit(@sizeOf(u32));
|
||||
defer actual.decref(@sizeOf(u32));
|
||||
|
||||
try expect(RocList.eql(actual, expected));
|
||||
}
|
||||
@ -730,14 +726,14 @@ test "strToScalars: One 4-byte UTF-8 character" {
|
||||
test "strToScalars: Multiple 4-byte UTF-8 characters" {
|
||||
// from https://design215.com/toolbox/utf8-4byte-characters.php
|
||||
const str = RocStr.fromSlice("𒀀𒀁");
|
||||
defer RocStr.deinit(str);
|
||||
defer RocStr.decref(str);
|
||||
|
||||
const expected_array = [_]u32{ 73728, 73729 };
|
||||
const expected = RocList.fromSlice(u32, expected_array[0..expected_array.len]);
|
||||
defer expected.deinit(@sizeOf(u32));
|
||||
defer expected.decref(@sizeOf(u32));
|
||||
|
||||
const actual = strToScalars(str);
|
||||
defer actual.deinit(@sizeOf(u32));
|
||||
defer actual.decref(@sizeOf(u32));
|
||||
|
||||
try expect(RocList.eql(actual, expected));
|
||||
}
|
||||
@ -871,15 +867,15 @@ test "strSplitHelp: empty delimiter" {
|
||||
|
||||
defer {
|
||||
for (array) |roc_str| {
|
||||
roc_str.deinit();
|
||||
roc_str.decref();
|
||||
}
|
||||
|
||||
for (expected) |roc_str| {
|
||||
roc_str.deinit();
|
||||
roc_str.decref();
|
||||
}
|
||||
|
||||
str.deinit();
|
||||
delimiter.deinit();
|
||||
str.decref();
|
||||
delimiter.decref();
|
||||
}
|
||||
|
||||
try expectEqual(array.len, expected.len);
|
||||
@ -905,15 +901,15 @@ test "strSplitHelp: no delimiter" {
|
||||
|
||||
defer {
|
||||
for (array) |roc_str| {
|
||||
roc_str.deinit();
|
||||
roc_str.decref();
|
||||
}
|
||||
|
||||
for (expected) |roc_str| {
|
||||
roc_str.deinit();
|
||||
roc_str.decref();
|
||||
}
|
||||
|
||||
str.deinit();
|
||||
delimiter.deinit();
|
||||
str.decref();
|
||||
delimiter.decref();
|
||||
}
|
||||
|
||||
try expectEqual(array.len, expected.len);
|
||||
@ -944,15 +940,15 @@ test "strSplitHelp: empty start" {
|
||||
|
||||
defer {
|
||||
for (array) |rocStr| {
|
||||
rocStr.deinit();
|
||||
rocStr.decref();
|
||||
}
|
||||
|
||||
for (expected) |rocStr| {
|
||||
rocStr.deinit();
|
||||
rocStr.decref();
|
||||
}
|
||||
|
||||
str.deinit();
|
||||
delimiter.deinit();
|
||||
str.decref();
|
||||
delimiter.decref();
|
||||
}
|
||||
|
||||
try expectEqual(array.len, expected.len);
|
||||
@ -986,15 +982,15 @@ test "strSplitHelp: empty end" {
|
||||
|
||||
defer {
|
||||
for (array) |rocStr| {
|
||||
rocStr.deinit();
|
||||
rocStr.decref();
|
||||
}
|
||||
|
||||
for (expected) |rocStr| {
|
||||
rocStr.deinit();
|
||||
rocStr.decref();
|
||||
}
|
||||
|
||||
str.deinit();
|
||||
delimiter.deinit();
|
||||
str.decref();
|
||||
delimiter.decref();
|
||||
}
|
||||
|
||||
try expectEqual(array.len, expected.len);
|
||||
@ -1020,14 +1016,14 @@ test "strSplitHelp: string equals delimiter" {
|
||||
|
||||
defer {
|
||||
for (array) |rocStr| {
|
||||
rocStr.deinit();
|
||||
rocStr.decref();
|
||||
}
|
||||
|
||||
for (expected) |rocStr| {
|
||||
rocStr.deinit();
|
||||
rocStr.decref();
|
||||
}
|
||||
|
||||
str_delimiter.deinit();
|
||||
str_delimiter.decref();
|
||||
}
|
||||
|
||||
try expectEqual(array.len, expected.len);
|
||||
@ -1060,15 +1056,15 @@ test "strSplitHelp: delimiter on sides" {
|
||||
|
||||
defer {
|
||||
for (array) |rocStr| {
|
||||
rocStr.deinit();
|
||||
rocStr.decref();
|
||||
}
|
||||
|
||||
for (expected) |rocStr| {
|
||||
rocStr.deinit();
|
||||
rocStr.decref();
|
||||
}
|
||||
|
||||
str.deinit();
|
||||
delimiter.deinit();
|
||||
str.decref();
|
||||
delimiter.decref();
|
||||
}
|
||||
|
||||
try expectEqual(array.len, expected.len);
|
||||
@ -1101,15 +1097,15 @@ test "strSplitHelp: three pieces" {
|
||||
|
||||
defer {
|
||||
for (array) |roc_str| {
|
||||
roc_str.deinit();
|
||||
roc_str.decref();
|
||||
}
|
||||
|
||||
for (expected_array) |roc_str| {
|
||||
roc_str.deinit();
|
||||
roc_str.decref();
|
||||
}
|
||||
|
||||
str.deinit();
|
||||
delimiter.deinit();
|
||||
str.decref();
|
||||
delimiter.decref();
|
||||
}
|
||||
|
||||
try expectEqual(expected_array.len, array.len);
|
||||
@ -1226,8 +1222,8 @@ test "countSegments: long delimiter" {
|
||||
const delimiter = RocStr.init(delimiter_arr, delimiter_arr.len);
|
||||
|
||||
defer {
|
||||
str.deinit();
|
||||
delimiter.deinit();
|
||||
str.decref();
|
||||
delimiter.decref();
|
||||
}
|
||||
|
||||
const segments_count = countSegments(str, delimiter);
|
||||
@ -1244,8 +1240,8 @@ test "countSegments: delimiter at start" {
|
||||
const delimiter = RocStr.init(delimiter_arr, delimiter_arr.len);
|
||||
|
||||
defer {
|
||||
str.deinit();
|
||||
delimiter.deinit();
|
||||
str.decref();
|
||||
delimiter.decref();
|
||||
}
|
||||
|
||||
const segments_count = countSegments(str, delimiter);
|
||||
@ -1263,8 +1259,8 @@ test "countSegments: delimiter interspered" {
|
||||
const delimiter = RocStr.init(delimiter_arr, delimiter_arr.len);
|
||||
|
||||
defer {
|
||||
str.deinit();
|
||||
delimiter.deinit();
|
||||
str.decref();
|
||||
delimiter.decref();
|
||||
}
|
||||
|
||||
const segments_count = countSegments(str, delimiter);
|
||||
@ -1279,7 +1275,7 @@ test "countSegments: string equals delimiter" {
|
||||
const str_delimiter = RocStr.init(str_delimiter_arr, str_delimiter_arr.len);
|
||||
|
||||
defer {
|
||||
str_delimiter.deinit();
|
||||
str_delimiter.decref();
|
||||
}
|
||||
|
||||
const segments_count = countSegments(str_delimiter, str_delimiter);
|
||||
@ -1372,12 +1368,12 @@ pub fn strGraphemes(roc_str: RocStr) callconv(.C) RocList {
|
||||
// these test both countGraphemeClusters() and strGraphemes()
|
||||
fn graphemesTest(input: []const u8, expected: []const []const u8) !void {
|
||||
const rocstr = RocStr.fromSlice(input);
|
||||
defer rocstr.deinit();
|
||||
defer rocstr.decref();
|
||||
const count = countGraphemeClusters(rocstr);
|
||||
try expectEqual(expected.len, count);
|
||||
|
||||
const graphemes = strGraphemes(rocstr);
|
||||
defer graphemes.deinit(@sizeOf(u8));
|
||||
defer graphemes.decref(@sizeOf(u8));
|
||||
if (input.len == 0) return; // empty string
|
||||
const elems = graphemes.elements(RocStr) orelse unreachable;
|
||||
for (expected) |g, i| {
|
||||
@ -1428,10 +1424,10 @@ pub fn getUnsafe(string: RocStr, index: usize) callconv(.C) u8 {
|
||||
|
||||
test "substringUnsafe: start" {
|
||||
const str = RocStr.fromSlice("abcdef");
|
||||
defer str.deinit();
|
||||
defer str.decref();
|
||||
|
||||
const expected = RocStr.fromSlice("abc");
|
||||
defer expected.deinit();
|
||||
defer expected.decref();
|
||||
|
||||
const actual = substringUnsafe(str, 0, 3);
|
||||
|
||||
@ -1440,10 +1436,10 @@ test "substringUnsafe: start" {
|
||||
|
||||
test "substringUnsafe: middle" {
|
||||
const str = RocStr.fromSlice("abcdef");
|
||||
defer str.deinit();
|
||||
defer str.decref();
|
||||
|
||||
const expected = RocStr.fromSlice("bcd");
|
||||
defer expected.deinit();
|
||||
defer expected.decref();
|
||||
|
||||
const actual = substringUnsafe(str, 1, 3);
|
||||
|
||||
@ -1452,10 +1448,10 @@ test "substringUnsafe: middle" {
|
||||
|
||||
test "substringUnsafe: end" {
|
||||
const str = RocStr.fromSlice("a string so long it is heap-allocated");
|
||||
defer str.deinit();
|
||||
defer str.decref();
|
||||
|
||||
const expected = RocStr.fromSlice("heap-allocated");
|
||||
defer expected.deinit();
|
||||
defer expected.decref();
|
||||
|
||||
const actual = substringUnsafe(str, 23, 37 - 23);
|
||||
|
||||
@ -1547,15 +1543,15 @@ test "startsWith: foo starts with fo" {
|
||||
|
||||
test "startsWith: 123456789123456789 starts with 123456789123456789" {
|
||||
const str = RocStr.fromSlice("123456789123456789");
|
||||
defer str.deinit();
|
||||
defer str.decref();
|
||||
try expect(startsWith(str, str));
|
||||
}
|
||||
|
||||
test "startsWith: 12345678912345678910 starts with 123456789123456789" {
|
||||
const str = RocStr.fromSlice("12345678912345678910");
|
||||
defer str.deinit();
|
||||
defer str.decref();
|
||||
const prefix = RocStr.fromSlice("123456789123456789");
|
||||
defer prefix.deinit();
|
||||
defer prefix.decref();
|
||||
|
||||
try expect(startsWith(str, prefix));
|
||||
}
|
||||
@ -1586,23 +1582,23 @@ pub fn endsWith(string: RocStr, suffix: RocStr) callconv(.C) bool {
|
||||
test "endsWith: foo ends with oo" {
|
||||
const foo = RocStr.init("foo", 3);
|
||||
const oo = RocStr.init("oo", 2);
|
||||
defer foo.deinit();
|
||||
defer oo.deinit();
|
||||
defer foo.decref();
|
||||
defer oo.decref();
|
||||
|
||||
try expect(endsWith(foo, oo));
|
||||
}
|
||||
|
||||
test "endsWith: 123456789123456789 ends with 123456789123456789" {
|
||||
const str = RocStr.init("123456789123456789", 18);
|
||||
defer str.deinit();
|
||||
defer str.decref();
|
||||
try expect(endsWith(str, str));
|
||||
}
|
||||
|
||||
test "endsWith: 12345678912345678910 ends with 345678912345678910" {
|
||||
const str = RocStr.init("12345678912345678910", 20);
|
||||
const suffix = RocStr.init("345678912345678910", 18);
|
||||
defer str.deinit();
|
||||
defer suffix.deinit();
|
||||
defer str.decref();
|
||||
defer suffix.decref();
|
||||
|
||||
try expect(endsWith(str, suffix));
|
||||
}
|
||||
@ -1610,8 +1606,8 @@ test "endsWith: 12345678912345678910 ends with 345678912345678910" {
|
||||
test "endsWith: hello world ends with world" {
|
||||
const str = RocStr.init("hello world", 11);
|
||||
const suffix = RocStr.init("world", 5);
|
||||
defer str.deinit();
|
||||
defer suffix.deinit();
|
||||
defer str.decref();
|
||||
defer suffix.decref();
|
||||
|
||||
try expect(endsWith(str, suffix));
|
||||
}
|
||||
@ -1654,14 +1650,14 @@ test "RocStr.concat: small concat small" {
|
||||
var roc_str3 = RocStr.init(str3_ptr, str3_len);
|
||||
|
||||
defer {
|
||||
roc_str1.deinit();
|
||||
roc_str2.deinit();
|
||||
roc_str3.deinit();
|
||||
roc_str1.decref();
|
||||
roc_str2.decref();
|
||||
roc_str3.decref();
|
||||
}
|
||||
|
||||
const result = strConcat(roc_str1, roc_str2);
|
||||
|
||||
defer result.deinit();
|
||||
defer result.decref();
|
||||
|
||||
try expect(roc_str3.eq(result));
|
||||
}
|
||||
@ -1744,14 +1740,14 @@ test "RocStr.joinWith: result is big" {
|
||||
};
|
||||
|
||||
defer {
|
||||
roc_sep.deinit();
|
||||
roc_elem.deinit();
|
||||
roc_result.deinit();
|
||||
roc_sep.decref();
|
||||
roc_elem.decref();
|
||||
roc_result.decref();
|
||||
}
|
||||
|
||||
const result = strJoinWith(list, roc_sep);
|
||||
|
||||
defer result.deinit();
|
||||
defer result.decref();
|
||||
|
||||
try expect(roc_result.eq(result));
|
||||
}
|
||||
@ -1802,7 +1798,7 @@ inline fn fromUtf8(arg: RocList, update_mode: UpdateMode) FromUtf8Result {
|
||||
const string = RocStr.init(@ptrCast([*]u8, arg.bytes), arg.len());
|
||||
|
||||
// then decrement the input list
|
||||
arg.deinit(RocStr.alignment);
|
||||
arg.decref(RocStr.alignment);
|
||||
|
||||
return FromUtf8Result{
|
||||
.is_ok = true,
|
||||
@ -1830,7 +1826,7 @@ inline fn fromUtf8(arg: RocList, update_mode: UpdateMode) FromUtf8Result {
|
||||
const temp = errorToProblem(@ptrCast([*]u8, arg.bytes), arg.length);
|
||||
|
||||
// consume the input list
|
||||
arg.deinit(RocStr.alignment);
|
||||
arg.decref(RocStr.alignment);
|
||||
|
||||
return FromUtf8Result{
|
||||
.is_ok = false,
|
||||
@ -1877,7 +1873,7 @@ pub fn fromUtf8Range(arg: RocList, start: usize, count: usize, update_mode: Upda
|
||||
const string = RocStr.init(@ptrCast([*]const u8, bytes), count);
|
||||
|
||||
// decref the list
|
||||
arg.deinit(RocStr.alignment);
|
||||
arg.decref(RocStr.alignment);
|
||||
|
||||
return FromUtf8Result{
|
||||
.is_ok = true,
|
||||
@ -1890,7 +1886,7 @@ pub fn fromUtf8Range(arg: RocList, start: usize, count: usize, update_mode: Upda
|
||||
const temp = errorToProblem(@ptrCast([*]u8, arg.bytes), arg.length);
|
||||
|
||||
// decref the list
|
||||
arg.deinit(RocStr.alignment);
|
||||
arg.decref(RocStr.alignment);
|
||||
|
||||
return FromUtf8Result{
|
||||
.is_ok = false,
|
||||
@ -2158,7 +2154,7 @@ pub fn strTrim(input_string: RocStr) callconv(.C) RocStr {
|
||||
var string = input_string;
|
||||
|
||||
if (string.isEmpty()) {
|
||||
string.deinit();
|
||||
string.decref();
|
||||
return RocStr.empty();
|
||||
}
|
||||
|
||||
@ -2168,7 +2164,7 @@ pub fn strTrim(input_string: RocStr) callconv(.C) RocStr {
|
||||
const original_len = string.len();
|
||||
|
||||
if (original_len == leading_bytes) {
|
||||
string.deinit();
|
||||
string.decref();
|
||||
return RocStr.empty();
|
||||
}
|
||||
|
||||
@ -2209,7 +2205,7 @@ pub fn strTrimLeft(input_string: RocStr) callconv(.C) RocStr {
|
||||
var string = input_string;
|
||||
|
||||
if (string.isEmpty()) {
|
||||
string.deinit();
|
||||
string.decref();
|
||||
return RocStr.empty();
|
||||
}
|
||||
|
||||
@ -2219,7 +2215,7 @@ pub fn strTrimLeft(input_string: RocStr) callconv(.C) RocStr {
|
||||
const original_len = string.len();
|
||||
|
||||
if (original_len == leading_bytes) {
|
||||
string.deinit();
|
||||
string.decref();
|
||||
return RocStr.empty();
|
||||
}
|
||||
|
||||
@ -2259,7 +2255,7 @@ pub fn strTrimRight(input_string: RocStr) callconv(.C) RocStr {
|
||||
var string = input_string;
|
||||
|
||||
if (string.isEmpty()) {
|
||||
string.deinit();
|
||||
string.decref();
|
||||
return RocStr.empty();
|
||||
}
|
||||
|
||||
@ -2269,7 +2265,7 @@ pub fn strTrimRight(input_string: RocStr) callconv(.C) RocStr {
|
||||
const original_len = string.len();
|
||||
|
||||
if (original_len == trailing_bytes) {
|
||||
string.deinit();
|
||||
string.decref();
|
||||
return RocStr.empty();
|
||||
}
|
||||
|
||||
@ -2405,13 +2401,13 @@ test "strTrim: null byte" {
|
||||
try expectEqual(@as(usize, SMALL_STR_MAX_LENGTH), original.getCapacity());
|
||||
|
||||
const original_with_capacity = reserve(original, 40);
|
||||
defer original_with_capacity.deinit();
|
||||
defer original_with_capacity.decref();
|
||||
|
||||
try expectEqual(@as(usize, 1), original_with_capacity.len());
|
||||
try expectEqual(@as(usize, 64), original_with_capacity.getCapacity());
|
||||
|
||||
const trimmed = strTrim(original.clone());
|
||||
defer trimmed.deinit();
|
||||
defer trimmed.decref();
|
||||
|
||||
try expect(original.eq(trimmed));
|
||||
}
|
||||
@ -2419,7 +2415,7 @@ test "strTrim: null byte" {
|
||||
test "strTrim: blank" {
|
||||
const original_bytes = " ";
|
||||
const original = RocStr.init(original_bytes, original_bytes.len);
|
||||
defer original.deinit();
|
||||
defer original.decref();
|
||||
|
||||
const trimmed = strTrim(original);
|
||||
|
||||
@ -2429,13 +2425,13 @@ test "strTrim: blank" {
|
||||
test "strTrim: large to large" {
|
||||
const original_bytes = " hello even more giant world ";
|
||||
const original = RocStr.init(original_bytes, original_bytes.len);
|
||||
defer original.deinit();
|
||||
defer original.decref();
|
||||
|
||||
try expect(!original.isSmallStr());
|
||||
|
||||
const expected_bytes = "hello even more giant world";
|
||||
const expected = RocStr.init(expected_bytes, expected_bytes.len);
|
||||
defer expected.deinit();
|
||||
defer expected.decref();
|
||||
|
||||
try expect(!expected.isSmallStr());
|
||||
|
||||
@ -2447,13 +2443,13 @@ test "strTrim: large to large" {
|
||||
test "strTrim: large to small" {
|
||||
const original_bytes = " hello ";
|
||||
const original = RocStr.init(original_bytes, original_bytes.len);
|
||||
defer original.deinit();
|
||||
defer original.decref();
|
||||
|
||||
try expect(!original.isSmallStr());
|
||||
|
||||
const expected_bytes = "hello";
|
||||
const expected = RocStr.init(expected_bytes, expected_bytes.len);
|
||||
defer expected.deinit();
|
||||
defer expected.decref();
|
||||
|
||||
try expect(expected.isSmallStr());
|
||||
|
||||
@ -2469,13 +2465,13 @@ test "strTrim: large to small" {
|
||||
test "strTrim: small to small" {
|
||||
const original_bytes = " hello ";
|
||||
const original = RocStr.init(original_bytes, original_bytes.len);
|
||||
defer original.deinit();
|
||||
defer original.decref();
|
||||
|
||||
try expect(original.isSmallStr());
|
||||
|
||||
const expected_bytes = "hello";
|
||||
const expected = RocStr.init(expected_bytes, expected_bytes.len);
|
||||
defer expected.deinit();
|
||||
defer expected.decref();
|
||||
|
||||
try expect(expected.isSmallStr());
|
||||
|
||||
@ -2493,7 +2489,7 @@ test "strTrimLeft: empty" {
|
||||
test "strTrimLeft: blank" {
|
||||
const original_bytes = " ";
|
||||
const original = RocStr.init(original_bytes, original_bytes.len);
|
||||
defer original.deinit();
|
||||
defer original.decref();
|
||||
|
||||
const trimmed = strTrimLeft(original);
|
||||
|
||||
@ -2503,13 +2499,13 @@ test "strTrimLeft: blank" {
|
||||
test "strTrimLeft: large to large" {
|
||||
const original_bytes = " hello even more giant world ";
|
||||
const original = RocStr.init(original_bytes, original_bytes.len);
|
||||
defer original.deinit();
|
||||
defer original.decref();
|
||||
|
||||
try expect(!original.isSmallStr());
|
||||
|
||||
const expected_bytes = "hello even more giant world ";
|
||||
const expected = RocStr.init(expected_bytes, expected_bytes.len);
|
||||
defer expected.deinit();
|
||||
defer expected.decref();
|
||||
|
||||
try expect(!expected.isSmallStr());
|
||||
|
||||
@ -2527,12 +2523,12 @@ test "strTrimLeft: large to small" {
|
||||
|
||||
const expected_bytes = "hello ";
|
||||
const expected = RocStr.init(expected_bytes, expected_bytes.len);
|
||||
defer expected.deinit();
|
||||
defer expected.decref();
|
||||
|
||||
try expect(expected.isSmallStr());
|
||||
|
||||
const trimmed = strTrimLeft(original);
|
||||
defer trimmed.deinit();
|
||||
defer trimmed.decref();
|
||||
|
||||
try expect(trimmed.eq(expected));
|
||||
try expect(!trimmed.isSmallStr());
|
||||
@ -2541,13 +2537,13 @@ test "strTrimLeft: large to small" {
|
||||
test "strTrimLeft: small to small" {
|
||||
const original_bytes = " hello ";
|
||||
const original = RocStr.init(original_bytes, original_bytes.len);
|
||||
defer original.deinit();
|
||||
defer original.decref();
|
||||
|
||||
try expect(original.isSmallStr());
|
||||
|
||||
const expected_bytes = "hello ";
|
||||
const expected = RocStr.init(expected_bytes, expected_bytes.len);
|
||||
defer expected.deinit();
|
||||
defer expected.decref();
|
||||
|
||||
try expect(expected.isSmallStr());
|
||||
|
||||
@ -2565,7 +2561,7 @@ test "strTrimRight: empty" {
|
||||
test "strTrimRight: blank" {
|
||||
const original_bytes = " ";
|
||||
const original = RocStr.init(original_bytes, original_bytes.len);
|
||||
defer original.deinit();
|
||||
defer original.decref();
|
||||
|
||||
const trimmed = strTrimRight(original);
|
||||
|
||||
@ -2575,13 +2571,13 @@ test "strTrimRight: blank" {
|
||||
test "strTrimRight: large to large" {
|
||||
const original_bytes = " hello even more giant world ";
|
||||
const original = RocStr.init(original_bytes, original_bytes.len);
|
||||
defer original.deinit();
|
||||
defer original.decref();
|
||||
|
||||
try expect(!original.isSmallStr());
|
||||
|
||||
const expected_bytes = " hello even more giant world";
|
||||
const expected = RocStr.init(expected_bytes, expected_bytes.len);
|
||||
defer expected.deinit();
|
||||
defer expected.decref();
|
||||
|
||||
try expect(!expected.isSmallStr());
|
||||
|
||||
@ -2599,12 +2595,12 @@ test "strTrimRight: large to small" {
|
||||
|
||||
const expected_bytes = " hello";
|
||||
const expected = RocStr.init(expected_bytes, expected_bytes.len);
|
||||
defer expected.deinit();
|
||||
defer expected.decref();
|
||||
|
||||
try expect(expected.isSmallStr());
|
||||
|
||||
const trimmed = strTrimRight(original);
|
||||
defer trimmed.deinit();
|
||||
defer trimmed.decref();
|
||||
|
||||
try expect(trimmed.eq(expected));
|
||||
try expect(!trimmed.isSmallStr());
|
||||
@ -2613,13 +2609,13 @@ test "strTrimRight: large to small" {
|
||||
test "strTrimRight: small to small" {
|
||||
const original_bytes = " hello ";
|
||||
const original = RocStr.init(original_bytes, original_bytes.len);
|
||||
defer original.deinit();
|
||||
defer original.decref();
|
||||
|
||||
try expect(original.isSmallStr());
|
||||
|
||||
const expected_bytes = " hello";
|
||||
const expected = RocStr.init(expected_bytes, expected_bytes.len);
|
||||
defer expected.deinit();
|
||||
defer expected.decref();
|
||||
|
||||
try expect(expected.isSmallStr());
|
||||
|
||||
@ -2653,7 +2649,7 @@ test "ReverseUtf8View: empty" {
|
||||
test "capacity: small string" {
|
||||
const data_bytes = "foobar";
|
||||
var data = RocStr.init(data_bytes, data_bytes.len);
|
||||
defer data.deinit();
|
||||
defer data.decref();
|
||||
|
||||
try expectEqual(data.getCapacity(), SMALL_STR_MAX_LENGTH);
|
||||
}
|
||||
@ -2661,7 +2657,7 @@ test "capacity: small string" {
|
||||
test "capacity: big string" {
|
||||
const data_bytes = "a string so large that it must be heap-allocated";
|
||||
var data = RocStr.init(data_bytes, data_bytes.len);
|
||||
defer data.deinit();
|
||||
defer data.decref();
|
||||
|
||||
try expect(data.getCapacity() >= data_bytes.len);
|
||||
}
|
||||
@ -2685,11 +2681,11 @@ test "appendScalar: small A" {
|
||||
var data = RocStr.init(data_bytes, data_bytes.len);
|
||||
|
||||
const actual = appendScalar(data, A[0]);
|
||||
defer actual.deinit();
|
||||
defer actual.decref();
|
||||
|
||||
const expected_bytes = "helloA";
|
||||
const expected = RocStr.init(expected_bytes, expected_bytes.len);
|
||||
defer expected.deinit();
|
||||
defer expected.decref();
|
||||
|
||||
try expect(actual.eq(expected));
|
||||
}
|
||||
@ -2699,11 +2695,11 @@ test "appendScalar: small 😀" {
|
||||
var data = RocStr.init(data_bytes, data_bytes.len);
|
||||
|
||||
const actual = appendScalar(data, 0x1F600);
|
||||
defer actual.deinit();
|
||||
defer actual.decref();
|
||||
|
||||
const expected_bytes = "hello😀";
|
||||
const expected = RocStr.init(expected_bytes, expected_bytes.len);
|
||||
defer expected.deinit();
|
||||
defer expected.decref();
|
||||
|
||||
try expect(actual.eq(expected));
|
||||
}
|
||||
@ -2715,11 +2711,11 @@ test "appendScalar: big A" {
|
||||
var data = RocStr.init(data_bytes, data_bytes.len);
|
||||
|
||||
const actual = appendScalar(data, A[0]);
|
||||
defer actual.deinit();
|
||||
defer actual.decref();
|
||||
|
||||
const expected_bytes = "a string so large that it must be heap-allocatedA";
|
||||
const expected = RocStr.init(expected_bytes, expected_bytes.len);
|
||||
defer expected.deinit();
|
||||
defer expected.decref();
|
||||
|
||||
try expect(actual.eq(expected));
|
||||
}
|
||||
@ -2729,11 +2725,11 @@ test "appendScalar: big 😀" {
|
||||
var data = RocStr.init(data_bytes, data_bytes.len);
|
||||
|
||||
const actual = appendScalar(data, 0x1F600);
|
||||
defer actual.deinit();
|
||||
defer actual.decref();
|
||||
|
||||
const expected_bytes = "a string so large that it must be heap-allocated😀";
|
||||
const expected = RocStr.init(expected_bytes, expected_bytes.len);
|
||||
defer expected.deinit();
|
||||
defer expected.decref();
|
||||
|
||||
try expect(actual.eq(expected));
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ pub fn main() u8 {
|
||||
// stdout the result
|
||||
stdout.print("{s}", .{callresult.asSlice()}) catch unreachable;
|
||||
|
||||
callresult.deinit();
|
||||
callresult.decref();
|
||||
|
||||
stderr.print("runtime: {d:.3}ms\n", .{seconds * 1000}) catch unreachable;
|
||||
|
||||
|
@ -51,7 +51,7 @@ pub fn main() u8 {
|
||||
// display the result using JavaScript
|
||||
js_display_roc_string(callresult.asU8ptr(), callresult.len());
|
||||
|
||||
callresult.deinit();
|
||||
callresult.decref();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ pub fn main() u8 {
|
||||
// stdout the result
|
||||
stdout.print("{s}", .{callresult.asSlice()}) catch unreachable;
|
||||
|
||||
callresult.deinit();
|
||||
callresult.decref();
|
||||
|
||||
stderr.print("runtime: {d:.3}ms\n", .{seconds * 1000}) catch unreachable;
|
||||
|
||||
|
@ -51,13 +51,13 @@ const hostJavaScriptBytes = @embedFile("../client-side/host.js");
|
||||
|
||||
pub fn main() u8 {
|
||||
const json = RocStr.fromSlice("42");
|
||||
defer json.deinit();
|
||||
defer json.decref();
|
||||
|
||||
const hostJavaScript = RocStr.fromSlice(hostJavaScriptBytes);
|
||||
defer hostJavaScript.deinit();
|
||||
defer hostJavaScript.decref();
|
||||
|
||||
const result = roc__main_1_exposed(json, hostJavaScript);
|
||||
defer result.payload.deinit();
|
||||
defer result.payload.decref();
|
||||
|
||||
const writer = if (result.isOk)
|
||||
std.io.getStdOut().writer()
|
||||
|
Loading…
Reference in New Issue
Block a user