Skip to content

Commit

Permalink
Fix compilation and add new helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
UplinkCoder committed Feb 28, 2024
1 parent 7e65118 commit f9a9b91
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 35 deletions.
2 changes: 2 additions & 0 deletions debug/debug_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,9 @@ void Debug_Logf(debug_server_t* debugServer,
OS.GetTimeStamp(&log.Timestamp);

va_start(list, fmt);
ALIGN_STACK();
len = vsnprintf(buffer, sizeof(buffer), fmt, list);
RESTORE_STACK();
va_end(list);

if (len >= ARRAY_SIZE(buffer))
Expand Down
10 changes: 5 additions & 5 deletions os/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#define _scope

#define xprintf(...) \
ALIGN_STACK() \
printf(__VA_ARGS__); \
RESTORE_STACK();

#define cast(T) (T)

#ifndef ARRAY_SIZE
Expand All @@ -21,11 +26,6 @@
# define snprintf _snprintf
#endif

#define xprintf(...) \
ALIGN_STACK() \
printf(__VA_ARGS__); \
RESTORE_STACK();

#if (defined(_MSC_VER) && (_MSC_VER < 1600) )
# define __STDC_LIMIT_MACROS
# include "../3rd_party/stdint_msvc.h"
Expand Down
3 changes: 2 additions & 1 deletion os/metac_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@ arena_ptr_t Allocator_AddArena(metac_alloc_t* allocator, tagged_arena_t* arena)
{
uint32_t newArenaCapa = ALIGN16(allocator->ArenasCapacity + 1);
uint32_t inUseArenasCount = allocator->inuseArenasCount;
ALIGN_STACK();
allocator->Arenas = cast(tagged_arena_t*)
realloc(allocator->Arenas, sizeof(tagged_arena_t) * newArenaCapa);

memcpy(allocator->Arenas + newArenaCapa - inUseArenasCount,
allocator->Arenas + allocator->ArenasCapacity - inUseArenasCount,
inUseArenasCount * sizeof(tagged_arena_t));

RESTORE_STACK();
allocator->ArenasCapacity = newArenaCapa;
goto LaddArena;
}
Expand Down
9 changes: 1 addition & 8 deletions parser/metac_alloc_node.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "../os/metac_atomic.h"
#include "metac_alloc_node.h"
#include <string.h>
#include <stdlib.h>
Expand Down Expand Up @@ -122,14 +123,6 @@ FOREACH_ALLOCATED_PARSER_TYPE(DECLARE_STATIC_ARRAY)
static uint32_t _nodeCounter = 1;


#ifndef ATOMIC
#define INC(v) \
(v++)
#else
#define INC(v)
(__builtin_atomic_fetch_add(&v, __ATOMIC_RELEASE))
#endif

/// TODO: lock during realloc
#define REALLOC_BOILERPLATE(PREFIX) \
if (PREFIX ## _capacity <= PREFIX ## _size) \
Expand Down
18 changes: 18 additions & 0 deletions parser/metac_identifier_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,24 @@ int32_t MetaCIdentifierTable_HasKey(metac_identifier_table_t* table,
return result;
}

static inline metac_identifier_ptr_t
MetaCIdentifierTable_CopyIdentifier(const metac_identifier_table_t* srcTable,
metac_identifier_table_t* dstTable,
metac_identifier_ptr_t srcIdPtr)
{
assert(srcIdPtr.v);
const char* idChars =
IdentifierPtrToCharPtr((metac_identifier_table_t*)srcTable, srcIdPtr);
const uint32_t idLen = strlen(idChars);
const uint32_t idHash = crc32c_nozero(~0, idChars, idLen);
const uint32_t idKey = IDENTIFIER_KEY(idHash, idLen);

metac_identifier_ptr_t newPtr =
GetOrAddIdentifier(dstTable, idKey, idChars);
return newPtr;
}


#define slot_t metac_identifier_table_slot_t

void InsertSlot(slot_t* slots, slot_t slot, const uint32_t slotIndexMask)
Expand Down
2 changes: 1 addition & 1 deletion parser/metac_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2438,7 +2438,7 @@ static stmt_block_t* MetaCParser_ParseBlockStmt(metac_parser_t* self,

const char* MetaCExprKind_toChars(metac_expr_kind_t type)
{
const char* result = 0;
const char* result = "Value out of Range";

#define CASE_MACRO(EXPR_TYPE) \
case EXPR_TYPE : {result = #EXPR_TYPE;} break;
Expand Down
13 changes: 3 additions & 10 deletions repl/repl.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,9 @@ static inline void TranslateIdentifier(metac_identifier_table_t* dstTable,
const metac_identifier_table_t* srcTable,
metac_identifier_ptr_t* idPtrP)
{
assert(idPtrP->v);
const char* idChars =
IdentifierPtrToCharPtr((metac_identifier_table_t*)srcTable, *idPtrP);
const uint32_t idLen = strlen(idChars);
const uint32_t idHash = crc32c_nozero(~0, idChars, idLen);
const uint32_t idKey = IDENTIFIER_KEY(idHash, idLen);

metac_identifier_ptr_t newPtr =
GetOrAddIdentifier(dstTable, idKey, idChars);
idPtrP->v = newPtr.v;
metac_identifier_ptr_t dstPtr =
MetaCIdentifierTable_CopyIdentifier(srcTable, dstTable, *idPtrP);
(*idPtrP) = dstPtr;
}

static inline int TranslateIdentifiers(metac_node_t node, void* ctx)
Expand Down
2 changes: 1 addition & 1 deletion semantic/metac_expr_semantic.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ metac_sema_expr_t* MetaCSemantic_doExprSemantic_(metac_sema_state_t* self,
case expr_invalid:
default:
{
fprintf(stderr, "expression semantic doesn't support %s yet.\n",
xprintf("expression semantic doesn't support %s yet.\n",
MetaCExprKind_toChars(expr->Kind));
assert(0);
}
Expand Down
18 changes: 9 additions & 9 deletions semantic/metac_type_semantic.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,9 @@ void MetaCSemantic_ComputeEnumValues(metac_sema_state_t* self,

//TODO you want to make CurrentValue a metac_sema_expr_t
// such that you can interpret the increment operator
//SetInProgress(semaEnum, "Members");
// semaEnum->Name = MetaCSemantic_RegisterIdentifier(self, enum->Identifier);
// MetaCSemantic_SetInProgress(self, semaEnum, "Members");

semaEnum->Name = enum_->Identifier;
semaEnum->Name = MetaCIdentifierTable_CopyIdentifier(self->ParserIdentifierTable, &self->SemanticIdentifierTable, enum_->Identifier);
semaEnum->Header.Kind = decl_type_enum;
if (METAC_NODE(enum_->BaseType) == emptyNode)
{
Expand All @@ -744,17 +743,18 @@ void MetaCSemantic_ComputeEnumValues(metac_sema_state_t* self,
memberIdx < memberCount;
memberIdx++, member = member->Next)
{
metac_sema_expr_t* semaMember = memberPlaceholders + memberIdx;
metac_sema_expr_t* placeHolder = memberPlaceholders + memberIdx;

memberPlaceholders[memberIdx].Kind = expr_unknown_value;
memberPlaceholders[memberIdx].TypeIndex = semaEnum->BaseType;
memberPlaceholders[memberIdx].Expr = member->Value;
placeHolder->Kind = expr_unknown_value;
placeHolder->TypeIndex = semaEnum->BaseType;
placeHolder->Expr = member->Value;

MetaCSemantic_RegisterInScope(self, member->Name,
METAC_NODE(semaMember));
METAC_NODE(placeHolder));
}
}

// Set the currentScope to be an override scope
// Since we are inserting members
self->CurrentScope->ScopeTable.AllowOverride = true;
{
MetaCSemantic_PushOnResolveFail(self, OnResolveFail_ReturnNull);
Expand Down

0 comments on commit f9a9b91

Please sign in to comment.