File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
test/tools/yulInterpreter Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -106,11 +106,27 @@ void Interpreter::operator()(ForLoop const& _forLoop)
106
106
while (evaluate (*_forLoop.condition ) != 0 )
107
107
{
108
108
(*this )(_forLoop.body );
109
+ if (m_state.loopState == LoopState::Break)
110
+ {
111
+ m_state.loopState = LoopState::Default;
112
+ break ;
113
+ }
109
114
(*this )(_forLoop.post );
115
+ m_state.loopState = LoopState::Default;
110
116
}
111
117
closeScope ();
112
118
}
113
119
120
+ void Interpreter::operator ()(Break const & _break)
121
+ {
122
+ m_state.loopState = LoopState::Break;
123
+ }
124
+
125
+ void Interpreter::operator ()(Continue const & _continue)
126
+ {
127
+ m_state.loopState = LoopState::Continue;
128
+ }
129
+
114
130
void Interpreter::operator ()(Block const & _block)
115
131
{
116
132
openScope ();
@@ -122,7 +138,14 @@ void Interpreter::operator()(Block const& _block)
122
138
m_functions[funDef.name ] = &funDef;
123
139
m_scopes.back ().insert (funDef.name );
124
140
}
125
- ASTWalker::operator ()(_block);
141
+
142
+ for (auto const & statement : _block.statements )
143
+ {
144
+ visit (statement);
145
+ if (m_state.loopState != LoopState::Default)
146
+ break ;
147
+ }
148
+
126
149
closeScope ();
127
150
}
128
151
Original file line number Diff line number Diff line change @@ -39,6 +39,12 @@ class InterpreterTerminated: dev::Exception
39
39
{
40
40
};
41
41
42
+ enum class LoopState {
43
+ Default,
44
+ Continue,
45
+ Break,
46
+ };
47
+
42
48
struct InterpreterState
43
49
{
44
50
dev::bytes calldata;
@@ -65,6 +71,7 @@ struct InterpreterState
65
71
std::vector<std::string> trace;
66
72
// / This is actually an input parameter that more or less limits the runtime.
67
73
size_t maxTraceSize = 0 ;
74
+ LoopState loopState = LoopState::Default;
68
75
};
69
76
70
77
/* *
@@ -90,6 +97,8 @@ class Interpreter: public ASTWalker
90
97
void operator ()(Switch const & _switch) override ;
91
98
void operator ()(FunctionDefinition const &) override ;
92
99
void operator ()(ForLoop const &) override ;
100
+ void operator ()(Break const &) override ;
101
+ void operator ()(Continue const &) override ;
93
102
void operator ()(Block const & _block) override ;
94
103
95
104
std::vector<std::string> const & trace () const { return m_state.trace ; }
You can’t perform that action at this time.
0 commit comments