Fix variables tests
This commit is contained in:
parent
62eb2bece6
commit
1d571f36b1
@ -285,6 +285,9 @@ EvalResult eval(Node &ast, Memory &memory) {
|
||||
string typeName = get<string>(typeTok.data);
|
||||
string identifier = get<string>(identifierTok.data);
|
||||
|
||||
if (memory.contains(identifier))
|
||||
throw RuntimeError("Already defined identifier \""+identifier+"\"", identifierTok.pos);
|
||||
|
||||
memory.declare(identifier, string_to_type(typeName));
|
||||
|
||||
return {};
|
||||
@ -296,6 +299,9 @@ EvalResult eval(Node &ast, Memory &memory) {
|
||||
string identifier = get<string>(identifierTok.data);
|
||||
EvalResult value = eval(node.children[2], memory);
|
||||
|
||||
if (memory.contains(identifier))
|
||||
throw RuntimeError("Already defined identifier \""+identifier+"\"", identifierTok.pos);
|
||||
|
||||
Type type = string_to_type(typeName);
|
||||
memory.declare(identifier, type);
|
||||
|
||||
@ -313,6 +319,9 @@ EvalResult eval(Node &ast, Memory &memory) {
|
||||
string identifier = get<string>(identifierTok.data);
|
||||
EvalResult value = eval(node.children[1], memory);
|
||||
|
||||
if (!memory.contains(identifier))
|
||||
throw RuntimeError("Unknown identifier \""+identifier+"\"", identifierTok.pos);
|
||||
|
||||
Type type = memory.get(identifier).type;
|
||||
|
||||
if (type == Type::Int) {
|
||||
@ -328,6 +337,9 @@ EvalResult eval(Node &ast, Memory &memory) {
|
||||
Token identifierTok = get<Token>(node.children[0]);
|
||||
string identifier = get<string>(identifierTok.data);
|
||||
|
||||
if (!memory.contains(identifier))
|
||||
throw RuntimeError("Unknown identifier \""+identifier+"\"", identifierTok.pos);
|
||||
|
||||
MemoryVar& var = memory.get(identifier);
|
||||
|
||||
if (!var.initialized) {
|
||||
@ -345,6 +357,9 @@ EvalResult eval(Node &ast, Memory &memory) {
|
||||
Token identifierTok = get<Token>(node.children[0]);
|
||||
string identifier = get<string>(identifierTok.data);
|
||||
|
||||
if (!memory.contains(identifier))
|
||||
throw RuntimeError("Unknown identifier \""+identifier+"\"", identifierTok.pos);
|
||||
|
||||
MemoryVar& var = memory.get(identifier);
|
||||
|
||||
if (!var.initialized) {
|
||||
@ -363,6 +378,9 @@ EvalResult eval(Node &ast, Memory &memory) {
|
||||
Token identifierTok = get<Token>(node.children[0]);
|
||||
string identifier = get<string>(identifierTok.data);
|
||||
|
||||
if (!memory.contains(identifier))
|
||||
throw RuntimeError("Unknown identifier \""+identifier+"\"", identifierTok.pos);
|
||||
|
||||
MemoryVar& var = memory.get(identifier);
|
||||
|
||||
if (!var.initialized) {
|
||||
@ -380,6 +398,9 @@ EvalResult eval(Node &ast, Memory &memory) {
|
||||
Token identifierTok = get<Token>(node.children[0]);
|
||||
string identifier = get<string>(identifierTok.data);
|
||||
|
||||
if (!memory.contains(identifier))
|
||||
throw RuntimeError("Unknown identifier \""+identifier+"\"", identifierTok.pos);
|
||||
|
||||
MemoryVar& var = memory.get(identifier);
|
||||
|
||||
if (!var.initialized) {
|
||||
@ -414,10 +435,14 @@ EvalResult eval(Node &ast, Memory &memory) {
|
||||
} break;
|
||||
case TokenType::Identifier: {
|
||||
string identifier = get<string>(token.data);
|
||||
|
||||
if (!memory.contains(identifier))
|
||||
throw RuntimeError("Unknown identifier \""+identifier+"\"", token.pos);
|
||||
|
||||
MemoryVar& var = memory.get(identifier);
|
||||
|
||||
if (!var.initialized) throw RuntimeError("Accessing uninitialized identifier \""+identifier+"\"", token.pos);
|
||||
if (!var.initialized)
|
||||
throw RuntimeError("Accessing uninitialized identifier \""+identifier+"\"", token.pos);
|
||||
|
||||
return var.value;
|
||||
} break;
|
||||
|
Loading…
Reference in New Issue
Block a user