Skip to content

Commit bcdc6ac

Browse files
committed
checkpoint on eval2 parse
1 parent eb87cb0 commit bcdc6ac

9 files changed

Lines changed: 688 additions & 88 deletions

File tree

src/eval2/eval2.c

Lines changed: 397 additions & 0 deletions
Large diffs are not rendered by default.

src/eval2/eval2.h

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44
#ifndef EVAL2_H
55
#define EVAL2_H
66

7+
////////////////////////////////
8+
//~ rjf: Operator Info Tables
9+
10+
typedef enum E2_OpParseKind
11+
{
12+
E2_OpParseKind_Null,
13+
E2_OpParseKind_UnaryPrefix,
14+
E2_OpParseKind_Binary,
15+
}
16+
E2_OpParseKind;
17+
18+
typedef struct E2_OpInfo E2_OpInfo;
19+
struct E2_OpInfo
20+
{
21+
E2_OpParseKind parse_kind;
22+
S64 precedence;
23+
String8 pre;
24+
String8 sep;
25+
String8 post;
26+
String8 chain;
27+
};
28+
729
////////////////////////////////
830
//~ rjf: Generated Code
931

@@ -242,6 +264,31 @@ struct E2_Ctx
242264
U64 tls_base_addr;
243265
};
244266

267+
////////////////////////////////
268+
//~ rjf: Tokens
269+
270+
typedef enum E2_TokenKind
271+
{
272+
E2_TokenKind_Null,
273+
E2_TokenKind_Whitespace,
274+
E2_TokenKind_Comment,
275+
E2_TokenKind_Identifier,
276+
E2_TokenKind_Numeric,
277+
E2_TokenKind_Symbol,
278+
E2_TokenKind_CharLiteral,
279+
E2_TokenKind_StringLiteral,
280+
E2_TokenKind_COUNT
281+
}
282+
E2_TokenKind;
283+
284+
typedef struct E2_Token E2_Token;
285+
struct E2_Token
286+
{
287+
E2_TokenKind kind;
288+
U32 unused;
289+
Rng1U64 range;
290+
};
291+
245292
////////////////////////////////
246293
//~ rjf: Expression Tree Building
247294

@@ -273,10 +320,38 @@ struct E2_ExprMap
273320
U64 slots_count;
274321
};
275322

323+
typedef struct E2_ParseTask E2_ParseTask;
324+
struct E2_ParseTask
325+
{
326+
E2_ParseTask *next;
327+
E2_Expr *parent;
328+
U64 child_count;
329+
U64 child_count_target;
330+
String8 expected_closer;
331+
};
332+
276333
typedef struct E2_ParseState E2_ParseState;
277334
struct E2_ParseState
278335
{
279336
U64 string_off;
337+
E2_ParseTask *top_task;
338+
E2_ParseTask *free_task;
339+
};
340+
341+
typedef struct E2_Msg E2_Msg;
342+
struct E2_Msg
343+
{
344+
E2_Msg *next;
345+
U64 src_off;
346+
String8 string;
347+
};
348+
349+
typedef struct E2_MsgList E2_MsgList;
350+
struct E2_MsgList
351+
{
352+
E2_Msg *first;
353+
E2_Msg *last;
354+
U64 count;
280355
};
281356

282357
typedef struct E2_Parse E2_Parse;
@@ -287,8 +362,10 @@ struct E2_Parse
287362
Rng1U64 missed_read_space_addr_range;
288363
E2_CtxID ctx_id;
289364
E2_CtxFlags missing_ctx_flags;
365+
String8 missed_identifier;
290366
E2_Expr *expr;
291367
E2_Expr *access_expr;
368+
E2_MsgList msgs;
292369
};
293370

