blob: 48a257ee2d58892e29b746a069ddba68b132a542 (
plain) (
blame)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#ifndef ID_TABLE_H_
#define ID_TABLE_H_
#include "ast.h"
#include "mytype.h"
// When NUM_AGENT is 256:
// 0 .. 255: AGENT
// 256 : NAME,
// 257 .. : GNAME
#define ID_FLOAT 0
// NOTE:
// For a NEW BUILT-IN AGENT,
// STORE the ARITY on IdTable in the function IdTable_init()!
#define ID_TUPLE0 1
#define ID_TUPLE1 2
#define ID_TUPLE2 3
#define ID_TUPLE3 4
#define ID_TUPLE4 5
#define ID_TUPLE5 6
#define GET_TUPLEID(arity) (ID_TUPLE0+arity)
#define IS_TUPLEID(id) ((id >= ID_TUPLE0) && (id <= ID_TUPLE5))
#define GET_TUPLEARITY(id) (id - ID_TUPLE0)
#define ID_NIL 7
#define ID_CONS 8
#define IS_LISTID(id) ((id == ID_NIL) && (id == ID_CONS))
#define ID_WILDCARD 9
#define ID_FLOATAGENT 10 // This is an experimental dummy agent
// to show the use effect of Int agent.
#define START_ID_OF_BUILTIN_CONSTRUCTOR_AGENT 10
#define START_ID_OF_BUILTIN_OP_AGENT 15
#define ID_APPEND 15
#define ID_ZIP 16
#define ID_ZIPC 17
#define ID_MERGER 18
#define ID_MERGER_P 19
#define ID_ADD 20
#define ID_ADD2 21
#define ID_SUB 22
#define ID_SUB2 23
#define ID_MUL 24
#define ID_MUL2 25
#define ID_DIV 26
#define ID_DIV2 27
#define ID_MOD 28
#define ID_MOD2 29
#define ID_PERCENT 30
#define ID_MAP 31
#define END_ID_OF_BUILTIN_OP_AGENT 31
// ID_ERASER and ID_DUP were put as 254, 255
// because these IDs are wanted larger like ID_DUP > any_agent.id
#define NUM_AGENTS 1000 // Increased from 256
#define START_ID_OF_USER_AGENT END_ID_OF_BUILTIN_OP_AGENT+1
#define END_ID_OF_AGENT (NUM_AGENTS-1)
#define END_ID_OF_USER_AGENT END_ID_OF_AGENT-2
#define ID_ERASER END_ID_OF_AGENT-1
#define ID_DUP END_ID_OF_AGENT
#define ID_NAME NUM_AGENTS // starts from 1000
#define START_ID_OF_GNAME ID_NAME+1
#define NUM_GNAMES 1000000 // 1,000,000 global names
#define IS_AGENTID(a) ((a) < ID_NAME)
#define IS_NAMEID(a) ((a) >= ID_NAME)
#define IS_GNAMEID(a) ((a) > ID_NAME)
#define IS_LOCAL_NAMEID(a) ((a) == ID_NAME)
//#define IS_BUILTIN_AGENTID(a) (a <= END_ID_OF_BUILTIN_AGENT)
#define SET_LOCAL_NAMEID(a) ((a) = ID_NAME)
/**************************************
TABLE for SYMBOLS
**************************************/
typedef struct {
char *name;
union {
int arity;
VALUE heap;
} aux;
} IdTableT;
#define IDTABLE_SIZE (NUM_AGENTS + NUM_GNAMES) // AGENT + GNAME
void IdTable_init();
void IdTable_set_name(int id, char *symname);
char *IdTable_get_name(int id);
void IdTable_set_arity(int id, int arity);
int IdTable_get_arity(int id);
void IdTable_set_heap(int id, VALUE heap);
VALUE IdTable_get_heap(int id);
int IdTable_new_agentid();
int IdTable_new_gnameid();
int IdTable_getid_builtin_funcAgent(Ast *agent);
#endif
|