From 7deb41b0e88b3670476ed86bab541340f5551b52 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 9 Jun 2020 22:30:14 +0900 Subject: Generate C source file to represent `mrb_irep` structures. Type `mrbc -S -B -o ` to generate the C source code that holds compiled `mrb_irep`. Appending the following code to the bottom of the generated code, `mruby` executes the compiled code: ```C int main() { mrb_state *mrb = mrb_open(); struct RProc *p = mrb_proc_new(mrb, &init_irep); mrb_vm_run(mrb, p, mrb_top_self(mrb), 0); mrb_close(mrb); return 0; } ``` Eventually static compile should use this representation, instead of `uint8_t` array that holds `mrb` data, so that we can skip interpreting `mrb` data. --- src/dump.c | 99 +++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 73 insertions(+), 26 deletions(-) (limited to 'src/dump.c') diff --git a/src/dump.c b/src/dump.c index 3aade76a3..8aa7b4edb 100644 --- a/src/dump.c +++ b/src/dump.c @@ -930,6 +930,34 @@ mrb_dump_irep_cfunc(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, FILE *f return result; } +static int +dump_pool(mrb_state *mrb, const mrb_pool_value *p, FILE *fp) +{ + if (p->tt & IREP_TT_NFLAG) { /* number */ + switch (p->tt) { + case IREP_TT_INT32: + fprintf(fp, "{IREP_TT_INT32, {.i32=%"PRId32"}},\n", p->u.i32); + break; + case IREP_TT_INT64: + fprintf(fp, "{IREP_TT_INT64, {.i64=%"PRId64"}},\n", p->u.i64); + break; + case IREP_TT_FLOAT: + fprintf(fp, "{IREP_TT_FLOAT, {.f="MRB_FLOAT_FMT"}},\n", p->u.f); + break; + } + } + else { /* string */ + int i, len = p->tt>>2; + const char *s = p->u.str; + fprintf(fp, "{IREP_TT_STR|(%d<<2), {.str=\"", len); + for (i=0; i\n" "#include \n\n") < 0) { return MRB_DUMP_WRITE_FAULT; } - return dump_irep_struct(mrb, irep, flags, fp, initname, &n); + return dump_irep_struct(mrb, irep, flags, fp, initname, 0, &max); } #endif /* MRB_DISABLE_STDIO */ -- cgit v1.2.3