Permalink
Browse files

remove with statement

  • Loading branch information...
1 parent 66982fc commit 7d89a321f489c1c6cbcf905cd56d58529a8bee51 agemogolk committed Nov 10, 2012
View
@@ -2535,10 +2535,8 @@ static StatementAnalysis analyzeStatement(StatementPtr stmt, EnvPtr env, Analysi
case BLOCK : {
Block *block = (Block *)stmt.ptr();
- if (!block->desugared)
- block->desugared = desugarBlock(block);
- for (unsigned i = 0; i < block->desugared->statements.size(); ++i) {
- StatementAnalysis sa = analyzeBlockStatement(block->desugared->statements[i], env, ctx);
+ for (unsigned i = 0; i < block->statements.size(); ++i) {
+ StatementAnalysis sa = analyzeBlockStatement(block->statements[i], env, ctx);
if (sa != SA_FALLTHROUGH)
return sa;
}
View
@@ -512,7 +512,6 @@ struct Finally;
struct OnError;
struct Unreachable;
struct EvalStatement;
-struct WithStatement;
struct StaticAssertStatement;
struct FormalArg;
@@ -666,7 +665,6 @@ typedef Pointer<Finally> FinallyPtr;
typedef Pointer<OnError> OnErrorPtr;
typedef Pointer<Unreachable> UnreachablePtr;
typedef Pointer<EvalStatement> EvalStatementPtr;
-typedef Pointer<WithStatement> WithStatementPtr;
typedef Pointer<StaticAssertStatement> StaticAssertStatementPtr;
typedef Pointer<FormalArg> FormalArgPtr;
@@ -1412,7 +1410,6 @@ enum StatementKind {
ONERROR,
UNREACHABLE,
EVAL_STATEMENT,
- WITH,
STATIC_ASSERT_STATEMENT
};
@@ -1423,7 +1420,6 @@ struct Statement : public ANode {
};
struct Block : public Statement {
- BlockPtr desugared;
vector<StatementPtr> statements;
Block()
: Statement(BLOCK) {}
@@ -1704,16 +1700,6 @@ struct EvalStatement : public Statement {
: Statement(EVAL_STATEMENT), args(args), evaled(false) {}
};
-
-struct WithStatement : public Statement {
- vector<IdentifierPtr> lhs;
- ExprPtr rhs;
- Location withLocation;
- WithStatement( vector<IdentifierPtr> i, ExprPtr r, Location const &l)
- : Statement(WITH), lhs(i), rhs(r), withLocation(l) {}
-};
-
-
struct StaticAssertStatement : public Statement {
ExprPtr cond;
ExprListPtr message;
View
@@ -431,12 +431,6 @@ StatementPtr clone(StatementPtr x)
break;
}
- case WITH : {
- WithStatement *with= (WithStatement*)x.ptr();
- out = new WithStatement(with->lhs, with->rhs, with->withLocation);
- break;
- }
-
case STATIC_ASSERT_STATEMENT : {
StaticAssertStatement *staticAssert = (StaticAssertStatement *)x.ptr();
out = new StaticAssertStatement(clone(staticAssert->cond), clone(staticAssert->message));
View
@@ -3655,8 +3655,6 @@ static void codegenBlockStatement(BlockPtr block,
llvm::ArrayRef<StatementPtr> evaled = desugarEvalStatement(eval, env);
for (unsigned i = 0; i < evaled.size(); ++i)
codegenBlockStatement(block, i, evaled[i], env, ctx, terminated);
- } else if (stmt->stmtKind == WITH) {
- error("unexpected with statement");
} else {
terminated = codegenStatement(stmt, env, ctx);
}
View
@@ -405,61 +405,4 @@ llvm::ArrayRef<TopLevelItemPtr> desugarEvalTopLevel(EvalTopLevelPtr eval, EnvPtr
}
}
-static StatementPtr desugarWithBlock(WithStatementPtr with,
- llvm::ArrayRef<StatementPtr> statements, unsigned int i)
-{
- ++i;
- BlockPtr b = new Block();
- for (; i < statements.size(); ++i) {
- StatementPtr stmt = statements[i];
- if (stmt->stmtKind == WITH) {
- b->statements.push_back(desugarWithBlock((WithStatement *)stmt.ptr(), statements, i));
- break;
- }
- b->statements.push_back(statements[i]);
- }
-
- vector<FormalArgPtr> formalArgs;
- for(size_t i = 0; i < with->lhs.size(); i++) {
- formalArgs.push_back(new FormalArg(with->lhs.at(i), NULL, TEMPNESS_DONTCARE));
- }
-
- ExprPtr la = new Lambda(VALUE_CAPTURE, formalArgs, false, b.ptr());
- la->location = with->withLocation;
-
- if (with->rhs->exprKind != CALL) {
- error("the right hand side of a with statement must be a call.");
- }
-
- CallPtr call = (Call*)with->rhs.ptr();
-
- //prepend the lambda to the arguments for monad
- call->parenArgs->exprs.insert(call->parenArgs->exprs.begin(),la);
-
- //form the return yield expression
-
- ExprListPtr rexprs = new ExprList();
-
- rexprs->add(new Unpack(call.ptr()));
-
- StatementPtr r = new Return(RETURN_VALUE, rexprs);
- r->location = with->location;
-
- return r.ptr();
-}
-
-BlockPtr desugarBlock(BlockPtr block)
-{
- for (unsigned i = 0; i < block->statements.size(); ++i) {
- StatementPtr stmt = block->statements[i];
- if (stmt->stmtKind == WITH) {
- StatementPtr stn = desugarWithBlock((WithStatement *)stmt.ptr(), block->statements, i);
- block->statements[i] = stn;
- block->statements.resize( i + 1);
- break;
- }
- }
- return block;
-}
-
}
View
@@ -13,7 +13,6 @@ ExprListPtr desugarVariadicAssignmentRight(VariadicAssignment *x);
StatementPtr desugarForStatement(ForPtr x);
StatementPtr desugarCatchBlocks(llvm::ArrayRef<CatchPtr> catchBlocks);
StatementPtr desugarSwitchStatement(SwitchPtr x);
-BlockPtr desugarBlock(BlockPtr x);
ExprListPtr desugarEvalExpr(EvalExprPtr eval, EnvPtr env);
llvm::ArrayRef<StatementPtr> desugarEvalStatement(EvalStatementPtr eval, EnvPtr env);
View
@@ -2390,9 +2390,6 @@ TerminationPtr evalStatement(StatementPtr stmt,
error("unreachable statement");
return NULL;
}
- case WITH :
- error("unexpected with statement");
- return NULL;
case STATIC_ASSERT_STATEMENT : {
StaticAssertStatement *x = (StaticAssertStatement *)stmt.ptr();
View
@@ -348,10 +348,8 @@ void convertFreeVars(StatementPtr x, EnvPtr env, LambdaContext &ctx)
case BLOCK : {
Block *y = (Block *)x.ptr();
- if (!y->desugared)
- y->desugared = desugarBlock(y);
- for (unsigned i = 0; i < y->desugared->statements.size(); ++i) {
- StatementPtr z = y->desugared->statements[i];
+ for (unsigned i = 0; i < y->statements.size(); ++i) {
+ StatementPtr z = y->statements[i];
if (z->stmtKind == BINDING)
env = convertFreeVarsFromBinding((Binding *)z.ptr(), env, ctx);
else
View
@@ -140,7 +140,7 @@ static void initKeywords() {
"switch", "case", "break", "continue", "for", "in",
"true", "false", "try", "catch", "throw",
"finally", "onerror", "staticassert",
- "eval", "with", "when", "newtype",
+ "eval", "when", "newtype",
"__FILE__", "__LINE__", "__COLUMN__", "__ARG__", NULL};
keywords = new std::set<llvm::StringRef>();
for (const char **p = s; *p; ++p)
View
@@ -1104,35 +1104,9 @@ static bool localBinding(StatementPtr &x) {
return true;
}
-static bool blockItems(vector<StatementPtr> &stmts, bool);
-static bool withStatement(StatementPtr &x) {
- Location startLocation = currentLocation();
-
- if (!keyword("with")) return false;
- vector<IdentifierPtr> lhs;
-
- int p = save();
- if (!identifierList(lhs) || !opsymbol("=")) {
- lhs.clear();
- restore(p);
- }
- Location location = currentLocation();
-
- ExprPtr rhs = NULL;
- if (!suffixExpr(rhs)) return false;
- if (!symbol(";")) return false;
-
- WithStatementPtr w = new WithStatement(lhs, rhs, location);
-
- x = w.ptr();
- x->location = location;
- return true;
-}
-
static bool blockItem(StatementPtr &x) {
int p = save();
if (labelDef(x)) return true;
- if (restore(p), withStatement(x)) return true;
if (restore(p), localBinding(x)) return true;
if (restore(p), statement(x)) return true;
return false;
View
@@ -323,11 +323,6 @@ static void printExpr(llvm::raw_ostream &out, const Expr *x) {
static void printStatement(llvm::raw_ostream &out, const Statement *x) {
switch (x->stmtKind) {
- case WITH : {
- const WithStatement *y = (const WithStatement *)x;
- out << "WithStatement(" << y->lhs << ", " << y->rhs << ")";
- break;
- }
case BLOCK : {
const Block *y = (const Block *)x;
out << "Block(" << bigVec(y->statements) << ")";
@@ -1,29 +0,0 @@
-import printer.(println);
-
-variant V(Int, StringLiteralRef);
-
-
-[C] ignore (c:C, ..T)
-{
- c();
-}
-
-
-[C,V when Variant?(V) ]
-dispatch(c:C, v:V)
-{
- return ..c(*v);
-}
-
-test(m : V)
-{
- with ignore(3);
- with s = dispatch(m);
- println(s);
-}
-
-main()
-{
- test(V(5));
- test(V(StringLiteralRef(":)")));
-}
@@ -1,2 +0,0 @@
-5
-:)

0 comments on commit 7d89a32

Please sign in to comment.