Rez: rect and point

This commit is contained in:
Wolfgang Thaller 2014-10-08 01:55:54 +02:00
parent e9edbb2ffa
commit cb25b8106c
4 changed files with 52 additions and 12 deletions

View File

@ -108,6 +108,16 @@ void IdentifierExpr::addArgument(ExprPtr e)
arguments.push_back(e); arguments.push_back(e);
} }
ExprPtr IdentifierExpr::lookup(ResourceCompiler *ctx)
{
Subscripts sub;
for(auto arg : arguments)
sub.addSubscript(arg->evaluateInt(ctx));
ExprPtr val = ctx->lookupIdentifier(id, sub);
assert(val);
return val;
}
int IdentifierExpr::evaluateInt(ResourceCompiler *ctx) int IdentifierExpr::evaluateInt(ResourceCompiler *ctx)
{ {
if(isFunction) if(isFunction)
@ -130,24 +140,14 @@ int IdentifierExpr::evaluateInt(ResourceCompiler *ctx)
} }
else else
{ {
Subscripts sub; return lookup(ctx)->evaluateInt(ctx);
for(auto arg : arguments)
sub.addSubscript(arg->evaluateInt(ctx));
ExprPtr val = ctx->lookupIdentifier(id, sub);
assert(val);
return val->evaluateInt(ctx);
} }
} }
std::string IdentifierExpr::evaluateString(ResourceCompiler *ctx) std::string IdentifierExpr::evaluateString(ResourceCompiler *ctx)
{ {
assert(!isFunction); assert(!isFunction);
Subscripts sub; return lookup(ctx)->evaluateString(ctx);
for(auto arg : arguments)
sub.addSubscript(arg->evaluateInt(ctx));
ExprPtr val = ctx->lookupIdentifier(id, sub);
assert(val);
return val->evaluateString(ctx);
} }

View File

@ -110,6 +110,7 @@ public:
IdentifierExpr(std::string id, bool isFunction = false); IdentifierExpr(std::string id, bool isFunction = false);
void addArgument(ExprPtr e); void addArgument(ExprPtr e);
ExprPtr lookup(ResourceCompiler *ctx);
virtual int evaluateInt(ResourceCompiler *ctx); virtual int evaluateInt(ResourceCompiler *ctx);
virtual std::string evaluateString(ResourceCompiler *ctx); virtual std::string evaluateString(ResourceCompiler *ctx);
}; };

View File

@ -103,6 +103,12 @@ void SimpleField::compile(ExprPtr expr, ResourceCompiler *compiler, bool prePass
case Type::char_: case Type::char_:
compileString(expr, compiler, prePass); compileString(expr, compiler, prePass);
break; break;
case Type::rect:
case Type::point:
compileCompound(expr, compiler, prePass);
break;
} }
} }
@ -181,6 +187,38 @@ void SimpleField::compileInt(ExprPtr expr, ResourceCompiler *compiler, bool preP
compiler->write(bitSize, actualValue); compiler->write(bitSize, actualValue);
} }
void SimpleField::compileCompound(ExprPtr expr, ResourceCompiler *compiler, bool prePass)
{
ExprPtr val = value ? value : expr;
if(IdentifierExprPtr id = std::dynamic_pointer_cast<IdentifierExpr>(val))
{
ResourceCompiler::FieldScope scope(compiler, this);
val = id->lookup(compiler);
}
int count = 0;
switch(type)
{
case Type::rect:
count = 4;
break;
case Type::point:
count = 2;
break;
}
CompoundExprPtr compound = std::dynamic_pointer_cast<CompoundExpr>(val);
assert(compound);
assert(compound->size() == count);
for(int i = 0; i < count; i++)
{
int x = compound->getItem(i)->evaluateInt(compiler);
compiler->write(16, x);
}
}
ArrayField::ArrayField(std::string name, ExprPtr count) ArrayField::ArrayField(std::string name, ExprPtr count)
: name(name), arrayCount(count) : name(name), arrayCount(count)

View File

@ -94,6 +94,7 @@ public:
private: private:
void compileString(ExprPtr expr, ResourceCompiler *compiler, bool prePass); void compileString(ExprPtr expr, ResourceCompiler *compiler, bool prePass);
void compileInt(ExprPtr expr, ResourceCompiler *compiler, bool prePass); void compileInt(ExprPtr expr, ResourceCompiler *compiler, bool prePass);
void compileCompound(ExprPtr expr, ResourceCompiler *compiler, bool prePass);
}; };
typedef std::shared_ptr<SimpleField> SimpleFieldPtr; typedef std::shared_ptr<SimpleField> SimpleFieldPtr;