Ejemplo n.º 1
0
void Script_v6::o6_assign(FuncParams &params) {
	uint8 type = peekUint8();
	uint16 var_0, var_4;
	std::string varIndex = readVarIndex(&var_0, &var_4);

	if (var_0 != 0) {
		std::string varIndex2;
		uint16 var_6;

		uint32 savedPos = getPos();

		varIndex2 = readVarIndex(&var_6, 0);

		printIndent();
		print("memcpy(%s, %s, %d);\n", varIndex.c_str(), varIndex2.c_str(), var_6 * 4);

		seek(savedPos);
		skipExpr(99);

		return;
	}

	if (peekUint8() == 98) {
		skip(1);
		uint8 loopCount = readUint8();

		uint32 off = 0;
		for (uint16 i = 0; i < loopCount; i++) {
			uint8 c = readUint8();
			uint16 n = readUint16();

			printIndent();
			print("memset(%s + %d, %d, %d);\n", varIndex.c_str(), off, c, n);

			off += n;
		}
	} else if (peekUint8() == 99) {
		skip(1);
		uint8 loopCount = readUint8();

		for (uint16 i = 0; i < loopCount; i++) {
			std::string expr = readExpr();
			printIndent();
			print("%s[%d] = %s;\n", varIndex.c_str(), (type == 24) ? (i * 2) : i, expr.c_str());
		}
	} else {
		std::string expr = readExpr();

		printIndent();
		print("%s = %s;\n", varIndex.c_str(), expr.c_str());
	}
}
Ejemplo n.º 2
0
void Script_v2::o2_assign(FuncParams &params) {
	uint8 type = peekUint8();
	std::string varIndex = readVarIndex();

	if (peekUint8() == 99) {
		skip(1);
		uint8 loopCount = readUint8();

		for (uint16 i = 0; i < loopCount; i++) {
			std::string expr = readExpr();
			printIndent();
			print("%s[%d] = %s;\n", varIndex.c_str(), (type == 24) ? (i * 2) : i, expr.c_str());
		}
	} else {
		std::string expr = readExpr();

		printIndent();
		print("%s = %s;\n", varIndex.c_str(), expr.c_str());
	}
}
Ejemplo n.º 3
0
void Script_v2::o2_pushVars(FuncParams &params) {
	uint8 count = readUint8();

	for (uint16 i = 0; i < count; i++) {
		printIndent();
		if ((peekUint8() == 25) || (peekUint8() == 28)) {
			print("push(%s, animDataSize);\n", readVarIndex().c_str());
			skip(1);
		} else
			print("push(%s, 4);\n", readExpr().c_str());
	}
}
Ejemplo n.º 4
0
void Script_v6::o6_createSprite(FuncParams &params) {
	uint32 pos;

	pos = getPos();
	skip(1);

	startFunc(params);
	if (peekUint8() == 0) {
		seek(pos);
		print("%d, ", readUint16());
		print("%d, ", readUint16());
		print("%d, ", readUint16());
	} else {
		seek(pos);
		print("%s, ", readExpr().c_str());
		print("%s, ", readExpr().c_str());
		print("%s, ", readExpr().c_str());
	}
	print("%d", readUint16());
	endFunc();
}
int ScriptParser::debugprintCommand()
{
    do {
	const char* s = readExpr(script_h);
	if (!s) s = "[no token]";
	if (s[0] == '`') ++s;
	fputs(s, stdout);
    }
    while (script_h.getEndStatus() & ScriptHandler::END_COMMA);
    putchar('\n');
    fflush(stdout);
    return RET_CONTINUE;
}
Ejemplo n.º 6
0
static Equations readEquations(FILE *f) {
  int i;
  int count = readInt(f);
  Equations equs = (Equations) malloc(sizeof(struct _Equations)+count*sizeof(struct _Equation));
  
  equs->count = count;
  for (i = 0; i < count; i++) {
    equs->equs[i].lhs = readPatts(f);
    equs->equs[i].rhs = readExpr(f);
  }

  return equs;
}
Ejemplo n.º 7
0
void Script_v2::o2_totSub(FuncParams &params) {
	startFunc(params);

	uint8 length = readUint8();
	if (!(length & 0x80)) {
		for (uint16 i = 0; i < length; i++)
			print("%c", (char) readUint8());
	} else
		print("%s", readExpr().c_str());

	print(", %d", readUint8());

	endFunc();
}
int main()
{
	AST *e;
	
    getToken(); // Lexical Analysis (look-forward)
	
    e = readExpr(); // Syntax Analysis (build AST)
	
    if (currentToken != EOL) { // Error check
		printf("error: EOL expected\n");
		exit(1);
    }
	
    printf("= %d\n", evalExpr(e)); // Semantics Analysis (evaluate AST)

    exit(0);
}
Ejemplo n.º 9
0
static Type readType(FILE *f) {
  Context hypos = readContext(f);
  CId     cat   = readCId(f);
  
  int i;
  int count = readInt(f);
  Type ty = (Type) malloc(sizeof(struct _Type)+count*sizeof(Expr));
  
  ty->hypos = hypos;
  ty->cat   = cat;
  ty->nArgs = count;
  for (i = 0; i < count; i++) {
    ty->args[i]  = readExpr(f);
  }
  
  return ty;
}
Ejemplo n.º 10
0
void Script_v2::o2_loadMult(FuncParams &params) {
	uint16 id;
	bool hasImds;

	id = readUint16();
	if (id & 0x8000) {
		id &= 0x7FFF;
		skip(1);
	}

	startFunc(params);
	print("%d", id);
	endFunc();

	if (!_extTable)
		error("EXT file needed");

	uint32 size;
	byte *extData = _extTable->getItem(id - 30000, size);
	byte *data = extData;

	int32 count1, count2;

	count1 = ((int8) data[0]) + 1;
	hasImds = ((count1 & 0x80) != 0);
		count1 &= 0x7F;
	count2 = ((int8) data[1]) + 1;
	data += 2;
	// Statics
	for (int i = 0; i < count1; i++, data += 14) {
		int16 sSize;

		readExpr();
		sSize = (int16) readUint16();
		skip(sSize * 2);
		sSize = (int16) readUint16();
		skip(2 + sSize * 8);
	}
	// Anims
	for (int i = 0; i < count2; i++, data += 14) {
		readExpr();
		int16 sSize = (int16) readUint16();
		skip(2 + sSize * 8);
	}

	// FPS
	data += 2;

	// StaticKeys
	count1 = (int16) READ_LE_UINT16(data);
	data += 2 + count1 * 4;

	// AnimKeys
	for (int i = 0; i < 4; i++) {
		count1 = (int16) READ_LE_UINT16(data);
		data += 2 + count1 * 10;
	}

	// fadePal
	data += 5 * 16 * 3;

	// palFadeKeys
	count1 = (int16) READ_LE_UINT16(data);
	data += 2 + count1 * 7;

	// palKeys
	count1 = (int16) READ_LE_UINT16(data);
	data += 2 + count1 * 80;

	// textKeys
	count1 = (int16) READ_LE_UINT16(data);
	data += 2 + count1 * (4 + (hasImds ? 0 : 24));

	// soundKeys
	count1 = (int16) READ_LE_UINT16(data);
	data += 2;
	for (int i = 0; i < count1; i++, data += (12 + (hasImds ? 0 : 24))) {
		int16 cmd = (int16) READ_LE_UINT16(data + 2);

		if ((cmd == 1) || (cmd == 4))
			skip(2);
		else if (cmd == 3)
			skip(4);
	}

	// ImdKeys
	if (hasImds) {
		int16 sSize = (int16) readUint16();
		skip(sSize * 2);

		if (getVerScript() >= 51) {
			sSize = (int16) readUint16();
			if (sSize > 0)
				skip(sSize * 14);
		}
	}

	delete[] extData;
}
Ejemplo n.º 11
0
static Patt readPatt(FILE *f) {
  int tag = readTag(f);

  switch (tag) {
  case TAG_PAPP:
    {
       CId fun = readCId(f);
       
       int i;
       int count = readInt(f);
       PattApp p = (PattApp) malloc(sizeof(struct _PattApp)+count*sizeof(Patt));
  
       p->_.tag      = tag;
       p->fun        = fun;
       p->args.count = count;
       for (i = 0; i < count; i++) {
         p->args.pats[i] = readPatt(f);
       }
       
       return ((Patt) p);
    }
  case TAG_PVAR:
    {
        PattVar p = (PattVar) malloc(sizeof(struct _PattVar));
        p->_.tag = tag;
        p->var   = readCId(f);
        return ((Patt) p);
    }
  case TAG_PAT:
    {
        PattAt p = (PattAt) malloc(sizeof(struct _PattAt));
        p->_.tag = tag;
        p->var   = readCId(f);
        p->pat   = readPatt(f);
        return ((Patt) p);
    }
  case TAG_PWILD:
    {
        PattWild p = (PattWild) malloc(sizeof(struct _PattWild));
        p->_.tag = tag;
        return ((Patt) p);
    }
  case TAG_PLIT:
    {
        PattLit p = (PattLit) malloc(sizeof(struct _PattLit));
        p->_.tag = tag;
        p->lit   = readLiteral(f);
        return ((Patt) p);
    }
  case TAG_PIMP:
    {
        PattImplArg p = (PattImplArg) malloc(sizeof(struct _PattImplArg));
        p->_.tag = tag;
        p->pat   = readPatt(f);
        return ((Patt) p);
    }
  case TAG_PTILDE:
    {
        PattTilde p = (PattTilde) malloc(sizeof(struct _PattTilde));
        p->_.tag = tag;
        p->e     = readExpr(f);
        return ((Patt) p);
    }
  default:
    __pgf_panic("Unknown pattern tag");
  }  
}
Ejemplo n.º 12
0
static Expr readExpr(FILE *f) {
  int tag = readTag(f);
  
  switch (tag) {
  case TAG_ABS:
    {
        ExprAbs e = (ExprAbs) malloc(sizeof(struct _ExprAbs));
        e->_.tag = tag;
        e->bt    = readTag(f);
        e->var   = readCId(f);
        e->body  = readExpr(f);
        return ((Expr) e);
    }
  case TAG_APP:
    {
        ExprApp e = (ExprApp) malloc(sizeof(struct _ExprApp));
        e->_.tag = tag;
        e->left  = readExpr(f);
        e->right = readExpr(f);
        return ((Expr) e);
    }
  case TAG_LIT:
    {
        ExprLit e = (ExprLit) malloc(sizeof(struct _ExprLit));
        e->_.tag = tag;
        e->lit   = readLiteral(f);
        return ((Expr) e);
    }
  case TAG_MET:
    {
        ExprMeta e = (ExprMeta) malloc(sizeof(struct _ExprMeta));
        e->_.tag = tag;
        e->id    = readInt(f);
        return ((Expr) e);
    }
  case TAG_FUN:
    {
        ExprFun e = (ExprFun) malloc(sizeof(struct _ExprFun));
        e->_.tag = tag;
        e->fun   = readCId(f);
        return ((Expr) e);
    }
  case TAG_VAR:
    {
        ExprVar e = (ExprVar) malloc(sizeof(struct _ExprVar));
        e->_.tag = tag;
        e->index = readInt(f);
        return ((Expr) e);
    }
  case TAG_TYP:
    {
        ExprTyped e = (ExprTyped) malloc(sizeof(struct _ExprTyped));
        e->_.tag = tag;
        e->e     = readExpr(f);
        e->ty    = readType(f);
        return ((Expr) e);
    }
  case TAG_IMP:
    {
        ExprImplArg e = (ExprImplArg) malloc(sizeof(struct _ExprImplArg));
        e->_.tag = tag;
        e->e     = readExpr(f);
        return ((Expr) e);
    }
  default:
    __pgf_panic("Unknown expression tag");
  }
}