mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-19 16:54:08 +10:00
Renemed all variables to fit into a namespace
Basically, all Toy varaibles, functions, etc. are prepended with "Toy_", and macros are prepended with "TOY_". This is to reduce namespace pollution, which was an issue pointed out to be - blame @GyroVorbis. I've also bumped the minor version number - theoretically I should bump the major number, but I'm not quite ready for 1.0 yet.
This commit is contained in:
@@ -1,124 +1,124 @@
|
||||
#include "scope.h"
|
||||
#include "toy_scope.h"
|
||||
|
||||
#include "memory.h"
|
||||
#include "console_colors.h"
|
||||
#include "toy_memory.h"
|
||||
#include "toy_console_colors.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
{
|
||||
//test init & quit
|
||||
Scope* scope = pushScope(NULL);
|
||||
scope = popScope(scope);
|
||||
Toy_Scope* scope = Toy_pushScope(NULL);
|
||||
scope = Toy_popScope(scope);
|
||||
}
|
||||
|
||||
{
|
||||
//prerequisites
|
||||
char* idn_raw = "foobar";
|
||||
|
||||
Literal identifier = TO_IDENTIFIER_LITERAL(createRefString(idn_raw));
|
||||
Literal value = TO_INTEGER_LITERAL(42);
|
||||
Literal type = TO_TYPE_LITERAL(value.type, false);
|
||||
Toy_Literal identifier = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString(idn_raw));
|
||||
Toy_Literal value = TOY_TO_INTEGER_LITERAL(42);
|
||||
Toy_Literal type = TOY_TO_TYPE_LITERAL(value.type, false);
|
||||
|
||||
//test declarations & assignments
|
||||
Scope* scope = pushScope(NULL);
|
||||
Toy_Scope* scope = Toy_pushScope(NULL);
|
||||
|
||||
//declare & assign
|
||||
if (!declareScopeVariable(scope, identifier, type)) {
|
||||
printf(ERROR "Failed to declare scope variable" RESET);
|
||||
if (!Toy_declareScopeVariable(scope, identifier, type)) {
|
||||
printf(TOY_CC_ERROR "Failed to declare scope variable" TOY_CC_RESET);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!setScopeVariable(scope, identifier, value, true)) {
|
||||
printf(ERROR "Failed to sete scope variable" RESET);
|
||||
if (!Toy_setScopeVariable(scope, identifier, value, true)) {
|
||||
printf(TOY_CC_ERROR "Failed to sete scope variable" TOY_CC_RESET);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//cleanup
|
||||
scope = popScope(scope);
|
||||
scope = Toy_popScope(scope);
|
||||
|
||||
freeLiteral(identifier);
|
||||
freeLiteral(value);
|
||||
freeLiteral(type);
|
||||
Toy_freeLiteral(identifier);
|
||||
Toy_freeLiteral(value);
|
||||
Toy_freeLiteral(type);
|
||||
}
|
||||
|
||||
{
|
||||
//prerequisites
|
||||
char* idn_raw = "foobar";
|
||||
|
||||
Literal identifier = TO_IDENTIFIER_LITERAL(createRefString(idn_raw));
|
||||
Literal type = TO_TYPE_LITERAL(LITERAL_INTEGER, false);
|
||||
Toy_Literal identifier = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString(idn_raw));
|
||||
Toy_Literal type = TOY_TO_TYPE_LITERAL(TOY_LITERAL_INTEGER, false);
|
||||
|
||||
//test declarations & assignments
|
||||
Scope* scope = pushScope(NULL);
|
||||
Toy_Scope* scope = Toy_pushScope(NULL);
|
||||
|
||||
//declare & assign
|
||||
if (!declareScopeVariable(scope, identifier, type)) {
|
||||
printf(ERROR "Failed to declare the scope variable" RESET);
|
||||
if (!Toy_declareScopeVariable(scope, identifier, type)) {
|
||||
printf(TOY_CC_ERROR "Failed to declare the scope variable" TOY_CC_RESET);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!setScopeVariable(scope, identifier, TO_INTEGER_LITERAL(42), true)) {
|
||||
printf(ERROR "Failed to set the scope variable" RESET);
|
||||
if (!Toy_setScopeVariable(scope, identifier, TOY_TO_INTEGER_LITERAL(42), true)) {
|
||||
printf(TOY_CC_ERROR "Failed to set the scope variable" TOY_CC_RESET);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//deeper scope
|
||||
scope = pushScope(scope);
|
||||
scope = Toy_pushScope(scope);
|
||||
|
||||
//test shadowing
|
||||
Literal ref;
|
||||
if (!getScopeVariable(scope, identifier, &ref)) {
|
||||
printf(ERROR "Failed to get the scope variable" RESET);
|
||||
Toy_Literal ref;
|
||||
if (!Toy_getScopeVariable(scope, identifier, &ref)) {
|
||||
printf(TOY_CC_ERROR "Failed to get the scope variable" TOY_CC_RESET);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (AS_INTEGER(ref) != 42) {
|
||||
printf(ERROR "Failed to retreive the correct variable value" RESET);
|
||||
if (TOY_AS_INTEGER(ref) != 42) {
|
||||
printf(TOY_CC_ERROR "Failed to retreive the correct variable value" TOY_CC_RESET);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!declareScopeVariable(scope, identifier, type)) {
|
||||
printf(ERROR "Failed to declare the scope variable (shadowing)" RESET);
|
||||
if (!Toy_declareScopeVariable(scope, identifier, type)) {
|
||||
printf(TOY_CC_ERROR "Failed to declare the scope variable (shadowing)" TOY_CC_RESET);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!setScopeVariable(scope, identifier, TO_INTEGER_LITERAL(69), true)) {
|
||||
printf(ERROR "Failed to set the scope variable (shadowing)" RESET);
|
||||
if (!Toy_setScopeVariable(scope, identifier, TOY_TO_INTEGER_LITERAL(69), true)) {
|
||||
printf(TOY_CC_ERROR "Failed to set the scope variable (shadowing)" TOY_CC_RESET);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!getScopeVariable(scope, identifier, &ref)) {
|
||||
printf(ERROR "Failed to get the scope variable (shadowing)" RESET);
|
||||
if (!Toy_getScopeVariable(scope, identifier, &ref)) {
|
||||
printf(TOY_CC_ERROR "Failed to get the scope variable (shadowing)" TOY_CC_RESET);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (AS_INTEGER(ref) != 69) {
|
||||
printf(ERROR "Failed to retreive the correct variable value (shadowing)" RESET);
|
||||
if (TOY_AS_INTEGER(ref) != 69) {
|
||||
printf(TOY_CC_ERROR "Failed to retreive the correct variable value (shadowing)" TOY_CC_RESET);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//unwind
|
||||
scope = popScope(scope);
|
||||
scope = Toy_popScope(scope);
|
||||
|
||||
if (!getScopeVariable(scope, identifier, &ref)) {
|
||||
printf(ERROR "Failed to get the scope variable" RESET);
|
||||
if (!Toy_getScopeVariable(scope, identifier, &ref)) {
|
||||
printf(TOY_CC_ERROR "Failed to get the scope variable" TOY_CC_RESET);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (AS_INTEGER(ref) != 42) {
|
||||
printf(ERROR "Failed to retreive the correct variable value" RESET);
|
||||
if (TOY_AS_INTEGER(ref) != 42) {
|
||||
printf(TOY_CC_ERROR "Failed to retreive the correct variable value" TOY_CC_RESET);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//cleanup
|
||||
scope = popScope(scope);
|
||||
scope = Toy_popScope(scope);
|
||||
|
||||
freeLiteral(identifier);
|
||||
freeLiteral(type);
|
||||
Toy_freeLiteral(identifier);
|
||||
Toy_freeLiteral(type);
|
||||
}
|
||||
|
||||
printf(NOTICE "All good\n" RESET);
|
||||
printf(TOY_CC_NOTICE "All good\n" TOY_CC_RESET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user