Skip to content

Commit bf3e99f

Browse files
authored
Merge pull request #2003 from andrew-johnson-4/misc-small-fixes-dskflsl
deep-hash -> hash
2 parents 0abb084 + 0a18bc5 commit bf3e99f

21 files changed

Lines changed: 3551 additions & 3549 deletions

BOOTSTRAP/cli.c

Lines changed: 3445 additions & 3470 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LSTSFLAGS = MALLOC_CHECK_=3
88
# recommendation: ulimit -s unlimited
99

1010
dev: install-production
11-
lm --v23 tests/promises/syntax/logical-not.lsts
11+
lm --v23 tests/promises/typechecking/nil-never-variables.lsts
1212
$(CC) $(CFLAGS) tmp.c
1313
./a.out
1414

PLUGINS/BACKEND/C/std-c-compile-expr.lsts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ let std-c-compile-expr(ctx: FContext, t: AST, is-stmt: Bool): Fragment = (
9494
let f = mk-fragment();
9595
std-c-fragment-context = std-c-fragment-context.bind( lhs, v );
9696
ctx = ctx.bind( name, lt, v );
97-
if lt.is-t(c"Nil",0) or lt <: t1(c"C",t0(c"void")) {
97+
if lt.is-t(c"Nil",0) or lt.is-t(c"Never",0) or lt <: t1(c"C",t0(c"void")) {
9898
} else if lt <: t1(c"C",t0(c":Label")) {
9999
f = f.set(c"expression", v.get(c"expression") + SAtom(c":"));
100100
} else {
@@ -112,7 +112,7 @@ let std-c-compile-expr(ctx: FContext, t: AST, is-stmt: Bool): Fragment = (
112112
_ => (
113113
let rf = std-c-compile-expr(ctx, rhs, false);
114114
f = f.set(c"frame", f.get(c"frame") + rf.get(c"frame"));
115-
if lt.is-t(c"Nil",0) or lt <: t1(c"C",t0(c"void")) {
115+
if lt.is-t(c"Nil",0) or lt.is-t(c"Never",0) or lt <: t1(c"C",t0(c"void")) {
116116
f = f.set(c"expression", SAtom(c"({") + rf.get(c"expression") + SAtom(c";({});})"));
117117
} else {
118118
f = f.set(c"expression", SAtom(c"({")

PLUGINS/BACKEND/C/std-c-compile-global.lsts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ let std-c-finish-forced-imports(): S = (
1717
let compile-global-c-main-term = mk-eof();
1818

1919
let std-c-compile-global(ctx: FContext, k: CString, term: AST): Nil = (
20+
let kt = typeof-term(term);
2021
std-c-force-import-clib(c"string.h");
2122
if k==c"" then ()
2223
else if k==c"div_t" then std-c-force-import-clib(c"stdlib.h")
@@ -39,13 +40,13 @@ let std-c-compile-global(ctx: FContext, k: CString, term: AST): Nil = (
3940
else if k==c"bsearch" then std-c-force-import-clib(c"stdlib.h")
4041
else if k==c"qsort" then std-c-force-import-clib(c"stdlib.h")
4142
else if k==c"__compar_fn_t" then std-c-force-import-clib(c"stdlib.h")
42-
else if typeof-term(term).is-open or typeof-term(term).is-t(c"Blob",0) or typeof-term(term).is-t(c"FFI",0) or typeof-term(term).is-t(c"Prop",0) then ()
43+
else if kt.is-open or kt.is-t(c"Blob",0) or kt.is-t(c"FFI",0) or kt.is-t(c"Prop",0) then ()
4344
else if k==c"main" and not(non-zero(compile-global-c-main-term)) then {
4445
compile-global-c-main-term = term;
4546
} else match term {
4647
App{left:Lit{key:c":"}, right:App{left:ASTNil{}, right:AType{tt=tt}}} => (
4748
if not(tt.is-t(c"C-FFI",0)) and not(tt.is-t(c"C-Fragment",0)) {
48-
let clean-tt = typeof-term(term).weaken.without-phi;
49+
let clean-tt = kt.weaken.without-phi;
4950
k = mangle-identifier(k, clean-tt);
5051
};
5152
(let pre-decl, let post-decl) = std-c-mangle-declaration(tt, term);
@@ -55,28 +56,34 @@ let std-c-compile-global(ctx: FContext, k: CString, term: AST): Nil = (
5556
text = text + SAtom(k);
5657
text = text + post-decl;
5758
text = text + SAtom(c";\n");
58-
if can-unify(t1(c"C",t0(c"typedef")), tt) or can-unify(t2(c"Array",t1(c"C",t0(c"typedef")),ta), tt) {
59+
if kt.is-t(c"Nil",0) or kt.is-t(c"Never",0) or kt <: t1(c"C",t0(c"void")) then ()
60+
else if can-unify(t1(c"C",t0(c"typedef")), tt) or can-unify(t2(c"Array",t1(c"C",t0(c"typedef")),ta), tt) {
5961
assemble-header-typedef-section = assemble-header-typedef-section + text;
6062
} else {
6163
assemble-gdecl-section = assemble-gdecl-section + text;
6264
}
6365
);
6466
App{left:Lit{key:c":"}, right:App{t=left, right:AType{tt=tt}}} => (
6567
if not(tt.is-t(c"C-FFI",0)) and not(tt.is-t(c"C-Fragment",0)) {
66-
let clean-tt = typeof-term(term).weaken.without-phi;
68+
let clean-tt = kt.weaken.without-phi;
6769
k = mangle-identifier(k, clean-tt);
6870
};
6971
let gend = false;
7072
if tt.is-t(c"C-Fragment",0) {
7173
match t {
7274
Lit{key=key} => (
73-
assemble-gdecl-section = assemble-gdecl-section + SAtom(key);
75+
if kt.is-t(c"Nil",0) or kt.is-t(c"Never",0) or kt <: t1(c"C",t0(c"void")) then ()
76+
else assemble-gdecl-section = assemble-gdecl-section + SAtom(key);
7477
gend = true;
7578
);
7679
_ => ();
7780
}
7881
};
79-
if not(gend) {
82+
if not(gend) and (kt.is-t(c"Nil",0) or kt.is-t(c"Never",0) or kt <: t1(c"C",t0(c"void"))) {
83+
let inner-expr = std-c-compile-expr( ctx, t, false );
84+
let text = inner-expr.get(c"expression") + SAtom(c";\n");
85+
assemble-global-initializer-section = assemble-global-initializer-section + text;
86+
} else if not(gend) {
8087
(let pre-decl, let post-decl) = std-c-mangle-declaration(tt, term);
8188
let text = SNil();
8289
text = text + pre-decl;
@@ -86,7 +93,10 @@ let std-c-compile-global(ctx: FContext, k: CString, term: AST): Nil = (
8693
text = text + SAtom(c";\n");
8794

8895
let inner-expr = std-c-compile-expr( ctx, t, false );
89-
if can-unify(t1(c"C",t0(c"typedef")), tt) or can-unify(t2(c"Array",t1(c"C",t0(c"typedef")),ta), tt) {
96+
if kt.is-t(c"Nil",0) or kt.is-t(c"Never",0) or kt <: t1(c"C",t0(c"void")) then {
97+
text = SNil;
98+
text = SAtom(k) + SAtom(c" = ") + inner-expr.get(c"expression") + SAtom(c";\n");
99+
} else if can-unify(t1(c"C",t0(c"typedef")), tt) or can-unify(t2(c"Array",t1(c"C",t0(c"typedef")),ta), tt) {
90100
assemble-header-typedef-section = assemble-header-typedef-section + text;
91101
} else {
92102
assemble-gdecl-section = assemble-gdecl-section + text;
@@ -96,8 +106,8 @@ let std-c-compile-global(ctx: FContext, k: CString, term: AST): Nil = (
96106
}
97107
);
98108
Abs{lhs=lhs,rhs=rhs,tt=tt} => (
99-
if k!=c"main" and not(typeof-term(term).is-t(c"C-FFI_s",0)) {
100-
k = mangle-identifier-function(k, typeof-term(term).without-phi);
109+
if k!=c"main" and not(kt.is-t(c"C-FFI_s",0)) {
110+
k = mangle-identifier-function(k, kt.without-phi);
101111
};
102112
ctx = std-c-compile-destructure-args( ctx, lhs, false );
103113
let loc = term.location;
@@ -154,8 +164,8 @@ let std-c-compile-global(ctx: FContext, k: CString, term: AST): Nil = (
154164
};
155165
);
156166
t => (
157-
let tt = typeof-term(term);
158-
if not(typeof-term(term).is-t(c"C-FFI",0)) and not(tt.is-t(c"C-Fragment",0)) {
167+
let tt = kt;
168+
if not(kt.is-t(c"C-FFI",0)) and not(tt.is-t(c"C-Fragment",0)) {
159169
k = mangle-identifier(k, tt.without-phi);
160170
};
161171

@@ -166,11 +176,17 @@ let std-c-compile-global(ctx: FContext, k: CString, term: AST): Nil = (
166176
text = text + SAtom(k);
167177
text = text + post-decl;
168178
text = text + SAtom(c";\n");
169-
assemble-gdecl-section = assemble-gdecl-section + text;
179+
if kt.is-t(c"Nil",0) or kt.is-t(c"Never",0) or kt <: t1(c"C",t0(c"void")) then ()
180+
else assemble-gdecl-section = assemble-gdecl-section + text;
170181

171182
let inner-expr = std-c-compile-expr( ctx, t, false );
172-
text = SAtom(k) + SAtom(c" = ") + inner-expr.get(c"expression") + SAtom(c";\n");
173-
assemble-global-initializer-section = assemble-global-initializer-section + text;
183+
if kt.is-t(c"Nil",0) or kt.is-t(c"Never",0) or kt <: t1(c"C",t0(c"void")) {
184+
text = inner-expr.get(c"expression") + SAtom(c";\n");
185+
assemble-global-initializer-section = assemble-global-initializer-section + text;
186+
} else {
187+
text = SAtom(k) + SAtom(c" = ") + inner-expr.get(c"expression") + SAtom(c";\n");
188+
assemble-global-initializer-section = assemble-global-initializer-section + text;
189+
}
174190
);
175191
}
176192
);

PLUGINS/FRONTEND/LSTS/lsts-parse.lsts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,21 @@ let lsts-parse-type(tokens: List<Token>): Tuple<Type,List<Token>> = (
309309
let lsts-parse-type-conjugate(tokens: List<Token>): Tuple<Type,List<Token>> = (
310310
let tt = if lsts-parse-head(tokens) == c"(" {
311311
lsts-parse-expect(c"(", tokens); tokens = tail(tokens);
312-
let args-rest = lsts-parse-type(tokens);
313-
let args = [ args-rest.first ];
314-
tokens = args-rest.second;
312+
let args = [] : List<Type>;
313+
if lsts-parse-head(tokens)!=c")" {
314+
(let arg, tokens) = lsts-parse-type(tokens);
315+
args = [ arg ];
316+
};
315317
while lsts-parse-head(tokens) == c"," {
316318
lsts-parse-expect(c",", tokens); tokens = tail(tokens);
317319
let tnext-rest = lsts-parse-type(tokens);
318320
args = cons( tnext-rest.first, args );
319321
tokens = tnext-rest.second;
320322
};
321323
lsts-parse-expect(c")", tokens); tokens = tail(tokens);
322-
if args.length==1 then head(args) else TGround ( c"Tuple", close(args) );
324+
if args.length==0 then t0(c"Nil")
325+
else if args.length==1 then head(args)
326+
else TGround ( c"Tuple", close(args) );
323327
} else if lsts-parse-head(tokens)==c"?" {
324328
lsts-parse-expect(c"?", tokens); tokens = tail(tokens);
325329
ta

PLUGINS/FRONTEND/LSTS/lsts-smart-tokenize.lsts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ let lsts-tokenize-string(file-path: String, text: String): List<Token> = (
1919
text = rest;
2020
);
2121

22-
"__".. rest => (tokens = cons(text[:"__".length], tokens); text = rest;);
2322
"**".. rest => (tokens = cons(text[:"**".length], tokens); text = rest;);
2423
"\\".. rest => (tokens = cons(text[:"\\".length], tokens); text = rest;);
2524
"~=".. rest => (tokens = cons(text[:"~=".length], tokens); text = rest;);

SRC/ast-deep-hash.lsts

Lines changed: 0 additions & 23 deletions
This file was deleted.

SRC/ast-hash.lsts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
let hash(t: AST): U64 = (
3+
match t {
4+
Meta{ val=val } => hash(val) + 123;
5+
ASTEOF{} => 456;
6+
ASTNil{} => 789;
7+
App{ is-cons=is-cons, left=left, right=right } => hash(is-cons) + hash(left) + hash(right);
8+
Var{ key1=key, token=token } => hash(key1);
9+
Lit{ key2=key, token=token } => hash(key2);
10+
Abs{ lhs=lhs, rhs=rhs, tt=tt } => hash(lhs) + hash(rhs) + hash(tt);
11+
AType{ tt=tt } => hash(tt);
12+
Seq{ seq=seq } => hash(seq);
13+
Glb{ key3=key, val=val } => 012 + hash(val);
14+
Typedef{ lhs-type=lhs-type, implies=implies, implements=implements, size=size, alias=alias, opaque-alias=opaque-alias } =>
15+
hash(lhs-type) + hash(implies) + hash(implements) + hash(size) + hash(alias) + hash(opaque-alias);
16+
}
17+
);

SRC/type-deep-hash.lsts

Lines changed: 0 additions & 13 deletions
This file was deleted.

SRC/type-hash.lsts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
let hash(tt: Type): U64 = (
3+
match tt {
4+
TAny{} => 0_u64;
5+
TVar{name=name} => hash(name);
6+
TAnd{conjugate=conjugate} => (
7+
let result = 0_u64;
8+
for vector c in conjugate { result = result + hash(c) };
9+
result
10+
);
11+
TGround{tag=tag,parameters=parameters} => hash(tag) + hash(parameters);
12+
}
13+
);

0 commit comments

Comments
 (0)