Skip to content

Commit

Permalink
Let var const (#47)
Browse files Browse the repository at this point in the history
let var keywords type checks
  • Loading branch information
smaludzi authored Feb 7, 2021
1 parent 232a34b commit 114bcf8
Show file tree
Hide file tree
Showing 127 changed files with 1,232 additions and 414 deletions.
14 changes: 0 additions & 14 deletions front/emit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3311,20 +3311,6 @@ int expr_emit(expr * value, int stack_level, module * module_value,
assert(0);
}
break;
#if 0
case EXPR_BIND:
if (value->bind.bind_value != NULL &&
value->bind.bind_value->expr_value != NULL)
{
bind * bind_value = value->bind.bind_value;
value->bind.bind_value->index = stack_level + 1;

printf("bind %s %d\n", bind_value->id, bind_value->index);

expr_emit(value->bind.bind_value->expr_value, stack_level, module_value, list_weak, result);
}
break;
#endif
}
return 0;
}
Expand Down
108 changes: 105 additions & 3 deletions front/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ expr * expr_new_bool(int int_value)
ret->type = EXPR_BOOL;
ret->int_value = int_value;
ret->comb.comb = COMB_TYPE_BOOL;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;

return ret;
Expand All @@ -51,6 +53,8 @@ expr * expr_new_int(int int_value)
ret->type = EXPR_INT;
ret->int_value = int_value;
ret->comb.comb = COMB_TYPE_INT;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;

return ret;
Expand All @@ -63,6 +67,8 @@ expr * expr_new_long(long long long_value)
ret->type = EXPR_LONG;
ret->long_value = long_value;
ret->comb.comb = COMB_TYPE_LONG;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;

return ret;
Expand All @@ -75,6 +81,8 @@ expr * expr_new_char(char char_value)
ret->type = EXPR_CHAR;
ret->char_value = char_value;
ret->comb.comb = COMB_TYPE_CHAR;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;

return ret;
Expand All @@ -87,6 +95,8 @@ expr * expr_new_float(float float_value)
ret->type = EXPR_FLOAT;
ret->float_value = float_value;
ret->comb.comb = COMB_TYPE_FLOAT;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;

return ret;
Expand All @@ -99,6 +109,8 @@ expr * expr_new_double(double double_value)
ret->type = EXPR_DOUBLE;
ret->double_value = double_value;
ret->comb.comb = COMB_TYPE_DOUBLE;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;

return ret;
Expand All @@ -111,6 +123,8 @@ expr * expr_new_string(char * string_value)
ret->type = EXPR_STRING;
ret->string_value = string_value;
ret->comb.comb = COMB_TYPE_STRING;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;

return ret;
Expand All @@ -127,6 +141,8 @@ expr * expr_new_enumtype(expr * enum_id, char * item_id)
ret->enumtype.id_enumerator_value = NULL;
ret->enumtype.id_enumtype_value = NULL;
ret->comb.comb = COMB_TYPE_ENUMTYPE;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;

return ret;
Expand All @@ -139,6 +155,8 @@ expr * expr_new_id(char * id)
ret->type = EXPR_ID;
ret->id.id = id;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;

return ret;
Expand All @@ -150,6 +168,8 @@ expr * expr_new_nil()

ret->type = EXPR_NIL;
ret->comb.comb = COMB_TYPE_NIL;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;

return ret;
Expand All @@ -161,6 +181,8 @@ expr * expr_new_c_null()

ret->type = EXPR_C_NULL;
ret->comb.comb = COMB_TYPE_C_PTR;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;

return ret;
Expand All @@ -172,6 +194,8 @@ expr * expr_new_one(int type, expr * left)

ret->type = type;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;
ret->left = left;
ret->middle = NULL;
Expand All @@ -186,6 +210,8 @@ expr * expr_new_two(int type, expr * left, expr * right)

ret->type = type;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;
ret->left = left;
ret->middle = NULL;
Expand All @@ -200,6 +226,8 @@ expr * expr_new_three(int type, expr * left, expr * middle, expr * right)

ret->type = type;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;
ret->left = left;
ret->middle = middle;
Expand All @@ -214,6 +242,8 @@ expr * expr_new_array(array * value)

ret->type = EXPR_ARRAY;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->comb.array.comb_dims = 0;
ret->comb.array.comb_ret = NULL;
ret->line_no = 0;
Expand All @@ -228,6 +258,8 @@ expr * expr_new_array_deref(expr * array_expr, expr_list * ref)

ret->type = EXPR_ARRAY_DEREF;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;
ret->array_deref.array_expr = array_expr;
ret->array_deref.ref = ref;
Expand All @@ -241,6 +273,8 @@ expr * expr_new_range_dim(expr * from, expr * to)

ret->type = EXPR_RANGE_DIM;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;
ret->range_dim.from = from;
ret->range_dim.to = to;
Expand All @@ -254,8 +288,11 @@ expr * expr_new_range(expr_list * range_dims)

ret->type = EXPR_RANGE;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;
ret->range.ret = param_new_int(NULL);
ret->range.ret->const_type = PARAM_CONST_TYPE_CONST;
ret->range.range_dims = range_dims;

return ret;
Expand All @@ -267,6 +304,8 @@ expr * expr_new_slice(expr * array_expr, expr_list * range_dims)

