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 imported: set<string>
|
||||||
var translation_unit: *ast_node
|
var translation_unit: *ast_node
|
||||||
var name: string
|
var name: string
|
||||||
|
var starred: bool
|
||||||
fun construct(nameIn: string, translation_unit_in: *ast_node): *import {
|
fun construct(nameIn: string, translation_unit_in: *ast_node): *import {
|
||||||
scope.construct()
|
scope.construct()
|
||||||
imported.construct()
|
imported.construct()
|
||||||
name.copy_construct(&nameIn)
|
name.copy_construct(&nameIn)
|
||||||
translation_unit = translation_unit_in
|
translation_unit = translation_unit_in
|
||||||
|
starred = false
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
fun copy_construct(old: *import) {
|
fun copy_construct(old: *import) {
|
||||||
@@ -118,6 +120,7 @@ obj import (Object) {
|
|||||||
imported.copy_construct(&old->imported)
|
imported.copy_construct(&old->imported)
|
||||||
name.copy_construct(&old->name)
|
name.copy_construct(&old->name)
|
||||||
translation_unit = old->translation_unit
|
translation_unit = old->translation_unit
|
||||||
|
starred = old->starred
|
||||||
}
|
}
|
||||||
fun destruct() {
|
fun destruct() {
|
||||||
scope.destruct()
|
scope.destruct()
|
||||||
@@ -129,7 +132,7 @@ obj import (Object) {
|
|||||||
copy_construct(&other)
|
copy_construct(&other)
|
||||||
}
|
}
|
||||||
fun operator==(other: ref import): bool {
|
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 {
|
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)
|
ast_to_syntax.set(import_node, child)
|
||||||
add_to_scope("~enclosing_scope", translation_unit, import_node)
|
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);))
|
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
|
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> {
|
fun scope_lookup(name: string, scope: *ast_node): vector<*ast_node> {
|
||||||
println("*****Doing a name lookup for*****")
|
println("*****Doing a name lookup for*****")
|
||||||
println(name)
|
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
|
// need to do properly scopded lookups
|
||||||
// prevent re-checking the same one...
|
|
||||||
print("scope is: ")
|
print("scope is: ")
|
||||||
get_ast_scope(scope)->for_each(fun(key: string, value: vector<*ast_node>) print(key + " ");)
|
get_ast_scope(scope)->for_each(fun(key: string, value: vector<*ast_node>) print(key + " ");)
|
||||||
println()
|
println()
|
||||||
var results = vector<*ast_node>()
|
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)) {
|
if (get_ast_scope(scope)->contains_key(name)) {
|
||||||
println(name + " is in scope, adding to results")
|
println(name + " is in scope, adding to results")
|
||||||
results += get_ast_scope(scope)->get(name)
|
results += get_ast_scope(scope)->get(name)
|
||||||
}
|
}
|
||||||
if (get_ast_scope(scope)->contains_key(string("~enclosing_scope")))
|
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)) {
|
if (is_translation_unit(scope)) {
|
||||||
scope->translation_unit.children.for_each(fun(child: *ast_node) {
|
scope->translation_unit.children.for_each(fun(child: *ast_node) {
|
||||||
if (is_import(child) && child->import.imported.contains(name)) {
|
if (is_import(child)) {
|
||||||
println(name + " is indeed imported")
|
if (child->import.imported.contains(name)) {
|
||||||
results += scope_lookup_helper(name, child->import.translation_unit)
|
println(name + " is indeed imported")
|
||||||
} 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
|
return results
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
krakenPath="../build-ninja/kraken"
|
runner_path="./test_runner/test_runner"
|
||||||
#testDir=${1:-"../tests"}
|
#testDir=${1:-"../tests"}
|
||||||
testDir="."
|
testDir="."
|
||||||
ext=${2:-"krak"}
|
ext=${2:-"krak"}
|
||||||
@@ -12,4 +12,4 @@ for dir in `find ${testDir} -type f -name "test_*.${ext}"`; do
|
|||||||
fileList+=\ $testDir\/$filename
|
fileList+=\ $testDir\/$filename
|
||||||
done
|
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 c_generator:*
|
||||||
import os:*
|
import os:*
|
||||||
|
|
||||||
fun main():int {
|
fun main(argc: int, argv: **char):int {
|
||||||
|
|
||||||
/*var gram.construct(): grammer*/
|
/*var gram.construct(): grammer*/
|
||||||
// delay construction until we either load it or copy construct it
|
// 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")
|
var kraken_file_name = string("to_parse.krak")
|
||||||
|
if (argc > 1)
|
||||||
|
kraken_file_name = string(argv[1])
|
||||||
var parse.construct(gram): parser
|
var parse.construct(gram): parser
|
||||||
var ast_pass.construct(): ast_transformation
|
var ast_pass.construct(): ast_transformation
|
||||||
var importer.construct(parse, ast_pass): importer
|
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 {
|
fun addAndPrintInt(a: int, b: int): int {
|
||||||
print(a+b);
|
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 {
|
fun something(param: int): Something {
|
||||||
var to_ret.construct_with_param(param): Something
|
var to_ret.construct_with_param(param): Something
|
||||||
@@ -7,22 +7,22 @@ fun something(param: int): Something {
|
|||||||
obj Something (ObjectTrait) {
|
obj Something (ObjectTrait) {
|
||||||
var member: int
|
var member: int
|
||||||
fun construct(): *Something {
|
fun construct(): *Something {
|
||||||
simple_println("Constructing a Something")
|
println("Constructing a Something")
|
||||||
member = 1337
|
member = 1337
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
fun construct_with_param(param: int): *Something {
|
fun construct_with_param(param: int): *Something {
|
||||||
simple_println("Constructing a Something with a param")
|
println("Constructing a Something with a param")
|
||||||
member = param
|
member = param
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
fun copy_construct(old: *Something) {
|
fun copy_construct(old: *Something) {
|
||||||
simple_println("Copy Constructing a Something")
|
println("Copy Constructing a Something")
|
||||||
member = old->member
|
member = old->member
|
||||||
}
|
}
|
||||||
fun destruct() {
|
fun destruct() {
|
||||||
simple_print("Destructing a Something: ")
|
print("Destructing a Something: ")
|
||||||
simple_println(member)
|
println(member)
|
||||||
}
|
}
|
||||||
fun method(a: int):int {
|
fun method(a: int):int {
|
||||||
return 5+a+member + other_method()
|
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 {
|
fun other_id<T>(in: T): T {
|
||||||
var a: T
|
var a: T
|
||||||
a = in
|
a = in
|
||||||
simple_println(id<T>(in))
|
println(id<T>(in))
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@@ -53,87 +53,87 @@ fun some_other_function(in: bool): float {
|
|||||||
*/
|
*/
|
||||||
fun main(): int {
|
fun main(): int {
|
||||||
var a = id<int>(7)
|
var a = id<int>(7)
|
||||||
simple_println(a)
|
println(a)
|
||||||
var b = id<int>(8)
|
var b = id<int>(8)
|
||||||
/*var b = id<*char>("Double down time")*/
|
/*var b = id<*char>("Double down time")*/
|
||||||
/*simple_println(b)*/
|
/*println(b)*/
|
||||||
simple_println(id<char>("Double down time"))
|
println(id<char>("Double down time"))
|
||||||
simple_println(other_id<*char>("Triple down time"))
|
println(other_id<*char>("Triple down time"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*var test_methods = something(77)*/
|
/*var test_methods = something(77)*/
|
||||||
/*var test_methods_param.construct_with_param(10090): Something*/
|
/*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")*/
|
/*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)*/
|
/*println(test_methods.member)*/
|
||||||
/*simple_println(test_methods_param.member)*/
|
/*println(test_methods_param.member)*/
|
||||||
/*var second_obj = test_methods*/
|
/*var second_obj = test_methods*/
|
||||||
/*second_obj.member += 5*/
|
/*second_obj.member += 5*/
|
||||||
/*simple_println(second_obj.member)*/
|
/*println(second_obj.member)*/
|
||||||
/*[>var some = return_something_p_1(second_obj)<]*/
|
/*[>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
|
return 0
|
||||||
/*
|
/*
|
||||||
var a_declaration:int
|
var a_declaration:int
|
||||||
simple_print(1 + 2)
|
print(1 + 2)
|
||||||
var again = 2 + 4 - 1 * 400
|
var again = 2 + 4 - 1 * 400
|
||||||
simple_print(again)
|
print(again)
|
||||||
again = 2 + (4 - 1) * 400
|
again = 2 + (4 - 1) * 400
|
||||||
simple_print(again)
|
print(again)
|
||||||
var another_declaration: int = 8.0
|
var another_declaration: int = 8.0
|
||||||
simple_print(another_declaration)
|
print(another_declaration)
|
||||||
var yet_another_declaration = "Hello Marcus\n"
|
var yet_another_declaration = "Hello Marcus\n"
|
||||||
simple_print(yet_another_declaration)
|
print(yet_another_declaration)
|
||||||
simple_print("Hello World!\n")
|
print("Hello World!\n")
|
||||||
simple_print(1337)
|
print(1337)
|
||||||
if (1 + 2 && false) simple_print("its true!")
|
if (1 + 2 && false) print("its true!")
|
||||||
else simple_print("its false!")
|
else print("its false!")
|
||||||
var counter = 10
|
var counter = 10
|
||||||
counter--
|
counter--
|
||||||
--counter
|
--counter
|
||||||
while (counter) simple_print(counter--)
|
while (counter) print(counter--)
|
||||||
simple_print("\n")
|
print("\n")
|
||||||
counter = 8
|
counter = 8
|
||||||
while (counter) {
|
while (counter) {
|
||||||
simple_print(--counter)
|
print(--counter)
|
||||||
if (counter == 2)
|
if (counter == 2)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
simple_print("\n")
|
print("\n")
|
||||||
for (var j = 0; j < 10; j++;)
|
for (var j = 0; j < 10; j++;)
|
||||||
if (j%2) continue
|
if (j%2) continue
|
||||||
else simple_print(j)
|
else print(j)
|
||||||
var an_obj: Something
|
var an_obj: Something
|
||||||
an_obj.member = 20
|
an_obj.member = 20
|
||||||
simple_print(an_obj.member)
|
print(an_obj.member)
|
||||||
simple_print("here is thing")
|
print("here is thing")
|
||||||
simple_print(123)
|
print(123)
|
||||||
simple_print("\n")
|
print("\n")
|
||||||
simple_print(an_obj.method(1))
|
print(an_obj.method(1))
|
||||||
simple_print("\n")
|
print("\n")
|
||||||
simple_print(string_id("WoooopsEee\n"))
|
print(string_id("WoooopsEee\n"))
|
||||||
var with_ptr = an_obj.return_this()
|
var with_ptr = an_obj.return_this()
|
||||||
simple_print(with_ptr->method(2))
|
print(with_ptr->method(2))
|
||||||
simple_print("\n")
|
print("\n")
|
||||||
{
|
{
|
||||||
defer simple_print("should_be_third\n")
|
defer print("should_be_third\n")
|
||||||
defer simple_print("should_be_second\n")
|
defer print("should_be_second\n")
|
||||||
simple_print("should be first\n")
|
print("should be first\n")
|
||||||
}
|
}
|
||||||
for (var i = 1; i < 10; i++;) {
|
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)
|
if (i % 2 == 0)
|
||||||
continue
|
continue
|
||||||
if (i == 9)
|
if (i == 9)
|
||||||
break
|
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
|
return 0
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user