mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Found a leak, moving to linux
This commit is contained in:
@@ -27,6 +27,7 @@ DONE: native functions
|
|||||||
DONE: global functions _get, _set, _push, _pop, _length, clear available
|
DONE: global functions _get, _set, _push, _pop, _length, clear available
|
||||||
|
|
||||||
|
|
||||||
|
TODO: change comma to colon in dictionary definition?
|
||||||
TODO: slice and dot notation around the _index function
|
TODO: slice and dot notation around the _index function
|
||||||
TODO: ternary operator
|
TODO: ternary operator
|
||||||
TODO: Nullish types
|
TODO: Nullish types
|
||||||
|
|||||||
@@ -194,8 +194,8 @@ int hashLiteral(Literal lit) {
|
|||||||
return hash(res);
|
return hash(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
// case LITERAL_FUNCTION:
|
case LITERAL_FUNCTION:
|
||||||
// //
|
return 0;
|
||||||
|
|
||||||
case LITERAL_IDENTIFIER:
|
case LITERAL_IDENTIFIER:
|
||||||
return HASH_I(lit); //pre-computed
|
return HASH_I(lit); //pre-computed
|
||||||
|
|||||||
@@ -8,3 +8,5 @@ int hashLiteral(Literal lit);
|
|||||||
|
|
||||||
void printLiteral(Literal literal);
|
void printLiteral(Literal literal);
|
||||||
void printLiteralCustom(Literal literal, void (printFn)(const char*));
|
void printLiteralCustom(Literal literal, void (printFn)(const char*));
|
||||||
|
|
||||||
|
//TODO: copy literal (to be used in dictionaries and arrays, as well)
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ int main() {
|
|||||||
//test a single null literal
|
//test a single null literal
|
||||||
Literal literal = TO_NULL_LITERAL;
|
Literal literal = TO_NULL_LITERAL;
|
||||||
|
|
||||||
//
|
|
||||||
if (!IS_NULL(literal)) {
|
if (!IS_NULL(literal)) {
|
||||||
fprintf(stderr, ERROR "ERROR: null literal failed\n" RESET);
|
fprintf(stderr, ERROR "ERROR: null literal failed\n" RESET);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -22,7 +21,6 @@ int main() {
|
|||||||
Literal t = TO_BOOLEAN_LITERAL(true);
|
Literal t = TO_BOOLEAN_LITERAL(true);
|
||||||
Literal f = TO_BOOLEAN_LITERAL(false);
|
Literal f = TO_BOOLEAN_LITERAL(false);
|
||||||
|
|
||||||
//
|
|
||||||
if (!IS_TRUTHY(t) || IS_TRUTHY(f)) {
|
if (!IS_TRUTHY(t) || IS_TRUTHY(f)) {
|
||||||
fprintf(stderr, ERROR "ERROR: boolean literal failed\n" RESET);
|
fprintf(stderr, ERROR "ERROR: boolean literal failed\n" RESET);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -30,6 +28,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
//test string literals
|
||||||
char* buffer = ALLOCATE(char, 128);
|
char* buffer = ALLOCATE(char, 128);
|
||||||
|
|
||||||
snprintf(buffer, 128, "Hello world");
|
snprintf(buffer, 128, "Hello world");
|
||||||
@@ -39,6 +38,17 @@ int main() {
|
|||||||
freeLiteral(literal);
|
freeLiteral(literal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
//test identifier literals
|
||||||
|
char* buffer = ALLOCATE(char, 128);
|
||||||
|
|
||||||
|
snprintf(buffer, 128, "foobar");
|
||||||
|
|
||||||
|
Literal literal = TO_IDENTIFIER_LITERAL(buffer, 128);
|
||||||
|
|
||||||
|
freeLiteral(literal);
|
||||||
|
}
|
||||||
|
|
||||||
//check allocated memory
|
//check allocated memory
|
||||||
if (getAllocatedMemoryCount() != 0) {
|
if (getAllocatedMemoryCount() != 0) {
|
||||||
fprintf(stderr, ERROR "ERROR: Dangling memory detected: %d byes\n" RESET, getAllocatedMemoryCount());
|
fprintf(stderr, ERROR "ERROR: Dangling memory detected: %d byes\n" RESET, getAllocatedMemoryCount());
|
||||||
|
|||||||
78
test/test_literal_array.c
Normal file
78
test/test_literal_array.c
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
#include "literal_array.h"
|
||||||
|
|
||||||
|
#include "memory.h"
|
||||||
|
#include "console_colors.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
{
|
||||||
|
//test init & cleanup
|
||||||
|
LiteralArray array;
|
||||||
|
initLiteralArray(&array);
|
||||||
|
freeLiteralArray(&array);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
//test pushing and pulling
|
||||||
|
LiteralArray array;
|
||||||
|
initLiteralArray(&array);
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
pushLiteralArray(&array, TO_INTEGER_LITERAL(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 90; i++) {
|
||||||
|
Literal lit = popLiteralArray(&array);
|
||||||
|
|
||||||
|
freeLiteral(lit);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array.count != 10) {
|
||||||
|
fprintf(stderr, ERROR "ERROR: Array didn't clear the correct number of literal integers\n" RESET);
|
||||||
|
freeLiteralArray(&array);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
freeLiteralArray(&array);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
//check string, identifier and compound type behaviours
|
||||||
|
LiteralArray array;
|
||||||
|
initLiteralArray(&array);
|
||||||
|
|
||||||
|
//raw
|
||||||
|
char* str_raw = "hello world";
|
||||||
|
char* idn_raw = "foobar";
|
||||||
|
|
||||||
|
Literal string = TO_STRING_LITERAL(copyString(str_raw, strlen(str_raw)), strlen(str_raw));
|
||||||
|
Literal identifier = TO_IDENTIFIER_LITERAL(copyString(idn_raw, strlen(idn_raw)), strlen(idn_raw));
|
||||||
|
|
||||||
|
//[string, string]
|
||||||
|
Literal type = TO_TYPE_LITERAL(LITERAL_DICTIONARY, false);
|
||||||
|
TYPE_PUSH_SUBTYPE(&type, TO_TYPE_LITERAL(LITERAL_STRING, false));
|
||||||
|
TYPE_PUSH_SUBTYPE(&type, TO_TYPE_LITERAL(LITERAL_STRING, false));
|
||||||
|
|
||||||
|
//push
|
||||||
|
pushLiteralArray(&array, string);
|
||||||
|
pushLiteralArray(&array, identifier);
|
||||||
|
pushLiteralArray(&array, type);
|
||||||
|
|
||||||
|
//free the local literals
|
||||||
|
freeLiteral(string);
|
||||||
|
freeLiteral(identifier);
|
||||||
|
freeLiteral(type);
|
||||||
|
|
||||||
|
freeLiteralArray(&array);
|
||||||
|
}
|
||||||
|
|
||||||
|
//check allocated memory
|
||||||
|
if (getAllocatedMemoryCount() != 0) {
|
||||||
|
fprintf(stderr, ERROR "ERROR: Dangling memory detected: %d byes\n" RESET, getAllocatedMemoryCount());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(NOTICE "All good\n" RESET);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user