sydparse 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt ADDED
@@ -0,0 +1,26 @@
1
+ env.h
2
+ extconf.rb
3
+ internal.h
4
+ lex.c.tab
5
+ lib
6
+ bin/syd_pt_show
7
+ lib/sydparse
8
+ lib/sydparse.rb
9
+ Manifest.txt
10
+ node.h
11
+ parse_override.h
12
+ Rakefile
13
+ runtime.c
14
+ runtime.h
15
+ state.h
16
+ sydparse.c
17
+ sydparse.y
18
+ test
19
+ test/class.rb
20
+ test/pt.rb
21
+ test/show.rb
22
+ test/t.rb
23
+ test/t3.rb
24
+ test/t4.rb
25
+ test/test.rb
26
+ test/ubs.rb
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/gempackagetask'
4
+
5
+ $VERBOSE = nil
6
+
7
+ spec = Gem::Specification.new do |s|
8
+ s.name = 'sydparse'
9
+ s.version = '1.0.0'
10
+ s.summary = 'A standalone ruby parser with sexp support.'
11
+ s.author = 'Evan Webb'
12
+ s.email = 'evan@fallingsnow.net'
13
+
14
+ s.has_rdoc = true
15
+ s.files = File.read('Manifest.txt').split($/)
16
+ s.require_path = 'lib'
17
+ s.executables = ['syd_pt_show']
18
+ s.default_executable = ''
19
+ s.extensions = ['extconf.rb']
20
+ end
21
+
22
+ desc 'Build Gem'
23
+ Rake::GemPackageTask.new spec do |pkg|
24
+ pkg.need_tar = true
25
+ end
26
+
27
+ desc 'Clean up'
28
+ task :clean => [ :clobber_package ]
29
+
30
+ desc 'Clean up'
31
+ task :clobber => [ :clean ]
32
+
33
+ # vim: syntax=Ruby
34
+
data/bin/syd_pt_show ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'sydparse'
5
+ require 'pp'
6
+
7
+ if ARGV.first == "-l"
8
+ newlines = true
9
+ ARGV.shift
10
+ elsif ARGV.first == "-u"
11
+ unified = true
12
+ ARGV.shift
13
+ end
14
+
15
+ name = ARGV.shift
16
+ File.open(name, "r") do |fd|
17
+ if unified
18
+ pp SydneyParser.unified_sexp(fd)
19
+ else
20
+ syd = SydneyParser.load_file fd
21
+ pp syd.sexp(false, newlines)
22
+ end
23
+ end
data/env.h ADDED
@@ -0,0 +1,66 @@
1
+ /**********************************************************************
2
+
3
+ env.h -
4
+
5
+ $Author: matz $
6
+ $Date: 2003/10/20 08:33:48 $
7
+ created at: Mon Jul 11 11:53:03 JST 1994
8
+
9
+ Copyright (C) 1993-2003 Yukihiro Matsumoto
10
+
11
+ **********************************************************************/
12
+
13
+ #ifndef ENV_H
14
+ #define ENV_H
15
+
16
+ struct FRAME {
17
+ VALUE self;
18
+ int argc;
19
+ VALUE *argv;
20
+ ID last_func;
21
+ ID orig_func;
22
+ VALUE last_class;
23
+ struct FRAME *prev;
24
+ struct FRAME *tmp;
25
+ struct RNode *node;
26
+ int iter;
27
+ int flags;
28
+ unsigned long uniq;
29
+ struct SCOPE *scope;
30
+ VALUE metadata;
31
+ };
32
+
33
+ /*
34
+ // VALUE rb_cFrame;
35
+ // VALUE rb_cBacktrace;
36
+ // VALUE rb_cMain;
37
+ */
38
+ void rb_gc_mark_frame _((struct FRAME *));
39
+
40
+ #define FRAME_ALLOCA 0
41
+ #define FRAME_MALLOC 1
42
+
43
+ struct SCOPE {
44
+ struct RBasic super;
45
+ ID *local_tbl;
46
+ VALUE *local_vars;
47
+ int flags;
48
+ };
49
+
50
+ #define SCOPE_ALLOCA 0
51
+ #define SCOPE_MALLOC 1
52
+ #define SCOPE_NOSTACK 2
53
+ #define SCOPE_DONT_RECYCLE 4
54
+
55
+ /* extern int ruby_in_eval;
56
+
57
+ // extern VALUE ruby_class;
58
+ */
59
+ struct RVarmap {
60
+ struct RBasic super;
61
+ ID id;
62
+ VALUE val;
63
+ struct RVarmap *next;
64
+ };
65
+
66
+ #endif /* ENV_H */
data/extconf.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'rbconfig'
2
+ require 'mkmf'
3
+
4
+ create_makefile('sydney_parser')
5
+
6
+
7
+ File.open("Makefile","a+") do |f|
8
+ f << <<END
9
+ sydparse.c: sydparse.y
10
+ bison -o sydparse.c sydparse.y
11
+ END
12
+ end
data/internal.h ADDED
@@ -0,0 +1,716 @@
1
+ #ifndef __INTERNAL_H__
2
+ #define __INTERNAL_H__
3
+
4
+ #include "st.h"
5
+ #include "re.h"
6
+ #include "node.h"
7
+ #include "env.h"
8
+
9
+ struct gc_list {
10
+ VALUE *varptr;
11
+ struct gc_list *next;
12
+ };
13
+
14
+ struct global_entry {
15
+ struct global_variable *var;
16
+ ID id;
17
+ };
18
+
19
+
20
+ #undef GC_DEBUG
21
+ /* #define GC_DEBUG */
22
+
23
+ typedef struct RVALUE {
24
+ union {
25
+ struct {
26
+ unsigned long flags; /* always 0 for freed obj */
27
+ struct RVALUE *next;
28
+ } free;
29
+ struct RBasic basic;
30
+ struct RObject object;
31
+ struct RClass klass;
32
+ struct RFloat flonum;
33
+ struct RString string;
34
+ struct RArray array;
35
+ struct RRegexp regexp;
36
+ struct RHash hash;
37
+ struct RData data;
38
+ struct RStruct rstruct;
39
+ struct RBignum bignum;
40
+ struct RFile file;
41
+ struct RNode node;
42
+ struct RMatch match;
43
+ struct RVarmap varmap;
44
+ struct SCOPE scope;
45
+ } as;
46
+ #ifdef GC_DEBUG
47
+ char *file;
48
+ int line;
49
+ #endif
50
+ } RVALUE;
51
+
52
+ #define HEAP_MIN_SLOTS 10000
53
+
54
+ struct heaps_slot {
55
+ RVALUE *slot;
56
+ int limit;
57
+ };
58
+
59
+ #define MARK_STACK_MAX 1024
60
+
61
+ /* from eval.c */
62
+
63
+ struct cache_entry { /* method hash table. */
64
+ ID mid; /* method's id */
65
+ ID mid0; /* method's original id */
66
+ VALUE klass; /* receiver's class */
67
+ VALUE origin; /* where method defined */
68
+ NODE *method;
69
+ int noex;
70
+ };
71
+
72
+ #define CACHE_SIZE 0x800
73
+ #define CACHE_MASK 0x7ff
74
+ #define EXPR1(c,m) ((((c)>>3)^(m))&CACHE_MASK)
75
+
76
+ struct BLOCK {
77
+ NODE *var;
78
+ NODE *body;
79
+ VALUE self;
80
+ struct FRAME frame;
81
+ struct SCOPE *scope;
82
+ VALUE klass;
83
+ NODE *cref;
84
+ int iter;
85
+ int vmode;
86
+ int flags;
87
+ int uniq;
88
+ struct RVarmap *dyna_vars;
89
+ VALUE orig_thread;
90
+ VALUE wrapper;
91
+ VALUE block_obj;
92
+ struct BLOCK *outer;
93
+ struct BLOCK *prev;
94
+ };
95
+
96
+ struct iter {
97
+ int iter;
98
+ struct iter *prev;
99
+ };
100
+
101
+
102
+ #define ITER_NOT 0
103
+ #define ITER_PRE 1
104
+ #define ITER_CUR 2
105
+
106
+ #define PUSH_ITER(i) do { \
107
+ struct iter _iter; \
108
+ _iter.prev = ruby_iter; \
109
+ _iter.iter = (i); \
110
+ ruby_iter = &_iter
111
+
112
+ #define POP_ITER() \
113
+ ruby_iter = _iter.prev; \
114
+ } while (0)
115
+
116
+ #define CSTAT_PRIV 1
117
+ #define CSTAT_PROT 2
118
+ #define CSTAT_VCALL 4
119
+ #define CSTAT_SUPER 8
120
+
121
+ #define BLOCK_D_SCOPE 1
122
+ #define BLOCK_LAMBDA 2
123
+
124
+ #define PUSH_BLOCK(v,b) do { \
125
+ struct BLOCK _block; \
126
+ _block.var = (v); \
127
+ _block.body = (b); \
128
+ _block.self = self; \
129
+ _block.frame = *ruby_frame; \
130
+ _block.klass = ruby_class; \
131
+ _block.cref = ruby_cref; \
132
+ _block.frame.node = ruby_current_node;\
133
+ _block.scope = ruby_scope; \
134
+ _block.prev = ruby_block; \
135
+ _block.outer = ruby_block; \
136
+ _block.iter = ruby_iter->iter; \
137
+ _block.vmode = scope_vmode; \
138
+ _block.flags = BLOCK_D_SCOPE; \
139
+ _block.dyna_vars = ruby_dyna_vars; \
140
+ _block.wrapper = ruby_wrapper; \
141
+ _block.block_obj = 0; \
142
+ _block.uniq = (b)?block_unique++:0; \
143
+ if (b) { \
144
+ prot_tag->blkid = _block.uniq; \
145
+ } \
146
+ ruby_block = &_block
147
+
148
+ #define POP_BLOCK() \
149
+ ruby_block = _block.prev; \
150
+ } while (0)
151
+
152
+ /* eval.c */
153
+ #if defined(HAVE_GETCONTEXT) && defined(HAVE_SETCONTEXT)
154
+
155
+ #include <signal.h>
156
+ #include <ucontext.h>
157
+ typedef struct {
158
+ ucontext_t context;
159
+ volatile int status;
160
+ } rb_jmpbuf_t[1];
161
+ #else
162
+ #include <setjmp.h>
163
+ typedef jmp_buf rb_jmpbuf_t;
164
+ #endif
165
+
166
+ struct tag {
167
+ rb_jmpbuf_t buf;
168
+ struct FRAME *frame;
169
+ struct iter *iter;
170
+ VALUE tag;
171
+ VALUE retval;
172
+ struct SCOPE *scope;
173
+ VALUE dst;
174
+ struct tag *prev;
175
+ int blkid;
176
+ };
177
+
178
+ typedef struct thread * rb_thread_t;
179
+
180
+ #ifndef MAXPATHLEN
181
+ # define MAXPATHLEN 1024
182
+ #endif
183
+
184
+ struct end_proc_data {
185
+ void (*func)();
186
+ VALUE data;
187
+ int safe;
188
+ struct end_proc_data *next;
189
+ };
190
+
191
+ struct local_vars {
192
+ ID *tbl;
193
+ int nofree;
194
+ int cnt;
195
+ int dlev;
196
+ struct RVarmap* dyna_vars;
197
+ struct local_vars *prev;
198
+ };
199
+
200
+ #include <signal.h>
201
+ #ifdef __BEOS__
202
+ #undef SIGBUS
203
+ #endif
204
+
205
+ #ifndef NSIG
206
+ # ifdef DJGPP
207
+ # define NSIG SIGMAX
208
+ # else
209
+ # define NSIG (_SIGMAX + 1) /* For QNX */
210
+ # endif
211
+ #endif
212
+
213
+ struct trap_list_struct {
214
+ VALUE cmd;
215
+ int safe;
216
+ };
217
+
218
+ #ifndef GC_MALLOC_LIMIT
219
+ #if defined(MSDOS) || defined(__human68k__)
220
+ #define GC_MALLOC_LIMIT 200000
221
+ #else
222
+ #define GC_MALLOC_LIMIT 8000000
223
+ #endif
224
+ #endif
225
+
226
+ #ifdef _WIN32
227
+ typedef LONG rb_atomic_t;
228
+ #else
229
+ typedef int rb_atomic_t;
230
+ #endif
231
+
232
+ enum thread_status {
233
+ THREAD_TO_KILL,
234
+ THREAD_RUNNABLE,
235
+ THREAD_STOPPED,
236
+ THREAD_KILLED,
237
+ THREAD_RUNNING,
238
+ THREAD_GC,
239
+ THREAD_PAUSE
240
+ };
241
+ #define FOREACH_THREAD_FROM(f,x) x = f; do { x = x->next;
242
+ #define END_FOREACH_FROM(f,x) } while (x != f)
243
+
244
+ #define FOREACH_THREAD(x) FOREACH_THREAD_FROM(curr_thread,x)
245
+ #define END_FOREACH(x) END_FOREACH_FROM(curr_thread,x)
246
+
247
+ #define FOREACH_ARY(ary, val) do { \
248
+ int __foreach_idx; \
249
+ VALUE val; \
250
+ for(__foreach_idx = 0; __foreach_idx < RARRAY(ary)->len; __foreach_idx++) { \
251
+ val = RARRAY(ary)->ptr[__foreach_idx];
252
+ #define END_FOREACH_ARY } } while(0)
253
+
254
+ /* for fd_set, etc */
255
+ #include <sys/select.h>
256
+
257
+ struct thread {
258
+ struct thread *next, *prev;
259
+ rb_jmpbuf_t context;
260
+ #ifdef SAVE_WIN32_EXCEPTION_LIST
261
+ DWORD win32_exception_list;
262
+ #endif
263
+
264
+ VALUE result;
265
+
266
+ long stk_len;
267
+ long stk_max;
268
+ VALUE *stk_ptr;
269
+ VALUE *stk_pos;
270
+ #ifdef __ia64__
271
+ VALUE *bstr_ptr;
272
+ long bstr_len;
273
+ #endif
274
+
275
+ struct FRAME *frame;
276
+ struct SCOPE *scope;
277
+ struct RVarmap *dyna_vars;
278
+ struct BLOCK *block;
279
+ struct iter *iter;
280
+ struct tag *tag;
281
+ VALUE klass;
282
+ VALUE wrapper;
283
+ NODE *cref;
284
+
285
+ int flags; /* misc. states (vmode/rb_trap_immediate/raised) */
286
+
287
+ NODE *node;
288
+
289
+ int thl_tracing;
290
+ VALUE errinfo;
291
+ VALUE last_status;
292
+ VALUE last_line;
293
+ VALUE last_match;
294
+
295
+ int safe;
296
+
297
+ enum thread_status status;
298
+ int wait_for;
299
+ int fd;
300
+ fd_set readfds;
301
+ fd_set writefds;
302
+ fd_set exceptfds;
303
+ int select_value;
304
+ double delay;
305
+ rb_thread_t join;
306
+
307
+ int abort;
308
+ int priority;
309
+ VALUE thgroup;
310
+
311
+ st_table *locals;
312
+
313
+ VALUE thread;
314
+
315
+ VALUE (*schedule)();
316
+ };
317
+
318
+ #define THREAD_RAISED 0x200 /* temporary flag */
319
+ #define THREAD_TERMINATING 0x400 /* persistent flag */
320
+ #define THREAD_FLAGS_MASK 0x400 /* mask for persistent flags */
321
+
322
+
323
+ struct thread_status_t {
324
+ NODE *node;
325
+
326
+ int thl_tracing;
327
+ VALUE errinfo;
328
+ VALUE last_status;
329
+ VALUE last_line;
330
+ VALUE last_match;
331
+
332
+ int safe;
333
+
334
+ enum thread_status status;
335
+ int wait_for;
336
+ int fd;
337
+ fd_set readfds;
338
+ fd_set writefds;
339
+ fd_set exceptfds;
340
+ int select_value;
341
+ double delay;
342
+ rb_thread_t join;
343
+ };
344
+
345
+ struct gc_state {
346
+ int dont_gc;
347
+ int during_gc;
348
+ int need_call_final;
349
+ st_table *finalizer_table;
350
+ struct gc_list *global_List;
351
+ VALUE globals;
352
+ RVALUE *freelist;
353
+ RVALUE *deferred_final_list;
354
+ struct heaps_slot *heaps;
355
+ int heaps_length;
356
+ int heaps_used;
357
+ int heap_slots;
358
+ unsigned long num_objects;
359
+ RVALUE *gc_himem;
360
+ RVALUE *gc_lomem;
361
+ VALUE mark_stack[MARK_STACK_MAX];
362
+ VALUE *mark_stack_ptr;
363
+ int mark_stack_overflow;
364
+ st_table *source_filenames;
365
+ VALUE finalizers;
366
+ unsigned long malloc_increase;
367
+ unsigned long malloc_limit;
368
+ int grow_direction;
369
+ int memerror_recurse;
370
+
371
+ pthread_mutex_t lock;
372
+ pthread_t lock_owner;
373
+ pthread_mutex_t heap_modification;
374
+ };
375
+
376
+ struct lock_table_entry {
377
+ VALUE object;
378
+ };
379
+
380
+ typedef struct ruby_state {
381
+
382
+ int state;
383
+ char **environment;
384
+ int binmode;
385
+ VALUE signal_overriding;
386
+ int saved_group_id;
387
+ int saved_user_id;
388
+ int under_uid_switch;
389
+ int under_gid_switch;
390
+
391
+ VALUE time_struct;
392
+
393
+ int case_cache;
394
+ int kcode_cache;
395
+ int curr_kcode;
396
+ VALUE reg_cache;
397
+ int reg_kcode;
398
+ int ignorecase;
399
+ int reg_recompile_p;
400
+
401
+ struct re_registers reg_regs;
402
+
403
+ int uid;
404
+ int euid;
405
+ int gid;
406
+ int egid;
407
+
408
+ int original_argc;
409
+ char **original_argv;
410
+ int argv_len;
411
+ char *script;
412
+
413
+ /* from random.c */
414
+
415
+ int rand_init;
416
+ int rand_inc;
417
+ int rand_left;
418
+ int rand_initf;
419
+ unsigned long rand_state[624]; /* FIXME 624 is N from random.c */
420
+ unsigned long *rand_next;
421
+ unsigned long rand_saved_seed;
422
+
423
+ /* from pack.c */
424
+ int pack_b64_init;
425
+ int pack_b64_xtable[256];
426
+
427
+ /* from ruby.c */
428
+ VALUE progname;
429
+ VALUE argv;
430
+ VALUE argv0;
431
+ VALUE ruby_debug;
432
+ VALUE ruby_verbose;
433
+ int sflag;
434
+ int xflag;
435
+ VALUE do_loop;
436
+ VALUE do_print;
437
+ VALUE do_check;
438
+ VALUE do_line;
439
+ VALUE do_split;
440
+ VALUE init_requires;
441
+ int end_seen;
442
+
443
+ /* from gc.c */
444
+ VALUE *gc_stack_start;
445
+ st_table *rb_class_tbl;
446
+ VALUE nomem_error;
447
+
448
+ struct gc_state *gc;
449
+ VALUE gc_start_hook;
450
+
451
+ /* from eval.c */
452
+ char **original_environ;
453
+ int initialized;
454
+ int ruby_in_compile;
455
+ int scope_vmode;
456
+ NODE *ruby_current_node;
457
+ int safe_level;
458
+ struct cache_entry cache[CACHE_SIZE];
459
+ int cache_hits;
460
+ int cache_misses;
461
+ int ruby_running;
462
+ struct FRAME initial_frame;
463
+ struct FRAME *frames;
464
+ struct SCOPE *ruby_scope;
465
+ struct FRAME *top_frame;
466
+ struct SCOPE *top_scope;
467
+ VALUE ruby_top_self;
468
+ unsigned long frame_unique;
469
+
470
+ struct BLOCK *ruby_block;
471
+ unsigned long block_unique;
472
+
473
+ struct RVarmap *ruby_dyna_vars;
474
+ struct iter initial_iter;
475
+ struct iter *ruby_iter;
476
+ struct tag *prot_tag;
477
+
478
+ VALUE ruby_class;
479
+ VALUE ruby_wrapper;
480
+
481
+ NODE *ruby_cref;
482
+ NODE *top_cref;
483
+ rb_thread_t current_thread;
484
+ rb_thread_t main_thread;
485
+
486
+ VALUE trace_func;
487
+ int tracing;
488
+
489
+ pthread_t primary_thid;
490
+
491
+ int ruby_in_eval;
492
+ VALUE rb_load_path;
493
+ VALUE ruby_dln_librefs;
494
+ VALUE rb_features;
495
+ st_table *loading_tbl;
496
+
497
+ int thread_pending;
498
+ VALUE th_raise_exception;
499
+ NODE *th_raise_node;
500
+ VALUE th_cmd;
501
+ int th_sig, th_safe;
502
+ char *th_signm;
503
+ int thread_init;
504
+ #if defined(_THREAD_SAFE)
505
+ pthread_t time_thread;
506
+ #endif
507
+ int thread_critical;
508
+ int prohibit_interrupt;
509
+ int exception_interrupt;
510
+ int trap_pending;
511
+ int trap_immediate;
512
+ VALUE cont_protect;
513
+
514
+ VALUE ruby_errinfo;
515
+ VALUE ruby_errhandler;
516
+ NODE *ruby_eval_tree_begin;
517
+ NODE *ruby_eval_tree;
518
+ int ruby_nerrs;
519
+
520
+ VALUE cObject;
521
+ VALUE cClass;
522
+ VALUE cModule;
523
+ VALUE output_field_seperator;
524
+ VALUE record_seperator;
525
+ VALUE default_record_seperator;
526
+ VALUE output_record_seperator;
527
+ VALUE ruby_stderr;
528
+ VALUE ruby_stdin;
529
+ VALUE ruby_stdout;
530
+ VALUE ruby_deferr;
531
+ VALUE orig_stdout;
532
+ VALUE orig_stderr;
533
+ VALUE fatal_exception;
534
+ VALUE sysstack_error;
535
+ NODE *basic_respond_to;
536
+
537
+ int thread_abort;
538
+ VALUE thgroup_default;
539
+
540
+ VALUE argf;
541
+
542
+ char *ruby_inplace_mode;
543
+ int stack_overflowing;
544
+ int eval_tick;
545
+ int thread_tick;
546
+
547
+ VALUE thread_save_value;
548
+
549
+ rb_thread_t thread_restore;
550
+ int thread_restore_state;
551
+ VALUE thread_restore_value;
552
+
553
+ /* from parse.y */
554
+ int parse_debug;
555
+ char *ruby_sourcefile;
556
+ int ruby_sourceline;
557
+ struct local_vars *lvtbl;
558
+ st_table *sym_tbl;
559
+ st_table *sym_rev_tbl;
560
+ int last_call_status;
561
+ struct end_proc_data *end_procs, *ephemeral_end_procs, *tmp_end_procs;
562
+
563
+ VALUE rb_last_status;
564
+
565
+ ID last_id;
566
+ int maxgroups;
567
+
568
+ /* from dir.c */
569
+ int chdir_blocking;
570
+ VALUE chdir_thread;
571
+
572
+ /* from dln.c */
573
+ int dln_errno;
574
+ int dln_init_p;
575
+ st_table *dln_sym_tbl;
576
+ st_table *dln_undef_tbl;
577
+ st_table *dln_reloc_tbl;
578
+ int link_no;
579
+
580
+ int target_offset;
581
+ char fbuf[MAXPATHLEN];
582
+ st_table *syserr_tbl;
583
+
584
+ /* from hash.c */
585
+ VALUE envtbl;
586
+ int path_tainted;
587
+
588
+ /* from variable.c */
589
+ st_table *rb_global_tbl;
590
+
591
+ VALUE current_file, filename;
592
+ int gets_lineno;
593
+ int init_p, next_p;
594
+ VALUE lineno;
595
+
596
+ int special_generic_ivar;
597
+ st_table *generic_iv_tbl;
598
+
599
+
600
+ /* from file.c */
601
+ VALUE separator;
602
+
603
+ /* from string.c */
604
+ VALUE rb_fs;
605
+
606
+ /* from signal.c */
607
+ struct trap_list_struct trap_list[NSIG];
608
+ rb_atomic_t trap_pending_list[NSIG];
609
+
610
+ # ifdef HAVE_SIGPROCMASK
611
+ sigset_t trap_last_mask;
612
+ # else
613
+ int trap_last_mask;
614
+ # endif
615
+
616
+ pthread_mutex_t xcritical;
617
+ pthread_t xcritical_owner;
618
+
619
+ struct ruby_state *pristine;
620
+
621
+ VALUE thread;
622
+ pthread_t main_osthread;
623
+ VALUE os_threads;
624
+ VALUE sub_states;
625
+ VALUE on_switch;
626
+ VALUE interrupt;
627
+
628
+ struct ruby_state *parent;
629
+
630
+ struct lock_table_entry *locks;
631
+ struct lock_table_entry *lock_entry;
632
+
633
+ int load_depth;
634
+
635
+ /* for behavior.c */
636
+ int behavior_disabled;
637
+ VALUE default_behavior;
638
+ NODE *current_call_node;
639
+ struct BLOCK *current_call_block;
640
+ struct SCOPE *current_call_scope;
641
+ } ruby_state;
642
+
643
+ #define GET_THREAD(self) ((struct rb_os_thread_t*)(DATA_PTR(self)))
644
+
645
+ struct rb_os_thread_t {
646
+ VALUE result;
647
+ VALUE group;
648
+ VALUE locals;
649
+ VALUE error;
650
+ ruby_state *state;
651
+ pthread_t os_thread;
652
+ enum thread_status status;
653
+ };
654
+
655
+ ruby_state *rb_get_state();
656
+ ruby_state *inherit_from_state(ruby_state*);
657
+ void rb_set_state(ruby_state *st);
658
+ ruby_state *rb_dup_state(ruby_state *state);
659
+ void init_ruby_state();
660
+ int rb_lock_xcritical();
661
+ int rb_unlock_xcritical();
662
+ void rb_state_run_interrupt();
663
+ void rb_modify();
664
+ void rb_end_modify();
665
+
666
+ #define ENTER_CRITICAL do { \
667
+ int __thr_critical = rb_thread_critical; \
668
+ rb_thread_critical = Qtrue; \
669
+ rb_lock_xcritical(__FILE__,__LINE__)
670
+
671
+ #define LEAVE_CRITICAL \
672
+ rb_thread_critical = __thr_critical; \
673
+ rb_unlock_xcritical(); } while(0)
674
+
675
+ #ifdef GC_DEBUG
676
+
677
+ #define GC_LOCK fprintf(stderr, "locked at %s:%d\n", __FILE__, __LINE__); pthread_mutex_lock(&GC_VAR(lock)); \
678
+ GC_VAR(lock_owner) = pthread_self()
679
+
680
+ #define GC_UNLOCK pthread_mutex_unlock(&GC_VAR(lock)); fprintf(stderr, "unlocked at %s:%d\n", __FILE__, __LINE__)
681
+
682
+ #define HEAP_LOCK fprintf(stderr, "heap locked at %s:%d\n", __FILE__, __LINE__); pthread_mutex_lock(&GC_VAR(heap_modification));
683
+ #define HEAP_UNLOCK pthread_mutex_unlock(&GC_VAR(heap_modification)); fprintf(stderr, "heap unlocked at %s:%d\n", __FILE__, __LINE__)
684
+
685
+ #else
686
+
687
+ #if 0
688
+
689
+ #define GC_LOCK if(!pthread_equal(pthread_self(), GC_VAR(lock_owner))) { \
690
+ pthread_mutex_lock(&GC_VAR(lock)); GC_VAR(lock_owner) = pthread_self(); }
691
+
692
+ #define GC_UNLOCK if(!pthread_equal(pthread_self(), GC_VAR(lock_owner))) pthread_mutex_unlock(&GC_VAR(lock))
693
+
694
+ #endif
695
+
696
+ #define GC_LOCK pthread_mutex_lock(&GC_VAR(lock))
697
+
698
+ #define GC_UNLOCK pthread_mutex_unlock(&GC_VAR(lock))
699
+
700
+ #define HEAP_LOCK pthread_mutex_lock(&GC_VAR(heap_modification))
701
+ #define HEAP_UNLOCK pthread_mutex_unlock(&GC_VAR(heap_modification))
702
+
703
+ #endif
704
+
705
+ #define MODIFY(value) rb_modify(value)
706
+
707
+ #define END_MODIFY(value) rb_end_modify(value)
708
+ void __place_exit(char*, int, int);
709
+
710
+ #define RUBY_STATE ((ruby_state*)rb_get_state())
711
+ #define STATE_VAR(obj) (RUBY_STATE->obj)
712
+ #define GC_VAR(obj) STATE_VAR(gc->obj)
713
+ // #define rb_cObject STATE_VAR(cObject)
714
+ // #define rb_cClass STATE_VAR(cClass)
715
+
716
+ #endif