Skip to content

Commit 441a069

Browse files
committed
Various Fixes
1 parent 0912982 commit 441a069

File tree

14 files changed

+157
-73
lines changed

14 files changed

+157
-73
lines changed

libinterpret/bc_lightning_backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define AllocMemory(SIZE, FN) \
33
self->allocMemory(self->allocCtx, SIZE, FN)
44

5-
#include "3rd_party/lightning/include/lightning.h"
5+
#include "lightning.h"
66
#include "../os/compat.h"
77
#include "backend_interface_funcs.h"
88
#include "bc_common.h"

make_boilerplate/make_boilerplate.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void WriteSwitchCaseEntryFor(decl_type_struct_t* decl_type_struct,
8585
if (IsNode(fieldVar->VarType, table))
8686
{
8787
outputSize += sprintf(outputString + outputSize,
88-
"%s if (%s->%s != emptyNode)\n",
88+
"%s if (METAC_NODE(%s->%s) != emptyNode)\n",
8989
indent8, scratchpad, fieldName);
9090

9191
outputSize += sprintf(outputString + outputSize,
@@ -133,7 +133,7 @@ int MakeBoilerCb(metac_node_t node, void* ctxP)
133133
structName : "anonymous")
134134
);
135135

136-
if (decl_struct->Identifier.v == 0)
136+
if (decl_struct->Identifier.v == -1)
137137
return 1;
138138

139139
if(!memcmp(structName, "stmt", 4))
@@ -190,8 +190,8 @@ int main(int argc, const char** argv)
190190
make_boiler_ctx_t makeBoilerCtx = {
191191
&LPP.Parser.IdentifierTable,
192192

193-
(char*) malloc(16384),0, 16384,
194-
(char*) malloc(16384),0, 16384
193+
(char*) malloc(16384*2),0, 16384*2,
194+
(char*) malloc(16384*2),0, 16384*2
195195
};
196196

197197
for(uint32_t i = 0; i < result.Length; i++)

make_header/make_header.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int main(int argc, const char* argv[])
4141
MetaCPrinter_PrintForHeader(&lpp.Parser.DebugPrinter, decl);
4242
printf("%.*s\n", (int) lpp.Parser.DebugPrinter.StringMemoryCount, lpp.Parser.DebugPrinter.StringMemory);
4343
memset(lpp.Parser.DebugPrinter.StringMemory, ' ', lpp.Parser.DebugPrinter.StringMemoryCount);
44-
lpp.Parser.DebugPrinter.StringMemorySize = 0;
44+
lpp.Parser.DebugPrinter.StringMemoryCount = 0;
4545
}
4646

4747
// printf("%.*s\n", (int) lpp.Parser.DebugPrinter.StringMemorySize, lpp.Parser.DebugPrinter.StringMemory);

os/compat.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
printf(__VA_ARGS__); \
99
RESTORE_STACK();
1010

11+
#define xfprintf(...) \
12+
ALIGN_STACK() \
13+
fprintf(__VA_ARGS__); \
14+
RESTORE_STACK();
15+
1116
#define cast(T) (T)
1217

1318
#ifndef ARRAY_SIZE

package_serializer/build.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ fi
1212
#echo $CC package_serializer.c -DACCEL=$ACCEL -DWRITE_TABLE ../os/metac_task.c \
1313
# -g2 -O0 -march=native -mtune=native -o package_serializer $@
1414

15-
#$CC package_serializer.c \
16-
# -DACCEL=$ACCEL -DWRITE_TABLE ../os/metac_task.c \
17-
# -g2 -O0 -march=native -mtune=native -o package_serializer -lpthread $@
15+
$CC package_serializer.c \
16+
-DACCEL=$ACCEL -DWRITE_TABLE ../os/metac_task.c \
17+
-g2 -O0 -march=native -mtune=native -o package_serializer -lpthread $@
1818

