mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Added aliasing of standard as a feature of standard
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
fn omitFirstInteger(arg1: int, ...rest) {
|
||||
//rest comes in as an array of any
|
||||
return rest;
|
||||
}
|
||||
|
||||
print omitFirstInteger(1, 2, 3);
|
||||
|
||||
import standard as std;
|
||||
|
||||
print std;
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user