Skip to content

Commit

Permalink
compiler: fix and improve code generation for iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed May 20, 2024
1 parent 92dcc36 commit 06e8851
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions src/julec/obj/cxx/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,23 @@ impl scopeCoder {
self.oc.indent()
self.oc.write("auto expr = ")
let mut ref = false
match type it.Expr.Model {
| &Var:
let v = (&Var)(it.Expr.Model)
if v.Reference {
ref = true
self.oc.ec.model(it.Expr.Model)
break
}
fall
|:
if opt::Copy && isCopyOptimizable(it.Expr) {
ref = true
if opt::Copy && isCopyOptimizable(it.Expr) {
ref = true
match type it.Expr.Model {
| &Var:
let v = (&Var)(it.Expr.Model)
if v.Reference {
self.oc.ec.model(it.Expr.Model)
break
}
fall
|:
self.oc.write("&(")
self.oc.ec.model(it.Expr.Model)
self.oc.write(")")
} else {
self.oc.ec.model(it.Expr.Model)
}
} else {
self.oc.ec.possibleRefExpr(it.Expr.Model)
}
self.oc.write(";\n")
self.oc.indent()
Expand All @@ -102,16 +101,18 @@ impl scopeCoder {
}
self.oc.write("begin();\n")
self.oc.indent()
self.oc.write(begin)
self.oc.write(":;\n")
self.oc.indent()
self.oc.write("if (it != expr")
self.oc.write("auto expr_end = expr")
if ref {
self.oc.write("->")
} else {
self.oc.write(".")
}
self.oc.write("end()) {\n")
self.oc.write("end();\n")
self.oc.indent()
self.oc.write(begin)
self.oc.write(":;\n")
self.oc.indent()
self.oc.write("if (it != expr_end) {\n")
self.oc.addIndent()
self.oc.indent()
if it.KeyA != nil {
Expand Down Expand Up @@ -180,24 +181,23 @@ impl scopeCoder {
self.oc.indent()
self.oc.write("auto expr = ")
let mut ref = false
match type it.Expr.Model {
| &Var:
let v = (&Var)(it.Expr.Model)
if v.Reference {
ref = true
self.oc.ec.model(it.Expr.Model)
break
}
fall
|:
if opt::Copy && isCopyOptimizable(it.Expr) {
ref = true
if opt::Copy && isCopyOptimizable(it.Expr) {
ref = true
match type it.Expr.Model {
| &Var:
let v = (&Var)(it.Expr.Model)
if v.Reference {
self.oc.ec.model(it.Expr.Model)
break
}
fall
|:
self.oc.write("&(")
self.oc.ec.model(it.Expr.Model)
self.oc.write(")")
} else {
self.oc.ec.model(it.Expr.Model)
}
} else {
self.oc.ec.possibleRefExpr(it.Expr.Model)
}
self.oc.write(";\n")
self.oc.indent()
Expand All @@ -209,16 +209,18 @@ impl scopeCoder {
}
self.oc.write("begin();\n")
self.oc.indent()
self.oc.write(begin)
self.oc.write(":;\n")
self.oc.indent()
self.oc.write("if (it != expr")
self.oc.write("auto expr_end = expr")
if ref {
self.oc.write("->")
} else {
self.oc.write(".")
}
self.oc.write("end()) {\n")
self.oc.write("end();\n")
self.oc.indent()
self.oc.write(begin)
self.oc.write(":;\n")
self.oc.indent()
self.oc.write("if (it != expr_end) {\n")
self.oc.addIndent()
self.oc.indent()
if it.KeyA != nil {
Expand Down

0 comments on commit 06e8851

Please sign in to comment.