|
|
|
|
@@ -184,13 +184,12 @@ struct Call_Frame{
|
|
|
|
|
Call_Frame *previous_call;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
U8 *stack_bottom;
|
|
|
|
|
U8 *stack_base;
|
|
|
|
|
U8 *stack_pointer;
|
|
|
|
|
U8 *stack_top;
|
|
|
|
|
|
|
|
|
|
@@ -225,6 +224,8 @@ allocate_register(Bc *b){
|
|
|
|
|
|
|
|
|
|
function void
|
|
|
|
|
release_register(Bc *b, Register_Index reg){
|
|
|
|
|
if(reg == -1) return;
|
|
|
|
|
|
|
|
|
|
B32 found = false;
|
|
|
|
|
For(b->used_registers){
|
|
|
|
|
if(it == reg){
|
|
|
|
|
@@ -306,6 +307,7 @@ emit_load_constant(Bc *b, Token *pos, Register_Index dst, Value value){
|
|
|
|
|
CASE_UINT: i->constant.u64 = bigint_as_unsigned(&value.big_int_val); break;
|
|
|
|
|
CASE_SINT: i->constant.s64 = bigint_as_signed(&value.big_int_val); break;
|
|
|
|
|
CASE_FLOAT: i->constant.f64 = value.f64_val; break;
|
|
|
|
|
case TYPE_TYPE: i->constant.u64 = value.type_val->type_id; break;
|
|
|
|
|
invalid_default_case;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -313,6 +315,16 @@ emit_load_constant(Bc *b, Token *pos, Register_Index dst, Value value){
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Instruction *
|
|
|
|
|
emit_load_constant_address(Bc *b, Token *pos, Register_Index dst, void *address){
|
|
|
|
|
auto i = new_instruction(b, pos);
|
|
|
|
|
i->operation = BC_LOAD_CONSTANT;
|
|
|
|
|
i->index_c = dst;
|
|
|
|
|
i->constant.u64 = (U64)address;
|
|
|
|
|
i->debug_type_flag = TYPE_POINTER;
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function void
|
|
|
|
|
emit_push(Bc *b, Token *pos, Register_Index src){
|
|
|
|
|
auto i = new_instruction(b, pos);
|
|
|
|
|
@@ -364,11 +376,11 @@ bc_stack_push_size(Bc *b, U64 size){
|
|
|
|
|
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->first_register_index_in_window = function_address_register;
|
|
|
|
|
call->previous_call = b->top_call;
|
|
|
|
|
call->saved_instruction_pointer = 0;
|
|
|
|
|
|
|
|
|
|
b->stack_pointer = b->stack_base = (U8 *)(call+1);
|
|
|
|
|
b->top_call = call;
|
|
|
|
|
return call;
|
|
|
|
|
}
|
|
|
|
|
@@ -376,7 +388,7 @@ bc_push_call_frame(Bc *b, Register_Index function_address_register){
|
|
|
|
|
function void
|
|
|
|
|
run_bytecode_interp(Bc *b){
|
|
|
|
|
b->instruction_pointer = (Instruction *)b->instructions.memory.data;
|
|
|
|
|
b->stack_pointer = b->stack_bottom = b->stack.memory.data;
|
|
|
|
|
b->stack_pointer = b->stack_base = b->stack.memory.data;
|
|
|
|
|
b->stack_top = (b->stack.memory.data + b->stack.len);
|
|
|
|
|
bc_push_call_frame(b, 0);
|
|
|
|
|
|
|
|
|
|
@@ -386,7 +398,7 @@ run_bytecode_interp(Bc *b){
|
|
|
|
|
#if BC_ASSERTS
|
|
|
|
|
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->stack_pointer >= b->stack_base, "Bytecode stack underflow");
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
@@ -435,6 +447,8 @@ run_bytecode_interp(Bc *b){
|
|
|
|
|
Call_Frame *prev = call->previous_call;
|
|
|
|
|
assert(prev);
|
|
|
|
|
|
|
|
|
|
b->stack_base = (U8 *)(prev + 1);
|
|
|
|
|
b->stack_pointer = (U8 *)call;
|
|
|
|
|
b->top_call = prev;
|
|
|
|
|
}break;
|
|
|
|
|
|
|
|
|
|
@@ -456,7 +470,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;
|
|
|
|
|
@@ -468,7 +482,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;
|
|
|
|
|
@@ -480,7 +494,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;
|
|
|
|
|
@@ -492,87 +506,87 @@ 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;
|
|
|
|
|
S64 result = left + right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] + [r%d, %lld] = [r%d, %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;
|
|
|
|
|
S64 result = left - right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] - [r%d, %lld] = [r%d, %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;
|
|
|
|
|
S64 result = left / right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] / [r%d, %lld] = [r%d, %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;
|
|
|
|
|
S64 result = left * right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] * [r%d, %lld] = [r%d, %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;
|
|
|
|
|
S64 result = left % right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] % [r%d, %lld] = [r%d, %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;
|
|
|
|
|
S64 result = left >> right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] >> [r%d, %lld] = [r%d, %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;
|
|
|
|
|
S64 result = left << right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] << [r%d, %lld] = [r%d, %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;
|
|
|
|
|
S64 result = left & right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] & [r%d, %lld] = [r%d, %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;
|
|
|
|
|
S64 result = left | right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] | [r%d, %lld] = [r%d, %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;
|
|
|
|
|
S64 result = left ^ right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] ^ [r%d, %lld] = [r%d, %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;
|
|
|
|
|
@@ -580,143 +594,143 @@ 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;
|
|
|
|
|
S64 result = left == right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] == [r%d, %lld] = [r%d, %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;
|
|
|
|
|
S64 result = left != right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] != [r%d, %lld] = [r%d, %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;
|
|
|
|
|
S64 result = left > right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] > [r%d, %lld] = [r%d, %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;
|
|
|
|
|
S64 result = left < right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] < [r%d, %lld] = [r%d, %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;
|
|
|
|
|
S64 result = left || right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] || [r%d, %lld] = [r%d, %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;
|
|
|
|
|
S64 result = left >= right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] >= [r%d, %lld] = [r%d, %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;
|
|
|
|
|
S64 result = left <= right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %lld] <= [r%d, %lld] = [r%d, %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;
|
|
|
|
|
U64 result = left + right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] + [r%d, %llu] = [r%d, %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;
|
|
|
|
|
U64 result = left - right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] - [r%d, %llu] = [r%d, %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;
|
|
|
|
|
U64 result = left / right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] / [r%d, %llu] = [r%d, %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;
|
|
|
|
|
U64 result = left * right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] * [r%d, %llu] = [r%d, %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;
|
|
|
|
|
U64 result = left % right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] % [r%d, %llu] = [r%d, %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;
|
|
|
|
|
U64 result = left >> right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] >> [r%d, %llu] = [r%d, %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;
|
|
|
|
|
U64 result = left << right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] << [r%d, %llu] = [r%d, %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;
|
|
|
|
|
U64 result = left & right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] & [r%d, %llu] = [r%d, %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;
|
|
|
|
|
U64 result = left | right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] | [r%d, %llu] = [r%d, %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;
|
|
|
|
|
U64 result = left ^ right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] ^ [r%d, %llu] = [r%d, %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;
|
|
|
|
|
@@ -724,143 +738,143 @@ 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;
|
|
|
|
|
U64 result = left == right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] == [r%d, %llu] = [r%d, %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;
|
|
|
|
|
U64 result = left != right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] != [r%d, %llu] = [r%d, %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;
|
|
|
|
|
U64 result = left > right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] > [r%d, %llu] = [r%d, %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;
|
|
|
|
|
U64 result = left < right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] < [r%d, %llu] = [r%d, %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;
|
|
|
|
|
U64 result = left || right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] || [r%d, %llu] = [r%d, %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;
|
|
|
|
|
U64 result = left >= right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] >= [r%d, %llu] = [r%d, %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;
|
|
|
|
|
U64 result = left <= right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %llu] <= [r%d, %llu] = [r%d, %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;
|
|
|
|
|
F64 result = left + right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %f] + [r%d, %f] = [r%d, %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;
|
|
|
|
|
F64 result = left - right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %f] - [r%d, %f] = [r%d, %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;
|
|
|
|
|
F64 result = left / right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %f] / [r%d, %f] = [r%d, %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;
|
|
|
|
|
F64 result = left * right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %f] * [r%d, %f] = [r%d, %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;
|
|
|
|
|
F64 result = left == right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %f] == [r%d, %f] = [r%d, %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;
|
|
|
|
|
F64 result = left != right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %f] != [r%d, %f] = [r%d, %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;
|
|
|
|
|
F64 result = left > right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %f] > [r%d, %f] = [r%d, %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;
|
|
|
|
|
F64 result = left < right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %f] < [r%d, %f] = [r%d, %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;
|
|
|
|
|
F64 result = left >= right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %f] >= [r%d, %f] = [r%d, %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;
|
|
|
|
|
F64 result = left <= right;
|
|
|
|
|
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);
|
|
|
|
|
bc_log("[r%d, %f] <= [r%d, %f] = [r%d, %f]", instr->index_a, left, instr->index_b, right, instr->index_c, result);
|
|
|
|
|
}break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// *End* of switch_cases generated using code_generating_script.py
|
|
|
|
|
//
|
|
|
|
|
|