gettc 1.10 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/bin/gettc +60 -69
  3. data/dist/config.yml +1 -1
  4. data/dist/include/cpp/engine.rb +78 -86
  5. data/dist/include/cpp/topcoder +236 -236
  6. data/dist/include/go/engine.rb +53 -61
  7. data/dist/include/haskell/engine.rb +112 -122
  8. data/dist/include/java/engine.rb +187 -184
  9. data/dist/include/javascript/engine.rb +26 -30
  10. data/dist/include/javascript/topcoder.js +3 -3
  11. data/dist/include/javascript/topcoder/errors.js +5 -5
  12. data/dist/include/javascript/topcoder/reader.js +188 -165
  13. data/dist/include/javascript/topcoder/writer.js +37 -33
  14. data/dist/include/python/engine.rb +43 -52
  15. data/dist/include/python/topcoder/__init__.pyc +0 -0
  16. data/dist/include/python/topcoder/__pycache__/__init__.cpython-34.pyc +0 -0
  17. data/dist/include/python/topcoder/__pycache__/errors.cpython-34.pyc +0 -0
  18. data/dist/include/python/topcoder/__pycache__/reader.cpython-34.pyc +0 -0
  19. data/dist/include/python/topcoder/__pycache__/writer.cpython-34.pyc +0 -0
  20. data/dist/include/python/topcoder/errors.pyc +0 -0
  21. data/dist/include/python/topcoder/reader.pyc +0 -0
  22. data/dist/include/python/topcoder/writer.pyc +0 -0
  23. data/dist/include/ruby/engine.rb +47 -52
  24. data/dist/include/ruby/topcoder/reader.rb +205 -193
  25. data/dist/include/ruby/topcoder/writer.rb +39 -37
  26. data/dist/template/bin/runner.rb +146 -151
  27. data/dist/template/bin/runner.sh +96 -96
  28. data/dist/template/prob/{name}.html +1 -1
  29. data/dist/template/solve/cpp/{name}.cpp +3 -4
  30. data/dist/template/solve/cpp/{name}Solver.cpp +14 -14
  31. data/dist/template/solve/go/{name}/{name}.go +3 -3
  32. data/dist/template/solve/go/{name}Solver.go +2 -2
  33. data/dist/template/solve/haskell/{name}.hs +6 -6
  34. data/dist/template/solve/haskell/{name}Solver.hs +10 -10
  35. data/dist/template/solve/java/{name}.java +4 -4
  36. data/dist/template/solve/java/{name}Solver.java +4 -4
  37. data/dist/template/solve/javascript/{name}.js +4 -6
  38. data/dist/template/solve/javascript/{name}Solver.js +11 -9
  39. data/dist/template/solve/python/{name}.py +1 -1
  40. data/dist/template/solve/python/{name}Solver.py +2 -2
  41. data/dist/template/solve/ruby/{name}.rb +4 -4
  42. data/dist/template/solve/ruby/{name}Solver.rb +14 -17
  43. data/dist/template/util/check/check.cpp +19 -19
  44. data/{core/lib → lib}/gettc.rb +0 -0
  45. data/lib/gettc/account.rb +14 -0
  46. data/lib/gettc/download.rb +211 -0
  47. data/lib/gettc/generate.rb +156 -0
  48. data/lib/gettc/parse.rb +237 -0
  49. data/lib/gettc/print.rb +54 -0
  50. data/lib/gettc/problem.rb +39 -0
  51. data/lib/gettc/signature.rb +63 -0
  52. data/lib/gettc/types.rb +93 -0
  53. data/lib/version.rb +3 -0
  54. data/test/gettc/download_test.rb +61 -0
  55. data/test/gettc/generate_test.rb +70 -0
  56. data/test/gettc/parse_test.rb +78 -0
  57. data/test/gettc/signature_test.rb +71 -0
  58. data/test/gettc/types_test.rb +31 -0
  59. metadata +28 -23
  60. data/core/lib/gettc/download.rb +0 -130
  61. data/core/lib/gettc/generate.rb +0 -145
  62. data/core/lib/gettc/parse.rb +0 -233
  63. data/core/lib/gettc/print.rb +0 -56
  64. data/core/lib/gettc/problem.rb +0 -33
  65. data/core/lib/gettc/signature.rb +0 -55
  66. data/core/lib/gettc/types.rb +0 -83
  67. data/core/lib/version.rb +0 -3
  68. data/core/test/gettc/download_test.rb +0 -29
  69. data/core/test/gettc/generate_test.rb +0 -31
  70. data/core/test/gettc/parse_test.rb +0 -104
  71. data/core/test/gettc/signature_test.rb +0 -54
  72. data/core/test/gettc/types_test.rb +0 -28
