looksee 1.0.0-universal-java-1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/CHANGELOG +14 -0
  2. data/LICENSE +22 -0
  3. data/README.markdown +161 -0
  4. data/Rakefile +10 -0
  5. data/ext/extconf.rb +9 -0
  6. data/ext/mri/1.9.2/debug.h +36 -0
  7. data/ext/mri/1.9.2/id.h +170 -0
  8. data/ext/mri/1.9.2/method.h +103 -0
  9. data/ext/mri/1.9.2/node.h +483 -0
  10. data/ext/mri/1.9.2/thread_pthread.h +27 -0
  11. data/ext/mri/1.9.2/vm_core.h +707 -0
  12. data/ext/mri/1.9.2/vm_opts.h +51 -0
  13. data/ext/mri/env-1.8.h +27 -0
  14. data/ext/mri/eval_c-1.8.h +27 -0
  15. data/ext/mri/mri.c +269 -0
  16. data/ext/mri/node-1.9.h +35 -0
  17. data/ext/rbx/rbx.c +13 -0
  18. data/lib/looksee.rb +5 -0
  19. data/lib/looksee/adapter.rb +10 -0
  20. data/lib/looksee/adapter/base.rb +100 -0
  21. data/lib/looksee/adapter/rubinius.rb +73 -0
  22. data/lib/looksee/clean.rb +122 -0
  23. data/lib/looksee/columnizer.rb +73 -0
  24. data/lib/looksee/core_ext.rb +59 -0
  25. data/lib/looksee/editor.rb +58 -0
  26. data/lib/looksee/help.rb +54 -0
  27. data/lib/looksee/inspector.rb +55 -0
  28. data/lib/looksee/jruby.jar +0 -0
  29. data/lib/looksee/lookup_path.rb +95 -0
  30. data/lib/looksee/rbx.bundle +0 -0
  31. data/lib/looksee/shortcuts.rb +3 -0
  32. data/lib/looksee/version.rb +11 -0
  33. data/lib/looksee/wirble_compatibility.rb +86 -0
  34. data/spec/adapter_spec.rb +546 -0
  35. data/spec/columnizer_spec.rb +52 -0
  36. data/spec/core_ext_spec.rb +41 -0
  37. data/spec/editor_spec.rb +128 -0
  38. data/spec/inspector_spec.rb +178 -0
  39. data/spec/lookup_path_spec.rb +84 -0
  40. data/spec/spec_helper.rb +25 -0
  41. data/spec/support/core_ext.rb +25 -0
  42. data/spec/support/temporary_classes.rb +102 -0
  43. data/spec/support/test_adapter.rb +72 -0
  44. data/spec/wirble_compatibility_spec.rb +116 -0
  45. metadata +158 -0
