mirah 0.0.8-java → 0.0.9-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/History.txt +28 -0
  2. data/examples/macros/square.mirah +15 -0
  3. data/examples/macros/square_int.mirah +15 -0
  4. data/examples/macros/string-each-char.mirah +15 -0
  5. data/examples/rosettacode/100-doors.mirah +16 -0
  6. data/examples/rosettacode/99-bottles-of-beer.mirah +16 -0
  7. data/examples/rosettacode/arrays.mirah +21 -0
  8. data/examples/rosettacode/boolean-values.mirah +15 -0
  9. data/examples/rosettacode/comments.mirah +20 -1
  10. data/examples/rosettacode/copy-a-string.mirah +16 -0
  11. data/examples/rosettacode/count-occurrences-of-a-substring.mirah +16 -0
  12. data/examples/rosettacode/create-a-file.mirah +16 -0
  13. data/examples/rosettacode/empty-string.mirah +15 -0
  14. data/examples/rosettacode/factorial.mirah +15 -0
  15. data/examples/rosettacode/fibonacci.mirah +15 -0
  16. data/examples/rosettacode/file-size.mirah +16 -0
  17. data/examples/rosettacode/fizz-buzz.mirah +16 -0
  18. data/examples/rosettacode/flatten-a-list.mirah +15 -0
  19. data/examples/rosettacode/guess-the-number.mirah +15 -0
  20. data/examples/rosettacode/hamming-numbers.mirah +49 -0
  21. data/examples/rosettacode/host-introspection.mirah +17 -0
  22. data/examples/rosettacode/hostname.mirah +18 -0
  23. data/examples/rosettacode/is-string-numeric.mirah +15 -0
  24. data/examples/rosettacode/palindrome.mirah +15 -0
  25. data/examples/rosettacode/random-numbers.mirah +25 -0
  26. data/examples/rosettacode/repeat-a-string.mirah +16 -0
  27. data/examples/rosettacode/reverse-a-string.mirah +15 -0
  28. data/examples/rosettacode/rot-13.mirah +15 -0
  29. data/examples/rosettacode/secure-temporary-file.mirah +23 -0
  30. data/examples/rosettacode/sleep.mirah +22 -0
  31. data/examples/rosettacode/sort-integer-array.mirah +35 -0
  32. data/examples/rosettacode/string-case.mirah +19 -0
  33. data/examples/rosettacode/string-length.mirah +31 -0
  34. data/examples/rosettacode/user-input.mirah +15 -0
  35. data/javalib/mirah-bootstrap.jar +0 -0
  36. data/lib/mirah/ast/call.rb +1 -1
  37. data/lib/mirah/ast/intrinsics.rb +1 -1
  38. data/lib/mirah/commands/run.rb +1 -1
  39. data/lib/mirah/jvm/compiler/jvm_bytecode.rb +1 -1
  40. data/lib/mirah/jvm/source_generator/builder.rb +4 -0
  41. data/lib/mirah/transform/helper.rb +4 -0
  42. data/lib/mirah/util/class_loader.rb +5 -33
  43. data/lib/mirah/version.rb +1 -1
  44. data/test/core/test_compilation.rb +7 -0
  45. data/test/jvm/bytecode_test_helper.rb +3 -1
  46. data/test/jvm/test_jvm_compiler.rb +25 -0
  47. metadata +12 -2
@@ -1,3 +1,31 @@
1
+ === 0.0.9 / 2011-09-12
2
+
3
+ a5963ef use self hosted classloader fixes #144
4
+ a858a2f fix for #114
5
+ 989fd1b fix #119, add transform for empty array literal
6
+ a474b84 fix #120, java source now prints out longs as <n>L
7
+ 0e25733 bump version to 0.0.9{dev, -SNAPSHOT}
8
+ fb34f03 fix #138, underscores and dashes both act the same
9
+ cffd819 Merge pull request #143 from hackergarten/master
10
+ 0f3af83 sorting lists and arrays examples
11
+ 59662e2 string 'character' length example
12
+ 9e541df string case example
13
+ f8174ac sleep example
14
+ 04399d3 secure temporary file example
15
+ d77902c host instrospection example
16
+ c0433a5 hostname example
17
+ ab134aa hamming numbers example
18
+ d468081 arrays examples
19
+ e8425f3 random number example
20
+ e974827 Merge pull request #142 from consiliens/master
21
+ 084aa65 Update NOTICE.
22
+ 735983f Merge pull request #140 from abscondment/140-ant-compile
23
+ d2a4010 Allow for false case too. #140
24
+ a7925ed Fixes #140 by * Raising an Exception in MirahCommand.compile if Mirah.compile fails (i.e. it returns nil) * Allowing that exception to pass through the two layers of scope in the ant task so Ant will actually see it and fail accordingly.
25
+ 7244e11 Merge pull request #139 from hackergarten/master
26
+ f0ef0d5 added apache license to all samples files.
27
+ a4f8cf0 added multiline comments example
28
+
1
29
  === 0.0.8 / 2011-08-31
