Skip to content

Commit

Permalink
Merge pull request #1208 from andrew-johnson-4/lm-to-lsts-asdflk
Browse files Browse the repository at this point in the history
Lm to lsts asdflk
  • Loading branch information
andrew-johnson-4 authored Jan 31, 2025
2 parents a4c7711 + 065cfe5 commit 809ea25
Show file tree
Hide file tree
Showing 14 changed files with 21,660 additions and 21,914 deletions.
43,350 changes: 21,582 additions & 21,768 deletions BOOTSTRAP/cli.c

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions SRC/actx-bind.lsts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

let .bind(ctx: Maybe<AContext>, key: CString, val: AST): Maybe<AContext> = (
Some{ cons( Tuple{key,val}, ctx.get-or([] :: AContext) ) }
);
16 changes: 3 additions & 13 deletions SRC/apply.lm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply := λ(: function-name String)(: ft Type)(: pt Type)(: blame AST). (: (
(apply-blame( function-name ft pt 0_u64 blame ))
) ApplyResult);

apply := λ(: ctx Context)(: term AST). (: (
apply := λ(: ctx AContext)(: term AST). (: (
(let return term)
(match term (
()
Expand All @@ -13,18 +13,8 @@ apply := λ(: ctx Context)(: term AST). (: (
(set return (AType( (substitute( ctx tt )) )))
))
( (Var( n _ )) (
(while (non-zero ctx) (match ctx (
()
( (CtxBind( rst k v )) (
(if (==( k n )) (
(set return v)
(set ctx CtxEOF)
) (
(set ctx rst)
))
))
( _ (set ctx CtxEOF))
)))
(let nr (.lookup( ctx n ASTEOF )))
(if (non-zero nr) (set return nr) ())
))
( (App( vl vr )) (
(set return (App(
Expand Down
1 change: 0 additions & 1 deletion SRC/index-definitions.lm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ type CompileMode ModeParse | ModePreprocess | ModeTypecheck | ModeCompile;
type IsUsed Used | Unused | Tail | Return | Call;
type IsScoped Scoped | Unscoped;

type Context CtxEOF | CtxNil | (CtxBind( Context[] , String , AST )); zero Context CtxEOF;
type FContext FCtxEOF | (FCtxBind( remainder:FContext[] , k:String , kt:Type , kv:Fragment )); zero FContext FCtxEOF;

type STypeList STEOF | (STSeq( STypeList[] , S , Type )); zero STypeList STEOF;
Expand Down
5 changes: 5 additions & 0 deletions SRC/index-index.lm
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ import SRC/index-preprocess.lm;
import SRC/index-plugins.lm;

import SRC/main.lsts;

# TODO: remove Core dependency on "parse-type" function
import SRC/substitute.lsts;
import SRC/union.lsts;
import SRC/actx-bind.lsts;
1 change: 0 additions & 1 deletion SRC/index-types.lm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import SRC/index-of-tag.lm;
import SRC/is-sized-array.lsts;
import SRC/maybe-specialize.lm;

import SRC/union.lm;
import SRC/tag-of.lm;
import SRC/has-infinite.lm;
import SRC/has-forward.lm;
Expand Down
26 changes: 12 additions & 14 deletions SRC/preprocess-apply-hard.lm
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@ preprocess-apply-hard := λ(: macro-name String)(: arity U64)(: program AST). (:
))
))
(if (==( go True_u8 )) (
(match (try-destructure-macro( (.location program) lhs program )) (
()
( CtxEOF (set macros rst) )
( ctx (
(set rhs (with-location( rhs (.location program) )))
(set rhs (preprocess-apply-literals( rhs )))
(let p (apply( ctx rhs )))
(let c (extract-uuids( p )))
(set p (substitute-uuids( c p )))
(set return (preprocess-apply p))
(set macros MEOF)
(set matched True_u8)
))
))
(let des (try-destructure-macro( (.location program) lhs program )))
(if (.is-some des) (
(let ctx (.get-or( des (: LEOF AContext) )))
(set rhs (with-location( rhs (.location program) )))
(set rhs (preprocess-apply-literals( rhs )))
(let p (apply( ctx rhs )))
(let c (extract-uuids( p )))
(set p (substitute-uuids( c p )))
(set return (preprocess-apply p))
(set macros MEOF)
(set matched True_u8)
) ())
) ())
))
( _ (set macros MEOF) )
Expand Down
85 changes: 0 additions & 85 deletions SRC/substitute.lm
Original file line number Diff line number Diff line change
@@ -1,89 +1,4 @@

substitute := λ(: ctx Context)(: v Token). (: (
(let vk (.key v))
(while (non-zero ctx) (match ctx (
()
( CtxNil (set ctx CtxEOF) )
( (CtxBind( rst tk (Lit( _ tv )) )) (
(if (==( tk vk )) (
(set v tv)
(set ctx CtxEOF)
) (set ctx rst))
))
( (CtxBind( rst tk (Var( _ tv )) )) (
(if (==( tk vk )) (
(set v tv)
(set ctx CtxEOF)
) (set ctx rst))
))
( (CtxBind( rst tk tv )) (
(set ctx rst)
))
)))
v
) Token);

substitute := λ(: tctx Context)(: tt List<Type>). (: (
(match tt (
()
( LEOF () )
( (LCons( par rst )) (
(set tt (cons(
(substitute( tctx par ))
(substitute( tctx rst ))
)))
))
))
tt
) List<Type>);

substitute := λ(: tctx Context)(: tt Type). (: (
(match tt (
()
( (TVar v) (
(while (non-zero tctx) (match tctx (
()
( CtxNil (set tctx CtxEOF) )
( (CtxBind( rst tk (Lit( tv _ )) )) (
(if (==( tk v )) (
(set tt (parse-type tv))
(set tctx CtxEOF)
) (set tctx rst))
))
( (CtxBind( rst tk (Var( tv _ )) )) (
(if (==( tk v )) (
(set tt (parse-type tv))
(set tctx CtxEOF)
) (set tctx rst))
))
( (CtxBind( rst tk (AType( tv )) )) (
(if (==( tk v )) (
(set tt tv)
(set tctx CtxEOF)
) (set tctx rst))
))
( (CtxBind( rst tk tv )) (
(set tctx rst)
))
)))
))
( (TGround( tag pars )) (
(set tt (TGround(
tag
(close(substitute( tctx pars )))
)))
))
( (TAnd( lt rt )) (
(set tt (TAnd(
(close(substitute( tctx lt )))
(close(substitute( tctx rt )))
)))
))
( _ () )
))
tt
) Type);

substitute-lhs := λ(: tctx Maybe<TContext>)(: t AST). (: (
(match t (
()
Expand Down
31 changes: 31 additions & 0 deletions SRC/substitute.lsts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

let substitute(ctx: AContext, v: Token): Token = (
match ctx.lookup(v.key, ASTEOF) {
Lit{t=token} => t;
Var{t=token} => t;
_ => v;
}
);

let substitute(ctx: AContext, tt: Type): Type = (
match tt {
TVar{v=name} => match ctx.lookup(v, ASTEOF) {
Lit{tv=key} => parse-type(tv);
Var{tv=key} => parse-type(tv);
AType{tv=tt} => tv;
_ => tt;
};
TGround{tag=tag,parameters=parameters} => (
TGround{ tag, close(substitute(ctx,parameters)) }
);
TAnd{left=left,right=right} => substitute(ctx,left) && substitute(ctx,right);
_ => tt;
}
);

let substitute(ctx: AContext, tt: List<Type>): List<Type> = (
match tt {
LCons{head=head,tail=tail} => cons( substitute(ctx,head), substitute(ctx,tail) );
_ => tt;
}
);
1 change: 1 addition & 0 deletions SRC/t.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ let t1(tag: CString): Type = TGround{ tag, close([] :: List<Type>) };
let t2(tag: CString, p1: Type): Type = TGround{ tag, close([p1]) };
let t3(tag: CString, p1: Type, p2: Type): Type = TGround{ tag, close([p2, p1]) };
let tv(v: CString): Type = TVar{ v };
let ta = TAny;
let $"&&"(lt: Type, rt: Type): Type = if not(non-zero(lt)) then rt else if not(non-zero(rt)) then lt else TAnd{ close(lt), close(rt) };
let $"||"(lt: Type, rt: Type): Type = if non-zero(lt) then lt else rt;

29 changes: 15 additions & 14 deletions SRC/try-destructure-macro.lm
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

try-destructure-macro := λ(: loc SourceLocation)(: lhs AST)(: term AST). (: (
(let r CtxEOF)
(let r (: None Maybe<AContext>))
(let yes (Some(: LEOF AContext)))
(match (Tuple( lhs term )) (
()
( (Tuple( ASTNil ASTNil )) (set r CtxNil) )
( (Tuple( ASTNil ASTNil )) (set r yes) )
( (Tuple( (App( (App( (Var( _ _ )) (Var( _ _ )) )) (Var( _ _ )) )) (App( (App( (Lit( possibly-tag _ )) _ )) _ )) )) () )
( (Tuple( (App( (Lit( ':Literal:_s _ )) (Var( pv _ )) )) (App( (Lit( ':_s ctk )) (App( (Lit( _ _ )) (AType _) )) )) )) (
(set r (CtxBind( (close CtxNil) pv (with-location( term (.location ctk) )) )))
(set r (.bind( r pv (with-location( term (.location ctk) )) )))
))
( (Tuple( (App( (Var( _ _ )) (Var( _ _ )) )) (App( (Lit( tag _ )) _ )) )) (
(if (||( (is-lone-tag tag) (preprocess-is-suffixed tag) )) (
Expand Down Expand Up @@ -43,36 +44,36 @@ try-destructure-macro := λ(: loc SourceLocation)(: lhs AST)(: term AST). (: (
) ())
))
( (Tuple( (Lit( ':Any:_s _ )) (Var( '__s _ )) )) (
(set r CtxNil)
(set r yes)
))
( (Tuple( (Lit( pl _ )) (Var( el _ )) )) (
(if (==( pl el )) (set r CtxNil) ())
(if (==( pl el )) (set r yes) ())
))
( (Tuple( (Lit( pl _ )) (Lit( el _ )) )) (
(if (==( pl el )) (set r CtxNil) ())
(if (==( pl el )) (set r yes) ())
))
( (Tuple( (App( (Lit( ':Literal:_s _ )) (Var( pv _ )) )) (Lit( el eltk )) )) (
(if (==( (index-of-tag el) unknown-index-of-tag ))
(set r (CtxBind( (close CtxNil) pv (with-location( term (.location eltk) )) )))
(set r (.bind( r pv (with-location( term (.location eltk) )) )))
()
)
))
( (Tuple( (App( (Lit( ':Field:_s _ )) (Var( pv _ )) )) (Var( el eltk )) )) (
(if (.has-prefix( el '._s )) (
(set r (CtxBind( (close CtxNil) pv (with-location( term (.location eltk) )) )))
(set r (.bind( r pv (with-location( term (.location eltk) )) )))
) ())
))
( (Tuple( (App( (Lit( ':Variable:_s _ )) (Var( _ _ )) )) (Var( '__s _ )) )) (
()
))
( (Tuple( (App( (Lit( ':Variable:_s _ )) (Var( pv _ )) )) (Var( el eltk )) )) (
(set r (CtxBind( (close CtxNil) pv (with-location( term (.location eltk) )) )))
(set r (.bind( r pv (with-location( term (.location eltk) )) )))
))
( (Tuple( (App( (App( (Lit( ':Tag:_s _ )) (Var( pv _ )) )) (Var( pt _ )) )) (Lit( el eltk )) )) (
(if (==( (index-of-tag el) unknown-index-of-tag )) () (
(set r CtxNil)
(set r yes)
(let tag-i (to-string(index-of-tag el)))
(set r (CtxBind( (close r) pv (
(set r (.bind( r pv (
(App(
(close(Lit( ':_s (with-key( eltk ':_s )) )))
(close(App(
Expand All @@ -85,14 +86,14 @@ try-destructure-macro := λ(: loc SourceLocation)(: lhs AST)(: term AST). (: (
(close(SAtom 'Tag::_s))
(close(SAtom el))
))))
(set r (CtxBind( (close r) pt (Lit( tag-tt (with-key( eltk tag-tt )) )) )))
(set r (.bind( r pt (Lit( tag-tt (with-key( eltk tag-tt )) )) )))
))
))
( (Tuple( (Var( pv _ )) t )) (
(set r (CtxBind( (close CtxNil) pv (with-location( term (.location t) )) )))
(set r (.bind( r pv (with-location( term (.location t) )) )))
))
( _ () )
))
r
) Context);
) Maybe<AContext>);

18 changes: 0 additions & 18 deletions SRC/union.lm

This file was deleted.

6 changes: 6 additions & 0 deletions SRC/union.lsts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

let union(l: Maybe<AContext>, r: Maybe<AContext>): Maybe<AContext> = (
if l.is-some && r.is-some then (
Some { l.get-or([] :: AContext) + r.get-or([] :: AContext) }
) else (None :: Maybe<AContext>)
);
1 change: 1 addition & 0 deletions SRC/unit-globals.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ import SRC/global-type-context.lsts;

# queries dependent on index information
import SRC/with-only-class.lsts;

0 comments on commit 809ea25

Please sign in to comment.