Added ok value typeto represent success of a function, ie load.

'ok' now represents this type and can be compared to, also cannot be
used as a symbol/variable.
This commit is contained in:
2014-06-21 22:26:49 +01:00
parent 198367882e
commit f74035fcce
5 changed files with 26 additions and 10 deletions

11
lval.c
View File

@@ -63,6 +63,10 @@ lval* lval_str(char* str) {
val->data.str = strdup(str);
return val;
}
lval* lval_ok() {
lval* val = lval_new(LVAL_OK);
return val;
}
lval* lval_add(lval* val, lval* x) {
val->cell_count++;
@@ -149,10 +153,12 @@ BOOL lval_equal(lval* a, lval* b) {
switch(a->type) {
case LVAL_ERR: return a->data.err.num == b->data.err.num;
case LVAL_EXIT: return TRUE;
case LVAL_NUM: return fabs(a->data.num - b->data.num) <= DBL_EPSILON;
case LVAL_SYM: return strcmp(a->data.sym, b->data.sym) == 0;
case LVAL_STR: return strcmp(a->data.str, b->data.str) == 0;
case LVAL_OK:
case LVAL_EXIT:
return TRUE;
case LVAL_FUNC:
if (a->data.func->builtin != NULL) {
if (b->data.func->builtin != NULL) {
@@ -186,6 +192,7 @@ void lval_delete(lval* val) {
switch(val->type) {
case LVAL_NUM: break;
case LVAL_EXIT: break;
case LVAL_OK: break;
case LVAL_FUNC:
if (val->data.func != NULL) {
if (val->data.func->builtin == NULL) {
@@ -238,6 +245,7 @@ lval* lval_copy(lval* current) {
break;
case LVAL_NUM: new->data.num = current->data.num; break;
case LVAL_EXIT: break;
case LVAL_OK: break;
case LVAL_SYM: new->data.sym = strdup(current->data.sym); break;
case LVAL_STR: new->data.str = strdup(current->data.str); break;
@@ -300,6 +308,7 @@ char* lval_str_name(VAL_TYPE type) {
case LVAL_S_EXPR: return "S-Expression";
case LVAL_EXIT: return "Exit";
case LVAL_ERR: return "Error";
case LVAL_OK: return "Ok/Success";
default: return "UNKNOWN";
}
}