Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
UplinkCoder committed Jun 17, 2024
1 parent de0a794 commit 2f6be30
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 32 deletions.
17 changes: 10 additions & 7 deletions debug/debug_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,22 @@ static MHD_COMPLETED_CB (MhdCompletionCallback)
{
}

const char* DebugServer_AddString(debug_server_t* debugServer,
const char* name, uint32_t len)
{
char* memory = Allocator_Calloc(&debugServer->Allocator, char, len);
memcpy(memory, name, len);
return memory;
}


void DebugServer_AddRoute(debug_server_t* debugServer,
const char* url,
mhd_handler_t handler)
{
debug_server_route_t route;

route.Url = url;
route.Url = DebugServer_AddString(debugServer, url, strlen(url));
route.Handler = handler;

ARENA_ARRAY_ADD(debugServer->Routes, route);
Expand Down Expand Up @@ -773,12 +782,6 @@ metac_identifier_ptr_t DebugServer_Category(debug_server_t* debugServer, const c
return GetOrAddIdentifier(&debugServer->CategoryTable, IDENTIFIER_KEY(hash, len), category);
}

const char* DebugServer_AddString(debug_server_t* debugServer, const char* name, uint32_t len)
{
char* memory = Allocator_Calloc(&debugServer->Allocator, char, len);
memcpy(memory, name, len);
return memory;
}

void Debug_Logf(debug_server_t* debugServer,
const char* category,
Expand Down
9 changes: 6 additions & 3 deletions parser/metac_expr_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1627,9 +1627,12 @@ metac_expr_t* MetaCParser_PopExpr(metac_parser_t* self)
metac_expr_t* result = 0;

metac_expr_t* top = MetaCParser_TopExpr(self);
const char* expr = MetaCPrinter_PrintExpr(&self->DebugPrinter, top);
Debug_Logf(g_DebugServer, "Parser", "[PopExpr] %s", expr);
MetaCPrinter_Reset(&self->DebugPrinter);
if (top)
{
const char* expr = MetaCPrinter_PrintExpr(&self->DebugPrinter, top);
Debug_Logf(g_DebugServer, "Parser", "[PopExpr] %s", expr);
MetaCPrinter_Reset(&self->DebugPrinter);
}
/*
printf("Poping ExprStack(%d): %s\n",
self->ExprParser.ExprStackCount,
Expand Down
1 change: 0 additions & 1 deletion parser/metac_lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,6 @@ metac_token_t* MetaCLexerLexNextToken(metac_lexer_t* self,
uint32_t charLength = 0;
text++;
token.TokenType = tok_char;
uint32_t charHash = ~0u;
c = *text++;
eatenChars++;
if (c == '\'')
Expand Down
16 changes: 10 additions & 6 deletions parser/metac_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,13 @@ metac_token_t* MetaCParser_PeekToken_(metac_parser_t* self, int32_t p, uint32_t
{
metac_token_t* result = 0;
assert(self->Lexer->TokenCount);
uint32_t CurrentTokenIndex = self->CurrentTokenIndex;

#if !defined(NO_PREPROCESSOR)

metac_preprocessor_t* preProc = self->Preprocessor;

uint32_t CurrentTokenIndex =
CurrentTokenIndex =
(preProc && preProc->DefineTokenStackCount)
? preProc->DefineTokenIndexStack[preProc->DefineTokenStackCount - 1]:
self->CurrentTokenIndex;
Expand All @@ -603,10 +605,10 @@ metac_token_t* MetaCParser_PeekToken_(metac_parser_t* self, int32_t p, uint32_t
goto Lpeek;
} else
#endif
if (cast(uint32_t)(self->CurrentTokenIndex + (p - 1)) < self->Lexer->TokenCount)
if (cast(uint32_t)(CurrentTokenIndex + (p - 1)) < self->Lexer->TokenCount)
{
Lpeek:
result = self->Lexer->Tokens + self->CurrentTokenIndex + (p - 1);
result = self->Lexer->Tokens + CurrentTokenIndex + (p - 1);
if (result->TokenType != tok_newline)
{
self->LastLocation =
Expand All @@ -625,9 +627,11 @@ metac_token_t* MetaCParser_PeekToken_(metac_parser_t* self, int32_t p, uint32_t
}
#endif
}

Debug_Logf(g_DebugServer, "Parser","%s = MetaCParser_PeekToken(offset=%d, line=%d)", MetaCTokenEnum_toChars(result->TokenType), p, line);

if (result)
{
Debug_Logf(g_DebugServer, "Parser","%s = MetaCParser_PeekToken(offset=%d, line=%d)", MetaCTokenEnum_toChars(result->TokenType), p, line);
}

return result;
}

Expand Down
7 changes: 7 additions & 0 deletions semantic/metac_expr_semantic.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,12 @@ metac_sema_expr_t* MetaCSemantic_doExprSemantic_(metac_sema_state_t* self,
const char* callFun,
uint32_t callLine)
{
static metac_printer_t debugPrinter = {0};
if (!debugPrinter.StringTable)
{
MetaCPrinter_Init(&debugPrinter, self->ParserIdentifierTable, self->ParserStringTable, 0);
}

if (expr->Kind == expr_and)
{
expr = RewriteAndtoAddrIfNeeded(self, expr);
Expand Down Expand Up @@ -680,6 +686,7 @@ metac_sema_expr_t* MetaCSemantic_doExprSemantic_(metac_sema_state_t* self,
}
else
{
xprintf("Unary dot %s not recognized: %s\n", MetaCExprKind_toChars(result->E1->Kind), MetaCPrinter_PrintExpr(&debugPrinter, expr));
assert(0);
}
} break;
Expand Down
28 changes: 14 additions & 14 deletions semantic/metac_semantic.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ metac_sema_stmt_t* MetaCSemantic_doStmtSemantic_(metac_sema_state_t* self,
AllocNewSemaBlockStmt(self, 0, stmtCount, cast(void**)&result);

metac_scope_owner_t parent = {SCOPE_OWNER_V(scope_owner_statement,
BlockStmtIndex(self, semaBlockStmt))};
BlockStmtIndex(self, semaBlockStmt))};

MetaCSemantic_PushNewScope(self,
scope_owner_block,
Expand Down Expand Up @@ -616,59 +616,59 @@ metac_sema_stmt_t* MetaCSemantic_doStmtSemantic_(metac_sema_state_t* self,
{
hash ^= stmt_for;

stmt_for_t* for_ = (stmt_for_t*) stmt;
stmt_for_t* forStmt = (stmt_for_t*) stmt;
sema_stmt_for_t* semaFor =
AllocNewSemaStmt(self, stmt_for, &result);

metac_scope_t* forScope = semaFor->Scope =
semaFor->Scope =
MetaCSemantic_PushNewScope(self,
scope_owner_statement,
METAC_NODE(semaFor));

if (METAC_NODE(for_->ForInit) != emptyNode)
if (METAC_NODE(forStmt->ForInit) != emptyNode)
{
if (IsExprNode(for_->ForInit->Kind))
if (IsExprNode(forStmt->ForInit->Kind))
{

semaFor->ForInit = cast(metac_node_t)
MetaCSemantic_doExprSemantic(self,
(cast(metac_expr_t*)for_->ForInit), 0);
(cast(metac_expr_t*)forStmt->ForInit), 0);
}
else
{
semaFor->ForInit = cast(metac_node_t)
MetaCSemantic_doDeclSemantic(self,
(cast(metac_decl_t*)for_->ForInit));
(cast(metac_decl_t*)forStmt->ForInit));
}
hash = CRC32C_VALUE(hash, semaFor->ForInit->Hash);
}

if (METAC_NODE(for_->ForCond) != emptyNode)
if (METAC_NODE(forStmt->ForCond) != emptyNode)
{
semaFor->ForCond =
MetaCSemantic_doExprSemantic(self, for_->ForCond, 0);
MetaCSemantic_doExprSemantic(self, forStmt->ForCond, 0);
hash = CRC32C_VALUE(hash, semaFor->ForCond->Hash);
}
else
{
METAC_NODE(semaFor->ForCond) = emptyNode;
}

if (METAC_NODE(for_->ForPostLoop) != emptyNode)
if (METAC_NODE(forStmt->ForPostLoop) != emptyNode)
{
semaFor->ForPostLoop =
MetaCSemantic_doExprSemantic(self, for_->ForPostLoop, 0);
MetaCSemantic_doExprSemantic(self, forStmt->ForPostLoop, 0);
hash = CRC32C_VALUE(hash, semaFor->ForPostLoop->Hash);
}
else
{
METAC_NODE(semaFor->ForPostLoop) = emptyNode;
}

if (METAC_NODE(for_->ForBody) != emptyNode)
if (METAC_NODE(forStmt->ForBody) != emptyNode)
{
metac_sema_stmt_t* forBody =
MetaCSemantic_doStmtSemantic(self, for_->ForBody);
MetaCSemantic_doStmtSemantic(self, forStmt->ForBody);
semaFor->ForBody = forBody;
hash = CRC32C_VALUE(hash, semaFor->ForBody->Hash);
}
Expand Down Expand Up @@ -815,7 +815,7 @@ scope_insert_error_t MetaCSemantic_RegisterInScope(metac_sema_state_t* self,
{
task_t* waitingTask = cast(task_t*)waiter->Continuation->arg;
// assert(waitingTask->TaskFlags == Task_Waiting);
printf("Found matching waiter\n");
xprintf("Found matching waiter\n");
U32(waitingTask->TaskFlags) &= (~Task_Waiting);
U32(waitingTask->TaskFlags) |= Task_Resumable;
// Worker_EnqueueTask(worker, waitingTask);
Expand Down
3 changes: 2 additions & 1 deletion semantic/metac_type_semantic.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,10 +972,11 @@ metac_type_index_t TypeEnumSemantic(metac_sema_state_t* self,

MetaCSemantic_PopTemporaryScope(self);
{
/*
metac_printer_t debugPrinter;
MetaCPrinter_Init(&debugPrinter, self->ParserIdentifierTable, self->ParserStringTable, 0);
/*
for(uint32_t i = 0; i < tmpSemaEnum.MemberCount; i++)
{
const char* valueString = MetaCPrinter_PrintSemaNode(&debugPrinter,
Expand Down

0 comments on commit 2f6be30

Please sign in to comment.