Browse Source

Sol Part 9: This is Why We Can't Have Nice Things

master
Grissess 7 years ago
parent
commit
7505e8452d
  1. 6
      builtins.c
  2. 6
      object.c
  3. 16
      runtime.c
  4. 2
      sol.h

6
builtins.c

@ -67,8 +67,8 @@ sol_object_t *sol_f_try(sol_state_t *state, sol_object_t *args) {
sol_obj_free(func);
sol_obj_free(fargs);
if(sol_has_error(state)) {
sol_clear_error(state);
sol_object_t *err = sol_get_error(state);
sol_clear_error(state);
sol_object_t *zero = sol_new_int(state, 0);
sol_obj_free(res);
sol_obj_free(one);
@ -653,7 +653,7 @@ sol_object_t *sol_f_list_index(sol_state_t *state, sol_object_t *args) {
} else {
ival = sol_cast_int(state, b);
res = sol_list_get_index(state, ls, ival->ival);
if(ival!=b) sol_obj_free(ival);
sol_obj_free(ival);
}
sol_obj_free(ls);
sol_obj_free(b);
@ -752,7 +752,7 @@ sol_object_t *sol_f_list_filter(sol_state_t *state, sol_object_t *args) {
sol_list_remove(state, list, idx);
len--;
}
if(ival!=item) sol_obj_free(item);
sol_obj_free(item);
sol_obj_free(ival);
}
sol_obj_free(fargs);

6
object.c

@ -7,7 +7,7 @@
sol_object_t *sol_cast_int(sol_state_t *state, sol_object_t *obj) {
sol_object_t *res, *ls;
if(sol_is_int(obj)) return obj;
if(sol_is_int(obj)) return sol_incref(obj);
ls = sol_new_list(state);
sol_list_insert(state, ls, 0, obj);
res = obj->ops->toint(state, ls);
@ -18,7 +18,7 @@ sol_object_t *sol_cast_int(sol_state_t *state, sol_object_t *obj) {
sol_object_t *sol_cast_float(sol_state_t *state, sol_object_t *obj) {
sol_object_t *res, *ls;
if(sol_is_float(obj)) return obj;
if(sol_is_float(obj)) return sol_incref(obj);
ls = sol_new_list(state);
sol_list_insert(state, ls, 0, obj);
res = obj->ops->tofloat(state, ls);
@ -29,7 +29,7 @@ sol_object_t *sol_cast_float(sol_state_t *state, sol_object_t *obj) {
sol_object_t *sol_cast_string(sol_state_t *state, sol_object_t *obj) {
sol_object_t *res, *ls;
if(sol_is_string(obj)) return obj;
if(sol_is_string(obj)) return sol_incref(obj);
ls = sol_new_list(state);
sol_list_insert(state, ls, 0, obj);
res = obj->ops->tostring(state, ls);

16
runtime.c

@ -249,16 +249,16 @@ sol_object_t *sol_eval(sol_state_t *state, expr_node *expr) {
lint = sol_cast_int(state, left);
rint = sol_cast_int(state, right);
res = sol_new_int(state, BOOL_TO_INT(lint && rint));
if(lint != left) sol_obj_free(lint);
if(rint != right) sol_obj_free(rint);
sol_obj_free(lint);
sol_obj_free(rint);
break;
case OP_LOR:
lint = sol_cast_int(state, left);
rint = sol_cast_int(state, right);
res = sol_new_int(state, BOOL_TO_INT(lint || rint));
if(lint != left) sol_obj_free(lint);
if(rint != right) sol_obj_free(rint);
sol_obj_free(lint);
sol_obj_free(rint);
break;
case OP_EQUAL:
@ -410,7 +410,7 @@ void sol_exec(sol_state_t *state, stmt_node *stmt) {
} else {
if(stmt->ifelse->iffalse) sol_exec(state, stmt->ifelse->iffalse);
}
if(vint != value) sol_obj_free(value);
sol_obj_free(value);
sol_obj_free(vint);
break;
@ -418,7 +418,7 @@ void sol_exec(sol_state_t *state, stmt_node *stmt) {
value = sol_eval(state, stmt->loop->cond);
vint = sol_cast_int(state, value);
while(vint->ival) {
if(value != vint) sol_obj_free(value);
sol_obj_free(value);
sol_obj_free(vint);
sol_exec(state, stmt->loop->loop);
if(state->ret || state->sflag == SF_BREAKING || sol_has_error(state)) break;
@ -426,8 +426,8 @@ void sol_exec(sol_state_t *state, stmt_node *stmt) {
vint = sol_cast_int(state, value);
}
state->sflag = SF_NORMAL;
if(vint != value) sol_obj_free(value);
if(vint) sol_obj_free(vint);
sol_obj_free(value);
sol_obj_free(vint);
break;
case ST_ITER:

2
sol.h

@ -299,6 +299,6 @@ int sol_validate_map(sol_state_t *, sol_object_t *);
// util.c
sol_object_t *sol_util_call(sol_state_t *, sol_object_t *, int, ...)
sol_object_t *sol_util_call(sol_state_t *, sol_object_t *, int, ...);
#endif
Loading…
Cancel
Save