duby 0.0.2-java → 0.0.3-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/History.txt +7 -0
  2. data/README.txt +18 -7
  3. data/Rakefile +72 -0
  4. data/examples/ant/example-build.xml +7 -0
  5. data/examples/appengine/Rakefile +8 -67
  6. data/examples/appengine/Readme +4 -3
  7. data/examples/appengine/lib/duby/appengine_tasks.rb +173 -0
  8. data/examples/appengine/lib/duby/plugin/datastore.rb +92 -31
  9. data/examples/appengine/lib/duby_task.rb +61 -0
  10. data/examples/appengine/src/com/ribrdb/DubyApp.duby +32 -6
  11. data/examples/appengine/src/com/ribrdb/list.dhtml +2 -2
  12. data/examples/appengine/{config.ru → src/config.ru} +0 -0
  13. data/examples/bintrees.duby +66 -0
  14. data/examples/dynamic.duby +17 -0
  15. data/examples/fib.duby +3 -11
  16. data/examples/fields.duby +3 -3
  17. data/examples/fractal.duby +1 -3
  18. data/examples/sort_closure.duby +7 -0
  19. data/examples/swing.duby +11 -11
  20. data/javalib/duby-bootstrap.jar +0 -0
  21. data/javalib/dynalang-invoke-0.1.jar +0 -0
  22. data/lib/duby.rb +168 -35
  23. data/lib/duby/ast.rb +224 -27
  24. data/lib/duby/ast/call.rb +85 -25
  25. data/lib/duby/ast/class.rb +112 -28
  26. data/lib/duby/ast/flow.rb +65 -44
  27. data/lib/duby/ast/intrinsics.rb +223 -21
  28. data/lib/duby/ast/literal.rb +67 -16
  29. data/lib/duby/ast/local.rb +36 -40
  30. data/lib/duby/ast/method.rb +83 -67
  31. data/lib/duby/ast/structure.rb +105 -23
  32. data/lib/duby/compiler.rb +83 -28
  33. data/lib/duby/env.rb +33 -0
  34. data/lib/duby/jvm/base.rb +210 -0
  35. data/lib/duby/jvm/compiler.rb +293 -219
  36. data/lib/duby/jvm/method_lookup.rb +77 -67
  37. data/lib/duby/jvm/source_compiler.rb +250 -157
  38. data/lib/duby/jvm/source_generator/builder.rb +53 -49
  39. data/lib/duby/jvm/source_generator/loops.rb +9 -9
  40. data/lib/duby/jvm/source_generator/precompile.rb +35 -25
  41. data/lib/duby/jvm/typer.rb +19 -10
  42. data/lib/duby/jvm/types.rb +127 -68
  43. data/lib/duby/jvm/types/basic_types.rb +26 -13
  44. data/lib/duby/jvm/types/enumerable.rb +6 -4
  45. data/lib/duby/jvm/types/factory.rb +49 -13
  46. data/lib/duby/jvm/types/floats.rb +16 -0
  47. data/lib/duby/jvm/types/integers.rb +63 -2
  48. data/lib/duby/jvm/types/intrinsics.rb +43 -21
  49. data/lib/duby/jvm/types/methods.rb +326 -86
  50. data/lib/duby/jvm/types/number.rb +3 -0
  51. data/lib/duby/nbcompiler.rb +1 -1
  52. data/lib/duby/plugin/edb.rb +1 -1
  53. data/lib/duby/plugin/java.rb +10 -1
  54. data/lib/duby/transform.rb +134 -46
  55. data/lib/duby/typer.rb +75 -50
  56. data/test/test_ast.rb +106 -106
  57. data/test/test_compilation.rb +46 -32
  58. data/test/test_env.rb +42 -0
  59. data/test/test_java_typer.rb +35 -51
  60. data/test/test_javac_compiler.rb +4 -1
  61. data/test/test_jvm_compiler.rb +564 -133
  62. data/test/test_typer.rb +68 -92
  63. metadata +37 -21
  64. data/examples/README +0 -16
  65. data/lib/duby/c/compiler.rb +0 -134
  66. data/lib/duby/old/compiler_old.rb +0 -845
  67. data/lib/duby/old/declaration.rb +0 -72
  68. data/lib/duby/old/mapper.rb +0 -72
  69. data/lib/duby/old/signature.rb +0 -52
  70. data/lib/duby/old/typer_old.rb +0 -163
  71. data/lib/duby/plugin/math.rb +0 -84
  72. data/test/test_math_plugin.rb +0 -87
