summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/mruby.h10
-rw-r--r--include/mruby/array.h6
-rw-r--r--include/mruby/irep.h4
-rw-r--r--include/mruby/string.h14
4 files changed, 23 insertions, 11 deletions
diff --git a/include/mruby.h b/include/mruby.h
index 6ac15715e..87ccd8c05 100644
--- a/include/mruby.h
+++ b/include/mruby.h
@@ -134,8 +134,8 @@ typedef struct {
uint16_t ridx;
uint16_t epos;
struct REnv *env;
- mrb_code *pc; /* return address */
- mrb_code *err; /* error position */
+ const mrb_code *pc; /* return address */
+ const mrb_code *err; /* error position */
int argc;
int acc;
struct RClass *target_class;
@@ -250,8 +250,8 @@ typedef struct mrb_state {
#endif
#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);
+ void (*code_fetch_hook)(struct mrb_state* mrb, struct mrb_irep *irep, const mrb_code *pc, mrb_value *regs);
+ void (*debug_op_hook)(struct mrb_state* mrb, struct mrb_irep *irep, const mrb_code *pc, mrb_value *regs);
#endif
#ifdef MRB_BYTECODE_DECODE_OPTION
@@ -1064,7 +1064,7 @@ MRB_API mrb_value mrb_top_self(mrb_state *);
MRB_API mrb_value mrb_run(mrb_state*, struct RProc*, mrb_value);
MRB_API mrb_value mrb_top_run(mrb_state*, struct RProc*, mrb_value, unsigned int);
MRB_API mrb_value mrb_vm_run(mrb_state*, struct RProc*, mrb_value, unsigned int);
-MRB_API mrb_value mrb_vm_exec(mrb_state*, struct RProc*, mrb_code*);
+MRB_API mrb_value mrb_vm_exec(mrb_state*, struct RProc*, const mrb_code*);
/* compatibility macros */
#define mrb_toplevel_run_keep(m,p,k) mrb_top_run((m),(p),mrb_top_self(m),(k))
#define mrb_toplevel_run(m,p) mrb_toplevel_run_keep((m),(p),0)
diff --git a/include/mruby/array.h b/include/mruby/array.h
index c280df3ee..dde9f80cb 100644
--- a/include/mruby/array.h
+++ b/include/mruby/array.h
@@ -33,7 +33,9 @@ struct RArray {
} aux;
mrb_value *ptr;
} heap;
+#if defined(__cplusplus)
mrb_value ary[MRB_ARY_EMBED_LEN_MAX];
+#endif
} as;
};
@@ -46,7 +48,11 @@ struct RArray {
#define ARY_UNSET_EMBED_FLAG(a) ((a)->flags &= ~(MRB_ARY_EMBED_MASK))
#define ARY_EMBED_LEN(a) ((mrb_int)(((a)->flags & MRB_ARY_EMBED_MASK) - 1))
#define ARY_SET_EMBED_LEN(a,len) ((a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | ((uint32_t)(len) + 1))
+#if defined(__cplusplus)
#define ARY_EMBED_PTR(a) (a)->as.ary
+#else
+#define ARY_EMBED_PTR(a) ((mrb_value*)(&(a)->as))
+#endif
#define ARY_LEN(a) (ARY_EMBED_P(a)?ARY_EMBED_LEN(a):(a)->as.heap.len)
#define ARY_PTR(a) (ARY_EMBED_P(a)?ARY_EMBED_PTR(a):(a)->as.heap.ptr)
diff --git a/include/mruby/irep.h b/include/mruby/irep.h
index fe518e713..4393129c7 100644
--- a/include/mruby/irep.h
+++ b/include/mruby/irep.h
@@ -32,7 +32,7 @@ typedef struct mrb_irep {
uint16_t nregs; /* Number of register variables */
uint8_t flags;
- mrb_code *iseq;
+ const mrb_code *iseq;
mrb_value *pool;
mrb_sym *syms;
struct mrb_irep **reps;
@@ -80,7 +80,7 @@ struct mrb_insn_data {
uint8_t c;
};
-struct mrb_insn_data mrb_decode_insn(mrb_code *pc);
+struct mrb_insn_data mrb_decode_insn(const mrb_code *pc);
MRB_END_DECL
diff --git a/include/mruby/string.h b/include/mruby/string.h
index 6748446f9..ab29be421 100644
--- a/include/mruby/string.h
+++ b/include/mruby/string.h
@@ -34,6 +34,9 @@ struct RString {
} as;
};
+#define RSTR_SET_TYPE_FLAG(s, type) (RSTR_UNSET_TYPE_FLAG(s), (s)->flags |= MRB_STR_##type)
+#define RSTR_UNSET_TYPE_FLAG(s) ((s)->flags &= ~(MRB_STR_TYPE_MASK|MRB_STR_EMBED_LEN_MASK))
+
#define RSTR_EMBED_P(s) ((s)->flags & MRB_STR_EMBED)
#define RSTR_SET_EMBED_FLAG(s) ((s)->flags |= MRB_STR_EMBED)
#define RSTR_UNSET_EMBED_FLAG(s) ((s)->flags &= ~(MRB_STR_EMBED|MRB_STR_EMBED_LEN_MASK))
@@ -103,11 +106,14 @@ MRB_API mrb_int mrb_str_strlen(mrb_state*, struct RString*);
#define MRB_STR_SHARED 1
#define MRB_STR_FSHARED 2
#define MRB_STR_NOFREE 4
-#define MRB_STR_POOL 8
-#define MRB_STR_ASCII 16
-#define MRB_STR_EMBED 32
-#define MRB_STR_EMBED_LEN_MASK 0x7c0
+#define MRB_STR_EMBED 8 /* type flags up to here */
+#define MRB_STR_POOL 16 /* status flags from here */
+#define MRB_STR_ASCII 32
#define MRB_STR_EMBED_LEN_SHIFT 6
+#define MRB_STR_EMBED_LEN_BITSIZE 5
+#define MRB_STR_EMBED_LEN_MASK (((1 << MRB_STR_EMBED_LEN_BITSIZE) - 1) << MRB_STR_EMBED_LEN_SHIFT)
+#define MRB_STR_TYPE_MASK (MRB_STR_POOL - 1)
+
void mrb_gc_free_str(mrb_state*, struct RString*);