mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge branch 'improve-source-scanning-for-presym' of https://github.com/shuujii/mruby into shuujii-improve-source-scanning-for-presym
This commit is contained in:
+25
-31
@@ -7,42 +7,36 @@
|
||||
#ifndef MRUBY_PRESYM_H
|
||||
#define MRUBY_PRESYM_H
|
||||
|
||||
#undef MRB_PRESYM_MAX
|
||||
#ifdef MRB_USE_ALL_SYMBOLS
|
||||
#define MRB_PRESYM_NAMED(lit, num, type, name) MRB_##type##__##name = (num),
|
||||
#if defined(MRB_PRESYM_SCANNING)
|
||||
# include <mruby/presym/scanning.h>
|
||||
#elif defined(MRB_NO_PRESYM)
|
||||
# include <mruby/presym/disable.h>
|
||||
#else
|
||||
#define MRB_PRESYM_NAMED(lit, num, type, name) MRB_##type##__##name = (num<<1),
|
||||
# include <mruby/presym/enable.h>
|
||||
#endif
|
||||
#define MRB_PRESYM_UNNAMED(lit, num)
|
||||
|
||||
enum mruby_presym {
|
||||
#include <../build/presym.inc>
|
||||
};
|
||||
|
||||
#undef MRB_PRESYM_NAMED
|
||||
#undef MRB_PRESYM_UNNAMED
|
||||
|
||||
/*
|
||||
* For `MRB_OPSYM`, specify the names corresponding to operators (refer to
|
||||
* `op_table` in `Rakefile` for the names that can be specified for it).
|
||||
* Other than that, describe only word characters excluding leading and
|
||||
* ending punctuations.
|
||||
* Where `mrb_intern_lit` is allowed for symbol interning, it is directly
|
||||
* replaced by the symbol ID if presym is enabled by using the following
|
||||
* macros.
|
||||
*
|
||||
* Example:
|
||||
* MRB_OPSYM(and) //=> &
|
||||
* MRB_CVSYM(foo) //=> @@foo
|
||||
* MRB_IVSYM(foo) //=> @foo
|
||||
* MRB_SYM_B(foo) //=> foo!
|
||||
* MRB_SYM_Q(foo) //=> foo?
|
||||
* MRB_SYM_E(foo) //=> foo=
|
||||
* MRB_SYM(foo) //=> foo
|
||||
* MRB_OPSYM(xor) //=> ^ (Operator)
|
||||
* MRB_CVSYM(xor) //=> @@xor (Class Variable)
|
||||
* MRB_IVSYM(xor) //=> @xor (Instance Variable)
|
||||
* MRB_SYM_B(xor) //=> xor! (Method with Bang)
|
||||
* MRB_SYM_Q(xor) //=> xor? (Method with Question mark)
|
||||
* MRB_SYM_E(xor) //=> xor= (Method with Equal)
|
||||
* MRB_SYM(xor) //=> xor (Word characters)
|
||||
*
|
||||
* For `MRB_OPSYM`, specify the names corresponding to operators (see
|
||||
* `MRuby::Presym::OPERATORS` in `lib/mruby/presym.rb for the names that can
|
||||
* be specified for it). Other than that, describe only word characters
|
||||
* excluding leading and ending punctuations.
|
||||
*
|
||||
* These macros are expanded to `mrb_intern_lit` if presym is disabled,
|
||||
* therefore the mruby state variable is required. The above macros can be
|
||||
* used when the variable name is `mrb`. If you want to use other variable
|
||||
* names, you need to use macros with `_2` suffix, such as `MRB_SYM_2`.
|
||||
*/
|
||||
#define MRB_OPSYM(name) MRB_OPSYM__##name /* Operator */
|
||||
#define MRB_CVSYM(name) MRB_CVSYM__##name /* Class Variable */
|
||||
#define MRB_IVSYM(name) MRB_IVSYM__##name /* Instance Variable */
|
||||
#define MRB_SYM_B(name) MRB_SYM_B__##name /* Method with Bang */
|
||||
#define MRB_SYM_Q(name) MRB_SYM_Q__##name /* Method with Question mark */
|
||||
#define MRB_SYM_E(name) MRB_SYM_E__##name /* Method with Equal */
|
||||
#define MRB_SYM(name) MRB_SYM__##name /* Word characters */
|
||||
|
||||
#endif /* MRUBY_PRESYM_H */
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
** @file mruby/presym/scanning.h - Disable Preallocated Symbols
|
||||
**
|
||||
** See Copyright Notice in mruby.h
|
||||
*/
|
||||
|
||||
#ifndef MRUBY_PRESYM_DISABLE_H
|
||||
#define MRUBY_PRESYM_DISABLE_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define MRB_PRESYM_MAX 0
|
||||
|
||||
#define MRB_OPSYM(name) MRB_OPSYM__##name(mrb)
|
||||
#define MRB_CVSYM(name) mrb_intern_lit(mrb, "@@" #name)
|
||||
#define MRB_IVSYM(name) mrb_intern_lit(mrb, "@" #name)
|
||||
#define MRB_SYM_B(name) mrb_intern_lit(mrb, #name "!")
|
||||
#define MRB_SYM_Q(name) mrb_intern_lit(mrb, #name "?")
|
||||
#define MRB_SYM_E(name) mrb_intern_lit(mrb, #name "=")
|
||||
#define MRB_SYM(name) mrb_intern_lit(mrb, #name)
|
||||
|
||||
#define MRB_OPSYM_2(mrb, name) MRB_OPSYM__##name(mrb)
|
||||
#define MRB_CVSYM_2(mrb, name) mrb_intern_lit(mrb, "@@" #name)
|
||||
#define MRB_IVSYM_2(mrb, name) mrb_intern_lit(mrb, "@" #name)
|
||||
#define MRB_SYM_B_2(mrb, name) mrb_intern_lit(mrb, #name "!")
|
||||
#define MRB_SYM_Q_2(mrb, name) mrb_intern_lit(mrb, #name "?")
|
||||
#define MRB_SYM_E_2(mrb, name) mrb_intern_lit(mrb, #name "=")
|
||||
#define MRB_SYM_2(mrb, name) mrb_intern_lit(mrb, #name)
|
||||
|
||||
#define MRB_OPSYM__not(mrb) mrb_intern_lit(mrb, "!")
|
||||
#define MRB_OPSYM__mod(mrb) mrb_intern_lit(mrb, "%")
|
||||
#define MRB_OPSYM__and(mrb) mrb_intern_lit(mrb, "&")
|
||||
#define MRB_OPSYM__mul(mrb) mrb_intern_lit(mrb, "*")
|
||||
#define MRB_OPSYM__add(mrb) mrb_intern_lit(mrb, "+")
|
||||
#define MRB_OPSYM__sub(mrb) mrb_intern_lit(mrb, "-")
|
||||
#define MRB_OPSYM__div(mrb) mrb_intern_lit(mrb, "/")
|
||||
#define MRB_OPSYM__lt(mrb) mrb_intern_lit(mrb, "<")
|
||||
#define MRB_OPSYM__gt(mrb) mrb_intern_lit(mrb, ">")
|
||||
#define MRB_OPSYM__xor(mrb) mrb_intern_lit(mrb, "^")
|
||||
#define MRB_OPSYM__tick(mrb) mrb_intern_lit(mrb, "`")
|
||||
#define MRB_OPSYM__or(mrb) mrb_intern_lit(mrb, "|")
|
||||
#define MRB_OPSYM__neg(mrb) mrb_intern_lit(mrb, "~")
|
||||
#define MRB_OPSYM__neq(mrb) mrb_intern_lit(mrb, "!=")
|
||||
#define MRB_OPSYM__nmatch(mrb) mrb_intern_lit(mrb, "!~")
|
||||
#define MRB_OPSYM__andand(mrb) mrb_intern_lit(mrb, "&&")
|
||||
#define MRB_OPSYM__pow(mrb) mrb_intern_lit(mrb, "**")
|
||||
#define MRB_OPSYM__plus(mrb) mrb_intern_lit(mrb, "+@")
|
||||
#define MRB_OPSYM__minus(mrb) mrb_intern_lit(mrb, "-@")
|
||||
#define MRB_OPSYM__lshift(mrb) mrb_intern_lit(mrb, "<<")
|
||||
#define MRB_OPSYM__le(mrb) mrb_intern_lit(mrb, "<=")
|
||||
#define MRB_OPSYM__eq(mrb) mrb_intern_lit(mrb, "==")
|
||||
#define MRB_OPSYM__match(mrb) mrb_intern_lit(mrb, "=~")
|
||||
#define MRB_OPSYM__ge(mrb) mrb_intern_lit(mrb, ">=")
|
||||
#define MRB_OPSYM__rshift(mrb) mrb_intern_lit(mrb, ">>")
|
||||
#define MRB_OPSYM__aref(mrb) mrb_intern_lit(mrb, "[]")
|
||||
#define MRB_OPSYM__oror(mrb) mrb_intern_lit(mrb, "||")
|
||||
#define MRB_OPSYM__cmp(mrb) mrb_intern_lit(mrb, "<=>")
|
||||
#define MRB_OPSYM__eqq(mrb) mrb_intern_lit(mrb, "===")
|
||||
#define MRB_OPSYM__aset(mrb) mrb_intern_lit(mrb, "[]=")
|
||||
|
||||
#define MRB_PRESYM_DEFINE_VAR_AND_INITER(name, size, ...) \
|
||||
static mrb_sym name[size]; \
|
||||
static void init_##name(mrb_state *mrb) { \
|
||||
mrb_sym name__[] = {__VA_ARGS__}; \
|
||||
memcpy(name, name__, sizeof(name)); \
|
||||
}
|
||||
|
||||
#endif /* MRUBY_PRESYM_DISABLE_H */
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
** @file mruby/presym/scanning.h - Enable Preallocated Symbols
|
||||
**
|
||||
** See Copyright Notice in mruby.h
|
||||
*/
|
||||
|
||||
#ifndef MRUBY_PRESYM_ENABLE_H
|
||||
#define MRUBY_PRESYM_ENABLE_H
|
||||
|
||||
#undef MRB_PRESYM_MAX
|
||||
#ifdef MRB_USE_ALL_SYMBOLS
|
||||
# define MRB_PRESYM_NAMED(lit, num, type, name) MRB_##type##__##name = (num),
|
||||
#else
|
||||
# define MRB_PRESYM_NAMED(lit, num, type, name) MRB_##type##__##name = (num<<1),
|
||||
#endif
|
||||
#define MRB_PRESYM_UNNAMED(lit, num)
|
||||
|
||||
enum mruby_presym {
|
||||
# include <mruby/presym.inc>
|
||||
};
|
||||
|
||||
#undef MRB_PRESYM_NAMED
|
||||
#undef MRB_PRESYM_UNNAMED
|
||||
|
||||
#define MRB_OPSYM(name) MRB_OPSYM__##name
|
||||
#define MRB_CVSYM(name) MRB_CVSYM__##name
|
||||
#define MRB_IVSYM(name) MRB_IVSYM__##name
|
||||
#define MRB_SYM_B(name) MRB_SYM_B__##name
|
||||
#define MRB_SYM_Q(name) MRB_SYM_Q__##name
|
||||
#define MRB_SYM_E(name) MRB_SYM_E__##name
|
||||
#define MRB_SYM(name) MRB_SYM__##name
|
||||
|
||||
#define MRB_OPSYM_2(mrb, name) MRB_OPSYM__##name
|
||||
#define MRB_CVSYM_2(mrb, name) MRB_CVSYM__##name
|
||||
#define MRB_IVSYM_2(mrb, name) MRB_IVSYM__##name
|
||||
#define MRB_SYM_B_2(mrb, name) MRB_SYM_B__##name
|
||||
#define MRB_SYM_Q_2(mrb, name) MRB_SYM_Q__##name
|
||||
#define MRB_SYM_E_2(mrb, name) MRB_SYM_E__##name
|
||||
#define MRB_SYM_2(mrb, name) MRB_SYM__##name
|
||||
|
||||
#define MRB_PRESYM_DEFINE_VAR_AND_INITER(name, size, ...) \
|
||||
static const mrb_sym name[] = {__VA_ARGS__}; \
|
||||
static void init_##name(mrb_state *mrb) {}
|
||||
|
||||
#endif /* MRUBY_PRESYM_ENABLE_H */
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
** @file mruby/presym/scanning.h - Scanning Preallocated Symbols
|
||||
**
|
||||
** See Copyright Notice in mruby.h
|
||||
*/
|
||||
|
||||
#ifndef MRUBY_PRESYM_SCANNING_H
|
||||
#define MRUBY_PRESYM_SCANNING_H
|
||||
|
||||
#define MRB_PRESYM_SCANNING_TAGGED(arg) <@! arg !@>
|
||||
|
||||
#undef mrb_intern_lit
|
||||
#define mrb_intern_lit(mrb, name) MRB_PRESYM_SCANNING_TAGGED(name)
|
||||
#define mrb_define_method(mrb, c, name, f, a) MRB_PRESYM_SCANNING_TAGGED(name)
|
||||
#define mrb_define_class_method(mrb, c, name, f, a) MRB_PRESYM_SCANNING_TAGGED(name)
|
||||
#define mrb_define_class(mrb, name, s) MRB_PRESYM_SCANNING_TAGGED(name)
|
||||
#define mrb_define_module(mrb, name) MRB_PRESYM_SCANNING_TAGGED(name)
|
||||
#define mrb_define_module_function(mrb, c, name, f, s) MRB_PRESYM_SCANNING_TAGGED(name)
|
||||
#define mrb_define_const(mrb, c, name, v) MRB_PRESYM_SCANNING_TAGGED(name)
|
||||
#define mrb_define_global_const(mrb, name, v) MRB_PRESYM_SCANNING_TAGGED(name)
|
||||
|
||||
#define MRB_OPSYM(name) MRB_OPSYM__##name(mrb)
|
||||
#define MRB_CVSYM(name) MRB_PRESYM_SCANNING_TAGGED("@@" #name)
|
||||
#define MRB_IVSYM(name) MRB_PRESYM_SCANNING_TAGGED("@" #name)
|
||||
#define MRB_SYM_B(name) MRB_PRESYM_SCANNING_TAGGED(#name "!")
|
||||
#define MRB_SYM_Q(name) MRB_PRESYM_SCANNING_TAGGED(#name "?")
|
||||
#define MRB_SYM_E(name) MRB_PRESYM_SCANNING_TAGGED(#name "=")
|
||||
#define MRB_SYM(name) MRB_PRESYM_SCANNING_TAGGED(#name)
|
||||
|
||||
#define MRB_OPSYM_2(mrb, name) MRB_OPSYM__##name(mrb)
|
||||
#define MRB_CVSYM_2(mrb, name) MRB_PRESYM_SCANNING_TAGGED("@@" #name)
|
||||
#define MRB_IVSYM_2(mrb, name) MRB_PRESYM_SCANNING_TAGGED("@" #name)
|
||||
#define MRB_SYM_B_2(mrb, name) MRB_PRESYM_SCANNING_TAGGED(#name "!")
|
||||
#define MRB_SYM_Q_2(mrb, name) MRB_PRESYM_SCANNING_TAGGED(#name "?")
|
||||
#define MRB_SYM_E_2(mrb, name) MRB_PRESYM_SCANNING_TAGGED(#name "=")
|
||||
#define MRB_SYM_2(mrb, name) MRB_PRESYM_SCANNING_TAGGED(#name)
|
||||
|
||||
#define MRB_OPSYM__not(mrb) MRB_PRESYM_SCANNING_TAGGED("!")
|
||||
#define MRB_OPSYM__mod(mrb) MRB_PRESYM_SCANNING_TAGGED("%")
|
||||
#define MRB_OPSYM__and(mrb) MRB_PRESYM_SCANNING_TAGGED("&")
|
||||
#define MRB_OPSYM__mul(mrb) MRB_PRESYM_SCANNING_TAGGED("*")
|
||||
#define MRB_OPSYM__add(mrb) MRB_PRESYM_SCANNING_TAGGED("+")
|
||||
#define MRB_OPSYM__sub(mrb) MRB_PRESYM_SCANNING_TAGGED("-")
|
||||
#define MRB_OPSYM__div(mrb) MRB_PRESYM_SCANNING_TAGGED("/")
|
||||
#define MRB_OPSYM__lt(mrb) MRB_PRESYM_SCANNING_TAGGED("<")
|
||||
#define MRB_OPSYM__gt(mrb) MRB_PRESYM_SCANNING_TAGGED(">")
|
||||
#define MRB_OPSYM__xor(mrb) MRB_PRESYM_SCANNING_TAGGED("^")
|
||||
#define MRB_OPSYM__tick(mrb) MRB_PRESYM_SCANNING_TAGGED("`")
|
||||
#define MRB_OPSYM__or(mrb) MRB_PRESYM_SCANNING_TAGGED("|")
|
||||
#define MRB_OPSYM__neg(mrb) MRB_PRESYM_SCANNING_TAGGED("~")
|
||||
#define MRB_OPSYM__neq(mrb) MRB_PRESYM_SCANNING_TAGGED("!=")
|
||||
#define MRB_OPSYM__nmatch(mrb) MRB_PRESYM_SCANNING_TAGGED("!~")
|
||||
#define MRB_OPSYM__andand(mrb) MRB_PRESYM_SCANNING_TAGGED("&&")
|
||||
#define MRB_OPSYM__pow(mrb) MRB_PRESYM_SCANNING_TAGGED("**")
|
||||
#define MRB_OPSYM__plus(mrb) MRB_PRESYM_SCANNING_TAGGED("+@")
|
||||
#define MRB_OPSYM__minus(mrb) MRB_PRESYM_SCANNING_TAGGED("-@")
|
||||
#define MRB_OPSYM__lshift(mrb) MRB_PRESYM_SCANNING_TAGGED("<<")
|
||||
#define MRB_OPSYM__le(mrb) MRB_PRESYM_SCANNING_TAGGED("<=")
|
||||
#define MRB_OPSYM__eq(mrb) MRB_PRESYM_SCANNING_TAGGED("==")
|
||||
#define MRB_OPSYM__match(mrb) MRB_PRESYM_SCANNING_TAGGED("=~")
|
||||
#define MRB_OPSYM__ge(mrb) MRB_PRESYM_SCANNING_TAGGED(">=")
|
||||
#define MRB_OPSYM__rshift(mrb) MRB_PRESYM_SCANNING_TAGGED(">>")
|
||||
#define MRB_OPSYM__aref(mrb) MRB_PRESYM_SCANNING_TAGGED("[]")
|
||||
#define MRB_OPSYM__oror(mrb) MRB_PRESYM_SCANNING_TAGGED("||")
|
||||
#define MRB_OPSYM__cmp(mrb) MRB_PRESYM_SCANNING_TAGGED("<=>")
|
||||
#define MRB_OPSYM__eqq(mrb) MRB_PRESYM_SCANNING_TAGGED("===")
|
||||
#define MRB_OPSYM__aset(mrb) MRB_PRESYM_SCANNING_TAGGED("[]=")
|
||||
|
||||
#endif /* MRUBY_PRESYM_SCANNING_H */
|
||||
Reference in New Issue
Block a user