Merge remote-tracking branch 'origin/main' into abilities-syntax

This commit is contained in:
Richard Feldman 2023-08-10 20:29:27 -04:00
commit 2da41be29f
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
524 changed files with 47536 additions and 15089 deletions

View file

@ -5,20 +5,6 @@ const expectEqual = testing.expectEqual;
const expect = testing.expect;
const maxInt = std.math.maxInt;
comptime {
// This is a workaround for https://github.com/ziglang/zig/issues/8218
// which is only necessary on macOS.
//
// Once that issue is fixed, we can undo the changes in
// 177cf12e0555147faa4d436e52fc15175c2c4ff0 and go back to passing
// -fcompiler-rt in link.rs instead of doing this. Note that this
// workaround is present in many host.zig files, so make sure to undo
// it everywhere!
if (builtin.os.tag == .macos) {
_ = @import("compiler_rt");
}
}
const mem = std.mem;
const Allocator = mem.Allocator;

View file

@ -6,20 +6,6 @@ const testing = std.testing;
const expectEqual = testing.expectEqual;
const expect = testing.expect;
comptime {
// This is a workaround for https://github.com/ziglang/zig/issues/8218
// which is only necessary on macOS.
//
// Once that issue is fixed, we can undo the changes in
// 177cf12e0555147faa4d436e52fc15175c2c4ff0 and go back to passing
// -fcompiler-rt in link.rs instead of doing this. Note that this
// workaround is present in many host.zig files, so make sure to undo
// it everywhere!
if (builtin.os.tag == .macos) {
_ = @import("compiler_rt");
}
}
const mem = std.mem;
const Allocator = mem.Allocator;

View file

