mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-29 14:51:49 -07:00
convert all eval visualization paths to incrementally building expression trees, rather than using final eval bundles; ensure all evaluation paths, in various circumstances (single line viz, row viz), go through exactly the same path; deduplicate single-row-expr evaluation paths
This commit is contained in:
+46
-45
@@ -73,59 +73,60 @@ E_TypeKindTable:
|
||||
{Variadic "" 0 }
|
||||
}
|
||||
|
||||
@table(name op_string)
|
||||
@table(name op_kind precedence string op_pre op_sep op_pos)
|
||||
E_ExprKindTable:
|
||||
{
|
||||
{ Nil "" }
|
||||
{ Nil Null 0 "" "" "" "" }
|
||||
{ Ref Null 0 "" "" "" "" }
|
||||
|
||||
{ ArrayIndex "[]" }
|
||||
{ MemberAccess "." }
|
||||
{ Deref "*" }
|
||||
{ Address "&" }
|
||||
{ ArrayIndex Null 0 "[]" "" "[" "]"}
|
||||
{ MemberAccess Null 0 "." "" "." "" }
|
||||
{ Deref UnaryPrefix 2 "*" "*" "" "" }
|
||||
{ Address UnaryPrefix 2 "&" "&" "" "" }
|
||||
|
||||
{ Cast "cast" }
|
||||
{ Sizeof "sizeof" }
|
||||
{ Cast Null 0 "cast" "" "" "" }
|
||||
{ Sizeof UnaryPrefix 0 "sizeof" "sizeof" "" "" }
|
||||
|
||||
{ Neg "-" }
|
||||
{ LogNot "!" }
|
||||
{ BitNot "~" }
|
||||
{ Mul "*" }
|
||||
{ Div "/" }
|
||||
{ Mod "%" }
|
||||
{ Add "+" }
|
||||
{ Sub "-" }
|
||||
{ LShift "<<" }
|
||||
{ RShift ">>" }
|
||||
{ Less "<" }
|
||||
{ LsEq "<=" }
|
||||
{ Grtr ">" }
|
||||
{ GrEq ">=" }
|
||||
{ EqEq "==" }
|
||||
{ NtEq "!=" }
|
||||
{ Neg UnaryPrefix 2 "-" "-" "" "" }
|
||||
{ LogNot UnaryPrefix 2 "!" "!" "" "" }
|
||||
{ BitNot UnaryPrefix 2 "~" "~" "" "" }
|
||||
{ Mul Binary 3 "*" "" "*" "" }
|
||||
{ Div Binary 3 "/" "" "/" "" }
|
||||
{ Mod Binary 3 "%" "" "%" "" }
|
||||
{ Add Binary 4 "+" "" "+" "" }
|
||||
{ Sub Binary 4 "-" "" "-" "" }
|
||||
{ LShift Binary 5 "<<" "" "<<" "" }
|
||||
{ RShift Binary 5 ">>" "" ">>" "" }
|
||||
{ Less Binary 6 "<" "" "<" "" }
|
||||
{ LsEq Binary 6 "<=" "" "<=" "" }
|
||||
{ Grtr Binary 6 ">" "" ">" "" }
|
||||
{ GrEq Binary 6 ">=" "" ">=" "" }
|
||||
{ EqEq Binary 7 "==" "" "==" "" }
|
||||
{ NtEq Binary 7 "!=" "" "!=" "" }
|
||||
|
||||
{ BitAnd "&" }
|
||||
{ BitXor "^" }
|
||||
{ BitOr "|" }
|
||||
{ LogAnd "&&" }
|
||||
{ LogOr "||" }
|
||||
{ BitAnd Binary 8 "&" "" "&" "" }
|
||||
{ BitXor Binary 9 "^" "" "^" "" }
|
||||
{ BitOr Binary 10 "|" "" "|" "" }
|
||||
{ LogAnd Binary 11 "&&" "" "&&" "" }
|
||||
{ LogOr Binary 12 "||" "" "||" "" }
|
||||
|
||||
{ Ternary "? " }
|
||||
{ Ternary Null 0 "? " "" "?" ":" }
|
||||
|
||||
{ LeafBytecode "bytecode" }
|
||||
{ LeafMember "member" }
|
||||
{ LeafStringLiteral "string_literal" }
|
||||
{ LeafU64 "U64" }
|
||||
{ LeafF64 "F64" }
|
||||
{ LeafF32 "F32" }
|
||||
{ LeafIdent "leaf_ident" }
|
||||
{ LeafID "leaf_id" }
|
||||
{ LeafBytecode Null 0 "bytecode" "" "" "" }
|
||||
{ LeafMember Null 0 "member" "" "" "" }
|
||||
{ LeafStringLiteral Null 0 "string_literal" "" "" "" }
|
||||
{ LeafU64 Null 0 "U64" "" "" "" }
|
||||
{ LeafF64 Null 0 "F64" "" "" "" }
|
||||
{ LeafF32 Null 0 "F32" "" "" "" }
|
||||
{ LeafIdent Null 0 "leaf_ident" "" "" "" }
|
||||
{ LeafID Null 0 "leaf_id" "" "" "" }
|
||||
|
||||
{ TypeIdent "type_ident" }
|
||||
{ Ptr "ptr" }
|
||||
{ Array "array" }
|
||||
{ Func "function" }
|
||||
{ TypeIdent Null 0 "type_ident" "" "" "" }
|
||||
{ Ptr Null 0 "ptr" "" "" "" }
|
||||
{ Array Null 0 "array" "" "" "" }
|
||||
{ Func Null 0 "function" "" "" "" }
|
||||
|
||||
{ Define "=" }
|
||||
{ Define Binary 13 "=" "" "=" "" }
|
||||
}
|
||||
|
||||
@table(name display_string)
|
||||
@@ -195,9 +196,9 @@ e_expr_kind_strings:
|
||||
@expand(E_InterpretationCodeTable a) `str8_lit_comp("$(a.display_string)")`
|
||||
}
|
||||
|
||||
@data(String8) e_expr_op_strings:
|
||||
@data(E_OpInfo) e_expr_kind_op_info_table:
|
||||
{
|
||||
@expand(E_ExprKindTable a) `str8_lit_comp("$(a.op_string)")`
|
||||
@expand(E_ExprKindTable a) `{ E_OpKind_$(a.op_kind), $(a.precedence), str8_lit_comp("$(a.op_pre)"), str8_lit_comp("$(a.op_sep)"), str8_lit_comp("$(a.op_post)") }`
|
||||
}
|
||||
|
||||
@data(U8) e_kind_basic_byte_size_table:
|
||||
|
||||
+13
-6
@@ -5,11 +5,9 @@
|
||||
//~ rjf: Bundled Evaluation Functions
|
||||
|
||||
internal E_Eval
|
||||
e_eval_from_string(Arena *arena, String8 string)
|
||||
e_eval_from_expr(Arena *arena, E_Expr *expr)
|
||||
{
|
||||
E_TokenArray tokens = e_token_array_from_text(arena, string);
|
||||
E_Parse parse = e_parse_expr_from_text_tokens(arena, string, &tokens);
|
||||
E_IRTreeAndType irtree = e_irtree_and_type_from_expr(arena, parse.expr);
|
||||
E_IRTreeAndType irtree = e_irtree_and_type_from_expr(arena, expr);
|
||||
E_OpList oplist = e_oplist_from_irtree(arena, irtree.root);
|
||||
String8 bytecode = e_bytecode_from_oplist(arena, &oplist);
|
||||
E_Interpretation interp = e_interpret(bytecode);
|
||||
@@ -18,11 +16,10 @@ e_eval_from_string(Arena *arena, String8 string)
|
||||
.value = interp.value,
|
||||
.mode = irtree.mode,
|
||||
.space = irtree.space,
|
||||
.expr = expr,
|
||||
.type_key = irtree.type_key,
|
||||
.code = interp.code,
|
||||
.advance = parse.last_token >= tokens.v + tokens.count ? string.size : parse.last_token->range.min,
|
||||
};
|
||||
e_msg_list_concat_in_place(&eval.msgs, &parse.msgs);
|
||||
e_msg_list_concat_in_place(&eval.msgs, &irtree.msgs);
|
||||
if(E_InterpretationCode_Good < eval.code && eval.code < E_InterpretationCode_COUNT)
|
||||
{
|
||||
@@ -31,6 +28,16 @@ e_eval_from_string(Arena *arena, String8 string)
|
||||
return eval;
|
||||
}
|
||||
|
||||
internal E_Eval
|
||||
e_eval_from_string(Arena *arena, String8 string)
|
||||
{
|
||||
E_TokenArray tokens = e_token_array_from_text(arena, string);
|
||||
E_Parse parse = e_parse_expr_from_text_tokens(arena, string, &tokens);
|
||||
E_Eval eval = e_eval_from_expr(arena, parse.expr);
|
||||
e_msg_list_concat_in_place(&eval.msgs, &parse.msgs);
|
||||
return eval;
|
||||
}
|
||||
|
||||
internal E_Eval
|
||||
e_autoresolved_eval_from_eval(E_Eval eval)
|
||||
{
|
||||
|
||||
@@ -13,15 +13,16 @@ struct E_Eval
|
||||
E_Value value;
|
||||
E_Mode mode;
|
||||
E_Space space;
|
||||
E_Expr *expr;
|
||||
E_TypeKey type_key;
|
||||
E_InterpretationCode code;
|
||||
E_MsgList msgs;
|
||||
U64 advance;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Bundled Evaluation Functions
|
||||
|
||||
internal E_Eval e_eval_from_expr(Arena *arena, E_Expr *expr);
|
||||
internal E_Eval e_eval_from_string(Arena *arena, String8 string);
|
||||
internal E_Eval e_autoresolved_eval_from_eval(E_Eval eval);
|
||||
internal E_Eval e_dynamically_typed_eval_from_eval(E_Eval eval);
|
||||
|
||||
@@ -36,6 +36,27 @@ struct E_MsgList
|
||||
U64 count;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Operator Info
|
||||
|
||||
typedef enum E_OpKind
|
||||
{
|
||||
E_OpKind_Null,
|
||||
E_OpKind_UnaryPrefix,
|
||||
E_OpKind_Binary,
|
||||
}
|
||||
E_OpKind;
|
||||
|
||||
typedef struct E_OpInfo E_OpInfo;
|
||||
struct E_OpInfo
|
||||
{
|
||||
E_OpKind kind;
|
||||
S64 precedence;
|
||||
String8 pre;
|
||||
String8 sep;
|
||||
String8 post;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Evaluation Spaces
|
||||
|
||||
|
||||
+7
-1
@@ -387,6 +387,12 @@ e_irtree_and_type_from_expr(Arena *arena, E_Expr *expr)
|
||||
{
|
||||
default:{}break;
|
||||
|
||||
//- rjf: references -> just descend to sub-expr
|
||||
case E_ExprKind_Ref:
|
||||
{
|
||||
result = e_irtree_and_type_from_expr(arena, expr->ref);
|
||||
}break;
|
||||
|
||||
//- rjf: array indices
|
||||
case E_ExprKind_ArrayIndex:
|
||||
{
|
||||
@@ -1093,7 +1099,7 @@ e_irtree_and_type_from_expr(Arena *arena, E_Expr *expr)
|
||||
//- rjf: leaf bytecode
|
||||
case E_ExprKind_LeafBytecode:
|
||||
{
|
||||
E_IRNode *new_tree = e_irtree_bytecode_no_copy(arena, expr->string);
|
||||
E_IRNode *new_tree = e_irtree_bytecode_no_copy(arena, expr->bytecode);
|
||||
E_TypeKey final_type_key = expr->type_key;
|
||||
result.root = new_tree;
|
||||
result.type_key = final_type_key;
|
||||
|
||||
+143
-50
@@ -17,40 +17,6 @@ global read_only String8 e_multichar_symbol_strings[] =
|
||||
str8_lit_comp("||"),
|
||||
};
|
||||
|
||||
global read_only struct {E_ExprKind kind; String8 string; S64 precedence;} e_unary_prefix_op_table[] =
|
||||
{
|
||||
// { E_ExprKind_???, str8_lit_comp("+"), 2 },
|
||||
{ E_ExprKind_Neg, str8_lit_comp("-"), 2 },
|
||||
{ E_ExprKind_LogNot, str8_lit_comp("!"), 2 },
|
||||
{ E_ExprKind_Deref, str8_lit_comp("*"), 2 },
|
||||
{ E_ExprKind_Address,str8_lit_comp("&"), 2 },
|
||||
{ E_ExprKind_Sizeof, str8_lit_comp("sizeof"), 2 },
|
||||
// { E_ExprKind_Alignof, str8_lit_comp("_Alignof"), 2 },
|
||||
};
|
||||
|
||||
global read_only struct {E_ExprKind kind; String8 string; S64 precedence;} e_binary_op_table[] =
|
||||
{
|
||||
{ E_ExprKind_Mul, str8_lit_comp("*"), 3 },
|
||||
{ E_ExprKind_Div, str8_lit_comp("/"), 3 },
|
||||
{ E_ExprKind_Mod, str8_lit_comp("%"), 3 },
|
||||
{ E_ExprKind_Add, str8_lit_comp("+"), 4 },
|
||||
{ E_ExprKind_Sub, str8_lit_comp("-"), 4 },
|
||||
{ E_ExprKind_LShift, str8_lit_comp("<<"), 5 },
|
||||
{ E_ExprKind_RShift, str8_lit_comp(">>"), 5 },
|
||||
{ E_ExprKind_Less, str8_lit_comp("<"), 6 },
|
||||
{ E_ExprKind_LsEq, str8_lit_comp("<="), 6 },
|
||||
{ E_ExprKind_Grtr, str8_lit_comp(">"), 6 },
|
||||
{ E_ExprKind_GrEq, str8_lit_comp(">="), 6 },
|
||||
{ E_ExprKind_EqEq, str8_lit_comp("=="), 7 },
|
||||
{ E_ExprKind_NtEq, str8_lit_comp("!="), 7 },
|
||||
{ E_ExprKind_BitAnd, str8_lit_comp("&"), 8 },
|
||||
{ E_ExprKind_BitXor, str8_lit_comp("^"), 9 },
|
||||
{ E_ExprKind_BitOr, str8_lit_comp("|"), 10 },
|
||||
{ E_ExprKind_LogAnd, str8_lit_comp("&&"), 11 },
|
||||
{ E_ExprKind_LogOr, str8_lit_comp("||"), 12 },
|
||||
{ E_ExprKind_Define, str8_lit_comp("="), 13 },
|
||||
};
|
||||
|
||||
global read_only S64 e_max_precedence = 15;
|
||||
|
||||
////////////////////////////////
|
||||
@@ -676,7 +642,7 @@ internal E_Expr *
|
||||
e_push_expr(Arena *arena, E_ExprKind kind, void *location)
|
||||
{
|
||||
E_Expr *e = push_array(arena, E_Expr, 1);
|
||||
e->first = e->last = e->next = &e_expr_nil;
|
||||
e->first = e->last = e->next = e->ref = &e_expr_nil;
|
||||
e->location = location;
|
||||
e->kind = kind;
|
||||
return e;
|
||||
@@ -688,6 +654,124 @@ e_expr_push_child(E_Expr *parent, E_Expr *child)
|
||||
SLLQueuePush_NZ(&e_expr_nil, parent->first, parent->last, child, next);
|
||||
}
|
||||
|
||||
internal E_Expr *
|
||||
e_expr_ref(Arena *arena, E_Expr *ref)
|
||||
{
|
||||
E_Expr *expr = e_push_expr(arena, E_ExprKind_Ref, 0);
|
||||
expr->ref = ref;
|
||||
return expr;
|
||||
}
|
||||
|
||||
internal E_Expr *
|
||||
e_expr_ref_member_access(Arena *arena, E_Expr *lhs, String8 member_name)
|
||||
{
|
||||
E_Expr *root = e_push_expr(arena, E_ExprKind_MemberAccess, 0);
|
||||
E_Expr *lhs_ref = e_expr_ref(arena, lhs);
|
||||
E_Expr *rhs = e_push_expr(arena, E_ExprKind_LeafMember, 0);
|
||||
rhs->string = push_str8_copy(arena, member_name);
|
||||
e_expr_push_child(root, lhs_ref);
|
||||
e_expr_push_child(root, rhs);
|
||||
return root;
|
||||
}
|
||||
|
||||
internal E_Expr *
|
||||
e_expr_ref_array_index(Arena *arena, E_Expr *lhs, U64 index)
|
||||
{
|
||||
E_Expr *root = e_push_expr(arena, E_ExprKind_ArrayIndex, 0);
|
||||
E_Expr *lhs_ref = e_expr_ref(arena, lhs);
|
||||
E_Expr *rhs = e_push_expr(arena, E_ExprKind_LeafU64, 0);
|
||||
rhs->u64 = index;
|
||||
e_expr_push_child(root, lhs_ref);
|
||||
e_expr_push_child(root, rhs);
|
||||
return root;
|
||||
}
|
||||
|
||||
internal E_Expr *
|
||||
e_expr_ref_deref(Arena *arena, E_Expr *rhs)
|
||||
{
|
||||
E_Expr *root = e_push_expr(arena, E_ExprKind_Deref, 0);
|
||||
E_Expr *rhs_ref = e_expr_ref(arena, rhs);
|
||||
e_expr_push_child(root, rhs_ref);
|
||||
return rhs_ref;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Expression Tree -> String Conversions
|
||||
|
||||
internal void
|
||||
e_append_strings_from_expr(Arena *arena, E_Expr *expr, String8List *out)
|
||||
{
|
||||
switch(expr->kind)
|
||||
{
|
||||
default:
|
||||
{
|
||||
E_OpInfo *op_info = &e_expr_kind_op_info_table[expr->kind];
|
||||
String8 seps[] =
|
||||
{
|
||||
op_info->pre,
|
||||
op_info->sep,
|
||||
op_info->post,
|
||||
};
|
||||
U64 idx = 0;
|
||||
for(E_Expr *child = expr->first; child != &e_expr_nil; child = child->next, idx += 1)
|
||||
{
|
||||
if(seps[idx].size != 0)
|
||||
{
|
||||
str8_list_push(arena, out, seps[idx]);
|
||||
}
|
||||
E_OpInfo *child_op_info = &e_expr_kind_op_info_table[child->kind];
|
||||
B32 need_parens = (child_op_info->precedence > op_info->precedence);
|
||||
if(need_parens)
|
||||
{
|
||||
str8_list_pushf(arena, out, "(");
|
||||
}
|
||||
e_append_strings_from_expr(arena, child, out);
|
||||
if(need_parens)
|
||||
{
|
||||
str8_list_pushf(arena, out, ")");
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case E_ExprKind_LeafBytecode:
|
||||
case E_ExprKind_LeafMember:
|
||||
case E_ExprKind_LeafIdent:
|
||||
{
|
||||
str8_list_push(arena, out, expr->string);
|
||||
}break;
|
||||
case E_ExprKind_LeafStringLiteral:
|
||||
{
|
||||
str8_list_pushf(arena, out, "\"%S\"", expr->string);
|
||||
}break;
|
||||
case E_ExprKind_LeafU64:
|
||||
case E_ExprKind_LeafID:
|
||||
{
|
||||
str8_list_pushf(arena, out, "0x%I64x", expr->u64);
|
||||
}break;
|
||||
case E_ExprKind_LeafF64:
|
||||
{
|
||||
str8_list_pushf(arena, out, "%f", expr->f64);
|
||||
}break;
|
||||
case E_ExprKind_LeafF32:
|
||||
{
|
||||
str8_list_pushf(arena, out, "%f", expr->f32);
|
||||
}break;
|
||||
case E_ExprKind_TypeIdent:
|
||||
{
|
||||
String8 type_string = e_type_string_from_key(arena, expr->type_key);
|
||||
str8_list_push(arena, out, type_string);
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
internal String8
|
||||
e_string_from_expr(Arena *arena, E_Expr *expr)
|
||||
{
|
||||
String8List strings = {0};
|
||||
e_append_strings_from_expr(arena, expr, &strings);
|
||||
String8 result = str8_list_join(arena, &strings, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Parsing Functions
|
||||
|
||||
@@ -966,12 +1050,13 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
|
||||
void *location = 0;
|
||||
|
||||
// rjf: try op table
|
||||
for(U64 idx = 0; idx < ArrayCount(e_unary_prefix_op_table); idx += 1)
|
||||
for(EachNonZeroEnumVal(E_ExprKind, k))
|
||||
{
|
||||
if(str8_match(token_string, e_unary_prefix_op_table[idx].string, 0))
|
||||
E_OpInfo *op_info = &e_expr_kind_op_info_table[k];
|
||||
if(op_info->kind == E_OpKind_UnaryPrefix && str8_match(op_info->pre, token_string, 0))
|
||||
{
|
||||
prefix_unary_precedence = e_unary_prefix_op_table[idx].precedence;
|
||||
prefix_unary_kind = e_unary_prefix_op_table[idx].kind;
|
||||
prefix_unary_precedence = op_info->precedence;
|
||||
prefix_unary_kind = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1445,7 +1530,8 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
|
||||
atom->mode = E_Mode_Offset;
|
||||
atom->space = space;
|
||||
atom->type_key = type_key;
|
||||
atom->string = e_bytecode_from_oplist(arena, &oplist);
|
||||
atom->string = token_string;
|
||||
atom->bytecode = e_bytecode_from_oplist(arena, &oplist);
|
||||
}
|
||||
else if(alias_code != 0)
|
||||
{
|
||||
@@ -1457,7 +1543,8 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
|
||||
atom->mode = E_Mode_Offset;
|
||||
atom->space = space;
|
||||
atom->type_key = type_key;
|
||||
atom->string = e_bytecode_from_oplist(arena, &oplist);
|
||||
atom->string = token_string;
|
||||
atom->bytecode = e_bytecode_from_oplist(arena, &oplist);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1470,7 +1557,8 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
|
||||
atom->mode = E_Mode_Offset;
|
||||
atom->space = space;
|
||||
atom->type_key = type_key;
|
||||
atom->string = loc_bytecode;
|
||||
atom->string = token_string;
|
||||
atom->bytecode = loc_bytecode;
|
||||
}break;
|
||||
case RDI_LocationKind_ValBytecodeStream:
|
||||
{
|
||||
@@ -1478,7 +1566,8 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
|
||||
atom->mode = E_Mode_Value;
|
||||
atom->space = space;
|
||||
atom->type_key = type_key;
|
||||
atom->string = loc_bytecode;
|
||||
atom->string = token_string;
|
||||
atom->bytecode = loc_bytecode;
|
||||
}break;
|
||||
case RDI_LocationKind_AddrRegPlusU16:
|
||||
{
|
||||
@@ -1492,7 +1581,8 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
|
||||
atom->mode = E_Mode_Offset;
|
||||
atom->space = space;
|
||||
atom->type_key = type_key;
|
||||
atom->string = e_bytecode_from_oplist(arena, &oplist);
|
||||
atom->string = token_string;
|
||||
atom->bytecode = e_bytecode_from_oplist(arena, &oplist);
|
||||
}break;
|
||||
case RDI_LocationKind_AddrAddrRegPlusU16:
|
||||
{
|
||||
@@ -1507,7 +1597,8 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
|
||||
atom->mode = E_Mode_Offset;
|
||||
atom->space = space;
|
||||
atom->type_key = type_key;
|
||||
atom->string = e_bytecode_from_oplist(arena, &oplist);
|
||||
atom->string = token_string;
|
||||
atom->bytecode = e_bytecode_from_oplist(arena, &oplist);
|
||||
}break;
|
||||
case RDI_LocationKind_ValReg:
|
||||
{
|
||||
@@ -1522,7 +1613,8 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
|
||||
atom->mode = E_Mode_Value;
|
||||
atom->space = space;
|
||||
atom->type_key = type_key;
|
||||
atom->string = e_bytecode_from_oplist(arena, &oplist);
|
||||
atom->string = token_string;
|
||||
atom->bytecode = e_bytecode_from_oplist(arena, &oplist);
|
||||
}break;
|
||||
}
|
||||
|
||||
@@ -1763,12 +1855,13 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
|
||||
// rjf: first try to find a matching binary operator
|
||||
S64 binary_precedence = 0;
|
||||
E_ExprKind binary_kind = 0;
|
||||
for(U64 idx = 0; idx < ArrayCount(e_binary_op_table); idx += 1)
|
||||
for(EachNonZeroEnumVal(E_ExprKind, k))
|
||||
{
|
||||
if(str8_match(token_string, e_binary_op_table[idx].string, 0))
|
||||
E_OpInfo *op_info = &e_expr_kind_op_info_table[k];
|
||||
if(op_info->kind == E_OpKind_Binary && str8_match(op_info->sep, token_string, 0))
|
||||
{
|
||||
binary_precedence = e_binary_op_table[idx].precedence;
|
||||
binary_kind = e_binary_op_table[idx].kind;
|
||||
binary_precedence = op_info->precedence;
|
||||
binary_kind = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ struct E_Expr
|
||||
E_Expr *first;
|
||||
E_Expr *last;
|
||||
E_Expr *next;
|
||||
E_Expr *ref;
|
||||
void *location;
|
||||
E_ExprKind kind;
|
||||
E_Mode mode;
|
||||
@@ -63,6 +64,7 @@ struct E_Expr
|
||||
U64 u64;
|
||||
F64 f64;
|
||||
String8 string;
|
||||
String8 bytecode;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
@@ -219,6 +221,17 @@ internal U32 e_parse_ctx_module_idx_from_rdi(RDI_Parsed *rdi);
|
||||
internal E_Expr *e_push_expr(Arena *arena, E_ExprKind kind, void *location);
|
||||
internal void e_expr_push_child(E_Expr *parent, E_Expr *child);
|
||||
|
||||
internal E_Expr *e_expr_ref(Arena *arena, E_Expr *ref);
|
||||
internal E_Expr *e_expr_ref_member_access(Arena *arena, E_Expr *lhs, String8 member_name);
|
||||
internal E_Expr *e_expr_ref_array_index(Arena *arena, E_Expr *lhs, U64 index);
|
||||
internal E_Expr *e_expr_ref_deref(Arena *arena, E_Expr *rhs);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Expression Tree -> String Conversions
|
||||
|
||||
internal void e_append_strings_from_expr(Arena *arena, E_Expr *expr, String8List *out);
|
||||
internal String8 e_string_from_expr(Arena *arena, E_Expr *expr);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Parsing Functions
|
||||
|
||||
|
||||
@@ -156,6 +156,13 @@ e_type_kind_is_basic_or_enum(E_TypeKind kind)
|
||||
return result;
|
||||
}
|
||||
|
||||
internal B32
|
||||
e_type_kind_is_pointer_or_ref(E_TypeKind kind)
|
||||
{
|
||||
B32 result = (kind == E_TypeKind_Ptr || kind == E_TypeKind_LRef || kind == E_TypeKind_RRef);
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Member Functions
|
||||
|
||||
@@ -1409,6 +1416,22 @@ e_type_data_members_from_key(Arena *arena, E_TypeKey key)
|
||||
return members;
|
||||
}
|
||||
|
||||
internal E_Member *
|
||||
e_type_member_from_array_name(E_MemberArray *members, String8 name)
|
||||
{
|
||||
E_Member *member = 0;
|
||||
for(U64 idx = 0; idx < members->count; idx += 1)
|
||||
{
|
||||
if(members->v[idx].kind == E_MemberKind_DataField &&
|
||||
str8_match(members->v[idx].name, name, 0))
|
||||
{
|
||||
member = &members->v[idx];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return member;
|
||||
}
|
||||
|
||||
internal void
|
||||
e_type_lhs_string_from_key(Arena *arena, E_TypeKey key, String8List *out, U32 prec, B32 skip_return)
|
||||
{
|
||||
|
||||
@@ -210,6 +210,7 @@ internal RDI_EvalTypeGroup e_type_group_from_kind(E_TypeKind kind);
|
||||
internal B32 e_type_kind_is_integer(E_TypeKind kind);
|
||||
internal B32 e_type_kind_is_signed(E_TypeKind kind);
|
||||
internal B32 e_type_kind_is_basic_or_enum(E_TypeKind kind);
|
||||
internal B32 e_type_kind_is_pointer_or_ref(E_TypeKind kind);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Member Functions
|
||||
@@ -261,6 +262,7 @@ internal B32 e_type_match(E_TypeKey l, E_TypeKey r);
|
||||
internal E_Member *e_type_member_copy(Arena *arena, E_Member *src);
|
||||
internal int e_type_qsort_compare_members_offset(E_Member *a, E_Member *b);
|
||||
internal E_MemberArray e_type_data_members_from_key(Arena *arena, E_TypeKey key);
|
||||
internal E_Member *e_type_member_from_array_name(E_MemberArray *members, String8 name);
|
||||
internal void e_type_lhs_string_from_key(Arena *arena, E_TypeKey key, String8List *out, U32 prec, B32 skip_return);
|
||||
internal void e_type_rhs_string_from_key(Arena *arena, E_TypeKey key, String8List *out, U32 prec);
|
||||
internal String8 e_type_string_from_key(Arena *arena, E_TypeKey key);
|
||||
|
||||
@@ -14,9 +14,10 @@ str8_lit_comp("CharLiteral"),
|
||||
str8_lit_comp("Symbol"),
|
||||
};
|
||||
|
||||
String8 e_expr_kind_strings[42] =
|
||||
String8 e_expr_kind_strings[43] =
|
||||
{
|
||||
str8_lit_comp("Nil"),
|
||||
str8_lit_comp("Ref"),
|
||||
str8_lit_comp("ArrayIndex"),
|
||||
str8_lit_comp("MemberAccess"),
|
||||
str8_lit_comp("Deref"),
|
||||
@@ -75,50 +76,51 @@ str8_lit_comp("Insufficient evaluation machine stack space."),
|
||||
str8_lit_comp("Malformed bytecode."),
|
||||
};
|
||||
|
||||
String8 e_expr_op_strings[42] =
|
||||
E_OpInfo e_expr_kind_op_info_table[43] =
|
||||
{
|
||||
str8_lit_comp(""),
|
||||
str8_lit_comp("[]"),
|
||||
str8_lit_comp("."),
|
||||
str8_lit_comp("*"),
|
||||
str8_lit_comp("&"),
|
||||
str8_lit_comp("cast"),
|
||||
str8_lit_comp("sizeof"),
|
||||
str8_lit_comp("-"),
|
||||
str8_lit_comp("!"),
|
||||
str8_lit_comp("~"),
|
||||
str8_lit_comp("*"),
|
||||
str8_lit_comp("/"),
|
||||
str8_lit_comp("%"),
|
||||
str8_lit_comp("+"),
|
||||
str8_lit_comp("-"),
|
||||
str8_lit_comp("<<"),
|
||||
str8_lit_comp(">>"),
|
||||
str8_lit_comp("<"),
|
||||
str8_lit_comp("<="),
|
||||
str8_lit_comp(">"),
|
||||
str8_lit_comp(">="),
|
||||
str8_lit_comp("=="),
|
||||
str8_lit_comp("!="),
|
||||
str8_lit_comp("&"),
|
||||
str8_lit_comp("^"),
|
||||
str8_lit_comp("|"),
|
||||
str8_lit_comp("&&"),
|
||||
str8_lit_comp("||"),
|
||||
str8_lit_comp("? "),
|
||||
str8_lit_comp("bytecode"),
|
||||
str8_lit_comp("member"),
|
||||
str8_lit_comp("string_literal"),
|
||||
str8_lit_comp("U64"),
|
||||
str8_lit_comp("F64"),
|
||||
str8_lit_comp("F32"),
|
||||
str8_lit_comp("leaf_ident"),
|
||||
str8_lit_comp("leaf_id"),
|
||||
str8_lit_comp("type_ident"),
|
||||
str8_lit_comp("ptr"),
|
||||
str8_lit_comp("array"),
|
||||
str8_lit_comp("function"),
|
||||
str8_lit_comp("="),
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("Nil") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("Ref") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp("["), str8_lit_comp("ArrayIndex") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp("."), str8_lit_comp("MemberAccess") },
|
||||
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("*"), str8_lit_comp(""), str8_lit_comp("Deref") },
|
||||
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("&"), str8_lit_comp(""), str8_lit_comp("Address") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("Cast") },
|
||||
{ E_OpKind_UnaryPrefix, 0, str8_lit_comp("sizeof"), str8_lit_comp(""), str8_lit_comp("Sizeof") },
|
||||
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("-"), str8_lit_comp(""), str8_lit_comp("Neg") },
|
||||
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("!"), str8_lit_comp(""), str8_lit_comp("LogNot") },
|
||||
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("~"), str8_lit_comp(""), str8_lit_comp("BitNot") },
|
||||
{ E_OpKind_Binary, 3, str8_lit_comp(""), str8_lit_comp("*"), str8_lit_comp("Mul") },
|
||||
{ E_OpKind_Binary, 3, str8_lit_comp(""), str8_lit_comp("/"), str8_lit_comp("Div") },
|
||||
{ E_OpKind_Binary, 3, str8_lit_comp(""), str8_lit_comp("%"), str8_lit_comp("Mod") },
|
||||
{ E_OpKind_Binary, 4, str8_lit_comp(""), str8_lit_comp("+"), str8_lit_comp("Add") },
|
||||
{ E_OpKind_Binary, 4, str8_lit_comp(""), str8_lit_comp("-"), str8_lit_comp("Sub") },
|
||||
{ E_OpKind_Binary, 5, str8_lit_comp(""), str8_lit_comp("<<"), str8_lit_comp("LShift") },
|
||||
{ E_OpKind_Binary, 5, str8_lit_comp(""), str8_lit_comp(">>"), str8_lit_comp("RShift") },
|
||||
{ E_OpKind_Binary, 6, str8_lit_comp(""), str8_lit_comp("<"), str8_lit_comp("Less") },
|
||||
{ E_OpKind_Binary, 6, str8_lit_comp(""), str8_lit_comp("<="), str8_lit_comp("LsEq") },
|
||||
{ E_OpKind_Binary, 6, str8_lit_comp(""), str8_lit_comp(">"), str8_lit_comp("Grtr") },
|
||||
{ E_OpKind_Binary, 6, str8_lit_comp(""), str8_lit_comp(">="), str8_lit_comp("GrEq") },
|
||||
{ E_OpKind_Binary, 7, str8_lit_comp(""), str8_lit_comp("=="), str8_lit_comp("EqEq") },
|
||||
{ E_OpKind_Binary, 7, str8_lit_comp(""), str8_lit_comp("!="), str8_lit_comp("NtEq") },
|
||||
{ E_OpKind_Binary, 8, str8_lit_comp(""), str8_lit_comp("&"), str8_lit_comp("BitAnd") },
|
||||
{ E_OpKind_Binary, 9, str8_lit_comp(""), str8_lit_comp("^"), str8_lit_comp("BitXor") },
|
||||
{ E_OpKind_Binary, 10, str8_lit_comp(""), str8_lit_comp("|"), str8_lit_comp("BitOr") },
|
||||
{ E_OpKind_Binary, 11, str8_lit_comp(""), str8_lit_comp("&&"), str8_lit_comp("LogAnd") },
|
||||
{ E_OpKind_Binary, 12, str8_lit_comp(""), str8_lit_comp("||"), str8_lit_comp("LogOr") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp("?"), str8_lit_comp("Ternary") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("LeafBytecode") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("LeafMember") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("LeafStringLiteral") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("LeafU64") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("LeafF64") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("LeafF32") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("LeafIdent") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("LeafID") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("TypeIdent") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("Ptr") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("Array") },
|
||||
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("Func") },
|
||||
{ E_OpKind_Binary, 13, str8_lit_comp(""), str8_lit_comp("="), str8_lit_comp("Define") },
|
||||
};
|
||||
|
||||
U8 e_kind_basic_byte_size_table[55] =
|
||||
|
||||
@@ -91,6 +91,7 @@ typedef U32 E_ExprKind;
|
||||
typedef enum E_ExprKindEnum
|
||||
{
|
||||
E_ExprKind_Nil,
|
||||
E_ExprKind_Ref,
|
||||
E_ExprKind_ArrayIndex,
|
||||
E_ExprKind_MemberAccess,
|
||||
E_ExprKind_Deref,
|
||||
@@ -153,9 +154,9 @@ E_InterpretationCode_COUNT,
|
||||
|
||||
C_LINKAGE_BEGIN
|
||||
extern String8 e_token_kind_strings[6];
|
||||
extern String8 e_expr_kind_strings[42];
|
||||
extern String8 e_expr_kind_strings[43];
|
||||
extern String8 e_interpretation_code_display_strings[11];
|
||||
extern String8 e_expr_op_strings[42];
|
||||
extern E_OpInfo e_expr_kind_op_info_table[43];
|
||||
extern U8 e_kind_basic_byte_size_table[55];
|
||||
extern String8 e_kind_basic_string_table[55];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user