@@ -1,70 +1,62 @@
1
- require "gettc/types"
1
+ require "gettc/types"
2
2
 
3
3
  module Gettc
4
- class Type
5
- def to_go
6
- if is_a? TArray
7
- return "[]#{subtype.to_go}"
8
- end
4
+ class Type
5
+ def to_go
6
+ return "[]#{subtype.to_go}" if self.is_a?(TArray)
9
7
 
10
- case self
11
- when TInt
12
- return "int"
13
- when TLong
14
- return "int64"
15
- when TFloat
16
- return "float32"
17
- when TDouble
18
- return "float64"
19
- when TChar
20
- return "byte"
21
- when TString
22
- return "string"
23
- when TBoolean
24
- return "bool"
25
- end
26
-
27
- return "unknown"
28
- end
29
- def dumb_go
30
- if is_a? TArray
31
- return to_go + " {}"
32
- end
8
+ case self
9
+ when TInt
10
+ "int"
11
+ when TLong
12
+ "int64"
13
+ when TFloat
14
+ "float32"
15
+ when TDouble
16
+ "float64"
17
+ when TChar
18
+ "byte"
19
+ when TString
20
+ "string"
21
+ when TBoolean
22
+ "bool"
23
+ else
24
+ "unknown"
25
+ end
26
+ end
33
27
 
34
- case self
35
- when TInt, TLong, TDouble, TFloat
36
- return "0"
37
- when TChar
38
- return "'$'"
39
- when TString
40
- return '"$"'
41
- when TBoolean
42
- return "true"
43
- end
28
+ def dumb_go
29
+ return "#{self.to_go} {}" if self.is_a?(TArray)
44
30
 
45
- return "nil"
46
- end
31
+ case self
32
+ when TInt, TLong, TDouble, TFloat
33
+ "0"
34
+ when TChar
35
+ "'$'"
36
+ when TString
37
+ '"$"'
38
+ when TBoolean
39
+ "true"
40
+ else
41
+ "nil"
42
+ end
47
43
  end
48
- class Signature
49
- def to_go
50
- return @name + " " + @type.to_go
51
- end
44
+ end
45
+
46
+ class Signature
47
+ def to_go
48
+ "#{@name} #{@type.to_go}"
52
49
  end
53
- class GoEngine
54
- attr_reader :declare, :input, :output, :func_name
55
- def initialize func, vars
56
- @declare = vars.map do |var|
57
- var.to_go
58
- end
59
- temp = vars.map do |var|
60
- var.name
61
- end
62
- @output = temp.join ", "
63
- temp = temp.map do |name|
64
- "&" + name
65
- end
66
- @input = temp.join ", "
67
- @func_name = func.name[0, 1].upcase + func.name[1..-1]
68
- end
50
+ end
51
+
52
+ class GoEngine
53
+ attr_reader :declare, :input, :output, :func_name
54
+
55
+ def initialize(func, vars)
56
+ @declare = vars.map(&:to_go)
57
+ @output = vars.map(&:name).join(", ")
58
+ @input = vars.map { |var| "&#{var.name}" }.join(", ")
59
+ @func_name = func.name[0, 1].upcase + func.name[1..-1]
69
60
  end
61
+ end
70
62
  end