@ -21,7 +21,7 @@ main =
|> Task.putLine
Err GetIntError ->
Task.putLine "Error: Failed to get Integer from stdin."
Task.putLine "Error: Failed to get Integer from stdin."
Expr : [
Add Expr Expr,
@ -100,35 +100,27 @@ constFolding = \e ->
x1 = constFolding e1
x2 = constFolding e2
when Pair x1 x2 is
Pair (Val a) (Val b) ->
Val (a + b)
when x1 is
Val a ->
when x2 is
Val b -> Val (a + b)
Add (Val b) x | Add x (Val b) -> Add (Val (a + b)) x
_ -> Add x1 x2
Pair (Val a) (Add (Val b) x) ->
Add (Val (a + b)) x
Pair (Val a) (Add x (Val b)) ->
Add (Val (a + b)) x
Pair y1 y2 ->
Add y1 y2
_ -> Add x1 x2
Mul e1 e2 ->
x1 = constFolding e1
x2 = constFolding e2
when Pair x1 x2 is
Pair (Val a) (Val b) ->
Val (a * b)
when x1 is
Val a ->
when x2 is
Val b -> Val (a * b)
Mul (Val b) x | Mul x (Val b) -> Mul (Val (a * b)) x
_ -> Mul x1 x2
Pair (Val a) (Mul (Val b) x) ->
Mul (Val (a * b)) x
Pair (Val a) (Mul x (Val b)) ->
Mul (Val (a * b)) x
Pair y1 y2 ->
Add y1 y2
_ -> Mul x1 x2
_ ->
e

View file

@ -23,21 +23,16 @@ main =
Err GetIntError ->
Task.putLine "Error: Failed to get Integer from stdin."
nestHelp : I64, (I64, Expr -> IO Expr), I64, Expr -> IO Expr
nestHelp = \s, f, m, x -> when m is
0 -> Task.succeed x
_ ->
w <- Task.after (f (s - m) x)
nestHelp s f (m - 1) w
nest : (I64, Expr -> IO Expr), I64, Expr -> IO Expr
nest = \f, n, e -> Task.loop { s: n, f, m: n, x: e } nestHelp
State : { s : I64, f : I64, Expr -> IO Expr, m : I64, x : Expr }
nestHelp : State -> IO [Step State, Done Expr]
nestHelp = \{ s, f, m, x } ->
when m is
0 -> Task.succeed (Done x)
_ ->
w <- Task.after (f (s - m) x)
Task.succeed (Step { s, f, m: (m - 1), x: w })
nest = \f, n, e -> nestHelp n f n e
Expr : [Val I64, Var Str, Add Expr Expr, Mul Expr Expr, Pow Expr Expr, Ln Expr]

View file

@ -10,8 +10,8 @@ main =
when inputResult is
Ok n ->
queens n # original koka 13
|> Num.toStr
|> Task.putLine
|> Num.toStr
|> Task.putLine
Err GetIntError ->
Task.putLine "Error: Failed to get Integer from stdin."
@ -21,7 +21,8 @@ ConsList a : [Nil, Cons a (ConsList a)]
queens = \n -> length (findSolutions n n)
findSolutions = \n, k ->
if k <= 0 then # should we use U64 as input type here instead?
if k <= 0 then
# should we use U64 as input type here instead?
Cons Nil Nil
else
extend n Nil (findSolutions n (k - 1))
@ -40,18 +41,18 @@ appendSafe = \k, soln, solns ->
else
appendSafe (k - 1) soln solns
safe : I64, I64, ConsList I64 -> Bool
safe = \queen, diagonal, xs ->
when xs is
Nil -> Bool.true
Cons q t ->
queen != q && queen != q + diagonal && queen != q - diagonal && safe queen (diagonal + 1) t
if queen != q && queen != q + diagonal && queen != q - diagonal then
safe queen (diagonal + 1) t
else
Bool.false
length : ConsList a -> I64
length = \xs ->
dbg "length"
lengthHelp xs 0
lengthHelp : ConsList a, I64 -> I64

View file

@ -23,7 +23,6 @@ main =
Err GetIntError ->
Task.putLine "Error: Failed to get Integer from stdin."
sort : List I64 -> List I64
sort = \list ->

View file

@ -93,9 +93,15 @@ ins = \tree, kx, vx ->
Node Black a ky vy b ->
if lt kx ky then
(if isRed a then balance1 (Node Black Leaf ky vy b) (ins a kx vx) else Node Black (ins a kx vx) ky vy b)
if isRed a then
balance1 (Node Black Leaf ky vy b) (ins a kx vx)
else
Node Black (ins a kx vx) ky vy b
else if lt ky kx then
(if isRed b then balance2 (Node Black a ky vy Leaf) (ins b kx vx) else Node Black a ky vy (ins b kx vx))
if isRed b then
balance2 (Node Black a ky vy Leaf) (ins b kx vx)
else
Node Black a ky vy (ins b kx vx)
else
Node Black a kx vx b

View file

@ -26,7 +26,6 @@ main =
Err GetIntError ->
Task.putLine "Error: Failed to get Integer from stdin."
boom : Str -> a
boom = \_ -> boom ""

View file

@ -7,20 +7,6 @@ const expectEqual = testing.expectEqual;
const expect = testing.expect;
const maxInt = std.math.maxInt;
comptime {
// This is a workaround for https://github.com/ziglang/zig/issues/8218
// which is only necessary on macOS.
//
// Once that issue is fixed, we can undo the changes in
// 177cf12e0555147faa4d436e52fc15175c2c4ff0 and go back to passing
// -fcompiler-rt in link.rs instead of doing this. Note that this
// workaround is present in many host.zig files, so make sure to undo
// it everywhere!
if (builtin.os.tag == .macos) {
_ = @import("compiler_rt");
}
}
const mem = std.mem;
const Allocator = mem.Allocator;

View file

@ -5,5 +5,5 @@ platform "benchmarks"
imports [Task.{ Task }]
provides [mainForHost]
mainForHost : Task {} [] as Fx
mainForHost : Task {} []
mainForHost = main

View file

@ -6,20 +6,6 @@ const testing = std.testing;
const expectEqual = testing.expectEqual;
const expect = testing.expect;
comptime {
// This is a workaround for https://github.com/ziglang/zig/issues/8218
// which is only necessary on macOS.
//
// Once that issue is fixed, we can undo the changes in
// 177cf12e0555147faa4d436e52fc15175c2c4ff0 and go back to passing
// -fcompiler-rt in link.rs instead of doing this. Note that this
// workaround is present in many host.zig files, so make sure to undo
// it everywhere!
if (builtin.os.tag == .macos) {
_ = @import("compiler_rt");
}
}
const Align = 2 * @alignOf(usize);
extern fn malloc(size: usize) callconv(.C) ?*align(Align) anyopaque;
extern fn realloc(c_ptr: [*]align(Align) u8, size: usize) callconv(.C) ?*anyopaque;