diff options
Diffstat (limited to 'src/builtin.h')
-rw-r--r-- | src/builtin.h | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/src/builtin.h b/src/builtin.h index 144ed4c..43d7ee2 100644 --- a/src/builtin.h +++ b/src/builtin.h @@ -3,10 +3,12 @@ #define PROCEDURES(X) \ /* X(symbol, name, argc) */ \ X(plus, "+", 2) \ + X(equal, "=", 2) \ X(minus, "-", 2) \ X(cons, "cons", 2) \ - X(car, "car", 1) \ - X(cdr, "cdr", 1) \ + X(car, "car", 1) \ + X(cdr, "cdr", 1) \ + X(display,"display", 1) \ // Number of builtin procedures #define PLUS_ONE(_symbol, _name, _argc) 1 + @@ -69,6 +71,27 @@ DECLARE_PROCEDURE(P) } #undef P +#define P equal +DECLARE_PROCEDURE(P) +{ + int f = 0; + int t = 1; + + if(args[0]->type != args[1]->type) goto l_false; + + switch(args[0]->type) { + case VALUE_INT: + if(args[0]->value.num == args[1]->value.num) goto l_true; + default: break; + } + +l_false: + return value_create(VALUE_INT, &f); +l_true: + return value_create(VALUE_INT, &t); +} +#undef P + #define P cons DECLARE_PROCEDURE(P) { @@ -96,3 +119,19 @@ DECLARE_PROCEDURE(P) return right; } #undef P + +#define P display +DECLARE_PROCEDURE(P) +{ + char buf[256]; + value_string(args[0], (sizeof(buf)/sizeof(*buf)), buf); + + #ifdef DEBUG + info("%s", buf); + #else + printf("%s\n", buf); + #endif + + return value_copy(args[0]); +} +#undef P |