Fixed API naming convention

Anything prepended with TOY_API is 'public'.

Anything that starts with Toy_private_* shouldn't be touched.
This commit is contained in:
2026-05-06 16:12:50 +10:00
parent 60a0fe8907
commit 185f3896c5
15 changed files with 44 additions and 44 deletions
+1 -1
View File
@@ -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);
+4 -4
View File
@@ -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;
}
}
+2 -2
View File
@@ -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));
+6 -6
View File
@@ -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;
}
+5 -5
View File
@@ -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);
+1 -1
View File
@@ -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;
}
+2 -2
View File
@@ -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);
/*
+1 -1
View File
@@ -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 {
+4 -4
View File
@@ -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);
+2 -2
View File
@@ -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;
}
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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
+7 -7
View File
@@ -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";
+1 -1
View File
@@ -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);
+4 -4
View File
@@ -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);
}