rubex 0.0.1 → 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.travis.yml +14 -0
- data/CONTRIBUTING.md +101 -0
- data/HISTORY.md +3 -0
- data/README.md +112 -297
- data/REFERENCE.md +753 -0
- data/Rakefile +4 -1
- data/TUTORIAL.md +234 -0
- data/bin/rubex +1 -1
- data/docs/_config.yml +1 -0
- data/docs/index.html +1 -0
- data/examples/c_struct_interface/c_struct_interface.rb +6 -0
- data/examples/c_struct_interface/c_struct_interface.rubex +47 -0
- data/examples/linked_list/linked_list.rubex +39 -0
- data/examples/linked_list/rb_linked_list.rb +8 -0
- data/examples/rcsv wrapper/rcsv/README.md +1 -0
- data/examples/rcsv wrapper/rcsv/Rakefile +7 -0
- data/examples/rcsv wrapper/rcsv/ext/rcsv/extconf.rb +3 -0
- data/examples/rcsv wrapper/rcsv/ext/rcsv/rcsv.c +302 -0
- data/examples/rcsv wrapper/rcsv/ext/rcsv/rcsv.rubex +124 -0
- data/examples/rcsv wrapper/rcsv/lib/rcsv.rb +8 -0
- data/examples/rcsv wrapper/rcsv/lib/rcsv.so +0 -0
- data/examples/rcsv wrapper/rcsv/lib/rcsv/version.rb +1 -0
- data/examples/rcsv wrapper/rcsv/rcsv.gemspec +27 -0
- data/examples/rcsv wrapper/rcsv/spec/rcsv.csv +5 -0
- data/examples/rcsv wrapper/rcsv/spec/rcsv_spec.rb +17 -0
- data/examples/rcsv wrapper/rcsv/spec/spec_helper.rb +6 -0
- data/{spec/fixtures/basic_ruby_method/Makefile → examples/rcsv wrapper/rcsv/tmp/x86_64-linux/rcsv/2.3.3/Makefile } +20 -20
- data/examples/rcsv wrapper/rcsv/tmp/x86_64-linux/rcsv/2.3.3/rcsv.o +0 -0
- data/examples/rcsv wrapper/rcsv/tmp/x86_64-linux/rcsv/2.3.3/rcsv.so +0 -0
- data/examples/rcsv wrapper/rcsv/tmp/x86_64-linux/stage/lib/rcsv.so +0 -0
- data/lib/rubex.rb +6 -50
- data/lib/rubex/ast.rb +1 -3
- data/lib/rubex/ast/expression.rb +1257 -8
- data/lib/rubex/ast/node.rb +226 -28
- data/lib/rubex/ast/statement.rb +1162 -35
- data/lib/rubex/ast/top_statement.rb +815 -0
- data/lib/rubex/code_writer.rb +103 -26
- data/lib/rubex/compiler.rb +72 -0
- data/lib/rubex/compiler_config.rb +19 -0
- data/lib/rubex/constants.rb +145 -8
- data/lib/rubex/data_type.rb +667 -4
- data/lib/rubex/error.rb +15 -0
- data/lib/rubex/helpers.rb +154 -0
- data/lib/rubex/lexer.rex +186 -22
- data/lib/rubex/lexer.rex.rb +261 -35
- data/lib/rubex/parser.racc +876 -28
- data/lib/rubex/parser.racc.rb +2845 -90
- data/lib/rubex/rake_task.rb +34 -0
- data/lib/rubex/symbol_table/entry.rb +17 -3
- data/lib/rubex/symbol_table/scope.rb +298 -25
- data/lib/rubex/version.rb +1 -1
- data/rubex.gemspec +11 -3
- data/spec/basic_ruby_method_spec.rb +15 -21
- data/spec/binding_ptr_args_spec.rb +33 -0
- data/spec/bitwise_operators_spec.rb +40 -0
- data/spec/blocks_spec.rb +35 -0
- data/spec/c_bindings_spec.rb +36 -0
- data/spec/c_constants_spec.rb +33 -0
- data/spec/c_function_ptrs_spec.rb +38 -0
- data/spec/c_functions_spec.rb +35 -0
- data/spec/c_struct_interface_spec.rb +38 -0
- data/spec/call_by_reference_spec.rb +33 -0
- data/spec/class_methods_spec.rb +33 -0
- data/spec/class_spec.rb +40 -0
- data/spec/comments_spec.rb +33 -0
- data/spec/default_args_spec.rb +37 -0
- data/spec/error_handling_spec.rb +42 -0
- data/spec/examples_spec.rb +52 -0
- data/spec/expressions_spec.rb +33 -0
- data/spec/fixtures/basic_ruby_method/basic_ruby_method.rubex +2 -0
- data/spec/fixtures/binding_ptr_args/binding_ptr_args.rubex +30 -0
- data/spec/fixtures/bitwise_operators/bitwise_operators.rubex +40 -0
- data/spec/fixtures/blocks/blocks.rubex +11 -0
- data/spec/fixtures/c_bindings/c_bindings.rubex +58 -0
- data/spec/fixtures/c_constants/c_constants.rubex +7 -0
- data/spec/fixtures/c_function_ptrs/c_function_ptrs.rubex +52 -0
- data/spec/fixtures/c_functions/c_functions.rubex +25 -0
- data/spec/fixtures/c_struct_interface/c_struct_interface.rubex +34 -0
- data/spec/fixtures/call_by_reference/call_by_reference.rubex +30 -0
- data/spec/fixtures/class/class.rubex +20 -0
- data/spec/fixtures/class_methods/class_methods.rubex +12 -0
- data/spec/fixtures/comments/comments.rubex +9 -0
- data/spec/fixtures/default_args/default_args.rubex +11 -0
- data/spec/fixtures/error_handling/error_handling.rubex +54 -0
- data/spec/fixtures/examples/array_to_hash.rubex +14 -0
- data/spec/fixtures/examples/rcsv.csv +5 -0
- data/spec/fixtures/examples/rcsv.rubex +329 -0
- data/spec/fixtures/expressions/expressions.rubex +10 -0
- data/spec/fixtures/if_else/if_else.rubex +77 -0
- data/spec/fixtures/implicit_lib_include/implicit_lib_include.rubex +15 -0
- data/spec/fixtures/init_ruby_objects_with_literal_syntax/init_ruby_objects_with_literal_syntax.rubex +17 -0
- data/spec/fixtures/loops/loops.rubex +33 -0
- data/spec/fixtures/recursion/recursion.rubex +9 -0
- data/spec/fixtures/ruby_constant_method_calls/ruby_constant_method_calls.rubex +17 -0
- data/spec/fixtures/ruby_operators/ruby_operators.rubex +29 -0
- data/spec/fixtures/ruby_raise/ruby_raise.rubex +13 -0
- data/spec/fixtures/ruby_strings/ruby_strings.rubex +19 -0
- data/spec/fixtures/ruby_strings/string_blank_bm.rb +37 -0
- data/spec/fixtures/ruby_symbols/ruby_symbols.rubex +12 -0
- data/spec/fixtures/ruby_types/ruby_types.rubex +15 -0
- data/spec/fixtures/statement_expression/statement_expression.rubex +23 -0
- data/spec/fixtures/static_array/static_array.rubex +20 -0
- data/spec/fixtures/string_literals/string_literals.rubex +15 -0
- data/spec/fixtures/struct/struct.rubex +82 -0
- data/spec/fixtures/typecasting/typecasting.rubex +23 -0
- data/spec/fixtures/var_declarations/var_declarations.rubex +39 -0
- data/spec/if_else_spec.rb +39 -0
- data/spec/implicit_lib_include_spec.rb +33 -0
- data/spec/init_ruby_objects_with_literal_syntax_spec.rb +39 -0
- data/spec/loops_spec.rb +34 -0
- data/spec/recursion_spec.rb +35 -0
- data/spec/ruby_constant_method_calls_spec.rb +35 -0
- data/spec/ruby_operators_spec.rb +40 -0
- data/spec/ruby_raise_spec.rb +35 -0
- data/spec/ruby_strings_spec.rb +33 -0
- data/spec/ruby_symbols_spec.rb +37 -0
- data/spec/ruby_types_spec.rb +35 -0
- data/spec/spec_helper.rb +54 -1
- data/spec/statement_expression_spec.rb +34 -0
- data/spec/static_array_spec.rb +33 -0
- data/spec/string_literals_spec.rb +34 -0
- data/spec/struct_spec.rb +36 -0
- data/spec/typecasting_spec.rb +38 -0
- data/spec/var_declarions_spec.rb +35 -0
- metadata +255 -29
- data/lib/rubex/ast/argument_list.rb +0 -20
- data/lib/rubex/ast/c_base_type.rb +0 -11
- data/lib/rubex/ast/ruby_method_def.rb +0 -84
- data/spec/fixtures/basic_ruby_method/basic.rb +0 -3
- data/spec/fixtures/basic_ruby_method/basic_ruby_method.c +0 -16
- data/spec/fixtures/basic_ruby_method/basic_ruby_method.o +0 -0
- data/spec/fixtures/basic_ruby_method/basic_ruby_method.so +0 -0
- data/spec/fixtures/basic_ruby_method/extconf.rb +0 -3
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/tasklib'
|
3
|
+
require "rake/extensiontask"
|
4
|
+
require_relative '../rubex.rb'
|
5
|
+
|
6
|
+
module Rubex
|
7
|
+
class RakeTask < ::Rake::TaskLib
|
8
|
+
|
9
|
+
def initialize name, gem_spec=nil
|
10
|
+
@name = name
|
11
|
+
@gem_spec = gem_spec
|
12
|
+
@ext_dir = "ext/#{@name}"
|
13
|
+
@lib_dir = 'lib'
|
14
|
+
@source_pattern = "*.rubex"
|
15
|
+
@compiled_pattern = "*.c"
|
16
|
+
@config_script = "extconf.rb"
|
17
|
+
define_compile_tasks
|
18
|
+
end
|
19
|
+
|
20
|
+
def define_compile_tasks
|
21
|
+
namespace :rubex do
|
22
|
+
desc "Compile a Rubex file into a shared object."
|
23
|
+
task :compile do
|
24
|
+
file_name = "#{Dir.pwd}/#{@ext_dir}/#{@name}#{@source_pattern[1..-1]}"
|
25
|
+
Rubex::Compiler.compile file_name, directory: "#{@ext_dir}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
Rake::ExtensionTask.new(@name)
|
29
|
+
|
30
|
+
desc "Compile Rubex code into a .so file for use in Ruby scripts."
|
31
|
+
task :compile => "rubex:compile"
|
32
|
+
end
|
33
|
+
end # class RakeTask
|
34
|
+
end # module Rubex
|
@@ -7,10 +7,24 @@ module Rubex
|
|
7
7
|
attr_accessor :c_name
|
8
8
|
# Ctype of the the entry.
|
9
9
|
attr_accessor :type
|
10
|
+
# Default value of the entry, if any.
|
11
|
+
attr_accessor :value
|
12
|
+
# Is an extern entry
|
13
|
+
attr_accessor :extern
|
14
|
+
# Is a Ruby singleton method
|
15
|
+
attr_accessor :singleton
|
10
16
|
|
11
|
-
def initialize name, c_name, type
|
12
|
-
@name, @c_name, @type = name, c_name, type
|
17
|
+
def initialize name, c_name, type, value
|
18
|
+
@name, @c_name, @type, @value = name, c_name, type, value
|
13
19
|
end
|
20
|
+
|
21
|
+
def c_code local_scope
|
22
|
+
c_name
|
23
|
+
end
|
24
|
+
|
25
|
+
def extern?; @extern; end
|
26
|
+
|
27
|
+
def singleton?; @singleton; end
|
14
28
|
end
|
15
29
|
end
|
16
|
-
end
|
30
|
+
end
|
@@ -1,57 +1,330 @@
|
|
1
1
|
module Rubex
|
2
2
|
module SymbolTable
|
3
3
|
module Scope
|
4
|
-
attr_accessor :entries
|
4
|
+
attr_accessor :entries
|
5
|
+
attr_accessor :outer_scope
|
6
|
+
attr_accessor :arg_entries
|
7
|
+
attr_accessor :type
|
8
|
+
attr_accessor :var_entries
|
9
|
+
attr_accessor :ruby_obj_entries
|
10
|
+
attr_accessor :carray_entries
|
11
|
+
attr_accessor :sue_entries
|
12
|
+
attr_accessor :c_method_entries
|
13
|
+
attr_accessor :type_entries
|
14
|
+
attr_accessor :ruby_class_entries
|
15
|
+
attr_accessor :ruby_method_entries
|
16
|
+
attr_accessor :ruby_constant_entries
|
17
|
+
attr_accessor :self_name
|
18
|
+
attr_accessor :temp_entries
|
19
|
+
attr_accessor :free_temp_entries
|
20
|
+
attr_accessor :global_entries
|
21
|
+
attr_reader :klass_name, :name
|
5
22
|
|
6
23
|
def initialize outer_scope=nil
|
7
24
|
@outer_scope = outer_scope
|
8
25
|
@entries = {}
|
9
26
|
@arg_entries = []
|
10
|
-
@
|
27
|
+
@var_entries = []
|
28
|
+
@type = nil
|
29
|
+
@ruby_obj_entries = []
|
30
|
+
@carray_entries = []
|
31
|
+
@sue_entries = []
|
32
|
+
@c_method_entries = []
|
33
|
+
@type_entries = []
|
34
|
+
@ruby_class_entries = []
|
35
|
+
@ruby_method_entries = []
|
36
|
+
@ruby_constant_entries = []
|
37
|
+
@self_name = ""
|
38
|
+
@klass_name = ""
|
39
|
+
@temp_entries = []
|
40
|
+
@free_temp_entries = []
|
41
|
+
@global_entries = []
|
42
|
+
@temp_counter = 0
|
43
|
+
end
|
44
|
+
|
45
|
+
def check_entry name
|
46
|
+
if @entries.has_key? name
|
47
|
+
raise "Symbol name #{name} already exists in this scope."
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# vars - Rubex::AST::Statement::VarDecl/CPtrDecl
|
52
|
+
def declare_var(name: "", c_name: "", type: nil, value: nil, extern: false)
|
53
|
+
entry = Rubex::SymbolTable::Entry.new(name, c_name, type, value)
|
54
|
+
entry.extern = extern
|
55
|
+
check_entry name
|
56
|
+
@entries[name] = entry
|
57
|
+
@var_entries << entry
|
58
|
+
|
59
|
+
entry
|
60
|
+
end
|
61
|
+
|
62
|
+
def declare_sue name:, c_name:, type:, extern:
|
63
|
+
entry = Rubex::SymbolTable::Entry.new(
|
64
|
+
name, c_name, type, nil)
|
65
|
+
entry.extern = extern
|
66
|
+
@entries[name] = entry
|
67
|
+
@sue_entries << entry
|
68
|
+
@type_entries << entry
|
69
|
+
|
70
|
+
entry
|
71
|
+
end
|
72
|
+
|
73
|
+
def declare_type type:, extern:
|
74
|
+
entry = Rubex::SymbolTable::Entry.new(nil, nil, type, nil)
|
75
|
+
entry.extern = extern
|
76
|
+
@type_entries << entry
|
77
|
+
|
78
|
+
entry
|
79
|
+
end
|
80
|
+
|
81
|
+
def add_ruby_obj name: , c_name:, value: nil
|
82
|
+
entry = Rubex::SymbolTable::Entry.new(
|
83
|
+
name, c_name, Rubex::DataType::RubyObject.new, value)
|
84
|
+
@entries[name] = entry
|
85
|
+
@ruby_obj_entries << entry
|
86
|
+
|
87
|
+
entry
|
88
|
+
end
|
89
|
+
|
90
|
+
# Add a C array to the current scope.
|
91
|
+
def add_carray name: ,c_name: ,dimension: ,type: ,value: nil
|
92
|
+
type = Rubex::DataType::CArray.new dimension, type
|
93
|
+
entry = Rubex::SymbolTable::Entry.new name, c_name, type, value
|
94
|
+
@entries[name] = entry
|
95
|
+
@carray_entries << entry
|
96
|
+
|
97
|
+
entry
|
98
|
+
end
|
99
|
+
|
100
|
+
# Add a Ruby class to the current scope.
|
101
|
+
def add_ruby_class name: , c_name:, scope:, ancestor:, extern:
|
102
|
+
type = Rubex::DataType::RubyClass.new name, c_name, scope, ancestor
|
103
|
+
entry = Rubex::SymbolTable::Entry.new name, c_name, type, nil
|
104
|
+
entry.extern = extern
|
105
|
+
@entries[name] = entry
|
106
|
+
@ruby_class_entries << entry
|
107
|
+
|
108
|
+
entry
|
109
|
+
end
|
110
|
+
|
111
|
+
def add_c_method name:, c_name:, scope:, arg_list:, return_type:, extern: false
|
112
|
+
type = Rubex::DataType::CFunction.new(
|
113
|
+
name, c_name, arg_list, return_type, scope)
|
114
|
+
entry = Rubex::SymbolTable::Entry.new name, c_name, type, nil
|
115
|
+
entry.extern = extern
|
116
|
+
@entries[name] = entry
|
117
|
+
@c_method_entries << entry
|
118
|
+
|
119
|
+
entry
|
120
|
+
end
|
121
|
+
|
122
|
+
# name: name of the method
|
123
|
+
# c_name: c_name of the method
|
124
|
+
# extern: whether it is defined within the Rubex script or in a scope
|
125
|
+
# outside the Rubex script.
|
126
|
+
def add_ruby_method name:, c_name:, scope:, arg_list:, extern: false
|
127
|
+
type = Rubex::DataType::RubyMethod.new name, c_name, scope, arg_list
|
128
|
+
entry = Rubex::SymbolTable::Entry.new name, c_name, type, nil
|
129
|
+
entry.extern = extern
|
130
|
+
@entries[name] = entry
|
131
|
+
@ruby_method_entries << entry unless extern
|
132
|
+
|
133
|
+
entry
|
134
|
+
end
|
135
|
+
|
136
|
+
# allocate a temp and return its c_name
|
137
|
+
def allocate_temp type
|
138
|
+
if @free_temp_entries.empty?
|
139
|
+
@temp_counter += 1
|
140
|
+
c_name = Rubex::TEMP_PREFIX + @temp_counter.to_s
|
141
|
+
entry = Rubex::SymbolTable::Entry.new c_name, c_name, type,
|
142
|
+
Expression::Literal::CNull.new('NULL')
|
143
|
+
@entries[c_name] = entry
|
144
|
+
@temp_entries << entry
|
145
|
+
else
|
146
|
+
entry = @free_temp_entries.pop
|
147
|
+
c_name = entry.c_name
|
148
|
+
end
|
149
|
+
|
150
|
+
c_name
|
151
|
+
end
|
152
|
+
|
153
|
+
# release a temp of name 'c_name' for reuse
|
154
|
+
def release_temp c_name
|
155
|
+
@free_temp_entries << @entries[c_name]
|
156
|
+
end
|
157
|
+
|
158
|
+
def [] entry
|
159
|
+
@entries[entry] or raise(Rubex::SymbolNotFoundError,
|
160
|
+
"Symbol #{entry} does not exist in this scope.")
|
161
|
+
end
|
162
|
+
|
163
|
+
def has_entry? entry
|
164
|
+
!!@entries[entry]
|
11
165
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
166
|
+
|
167
|
+
# Find an entry in this scope or the ones above it recursively.
|
168
|
+
def find name
|
169
|
+
return recursive_find(name, self)
|
170
|
+
end
|
171
|
+
|
172
|
+
private
|
173
|
+
def recursive_find name, scope
|
174
|
+
if scope
|
175
|
+
if scope.has_entry?(name)
|
176
|
+
return scope[name]
|
177
|
+
else
|
178
|
+
return recursive_find(name, scope.outer_scope)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
return nil
|
183
|
+
end
|
184
|
+
end # module Scope
|
185
|
+
end # module SymbolTable
|
186
|
+
end # module Rubex
|
15
187
|
|
16
188
|
module Rubex
|
17
189
|
module SymbolTable
|
18
190
|
module Scope
|
19
191
|
class Klass
|
20
192
|
include Rubex::SymbolTable::Scope
|
193
|
+
attr_accessor :include_files #TODO: this should probably not be here.
|
194
|
+
attr_accessor :begin_block_callbacks
|
21
195
|
|
22
|
-
|
23
|
-
|
24
|
-
def initialize name
|
25
|
-
name == 'Object' ? super(nil) : super
|
196
|
+
def initialize name, outer_scope
|
197
|
+
super(outer_scope)
|
26
198
|
@name = name
|
199
|
+
@klass_name = @name
|
200
|
+
@include_files = []
|
201
|
+
@begin_block_callbacks = []
|
202
|
+
end
|
27
203
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
204
|
+
def object_scope
|
205
|
+
temp = self
|
206
|
+
while temp.outer_scope != nil
|
207
|
+
temp = temp.outer_scope
|
32
208
|
end
|
209
|
+
|
210
|
+
temp
|
33
211
|
end
|
34
|
-
|
212
|
+
|
213
|
+
# Stores CFunctionDef nodes that represent begin block callbacks.
|
214
|
+
def add_begin_block_callback func
|
215
|
+
@begin_block_callbacks << func
|
216
|
+
end
|
217
|
+
end # class Klass
|
35
218
|
|
36
219
|
class Local
|
37
220
|
include Rubex::SymbolTable::Scope
|
221
|
+
attr_reader :begin_block_counter
|
222
|
+
|
223
|
+
def initialize name, outer_scope
|
224
|
+
super(outer_scope)
|
225
|
+
@name = name
|
226
|
+
@klass_name = outer_scope.klass_name
|
227
|
+
@begin_block_counter = 0
|
228
|
+
end
|
38
229
|
|
39
230
|
# args - Rubex::AST::ArgumentList. Creates sym. table entries for args.
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
@arg_entries << entry
|
48
|
-
end
|
231
|
+
def add_arg name:, c_name:, type:, value:
|
232
|
+
entry = Rubex::SymbolTable::Entry.new name, c_name, type, value
|
233
|
+
check_entry name
|
234
|
+
@entries[name] = entry
|
235
|
+
@arg_entries << entry
|
236
|
+
|
237
|
+
entry
|
49
238
|
end
|
50
239
|
|
51
|
-
def
|
52
|
-
@
|
240
|
+
def found_begin_block
|
241
|
+
@begin_block_counter += 1
|
53
242
|
end
|
54
243
|
end # class Local
|
244
|
+
|
245
|
+
class BeginBlock
|
246
|
+
attr_reader :name, :outer_scope
|
247
|
+
|
248
|
+
def initialize name, outer_scope
|
249
|
+
@outer_scope = outer_scope
|
250
|
+
@name = name
|
251
|
+
@block_entries = []
|
252
|
+
end
|
253
|
+
|
254
|
+
def upgrade_symbols_to_global
|
255
|
+
@block_entries.uniq!
|
256
|
+
@block_entries.each do |entry|
|
257
|
+
entry.c_name = Rubex::GLOBAL_PREFIX + @name + entry.c_name
|
258
|
+
@outer_scope.global_entries << entry
|
259
|
+
end
|
260
|
+
|
261
|
+
remove_global_from_local_entries
|
262
|
+
end
|
263
|
+
|
264
|
+
# IMPORTANT NOTE TO PROGRAMMER:
|
265
|
+
#
|
266
|
+
# A problem with the BeginBlock is that in the Ruby world, it must share
|
267
|
+
# scope with the method above and below it. However, when translating to
|
268
|
+
# C, the begin block must be put inside its own C function, which is then
|
269
|
+
# sent as a callback to rb_protect().
|
270
|
+
#
|
271
|
+
# As a result, it is necesary to 'upgrade' the local variables present
|
272
|
+
# inside the begin block to C global variables so that they can be shared
|
273
|
+
# between the callback C function encapsulating the begin block and the
|
274
|
+
# ruby method that has a begin block defined inside it.
|
275
|
+
#
|
276
|
+
# Now, since variables must be shared, it is also necessary to share the
|
277
|
+
# scopes between these functions. Therefore, the BeginBlock scope uses
|
278
|
+
# method_missing to capture whatever methods calls it has received and
|
279
|
+
# redirect those to @outer_scope, which is the scope of the method that
|
280
|
+
# contains the begin block. Whenever a method call to @outer_scope returns
|
281
|
+
# a SymbolTable::Entry object, that object is read to check if it is a
|
282
|
+
# variable. If yes, it is added into the @block_entries Array which
|
283
|
+
# stores the entries that need to be upgraded to C global variables.
|
284
|
+
#
|
285
|
+
# Now as a side effect of this behaviour, the various *_entries Arrays
|
286
|
+
# of @outer_scope get carried forward into this begin block callback.
|
287
|
+
# Therefore these variables get declared inside the begin block callback
|
288
|
+
# as well. So whenever one of these Arrays is called for this particular
|
289
|
+
# scope, we return an empty array so that nothing gets declared.
|
290
|
+
def method_missing meth, *args, &block
|
291
|
+
return [] if meth == :var_entries
|
292
|
+
ret = @outer_scope.send(meth, *args, &block)
|
293
|
+
if ret.is_a?(Rubex::SymbolTable::Entry)
|
294
|
+
if !ret.extern?
|
295
|
+
if !ret.type.c_function? && !ret.type.ruby_method? &&
|
296
|
+
!ret.type.ruby_class?
|
297
|
+
@block_entries << ret
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
ret
|
303
|
+
end
|
304
|
+
|
305
|
+
private
|
306
|
+
|
307
|
+
def remove_global_from_local_entries
|
308
|
+
@outer_scope.arg_entries -= @outer_scope.global_entries
|
309
|
+
@outer_scope.var_entries -= @outer_scope.global_entries
|
310
|
+
@outer_scope.ruby_obj_entries -= @outer_scope.global_entries
|
311
|
+
@outer_scope.carray_entries -= @outer_scope.global_entries
|
312
|
+
@outer_scope.sue_entries -= @outer_scope.global_entries
|
313
|
+
@outer_scope.c_method_entries -= @outer_scope.global_entries
|
314
|
+
@outer_scope.type_entries -= @outer_scope.global_entries
|
315
|
+
end
|
316
|
+
end # class BeginBlock
|
317
|
+
|
318
|
+
class StructOrUnion
|
319
|
+
include Rubex::SymbolTable::Scope
|
320
|
+
# FIXME: Change scope structure to identify struct scopes by name too.
|
321
|
+
|
322
|
+
def initialize name, outer_scope
|
323
|
+
super(outer_scope)
|
324
|
+
@klass_name = outer_scope.klass_name
|
325
|
+
@name = name
|
326
|
+
end
|
327
|
+
end # class StructOrUnion
|
55
328
|
end
|
56
329
|
end
|
57
330
|
end
|
data/lib/rubex/version.rb
CHANGED
data/rubex.gemspec
CHANGED
@@ -4,7 +4,9 @@ $:.unshift File.expand_path("../lib", __FILE__)
|
|
4
4
|
require 'rubex/version.rb'
|
5
5
|
|
6
6
|
Rubex::DESCRIPTION = <<MSG
|
7
|
-
A
|
7
|
+
A Ruby-like language for writing Ruby C extensions.
|
8
|
+
|
9
|
+
Rubex keeps you happy even when writing C extensions.
|
8
10
|
MSG
|
9
11
|
|
10
12
|
Gem::Specification.new do |spec|
|
@@ -14,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
14
16
|
spec.email = ['sameer.deshmukh93@gmail.com']
|
15
17
|
spec.summary = Rubex::DESCRIPTION
|
16
18
|
spec.description = Rubex::DESCRIPTION
|
17
|
-
spec.homepage = "http://github.com/
|
19
|
+
spec.homepage = "http://github.com/sciruby/rubex"
|
18
20
|
spec.license = 'BSD-2'
|
19
21
|
|
20
22
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -22,9 +24,15 @@ Gem::Specification.new do |spec|
|
|
22
24
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
25
|
spec.require_paths = ["lib"]
|
24
26
|
|
27
|
+
spec.add_runtime_dependency 'racc', '~> 1.4.14'
|
28
|
+
spec.add_runtime_dependency 'rake-compiler', '~> 1.0.4'
|
29
|
+
|
25
30
|
spec.add_development_dependency 'oedipus_lex', '~> 2.4'
|
26
|
-
spec.add_development_dependency 'racc', '~> 1.4.14'
|
27
31
|
spec.add_development_dependency 'rake', '~> 11.2'
|
28
32
|
spec.add_development_dependency 'rspec', '~> 3.4'
|
29
33
|
spec.add_development_dependency 'awesome_print'
|
34
|
+
spec.add_development_dependency 'pry-byebug'
|
35
|
+
spec.add_development_dependency 'pretty_backtrace'
|
36
|
+
spec.add_development_dependency 'ruby-prof'
|
37
|
+
spec.add_development_dependency 'benchmark-ips'
|
30
38
|
end
|