duby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +68 -0
  3. data/README.txt +31 -0
  4. data/Rakefile +37 -0
  5. data/bin/duby +9 -0
  6. data/bin/dubyc +9 -0
  7. data/bin/dubyp +9 -0
  8. data/examples/appengine/src/com/google/appengine/ext/duby/db/Model.duby +132 -0
  9. data/examples/appengine/src/com/ribrdb/DubyApp.duby +28 -0
  10. data/examples/bench_fractal.duby +57 -0
  11. data/examples/construction.duby +8 -0
  12. data/examples/edb.duby +3 -0
  13. data/examples/fib.duby +24 -0
  14. data/examples/fields.duby +22 -0
  15. data/examples/java_thing.duby +13 -0
  16. data/examples/simple_class.duby +12 -0
  17. data/examples/swing.duby +20 -0
  18. data/examples/tak.duby +15 -0
  19. data/javalib/JRubyParser.jar +0 -0
  20. data/lib/duby.rb +170 -0
  21. data/lib/duby/ast.rb +340 -0
  22. data/lib/duby/ast/call.rb +73 -0
  23. data/lib/duby/ast/class.rb +145 -0
  24. data/lib/duby/ast/flow.rb +328 -0
  25. data/lib/duby/ast/intrinsics.rb +46 -0
  26. data/lib/duby/ast/literal.rb +93 -0
  27. data/lib/duby/ast/local.rb +77 -0
  28. data/lib/duby/ast/method.rb +187 -0
  29. data/lib/duby/ast/structure.rb +44 -0
  30. data/lib/duby/ast/type.rb +93 -0
  31. data/lib/duby/c/compiler.rb +134 -0
  32. data/lib/duby/compiler.rb +261 -0
  33. data/lib/duby/jvm/compiler.rb +684 -0
  34. data/lib/duby/jvm/method_lookup.rb +185 -0
  35. data/lib/duby/jvm/source_compiler.rb +516 -0
  36. data/lib/duby/jvm/source_generator/builder.rb +368 -0
  37. data/lib/duby/jvm/source_generator/loops.rb +132 -0
  38. data/lib/duby/jvm/source_generator/precompile.rb +154 -0
  39. data/lib/duby/jvm/source_generator/typer.rb +11 -0
  40. data/lib/duby/jvm/typer.rb +118 -0
  41. data/lib/duby/jvm/types.rb +326 -0
  42. data/lib/duby/jvm/types/basic_types.rb +18 -0
  43. data/lib/duby/jvm/types/boolean.rb +11 -0
  44. data/lib/duby/jvm/types/factory.rb +151 -0
  45. data/lib/duby/jvm/types/floats.rb +70 -0
  46. data/lib/duby/jvm/types/integers.rb +110 -0
  47. data/lib/duby/jvm/types/intrinsics.rb +157 -0
  48. data/lib/duby/jvm/types/literals.rb +82 -0
  49. data/lib/duby/jvm/types/methods.rb +344 -0
  50. data/lib/duby/jvm/types/number.rb +92 -0
  51. data/lib/duby/nbcompiler.rb +29 -0
  52. data/lib/duby/old/compiler_old.rb +845 -0
  53. data/lib/duby/old/declaration.rb +72 -0
  54. data/lib/duby/old/mapper.rb +72 -0
  55. data/lib/duby/old/signature.rb +52 -0
  56. data/lib/duby/old/typer_old.rb +163 -0
  57. data/lib/duby/plugin/edb.rb +25 -0
  58. data/lib/duby/plugin/java.rb +42 -0
  59. data/lib/duby/plugin/math.rb +84 -0
  60. data/lib/duby/transform.rb +908 -0
  61. data/lib/duby/typer.rb +359 -0
  62. data/test/test_ast.rb +391 -0
  63. data/test/test_compilation.rb +98 -0
  64. data/test/test_java_typer.rb +199 -0
  65. data/test/test_javac_compiler.rb +57 -0
  66. data/test/test_jvm_compiler.rb +1459 -0
  67. data/test/test_math_plugin.rb +87 -0
  68. data/test/test_typer.rb +246 -0
  69. metadata +155 -0
