mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Remove reserved symbols for now.
It should be done by planned embedded symbols.
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
** mruby/symbol.h - symbol utilities
|
||||
**
|
||||
** See Copyright Notice in mruby.h
|
||||
*/
|
||||
|
||||
#ifndef MRUBY_SYMBOL_H
|
||||
#define MRUBY_SYMBOL_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Symbol utilities
|
||||
*/
|
||||
MRB_BEGIN_DECL
|
||||
|
||||
typedef enum mrb_reserved_symbol {
|
||||
mrb_sym_null = 0, // NULL symbol
|
||||
|
||||
mrb_sym_add = 1, // +
|
||||
mrb_sym_sub = 2, // -
|
||||
mrb_sym_mul = 3, // *
|
||||
mrb_sym_div = 4, // /
|
||||
mrb_sym_eq = 5, // ==
|
||||
mrb_sym_lt = 6, // <
|
||||
mrb_sym_le = 7, // <=
|
||||
mrb_sym_gt = 8, // >
|
||||
mrb_sym_ge = 9, // >=
|
||||
|
||||
mrb_sym_method_missing = 10, // method_missing
|
||||
} mrb_reserved_symbol;
|
||||
|
||||
static inline mrb_bool
|
||||
mrb_symbol_constsym_send_p(mrb_sym sym) {
|
||||
return mrb_sym_add <= sym && sym <= mrb_sym_ge;
|
||||
}
|
||||
|
||||
MRB_END_DECL
|
||||
|
||||
#endif /* MRUBY_SYMBOL_H */
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <mruby/opcode.h>
|
||||
#include <mruby/re.h>
|
||||
#include <mruby/throw.h>
|
||||
#include <mruby/symbol.h>
|
||||
|
||||
#ifndef MRB_CODEGEN_LEVEL_MAX
|
||||
#define MRB_CODEGEN_LEVEL_MAX 1024
|
||||
@@ -974,7 +973,7 @@ static void
|
||||
gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)
|
||||
{
|
||||
mrb_sym sym = name ? name : nsym(tree->cdr->car);
|
||||
int idx, skip = 0;
|
||||
int skip = 0;
|
||||
int n = 0, noop = 0, sendv = 0, blk = 0;
|
||||
|
||||
codegen(s, tree->car, VAL); /* receiver */
|
||||
@@ -983,9 +982,6 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)
|
||||
gen_move(s, cursp(), recv, 1);
|
||||
skip = genjmp2(s, OP_JMPNIL, cursp(), 0, val);
|
||||
}
|
||||
if (!mrb_symbol_constsym_send_p(sym)) {
|
||||
idx = new_sym(s, sym);
|
||||
}
|
||||
tree = tree->cdr->cdr->car;
|
||||
if (tree) {
|
||||
n = gen_values(s, tree->car, VAL, sp?1:0);
|
||||
@@ -1047,6 +1043,8 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)
|
||||
genop_1(s, OP_EQ, cursp());
|
||||
}
|
||||
else {
|
||||
int idx = new_sym(s, sym);
|
||||
|
||||
if (sendv) {
|
||||
genop_2(s, blk ? OP_SENDVB : OP_SENDV, cursp(), idx);
|
||||
}
|
||||
@@ -2026,9 +2024,6 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
push(); pop();
|
||||
pop(); pop();
|
||||
|
||||
if (!mrb_symbol_constsym_send_p(sym)) {
|
||||
idx = new_sym(s, sym);
|
||||
}
|
||||
if (len == 1 && name[0] == '+') {
|
||||
gen_addsub(s, OP_ADD, cursp());
|
||||
}
|
||||
@@ -2054,6 +2049,7 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
genop_1(s, OP_GE, cursp());
|
||||
}
|
||||
else {
|
||||
idx = new_sym(s, sym);
|
||||
genop_3(s, OP_SEND, cursp(), idx, 1);
|
||||
}
|
||||
if (callargs < 0) {
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <mruby/string.h>
|
||||
#include <mruby/dump.h>
|
||||
#include <mruby/class.h>
|
||||
#include <mruby/symbol.h>
|
||||
|
||||
/* ------------------------------------------------------ */
|
||||
typedef struct symbol_name {
|
||||
@@ -171,35 +170,10 @@ mrb_free_symtbl(mrb_state *mrb)
|
||||
kh_destroy(n2s, mrb, mrb->name2sym);
|
||||
}
|
||||
|
||||
struct reserved_symbol_t {
|
||||
mrb_reserved_symbol sym;
|
||||
char const *str;
|
||||
};
|
||||
|
||||
static struct reserved_symbol_t reserved_symbols[] = {
|
||||
{ mrb_sym_add, "+" },
|
||||
{ mrb_sym_sub, "-" },
|
||||
{ mrb_sym_mul, "*" },
|
||||
{ mrb_sym_div, "/" },
|
||||
{ mrb_sym_eq, "==" },
|
||||
{ mrb_sym_lt, "<" },
|
||||
{ mrb_sym_le, "<=" },
|
||||
{ mrb_sym_gt, ">" },
|
||||
{ mrb_sym_ge, ">=" },
|
||||
{ mrb_sym_method_missing, "method_missing" },
|
||||
{ mrb_sym_null, NULL },
|
||||
};
|
||||
|
||||
void
|
||||
mrb_init_symtbl(mrb_state *mrb)
|
||||
{
|
||||
int i;
|
||||
mrb->name2sym = kh_init(n2s, mrb);
|
||||
|
||||
for (i = 0; reserved_symbols[i].sym != mrb_sym_null; ++i) {
|
||||
mrb_sym s = mrb_intern_static(mrb, reserved_symbols[i].str, strlen(reserved_symbols[i].str));
|
||||
mrb_assert(s == reserved_symbols[i].sym);
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include <mruby/opcode.h>
|
||||
#include "value_array.h"
|
||||
#include <mruby/throw.h>
|
||||
#include <mruby/symbol.h>
|
||||
|
||||
#ifdef MRB_DISABLE_STDIO
|
||||
#if defined(__cplusplus)
|
||||
@@ -1388,18 +1387,18 @@ RETRY_TRY_BLOCK:
|
||||
SET_NIL_VALUE(regs[bidx]);
|
||||
goto L_SENDB;
|
||||
};
|
||||
L_SEND_CONSTSYM:
|
||||
L_SEND_SYM:
|
||||
{
|
||||
/* push nil after arguments */
|
||||
int bidx = (c == CALL_MAXARGS) ? a+2 : a+c+1;
|
||||
SET_NIL_VALUE(regs[bidx]);
|
||||
goto L_SENDB_CONSTSYM;
|
||||
goto L_SENDB_SYM;
|
||||
};
|
||||
|
||||
CASE(OP_SENDB, BBB)
|
||||
L_SENDB:
|
||||
mid = syms[b];
|
||||
L_SENDB_CONSTSYM:
|
||||
L_SENDB_SYM:
|
||||
{
|
||||
int argc = (c == CALL_MAXARGS) ? -1 : c;
|
||||
int bidx = (argc < 0) ? a+2 : a+c+1;
|
||||
@@ -2269,8 +2268,8 @@ RETRY_TRY_BLOCK:
|
||||
break;
|
||||
default:
|
||||
c = 1;
|
||||
mid = mrb_sym_add;
|
||||
goto L_SEND_CONSTSYM;
|
||||
mid = mrb_intern_lit(mrb, "+");
|
||||
goto L_SEND_SYM;
|
||||
}
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
NEXT;
|
||||
@@ -2327,8 +2326,8 @@ RETRY_TRY_BLOCK:
|
||||
#endif
|
||||
default:
|
||||
c = 1;
|
||||
mid = mrb_sym_sub;
|
||||
goto L_SEND_CONSTSYM;
|
||||
mid = mrb_intern_lit(mrb, "-");
|
||||
goto L_SEND_SYM;
|
||||
}
|
||||
NEXT;
|
||||
}
|
||||
@@ -2384,8 +2383,8 @@ RETRY_TRY_BLOCK:
|
||||
#endif
|
||||
default:
|
||||
c = 1;
|
||||
mid = mrb_sym_mul;
|
||||
goto L_SEND_CONSTSYM;
|
||||
mid = mrb_intern_lit(mrb, "*");
|
||||
goto L_SEND_SYM;
|
||||
}
|
||||
NEXT;
|
||||
}
|
||||
@@ -2424,8 +2423,8 @@ RETRY_TRY_BLOCK:
|
||||
#endif
|
||||
default:
|
||||
c = 1;
|
||||
mid = mrb_sym_div;
|
||||
goto L_SEND_CONSTSYM;
|
||||
mid = mrb_intern_lit(mrb, "/");
|
||||
goto L_SEND_SYM;
|
||||
}
|
||||
|
||||
#ifndef MRB_WITHOUT_FLOAT
|
||||
@@ -2475,8 +2474,8 @@ RETRY_TRY_BLOCK:
|
||||
default:
|
||||
SET_INT_VALUE(regs[a+1], b);
|
||||
c = 1;
|
||||
mid = mrb_sym_add;
|
||||
goto L_SEND_CONSTSYM;
|
||||
mid = mrb_intern_lit(mrb, "+");
|
||||
goto L_SEND_SYM;
|
||||
}
|
||||
NEXT;
|
||||
}
|
||||
@@ -2516,8 +2515,8 @@ RETRY_TRY_BLOCK:
|
||||
default:
|
||||
SET_INT_VALUE(regs_a[1], b);
|
||||
c = 1;
|
||||
mid = mrb_sym_sub;
|
||||
goto L_SEND_CONSTSYM;
|
||||
mid = mrb_intern_lit(mrb, "-");
|
||||
goto L_SEND_SYM;
|
||||
}
|
||||
NEXT;
|
||||
}
|
||||
@@ -2525,7 +2524,7 @@ RETRY_TRY_BLOCK:
|
||||
#define OP_CMP_BODY(op,v1,v2) (v1(regs[a]) op v2(regs[a+1]))
|
||||
|
||||
#ifdef MRB_WITHOUT_FLOAT
|
||||
#define OP_CMP(op, sym) do {\
|
||||
#define OP_CMP(op) do {\
|
||||
int result;\
|
||||
/* need to check if - is overridden */\
|
||||
switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {\
|
||||
@@ -2534,8 +2533,8 @@ RETRY_TRY_BLOCK:
|
||||
break;\
|
||||
default:\
|
||||
c = 1;\
|
||||
mid = mrb_sym_ ## sym;\
|
||||
goto L_SEND_CONSTSYM;\
|
||||
mid = mrb_intern_lit(mrb, # op);\
|
||||
goto L_SEND_SYM;\
|
||||
}\
|
||||
if (result) {\
|
||||
SET_TRUE_VALUE(regs[a]);\
|
||||
@@ -2545,7 +2544,7 @@ RETRY_TRY_BLOCK:
|
||||
}\
|
||||
} while(0)
|
||||
#else
|
||||
#define OP_CMP(op, sym) do {\
|
||||
#define OP_CMP(op) do {\
|
||||
int result;\
|
||||
/* need to check if - is overridden */\
|
||||
switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {\
|
||||
@@ -2563,8 +2562,8 @@ RETRY_TRY_BLOCK:
|
||||
break;\
|
||||
default:\
|
||||
c = 1;\
|
||||
mid = mrb_sym_ ## sym;\
|
||||
goto L_SEND_CONSTSYM;\
|
||||
mid = mrb_intern_lit(mrb, # op);\
|
||||
goto L_SEND_SYM;\
|
||||
}\
|
||||
if (result) {\
|
||||
SET_TRUE_VALUE(regs[a]);\
|
||||
@@ -2580,28 +2579,28 @@ RETRY_TRY_BLOCK:
|
||||
SET_TRUE_VALUE(regs[a]);
|
||||
}
|
||||
else {
|
||||
OP_CMP(==, eq);
|
||||
OP_CMP(==);
|
||||
}
|
||||
NEXT;
|
||||
}
|
||||
|
||||
CASE(OP_LT, B) {
|
||||
OP_CMP(<, lt);
|
||||
OP_CMP(<);
|
||||
NEXT;
|
||||
}
|
||||
|
||||
CASE(OP_LE, B) {
|
||||
OP_CMP(<=, le);
|
||||
OP_CMP(<=);
|
||||
NEXT;
|
||||
}
|
||||
|
||||
CASE(OP_GT, B) {
|
||||
OP_CMP(>, gt);
|
||||
OP_CMP(>);
|
||||
NEXT;
|
||||
}
|
||||
|
||||
CASE(OP_GE, B) {
|
||||
OP_CMP(>=, ge);
|
||||
OP_CMP(>=);
|
||||
NEXT;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user