27 lines
553 B
Odin
27 lines
553 B
Odin
|
package sectr
|
||
|
|
||
|
Stack :: struct ( $ Type : typeid, $ Size : i32 ) {
|
||
|
idx : i32,
|
||
|
items : [ Size ] Type,
|
||
|
}
|
||
|
|
||
|
stack_push :: proc( using stack : ^ Stack( $ Type, $ Size ), value : Type ) {
|
||
|
verify( idx < len( items ), "Attempted to push on a full stack" )
|
||
|
|
||
|
items[ idx ] = value
|
||
|
idx += 1
|
||
|
}
|
||
|
|
||
|
stack_pop :: proc( using stack : ^ Stack( $ Type, $ Size ) ) {
|
||
|
verify( idx > 0, "Attempted to pop an empty stack" )
|
||
|
|
||
|
idx -= 1
|
||
|
if idx == 0 {
|
||
|
items[idx] = {}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
stack_peek :: proc( using stack : ^ Stack( $ Type, $ Size ) ) -> ^ Type {
|
||
|
return & items[idx]
|
||
|
}
|