mirror of
https://github.com/autc04/Retro68.git
synced 2024-11-23 15:32:26 +00:00
Rez: rect and point
This commit is contained in:
parent
e9edbb2ffa
commit
cb25b8106c
@ -108,6 +108,16 @@ void IdentifierExpr::addArgument(ExprPtr 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)
|
||||
{
|
||||
if(isFunction)
|
||||
@ -130,24 +140,14 @@ int IdentifierExpr::evaluateInt(ResourceCompiler *ctx)
|
||||
}
|
||||
else
|
||||
{
|
||||
Subscripts sub;
|
||||
for(auto arg : arguments)
|
||||
sub.addSubscript(arg->evaluateInt(ctx));
|
||||
ExprPtr val = ctx->lookupIdentifier(id, sub);
|
||||
assert(val);
|
||||
return val->evaluateInt(ctx);
|
||||
return lookup(ctx)->evaluateInt(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
std::string IdentifierExpr::evaluateString(ResourceCompiler *ctx)
|
||||
{
|
||||
assert(!isFunction);
|
||||
Subscripts sub;
|
||||
for(auto arg : arguments)
|
||||
sub.addSubscript(arg->evaluateInt(ctx));
|
||||
ExprPtr val = ctx->lookupIdentifier(id, sub);
|
||||
assert(val);
|
||||
return val->evaluateString(ctx);
|
||||
return lookup(ctx)->evaluateString(ctx);
|
||||
}
|
||||
|
||||
|
||||
|
@ -110,6 +110,7 @@ public:
|
||||
IdentifierExpr(std::string id, bool isFunction = false);
|
||||
|
||||
void addArgument(ExprPtr e);
|
||||
ExprPtr lookup(ResourceCompiler *ctx);
|
||||
virtual int evaluateInt(ResourceCompiler *ctx);
|
||||
virtual std::string evaluateString(ResourceCompiler *ctx);
|
||||
};
|
||||
|
@ -103,6 +103,12 @@ void SimpleField::compile(ExprPtr expr, ResourceCompiler *compiler, bool prePass
|
||||
case Type::char_:
|
||||
compileString(expr, compiler, prePass);
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
: name(name), arrayCount(count)
|
||||
|
@ -94,6 +94,7 @@ public:
|
||||
private:
|
||||
void compileString(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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user