|
@@ -350,24 +350,44 @@ export class IVProgProcessor {
|
|
//BEGIN for -> while rewrite
|
|
//BEGIN for -> while rewrite
|
|
const initCmd = new Commands.Assign(cmd.for_id.id, cmd.for_from);
|
|
const initCmd = new Commands.Assign(cmd.for_id.id, cmd.for_from);
|
|
initCmd.sourceInfo = cmd.sourceInfo;
|
|
initCmd.sourceInfo = cmd.sourceInfo;
|
|
- const is_forward_exp = new Expressions.InfixApp(Operators.GE, cmd.for_to, cmd.for_from);
|
|
|
|
- return this.evaluateExpression(store, is_forward_exp).then (result => {
|
|
|
|
- const is_forward = result.value;
|
|
|
|
|
|
+ const expression_tuple = []; //(for conditional, is for increasing)
|
|
|
|
+ if(cmd.for_pass == null) {
|
|
|
|
+ expression_tuple.push(Promise.resolve(null));
|
|
|
|
+ expression_tuple.push(this.evaluateExpression(store, new Expressions.InfixApp(Operators.GE, cmd.for_to, cmd.for_from)));
|
|
|
|
+ } else {
|
|
|
|
+ expression_tuple.push(this.evaluateExpression(store, new Expressions.InfixApp(Operators.GE, cmd.for_pass, new Expressions.IntLiteral(toInt(0)))));
|
|
|
|
+ expression_tuple.push(Promise.resolve(null));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Promise.all(expression_tuple).then (results => {
|
|
|
|
+ console.log(results);
|
|
|
|
+ let is_forward = true;
|
|
|
|
+ let is_end_gt_init = undefined;
|
|
let condition = null;
|
|
let condition = null;
|
|
- if (is_forward) {
|
|
|
|
- condition = new Expressions.InfixApp(Operators.LE, cmd.for_id, cmd.for_to);
|
|
|
|
|
|
+ let pass_value = cmd.for_pass;
|
|
|
|
+ if (results[0] == null) {
|
|
|
|
+ // pass is null, we need to deduce a value for it
|
|
|
|
+ is_end_gt_init = results[1].value;
|
|
} else {
|
|
} else {
|
|
- condition = new Expressions.InfixApp(Operators.GE, cmd.for_id, cmd.for_to);
|
|
|
|
|
|
+ is_forward = results[0].value
|
|
}
|
|
}
|
|
- condition.sourceInfo = cmd.sourceInfo;
|
|
|
|
- let pass_value = cmd.for_pass;
|
|
|
|
- if(pass_value == null) {
|
|
|
|
|
|
+
|
|
|
|
+ if(is_end_gt_init == null) {
|
|
|
|
+ console.log("pass is not null and is forward? ", is_forward);
|
|
if(is_forward) {
|
|
if(is_forward) {
|
|
- pass_value = new Expressions.IntLiteral(toInt(1));
|
|
|
|
|
|
+ condition = new Expressions.InfixApp(Operators.LE, cmd.for_id, cmd.for_to);
|
|
} else {
|
|
} else {
|
|
- pass_value = new Expressions.IntLiteral(toInt(-1));
|
|
|
|
|
|
+ condition = new Expressions.InfixApp(Operators.GE, cmd.for_id, cmd.for_to);
|
|
}
|
|
}
|
|
|
|
+ console.log("Cond", condition);
|
|
|
|
+ } else if(is_end_gt_init) {
|
|
|
|
+ pass_value = new Expressions.IntLiteral(toInt(1));
|
|
|
|
+ condition = new Expressions.InfixApp(Operators.LE, cmd.for_id, cmd.for_to);
|
|
|
|
+ } else {
|
|
|
|
+ pass_value = new Expressions.IntLiteral(toInt(-1));
|
|
|
|
+ condition = new Expressions.InfixApp(Operators.GE, cmd.for_id, cmd.for_to);
|
|
}
|
|
}
|
|
|
|
+ condition.sourceInfo = cmd.sourceInfo;
|
|
const increment = new Commands.Assign(cmd.for_id.id,
|
|
const increment = new Commands.Assign(cmd.for_id.id,
|
|
new Expressions.InfixApp(Operators.ADD, cmd.for_id, pass_value));
|
|
new Expressions.InfixApp(Operators.ADD, cmd.for_id, pass_value));
|
|
increment.sourceInfo = cmd.sourceInfo;
|
|
increment.sourceInfo = cmd.sourceInfo;
|