1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 03:28:20 +02:00

Enum fixes, small reflection fixes

This commit is contained in:
Brian Fiete 2019-11-25 06:47:41 -08:00
parent 973b5e73cf
commit dffde00a6a
11 changed files with 100 additions and 35 deletions

View file

@ -334,7 +334,7 @@ namespace System
} }
public this(String error, bool isError) public this(String message, bool isError)
{ {
} }

View file

@ -39,7 +39,7 @@ namespace System.Reflection
{ {
extension TypeInstance extension TypeInstance
{ {
public override FieldInfo? GetField(String fieldName) public override Result<FieldInfo> GetField(String fieldName)
{ {
for (int32 i = 0; i < mFieldDataCount; i++) for (int32 i = 0; i < mFieldDataCount; i++)
{ {
@ -47,7 +47,7 @@ namespace System.Reflection
if (fieldData.mName == fieldName) if (fieldData.mName == fieldName)
return FieldInfo(this, fieldData); return FieldInfo(this, fieldData);
} }
return null; return .Err;
} }
public override FieldInfo.Enumerator GetFields(BindingFlags bindingFlags = cDefaultLookup) public override FieldInfo.Enumerator GetFields(BindingFlags bindingFlags = cDefaultLookup)

View file

@ -349,6 +349,24 @@ namespace System
} }
} }
public virtual int32 MinValue
{
[Error("This property can only be accessed directly from a typeof() expression")]
get
{
return 0;
}
}
public virtual int32 MaxValue
{
[Error("This property can only be accessed directly from a typeof() expression")]
get
{
return 0;
}
}
public int32 GetTypeId() public int32 GetTypeId()
{ {
return (int32)mTypeId; return (int32)mTypeId;
@ -425,9 +443,9 @@ namespace System
return type == this; return type == this;
} }
public virtual FieldInfo? GetField(String fieldName) public virtual Result<FieldInfo> GetField(String fieldName)
{ {
return null; return .Err;
} }
public virtual FieldInfo.Enumerator GetFields(BindingFlags bindingFlags = cDefaultLookup) public virtual FieldInfo.Enumerator GetFields(BindingFlags bindingFlags = cDefaultLookup)
@ -665,7 +683,7 @@ namespace System.Reflection
strBuffer.Append(mName); strBuffer.Append(mName);
} }
public override FieldInfo? GetField(String fieldName) public override Result<FieldInfo> GetField(String fieldName)
{ {
for (int32 i = 0; i < mFieldDataCount; i++) for (int32 i = 0; i < mFieldDataCount; i++)
{ {
@ -673,7 +691,7 @@ namespace System.Reflection
if (fieldData.mName == fieldName) if (fieldData.mName == fieldName)
return FieldInfo(this, fieldData); return FieldInfo(this, fieldData);
} }
return null; return .Err;
} }
public override FieldInfo.Enumerator GetFields(BindingFlags bindingFlags = cDefaultLookup) public override FieldInfo.Enumerator GetFields(BindingFlags bindingFlags = cDefaultLookup)

View file

@ -132,9 +132,9 @@ WinBFWindow::WinBFWindow(BFWindow* parent, const StringImpl& title, int x, int y
::SystemParametersInfo(SPI_GETWORKAREA, NULL, &desktopRect, NULL); ::SystemParametersInfo(SPI_GETWORKAREA, NULL, &desktopRect, NULL);
if (x + width >= desktopRect.right) if (x + width >= desktopRect.right)
x = BF_MAX((int)desktopRect.left, requestedX - width); x = BF_MAX((int)desktopRect.left, desktopRect.right - width);
if (y + height >= desktopRect.bottom) if (y + height >= desktopRect.bottom)
y = BF_MAX((int)desktopRect.top, requestedY - height); y = BF_MAX((int)desktopRect.top, desktopRect.bottom - height);
} }
mFlags = windowFlags; mFlags = windowFlags;

View file

