Skip to content

Commit 35e6cc3

Browse files
committed
Work on making sum-types able to hold ref-to-structure types
1 parent d998a46 commit 35e6cc3

File tree

5 files changed

+76
-580
lines changed

5 files changed

+76
-580
lines changed

EpochDevTools32/Compiler/LLVM.epoch

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ GetLLVMTypeForEpochType : LLVMContextHandle context, integer typeid -> LLVMType
422422
boolean found = BinaryTreeCopyPayload<LLVMType>(LLVMSumTypeTable.RootNode, typeid, t)
423423
if(!found)
424424
{
425-
t = EpochLLVMSumTypeCreate(context, GetPooledString(GetNameOfType(typeid)), 8) // TODO - fix sum typed objects to packed storage
425+
t = EpochLLVMSumTypeCreate(context, GetPooledString(GetNameOfType(typeid)), GetTypeSize(typeid)) // TODO - fix sum typed objects to packed storage
426426
BinaryTreeCreateOrInsert<LLVMType>(LLVMSumTypeTable, typeid, t)
427427
}
428428
}
@@ -1005,9 +1005,12 @@ EmitSingleCodeBlockEntryToLLVM : LLVMBuildContext ref context, Statement ref ent
10051005
if (IsReferenceType(rhstype))
10061006
{
10071007
EmitPartialExpressionListToLLVM(context, entry.Parameters)
1008-
EpochLLVMCodeCreateDereference(context.Context)
1008+
1009+
// TODO - HACK - this should only dereference if the LHS is not reftype
1010+
//EpochLLVMCodeCreateDereference(context.Context)
1011+
10091012
EpochLLVMCodePushRawAlloca(context.Context, stalloca)
1010-
EpochLLVMCodePushInteger(context.Context, MakeNonReferenceType(rhstype))
1013+
EpochLLVMCodePushInteger(context.Context, rhstype)
10111014
EpochLLVMCodeCreateWriteStructurePopSumType(context.Context)
10121015
}
10131016
else
@@ -2443,7 +2446,7 @@ EmitTypeMatcherParamsInLLVM : LLVMContextHandle context, list<FunctionSignature>
24432446
else
24442447
{
24452448
boolean refflag = IsReferenceType(params.value.Type)
2446-
integer paramtype = MakeNonReferenceType(params.value.Type)
2449+
integer paramtype = params.value.Type // TODO - HACK - was makenonreftype but that breaks reftypes inside sum types
24472450
while((paramtype & 0x7f000000) == 0x05000000)
24482451
{
24492452
paramtype = FindTypeAliasBase(paramtype)
@@ -2457,7 +2460,7 @@ EmitTypeMatcherParamsInLLVM : LLVMContextHandle context, list<FunctionSignature>
24572460
{
24582461
EpochLLVMCodeCreateReadParam(context, paramindex)
24592462
EpochLLVMCodePushExtractedStructValue(context, 0)
2460-
EpochLLVMCodePushInteger(context, MakeNonReferenceType(paramtype))
2463+
EpochLLVMCodePushInteger(context, paramtype)
24612464
EpochLLVMCodeOperatorIntegerEquals(context)
24622465
EpochLLVMCodeCreateCondBranch(context, EpochLLVMCodePopValue(context), nextparamblock, nextoverloadblock)
24632466
++relevantparams

EpochDevTools32/Compiler/Structures.epoch

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,3 +488,29 @@ ExtractAllMemberTypes : list<StructureMember> ref members, list<ParameterTypeLis
488488
}
489489

490490
ExtractAllMemberTypes : nothing, nothing
491+
492+
493+
ComputeStructureSize : integer typeid -> integer size = 0
494+
{
495+
integer structurename = GetNameOfType(typeid)
496+
497+
ContextNode<StructureDefinition> wrap = nothing
498+
boolean found = SearchBinaryTreeForPayload<StructureDefinition>(GlobalRootNamespace.Structures.RootNode, structurename, wrap)
499+
assert(found)
500+
501+
ComputeStructureMemberSizes(wrap, size)
502+
}
503+
504+
ComputeStructureMemberSizes : StructureDefinition ref structuredef, integer ref size
505+
{
506+
ComputeStructureMemberSizes(structuredef.Members, size)
507+
}
508+
509+
ComputeStructureMemberSizes : list<StructureMember> ref members, integer ref size
510+
{
511+
size = size + GetTypeSize(GetMemberTypeDecompose(members.value))
512+
ComputeStructureMemberSizes(members.next, size)
513+
}
514+
515+
ComputeStructureMemberSizes : nothing, integer ref size
516+

EpochDevTools32/Compiler/SumTypes.epoch

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ ResolveSumTypeBases : list<SumTypeBase> ref bases -> boolean success = true
193193
success = false
194194
}
195195

196+
// TODO - HACK - this forces all structures in sum types to be indirected!
197+
if(IsStructureType(resolvedtype))
198+
{
199+
resolvedtype = MakeReferenceType(resolvedtype)
200+
}
201+
196202
bases.value.Name = resolvedtype
197203
}
198204

EpochDevTools32/Compiler/TypeInfo.epoch

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,25 @@ GetTypeSize : integer typeid -> integer size = 0
3333
}
3434
elseif(IsStructureType(typeid)) // StructureHandle
3535
{
36-
size = 8
36+
if(IsReferenceType(typeid))
37+
{
38+
size = 8
39+
}
40+
else
41+
{
42+
size = ComputeStructureSize(typeid)
43+
}
3744
}
3845
elseif((typeid & 0xff000000) == 0x07000000) // SumType
3946
{
40-
size = 4 + 8
47+
if(IsReferenceType(typeid))
48+
{
49+
size = 8
50+
}
51+
else
52+
{
53+
size = 4 + GetLargestSumTypeBaseSize(typeid)
54+
}
4155
}
4256
elseif(typeid == 0x00000004) // Nothing
4357
{

0 commit comments

Comments
 (0)