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:
Nathan Braswell
2016-05-22 14:10:19 -07:00
parent 12dfa837e3
commit ce2eff42a6
9 changed files with 49 additions and 51 deletions

View File

@@ -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)
}

View File

@@ -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))*/

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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)
}

View File

@@ -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