@@ -3,65 +3,65 @@ require 'duby'
3
3
 
4
4
  class TestTyper < Test::Unit::TestCase
5
5
  include Duby
6
-
6
+
7
7
  def test_fixnum
8
8
  ast = AST.parse("1")
9
-
9
+
10
10
  assert_equal(AST::TypeReference.new("fixnum"), ast.infer(Typer::Simple.new(:bar)))
11
11
  end
12
-
12
+
13
13
  def test_float
14
14
  ast = AST.parse("1.0")
15
-
15
+
16
16
  assert_equal(AST::TypeReference.new("float"), ast.infer(Typer::Simple.new(:bar)))
17
17
  end
18
-
18
+
19
19
  def test_string
20
20
  ast = AST.parse("'foo'")
21
-
21
+
22
22
  assert_equal(AST::TypeReference.new("string"), ast.infer(Typer::Simple.new(:bar)))
23
23
  end
24
-
24
+
25
25
  def test_boolean
26
26
  ast1 = AST.parse("true")
27
27
  ast2 = AST.parse("false")
28
-
28
+
29
29
  assert_equal(AST::TypeReference.new("boolean"), ast1.infer(Typer::Simple.new(:bar)))
30
30
  assert_equal(AST::TypeReference.new("boolean"), ast2.infer(Typer::Simple.new(:bar)))
31
31
  end
32
-
32
+
33
33
  def test_body
34
34
  ast1 = AST.parse("'foo'; 1.0; 1")
35
35
  ast2 = AST.parse("begin; end")
36
-
36
+
37
37
  assert_equal(AST::TypeReference.new("fixnum"), ast1.infer(Typer::Simple.new(:bar)))
38
38
  assert_equal(AST::no_type, ast2.infer(Typer::Simple.new(:bar)))
39
39
  end
40
-
40
+
41
41
  def test_local
42
42
  ast1 = AST.parse("a = 1; a")
43
43
  typer = Typer::Simple.new :bar
44
-
44
+
45
45
  ast1.infer(typer)
46
-
47
- assert_equal(AST::TypeReference.new("fixnum"), typer.local_type(ast1, 'a'))
46
+
47
+ assert_equal(AST::TypeReference.new("fixnum"), typer.local_type(ast1.static_scope, 'a'))
48
48
  assert_equal(AST::TypeReference.new("fixnum"), ast1.body.children[0].inferred_type)
49
49
  assert_equal(AST::TypeReference.new("fixnum"), ast1.body.children[1].inferred_type)
50
-
50
+
51
51
  ast2 = AST.parse("b = a = 1")
52
52
  ast2.infer(typer)
53
-
54
- assert_equal(AST::TypeReference.new("fixnum"), typer.local_type(ast2, 'a'))
53
+
54
+ assert_equal(AST::TypeReference.new("fixnum"), typer.local_type(ast2.static_scope, 'a'))
55
55
  assert_equal(AST::TypeReference.new("fixnum"), ast2.body.children[0].inferred_type)
56
56
  end
57
-
57
+
58
58
  def test_signature
59
59
  ["def foo", "def self.foo"].each do |def_foo|
60
60
  ast1 = AST.parse("#{def_foo}(a); {a => :string}; end")
61
61
  typer = Typer::Simple.new :bar
62
62
 
63
63
  ast1.infer(typer)
64
-
64
+
65
65
  assert_nothing_raised {typer.resolve(true)}
66
66
  assert_nothing_raised {typer.resolve}
