Add some more test cases to the generator

This commit is contained in:
Sasha Koshka 2023-12-05 22:29:29 -05:00
parent e06fd099ce
commit 7d436290c4
1 changed files with 36 additions and 15 deletions

View File

@ -2,27 +2,48 @@ package generator
import "testing"
func TestFunction (test *testing.T) {
func TestFunctionExternal (test *testing.T) {
testString (test,
`
`declare void @exit(i64 %status)
define void @main() {
0:
call void @exit(i64 1)
ret void
}
`,
`
[puts string: *Byte]: Index
[write file:I32 buffer:*Byte count:Index]: Index
[printDigit digit:Byte] = {
digit = [+ digit '0']
[write 1 [@digit] 1]
[exit status:Int]
[main] = [exit 1]
`)
}
[main] = {
[puts 'printing']
[printDigit 0]
[printDigit 1]
[printDigit 2]
[printDigit 3]
[puts '\nprinted']
func TestFunctionCall (test *testing.T) {
testString (test,
`define i64 @f() {
0:
%1 = call i64 @g(i64 5)
ret i64 %1
}
define i64 @g(i64 %x) {
0:
%1 = alloca i64
store i64 %x, ptr %1
%2 = load i64, ptr %1
%3 = call i64 @h(i64 %2)
ret i64 %3
}
define i64 @h(i64 %x) {
0:
%1 = alloca i64
store i64 %x, ptr %1
%2 = load i64, ptr %1
ret i64 %2
}
`,
`
[f ]:Int = [g 5]
[g x:Int]:Int = [h x]
[h x:Int]:Int = x
`)
}
// [write 1 (* 72 101 108 108 111 114 108 100 0) 7]