Moved over compiler information printing and error to use stderr, enabled interpreter testing in tester. The interpreter passes 34/74 tests
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
kraken="kraken"
|
||||
bootstrap_commits=(cf46fb13afe66ba475db9725e9269c9c1cd3bbc3 2cd43e5a217318c70097334b3598d2924f64b362 2051f54b559ac5edf67277d4f1134aca2cb9215d ecbbcb4eda56e2467efb0a04e7d668b95856aa4b d126cbf24ba8b26e3814e2260d555ecaee86508c 947384cced5397a517a71963edc8f47e668d734f cfcaff7887a804fe77dadaf2ebb0251d6e8ae8e2)
|
||||
bootstrap_commits=(cf46fb13afe66ba475db9725e9269c9c1cd3bbc3 2cd43e5a217318c70097334b3598d2924f64b362 2051f54b559ac5edf67277d4f1134aca2cb9215d ecbbcb4eda56e2467efb0a04e7d668b95856aa4b d126cbf24ba8b26e3814e2260d555ecaee86508c 947384cced5397a517a71963edc8f47e668d734f cfcaff7887a804fe77dadaf2ebb0251d6e8ae8e2 12dfa837e31bf09adb1335219473b9a7e6db9eac)
|
||||
|
||||
|
||||
# Echo version string to a file included by kraken.krak
|
||||
|
||||
@@ -77,18 +77,18 @@ fun main(argc: int, argv: **char):int {
|
||||
var importer.construct(parse, ast_pass, vector(string(), base_dir + "/stdlib/")): importer
|
||||
importer.import(kraken_file_name)
|
||||
if (interpret_instead) {
|
||||
println("Interpreting!")
|
||||
printlnerr("Interpreting!")
|
||||
var interpret.construct(importer.name_ast_map, importer.ast_pass.ast_to_syntax): interpreter
|
||||
interpret.call_main()
|
||||
} else {
|
||||
println("Generating C")
|
||||
printlnerr("Generating C")
|
||||
var c_generator.construct(): c_generator
|
||||
var c_output_pair = c_generator.generate_c(importer.name_ast_map, importer.ast_pass.ast_to_syntax)
|
||||
var kraken_c_output_name = kraken_file_name + ".c"
|
||||
write_file(kraken_c_output_name, c_output_pair.first)
|
||||
/*println(string("linker string: ") + c_output_pair.second)*/
|
||||
var compile_string = "cc -g -O3 -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -std=c99 " + c_output_pair.second + " " + kraken_c_output_name + " -o " + executable_name
|
||||
println(compile_string)
|
||||
printlnerr(compile_string)
|
||||
system(compile_string)
|
||||
}
|
||||
|
||||
|
||||
@@ -1377,17 +1377,11 @@ fun assert(works: bool, message: string) {
|
||||
if (!works)
|
||||
error(message)
|
||||
}
|
||||
fun error(message: *char) error(string(message));
|
||||
fun error(source: *tree<symbol>, message: *char) error(source, string(message));
|
||||
fun error(message: string) error(null<tree<symbol>>(), message);
|
||||
fun error(source: *tree<symbol>, message: string) {
|
||||
println("****ERROR****")
|
||||
source = get_first_terminal(source)
|
||||
if (source) {
|
||||
print(source->data.source + ": " + source->data.position + " ")
|
||||
}
|
||||
println(message)
|
||||
exit(-1)
|
||||
/*while (true){}*/
|
||||
if (source)
|
||||
error(source->data.source + ": " + source->data.position + " " + message)
|
||||
error(message)
|
||||
}
|
||||
|
||||
|
||||
@@ -40,16 +40,16 @@ obj importer (Object) {
|
||||
import_paths.destruct()
|
||||
}
|
||||
fun import(file_name: string): *ast_node {
|
||||
println("**First Pass**")
|
||||
print("parsing: ")
|
||||
printlnerr("**First Pass**")
|
||||
printerr("parsing: ")
|
||||
var to_ret = import_first_pass(file_name)
|
||||
println()
|
||||
println("**Second Pass**")
|
||||
printlnerr()
|
||||
printlnerr("**Second Pass**")
|
||||
name_ast_map.for_each(fun(name: string, tree_pair: pair<*tree<symbol>, *ast_node>) ast_pass.second_pass(tree_pair.first, tree_pair.second);)
|
||||
println("**Third Pass**")
|
||||
printlnerr("**Third Pass**")
|
||||
name_ast_map.for_each(fun(name: string, tree_pair: pair<*tree<symbol>, *ast_node>) ast_pass.third_pass(tree_pair.first, tree_pair.second);)
|
||||
// this needs to be modified to do chaotic iteration on instantiating template classes, based on what I see in the C++ version
|
||||
println("**Fourth Pass**")
|
||||
printlnerr("**Fourth Pass**")
|
||||
name_ast_map.for_each(fun(name: string, tree_pair: pair<*tree<symbol>, *ast_node>) ast_pass.fourth_pass(tree_pair.first, tree_pair.second);)
|
||||
|
||||
/*
|
||||
@@ -77,7 +77,7 @@ obj importer (Object) {
|
||||
/*println("did not find it")*/
|
||||
}
|
||||
})
|
||||
print(file_name + ", ")
|
||||
printerr(file_name + ", ")
|
||||
var parse_tree = parse.parse_input(file, file_name)
|
||||
/*print("post-parse: "); println(file_name)*/
|
||||
/*write_file(file_name + ".parse.dot", syntax_tree_to_dot(parse_tree))*/
|
||||
|
||||
@@ -505,17 +505,16 @@ obj interpreter (Object) {
|
||||
})
|
||||
if (results.size != 1)
|
||||
error(string("wrong number of mains to call: ") + results.size)
|
||||
println("=============")
|
||||
println("calling main!")
|
||||
println("=============")
|
||||
printlnerr("=============")
|
||||
printlnerr("calling main!")
|
||||
printlnerr("=============")
|
||||
var var_stack = stack<map<string, value>>()
|
||||
var_stack.push(map<string,value>())
|
||||
var defer_stack = stack<*ast_node>()
|
||||
var result = call_function(results[0], vector<value>(), vector<*ast_node>(), &var_stack, &defer_stack, value::void_nothing(), value::void_nothing(), null<ast_node>())
|
||||
println("=============")
|
||||
println("Main returned: ")
|
||||
print_value(result)
|
||||
println("=============")
|
||||
printlnerr("=============")
|
||||
printlnerr("Done!")
|
||||
printlnerr("=============")
|
||||
|
||||
interpret_from_defer_stack(&defer_stack, &var_stack, value::void_nothing(), null<ast_node>())
|
||||
pop_and_free(&var_stack)
|
||||
|
||||
@@ -12,6 +12,8 @@ fun printlnerr<T>(toPrint: T) : void {
|
||||
printerr(toPrint)
|
||||
printerr("\n")
|
||||
}
|
||||
fun printlnerr()
|
||||
printerr("\n")
|
||||
fun printerr(toPrint: string::string) : void {
|
||||
var charArr = toPrint.toCharArray()
|
||||
printerr(charArr)
|
||||
@@ -19,7 +21,7 @@ fun printerr(toPrint: string::string) : void {
|
||||
}
|
||||
fun printerr(toPrint: *char) : void {
|
||||
fprintf(stderr, "%s", toPrint)
|
||||
fflush(0)
|
||||
// stderr is already flushed
|
||||
}
|
||||
|
||||
fun println<T>(toPrint: T) : void {
|
||||
|
||||
@@ -71,10 +71,8 @@ obj map<T,U> (Object, Serializable) {
|
||||
fun get(key: T): ref U {
|
||||
/*return values.get(keys.find(key))*/
|
||||
var key_loc = keys.find(key)
|
||||
if (key_loc == -1) {
|
||||
io::println("trying to access nonexistant key-value!")
|
||||
while (true) {}
|
||||
}
|
||||
if (key_loc == -1)
|
||||
util::error("trying to access nonexistant key-value!")
|
||||
return values.get(key_loc)
|
||||
}
|
||||
fun get_with_default(key: T, default_val: ref U): ref U {
|
||||
@@ -85,18 +83,14 @@ obj map<T,U> (Object, Serializable) {
|
||||
fun reverse_get(value: U): ref T {
|
||||
/*return values.get(keys.find(key))*/
|
||||
var value_loc = values.find(value)
|
||||
if (value_loc == -1) {
|
||||
io::println("trying to access nonexistant value-key!")
|
||||
while (true) {}
|
||||
}
|
||||
if (value_loc == -1)
|
||||
util::error("trying to access nonexistant value-key!")
|
||||
return keys.get(value_loc)
|
||||
}
|
||||
fun remove(key: T) {
|
||||
var idx = keys.find(key)
|
||||
if (idx < 0) {
|
||||
io::println("trying to remove nonexistant key-value!")
|
||||
return;
|
||||
}
|
||||
if (idx < 0)
|
||||
util::error("trying to remove nonexistant key-value!")
|
||||
keys.remove(idx)
|
||||
values.remove(idx)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import mem
|
||||
import io
|
||||
import os
|
||||
import string
|
||||
import set
|
||||
import map
|
||||
import vector
|
||||
@@ -9,6 +11,13 @@ import serialize
|
||||
// maybe my favorite function
|
||||
fun do_nothing() {}
|
||||
|
||||
fun error(message: *char) error(string::string(message));
|
||||
fun error(message: string::string) {
|
||||
io::printlnerr("****ERROR****")
|
||||
io::printlnerr(message)
|
||||
os::exit(-1)
|
||||
}
|
||||
|
||||
fun deref_equality<T>(a: *T, b: *T): bool {
|
||||
if ( (a && b && !(*a == *b)) || (a && !b) || (!a && b) )
|
||||
return false
|
||||
|
||||
@@ -40,17 +40,17 @@ fun main(argc: int, argv: **char): int {
|
||||
println(test_name + "\tFAILED!")
|
||||
all_results += pad_with_spaces(test_name) + "\tFAILED!!!\n"
|
||||
}
|
||||
/*results_file_name += ".interp"*/
|
||||
/*if (system(kraken_path + " -i " + test_name + ".krak > " + results_file_name)) error("could not interpret")*/
|
||||
/*if (file_exists(results_file_name) && file_exists(expected_results_file_name) && read_file(results_file_name) == read_file(expected_results_file_name)) {*/
|
||||
/*println(test_name + "interp\tPASSED!")*/
|
||||
/*all_results_interp += pad_with_spaces(test_name+"_interp") + "\tPASSED!\n"*/
|
||||
/*num_passed_interp++*/
|
||||
/*system(string("rm ./") + results_file_name)*/
|
||||
/*} else {*/
|
||||
/*println(test_name + "_interp\tFAILED!")*/
|
||||
/*all_results_interp += pad_with_spaces(test_name + "_interp") + "\tFAILED!!!\n"*/
|
||||
/*}*/
|
||||
results_file_name += ".interp"
|
||||
if (system(kraken_path + " -i " + test_name + ".krak > " + results_file_name)) error("could not interpret")
|
||||
if (file_exists(results_file_name) && file_exists(expected_results_file_name) && read_file(results_file_name) == read_file(expected_results_file_name)) {
|
||||
println(test_name + "interp\tPASSED!")
|
||||
all_results_interp += pad_with_spaces(test_name+"_interp") + "\tPASSED!\n"
|
||||
num_passed_interp++
|
||||
system(string("rm ./") + results_file_name)
|
||||
} else {
|
||||
println(test_name + "_interp\tFAILED!")
|
||||
all_results_interp += pad_with_spaces(test_name + "_interp") + "\tFAILED!!!\n"
|
||||
}
|
||||
system(string("rm ./") + test_name + ".krak.*")
|
||||
system(string("rm ./") + test_name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user