1919
# ../3rd_party/deboost.context/fcontext_aarch64.o \
2020
# -I../3rd_party/deboost.context/include/fcontext \
2121
# ../3rd_party/deboost.context/source/stack.c \
2222

23-
g++ package_serializer.c -DACCEL=$ACCEL -DWRITE_TABLE ../os/metac_task.c \
24-
~/dev/tracy/TracyClientNoExit.o -I.. -DENABLE_TRACY=1 -DTRACY_ENABLE=1 \
25-
-g2 -O0 -march=native -mtune=native -lpthread -lm -ldl -o package_serializer $@
23+
#g++ package_serializer.c -DACCEL=$ACCEL -DWRITE_TABLE ../os/metac_task.c \
24+
# ~/dev/tracy/TracyClientNoExit.o -I.. -DENABLE_TRACY=1 -DTRACY_ENABLE=1 \
25+
# -g2 -O0 -march=native -mtune=native -lpthread -lm -ldl -o package_serializer $@

parser/metac_expr_parser.c

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -364,22 +364,26 @@ static inline uint32_t OpToPrecedence(metac_expr_kind_t exp)
364364
|| exp == expr_compl
365365
|| exp == expr_assert
366366
|| exp == expr_template_instance
367-
|| exp == expr_inject)
367+
|| exp == expr_inject
368+
|| exp == expr_eject)
368369
{
369370
return 30;
370371
}
371-
else if (exp == expr_arrow || exp == expr_dot)
372+
else if (exp == expr_unary_dot)
372373
{
373374
return 31;
374375
}
376+
else if (exp == expr_arrow || exp == expr_dot)
377+
{
378+
return 32;
379+
}
375380
else if (exp == expr_umin
376-
|| exp == expr_unary_dot
377381
|| exp == expr_sizeof
378382
|| exp == expr_typeof
379383
|| exp == expr_not
380384
|| exp == expr_outer)
381385
{
382-
return 32;
386+
return 33;
383387
}
384388
else if (exp == expr_paren
385389
|| exp == expr_signed_integer
@@ -390,7 +394,11 @@ static inline uint32_t OpToPrecedence(metac_expr_kind_t exp)
390394
|| exp == expr_tuple
391395
|| exp == expr_type)
392396
{
393-
return 33;
397+
return 34;
398+
}
399+
else if (exp == expr_comma)
400+
{
401+
return 36;
394402
}
395403

