source: doc/generic_types/evaluation/cfa-stack.c@ 75ac87e

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 75ac87e was 75ac87e, checked in by Aaron Moss <a3moss@…>, 9 years ago

Fix CFA benchmark to compile

  • Property mode set to 100644
File size: 654 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 = ((stack_node(T)*)malloc()){ 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.