more fixes

This commit is contained in:
2025-10-06 18:25:12 +11:00
parent 8fea13cc17
commit 38557cdf4c

View File

@@ -45,11 +45,7 @@ Value execute(Instruction inst) {
return modules::assert(inst.args);
}
// For all other instructions, evaluate the arguments first
for(auto& arg : inst.args) {
arg = evaluate(arg);
}
// Handle variable operations that require unevaluated arguments
if (inst.instruction == InstructionType::Variable) {
auto& args = inst.args;
@@ -123,8 +119,6 @@ Value execute(Instruction inst) {
return instance;
}
// Indexed assignment: $var index = value
if (args.size() == 4 && args[2].valtype == ValueType::Identifier && args[2].string_val == "=") {
std::string var_name;
@@ -172,14 +166,23 @@ Value execute(Instruction inst) {
data::modifyValue(var_name, new_val);
return Value();
}
// Variable access or indexed get
// If args[0] is an Identifier and there are no args, it's a variable access.
if (args[0].valtype == ValueType::Identifier && args.empty()) {
return data::getValue(args[0].string_val);
}
Value subject = evaluate(args[0]);
// For all other instructions, evaluate the arguments first
for(auto& arg : inst.args) {
arg = evaluate(arg);
}
if (inst.instruction == InstructionType::Variable) {
// This part handles variable access and member/method access on evaluated arguments
auto& args = inst.args;
if (args.empty()) {
error("Empty variable instruction after evaluation");
return Value();
}
Value subject = args[0]; // First arg is already evaluated
std::vector<Value> op_args(args.begin() + 1, args.end());
if (op_args.empty()) {
@@ -195,8 +198,8 @@ Value execute(Instruction inst) {
if (op_args.empty()) {
return subject;
}
if (op_args[0].valtype != ValueType::Identifier) {
error("Struct member name must be an identifier.");
if (op_args[0].valtype != ValueType::Identifier && op_args[0].valtype != ValueType::String) {
error("Struct member name must be an identifier or string.");
return Value();
}
std::string member_name = op_args[0].string_val;
@@ -218,7 +221,7 @@ Value execute(Instruction inst) {
data::pushScope();
data::scopes.back()["self"] = subject;
for (size_t i = 0; i < func.arg_names.size(); ++i) {
data::scopes.back()[func.arg_names[i]] = evaluate(func_args[i]);
data::scopes.back()[func.arg_names[i]] = func_args[i];
}
Value return_val;
for (const auto& body_inst : func.body) {