@@ -0,0 +1,51 @@
1
+ /*-*-c-*-*/
2
+ /**********************************************************************
3
+
4
+ vm_opts.h - VM optimize option
5
+
6
+ $Author: akr $
7
+
8
+ Copyright (C) 2004-2007 Koichi Sasada
9
+
10
+ **********************************************************************/
11
+
12
+
13
+ #ifndef RUBY_VM_OPTS_H
14
+ #define RUBY_VM_OPTS_H
15
+
16
+ /* Compile options.
17
+ * You can change these options at runtime by VM::CompileOption.
18
+ * Following definitions are default values.
19
+ */
20
+
21
+ #define OPT_TRACE_INSTRUCTION 1
22
+ #define OPT_TAILCALL_OPTIMIZATION 0
23
+ #define OPT_PEEPHOLE_OPTIMIZATION 1
24
+ #define OPT_SPECIALISED_INSTRUCTION 1
25
+ #define OPT_INLINE_CONST_CACHE 1
26
+
27
+
28
+ /* Build Options.
29
+ * You can't change these options at runtime.
30
+ */
31
+
32
+ /* C compiler depend */
33
+ #define OPT_DIRECT_THREADED_CODE 1
34
+ #define OPT_TOKEN_THREADED_CODE 0
35
+ #define OPT_CALL_THREADED_CODE 0
36
+
37
+ /* VM running option */
38
+ #define OPT_CHECKED_RUN 1
39
+ #define OPT_INLINE_METHOD_CACHE 1
40
+ #define OPT_BLOCKINLINING 0
41
+
42
+ /* architecture independent, affects generated code */
43
+ #define OPT_OPERANDS_UNIFICATION 0
44
+ #define OPT_INSTRUCTIONS_UNIFICATION 0
45
+ #define OPT_UNIFY_ALL_COMBINATION 0
46
+ #define OPT_STACK_CACHING 0
47
+
48
+ /* misc */
49
+ #define SUPPORT_JOKE 0
50
+
51
+ #endif /* RUBY_VM_OPTS_H */
data/ext/mri/env-1.8.h ADDED
@@ -0,0 +1,27 @@
1
+ struct FRAME {
2
+ VALUE self;
3
+ int argc;
4
+ ID last_func;
5
+ ID orig_func;
6
+ VALUE last_class;
7
+ struct FRAME *prev;
8
+ struct FRAME *tmp;
9
+ struct RNode *node;
10
+ int iter;
11
+ int flags;
12
+ unsigned long uniq;
13
+ };
14
+
15
+ struct SCOPE {
16
+ struct RBasic super;
17
+ ID *local_tbl;
18
+ VALUE *local_vars;
19
+ int flags;
20
+ };
21
+
22
+ struct RVarmap {
23
+ struct RBasic super;
24
+ ID id;
25
+ VALUE val;
26
+ struct RVarmap *next;
27
+ };
@@ -0,0 +1,27 @@
1
+ struct BLOCK {
2
+ NODE *var;
3
+ NODE *body;
4
+ VALUE self;
5
+ struct FRAME frame;
6
+ struct SCOPE *scope;
7
+ VALUE klass;
8
+ NODE *cref;
9
+ int iter;
10
+ int vmode;
11
+ int flags;
12
+ int uniq;
13
+ struct RVarmap *dyna_vars;
14
+ VALUE orig_thread;
15
+ VALUE wrapper;
16
+ VALUE block_obj;
17
+ struct BLOCK *outer;
18
+ struct BLOCK *prev;
19
+ };
20
+
21
+ struct METHOD {
22
+ VALUE klass, rklass;
23
+ VALUE recv;
24
+ ID id, oid;
25
+ int safe_level;
26
+ NODE *body;
27
+ };
data/ext/mri/mri.c ADDED
@@ -0,0 +1,269 @@
1
+ #include "ruby.h"
2
+
3
+ #if RUBY_VERSION >= 192
4
+ # include "vm_core.h"
5
+ # include "method.h"
6
+ # include "ruby/st.h"
7
+ #elif RUBY_VERSION >= 190
8
+ # include "node-1.9.h"
9
+ # include "ruby/st.h"
10
+ #else
11
+ # include "node.h"
12
+ # include "st.h"
13
+ #endif
14
+
15
+ #if RUBY_VERSION < 187
16
+ # define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl)
17
+ # define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
18
+ # define RCLASS_SUPER(c) (RCLASS(c)->super)
19
+ #endif
20
+
21
+ /*
22
+ * Return the internal superclass of this class.
23
+ *
24
+ * This is either a Class or "IClass." IClasses represent Modules
25
+ * included in the ancestry, and should be treated as opaque objects
26
+ * in ruby space. Convert the IClass to a Module using #iclass_to_module
27
+ * before using it in ruby.
28
+ */
29
+ VALUE Looksee_internal_superclass(VALUE self, VALUE internal_class) {
30
+ VALUE super = RCLASS_SUPER(internal_class);
31
+ if (!super)
32
+ return Qnil;
33
+ return super;
34
+ }
35
+
36
+ /*
37
+ * Return the internal class of the given object.
38
+ *
39
+ * This is either the object's singleton class, if it exists, or the
40
+ * object's birth class.
41
+ */
42
+ VALUE Looksee_internal_class(VALUE self, VALUE object) {
43
+ return CLASS_OF(object);
44
+ }
45
+
46
+ /*
47
+ * Return the class or module that the given internal class
48
+ * represents.
49
+ *
50
+ * If a class is given, this is the class. If an iclass is given,
51
+ * this is the module it represents in the lookup chain.
52
+ */
53
+ VALUE Looksee_internal_class_to_module(VALUE self, VALUE internal_class) {
54
+ if (!SPECIAL_CONST_P(internal_class)) {
55
+ switch (BUILTIN_TYPE(internal_class)) {
56
+ case T_ICLASS:
57
+ return RBASIC(internal_class)->klass;
58
+ case T_CLASS:
59
+ return internal_class;
60
+ }
61
+ }
62
+ rb_raise(rb_eArgError, "not an internal class: %s", RSTRING_PTR(rb_inspect(internal_class)));
63
+ }
64
+
65
+ #if RUBY_VERSION >= 192
66
+
67
+ # define VISIBILITY_TYPE rb_method_flag_t
68
+
69
+ typedef struct add_method_if_matching_arg {
70
+ VALUE names;
71
+ VISIBILITY_TYPE visibility;
72
+ } add_method_if_matching_arg_t;
73
+
74
+ static int add_method_if_matching(ID method_name, rb_method_entry_t *me, add_method_if_matching_arg_t *arg) {
75
+ if (method_name == ID_ALLOCATOR)
76
+ return ST_CONTINUE;
77
+
78
+ if (UNDEFINED_METHOD_ENTRY_P(me))
79
+ return ST_CONTINUE;
80
+
81
+ if ((me->flag & NOEX_MASK) == arg->visibility)
82
+ rb_ary_push(arg->names, ID2SYM(method_name));
83
+
84
+ return ST_CONTINUE;
85
+ }
86
+
87
+ static int add_method_if_undefined(ID method_name, rb_method_entry_t *me, VALUE *names) {
88
+ if (UNDEFINED_METHOD_ENTRY_P(me))
89
+ rb_ary_push(*names, ID2SYM(method_name));
90
+ return ST_CONTINUE;
91
+ }
92
+
93
+ #else
94
+
95
+ # if RUBY_VERSION >= 190
96
+ # define VISIBILITY(node) ((node)->nd_body->nd_noex & NOEX_MASK)
97
+ # else
98
+ # define VISIBILITY(node) ((node)->nd_noex & NOEX_MASK)
99
+ # endif
100
+
101
+ # define VISIBILITY_TYPE unsigned long
102
+
103
+ typedef struct add_method_if_matching_arg {
104
+ VALUE names;
105
+ VISIBILITY_TYPE visibility;
106
+ } add_method_if_matching_arg_t;
107
+
108
+ static int add_method_if_matching(ID method_name, NODE *body, add_method_if_matching_arg_t *arg) {
109
+ /* This entry is for the internal allocator function. */
110
+ if (method_name == ID_ALLOCATOR)
111
+ return ST_CONTINUE;
112
+
113
+ /* Module#undef_method:
114
+ * * sets body->nd_body to NULL in ruby <= 1.8
115
+ * * sets body to NULL in ruby >= 1.9
116
+ */
117
+ if (!body || !body->nd_body)
118
+ return ST_CONTINUE;
119
+
120
+ if (VISIBILITY(body) == arg->visibility)
121
+ rb_ary_push(arg->names, ID2SYM(method_name));
122
+ return ST_CONTINUE;
123
+ }
124
+
125
+ static int add_method_if_undefined(ID method_name, NODE *body, VALUE *names) {
126
+ if (!body || !body->nd_body)
127
+ rb_ary_push(*names, ID2SYM(method_name));
128
+ return ST_CONTINUE;
129
+ }
130
+
131
+ #endif
132
+
133
+ static VALUE internal_instance_methods(VALUE klass, VISIBILITY_TYPE visibility) {
134
+ add_method_if_matching_arg_t arg;
135
+ arg.names = rb_ary_new();
136
+ arg.visibility = visibility;
137
+ st_foreach(RCLASS_M_TBL(klass), add_method_if_matching, (st_data_t)&arg);
138
+ return arg.names;
139
+ }
140
+
141
+ /*
142
+ * Return the list of public instance methods (as Symbols) of the
143
+ * given internal class.
144
+ */
145
+ VALUE Looksee_internal_public_instance_methods(VALUE self, VALUE klass) {
146
+ return internal_instance_methods(klass, NOEX_PUBLIC);
147
+ }
148
+
149
+ /*
150
+ * Return the list of protected instance methods (as Symbols) of the
151
+ * given internal class.
152
+ */
153
+ VALUE Looksee_internal_protected_instance_methods(VALUE self, VALUE klass) {
154
+ return internal_instance_methods(klass, NOEX_PROTECTED);
155
+ }
156
+
157
+ /*
158
+ * Return the list of private instance methods (as Symbols) of the
159
+ * given internal class.
160
+ */
161
+ VALUE Looksee_internal_private_instance_methods(VALUE self, VALUE klass) {
162
+ return internal_instance_methods(klass, NOEX_PRIVATE);
163
+ }
164
+
165
+ /*
166
+ * Return the list of undefined instance methods (as Symbols) of the
167
+ * given internal class.
168
+ */
169
+ VALUE Looksee_internal_undefined_instance_methods(VALUE self, VALUE klass) {
170
+ VALUE names = rb_ary_new();
171
+ st_foreach(RCLASS_M_TBL(klass), add_method_if_undefined, (st_data_t)&names);
172
+ return names;
173
+ }
174
+
175
+ VALUE Looksee_singleton_class_p(VALUE self, VALUE object) {
176
+ return BUILTIN_TYPE(object) == T_CLASS && FL_TEST(object, FL_SINGLETON) ? Qtrue : Qfalse;
177
+ }
178
+
179
+ VALUE Looksee_singleton_instance(VALUE self, VALUE singleton_class) {
180
+ if (BUILTIN_TYPE(singleton_class) == T_CLASS && FL_TEST(singleton_class, FL_SINGLETON)) {
181
+ VALUE object;
182
+ if (!st_lookup(RCLASS_IV_TBL(singleton_class), rb_intern("__attached__"), (st_data_t *)&object))
183
+ rb_raise(rb_eRuntimeError, "[looksee bug] can't find singleton object");
184
+ return object;
185
+ } else {
186
+ rb_raise(rb_eTypeError, "expected singleton class, got %s", rb_obj_classname(singleton_class));
187
+ }
188
+ }
189
+
190
+ VALUE Looksee_module_name(VALUE self, VALUE module) {
191
+ if (BUILTIN_TYPE(module) == T_CLASS || BUILTIN_TYPE(module) == T_MODULE) {
192
+ VALUE name = rb_mod_name(module);
193
+ return name == Qnil ? rb_str_new2("") : name;
194
+ } else {
195
+ rb_raise(rb_eTypeError, "expected module, got %s", rb_obj_classname(module));
196
+ }
197
+ }
198
+
199
+ #if RUBY_VERSION < 190
200
+
201
+ #include "env-1.8.h"
202
+ #include "eval_c-1.8.h"
203
+
204
+ /*
205
+ * Return the source file and line number of the given object and method.
206
+ */
207
+ VALUE Looksee_source_location(VALUE self, VALUE unbound_method) {
208
+ if (!rb_obj_is_kind_of(unbound_method, rb_cUnboundMethod))
209
+ rb_raise(rb_eTypeError, "expected UnboundMethod, got %s", rb_obj_classname(unbound_method));
210
+
211
+ struct METHOD *method;
212
+ Data_Get_Struct(unbound_method, struct METHOD, method);
213
+
214
+ NODE *node;
215
+ switch (nd_type(method->body)) {
216
+ // Can't be a FBODY or ZSUPER.
217
+ case NODE_SCOPE:
218
+ node = method->body->nd_defn;
219
+ break;
220
+ case NODE_BMETHOD:
221
+ {
222
+ struct BLOCK *block;
223
+ Data_Get_Struct(method->body->nd_orig, struct BLOCK, block);
224
+ (node = block->frame.node) || (node = block->body);
225
+ // Proc#to_s suggests this may be NULL sometimes.
226
+ if (!node)
227
+ return Qnil;
228
+ }
229
+ break;
230
+ case NODE_DMETHOD:
231
+ {
232
+ struct METHOD *original_method;
233
+ NODE *body = method->body;
234
+ Data_Get_Struct(body->nd_orig, struct METHOD, original_method);
235
+ node = original_method->body->nd_defn;
236
+ }
237
+ break;
238
+ default:
239
+ rb_raise(rb_eRuntimeError, "[LOOKSEE BUG] unexpected NODE type: %d", nd_type(method->body));
240
+ }
241
+ VALUE file = rb_str_new2(node->nd_file);
242
+ VALUE line = INT2NUM(nd_line(node));
243
+ VALUE location = rb_ary_new2(2);
244
+ rb_ary_store(location, 0, file);
245
+ rb_ary_store(location, 1, line);
246
+ return location;
247
+ }
248
+
249
+ #endif
250
+
251
+ void Init_mri(void) {
252
+ VALUE mLooksee = rb_const_get(rb_cObject, rb_intern("Looksee"));
253
+ VALUE mAdapter = rb_const_get(mLooksee, rb_intern("Adapter"));
254
+ VALUE mBase = rb_const_get(mAdapter, rb_intern("Base"));
255
+ VALUE mMRI = rb_define_class_under(mAdapter, "MRI", mBase);
256
+ rb_define_method(mMRI, "internal_superclass", Looksee_internal_superclass, 1);
257
+ rb_define_method(mMRI, "internal_class", Looksee_internal_class, 1);
258
+ rb_define_method(mMRI, "internal_class_to_module", Looksee_internal_class_to_module, 1);
259
+ rb_define_method(mMRI, "internal_public_instance_methods", Looksee_internal_public_instance_methods, 1);
260
+ rb_define_method(mMRI, "internal_protected_instance_methods", Looksee_internal_protected_instance_methods, 1);
261
+ rb_define_method(mMRI, "internal_private_instance_methods", Looksee_internal_private_instance_methods, 1);
262
+ rb_define_method(mMRI, "internal_undefined_instance_methods", Looksee_internal_undefined_instance_methods, 1);
263
+ rb_define_method(mMRI, "singleton_class?", Looksee_singleton_class_p, 1);
264
+ rb_define_method(mMRI, "singleton_instance", Looksee_singleton_instance, 1);
265
+ rb_define_method(mMRI, "module_name", Looksee_module_name, 1);
266
+ #if RUBY_VERSION < 190
267
+ rb_define_method(mMRI, "source_location", Looksee_source_location, 1);
268
+ #endif
269
+ }
@@ -0,0 +1,35 @@
1
+ /* MRI 1.9 does not install node.h. This is the part we need. */
2
+
3
+ typedef struct RNode {
4
+ unsigned long flags;
5
+ char *nd_file;
6
+ union {
7
+ struct RNode *node;
8
+ ID id;
9
+ VALUE value;
10
+ VALUE (*cfunc)(ANYARGS);
11
+ ID *tbl;
12
+ } u1;
13
+ union {
14
+ struct RNode *node;
15
+ ID id;
16
+ long argc;
17
+ VALUE value;
18
+ } u2;
19
+ union {
20
+ struct RNode *node;
21
+ ID id;
22
+ long state;
23
+ struct global_entry *entry;
24
+ long cnt;
25
+ VALUE value;
26
+ } u3;
27
+ } NODE;
28
+
29
+ #define nd_body u2.node
30
+ #define nd_noex u3.id
31
+
32
+ #define NOEX_PUBLIC 0x00
33
+ #define NOEX_PRIVATE 0x02
34
+ #define NOEX_PROTECTED 0x04
35
+ #define NOEX_MASK 0x06
data/ext/rbx/rbx.c ADDED
@@ -0,0 +1,13 @@
1
+ #include "ruby.h"
2
+
3
+ VALUE Looksee_internal_class(VALUE self, VALUE object) {
4
+ return CLASS_OF(object);
5
+ }
6
+
7
+ void Init_rbx(void) {
8
+ VALUE mLooksee = rb_const_get(rb_cObject, rb_intern("Looksee"));
9
+ VALUE mAdapter = rb_const_get(mLooksee, rb_intern("Adapter"));
10
+ VALUE mBase = rb_const_get(mAdapter, rb_intern("Base"));
11
+ VALUE mRubinius = rb_define_class_under(mAdapter, "Rubinius", mBase);
12
+ rb_define_method(mRubinius, "internal_class", Looksee_internal_class, 1);
13
+ }
data/lib/looksee.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'looksee/clean'
2
+ require 'looksee/core_ext'
3
+
4
+ # Ugh.
5
+ Looksee::WirbleCompatibility.init
@@ -0,0 +1,10 @@
1
+ require 'rbconfig'
2
+
3
+ module Looksee
4
+ module Adapter
5
+ autoload :Base, 'looksee/adapter/base'
6
+ autoload :MRI, "looksee/mri.#{Config::CONFIG['DLEXT']}"
7
+ autoload :JRuby, 'looksee/JRuby.jar'
8
+ autoload :Rubinius, "looksee/adapter/rubinius"
9
+ end
10
+ end