ret->type = EXPR_SLICE;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->line_no = 0;
ret->slice.array_expr = array_expr;
ret->slice.range_dims = range_dims;
Expand All @@ -279,8 +318,10 @@ expr * expr_new_seq(seq * value)
expr * ret = (expr *)malloc(sizeof(expr));

ret->type = EXPR_SEQ;
ret->line_no = 0;
ret->line_no = value != NULL ? value->line_no : 0;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->seq_value = value;

return ret;
Expand All @@ -293,6 +334,8 @@ expr * expr_new_func(func * value)
ret->type = EXPR_FUNC;
ret->line_no = 0;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->func_value = value;

return ret;
Expand All @@ -305,6 +348,8 @@ expr * expr_new_call(expr * func_expr, expr_list * params)
ret->type = EXPR_CALL;
ret->line_no = 0;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->call.func_expr = func_expr;
ret->call.params = params;

Expand All @@ -318,6 +363,8 @@ expr * expr_new_build_in(unsigned int id, expr_list * params, param * param_ret)
ret->type = EXPR_BUILD_IN;
ret->line_no = 0;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->func_build_in.id = id;
ret->func_build_in.param = params;
ret->func_build_in.ret = param_ret;
Expand All @@ -332,6 +379,8 @@ expr * expr_new_ass(expr * left, expr * right)
ret->type = EXPR_ASS;
ret->line_no = 0;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->left = left;
ret->right = right;

Expand All @@ -345,6 +394,8 @@ expr * expr_new_while(expr * cond, expr * do_value)
ret->type = EXPR_WHILE;
ret->line_no = 0;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->whileloop.cond = cond;
ret->whileloop.do_value = do_value;

Expand All @@ -358,6 +409,8 @@ expr * expr_new_do_while(expr * cond, expr * do_value)
ret->type = EXPR_DO_WHILE;
ret->line_no = 0;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->whileloop.cond = cond;
ret->whileloop.do_value = do_value;

Expand All @@ -371,6 +424,8 @@ expr * expr_new_for(expr * init, expr * cond, expr * incr, expr * do_value)
ret->type = EXPR_FOR;
ret->line_no = 0;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->forloop.init = init;
ret->forloop.cond = cond;
ret->forloop.incr = incr;
Expand All @@ -386,6 +441,8 @@ expr * expr_new_for_in(char * id, expr * in_value, expr * do_value)
ret->type = EXPR_FORIN;
ret->line_no = 0;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->forin_value = forin_new(id, in_value, do_value);

return ret;
Expand All @@ -398,6 +455,8 @@ expr * expr_new_iflet(iflet * iflet_value)
ret->type = EXPR_IFLET;
ret->line_no = 0;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->iflet_value = iflet_value;

return ret;
Expand All @@ -409,6 +468,9 @@ expr * expr_new_match(expr * expr_value, match_guard_list * match_guards)

ret->type = EXPR_MATCH;
ret->line_no = 0;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->match.expr_value = expr_value;
ret->match.match_guards = match_guards;

Expand All @@ -422,6 +484,8 @@ expr * expr_new_listcomp(listcomp * listcomp_value)
ret->type = EXPR_LISTCOMP;
ret->line_no = 0;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->listcomp_value = listcomp_value;

return ret;
Expand All @@ -432,10 +496,12 @@ expr * expr_new_attr(expr * record_value, expr * id)
expr * ret = (expr *)malloc(sizeof(expr));

ret->type = EXPR_ATTR;
ret->attr.record_value = record_value;
ret->attr.id = id;
ret->line_no = 0;
ret->comb.comb = COMB_TYPE_UNKNOWN;
ret->comb.comb_const = COMB_CONST_TYPE_CONST;
ret->comb.comb_lr = COMB_LR_TYPE_RIGHT;
ret->attr.record_value = record_value;
ret->attr.id = id;

return ret;
}
Expand Down Expand Up @@ -481,6 +547,42 @@ expr * expr_conv(expr * expr_value, conv_type conv)
return ret;
}

int comb_type_is_basic(comb_type comb)
{
switch(comb)
{
case COMB_TYPE_NIL:
case COMB_TYPE_BOOL:
case COMB_TYPE_INT:
case COMB_TYPE_LONG:
case COMB_TYPE_FLOAT:
case COMB_TYPE_DOUBLE:
case COMB_TYPE_CHAR:
case COMB_TYPE_VOID:
case COMB_TYPE_C_PTR:
return 1;
break;
case COMB_TYPE_ERR:
case COMB_TYPE_STRING:
case COMB_TYPE_ARRAY:
case COMB_TYPE_RANGE:
case COMB_TYPE_SLICE:
case COMB_TYPE_FUNC:
case COMB_TYPE_ENUMTYPE:
case COMB_TYPE_ENUMTYPE_ID:
case COMB_TYPE_RECORD:
case COMB_TYPE_RECORD_ID:
case COMB_TYPE_MODULE:
return 0;
break;
case COMB_TYPE_UNKNOWN:
assert(0);
break;
}

return 0;
}

void expr_delete(expr * value)
{
switch (value->type)
Expand Down
Loading

0 comments on commit 114bcf8

Please sign in to comment.