# Parameter denomination for function calls

There are a some languages which support parameter denomination for function calls.
XieXie is going to become one of them

I actually don’t know the correct denomination for what I call “parameter denomination” ^^
But this was the best fitting name for it.

Consider a function with lots of parameters and all or nearly all have default values.
Now you want to set the last parameter in a function call but for all others you want to use the default values.
In C++ you have to write all arguments in your function call again.
Here is an example:

// C++ code:
void FunctionWithManyParameters(int a = 1, float b = 3.14, double c = (1.0/3.0), long double d = 0.5, unsigned long long int e = 27)
{
/* ... */
}
FunctionWithManyParameters(1, 3.14, 1.0/3.0, 0.5, 100);
FunctionWithManyParameters(1, 3.14, 1.0/3.0, 0.5, 200);

In XieXie you can do it much easier:

// XieXie code:
void FunctionWithManyParameters(int a := 1, float b := 3.14, double c := (1.0/3.0), quad d := 0.5, ulong e := 27) {
/* ... */
}
FunctionWithManyParameters(e: 100)
FunctionWithManyParameters(e: 200)

Certainly once you’ve started such parameter denomination you are forced to continue this for the rest of your argument list,
i.e. the following example is not valid:

// XieXie false example:
//                                  ERROR
//                                    V
FunctionWithManyParameters(1, e: 100, 3.14)

# Pointer validation expression

When handling pointers (or more general ‘Objects’ in Java) you often have to check or rather validate your pointers to not be a null-pointer.

In C++ for instance you could have such a code:

// Function creates an entity and returns it as a pointer
Entity* CreateEntity() { /* ... */ }

void DoSomethingWithFirstEntity(Entity** listOfEntities)
{
// Make sure we don't have null pointers
if (listOfEntities != nullptr && *listOfEntities != nullptr)
{
(**listOfEntities).DoSomething();
}
}

Of course, C++ programmers should use references or const-references as much as possible,
so you don’t have to do this pointer validation.
But in some cases you still need to do such things.

In XieXie this is again much more comfortable:

Entity* CreateEntity() { /* ... */ }

void DoSomethingWithFirstEntity(Entity** listOfEntities) {
if valid listOfEntities {
listOfEntities.DoSomething()
}
}

This XieXie code will translate exactly to the above C++ code.
No matter how many pointers must be dereferenced, XieXie does it for you

Here is another example:

// XieXie code:
int a
int* b
int**@ c

/* ... */

bool b1 := valid a
bool b2 := valid b
bool b3 := valid c

This will translate to:

// C++ code:
int a = 0;
int* b = 0;
std::shared_ptr< int** > c = nullptr;

/* ... */

bool b1 = true;
bool b2 = (b != nullptr);
bool b3 = (c != nullptr && *c != nullptr && **c != nullptr);

# Template instantiation

Since XieXie has its own type system, I need to instantiate the templates by myself
(so I can not just translate a XieXie template to a C++ template).

Today I’ve got the first template example to work

But it’s still a lot of work, so that the templates
can be used comfortable, safe and in arbitrary variants.

And by the way: the project has now over 20.000 lines of code.
It’s starting to become interesting ^^

# Patterns

Today I’ve started with the patterns (which are similar to the C++ template typenames).
This will be a lot of work, but XieXie must instantiate the templates by itself – and not just compile it to C++ templates.
That’s because the type-system works a little different to that of C++.
Here is a small example:

// Small C++ template structure with typename T
template <typename T> struct Test
{
T foo;
void Proc()
{
foo.Bar();
}
};

// Small structure for template argument
struct TestFoo
{
void Bar() { /* ... */ }
};

// No problem
Test<TestFoo> TemplateInstance1;

// ERROR: "foo.Bar" can not be used
// because "TemplateInstance2.foo" is a pointer!
Test<TestFoo*> TemplateInstance2;

In XieXie you can (or rather you will be able to) write this:

// Small XieXie template class with pattern T
class Test<pattern T> {
T foo
void Proc() {
foo.Bar()
}
}

// Small class for template argument
class TestFoo
{
void Bar() { /* ... */ }
}

// No problem
Test<TestFoo> TemplateInstance1

