Skip to content

Commit 98104c5

Browse files
committed
Unification
1 parent 4399a84 commit 98104c5

File tree

8 files changed

+35
-46
lines changed

8 files changed

+35
-46
lines changed

include/mrc_ccontext.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ typedef struct mrc_filename_table {
2828
} mrc_filename_table;
2929

3030
typedef struct mrc_ccontext {
31-
#if defined(MRC_TARGET_MRUBY)
3231
mrb_state *mrb;
33-
#endif
3432
struct mrc_jmpbuf *jmp;
3533
mrc_parser_state *p;
3634
mrc_sym *syms;

include/mrc_common.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@
66
#define MRC_STRINGIZE0(expr) #expr
77
#define MRC_STRINGIZE(expr) MRC_STRINGIZE0(expr)
88

9+
#ifdef MRC_TARGET_MRUBY
10+
# include <mruby.h>
11+
static inline int mrc_gc_arena_save(mrb_state *mrb)
12+
{
13+
if (!mrb) return 0;
14+
return mrb_gc_arena_save(mrb);
15+
}
16+
static inline void mrc_gc_arena_restore(mrb_state *mrb, int ai)
17+
{
18+
if (!mrb) return;
19+
mrb_gc_arena_restore(mrb, ai);
20+
}
21+
#else
22+
# define mrb_state void
23+
# define mrc_gc_arena_save(mrb) 0;(void)ai
24+
# define mrc_gc_arena_restore(mrb,ai)
25+
#endif
26+
927
#define MRC_RELEASE_YEAR 2024
1028
#define MRC_RELEASE_MONTH 9
1129
#define MRC_RELEASE_DAY 9
@@ -23,9 +41,6 @@
2341
#define mrc_free free
2442
#endif
2543

26-
//typedef void mrb_state;
27-
#define mrb_state void
28-
2944
#ifdef MRB_USE_CXX_ABI
3045
#define MRC_USE_CXX_ABI
3146
#endif

mrbgem.rake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ MRuby::Gem::Specification.new('mruby-compiler2') do |spec|
1111

1212
cc.defines.flatten!
1313

14+
if cc.defines.include? "PICORB_VM_MRUBY"
15+
cc.defines << "MRC_TARGET_MRUBY"
16+
cc.include_paths << "#{build.gems['picoruby-mruby']}/lib/mruby/include"
17+
end
18+
1419
if cc.defines.any? { _1.match? /\A(PICORUBY|MRB)_NO_FLOAT(=|\z)/ }
1520
cc.defines << "MRC_NO_FLOAT"
1621
end

src/ccontext.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ mrc_ccontext_new(mrb_state *mrb)
99
mrc_ccontext *c = (mrc_ccontext*)mrc_calloc(1, sizeof(mrc_ccontext));
1010
c->p = (mrc_parser_state *)mrc_malloc(sizeof(mrc_parser_state));
1111
c->options = NULL;
12-
#if defined(MRC_TARGET_MRUBY)
1312
c->mrb = mrb;
14-
#else
15-
(void)mrb;
16-
#endif
1713
return c;
1814
}
1915

src/cdump.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,7 @@ cdump_sym(mrc_ccontext *c, mrc_sym sym, const char *var_name, int idx, mrc_strin
346346
static int
347347
cdump_syms(mrc_ccontext *c, const char *name, const char *key, int n, int syms_len, const mrc_sym *syms, mrc_string *init_syms_code, FILE *fp)
348348
{
349-
#if defined(MRC_TARGET_MRUBY)
350-
int ai = mrb_gc_arena_save(c->mrb);
351-
#endif
349+
int ai = mrc_gc_arena_save(c->mrb);
352350
mrc_int code_len = MRC_STRING_LEN(init_syms_code);
353351
mrc_string *var_name = sym_var_name_str(c, name, key, n);
354352

@@ -360,9 +358,7 @@ cdump_syms(mrc_ccontext *c, const char *name, const char *key, int n, int syms_l
360358
fputs("), ", fp);
361359
if (code_len == MRC_STRING_LEN(init_syms_code)) fputs("const", fp);
362360
fputs(");\n", fp);
363-
#if defined(MRC_TARGET_MRUBY)
364-
mrb_gc_arena_restore(c->mrb, ai);
365-
#endif
361+
mrc_gc_arena_restore(c->mrb, ai);
366362
return MRC_DUMP_OK;
367363
}
368364

@@ -384,9 +380,7 @@ static int
384380
cdump_debug(mrc_ccontext *c, const char *name, int n, mrc_irep_debug_info *info,
385381
mrc_string *init_syms_code, FILE *fp)
386382
{
387-
#if defined(MRC_TARGET_MRUBY)
388-
int ai = mrb_gc_arena_save(c->mrb);
389-
#endif
383+
int ai = mrc_gc_arena_save(c->mrb);
390384
char buffer[256];
391385
const char *line_type = "mrb_debug_line_ary";
392386

@@ -448,9 +442,7 @@ cdump_debug(mrc_ccontext *c, const char *name, int n, mrc_irep_debug_info *info,
448442
fprintf(fp, "static mrb_irep_debug_info %s_debug_%d = {\n", name, n);
449443
fprintf(fp, "%d, %d, &%s_debug_file_%d_};\n", info->pc_count, info->flen, name, n);
450444

451-
#if defined(MRC_TARGET_MRUBY)
452-
mrb_gc_arena_restore(c->mrb, ai);
453-
#endif
445+
mrc_gc_arena_restore(c->mrb, ai);
454446
return MRC_DUMP_OK;
455447
}
456448

src/codedump.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ codedump(mrc_ccontext *c, const mrc_irep *irep, FILE *out)
180180
uint16_t b;
181181
uint16_t cc;
182182

183-
#if defined(MRC_TARGET_MRUBY)
184-
ai = mrc_gc_arena_save(c->mrb);
185-
#endif
183+
int ai = mrc_gc_arena_save(c->mrb);
186184

187185
i = pc - irep->iseq;
188186
next_file = mrc_debug_get_filename(c, irep, (uint32_t)i);
@@ -644,9 +642,7 @@ codedump(mrc_ccontext *c, const mrc_irep *irep, FILE *out)
644642
fprintf(out, "unknown_op (0x%x)\n", ins);
645643
break;
646644
}
647-
#if defined(MRC_TARGET_MRUBY)
648645
mrc_gc_arena_restore(c->mrb, ai);
649-
#endif
650646
}
651647
fprintf(out, "\n");
652648
}

