some tests failing because things have been made reference in vector, but grammer actually generates the state set for the real grammer in 2 minutes or so after a day of profiling and bugfixing, so this is gonna be committed.
This commit is contained in:
43
stdlib/stack.krak
Normal file
43
stdlib/stack.krak
Normal file
@@ -0,0 +1,43 @@
|
||||
import vector
|
||||
|
||||
|
||||
fun stack<T>():stack<T> {
|
||||
var out.construct():stack<T>
|
||||
return out
|
||||
}
|
||||
fun stack<T>(in:T):stack<T> {
|
||||
var out.construct():stack<T>
|
||||
out.push(in)
|
||||
return out
|
||||
}
|
||||
|
||||
obj stack<T> (Object) {
|
||||
var data: vector::vector<T>
|
||||
fun construct(): *stack<T> {
|
||||
data.construct()
|
||||
return this
|
||||
}
|
||||
fun copy_construct(other: *stack<T>) {
|
||||
data.copy_construct(&other->data)
|
||||
}
|
||||
fun destruct() {
|
||||
data.destruct()
|
||||
}
|
||||
fun operator=(other: ref stack<T>) {
|
||||
data = other.data
|
||||
}
|
||||
fun push(it: ref T) {
|
||||
data.addEnd(it)
|
||||
}
|
||||
fun pop(): T {
|
||||
var toRet = data[data.size-1]
|
||||
data.remove(data.size-1)
|
||||
return toRet
|
||||
}
|
||||
fun top(): T {
|
||||
return data[data.size-1]
|
||||
}
|
||||
fun size(): int {
|
||||
return data.size
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user