source: doc/generic_types/evaluation/cfa-stack.c @ 7a026ff

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since 7a026ff was 309be81, checked in by Aaron Moss <a3moss@…>, 5 years ago

Started evaluation benchmarks for paper (CFA version doesn't compile yet)

  • Property mode set to 100644
File size: 630 bytes
Line 
1#include <stdlib>
2#include "cfa-stack.h"
3
4forall(otype T) struct stack_node {
5        T value;
6        stack_node(T)* next;
7};
8
9forall(otype T) void ?{}(stack(T)* s) {
10        ?{}( s->head, 0 );
11}
12
13forall(otype T) void ^?{}(stack(T)* s) {
14        stack_node(T)* next = s->head;
15        while ( next ) {
16                stack_node(T)* crnt = next;
17                next = crnt->next;
18                delete(crnt);
19        }
20}
21
22forall(otype T) _Bool empty(const stack(T)* s) {
23        return s->head == 0;
24}
25
26forall(otype T) void push(stack(T)* s, T value) {
27        s->head = new( value, s->head );
28}
29
30forall(otype T) T pop(stack(T)* s) {
31        stack_node(T)* n = s->head;
32        s->head = n->next;
33        T x = n->value;
34        delete(n);
35        return x;
36}
Note: See TracBrowser for help on using the repository browser.