Skip to content

iincity/hermes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hermes

A C-like scripting language.

Example program

Here is a small program that iterates and prints the contents of a list:

list fruits = [
    "apple",
    "banana",
    "pear",
    "lemon"
];

int i = 0;

while (i < fruits.length)
{
    print(fruits[i]);
    i += 1;
}

Linking a C program

Hermes can execute functions written in C. To load a function written in C, you can use the dload method, to load a function from a shared object file (.so). Example:

dload("librequests.so", "httpget");

string response = httpget("http://example.org")

print(response)

Here, the httpget function was loaded from the librequests.so file. Read more about how to write C methods for Hermes here.

Available Data types

Here is a list of implemented data types:

  • list
  • int
  • bool
  • float
  • char
  • string
  • object
  • ref
  • source

List example

list colors = [
    "red",
    "green",
    "blue"
];

Built-in list methods

Add

To add an item to a list:

list names = [];

names.add("john");

Remove

To remove an item from a list by index

list names = ["john"];

names.remove(0);

Int example

Everyone knows what an integer is.

int age = 22;

Bool example

Everyone knows what an boolean is.

bool x = 10 > 3;

Float example

Everyone knows what an float is.

float x = 0.5;

Char example

char c = 'a';

String example

Everyone knows what a string is.

string name = "John Doe";

Object example

Objects are sort of what you think they are.

object person = {
    string name = "john";
    int age = 22;
};

print(person.name);

Ref example

Refs are supposed to be used when integrating hermes in some sort of environment and you want to keep track of "references" that the programmer can work with.

ref something;

something.x += 1;

Source example

Sources are basically objects that represents a parsed source code.

source s = include("examples/functions.he");

To have hermes interpret the source, simply use the built-in visit method:

visit(s);

Now you can also dump that source to a serialized .dat file using the built-in wad method:

wad(s, "functions");

This will create a functions.dat file. To read the use case for these .dat files, please read this.

Built-in methods

  • print
  • aprint
  • include
  • wad
  • lad
  • visit
  • fopen
  • fputs
  • fclose
  • free

print

Prints what ever you gives it, example:

print("hello world");

aprint

Prints the adress of a value, example:

object person = {string name = "John Doe";};

aprint(person);

include

Loads an external source file, example:

source s = include("examples/functions.he");

wad

Writes an AST compound to disk, example:

source s = include("examples/functions.he");
wad(s, "functions");

This creates a functions.dat file.

lad

Loads an AST compound from disk, example:

source s = lad("functions");

visit

Visits and executes a source, example:

source s = include("examples/functions.he");
visit(s);

fopen

Open a file, here is an example to read the contents of a file:

object file = fopen("examples/functions.he", "r");
string x = file.read();

print(x);
fclose(file);

fputs

Write string to file, example:

object file = fopen("myfile.txt", "w+");

fputs("hello world", file);
fclose(file);

fclose

Close file, example:

object file = fopen("myfile.txt", "w+");
fclose(file);

free

Deallocates a variable, example:

string x = "hello";
free(x);

Available statements

  • new
  • iterate

new example

object get_person(string name)
{
    object o = {
        string name;    
    };

    o.name = name;

    return o;
}

object person = new get_person("Hanna");

The new statement will always return a new address of whatever is to the right of the statement.

iterate example

void char_iterator(char c)
{
    print(c);
}

void list_iterator(string name)
{
    print(name);
}

string x = "john doe";
list y = ["john", "sarah", "hannah"];

iterate x with char_iterator;
iterate y with list_iterator;

Compositions

Hermes now also support compositions, like this:

int add_2(int x)
{
    return x + 2;
}

int remove_1(int x)
{
    return x - 1;
}

int mycomp(int x) =
    add_2, remove_1;

int x = mycomp(10);

print(x);

Notes

For loops

For loops does not exist, you can acheive the same thing with while loops and we are trying to keep the language simple.

Lists

This might not be obvious, but lists can contain any sort of value. Example:

list cool_stuff = [
    "this is a string",
    { string x = "Wow, this is an object"; },
    [
        "a string in a list in a list"
    ]
];

Installing Hermes

To install Hermes on your system, simple run:

make && sudo make install

About

C-like scripting language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages