Skip to content

Commit 8676f98

Browse files
Merge pull request #212 from andrew-johnson-4/inline-structure-creation
Inline structure creation
2 parents a5bdd4a + f4860d9 commit 8676f98

File tree

8 files changed

+12184
-11545
lines changed

8 files changed

+12184
-11545
lines changed

BOOTSTRAP/cli.s

Lines changed: 12113 additions & 11521 deletions
Large diffs are not rendered by default.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lambda_mountain"
3-
version = "1.11.74"
3+
version = "1.11.75"
44
authors = ["Andrew <andrew@subarctic.org>"]
55
license = "MIT"
66
description = "Lambda Mountain"

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
nostd: prod
3-
./production --nostd -o tmp.s tests/nostd/write_function2.lm
4-
# ./production --nostd -o tmp.s tests/strict/cc2.lm
3+
./production --nostd -o tmp.s tests/strict/cc2.lm
54
as -o tmp.o tmp.s
65
ld -o tmp tmp.o
76
./tmp && echo $?

PRODUCTION/codegen-strict.lm

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ compile-push-rvalue := λctx e offset . (tail(
99
()
1010
( (App( le re )) (tail(
1111
(set e1 (compile-push-rvalue( ctx le offset )))
12-
(set e2 (compile-push-rvalue( ctx re offset )))
12+
(set e2 (compile-push-rvalue( ctx re (expr::get-offset e1) )))
1313
(expr::chain( e1 e2 ))
1414
)))
1515
( u (fail (UnexpectedRvalue e)))
@@ -38,6 +38,7 @@ compile-expr-strict := λctx e offset used . (tail(
3838
(local e2)
3939
(local e3)
4040
(local e4)
41+
(local return)
4142
(match used (
4243
()
4344
(Return (tail(
@@ -52,8 +53,8 @@ compile-expr-strict := λctx e offset used . (tail(
5253
))
5354
))
5455
)))
55-
(_ (
56-
(match e (
56+
(_ (tail(
57+
(set return (match e (
5758
()
5859
( (App( (Lambda( (Variable lname) Nil )) rhs )) (tail(
5960
(local sz)
@@ -243,7 +244,12 @@ compile-expr-strict := λctx e offset used . (tail(
243244
( (Literal tag) (tail(
244245
(set e1 (compile-push-rvalue( ctx r offset )))
245246
(set e2 (fragment-apply( ctx 'push (And( (typecheck-lookup e) DontChain)) (() e1) e1 )))
247+
(local sz)
248+
(set sz (typecheck-sizeof(typecheck-lookup e)))
249+
(set offset (expr::get-offset e2))
250+
(set offset (i2s(add( (inv(s2i( sz ))) (s2i offset) ))))
246251
(set e2 (expr::set-type( e2 StackVariable )))
252+
(set e2 (expr::set-offset( e2 offset )))
247253
e2
248254
)))
249255
( u (tail(
@@ -268,8 +274,9 @@ compile-expr-strict := λctx e offset used . (tail(
268274
result
269275
)))
270276
( _ (fail (TODO CompileStrict e)))
271-
))
272-
))
277+
)))
278+
return
279+
)))
273280
))
274281
));
275282

@@ -347,6 +354,7 @@ strict-codegen-type-case := λ ctx base-type type-body case-number . (tail(
347354
\t 'sub \s '$ case-padding , \s '%rsp \n
348355
))
349356
(App( (Variable '.program) (Variable 'src) ))
357+
DontChain
350358
\t 'pushq \s '$ case-number \n
351359
)))
352360
))))
@@ -393,6 +401,7 @@ strict-codegen-type-case := λ ctx base-type type-body case-number . (tail(
393401
(if (eq( case-padding 0 )) () (
394402
\t 'sub \s '$ case-padding , \s '%rsp \n
395403
))
404+
DontChain
396405
\t 'pushq \s '$ case-number \n
397406
)))
398407
))))

