Skip to content

Commit b21b91c

Browse files
committed
Commit random fixes
1 parent 391b408 commit b21b91c

File tree

12 files changed

+101
-30
lines changed

12 files changed

+101
-30
lines changed

cache/cached_tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ name_cache_ptr_t GetOrAddNameByKey(cache_t* cache, const char* name,
119119
currentBranch;)
120120
{
121121
int cmp_result = entry_key - currentBranch->entry_key;
122-
if (!cmp_result)
122+
if (cmp_result == 0)
123123
{
124124
const char* cached_name = (currentBranch->name_ptr.v - 4)
125125
+ cache->name_stringtable;

codegen/metac_codegen.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ void MetaCCodegen_doGlobal(metac_bytecode_ctx_t* ctx, metac_sema_decl_t* decl, u
324324
}
325325
else
326326
{
327-
assert(0);
327+
assert(!"Invalid type index not expected here");
328328
}
329329

330330
}
@@ -1534,6 +1534,10 @@ static void MetaCCodegen_doExpr(metac_bytecode_ctx_t* ctx,
15341534
{
15351535
gen.Store32(c, &address, bcValues + i);
15361536
}
1537+
else if (te.TypeIndex.v == TYPE_INDEX_V(type_index_basic, type_float))
1538+
{
1539+
gen.Store32(c, &address, bcValues + i);
1540+
}
15371541
else if (te.TypeIndex.v == TYPE_INDEX_V(type_index_basic, type_type))
15381542
{
15391543
gen.Store32(c, &address, bcValues + i);
@@ -2078,12 +2082,12 @@ void MetaCCodegen_doStmt(metac_bytecode_ctx_t* ctx,
20782082
{
20792083
BCValue dontCare;
20802084
MetaCCodegen_doExpr(ctx,
2081-
(metac_sema_expr_t*)forStmt->ForInit, &dontCare, _Discard);
2085+
cast(metac_sema_expr_t*)forStmt->ForInit, &dontCare, _Discard);
20822086
}
20832087
else
20842088
{
20852089
MetaCCodegen_doLocalVar(ctx,
2086-
(sema_decl_variable_t*)forStmt->ForInit);
2090+
cast(sema_decl_variable_t*)forStmt->ForInit);
20872091
}
20882092
}
20892093

libinterpret/bc_interpreter_backend.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,6 +2179,10 @@ LendSearch2:{}
21792179

21802180
if (cpySrc != cpyDst && cpySize != 0)
21812181
{
2182+
uint8_t* cpySrcP;
2183+
uint8_t* cpyDstP;
2184+
uint8_t* heapData = heapPtr->heapData;
2185+
21822186
// assert(cpySize, "cpySize == 0");
21832187
assert(cpySrc);//, "cpySrc == 0" ~ " inLine: " ~ itos(lastLine));
21842188

@@ -2188,10 +2192,27 @@ LendSearch2:{}
21882192
//, "Overlapping MemCpy is not supported --- src: " ~ itos(cpySrc)
21892193
// ~ " dst: " ~ itos(cpyDst) ~ " size: " ~ itos(cpySize));
21902194

2191-
uint8_t* heapData = heapPtr->heapData;
21922195

2193-
uint8_t* cpyDstP = heapData + cpyDst;
2194-
uint8_t* cpySrcP = heapData + cpySrc;
2196+
switch (ClassifyAddress(cpySrc))
2197+
{
2198+
case AddressKind_External:
2199+
cpySrcP = state.externals[cpySrc & ~AddrMask].addr;
2200+
break;
2201+
case AddressKind_Heap:
2202+
cpySrcP = heapData + cpySrc;
2203+
break;
2204+
default : assert(0);
2205+
}
2206+
switch (ClassifyAddress(cpyDst))
2207+
{
2208+
case AddressKind_External:
2209+
cpyDstP = state.externals[cpyDst & ~AddrMask].addr;
2210+
break;
2211+
case AddressKind_Heap:
2212+
cpyDstP = heapData + cpyDst;
2213+
break;
2214+
default : assert(0);
2215+
}
21952216

21962217
memcpy(cpyDstP, cpySrcP, cpySize * sizeof(*heapPtr->heapData));
21972218
//heapPtr->heapData[cpyDst .. cpyDst + cpySize] = heapPtr->heapData[cpySrc .. cpySrc + cpySize];

os/metac_alloc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ void* Allocator_Realloc_(metac_alloc_t* alloc, void* oldMem,
334334
for(i = 0; i < alloc->inuseArenasCount; i++)
335335
{
336336
tagged_arena_t* candidate = &alloc->Arenas[alloc->ArenasCapacity - (i + 1)];
337-
if (Arena_ContainsMemoryP(candidate->Memory, oldMem))
337+
if (Arena_ContainsMemoryP(candidate, oldMem))
338338
{
339339
oldArena = candidate;
340340
oldArenaPtr.Index = i;
@@ -343,12 +343,14 @@ void* Allocator_Realloc_(metac_alloc_t* alloc, void* oldMem,
343343
}
344344
}
345345

346+
347+
if (!oldArena)
346348
{
347349
uint32_t i;
348350
for(i = 0; i < alloc->ArenasCount; i++)
349351
{
350352
tagged_arena_t* candidate = &alloc->Arenas[i];
351-
if (candidate->Memory == oldMem)
353+
if (Arena_ContainsMemoryP(candidate, oldMem))
352354
{
353355
oldArena = candidate;
354356
oldArenaPtr.Index = i;

parser/metac_parser.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,7 @@ decl_type_t* MetaCParser_ParseTypeDecl(metac_parser_t* self, metac_decl_t* paren
10451045

10461046
while(IsTypeToken(tokenType))
10471047
{
1048+
loc = LocationFromToken(self, currentToken);
10481049
if (tokenType == tok_lBrace)
10491050
{
10501051
STACK_ARENA_ARRAY(decl_type_t*, types, 16, &self->Allocator)
@@ -1058,6 +1059,11 @@ decl_type_t* MetaCParser_ParseTypeDecl(metac_parser_t* self, metac_decl_t* paren
10581059
{
10591060
ARENA_ARRAY_ADD(types,
10601061
MetaCParser_ParseTypeDecl(self, cast(metac_decl_t*)type, 0));
1062+
if (types[typesCount - 1]->TypeKind == type_invalid)
1063+
{
1064+
ParseError(loc, "Parsed invalid type");
1065+
MetaCParser_Advance(self);
1066+
}
10611067
if (MetaCParser_PeekMatch(self, tok_comma, 1))
10621068
{
10631069
MetaCParser_Match(self, tok_comma);
@@ -1115,6 +1121,7 @@ decl_type_t* MetaCParser_ParseTypeDecl(metac_parser_t* self, metac_decl_t* paren
11151121
hash = CRC32C_VALUE(hash, type->TypeIdentifier);
11161122
if (MetaCParser_PeekMatch(self, tok_bang, 1))
11171123
{
1124+
11181125
decl_type_template_instance_t* tinst =
11191126
AllocNewDecl(decl_type_template_instance, &result);
11201127

printer/metac_printer.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,16 +1743,16 @@ static inline void PrintSemaExpr(metac_printer_t* self,
17431743
metac_sema_expr_t** tupleElement =
17441744
semaExpr->TupleExprs;
17451745
PrintChar(self, '{');
1746-
for(uint32_t i = 0;
1747-
i < tupleExprCount - 1;
1748-
i++)
1749-
{
1750-
PrintSemaExpr(self, sema, tupleElement[i]);
1751-
PrintChar(self, ',');
1752-
PrintSpace(self);
1753-
}
17541746
if (tupleExprCount > 0)
17551747
{
1748+
for(uint32_t i = 0;
1749+
i < tupleExprCount - 1;
1750+
i++)
1751+
{
1752+
PrintSemaExpr(self, sema, tupleElement[i]);
1753+
PrintChar(self, ',');
1754+
PrintSpace(self);
1755+
}
17561756
PrintSemaExpr(self, sema, tupleElement[tupleExprCount - 1]);
17571757
}
17581758
PrintChar(self, '}');

semantic/metac_expr_fold.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,32 @@
55
#define CASE_(EXP) \
66
case EXP:
77

8-
bool IsLiteral(metac_expr_kind_t kind)
8+
bool IsLiteral(metac_sema_expr_t* e)
99
{
10+
metac_expr_kind_t kind = e->Kind;
1011
switch(kind)
1112
{
12-
default: return false;
13+
case expr_type:
14+
return true;
1315

1416
FOREACH_LITERAL_EXP(CASE_)
1517
return true;
1618
}
19+
20+
if (kind == expr_tuple)
21+
{
22+
const uint32_t tupleExprCount = e->TupleExprCount;
23+
for(uint32_t i = 0; i < tupleExprCount; i++)
24+
{
25+
metac_sema_expr_t* te = e->TupleExprs[i];
26+
if (!IsLiteral(te))
27+
return false;
28+
}
29+
return true;
30+
}
31+
32+
// by default return false;
33+
return false;
1734
}
1835

1936
bool IsConstant(metac_sema_expr_t* expr)
@@ -187,4 +204,4 @@ constant_fold_result_t ConstantFold_SubExps(metac_sema_state_t* sema, metac_sema
187204
return result;
188205

189206
}
190-
#endif
207+
#endif

semantic/metac_expr_fold.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef struct constant_fold_result_t
2626
constant_fold_ctx_t Ctx;
2727
} constant_fold_result_t;
2828

29-
bool IsLiteral(metac_expr_kind_t e);
29+
bool IsLiteral(metac_sema_expr_t* e);
3030

3131
bool IsConstant(metac_sema_expr_t* e);
3232

semantic/metac_expr_semantic.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ EvaluateExpr(metac_sema_state_t* sema,
135135
return result;
136136
}
137137

138-
if (IsLiteral(e->Kind))
138+
if (IsLiteral(e))
139139
{
140140
return *e;
141141
}
@@ -1107,6 +1107,27 @@ metac_sema_expr_t* MetaCSemantic_doExprSemantic_(metac_sema_state_t* self,
11071107
{
11081108
result->TypeIndex.v = TYPE_INDEX_V(type_index_basic, type_code);
11091109
} break;
1110+
case expr_stringize:
1111+
{
1112+
metac_expr_t* e1 = expr->E1;
1113+
uint32_t identifierLength = 0;
1114+
if (e1->Kind == expr_identifier)
1115+
{
1116+
identifierLength = LENGTH_FROM_IDENTIFIER_KEY(e1->IdentifierKey);
1117+
result->TypeIndex = MetaCSemantic_GetArrayTypeOf(self,
1118+
MetaCSemantic_GetTypeIndex(self, type_char, (decl_type_t*)emptyPointer),
1119+
identifierLength + 1
1120+
);
1121+
}
1122+
else
1123+
{
1124+
xfprintf(stderr,
1125+
"expr_semantic does not support %s as a stringize expression\n",
1126+
MetaCExprKind_toChars(e1->Kind)
1127+
);
1128+
}
1129+
} break;
1130+
11101131
case expr_dot_compiler:
11111132
{
11121133
if (expr->E1->Kind != expr_call)

semantic/metac_semantic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ void MetaCSemantic_doDeclSemantic_Task(task_t* task)
12491249
const char* taskPrint = doDeclSemantic_PrintFunction(task);
12501250
xprintf("Task: %s\n", taskPrint);
12511251

1252-
Allocator_Realloc(&ctx->Sema->TempAlloc, taskPrint, char, 0);
1252+
// Allocator_Realloc(&ctx->Sema->TempAlloc, taskPrint, char, 0);
12531253
ctx->Result =
12541254
MetaCSemantic_doDeclSemantic_(ctx->Sema, ctx->Decl, Origin.File, Origin.Line);
12551255
}

0 commit comments

Comments
 (0)