Skip to content

Commit

Permalink
Merge pull request #1091 from andrew-johnson-4/umbra-23423
Browse files Browse the repository at this point in the history
Umbra 23423
  • Loading branch information
andrew-johnson-4 authored Jan 13, 2025
2 parents 63274c2 + 4520053 commit 5fcc851
Show file tree
Hide file tree
Showing 7 changed files with 23,421 additions and 23,306 deletions.
46,620 changes: 23,366 additions & 23,254 deletions BOOTSTRAP/cli.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lambda_mountain"
version = "1.20.10"
version = "1.20.11"
authors = ["Andrew <andrew@subarctic.org>"]
license = "MIT"
description = "Typed Macro Assembler (backed by Coq proofs-of-correctness)"
Expand Down
6 changes: 6 additions & 0 deletions PLATFORM/C/LIB/array.lm
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ close := λ(: x p). (: (
r
) p[]);

#declare-binop( mov, raw-type(base[CONST+array-len]), raw-type(base[CONST+array-len]), raw-type(Nil), (
# l"({memcpy(&"; y;
# l","; x;
# l"sizeof("; base_l; l")*"; x-len_l;
# l");({});})";
#));
2 changes: 2 additions & 0 deletions PLATFORM/C/LIB/array.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ declare-unop( open, raw-type(base-type[]), raw-type(base-type), (l"(*"; x; l")";
#declare-unop( open, raw-type(base-type[CONST]), raw-type(base-type[CONST]), x );
declare-unop( $"&", raw-type(t), raw-type(t[]), (l"(&"; x; l")";) );

declare-unop( raw, raw-type(t), raw-type(t), x );
declare-unop( raw, raw-type(base-type[]), raw-type(base-type[]), x );
10 changes: 5 additions & 5 deletions PLATFORM/C/LIB/common-macros.lm
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ macro ('match-pats-arm( term ((:Tag: l lt) ('macro::bind-field-by-key( x1-key ('
(let (uuid v) term)
(let (uuid m) 0_u8)
(if (==( (.0( (uuid v) )) l ))
(if (match-pats-arm( (x1-key( (as (uuid v) lt) )) x1 ))
(if (match-pats-arm( (raw(x1-key( (as (uuid v) lt) ))) x1 ))
(set (uuid m) 1_u8)
()
)
Expand Down Expand Up @@ -323,7 +323,7 @@ macro ('match-pats-arm( term ((:Tag: l lt) ( ('macro::bind-field-by-key( x2-key
(let (uuid v) term)
(let (uuid m) 0_u8)
(if (==( (.0( (uuid v) )) l ))
(if (match-pats-arm( (x1-key( (as (uuid v) lt) )) x1 ))
(if (match-pats-arm( (raw(x1-key( (as (uuid v) lt) ))) x1 ))
(if (match-pats-arm( (open(x2-key( (as (uuid v) lt) ))) x2 ))
(set (uuid m) 1_u8)
()
Expand All @@ -342,7 +342,7 @@ macro ('match-pats-arm( term ((:Tag: l lt) ( ('macro::bind-field-by-key( x2-key
(let (uuid m) 0_u8)
(if (==( (.0( (uuid v) )) l ))
(if (match-pats-arm( (open(x1-key( (as (uuid v) lt) ))) x1 ))
(if (match-pats-arm( (x2-key( (as (uuid v) lt) )) x2 ))
(if (match-pats-arm( (raw(x2-key( (as (uuid v) lt) ))) x2 ))
(set (uuid m) 1_u8)
()
)
Expand All @@ -359,8 +359,8 @@ macro ('match-pats-arm( term ((:Tag: l lt) ( ('macro::bind-field-by-key( x2-key
(let (uuid v) term)
(let (uuid m) 0_u8)
(if (==( (.0( (uuid v) )) l ))
(if (match-pats-arm( (x1-key( (as (uuid v) lt) )) x1 ))
(if (match-pats-arm( (x2-key( (as (uuid v) lt) )) x2 ))
(if (match-pats-arm( (raw(x1-key( (as (uuid v) lt) ))) x1 ))
(if (match-pats-arm( (raw(x2-key( (as (uuid v) lt) ))) x2 ))
(set (uuid m) 1_u8)
()
)
Expand Down
66 changes: 30 additions & 36 deletions PLATFORM/C/LIB/umbra.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,32 @@ let .length(s: Umbra): U64 = (
# using this in a vectorizable loop can break vectorization
# if you know that your loop is vectorizable, consider using [addr]
let $"[]"(s: Umbra, i: U64): U8 = (
# TODO
#let u = s.backing;
#match u {
# UmbraShort { arr=arr } => arr[i];
# UmbraLong { prefix=prefix, raw ptr=ptr } => (
# if i < 4 {
# prefix[i]
# } else {
# ptr[i]
# }
# );
#}
0_u8
let u = s.backing;
match u {
UmbraShort { raw arr=arr } => arr[i];
UmbraLong { raw prefix=prefix, raw ptr=ptr } => (
if i < 4 {
prefix[i]
} else {
ptr[i]
}
);
}
);

# DOES NOT CLONE THE STRING
let $"set[]"(s: Umbra, i: U64, v: U8): Umbra = (
# TODO
#match s.backing {
# UmbraShort { arr=arr } => (
# arr[i] = v;
# );
# UmbraLong { prefix=prefix, raw ptr=ptr } => (
# if i < 4 {
# prefix[i] = v;
# };
# ptr[i] = v;
# );
#};
match s.backing {
UmbraShort { raw arr=arr } => (
arr[i] = v;
);
UmbraLong { raw prefix=prefix, raw ptr=ptr } => (
if i < 4 {
prefix[i] = v;
};
ptr[i] = v;
);
};
s
);

Expand All @@ -82,17 +79,14 @@ let $"set[]"(s: Umbra, i: U64, v: U8): Umbra = (
# for [UmbraLong], returns the pointer to the heap data
# for [UmbraShort], returns the pointer to the on-stack data
let addr(s: Umbra): U8[] = (
0 as U8[]
#TODO
#match s.backing {
# UmbraShort { arr=arr } => (
# (arr as U8[])
# );
#
# UmbraLong { raw ptr=ptr } => (
# ptr
# );
#}
match s.backing {
UmbraShort { raw arr=arr } => (
(arr as U8[])
);
UmbraLong { raw ptr=ptr } => (
ptr
);
}
);

# like [clone-len], except that if the input string is a UmbraLong,
Expand Down
21 changes: 11 additions & 10 deletions tests/lib/umbra.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
import LIB/default.lm;

# UmbraShort
let a = to-umbra("Hey");
assert( a.length == 3 );
assert( a[0] == "H"[0] );
assert( a[1] == "e"[0] );
assert( a[2] == "y"[0] );
assert( a == "Hey" );
a = to-umbra(a);
assert( a.length == 3 );
print(a);
assert( a == "Hey" );
#let a = to-umbra("Hey");
#assert( a.length == 3 );
#print(a[0]);
#assert( a[0] == "H"[0] );
#assert( a[1] == "e"[0] );
#assert( a[2] == "y"[0] );
#assert( a == "Hey" );
#a = to-umbra(a);
#assert( a.length == 3 );
#print(a);
#assert( a == "Hey" );
#a = a + "!";
#let hash = deep-hash(a);
#assert( a.length == 4 );
Expand Down

0 comments on commit 5fcc851

Please sign in to comment.