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:
2025-12-04 05:14:22 +00:00
parent e768ed066c
commit ed69521892
18 changed files with 930 additions and 236 deletions
+11 -4
View File
@@ -1,11 +1,13 @@
#define _POSIX_C_SOURCE 200809L
#include "parser.h"
#include "../utils/safe_alloc.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
RavaASTNode_t* rava_ast_node_create(RavaASTNodeType_e type, int line, int column) {
RavaASTNode_t *node = calloc(1, sizeof(RavaASTNode_t));
if (!node) return NULL;
node->type = type;
node->line = line;
node->column = column;
@@ -81,7 +83,9 @@ void rava_ast_node_add_child(RavaASTNode_t *parent, RavaASTNode_t *child) {
if (parent->children_count >= parent->children_capacity) {
size_t new_capacity = parent->children_capacity == 0 ? 4 : parent->children_capacity * 2;
parent->children = realloc(parent->children, sizeof(RavaASTNode_t*) * new_capacity);
RavaASTNode_t **new_children = rava_safe_realloc(parent->children, sizeof(RavaASTNode_t*) * new_capacity);
if (!new_children) return;
parent->children = new_children;
parent->children_capacity = new_capacity;
}
@@ -91,6 +95,7 @@ void rava_ast_node_add_child(RavaASTNode_t *parent, RavaASTNode_t *child) {
RavaParser_t* rava_parser_create(RavaLexer_t *lexer) {
RavaParser_t *parser = malloc(sizeof(RavaParser_t));
if (!parser) return NULL;
parser->lexer = lexer;
parser->current_token = rava_lexer_next_token(lexer);
parser->peek_token = rava_lexer_next_token(lexer);
@@ -134,9 +139,11 @@ bool _rava_parser_expect(RavaParser_t *parser, RavaTokenType_e type, const char
parser->had_error = true;
if (parser->error_message) free(parser->error_message);
parser->error_message = malloc(256);
snprintf(parser->error_message, 256, "%s at line %d, column %d",
message, parser->current_token->line, parser->current_token->column);
parser->error_message = malloc(RAVA_ERROR_BUFFER_SIZE);
if (parser->error_message) {
snprintf(parser->error_message, RAVA_ERROR_BUFFER_SIZE, "%s at line %d, column %d",
message, parser->current_token->line, parser->current_token->column);
}
return false;
}
+11 -1
View File
@@ -1,5 +1,6 @@
#define _POSIX_C_SOURCE 200809L
#include "parser.h"
#include "../utils/safe_alloc.h"
#include <stdlib.h>
#include <string.h>
@@ -96,13 +97,22 @@ RavaASTNode_t* _rava_parser_parse_class_declaration(RavaParser_t *parser) {
if (_rava_parser_match(parser, RAVA_TOKEN_KEYWORD_IMPLEMENTS)) {
size_t capacity = 4;
class_decl->data.class_decl.interfaces = malloc(capacity * sizeof(char*));
if (!class_decl->data.class_decl.interfaces) {
parser->had_error = true;
return NULL;
}
do {
if (_rava_parser_check(parser, RAVA_TOKEN_IDENTIFIER)) {
if (class_decl->data.class_decl.interfaces_count >= capacity) {
capacity *= 2;
class_decl->data.class_decl.interfaces = realloc(
char **new_interfaces = rava_safe_realloc(
class_decl->data.class_decl.interfaces,
capacity * sizeof(char*));
if (!new_interfaces) {
parser->had_error = true;
return NULL;
}
class_decl->data.class_decl.interfaces = new_interfaces;
}
class_decl->data.class_decl.interfaces[class_decl->data.class_decl.interfaces_count++] =
strdup(parser->current_token->lexeme);
+45 -8
View File
@@ -1,5 +1,6 @@
#define _POSIX_C_SOURCE 200809L
#include "parser.h"
#include "../utils/safe_alloc.h"
#include <stdlib.h>
#include <string.h>
@@ -97,6 +98,10 @@ static RavaASTNode_t* _rava_parser_parse_primary(RavaParser_t *parser) {
if (_rava_parser_match(parser, RAVA_TOKEN_LBRACKET)) {
size_t args_capacity = 4;
node->data.new_expr.arguments = malloc(sizeof(RavaASTNode_t*) * args_capacity);
if (!node->data.new_expr.arguments) {
parser->had_error = true;
return NULL;
}
node->data.new_expr.arguments_count = 0;
if (!_rava_parser_check(parser, RAVA_TOKEN_RBRACKET)) {
@@ -108,8 +113,13 @@ static RavaASTNode_t* _rava_parser_parse_primary(RavaParser_t *parser) {
while (_rava_parser_match(parser, RAVA_TOKEN_LBRACKET)) {
if (node->data.new_expr.arguments_count >= args_capacity) {
args_capacity *= 2;
node->data.new_expr.arguments = realloc(node->data.new_expr.arguments,
sizeof(RavaASTNode_t*) * args_capacity);
RavaASTNode_t **new_args = rava_safe_realloc(node->data.new_expr.arguments,
sizeof(RavaASTNode_t*) * args_capacity);
if (!new_args) {
parser->had_error = true;
return NULL;
}
node->data.new_expr.arguments = new_args;
}
if (!_rava_parser_check(parser, RAVA_TOKEN_RBRACKET)) {
node->data.new_expr.arguments[node->data.new_expr.arguments_count++] =
@@ -129,14 +139,23 @@ static RavaASTNode_t* _rava_parser_parse_primary(RavaParser_t *parser) {
size_t args_capacity = 4;
node->data.new_expr.arguments = malloc(sizeof(RavaASTNode_t*) * args_capacity);
if (!node->data.new_expr.arguments) {
parser->had_error = true;
return NULL;
}
node->data.new_expr.arguments_count = 0;
if (!_rava_parser_check(parser, RAVA_TOKEN_RPAREN)) {
do {
if (node->data.new_expr.arguments_count >= args_capacity) {
args_capacity *= 2;
node->data.new_expr.arguments = realloc(node->data.new_expr.arguments,
sizeof(RavaASTNode_t*) * args_capacity);
RavaASTNode_t **new_args = rava_safe_realloc(node->data.new_expr.arguments,
sizeof(RavaASTNode_t*) * args_capacity);
if (!new_args) {
parser->had_error = true;
return NULL;
}
node->data.new_expr.arguments = new_args;
}
node->data.new_expr.arguments[node->data.new_expr.arguments_count++] =
_rava_parser_parse_expression(parser);
@@ -173,14 +192,23 @@ static RavaASTNode_t* _rava_parser_parse_postfix(RavaParser_t *parser) {
size_t args_capacity = 4;
call->data.call.arguments = malloc(sizeof(RavaASTNode_t*) * args_capacity);
if (!call->data.call.arguments) {
parser->had_error = true;
return NULL;
}
call->data.call.arguments_count = 0;
if (!_rava_parser_check(parser, RAVA_TOKEN_RPAREN)) {
do {
if (call->data.call.arguments_count >= args_capacity) {
args_capacity *= 2;
call->data.call.arguments = realloc(call->data.call.arguments,
sizeof(RavaASTNode_t*) * args_capacity);
RavaASTNode_t **new_args = rava_safe_realloc(call->data.call.arguments,
sizeof(RavaASTNode_t*) * args_capacity);
if (!new_args) {
parser->had_error = true;
return NULL;
}
call->data.call.arguments = new_args;
}
call->data.call.arguments[call->data.call.arguments_count++] =
_rava_parser_parse_expression(parser);
@@ -576,14 +604,23 @@ RavaASTNode_t* _rava_parser_parse_array_initializer(RavaParser_t *parser) {
size_t capacity = 8;
node->data.array_init.elements = malloc(sizeof(RavaASTNode_t*) * capacity);
if (!node->data.array_init.elements) {
parser->had_error = true;
return NULL;
}
node->data.array_init.elements_count = 0;
if (!_rava_parser_check(parser, RAVA_TOKEN_RBRACE)) {
do {
if (node->data.array_init.elements_count >= capacity) {
capacity *= 2;
node->data.array_init.elements = realloc(node->data.array_init.elements,
sizeof(RavaASTNode_t*) * capacity);
RavaASTNode_t **new_elements = rava_safe_realloc(node->data.array_init.elements,
sizeof(RavaASTNode_t*) * capacity);
if (!new_elements) {
parser->had_error = true;
return NULL;
}
node->data.array_init.elements = new_elements;
}
node->data.array_init.elements[node->data.array_init.elements_count++] =
_rava_parser_parse_expression(parser);