Skip to content

Commit

Permalink
Merge pull request #553 from shiika-lang/new-runtime-test
Browse files Browse the repository at this point in the history
new_runtime: Add tests
  • Loading branch information
yhara authored Oct 9, 2024
2 parents f923879 + 0cf49f5 commit 0738137
Show file tree
Hide file tree
Showing 26 changed files with 156 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
*.ll
*.out
*.bc
Expand All @@ -14,4 +15,4 @@
/target
/tests/tmp.*
/tests/tmp/hello.txt
.DS_Store
/tests/new_runtime/*.actual_out
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,14 @@ task :async do
sh "cargo build"
end
sh "cargo run --bin exp_shiika -- a.milika"
end
task async_test: :async do
sh "./a"
end
task :async_integration_test do
Dir["tests/new_runtime/*.sk"].each do |path|
name = path.sub(".sk", "")
sh "cargo run --bin exp_shiika -- #{name}.sk > #{name}.actual_out"
sh "diff #{name}.actual_out #{name}.expected_out"
end
end
9 changes: 1 addition & 8 deletions lib/skc_async_experiment/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<'run, 'ictx: 'run> CodeGen<'run, 'ictx> {
hir::Expr::Assign(name, rhs) => self.compile_assign(ctx, name, rhs),
hir::Expr::Return(val_expr) => self.compile_return(ctx, val_expr),
hir::Expr::Exprs(exprs) => self.compile_exprs(ctx, exprs),
hir::Expr::Cast(expr, cast_type) => self.compile_cast(ctx, expr, cast_type),
hir::Expr::Cast(_, expr) => self.compile_cast(ctx, expr),
hir::Expr::Unbox(expr) => self.compile_unbox(ctx, expr),
hir::Expr::RawI64(n) => self.compile_raw_i64(*n),
// hir::Expr::Br(expr, block_id) => self.compile_br(blocks, block, lvars, expr, block_id),
Expand Down Expand Up @@ -289,19 +289,12 @@ impl<'run, 'ictx: 'run> CodeGen<'run, 'ictx> {
last_val
}

// TODO: just remove this?
fn compile_cast<'a>(
&mut self,
ctx: &mut CodeGenContext<'run>,
_cast_type: &hir::CastType,
expr: &hir::TypedExpr,
) -> Option<inkwell::values::BasicValueEnum<'run>> {
let e = self.compile_value_expr(ctx, expr);
// let v = match cast_type {
// hir::CastType::AnyToFun(_) => e,
// hir::CastType::AnyToInt | hir::CastType::IntToAny | hir::CastType::VoidToAny => e,
// hir::CastType::FunToAny => e,
// };
Some(e)
}

Expand Down
1 change: 0 additions & 1 deletion lib/skc_async_experiment/src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ fn build_clang_cmd(bc_path: &Path, exe_path: PathBuf) -> Command {
cmd.arg("-lpthread");
}

dbg!(&cmd);
cmd
}

Expand Down
2 changes: 2 additions & 0 deletions tests/new_runtime/arg_ref.expected_out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
3
3
18 changes: 18 additions & 0 deletions tests/new_runtime/arg_ref.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Main
def self.foo(a: Int, b: Int) -> Int
if a < b
print(a + b)
sleep_sec(0)
return a + b
else
print(a + b)
sleep_sec(0)
return a + b
end
end

def self.chiika_main() -> Int
print(foo(1, 2))
return 0
end
end
2 changes: 2 additions & 0 deletions tests/new_runtime/async.expected_out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
123
456
8 changes: 8 additions & 0 deletions tests/new_runtime/async.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Main
def self.chiika_main() -> Int
print(123)
sleep_sec(1)
print(456)
return 0
end
end
1 change: 1 addition & 0 deletions tests/new_runtime/async_if.expected_out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
456
11 changes: 11 additions & 0 deletions tests/new_runtime/async_if.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Main
def self.chiika_main() -> Int
if true
sleep_sec(1)
print(456)
else
print(789)
end
return 0
end
end
2 changes: 2 additions & 0 deletions tests/new_runtime/async_lvar.expected_out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
3
3
10 changes: 10 additions & 0 deletions tests/new_runtime/async_lvar.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Main
def self.chiika_main() -> Int
alloc x
x = 3
print(x)
sleep_sec(1)
print(x)
return 0
end
end
1 change: 1 addition & 0 deletions tests/new_runtime/async_valued_if.expected_out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
456
13 changes: 13 additions & 0 deletions tests/new_runtime/async_valued_if.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Main
def self.chiika_main() -> Int
print(
if true
sleep_sec(1)
456
else
789
end
)
return 0
end
end
4 changes: 4 additions & 0 deletions tests/new_runtime/countdown.expected_out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3
2
1
0
15 changes: 15 additions & 0 deletions tests/new_runtime/countdown.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Main
def self.countdown(i: Int) -> Null
print(i)
sleep_sec(0)
if i == 0
return null
end
return countdown(i - 1)
end

def self.chiika_main() -> Int
countdown(3)
return 0
end
end
1 change: 1 addition & 0 deletions tests/new_runtime/early_return.expected_out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
123
11 changes: 11 additions & 0 deletions tests/new_runtime/early_return.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Main
def self.chiika_main() -> Int
if true
sleep_sec(1)
print(123)
return 0
end
print(456)
return 0
end
end
1 change: 1 addition & 0 deletions tests/new_runtime/if.expected_out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
456
10 changes: 10 additions & 0 deletions tests/new_runtime/if.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Main
def self.chiika_main() -> Int
if true
print(456)
else
print(789)
end
return 0
end
end
1 change: 1 addition & 0 deletions tests/new_runtime/if_return_return.expected_out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
123
13 changes: 13 additions & 0 deletions tests/new_runtime/if_return_return.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Main
def self.chiika_main() -> Int
if true
sleep_sec(1)
print(123)
return 0
else
print(456)
return 0
end
end

end
1 change: 1 addition & 0 deletions tests/new_runtime/sync.expected_out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
123
6 changes: 6 additions & 0 deletions tests/new_runtime/sync.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Main
def self.chiika_main() -> Int
print(123)
return 0
end
end
1 change: 1 addition & 0 deletions tests/new_runtime/valued_if.expected_out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
456
12 changes: 12 additions & 0 deletions tests/new_runtime/valued_if.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Main
def self.chiika_main() -> Int
print(
if true
456
else
789
end
)
return 0
end
end

0 comments on commit 0738137

Please sign in to comment.