@@ -1,128 +1,118 @@
1
- require "gettc/types"
1
+ require "gettc/types"
2
2
 
3
3
  module Gettc
4
- class Type
5
- def to_haskell
6
- if is_a? TArray then
7
- return "[" + subtype.to_haskell + "]"
8
- end
9
-
10
- case self
11
- when TInt
12
- return "Int"
13
- when TLong
14
- return "Integer"
15
- when TFloat
16
- return "Float"
17
- when TDouble
18
- return "Double"
19
- when TChar
20
- return "Char"
21
- when TString
22
- return "String"
23
- when TBoolean
24
- return "Bool"
25
- end
26
-
27
- return "Unknown"
28
- end
29
- def get_haskell_parser
30
- if is_a? TArray then
31
- return "(TC.parseList " + subtype.get_haskell_parser + ")"
32
- end
33
-
34
- case self
35
- when TInt
36
- return "TC.parseInt"
37
- when TLong
38
- return "TC.parseLong"
39
- when TFloat
40
- return "TC.parseFloat"
41
- when TDouble
42
- return "TC.parseDouble"
43
- when TChar
44
- return "TC.parseChar"
45
- when TString
46
- return "TC.parseString"
47
- when TBoolean
48
- return "TC.parseBool"
49
- end
50
-
51
- return "unknown"
52
- end
53
- def dumb_haskell
54
- if is_a? TArray
55
- return "[]"
56
- end
57
-
58
- case self
59
- when TInt, TLong, TFloat, TDouble
60
- return "0"
61
- when TChar
62
- return "'$'"
63
- when TString
64
- return '"$"'
65
- when TBoolean
66
- return "True"
67
- end
68
-
69
- return "Nil"
70
- end
4
+ class Type
5
+ def to_haskell
6
+ return "[#{subtype.to_haskell}]" if self.is_a?(TArray)
7
+
8
+ case self
9
+ when TInt
10
+ "Int"
11
+ when TLong
12
+ "Integer"
13
+ when TFloat
14
+ "Float"
15
+ when TDouble
16
+ "Double"
17
+ when TChar
18
+ "Char"
19
+ when TString
20
+ "String"
21
+ when TBoolean
22
+ "Bool"
23
+ else
24
+ "Unknown"
25
+ end
26
+ end
27
+
28
+ def get_haskell_parser
29
+ return "(TC.parseList #{subtype.get_haskell_parser})" if self.is_a?(TArray)
30
+
31
+ case self
32
+ when TInt
33
+ "TC.parseInt"
34
+ when TLong
35
+ "TC.parseLong"
36
+ when TFloat
37
+ "TC.parseFloat"
38
+ when TDouble
39
+ "TC.parseDouble"
40
+ when TChar
41
+ "TC.parseChar"
42
+ when TString
43
+ "TC.parseString"
44
+ when TBoolean
45
+ "TC.parseBool"
46
+ else
47
+ "unknown"
48
+ end
71
49
  end
