Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 3b6baa1430e04c0f29cca0ee0696eb5b3b71d177 @banister committed Oct 16, 2011
Showing with 4,484 additions and 0 deletions.
  1. 0 .gemtest
  2. +7 −0 .gitignore
  3. +1 −0 .yardopts
  4. 0 HISTORY
  5. +25 −0 LICENSE
  6. +56 −0 README.md
  7. +99 −0 Rakefile
  8. +116 −0 ext/binding_of_caller/binding_of_caller.c
  9. +57 −0 ext/binding_of_caller/compat.h
  10. +26 −0 ext/binding_of_caller/example.rb
  11. +6 −0 ext/binding_of_caller/extconf.rb
  12. +36 −0 ext/binding_of_caller/ruby_headers/debug.h
  13. +41 −0 ext/binding_of_caller/ruby_headers/dln.h
  14. +232 −0 ext/binding_of_caller/ruby_headers/eval_intern.h
  15. +77 −0 ext/binding_of_caller/ruby_headers/gc.h
  16. +173 −0 ext/binding_of_caller/ruby_headers/id.h
  17. +104 −0 ext/binding_of_caller/ruby_headers/iseq.h
  18. +103 −0 ext/binding_of_caller/ruby_headers/method.h
  19. +483 −0 ext/binding_of_caller/ruby_headers/node.h
  20. +211 −0 ext/binding_of_caller/ruby_headers/regenc.h
  21. +841 −0 ext/binding_of_caller/ruby_headers/regint.h
  22. +354 −0 ext/binding_of_caller/ruby_headers/regparse.h
  23. +27 −0 ext/binding_of_caller/ruby_headers/thread_pthread.h
  24. +33 −0 ext/binding_of_caller/ruby_headers/thread_win32.h
  25. +21 −0 ext/binding_of_caller/ruby_headers/timev.h
  26. +109 −0 ext/binding_of_caller/ruby_headers/transcode_data.h
  27. +63 −0 ext/binding_of_caller/ruby_headers/version.h
  28. +703 −0 ext/binding_of_caller/ruby_headers/vm_core.h
  29. +184 −0 ext/binding_of_caller/ruby_headers/vm_exec.h
  30. +208 −0 ext/binding_of_caller/ruby_headers/vm_insnhelper.h
  31. +51 −0 ext/binding_of_caller/ruby_headers/vm_opts.h
  32. +22 −0 lib/binding_of_caller.rb
  33. +3 −0 lib/binding_of_caller/version.rb
  34. +12 −0 test/test.rb
