Skip to content

Commit

Permalink
Merge branch 'patch' of https://github.com/julelang/jule into patch
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Apr 8, 2024
2 parents 396cc35 + 1187d37 commit 465c99a
Show file tree
Hide file tree
Showing 17 changed files with 624 additions and 763 deletions.
44 changes: 38 additions & 6 deletions api/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,49 @@ namespace jule

class MapKeyHasher
{
private:
class fnv1a
{
public:
mutable jule::U64 sum;

fnv1a(void) noexcept
{
this->reset();
}

inline void reset(void) const noexcept
{
this->sum = 14695981039346656037LLU;
}

void write(const jule::Slice<jule::U8> &data) const noexcept
{
for (const jule::U8 &b : data)
{
this->sum ^= static_cast<jule::U64>(b);
this->sum *= 1099511628211LLU;
}
}
};

private:
const jule::MapKeyHasher::fnv1a hasher;

public:
size_t operator()(const jule::Str &key) const
inline size_t operator()(const jule::Slice<jule::U8> &key) const noexcept {
this->hasher.reset();
this->hasher.write(key);
return this->hasher.sum;
}

inline size_t operator()(const jule::Str &key) const noexcept
{
size_t hash = 0;
for (jule::Int i = 0; i < key.len(); ++i)
hash += key.buffer[i] % 7;
return hash;
return this->operator()(key.fake_slice());
}

template <typename T>
inline size_t operator()(const T &obj) const
inline size_t operator()(const T &obj) const noexcept
{
return this->operator()(jule::to_str<T>(obj));
}
Expand Down
6 changes: 3 additions & 3 deletions api/str.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace jule
class Str
{
public:
std::basic_string<jule::U8> buffer;
mutable std::basic_string<jule::U8> buffer;

static jule::Str alloc(const jule::Int &len) noexcept {
if (len < 0)
Expand Down Expand Up @@ -217,9 +217,9 @@ namespace jule
return this->buffer.empty();
}

jule::Slice<jule::U8> fake_slice(void) {
jule::Slice<jule::U8> fake_slice(void) const {
jule::Slice<jule::U8> slice;
slice.data.alloc = this->begin();
slice.data.alloc = const_cast<Iterator>(this->begin());
slice.data.ref = nullptr;
slice._slice = slice.data.alloc;
slice._len = this->len();
Expand Down
3 changes: 1 addition & 2 deletions api/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ namespace jule
using U16 = std::uint16_t;
using U32 = std::uint32_t;
using U64 = std::uint64_t;
using Uintptr = std::uintptr_t;
typedef float F32;
typedef double F64;
typedef bool Bool;

#ifdef ARCH_X32
using Uint = std::uint32_t;
using Int = std::int32_t;
using Uintptr = std::uint32_t;
#else
using Uint = std::uint64_t;
using Int = std::int64_t;
using Uintptr = std::uint64_t;
#endif

constexpr decltype(nullptr) nil = nullptr;
Expand Down
5 changes: 0 additions & 5 deletions src/julec/compile.jule
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,6 @@ fn compile_command(mut &args: []str) {
if main == nil {
throw(logf(LogMsg.NoEntryPoint))
}
main.statically = true // Mark used for deadcode elimination.
}
let mut init = ir.main.find_fn(INIT_FN, CPP_LINKED)
if init != nil {
init.statically = true // Mark used for deadcode elimination.
}

apply_target_independent_optimizations(ir)
Expand Down
86 changes: 42 additions & 44 deletions src/julec/obj/cxx/ident.jule
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,24 @@ struct IdentCoder {}
impl IdentCoder {
const Self = "_self_"

// Returns specified identifer as JuleC identifer.
// Equavalents: "JULEC_ID(" + ident + ")" of JuleC API.
static fn to_ident(ident: str): str {
ret "_" + ident
}

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

// Returns cpp output identifier form of given identifier.
//
// Parameters:
// - ident: Identifier.
// - addr: Pointer address of package file handler.
static fn to_out(ident: str, addr: uintptr): str {
static fn to_out(&ident: str, addr: uintptr): str {
if addr != 0 {
let mut obj = IdentCoder.addr(addr)
let mut obj = make(str, 40)
obj += "_"
obj += conv::fmt_uint(u64(addr), 0xF)
obj += "_"
obj += ident
ret obj
}
ret IdentCoder.to_ident(ident)
let mut obj = make(str, ident.len + 1)
obj += "_"
obj += ident
ret obj
}

// Returns cpp output local identifier form of fiven identifier.
Expand All @@ -57,12 +51,14 @@ impl IdentCoder {
// - row: Row of definition.
// - col: Column of definition.
// - ident: Identifier of definition.
static fn to_local(row: int, col: int, ident: str): str {
let mut obj = conv::itoa(row)
static fn to_local(row: int, col: int, &ident: str): str {
let mut obj = make(str, 40)
obj += "_"
obj += conv::itoa(row)
obj += conv::itoa(col)
obj += "_"
obj += ident
ret IdentCoder.to_ident(obj)
ret obj
}

// Returns output identifier of function.
Expand All @@ -85,22 +81,14 @@ impl IdentCoder {
}

// Returns output identifier of function instance.
static fn func_ins(mut &f: &FnIns): str {
static fn func_ins(&f: &FnIns): str {
if f.is_builtin() {
ret "jule::" + f.decl.ident
}
if f.decl.cpp_linked || f.generics.len == 0 {
ret IdentCoder.func(f.decl)
}
for (i, mut ins) in f.decl.instances {
if ins.same(f) {
let mut obj = IdentCoder.func(f.decl)
obj += "_"
obj += conv::itoa(i)
ret obj
}
}
ret "__?__"
ret IdentCoder.to_out(f.decl.ident, uintptr(f))
}

// Returns output identifier of trait.
Expand Down Expand Up @@ -137,19 +125,11 @@ impl IdentCoder {
}

// Returns output identifier of structure instance.
static fn structure_ins(mut &s: &StructIns): str {
static fn structure_ins(&s: &StructIns): str {
if s.decl.cpp_linked || s.generics.len == 0 {
ret IdentCoder.structure(s.decl)
}
for (i, mut ins) in s.decl.instances {
if ins.same(s) {
let mut obj = IdentCoder.structure(s.decl)
obj += "_"
obj += conv::itoa(i)
ret obj
}
}
ret "__?__"
ret IdentCoder.to_out(s.decl.ident, uintptr(s))
}

// Returns output identifier of field.
Expand Down Expand Up @@ -181,31 +161,49 @@ impl IdentCoder {

// Returns begin label identifier of iteration.
static fn iter_begin(it: uintptr): str {
ret "_iter_begin_" + conv::fmt_uint(u64(it), 0xF)
let mut obj = make(str, 30)
obj += "_iter_begin_"
obj += conv::fmt_uint(u64(it), 0xF)
ret obj
}

// Returns end label identifier of iteration.
static fn iter_end(it: uintptr): str {
ret "_iter_end_" + conv::fmt_uint(u64(it), 0xF)
let mut obj = make(str, 30)
obj += "_iter_end_"
obj += conv::fmt_uint(u64(it), 0xF)
ret obj
}

// Returns next label identifier of iteration.
static fn iter_next(it: uintptr): str {
ret "_iter_next_" + conv::fmt_uint(u64(it), 0xF)
let mut obj = make(str, 30)
obj += "_iter_next_"
obj += conv::fmt_uint(u64(it), 0xF)
ret obj
}

// Returns label identifier.
static fn label(ident: str): str {
ret "_julec_label_" + ident
static fn label(&ident: str): str {
let mut obj = make(str, 30)
obj += "_julec_label_"
obj += ident
ret obj
}

// Returns end label identifier of match-case.
static fn match_end(m: uintptr): str {
ret "_match_end_" + conv::fmt_uint(u64(m), 0xF)
let mut obj = make(str, 30)
obj += "_match_end_"
obj += conv::fmt_uint(u64(m), 0xF)
ret obj
}

// Returns begin label identifier of case.
static fn case_begin(c: uintptr): str {
ret "_case_begin_" + conv::fmt_uint(u64(c), 0xF)
let mut obj = make(str, 30)
obj += "_case_begin_"
obj += conv::fmt_uint(u64(c), 0xF)
ret obj
}
}
4 changes: 3 additions & 1 deletion src/julec/obj/cxx/type.jule
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ impl TypeCoder {

// Returns given identifier as Jule type identifier.
static fn to_type(mut id: str): str {
id = types::real_kind_of(id)
if id != types::TypeKind.Uintptr {
id = types::real_kind_of(id)
}
if 97 <= id[0] && id[0] <= 122 {
id[0] -= 32 // To upper first byte.
}
Expand Down
Loading

0 comments on commit 465c99a

Please sign in to comment.