AppendOperations implements the interface Statement.
(ops *[]InterpreterOperation, stack *InterpreterStack)
| 267 | |
| 268 | // AppendOperations implements the interface Statement. |
| 269 | func (stmt Goto) AppendOperations(ops *[]InterpreterOperation, stack *InterpreterStack) error { |
| 270 | if len(stmt.Label) > 0 { |
| 271 | *ops = append(*ops, InterpreterOperation{ |
| 272 | OpCode: OpCode_Goto, |
| 273 | PrimaryData: stmt.Label, |
| 274 | Index: int(stmt.Offset), |
| 275 | }) |
| 276 | } else if stmt.NearestScopeOp { |
| 277 | label := stack.GetCurrentLabel() |
| 278 | if len(label) == 0 { |
| 279 | if stmt.Offset > 0 { |
| 280 | return errors.New("EXIT cannot be used outside a loop, unless it has a label") |
| 281 | } else { |
| 282 | return errors.New("CONTINUE cannot be used outside a loop") |
| 283 | } |
| 284 | } |
| 285 | *ops = append(*ops, InterpreterOperation{ |
| 286 | OpCode: OpCode_Goto, |
| 287 | PrimaryData: label, |
| 288 | Index: int(stmt.Offset), |
| 289 | }) |
| 290 | } else { |
| 291 | *ops = append(*ops, InterpreterOperation{ |
| 292 | OpCode: OpCode_Goto, |
| 293 | Index: len(*ops) + int(stmt.Offset), |
| 294 | }) |
| 295 | } |
| 296 | return nil |
| 297 | } |
| 298 | |
| 299 | // If represents an IF condition, alongside its Goto offset if the condition is true. |
| 300 | type If struct { |
nothing calls this directly
no test coverage detected