Skip to content

Commit cd8283e

Browse files
Merge pull request #202 from andrew-johnson-4/strict-compiler-dev-17
Strict compiler dev 17
2 parents 959388a + d7cb2e3 commit cd8283e

File tree

8 files changed

+130
-11
lines changed

8 files changed

+130
-11
lines changed

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.66"
3+
version = "1.11.67"
44
authors = ["Andrew <andrew@subarctic.org>"]
55
license = "MIT"
66
description = "Lambda Mountain"

PRODUCTION/codegen-strict.lm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,12 @@ compile-expr-strict := λctx e offset used . (tail(
180180
)))
181181
( (App( (App( (Literal ':) lval )) ltype )) (tail(
182182
(set e1 (compile-expr-strict( ctx lval offset Unused )))
183+
(set e1 (expr::set-type( e1 (typecheck-lookup e) )))
183184
e1
184185
)))
185186
( (App( (App( (Variable 'as) lval )) ltype )) (tail(
186187
(set e1 (compile-expr-strict( ctx lval offset Unused )))
188+
(set e1 (expr::set-type( e1 (typecheck-lookup e) )))
187189
e1
188190
)))
189191
( (App( (Variable 'tail) (App( l r )) )) (tail(
@@ -212,6 +214,7 @@ compile-expr-strict := λctx e offset used . (tail(
212214
)))
213215
( (Variable v) (tail(
214216
(set e1 (fragment-get-local( ctx v offset )))
217+
(set e1 (expr::set-type( e1 (typecheck-lookup e) )))
215218
e1
216219
)))
217220
( (App (l r)) (tail(
@@ -236,7 +239,7 @@ compile-expr-strict := λctx e offset used . (tail(
236239
)))
237240
( _ (
238241
(if (eq( used Used )) (
239-
(fail( Raw Cons Cells Are Not Permitted In Strict Mode ))
242+
(fail( Raw Cons Cells Are Not Permitted In Strict Mode \n e ))
240243
) (tail(
241244
(set e1 (compile-expr-strict( ctx l offset Unused )))
242245
(set e2 (compile-expr-strict( (expr::get-context e1) r (expr::get-offset e1) Used )))

PRODUCTION/fragment.lm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ fragment-destructure-lhs := λ ctx lhs args . (tail(
299299
(local ctype)
300300
(set ctype (typecheck-infer-type-compound vtype))
301301
(local tctx)
302-
(set tctx (typecheck-unify-args( (expr::get-type (tail args)) ctype )))
302+
(set tctx (typecheck-unify-args( ctype (expr::get-type (tail args)) )))
303303
(set ctx (fragment-bind-types( ctx tctx )))
304304
(set ctx ( ctx (vname (tail args)) ))
305305
ctx
@@ -308,7 +308,7 @@ fragment-destructure-lhs := λ ctx lhs args . (tail(
308308
(local ctype)
309309
(set ctype (typecheck-infer-type-compound vtype))
310310
(local tctx)
311-
(set tctx (typecheck-unify-args( (expr::get-type (tail args)) ctype )))
311+
(set tctx (typecheck-unify-args( ctype (expr::get-type (tail args)) )))
312312
(set ctx (fragment-bind-types( ctx tctx )))
313313
(set ctx ( ctx (vname (tail args)) ))
314314
(set ctx (fragment-destructure-lhs( ctx inner (head args) )))

PRODUCTION/typecheck.lm

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ typecheck-infer-expr := λctx e used . (tail(
725725
(set asc_t (typecheck-lookup asc))
726726
(if asc_t (
727727
(typecheck-ascript( e
728-
(typecheck-and( asc_t (typecheck-infer-type-compound tt) ))
728+
(typecheck-as( asc_t (typecheck-infer-type-compound tt) ))
729729
))
730730
) ())
731731
))
@@ -885,9 +885,37 @@ typecheck-not-representation := λtt . (match tt (
885885
( _ tt )
886886
));
887887

888-
typecheck-and := λlt rt . (tail(
888+
typecheck-as := λlt rt . (tail(
889+
(set lt (typecheck-modifiers( lt )))
890+
(if lt (
891+
(And( lt rt ))
892+
) rt )
893+
));
894+
typecheck-modifiers := λtt . (match tt (
889895
()
890-
(And( lt rt ))
896+
( (And( lt rt )) (tail(
897+
(set lt (typecheck-modifiers lt))
898+
(set rt (typecheck-modifiers rt))
899+
(match (lt rt) (
900+
()
901+
( (() ()) () )
902+
( (() rt) rt )
903+
( (lt ()) lt )
904+
( (lt rt) (And( lt rt )) )
905+
))
906+
)))
907+
( LocalVariable tt )
908+
( GlobalVariable tt )
909+
( StackVariable tt )
910+
( Constant tt )
911+
( Literal tt )
912+
( Label tt )
913+
( Reg8 tt )
914+
( Reg16 tt )
915+
( Reg32 tt )
916+
( Reg64 tt )
917+
( (Sized _) tt )
918+
( _ () )
891919
));
892920

893921
typecheck-as-return := λrt . (tail(

STDLIB/default-instruction-set.lm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ fragment mov := λ(: src LocalVariable+Sized<size>)(: dst LocalVariable+Sized<si
3838
)) \[ '%rbp \] \n
3939
)))
4040
) Nil);
41+
fragment push := λ(: src GlobalVariable+Sized<size>). (: (
42+
(.program (
43+
(\t 'mov \s '$ (.expression src) , \s '%r15 \n)
44+
(for word-offset in (range( 0 (/( size 8 )) )) (
45+
\t 'pushq \s '0 \[ '%r15 \] \n
46+
\t 'add \s '$8 , \s '%r15 \n
47+
))
48+
))
49+
) Nil);
4150
fragment push := λ(: src LocalVariable+Sized<size>). (: (
4251
(.program ( for word-offset in (range( 0 (/( size 8 )) )) (
4352
\t 'pushq \s (+( (.expression src) (*( word-offset 8 )) )) \[ '%rbp \] \n

STDLIB/default-primitives.lm

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ fragment + := λ(: l LocalVariable+U64)(: r Constant+U64). (: (
108108
(.expression( 'r12 ))
109109
) Reg64+U64);
110110

111+
fragment + := λ(: l GlobalVariable+U64)(: r Literal+Constant+U64). (: (
112+
(.program( \t 'mov \s '$ (.expression l) , \s '%r15 \n \t 'mov \s '0 \[ '%r15 \] , '%r15 \n \t 'add \s '$ (.expression r) , \s '%r15 \n ))
113+
(.expression( 'r15 ))
114+
) Reg64+U64);
115+
fragment + := λ(: l Literal+Constant+U64)(: r GlobalVariable+U64). (: (
116+
(.program( \t 'mov \s '$ (.expression r) , \s '%r15 \n \t 'mov \s '0 \[ '%r15 \] , '%r15 \n \t 'add \s '$ (.expression l) , \s '%r15 \n ))
117+
(.expression( 'r15 ))
118+
) Reg64+U64);
119+
120+
fragment + := λ(: l GlobalVariable+U64)(: r LocalVariable+U64). (: (
121+
(.program( \t 'mov \s '$ (.expression l) , \s '%r15 \n
122+
\t 'mov \s '0 \[ '%r15 \] , '%r15 \n
123+
\t 'mov \s (.expression r) \[ '%rbp \] , '%r14 \n
124+
\t 'add \s '%r14 , \s '%r15 \n ))
125+
(.expression( 'r15 ))
126+
) Reg64+U64);
127+
111128
fragment - := λ(: l LocalVariable+U8)(: r Constant+U8). (: (
112129
(.program( \t 'mov \s (.expression l) \[ '%rbp \] , \s '%r12b \n \t 'sub \s '$ (.expression r) , \s '%r12b \n ))
113130
(.expression( 'r12b ))
@@ -151,4 +168,20 @@ fragment == := λ(: l U64+Literal+Constant)(: r U64+Reg64). (: (
151168
))
152169
(.expression( 'je ))
153170
) BranchConditional);
171+
fragment == := λ(: l U64+GlobalVariable)(: r U64+Literal+Constant). (: (
172+
(.program (
173+
\t 'mov \s '$ (.expression l) , '%r15 \n
174+
\t 'mov \s '0 \[ '%r15 \] , \s '%r15 \n
175+
\t 'cmp \s '$ (.expression r) , '%r15 \n
176+
))
177+
(.expression( 'je ))
178+
) BranchConditional);
179+
fragment == := λ(: l U64+Literal+Constant)(: r U64+GlobalVariable). (: (
180+
(.program (
181+
\t 'mov \s '$ (.expression r) , '%r15 \n
182+
\t 'mov \s '0 \[ '%r15 \] , \s '%r15 \n
183+
\t 'cmp \s '$ (.expression l) , '%r15 \n
184+
))
185+
(.expression( 'je ))
186+
) BranchConditional);
154187

STDLIB/default-stdlib.lm

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,29 @@ type S (SNil)
44
| (SCons( S[] , S[] ))
55
| (SPointer( ?[] ));
66

7+
close := λ(: x S). (: (tail(
8+
()
9+
(as 0u64 S[])
10+
)) S[]);
11+
712
print := λ(: x S). (: (tail(
813
(if (==( (.0 x) 3u64 )) (
914
(print '\[\]_s)
1015
) (
1116
(if (==( (.0 x) 2u64 )) (
1217
(print (.1 (as x SAtom)))
1318
) (
14-
(print (.0 x))
19+
(if (==( (.0 x) 1u64 )) (tail(
20+
(print '\[_s)
21+
(print (as (.1 (as x SCons)) U64))
22+
(print '\s_s)
23+
(print (as (.2 (as x SCons)) U64))
24+
(print '\]_s)
25+
)) (tail(
26+
(print '[_s)
27+
(print (as (.1 (as x SPointer)) U64))
28+
(print ']_s)
29+
)))
1530
))
1631
))
1732
()
@@ -155,3 +170,25 @@ print := λ(: x I8). (: (tail(
155170
123u8
156171
123u8
157172
)) U8);
173+
174+
cons-page-tail := 0u64;
175+
malloc := λ (: sz U64) . (: (tail(
176+
(if (==( cons-page-tail 0u64 )) (tail(
177+
(mov( 12u64 RAX ))
178+
(mov( 0u64 RDI ))
179+
(syscall())
180+
(mov( RAX R8 )) #current page break in R8
181+
(set cons-page-tail (as R8 U64))
182+
# 4 GB
183+
(add( 1073741824u64 R8 ))
184+
(add( 1073741824u64 R8 ))
185+
(add( 1073741824u64 R8 ))
186+
(add( 1073741824u64 R8 ))
187+
(mov( 12u64 RAX ))
188+
(mov( R8 RDI ))
189+
(syscall())
190+
)) ())
191+
(let curr cons-page-tail)
192+
(set cons-page-tail (+( cons-page-tail sz )))
193+
(as curr ?[])
194+
)) ?[]);

STRICT/cli.lm

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@ config-mode := Compile;
1313

1414
main := λ(: argc U64)(: argv U8[][]).(tail(
1515
# (let argi 0u64)
16-
(let input SNil)
17-
# (let input (SAtom( 'test_s )))
16+
(let input_l (SAtom( 'an-atom_s )))
17+
(let input_r (SPointer( as 'test_s ?[] )))
18+
(let input (SCons(
19+
(close( input_l ))
20+
(close( input_r ))
21+
)))
22+
(print input)
23+
(print (as (malloc 24u64) U64))
24+
(print ',_s)
25+
(print (as (malloc 24u64) U64))
26+
(print ',_s)
27+
(print (as (malloc 24u64) U64))
1828
# (while (<( argi argc )) (
19-
(print input)
2029
# (if (==( ([]( argv argi )) '--tokenize_s )) (
2130
# (print '--tokenize_s)
2231
# ) (

0 commit comments

Comments
 (0)