67
67
 
@@ -73,19 +73,9 @@ class TestTyper < Test::Unit::TestCase
73
73
  end
74
74
 
75
75
  assert_equal(typer.no_type, typer.method_type(type, 'foo', [typer.string_type]))
76
- assert_equal(typer.string_type, typer.local_type(ast1.body, 'a'))
76
+ assert_equal(typer.string_type, typer.local_type(ast1.body[0].static_scope, 'a'))
77
77
  assert_equal(typer.no_type, ast1.body.inferred_type)
78
- assert_equal(typer.string_type, ast1.body.arguments.args[0].inferred_type)
79
-
80
- ast1 = AST.parse("#{def_foo}(a); 1 end")
81
- typer = Typer::Simple.new :bar
82
-
83
- ast1.infer(typer)
84
-
85
- assert_equal(typer.fixnum_type, typer.method_type(type, 'foo', [typer.default_type]))
86
- assert_equal(typer.default_type, typer.local_type(ast1.body, 'a'))
87
- assert_equal(typer.fixnum_type, ast1.body.inferred_type)
88
- assert_equal(typer.default_type, ast1.body.arguments.args[0].inferred_type)
78
+ assert_equal(typer.string_type, ast1.body[0].arguments.args[0].inferred_type)
89
79
 
90
80
  ast1 = AST.parse("#{def_foo}(a); {a => :string}; a; end")
91
81
  typer = Typer::Simple.new :bar
@@ -93,9 +83,9 @@ class TestTyper < Test::Unit::TestCase
93
83
  ast1.infer(typer)
94
84
 
95
85
  assert_equal(typer.string_type, typer.method_type(type, 'foo', [typer.string_type]))
96
- assert_equal(typer.string_type, typer.local_type(ast1.body, 'a'))
97
- assert_equal(typer.string_type, ast1.body.inferred_type)
98
- assert_equal(typer.string_type, ast1.body.arguments.args[0].inferred_type)
86
+ assert_equal(typer.string_type, typer.local_type(ast1.body[0].static_scope, 'a'))
87
+ assert_equal(typer.string_type, ast1.body[0].inferred_type)
88
+ assert_equal(typer.string_type, ast1.body[0].arguments.args[0].inferred_type)
99
89
 
100
90
  ast1 = AST.parse("#{def_foo}(a); {:return => :string}; end")
101
91
  typer = Typer::Simple.new :bar
@@ -104,141 +94,127 @@ class TestTyper < Test::Unit::TestCase
104
94
  ast1.infer(typer)
105
95
  typer.resolve(true)
106
96
  end
107
-
108
- ast1 = AST.parse("#{def_foo}(a); a = 'foo'; end")
109
- typer = Typer::Simple.new :bar
110
-
111
- ast1.infer(typer)
112
-
113
- assert_equal(typer.string_type, typer.method_type(type, 'foo', [typer.default_type]))
114
- assert_equal(typer.string_type, typer.local_type(ast1.body, 'a'))
115
- assert_equal(typer.string_type, ast1.body.inferred_type)
116
- assert_equal(typer.default_type, ast1.body.arguments.args[0].inferred_type)
117
-
118
- typer.resolve
119
-
120
- assert_equal(typer.string_type, ast1.body.arguments.args[0].inferred_type)
121
97
  end
122
98
  end
123
-
99
+
124
100
  def test_call
125
101
  ast = AST.parse("1.foo(2)").body
126
102
  typer = Typer::Simple.new "bar"
127
-
103
+
128
104
  typer.learn_method_type(typer.fixnum_type, "foo", [typer.fixnum_type], typer.string_type, [])
129
105
  assert_equal(typer.string_type, typer.method_type(typer.fixnum_type, "foo", [typer.fixnum_type]))
130
-
106
+
131
107
  ast.infer(typer)
132
-
108
+
133
109
  assert_equal(typer.string_type, ast.inferred_type)
134
-
110
+
135
111
  ast = AST.parse("def bar(a, b); {a => :fixnum, b => :string}; 1.0; end; def baz; bar(1, 'x'); end").body
