Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lists and tuples #115

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions regression-tests/tests/list4.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A
D
[]
56 changes: 56 additions & 0 deletions regression-tests/tests/list4.ssl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// ./runtests.sh tests/list4.ssl
// stack exec sslc -- --dump-ir tests/list4.ssl
// stack exec sslc -- tests/list4.ssl
// stack exec sslc -- --dump-ir-annotated tests/list4.ssl


type List a
Cons a (List a)
Nil

testfunc (arg0 : Int) -> Int = arg0



main cin cout =
let putc c = after 1, cout <- c
wait cout
let printNil _ = putc '[' // maybe we don't have 0 argument functions yet??
putc ']'

/* maybe we don't have local recursive functions yet??
let printList lst = match lst
Cons h tl = putc h
putc '\n'
printList tl
Nil = printNil
putc '\n'
*/

let x = 'h' + 't' // this should throw an error once character literals are a thing!

// want to add syntax for list here!
let two = Cons 65 (Cons 68 Nil) // 'A' : 'D' : []
//^ instead of this, eventually want to be able to do
//^ let two = ['A', 'D']

match two
Cons c _ = putc c // Should print A
Nil = printNil 33
putc '\n'

match two
Cons _ l = match l
Cons c _ = putc c // Should print D
Nil = printNil 33
Nil = printNil 33
putc '\n'

match two
Cons _ l = match l
Cons _ l = match l
Cons c _ = putc 33 // should never reach here
Nil = printNil 33
Nil = printNil 33
Nil = printNil 33
putc '\n'
2 changes: 1 addition & 1 deletion src/Common/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ spaghetti :: Dumpy t => t -> String
spaghetti = renderString . layoutPretty opts . dumpy
where opts = LayoutOptions { layoutPageWidth = Unbounded }

{- | Lengthy Typeclass: print an ugly but parseable representation of the AST
{- | Dumpy Typeclass: print an ugly but parseable representation of the AST

* Translates from IR to Doc representation in one-to-one fashion
* No simplifications
Expand Down