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

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

Fix CFA benchmark to compile

  • Property mode set to 100644
File size: 654 bytes
RevLine 
[309be81]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) {
[75ac87e]10        ?{}( &s->head, 0 );
[309be81]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) {
[75ac87e]27        s->head = ((stack_node(T)*)malloc()){ value, s->head };
[309be81]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.