gettc 1.6.2 → 1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/core/lib/gettc.rb +1 -1
- data/core/lib/gettc/generate.rb +133 -133
- data/dist/config.yml +1 -1
- data/dist/include/cpp/engine.rb +22 -15
- data/dist/include/go/engine.rb +70 -0
- data/dist/include/go/src/topcoder/errors.go +41 -0
- data/dist/include/go/src/topcoder/reader.go +266 -0
- data/dist/include/go/src/topcoder/reader_test.go +335 -0
- data/dist/include/go/src/topcoder/writer.go +54 -0
- data/dist/include/go/src/topcoder/writer_test.go +19 -0
- data/dist/include/haskell/engine.rb +16 -15
- data/dist/include/java/engine.rb +14 -10
- data/dist/include/python/engine.rb +36 -13
- data/dist/include/python/topcoder/__pycache__/__init__.cpython-32.pyc +0 -0
- data/dist/include/python/topcoder/__pycache__/errors.cpython-32.pyc +0 -0
- data/dist/include/python/topcoder/__pycache__/reader.cpython-32.pyc +0 -0
- data/dist/include/python/topcoder/__pycache__/writer.cpython-32.pyc +0 -0
- data/dist/template/solve/cpp/Makefile +1 -5
- data/dist/template/solve/cpp/{name}.cpp +2 -2
- data/dist/template/solve/go/Makefile +29 -0
- data/dist/template/solve/go/{name}/{name}.go +7 -0
- data/dist/template/solve/go/{name}Runner.go +34 -0
- data/dist/template/solve/haskell/Makefile +1 -5
- data/dist/template/solve/java/build.xml +0 -16
- data/dist/template/solve/python/Makefile +1 -1
- data/dist/template/solve/python/{name}.py +2 -2
- data/dist/template/solve/python/{name}Runner.py +4 -5
- data/dist/template/util/check/check.cpp +1 -1
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbe6b178b2e8a91c7cafef4182730cf4873d177f
|
4
|
+
data.tar.gz: 163a10b0052c1d94dc9d5d4ea463984633a744e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 684edc1982ebfe09fe0dd271f7d3c916163be15eccf295002e68f78551275d74d1f8d3302748d17b62c269a04e3d964577d3cc5fdd4574b4bf40b288067988d6
|
7
|
+
data.tar.gz: 79cfa937b2c0f9170d13f977209fb2de63d9385cde36efca45da0d12048eaae6420ced5798f2752588974053f33b82d3a01407de06493ff3dbb2ab8102ddb319
|
data/core/lib/gettc.rb
CHANGED
data/core/lib/gettc/generate.rb
CHANGED
@@ -7,139 +7,139 @@ require "gettc/signature"
|
|
7
7
|
require "gettc/print"
|
8
8
|
|
9
9
|
module Gettc
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
10
|
+
GenerateError = Class.new StandardError
|
11
|
+
class ProblemDirExists < GenerateError
|
12
|
+
attr_accessor :dir
|
13
|
+
def initialize dir, msg = nil
|
14
|
+
if msg.nil? then
|
15
|
+
msg = "Cannot create problem directory because it already exists"
|
16
|
+
end
|
17
|
+
@dir = dir
|
18
|
+
super "#{msg} (#{dir})"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
class SourceDirNotExist < GenerateError
|
22
|
+
attr_accessor :dir
|
23
|
+
def initialize dir, msg = "Source directory does not exist"
|
24
|
+
@dir = dir
|
25
|
+
super "#{msg} (#{dir})"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
class TargetDirNotExist < GenerateError
|
29
|
+
attr_accessor :dir
|
30
|
+
def initialize dir, msg = "Target directory does not exist"
|
31
|
+
@dir = dir
|
32
|
+
super "#{msg} (#{dir})"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
class TemplateError < GenerateError
|
36
|
+
attr_accessor :dir
|
37
|
+
def initialize err, source, msg = "Template error"
|
38
|
+
@err = err
|
39
|
+
@source = source
|
40
|
+
super "#{msg} (#{source})\n#{err}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
class Generator
|
44
|
+
def initialize config_d, target_d
|
45
|
+
@source_d = File.join config_d, "template"
|
46
|
+
@target_d = target_d
|
47
|
+
raise SourceDirNotExist.new @source_d unless File.directory? @source_d
|
48
|
+
raise TargetDirNotExist.new @target_d unless File.directory? @target_d
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
50
|
+
include_d = File.join config_d, "include"
|
51
|
+
load_engines include_d
|
52
|
+
end
|
53
|
+
def generate prob
|
54
|
+
@prob = prob
|
55
|
+
@prob_d = File.join @target_d, prob.name
|
56
|
+
raise ProblemDirExists.new @prob_d if File.exists? @prob_d
|
57
|
+
FileUtils.mkdir @prob_d
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
59
|
+
method_sig = @prob.definitions["Method signature"]
|
60
|
+
if method_sig.nil? then
|
61
|
+
$stderr.puts "[Warning] No definition for method signature found"
|
62
|
+
else
|
63
|
+
vars = parse_method_signature method_sig
|
64
|
+
func = vars.shift
|
65
|
+
end
|
66
|
+
@context = binding
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
end
|
68
|
+
walk @source_d, @prob_d
|
69
|
+
end
|
70
|
+
private
|
71
|
+
def gen_images images, images_d
|
72
|
+
images.each do |image|
|
73
|
+
filename = File.join images_d, image.name
|
74
|
+
File.open filename, "wb" do |f| f.write image.content end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
def gen_cases cases, data_d
|
78
|
+
cases.each_index do |i|
|
79
|
+
c = cases[i]
|
80
|
+
File.open File.join(data_d, "#{i.to_s}.in"), "w" do |f|
|
81
|
+
f.write c.input
|
82
|
+
end
|
83
|
+
File.open File.join(data_d, "#{i.to_s}.out"), "w" do |f|
|
84
|
+
f.write c.output
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
def gen_template source, target
|
89
|
+
before = File.open source, "r" do |f| f.read end
|
90
|
+
begin
|
91
|
+
after = ERB.new(before).result @context
|
92
|
+
rescue SyntaxError, NameError => err
|
93
|
+
raise TemplateError.new err, source
|
94
|
+
end
|
95
|
+
File.open target, "w" do |f| f.write after end
|
96
|
+
end
|
97
|
+
def filter target_d, name
|
98
|
+
if name == "{images_d}" then
|
99
|
+
gen_images @prob.images, target_d
|
100
|
+
elsif name == "{examples_d}" then
|
101
|
+
gen_cases @prob.examples, target_d
|
102
|
+
elsif name == "{systests_d}" then
|
103
|
+
gen_cases @prob.systests, target_d
|
104
|
+
else
|
105
|
+
target_n = name.gsub /\{(\w*)\}/ do |match|
|
106
|
+
@prob.name if $1 == "name"
|
107
|
+
end
|
108
|
+
return target_n
|
109
|
+
end
|
110
|
+
return nil
|
111
|
+
end
|
112
|
+
def load_engines include_d
|
113
|
+
return unless File.exists? include_d
|
114
|
+
Dir.foreach include_d do |name|
|
115
|
+
child = File.join include_d, name
|
116
|
+
if File.directory? child then
|
117
|
+
engine = File.join child, "engine.rb"
|
118
|
+
if File.exists? engine then
|
119
|
+
unless (Pathname.new engine).absolute? then
|
120
|
+
engine = "./" + engine
|
121
|
+
end
|
122
|
+
require engine
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
def walk source_d, target_d
|
128
|
+
Dir.foreach source_d do |name|
|
129
|
+
if name != "." and name != ".." then
|
130
|
+
source_p = File.join source_d, name
|
131
|
+
target_n = filter target_d, name
|
132
|
+
unless target_n.nil? then
|
133
|
+
target_p = File.join target_d, target_n
|
134
|
+
if File.directory? source_p then
|
135
|
+
FileUtils.mkdir target_p unless File.exists? target_p
|
136
|
+
walk source_p, target_p
|
137
|
+
elsif File.file? source_p then
|
138
|
+
gen_template source_p, target_p
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
data/dist/config.yml
CHANGED
data/dist/include/cpp/engine.rb
CHANGED
@@ -58,33 +58,40 @@ module Gettc
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
class CppEngine
|
61
|
-
|
61
|
+
attr_reader :declare, :input, :output
|
62
62
|
def initialize func, vars
|
63
63
|
@func = func
|
64
64
|
@vars = vars
|
65
|
+
compute_declare
|
66
|
+
compute_input
|
67
|
+
compute_output
|
65
68
|
end
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
private
|
70
|
+
def compute_declare
|
71
|
+
@declare = @func.to_cpp
|
72
|
+
@declare << "("
|
73
|
+
indent = " " * @declare.size
|
74
|
+
temp = @vars.map do |var|
|
75
|
+
var.to_cpp true
|
76
|
+
end
|
77
|
+
@declare << temp.join(",\n#{indent}")
|
78
|
+
@declare << ")"
|
74
79
|
end
|
75
|
-
def
|
80
|
+
def compute_input
|
76
81
|
temp = @vars.map do |var|
|
77
82
|
x = var.to_cpp
|
78
83
|
x << "; tc::read(ifs, "
|
79
84
|
x << var.name
|
80
85
|
x << ");"
|
81
86
|
end
|
82
|
-
|
87
|
+
@input = temp.join " tc::next(ifs);\n"
|
83
88
|
end
|
84
|
-
def
|
85
|
-
|
86
|
-
temp = @vars.map do |var|
|
87
|
-
|
89
|
+
def compute_output
|
90
|
+
@output = "tc::show(ofs, solver." << @func.name << "("
|
91
|
+
temp = @vars.map do |var|
|
92
|
+
var.name
|
93
|
+
end
|
94
|
+
@output << temp.join(", ") << "));"
|
88
95
|
end
|
89
96
|
end
|
90
97
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "gettc/types"
|
2
|
+
|
3
|
+
module Gettc
|
4
|
+
class Type
|
5
|
+
def to_go
|
6
|
+
if self == TInt then
|
7
|
+
return "int"
|
8
|
+
elsif self == TLong then
|
9
|
+
return "int64"
|
10
|
+
elsif self == TFloat then
|
11
|
+
return "float32"
|
12
|
+
elsif self == TDouble then
|
13
|
+
return "float64"
|
14
|
+
elsif self == TChar then
|
15
|
+
return "byte"
|
16
|
+
elsif self == TString then
|
17
|
+
return "string"
|
18
|
+
elsif self == TBoolean then
|
19
|
+
return "bool"
|
20
|
+
elsif is_a? TArray then
|
21
|
+
return "[]#{subtype.to_go}"
|
22
|
+
else
|
23
|
+
return "unknown"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
def dumb_go
|
27
|
+
if self == TInt then
|
28
|
+
return "0"
|
29
|
+
elsif self == TLong then
|
30
|
+
return "0"
|
31
|
+
elsif self == TFloat then
|
32
|
+
return "0"
|
33
|
+
elsif self == TDouble then
|
34
|
+
return "0"
|
35
|
+
elsif self == TChar then
|
36
|
+
return "'$'"
|
37
|
+
elsif self == TString then
|
38
|
+
return '"$"'
|
39
|
+
elsif self == TBoolean then
|
40
|
+
return "true"
|
41
|
+
elsif is_a? TArray then
|
42
|
+
return self.to_go + " {}"
|
43
|
+
else
|
44
|
+
return "nil"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
class Signature
|
49
|
+
def to_go
|
50
|
+
return @name + " " + @type.to_go
|
51
|
+
end
|
52
|
+
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
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
package topcoder
|
2
|
+
|
3
|
+
import (
|
4
|
+
"io"
|
5
|
+
"io/ioutil"
|
6
|
+
"fmt"
|
7
|
+
"reflect"
|
8
|
+
)
|
9
|
+
|
10
|
+
|
11
|
+
type ErrType struct {
|
12
|
+
typ reflect.Type
|
13
|
+
}
|
14
|
+
|
15
|
+
func (me ErrType) Error() string {
|
16
|
+
return fmt.Sprintf("Cannot handle type %s", me.typ.String())
|
17
|
+
}
|
18
|
+
|
19
|
+
func NewErrType(typ reflect.Type) *ErrType {
|
20
|
+
return &ErrType { typ }
|
21
|
+
}
|
22
|
+
|
23
|
+
|
24
|
+
func rest(r io.Reader) string {
|
25
|
+
bs, err := ioutil.ReadAll(r)
|
26
|
+
if err != nil {
|
27
|
+
return err.Error()
|
28
|
+
}
|
29
|
+
return string(bs)
|
30
|
+
}
|
31
|
+
|
32
|
+
|
33
|
+
type ErrExpect string
|
34
|
+
|
35
|
+
func (me ErrExpect) Error() string {
|
36
|
+
return string(me)
|
37
|
+
}
|
38
|
+
|
39
|
+
func NewErrExpect(r io.Reader, what string) ErrExpect {
|
40
|
+
return ErrExpect(fmt.Sprintf("Expect %s at <%s>", what, rest(r)))
|
41
|
+
}
|