diff --git a/.gitignore b/.gitignore index 17faeeba..e3f31117 100644 --- a/.gitignore +++ b/.gitignore @@ -24,11 +24,14 @@ cabal.project.local~ .idea *.iml -build/ .gradle +build/ gradle/ Gemfile.lock _site .hlint-*/ +out/ + +/stan.html diff --git a/.output/actual/examples/wsa/il/linkAppFile/from-eas/bottles.il b/.output/actual/examples/wsa/il/linkAppFile/from-eas/bottles.il index dfb92646..5ae5c8f1 100644 --- a/.output/actual/examples/wsa/il/linkAppFile/from-eas/bottles.il +++ b/.output/actual/examples/wsa/il/linkAppFile/from-eas/bottles.il @@ -1 +1,45 @@ -[Push (Literal 3),Mark "LOOP",Dup,OutputNum,PushS (Literal " bottles of beer on the wall, "),Call "prints",Dup,OutputNum,PushS (Literal " bottles of beer"),Call "printsln",PushS (Literal "Take one down, pass it around"),Call "printsln",Push (Literal 1),Sub Nothing,Dup,OutputNum,PushS (Literal " bottles of beer on the wall"),Call "printsln",PushS (Literal ""),Call "printsln",Dup,BranchNZ "LOOP",End,Mark "prints",Dup,BranchZ "prints_end",OutputChar,Branch "prints",Mark "prints_end",Pop,Return,Mark "printsln",Call "prints",Push (Literal 10),OutputChar,Return] \ No newline at end of file +[ Push + ( Literal 3 ) +, Mark "LOOP" +, Dup +, OutputNum +, PushS + ( Literal " bottles of beer on the wall, " ) +, Call "prints" +, Dup +, OutputNum +, PushS + ( Literal " bottles of beer" ) +, Call "printsln" +, PushS + ( Literal "Take one down, pass it around" ) +, Call "printsln" +, Push + ( Literal 1 ) +, Sub Nothing +, Dup +, OutputNum +, PushS + ( Literal " bottles of beer on the wall" ) +, Call "printsln" +, PushS + ( Literal "" ) +, Call "printsln" +, Dup +, BranchNZ "LOOP" +, End +, Mark "prints" +, Dup +, BranchZ "prints_end" +, OutputChar +, Branch "prints" +, Mark "prints_end" +, Pop +, Return +, Mark "printsln" +, Call "prints" +, Push + ( Literal 10 ) +, OutputChar +, Return +] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/linkAppFile/from-eas/hello.il b/.output/actual/examples/wsa/il/linkAppFile/from-eas/hello.il index 7a907ca8..04717598 100644 --- a/.output/actual/examples/wsa/il/linkAppFile/from-eas/hello.il +++ b/.output/actual/examples/wsa/il/linkAppFile/from-eas/hello.il @@ -1 +1,44 @@ -[Push (Literal 32),Push (Literal 44),Push (Literal 111),Push (Literal 108),Push (Literal 108),Push (Literal 101),Push (Literal 72),OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,Push (Literal 10),Push (Literal 33),Push (Literal 100),Push (Literal 108),Push (Literal 114),Push (Literal 111),Push (Literal 119),OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,End] \ No newline at end of file +[ Push + ( Literal 32 ) +, Push + ( Literal 44 ) +, Push + ( Literal 111 ) +, Push + ( Literal 108 ) +, Push + ( Literal 108 ) +, Push + ( Literal 101 ) +, Push + ( Literal 72 ) +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, Push + ( Literal 10 ) +, Push + ( Literal 33 ) +, Push + ( Literal 100 ) +, Push + ( Literal 108 ) +, Push + ( Literal 114 ) +, Push + ( Literal 111 ) +, Push + ( Literal 119 ) +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, End +] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/linkAppFile/from-eas/hello2.il b/.output/actual/examples/wsa/il/linkAppFile/from-eas/hello2.il index d82da1bb..e353881e 100644 --- a/.output/actual/examples/wsa/il/linkAppFile/from-eas/hello2.il +++ b/.output/actual/examples/wsa/il/linkAppFile/from-eas/hello2.il @@ -1 +1,47 @@ -[Push (Literal 0),Push (Literal 10),Push (Literal 33),Push (Literal 100),Push (Literal 108),Push (Literal 114),Push (Literal 111),Push (Literal 119),Push (Literal 32),Push (Literal 44),Push (Literal 111),Push (Literal 108),Push (Literal 108),Push (Literal 101),Push (Literal 72),Call "prints",End,Mark "prints",Dup,BranchZ "prints_end",OutputChar,Branch "prints",Mark "prints_end",Pop,Return,Mark "printsln",Call "prints",Push (Literal 10),OutputChar,Return] \ No newline at end of file +[ Push + ( Literal 0 ) +, Push + ( Literal 10 ) +, Push + ( Literal 33 ) +, Push + ( Literal 100 ) +, Push + ( Literal 108 ) +, Push + ( Literal 114 ) +, Push + ( Literal 111 ) +, Push + ( Literal 119 ) +, Push + ( Literal 32 ) +, Push + ( Literal 44 ) +, Push + ( Literal 111 ) +, Push + ( Literal 108 ) +, Push + ( Literal 108 ) +, Push + ( Literal 101 ) +, Push + ( Literal 72 ) +, Call "prints" +, End +, Mark "prints" +, Dup +, BranchZ "prints_end" +, OutputChar +, Branch "prints" +, Mark "prints_end" +, Pop +, Return +, Mark "printsln" +, Call "prints" +, Push + ( Literal 10 ) +, OutputChar +, Return +] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/linkAppFile/from-eas/hello4.il b/.output/actual/examples/wsa/il/linkAppFile/from-eas/hello4.il index 46e34b94..6545f652 100644 --- a/.output/actual/examples/wsa/il/linkAppFile/from-eas/hello4.il +++ b/.output/actual/examples/wsa/il/linkAppFile/from-eas/hello4.il @@ -1 +1,19 @@ -[PushS (Literal "Hello, world!"),Call "printsln",End,Mark "prints",Dup,BranchZ "prints_end",OutputChar,Branch "prints",Mark "prints_end",Pop,Return,Mark "printsln",Call "prints",Push (Literal 10),OutputChar,Return] \ No newline at end of file +[ PushS + ( Literal "Hello, world!" ) +, Call "printsln" +, End +, Mark "prints" +, Dup +, BranchZ "prints_end" +, OutputChar +, Branch "prints" +, Mark "prints_end" +, Pop +, Return +, Mark "printsln" +, Call "prints" +, Push + ( Literal 10 ) +, OutputChar +, Return +] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/linkAppFile/from-eas/pip.il b/.output/actual/examples/wsa/il/linkAppFile/from-eas/pip.il index de1a133f..829f55f1 100644 --- a/.output/actual/examples/wsa/il/linkAppFile/from-eas/pip.il +++ b/.output/actual/examples/wsa/il/linkAppFile/from-eas/pip.il @@ -1 +1,14 @@ -[Mark "LOOP",Dup,Push (Literal 0),Push (Literal 1),Sub Nothing,Sub Nothing,BranchNZ "WRITE",End,Mark "WRITE",OutputChar,Branch "LOOP"] \ No newline at end of file +[ Mark "LOOP" +, Dup +, Push + ( Literal 0 ) +, Push + ( Literal 1 ) +, Sub Nothing +, Sub Nothing +, BranchNZ "WRITE" +, End +, Mark "WRITE" +, OutputChar +, Branch "LOOP" +] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/linkAppFile/from-eas/true.il b/.output/actual/examples/wsa/il/linkAppFile/from-eas/true.il index f93ec408..7f93ef7d 100644 --- a/.output/actual/examples/wsa/il/linkAppFile/from-eas/true.il +++ b/.output/actual/examples/wsa/il/linkAppFile/from-eas/true.il @@ -1 +1 @@ -[End] \ No newline at end of file +[ End ] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/linkAppFile/original/prim.il b/.output/actual/examples/wsa/il/linkAppFile/original/prim.il index 270eecdf..6ff9a1fc 100644 --- a/.output/actual/examples/wsa/il/linkAppFile/original/prim.il +++ b/.output/actual/examples/wsa/il/linkAppFile/original/prim.il @@ -1 +1,120 @@ -[Mark "st",PushS (Literal "prim numbers [2-100]"),Call "printsln",Push (Literal 0),Mark "f_start_1",Test 100,BranchZ "f_finished_1",Dup,Add (Just (Literal 100)),Push (Literal 1),Store Nothing,Add (Just (Literal 1)),Branch "f_start_1",Mark "f_finished_1",Pop,Push (Literal 2),Mark "f_start_2",Test 11,BranchZ "f_finished_2",Push (Literal 2),Mark "f_start_3",Test 100,BranchZ "f_finished_3",Dup,Push (Literal 1),Swap,Store Nothing,Swap,Dup,Push (Literal 2),Swap,Store Nothing,Swap,Load (Just (Literal 1)),Load (Just (Literal 2)),Mul Nothing,Add (Just (Literal 100)),Push (Literal 0),Store Nothing,Add (Just (Literal 1)),Branch "f_start_3",Mark "f_finished_3",Pop,Add (Just (Literal 1)),Branch "f_start_2",Mark "f_finished_2",Pop,Push (Literal 2),Mark "f_start_4",Test 100,BranchZ "f_finished_4",Dup,Add (Just (Literal 100)),Load Nothing,BranchZ "nodraw",Dup,OutputNum,PushS (Literal " "),Call "prints",Mark "nodraw",Add (Just (Literal 1)),Branch "f_start_4",Mark "f_finished_4",Pop,Push (Literal 0),Call "printsln",End,Mark "prints",Dup,BranchZ "prints_end",OutputChar,Branch "prints",Mark "prints_end",Pop,Return,Mark "printsln",Call "prints",Push (Literal 10),OutputChar,Return] \ No newline at end of file +[ Mark "st" +, PushS + ( Literal "prim numbers [2-100]" ) +, Call "printsln" +, Push + ( Literal 0 ) +, Mark "f_start_1" +, Test 100 +, BranchZ "f_finished_1" +, Dup +, Add + ( Just + ( Literal 100 ) + ) +, Push + ( Literal 1 ) +, Store Nothing +, Add + ( Just + ( Literal 1 ) + ) +, Branch "f_start_1" +, Mark "f_finished_1" +, Pop +, Push + ( Literal 2 ) +, Mark "f_start_2" +, Test 11 +, BranchZ "f_finished_2" +, Push + ( Literal 2 ) +, Mark "f_start_3" +, Test 100 +, BranchZ "f_finished_3" +, Dup +, Push + ( Literal 1 ) +, Swap +, Store Nothing +, Swap +, Dup +, Push + ( Literal 2 ) +, Swap +, Store Nothing +, Swap +, Load + ( Just + ( Literal 1 ) + ) +, Load + ( Just + ( Literal 2 ) + ) +, Mul Nothing +, Add + ( Just + ( Literal 100 ) + ) +, Push + ( Literal 0 ) +, Store Nothing +, Add + ( Just + ( Literal 1 ) + ) +, Branch "f_start_3" +, Mark "f_finished_3" +, Pop +, Add + ( Just + ( Literal 1 ) + ) +, Branch "f_start_2" +, Mark "f_finished_2" +, Pop +, Push + ( Literal 2 ) +, Mark "f_start_4" +, Test 100 +, BranchZ "f_finished_4" +, Dup +, Add + ( Just + ( Literal 100 ) + ) +, Load Nothing +, BranchZ "nodraw" +, Dup +, OutputNum +, PushS + ( Literal " " ) +, Call "prints" +, Mark "nodraw" +, Add + ( Just + ( Literal 1 ) + ) +, Branch "f_start_4" +, Mark "f_finished_4" +, Pop +, Push + ( Literal 0 ) +, Call "printsln" +, End +, Mark "prints" +, Dup +, BranchZ "prints_end" +, OutputChar +, Branch "prints" +, Mark "prints_end" +, Pop +, Return +, Mark "printsln" +, Call "prints" +, Push + ( Literal 10 ) +, OutputChar +, Return +] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/linkLibFile/io.il b/.output/actual/examples/wsa/il/linkLibFile/io.il index d0e7bba1..a4542d9e 100644 --- a/.output/actual/examples/wsa/il/linkLibFile/io.il +++ b/.output/actual/examples/wsa/il/linkLibFile/io.il @@ -1 +1,15 @@ -[Mark "prints",Dup,BranchZ "prints_end",OutputChar,Branch "prints",Mark "prints_end",Pop,Return,Mark "printsln",Call "prints",Push (Literal 10),OutputChar,Return] \ No newline at end of file +[ Mark "prints" +, Dup +, BranchZ "prints_end" +, OutputChar +, Branch "prints" +, Mark "prints_end" +, Pop +, Return +, Mark "printsln" +, Call "prints" +, Push + ( Literal 10 ) +, OutputChar +, Return +] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/linkLibFile/memory.il b/.output/actual/examples/wsa/il/linkLibFile/memory.il index 74ede482..ebc82bf6 100644 --- a/.output/actual/examples/wsa/il/linkLibFile/memory.il +++ b/.output/actual/examples/wsa/il/linkLibFile/memory.il @@ -1 +1,205 @@ -[Mark "memcopy",Mark "mem_copy",Mark "mem_move",Push (Literal 3),Swap,Store Nothing,Push (Literal 2),Swap,Store Nothing,Push (Literal 1),Swap,Store Nothing,Load (Just (Literal 3)),BranchNP "memcopy_end",Load (Just (Literal 1)),Load (Just (Literal 2)),Sub Nothing,BranchZ "memcopy_end",Load (Just (Literal 1)),Load (Just (Literal 2)),Sub Nothing,BranchM "memcopy_loop_dest_greater_source_begin",Branch "memcopy_loop_source_greater_dest",Mark "memcopy_loop_source_greater_dest",Push (Literal 2),Load Nothing,Push (Literal 1),Load Nothing,Load Nothing,Store Nothing,Push (Literal 2),Push (Literal 2),Load Nothing,Push (Literal 1),Add Nothing,Store Nothing,Push (Literal 1),Push (Literal 1),Load Nothing,Push (Literal 1),Add Nothing,Store Nothing,Push (Literal 3),Push (Literal 3),Load Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Load (Just (Literal 3)),BranchZ "memcopy_end",Branch "memcopy_loop_source_greater_dest",Mark "memcopy_loop_dest_greater_source_begin",Push (Literal 2),Push (Literal 2),Load Nothing,Push (Literal 3),Load Nothing,Add Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Push (Literal 1),Push (Literal 1),Load Nothing,Push (Literal 3),Load Nothing,Add Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Mark "memcopy_loop_dest_greater_source",Push (Literal 2),Load Nothing,Push (Literal 1),Load Nothing,Load Nothing,Store Nothing,Push (Literal 2),Push (Literal 2),Load Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Push (Literal 1),Push (Literal 1),Load Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Push (Literal 3),Push (Literal 3),Load Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Load (Just (Literal 3)),BranchZ "memcopy_end",Branch "memcopy_loop_dest_greater_source",Mark "memcopy_end",Return,Mark "mem_zero",Mark "mem_zero_start",Dup,BranchZ "mem_zero_end",Swap,Dup,Push (Literal 0),Store Nothing,Push (Literal 1),Add Nothing,Swap,Push (Literal 1),Sub Nothing,Branch "mem_zero_start",Mark "mem_zero_end",Pop,Pop,Return,Mark "numeriere",Push (Literal 2),Swap,Store Nothing,Push (Literal 1),Swap,Store Nothing,Push (Literal 1),Load Nothing,Mark "numeriere_start",Dup,Dup,Store Nothing,Push (Literal 1),Add Nothing,Dup,Push (Literal 2),Load Nothing,Sub Nothing,BranchZ "numeriere_end",Branch "numeriere_start",Mark "numeriere_end",Pop,Return] \ No newline at end of file +[ Mark "memcopy" +, Mark "mem_copy" +, Mark "mem_move" +, Push + ( Literal 3 ) +, Swap +, Store Nothing +, Push + ( Literal 2 ) +, Swap +, Store Nothing +, Push + ( Literal 1 ) +, Swap +, Store Nothing +, Load + ( Just + ( Literal 3 ) + ) +, BranchNP "memcopy_end" +, Load + ( Just + ( Literal 1 ) + ) +, Load + ( Just + ( Literal 2 ) + ) +, Sub Nothing +, BranchZ "memcopy_end" +, Load + ( Just + ( Literal 1 ) + ) +, Load + ( Just + ( Literal 2 ) + ) +, Sub Nothing +, BranchM "memcopy_loop_dest_greater_source_begin" +, Branch "memcopy_loop_source_greater_dest" +, Mark "memcopy_loop_source_greater_dest" +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 1 ) +, Load Nothing +, Load Nothing +, Store Nothing +, Push + ( Literal 2 ) +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 1 ) +, Add Nothing +, Store Nothing +, Push + ( Literal 1 ) +, Push + ( Literal 1 ) +, Load Nothing +, Push + ( Literal 1 ) +, Add Nothing +, Store Nothing +, Push + ( Literal 3 ) +, Push + ( Literal 3 ) +, Load Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Load + ( Just + ( Literal 3 ) + ) +, BranchZ "memcopy_end" +, Branch "memcopy_loop_source_greater_dest" +, Mark "memcopy_loop_dest_greater_source_begin" +, Push + ( Literal 2 ) +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 3 ) +, Load Nothing +, Add Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Push + ( Literal 1 ) +, Push + ( Literal 1 ) +, Load Nothing +, Push + ( Literal 3 ) +, Load Nothing +, Add Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Mark "memcopy_loop_dest_greater_source" +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 1 ) +, Load Nothing +, Load Nothing +, Store Nothing +, Push + ( Literal 2 ) +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Push + ( Literal 1 ) +, Push + ( Literal 1 ) +, Load Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Push + ( Literal 3 ) +, Push + ( Literal 3 ) +, Load Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Load + ( Just + ( Literal 3 ) + ) +, BranchZ "memcopy_end" +, Branch "memcopy_loop_dest_greater_source" +, Mark "memcopy_end" +, Return +, Mark "mem_zero" +, Mark "mem_zero_start" +, Dup +, BranchZ "mem_zero_end" +, Swap +, Dup +, Push + ( Literal 0 ) +, Store Nothing +, Push + ( Literal 1 ) +, Add Nothing +, Swap +, Push + ( Literal 1 ) +, Sub Nothing +, Branch "mem_zero_start" +, Mark "mem_zero_end" +, Pop +, Pop +, Return +, Mark "numeriere" +, Push + ( Literal 2 ) +, Swap +, Store Nothing +, Push + ( Literal 1 ) +, Swap +, Store Nothing +, Push + ( Literal 1 ) +, Load Nothing +, Mark "numeriere_start" +, Dup +, Dup +, Store Nothing +, Push + ( Literal 1 ) +, Add Nothing +, Dup +, Push + ( Literal 2 ) +, Load Nothing +, Sub Nothing +, BranchZ "numeriere_end" +, Branch "numeriere_start" +, Mark "numeriere_end" +, Pop +, Return +] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/bottles.il b/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/bottles.il index c254e8f4..c8a36072 100644 --- a/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/bottles.il +++ b/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/bottles.il @@ -1 +1,32 @@ -[Include "io",Push (Literal 3),Mark "LOOP",Dup,OutputNum,PushS (Literal " bottles of beer on the wall, "),Call "prints",Dup,OutputNum,PushS (Literal " bottles of beer"),Call "printsln",PushS (Literal "Take one down, pass it around"),Call "printsln",Push (Literal 1),Sub Nothing,Dup,OutputNum,PushS (Literal " bottles of beer on the wall"),Call "printsln",PushS (Literal ""),Call "printsln",Dup,BranchNZ "LOOP",End] \ No newline at end of file +[ Include "io" +, Push + ( Literal 3 ) +, Mark "LOOP" +, Dup +, OutputNum +, PushS + ( Literal " bottles of beer on the wall, " ) +, Call "prints" +, Dup +, OutputNum +, PushS + ( Literal " bottles of beer" ) +, Call "printsln" +, PushS + ( Literal "Take one down, pass it around" ) +, Call "printsln" +, Push + ( Literal 1 ) +, Sub Nothing +, Dup +, OutputNum +, PushS + ( Literal " bottles of beer on the wall" ) +, Call "printsln" +, PushS + ( Literal "" ) +, Call "printsln" +, Dup +, BranchNZ "LOOP" +, End +] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/hello.il b/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/hello.il index 7a907ca8..04717598 100644 --- a/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/hello.il +++ b/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/hello.il @@ -1 +1,44 @@ -[Push (Literal 32),Push (Literal 44),Push (Literal 111),Push (Literal 108),Push (Literal 108),Push (Literal 101),Push (Literal 72),OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,Push (Literal 10),Push (Literal 33),Push (Literal 100),Push (Literal 108),Push (Literal 114),Push (Literal 111),Push (Literal 119),OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,End] \ No newline at end of file +[ Push + ( Literal 32 ) +, Push + ( Literal 44 ) +, Push + ( Literal 111 ) +, Push + ( Literal 108 ) +, Push + ( Literal 108 ) +, Push + ( Literal 101 ) +, Push + ( Literal 72 ) +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, Push + ( Literal 10 ) +, Push + ( Literal 33 ) +, Push + ( Literal 100 ) +, Push + ( Literal 108 ) +, Push + ( Literal 114 ) +, Push + ( Literal 111 ) +, Push + ( Literal 119 ) +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, End +] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/hello2.il b/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/hello2.il index 00e91327..1cd343c3 100644 --- a/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/hello2.il +++ b/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/hello2.il @@ -1 +1,34 @@ -[Include "io",Push (Literal 0),Push (Literal 10),Push (Literal 33),Push (Literal 100),Push (Literal 108),Push (Literal 114),Push (Literal 111),Push (Literal 119),Push (Literal 32),Push (Literal 44),Push (Literal 111),Push (Literal 108),Push (Literal 108),Push (Literal 101),Push (Literal 72),Call "prints",End] \ No newline at end of file +[ Include "io" +, Push + ( Literal 0 ) +, Push + ( Literal 10 ) +, Push + ( Literal 33 ) +, Push + ( Literal 100 ) +, Push + ( Literal 108 ) +, Push + ( Literal 114 ) +, Push + ( Literal 111 ) +, Push + ( Literal 119 ) +, Push + ( Literal 32 ) +, Push + ( Literal 44 ) +, Push + ( Literal 111 ) +, Push + ( Literal 108 ) +, Push + ( Literal 108 ) +, Push + ( Literal 101 ) +, Push + ( Literal 72 ) +, Call "prints" +, End +] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/hello4.il b/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/hello4.il index a1afdd2e..81db1569 100644 --- a/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/hello4.il +++ b/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/hello4.il @@ -1 +1,6 @@ -[Include "io",PushS (Literal "Hello, world!"),Call "printsln",End] \ No newline at end of file +[ Include "io" +, PushS + ( Literal "Hello, world!" ) +, Call "printsln" +, End +] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/pip.il b/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/pip.il index de1a133f..829f55f1 100644 --- a/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/pip.il +++ b/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/pip.il @@ -1 +1,14 @@ -[Mark "LOOP",Dup,Push (Literal 0),Push (Literal 1),Sub Nothing,Sub Nothing,BranchNZ "WRITE",End,Mark "WRITE",OutputChar,Branch "LOOP"] \ No newline at end of file +[ Mark "LOOP" +, Dup +, Push + ( Literal 0 ) +, Push + ( Literal 1 ) +, Sub Nothing +, Sub Nothing +, BranchNZ "WRITE" +, End +, Mark "WRITE" +, OutputChar +, Branch "LOOP" +] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/true.il b/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/true.il index f93ec408..7f93ef7d 100644 --- a/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/true.il +++ b/.output/actual/examples/wsa/il/parseAssemblyApp/from-eas/true.il @@ -1 +1 @@ -[End] \ No newline at end of file +[ End ] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/parseAssemblyApp/original/prim.il b/.output/actual/examples/wsa/il/parseAssemblyApp/original/prim.il index 06495869..2a8c9ace 100644 --- a/.output/actual/examples/wsa/il/parseAssemblyApp/original/prim.il +++ b/.output/actual/examples/wsa/il/parseAssemblyApp/original/prim.il @@ -1 +1,107 @@ -[Include "io",Mark "st",PushS (Literal "prim numbers [2-100]"),Call "printsln",Push (Literal 0),Mark "f_start_1",Test 100,BranchZ "f_finished_1",Dup,Add (Just (Literal 100)),Push (Literal 1),Store Nothing,Add (Just (Literal 1)),Branch "f_start_1",Mark "f_finished_1",Pop,Push (Literal 2),Mark "f_start_2",Test 11,BranchZ "f_finished_2",Push (Literal 2),Mark "f_start_3",Test 100,BranchZ "f_finished_3",Dup,Push (Literal 1),Swap,Store Nothing,Swap,Dup,Push (Literal 2),Swap,Store Nothing,Swap,Load (Just (Literal 1)),Load (Just (Literal 2)),Mul Nothing,Add (Just (Literal 100)),Push (Literal 0),Store Nothing,Add (Just (Literal 1)),Branch "f_start_3",Mark "f_finished_3",Pop,Add (Just (Literal 1)),Branch "f_start_2",Mark "f_finished_2",Pop,Push (Literal 2),Mark "f_start_4",Test 100,BranchZ "f_finished_4",Dup,Add (Just (Literal 100)),Load Nothing,BranchZ "nodraw",Dup,OutputNum,PushS (Literal " "),Call "prints",Mark "nodraw",Add (Just (Literal 1)),Branch "f_start_4",Mark "f_finished_4",Pop,Push (Literal 0),Call "printsln",End] \ No newline at end of file +[ Include "io" +, Mark "st" +, PushS + ( Literal "prim numbers [2-100]" ) +, Call "printsln" +, Push + ( Literal 0 ) +, Mark "f_start_1" +, Test 100 +, BranchZ "f_finished_1" +, Dup +, Add + ( Just + ( Literal 100 ) + ) +, Push + ( Literal 1 ) +, Store Nothing +, Add + ( Just + ( Literal 1 ) + ) +, Branch "f_start_1" +, Mark "f_finished_1" +, Pop +, Push + ( Literal 2 ) +, Mark "f_start_2" +, Test 11 +, BranchZ "f_finished_2" +, Push + ( Literal 2 ) +, Mark "f_start_3" +, Test 100 +, BranchZ "f_finished_3" +, Dup +, Push + ( Literal 1 ) +, Swap +, Store Nothing +, Swap +, Dup +, Push + ( Literal 2 ) +, Swap +, Store Nothing +, Swap +, Load + ( Just + ( Literal 1 ) + ) +, Load + ( Just + ( Literal 2 ) + ) +, Mul Nothing +, Add + ( Just + ( Literal 100 ) + ) +, Push + ( Literal 0 ) +, Store Nothing +, Add + ( Just + ( Literal 1 ) + ) +, Branch "f_start_3" +, Mark "f_finished_3" +, Pop +, Add + ( Just + ( Literal 1 ) + ) +, Branch "f_start_2" +, Mark "f_finished_2" +, Pop +, Push + ( Literal 2 ) +, Mark "f_start_4" +, Test 100 +, BranchZ "f_finished_4" +, Dup +, Add + ( Just + ( Literal 100 ) + ) +, Load Nothing +, BranchZ "nodraw" +, Dup +, OutputNum +, PushS + ( Literal " " ) +, Call "prints" +, Mark "nodraw" +, Add + ( Just + ( Literal 1 ) + ) +, Branch "f_start_4" +, Mark "f_finished_4" +, Pop +, Push + ( Literal 0 ) +, Call "printsln" +, End +] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/parseAssemblyLib/io.il b/.output/actual/examples/wsa/il/parseAssemblyLib/io.il index d0e7bba1..a4542d9e 100644 --- a/.output/actual/examples/wsa/il/parseAssemblyLib/io.il +++ b/.output/actual/examples/wsa/il/parseAssemblyLib/io.il @@ -1 +1,15 @@ -[Mark "prints",Dup,BranchZ "prints_end",OutputChar,Branch "prints",Mark "prints_end",Pop,Return,Mark "printsln",Call "prints",Push (Literal 10),OutputChar,Return] \ No newline at end of file +[ Mark "prints" +, Dup +, BranchZ "prints_end" +, OutputChar +, Branch "prints" +, Mark "prints_end" +, Pop +, Return +, Mark "printsln" +, Call "prints" +, Push + ( Literal 10 ) +, OutputChar +, Return +] \ No newline at end of file diff --git a/.output/actual/examples/wsa/il/parseAssemblyLib/memory.il b/.output/actual/examples/wsa/il/parseAssemblyLib/memory.il index 74ede482..ebc82bf6 100644 --- a/.output/actual/examples/wsa/il/parseAssemblyLib/memory.il +++ b/.output/actual/examples/wsa/il/parseAssemblyLib/memory.il @@ -1 +1,205 @@ -[Mark "memcopy",Mark "mem_copy",Mark "mem_move",Push (Literal 3),Swap,Store Nothing,Push (Literal 2),Swap,Store Nothing,Push (Literal 1),Swap,Store Nothing,Load (Just (Literal 3)),BranchNP "memcopy_end",Load (Just (Literal 1)),Load (Just (Literal 2)),Sub Nothing,BranchZ "memcopy_end",Load (Just (Literal 1)),Load (Just (Literal 2)),Sub Nothing,BranchM "memcopy_loop_dest_greater_source_begin",Branch "memcopy_loop_source_greater_dest",Mark "memcopy_loop_source_greater_dest",Push (Literal 2),Load Nothing,Push (Literal 1),Load Nothing,Load Nothing,Store Nothing,Push (Literal 2),Push (Literal 2),Load Nothing,Push (Literal 1),Add Nothing,Store Nothing,Push (Literal 1),Push (Literal 1),Load Nothing,Push (Literal 1),Add Nothing,Store Nothing,Push (Literal 3),Push (Literal 3),Load Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Load (Just (Literal 3)),BranchZ "memcopy_end",Branch "memcopy_loop_source_greater_dest",Mark "memcopy_loop_dest_greater_source_begin",Push (Literal 2),Push (Literal 2),Load Nothing,Push (Literal 3),Load Nothing,Add Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Push (Literal 1),Push (Literal 1),Load Nothing,Push (Literal 3),Load Nothing,Add Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Mark "memcopy_loop_dest_greater_source",Push (Literal 2),Load Nothing,Push (Literal 1),Load Nothing,Load Nothing,Store Nothing,Push (Literal 2),Push (Literal 2),Load Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Push (Literal 1),Push (Literal 1),Load Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Push (Literal 3),Push (Literal 3),Load Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Load (Just (Literal 3)),BranchZ "memcopy_end",Branch "memcopy_loop_dest_greater_source",Mark "memcopy_end",Return,Mark "mem_zero",Mark "mem_zero_start",Dup,BranchZ "mem_zero_end",Swap,Dup,Push (Literal 0),Store Nothing,Push (Literal 1),Add Nothing,Swap,Push (Literal 1),Sub Nothing,Branch "mem_zero_start",Mark "mem_zero_end",Pop,Pop,Return,Mark "numeriere",Push (Literal 2),Swap,Store Nothing,Push (Literal 1),Swap,Store Nothing,Push (Literal 1),Load Nothing,Mark "numeriere_start",Dup,Dup,Store Nothing,Push (Literal 1),Add Nothing,Dup,Push (Literal 2),Load Nothing,Sub Nothing,BranchZ "numeriere_end",Branch "numeriere_start",Mark "numeriere_end",Pop,Return] \ No newline at end of file +[ Mark "memcopy" +, Mark "mem_copy" +, Mark "mem_move" +, Push + ( Literal 3 ) +, Swap +, Store Nothing +, Push + ( Literal 2 ) +, Swap +, Store Nothing +, Push + ( Literal 1 ) +, Swap +, Store Nothing +, Load + ( Just + ( Literal 3 ) + ) +, BranchNP "memcopy_end" +, Load + ( Just + ( Literal 1 ) + ) +, Load + ( Just + ( Literal 2 ) + ) +, Sub Nothing +, BranchZ "memcopy_end" +, Load + ( Just + ( Literal 1 ) + ) +, Load + ( Just + ( Literal 2 ) + ) +, Sub Nothing +, BranchM "memcopy_loop_dest_greater_source_begin" +, Branch "memcopy_loop_source_greater_dest" +, Mark "memcopy_loop_source_greater_dest" +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 1 ) +, Load Nothing +, Load Nothing +, Store Nothing +, Push + ( Literal 2 ) +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 1 ) +, Add Nothing +, Store Nothing +, Push + ( Literal 1 ) +, Push + ( Literal 1 ) +, Load Nothing +, Push + ( Literal 1 ) +, Add Nothing +, Store Nothing +, Push + ( Literal 3 ) +, Push + ( Literal 3 ) +, Load Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Load + ( Just + ( Literal 3 ) + ) +, BranchZ "memcopy_end" +, Branch "memcopy_loop_source_greater_dest" +, Mark "memcopy_loop_dest_greater_source_begin" +, Push + ( Literal 2 ) +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 3 ) +, Load Nothing +, Add Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Push + ( Literal 1 ) +, Push + ( Literal 1 ) +, Load Nothing +, Push + ( Literal 3 ) +, Load Nothing +, Add Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Mark "memcopy_loop_dest_greater_source" +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 1 ) +, Load Nothing +, Load Nothing +, Store Nothing +, Push + ( Literal 2 ) +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Push + ( Literal 1 ) +, Push + ( Literal 1 ) +, Load Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Push + ( Literal 3 ) +, Push + ( Literal 3 ) +, Load Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Load + ( Just + ( Literal 3 ) + ) +, BranchZ "memcopy_end" +, Branch "memcopy_loop_dest_greater_source" +, Mark "memcopy_end" +, Return +, Mark "mem_zero" +, Mark "mem_zero_start" +, Dup +, BranchZ "mem_zero_end" +, Swap +, Dup +, Push + ( Literal 0 ) +, Store Nothing +, Push + ( Literal 1 ) +, Add Nothing +, Swap +, Push + ( Literal 1 ) +, Sub Nothing +, Branch "mem_zero_start" +, Mark "mem_zero_end" +, Pop +, Pop +, Return +, Mark "numeriere" +, Push + ( Literal 2 ) +, Swap +, Store Nothing +, Push + ( Literal 1 ) +, Swap +, Store Nothing +, Push + ( Literal 1 ) +, Load Nothing +, Mark "numeriere_start" +, Dup +, Dup +, Store Nothing +, Push + ( Literal 1 ) +, Add Nothing +, Dup +, Push + ( Literal 2 ) +, Load Nothing +, Sub Nothing +, BranchZ "numeriere_end" +, Branch "numeriere_start" +, Mark "numeriere_end" +, Pop +, Return +] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/linkAppFile/from-eas/bottles.il b/.output/golden/examples/wsa/il/linkAppFile/from-eas/bottles.il index dfb92646..5ae5c8f1 100644 --- a/.output/golden/examples/wsa/il/linkAppFile/from-eas/bottles.il +++ b/.output/golden/examples/wsa/il/linkAppFile/from-eas/bottles.il @@ -1 +1,45 @@ -[Push (Literal 3),Mark "LOOP",Dup,OutputNum,PushS (Literal " bottles of beer on the wall, "),Call "prints",Dup,OutputNum,PushS (Literal " bottles of beer"),Call "printsln",PushS (Literal "Take one down, pass it around"),Call "printsln",Push (Literal 1),Sub Nothing,Dup,OutputNum,PushS (Literal " bottles of beer on the wall"),Call "printsln",PushS (Literal ""),Call "printsln",Dup,BranchNZ "LOOP",End,Mark "prints",Dup,BranchZ "prints_end",OutputChar,Branch "prints",Mark "prints_end",Pop,Return,Mark "printsln",Call "prints",Push (Literal 10),OutputChar,Return] \ No newline at end of file +[ Push + ( Literal 3 ) +, Mark "LOOP" +, Dup +, OutputNum +, PushS + ( Literal " bottles of beer on the wall, " ) +, Call "prints" +, Dup +, OutputNum +, PushS + ( Literal " bottles of beer" ) +, Call "printsln" +, PushS + ( Literal "Take one down, pass it around" ) +, Call "printsln" +, Push + ( Literal 1 ) +, Sub Nothing +, Dup +, OutputNum +, PushS + ( Literal " bottles of beer on the wall" ) +, Call "printsln" +, PushS + ( Literal "" ) +, Call "printsln" +, Dup +, BranchNZ "LOOP" +, End +, Mark "prints" +, Dup +, BranchZ "prints_end" +, OutputChar +, Branch "prints" +, Mark "prints_end" +, Pop +, Return +, Mark "printsln" +, Call "prints" +, Push + ( Literal 10 ) +, OutputChar +, Return +] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/linkAppFile/from-eas/hello.il b/.output/golden/examples/wsa/il/linkAppFile/from-eas/hello.il index 7a907ca8..04717598 100644 --- a/.output/golden/examples/wsa/il/linkAppFile/from-eas/hello.il +++ b/.output/golden/examples/wsa/il/linkAppFile/from-eas/hello.il @@ -1 +1,44 @@ -[Push (Literal 32),Push (Literal 44),Push (Literal 111),Push (Literal 108),Push (Literal 108),Push (Literal 101),Push (Literal 72),OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,Push (Literal 10),Push (Literal 33),Push (Literal 100),Push (Literal 108),Push (Literal 114),Push (Literal 111),Push (Literal 119),OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,End] \ No newline at end of file +[ Push + ( Literal 32 ) +, Push + ( Literal 44 ) +, Push + ( Literal 111 ) +, Push + ( Literal 108 ) +, Push + ( Literal 108 ) +, Push + ( Literal 101 ) +, Push + ( Literal 72 ) +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, Push + ( Literal 10 ) +, Push + ( Literal 33 ) +, Push + ( Literal 100 ) +, Push + ( Literal 108 ) +, Push + ( Literal 114 ) +, Push + ( Literal 111 ) +, Push + ( Literal 119 ) +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, End +] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/linkAppFile/from-eas/hello2.il b/.output/golden/examples/wsa/il/linkAppFile/from-eas/hello2.il index d82da1bb..e353881e 100644 --- a/.output/golden/examples/wsa/il/linkAppFile/from-eas/hello2.il +++ b/.output/golden/examples/wsa/il/linkAppFile/from-eas/hello2.il @@ -1 +1,47 @@ -[Push (Literal 0),Push (Literal 10),Push (Literal 33),Push (Literal 100),Push (Literal 108),Push (Literal 114),Push (Literal 111),Push (Literal 119),Push (Literal 32),Push (Literal 44),Push (Literal 111),Push (Literal 108),Push (Literal 108),Push (Literal 101),Push (Literal 72),Call "prints",End,Mark "prints",Dup,BranchZ "prints_end",OutputChar,Branch "prints",Mark "prints_end",Pop,Return,Mark "printsln",Call "prints",Push (Literal 10),OutputChar,Return] \ No newline at end of file +[ Push + ( Literal 0 ) +, Push + ( Literal 10 ) +, Push + ( Literal 33 ) +, Push + ( Literal 100 ) +, Push + ( Literal 108 ) +, Push + ( Literal 114 ) +, Push + ( Literal 111 ) +, Push + ( Literal 119 ) +, Push + ( Literal 32 ) +, Push + ( Literal 44 ) +, Push + ( Literal 111 ) +, Push + ( Literal 108 ) +, Push + ( Literal 108 ) +, Push + ( Literal 101 ) +, Push + ( Literal 72 ) +, Call "prints" +, End +, Mark "prints" +, Dup +, BranchZ "prints_end" +, OutputChar +, Branch "prints" +, Mark "prints_end" +, Pop +, Return +, Mark "printsln" +, Call "prints" +, Push + ( Literal 10 ) +, OutputChar +, Return +] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/linkAppFile/from-eas/hello4.il b/.output/golden/examples/wsa/il/linkAppFile/from-eas/hello4.il index 46e34b94..6545f652 100644 --- a/.output/golden/examples/wsa/il/linkAppFile/from-eas/hello4.il +++ b/.output/golden/examples/wsa/il/linkAppFile/from-eas/hello4.il @@ -1 +1,19 @@ -[PushS (Literal "Hello, world!"),Call "printsln",End,Mark "prints",Dup,BranchZ "prints_end",OutputChar,Branch "prints",Mark "prints_end",Pop,Return,Mark "printsln",Call "prints",Push (Literal 10),OutputChar,Return] \ No newline at end of file +[ PushS + ( Literal "Hello, world!" ) +, Call "printsln" +, End +, Mark "prints" +, Dup +, BranchZ "prints_end" +, OutputChar +, Branch "prints" +, Mark "prints_end" +, Pop +, Return +, Mark "printsln" +, Call "prints" +, Push + ( Literal 10 ) +, OutputChar +, Return +] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/linkAppFile/from-eas/pip.il b/.output/golden/examples/wsa/il/linkAppFile/from-eas/pip.il index de1a133f..829f55f1 100644 --- a/.output/golden/examples/wsa/il/linkAppFile/from-eas/pip.il +++ b/.output/golden/examples/wsa/il/linkAppFile/from-eas/pip.il @@ -1 +1,14 @@ -[Mark "LOOP",Dup,Push (Literal 0),Push (Literal 1),Sub Nothing,Sub Nothing,BranchNZ "WRITE",End,Mark "WRITE",OutputChar,Branch "LOOP"] \ No newline at end of file +[ Mark "LOOP" +, Dup +, Push + ( Literal 0 ) +, Push + ( Literal 1 ) +, Sub Nothing +, Sub Nothing +, BranchNZ "WRITE" +, End +, Mark "WRITE" +, OutputChar +, Branch "LOOP" +] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/linkAppFile/from-eas/true.il b/.output/golden/examples/wsa/il/linkAppFile/from-eas/true.il index f93ec408..7f93ef7d 100644 --- a/.output/golden/examples/wsa/il/linkAppFile/from-eas/true.il +++ b/.output/golden/examples/wsa/il/linkAppFile/from-eas/true.il @@ -1 +1 @@ -[End] \ No newline at end of file +[ End ] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/linkAppFile/original/prim.il b/.output/golden/examples/wsa/il/linkAppFile/original/prim.il index 270eecdf..6ff9a1fc 100644 --- a/.output/golden/examples/wsa/il/linkAppFile/original/prim.il +++ b/.output/golden/examples/wsa/il/linkAppFile/original/prim.il @@ -1 +1,120 @@ -[Mark "st",PushS (Literal "prim numbers [2-100]"),Call "printsln",Push (Literal 0),Mark "f_start_1",Test 100,BranchZ "f_finished_1",Dup,Add (Just (Literal 100)),Push (Literal 1),Store Nothing,Add (Just (Literal 1)),Branch "f_start_1",Mark "f_finished_1",Pop,Push (Literal 2),Mark "f_start_2",Test 11,BranchZ "f_finished_2",Push (Literal 2),Mark "f_start_3",Test 100,BranchZ "f_finished_3",Dup,Push (Literal 1),Swap,Store Nothing,Swap,Dup,Push (Literal 2),Swap,Store Nothing,Swap,Load (Just (Literal 1)),Load (Just (Literal 2)),Mul Nothing,Add (Just (Literal 100)),Push (Literal 0),Store Nothing,Add (Just (Literal 1)),Branch "f_start_3",Mark "f_finished_3",Pop,Add (Just (Literal 1)),Branch "f_start_2",Mark "f_finished_2",Pop,Push (Literal 2),Mark "f_start_4",Test 100,BranchZ "f_finished_4",Dup,Add (Just (Literal 100)),Load Nothing,BranchZ "nodraw",Dup,OutputNum,PushS (Literal " "),Call "prints",Mark "nodraw",Add (Just (Literal 1)),Branch "f_start_4",Mark "f_finished_4",Pop,Push (Literal 0),Call "printsln",End,Mark "prints",Dup,BranchZ "prints_end",OutputChar,Branch "prints",Mark "prints_end",Pop,Return,Mark "printsln",Call "prints",Push (Literal 10),OutputChar,Return] \ No newline at end of file +[ Mark "st" +, PushS + ( Literal "prim numbers [2-100]" ) +, Call "printsln" +, Push + ( Literal 0 ) +, Mark "f_start_1" +, Test 100 +, BranchZ "f_finished_1" +, Dup +, Add + ( Just + ( Literal 100 ) + ) +, Push + ( Literal 1 ) +, Store Nothing +, Add + ( Just + ( Literal 1 ) + ) +, Branch "f_start_1" +, Mark "f_finished_1" +, Pop +, Push + ( Literal 2 ) +, Mark "f_start_2" +, Test 11 +, BranchZ "f_finished_2" +, Push + ( Literal 2 ) +, Mark "f_start_3" +, Test 100 +, BranchZ "f_finished_3" +, Dup +, Push + ( Literal 1 ) +, Swap +, Store Nothing +, Swap +, Dup +, Push + ( Literal 2 ) +, Swap +, Store Nothing +, Swap +, Load + ( Just + ( Literal 1 ) + ) +, Load + ( Just + ( Literal 2 ) + ) +, Mul Nothing +, Add + ( Just + ( Literal 100 ) + ) +, Push + ( Literal 0 ) +, Store Nothing +, Add + ( Just + ( Literal 1 ) + ) +, Branch "f_start_3" +, Mark "f_finished_3" +, Pop +, Add + ( Just + ( Literal 1 ) + ) +, Branch "f_start_2" +, Mark "f_finished_2" +, Pop +, Push + ( Literal 2 ) +, Mark "f_start_4" +, Test 100 +, BranchZ "f_finished_4" +, Dup +, Add + ( Just + ( Literal 100 ) + ) +, Load Nothing +, BranchZ "nodraw" +, Dup +, OutputNum +, PushS + ( Literal " " ) +, Call "prints" +, Mark "nodraw" +, Add + ( Just + ( Literal 1 ) + ) +, Branch "f_start_4" +, Mark "f_finished_4" +, Pop +, Push + ( Literal 0 ) +, Call "printsln" +, End +, Mark "prints" +, Dup +, BranchZ "prints_end" +, OutputChar +, Branch "prints" +, Mark "prints_end" +, Pop +, Return +, Mark "printsln" +, Call "prints" +, Push + ( Literal 10 ) +, OutputChar +, Return +] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/linkLibFile/io.il b/.output/golden/examples/wsa/il/linkLibFile/io.il index d0e7bba1..a4542d9e 100644 --- a/.output/golden/examples/wsa/il/linkLibFile/io.il +++ b/.output/golden/examples/wsa/il/linkLibFile/io.il @@ -1 +1,15 @@ -[Mark "prints",Dup,BranchZ "prints_end",OutputChar,Branch "prints",Mark "prints_end",Pop,Return,Mark "printsln",Call "prints",Push (Literal 10),OutputChar,Return] \ No newline at end of file +[ Mark "prints" +, Dup +, BranchZ "prints_end" +, OutputChar +, Branch "prints" +, Mark "prints_end" +, Pop +, Return +, Mark "printsln" +, Call "prints" +, Push + ( Literal 10 ) +, OutputChar +, Return +] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/linkLibFile/memory.il b/.output/golden/examples/wsa/il/linkLibFile/memory.il index 74ede482..ebc82bf6 100644 --- a/.output/golden/examples/wsa/il/linkLibFile/memory.il +++ b/.output/golden/examples/wsa/il/linkLibFile/memory.il @@ -1 +1,205 @@ -[Mark "memcopy",Mark "mem_copy",Mark "mem_move",Push (Literal 3),Swap,Store Nothing,Push (Literal 2),Swap,Store Nothing,Push (Literal 1),Swap,Store Nothing,Load (Just (Literal 3)),BranchNP "memcopy_end",Load (Just (Literal 1)),Load (Just (Literal 2)),Sub Nothing,BranchZ "memcopy_end",Load (Just (Literal 1)),Load (Just (Literal 2)),Sub Nothing,BranchM "memcopy_loop_dest_greater_source_begin",Branch "memcopy_loop_source_greater_dest",Mark "memcopy_loop_source_greater_dest",Push (Literal 2),Load Nothing,Push (Literal 1),Load Nothing,Load Nothing,Store Nothing,Push (Literal 2),Push (Literal 2),Load Nothing,Push (Literal 1),Add Nothing,Store Nothing,Push (Literal 1),Push (Literal 1),Load Nothing,Push (Literal 1),Add Nothing,Store Nothing,Push (Literal 3),Push (Literal 3),Load Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Load (Just (Literal 3)),BranchZ "memcopy_end",Branch "memcopy_loop_source_greater_dest",Mark "memcopy_loop_dest_greater_source_begin",Push (Literal 2),Push (Literal 2),Load Nothing,Push (Literal 3),Load Nothing,Add Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Push (Literal 1),Push (Literal 1),Load Nothing,Push (Literal 3),Load Nothing,Add Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Mark "memcopy_loop_dest_greater_source",Push (Literal 2),Load Nothing,Push (Literal 1),Load Nothing,Load Nothing,Store Nothing,Push (Literal 2),Push (Literal 2),Load Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Push (Literal 1),Push (Literal 1),Load Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Push (Literal 3),Push (Literal 3),Load Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Load (Just (Literal 3)),BranchZ "memcopy_end",Branch "memcopy_loop_dest_greater_source",Mark "memcopy_end",Return,Mark "mem_zero",Mark "mem_zero_start",Dup,BranchZ "mem_zero_end",Swap,Dup,Push (Literal 0),Store Nothing,Push (Literal 1),Add Nothing,Swap,Push (Literal 1),Sub Nothing,Branch "mem_zero_start",Mark "mem_zero_end",Pop,Pop,Return,Mark "numeriere",Push (Literal 2),Swap,Store Nothing,Push (Literal 1),Swap,Store Nothing,Push (Literal 1),Load Nothing,Mark "numeriere_start",Dup,Dup,Store Nothing,Push (Literal 1),Add Nothing,Dup,Push (Literal 2),Load Nothing,Sub Nothing,BranchZ "numeriere_end",Branch "numeriere_start",Mark "numeriere_end",Pop,Return] \ No newline at end of file +[ Mark "memcopy" +, Mark "mem_copy" +, Mark "mem_move" +, Push + ( Literal 3 ) +, Swap +, Store Nothing +, Push + ( Literal 2 ) +, Swap +, Store Nothing +, Push + ( Literal 1 ) +, Swap +, Store Nothing +, Load + ( Just + ( Literal 3 ) + ) +, BranchNP "memcopy_end" +, Load + ( Just + ( Literal 1 ) + ) +, Load + ( Just + ( Literal 2 ) + ) +, Sub Nothing +, BranchZ "memcopy_end" +, Load + ( Just + ( Literal 1 ) + ) +, Load + ( Just + ( Literal 2 ) + ) +, Sub Nothing +, BranchM "memcopy_loop_dest_greater_source_begin" +, Branch "memcopy_loop_source_greater_dest" +, Mark "memcopy_loop_source_greater_dest" +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 1 ) +, Load Nothing +, Load Nothing +, Store Nothing +, Push + ( Literal 2 ) +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 1 ) +, Add Nothing +, Store Nothing +, Push + ( Literal 1 ) +, Push + ( Literal 1 ) +, Load Nothing +, Push + ( Literal 1 ) +, Add Nothing +, Store Nothing +, Push + ( Literal 3 ) +, Push + ( Literal 3 ) +, Load Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Load + ( Just + ( Literal 3 ) + ) +, BranchZ "memcopy_end" +, Branch "memcopy_loop_source_greater_dest" +, Mark "memcopy_loop_dest_greater_source_begin" +, Push + ( Literal 2 ) +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 3 ) +, Load Nothing +, Add Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Push + ( Literal 1 ) +, Push + ( Literal 1 ) +, Load Nothing +, Push + ( Literal 3 ) +, Load Nothing +, Add Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Mark "memcopy_loop_dest_greater_source" +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 1 ) +, Load Nothing +, Load Nothing +, Store Nothing +, Push + ( Literal 2 ) +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Push + ( Literal 1 ) +, Push + ( Literal 1 ) +, Load Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Push + ( Literal 3 ) +, Push + ( Literal 3 ) +, Load Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Load + ( Just + ( Literal 3 ) + ) +, BranchZ "memcopy_end" +, Branch "memcopy_loop_dest_greater_source" +, Mark "memcopy_end" +, Return +, Mark "mem_zero" +, Mark "mem_zero_start" +, Dup +, BranchZ "mem_zero_end" +, Swap +, Dup +, Push + ( Literal 0 ) +, Store Nothing +, Push + ( Literal 1 ) +, Add Nothing +, Swap +, Push + ( Literal 1 ) +, Sub Nothing +, Branch "mem_zero_start" +, Mark "mem_zero_end" +, Pop +, Pop +, Return +, Mark "numeriere" +, Push + ( Literal 2 ) +, Swap +, Store Nothing +, Push + ( Literal 1 ) +, Swap +, Store Nothing +, Push + ( Literal 1 ) +, Load Nothing +, Mark "numeriere_start" +, Dup +, Dup +, Store Nothing +, Push + ( Literal 1 ) +, Add Nothing +, Dup +, Push + ( Literal 2 ) +, Load Nothing +, Sub Nothing +, BranchZ "numeriere_end" +, Branch "numeriere_start" +, Mark "numeriere_end" +, Pop +, Return +] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/bottles.il b/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/bottles.il index c254e8f4..c8a36072 100644 --- a/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/bottles.il +++ b/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/bottles.il @@ -1 +1,32 @@ -[Include "io",Push (Literal 3),Mark "LOOP",Dup,OutputNum,PushS (Literal " bottles of beer on the wall, "),Call "prints",Dup,OutputNum,PushS (Literal " bottles of beer"),Call "printsln",PushS (Literal "Take one down, pass it around"),Call "printsln",Push (Literal 1),Sub Nothing,Dup,OutputNum,PushS (Literal " bottles of beer on the wall"),Call "printsln",PushS (Literal ""),Call "printsln",Dup,BranchNZ "LOOP",End] \ No newline at end of file +[ Include "io" +, Push + ( Literal 3 ) +, Mark "LOOP" +, Dup +, OutputNum +, PushS + ( Literal " bottles of beer on the wall, " ) +, Call "prints" +, Dup +, OutputNum +, PushS + ( Literal " bottles of beer" ) +, Call "printsln" +, PushS + ( Literal "Take one down, pass it around" ) +, Call "printsln" +, Push + ( Literal 1 ) +, Sub Nothing +, Dup +, OutputNum +, PushS + ( Literal " bottles of beer on the wall" ) +, Call "printsln" +, PushS + ( Literal "" ) +, Call "printsln" +, Dup +, BranchNZ "LOOP" +, End +] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/hello.il b/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/hello.il index 7a907ca8..04717598 100644 --- a/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/hello.il +++ b/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/hello.il @@ -1 +1,44 @@ -[Push (Literal 32),Push (Literal 44),Push (Literal 111),Push (Literal 108),Push (Literal 108),Push (Literal 101),Push (Literal 72),OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,Push (Literal 10),Push (Literal 33),Push (Literal 100),Push (Literal 108),Push (Literal 114),Push (Literal 111),Push (Literal 119),OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,OutputChar,End] \ No newline at end of file +[ Push + ( Literal 32 ) +, Push + ( Literal 44 ) +, Push + ( Literal 111 ) +, Push + ( Literal 108 ) +, Push + ( Literal 108 ) +, Push + ( Literal 101 ) +, Push + ( Literal 72 ) +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, Push + ( Literal 10 ) +, Push + ( Literal 33 ) +, Push + ( Literal 100 ) +, Push + ( Literal 108 ) +, Push + ( Literal 114 ) +, Push + ( Literal 111 ) +, Push + ( Literal 119 ) +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, OutputChar +, End +] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/hello2.il b/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/hello2.il index 00e91327..1cd343c3 100644 --- a/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/hello2.il +++ b/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/hello2.il @@ -1 +1,34 @@ -[Include "io",Push (Literal 0),Push (Literal 10),Push (Literal 33),Push (Literal 100),Push (Literal 108),Push (Literal 114),Push (Literal 111),Push (Literal 119),Push (Literal 32),Push (Literal 44),Push (Literal 111),Push (Literal 108),Push (Literal 108),Push (Literal 101),Push (Literal 72),Call "prints",End] \ No newline at end of file +[ Include "io" +, Push + ( Literal 0 ) +, Push + ( Literal 10 ) +, Push + ( Literal 33 ) +, Push + ( Literal 100 ) +, Push + ( Literal 108 ) +, Push + ( Literal 114 ) +, Push + ( Literal 111 ) +, Push + ( Literal 119 ) +, Push + ( Literal 32 ) +, Push + ( Literal 44 ) +, Push + ( Literal 111 ) +, Push + ( Literal 108 ) +, Push + ( Literal 108 ) +, Push + ( Literal 101 ) +, Push + ( Literal 72 ) +, Call "prints" +, End +] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/hello4.il b/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/hello4.il index a1afdd2e..81db1569 100644 --- a/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/hello4.il +++ b/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/hello4.il @@ -1 +1,6 @@ -[Include "io",PushS (Literal "Hello, world!"),Call "printsln",End] \ No newline at end of file +[ Include "io" +, PushS + ( Literal "Hello, world!" ) +, Call "printsln" +, End +] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/pip.il b/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/pip.il index de1a133f..829f55f1 100644 --- a/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/pip.il +++ b/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/pip.il @@ -1 +1,14 @@ -[Mark "LOOP",Dup,Push (Literal 0),Push (Literal 1),Sub Nothing,Sub Nothing,BranchNZ "WRITE",End,Mark "WRITE",OutputChar,Branch "LOOP"] \ No newline at end of file +[ Mark "LOOP" +, Dup +, Push + ( Literal 0 ) +, Push + ( Literal 1 ) +, Sub Nothing +, Sub Nothing +, BranchNZ "WRITE" +, End +, Mark "WRITE" +, OutputChar +, Branch "LOOP" +] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/true.il b/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/true.il index f93ec408..7f93ef7d 100644 --- a/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/true.il +++ b/.output/golden/examples/wsa/il/parseAssemblyApp/from-eas/true.il @@ -1 +1 @@ -[End] \ No newline at end of file +[ End ] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/parseAssemblyApp/original/prim.il b/.output/golden/examples/wsa/il/parseAssemblyApp/original/prim.il index 06495869..2a8c9ace 100644 --- a/.output/golden/examples/wsa/il/parseAssemblyApp/original/prim.il +++ b/.output/golden/examples/wsa/il/parseAssemblyApp/original/prim.il @@ -1 +1,107 @@ -[Include "io",Mark "st",PushS (Literal "prim numbers [2-100]"),Call "printsln",Push (Literal 0),Mark "f_start_1",Test 100,BranchZ "f_finished_1",Dup,Add (Just (Literal 100)),Push (Literal 1),Store Nothing,Add (Just (Literal 1)),Branch "f_start_1",Mark "f_finished_1",Pop,Push (Literal 2),Mark "f_start_2",Test 11,BranchZ "f_finished_2",Push (Literal 2),Mark "f_start_3",Test 100,BranchZ "f_finished_3",Dup,Push (Literal 1),Swap,Store Nothing,Swap,Dup,Push (Literal 2),Swap,Store Nothing,Swap,Load (Just (Literal 1)),Load (Just (Literal 2)),Mul Nothing,Add (Just (Literal 100)),Push (Literal 0),Store Nothing,Add (Just (Literal 1)),Branch "f_start_3",Mark "f_finished_3",Pop,Add (Just (Literal 1)),Branch "f_start_2",Mark "f_finished_2",Pop,Push (Literal 2),Mark "f_start_4",Test 100,BranchZ "f_finished_4",Dup,Add (Just (Literal 100)),Load Nothing,BranchZ "nodraw",Dup,OutputNum,PushS (Literal " "),Call "prints",Mark "nodraw",Add (Just (Literal 1)),Branch "f_start_4",Mark "f_finished_4",Pop,Push (Literal 0),Call "printsln",End] \ No newline at end of file +[ Include "io" +, Mark "st" +, PushS + ( Literal "prim numbers [2-100]" ) +, Call "printsln" +, Push + ( Literal 0 ) +, Mark "f_start_1" +, Test 100 +, BranchZ "f_finished_1" +, Dup +, Add + ( Just + ( Literal 100 ) + ) +, Push + ( Literal 1 ) +, Store Nothing +, Add + ( Just + ( Literal 1 ) + ) +, Branch "f_start_1" +, Mark "f_finished_1" +, Pop +, Push + ( Literal 2 ) +, Mark "f_start_2" +, Test 11 +, BranchZ "f_finished_2" +, Push + ( Literal 2 ) +, Mark "f_start_3" +, Test 100 +, BranchZ "f_finished_3" +, Dup +, Push + ( Literal 1 ) +, Swap +, Store Nothing +, Swap +, Dup +, Push + ( Literal 2 ) +, Swap +, Store Nothing +, Swap +, Load + ( Just + ( Literal 1 ) + ) +, Load + ( Just + ( Literal 2 ) + ) +, Mul Nothing +, Add + ( Just + ( Literal 100 ) + ) +, Push + ( Literal 0 ) +, Store Nothing +, Add + ( Just + ( Literal 1 ) + ) +, Branch "f_start_3" +, Mark "f_finished_3" +, Pop +, Add + ( Just + ( Literal 1 ) + ) +, Branch "f_start_2" +, Mark "f_finished_2" +, Pop +, Push + ( Literal 2 ) +, Mark "f_start_4" +, Test 100 +, BranchZ "f_finished_4" +, Dup +, Add + ( Just + ( Literal 100 ) + ) +, Load Nothing +, BranchZ "nodraw" +, Dup +, OutputNum +, PushS + ( Literal " " ) +, Call "prints" +, Mark "nodraw" +, Add + ( Just + ( Literal 1 ) + ) +, Branch "f_start_4" +, Mark "f_finished_4" +, Pop +, Push + ( Literal 0 ) +, Call "printsln" +, End +] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/parseAssemblyLib/io.il b/.output/golden/examples/wsa/il/parseAssemblyLib/io.il index d0e7bba1..a4542d9e 100644 --- a/.output/golden/examples/wsa/il/parseAssemblyLib/io.il +++ b/.output/golden/examples/wsa/il/parseAssemblyLib/io.il @@ -1 +1,15 @@ -[Mark "prints",Dup,BranchZ "prints_end",OutputChar,Branch "prints",Mark "prints_end",Pop,Return,Mark "printsln",Call "prints",Push (Literal 10),OutputChar,Return] \ No newline at end of file +[ Mark "prints" +, Dup +, BranchZ "prints_end" +, OutputChar +, Branch "prints" +, Mark "prints_end" +, Pop +, Return +, Mark "printsln" +, Call "prints" +, Push + ( Literal 10 ) +, OutputChar +, Return +] \ No newline at end of file diff --git a/.output/golden/examples/wsa/il/parseAssemblyLib/memory.il b/.output/golden/examples/wsa/il/parseAssemblyLib/memory.il index 74ede482..ebc82bf6 100644 --- a/.output/golden/examples/wsa/il/parseAssemblyLib/memory.il +++ b/.output/golden/examples/wsa/il/parseAssemblyLib/memory.il @@ -1 +1,205 @@ -[Mark "memcopy",Mark "mem_copy",Mark "mem_move",Push (Literal 3),Swap,Store Nothing,Push (Literal 2),Swap,Store Nothing,Push (Literal 1),Swap,Store Nothing,Load (Just (Literal 3)),BranchNP "memcopy_end",Load (Just (Literal 1)),Load (Just (Literal 2)),Sub Nothing,BranchZ "memcopy_end",Load (Just (Literal 1)),Load (Just (Literal 2)),Sub Nothing,BranchM "memcopy_loop_dest_greater_source_begin",Branch "memcopy_loop_source_greater_dest",Mark "memcopy_loop_source_greater_dest",Push (Literal 2),Load Nothing,Push (Literal 1),Load Nothing,Load Nothing,Store Nothing,Push (Literal 2),Push (Literal 2),Load Nothing,Push (Literal 1),Add Nothing,Store Nothing,Push (Literal 1),Push (Literal 1),Load Nothing,Push (Literal 1),Add Nothing,Store Nothing,Push (Literal 3),Push (Literal 3),Load Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Load (Just (Literal 3)),BranchZ "memcopy_end",Branch "memcopy_loop_source_greater_dest",Mark "memcopy_loop_dest_greater_source_begin",Push (Literal 2),Push (Literal 2),Load Nothing,Push (Literal 3),Load Nothing,Add Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Push (Literal 1),Push (Literal 1),Load Nothing,Push (Literal 3),Load Nothing,Add Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Mark "memcopy_loop_dest_greater_source",Push (Literal 2),Load Nothing,Push (Literal 1),Load Nothing,Load Nothing,Store Nothing,Push (Literal 2),Push (Literal 2),Load Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Push (Literal 1),Push (Literal 1),Load Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Push (Literal 3),Push (Literal 3),Load Nothing,Push (Literal 1),Sub Nothing,Store Nothing,Load (Just (Literal 3)),BranchZ "memcopy_end",Branch "memcopy_loop_dest_greater_source",Mark "memcopy_end",Return,Mark "mem_zero",Mark "mem_zero_start",Dup,BranchZ "mem_zero_end",Swap,Dup,Push (Literal 0),Store Nothing,Push (Literal 1),Add Nothing,Swap,Push (Literal 1),Sub Nothing,Branch "mem_zero_start",Mark "mem_zero_end",Pop,Pop,Return,Mark "numeriere",Push (Literal 2),Swap,Store Nothing,Push (Literal 1),Swap,Store Nothing,Push (Literal 1),Load Nothing,Mark "numeriere_start",Dup,Dup,Store Nothing,Push (Literal 1),Add Nothing,Dup,Push (Literal 2),Load Nothing,Sub Nothing,BranchZ "numeriere_end",Branch "numeriere_start",Mark "numeriere_end",Pop,Return] \ No newline at end of file +[ Mark "memcopy" +, Mark "mem_copy" +, Mark "mem_move" +, Push + ( Literal 3 ) +, Swap +, Store Nothing +, Push + ( Literal 2 ) +, Swap +, Store Nothing +, Push + ( Literal 1 ) +, Swap +, Store Nothing +, Load + ( Just + ( Literal 3 ) + ) +, BranchNP "memcopy_end" +, Load + ( Just + ( Literal 1 ) + ) +, Load + ( Just + ( Literal 2 ) + ) +, Sub Nothing +, BranchZ "memcopy_end" +, Load + ( Just + ( Literal 1 ) + ) +, Load + ( Just + ( Literal 2 ) + ) +, Sub Nothing +, BranchM "memcopy_loop_dest_greater_source_begin" +, Branch "memcopy_loop_source_greater_dest" +, Mark "memcopy_loop_source_greater_dest" +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 1 ) +, Load Nothing +, Load Nothing +, Store Nothing +, Push + ( Literal 2 ) +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 1 ) +, Add Nothing +, Store Nothing +, Push + ( Literal 1 ) +, Push + ( Literal 1 ) +, Load Nothing +, Push + ( Literal 1 ) +, Add Nothing +, Store Nothing +, Push + ( Literal 3 ) +, Push + ( Literal 3 ) +, Load Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Load + ( Just + ( Literal 3 ) + ) +, BranchZ "memcopy_end" +, Branch "memcopy_loop_source_greater_dest" +, Mark "memcopy_loop_dest_greater_source_begin" +, Push + ( Literal 2 ) +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 3 ) +, Load Nothing +, Add Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Push + ( Literal 1 ) +, Push + ( Literal 1 ) +, Load Nothing +, Push + ( Literal 3 ) +, Load Nothing +, Add Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Mark "memcopy_loop_dest_greater_source" +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 1 ) +, Load Nothing +, Load Nothing +, Store Nothing +, Push + ( Literal 2 ) +, Push + ( Literal 2 ) +, Load Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Push + ( Literal 1 ) +, Push + ( Literal 1 ) +, Load Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Push + ( Literal 3 ) +, Push + ( Literal 3 ) +, Load Nothing +, Push + ( Literal 1 ) +, Sub Nothing +, Store Nothing +, Load + ( Just + ( Literal 3 ) + ) +, BranchZ "memcopy_end" +, Branch "memcopy_loop_dest_greater_source" +, Mark "memcopy_end" +, Return +, Mark "mem_zero" +, Mark "mem_zero_start" +, Dup +, BranchZ "mem_zero_end" +, Swap +, Dup +, Push + ( Literal 0 ) +, Store Nothing +, Push + ( Literal 1 ) +, Add Nothing +, Swap +, Push + ( Literal 1 ) +, Sub Nothing +, Branch "mem_zero_start" +, Mark "mem_zero_end" +, Pop +, Pop +, Return +, Mark "numeriere" +, Push + ( Literal 2 ) +, Swap +, Store Nothing +, Push + ( Literal 1 ) +, Swap +, Store Nothing +, Push + ( Literal 1 ) +, Load Nothing +, Mark "numeriere_start" +, Dup +, Dup +, Store Nothing +, Push + ( Literal 1 ) +, Add Nothing +, Dup +, Push + ( Literal 2 ) +, Load Nothing +, Sub Nothing +, BranchZ "numeriere_end" +, Branch "numeriere_start" +, Mark "numeriere_end" +, Pop +, Return +] \ No newline at end of file diff --git a/compile-streaming.sh b/compile-streaming.sh index 219f20a6..3074afc9 100755 --- a/compile-streaming.sh +++ b/compile-streaming.sh @@ -1,3 +1,12 @@ #!/usr/bin/env bash -cabal new-clean && cabal new-build && cabal new-test --test-show-details=streaming \ No newline at end of file +rm -rf cabal.project.local +rm -rf .hie + +cabal new-clean && +cabal new-build && +cabal configure --enable-tests --enable-coverage && +cabal new-test --test-show-details=streaming && +./stan.sh + +cp stan.html docs/reports diff --git a/compile.sh b/compile.sh index 4b6a20e2..f3bfc26d 100755 --- a/compile.sh +++ b/compile.sh @@ -1,3 +1,12 @@ #!/usr/bin/env bash -cabal new-clean && cabal new-build && cabal new-test +rm -rf cabal.project.local +rm -rf .hie + +cabal new-clean && +cabal new-build && +cabal configure --enable-tests --enable-coverage && +cabal new-test && +./stan.sh + +cp stan.html docs/reports diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 5e2929ba..9a2bba2a 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -1,3 +1,40 @@ # 📐 ARCHITECTURE -We do not have ARCHITECTURE +We have Spaghetti ARCHITECTURE inspired by Flying Spaghetti Monster + +Tools and libraries: +* For start: + * [x] [Summoner](https://kowainik.github.io/projects/summoner) for scaffolding fully configured batteries-included production-level Haskell projects + * [ ] [cake-slayer](https://github.com/kowainik/cake-slayer) - Architecture of Haskell backend applications + * [ ] [three-layer](https://github.com/Holmusk/three-layer) - Architecture of Haskell backend applications +* For static code analysis: + * [x] [hlint](https://github.com/ndmitchell/hlint) for source code suggestions + * [x] [stan](https://kowainik.github.io/projects/stan) for STatic ANalysis + * [ ] [weeder](https://github.com/ocharles/weeder) for detect dead code +* For dynamic code analysis: + * [x] [hspec](https://hspec.github.io/) for unit and integration tests + * [x] [hspec-expectations-pretty-diff](https://github.com/unrelentingtech/hspec-expectations-pretty-diff#readme) for catchy combinators for HUnit + * [x] [hspec-golden](https://github.com/stackbuilders/hspec-golden#readme) for golden tests + * [x] [hspec-slow](https://github.com/SupercedeTech/hspec-slow) for find slow test cases + * [ ] [gauge](https://github.com/vincenthz/hs-gauge) for performance measurement and analysis + * [ ] [weigh](https://github.com/fpco/weigh#readme) for measure allocations of a Haskell functions/values + * [ ] [hedgehog](https://hedgehog.qa/) for property tests +* For Configuration: + * [x] [optparse-applicative](https://github.com/pcapriotti/optparse-applicative) for parse options + * [ ] [tomland](https://kowainik.github.io/posts/2019-01-14-tomland) for configuration from file + * [ ] [dhall-haskell](https://github.com/dhall-lang/dhall-haskell) for configuration from file +* For patching List: + * [x] [ilist](https://hackage.haskell.org/package/ilist) for doing index-related things + * [x] [list-singleton](https://hackage.haskell.org/package/list-singleton) for easily and clearly create lists with only one element in them + * [ ] [slist](https://kowainik.github.io/projects/slist) for sized list + * [x] [split](https://hackage.haskell.org/package/split) for splitting lists +* For production code: + * [x] [mtl](https://github.com/haskell/mtl) for IoC + * [x] [relude](https://kowainik.github.io/projects/relude) as standard library + * [ ] [co-log](https://github.com/kowainik/co-log) for logging + * [ ] [mono-traversable](https://github.com/snoyberg/mono-traversable#readme) as container standard library + * [x] [data-default](https://hackage.haskell.org/package/data-default) for default values + * [ ] [validation-selective](https://github.com/kowainik/validation-selective) is lighweight pure data validation based on Applicative and Selective functors + * [x] [filepath](https://github.com/haskell/filepath#readme) for manipulating FilePaths in a cross platform way. + * [ ] [pretty-simple](https://github.com/cdepillabout/pretty-simple) for data types with a 'Show' instance + * [x] [attoparsec](https://github.com/bgamari/attoparsec) for parsing assembly languages diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 10158371..98c7d732 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,14 @@ # 📅 Revision history for Helpa +## 0.3.4.0 -- 2021-07-22 + +* Use MonadError +* Use Stan +* Use pretty-simple for golden tests +* Fill up ARCHITECTURE.md +* Replace WrapperIO by BusinessIO +* Remove gradle + ## 0.3.3.0 -- 2021-07-6 * Use `Safe`, remove `error` calls diff --git a/docs/reports/stan.html b/docs/reports/stan.html new file mode 100644 index 00000000..707f3580 --- /dev/null +++ b/docs/reports/stan.html @@ -0,0 +1,58 @@ + +Stan Report