72
- class HaskellEngine
73
- attr_reader :func, :vars, :declare, :input, :output
74
- def initialize func, vars
75
- @func = Signature.new func.type, uncapitalize(func.name)
76
- @vars = vars.map do |var|
77
- Signature.new var.type, uncapitalize(var.name)
78
- end
79
- compute_declare
80
- compute_input
81
- compute_output
82
- end
50
+
51
+ def dumb_haskell
52
+ return "[]" if self.is_a?(TArray)
53
+
54
+ case self
55
+ when TInt, TLong, TFloat, TDouble
56
+ "0"
57
+ when TChar
58
+ "'$'"
59
+ when TString
60
+ '"$"'
61
+ when TBoolean
62
+ "True"
63
+ else
64
+ "Nil"
65
+ end
66
+ end
67
+ end
68
+
69
+ class HaskellEngine
70
+ attr_reader :func, :vars
71
+
72
+ def initialize(func, vars)
73
+ @func = Signature.new(func.type, uncapitalize(func.name))
74
+ @vars = vars.map { |var| Signature.new(var.type, uncapitalize(var.name)) }
75
+ end
76
+
77
+ def declare
78
+ ret = ""
79
+ ret << @func.name << " :: "
80
+ ret << @vars.map { |var| var.type.to_haskell }.join(" -> ")
81
+ ret << " -> " << @func.type.to_haskell << "\n"
82
+ ret << @func.name << " "
83
+ ret << @vars.map(&:name).join(" ")
84
+ ret << " = " << @func.type.dumb_haskell
85
+ end
86
+
87
+ def input
88
+ ret = "getVars :: TC.Parser ("
89
+ ret << @vars.map { |var| var.type.to_haskell }.join(", ") << ")\n"
90
+
91
+ temp = "getVars = do "
92
+ indent = " " * temp.size
93
+ ret << temp
94
+
95
+ ret << @vars.map do |var|
96
+ x = ""
97
+ x << var.name
98
+ x << " <- TC.spaces >> "
99
+ x << var.type.get_haskell_parser
100
+ end.join(" ; TC.spaces >> TC.next\n#{indent}")
101
+
102
+ ret << "\n"
103
+ ret << indent << "return ("
104
+ ret << @vars.map(&:name).join(", ")
105
+ ret << ")"
106
+ end
107
+
108
+ def output
109
+ @func.name + " " + @vars.map(&:name).join(" ")
110
+ end
111
+
83
112
  private
84
- def uncapitalize str
85
- return str[0, 1].downcase + str[1..-1]
86
- end
87
- def compute_declare
88
- ret = ""
89
- ret << func.name << " :: "
90
-
91
- temp = vars.map do |var| var.type.to_haskell end
92
- ret << temp.join(" -> ") << " -> " << func.type.to_haskell << "\n"
93
-
94
- ret << func.name << " "
95
- temp = vars.map do |var| var.name end
96
- ret << temp.join(" ") << " = " << func.type.dumb_haskell
97
-
98
- @declare = ret
99
- end
100
- def compute_input
101
- ret = "getVars :: TC.Parser ("
102
- temp = @vars.map do |var| var.type.to_haskell end
103
- ret << temp.join(", ") << ")\n"
104
- temp = "getVars = do "
105
- ret << temp
106
- indent = " " * temp.size
107
- temp = @vars.map do |var|
108
- x = ""
109
- x << var.name
110
- x << " <- TC.spaces >> "
111
- x << var.type.get_haskell_parser
112
- end
113
- ret << temp.join(" ; TC.spaces >> TC.next\n#{indent}") << "\n"
114
- ret << indent << "return ("
115
- temp = @vars.map do |var| var.name end
116
- ret << temp.join(", ")
117
- ret << ")"
118
- @input = ret
119
- end
120
- def compute_output
121
- ret = ""
122
- ret << @func.name << " "
123
- temp = vars.map do |var| var.name end
124
- ret << temp.join(" ")
125
- @output = ret
126
- end
113
+
114
+ def uncapitalize str
115
+ str[0, 1].downcase + str[1..-1]
127
116
  end
117
+ end
128
118
  end
@@ -1,193 +1,196 @@
1
- require "gettc/types"
1
+ require "gettc/types"
2
2
 
3
3
  module Gettc
4
- class Type
5
- def to_java
6
- return to_s
7
- end
8
- def to_java_boxed
9
- if is_a? TArray then
10
- return "List<#{subtype.to_java_boxed}>"
11
- end
12
-
13
- case self
14
- when TInt
15
- return "Integer"
16
- when TLong
17
- return "Long"
18
- when TFloat
19
- return "Float"
20
- when TDouble
21
- return "Double"
22
- when TChar
23
- return "Character"
24
- when TString
25
- return "String"
26
- when TBoolean
27
- return "Boolean"
28
- end
29
-
30
- return "Unknown"
31
- end
32
- def dumb_java
33
- if self.is_a? TArray then
34
- return "new #{subtype.to_java}[1]"
35
- end
36
-
37
- case self
38
- when TInt, TLong, TFloat, TDouble
39
- return "0"
40
- when TChar
41
- return "'$'"
42
- when TString
43
- return '"$"'
44
- when TBoolean
45
- return "true"
46
- end
47
-
48
- return "Nil"
49
- end
4
+ class Type
5
+ def to_java
6
+ to_s
50
7
  end
