It's bloody never-ending

This commit is contained in:
2022-09-06 20:42:37 +10:00
parent 39af340fbc
commit 6511d652f2
5 changed files with 27 additions and 13 deletions

View File

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

10
scripts/small.toy Normal file
View File

@@ -0,0 +1,10 @@
var t: type = typeas [[int]];
var a: t = [
[1, 2, 3]
];
print a;
print typeof a;

View File

@@ -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) {

View File

@@ -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,12 +98,9 @@ static bool checkType(Literal typeLiteral, Literal value) {
}
}
if (IS_FUNCTION(value)) {
//check value's type
if (AS_TYPE(typeLiteral).typeOf != LITERAL_FUNCTION) {
if (AS_TYPE(typeLiteral).typeOf == LITERAL_FUNCTION && !IS_FUNCTION(value)) {
return false;
}
}
if (AS_TYPE(typeLiteral).typeOf == LITERAL_TYPE && !IS_TYPE(value)) {
return false;
@@ -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;
}

View File

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