mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Added tables to integration tests, tweaked a lot of comments
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
//TODO: functions don't work yet
|
||||
|
||||
//example of the fibonacci sequence
|
||||
fn fib(n: int) {
|
||||
if (n < 2) return n;
|
||||
return fib(n-1) + fib(n-2);
|
||||
}
|
||||
|
||||
//NOTE: type coercion syntax hasn't been decided on yet
|
||||
//TODO: type coercion syntax hasn't been decided on yet, but it will be needed
|
||||
for (var i = 1; i <= 10; i++) {
|
||||
print i .. ":" .. fib(i);
|
||||
}
|
||||
|
||||
//Note to self: yes, the base case in 'fib()' is 'n < 2', stop second guessing yourself!
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//standard example
|
||||
//standard example, using 'while' instead of 'for', because it's not ready yet
|
||||
|
||||
var counter: int = 1;
|
||||
|
||||
while (counter <= 100) {
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
set breakpoint pending on
|
||||
|
||||
break toy_vm.c:547
|
||||
|
||||
command 1
|
||||
print opcode
|
||||
continue
|
||||
end
|
||||
|
||||
break toy_vm.c:373
|
||||
|
||||
command 2
|
||||
printf "JUMP %d %d %d\n", type, cond, param
|
||||
continue
|
||||
end
|
||||
|
||||
break toy_vm.c:375
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//TODO: functions don't work yet
|
||||
|
||||
//find the leap years
|
||||
fn isLeapYear(n: int) {
|
||||
if (n % 400) return true;
|
||||
if (n % 100) return false;
|
||||
if (n % 400 == 0) return true;
|
||||
if (n % 100 == 0) return false;
|
||||
return n % 4 == 0;
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
//if and while work together
|
||||
var count = 1;
|
||||
while (count <= 10) {
|
||||
if (count % 2 == 0) {
|
||||
print "even";
|
||||
}
|
||||
else {
|
||||
print "odd";
|
||||
}
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
//test trailing commas
|
||||
var a = [1, 2, 3, ];
|
||||
|
||||
print a;
|
||||
|
||||
//test empty arrays
|
||||
var b = [];
|
||||
|
||||
print b;
|
||||
|
||||
|
||||
//TODO: prevent circular references
|
||||
@@ -1,5 +0,0 @@
|
||||
var barr = [
|
||||
[1, 2, 3],
|
||||
// [4, 5, 6],
|
||||
// [7, 8, 9]
|
||||
];
|
||||
@@ -85,7 +85,7 @@ Toy_Bytecode Toy_compileBytecode(Toy_Ast* ast) {
|
||||
|
||||
//build
|
||||
writeBytecodeHeader(&bc);
|
||||
writeBytecodeBody(&bc, ast); //TODO: implement module packing
|
||||
writeBytecodeBody(&bc, ast); //TODO: implement module packing (multiple modules in one package)
|
||||
|
||||
return bc;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ typedef enum Toy_OpcodeType {
|
||||
TOY_OPCODE_PRINT,
|
||||
TOY_OPCODE_CONCAT,
|
||||
TOY_OPCODE_INDEX,
|
||||
//TODO: clear the program stack - much needed
|
||||
//URGENT: clear the program stack - much needed
|
||||
|
||||
//meta instructions
|
||||
TOY_OPCODE_PASS,
|
||||
|
||||
@@ -651,11 +651,6 @@ static Toy_AstFlag aggregate(Toy_Bucket** bucketHandle, Toy_Parser* parser, Toy_
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: allow trailing commas
|
||||
// static Toy_AstFlag noop(Toy_Bucket** bucketHandle, Toy_Parser* parser, Toy_Ast** rootHandle) {
|
||||
// return return TOY_AST_FLAG_NONE;
|
||||
// }
|
||||
|
||||
static ParsingTuple* getParsingRule(Toy_TokenType type) {
|
||||
return &parsingRulesetTable[type];
|
||||
}
|
||||
|
||||
@@ -392,7 +392,7 @@ static unsigned int writeInstructionIfThenElse(Toy_Routine** rt, Toy_AstIfThenEl
|
||||
}
|
||||
|
||||
static unsigned int writeInstructionWhileThen(Toy_Routine** rt, Toy_AstWhileThen ast) {
|
||||
//TODO: begin
|
||||
//begin
|
||||
unsigned int beginAddr = CURRENT_ADDRESS(rt, code);
|
||||
|
||||
//cond-branch
|
||||
@@ -830,7 +830,7 @@ static void* writeRoutine(Toy_Routine* rt, Toy_Ast* ast) {
|
||||
count += rt->dataCount;
|
||||
}
|
||||
|
||||
//TODO: subs region
|
||||
//TODO: subroutine region
|
||||
|
||||
//finally, record the total size within the header, and return the result
|
||||
*((int*)buffer) = count;
|
||||
|
||||
@@ -126,8 +126,6 @@ void Toy_declareScope(Toy_Scope* scope, Toy_String* key, Toy_Value value) {
|
||||
Toy_insertTable(&scope->table, TOY_VALUE_FROM_STRING(Toy_copyString(key)), value);
|
||||
}
|
||||
|
||||
|
||||
//TODO: check for clearign old values
|
||||
void Toy_assignScope(Toy_Scope* scope, Toy_String* key, Toy_Value value) {
|
||||
if (key->info.type != TOY_STRING_NAME) {
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: Toy_Scope only allows name strings as keys\n" TOY_CC_RESET);
|
||||
|
||||
@@ -189,7 +189,7 @@ Toy_String* Toy_concatStrings(Toy_Bucket** bucketHandle, Toy_String* left, Toy_S
|
||||
}
|
||||
|
||||
void Toy_freeString(Toy_String* str) {
|
||||
decrementRefCount(str); //TODO: tool for checking the bucket is empty, and freeing it
|
||||
decrementRefCount(str); //TODO: tool for checking the bucket is empty, and freeing it?
|
||||
}
|
||||
|
||||
unsigned int Toy_getStringLength(Toy_String* str) {
|
||||
|
||||
@@ -26,7 +26,7 @@ TOY_API Toy_Value Toy_lookupTable(Toy_Table** tableHandle, Toy_Value key);
|
||||
TOY_API void Toy_removeTable(Toy_Table** tableHandle, Toy_Value key);
|
||||
|
||||
//NOTE: exposed to skip unnecessary allocations within Toy_Scope
|
||||
TOY_API Toy_Table* Toy_private_adjustTableCapacity(Toy_Table* oldTable, unsigned int newCapacity); //TODO: make it public
|
||||
TOY_API Toy_Table* Toy_private_adjustTableCapacity(Toy_Table* oldTable, unsigned int newCapacity); //TODO: make it public?
|
||||
TOY_API Toy_TableEntry* Toy_private_lookupTableEntryPtr(Toy_Table** tableHandle, Toy_Value key); //TODO: make it public?
|
||||
|
||||
//some useful sizes, could be swapped out as needed
|
||||
|
||||
@@ -412,7 +412,7 @@ int Toy_compareValues(Toy_Value left, Toy_Value right) {
|
||||
Toy_String* Toy_stringifyValue(Toy_Bucket** bucketHandle, Toy_Value value) {
|
||||
value = Toy_unwrapValue(value);
|
||||
|
||||
//TODO: could have "constant" strings that can be referenced, instead of null, true, false, etc.
|
||||
//TODO: could have "constant" strings that can be referenced, instead of null, true, false, etc. - new string type of 'permanent'
|
||||
|
||||
switch(value.type) {
|
||||
case TOY_VALUE_NULL:
|
||||
|
||||
@@ -37,7 +37,6 @@ typedef struct Toy_Value { //32 | 64 BITNESS
|
||||
struct Toy_Array* array; //4 | 8
|
||||
struct Toy_Table* table; //4 | 8
|
||||
//TODO: more types go here
|
||||
//TODO: consider 'stack' as a possible addition
|
||||
|
||||
} as; //4 | 8
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ static void processRead(Toy_VM* vm) {
|
||||
unsigned int count = (unsigned int)READ_INT(vm);
|
||||
unsigned int capacity = count > TOY_ARRAY_INITIAL_CAPACITY ? count : TOY_ARRAY_INITIAL_CAPACITY;
|
||||
|
||||
//neat trick to find the next power of two, inclusive (restriction of the array system) TODO: move this into a function
|
||||
//neat trick to find the next power of two, inclusive (restriction of the array system)
|
||||
capacity--;
|
||||
capacity |= capacity >> 1;
|
||||
capacity |= capacity >> 2;
|
||||
@@ -128,7 +128,7 @@ static void processRead(Toy_VM* vm) {
|
||||
unsigned int capacity = count / 2;
|
||||
capacity = capacity > TOY_TABLE_INITIAL_CAPACITY ? capacity : TOY_TABLE_INITIAL_CAPACITY;
|
||||
|
||||
//neat trick to find the next power of two, inclusive (restriction of the table system) TODO: move this into a function
|
||||
//neat trick to find the next power of two, inclusive (restriction of the table system)
|
||||
capacity--;
|
||||
capacity |= capacity >> 1;
|
||||
capacity |= capacity >> 2;
|
||||
@@ -317,7 +317,6 @@ static void processAccess(Toy_VM* vm) {
|
||||
|
||||
//in the event of a certain subset of types, create references instead (these should only exist on the stack)
|
||||
if (TOY_VALUE_IS_REFERENCE(*valuePtr) || TOY_VALUE_IS_ARRAY(*valuePtr) || TOY_VALUE_IS_TABLE(*valuePtr)) {
|
||||
//TODO: more types to be implemented as stack-only references
|
||||
Toy_Value ref = TOY_REFERENCE_FROM_POINTER(valuePtr);
|
||||
Toy_pushStack(&vm->stack, ref);
|
||||
}
|
||||
@@ -635,7 +634,7 @@ static void processIndex(Toy_VM* vm) {
|
||||
}
|
||||
else {
|
||||
Toy_error("Incorrect number of elements found in index");
|
||||
//TODO: clear stack, then leave null?
|
||||
//TODO: clear stack, then leave null
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -728,7 +727,6 @@ static void processIndex(Toy_VM* vm) {
|
||||
|
||||
//in the event of a certain subset of types, create references instead (these should only exist on the stack)
|
||||
if (TOY_VALUE_IS_REFERENCE(array->data[i]) || TOY_VALUE_IS_ARRAY(array->data[i]) || TOY_VALUE_IS_TABLE(array->data[i])) {
|
||||
//TODO: more types to be implemented as stack-only references
|
||||
Toy_Value ref = TOY_REFERENCE_FROM_POINTER(&(array->data[i]));
|
||||
Toy_pushStack(&vm->stack, ref);
|
||||
}
|
||||
@@ -761,7 +759,6 @@ static void processIndex(Toy_VM* vm) {
|
||||
|
||||
//in the event of a certain subset of types, create references instead (these should only exist on the stack)
|
||||
if (TOY_VALUE_IS_REFERENCE(entry->value) || TOY_VALUE_IS_ARRAY(entry->value) || TOY_VALUE_IS_TABLE(entry->value)) {
|
||||
//TODO: more types to be implemented as stack-only references
|
||||
Toy_Value ref = TOY_REFERENCE_FROM_POINTER(&(entry->value));
|
||||
Toy_pushStack(&vm->stack, ref);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ typedef struct Toy_VM {
|
||||
Toy_Bucket* stringBucket; //stores the string literals
|
||||
Toy_Bucket* scopeBucket; //stores the scopes
|
||||
|
||||
//TODO: panic flag
|
||||
//URGENT: panic/failed state flag
|
||||
} Toy_VM;
|
||||
|
||||
TOY_API void Toy_initVM(Toy_VM* vm);
|
||||
|
||||
@@ -885,7 +885,5 @@ int main(void) {
|
||||
total += res;
|
||||
}
|
||||
|
||||
//TODO: hashing
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ print !true; //false
|
||||
print !false; //true
|
||||
|
||||
//precedence
|
||||
print true && false || true; //TODO: a grouping warning is needed for this
|
||||
print true && false || true; //URGENT: a grouping warning is needed for this, see issue #154
|
||||
|
||||
//types
|
||||
var a: int;
|
||||
|
||||
Reference in New Issue
Block a user