51
- class Signature
52
- def to_java
53
- return "#{type.to_java} #{name}"
54
- end
8
+
9
+ def to_java_boxed
10
+ return "List<#{subtype.to_java_boxed}>" if self.is_a?(TArray)
11
+
12
+ case self
13
+ when TInt
14
+ "Integer"
15
+ when TLong
16
+ "Long"
17
+ when TFloat
18
+ "Float"
19
+ when TDouble
20
+ "Double"
21
+ when TChar
22
+ "Character"
23
+ when TString
24
+ "String"
25
+ when TBoolean
26
+ "Boolean"
27
+ else
28
+ "Unknown"
29
+ end
55
30
  end
56
- class JavaArray
57
- def self.get_depth type
58
- return 0 unless type.is_a? TArray
59
- return 1 + get_depth(type.subtype)
60
- end
61
- def self.get_elem_type type
62
- return type unless type.is_a? TArray
63
- return get_elem_type type.subtype
64
- end
65
- attr_reader :name, :boxed_name, :type, :boxed_type
66
- def initialize sig
67
- @sig = sig
68
- @name = sig.name
69
- @boxed_name = "#{@name}Boxed"
70
- @type = sig.type.to_java
71
- @boxed_type = sig.type.to_java_boxed
72
- @depth = self.class.get_depth sig.type
73
- @elem_type = self.class.get_elem_type(sig.type).to_java
74
- end
75
- def unbox_code
76
- counters = @depth.times.map do |i| "_" + ("i"[0].ord + i).chr end
77
- indents = 0.upto(@depth).map do |i| " " * 4 * i end
78
- sizes = @depth.times.map do |i|
79
- @boxed_name + (".get(0)" * i) + ".size()"
80
- end
81
- ret = ""
82
-
83
- ret << @type << " " << @name << " = new " << @elem_type;
84
- @depth.times do |i| ret << "[" << sizes[i] << "]" end
85
- ret << ";\n"
86
-
87
- @depth.times do |i|
88
- ret << indents[i] << "for (int " << counters[i] << " = 0; "
89
- ret << counters[i] << " < " << sizes[i]
90
- ret << "; ++" << counters[i] << ")\n"
91
- end
92
-
93
- ret << indents[@depth] << @name
94
- @depth.times do |i| ret << "[" << counters[i] << "]" end
95
- ret << " = "
96
- ret << @boxed_name
97
- @depth.times do |i| ret << ".get(" << counters[i] << ")" end
98
- ret << ";"
99
-
100
- return ret
101
- end
102
- def box_code_recurse boxed_type, parent, boxed_name, depth, counters
103
- ret = ""
104
- index = counters.map do |counter| "[" + counter + "]" end
105
- index = index.join
106
- if depth == 0
107
- ret << parent << ".add(" << @name << index << ");\n"
108
- else
109
- type_str = boxed_type.to_java_boxed
110
- ret << type_str << " " << boxed_name
111
- ret << " = new Array" << type_str << "();" << "\n"
112
-
113
- counter = "_" + ("i"[0].ord + counters.size).chr
114
- ret << "for (int " << counter << " = 0; "
115
- ret << counter << " < " << @name << index << ".length; "
116
- ret << "++" << counter << ") {\n"
117
-
118
- ret << box_code_recurse(boxed_type.subtype,
119
- boxed_name,
120
- boxed_name + counter,
121
- depth - 1, counters << counter)
122
- ret << "}\n"
123
-
124
- unless parent.nil?
125
- ret << parent << ".add("
126
- ret << boxed_name << ");\n"
127
- end
128
- end
129
- ret.gsub! /^/, " " * 4 unless parent.nil?
130
- return ret
131
- end
132
- def box_code
133
- box_code_recurse @sig.type, nil, @boxed_name, @depth, []
134
- end
31
+
32
+ def dumb_java
33
+ return "new #{subtype.to_java}[1]" if self.is_a?(TArray)
34
+
35
+ case self
36
+ when TInt, TLong, TFloat, TDouble
37
+ "0"
38
+ when TChar
39
+ "'$'"
40
+ when TString
41
+ '"$"'
42
+ when TBoolean
43
+ "true"
44
+ else
45
+ "Nil"
46
+ end
135
47
  end