2
30
 
3
31
  af43b77 Merge pull request #132 from hackergarten/master
@@ -1,3 +1,18 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
 
2
17
 
3
18
  macro def sqrt(input)
@@ -1,3 +1,18 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
 
2
17
 
3
18
  macro def sqrt(input)
@@ -1,3 +1,18 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
 
2
17
  macro def eachChar(value, &block)
3
18
 
@@ -1,3 +1,19 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
1
17
  import java.util.ArrayList
2
18
 
3
19
  class Door
@@ -1,3 +1,19 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
1
17
  plural = 's'
2
18
  99.downto(1) do |i|
3
19
  puts "#{i} bottle#{plural} of beer on the wall,"
@@ -0,0 +1,21 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ array = int[10]
17
+ array[0] = 42
18
+ puts array[0]
19
+
20
+
21
+
@@ -1,3 +1,18 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
  import java.util.ArrayList
2
17
  import java.util.HashMap
3
18
 
@@ -1,2 +1,21 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
  puts 'code' # I am a comment
2
-
17
+
18
+ /*
19
+ Here is a multi-
20
+ line comment.
21
+ */
@@ -1,3 +1,19 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
1
17
  src = "Hello"
2
18
  new_alias = src
3
19
 
@@ -1,3 +1,19 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
1
17
  import java.util.regex.Pattern
2
18
  import java.util.regex.Matcher
3
19
 
@@ -1,3 +1,19 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
1
17
  import java.io.File
2
18
 
3
19
  File.new('output.txt').createNewFile()
@@ -1,3 +1,18 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
 
2
17
  empty_string1 = ""
3
18
  empty_string2 = String.new
@@ -1,3 +1,18 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
  def factorial_iterative(n:int)
2
17
  2.upto(n-1) do |i|
3
18
  n *= i
@@ -1,3 +1,18 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
 
2
17
  def fibonacci(n:int)
3
18
  return n if n < 2
@@ -1,3 +1,19 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
1
17
  import java.io.File
2
18
 
3
19
  puts File.new('file-size.mirah').length()
@@ -1,3 +1,19 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
1
17
  1.upto(100) do |n|
2
18
  print "Fizz" if a = ((n % 3) == 0)
3
19
  print "Buzz" if b = ((n % 5) == 0)
@@ -1,3 +1,18 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
  import java.util.ArrayList
2
17
  import java.util.List
3
18
  import java.util.Collection
@@ -1,3 +1,18 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
  def getInput:int
2
17
  s = System.console.readLine()
3
18
  Integer.parseInt(s)
@@ -0,0 +1,49 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import java.math.BigInteger
17
+ import java.util.PriorityQueue
18
+
19
+ def updateFrontier(x:BigInteger, queue:PriorityQueue):void
20
+ queue.offer(x.shiftLeft(1))
21
+ queue.offer(x.multiply(BigInteger.valueOf(3)))
22
+ queue.offer(x.multiply(BigInteger.valueOf(5)))
23
+ end
24
+
25
+ def hamming(n:int):BigInteger
26
+ raise "Invalid parameter" if (n <= 0)
27
+
28
+ frontier = PriorityQueue.new
29
+ updateFrontier(BigInteger.ONE, frontier)
30
+ lowest = BigInteger.ONE
31
+ 1.upto(n-1) do | i |
32
+ lowest = BigInteger(frontier.poll())
33
+ while (frontier.peek().equals(lowest))
34
+ frontier.poll()
35
+ end
36
+ updateFrontier(lowest, frontier)
37
+ end
38
+ lowest
39
+ end
40
+
41
+
42
+ nums = ""
43
+ 1.upto(20) do | i |
44
+ nums = nums + " #{hamming(i)}"
45
+ end
46
+ puts "Hamming(1 .. 20) =#{nums}"
47
+ puts "\nHamming(1691) = #{hamming(1691)}"
48
+ puts "Hamming(1000000) = #{hamming(1000000)}"
49
+
@@ -0,0 +1,17 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ puts "word size: #{System.getProperty("sun.arch.data.model")}"
17
+ puts "endianness: #{System.getProperty("sun.cpu.endian")}"
@@ -0,0 +1,18 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import java.net.InetAddress
17
+
18
+ puts InetAddress.getLocalHost().getHostName()
@@ -1,3 +1,18 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
  import java.text.NumberFormat
