From e0d4dbf946ec2af6667ea220b71b336558c981c9 Mon Sep 17 00:00:00 2001 From: Max Acebal Date: Fri, 7 Oct 2022 15:22:38 -0400 Subject: [PATCH 01/19] Broken List Parser --- regression-tests/tests/lists_sample.out | 0 regression-tests/tests/lists_sample.ssl | 18 ++++++++++++++++++ regression-tests/tests/lists_sample2.out | 1 + regression-tests/tests/lists_sample2.ssl | 17 +++++++++++++++++ src/Front/Ast.hs | 1 + src/Front/Parser.y | 10 ++++++++++ 6 files changed, 47 insertions(+) create mode 100644 regression-tests/tests/lists_sample.out create mode 100644 regression-tests/tests/lists_sample.ssl create mode 100644 regression-tests/tests/lists_sample2.out create mode 100644 regression-tests/tests/lists_sample2.ssl diff --git a/regression-tests/tests/lists_sample.out b/regression-tests/tests/lists_sample.out new file mode 100644 index 00000000..e69de29b diff --git a/regression-tests/tests/lists_sample.ssl b/regression-tests/tests/lists_sample.ssl new file mode 100644 index 00000000..995d1326 --- /dev/null +++ b/regression-tests/tests/lists_sample.ssl @@ -0,0 +1,18 @@ +/*type List + Cons Int List + Nil +*/ + +/*puts cout s = + match s + Cons c ss = + after 1, cout <- c + wait cout + after 1, cout <- 32 + wait cout + puts cout ss + Nil = () +*/ + +main cin cout = + let lst = [] \ No newline at end of file diff --git a/regression-tests/tests/lists_sample2.out b/regression-tests/tests/lists_sample2.out new file mode 100644 index 00000000..911e0197 --- /dev/null +++ b/regression-tests/tests/lists_sample2.out @@ -0,0 +1 @@ +1 2 3 4 5 \ No newline at end of file diff --git a/regression-tests/tests/lists_sample2.ssl b/regression-tests/tests/lists_sample2.ssl new file mode 100644 index 00000000..679442b9 --- /dev/null +++ b/regression-tests/tests/lists_sample2.ssl @@ -0,0 +1,17 @@ +type List + Cons Int List + Nil + +puts cout s = + match s + Cons c ss = + after 1, cout <- c + wait cout + after 1, cout <- 32 + wait cout + puts cout ss + Nil = () + +main cin cout = + let lst = Cons '1' (Cons '2' (Cons '3' (Cons '4' (Cons '5' Nil)))) + puts cout lst \ No newline at end of file diff --git a/src/Front/Ast.hs b/src/Front/Ast.hs index 9b955bc0..2b86a658 100644 --- a/src/Front/Ast.hs +++ b/src/Front/Ast.hs @@ -95,6 +95,7 @@ data Expr | Match Expr [(Pat, Expr)] | CQuote String | CCall Identifier [Expr] + | ListExpr [Expr] deriving (Eq, Show) {- | An operator region: a flat list of alternating expressions and operators diff --git a/src/Front/Parser.y b/src/Front/Parser.y index 3fdc3562..d5177359 100644 --- a/src/Front/Parser.y +++ b/src/Front/Parser.y @@ -314,6 +314,16 @@ exprAtom | id { Id $1 } | '(' expr ')' { $2 } | '(' ')' { Lit LitEvent } + | '[' exprList ']' { ListExpr $2 } + +-- | List Expression. +exprList + :list { $1 } + | {- empty list -} { [] } + +list + :exprAtom { [$1] } + | exprAtom ',' list { $1 : $3 } -- | Pipe-separated expressions, for parallel composition. exprPar --> [Expr] From 3231de97f7938190b9bacae19306d878b900834f Mon Sep 17 00:00:00 2001 From: Max Acebal Date: Wed, 12 Oct 2022 16:23:14 -0400 Subject: [PATCH 02/19] fix to main --- regression-tests/tests/lists_sample.ssl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/regression-tests/tests/lists_sample.ssl b/regression-tests/tests/lists_sample.ssl index 995d1326..8b83628f 100644 --- a/regression-tests/tests/lists_sample.ssl +++ b/regression-tests/tests/lists_sample.ssl @@ -15,4 +15,5 @@ */ main cin cout = - let lst = [] \ No newline at end of file + let lst = [] + () // main must return unit \ No newline at end of file From 73cd3ff3f15f33a0360f94cffcc109e300ac9f88 Mon Sep 17 00:00:00 2001 From: Max Acebal Date: Wed, 12 Oct 2022 16:39:31 -0400 Subject: [PATCH 03/19] Small chagnes to pattern match ListExpr --- src/Front/Pattern/Anomaly.hs | 1 + src/Front/Pattern/Desugar.hs | 1 + src/Front/Scope.hs | 1 + 3 files changed, 3 insertions(+) diff --git a/src/Front/Pattern/Anomaly.hs b/src/Front/Pattern/Anomaly.hs index 5abd33b8..be5f0616 100644 --- a/src/Front/Pattern/Anomaly.hs +++ b/src/Front/Pattern/Anomaly.hs @@ -118,6 +118,7 @@ checkExpr (A.Match e arms) = let (ps, es) = unzip arms in checkExpr e >> checkExprs es >> checkPats ps checkExpr (A.CQuote _ ) = return () checkExpr (A.CCall _ es) = mapM_ checkExpr es +checkExpr (A.ListExpr _) = return () checkOpRegion :: A.OpRegion -> AnomalyFn () checkOpRegion (A.NextOp _ e opRegion) = checkExpr e >> checkOpRegion opRegion diff --git a/src/Front/Pattern/Desugar.hs b/src/Front/Pattern/Desugar.hs index dc7070c5..532fe404 100644 --- a/src/Front/Pattern/Desugar.hs +++ b/src/Front/Pattern/Desugar.hs @@ -90,6 +90,7 @@ desugarExprs = mapM desugarExpr desugarExpr :: A.Expr -> DesugarFn A.Expr desugarExpr e@(A.Id _ ) = return e desugarExpr e@(A.Lit _ ) = return e +desugarExpr e@(A.ListExpr _ ) = return e desugarExpr ( A.Apply e1 e2) = A.Apply <$> desugarExpr e1 <*> desugarExpr e2 desugarExpr ( A.Lambda ps e ) = A.Lambda ps <$> desugarExpr e -- WARN: patterns here are not checked desugarExpr (A.OpRegion e opRegion) = diff --git a/src/Front/Scope.hs b/src/Front/Scope.hs index da2f879c..1442f950 100644 --- a/src/Front/Scope.hs +++ b/src/Front/Scope.hs @@ -337,6 +337,7 @@ scopeExpr (A.Assign l r ) = mapM_ scopeExpr [l, r] scopeExpr (A.Wait es ) = mapM_ scopeExpr es scopeExpr (A.Seq e e' ) = mapM_ scopeExpr [e, e'] scopeExpr (A.Lit _ ) = return () +scopeExpr (A.ListExpr _ ) = return () scopeExpr A.Break = return () scopeExpr (A.OpRegion e o) = throwError From 73a76368c32c68305c494314df983e0e871734ff Mon Sep 17 00:00:00 2001 From: Max Acebal Date: Fri, 14 Oct 2022 14:27:34 -0400 Subject: [PATCH 04/19] Todo add list with element implentation to Scope --- src/Front/Scope.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Front/Scope.hs b/src/Front/Scope.hs index 1442f950..e97a58b2 100644 --- a/src/Front/Scope.hs +++ b/src/Front/Scope.hs @@ -337,7 +337,7 @@ scopeExpr (A.Assign l r ) = mapM_ scopeExpr [l, r] scopeExpr (A.Wait es ) = mapM_ scopeExpr es scopeExpr (A.Seq e e' ) = mapM_ scopeExpr [e, e'] scopeExpr (A.Lit _ ) = return () -scopeExpr (A.ListExpr _ ) = return () +scopeExpr (A.ListExpr _ ) = return () -- TODO: include implentation for list with elements scopeExpr A.Break = return () scopeExpr (A.OpRegion e o) = throwError From 84e02770f99f15250cd1343e72d7e147c93303b3 Mon Sep 17 00:00:00 2001 From: Max Acebal Date: Fri, 14 Oct 2022 14:45:19 -0400 Subject: [PATCH 05/19] Looping through elements of ListExpr in scope --- src/Front/Scope.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Front/Scope.hs b/src/Front/Scope.hs index e97a58b2..88c01732 100644 --- a/src/Front/Scope.hs +++ b/src/Front/Scope.hs @@ -337,7 +337,7 @@ scopeExpr (A.Assign l r ) = mapM_ scopeExpr [l, r] scopeExpr (A.Wait es ) = mapM_ scopeExpr es scopeExpr (A.Seq e e' ) = mapM_ scopeExpr [e, e'] scopeExpr (A.Lit _ ) = return () -scopeExpr (A.ListExpr _ ) = return () -- TODO: include implentation for list with elements +scopeExpr (A.ListExpr l ) = mapM_ scopeExpr l scopeExpr A.Break = return () scopeExpr (A.OpRegion e o) = throwError From 9d9e7bdb8e7fcf6fc9090df593899846d8ea986a Mon Sep 17 00:00:00 2001 From: Max Acebal Date: Mon, 31 Oct 2022 17:18:53 -0400 Subject: [PATCH 06/19] Add todo message to LowerAst --- src/IR/LowerAst.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/IR/LowerAst.hs b/src/IR/LowerAst.hs index 44b5d795..2830b555 100644 --- a/src/IR/LowerAst.hs +++ b/src/IR/LowerAst.hs @@ -162,6 +162,8 @@ lowerExpr (A.OpRegion _ _) = lowerExpr (A.Match s ps) = I.Match <$> lowerExpr s <*> mapM lowerArm ps <*> pure untyped where lowerArm (a, e) = (,) <$> lowerPatAlt a <*> lowerExpr e +lowerExpr (A.ListExpr a) = + Compiler.todo "ListExpr lowering not yet implemented" -- | Lower an A.Pat into an I.Alt lowerPatAlt :: A.Pat -> Compiler.Pass I.Alt From f14c81bd88ecca61f6c6a65bc8ba7d29428c27ca Mon Sep 17 00:00:00 2001 From: Max Acebal Date: Mon, 31 Oct 2022 17:22:59 -0400 Subject: [PATCH 07/19] compiler.unexpected in lowerAst --- src/IR/LowerAst.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IR/LowerAst.hs b/src/IR/LowerAst.hs index 2830b555..fb67ce36 100644 --- a/src/IR/LowerAst.hs +++ b/src/IR/LowerAst.hs @@ -163,7 +163,7 @@ lowerExpr (A.Match s ps) = I.Match <$> lowerExpr s <*> mapM lowerArm ps <*> pure untyped where lowerArm (a, e) = (,) <$> lowerPatAlt a <*> lowerExpr e lowerExpr (A.ListExpr a) = - Compiler.todo "ListExpr lowering not yet implemented" + Compiler.unexpected "lowerExpr: ListExprs should have already been desugared" -- | Lower an A.Pat into an I.Alt lowerPatAlt :: A.Pat -> Compiler.Pass I.Alt From 03ec538df36a8898aaeba1c750132c992068615c Mon Sep 17 00:00:00 2001 From: EmilySillars Date: Mon, 31 Oct 2022 17:38:20 -0400 Subject: [PATCH 08/19] fix warnings and failing regression test --- regression-tests/tests/lists_sample.ssl | 2 +- src/Front/Ast.hs | 1 + src/Front/Pattern/Desugar.hs | 1 + src/IR/LowerAst.hs | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/regression-tests/tests/lists_sample.ssl b/regression-tests/tests/lists_sample.ssl index 8b83628f..89d21557 100644 --- a/regression-tests/tests/lists_sample.ssl +++ b/regression-tests/tests/lists_sample.ssl @@ -15,5 +15,5 @@ */ main cin cout = - let lst = [] + // let lst = [] // will uncomment this when list syntax works end-to-end () // main must return unit \ No newline at end of file diff --git a/src/Front/Ast.hs b/src/Front/Ast.hs index 2b86a658..2a5cdeef 100644 --- a/src/Front/Ast.hs +++ b/src/Front/Ast.hs @@ -269,6 +269,7 @@ instance Pretty Expr where (hsep $ punctuate bar $ map prettyPatExprTup as) where prettyPatExprTup (p, e) = pretty p <+> pretty "=" <+> braces (pretty e) + pretty (ListExpr es) = brackets $ hsep $ punctuate comma $ map pretty es pretty NoExpr = error "Unexpected NoExpr" instance Pretty Literal where diff --git a/src/Front/Pattern/Desugar.hs b/src/Front/Pattern/Desugar.hs index 532fe404..b4e6418d 100644 --- a/src/Front/Pattern/Desugar.hs +++ b/src/Front/Pattern/Desugar.hs @@ -338,6 +338,7 @@ substId old new = substExpr in A.Match (substExpr e) (map substArm arms) substExpr e@(A.CQuote _ ) = e substExpr ( A.CCall s es) = A.CCall s $ map substExpr es + substExpr (A.ListExpr es) = A.ListExpr $ map substExpr es singleLet :: Identifier -> A.Expr -> A.Expr -> A.Expr singleLet i e = A.Let [A.DefFn i [] A.TypNone e] diff --git a/src/IR/LowerAst.hs b/src/IR/LowerAst.hs index fb67ce36..1535f650 100644 --- a/src/IR/LowerAst.hs +++ b/src/IR/LowerAst.hs @@ -162,7 +162,7 @@ lowerExpr (A.OpRegion _ _) = lowerExpr (A.Match s ps) = I.Match <$> lowerExpr s <*> mapM lowerArm ps <*> pure untyped where lowerArm (a, e) = (,) <$> lowerPatAlt a <*> lowerExpr e -lowerExpr (A.ListExpr a) = +lowerExpr (A.ListExpr _) = Compiler.unexpected "lowerExpr: ListExprs should have already been desugared" -- | Lower an A.Pat into an I.Alt From 12688b631192d1444ccf2a6825fcd90e81bbd0d6 Mon Sep 17 00:00:00 2001 From: EmilySillars Date: Mon, 31 Oct 2022 17:53:33 -0400 Subject: [PATCH 09/19] fix desugarExpr case, add newlines --- regression-tests/testoutput.c | 215 +++++++++++++++++++++++ regression-tests/tests/lists_sample.ssl | 2 +- regression-tests/tests/lists_sample2.out | 2 +- regression-tests/tests/lists_sample2.ssl | 2 +- src/Front/Pattern/Desugar.hs | 2 +- 5 files changed, 219 insertions(+), 4 deletions(-) create mode 100644 regression-tests/testoutput.c diff --git a/regression-tests/testoutput.c b/regression-tests/testoutput.c new file mode 100644 index 00000000..8829b29f --- /dev/null +++ b/regression-tests/testoutput.c @@ -0,0 +1,215 @@ +#include "ssm.h" +typedef char unit; + +typedef struct { + ssm_act_t act; + ssm_value_t cint; + ssm_value_t cout; + ssm_value_t *__return_val; + ssm_value_t __tmp_0; + ssm_value_t __tmp_1; + ssm_value_t __tmp_10; + ssm_value_t __tmp_11; + ssm_value_t __tmp_12; + ssm_value_t __tmp_13; + ssm_value_t __tmp_2; + ssm_value_t __tmp_3; + ssm_value_t __tmp_4; + ssm_value_t __tmp_5; + ssm_value_t __tmp_6; + ssm_value_t __tmp_7; + ssm_value_t __tmp_8; + ssm_value_t __tmp_9; + ssm_value_t anon0_underscore; + ssm_value_t anon10_underscore; + ssm_value_t anon11_underscore; + ssm_value_t anon12_underscore; + ssm_value_t anon1_underscore; + ssm_value_t anon2_underscore; + ssm_value_t anon3_underscore; + ssm_value_t anon4_underscore; + ssm_value_t anon5_underscore; + ssm_value_t anon6_underscore; + ssm_value_t anon7_underscore; + ssm_value_t anon8_underscore; + ssm_value_t anon9_underscore; + ssm_trigger_t __trig_1; + } act_main_t; +ssm_act_t *__enter_main(ssm_act_t *caller, ssm_priority_t priority, ssm_depth_t depth, ssm_value_t *__argv, + ssm_value_t *__return_val); +extern struct ssm_closure1 __closure_main; +void __step_main(ssm_act_t *actg); +ssm_act_t *__enter_main(ssm_act_t *caller, ssm_priority_t priority, ssm_depth_t depth, ssm_value_t *__argv, + ssm_value_t *__return_val) +{ + ssm_act_t *actg = ssm_enter(sizeof(act_main_t), __step_main, caller, priority, depth); + act_main_t *acts = container_of(actg, act_main_t, act); + + acts->cint = __argv[0]; + acts->cout = __argv[1]; + acts->__return_val = __return_val; + acts->__trig_1.act = actg; + return actg; +} +struct ssm_closure1 __closure_main = {.mm ={.ref_count =1, .kind =SSM_CLOSURE_K, .info ={.vector ={.count =0, .cap = + 2}}}, .f = + __enter_main, .argv ={{0}}}; +void __step_main(ssm_act_t *actg) +{ + act_main_t *acts = container_of(actg, act_main_t, act); + + switch (actg->pc) { + + case 0: + ; + acts->__tmp_0 = ssm_marshal((uint32_t) 10); + ssm_dup(acts->cout); + acts->__tmp_1 = ssm_marshal((uint32_t) 72); + ssm_later(acts->cout, ssm_now() + (uint32_t) ssm_unmarshal(acts->__tmp_0), acts->__tmp_1); + ssm_drop(acts->__tmp_0); + ssm_drop(acts->__tmp_1); + ssm_drop(acts->cout); + acts->anon0_underscore = ssm_marshal((uint32_t) 0); + ssm_dup(acts->cout); + ssm_sensitize(acts->cout, &acts->__trig_1); + actg->pc = 1; + return; + + case 1: + ; + ssm_desensitize(&acts->__trig_1); + ssm_drop(acts->cout); + acts->anon1_underscore = ssm_marshal((uint32_t) 0); + acts->__tmp_2 = ssm_marshal((uint32_t) 10); + ssm_dup(acts->cout); + acts->__tmp_3 = ssm_marshal((uint32_t) 101); + ssm_later(acts->cout, ssm_now() + (uint32_t) ssm_unmarshal(acts->__tmp_2), acts->__tmp_3); + ssm_drop(acts->__tmp_2); + ssm_drop(acts->__tmp_3); + ssm_drop(acts->cout); + acts->anon2_underscore = ssm_marshal((uint32_t) 0); + ssm_dup(acts->cout); + ssm_sensitize(acts->cout, &acts->__trig_1); + actg->pc = 2; + return; + + case 2: + ; + ssm_desensitize(&acts->__trig_1); + ssm_drop(acts->cout); + acts->anon3_underscore = ssm_marshal((uint32_t) 0); + acts->__tmp_4 = ssm_marshal((uint32_t) 10); + ssm_dup(acts->cout); + acts->__tmp_5 = ssm_marshal((uint32_t) 108); + ssm_later(acts->cout, ssm_now() + (uint32_t) ssm_unmarshal(acts->__tmp_4), acts->__tmp_5); + ssm_drop(acts->__tmp_4); + ssm_drop(acts->__tmp_5); + ssm_drop(acts->cout); + acts->anon4_underscore = ssm_marshal((uint32_t) 0); + ssm_dup(acts->cout); + ssm_sensitize(acts->cout, &acts->__trig_1); + actg->pc = 3; + return; + + case 3: + ; + ssm_desensitize(&acts->__trig_1); + ssm_drop(acts->cout); + acts->anon5_underscore = ssm_marshal((uint32_t) 0); + acts->__tmp_6 = ssm_marshal((uint32_t) 10); + ssm_dup(acts->cout); + acts->__tmp_7 = ssm_marshal((uint32_t) 108); + ssm_later(acts->cout, ssm_now() + (uint32_t) ssm_unmarshal(acts->__tmp_6), acts->__tmp_7); + ssm_drop(acts->__tmp_6); + ssm_drop(acts->__tmp_7); + ssm_drop(acts->cout); + acts->anon6_underscore = ssm_marshal((uint32_t) 0); + ssm_dup(acts->cout); + ssm_sensitize(acts->cout, &acts->__trig_1); + actg->pc = 4; + return; + + case 4: + ; + ssm_desensitize(&acts->__trig_1); + ssm_drop(acts->cout); + acts->anon7_underscore = ssm_marshal((uint32_t) 0); + acts->__tmp_8 = ssm_marshal((uint32_t) 10); + ssm_dup(acts->cout); + acts->__tmp_9 = ssm_marshal((uint32_t) 111); + ssm_later(acts->cout, ssm_now() + (uint32_t) ssm_unmarshal(acts->__tmp_8), acts->__tmp_9); + ssm_drop(acts->__tmp_8); + ssm_drop(acts->__tmp_9); + ssm_drop(acts->cout); + acts->anon8_underscore = ssm_marshal((uint32_t) 0); + ssm_dup(acts->cout); + ssm_sensitize(acts->cout, &acts->__trig_1); + actg->pc = 5; + return; + + case 5: + ; + ssm_desensitize(&acts->__trig_1); + ssm_drop(acts->cout); + acts->anon9_underscore = ssm_marshal((uint32_t) 0); + acts->__tmp_10 = ssm_marshal((uint32_t) 10); + ssm_dup(acts->cout); + acts->__tmp_11 = ssm_marshal((uint32_t) 10); + ssm_later(acts->cout, ssm_now() + (uint32_t) ssm_unmarshal(acts->__tmp_10), acts->__tmp_11); + ssm_drop(acts->__tmp_10); + ssm_drop(acts->__tmp_11); + ssm_drop(acts->cout); + acts->anon10_underscore = ssm_marshal((uint32_t) 0); + ssm_dup(acts->cout); + ssm_sensitize(acts->cout, &acts->__trig_1); + actg->pc = 6; + return; + + case 6: + ; + ssm_desensitize(&acts->__trig_1); + ssm_drop(acts->cout); + acts->anon11_underscore = ssm_marshal((uint32_t) 0); + acts->__tmp_12 = ssm_marshal((uint32_t) 10); + ssm_dup(acts->cout); + acts->__tmp_13 = ssm_marshal((uint32_t) 0); + ssm_later(acts->cout, ssm_now() + (uint32_t) ssm_unmarshal(acts->__tmp_12), acts->__tmp_13); + ssm_drop(acts->__tmp_12); + ssm_drop(acts->__tmp_13); + ssm_drop(acts->cout); + acts->anon12_underscore = ssm_marshal((uint32_t) 0); + ssm_dup(acts->cout); + ssm_sensitize(acts->cout, &acts->__trig_1); + actg->pc = 7; + return; + + case 7: + ; + ssm_desensitize(&acts->__trig_1); + ssm_drop(acts->cout); + ssm_drop(acts->anon12_underscore); + ssm_drop(acts->anon11_underscore); + ssm_drop(acts->anon10_underscore); + ssm_drop(acts->anon9_underscore); + ssm_drop(acts->anon8_underscore); + ssm_drop(acts->anon7_underscore); + ssm_drop(acts->anon6_underscore); + ssm_drop(acts->anon5_underscore); + ssm_drop(acts->anon4_underscore); + ssm_drop(acts->anon3_underscore); + ssm_drop(acts->anon2_underscore); + ssm_drop(acts->anon1_underscore); + ssm_drop(acts->anon0_underscore); + ssm_drop(acts->cout); + ssm_drop(acts->cint); + + default: + break; + } + if (acts->__return_val) + *acts->__return_val = ssm_marshal((uint32_t) 0); + + __leave_step: + ssm_leave(actg, sizeof(act_main_t)); +} + diff --git a/regression-tests/tests/lists_sample.ssl b/regression-tests/tests/lists_sample.ssl index 89d21557..3cad9f1d 100644 --- a/regression-tests/tests/lists_sample.ssl +++ b/regression-tests/tests/lists_sample.ssl @@ -16,4 +16,4 @@ main cin cout = // let lst = [] // will uncomment this when list syntax works end-to-end - () // main must return unit \ No newline at end of file + () // main must return unit diff --git a/regression-tests/tests/lists_sample2.out b/regression-tests/tests/lists_sample2.out index 911e0197..aacb5952 100644 --- a/regression-tests/tests/lists_sample2.out +++ b/regression-tests/tests/lists_sample2.out @@ -1 +1 @@ -1 2 3 4 5 \ No newline at end of file +1 2 3 4 5 diff --git a/regression-tests/tests/lists_sample2.ssl b/regression-tests/tests/lists_sample2.ssl index 679442b9..9d492098 100644 --- a/regression-tests/tests/lists_sample2.ssl +++ b/regression-tests/tests/lists_sample2.ssl @@ -14,4 +14,4 @@ puts cout s = main cin cout = let lst = Cons '1' (Cons '2' (Cons '3' (Cons '4' (Cons '5' Nil)))) - puts cout lst \ No newline at end of file + puts cout lst diff --git a/src/Front/Pattern/Desugar.hs b/src/Front/Pattern/Desugar.hs index b4e6418d..9757ea24 100644 --- a/src/Front/Pattern/Desugar.hs +++ b/src/Front/Pattern/Desugar.hs @@ -90,7 +90,7 @@ desugarExprs = mapM desugarExpr desugarExpr :: A.Expr -> DesugarFn A.Expr desugarExpr e@(A.Id _ ) = return e desugarExpr e@(A.Lit _ ) = return e -desugarExpr e@(A.ListExpr _ ) = return e +desugarExpr (A.ListExpr es ) = A.ListExpr <$> mapM desugarExpr es desugarExpr ( A.Apply e1 e2) = A.Apply <$> desugarExpr e1 <*> desugarExpr e2 desugarExpr ( A.Lambda ps e ) = A.Lambda ps <$> desugarExpr e -- WARN: patterns here are not checked desugarExpr (A.OpRegion e opRegion) = From 0431f437e522300bc591de0dc2851ea9c542b4f1 Mon Sep 17 00:00:00 2001 From: EmilySillars Date: Mon, 31 Oct 2022 17:56:23 -0400 Subject: [PATCH 10/19] remove unnecessary file --- regression-tests/testoutput.c | 215 ---------------------------------- 1 file changed, 215 deletions(-) delete mode 100644 regression-tests/testoutput.c diff --git a/regression-tests/testoutput.c b/regression-tests/testoutput.c deleted file mode 100644 index 8829b29f..00000000 --- a/regression-tests/testoutput.c +++ /dev/null @@ -1,215 +0,0 @@ -#include "ssm.h" -typedef char unit; - -typedef struct { - ssm_act_t act; - ssm_value_t cint; - ssm_value_t cout; - ssm_value_t *__return_val; - ssm_value_t __tmp_0; - ssm_value_t __tmp_1; - ssm_value_t __tmp_10; - ssm_value_t __tmp_11; - ssm_value_t __tmp_12; - ssm_value_t __tmp_13; - ssm_value_t __tmp_2; - ssm_value_t __tmp_3; - ssm_value_t __tmp_4; - ssm_value_t __tmp_5; - ssm_value_t __tmp_6; - ssm_value_t __tmp_7; - ssm_value_t __tmp_8; - ssm_value_t __tmp_9; - ssm_value_t anon0_underscore; - ssm_value_t anon10_underscore; - ssm_value_t anon11_underscore; - ssm_value_t anon12_underscore; - ssm_value_t anon1_underscore; - ssm_value_t anon2_underscore; - ssm_value_t anon3_underscore; - ssm_value_t anon4_underscore; - ssm_value_t anon5_underscore; - ssm_value_t anon6_underscore; - ssm_value_t anon7_underscore; - ssm_value_t anon8_underscore; - ssm_value_t anon9_underscore; - ssm_trigger_t __trig_1; - } act_main_t; -ssm_act_t *__enter_main(ssm_act_t *caller, ssm_priority_t priority, ssm_depth_t depth, ssm_value_t *__argv, - ssm_value_t *__return_val); -extern struct ssm_closure1 __closure_main; -void __step_main(ssm_act_t *actg); -ssm_act_t *__enter_main(ssm_act_t *caller, ssm_priority_t priority, ssm_depth_t depth, ssm_value_t *__argv, - ssm_value_t *__return_val) -{ - ssm_act_t *actg = ssm_enter(sizeof(act_main_t), __step_main, caller, priority, depth); - act_main_t *acts = container_of(actg, act_main_t, act); - - acts->cint = __argv[0]; - acts->cout = __argv[1]; - acts->__return_val = __return_val; - acts->__trig_1.act = actg; - return actg; -} -struct ssm_closure1 __closure_main = {.mm ={.ref_count =1, .kind =SSM_CLOSURE_K, .info ={.vector ={.count =0, .cap = - 2}}}, .f = - __enter_main, .argv ={{0}}}; -void __step_main(ssm_act_t *actg) -{ - act_main_t *acts = container_of(actg, act_main_t, act); - - switch (actg->pc) { - - case 0: - ; - acts->__tmp_0 = ssm_marshal((uint32_t) 10); - ssm_dup(acts->cout); - acts->__tmp_1 = ssm_marshal((uint32_t) 72); - ssm_later(acts->cout, ssm_now() + (uint32_t) ssm_unmarshal(acts->__tmp_0), acts->__tmp_1); - ssm_drop(acts->__tmp_0); - ssm_drop(acts->__tmp_1); - ssm_drop(acts->cout); - acts->anon0_underscore = ssm_marshal((uint32_t) 0); - ssm_dup(acts->cout); - ssm_sensitize(acts->cout, &acts->__trig_1); - actg->pc = 1; - return; - - case 1: - ; - ssm_desensitize(&acts->__trig_1); - ssm_drop(acts->cout); - acts->anon1_underscore = ssm_marshal((uint32_t) 0); - acts->__tmp_2 = ssm_marshal((uint32_t) 10); - ssm_dup(acts->cout); - acts->__tmp_3 = ssm_marshal((uint32_t) 101); - ssm_later(acts->cout, ssm_now() + (uint32_t) ssm_unmarshal(acts->__tmp_2), acts->__tmp_3); - ssm_drop(acts->__tmp_2); - ssm_drop(acts->__tmp_3); - ssm_drop(acts->cout); - acts->anon2_underscore = ssm_marshal((uint32_t) 0); - ssm_dup(acts->cout); - ssm_sensitize(acts->cout, &acts->__trig_1); - actg->pc = 2; - return; - - case 2: - ; - ssm_desensitize(&acts->__trig_1); - ssm_drop(acts->cout); - acts->anon3_underscore = ssm_marshal((uint32_t) 0); - acts->__tmp_4 = ssm_marshal((uint32_t) 10); - ssm_dup(acts->cout); - acts->__tmp_5 = ssm_marshal((uint32_t) 108); - ssm_later(acts->cout, ssm_now() + (uint32_t) ssm_unmarshal(acts->__tmp_4), acts->__tmp_5); - ssm_drop(acts->__tmp_4); - ssm_drop(acts->__tmp_5); - ssm_drop(acts->cout); - acts->anon4_underscore = ssm_marshal((uint32_t) 0); - ssm_dup(acts->cout); - ssm_sensitize(acts->cout, &acts->__trig_1); - actg->pc = 3; - return; - - case 3: - ; - ssm_desensitize(&acts->__trig_1); - ssm_drop(acts->cout); - acts->anon5_underscore = ssm_marshal((uint32_t) 0); - acts->__tmp_6 = ssm_marshal((uint32_t) 10); - ssm_dup(acts->cout); - acts->__tmp_7 = ssm_marshal((uint32_t) 108); - ssm_later(acts->cout, ssm_now() + (uint32_t) ssm_unmarshal(acts->__tmp_6), acts->__tmp_7); - ssm_drop(acts->__tmp_6); - ssm_drop(acts->__tmp_7); - ssm_drop(acts->cout); - acts->anon6_underscore = ssm_marshal((uint32_t) 0); - ssm_dup(acts->cout); - ssm_sensitize(acts->cout, &acts->__trig_1); - actg->pc = 4; - return; - - case 4: - ; - ssm_desensitize(&acts->__trig_1); - ssm_drop(acts->cout); - acts->anon7_underscore = ssm_marshal((uint32_t) 0); - acts->__tmp_8 = ssm_marshal((uint32_t) 10); - ssm_dup(acts->cout); - acts->__tmp_9 = ssm_marshal((uint32_t) 111); - ssm_later(acts->cout, ssm_now() + (uint32_t) ssm_unmarshal(acts->__tmp_8), acts->__tmp_9); - ssm_drop(acts->__tmp_8); - ssm_drop(acts->__tmp_9); - ssm_drop(acts->cout); - acts->anon8_underscore = ssm_marshal((uint32_t) 0); - ssm_dup(acts->cout); - ssm_sensitize(acts->cout, &acts->__trig_1); - actg->pc = 5; - return; - - case 5: - ; - ssm_desensitize(&acts->__trig_1); - ssm_drop(acts->cout); - acts->anon9_underscore = ssm_marshal((uint32_t) 0); - acts->__tmp_10 = ssm_marshal((uint32_t) 10); - ssm_dup(acts->cout); - acts->__tmp_11 = ssm_marshal((uint32_t) 10); - ssm_later(acts->cout, ssm_now() + (uint32_t) ssm_unmarshal(acts->__tmp_10), acts->__tmp_11); - ssm_drop(acts->__tmp_10); - ssm_drop(acts->__tmp_11); - ssm_drop(acts->cout); - acts->anon10_underscore = ssm_marshal((uint32_t) 0); - ssm_dup(acts->cout); - ssm_sensitize(acts->cout, &acts->__trig_1); - actg->pc = 6; - return; - - case 6: - ; - ssm_desensitize(&acts->__trig_1); - ssm_drop(acts->cout); - acts->anon11_underscore = ssm_marshal((uint32_t) 0); - acts->__tmp_12 = ssm_marshal((uint32_t) 10); - ssm_dup(acts->cout); - acts->__tmp_13 = ssm_marshal((uint32_t) 0); - ssm_later(acts->cout, ssm_now() + (uint32_t) ssm_unmarshal(acts->__tmp_12), acts->__tmp_13); - ssm_drop(acts->__tmp_12); - ssm_drop(acts->__tmp_13); - ssm_drop(acts->cout); - acts->anon12_underscore = ssm_marshal((uint32_t) 0); - ssm_dup(acts->cout); - ssm_sensitize(acts->cout, &acts->__trig_1); - actg->pc = 7; - return; - - case 7: - ; - ssm_desensitize(&acts->__trig_1); - ssm_drop(acts->cout); - ssm_drop(acts->anon12_underscore); - ssm_drop(acts->anon11_underscore); - ssm_drop(acts->anon10_underscore); - ssm_drop(acts->anon9_underscore); - ssm_drop(acts->anon8_underscore); - ssm_drop(acts->anon7_underscore); - ssm_drop(acts->anon6_underscore); - ssm_drop(acts->anon5_underscore); - ssm_drop(acts->anon4_underscore); - ssm_drop(acts->anon3_underscore); - ssm_drop(acts->anon2_underscore); - ssm_drop(acts->anon1_underscore); - ssm_drop(acts->anon0_underscore); - ssm_drop(acts->cout); - ssm_drop(acts->cint); - - default: - break; - } - if (acts->__return_val) - *acts->__return_val = ssm_marshal((uint32_t) 0); - - __leave_step: - ssm_leave(actg, sizeof(act_main_t)); -} - From a0185ac2192941d2e9453a8f9b82a77897ae037c Mon Sep 17 00:00:00 2001 From: Max Acebal Date: Tue, 8 Nov 2022 15:26:09 -0500 Subject: [PATCH 11/19] DesugarLists partial implementation --- src/Front/DesugarLists.hs | 46 +++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/Front/DesugarLists.hs b/src/Front/DesugarLists.hs index 6d009f75..2f345040 100644 --- a/src/Front/DesugarLists.hs +++ b/src/Front/DesugarLists.hs @@ -1,29 +1,37 @@ -- | Desugar ListExpr nodes into App nodes module Front.DesugarLists - ( desugarLists - ) where + ( desugarLists, + ) +where -import qualified Common.Compiler as Compiler -import Front.Ast ( Definition(..) - , Expr(..) - , Program(..) - , TopDef(..) - ) +import qualified Common.Compiler as Compiler +import Front.Ast as A +import Common.Identifiers as I -- | Desugar ListExpr nodes inside of an AST 'Program'. desugarLists :: Program -> Compiler.Pass Program -desugarLists (Program decls) = return $ Program $ desugarTop <$> decls - where - desugarTop (TopDef d) = TopDef $ desugarDef d - desugarTop t = t +desugarLists (Program decls) = return $ Program $ desugarTop <$> decls --test + where + desugarTop (TopDef d) = TopDef $ desugarDef d + desugarTop t = t + -- test = Compiler.unexpected $ (show $ (A.foldApp) (A.Id (I.Identifier "Cons")) [(Lit (LitInt 1)), (Lit (LitInt 2))]) + desugarDef (DefFn v bs t e) = DefFn v bs t $ desugarExpr e + desugarDef (DefPat b e) = DefPat b $ desugarExpr e - desugarDef (DefFn v bs t e) = DefFn v bs t $ desugarExpr e - desugarDef (DefPat b e ) = DefPat b $ desugarExpr e - --- | Transform a node of type ListExpr into a node of type App +-- | Transform a node of type ListExpr into a node of type App -- For ex, (ListExpr [1, 2, 3]) turns into --- App (App (Id "Cons") (Lit (LitInt 1) )) --- (App (App (Id "Cons") (Lit (LitInt 2))) +-- App (App (Id "Cons") (Lit (LitInt 1) )) +-- (App (App (Id "Cons") (Lit (LitInt 2))) -- (App (App (Id "Cons") (Lit (LitInt 3))) (id "Nil"))) + +appidhelper:: A.ListExpr -> A.ListExpr +appidhelper [] = [(A.Id (I.Identifier "App")) (A.Id (I.Identifier "Cons")) (A.Id (I.Identifier "Nil"))] +appidhelper (h:t) = A.Id (I.Identifier "App") (A.Id (I.Identifier "Cons")) h : appidhelper t + +--[(A.Id (I.Identifier "App")) (A.Id (I.Identifier "Cons")) | i <- a] desugarExpr :: Expr -> Expr -desugarExpr e = e -- TODO: actually implement transformation +--desugarExpr _ = Compiler.unexpected $ (show (A.Lit(A.LitInt 5))) +desugarExpr (A.ListExpr es) = A.foldApp h t +where + (h : t) = appidhelper es + From bc26a7d5a9332bf0d08171939ac9209f8c68c189 Mon Sep 17 00:00:00 2001 From: EmilySillars Date: Thu, 10 Nov 2022 10:02:03 -0500 Subject: [PATCH 12/19] add dev hints --- src/Front/DesugarLists.hs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Front/DesugarLists.hs b/src/Front/DesugarLists.hs index 2f345040..55d6f04c 100644 --- a/src/Front/DesugarLists.hs +++ b/src/Front/DesugarLists.hs @@ -1,6 +1,6 @@ -- | Desugar ListExpr nodes into App nodes module Front.DesugarLists - ( desugarLists, + ( desugarLists ) where @@ -24,14 +24,31 @@ desugarLists (Program decls) = return $ Program $ desugarTop <$> decls --test -- (App (App (Id "Cons") (Lit (LitInt 2))) -- (App (App (Id "Cons") (Lit (LitInt 3))) (id "Nil"))) +{- appidhelper:: A.ListExpr -> A.ListExpr appidhelper [] = [(A.Id (I.Identifier "App")) (A.Id (I.Identifier "Cons")) (A.Id (I.Identifier "Nil"))] appidhelper (h:t) = A.Id (I.Identifier "App") (A.Id (I.Identifier "Cons")) h : appidhelper t + +ListExpr is not a type, it's a data constructor. +Data constructors return an instance of a type. +ListExpr is a data constructor that returns an instance of type Expr. +It's not possible to have a function that takes in +something of type ListExpr and returns something of type ListExpr, because a ListExpr is not a type. +It is possible to have a function that takes in +something of type Expr and returns something of type Expr! +Then you can special case on instance of ListExpr. +I think this is what you wanted to do. +-} + +appidhelper:: Expr -> Expr +appidhelper (ListExpr []) = [(A.Id (I.Identifier "App")) (A.Id (I.Identifier "Cons")) (A.Id (I.Identifier "Nil"))] +appidhelper (ListExpr (h:t)) = A.Id (I.Identifier "App") (A.Id (I.Identifier "Cons")) h : appidhelper t +appidhelper e = e -- if it's not a listExpr instance, don't do anything + --[(A.Id (I.Identifier "App")) (A.Id (I.Identifier "Cons")) | i <- a] desugarExpr :: Expr -> Expr --desugarExpr _ = Compiler.unexpected $ (show (A.Lit(A.LitInt 5))) desugarExpr (A.ListExpr es) = A.foldApp h t -where - (h : t) = appidhelper es - + where (h : t) = appidhelper es +desugarExpr e = e -- if it's not a listExpr instance, don't do anything From 0cc35f72d5ebec1c8a4f9266d7d3f209fbc65bb0 Mon Sep 17 00:00:00 2001 From: Max Acebal Date: Fri, 11 Nov 2022 15:00:48 -0500 Subject: [PATCH 13/19] Desugaring Lists progress, no longer using foldapp --- src/Front/DesugarLists.hs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Front/DesugarLists.hs b/src/Front/DesugarLists.hs index 55d6f04c..de08e326 100644 --- a/src/Front/DesugarLists.hs +++ b/src/Front/DesugarLists.hs @@ -10,11 +10,11 @@ import Common.Identifiers as I -- | Desugar ListExpr nodes inside of an AST 'Program'. desugarLists :: Program -> Compiler.Pass Program -desugarLists (Program decls) = return $ Program $ desugarTop <$> decls --test +desugarLists (Program decls) = test -- $ return Program $ desugarTop <$> decls where desugarTop (TopDef d) = TopDef $ desugarDef d desugarTop t = t - -- test = Compiler.unexpected $ (show $ (A.foldApp) (A.Id (I.Identifier "Cons")) [(Lit (LitInt 1)), (Lit (LitInt 2))]) + test = Compiler.unexpected $ show $ (appidhelper [(Lit (LitInt 1)), (Lit (LitInt 2))]) desugarDef (DefFn v bs t e) = DefFn v bs t $ desugarExpr e desugarDef (DefPat b e) = DefPat b $ desugarExpr e @@ -40,15 +40,13 @@ Then you can special case on instance of ListExpr. I think this is what you wanted to do. -} -appidhelper:: Expr -> Expr -appidhelper (ListExpr []) = [(A.Id (I.Identifier "App")) (A.Id (I.Identifier "Cons")) (A.Id (I.Identifier "Nil"))] -appidhelper (ListExpr (h:t)) = A.Id (I.Identifier "App") (A.Id (I.Identifier "Cons")) h : appidhelper t -appidhelper e = e -- if it's not a listExpr instance, don't do anything +appidhelper:: [A.Expr] -> A.Expr +appidhelper (A.ListExpr []) = (A.Id (I.Identifier "Nil")) +appidhelper (A.ListExpr (h:t)) = A.Apply (A.Apply (A.Id (I.Identifier "Cons") h)) (appidhelper t) - --[(A.Id (I.Identifier "App")) (A.Id (I.Identifier "Cons")) | i <- a] desugarExpr :: Expr -> Expr --desugarExpr _ = Compiler.unexpected $ (show (A.Lit(A.LitInt 5))) -desugarExpr (A.ListExpr es) = A.foldApp h t - where (h : t) = appidhelper es -desugarExpr e = e -- if it's not a listExpr instance, don't do anything +desugarExpr (A.ListExpr es) = appidhelper es +desugarExpr (A.ListExpr []) = (A.Id (I.Identifier "Nil")) +desugarExpr e = e -- if it's not a listExpr instance, don't do anything \ No newline at end of file From 88a1504546125cc46c9c8ce403d154dfcfff1aa8 Mon Sep 17 00:00:00 2001 From: Max Acebal Date: Fri, 18 Nov 2022 15:11:25 -0500 Subject: [PATCH 14/19] desugar lists with errors --- regression-tests/tests/lists_sample.ssl | 2 +- src/Front/DesugarLists.hs | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/regression-tests/tests/lists_sample.ssl b/regression-tests/tests/lists_sample.ssl index 3cad9f1d..8570a488 100644 --- a/regression-tests/tests/lists_sample.ssl +++ b/regression-tests/tests/lists_sample.ssl @@ -15,5 +15,5 @@ */ main cin cout = - // let lst = [] // will uncomment this when list syntax works end-to-end + let lst = [1,2,3] // will uncomment this when list syntax works end-to-end () // main must return unit diff --git a/src/Front/DesugarLists.hs b/src/Front/DesugarLists.hs index de08e326..2ce98746 100644 --- a/src/Front/DesugarLists.hs +++ b/src/Front/DesugarLists.hs @@ -5,16 +5,16 @@ module Front.DesugarLists where import qualified Common.Compiler as Compiler -import Front.Ast as A +import Front.Ast (Definition(..), Expr(..), Program(..), TopDef(..), Literal(..)) import Common.Identifiers as I -- | Desugar ListExpr nodes inside of an AST 'Program'. desugarLists :: Program -> Compiler.Pass Program -desugarLists (Program decls) = test -- $ return Program $ desugarTop <$> decls +desugarLists (Program decls) = return $ Program $ desugarTop <$> decls where desugarTop (TopDef d) = TopDef $ desugarDef d desugarTop t = t - test = Compiler.unexpected $ show $ (appidhelper [(Lit (LitInt 1)), (Lit (LitInt 2))]) + --test = Compiler.unexpected $ show $ (appidhelper [(Lit (LitInt 1)), (Lit (LitInt 2))]) desugarDef (DefFn v bs t e) = DefFn v bs t $ desugarExpr e desugarDef (DefPat b e) = DefPat b $ desugarExpr e @@ -40,13 +40,16 @@ Then you can special case on instance of ListExpr. I think this is what you wanted to do. -} -appidhelper:: [A.Expr] -> A.Expr -appidhelper (A.ListExpr []) = (A.Id (I.Identifier "Nil")) -appidhelper (A.ListExpr (h:t)) = A.Apply (A.Apply (A.Id (I.Identifier "Cons") h)) (appidhelper t) +appidhelper:: [Expr] -> Expr +appidhelper ([]) = (Id (I.Identifier "Nil")) +appidhelper ((h:t)) = Apply (Apply (Id (I.Identifier "Cons")) h) (appidhelper t) --[(A.Id (I.Identifier "App")) (A.Id (I.Identifier "Cons")) | i <- a] desugarExpr :: Expr -> Expr --desugarExpr _ = Compiler.unexpected $ (show (A.Lit(A.LitInt 5))) -desugarExpr (A.ListExpr es) = appidhelper es -desugarExpr (A.ListExpr []) = (A.Id (I.Identifier "Nil")) -desugarExpr e = e -- if it's not a listExpr instance, don't do anything \ No newline at end of file +desugarExpr (ListExpr es) = appidhelper es +desugarExpr (ListExpr []) = (Id (I.Identifier "Nil")) +desugarExpr e = e -- if it's not a listExpr instance, don't do anything + + +-- Not on literal, no expr, break, cquote \ No newline at end of file From 1528dcc03fa40dc4da2247e84c6b67cab5919cf9 Mon Sep 17 00:00:00 2001 From: Max Acebal Date: Thu, 1 Dec 2022 18:24:24 -0500 Subject: [PATCH 15/19] Bypass matching on diff Exprs --- src/Front.hs | 2 +- src/Front/DesugarLists.hs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Front.hs b/src/Front.hs index ac10a14f..8c462528 100644 --- a/src/Front.hs +++ b/src/Front.hs @@ -84,7 +84,7 @@ parseAst opt src = do astL <- desugarLists astS -- TODO: other desugaring - let astTuple = insertTypeDef pairDef astP + let astTuple = insertTypeDef pairDef astL Pattern.checkAnomaly astTuple astD <- Pattern.desugarProgram astTuple diff --git a/src/Front/DesugarLists.hs b/src/Front/DesugarLists.hs index 2ce98746..2a241ba4 100644 --- a/src/Front/DesugarLists.hs +++ b/src/Front/DesugarLists.hs @@ -4,6 +4,7 @@ module Front.DesugarLists ) where +import Data.Generics import qualified Common.Compiler as Compiler import Front.Ast (Definition(..), Expr(..), Program(..), TopDef(..), Literal(..)) import Common.Identifiers as I @@ -15,8 +16,8 @@ desugarLists (Program decls) = return $ Program $ desugarTop <$> decls desugarTop (TopDef d) = TopDef $ desugarDef d desugarTop t = t --test = Compiler.unexpected $ show $ (appidhelper [(Lit (LitInt 1)), (Lit (LitInt 2))]) - desugarDef (DefFn v bs t e) = DefFn v bs t $ desugarExpr e - desugarDef (DefPat b e) = DefPat b $ desugarExpr e + desugarDef (DefFn v bs t e) = DefFn v bs t $ everywhere (mkT desugarExpr) e + desugarDef (DefPat b e ) = DefPat b $ everywhere (mkT desugarExpr) e -- | Transform a node of type ListExpr into a node of type App -- For ex, (ListExpr [1, 2, 3]) turns into From 92f9ddc623be0d83ba40f4d635757a41e61653e0 Mon Sep 17 00:00:00 2001 From: Max Acebal Date: Fri, 2 Dec 2022 14:12:08 -0500 Subject: [PATCH 16/19] Test cases passing --- regression-tests/tests/lists_sample.out | 1 + regression-tests/tests/lists_sample.ssl | 11 +++++------ regression-tests/tests/lists_sample2.ssl | 2 +- src/Common/Identifiers.hs | 12 +++++++++++- src/Front/DesugarLists.hs | 8 ++++---- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/regression-tests/tests/lists_sample.out b/regression-tests/tests/lists_sample.out index e69de29b..703ca85b 100644 --- a/regression-tests/tests/lists_sample.out +++ b/regression-tests/tests/lists_sample.out @@ -0,0 +1 @@ +1 2 3 \ No newline at end of file diff --git a/regression-tests/tests/lists_sample.ssl b/regression-tests/tests/lists_sample.ssl index 8570a488..8dfd524f 100644 --- a/regression-tests/tests/lists_sample.ssl +++ b/regression-tests/tests/lists_sample.ssl @@ -1,9 +1,8 @@ -/*type List +type List Cons Int List Nil -*/ -/*puts cout s = +puts cout s = match s Cons c ss = after 1, cout <- c @@ -12,8 +11,8 @@ wait cout puts cout ss Nil = () -*/ main cin cout = - let lst = [1,2,3] // will uncomment this when list syntax works end-to-end - () // main must return unit + let lst = [49,50,51] // will uncomment this when list syntax works end-to-end + puts cout lst + // () // main must return unit diff --git a/regression-tests/tests/lists_sample2.ssl b/regression-tests/tests/lists_sample2.ssl index 9d492098..400387f9 100644 --- a/regression-tests/tests/lists_sample2.ssl +++ b/regression-tests/tests/lists_sample2.ssl @@ -13,5 +13,5 @@ puts cout s = Nil = () main cin cout = - let lst = Cons '1' (Cons '2' (Cons '3' (Cons '4' (Cons '5' Nil)))) + let lst = Cons 49 (Cons 50 (Cons 51 (Cons 52 (Cons 53 Nil)))) puts cout lst diff --git a/src/Common/Identifiers.hs b/src/Common/Identifiers.hs index 96996e1d..3c6f530a 100644 --- a/src/Common/Identifiers.hs +++ b/src/Common/Identifiers.hs @@ -62,6 +62,8 @@ module Common.Identifiers , ungenId , tuple , tempTuple + , cons + , nil ) where import Common.Pretty ( Pretty(..) ) @@ -286,4 +288,12 @@ tuple = Identifier "(,)" -- | we'll use this temp tuple name for now due to the naming issue tempTuple :: Identifier -tempTuple = Identifier "Pair" \ No newline at end of file +tempTuple = Identifier "Pair" + +-- | Cons identifier for Lists +cons :: Identifier +cons = Identifier "Cons" + +-- | Nil identifier for Lists +nil :: Identifier +nil = Identifier "Nil" \ No newline at end of file diff --git a/src/Front/DesugarLists.hs b/src/Front/DesugarLists.hs index 2a241ba4..a1b17f87 100644 --- a/src/Front/DesugarLists.hs +++ b/src/Front/DesugarLists.hs @@ -7,7 +7,7 @@ where import Data.Generics import qualified Common.Compiler as Compiler import Front.Ast (Definition(..), Expr(..), Program(..), TopDef(..), Literal(..)) -import Common.Identifiers as I +import Common.Identifiers -- | Desugar ListExpr nodes inside of an AST 'Program'. desugarLists :: Program -> Compiler.Pass Program @@ -42,14 +42,14 @@ I think this is what you wanted to do. -} appidhelper:: [Expr] -> Expr -appidhelper ([]) = (Id (I.Identifier "Nil")) -appidhelper ((h:t)) = Apply (Apply (Id (I.Identifier "Cons")) h) (appidhelper t) +appidhelper ([]) = (Id nil) +appidhelper ((h:t)) = Apply (Apply (Id cons) h) (appidhelper t) --[(A.Id (I.Identifier "App")) (A.Id (I.Identifier "Cons")) | i <- a] desugarExpr :: Expr -> Expr --desugarExpr _ = Compiler.unexpected $ (show (A.Lit(A.LitInt 5))) desugarExpr (ListExpr es) = appidhelper es -desugarExpr (ListExpr []) = (Id (I.Identifier "Nil")) +desugarExpr (ListExpr []) = (Id nil) desugarExpr e = e -- if it's not a listExpr instance, don't do anything From 9277a8923492ace92f4f884066c0f4565aeb1c67 Mon Sep 17 00:00:00 2001 From: Max Acebal Date: Fri, 2 Dec 2022 14:45:06 -0500 Subject: [PATCH 17/19] Added more meaningful tests to lists_sample --- regression-tests/tests/lists_sample.out | 4 +++- regression-tests/tests/lists_sample.ssl | 22 +++++++++++++++++++--- src/Front/DesugarLists.hs | 18 +++++++----------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/regression-tests/tests/lists_sample.out b/regression-tests/tests/lists_sample.out index 703ca85b..40d9a815 100644 --- a/regression-tests/tests/lists_sample.out +++ b/regression-tests/tests/lists_sample.out @@ -1 +1,3 @@ -1 2 3 \ No newline at end of file +1 2 3 +1 + \ No newline at end of file diff --git a/regression-tests/tests/lists_sample.ssl b/regression-tests/tests/lists_sample.ssl index 8dfd524f..9900e8f6 100644 --- a/regression-tests/tests/lists_sample.ssl +++ b/regression-tests/tests/lists_sample.ssl @@ -13,6 +13,22 @@ puts cout s = Nil = () main cin cout = - let lst = [49,50,51] // will uncomment this when list syntax works end-to-end - puts cout lst - // () // main must return unit +// check multi element list + let multi_lst = [49,50,51] + puts cout multi_lst + after 1, cout <- 10 + wait cout + +// check singleton list + let single_lst = [49] + puts cout single_lst + + after 1, cout <- 10 + wait cout + +// check empty element list + let empty_lst = [] + puts cout empty_lst + + after 1, cout <- 10 + wait cout diff --git a/src/Front/DesugarLists.hs b/src/Front/DesugarLists.hs index a1b17f87..dab0b1cd 100644 --- a/src/Front/DesugarLists.hs +++ b/src/Front/DesugarLists.hs @@ -15,15 +15,9 @@ desugarLists (Program decls) = return $ Program $ desugarTop <$> decls where desugarTop (TopDef d) = TopDef $ desugarDef d desugarTop t = t - --test = Compiler.unexpected $ show $ (appidhelper [(Lit (LitInt 1)), (Lit (LitInt 2))]) desugarDef (DefFn v bs t e) = DefFn v bs t $ everywhere (mkT desugarExpr) e desugarDef (DefPat b e ) = DefPat b $ everywhere (mkT desugarExpr) e --- | Transform a node of type ListExpr into a node of type App --- For ex, (ListExpr [1, 2, 3]) turns into --- App (App (Id "Cons") (Lit (LitInt 1) )) --- (App (App (Id "Cons") (Lit (LitInt 2))) --- (App (App (Id "Cons") (Lit (LitInt 3))) (id "Nil"))) {- appidhelper:: A.ListExpr -> A.ListExpr @@ -46,11 +40,13 @@ appidhelper ([]) = (Id nil) appidhelper ((h:t)) = Apply (Apply (Id cons) h) (appidhelper t) --[(A.Id (I.Identifier "App")) (A.Id (I.Identifier "Cons")) | i <- a] + +-- | Transform a node of type ListExpr into a node of type App +-- For ex, (ListExpr [1, 2, 3]) turns into +-- App (App (Id "Cons") (Lit (LitInt 1) )) +-- (App (App (Id "Cons") (Lit (LitInt 2))) +-- (App (App (Id "Cons") (Lit (LitInt 3))) (id "Nil"))) desugarExpr :: Expr -> Expr ---desugarExpr _ = Compiler.unexpected $ (show (A.Lit(A.LitInt 5))) desugarExpr (ListExpr es) = appidhelper es desugarExpr (ListExpr []) = (Id nil) -desugarExpr e = e -- if it's not a listExpr instance, don't do anything - - --- Not on literal, no expr, break, cquote \ No newline at end of file +desugarExpr e = e -- if it's not a listExpr instance, don't do anything \ No newline at end of file From 9f21f51436a868b9fe4f85c018df0bbb2554a09b Mon Sep 17 00:00:00 2001 From: Max Acebal Date: Thu, 8 Dec 2022 21:54:34 -0500 Subject: [PATCH 18/19] Fix warnings and style nits --- regression-tests/tests/lists_sample.out | 2 +- regression-tests/tests/lists_sample2.ssl | 3 +++ src/Common/Identifiers.hs | 2 +- src/Front/DesugarLists.hs | 33 +++++------------------- src/Front/Parser.y | 8 +++--- src/Front/Pattern/Anomaly.hs | 3 +-- src/Front/Pattern/Desugar.hs | 1 - 7 files changed, 16 insertions(+), 36 deletions(-) diff --git a/regression-tests/tests/lists_sample.out b/regression-tests/tests/lists_sample.out index 40d9a815..3cf97b0e 100644 --- a/regression-tests/tests/lists_sample.out +++ b/regression-tests/tests/lists_sample.out @@ -1,3 +1,3 @@ 1 2 3 1 - \ No newline at end of file + diff --git a/regression-tests/tests/lists_sample2.ssl b/regression-tests/tests/lists_sample2.ssl index 400387f9..d914abcf 100644 --- a/regression-tests/tests/lists_sample2.ssl +++ b/regression-tests/tests/lists_sample2.ssl @@ -1,3 +1,6 @@ +// Checking if list ADTs work as intended +// Tests underlying construction of lists + type List Cons Int List Nil diff --git a/src/Common/Identifiers.hs b/src/Common/Identifiers.hs index 3c6f530a..62d096f3 100644 --- a/src/Common/Identifiers.hs +++ b/src/Common/Identifiers.hs @@ -296,4 +296,4 @@ cons = Identifier "Cons" -- | Nil identifier for Lists nil :: Identifier -nil = Identifier "Nil" \ No newline at end of file +nil = Identifier "Nil" diff --git a/src/Front/DesugarLists.hs b/src/Front/DesugarLists.hs index dab0b1cd..e17e2bd4 100644 --- a/src/Front/DesugarLists.hs +++ b/src/Front/DesugarLists.hs @@ -6,7 +6,7 @@ where import Data.Generics import qualified Common.Compiler as Compiler -import Front.Ast (Definition(..), Expr(..), Program(..), TopDef(..), Literal(..)) +import Front.Ast (Definition(..), Expr(..), Program(..), TopDef(..)) import Common.Identifiers -- | Desugar ListExpr nodes inside of an AST 'Program'. @@ -18,35 +18,14 @@ desugarLists (Program decls) = return $ Program $ desugarTop <$> decls desugarDef (DefFn v bs t e) = DefFn v bs t $ everywhere (mkT desugarExpr) e desugarDef (DefPat b e ) = DefPat b $ everywhere (mkT desugarExpr) e - -{- -appidhelper:: A.ListExpr -> A.ListExpr -appidhelper [] = [(A.Id (I.Identifier "App")) (A.Id (I.Identifier "Cons")) (A.Id (I.Identifier "Nil"))] -appidhelper (h:t) = A.Id (I.Identifier "App") (A.Id (I.Identifier "Cons")) h : appidhelper t - -ListExpr is not a type, it's a data constructor. -Data constructors return an instance of a type. -ListExpr is a data constructor that returns an instance of type Expr. -It's not possible to have a function that takes in -something of type ListExpr and returns something of type ListExpr, because a ListExpr is not a type. -It is possible to have a function that takes in -something of type Expr and returns something of type Expr! -Then you can special case on instance of ListExpr. -I think this is what you wanted to do. --} - -appidhelper:: [Expr] -> Expr -appidhelper ([]) = (Id nil) -appidhelper ((h:t)) = Apply (Apply (Id cons) h) (appidhelper t) - ---[(A.Id (I.Identifier "App")) (A.Id (I.Identifier "Cons")) | i <- a] - -- | Transform a node of type ListExpr into a node of type App -- For ex, (ListExpr [1, 2, 3]) turns into -- App (App (Id "Cons") (Lit (LitInt 1) )) -- (App (App (Id "Cons") (Lit (LitInt 2))) -- (App (App (Id "Cons") (Lit (LitInt 3))) (id "Nil"))) desugarExpr :: Expr -> Expr -desugarExpr (ListExpr es) = appidhelper es -desugarExpr (ListExpr []) = (Id nil) -desugarExpr e = e -- if it's not a listExpr instance, don't do anything \ No newline at end of file +desugarExpr (ListExpr es) = helper es + where helper :: [Expr] -> Expr + helper [] = (Id nil) + helper (h:t) = Apply (Apply (Id cons) h) (helper t) +desugarExpr e = e \ No newline at end of file diff --git a/src/Front/Parser.y b/src/Front/Parser.y index a0f9cee5..7372b894 100644 --- a/src/Front/Parser.y +++ b/src/Front/Parser.y @@ -319,12 +319,12 @@ exprAtom -- | List Expression. exprList - :list { $1 } - | {- empty list -} { [] } + :list { $1 } + | {- empty list -} { [] } list - :exprAtom { [$1] } - | exprAtom ',' list { $1 : $3 } + :exprAtom { [$1] } + | exprAtom ',' list { $1 : $3 } -- | Pipe-separated expressions, for parallel composition. exprPar --> [Expr] diff --git a/src/Front/Pattern/Anomaly.hs b/src/Front/Pattern/Anomaly.hs index 466cdba2..5d3dd47b 100644 --- a/src/Front/Pattern/Anomaly.hs +++ b/src/Front/Pattern/Anomaly.hs @@ -99,7 +99,6 @@ checkExprs = mapM_ checkExpr checkExpr :: A.Expr -> AnomalyFn () checkExpr (A.Id _ ) = return () checkExpr (A.Lit _ ) = return () -checkExpr (A.ListExpr es ) = checkExprs es checkExpr (A.Apply e1 e2 ) = checkExprs [e1, e2] checkExpr (A.Lambda _ e ) = checkExpr e -- WARN: patterns here are not checked checkExpr (A.OpRegion e opRegion) = checkExpr e >> checkOpRegion opRegion @@ -119,7 +118,7 @@ checkExpr (A.Match e arms) = let (ps, es) = unzip arms in checkExpr e >> checkExprs es >> checkPats ps checkExpr (A.CQuote _ ) = return () checkExpr (A.CCall _ es) = mapM_ checkExpr es -checkExpr (A.ListExpr _) = return () +checkExpr (A.ListExpr es) = mapM_ checkExpr es checkExpr (A.Tuple es ) = checkExprs es checkOpRegion :: A.OpRegion -> AnomalyFn () diff --git a/src/Front/Pattern/Desugar.hs b/src/Front/Pattern/Desugar.hs index 0aee5a3f..1fa24133 100644 --- a/src/Front/Pattern/Desugar.hs +++ b/src/Front/Pattern/Desugar.hs @@ -341,7 +341,6 @@ substId old new = substExpr in A.Match (substExpr e) (map substArm arms) substExpr e@(A.CQuote _ ) = e substExpr ( A.CCall s es) = A.CCall s $ map substExpr es - substExpr (A.ListExpr es) = A.ListExpr $ map substExpr es singleLet :: Identifier -> A.Expr -> A.Expr -> A.Expr singleLet i e = A.Let [A.DefFn i [] A.TypNone e] From fdab3241a0d466a03d0b2a9d83303d40d9d4106c Mon Sep 17 00:00:00 2001 From: Max Acebal Date: Fri, 9 Dec 2022 14:33:06 -0500 Subject: [PATCH 19/19] fix imports --- src/Front/DesugarLists.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Front/DesugarLists.hs b/src/Front/DesugarLists.hs index d24116bb..5d5cff3c 100644 --- a/src/Front/DesugarLists.hs +++ b/src/Front/DesugarLists.hs @@ -4,7 +4,7 @@ module Front.DesugarLists ) where import qualified Common.Compiler as Compiler -import Common.Identifiers (Identifier(Identifier)) +import Common.Identifiers import Front.Ast ( Definition(..) , Expr(..) , Program(..)