aboutsummaryrefslogtreecommitdiff
path: root/src/id_table.h
blob: 7567b701d538e110809fcdab8f664b024bbbbe49 (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
#ifndef _ID_TABLE_
#define _ID_TABLE_


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


#define ID_INT 0

// builtin を加えたら void IdTable_init() 内で
// IdTable に arity と 表示方法の登録を忘れないように!
#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_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 END_ID_OF_BUILTIN_AGENT 27

 
#define START_ID_OF_AGENT END_ID_OF_BUILTIN_AGENT+1
//#define NUM_AGENTS 1024
#define END_ID_OF_AGENT 255
#define NUM_AGENTS END_ID_OF_AGENT+1  // 256

#define ID_NAME NUM_AGENTS // 256
#define START_ID_OF_GNAME  ID_NAME+1
#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;
  int arity;
} IdTableT;

#define IDTABLE_SIZE  (NUM_AGENTS)*2 // AGENT + NAME

void IdTable_init();
void IdTable_set_name(int id, char *symname);
void IdTable_set_arity(int id, int arity);
char *IdTable_get_name(int id);
int IdTable_get_arity(int id);
int IdTable_new_agentid();
int IdTable_new_gnameid();

int IdTable_getid_builtin_funcAgent(Ast *agent);
int IdTable_is_builtin_rule(Ast *agentL, Ast *agentR);


#endif