Added 'min' and 'max' as standard functions
Also fixed floating point printing with sprintf
This commit is contained in:
@@ -56,5 +56,3 @@ TOY_API void Toy_collectBucketGarbage(Toy_Bucket** bucketHandle);
|
||||
#ifndef TOY_BUCKET_IDEAL
|
||||
#define TOY_BUCKET_IDEAL (TOY_BUCKET_64KB - sizeof(Toy_Bucket))
|
||||
#endif
|
||||
|
||||
//TODO: check for leaks when freeBucket is called, for debugging
|
||||
@@ -787,7 +787,7 @@ static unsigned int writeInstructionForThen(Toy_Bytecode** mb, Toy_AstForThen as
|
||||
|
||||
emitString(mb, ast.condBranch->iterable.left->varDeclare.name);
|
||||
|
||||
//TODO: use a different approach
|
||||
//TODO: use a different approach?
|
||||
//BUGFIX: shadow the iterable's name
|
||||
EMIT_BYTE(mb, code, TOY_OPCODE_READ);
|
||||
EMIT_BYTE(mb, code, TOY_VALUE_NULL);
|
||||
|
||||
+3
-17
@@ -464,29 +464,15 @@ Toy_String* Toy_stringifyValue(Toy_Bucket** bucketHandle, Toy_Value value) {
|
||||
}
|
||||
|
||||
case TOY_VALUE_INTEGER: {
|
||||
char buffer[16];
|
||||
char buffer[128];
|
||||
sprintf(buffer, "%d", value.as.integer);
|
||||
return Toy_createStringLength(bucketHandle, buffer, strlen(buffer));
|
||||
}
|
||||
|
||||
case TOY_VALUE_FLOAT: {
|
||||
//using printf
|
||||
char buffer[16];
|
||||
sprintf(buffer, "%f", value.as.number);
|
||||
|
||||
//BUGFIX: printf format specificer '%f' will set the precision to 6 decimal places, which means there's trailing zeroes
|
||||
char buffer[128];
|
||||
sprintf(buffer, "%g", value.as.number);
|
||||
unsigned int length = strlen(buffer);
|
||||
|
||||
//find the decimal, if it exists
|
||||
unsigned int decimal = 0;
|
||||
while (decimal != length && buffer[decimal] != '.' && buffer[decimal] != ',') decimal++; //'.' and ',' supports more locales
|
||||
|
||||
//locales are hard, sorry!
|
||||
if (decimal != length && buffer[decimal] == ',') buffer[decimal] = '.';
|
||||
|
||||
//wipe the trailing zeros
|
||||
while(decimal != length && buffer[length-1] == '0') buffer[--length] = '\0';
|
||||
|
||||
return Toy_createStringLength(bucketHandle, buffer, length);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -546,7 +546,7 @@ static void processIterate(Toy_VM* vm) {
|
||||
processJump(vm);
|
||||
}
|
||||
}
|
||||
//TODO: support closures as a parameter
|
||||
//TODO: support closures in for-loops
|
||||
else {
|
||||
fprintf(stderr, TOY_CC_ERROR "ERROR: Unknown iterable type '%s' found in for loop, exiting\n" TOY_CC_RESET, Toy_getValueTypeAsCString(Toy_unwrapValue(compound).type));
|
||||
exit(-1);
|
||||
@@ -826,7 +826,7 @@ static void processAssert(Toy_VM* vm) {
|
||||
|
||||
//determine the args
|
||||
if (count == 1) {
|
||||
message = TOY_VALUE_FROM_STRING(Toy_toString(&vm->memoryBucket, "assertion failed")); //TODO: better default error message
|
||||
message = TOY_VALUE_FROM_STRING(Toy_toString(&vm->memoryBucket, "assertion failed")); //TODO: better default assert message
|
||||
value = Toy_popStack(&vm->stack);
|
||||
}
|
||||
else if (count == 2) {
|
||||
|
||||
Reference in New Issue
Block a user