136
- class JavaEngine
137
- attr_accessor :declare, :input, :output
138
- def initialize func, vars
139
- @func = func
140
- @vars = vars
141
- compute_declare
142
- compute_input
143
- compute_output
144
- end
145
- private
146
- def compute_declare
147
- ret = "public "
148
- ret << @func.to_java << "("
149
- indent = " " * ret.size
150
- temp = @vars.map do |var| var.to_java end
151
- ret << temp.join(",\n#{indent}")
152
- ret << ")"
153
- @declare = ret
154
- end
155
- def compute_input
156
- temp = @vars.map do |var|
157
- ret = ""
158
- if var.type.is_a? TArray
159
- arr = JavaArray.new var
160
- ret << arr.boxed_type
161
- ret << " " << arr.boxed_name
162
- ret << " = (" << arr.boxed_type << ") "
163
- ret << "reader.next(new TypeRef<" << arr.boxed_type << ">"
164
- ret << "(){}.getType());\n"
165
- ret << arr.unbox_code
166
- else
167
- ret << var.to_java
168
- ret << " = (" << var.type.to_java_boxed << ") "
169
- ret << "reader.next("
170
- ret << var.type.to_java_boxed
171
- ret << ".class);"
172
- end
173
- ret
174
- end
175
- @input = temp.join "\nreader.next();\n\n"
48
+ end
49
+
50
+ class Signature
51
+ def to_java
52
+ "#{type.to_java} #{name}"
53
+ end
54
+ end
55
+
56
+ class JavaArray
57
+ attr_reader :name, :boxed_name, :type, :boxed_type
58
+
59
+ def self.get_depth(type)
60
+ type.is_a?(TArray) ? 1 + get_depth(type.subtype) : 0
61
+ end
62
+
63
+ def self.get_elem_type(type)
64
+ type.is_a?(TArray) ? get_elem_type(type.subtype) : type
65
+ end
66
+
67
+ def initialize(sig)
68
+ @sig = sig
69
+ @name = sig.name
70
+ @boxed_name = "#{@name}Boxed"
71
+ @type = sig.type.to_java
72
+ @boxed_type = sig.type.to_java_boxed
73
+ @depth = self.class.get_depth(sig.type)
74
+ @elem_type = self.class.get_elem_type(sig.type).to_java
75
+ end
76
+
77
+ def unbox_code
78
+ ret = ""
79
+
80
+ counters = @depth.times.map { |i| "_" + ("i"[0].ord + i).chr }
81
+ indents = 0.upto(@depth).map { |i| " " * 4 * i }
82
+ sizes = @depth.times.map { |i| @boxed_name + (".get(0)" * i) + ".size()" }
83
+
84
+ ret << @type << " " << @name << " = new " << @elem_type
85
+ @depth.times { |i| ret << "[" << sizes[i] << "]" }
86
+ ret << ";\n"
87
+
88
+ @depth.times do |i|
89
+ ret << indents[i] << "for (int " << counters[i] << " = 0; "
90
+ ret << counters[i] << " < " << sizes[i]
91
+ ret << "; ++" << counters[i] << ")\n"
92
+ end
93
+
94
+ ret << indents[@depth] << @name
95
+ @depth.times { |i| ret << "[" << counters[i] << "]" }
96
+ ret << " = "
97
+
98
+ ret << @boxed_name
99
+ @depth.times { |i| ret << ".get(" << counters[i] << ")" }
100
+ ret << ";"
101
+
102
+ ret
103
+ end
104
+
105
+ def box_code_recurse(boxed_type, parent, boxed_name, depth, counters)
106
+ ret = ""
107
+
108
+ index = counters.map { |counter| "[#{counter}]" }.join
109
+
110
+ if depth == 0
111
+ ret << parent << ".add(" << @name << index << ");\n"
112
+ else
113
+ type_str = boxed_type.to_java_boxed
114
+ ret << type_str << " " << boxed_name
115
+ ret << " = new Array" << type_str << "();" << "\n"
116
+
117
+ counter = "_" + ("i"[0].ord + counters.size).chr
118
+ ret << "for (int " << counter << " = 0; "
119
+ ret << counter << " < " << @name << index << ".length; "
120
+ ret << "++" << counter << ") {\n"
121
+
122
+ ret << box_code_recurse(boxed_type.subtype,
123
+ boxed_name,
124
+ boxed_name + counter,
125
+ depth - 1, counters << counter)
126
+ ret << "}\n"
127
+
128
+ unless parent.nil?
129
+ ret << parent << ".add("
130
+ ret << boxed_name << ");\n"
176
131
  end
