-
Notifications
You must be signed in to change notification settings - Fork 4
/
utils.c
50 lines (45 loc) · 914 Bytes
/
utils.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
/* FILE: utils.c */
/*
* module : utils.c
* version : 1.50
* date : 10/11/24
*/
#include "globals.h"
/*
* newnode - allocate a new node or die trying.
*/
Index newnode(pEnv env, Operator o, Types u, Index r)
{
Index p;
p = GC_malloc(sizeof(Node));
#ifdef _MSC_VER
if (!p)
execerror(env, "memory", "allocator");
#endif
p->op = o;
p->u = u;
p->next = r;
env->nodes++;
return p;
}
/*
* newnode2 - allocate a node as copy of an existing node.
*/
Index newnode2(pEnv env, Index n, Index r)
{
return newnode(env, n->op, n->u, r);
}
/*
* Report the number of nodes that are currently being used.
*/
void my_memoryindex(pEnv env)
{
NULLARY(INTEGER_NEWNODE, GC_get_memory_use());
}
/*
* Report the total number of nodes that are currently available.
*/
void my_memorymax(pEnv env)
{
NULLARY(INTEGER_NEWNODE, GC_get_memory_use() + GC_get_free_bytes());
}