Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
29b936f
Add a wrapper over memset/memcpy for object initialization to conditi…
mingodad Jan 6, 2022
adc672a
Fix strcmp tests assuming we want return value like in C
mingodad Jan 6, 2022
ccf6eb4
Replace lex_string by lex_identifier because it seems that is the int…
mingodad Jan 6, 2022
c461e7f
Small modification of REGISTER_FUNC macro to simplify it's usage here
mingodad Jan 6, 2022
abdd021
Allow to build without link to libstdc++
mingodad Sep 27, 2022
5373cb0
Add a wrapper to allow silency warnings
mingodad Sep 28, 2022
86a9e81
Add the missing math lib command line
mingodad Sep 28, 2022
ea465c2
Add a conditional wrapper for msvc compiler pragmas
mingodad Sep 28, 2022
c552835
Change class member declarator separator from ':' to '::'
mingodad Sep 28, 2022
c438346
Fix for preserve double precision
mingodad Sep 29, 2022
75fcded
Fix lexer numbers like '-.34'
mingodad Sep 30, 2022
8abdad9
Add lua-regex to CMakeKists.txt
mingodad Sep 30, 2022
8b6467f
Show error message when it fails
mingodad Sep 30, 2022
5649775
More code added to implement "goto" and accept "struct"
mingodad Sep 30, 2022
62b869b
Somehow it seems that the problem was related to source dependencies …
mingodad Oct 1, 2022
8a34423
Almost working the conversion of namespace separator from '.' by '::'
mingodad Oct 1, 2022
ca9d6a9
Allow optional semicolon after class/enum definition
mingodad Oct 1, 2022
5bf4e9a
Added a few more C++ keywords "template, static, public, private, pro…
mingodad Oct 1, 2022
26ebfeb
Add the "inline" keyword and parse and ignore it for now
mingodad Oct 1, 2022
a2db796
It's accepting simple template syntax for class/struct but for functi…
mingodad Oct 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@
config=debug
check=none

REG_CFLAGS=-g -Wall -Wextra
COMP_CFLAGS=-g -Wall -Wextra -D NULLC_NO_EXECUTOR
DYNCALL_FLAGS=-g -Wall -Wextra
STDLIB_FLAGS=-lstdc++ -lm
CXXFLAGS=-fno-exceptions -fno-rtti -fno-threadsafe-statics
OPTFLAGS=-O2 -pipe
#OPTFLAGS=-Os -pipe

REG_CFLAGS=-g -Wall -Wextra $(CXXFLAGS)
COMP_CFLAGS=-g -Wall -Wextra $(CXXFLAGS) -D NULLC_NO_EXECUTOR
DYNCALL_FLAGS=-g -Wall -Wextra $(CXXFLAGS)
#STDLIB_FLAGS=-lstdc++ -lm
STDLIB_FLAGS=-lm
FUZZ_FLAGS=
ALIGN_FLAGS=

ifeq ($(config),release)
REG_CFLAGS += -O2 -fno-omit-frame-pointer -DNDEBUG
COMP_CFLAGS += -O2 -fno-omit-frame-pointer -DNDEBUG
DYNCALL_FLAGS += -O2 -fno-omit-frame-pointer -DNDEBUG
REG_CFLAGS += $(OPTFLAGS) -fno-omit-frame-pointer -DNDEBUG
COMP_CFLAGS += $(OPTFLAGS) -fno-omit-frame-pointer -DNDEBUG
DYNCALL_FLAGS += $(OPTFLAGS) -fno-omit-frame-pointer -DNDEBUG
endif

ifeq ($(config),coverage)
Expand Down Expand Up @@ -129,6 +134,7 @@ STDLIB_TARGETS = \
temp/lib/pugi.o \
temp/lib/random.o \
temp/lib/string.o \
temp/lib/lua-regex.o \
temp/lib/time.o \
temp/lib/typeinfo.o \
temp/lib/vector.o \
Expand Down Expand Up @@ -163,6 +169,9 @@ endif
temp/lib/%.o: NULLC/includes/%.cpp
$(CXX) $(REG_CFLAGS) -c $< -o $@

temp/lib/lua-regex.o: NULLC/includes/lua-regex.c
$(CXX) $(REG_CFLAGS) -c $< -o $@

${LIB_TARGETS}: ${LIB_SOURCES}
$(CXX) $(REG_CFLAGS) -c $(@:temp/%.o=NULLC/%.cpp) -o $@

Expand Down
20 changes: 10 additions & 10 deletions Modules/img/canvas.nc
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ Canvas Canvas(int width, height)
return ret;
}

void Canvas:Clear(float red, green, blue);
void Canvas:Clear(float red, green, blue, alpha);
void Canvas::Clear(float red, green, blue);
void Canvas::Clear(float red, green, blue, alpha);

void Canvas:SetColor(char red, green, blue);
void Canvas:SetAA(bool enable);
void Canvas::SetColor(char red, green, blue);
void Canvas::SetAA(bool enable);

