Commit 09d084d1 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add some a new test (a gcj solution) and start making it work

parent cb37b376
...@@ -668,6 +668,7 @@ define make_search ...@@ -668,6 +668,7 @@ define make_search
$(eval \ $(eval \
$1: ../test/tests/$1 ; $1: ../test/tests/$1 ;
$1: ../microbenchmarks/$1 ; $1: ../microbenchmarks/$1 ;
$1: ../millibenchmarks/$1 ;
$1: ../benchmarks/$1 ; $1: ../benchmarks/$1 ;
) )
endef endef
......
...@@ -135,7 +135,7 @@ template <class T> static void readMiscVector(std::vector<T*>& vec, BufferedRead ...@@ -135,7 +135,7 @@ template <class T> static void readMiscVector(std::vector<T*>& vec, BufferedRead
static int readColOffset(BufferedReader* reader) { static int readColOffset(BufferedReader* reader) {
int rtn = reader->readULL(); int rtn = reader->readULL();
// offsets out of this range are almost certainly parse bugs: // offsets out of this range are almost certainly parse bugs:
ASSERT(rtn >= 0 && rtn < 100000, "%d", rtn); ASSERT(rtn >= -1 && rtn < 100000, "%d", rtn);
return rtn; return rtn;
} }
......
...@@ -301,6 +301,11 @@ private: ...@@ -301,6 +301,11 @@ private:
// Probably better to create an AST_Callattr type, and solidify the // Probably better to create an AST_Callattr type, and solidify the
// idea that a callattr is a single expression. // idea that a callattr is a single expression.
rtn->func = remapAttribute(ast_cast<AST_Attribute>(node->func)); rtn->func = remapAttribute(ast_cast<AST_Attribute>(node->func));
} else if (node->func->type == AST_TYPE::ClsAttribute) {
// TODO this is a cludge to make sure that "callattrs" stick together.
// Probably better to create an AST_Callattr type, and solidify the
// idea that a callattr is a single expression.
rtn->func = remapClsAttribute(ast_cast<AST_ClsAttribute>(node->func));
} else { } else {
rtn->func = remapExpr(node->func); rtn->func = remapExpr(node->func);
} }
...@@ -320,6 +325,14 @@ private: ...@@ -320,6 +325,14 @@ private:
return rtn; return rtn;
} }
AST_expr* remapClsAttribute(AST_ClsAttribute* node) {
AST_ClsAttribute* rtn = new AST_ClsAttribute();
rtn->attr = node->attr;
rtn->value = remapExpr(node->value);
return rtn;
}
AST_expr* remapCompare(AST_Compare* node) { AST_expr* remapCompare(AST_Compare* node) {
AST_Compare* rtn = new AST_Compare(); AST_Compare* rtn = new AST_Compare();
rtn->lineno = node->lineno; rtn->lineno = node->lineno;
...@@ -461,7 +474,7 @@ private: ...@@ -461,7 +474,7 @@ private:
push_back(j); push_back(j);
curblock = test_block; curblock = test_block;
AST_expr* test_call = makeCall(hasnext_attr); AST_expr* test_call = remapExpr(makeCall(hasnext_attr));
CFGBlock* body_block = cfg->addBlock(); CFGBlock* body_block = cfg->addBlock();
body_block->info = "listcomp_body"; body_block->info = "listcomp_body";
...@@ -623,6 +636,9 @@ private: ...@@ -623,6 +636,9 @@ private:
case AST_TYPE::Call: case AST_TYPE::Call:
rtn = remapCall(ast_cast<AST_Call>(node)); rtn = remapCall(ast_cast<AST_Call>(node));
break; break;
case AST_TYPE::ClsAttribute:
rtn = remapClsAttribute(ast_cast<AST_ClsAttribute>(node));
break;
case AST_TYPE::Compare: case AST_TYPE::Compare:
rtn = remapCompare(ast_cast<AST_Compare>(node)); rtn = remapCompare(ast_cast<AST_Compare>(node));
break; break;
...@@ -709,7 +725,7 @@ public: ...@@ -709,7 +725,7 @@ public:
if (type == AST_TYPE::Branch) { if (type == AST_TYPE::Branch) {
AST_TYPE::AST_TYPE test_type = ast_cast<AST_Branch>(node)->test->type; AST_TYPE::AST_TYPE test_type = ast_cast<AST_Branch>(node)->test->type;
assert(test_type == AST_TYPE::Name || test_type == AST_TYPE::Num); ASSERT(test_type == AST_TYPE::Name || test_type == AST_TYPE::Num, "%d", test_type);
curblock->push_back(node); curblock->push_back(node);
return; return;
} }
...@@ -1147,7 +1163,7 @@ public: ...@@ -1147,7 +1163,7 @@ public:
curblock = test_block; curblock = test_block;
AST_expr* test_call = makeCall(hasnext_attr); AST_expr* test_call = makeCall(hasnext_attr);
AST_Branch* test_br = makeBranch(test_call); AST_Branch* test_br = makeBranch(remapExpr(test_call));
push_back(test_br); push_back(test_br);
CFGBlock* test_true = cfg->addBlock(); CFGBlock* test_true = cfg->addBlock();
...@@ -1187,7 +1203,7 @@ public: ...@@ -1187,7 +1203,7 @@ public:
if (curblock) { if (curblock) {
AST_expr* end_call = makeCall(hasnext_attr); AST_expr* end_call = makeCall(hasnext_attr);
AST_Branch* end_br = makeBranch(end_call); AST_Branch* end_br = makeBranch(remapExpr(end_call));
push_back(end_br); push_back(end_br);
CFGBlock* end_true = cfg->addBlock(); CFGBlock* end_true = cfg->addBlock();
...@@ -1487,6 +1503,8 @@ CFG* computeCFG(AST_TYPE::AST_TYPE root_type, std::vector<AST_stmt*> body) { ...@@ -1487,6 +1503,8 @@ CFG* computeCFG(AST_TYPE::AST_TYPE root_type, std::vector<AST_stmt*> body) {
return_stmt->value = NULL; return_stmt->value = NULL;
visitor.push_back(return_stmt); visitor.push_back(return_stmt);
// rtn->print();
#ifndef NDEBUG #ifndef NDEBUG
//// ////
// Check some properties expected by later stages: // Check some properties expected by later stages:
......
# expected: fail
# - working on it
# Regression test:
for i in xrange(5):
try:
for j in xrange(5):
print i, j
except:
pass
# expected: fail
# - working on it
import sys
def compact(s):
i = 0
while i < len(s) - 1:
if s[i] == s[i+1]:
s = s[:i] + s[i+1:]
else:
i += 1
return s
class NotPossible(Exception):
pass
P = 1000000007
def fact(n):
t = 1
for i in xrange(1, n+1):
t = (t * i) % P
return t
if __name__ == "__main__":
s = """
3
3
ab bbbc cd
4
aa aa bc c
2
abc bcd
""".strip()
l = s.split('\n')
T = int(l.pop(0))
for _T in xrange(T):
N = int(l.pop(0))
trains = l.pop(0).split()
trains = map(compact, trains)
try:
for s in trains:
if s[0] in s[1:]:
raise NotPossible
if s[-1] in s[:-1]:
raise NotPossible
for c in s[1:-1]:
cnt = sum([s2.count(c) for s2 in trains])
assert cnt >= 1
if cnt != 1:
raise NotPossible()
# print trains
singles = {}
chunks = []
for i in xrange(N):
if len(trains[i]) == 1:
singles[trains[i]] = singles.get(trains[i], 0) + 1
else:
chunks.append(trains[i][0] + trains[i][-1])
# print singles, chunks
mult = 1
left = 0
while chunks:
# print mult, left, singles, chunks
first = chunks.pop()
assert len(set(first)) == len(first)
mult = (mult * fact(singles.pop(first[0], 0))) % P
mult = (mult * fact(singles.pop(first[-1], 0))) % P
for ch in chunks:
assert len(set(ch)) == len(ch)
if ch[0] in first:
if ch[0] in first[:-1]:
raise NotPossible()
# assert not any(c == ch[0] for c in ch[1:])
if any([c in first for c in ch[1:]]):
raise NotPossible()
assert ch[0] == first[-1]
chunks.remove(ch)
chunks.append(first + ch[1:])
break
if ch[-1] in first:
if ch[-1] in first[1:]:
raise NotPossible()
# assert not any(c == ch[-1] for c in ch[:-1])
if any([c in first for c in ch[:-1]]):
raise NotPossible()
assert ch[-1] == first[0]
chunks.remove(ch)
chunks.append(ch + first[1:])
break
else:
left += 1
continue
# print mult, left, singles, chunks
for k, v in singles.iteritems():
left += 1
mult = (mult * fact(v)) % P
assert left >= 0
while left:
mult = (mult * left) % P
left = left - 1
print "Case #%d: %d" % (_T+1, mult)
except NotPossible:
print "Case #%d: 0" % (_T+1,)
assert not l
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment