diff --git a/docs/TODO.txt b/docs/TODO.txt index 139bc91..c5a1818 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -36,16 +36,14 @@ DONE: slice and dot notation around the builtin _index and _dot functions DONE: maximum recursion/function depth DONE: better sugar for _push, _pop, _length DONE: nested compound assignment bug - - -TODO: hooks on the external libraries, triggered on import +DONE: hooks on the external libraries, triggered on import TODO: standard library TODO: external script runner library TODO: document how it all works TODO: packaging for release? -TODO: test embedding +TODO: test embedding in a game NOPE: a = b = c = 1; NOPE: functions return a set number of values diff --git a/repl/lib_standard.c b/repl/lib_standard.c index d86e979..5ad4bee 100644 --- a/repl/lib_standard.c +++ b/repl/lib_standard.c @@ -42,22 +42,20 @@ int hookStandard(Interpreter* interpreter, Literal identifier, Literal alias) { {NULL, NULL} }; - /* TODO: too exhuasted to fix this right now //store the library in an aliased dictionary if (!IS_NULL(alias)) { - //get the alias as a string - Literal dictName = TO_STRING_LITERAL( copyString(AS_IDENTIFIER(alias), alias.as.identifier.length), alias.as.identifier.length ); - //make sure the name isn't taken - if (existsLiteralDictionary(&interpreter->scope->variables, dictName)) { + if (isDelcaredScopeVariable(interpreter->scope, alias)) { interpreter->errorOutput("Can't override an existing variable\n"); - freeLiteral(dictName); + freeLiteral(alias); return false; } + //create the dictionary to load up with functions LiteralDictionary* dictionary = ALLOCATE(LiteralDictionary, 1); initLiteralDictionary(dictionary); + //load the dict with functions for (int i = 0; natives[i].name; i++) { Literal name = TO_STRING_LITERAL(copyString(natives[i].name, strlen(natives[i].name)), strlen(natives[i].name)); Literal func = TO_FUNCTION_LITERAL((void*)natives[i].fn, 0); @@ -78,16 +76,14 @@ int hookStandard(Interpreter* interpreter, Literal identifier, Literal alias) { //set scope Literal dict = TO_DICTIONARY_LITERAL(dictionary); - setLiteralDictionary(&interpreter->scope->variables, dictName, dict); - setLiteralDictionary(&interpreter->scope->types, dictName, type); + declareScopeVariable(interpreter->scope, alias, type); + setScopeVariable(interpreter->scope, alias, dict, false); //cleanup freeLiteral(dict); freeLiteral(type); - freeLiteral(dictName); return 0; } - */ //default for (int i = 0; natives[i].name; i++) { diff --git a/repl/makefile b/repl/makefile index b3ddf7c..494cd56 100644 --- a/repl/makefile +++ b/repl/makefile @@ -1,7 +1,7 @@ CC=gcc IDIR+=. ../source -CFLAGS+=$(addprefix -I,$(IDIR)) -g -Wall -W -pedantic -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable +CFLAGS+=$(addprefix -I,$(IDIR)) -g -Wall -W -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable LIBS+=-ltoy ODIR = obj diff --git a/scripts/small.toy b/scripts/small.toy index 314be54..445f223 100644 --- a/scripts/small.toy +++ b/scripts/small.toy @@ -1,6 +1,5 @@ -fn omitFirstInteger(arg1: int, ...rest) { - //rest comes in as an array of any - return rest; -} -print omitFirstInteger(1, 2, 3); \ No newline at end of file + +import standard as std; + +print std; diff --git a/scripts/test/lib/interactions.toy b/scripts/test/lib/interactions.toy index f4e1c64..a2a7134 100644 --- a/scripts/test/lib/interactions.toy +++ b/scripts/test/lib/interactions.toy @@ -39,4 +39,12 @@ } +//test importing as an alias +{ + import standard as std; + + assert std["clock"]().length() == 24, "import library as alias failed"; +} + + print "All good"; diff --git a/source/makefile b/source/makefile index e3287e5..b2bfdde 100644 --- a/source/makefile +++ b/source/makefile @@ -1,7 +1,7 @@ CC=gcc IDIR+=. -CFLAGS+=$(addprefix -I,$(IDIR)) -g -Wall -W -pedantic -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable +CFLAGS+=$(addprefix -I,$(IDIR)) -g -Wall -W -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable LIBS+= ODIR = obj diff --git a/test/makefile b/test/makefile index 80c0946..c35bf41 100644 --- a/test/makefile +++ b/test/makefile @@ -1,7 +1,7 @@ CC=gcc IDIR +=. ../source -CFLAGS +=$(addprefix -I,$(IDIR)) -g -Wall -W -pedantic -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable +CFLAGS +=$(addprefix -I,$(IDIR)) -g -Wall -W -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable LIBS += ODIR = obj