- added static constant arrays. At the moment they can only be defined inside functions due to lack of dedicated storage inside classes for static data.

- added new VM instructions to access the constant tables with a variable index.
- refactored VMFunctionBuilder's constant tables so that they are not limited to one entry per value. While this works fine for single values, it makes it impossible to store constant arrays in here.
This commit is contained in:
Christoph Oelckers 2016-11-20 18:00:37 +01:00
commit 5951a9449c
11 changed files with 412 additions and 105 deletions

View file

@ -595,6 +595,16 @@ static void PrintExprClassCast(FLispString &out, ZCC_TreeNode *node)
out.Close();
}
static void PrintStaticArray(FLispString &out, ZCC_TreeNode *node)
{
ZCC_StaticArrayStatement *enode = (ZCC_StaticArrayStatement *)node;
out.Open("static-array-stmt");
PrintNodes(out, enode->Type, false);
out.AddName(enode->Id);
PrintNodes(out, enode->Values, false);
out.Close();
}
static void PrintExprMemberAccess(FLispString &out, ZCC_TreeNode *node)
{
ZCC_ExprMemberAccess *enode = (ZCC_ExprMemberAccess *)node;

View file

@ -1559,6 +1559,29 @@ statement(X) ::= jump_statement(X).
statement(X) ::= assign_statement(A) SEMICOLON. { X = A; /*X-overwrites-A*/ }
statement(X) ::= local_var(A) SEMICOLON. { X = A; /*X-overwrites-A*/ }
statement(X) ::= error SEMICOLON. { X = NULL; }
statement(X) ::= staticarray_statement(A). { X = A; /*X-overwrites-A*/ }
/*----- Static array Statements -----*/
%type staticarray_statement{ZCC_StaticArrayStatement *}
staticarray_statement(X) ::= STATIC CONST type(A) IDENTIFIER(B) LBRACKET RBRACKET EQ LBRACE expr_list(C) RBRACE.
{
NEW_AST_NODE(StaticArrayStatement, stmt, A);
stmt->Type = A;
stmt->Id = ENamedName(B.Int);
stmt->Values = C;
X = stmt;
}
staticarray_statement(X) ::= STATIC CONST type(A) LBRACKET RBRACKET IDENTIFIER(B) EQ LBRACE expr_list(C) RBRACE.
{
NEW_AST_NODE(StaticArrayStatement, stmt, A);
stmt->Type = A;
stmt->Id = ENamedName(B.Int);
stmt->Values = C;
X = stmt;
}
/*----- Jump Statements -----*/

View file

@ -2826,6 +2826,15 @@ FxExpression *ZCCCompiler::ConvertNode(ZCC_TreeNode *ast)
return new FxClassPtrCast(cls, ConvertNode(cc->Parameters));
}
case AST_StaticArrayStatement:
{
auto sas = static_cast<ZCC_StaticArrayStatement *>(ast);
PType *ztype = DetermineType(ConvertClass, sas, sas->Id, sas->Type, false, false);
FArgumentList args;
ConvertNodeList(args, sas->Values);
// This has to let the code generator resolve the constants, not the Simplifier, which lacks all the necessary type info.
return new FxStaticArray(ztype, sas->Id, args, *ast);
}
case AST_ExprMemberAccess:
{

View file

@ -103,6 +103,7 @@ enum EZCCTreeNodeType
AST_VectorValue,
AST_DeclFlags,
AST_ClassCast,
AST_StaticArrayStatement,
NUM_AST_NODE_TYPES
};
@ -406,6 +407,13 @@ struct ZCC_Statement : ZCC_TreeNode
{
};
struct ZCC_StaticArrayStatement : ZCC_Statement
{
ZCC_Type *Type;
ENamedName Id;
ZCC_Expression *Values;
};
struct ZCC_CompoundStmt : ZCC_Statement
{
ZCC_Statement *Content;