Skip to content
Open
Changes from all commits
Commits
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
55 changes: 33 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# gs-lang

Parser and compiler to translate GScript in to the GVM bytecode language. It depends on the gs-code module that implements the bytecode and vm. See https://github.com/geertvos/gs-core

# design goals
The idea behind the scripting language and the vm is that it easy to understand and modify, targeted for educational purposes. The entire bytecode language, the stack machine and the compiler and AST are easily readable, not optimized in any way and allow for easy modification. Therefor making it perferct for programming language courses etc.
# Design Goals

The idea behind the scripting language and the vm is that it easy to understand and modify, targeted for educational purposes. The entire bytecode language, the stack machine and the compiler and AST are easily readable, not optimized in any way and allow for easy modification. There for making it perfect for programming language courses etc.

# State of the Project

# state of the project
Currently most of the basic language features are working. However, programming in the language is not yet very easy due to the lack of debug information. Also some of the open bugs make it hard to write anything useful yet. However, it already serves the main purposes!

# language
The GScript language is a basic functional scripting language loosely based on Javascript. It is both object oriented and functional where both Objects and Functions are first class citizens.
# Language

The GScript language is a basic functional scripting language loosely based on Javascript. It is both object oriented and functional where both objects and functions are first class citizens.

# Types

# types
At the core of GScript are 7 types:

- Boolean
Expand All @@ -35,22 +40,24 @@ Strings are UTF-8 encoded and can be defined by using the following notation:
```
For objects and functions, see the sections below. Undefined cannot be defined. It is the opposite.

# array support
# Array Support

The language supports arrays with dynamic lengths.
```
names = new ["Johny", "Calvin", "Clara"];
System.print(names[0]);
```
# map syntax support
# Map Syntax Support

The language supports maps naturally, since all objects are implemented as hashmaps. The syntax supports maps, by using a similar definition as arrays.
```
ageMap = new ["Johny" => 32, "Calvin" => 25, "Clara" => 16];
System.print(ageMap["Johny"]);
```


# functions
The following example shows how to create a Constructor that creates person objects.
# Functions
The following example shows how to create a constructor that creates person objects.
```
person = (name) -> {
this.name = name;
Expand All @@ -59,7 +66,7 @@ person = (name) -> {
};
Person john = new Person("John");
```
# anonymous objects
# Anonymous Objects
```
create = () -> {
return new {
Expand All @@ -69,25 +76,26 @@ create = () -> {

```

# control flow
# Control Flow

The language has support for the usual control flow statements like the if, while and for loop. Both while and for support break and continue and work as expected.
The language has support for the usual control flow statements like the if, while, and for loop. Both while and for support break and continue and work as expected.
```
if( a < b ) {
print("a < b)
if(a < b) {
print("a < b")
}

for(a=0;a<10;a++) {
for(a=0; a<10; a++) {
print("a: "+a)
}

while(a<100) {
while(a < 100) {
a++;
print("a: "+a)
}
```

# exception handling
# Exception Handling

The language and underlying VM have support for exception handling. Any type can be thrown as an Exception. The VM internally will throw String objects with a message.
```
try {
Expand All @@ -98,7 +106,8 @@ try {
print("Exception caught: "+a);
};
```
# module support
# Module Support

All the code written in gscript is in scope of a module. With the import statement, other modules can be loaded. Each module is executed at load time. The example below creates Math module with a sum function in it.
```
module Math;
Expand All @@ -115,7 +124,8 @@ import Math;
value = Math.sum(2, 4)
```

# native code support.
# Native Code Support

This compiler compiles the GScript code in to an a bytecode format that can be executed by the GVM. (See other project). Both have support for 'native' code by binding a function to a Java method.

```
Expand All @@ -125,5 +135,6 @@ myFunction = (argument) -> {
}
```

# tail recursion
The compiler contains support to optimze tail recursion. This will reduce the stack usage and will reuse the existing stackframe for the tail call. The optimization can be enabled/disabled. The optimization is implemented as a runtime check becuase the language is dynamically typed and functions are first class citizens. Only at runtime we can verify that we are performing an actual tail call. The runtime check might impact performane.
# Tail Recursion

The compiler contains support to optimze tail recursion. This will reduce the stack usage and will reuse the existing stackframe for the tail call. The optimization can be enabled/disabled. The optimization is implemented as a runtime check becuase the language is dynamically typed and functions are first class citizens. Only at runtime we can verify that we are performing an actual tail call. The runtime check might impact performane.