-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): adding first test for IR generation and optimization
- Loading branch information
Showing
4 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
tests/unittests/resources/CompilerSuite/ir/ackermann_iroptimized.ark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# the Ackermann Peter function (see https://en.wikipedia.org/wiki/Ackermann_function) | ||
# One of the simplest and earliest-discovered examples of a total computable function, | ||
# that is not primitive. All primitive recursive functions are total and computable, | ||
# but the Ackermann function illustrates that not all total computable functions | ||
# are primitive recursive. | ||
# Due to its definitions in terms of extremely deep recursion, it can be used as a | ||
# benchmark of a compiler's ability to optimize recursion, which is the reason why | ||
# we are using this function to benchmark the language. | ||
(let ackermann (fun (m n) { | ||
(if (> m 0) | ||
# then | ||
(if (= 0 n) | ||
# then | ||
(ackermann (- m 1) 1) | ||
# else | ||
(ackermann (- m 1) (ackermann m (- n 1)))) | ||
# else | ||
(+ 1 n)) })) | ||
|
||
(print "Ackermann-Péter function, m=3, n=6: " (ackermann 3 6)) |
38 changes: 38 additions & 0 deletions
38
tests/unittests/resources/CompilerSuite/ir/ackermann_iroptimized.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
page_0 | ||
LOAD_CONST_STORE 0, 0 | ||
LOAD_CONST_LOAD_CONST 3, 4 | ||
LOAD_CONST 5 | ||
LOAD_SYMBOL 0 | ||
CALL 2 | ||
CALL_BUILTIN 9, 2 | ||
HALT 0 | ||
|
||
page_1 | ||
STORE 1 | ||
STORE 2 | ||
LOAD_SYMBOL 1 | ||
LOAD_CONST 1 | ||
GT 0 | ||
GOTO_IF_TRUE L0 | ||
INCREMENT 2 | ||
GOTO L1 | ||
.L0: | ||
LOAD_CONST 1 | ||
LOAD_SYMBOL 2 | ||
EQ 0 | ||
GOTO_IF_TRUE L2 | ||
LOAD_SYMBOL 1 | ||
DECREMENT 2 | ||
LOAD_SYMBOL 0 | ||
CALL 2 | ||
DECREMENT 1 | ||
JUMP 0 | ||
GOTO L3 | ||
.L2: | ||
LOAD_CONST 2 | ||
DECREMENT 1 | ||
JUMP 0 | ||
.L3: | ||
.L1: | ||
RET 0 | ||
HALT 0 |