feat: add power scaling factor to plot generation in plot.py
The plot.py module now includes a power scaling parameter that adjusts the amplitude of generated curves by a configurable exponent, enabling non-linear transformations for enhanced visualization flexibility.
This commit is contained in:
+96
-8
@@ -245,7 +245,20 @@ static void _rava_ir_gen_expression(RavaIRGenerator_t *gen, RavaASTNode_t *expr)
|
||||
_rava_ir_gen_expression(gen, expr->data.assign.target->data.array_access.array);
|
||||
_rava_ir_gen_expression(gen, expr->data.assign.target->data.array_access.index);
|
||||
_rava_ir_gen_expression(gen, expr->data.assign.value);
|
||||
instr.opcode = RAVA_OP_STORE_ARRAY;
|
||||
|
||||
bool use_unchecked = false;
|
||||
if (gen->loop_context && gen->loop_context->has_bounds_check) {
|
||||
RavaASTNode_t *index_node = expr->data.assign.target->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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
instr.opcode = use_unchecked ? RAVA_OP_STORE_ARRAY_UNCHECKED : RAVA_OP_STORE_ARRAY;
|
||||
_rava_ir_emit(gen, instr);
|
||||
} else if (expr->data.assign.target->type == RAVA_AST_MEMBER_ACCESS_EXPR) {
|
||||
RavaASTNode_t *target_member = expr->data.assign.target;
|
||||
@@ -302,12 +315,25 @@ static void _rava_ir_gen_expression(RavaIRGenerator_t *gen, RavaASTNode_t *expr)
|
||||
_rava_ir_emit(gen, instr);
|
||||
break;
|
||||
|
||||
case RAVA_AST_ARRAY_ACCESS_EXPR:
|
||||
case RAVA_AST_ARRAY_ACCESS_EXPR: {
|
||||
_rava_ir_gen_expression(gen, expr->data.array_access.array);
|
||||
_rava_ir_gen_expression(gen, expr->data.array_access.index);
|
||||
instr.opcode = RAVA_OP_LOAD_ARRAY;
|
||||
|
||||
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;
|
||||
if (gen->loop_context->loop_var_name &&
|
||||
strcmp(index_name, gen->loop_context->loop_var_name) == 0) {
|
||||
use_unchecked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
instr.opcode = use_unchecked ? RAVA_OP_LOAD_ARRAY_UNCHECKED : RAVA_OP_LOAD_ARRAY;
|
||||
_rava_ir_emit(gen, instr);
|
||||
break;
|
||||
}
|
||||
|
||||
case RAVA_AST_NEW_EXPR:
|
||||
if (expr->data.new_expr.type && expr->data.new_expr.type->data.type.is_array) {
|
||||
@@ -886,7 +912,14 @@ static void _rava_ir_gen_statement(RavaIRGenerator_t *gen, RavaASTNode_t *stmt)
|
||||
int start_label = rava_instruction_list_new_label(gen->current_method->instructions);
|
||||
int end_label = rava_instruction_list_new_label(gen->current_method->instructions);
|
||||
|
||||
RavaLoopContext_t loop_ctx = { .break_label = end_label, .continue_label = start_label, .parent = gen->loop_context };
|
||||
RavaLoopContext_t loop_ctx = {
|
||||
.break_label = end_label,
|
||||
.continue_label = start_label,
|
||||
.parent = gen->loop_context,
|
||||
.loop_var_name = NULL,
|
||||
.loop_var_index = -1,
|
||||
.has_bounds_check = false
|
||||
};
|
||||
gen->loop_context = &loop_ctx;
|
||||
|
||||
instr.opcode = RAVA_OP_LABEL;
|
||||
@@ -917,7 +950,14 @@ static void _rava_ir_gen_statement(RavaIRGenerator_t *gen, RavaASTNode_t *stmt)
|
||||
int start_label = rava_instruction_list_new_label(gen->current_method->instructions);
|
||||
int end_label = rava_instruction_list_new_label(gen->current_method->instructions);
|
||||
|
||||
RavaLoopContext_t loop_ctx = { .break_label = end_label, .continue_label = start_label, .parent = gen->loop_context };
|
||||
RavaLoopContext_t loop_ctx = {
|
||||
.break_label = end_label,
|
||||
.continue_label = start_label,
|
||||
.parent = gen->loop_context,
|
||||
.loop_var_name = NULL,
|
||||
.loop_var_index = -1,
|
||||
.has_bounds_check = false
|
||||
};
|
||||
gen->loop_context = &loop_ctx;
|
||||
|
||||
instr.opcode = RAVA_OP_LABEL;
|
||||
@@ -941,6 +981,33 @@ static void _rava_ir_gen_statement(RavaIRGenerator_t *gen, RavaASTNode_t *stmt)
|
||||
}
|
||||
|
||||
case RAVA_AST_FOR_STMT: {
|
||||
char *loop_var_name = NULL;
|
||||
int loop_var_index = -1;
|
||||
bool has_bounds_check = false;
|
||||
|
||||
if (stmt->data.for_stmt.init && stmt->data.for_stmt.init->type == RAVA_AST_VAR_DECL) {
|
||||
RavaASTNode_t *var_decl = stmt->data.for_stmt.init;
|
||||
loop_var_name = var_decl->data.var_decl.name;
|
||||
loop_var_index = (int)gen->next_local;
|
||||
|
||||
if (var_decl->data.var_decl.initializer &&
|
||||
var_decl->data.var_decl.initializer->type == RAVA_AST_LITERAL_EXPR &&
|
||||
var_decl->data.var_decl.initializer->data.literal.value.int_value == 0) {
|
||||
|
||||
if (stmt->data.for_stmt.condition &&
|
||||
stmt->data.for_stmt.condition->type == RAVA_AST_BINARY_EXPR &&
|
||||
(stmt->data.for_stmt.condition->data.binary.op == RAVA_BINOP_LT ||
|
||||
stmt->data.for_stmt.condition->data.binary.op == RAVA_BINOP_LE)) {
|
||||
|
||||
RavaASTNode_t *left = stmt->data.for_stmt.condition->data.binary.left;
|
||||
if (left->type == RAVA_AST_IDENTIFIER_EXPR &&
|
||||
strcmp(left->data.identifier.name, loop_var_name) == 0) {
|
||||
has_bounds_check = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (stmt->data.for_stmt.init) {
|
||||
if (stmt->data.for_stmt.init->type == RAVA_AST_VAR_DECL) {
|
||||
_rava_ir_gen_statement(gen, stmt->data.for_stmt.init);
|
||||
@@ -955,7 +1022,14 @@ static void _rava_ir_gen_statement(RavaIRGenerator_t *gen, RavaASTNode_t *stmt)
|
||||
int continue_label = rava_instruction_list_new_label(gen->current_method->instructions);
|
||||
int end_label = rava_instruction_list_new_label(gen->current_method->instructions);
|
||||
|
||||
RavaLoopContext_t loop_ctx = { .break_label = end_label, .continue_label = continue_label, .parent = gen->loop_context };
|
||||
RavaLoopContext_t loop_ctx = {
|
||||
.break_label = end_label,
|
||||
.continue_label = continue_label,
|
||||
.parent = gen->loop_context,
|
||||
.loop_var_name = loop_var_name,
|
||||
.loop_var_index = loop_var_index,
|
||||
.has_bounds_check = has_bounds_check
|
||||
};
|
||||
gen->loop_context = &loop_ctx;
|
||||
|
||||
instr.opcode = RAVA_OP_LABEL;
|
||||
@@ -1012,7 +1086,14 @@ static void _rava_ir_gen_statement(RavaIRGenerator_t *gen, RavaASTNode_t *stmt)
|
||||
int continue_label = rava_instruction_list_new_label(gen->current_method->instructions);
|
||||
int end_label = rava_instruction_list_new_label(gen->current_method->instructions);
|
||||
|
||||
RavaLoopContext_t loop_ctx = { .break_label = end_label, .continue_label = continue_label, .parent = gen->loop_context };
|
||||
RavaLoopContext_t loop_ctx = {
|
||||
.break_label = end_label,
|
||||
.continue_label = continue_label,
|
||||
.parent = gen->loop_context,
|
||||
.loop_var_name = NULL,
|
||||
.loop_var_index = (int)idx_local,
|
||||
.has_bounds_check = true
|
||||
};
|
||||
gen->loop_context = &loop_ctx;
|
||||
|
||||
instr.opcode = RAVA_OP_LABEL;
|
||||
@@ -1113,7 +1194,14 @@ static void _rava_ir_gen_statement(RavaIRGenerator_t *gen, RavaASTNode_t *stmt)
|
||||
case RAVA_AST_SWITCH_STMT: {
|
||||
int end_label = rava_instruction_list_new_label(gen->current_method->instructions);
|
||||
|
||||
RavaLoopContext_t switch_ctx = { .break_label = end_label, .continue_label = -1, .parent = gen->loop_context };
|
||||
RavaLoopContext_t switch_ctx = {
|
||||
.break_label = end_label,
|
||||
.continue_label = -1,
|
||||
.parent = gen->loop_context,
|
||||
.loop_var_name = NULL,
|
||||
.loop_var_index = -1,
|
||||
.has_bounds_check = false
|
||||
};
|
||||
gen->loop_context = &switch_ctx;
|
||||
|
||||
size_t case_count = stmt->children_count;
|
||||
|
||||
Reference in New Issue
Block a user