Skip to content

Commit 4cc5f63

Browse files
committed
cfg tree collection evaluation
1 parent b085acb commit 4cc5f63

File tree

15 files changed

+493
-711
lines changed

15 files changed

+493
-711
lines changed

src/eval/eval.mdesk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ E_TypeKindTable:
7171
{IncompleteEnum "enum" 0 }
7272
{Bitfield "bitfield" 0 }
7373
{Variadic "variadic" 0 }
74+
{SpacePtr "space_ptr" 0 }
7475
}
7576

7677
@table(name op_kind precedence string op_pre op_sep op_pos)

src/eval/eval_bundles.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ e_eval_from_expr(Arena *arena, E_Expr *expr)
1111
E_OpList oplist = e_oplist_from_irtree(arena, irtree.root);
1212
String8 bytecode = e_bytecode_from_oplist(arena, &oplist);
1313
E_Interpretation interp = e_interpret(bytecode);
14-
E_Space zero_space = {0};
15-
E_Space space = (MemoryMatchStruct(&zero_space, &irtree.space) ? e_interpret_ctx->primary_space : irtree.space);
1614
E_Eval eval =
1715
{
1816
.value = interp.value,
1917
.mode = irtree.mode,
20-
.space = space,
18+
.space = interp.space,
2119
.expr = expr,
2220
.type_key = irtree.type_key,
2321
.code = interp.code,

src/eval/eval_interpret.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ e_interpret(String8 bytecode)
7474
}
7575
else switch(op)
7676
{
77-
case E_IRExtKind_SetSpace:{ctrlbits = RDI_EVAL_CTRLBITS(32, 0, 0);}break;
77+
case E_IRExtKind_SetSpace: {ctrlbits = RDI_EVAL_CTRLBITS(32, 0, 0);}break;
78+
case E_IRExtKind_DerefSpacePtr:{ctrlbits = RDI_EVAL_CTRLBITS(0, 1, 1);}break;
7879
default:
7980
{
8081
result.code = E_InterpretationCode_BadOp;
@@ -124,6 +125,27 @@ e_interpret(String8 bytecode)
124125
MemoryCopy(&selected_space, &imm, sizeof(selected_space));
125126
}break;
126127

128+
case E_IRExtKind_DerefSpacePtr:
129+
{
130+
U64 addr = svals[0].u64;
131+
U64 size = sizeof(E_Space) + sizeof(U64);
132+
typedef struct SpacePtrRead SpacePtrRead;
133+
struct SpacePtrRead
134+
{
135+
E_Space space;
136+
U64 off;
137+
};
138+
SpacePtrRead space_ptr_read = {0};
139+
B32 good_read = e_space_read(selected_space, &space_ptr_read, r1u64(addr, addr+size));
140+
if(!good_read)
141+
{
142+
result.code = E_InterpretationCode_BadMemRead;
143+
goto done;
144+
}
145+
MemoryCopyStruct(&selected_space, &space_ptr_read.space);
146+
nval.u64 = space_ptr_read.off;
147+
}break;
148+
127149
case RDI_EvalOp_Stop:
128150
{
129151
goto done;
@@ -812,6 +834,7 @@ e_interpret(String8 bytecode)
812834
{
813835
result.value = stack[0];
814836
}
837+
result.space = selected_space;
815838
scratch_end(scratch);
816839
return result;
817840
}

src/eval/eval_interpret.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ typedef struct E_Interpretation E_Interpretation;
1111
struct E_Interpretation
1212
{
1313
E_Value value;
14+
E_Space space;
1415
E_InterpretationCode code;
1516
};
1617

0 commit comments

Comments
 (0)