Skip to content

Commit

Permalink
compiler: fix code generation for multi-return types
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Nov 9, 2024
1 parent 2cd211a commit dd1068c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/julec/obj/cxx/object.jule
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct ObjectCoder {
// Internal buffer which is commonly used.
Buf: strings::Builder

resultProto: strings::Builder // Prototype declarations of the result declarations.
resultDecls: strings::Builder // Struct wrappers for multi-ret function types.
anyObj: strings::Builder // Type handlers and others for the <any> type.
anonObj: strings::Builder // Anonymous functions.
Expand Down Expand Up @@ -109,9 +110,10 @@ struct ObjectCoder {
sc: &scopeCoder
tc: &typeCoder

headPos: int
declPos: int
wrapPos: int
headPos: int
declPos: int
wrapPos: int
plainPos: int

meta: metadata
}
Expand Down Expand Up @@ -430,8 +432,11 @@ impl ObjectCoder {
ret
}
self.resultMap[s] = false
self.resultProto.WriteStr("struct ")!
self.resultDecls.WriteStr("struct ")!
self.resultDecls.WriteStr(s)!
self.resultProto.WriteStr(s)!
self.resultProto.WriteStr(";\n")!
self.resultDecls.WriteStr(" {\n")!
for (i, mut t) in f.Result.Tup().Types {
self.resultDecls.WriteByte(indentKind)!
Expand Down Expand Up @@ -1143,6 +1148,7 @@ impl ObjectCoder {

fn decls(mut &self) {
self.structurePlainDecls()
self.plainPos = self.Buf.Len()
self.structureDecls()
self.headPos = self.Buf.Len()
self.structureMethodDecls()
Expand Down Expand Up @@ -1364,6 +1370,11 @@ impl ObjectCoder {
// Implement RC functions.
self.implementRC()

self.insertBuf(self.resultProto, self.plainPos)
self.headPos += self.resultProto.Len()
self.wrapPos += self.resultProto.Len()
self.declPos += self.resultProto.Len()

self.insertBuf(self.deallocObj, self.wrapPos)
self.wrapPos += self.deallocObj.Len()
self.declPos += self.deallocObj.Len()
Expand Down

0 comments on commit dd1068c

Please sign in to comment.