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

Fixed zero-sized sized array loop issues

This commit is contained in:
Brian Fiete 2021-01-19 05:40:57 -08:00
parent 966b740e6c
commit c0e19171d4
5 changed files with 83 additions and 11 deletions

View file

@ -19161,9 +19161,7 @@ void BfExprEvaluator::Visit(BfIndexerExpression* indexerExpr)
mResult = BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), underlyingType, true); mResult = BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), underlyingType, true);
else else
{ {
mResult = mModule->GetDefaultTypedValue(underlyingType); mResult = mModule->GetDefaultTypedValue(underlyingType, false, BfDefaultValueKind_Addr);
if (sizedArrayType->mElementCount != 0)
mModule->AssertErrorState();
} }
} }
else if (target.IsAddr()) else if (target.IsAddr())

View file

@ -5053,11 +5053,6 @@ BfIRValue BfModule::CreateTypeDataRef(BfType* type)
BfMangler::Mangle(typeDataName, mCompiler->GetMangleKind(), type, this); BfMangler::Mangle(typeDataName, mCompiler->GetMangleKind(), type, this);
} }
if (typeDataName == "?sBfTypeData@Zoing@BeefTest@bf@@2HA")
{
NOP;
}
BfLogSysM("Creating TypeData %s\n", typeDataName.c_str()); BfLogSysM("Creating TypeData %s\n", typeDataName.c_str());
globalVariable = mBfIRBuilder->CreateGlobalVariable(mBfIRBuilder->MapTypeInst(typeTypeInst, BfIRPopulateType_Full), true, BfIRLinkageType_External, BfIRValue(), typeDataName); globalVariable = mBfIRBuilder->CreateGlobalVariable(mBfIRBuilder->MapTypeInst(typeTypeInst, BfIRPopulateType_Full), true, BfIRLinkageType_External, BfIRValue(), typeDataName);

View file

@ -3686,7 +3686,7 @@ BfTypedValue CeContext::Call(BfAstNode* targetSrc, BfModule* module, BfMethodIns
AutoTimer autoTimer(mCeMachine->mRevisionExecuteTime); AutoTimer autoTimer(mCeMachine->mRevisionExecuteTime);
SetAndRestoreValue<CeContext*> prevContext(mCeMachine->mCurContext, this); SetAndRestoreValue<CeContext*> prevContext(mCeMachine->mCurContext, this);
SetAndRestoreValue<CeEvalFlags> prevEvalFlags(mCurEvalFlags, flags); SetAndRestoreValue<CeEvalFlags> prevEvalFlags(mCurEvalFlags, flags);
SetAndRestoreValue<BfAstNode*> prevTargetSrc(mCurTargetSrc, targetSrc); SetAndRestoreValue<BfAstNode*> prevTargetSrc(mCurTargetSrc, targetSrc);
SetAndRestoreValue<BfModule*> prevModule(mCurModule, module); SetAndRestoreValue<BfModule*> prevModule(mCurModule, module);
@ -3942,6 +3942,10 @@ BfTypedValue CeContext::Call(BfAstNode* targetSrc, BfModule* module, BfMethodIns
Fail("Failed to encode return argument"); Fail("Failed to encode return argument");
} }
} }
else if (returnType->IsComposite())
{
returnValue = BfTypedValue(module->mBfIRBuilder->CreateConstArrayZero(module->mBfIRBuilder->MapType(returnType)), returnType);
}
else else
{ {
returnValue = BfTypedValue(module->mBfIRBuilder->GetFakeVal(), returnType); returnValue = BfTypedValue(module->mBfIRBuilder->GetFakeVal(), returnType);

View file

@ -109,6 +109,58 @@ namespace Tests
return (.)val; return (.)val;
} }
public struct TypePrinter<T>
{
const int cFieldCount = GetFieldCount();
const (int32, StringView)[cFieldCount] cMembers = Make();
static int GetFieldCount()
{
int fieldCount = 0;
for (let field in typeof(T).GetFields())
if (!field.IsStatic)
fieldCount++;
//Debug.WriteLine($"{fieldCount}");
return fieldCount;
}
static decltype(cMembers) Make()
{
if (cFieldCount == 0)
return default(decltype(cMembers));
decltype(cMembers) fields = ?;
int i = 0;
for (let field in typeof(T).GetFields())
{
if (!field.IsStatic)
fields[i++] = (field.MemberOffset, field.Name);
}
return fields;
}
public override void ToString(String strBuffer)
{
for (var t in cMembers)
{
if (@t != 0)
strBuffer.Append("\n");
strBuffer.AppendF($"{t.0} {t.1}");
}
}
}
struct TestType
{
public float mX;
public float mY;
public float mZ;
}
[Test] [Test]
public static void TestBasics() public static void TestBasics()
{ {
@ -122,12 +174,20 @@ namespace Tests
Compiler.Mixin("int val = 99;"); Compiler.Mixin("int val = 99;");
Test.Assert(val == 99); Test.Assert(val == 99);
MethodA(34, 45).IgnoreError(); MethodA(34, 45).IgnoreError();
Debug.Assert(LogAttribute.gLog == "Called Tests.Comptime.MethodA(int a, int b) 34 45\nError: Err(ErrorB)"); Debug.Assert(LogAttribute.gLog == "Called Tests.Comptime.MethodA(int a, int b) 34 45\nError: Err(ErrorB)");
var v0 = GetBigger((int8)123); var v0 = GetBigger((int8)123);
Test.Assert(v0.GetType() == typeof(int16)); Test.Assert(v0.GetType() == typeof(int16));
String str = scope .();
TypePrinter<TestType> tp = .();
tp.ToString(str);
Debug.Assert(str == """
0 mX
4 mY
8 mZ
""");
} }
} }
} }

View file

@ -1,9 +1,17 @@
#pragma warning disable 168
using System; using System;
namespace Tests namespace Tests
{ {
class Loops class Loops
{ {
struct StructA
{
public int32 mA;
public int32 mB;
}
[Test] [Test]
public static void TestBasics() public static void TestBasics()
{ {
@ -11,6 +19,13 @@ namespace Tests
{ {
} }
StructA[0] zeroLoop = default;
for (var val in zeroLoop)
{
StructA sa = val;
int idx = @val;
}
} }
} }
} }