Skip to content

Commit

Permalink
compiler: update naming of the TypeCoder, and IdentCoder structures
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Feb 5, 2024
1 parent 50df78d commit d1817fb
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 116 deletions.
4 changes: 2 additions & 2 deletions src/julec/obj/cxx/derive.jule
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ struct DeriveCoder {}

impl DeriveCoder {
static fn fn_decl_clone(&s: &Struct): str {
let mut obj = TypeCoder.from_struct(s)
let mut obj = TypeCoder.structure(s)
obj += " clone(void) const "
ret obj
}

static fn fn_def_clone(&s: &Struct): str {
let mut obj = TypeCoder.from_struct(s)
let mut obj = TypeCoder.structure(s)
obj += " " + obj
obj += "::clone(void) const "
ret obj
Expand Down
72 changes: 36 additions & 36 deletions src/julec/obj/cxx/expr.jule
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,19 @@ impl ExprCoder {
if d != nil {
let mut obj = concat_all_parts(d.args...)
obj += "::"
obj += IdentCoder.from_var(m)
obj += IdentCoder.var(m)
ret obj
}
}
ret IdentCoder.from_var(m)
ret IdentCoder.var(m)
}

fn structure(self, m: &Struct): str {
ret TypeCoder.from_struct(m)
ret TypeCoder.structure(m)
}

fn structure_ins(self, mut m: &StructIns): str {
ret TypeCoder.from_struct_ins(m)
ret TypeCoder.structure_ins(m)
}

fn unary(mut self, mut m: &UnaryExprModel): str {
Expand Down Expand Up @@ -328,7 +328,7 @@ impl ExprCoder {
}

fn cpp_structure_lit(mut self, mut m: &StructLitExprModel): str {
let mut obj = "(" + TypeCoder.from_struct_ins(m.strct)
let mut obj = "(" + TypeCoder.structure_ins(m.strct)
obj += "){"
if m.args.len > 0 {
iter:
Expand All @@ -337,7 +337,7 @@ impl ExprCoder {
for (_, mut arg) in m.args {
if arg.field == f {
obj += "."
obj += IdentCoder.from_field(f.decl)
obj += IdentCoder.field(f.decl)
obj += "="
obj += self.expr(arg.expr)
obj += ","
Expand All @@ -346,7 +346,7 @@ impl ExprCoder {
}
continue
}
obj += IdentCoder.from_field(f.decl)
obj += IdentCoder.field(f.decl)
obj += ": "
for (_, mut arg) in m.args {
if arg.field == f {
Expand All @@ -369,7 +369,7 @@ impl ExprCoder {
ret self.cpp_structure_lit(m)
}

let mut obj = IdentCoder.from_struct_ins(m.strct)
let mut obj = IdentCoder.structure_ins(m.strct)
obj += "("
if m.args.len > 0 {
iter:
Expand All @@ -396,7 +396,7 @@ impl ExprCoder {
obj += "_ptr"
}
obj += "<"
obj += IdentCoder.from_struct_ins(m.lit.strct)
obj += IdentCoder.structure_ins(m.lit.strct)
obj += ">("
if !env::PRODUCTION {
obj += "\""
Expand All @@ -413,14 +413,14 @@ impl ExprCoder {
let mut obj = ""
match {
| m.kind.prim() != nil && m.kind.prim().is_any():
obj += TypeCoder.from_kind(m.kind)
obj += TypeCoder.kind(m.kind)
obj += "("
obj += self.model(m.expr)
obj += ")"
| m.expr_kind.ptr() != nil
| m.kind.ptr() != nil:
obj += "(("
obj += TypeCoder.from_kind(m.kind)
obj += TypeCoder.kind(m.kind)
obj += ")("
obj += self.expr(m.expr)
obj += "))"
Expand All @@ -430,23 +430,23 @@ impl ExprCoder {
obj += "."
if env::PRODUCTION {
obj += "operator "
obj += TypeCoder.from_kind(m.kind)
obj += TypeCoder.kind(m.kind)
obj += "()"
} else {
if m.expr_kind.trt() != nil && m.kind.sptr() != nil {
obj += "cast_ptr<"
obj += TypeCoder.from_kind(m.kind.sptr().elem)
obj += TypeCoder.kind(m.kind.sptr().elem)
} else {
obj += "cast<"
obj += TypeCoder.from_kind(m.kind)
obj += TypeCoder.kind(m.kind)
}
obj += ">(\""
obj += gen_loc_info(m.token)
obj += "\")"
}
|:
obj += "static_cast<"
obj += TypeCoder.from_kind(m.kind)
obj += TypeCoder.kind(m.kind)
obj += ">("
obj += self.expr(m.expr)
obj += ")"
Expand Down Expand Up @@ -483,7 +483,7 @@ impl ExprCoder {
if !has_directive(m.func.decl.directives, Directive.Cdef) {
obj += "<"
for (_, mut g) in m.func.generics {
obj += TypeCoder.from_kind(g)
obj += TypeCoder.kind(g)
obj += ","
}
obj = obj[:obj.len-1] // Remove last comma.
Expand Down Expand Up @@ -640,11 +640,11 @@ impl ExprCoder {
}

fn anon_func(mut self, mut m: &AnonFnExprModel): str {
let mut obj = TypeCoder.from_fn(m.func)
let mut obj = TypeCoder.func(m.func)
obj += "([=]"
obj += self.oc.gen_params_ins(m.func.params)
obj += " mutable -> "
obj += TypeCoder.from_fn_ins_result(m.func)
obj += TypeCoder.func_ins_result(m.func)
obj += " "
obj += self.oc.sc.func_scope(m.func)
obj += ")"
Expand All @@ -654,9 +654,9 @@ impl ExprCoder {
fn map(mut self, mut m: &MapExprModel): str {
let mut obj = TypeCoder.to_type("map")
obj += "<"
obj += TypeCoder.from_kind(m.key_kind)
obj += TypeCoder.kind(m.key_kind)
obj += ","
obj += TypeCoder.from_kind(m.val_kind)
obj += TypeCoder.kind(m.val_kind)
obj += ">({"
if m.entries.len > 0 {
for (_, mut pair) in m.entries {
Expand Down Expand Up @@ -708,9 +708,9 @@ impl ExprCoder {
let mut obj = self.model(m.expr)
obj += "."
if m.field != nil {
obj += IdentCoder.from_field(m.field.decl)
obj += IdentCoder.field(m.field.decl)
} else {
obj += IdentCoder.from_fn_ins(m.method)
obj += IdentCoder.func_ins(m.method)
}
ret obj
}
Expand All @@ -727,7 +727,7 @@ impl ExprCoder {
}

fn array(mut self, mut m: &ArrayExprModel): str {
let mut obj = TypeCoder.from_array(m.kind)
let mut obj = TypeCoder.array(m.kind)
if m.elems.len == 0 {
obj += "()"
ret obj
Expand All @@ -750,7 +750,7 @@ impl ExprCoder {
// Returns complete expression model of function instance.
// Usefull for strict type safety.
fn func_ins_common(self, mut m: &FnIns): str {
let mut obj = TypeCoder.from_fn(m)
let mut obj = TypeCoder.func(m)
obj += "("
obj += self.func_ins(m)
obj += ")"
Expand All @@ -764,11 +764,11 @@ impl ExprCoder {
if d != nil {
let mut obj = concat_all_parts(d.args...)
obj += "::"
obj += IdentCoder.from_fn_ins(m)
obj += IdentCoder.func_ins(m)
ret obj
}
}
ret IdentCoder.from_fn_ins(m)
ret IdentCoder.func_ins(m)
}

fn tuple(mut self, mut m: &TupleExprModel): str {
Expand All @@ -784,7 +784,7 @@ impl ExprCoder {

fn new_call(mut self, mut m: &BuiltinNewCallExprModel): str {
let mut obj = "jule::new_ptr<"
obj += TypeCoder.from_kind(m.kind)
obj += TypeCoder.kind(m.kind)
obj += ">("
if m.init != nil {
obj += self.expr(m.init)
Expand Down Expand Up @@ -842,7 +842,7 @@ impl ExprCoder {
obj += "jule::VoidExceptional("
} else {
obj += "jule::Exceptional<"
obj += TypeCoder.from_kind(m.func.result)
obj += TypeCoder.kind(m.func.result)
obj += ">("
}
obj += self.expr(m.err)
Expand All @@ -865,12 +865,12 @@ impl ExprCoder {
obj += ","
obj += self.init_expr(m.kind.slc().elem)
if m.cap != nil {
obj = TypeCoder.from_kind(m.kind) + "::alloc(" + obj
obj = TypeCoder.kind(m.kind) + "::alloc(" + obj
} else {
obj = TypeCoder.from_kind(m.kind) + "::alloc_def(" + obj
obj = TypeCoder.kind(m.kind) + "::alloc_def(" + obj
}
} else {
obj = TypeCoder.from_kind(m.kind) + "::alloc(" + obj
obj = TypeCoder.kind(m.kind) + "::alloc(" + obj
}

obj += ")"
Expand Down Expand Up @@ -961,9 +961,9 @@ impl ExprCoder {
}

fn structure_static(self, mut m: &StructStaticIdentExprModel): str {
let mut obj = IdentCoder.from_struct_ins(m.structure)
let mut obj = IdentCoder.structure_ins(m.structure)
obj += "::"
obj += IdentCoder.from_fn_ins(m.method)
obj += IdentCoder.func_ins(m.method)
ret obj
}

Expand Down Expand Up @@ -1007,13 +1007,13 @@ impl ExprCoder {
| &Data:
ret self.model((&Data)(m).model)
| &TypeKind:
ret TypeCoder.from_kind((&TypeKind)(m))
ret TypeCoder.kind((&TypeKind)(m))
| &Const:
ret self.constant((&Const)(m), false)
| &Var:
ret self.var((&Var)(m))
| &Trait:
ret IdentCoder.from_trait((&Trait)(m))
ret IdentCoder.trait_decl((&Trait)(m))
| &Struct:
ret self.structure((&Struct)(m))
| &StructIns:
Expand Down Expand Up @@ -1120,7 +1120,7 @@ impl ExprCoder {
if enm != nil {
ret self.val(enm.items[0].value)
}
ret TypeCoder.from_kind(t) + "()"
ret TypeCoder.kind(t) + "()"
}
}

Expand Down
28 changes: 14 additions & 14 deletions src/julec/obj/cxx/ident.jule
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl IdentCoder {
}

// Returns cpp output identifier form of pointer address.
static fn from_addr(addr: uintptr): str {
static fn addr(addr: uintptr): str {
ret "_" + conv::fmt_uint(u64(addr), 0xF)
}

Expand All @@ -40,7 +40,7 @@ impl IdentCoder {
// - addr: Pointer address of package file handler.
static fn to_out(ident: str, addr: uintptr): str {
if addr != 0 {
let mut obj = IdentCoder.from_addr(addr)
let mut obj = IdentCoder.addr(addr)
obj += "_"
obj += ident
ret obj
Expand All @@ -63,7 +63,7 @@ impl IdentCoder {
}

// Returns output identifier of function.
static fn from_fn(&f: &Fn): str {
static fn func(&f: &Fn): str {
match {
| f.cpp_linked:
ret f.ident
Expand All @@ -80,16 +80,16 @@ impl IdentCoder {
}

// Returns output identifier of function instance.
static fn from_fn_ins(mut &f: &FnIns): str {
static fn func_ins(mut &f: &FnIns): str {
if f.is_builtin() {
ret "jule::" + f.decl.ident
}
if f.decl.cpp_linked || f.generics.len == 0 {
ret IdentCoder.from_fn(f.decl)
ret IdentCoder.func(f.decl)
}
for (i, mut ins) in f.decl.instances {
if ins.same(f) {
let mut obj = IdentCoder.from_fn(f.decl)
let mut obj = IdentCoder.func(f.decl)
obj += "_"
obj += conv::itoa(i)
ret obj
Expand All @@ -99,23 +99,23 @@ impl IdentCoder {
}

// Returns output identifier of trait.
static fn from_trait(t: &Trait): str {
static fn trait_decl(t: &Trait): str {
if t.is_builtin() {
ret "jule::" + t.ident
}
ret IdentCoder.to_out(t.ident, t.token.file.addr())
}

// Returns output identifier of parameter.
static fn from_param(&p: &Param): str {
static fn param(&p: &Param): str {
if is_anon_ident(p.ident) || is_ignore_ident(p.ident) {
ret ""
}
ret IdentCoder.to_local(p.token.row, p.token.column, p.ident)
}

// Returns output identifier of structure.
static fn from_struct(&s: &Struct): str {
static fn structure(&s: &Struct): str {
if s.cpp_linked {
if has_directive(s.directives, Directive.Typedef) {
ret s.ident
Expand All @@ -126,13 +126,13 @@ impl IdentCoder {
}

// Returns output identifier of structure instance.
static fn from_struct_ins(mut &s: &StructIns): str {
static fn structure_ins(mut &s: &StructIns): str {
if s.decl.cpp_linked || s.generics.len == 0 {
ret IdentCoder.from_struct(s.decl)
ret IdentCoder.structure(s.decl)
}
for (i, mut ins) in s.decl.instances {
if ins.same(s) {
let mut obj = IdentCoder.from_struct(s.decl)
let mut obj = IdentCoder.structure(s.decl)
obj += "_"
obj += conv::itoa(i)
ret obj
Expand All @@ -142,15 +142,15 @@ impl IdentCoder {
}

// Returns output identifier of field.
static fn from_field(&f: &Field): str {
static fn field(&f: &Field): str {
if f.owner.cpp_linked {
ret f.ident
}
ret "_field_" + f.ident
}

// Returns output identifier of variable.
static fn from_var(mut v: &Var): str {
static fn var(mut v: &Var): str {
match {
| v.cpp_linked:
ret v.ident
Expand Down
Loading

0 comments on commit d1817fb

Please sign in to comment.