Skip to content

Commit

Permalink
Added tables to integration tests, tweaked a lot of comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratstail91 committed Dec 25, 2024
1 parent 9e2cbb1 commit 9cb138a
Show file tree
Hide file tree
Showing 21 changed files with 22 additions and 78 deletions.
6 changes: 5 additions & 1 deletion scripts/fib.toy
Original file line number Diff line number Diff line change
@@ -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!
3 changes: 2 additions & 1 deletion scripts/fizzbuzz.toy
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
19 changes: 0 additions & 19 deletions scripts/gdb_init

This file was deleted.

5 changes: 3 additions & 2 deletions scripts/leapyear.toy
Original file line number Diff line number Diff line change
@@ -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;
}
13 changes: 0 additions & 13 deletions scripts/odd_and_even.toy

This file was deleted.

12 changes: 0 additions & 12 deletions scripts/trailing.toy

This file was deleted.

5 changes: 0 additions & 5 deletions scripts/valgrind.toy
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
var barr = [
[1, 2, 3],
// [4, 5, 6],
// [7, 8, 9]
];
2 changes: 1 addition & 1 deletion source/toy_bytecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion source/toy_opcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions source/toy_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
4 changes: 2 additions & 2 deletions source/toy_routine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions source/toy_scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion source/toy_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion source/toy_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/toy_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion source/toy_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 3 additions & 6 deletions source/toy_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion source/toy_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions tests/cases/test_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,5 @@ int main(void) {
total += res;
}

//TODO: hashing

return total;
}
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/integrations/test_variables.toy
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9cb138a

Please sign in to comment.