136
-
112
+
137
113
  ast.infer(typer)
138
-
114
+
139
115
  assert_equal(typer.float_type, typer.method_type(typer.self_type, "bar", [typer.fixnum_type, typer.string_type]))
140
116
  assert_equal(typer.float_type, typer.method_type(typer.self_type, "baz", []))
141
117
  assert_equal(typer.float_type, ast.children[0].inferred_type)
142
118
  assert_equal(typer.float_type, ast.children[1].inferred_type)
143
-
119
+
144
120
  # Reverse the order, ensure deferred inference succeeds
145
121
  ast = AST.parse("def baz; bar(1, 'x'); end; def bar(a, b); {a => :fixnum, b => :string}; 1.0; end").body
146
122
  typer = Typer::Simple.new("bar")
147
-
123
+
148
124
  ast.infer(typer)
149
-
125
+
150
126
  assert_equal(typer.default_type, typer.method_type(typer.self_type, "baz", []))
151
127
  assert_equal(typer.float_type, typer.method_type(typer.self_type, "bar", [typer.fixnum_type, typer.string_type]))
152
128
  assert_equal(typer.default_type, ast.children[0].inferred_type)
153
129
  assert_equal(typer.float_type, ast.children[1].inferred_type)
154
-
130
+
155
131
  # allow resolution to run
156
132
  assert_nothing_raised {typer.resolve}
157
-
133
+
158
134
  assert_equal(typer.float_type, typer.method_type(typer.self_type, "baz", []))
159
135
  assert_equal(typer.float_type, typer.method_type(typer.self_type, "bar", [typer.fixnum_type, typer.string_type]))
160
136
  assert_equal(typer.float_type, ast.children[0].inferred_type)
161
137
  assert_equal(typer.float_type, ast.children[1].inferred_type)
162
-
138
+
163
139
  # modify bar call to have bogus types, ensure resolution fails
164
140
  ast = AST.parse("def baz; bar(1, 1); end; def bar(a, b); {a => :fixnum, b => :string}; 1.0; end").body
165
141
  typer = Typer::Simple.new("bar")
166
-
142
+
167
143
  ast.infer(typer)
168
-
144
+
169
145
  assert_equal(typer.default_type, typer.method_type(typer.self_type, "baz", []))
170
146
  assert_equal(typer.float_type, typer.method_type(typer.self_type, "bar", [typer.fixnum_type, typer.string_type]))
171
147
  assert_equal(typer.default_type, ast.children[0].inferred_type)
172
148
  assert_equal(typer.float_type, ast.children[1].inferred_type)
173
-
149
+
174
150
  # allow resolution to run and produce error
175
151
  assert_raise(Typer::InferenceError) {typer.resolve(true)}
176
152
  error_nodes = typer.errors.map {|e| e.node}
177
153
  inspected = "[FunctionalCall(bar)\n Fixnum(1)\n Fixnum(1)]"
178
154
  assert_equal(inspected, error_nodes.inspect)
179
155
  end
180
-
156
+
181
157
  def test_if
182
- ast = AST.parse("if true; 1.0; else; ''; end").body
158
+ ast = AST.parse("if true; 1.0; else; ''; end").body[0]
183
159
  typer = Typer::Simple.new("bar")
184
-
160
+
185
161
  # incompatible body types
186
162
  assert_raise(Typer::InferenceError) {ast.infer(typer)}
187
-
188
- ast = AST.parse("if true; 1.0; else; 2.0; end").body
189
-
163
+
164
+ ast = AST.parse("if true; 1.0; else; 2.0; end").body[0]
165
+
190
166
  assert_nothing_raised {ast.infer(typer); typer.resolve(true)}
191
-
167
+
192
168
  assert_equal(typer.boolean_type, ast.condition.inferred_type)
193
169
  assert_equal(typer.float_type, ast.body.inferred_type)
194
170
  assert_equal(typer.float_type, ast.else.inferred_type)