@ -51,8 +51,10 @@ namespace System
public static extern void ObjectDynCheck(Object obj, int32 typeId, bool allowNull); public static extern void ObjectDynCheck(Object obj, int32 typeId, bool allowNull);
public static extern void ObjectDynCheckFailed(Object obj, int32 typeId); public static extern void ObjectDynCheckFailed(Object obj, int32 typeId);
public static extern void Dbg_ObjectCreated(Object obj, int size, ClassVData* classVData); public static extern void Dbg_ObjectCreated(Object obj, int size, ClassVData* classVData);
public static extern void Dbg_ObjectCreatedEx(Object obj, int size, ClassVData* classVData);
public static extern void Dbg_ObjectAllocated(Object obj, int size, ClassVData* classVData); public static extern void Dbg_ObjectAllocated(Object obj, int size, ClassVData* classVData);
public static extern int Dbg_PrepareStackTrace(int maxDepth); public static extern void Dbg_ObjectAllocatedEx(Object obj, int size, ClassVData* classVData);
public static extern int Dbg_PrepareStackTrace(int baseAllocSize, int maxStackTraceDepth);
public static extern void Dbg_ObjectStackInit(Object object, ClassVData* classVData); public static extern void Dbg_ObjectStackInit(Object object, ClassVData* classVData);
public static extern Object Dbg_ObjectAlloc(TypeInstance typeInst, int size); public static extern Object Dbg_ObjectAlloc(TypeInstance typeInst, int size);
public static extern Object Dbg_ObjectAlloc(ClassVData* classVData, int size, int align, int maxStackTraceDepth); public static extern Object Dbg_ObjectAlloc(ClassVData* classVData, int size, int align, int maxStackTraceDepth);
@ -139,6 +141,8 @@ namespace System
public static String[] CreateParamsArray() public static String[] CreateParamsArray()
{ {
char8* cmdLine = GetCommandLineArgs(); char8* cmdLine = GetCommandLineArgs();
//Windows.MessageBoxA(default, scope String()..AppendF("CmdLine: {0}", StringView(cmdLine)), "HI", 0);
String[] strVals = null; String[] strVals = null;
for (int pass = 0; pass < 2; pass++) for (int pass = 0; pass < 2; pass++)
{ {
@ -151,21 +155,40 @@ namespace System
var str = new String(len); var str = new String(len);
char8* outStart = str.Ptr; char8* outStart = str.Ptr;
char8* outPtr = outStart; char8* outPtr = outStart;
bool inQuote = false;
for (int i < len) for (int i < len)
{ {
char8 c = cmdLine[idx + i]; char8 c = cmdLine[idx + i];
if (c == '\"')
if (!inQuote)
{ {
if ((cmdLine[idx + i + 1] == '\"') && if (c == '"')
(cmdLine[idx + i + 2] == '\"'))
{ {
*(outPtr++) = '\"'; inQuote = true;
i += 2;
continue; continue;
} }
continue;
} }
else
{
if (c == '^')
{
i++;
c = cmdLine[idx + i];
}
else if (c == '\"')
{
if (cmdLine[idx + i + 1] == '\"')
{
*(outPtr++) = '\"';
i++;
continue;
}
inQuote = false;
continue;
}
}
*(outPtr++) = c; *(outPtr++) = c;
} }
str.[Friend]mLength = (.)(outPtr - outStart); str.[Friend]mLength = (.)(outPtr - outStart);
@ -195,6 +218,10 @@ namespace System
{ {
if (firstCharIdx == -1) if (firstCharIdx == -1)
firstCharIdx = i; firstCharIdx = i;
if (c == '^')
{
i++;
}
if (c == '"') if (c == '"')
inQuote = !inQuote; inQuote = !inQuote;
else if ((inQuote) && (c == '\\')) else if ((inQuote) && (c == '\\'))
@ -225,4 +252,22 @@ namespace System
extern static this(); extern static this();
extern static ~this(); extern static ~this();
} }
struct CRTAlloc
{
public void* Alloc(int size, int align)
{
return Internal.StdMalloc(size);
}
public void Free(void* ptr)
{
Internal.StdFree(ptr);
}
}
static
{
public static CRTAlloc gCRTAlloc;
}
} }

View file

@ -994,6 +994,7 @@ void COFF::CvParseMembers(DbgType* parentType, int tagIdx, bool ipi)
parentType->mTypeParam = CvGetType(fieldTypeId); parentType->mTypeParam = CvGetType(fieldTypeId);
if ((parentType->mBaseTypes.mHead != NULL) && (strcmp(parentType->mBaseTypes.mHead->mBaseType->mName, "System.Enum") == 0)) if ((parentType->mBaseTypes.mHead != NULL) && (strcmp(parentType->mBaseTypes.mHead->mBaseType->mName, "System.Enum") == 0))
parentType->mTypeCode = DbgType_Enum; parentType->mTypeCode = DbgType_Enum;
break;
} }
} }

