bitescript 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/bitescript.gemspec +2 -3
- data/examples/hello_world.class +0 -0
- data/lib/bitescript/builder.rb +35 -11
- data/lib/bitescript/bytecode.rb +2 -4
- data/lib/bitescript/mirror.rb +13 -1
- data/lib/bitescript/signature.rb +13 -2
- data/test/test_builder.rb +3 -4
- data/test/test_bytecode.rb +2 -0
- metadata +5 -4
data/bitescript.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{bitescript}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.7"
|
6
6
|
s.authors = ["Charles Oliver Nutter", "Ryan Brown"]
|
7
7
|
s.date = Time.now.strftime('YYYY-MM-DD')
|
8
8
|
s.description = %q{BiteScript is a Ruby DSL for generating Java bytecode and classes.}
|
@@ -10,8 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.executables = ["bite", "bitec"]
|
11
11
|
s.extra_rdoc_files = Dir['*.txt']
|
12
12
|
s.files = Dir['{bin,examples,lib,nbproject,test}/**/*'] + Dir['{*.txt,*.gemspec,Rakefile}']
|
13
|
-
|
14
|
-
s.homepage = %q{http://kenai.com/projects/jvmscript}
|
13
|
+
s.homepage = %q{http://github.com/headius/bitescript}
|
15
14
|
s.rdoc_options = ["--main", "README.txt"]
|
16
15
|
s.require_paths = ["lib"]
|
17
16
|
s.rubyforge_project = %q{jruby-extras}
|
Binary file
|
data/lib/bitescript/builder.rb
CHANGED
@@ -78,6 +78,9 @@ module BiteScript
|
|
78
78
|
def find_retention(cls)
|
79
79
|
if cls.kind_of?(BiteScript::ASM::ClassMirror)
|
80
80
|
retention = cls.getDeclaredAnnotation('java.lang.annotation.Retention')
|
81
|
+
elsif cls.kind_of?(BiteScript::ASM::Type)
|
82
|
+
mirror = BiteScript::ASM::ClassMirror.for_name(cls.class_name) rescue nil
|
83
|
+
return find_retention(mirror) if mirror
|
81
84
|
elsif Java::JavaClass === cls
|
82
85
|
retention = cls.annotation(Retention.java_class)
|
83
86
|
else
|
@@ -224,15 +227,12 @@ module BiteScript
|
|
224
227
|
@interfaces = opts[:interfaces] || []
|
225
228
|
@interface = opts[:interface]
|
226
229
|
flags = Opcodes::ACC_SUPER
|
230
|
+
flags |= Opcodes::ACC_ABSTRACT if opts[:abstract]
|
227
231
|
if @interface
|
228
232
|
flags = Opcodes::ACC_INTERFACE | Opcodes::ACC_ABSTRACT
|
229
233
|
end
|
230
234
|
|
231
235
|
@class_writer = ClassWriter.new(ClassWriter::COMPUTE_MAXS)
|
232
|
-
if ENV['BS_CHECK_CLASSES']
|
233
|
-
@real_class_writer = @class_writer
|
234
|
-
@class_writer = CheckClassAdapter.new(@class_writer)
|
235
|
-
end
|
236
236
|
|
237
237
|
interface_paths = []
|
238
238
|
(@interfaces).each {|interface| interface_paths << path(interface)}
|
@@ -280,12 +280,15 @@ module BiteScript
|
|
280
280
|
end
|
281
281
|
|
282
282
|
def generate
|
283
|
+
bytes = @class_writer.to_byte_array
|
283
284
|
if ENV['BS_CHECK_CLASSES']
|
284
|
-
|
285
|
-
|
286
|
-
|
285
|
+
BiteScript::ASM::CheckClassAdapter.verify(
|
286
|
+
BiteScript::ASM::ClassReader.new(bytes),
|
287
|
+
JRuby.runtime.jruby_class_loader,
|
288
|
+
false,
|
289
|
+
java.io.PrintWriter.new(java.lang.System.out, true))
|
287
290
|
end
|
288
|
-
String.from_java_bytes(
|
291
|
+
String.from_java_bytes(bytes)
|
289
292
|
end
|
290
293
|
|
291
294
|
%w[public private protected].each do |modifier|
|
@@ -330,7 +333,28 @@ module BiteScript
|
|
330
333
|
def static_init(&block)
|
331
334
|
method(Opcodes::ACC_STATIC, "<clinit>", [void], [], &block)
|
332
335
|
end
|
333
|
-
|
336
|
+
|
337
|
+
def build_method(name, visibility, static, exceptions, type, *args)
|
338
|
+
flags =
|
339
|
+
case visibility
|
340
|
+
when :public; Opcodes::ACC_PUBLIC
|
341
|
+
when :private; Opcodes::ACC_PRIVATE
|
342
|
+
when :protected; Opcodes::ACC_PROTECTED
|
343
|
+
end
|
344
|
+
flags |= Opcodes::ACC_STATIC if static
|
345
|
+
method(flags, name, [type, *args], exceptions)
|
346
|
+
end
|
347
|
+
|
348
|
+
def build_constructor(visibility, exceptions, *args)
|
349
|
+
flags =
|
350
|
+
case visibility
|
351
|
+
when :public; Opcodes::ACC_PUBLIC
|
352
|
+
when :private; Opcodes::ACC_PRIVATE
|
353
|
+
when :protected; Opcodes::ACC_PROTECTED
|
354
|
+
end
|
355
|
+
@constructor = method(flags, "<init>", [nil, *args], exceptions)
|
356
|
+
end
|
357
|
+
|
334
358
|
def method(flags, name, signature, exceptions, &block)
|
335
359
|
flags |= Opcodes::ACC_ABSTRACT if interface?
|
336
360
|
mb = MethodBuilder.new(self, flags, name, exceptions, signature)
|
@@ -448,8 +472,8 @@ module BiteScript
|
|
448
472
|
@next_local = 0
|
449
473
|
|
450
474
|
@static = (modifiers & Opcodes::ACC_STATIC) != 0
|
451
|
-
@start_label = labels[:
|
452
|
-
@end_label = labels[:
|
475
|
+
@start_label = labels[:_start] = self.label
|
476
|
+
@end_label = labels[:_end] = self.label
|
453
477
|
@exceptions = exceptions || []
|
454
478
|
end
|
455
479
|
|
data/lib/bitescript/bytecode.rb
CHANGED
@@ -65,9 +65,7 @@ module BiteScript
|
|
65
65
|
def ldc_float(value); method_visitor.visit_ldc_insn(java.lang.Float.new(value)); 1; end
|
66
66
|
def ldc_double(value); method_visitor.visit_ldc_insn(java.lang.Double.new(value)); 2; end
|
67
67
|
def ldc_class(value)
|
68
|
-
|
69
|
-
method_visitor.visit_ldc_insn(ASM::Type.get_type(value))
|
70
|
-
1
|
68
|
+
method_visitor.visit_ldc_insn(ASM::Type.get_type(ci(value)))
|
71
69
|
end
|
72
70
|
line = __LINE__; eval "
|
73
71
|
def #{const_down}(value)
|
@@ -183,7 +181,7 @@ module BiteScript
|
|
183
181
|
# type instructions
|
184
182
|
line = __LINE__; eval "
|
185
183
|
def #{const_down}(type)
|
186
|
-
method_visitor.visit_type_insn(Opcodes::#{const_name},
|
184
|
+
method_visitor.visit_type_insn(Opcodes::#{const_name}, tipath(type))
|
187
185
|
#{OpcodeStackDeltas[const_name]}
|
188
186
|
end
|
189
187
|
", b, __FILE__, line
|
data/lib/bitescript/mirror.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'jruby'
|
2
|
+
|
1
3
|
module BiteScript::ASM
|
2
4
|
class EnumValue
|
3
5
|
attr_reader :declaring_type, :name
|
@@ -180,10 +182,20 @@ module BiteScript::ASM
|
|
180
182
|
|
181
183
|
def self.load(name_or_bytes)
|
182
184
|
builder = BiteScript::ASM::ClassMirror::Builder.new
|
185
|
+
if name_or_bytes.kind_of?(String)
|
186
|
+
classname = name_or_bytes.tr('.', '/') + ".class"
|
187
|
+
stream = JRuby.runtime.jruby_class_loader.getResourceAsStream(
|
188
|
+
classname)
|
189
|
+
raise NameError, "Class '#{name_or_bytes}' not found." unless stream
|
190
|
+
name_or_bytes = stream
|
191
|
+
end
|
183
192
|
BiteScript::ASM::ClassReader.new(name_or_bytes).accept(builder, 3)
|
184
193
|
builder.mirror
|
185
194
|
end
|
186
|
-
|
195
|
+
|
196
|
+
def self.for_name(name)
|
197
|
+
load(name)
|
198
|
+
end
|
187
199
|
|
188
200
|
def getConstructor(*arg_types)
|
189
201
|
@constructors[arg_types]
|
data/lib/bitescript/signature.rb
CHANGED
@@ -18,7 +18,18 @@ module BiteScript
|
|
18
18
|
path.gsub('/', '.')
|
19
19
|
end
|
20
20
|
module_function :classname
|
21
|
-
|
21
|
+
|
22
|
+
def type_insn_path(cls)
|
23
|
+
descriptor = class_id(cls)
|
24
|
+
if descriptor[0, 1] == '['
|
25
|
+
descriptor
|
26
|
+
else
|
27
|
+
path(cls)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
alias tipath type_insn_path
|
31
|
+
module_function :type_insn_path, :tipath
|
32
|
+
|
22
33
|
def path(cls)
|
23
34
|
case cls
|
24
35
|
when Symbol
|
@@ -42,7 +53,7 @@ module BiteScript
|
|
42
53
|
return "V"
|
43
54
|
end
|
44
55
|
|
45
|
-
if Module === cls
|
56
|
+
if Module === cls || Symbol === cls
|
46
57
|
return "L#{path(cls)};"
|
47
58
|
end
|
48
59
|
|
data/test/test_builder.rb
CHANGED
@@ -60,7 +60,6 @@ class TestBuilder < Test::Unit::TestCase
|
|
60
60
|
def test_sync_ops
|
61
61
|
# TODO figure out what's wrong with this and add error cases
|
62
62
|
assert_equal 'ok', try(JString) {
|
63
|
-
after = label
|
64
63
|
ldc 'ok'
|
65
64
|
astore 0
|
66
65
|
ldc 'ok'
|
@@ -70,14 +69,14 @@ class TestBuilder < Test::Unit::TestCase
|
|
70
69
|
label :begin
|
71
70
|
ldc 'ok'
|
72
71
|
astore 1
|
73
|
-
goto after
|
72
|
+
goto :after
|
74
73
|
label :finally
|
75
74
|
pop
|
76
75
|
aload 0
|
77
76
|
# monitorexit
|
78
77
|
trycatch(:begin, :finally, :finally, nil)
|
79
|
-
trycatch(:finally, :
|
80
|
-
after
|
78
|
+
trycatch(:finally, :after, :finally, nil)
|
79
|
+
label :after
|
81
80
|
aload 1
|
82
81
|
areturn
|
83
82
|
}
|
data/test/test_bytecode.rb
CHANGED
@@ -82,6 +82,8 @@ class TestBytecode < Test::Unit::TestCase
|
|
82
82
|
assert_equal([:visit_ldc_insn, java.lang.Double.new(1)], @dummy.single {ldc(1.0)})
|
83
83
|
|
84
84
|
assert_equal([:visit_ldc_insn, BiteScript::ASM::Type.get_type(System.java_class)], @dummy.single {ldc(System)})
|
85
|
+
type = BiteScript::ASM::Type.get_type('Lcom.example.Test;')
|
86
|
+
assert_equal([:visit_ldc_insn, type], @dummy.single {ldc(type)})
|
85
87
|
end
|
86
88
|
|
87
89
|
def test_int_insns
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 7
|
9
|
+
version: 0.0.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Charles Oliver Nutter
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-10 08:48:06.220000 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- bin/bitep
|
39
39
|
- examples/fib.bs
|
40
40
|
- examples/hello_world.bs
|
41
|
+
- examples/hello_world.class
|
41
42
|
- examples/hello_world_macro.bs
|
42
43
|
- examples/indy.bs
|
43
44
|
- examples/mixed_bag.rb
|
@@ -64,7 +65,7 @@ files:
|
|
64
65
|
- bitescript.gemspec
|
65
66
|
- Rakefile
|
66
67
|
has_rdoc: true
|
67
|
-
homepage: http://
|
68
|
+
homepage: http://github.com/headius/bitescript
|
68
69
|
licenses: []
|
69
70
|
|
70
71
|
post_install_message:
|