mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
commandLine now initializes with default values
This commit is contained in:
@@ -15,23 +15,22 @@ STATIC_ASSERT(sizeof(unsigned char) == 1);
|
||||
STATIC_ASSERT(sizeof(unsigned short) == 2);
|
||||
STATIC_ASSERT(sizeof(unsigned int) == 4);
|
||||
|
||||
//declare the singleton
|
||||
Toy_CommandLine Toy_commandLine;
|
||||
//declare the singleton with default values
|
||||
Toy_CommandLine Toy_commandLine = {
|
||||
.error = false,
|
||||
.help = false,
|
||||
.version = false,
|
||||
.binaryfile = NULL,
|
||||
.sourcefile = NULL,
|
||||
.compilefile = NULL,
|
||||
.outfile = "out.tb",
|
||||
.source = NULL,
|
||||
.initialfile = NULL,
|
||||
.enablePrintNewline = true,
|
||||
.verbose = false
|
||||
};
|
||||
|
||||
void Toy_initCommandLine(int argc, const char* argv[]) {
|
||||
//default values
|
||||
Toy_commandLine.error = false;
|
||||
Toy_commandLine.help = false;
|
||||
Toy_commandLine.version = false;
|
||||
Toy_commandLine.binaryfile = NULL;
|
||||
Toy_commandLine.sourcefile = NULL;
|
||||
Toy_commandLine.compilefile = NULL;
|
||||
Toy_commandLine.outfile = "out.tb";
|
||||
Toy_commandLine.source = NULL;
|
||||
Toy_commandLine.initialfile = NULL;
|
||||
Toy_commandLine.enablePrintNewline = true;
|
||||
Toy_commandLine.verbose = false;
|
||||
|
||||
for (int i = 1; i < argc; i++) { //start at 1 to skip the program name
|
||||
Toy_commandLine.error = true; //error state by default, set to false by successful flags
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#define TOY_VERSION_MAJOR 0
|
||||
#define TOY_VERSION_MINOR 9
|
||||
#define TOY_VERSION_PATCH 1
|
||||
#define TOY_VERSION_PATCH 2
|
||||
#define TOY_VERSION_BUILD __DATE__ " " __TIME__
|
||||
|
||||
//platform/compiler-specific instructions
|
||||
|
||||
@@ -20,7 +20,7 @@ static void noPrintFn(const char* output) {
|
||||
}
|
||||
|
||||
void error(char* msg) {
|
||||
printf("%s", msg);
|
||||
printf("%s\n", msg);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ int main() {
|
||||
|
||||
//test answer
|
||||
{
|
||||
interpreter.printOutput("Testing answer\n");
|
||||
interpreter.printOutput("Testing answer");
|
||||
|
||||
Toy_LiteralArray arguments;
|
||||
Toy_initLiteralArray(&arguments);
|
||||
@@ -52,15 +52,15 @@ int main() {
|
||||
|
||||
//check the results
|
||||
if (arguments.count != 0) {
|
||||
error("Arguments has the wrong number of members\n");
|
||||
error("Arguments has the wrong number of members");
|
||||
}
|
||||
|
||||
if (returns.count != 1) {
|
||||
error("Returns has the wrong number of members\n");
|
||||
error("Returns has the wrong number of members");
|
||||
}
|
||||
|
||||
if (!TOY_IS_INTEGER(returns.literals[0]) || TOY_AS_INTEGER(returns.literals[0]) != 42) {
|
||||
error("Returned value is incorrect\n");
|
||||
error("Returned value is incorrect");
|
||||
}
|
||||
|
||||
Toy_freeLiteralArray(&arguments);
|
||||
@@ -69,7 +69,7 @@ int main() {
|
||||
|
||||
//test identity
|
||||
{
|
||||
interpreter.printOutput("Testing identity\n");
|
||||
interpreter.printOutput("Testing identity");
|
||||
|
||||
Toy_LiteralArray arguments;
|
||||
Toy_initLiteralArray(&arguments);
|
||||
@@ -85,17 +85,17 @@ int main() {
|
||||
|
||||
//check the results
|
||||
if (arguments.count != 0) {
|
||||
error("Arguments has the wrong number of members\n");
|
||||
error("Arguments has the wrong number of members");
|
||||
}
|
||||
|
||||
if (returns.count != 1) {
|
||||
error("Returns has the wrong number of members\n");
|
||||
error("Returns has the wrong number of members");
|
||||
}
|
||||
|
||||
float epsilon = 0.1; //because floats are evil
|
||||
|
||||
if (!TOY_IS_FLOAT(returns.literals[0]) || fabs(TOY_AS_FLOAT(returns.literals[0]) - pi) > epsilon) {
|
||||
error("Returned value is incorrect\n");
|
||||
error("Returned value is incorrect");
|
||||
}
|
||||
|
||||
Toy_freeLiteralArray(&arguments);
|
||||
@@ -104,7 +104,7 @@ int main() {
|
||||
|
||||
//test makeCounter (closures)
|
||||
{
|
||||
interpreter.printOutput("Testing makeCounter (closures)\n");
|
||||
interpreter.printOutput("Testing makeCounter (closures)");
|
||||
|
||||
Toy_LiteralArray arguments;
|
||||
Toy_initLiteralArray(&arguments);
|
||||
@@ -115,11 +115,11 @@ int main() {
|
||||
|
||||
//check the results
|
||||
if (arguments.count != 0) {
|
||||
error("Arguments has the wrong number of members\n");
|
||||
error("Arguments has the wrong number of members");
|
||||
}
|
||||
|
||||
if (returns.count != 1) {
|
||||
error("Returns has the wrong number of members\n");
|
||||
error("Returns has the wrong number of members");
|
||||
}
|
||||
|
||||
//grab the resulting literal
|
||||
@@ -139,15 +139,15 @@ int main() {
|
||||
|
||||
//check the results
|
||||
if (arguments.count != 0) {
|
||||
error("Arguments (1) has the wrong number of members\n");
|
||||
error("Arguments (1) has the wrong number of members");
|
||||
}
|
||||
|
||||
if (returns.count != 1) {
|
||||
error("Returns (1) has the wrong number of members\n");
|
||||
error("Returns (1) has the wrong number of members");
|
||||
}
|
||||
|
||||
if (!TOY_IS_INTEGER(returns.literals[0]) || TOY_AS_INTEGER(returns.literals[0]) != 1) {
|
||||
error("Returned value (1) is incorrect\n");
|
||||
error("Returned value (1) is incorrect");
|
||||
}
|
||||
|
||||
Toy_freeLiteralArray(&arguments);
|
||||
@@ -164,15 +164,15 @@ int main() {
|
||||
|
||||
//check the results
|
||||
if (arguments.count != 0) {
|
||||
error("Arguments (2) has the wrong number of members\n");
|
||||
error("Arguments (2) has the wrong number of members");
|
||||
}
|
||||
|
||||
if (returns.count != 1) {
|
||||
error("Returns (2) has the wrong number of members\n");
|
||||
error("Returns (2) has the wrong number of members");
|
||||
}
|
||||
|
||||
if (!TOY_IS_INTEGER(returns.literals[0]) || TOY_AS_INTEGER(returns.literals[0]) != 2) {
|
||||
error("Returned value (2) is incorrect\n");
|
||||
error("Returned value (2) is incorrect");
|
||||
}
|
||||
|
||||
Toy_freeLiteralArray(&arguments);
|
||||
@@ -189,15 +189,15 @@ int main() {
|
||||
|
||||
//check the results
|
||||
if (arguments.count != 0) {
|
||||
error("Arguments (3) has the wrong number of members\n");
|
||||
error("Arguments (3) has the wrong number of members");
|
||||
}
|
||||
|
||||
if (returns.count != 1) {
|
||||
error("Returns (3) has the wrong number of members\n");
|
||||
error("Returns (3) has the wrong number of members");
|
||||
}
|
||||
|
||||
if (!TOY_IS_INTEGER(returns.literals[0]) || TOY_AS_INTEGER(returns.literals[0]) != 3) {
|
||||
error("Returned value (3) is incorrect\n");
|
||||
error("Returned value (3) is incorrect");
|
||||
}
|
||||
|
||||
Toy_freeLiteralArray(&arguments);
|
||||
@@ -209,7 +209,7 @@ int main() {
|
||||
|
||||
//test assertion failure
|
||||
{
|
||||
interpreter.printOutput("Testing assertion failure\n");
|
||||
interpreter.printOutput("Testing assertion failure");
|
||||
|
||||
Toy_setInterpreterAssert(&interpreter, noPrintFn);
|
||||
|
||||
@@ -222,15 +222,15 @@ int main() {
|
||||
|
||||
//check the results
|
||||
if (arguments.count != 0) {
|
||||
error("Arguments has the wrong number of members\n");
|
||||
error("Arguments has the wrong number of members");
|
||||
}
|
||||
|
||||
if (returns.count != 1 || !TOY_IS_NULL(returns.literals[0])) {
|
||||
error("Returns has the wrong number of members\n");
|
||||
error("Returns has the wrong number of members");
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
error("Assertion gives the wrong return value\n");
|
||||
error("Assertion gives the wrong return value");
|
||||
}
|
||||
|
||||
Toy_freeLiteralArray(&arguments);
|
||||
|
||||
Reference in New Issue
Block a user