Skip to content

TomasBoda/agent-lang-interpreter

Repository files navigation

Version Badge Contributors Badge License Badge

About

Interpreter for the AgentLang programming language written in TypeScript and uses the Bun runtime framework.

AgentLang

AgentLang is an interpreted programming language designed for agent-based modeling. Below is an example AgentLang source code.

agent snowflake 200 {

    const speed = random(8, 15);

    property x: random(0, width()) = x;
    property y: random(0, height()) = (y + speed) % height();
    
    const w = 10;
    const h = 10;
}

Usage

Below is an example usage of the AgentLang interpreter in a TypeScript project.

import {
    Interpreter,
    InterpreterConfiguration,
    InterpreterOutput
} from "@/agent-lang-interpreter";

const filename = "source-code.txt";
const sourceCode = readFileSync(filename, "utf-8");

const config: InterpreterConfiguration = { steps: 10, delay: 500, width: 500, height: 500 };
const interpreter: Interpreter = new Interpreter();

interpreter.get(sourceCode, config).subscribe((output: InterpreterOutput) => {
    console.log(output);
});

Running

There are four ways to run the AgentLang interpreter:

Run Locally

To run an example program of the AgentLang interpreter, run the following command in your terminal.

# clone the interpreter
git clone https://github.com/TomasBoda/agent-lang-interpreter.git
# checkout the interpreter
cd agent-lang-interpreter
# install necessary packages
npm install
# run the example program
npm run start

The example program with the example source code from the ./example folder will compile and run.

Run Using Docker

To run AgentLang interpreter using Docker, run the following commands the project root in your terminal.

docker build -t agent-lang-interpreter-image .
# run the image
docker run -it agent-lang-interpreter-image

Integrate into TypeScript Project

To integrate the AgentLang interpreter into your TypeScript project, add it as a git submodule and install all the necessary packages.

# add the submodule to your project
git submodule add https://github.com/TomasBoda/agent-lang-interpreter.git
# checkout the submodule
cd agent-lang-interpreter
# install the necessary packages
npm install

Build Binary Executable

AgentLang interpreter can also be built as a binary executable runnable on various platforms. To build the binary executables of the interpreter, run the following command in the project root in your terminal.

npm run build-all

Warning

The build script uses Deno for compiling the TypeScript files into an executable binary. Before running the script, be sure to have Deno installed on your system and change the Deno installation path in the package.json file in the project root.

The script will build executable binaries for supported platforms into the ./prod folder. To run the binary file, run the following.

./prod/current-platform/agent-lang --input source-code.txt --output output.json

The interpreter will run the AgentLang code from the source-code.txt file and store the output of each step into the output.json file.

Tests

To run the AgentLang interpreter's unit tests, run the following in the project root in your terminal.

npm run test

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Made by Tomas Boda