Bob/source/bob.cpp
Bobby Lucero eacb86ec77 feat: comprehensive language enhancements and code quality improvements
Major additions and improvements across the Bob language ecosystem:

Core Language Features:

- Add comprehensive dictionary support with full CRUD operations

- Implement built-in functions: keys(), values(), has() for dictionaries

- Add string multiplication operator (string * number)

- Enhance error reporting with detailed context and call stacks

- Add ternary operator support (condition ? true_expr : false_expr)

- Implement do-while loops with break/continue support

- Add array increment/decrement operators (++, --)

- Add cross-type comparison operators with proper type coercion

- Implement toInt() function for float-to-integer conversion

- Add float array index auto-truncation (like JavaScript/Lua)

Code Quality & Linter Fixes:

- Remove all "using namespace std;" statements (best practice)

- Add proper std:: prefixes throughout codebase

- Fix const correctness in helper functions

- Resolve class/struct declaration mismatches

- Fix sign comparison warnings in array indexing

- Remove unused lambda captures in built-in functions

- Fix brace initialization warnings in parser

Documentation & Tooling:

- Significantly expand BOB_LANGUAGE_REFERENCE.md with new features

- Update VS Code extension with enhanced syntax highlighting

- Add comprehensive code snippets for new language features

- Update version information and package metadata

Test Suite:

- Add extensive dictionary functionality tests

- Add tests for new operators and built-in functions

- Add comprehensive copy behavior tests (by value vs by reference)

- Add performance and edge case testing

Architecture Improvements:

- Enhance Value system with proper move semantics

- Improve memory management with shared_ptr for complex types

- Add trampoline-based tail call optimization

- Implement proper error context propagation

This represents a major milestone in Bob language development with production-ready dictionary support, comprehensive testing, and significantly improved code quality.
2025-08-07 00:12:04 -04:00

96 lines
2.4 KiB
C++

#include <utility>
#include "../headers/bob.h"
#include "../headers/Parser.h"
void Bob::runFile(const std::string& path)
{
this->interpreter = msptr(Interpreter)(false);
std::ifstream file = std::ifstream(path);
std::string source;
if(file.is_open()){
source = std::string(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
}
else
{
std::cout << "File not found" << std::endl;
return;
}
// Load source code into error reporter for context
errorReporter.loadSource(source, path);
// Connect error reporter to interpreter
interpreter->setErrorReporter(&errorReporter);
this->run(source);
}
void Bob::runPrompt()
{
this->interpreter = msptr(Interpreter)(true);
std::cout << "Bob v" << VERSION << ", 2025" << std::endl;
for(;;)
{
std::string line;
std::cout << "\033[0;36m" << "-> " << "\033[0;37m";
std::getline(std::cin, line);
if(std::cin.eof())
{
break;
}
// Reset error state before each REPL command
errorReporter.resetErrorState();
// Load source code into error reporter for context
errorReporter.loadSource(line, "REPL");
// Connect error reporter to interpreter
interpreter->setErrorReporter(&errorReporter);
this->run(line);
}
}
void Bob::run(std::string source)
{
try {
// Connect error reporter to lexer
lexer.setErrorReporter(&errorReporter);
std::vector<Token> tokens = lexer.Tokenize(std::move(source));
Parser p(tokens);
// Connect error reporter to parser
p.setErrorReporter(&errorReporter);
std::vector<sptr(Stmt)> statements = p.parse();
interpreter->interpret(statements);
}
catch(std::exception &e)
{
// Only suppress errors that have already been reported by the error reporter
if (errorReporter.hasReportedError()) {
return;
}
// For errors that weren't reported (like parser errors, undefined variables, etc.)
// print them normally
std::cout << "Error: " << e.what() << std::endl;
return;
}
catch(...)
{
// Unknown error - report it since it wasn't handled by the interpreter
errorReporter.reportError(0, 0, "Unknown Error", "An unknown error occurred");
return;
}
}