mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Renemed all variables to fit into a namespace
Basically, all Toy varaibles, functions, etc. are prepended with "Toy_", and macros are prepended with "TOY_". This is to reduce namespace pollution, which was an issue pointed out to be - blame @GyroVorbis. I've also bumped the minor version number - theoretically I should bump the major number, but I'm not quite ready for 1.0 yet.
This commit is contained in:
@@ -1,56 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include "toy_common.h"
|
||||
#include "literal.h"
|
||||
#include "literal_array.h"
|
||||
#include "literal_dictionary.h"
|
||||
#include "scope.h"
|
||||
#include "toy_literal.h"
|
||||
#include "toy_literal_array.h"
|
||||
#include "toy_literal_dictionary.h"
|
||||
#include "toy_scope.h"
|
||||
|
||||
typedef void (*PrintFn)(const char*);
|
||||
typedef void (*Toy_PrintFn)(const char*);
|
||||
|
||||
//the interpreter acts depending on the bytecode instructions
|
||||
typedef struct Interpreter {
|
||||
typedef struct Toy_Interpreter {
|
||||
//input
|
||||
unsigned char* bytecode;
|
||||
int length;
|
||||
int count;
|
||||
int codeStart; //BUGFIX: for jumps, must be initialized to -1
|
||||
LiteralArray literalCache; //read-only - built from the bytecode, refreshed each time new bytecode is provided
|
||||
Toy_LiteralArray literalCache; //read-only - built from the bytecode, refreshed each time new bytecode is provided
|
||||
|
||||
//operation
|
||||
Scope* scope;
|
||||
LiteralArray stack;
|
||||
Toy_Scope* scope;
|
||||
Toy_LiteralArray stack;
|
||||
|
||||
//Library APIs
|
||||
LiteralDictionary* hooks;
|
||||
Toy_LiteralDictionary* hooks;
|
||||
|
||||
//debug outputs
|
||||
PrintFn printOutput;
|
||||
PrintFn assertOutput;
|
||||
PrintFn errorOutput;
|
||||
Toy_PrintFn printOutput;
|
||||
Toy_PrintFn assertOutput;
|
||||
Toy_PrintFn errorOutput;
|
||||
|
||||
int depth; //don't overflow
|
||||
bool panic;
|
||||
} Interpreter;
|
||||
} Toy_Interpreter;
|
||||
|
||||
//native API
|
||||
typedef int (*NativeFn)(Interpreter* interpreter, LiteralArray* arguments);
|
||||
TOY_API bool injectNativeFn(Interpreter* interpreter, char* name, NativeFn func);
|
||||
typedef int (*Toy_NativeFn)(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments);
|
||||
TOY_API bool Toy_injectNativeFn(Toy_Interpreter* interpreter, char* name, Toy_NativeFn func);
|
||||
|
||||
typedef int (*HookFn)(Interpreter* interpreter, Literal identifier, Literal alias);
|
||||
TOY_API bool injectNativeHook(Interpreter* interpreter, char* name, HookFn hook);
|
||||
typedef int (*Toy_HookFn)(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Literal alias);
|
||||
TOY_API bool Toy_injectNativeHook(Toy_Interpreter* interpreter, char* name, Toy_HookFn hook);
|
||||
|
||||
TOY_API bool callLiteralFn(Interpreter* interpreter, Literal func, LiteralArray* arguments, LiteralArray* returns);
|
||||
TOY_API bool callFn(Interpreter* interpreter, char* name, LiteralArray* arguments, LiteralArray* returns);
|
||||
TOY_API bool Toy_callLiteralFn(Toy_Interpreter* interpreter, Toy_Literal func, Toy_LiteralArray* arguments, Toy_LiteralArray* returns);
|
||||
TOY_API bool Toy_callFn(Toy_Interpreter* interpreter, char* name, Toy_LiteralArray* arguments, Toy_LiteralArray* returns);
|
||||
|
||||
//utilities for the host program
|
||||
TOY_API bool parseIdentifierToValue(Interpreter* interpreter, Literal* literalPtr);
|
||||
TOY_API void setInterpreterPrint(Interpreter* interpreter, PrintFn printOutput);
|
||||
TOY_API void setInterpreterAssert(Interpreter* interpreter, PrintFn assertOutput);
|
||||
TOY_API void setInterpreterError(Interpreter* interpreter, PrintFn errorOutput);
|
||||
TOY_API bool Toy_parseIdentifierToValue(Toy_Interpreter* interpreter, Toy_Literal* literalPtr);
|
||||
TOY_API void Toy_setInterpreterPrint(Toy_Interpreter* interpreter, Toy_PrintFn printOutput);
|
||||
TOY_API void Toy_setInterpreterAssert(Toy_Interpreter* interpreter, Toy_PrintFn assertOutput);
|
||||
TOY_API void Toy_setInterpreterError(Toy_Interpreter* interpreter, Toy_PrintFn errorOutput);
|
||||
|
||||
//main access
|
||||
TOY_API void initInterpreter(Interpreter* interpreter); //start of program
|
||||
TOY_API void runInterpreter(Interpreter* interpreter, unsigned char* bytecode, int length); //run the code
|
||||
TOY_API void resetInterpreter(Interpreter* interpreter); //use this to reset the interpreter's environment between runs
|
||||
TOY_API void freeInterpreter(Interpreter* interpreter); //end of program
|
||||
TOY_API void Toy_initInterpreter(Toy_Interpreter* interpreter); //start of program
|
||||
TOY_API void Toy_runInterpreter(Toy_Interpreter* interpreter, unsigned char* bytecode, int length); //run the code
|
||||
TOY_API void Toy_resetInterpreter(Toy_Interpreter* interpreter); //use this to reset the interpreter's environment between runs
|
||||
TOY_API void Toy_freeInterpreter(Toy_Interpreter* interpreter); //end of program
|
||||
|
||||
Reference in New Issue
Block a user