Skip to content

TomasBoda/bytecode-interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GenLang

The official repository for the GenLang programming language.

var cache = {};

func fibonacci(var n) {
    if (n <= 1) {
        return n;
    }

    if (cache[tostring n] != null) {
        return cache[tostring n];
    }

    var result = fibonacci(n - 1) + fibonacci(n - 2);
    cache[tostring n] = result;
    return result;
}

func main(var argv) {
    var n = tonumber argv[0];
    print fibonacci(n);
}

Example Demos

The /programs folder contains several demo programs that showcase the power of the language:

Documentation

The documentation can be found in the following documents:

Repository Structure

Below is an overview of the repository structure:

  • /src - contains the source code of the GenLang interpreter
  • /tests - contains unit test files
  • /programs - contains example demo programs
  • /docs - contains documentation documents
  • /debug - contains the list of tokens and bytecode instructions emitted from the most recent run of the interpreter

Setup & Run

The project was developed using Python version 3.14.0, therefore Python version 3 and higher is recommended for running the project. To run a source code file in the language, modify the program.gen source code and use the run.sh script:

./run.sh

To provide command line arguments to the GenLang program, use the following syntax:

./run.sh "Hello, World!" 25

These arguments are forwarded to the main function:

func main(var args) {
    print args;
}

Alternatively, you can run the program using:

python3 main.py <source_code_file_path> <command_line_arguments>

Tests

To run tests, use the test.sh script that runs lexer, parser, compiler, virtual machine and complex test suites:

./test.sh

About

Bytecode Interpreter for the GenLang programming language written in Python

Topics

Resources

Stars

Watchers

Forks

Contributors