diff options
| author | Mel <einebeere@gmail.com> | 2022-07-06 02:05:58 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-07-06 14:05:28 +0200 |
| commit | 32ec3e1186b3ed29e910ad60a18f956b823ddc23 (patch) | |
| tree | 413c4613059b9d870ac631ad7daa24b1369e5f2c /pkg/lang/compiler/compiler.go | |
| parent | 16899111516fbff736dedacb2804e8ea83267968 (diff) | |
| download | jinx-32ec3e1186b3ed29e910ad60a18f956b823ddc23.tar.zst jinx-32ec3e1186b3ed29e910ad60a18f956b823ddc23.zip | |
Increment hidden i variable in ForIn code
Diffstat (limited to 'pkg/lang/compiler/compiler.go')
| -rw-r--r-- | pkg/lang/compiler/compiler.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/pkg/lang/compiler/compiler.go b/pkg/lang/compiler/compiler.go index 3a5efd9..c51728f 100644 --- a/pkg/lang/compiler/compiler.go +++ b/pkg/lang/compiler/compiler.go @@ -204,6 +204,11 @@ func (comp *Compiler) compileForInStmt(t *code.Builder, forInStmt ast.StmtForIn) // get_local 1 // index // set_local 2 + + // get_local 1 + // push_int 1 + // add + // set_local 1 // 3. Do block // ... // 4. Repeat jump: @@ -259,6 +264,17 @@ func (comp *Compiler) compileForInStmt(t *code.Builder, forInStmt ast.StmtForIn) doPreparationTarget.AppendOp(code.OpSetLocal) doPreparationTarget.AppendInt(int64(nameLocal)) + doPreparationTarget.AppendOp(code.OpGetLocal) + doPreparationTarget.AppendInt(int64(iLocal)) + + doPreparationTarget.AppendOp(code.OpPushInt) + doPreparationTarget.AppendInt(1) + + doPreparationTarget.AppendOp(code.OpAdd) + + doPreparationTarget.AppendOp(code.OpSetLocal) + doPreparationTarget.AppendInt(int64(iLocal)) + // Do block doTarget := code.NewBuilder() if err := comp.compileBlockNode(&doTarget, forInStmt.Do); err != nil { |