177
- def compute_output
178
- ret = ""
179
- caller = "solver." + @func.name + "("
180
- temp = @vars.map do |var| var.name end
181
- caller << temp.join(", ") << ")"
182
- if @func.type.is_a? TArray
183
- ret << @func.type.to_java << " result = " << caller << ";\n"
184
- arr = JavaArray.new(Signature.new @func.type, "result")
185
- ret << arr.box_code
186
- ret << "writer.write(resultBoxed);"
187
- else
188
- ret << "writer.write(" << caller << ");"
189
- end
190
- @output = ret
132
+ end
133
+
134
+ parent.nil? ? ret : ret.gsub(/^/, " " * 4)
135
+ end
136
+
137
+ def box_code
138
+ box_code_recurse(@sig.type, nil, @boxed_name, @depth, [])
139
+ end
140
+ end
141
+
142
+ class JavaEngine
143
+ def initialize func, vars
144
+ @func = func
145
+ @vars = vars
146
+ end
147
+
148
+ def declare
149
+ ret = "public "
150
+ ret << @func.to_java << "("
151
+ indent = " " * ret.size
152
+ ret << @vars.map(&:to_java).join(",\n#{indent}")
153
+ ret << ")"
154
+ end
155
+
156
+ def input
157
+ @vars.map do |var|
158
+ ret = ""
159
+ if var.type.is_a?(TArray)
160
+ arr = JavaArray.new(var)
161
+ ret << arr.boxed_type
162
+ ret << " " << arr.boxed_name
163
+ ret << " = (" << arr.boxed_type << ") "
164
+ ret << "reader.next(new TypeRef<" << arr.boxed_type << ">"
165
+ ret << "(){}.getType());\n"
166
+ ret << arr.unbox_code
167
+ else
168
+ ret << var.to_java
169
+ ret << " = (" << var.type.to_java_boxed << ") "
170
+ ret << "reader.next("
171
+ ret << var.type.to_java_boxed
172
+ ret << ".class);"
191
173
  end
174
+ ret
175
+ end.join("\nreader.next();\n\n")
176
+ end
177
+
178
+ def output
179
+ ret = ""
180
+
181
+ solver = "solver." + @func.name + "("
182
+ solver << @vars.map(&:name).join(", ") << ")"
183
+
184
+ if @func.type.is_a?(TArray)
185
+ ret << @func.type.to_java << " result = " << solver << ";\n"
186
+ arr = JavaArray.new(Signature.new(@func.type, "result"))
187
+ ret << arr.box_code
188
+ ret << "writer.write(resultBoxed);"
189
+ else
190
+ ret << "writer.write(" << solver << ");"
191
+ end
192
+
193
+ ret
192
194
  end
195
+ end
193
196
  end