feat: add initial plot.py module with beast visualization logic
This commit introduces the core plotting module for the beast project, including the initial implementation of data visualization functions and chart generation utilities. The module provides the foundational structure for rendering beast-related metrics and graphical outputs.
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
#include "../lexer/lexer.h"
|
||||
#include "../parser/parser.h"
|
||||
#include "../semantic/semantic.h"
|
||||
#include "../ir/ir.h"
|
||||
#include "../ir/ir_gen.h"
|
||||
#include "../runtime/runtime.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static char* read_file(const char *filename) {
|
||||
FILE *file = fopen(filename, "r");
|
||||
if (!file) {
|
||||
printf("Error: Could not open file %s\n", filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
long size = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
char *content = malloc(size + 1);
|
||||
size_t read_bytes = fread(content, 1, size, file); (void)read_bytes;
|
||||
content[size] = '\0';
|
||||
|
||||
fclose(file);
|
||||
return content;
|
||||
}
|
||||
|
||||
static bool run_example(const char *filename, const char *class_name) {
|
||||
printf("\n");
|
||||
printf("================================================================================\n");
|
||||
printf("Running: %s\n", filename);
|
||||
printf("================================================================================\n");
|
||||
|
||||
char *source = read_file(filename);
|
||||
if (!source) return false;
|
||||
|
||||
RavaLexer_t *lexer = rava_lexer_create(source);
|
||||
RavaParser_t *parser = rava_parser_create(lexer);
|
||||
RavaASTNode_t *ast = rava_parser_parse(parser);
|
||||
|
||||
if (parser->had_error) {
|
||||
printf("❌ Parse error: %s\n", parser->error_message);
|
||||
free(source);
|
||||
return false;
|
||||
}
|
||||
|
||||
RavaSemanticAnalyzer_t *analyzer = rava_semantic_analyzer_create();
|
||||
if (!rava_semantic_analyze(analyzer, ast)) {
|
||||
printf("❌ Semantic error: %s\n", analyzer->error_message);
|
||||
free(source);
|
||||
return false;
|
||||
}
|
||||
|
||||
RavaIRGenerator_t *ir_gen = rava_ir_generator_create(analyzer);
|
||||
RavaProgram_t *program = rava_ir_generate(ir_gen, ast);
|
||||
|
||||
if (!program) {
|
||||
printf("❌ IR generation failed\n");
|
||||
free(source);
|
||||
return false;
|
||||
}
|
||||
|
||||
RavaVM_t *vm = rava_vm_create(program);
|
||||
printf("\nOutput:\n");
|
||||
|
||||
if (!rava_vm_execute(vm, class_name, "main")) {
|
||||
printf("\n❌ Runtime error: %s\n", vm->error_message);
|
||||
rava_vm_destroy(vm);
|
||||
free(source);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("\n✅ Execution completed successfully!\n");
|
||||
|
||||
rava_vm_destroy(vm);
|
||||
rava_program_destroy(program);
|
||||
rava_ir_generator_destroy(ir_gen);
|
||||
rava_semantic_analyzer_destroy(analyzer);
|
||||
rava_ast_node_destroy(ast);
|
||||
rava_parser_destroy(parser);
|
||||
rava_lexer_destroy(lexer);
|
||||
free(source);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("================================================================================\n");
|
||||
printf("RAVA JAVA INTERPRETER - UNIVERSITY-LEVEL DEMONSTRATION SUITE\n");
|
||||
printf("================================================================================\n");
|
||||
|
||||
int passed = 0;
|
||||
int total = 0;
|
||||
|
||||
const char *examples[][2] = {
|
||||
{"examples/01_Fibonacci.java", "Fibonacci"},
|
||||
{"examples/02_PrimeNumbers.java", "PrimeNumbers"},
|
||||
{"examples/03_FactorialVariations.java", "FactorialVariations"},
|
||||
{"examples/04_GCD_LCM.java", "GCD_LCM"},
|
||||
{"examples/05_PowerFunction.java", "PowerFunction"},
|
||||
{"examples/06_BubbleSort.java", "BubbleSort"},
|
||||
{"examples/07_CollatzConjecture.java", "CollatzConjecture"},
|
||||
{"examples/08_PascalTriangle.java", "PascalTriangle"},
|
||||
{"examples/09_TowerOfHanoi.java", "TowerOfHanoi"},
|
||||
{"examples/10_AckermannFunction.java", "AckermannFunction"},
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < 10; i++) {
|
||||
total++;
|
||||
if (run_example(examples[i][0], examples[i][1])) {
|
||||
passed++;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
printf("================================================================================\n");
|
||||
printf("DEMONSTRATION SUMMARY\n");
|
||||
printf("================================================================================\n");
|
||||
printf("Passed: %d/%d\n", passed, total);
|
||||
printf("Failed: %d/%d\n", total - passed, total);
|
||||
|
||||
if (passed == total) {
|
||||
printf("\n🎉 ALL DEMONSTRATIONS PASSED!\n");
|
||||
printf("The Rava interpreter successfully executed university-level Java programs!\n");
|
||||
}
|
||||
|
||||
return (passed == total) ? 0 : 1;
|
||||
}
|
||||
Reference in New Issue
Block a user