Added the opaque keyword

This commit is contained in:
2022-10-03 21:32:09 +01:00
parent 8ce7dd0d95
commit bd4ab2aa04
5 changed files with 10 additions and 3 deletions

View File

@@ -1,6 +1,5 @@
//test the opaque data type works
var o = produce();
var o: opaque = produce();
consume(o);

View File

@@ -570,6 +570,8 @@ static bool execVarDecl(Interpreter* interpreter, bool lng) {
parseCompoundToPureValues(interpreter, &val);
}
//TODO: could restrict opaque data to only opaque variables
//BUGFIX: allow easy coercion on decl
if (AS_TYPE(type).typeOf == LITERAL_FLOAT && IS_INTEGER(val)) {
val = TO_FLOAT_LITERAL(AS_INTEGER(val));

View File

@@ -12,6 +12,7 @@ KeywordType keywordTypes[] = {
{TOKEN_FLOAT, "float"},
{TOKEN_STRING, "string"},
{TOKEN_FUNCTION, "fn"},
{TOKEN_OPAQUE, "opaque"},
{TOKEN_ANY, "any"},
//other keywords

View File

@@ -816,6 +816,7 @@ ParseRule parseRules[] = { //must match the token types
{NULL, NULL, PREC_NONE},// TOKEN_ARRAY,
{NULL, NULL, PREC_NONE},// TOKEN_DICTIONARY,
{NULL, NULL, PREC_NONE},// TOKEN_FUNCTION,
{NULL, NULL, PREC_NONE},// TOKEN_OPAQUE,
{NULL, NULL, PREC_NONE},// TOKEN_ANY,
//keywords and reserved words
@@ -1486,6 +1487,10 @@ static Literal readTypeToLiteral(Parser* parser) {
AS_TYPE(literal).typeOf = LITERAL_FUNCTION;
break;
case TOKEN_OPAQUE:
AS_TYPE(literal).typeOf = LITERAL_OPAQUE;
break;
case TOKEN_ANY:
AS_TYPE(literal).typeOf = LITERAL_ANY;
break;

View File

@@ -10,6 +10,7 @@ typedef enum TokenType {
TOKEN_ARRAY,
TOKEN_DICTIONARY,
TOKEN_FUNCTION,
TOKEN_OPAQUE,
TOKEN_ANY,
//keywords and reserved words
@@ -89,4 +90,3 @@ typedef enum TokenType {
TOKEN_ERROR,
TOKEN_EOF,
} TokenType;