195
-
196
- ast = AST.parse("if foo; bar; else; baz; end").body
197
-
171
+
172
+ ast = AST.parse("if foo; bar; else; baz; end").body[0]
173
+
198
174
  assert_nothing_raised {ast.infer(typer)}
199
-
175
+
200
176
  assert_equal(typer.default_type, ast.condition.inferred_type)
201
177
  assert_equal(typer.default_type, ast.body.inferred_type)
202
178
  assert_equal(typer.default_type, ast.else.inferred_type)
203
-
179
+
204
180
  # unresolved types for the foo, bar, and baz calls
205
181
  assert_raise(Typer::InferenceError) {typer.resolve(true)}
206
-
207
- ast2 = AST.parse("def foo; 1; end; def bar; 1.0; end")
208
-
182
+
183
+ ast2 = AST.parse("def foo; 1; end; def bar; 1.0; end")[0]
184
+
209
185
  ast2.infer(typer)
210
186
  ast.infer(typer)
211
-
187
+
212
188
  # unresolved types for the baz call
213
189
  assert_raise(Typer::InferenceError) {typer.resolve(true)}
214
-
190
+
215
191
  assert_equal(AST.error_type, ast.condition.inferred_type)
216
192
  assert_equal(AST.error_type, ast.body.inferred_type)
217
193
  assert_equal(AST.error_type, ast.else.inferred_type)
218
-
194
+
219
195
  typer.errors.clear
220
-
196
+
221
197
  ast2 = AST.parse("def baz; 2.0; end")
222
-
198
+
223
199
  ast2.infer(typer)
224
200
  ast.infer(typer)
225
-
201
+
226
202
  assert_nothing_raised {typer.resolve(true)}
227
-
228
- assert_equal(typer.float_type, ast2.body.inferred_type)
203
+
204
+ assert_equal(typer.float_type, ast2.body[0].inferred_type)
229
205
  end
230
-
206
+
231
207
  def test_class
232
208
  ast = AST.parse("class Foo; def foo; 1; end; def baz; foo; end; end")
233
- cls = ast.body
209
+ cls = ast.body[0]
234
210
  foo = cls.body[0]
235
211
  baz = cls.body[1]
236
-
212
+
237
213
  typer = Typer::Simple.new("script")
238
214
  ast.infer(typer)
239
-
215
+
240
216
  assert_nothing_raised {typer.resolve(true)}
241
-
217
+
242
218
  assert_not_nil(typer.known_types["Foo"])
243
219
  assert(AST::TypeDefinition === typer.known_types["Foo"])
244
220
  assert_equal(typer.known_types["Foo"], cls.inferred_type)
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 3
9
+ version: 0.0.3
5
10
  platform: java
6
11
  authors:
7
12
  - Charles Oliver Nutter
@@ -10,19 +15,24 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2010-02-15 19:19:39.063000 -06:00
18
+ date: 2010-06-09 15:09:02.286000 -04:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: bitescript
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
21
26
  requirements:
22
27
  - - ">="
23
28
  - !ruby/object:Gem::Version
24
- version: 0.0.5
25
- version:
29
+ segments:
30
+ - 0
31
+ - 0
32
+ - 6
33
+ version: 0.0.6
34
+ type: :runtime
35
+ version_requirements: *id001
26
36
  description: |-
27
37
  Duby is a customizable programming language featuring static types,
28
38
  local type inference and a heavily Ruby-inspired syntax. Duby
@@ -47,6 +57,7 @@ files:
47
57
  - lib/duby.rb
48
58
  - lib/duby/ast.rb
49
59
  - lib/duby/compiler.rb
60
+ - lib/duby/env.rb
50
61
  - lib/duby/nbcompiler.rb
51
62
  - lib/duby/transform.rb
52
63
  - lib/duby/typer.rb
@@ -59,7 +70,7 @@ files:
59
70
  - lib/duby/ast/method.rb
60
71
  - lib/duby/ast/structure.rb
61
72
  - lib/duby/ast/type.rb
