#include #include #include #include "id_table.h" static IdTableT IdTable[IDTABLE_SIZE]; static int NextAgentId, NextGnameId; void IdTable_init() { int i; NextAgentId = START_ID_OF_AGENT -1; NextGnameId = START_ID_OF_GNAME -1; // 0 : ID_INT(used in expressions) // 1 .. START_ID_OF_AGENT-1 : built-in agents // START_IS_OF_AGENT .. NUM_AGENTS-1: user defined agents // NUM_AGENTS(=ID_NAME) .. : names for (i=0; i<=END_ID_OF_AGENT; i++) { IdTable[i].name = NULL; IdTable[i].aux.arity = -1; } for (i=START_ID_OF_GNAME; iid != AST_AGENT) { return -1; } if (strcmp((char *)agent->left->sym, "Add") == 0) { id = ID_ADD; } else if (strcmp((char *)agent->left->sym, "Sub") == 0) { id = ID_SUB; } else if (strcmp((char *)agent->left->sym, "Mul") == 0) { id = ID_MUL; } else if (strcmp((char *)agent->left->sym, "Div") == 0) { id = ID_DIV; } else if (strcmp((char *)agent->left->sym, "Mod") == 0) { id = ID_MOD; } else if (strcmp((char *)agent->left->sym, "Append") == 0) { id = ID_APPEND; } else if (strcmp((char *)agent->left->sym, "Int") == 0) { id = ID_INTAGENT; } else if (strcmp((char *)agent->left->sym, "Merger") == 0) { id = ID_MERGER; } else if (strcmp((char *)agent->left->sym, "Eraser") == 0) { id = ID_ERASER; } return id; } void IdTable_set_name(int id, char *symname) { if (id > IDTABLE_SIZE) { printf("Error: The given id %d was beyond of the size of IdTable (%d)\n", id, IDTABLE_SIZE); exit(-1); } IdTable[id].name = symname; } char *IdTable_get_name(int id) { return IdTable[id].name; } void IdTable_set_arity(int id, int arity) { if ((IdTable[id].aux.arity == -1) || (IdTable[id].aux.arity == arity)) { IdTable[id].aux.arity = arity; } else { printf("Warning: The agent '%s' has been already defined as whose arity is %d, but now used as the arity is %d.\n", IdTable[id].name, IdTable[id].aux.arity, arity); IdTable[id].aux.arity = arity; } } int IdTable_get_arity(int id) { return IdTable[id].aux.arity; } void IdTable_set_heap(int id, VALUE heap) { if (id > IDTABLE_SIZE) { printf("Error: The given id %d was beyond of the size of IdTable (%d)\n", id, IDTABLE_SIZE); exit(-1); } IdTable[id].aux.heap = heap; } VALUE IdTable_get_heap(int id) { return IdTable[id].aux.heap; } int IdTable_new_agentid() { NextAgentId++; if (NextAgentId > ID_NAME) { printf("ERROR: The number of agents exceeded the size (%d) for agents in IDTABLE\n", ID_NAME); exit(-1); } return(NextAgentId); } int IdTable_new_gnameid() { NextGnameId++; if (NextGnameId < IDTABLE_SIZE) { return(NextGnameId); } else { printf("ERROR: The total number of names exceeded the size of IDTABLE (%d)\n", IDTABLE_SIZE); exit(-1); } }