There was an error while loading. Please reload this page.
1 parent c235fe2 commit 02e1435Copy full SHA for 02e1435
1 file changed
libs/core/lib/memory/stack_allocator.hcs
@@ -0,0 +1,34 @@
1
+struct StackAllocator [
2
+ data: List<Int>
3
+]
4
+
5
+fun stack_new() -> StackAllocator [
6
+ let s = StackAllocator([])
7
+ end s
8
9
10
+!! Odklada wartosc na wierzch stosu. Zwraca nowy rozmiar stosu.
11
+fun stack_push(s: StackAllocator, value: Int) -> Int [
12
+ s.data = s.data + [value]
13
+ end s.data.len()
14
15
16
+!! Zdejmuje i zwraca wartosc z wierzchu stosu.
17
+fun stack_pop(s: StackAllocator) -> Int [
18
+ manual [
19
+ if s.data.len() <= 0 [
20
+ log("stack_allocator: pop na pustym stosie")
21
+ ]
22
23
+ end s.data.pop().unwrap()
24
25
26
+!! Podglada wartosc na wierzchu bez zdejmowania.
27
+fun stack_peek(s: StackAllocator) -> Int [
28
+ let top_idx = s.data.len() - 1
29
+ end s.data[top_idx]
30
31
32
+fun stack_len(s: StackAllocator) -> Int [
33
34
0 commit comments