summaryrefslogtreecommitdiff
path: root/compiler.c
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2024-03-25 22:16:48 -0400
committerKyle Gunger <kgunger12@gmail.com>2024-03-25 22:16:48 -0400
commit89a27e4159b2b01be96b5f8ca51832766e878c51 (patch)
tree6fdef2ee921598dfc44f1cf6e72ab555f0e20876 /compiler.c
parent12679f9be4bd3a924ca0859a7ad133178513bace (diff)
len fix for variables
Diffstat (limited to 'compiler.c')
-rw-r--r--compiler.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/compiler.c b/compiler.c
index 05dbc99..cd6709d 100644
--- a/compiler.c
+++ b/compiler.c
@@ -2445,14 +2445,14 @@ bool tok_eq(Token *a, Token *b) {
#define TT_DELIMIT 5
#define TT_SPLITTR 6
-char *KEYWORDS = "module,export,asm,if,else,loop,label,goto,continue,break,return,import,as,using,struct,method,interface,enum,implements,operator,len,is";
+char *KEYWORDS = "module,export,asm,if,else,loop,label,goto,continue,break,return,import,as,using,struct,method,interface,enum,implements,operator,is";
char *KEYTYPES = "uint8,uint16,uint32,uint64,uint,int8,int16,int32,int64,int,float32,float64,float,comp64,comp,bool,vect,void,type";
char *LITERALS = "false,true";
char *RESERVED = "~`!@#$%^&*()[]{}+-=\"\'\\|:;/?>.<,";
char *OPS = "~`!%&|^*/+-=.<>@";
-char *MULTI_OPS = "==,&&,||,^^,!==,!&&,!||,!^^,!<,!>,<<,>>,!&,!|,!^,++,--,>==,<==,+=,-=,*=,/=,%=,!=,&=,|=,^=,~=,`=";
+char *MULTI_OPS = "==,&&,||,^^,!==,!&&,!||,!^^,!<,!>,<<,>>,!&,!|,!^,++,--,>==,<==,+=,-=,*=,/=,%=,!=,&=,|=,^=,~=,`=,len";
char *DELIMS = "()[]{}";
char *MULTI_DELIMS = ";:#";
@@ -2503,17 +2503,13 @@ int token_type(char*data) {
if (is_delim(data))
return TT_DELIMIT;
- else if (is_reserved(data[0])) {
- if (l == 1) {
- if (strchr(OPS, data[0]) != NULL)
- return TT_AUGMENT;
- else if (data[0] == ',' || data[0] == ';' || data[0] == ':')
- return TT_SPLITTR;
- } else if (l == 2 && in_csv(MULTI_OPS, data)) {
+ else if (is_reserved(data[0]) && l == 1) {
+ if (strchr(OPS, data[0]) != NULL)
return TT_AUGMENT;
- } else if (l == 3 && in_csv(MULTI_OPS, data)) {
+ else if (data[0] == ',' || data[0] == ';' || data[0] == ':')
+ return TT_SPLITTR;
+ } else if (in_csv(MULTI_OPS, data)) {
return TT_AUGMENT;
- }
} else if (in_csv(KEYTYPES, data)) {
return TT_KEYTYPE;
} else if (in_csv(KEYWORDS, data)) {
@@ -4651,7 +4647,7 @@ Variable _eval_dot(Scope *s, CompData *data, Vector *tokens, size_t start, size_
if (start == end - 1) {
Variable v = scope_get_var(s, &name);
if (v.name == NULL) {
- printf("ERROR: Failed to find variable or call in dot chain \"%s\" (%d:%d)\n\n", t->data, t->line, t->col);
+ printf("ERROR: Failed to find singlet variable or call in dot chain \"%s\" (%d:%d)\n\n", t->data, t->line, t->col);
p2_error = true;
}
art_end(&name);
@@ -4934,6 +4930,12 @@ Variable _eval(Scope *s, CompData *data, Vector *tokens, size_t start, size_t en
var_op_not(data, &out);
return out;
+ } else if (tok_str_eq(op_token, "len")){
+ out = var_init("#literal", typ_get_inbuilt("uint"));
+ out.location = LOC_LITL;
+ out.offset = rhs.type->size;
+ var_end(&rhs);
+ return out;
} else {
printf("ERROR: Unexpected prefix token\n");
p2_error = true;