Category Archives: Progress

100 Commits

Today I made my 100th commit on the Git repository :-D

I also extended the ‘enumeration’ declarations. Now they have a similar complex code-generation as the ‘flags enumerations’:

// XieXie
enum Types {
	Unknown	("unknown")			:= 0
	Foo		("this is foo")		:= 5
	Bar		("and this is bar") := 6
}

// C++
struct Types
{
    enum __XX__Enum
    {
        Unknown = 0,
        Foo = 5,
        Bar = 6,
        __XX__Uninitialized
    };
    Types() :
        __XX__Entry(__XX__Uninitialized)
    {
    }
    Types(const __XX__Enum& entry) :
        __XX__Entry(entry)
    {
    }
    inline operator __XX__Enum () const
    {
        return __XX__Entry;
    }
    inline size_t Num() const
    {
        return 3;
    }
    std::string Str() const
    {
        switch (__XX__Entry)
        {
            case Unknown: return "unknown";
            case Foo:     return "this is foo";
            case Bar:     return "and this is bar";
        }
        return "";
    }
    __XX__Enum __XX__Entry;
};

Lambdas

Just right now I’ve added a syntax for lambda expressions:

// XieXie
lambda bool(int a, int b) { ret a < b }

// C++
[&](int a, int b) -> bool { return a < b; }

For XieXie I simplified the feature set of lambdas by always using automatic variable capturing (with the ‘[&]‘ C++ syntax).

In XieXie I’m using lots of different keywords. In contrast to C++, where keywords are massive overloaded – such as the ‘const’ keyword.
I think this helps for the readability.

Initializer Lists and new Attributes Syntax

Today I’ve added the initializer lists which should work similiar to the C++11′s equivalent.

// --- Already implemented: ---
int[] array1 := { 1, 2, 3 }
string[] array2 := { "Hello", "World" }
int[][] array3 := { { 1, 2, 3 }, { 42, 19 } }

// --- Currently just in planning: ---

// Test class
class Test { int foo, bar }

// Default initialization
Test t1 := { 12, 5 }

// Initialization with member denomination (like with the named parameters)
Test t2 := { foo: 12, bar: 5 }
Test t3 := { bar: 5, foo: 12 }

I also changed the syntax for the attributes. Now you can write several attributes for a statement:

void DoSomething(int x) { /* ... */ }

// Auto-unroll loop
[[unroll]]
for i := 1 .. 3 {
    DoSomething(i)
}

// Pack class (and disable alignment)
[[pack]] class Foo {
    [[set,get]] int bar
}

And this is the generated code:

// Example.xx.cpp
// XieXie generated source file
// Sat Feb 01 21:10:13 2014

//! DoSomething function
//! \param[in] x Input parameter x.
void DoSomething(int x)
{
}

// Unrolled Range-Based For Loop
{
    // Iteration 1
    unsigned char i = 1;
    {
        DoSomething(i);
    }
    
    // Iteration 2
    i = 2;
    {
        DoSomething(i);
    }
    
    // Iteration 3
    i = 3;
    {
        DoSomething(i);
    }
    
}
// Structure Packing Alignment
#if defined(_MSC_VER)
#   pragma pack(push, packing)
#   pragma pack(1)
#   define __XX__PACK_STRUCT__
#elif defined(__GNUC__)
#   define __XX__PACK_STRUCT__ __attribute__((packed))
#else
#   define __XX__PACK_STRUCT__
#endif

//! Foo class.
class Foo
{
    public:
        int bar;
        Foo() :
            bar(0)
        {
        }
        
        ~Foo()
        {
        }
        
    public:
        //! Setter for "bar" member variable.
        //! \param[in] bar Specifies the new value.
        //! \see bar
        inline void SetBar(const int& bar)
        {
            this->bar = bar;
        }
        //! Getter for "bar" member variable.
        //! \see bar
        //! \return Current value.
        inline const int& GetBar() const
        {
            return bar;
        }
        
} __XX__PACK_STRUCT__;

// /Structure Packing Alignment
#ifdef _MSC_VER
#   pragma pack(pop, packing)
#endif
#undef __XX__PACK_STRUCT__

// ================

The old syntax with the ‘#’ character was just a temporary solution.
The new one works correct together with the rest of the grammar.

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 :-D

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 ^^