Added aliasing of standard as a feature of standard

This commit is contained in:
2022-09-24 07:20:26 +01:00
parent f745470abe
commit aa44d5fd43
7 changed files with 23 additions and 22 deletions

View File

@@ -36,16 +36,14 @@ DONE: slice and dot notation around the builtin _index and _dot functions
DONE: maximum recursion/function depth DONE: maximum recursion/function depth
DONE: better sugar for _push, _pop, _length DONE: better sugar for _push, _pop, _length
DONE: nested compound assignment bug DONE: nested compound assignment bug
DONE: hooks on the external libraries, triggered on import
TODO: hooks on the external libraries, triggered on import
TODO: standard library TODO: standard library
TODO: external script runner library TODO: external script runner library
TODO: document how it all works TODO: document how it all works
TODO: packaging for release? TODO: packaging for release?
TODO: test embedding TODO: test embedding in a game
NOPE: a = b = c = 1; NOPE: a = b = c = 1;
NOPE: functions return a set number of values NOPE: functions return a set number of values

View File

@@ -42,22 +42,20 @@ int hookStandard(Interpreter* interpreter, Literal identifier, Literal alias) {
{NULL, NULL} {NULL, NULL}
}; };
/* TODO: too exhuasted to fix this right now
//store the library in an aliased dictionary //store the library in an aliased dictionary
if (!IS_NULL(alias)) { 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 //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"); interpreter->errorOutput("Can't override an existing variable\n");
freeLiteral(dictName); freeLiteral(alias);
return false; return false;
} }
//create the dictionary to load up with functions
LiteralDictionary* dictionary = ALLOCATE(LiteralDictionary, 1); LiteralDictionary* dictionary = ALLOCATE(LiteralDictionary, 1);
initLiteralDictionary(dictionary); initLiteralDictionary(dictionary);
//load the dict with functions
for (int i = 0; natives[i].name; i++) { 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 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); Literal func = TO_FUNCTION_LITERAL((void*)natives[i].fn, 0);
@@ -78,16 +76,14 @@ int hookStandard(Interpreter* interpreter, Literal identifier, Literal alias) {
//set scope //set scope
Literal dict = TO_DICTIONARY_LITERAL(dictionary); Literal dict = TO_DICTIONARY_LITERAL(dictionary);
setLiteralDictionary(&interpreter->scope->variables, dictName, dict); declareScopeVariable(interpreter->scope, alias, type);
setLiteralDictionary(&interpreter->scope->types, dictName, type); setScopeVariable(interpreter->scope, alias, dict, false);
//cleanup //cleanup
freeLiteral(dict); freeLiteral(dict);
freeLiteral(type); freeLiteral(type);
freeLiteral(dictName);
return 0; return 0;
} }
*/
//default //default
for (int i = 0; natives[i].name; i++) { for (int i = 0; natives[i].name; i++) {

View File

@@ -1,7 +1,7 @@
CC=gcc CC=gcc
IDIR+=. ../source 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 LIBS+=-ltoy
ODIR = obj ODIR = obj

View File

@@ -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;

View File

@@ -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"; print "All good";

View File

@@ -1,7 +1,7 @@
CC=gcc CC=gcc
IDIR+=. 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+= LIBS+=
ODIR = obj ODIR = obj

View File

@@ -1,7 +1,7 @@
CC=gcc CC=gcc
IDIR +=. ../source 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 += LIBS +=
ODIR = obj ODIR = obj