void Canvas:DrawLine(double x1, y1, x2, y2);
void Canvas:DrawRect(int x1, y1, x2, y2);
void Canvas:DrawRect(int x1, y1, x2, y2, double alpha);
void Canvas:DrawPoint(double x, y);
void Canvas:DrawPoint(double x, y, alpha);
void Canvas::DrawLine(double x1, y1, x2, y2);
void Canvas::DrawRect(int x1, y1, x2, y2);
void Canvas::DrawRect(int x1, y1, x2, y2, double alpha);
void Canvas::DrawPoint(double x, y);
void Canvas::DrawPoint(double x, y, alpha);

float[] Canvas:GetData()
float[] Canvas::GetData()
{
return data;
}
28 changes: 14 additions & 14 deletions Modules/old/list.nc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ auto ref list_node.value(auto ref val)
return elem = duplicate(val);
}

void list:list(typeid type = auto ref)
void list::list(typeid type = auto ref)
{
anyType = type == auto ref;
elemType = type;
Expand All @@ -43,7 +43,7 @@ list list(typeid type = auto ref)
return ret;
}

void list:push_back(auto ref elem)
void list::push_back(auto ref elem)
{
if(!anyType && typeid(elem) != (isPointer(elemType) ? elemType.subType() : elemType))
assert(0, "list::push_back argument type (" + typeid(elem).name + ") differs from list element type (" + elemType.name + ")");
Expand All @@ -61,7 +61,7 @@ void list:push_back(auto ref elem)
}
last.parent = this;
}
void list:push_front(auto ref elem)
void list::push_front(auto ref elem)
{
if(!anyType && typeid(elem) != elemType)
assert(0, "list::push_front argument type (" + typeid(elem).name + ") differs from list element type (" + elemType.name + ")");
Expand All @@ -79,7 +79,7 @@ void list:push_front(auto ref elem)
}
last.parent = this;
}
void list:insert(list_node ref it, auto ref elem)
void list::insert(list_node ref it, auto ref elem)
{
if(!anyType && typeid(elem) != elemType)
assert(0, "list::insert argument type (" + typeid(elem).name + ") differs from list element type (" + elemType.name + ")");
Expand All @@ -94,7 +94,7 @@ void list:insert(list_node ref it, auto ref elem)
if(next)
next.prev = it.next;
}
void list:erase(list_node ref it)
void list::erase(list_node ref it)
{
if(list ref(it.parent) != this)
assert(0, "list::insert iterator is from a different list");
Expand All @@ -108,29 +108,29 @@ void list:erase(list_node ref it)
if(it == last)
last = last.prev;
}
void list:clear()
void list::clear()
{
first = last = nullptr;
}
auto ref list:back()
auto ref list::back()
{
assert(first != nullptr, "list::back called on empty list");
return last.elem;
}
auto ref list:front()
auto ref list::front()
{
assert(first != nullptr, "list::front called on empty list");
return first.elem;
}
auto list:begin()
auto list::begin()
{
return first;
}
auto list:end()
auto list::end()
{
return last;
}
int list:empty()
int list::empty()
{
return first == nullptr;
}
Expand All @@ -146,17 +146,17 @@ auto list_iterator(list_node ref start)
ret.curr = start;
return ret;
}
auto list:start()
auto list::start()
{
return list_iterator(this.first);
}
auto list_iterator:next()
auto list_iterator::next()
{
auto ref ret = curr.elem;
curr = curr.next;
return ret;
}
auto list_iterator:hasnext()
auto list_iterator::hasnext()
{
return curr ? 1 : 0;
}
28 changes: 14 additions & 14 deletions Modules/old/vector.nc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ vector vector(typeid type, int reserved = 0)
cConstructVector(ret, type, reserved);
return ret;
}
void vector:vector(typeid type, int reserved = 0)
void vector::vector(typeid type, int reserved = 0)
{
cConstructVector(this, type, reserved);
}
Expand All @@ -28,24 +28,24 @@ class vector_iterator
vector ref arr;
int pos;
}
auto vector:start()
auto vector::start()
{
vector_iterator iter;
iter.arr = this;
iter.pos = 0;
return iter;
}
auto ref vector_iterator:next();
int vector_iterator:hasnext();
auto ref vector_iterator::next();
int vector_iterator::hasnext();

void vector:push_back(auto ref val);
void vector:pop_back();
auto ref vector:front();
auto ref vector:back();
void vector::push_back(auto ref val);
void vector::pop_back();
auto ref vector::front();
auto ref vector::back();
auto ref operator[](vector ref v, int index);
void vector:reserve(int size);
void vector:resize(int size);
void vector:clear();
void vector:destroy();
int vector:size();
int vector:capacity();
void vector::reserve(int size);
void vector::resize(int size);
void vector::clear();
void vector::destroy();
int vector::size();
int vector::capacity();
2 changes: 1 addition & 1 deletion Modules/std/error.nc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ bool try_result.has_error()
return message != nullptr;
}

void try_result:rethrow()
void try_result::rethrow()
{
if(exception)
throw(exception);
Expand Down
6 changes: 3 additions & 3 deletions Modules/std/event.nc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bool bool(event<@T> ref e)
}

