Skip to content

Commit

Permalink
Progress on support for scoped local variables
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
  • Loading branch information
mballance committed Dec 23, 2023
1 parent 856feb3 commit 7143b21
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
60 changes: 43 additions & 17 deletions src/EvalTypeProcStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,38 +189,64 @@ void EvalTypeProcStmt::visitTypeProcStmtIfElse(dm::ITypeProcStmtIfElse *s) {
case 0: {
// Evaluate condition
m_idx = 1;
m_sub_idx = 0;

if (EvalTypeExpr(m_ctxt, m_thread, m_vp_id, s->getCond()).eval()) {
clrFlags(EvalFlags::Complete);
break;
}
}

case 1: {
m_idx = 2;
// Have the condition result
vsc::dm::ValRefBool cond(getResult());

if (!cond.valid()) {
ERROR("if-condition value is not valid");
// Step through if-else clauses until we find cond==true or
// reach the end of the list
if (m_sub_idx > 0 && hasFlags(EvalFlags::Complete) && getResult().vp()) {
// Move on to the 'execute' stage
m_idx = 2;
// The condition was for the *previous* entry, so adjust
m_sub_idx--;
} else {
while (m_sub_idx < s->getIfClauses().size()) {

if (EvalTypeExpr(m_ctxt, m_thread, m_vp_id,
s->getIfClauses().at(m_sub_idx)->getCond()).eval()) {
clrFlags(EvalFlags::Complete);
m_sub_idx++;
break;
} else if (getResult().vp()) {
// Roll
m_idx = 2;
break;
} else {
m_sub_idx++;
}
}

if (!hasFlags(EvalFlags::Complete)) {
break;
}
}
}
case 2: {
m_idx = 3;

if (cond.valid() && cond.get_val()) {
DEBUG("True branch");
if (EvalTypeProcStmt(m_ctxt, m_thread, m_vp_id, s->getTrue()).eval()) {
vsc::dm::ValRefBool cond(getResult());
// Evaluate the selected branch (if cond==true)
if (m_sub_idx < s->getIfClauses().size() && cond.valid() && cond.get_val()) {
//
if (EvalTypeProcStmt(m_ctxt, m_thread, m_vp_id,
s->getIfClauses().at(m_sub_idx).get()).eval()) {
clrFlags(EvalFlags::Complete);
break;
}
} else if (s->getFalse()) {
DEBUG("False branch");
if (EvalTypeProcStmt(m_ctxt, m_thread, m_vp_id, s->getFalse()).eval()) {
} else if (s->getElseClause()) {
if (EvalTypeProcStmt(m_ctxt, m_thread, m_vp_id,
s->getElseClause()).eval()) {
clrFlags(EvalFlags::Complete);
break;
}
}
}
case 2: {
//

case 3: {

}
}
DEBUG_LEAVE("visitTypeProcStmtIfElse");
Expand Down
1 change: 1 addition & 0 deletions src/EvalTypeProcStmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class EvalTypeProcStmt :
static dmgr::IDebug *m_dbg;
dm::ITypeProcStmt *m_stmt;
uint32_t m_idx;
int32_t m_sub_idx;

};

Expand Down

0 comments on commit 7143b21

Please sign in to comment.