Skip to content

Commit

Permalink
sema: rename L field as Left and R field as Right of MultiAssign
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Aug 29, 2024
1 parent a500ab9 commit 8375a1a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
28 changes: 14 additions & 14 deletions src/julec/obj/cxx/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -472,21 +472,21 @@ impl scopeCoder {
}

fn mapLookupAssign(mut &self, mut &a: &MultiAssign) {
mut iem := (&IndexingExprModel)(a.R)
mut iem := (&IndexingExprModel)(a.Right)
self.oc.ec.possibleRefExpr(iem.Expr.Model)
self.oc.write(".lookup(")
self.oc.ec.possibleRefExpr(iem.Index.Model)
self.oc.write(", ")
if a.L[0] != nil {
if a.Left[0] != nil {
self.oc.write("&(")
self.oc.ec.possibleRefExpr(a.L[0].Model)
self.oc.ec.possibleRefExpr(a.Left[0].Model)
self.oc.write("), ")
} else {
self.oc.write("nullptr, ")
}
if a.L[1] != nil {
if a.Left[1] != nil {
self.oc.write("&(")
self.oc.ec.possibleRefExpr(a.L[1].Model)
self.oc.ec.possibleRefExpr(a.Left[1].Model)
self.oc.write(")")
} else {
self.oc.write("nullptr")
Expand All @@ -498,11 +498,11 @@ impl scopeCoder {
self.oc.write("({\n")
self.oc.addIndent()

mut tup := (&TupleExprModel)(a.R)
mut tup := (&TupleExprModel)(a.Right)

for (i, mut r) in tup.Datas {
self.oc.indent()
mut l := a.L[i]
mut l := a.Left[i]
if l != nil {
match type l.Model {
| &Var:
Expand All @@ -514,7 +514,7 @@ impl scopeCoder {
self.oc.write(" = &(")
self.oc.ec.possibleRefExpr(r.Model)
self.oc.write(");\n")
a.L[i] = nil // Ignore handling for following statements.
a.Left[i] = nil // Ignore handling for following statements.
continue
}
}
Expand All @@ -527,7 +527,7 @@ impl scopeCoder {
self.oc.write(";\n")
}

for (i, mut l) in a.L {
for (i, mut l) in a.Left {
if l == nil {
continue
}
Expand All @@ -548,14 +548,14 @@ impl scopeCoder {
self.oc.addIndent()
self.oc.indent()

mut f := (&FnCallExprModel)(a.R)
mut f := (&FnCallExprModel)(a.Right)
self.oc.tc.rc.codeMut1(self.oc.Buf, f.Func.Result)
self.oc.write(" " + assignResultName + " = ")
self.oc.ec.possibleRefExpr(a.R)
self.oc.ec.possibleRefExpr(a.Right)
self.oc.write(";\n")

mut tup := f.Func.Result.Tup()
for (i, mut l) in a.L {
for (i, mut l) in a.Left {
if l != nil {
const r = assignResultName + "." + resultArgName
self.oc.indent()
Expand Down Expand Up @@ -604,13 +604,13 @@ impl scopeCoder {

fn multiAssign(mut &self, mut a: &MultiAssign) {
// Special cases.
match type a.R {
match type a.Right {
| &IndexingExprModel: // Map lookup.
self.mapLookupAssign(a)
ret
}

match type a.R {
match type a.Right {
| &TupleExprModel:
self.multiAssignTup(a)
| &FnCallExprModel:
Expand Down
4 changes: 2 additions & 2 deletions src/julec/opt/deadcode/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ impl scopeDeadCode {
}

fn optimizeMultiAssign(mut &self, mut assign: &MultiAssign) {
for (_, mut l) in assign.L {
for (_, mut l) in assign.Left {
if l != nil {
self.optimizeExprModel(l.Model)
}
}
self.optimizeExprModel(assign.R)
self.optimizeExprModel(assign.Right)
}

fn optimizeStmt(mut &self, mut st: Stmt) {
Expand Down
28 changes: 14 additions & 14 deletions src/julec/opt/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -523,35 +523,35 @@ impl scopeOptimizer {
}

fn tryOptimizeSwap(mut &self, mut &assign: &MultiAssign): bool {
if !Assign || len(assign.L) != 2 ||
assign.L[0] == nil || assign.L[1] == nil {
if !Assign || len(assign.Left) != 2 ||
assign.Left[0] == nil || assign.Left[1] == nil {
ret false
}
let mut tup: &TupleExprModel
match type assign.R {
match type assign.Right {
| &TupleExprModel:
tup = (&TupleExprModel)(assign.R)
tup = (&TupleExprModel)(assign.Right)
}
if tup == nil || len(tup.Datas) != 2 {
ret false
}

// Catch self assignments.
if equalModels(assign.L[0].Model, tup.Datas[0].Model) &&
equalModels(assign.L[1].Model, tup.Datas[1].Model) {
if equalModels(assign.Left[0].Model, tup.Datas[0].Model) &&
equalModels(assign.Left[1].Model, tup.Datas[1].Model) {
self.removeCurrent()
self.i-- // In next iteration, point to correct statement.
ret true
}

// Catch swaps.
if !equalModels(assign.L[0].Model, tup.Datas[1].Model) ||
!equalModels(assign.L[1].Model, tup.Datas[0].Model) {
if !equalModels(assign.Left[0].Model, tup.Datas[1].Model) ||
!equalModels(assign.Left[1].Model, tup.Datas[0].Model) {
ret false
}
mut model := &SwapExprModel{
Left: assign.L[0],
Right: assign.L[1],
Left: assign.Left[0],
Right: assign.Left[1],
}
exprOptimizer.optimizeData(model.Left.Model, self.data)
exprOptimizer.optimizeData(model.Right.Model, self.data)
Expand All @@ -567,11 +567,11 @@ impl scopeOptimizer {
}

mut tup := (&TupleExprModel)(nil)
match type assign.R {
match type assign.Right {
| &TupleExprModel:
tup = (&TupleExprModel)(assign.R)
tup = (&TupleExprModel)(assign.Right)
}
for (i, mut l) in assign.L {
for (i, mut l) in assign.Left {
if l != nil {
if self.data.boundary != nil {
if isBoundaryRiskyType(l.Kind) {
Expand Down Expand Up @@ -602,7 +602,7 @@ impl scopeOptimizer {
exprOptimizer.optimizeData(l.Model, self.data)
}
}
exprOptimizer.optimizeData(assign.R, self.data)
exprOptimizer.optimizeData(assign.Right, self.data)
}

fn optimizeRet(mut &self, mut r: &RetSt) {
Expand Down
12 changes: 6 additions & 6 deletions std/jule/sema/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ struct Assign {

// Multi-declarative assignment.
struct MultiAssign {
L: []&Data // Nil Model:s represents ingored expressions.
R: ExprModel
Left: []&Data // Nil Model:s represents ingored expressions.
Right: ExprModel
}

// Match-Case.
Expand Down Expand Up @@ -1397,7 +1397,7 @@ impl scopeChecker {
if r.Kind.Void() {
self.s.pushErr(a.Right.Token, LogMsg.InvalidExpr)
}
st.L = append(st.L, nil)
st.Left = append(st.Left, nil)
ret
}

Expand Down Expand Up @@ -1425,7 +1425,7 @@ impl scopeChecker {
},
}
self.s.checkVarValue(v)
st.L = append(st.L, &Data{
st.Left = append(st.Left, &Data{
Lvalue: !v.Constant,
Mutable: v.Mutable,
Reference: v.Reference,
Expand Down Expand Up @@ -1458,7 +1458,7 @@ impl scopeChecker {
errorToken: a.Setter,
}
checker.check()
st.L = append(st.L, l)
st.Left = append(st.Left, l)
}

fn checkMultiAssign(mut &self, mut &a: &AssignSt) {
Expand Down Expand Up @@ -1490,7 +1490,7 @@ impl scopeChecker {
}

mut st := &MultiAssign{
R: rd.Model,
Right: rd.Model,
}
for i in a.Left {
mut lexpr := a.Left[i]
Expand Down

0 comments on commit 8375a1a

Please sign in to comment.