Skip to content

Commit

Permalink
Work on the test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Feb 7, 2024
1 parent 63ae9da commit 17b154d
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 129 deletions.
2 changes: 1 addition & 1 deletion src/testrunner.pr
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ if runner {
test_env.err = *get_stderr
test_env.assertion_handler = *assertion_handler

let test = symbol.value !(def (*runtime::TestEnvironment) -> ())
let test = symbol.value !(def *runtime::TestEnvironment -> [])
test(*test_env)
flush(std::stdout())

Expand Down
2 changes: 1 addition & 1 deletion std/process.pr
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ import std
}

export def wait(process: *Process, timeout: ulong = -1) {
var pfd = [process.fd !int, POLLIN, 0] !linux::s_pollfd;
var pfd = [fd = process.fd !int, events = POLLIN, revents = 0] !linux::s_pollfd;
if linux::poll(*pfd, 1, timeout !int) == 0 {
return
}
Expand Down
14 changes: 7 additions & 7 deletions std/shared.pr
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export def find_symbol(library: *Library, name: String) -> Optional(Symbol) {
if init {
let main_sym = find_symbol(*library, "main::__main__::([[char]])")
if main_sym.exists {
let main = main_sym.get().value !(def ([[char]]) -> ())
let main = main_sym.get().value !(def ([[char]]) -> [])
// FIXME Pass in actual command line arguments
let args = zero_allocate(type [char], 0)
main(args)
Expand All @@ -121,7 +121,7 @@ export def find_symbol(library: *Library, name: String) -> Optional(Symbol) {
if finalize {
let finalizer_sym = find_symbol(library, "main::__finalizer__::()")
if finalizer_sym.exists {
let finalizer = finalizer_sym.get().value !(def () -> ())
let finalizer = finalizer_sym.get().value !(def -> [])
finalizer()
}
}
Expand Down Expand Up @@ -231,15 +231,15 @@ export def find_symbol(library: *Library, name: String) -> Optional(Symbol) {
}

let library = [
path,
handle,
symbols.to_array()
path = path,
handle = handle,
symbols = symbols.to_array()
] !Library

if init {
let main_sym = find_symbol(*library, "main::__main__::([[char]])")
if main_sym.exists {
let main = main_sym.get().value !(def ([[char]]) -> ())
let main = main_sym.get().value !(def ([[char]]) -> [])
// FIXME Pass in actual command line arguments
let args = zero_allocate(type [char], 0)
main(args)
Expand All @@ -253,7 +253,7 @@ export def find_symbol(library: *Library, name: String) -> Optional(Symbol) {
if finalize {
let finalizer_sym = find_symbol(library, "main::__finalizer__::()")
if finalizer_sym.exists {
let finalizer = finalizer_sym.get().value !(def () -> ())
let finalizer = finalizer_sym.get().value !(def -> [])
finalizer()
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/runtime/test_vector.pr
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ def push(vec: &Vector, elem: &) {


def test_vector {
let s: &S = [0] !S
let s: &S = [a = 0] !S
let vec = make()
vec.push(s)
vec.push([20] !S)
vec.push([30] !S)
vec.push([40] !S)
vec.push([a = 20] !S)
vec.push([a = 30] !S)
vec.push([a = 40] !S)

let vec2 = copy(vec)

Expand Down
123 changes: 58 additions & 65 deletions test/test_compiler.pr
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ def #test test_vardecl {
let baz, (bar) = 0, 1
"""
var res = compile(str)
assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "byte"
assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "long"
assert res["body"][2]["left"][0]["value"]["type_tag"]["name"].as_string() == "int"
assert res["body"][2]["left"][1]["value"]["type_tag"]["name"].as_string() == "long"
assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "byte"
assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "long"
assert res("body")(2)("left")(0)("value")("type_tag")("name").as_string() == "int"
assert res("body")(2)("left")(1)("value")("type_tag")("name").as_string() == "long"
}

def #test test_vardecl_fail {
Expand Down Expand Up @@ -308,11 +308,11 @@ def #test test_literals {
let v5 = false
"""
var res = compile(str)
assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "[char]"
assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "char"
assert res["body"][2]["left"][0]["value"]["type_tag"]["name"].as_string() == "double"
assert res["body"][3]["left"][0]["value"]["type_tag"]["name"].as_string() == "int"
assert res["body"][4]["left"][0]["value"]["type_tag"]["name"].as_string() == "bool"
assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "[char]"
assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "char"
assert res("body")(2)("left")(0)("value")("type_tag")("name").as_string() == "double"
assert res("body")(3)("left")(0)("value")("type_tag")("name").as_string() == "int"
assert res("body")(4)("left")(0)("value")("type_tag")("name").as_string() == "bool"
}

def #test test_switch {
Expand Down Expand Up @@ -388,13 +388,13 @@ def #test test_operators {
"""
let res = compile(str)

assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "int"
assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "int"
assert res["body"][2]["left"][0]["value"]["type_tag"]["name"].as_string() == "int"
assert res["body"][3]["left"][0]["value"]["type_tag"]["name"].as_string() == "int"
assert res["body"][4]["left"][0]["value"]["type_tag"]["name"].as_string() == "int"
assert res["body"][5]["left"][0]["value"]["type_tag"]["name"].as_string() == "long"
assert res["body"][6]["left"][0]["value"]["type_tag"]["name"].as_string() == "long"
assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "int"
assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "int"
assert res("body")(2)("left")(0)("value")("type_tag")("name").as_string() == "int"
assert res("body")(3)("left")(0)("value")("type_tag")("name").as_string() == "int"
assert res("body")(4)("left")(0)("value")("type_tag")("name").as_string() == "int"
assert res("body")(5)("left")(0)("value")("type_tag")("name").as_string() == "long"
assert res("body")(6)("left")(0)("value")("type_tag")("name").as_string() == "long"
}

def #test test_operators_fail {
Expand Down Expand Up @@ -586,21 +586,21 @@ def #test test_struct {
}
"""
let res = compile(str)
let A = res["body"][0]["right"][0]["type_tag"]
assert A["size"].as_double() == 24
assert A["align"].as_double() == 8
let A = res("body")(0)("right")(0)("type_tag")
assert A("size").as_double() == 24
assert A("align").as_double() == 8

let B = res["body"][1]["right"][0]["type_tag"]
assert B["size"].as_double() == 4
assert B["align"].as_double() == 2
let B = res("body")(1)("right")(0)("type_tag")
assert B("size").as_double() == 4
assert B("align").as_double() == 2

let C = res["body"][2]["right"][0]["type_tag"]
assert C["size"].as_double() == 8
assert C["align"].as_double() == 4
let C = res("body")(2)("right")(0)("type_tag")
assert C("size").as_double() == 8
assert C("align").as_double() == 4

let D = res["body"][3]["right"][0]["type_tag"]
assert D["size"].as_double() == 8
assert D["align"].as_double() == 8
let D = res("body")(3)("right")(0)("type_tag")
assert D("size").as_double() == 8
assert D("align").as_double() == 8
}

def #test test_struct_lit {
Expand Down Expand Up @@ -628,12 +628,12 @@ def #test test_struct_lit {
let g = [b = [a = e] !A, c = f] !B

def ret_a -> A {
return {10}
return [a = 10]
}

let h: A = {10}
var i: A
i = {10}
i = [a = 10]

type C = struct {
a: int
Expand Down Expand Up @@ -765,9 +765,9 @@ def #test test_pointers {
"""
let res = compile(str)

assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "int"
assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "*int"
assert res["body"][2]["left"][0]["value"]["type_tag"]["name"].as_string() == "int"
assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "int"
assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "*int"
assert res("body")(2)("left")(0)("value")("type_tag")("name").as_string() == "int"
}

def #test test_pointers_fail {
Expand Down Expand Up @@ -803,15 +803,15 @@ def #test test_ref {

let res = compile(str)

assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "&int"
assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "&"
assert res["body"][3]["left"][0]["value"]["type_tag"]["name"].as_string() == "&int"
assert res["body"][4]["left"][0]["value"]["type_tag"]["name"].as_string() == "&int"
assert res["body"][5]["left"][0]["value"]["type_tag"]["name"].as_string() == "&int"
assert res["body"][6]["left"][0]["value"]["type_tag"]["name"].as_string() == "int"
assert res["body"][7]["left"][0]["value"]["type_tag"]["name"].as_string() == "&int"
assert res["body"][8]["left"][0]["value"]["type_tag"]["name"].as_string() == "&float"
assert res["body"][9]["left"][0]["value"]["type_tag"]["name"].as_string() == "*int"
assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "&int"
assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "&"
assert res("body")(3)("left")(0)("value")("type_tag")("name").as_string() == "&int"
assert res("body")(4)("left")(0)("value")("type_tag")("name").as_string() == "&int"
assert res("body")(5)("left")(0)("value")("type_tag")("name").as_string() == "&int"
assert res("body")(6)("left")(0)("value")("type_tag")("name").as_string() == "int"
assert res("body")(7)("left")(0)("value")("type_tag")("name").as_string() == "&int"
assert res("body")(8)("left")(0)("value")("type_tag")("name").as_string() == "&float"
assert res("body")(9)("left")(0)("value")("type_tag")("name").as_string() == "*int"
}

def #test test_convert {
Expand All @@ -835,14 +835,14 @@ def #test test_convert {
"""
let res = compile(str)

assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "float"
assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "int"
assert res["body"][2]["left"][0]["value"]["type_tag"]["name"].as_string() == "float"
assert res["body"][3]["left"][0]["value"]["type_tag"]["name"].as_string() == "uint"
assert res["body"][4]["left"][0]["value"]["type_tag"]["name"].as_string() == "bool"
assert res["body"][5]["left"][0]["value"]["type_tag"]["name"].as_string() == "bool"
assert res["body"][6]["left"][0]["value"]["type_tag"]["name"].as_string() == "*int"
assert res["body"][7]["left"][0]["value"]["type_tag"]["name"].as_string() == "bool"
assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "float"
assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "int"
assert res("body")(2)("left")(0)("value")("type_tag")("name").as_string() == "float"
assert res("body")(3)("left")(0)("value")("type_tag")("name").as_string() == "uint"
assert res("body")(4)("left")(0)("value")("type_tag")("name").as_string() == "bool"
assert res("body")(5)("left")(0)("value")("type_tag")("name").as_string() == "bool"
assert res("body")(6)("left")(0)("value")("type_tag")("name").as_string() == "*int"
assert res("body")(7)("left")(0)("value")("type_tag")("name").as_string() == "bool"
}

def #test test_member_access {
Expand All @@ -857,26 +857,19 @@ def #test test_member_access {
"""
let res = compile(str)

assert res["body"][2]["left"][0]["value"]["type_tag"]["name"].as_string() == "int"
assert res["body"][3]["left"][0]["value"]["type_tag"]["name"].as_string() == "double"
assert res("body")(2)("left")(0)("value")("type_tag")("name").as_string() == "int"
assert res("body")(3)("left")(0)("value")("type_tag")("name").as_string() == "double"
}

def #test test_array_subscript {
let str = """
var a: [4; int]
let b = a(2)

var c = 10
var d = *c
let e = d(2)
"""
let res = compile(str)

assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "[4; int]"
assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "int"
assert res["body"][2]["left"][0]["value"]["type_tag"]["name"].as_string() == "int"
assert res["body"][3]["left"][0]["value"]["type_tag"]["name"].as_string() == "*int"
assert res["body"][4]["left"][0]["value"]["type_tag"]["name"].as_string() == "int"
assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "[4; int]"
assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "int"
}

def #test test_array_lit {
Expand All @@ -886,8 +879,8 @@ def #test test_array_lit {
"""
let res = compile(str)

assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "[4; int]"
assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "[int]"
assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "[4; int]"
assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "[int]"
}

def #test test_array_inference {
Expand All @@ -897,8 +890,8 @@ def #test test_array_inference {
"""
let res = compile(str)

assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "[4; int]"
assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "[int]"
assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "[4; int]"
assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "[int]"
}

def #test test_array_inference_fail {
Expand Down
Loading

0 comments on commit 17b154d

Please sign in to comment.