mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Merge branch 'main' of https://github.com/Ratstail91/Toy
This commit is contained in:
@@ -35,7 +35,7 @@ var tiles: [[int]] const = [
|
|||||||
|
|
||||||
var tileset: [int: string] const = [
|
var tileset: [int: string] const = [
|
||||||
0: " ",
|
0: " ",
|
||||||
1: " X "
|
1: "X "
|
||||||
];
|
];
|
||||||
|
|
||||||
//variables
|
//variables
|
||||||
@@ -48,7 +48,7 @@ fn draw() {
|
|||||||
for (var i: int = 0; i < WIDTH; i++) {
|
for (var i: int = 0; i < WIDTH; i++) {
|
||||||
//draw the player pos
|
//draw the player pos
|
||||||
if (i == posX && j == posY) {
|
if (i == posX && j == posY) {
|
||||||
print " O ";
|
print "O ";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
struct Toy_Literal;
|
struct Toy_Literal;
|
||||||
struct Toy_Interpreter;
|
struct Toy_Interpreter;
|
||||||
struct Toy_LiteralArray;
|
struct Toy_LiteralArray;
|
||||||
|
struct Toy_Scope;
|
||||||
typedef int (*Toy_NativeFn)(struct Toy_Interpreter* interpreter, struct Toy_LiteralArray* arguments);
|
typedef int (*Toy_NativeFn)(struct Toy_Interpreter* interpreter, struct Toy_LiteralArray* arguments);
|
||||||
typedef int (*Toy_HookFn)(struct Toy_Interpreter* interpreter, struct Toy_Literal identifier, struct Toy_Literal alias);
|
typedef int (*Toy_HookFn)(struct Toy_Interpreter* interpreter, struct Toy_Literal identifier, struct Toy_Literal alias);
|
||||||
typedef void (*Toy_PrintFn)(const char*);
|
typedef void (*Toy_PrintFn)(const char*);
|
||||||
@@ -57,7 +58,7 @@ typedef struct Toy_Literal {
|
|||||||
Toy_NativeFn native; //8
|
Toy_NativeFn native; //8
|
||||||
Toy_HookFn hook; //8
|
Toy_HookFn hook; //8
|
||||||
} inner; //8
|
} inner; //8
|
||||||
void* scope; //8
|
struct Toy_Scope* scope; //8
|
||||||
} function; //16
|
} function; //16
|
||||||
|
|
||||||
struct { //for variable names
|
struct { //for variable names
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ static void setEntryValues(Toy_private_dictionary_entry* entry, Toy_Literal key,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Toy_private_dictionary_entry* getEntryArray(Toy_private_dictionary_entry* array, int capacity, Toy_Literal key, unsigned int hash, bool mustExist) {
|
static Toy_private_dictionary_entry* getEntryArray(Toy_private_dictionary_entry* array, int capacity, Toy_Literal key, unsigned int hash, bool mustExist) {
|
||||||
|
if (!capacity) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
//find "key", starting at index
|
//find "key", starting at index
|
||||||
unsigned int index = hash % capacity;
|
unsigned int index = hash % capacity;
|
||||||
unsigned int start = index;
|
unsigned int start = index;
|
||||||
@@ -122,10 +126,10 @@ static void freeEntryArray(Toy_private_dictionary_entry* array, int capacity) {
|
|||||||
void Toy_initLiteralDictionary(Toy_LiteralDictionary* dictionary) {
|
void Toy_initLiteralDictionary(Toy_LiteralDictionary* dictionary) {
|
||||||
//HACK: because modulo by 0 is undefined, set the capacity to a non-zero value (and allocate the arrays)
|
//HACK: because modulo by 0 is undefined, set the capacity to a non-zero value (and allocate the arrays)
|
||||||
dictionary->entries = NULL;
|
dictionary->entries = NULL;
|
||||||
dictionary->capacity = TOY_GROW_CAPACITY(0);
|
dictionary->capacity = 0;
|
||||||
dictionary->contains = 0;
|
dictionary->contains = 0;
|
||||||
dictionary->count = 0;
|
dictionary->count = 0;
|
||||||
adjustEntryCapacity(&dictionary->entries, 0, dictionary->capacity);
|
dictionary->capacity = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Toy_freeLiteralDictionary(Toy_LiteralDictionary* dictionary) {
|
void Toy_freeLiteralDictionary(Toy_LiteralDictionary* dictionary) {
|
||||||
@@ -215,5 +219,5 @@ void Toy_removeLiteralDictionary(Toy_LiteralDictionary* dictionary, Toy_Literal
|
|||||||
bool Toy_existsLiteralDictionary(Toy_LiteralDictionary* dictionary, Toy_Literal key) {
|
bool Toy_existsLiteralDictionary(Toy_LiteralDictionary* dictionary, Toy_Literal key) {
|
||||||
//null & not tombstoned
|
//null & not tombstoned
|
||||||
Toy_private_dictionary_entry* entry = getEntryArray(dictionary->entries, dictionary->capacity, key, Toy_hashLiteral(key), false);
|
Toy_private_dictionary_entry* entry = getEntryArray(dictionary->entries, dictionary->capacity, key, Toy_hashLiteral(key), false);
|
||||||
return !(TOY_IS_NULL(entry->key) && TOY_IS_NULL(entry->value));
|
return entry != NULL && !(TOY_IS_NULL(entry->key) && TOY_IS_NULL(entry->value));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,6 +209,10 @@ Toy_Scope* Toy_popScope(Toy_Scope* scope) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Toy_Scope* Toy_copyScope(Toy_Scope* original) {
|
Toy_Scope* Toy_copyScope(Toy_Scope* original) {
|
||||||
|
if (original == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
Toy_Scope* scope = TOY_ALLOCATE(Toy_Scope, 1);
|
Toy_Scope* scope = TOY_ALLOCATE(Toy_Scope, 1);
|
||||||
scope->ancestor = original->ancestor;
|
scope->ancestor = original->ancestor;
|
||||||
Toy_initLiteralDictionary(&scope->variables);
|
Toy_initLiteralDictionary(&scope->variables);
|
||||||
|
|||||||
Reference in New Issue
Block a user