294371
////////////////////////////////
@@ -353,9 +430,23 @@ internal U64 e2_space_map_read(E2_SpaceMap *map, E2_SpaceID space_id, Rng1U64 ad
353430
internal void e2_expr_map_push(Arena *arena, E2_ExprMap *map, String8 name, E2_Expr *expr);
354431
internal E2_Expr *e2_expr_from_name(E2_ExprMap *map, String8 name);
355432

433+
////////////////////////////////
434+
//~ rjf: Messages
435+
436+
internal E2_Msg *e2_msg(Arena *arena, E2_MsgList *msgs, U64 src_off, String8 string);
437+
internal E2_Msg *e2_msgf(Arena *arena, E2_MsgList *msgs, U64 src_off, char *fmt, ...);
438+
439+
////////////////////////////////
440+
//~ rjf: Types
441+
442+
internal E2_TypeKey e2_type_key_basic(E2_TypeKind kind);
443+
356444
////////////////////////////////
357445
//~ rjf: String -> Expression
358446

447+
internal E2_Token e2_token_from_string(String8 string);
448+
internal U64 e2_read_token(String8 string, U64 off, E2_Token *token_out);
449+
internal B32 e2_try_token(String8 string, E2_TokenKind kind, String8 expected_string, U64 *off_out, E2_Token *token_out);
359450
internal E2_Parse e2_parse_from_string(Arena *arena, E2_ParseState *state, E2_SpaceMap *space_map, E2_ExprMap *expr_map, String8 string);
360451

361452
////////////////////////////////

src/eval2/eval2.mdesk

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,49 @@
11
// Copyright (c) Epic Games Tools
22
// Licensed under the MIT license (https://opensource.org/license/mit/)
33

4+
@table(name parse_kind precedence pre sep pos chain)
5+
E2_OpTable:
6+
{
7+
{Deref UnaryPrefix 2 "*" "" "" ""}
8+
{Address UnaryPrefix 2 "&" "" "" ""}
9+
{Pos UnaryPrefix 2 "+" "" "" ""}
10+
{Neg UnaryPrefix 2 "-" "" "" ""}
11+
{LogNot UnaryPrefix 2 "!" "" "" ""}
12+
{BitNot UnaryPrefix 2 "~" "" "" ""}
13+
{Mul Binary 3 "" "*" "" ""}
14+
{Div Binary 3 "" "/" "" ""}
15+
{Mod Binary 3 "" "%" "" ""}
16+
{Add Binary 4 "" "+" "" ""}
17+
{Sub Binary 4 "" "-" "" ""}
18+
{LShift Binary 5 "" "<<" "" ""}
19+
{RShift Binary 5 "" ">>" "" ""}
20+
{Less Binary 6 "" "<" "" ""}
21+
{LtEq Binary 6 "" "<=" "" ""}
22+
{Grtr Binary 6 "" ">" "" ""}
23+
{GrEq Binary 6 "" ">=" "" ""}
24+
{EqEq Binary 7 "" "==" "" ""}
25+
{NtEq Binary 7 "" "!=" "" ""}
26+
{BitAnd Binary 8 "" "&" "" ""}
27+
{BitXor Binary 9 "" "^" "" ""}
28+
{BitOr Binary 10 "" "|" "" ""}
29+
{LogAnd Binary 11 "" "&&" "" ""}
30+
{LogOr Binary 12 "" "||" "" ""}
31+
{Define Binary 13 "" "=" "" ""}
32+
}
33+
34+
@enum E2_OpKind:
35+
{
36+
Null,
37+
@expand(E2_OpTable a) `$(a.name)`,
38+
COUNT,
39+
}
40+
41+
@data(E2_OpInfo) e2_op_kind_info_table:
42+
{
43+
`{0}`,
44+
@expand(E2_OpTable a) `{E2_OpParseKind_$(a.parse_kind), $(a.precedence), str8_lit_comp("$(a.pre)"), str8_lit_comp("$(a.sep)"), str8_lit_comp("$(a.pos)"), str8_lit_comp("$(a.chain)")}`
45+
}
46+
447
@table(name basic_string basic_byte_size)
548
// NOTE(rjf): basic_byte_size == 0xFF? => address sized
649
E2_TypeKindTable:

src/eval2/generated/eval2.meta.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,36 @@
33

44
//- GENERATED CODE
55

6+
C_LINKAGE_BEGIN
7+
E2_OpInfo e2_op_kind_info_table[26] =
8+
{
9+
{0},
10+
{E2_OpParseKind_UnaryPrefix, 2, str8_lit_comp("*"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
11+
{E2_OpParseKind_UnaryPrefix, 2, str8_lit_comp("&"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
12+
{E2_OpParseKind_UnaryPrefix, 2, str8_lit_comp("+"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
13+
{E2_OpParseKind_UnaryPrefix, 2, str8_lit_comp("-"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
14+
{E2_OpParseKind_UnaryPrefix, 2, str8_lit_comp("!"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
15+
{E2_OpParseKind_UnaryPrefix, 2, str8_lit_comp("~"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("")},
16+
{E2_OpParseKind_Binary, 3, str8_lit_comp(""), str8_lit_comp("*"), str8_lit_comp(""), str8_lit_comp("")},
17+
{E2_OpParseKind_Binary, 3, str8_lit_comp(""), str8_lit_comp("/"), str8_lit_comp(""), str8_lit_comp("")},
18+
{E2_OpParseKind_Binary, 3, str8_lit_comp(""), str8_lit_comp("%"), str8_lit_comp(""), str8_lit_comp("")},
19+
{E2_OpParseKind_Binary, 4, str8_lit_comp(""), str8_lit_comp("+"), str8_lit_comp(""), str8_lit_comp("")},
20+
{E2_OpParseKind_Binary, 4, str8_lit_comp(""), str8_lit_comp("-"), str8_lit_comp(""), str8_lit_comp("")},
21+
{E2_OpParseKind_Binary, 5, str8_lit_comp(""), str8_lit_comp("<<"), str8_lit_comp(""), str8_lit_comp("")},
22+
{E2_OpParseKind_Binary, 5, str8_lit_comp(""), str8_lit_comp(">>"), str8_lit_comp(""), str8_lit_comp("")},
23+
{E2_OpParseKind_Binary, 6, str8_lit_comp(""), str8_lit_comp("<"), str8_lit_comp(""), str8_lit_comp("")},
24+
{E2_OpParseKind_Binary, 6, str8_lit_comp(""), str8_lit_comp("<="), str8_lit_comp(""), str8_lit_comp("")},
25+
{E2_OpParseKind_Binary, 6, str8_lit_comp(""), str8_lit_comp(">"), str8_lit_comp(""), str8_lit_comp("")},
26+
{E2_OpParseKind_Binary, 6, str8_lit_comp(""), str8_lit_comp(">="), str8_lit_comp(""), str8_lit_comp("")},
27+
{E2_OpParseKind_Binary, 7, str8_lit_comp(""), str8_lit_comp("=="), str8_lit_comp(""), str8_lit_comp("")},
28+
{E2_OpParseKind_Binary, 7, str8_lit_comp(""), str8_lit_comp("!="), str8_lit_comp(""), str8_lit_comp("")},
29+
{E2_OpParseKind_Binary, 8, str8_lit_comp(""), str8_lit_comp("&"), str8_lit_comp(""), str8_lit_comp("")},
30+
{E2_OpParseKind_Binary, 9, str8_lit_comp(""), str8_lit_comp("^"), str8_lit_comp(""), str8_lit_comp("")},
31+
{E2_OpParseKind_Binary, 10, str8_lit_comp(""), str8_lit_comp("|"), str8_lit_comp(""), str8_lit_comp("")},
32+
{E2_OpParseKind_Binary, 11, str8_lit_comp(""), str8_lit_comp("&&"), str8_lit_comp(""), str8_lit_comp("")},
33+
{E2_OpParseKind_Binary, 12, str8_lit_comp(""), str8_lit_comp("||"), str8_lit_comp(""), str8_lit_comp("")},
34+
{E2_OpParseKind_Binary, 13, str8_lit_comp(""), str8_lit_comp("="), str8_lit_comp(""), str8_lit_comp("")},
35+
};
36+
37+
C_LINKAGE_END
38+

src/eval2/generated/eval2.meta.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,37 @@
66
#ifndef EVAL2_META_H
77
#define EVAL2_META_H
88

9+
typedef enum E2_OpKind
10+
{
11+
E2_OpKind_Null,
12+
E2_OpKind_Deref,
13+
E2_OpKind_Address,
14+
E2_OpKind_Pos,
15+
E2_OpKind_Neg,
16+
E2_OpKind_LogNot,
17+
E2_OpKind_BitNot,
18+
E2_OpKind_Mul,
19+
E2_OpKind_Div,
20+
E2_OpKind_Mod,
21+
E2_OpKind_Add,
22+
E2_OpKind_Sub,
23+
E2_OpKind_LShift,
24+
E2_OpKind_RShift,
25+
E2_OpKind_Less,
26+
E2_OpKind_LtEq,
27+
E2_OpKind_Grtr,
28+
E2_OpKind_GrEq,
29+
E2_OpKind_EqEq,
30+
E2_OpKind_NtEq,
31+
E2_OpKind_BitAnd,
32+
E2_OpKind_BitXor,
33+
E2_OpKind_BitOr,
34+
E2_OpKind_LogAnd,
35+
E2_OpKind_LogOr,
36+
E2_OpKind_Define,
37+
E2_OpKind_COUNT,
38+
} E2_OpKind;
39+
940
typedef enum E2_TypeKind
1041
{
1142
E2_TypeKind_Null,
@@ -84,4 +115,9 @@ E2_TypeKind_FirstMeta = E2_TypeKind_MetaExpr,
84115
E2_TypeKind_LastMeta = E2_TypeKind_MetaDescription,
85116
} E2_TypeKind;
86117

118+
C_LINKAGE_BEGIN
119+
extern E2_OpInfo e2_op_kind_info_table[26];
120+
121+
C_LINKAGE_END
122+
87123
#endif // EVAL2_META_H

src/lib_rdi/rdi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ RDI_EVAL_CTRLBITS(2, 1, 0),
6666
RDI_EVAL_CTRLBITS(2, 0, 0),
6767
RDI_EVAL_CTRLBITS(1, 1, 1),
6868
RDI_EVAL_CTRLBITS(4, 0, 1),
69-
RDI_EVAL_CTRLBITS(0, 0, 1),
7069
RDI_EVAL_CTRLBITS(8, 0, 1),
7170
RDI_EVAL_CTRLBITS(4, 0, 1),
7271
RDI_EVAL_CTRLBITS(4, 0, 1),
@@ -77,6 +76,8 @@ RDI_EVAL_CTRLBITS(2, 0, 1),
7776
RDI_EVAL_CTRLBITS(4, 0, 1),
7877
RDI_EVAL_CTRLBITS(8, 0, 1),
7978
RDI_EVAL_CTRLBITS(16, 0, 1),
79+
RDI_EVAL_CTRLBITS(32, 0, 1),
80+
RDI_EVAL_CTRLBITS(64, 0, 1),
8081
RDI_EVAL_CTRLBITS(1, 0, 1),
8182
RDI_EVAL_CTRLBITS(1, 1, 1),
8283
RDI_EVAL_CTRLBITS(1, 1, 1),
@@ -105,7 +106,6 @@ RDI_EVAL_CTRLBITS(1, 1, 1),
105106
RDI_EVAL_CTRLBITS(2, 1, 1),
106107
RDI_EVAL_CTRLBITS(1, 0, 1),
107108
RDI_EVAL_CTRLBITS(0, 1, 0),
108-
RDI_EVAL_CTRLBITS(0, 0, 1),
109109
RDI_EVAL_CTRLBITS(1, 2, 1),
110110
RDI_EVAL_CTRLBITS(1, 1, 1),
111111
RDI_EVAL_CTRLBITS(4, 0, 0),

0 commit comments

Comments
 (0)