mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Suppressed print statements during tests
This commit is contained in:
@@ -27,22 +27,20 @@ DONE: native functions
|
|||||||
DONE: global functions _get, _set, _push, _pop, _length, clear available
|
DONE: global functions _get, _set, _push, _pop, _length, clear available
|
||||||
DONE: change comma to colon in dictionary definition
|
DONE: change comma to colon in dictionary definition
|
||||||
DONE: Address circular references
|
DONE: Address circular references
|
||||||
TODO: are compounds shallow or deep copies? Deep copies
|
DONE: are compounds shallow or deep copies? Deep copies
|
||||||
|
DONE: third output stream, for lexer/parser/compiler/interpreter errors
|
||||||
|
DONE: Assertion-based test scripts
|
||||||
|
|
||||||
|
|
||||||
TODO: third output stream, for lexer/parser/compiler/interpreter errors
|
TODO: Import/export keywords
|
||||||
|
TODO: slice and dot notation around the builtin _index function
|
||||||
|
|
||||||
TODO: slice and dot notation around the _index function
|
|
||||||
TODO: ternary operator
|
TODO: ternary operator
|
||||||
TODO: Nullish types
|
TODO: Nullish types?
|
||||||
TODO: A way to check the type of a variable (typeOf keyword)
|
TODO: A way to check the type of a variable (typeOf keyword)
|
||||||
TODO: a = b = c = 1; ?
|
TODO: a = b = c = 1; ?
|
||||||
TODO: Assertion-based test scripts
|
|
||||||
TODO: standard library
|
TODO: standard library
|
||||||
TODO: external runner library
|
TODO: external script runner library
|
||||||
TODO: document how it all works
|
TODO: document how it all works - book?
|
||||||
TODO: better and more consistent error messages
|
|
||||||
TODO: maximum recursion/function depth
|
TODO: maximum recursion/function depth
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ static int writeNodeCompoundToCache(Compiler* compiler, Node* node) {
|
|||||||
freeLiteral(literal);
|
freeLiteral(literal);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, ERROR "[Internal] Unrecognized compound type in writeNodeCompoundToCache()" RESET);
|
fprintf(stderr, ERROR "[internal] Unrecognized compound type in writeNodeCompoundToCache()" RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
@@ -279,7 +279,7 @@ static void writeCompilerWithJumps(Compiler* compiler, Node* node, void* breakAd
|
|||||||
//determine node type
|
//determine node type
|
||||||
switch(node->type) {
|
switch(node->type) {
|
||||||
case NODE_ERROR: {
|
case NODE_ERROR: {
|
||||||
fprintf(stderr, ERROR "[Internal] NODE_ERROR encountered in writeCompilerWithJumps()\n" RESET);
|
fprintf(stderr, ERROR "[internal] NODE_ERROR encountered in writeCompilerWithJumps()\n" RESET);
|
||||||
compiler->bytecode[compiler->count++] = OP_EOF; //1 byte
|
compiler->bytecode[compiler->count++] = OP_EOF; //1 byte
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -338,7 +338,7 @@ static void writeCompilerWithJumps(Compiler* compiler, Node* node, void* breakAd
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case NODE_PAIR:
|
case NODE_PAIR:
|
||||||
fprintf(stderr, ERROR "[Internal] NODE_PAIR encountered in writeCompilerWithJumps()\n" RESET);
|
fprintf(stderr, ERROR "[internal] NODE_PAIR encountered in writeCompilerWithJumps()\n" RESET);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NODE_VAR_DECL: {
|
case NODE_VAR_DECL: {
|
||||||
|
|||||||
@@ -308,6 +308,7 @@ static void trim(char** s, int* l) { //all this to remove a newline?
|
|||||||
while(**s && isspace( **(unsigned char**)(s)) ) { (*s)++; (*l)--; }
|
while(**s && isspace( **(unsigned char**)(s)) ) { (*s)++; (*l)--; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//for debugging
|
||||||
void printToken(Token* token) {
|
void printToken(Token* token) {
|
||||||
if (token->type == TOKEN_ERROR) {
|
if (token->type == TOKEN_ERROR) {
|
||||||
printf(ERROR "Error\t%d\t%.*s\n" RESET, token->line, token->length, token->lexeme);
|
printf(ERROR "Error\t%d\t%.*s\n" RESET, token->line, token->length, token->lexeme);
|
||||||
|
|||||||
@@ -22,4 +22,5 @@ typedef struct {
|
|||||||
void initLexer(Lexer* lexer, char* source);
|
void initLexer(Lexer* lexer, char* source);
|
||||||
Token scanLexer(Lexer* lexer);
|
Token scanLexer(Lexer* lexer);
|
||||||
|
|
||||||
|
//for debugging
|
||||||
void printToken(Token* token);
|
void printToken(Token* token);
|
||||||
@@ -11,7 +11,12 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
//IO functions
|
//supress the print output
|
||||||
|
static void noPrintFn(const char* output) {
|
||||||
|
//NO OP
|
||||||
|
}
|
||||||
|
|
||||||
|
//compilation functions
|
||||||
char* readFile(char* path, size_t* fileSize) {
|
char* readFile(char* path, size_t* fileSize) {
|
||||||
FILE* file = fopen(path, "rb");
|
FILE* file = fopen(path, "rb");
|
||||||
|
|
||||||
@@ -86,6 +91,10 @@ unsigned char* compileString(char* source, size_t* size) {
|
|||||||
void runBinary(unsigned char* tb, size_t size) {
|
void runBinary(unsigned char* tb, size_t size) {
|
||||||
Interpreter interpreter;
|
Interpreter interpreter;
|
||||||
initInterpreter(&interpreter);
|
initInterpreter(&interpreter);
|
||||||
|
|
||||||
|
//NOTE: supress print output for testing
|
||||||
|
setInterpreterPrint(&interpreter, noPrintFn);
|
||||||
|
|
||||||
runInterpreter(&interpreter, tb, size);
|
runInterpreter(&interpreter, tb, size);
|
||||||
freeInterpreter(&interpreter);
|
freeInterpreter(&interpreter);
|
||||||
}
|
}
|
||||||
@@ -138,6 +147,9 @@ int main() {
|
|||||||
int size = 0;
|
int size = 0;
|
||||||
unsigned char* bytecode = collateCompiler(&compiler, &size);
|
unsigned char* bytecode = collateCompiler(&compiler, &size);
|
||||||
|
|
||||||
|
//NOTE: supress print output for testing
|
||||||
|
setInterpreterPrint(&interpreter, noPrintFn);
|
||||||
|
|
||||||
//run
|
//run
|
||||||
runInterpreter(&interpreter, bytecode, size);
|
runInterpreter(&interpreter, bytecode, size);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user