Small speed improvement int trim by using stack (and DFS) instead of queue (and BFS) for remove and collapse, finally fix the unknown escape '\*' error

This commit is contained in:
Nathan Braswell
2017-01-25 01:47:05 -05:00
parent 987e6eb9a5
commit caba8b310f
4 changed files with 12 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
import symbol:*
import tree:*
import vector:*
import queue:*
import stack:*
import map:*
import util:*

View File

@@ -1,7 +1,7 @@
import symbol:*
import tree:*
import vector:*
import queue:*
import stack:*
import map:*
import util:*
import string:*
@@ -151,7 +151,7 @@ fun trim(parse_tree: *tree<symbol>): *tree<symbol> {
return parse_tree
}
fun remove_node(remove: symbol, parse_tree: *tree<symbol>) {
var to_process = queue<*tree<symbol>>()
var to_process = stack<*tree<symbol>>()
to_process.push(parse_tree)
while(!to_process.empty()) {
var node = to_process.pop()
@@ -174,7 +174,7 @@ fun remove_node(remove: symbol, parse_tree: *tree<symbol>) {
}
}
fun collapse_node(remove: symbol, parse_tree: *tree<symbol>) {
var to_process = queue<*tree<symbol>>()
var to_process = stack<*tree<symbol>>()
to_process.push(parse_tree)
while(!to_process.empty()) {
var node = to_process.pop()

View File

@@ -196,7 +196,7 @@ fun get_builtin_function(name: string, param_types: vector<*type>, syntax: *tree
}
if (name == "&" && param_types.size == 1)
return ast_function_ptr(name, type_ptr(param_types, param_types[0]->clone_with_increased_indirection()), vector<*ast_node>(), false)
if (name == "\*" && param_types.size == 1) {
if (name == "*" && param_types.size == 1) {
if (param_types[0]->indirection == 0)
error(syntax, string("drereferencing not a pointer: ") + name)
else

View File

@@ -24,6 +24,10 @@ obj stack<T> (Object, Serializable) {
data.construct()
return this
}
fun construct(ammt: int): *stack<T> {
data.construct(ammt)
return this
}
fun copy_construct(other: *stack<T>) {
data.copy_construct(&other->data)
}
@@ -59,6 +63,9 @@ obj stack<T> (Object, Serializable) {
fun size(): int {
return data.size
}
fun available(): int {
return data.available
}
fun empty():bool {
return data.size == 0
}