Skip to content

Commit

Permalink
Nim: Use correct float division operator
Browse files Browse the repository at this point in the history
Integer division operator is `div`
Float   division operator is `/`
  • Loading branch information
Mingun committed Oct 4, 2024
1 parent 835eaed commit 5ab65fd
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import io.kaitai.struct.format.{EnumSpec, Identifier}
import io.kaitai.struct.languages.NimCompiler.{ksToNim, namespaced, camelCase}

class NimTranslator(provider: TypeProvider, importList: ImportList) extends BaseTranslator(provider) {
override def genericBinOp(left: Ast.expr, op: Ast.operator, right: Ast.expr, extPrec: Int) = {
(detectType(left), detectType(right), op) match {
case (_: IntType, _: IntType, Ast.operator.Div) =>
genericBinOpStr(left, op, "div", right, extPrec)
case _ =>
super.genericBinOp(left, op, right, extPrec)
}
}

// Members declared in io.kaitai.struct.translators.BaseTranslator
override def bytesToStr(bytesExpr: String, encoding: String): String = {
s"""encode($bytesExpr, ${doStringLiteral(encoding)})"""
Expand Down Expand Up @@ -62,7 +71,7 @@ class NimTranslator(provider: TypeProvider, importList: ImportList) extends Base
case Ast.operator.Add => "+"
case Ast.operator.Sub => "-"
case Ast.operator.Mult => "*"
case Ast.operator.Div => "div"
case Ast.operator.Div => "/"
case Ast.operator.Mod => "%%%"
case Ast.operator.BitAnd => "and"
case Ast.operator.BitOr => "or"
Expand Down

0 comments on commit 5ab65fd

Please sign in to comment.