Slowly trying to add function calls, cases for RETURN and CALL
This commit is contained in:
@@ -17,6 +17,7 @@ enum Operation: U16{
|
||||
BC_LOAD_CONSTANT,
|
||||
BC_STORE_CONSTANT,
|
||||
BC_CALL,
|
||||
BC_CALL_RETURN,
|
||||
BC_LOAD_FROM_MEMORY64,
|
||||
BC_LOAD_FROM_MEMORY32,
|
||||
BC_LOAD_FROM_MEMORY16,
|
||||
@@ -79,6 +80,7 @@ const char *op_name[] = {
|
||||
"BC_LOAD_CONSTANT",
|
||||
"BC_STORE_CONSTANT",
|
||||
"BC_CALL",
|
||||
"BC_CALL_RETURN",
|
||||
"BC_LOAD_FROM_MEMORY64",
|
||||
"BC_LOAD_FROM_MEMORY32",
|
||||
"BC_LOAD_FROM_MEMORY16",
|
||||
@@ -181,18 +183,20 @@ struct Instruction{
|
||||
|
||||
struct Call_Frame{
|
||||
Call_Frame *previous_call;
|
||||
Register_Index first_register;
|
||||
Instruction *saved_instruction_pointer;
|
||||
Register_Index first_register_index_in_window;
|
||||
Register_Index register_where_you_write_return_value;
|
||||
};
|
||||
|
||||
struct Bc{
|
||||
U32 dis; // @debug_ids
|
||||
|
||||
U64 *stack_bottom;
|
||||
U64 *stack_pointer;
|
||||
U64 *stack_top;
|
||||
U8 *stack_bottom;
|
||||
U8 *stack_pointer;
|
||||
U8 *stack_top;
|
||||
|
||||
Call_Frame *top_call;
|
||||
Register_Index first_register_index_in_window;
|
||||
|
||||
Array<Register> registers;
|
||||
Array<Register_Index> used_registers;
|
||||
Array<Register_Index> free_registers;
|
||||
@@ -274,13 +278,13 @@ new_instruction(Bc *b, Token *pos){
|
||||
return i;
|
||||
}
|
||||
|
||||
// function void
|
||||
// emit_call(Bc *b, Token *pos, Register_Index register_with_call_address, Register_Index register_with_last_argument){
|
||||
// auto i = new_instruction(b, pos);
|
||||
// i->operation = BC_CALL;
|
||||
// i->index_a = register_with_call_address;
|
||||
// i->index_b = register_with_last_argument;
|
||||
// }
|
||||
function void
|
||||
emit_call(Bc *b, Token *pos, Register_Index register_with_call_address, Register_Index register_with_last_argument){
|
||||
auto i = new_instruction(b, pos);
|
||||
i->operation = BC_CALL;
|
||||
i->index_a = register_with_call_address;
|
||||
i->index_b = register_with_last_argument;
|
||||
}
|
||||
|
||||
function void
|
||||
emit_load_constant_f64(Bc *b, Token *pos, Register_Index dst, F64 constant){
|
||||
@@ -356,15 +360,36 @@ emit_end(Bc *b){
|
||||
i->operation = BC_END_OF_INSTRUCTIONS;
|
||||
}
|
||||
|
||||
#define R(x) (b->registers[b->top_call->first_register_index_in_window + (x)]) // Get register
|
||||
#define bc_stack_push(b, T) (T *)bc__stack_push(b, sizeof(T))
|
||||
|
||||
function U8 *
|
||||
bc__stack_push(Bc *b, U64 size){
|
||||
U8 *result = (U8 *)b->stack_pointer;
|
||||
b->stack_pointer += size;
|
||||
assert(b->stack_pointer < b->stack_top);
|
||||
return result;
|
||||
}
|
||||
|
||||
function Call_Frame *
|
||||
bc_push_call_frame(Bc *b, Register_Index function_address_register){
|
||||
auto call = bc_stack_push(b, Call_Frame);
|
||||
call->first_register_index_in_window = function_address_register + 1;
|
||||
call->register_where_you_write_return_value = function_address_register;
|
||||
call->previous_call = b->top_call;
|
||||
call->saved_instruction_pointer = 0;
|
||||
|
||||
b->top_call = call;
|
||||
return call;
|
||||
}
|
||||
|
||||
function void
|
||||
run_bytecode_interp(Bc *b){
|
||||
// Setup registers
|
||||
b->instruction_pointer = (Instruction *)b->instructions.memory.data;
|
||||
b->stack_pointer = b->stack_bottom = (U64 *)b->stack.memory.data;
|
||||
b->stack_top = (U64 *)(b->stack.memory.data + b->stack.len);
|
||||
b->first_register_index_in_window = 0;
|
||||
b->stack_pointer = b->stack_bottom = b->stack.memory.data;
|
||||
b->stack_top = (b->stack.memory.data + b->stack.len);
|
||||
bc_push_call_frame(b, 0);
|
||||
|
||||
#define R(x) (b->registers[b->first_register_index_in_window + (x)]) // Get register
|
||||
for(;;){
|
||||
Instruction *instr = b->instruction_pointer++;
|
||||
|
||||
@@ -372,7 +397,7 @@ run_bytecode_interp(Bc *b){
|
||||
print_token_line(instr->debug_pos);
|
||||
assert_msg(b->stack_pointer < b->stack_top, "Bytecode stack overflow");
|
||||
assert_msg(b->stack_pointer >= b->stack_bottom, "Bytecode stack underflow");
|
||||
assert_msg(b->first_register_index_in_window < b->registers.cap, "Bytecode interpreter bug, register pointer is pointing over last possible register");
|
||||
assert_msg(b->top_call->first_register_index_in_window < b->registers.cap, "Bytecode interpreter bug, register pointer is pointing over last possible register");
|
||||
#endif
|
||||
|
||||
bc_log("i%u[0x%llx] %s ", instr->di, instr, op_name[instr->operation]);
|
||||
@@ -380,7 +405,8 @@ run_bytecode_interp(Bc *b){
|
||||
invalid_default_case;
|
||||
|
||||
case BC_PUSH_STACK:{
|
||||
U64 *stack = b->stack_pointer++;
|
||||
U64 *stack = (U64 *)b->stack_pointer;
|
||||
b->stack_pointer += sizeof(U64);
|
||||
|
||||
U64 src = R(instr->index_a).u64;
|
||||
bc_log("r%u(src) [0x%llx|%lld|%f]", instr->index_a, src, src, src);
|
||||
@@ -388,15 +414,12 @@ run_bytecode_interp(Bc *b){
|
||||
}break;
|
||||
|
||||
case BC_POP_STACK:{
|
||||
U64 *stack = --b->stack_pointer;
|
||||
b->stack_pointer -= sizeof(U64);
|
||||
U64 *stack = (U64 *)b->stack_pointer;
|
||||
bc_log("r%u(dst) [0x%llx|%lld|%f]", instr->index_c, *stack, *stack, *stack);
|
||||
R(instr->index_c).u64 = *stack;
|
||||
}break;
|
||||
|
||||
case BC_END_OF_INSTRUCTIONS:{
|
||||
goto end_of_program;
|
||||
}break;
|
||||
|
||||
case BC_LOAD_CONSTANT: {
|
||||
R(instr->index_c) = instr->constant;
|
||||
#if BC_LOG
|
||||
@@ -410,6 +433,25 @@ run_bytecode_interp(Bc *b){
|
||||
#endif
|
||||
}break;
|
||||
|
||||
case BC_CALL:{
|
||||
Register_Index register_with_call_address = instr->index_a;
|
||||
// Register_Index register_with_last_argument = instr->index_b;
|
||||
Call_Frame *call = bc_push_call_frame(b, register_with_call_address);
|
||||
call->saved_instruction_pointer = b->instruction_pointer;
|
||||
b->instruction_pointer = (Instruction *)R(register_with_call_address).pointer;
|
||||
}break;
|
||||
|
||||
case BC_CALL_RETURN:{
|
||||
Call_Frame *call = b->top_call;
|
||||
Call_Frame *prev = call->previous_call;
|
||||
assert(prev);
|
||||
|
||||
b->top_call = prev;
|
||||
}break;
|
||||
|
||||
case BC_END_OF_INSTRUCTIONS:{
|
||||
goto end_of_program;
|
||||
}break;
|
||||
//
|
||||
// *Begin* of switch_cases generated using code_generating_script.py
|
||||
//
|
||||
@@ -425,7 +467,7 @@ run_bytecode_interp(Bc *b){
|
||||
*store_address = R(instr->index_a).u64;
|
||||
bc_log("src[r%u] store_address[r%u, %llx] value_written[0x%llx|%lld|%f]", instr->index_a, instr->index_c, store_address, *store_address, *store_address, *store_address);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_LOAD_FROM_MEMORY32:{
|
||||
U32 *load_address = R(instr->index_a).pointer_u32;
|
||||
R(instr->index_c).u32 = *load_address;
|
||||
@@ -437,7 +479,7 @@ run_bytecode_interp(Bc *b){
|
||||
*store_address = R(instr->index_a).u32;
|
||||
bc_log("src[r%u] store_address[r%u, %llx] value_written[0x%llx|%lld|%f]", instr->index_a, instr->index_c, store_address, *store_address, *store_address, *store_address);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_LOAD_FROM_MEMORY16:{
|
||||
U16 *load_address = R(instr->index_a).pointer_u16;
|
||||
R(instr->index_c).u16 = *load_address;
|
||||
@@ -449,7 +491,7 @@ run_bytecode_interp(Bc *b){
|
||||
*store_address = R(instr->index_a).u16;
|
||||
bc_log("src[r%u] store_address[r%u, %llx] value_written[0x%llx|%lld|%f]", instr->index_a, instr->index_c, store_address, *store_address, *store_address, *store_address);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_LOAD_FROM_MEMORY8:{
|
||||
U8 *load_address = R(instr->index_a).pointer_u8;
|
||||
R(instr->index_c).u8 = *load_address;
|
||||
@@ -461,7 +503,7 @@ run_bytecode_interp(Bc *b){
|
||||
*store_address = R(instr->index_a).u8;
|
||||
bc_log("src[r%u] store_address[r%u, %llx] value_written[0x%llx|%lld|%f]", instr->index_a, instr->index_c, store_address, *store_address, *store_address, *store_address);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_ADD_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -469,7 +511,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] + [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_SUB_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -477,7 +519,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] - [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_DIV_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -485,7 +527,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] / [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_MUL_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -493,7 +535,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] * [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_MOD_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -501,7 +543,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] % [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_SHR_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -509,7 +551,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] >> [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_SHL_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -517,7 +559,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] << [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_BITAND_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -525,7 +567,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] & [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_BITOR_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -533,7 +575,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] | [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_BITXOR_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -541,7 +583,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] ^ [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_BITNOT_S64:{
|
||||
S64 left = (S64)R(instr->index_a).s64;
|
||||
S64 result = ~left;
|
||||
@@ -549,7 +591,7 @@ run_bytecode_interp(Bc *b){
|
||||
*dst = result;
|
||||
bc_log("~ [%lld] = [%lld]", left, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_EQ_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -557,7 +599,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] == [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_NEQ_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -565,7 +607,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] != [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_GT_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -573,7 +615,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] > [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_LT_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -581,7 +623,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] < [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_OR_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -589,7 +631,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] || [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_GTE_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -597,7 +639,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] >= [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_LTE_S64:{
|
||||
S64 left = R(instr->index_a).s64;
|
||||
S64 right = R(instr->index_b).s64;
|
||||
@@ -605,7 +647,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).s64 = result;
|
||||
bc_log("[r%s, %lld] <= [r%s, %lld] = [r%s, %lld]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_ADD_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -613,7 +655,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] + [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_SUB_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -621,7 +663,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] - [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_DIV_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -629,7 +671,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] / [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_MUL_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -637,7 +679,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] * [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_MOD_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -645,7 +687,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] % [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_SHR_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -653,7 +695,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] >> [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_SHL_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -661,7 +703,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] << [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_BITAND_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -669,7 +711,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] & [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_BITOR_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -677,7 +719,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] | [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_BITXOR_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -685,7 +727,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] ^ [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_BITNOT_U64:{
|
||||
U64 left = (U64)R(instr->index_a).u64;
|
||||
U64 result = ~left;
|
||||
@@ -693,7 +735,7 @@ run_bytecode_interp(Bc *b){
|
||||
*dst = result;
|
||||
bc_log("~ [%llu] = [%llu]", left, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_EQ_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -701,7 +743,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] == [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_NEQ_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -709,7 +751,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] != [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_GT_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -717,7 +759,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] > [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_LT_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -725,7 +767,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] < [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_OR_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -733,7 +775,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] || [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_GTE_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -741,7 +783,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] >= [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_LTE_U64:{
|
||||
U64 left = R(instr->index_a).u64;
|
||||
U64 right = R(instr->index_b).u64;
|
||||
@@ -749,7 +791,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).u64 = result;
|
||||
bc_log("[r%s, %llu] <= [r%s, %llu] = [r%s, %llu]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_ADD_F64:{
|
||||
F64 left = R(instr->index_a).f64;
|
||||
F64 right = R(instr->index_b).f64;
|
||||
@@ -757,7 +799,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).f64 = result;
|
||||
bc_log("[r%s, %f] + [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_SUB_F64:{
|
||||
F64 left = R(instr->index_a).f64;
|
||||
F64 right = R(instr->index_b).f64;
|
||||
@@ -765,7 +807,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).f64 = result;
|
||||
bc_log("[r%s, %f] - [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_DIV_F64:{
|
||||
F64 left = R(instr->index_a).f64;
|
||||
F64 right = R(instr->index_b).f64;
|
||||
@@ -773,7 +815,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).f64 = result;
|
||||
bc_log("[r%s, %f] / [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_MUL_F64:{
|
||||
F64 left = R(instr->index_a).f64;
|
||||
F64 right = R(instr->index_b).f64;
|
||||
@@ -781,7 +823,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).f64 = result;
|
||||
bc_log("[r%s, %f] * [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_EQ_F64:{
|
||||
F64 left = R(instr->index_a).f64;
|
||||
F64 right = R(instr->index_b).f64;
|
||||
@@ -789,7 +831,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).f64 = result;
|
||||
bc_log("[r%s, %f] == [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_NEQ_F64:{
|
||||
F64 left = R(instr->index_a).f64;
|
||||
F64 right = R(instr->index_b).f64;
|
||||
@@ -797,7 +839,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).f64 = result;
|
||||
bc_log("[r%s, %f] != [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_GT_F64:{
|
||||
F64 left = R(instr->index_a).f64;
|
||||
F64 right = R(instr->index_b).f64;
|
||||
@@ -805,7 +847,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).f64 = result;
|
||||
bc_log("[r%s, %f] > [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_LT_F64:{
|
||||
F64 left = R(instr->index_a).f64;
|
||||
F64 right = R(instr->index_b).f64;
|
||||
@@ -813,7 +855,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).f64 = result;
|
||||
bc_log("[r%s, %f] < [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_GTE_F64:{
|
||||
F64 left = R(instr->index_a).f64;
|
||||
F64 right = R(instr->index_b).f64;
|
||||
@@ -821,7 +863,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).f64 = result;
|
||||
bc_log("[r%s, %f] >= [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
case BC_LTE_F64:{
|
||||
F64 left = R(instr->index_a).f64;
|
||||
F64 right = R(instr->index_b).f64;
|
||||
@@ -829,7 +871,7 @@ run_bytecode_interp(Bc *b){
|
||||
R(instr->index_c).f64 = result;
|
||||
bc_log("[r%s, %f] <= [r%s, %f] = [r%s, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
||||
}break;
|
||||
|
||||
|
||||
//
|
||||
// *End* of switch_cases generated using code_generating_script.py
|
||||
//
|
||||
|
||||
@@ -14,6 +14,10 @@ def should_skip(T, op):
|
||||
and op != "GT" and op != "LT" and op != "GTE" and op != "LTE":
|
||||
return True
|
||||
|
||||
# This function inserts generated code into the specified file
|
||||
# it requires a specific comment to be triggered.
|
||||
# Lossing data would be terrible so we also backup that file
|
||||
# in case something bad happens
|
||||
def update_file(filename, comment_name, data_to_write):
|
||||
begin = f"""//
|
||||
// *Begin* of {comment_name} generated using code_generating_script.py
|
||||
@@ -55,13 +59,15 @@ def update_file(filename, comment_name, data_to_write):
|
||||
|
||||
if True:
|
||||
result = ""
|
||||
enum_members = []
|
||||
enum_members.append("BC_END_OF_INSTRUCTIONS")
|
||||
enum_members.append("BC_POP_STACK")
|
||||
enum_members.append("BC_PUSH_STACK")
|
||||
enum_members.append("BC_LOAD_CONSTANT")
|
||||
enum_members.append("BC_STORE_CONSTANT")
|
||||
enum_members.append("BC_CALL")
|
||||
enum_members = [
|
||||
"BC_END_OF_INSTRUCTIONS",
|
||||
"BC_POP_STACK",
|
||||
"BC_PUSH_STACK",
|
||||
"BC_LOAD_CONSTANT",
|
||||
"BC_STORE_CONSTANT",
|
||||
"BC_CALL",
|
||||
"BC_CALL_RETURN",
|
||||
]
|
||||
|
||||
load_store = ["LOAD_FROM_MEMORY", "STORE_TO_MEMORY"]
|
||||
for op in load_store:
|
||||
|
||||
Reference in New Issue
Block a user