/** * @file test_interpreter.c * @brief Test program for interpreter implementation * @author eli_oat * @version 0.0.1 * @date 2025 * * This file tests the interpreter implementation for the Baba Yaga language. */ #include #include #include #include "baba_yaga.h" int main(void) { printf("Testing Baba Yaga Interpreter\n"); printf("============================\n\n"); /* Set debug level */ baba_yaga_set_debug_level(DEBUG_INFO); /* Create interpreter */ Interpreter* interp = baba_yaga_create(); if (interp == NULL) { printf("Failed to create interpreter\n"); return 1; } printf("āœ“ Interpreter created successfully\n"); /* Test basic arithmetic */ printf("\nTesting basic arithmetic:\n"); const char* source1 = "5 + 3"; ExecResult result1; Value value1 = baba_yaga_execute(interp, source1, strlen(source1), &result1); if (result1 == EXEC_SUCCESS) { char* str1 = baba_yaga_value_to_string(&value1); printf(" %s = %s\n", source1, str1); free(str1); baba_yaga_value_destroy(&value1); } else { printf(" Failed to execute: %s\n", source1); } /* Test variable declaration */ printf("\nTesting variable declaration:\n"); const char* source2 = "x = 42"; ExecResult result2; Value value2 = baba_yaga_execute(interp, source2, strlen(source2), &result2); if (result2 == EXEC_SUCCESS) { char* str2 = baba_yaga_value_to_string(&value2); printf(" %s = %s\n", source2, str2); free(str2); baba_yaga_value_destroy(&value2); } else { printf(" Failed to execute: %s\n", source2); } /* Test variable access */ printf("\nTesting variable access:\n"); const char* source3 = "x"; ExecResult result3; Value value3 = baba_yaga_execute(interp, source3, strlen(source3), &result3); if (result3 == EXEC_SUCCESS) { char* str3 = baba_yaga_value_to_string(&value3); printf(" %s = %s\n", source3, str3); free(str3); baba_yaga_value_destroy(&value3); } else { printf(" Failed to execute: %s\n", source3); } /* Test standard library functions */ printf("\nTesting standard library functions:\n"); const char* source4 = "out(42)"; ExecResult result4; Value value4 = baba_yaga_execute(interp, source4, strlen(source4), &result4); if (result4 == EXEC_SUCCESS) { char* str4 = baba_yaga_value_to_string(&value4); printf(" %s = %s\n", source4, str4); free(str4); baba_yaga_value_destroy(&value4); } else { printf(" Failed to execute: %s\n", source4); } /* Cleanup */ baba_yaga_destroy(interp); printf("\nāœ“ Interpreter destroyed successfully\n"); printf("\nāœ“ All interpreter tests completed!\n"); return 0; }