Lephe's fixes

This commit is contained in:
KikooDX 2021-11-19 12:01:24 +01:00
parent 0c0d60706c
commit a29e1f0cc4
1 changed files with 21 additions and 8 deletions

View File

@ -33,7 +33,11 @@
#define number(x) ( (x)->cdr.n )
#define prim(x) ( (x)->cdr.c )
#define cfunc(x) ( (x)->cdr.f )
#ifdef GINT
#define strbuf(x) ( (char *)&(x) )
#else
#define strbuf(x) ( &(x)->car.c + 1 )
#endif
#define STRBUFSIZE ( (int) sizeof(fe_Object*) - 1 )
#define GCMARKBIT ( 0x2 )
@ -57,7 +61,16 @@ static const char *typenames[] = {
"func", "macro", "prim", "cfunc", "ptr"
};
typedef union { fe_Object *o; fe_CFunc f; fe_Number n; char c; } Value;
typedef union {
fe_Object *o;
fe_CFunc f;
fe_Number n;
#ifdef GINT
struct { char _[3]; char c };
#else
char c;
#endif
} Value;
struct fe_Object { Value car, cdr; };
@ -89,13 +102,13 @@ void fe_error(fe_Context *ctx, const char *msg) {
/* do error handler */
if (ctx->handlers.error) { ctx->handlers.error(ctx, msg, cl); }
/* error handler returned -- print error and traceback, exit */
#ifdef RAYLIB
#ifndef GINT
fprintf(stderr, "error: %s\n", msg);
#endif
for (; !isnil(cl); cl = cdr(cl)) {
char buf[64];
fe_tostring(ctx, car(cl), buf, sizeof(buf));
#ifdef RAYLIB
#ifndef GINT
fprintf(stderr, "=> %s\n", buf);
#endif
}
@ -735,7 +748,7 @@ static fe_Object* eval(fe_Context *ctx, fe_Object *obj, fe_Object *env, fe_Objec
case P_PRINT:
while (!isnil(arg)) {
#ifdef RAYLIB
#ifndef GINT
fe_writefp(ctx, evalarg(), stdout);
if (!isnil(arg)) { printf(" "); }
#else
@ -743,7 +756,7 @@ static fe_Object* eval(fe_Context *ctx, fe_Object *obj, fe_Object *env, fe_Objec
unused(isnil(arg));
#endif
}
#ifdef RAYLIB
#ifndef GINT
printf("\n");
#endif
break;
@ -855,7 +868,7 @@ static char buf[64000];
static void onerror(fe_Context *ctx, const char *msg, fe_Object *cl) {
unused(ctx), unused(cl);
#ifdef RAYLIB
#ifndef GINT
fprintf(stderr, "error: %s\n", msg);
#endif
longjmp(toplevel, -1);
@ -881,12 +894,12 @@ int main(int argc, char **argv) {
/* re(p)l */
for (;;) {
fe_restoregc(ctx, gc);
#ifdef RAYLIB
#ifndef GINT
if (fp == stdin) { printf("> "); }
#endif
if (!(obj = fe_readfp(ctx, fp))) { break; }
obj = fe_eval(ctx, obj);
#ifdef RAYLIB
#ifndef GINT
if (fp == stdin) { fe_writefp(ctx, obj, stdout); printf("\n"); }
#endif
}