62
- - lib/duby/c/compiler.rb
73
+ - lib/duby/jvm/base.rb
63
74
  - lib/duby/jvm/compiler.rb
64
75
  - lib/duby/jvm/method_lookup.rb
65
76
  - lib/duby/jvm/source_compiler.rb
@@ -79,40 +90,41 @@ files:
79
90
  - lib/duby/jvm/types/literals.rb
80
91
  - lib/duby/jvm/types/methods.rb
81
92
  - lib/duby/jvm/types/number.rb
82
- - lib/duby/old/compiler_old.rb
83
- - lib/duby/old/declaration.rb
84
- - lib/duby/old/mapper.rb
85
- - lib/duby/old/signature.rb
86
- - lib/duby/old/typer_old.rb
87
93
  - lib/duby/plugin/edb.rb
88
94
  - lib/duby/plugin/java.rb
89
- - lib/duby/plugin/math.rb
90
95
  - test/test_ast.rb
91
96
  - test/test_compilation.rb
97
+ - test/test_env.rb
92
98
  - test/test_java_typer.rb
93
99
  - test/test_javac_compiler.rb
94
100
  - test/test_jvm_compiler.rb
95
- - test/test_math_plugin.rb
96
101
  - test/test_typer.rb
97
102
  - test/TestUser.class
103
+ - examples/bintrees.duby
98
104
  - examples/construction.duby
105
+ - examples/dynamic.duby
99
106
  - examples/edb.duby
100
107
  - examples/fib.duby
101
108
  - examples/fields.duby
102
109
  - examples/fractal.duby
103
110
  - examples/java_thing.duby
104
- - examples/README
105
111
  - examples/simple_class.duby
112
+ - examples/sort_closure.duby
106
113
  - examples/swing.duby
107
114
  - examples/tak.duby
108
115
  - examples/test.edb
109
- - examples/appengine/config.ru
116
+ - examples/ant/example-build.xml
110
117
  - examples/appengine/Rakefile
111
118
  - examples/appengine/Readme
119
+ - examples/appengine/lib/duby_task.rb
120
+ - examples/appengine/lib/duby/appengine_tasks.rb
112
121
  - examples/appengine/lib/duby/plugin/datastore.rb
122
+ - examples/appengine/src/config.ru
113
123
  - examples/appengine/src/com/google/appengine/ext/duby/db/Model.duby
114
124
  - examples/appengine/src/com/ribrdb/DubyApp.duby
115
125
  - examples/appengine/src/com/ribrdb/list.dhtml
126
+ - javalib/duby-bootstrap.jar
127
+ - javalib/dynalang-invoke-0.1.jar
116
128
  - javalib/JRubyParser.jar
117
129
  - History.txt
118
130
  - README.txt
@@ -128,29 +140,33 @@ rdoc_options:
128
140
  require_paths:
129
141
  - lib
130
142
  required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
131
144
  requirements:
132
145
  - - ">="
133
146
  - !ruby/object:Gem::Version
147
+ segments:
148
+ - 0
134
149
  version: "0"
135
- version:
136
150
  required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
137
152
  requirements:
138
153
  - - ">="
139
154
  - !ruby/object:Gem::Version
155
+ segments:
156
+ - 0
140
157
  version: "0"
141
- version:
142
158
  requirements: []
143
159
 
144
160
  rubyforge_project: duby
145
- rubygems_version: 1.3.5
161
+ rubygems_version: 1.3.7
146
162
  signing_key:
147
163
  specification_version: 3
148
164
  summary: Duby is a customizable programming language featuring static types, local type inference and a heavily Ruby-inspired syntax
149
165
  test_files:
150
166
  - test/test_ast.rb
151
167
  - test/test_compilation.rb
168
+ - test/test_env.rb
152
169
  - test/test_java_typer.rb
153
170
  - test/test_javac_compiler.rb
154
171
  - test/test_jvm_compiler.rb
155
- - test/test_math_plugin.rb
156
172
  - test/test_typer.rb