evaluate method

  1. @override
LangVal<LangType> evaluate(
  1. SymbolTable table
)
override

Evaluates the identifier by looking up and loading the variable's value.

Looks up the variable in the symbol table and generates LLVM IR to load its value. For arrays, returns the array pointer. For primitive types, generates a load instruction.

Parameters:

  • table: The symbol table to look up the variable

Returns: A LangVal containing the loaded value or array pointer

Throws:

  • Exception if the variable is not found in the symbol table

Implementation

@override
LangVal evaluate(SymbolTable table) {
  var varData = table.get(nodeValue);
  if (varData == null) {
    throw Exception("Variable $nodeValue not found");
  }
  if (varData.type is ArrayType) {
    return LangVal(varData.ptrName, varData.type);
  }
  Node.addIrLine(
      "%var$id = load ${varData.type.primitiveType.irType}, ptr ${varData.ptrName}");
  return LangVal("%var$id", varData.type);
}