Reworked the tests, read more

I've brought the tests up to scratch, except for compounds im the
parser, because I'm too damn tired to do that over SSH. It looks like
collections are right-recursive, whixh was unintended but still works
just fine.

I've also added the '--verbose' flag to the repl to control the
debugging output.

Several obscure bugs have been fixed, and comments have been tweaked.

Mustfail tests are still needed, but that's a low priority. See #142.

Fixed #151
This commit is contained in:
2024-11-12 22:04:07 +11:00
parent b74aa63c1c
commit be7e4ddd18
22 changed files with 364 additions and 102 deletions

View File

@@ -33,11 +33,10 @@ TOY_API Toy_Array* Toy_resizeArray(Toy_Array* array, unsigned int capacity);
//one line to expand the array
#ifndef TOY_ARRAY_EXPAND
#define TOY_ARRAY_EXPAND(array) (array = (array != NULL && (array)->count + 1 > (array)->capacity ? Toy_resizeArray(array, (array)-> capacity * TOY_ARRAY_EXPANSION_RATE) : array))
#define TOY_ARRAY_EXPAND(array) (array = (array != NULL && (array)->count + 1 > (array)->capacity ? Toy_resizeArray(array, (array)->capacity * TOY_ARRAY_EXPANSION_RATE) : array))
#endif
//quick push back
#ifndef TOY_ARRAY_PUSHBACK
#define TOY_ARRAY_PUSHBACK(array, value) (TOY_ARRAY_EXPAND(array),(array)->data[(array)->count++] = (value))
#endif

View File

@@ -11,4 +11,3 @@ typedef struct Toy_Bytecode {
TOY_API Toy_Bytecode Toy_compileBytecode(Toy_Ast* ast);
TOY_API void Toy_freeBytecode(Toy_Bytecode bc);

View File

@@ -23,7 +23,7 @@ const Toy_KeywordTypeTuple keywordTuples[] = {
{TOY_TOKEN_TYPE_STRING, "string"},
{TOY_TOKEN_TYPE_ARRAY, "array"},
{TOY_TOKEN_TYPE_TABLE, "table"},
{TOY_TOKEN_TYPE_FUNCTION, "function"}, //TODO: type??
{TOY_TOKEN_TYPE_FUNCTION, "function"},
{TOY_TOKEN_TYPE_OPAQUE, "opaque"},
{TOY_TOKEN_TYPE_ANY, "any"},

View File

@@ -41,11 +41,10 @@ typedef enum Toy_OpcodeType {
TOY_OPCODE_PRINT,
TOY_OPCODE_CONCAT,
TOY_OPCODE_INDEX,
//TODO: clear the program stack?
//TODO: clear the program stack - much needed
//meta instructions
TOY_OPCODE_PASS,
TOY_OPCODE_ERROR,
TOY_OPCODE_EOF = 255,
} Toy_OpcodeType;

View File

@@ -563,7 +563,7 @@ static Toy_AstFlag compound(Toy_Bucket** bucketHandle, Toy_Parser* parser, Toy_A
advance(parser);
if (parser->previous.type == TOY_TOKEN_OPERATOR_COMMA) {
parsePrecedence(bucketHandle, parser, rootHandle, PREC_GROUP);
parsePrecedence(bucketHandle, parser, rootHandle, PREC_GROUP); //NOT +1, as compounds are right-recursive
return TOY_AST_FLAG_COMPOUND_COLLECTION;
}
else if (parser->previous.type == TOY_TOKEN_OPERATOR_BRACKET_LEFT) {
@@ -848,4 +848,4 @@ void Toy_resetParser(Toy_Parser* parser) {
void Toy_configureParser(Toy_Parser* parser, bool removeAssert) {
parser->removeAssert = removeAssert;
}
}

View File

@@ -272,8 +272,6 @@ void Toy_stringifyValue(Toy_Value value, Toy_callbackType callback) {
case TOY_VALUE_STRING: {
Toy_String* str = TOY_VALUE_AS_STRING(value);
//TODO: decide on how long strings, etc. live for in memory
if (str->type == TOY_STRING_NODE) {
char* buffer = Toy_getStringRawBuffer(str);
callback(buffer);

View File

@@ -189,7 +189,7 @@ static void processAccess(Toy_VM* vm) {
//find and push the value
Toy_Value value = Toy_accessScope(vm->scope, TOY_VALUE_AS_STRING(name));
Toy_pushStack(&vm->stack, value);
Toy_pushStack(&vm->stack, Toy_copyValue(value));
//cleanup
Toy_freeValue(name);

View File

@@ -49,4 +49,4 @@ TOY_API void Toy_freeVM(Toy_VM* vm);
TOY_API void Toy_resetVM(Toy_VM* vm); //prepares for another run without deleting stack, scope and memory
//TODO: inject extra data
//TODO: inject extra data (hook system for external libraries)