Skip to content

Commit

Permalink
compiler: use structure to generate code for scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Feb 5, 2024
1 parent d1817fb commit 01fa4e5
Show file tree
Hide file tree
Showing 3 changed files with 645 additions and 658 deletions.
2 changes: 1 addition & 1 deletion src/julec/obj/cxx/ident.jule
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl IdentCoder {
}

// Returns label identifier.
static fn to_label(ident: str): str {
static fn label(ident: str): str {
ret "_julec_label_" + ident
}

Expand Down
107 changes: 48 additions & 59 deletions src/julec/obj/cxx/object.jule
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
// Use of this source code is governed by a BSD 3-Clause
// license that can be found in the LICENSE file.

use env
use obj::{IR}

use conv for std::conv
use std::jule::{VERSION}
use std::jule::build::{
Directive,
Derive,
INIT_FN,
PATH_API,
is_std_header_path,
is_valid_header_ext,
}
Expand All @@ -21,8 +28,13 @@ use std::jule::sema::{
Trait,
Struct,
FieldIns,
Var,
StructIns,
Fn,
FnIns,
}
use strings for std::strings
use std::time::{Time}

struct ObjectCoder {
ir: &IR
Expand Down Expand Up @@ -283,6 +295,41 @@ impl ObjectCoder {
obj = obj[:obj.len-1] // Remove last comma.
ret obj
}

// Generats C++ code of variable with initialize expression.
fn var_init_expr(mut self, mut &v: &Var, init: str): str {
let mut obj = ""
if v.statically {
obj += "static "
}

obj += TypeCoder.kind(v.kind.kind)
obj += " "
if v.reference {
obj += "&"
}
obj += IdentCoder.var(v)
if init != "" {
obj += " = "
obj += init
}
obj += ";"
ret obj
}

// Generates C++ code of variable.
fn var(mut self, mut v: &Var): str {
if is_ignore_ident(v.ident) {
ret ""
}
if v.value != nil && v.value.expr != nil {
if v.value.data.model != nil {
ret self.var_init_expr(v, self.ec.val(v.value))
}
ret self.var_init_expr(v, "")
}
ret self.var_init_expr(v, self.ec.init_expr(v.kind.kind))
}
}

fn is_cpp_header_file(path: str): bool {
Expand All @@ -294,29 +341,6 @@ fn is_cpp_header_file(path: str): bool {
}

/*
use env

use conv for std::conv
use std::jule::{VERSION}
use std::jule::build::{
Directive,
Derive,
INIT_FN,
PATH_API,
is_valid_cpp_ext,
}
use std::jule::lex::{
TokenKind,
}
use std::jule::sema::{
ImportInfo,
Var,
StructIns,
Fn,
FnIns,
BUILTIN_TRAIT_DISPOSE,
}
use std::time::{Time}

impl ObjectCoder {
// Generates C++ declaration code of field.
Expand Down Expand Up @@ -605,7 +629,7 @@ impl ObjectCoder {
obj += indent()
obj += gen_fn_decl_head(c, method)
obj += gen_params_prototypes(c.params)
obj += CPP_ST_TERM + "\n"
obj += ";\n"
}
ret obj
}
Expand Down Expand Up @@ -652,41 +676,6 @@ impl ObjectCoder {
ret obj
}

// Generats C++ code of variable with initialize expression.
fn gen_var_init_expr(mut self, mut &v: &Var, init: str): str {
let mut obj = ""
if v.statically {
obj += "static "
}

obj += gen_type_kind(v.kind.kind)
obj += " "
if v.reference {
obj += "&"
}
obj += var_out_ident(v)
if init != "" {
obj += " = "
obj += init
}
obj += CPP_ST_TERM
ret obj
}

// Generates C++ code of variable.
fn gen_var(mut self, mut v: &Var): str {
if is_ignore_ident(v.ident) {
ret ""
}
if v.value != nil && v.value.expr != nil {
if v.value.data.model != nil {
ret gen_var_init_expr(v, gen_val(v.value))
}
ret gen_var_init_expr(v, "")
}
ret gen_var_init_expr(v, get_init_expr(v.kind.kind))
}

fn gen_pkg_globals(mut self, mut &p: &Package, mut &global_initializers: str): str {
let mut obj = ""
for (_, mut f) in p.files {
Expand Down
Loading

0 comments on commit 01fa4e5

Please sign in to comment.