CalculationSymbol::CalculationSymbol(const CalculationSymbol& v) { switch (v.type) { case INT: makeInt(v.mem.intValue); break; case FLOAT: makeFloat(v.getFloat()); break; case STRING: makeString(v.getString()); break; } }
// // ::makeData // // Pushes data members to the stack for an extended print call. // void makeData(ObjectVector *objects, FormatData &data) { makeInt(objects, data.flags); if(data.width == -1) makeExpr(objects, VariableType::get_bt_int()); else makeInt(objects, data.width); if(data.prec == -1) makeExpr(objects, VariableType::get_bt_int()); else makeInt(objects, data.prec); makeInt(objects, data.fmt); }
void initTypes() { typeErrors = 0; intType = makeInt(); boolType = makeBool(); stringType = makeString(); voidType = makeVoid(); }
int AX12::presentPSL (int* PSL) { // lee position, speed & load de una sola vez AX12data data = readData (PRESENT_POSITION, 6); for (byte f=0; f<3; f++) { PSL[f] = makeInt (&data.data[2*f], 2); processValue (PRESENT_POSITION + 2*f, &PSL[f]); } return data.error; }
AstNode * makeObject() { AstNode *object; AstNode *equMeth, *construct, *destruct; AstNode *declator, *fparam; AstNode *ret, *eq; Literal *classLit, *oLit, *equalsLit; /* * Build the * int equals(Object o) { return this == o; } * method. */ classLit = makeLiteral(OBJECT_NAME, 0); oLit = makeLiteral("o", 0); fparam = makeFormalParam(makeNameId(classLit), makeNameId(oLit), 0); equalsLit = makeLiteral("equals", 0); declator = makeMethDeclator(makeNameId(equalsLit), makeSeq(fparam), 0); eq = makeBinaryOp(EQU_OP, makeThis(0), makeExprId(oLit), 0); ret = makeReturnSt(eq, 0); equMeth = makeMethDecl(makeInt(0), declator, makeSeq(ret), 0); /* * Build * Object() { return; } * constructor */ declator = makeConstDeclator(makeNameId(classLit), NULL, 0); construct = makeConstDecl(declator, makeSeq(makeReturnSt(NULL, 0)), 0); /* * Build * ~Object() { return; } * destructor */ destruct = makeDestructor(makeNameId(classLit), makeSeq(makeReturnSt(NULL, 0)), 0); /* * Link the class all together. */ object = makeClass(makeNameId(classLit), NULL, appendSeq(appendSeq(makeSeq(equMeth), makeSeq(construct)), makeSeq(destruct)), 0); return object; }
/** "intelligent" read data */ AX12info AX12::readInfo (byte registr) { byte reglength = lengthRead (registr); AX12info returninfo; returninfo.error = -2; if (reglength == 0) {return returninfo;} AX12data returndata = readData (registr, reglength); returninfo.error = returndata.error; returninfo.value = makeInt (returndata.data, reglength); processValue (registr, &returninfo.value); return returninfo; }
void int_09 (int scan_code) { byte aux_chr = 0; int ctrl_chr = scan_code & 0x80; if (ctrl_chr) breakInt(scan_code); else aux_chr = makeInt(scan_code); if (aux_chr) write_buffer(aux_chr); }
/** retorna el código interno de error; 0 = OK */ byte AX12::ax12ReadPacket (int* status_id, int* status_error, int* status_data) { unsigned long ulCounter; byte timeout, error, status_length, checksum, offset; byte volatile bcount; // primero espera que llegue toda la data offset = 0; timeout = 0; bcount = 0; while(bcount < 13){ // 10 es el largo máximo que puede tener un packet ulCounter = 0; while((bcount + offset) == ax_rx_Pointer){ if(ulCounter++ > 1000L){ // was 3000 timeout = 1; break; } } if (timeout) break; if ((bcount == 0) && (ax_rx_buffer[offset] != 0xff)) offset++; else bcount++; } setNone(); // ahora decodifica el packet // corrección de cabecera error = 0; // código interno de error do { error++; offset++; bcount--; } while (ax_rx_buffer[offset] == 255); if (error > 1) error =0; // prueba de cabecera // offset = primer byte del mensaje (sin cabecera) // bcount = largo del mensaje leido (sin cabecera) status_length = 2 + ax_rx_buffer[offset+1]; // largo del mensaje decodificado if (bcount != status_length) error+=2; // prueba de coherencia de data checksum = 0; // cálculo de checksum for (byte f=0; f<status_length; f++) checksum += ax_rx_buffer[offset+f]; if (checksum != 255) error+=4; // prueba de checksum if (error == 0) { *status_id = ax_rx_buffer[offset]; *status_error = ax_rx_buffer[offset+2]; switch (status_length) { case 5: *status_data = ax_rx_buffer[offset+3]; break; case 6: *status_data = makeInt (ax_rx_buffer[offset+3], ax_rx_buffer[offset+4]); break; default: *status_data = offset+3; } } else { *status_id = -1; *status_error = -1; *status_data = -1; } return error; }
// Parses the ConfigU6 packet into something useful. void parseConfigU6Bytes(BYTE * recBuffer){ printf("Results of ConfigU6:\n"); printf(" FirmwareVersion = %d.%02d\n", recBuffer[10], recBuffer[9]); printf(" BootloaderVersion = %d.%02d\n", recBuffer[12], recBuffer[11]); printf(" HardwareVersion = %d.%02d\n", recBuffer[14], recBuffer[13]); printf(" SerialNumber = %d\n", makeInt(recBuffer, 15)); printf(" ProductID = %d\n", makeShort(recBuffer, 19)); printf(" LocalID = %d\n", recBuffer[21]); printf(" VersionInfo = %d\n", recBuffer[37]); if( recBuffer[37] == 4 ){ printf(" DeviceName = U6\n"); } else if(recBuffer[37] == 12) { printf(" DeviceName = U6-Pro\n"); } }
// // ::doFormat_s // void doFormat_s(ObjectVector *objects, FormatData &data) { SourceExpression::Pointer argExpr = nextExpr(); VariableType::Reference argType = argExpr->getType(); VariableType::BasicType argBT = argType->getBasicType(); VariableData::Pointer tmp = VariableData::create_stack(argType->getSize(pos)); if(argBT == VariableType::BT_STR) { argExpr->makeObjects(objects, tmp); objects->addToken(OCODE_ACSP_STR); return; } if(argBT == VariableType::BT_ARR) { argBT = VariableType::BT_PTR; argType = argType->getReturn()->getPointer(); argExpr = create_value_cast_implicit(argExpr, argType, context, pos); } if (argBT != VariableType::BT_PTR) Error_NP("expected pointer got %s", make_string(argType).c_str()); // Convert auto* to static*. StoreType argStore = argType->getReturn()->getStoreType(); if (argStore == STORE_AUTO) argStore = STORE_STATIC; // For string* or custom print rules, cast to far*. if(data.flags || data.width || data.prec || argStore == STORE_STRING) argStore = STORE_FAR; argType = argType->getReturn(); argType = VariableType::get_bt_chr() ->setQualifier(argType->getQualifiers()) ->setStorage(argStore, argType->getStoreArea()) ->getPointer(); argExpr = create_value_cast_implicit(argExpr, argType, context, pos); // Special handling for far*. if(argStore == STORE_FAR) { makeData(objects, data); argExpr->makeObjects(objects, tmp); objects->addToken(OCODE_JMP_CAL_NIL_IMM, objects->getValue("__Print_s")); return; } argExpr->makeObjects(objects, tmp); switch (argType->getReturn()->getStoreType()) { case STORE_STATIC: makeInt(objects, option_addr_array); objects->addToken(OCODE_ACSP_STR_GBLARR); break; case STORE_NONE: case STORE_FAR: case STORE_AUTO: case STORE_CONST: case STORE_STRING: Error_NP("cannot %%s pointer"); case STORE_REGISTER: case STORE_MAPREGISTER: case STORE_WORLDREGISTER: case STORE_GLOBALREGISTER: Error_NP("cannot %%s register-pointer"); case STORE_MAPARRAY: objects->addToken(OCODE_GET_IMM, objects->getValue(argType->getReturn()->getStoreArea())); objects->addToken(OCODE_ACSP_STR_MAPARR); break; case STORE_WORLDARRAY: objects->addToken(OCODE_GET_IMM, objects->getValue(argType->getReturn()->getStoreArea())); objects->addToken(OCODE_ACSP_STR_WLDARR); break; case STORE_GLOBALARRAY: objects->addToken(OCODE_GET_IMM, objects->getValue(argType->getReturn()->getStoreArea())); objects->addToken(OCODE_ACSP_STR_GBLARR); break; } }
void SecondPassBinary::resolveStack(BinaryDependencies::DependencyObject& dependency, FirstPassBinary& firstPass, addressNumericValue binaryAddress, addressNumericValue dependencyAddress, uint dataStartAddress) { uint relocatePositionTo = dependencyAddress; uint currentPosition = binaryAddress + dependency.m_position; int distance = relocatePositionTo; distance-= currentPosition; switch (dependency.m_type) { case BinaryDependencies::DEP_STACK_ARG: distance = firstPass.getStackSize() + firstPass.getNonVolatilesSize(); break; case BinaryDependencies::DEP_STACK_LOCAL: distance = firstPass.getStackSize(); break; case BinaryDependencies::DEP_STACK_TEMP: distance = firstPass.getStackSize() - firstPass.getStackBaseSize(); break; default: CHECK_FAIL(); } switch (dependency.m_length) { case BinaryDependencies::DEP_8BIT: { if (dependency.m_shouldAddExistValue) distance += ((char)m_data[dataStartAddress + dependency.m_position]); // If we fails here, it means that the basic-block should have been arranged better CHECK_RELOCATION_RANGE(t_abs(distance), 0x100); distance >>= dependency.m_shiftRightCount; m_data[dataStartAddress + dependency.m_position] = ((int8)(distance)); } break; /* case BinaryDependencies::DEP_3BIT_3SKIP: { uint16 oldValue = cEndian::readUint16(m_data.getBuffer() + dependency.m_position + dataStartAddress, OpcodeSubsystems::isLittleEndian(m_type)); if (dependency.m_shouldAddExistValue) { // TODO! Pavel - It's doesn't look right... distance += makeInt(((oldValue >> 3) & 0x07), 3); } // If we fails here, it means that the basic-block should have been arranged better CHECK_RELOCATION_RANGE(t_abs(distance), 0x100); // TODO! Pavel - It's doesn't look right... oldValue = (oldValue & 0xF83F) + ((distance & 3) << 6) + ((distance & 0x1C) << 4); cEndian::writeUint16(m_data.getBuffer() + dependency.m_position + dataStartAddress, oldValue, OpcodeSubsystems::isLittleEndian(m_type)); } break; */ case BinaryDependencies::DEP_4BIT_LOWER: { char oldVal = ((char)m_data[dataStartAddress + dependency.m_position]); if (dependency.m_shouldAddExistValue) distance += makeInt(oldVal & 0x0F, 4); distance >>= dependency.m_shiftRightCount; CHECK_RELOCATION_RANGE(t_abs(distance), 0x10); m_data[dataStartAddress + dependency.m_position] = ((int8)((oldVal & 0xF0) + (distance & 0x0F))); } break; case BinaryDependencies::DEP_5BIT_5SPACE: { uint16 oldValue = cEndian::readUint16(m_data.getBuffer() + dependency.m_position + dataStartAddress, OpcodeSubsystems::isLittleEndian(m_type)); if (dependency.m_shouldAddExistValue) { distance+= makeInt((((oldValue >> 8) << 2) + (oldValue & 3)) & 0x1F, 5); } oldValue = (oldValue & 0xF83F) + ((distance & 3) << 6) + ((distance & 0x1C) << 4); CHECK_RELOCATION_RANGE(t_abs(distance), 0x20); cEndian::writeUint16(m_data.getBuffer() + dependency.m_position + dataStartAddress, oldValue, OpcodeSubsystems::isLittleEndian(m_type)); } break; case BinaryDependencies::DEP_8BIT_4SPACE: { uint16 oldValue = cEndian::readUint16(m_data.getBuffer() + dependency.m_position + dataStartAddress, OpcodeSubsystems::isLittleEndian(m_type)); if (dependency.m_shouldAddExistValue) { distance += makeInt(((oldValue & 0xF00) >> 4) + (oldValue & 0x0F), 8); } CHECK_RELOCATION_RANGE(t_abs(distance), 0x100); oldValue = ((distance & 0xF0) << 4) + (oldValue & 0xF0F0) + (distance & 0x0F); cEndian::writeUint16(m_data.getBuffer() + dependency.m_position + dataStartAddress, oldValue, OpcodeSubsystems::isLittleEndian(m_type)); }
void typeEXP(EXP* e) { int counter; if(e == NULL) return; if(e->next != NULL) typeEXP(e->next); switch(e->kind) { case lvalueK: typeLVALUE(e->val.lvalueE); e->type = e->val.lvalueE->type; break; case assignK: typeLVALUE(e->val.assignE.lvalue); typeEXP(e->val.assignE.expr); if(compareTypes(e->val.assignE.lvalue->type, e->val.assignE.expr->type)) { e->type = e->val.assignE.lvalue->type; } else { printf("%d: Type Error: Assignment of incompatible types.\n", e->lineno); typeErrors++; } break; case equalsK: typeEXP(e->val.equalsE.left); typeEXP(e->val.equalsE.right); if(compareTypes(e->val.equalsE.left->type, e->val.equalsE.right->type)) { e->type = makeBool(); } else { printf("%d: Type Error: Comparing incompatible types.\n", e->lineno); typeErrors++; } break; case notequalsK: typeEXP(e->val.notequalsE.left); typeEXP(e->val.notequalsE.right); if(compareTypes(e->val.notequalsE.left->type, e->val.notequalsE.right->type)) { e->type = makeBool(); } else { printf("%d: Type Error: Comparing incompatible types.\n", e->lineno); typeErrors++; } break; case ltK: typeEXP(e->val.ltE.left); typeEXP(e->val.ltE.right); if(compareTypes(e->val.ltE.left->type, e->val.ltE.right->type)) { e->type = makeBool(); } else { printf("%d: Type Error: Comparing incompatible types.\n", e->lineno); typeErrors++; } if(!compareTypes(stringType, e->val.ltE.left->type) && !compareTypes(intType, e->val.ltE.left->type)) { printf("%d: Type Error: Comparisons can only be between ints or strings.\n", e->lineno); typeErrors++; } break; case gtK: typeEXP(e->val.gtE.left); typeEXP(e->val.gtE.right); if(compareTypes(e->val.gtE.left->type, e->val.gtE.right->type)) { e->type = makeBool(); } else { printf("%d: Type Error: Comparing incompatible types.\n", e->lineno); typeErrors++; } if(!compareTypes(stringType, e->val.gtE.left->type) && !compareTypes(intType, e->val.gtE.left->type)) { printf("%d: Type Error: Comparisons can only be between ints or strings.\n", e->lineno); typeErrors++; } break; case lteK: typeEXP(e->val.lteE.left); typeEXP(e->val.lteE.right); if(compareTypes(e->val.lteE.left->type, e->val.lteE.right->type)) { e->type = makeBool(); } else { printf("%d: Type Error: Comparing incompatible types.\n", e->lineno); typeErrors++; } if(!compareTypes(stringType, e->val.lteE.left->type) && !compareTypes(intType, e->val.lteE.left->type)) { printf("%d: Type Error: Comparisons can only be between ints or strings.\n", e->lineno); typeErrors++; } break; case gteK: typeEXP(e->val.gteE.left); typeEXP(e->val.gteE.right); if(compareTypes(e->val.gteE.left->type, e->val.gteE.right->type)) { e->type = makeBool(); } else { printf("%d: Type Error: Comparing incompatible types.\n", e->lineno); typeErrors++; } if(!compareTypes(stringType, e->val.gteE.left->type) && !compareTypes(intType, e->val.gteE.left->type)) { printf("%d: Type Error: Comparisons can only be between ints or strings.\n", e->lineno); typeErrors++; } break; case notK: typeEXP(e->val.exprE); if(compareTypes(boolType, e->val.exprE->type)) e->type = makeBool(); else { printf("%d: Type Error: bool type expected.\n", e->lineno); typeErrors++; } break; case plusK: typeEXP(e->val.plusE.left); typeEXP(e->val.plusE.right); counter = 0; if(compareTypes(stringType, e->val.plusE.left->type)) counter++; else if(!compareTypes(intType, e->val.plusE.left->type)) { printf("%d: Type Error: incorrect types for operator '+'.\n", e->lineno); typeErrors++; } if(compareTypes(stringType, e->val.plusE.right->type)) counter++; else if(!compareTypes(intType, e->val.plusE.right->type)) { printf("%d: Type Error: incorrect types for operator '+'.\n", e->lineno); typeErrors++; } if(counter > 0) e->type = makeString(); else e->type = makeInt(); break; case minusK: typeEXP(e->val.minusE.left); typeEXP(e->val.minusE.right); if(compareTypes(e->val.minusE.left->type, e->val.minusE.right->type) && compareTypes(intType, e->val.minusE.left->type)) { e->type = makeInt(); } else { printf("%d: Type Error: Expected type int for subtraction.\n", e->lineno); typeErrors++; } break; case multK: typeEXP(e->val.multE.left); typeEXP(e->val.multE.right); if(compareTypes(e->val.multE.left->type, e->val.multE.right->type) && compareTypes(intType, e->val.multE.left->type)) { e->type = makeInt(); } else { printf("%d: Type Error: Expected type int for multiplication.\n", e->lineno); typeErrors++; } break; case divK: typeEXP(e->val.divE.left); typeEXP(e->val.divE.right); if(compareTypes(e->val.divE.left->type, e->val.divE.right->type) && compareTypes(intType, e->val.divE.left->type)) { e->type = makeInt(); } else { printf("%d: Type Error: Expected type int for division.\n", e->lineno); typeErrors++; } break; case modK: typeEXP(e->val.modE.left); typeEXP(e->val.modE.right); if(compareTypes(e->val.modE.left->type, e->val.modE.right->type) && compareTypes(intType, e->val.modE.left->type)) { e->type = makeInt(); } else { printf("%d: Type Error: Expected type int for mod.\n", e->lineno); typeErrors++; } break; case andK: typeEXP(e->val.andE.left); typeEXP(e->val.andE.right); if(compareTypes(e->val.andE.left->type, e->val.andE.right->type) && compareTypes(boolType, e->val.andE.left->type)) { e->type = makeBool(); } else { printf("%d: Type Error: Expected type bool for &&.\n", e->lineno); typeErrors++; } break; case orK: typeEXP(e->val.orE.left); typeEXP(e->val.orE.right); if(compareTypes(e->val.orE.left->type, e->val.orE.right->type) && compareTypes(boolType, e->val.orE.left->type)) { e->type = makeBool(); } else { printf("%d: Type Error: Expected type bool for ||.\n", e->lineno); typeErrors++; } break; case joinK: typeEXP(e->val.joinE.left); typeEXP(e->val.joinE.right); if(e->val.joinE.left->type->schema == NULL || e->val.joinE.right->type->schema == NULL) { return; } e->type = NEW(TYPE); e->type->kind = tupleidK; e->type->schema = joinTuples(e->val.joinE.left->type->schema, e->val.joinE.right->type->schema); break; case keepK: typeEXP(e->val.keepE.left); e->type = NEW(TYPE); e->type->kind = tupleidK; e->type->schema = keepIDs(e->val.keepE.left->type->schema, e->val.keepE.right); if(e->type->schema == NULL) { printf("%d: Type Error: Identifiers are not a subset of schema fields.\n", e->lineno); typeErrors++; } break; case removeK: typeEXP(e->val.removeE.left); e->type = NEW(TYPE); e->type->kind = tupleidK; e->type->schema = removeIDs(e->val.keepE.left->type->schema, e->val.keepE.right); if(e->type->schema == NULL) { printf("%d: Type Error: Identifiers are not a subset of schema fields.\n", e->lineno); typeErrors++; } break; case callK: typeARGUMENT(e->val.callE.left->symbol->val.functionS->argument, e->val.callE.right); e->type = e->val.callE.left->symbol->val.functionS->type; break; case tupleK: typeFIELDVALUE(e->val.tupleE); e->type = NEW(TYPE); e->type->kind = tupleidK; /* SEGFAULT WARNING TODO HELP */ e->type->schema = NEW(SCHEMA); makeAnonymousTuple(e->type->schema, e->val.tupleE); break; case parenK: typeEXP(e->val.exprE); e->type = e->val.exprE->type; break; case intconstK: e->type = makeInt(); break; case trueK: e->type = makeBool(); break; case falseK: e->type = makeBool(); break; case stringconstK: e->type = makeString(); break; } }
int main (void) { char* requete; query* q=NULL; line* ligne= create_line(7);; data *d; system("clear"); printf(" Test et simultation d'une session d'utilisation de littleBD avec un pronpteur \n"); printf(" Exercice 1 : Comprehension LOAD SAVE EXIT SELECT * FROM Table \n\n"); requete = "LOAD basededonnee.sql"; testfusion(requete,q); requete = "LOAD basededonnee.sql.old"; testfusion(requete,q); printf(" /*prise en charge des fichiers.old */ \n"); pause(); requete = "SAVE"; testfusion(requete,q); requete = "EXIT"; testfusion(requete,q); requete = "SELECT * FROM Table"; testfusion(requete,q); pause(); printf(" Exercice 2 : Fusion de query et de la structure \n\n"); printf(" Requete implemente CREATE TABLE \n"); requete = "CREATE TABLE toto ( id INT, ville CHAR)"; testfusion(requete,q); printf(" Comprehenion et restitution des autres requetes : \n"); requete = "DELETE FROM toto WHERE id = '1'"; testfusion(requete,q); requete = "INSERT INTO toto ( id , ville ) VALUES ( 1 , 'c' )"; testfusion(requete,q); pause(); requete = "DROP TABLE toto"; testfusion(requete,q); requete = "SELECT id FROM toto WHERE ! ( id > 1 AND c = 'c' )"; testfusion(requete,q); pause(); printf(" Exercice 3.1 : Effacer une ligne \n\n"); printf(" Create Line ( 7 ) \n"); print_line (ligne); printf(" Remplissage de la ligne ... \n"); d=makeInt(1); update_line(ligne,*d,1); d=makeCar('c'); update_line(ligne,*d,2); d=makeInt(345); update_line(ligne,*d,3); d=makeInt(2113); update_line(ligne,*d,4); d=makeInt(303); update_line(ligne,*d,6); print_line(ligne); printf("\n Deleteline \n"); delete_line(ligne); print_line(ligne); return EXIT_SUCCESS; }