Skip to content

Commit

Permalink
fix behavior for repetition index within repeat-until expression
Browse files Browse the repository at this point in the history
  • Loading branch information
transverberate committed Apr 4, 2022
1 parent ada9574 commit fe6aa38
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ class GoCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.puts(s"${privateMemberName(RawIdentifier(id))} = make([][]byte, 0);")
if (needRaw.level >= 2)
out.puts(s"${privateMemberName(RawIdentifier(RawIdentifier(id)))} = make([][]byte, 0);")
out.puts(s"for i := 1;; i++ {")
out.puts("i := 0")
out.puts("for {")
out.inc
}

Expand All @@ -352,6 +353,7 @@ class GoCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)

override def condRepeatUntilFooter(id: Identifier, io: String, dataType: DataType, needRaw: NeedRaw, untilExpr: Ast.expr): Unit = {
typeProvider._currentIteratorType = Some(dataType)
out.puts("i++")
out.puts(s"if ${expression(untilExpr)} {")
out.inc
out.puts("break")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ class LuaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
}
override def condRepeatUntilFooter(id: Identifier, io: String, dataType: DataType, needRaw: NeedRaw, untilExpr: Ast.expr): Unit = {
typeProvider._currentIteratorType = Some(dataType)
out.puts("i = i + 1")
out.puts(s"if ${expression(untilExpr)} then")
out.inc
out.puts("break")
out.dec
out.puts("end")
out.puts("i = i + 1")
out.dec
out.puts("end")
out.dec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ class NimCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
}
override def condRepeatUntilFooter(id: Identifier, io: String, dataType: DataType, needRaw: NeedRaw, repeatExpr: Ast.expr): Unit = {
typeProvider._currentIteratorType = Some(dataType)
out.puts("inc i")
out.puts(s"if ${expression(repeatExpr)}:")
out.inc
out.puts("break")
out.dec
out.puts("inc i")
out.dec
out.dec
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class PerlCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
if (needRaw.level >= 2)
out.puts(s"${privateMemberName(RawIdentifier(RawIdentifier(id)))} = ();")
out.puts(s"${privateMemberName(id)} = ();")
out.puts("my $i = 0;")
out.puts("do {")
out.inc
}
Expand All @@ -286,6 +287,7 @@ class PerlCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)

override def condRepeatUntilFooter(id: Identifier, io: String, dataType: DataType, needRaw: NeedRaw, untilExpr: expr): Unit = {
typeProvider._currentIteratorType = Some(dataType)
out.puts("$i++;")
out.dec
out.puts(s"} until (${expression(untilExpr)});")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,11 @@ class PythonCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)

override def condRepeatUntilFooter(id: Identifier, io: String, dataType: DataType, needRaw: NeedRaw, untilExpr: expr): Unit = {
typeProvider._currentIteratorType = Some(dataType)
out.puts("i += 1")
out.puts(s"if ${expression(untilExpr)}:")
out.inc
out.puts("break")
out.dec
out.puts("i += 1")
out.dec
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class RustCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
if (needRaw.level >= 2)
out.puts(s"${privateMemberName(RawIdentifier(RawIdentifier(id)))} = vec!();")
out.puts(s"${privateMemberName(id)} = vec!();")
out.puts("let mut i = 0;")
out.puts("while {")
out.inc
}
Expand All @@ -307,6 +308,7 @@ class RustCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)

override def condRepeatUntilFooter(id: Identifier, io: String, dataType: DataType, needRaw: NeedRaw, untilExpr: Ast.expr): Unit = {
typeProvider._currentIteratorType = Some(dataType)
out.puts("i += 1;")
out.puts(s"!(${expression(untilExpr)})")
out.dec
out.puts("} { }")
Expand Down

0 comments on commit fe6aa38

Please sign in to comment.