diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 210d2db2b..ecc0b5048 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -66,6 +66,7 @@ PVoidType *TypeVoid; PInt *TypeSInt8, *TypeUInt8; PInt *TypeSInt16, *TypeUInt16; PInt *TypeSInt32, *TypeUInt32; +PBool *TypeBool; PFloat *TypeFloat32, *TypeFloat64; PString *TypeString; PName *TypeName; @@ -307,6 +308,7 @@ void PType::StaticInit() RUNTIME_CLASS(PErrorType)->TypeTableType = RUNTIME_CLASS(PErrorType); RUNTIME_CLASS(PVoidType)->TypeTableType = RUNTIME_CLASS(PVoidType); RUNTIME_CLASS(PInt)->TypeTableType = RUNTIME_CLASS(PInt); + RUNTIME_CLASS(PBool)->TypeTableType = RUNTIME_CLASS(PBool); RUNTIME_CLASS(PFloat)->TypeTableType = RUNTIME_CLASS(PFloat); RUNTIME_CLASS(PString)->TypeTableType = RUNTIME_CLASS(PString); RUNTIME_CLASS(PName)->TypeTableType = RUNTIME_CLASS(PName); @@ -334,6 +336,7 @@ void PType::StaticInit() TypeTable.AddType(TypeUInt16 = new PInt(2, true)); TypeTable.AddType(TypeSInt32 = new PInt(4, false)); TypeTable.AddType(TypeUInt32 = new PInt(4, true)); + TypeTable.AddType(TypeBool = new PBool); TypeTable.AddType(TypeFloat32 = new PFloat(4)); TypeTable.AddType(TypeFloat64 = new PFloat(8)); TypeTable.AddType(TypeString = new PString); @@ -561,6 +564,10 @@ int PInt::GetRegType() const return REGT_INT; } +/* PBool ******************************************************************/ + +IMPLEMENT_CLASS(PBool) + /* PFloat *****************************************************************/ IMPLEMENT_CLASS(PFloat) diff --git a/src/dobjtype.h b/src/dobjtype.h index 1e9cebf02..2861b1da2 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -230,6 +230,13 @@ protected: PInt(); }; +class PBool : public PInt +{ + DECLARE_CLASS(PBool, PInt); +public: + PBool() : PInt(sizeof(bool), true) {} +}; + class PFloat : public PBasicType { DECLARE_CLASS(PFloat, PBasicType); @@ -643,6 +650,7 @@ extern PVoidType *TypeVoid; extern PInt *TypeSInt8, *TypeUInt8; extern PInt *TypeSInt16, *TypeUInt16; extern PInt *TypeSInt32, *TypeUInt32; +extern PBool *TypeBool; extern PFloat *TypeFloat32, *TypeFloat64; extern PString *TypeString; extern PName *TypeName; diff --git a/src/zscript/zcc-parse.lemon b/src/zscript/zcc-parse.lemon index a8e069511..44bf56fb3 100644 --- a/src/zscript/zcc-parse.lemon +++ b/src/zscript/zcc-parse.lemon @@ -43,6 +43,25 @@ static void SetNodeLine(ZCC_TreeNode *name, int line) name->Type = type; \ name->IntVal = val + struct ClassFlagsBlock { + VM_UWORD Flags; + ZCC_Identifier *Replaces; + }; + + struct StateOpts { + ZCC_Expression *Offset; + bool Bright; + }; + + struct VarOrFun + { + ZCC_VarName *VarNames; + ZCC_FuncParamDecl *FuncParams; + ZCC_CompoundStmt *FuncBody; + ENamedName FuncName; + int FuncFlags; + int SourceLoc; + }; } %token_prefix ZCC_ @@ -164,12 +183,6 @@ class_ancestry(X) ::= . { X = NULL; } class_ancestry(X) ::= COLON dottable_id(A). { X = A; } %type class_flags{ClassFlagsBlock} -%include { - struct ClassFlagsBlock { - VM_UWORD Flags; - ZCC_Identifier *Replaces; - }; -} class_flags(X) ::= . { X.Flags = 0; X.Replaces = NULL; } class_flags(X) ::= class_flags(A) ABSTRACT. { X.Flags = A.Flags | 0/*FIXME*/; X.Replaces = A.Replaces; } class_flags(X) ::= class_flags(A) NATIVE. { X.Flags = A.Flags | 0/*FIXME*/; X.Replaces = A.Replaces; } @@ -369,12 +382,6 @@ enumerator(X) ::= IDENTIFIER(A) EQ expr(B). /* Expression must be constant. */ %type state_call {ZCC_ExprFuncCall *} %type state_call_params {ZCC_FuncParm *} -%include { - struct StateOpts { - ZCC_Expression *Offset; - bool Bright; - }; -} %type state_opts {StateOpts} states_def(X) ::= STATES(T) scanner_mode LBRACE states_body(A) RBRACE. @@ -618,18 +625,6 @@ array_size(X) ::= array_size(A) array_size_expr(B). X = A; } -%include -{ - struct VarOrFun - { - ZCC_VarName *VarNames; - ZCC_FuncParamDecl *FuncParams; - ZCC_CompoundStmt *FuncBody; - ENamedName FuncName; - int FuncFlags; - int SourceLoc; - }; -} %type variables_or_function {VarOrFun} /* Multiple type names are only valid for functions. */ @@ -1232,6 +1227,16 @@ constant(X) ::= NAMECONST(A). floatconst->IntVal = A.Int; X = floatconst; } +constant(X) ::= FALSE(A). +{ + NEW_INTCONST_NODE(boolconst, TypeBool, false, A); + X = boolconst; +} +constant(X) ::= TRUE(A). +{ + NEW_INTCONST_NODE(boolconst, TypeBool, true, A); + X = boolconst; +} /************ Statements ************/