2
17
  import java.text.ParsePosition
3
18
  import java.util.Scanner
@@ -1,3 +1,18 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
 
2
17
  def reverse(s:string)
3
18
  StringBuilder.new(s).reverse.toString()
@@ -0,0 +1,25 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import java.util.Random
17
+
18
+ list = double[999]
19
+ mean = 1.0
20
+ std = 0.5
21
+ rng = Random.new
22
+ 0.upto(998) do | i |
23
+ list[i] = mean + std * rng.nextGaussian
24
+ end
25
+
@@ -1,3 +1,19 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
1
17
  x = ""
2
18
 
3
19
  5.times do
@@ -1,3 +1,18 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
 
2
17
  def reverse(s:string)
3
18
  StringBuilder.new(s).reverse
@@ -1,3 +1,18 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
 
2
17
 
3
18
  def rot13 (value:string)
@@ -0,0 +1,23 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import java.io.File
17
+
18
+ filename = File.createTempFile('prefix', '.suffix')
19
+
20
+ # Delete temp file when program exits
21
+ filename.deleteOnExit()
22
+
23
+ puts filename
@@ -0,0 +1,22 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import java.util.Scanner
17
+
18
+ puts 'Enter time to sleep in milliseconds: '
19
+ ms = Scanner.new(System.in).nextInt()
20
+ puts 'Sleeping...'
21
+ Thread.sleep(ms)
22
+ puts 'Awake!'
@@ -0,0 +1,35 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import java.util.Arrays
17
+ import java.util.ArrayList
18
+ import java.util.Collections
19
+
20
+ # Sorting arrays
21
+ nums = [2, 4, 3, 1, 2].toArray
22
+ puts Arrays.toString(nums)
23
+ Arrays.sort(nums)
24
+ puts Arrays.toString(nums)
25
+
26
+
27
+ # Sorting collections and lists
28
+
29
+ # list literals are immutable, so make an ArrayList
30
+ list = ArrayList.new
31
+ list.addAll([2,4,3,1,2])
32
+ puts list
33
+ Collections.sort(list)
34
+ puts list
35
+
@@ -0,0 +1,19 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
17
+ str = "alphaBETA"
18
+ puts str.toUpperCase()
19
+ puts str.toLowerCase()
@@ -0,0 +1,31 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ /**
17
+ * Java encodes strings in UTF-16, which represents each character with one
18
+ * or two 16-bit values. The length method of String objects returns the
19
+ * number of 16-bit values used to encode a string, so the number of bytes
20
+ * can be determined by doubling that number.
21
+ */
22
+
23
+ s = "Hello, world!"
24
+ puts s.length() * 2
25
+
26
+ /**
27
+ * Another way to know the byte length of a string is to explicitly
28
+ * specify the charset we desire.
29
+ */
30
+ puts s.getBytes("UTF-16").length
31
+ puts s.getBytes("UTF-8").length
@@ -1,3 +1,18 @@
1
+ # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
+ # All contributing project authors may be found in the NOTICE file.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
1
16
 
2
17
  s = System.console.readLine()
3
18
 
Binary file
@@ -91,7 +91,7 @@ module Mirah::AST
91
91
  end
92
92
  end
93
93
 
94
- if @inferred_type
94
+ if @inferred_type && !@inferred_type.error?
95
95
  if block
96
96
  method = receiver_type.get_method(name, parameter_types)
97
97
  block.prepare(typer, method)
@@ -368,7 +368,7 @@ module Mirah::AST
368
368
  compiler.generate do |outfile, builder|
369
369
  bytes = builder.generate
