Levels *Levels_new(IoMessage *msg) { Levels *self = io_calloc(1, sizeof(Levels)); IoState *state = IoObject_state(msg); IoSymbol *operatorTableSymbol = IoState_symbolWithCString_(state, "OperatorTable"); // Be ultra flexable, and try to use the first message's operator table. IoObject *opTable = IoObject_rawGetSlot_(msg, operatorTableSymbol); // Otherwise, use Core OperatorTable, and if that doesn't exist, create it. if (opTable == NULL) { // There is a chance the message didn't have it, but the core did---due // to the Core not being part of the message's protos. Use Core // Message's OperatorTable opTable = IoObject_rawGetSlot_(state->core, operatorTableSymbol); // If Core doesn't have an OperatorTable, then create it. if (opTable == NULL) { opTable = IoObject_new(state); IoObject_setSlot_to_(state->core, operatorTableSymbol, opTable); IoObject_setSlot_to_(opTable, IoState_symbolWithCString_(state, "precedenceLevelCount"), IoState_numberWithDouble_(state, IO_OP_MAX_LEVEL)); } } self->operatorTable = getOpTable(opTable, "operators", IoState_createOperatorTable); self->assignOperatorTable = getOpTable(opTable, "assignOperators", IoState_createAssignOperatorTable); self->stack = List_new(); Levels_reset(self); return self; }
void Levels_nextMessage(Levels *self) { Level *level; while ((level = List_pop(self->stack))) { Level_finish(level); } Levels_reset(self); }