Skip to content

Commit

Permalink
Merge pull request #1205 from andrew-johnson-4/lm-to-lsts-qyqrp
Browse files Browse the repository at this point in the history
Lm to lsts qyqrp
  • Loading branch information
andrew-johnson-4 authored Jan 30, 2025
2 parents 0526463 + 70bd0df commit 80b419e
Show file tree
Hide file tree
Showing 38 changed files with 22,166 additions and 22,011 deletions.
43,925 changes: 22,030 additions & 21,895 deletions BOOTSTRAP/cli.c

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions PLATFORM/C/LIB/list.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ let .next(ls: Array<List<x>,?>): Maybe<x> = (
[] => (None :: Maybe<x>);
};
);

let .lookup(ls: List<Tuple<k,v>>, key: k, default: v): v = (
let found = false;
for Tuple{lkey=first, rval=second} in ls {
if not(found) && key==lkey { default=rval; found=true; }
};
default;
);
14 changes: 7 additions & 7 deletions PLUGINS/BACKEND/C/compile-c-typedef.lm
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ compile-c-typedef-ordinal := λ(: base-type Type). (: (
) ())
) Nil);

continue-compile-c-typedefs-concrete := (: LEOF List<Tuple<Tuple<Maybe<List<Tuple<String,Type,AST>>>,Type>,AST>>);
continue-compile-c-typedefs-concrete := (: LEOF List<Tuple<Tuple<Maybe<TContext>,Type>,AST>>);
continue-compile-c-typedefs-count := 0_u64;
try-continue-compile-c-typedefs := λ. (: (
(let continue continue-compile-c-typedefs-concrete)
(set continue-compile-c-typedefs-concrete (: LEOF List<Tuple<Tuple<Maybe<List<Tuple<String,Type,AST>>>,Type>,AST>>))
(set continue-compile-c-typedefs-concrete (: LEOF List<Tuple<Tuple<Maybe<TContext>,Type>,AST>>))
(while (non-zero continue) (
(set continue-compile-c-typedefs-count (+( continue-compile-c-typedefs-count 1_u64 )))
(if (>( continue-compile-c-typedefs-count 100_u64 )) (
Expand All @@ -48,7 +48,7 @@ try-continue-compile-c-typedefs := λ. (: (
))
))
(set continue continue-compile-c-typedefs-concrete)
(set continue-compile-c-typedefs-concrete (: LEOF List<Tuple<Tuple<Maybe<List<Tuple<String,Type,AST>>>,Type>,AST>>))
(set continue-compile-c-typedefs-concrete (: LEOF List<Tuple<Tuple<Maybe<TContext>,Type>,AST>>))
))
) Nil);

Expand Down Expand Up @@ -88,7 +88,7 @@ is-incomplete-typedef := λ(: tt Type). (: (
) U64);