370
370
  name = builder.class_name.gsub(/\//, '.')
371
- class_map[name] = bytes
371
+ class_map[name] = Mirah::Util::ClassLoader.binary_string bytes
372
372
  if transformer.state.save_extensions
373
373
  outfile = "#{transformer.destination}#{outfile}"
374
374
  FileUtils.mkdir_p(File.dirname(outfile))
@@ -28,7 +28,7 @@ module Mirah
28
28
  generator = Mirah::Generator.new(@state, @state.compiler_class, false, @state.verbose)
29
29
 
30
30
  generator.generate(args).each do |result|
31
- class_map[result.classname.gsub(/\//, '.')] = result.bytes
31
+ class_map[result.classname.gsub(/\//, '.')] = Mirah::Util::ClassLoader.binary_string result.bytes
32
32
  end
33
33
 
34
34
  # load all classes
@@ -16,7 +16,7 @@ module Mirah
16
16
 
17
17
  def classname_from_filename(filename)
18
18
  basename = File.basename(filename).sub(/\.(duby|mirah)$/, '')
19
- basename.split(/_/).map{|x| x[0...1].upcase + x[1..-1]}.join
19
+ basename.split(/[_-]/).map{|x| x[0...1].upcase + x[1..-1]}.join
20
20
  end
21
21
  end
22
22
 
@@ -436,6 +436,10 @@ module Mirah
436
436
  def ldc_double(value)
437
437
  print value
438
438
  end
439
+
440
+ def ldc_long(value)
441
+ print "#{value}L"
442
+ end
439
443
 
440
444
  def ldc_class(type)
441
445
  print "#{type.to_source}.class"
@@ -159,6 +159,10 @@ module Mirah
159
159
  end
160
160
  end
161
161
 
162
+ def transform_zarray(node, parent)
163
+ Mirah::AST::Array.new(parent, position(node))
164
+ end
165
+
162
166
  def transform_array(node, parent)
163
167
  Mirah::AST::Array.new(parent, position(node)) do |array|
164
168
  node.children.map {|child| transformer.transform(child, array)}
@@ -1,37 +1,9 @@
1
- # This is a custom classloader impl to allow loading classes with
2
- # interdependencies by having findClass retrieve classes as needed from the
3
- # collection of all classes generated by the target script.
4
1
  module Mirah
5
2
  module Util
6
- class ClassLoader < java::security::SecureClassLoader
7
- def initialize(parent, class_map)
8
- super(parent)
9
- @class_map = class_map
10
- end
11
-
12
- def findClass(name)
13
- if @class_map[name]
14
- bytes = @class_map[name].to_java_bytes
15
- defineClass(name, bytes, 0, bytes.length)
16
- else
17
- raise java.lang.ClassNotFoundException.new(name)
18
- end
19
- end
20
-
21
- def loadClass(name, resolve)
22
- cls = findLoadedClass(name)
23
- if cls == nil
24
- if @class_map[name]
25
- cls = findClass(name)
26
- else
27
- cls = super(name, false)
28
- end
29
- end
30
-
31
- resolveClass(cls) if resolve
32
-
33
- cls
34
- end
35
- end
3
+
4
+ ClassLoader = Java::OrgMirah::MirahClassLoader
5
+ def ClassLoader.binary_string string
6
+ java.lang.String.new string.to_java_bytes, "ISO-8859-1"
7
+ end
36
8
  end
37
9
  end
@@ -14,5 +14,5 @@
14
14
  # limitations under the License.
15
15
 
16
16
  module Mirah
17
- VERSION = "0.0.8"
17
+ VERSION = "0.0.9"
18
18
  end
@@ -124,4 +124,11 @@ class TestAst < Test::Unit::TestCase
124
124
  assert_equal([[:empty_array, nil]], @compiler.calls)
125
125
  assert_equal(5, size.literal)
126
126
  end
127
+
128
+ def test_empty_literal_array
129
+ new_ast = AST.parse("[]").body[0]
130
+ new_ast.compile(@compiler, true)
131
+
132
+ assert_equal([:array, a(Mirah::AST::Array), true], @compiler.calls.first)
133
+ end
127
134
  end
@@ -19,6 +19,8 @@ require 'jruby'
19
19
  require 'stringio'
20
20
  require 'fileutils'
21
21
 
22
+ #$CLASSPATH << File.expand_path("#{File.dirname(__FILE__)}/../..")
23
+
22
24
  unless Mirah::AST.macro "__gloop__"
23
25
  Mirah::AST.defmacro "__gloop__" do |transformer, fcall, parent|
24
26
  Mirah::AST::Loop.new(parent, parent.position, true, false) do |loop|
@@ -104,7 +106,7 @@ module JVMCompiler
104
106
  open("#{filename}", "wb") do |f|
105
107
  f << bytes
106
108
  end
107
- classes[filename[0..-7]] = bytes
109
+ classes[filename[0..-7]] = Mirah::Util::ClassLoader.binary_string bytes
108
110
  end
109
111
 
110
112
  loader = Mirah::Util::ClassLoader.new(JRuby.runtime.jruby_class_loader, classes)
@@ -312,6 +312,16 @@ class TestJVMCompiler < Test::Unit::TestCase
312
312
  assert_equal('ClassDeclTest', foo.java_class.name)
313
313
  end
314
314
 
315
+ def test_class_name_from_file_with_underscore
316
+ foo, = compile("puts 'blah'", 'class_name_test.mirah')
317
+ assert_equal('ClassNameTest', foo.java_class.name)
318
+ end
319
+
320
+ def test_class_name_from_file_with_dash
321
+ foo, = compile("puts 'blah'", 'class-dash-test.mirah')
322
+ assert_equal('ClassDashTest', foo.java_class.name)
323
+ end
324
+
315
325
  def test_puts
316
326
  cls, = compile("def foo;puts 'Hello World!';end")
317
327
  output = capture_output do
@@ -2461,6 +2471,13 @@ class TestJVMCompiler < Test::Unit::TestCase
2461
2471
  end
2462
2472
  end
2463
2473
 
2474
+ def test_long_generation
2475
+ cls, = compile(<<-EOF)
2476
+ c = 2_000_000_000_000
2477
+ puts c
2478
+ EOF
2479
+ end
2480
+
2464
2481
  def test_empty_rescues
2465
2482
  cls, = compile(<<-EOF)
2466
2483
  begin
@@ -2478,4 +2495,12 @@ class TestJVMCompiler < Test::Unit::TestCase
2478
2495
  nil
2479
2496
  EOF
2480
2497
  end
2498
+
2499
+ def test_missing_class_with_block_raises_inference_error
2500
+ assert_raises Typer::InferenceError do
2501
+ compile("Interface Implements_Go do; end")
2502
+ end
2503
+ end
2504
+
2505
+
2481
2506
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mirah
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.8
5
+ version: 0.0.9
6
6
  platform: java
7
7
  authors:
8
8
  - Charles Oliver Nutter
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-08-31 00:00:00 -06:00
14
+ date: 2011-09-12 00:00:00 -06:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -176,6 +176,7 @@ files:
176
176
  - examples/plugins/appengine/test/com/google/appengine/ext/duby/db/ModelTest.duby
177
177
  - examples/rosettacode/100-doors.mirah
178
178
  - examples/rosettacode/99-bottles-of-beer.mirah
179
+ - examples/rosettacode/arrays.mirah
179
180
  - examples/rosettacode/boolean-values.mirah
180
181
  - examples/rosettacode/comments.mirah
181
182
  - examples/rosettacode/copy-a-string.mirah
@@ -188,12 +189,21 @@ files:
188
189
  - examples/rosettacode/fizz-buzz.mirah
189
190
  - examples/rosettacode/flatten-a-list.mirah
190
191
  - examples/rosettacode/guess-the-number.mirah
192
+ - examples/rosettacode/hamming-numbers.mirah
193
+ - examples/rosettacode/host-introspection.mirah
194
+ - examples/rosettacode/hostname.mirah
191
195
  - examples/rosettacode/is-string-numeric.mirah
192
196
  - examples/rosettacode/palindrome.mirah
197
+ - examples/rosettacode/random-numbers.mirah
193
198
  - examples/rosettacode/README.txt
194
199
  - examples/rosettacode/repeat-a-string.mirah
195
200
  - examples/rosettacode/reverse-a-string.mirah
196
201
  - examples/rosettacode/rot-13.mirah
202
+ - examples/rosettacode/secure-temporary-file.mirah
203
+ - examples/rosettacode/sleep.mirah
204
+ - examples/rosettacode/sort-integer-array.mirah
205
+ - examples/rosettacode/string-case.mirah
206
+ - examples/rosettacode/string-length.mirah
197
207
  - examples/rosettacode/user-input.mirah
198
208
  - javalib/dynalink-0.2.jar
199
209
  - javalib/mirah-bootstrap.jar