-
Notifications
You must be signed in to change notification settings - Fork 2
/
prog.c
64 lines (55 loc) · 1.11 KB
/
prog.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
/*
module : prog.c
version : 1.11
date : 04/11/24
*/
#include "globals.h"
/*
prog - push the contents of a program onto the code stack
*/
void prog(pEnv env, NodeList *list)
{
int i, j;
for (i = 0, j = pvec_cnt(list); i < j; i++)
env->prog = pvec_add(env->prog, pvec_nth(list, i));
}
/*
code - push an anonymous function onto the code stack
*/
void code(pEnv env, proc_t proc)
{
Node node;
node.u.proc = proc;
node.op = ANON_FUNCT_;
env->prog = pvec_add(env->prog, node);
}
/*
push - push an integer on the code stack
*/
void push(pEnv env, int64_t num)
{
Node node;
node.u.num = num;
node.op = INTEGER_;
env->prog = pvec_add(env->prog, node);
}
/*
prime - push node on the code stack that came from the data stack
*/
void prime(pEnv env, Node node)
{
if (node.op == USR_)
node.op = USR_PRIME_;
if (node.op == ANON_FUNCT_)
node.op = ANON_PRIME_;
env->prog = pvec_add(env->prog, node);
}
/*
pop - remove an item from the code stack
*/
Node pop(pEnv env)
{
Node node;
env->prog = pvec_pop(env->prog, &node);
return node;
}