duby 0.0.2-java → 0.0.3-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +7 -0
- data/README.txt +18 -7
- data/Rakefile +72 -0
- data/examples/ant/example-build.xml +7 -0
- data/examples/appengine/Rakefile +8 -67
- data/examples/appengine/Readme +4 -3
- data/examples/appengine/lib/duby/appengine_tasks.rb +173 -0
- data/examples/appengine/lib/duby/plugin/datastore.rb +92 -31
- data/examples/appengine/lib/duby_task.rb +61 -0
- data/examples/appengine/src/com/ribrdb/DubyApp.duby +32 -6
- data/examples/appengine/src/com/ribrdb/list.dhtml +2 -2
- data/examples/appengine/{config.ru → src/config.ru} +0 -0
- data/examples/bintrees.duby +66 -0
- data/examples/dynamic.duby +17 -0
- data/examples/fib.duby +3 -11
- data/examples/fields.duby +3 -3
- data/examples/fractal.duby +1 -3
- data/examples/sort_closure.duby +7 -0
- data/examples/swing.duby +11 -11
- data/javalib/duby-bootstrap.jar +0 -0
- data/javalib/dynalang-invoke-0.1.jar +0 -0
- data/lib/duby.rb +168 -35
- data/lib/duby/ast.rb +224 -27
- data/lib/duby/ast/call.rb +85 -25
- data/lib/duby/ast/class.rb +112 -28
- data/lib/duby/ast/flow.rb +65 -44
- data/lib/duby/ast/intrinsics.rb +223 -21
- data/lib/duby/ast/literal.rb +67 -16
- data/lib/duby/ast/local.rb +36 -40
- data/lib/duby/ast/method.rb +83 -67
- data/lib/duby/ast/structure.rb +105 -23
- data/lib/duby/compiler.rb +83 -28
- data/lib/duby/env.rb +33 -0
- data/lib/duby/jvm/base.rb +210 -0
- data/lib/duby/jvm/compiler.rb +293 -219
- data/lib/duby/jvm/method_lookup.rb +77 -67
- data/lib/duby/jvm/source_compiler.rb +250 -157
- data/lib/duby/jvm/source_generator/builder.rb +53 -49
- data/lib/duby/jvm/source_generator/loops.rb +9 -9
- data/lib/duby/jvm/source_generator/precompile.rb +35 -25
- data/lib/duby/jvm/typer.rb +19 -10
- data/lib/duby/jvm/types.rb +127 -68
- data/lib/duby/jvm/types/basic_types.rb +26 -13
- data/lib/duby/jvm/types/enumerable.rb +6 -4
- data/lib/duby/jvm/types/factory.rb +49 -13
- data/lib/duby/jvm/types/floats.rb +16 -0
- data/lib/duby/jvm/types/integers.rb +63 -2
- data/lib/duby/jvm/types/intrinsics.rb +43 -21
- data/lib/duby/jvm/types/methods.rb +326 -86
- data/lib/duby/jvm/types/number.rb +3 -0
- data/lib/duby/nbcompiler.rb +1 -1
- data/lib/duby/plugin/edb.rb +1 -1
- data/lib/duby/plugin/java.rb +10 -1
- data/lib/duby/transform.rb +134 -46
- data/lib/duby/typer.rb +75 -50
- data/test/test_ast.rb +106 -106
- data/test/test_compilation.rb +46 -32
- data/test/test_env.rb +42 -0
- data/test/test_java_typer.rb +35 -51
- data/test/test_javac_compiler.rb +4 -1
- data/test/test_jvm_compiler.rb +564 -133
- data/test/test_typer.rb +68 -92
- metadata +37 -21
- data/examples/README +0 -16
- data/lib/duby/c/compiler.rb +0 -134
- data/lib/duby/old/compiler_old.rb +0 -845
- data/lib/duby/old/declaration.rb +0 -72
- data/lib/duby/old/mapper.rb +0 -72
- data/lib/duby/old/signature.rb +0 -52
- data/lib/duby/old/typer_old.rb +0 -163
- data/lib/duby/plugin/math.rb +0 -84
- data/test/test_math_plugin.rb +0 -87
@@ -3,7 +3,9 @@ require 'duby/jvm/types'
|
|
3
3
|
module Duby
|
4
4
|
class JVM::Types::Type
|
5
5
|
def to_source
|
6
|
-
|
6
|
+
java_name = name
|
7
|
+
java_name = java_name.tr '$', '.' if inner_class?
|
8
|
+
"#{java_name}#{'[]' if array?}"
|
7
9
|
end
|
8
10
|
end
|
9
11
|
|
@@ -12,38 +14,38 @@ module Duby
|
|
12
14
|
|
13
15
|
class Builder
|
14
16
|
attr_accessor :package, :classes, :filename, :compiler
|
15
|
-
|
17
|
+
|
16
18
|
def initialize(filename, compiler)
|
17
19
|
@filename = filename
|
18
20
|
@classes = []
|
19
21
|
@compiler = compiler
|
20
22
|
end
|
21
|
-
|
23
|
+
|
22
24
|
def public_class(name, superclass=nil, *interfaces)
|
23
25
|
cls = ClassBuilder.new(self, name, superclass, interfaces)
|
24
26
|
@classes << cls
|
25
27
|
cls
|
26
28
|
end
|
27
|
-
|
29
|
+
|
28
30
|
def public_interface(name, *interfaces)
|
29
31
|
cls = InterfaceBuilder.new(self, name, interfaces)
|
30
32
|
@classes << cls
|
31
33
|
cls
|
32
34
|
end
|
33
|
-
|
35
|
+
|
34
36
|
def generate
|
35
37
|
@classes.each do |cls|
|
36
38
|
yield cls.filename, cls
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
40
|
-
|
42
|
+
|
41
43
|
class Output
|
42
44
|
def initialize
|
43
45
|
@out = ""
|
44
46
|
@indent = 0
|
45
47
|
end
|
46
|
-
|
48
|
+
|
47
49
|
def puts(*lines)
|
48
50
|
lines.each do |line|
|
49
51
|
print_indent
|
@@ -52,22 +54,22 @@ module Duby
|
|
52
54
|
@indented = false
|
53
55
|
end
|
54
56
|
end
|
55
|
-
|
57
|
+
|
56
58
|
def print_indent
|
57
59
|
@indent ||= 0
|
58
60
|
@out << (' ' * @indent) unless @indented
|
59
61
|
@indented = true
|
60
62
|
end
|
61
|
-
|
63
|
+
|
62
64
|
def print(str)
|
63
65
|
print_indent
|
64
66
|
@out << str.to_s
|
65
67
|
end
|
66
|
-
|
68
|
+
|
67
69
|
def indent
|
68
70
|
@indent += 2
|
69
71
|
end
|
70
|
-
|
72
|
+
|
71
73
|
def dedent
|
72
74
|
@indent -= 2
|
73
75
|
end
|
@@ -79,29 +81,29 @@ module Duby
|
|
79
81
|
@indented = false
|
80
82
|
end
|
81
83
|
end
|
82
|
-
|
84
|
+
|
83
85
|
def to_s
|
84
86
|
@out
|
85
87
|
end
|
86
88
|
end
|
87
|
-
|
89
|
+
|
88
90
|
module Helper
|
89
91
|
def puts(*args)
|
90
92
|
@out.puts(*args)
|
91
93
|
end
|
92
|
-
|
94
|
+
|
93
95
|
def print(*args)
|
94
96
|
@out.print(*args)
|
95
97
|
end
|
96
|
-
|
98
|
+
|
97
99
|
def indent
|
98
100
|
@out.indent
|
99
101
|
end
|
100
|
-
|
102
|
+
|
101
103
|
def dedent
|
102
104
|
@out.dedent
|
103
105
|
end
|
104
|
-
|
106
|
+
|
105
107
|
def block(line='')
|
106
108
|
puts line + " {"
|
107
109
|
indent
|
@@ -120,16 +122,15 @@ module Duby
|
|
120
122
|
else
|
121
123
|
'null'
|
122
124
|
end
|
123
|
-
end
|
125
|
+
end
|
124
126
|
|
125
127
|
def annotate(annotations)
|
126
128
|
annotations.each do |annotation|
|
127
|
-
# TODO values
|
128
129
|
puts "@#{annotation.name}"
|
129
130
|
end
|
130
131
|
end
|
131
132
|
end
|
132
|
-
|
133
|
+
|
133
134
|
class ClassBuilder
|
134
135
|
include Helper
|
135
136
|
include Duby::Compiler::JVM::JVMLogger
|
@@ -159,11 +160,11 @@ module Duby
|
|
159
160
|
@fields = {}
|
160
161
|
start
|
161
162
|
end
|
162
|
-
|
163
|
+
|
163
164
|
def compiler
|
164
165
|
@builder.compiler
|
165
166
|
end
|
166
|
-
|
167
|
+
|
167
168
|
def start
|
168
169
|
puts "// Generated from #{@builder.filename}"
|
169
170
|
puts "package #{package};" if package
|
@@ -183,7 +184,7 @@ module Duby
|
|
183
184
|
puts " {"
|
184
185
|
indent
|
185
186
|
end
|
186
|
-
|
187
|
+
|
187
188
|
def stop
|
188
189
|
finish_declaration
|
189
190
|
return if @stopped
|
@@ -196,23 +197,24 @@ module Duby
|
|
196
197
|
puts "}"
|
197
198
|
log "Class #{name} complete (#{@out.to_s.size})"
|
198
199
|
end
|
199
|
-
|
200
|
+
|
200
201
|
def main
|
201
|
-
public_static_method('main', JVMTypes::Void,
|
202
|
+
public_static_method('main', [], JVMTypes::Void,
|
202
203
|
[JVMTypes::String.array_type, 'argv'])
|
203
204
|
end
|
204
|
-
|
205
|
-
def declare_field(name, type, static, annotations=[])
|
205
|
+
|
206
|
+
def declare_field(name, type, static, access='private', annotations=[])
|
206
207
|
finish_declaration
|
207
208
|
return if @fields[name]
|
208
209
|
static = static ? 'static' : ''
|
209
210
|
annotate(annotations)
|
210
|
-
puts "
|
211
|
+
puts "#{access} #{static} #{type.to_source} #{name};"
|
211
212
|
@fields[name] = true
|
212
213
|
end
|
213
|
-
|
214
|
-
def public_method(name,
|
214
|
+
|
215
|
+
def public_method(name, exceptions, type, *args)
|
215
216
|
finish_declaration
|
217
|
+
type ||= Duby::AST::type(:void)
|
216
218
|
@methods << MethodBuilder.new(self,
|
217
219
|
:name => name,
|
218
220
|
:return => type,
|
@@ -220,9 +222,10 @@ module Duby
|
|
220
222
|
:exceptions => exceptions)
|
221
223
|
@methods[-1]
|
222
224
|
end
|
223
|
-
|
224
|
-
def public_static_method(name,
|
225
|
+
|
226
|
+
def public_static_method(name, exceptions, type, *args)
|
225
227
|
finish_declaration
|
228
|
+
type ||= Duby::AST::type(:void)
|
226
229
|
@methods << MethodBuilder.new(self,
|
227
230
|
:name => name,
|
228
231
|
:return => type,
|
@@ -231,7 +234,7 @@ module Duby
|
|
231
234
|
:exceptions => exceptions)
|
232
235
|
@methods[-1]
|
233
236
|
end
|
234
|
-
|
237
|
+
|
235
238
|
def public_constructor(exceptions, *args)
|
236
239
|
finish_declaration
|
237
240
|
@methods << MethodBuilder.new(self,
|
@@ -240,18 +243,18 @@ module Duby
|
|
240
243
|
:exceptions => exceptions)
|
241
244
|
@methods[-1]
|
242
245
|
end
|
243
|
-
|
246
|
+
|
244
247
|
def generate
|
245
248
|
stop
|
246
249
|
@out.to_s
|
247
250
|
end
|
248
251
|
end
|
249
|
-
|
252
|
+
|
250
253
|
class InterfaceBuilder < ClassBuilder
|
251
254
|
def initialize(builder, name, interfaces)
|
252
255
|
super(builder, name, nil, interfaces)
|
253
256
|
end
|
254
|
-
|
257
|
+
|
255
258
|
def finish_declaration
|
256
259
|
return if @declaration_finished
|
257
260
|
@declaration_finished = true
|
@@ -266,9 +269,10 @@ module Duby
|
|
266
269
|
puts " {"
|
267
270
|
indent
|
268
271
|
end
|
269
|
-
|
272
|
+
|
270
273
|
def public_method(name, type, exceptions, *args)
|
271
274
|
finish_declaration
|
275
|
+
type ||= Duby::AST::type(:void)
|
272
276
|
@methods << MethodBuilder.new(self,
|
273
277
|
:name => name,
|
274
278
|
:return => type,
|
@@ -278,12 +282,12 @@ module Duby
|
|
278
282
|
@methods[-1]
|
279
283
|
end
|
280
284
|
end
|
281
|
-
|
285
|
+
|
282
286
|
class MethodBuilder
|
283
287
|
include Helper
|
284
|
-
|
288
|
+
|
285
289
|
attr_accessor :name, :type, :out
|
286
|
-
|
290
|
+
|
287
291
|
def initialize(cls, options)
|
288
292
|
@class = cls
|
289
293
|
@compiler = cls.compiler
|
@@ -328,7 +332,7 @@ module Duby
|
|
328
332
|
end
|
329
333
|
indent
|
330
334
|
end
|
331
|
-
|
335
|
+
|
332
336
|
def stop
|
333
337
|
dedent
|
334
338
|
puts "}"
|
@@ -347,33 +351,33 @@ module Duby
|
|
347
351
|
end
|
348
352
|
name
|
349
353
|
end
|
350
|
-
|
354
|
+
|
351
355
|
def local?(name)
|
352
356
|
!!@locals[name]
|
353
357
|
end
|
354
358
|
|
355
|
-
def tmp(type)
|
359
|
+
def tmp(type, &block)
|
356
360
|
@temps += 1
|
357
|
-
declare_local(type, "temp$#{@temps}")
|
361
|
+
declare_local(type, "temp$#{@temps}", &block)
|
358
362
|
end
|
359
|
-
|
363
|
+
|
360
364
|
def label
|
361
365
|
@temps += 1
|
362
366
|
"label#{@temps}"
|
363
367
|
end
|
364
|
-
|
368
|
+
|
365
369
|
def push_int(value)
|
366
370
|
print value
|
367
371
|
end
|
368
|
-
|
372
|
+
|
369
373
|
def ldc_float(value)
|
370
374
|
print "(float)#{value}"
|
371
375
|
end
|
372
|
-
|
376
|
+
|
373
377
|
def ldc_double(value)
|
374
378
|
print value
|
375
379
|
end
|
376
|
-
|
380
|
+
|
377
381
|
def method_missing(name, *args)
|
378
382
|
if name.to_s =~ /.const_(m)?(\d)/
|
379
383
|
print '-' if $1
|
@@ -1,23 +1,23 @@
|
|
1
|
-
class Duby::Compiler::JavaSource
|
1
|
+
class Duby::Compiler::JavaSource < Duby::Compiler::JVMCompilerBase
|
2
2
|
class SimpleWhileLoop
|
3
3
|
attr_reader :compiler, :loop
|
4
4
|
def initialize(loop, compiler)
|
5
5
|
@loop = loop
|
6
6
|
@compiler = compiler
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def break
|
10
10
|
compiler.method.puts "break;"
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def next
|
14
14
|
compiler.method.puts "continue;"
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def redo
|
18
18
|
raise "#{self.class.name} doesn't support redo"
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def compile(expression)
|
22
22
|
prepare
|
23
23
|
@loop.init.compile(compiler, false) if @loop.init?
|
@@ -35,11 +35,11 @@ class Duby::Compiler::JavaSource
|
|
35
35
|
compiler.method.puts "#{compiler.lvalue}null;"
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def compile_body
|
40
40
|
loop.body.compile(compiler, false)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def prepare
|
44
44
|
predicate = loop.condition.predicate.precompile(compiler)
|
45
45
|
negative = loop.negative ? '!' : ''
|
@@ -71,11 +71,11 @@ class Duby::Compiler::JavaSource
|
|
71
71
|
def break
|
72
72
|
compiler.method.puts "break #{@outer};"
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
def next
|
76
76
|
compiler.method.puts "break #{@inner};"
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
def redo
|
80
80
|
compiler.method.puts "#{@redo} = true;"
|
81
81
|
compiler.method.puts "continue #{@inner};"
|
@@ -10,18 +10,18 @@ module Duby::AST
|
|
10
10
|
@tempvalue = value || node
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def compile(compiler, expression)
|
15
15
|
if expression
|
16
16
|
compiler.method.print @tempname
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def reload(compiler)
|
21
21
|
compiler.assign(@tempname, @tempvalue)
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
class Node
|
26
26
|
def expr?(compiler)
|
27
27
|
true
|
@@ -34,18 +34,18 @@ module Duby::AST
|
|
34
34
|
temp(compiler)
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def temp(compiler, value=nil)
|
39
39
|
TempValue.new(self, compiler, value)
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
class Body
|
44
44
|
def expr?(compiler)
|
45
45
|
false
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
class If
|
50
50
|
def expr?(compiler)
|
51
51
|
return false unless condition.predicate.expr?(compiler)
|
@@ -54,18 +54,18 @@ module Duby::AST
|
|
54
54
|
true
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
class Loop
|
59
59
|
def expr?(compiler)
|
60
60
|
false
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def precompile(compiler)
|
64
64
|
compile(compiler, false)
|
65
65
|
temp(compiler, 'null')
|
66
66
|
end
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
class Call
|
70
70
|
def method(compiler=nil)
|
71
71
|
@method ||= begin
|
@@ -73,7 +73,7 @@ module Duby::AST
|
|
73
73
|
target.inferred_type.get_method(name, arg_types)
|
74
74
|
end
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
def expr?(compiler)
|
78
78
|
target.expr?(compiler) &&
|
79
79
|
parameters.all? {|p| p.expr?(compiler)} &&
|
@@ -81,7 +81,7 @@ module Duby::AST
|
|
81
81
|
!method.actual_return_type.void?
|
82
82
|
end
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
class FunctionalCall
|
86
86
|
def method(compiler)
|
87
87
|
@method ||= begin
|
@@ -89,7 +89,7 @@ module Duby::AST
|
|
89
89
|
compiler.self_type.get_method(name, arg_types)
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
def expr?(compiler)
|
94
94
|
parameters.all? {|p| p.expr?(compiler)} &&
|
95
95
|
(cast? || !method(compiler).actual_return_type.void?)
|
@@ -110,13 +110,13 @@ module Duby::AST
|
|
110
110
|
!method(compiler).actual_return_type.void?
|
111
111
|
end
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
class EmtpyArray
|
115
115
|
def expr?(compiler)
|
116
116
|
size.expr?(compiler)
|
117
117
|
end
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
class LocalAssignment
|
121
121
|
def expr?(compiler)
|
122
122
|
compiler.method.local?(name) && value.expr?(compiler)
|
@@ -131,40 +131,50 @@ module Duby::AST
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
|
+
class ToString
|
136
|
+
def expr?(compiler)
|
137
|
+
body.expr?(compiler)
|
138
|
+
end
|
139
|
+
|
140
|
+
def temp(compiler, value=nil)
|
141
|
+
TempValue.new(body, compiler, value)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
class StringConcat
|
146
|
+
def expr?(compiler)
|
147
|
+
children.all? {|x| x.expr?(compiler)}
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
135
151
|
class Return
|
136
152
|
def expr?(compiler)
|
137
153
|
false
|
138
154
|
end
|
139
155
|
end
|
140
|
-
|
156
|
+
|
141
157
|
class Raise
|
142
158
|
def expr?(compiler)
|
143
159
|
false
|
144
160
|
end
|
145
161
|
end
|
146
|
-
|
162
|
+
|
147
163
|
class Rescue
|
148
164
|
def expr?(compiler)
|
149
165
|
false
|
150
166
|
end
|
151
167
|
end
|
152
|
-
|
168
|
+
|
153
169
|
class Ensure
|
154
170
|
def expr?(compiler)
|
155
171
|
false
|
156
172
|
end
|
157
173
|
end
|
158
|
-
|
174
|
+
|
159
175
|
class FieldAssignment
|
160
176
|
def expr?(compiler)
|
161
177
|
false
|
162
178
|
end
|
163
179
|
end
|
164
|
-
|
165
|
-
class LocalAssignment
|
166
|
-
def expr?(compiler)
|
167
|
-
false
|
168
|
-
end
|
169
|
-
end
|
170
180
|
end
|