0 .gemtest
No changes.
7 .gitignore
@@ -0,0 +1,7 @@
+Makefile
+*.so
+*.o
+*.def
+doc/
+pkg/
+.yardoc/
1 .yardopts
@@ -0,0 +1 @@
+--markup markdown
0 HISTORY
No changes.
25 LICENSE
@@ -0,0 +1,25 @@
+License
+-------
+
+(The MIT License)
+
+Copyright (c) 2011 John Mair (banisterfiend)
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56 README.md
@@ -0,0 +1,56 @@
+binding_of_caller
+===========
+
+(C) John Mair (banisterfiend) 2011
+
+FIXME: _tagline_
+
+FIXME: _description goes here_
+
+* Install the [gem](https://rubygems.org/gems/binding_of_caller): `gem install binding_of_caller`
+* Read the [documentation](http://rdoc.info/github/banister/binding_of_caller/master/file/README.markdown)
+* See the [source code](http://github.com/banister/binding_of_caller)
+
+Example: Example description
+--------
+
+Example preamble
+
+ puts "example code"
+
+Features and limitations
+-------------------------
+
+Feature List Preamble
+
+Contact
+-------
+
+Problems or questions contact me at [github](http://github.com/banister)
+
+
+License
+-------
+
+(The MIT License)
+
+Copyright (c) 2011 (John Mair)
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
99 Rakefile
@@ -0,0 +1,99 @@
+dlext = Config::CONFIG['DLEXT']
+direc = File.dirname(__FILE__)
+
+PROJECT_NAME = "binding_of_caller"
+
+require 'rake/clean'
+require 'rake/gempackagetask'
+require "#{direc}/lib/#{PROJECT_NAME}/version"
+
+CLOBBER.include("**/*.#{dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o")
+CLEAN.include("ext/**/*.#{dlext}", "ext/**/*.log", "ext/**/*.o",
+ "ext/**/*~", "ext/**/*#*", "ext/**/*.obj", "**/*#*", "**/*#*.*",
+ "ext/**/*.def", "ext/**/*.pdb", "**/*_flymake*.*", "**/*_flymake")
+
+def apply_spec_defaults(s)
+ s.name = PROJECT_NAME
+ s.summary = "FIX ME"
+ s.version = BindingOfCaller::VERSION
+ s.date = Time.now.strftime '%Y-%m-%d'
+ s.author = "John Mair (banisterfiend)"
+ s.email = 'jrmair@gmail.com'
+ s.description = s.summary
+ s.require_path = 'lib'
+ s.add_development_dependency("bacon",">=1.1.0")
+ s.homepage = "http://banisterfiend.wordpress.com"
+ s.has_rdoc = 'yard'
+ s.files = Dir["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "lib/**/*.rb",
+ "test/*.rb", "HISTORY", "README.md", "Rakefile"]
+end
+
+desc "run tests"
+task :test do
+ sh "bacon -k #{direc}/test/test.rb"
+end
+
+[:mingw32, :mswin32].each do |v|
+ namespace v do
+ spec = Gem::Specification.new do |s|
+ apply_spec_defaults(s)
+ s.platform = "i386-#{v}"
+ s.files += FileList["lib/**/*.#{dlext}"].to_a
+ end
+
+ Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.need_zip = false
+ pkg.need_tar = false
+ end
+ end
+end
+
+namespace :ruby do
+ spec = Gem::Specification.new do |s|
+ apply_spec_defaults(s)
+ s.platform = Gem::Platform::RUBY
+ s.extensions = ["ext/#{PROJECT_NAME}/extconf.rb"]
+ end
+
+ Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.need_zip = false
+ pkg.need_tar = false
+ end
+end
+
+directories = ["#{direc}/lib/1.8", "#{direc}/lib/1.9"]
+directories.each { |d| directory d }
+
+desc "build the 1.8 and 1.9 binaries from source and copy to lib/"
+task :compile => directories do
+ build_for = proc do |pik_ver, ver|
+ sh %{ \
+ c:\\devkit\\devkitvars.bat && \
+ pik #{pik_ver} && \
+ ruby extconf.rb && \
+ make clean && \
+ make && \
+ cp *.so #{direc}/lib/#{ver} \
+ }
+ end
+
+ chdir("#{direc}/ext/#{PROJECT_NAME}") do
+ build_for.call("187", "1.8")
+ build_for.call("192", "1.9")
+ end
+end
+
+desc "build all platform gems at once"
+task :gems => [:clean, :rmgems, "mingw32:gem", "mswin32:gem", "ruby:gem"]
+
+desc "remove all platform gems"
+task :rmgems => ["ruby:clobber_package"]
+
+desc "build and push latest gems"
+task :pushgems => :gems do
+ chdir("#{direc}/pkg") do
+ Dir["*.gem"].each do |gemfile|
+ sh "gem push #{gemfile}"
+ end
+ end
+end
116 ext/binding_of_caller/binding_of_caller.c
@@ -0,0 +1,116 @@
+/* (c) 2010 John Mair (banisterfiend), MIT license */
+
+#include <ruby.h>
+//#include "compat.h"
+
+//#ifdef RUBY_19
+# include <ruby/io.h>
+# include <ruby/re.h>
+# include "vm_core.h"
+# include "gc.h"
+/* #else */
+/* # include "re.h" */
+/* # include "env.h" */
+/* # include "node.h" */
+/* # include "rubysig.h" */
+/* # include "rubyio.h" */
+/* #endif */
+
+static size_t
+binding_memsize(const void *ptr)
+{
+ return ptr ? sizeof(rb_binding_t) : 0;
+}
+
+static void
+binding_free(void *ptr)
+{
+ rb_binding_t *bind;
+ RUBY_FREE_ENTER("binding");
+ if (ptr) {
+ bind = ptr;
+ ruby_xfree(ptr);
+ }
+ RUBY_FREE_LEAVE("binding");
+}
+
+static void
+binding_mark(void *ptr)
+{
+ rb_binding_t *bind;
+ RUBY_MARK_ENTER("binding");
+ if (ptr) {
+ bind = ptr;
+ RUBY_MARK_UNLESS_NULL(bind->env);
+ RUBY_MARK_UNLESS_NULL(bind->filename);
+ }
+ RUBY_MARK_LEAVE("binding");
+}
+
+static const rb_data_type_t binding_data_type = {
+ "binding",
+ binding_mark,
+ binding_free,
+ binding_memsize,
+};
+
+static VALUE
+binding_alloc(VALUE klass)
+{
+ VALUE obj;
+ rb_binding_t *bind;
+ obj = TypedData_Make_Struct(klass, rb_binding_t, &binding_data_type, bind);
+ return obj;
+}
+
+static rb_control_frame_t *
+vm_get_ruby_level_caller_cfp(rb_thread_t *th, rb_control_frame_t *cfp)
+{
+ if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
+ return cfp;
+ }
+
+ cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
+
+ while (!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) {
+ if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
+ return cfp;
+ }
+
+ if ((cfp->flag & VM_FRAME_FLAG_PASSED) == 0) {
+ break;
+ }
+ cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
+ }
+ return 0;
+}
+
+
+static VALUE hello(VALUE self)
+{
+ rb_thread_t *th = GET_THREAD();
+ rb_control_frame_t *cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp));
+ //vm_get_ruby_level_caller_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(RUBY_VM_PREVIOUS_CONTROL_FRAME(RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp))));
+ VALUE bindval = binding_alloc(rb_cBinding);
+ rb_binding_t *bind;
+
+ if (cfp == 0) {
+ rb_raise(rb_eRuntimeError, "Can't create Binding Object on top of Fiber.");
+ }
+
+ GetBindingPtr(bindval, bind);
+ bind->env = rb_vm_make_env_object(th, cfp);
+ bind->filename = cfp->iseq->filename;
+ bind->line_no = rb_vm_get_sourceline(cfp);
+ return bindval;
+}
+
+void
+Init_binding_of_caller()
+ {
+ // VALUE cBindingOfCaller = rb_define_module("BindingOfCaller");
+
+ rb_define_method(rb_cObject, "binding_of_caller", hello, 0);
+
+}
+
57 ext/binding_of_caller/compat.h
@@ -0,0 +1,57 @@
+/* contains basic macros to facilitate ruby 1.8 and ruby 1.9 compatibility */
+
+#ifndef GUARD_COMPAT_H
+#define GUARD_COMPAT_H
+
+#include <ruby.h>
+
+/* test for 1.9 */
+#if !defined(RUBY_19) && defined(ROBJECT_EMBED_LEN_MAX)
+# define RUBY_19
+#endif
+
+/* macros for backwards compatibility with 1.8 */
+#ifndef RUBY_19
+# define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
+# define RCLASS_SUPER(c) (RCLASS(c)->super)
+# define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl)
+# define OBJ_UNTRUSTED OBJ_TAINTED
+# include "st.h"
+#endif
+
+#ifdef RUBY_19
+inline static VALUE
+class_alloc(VALUE flags, VALUE klass)
+{
+ rb_classext_t *ext = ALLOC(rb_classext_t);
+ NEWOBJ(obj, struct RClass);
+ OBJSETUP(obj, klass, flags);
+ obj->ptr = ext;
+ RCLASS_IV_TBL(obj) = 0;
+ RCLASS_M_TBL(obj) = 0;
+ RCLASS_SUPER(obj) = 0;
+ RCLASS_IV_INDEX_TBL(obj) = 0;
+ return (VALUE)obj;
+}
+#endif
+
+inline static VALUE
+create_class(VALUE flags, VALUE klass)
+{
+#ifdef RUBY_19
+ VALUE new_klass = class_alloc(flags, klass);
+#else
+ NEWOBJ(new_klass, struct RClass);
+ OBJSETUP(new_klass, klass, flags);
+#endif
+
+ return (VALUE)new_klass;
+}
+
+# define FALSE 0
+# define TRUE 1
+
+/* a useful macro. cannot use ordinary CLASS_OF as it does not return an lvalue */
+#define KLASS_OF(c) (RBASIC(c)->klass)
+
+#endif
26 ext/binding_of_caller/example.rb
@@ -0,0 +1,26 @@
+require './binding_of_caller'
+
+class Z
+ def z
+ u = 10
+ A.new.a
+ end
+end
+
+class A
+ def a
+ y = 10
+ B.new.b
+ end
+end
+
+class B
+ def b
+ x = 10
+ puts binding_of_caller.eval('self')
+ puts binding_of_caller.eval('local_variables')
+ end
+end
+
+Z.new.z
+
6 ext/binding_of_caller/extconf.rb
@@ -0,0 +1,6 @@
+require 'mkmf'
+
+$CFLAGS += " -std=c99"
+$CFLAGS += " -I./ruby_headers/"
+
+create_makefile('binding_of_caller')
36 ext/binding_of_caller/ruby_headers/debug.h
@@ -0,0 +1,36 @@
+/**********************************************************************
+
+ debug.h - YARV Debug function interface
+
+ $Author$
+ created at: 04/08/25 02:33:49 JST
+
+ Copyright (C) 2004-2007 Koichi Sasada
+
+**********************************************************************/
+
+#ifndef RUBY_DEBUG_H
+#define RUBY_DEBUG_H
+
+#include "ruby/ruby.h"
+#include "node.h"
+
+#define dpv(h,v) ruby_debug_print_value(-1, 0, h, v)
+#define dp(v) ruby_debug_print_value(-1, 0, "", v)
+#define dpi(i) ruby_debug_print_id(-1, 0, "", i)
+#define dpn(n) ruby_debug_print_node(-1, 0, "", n)
+
+#define bp() ruby_debug_breakpoint()
+
+VALUE ruby_debug_print_value(int level, int debug_level, const char *header, VALUE v);
+ID ruby_debug_print_id(int level, int debug_level, const char *header, ID id);
+NODE *ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node);
+int ruby_debug_print_indent(int level, int debug_level, int indent_level);
+void ruby_debug_breakpoint(void);
+void ruby_debug_gc_check_func(void);
+
+#ifdef RUBY_DEBUG_ENV
+void ruby_set_debug_option(const char *str);
+#endif
+
+#endif /* RUBY_DEBUG_H */
41 ext/binding_of_caller/ruby_headers/dln.h
@@ -0,0 +1,41 @@
+/**********************************************************************
+
+ dln.h -
+
+ $Author$
+ created at: Wed Jan 19 16:53:09 JST 1994
+
+ Copyright (C) 1993-2007 Yukihiro Matsumoto
+
+**********************************************************************/
+
+#ifndef DLN_H
+#define DLN_H
+
+#ifdef __cplusplus
+# ifndef HAVE_PROTOTYPES
+# define HAVE_PROTOTYPES 1
+# endif
+# ifndef HAVE_STDARG_PROTOTYPES
+# define HAVE_STDARG_PROTOTYPES 1
+# endif
+#endif
+
+#undef _
+#ifdef HAVE_PROTOTYPES
+# define _(args) args
+#else
+# define _(args) ()
+#endif
+
+DEPRECATED(char *dln_find_exe(const char*,const char*));
+DEPRECATED(char *dln_find_file(const char*,const char*));
+char *dln_find_exe_r(const char*,const char*,char*,size_t);
+char *dln_find_file_r(const char*,const char*,char*,size_t);
+
+#ifdef USE_DLN_A_OUT
+extern char *dln_argv0;
+#endif
+
+void *dln_load(const char*);
+#endif
232 ext/binding_of_caller/ruby_headers/eval_intern.h
@@ -0,0 +1,232 @@
+#ifndef RUBY_EVAL_INTERN_H
+#define RUBY_EVAL_INTERN_H
+
+#include "ruby/ruby.h"
+#include "vm_core.h"
+
+#define PASS_PASSED_BLOCK_TH(th) do { \
+ (th)->passed_block = GC_GUARDED_PTR_REF((rb_block_t *)(th)->cfp->lfp[0]); \
+ (th)->cfp->flag |= VM_FRAME_FLAG_PASSED; \
+} while (0)
+
+#define PASS_PASSED_BLOCK() do { \
+ rb_thread_t * const __th__ = GET_THREAD(); \
+ PASS_PASSED_BLOCK_TH(__th__); \
+} while (0)
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
+#include <stdio.h>
+#include <setjmp.h>
+
+#ifdef __APPLE__
+#include <crt_externs.h>
+#endif
+
+/* Make alloca work the best possible way. */
+#ifdef __GNUC__
+# ifndef atarist
+# ifndef alloca
+# define alloca __builtin_alloca
+# endif
+# endif /* atarist */
+#else
+# ifdef HAVE_ALLOCA_H
+# include <alloca.h>
+# else
+# ifdef _AIX
+#pragma alloca
+# else
+# ifndef alloca /* predefined by HP cc +Olibcalls */
+void *alloca();
+# endif
+# endif /* AIX */
+# endif /* HAVE_ALLOCA_H */
+#endif /* __GNUC__ */
+
+#ifndef HAVE_STRING_H
+char *strrchr(const char *, const char);
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef HAVE_NET_SOCKET_H
+#include <net/socket.h>
+#endif
+
+#define ruby_setjmp(env) RUBY_SETJMP(env)
+#define ruby_longjmp(env,val) RUBY_LONGJMP(env,val)
+#ifdef __CYGWIN__
+# ifndef _setjmp
+int _setjmp(jmp_buf);
+# endif
+# ifndef _longjmp
+NORETURN(void _longjmp(jmp_buf, int));
+# endif
+#endif
+
+#include <sys/types.h>
+#include <signal.h>
+#include <errno.h>
+
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+
+/*
+ Solaris sys/select.h switches select to select_large_fdset to support larger
+ file descriptors if FD_SETSIZE is larger than 1024 on 32bit environment.
+ But Ruby doesn't change FD_SETSIZE because fd_set is allocated dynamically.
+ So following definition is required to use select_large_fdset.
+*/
+#ifdef HAVE_SELECT_LARGE_FDSET
+#define select(n, r, w, e, t) select_large_fdset(n, r, w, e, t)
+#endif
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+#include <sys/stat.h>
+
+#define SAVE_ROOT_JMPBUF(th, stmt) do \
+ if (ruby_setjmp((th)->root_jmpbuf) == 0) { \
+ stmt; \
+ } \
+ else { \
+ rb_fiber_start(); \
+ } while (0)
+
+#define TH_PUSH_TAG(th) do { \
+ rb_thread_t * const _th = th; \
+ struct rb_vm_tag _tag; \
+ _tag.tag = 0; \
+ _tag.prev = _th->tag; \
+ _th->tag = &_tag;
+
+#define TH_POP_TAG() \
+ _th->tag = _tag.prev; \
+} while (0)
+
+#define TH_POP_TAG2() \
+ _th->tag = _tag.prev
+
+#define PUSH_TAG() TH_PUSH_TAG(GET_THREAD())
+#define POP_TAG() TH_POP_TAG()
+
+#define TH_EXEC_TAG() ruby_setjmp(_th->tag->buf)
+
+#define EXEC_TAG() \
+ TH_EXEC_TAG()
+
+#define TH_JUMP_TAG(th, st) do { \
+ ruby_longjmp(th->tag->buf,(st)); \
+} while (0)
+
+#define JUMP_TAG(st) TH_JUMP_TAG(GET_THREAD(), st)
+
+enum ruby_tag_type {
+ RUBY_TAG_RETURN = 0x1,
+ RUBY_TAG_BREAK = 0x2,
+ RUBY_TAG_NEXT = 0x3,
+ RUBY_TAG_RETRY = 0x4,
+ RUBY_TAG_REDO = 0x5,
+ RUBY_TAG_RAISE = 0x6,
+ RUBY_TAG_THROW = 0x7,
+ RUBY_TAG_FATAL = 0x8,
+ RUBY_TAG_MASK = 0xf
+};
+#define TAG_RETURN RUBY_TAG_RETURN
+#define TAG_BREAK RUBY_TAG_BREAK
+#define TAG_NEXT RUBY_TAG_NEXT
+#define TAG_RETRY RUBY_TAG_RETRY
+#define TAG_REDO RUBY_TAG_REDO
+#define TAG_RAISE RUBY_TAG_RAISE
+#define TAG_THROW RUBY_TAG_THROW
+#define TAG_FATAL RUBY_TAG_FATAL
+#define TAG_MASK RUBY_TAG_MASK
+
+#define NEW_THROW_OBJECT(val, pt, st) \
+ ((VALUE)rb_node_newnode(NODE_LIT, (VALUE)(val), (VALUE)(pt), (VALUE)(st)))
+#define SET_THROWOBJ_CATCH_POINT(obj, val) \
+ (RNODE((obj))->u2.value = (val))
+#define SET_THROWOBJ_STATE(obj, val) \
+ (RNODE((obj))->u3.value = (val))
+
+#define GET_THROWOBJ_VAL(obj) ((VALUE)RNODE((obj))->u1.value)
+#define GET_THROWOBJ_CATCH_POINT(obj) ((VALUE*)RNODE((obj))->u2.value)
+#define GET_THROWOBJ_STATE(obj) ((int)RNODE((obj))->u3.value)
+
+#define SCOPE_TEST(f) (rb_vm_cref()->nd_visi & (f))
+#define SCOPE_CHECK(f) (rb_vm_cref()->nd_visi == (f))
+#define SCOPE_SET(f) (rb_vm_cref()->nd_visi = (f))
+
+#define CHECK_STACK_OVERFLOW(cfp, margin) do \
+ if (((VALUE *)(cfp)->sp) + (margin) + sizeof(rb_control_frame_t) >= ((VALUE *)cfp)) { \
+ rb_exc_raise(sysstack_error); \
+ } \
+while (0)
+
+void rb_thread_cleanup(void);
+void rb_thread_wait_other_threads(void);
+
+enum {
+ RAISED_EXCEPTION = 1,
+ RAISED_STACKOVERFLOW = 2,
+ RAISED_NOMEMORY = 4
+};
+int rb_threadptr_set_raised(rb_thread_t *th);
+int rb_threadptr_reset_raised(rb_thread_t *th);
+#define rb_thread_raised_set(th, f) ((th)->raised_flag |= (f))
+#define rb_thread_raised_reset(th, f) ((th)->raised_flag &= ~(f))
+#define rb_thread_raised_p(th, f) (((th)->raised_flag & (f)) != 0)
+#define rb_thread_raised_clear(th) ((th)->raised_flag = 0)
+
+VALUE rb_f_eval(int argc, VALUE *argv, VALUE self);
+VALUE rb_make_exception(int argc, VALUE *argv);
+
+NORETURN(void rb_fiber_start(void));
+
+NORETURN(void rb_print_undef(VALUE, ID, int));
+NORETURN(void rb_vm_localjump_error(const char *,VALUE, int));
+NORETURN(void rb_vm_jump_tag_but_local_jump(int, VALUE));
+NORETURN(void rb_raise_method_missing(rb_thread_t *th, int argc, VALUE *argv,
+ VALUE obj, int call_status));
+
+VALUE rb_vm_make_jump_tag_but_local_jump(int state, VALUE val);
+NODE *rb_vm_cref(void);
+VALUE rb_vm_call_cfunc(VALUE recv, VALUE (*func)(VALUE), VALUE arg, const rb_block_t *blockptr, VALUE filename, VALUE filepath);
+void rb_vm_set_progname(VALUE filename);
+void rb_thread_terminate_all(void);
+VALUE rb_vm_top_self();
+VALUE rb_vm_cbase(void);
+int rb_vm_get_sourceline(const rb_control_frame_t *);
+void rb_trap_restore_mask(void);
+
+#ifndef CharNext /* defined as CharNext[AW] on Windows. */
+#define CharNext(p) ((p) + mblen(p, RUBY_MBCHAR_MAXSIZE))
+#endif
+
+#if defined DOSISH || defined __CYGWIN__
+static inline void
+translit_char(char *p, int from, int to)
+{
+ while (*p) {
+ if ((unsigned char)*p == from)
+ *p = to;
+ p = CharNext(p);
+ }
+}
+#endif
+
+#endif /* RUBY_EVAL_INTERN_H */
77 ext/binding_of_caller/ruby_headers/gc.h
@@ -0,0 +1,77 @@
+
+#ifndef RUBY_GC_H
+#define RUBY_GC_H 1
+
+#if defined(__x86_64__) && defined(__GNUC__)
+#define SET_MACHINE_STACK_END(p) __asm__("movq\t%%rsp, %0" : "=r" (*p))
+#elif defined(__i386) && defined(__GNUC__)
+#define SET_MACHINE_STACK_END(p) __asm__("movl\t%%esp, %0" : "=r" (*p))
+#else
+NOINLINE(void rb_gc_set_stack_end(VALUE **stack_end_p));
+#define SET_MACHINE_STACK_END(p) rb_gc_set_stack_end(p)
+#define USE_CONSERVATIVE_STACK_END
+#endif
+
+/* for GC debug */
+
+#ifndef RUBY_MARK_FREE_DEBUG
+#define RUBY_MARK_FREE_DEBUG 0
+#endif
+
+#if RUBY_MARK_FREE_DEBUG
+extern int ruby_gc_debug_indent;
+
+static void
+rb_gc_debug_indent(void)
+{
+ printf("%*s", ruby_gc_debug_indent, "");
+}
+
+static void
+rb_gc_debug_body(const char *mode, const char *msg, int st, void *ptr)
+{
+ if (st == 0) {
+ ruby_gc_debug_indent--;
+ }
+ rb_gc_debug_indent();
+ printf("%s: %s %s (%p)\n", mode, st ? "->" : "<-", msg, ptr);
+
+ if (st) {
+ ruby_gc_debug_indent++;
+ }
+
+ fflush(stdout);
+}
+
+#define RUBY_MARK_ENTER(msg) rb_gc_debug_body("mark", msg, 1, ptr)
+#define RUBY_MARK_LEAVE(msg) rb_gc_debug_body("mark", msg, 0, ptr)
+#define RUBY_FREE_ENTER(msg) rb_gc_debug_body("free", msg, 1, ptr)
+#define RUBY_FREE_LEAVE(msg) rb_gc_debug_body("free", msg, 0, ptr)
+#define RUBY_GC_INFO rb_gc_debug_indent(); printf
+
+#else
+#define RUBY_MARK_ENTER(msg)
+#define RUBY_MARK_LEAVE(msg)
+#define RUBY_FREE_ENTER(msg)
+#define RUBY_FREE_LEAVE(msg)
+#define RUBY_GC_INFO if(0)printf
+#endif
+
+#define RUBY_MARK_UNLESS_NULL(ptr) if(RTEST(ptr)){rb_gc_mark(ptr);}
+#define RUBY_FREE_UNLESS_NULL(ptr) if(ptr){ruby_xfree(ptr);}
+
+#if STACK_GROW_DIRECTION > 0
+# define STACK_UPPER(x, a, b) a
+#elif STACK_GROW_DIRECTION < 0
+# define STACK_UPPER(x, a, b) b
+#else
+RUBY_EXTERN int ruby_stack_grow_direction;
+int ruby_get_stack_grow_direction(volatile VALUE *addr);
+# define stack_growup_p(x) ( \
+ (ruby_stack_grow_direction ? \
+ ruby_stack_grow_direction : \
+ ruby_get_stack_grow_direction(x)) > 0)
+# define STACK_UPPER(x, a, b) (stack_growup_p(x) ? a : b)
+#endif
+
+#endif /* RUBY_GC_H */
173 ext/binding_of_caller/ruby_headers/id.h
@@ -0,0 +1,173 @@
+/* DO NOT EDIT THIS FILE DIRECTLY */
+/**********************************************************************
+
+ id.h -
+
+ $Author$
+ created at: Sun Oct 19 21:12:51 2008
+
+ Copyright (C) 2007 Koichi Sasada
+
+**********************************************************************/
+
+#ifndef RUBY_ID_H
+#define RUBY_ID_H
+
+#define ID_SCOPE_SHIFT 3
+#define ID_SCOPE_MASK 0x07
+#define ID_LOCAL 0x00
+#define ID_INSTANCE 0x01
+#define ID_GLOBAL 0x03
+#define ID_ATTRSET 0x04
+#define ID_CONST 0x05
+#define ID_CLASS 0x06
+#define ID_JUNK 0x07
+#define ID_INTERNAL ID_JUNK
+
+#ifdef USE_PARSE_H
+#include "parse.h"
+#endif
+
+#define symIFUNC ID2SYM(idIFUNC)
+#define symCFUNC ID2SYM(idCFUNC)
+
+#if !defined tLAST_TOKEN && defined YYTOKENTYPE
+#define tLAST_TOKEN tLAST_TOKEN
+#endif
+
+enum ruby_method_ids {
+#ifndef tLAST_TOKEN
+ tUPLUS = 321,
+ tUMINUS = 322,
+ tPOW = 323,
+ tCMP = 324,
+ tEQ = 325,
+ tEQQ = 326,
+ tNEQ = 327,
+ tGEQ = 328,
+ tLEQ = 329,
+ tANDOP = 330,
+ tOROP = 331,
+ tMATCH = 332,
+ tNMATCH = 333,
+ tDOT2 = 334,
+ tDOT3 = 335,
+ tAREF = 336,
+ tASET = 337,
+ tLSHFT = 338,
+ tRSHFT = 339,
+ tLAMBDA = 352,
+ idNULL = 365,
+ idRespond_to = 366,
+ idIFUNC = 367,
+ idCFUNC = 368,
+ id_core_set_method_alias = 369,
+ id_core_set_variable_alias = 370,
+ id_core_undef_method = 371,
+ id_core_define_method = 372,
+ id_core_define_singleton_method = 373,
+ id_core_set_postexe = 374,
+ tLAST_TOKEN = 375,
+#endif
+ idDot2 = tDOT2,
+ idDot3 = tDOT3,
+ idUPlus = tUPLUS,
+ idUMinus = tUMINUS,
+ idPow = tPOW,
+ idCmp = tCMP,
+ idPLUS = '+',
+ idMINUS = '-',
+ idMULT = '*',
+ idDIV = '/',
+ idMOD = '%',
+ idLT = '<',
+ idLTLT = tLSHFT,
+ idLE = tLEQ,
+ idGT = '>',
+ idGE = tGEQ,
+ idEq = tEQ,
+ idEqq = tEQQ,
+ idNeq = tNEQ,
+ idNot = '!',
+ idBackquote = '`',
+ idEqTilde = tMATCH,
+ idNeqTilde = tNMATCH,
+ idAREF = tAREF,
+ idASET = tASET,
+ idLAST_TOKEN = tLAST_TOKEN >> ID_SCOPE_SHIFT,
+ tIntern,
+ tMethodMissing,
+ tLength,
+ tSize,
+ tGets,
+ tSucc,
+ tEach,
+ tLambda,
+ tSend,
+ t__send__,
+ tInitialize,
+ tUScore,
+#if SUPPORT_JOKE
+ tBitblt,
+ tAnswer,
+#endif
+ tLAST_ID,
+#define TOKEN2ID(n) id##n = ((t##n<<ID_SCOPE_SHIFT)|ID_LOCAL)
+#if SUPPORT_JOKE
+ TOKEN2ID(Bitblt),
+ TOKEN2ID(Answer),
+#endif
+ TOKEN2ID(Intern),
+ TOKEN2ID(MethodMissing),
+ TOKEN2ID(Length),
+ TOKEN2ID(Size),
+ TOKEN2ID(Gets),
+ TOKEN2ID(Succ),
+ TOKEN2ID(Each),
+ TOKEN2ID(Lambda),
+ TOKEN2ID(Send),
+ TOKEN2ID(__send__),
+ TOKEN2ID(Initialize),
+ TOKEN2ID(UScore),
+ TOKEN2ID(LAST_ID)
+};
+
+#ifdef tLAST_TOKEN
+struct ruby_method_ids_check {
+#define ruby_method_id_check_for(name, value) \
+ int checking_for_##name[name == value ? 1 : -1]
+ruby_method_id_check_for(tUPLUS, 321);
+ruby_method_id_check_for(tUMINUS, 322);
+ruby_method_id_check_for(tPOW, 323);
+ruby_method_id_check_for(tCMP, 324);
+ruby_method_id_check_for(tEQ, 325);
+ruby_method_id_check_for(tEQQ, 326);
+ruby_method_id_check_for(tNEQ, 327);
+ruby_method_id_check_for(tGEQ, 328);
+ruby_method_id_check_for(tLEQ, 329);
+ruby_method_id_check_for(tANDOP, 330);
+ruby_method_id_check_for(tOROP, 331);
+ruby_method_id_check_for(tMATCH, 332);
+ruby_method_id_check_for(tNMATCH, 333);
+ruby_method_id_check_for(tDOT2, 334);
+ruby_method_id_check_for(tDOT3, 335);
+ruby_method_id_check_for(tAREF, 336);
+ruby_method_id_check_for(tASET, 337);
+ruby_method_id_check_for(tLSHFT, 338);
+ruby_method_id_check_for(tRSHFT, 339);
+ruby_method_id_check_for(tLAMBDA, 352);
+ruby_method_id_check_for(idNULL, 365);
+ruby_method_id_check_for(idRespond_to, 366);
+ruby_method_id_check_for(idIFUNC, 367);
+ruby_method_id_check_for(idCFUNC, 368);
+ruby_method_id_check_for(id_core_set_method_alias, 369);
+ruby_method_id_check_for(id_core_set_variable_alias, 370);
+ruby_method_id_check_for(id_core_undef_method, 371);
+ruby_method_id_check_for(id_core_define_method, 372);
+ruby_method_id_check_for(id_core_define_singleton_method, 373);
+ruby_method_id_check_for(id_core_set_postexe, 374);
+ruby_method_id_check_for(tLAST_TOKEN, 375);
+};
+#endif
+
+#endif /* RUBY_ID_H */
104 ext/binding_of_caller/ruby_headers/iseq.h
@@ -0,0 +1,104 @@
+/**********************************************************************
+
+ iseq.h -
+
+ $Author$
+ created at: 04/01/01 23:36:57 JST
+
+ Copyright (C) 2004-2008 Koichi Sasada
+
+**********************************************************************/
+
+#ifndef RUBY_COMPILE_H
+#define RUBY_COMPILE_H
+
+/* compile.c */
+VALUE rb_iseq_compile_node(VALUE self, NODE *node);
+int rb_iseq_translate_threaded_code(rb_iseq_t *iseq);
+VALUE rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE locals, VALUE args,
+ VALUE exception, VALUE body);
+
+/* iseq.c */
+VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt);
+struct st_table *ruby_insn_make_insn_table(void);
+
+#define ISEQ_TYPE_TOP INT2FIX(1)
+#define ISEQ_TYPE_METHOD INT2FIX(2)
+#define ISEQ_TYPE_BLOCK INT2FIX(3)
+#define ISEQ_TYPE_CLASS INT2FIX(4)
+#define ISEQ_TYPE_RESCUE INT2FIX(5)
+#define ISEQ_TYPE_ENSURE INT2FIX(6)
+#define ISEQ_TYPE_EVAL INT2FIX(7)
+#define ISEQ_TYPE_MAIN INT2FIX(8)
+#define ISEQ_TYPE_DEFINED_GUARD INT2FIX(9)
+
+#define CATCH_TYPE_RESCUE ((int)INT2FIX(1))
+#define CATCH_TYPE_ENSURE ((int)INT2FIX(2))
+#define CATCH_TYPE_RETRY ((int)INT2FIX(3))
+#define CATCH_TYPE_BREAK ((int)INT2FIX(4))
+#define CATCH_TYPE_REDO ((int)INT2FIX(5))
+#define CATCH_TYPE_NEXT ((int)INT2FIX(6))
+
+struct iseq_insn_info_entry {
+ unsigned short position;
+ unsigned short line_no;
+ unsigned short sp;
+};
+
+struct iseq_catch_table_entry {
+ VALUE type;
+ VALUE iseq;
+ unsigned long start;
+ unsigned long end;
+ unsigned long cont;
+ unsigned long sp;
+};
+
+#define INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE (512)
+
+struct iseq_compile_data_storage {
+ struct iseq_compile_data_storage *next;
+ unsigned long pos;
+ unsigned long size;
+ char *buff;
+};
+
+struct iseq_compile_data {
+ /* GC is needed */
+ VALUE err_info;
+ VALUE mark_ary;
+ VALUE catch_table_ary; /* Array */
+
+ /* GC is not needed */
+ struct iseq_label_data *start_label;
+ struct iseq_label_data *end_label;
+ struct iseq_label_data *redo_label;
+ VALUE current_block;
+ VALUE ensure_node;
+ VALUE for_iseq;
+ struct iseq_compile_data_ensure_node_stack *ensure_node_stack;
+ int loopval_popped; /* used by NODE_BREAK */
+ int cached_const;
+ struct iseq_compile_data_storage *storage_head;
+ struct iseq_compile_data_storage *storage_current;
+ int last_line;
+ int last_coverable_line;
+ int flip_cnt;
+ int label_no;
+ int node_level;
+ const rb_compile_option_t *option;
+};
+
+/* defined? */
+#define DEFINED_IVAR INT2FIX(1)
+#define DEFINED_IVAR2 INT2FIX(2)
+#define DEFINED_GVAR INT2FIX(3)
+#define DEFINED_CVAR INT2FIX(4)
+#define DEFINED_CONST INT2FIX(5)
+#define DEFINED_METHOD INT2FIX(6)
+#define DEFINED_YIELD INT2FIX(7)
+#define DEFINED_REF INT2FIX(8)
+#define DEFINED_ZSUPER INT2FIX(9)
+#define DEFINED_FUNC INT2FIX(10)
+
+#endif /* RUBY_COMPILE_H */
103 ext/binding_of_caller/ruby_headers/method.h
@@ -0,0 +1,103 @@
+/**********************************************************************
+
+ method.h -
+
+ $Author$
+ created at: Wed Jul 15 20:02:33 2009
+
+ Copyright (C) 2009 Koichi Sasada
+
+**********************************************************************/
+#ifndef METHOD_H
+#define METHOD_H
+
+typedef enum {
+ NOEX_PUBLIC = 0x00,
+ NOEX_NOSUPER = 0x01,
+ NOEX_PRIVATE = 0x02,
+ NOEX_PROTECTED = 0x04,
+ NOEX_MASK = 0x06,
+ NOEX_BASIC = 0x08,
+ NOEX_UNDEF = NOEX_NOSUPER,
+ NOEX_MODFUNC = 0x12,
+ NOEX_SUPER = 0x20,
+ NOEX_VCALL = 0x40,
+ NOEX_RESPONDS = 0x80
+} rb_method_flag_t;
+
+#define NOEX_SAFE(n) ((int)((n) >> 8) & 0x0F)
+#define NOEX_WITH(n, s) ((s << 8) | (n) | (ruby_running ? 0 : NOEX_BASIC))
+#define NOEX_WITH_SAFE(n) NOEX_WITH(n, rb_safe_level())
+
+/* method data type */
+
+typedef enum {
+ VM_METHOD_TYPE_ISEQ,
+ VM_METHOD_TYPE_CFUNC,
+ VM_METHOD_TYPE_ATTRSET,
+ VM_METHOD_TYPE_IVAR,
+ VM_METHOD_TYPE_BMETHOD,
+ VM_METHOD_TYPE_ZSUPER,
+ VM_METHOD_TYPE_UNDEF,
+ VM_METHOD_TYPE_NOTIMPLEMENTED,
+ VM_METHOD_TYPE_OPTIMIZED, /* Kernel#send, Proc#call, etc */
+ VM_METHOD_TYPE_MISSING /* wrapper for method_missing(id) */
+} rb_method_type_t;
+
+typedef struct rb_method_cfunc_struct {
+ VALUE (*func)(ANYARGS);
+ int argc;
+} rb_method_cfunc_t;
+
+typedef struct rb_method_attr_struct {
+ ID id;
+ VALUE location;
+} rb_method_attr_t;
+
+typedef struct rb_iseq_struct rb_iseq_t;
+
+typedef struct rb_method_definition_struct {
+ rb_method_type_t type; /* method type */
+ ID original_id;
+ union {
+ rb_iseq_t *iseq; /* should be mark */
+ rb_method_cfunc_t cfunc;
+ rb_method_attr_t attr;
+ VALUE proc; /* should be mark */
+ enum method_optimized_type {
+ OPTIMIZED_METHOD_TYPE_SEND,
+ OPTIMIZED_METHOD_TYPE_CALL
+ } optimize_type;
+ } body;
+ int alias_count;
+} rb_method_definition_t;
+
+typedef struct rb_method_entry_struct {
+ rb_method_flag_t flag;
+ char mark;
+ rb_method_definition_t *def;
+ ID called_id;
+ VALUE klass; /* should be mark */
+} rb_method_entry_t;
+
+struct unlinked_method_entry_list_entry {
+ struct unlinked_method_entry_list_entry *next;
+ rb_method_entry_t *me;
+};
+
+#define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF)
+
+void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_flag_t noex);
+rb_method_entry_t *rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_flag_t noex);
+rb_method_entry_t *rb_method_entry(VALUE klass, ID id);
+
+rb_method_entry_t *rb_method_entry_get_without_cache(VALUE klass, ID id);
+rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_flag_t noex);
+
+int rb_method_entry_arity(const rb_method_entry_t *me);
+
+void rb_mark_method_entry(const rb_method_entry_t *me);
+void rb_free_method_entry(rb_method_entry_t *me);
+void rb_sweep_method_entry(void *vm);
+
+#endif /* METHOD_H */
483 ext/binding_of_caller/ruby_headers/node.h
@@ -0,0 +1,483 @@
+/**********************************************************************
+
+ node.h -
+
+ $Author$
+ created at: Fri May 28 15:14:02 JST 1993
+
+ Copyright (C) 1993-2007 Yukihiro Matsumoto
+
+**********************************************************************/
+
+#ifndef RUBY_NODE_H
+#define RUBY_NODE_H 1
+
+#if defined(__cplusplus)
+extern "C" {
+#if 0
+} /* satisfy cc-mode */
+#endif
+#endif
+
+enum node_type {
+ NODE_SCOPE,
+#define NODE_SCOPE NODE_SCOPE
+ NODE_BLOCK,
+#define NODE_BLOCK NODE_BLOCK
+ NODE_IF,
+#define NODE_IF NODE_IF
+ NODE_CASE,
+#define NODE_CASE NODE_CASE
+ NODE_WHEN,
+#define NODE_WHEN NODE_WHEN
+ NODE_OPT_N,
+#define NODE_OPT_N NODE_OPT_N
+ NODE_WHILE,
+#define NODE_WHILE NODE_WHILE
+ NODE_UNTIL,
+#define NODE_UNTIL NODE_UNTIL
+ NODE_ITER,
+#define NODE_ITER NODE_ITER
+ NODE_FOR,
+#define NODE_FOR NODE_FOR
+ NODE_BREAK,
+#define NODE_BREAK NODE_BREAK
+ NODE_NEXT,
+#define NODE_NEXT NODE_NEXT
+ NODE_REDO,
+#define NODE_REDO NODE_REDO
+ NODE_RETRY,
+#define NODE_RETRY NODE_RETRY
+ NODE_BEGIN,
+#define NODE_BEGIN NODE_BEGIN
+ NODE_RESCUE,
+#define NODE_RESCUE NODE_RESCUE
+ NODE_RESBODY,
+#define NODE_RESBODY NODE_RESBODY
+ NODE_ENSURE,
+#define NODE_ENSURE NODE_ENSURE
+ NODE_AND,
+#define NODE_AND NODE_AND
+ NODE_OR,
+#define NODE_OR NODE_OR
+ NODE_MASGN,
+#define NODE_MASGN NODE_MASGN
+ NODE_LASGN,
+#define NODE_LASGN NODE_LASGN
+ NODE_DASGN,
+#define NODE_DASGN NODE_DASGN
+ NODE_DASGN_CURR,
+#define NODE_DASGN_CURR NODE_DASGN_CURR
+ NODE_GASGN,
+#define NODE_GASGN NODE_GASGN
+ NODE_IASGN,
+#define NODE_IASGN NODE_IASGN
+ NODE_IASGN2,
+#define NODE_IASGN2 NODE_IASGN2
+ NODE_CDECL,
+#define NODE_CDECL NODE_CDECL
+ NODE_CVASGN,
+#define NODE_CVASGN NODE_CVASGN
+ NODE_CVDECL,
+#define NODE_CVDECL NODE_CVDECL
+ NODE_OP_ASGN1,
+#define NODE_OP_ASGN1 NODE_OP_ASGN1
+ NODE_OP_ASGN2,
+#define NODE_OP_ASGN2 NODE_OP_ASGN2
+ NODE_OP_ASGN_AND,
+#define NODE_OP_ASGN_AND NODE_OP_ASGN_AND
+ NODE_OP_ASGN_OR,
+#define NODE_OP_ASGN_OR NODE_OP_ASGN_OR
+ NODE_CALL,
+#define NODE_CALL NODE_CALL
+ NODE_FCALL,
+#define NODE_FCALL NODE_FCALL
+ NODE_VCALL,
+#define NODE_VCALL NODE_VCALL
+ NODE_SUPER,
+#define NODE_SUPER NODE_SUPER
+ NODE_ZSUPER,
+#define NODE_ZSUPER NODE_ZSUPER
+ NODE_ARRAY,
+#define NODE_ARRAY NODE_ARRAY
+ NODE_ZARRAY,
+#define NODE_ZARRAY NODE_ZARRAY
+ NODE_VALUES,
+#define NODE_VALUES NODE_VALUES
+ NODE_HASH,
+#define NODE_HASH NODE_HASH
+ NODE_RETURN,
+#define NODE_RETURN NODE_RETURN
+ NODE_YIELD,
+#define NODE_YIELD NODE_YIELD
+ NODE_LVAR,
+#define NODE_LVAR NODE_LVAR
+ NODE_DVAR,
+#define NODE_DVAR NODE_DVAR
+ NODE_GVAR,
+#define NODE_GVAR NODE_GVAR
+ NODE_IVAR,
+#define NODE_IVAR NODE_IVAR
+ NODE_CONST,
+#define NODE_CONST NODE_CONST
+ NODE_CVAR,
+#define NODE_CVAR NODE_CVAR
+ NODE_NTH_REF,
+#define NODE_NTH_REF NODE_NTH_REF
+ NODE_BACK_REF,
+#define NODE_BACK_REF NODE_BACK_REF
+ NODE_MATCH,
+#define NODE_MATCH NODE_MATCH
+ NODE_MATCH2,
+#define NODE_MATCH2 NODE_MATCH2
+ NODE_MATCH3,
+#define NODE_MATCH3 NODE_MATCH3
+ NODE_LIT,
+#define NODE_LIT NODE_LIT
+ NODE_STR,
+#define NODE_STR NODE_STR
+ NODE_DSTR,
+#define NODE_DSTR NODE_DSTR
+ NODE_XSTR,
+#define NODE_XSTR NODE_XSTR
+ NODE_DXSTR,
+#define NODE_DXSTR NODE_DXSTR
+ NODE_EVSTR,
+#define NODE_EVSTR NODE_EVSTR
+ NODE_DREGX,
+#define NODE_DREGX NODE_DREGX
+ NODE_DREGX_ONCE,
+#define NODE_DREGX_ONCE NODE_DREGX_ONCE
+ NODE_ARGS,
+#define NODE_ARGS NODE_ARGS
+ NODE_ARGS_AUX,
+#define NODE_ARGS_AUX NODE_ARGS_AUX
+ NODE_OPT_ARG,
+#define NODE_OPT_ARG NODE_OPT_ARG
+ NODE_POSTARG,
+#define NODE_POSTARG NODE_POSTARG
+ NODE_ARGSCAT,
+#define NODE_ARGSCAT NODE_ARGSCAT
+ NODE_ARGSPUSH,
+#define NODE_ARGSPUSH NODE_ARGSPUSH
+ NODE_SPLAT,
+#define NODE_SPLAT NODE_SPLAT
+ NODE_TO_ARY,
+#define NODE_TO_ARY NODE_TO_ARY
+ NODE_BLOCK_ARG,
+#define NODE_BLOCK_ARG NODE_BLOCK_ARG
+ NODE_BLOCK_PASS,
+#define NODE_BLOCK_PASS NODE_BLOCK_PASS
+ NODE_DEFN,
+#define NODE_DEFN NODE_DEFN
+ NODE_DEFS,
+#define NODE_DEFS NODE_DEFS
+ NODE_ALIAS,
+#define NODE_ALIAS NODE_ALIAS
+ NODE_VALIAS,
+#define NODE_VALIAS NODE_VALIAS
+ NODE_UNDEF,
+#define NODE_UNDEF NODE_UNDEF
+ NODE_CLASS,
+#define NODE_CLASS NODE_CLASS
+ NODE_MODULE,
+#define NODE_MODULE NODE_MODULE
+ NODE_SCLASS,
+#define NODE_SCLASS NODE_SCLASS
+ NODE_COLON2,
+#define NODE_COLON2 NODE_COLON2
+ NODE_COLON3,
+#define NODE_COLON3 NODE_COLON3
+ NODE_DOT2,
+#define NODE_DOT2 NODE_DOT2
+ NODE_DOT3,
+#define NODE_DOT3 NODE_DOT3
+ NODE_FLIP2,
+#define NODE_FLIP2 NODE_FLIP2
+ NODE_FLIP3,
+#define NODE_FLIP3 NODE_FLIP3
+ NODE_SELF,
+#define NODE_SELF NODE_SELF
+ NODE_NIL,
+#define NODE_NIL NODE_NIL
+ NODE_TRUE,
+#define NODE_TRUE NODE_TRUE
+ NODE_FALSE,
+#define NODE_FALSE NODE_FALSE
+ NODE_ERRINFO,
+#define NODE_ERRINFO NODE_ERRINFO
+ NODE_DEFINED,
+#define NODE_DEFINED NODE_DEFINED
+ NODE_POSTEXE,
+#define NODE_POSTEXE NODE_POSTEXE
+ NODE_ALLOCA,
+#define NODE_ALLOCA NODE_ALLOCA
+ NODE_BMETHOD,
+#define NODE_BMETHOD NODE_BMETHOD
+ NODE_MEMO,
+#define NODE_MEMO NODE_MEMO
+ NODE_IFUNC,
+#define NODE_IFUNC NODE_IFUNC
+ NODE_DSYM,
+#define NODE_DSYM NODE_DSYM
+ NODE_ATTRASGN,
+#define NODE_ATTRASGN NODE_ATTRASGN
+ NODE_PRELUDE,
+#define NODE_PRELUDE NODE_PRELUDE
+ NODE_LAMBDA,
+#define NODE_LAMBDA NODE_LAMBDA
+ NODE_OPTBLOCK,
+#define NODE_OPTBLOCK NODE_OPTBLOCK
+ NODE_LAST
+#define NODE_LAST NODE_LAST
+};
+
+typedef struct RNode {
+ unsigned long flags;
+ char *nd_file;
+ union {
+ struct RNode *node;
+ ID id;
+ VALUE value;
+ VALUE (*cfunc)(ANYARGS);
+ ID *tbl;
+ } u1;
+ union {
+ struct RNode *node;
+ ID id;
+ long argc;
+ VALUE value;
+ } u2;
+ union {
+ struct RNode *node;
+ ID id;
+ long state;
+ struct rb_global_entry *entry;
+ long cnt;
+ VALUE value;
+ } u3;
+} NODE;
+
+#define RNODE(obj) (R_CAST(RNode)(obj))
+
+/* 0..4:T_TYPES, 5:FL_MARK, 6:reserved, 7:NODE_FL_NEWLINE */
+#define NODE_FL_NEWLINE (((VALUE)1)<<7)
+#define NODE_FL_CREF_PUSHED_BY_EVAL NODE_FL_NEWLINE
+
+#define NODE_TYPESHIFT 8
+#define NODE_TYPEMASK (((VALUE)0x7f)<<NODE_TYPESHIFT)
+
+#define nd_type(n) ((int) (((RNODE(n))->flags & NODE_TYPEMASK)>>NODE_TYPESHIFT))
+#define nd_set_type(n,t) \
+ RNODE(n)->flags=((RNODE(n)->flags&~NODE_TYPEMASK)|((((unsigned long)t)<<NODE_TYPESHIFT)&NODE_TYPEMASK))
+
+#define NODE_LSHIFT (NODE_TYPESHIFT+7)
+#define NODE_LMASK (((SIGNED_VALUE)1<<(sizeof(VALUE)*CHAR_BIT-NODE_LSHIFT))-1)
+#define nd_line(n) (int)(RNODE(n)->flags>>NODE_LSHIFT)
+#define nd_set_line(n,l) \
+ RNODE(n)->flags=((RNODE(n)->flags&~(-1<<NODE_LSHIFT))|(((l)&NODE_LMASK)<<NODE_LSHIFT))
+
+#define nd_head u1.node
+#define nd_alen u2.argc
+#define nd_next u3.node
+
+#define nd_cond u1.node
+#define nd_body u2.node
+#define nd_else u3.node
+
+#define nd_orig u3.value
+
+#define nd_resq u2.node
+#define nd_ensr u3.node
+
+#define nd_1st u1.node
+#define nd_2nd u2.node
+
+#define nd_stts u1.node
+
+#define nd_entry u3.entry
+#define nd_vid u1.id
+#define nd_cflag u2.id
+#define nd_cval u3.value
+
+#define nd_oid u1.id
+#define nd_cnt u3.cnt
+#define nd_tbl u1.tbl
+
+#define nd_var u1.node
+#define nd_iter u3.node
+
+#define nd_value u2.node
+#define nd_aid u3.id
+
+#define nd_lit u1.value
+
+#define nd_frml u2.argc
+#define nd_rest u1.id
+#define nd_opt u1.node
+#define nd_pid u1.id
+#define nd_plen u2.argc
+
+#define nd_recv u1.node
+#define nd_mid u2.id
+#define nd_args u3.node
+
+#define nd_noex u3.id
+#define nd_defn u3.node
+
+#define nd_cfnc u1.cfunc
+#define nd_argc u2.argc
+
+#define nd_cpath u1.node
+#define nd_super u3.node
+
+#define nd_modl u1.id
+#define nd_clss u1.value
+
+#define nd_beg u1.node
+#define nd_end u2.node
+#define nd_state u3.state
+#define nd_rval u2.value
+
+#define nd_nth u2.argc
+
+#define nd_tag u1.id
+#define nd_tval u2.value
+
+#define nd_visi u2.argc
+
+#define NEW_NODE(t,a0,a1,a2) rb_node_newnode((t),(VALUE)(a0),(VALUE)(a1),(VALUE)(a2))
+
+#define NEW_DEFN(i,a,d,p) NEW_NODE(NODE_DEFN,0,i,NEW_SCOPE(a,d))
+#define NEW_DEFS(r,i,a,d) NEW_NODE(NODE_DEFS,r,i,NEW_SCOPE(a,d))
+#define NEW_IFUNC(f,c) NEW_NODE(NODE_IFUNC,f,c,0)
+#define NEW_SCOPE(a,b) NEW_NODE(NODE_SCOPE,local_tbl(),b,a)
+#define NEW_BLOCK(a) NEW_NODE(NODE_BLOCK,a,0,0)
+#define NEW_IF(c,t,e) NEW_NODE(NODE_IF,c,t,e)
+#define NEW_UNLESS(c,t,e) NEW_IF(c,e,t)
+#define NEW_CASE(h,b) NEW_NODE(NODE_CASE,h,b,0)
+#define NEW_WHEN(c,t,e) NEW_NODE(NODE_WHEN,c,t,e)
+#define NEW_OPT_N(b) NEW_NODE(NODE_OPT_N,0,b,0)
+#define NEW_WHILE(c,b,n) NEW_NODE(NODE_WHILE,c,b,n)
+#define NEW_UNTIL(c,b,n) NEW_NODE(NODE_UNTIL,c,b,n)
+#define NEW_FOR(v,i,b) NEW_NODE(NODE_FOR,v,b,i)
+#define NEW_ITER(a,b) NEW_NODE(NODE_ITER,0,NEW_SCOPE(a,b),0)
+#define NEW_LAMBDA(a) NEW_NODE(NODE_LAMBDA,a,0,0)
+#define NEW_BREAK(s) NEW_NODE(NODE_BREAK,s,0,0)
+#define NEW_NEXT(s) NEW_NODE(NODE_NEXT,s,0,0)
+#define NEW_REDO() NEW_NODE(NODE_REDO,0,0,0)
+#define NEW_RETRY() NEW_NODE(NODE_RETRY,0,0,0)
+#define NEW_BEGIN(b) NEW_NODE(NODE_BEGIN,0,b,0)
+#define NEW_RESCUE(b,res,e) NEW_NODE(NODE_RESCUE,b,res,e)
+#define NEW_RESBODY(a,ex,n) NEW_NODE(NODE_RESBODY,n,ex,a)
+#define NEW_ENSURE(b,en) NEW_NODE(NODE_ENSURE,b,0,en)
+#define NEW_RETURN(s) NEW_NODE(NODE_RETURN,s,0,0)
+#define NEW_YIELD(a,s) NEW_NODE(NODE_YIELD,a,0,s)
+#define NEW_LIST(a) NEW_ARRAY(a)
+#define NEW_ARRAY(a) NEW_NODE(NODE_ARRAY,a,1,0)
+#define NEW_ZARRAY() NEW_NODE(NODE_ZARRAY,0,0,0)
+#define NEW_HASH(a) NEW_NODE(NODE_HASH,a,0,0)
+#define NEW_MASGN(l,r) NEW_NODE(NODE_MASGN,l,0,r)
+#define NEW_GASGN(v,val) NEW_NODE(NODE_GASGN,v,val,rb_global_entry(v))
+#define NEW_LASGN(v,val) NEW_NODE(NODE_LASGN,v,val,0)
+#define NEW_DASGN(v,val) NEW_NODE(NODE_DASGN,v,val,0)
+#define NEW_DASGN_CURR(v,val) NEW_NODE(NODE_DASGN_CURR,v,val,0)
+#define NEW_IASGN(v,val) NEW_NODE(NODE_IASGN,v,val,0)
+#define NEW_IASGN2(v,val) NEW_NODE(NODE_IASGN2,v,val,0)
+#define NEW_CDECL(v,val,path) NEW_NODE(NODE_CDECL,v,val,path)
+#define NEW_CVASGN(v,val) NEW_NODE(NODE_CVASGN,v,val,0)
+#define NEW_CVDECL(v,val) NEW_NODE(NODE_CVDECL,v,val,0)
+#define NEW_OP_ASGN1(p,id,a) NEW_NODE(NODE_OP_ASGN1,p,id,a)
+#define NEW_OP_ASGN2(r,i,o,val) NEW_NODE(NODE_OP_ASGN2,r,val,NEW_OP_ASGN22(i,o))
+#define NEW_OP_ASGN22(i,o) NEW_NODE(NODE_OP_ASGN2,i,o,rb_id_attrset(i))
+#define NEW_OP_ASGN_OR(i,val) NEW_NODE(NODE_OP_ASGN_OR,i,val,0)
+#define NEW_OP_ASGN_AND(i,val) NEW_NODE(NODE_OP_ASGN_AND,i,val,0)
+#define NEW_GVAR(v) NEW_NODE(NODE_GVAR,v,0,rb_global_entry(v))
+#define NEW_LVAR(v) NEW_NODE(NODE_LVAR,v,0,0)
+#define NEW_DVAR(v) NEW_NODE(NODE_DVAR,v,0,0)
+#define NEW_IVAR(v) NEW_NODE(NODE_IVAR,v,0,0)
+#define NEW_CONST(v) NEW_NODE(NODE_CONST,v,0,0)
+#define NEW_CVAR(v) NEW_NODE(NODE_CVAR,v,0,0)
+#define NEW_NTH_REF(n) NEW_NODE(NODE_NTH_REF,0,n,0)
+#define NEW_BACK_REF(n) NEW_NODE(NODE_BACK_REF,0,n,0)
+#define NEW_MATCH(c) NEW_NODE(NODE_MATCH,c,0,0)
+#define NEW_MATCH2(n1,n2) NEW_NODE(NODE_MATCH2,n1,n2,0)
+#define NEW_MATCH3(r,n2) NEW_NODE(NODE_MATCH3,r,n2,0)
+#define NEW_LIT(l) NEW_NODE(NODE_LIT,l,0,0)
+#define NEW_STR(s) NEW_NODE(NODE_STR,s,0,0)
+#define NEW_DSTR(s) NEW_NODE(NODE_DSTR,s,1,0)
+#define NEW_XSTR(s) NEW_NODE(NODE_XSTR,s,0,0)
+#define NEW_DXSTR(s) NEW_NODE(NODE_DXSTR,s,0,0)
+#define NEW_DSYM(s) NEW_NODE(NODE_DSYM,s,0,0)
+#define NEW_EVSTR(n) NEW_NODE(NODE_EVSTR,0,(n),0)
+#define NEW_CALL(r,m,a) NEW_NODE(NODE_CALL,r,m,a)
+#define NEW_FCALL(m,a) NEW_NODE(NODE_FCALL,0,m,a)
+#define NEW_VCALL(m) NEW_NODE(NODE_VCALL,0,m,0)
+#define NEW_SUPER(a) NEW_NODE(NODE_SUPER,0,0,a)
+#define NEW_ZSUPER() NEW_NODE(NODE_ZSUPER,0,0,0)
+#define NEW_ARGS(m,o) NEW_NODE(NODE_ARGS,o,m,0)
+#define NEW_ARGS_AUX(r,b) NEW_NODE(NODE_ARGS_AUX,r,b,0)
+#define NEW_OPT_ARG(i,v) NEW_NODE(NODE_OPT_ARG,i,v,0)
+#define NEW_POSTARG(i,v) NEW_NODE(NODE_POSTARG,i,v,0)
+#define NEW_ARGSCAT(a,b) NEW_NODE(NODE_ARGSCAT,a,b,0)
+#define NEW_ARGSPUSH(a,b) NEW_NODE(NODE_ARGSPUSH,a,b,0)
+#define NEW_SPLAT(a) NEW_NODE(NODE_SPLAT,a,0,0)
+#define NEW_TO_ARY(a) NEW_NODE(NODE_TO_ARY,a,0,0)
+#define NEW_BLOCK_ARG(v) NEW_NODE(NODE_BLOCK_ARG,v,0,local_cnt(v))
+#define NEW_BLOCK_PASS(b) NEW_NODE(NODE_BLOCK_PASS,0,b,0)
+#define NEW_ALIAS(n,o) NEW_NODE(NODE_ALIAS,n,o,0)
+#define NEW_VALIAS(n,o) NEW_NODE(NODE_VALIAS,n,o,0)
+#define NEW_UNDEF(i) NEW_NODE(NODE_UNDEF,0,i,0)
+#define NEW_CLASS(n,b,s) NEW_NODE(NODE_CLASS,n,NEW_SCOPE(0,b),(s))
+#define NEW_SCLASS(r,b) NEW_NODE(NODE_SCLASS,r,NEW_SCOPE(0,b),0)
+#define NEW_MODULE(n,b) NEW_NODE(NODE_MODULE,n,NEW_SCOPE(0,b),0)
+#define NEW_COLON2(c,i) NEW_NODE(NODE_COLON2,c,i,0)
+#define NEW_COLON3(i) NEW_NODE(NODE_COLON3,0,i,0)
+#define NEW_DOT2(b,e) NEW_NODE(NODE_DOT2,b,e,0)
+#define NEW_DOT3(b,e) NEW_NODE(NODE_DOT3,b,e,0)
+#define NEW_SELF() NEW_NODE(NODE_SELF,0,0,0)
+#define NEW_NIL() NEW_NODE(NODE_NIL,0,0,0)
+#define NEW_TRUE() NEW_NODE(NODE_TRUE,0,0,0)
+#define NEW_FALSE() NEW_NODE(NODE_FALSE,0,0,0)
+#define NEW_ERRINFO() NEW_NODE(NODE_ERRINFO,0,0,0)
+#define NEW_DEFINED(e) NEW_NODE(NODE_DEFINED,e,0,0)
+#define NEW_PREEXE(b) NEW_SCOPE(b)
+#define NEW_POSTEXE(b) NEW_NODE(NODE_POSTEXE,0,b,0)
+#define NEW_BMETHOD(b) NEW_NODE(NODE_BMETHOD,0,0,b)
+#define NEW_ATTRASGN(r,m,a) NEW_NODE(NODE_ATTRASGN,r,m,a)
+#define NEW_PRELUDE(p,b) NEW_NODE(NODE_PRELUDE,p,b,0)
+#define NEW_OPTBLOCK(a) NEW_NODE(NODE_OPTBLOCK,a,0,0)
+
+VALUE rb_parser_new(void);
+VALUE rb_parser_end_seen_p(VALUE);
+VALUE rb_parser_encoding(VALUE);
+
+NODE *rb_parser_compile_cstr(volatile VALUE, const char*, const char*, int, int);
+NODE *rb_parser_compile_string(volatile VALUE, const char*, VALUE, int);
+NODE *rb_parser_compile_file(volatile VALUE, const char*, VALUE, int);
+
+NODE *rb_compile_cstr(const char*, const char*, int, int);
+NODE *rb_compile_string(const char*, VALUE, int);
+NODE *rb_compile_file(const char*, VALUE, int);
+
+NODE *rb_node_newnode(enum node_type,VALUE,VALUE,VALUE);
+NODE *rb_node_newnode_longlife(enum node_type,VALUE,VALUE,VALUE);
+
+struct rb_global_entry {
+ struct rb_global_variable *var;
+ ID id;
+};
+
+struct rb_global_entry *rb_global_entry(ID);
+VALUE rb_gvar_get(struct rb_global_entry *);
+VALUE rb_gvar_set(struct rb_global_entry *, VALUE);
+VALUE rb_gvar_defined(struct rb_global_entry *);
+
+#if defined(__cplusplus)
+#if 0
+{ /* satisfy cc-mode */
+#endif
+} /* extern "C" { */
+#endif
+
+#endif /* RUBY_NODE_H */
211 ext/binding_of_caller/ruby_headers/regenc.h
@@ -0,0 +1,211 @@
+#ifndef ONIGURUMA_REGENC_H
+#define ONIGURUMA_REGENC_H
+/**********************************************************************
+ regenc.h - Oniguruma (regular expression library)
+**********************************************************************/
+/*-
+ * Copyright (c) 2002-2008 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#ifndef REGINT_H
+#ifndef RUBY_EXTERN
+#include "ruby/config.h"
+#include "ruby/defines.h"
+#endif
+#ifdef ONIG_ESCAPE_UCHAR_COLLISION
+#undef ONIG_ESCAPE_UCHAR_COLLISION
+#endif
+#endif
+#include "ruby/oniguruma.h"
+
+typedef struct {
+ OnigCodePoint from;
+ OnigCodePoint to;
+} OnigPairCaseFoldCodes;
+
+
+#ifndef NULL
+#define NULL ((void* )0)
+#endif
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#ifndef ARG_UNUSED
+#if defined(__GNUC__)
+# define ARG_UNUSED __attribute__ ((unused))
+#else
+# define ARG_UNUSED
+#endif
+#endif
+
+#define ONIG_IS_NULL(p) (((void*)(p)) == (void*)0)
+#define ONIG_IS_NOT_NULL(p) (((void*)(p)) != (void*)0)
+#define ONIG_CHECK_NULL_RETURN(p) if (ONIG_IS_NULL(p)) return NULL
+#define ONIG_CHECK_NULL_RETURN_VAL(p,val) if (ONIG_IS_NULL(p)) return (val)
+
+#define enclen(enc,p,e) ((enc->max_enc_len == enc->min_enc_len) ? enc->min_enc_len : ONIGENC_MBC_ENC_LEN(enc,p,e))
+
+/* character types bit flag */
+#define BIT_CTYPE_NEWLINE (1<< ONIGENC_CTYPE_NEWLINE)
+#define BIT_CTYPE_ALPHA (1<< ONIGENC_CTYPE_ALPHA)
+#define BIT_CTYPE_BLANK (1<< ONIGENC_CTYPE_BLANK)
+#define BIT_CTYPE_CNTRL (1<< ONIGENC_CTYPE_CNTRL)
+#define BIT_CTYPE_DIGIT (1<< ONIGENC_CTYPE_DIGIT)
+#define BIT_CTYPE_GRAPH (1<< ONIGENC_CTYPE_GRAPH)
+#define BIT_CTYPE_LOWER (1<< ONIGENC_CTYPE_LOWER)
+#define BIT_CTYPE_PRINT (1<< ONIGENC_CTYPE_PRINT)
+#define BIT_CTYPE_PUNCT (1<< ONIGENC_CTYPE_PUNCT)
+#define BIT_CTYPE_SPACE (1<< ONIGENC_CTYPE_SPACE)
+#define BIT_CTYPE_UPPER (1<< ONIGENC_CTYPE_UPPER)
+#define BIT_CTYPE_XDIGIT (1<< ONIGENC_CTYPE_XDIGIT)
+#define BIT_CTYPE_WORD (1<< ONIGENC_CTYPE_WORD)
+#define BIT_CTYPE_ALNUM (1<< ONIGENC_CTYPE_ALNUM)
+#define BIT_CTYPE_ASCII (1<< ONIGENC_CTYPE_ASCII)
+
+#define CTYPE_TO_BIT(ctype) (1<<(ctype))
+#define CTYPE_IS_WORD_GRAPH_PRINT(ctype) \
+ ((ctype) == ONIGENC_CTYPE_WORD || (ctype) == ONIGENC_CTYPE_GRAPH ||\
+ (ctype) == ONIGENC_CTYPE_PRINT)
+
+
+typedef struct {
+ const UChar *name;
+ int ctype;
+ short int len;
+} PosixBracketEntryType;
+
+#define PosixBracketEntryInit(name, ctype) {(const UChar *)name, ctype, (short int)(sizeof(name) - 1)}
+
+/* #define USE_CRNL_AS_LINE_TERMINATOR */
+#define USE_UNICODE_PROPERTIES
+/* #define USE_UNICODE_CASE_FOLD_TURKISH_AZERI */
+/* #define USE_UNICODE_ALL_LINE_TERMINATORS */ /* see Unicode.org UTF#18 */
+
+
+#define ONIG_ENCODING_INIT_DEFAULT ONIG_ENCODING_ASCII
+
+/* for encoding system implementation (internal) */
+ONIG_EXTERN int onigenc_ascii_apply_all_case_fold P_((OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg, OnigEncoding enc));
+ONIG_EXTERN int onigenc_ascii_get_case_fold_codes_by_str P_((OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[], OnigEncoding enc));
+ONIG_EXTERN int onigenc_apply_all_case_fold_with_map P_((int map_size, const OnigPairCaseFoldCodes map[], int ess_tsett_flag, OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg));
+ONIG_EXTERN int onigenc_get_case_fold_codes_by_str_with_map P_((int map_size, const OnigPairCaseFoldCodes map[], int ess_tsett_flag, OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[]));
+ONIG_EXTERN int onigenc_not_support_get_ctype_code_range P_((OnigCtype ctype, OnigCodePoint* sb_out, const OnigCodePoint* ranges[], OnigEncoding enc));
+ONIG_EXTERN int onigenc_is_mbc_newline_0x0a P_((const UChar* p, const UChar* end, OnigEncoding enc));
+
+
+/* methods for single byte encoding */
+ONIG_EXTERN int onigenc_ascii_mbc_case_fold P_((OnigCaseFoldType flag, const UChar** p, const UChar* end, UChar* lower, OnigEncoding enc));
+ONIG_EXTERN int onigenc_single_byte_mbc_enc_len P_((const UChar* p, const UChar* e, OnigEncoding enc));
+ONIG_EXTERN OnigCodePoint onigenc_single_byte_mbc_to_code P_((const UChar* p, const UChar* end, OnigEncoding enc));
+ONIG_EXTERN int onigenc_single_byte_code_to_mbclen P_((OnigCodePoint code, OnigEncoding enc));
+ONIG_EXTERN int onigenc_single_byte_code_to_mbc P_((OnigCodePoint code, UChar *buf, OnigEncoding enc));
+ONIG_EXTERN UChar* onigenc_single_byte_left_adjust_char_head P_((const UChar* start, const UChar* s, const OnigUChar* end, OnigEncoding enc));
+ONIG_EXTERN int onigenc_always_true_is_allowed_reverse_match P_((const UChar* s, const UChar* end, OnigEncoding enc));
+ONIG_EXTERN int onigenc_always_false_is_allowed_reverse_match P_((const UChar* s, const UChar* end, OnigEncoding enc));
+ONIG_EXTERN int onigenc_ascii_is_code_ctype P_((OnigCodePoint code, unsigned int ctype, OnigEncoding enc));
+
+/* methods for multi byte encoding */
+ONIG_EXTERN OnigCodePoint onigenc_mbn_mbc_to_code P_((OnigEncoding enc, const UChar* p, const UChar* end));
+ONIG_EXTERN int onigenc_mbn_mbc_case_fold P_((OnigEncoding enc, OnigCaseFoldType flag, const UChar** p, const UChar* end, UChar* lower));
+ONIG_EXTERN int onigenc_mb2_code_to_mbclen P_((OnigCodePoint code, OnigEncoding enc));
+ONIG_EXTERN int onigenc_mb2_code_to_mbc P_((OnigEncoding enc, OnigCodePoint code, UChar *buf));
+ONIG_EXTERN int onigenc_minimum_property_name_to_ctype P_((OnigEncoding enc, UChar* p, UChar* end));
+ONIG_EXTERN int onigenc_unicode_property_name_to_ctype P_((OnigEncoding enc, UChar* p, UChar* end));
+ONIG_EXTERN int onigenc_mb2_is_code_ctype P_((OnigEncoding enc, OnigCodePoint code, unsigned int ctype));
+ONIG_EXTERN int onigenc_mb4_code_to_mbclen P_((OnigCodePoint code, OnigEncoding enc));
+ONIG_EXTERN int onigenc_mb4_code_to_mbc P_((OnigEncoding enc, OnigCodePoint code, UChar *buf));
+ONIG_EXTERN int onigenc_mb4_is_code_ctype P_((OnigEncoding enc, OnigCodePoint code, unsigned int ctype));
+
+
+/* in enc/unicode.c */
+ONIG_EXTERN int onigenc_unicode_is_code_ctype P_((OnigCodePoint code, unsigned int ctype, OnigEncoding enc));
+ONIG_EXTERN int onigenc_utf16_32_get_ctype_code_range P_((OnigCtype ctype, OnigCodePoint *sb_out, const OnigCodePoint* ranges[], OnigEncoding enc));
+ONIG_EXTERN int onigenc_unicode_ctype_code_range P_((int ctype, const OnigCodePoint* ranges[]));
+ONIG_EXTERN int onigenc_unicode_get_case_fold_codes_by_str P_((OnigEncoding enc, OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[]));
+ONIG_EXTERN int onigenc_unicode_mbc_case_fold P_((OnigEncoding enc, OnigCaseFoldType flag, const UChar** pp, const UChar* end, UChar* fold));
+ONIG_EXTERN int onigenc_unicode_apply_all_case_fold P_((OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg, OnigEncoding enc));
+
+
+#define UTF16_IS_SURROGATE_FIRST(c) (((c) & 0xfc) == 0xd8)
+#define UTF16_IS_SURROGATE_SECOND(c) (((c) & 0xfc) == 0xdc)
+
+#define ONIGENC_ISO_8859_1_TO_LOWER_CASE(c) \
+ OnigEncISO_8859_1_ToLowerCaseTable[c]
+#define ONIGENC_ISO_8859_1_TO_UPPER_CASE(c) \
+ OnigEncISO_8859_1_ToUpperCaseTable[c]
+
+ONIG_EXTERN const UChar OnigEncISO_8859_1_ToLowerCaseTable[];
+ONIG_EXTERN const UChar OnigEncISO_8859_1_ToUpperCaseTable[];
+
+ONIG_EXTERN int
+onigenc_with_ascii_strncmp P_((OnigEncoding enc, const UChar* p, const UChar* end, const UChar* sascii /* ascii */, int n));
+ONIG_EXTERN UChar*
+onigenc_step P_((OnigEncoding enc, const UChar* p, const UChar* end, int n));
+
+/* defined in regexec.c, but used in enc/xxx.c */
+extern int onig_is_in_code_range P_((const UChar* p, OnigCodePoint code));
+
+ONIG_EXTERN OnigEncoding OnigEncDefaultCharEncoding;
+ONIG_EXTERN const UChar OnigEncAsciiToLowerCaseTable[];
+ONIG_EXTERN const UChar OnigEncAsciiToUpperCaseTable[];
+ONIG_EXTERN const unsigned short OnigEncAsciiCtypeTable[];
+
+#define ONIGENC_IS_ASCII_CODE(code) ((code) < 0x80)
+#define ONIGENC_ASCII_CODE_TO_LOWER_CASE(c) OnigEncAsciiToLowerCaseTable[c]
+#define ONIGENC_ASCII_CODE_TO_UPPER_CASE(c) OnigEncAsciiToUpperCaseTable[c]
+#define ONIGENC_IS_ASCII_CODE_CTYPE(code,ctype) \
+ ((OnigEncAsciiCtypeTable[code] & CTYPE_TO_BIT(ctype)) != 0)
+#define ONIGENC_IS_ASCII_CODE_CASE_AMBIG(code) \
+ (ONIGENC_IS_ASCII_CODE_CTYPE(code, ONIGENC_CTYPE_UPPER) ||\
+ ONIGENC_IS_ASCII_CODE_CTYPE(code, ONIGENC_CTYPE_LOWER))
+
+#ifdef ONIG_ENC_REGISTER
+extern int ONIG_ENC_REGISTER(const char *, OnigEncodingType*);
+#define OnigEncodingName(n) encoding_##n
+#define OnigEncodingDeclare(n) static OnigEncodingType OnigEncodingName(n)
+#define OnigEncodingDefine(f,n) \
+ OnigEncodingDeclare(n); \
+ void Init_##f(void) { \
+ ONIG_ENC_REGISTER(OnigEncodingName(n).name, \
+ &OnigEncodingName(n)); \
+ } \
+ OnigEncodingDeclare(n)
+#else
+#define OnigEncodingName(n) OnigEncoding##n
+#define OnigEncodingDeclare(n) OnigEncodingType OnigEncodingName(n)
+#define OnigEncodingDefine(f,n) OnigEncodingDeclare(n)
+#endif
+
+/* macros for define replica encoding and encoding alias */
+#define ENC_REPLICATE(name, orig)
+#define ENC_ALIAS(name, orig)
+#define ENC_DUMMY(name)
+
+#endif /* ONIGURUMA_REGENC_H */
841 ext/binding_of_caller/ruby_headers/regint.h
@@ -0,0 +1,841 @@
+#ifndef ONIGURUMA_REGINT_H
+#define ONIGURUMA_REGINT_H
+/**********************************************************************
+ regint.h - Oniguruma (regular expression library)
+**********************************************************************/
+/*-
+ * Copyright (c) 2002-2008 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* for debug */
+/* #define ONIG_DEBUG_PARSE_TREE */
+/* #define ONIG_DEBUG_COMPILE */
+/* #define ONIG_DEBUG_SEARCH */
+/* #define ONIG_DEBUG_MATCH */
+/* #define ONIG_DONT_OPTIMIZE */
+
+/* for byte-code statistical data. */
+/* #define ONIG_DEBUG_STATISTICS */
+
+#if defined(ONIG_DEBUG_PARSE_TREE) || defined(ONIG_DEBUG_MATCH) || \
+ defined(ONIG_DEBUG_SEARCH) || defined(ONIG_DEBUG_COMPILE) || \
+ defined(ONIG_DEBUG_STATISTICS)
+#ifndef ONIG_DEBUG
+#define ONIG_DEBUG
+#endif
+#endif
+
+#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
+ (defined(__ppc__) && defined(__APPLE__)) || \
+ defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD86) || \
+ defined(__mc68020__)
+#define PLATFORM_UNALIGNED_WORD_ACCESS
+#endif
+
+/* config */
+/* spec. config */
+#define USE_NAMED_GROUP
+#define USE_SUBEXP_CALL
+#define USE_BACKREF_WITH_LEVEL /* \k<name+n>, \k<name-n> */
+#define USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT /* /(?:()|())*\2/ */
+#define USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE /* /\n$/ =~ "\n" */
+#define USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR
+/* #define USE_RECOMPILE_API */
+/* !!! moved to regenc.h. */ /* #define USE_CRNL_AS_LINE_TERMINATOR */
+
+/* internal config */
+#define USE_PARSE_TREE_NODE_RECYCLE
+#define USE_OP_PUSH_OR_JUMP_EXACT
+#define USE_QTFR_PEEK_NEXT
+#define USE_ST_LIBRARY
+#define USE_SHARED_CCLASS_TABLE
+
+#define INIT_MATCH_STACK_SIZE 160
+#define DEFAULT_MATCH_STACK_LIMIT_SIZE 0 /* unlimited */
+
+#if defined(__GNUC__)
+# define ARG_UNUSED __attribute__ ((unused))
+#else
+# define ARG_UNUSED
+#endif
+
+/* */
+/* escape other system UChar definition */
+#ifndef RUBY_DEFINES_H
+#include "ruby/ruby.h"
+#undef xmalloc
+#undef xrealloc
+#undef xcalloc
+#undef xfree
+#endif
+#ifdef ONIG_ESCAPE_UCHAR_COLLISION
+#undef ONIG_ESCAPE_UCHAR_COLLISION
+#endif
+#undef USE_MATCH_RANGE_IS_COMPLETE_RANGE
+#undef USE_CAPTURE_HISTORY
+#define USE_VARIABLE_META_CHARS
+#define USE_WORD_BEGIN_END /* "\<": word-begin, "\>": word-end */
+#define USE_POSIX_REGION_OPTION /* needed for POSIX API support */
+#define USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE
+/* #define USE_COMBINATION_EXPLOSION_CHECK */ /* (X*)* */
+/* #define USE_MULTI_THREAD_SYSTEM */
+#define THREAD_SYSTEM_INIT /* depend on thread system */
+#define THREAD_SYSTEM_END /* depend on thread system */
+#define THREAD_ATOMIC_START /* depend on thread system */
+#define THREAD_ATOMIC_END /* depend on thread system */
+#define THREAD_PASS /* depend on thread system */
+#ifndef xmalloc
+#define xmalloc malloc
+#define xrealloc realloc
+#define xcalloc calloc
+#define xfree free
+#endif
+
+#ifdef RUBY
+
+#define CHECK_INTERRUPT_IN_MATCH_AT rb_thread_check_ints()
+#define onig_st_init_table st_init_table
+#define onig_st_init_table_with_size st_init_table_with_size
+#define onig_st_init_numtable st_init_numtable
+#define onig_st_init_numtable_with_size st_init_numtable_with_size
+#define onig_st_init_strtable st_init_strtable
+#define onig_st_init_strtable_with_size st_init_strtable_with_size
+#define onig_st_delete st_delete
+#define onig_st_delete_safe st_delete_safe
+#define onig_st_insert st_insert
+#define onig_st_lookup st_lookup
+#define onig_st_foreach st_foreach
+#define onig_st_add_direct st_add_direct
+#define onig_st_free_table st_free_table
+#define onig_st_cleanup_safe st_cleanup_safe
+#define onig_st_copy st_copy
+#define onig_st_nothing_key_clone st_nothing_key_clone
+#define onig_st_nothing_key_free st_nothing_key_free
+#define onig_st_is_member st_is_member
+
+#define USE_UPPER_CASE_TABLE
+#else
+
+#define st_init_table onig_st_init_table
+#define st_init_table_with_size onig_st_init_table_with_size
+#define st_init_numtable onig_st_init_numtable
+#define st_init_numtable_with_size onig_st_init_numtable_with_size
+#define st_init_strtable onig_st_init_strtable
+#define st_init_strtable_with_size onig_st_init_strtable_with_size
+#define st_delete onig_st_delete
+#define st_delete_safe onig_st_delete_safe
+#define st_insert onig_st_insert
+#define st_lookup onig_st_lookup
+#define st_foreach onig_st_foreach
+#define st_add_direct onig_st_add_direct
+#define st_free_table onig_st_free_table
+#define st_cleanup_safe onig_st_cleanup_safe
+#define st_copy onig_st_copy
+#define st_nothing_key_clone onig_st_nothing_key_clone
+#define st_nothing_key_free onig_st_nothing_key_free
+/* */
+#define onig_st_is_member st_is_member
+
+#define CHECK_INTERRUPT_IN_MATCH_AT
+
+#endif
+
+#define STATE_CHECK_STRING_THRESHOLD_LEN 7
+#define STATE_CHECK_BUFF_MAX_SIZE 0x4000
+
+#define THREAD_PASS_LIMIT_COUNT 8
+#define xmemset memset
+#define xmemcpy memcpy
+#define xmemmove memmove
+
+#if defined(_WIN32) && !defined(__GNUC__)
+#define xalloca _alloca
+#define xvsnprintf _vsnprintf
+#else
+#define xalloca alloca
+#define xvsnprintf vsnprintf
+#endif
+
+
+#if defined(USE_RECOMPILE_API) && defined(USE_MULTI_THREAD_SYSTEM)
+#define ONIG_STATE_INC(reg) (reg)->state++
+#define ONIG_STATE_DEC(reg) (reg)->state--
+
+#define ONIG_STATE_INC_THREAD(reg) do {\
+ THREAD_ATOMIC_START;\
+ (reg)->state++;\
+ THREAD_ATOMIC_END;\
+} while(0)
+#define ONIG_STATE_DEC_THREAD(reg) do {\
+ THREAD_ATOMIC_START;\
+ (reg)->state--;\
+ THREAD_ATOMIC_END;\
+} while(0)
+#else
+#define ONIG_STATE_INC(reg) /* Nothing */
+#define ONIG_STATE_DEC(reg) /* Nothing */
+#define ONIG_STATE_INC_THREAD(reg) /* Nothing */
+#define ONIG_STATE_DEC_THREAD(reg) /* Nothing */
+#endif /* USE_RECOMPILE_API && USE_MULTI_THREAD_SYSTEM */
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#if defined(HAVE_ALLOCA_H) && (defined(_AIX) || !defined(__GNUC__))
+#include <alloca.h>
+#endif
+
+#ifdef HAVE_STRING_H
+# include <string.h>
+#else
+# include <strings.h>
+#endif
+
+#include <ctype.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef ONIG_DEBUG
+# include <stdio.h>
+#endif
+
+#include "regenc.h"
+
+#ifdef MIN
+#undef MIN
+#endif
+#ifdef MAX
+#undef MAX
+#endif
+#define MIN(a,b) (((a)>(b))?(b):(a))
+#define MAX(a,b) (((a)<(b))?(b):(a))
+
+#define IS_NULL(p) (((void*)(p)) == (void*)0)
+#define IS_NOT_NULL(p) (((void*)(p)) != (void*)0)
+#define CHECK_NULL_RETURN(p) if (IS_NULL(p)) return NULL
+#define CHECK_NULL_RETURN_MEMERR(p) if (IS_NULL(p)) return ONIGERR_MEMORY
+#define NULL_UCHARP ((UChar* )0)
+
+#ifdef PLATFORM_UNALIGNED_WORD_ACCESS
+
+#define PLATFORM_GET_INC(val,p,type) do{\
+ val = *(type* )p;\
+ (p) += sizeof(type);\
+} while(0)
+
+#else
+
+#define PLATFORM_GET_INC(val,p,type) do{\
+ xmemcpy(&val, (p), sizeof(type));\
+ (p) += sizeof(type);\
+} while(0)
+
+/* sizeof(OnigCodePoint) */
+#define WORD_ALIGNMENT_SIZE SIZEOF_LONG
+
+#define GET_ALIGNMENT_PAD_SIZE(addr,pad_size) do {\
+ (pad_size) = WORD_ALIGNMENT_SIZE \
+ - ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\
+ if ((pad_size) == WORD_ALIGNMENT_SIZE) (pad_size) = 0;\
+} while (0)
+
+#define ALIGNMENT_RIGHT(addr) do {\
+ (addr) += (WORD_ALIGNMENT_SIZE - 1);\
+ (addr) -= ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\
+} while (0)
+
+#endif /* PLATFORM_UNALIGNED_WORD_ACCESS */
+
+/* stack pop level */
+#define STACK_POP_LEVEL_FREE 0
+#define STACK_POP_LEVEL_MEM_START 1
+#define STACK_POP_LEVEL_ALL 2
+
+/* optimize flags */
+#define ONIG_OPTIMIZE_NONE 0
+#define ONIG_OPTIMIZE_EXACT 1 /* Slow Search */
+#define ONIG_OPTIMIZE_EXACT_BM 2 /* Boyer Moore Search */
+#define ONIG_OPTIMIZE_EXACT_BM_NOT_REV 3 /* BM (but not simple match) */
+#define ONIG_OPTIMIZE_EXACT_IC 4 /* Slow Search (ignore case) */
+#define ONIG_OPTIMIZE_MAP 5 /* char map */
+
+/* bit status */
+typedef unsigned int BitStatusType;
+
+#define BIT_STATUS_BITS_NUM (sizeof(BitStatusType) * 8)
+#define BIT_STATUS_CLEAR(stats) (stats) = 0
+#define BIT_STATUS_ON_ALL(stats) (stats) = ~((BitStatusType )0)
+#define BIT_STATUS_AT(stats,n) \
+ ((n) < (int )BIT_STATUS_BITS_NUM ? ((stats) & (1 << n)) : ((stats) & 1))
+
+#define BIT_STATUS_ON_AT(stats,n) do {\
+ if ((n) < (int )BIT_STATUS_BITS_NUM) \
+ (stats) |= (1 << (n));\
+ else\
+ (stats) |= 1;\
+} while (0)
+
+#define BIT_STATUS_ON_AT_SIMPLE(stats,n) do {\
+ if ((n) < (int )BIT_STATUS_BITS_NUM)\
+ (stats) |= (1 << (n));\
+} while (0)
+
+
+#define INT_MAX_LIMIT ((1UL << (SIZEOF_INT * 8 - 1)) - 1)
+
+#define DIGITVAL(code) ((code) - '0')
+#define ODIGITVAL(code) DIGITVAL(code)
+#define XDIGITVAL(enc,code) \
+ (ONIGENC_IS_CODE_DIGIT(enc,code) ? DIGITVAL(code) \
+ : (ONIGENC_IS_CODE_UPPER(enc,code) ? (code) - 'A' + 10 : (code) - 'a' + 10))
+
+#define IS_SINGLELINE(option) ((option) & ONIG_OPTION_SINGLELINE)
+#define IS_MULTILINE(option) ((option) & ONIG_OPTION_MULTILINE)
+#define IS_IGNORECASE(option) ((option) & ONIG_OPTION_IGNORECASE)
+#define IS_EXTEND(option) ((option) & ONIG_OPTION_EXTEND)
+#define IS_FIND_LONGEST(option) ((option) & ONIG_OPTION_FIND_LONGEST)
+#define IS_FIND_NOT_EMPTY(option) ((option) & ONIG_OPTION_FIND_NOT_EMPTY)
+#define IS_FIND_CONDITION(option) ((option) & \
+ (ONIG_OPTION_FIND_LONGEST | ONIG_OPTION_FIND_NOT_EMPTY))
+#define IS_NOTBOL(option) ((option) & ONIG_OPTION_NOTBOL)
+#define IS_NOTEOL(option) ((option) & ONIG_OPTION_NOTEOL)
+#define IS_POSIX_REGION(option) ((option) & ONIG_OPTION_POSIX_REGION)
+
+/* OP_SET_OPTION is required for these options.
+#define IS_DYNAMIC_OPTION(option) \
+ (((option) & (ONIG_OPTION_MULTILINE | ONIG_OPTION_IGNORECASE)) != 0)
+*/
+/* ignore-case and multibyte status are included in compiled code. */
+#define IS_DYNAMIC_OPTION(option) 0
+
+#define DISABLE_CASE_FOLD_MULTI_CHAR(case_fold_flag) \
+ ((case_fold_flag) & ~INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR)
+
+#define REPEAT_INFINITE -1
+#define IS_REPEAT_INFINITE(n) ((n) == REPEAT_INFINITE)
+
+/* bitset */
+#define BITS_PER_BYTE 8
+#define SINGLE_BYTE_SIZE (1 << BITS_PER_BYTE)
+#define BITS_IN_ROOM (sizeof(Bits) * BITS_PER_BYTE)
+#define BITSET_SIZE (SINGLE_BYTE_SIZE / BITS_IN_ROOM)
+
+#ifdef PLATFORM_UNALIGNED_WORD_ACCESS
+typedef unsigned int Bits;
+#else
+typedef unsigned char Bits;
+#endif
+typedef Bits BitSet[BITSET_SIZE];
+typedef Bits* BitSetRef;
+
+#define SIZE_BITSET (int)sizeof(BitSet)
+
+#define BITSET_CLEAR(bs) do {\
+ int i;\
+ for (i = 0; i < (int )BITSET_SIZE; i++) { (bs)[i] = 0; } \
+} while (0)
+
+#define BS_ROOM(bs,pos) (bs)[pos / BITS_IN_ROOM]
+#define BS_BIT(pos) (1 << (pos % BITS_IN_ROOM))
+
+#define BITSET_AT(bs, pos) (BS_ROOM(bs,pos) & BS_BIT(pos))
+#define BITSET_SET_BIT(bs, pos) BS_ROOM(bs,pos) |= BS_BIT(pos)
+#define BITSET_CLEAR_BIT(bs, pos) BS_ROOM(bs,pos) &= ~(BS_BIT(pos))
+#define BITSET_INVERT_BIT(bs, pos) BS_ROOM(bs,pos) ^= BS_BIT(pos)
+
+/* bytes buffer */
+typedef struct _BBuf {
+ UChar* p;
+ unsigned int used;
+ unsigned int alloc;
+} BBuf;
+
+#define BBUF_INIT(buf,size) onig_bbuf_init((BBuf* )(buf), (size))
+
+#define BBUF_SIZE_INC(buf,inc) do{\
+ (buf)->alloc += (inc);\
+ (buf)->p = (UChar* )xrealloc((buf)->p, (buf)->alloc);\
+ if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
+} while (0)
+
+#define BBUF_EXPAND(buf,low) do{\
+ do { (buf)->alloc *= 2; } while ((buf)->alloc < (unsigned int )low);\
+ (buf)->p = (UChar* )xrealloc((buf)->p, (buf)->alloc);\
+ if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
+} while (0)
+
+#define BBUF_ENSURE_SIZE(buf,size) do{\
+ unsigned int new_alloc = (buf)->alloc;\
+ while (new_alloc < (unsigned int )(size)) { new_alloc *= 2; }\
+ if ((buf)->alloc != new_alloc) {\
+ (buf)->p = (UChar* )xrealloc((buf)->p, new_alloc);\
+ if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
+ (buf)->alloc = new_alloc;\
+ }\
+} while (0)
+
+#define BBUF_WRITE(buf,pos,bytes,n) do{\
+ int used = (pos) + (n);\
+ if ((buf)->alloc < (unsigned int )used) BBUF_EXPAND((buf),used);\
+ xmemcpy((buf)->p + (pos), (bytes), (n));\
+ if ((buf)->used < (unsigned int )used) (buf)->used = used;\
+} while (0)
+
+#define BBUF_WRITE1(buf,pos,byte) do{\
+ int used = (pos) + 1;\
+ if ((buf)->alloc < (unsigned int )used) BBUF_EXPAND((buf),used);\
+ (buf)->p[(pos)] = (byte);\
+ if ((buf)->used < (unsigned int )used) (buf)->used = used;\
+} while (0)
+
+#define BBUF_ADD(buf,bytes,n) BBUF_WRITE((buf),(buf)->used,(bytes),(n))
+#define BBUF_ADD1(buf,byte) BBUF_WRITE1((buf),(buf)->used,(byte))
+#define BBUF_GET_ADD_ADDRESS(buf) ((buf)->p + (buf)->used)
+#define BBUF_GET_OFFSET_POS(buf) ((buf)->used)
+
+/* from < to */
+#define BBUF_MOVE_RIGHT(buf,from,to,n) do {\
+ if ((unsigned int )((to)+(n)) > (buf)->alloc) BBUF_EXPAND((buf),(to) + (n));\
+ xmemmove((buf)->p + (to), (buf)->p + (from), (n));\
+ if ((unsigned int )((to)+(n)) > (buf)->used) (buf)->used = (to) + (n);\
+} while (0)
+
+/* from > to */
+#define BBUF_MOVE_LEFT(buf,from,to,n) do {\
+ xmemmove((buf)->p + (to), (buf)->p + (from), (n));\
+} while (0)
+
+/* from > to */
+#define BBUF_MOVE_LEFT_REDUCE(buf,from,to) do {\
+ xmemmove((buf)->p + (to), (buf)->p + (from), (buf)->used - (from));\
+ (buf)->used -= (from - to);\
+} while (0)
+
+#define BBUF_INSERT(buf,pos,bytes,n) do {\
+ if (pos >= (buf)->used) {\
+ BBUF_WRITE(buf,pos,bytes,n);\
+ }\
+ else {\
+ BBUF_MOVE_RIGHT((buf),(pos),(pos) + (n),((buf)->used - (pos)));\
+ xmemcpy((buf)->p + (pos), (bytes), (n));\
+ }\
+} while (0)
+
+#define BBUF_GET_BYTE(buf, pos) (buf)->p[(pos)]
+
+
+#define ANCHOR_BEGIN_BUF (1<<0)
+#define ANCHOR_BEGIN_LINE (1<<1)
+#define ANCHOR_BEGIN_POSITION (1<<2)
+#define ANCHOR_END_BUF (1<<3)
+#define ANCHOR_SEMI_END_BUF (1<<4)
+#define ANCHOR_END_LINE (1<<5)
+
+#define ANCHOR_WORD_BOUND (1<<6)
+#define ANCHOR_NOT_WORD_BOUND (1<<7)
+#define ANCHOR_WORD_BEGIN (1<<8)
+#define ANCHOR_WORD_END (1<<9)
+#define ANCHOR_PREC_READ (1<<10)
+#define ANCHOR_PREC_READ_NOT (1<<11)
+#define ANCHOR_LOOK_BEHIND (1<<12)
+#define ANCHOR_LOOK_BEHIND_NOT (1<<13)
+
+#define ANCHOR_ANYCHAR_STAR (1<<14) /* ".*" optimize info */
+#define ANCHOR_ANYCHAR_STAR_ML (1<<15) /* ".*" optimize info (multi-line) */
+
+/* operation code */
+enum OpCode {
+ OP_FINISH = 0, /* matching process terminator (no more alternative) */
+ OP_END = 1, /* pattern code terminator (success end) */
+
+ OP_EXACT1 = 2, /* single byte, N = 1 */
+ OP_EXACT2, /* single byte, N = 2 */
+ OP_EXACT3, /* single byte, N = 3 */
+ OP_EXACT4, /* single byte, N = 4 */
+ OP_EXACT5, /* single byte, N = 5 */
+ OP_EXACTN, /* single byte */
+ OP_EXACTMB2N1, /* mb-length = 2 N = 1 */
+ OP_EXACTMB2N2, /* mb-length = 2 N = 2 */
+ OP_EXACTMB2N3, /* mb-length = 2 N = 3 */
+ OP_EXACTMB2N, /* mb-length = 2 */
+ OP_EXACTMB3N, /* mb-length = 3 */
+ OP_EXACTMBN, /* other length */
+
+ OP_EXACT1_IC, /* single byte, N = 1, ignore case */
+ OP_EXACTN_IC, /* single byte, ignore case */
+
+ OP_CCLASS,
+ OP_CCLASS_MB,
+ OP_CCLASS_MIX,
+ OP_CCLASS_NOT,
+ OP_CCLASS_MB_NOT,
+ OP_CCLASS_MIX_NOT,
+ OP_CCLASS_NODE, /* pointer to CClassNode node */
+
+ OP_ANYCHAR, /* "." */
+ OP_ANYCHAR_ML, /* "." multi-line */
+ OP_ANYCHAR_STAR, /* ".*" */
+ OP_ANYCHAR_ML_STAR, /* ".*" multi-line */
+ OP_ANYCHAR_STAR_PEEK_NEXT,
+ OP_ANYCHAR_ML_STAR_PEEK_NEXT,
+
+ OP_WORD,
+ OP_NOT_WORD,
+ OP_WORD_BOUND,
+ OP_NOT_WORD_BOUND,
+ OP_WORD_BEGIN,
+ OP_WORD_END,
+
+ OP_BEGIN_BUF,
+ OP_END_BUF,
+ OP_BEGIN_LINE,
+ OP_END_LINE,
+ OP_SEMI_END_BUF,
+ OP_BEGIN_POSITION,
+
+ OP_BACKREF1,
+ OP_BACKREF2,
+ OP_BACKREFN,
+ OP_BACKREFN_IC,
+ OP_BACKREF_MULTI,
+ OP_BACKREF_MULTI_IC,
+ OP_BACKREF_WITH_LEVEL, /* \k<xxx+n>, \k<xxx-n> */
+
+ OP_MEMORY_START,
+ OP_MEMORY_START_PUSH, /* push back-tracker to stack */
+ OP_MEMORY_END_PUSH, /* push back-tracker to stack */
+ OP_MEMORY_END_PUSH_REC, /* push back-tracker to stack */
+ OP_MEMORY_END,
+ OP_MEMORY_END_REC, /* push marker to stack */
+
+ OP_FAIL, /* pop stack and move */
+ OP_JUMP,
+ OP_PUSH,
+ OP_POP,
+ OP_PUSH_OR_JUMP_EXACT1, /* if match exact then push, else jump. */
+ OP_PUSH_IF_PEEK_NEXT, /* if match exact then push, else none. */
+ OP_REPEAT, /* {n,m} */
+ OP_REPEAT_NG, /* {n,m}? (non greedy) */
+ OP_REPEAT_INC,
+ OP_REPEAT_INC_NG, /* non greedy */
+ OP_REPEAT_INC_SG, /* search and get in stack */