DISABLE_STDIO/ENABLE_DEBUG macros to rename; close #3014

changes:
 * rename DISABLE_STDIO -> MRB_DISABLE_STDIO
 * rename ENABLE_DEBUG -> MRB_ENABLE_DEBUG_HOOK
 * no more opposite macro definitions (e.g. ENABLE_STDIO, DISABLE_DEBUG).
 * rewrite above macro references throughout the code.
 * update documents
parent 1dfe38be
......@@ -98,7 +98,7 @@ MRuby::Build.new('host-debug') do |conf|
conf.gembox 'default'
# C compiler settings
conf.cc.defines = %w(ENABLE_DEBUG)
conf.cc.defines = %w(MRB_ENABLE_DEBUG)
# Generate mruby debugger command (require mruby-eval)
conf.gem :core => "mruby-bin-debugger"
......
......@@ -463,7 +463,7 @@ can't be disabled for the main build.
MRuby::CrossBuild.new('Minimal') do |conf|
toolchain :gcc
conf.cc.defines = %w(DISABLE_STDIO)
conf.cc.defines = %w(MRB_DISABLE_STDIO)
conf.bins = []
end
```
......
......@@ -11,11 +11,7 @@ You can use mrbconfs with following ways:
changes `struct` layout and cause memory access error when C and other language(e.g., C++) is mixed.
## stdio setting.
`ENABLE_STDIO`
* Will be defined automatically if `DISABLE_STDIO` isn't defined.
* Uses `<stdio.h>` functions.
`DISABLE_STDIO`
`MRB_DISABLE_STDIO`
* When defined `<stdio.h>` functions won't be used.
* Some features will be disabled when this is enabled:
* `mrb_irep` load/dump from/to file.
......@@ -23,15 +19,12 @@ You can use mrbconfs with following ways:
* Printing features in **src/print.c**.
## Debug macros.
`ENABLE_DEBUG`
`MRB_ENABLE_DEBUG_HOOK`
* When defined code fetch hook and debug OP hook will be enabled.
* When using any of the hook set function pointer `code_fetch_hook` and/or `debug_op_hook` of `mrb_state`.
* Fetch hook will be called before any OP.
* Debug OP hook will be called when dispatching `OP_DEBUG`.
`DISABLE_DEBUG`
* Will be define automatically if `ENABLE_DEBUG` isn't defined.
`MRB_DEBUG`
* When defined `mrb_assert*` macro will be defined with macros from `<assert.h>`.
* Could be enabled via `enable_debug` method of `MRuby::Build`.
......
......@@ -50,7 +50,7 @@ MRuby::CrossBuild.new("ArduinoDue") do |conf|
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)
cc.defines << %w(MRB_GC_STRESS)
#cc.defines << %w(DISABLE_STDIO) #if you dont need stdio.
#cc.defines << %w(MRB_DISABLE_STDIO) #if you dont need stdio.
#cc.defines << %w(POOL_PAGE_SIZE=1000) #effective only for use with mruby-eval
end
......
......@@ -47,7 +47,7 @@ MRuby::CrossBuild.new("chipKITMax32") do |conf|
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)
cc.defines << %w(MRB_GC_STRESS)
#cc.defines << %w(DISABLE_STDIO) #if you dont need stdio.
#cc.defines << %w(MRB_DISABLE_STDIO) #if you dont need stdio.
#cc.defines << %w(POOL_PAGE_SIZE=1000) #effective only for use with mruby-eval
end
......
......@@ -75,23 +75,25 @@
/* fixed size state atexit stack */
//#define MRB_FIXED_STATE_ATEXIT_STACK
/* -DDISABLE_XXXX to drop following features */
//#define DISABLE_STDIO /* use of stdio */
/* -DMRB_DISABLE_XXXX to drop following features */
//#define MRB_DISABLE_STDIO /* use of stdio */
/* -DENABLE_XXXX to enable following features */
//#define ENABLE_DEBUG /* hooks for debugger */
/* -DMRB_ENABLE_XXXX to enable following features */
//#define MRB_ENABLE_DEBUG_HOOK /* hooks for debugger */
/* end of configuration */
/* define ENABLE_XXXX from DISABLE_XXX */
#ifndef DISABLE_STDIO
#define ENABLE_STDIO
/* define MRB_DISABLE_XXXX from DISABLE_XXX (for compatibility) */
#ifdef DISABLE_STDIO
#define MRB_DIABLE_STDIO
#endif
#ifndef ENABLE_DEBUG
#define DISABLE_DEBUG
/* define MRB_ENABLE_XXXX from ENABLE_XXX (for compatibility) */
#ifdef ENABLE_DEBUG
#define MRB_ENABLE_DEBUG_HOOK
#endif
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
# include <stdio.h>
#endif
......
......@@ -152,7 +152,7 @@ typedef struct mrb_state {
struct symbol_name *symtbl; /* symbol table */
size_t symcapa;
#ifdef ENABLE_DEBUG
#ifdef MRB_ENABLE_DEBUG_HOOK
void (*code_fetch_hook)(struct mrb_state* mrb, struct mrb_irep *irep, mrb_code *pc, mrb_value *regs);
void (*debug_op_hook)(struct mrb_state* mrb, struct mrb_irep *irep, mrb_code *pc, mrb_value *regs);
#endif
......
......@@ -112,7 +112,7 @@ struct mrb_parser_state {
struct mrb_pool *pool;
mrb_ast_node *cells;
const char *s, *send;
#ifdef ENABLE_STDIO
#ifndef MRB_DIABLE_STDIO
FILE *f;
#endif
mrbc_context *cxt;
......@@ -167,7 +167,7 @@ MRB_API void mrb_parser_set_filename(struct mrb_parser_state*, char const*);
MRB_API char const* mrb_parser_get_filename(struct mrb_parser_state*, uint16_t idx);
/* utility functions */
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
MRB_API struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*,mrbc_context*);
#endif
MRB_API struct mrb_parser_state* mrb_parse_string(mrb_state*,const char*,mrbc_context*);
......@@ -175,14 +175,12 @@ MRB_API struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,int,mr
MRB_API struct RProc* mrb_generate_code(mrb_state*, struct mrb_parser_state*);
/* program load functions */
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
MRB_API mrb_value mrb_load_file(mrb_state*,FILE*);
MRB_API mrb_value mrb_load_file_cxt(mrb_state*,FILE*, mrbc_context *cxt);
#endif
MRB_API mrb_value mrb_load_string(mrb_state *mrb, const char *s);
MRB_API mrb_value mrb_load_nstring(mrb_state *mrb, const char *s, int len);
#ifdef ENABLE_STDIO
MRB_API mrb_value mrb_load_file_cxt(mrb_state*,FILE*, mrbc_context *cxt);
#endif
MRB_API mrb_value mrb_load_string_cxt(mrb_state *mrb, const char *s, mrbc_context *cxt);
MRB_API mrb_value mrb_load_nstring_cxt(mrb_state *mrb, const char *s, int len, mrbc_context *cxt);
......
......@@ -23,7 +23,7 @@ MRB_BEGIN_DECL
#define DUMP_ENDIAN_MASK 6
int mrb_dump_irep(mrb_state *mrb, mrb_irep *irep, uint8_t flags, uint8_t **bin, size_t *bin_size);
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
int mrb_dump_irep_binary(mrb_state*, mrb_irep*, uint8_t, FILE*);
int mrb_dump_irep_cfunc(mrb_state *mrb, mrb_irep*, uint8_t flags, FILE *f, const char *initname);
mrb_irep *mrb_read_irep_file(mrb_state*, FILE*);
......
......@@ -7,7 +7,7 @@
#include "mruby/dump.h"
#include "mruby/variable.h"
#ifndef ENABLE_STDIO
#ifdef MRB_DISABLE_STDIO
static void
p(mrb_state *mrb, mrb_value obj)
{
......
......@@ -96,7 +96,7 @@ codegen_error(codegen_scope *s, const char *message)
mrb_pool_close(s->mpool);
s = tmp;
}
#ifdef ENABLE_STDIO
#ifndef MBB_DISABLE_STDIO
if (s->filename && s->lineno) {
fprintf(stderr, "codegen error:%s:%d: %s\n", s->filename, s->lineno, message);
}
......@@ -375,7 +375,7 @@ dispatch(codegen_scope *s, int pc)
case OP_ONERR:
break;
default:
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
fprintf(stderr, "bug: dispatch on non JMP op\n");
#endif
scope_error(s);
......@@ -978,7 +978,7 @@ gen_assignment(codegen_scope *s, node *tree, int sp, int val)
break;
default:
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
printf("unknown lhs %d\n", type);
#endif
break;
......
......@@ -3294,7 +3294,7 @@ yyerror(parser_state *p, const char *s)
int n;
if (! p->capture_errors) {
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
if (p->filename) {
fprintf(stderr, "%s:%d:%d: %s\n", p->filename, p->lineno, p->column, s);
}
......@@ -3330,7 +3330,7 @@ yywarn(parser_state *p, const char *s)
int n;
if (! p->capture_errors) {
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
if (p->filename) {
fprintf(stderr, "%s:%d:%d: %s\n", p->filename, p->lineno, p->column, s);
}
......@@ -3401,7 +3401,7 @@ nextc(parser_state *p)
cons_free(tmp);
}
else {
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
if (p->f) {
if (feof(p->f)) goto eof;
c = fgetc(p->f);
......@@ -3491,7 +3491,7 @@ peeks(parser_state *p, const char *s)
{
int len = strlen(s);
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
if (p->f) {
int n = 0;
while (*s) {
......@@ -5442,7 +5442,7 @@ mrb_parser_new(mrb_state *mrb)
p->pool = pool;
p->s = p->send = NULL;
#ifdef ENABLE_STDIO
#ifndef MRB_DISBLE_STDIO
p->f = NULL;
#endif
......@@ -5541,7 +5541,7 @@ mrb_parser_get_filename(struct mrb_parser_state* p, uint16_t idx) {
}
}
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
MRB_API parser_state*
mrb_parse_file(mrb_state *mrb, FILE *f, mrbc_context *c)
{
......@@ -5633,7 +5633,7 @@ load_exec(mrb_state *mrb, parser_state *p, mrbc_context *c)
return v;
}
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
MRB_API mrb_value
mrb_load_file_cxt(mrb_state *mrb, FILE *f, mrbc_context *c)
{
......@@ -5671,7 +5671,7 @@ mrb_load_string(mrb_state *mrb, const char *s)
return mrb_load_string_cxt(mrb, s, NULL);
}
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
static void
dump_prefix(node *tree, int offset)
......@@ -5697,7 +5697,7 @@ dump_recur(mrb_state *mrb, node *tree, int offset)
void
mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
{
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
int nodetype;
if (!tree) return;
......
......@@ -25,7 +25,7 @@ struct backtrace_location {
typedef void (*output_stream_func)(mrb_state*, struct backtrace_location*, void*);
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
struct print_backtrace_args {
FILE *stream;
......@@ -165,7 +165,7 @@ exc_output_backtrace(mrb_state *mrb, struct RObject *exc, output_stream_func fun
overwritten. So invoke these functions just after detecting exceptions.
*/
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
MRB_API void
mrb_print_backtrace(mrb_state *mrb)
......
......@@ -5,7 +5,7 @@
#include "mruby/string.h"
#include "mruby/proc.h"
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
static int
print_r(mrb_state *mrb, mrb_irep *irep, size_t n, int pre)
{
......@@ -53,7 +53,7 @@ print_lv(mrb_state *mrb, mrb_irep *irep, mrb_code c, int r)
static void
codedump(mrb_state *mrb, mrb_irep *irep)
{
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
int i;
int ai;
mrb_code c;
......
......@@ -989,7 +989,7 @@ mrb_dump_irep(mrb_state *mrb, mrb_irep *irep, uint8_t flags, uint8_t **bin, size
return dump_irep(mrb, irep, dump_flags(flags, FLAG_BYTEORDER_NONATIVE), bin, bin_size);
}
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
int
mrb_dump_irep_binary(mrb_state *mrb, mrb_irep *irep, uint8_t flags, FILE* fp)
......@@ -1092,4 +1092,4 @@ mrb_dump_irep_cfunc(mrb_state *mrb, mrb_irep *irep, uint8_t flags, FILE *fp, con
return result;
}
#endif /* ENABLE_STDIO */
#endif /* MRB_DISABLE_STDIO */
......@@ -309,7 +309,7 @@ mrb_name_error(mrb_state *mrb, mrb_sym id, const char *fmt, ...)
MRB_API void
mrb_warn(mrb_state *mrb, const char *fmt, ...)
{
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
va_list ap;
mrb_value str;
......@@ -324,7 +324,7 @@ mrb_warn(mrb_state *mrb, const char *fmt, ...)
MRB_API mrb_noreturn void
mrb_bug(mrb_state *mrb, const char *fmt, ...)
{
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
va_list ap;
mrb_value str;
......
......@@ -642,7 +642,7 @@ mrb_load_irep(mrb_state *mrb, const uint8_t *bin)
return mrb_load_irep_cxt(mrb, bin, NULL);
}
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
MRB_API mrb_irep*
mrb_read_irep_file(mrb_state *mrb, FILE* fp)
......@@ -704,4 +704,4 @@ mrb_load_irep_file(mrb_state *mrb, FILE* fp)
{
return mrb_load_irep_file_cxt(mrb, fp, NULL);
}
#endif /* ENABLE_STDIO */
#endif /* MRB_DISABLE_STDIO */
......@@ -8,7 +8,7 @@
#include "mruby/string.h"
#include "mruby/variable.h"
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
static void
printstr(mrb_value obj, FILE *stream)
{
......@@ -24,35 +24,24 @@ printstr(mrb_value obj, FILE *stream)
MRB_API void
mrb_p(mrb_state *mrb, mrb_value obj)
{
mrb_value val = mrb_inspect(mrb, obj);
printstr(val, stdout);
printstr(mrb_inspect(mrb, obj), stdout);
}
MRB_API void
mrb_print_error(mrb_state *mrb)
{
mrb_value s;
mrb_print_backtrace(mrb);
s = mrb_funcall(mrb, mrb_obj_value(mrb->exc), "inspect", 0);
printstr(s, stderr);
printstr(mrb_funcall(mrb, mrb_obj_value(mrb->exc), "inspect", 0), stderr);
}
MRB_API void
mrb_show_version(mrb_state *mrb)
{
mrb_value msg;
msg = mrb_const_get(mrb, mrb_obj_value(mrb->object_class), mrb_intern_lit(mrb, "MRUBY_DESCRIPTION"));
printstr(msg, stdout);
printstr(mrb_const_get(mrb, mrb_obj_value(mrb->object_class), mrb_intern_lit(mrb, "MRUBY_DESCRIPTION")), stdout);
}
MRB_API void
mrb_show_copyright(mrb_state *mrb)
{
mrb_value msg;
msg = mrb_const_get(mrb, mrb_obj_value(mrb->object_class), mrb_intern_lit(mrb, "MRUBY_COPYRIGHT"));
printstr(msg, stdout);
printstr(mrb_const_get(mrb, mrb_obj_value(mrb->object_class), mrb_intern_lit(mrb, "MRUBY_COPYRIGHT")), stdout);
}
......@@ -22,7 +22,7 @@
#include "value_array.h"
#include "mruby/throw.h"
#ifndef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
#if defined(__cplusplus)
extern "C" {
#endif
......@@ -693,7 +693,7 @@ argnum_error(mrb_state *mrb, mrb_int num)
#define ERR_PC_SET(mrb, pc) mrb->c->ci->err = pc;
#define ERR_PC_CLR(mrb) mrb->c->ci->err = 0;
#ifdef ENABLE_DEBUG
#ifdef MRB_ENABLE_DEBUG_HOOK
#define CODE_FETCH_HOOK(mrb, irep, pc, regs) if ((mrb)->code_fetch_hook) (mrb)->code_fetch_hook((mrb), (irep), (pc), (regs));
#else
#define CODE_FETCH_HOOK(mrb, irep, pc, regs)
......@@ -2340,10 +2340,10 @@ RETRY_TRY_BLOCK:
CASE(OP_DEBUG) {
/* A B C debug print R(A),R(B),R(C) */
#ifdef ENABLE_DEBUG
#ifdef MRB_ENABLE_DEBUG_HOOK
mrb->debug_op_hook(mrb, irep, pc, regs);
#else
#ifdef ENABLE_STDIO
#ifndef MRB_DISABLE_STDIO
printf("OP_DEBUG %d %d %d\n", GETARG_A(i), GETARG_B(i), GETARG_C(i));
#else
abort();
......
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