Skip to content

Commit

Permalink
Extract common functionality outside the scope of the incremental loop
Browse files Browse the repository at this point in the history
  • Loading branch information
asynchroza committed Nov 18, 2023
1 parent bbb503b commit 5eb1d07
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions nulascript/eval/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -289,33 +289,33 @@ Storage* runForLoop(ForLoop* fl, Environment* env) {
"Incorrectly provisioned incremental boolean variable for loop");
}

if (increment->value) {
Infix* conditional = dynamic_cast<Infix*>(fl->definition.conditional);
Infix* conditional = dynamic_cast<Infix*>(fl->definition.conditional);

if (!conditional) {
return new ErrorStorage(
"Incorrectly provisioned conditional statement for loop");
}
if (!conditional) {
return new ErrorStorage(
"Incorrectly provisioned conditional statement for loop");
}

Identifier* identifier = dynamic_cast<Identifier*>(conditional->left);
if (!identifier) {
// TODO: come up with better message;
return new ErrorStorage("something 1");
}
Identifier* identifier = dynamic_cast<Identifier*>(conditional->left);
if (!identifier) {
// TODO: come up with better message;
return new ErrorStorage("something 1");
}

Integer* threshold = dynamic_cast<Integer*>(conditional->right);
if (!threshold) {
// TODO: come up with better message;
return new ErrorStorage("something 2");
}
Integer* threshold = dynamic_cast<Integer*>(conditional->right);
if (!threshold) {
// TODO: come up with better message;
return new ErrorStorage("something 2");
}

IntegerStorage* initializer =
dynamic_cast<IntegerStorage*>(env->get(identifier->token.literal));
if (!initializer) {
// TODO: come up with better message;
return new ErrorStorage("something 3");
}
IntegerStorage* initializer =
dynamic_cast<IntegerStorage*>(env->get(identifier->token.literal));
if (!initializer) {
// TODO: come up with better message;
return new ErrorStorage("something 3");
}

if (increment->value) {
for (int i = initializer->value; true; i++) {
if (!evaluateConditionalExpression(i, conditional->op,
threshold->value))
Expand All @@ -336,6 +336,7 @@ Storage* runForLoop(ForLoop* fl, Environment* env) {
return new ErrorStorage("Decremental loops are not yet implemented");
}

// TODO: delete newly created loop variable from environment
return emptyStorage;
}

Expand Down

0 comments on commit 5eb1d07

Please sign in to comment.