void makeContextFromSymbol(SYMBOL * symbol, SYMBOL * treePtr) { CELL * contextCell; UINT * idx = envStackIdx; /* make sure symbol is not used as local in call hierachy and symbol is legal */ while(idx > envStack) { if(symbol == (SYMBOL *)*(--idx)) errorProcExt2(ERR_CANNOT_PROTECT_LOCAL, stuffSymbol(symbol)); --idx; } if(!isLegalSymbol(symbol->name)) errorProcExt2(ERR_INVALID_PARAMETER, stuffString(symbol->name)); contextCell = makeCell(CELL_CONTEXT, (UINT)symbol); contextCell->aux = (UINT)treePtr; symbol->contents = (UINT)contextCell; symbol->context = mainContext; symbol->flags |= (SYMBOL_PROTECTED | SYMBOL_GLOBAL); }
CELL * p_prefix(CELL * params) { SYMBOL * sPtr; getSymbol(params, &sPtr); return(makeCell(CELL_CONTEXT, (UINT)sPtr->context)); }
CELL * p_member(CELL * params) { CELL * key; CELL * list; long options = -1; char * ptr; ssize_t pos; key = evaluateExpression(params); params = getEvalDefault(params->next, &list); if(params != nilCell) getInteger(params, (UINT *)&options); if(isList(list->type)) list = (CELL *)list->contents; else if (list->type == CELL_STRING) { if(key->type != CELL_STRING) return(errorProcExt(ERR_STRING_EXPECTED, key)); if(options == -1) { ptr = strstr((char *)list->contents, (char *) key->contents); if(ptr) return(stuffString(ptr)); } else { pos = searchBufferRegex((char*)list->contents, 0, (char *)key->contents, list->aux - 1, options, 0); if(pos != -1) return(stuffString((char *)list->contents + pos)); } return(nilCell); } else return(errorProcExt(ERR_LIST_OR_STRING_EXPECTED, params->next)); while(list != nilCell) { if(compareCells(key, list) == 0) break; list = list->next; } if(list == nilCell) return(nilCell); return(makeCell(CELL_EXPRESSION, (UINT)copyList(list))); }
/* only for symbols starting with underscore character _ */ void collectSymbolAssocs(SYMBOL * sPtr, CELL * assocList) { CELL * cell; if(sPtr != NIL_SYM && sPtr != NULL) { collectSymbolAssocs(sPtr->left, assocList); if(*sPtr->name == '_') { cell = makeCell(CELL_EXPRESSION, (UINT)stuffString(sPtr->name + 1)); ((CELL *)cell->contents)->next = copyCell((CELL *)sPtr->contents); if(assocList->contents == (UINT)nilCell) assocList->contents = (UINT)cell; else ((CELL *)assocList->aux)->next = cell; assocList->aux = (UINT)cell; } collectSymbolAssocs(sPtr->right, assocList); } }
void ModuleEditLayer::initBoard() { cocos2d::Size moduleSize = GET_DATA_MANAGER()->getModuleSize(); cocos2d::Size tileSize = GET_DATA_MANAGER()->getTileSize(); for (auto cell : m_Cells) { removeChild(cell); } m_Cells.clear(); tileSize.width *= 0.25; tileSize.height *= 0.25; for (int x = 0; x < moduleSize.width; x++) { for (int y = 0; y < moduleSize.height; y++) { m_Cells.push_back(makeCell(MAP_CELL_START_X + x*tileSize.width, MAP_CELL_START_Y - y*tileSize.height)); addChild(m_Cells[m_Cells.size()-1]); } } }
CELL * p_push(CELL * params) { CELL * newCell; CELL * list; CELL * cell = NULL; CELL * listOrg; SYMBOL * symbolRef; int insert = 0, evalFlag = 0; ssize_t index; newCell = evaluateExpression(params); params = getEvalDefault(params->next, &list); listOrg = list; if((symbolRef = symbolCheck)) { if(isProtected(symbolCheck->flags)) return(errorProcExt2(ERR_SYMBOL_PROTECTED, stuffSymbol(symbolCheck))); if(isNil((CELL *)symbolCheck->contents)) { deleteList((CELL*)symbolCheck->contents); listOrg = makeCell(CELL_EXPRESSION, (UINT)copyCell(newCell)); symbolCheck->contents = (UINT)listOrg; goto PUSH_RETURN; } } if(!isList(list->type)) { if(list->type == CELL_STRING) { pushOnString(newCell, list, params); goto PUSH_RETURN; } else return(errorProcExt(ERR_LIST_OR_STRING_EXPECTED, list)); } if(params == nilCell) index = 0; else { cell = (CELL*)params->next; params = evaluateExpression(params); if(isList(params->type)) { evalFlag = FALSE; params = getIntegerExt((CELL*)params->contents, (UINT*)&index, FALSE); } else { evalFlag = TRUE; getIntegerExt(params, (UINT*)&index, FALSE); params = cell; } } if(index == -1) { if(params == nilCell) { newCell = copyCell(newCell); cell = (CELL*)list->aux; list->aux = (UINT)newCell; if(cell != nilCell && cell != trueCell) cell->next = newCell; else if(list->contents == (UINT)nilCell) list->contents = (UINT)newCell; else { cell = (CELL *)list->contents; while(cell->next != nilCell) cell = cell->next; cell->next = newCell; } goto PUSH_RETURN; } } list->aux = (UINT)nilCell; /* undo last element optimization */ while(isList(list->type)) { cell = list; list = (CELL *)list->contents; if(index < 0) { index = listlen(list) + index; if(index == -1) { index = 0; insert = INSERT_BEFORE; } else if(index >= 0) insert = INSERT_AFTER; else errorProc(ERR_LIST_INDEX_OUTOF_BOUNDS); } else insert = INSERT_BEFORE; while(index--) { if(list == nilCell) { if(index >= 0) errorProc(ERR_LIST_INDEX_OUTOF_BOUNDS); insert = INSERT_END; break; } cell = list; list = list->next; } if(params == nilCell || !isList(list->type)) break; params = getIntegerExt(params, (UINT*)&index, evalFlag); } newCell = copyCell(newCell); if(insert == INSERT_BEFORE || list == nilCell) { if(list == (CELL*)cell->contents) { cell->contents = (UINT)newCell; newCell->next = list; } else { cell->next = newCell; newCell->next = list; } } else if(insert == INSERT_AFTER || insert == INSERT_END) { cell = list->next; list->next = newCell; newCell->next = cell; } PUSH_RETURN: symbolCheck = symbolRef; pushResultFlag = FALSE; return(listOrg); }
CELL * findAllList(CELL * pattern, CELL * list, CELL * exprCell) { CELL * result = nilCell; CELL * cell = NULL; CELL * exprRes; CELL * match; CELL * funcCell; int errNo; UINT * resultIdxSave; funcCell = evaluateExpression(exprCell->next); resultIdxSave = resultStackIdx; if(funcCell == nilCell && !isList(pattern->type)) return(errorProcExt(ERR_LIST_EXPECTED, pattern)); while(list != nilCell) { if(funcCell == nilCell) { /* match only takes lists*/ if(!isList(list->type)) goto CONTINUE_NEXT; match = patternMatchL((CELL *)pattern->contents, (CELL *)list->contents, TRUE); if(match == NULL || match == nilCell) goto CONTINUE_NEXT; deleteList(match); } else { cleanupResults(resultIdxSave); if(compareFunc(pattern, list, funcCell) != 0) goto CONTINUE_NEXT; } /* take out sysSymbol in future, should only be used in regex */ deleteList((CELL*)sysSymbol[0]->contents); sysSymbol[0]->contents = (UINT)copyCell(list); itSymbol->contents = (UINT)list; if(exprCell != nilCell) { if((exprRes = evaluateExpressionSafe(exprCell, &errNo)) == NULL) { pushResult(result); /* push for later deletion */ longjmp(errorJump, errNo); } } else exprRes = list; exprRes = copyCell(exprRes); if(result == nilCell) { cell = exprRes; result = makeCell(CELL_EXPRESSION, (UINT)cell); } else { cell->next = exprRes; cell = cell->next; } CONTINUE_NEXT: list = list->next; } if(result == nilCell) return(getCell(CELL_EXPRESSION)); itSymbol->contents = (UINT)nilCell; return(result); }
CELL * findAllString(char * pattern, char * str, size_t size, CELL * params) { long options = 0; ssize_t findPos = -1; int len; int offset = 0; CELL * result = nilCell; CELL * cell = NULL; CELL * exprCell; CELL * exprRes; UINT * resultIdxSave; int errNo; int lastPos = -1; exprCell = params; if((params = params->next) != nilCell) getInteger(params, (UINT *)&options); resultIdxSave = resultStackIdx; while( (findPos = searchBufferRegex(str, offset, pattern, (int)size, options, &len)) != -1) { if(exprCell != nilCell) { itSymbol->contents = sysSymbol[0]->contents; if((exprRes = evaluateExpressionSafe(exprCell, &errNo)) == NULL) { pushResult(result); /* push for later deletion */ longjmp(errorJump, errNo); } exprRes = copyCell(exprRes); } else exprRes = stuffStringN(str + findPos, len); if(lastPos == findPos) { ++findPos; pushResult(exprRes); goto FINDALL_CONTINUE; } lastPos = findPos; if(result == nilCell) { cell = exprRes; result = makeCell(CELL_EXPRESSION, (UINT)cell); } else { cell->next = exprRes; cell = cell->next; } FINDALL_CONTINUE: offset = (findPos + len); cleanupResults(resultIdxSave); } if(result == nilCell) return(getCell(CELL_EXPRESSION)); itSymbol->contents = (UINT)nilCell; return(result); }