Use new type system with DECORATE

This commit is contained in:
Randy Heit 2016-02-29 21:11:24 -06:00
parent 15b6c11748
commit f23c0121c5
5 changed files with 197 additions and 364 deletions

View File

@ -5,7 +5,6 @@
#error You must #include "dobject.h" to get dobjtype.h #error You must #include "dobject.h" to get dobjtype.h
#endif #endif
#include "thingdef/thingdef_type.h"
#include "vm.h" #include "vm.h"
// Variable/parameter/field flags ------------------------------------------- // Variable/parameter/field flags -------------------------------------------

View File

@ -84,7 +84,7 @@ struct FCompileContext
struct ExpVal struct ExpVal
{ {
ExpValType Type; PType *Type;
union union
{ {
int Int; int Int;
@ -94,13 +94,13 @@ struct ExpVal
ExpVal() ExpVal()
{ {
Type = VAL_Int; Type = TypeSInt32;
Int = 0; Int = 0;
} }
~ExpVal() ~ExpVal()
{ {
if (Type == VAL_String) if (Type == TypeString)
{ {
((FString *)&pointer)->~FString(); ((FString *)&pointer)->~FString();
} }
@ -108,14 +108,14 @@ struct ExpVal
ExpVal(const FString &str) ExpVal(const FString &str)
{ {
Type = VAL_String; Type = TypeString;
::new(&pointer) FString(str); ::new(&pointer) FString(str);
} }
ExpVal(const ExpVal &o) ExpVal(const ExpVal &o)
{ {
Type = o.Type; Type = o.Type;
if (o.Type == VAL_String) if (o.Type == TypeString)
{ {
::new(&pointer) FString(*(FString *)&o.pointer); ::new(&pointer) FString(*(FString *)&o.pointer);
} }
@ -127,12 +127,12 @@ struct ExpVal
ExpVal &operator=(const ExpVal &o) ExpVal &operator=(const ExpVal &o)
{ {
if (Type == VAL_String) if (Type == TypeString)
{ {
((FString *)&pointer)->~FString(); ((FString *)&pointer)->~FString();
} }
Type = o.Type; Type = o.Type;
if (o.Type == VAL_String) if (o.Type == TypeString)
{ {
::new(&pointer) FString(*(FString *)&o.pointer); ::new(&pointer) FString(*(FString *)&o.pointer);
} }
@ -145,27 +145,30 @@ struct ExpVal
int GetInt() const int GetInt() const
{ {
return Type == VAL_Int? Int : Type == VAL_Float? int(Float) : 0; int regtype = Type->GetRegType();
return regtype == REGT_INT ? Int : regtype == REGT_FLOAT ? int(Float) : 0;
} }
double GetFloat() const double GetFloat() const
{ {
return Type == VAL_Int? double(Int) : Type == VAL_Float? Float : 0; int regtype = Type->GetRegType();
return regtype == REGT_INT ? double(Int) : regtype == REGT_FLOAT ? Float : 0;
} }
const FString GetString() const const FString GetString() const
{ {
return Type == VAL_String ? *(FString *)&pointer : Type == VAL_Name ? FString(FName(ENamedName(Int)).GetChars()) : ""; return Type == TypeString ? *(FString *)&pointer : Type == TypeName ? FString(FName(ENamedName(Int)).GetChars()) : "";
} }
bool GetBool() const bool GetBool() const
{ {
return (Type == VAL_Int || Type == VAL_Sound) ? !!Int : Type == VAL_Float? Float!=0. : false; int regtype = Type->GetRegType();
return regtype == REGT_INT ? !!Int : regtype == REGT_FLOAT ? Float!=0. : false;
} }
FName GetName() const FName GetName() const
{ {
return Type == VAL_Name? ENamedName(Int) : NAME_None; return Type == TypeName ? ENamedName(Int) : NAME_None;
} }
}; };
@ -195,7 +198,7 @@ protected:
{ {
isresolved = false; isresolved = false;
ScriptPosition = pos; ScriptPosition = pos;
ValueType = VAL_Unresolved; ValueType = NULL;
} }
public: public:
virtual ~FxExpression() {} virtual ~FxExpression() {}
@ -205,11 +208,13 @@ public:
virtual bool isConstant() const; virtual bool isConstant() const;
virtual void RequestAddress(); virtual void RequestAddress();
virtual VMFunction *GetDirectFunction(); virtual VMFunction *GetDirectFunction();
bool IsNumeric() const { return ValueType->GetRegType() == REGT_INT || ValueType->GetRegType() == REGT_FLOAT; }
bool IsPointer() const { return ValueType->GetRegType() == REGT_POINTER; }
virtual ExpEmit Emit(VMFunctionBuilder *build); virtual ExpEmit Emit(VMFunctionBuilder *build);
FScriptPosition ScriptPosition; FScriptPosition ScriptPosition;
FExpressionType ValueType; PType *ValueType;
bool isresolved; bool isresolved;
}; };
@ -288,35 +293,35 @@ class FxConstant : public FxExpression
public: public:
FxConstant(int val, const FScriptPosition &pos) : FxExpression(pos) FxConstant(int val, const FScriptPosition &pos) : FxExpression(pos)
{ {
ValueType = value.Type = VAL_Int; ValueType = value.Type = TypeSInt32;
value.Int = val; value.Int = val;
isresolved = true; isresolved = true;
} }
FxConstant(double val, const FScriptPosition &pos) : FxExpression(pos) FxConstant(double val, const FScriptPosition &pos) : FxExpression(pos)
{ {
ValueType = value.Type = VAL_Float; ValueType = value.Type = TypeFloat64;
value.Float = val; value.Float = val;
isresolved = true; isresolved = true;
} }
FxConstant(FSoundID val, const FScriptPosition &pos) : FxExpression(pos) FxConstant(FSoundID val, const FScriptPosition &pos) : FxExpression(pos)
{ {
ValueType = value.Type = VAL_Sound; ValueType = value.Type = TypeSound;
value.Int = val; value.Int = val;
isresolved = true; isresolved = true;
} }
FxConstant(FName val, const FScriptPosition &pos) : FxExpression(pos) FxConstant(FName val, const FScriptPosition &pos) : FxExpression(pos)
{ {
ValueType = value.Type = VAL_Name; ValueType = value.Type = TypeName;
value.Int = val; value.Int = val;
isresolved = true; isresolved = true;
} }
FxConstant(const FString &str, const FScriptPosition &pos) : FxExpression(pos) FxConstant(const FString &str, const FScriptPosition &pos) : FxExpression(pos)
{ {
ValueType = VAL_String; ValueType = TypeString;
value = ExpVal(str); value = ExpVal(str);
isresolved = true; isresolved = true;
} }
@ -328,18 +333,18 @@ public:
isresolved = true; isresolved = true;
} }
FxConstant(const PClass *val, const FScriptPosition &pos) : FxExpression(pos) FxConstant(PClass *val, const FScriptPosition &pos) : FxExpression(pos)
{ {
value.pointer = (void*)val; value.pointer = (void*)val;
ValueType = val; ValueType = val;
value.Type = VAL_Class; value.Type = NewClassPointer(RUNTIME_CLASS(AActor));
isresolved = true; isresolved = true;
} }
FxConstant(FState *state, const FScriptPosition &pos) : FxExpression(pos) FxConstant(FState *state, const FScriptPosition &pos) : FxExpression(pos)
{ {
value.pointer = state; value.pointer = state;
ValueType = value.Type = VAL_State; ValueType = value.Type = TypeState;
isresolved = true; isresolved = true;
} }

File diff suppressed because it is too large Load Diff

View File

@ -127,7 +127,7 @@ FxExpression *ParseParameter(FScanner &sc, PClassActor *cls, PType *type, bool c
v = MAKEARGB(1, RPART(c), GPART(c), BPART(c)); v = MAKEARGB(1, RPART(c), GPART(c), BPART(c));
} }
ExpVal val; ExpVal val;
val.Type = VAL_Color; val.Type = TypeColor;
val.Int = v; val.Int = v;
x = new FxConstant(val, sc); x = new FxConstant(val, sc);
} }

View File

@ -1,96 +0,0 @@
#ifndef THINGDEF_TYPE_H
#define THINGDEF_TYPE_H
//==========================================================================
//
//
//
//==========================================================================
enum ExpValType
{
VAL_Unresolved, // type not yet known
VAL_Int, // integer number
VAL_Float, // floating point number
VAL_Unknown, // nothing
VAL_Array, // Array (very limited right now)
VAL_Object, // Object reference
VAL_Class, // Class reference
VAL_Sound, // Sound identifier. Internally it's an int.
VAL_Name, // A Name
VAL_String, // A string
VAL_Color, // A color
VAL_State, // A State pointer
// only used for accessing external variables to ensure proper conversion
VAL_Fixed,
VAL_Angle,
VAL_Bool,
};
struct FExpressionType
{
BYTE Type;
BYTE BaseType;
WORD size; // for arrays;
const PClass *ClassType;
FExpressionType &operator=(int typeval)
{
Type = typeval;
BaseType = 0;
size = 0;
ClassType = NULL;
return *this;
}
FExpressionType &operator=(const PClass *cls)
{
Type = VAL_Class;
BaseType = 0;
size = 0;
ClassType = cls;
return *this;
}
bool operator==(int typeval) const
{
return Type == typeval;
}
bool operator!=(int typeval) const
{
return Type != typeval;
}
bool isNumeric() const
{
return Type == VAL_Float || Type == VAL_Int;
}
bool isPointer() const
{
return Type == VAL_Object || Type == VAL_Class;
}
FExpressionType GetBaseType() const
{
FExpressionType ret = *this;
ret.Type = BaseType;
ret.BaseType = 0;
ret.size = 0;
return ret;
}
// currently only used for args[].
// Needs to be done differently for a generic implementation!
void MakeArray(int siz)
{
BaseType = Type;
Type = VAL_Array;
size = siz;
}
};
#endif