1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Fixed varargs and tuple building

This commit is contained in:
Brian Fiete 2020-02-11 08:37:52 -08:00
parent 7741344fd2
commit 8171c842f0
5 changed files with 42 additions and 25 deletions

View file

@ -2893,11 +2893,6 @@ BeMCOperand BeMCContext::CreateCall(const BeMCOperand& func, const SizedArrayImp
int argCount = (int)args.size() + argOfs; int argCount = (int)args.size() + argOfs;
int dynStackSize = 0; int dynStackSize = 0;
// if (mUseBP)
// {
// dynStackSize = BF_MAX(4, argCount) * 8;
// dynStackSize = BF_ALIGN(dynStackSize, 16);
// }
if (dynStackSize > 0) if (dynStackSize > 0)
AllocInst(BeMCInstKind_Sub, BeMCOperand::FromReg(X64Reg_RSP), BeMCOperand::FromImmediate(dynStackSize)); AllocInst(BeMCInstKind_Sub, BeMCOperand::FromReg(X64Reg_RSP), BeMCOperand::FromImmediate(dynStackSize));
@ -15894,8 +15889,8 @@ void BeMCContext::Generate(BeFunction* function)
retCount++; retCount++;
} }
break; break;
case BeCallInst::TypeId: case BeCallInst::TypeId:
{ {
auto castedInst = (BeCallInst*)inst; auto castedInst = (BeCallInst*)inst;
BeMCOperand mcFunc; BeMCOperand mcFunc;
BeType* returnType = NULL; BeType* returnType = NULL;
@ -16268,18 +16263,15 @@ void BeMCContext::Generate(BeFunction* function)
} }
else else
{ {
if (auto func = BeValueDynCast<BeFunction>(castedInst->mFunc)) auto funcPtrType = castedInst->mFunc->GetType();
if (funcPtrType->IsPointer())
{ {
auto funcPtrType = func->mType; auto elementType = ((BePointerType*)funcPtrType)->mElementType;
if (funcPtrType->IsPointer()) if (elementType->mTypeCode == BeTypeCode_Function)
{ {
auto elementType = ((BePointerType*)funcPtrType)->mElementType; isVarArg = ((BeFunctionType*)elementType)->mIsVarArg;
if (elementType->mTypeCode == BeTypeCode_Function) }
{ }
isVarArg = ((BeFunctionType*)elementType)->mIsVarArg;
}
}
}
returnType = castedInst->GetType(); returnType = castedInst->GetType();
mcFunc = GetOperand(castedInst->mFunc); mcFunc = GetOperand(castedInst->mFunc);

View file

@ -13825,6 +13825,11 @@ void BfExprEvaluator::CheckPropFail(BfMethodDef* propMethodDef, BfMethodInstance
} }
} }
bool BfExprEvaluator::HasResult()
{
return (mResult) || (mPropDef != NULL);
}
BfTypedValue BfExprEvaluator::GetResult(bool clearResult, bool resolveGenericType) BfTypedValue BfExprEvaluator::GetResult(bool clearResult, bool resolveGenericType)
{ {
if ((!mResult) && (mPropDef != NULL)) if ((!mResult) && (mPropDef != NULL))
@ -14550,7 +14555,7 @@ void BfExprEvaluator::AssignDeferrredTupleAssignData(BfAssignmentExpression* ass
} }
else else
{ {
if (child.mExprEvaluator->mResult) if (child.mExprEvaluator->HasResult())
{ {
child.mExprEvaluator->mBfEvalExprFlags = (BfEvalExprFlags)(child.mExprEvaluator->mBfEvalExprFlags | BfEvalExprFlags_NoAutoComplete); child.mExprEvaluator->mBfEvalExprFlags = (BfEvalExprFlags)(child.mExprEvaluator->mBfEvalExprFlags | BfEvalExprFlags_NoAutoComplete);
child.mExprEvaluator->PerformAssignment(assignExpr, true, elementValue); child.mExprEvaluator->PerformAssignment(assignExpr, true, elementValue);
@ -14588,7 +14593,7 @@ void BfExprEvaluator::DoTupleAssignment(BfAssignmentExpression* assignExpr)
rightValue = mModule->LoadValue(rightValue); rightValue = mModule->LoadValue(rightValue);
AssignDeferrredTupleAssignData(assignExpr, deferredTupleAssignData, rightValue); AssignDeferrredTupleAssignData(assignExpr, deferredTupleAssignData, rightValue);
mResult = rightValue; mResult = rightValue;
} }

View file

@ -329,7 +329,8 @@ public:
BfMethodDef* GetPropertyMethodDef(BfPropertyDef* propDef, BfMethodType methodType, BfCheckedKind checkedKind); BfMethodDef* GetPropertyMethodDef(BfPropertyDef* propDef, BfMethodType methodType, BfCheckedKind checkedKind);
BfModuleMethodInstance GetPropertyMethodInstance(BfMethodDef* methodDef); BfModuleMethodInstance GetPropertyMethodInstance(BfMethodDef* methodDef);
void CheckPropFail(BfMethodDef* propMethodDef, BfMethodInstance* methodInstance); void CheckPropFail(BfMethodDef* propMethodDef, BfMethodInstance* methodInstance);
BfTypedValue GetResult(bool clearResult = false, bool resolveGenericType = false); bool HasResult();
BfTypedValue GetResult(bool clearResult = false, bool resolveGenericType = false);
void CheckResultForReading(BfTypedValue& typedValue); void CheckResultForReading(BfTypedValue& typedValue);
void MarkResultUsed(); void MarkResultUsed();
void MarkResultAssigned(); void MarkResultAssigned();

View file

@ -8794,11 +8794,6 @@ BfIRValue BfModule::CreateFunctionFrom(BfMethodInstance* methodInstance, bool tr
if (mCompiler->IsSkippingExtraResolveChecks()) if (mCompiler->IsSkippingExtraResolveChecks())
return BfIRValue(); return BfIRValue();
if (methodInstance->mMethodDef->mName == "Check")
{
NOP;
}
if (methodInstance->mMethodInstanceGroup->mOwner->IsInterface()) if (methodInstance->mMethodInstanceGroup->mOwner->IsInterface())
{ {
//BF_ASSERT(!methodInstance->mIRFunction); //BF_ASSERT(!methodInstance->mIRFunction);

View file

@ -0,0 +1,24 @@
using System;
namespace Tests
{
class VarArgs
{
#if BF_PLATFORM_WINDOWS
[CLink, Import("msvcrt.dll")]
#else
[CLink]
#endif
public static extern int32 sprintf(char8* dest, char8* fmt, ...);
[Test]
public static void TestBasics()
{
char8[256] cStr;
sprintf(&cStr, "Test %d %0.1f %0.1f", 123, 1.2f, 2.3f);
String str = scope .(&cStr);
Test.Assert(str == "Test 123 1.2 2.3");
}
}
}