Added CONTRIBUTING.md

Also renamed 'handles' throughout the project for consistency.

Some meta files also had their file extensions added.
This commit is contained in:
2024-10-05 06:04:17 +10:00
parent 29f5647e31
commit d19a90f9bd
20 changed files with 415 additions and 287 deletions

View File

@@ -57,12 +57,12 @@ int test_sizeof_ast_32bit() {
return -err;
}
int test_type_emission(Toy_Bucket** bucket) {
int test_type_emission(Toy_Bucket** bucketHandle) {
//emit value
{
//emit to an AST
Toy_Ast* ast = NULL;
Toy_private_emitAstValue(bucket, &ast, TOY_VALUE_TO_INTEGER(42));
Toy_private_emitAstValue(bucketHandle, &ast, TOY_VALUE_TO_INTEGER(42));
//check if it worked
if (
@@ -79,8 +79,8 @@ int test_type_emission(Toy_Bucket** bucket) {
{
//build the AST
Toy_Ast* ast = NULL;
Toy_private_emitAstValue(bucket, &ast, TOY_VALUE_TO_INTEGER(42));
Toy_private_emitAstUnary(bucket, &ast, TOY_AST_FLAG_NEGATE);
Toy_private_emitAstValue(bucketHandle, &ast, TOY_VALUE_TO_INTEGER(42));
Toy_private_emitAstUnary(bucketHandle, &ast, TOY_AST_FLAG_NEGATE);
//check if it worked
if (
@@ -100,9 +100,9 @@ int test_type_emission(Toy_Bucket** bucket) {
//build the AST
Toy_Ast* ast = NULL;
Toy_Ast* right = NULL;
Toy_private_emitAstValue(bucket, &ast, TOY_VALUE_TO_INTEGER(42));
Toy_private_emitAstValue(bucket, &right, TOY_VALUE_TO_INTEGER(69));
Toy_private_emitAstBinary(bucket, &ast, TOY_AST_FLAG_ADD, right);
Toy_private_emitAstValue(bucketHandle, &ast, TOY_VALUE_TO_INTEGER(42));
Toy_private_emitAstValue(bucketHandle, &right, TOY_VALUE_TO_INTEGER(69));
Toy_private_emitAstBinary(bucketHandle, &ast, TOY_AST_FLAG_ADD, right);
//check if it worked
if (
@@ -124,10 +124,10 @@ int test_type_emission(Toy_Bucket** bucket) {
//build the AST
Toy_Ast* ast = NULL;
Toy_Ast* right = NULL;
Toy_private_emitAstValue(bucket, &ast, TOY_VALUE_TO_INTEGER(42));
Toy_private_emitAstValue(bucket, &right, TOY_VALUE_TO_INTEGER(69));
Toy_private_emitAstBinary(bucket, &ast, TOY_AST_FLAG_ADD, right);
Toy_private_emitAstGroup(bucket, &ast);
Toy_private_emitAstValue(bucketHandle, &ast, TOY_VALUE_TO_INTEGER(42));
Toy_private_emitAstValue(bucketHandle, &right, TOY_VALUE_TO_INTEGER(69));
Toy_private_emitAstBinary(bucketHandle, &ast, TOY_AST_FLAG_ADD, right);
Toy_private_emitAstGroup(bucketHandle, &ast);
//check if it worked
if (
@@ -150,19 +150,19 @@ int test_type_emission(Toy_Bucket** bucket) {
{
//initialize the root block
Toy_Ast* block = NULL;
Toy_private_initAstBlock(bucket, &block);
Toy_private_initAstBlock(bucketHandle, &block);
//loop over the ast emissions, appending each one as you go
for (int i = 0; i < 5; i++) {
//build the AST
Toy_Ast* ast = NULL;
Toy_Ast* right = NULL;
Toy_private_emitAstValue(bucket, &ast, TOY_VALUE_TO_INTEGER(42));
Toy_private_emitAstValue(bucket, &right, TOY_VALUE_TO_INTEGER(69));
Toy_private_emitAstBinary(bucket, &ast, TOY_AST_FLAG_ADD, right);
Toy_private_emitAstGroup(bucket, &ast);
Toy_private_emitAstValue(bucketHandle, &ast, TOY_VALUE_TO_INTEGER(42));
Toy_private_emitAstValue(bucketHandle, &right, TOY_VALUE_TO_INTEGER(69));
Toy_private_emitAstBinary(bucketHandle, &ast, TOY_AST_FLAG_ADD, right);
Toy_private_emitAstGroup(bucketHandle, &ast);
Toy_private_appendAstBlock(bucket, block, ast);
Toy_private_appendAstBlock(bucketHandle, block, ast);
}
//check if it worked
@@ -216,9 +216,9 @@ int main() {
#endif
{
Toy_Bucket* bucket = Toy_allocateBucket(sizeof(Toy_Ast) * 32);
res = test_type_emission(&bucket);
Toy_freeBucket(&bucket);
Toy_Bucket* bucketHandle = Toy_allocateBucket(sizeof(Toy_Ast) * 32);
res = test_type_emission(&bucketHandle);
Toy_freeBucket(&bucketHandle);
if (res == 0) {
printf(TOY_CC_NOTICE "All good\n" TOY_CC_RESET);
}

View File

@@ -9,12 +9,12 @@
#include <string.h>
//tests
int test_bytecode_header(Toy_Bucket** bucket) {
int test_bytecode_header(Toy_Bucket** bucketHandle) {
//simple test to ensure the header looks right
{
//setup
Toy_Ast* ast = NULL;
Toy_private_emitAstPass(bucket, &ast);
Toy_private_emitAstPass(bucketHandle, &ast);
//run
Toy_Bytecode bc = Toy_compileBytecode(ast);
@@ -49,7 +49,7 @@ int test_bytecode_header(Toy_Bucket** bucket) {
return 0;
}
int test_bytecode_from_source(Toy_Bucket** bucket) {
int test_bytecode_from_source(Toy_Bucket** bucketHandle) {
{
//setup
const char* source = "(1 + 2) * (3 + 4);";
@@ -58,7 +58,7 @@ int test_bytecode_from_source(Toy_Bucket** bucket) {
Toy_bindLexer(&lexer, source);
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
//run
Toy_Bytecode bc = Toy_compileBytecode(ast);

View File

@@ -4,18 +4,18 @@
#include <stdio.h>
//utils
Toy_Ast* makeAstFromSource(Toy_Bucket** bucket, const char* source) {
Toy_Ast* makeAstFromSource(Toy_Bucket** bucketHandle, const char* source) {
Toy_Lexer lexer;
Toy_bindLexer(&lexer, source);
Toy_Parser parser;
Toy_bindParser(&parser, &lexer);
return Toy_scanParser(bucket, &parser);
return Toy_scanParser(bucketHandle, &parser);
}
//tests
int test_simple_empty_parsers(Toy_Bucket** bucket) {
int test_simple_empty_parsers(Toy_Bucket** bucketHandle) {
//simple parser setup and cleanup
{
//raw source code and lexer
@@ -27,7 +27,7 @@ int test_simple_empty_parsers(Toy_Bucket** bucket) {
Toy_Parser parser;
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
//check if it worked
if (
@@ -50,7 +50,7 @@ int test_simple_empty_parsers(Toy_Bucket** bucket) {
Toy_Parser parser;
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
//check if it worked
if (
@@ -75,7 +75,7 @@ int test_simple_empty_parsers(Toy_Bucket** bucket) {
Toy_Parser parser;
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
Toy_Ast* iter = ast;
@@ -98,10 +98,10 @@ int test_simple_empty_parsers(Toy_Bucket** bucket) {
return 0;
}
int test_values(Toy_Bucket** bucket) {
int test_values(Toy_Bucket** bucketHandle) {
//test boolean true
{
Toy_Ast* ast = makeAstFromSource(bucket, "true;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "true;");
//check if it worked
if (
@@ -119,7 +119,7 @@ int test_values(Toy_Bucket** bucket) {
//test boolean false (just to be safe)
{
Toy_Ast* ast = makeAstFromSource(bucket, "false;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "false;");
//check if it worked
if (
@@ -137,7 +137,7 @@ int test_values(Toy_Bucket** bucket) {
//test integer
{
Toy_Ast* ast = makeAstFromSource(bucket, "42;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "42;");
//check if it worked
if (
@@ -155,7 +155,7 @@ int test_values(Toy_Bucket** bucket) {
//test float
{
Toy_Ast* ast = makeAstFromSource(bucket, "3.1415;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "3.1415;");
//check if it worked
if (
@@ -173,7 +173,7 @@ int test_values(Toy_Bucket** bucket) {
//test integer with separators
{
Toy_Ast* ast = makeAstFromSource(bucket, "1_234_567_890;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "1_234_567_890;");
//check if it worked
if (
@@ -191,7 +191,7 @@ int test_values(Toy_Bucket** bucket) {
//test float with separators
{
Toy_Ast* ast = makeAstFromSource(bucket, "3.141_592_65;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "3.141_592_65;");
//check if it worked
if (
@@ -210,10 +210,10 @@ int test_values(Toy_Bucket** bucket) {
return 0;
}
int test_unary(Toy_Bucket** bucket) {
int test_unary(Toy_Bucket** bucketHandle) {
//test unary boolean negation (!true)
{
Toy_Ast* ast = makeAstFromSource(bucket, "!true;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "!true;");
//check if it worked
if (
@@ -231,7 +231,7 @@ int test_unary(Toy_Bucket** bucket) {
//test unary boolean negation (!false, just to be safe)
{
Toy_Ast* ast = makeAstFromSource(bucket, "!false;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "!false;");
//check if it worked
if (
@@ -249,7 +249,7 @@ int test_unary(Toy_Bucket** bucket) {
//test unary integer negation
{
Toy_Ast* ast = makeAstFromSource(bucket, "-42;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "-42;");
//check if it worked
if (
@@ -267,7 +267,7 @@ int test_unary(Toy_Bucket** bucket) {
//test unary float negation
{
Toy_Ast* ast = makeAstFromSource(bucket, "-3.1415;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "-3.1415;");
//check if it worked
if (
@@ -285,7 +285,7 @@ int test_unary(Toy_Bucket** bucket) {
//ensure unary negation doesn't occur with a group
{
Toy_Ast* ast = makeAstFromSource(bucket, "-(42);");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "-(42);");
//check if it worked
if (
@@ -301,7 +301,7 @@ int test_unary(Toy_Bucket** bucket) {
//ensure unary negation doesn't occur with a space
{
Toy_Ast* ast = makeAstFromSource(bucket, "- 42;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "- 42;");
//check if it worked
if (
@@ -318,10 +318,10 @@ int test_unary(Toy_Bucket** bucket) {
return 0;
}
int test_binary(Toy_Bucket** bucket) {
int test_binary(Toy_Bucket** bucketHandle) {
//test binary add (term); also covers subtract
{
Toy_Ast* ast = makeAstFromSource(bucket, "1 + 2;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "1 + 2;");
//check if it worked
if (
@@ -348,7 +348,7 @@ int test_binary(Toy_Bucket** bucket) {
//test binary multiply (factor); also covers divide and modulo
{
Toy_Ast* ast = makeAstFromSource(bucket, "3 * 5;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "3 * 5;");
//check if it worked
if (
@@ -375,7 +375,7 @@ int test_binary(Toy_Bucket** bucket) {
//test binary assign (using numbers for now, as identifiers aren't coded yet)
{
Toy_Ast* ast = makeAstFromSource(bucket, "1 = 2;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "1 = 2;");
//check if it worked
if (
@@ -402,7 +402,7 @@ int test_binary(Toy_Bucket** bucket) {
//test binary compare (equality)
{
Toy_Ast* ast = makeAstFromSource(bucket, "42 == 69;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "42 == 69;");
//check if it worked
if (
@@ -430,10 +430,10 @@ int test_binary(Toy_Bucket** bucket) {
return 0;
}
int test_precedence(Toy_Bucket** bucket) {
int test_precedence(Toy_Bucket** bucketHandle) {
//test term-factor precedence
{
Toy_Ast* ast = makeAstFromSource(bucket, "1 * 2 + 3 * 4;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "1 * 2 + 3 * 4;");
//check if it worked
if (
@@ -474,7 +474,7 @@ int test_precedence(Toy_Bucket** bucket) {
//test left-recrusive precedence
{
Toy_Ast* ast = makeAstFromSource(bucket, "1 + 2 + 3 + 4 + 5 + 6;");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "1 + 2 + 3 + 4 + 5 + 6;");
//check if it worked
if (
@@ -531,7 +531,7 @@ int test_precedence(Toy_Bucket** bucket) {
//test group precedence
{
Toy_Ast* ast = makeAstFromSource(bucket, "(1 + 2) * (3 + 4);");
Toy_Ast* ast = makeAstFromSource(bucketHandle, "(1 + 2) * (3 + 4);");
//check if it worked
if (

View File

@@ -10,12 +10,12 @@
#include <string.h>
//tests
int test_routine_header_and_values(Toy_Bucket** bucket) {
int test_routine_header_and_values(Toy_Bucket** bucketHandle) {
//simple test to ensure the header looks right with an empty ast
{
//setup
Toy_Ast* ast = NULL;
Toy_private_emitAstPass(bucket, &ast);
Toy_private_emitAstPass(bucketHandle, &ast);
//run
void* buffer = Toy_compileRoutine(ast);
@@ -64,7 +64,7 @@ int test_routine_header_and_values(Toy_Bucket** bucket) {
Toy_bindLexer(&lexer, source);
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
//run
void* buffer = Toy_compileRoutine(ast);
@@ -113,7 +113,7 @@ int test_routine_header_and_values(Toy_Bucket** bucket) {
Toy_bindLexer(&lexer, source);
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
//run
void* buffer = Toy_compileRoutine(ast);
@@ -166,7 +166,7 @@ int test_routine_header_and_values(Toy_Bucket** bucket) {
Toy_bindLexer(&lexer, source);
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
//run
void* buffer = Toy_compileRoutine(ast);
@@ -219,7 +219,7 @@ int test_routine_header_and_values(Toy_Bucket** bucket) {
Toy_bindLexer(&lexer, source);
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
//run
void* buffer = Toy_compileRoutine(ast);
@@ -273,7 +273,7 @@ int test_routine_header_and_values(Toy_Bucket** bucket) {
Toy_bindLexer(&lexer, source);
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
//run
void* buffer = Toy_compileRoutine(ast);
@@ -321,11 +321,11 @@ int test_routine_header_and_values(Toy_Bucket** bucket) {
return 0;
}
// int test_routine_unary(Toy_Bucket** bucket) {
// int test_routine_unary(Toy_Bucket** bucketHandle) {
// //Nothing produces a unary instruction yet
// }
int test_routine_binary(Toy_Bucket** bucket) {
int test_routine_binary(Toy_Bucket** bucketHandle) {
//produce a simple algorithm
{
//setup
@@ -335,7 +335,7 @@ int test_routine_binary(Toy_Bucket** bucket) {
Toy_bindLexer(&lexer, source);
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
//run
void* buffer = Toy_compileRoutine(ast);
@@ -401,7 +401,7 @@ int test_routine_binary(Toy_Bucket** bucket) {
Toy_bindLexer(&lexer, source);
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
//run
void* buffer = Toy_compileRoutine(ast);
@@ -467,7 +467,7 @@ int test_routine_binary(Toy_Bucket** bucket) {
Toy_bindLexer(&lexer, source);
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
//run
void* buffer = Toy_compileRoutine(ast);
@@ -533,7 +533,7 @@ int test_routine_binary(Toy_Bucket** bucket) {
Toy_bindLexer(&lexer, source);
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
//run
void* buffer = Toy_compileRoutine(ast);

View File

@@ -9,21 +9,21 @@
#include <string.h>
//utils
Toy_Bytecode makeBytecodeFromSource(Toy_Bucket** bucket, const char* source) {
Toy_Bytecode makeBytecodeFromSource(Toy_Bucket** bucketHandle, const char* source) {
Toy_Lexer lexer;
Toy_bindLexer(&lexer, source);
Toy_Parser parser;
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
Toy_Bytecode bc = Toy_compileBytecode(ast);
return bc;
}
//tests
int test_setup_and_teardown(Toy_Bucket** bucket) {
int test_setup_and_teardown(Toy_Bucket** bucketHandle) {
//basic init & quit
{
//generate bytecode for testing
@@ -35,7 +35,7 @@ int test_setup_and_teardown(Toy_Bucket** bucket) {
Toy_Parser parser;
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
Toy_Bytecode bc = Toy_compileBytecode(ast);
@@ -73,7 +73,7 @@ int test_setup_and_teardown(Toy_Bucket** bucket) {
return 0;
}
int test_simple_execution(Toy_Bucket** bucket) {
int test_simple_execution(Toy_Bucket** bucketHandle) {
//test execution
{
//generate bytecode for testing
@@ -85,7 +85,7 @@ int test_simple_execution(Toy_Bucket** bucket) {
Toy_Parser parser;
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
Toy_Bytecode bc = Toy_compileBytecode(ast);
@@ -117,7 +117,7 @@ int test_simple_execution(Toy_Bucket** bucket) {
return 0;
}
int test_opcode_not_equal(Toy_Bucket** bucket) {
int test_opcode_not_equal(Toy_Bucket** bucketHandle) {
//testing a specific opcode; '!=' is compressed into a single word, so lets check it works
{
//generate bytecode for testing
@@ -129,7 +129,7 @@ int test_opcode_not_equal(Toy_Bucket** bucket) {
Toy_Parser parser;
Toy_bindParser(&parser, &lexer);
Toy_Ast* ast = Toy_scanParser(bucket, &parser);
Toy_Ast* ast = Toy_scanParser(bucketHandle, &parser);
Toy_Bytecode bc = Toy_compileBytecode(ast);