Commit 737eaea0 authored by Yukihiro Matsumoto's avatar Yukihiro Matsumoto

allow DISABLE/ENABLE_SATDIO

parent bbec03bb
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
//#define DISABLE_MATH /* Math functions */ //#define DISABLE_MATH /* Math functions */
//#define DISABLE_TIME /* Time class */ //#define DISABLE_TIME /* Time class */
//#define DISABLE_STRUCT /* Struct class */ //#define DISABLE_STRUCT /* Struct class */
//#define DISABLE_STDIO /* use of stdio */
#undef HAVE_UNISTD_H /* WINDOWS */ #undef HAVE_UNISTD_H /* WINDOWS */
#define HAVE_UNISTD_H /* LINUX */ #define HAVE_UNISTD_H /* LINUX */
...@@ -50,6 +51,9 @@ typedef intptr_t mrb_sym; ...@@ -50,6 +51,9 @@ typedef intptr_t mrb_sym;
#ifndef DISABLE_STRUCT #ifndef DISABLE_STRUCT
#define ENABLE_STRUCT #define ENABLE_STRUCT
#endif #endif
#ifndef DISABLE_STDIO
#define ENABLE_STDIO
#endif
#ifndef FALSE #ifndef FALSE
# define FALSE 0 # define FALSE 0
......
...@@ -94,7 +94,9 @@ codegen_error(codegen_scope *s, const char *message) ...@@ -94,7 +94,9 @@ codegen_error(codegen_scope *s, const char *message)
s = s->prev; s = s->prev;
} }
mrb_pool_close(s->mpool); mrb_pool_close(s->mpool);
#ifdef ENABLE_STDIO
fprintf(stderr, "codegen error: %s\n", message); fprintf(stderr, "codegen error: %s\n", message);
#endif
longjmp(s->jmp, 1); longjmp(s->jmp, 1);
} }
...@@ -270,7 +272,9 @@ dispatch(codegen_scope *s, int pc) ...@@ -270,7 +272,9 @@ dispatch(codegen_scope *s, int pc)
case OP_ONERR: case OP_ONERR:
break; break;
default: default:
#ifdef ENABLE_STDIO
fprintf(stderr, "bug: dispatch on non JMP op\n"); fprintf(stderr, "bug: dispatch on non JMP op\n");
#endif
scope_error(s); scope_error(s);
} }
s->iseq[pc] = MKOP_AsBx(c, GETARG_A(i), diff); s->iseq[pc] = MKOP_AsBx(c, GETARG_A(i), diff);
...@@ -739,7 +743,9 @@ gen_assignment(codegen_scope *s, node *node, int sp, int val) ...@@ -739,7 +743,9 @@ gen_assignment(codegen_scope *s, node *node, int sp, int val)
break; break;
default: default:
#ifdef ENABLE_STDIO
printf("unknown lhs %d\n", type); printf("unknown lhs %d\n", type);
#endif
break; break;
} }
if (val) push(); if (val) push();
...@@ -2047,6 +2053,7 @@ loop_pop(codegen_scope *s, int val) ...@@ -2047,6 +2053,7 @@ loop_pop(codegen_scope *s, int val)
static void static void
codedump(mrb_state *mrb, int n) codedump(mrb_state *mrb, int n)
{ {
#ifdef ENABLE_STDIO
mrb_irep *irep = mrb->irep[n]; mrb_irep *irep = mrb->irep[n];
int i; int i;
mrb_code c; mrb_code c;
...@@ -2342,6 +2349,7 @@ codedump(mrb_state *mrb, int n) ...@@ -2342,6 +2349,7 @@ codedump(mrb_state *mrb, int n)
} }
} }
printf("\n"); printf("\n");
#endif
} }
void void
......
...@@ -403,11 +403,6 @@ mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t) ...@@ -403,11 +403,6 @@ mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t)
struct RString *s; struct RString *s;
int xt; int xt;
/*if (x == Qundef) {
//mrb_bug("undef leaked to the Ruby space");
printf ("undef leaked to the Ruby space\n");
}*/
xt = mrb_type(x); xt = mrb_type(x);
if ((xt != t) || (xt == MRB_TT_DATA)) { if ((xt != t) || (xt == MRB_TT_DATA)) {
while (type->type < MRB_TT_MAXDEFINE) { while (type->type < MRB_TT_MAXDEFINE) {
...@@ -435,8 +430,7 @@ mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t) ...@@ -435,8 +430,7 @@ mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t)
} }
type++; type++;
} }
/*mrb_bug("unknown type 0x%x", t);*/ mrb_raise(mrb, E_TYPE_ERROR, "unknown type 0x%x (0x%x given)", t, mrb_type(x));
printf ("unknown type 0x%x (0x%x given)", t, mrb_type(x));
} }
} }
......
...@@ -2964,12 +2964,14 @@ yyerror(parser_state *p, const char *s) ...@@ -2964,12 +2964,14 @@ yyerror(parser_state *p, const char *s)
int n; int n;
if (! p->capture_errors) { if (! p->capture_errors) {
#ifdef ENABLE_STDIO
if (p->filename) { if (p->filename) {
fprintf(stderr, "%s:%d:%d: %s\n", p->filename, p->lineno, p->column, s); fprintf(stderr, "%s:%d:%d: %s\n", p->filename, p->lineno, p->column, s);
} }
else { else {
fprintf(stderr, "line %d:%d: %s\n", p->lineno, p->column, s); fprintf(stderr, "line %d:%d: %s\n", p->lineno, p->column, s);
} }
#endif
} }
else if (p->nerr < sizeof(p->error_buffer) / sizeof(p->error_buffer[0])) { else if (p->nerr < sizeof(p->error_buffer) / sizeof(p->error_buffer[0])) {
n = strlen(s); n = strlen(s);
...@@ -2998,12 +3000,14 @@ yywarn(parser_state *p, const char *s) ...@@ -2998,12 +3000,14 @@ yywarn(parser_state *p, const char *s)
int n; int n;
if (! p->capture_errors) { if (! p->capture_errors) {
#ifdef ENABLE_STDIO
if (p->filename) { if (p->filename) {
fprintf(stderr, "%s:%d:%d: %s\n", p->filename, p->lineno, p->column, s); fprintf(stderr, "%s:%d:%d: %s\n", p->filename, p->lineno, p->column, s);
} }
else { else {
fprintf(stderr, "line %d:%d: %s\n", p->lineno, p->column, s); fprintf(stderr, "line %d:%d: %s\n", p->lineno, p->column, s);
} }
#endif
} }
else if (p->nerr < sizeof(p->warn_buffer) / sizeof(p->warn_buffer[0])) { else if (p->nerr < sizeof(p->warn_buffer) / sizeof(p->warn_buffer[0])) {
n = strlen(s); n = strlen(s);
...@@ -4943,6 +4947,7 @@ dump_recur(mrb_state *mrb, node *tree, int offset) ...@@ -4943,6 +4947,7 @@ dump_recur(mrb_state *mrb, node *tree, int offset)
void void
parser_dump(mrb_state *mrb, node *tree, int offset) parser_dump(mrb_state *mrb, node *tree, int offset)
{ {
#ifdef ENABLE_STDIO
int n; int n;
if (!tree) return; if (!tree) return;
...@@ -5631,7 +5636,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5631,7 +5636,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
printf("node type: %d (0x%x)\n", (int)n, (int)n); printf("node type: %d (0x%x)\n", (int)n, (int)n);
break; break;
} }
return; #endif
} }
#ifdef PARSER_TEST #ifdef PARSER_TEST
......
...@@ -1577,7 +1577,11 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) ...@@ -1577,7 +1577,11 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
CASE(OP_DEBUG) { CASE(OP_DEBUG) {
/* A debug print R(A),R(B),R(C) */ /* A debug print R(A),R(B),R(C) */
#ifdef ENABLE_STDIO
printf("OP_DEBUG %d %d %d\n", GETARG_A(i), GETARG_B(i), GETARG_C(i)); printf("OP_DEBUG %d %d %d\n", GETARG_A(i), GETARG_B(i), GETARG_C(i));
#else
abort();
#endif
NEXT; NEXT;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment