Skip to content

Commit

Permalink
compiler: minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Jul 26, 2024
1 parent ffec721 commit 6f1500d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 40 deletions.
18 changes: 9 additions & 9 deletions src/julec/obj/cxx/expr.jule
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ impl exprCoder {
let lit = cstrLit(bytes)
self.oc.write(typeCoder.Str)
self.oc.write("(")
self.oc.write(lit)
self.oc.writeR(lit)
self.oc.write(", ")
self.oc.write(len)
self.oc.writeR(len)
self.oc.write(")")
}

Expand Down Expand Up @@ -264,7 +264,7 @@ impl exprCoder {
self.oc.write("(")
self.possibleRefExpr(m.Left.Model)
self.oc.write(" ")
self.oc.write(m.Op.Kind)
self.oc.writeR(m.Op.Kind)
self.oc.write(" ")
self.possibleRefExpr(m.Right.Model)
self.oc.write(")")
Expand Down Expand Up @@ -315,7 +315,7 @@ impl exprCoder {
ret
}
self.oc.write("(")
self.oc.write(m.Op.Kind)
self.oc.writeR(m.Op.Kind)
self.oc.write("(")
self.possibleRefExpr(m.Expr.Model)
self.oc.write("))")
Expand Down Expand Up @@ -716,15 +716,15 @@ impl exprCoder {
if m.Func.Params[i].Decl.Reference {
self.oc.write("&")
}
self.oc.write(name)
self.oc.writeR(name)
self.oc.write(" = ")
self.possibleRefExpr(arg)
self.oc.write(";\n")
let argS: any = name
m.Args[i] = unsafe { *(*ExprModel)(&argS) }
}
self.oc.indent()
self.oc.write(head)
self.oc.writeR(head)
self.oc.write("](void) mutable -> void {\n")
self.oc.addIndent()
self.oc.indent()
Expand Down Expand Up @@ -958,7 +958,7 @@ impl exprCoder {
}

fn commonIdent(mut &self, m: &CommonIdentExprModel) {
self.oc.write(m.Ident)
self.oc.writeR(m.Ident)
}

fn commonSub(mut &self, mut m: &CommonSubIdentExprModel) {
Expand All @@ -977,7 +977,7 @@ impl exprCoder {
|:
self.oc.write(".")
}
self.oc.write(m.Ident)
self.oc.writeR(m.Ident)
}

fn array(mut &self, mut m: &ArrayExprModel) {
Expand Down Expand Up @@ -1304,7 +1304,7 @@ impl exprCoder {

fn backendEmit(mut &self, mut m: &BackendEmitExprModel) {
if len(m.Exprs) == 0 {
self.oc.write(m.Code)
self.oc.writeR(m.Code)
ret
}
let n = len(self.oc.Obj)
Expand Down
52 changes: 28 additions & 24 deletions src/julec/obj/cxx/object.jule
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ impl ObjectCoder {
self.Obj += s
}

fn writeR(mut &self, &s: str) {
self.Obj += s
}

// Increase indentation.
fn addIndent(mut &self) {
self.indentBuffer += indentKind
Expand Down Expand Up @@ -305,7 +309,7 @@ impl ObjectCoder {
ident += conv::FmtUint(u64(uintptr(t2)), 0xF)
ident += "_to_"
ident += conv::FmtUint(u64(uintptr(t1)), 0xF)
self.write(ident)
self.writeR(ident)

// Lookup and push if this match is not exist.
for _, m in self.traitCastMap {
Expand Down Expand Up @@ -388,9 +392,9 @@ impl ObjectCoder {
self.write("/")
self.write(conv::FmtUint(abs.Year, 10))
self.write(" (DD/MM/YYYY) UTC\n//\n// Recomended Compile Command;\n// ")
self.write(self.info.Compiler)
self.writeR(self.info.Compiler)
self.write(" ")
self.write(self.info.CompilerCommand)
self.writeR(self.info.CompilerCommand)
self.write("\n\n")

if env::Production {
Expand All @@ -408,7 +412,7 @@ impl ObjectCoder {
self.links()

self.write("\n\n#include \"")
self.write(build::PathApi)
self.writeR(build::PathApi)
self.write("\"\n\n")
}

Expand All @@ -419,11 +423,11 @@ impl ObjectCoder {
continue
| build::IsStdHeaderPath(used.Path):
self.write("#include ")
self.write(used.Path)
self.writeR(used.Path)
self.write("\n")
| build::IsValidHeaderExt(path::Ext(used.Path)):
self.write("#include \"")
self.write(used.Path)
self.writeR(used.Path)
self.write("\"\n")
}
}
Expand Down Expand Up @@ -595,7 +599,7 @@ impl ObjectCoder {
self.write("inline ")
}
self.write("bool operator==(")
self.write(ident)
self.writeR(ident)
self.write(" _other) {")
if len(s.Fields) > 0 {
self.addIndent()
Expand All @@ -618,9 +622,9 @@ impl ObjectCoder {
self.indent()
self.write("this->")
let fIdent = identCoder.field(f.Decl)
self.write(fIdent)
self.writeR(fIdent)
self.write(" == _other.")
self.write(fIdent)
self.writeR(fIdent)
}
self.doneIndent()
if !writed {
Expand All @@ -645,7 +649,7 @@ impl ObjectCoder {
self.write("inline ")
}
self.write("bool operator!=(")
self.write(ident)
self.writeR(ident)
self.write(" _other) { return !this->operator==(_other); }\n\n")
}

Expand All @@ -663,19 +667,19 @@ impl ObjectCoder {
self.write("inline ")
}
if assignment {
self.write(ident)
self.writeR(ident)
self.write("&")
} else {
if f.Result.Prim() == nil {
// If result type is not primitive, always structure's itself.
self.write(ident)
self.writeR(ident)
} else {
// Logical.
self.write(typeCoder.Bool)
}
}
self.write(" operator")
self.write(op)
self.writeR(op)
self.write("(")
if !unary {
let mut p = f.Params[1]
Expand Down Expand Up @@ -749,7 +753,7 @@ impl ObjectCoder {
self.write("struct ")
let outIdent = identCoder.structureIns(s)

self.write(outIdent)
self.writeR(outIdent)
self.write(" {\n")

self.addIndent()
Expand All @@ -765,7 +769,7 @@ impl ObjectCoder {

// Default constructor.
self.indent()
self.write(outIdent)
self.writeR(outIdent)
self.write("(void) = default;\n\n")

self.structureDeriveDefsDecls(s)
Expand Down Expand Up @@ -1085,11 +1089,11 @@ impl ObjectCoder {
let mIdent = identCoder.func(m)
self.indent()
self.write(".")
self.write(mIdent)
self.writeR(mIdent)
self.write("=")
self.write(mIdent)
self.writeR(mIdent)
self.write("_")
self.write(hash.t.Ident)
self.writeR(hash.t.Ident)
self.write("_")
self.write(conv::Itoa(hash.i))
self.write(",\n")
Expand All @@ -1108,9 +1112,9 @@ impl ObjectCoder {
self.write("};\n")
}
self.write("static ")
self.write(ident)
self.writeR(ident)
self.write("MptrData ")
self.write(ident)
self.writeR(ident)
self.write("_mptr_data[] = {\n")
old = hash.t
self.addIndent()
Expand Down Expand Up @@ -1183,9 +1187,9 @@ impl ObjectCoder {
let ident = identCoder.field(f.Decl)
self.indent()
self.write("clone.")
self.write(ident)
self.writeR(ident)
self.write(" = jule::clone(this->")
self.write(ident)
self.writeR(ident)
self.write(");\n")
}
self.indent()
Expand All @@ -1210,13 +1214,13 @@ impl ObjectCoder {
self.write("(&_Src);\n")
} else {
self.write(`_Stream << "`)
self.write(s.Decl.Ident)
self.writeR(s.Decl.Ident)
self.write("{\";\n")

for (i, mut f) in s.Fields {
self.indent()
self.write(`_Stream << "`)
self.write(f.Decl.Ident)
self.writeR(f.Decl.Ident)
self.write(`:`)

// Skip binded struct kinds.
Expand Down
14 changes: 7 additions & 7 deletions src/julec/obj/cxx/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl scopeCoder {
}
self.oc.write("end();\n")
self.oc.indent()
self.oc.write(begin)
self.oc.writeR(begin)
self.oc.write(":;\n")
self.oc.indent()
self.oc.write("if (it != expr_end) {\n")
Expand Down Expand Up @@ -153,7 +153,7 @@ impl scopeCoder {
self.scope(it.Scope)
self.oc.write("\n")
self.oc.indent()
self.oc.write(next)
self.oc.writeR(next)
self.oc.write(":;\n")
self.oc.indent()
self.oc.write("++it;\n")
Expand All @@ -164,7 +164,7 @@ impl scopeCoder {
self.oc.indent()
}
self.oc.write("goto ")
self.oc.write(begin)
self.oc.writeR(begin)
self.oc.write(";\n")

// Close if.
Expand Down Expand Up @@ -201,13 +201,13 @@ impl scopeCoder {
self.scope(it.Scope)
self.oc.write("\n")
self.oc.indent()
self.oc.write(next)
self.oc.writeR(next)
self.oc.write(":;\n")
self.oc.indent()
self.oc.write("++it;\n")
self.oc.indent()
self.oc.write("goto ")
self.oc.write(begin)
self.oc.writeR(begin)
self.oc.write(";\n")

// Close if.
Expand Down Expand Up @@ -336,12 +336,12 @@ impl scopeCoder {
self.oc.write("(")
self.oc.ec.possibleRefExpr(p.Expr)
self.oc.write(")")
self.oc.write(p.Op)
self.oc.writeR(p.Op)
}

fn assign(mut &self, mut a: &Assign) {
self.oc.ec.possibleRefExpr(a.L.Model)
self.oc.write(a.Op.Kind)
self.oc.writeR(a.Op.Kind)
self.oc.ec.possibleRefExpr(a.R.Model)
}

Expand Down

0 comments on commit 6f1500d

Please sign in to comment.