Made a test_runner in Kraken to run the tests on Kalypso, and moved to_import.krak to simple_print.krak and ported one function over to use it instead, so that Kalypso testing can get started before implementing everything needed to use io.krak
This commit is contained in:
@@ -106,11 +106,13 @@ obj import (Object) {
|
||||
var imported: set<string>
|
||||
var translation_unit: *ast_node
|
||||
var name: string
|
||||
var starred: bool
|
||||
fun construct(nameIn: string, translation_unit_in: *ast_node): *import {
|
||||
scope.construct()
|
||||
imported.construct()
|
||||
name.copy_construct(&nameIn)
|
||||
translation_unit = translation_unit_in
|
||||
starred = false
|
||||
return this
|
||||
}
|
||||
fun copy_construct(old: *import) {
|
||||
@@ -118,6 +120,7 @@ obj import (Object) {
|
||||
imported.copy_construct(&old->imported)
|
||||
name.copy_construct(&old->name)
|
||||
translation_unit = old->translation_unit
|
||||
starred = old->starred
|
||||
}
|
||||
fun destruct() {
|
||||
scope.destruct()
|
||||
@@ -129,7 +132,7 @@ obj import (Object) {
|
||||
copy_construct(&other)
|
||||
}
|
||||
fun operator==(other: ref import): bool {
|
||||
return imported == other.imported && name == other.name && translation_unit == other.translation_unit
|
||||
return imported == other.imported && name == other.name && translation_unit == other.translation_unit && starred == other.starred
|
||||
}
|
||||
}
|
||||
fun ast_identifier_ptr(name: *char, type: *type): *ast_node {
|
||||
|
||||
@@ -73,6 +73,8 @@ obj ast_transformation (Object) {
|
||||
ast_to_syntax.set(import_node, child)
|
||||
add_to_scope("~enclosing_scope", translation_unit, import_node)
|
||||
import_node->import.imported = from_vector(import_identifier_children.slice(1,-1).map(fun(ident: *tree<symbol>):string return concat_symbol_tree(ident);))
|
||||
if (get_node("\"\\*\"", child))
|
||||
import_node->import.starred = true
|
||||
}
|
||||
})
|
||||
return translation_unit
|
||||
@@ -577,27 +579,39 @@ fun identifier_lookup(name: string, scope: *ast_node): *ast_node {
|
||||
fun scope_lookup(name: string, scope: *ast_node): vector<*ast_node> {
|
||||
println("*****Doing a name lookup for*****")
|
||||
println(name)
|
||||
return scope_lookup_helper(name, scope)
|
||||
return scope_lookup_helper(name, scope, set<*ast_node>())
|
||||
}
|
||||
fun scope_lookup_helper(name: string, scope: *ast_node): vector<*ast_node> {
|
||||
fun scope_lookup_helper(name: string, scope: *ast_node, visited: set<*ast_node>): vector<*ast_node> {
|
||||
// need to do properly scopded lookups
|
||||
// prevent re-checking the same one...
|
||||
print("scope is: ")
|
||||
get_ast_scope(scope)->for_each(fun(key: string, value: vector<*ast_node>) print(key + " ");)
|
||||
println()
|
||||
var results = vector<*ast_node>()
|
||||
// prevent re-checking the same one...
|
||||
if (visited.contains(scope))
|
||||
return results
|
||||
visited.add(scope)
|
||||
if (get_ast_scope(scope)->contains_key(name)) {
|
||||
println(name + " is in scope, adding to results")
|
||||
results += get_ast_scope(scope)->get(name)
|
||||
}
|
||||
if (get_ast_scope(scope)->contains_key(string("~enclosing_scope")))
|
||||
results += scope_lookup_helper(name, get_ast_scope(scope)->get(string("~enclosing_scope"))[0])
|
||||
results += scope_lookup_helper(name, get_ast_scope(scope)->get(string("~enclosing_scope"))[0], visited)
|
||||
if (is_translation_unit(scope)) {
|
||||
scope->translation_unit.children.for_each(fun(child: *ast_node) {
|
||||
if (is_import(child) && child->import.imported.contains(name)) {
|
||||
if (is_import(child)) {
|
||||
if (child->import.imported.contains(name)) {
|
||||
println(name + " is indeed imported")
|
||||
results += scope_lookup_helper(name, child->import.translation_unit)
|
||||
} else println(name + " is not imported (this time)")
|
||||
results += scope_lookup_helper(name, child->import.translation_unit, visited)
|
||||
} else if (child->import.starred) {
|
||||
println("import has an import *, checking along it")
|
||||
results += scope_lookup_helper(name, child->import.translation_unit, visited)
|
||||
} else {
|
||||
println(name + " is not imported (this time)")
|
||||
print("import imports")
|
||||
child->import.imported.for_each(fun(it: string) print(it + " ");)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
return results
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
krakenPath="../build-ninja/kraken"
|
||||
runner_path="./test_runner/test_runner"
|
||||
#testDir=${1:-"../tests"}
|
||||
testDir="."
|
||||
ext=${2:-"krak"}
|
||||
@@ -12,4 +12,4 @@ for dir in `find ${testDir} -type f -name "test_*.${ext}"`; do
|
||||
fileList+=\ $testDir\/$filename
|
||||
done
|
||||
|
||||
${krakenPath} "--test" ${fileList}
|
||||
${runner_path} "--test" ${fileList}
|
||||
20
tests/simple_print.krak
Normal file
20
tests/simple_print.krak
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
fun println(to_print: *char) {
|
||||
print(to_print)
|
||||
print("\n")
|
||||
}
|
||||
fun println(to_print: int) {
|
||||
print(to_print)
|
||||
print("\n")
|
||||
}
|
||||
fun print(to_print: *char) {
|
||||
__if_comp__ __C__ simple_passthrough(to_print::) """
|
||||
printf("%s", to_print);
|
||||
"""
|
||||
}
|
||||
fun print(to_print: int) {
|
||||
__if_comp__ __C__ simple_passthrough(to_print::) """
|
||||
printf("%d", to_print);
|
||||
"""
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import serialize:*
|
||||
import c_generator:*
|
||||
import os:*
|
||||
|
||||
fun main():int {
|
||||
fun main(argc: int, argv: **char):int {
|
||||
|
||||
/*var gram.construct(): grammer*/
|
||||
// delay construction until we either load it or copy construct it
|
||||
@@ -62,6 +62,8 @@ fun main():int {
|
||||
}
|
||||
|
||||
var kraken_file_name = string("to_parse.krak")
|
||||
if (argc > 1)
|
||||
kraken_file_name = string(argv[1])
|
||||
var parse.construct(gram): parser
|
||||
var ast_pass.construct(): ast_transformation
|
||||
var importer.construct(parse, ast_pass): importer
|
||||
|
||||
47
tests/test_runner.krak
Normal file
47
tests/test_runner.krak
Normal file
@@ -0,0 +1,47 @@
|
||||
import string:*
|
||||
import io:*
|
||||
import os:*
|
||||
|
||||
fun error(message: *char) {
|
||||
println("ERROR:")
|
||||
println(message)
|
||||
}
|
||||
|
||||
fun main(argc: int, argv: **char): int {
|
||||
var kraken_path = string("./test_compiler/test_compiler")
|
||||
var all_results = string()
|
||||
var num_passed = 0
|
||||
var name_length = 0
|
||||
// first iterate and get the length of the longest line
|
||||
for (var i = 1; i < argc; i++;) {
|
||||
var name = string(argv[i])
|
||||
if (name.length() > name_length)
|
||||
name_length = name.length()
|
||||
}
|
||||
var pad_with_spaces = fun(name: string): string {
|
||||
while (name.length() < name_length) name += " "
|
||||
return name
|
||||
}
|
||||
for (var i = 1; i < argc; i++;) {
|
||||
var test_name = string(argv[i])
|
||||
println(string("Doing test for ") + test_name)
|
||||
if (system(kraken_path + " " + test_name + ".krak")) error("could not compile")
|
||||
var results_file_name = test_name + ".results"
|
||||
var expected_results_file_name = test_name + ".expected_results"
|
||||
if (system(string("./") + test_name + ".krak.exe > " + results_file_name)) error("could not run")
|
||||
if (read_file(results_file_name) == read_file(expected_results_file_name)) {
|
||||
println(test_name + "\tPASSED!")
|
||||
all_results += pad_with_spaces(test_name) + "\tPASSED!\n"
|
||||
num_passed++
|
||||
system(string("rm ./") + results_file_name)
|
||||
} else {
|
||||
println(test_name + "\tFAILED!")
|
||||
all_results += pad_with_spaces(test_name) + "\tFAILED!\n"
|
||||
}
|
||||
system(string("rm ./") + test_name + ".krak.*")
|
||||
}
|
||||
println(string("\n\nTEST RESULTS: ") + num_passed + "/" + (argc-1))
|
||||
println(all_results)
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import io:*;
|
||||
import simple_print:*
|
||||
|
||||
fun addAndPrintInt(a: int, b: int): int {
|
||||
print(a+b);
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
|
||||
fun simple_println(to_print: *char) {
|
||||
simple_print(to_print)
|
||||
simple_print("\n")
|
||||
}
|
||||
fun simple_println(to_print: int) {
|
||||
simple_print(to_print)
|
||||
simple_print("\n")
|
||||
}
|
||||
fun simple_print(to_print: *char) {
|
||||
__if_comp__ __C__ simple_passthrough(to_print::) """
|
||||
printf("%s", to_print);
|
||||
"""
|
||||
}
|
||||
fun simple_print(to_print: int) {
|
||||
__if_comp__ __C__ simple_passthrough(to_print::) """
|
||||
printf("%d", to_print);
|
||||
"""
|
||||
}
|
||||
fun string_id(it: *char): *char {
|
||||
return it;
|
||||
}
|
||||
var a = 1
|
||||
var b:int
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import to_import: simple_print, simple_println, a, b, string_id
|
||||
import simple_print: *
|
||||
/*
|
||||
fun something(param: int): Something {
|
||||
var to_ret.construct_with_param(param): Something
|
||||
@@ -7,22 +7,22 @@ fun something(param: int): Something {
|
||||
obj Something (ObjectTrait) {
|
||||
var member: int
|
||||
fun construct(): *Something {
|
||||
simple_println("Constructing a Something")
|
||||
println("Constructing a Something")
|
||||
member = 1337
|
||||
return this
|
||||
}
|
||||
fun construct_with_param(param: int): *Something {
|
||||
simple_println("Constructing a Something with a param")
|
||||
println("Constructing a Something with a param")
|
||||
member = param
|
||||
return this
|
||||
}
|
||||
fun copy_construct(old: *Something) {
|
||||
simple_println("Copy Constructing a Something")
|
||||
println("Copy Constructing a Something")
|
||||
member = old->member
|
||||
}
|
||||
fun destruct() {
|
||||
simple_print("Destructing a Something: ")
|
||||
simple_println(member)
|
||||
print("Destructing a Something: ")
|
||||
println(member)
|
||||
}
|
||||
fun method(a: int):int {
|
||||
return 5+a+member + other_method()
|
||||
@@ -42,7 +42,7 @@ fun id<T>(in: T): T return in;
|
||||
fun other_id<T>(in: T): T {
|
||||
var a: T
|
||||
a = in
|
||||
simple_println(id<T>(in))
|
||||
println(id<T>(in))
|
||||
return in;
|
||||
}
|
||||
/*
|
||||
@@ -53,87 +53,87 @@ fun some_other_function(in: bool): float {
|
||||
*/
|
||||
fun main(): int {
|
||||
var a = id<int>(7)
|
||||
simple_println(a)
|
||||
println(a)
|
||||
var b = id<int>(8)
|
||||
/*var b = id<*char>("Double down time")*/
|
||||
/*simple_println(b)*/
|
||||
simple_println(id<char>("Double down time"))
|
||||
simple_println(other_id<*char>("Triple down time"))
|
||||
/*println(b)*/
|
||||
println(id<char>("Double down time"))
|
||||
println(other_id<*char>("Triple down time"))
|
||||
|
||||
|
||||
|
||||
/*var test_methods = something(77)*/
|
||||
/*var test_methods_param.construct_with_param(10090): Something*/
|
||||
/*simple_println("Constructing an object and printint its member, copy-constructing it, and printing that out, then letting both be destructed")*/
|
||||
/*simple_println(test_methods.member)*/
|
||||
/*simple_println(test_methods_param.member)*/
|
||||
/*println("Constructing an object and printint its member, copy-constructing it, and printing that out, then letting both be destructed")*/
|
||||
/*println(test_methods.member)*/
|
||||
/*println(test_methods_param.member)*/
|
||||
/*var second_obj = test_methods*/
|
||||
/*second_obj.member += 5*/
|
||||
/*simple_println(second_obj.member)*/
|
||||
/*println(second_obj.member)*/
|
||||
/*[>var some = return_something_p_1(second_obj)<]*/
|
||||
/*simple_println(return_something_p_1(second_obj).member)*/
|
||||
/*println(return_something_p_1(second_obj).member)*/
|
||||
return 0
|
||||
/*
|
||||
var a_declaration:int
|
||||
simple_print(1 + 2)
|
||||
print(1 + 2)
|
||||
var again = 2 + 4 - 1 * 400
|
||||
simple_print(again)
|
||||
print(again)
|
||||
again = 2 + (4 - 1) * 400
|
||||
simple_print(again)
|
||||
print(again)
|
||||
var another_declaration: int = 8.0
|
||||
simple_print(another_declaration)
|
||||
print(another_declaration)
|
||||
var yet_another_declaration = "Hello Marcus\n"
|
||||
simple_print(yet_another_declaration)
|
||||
simple_print("Hello World!\n")
|
||||
simple_print(1337)
|
||||
if (1 + 2 && false) simple_print("its true!")
|
||||
else simple_print("its false!")
|
||||
print(yet_another_declaration)
|
||||
print("Hello World!\n")
|
||||
print(1337)
|
||||
if (1 + 2 && false) print("its true!")
|
||||
else print("its false!")
|
||||
var counter = 10
|
||||
counter--
|
||||
--counter
|
||||
while (counter) simple_print(counter--)
|
||||
simple_print("\n")
|
||||
while (counter) print(counter--)
|
||||
print("\n")
|
||||
counter = 8
|
||||
while (counter) {
|
||||
simple_print(--counter)
|
||||
print(--counter)
|
||||
if (counter == 2)
|
||||
break
|
||||
}
|
||||
simple_print("\n")
|
||||
print("\n")
|
||||
for (var j = 0; j < 10; j++;)
|
||||
if (j%2) continue
|
||||
else simple_print(j)
|
||||
else print(j)
|
||||
var an_obj: Something
|
||||
an_obj.member = 20
|
||||
simple_print(an_obj.member)
|
||||
simple_print("here is thing")
|
||||
simple_print(123)
|
||||
simple_print("\n")
|
||||
simple_print(an_obj.method(1))
|
||||
simple_print("\n")
|
||||
simple_print(string_id("WoooopsEee\n"))
|
||||
print(an_obj.member)
|
||||
print("here is thing")
|
||||
print(123)
|
||||
print("\n")
|
||||
print(an_obj.method(1))
|
||||
print("\n")
|
||||
print(string_id("WoooopsEee\n"))
|
||||
var with_ptr = an_obj.return_this()
|
||||
simple_print(with_ptr->method(2))
|
||||
simple_print("\n")
|
||||
print(with_ptr->method(2))
|
||||
print("\n")
|
||||
{
|
||||
defer simple_print("should_be_third\n")
|
||||
defer simple_print("should_be_second\n")
|
||||
simple_print("should be first\n")
|
||||
defer print("should_be_third\n")
|
||||
defer print("should_be_second\n")
|
||||
print("should be first\n")
|
||||
}
|
||||
for (var i = 1; i < 10; i++;) {
|
||||
defer simple_println("OUTER:happens every time, even when breaking or continueing")
|
||||
defer println("OUTER:happens every time, even when breaking or continueing")
|
||||
{
|
||||
defer simple_println("INNER:happens every time, even when breaking or continueing")
|
||||
defer println("INNER:happens every time, even when breaking or continueing")
|
||||
if (i % 2 == 0)
|
||||
continue
|
||||
if (i == 9)
|
||||
break
|
||||
simple_println(i)
|
||||
println(i)
|
||||
}
|
||||
}
|
||||
defer simple_println("Here is a return defer outer")
|
||||
defer println("Here is a return defer outer")
|
||||
{
|
||||
defer simple_println("Here is a return defer inner")
|
||||
defer println("Here is a return defer inner")
|
||||
return 0
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user