Skip to content

Commit

Permalink
compiler: minor fix for lvalue handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Sep 15, 2024
1 parent 4c863e6 commit a6daa75
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
45 changes: 39 additions & 6 deletions src/julec/obj/cxx/expr.jule
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -1440,29 +1453,48 @@ 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)
self.oc.write("; ")
}
// 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("->")
} else {
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
}

Expand Down Expand Up @@ -2145,6 +2177,7 @@ impl exprCoder {
|:
self.oc.write("<unimplemented_expression_model>")
}
self.flags = exprFlag.NA
}

// Writes default initialization of struct field.
Expand Down
1 change: 1 addition & 0 deletions src/julec/obj/cxx/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ impl scopeCoder {
self.oc.write("]")
ret
}
self.oc.ec.flags |= exprFlag.lvalue
self.oc.ec.possibleRefExpr(model)
}

Expand Down

0 comments on commit a6daa75

Please sign in to comment.