Exemplo n.º 1
0
ChunkBase::ChunkBase(World& world, wCoord xPos, wCoord yPos, wCoord zPos)
	: Chunk(xPos, yPos, zPos),
	  mLevel(world), mStorage(world.getStorage()), mChunkEntity(0), mChunkScene(0), mSceneAttached(false), mMeshGenerated(false),
	  mPhysicsIvArray(0), mPhysicsShape(0), mPhysicsBody(0), mPhysicsAttached(false),
	  mHighestCube(ChunkSizeY - 1), isEmpty(false), isSaved(false),
	  mNumVertices(0), mNumIndices(0), mVertices(0), mIndices(0), mIsModified(true), mVertexBufferCreated(false)
{
	initChunk();

	blocks.fill(0);
	blocksData.fill(0);
}
Exemplo n.º 2
0
ChunkBase::ChunkBase(World& world, wCoord xPos, wCoord yPos, wCoord zPos, std::istream& data)
	: Chunk(xPos, yPos, zPos),
	  mLevel(world), mStorage(world.getStorage()), mChunkEntity(0), mChunkScene(0), mSceneAttached(false), mMeshGenerated(false),
	  mPhysicsIvArray(0), mPhysicsShape(0), mPhysicsBody(0), mPhysicsAttached(false),
	  mHighestCube(ChunkSizeY - 1), isEmpty(false), isSaved(true),
	  mNumVertices(0), mNumIndices(0), mVertices(0), mIndices(0), mIsModified(true), mVertexBufferCreated(false)
{
	initChunk();

	data.read(reinterpret_cast<char*>(&mHighestCube), sizeof(mHighestCube));
	char empty = 0;
	data.read(&empty, sizeof(empty));
	isEmpty = (empty != 0);

	data.read(reinterpret_cast<char*>(blocks.data()), blocks.size() * sizeof(blocks[0]));
	data.read(reinterpret_cast<char*>(blocksData.data()), blocksData.size() * sizeof(blocksData[0]));
}
Exemplo n.º 3
0
void generateASM(ANTLR3_BASE_TREE *node) {
  debug(DEBUG_GENERATION, "\033[22;93mGenerate ASM\033[0m");
  initRegisters();

  program = initChunk();

  addInstruction(program, "SP EQU R15");
  addInstruction(program, "FP EQU R14");
  addInstruction(program, "DISPLAY EQU R13");
  // TODO - dynamise load adr
  addInstruction(program, "ORG 0xE000");
  addInstruction(program, "START MAIN");


  chunk *stack = stackEnvironement();
  chunk *instructionASM = computeInstruction(node);
  chunk *unstack = unstackEnvironement();


  addInstruction(program, "\n\n\n// PRGM");
  addEtiquette(program, "MAIN");
  addInstruction(program, "STACKBASE 0x1000");
  addInstruction(program, "LDW FP, SP");
  addInstruction(program, "LDW DISPLAY, #0x2000");
  addInstruction(program, "// STACK FACK RETURN");
  addInstruction(program, "ADQ -2, SP");
  appendChunks(program, stack);
  appendChunks(program, instructionASM);
  appendChunks(program, unstack);
  addInstruction(program, "// UNSTACK FACK RETURN");
  addInstruction(program, "ADQ 2, SP");


  FILE *file = fopen("a.asm", "w");
  fprintf(file, program->string);
  fclose(file);

  // printChunk(program);

  freeChunk(instructionASM);
  freeChunk(stack);
  freeChunk(unstack);
  freeChunk(program);
}
Exemplo n.º 4
0
chunk *computeInstruction(ANTLR3_BASE_TREE *node) {
  debug(DEBUG_GENERATION, "\033[22;93mCompute instruction\033[0m");

  chunk *chunk, *tmp_chunk;
  int i, scope_tmp;

  static int scope = 0;


  switch (node->getType(node)) {

    case INTEGER :
    case STRING :
    case ID :
    case FUNC_CALL :
    case SUP    :
    case INF    :
    case SUP_EQ :
    case INF_EQ :
    case EQ     :
    case DIFF   :
    case AND :
    case OR :
    case MINUS :
    case PLUS :
    case DIV :
    case MULT :
    case NEG :
    case ASSIGNE :
      return computeExpr(node);


    case IF:
      return computeIf(node);

    case WHILE :
      return computeWhile(node);

    case FOR :
      return computeFor(node);


    case VAR_DECLARATION :
      return computeVarDeclaration(node);

    case FUNC_DECLARATION :
    case LET :
      enterScopeN(scope);

      scope_tmp = scope;
      scope = 0;

      switch (node->getType(node)) {
        case LET:
          chunk = computeLet(node);
          break;
        case FUNC_DECLARATION:
          chunk = computeFuncDeclaration(node);
          break;
      }

      scope = scope_tmp;
      scope++;

      leaveScope();

      return chunk;


    default:
      chunk = initChunk();

      // Compute all children
      for (i = 0; i < node->getChildCount(node); i++) {
        tmp_chunk = computeInstruction(node->getChild(node, i));
        appendChunks(chunk, tmp_chunk);
        // appendChunks replace chunk->registre with tmp_chunk's one
        // but freeChunk free the registre of tmp_chunk
        // we don't want chunk->registre to be overwritten !
        if (tmp_chunk != NULL)
          tmp_chunk->registre = -1;
        freeChunk(tmp_chunk);
      }

      return chunk;
  }
}
Exemplo n.º 5
0
chunk *computeExpr(ANTLR3_BASE_TREE *node) {
  debug(DEBUG_GENERATION,
        "\033[22;93mCompute expression [%s] (%d:%d)\033[0m",
        (char *)node->toString(node)->chars,
        node->getLine(node),
        node->getCharPositionInLine(node));

  chunk *chunk, *chunk_left = NULL, *chunk_right = NULL;
  int type = node->getType(node);
  char *template;
  char etiq_1[10], etiq_2[10];
  static int etiq_nb = 0;


  chunk = initChunk();

  // If it's an atom, get the address to access it
  if (type == INTEGER ||
      type == STRING ||
      type == ID ||
      type == FUNC_CALL) {
    loadAtom(node, chunk);
    return chunk;
  }


  // Else get both operand chunk
  // unless it's assign, we only want the address of the left opperand
  if (type != ASSIGNE) chunk_left  = computeExpr(node->getChild(node, 0));
  // unless it's a NEG node, because NEG only has one child
  if (type != NEG)     chunk_right = computeExpr(node->getChild(node, 1));


  appendChunks(chunk, chunk_left);
  // It frees chunk_left->registre. Weird but ok because no more registre needed
  // unless for assign, but it will erased chunk_left->registre that is not initialised
  // SO KEEP THAT ORDER UNLESS YOU KNOW WHAT YOU'RE DOING !
  appendChunks(chunk, chunk_right);


  // Do operation
  switch (type) {
    case SUP :
    case INF :
    case SUP_EQ :
    case INF_EQ :
    case EQ :
    case DIFF :
      addInstruction(chunk, "SUB R%d, R%d, R%d // %d:%d",
                    chunk_left->registre,
                    chunk_right->registre,
                    chunk->registre,
                    node->getLine(node),
                    node->getCharPositionInLine(node));

      sprintf(etiq_1, "ETIQ_%d", etiq_nb++);
      sprintf(etiq_2, "ETIQ_%d", etiq_nb++);

      jumpTo(chunk, type, etiq_1, 0);

      addInstruction(chunk, "LDW R%d, #0", chunk->registre);
      jumpTo(chunk, 0, etiq_2, 0);

      addEtiquette(chunk, etiq_1);
      addInstruction(chunk, "LDW R%d, #1", chunk->registre);

      addEtiquette(chunk, etiq_2);

      chunk_right->registre = -1;

      break;


    case AND :
    case OR :
    case MINUS :
    case PLUS :
    case DIV :
    case MULT :
      switch (type) {
        case OR :
          template = "OR R%d, R%d, R%d // %d:%d";
          break;
        case MINUS :