Stan Report

This is the Haskell Static Analysis report generated by Stan

Stan Info

In this section, you can find the general information about the used Stan tool, compile-time and run-time environment variables and settings, including build information, system data and execution configurations.

Stan Version
Version0.0.1.0
Git RevisionUNKNOWN
Release DateUNKNOWN
System Info
Operating Systemlinux
Architecturex86_64
Compilerghc
Compiler Version8.10
Environment
Environment Variables
TOML configuration files
CLI arguments-s --hide-solution report

Project Info

Information about the analysed project

Project namehelpa
Cabal Fileshelpa.cabal
HIE Files Directory.hie
Files Number54

Analysis Info

Summary stats from the static analysis

Modules54
LoC2952
Extensions3
SafeHaskell Extensions0
Available inspections44
Checked inspections44
Found Observations14
Ignored Observations0

Static Analysis Summary

Here you can find the overall conclusion based on the various metadata and gathered information during the work of Stan on this project.

Observations

Based on the analysis results, Stan found different vulnerabilities distributed among the analysed files. In Stan terminology, we call such vulnerability as Observation. Below you can see the more detailed information about each observation, and find the possible ways to fix them for your project.

📄 hs/src/HelVM/Common/Containers/Reverse.hs

  • ModuleHelVM.Common.Containers.Reverse
    Lines of Code15
      1. Observations

        IDOBS-STAN-0101-NL6FaO-12:13
        SeverityPotentialBug
        DescriptionUsage of the 'reverse' function that hangs on infinite lists
        Inspection IDSTAN-0101
        Category
        • Infinite
        • List
        Filehs/src/HelVM/Common/Containers/Reverse.hs
          11 ┃ 
        +  12 ┃   reverse = List.reverse
        +  13 ┃             ^^^^^^^^^^^^
        +

        Possible solutions

        • Don't use 'reverse' if you expect your function to work with infinite lists
        • {Extra dependency} Use the 'slist' library for fast and safe functions on infinite lists

      📄 hs/src/HelVM/Common/Digit/ToDigit.hs

      • ModuleHelVM.Common.Digit.ToDigit
        Lines of Code29
          1. Observations

            IDOBS-STAN-0101-8byvAX-17:47
            SeverityPotentialBug
            DescriptionUsage of the 'reverse' function that hangs on infinite lists
            Inspection IDSTAN-0101
            Category
            • Infinite
            • List
            Filehs/src/HelVM/Common/Digit/ToDigit.hs
              16 ┃ 
            +  17 ┃ makeChar base xs = chr <$> makeIntegral base (reverse xs)
            +  18 ┃                                               ^^^^^^^
            +

            Possible solutions

            • Don't use 'reverse' if you expect your function to work with infinite lists
            • {Extra dependency} Use the 'slist' library for fast and safe functions on infinite lists

          📄 hs/src/HelVM/Common/Safe.hs

          • ModuleHelVM.Common.Safe
            Lines of Code144
              1. Observations

                IDOBS-STAN-0101-Fp7WQh-69:26
                SeverityPotentialBug
                DescriptionUsage of the 'reverse' function that hangs on infinite lists
                Inspection IDSTAN-0101
                Category
                • Infinite
                • List
                Filehs/src/HelVM/Common/Safe.hs
                  68 ┃ 
                +  69 ┃ errorsToText = unlines . reverse
                +  70 ┃                          ^^^^^^^
                +

                Possible solutions

                • Don't use 'reverse' if you expect your function to work with infinite lists
                • {Extra dependency} Use the 'slist' library for fast and safe functions on infinite lists

              📄 hs/src/HelVM/HelPA/Assemblers/EAS/Reducer.hs

              • ModuleHelVM.HelPA.Assemblers.EAS.Reducer
                Lines of Code59
                  1. TupleSections
                1. Observations

                  IDOBS-STAN-0101-iUgfuQ-50:45
                  SeverityPotentialBug
                  DescriptionUsage of the 'reverse' function that hangs on infinite lists
                  Inspection IDSTAN-0101
                  Category
                  • Infinite
                  • List
                  Filehs/src/HelVM/HelPA/Assemblers/EAS/Reducer.hs
                    49 ┃ 
                  +  50 ┃ replaceString (U s) = charToInstruction <$> reverse s
                  +  51 ┃                                             ^^^^^^^
                  +

                  Possible solutions

                  • Don't use 'reverse' if you expect your function to work with infinite lists
                  • {Extra dependency} Use the 'slist' library for fast and safe functions on infinite lists

                📄 hs/test/HelVM/CartesianProduct.hs

                • ModuleHelVM.CartesianProduct
                  Lines of Code33
                    1. Observations

                      IDOBS-STAN-0302-J+yUBQ-16:41
                      SeverityStyle
                      DescriptionUsing tuples of big size (>= 4) can decrease code readability
                      Inspection IDSTAN-0302
                      Category
                      • AntiPattern
                      • Syntax
                      Filehs/test/HelVM/CartesianProduct.hs
                        15 ┃ 
                      +  16 ┃ (|><<<) :: [a1] -> [(b1 , b2 , b3)] -> [(a1 , b1 , b2 , b3)]
                      +  17 ┃                                         ^^^^^^^^^^^^^^^^^^^
                      +

                      Possible solutions

                      • Consider defining and using a custom data type to improve code comprehension
                      IDOBS-STAN-0302-J+yUBQ-17:41
                      SeverityStyle
                      DescriptionUsing tuples of big size (>= 4) can decrease code readability
                      Inspection IDSTAN-0302
                      Category
                      • AntiPattern
                      • Syntax
                      Filehs/test/HelVM/CartesianProduct.hs
                        16 ┃ 
                      +  17 ┃ (|><<<) = liftA2 (\a1 (b1 , b2 , b3) -> (a1 , b1 , b2 , b3))
                      +  18 ┃                                         ^^^^^^^^^^^^^^^^^^^
                      +

                      Possible solutions

                      • Consider defining and using a custom data type to improve code comprehension
                      IDOBS-STAN-0302-J+yUBQ-20:42
                      SeverityStyle
                      DescriptionUsing tuples of big size (>= 4) can decrease code readability
                      Inspection IDSTAN-0302
                      Category
                      • AntiPattern
                      • Syntax
                      Filehs/test/HelVM/CartesianProduct.hs
                        19 ┃ 
                      +  20 ┃ (>><<) :: [(a1 , a2)] -> [(b1 , b2)] -> [(a1 , a2 , b1 , b2)]
                      +  21 ┃                                          ^^^^^^^^^^^^^^^^^^^
                      +

                      Possible solutions

                      • Consider defining and using a custom data type to improve code comprehension
                      IDOBS-STAN-0302-J+yUBQ-21:42
                      SeverityStyle
                      DescriptionUsing tuples of big size (>= 4) can decrease code readability
                      Inspection IDSTAN-0302
                      Category
                      • AntiPattern
                      • Syntax
                      Filehs/test/HelVM/CartesianProduct.hs
                        20 ┃ 
                      +  21 ┃ (>><<) = liftA2 (\(a1 , a2) (b1 , b2) -> (a1 , a2 , b1 , b2))
                      +  22 ┃                                          ^^^^^^^^^^^^^^^^^^^
                      +

                      Possible solutions

                      • Consider defining and using a custom data type to improve code comprehension
                      IDOBS-STAN-0302-J+yUBQ-24:48
                      SeverityStyle
                      DescriptionUsing tuples of big size (>= 4) can decrease code readability
                      Inspection IDSTAN-0302
                      Category
                      • AntiPattern
                      • Syntax
                      Filehs/test/HelVM/CartesianProduct.hs
                        23 ┃ 
                      +  24 ┃ (>>><<) :: [(a1 , a2 , a3)] -> [(b1 , b2)] -> [(a1 , a2 , a3 , b1 , b2)]
                      +  25 ┃                                                ^^^^^^^^^^^^^^^^^^^^^^^^
                      +

                      Possible solutions

                      • Consider defining and using a custom data type to improve code comprehension
                      IDOBS-STAN-0302-J+yUBQ-25:48
                      SeverityStyle
                      DescriptionUsing tuples of big size (>= 4) can decrease code readability
                      Inspection IDSTAN-0302
                      Category
                      • AntiPattern
                      • Syntax
                      Filehs/test/HelVM/CartesianProduct.hs
                        24 ┃ 
                      +  25 ┃ (>>><<) = liftA2 (\(a1 , a2 , a3) (b1 , b2) -> (a1 , a2 , a3 , b1 , b2))
                      +  26 ┃                                                ^^^^^^^^^^^^^^^^^^^^^^^^
                      +

                      Possible solutions

                      • Consider defining and using a custom data type to improve code comprehension
                      IDOBS-STAN-0302-J+yUBQ-28:48
                      SeverityStyle
                      DescriptionUsing tuples of big size (>= 4) can decrease code readability
                      Inspection IDSTAN-0302
                      Category
                      • AntiPattern
                      • Syntax
                      Filehs/test/HelVM/CartesianProduct.hs
                        27 ┃ 
                      +  28 ┃ (>><<<) :: [(a1 , a2)] -> [(b1 , b2 , b3)] -> [(a1 , a2 , b1 , b2 , b3)]
                      +  29 ┃                                                ^^^^^^^^^^^^^^^^^^^^^^^^
                      +

                      Possible solutions

                      • Consider defining and using a custom data type to improve code comprehension
                      IDOBS-STAN-0302-J+yUBQ-29:48
                      SeverityStyle
                      DescriptionUsing tuples of big size (>= 4) can decrease code readability
                      Inspection IDSTAN-0302
                      Category
                      • AntiPattern
                      • Syntax
                      Filehs/test/HelVM/CartesianProduct.hs
                        28 ┃ 
                      +  29 ┃ (>><<<) = liftA2 (\(a1 , a2) (b1 , b2 , b3) -> (a1 , a2 , b1 , b2 , b3))
                      +  30 ┃                                                ^^^^^^^^^^^^^^^^^^^^^^^^
                      +

                      Possible solutions

                      • Consider defining and using a custom data type to improve code comprehension
                      IDOBS-STAN-0302-J+yUBQ-32:54
                      SeverityStyle
                      DescriptionUsing tuples of big size (>= 4) can decrease code readability
                      Inspection IDSTAN-0302
                      Category
                      • AntiPattern
                      • Syntax
                      Filehs/test/HelVM/CartesianProduct.hs
                        31 ┃ 
                      +  32 ┃ (>>><<<) :: [(a1 , a2 , a3)] -> [(b1 , b2 , b3)] -> [(a1 , a2 , a3 , b1 , b2 , b3)]
                      +  33 ┃                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                      +

                      Possible solutions

                      • Consider defining and using a custom data type to improve code comprehension
                      IDOBS-STAN-0302-J+yUBQ-33:54
                      SeverityStyle
                      DescriptionUsing tuples of big size (>= 4) can decrease code readability
                      Inspection IDSTAN-0302
                      Category
                      • AntiPattern
                      • Syntax
                      Filehs/test/HelVM/CartesianProduct.hs
                        32 ┃ 
                      +  33 ┃ (>>><<<) = liftA2 (\(a1 , a2 , a3) (b1 , b2 , b3) -> (a1 , a2 , a3 , b1 , b2 , b3))
                      +  34 ┃                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                      +

                      Possible solutions

                      • Consider defining and using a custom data type to improve code comprehension

                    Configurations

                    This section describes the final Stan configuration that was used on the project and explains how this result was assembled. Stan runtime settings have many parts, and each of them can come from different configuration sources. Stan is using Environment variables, TOML configuration file and CLI arguments to get the final results. If some option is specified through the multiple sources, the most prioritized one is used.

                    ActionFilterScope

                    Configuration Process Information

                    Information and warnings that were gathered during the configuration assemble process. This helps to understand how different parts of the configurations were retrieved.

                    • TOML Configurations file doesn't exist: /home/kamil-adam/git/helvm/helpa/.stan.toml
                    • TOML Configurations file doesn't exist: /home/kamil-adam/.stan.toml
                    • No CLI option specified for: checks
                    • configChecks is set through the source: Default
                    • TOML Configurations file doesn't exist: /home/kamil-adam/git/helvm/helpa/.stan.toml
                    • TOML Configurations file doesn't exist: /home/kamil-adam/.stan.toml
                    • No CLI option specified for: remove
                    • configRemoved is set through the source: Default
                    • TOML Configurations file doesn't exist: /home/kamil-adam/git/helvm/helpa/.stan.toml
                    • TOML Configurations file doesn't exist: /home/kamil-adam/.stan.toml
                    • No CLI option specified for: ignore
                    • configIgnored is set through the source: Default

                    Report Explained

                    Inspections

                    List of Inspections used for analysing the project

                    Inspection STAN-0001

                    Partial: base/head

                    Usage of partial function 'head' for lists

                    Warning
                    • Partial
                    • List

                    Possible solutions

                    • Replace list with 'NonEmpty' from 'Data.List.NonEmpty'
                    • Use explicit pattern-matching over lists

                    Inspection STAN-0002

                    Partial: base/tail

                    Usage of partial function 'tail' for lists

                    Warning
                    • Partial
                    • List

                    Possible solutions

                    • Replace list with 'NonEmpty' from 'Data.List.NonEmpty'
                    • Use explicit pattern-matching over lists

                    Inspection STAN-0003

                    Partial: base/init

                    Usage of partial function 'init' for lists

                    Warning
                    • Partial
                    • List

                    Possible solutions

                    • Replace list with 'NonEmpty' from 'Data.List.NonEmpty'
                    • Use explicit pattern-matching over lists

                    Inspection STAN-0004

                    Partial: base/last

                    Usage of partial function 'last' for lists

                    Warning
                    • Partial
                    • List

                    Possible solutions

                    • Replace list with 'NonEmpty' from 'Data.List.NonEmpty'
                    • Use explicit pattern-matching over lists

                    Inspection STAN-0005

                    Partial: base/!!

                    Usage of partial function '!!' for lists

                    Warning
                    • Partial
                    • List

                    Inspection STAN-0006

                    Partial: base/cycle

                    Usage of partial function 'cycle' for lists

                    Warning
                    • Partial
                    • List

                    Possible solutions

                    • Replace list with 'NonEmpty' from 'Data.List.NonEmpty'
                    • Use explicit pattern-matching over lists

                    Inspection STAN-0007

                    Partial: base/genericIndex

                    Usage of partial function 'genericIndex' for lists

                    Warning
                    • Partial
                    • List

                    Inspection STAN-0008

                    Partial: base/fromJust

                    Usage of partial function 'fromJust' for 'Maybe'

                    Warning
                    • Partial

                    Possible solutions

                    • Use explicit pattern-matching over Maybe
                    • Use one of the standard functions: 'maybe', 'fromMaybe'

                    Inspection STAN-0009

                    Partial: base/read

                    Usage of partial function 'read' for parsing 'String'

                    Warning
                    • Partial

                    Possible solutions

                    • Use 'readMaybe' or 'readEither' to handle failed parsing

                    Inspection STAN-0010

                    Partial: base/succ

                    Usage of partial function 'succ' for enumerable types

                    Warning
                    • Partial

                    Possible solutions

                    • Use '(+ 1)' for integral types (but be aware of arithmetic overflow)
                    • {Extra dependency} Use 'next' from 'Relude.Extra.Enum' in 'relude'

                    Inspection STAN-0011

                    Partial: base/pred

                    Usage of partial function 'pred' for enumerable types

                    Warning
                    • Partial

                    Possible solutions

                    • Use '(- 1)' for integral types (but be aware of arithmetic overflow)
                    • {Extra dependency} Use 'prev' from 'Relude.Extra.Enum' in 'relude'

                    Inspection STAN-0012

                    Partial: base/toEnum

                    Usage of partial function 'toEnum' for enumerable types

                    Warning
                    • Partial

                    Possible solutions

                    • {Extra dependency} Use 'safeToEnum' from 'Relude.Extra.Enum' in 'relude'

                    Inspection STAN-0013

                    Partial: base/maximum

                    Usage of partial function 'maximum' for

                    Warning
                    • Partial

                    Inspection STAN-0014

                    Partial: base/minimum

                    Usage of partial function 'minimum' for

                    Warning
                    • Partial

                    Inspection STAN-0015

                    Partial: base/maximumBy

                    Usage of partial function 'maximumBy' for

                    Warning
                    • Partial

                    Inspection STAN-0016

                    Partial: base/minimumBy

                    Usage of partial function 'minimumBy' for

                    Warning
                    • Partial

                    Inspection STAN-0017

                    Partial: base/foldl1

                    Usage of partial function 'foldl1' for

                    Warning
                    • Partial

                    Inspection STAN-0018

                    Partial: base/foldl1'

                    Usage of partial function 'foldl1'' for lists

                    Warning
                    • Partial
                    • List

                    Possible solutions

                    • Replace list with 'NonEmpty' from 'Data.List.NonEmpty'
                    • Use explicit pattern-matching over lists

                    Inspection STAN-0019

                    Partial: base/foldr1

                    Usage of partial function 'foldr1' for

                    Warning
                    • Partial

                    Inspection STAN-0020

                    Partial: base/fromList

                    Usage of partial function 'fromList' for

                    Warning
                    • Partial

                    Inspection STAN-0021

                    Partial: base/fromInteger

                    Usage of partial function 'fromInteger' for

                    Warning
                    • Partial

                    Inspection STAN-0101

                    Infinite: base/reverse

                    Usage of the 'reverse' function that hangs on infinite lists

                    PotentialBug
                    • Infinite
                    • List

                    Possible solutions

                    • Don't use 'reverse' if you expect your function to work with infinite lists
                    • {Extra dependency} Use the 'slist' library for fast and safe functions on infinite lists

                    Inspection STAN-0102

                    Infinite: base/isSuffixOf

                    Usage of the 'isSuffixOf' function that hangs on infinite lists

                    PotentialBug
                    • Infinite
                    • List

                    Possible solutions

                    • Don't use 'isSuffixOf' if you expect your function to work with infinite lists
                    • {Extra dependency} Use the 'slist' library for fast and safe functions on infinite lists

                    Inspection STAN-0103

                    Infinite: base/length

                    Usage of the 'length' function that hangs on infinite lists

                    PotentialBug
                    • Infinite
                    • List

                    Possible solutions

                    • Don't use 'length' if you expect your function to work with infinite lists
                    • {Extra dependency} Use the 'slist' library for fast and safe functions on infinite lists

                    Inspection STAN-0104

                    Infinite: base/genericLength

                    Usage of the 'genericLength' function that hangs on infinite lists

                    PotentialBug
                    • Infinite
                    • List

                    Possible solutions

                    • Don't use 'genericLength' if you expect your function to work with infinite lists
                    • {Extra dependency} Use the 'slist' library for fast and safe functions on infinite lists

                    Inspection STAN-0105

                    Infinite: base/sum

                    Usage of the 'sum' function that hangs on infinite lists

                    PotentialBug
                    • Infinite
                    • List

                    Possible solutions

                    • Don't use 'sum' if you expect your function to work with infinite lists
                    • {Extra dependency} Use the 'slist' library for fast and safe functions on infinite lists

                    Inspection STAN-0106

                    Infinite: base/product

                    Usage of the 'product' function that hangs on infinite lists

                    PotentialBug
                    • Infinite
                    • List

                    Possible solutions

                    • Don't use 'product' if you expect your function to work with infinite lists
                    • {Extra dependency} Use the 'slist' library for fast and safe functions on infinite lists

                    Inspection STAN-0201

                    Anti-pattern: [0 .. length xs]

                    Creating a list with wrong number of indices

                    PotentialBug
                    • AntiPattern

                    Possible solutions

                    • Replace '[0 .. length xs]' with '[0 .. length xs - 1]'
                    • Use 'zip [0 ..] xs` to work with list of pairs: index and element

                    Inspection STAN-0202

                    Anti-pattern: foldl

                    Usage of space-leaking function 'foldl'

                    Error
                    • SpaceLeak
                    • AntiPattern

                    Possible solutions

                    • Replace 'foldl' with 'foldl''
                    • Use 'foldr (flip . f)` instead of 'foldl f'

                    Inspection STAN-0203

                    Anti-pattern: Data.ByteString.Char8.pack

                    Usage of 'pack' function that doesn't handle Unicode characters

                    Error
                    • AntiPattern

                    Possible solutions

                    • Convert to 'Text' and use 'encodeUtf8' from 'Data.Text.Encoding'
                    • {Extra dependency} Use 'encodeUtf8' from 'relude'
                    • {Extra dependency} Use the 'utf8-string' package

                    Inspection STAN-0204

                    Anti-pattern: HashMap size

                    Usage of 'size' or 'length' for 'HashMap' that runs in linear time

                    Performance
                    • AntiPattern

                    Possible solutions

                    • {Extra dependency} Switch to 'Map' from 'containers'

                    Inspection STAN-0205

                    Anti-pattern: HashSet size

                    Usage of 'size' or 'length' for 'HashSet' that runs in linear time

                    Performance
                    • AntiPattern

                    Possible solutions

                    • {Extra dependency} Switch to 'Set' from 'containers'

                    Inspection STAN-0206

                    Data types with non-strict fields

                    Defining lazy fields in data types can lead to unexpected space leaks

                    Performance
                    • SpaceLeak
                    • Syntax

                    Possible solutions

                    • Add '!' before the type, e.g. !Int or !(Maybe Bool)
                    • Enable the 'StrictData' extension: {-# LANGUAGE StrictData #-}

                    Inspection STAN-0207

                    Anti-pattern: Foldable methods on possibly error-prone structures

                    Usage of Foldable methods on (,), Maybe, Either

                    PotentialBug
                    • AntiPattern

                    Possible solutions

                    • Use more explicit functions with specific monomorphic types

                    Inspection STAN-0208

                    Anti-pattern: Slow 'length' for Text

                    Usage of 'length' for 'Text' that runs in linear time

                    Performance
                    • AntiPattern

                    Possible solutions

                    • {Extra dependency} Switch to 'ByteString' from 'bytestring'

                    Inspection STAN-0209

                    Anti-pattern: Slow 'nub' for lists

                    Usage of 'nub' on lists that runs in quadratic time

                    Performance
                    • AntiPattern

                    Possible solutions

                    • {Extra dependency} Switch list to 'Set' from 'containers'
                    • {Extra dependency} Use 'ordNub/hashNub/sortNub/unstableNub' from 'relude'
                    • {Extra dependency} Use 'nubOrd' from 'containers'
                    • {Extra dependency} Use 'nubOrd' from 'extra'

                    Inspection STAN-0210

                    Anti-pattern: Slow 'for_' on ranges

                    Usage of 'for_' or 'forM_' on numerical ranges is slow

                    Performance
                    • AntiPattern

                    Possible solutions

                    • {Extra dependency} Use 'loop' library for fast monadic looping

                    Inspection STAN-0211

                    Anti-pattern: '</>' for URLs

                    Usage of '</>' for URLs results in the errors on Windows

                    Error
                    • AntiPattern

                    Possible solutions

                    • {Extra dependency} Use type-safe library for URLs
                    • Concatenate URLs with slashes '/'

                    Inspection STAN-0212

                    Anti-pattern: unsafe functions

                    Usage of unsafe functions breaks referential transparency

                    Error
                    • Unsafe
                    • AntiPattern

                    Possible solutions

                    • Remove 'undefined' or at least replace with 'error' to give better error messages
                    • Replace 'unsafeCoerce' with 'coerce'
                    • Rewrite the code to avoid using 'unsafePerformIO' and other unsafe IO functions

                    Inspection STAN-0213

                    Anti-pattern: Pattern matching on '_'

                    Pattern matching on '_' for sum types can create maintainability issues

                    Warning
                    • AntiPattern

                    Possible solutions

                    • Pattern match on each constructor explicitly
                    • Add meaningful names to holes, e.g. '_anyOtherFailure'

                    Inspection STAN-0214

                    Anti-pattern: use 'compare'

                    Usage of multiple comparison operators instead of single 'compare'

                    Performance
                    • AntiPattern

                    Possible solutions

                    • Rewrite code to use single 'compare' instead of many comparison operators

                    Inspection STAN-0215

                    Anti-pattern: Slashes in paths

                    Usage of '/' or '\' in paths results in the errors on different operation systems

                    Error
                    • AntiPattern

                    Possible solutions

                    • {Extra dependency} Use '</>' operator from 'filepath'

                    Inspection STAN-0301

                    Missing fixity declaration for operator

                    Using the implicit default fixity for operator: infixl 9

                    Style
                    • Syntax

                    Possible solutions

                    • Add 'infix[l|r]' declaration to the operator with explicit precedence

                    Inspection STAN-0302

                    Big tuples

                    Using tuples of big size (>= 4) can decrease code readability

                    Style
                    • AntiPattern
                    • Syntax

                    Possible solutions

                    • Consider defining and using a custom data type to improve code comprehension

                    Severity

                    We are using the following severity system to indicate the observation level

                    SeverityDescription
                    StyleCode style issues. Usually harmless.
                    PerformanceSerious defects that could cause slowness and space leaking.
                    PotentialBugHuman errors in code.
                    WarningPotential runtime errors on some inputs.
                    ErrorDangerous behaviour.
                    \ No newline at end of file diff --git a/gradlew b/gradlew deleted file mode 100755 index 4f906e0c..00000000 --- a/gradlew +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100644 index ac1b06f9..00000000 --- a/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/helpa.cabal b/helpa.cabal index f63b6399..bdfefec0 100644 --- a/helpa.cabal +++ b/helpa.cabal @@ -1,9 +1,7 @@ -cabal-version: 3.4 --- Initial helpa.cabal generated by etlas init. For further documentation, --- see http://eta-lang.org/docs/ +cabal-version: 2.4 name: helpa -version: 0.3.1.0 +version: 0.3.4.0 synopsis: HELPA - Heavenly Esoteric Little Para Assembler to esoteric languages implemented in Haskell/Eta description: Please see the README on GitHub at @@ -18,73 +16,23 @@ copyright: 2020-2021 WriteOnly Developers category: Language build-type: Simple -extra-source-files: docs/CHANGELOG.md +extra-source-files: + docs/CHANGELOG.md + docs/README.md + +tested-with: GHC == 8.10.5 source-repository head type: git location: https://github.com/helvm/helpa -library - other-modules: - exposed-modules: - HelVM.Common.Containers.ChunksOf - HelVM.Common.Containers.FromList - HelVM.Common.Containers.Insert - HelVM.Common.Containers.Lookup - HelVM.Common.Containers.Pop - HelVM.Common.Containers.Reverse - HelVM.Common.Containers.SplitAt - HelVM.Common.Containers.Util - - HelVM.Common.Digit.Digitable - HelVM.Common.Digit.Digits - HelVM.Common.Digit.ToDigit - - HelVM.Common.ReadText - HelVM.Common.Safe - HelVM.Common.SafeMonadT - HelVM.Common.Util - - HelVM.HelPA.Assembler.API - HelVM.HelPA.Assembler.AssemblyOptions - HelVM.HelPA.Assembler.AsmParserUtil - HelVM.HelPA.Assembler.IO.WrapperIO - HelVM.HelPA.Assembler.TokenType - HelVM.HelPA.Assembler.Value - - HelVM.HelPA.Assemblers.EAS.AsmParser - HelVM.HelPA.Assemblers.EAS.Assembler - HelVM.HelPA.Assemblers.EAS.CodeGenerator - HelVM.HelPA.Assemblers.EAS.Instruction - HelVM.HelPA.Assemblers.EAS.Linker - HelVM.HelPA.Assemblers.EAS.Reducer - - HelVM.HelPA.Assemblers.WSA.AsmParser - HelVM.HelPA.Assemblers.WSA.Assembler - HelVM.HelPA.Assemblers.WSA.CodeGenerator - HelVM.HelPA.Assemblers.WSA.Instruction - HelVM.HelPA.Assemblers.WSA.Linker - HelVM.HelPA.Assemblers.WSA.Reducer - HelVM.HelPA.Assemblers.WSA.Token - other-extensions: +common common-options build-depends: base --- , rio == 0.1.20.0 --- , classy-prelude == 1.5.0 , relude == 1.0.0.0 - , attoparsec - - , containers == 0.6.2.1 - , data-default - , ilist - , list-singleton - , split - mixins: base hiding (Prelude) , relude (Relude as Prelude, Relude.Extra, Data.Text) - hs-source-dirs: hs/src - default-language: Haskell2010 ghc-options: --Extensions -XEmptyDataDecls @@ -126,8 +74,8 @@ library -- -XDeriveLift -- -XStaticPointers -XDerivingStrategies ---Only for lib - -XDeriveFunctor + -XConstraintKinds + -XStrictData --Warnings -Wall -Wcompat @@ -144,190 +92,132 @@ library -hiedir=.hie -Wunused-packages -Werror + -fprint-potential-instances -test-suite spec - type: exitcode-stdio-1.0 - main-is: Main.hs - other-modules: - Spec - - HelVM.CartesianProduct - HelVM.Expectations + default-language: Haskell2010 - HelVM.HelPA.Assemblers.EAS.AsmParserSpec - HelVM.HelPA.Assemblers.EAS.AssemblerSpec - HelVM.HelPA.Assemblers.EAS.CodeGeneratorSpec - HelVM.HelPA.Assemblers.EAS.FileUtil - HelVM.HelPA.Assemblers.EAS.LinkerSpec - HelVM.HelPA.Assemblers.EAS.TestData - HelVM.HelPA.Assemblers.EAS.ReducerSpec +library + import: common-options + hs-source-dirs: hs/src + exposed-modules: + HelVM.Common.Containers.ChunksOf + HelVM.Common.Containers.FromList + HelVM.Common.Containers.Insert + HelVM.Common.Containers.Lookup + HelVM.Common.Containers.Pop + HelVM.Common.Containers.Reverse + HelVM.Common.Containers.SplitAt + HelVM.Common.Containers.Util + + HelVM.Common.Digit.Digitable + HelVM.Common.Digit.Digits + HelVM.Common.Digit.ToDigit + + HelVM.Common.ReadText + HelVM.Common.Safe + HelVM.Common.Util + + HelVM.HelPA.Assembler.API + HelVM.HelPA.Assembler.AssemblyOptions + HelVM.HelPA.Assembler.AsmParserUtil + HelVM.HelPA.Assembler.IO.BusinessIO + HelVM.HelPA.Assembler.TokenType + HelVM.HelPA.Assembler.Value + + HelVM.HelPA.Assemblers.EAS.AsmParser + HelVM.HelPA.Assemblers.EAS.Assembler + HelVM.HelPA.Assemblers.EAS.CodeGenerator + HelVM.HelPA.Assemblers.EAS.Instruction + HelVM.HelPA.Assemblers.EAS.Linker + HelVM.HelPA.Assemblers.EAS.Reducer + + HelVM.HelPA.Assemblers.WSA.AsmParser + HelVM.HelPA.Assemblers.WSA.Assembler + HelVM.HelPA.Assemblers.WSA.CodeGenerator + HelVM.HelPA.Assemblers.WSA.Instruction + HelVM.HelPA.Assemblers.WSA.Linker + HelVM.HelPA.Assemblers.WSA.Reducer + HelVM.HelPA.Assemblers.WSA.Token + build-depends: + attoparsec + , containers == 0.6.2.1 + , data-default + , ilist + , list-singleton + , mtl + , pretty-simple + , split + , type-operators + ghc-options: - HelVM.HelPA.Assemblers.WSA.AsmParserSpec - HelVM.HelPA.Assemblers.WSA.AssemblerSpec - HelVM.HelPA.Assemblers.WSA.CodeGeneratorSpec - HelVM.HelPA.Assemblers.WSA.FileUtil - HelVM.HelPA.Assemblers.WSA.LinkerSpec - HelVM.HelPA.Assemblers.WSA.ReducerSpec - HelVM.HelPA.Assemblers.WSA.TestData - other-extensions: +executable helpa + import: common-options + hs-source-dirs: hs/app + main-is: Main.hs + other-modules: + AppOptions build-depends: - base --- , rio == 0.1.20.0 --- , classy-prelude == 1.5.0 - , relude == 1.0.0.0 + helpa + , optparse-applicative >= 0.14.3.0 + ghc-options: + -threaded + -rtsopts + -with-rtsopts=-N - , helpa +test-suite helpa-test + import: common-options + type: exitcode-stdio-1.0 + hs-source-dirs: hs/test + main-is: Main.hs + other-modules: + Spec + + HelVM.CartesianProduct + HelVM.Expectations + HelVM.GoldenExpectations + HelVM.MonadErrorSpec + + HelVM.HelPA.Assemblers.EAS.AsmParserSpec + HelVM.HelPA.Assemblers.EAS.AssemblerSpec + HelVM.HelPA.Assemblers.EAS.CodeGeneratorSpec + HelVM.HelPA.Assemblers.EAS.FileUtil + HelVM.HelPA.Assemblers.EAS.LinkerSpec + HelVM.HelPA.Assemblers.EAS.TestData + HelVM.HelPA.Assemblers.EAS.ReducerSpec + + HelVM.HelPA.Assemblers.WSA.AsmParserSpec + HelVM.HelPA.Assemblers.WSA.AssemblerSpec + HelVM.HelPA.Assemblers.WSA.CodeGeneratorSpec + HelVM.HelPA.Assemblers.WSA.FileUtil + HelVM.HelPA.Assemblers.WSA.LinkerSpec + HelVM.HelPA.Assemblers.WSA.ReducerSpec + HelVM.HelPA.Assemblers.WSA.TestData + build-depends: + helpa , filepath + , mtl + , type-operators , hspec - , hspec-attoparsec , hspec-core + , hspec-expectations-pretty-diff , hspec-golden , hspec-slow --- , QuickCheck --- , smallcheck - mixins: - base hiding (Prelude) - , relude (Relude as Prelude, Relude.Extra) - hs-source-dirs: hs/test - default-language: Haskell2010 build-tool-depends: hspec-discover:hspec-discover == 2.* ghc-options: ---Extensions - -XEmptyDataDecls - -XExistentialQuantification - -XFlexibleContexts - -XFlexibleInstances - -XFunctionalDependencies - -XGADTs - -XGeneralizedNewtypeDeriving - -XInstanceSigs - -XKindSignatures - -XLambdaCase - -XMultiParamTypeClasses - -XMultiWayIf - -XNamedFieldPuns --- -XNoImplicitPrelude - -XOverloadedStrings - -XPartialTypeSignatures - -XPatternGuards - -XPolyKinds - -XRankNTypes - -XRecordWildCards - -XScopedTypeVariables - -XStandaloneDeriving - -XTupleSections - -XTypeFamilies - -XTypeSynonymInstances - -XViewPatterns --- -XCPP --- -XTemplateHaskell --- -XForeignFunctionInterface --- -XMagicHash --- -XUnliftedFFITypes --- -XTypeOperators --- -XUnboxedTuples --- -XPackageImports --- -XQuasiQuotes --- -XDeriveAnyClass --- -XDeriveLift --- -XStaticPointers - -XDerivingStrategies ---Warnings - -Wall - -Wcompat - -Widentities - -Wincomplete-uni-patterns - -Wincomplete-record-updates - -Wredundant-constraints - -Wnoncanonical-monad-instances - -fhide-source-paths --- -Wmissing-export-lists FIXME - -Wpartial-fields - -Wmissing-deriving-strategies - -fwrite-ide-info - -hiedir=.hie - -Wunused-packages - -Werror ---Only for tests -threaded -rtsopts -with-rtsopts=-N -executable helpa - main-is: Main.hs - other-modules: - AppOptions - - other-extensions: - build-depends: - base --- , rio == 0.1.20.0 --- , classy-prelude == 1.5.0 - , relude == 1.0.0.0 - - , helpa - , optparse-applicative >= 0.14.3.0 - mixins: - base hiding (Prelude) - , relude (Relude as Prelude, Relude.Extra) - hs-source-dirs: hs/app - default-language: Haskell2010 - ghc-options: ---Extensions - -XEmptyDataDecls - -XExistentialQuantification - -XFlexibleContexts - -XFlexibleInstances - -XFunctionalDependencies - -XGADTs - -XGeneralizedNewtypeDeriving - -XInstanceSigs - -XKindSignatures - -XLambdaCase - -XMultiParamTypeClasses - -XMultiWayIf - -XNamedFieldPuns --- -XNoImplicitPrelude - -XOverloadedStrings - -XPartialTypeSignatures - -XPatternGuards - -XPolyKinds - -XRankNTypes - -XRecordWildCards - -XScopedTypeVariables - -XStandaloneDeriving - -XTupleSections - -XTypeFamilies - -XTypeSynonymInstances - -XViewPatterns --- -XCPP --- -XTemplateHaskell --- -XForeignFunctionInterface --- -XMagicHash --- -XUnliftedFFITypes --- -XTypeOperators --- -XUnboxedTuples --- -XPackageImports --- -XQuasiQuotes --- -XDeriveAnyClass --- -XDeriveLift --- -XStaticPointers - -XDerivingStrategies ---Warnings - -Wall - -Wcompat - -Widentities - -Wincomplete-uni-patterns - -Wincomplete-record-updates - -Wredundant-constraints - -Wnoncanonical-monad-instances - -fhide-source-paths --- -Wmissing-export-lists FIXME - -Wpartial-fields - -Wmissing-deriving-strategies - -fwrite-ide-info - -hiedir=.hie - -Wunused-packages - -Werror +--benchmark helpa-benchmark +-- import: common-options +-- type: exitcode-stdio-1.0 +-- hs-source-dirs: hs/benchmark +-- main-is: Main.hs +-- build-depends: +-- helpa +-- ghc-options: +-- -threaded +-- -rtsopts +-- -with-rtsopts=-N diff --git a/hlint-mv.sh b/hlint-mv.sh deleted file mode 100755 index ce31b8cf..00000000 --- a/hlint-mv.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -./hlint.sh - -mv .hlint.yaml .hlint.yaml.bak - -./hlint.sh - -mv .hlint.yaml.bak .hlint.yaml diff --git a/hpack.sh b/hpack.sh new file mode 100755 index 00000000..5a462a4d --- /dev/null +++ b/hpack.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +curl -sSL https://github.com/sol/hpack/raw/main/get-hpack.sh | bash diff --git a/hs/app/AppOptions.hs b/hs/app/AppOptions.hs index 81aa934c..e6518070 100644 --- a/hs/app/AppOptions.hs +++ b/hs/app/AppOptions.hs @@ -48,22 +48,22 @@ optionParser = AppOptions ) data AppOptions = AppOptions - { lang :: String --Lang - , tokenType :: String --TokenType - , debug :: Bool - , startOfInstruction :: Bool - , endOfLine :: Bool - , file :: String - , dir :: String + { lang :: !String --Lang + , tokenType :: !String --TokenType + , debug :: !Bool + , startOfInstruction :: !Bool + , endOfLine :: !Bool + , file :: !String + , dir :: !String } ---- data Lang = HAPAPL | EAS | WSA - deriving stock (Eq, Read, Show) + deriving stock (Eq , Read , Show) langs :: [Lang] -langs = [HAPAPL, EAS, WSA] +langs = [HAPAPL , EAS , WSA] computeLang :: String -> Lang computeLang raw = valid $ readMaybe raw where diff --git a/hs/app/Main.hs b/hs/app/Main.hs index 0320c90b..e88d0b45 100644 --- a/hs/app/Main.hs +++ b/hs/app/Main.hs @@ -4,6 +4,7 @@ module Main where import HelVM.HelPA.Assembler.API import HelVM.HelPA.Assembler.AssemblyOptions +import HelVM.HelPA.Assembler.IO.BusinessIO import HelVM.HelPA.Assembler.TokenType import qualified HelVM.HelPA.Assemblers.EAS.Assembler as EAS @@ -23,20 +24,19 @@ main = run =<< execParser opts where <> progDesc "" ) run :: AppOptions -> IO () -run AppOptions{lang, tokenType, debug, startOfInstruction, endOfLine, dir, file} = do - eval lang' assemblerOptions sourcePath where - assemblerOptions = (AssemblyOptions {tokenType=tokenType', debug=debug, startOfInstruction=startOfInstruction, endOfLine=endOfLine}) - sourcePath = (SourcePath {dirPath = dir, filePath = file}) +run AppOptions{lang , tokenType , debug , startOfInstruction , endOfLine , dir , file} = do + putTextLn =<< exceptTToIO (eval lang' assemblerOptions sourcePath) where --FIXME Bug in relude doc + assemblerOptions = AssemblyOptions {tokenType=tokenType', debug=debug , startOfInstruction=startOfInstruction , endOfLine=endOfLine} + sourcePath = SourcePath {dirPath = dir , filePath = file} tokenType' = parseTokenType tokenType lang' = computeLang lang -eval :: Lang -> AssemblyOptions -> SourcePath -> IO () -eval EAS _ = putExcept . EAS.assembleFile -eval WSA options = putExcept . flip WSA.assembleFile options -eval HAPAPL _ = hapapl -putExcept :: SafeFail IO Text -> IO () -putExcept io = putTextLn . unsafe =<< io --FIXME Bug in relude doc -hapapl :: SourcePath -> IO () -hapapl _ = putStrLn "HAPAPL is not supported now" +eval :: BIO m => Lang -> AssemblyOptions -> SourcePath -> m Text +eval EAS _ path = EAS.assembleFile path +eval WSA options path = WSA.assembleFile path options +eval HAPAPL _ _ = hapapl + +hapapl :: BIO m => m Text +hapapl = liftError "HAPAPL is not supported now" diff --git a/hs/benchmark/Main.hs b/hs/benchmark/Main.hs new file mode 100644 index 00000000..5c0b543c --- /dev/null +++ b/hs/benchmark/Main.hs @@ -0,0 +1,4 @@ +module Main where + +main :: IO () +main = print ("Hello benchmark!" :: Text) diff --git a/hs/src/HelVM/Common/Containers/ChunksOf.hs b/hs/src/HelVM/Common/Containers/ChunksOf.hs index 8d3c7b88..de90e8c4 100644 --- a/hs/src/HelVM/Common/Containers/ChunksOf.hs +++ b/hs/src/HelVM/Common/Containers/ChunksOf.hs @@ -1,13 +1,4 @@ module HelVM.Common.Containers.ChunksOf where ---import qualified Data.List.Split as List ---import qualified Data.Sequence as Seq - class ChunksOf e c | c -> e where chunksOf :: Int -> c -> c - ---instance ChunksOf e [e] where --- chunksOf = List.chunksOf --- ---instance ChunksOf e (Seq e) where --- chunksOf = Seq.chunksOf diff --git a/hs/src/HelVM/Common/Containers/FromList.hs b/hs/src/HelVM/Common/Containers/FromList.hs index 7aafc5b0..6f1727bc 100644 --- a/hs/src/HelVM/Common/Containers/FromList.hs +++ b/hs/src/HelVM/Common/Containers/FromList.hs @@ -1,6 +1,6 @@ module HelVM.Common.Containers.FromList where -import Prelude hiding (empty , fromList , one) +import Prelude hiding (fromList , one) import qualified Data.List.Index as List import qualified Data.List.Singleton as List @@ -10,34 +10,28 @@ import qualified Data.Text as Text maybeToFromList :: FromList e c => Maybe e -> c maybeToFromList (Just e) = one e -maybeToFromList Nothing = empty +maybeToFromList Nothing = mempty intMapFromList :: [e] -> IntMap e intMapFromList = IntMap.fromList . List.indexed -class FromList e c | c -> e where +class Monoid c => FromList e c | c -> e where fromList :: [e] -> c - empty :: c one :: e -> c - empty = fromList [] one e = fromList [e] instance FromList e [e] where fromList = id - empty = [] one = List.singleton instance FromList e (Seq e) where fromList = Seq.fromList - empty = Seq.empty one = Seq.singleton instance FromList e (IntMap e) where fromList = intMapFromList - empty = IntMap.empty one = IntMap.singleton 0 instance FromList Char Text where fromList = toText - empty = Text.empty one = Text.singleton diff --git a/hs/src/HelVM/Common/Containers/Lookup.hs b/hs/src/HelVM/Common/Containers/Lookup.hs index 2948f71a..698c3c77 100644 --- a/hs/src/HelVM/Common/Containers/Lookup.hs +++ b/hs/src/HelVM/Common/Containers/Lookup.hs @@ -5,11 +5,11 @@ import HelVM.Common.Safe import qualified Data.IntMap as IntMap import qualified Data.Sequence as Seq -naturalIndexSafe :: (Show c , Lookup e c) => c -> Natural -> Safe e +naturalIndexSafe :: (MonadSafeError m , Show c , Lookup e c) => c -> Natural -> m e naturalIndexSafe c i = indexSafe c $ fromIntegral i -indexSafe :: (Show c , Lookup e c) => c -> Int -> Safe e -indexSafe c i = maybeToSafeOrErrorTupleList [("Lookup.indexSafe" , show c) , ("index" , show i)] $ indexMaybe c i +indexSafe :: (MonadSafeError m , Show c , Lookup e c) => c -> Int -> m e +indexSafe c i = liftMaybeOrErrorTupleList [("Lookup.indexSafe" , show c) , ("index" , show i)] $ indexMaybe c i indexMaybe :: Lookup e c => c -> Int -> Maybe e indexMaybe = flip lookup diff --git a/hs/src/HelVM/Common/Containers/Pop.hs b/hs/src/HelVM/Common/Containers/Pop.hs index c9997d74..76414bcc 100644 --- a/hs/src/HelVM/Common/Containers/Pop.hs +++ b/hs/src/HelVM/Common/Containers/Pop.hs @@ -4,28 +4,28 @@ import HelVM.Common.Safe import Data.Sequence (Seq(..)) -discard :: Pop1 e c => c -> Safe c +discard :: (MonadSafeError m , Pop1 e c) => c -> m c discard s = discard' <$> pop1 s where discard' (_ , s') = s' class Pop1 e c | c -> e where - pop1 :: c -> Safe (e , c) + pop1 :: MonadSafeError m => c -> m (e , c) instance Show e => Pop1 e [e] where - pop1 (e : c) = safe (e , c) - pop1 c = safeErrorTuple ("Empty" , show c) + pop1 (e : c) = pure (e , c) + pop1 c = liftErrorTuple ("Empty" , show c) instance Show e => Pop1 e (Seq e) where - pop1 (e :<| c) = safe (e , c) - pop1 c = safeErrorTuple ("Empty" , show c) + pop1 (e :<| c) = pure (e , c) + pop1 c = liftErrorTuple ("Empty" , show c) class Pop2 e c | c -> e where - pop2 :: c -> Safe (e , e , c) + pop2 :: c -> MonadSafeError m => m (e , e , c) instance Show e => Pop2 e [e] where - pop2 (e : e' : c) = safe (e , e', c) - pop2 c = safeErrorTuple ("Empty" , show c) + pop2 (e : e' : c) = pure (e , e', c) + pop2 c = liftErrorTuple ("Empty" , show c) instance Show e => Pop2 e (Seq e) where - pop2 (e :<| e' :<| c) = safe (e , e', c) - pop2 c = safeErrorTuple ("Empty " , show c) + pop2 (e :<| e' :<| c) = pure (e , e', c) + pop2 c = liftErrorTuple ("Empty " , show c) diff --git a/hs/src/HelVM/Common/Containers/Util.hs b/hs/src/HelVM/Common/Containers/Util.hs index 482adf93..f37991db 100644 --- a/hs/src/HelVM/Common/Containers/Util.hs +++ b/hs/src/HelVM/Common/Containers/Util.hs @@ -4,8 +4,8 @@ import HelVM.Common.Safe import Relude.Extra -indexSafeByKey :: (Show k, Ord k, Show v) => k -> Map k v -> Safe v -indexSafeByKey k mapKV = maybeToSafeOrErrorTupleList [( "key" , show k) , ("map" , show mapKV)] $ lookup k mapKV +indexSafeByKey :: (MonadSafeError m , Show k , Ord k , Show v) => k -> Map k v -> m v +indexSafeByKey k mapKV = liftMaybeOrErrorTupleList [( "key" , show k) , ("map" , show mapKV)] $ lookup k mapKV showFoldable :: (Foldable c , Functor c , Show e) => c e -> Text showFoldable f = fmconcat $ show <$> f diff --git a/hs/src/HelVM/Common/Digit/Digitable.hs b/hs/src/HelVM/Common/Digit/Digitable.hs index d193dea2..cb9ca6c4 100644 --- a/hs/src/HelVM/Common/Digit/Digitable.hs +++ b/hs/src/HelVM/Common/Digit/Digitable.hs @@ -1,8 +1,8 @@ module HelVM.Common.Digit.Digitable where import HelVM.Common.Digit.ToDigit - + import HelVM.Common.Safe class ToDigit t => Digitable t where - fromDigit :: (Show a , Integral a) => a -> Safe t + fromDigit :: (MonadSafeError m , Show a , Integral a) => a -> m t diff --git a/hs/src/HelVM/Common/Digit/Digits.hs b/hs/src/HelVM/Common/Digit/Digits.hs index e6407bb1..b4a0f658 100644 --- a/hs/src/HelVM/Common/Digit/Digits.hs +++ b/hs/src/HelVM/Common/Digit/Digits.hs @@ -7,13 +7,13 @@ module HelVM.Common.Digit.Digits ( import HelVM.Common.Safe -digitsToIntegral :: Integral a => a -> [Safe a] -> Safe a --FIXME -digitsToIntegral base = foldr (liftedMulAndAdd base) (safe 0) +digitsToIntegral :: (MonadSafeError m , Integral a) => a -> [m a] -> m a +digitsToIntegral base = foldr (liftedMulAndAdd base) (pure 0) digitsToIntegral' :: Integral a => a -> [a] -> a digitsToIntegral' base = foldr (mulAndAdd base) 0 -liftedMulAndAdd :: (Integral a) => a -> Safe a -> Safe a -> Safe a +liftedMulAndAdd :: (MonadSafeError m , Integral a) => a -> m a -> m a -> m a liftedMulAndAdd base = liftA2 (mulAndAdd base) mulAndAdd :: Integral a => a -> a -> a -> a @@ -30,11 +30,11 @@ naturalToDigits2 = naturalToDigits 2 naturalToDigits :: Natural -> Natural -> [Natural] naturalToDigits base = unfoldl (divModMaybe base) -divModMaybe :: Natural -> Natural -> Maybe (Natural, Natural) +divModMaybe :: Natural -> Natural -> Maybe (Natural , Natural) divModMaybe _ 0 = Nothing divModMaybe base value = Just (value `divMod` base) -unfoldl :: (a -> Maybe (a,b)) -> a -> [b] +unfoldl :: (a -> Maybe (a , b)) -> a -> [b] unfoldl lambda value = check $ lambda value where check Nothing = [] check (Just (a , b)) = unfoldl lambda a <> [b] diff --git a/hs/src/HelVM/Common/Digit/ToDigit.hs b/hs/src/HelVM/Common/Digit/ToDigit.hs index 492697fe..b3c4bd37 100644 --- a/hs/src/HelVM/Common/Digit/ToDigit.hs +++ b/hs/src/HelVM/Common/Digit/ToDigit.hs @@ -7,23 +7,23 @@ import Data.Char hiding (chr) import qualified Data.List.Split as List -makeDigitString :: ToDigit a => [a] -> Safe String +makeDigitString :: (MonadSafeError m , ToDigit a) => [a] -> m String makeDigitString xs = sequenceA $ toDigitChar <$> xs -makeAsciiString :: ToDigit a => Int -> Int -> [a] -> Safe String +makeAsciiString :: (MonadSafeError m , ToDigit a) => Int -> Int -> [a] -> m String makeAsciiString base n xs = sequenceA $ makeChar base <$> List.chunksOf n xs -makeChar :: ToDigit a => Int -> [a] -> Safe Char +makeChar :: (MonadSafeError m , ToDigit a) => Int -> [a] -> m Char makeChar base xs = chr <$> makeIntegral base (reverse xs) -toDigitChar :: ToDigit a => a -> Safe Char +toDigitChar :: MonadSafeError m => ToDigit a => a -> m Char toDigitChar a = integerToDigit <$> toDigit a integerToDigit :: Integer -> Char integerToDigit = intToDigit . fromInteger -makeIntegral :: (ToDigit a , Integral b) => b -> [a] -> Safe b +makeIntegral :: (MonadSafeError m , ToDigit a , Integral b) => b -> [a] -> m b makeIntegral base digits = digitsToIntegral base (toDigit <$> digits) class ToDigit t where - toDigit :: Integral a => t -> Safe a + toDigit :: (MonadSafeError m, Integral a) => t -> m a diff --git a/hs/src/HelVM/Common/ReadText.hs b/hs/src/HelVM/Common/ReadText.hs index 4a420bae..48b34514 100644 --- a/hs/src/HelVM/Common/ReadText.hs +++ b/hs/src/HelVM/Common/ReadText.hs @@ -7,10 +7,12 @@ module HelVM.Common.ReadText ( import HelVM.Common.Safe readText :: Read a => Text -> a -readText = unsafe . readTextSafe +readText = unsafe . readTextSafe where + unsafe (Right a) = a + unsafe (Left a) = error $ errorsToText a -readTextSafe :: Read a => Text -> Safe a -readTextSafe a = appendErrorTuple ("" , a) $ readEither $ toString a +readTextSafe :: (MonadSafeError m , Read a) => Text -> m a +readTextSafe a = appendError a $ liftEitherError $ readEither $ toString a readTextMaybe :: Read a => Text -> Maybe a readTextMaybe = readMaybe . toString diff --git a/hs/src/HelVM/Common/Safe.hs b/hs/src/HelVM/Common/Safe.hs index f9b998bf..259802fa 100644 --- a/hs/src/HelVM/Common/Safe.hs +++ b/hs/src/HelVM/Common/Safe.hs @@ -1,19 +1,25 @@ module HelVM.Common.Safe ( - safeFailToFail, - safeToFail, - safeLegacyToFail, + safeIOToPTextIO, - safe, - safeLegacyToSafe, - safeToSafeLegacy, + safeIOToIO, + safeToIO, + exceptTToIO, + safeExceptT, + safeToEitherLegacy, + errorsToText, - maybeToSafeOrErrorTupleList, - maybeToSafeOrErrorTuple, - maybeToSafeOrError, + liftExceptT, + liftSafe, + liftEitherError, + liftEitherLegacy, - safeErrorTupleList, - safeErrorTuple, - safeError, + liftMaybeOrErrorTupleList, + liftMaybeOrErrorTuple, + liftMaybeOrError, + + liftErrorTupleList, + liftErrorTuple, + liftError, appendErrorTupleList, appendErrorTuple, @@ -22,68 +28,92 @@ module HelVM.Common.Safe ( tupleListToError, tupleToError, - unsafe, - - SafeFail_, - SafeFail, - Safe_, + MonadSafeError, + SafeExceptT, + EitherLegacy, + EitherError, Safe, Error, ) where -safeFailToFail :: MonadFail m => SafeFail m a -> m a -safeFailToFail m = safeToFail =<< m +import HelVM.Common.Util + +import Control.Monad.Except hiding (ExceptT , runExceptT) + +import System.IO.Error + +import qualified Data.List.Singleton as List + +safeIOToPTextIO :: Show a => IO (Safe a) -> IO Text +safeIOToPTextIO a = showP <$> safeIOToIO a + +safeIOToIO :: IO (Safe a) -> IO a +safeIOToIO a = safeToIO =<< a -safeToFail :: MonadFail m => Safe a -> m a -safeToFail = safeLegacyToFail . safeToSafeLegacy +safeToIO :: Safe a -> IO a +safeToIO = exceptTToIO . liftSafe -safeLegacyToFail :: MonadFail m => SafeLegacy a -> m a -safeLegacyToFail (Right a) = pure a -safeLegacyToFail (Left a) = fail a +exceptTToIO :: SafeExceptT IO a -> IO a +exceptTToIO = liftExceptT . withExceptT (userError . errorsToString) --- Create Safe +safeExceptT :: Monad m => m a -> SafeExceptT m a +safeExceptT a = ExceptT $ pure <$> a -safe :: a -> Safe a -safe = pure +safeToEitherLegacy :: Safe a -> EitherLegacy a +safeToEitherLegacy = first errorsToString -safeLegacyToSafe :: SafeLegacy a -> Safe a -safeLegacyToSafe = first toText +errorsToString :: Errors -> String +errorsToString = toString . errorsToText -safeToSafeLegacy :: Safe a -> SafeLegacy a -safeToSafeLegacy = first toString +errorsToText :: Errors -> Text +errorsToText = unlines . reverse ----- Create from Maybe +-- Lift -maybeToSafeOrErrorTupleList :: [ErrorTuple] -> Maybe a -> Safe a -maybeToSafeOrErrorTupleList = maybeToSafeOrError . tupleListToError +liftExceptT :: MonadError e m => ExceptT e m a -> m a +liftExceptT m = liftEither =<< runExceptT m -maybeToSafeOrErrorTuple :: ErrorTuple -> Maybe a -> Safe a -maybeToSafeOrErrorTuple = maybeToSafeOrError . tupleToError +liftSafe :: MonadSafeError m => Safe a -> m a +liftSafe = liftEither -maybeToSafeOrError :: Error -> Maybe a -> Safe a -maybeToSafeOrError = maybeToRight +liftEitherError :: MonadSafeError m => Either Text a -> m a +liftEitherError = liftEither . first List.singleton ----- Create Error +liftEitherLegacy :: MonadSafeError m => EitherLegacy a -> m a +liftEitherLegacy = liftSafe . first (List.singleton . toText) -safeErrorTupleList :: [ErrorTuple] -> Safe a -safeErrorTupleList = safeError . tupleListToError +-- Lift from Maybe -safeErrorTuple :: ErrorTuple -> Safe a -safeErrorTuple = safeError . tupleToError +liftMaybeOrErrorTupleList :: MonadSafeError m => [ErrorTuple] -> Maybe a -> m a +liftMaybeOrErrorTupleList = liftMaybeOrError . tupleListToError -safeError :: Error -> Safe a -safeError = Left +liftMaybeOrErrorTuple :: MonadSafeError m => ErrorTuple -> Maybe a -> m a +liftMaybeOrErrorTuple = liftMaybeOrError . tupleToError ----- Append Error +liftMaybeOrError :: MonadSafeError m => Error -> Maybe a -> m a +liftMaybeOrError e = liftSafe . maybeToRight [e] -appendErrorTupleList :: [ErrorTuple] -> Safe a -> Safe a +-- Lift from Error + +liftErrorTupleList :: MonadSafeError m => [ErrorTuple] -> m a +liftErrorTupleList = liftError . tupleListToError + +liftErrorTuple :: MonadSafeError m => ErrorTuple -> m a +liftErrorTuple = liftError . tupleToError + +liftError :: MonadSafeError m => Error -> m a +liftError e = throwError [e] + +-- Append Error + +appendErrorTupleList :: MonadSafeError m => [ErrorTuple] -> m a -> m a appendErrorTupleList = appendError . tupleListToError -appendErrorTuple :: ErrorTuple -> Safe a -> Safe a +appendErrorTuple :: MonadSafeError m => ErrorTuple -> m a -> m a appendErrorTuple = appendError . tupleToError -appendError :: Error -> Safe a -> Safe a -appendError message = first (<> message) +appendError :: MonadSafeError m => Error -> m a -> m a +appendError message a = catchError a appendAndThrow where appendAndThrow es = throwError ([message] <> es) ---- @@ -97,20 +127,18 @@ tupleToError (prefix , showed) = " [" <> format prefix <> showed <> "]" where ---- -unsafe :: Safe a -> a -unsafe (Right a) = a -unsafe (Left a) = error a +type MonadSafeError m = MonadError Errors m ----- +type SafeExceptT m = ExceptT Errors m -type SafeFail_ m = SafeFail m () -type SafeFail m a = m (Safe a) +type EitherLegacy = Either String -type SafeLegacy a = Either String a +type EitherError = Either Text -type Safe_ = Safe () -type Safe a = Either Error a +type Safe = Either Errors type ErrorTuple = (Error , Error) +type Errors = [Text] + type Error = Text diff --git a/hs/src/HelVM/Common/SafeMonadT.hs b/hs/src/HelVM/Common/SafeMonadT.hs deleted file mode 100644 index cb2225b3..00000000 --- a/hs/src/HelVM/Common/SafeMonadT.hs +++ /dev/null @@ -1,39 +0,0 @@ -module HelVM.Common.SafeMonadT ( - hoistSafe, - hoistMonad, - hoistError, - safeMonadToFail, - unsafeRunExceptT, - SafeMonadT_, - SafeMonadT, -) where - -import HelVM.Common.Safe - ---import Control.Monad.Except - -hoistMonad :: Monad m => m a -> SafeMonadT m a -hoistMonad a = ExceptT $ safe <$> a - ---except :: Monad m => Either e a -> ExceptT e m a -hoistSafe :: Monad m => Safe a -> SafeMonadT m a -hoistSafe = hoistEither ---hoistSafe = except - ---hoistError :: Monad m => e -> ExceptT e m a -hoistError :: Monad m => Error -> SafeMonadT m a -hoistError = hoistSafe . safeError ---hoistError = throwE - ----- - -safeMonadToFail :: MonadFail m => SafeMonadT m a -> m a -safeMonadToFail m = safeToFail =<< runExceptT m - -unsafeRunExceptT :: Monad m => SafeMonadT m a -> m a -unsafeRunExceptT = fmap unsafe . runExceptT - ----- - -type SafeMonadT_ m = SafeMonadT m () -type SafeMonadT m a = ExceptT Error m a diff --git a/hs/src/HelVM/Common/Util.hs b/hs/src/HelVM/Common/Util.hs index bec3f0a1..0e07a6db 100644 --- a/hs/src/HelVM/Common/Util.hs +++ b/hs/src/HelVM/Common/Util.hs @@ -1,13 +1,20 @@ -module HelVM.Common.Util where +module HelVM.Common.Util ( + toUppers, + splitOneOf, + showP, + showToText, + genericChr, + (???), + fromMaybeOrDef, +) where import Data.Char hiding (chr) import Data.Default import Data.Typeable +import Text.Pretty.Simple import qualified Data.Text as Text -type D a = a -> a - --- TextUtil toUppers :: Text -> Text @@ -16,7 +23,10 @@ toUppers = Text.map toUpper splitOneOf :: String -> Text -> [Text] splitOneOf s = Text.split contains where contains c = c `elem` s -showToText :: (Typeable a, Show a) => a -> Text +showP :: Show a => a -> Text +showP = toText . pShowNoColor + +showToText :: (Typeable a , Show a) => a -> Text showToText a = show a `fromMaybe` (cast a :: Maybe Text) ---- CharUtil @@ -26,8 +36,9 @@ genericChr = chr . fromIntegral ---- MaybeUtil -(??) :: Maybe a -> a -> a -(??) = flip fromMaybe +infixl 1 ??? +(???) :: Maybe a -> a -> a +(???) = flip fromMaybe fromMaybeOrDef :: Default a => Maybe a -> a fromMaybeOrDef = fromMaybe def diff --git a/hs/src/HelVM/HelPA/Assembler/API.hs b/hs/src/HelVM/HelPA/Assembler/API.hs index 27292e7e..b2608344 100644 --- a/hs/src/HelVM/HelPA/Assembler/API.hs +++ b/hs/src/HelVM/HelPA/Assembler/API.hs @@ -4,6 +4,6 @@ absolutePath :: SourcePath -> SourcePath absolutePath path = path { filePath = dirPath path <> "/" <> filePath path } data SourcePath = SourcePath - { dirPath :: FilePath - , filePath :: FilePath + { dirPath :: !FilePath + , filePath :: !FilePath } diff --git a/hs/src/HelVM/HelPA/Assembler/AsmParserUtil.hs b/hs/src/HelVM/HelPA/Assembler/AsmParserUtil.hs index 4f685968..1e607afa 100644 --- a/hs/src/HelVM/HelPA/Assembler/AsmParserUtil.hs +++ b/hs/src/HelVM/HelPA/Assembler/AsmParserUtil.hs @@ -5,7 +5,7 @@ import HelVM.HelPA.Assembler.Value import HelVM.Common.ReadText import Data.Attoparsec.Combinator -import Data.Attoparsec.Text hiding (I, D) +import Data.Attoparsec.Text hiding (I , D) import Data.Char naturalParser :: Parser Natural diff --git a/hs/src/HelVM/HelPA/Assembler/AssemblyOptions.hs b/hs/src/HelVM/HelPA/Assembler/AssemblyOptions.hs index 5e2b1ee9..30a5694a 100644 --- a/hs/src/HelVM/HelPA/Assembler/AssemblyOptions.hs +++ b/hs/src/HelVM/HelPA/Assembler/AssemblyOptions.hs @@ -2,7 +2,7 @@ module HelVM.HelPA.Assembler.AssemblyOptions where import HelVM.HelPA.Assembler.TokenType -manyOptionsWithName :: [(String, AssemblyOptions)] +manyOptionsWithName :: [(String , AssemblyOptions)] manyOptionsWithName = [ ( "bothTokenTypeOptions" , bothTokenTypeOptions ) , ( "visibleTokenTypeOptions" , visibleTokenTypeOptions ) @@ -12,38 +12,38 @@ manyOptionsWithName = [ , ( "dsoiOptions" , dsoiOptions ) , ( "deolOptions" , deolOptions ) , ( "allTrue" , allTrue ) - ] + ] bothTokenTypeOptions :: AssemblyOptions -bothTokenTypeOptions = AssemblyOptions {tokenType=BothTokenType, debug=False, startOfInstruction=False, endOfLine=False} +bothTokenTypeOptions = AssemblyOptions {tokenType=BothTokenType , debug=False , startOfInstruction=False , endOfLine=False} visibleTokenTypeOptions :: AssemblyOptions -visibleTokenTypeOptions = AssemblyOptions {tokenType=VisibleTokenType, debug=False, startOfInstruction=False, endOfLine=False} +visibleTokenTypeOptions = AssemblyOptions {tokenType=VisibleTokenType , debug=False , startOfInstruction=False , endOfLine=False} debugOptions :: AssemblyOptions -debugOptions = AssemblyOptions {tokenType=VisibleTokenType, debug=True, startOfInstruction=False, endOfLine=False} +debugOptions = AssemblyOptions {tokenType=VisibleTokenType , debug=True , startOfInstruction=False , endOfLine=False} soiOptions :: AssemblyOptions -soiOptions = AssemblyOptions {tokenType=VisibleTokenType, debug=False, startOfInstruction=True, endOfLine=False} +soiOptions = AssemblyOptions {tokenType=VisibleTokenType , debug=False , startOfInstruction=True , endOfLine=False} eolOptions :: AssemblyOptions -eolOptions = AssemblyOptions {tokenType=VisibleTokenType, debug=False, startOfInstruction=False, endOfLine=True} +eolOptions = AssemblyOptions {tokenType=VisibleTokenType , debug=False , startOfInstruction=False , endOfLine=True} dsoiOptions :: AssemblyOptions -dsoiOptions = AssemblyOptions {tokenType=VisibleTokenType, debug=True, startOfInstruction=True, endOfLine=False} +dsoiOptions = AssemblyOptions {tokenType=VisibleTokenType , debug=True , startOfInstruction=True , endOfLine=False} deolOptions :: AssemblyOptions -deolOptions = AssemblyOptions {tokenType=VisibleTokenType, debug=True, startOfInstruction=False, endOfLine=True} +deolOptions = AssemblyOptions {tokenType=VisibleTokenType , debug=True , startOfInstruction=False , endOfLine=True} allTrue :: AssemblyOptions -allTrue = AssemblyOptions {tokenType=VisibleTokenType, debug=True, startOfInstruction=True, endOfLine=True} +allTrue = AssemblyOptions {tokenType=VisibleTokenType , debug=True , startOfInstruction=True , endOfLine=True} allFalse :: AssemblyOptions -allFalse = AssemblyOptions {tokenType=WhiteTokenType, debug=False, startOfInstruction=False, endOfLine=False} +allFalse = AssemblyOptions {tokenType=WhiteTokenType , debug=False , startOfInstruction=False , endOfLine=False} data AssemblyOptions = AssemblyOptions - { tokenType :: TokenType - , debug :: Bool - , startOfInstruction :: Bool - , endOfLine :: Bool + { tokenType :: !TokenType + , debug :: !Bool + , startOfInstruction :: !Bool + , endOfLine :: !Bool } diff --git a/hs/src/HelVM/HelPA/Assembler/IO/BusinessIO.hs b/hs/src/HelVM/HelPA/Assembler/IO/BusinessIO.hs new file mode 100644 index 00000000..ac6c24e9 --- /dev/null +++ b/hs/src/HelVM/HelPA/Assembler/IO/BusinessIO.hs @@ -0,0 +1,18 @@ +module HelVM.HelPA.Assembler.IO.BusinessIO ( + BIO, + BusinessIO, + wReadFile, +) where + +import HelVM.Common.Safe + +type BIO m = (MonadSafeError m , BusinessIO m) + +class Monad m => BusinessIO m where + wReadFile :: FilePath -> m Text + +instance BusinessIO IO where + wReadFile = readFileText + +instance BusinessIO (SafeExceptT IO) where + wReadFile = safeExceptT . readFileText diff --git a/hs/src/HelVM/HelPA/Assembler/IO/WrapperIO.hs b/hs/src/HelVM/HelPA/Assembler/IO/WrapperIO.hs deleted file mode 100644 index e448ba7e..00000000 --- a/hs/src/HelVM/HelPA/Assembler/IO/WrapperIO.hs +++ /dev/null @@ -1,10 +0,0 @@ -module HelVM.HelPA.Assembler.IO.WrapperIO ( - wReadFile, - WrapperIO, -) where - -class Monad m => WrapperIO m where - wReadFile :: FilePath -> m Text - -instance WrapperIO IO where - wReadFile = readFileText diff --git a/hs/src/HelVM/HelPA/Assembler/Value.hs b/hs/src/HelVM/HelPA/Assembler/Value.hs index 97b98418..2914ea79 100644 --- a/hs/src/HelVM/HelPA/Assembler/Value.hs +++ b/hs/src/HelVM/HelPA/Assembler/Value.hs @@ -1,7 +1,7 @@ module HelVM.HelPA.Assembler.Value where -data Value a = Literal a | Variable Identifier - deriving stock (Eq, Show, Ord) +data Value a = Literal !a | Variable !Identifier + deriving stock (Eq , Show , Ord) type NaturalValue = Value Natural diff --git a/hs/src/HelVM/HelPA/Assemblers/EAS/AsmParser.hs b/hs/src/HelVM/HelPA/Assemblers/EAS/AsmParser.hs index 330ba0fb..c758e79d 100644 --- a/hs/src/HelVM/HelPA/Assemblers/EAS/AsmParser.hs +++ b/hs/src/HelVM/HelPA/Assemblers/EAS/AsmParser.hs @@ -1,5 +1,5 @@ module HelVM.HelPA.Assemblers.EAS.AsmParser ( - parseAssemblyText + parseAssemblyText, ) where import HelVM.HelPA.Assemblers.EAS.Instruction @@ -9,11 +9,11 @@ import HelVM.HelPA.Assembler.Value import HelVM.Common.Safe -import Data.Attoparsec.Text hiding (I, D) +import Data.Attoparsec.Text hiding (I , D) import Data.Char -parseAssemblyText :: Text -> Safe InstructionList -parseAssemblyText code = safeLegacyToSafe $ parseOnly (instructionListParser <* endOfInput) code +parseAssemblyText :: MonadSafeError m => Text -> m InstructionList +parseAssemblyText = liftEitherLegacy . parseOnly (instructionListParser <* endOfInput) instructionListParser :: Parser InstructionList instructionListParser = skipManyComment *> skipHorizontalSpace *> many (instructionParser <* skipHorizontalSpace) diff --git a/hs/src/HelVM/HelPA/Assemblers/EAS/Assembler.hs b/hs/src/HelVM/HelPA/Assemblers/EAS/Assembler.hs index 76cfca51..484a823b 100644 --- a/hs/src/HelVM/HelPA/Assemblers/EAS/Assembler.hs +++ b/hs/src/HelVM/HelPA/Assemblers/EAS/Assembler.hs @@ -8,17 +8,12 @@ import HelVM.HelPA.Assemblers.EAS.CodeGenerator import HelVM.HelPA.Assemblers.EAS.Linker import HelVM.HelPA.Assembler.API -import HelVM.HelPA.Assembler.IO.WrapperIO +import HelVM.HelPA.Assembler.IO.BusinessIO import HelVM.Common.Safe -import HelVM.Common.SafeMonadT -assembleFile :: WrapperIO m => SourcePath -> SafeFail m Text -assembleFile = runExceptT . exceptTAssembleFile +assembleFile :: BIO m => SourcePath -> m Text +assembleFile sourcePath = reduceAndGenerateCode =<< linkApp sourcePath -exceptTAssembleFile :: WrapperIO m => SourcePath -> SafeMonadT m Text -exceptTAssembleFile sourcePath = exceptTAssembleFile' =<< exceptTLinkApp sourcePath where - exceptTAssembleFile' code = hoistSafe $ reduceAndGenerateCode code - -assembleText :: Text -> Safe Text +assembleText :: MonadSafeError m => Text -> m Text assembleText code = reduceAndGenerateCode =<< parseAssemblyText code diff --git a/hs/src/HelVM/HelPA/Assemblers/EAS/CodeGenerator.hs b/hs/src/HelVM/HelPA/Assemblers/EAS/CodeGenerator.hs index 9c55690d..e62987d2 100644 --- a/hs/src/HelVM/HelPA/Assemblers/EAS/CodeGenerator.hs +++ b/hs/src/HelVM/HelPA/Assemblers/EAS/CodeGenerator.hs @@ -14,26 +14,26 @@ import HelVM.Common.Digit.Digits import HelVM.Common.Containers.Lookup import HelVM.Common.Safe -reduceAndGenerateCode :: InstructionList -> Safe Text -reduceAndGenerateCode il = generateCode <$> reduce il +reduceAndGenerateCode :: MonadSafeError m => InstructionList -> m Text +reduceAndGenerateCode il = generateCode =<< reduce il -generateCode :: InstructionList -> Text -generateCode il = mconcat $ unsafe $ sequenceA $ generateCode' <$> il +generateCode :: MonadSafeError m => InstructionList -> m Text +generateCode il = mconcat <$> sequenceA (generateCode' <$> il) -generateCode' :: Instruction -> Safe Text +generateCode' :: MonadSafeError m => Instruction -> m Text generateCode' (N (Literal n)) = generateNatural <$> naturalToDigitText n where generateNatural t = "N" <> t <> "e" -generateCode' (N (Variable i)) = safeError $ show i -generateCode' (D i) = safeError $ show i -generateCode' (U i) = safeError $ show i -generateCode' (L _) = safe "" -generateCode' R = safe "\n" -generateCode' i = safe $ show i - -naturalToDigitText :: Natural -> Safe Text +generateCode' (N (Variable i)) = liftError $ show i +generateCode' (D i) = liftError $ show i +generateCode' (U i) = liftError $ show i +generateCode' (L _) = pure "" +generateCode' R = pure "\n" +generateCode' i = pure $ show i + +naturalToDigitText :: MonadSafeError m => Natural -> m Text naturalToDigitText value = toText <$> naturalToDigitString value -naturalToDigitString :: Natural -> Safe String +naturalToDigitString :: MonadSafeError m => Natural -> m String naturalToDigitString value = sequenceA $ naturalToDigitChar <$> naturalToDigits7 value -naturalToDigitChar :: Natural -> Safe Char -naturalToDigitChar i = ['h', 't', 'a', 'o', 'i', 'n', 's'] `naturalIndexSafe` i +naturalToDigitChar :: MonadSafeError m => Natural -> m Char +naturalToDigitChar i = liftSafe $ ['h', 't', 'a', 'o', 'i', 'n', 's'] `naturalIndexSafe` i diff --git a/hs/src/HelVM/HelPA/Assemblers/EAS/Instruction.hs b/hs/src/HelVM/HelPA/Assemblers/EAS/Instruction.hs index 58956672..fe2a7500 100644 --- a/hs/src/HelVM/HelPA/Assemblers/EAS/Instruction.hs +++ b/hs/src/HelVM/HelPA/Assemblers/EAS/Instruction.hs @@ -2,11 +2,7 @@ module HelVM.HelPA.Assemblers.EAS.Instruction where import HelVM.HelPA.Assembler.Value -data Instruction = E | T | A | O | I | N NaturalValue | S | H | R | D Identifier | L Identifier | U String - deriving stock (Eq, Show, Ord) +data Instruction = E | T | A | O | I | N !NaturalValue | S | H | R | D !Identifier | L !Identifier | U !String + deriving stock (Eq , Show , Ord) type InstructionList = [Instruction] - -isLabel :: Instruction -> Bool -isLabel (L _) = True -isLabel _ = False diff --git a/hs/src/HelVM/HelPA/Assemblers/EAS/Linker.hs b/hs/src/HelVM/HelPA/Assemblers/EAS/Linker.hs index 379e0f50..bc608473 100644 --- a/hs/src/HelVM/HelPA/Assemblers/EAS/Linker.hs +++ b/hs/src/HelVM/HelPA/Assemblers/EAS/Linker.hs @@ -1,34 +1,24 @@ module HelVM.HelPA.Assemblers.EAS.Linker ( linkLib, - linkApp, - exceptTLinkApp + linkApp ) where import HelVM.HelPA.Assemblers.EAS.AsmParser import HelVM.HelPA.Assemblers.EAS.Instruction import HelVM.HelPA.Assembler.API -import HelVM.HelPA.Assembler.IO.WrapperIO +import HelVM.HelPA.Assembler.IO.BusinessIO import HelVM.HelPA.Assembler.Value -import HelVM.Common.Safe -import HelVM.Common.SafeMonadT +linkLib :: BIO m => SourcePath -> m InstructionList +linkLib sourcePath = linkApp (absolutePath sourcePath) -linkLib :: WrapperIO m => SourcePath -> SafeFail m InstructionList -linkLib = runExceptT . expectTLinkLib +linkApp :: BIO m => SourcePath -> m InstructionList +linkApp sourcePath = (includeLibs (dirPath sourcePath) =<<) $ parseAssemblyText =<< wReadFile (filePath sourcePath) -linkApp :: WrapperIO m => SourcePath -> SafeFail m InstructionList -linkApp = runExceptT . exceptTLinkApp +includeLibs :: BIO m => FilePath -> InstructionList -> m InstructionList +includeLibs dir il = concat <$> mapM (includeLib dir) il -expectTLinkLib :: WrapperIO m => SourcePath -> SafeMonadT m InstructionList -expectTLinkLib = exceptTLinkApp . absolutePath - -exceptTLinkApp :: WrapperIO m => SourcePath -> SafeMonadT m InstructionList -exceptTLinkApp path = (exceptTIncludeLibs (dirPath path) =<<) $ ExceptT $ parseAssemblyText <$> wReadFile (filePath path) - -exceptTIncludeLibs :: WrapperIO m => String -> InstructionList -> SafeMonadT m InstructionList -exceptTIncludeLibs dir il = concat <$> mapM (exceptTIncludeLib dir) il - -exceptTIncludeLib :: WrapperIO m => String -> Instruction -> SafeMonadT m InstructionList -exceptTIncludeLib dir (D libName) = expectTLinkLib SourcePath { dirPath = dir, filePath = unwrapIdentifier libName } -exceptTIncludeLib _ i = pure [i] +includeLib :: BIO m => FilePath -> Instruction -> m InstructionList +includeLib dir (D libName) = linkLib SourcePath { dirPath = dir , filePath = unwrapIdentifier libName } +includeLib _ i = pure [i] diff --git a/hs/src/HelVM/HelPA/Assemblers/EAS/Reducer.hs b/hs/src/HelVM/HelPA/Assemblers/EAS/Reducer.hs index 27a256c9..5f2a350b 100644 --- a/hs/src/HelVM/HelPA/Assemblers/EAS/Reducer.hs +++ b/hs/src/HelVM/HelPA/Assemblers/EAS/Reducer.hs @@ -12,7 +12,7 @@ import HelVM.Common.Safe import Data.List.Split -reduce :: InstructionList -> Safe InstructionList +reduce :: MonadSafeError m => InstructionList -> m InstructionList reduce il = replaceStrings <$> replaceLabels addresses il where addresses = addressOfLabels il ---- @@ -20,26 +20,26 @@ reduce il = replaceStrings <$> replaceLabels addresses il where addresses = addr type LabelAddresses = Map Identifier Natural addressOfLabels :: InstructionList -> LabelAddresses -addressOfLabels il = fromList $ setDefault =<< zip (labelsToStrings2 il) [1..] +addressOfLabels il = fromList $ setDefault =<< zip (labelsToIdentifiers2 il) [1..] -labelsToStrings2 :: InstructionList -> [[Identifier]] -labelsToStrings2 il = labelsToStrings <$> splitOn [R] il +labelsToIdentifiers2 :: InstructionList -> [[Identifier]] +labelsToIdentifiers2 il = labelsToIdentifiers <$> splitOn [R] il -labelsToStrings :: InstructionList -> [Identifier] -labelsToStrings il = labelToStrings =<< il +labelsToIdentifiers :: InstructionList -> [Identifier] +labelsToIdentifiers il = labelToIdentifiers =<< il -labelToStrings :: Instruction -> [Identifier] -labelToStrings (L s) = [s] -labelToStrings _ = [] +labelToIdentifiers :: Instruction -> [Identifier] +labelToIdentifiers (L s) = [s] +labelToIdentifiers _ = [] ---- -replaceLabels :: LabelAddresses -> InstructionList -> Safe InstructionList +replaceLabels :: MonadSafeError m => LabelAddresses -> InstructionList -> m InstructionList replaceLabels addresses il = sequenceA $ replaceLabel addresses <$> il -replaceLabel :: LabelAddresses -> Instruction -> Safe Instruction +replaceLabel :: MonadSafeError m => LabelAddresses -> Instruction -> m Instruction replaceLabel addresses (N (Variable l)) = N . Literal <$> indexSafeByKey l addresses -replaceLabel _ i = safe i +replaceLabel _ i = pure i ---- @@ -55,5 +55,5 @@ charToInstruction = N . Literal . fromIntegral . ord ---- -setDefault :: ([k], v) -> [(k, v)] -setDefault (keys, value) = (, value) <$> keys +setDefault :: ([k] , v) -> [(k , v)] +setDefault (keys , value) = (, value) <$> keys diff --git a/hs/src/HelVM/HelPA/Assemblers/WSA/AsmParser.hs b/hs/src/HelVM/HelPA/Assemblers/WSA/AsmParser.hs index a1c348c3..3c3fc962 100644 --- a/hs/src/HelVM/HelPA/Assemblers/WSA/AsmParser.hs +++ b/hs/src/HelVM/HelPA/Assemblers/WSA/AsmParser.hs @@ -1,5 +1,5 @@ module HelVM.HelPA.Assemblers.WSA.AsmParser ( - parseAssemblyText + parseAssemblyText, ) where import HelVM.HelPA.Assemblers.WSA.Instruction @@ -9,16 +9,17 @@ import HelVM.HelPA.Assembler.Value import HelVM.Common.Safe -import Data.Attoparsec.Text hiding (I, D) +import Control.Type.Operator +import Data.Attoparsec.Text hiding (I , D) import Data.Char -parseAssemblyText :: Text -> Safe InstructionList -parseAssemblyText code = safeLegacyToSafe $ parseOnly (instructionListParser <*skipSpace <* endOfInput) code +parseAssemblyText :: MonadSafeError m => Text -> m InstructionList +parseAssemblyText = liftEitherLegacy . parseOnly (instructionListParser <*skipSpace <* endOfInput) instructionListParser :: Parser InstructionList instructionListParser = catMaybes <$> many maybeInstructionParser -maybeInstructionParser :: Parser (Maybe Instruction) +maybeInstructionParser :: Parser $ Maybe Instruction maybeInstructionParser = Just <$> (skipSpace *> instructionParser) <|> (Nothing <$ (skipSpace *> skipComment)) diff --git a/hs/src/HelVM/HelPA/Assemblers/WSA/Assembler.hs b/hs/src/HelVM/HelPA/Assemblers/WSA/Assembler.hs index fa603d50..aede15c7 100644 --- a/hs/src/HelVM/HelPA/Assemblers/WSA/Assembler.hs +++ b/hs/src/HelVM/HelPA/Assemblers/WSA/Assembler.hs @@ -10,16 +10,12 @@ import HelVM.HelPA.Assemblers.WSA.Linker import HelVM.HelPA.Assembler.API import HelVM.HelPA.Assembler.AssemblyOptions -import HelVM.HelPA.Assembler.IO.WrapperIO +import HelVM.HelPA.Assembler.IO.BusinessIO import HelVM.Common.Safe -import HelVM.Common.SafeMonadT -assembleFile :: WrapperIO m => SourcePath -> AssemblyOptions -> SafeFail m Text -assembleFile sourcePath = runExceptT . exceptTAssembleFile sourcePath +assembleFile :: BIO m => SourcePath -> AssemblyOptions -> m Text +assembleFile sourcePath options = reduceAndGenerateCode options =<< exceptTLinkApp sourcePath -exceptTAssembleFile :: WrapperIO m => SourcePath -> AssemblyOptions -> SafeMonadT m Text -exceptTAssembleFile sourcePath options = (hoistSafe . reduceAndGenerateCode options) =<< exceptTLinkApp sourcePath - -assembleText :: Text -> AssemblyOptions -> Safe Text +assembleText :: MonadSafeError m => Text -> AssemblyOptions -> m Text assembleText code options = reduceAndGenerateCode options =<< parseAssemblyText code diff --git a/hs/src/HelVM/HelPA/Assemblers/WSA/CodeGenerator.hs b/hs/src/HelVM/HelPA/Assemblers/WSA/CodeGenerator.hs index 37d02023..2606d540 100644 --- a/hs/src/HelVM/HelPA/Assemblers/WSA/CodeGenerator.hs +++ b/hs/src/HelVM/HelPA/Assemblers/WSA/CodeGenerator.hs @@ -17,23 +17,23 @@ import HelVM.Common.Digit.Digitable import HelVM.Common.Digit.Digits import HelVM.Common.Safe -reduceAndGenerateCode :: AssemblyOptions -> InstructionList -> Safe Text +reduceAndGenerateCode :: MonadSafeError m => AssemblyOptions -> InstructionList -> m Text reduceAndGenerateCode options il = generateCode (tokenType options) (startOfInstruction options) (debug options) $ reduce (endOfLine options) il -generateCode :: TokenType -> Bool -> Bool -> InstructionList -> Safe Text +generateCode :: MonadSafeError m => TokenType -> Bool -> Bool -> InstructionList -> m Text generateCode tokenType startOfInstruction debug il = showTLByType tokenType <$> generateTL startOfInstruction debug il -generateTL :: Bool -> Bool -> InstructionList -> Safe TokenList +generateTL :: MonadSafeError m => Bool -> Bool -> InstructionList -> m TokenList generateTL startOfInstruction debug il = join <$> sequenceA (generateTLForInstruction startOfInstruction debug <$> il) -generateTLForInstruction :: Bool -> Bool -> Instruction -> Safe TokenList +generateTLForInstruction :: MonadSafeError m => Bool -> Bool -> Instruction -> m TokenList generateTLForInstruction _ _ EOL = pure [R] generateTLForInstruction True debug i = ([E] <>) <$> generateTLForInstruction' debug i generateTLForInstruction _ debug i = generateTLForInstruction' debug i -generateTLForInstruction' :: Bool -> Instruction -> Safe TokenList +generateTLForInstruction' :: MonadSafeError m => Bool -> Instruction -> m TokenList -- Stack instructions -generateTLForInstruction' _ (Push (Literal value)) = pure $ [S,S] <> valueToTL value +generateTLForInstruction' _ (Push (Literal value)) = ([S,S] <>) <$> valueToTL value generateTLForInstruction' _ Dup = pure [S,N,S] generateTLForInstruction' _ Swap = pure [S,N,T] generateTLForInstruction' _ Pop = pure [S,N,N] @@ -47,11 +47,11 @@ generateTLForInstruction' _ (Mod Nothing) = pure [T,S,T,T] generateTLForInstruction' _ (Store Nothing) = pure [T,T,S] generateTLForInstruction' _ (Load Nothing) = pure [T,T,T] -- Control -generateTLForInstruction' _ (Mark label) = pure $ [N,S,S] <> identifierToTL label -generateTLForInstruction' _ (Call label) = pure $ [N,S,T] <> identifierToTL label -generateTLForInstruction' _ (Branch label) = pure $ [N,S,N] <> identifierToTL label -generateTLForInstruction' _ (BranchZ label) = pure $ [N,T,S] <> identifierToTL label -generateTLForInstruction' _ (BranchM label) = pure $ [N,T,T] <> identifierToTL label +generateTLForInstruction' _ (Mark label) = ([N,S,S] <>) <$> identifierToTL label +generateTLForInstruction' _ (Call label) = ([N,S,T] <> ) <$> identifierToTL label +generateTLForInstruction' _ (Branch label) = ([N,S,N] <> ) <$> identifierToTL label +generateTLForInstruction' _ (BranchZ label) = ([N,T,S] <> ) <$> identifierToTL label +generateTLForInstruction' _ (BranchM label) = ([N,T,T] <> ) <$>identifierToTL label generateTLForInstruction' _ Return = pure [N,T,N] generateTLForInstruction' _ End = pure [N,N,N] -- IO instructions @@ -65,24 +65,24 @@ generateTLForInstruction' True DebugPrintStack = pure [N,N,S,S,S] generateTLForInstruction' True DebugPrintHeap = pure [N,N,S,S,T] generateTLForInstruction' False DebugPrintStack = pure [] generateTLForInstruction' False DebugPrintHeap = pure [] -generateTLForInstruction' _ i = safeErrorTuple ("Can not handle instruction" , show i) +generateTLForInstruction' _ i = liftErrorTuple ("Can not handle instruction" , show i) -valueToTL :: Integer -> TokenList -valueToTL value = integerToTL value <> [N] +valueToTL :: MonadSafeError m => Integer -> m TokenList +valueToTL value = integerToTL value <&> (<> [N]) -integerToTL :: Integer -> TokenList +integerToTL :: MonadSafeError m => Integer -> m TokenList integerToTL value - | 0 <= value = S : naturalToTL (fromIntegral value) - | otherwise = T : naturalToTL (fromIntegral (- value)) + | 0 <= value = (S : ) <$> naturalToTL (fromIntegral value) + | otherwise = (T : ) <$> naturalToTL (fromIntegral (- value)) -naturalToTL :: Natural -> TokenList -naturalToTL v = unsafe $ sequenceA $ fromDigit <$> naturalToDigits2 v +naturalToTL :: MonadSafeError m => Natural -> m TokenList +naturalToTL v = liftSafe $ sequenceA $ fromDigit <$> naturalToDigits2 v -identifierToTL :: Identifier -> TokenList -identifierToTL v = (charToTL =<< unwrapIdentifier v) <> [N] +identifierToTL :: MonadSafeError m => Identifier -> m TokenList +identifierToTL v = (join <$> sequenceA (charToTL <$> unwrapIdentifier v)) <&> (<> [N]) -charToTL :: Char -> TokenList -charToTL v = unsafe $ sequenceA $ fromDigit <$> toBits8 (ord v `mod` 256) +charToTL :: MonadSafeError m => Char -> m TokenList +charToTL v = sequenceA $ fromDigit <$> toBits8 (ord v `mod` 256) toBits8 :: Int -> [Natural] toBits8 = toBitsBySize 8 diff --git a/hs/src/HelVM/HelPA/Assemblers/WSA/Instruction.hs b/hs/src/HelVM/HelPA/Assemblers/WSA/Instruction.hs index 57d746c7..881a27db 100644 --- a/hs/src/HelVM/HelPA/Assemblers/WSA/Instruction.hs +++ b/hs/src/HelVM/HelPA/Assemblers/WSA/Instruction.hs @@ -4,30 +4,30 @@ import HelVM.HelPA.Assembler.Value data Instruction = -- Stack instructions - Push IntegerValue - | PushS StringValue + Push !IntegerValue + | PushS !StringValue | Pop | Dup | Swap --Arithmetic - | Add (Maybe IntegerValue) - | Sub (Maybe IntegerValue) - | Mul (Maybe IntegerValue) - | Div (Maybe IntegerValue) - | Mod (Maybe IntegerValue) + | Add !(Maybe IntegerValue) + | Sub !(Maybe IntegerValue) + | Mul !(Maybe IntegerValue) + | Div !(Maybe IntegerValue) + | Mod !(Maybe IntegerValue) -- Heap access - | Store (Maybe IntegerValue) - | Load (Maybe IntegerValue) + | Store !(Maybe IntegerValue) + | Load !(Maybe IntegerValue) -- Control - | Mark Identifier - | Call Identifier - | Branch Identifier - | BranchZ Identifier - | BranchM Identifier - | BranchP Identifier - | BranchNP Identifier - | BranchNM Identifier - | BranchNZ Identifier + | Mark !Identifier + | Call !Identifier + | Branch !Identifier + | BranchZ !Identifier + | BranchM !Identifier + | BranchP !Identifier + | BranchNP !Identifier + | BranchNM !Identifier + | BranchNZ !Identifier | Return | End -- IO instructions @@ -40,15 +40,15 @@ data Instruction = | DebugPrintStack | DebugPrintHeap -- Pseudo instructions - | Include Identifier - | Test Integer - | ValueString Identifier String - | ValueInteger Identifier Natural - | IfOption Identifier + | Include !Identifier + | Test !Integer + | ValueString !Identifier !String + | ValueInteger !Identifier !Natural + | IfOption !Identifier | ElseOption | EndOption - | ElseIfOption Identifier + | ElseIfOption !Identifier | EOL - deriving stock (Eq, Show, Ord) + deriving stock (Eq , Show , Ord) type InstructionList = [Instruction] diff --git a/hs/src/HelVM/HelPA/Assemblers/WSA/Linker.hs b/hs/src/HelVM/HelPA/Assemblers/WSA/Linker.hs index 2bc299fb..ed0ae745 100644 --- a/hs/src/HelVM/HelPA/Assemblers/WSA/Linker.hs +++ b/hs/src/HelVM/HelPA/Assemblers/WSA/Linker.hs @@ -6,31 +6,30 @@ import HelVM.HelPA.Assemblers.WSA.Instruction import HelVM.HelPA.Assembler.API import HelVM.HelPA.Assembler.Value -import HelVM.HelPA.Assembler.IO.WrapperIO +import HelVM.HelPA.Assembler.IO.BusinessIO -import HelVM.Common.Safe -import HelVM.Common.SafeMonadT +import Control.Type.Operator -linkLib :: WrapperIO m => SourcePath -> SafeFail m InstructionList -linkLib = runExceptT . expectTLinkLib +linkLib :: BIO m => SourcePath -> m InstructionList +linkLib = expectTLinkLib -linkApp :: WrapperIO m => SourcePath -> SafeFail m InstructionList -linkApp = runExceptT . exceptTLinkApp +linkApp :: BIO m => SourcePath -> m InstructionList +linkApp = exceptTLinkApp -expectTLinkLib :: WrapperIO m => SourcePath -> SafeMonadT m InstructionList +expectTLinkLib :: BIO m => SourcePath -> m InstructionList expectTLinkLib = exceptTLinkApp . absolutePath -exceptTLinkApp :: WrapperIO m => SourcePath -> SafeMonadT m InstructionList -exceptTLinkApp path = (exceptTIncludeLibs (dirPath path) =<<) $ ExceptT $ parseAssemblyText <$> wReadFile (filePath path) +exceptTLinkApp :: BIO m => SourcePath -> m InstructionList +exceptTLinkApp path = (exceptTIncludeLibs (dirPath path) =<<) $ parseAssemblyText =<< wReadFile (filePath path) -exceptTIncludeLibs :: WrapperIO m => String -> InstructionList -> SafeMonadT m InstructionList +exceptTIncludeLibs :: BIO m => FilePath -> InstructionList -> m InstructionList exceptTIncludeLibs dir il = sortBlocks <$> mapM (exceptTIncludeLib dir) il sortBlocks :: [Block InstructionList] -> InstructionList -sortBlocks list = unwrap =<< (filter isNormal list <> filter isIncluded list) +sortBlocks list = unwrap =<< (filter isNormal list <> filter isIncluded list) --FIXME groupBy ? -exceptTIncludeLib :: WrapperIO m => String -> Instruction -> SafeMonadT m (Block InstructionList) -exceptTIncludeLib dir (Include libName) = Included <$> expectTLinkLib (SourcePath {dirPath = dir, filePath = unwrapIdentifier libName <> ".wsa"}) +exceptTIncludeLib :: BIO m => FilePath -> Instruction -> m $ Block InstructionList +exceptTIncludeLib dir (Include libName) = Included <$> expectTLinkLib (SourcePath {dirPath = dir , filePath = unwrapIdentifier libName <> ".wsa"}) exceptTIncludeLib _ i = pure $ Normal [i] unwrap :: Block a -> a @@ -45,4 +44,4 @@ isIncluded :: Block a -> Bool isIncluded (Normal _) = False isIncluded (Included _) = True -data Block a = Normal a | Included a +data Block a = Normal !a | Included !a diff --git a/hs/src/HelVM/HelPA/Assemblers/WSA/Reducer.hs b/hs/src/HelVM/HelPA/Assemblers/WSA/Reducer.hs index db3d3f86..627725f3 100644 --- a/hs/src/HelVM/HelPA/Assemblers/WSA/Reducer.hs +++ b/hs/src/HelVM/HelPA/Assemblers/WSA/Reducer.hs @@ -9,32 +9,32 @@ reduce True il = reduceInstruction =<< addEndOfLine =<< il reduce False il = reduceInstruction =<< il addEndOfLine :: Instruction -> InstructionList -addEndOfLine i = [i, EOL] +addEndOfLine i = [i , EOL] reduceInstruction :: Instruction -> InstructionList reduceInstruction (PushS (Literal [])) = [Push (Literal 0)] reduceInstruction (PushS (Literal (x:xs))) = reduceInstruction (PushS (Literal xs)) <> [Push (Literal (fromIntegral (ord x)))] -reduceInstruction (Test v) = [Dup, Push (Literal v), Sub Nothing] -reduceInstruction (Load (Just v)) = [Push v, Load Nothing] -reduceInstruction (Store (Just v)) = [Push v, Swap, Store Nothing] +reduceInstruction (Test v) = [Dup , Push (Literal v), Sub Nothing] +reduceInstruction (Load (Just v)) = [Push v , Load Nothing] +reduceInstruction (Store (Just v)) = [Push v , Swap , Store Nothing] -reduceInstruction (Add (Just v)) = [Push v, Add Nothing] -reduceInstruction (Sub (Just v)) = [Push v, Sub Nothing] -reduceInstruction (Mul (Just v)) = [Push v, Mul Nothing] -reduceInstruction (Div (Just v)) = [Push v, Div Nothing] -reduceInstruction (Mod (Just v)) = [Push v, Mod Nothing] +reduceInstruction (Add (Just v)) = [Push v , Add Nothing] +reduceInstruction (Sub (Just v)) = [Push v , Sub Nothing] +reduceInstruction (Mul (Just v)) = [Push v , Mul Nothing] +reduceInstruction (Div (Just v)) = [Push v , Div Nothing] +reduceInstruction (Mod (Just v)) = [Push v , Mod Nothing] -reduceInstruction (BranchNZ l) = [BranchZ l1, Branch l, Mark l1] where +reduceInstruction (BranchNZ l) = [BranchZ l1 , Branch l , Mark l1] where l1 = calculateLocalLabel l 1 -reduceInstruction (BranchNM l) = [BranchM l1, Branch l, Mark l1] where +reduceInstruction (BranchNM l) = [BranchM l1 , Branch l , Mark l1] where l1 = calculateLocalLabel l 1 -reduceInstruction (BranchP l) = [Dup, BranchM l1, Dup, BranchZ l1, Pop, Branch l, Mark l1, Pop] where +reduceInstruction (BranchP l) = [Dup , BranchM l1 , Dup , BranchZ l1 , Pop , Branch l , Mark l1 , Pop] where l1 = calculateLocalLabel l 1 -reduceInstruction (BranchNP l) = [Dup, BranchM l1, Dup, BranchZ l1, Branch l2, Mark l1, Pop, Branch l, Mark l2, Pop] where +reduceInstruction (BranchNP l) = [Dup , BranchM l1 , Dup , BranchZ l1 , Branch l2 , Mark l1 , Pop , Branch l , Mark l2 , Pop] where l1 = calculateLocalLabel l 1 l2 = calculateLocalLabel l 2 diff --git a/hs/src/HelVM/HelPA/Assemblers/WSA/Token.hs b/hs/src/HelVM/HelPA/Assemblers/WSA/Token.hs index d64bf58d..2af2ad16 100644 --- a/hs/src/HelVM/HelPA/Assemblers/WSA/Token.hs +++ b/hs/src/HelVM/HelPA/Assemblers/WSA/Token.hs @@ -36,7 +36,7 @@ toBTL = map BothToken type TokenList = [Token] data Token = S | T | N | E | R - deriving stock (Eq, Ord, Enum, Read) + deriving stock (Eq , Ord , Enum , Read) instance Show Token where show S = "S" @@ -46,20 +46,20 @@ instance Show Token where show R = "\n" instance ToDigit Token where - toDigit S = safe 0 - toDigit T = safe 1 - toDigit t = safeError $ show t + toDigit S = pure 0 + toDigit T = pure 1 + toDigit t = liftError $ show t instance Digitable Token where - fromDigit 0 = safe S - fromDigit 1 = safe T - fromDigit t = safeError $ show t + fromDigit 0 = pure S + fromDigit 1 = pure T + fromDigit t = liftError $ show t ---- type WhiteTokenList = [WhiteToken] -newtype WhiteToken = WhiteToken Token +newtype WhiteToken = WhiteToken { unWhiteToken :: Token } deriving stock (Eq) instance Show WhiteToken where @@ -79,7 +79,7 @@ instance Read WhiteToken where type BothTokenList = [BothToken] -newtype BothToken = BothToken Token +newtype BothToken = BothToken { unBothToken :: Token } deriving stock (Eq) instance Show BothToken where diff --git a/hs/test/HelVM/CartesianProduct.hs b/hs/test/HelVM/CartesianProduct.hs index 714942a4..496abb44 100644 --- a/hs/test/HelVM/CartesianProduct.hs +++ b/hs/test/HelVM/CartesianProduct.hs @@ -12,6 +12,10 @@ infixr 9 |><< (|><<) :: [a1] -> [(b1 , b2)] -> [(a1 , b1 , b2)] (|><<) = liftA2 (\a1 (b1 , b2) -> (a1 , b1 , b2)) +infixr 9 |><<< +(|><<<) :: [a1] -> [(b1 , b2 , b3)] -> [(a1 , b1 , b2 , b3)] +(|><<<) = liftA2 (\a1 (b1 , b2 , b3) -> (a1 , b1 , b2 , b3)) + infixr 9 >><< (>><<) :: [(a1 , a2)] -> [(b1 , b2)] -> [(a1 , a2 , b1 , b2)] (>><<) = liftA2 (\(a1 , a2) (b1 , b2) -> (a1 , a2 , b1 , b2)) diff --git a/hs/test/HelVM/Expectations.hs b/hs/test/HelVM/Expectations.hs index 2e572899..b188ff66 100644 --- a/hs/test/HelVM/Expectations.hs +++ b/hs/test/HelVM/Expectations.hs @@ -1,82 +1,38 @@ -{-# LANGUAGE UndecidableInstances #-} module HelVM.Expectations ( - goldenShouldSafe, - goldenShouldSafeReturn, - goldenShouldReturn, - goldenShouldBe, ioShouldSafe, - shouldSafe, ioShouldBe, - shouldSafeReturn, + shouldSafeExceptT, + shouldSafeIO, + shouldSafe, shouldBeDo, ) where import HelVM.Common.Safe -import HelVM.Common.Util - -import System.FilePath.Posix - -import Test.Hspec -import Test.Hspec.Attoparsec -import Test.Hspec.Golden -import Test.Hspec.Core.Spec - -infix 1 `goldenShouldSafe` -goldenShouldSafe :: (Typeable a , Show a) => Safe a -> FilePath -> WrappedGoldenIO Text -goldenShouldSafe actualOutput = goldenShouldReturn (safeToFail actualOutput) -infix 1 `goldenShouldSafeReturn` -goldenShouldSafeReturn :: (Typeable a , Show a) => SafeFail IO a -> FilePath -> WrappedGoldenIO Text -goldenShouldSafeReturn = goldenShouldReturn . safeFailToFail - -infix 1 `goldenShouldReturn` -goldenShouldReturn :: (Typeable a , Show a) => IO a -> FilePath -> WrappedGoldenIO Text -goldenShouldReturn actualOutput fileName = WrappedGoldenIO $ flip goldenShouldBe fileName <$> actualOutput - -infix 1 `goldenShouldBe` -goldenShouldBe :: (Typeable a , Show a) => a -> FilePath -> Golden Text -goldenShouldBe actualOutput fileName = - Golden { - output = showToText actualOutput, - encodePretty = show, - writeToFile = writeFileText, - readFromFile = readFileText, - goldenFile = ".output" "golden" fileName, - actualFile = Just (".output" "actual" fileName), - failFirstTime = False - } - ----- +import Test.Hspec.Expectations.Pretty infix 1 `ioShouldSafe` -ioShouldSafe :: (Show a , Eq a) => SafeFail IO a -> IO a -> Expectation +ioShouldSafe :: (Show a , Eq a) => IO (Safe a) -> IO a -> Expectation ioShouldSafe action expected = join $ liftA2 shouldSafe action expected -infix 1 `shouldSafe` -shouldSafe :: (Show a , Eq a) => Safe a -> a -> Expectation -shouldSafe action = shouldParse (safeToSafeLegacy action) - infix 1 `ioShouldBe` ioShouldBe :: (HasCallStack , Show a , Eq a) => IO a -> IO a -> Expectation ioShouldBe action expected = join $ liftA2 shouldBe action expected ---- -infix 1 `shouldSafeReturn` -shouldSafeReturn :: (Show a , Eq a) => SafeFail IO a -> a -> Expectation -shouldSafeReturn action = shouldReturn (safeFailToFail action) +infix 1 `shouldSafeExceptT` +shouldSafeExceptT :: (Show a , Eq a) => SafeExceptT IO a -> a -> Expectation +shouldSafeExceptT action = shouldReturn (exceptTToIO action) + +infix 1 `shouldSafeIO` +shouldSafeIO :: (Show a , Eq a) => IO (Safe a) -> a -> Expectation +shouldSafeIO action = shouldReturn (safeIOToIO action) + +infix 1 `shouldSafe` +shouldSafe :: (HasCallStack , Show a , Eq a) => Safe a -> a -> Expectation +shouldSafe action expected = shouldBe action $ pure expected infix 1 `shouldBeDo` shouldBeDo :: (HasCallStack , Show a , Eq a) => a -> IO a -> Expectation shouldBeDo action expected = shouldBe action =<< expected - ----- - -newtype WrappedGoldenIO a = WrappedGoldenIO { unWrappedGoldenIO :: GoldenIO a } - -type GoldenIO a = IO (Golden a) - -instance Eq str => Example (WrappedGoldenIO str) where - type Arg (WrappedGoldenIO str) = () - evaluateExample wrapped params action callback = evaluateExample' =<< unWrappedGoldenIO wrapped where - evaluateExample' golden = evaluateExample golden params action callback diff --git a/hs/test/HelVM/GoldenExpectations.hs b/hs/test/HelVM/GoldenExpectations.hs new file mode 100644 index 00000000..031144d2 --- /dev/null +++ b/hs/test/HelVM/GoldenExpectations.hs @@ -0,0 +1,57 @@ +module HelVM.GoldenExpectations ( + (<->), + goldenShouldSafeExceptT, + goldenShouldSafe, + goldenShouldIO, + goldenShouldBe, +) where + +import HelVM.Common.Safe + +import Control.Type.Operator +import System.FilePath.Posix + +import Test.Hspec.Golden +import Test.Hspec.Core.Spec + +infixl 1 <-> +(<->) :: FilePath -> FilePath -> FilePath +(<->) major minor = major <> "-" <> minor + +infix 1 `goldenShouldSafeExceptT` +goldenShouldSafeExceptT:: SafeExceptT IO Text -> FilePath -> GoldenExpectations Text +goldenShouldSafeExceptT actualOutput = goldenShouldIO (exceptTToIO actualOutput) + +infix 1 `goldenShouldSafe` +goldenShouldSafe :: Safe Text -> FilePath -> GoldenExpectations Text +goldenShouldSafe actualOutputSafe = goldenShouldIO (safeToIO actualOutputSafe) + +infix 1 `goldenShouldIO` +goldenShouldIO :: IO Text -> FilePath -> GoldenExpectations Text +goldenShouldIO actualOutputIO fileName = GoldenExpectations $ flip goldenShouldBe fileName <$> actualOutputIO + +infix 1 `goldenShouldBe` +goldenShouldBe :: Text -> FilePath -> Golden Text +goldenShouldBe actualOutput fileName = + Golden { + output = actualOutput, + encodePretty = show, + writeToFile = writeFileText, + readFromFile = readFileText, + goldenFile = ".output" "golden" fileName, + actualFile = Just (".output" "actual" fileName), + failFirstTime = False + } + +---- + +newtype GoldenExpectations a = GoldenExpectations { unGoldenExpectations :: GoldenIO a } + +type GoldenIO a = IO $ Golden a + +---- + +instance Eq str => Example (GoldenExpectations str) where + type Arg (GoldenExpectations str) = () + evaluateExample wrapped params action callback = evaluateExample' =<< unGoldenExpectations wrapped where + evaluateExample' golden = evaluateExample golden params action callback diff --git a/hs/test/HelVM/HelPA/Assemblers/EAS/AsmParserSpec.hs b/hs/test/HelVM/HelPA/Assemblers/EAS/AsmParserSpec.hs index f673df26..c3d8e84b 100644 --- a/hs/test/HelVM/HelPA/Assemblers/EAS/AsmParserSpec.hs +++ b/hs/test/HelVM/HelPA/Assemblers/EAS/AsmParserSpec.hs @@ -9,7 +9,7 @@ import HelVM.Expectations import HelVM.HelPA.Assembler.Value -import Test.Hspec +import Test.Hspec (Spec , describe , it) spec :: Spec spec = do @@ -32,7 +32,7 @@ spec = do , ("euclid" , euclidIL) ] $ \(fileName , il) -> do let parseAssembly = parseAssemblyText <$> readFileText (buildAbsolutePathToEasFile fileName) - it fileName $ do parseAssembly `shouldSafeReturn` il + it fileName $ do parseAssembly `shouldSafeIO` il describe "empty" $ do it "parse ''" $ do parseAssemblyText "" `shouldSafe` [] @@ -143,8 +143,8 @@ spec = do it "parse 'A N0 T \nA N0 T \n'" $ do parseAssemblyText "A N0 T \nA N0 T \n" `shouldSafe` [A,N (Literal 0),T,R,A,N (Literal 0),T,R] describe "Comments" $ do - it "parse ' A N0 T \n '" $ do parseAssemblyText " A N0 T \n " `shouldSafe` [A, N (Literal 0), T, R] + it "parse ' A N0 T \n '" $ do parseAssemblyText " A N0 T \n " `shouldSafe` [A , N (Literal 0), T , R] it "parse '# A N0 T \n '" $ do parseAssemblyText "# A N0 T \n " `shouldSafe` [] it "parse ' #A N0 T \n '" $ do parseAssemblyText " #A N0 T \n " `shouldSafe` [R] - it "parse ' A# N0 T \n '" $ do parseAssemblyText " A# N0 T \n " `shouldSafe` [A, R] - it "parse ' A #N0 T \n '" $ do parseAssemblyText " A #N0 T \n " `shouldSafe` [A, R] + it "parse ' A# N0 T \n '" $ do parseAssemblyText " A# N0 T \n " `shouldSafe` [A , R] + it "parse ' A #N0 T \n '" $ do parseAssemblyText " A #N0 T \n " `shouldSafe` [A , R] diff --git a/hs/test/HelVM/HelPA/Assemblers/EAS/AssemblerSpec.hs b/hs/test/HelVM/HelPA/Assemblers/EAS/AssemblerSpec.hs index 2d0ef701..6800ad2f 100644 --- a/hs/test/HelVM/HelPA/Assemblers/EAS/AssemblerSpec.hs +++ b/hs/test/HelVM/HelPA/Assemblers/EAS/AssemblerSpec.hs @@ -3,13 +3,13 @@ module HelVM.HelPA.Assemblers.EAS.AssemblerSpec where import HelVM.HelPA.Assemblers.EAS.Assembler import HelVM.HelPA.Assemblers.EAS.FileUtil -import HelVM.Expectations +import HelVM.GoldenExpectations import HelVM.HelPA.Assembler.API import System.FilePath.Posix -import Test.Hspec +import Test.Hspec (Spec , describe , it) spec :: Spec spec = do @@ -35,5 +35,5 @@ spec = do , "bottles3" , "euclid" ] $ \fileName -> do - let assemble = assembleFile SourcePath {dirPath = easDir, filePath = buildAbsolutePathToEasFile fileName} - it fileName $ do assemble `goldenShouldSafeReturn` buildAbsolutePathToEtaFile ("assembleFile" fileName) + let assemble = assembleFile SourcePath {dirPath = easDir , filePath = buildAbsolutePathToEasFile fileName} + it fileName $ do assemble `goldenShouldSafeExceptT` buildAbsolutePathToEtaFile ("assembleFile" fileName) diff --git a/hs/test/HelVM/HelPA/Assemblers/EAS/CodeGeneratorSpec.hs b/hs/test/HelVM/HelPA/Assemblers/EAS/CodeGeneratorSpec.hs index 34ab25ee..deaeef17 100644 --- a/hs/test/HelVM/HelPA/Assemblers/EAS/CodeGeneratorSpec.hs +++ b/hs/test/HelVM/HelPA/Assemblers/EAS/CodeGeneratorSpec.hs @@ -5,10 +5,11 @@ import HelVM.HelPA.Assemblers.EAS.TestData import HelVM.HelPA.Assemblers.EAS.FileUtil import HelVM.Expectations +import HelVM.GoldenExpectations import System.FilePath.Posix -import Test.Hspec +import Test.Hspec (Spec , describe , it) spec :: Spec spec = do @@ -29,7 +30,7 @@ spec = do , ("bottles" , bottlesILReduced) , ("euclid" , euclidILReduced) ] $ \(fileName , ilReduced) -> do - it fileName $ do generateCode ilReduced `goldenShouldBe` buildAbsolutePathToEtaFile ("generateCode" fileName) + it fileName $ do generateCode ilReduced `goldenShouldSafe` buildAbsolutePathToEtaFile ("generateCode" fileName) describe "naturalToDigitString" $ do forM_ [ (0 , "") diff --git a/hs/test/HelVM/HelPA/Assemblers/EAS/LinkerSpec.hs b/hs/test/HelVM/HelPA/Assemblers/EAS/LinkerSpec.hs index d40330e6..183ae288 100644 --- a/hs/test/HelVM/HelPA/Assemblers/EAS/LinkerSpec.hs +++ b/hs/test/HelVM/HelPA/Assemblers/EAS/LinkerSpec.hs @@ -5,11 +5,11 @@ import HelVM.HelPA.Assemblers.EAS.Linker import HelVM.HelPA.Assemblers.EAS.TestData import HelVM.HelPA.Assemblers.EAS.FileUtil -import HelVM.Expectations - import HelVM.HelPA.Assembler.API -import Test.Hspec +import HelVM.Expectations + +import Test.Hspec (Spec , describe , it) spec :: Spec spec = do @@ -32,4 +32,4 @@ spec = do , ("euclid" , euclidIL) ] $ \(fileName , il) -> do let linkFile = linkLib SourcePath {dirPath = "examples/eas/", filePath = buildEasFileName fileName} - it fileName $ do linkFile `shouldSafeReturn` il + it fileName $ do linkFile `shouldSafeExceptT` il diff --git a/hs/test/HelVM/HelPA/Assemblers/EAS/ReducerSpec.hs b/hs/test/HelVM/HelPA/Assemblers/EAS/ReducerSpec.hs index e69a61e3..8eac9028 100644 --- a/hs/test/HelVM/HelPA/Assemblers/EAS/ReducerSpec.hs +++ b/hs/test/HelVM/HelPA/Assemblers/EAS/ReducerSpec.hs @@ -3,9 +3,9 @@ module HelVM.HelPA.Assemblers.EAS.ReducerSpec where import HelVM.HelPA.Assemblers.EAS.Reducer import HelVM.HelPA.Assemblers.EAS.TestData -import HelVM.Common.Safe +import HelVM.Expectations -import Test.Hspec +import Test.Hspec (Spec , describe , it) spec :: Spec spec = do @@ -26,5 +26,5 @@ spec = do , ("fact" , factILLinked , factILReduced) , ("bottles" , bottlesILLinked , bottlesILReduced) , ("euclid" , euclidIL , euclidILReduced) - ] $ \(fileName , ilLinked, ilReduced) -> do - it fileName $ do unsafe (reduce ilLinked) `shouldBe` ilReduced + ] $ \(fileName , ilLinked , ilReduced) -> do + it fileName $ do reduce ilLinked `shouldSafe` ilReduced diff --git a/hs/test/HelVM/HelPA/Assemblers/WSA/AsmParserSpec.hs b/hs/test/HelVM/HelPA/Assemblers/WSA/AsmParserSpec.hs index 6bc070de..c7c5a195 100644 --- a/hs/test/HelVM/HelPA/Assemblers/WSA/AsmParserSpec.hs +++ b/hs/test/HelVM/HelPA/Assemblers/WSA/AsmParserSpec.hs @@ -5,35 +5,37 @@ import HelVM.HelPA.Assemblers.WSA.Instruction import HelVM.HelPA.Assemblers.WSA.TestData import HelVM.HelPA.Assemblers.WSA.FileUtil +import HelVM.Common.Safe + import HelVM.Expectations +import HelVM.GoldenExpectations import HelVM.HelPA.Assembler.Value import System.FilePath.Posix -import Test.Hspec +import Test.Hspec (Spec , describe , it) spec :: Spec spec = do - let parseAssemblyFile = fmap parseAssemblyText . readFileText - - let parseAssemblyLib = \ fileName -> parseAssemblyFile (libDir fileName <.> ext) - let parseAssemblyApp = \ fileName -> parseAssemblyFile (appDir fileName <.> ext) - let parseAssemblyApp1 = \ fileName -> parseAssemblyFile (wsaDir "from-eas" fileName <.> ext) + let parseAssemblyFile fileName = parseAssemblyText <$> readFileText fileName + let parseAssemblyLib fileName = parseAssemblyFile (libDir fileName <.> ext) + let parseAssemblyApp fileName = parseAssemblyFile (appDir fileName <.> ext) + let parseAssemblyEAS fileName = parseAssemblyFile (wsaDir "from-eas" fileName <.> ext) describe "parseAssemblyLib" $ do forM_ [ "io" , "memory" ] $ \fileName -> do it fileName $ do - parseAssemblyLib fileName `goldenShouldSafeReturn` buildAbsolutePathToIlFile ("parseAssemblyLib" fileName) + safeIOToPTextIO (parseAssemblyLib fileName) `goldenShouldIO` buildAbsolutePathToIlFile ("parseAssemblyLib" fileName) describe "parseAssemblyApp" $ do describe "original" $ do forM_ [ "prim" ] $ \fileName -> do it fileName $ do - parseAssemblyApp fileName `goldenShouldSafeReturn` buildAbsolutePathToIlFile ("parseAssemblyApp" "original" fileName) + safeIOToPTextIO (parseAssemblyApp fileName) `goldenShouldIO` buildAbsolutePathToIlFile ("parseAssemblyApp" "original" fileName) describe "from-eas" $ do forM_ [ "true" @@ -55,12 +57,12 @@ spec = do -- , "euclid" ] $ \ fileName -> do it fileName $ do - parseAssemblyApp1 fileName `goldenShouldSafeReturn` buildAbsolutePathToIlFile ("parseAssemblyApp" "from-eas" fileName) + safeIOToPTextIO (parseAssemblyEAS fileName) `goldenShouldIO` buildAbsolutePathToIlFile ("parseAssemblyApp" "from-eas" fileName) describe "parseAssemblyText" $ do - it "io" $ do parseAssemblyLib "io" `shouldSafeReturn` ioIL - it "memory" $ do parseAssemblyLib "memory" `shouldSafeReturn` memoryIL - it "prim" $ do parseAssemblyApp "prim" `shouldSafeReturn` (Include "io" : primIL) + it "io" $ do parseAssemblyLib "io" `shouldSafeIO` ioIL + it "memory" $ do parseAssemblyLib "memory" `shouldSafeIO` memoryIL + it "prim" $ do parseAssemblyApp "prim" `shouldSafeIO` (Include "io" : primIL) describe "Commands without operands" $ do it "parse 'pop'" $ do parseAssemblyText "pop" `shouldSafe` [Pop] diff --git a/hs/test/HelVM/HelPA/Assemblers/WSA/AssemblerSpec.hs b/hs/test/HelVM/HelPA/Assemblers/WSA/AssemblerSpec.hs index dc663eab..98651a22 100644 --- a/hs/test/HelVM/HelPA/Assemblers/WSA/AssemblerSpec.hs +++ b/hs/test/HelVM/HelPA/Assemblers/WSA/AssemblerSpec.hs @@ -3,15 +3,15 @@ module HelVM.HelPA.Assemblers.WSA.AssemblerSpec (spec) where import HelVM.HelPA.Assemblers.WSA.Assembler import HelVM.HelPA.Assemblers.WSA.FileUtil -import HelVM.CartesianProduct -import HelVM.Expectations - import HelVM.HelPA.Assembler.API import HelVM.HelPA.Assembler.AssemblyOptions +import HelVM.CartesianProduct +import HelVM.GoldenExpectations + import System.FilePath.Posix -import Test.Hspec +import Test.Hspec (Spec , describe , it) spec :: Spec spec = do @@ -25,7 +25,7 @@ spec = do let assembleLib = assembleLibFile fileName options let minorPath = name fileName it minorPath $ do - assembleLib `goldenShouldSafeReturn` buildAbsolutePathToWsFile ("assembleLib" minorPath) + assembleLib `goldenShouldSafeExceptT` buildAbsolutePathToWsFile ("assembleLib" minorPath) describe "assembleApp" $ do describe "original" $ do @@ -34,7 +34,7 @@ spec = do let assembleApp = assembleAppFile fileName options let minorPath = name fileName it minorPath $ do - assembleApp `goldenShouldSafeReturn` buildAbsolutePathToWsFile ("assembleApp" "original" minorPath) + assembleApp `goldenShouldSafeExceptT` buildAbsolutePathToWsFile ("assembleApp" "original" minorPath) describe "from-eas" $ do forM_ ([ "true" @@ -58,17 +58,17 @@ spec = do let assemble = assembleFile SourcePath {dirPath = libDir , filePath = wsaDir "from-eas" fileName <.> ext} options let minorPath = name fileName it minorPath $ do - assemble `goldenShouldSafeReturn` buildAbsolutePathToWsFile ("assembleApp" "from-eas" minorPath) + assemble `goldenShouldSafeExceptT` buildAbsolutePathToWsFile ("assembleApp" "from-eas" minorPath) -- describe "assembleFile" $ do --- it "io" $ do assembleLibFile "io" visibleTokenTypeOptions `shouldSafeReturn` showTL ioTL --- it "memory" $ do assembleLibFile "memory" visibleTokenTypeOptions `shouldSafeReturn` showTL memoryTL --- it "prim" $ do assembleAppFile "prim" visibleTokenTypeOptions `shouldSafeReturn` showTL primTL +-- it "io" $ do assembleLibFile "io" visibleTokenTypeOptions `shouldSafeIO` showTL ioTL +-- it "memory" $ do assembleLibFile "memory" visibleTokenTypeOptions `shouldSafeIO` showTL memoryTL +-- it "prim" $ do assembleAppFile "prim" visibleTokenTypeOptions `shouldSafeIO` showTL primTL -- --- it "io" $ do assembleLibFile "io" allFalse `shouldSafeReturn` showTLAsWTL ioTL --- it "memory" $ do assembleLibFile "memory" allFalse `shouldSafeReturn` showTLAsWTL memoryTL --- it "prim" $ do assembleAppFile "prim" allFalse `shouldSafeReturn` showTLAsWTL primTL +-- it "io" $ do assembleLibFile "io" allFalse `shouldSafeIO` showTLAsWTL ioTL +-- it "memory" $ do assembleLibFile "memory" allFalse `shouldSafeIO` showTLAsWTL memoryTL +-- it "prim" $ do assembleAppFile "prim" allFalse `shouldSafeIO` showTLAsWTL primTL -- --- it "io" $ do assembleLibFile "io" bothTokenTypeOptions `shouldSafeReturn` showTLAsBTL ioTL --- it "memory" $ do assembleLibFile "memory" bothTokenTypeOptions `shouldSafeReturn` showTLAsBTL memoryTL --- it "prim" $ do assembleAppFile "prim" bothTokenTypeOptions `shouldSafeReturn` showTLAsBTL primTL +-- it "io" $ do assembleLibFile "io" bothTokenTypeOptions `shouldSafeIO` showTLAsBTL ioTL +-- it "memory" $ do assembleLibFile "memory" bothTokenTypeOptions `shouldSafeIO` showTLAsBTL memoryTL +-- it "prim" $ do assembleAppFile "prim" bothTokenTypeOptions `shouldSafeIO` showTLAsBTL primTL diff --git a/hs/test/HelVM/HelPA/Assemblers/WSA/CodeGeneratorSpec.hs b/hs/test/HelVM/HelPA/Assemblers/WSA/CodeGeneratorSpec.hs index 8be9394e..9510e566 100644 --- a/hs/test/HelVM/HelPA/Assemblers/WSA/CodeGeneratorSpec.hs +++ b/hs/test/HelVM/HelPA/Assemblers/WSA/CodeGeneratorSpec.hs @@ -7,12 +7,13 @@ import HelVM.HelPA.Assemblers.WSA.FileUtil import HelVM.CartesianProduct import HelVM.Expectations +import HelVM.GoldenExpectations import HelVM.HelPA.Assembler.AssemblyOptions import System.FilePath.Posix -import Test.Hspec +import Test.Hspec (Spec , describe , it) spec :: Spec spec = do @@ -20,31 +21,31 @@ spec = do forM_ ([ ("io" , ioILReduced) , ("memory" , memoryILReduced) , ("prim" , primILReduced <> ioILReduced) - ] >><< manyOptionsWithName) $ \(fileName , il, name, options) -> do + ] >><< manyOptionsWithName) $ \(fileName , il , name , options) -> do it (name fileName) $ do reduceAndGenerateCode options il `goldenShouldSafe` buildAbsolutePathToWsFile ("codeGenerator" name fileName) describe "valueToTL" $ do - it "valueToTL 0" $ do valueToTL 0 `shouldBe` [S,N] - it "valueToTL 1" $ do valueToTL 1 `shouldBe` [S,T,N] - it "valueToTL 2" $ do valueToTL 2 `shouldBe` [S,T,S,N] - it "valueToTL 3" $ do valueToTL 3 `shouldBe` [S,T,T,N] - it "valueToTL 4" $ do valueToTL 4 `shouldBe` [S,T,S,S,N] - it "valueToTL 5" $ do valueToTL 5 `shouldBe` [S,T,S,T,N] - it "valueToTL 6" $ do valueToTL 6 `shouldBe` [S,T,T,S,N] - it "valueToTL 7" $ do valueToTL 7 `shouldBe` [S,T,T,T,N] - it "valueToTL -0" $ do valueToTL (-0) `shouldBe` [S,N] - it "valueToTL -1" $ do valueToTL (-1) `shouldBe` [T,T,N] - it "valueToTL -2" $ do valueToTL (-2) `shouldBe` [T,T,S,N] - it "valueToTL -3" $ do valueToTL (-3) `shouldBe` [T,T,T,N] - it "valueToTL -4" $ do valueToTL (-4) `shouldBe` [T,T,S,S,N] - it "valueToTL -5" $ do valueToTL (-5) `shouldBe` [T,T,S,T,N] - it "valueToTL -6" $ do valueToTL (-6) `shouldBe` [T,T,T,S,N] - it "valueToTL -7" $ do valueToTL (-7) `shouldBe` [T,T,T,T,N] + it "valueToTL 0" $ do valueToTL 0 `shouldSafe` [S,N] + it "valueToTL 1" $ do valueToTL 1 `shouldSafe` [S,T,N] + it "valueToTL 2" $ do valueToTL 2 `shouldSafe` [S,T,S,N] + it "valueToTL 3" $ do valueToTL 3 `shouldSafe` [S,T,T,N] + it "valueToTL 4" $ do valueToTL 4 `shouldSafe` [S,T,S,S,N] + it "valueToTL 5" $ do valueToTL 5 `shouldSafe` [S,T,S,T,N] + it "valueToTL 6" $ do valueToTL 6 `shouldSafe` [S,T,T,S,N] + it "valueToTL 7" $ do valueToTL 7 `shouldSafe` [S,T,T,T,N] + it "valueToTL -0" $ do valueToTL (-0) `shouldSafe` [S,N] + it "valueToTL -1" $ do valueToTL (-1) `shouldSafe` [T,T,N] + it "valueToTL -2" $ do valueToTL (-2) `shouldSafe` [T,T,S,N] + it "valueToTL -3" $ do valueToTL (-3) `shouldSafe` [T,T,T,N] + it "valueToTL -4" $ do valueToTL (-4) `shouldSafe` [T,T,S,S,N] + it "valueToTL -5" $ do valueToTL (-5) `shouldSafe` [T,T,S,T,N] + it "valueToTL -6" $ do valueToTL (-6) `shouldSafe` [T,T,T,S,N] + it "valueToTL -7" $ do valueToTL (-7) `shouldSafe` [T,T,T,T,N] describe "identifierToTL" $ do - it "identifierToTL \" \"" $ do identifierToTL " " `shouldBe` [S,S,T,S,S,S,S,S, N] - it "identifierToTL \"A\"" $ do identifierToTL "A" `shouldBe` [S,T,S,S,S,S,S,T, N] - it "identifierToTL \"Z\"" $ do identifierToTL "Z" `shouldBe` [S,T,S,T,T,S,T,S, N] - it "identifierToTL \"a\"" $ do identifierToTL "a" `shouldBe` [S,T,T,S,S,S,S,T, N] - it "identifierToTL \"z\"" $ do identifierToTL "z" `shouldBe` [S,T,T,T,T,S,T,S, N] + it "identifierToTL \" \"" $ do identifierToTL " " `shouldSafe` [S,S,T,S,S,S,S,S , N] + it "identifierToTL \"A\"" $ do identifierToTL "A" `shouldSafe` [S,T,S,S,S,S,S,T , N] + it "identifierToTL \"Z\"" $ do identifierToTL "Z" `shouldSafe` [S,T,S,T,T,S,T,S , N] + it "identifierToTL \"a\"" $ do identifierToTL "a" `shouldSafe` [S,T,T,S,S,S,S,T , N] + it "identifierToTL \"z\"" $ do identifierToTL "z" `shouldSafe` [S,T,T,T,T,S,T,S , N] diff --git a/hs/test/HelVM/HelPA/Assemblers/WSA/LinkerSpec.hs b/hs/test/HelVM/HelPA/Assemblers/WSA/LinkerSpec.hs index 1777b44f..da3b145a 100644 --- a/hs/test/HelVM/HelPA/Assemblers/WSA/LinkerSpec.hs +++ b/hs/test/HelVM/HelPA/Assemblers/WSA/LinkerSpec.hs @@ -4,33 +4,36 @@ import HelVM.HelPA.Assemblers.WSA.Linker import HelVM.HelPA.Assemblers.WSA.TestData import HelVM.HelPA.Assemblers.WSA.FileUtil -import HelVM.Expectations - import HelVM.HelPA.Assembler.API +import HelVM.Common.Util + +import HelVM.Expectations +import HelVM.GoldenExpectations + import System.FilePath.Posix -import Test.Hspec +import Test.Hspec (Spec , describe , it) spec :: Spec spec = do - let linkLibFile = \ fileName -> linkLib SourcePath {dirPath = libDir, filePath = fileName <.> ext} - let linkAppFile = \ fileName -> linkApp SourcePath {dirPath = libDir, filePath = appDir fileName <.> ext} - let linkAppFile1 = \ fileName -> linkApp SourcePath {dirPath = libDir, filePath = wsaDir "from-eas" fileName <.> ext} + let linkLibFile fileName = linkLib SourcePath {dirPath = libDir , filePath = fileName <.> ext} + let linkAppFile fileName = linkApp SourcePath {dirPath = libDir , filePath = appDir fileName <.> ext} + let linkAppFile1 fileName = linkApp SourcePath {dirPath = libDir , filePath = wsaDir "from-eas" fileName <.> ext} describe "linkLibFile" $ do forM_ [ "io" , "memory" ] $ \fileName -> do it fileName $ do - linkLibFile fileName `goldenShouldSafeReturn` buildAbsolutePathToIlFile ("linkLibFile" fileName) + showP <$> linkLibFile fileName `goldenShouldSafeExceptT` buildAbsolutePathToIlFile ("linkLibFile" fileName) describe "linkAppFile" $ do describe "original" $ do forM_ [ "prim" ] $ \fileName -> do it fileName $ do - linkAppFile fileName `goldenShouldSafeReturn` buildAbsolutePathToIlFile ("linkAppFile" "original" fileName) + showP <$> linkAppFile fileName `goldenShouldSafeExceptT` buildAbsolutePathToIlFile ("linkAppFile" "original" fileName) describe "from-eas" $ do forM_ [ "true" @@ -52,9 +55,9 @@ spec = do -- , "euclid" ] $ \ fileName -> do it fileName $ do - linkAppFile1 fileName `goldenShouldSafeReturn` buildAbsolutePathToIlFile ("linkAppFile" "from-eas" fileName) + showP <$> linkAppFile1 fileName `goldenShouldSafeExceptT` buildAbsolutePathToIlFile ("linkAppFile" "from-eas" fileName) describe "linkFile" $ do - it "io" $ do linkLibFile "io" `shouldSafeReturn` ioIL - it "memory" $ do linkLibFile "memory" `shouldSafeReturn` memoryIL - it "prim" $ do linkAppFile "prim" `shouldSafeReturn` (primIL <> ioIL) + it "io" $ do linkLibFile "io" `shouldSafeExceptT` ioIL + it "memory" $ do linkLibFile "memory" `shouldSafeExceptT` memoryIL + it "prim" $ do linkAppFile "prim" `shouldSafeExceptT` (primIL <> ioIL) diff --git a/hs/test/HelVM/HelPA/Assemblers/WSA/ReducerSpec.hs b/hs/test/HelVM/HelPA/Assemblers/WSA/ReducerSpec.hs index d9c0c56e..a634d121 100644 --- a/hs/test/HelVM/HelPA/Assemblers/WSA/ReducerSpec.hs +++ b/hs/test/HelVM/HelPA/Assemblers/WSA/ReducerSpec.hs @@ -3,7 +3,8 @@ module HelVM.HelPA.Assemblers.WSA.ReducerSpec (spec) where import HelVM.HelPA.Assemblers.WSA.Reducer import HelVM.HelPA.Assemblers.WSA.TestData -import Test.Hspec +import Test.Hspec (Spec , describe , it) +import Test.Hspec.Expectations.Pretty spec :: Spec spec = do @@ -11,5 +12,5 @@ spec = do forM_ [ ("io" , ioIL , ioILReduced) , ("memory" , memoryIL , memoryILReduced) , ("prim" , primIL , primILReduced) - ] $ \(fileName , il, ilReduced) -> do + ] $ \(fileName , il , ilReduced) -> do it fileName $ do reduce False il `shouldBe` ilReduced diff --git a/hs/test/HelVM/MonadErrorSpec.hs b/hs/test/HelVM/MonadErrorSpec.hs new file mode 100644 index 00000000..c7c60a59 --- /dev/null +++ b/hs/test/HelVM/MonadErrorSpec.hs @@ -0,0 +1,20 @@ +module HelVM.MonadErrorSpec (spec) where + +import Control.Monad.Except + +import Test.Hspec (Spec , describe , it) +import Test.Hspec.Expectations.Pretty + +spec :: Spec +spec = do + describe "MonadError" $ do + it "Right" $ do textRight `shouldBe` Right 1 + it "Left" $ do textLeft `shouldBe` Left "one" + +type MonadTextError m = MonadError Text m + +textRight :: MonadTextError m => m Integer +textRight = pure 1 + +textLeft :: MonadTextError m => m Integer +textLeft = throwError "one" diff --git a/stan.sh b/stan.sh new file mode 100755 index 00000000..4391e611 --- /dev/null +++ b/stan.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +stan -s --hide-solution report