more eval scratch work

This commit is contained in:
Ryan Fleury
2025-03-31 13:09:30 -07:00
parent fbe0d3bc2e
commit 17ff4da9bf
6 changed files with 88 additions and 54 deletions
+24 -2
View File
@@ -382,11 +382,33 @@ typedef S64 B64;
typedef float F32; typedef float F32;
typedef double F64; typedef double F64;
typedef void VoidProc(void); typedef void VoidProc(void);
typedef struct U128 U128; typedef union U128 U128;
struct U128 union U128
{ {
U8 u8[16];
U16 u16[8];
U32 u32[4];
U64 u64[2]; U64 u64[2];
}; };
typedef union U256 U256;
union U256
{
U8 u8[32];
U16 u16[16];
U32 u32[8];
U64 u64[4];
U128 u128[2];
};
typedef union U512 U512;
union U512
{
U8 u8[64];
U16 u16[32];
U32 u32[16];
U64 u64[8];
U128 u128[4];
U256 u256[2];
};
//////////////////////////////// ////////////////////////////////
//~ rjf: Basic Types & Spaces //~ rjf: Basic Types & Spaces
+2 -2
View File
@@ -42,8 +42,8 @@ struct E_MsgList
typedef union E_Value E_Value; typedef union E_Value E_Value;
union E_Value union E_Value
{ {
U64 u512[8]; U512 u512;
U64 u256[4]; U256 u256;
U128 u128; U128 u128;
U64 u64; U64 u64;
U32 u32; U32 u32;
+3 -3
View File
@@ -572,13 +572,13 @@ e_interpret(String8 bytecode)
case RDI_EvalOp_EqEq: case RDI_EvalOp_EqEq:
{ {
B32 result = MemoryMatchArray(svals[0].u512, svals[1].u512); B32 result = MemoryMatchArray(svals[0].u512.u64, svals[1].u512.u64);
nval.u64 = !!result; nval.u64 = !!result;
}break; }break;
case RDI_EvalOp_NtEq: case RDI_EvalOp_NtEq:
{ {
B32 result = MemoryMatchArray(svals[0].u512, svals[1].u512); B32 result = MemoryMatchArray(svals[0].u512.u64, svals[1].u512.u64);
nval.u64 = !result; nval.u64 = !result;
}break; }break;
@@ -813,7 +813,7 @@ e_interpret(String8 bytecode)
if(offset + bytes_to_read <= sizeof(E_Value)) if(offset + bytes_to_read <= sizeof(E_Value))
{ {
E_Value src_val = svals[1]; E_Value src_val = svals[1];
MemoryCopy(&nval.u512[0], (U8 *)(&src_val.u512[0]) + offset, bytes_to_read); MemoryCopy(&nval.u512.u64[0], (U8 *)(&src_val.u512.u64[0]) + offset, bytes_to_read);
} }
}break; }break;
+39 -32
View File
@@ -633,6 +633,10 @@ e_select_parse_ctx(E_ParseCtx *ctx)
e_parse_state->arena_eval_start_pos = arena_pos(arena); e_parse_state->arena_eval_start_pos = arena_pos(arena);
} }
arena_pop_to(e_parse_state->arena, e_parse_state->arena_eval_start_pos); arena_pop_to(e_parse_state->arena, e_parse_state->arena_eval_start_pos);
if(ctx->regs_map == 0) { ctx->regs_map = &e_string2num_map_nil; }
if(ctx->reg_alias_map == 0) { ctx->reg_alias_map = &e_string2num_map_nil; }
if(ctx->locals_map == 0) { ctx->locals_map = &e_string2num_map_nil; }
if(ctx->member_map == 0) { ctx->member_map = &e_string2num_map_nil; }
e_parse_state->ctx = ctx; e_parse_state->ctx = ctx;
} }
@@ -1498,43 +1502,46 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
arch = module->arch; arch = module->arch;
U64 all_location_data_size = 0; U64 all_location_data_size = 0;
U8 *all_location_data = rdi_table_from_name(rdi, LocationData, &all_location_data_size); U8 *all_location_data = rdi_table_from_name(rdi, LocationData, &all_location_data_size);
loc_kind = *((RDI_LocationKind *)(all_location_data + block->location_data_off)); if(block->location_data_off + sizeof(RDI_LocationKind) <= all_location_data_size)
switch(loc_kind)
{ {
default:{mapped_identifier = 0;}break; loc_kind = *((RDI_LocationKind *)(all_location_data + block->location_data_off));
case RDI_LocationKind_ValBytecodeStream: goto bytecode_stream; switch(loc_kind)
case RDI_LocationKind_AddrBytecodeStream: goto bytecode_stream;
bytecode_stream:;
{ {
U64 bytecode_size = 0; default:{mapped_identifier = 0;}break;
U64 off_first = block->location_data_off + sizeof(RDI_LocationKind); case RDI_LocationKind_ValBytecodeStream: goto bytecode_stream;
U64 off_opl = all_location_data_size; case RDI_LocationKind_AddrBytecodeStream: goto bytecode_stream;
for(U64 off = off_first, next_off = off_opl; bytecode_stream:;
off < all_location_data_size;
off = next_off)
{ {
next_off = off_opl; U64 bytecode_size = 0;
U8 op = all_location_data[off]; U64 off_first = block->location_data_off + sizeof(RDI_LocationKind);
if(op == 0) U64 off_opl = all_location_data_size;
for(U64 off = off_first, next_off = off_opl;
off < all_location_data_size;
off = next_off)
{ {
break; next_off = off_opl;
U8 op = all_location_data[off];
if(op == 0)
{
break;
}
U16 ctrlbits = rdi_eval_op_ctrlbits_table[op];
U32 p_size = RDI_DECODEN_FROM_CTRLBITS(ctrlbits);
bytecode_size += (1 + p_size);
next_off = (off + 1 + p_size);
} }
U16 ctrlbits = rdi_eval_op_ctrlbits_table[op]; loc_bytecode = str8(all_location_data + off_first, bytecode_size);
U32 p_size = RDI_DECODEN_FROM_CTRLBITS(ctrlbits); }break;
bytecode_size += (1 + p_size); case RDI_LocationKind_AddrRegPlusU16:
next_off = (off + 1 + p_size); case RDI_LocationKind_AddrAddrRegPlusU16:
} {
loc_bytecode = str8(all_location_data + off_first, bytecode_size); MemoryCopy(&loc_reg_u16, (all_location_data + block->location_data_off), sizeof(loc_reg_u16));
}break; }break;
case RDI_LocationKind_AddrRegPlusU16: case RDI_LocationKind_ValReg:
case RDI_LocationKind_AddrAddrRegPlusU16: {
{ MemoryCopy(&loc_reg, (all_location_data + block->location_data_off), sizeof(loc_reg));
MemoryCopy(&loc_reg_u16, (all_location_data + block->location_data_off), sizeof(loc_reg_u16)); }break;
}break; }
case RDI_LocationKind_ValReg:
{
MemoryCopy(&loc_reg, (all_location_data + block->location_data_off), sizeof(loc_reg));
}break;
} }
} }
} }
-1
View File
@@ -834,4 +834,3 @@ rdi_size_from_bytecode_stream(RDI_U8 *ptr, RDI_U8 *opl)
} }
return bytecode_size; return bytecode_size;
} }
+20 -14
View File
@@ -27,7 +27,7 @@ internal void
entry_point(CmdLine *cmdline) entry_point(CmdLine *cmdline)
{ {
Arena *arena = arena_alloc(); Arena *arena = arena_alloc();
char *indent_spaces = " "; char *indent_spaces = " ";
E_TypeCtx *type_ctx = push_array(arena, E_TypeCtx, 1); E_TypeCtx *type_ctx = push_array(arena, E_TypeCtx, 1);
e_select_type_ctx(type_ctx); e_select_type_ctx(type_ctx);
E_ParseCtx *parse_ctx = push_array(arena, E_ParseCtx, 1); E_ParseCtx *parse_ctx = push_array(arena, E_ParseCtx, 1);
@@ -39,6 +39,8 @@ entry_point(CmdLine *cmdline)
String8 exprs[] = String8 exprs[] =
{ {
str8_lit("123"), str8_lit("123"),
str8_lit("1 + 2"),
str8_lit("foo"),
}; };
for EachElement(idx, exprs) for EachElement(idx, exprs)
{ {
@@ -48,12 +50,12 @@ entry_point(CmdLine *cmdline)
//- rjf: tokenize //- rjf: tokenize
E_TokenArray tokens = e_token_array_from_text(arena, expr_text); E_TokenArray tokens = e_token_array_from_text(arena, expr_text);
raddbg_log(" tokens:\n"); raddbg_log(" tokens:\n");
for EachIndex(idx, tokens.count) for EachIndex(idx, tokens.count)
{ {
E_Token token = tokens.v[idx]; E_Token token = tokens.v[idx];
String8 token_string = str8_substr(expr_text, token.range); String8 token_string = str8_substr(expr_text, token.range);
raddbg_log(" %S: `%S`\n", e_token_kind_strings[token.kind], token_string); raddbg_log(" %S: `%S`\n", e_token_kind_strings[token.kind], token_string);
} }
//- rjf: parse //- rjf: parse
@@ -66,13 +68,13 @@ entry_point(CmdLine *cmdline)
E_Expr *expr; E_Expr *expr;
S32 indent; S32 indent;
}; };
raddbg_log(" expr:\n"); raddbg_log(" expr:\n");
Task start_task = {0, parse.exprs.first, 2}; Task start_task = {0, parse.exprs.first, 2};
Task *first_task = &start_task; Task *first_task = &start_task;
for(Task *t = first_task; t != 0; t = t->next) for(Task *t = first_task; t != 0; t = t->next)
{ {
E_Expr *expr = t->expr; E_Expr *expr = t->expr;
raddbg_log("%.*s%S", (int)t->indent*2, indent_spaces, e_expr_kind_strings[expr->kind]); raddbg_log("%.*s%S", (int)t->indent*4, indent_spaces, e_expr_kind_strings[expr->kind]);
switch(expr->kind) switch(expr->kind)
{ {
default:{}break; default:{}break;
@@ -82,13 +84,15 @@ entry_point(CmdLine *cmdline)
}break; }break;
} }
raddbg_log("\n"); raddbg_log("\n");
Task *last_task = t;
for(E_Expr *child = expr->first; child != &e_expr_nil; child = child->next) for(E_Expr *child = expr->first; child != &e_expr_nil; child = child->next)
{ {
Task *task = push_array(arena, Task, 1); Task *task = push_array(arena, Task, 1);
task->next = t->next; task->next = last_task->next;
t->next = task; last_task->next = task;
task->expr = child; task->expr = child;
task->indent = t->indent+1; task->indent = t->indent+1;
last_task = task;
} }
} }
} }
@@ -96,7 +100,7 @@ entry_point(CmdLine *cmdline)
//- rjf: type //- rjf: type
E_IRTreeAndType irtree = e_irtree_and_type_from_expr(arena, parse.exprs.first); E_IRTreeAndType irtree = e_irtree_and_type_from_expr(arena, parse.exprs.first);
{ {
raddbg_log(" type:\n"); raddbg_log(" type:\n");
S32 indent = 2; S32 indent = 2;
for(E_TypeKey type_key = irtree.type_key; for(E_TypeKey type_key = irtree.type_key;
!e_type_key_match(e_type_key_zero(), type_key); !e_type_key_match(e_type_key_zero(), type_key);
@@ -104,7 +108,7 @@ entry_point(CmdLine *cmdline)
indent += 1) indent += 1)
{ {
E_Type *type = e_type_from_key(arena, type_key); E_Type *type = e_type_from_key(arena, type_key);
raddbg_log("%.*s%S\n", (int)indent*2, indent_spaces, e_kind_basic_string_table[type->kind]); raddbg_log("%.*s%S\n", (int)indent*4, indent_spaces, e_kind_basic_string_table[type->kind]);
} }
} }
@@ -117,17 +121,17 @@ entry_point(CmdLine *cmdline)
E_IRNode *irnode; E_IRNode *irnode;
S32 indent; S32 indent;
}; };
raddbg_log(" ir_tree:\n"); raddbg_log(" ir_tree:\n");
Task start_task = {0, irtree.root, 2}; Task start_task = {0, irtree.root, 2};
Task *first_task = &start_task; Task *first_task = &start_task;
for(Task *t = first_task; t != 0; t = t->next) for(Task *t = first_task; t != 0; t = t->next)
{ {
E_IRNode *irnode = t->irnode; E_IRNode *irnode = t->irnode;
raddbg_log("%.*s", (int)t->indent*2, indent_spaces); raddbg_log("%.*s", (int)t->indent*4, indent_spaces);
switch(irnode->op) switch(irnode->op)
{ {
default:{}break; default:{}break;
#define X(name) case RDI_EvalOp_##name:{raddbg_log(" " #name);}break; #define X(name) case RDI_EvalOp_##name:{raddbg_log(#name);}break;
RDI_EvalOp_XList RDI_EvalOp_XList
#undef X #undef X
} }
@@ -136,13 +140,15 @@ entry_point(CmdLine *cmdline)
raddbg_log(" (%I64u)", irnode->value.u64); raddbg_log(" (%I64u)", irnode->value.u64);
} }
raddbg_log("\n"); raddbg_log("\n");
Task *last_task = t;
for(E_IRNode *child = irnode->first; child != &e_irnode_nil; child = child->next) for(E_IRNode *child = irnode->first; child != &e_irnode_nil; child = child->next)
{ {
Task *task = push_array(arena, Task, 1); Task *task = push_array(arena, Task, 1);
task->next = t->next; task->next = last_task->next;
t->next = task; last_task->next = task;
task->irnode = child; task->irnode = child;
task->indent = t->indent+1; task->indent = t->indent+1;
last_task = task;
} }
} }
} }