is-cstruct-hard-compiled-index := (: (HashtableEq( 0_u64 0_u64 (as 0_u64 Tuple<Type,U64>[]) )) HashtableEq<Type,U64>);
compile-c-typedef-concrete := λ(: tctx TContext)(: base-type Type)(: body AST). (: (
compile-c-typedef-concrete := λ(: tctx Maybe<TContext>)(: base-type Type)(: body AST). (: (
(if (.is-open base-type) () (
(let original-body body)
(let base-uuid (.lookup( index-c-type-ordinal base-type 'UnknownCTypename_s )))
Expand Down Expand Up @@ -147,7 +147,7 @@ compile-c-typedef := λ(: base-type Type)(: body AST). (: (
(set compile-c-type-body-of-base-type (.bind( compile-c-type-body-of-base-type (tag-of base-type) (Tuple( base-type body )) )))
(if (.is-lm-struct base-type) (
(if (.is-open base-type) () (
(compile-c-typedef-concrete( (: None TContext) base-type body ))
(compile-c-typedef-concrete( (: None Maybe<TContext>) base-type body ))
))
(match base-type (
()
Expand All @@ -174,7 +174,7 @@ compile-c-fields-of-case := λ(: base-type Type)(: tag-definition AST)(: case-nu
ft
) Type);

compile-c-casedef := λ(: tctx TContext)(: fields Type)(: case-number U64). (: (
compile-c-casedef := λ(: tctx Maybe<TContext>)(: fields Type)(: case-number U64). (: (
(let r (+(
(SAtom 'struct\s{_s)
(+(
Expand Down Expand Up @@ -221,7 +221,7 @@ compile-c-mark-field-as-seen := λ(: tt Type). (: (
) ())
) Nil);

compile-c-casedef-fields := λ(: tctx TContext)(: fields Type)(: case-number U64)(: field-index U64). (: (
compile-c-casedef-fields := λ(: tctx Maybe<TContext>)(: fields Type)(: case-number U64)(: field-index U64). (: (
(let r SNil)
(match fields (
()
Expand Down
2 changes: 1 addition & 1 deletion SRC/apply.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let apply(function-name: CString, function-type: Type, parameters: Type, do-spec
let fpt = sft.domain;
let ctx = unify(fpt, parameters);
let phi-ctx = ctx;
for phi-row in phi-ctx.get-or([] :: List<Tuple<CString,Type,AST>>) {
for phi-row in phi-ctx.get-or([] :: TContext) {
match phi-row {
Tuple{ first:c"Phi::Transition", typ=second, third:Var{pid=key} } => (
phi-types = cons( Tuple{ pid, typ }, phi-types );
Expand Down
3 changes: 2 additions & 1 deletion SRC/ast-definitions.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ zero AST = ASTEOF;
# constructor with a default argument
let $"App"(left: AST[], right: AST[]): AST = App { false, left, right };

type alias TContext = Maybe<List<Tuple<CString,Type,AST>>>;
type alias TContext = List<Tuple<CString,Type,AST>>;
type alias AContext = List<Tuple<CString,AST>>;
13 changes: 13 additions & 0 deletions SRC/context-to-acontext.lm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

context-to-acontext := λ(: ctx Context). (: (
(let cs (: LEOF AContext))
(while (non-zero ctx) (match ctx (
()
( (CtxBind( rst k v )) (
(set cs (cons( (Tuple( k v )) cs )))
(set ctx rst)
))
( _ (set ctx CtxEOF) )
)))
cs
) AContext);
4 changes: 2 additions & 2 deletions SRC/ctx-union.lsts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

let union(ctx: FContext, tctx: TContext): FContext = (
let union(ctx: FContext, tctx: Maybe<TContext>): FContext = (
let r = ctx;
for Tuple{ k=first, vt=second } in tctx.get-or([] :: List<Tuple<CString,Type,AST>>) {
for Tuple{ k=first, vt=second } in tctx.get-or([] :: TContext) {
r = FCtxBind{ close(r), k, TAny, mk-fragment() };
};
r
Expand Down
37 changes: 0 additions & 37 deletions SRC/deep-hash.lm

This file was deleted.

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

let deep-hash(tt: Type): U64 = (
match tt {
TAny{} => 0_u64;
TVar{name=name} => deep-hash(name);
TAnd{lt=left,rt=right} => deep-hash(lt) + deep-hash(rt);
TGround{tag=tag,parameters=parameters} => deep-hash(tag) + deep-hash(parameters);
}
);

let deep-hash(ts: List<Type>): U64 = (
let return = 0_u64;
for t1 in ts { return = return + deep-hash(t1); };
return;
);

13 changes: 0 additions & 13 deletions SRC/error-formatting.lm

This file was deleted.

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

let exit-error(msg: CString, t: AST): Nil = (
print("\{msg}\n\{t.location}\n"); exit(1);
);
4 changes: 4 additions & 0 deletions SRC/index-index.lm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import SRC/unit-ast.lsts;
import SRC/unit-inference.lsts;
import SRC/unit-fragments.lsts;
import SRC/unit-globals.lsts;
import SRC/unit-error.lsts;
import SRC/unit-preprocess.lsts;

import SRC/index-definitions.lm;
import SRC/index-globals.lm;
Expand All @@ -19,4 +21,6 @@ import SRC/index-ast.lm;
import SRC/index-preprocess.lm;
import SRC/index-plugins.lm;

import SRC/context-to-acontext.lm;

import SRC/main.lsts;
1 change: 0 additions & 1 deletion SRC/index-preprocess.lm
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ import SRC/preprocess-apply-locations.lm;
import SRC/preprocess-apply.lm;
import SRC/preprocess-is-suffixed.lm;
import SRC/preprocess.lm;
import SRC/substitute-uuids.lm;
import SRC/try-destructure-macro.lm;
2 changes: 0 additions & 2 deletions SRC/index-types.lm
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import SRC/maybe-specialize.lm;

import SRC/is-constructor.lm;

import SRC/deep-hash.lm;

import SRC/union.lm;
import SRC/tag-of.lm;
import SRC/has-infinite.lm;
Expand Down
2 changes: 0 additions & 2 deletions SRC/index-utility.lm
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@

import SRC/index-definitions.lm;

import SRC/error-formatting.lm;
4 changes: 2 additions & 2 deletions SRC/infer-ctx.lm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

infer-ctx := λ(: tctx TContext)(: lhs AST). (: (
infer-ctx := λ(: tctx Maybe<TContext>)(: lhs AST). (: (
(match lhs (
()
( (App( (Lit( ':_s _ )) (App( (Var( v vtk )) (AType tt) )) )) (
Expand All @@ -16,4 +16,4 @@ infer-ctx := λ(: tctx TContext)(: lhs AST). (: (
( ASTNil () )
))
tctx
) TContext);
) Maybe<TContext>);
8 changes: 4 additions & 4 deletions SRC/infer-expr.lm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

infer-expr := λ(: tctx TContext)(: term AST)(: scoped IsScoped)(: hint Type)(: used IsUsed). (: (
infer-expr := λ(: tctx Maybe<TContext>)(: term AST)(: scoped IsScoped)(: hint Type)(: used IsUsed). (: (
(if (.is-seq term) (
(let seqs (: LEOF List<AST>))
(while (.is-seq term) (match term (
Expand All @@ -13,14 +13,14 @@ infer-expr := λ(: tctx TContext)(: term AST)(: scoped IsScoped)(: hint Type)(:
(set tctx (infer-expr-one( tctx term scoped hint used )))
))
tctx
) TContext);
) Maybe<TContext>);

meta
(description (
'Use\sa\sContext\sto\sinfer\sthe\stype\sof\san\sexpression.
))
;
infer-expr-one := λ(: tctx TContext)(: term AST)(: scoped IsScoped)(: hint Type)(: used IsUsed). (: (
infer-expr-one := λ(: tctx Maybe<TContext>)(: term AST)(: scoped IsScoped)(: hint Type)(: used IsUsed). (: (
(match term (
()
( ASTNil (ascript-normal( term (t1 'Nil_s) )) )
Expand Down Expand Up @@ -317,5 +317,5 @@ infer-expr-one := λ(: tctx TContext)(: term AST)(: scoped IsScoped)(: hint Type
( (AType( tt )) (ascript-normal( term tt )) )
))
tctx
) TContext);
) Maybe<TContext>);

4 changes: 2 additions & 2 deletions SRC/infer-global-context.lm
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ infer-global-context-2 := λ(: td AST). (: (
( (Glb( k_t (@( frhs (Abs( lhs (App( (Lit( ':_s _ )) (App( rhs (AType rhst) )) )) tlt )) )) )) (
))
( (Glb( k_t rhs )) (
(infer-expr( (: None TContext) rhs Unscoped TAny Used ))
(infer-expr( (: None Maybe<TContext>) rhs Unscoped TAny Used ))
(let rhst (normalize(typeof rhs)))
(let kt (&&( rhst (t1 'GlobalVariable_s) )))
(set global-type-context (.bind( global-type-context k kt td )))
(mark-global-as-seen( k kt TAny ))
(ascript-normal( td kt ))
(maybe-specialize( 'mov_s (typeof-var-raw( rhs (: None TContext) 'mov_s )) (t3( 'Cons_s kt kt )) ))
(maybe-specialize( 'mov_s (typeof-var-raw( rhs (: None Maybe<TContext>) 'mov_s )) (t3( 'Cons_s kt kt )) ))
))
( _ () )
))
Expand Down
8 changes: 4 additions & 4 deletions SRC/infer-tctx.lm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

infer-tctx := λ(: tctx TContext)(: tt List<Type>). (: (
infer-tctx := λ(: tctx Maybe<TContext>)(: tt List<Type>). (: (
(match tt (
()
( LEOF () )
Expand All @@ -9,9 +9,9 @@ infer-tctx := λ(: tctx TContext)(: tt List<Type>). (: (
))
))
tctx
) TContext);
) Maybe<TContext>);

infer-tctx := λ(: tctx TContext)(: tt Type). (: (
infer-tctx := λ(: tctx Maybe<TContext>)(: tt Type). (: (
(match tt (
()
( (TAnd( lt rt )) (
Expand All @@ -32,4 +32,4 @@ infer-tctx := λ(: tctx TContext)(: tt Type). (: (
( TAny () )
))
tctx
) TContext);
) Maybe<TContext>);
20 changes: 10 additions & 10 deletions SRC/phi-merge.lsts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

let phi-merge(ctx: TContext, weak-ctx: TContext): TContext = (
let phi-merge(ctx: Maybe<TContext>, weak-ctx: Maybe<TContext>): Maybe<TContext> = (
let iter-ctx = ctx;
let left-phi-ids = [] :: List<CString>;
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: List<Tuple<CString,Type,AST>>) {
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: TContext) {
left-phi-ids = left-phi-ids + typ.phi-ids;
};
iter-ctx = weak-ctx;
let right-phi-ids = [] :: List<CString>;
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: List<Tuple<CString,Type,AST>>) {
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: TContext) {
right-phi-ids = right-phi-ids + typ.phi-ids;
};
for lid in left-phi-ids.unique {
Expand All @@ -17,7 +17,7 @@ let phi-merge(ctx: TContext, weak-ctx: TContext): TContext = (
let left-typ = TAny {};
let left-term = ASTEOF {};
let found = false;
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: List<Tuple<CString,Type,AST>>) {
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: TContext) {
if not(found) && typ.contains-phi(lid) {
left-key = key;
left-typ = typ.get-phi(lid);
Expand All @@ -28,7 +28,7 @@ let phi-merge(ctx: TContext, weak-ctx: TContext): TContext = (
iter-ctx = weak-ctx;
let right-typ = TAny {};
found = false;
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: List<Tuple<CString,Type,AST>>) {
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: TContext) {
if not(found) && typ.contains-phi(lid) {
right-typ = typ.get-phi(lid);
found = true;
Expand All @@ -43,15 +43,15 @@ let phi-merge(ctx: TContext, weak-ctx: TContext): TContext = (
ctx
);

let phi-override(ctx: TContext, weak-ctx: TContext): TContext = (
let phi-override(ctx: Maybe<TContext>, weak-ctx: Maybe<TContext>): Maybe<TContext> = (
let iter-ctx = ctx;
let left-phi-ids = [] :: List<CString>;
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: List<Tuple<CString,Type,AST>>) {
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: TContext) {
left-phi-ids = left-phi-ids + typ.phi-ids;
};
iter-ctx = weak-ctx;
let right-phi-ids = [] :: List<CString>;
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: List<Tuple<CString,Type,AST>>) {
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: TContext) {
right-phi-ids = right-phi-ids + typ.phi-ids;
};
for lid in left-phi-ids.unique {
Expand All @@ -61,7 +61,7 @@ let phi-override(ctx: TContext, weak-ctx: TContext): TContext = (
let left-typ = TAny {};
let left-term = ASTEOF {};
let found = false;
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: List<Tuple<CString,Type,AST>>) {
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: TContext) {
if not(found) && typ.contains-phi(lid) {
left-key = key;
left-typ = typ.get-phi(lid);
Expand All @@ -72,7 +72,7 @@ let phi-override(ctx: TContext, weak-ctx: TContext): TContext = (
iter-ctx = weak-ctx;
let right-typ = TAny {};
found = false;
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: List<Tuple<CString,Type,AST>>) {
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: TContext) {
if not(found) && typ.contains-phi(lid) {
right-typ = typ.get-phi(lid);
found = true;
Expand Down
4 changes: 2 additions & 2 deletions SRC/phi-transition.lsts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

let phi-transition(ctx: TContext, phi-id: CString, phi-new-type: Type): TContext = (
let phi-transition(ctx: Maybe<TContext>, phi-id: CString, phi-new-type: Type): Maybe<TContext> = (
let iter-ctx = ctx;
let found = false;
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: List<Tuple<CString,Type,AST>>) {
for Tuple{ key=first, typ=second, term=third } in iter-ctx.get-or([] :: TContext) {
if not(found) && typ.contains-phi(phi-id) {
ctx = ctx.bind( key, typ.replace-phi(phi-id, phi-new-type), term );
found = true;
Expand Down
2 changes: 1 addition & 1 deletion SRC/preprocess-apply-hard.lm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ preprocess-apply-hard := λ(: macro-name String)(: arity U64)(: program AST). (:
(let p (apply( ctx rhs )))
(let c (extract-uuids( (.location program) CtxEOF p )))
(if (non-zero c) (
(set p (substitute-uuids( c p )))
(set p (substitute-uuids( (context-to-acontext c) p )))
) ())
(set return (preprocess-apply p))
(set macros MEOF)
Expand Down
Loading

0 comments on commit 80b419e

Please sign in to comment.