Use NUM_FORMAT in all tiny interpreters

Avoids compiler warnings about printf()
This commit is contained in:
Lassi Kortela 2020-02-26 11:16:19 +02:00
parent fe8b7a7029
commit 01890ff233
4 changed files with 16 additions and 5 deletions

View File

@ -21,6 +21,7 @@
#include <sys/types.h>
#include <ctype.h>
#include <inttypes.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stdio.h>
@ -28,9 +29,11 @@
#include <string.h>
#ifdef __LP64__
#define NUM_FORMAT "%" PRId64
typedef u_int64_t value_t;
typedef int64_t number_t;
#else
#define NUM_FORMAT "%" PRId32
typedef u_int32_t value_t;
typedef int32_t number_t;
#endif
@ -504,7 +507,7 @@ void print(FILE *f, value_t v)
value_t cd;
switch (tag(v)) {
case TAG_NUM: fprintf(f, "%d", numval(v)); break;
case TAG_NUM: fprintf(f, NUM_FORMAT, numval(v)); break;
case TAG_SYM: fprintf(f, "%s", ((symbol_t*)ptr(v))->name); break;
case TAG_BUILTIN: fprintf(f, "#<builtin %s>",
builtin_names[intval(v)]); break;

View File

@ -21,6 +21,7 @@
#include <sys/types.h>
#include <ctype.h>
#include <inttypes.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stdio.h>
@ -28,9 +29,11 @@
#include <string.h>
#ifdef __LP64__
#define NUM_FORMAT "%" PRId64
typedef u_int64_t value_t;
typedef int64_t number_t;
#else
#define NUM_FORMAT "%" PRId32
typedef u_int32_t value_t;
typedef int32_t number_t;
#endif
@ -502,7 +505,7 @@ void print(FILE *f, value_t v)
value_t cd;
switch (tag(v)) {
case TAG_NUM: fprintf(f, "%ld", numval(v)); break;
case TAG_NUM: fprintf(f, NUM_FORMAT, numval(v)); break;
case TAG_SYM: fprintf(f, "%s", ((symbol_t*)ptr(v))->name); break;
case TAG_BUILTIN: fprintf(f, "#<builtin %s>",
builtin_names[intval(v)]); break;

View File

@ -42,6 +42,7 @@
#include <sys/types.h>
#include <ctype.h>
#include <inttypes.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stdio.h>
@ -49,9 +50,11 @@
#include <string.h>
#ifdef __LP64__
#define NUM_FORMAT "%" PRId64
typedef u_int64_t value_t;
typedef int64_t number_t;
#else
#define NUM_FORMAT "%" PRId32
typedef u_int32_t value_t;
typedef int32_t number_t;
#endif
@ -765,7 +768,7 @@ static void do_print(FILE *f, value_t v, int princ)
char *name;
switch (tag(v)) {
case TAG_NUM: fprintf(f, "%d", numval(v)); break;
case TAG_NUM: fprintf(f, NUM_FORMAT, numval(v)); break;
case TAG_SYM:
name = ((symbol_t*)ptr(v))->name;
if (princ)

View File

@ -27,6 +27,7 @@
#include <sys/types.h>
#include <ctype.h>
#include <inttypes.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stdio.h>
@ -40,11 +41,14 @@ typedef u_int32_t value_t;
#endif
#ifdef FLOAT
#define NUM_FORMAT "%f"
typedef float number_t;
#else
#ifdef __LP64__
#define NUM_FORMAT "%" PRId64
typedef int64_t number_t;
#else
#define NUM_FORMAT "%" PRId32
typedef int32_t number_t;
#endif
#endif
@ -73,13 +77,11 @@ typedef struct _symbol_t {
#ifdef FLOAT
#define number(x) ((*(value_t*)&(x))&~0x3)
#define numval(x) (*(number_t*)&(x))
#define NUM_FORMAT "%f"
extern float strtof(const char *nptr, char **endptr);
#define strtonum(s, e) strtof(s, e)
#else
#define number(x) ((value_t)((x)<<2))
#define numval(x) (((number_t)(x))>>2)
#define NUM_FORMAT "%d"
#define strtonum(s, e) strtol(s, e, 10)
#endif
#define intval(x) (((int)(x))>>2)