PRODUCTION/fragment.lm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
fragment-substitute-context := λ ctx fragment-rhs . (match fragment-rhs (
33
()
44
( () () )
5+
( (Variable Dontchain) () )
6+
( DontChain () )
57
( (Variable( v )) (tail(
68
(while ctx (
79
(if (eq( v (head (tail ctx)) )) (
@@ -208,6 +210,16 @@ fragment-apply-context := λctx fragment-rhs e . (tail(
208210
return
209211
));
210212

213+
fragment-is-dont-chain := λ f . (match f (
214+
()
215+
( DontChain DontChain )
216+
( (l r) (
217+
if (fragment-is-dont-chain l) DontChain
218+
(fragment-is-dont-chain r)
219+
))
220+
( _ () )
221+
));
222+
211223
fragment-apply := λ ctx function-name function-type function-args e-proto . (tail(
212224
(assert-typeof( 'fragment-apply::e-proto e-proto StrictExpr ))
213225
(assert-typeof( 'fragment-apply::function-name function-name Atom ))
@@ -225,6 +237,9 @@ fragment-apply := λ ctx function-name function-type function-args e-proto . (ta
225237
()
226238
( DontChain (set dont-chain DontChain))
227239
))
240+
(if (fragment-is-dont-chain arrow) (
241+
(set dont-chain DontChain)
242+
) ())
228243
(local return)
229244
(set return (fragment-apply-direct( arrow function-args e-proto dont-chain )))
230245
(assert-typeof( 'fragment-apply::return return StrictExpr ))

PRODUCTION/stack.lm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,14 @@ stack-call-push-arg := λ ctx e-arg offset args-size . (tail(
130130
(set e1 (compile-expr-strict( ctx e-arg new-offset Used )))
131131
(set e1 (expr::set-type( e1 (typecheck-lookup e-arg))))
132132

133-
(set e2 (fragment-apply(
134-
ctx 'push (typecheck-lookup e-arg)
135-
(() e1) e1
136-
)))
133+
(if (typecheck-has-representation( typecheck-lookup e-arg )) (
134+
(set e2 (fragment-apply(
135+
ctx 'push (typecheck-lookup e-arg)
136+
(() e1) e1
137+
)))
138+
) (
139+
(set e2 e1)
140+
))
137141

138142
(set e2 (expr::set-unframe( e2 ((expr::get-unframe e2) unframe) )))
139143
(set e2 (expr::set-expr( e2 args-size )))

PRODUCTION/typecheck.lm

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,32 @@ typecheck-infer-type-compound := λcompound . (tail(
507507
result
508508
));
509509

510+
typecheck-is-constructor := λtt . (match tt (
511+
()
512+
( (And( lt rt )) (
513+
if (typecheck-is-constructor lt) True
514+
(typecheck-is-constructor rt)
515+
))
516+
( () () )
517+
( (_ _) () )
518+
( ta (typecheck-is-constructor-atom ta))
519+
));
520+
typecheck-is-constructor-atom := λta . (tail(
521+
(local is-constructor)
522+
(local constructors)
523+
(set constructors typecheck-constructors)
524+
(while constructors (tail(
525+
(if (eq( (head(tail constructors)) ta )) (
526+
(set is-constructor True)
527+
) ())
528+
(if (eq( (tail(tail constructors)) ta )) (
529+
(set is-constructor True)
530+
) ())
531+
(set constructors (head constructors))
532+
)))
533+
is-constructor
534+
));
535+
510536
typecheck-infer-type-constructor := λbase-type body . (match body (
511537
()
512538
( (Literal tag) (tail(
@@ -556,12 +582,12 @@ typecheck-infer-constructor-type := λtag . (tail(
556582
typecheck-set-size := λ tt sz . (if sz (tail(
557583
(local sizes)
558584
(local has-size)
559-
(while sizes (
585+
(while sizes (tail(
560586
(if (deep-eq( (head (tail sizes)) tt )) (
561587
(set has-size True)
562588
) ())
563589
(set sizes (head sizes))
564-
))
590+
)))
565591
(if has-size () (
566592
(if (eq( sz Unsized )) (
567593
(set typecheck-size ( typecheck-size ( tt () )))

tests/strict/cc2.lm

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,8 @@ echo := λ(: x U64). (: (
99
) U64);
1010

1111
main := (
12-
(let l1 (SAtom( 'an-atom_s )))
13-
(let l2 (close(l1)))
14-
(let r1 (SNil))
15-
(let r2 (close(r1)))
16-
(let x (SCons( l2 r2 )))
17-
(print x)
18-
# (print (SCons(
19-
# (close(SAtom( 'an-atom_s )))
20-
# (close(SNil))
21-
# )))
12+
(print(SCons(
13+
(close (SAtom( 'an-atom_s )))
14+
(close SNil)
15+
)))
2216
);

0 commit comments

Comments
 (0)