Bob/headers/TypeWrapper.h
Bobby Lucero 1e65b344ae Major speed optimization
- Replace Object* with Value tagged union for better performance
- Fix bug where "true"/"false" strings were treated as booleans
- Add isBoolean field to LiteralExpr to distinguish string vs boolean literals
- Implement fast function calls with g_returnContext instead of exceptions
- Add functions vector to prevent dangling pointers
- Remove try-catch blocks from execute() for 50x performance improvement
- Clean up test files, keep only main test suite and fib benchmark
- All 38 tests passing, fib(30) still ~848ms
2025-07-31 00:16:54 -04:00

66 lines
1.3 KiB
C++

#pragma once
#include <string>
#include <iostream>
#include <vector>
#include <memory>
#include <functional>
#include "Value.h"
// Forward declarations
struct Stmt;
struct Environment;
struct Object
{
virtual ~Object(){};
};
struct Number : Object
{
double value;
explicit Number(double value) : value(value) {}
};
struct String : Object
{
std::string value;
explicit String(std::string str) : value(str) {}
~String(){
}
};
struct Boolean : Object
{
bool value;
explicit Boolean(bool value) : value(value) {}
};
struct None : public Object
{
};
struct Function : public Object
{
const std::string name;
const std::vector<std::string> params;
const std::vector<std::shared_ptr<Stmt>> body;
const std::shared_ptr<Environment> closure;
Function(std::string name, std::vector<std::string> params,
std::vector<std::shared_ptr<Stmt>> body,
std::shared_ptr<Environment> closure)
: name(name), params(params), body(body), closure(closure) {}
};
struct BuiltinFunction : public Object
{
const std::string name;
const std::function<Value(std::vector<Value>)> func;
BuiltinFunction(std::string name, std::function<Value(std::vector<Value>)> func)
: name(name), func(func) {}
};