diff --git a/scripts/fib.toy b/scripts/fib.toy index 0b1c2b8..7d50b49 100644 --- a/scripts/fib.toy +++ b/scripts/fib.toy @@ -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! diff --git a/scripts/fizzbuzz.toy b/scripts/fizzbuzz.toy index c608c2c..9c37ab6 100644 --- a/scripts/fizzbuzz.toy +++ b/scripts/fizzbuzz.toy @@ -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) { diff --git a/scripts/gdb_init b/scripts/gdb_init deleted file mode 100644 index c6d1223..0000000 --- a/scripts/gdb_init +++ /dev/null @@ -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 - - diff --git a/scripts/leapyear.toy b/scripts/leapyear.toy index 20c7082..48bcdc6 100644 --- a/scripts/leapyear.toy +++ b/scripts/leapyear.toy @@ -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; } diff --git a/scripts/odd_and_even.toy b/scripts/odd_and_even.toy deleted file mode 100644 index e1a7517..0000000 --- a/scripts/odd_and_even.toy +++ /dev/null @@ -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; - } -} diff --git a/scripts/trailing.toy b/scripts/trailing.toy deleted file mode 100644 index b2a3934..0000000 --- a/scripts/trailing.toy +++ /dev/null @@ -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 diff --git a/scripts/valgrind.toy b/scripts/valgrind.toy index 0a4dea8..e69de29 100644 --- a/scripts/valgrind.toy +++ b/scripts/valgrind.toy @@ -1,5 +0,0 @@ -var barr = [ - [1, 2, 3], -// [4, 5, 6], -// [7, 8, 9] -]; \ No newline at end of file diff --git a/source/toy_bytecode.c b/source/toy_bytecode.c index fdb7ddc..c689f3b 100644 --- a/source/toy_bytecode.c +++ b/source/toy_bytecode.c @@ -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; } diff --git a/source/toy_opcodes.h b/source/toy_opcodes.h index 3878723..82703f9 100644 --- a/source/toy_opcodes.h +++ b/source/toy_opcodes.h @@ -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, diff --git a/source/toy_parser.c b/source/toy_parser.c index 7106519..77b10c8 100644 --- a/source/toy_parser.c +++ b/source/toy_parser.c @@ -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]; } diff --git a/source/toy_routine.c b/source/toy_routine.c index 8ba98c1..b45307a 100644 --- a/source/toy_routine.c +++ b/source/toy_routine.c @@ -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; diff --git a/source/toy_scope.c b/source/toy_scope.c index 7f36224..5954d9a 100644 --- a/source/toy_scope.c +++ b/source/toy_scope.c @@ -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); diff --git a/source/toy_string.c b/source/toy_string.c index 2334f03..9fcc679 100644 --- a/source/toy_string.c +++ b/source/toy_string.c @@ -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) { diff --git a/source/toy_table.h b/source/toy_table.h index 78fa103..ddd5f5a 100644 --- a/source/toy_table.h +++ b/source/toy_table.h @@ -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 diff --git a/source/toy_value.c b/source/toy_value.c index a6d6602..3ae623d 100644 --- a/source/toy_value.c +++ b/source/toy_value.c @@ -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: diff --git a/source/toy_value.h b/source/toy_value.h index a2be718..b1c3071 100644 --- a/source/toy_value.h +++ b/source/toy_value.h @@ -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 diff --git a/source/toy_vm.c b/source/toy_vm.c index 76686b5..4053705 100644 --- a/source/toy_vm.c +++ b/source/toy_vm.c @@ -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); } diff --git a/source/toy_vm.h b/source/toy_vm.h index 1022a91..75b440d 100644 --- a/source/toy_vm.h +++ b/source/toy_vm.h @@ -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); diff --git a/tests/cases/test_string.c b/tests/cases/test_string.c index a6a55bb..b5f8dae 100644 --- a/tests/cases/test_string.c +++ b/tests/cases/test_string.c @@ -885,7 +885,5 @@ int main(void) { total += res; } - //TODO: hashing - return total; } diff --git a/scripts/tables.toy b/tests/integrations/test_tables.toy similarity index 100% rename from scripts/tables.toy rename to tests/integrations/test_tables.toy diff --git a/tests/integrations/test_variables.toy b/tests/integrations/test_variables.toy index d570489..2938ead 100644 --- a/tests/integrations/test_variables.toy +++ b/tests/integrations/test_variables.toy @@ -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;