-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Welcome to the Autumn.cpp wiki! This repo contain a C++ implementation of Autumn interpreter. By writing in C++, the interpreter is compilable into a python module, and a web assembly module.
Please follow the README page for building instructions for both Python and Webassembly module. Both the CPP, Python, and Javascript implementation exposes the following interface:
- Runscript/start: This load an Autumn Program along with an Autumn Library and initialize the states of all object
- Step: This executes one update step in the Autumn program, it also register the effect of all actions
-
Action: This allows users to interact with a running Autumn environment. Specifically, the action set is as follows:
-
Click(x,y)
: the User clicks at a specific grid position -
Left()
: the User presses the left arrow key. -
Right()
: the User presses the right arrow key. -
Up()
: the User presses the up arrow key. -
Down()
: the User presses the down arrow key.
-
- Render: return the states of all objects in the rendering order (determined by the object declaration order).
Below is a sequence diagram on how to use the interpreter in general:
In the following sections, we describe how to use the interpreter module for python and javascript.
First, copy the interpreter_module*.so
to the python import folder.
import interpreter_module
# Creating a new interpreter
interpreter = interpreter_module.Interpreter()
# Loading autumn program, all arguments are string, the 2nd is the extra library/alternative std library, ignore for the 3rd argument for now.
run_result = interpreter.run_script(script, "", "", 42) # 42 is the random seed, any other number is fine.
# Action
interpreter.left()
interpreter.right()
interpreter.up()
interpreter.down()
interpreter.click(x, y) # int, int
# Step
interpreter.step()
# Render
interpreter.render_all()
Checkout the example implementation in python_test_mpl.py
First, copy the interpreter_web.wasm
, interpreter_web.js
, interpreter_web.wasm.map
to your static serving folder, include it in your script with:
<script src="./static/js/interpreter_web.js"></script>
Following this, use the interpreter as follow:
interpreter = await new interpreterModule.Interpreter();
interpreter.runScript(programContent, autumnstdlib, "", 42); // 42 is the random seed, any other number is fine.
interpreter.click(x, y);
interpreter.left();
interpreter.right();
interpreter.up();
interpreter.down();
interpreter.step();
interpreter.renderAll();
Note that, the wasm cannot find the default Autumn STDlib file, so please store the autumnstdlib
to a string. Checkout MARA repo for an example.