From 185f3896c52c781bcca6d22205f4be50eeaeff7f Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 6 May 2026 16:12:50 +1000 Subject: [PATCH] Fixed API naming convention Anything prepended with TOY_API is 'public'. Anything that starts with Toy_private_* shouldn't be touched. --- repl/ast_inspector.c | 2 +- repl/bytecode_inspector.c | 8 ++++---- repl/main.c | 4 ++-- source/toy_attributes.c | 12 ++++++------ source/toy_attributes.h | 10 +++++----- source/toy_common.c | 2 +- source/toy_common.h | 4 ++-- source/toy_compiler.h | 2 +- source/toy_lexer.h | 8 ++++---- source/toy_scope.c | 4 ++-- source/toy_scope.h | 4 ++-- source/toy_table.h | 4 ++-- source/toy_value.c | 14 +++++++------- source/toy_value.h | 2 +- source/toy_vm.c | 8 ++++---- 15 files changed, 44 insertions(+), 44 deletions(-) diff --git a/repl/ast_inspector.c b/repl/ast_inspector.c index 458bfcd..079ac42 100644 --- a/repl/ast_inspector.c +++ b/repl/ast_inspector.c @@ -84,7 +84,7 @@ void inspect_value(Toy_Ast* ast, int depth) { Toy_String* str = Toy_stringifyValue(&bucket, ast->value.value); char* buffer = Toy_getStringRaw(str); //SLOW - printf("%s '%s'", Toy_private_getValueTypeAsCString(ast->value.value.type), buffer); + printf("%s '%s'", Toy_getValueTypeAsCString(ast->value.value.type), buffer); free(buffer); Toy_freeString(str); diff --git a/repl/bytecode_inspector.c b/repl/bytecode_inspector.c index a78c538..292fd47 100644 --- a/repl/bytecode_inspector.c +++ b/repl/bytecode_inspector.c @@ -114,7 +114,7 @@ int inspect_bytecode(unsigned char* bytecode) { for (unsigned int i = 0; (i*4) < paramSize; i += 2) { printf(MARKER TOY_CC_NOTICE "%u (type %s, data %u)" TOY_CC_RESET "\n", MARKER_VALUE(param_addr + i, unsigned int), i, - Toy_private_getValueTypeAsCString(((unsigned int*)(bytecode + param_addr))[i + 1]), + Toy_getValueTypeAsCString(((unsigned int*)(bytecode + param_addr))[i + 1]), ((unsigned int*)(bytecode + param_addr))[i] + data_addr ); } @@ -162,7 +162,7 @@ int inspect_instruction(unsigned char* bytecode, unsigned int pc, unsigned int j char* cstr = ((char*)(bytecode + data_addr + jumpValue)); printf(MARKER "DECLARE %s: %s%s\n", MARKER_VALUE(pc, unsigned char), cstr, - Toy_private_getValueTypeAsCString(bytecode[pc + 1]), + Toy_getValueTypeAsCString(bytecode[pc + 1]), bytecode[pc + 3] ? " const" : "" ); return 8; @@ -182,7 +182,7 @@ int inspect_instruction(unsigned char* bytecode, unsigned int pc, unsigned int j case TOY_OPCODE_INVOKE: printf(MARKER "INVOKE as '%s' (%d parameters)\n", MARKER_VALUE(pc, unsigned char), - Toy_private_getValueTypeAsCString(bytecode[pc + 1]), + Toy_getValueTypeAsCString(bytecode[pc + 1]), bytecode[pc + 2]); return 4; @@ -380,7 +380,7 @@ int inspect_read(unsigned char* bytecode, unsigned int pc, unsigned int jumps_ad case TOY_VALUE_ANY: case TOY_VALUE_UNKNOWN: default: { - printf(MARKER TOY_CC_WARN "READ %s (unhandled by inspector)" TOY_CC_RESET "\n", MARKER_VALUE(pc, unsigned char), Toy_private_getValueTypeAsCString(type)); + printf(MARKER TOY_CC_WARN "READ %s (unhandled by inspector)" TOY_CC_RESET "\n", MARKER_VALUE(pc, unsigned char), Toy_getValueTypeAsCString(type)); return 4; } } diff --git a/repl/main.c b/repl/main.c index 7099cd4..499ddcf 100644 --- a/repl/main.c +++ b/repl/main.c @@ -259,7 +259,7 @@ static void debugStackPrint(Toy_Stack* stack) { Toy_Value v = ((Toy_Value*)(stack + 1))[i]; //'stack + 1' is a naughty trick //print type - printf("%-20s", Toy_private_getValueTypeAsCString(v.type)); + printf("%-20s", Toy_getValueTypeAsCString(v.type)); //print value Toy_String* string = Toy_stringifyValue(&stringBucket, Toy_unwrapValue(v)); @@ -289,7 +289,7 @@ static void debugScopePrint(Toy_Scope* scope, int depth) { Toy_String k = scope->data[i].key; Toy_Value v = scope->data[i].value; - printf("%-10s%-10s%-20s", Toy_private_getValueTypeAsCString(scope->data[i].type), scope->data[i].constant ? "const" : "", k.leaf.data); + printf("%-10s%-10s%-20s", Toy_getValueTypeAsCString(scope->data[i].type), scope->data[i].constant ? "const" : "", k.leaf.data); //print value Toy_String* string = Toy_stringifyValue(&stringBucket, Toy_unwrapValue(v)); diff --git a/source/toy_attributes.c b/source/toy_attributes.c index c999af5..e54364d 100644 --- a/source/toy_attributes.c +++ b/source/toy_attributes.c @@ -35,7 +35,7 @@ Toy_Value Toy_private_handleStringAttributes(Toy_VM* vm, Toy_Value compound, Toy } else { char buffer[256]; - snprintf(buffer, 256, "Unknown attribute '%s' of type '%s'", TOY_VALUE_AS_STRING(attribute)->leaf.data, Toy_private_getValueTypeAsCString(compound.type)); + snprintf(buffer, 256, "Unknown attribute '%s' of type '%s'", TOY_VALUE_AS_STRING(attribute)->leaf.data, Toy_getValueTypeAsCString(compound.type)); Toy_error(buffer); return TOY_VALUE_FROM_NULL(); } @@ -88,7 +88,7 @@ static void attr_arrayForEach(Toy_VM* vm) { if (TOY_VALUE_IS_FUNCTION(callback) != true) { char buffer[256]; - snprintf(buffer, 256, "Expected function, found '%s'", Toy_private_getValueTypeAsCString(callback.type)); + snprintf(buffer, 256, "Expected function, found '%s'", Toy_getValueTypeAsCString(callback.type)); Toy_error(buffer); return; } @@ -169,7 +169,7 @@ Toy_Value Toy_private_handleArrayAttributes(Toy_VM* vm, Toy_Value compound, Toy_ } else { char buffer[256]; - snprintf(buffer, 256, "Unknown attribute '%s' of type '%s'", TOY_VALUE_AS_STRING(attribute)->leaf.data, Toy_private_getValueTypeAsCString(compound.type)); + snprintf(buffer, 256, "Unknown attribute '%s' of type '%s'", TOY_VALUE_AS_STRING(attribute)->leaf.data, Toy_getValueTypeAsCString(compound.type)); Toy_error(buffer); return TOY_VALUE_FROM_NULL(); } @@ -245,7 +245,7 @@ Toy_Value Toy_private_handleTableAttributes(Toy_VM* vm, Toy_Value compound, Toy_ } else { char buffer[256]; - snprintf(buffer, 256, "Unknown attribute '%s' of type '%s'", TOY_VALUE_AS_STRING(attribute)->leaf.data, Toy_private_getValueTypeAsCString(compound.type)); + snprintf(buffer, 256, "Unknown attribute '%s' of type '%s'", TOY_VALUE_AS_STRING(attribute)->leaf.data, Toy_getValueTypeAsCString(compound.type)); Toy_error(buffer); return TOY_VALUE_FROM_NULL(); } @@ -254,7 +254,7 @@ Toy_Value Toy_private_handleTableAttributes(Toy_VM* vm, Toy_Value compound, Toy_ Toy_Value Toy_private_handleOpaqueAttributes(Toy_VM* vm, Toy_Value compound, Toy_Value attribute) { if (opaqueAttributeCallback == NULL) { char buffer[256]; - snprintf(buffer, 256, "Unknown attribute '%s' of type '%s' (did you set the opaque callbacks?)", TOY_VALUE_AS_STRING(attribute)->leaf.data, Toy_private_getValueTypeAsCString(compound.type)); + snprintf(buffer, 256, "Unknown attribute '%s' of type '%s' (did you set the opaque callbacks?)", TOY_VALUE_AS_STRING(attribute)->leaf.data, Toy_getValueTypeAsCString(compound.type)); Toy_error(buffer); return TOY_VALUE_FROM_NULL(); } @@ -262,6 +262,6 @@ Toy_Value Toy_private_handleOpaqueAttributes(Toy_VM* vm, Toy_Value compound, Toy return opaqueAttributeCallback(vm, compound, attribute); } -void Toy_private_setOpaqueAttributeHandler(Toy_OpaqueAttributeHandler cb) { +void Toy_setOpaqueAttributeHandler(Toy_OpaqueAttributeHandler cb) { opaqueAttributeCallback = cb; } \ No newline at end of file diff --git a/source/toy_attributes.h b/source/toy_attributes.h index f42a8a0..1e6811d 100644 --- a/source/toy_attributes.h +++ b/source/toy_attributes.h @@ -19,11 +19,11 @@ // [x] table.remove(x) // [ ] table.forEach(fn) // fn(x,y) -> void -TOY_API Toy_Value Toy_private_handleStringAttributes(Toy_VM* vm, Toy_Value compound, Toy_Value attribute); -TOY_API Toy_Value Toy_private_handleArrayAttributes(Toy_VM* vm, Toy_Value compound, Toy_Value attribute); -TOY_API Toy_Value Toy_private_handleTableAttributes(Toy_VM* vm, Toy_Value compound, Toy_Value attribute); -TOY_API Toy_Value Toy_private_handleOpaqueAttributes(Toy_VM* vm, Toy_Value compound, Toy_Value attribute); +Toy_Value Toy_private_handleStringAttributes(Toy_VM* vm, Toy_Value compound, Toy_Value attribute); +Toy_Value Toy_private_handleArrayAttributes(Toy_VM* vm, Toy_Value compound, Toy_Value attribute); +Toy_Value Toy_private_handleTableAttributes(Toy_VM* vm, Toy_Value compound, Toy_Value attribute); +Toy_Value Toy_private_handleOpaqueAttributes(Toy_VM* vm, Toy_Value compound, Toy_Value attribute); //plug-and-play attributes for custom objects typedef Toy_Value (*Toy_OpaqueAttributeHandler)(Toy_VM* vm, Toy_Value compound, Toy_Value attribute); -TOY_API void Toy_private_setOpaqueAttributeHandler(Toy_OpaqueAttributeHandler cb); +TOY_API void Toy_setOpaqueAttributeHandler(Toy_OpaqueAttributeHandler cb); \ No newline at end of file diff --git a/source/toy_common.c b/source/toy_common.c index 8ae0cf5..1ed5521 100644 --- a/source/toy_common.c +++ b/source/toy_common.c @@ -3,6 +3,6 @@ //defined separately, as compilation can take several seconds, invalidating the comparisons of the given macros static const char* build = __DATE__ " " __TIME__ ", incomplete Toy v2.x"; -const char* Toy_private_version_build(void) { +const char* Toy_private_versionBuild(void) { return build; } diff --git a/source/toy_common.h b/source/toy_common.h index b757a5c..b4b1cdb 100644 --- a/source/toy_common.h +++ b/source/toy_common.h @@ -59,8 +59,8 @@ #define TOY_VERSION_PATCH 0 //defined as a function, for technical reasons -#define TOY_VERSION_BUILD Toy_private_version_build() -TOY_API const char* Toy_private_version_build(void); +#define TOY_VERSION_BUILD Toy_private_versionBuild() +const char* Toy_private_versionBuild(void); /* diff --git a/source/toy_compiler.h b/source/toy_compiler.h index 051588a..c5473ad 100644 --- a/source/toy_compiler.h +++ b/source/toy_compiler.h @@ -24,7 +24,7 @@ typedef struct Toy_private_EscapeArray { #define TOY_ESCAPE_EXPANSION_RATE 4 #endif -TOY_API Toy_private_EscapeArray* Toy_private_resizeEscapeArray(Toy_private_EscapeArray* ptr, unsigned int capacity); +Toy_private_EscapeArray* Toy_private_resizeEscapeArray(Toy_private_EscapeArray* ptr, unsigned int capacity); //structure for holding the bytecode during compilation typedef struct Toy_Bytecode { diff --git a/source/toy_lexer.h b/source/toy_lexer.h index 30d3cae..6b77016 100644 --- a/source/toy_lexer.h +++ b/source/toy_lexer.h @@ -20,9 +20,9 @@ typedef struct { } Toy_Token; TOY_API void Toy_bindLexer(Toy_Lexer* lexer, const char* source); -TOY_API Toy_Token Toy_private_scanLexer(Toy_Lexer* lexer); +Toy_Token Toy_private_scanLexer(Toy_Lexer* lexer); -TOY_API const char* Toy_private_findKeywordByType(const Toy_TokenType type); -TOY_API Toy_TokenType Toy_private_findTypeByKeyword(const char* keyword); -TOY_API void Toy_private_printToken(Toy_Token* token); +const char* Toy_private_findKeywordByType(const Toy_TokenType type); +Toy_TokenType Toy_private_findTypeByKeyword(const char* keyword); +void Toy_private_printToken(Toy_Token* token); diff --git a/source/toy_scope.c b/source/toy_scope.c index f65412b..d71144e 100644 --- a/source/toy_scope.c +++ b/source/toy_scope.c @@ -157,7 +157,7 @@ void Toy_declareScope(Toy_Scope* scope, Toy_String* key, Toy_ValueType type, Toy //type check if (type != TOY_VALUE_ANY && value.type != TOY_VALUE_NULL && type != value.type && value.type != TOY_VALUE_REFERENCE) { char buffer[key->info.length + 256]; - sprintf(buffer, "Incorrect value type in declaration of '%.*s' (expected %s, got %s)", key->info.length, key->leaf.data, Toy_private_getValueTypeAsCString(type), Toy_private_getValueTypeAsCString(value.type)); + sprintf(buffer, "Incorrect value type in declaration of '%.*s' (expected %s, got %s)", key->info.length, key->leaf.data, Toy_getValueTypeAsCString(type), Toy_getValueTypeAsCString(value.type)); Toy_error(buffer); return; } @@ -180,7 +180,7 @@ void Toy_assignScope(Toy_Scope* scope, Toy_String* key, Toy_Value value) { //type check if (entryPtr->type != TOY_VALUE_ANY && value.type != TOY_VALUE_NULL && entryPtr->type != value.type && value.type != TOY_VALUE_REFERENCE) { char buffer[key->info.length + 256]; - sprintf(buffer, "Incorrect value type in assignment of '%.*s' (expected %s, got %s)", key->info.length, key->leaf.data, Toy_private_getValueTypeAsCString(entryPtr->type), Toy_private_getValueTypeAsCString(value.type)); + sprintf(buffer, "Incorrect value type in assignment of '%.*s' (expected %s, got %s)", key->info.length, key->leaf.data, Toy_getValueTypeAsCString(entryPtr->type), Toy_getValueTypeAsCString(value.type)); Toy_error(buffer); return; } diff --git a/source/toy_scope.h b/source/toy_scope.h index 249366a..b8c40e1 100644 --- a/source/toy_scope.h +++ b/source/toy_scope.h @@ -37,8 +37,8 @@ TOY_API Toy_Value* Toy_accessScopeAsPointer(Toy_Scope* scope, Toy_String* key); TOY_API bool Toy_isDeclaredScope(Toy_Scope* scope, Toy_String* key); //manage refcounting -TOY_API void Toy_private_incrementScopeRefCount(Toy_Scope* scope); -TOY_API void Toy_private_decrementScopeRefCount(Toy_Scope* scope); +void Toy_private_incrementScopeRefCount(Toy_Scope* scope); +void Toy_private_decrementScopeRefCount(Toy_Scope* scope); //some useful sizes, could be swapped out as needed #ifndef TOY_SCOPE_INITIAL_CAPACITY diff --git a/source/toy_table.h b/source/toy_table.h index ee85d4b..dfd8948 100644 --- a/source/toy_table.h +++ b/source/toy_table.h @@ -25,8 +25,8 @@ 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); -TOY_API Toy_TableEntry* Toy_private_lookupTableEntryPtr(Toy_Table** tableHandle, Toy_Value key); +Toy_Table* Toy_private_adjustTableCapacity(Toy_Table* oldTable, unsigned int newCapacity); +Toy_TableEntry* Toy_private_lookupTableEntryPtr(Toy_Table** tableHandle, Toy_Value key); //some useful sizes, could be swapped out as needed #ifndef TOY_TABLE_INITIAL_CAPACITY diff --git a/source/toy_value.c b/source/toy_value.c index 37cb426..82d761c 100644 --- a/source/toy_value.c +++ b/source/toy_value.c @@ -83,7 +83,7 @@ unsigned int Toy_hashValue(Toy_Value value) { case TOY_VALUE_ANY: case TOY_VALUE_REFERENCE: case TOY_VALUE_UNKNOWN: - fprintf(stderr, TOY_CC_ERROR "ERROR: Can't hash a given value type '%s', exiting\n" TOY_CC_RESET, Toy_private_getValueTypeAsCString(value.type)); + fprintf(stderr, TOY_CC_ERROR "ERROR: Can't hash a given value type '%s', exiting\n" TOY_CC_RESET, Toy_getValueTypeAsCString(value.type)); exit(-1); } @@ -147,7 +147,7 @@ Toy_Value Toy_copyValue(Toy_Bucket** bucketHandle, Toy_Value value) { case TOY_VALUE_ANY: case TOY_VALUE_REFERENCE: case TOY_VALUE_UNKNOWN: - fprintf(stderr, TOY_CC_ERROR "ERROR: Can't copy a given value type '%s', exiting\n" TOY_CC_RESET, Toy_private_getValueTypeAsCString(value.type)); + fprintf(stderr, TOY_CC_ERROR "ERROR: Can't copy a given value type '%s', exiting\n" TOY_CC_RESET, Toy_getValueTypeAsCString(value.type)); exit(-1); } @@ -190,7 +190,7 @@ void Toy_freeValue(Toy_Value value) { case TOY_VALUE_ANY: case TOY_VALUE_UNKNOWN: - fprintf(stderr, TOY_CC_ERROR "ERROR: Can't free a given value type '%s', exiting\n" TOY_CC_RESET, Toy_private_getValueTypeAsCString(value.type)); + fprintf(stderr, TOY_CC_ERROR "ERROR: Can't free a given value type '%s', exiting\n" TOY_CC_RESET, Toy_getValueTypeAsCString(value.type)); exit(-1); } } @@ -335,7 +335,7 @@ bool Toy_checkValuesAreEqual(Toy_Value left, Toy_Value right) { case TOY_VALUE_ANY: case TOY_VALUE_REFERENCE: case TOY_VALUE_UNKNOWN: - fprintf(stderr, TOY_CC_ERROR "ERROR: Can't find equality for a given value type '%s', exiting\n" TOY_CC_RESET, Toy_private_getValueTypeAsCString(left.type)); + fprintf(stderr, TOY_CC_ERROR "ERROR: Can't find equality for a given value type '%s', exiting\n" TOY_CC_RESET, Toy_getValueTypeAsCString(left.type)); exit(-1); } @@ -442,7 +442,7 @@ int Toy_compareValues(Toy_Value left, Toy_Value right) { break; } - fprintf(stderr, TOY_CC_ERROR "ERROR: Can't compare with a given value type '%s', exiting\n" TOY_CC_RESET, Toy_private_getValueTypeAsCString(left.type)); + fprintf(stderr, TOY_CC_ERROR "ERROR: Can't compare with a given value type '%s', exiting\n" TOY_CC_RESET, Toy_getValueTypeAsCString(left.type)); exit(-1); return ~0; @@ -658,14 +658,14 @@ Toy_String* Toy_stringifyValue(Toy_Bucket** bucketHandle, Toy_Value value) { case TOY_VALUE_ANY: case TOY_VALUE_REFERENCE: case TOY_VALUE_UNKNOWN: - fprintf(stderr, TOY_CC_ERROR "ERROR: Can't stringify a given value type '%s', exiting\n" TOY_CC_RESET, Toy_private_getValueTypeAsCString(value.type)); + fprintf(stderr, TOY_CC_ERROR "ERROR: Can't stringify a given value type '%s', exiting\n" TOY_CC_RESET, Toy_getValueTypeAsCString(value.type)); exit(-1); } return NULL; } -const char* Toy_private_getValueTypeAsCString(Toy_ValueType type) { +const char* Toy_getValueTypeAsCString(Toy_ValueType type) { switch (type) { case TOY_VALUE_NULL: return "Null"; case TOY_VALUE_BOOLEAN: return "Bool"; diff --git a/source/toy_value.h b/source/toy_value.h index c642fc6..41c847f 100644 --- a/source/toy_value.h +++ b/source/toy_value.h @@ -91,4 +91,4 @@ TOY_API int Toy_compareValues(Toy_Value left, Toy_Value right); TOY_API union Toy_String_t* Toy_stringifyValue(struct Toy_Bucket** bucketHandle, Toy_Value value); //for error messages -TOY_API const char* Toy_private_getValueTypeAsCString(Toy_ValueType type); +TOY_API const char* Toy_getValueTypeAsCString(Toy_ValueType type); diff --git a/source/toy_vm.c b/source/toy_vm.c index e765f85..4050a7f 100644 --- a/source/toy_vm.c +++ b/source/toy_vm.c @@ -441,7 +441,7 @@ static void processAttribute(Toy_VM* vm) { } else { char buffer[256]; - snprintf(buffer, 256, "Can't access an attribute of type '%s'", Toy_private_getValueTypeAsCString(compound.type)); + snprintf(buffer, 256, "Can't access an attribute of type '%s'", Toy_getValueTypeAsCString(compound.type)); Toy_error(buffer); Toy_pushStack(&vm->stack, TOY_VALUE_FROM_NULL()); return; @@ -484,7 +484,7 @@ static void processArithmetic(Toy_VM* vm, Toy_OpcodeType opcode) { //check types if ((!TOY_VALUE_IS_INTEGER(left) && !TOY_VALUE_IS_FLOAT(left)) || (!TOY_VALUE_IS_INTEGER(right) && !TOY_VALUE_IS_FLOAT(right))) { char buffer[256]; - snprintf(buffer, 256, "Invalid types '%s' and '%s' passed in arithmetic", Toy_private_getValueTypeAsCString(left.type), Toy_private_getValueTypeAsCString(right.type)); + snprintf(buffer, 256, "Invalid types '%s' and '%s' passed in arithmetic", Toy_getValueTypeAsCString(left.type), Toy_getValueTypeAsCString(right.type)); Toy_error(buffer); Toy_freeValue(left); @@ -578,7 +578,7 @@ static void processComparison(Toy_VM* vm, Toy_OpcodeType opcode) { if (Toy_checkValuesAreComparable(left, right) != true) { char buffer[256]; - snprintf(buffer, 256, "Can't compare value types '%s' and '%s'", Toy_private_getValueTypeAsCString(left.type), Toy_private_getValueTypeAsCString(right.type)); + snprintf(buffer, 256, "Can't compare value types '%s' and '%s'", Toy_getValueTypeAsCString(left.type), Toy_getValueTypeAsCString(right.type)); Toy_error(buffer); Toy_freeValue(left); @@ -945,7 +945,7 @@ static void processIndex(Toy_VM* vm) { } else { - fprintf(stderr, TOY_CC_ERROR "ERROR: Unknown value type '%s' found in processIndex, exiting\n" TOY_CC_RESET, Toy_private_getValueTypeAsCString(value.type)); + fprintf(stderr, TOY_CC_ERROR "ERROR: Unknown value type '%s' found in processIndex, exiting\n" TOY_CC_RESET, Toy_getValueTypeAsCString(value.type)); exit(-1); }