From a6daa75193d9a0f746483edd6bd1bab3f959d483 Mon Sep 17 00:00:00 2001 From: mertcandav Date: Sun, 15 Sep 2024 11:58:21 +0300 Subject: [PATCH] compiler: minor fix for lvalue handling --- src/julec/obj/cxx/expr.jule | 45 +++++++++++++++++++++++++++++++----- src/julec/obj/cxx/scope.jule | 1 + 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/julec/obj/cxx/expr.jule b/src/julec/obj/cxx/expr.jule index 28169cd9e..1e78af6d1 100644 --- a/src/julec/obj/cxx/expr.jule +++ b/src/julec/obj/cxx/expr.jule @@ -102,9 +102,18 @@ enum compExprModel: type { &UnsafeCastingExprModel, } +enum exprFlag { + NA, + lvalue, +} + struct exprCoder { oc: &ObjectCoder + // expression handling flags + // it will be reset to default after each handled expression model + flags: exprFlag + // It will executed before common variable handling algorithm. // If it returns true, common algorithm will not be executed. varPrefixes: []fn(mut v: &Var): bool @@ -1405,6 +1414,7 @@ impl exprCoder { fn handleStructSubMoveSemantics(mut &self, mut m: &StructSubIdentExprModel): (ordinary: bool) { const tempVar = "__jule_temp" const retVar = "__jule_result" + lvalue := self.flags&exprFlag.lvalue == exprFlag.lvalue mut deref := false mut dropKind := m.Expr.Kind match type m.Expr.Model { @@ -1422,7 +1432,10 @@ impl exprCoder { ret true } // guaranteed: type abviously needs to be dropped - self.oc.write("(*({ auto ") + if lvalue { + self.oc.write("(*") + } + self.oc.write("({ auto ") self.oc.write(tempVar) self.oc.write(" = ") self.possibleRefExpr(uem.Expr.Model) @@ -1440,7 +1453,10 @@ impl exprCoder { ret true } // guaranteed: type abviously needs to be dropped - self.oc.write("(*({ auto ") + if lvalue { + self.oc.write("(*") + } + self.oc.write("({ auto ") self.oc.write(tempVar) self.oc.write(" = ") self.possibleRefExpr(m.Expr.Model) @@ -1448,9 +1464,15 @@ impl exprCoder { } // guaranteed: type abviously needs to be dropped self.oc.tc.kind(self.oc.Buf, m.Field.Kind) - self.oc.write(" *") + self.oc.write(" ") + if lvalue { + self.oc.write("*") + } self.oc.write(retVar) - self.oc.write(" = &(") + self.oc.write(" = ") + if lvalue { + self.oc.write("&(") + } self.oc.write(tempVar) if deref { self.oc.write("->") @@ -1458,11 +1480,21 @@ impl exprCoder { self.oc.write(".") } identCoder.field(self.oc.Buf, m.Field.Decl) - self.oc.write("); ") + if lvalue { + self.oc.write(")") + } + self.oc.write("; ") + if !lvalue { + self.oc.sc.handleCopyS("&" + retVar, m.Field.Kind) + self.oc.write("; ") + } self.oc.sc.dh.dropModel(tempVar, dropKind) self.oc.write("(") self.oc.write(retVar) - self.oc.write("); }))") + self.oc.write("); })") + if lvalue { + self.oc.write(")") + } ret false } @@ -2145,6 +2177,7 @@ impl exprCoder { |: self.oc.write("") } + self.flags = exprFlag.NA } // Writes default initialization of struct field. diff --git a/src/julec/obj/cxx/scope.jule b/src/julec/obj/cxx/scope.jule index 6b332c9a1..7491e6628 100644 --- a/src/julec/obj/cxx/scope.jule +++ b/src/julec/obj/cxx/scope.jule @@ -512,6 +512,7 @@ impl scopeCoder { self.oc.write("]") ret } + self.oc.ec.flags |= exprFlag.lvalue self.oc.ec.possibleRefExpr(model) }