Skip to content

Commit 6cb666a

Browse files
committed
Various fixes and starting on handling eject expressions
1 parent 9a311f6 commit 6cb666a

File tree

11 files changed

+72
-19
lines changed

11 files changed

+72
-19
lines changed

compiler_intrinsics/metac_compiler_interface.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@ typedef void* type;
1212
typedef enum type_kind_t
1313
{
1414
TypeKind_Invalid,
15+
TypeKind_Enum,
1516
TypeKind_Struct = 5,
1617
TypeKind_Class = TypeKind_Struct + 2,
1718
TypeKind_Max
1819
} type_kind_t;
1920

21+
typedef struct metac_enum_members_t {
22+
const char** Names;
23+
uint32_t* Values;
24+
uint32_t Count;
25+
} metac_enum_members_t;
26+
2027
typedef struct metac_compiler_t
2128
{
2229
void* semanticState;
@@ -50,6 +57,11 @@ typedef struct metac_compiler_t
5057
void (*IdentfierCb)(const char* idChars, uint32_t idKey, void* context),
5158
void* context);
5259
void (*PrintInt) (int32_t* value);
60+
61+
metac_enum_members_t* (*GetEnumMembers) (struct metac_compiler_t* compilerP, type* T);
62+
63+
metac_node_t (*ResolveNode)(struct metac_compiler_t* compilerP, const char* name);
64+
5365
} metac_compiler_t;
5466

