Progress on updating entire compiler for snake_case

This commit is contained in:
Sam Mohr 2025-01-05 03:48:03 -08:00
parent db6cc5a7b1
commit b56fbd38e1
No known key found for this signature in database
GPG key ID: EA41D161A3C1BC99
297 changed files with 8416 additions and 8544 deletions

View file

@ -11,8 +11,8 @@ const mem = std.mem;
const Allocator = mem.Allocator;
// NOTE the LLVM backend expects this signature
// extern fn roc__mainForHost_1_exposed(i64, *i64) void;
extern fn roc__mainForHost_1_exposed(i64) i64;
// extern fn roc__main_for_host_1_exposed(i64, *i64) void;
extern fn roc__main_for_host_1_exposed(i64) i64;
const Align = 2 * @alignOf(usize);
extern fn malloc(size: usize) callconv(.C) ?*align(Align) anyopaque;
@ -110,7 +110,7 @@ comptime {
pub export fn main() u8 {
const stdout = std.io.getStdOut().writer();
const result = roc__mainForHost_1_exposed(10);
const result = roc__main_for_host_1_exposed(10);
stdout.print("{d}\n", .{result}) catch unreachable;

View file

@ -3,7 +3,7 @@ platform "fibonacci"
exposes []
packages {}
imports []
provides [mainForHost]
provides [main_for_host]
mainForHost : I64 -> I64
mainForHost = \a -> main a
main_for_host : I64 -> I64
main_for_host = \a -> main(a)

View file

@ -1,10 +1,10 @@
app [main] { pf: platform "fibonacci-platform/main.roc" }
main = \n -> fib n 0 1
main = \n -> fib(n, 0, 1)
# the clever implementation requires join points
fib = \n, a, b ->
if n == 0 then
a
else
fib (n - 1) b (a + b)
fib((n - 1), b, (a + b))

View file

@ -9,7 +9,7 @@ const expect = testing.expect;
const mem = std.mem;
const Allocator = mem.Allocator;
extern fn roc__mainForHost_1_exposed(input: RocList) callconv(.C) RocList;
extern fn roc__main_for_host_1_exposed(input: RocList) callconv(.C) RocList;
const Align = 2 * @alignOf(usize);
extern fn malloc(size: usize) callconv(.C) ?*align(Align) anyopaque;
@ -128,7 +128,7 @@ pub export fn main() u8 {
const roc_list = RocList{ .elements = numbers, .length = NUM_NUMS, .capacity = NUM_NUMS };
// actually call roc to populate the callresult
const callresult: RocList = roc__mainForHost_1_exposed(roc_list);
const callresult: RocList = roc__main_for_host_1_exposed(roc_list);
// stdout the result
const length = @min(20, callresult.length);

View file

@ -3,7 +3,7 @@ platform "quicksort"
exposes []
packages {}
imports []
provides [mainForHost]
provides [main_for_host]
mainForHost : List I64 -> List I64
mainForHost = \list -> quicksort list
main_for_host : List I64 -> List I64
main_for_host = \list -> quicksort(list)

View file

@ -1,54 +1,54 @@
app [quicksort] { pf: platform "quicksort-platform/main.roc" }
quicksort = \originalList ->
n = List.len originalList
quicksort = \original_list ->
n = List.len(original_list)
quicksortHelp originalList 0 (n - 1)
quicksort_help(original_list, 0, (n - 1))
quicksortHelp : List (Num a), U64, U64 -> List (Num a)
quicksortHelp = \list, low, high ->
quicksort_help : List (Num a), U64, U64 -> List (Num a)
quicksort_help = \list, low, high ->
if low < high then
when partition low high list is
Pair partitionIndex partitioned ->
when partition(low, high, list) is
Pair(partition_index, partitioned) ->
partitioned
|> quicksortHelp low (partitionIndex - 1)
|> quicksortHelp (partitionIndex + 1) high
|> quicksort_help(low, (partition_index - 1))
|> quicksort_help((partition_index + 1), high)
else
list
partition : U64, U64, List (Num a) -> [Pair U64 (List (Num a))]
partition = \low, high, initialList ->
when List.get initialList high is
Ok pivot ->
when partitionHelp low low initialList high pivot is
Pair newI newList ->
Pair newI (swap newI high newList)
partition = \low, high, initial_list ->
when List.get(initial_list, high) is
Ok(pivot) ->
when partition_help(low, low, initial_list, high, pivot) is
Pair(new_i, new_list) ->
Pair(new_i, swap(new_i, high, new_list))
Err _ ->
Pair low initialList
Err(_) ->
Pair(low, initial_list)
partitionHelp : U64, U64, List (Num c), U64, Num c -> [Pair U64 (List (Num c))]
partitionHelp = \i, j, list, high, pivot ->
partition_help : U64, U64, List (Num c), U64, Num c -> [Pair U64 (List (Num c))]
partition_help = \i, j, list, high, pivot ->
if j < high then
when List.get list j is
Ok value ->
when List.get(list, j) is
Ok(value) ->
if value <= pivot then
partitionHelp (i + 1) (j + 1) (swap i j list) high pivot
partition_help((i + 1), (j + 1), swap(i, j, list), high, pivot)
else
partitionHelp i (j + 1) list high pivot
partition_help(i, (j + 1), list, high, pivot)
Err _ ->
Pair i list
Err(_) ->
Pair(i, list)
else
Pair i list
Pair(i, list)
swap : U64, U64, List a -> List a
swap = \i, j, list ->
when Pair (List.get list i) (List.get list j) is
Pair (Ok atI) (Ok atJ) ->
when Pair(List.get(list, i), List.get(list, j)) is
Pair(Ok(at_i), Ok(at_j)) ->
list
|> List.set i atJ
|> List.set j atI
|> List.set(i, at_j)
|> List.set(j, at_i)
_ ->
# to prevent a decrement on list