src/codegen.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,7 @@ typedef struct scope {
234234

235235
uint16_t nlocals;
236236
uint16_t nregs;
237-
#if defined(MRC_TARGET_MRUBY)
238237
int ai;
239-
#endif
240238

241239
int debug_start_pos;
242240
uint16_t filename_index;
@@ -577,9 +575,8 @@ scope_new(mrc_ccontext *c, mrc_codegen_scope *prev, mrc_constant_id_list *nlv)
577575
mrc_assert(nlv->size < UINT16_MAX);
578576
}
579577

580-
#if defined(MRC_TARGET_MRUBY)
581-
s->ai = gc_arena_save(c->mrb);
582-
#endif
578+
int ai = mrc_gc_arena_save(c->mrb);
579+
s->ai = ai;
583580
s->filename = prev->filename;
584581
if (s->filename) {
585582
s->lines = (uint16_t *)mrc_malloc(sizeof(uint16_t)*s->icapa);
@@ -1210,9 +1207,7 @@ scope_finish(mrc_codegen_scope *s)
12101207
irep->nlocals = s->nlocals;
12111208
irep->nregs = s->nregs;
12121209

1213-
#if defined(MRC_TARGET_MRUBY)
1214-
mrb_gc_arena_restore(s->c->mrb, s->ai);
1215-
#endif
1210+
mrc_gc_arena_restore(s->c->mrb, s->ai);
12161211
mrc_pool_close(s->mpool);
12171212
}
12181213

src/dump.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ get_pool_block_size(mrc_ccontext *c, const mrc_irep *irep)
124124
size += irep->plen * sizeof(uint8_t); /* len(n) */
125125

126126
for (pool_no = 0; pool_no < irep->plen; pool_no++) {
127-
#if defined(MRC_TARGET_MRUBY)
128-
int ai = mrb_gc_arena_save(c->mrb);
129-
#endif
127+
int ai = mrc_gc_arena_save(c->mrb);
130128

131129
switch (irep->pool[pool_no].tt) {
132130
case IREP_TT_INT64:
@@ -172,9 +170,7 @@ get_pool_block_size(mrc_ccontext *c, const mrc_irep *irep)
172170
}
173171
break;
174172
}
175-
#if defined(MRC_TARGET_MRUBY)
176-
mrb_gc_arena_restore(c->mrb, ai);
177-
#endif
173+
mrc_gc_arena_restore(c->mrb, ai);
178174
}
179175

180176
return size;
@@ -191,9 +187,7 @@ write_pool_block(mrc_ccontext *c, const mrc_irep *irep, uint8_t *buf)
191187
cur += mrc_uint16_to_bin(irep->plen, cur); /* number of pool */
192188

193189
for (pool_no = 0; pool_no < irep->plen; pool_no++) {
194-
#if defined(MRC_TARGET_MRUBY)
195-
int ai = mrb_gc_arena_save(c->mrb);
196-
#endif
190+
int ai = mrc_gc_arena_save(c->mrb);
197191

198192
switch (irep->pool[pool_no].tt) {
199193
case IREP_TT_INT64:
@@ -247,9 +241,7 @@ write_pool_block(mrc_ccontext *c, const mrc_irep *irep, uint8_t *buf)
247241
*cur++ = '\0';
248242
break;
249243
}
250-
#if defined(MRC_TARGET_MRUBY)
251-
mrb_gc_arena_restore(c->mrb, ai);
252-
#endif
244+
mrc_gc_arena_restore(c->mrb, ai);
253245
}
254246

255247
return cur - buf;

0 commit comments

Comments
 (0)