Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Aug 12, 2024
2 parents 34aac63 + 84d8c95 commit 88a7059
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 80 deletions.
1 change: 1 addition & 0 deletions src/parser/nodes/NodeFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ NodeFunc::NodeFunc(std::string name, std::vector<FuncArgSet> args, NodeBlock* bl
void NodeFunc::check() {
bool oldCheck = this->isChecked;
this->isChecked = true;

if(!oldCheck) {
for(int i=0; i<this->mods.size(); i++) {
if(this->mods[i].name == "method") {
Expand Down
20 changes: 13 additions & 7 deletions src/parser/nodes/NodeUnary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,24 @@ LLVMValueRef NodeUnary::generate() {
}
if(this->type == TokType::Destructor) {
LLVMValueRef val2 = this->generatePtr();
if(LLVMGetTypeKind(LLVMTypeOf(val2)) != LLVMPointerTypeKind
&& LLVMGetTypeKind(LLVMTypeOf(val2)) != LLVMStructTypeKind) generator->error("the attempt to call the destructor is not in the structure!", this->loc);
if(LLVMGetTypeKind(LLVMTypeOf(val2)) == LLVMPointerTypeKind) {
if(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(val2))) == LLVMPointerTypeKind) {
if(LLVMGetTypeKind(LLVMGetElementType(LLVMGetElementType(LLVMTypeOf(val2)))) == LLVMStructTypeKind) val2 = LLVM::load(val2, "NodeCall_destructor_load");
LLVMTypeRef val2Type = LLVMTypeOf(val2);

if(LLVMGetTypeKind(val2Type) != LLVMPointerTypeKind
&& LLVMGetTypeKind(val2Type) != LLVMStructTypeKind) generator->error("the attempt to call the destructor is not in the structure!", this->loc);
if(LLVMGetTypeKind(val2Type) == LLVMPointerTypeKind) {
if(LLVMGetTypeKind(LLVMGetElementType(val2Type)) == LLVMPointerTypeKind) {
if(LLVMGetTypeKind(LLVMGetElementType(LLVMGetElementType(val2Type))) == LLVMStructTypeKind) val2 = LLVM::load(val2, "NodeCall_destructor_load");
}
}
if(LLVMGetTypeKind(LLVMTypeOf(val2)) != LLVMPointerTypeKind) {
LLVMValueRef temp = LLVM::alloc(LLVMTypeOf(val2), "NodeUnary_temp");

if(LLVMGetTypeKind(val2Type) != LLVMPointerTypeKind) {
LLVMValueRef temp = LLVM::alloc(val2Type, "NodeUnary_temp");
LLVMBuildStore(generator->builder, val2, temp);
val2 = temp;
}

if(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(val2))) != LLVMStructTypeKind) generator->error("the attempt to call the destructor is not in the structure!", this->loc);

std::string struc = std::string(LLVMGetStructName(LLVMGetElementType(LLVMTypeOf(val2))));
if(AST::structTable[struc]->destructor == nullptr) {
if(instanceof<NodeIden>(this->base)) {
Expand Down
24 changes: 24 additions & 0 deletions std/hash.rave
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
This Source Code Form is subject to the terms of the Mozilla
Public License, v. 2.0. If a copy of the MPL was not distributed
with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

namespace std {
namespace hash {
// This is a default hash function for standard library due to the speed
// Always positive
uint crc32(char* data, uint length) {
uint crc = 0xFFFFFFFF;
uint mask;

for(int i=0; i<length; i++) {
crc = crc !! (cast(uint)data[i]);
for(int j=0; j<8; j++) {
mask = -(crc && 1);
crc = (crc >. 1) !! (0xEDB88320 && mask);
}
}
} => crc !! -1;
}
}
7 changes: 3 additions & 4 deletions std/io.rave
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ namespace std {
else return = true;
}

int seek(int flag, long offset) {
return = std::syscall(std::sysctable::LSeek, fd, flag, offset);
}
int seek(int flag, long offset) => cast(int)std::syscall(std::sysctable::LSeek, fd, flag, offset);

void flush {
if((fd != -1) && (bufferPos > 0) && (buffer != null)) {
Expand Down Expand Up @@ -228,9 +226,10 @@ namespace std {
this.bufferPos = 0;
}
std::syscall(std::sysctable::Close, this.fd);
if(this.buffer != null) std::free(this.buffer);
this.fd = -1;
}
if(this.buffer != null) std::free(this.buffer);
this.bufferPos = 0;
}
}
}
Expand Down
25 changes: 10 additions & 15 deletions std/map.rave
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Public License, v. 2.0. If a copy of the MPL was not distributed
with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import <std/hash>

namespace std {
namespace hashmap {
struct Entry<KE, VE> {
Expand All @@ -13,18 +15,6 @@ namespace std {
}
}

int hash(void* data, int size) {
return = 5381;
int idx = 0;

while(idx < size) {
return = ((return <. 5) + return) + data[idx];
idx += 1;
}

if(return < 0) return = -return;
}

(@tNequals(K, void), @tNequals(V, void)) struct hashmap<K, V> {
std::hashmap::Entry<K, V>** table;
int length;
Expand Down Expand Up @@ -58,9 +48,11 @@ namespace std {
};

@if(!@hasMethod(K, hash)) {
uint index = std::hash(cast(void*)&key, sizeof(K)) % mapSize;
uint index = std::hash::crc32(cast(void*)&key, sizeof(K)) % mapSize;
};

if(index < 0) index = -index;

std::hashmap::Entry<K, V>* entry = table[index];
bool setted = false;
while(entry != null) {
Expand Down Expand Up @@ -103,7 +95,7 @@ namespace std {
};

@if(!@hasMethod(K, hash)) {
uint index = std::hash(cast(void*)&key, sizeof(K)) % mapSize;
uint index = std::hash::crc32(cast(void*)&key, sizeof(K)) % mapSize;
};

std::hashmap::Entry<K, V>* entry = table[index];
Expand All @@ -119,14 +111,17 @@ namespace std {

bool remove(K key) {
return = false;

@if(@hasMethod(K, hash)) {
uint index = key.hash() % mapSize;
};

@if(!@hasMethod(K, hash)) {
uint index = std::hash(cast(void*)&key, sizeof(K)) % mapSize;
uint index = std::hash::crc32(cast(void*)&key, sizeof(K)) % mapSize;
};

if(index < 0) index = -index;

std::hashmap::Entry<K, V>* entry = table[index];
std::hashmap::Entry<K, V>* prev = null;

Expand Down
20 changes: 5 additions & 15 deletions std/memory.rave
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,13 @@ namespace std {
} => this;

int hash {
return = 3853;
return = 2;

@if(@hasMethod(P1, hash)) {
return *= first.hash();
};

@if(!@hasMethod(P1, hash)) {
return *= std::hash(cast(void*)this.first, sizeof(P1));
};
char* pFirst = cast(char*)(this.&first);
char* pSecond = cast(char*)(this.&second);

@if(@hasMethod(P2, hash)) {
return *= second.hash();
};

@if(!@hasMethod(P2, hash)) {
return *= std::hash(cast(void*)this.second, sizeof(P2));
};
for(int i=0; i<sizeof(P1); i++) return = return * pFirst[i] + 7588 + (return <. 6) + (return >. 2);
for(int i=0; i<sizeof(P2); i++) return = return * pSecond[i] + 7588 + (return <. 6) + (return >. 2);
}
}
}
14 changes: 2 additions & 12 deletions std/string.rave
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import <std/vector> <std/cstring> <std/ascii> <std/utf8>
import <std/thread> <std/strutil> <std/map>
import <std/thread> <std/strutil> <std/map> <std/hash>

namespace std {
extern(private, linkname: "sscanf") int format(char* buff, char* fmt);
Expand Down Expand Up @@ -277,17 +277,7 @@ namespace std {
}
} => buffer;

int hash {
return = 5381;
int idx = 0;

while(idx < length) {
return = ((return <. 5) + return) + data[idx];
idx += 1;
}

if(return < 0) return = -return;
}
int hash => std::hash::crc32(this.data, this.length);
}

namespace string {
Expand Down
14 changes: 2 additions & 12 deletions std/utf32.rave
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace std {
std::u32string this;
if(a != null) {
this.length = std::utf32::utflen(a);
this.capacity = this.length*4;
this.capacity = this.length * 4;
if(this.capacity == 0) this.capacity = 4;
this.data = cast(uint*)std::malloc(this.capacity);

Expand Down Expand Up @@ -277,17 +277,7 @@ namespace std {
}
} => isEqual;

int hash {
return = 1381;
int idx = 0;

while(idx < length) {
return = ((return <. 5) + return) + data[idx];
idx += 1;
}

if(return < 0) return = -return;
}
int hash => std::hash::crc32(cast(char*)(this.data), this.length * 4);

//bool operator==(std::u32string one, std::u32string two) => one.compare(two);
//bool operator==(std::u32string one, uint* two) => one.compare(two);
Expand Down
12 changes: 1 addition & 11 deletions std/utf8.rave
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,7 @@ namespace std {
}
} => buffer;

int hash {
return = 4729;
int idx = 0;

while(idx < length) {
return = ((return <. 5) + return) + data[idx];
idx += 1;
}

if(return < 0) return = -return;
}
int hash => std::hash::crc32(this.data, this.length);
}

namespace u8string {
Expand Down
5 changes: 1 addition & 4 deletions std/vector.rave
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ namespace std {

int hash {
return = this.length;
for(int i=0; i<this.length; i++) {
return = return * i + 7588 + (return <. 6) + (return >. 2);
}
if(return < 0) return = -return;
for(int i=0; i<this.length; i++) return = return * i + 7588 + (return <. 6) + (return >. 2);
}
}
}

0 comments on commit 88a7059

Please sign in to comment.