Permalink
Browse files

Merge pull request #441 from agemogolk/remove_syntax

Remove 'with' statement & lambda call-with-suffix syntax - issue #438
  • Loading branch information...
2 parents 453ab59 + 9ee686e commit fa7b2827e7fcec0cd754868ff0cf618ded8089f8 agemogolk committed Nov 10, 2012
@@ -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;
@@ -1182,16 +1180,14 @@ struct Indexing : public Expr {
struct Call : public Expr {
ExprPtr expr;
ExprListPtr parenArgs;
- ExprListPtr lambdaArgs;
ExprListPtr _allArgs;
ExprListPtr allArgs();
- Call(ExprPtr expr, ExprListPtr parenArgs, ExprListPtr lambdaArgs)
- : Expr(CALL), expr(expr), parenArgs(parenArgs), lambdaArgs(lambdaArgs),
+ Call(ExprPtr expr, ExprListPtr parenArgs)
+ : Expr(CALL), expr(expr), parenArgs(parenArgs),
_allArgs(NULL) {}
- Call(ExprPtr expr, ExprListPtr parenArgs);
};
struct FieldRef : public Expr {
@@ -1375,14 +1371,10 @@ inline ExprListPtr Call::allArgs() {
if (_allArgs == NULL) {
_allArgs = new ExprList();
_allArgs->add(parenArgs);
- _allArgs->add(lambdaArgs);
}
return _allArgs;
}
-inline Call::Call(ExprPtr expr, ExprListPtr parenArgs)
- : Expr(CALL), expr(expr), parenArgs(parenArgs), lambdaArgs(new ExprList()),
- _allArgs(NULL) {}
//
// Stmt
@@ -1412,7 +1404,6 @@ enum StatementKind {
ONERROR,
UNREACHABLE,
EVAL_STATEMENT,
- WITH,
STATIC_ASSERT_STATEMENT
};
@@ -1423,7 +1414,6 @@ struct Statement : public ANode {
};
struct Block : public Statement {
- BlockPtr desugared;
vector<StatementPtr> statements;
Block()
: Statement(BLOCK) {}
@@ -1704,16 +1694,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
@@ -122,7 +122,7 @@ ExprPtr clone(ExprPtr x)
case CALL : {
Call *y = (Call *)x.ptr();
- out = new Call(clone(y->expr), clone(y->parenArgs), clone(y->lambdaArgs));
+ out = new Call(clone(y->expr), clone(y->parenArgs));
break;
}
@@ -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));
@@ -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;
-}
-
}
@@ -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);
@@ -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();
@@ -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
@@ -643,7 +641,6 @@ void convertFreeVars(ExprPtr &x, EnvPtr env, LambdaContext &ctx)
Call *y = (Call *)x.ptr();
convertFreeVars(y->expr, env, ctx);
convertFreeVars(y->parenArgs, env, ctx);
- convertFreeVars(y->lambdaArgs, env, ctx);
break;
}
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
@@ -402,7 +402,7 @@ static bool stringLiteralSuffix(ExprPtr &x) {
ExprPtr str;
if (!stringLiteral(str)) return false;
ExprListPtr strArgs = new ExprList(str);
- x = new Call(NULL, strArgs, new ExprList());
+ x = new Call(NULL, strArgs);
x->location = location;
return true;
}
@@ -418,42 +418,13 @@ static bool indexingSuffix(ExprPtr &x) {
return true;
}
-static bool lambda(ExprPtr &x);
-
-static bool optCallLambdaList(ExprListPtr &args) {
- args = new ExprList();
-
- int p = save();
- if (!symbol(":")) {
- restore(p);
- return true;
- }
-
- while (true) {
- ExprPtr lambdaArg;
- Location startLocation = currentLocation();
- if (!lambda(lambdaArg)) return false;
- lambdaArg->startLocation = startLocation;
- lambdaArg->endLocation = currentLocation();
-
- args->add(lambdaArg);
- p = save();
- if (!symbol("::")) {
- restore(p);
- return true;
- }
- }
-}
-
static bool callSuffix(ExprPtr &x) {
Location location = currentLocation();
if (!symbol("(")) return false;
ExprListPtr args;
if (!optExpressionList(args)) return false;
if (!symbol(")")) return false;
- ExprListPtr lambdaArgs;
- if (!optCallLambdaList(lambdaArgs)) return false;
- x = new Call(NULL, args, lambdaArgs);
+ x = new Call(NULL, args);
x->location = location;
return true;
}
@@ -1104,35 +1075,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;
@@ -1350,24 +1295,11 @@ static bool switchStatement(StatementPtr &x) {
return true;
}
-static bool exprStatementNeedsSemicolon(ExprPtr expr) {
- if (expr->exprKind == CALL) {
- CallPtr call = (Call*)expr.ptr();
- unsigned lambdaCount = call->lambdaArgs->size();
- if (lambdaCount != 0) {
- LambdaPtr lastLambda = (Lambda*)call->lambdaArgs->exprs.back().ptr();
- assert(lastLambda->exprKind == LAMBDA);
- return lastLambda->body->stmtKind != BLOCK;
- }
- }
- return true;
-}
-
static bool exprStatement(StatementPtr &x) {
Location location = currentLocation();
ExprPtr y;
if (!expression(y)) return false;
- if (exprStatementNeedsSemicolon(y) && !symbol(";")) return false;
+ if (!symbol(";")) return false;
x = new ExprStatement(y);
x->location = location;
return true;
@@ -213,7 +213,7 @@ static void printExpr(llvm::raw_ostream &out, const Expr *x) {
}
case CALL : {
const Call *y = (const Call *)x;
- out << "Call(" << y->expr << ", " << y->parenArgs << ", " << y->lambdaArgs << ")";
+ out << "Call(" << y->expr << ", " << y->parenArgs << ")";
break;
}
case FIELD_REF : {
@@ -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) << ")";
Oops, something went wrong.

0 comments on commit fa7b282

Please sign in to comment.