396404
fprintf(stderr, "There's no precedence for %s\n", MetaCExprKind_toChars(exp));
@@ -998,7 +1006,11 @@ static inline metac_expr_t* ParseUnaryDotExpr(metac_parser_t* self)
9981006
if (!result)
9991007
{
10001008
result = AllocNewExpr(expr_unary_dot);
1009+
#ifdef OLD_PARSER
1010+
result->E1 = MetaCParser_ParseExpr(self, expr_flags_unary, result);
1011+
#else
10011012
result->E1 = MetaCParser_ParseExpr2(self, expr_flags_unary);
1013+
#endif
10021014
result->Hash = CRC32C_VALUE(
10031015
crc32c_nozero(~0, ".", sizeof(".") - 1),
10041016
result->E1->Hash
@@ -1330,18 +1342,22 @@ expr_argument_t* MetaCParser_ParseArgumentList(metac_parser_t* self, parse_expr_
13301342
MetaCParser_Match(self, tok_rParen);
13311343
return arguments;
13321344
}
1333-
1345+
#ifndef OLD_PARSER
13341346
MetaCParser_PushExprStackBottom(self, self->ExprParser.ExprStackCount);
13351347
MetaCParser_PushOpStackBottom(self, self->ExprParser.OpStackCount);
13361348
MetaCParser_PushOpenParens(self);
13371349
MetaCParser_PushFlags(self, flags);
1338-
1350+
#endif
13391351
for (;;)
13401352
{
13411353
nArguments++;
13421354
assert((*nextArgument) == _emptyPointer);
13431355
(*nextArgument) = (expr_argument_t*)AllocNewExpr(expr_argument);
1356+
#ifndef OLD_PARSER
13441357
metac_expr_t* exp = MetaCParser_ParseExpr2(self, expr_flags_call);
1358+
#else
1359+
metac_expr_t* exp = MetaCParser_ParseExpr(self, expr_flags_call, 0);
1360+
#endif
13451361
((*nextArgument)->Expr) = exp;
13461362
assert(exp->Hash);
13471363
hash = CRC32C_VALUE(hash, exp->Hash);
@@ -1358,24 +1374,25 @@ expr_argument_t* MetaCParser_ParseArgumentList(metac_parser_t* self, parse_expr_
13581374
break;
13591375
}
13601376
}
1361-
1377+
#ifndef OLD_PARSER
13621378
MetaCParser_PopExprStackBottom(self);
13631379
MetaCParser_PopOpStackBottom(self);
13641380
MetaCParser_PopOpenParens(self);
13651381
MetaCParser_PopFlags(self);
1366-
1382+
#endif
13671383
if (arguments != emptyPointer)
13681384
{
13691385
arguments->Hash = hash;
13701386

1371-
metac_token_t* rParen = MetaCParser_PeekToken(self, 0);
1387+
metac_token_t* rParen = MetaCParser_Match(self, tok_rParen);
13721388
MetaCLocation_Expand(&loc, LocationFromToken(self, rParen));
13731389
arguments->LocationIdx =
13741390
MetaCLocationStorage_Store(&self->LocationStorage, loc);
13751391
}
13761392

13771393
return arguments;
13781394
}
1395+
13791396
#ifdef OLD_PARSER
13801397
metac_expr_t* MetaCParser_ParseBinaryExpr(metac_parser_t* self,
13811398
parse_expr_flags_t eflags,
@@ -2108,7 +2125,12 @@ metac_expr_t* MetaCParser_ParseExpr(metac_parser_t* self,
21082125
}
21092126
else
21102127
{
2111-
result = MetaCParser_ParseBinaryExpr(self, eflags, prev, 0);
2128+
int32_t initialPrec = 0;
2129+
if (prev->Kind == expr_unary_dot)
2130+
{
2131+
initialPrec = OpToPrecedence(prev->Kind);
2132+
}
2133+
result = MetaCParser_ParseBinaryExpr(self, eflags, prev, initialPrec);
21122134
}
21132135

21142136
#if !defined(NO_PREPROCESSOR)

parser/metac_parser.c

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef _METAC_PARSER_C_
22
#define _METAC_PARSER_C_
33

4-
#define TYPE_EXP
4+
//#define TYPE_EXP
55
#include "metac_identifier_table.c"
66

77
#include "../os/os.c"
@@ -665,7 +665,7 @@ metac_token_t* MetaCParser_PeekToken_(metac_parser_t* self, int32_t p, uint32_t
665665
{
666666
Debug_Logf(g_DebugServer, "Parser","%s = MetaCParser_PeekToken(offset=%d, line=%d)", MetaCTokenEnum_toChars(result->TokenType), p, line);
667667
}
668-
668+
669669
return result;
670670
}
671671

@@ -988,7 +988,11 @@ decl_type_t* MetaCParser_ParseTypeDecl(metac_parser_t* self, metac_decl_t* paren
988988
decl_type_array_t* typeArray = AllocNewDecl(decl_type_array, &result);
989989
if(!MetaCParser_PeekMatch(self, tok_rBracket, 1))
990990
{
991+
#ifdef OLD_PARSER
992+
typeArray->Dim = MetaCParser_ParseExpr(self, expr_flags_none, 0);
993+
#else
991994
typeArray->Dim = MetaCParser_ParseExpr2(self, expr_flags_none);
995+
#endif
992996
MetaCParser_Match(self, tok_rBracket);
993997
}
994998
else
@@ -1249,7 +1253,11 @@ decl_type_t* MetaCParser_ParseTypeDecl(metac_parser_t* self, metac_decl_t* paren
12491253
else
12501254
{
12511255
MetaCParser_Match(self, tok_assign);
1256+
#ifdef OLD_PARSER
1257+
member->Value = MetaCParser_ParseExpr(self, expr_flags_enum, 0);
1258+
#else
12521259
member->Value = MetaCParser_ParseExpr2(self, expr_flags_enum);
1260+
#endif
12531261
assert(member->Value->Hash != 0);
12541262
hash = CRC32C_VALUE(hash, member->Value->Hash);
12551263
}
@@ -1943,7 +1951,11 @@ metac_decl_t* MetaCParser_ParseDecl(metac_parser_t* self, metac_decl_t* parent)
19431951
if (MetaCParser_PeekMatch(self, tok_assign, 1))
19441952
{
19451953
MetaCParser_Match(self, tok_assign);
1954+
#ifdef OLD_PARSER
1955+
varDecl->VarInitExpr = MetaCParser_ParseExpr(self, expr_flags_none, 0);
1956+
#else
19461957
varDecl->VarInitExpr = MetaCParser_ParseExpr2(self, expr_flags_none);
1958+
#endif
19471959
}
19481960
}
19491961
}
@@ -2059,7 +2071,11 @@ metac_stmt_t* MetaCParser_ParseStmt(metac_parser_t* self,
20592071
}
20602072
MetaCParser_Match(self, tok_lParen);
20612073
if_stmt->IfCond =
2074+
#ifdef OLD_PARSER
2075+
MetaCParser_ParseExpr(self, expr_flags_none, 0);
2076+
#else
20622077
MetaCParser_ParseExpr2(self, expr_flags_none);
2078+
#endif
20632079
hash = CRC32C_VALUE(hash, if_stmt->IfCond->Hash);
20642080
MetaCParser_Match(self, tok_rParen);
20652081
if_stmt->IfBody = MetaCParser_ParseStmt(self, (metac_stmt_t*)result, 0);
@@ -2081,15 +2097,16 @@ metac_stmt_t* MetaCParser_ParseStmt(metac_parser_t* self,
20812097
else if (tokenType == tok_at)
20822098
{
20832099
peek2 = MetaCParser_PeekToken(self, 2);
2084-
if (peek2->TokenType == tok_identifier && peek2->IdentifierKey == 0x3809a6)
2100+
if (peek2->TokenType == tok_identifier && peek2->IdentifierKey == run_key)
20852101
{
20862102
stmt_run_t* run_stmt = AllocNewStmt(stmt_run, &result);
20872103
MetaCParser_Match(self, tok_at);
20882104
MetaCParser_Match(self, tok_identifier);
20892105
run_stmt->RunBody =
20902106
MetaCParser_ParseStmt(self, cast(metac_stmt_t*)run_stmt, 0);
2091-
hash = 0x3809a6;
2107+
hash = run_key;
20922108
hash = CRC32C_VALUE(hash, run_stmt->Hash);
2109+
result->Hash = hash;
20932110
}
20942111
}
20952112
else if (tokenType == tok_kw_while)
@@ -2098,7 +2115,11 @@ metac_stmt_t* MetaCParser_ParseStmt(metac_parser_t* self,
20982115
MetaCParser_Match(self, tok_kw_while);
20992116
MetaCParser_Match(self, tok_lParen);
21002117
while_stmt->WhileExp =
2118+
#ifdef OLD_PARSER
2119+
MetaCParser_ParseExpr(self, expr_flags_none, 0);
2120+
#else
21012121
MetaCParser_ParseExpr2(self, expr_flags_none);
2122+
#endif
21022123
hash = CRC32C_VALUE(hash, while_stmt->WhileExp->Hash);
21032124
MetaCParser_Match(self, tok_rParen);
21042125
while_stmt->WhileBody =
@@ -2126,7 +2147,11 @@ metac_stmt_t* MetaCParser_ParseStmt(metac_parser_t* self,
21262147
}
21272148
else
21282149
{
2150+
#ifdef OLD_PARSER
2151+
for_->ForInit = (metac_node_t)MetaCParser_ParseExpr(self, expr_flags_none, 0);
2152+
#else
21292153
for_->ForInit = (metac_node_t)MetaCParser_ParseExpr2(self, expr_flags_none);
2154+
#endif
21302155
MetaCParser_Match(self, tok_semicolon);
21312156
}
21322157

@@ -2139,7 +2164,11 @@ metac_stmt_t* MetaCParser_ParseStmt(metac_parser_t* self,
21392164
}
21402165
if (!MetaCParser_PeekMatch(self, tok_semicolon, 1))
21412166
{
2167+
#ifdef OLD_PARSER
2168+
for_->ForCond = MetaCParser_ParseExpr(self, expr_flags_none, 0);
2169+
#else
21422170
for_->ForCond = MetaCParser_ParseExpr2(self, expr_flags_none);
2171+
#endif
21432172
hash = CRC32C_VALUE(hash, for_->ForCond->Hash);
21442173
}
21452174
else
@@ -2150,7 +2179,11 @@ metac_stmt_t* MetaCParser_ParseStmt(metac_parser_t* self,
21502179

21512180
if (!MetaCParser_PeekMatch(self, tok_rParen, 1))
21522181
{
2182+
#ifdef OLD_PARSER
2183+
for_->ForPostLoop = MetaCParser_ParseExpr(self, expr_flags_none, 0);
2184+
#else
21532185
for_->ForPostLoop = MetaCParser_ParseExpr2(self, expr_flags_none);
2186+
#endif
21542187
hash = CRC32C_VALUE(hash, for_->ForPostLoop->Hash);
21552188
}
21562189
else
@@ -2169,7 +2202,11 @@ metac_stmt_t* MetaCParser_ParseStmt(metac_parser_t* self,
21692202
MetaCParser_Match(self, tok_kw_switch);
21702203
MetaCParser_Match(self, tok_lParen);
21712204
switch_->SwitchExp =
2205+
#ifdef OLD_PARSER
2206+
MetaCParser_ParseExpr(self, expr_flags_none, 0);
2207+
#else
21722208
MetaCParser_ParseExpr2(self, expr_flags_none);
2209+
#endif
21732210
hash = CRC32C_VALUE(hash, switch_->SwitchExp->Hash);
21742211
MetaCParser_Match(self, tok_rParen);
21752212
if (!MetaCParser_PeekMatch(self, tok_lBrace, 0))
@@ -2355,7 +2392,11 @@ metac_stmt_t* MetaCParser_ParseStmt(metac_parser_t* self,
23552392
if (!result || result == emptyPointer)
23562393
LparseAsExpr:
23572394
{
2395+
#ifdef OLD_PARSER
2396+
metac_expr_t* exp = MetaCParser_ParseExpr(self, expr_flags_none, 0);
2397+
#else
23582398
metac_expr_t* exp = MetaCParser_ParseExpr2(self, expr_flags_none);
2399+
#endif
23592400
stmt_expr_t* expStmt = AllocNewStmt(stmt_expr, &result);
23602401
expStmt->Expr = exp;
23612402
result->Hash = exp->Hash;

parser/metac_parsetree.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ int MetaCNode_TreeWalk_Real(metac_node_t node, walker_function_t walker_fn, void
2828
switch(node->Kind)
2929
{
3030
default: {
31+
if (((node->Kind > node_expr_invalid) & (node->Kind < node_expr_max))) break;
3132
printf("%s should provide a case for node type %s\n", __FUNCTION__, MetaCNodeKind_toChars(node->Kind));
3233
assert(!"nodeKind not expected to be here\n");
3334
} break;

0 commit comments

Comments
 (0)