aboutsummaryrefslogtreecommitdiff
path: root/src/id_table.h
blob: 152b0287ed274044ea866d68492486ca4a3a178f (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
#ifndef _ID_TABLE_
#define _ID_TABLE_
#include "ast.h"
#include "mytype.h"

// When NUM_AGENT is 256:
// 0 .. 255: AGENT
// 256     : NAME,
// 257 ..  : GNAME


#define ID_INT 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_INTAGENT 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_MERGER   16
#define ID_MERGER_P 17
#define ID_ADD      18
#define ID_ADD2     19
#define ID_SUB      20
#define ID_SUB2     21
#define ID_MUL      22
#define ID_MUL2     23
#define ID_DIV      24
#define ID_DIV2     25
#define ID_MOD      26
#define ID_MOD2     27
#define ID_PERCENT  28
#define END_ID_OF_BUILTIN_OP_AGENT 28

// ID_ERASER and ID_DUP was put as 254, 255
// because these IDs are wanted larger like ID_DUP > any_agent.id


#define START_ID_OF_USER_AGENT END_ID_OF_BUILTIN_OP_AGENT+1
#define END_ID_OF_AGENT 255

#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 NUM_AGENTS END_ID_OF_AGENT+1  // 256

#define ID_NAME NUM_AGENTS // starts from 256 (NUM_AGENTS)
#define START_ID_OF_GNAME  ID_NAME+1


#define NUM_GNAMES NUM_AGENTS // 256: the same as the size of AGENT


//#define IS_AGENTID(a) (a <= ID_END_ID_OF_AGENT)
#define IS_AGENTID(a) (!(a & 0x100)) // less than 256


#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