View file

@ -437,6 +437,7 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods)
continue; continue;
auto methodSpecializationRequest = *workItemRef; auto methodSpecializationRequest = *workItemRef;
auto module = workItemRef->mFromModule; auto module = workItemRef->mFromModule;
workIdx = mMethodSpecializationWorkList.RemoveAt(workIdx); workIdx = mMethodSpecializationWorkList.RemoveAt(workIdx);
@ -2339,11 +2340,6 @@ void BfContext::QueueMethodSpecializations(BfTypeInstance* typeInst, bool checkS
return; return;
} }
if ((module->mModuleName == "System_Array") && (!mCompiler->mIsResolveOnly))
{
NOP;
}
// Find any method specialization requests for types that are rebuilding, but from // Find any method specialization requests for types that are rebuilding, but from
// modules that are NOT rebuilding to be sure we generate those. Failure to do this // modules that are NOT rebuilding to be sure we generate those. Failure to do this
// will cause a link error from an old module // will cause a link error from an old module

View file

@ -16163,6 +16163,7 @@ void BfExprEvaluator::PerformUnaryOperation_OnResult(BfExpression* unaryOpExpr,
MarkResultUsed(); MarkResultUsed();
mModule->FixIntUnknown(mResult); mModule->FixIntUnknown(mResult);
mModule->PopulateType(mResult.mType);
auto ptrType = mModule->CreatePointerType(mResult.mType); auto ptrType = mModule->CreatePointerType(mResult.mType);
if ((!CheckModifyResult(mResult, unaryOpExpr, "take address of")) || (mResult.mType->IsValuelessType())) if ((!CheckModifyResult(mResult, unaryOpExpr, "take address of")) || (mResult.mType->IsValuelessType()))
{ {
@ -16194,6 +16195,7 @@ void BfExprEvaluator::PerformUnaryOperation_OnResult(BfExpression* unaryOpExpr,
return; return;
} }
mModule->PopulateType(resolvedType);
if (resolvedType->IsValuelessType()) if (resolvedType->IsValuelessType())
mResult = BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), resolvedType, true); mResult = BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), resolvedType, true);
else else

View file

