diff --git a/docs/TODO.txt b/docs/TODO.txt index 90fecf0..ec13803 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -32,11 +32,7 @@ DONE: third output stream, for lexer/parser/compiler/interpreter errors DONE: Assertion-based test scripts DONE: Import/export keywords DONE: A way to check the type of a variable (typeOf keyword) - - -TODO: slice and dot notation around the builtin _index and _dot functions -//TODO: check this const-ness -//TODO: add arithmetics +DONE: slice and dot notation around the builtin _index and _dot functions TODO: ternary operator @@ -47,6 +43,8 @@ TODO: external script runner library TODO: document how it all works - book? TODO: maximum recursion/function depth TODO: better API +TODO: better sugar for _push and _pop +TODO: nested compound assignment TODO: packaging for release? NOPE: a = b = c = 1; diff --git a/scripts/small.toy b/scripts/small.toy new file mode 100644 index 0000000..ae96b43 --- /dev/null +++ b/scripts/small.toy @@ -0,0 +1,10 @@ + + +var t: type = typeas [[int]]; + +var a: t = [ + [1, 2, 3] +]; + +print a; +print typeof a; diff --git a/source/interpreter.c b/source/interpreter.c index b657117..26af053 100644 --- a/source/interpreter.c +++ b/source/interpreter.c @@ -1625,7 +1625,7 @@ static bool execIndexAssign(Interpreter* interpreter) { LiteralArray arguments; initLiteralArray(&arguments); - pushLiteralArray(&arguments, compound); + pushLiteralArray(&arguments, compound); //TODO: nested compounds? pushLiteralArray(&arguments, first); pushLiteralArray(&arguments, second); pushLiteralArray(&arguments, third); @@ -2267,7 +2267,7 @@ static void readInterpreterSections(Interpreter* interpreter) { if (AS_TYPE(typeLiteral).typeOf == LITERAL_ARRAY) { unsigned short vt = readShort(interpreter->bytecode, &interpreter->count); - TYPE_PUSH_SUBTYPE(&typeLiteral, interpreter->literalCache.literals[vt]); + TYPE_PUSH_SUBTYPE(&typeLiteral, copyLiteral(interpreter->literalCache.literals[vt])); } if (AS_TYPE(typeLiteral).typeOf == LITERAL_DICTIONARY) { diff --git a/source/scope.c b/source/scope.c index 2a7b8cb..2c4df07 100644 --- a/source/scope.c +++ b/source/scope.c @@ -55,6 +55,10 @@ static bool checkType(Literal typeLiteral, Literal value) { return false; } + if (AS_TYPE(typeLiteral).typeOf == LITERAL_ARRAY && !IS_ARRAY(value)) { + return false; + } + if (IS_ARRAY(value)) { //check value's type if (AS_TYPE(typeLiteral).typeOf != LITERAL_ARRAY) { @@ -69,6 +73,10 @@ static bool checkType(Literal typeLiteral, Literal value) { } } + if (AS_TYPE(typeLiteral).typeOf == LITERAL_DICTIONARY && !IS_DICTIONARY(value)) { + return false; + } + if (IS_DICTIONARY(value)) { //check value's type if (AS_TYPE(typeLiteral).typeOf != LITERAL_DICTIONARY) { @@ -90,11 +98,8 @@ static bool checkType(Literal typeLiteral, Literal value) { } } - if (IS_FUNCTION(value)) { - //check value's type - if (AS_TYPE(typeLiteral).typeOf != LITERAL_FUNCTION) { - return false; - } + if (AS_TYPE(typeLiteral).typeOf == LITERAL_FUNCTION && !IS_FUNCTION(value)) { + return false; } if (AS_TYPE(typeLiteral).typeOf == LITERAL_TYPE && !IS_TYPE(value)) { @@ -217,11 +222,13 @@ bool setScopeVariable(Scope* scope, Literal key, Literal value, bool constCheck) Literal typeLiteral = getLiteralDictionary(&scope->types, key); if (!checkType(typeLiteral, value)) { + freeLiteral(typeLiteral); return false; } //const check if (constCheck && (AS_TYPE(typeLiteral).constant)) { + freeLiteral(typeLiteral); return false; } diff --git a/source/scope.h b/source/scope.h index f069401..153d837 100644 --- a/source/scope.h +++ b/source/scope.h @@ -23,4 +23,3 @@ bool setScopeVariable(Scope* scope, Literal key, Literal value, bool constCheck) bool getScopeVariable(Scope* scope, Literal key, Literal* value); Literal getScopeType(Scope* scope, Literal key); -