Use NUM_FORMAT in all tiny interpreters
Avoids compiler warnings about printf()
This commit is contained in:
parent
fe8b7a7029
commit
01890ff233
|
@ -21,6 +21,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -28,9 +29,11 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef __LP64__
|
#ifdef __LP64__
|
||||||
|
#define NUM_FORMAT "%" PRId64
|
||||||
typedef u_int64_t value_t;
|
typedef u_int64_t value_t;
|
||||||
typedef int64_t number_t;
|
typedef int64_t number_t;
|
||||||
#else
|
#else
|
||||||
|
#define NUM_FORMAT "%" PRId32
|
||||||
typedef u_int32_t value_t;
|
typedef u_int32_t value_t;
|
||||||
typedef int32_t number_t;
|
typedef int32_t number_t;
|
||||||
#endif
|
#endif
|
||||||
|
@ -504,7 +507,7 @@ void print(FILE *f, value_t v)
|
||||||
value_t cd;
|
value_t cd;
|
||||||
|
|
||||||
switch (tag(v)) {
|
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_SYM: fprintf(f, "%s", ((symbol_t*)ptr(v))->name); break;
|
||||||
case TAG_BUILTIN: fprintf(f, "#<builtin %s>",
|
case TAG_BUILTIN: fprintf(f, "#<builtin %s>",
|
||||||
builtin_names[intval(v)]); break;
|
builtin_names[intval(v)]); break;
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -28,9 +29,11 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef __LP64__
|
#ifdef __LP64__
|
||||||
|
#define NUM_FORMAT "%" PRId64
|
||||||
typedef u_int64_t value_t;
|
typedef u_int64_t value_t;
|
||||||
typedef int64_t number_t;
|
typedef int64_t number_t;
|
||||||
#else
|
#else
|
||||||
|
#define NUM_FORMAT "%" PRId32
|
||||||
typedef u_int32_t value_t;
|
typedef u_int32_t value_t;
|
||||||
typedef int32_t number_t;
|
typedef int32_t number_t;
|
||||||
#endif
|
#endif
|
||||||
|
@ -502,7 +505,7 @@ void print(FILE *f, value_t v)
|
||||||
value_t cd;
|
value_t cd;
|
||||||
|
|
||||||
switch (tag(v)) {
|
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_SYM: fprintf(f, "%s", ((symbol_t*)ptr(v))->name); break;
|
||||||
case TAG_BUILTIN: fprintf(f, "#<builtin %s>",
|
case TAG_BUILTIN: fprintf(f, "#<builtin %s>",
|
||||||
builtin_names[intval(v)]); break;
|
builtin_names[intval(v)]); break;
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -49,9 +50,11 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef __LP64__
|
#ifdef __LP64__
|
||||||
|
#define NUM_FORMAT "%" PRId64
|
||||||
typedef u_int64_t value_t;
|
typedef u_int64_t value_t;
|
||||||
typedef int64_t number_t;
|
typedef int64_t number_t;
|
||||||
#else
|
#else
|
||||||
|
#define NUM_FORMAT "%" PRId32
|
||||||
typedef u_int32_t value_t;
|
typedef u_int32_t value_t;
|
||||||
typedef int32_t number_t;
|
typedef int32_t number_t;
|
||||||
#endif
|
#endif
|
||||||
|
@ -765,7 +768,7 @@ static void do_print(FILE *f, value_t v, int princ)
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
switch (tag(v)) {
|
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:
|
case TAG_SYM:
|
||||||
name = ((symbol_t*)ptr(v))->name;
|
name = ((symbol_t*)ptr(v))->name;
|
||||||
if (princ)
|
if (princ)
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -40,11 +41,14 @@ typedef u_int32_t value_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FLOAT
|
#ifdef FLOAT
|
||||||
|
#define NUM_FORMAT "%f"
|
||||||
typedef float number_t;
|
typedef float number_t;
|
||||||
#else
|
#else
|
||||||
#ifdef __LP64__
|
#ifdef __LP64__
|
||||||
|
#define NUM_FORMAT "%" PRId64
|
||||||
typedef int64_t number_t;
|
typedef int64_t number_t;
|
||||||
#else
|
#else
|
||||||
|
#define NUM_FORMAT "%" PRId32
|
||||||
typedef int32_t number_t;
|
typedef int32_t number_t;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -73,13 +77,11 @@ typedef struct _symbol_t {
|
||||||
#ifdef FLOAT
|
#ifdef FLOAT
|
||||||
#define number(x) ((*(value_t*)&(x))&~0x3)
|
#define number(x) ((*(value_t*)&(x))&~0x3)
|
||||||
#define numval(x) (*(number_t*)&(x))
|
#define numval(x) (*(number_t*)&(x))
|
||||||
#define NUM_FORMAT "%f"
|
|
||||||
extern float strtof(const char *nptr, char **endptr);
|
extern float strtof(const char *nptr, char **endptr);
|
||||||
#define strtonum(s, e) strtof(s, e)
|
#define strtonum(s, e) strtof(s, e)
|
||||||
#else
|
#else
|
||||||
#define number(x) ((value_t)((x)<<2))
|
#define number(x) ((value_t)((x)<<2))
|
||||||
#define numval(x) (((number_t)(x))>>2)
|
#define numval(x) (((number_t)(x))>>2)
|
||||||
#define NUM_FORMAT "%d"
|
|
||||||
#define strtonum(s, e) strtol(s, e, 10)
|
#define strtonum(s, e) strtol(s, e, 10)
|
||||||
#endif
|
#endif
|
||||||
#define intval(x) (((int)(x))>>2)
|
#define intval(x) (((int)(x))>>2)
|
||||||
|
|
Loading…
Reference in New Issue