// No problem as well
// ( 'TemplateInstance2.foo.Bar()' is automatically
//   translated to '(*TemplateInstance2.foo).Bar()' )
Test<TestFoo*> TemplateInstance2

// No problem as well with shared-pointer of
// raw-pointer of shared-pointer
// ( 'TemplateInstance3.foo.Bar()' is automatically
//   translated to '(***TemplateInstance3.foo).Bar()' )
Test<TestFoo@*@> TemplateInstance3

# Anonymous Classes

Today I’ve started with anonymous classes. This is very usful, particular for event handlers and such things.

Here is a small example:

mainWindow.SetEventHandler(
// Create new object from an anonymous
// class which inherits from "WindowEventHandler".
new class WindowEventHandler() {
void OnResize(const ResizeEvent& event) {
// Clamp window width
if event.width < 800 {
event.window.SetWidth(event.width)
} else {
event.window.SetWidth(800)
}
event.window.SetHeight(event.height)
}
}
)

# The ‘copy’ keyword

Somtimes you may want to copy an object and all its sub-pointer objects (and not just the pointers itself). In those cases you have to write your own copy function with resursive calls. When you’ve ever wrote a tree-hierarchy, you should know how awful that can be.

Today I’ve started with a new and very nice keyword: the “copy”  keyword:

class BinaryTree {
int data
BinaryTree@ a
BinaryTree@ b
}
BinaryTree@ treeA := /* create tree here ... */
BinaryTree@ treeB := copy treeA

This will translate to that:

//! BinaryTree class.
class BinaryTree
{
public:
int data;
std::shared_ptr< BinaryTree > a;
std::shared_ptr< BinaryTree > b;
BinaryTree() :
data(0),
a(nullptr),
b(nullptr)
{
}

virtual ~BinaryTree()
{
}

std::shared_ptr< BinaryTree > __XX__Copy() const
{
std::shared_ptr< BinaryTree > dest = std::make_shared< BinaryTree >();
dest.data = data;
if (a != nullptr)
{
dest.a = (*a).__XX__Copy();
}
if (b != nullptr)
{
dest.b = (*b).__XX__Copy();
}
return dest;
}
};

std::shared_ptr< BinaryTree > treeA = /* create tree here ... */
std::shared_ptr< BinaryTree > treeB = (*treeA).__XX__Copy();

The actual implementation of the “__XX__Copy” function generation is still in progress,
so that part in the above example has been written by hand for presentation purspose

I already look forward to it

# Constness, pointers, procedure-objects …

Today I’ve got the constness, pointers, procedure-objects and arrays  parsing working.

Now you can write C++ like (crazy) interleaved type-denoters:

proc<void()>*[12]@ p :=
new proc<void()>*[12]()

Which will be translated to:

std::shared_ptr<
std::array<
std::function< void () >*,
12
>
> p =
std::make_shared<
std::array<
std::function< void () >*,
12
>
>();

# Range-based for loops

Today I splitted up the “loop” keyword into several types of loops: “while”, “until”, “do … while/until”, “for”, “forever”.

I also created a range-based ‘for-loop’ which can be unrolled using the #unroll attribute identifier.

# First executable App

After 6 weeks of development I already got my first executable test application

I’m currently using a batch file on Windows to run all required programs:
1.) The XièXiè Compiler
2.) The GNU C++ Compiler

This is the my current batch file:

set INPUT_FILE=%1
set INTERMEDIATE_FILE=%INPUT_FILE%.cpp
set APP_FILE=%INPUT_FILE%.exe

start "XieXie Compiler" /B "D:\SoftwareEntwicklung\C++\HLC\Tools\XieXie-Compiler\cmake_msvc11\build\Release\xxc.exe" -f %INPUT_FILE%

start "GNU C++ Compiler" /B "D:\Anwendungen\CodeBlocks\MinGW\bin\g++" -std=c++11 -O3 -I "D:\SoftwareEntwicklung\C++\HLC\Tools\XieXie-Compiler\trunk\sources\Library" -o %APP_FILE% .\%INTERMEDIATE_FILE%

# Started with eclipse pluging

Today I’ve started with an eclipse plugin for the XièXiè language. This will be a source-code editor with syntax highlighting and auto-completion. Currently I’m only using Notepad++ with this highlighting schemes.