-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpopc.c
100 lines (78 loc) · 1.91 KB
/
popc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <stdio.h>
#include <stdlib.h>
#include "popc.h"
varProto ptr varProtoNew () {
//PENDING
varProto ptr vi = NULL;
vi = (varProto ptr) malloc (sizeof (varProto));
dbcEnsure (vi != NULL, "Memory Allocation Error!");
return vi;
}
var ptr varNew (varType vt, object ptr obj) {
var ptr v;
v = (var ptr) malloc (sizeof (var));
dbcEnsure (v != NULL, "Memory Allocation Error!");
ptrVal (varType ptr) addr v->t = vt; //write to const
v -> o = obj;
return v;
}
/*
var ptr varInt (object ptr obj) {
var ptr v;
v = (var ptr) malloc (sizeof (var));
dbcEnsure (v != NULL, "Memory Allocation Error!");
//not allowed to update const: v -> vt = vtInt;
ptrVal (varType ptr) addr v->t = vtInt; //allowed to update const
v -> o = obj;
return v;
}
*/
void varDel (var ptr v) {
free (v);
}
/*
var ptr varSet (var ptr v, object ptr obj) {
}
var ptr varGet (object ptr obj) {
}
*/
arraySingleton ptr arraySingletonNew () {
static arraySingleton ptr sp = NULL;
if (sp == NULL) {
sp = (arraySingleton ptr) malloc (sizeof (arraySingleton));
dbcEnsure (sp != NULL, "Memory Allocation Error!");
}
//implement interfaces
return sp;
}
array ptr arrayNew () {
array ptr s = (array ptr) malloc (sizeof (array));
dbcEnsure (s != NULL, "Memory Allocation Error!");
//set properties
return s;
}
void arrayDel (array ptr s) {
// PENDING! need to clean-up inner objects
free (s);
s = NULL;
}
stringSingleton ptr stringSingletonNew () {
static stringSingleton ptr sp = NULL;
if (sp == NULL) {
sp = (stringSingleton ptr) malloc (sizeof (stringSingleton));
dbcEnsure (sp != NULL, "Memory Allocation Error!");
}
//implement interfaces
return sp;
}
string ptr stringNew () {
string ptr s = (string ptr) malloc (sizeof (string));
dbcEnsure (s != NULL, "Memory Allocation Error!");
//set properties
return s;
}
void stringDel (string ptr s) {
// PENDING! need to clean-up inner objects
free (s);
s = NULL;
}