-
- Open Tokens.hpp
-
- Add a new value to the enum
TokenKind
- Add a new value to the enum
-
- Add a new case for the TokenKind in the function
string token_kind_to_str(TokenKind k)
- Add a new case for the TokenKind in the function
-
- Create a new regex pattern for the new token.
const std::regex INCREMENT_PATTERN("^Incr$", std::regex_constants::icase);
-
- Go to the
Token token_from_str(std::string value, int line, int column)
function and add a new case for the token (usually above theIDENTIFIER_PATTERN
unless it is a single symbol).
- Go to the
-
- Open instructions.hpp
-
- Add a new value to the enum
InstructionKind
- Add a new value to the enum
-
- Define a new macro at the top of the file. Example:
#define DEF(name, val, t) \
{ \
.kind = InstructionKind::DefVar, .operand = {.value = val, .type = t}, \
.id = name, \
}
Keep in mind that instructions are defined as the following:
struct Instruction {
InstructionKind kind;
asa::Object operand;
std::string id;
std::vector<Instruction> block;
};
-
- Define a new function for the instruction.
-
- Open transpiler.hpp
-
- Go to the
Program load_program(vector<Token> tokens)
function
- Go to the
-
- Add a new case for the newly defined
TokenKind
and implement its parsing in aparse_<instructionname>(int &index, vector<Token> *tokens, Program *program, string ¤t_block)
function.
- Add a new case for the newly defined
-
- Open interpreter.hpp
-
- Go to the
asa::Object eval(Program program, string entryPoint, list<asa::Object> *stack)
function
- Go to the
-
- Add a new case for the newly created
InstructionKind
, pop any arguments from the stack withpop_args
and call the function you created defined in instructions.hpp.
- Add a new case for the newly created
-
- done! :) you just created a new instruction for asa!
If you have any questions just open a new issue and I'll be happy to help!