5567
/* Proposed Interface:

os/os.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <stdio.h>
66

77
#define DEFAULT_PAGESIZE 4096
8+
89
os_error_t PageAlloc(uint32_t minSize, uint32_t* allocatedSize, void** outMemory);
910
os_error_t GetTimeStamp(uint32_t* tsp);
1011
os_error_t SetStartTime(void);
@@ -41,6 +42,7 @@ os_error_t PageAlloc(uint32_t minSize, uint32_t* allocatedSize, void** outMemory
4142
#else
4243
# error "OS not supported"
4344
#endif
45+
4446
if (result)
4547
{
4648
(*allocatedSize) = allocated;

parser/metac_expr_parser.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,12 @@ metac_expr_t* MetaCParser_ParseUnaryExpr(metac_parser_t* self)
11821182
MetaCParser_Match(self, tok_kw_eject);
11831183
result = AllocNewExpr(expr_eject);
11841184
//PushOperator(expr_eject);
1185+
1186+
if (NextIsStmt(self, 1))
1187+
{
1188+
result->EjectedStmt = MetaCParser_ParseStmt(self, 0, 0);
1189+
}
1190+
11851191
result->E1 = MetaCParser_ParseExpr(self, expr_flags_none, 0);
11861192
result->Hash = CRC32C_VALUE(eject_key, result->E1->Hash);
11871193
//PushOperand(result);

parser/metac_node.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
\
4040
M(decl_function) \
4141
\
42-
M(decl_preproc) \
43-
\
4442
M(decl_label) \
4543
M(decl_comment)
4644

parser/metac_parser.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,29 @@ static metac_storageclasses_t ParseStorageClasses(metac_parser_t* self)
17371737
return result;
17381738
}
17391739

1740+
bool NextIsStmt(metac_parser_t* self, int32_t offset)
1741+
{
1742+
metac_token_t* peek = MetaCParser_PeekToken(self, offset);
1743+
metac_token_t* peek2 = MetaCParser_PeekToken(self, offset + 1);
1744+
metac_token_enum_t tok = peek->TokenType;
1745+
1746+
return (tok == tok_kw_if ||
1747+
tok == tok_kw_while ||
1748+
tok == tok_kw_do ||
1749+
(tok == tok_at && peek2->IdentifierKey == run_key) ||
1750+
tok == tok_kw_for ||
1751+
tok == tok_kw_switch ||
1752+
(tok == tok_identifier && peek2->TokenType == tok_colon) ||
1753+
tok == tok_kw_goto ||
1754+
tok == tok_kw_break ||
1755+
tok == tok_kw_continue ||
1756+
tok == tok_kw_case ||
1757+
tok == tok_kw_default ||
1758+
tok == tok_kw_return ||
1759+
tok == tok_kw__yield);
1760+
}
1761+
1762+
17401763
metac_decl_t* MetaCParser_ParseDecl(metac_parser_t* self, metac_decl_t* parent)
17411764
{
17421765
metac_storageclasses_t stc = storageclass_none;
@@ -1750,7 +1773,7 @@ metac_decl_t* MetaCParser_ParseDecl(metac_parser_t* self, metac_decl_t* parent)
17501773

17511774
decl_type_t* type = 0;
17521775

1753-
#ifndef NO_PREPROCESSOR
1776+
#if !defined(NO_PREPROCESSOR) && 0
17541777
decl_preproc_t* preProcDecl = AllocNewDecl(decl_preproc, &result);
17551778
preProcDecl->DirectiveKind = pp_invalid;
17561779

@@ -1884,11 +1907,11 @@ metac_decl_t* MetaCParser_ParseDecl(metac_parser_t* self, metac_decl_t* parent)
18841907
// typedefs are exactly like variables
18851908
decl_variable_t* var;
18861909
MetaCParser_Match(self, tok_kw_typedef);
1887-
var = (decl_variable_t*)MetaCParser_ParseDecl(self, (metac_decl_t*) typdef);
1910+
var = cast(decl_variable_t*) MetaCParser_ParseDecl(self, (metac_decl_t*) typdef);
18881911

18891912
MetaCParser_Match(self, tok_semicolon);
18901913

1891-
typdef->Type = var->VarType;
1914+
typdef->Type = var->VarType;
18921915
typdef->Identifier = var->VarIdentifier;
18931916
assert(typdef->Type->Hash != 0);
18941917
hash = CRC32C_VALUE(hash, typdef->Type->Hash);

parser/metac_parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ bool IsExprNode(metac_node_kind_t Kind);
113113
bool IsBinaryAssignExp(metac_expr_kind_t expr_kind);
114114
bool IsBinaryExp(metac_expr_kind_t expr_kind);
115115
static bool IsUnaryExp(metac_expr_kind_t expr_kind);
116+
bool NextIsStmt(metac_parser_t* self, int32_t offset);
116117

117118
void MetaCParser_Init(metac_parser_t* self, metac_alloc_t* allocator);
118119
void MetaCParser_InitFromLexer(metac_parser_t* self, metac_lexer_t* lexer, metac_alloc_t* allocator);

parser/metac_parsetree.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ int MetaCNode_TreeWalk_Real(metac_node_t node, walker_function_t walker_fn, void
3838
// decl_type_tuple doesn't really exist
3939
assert(0);
4040

41-
case node_decl_preproc:
42-
{
43-
//TODO do something here.
44-
} break;
45-
4641
case node_decl_variable:
4742
{
4843
decl_variable_t* decl_variable = cast(decl_variable_t*) node;

parser/metac_parsetree.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ typedef struct metac_expr_t
8686
struct {
8787
struct metac_expr_t* E1;
8888
};
89+
// case expr_eject:
90+
struct {
91+
struct metac_stmt_t* EjectedStmt;
92+
};
8993
// case expr_sizeof:
9094
struct {
9195
struct metac_expr_t* SizeofExp;

repl/repl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,13 @@ static inline int Presemantic(metac_node_t node, void* ctx)
233233

234234
return 1;
235235
}
236+
/*
236237
else if (node->Kind == node_decl_preproc)
237238
{
238239
// ignore preproc decls in presemantic
239240
return 1;
240241
}
242+
*/
241243
else if (MetaCNode_IsDecl(node))
242244
{
243245
MetaCSemantic_doDeclSemantic(context->Sema, node);

semantic/metac_semantic.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -876,15 +876,18 @@ sema_decl_function_t* MetaCSemantic_doFunctionSemantic(metac_sema_state_t* self,
876876
// as we have an easier time if we know at which
877877
// param we are and how many follow
878878
decl_variable_t* paramVar = currentParam->Parameter;
879-
/*TODO use identifier in sema table
880-
metac_identifier_ptr_t semaId =
881-
MetaCIdentifierTable_CopyIdentifier(self->ParserIdentifierTable,
882-
&self->SemanticIdentifierTable,
883-
paramVar->VarIdentifier);
884-
f->Parameters[i].VarIdentifier = semaId;
885-
*/
879+
#if 0
880+
// TODO use identifier in sema table
881+
{
882+
metac_identifier_ptr_t semaId =
883+
MetaCIdentifierTable_CopyIdentifier(self->ParserIdentifierTable,
884+
&self->SemanticIdentifierTable,
885+
paramVar->VarIdentifier);
886+
f->Parameters[i].VarIdentifier = semaId;
887+
}
888+
#else
886889
f->Parameters[i].VarIdentifier = paramVar->VarIdentifier;
887-
890+
#endif
888891
f->Parameters[i].VarFlags |= variable_is_parameter;
889892
if (METAC_NODE(paramVar->VarInitExpr) != emptyNode)
890893
{
@@ -915,6 +918,13 @@ sema_decl_function_t* MetaCSemantic_doFunctionSemantic(metac_sema_state_t* self,
915918
#endif
916919
}
917920
}
921+
metac_type_index_t paramTypeIdx = f->Parameters[i].TypeIndex;
922+
if (paramTypeIdx.Kind == type_index_basic
923+
&& paramTypeIdx.Index == type_auto)
924+
{
925+
fprintf(stderr,
926+
"Detected auto type in func params which implies template\n");
927+
}
918928
uint32_t hash = f->Parameters[i].TypeIndex.v;
919929
hash = CRC32C_VALUE(hash, i);
920930
f->Parameters[i].Hash = hash;

0 commit comments

Comments
 (0)