@ -1097,7 +1097,7 @@ void BfModule::EnsureIRBuilder(bool dbgVerifyCodeGen)
// code as we walk the AST // code as we walk the AST
//mBfIRBuilder->mDbgVerifyCodeGen = true; //mBfIRBuilder->mDbgVerifyCodeGen = true;
if ( if (
(mModuleName == "IDE_ui_LaunchDialog") (mModuleName == "Blurg")
//|| (mModuleName == "System_Internal") //|| (mModuleName == "System_Internal")
//|| (mModuleName == "vdata") //|| (mModuleName == "vdata")
//|| (mModuleName == "Hey_Dude_Bro_TestClass") //|| (mModuleName == "Hey_Dude_Bro_TestClass")
@ -11036,7 +11036,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
BF_ASSERT(instModule == mParentModule); BF_ASSERT(instModule == mParentModule);
} }
else if (instModule != this) else if (instModule != this)
{ {
if ((!mIsReified) && (instModule->mIsReified)) if ((!mIsReified) && (instModule->mIsReified))
{ {
BF_ASSERT(!mCompiler->mIsResolveOnly); BF_ASSERT(!mCompiler->mIsResolveOnly);
@ -11064,10 +11064,11 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
specializationRequest->mMethodDef = methodDef; specializationRequest->mMethodDef = methodDef;
specializationRequest->mMethodGenericArguments = methodGenericArguments; specializationRequest->mMethodGenericArguments = methodGenericArguments;
specializationRequest->mType = typeInst; specializationRequest->mType = typeInst;
specializationRequest->mFlags = flags;
} }
auto defFlags = (BfGetMethodInstanceFlags)(flags & ~BfGetMethodInstanceFlag_ForceInline); auto defFlags = (BfGetMethodInstanceFlags)(flags & ~BfGetMethodInstanceFlag_ForceInline);
// Not extern // Not extern
// Create the instance in the proper module and then create a reference in this one // Create the instance in the proper module and then create a reference in this one
moduleMethodInst = instModule->GetMethodInstance(typeInst, methodDef, methodGenericArguments, defFlags, foreignType); moduleMethodInst = instModule->GetMethodInstance(typeInst, methodDef, methodGenericArguments, defFlags, foreignType);
@ -11769,12 +11770,7 @@ void BfModule::HadSlotCountDependency()
} }
BfTypedValue BfModule::ReferenceStaticField(BfFieldInstance* fieldInstance) BfTypedValue BfModule::ReferenceStaticField(BfFieldInstance* fieldInstance)
{ {
if (fieldInstance->mResolvedType->IsVar())
{
NOP;
}
if (mIsScratchModule) if (mIsScratchModule)
{ {
// Just fake it for the extern and unspecialized modules // Just fake it for the extern and unspecialized modules
@ -19490,7 +19486,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool
// CheckHotMethod(methodInstance, mangledName); // CheckHotMethod(methodInstance, mangledName);
BfLogSysM("DoMethodDeclaration %s Module: %p Type: %p MethodInst: %p Reified: %d Unspecialized: %d IRFunction: %d MethodId:%llx\n", mangledName.c_str(), this, mCurTypeInstance, methodInstance, methodInstance->mIsReified, mCurTypeInstance->IsUnspecializedType(), methodInstance->mIRFunction.mId, methodInstance->mIdHash); BfLogSysM("DoMethodDeclaration %s Module: %p Type: %p MethodInst: %p Reified: %d Unspecialized: %d IRFunction: %d MethodId:%llx\n", mangledName.c_str(), this, mCurTypeInstance, methodInstance, methodInstance->mIsReified, mCurTypeInstance->IsUnspecializedType(), methodInstance->mIRFunction.mId, methodInstance->mIdHash);
SizedArray<BfIRMDNode, 8> diParams; SizedArray<BfIRMDNode, 8> diParams;
diParams.push_back(mBfIRBuilder->DbgGetType(resolvedReturnType)); diParams.push_back(mBfIRBuilder->DbgGetType(resolvedReturnType));

View file

@ -1867,9 +1867,14 @@ void BfTupleType::Finish()
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
BfType* BfBoxedType::GetModifiedElementType() BfType* BfBoxedType::GetModifiedElementType()
{ {
if ((mBoxedFlags & BoxedFlags_StructPtr) != 0) if ((mBoxedFlags & BoxedFlags_StructPtr) != 0)
return mModule->CreatePointerType(mElementType); {
auto module = mModule;
if (module == NULL)
module = mContext->mUnreifiedModule;
return module->CreatePointerType(mElementType);
}
return mElementType; return mElementType;
} }

View file

@ -1410,9 +1410,11 @@ DbgType* DbgType::GetPrimaryType()
{ {
if ((mCompileUnit != NULL) && if ((mCompileUnit != NULL) &&
((mCompileUnit->mLanguage == DbgLanguage_Beef) || (mTypeCode == DbgType_Namespace) || (mIsDeclaration))) ((mCompileUnit->mLanguage == DbgLanguage_Beef) || (mTypeCode == DbgType_Namespace) || (mIsDeclaration)))
{ {
mPrimaryType = mCompileUnit->mDbgModule->GetPrimaryType(this); mPrimaryType = mCompileUnit->mDbgModule->GetPrimaryType(this);
mPrimaryType->PopulateType();
mTypeCode = mPrimaryType->mTypeCode; mTypeCode = mPrimaryType->mTypeCode;
mTypeParam = mPrimaryType->mTypeParam;
} }
} }