Compare commits
4 Commits
d9013fcbee
...
5da83ee565
| Author | SHA1 | Date | |
|---|---|---|---|
| 5da83ee565 | |||
| 29b1218b0b | |||
| 4042cc77b6 | |||
| bd6afe1773 |
2
Makefile
2
Makefile
@ -159,7 +159,7 @@ UNITTEST_OBJECTS = $(UNITTEST_SOURCES:.c=.o)
|
||||
TEST_UNITTEST_DEMO_SOURCES = tests/test_unittest_demo.c
|
||||
TEST_UNITTEST_DEMO_OBJECTS = $(TEST_UNITTEST_DEMO_SOURCES:.c=.o)
|
||||
|
||||
all: test_lexer test_parser test_semantic test_ir test_runtime test_strings test_arrays test_objects test_instance_methods test_fileio test_dowhile test_switch test_math test_string_methods test_static test_interfaces test_exceptions test_ternary test_bitwise test_enhanced_for test_array_init test_instanceof test_shortcircuit test_multidim_arrays test_static_init test_negative test_enums test_collections test_super test_inheritance test_break test_elseif test_forloop test_println test_loader test_object_methods test_autobox test_sockets test_method_ref test_gc
|
||||
all: rava test_lexer test_parser test_semantic test_ir test_runtime test_strings test_arrays test_objects test_instance_methods test_fileio test_dowhile test_switch test_math test_string_methods test_static test_interfaces test_exceptions test_ternary test_bitwise test_enhanced_for test_array_init test_instanceof test_shortcircuit test_multidim_arrays test_static_init test_negative test_enums test_collections test_super test_inheritance test_break test_elseif test_forloop test_println test_loader test_object_methods test_autobox test_sockets test_method_ref test_gc
|
||||
|
||||
test_lexer: $(LEXER_OBJECTS) $(UNITTEST_OBJECTS) $(TEST_LEXER_OBJECTS)
|
||||
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
1
ir/ir.c
1
ir/ir.c
@ -338,6 +338,7 @@ static const char* _rava_opcode_name(RavaOpCode_e opcode) {
|
||||
case RAVA_OP_SOCKET_GET_REUSE_ADDRESS: return "SOCKET_GET_REUSE_ADDRESS";
|
||||
case RAVA_OP_METHOD_REF: return "METHOD_REF";
|
||||
case RAVA_OP_METHOD_REF_INVOKE: return "METHOD_REF_INVOKE";
|
||||
case RAVA_OP_ARRAY_CMP_SWAP_INT: return "ARRAY_CMP_SWAP_INT";
|
||||
default: return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
5
ir/ir.h
5
ir/ir.h
@ -113,6 +113,7 @@ typedef enum {
|
||||
RAVA_OP_LOAD_TWO_LOCALS,
|
||||
RAVA_OP_ADD_LOCAL_TO_LOCAL,
|
||||
RAVA_OP_LOAD_LOCAL_LT_LOCAL_JUMPFALSE,
|
||||
RAVA_OP_ARRAY_CMP_SWAP_INT,
|
||||
|
||||
RAVA_OP_MATH_ABS,
|
||||
RAVA_OP_MATH_SQRT,
|
||||
@ -263,6 +264,10 @@ typedef union {
|
||||
bool is_constructor;
|
||||
bool is_static;
|
||||
} method_ref;
|
||||
struct {
|
||||
int array_local;
|
||||
int index_local;
|
||||
} array_cmp_swap;
|
||||
} RavaOperand_u;
|
||||
|
||||
typedef struct {
|
||||
|
||||
27
ir/ir_gen.c
27
ir/ir_gen.c
@ -255,6 +255,17 @@ static void _rava_ir_gen_expression(RavaIRGenerator_t *gen, RavaASTNode_t *expr)
|
||||
strcmp(index_name, gen->loop_context->loop_var_name) == 0) {
|
||||
use_unchecked = true;
|
||||
}
|
||||
} else if (index_node->type == RAVA_AST_BINARY_EXPR &&
|
||||
(index_node->data.binary.op == RAVA_BINOP_ADD ||
|
||||
index_node->data.binary.op == RAVA_BINOP_SUB)) {
|
||||
RavaASTNode_t *left = index_node->data.binary.left;
|
||||
RavaASTNode_t *right = index_node->data.binary.right;
|
||||
if (left->type == RAVA_AST_IDENTIFIER_EXPR &&
|
||||
right->type == RAVA_AST_LITERAL_EXPR &&
|
||||
gen->loop_context->loop_var_name &&
|
||||
strcmp(left->data.identifier.name, gen->loop_context->loop_var_name) == 0) {
|
||||
use_unchecked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,12 +334,24 @@ static void _rava_ir_gen_expression(RavaIRGenerator_t *gen, RavaASTNode_t *expr)
|
||||
|
||||
bool use_unchecked = false;
|
||||
if (gen->loop_context && gen->loop_context->has_bounds_check) {
|
||||
if (expr->data.array_access.index->type == RAVA_AST_IDENTIFIER_EXPR) {
|
||||
const char *index_name = expr->data.array_access.index->data.identifier.name;
|
||||
RavaASTNode_t *index_node = expr->data.array_access.index;
|
||||
if (index_node->type == RAVA_AST_IDENTIFIER_EXPR) {
|
||||
const char *index_name = index_node->data.identifier.name;
|
||||
if (gen->loop_context->loop_var_name &&
|
||||
strcmp(index_name, gen->loop_context->loop_var_name) == 0) {
|
||||
use_unchecked = true;
|
||||
}
|
||||
} else if (index_node->type == RAVA_AST_BINARY_EXPR &&
|
||||
(index_node->data.binary.op == RAVA_BINOP_ADD ||
|
||||
index_node->data.binary.op == RAVA_BINOP_SUB)) {
|
||||
RavaASTNode_t *left = index_node->data.binary.left;
|
||||
RavaASTNode_t *right = index_node->data.binary.right;
|
||||
if (left->type == RAVA_AST_IDENTIFIER_EXPR &&
|
||||
right->type == RAVA_AST_LITERAL_EXPR &&
|
||||
gen->loop_context->loop_var_name &&
|
||||
strcmp(left->data.identifier.name, gen->loop_context->loop_var_name) == 0) {
|
||||
use_unchecked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3321,6 +3321,7 @@ bool _rava_vm_execute_ultrafast(RavaVM_t *vm, RavaMethod_t *entry_method) {
|
||||
&&uf_load_local_const_add, &&uf_load_local_const_lt_jumpfalse,
|
||||
&&uf_load_local_const_le_jumpfalse, &&uf_load_two_locals,
|
||||
&&uf_add_local_to_local, &&uf_load_local_lt_local_jumpfalse,
|
||||
&&uf_array_cmp_swap_int,
|
||||
&&uf_math_abs, &&uf_math_sqrt, &&uf_math_pow, &&uf_math_min, &&uf_math_max,
|
||||
&&uf_math_floor, &&uf_math_ceil, &&uf_math_round,
|
||||
&&uf_math_sin, &&uf_math_cos, &&uf_math_tan, &&uf_math_log, &&uf_math_exp,
|
||||
@ -3935,10 +3936,10 @@ uf_load_array_unchecked: {
|
||||
RavaArray_t *arr = rava_nanbox_as_array(arr_val);
|
||||
size_t i = (size_t)rava_nanbox_to_int(idx);
|
||||
if (arr->element_type == RAVA_VAL_ARRAY || arr->element_type == RAVA_VAL_OBJECT) {
|
||||
RavaValue_t v = rava_array_get_value(arr, i);
|
||||
RavaValue_t v = ((RavaValue_t*)arr->data)[i];
|
||||
UF_PUSH(rava_value_to_nanbox(v));
|
||||
} else {
|
||||
int64_t val = rava_array_get_int(arr, i);
|
||||
int64_t val = ((int64_t*)arr->data)[i];
|
||||
UF_PUSH(rava_nanbox_int(val));
|
||||
}
|
||||
UF_DISPATCH();
|
||||
@ -3967,9 +3968,9 @@ uf_store_array_unchecked: {
|
||||
RavaArray_t *arr = rava_nanbox_as_array(arr_val);
|
||||
size_t i = (size_t)rava_nanbox_to_int(idx);
|
||||
if (arr->element_type == RAVA_VAL_ARRAY || arr->element_type == RAVA_VAL_OBJECT) {
|
||||
rava_array_set_value(arr, i, rava_nanbox_to_value(val));
|
||||
((RavaValue_t*)arr->data)[i] = rava_nanbox_to_value(val);
|
||||
} else {
|
||||
rava_array_set_int(arr, i, rava_nanbox_to_int(val));
|
||||
((int64_t*)arr->data)[i] = rava_nanbox_to_int(val);
|
||||
}
|
||||
UF_DISPATCH();
|
||||
}
|
||||
@ -4479,6 +4480,23 @@ uf_load_local_lt_local_jumpfalse: {
|
||||
UF_DISPATCH();
|
||||
}
|
||||
|
||||
uf_array_cmp_swap_int: {
|
||||
int array_local = instr->operand.array_cmp_swap.array_local;
|
||||
int index_local = instr->operand.array_cmp_swap.index_local;
|
||||
RavaNanboxValue_t arr_val = frame->locals[array_local];
|
||||
RavaNanboxValue_t idx_val = frame->locals[index_local];
|
||||
RavaArray_t *arr = rava_nanbox_as_array(arr_val);
|
||||
size_t i = (size_t)rava_nanbox_to_int(idx_val);
|
||||
int64_t *data = (int64_t*)arr->data;
|
||||
int64_t v1 = data[i];
|
||||
int64_t v2 = data[i + 1];
|
||||
if (v1 > v2) {
|
||||
data[i] = v2;
|
||||
data[i + 1] = v1;
|
||||
}
|
||||
UF_DISPATCH();
|
||||
}
|
||||
|
||||
uf_math_abs: {
|
||||
RavaNanboxValue_t val = UF_POP();
|
||||
if (rava_nanbox_is_double(val)) {
|
||||
|
||||
@ -101,3 +101,19 @@ size_t rava_array_length(RavaArray_t *array) {
|
||||
if (!array) return 0;
|
||||
return array->length;
|
||||
}
|
||||
|
||||
static inline void rava_array_set_int_unchecked(RavaArray_t *array, size_t index, int64_t value) {
|
||||
((int64_t*)array->data)[index] = value;
|
||||
}
|
||||
|
||||
static inline int64_t rava_array_get_int_unchecked(RavaArray_t *array, size_t index) {
|
||||
return ((int64_t*)array->data)[index];
|
||||
}
|
||||
|
||||
static inline void rava_array_set_value_unchecked(RavaArray_t *array, size_t index, RavaValue_t value) {
|
||||
((RavaValue_t*)array->data)[index] = value;
|
||||
}
|
||||
|
||||
static inline RavaValue_t rava_array_get_value_unchecked(RavaArray_t *array, size_t index) {
|
||||
return ((RavaValue_t*)array->data)[index];
|
||||
}
|
||||
|
||||
@ -269,6 +269,11 @@ static void optimize_inline_calls(RavaInstruction_t *instrs, size_t count) {
|
||||
}
|
||||
}
|
||||
|
||||
static void optimize_array_cmp_swap(RavaInstruction_t *instrs, size_t count) {
|
||||
(void)instrs;
|
||||
(void)count;
|
||||
}
|
||||
|
||||
void rava_optimize_superinstructions(RavaMethod_t* method) {
|
||||
if (!method || !method->instructions) return;
|
||||
|
||||
@ -278,6 +283,7 @@ void rava_optimize_superinstructions(RavaMethod_t* method) {
|
||||
optimize_constant_folding(instrs, count);
|
||||
optimize_inline_calls(instrs, count);
|
||||
optimize_strength_reduction(instrs, count);
|
||||
optimize_array_cmp_swap(instrs, count);
|
||||
optimize_add_local_to_local(instrs, count);
|
||||
optimize_local_lt_local_jump(instrs, count);
|
||||
optimize_inc_dec_local(instrs, count);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user