frederikgramkortegaard / eridu

C-Like programming language with abstract data types, functions as first-class citizens, and multi-paradigm functionality

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Eridu - C-Like Programming Language

License: MIT

Eridu is a fully fledged C-Like programming language featuring various abstract data types, functions as first-class citizens, and multi-paradigm functionality, written from scratch in C , targeting x86 AT&T Assembly.

Testing and benchmarking was performed using a custom Python framework written from scratch as shown in sections 6. and 8. of the thesis in which a formal description of Eridu can also be found.

πŸ“Œ Thesis

πŸ“Œ Code Examples

πŸ“Œ Project Description

πŸ’¬ The reader is advised to look at section 8. regarding performance evaluation in the attached thesis to get an overview of the viability of the language as well as comparisons to C and C++ with regards to run-time and scalability metrics.


Using the Eridu compiler

To use the compiler, the following command can be run:

$ ./path/to/compiler < ./path/to/file.erd

From here, the newly created output.s file can be constructed into a runnable by using gcc. Here it is important to note that the -no-pie flag for GCC is required when using strings.

We advice the reader to test the following examples:

$ ./build/compiler < ./examples/generic_vehicle_simulator.erd
$ gcc -no-pie output.s
$ ./a.out
$ ./build/compiler < ./examples/iterator.erd
$ gcc -no-pie output.s
$ ./a.out

Code Samples

Map/Filter

define int * map(int * arr, int size, <int> callable <int> func) {

    int i = 0;
    int * new_arr = allocate(int, size);
    while(i < size) {
        new_arr[i] = func(arr[i]);
        i = i + 1;
    };

    return new_arr;
};
define int * filter(int * arr, int size, <int> callable <int> cond) {

    int i = 0;
    int j = 0;

    int * new_arr = allocate(int, size);

    while(i < size) {
        if(cond(arr[i]) == 1) {
            new_arr[j] = arr[i];
            j = j + 1;
        };
        i = i + 1;
    };

    return realloc(new_arr, size, j);
};

Structs and Callables (Functions as First-Class Citizens)

struct Iterator = {
    char ** values,
    int size,
    int current,
    <str> callable <struct Iterator *> next,
};

// Create dummy data
str * names = allocate(str, 5);
names[0] = "Michael";
names[1] = "Peter";
names[2] = "Hamurabe";
names[3] = "Wolfeschlegelsteinhausenberger";
names[4] = "Jackson";

struct Iterator * iter = create_iterator(names, 5);

// Test "next larger" iterator, starting from "Michael"
iter.next = _next_larger;
next = iter.next;
iter.current = 0;

str b = next(iter);
print(b); // Hamurabe
b = next(iter);
print(b); // Wolfeschlegelsteinhausenberger

Compiling Eridu from Source

It is possible to compile Eridu from source, by navigating to the ./dev/src folder and running make. Verbose output from the compilation process such as Abstract Syntax Tree structures or the code generation process can be exposed by using make debug instead.

$ cd ./dev/src && make

Testing

Tests can be run using our testing framework Gula, to use this framework, Python 3.8 and the numpy package is required. To see the help menu, use the command:

$ python3 ./tests/gula.py -help

And for a complete test pass:

$ python3 ./tests/gula.py -src ../build -path ./tests -verbose

Benchmarking

Benchmarking can be performed using our benchmarking framework Utu by running the following command:

$ python3 ./benchmarks/utu.py -src ./build -path . -verbose

Too see all the available options, run:

$ python3 ./benchmarks/utu.py -help

About

C-Like programming language with abstract data types, functions as first-class citizens, and multi-paradigm functionality


Languages

Language:C 74.4%Language:Python 6.9%Language:C# 6.6%Language:C++ 5.9%Language:Yacc 4.9%Language:Lex 1.1%Language:Makefile 0.2%Language:Shell 0.2%