@@ -0,0 +1,4 @@
1
+ === 0.0.1 / 2009-10-27
2
+
3
+ * First gem release
4
+ * Most things necessary for simple apps, scripts, servlets are working
@@ -0,0 +1,68 @@
1
+ bin/duby
2
+ bin/dubyc
3
+ bin/dubyp
4
+ lib/duby.rb
5
+ lib/duby/ast.rb
6
+ lib/duby/compiler.rb
7
+ lib/duby/nbcompiler.rb
8
+ lib/duby/transform.rb
9
+ lib/duby/typer.rb
10
+ lib/duby/ast/call.rb
11
+ lib/duby/ast/class.rb
12
+ lib/duby/ast/flow.rb
13
+ lib/duby/ast/intrinsics.rb
14
+ lib/duby/ast/literal.rb
15
+ lib/duby/ast/local.rb
16
+ lib/duby/ast/method.rb
17
+ lib/duby/ast/structure.rb
18
+ lib/duby/ast/type.rb
19
+ lib/duby/c/compiler.rb
20
+ lib/duby/jvm/compiler.rb
21
+ lib/duby/jvm/method_lookup.rb
22
+ lib/duby/jvm/source_compiler.rb
23
+ lib/duby/jvm/typer.rb
24
+ lib/duby/jvm/types.rb
25
+ lib/duby/jvm/source_generator/builder.rb
26
+ lib/duby/jvm/source_generator/loops.rb
27
+ lib/duby/jvm/source_generator/precompile.rb
28
+ lib/duby/jvm/source_generator/typer.rb
29
+ lib/duby/jvm/types/basic_types.rb
30
+ lib/duby/jvm/types/boolean.rb
31
+ lib/duby/jvm/types/factory.rb
32
+ lib/duby/jvm/types/floats.rb
33
+ lib/duby/jvm/types/integers.rb
34
+ lib/duby/jvm/types/intrinsics.rb
35
+ lib/duby/jvm/types/literals.rb
36
+ lib/duby/jvm/types/methods.rb
37
+ lib/duby/jvm/types/number.rb
38
+ lib/duby/old/compiler_old.rb
39
+ lib/duby/old/declaration.rb
40
+ lib/duby/old/mapper.rb
41
+ lib/duby/old/signature.rb
42
+ lib/duby/old/typer_old.rb
43
+ lib/duby/plugin/edb.rb
44
+ lib/duby/plugin/java.rb
45
+ lib/duby/plugin/math.rb
46
+ test/test_ast.rb
47
+ test/test_compilation.rb
48
+ test/test_java_typer.rb
49
+ test/test_javac_compiler.rb
50
+ test/test_jvm_compiler.rb
51
+ test/test_math_plugin.rb
52
+ test/test_typer.rb
53
+ examples/bench_fractal.duby
54
+ examples/construction.duby
55
+ examples/edb.duby
56
+ examples/fib.duby
57
+ examples/fields.duby
58
+ examples/java_thing.duby
59
+ examples/simple_class.duby
60
+ examples/swing.duby
61
+ examples/tak.duby
62
+ examples/appengine/src/com/google/appengine/ext/duby/db/Model.duby
63
+ examples/appengine/src/com/ribrdb/DubyApp.duby
64
+ History.txt
65
+ Manifest.txt
66
+ README.txt
67
+ Rakefile
68
+ javalib/JRubyParser.jar
@@ -0,0 +1,31 @@
1
+ = duby
2
+
3
+ * http://kenai.com/projects/duby
4
+
5
+ == DESCRIPTION:
6
+
7
+ Duby is a customizable programming language featuring static types, local type inference and a heavily Ruby-inspired syntax. Duby currently includes a typer/compiler backend for the JVM which can output either JVM bytecode or Java source files.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * Ruby syntax
12
+ * Compiles to .class or .java
13
+ * Fast as Java
14
+
15
+ == SYNOPSIS:
16
+
17
+ duby <script.duby>
18
+ duby -e "inline script"
19
+ dubyc <script.duby>
20
+ dubyc -e "inline script" # produces dash_e.class
21
+ dubyc -java <script.duby>
22
+ dubyc -java -e "inline script" # produces dash_e.java
23
+
24
+ == REQUIREMENTS:
25
+
26
+ * JRuby 1.4RC2 or higher.
27
+ * BiteScript 0.0.4 or higher
28
+
29
+ == INSTALL:
30
+
31
+ * gem install duby
@@ -0,0 +1,37 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'java'
5
+ require 'hoe'
6
+
7
+ $: << 'lib'
8
+ require 'duby'
9
+
10
+ task :default => :test
11
+
12
+ Rake::TestTask.new :test do |t|
13
+ t.libs << "lib"
14
+ t.libs << "../jvmscript/lib"
15
+ t.test_files = FileList["test/**/*.rb"]
16
+ java.lang.System.set_property("jruby.duby.enabled", "true")
17
+ end
18
+
19
+ # update manifest
20
+ files = []
21
+ files.concat Dir['bin/*'].to_a
22
+ files.concat Dir['lib/**/*.rb'].to_a
23
+ files.concat Dir['test/**/*.rb'].to_a
24
+ files.concat Dir['examples/**/*.duby'].to_a
25
+ files << 'History.txt'
26
+ files << 'Manifest.txt'
27
+ files << 'README.txt'
28
+ files << 'Rakefile'
29
+ files << 'javalib/JRubyParser.jar'
30
+
31
+ File.open('Manifest.txt', 'w') {|f| f.write(files.join("\n"))}
32
+
33
+ Hoe.spec 'duby' do
34
+ developer('Charles Oliver Nutter', 'headius@headius.com')
35
+ developer('Ryan Brown', 'ribrdb@google.com')
36
+ extra_deps << ['bitescript', '>= 0.0.4']
37
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env jruby
2
+ begin
3
+ require 'duby'
4
+ rescue LoadError
5
+ $: << File.dirname(File.dirname(__FILE__)) + '/lib'
6
+ require 'duby'
7
+ end
8
+
9
+ Duby.run(*ARGV)
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env jruby
2
+ begin
3
+ require 'duby'
4
+ rescue LoadError
5
+ $: << File.dirname(File.dirname(__FILE__)) + '/lib'
6
+ require 'duby'
7
+ end
8
+
9
+ Duby.compile(*ARGV)
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env jruby
2
+ begin
3
+ require 'duby'
4
+ rescue LoadError
5
+ $: << File.dirname(File.dirname(__FILE__)) + '/lib'
6
+ require 'duby'
7
+ end
8
+
9
+ puts Duby.parse(*ARGV).inspect
@@ -0,0 +1,132 @@
1
+ import com.google.appengine.api.datastore.DatastoreServiceFactory
2
+ import com.google.appengine.api.datastore.Entity
3
+ import com.google.appengine.api.datastore.EntityNotFoundException
4
+ import com.google.appengine.api.datastore.Key
5
+ import com.google.appengine.api.datastore.KeyFactory
6
+ import com.google.appengine.api.datastore.Query
7
+ import 'Builder', 'com.google.appengine.api.datastore.FetchOptions$Builder'
8
+ import 'FilterOperator', 'com.google.appengine.api.datastore.Query$FilterOperator'
9
+ import 'SortDirection', 'com.google.appengine.api.datastore.Query$SortDirection'
10
+
11
+ class DQuery
12
+ def initialize
13
+ @query = Query.new(kind)
14
+ end
15
+
16
+ def kind
17
+ "foo"
18
+ end
19
+
20
+ def limit(l:int)
21
+ returns :void
22
+ if @options
23
+ @options.limit(l)
24
+ else
25
+ @options = Builder.withLimit(l)
26
+ end
27
+ end
28
+
29
+ def offset(o:int)
30
+ returns :void
31
+ if @options
32
+ @options.offset(o)
33
+ else
34
+ @options = Builder.withOffset(o)
35
+ end
36
+ end
37
+
38
+ def sort(name:String)
39
+ sort(name, false)
40
+ end
41
+
42
+ def sort(name:String, descending:boolean)
43
+ returns :void
44
+ if descending
45
+ @query.addSort(name, _desc)
46
+ else
47
+ @query.addSort(name)
48
+ end
49
+ end
50
+
51
+ def count
52
+ _prepare.countEntities
53
+ end
54
+
55
+ def _query
56
+ @query
57
+ end
58
+
59
+ def _options
60
+ if @options.nil?
61
+ @options = Builder.withOffset(0)
62
+ end
63
+ @options
64
+ end
65
+
66
+ def _prepare
67
+ Model._datastore.prepare(@query)
68
+ end
69
+
70
+ def _eq_op
71
+ FilterOperator.valueOf("EQUAL")
72
+ end
73
+
74
+ def _desc
75
+ SortDirection.valueOf("DESCENDING")
76
+ end
77
+ end
78
+
79
+ class Model
80
+ def initialize
81
+ end
82
+
83
+ def self._datastore
84
+ unless @service
85
+ @service = DatastoreServiceFactory.getDatastoreService
86
+ end
87
+ @service
88
+ end
89
+
90
+ def self.delete(key:Key)
91
+ returns :void
92
+ keys = Key[1]
93
+ keys[0] = key
94
+ Model._datastore.delete(keys)
95
+ end
96
+
97
+ def kind
98
+ getClass.getSimpleName
99
+ end
100
+
101
+ def key
102
+ if @entity
103
+ @entity.getKey
104
+ else
105
+ Key(nil)
106
+ end
107
+ end
108
+
109
+ def save
110
+ Model._datastore.put(to_entity)
111
+ end
112
+
113
+ def delete
114
+ returns :void
115
+ Model.delete(key)
116
+ end
117
+
118
+ def to_entity
119
+ unless @entity
120
+ @entity = Entity.new(kind)
121
+ end
122
+ _save_to(@entity)
123
+ @entity
124
+ end
125
+
126
+ # protected
127
+ def _save_to(e:Entity)
128
+ end
129
+
130
+ def _read_from(e:Entity)
131
+ end
132
+ end
@@ -0,0 +1,28 @@
1
+ import javax.servlet.http.HttpServlet
2
+ import com.google.appengine.ext.duby.db.Model
3
+
4
+ class Post < Model
5
+ def initialize; end
6
+
7
+ property title, String
8
+ property body, Text
9
+ end
10
+
11
+ class DubyApp < HttpServlet
12
+ def_edb(list, 'com/ribrdb/list.dhtml')
13
+
14
+ def doGet(request, response)
15
+ returns :void
16
+ @posts = Post.all.run
17
+ response.getWriter.write(list)
18
+ end
19
+
20
+ def doPost(request, response)
21
+ post = Post.new
22
+ post.title = request.getParameter('title')
23
+ post.body = Text.new(request.getParameter('body'))
24
+ post.save
25
+ doGet(request, response)
26
+ end
27
+
28
+ end
@@ -0,0 +1,57 @@
1
+ import java.lang.System
2
+
3
+ def run
4
+ puts "Rendering"
5
+ y = -39.0
6
+ while y <= 39.0
7
+ puts
8
+ x = -39.0
9
+ while x <= 39.0
10
+ i = iterate(x/40.0,y/40.0)
11
+ if (i == 0)
12
+ print "*"
13
+ else
14
+ print " "
15
+ end
16
+ x += 1
17
+ end
18
+ y += 1
19
+ end
20
+ puts
21
+ end
22
+
23
+ def iterate(x:double,y:double)
24
+ cr = y-0.5
25
+ ci = x
26
+ zi = 0.0
27
+ zr = 0.0
28
+ i = 0
29
+
30
+ result = 0
31
+ while true
32
+ i += 1
33
+ temp = zr * zi
34
+ zr2 = zr * zr
35
+ zi2 = zi * zi
36
+ zr = zr2 - zi2 + cr
37
+ zi = temp + temp + ci
38
+ if (zi2 + zr2 > 16)
39
+ result = i
40
+ break
41
+ end
42
+ if (i > 1000)
43
+ result = 0
44
+ break
45
+ end
46
+ end
47
+
48
+ result
49
+ end
50
+
51
+ i = 0
52
+ while i < 10
53
+ start = System.currentTimeMillis
54
+ run
55
+ puts "Time: " + (System.currentTimeMillis - start) / 1000.0
56
+ i += 1
57
+ end
@@ -0,0 +1,8 @@
1
+ import "java.lang.StringBuffer"
2
+ import "java.util.ArrayList"
3
+
4
+ list = ArrayList.new
5
+ sb = StringBuffer.new("Hello")
6
+ sb.append(", world")
7
+ list.add(sb)
8
+ puts list
@@ -0,0 +1,3 @@
1
+ def_edb :render, 'test.edb'
2
+ @message = "Hello"
3
+ puts render
@@ -0,0 +1,24 @@
1
+ import "java.lang.System"
2
+
3
+ def fib(a:int)
4
+ if a < 2
5
+ a
6
+ else
7
+ fib(a - 1) + fib(a - 2)
8
+ end
9
+ end
10
+
11
+ def bench(times:int)
12
+ while times > 0
13
+ time_start = System.currentTimeMillis
14
+ puts "fib(45):"
15
+ puts fib(45)
16
+ time_total = System.currentTimeMillis - time_start
17
+ puts "Total time:"
18
+ puts time_total
19
+ times -= 1
20
+ end
21
+ nil
22
+ end
23
+
24
+ bench 10
@@ -0,0 +1,22 @@
1
+ import 'java.util.ArrayList'
2
+
3
+ class Bar
4
+ def initialize
5
+ @a = ArrayList
6
+ end
7
+
8
+ def list=(a:ArrayList)
9
+ @a = a
10
+ end
11
+
12
+ def foo
13
+ puts @a
14
+ end
15
+ end
16
+
17
+ b = Bar.new
18
+ list = ArrayList.new
19
+ list.add('hello')
20
+ list.add('world')
21
+ b.list = list
22
+ b.foo