// Attach the callback to the event (a single callback can be attached only once)
void event:attach(T callback)
void event::attach(T callback)
{
if(callback in callbacks)
return;
Expand All @@ -130,7 +130,7 @@ void operator+=(event<@T> ref e, @T callback)
}

// Detach the callback from the event
void event:detach(T callback)
void event::detach(T callback)
{
auto it = callbacks.find(callback);
if(it)
Expand All @@ -143,7 +143,7 @@ void operator-=(event<@T> ref e, @T callback)
}

// Detach all callbacks
void event:detach_all()
void event::detach_all()
{
callbacks.clear();
}
Expand Down
48 changes: 24 additions & 24 deletions Modules/std/file.nc
Original file line number Diff line number Diff line change
Expand Up @@ -19,67 +19,67 @@ File File(char[] name, char[] access);

// Open a file with the specified access. Previous file will be closed.
// Use Opened function to tell if the operation was successful
void File:Open(char[] name, char[] access);
void File::Open(char[] name, char[] access);

// Close the file
void File:Close();
void File::Close();

// Check if the file is opened
bool File:Opened();
bool File::Opened();
// Check if the file has ended
bool File:Eof();
bool File::Eof();

// Seek inside the file from the 3 available origin points
void File:Seek(Seek origin, int shift = 0);
void File::Seek(Seek origin, int shift = 0);
// Receive the current position inside the file
long File:Tell();
long File::Tell();

// Get the file size
long File:Size();
long File::Size();

// Write a basic type value to the file (binary)
// functions returns true on success
// if the file was not opened or was closed, these functions will throw an error
bool File:Write(char data);
bool File:Write(short data);
bool File:Write(int data);
bool File:Write(long data);
bool File:Write(float data);
bool File:Write(double data);
bool File::Write(char data);
bool File::Write(short data);
bool File::Write(int data);
bool File::Write(long data);
bool File::Write(float data);
bool File::Write(double data);

// Read a basic type value from the file (binary)
// functions returns true on success
// if the file was not opened or was closed, these functions will throw an error
bool File:Read(char ref data);
bool File:Read(short ref data);
bool File:Read(int ref data);
bool File:Read(long ref data);
bool File:Read(float ref data);
bool File:Read(double ref data);
bool File::Read(char ref data);
bool File::Read(short ref data);
bool File::Read(int ref data);
bool File::Read(long ref data);
bool File::Read(float ref data);
bool File::Read(double ref data);

// Read an array of bytes from the file (array size wil tell how many bytes are read)
// function returns the number of bytes successfully read
// if the file was not opened or was closed, this function will throw an error
int File:Read(char[] arr);
int File::Read(char[] arr);

// Write an array of bytes to the file (array size wil tell how many bytes are written)
// function returns the number of bytes successfully written
// if the file was not opened or was closed, this function will throw an error
int File:Write(char[] arr);
int File::Write(char[] arr);

// Print a sequence on bytes to the file, stopping at the zero-termination symbol or at the end of the array
// function returns true if the sequence was fully written
// if the file was not opened or was closed, this function will throw an error
bool File:Print(char[] arr);
bool File::Print(char[] arr);

// Read the specified number of bytes into the array at a specified offset
// function returns the number of bytes successfully read
// if the array size is not enough to fit the number of bytes from the file at the specified offset, the function will throw an error
// if the file was not opened or was closed, this function will throw an error
int File:Read(char[] arr, int offset, int bytes);
int File::Read(char[] arr, int offset, int bytes);

// Write the specified number of bytes from the array at a specified offset
// function returns the number of bytes successfully written
// if the array size is not enough to get the number of bytes from the it at the specified offset, the function will throw an error
// if the file was not opened or was closed, this function will throw an error
int File:Write(char[] arr, int offset, int bytes);
int File::Write(char[] arr, int offset, int bytes);
10 changes: 5 additions & 5 deletions Modules/std/hashmap.nc
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ class hashmap<Key, Value>

int hash_value_default(@Key key){ return hash_value(key); }

void hashmap:hashmap()
void hashmap::hashmap()
{
entries = new hashmap_node<Key, Value> ref[bucketCount];
this.compute_hash = hash_value_default;
}
void hashmap:hashmap(int ref(Key) compute_hash)
void hashmap::hashmap(int ref(Key) compute_hash)
{
entries = new hashmap_node<Key, Value> ref[bucketCount];
this.compute_hash = compute_hash;
}

void hashmap:clear()
void hashmap::clear()
{
for(i in entries)
i = nullptr;
Expand Down Expand Up @@ -62,7 +62,7 @@ auto operator[](hashmap<@K, @V> ref m, typeof(m).target.Key key)
m.entries[bucket] = n;
return &n.value;
}
void hashmap:remove(Key key)
void hashmap::remove(Key key)
{
int hash = compute_hash(key);
int bucket = hash & bucketMask;
Expand All @@ -81,7 +81,7 @@ void hashmap:remove(Key key)
entries[bucket] = curr.next;
}

auto hashmap:find(Key key)
auto hashmap::find(Key key)
{
int hash = compute_hash(key);
int bucket = hash & bucketMask;
Expand Down
Loading