Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove call-with-suffix syntax sugar

  • Loading branch information...
commit f8d59febe207897a2c4002fa27b6fe085206889b 1 parent 7d89a32
@agemogolk agemogolk authored
View
10 compiler/clay.hpp
@@ -1180,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 {
@@ -1373,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
View
2  compiler/clone.cpp
@@ -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;
}
View
1  compiler/lambdas.cpp
@@ -641,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
48 compiler/parser.cpp
@@ -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;
}
@@ -1324,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;
View
2  compiler/printer.cpp
@@ -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 : {
View
12 test/lang/variants/match/main.clay
@@ -2,14 +2,16 @@ import printer.(println);
variant Foo (Int, Double, StringLiteralRef);
foo(x) {
- match(x): (i:Int) => { println("I saw an Int ", i); }
- :: (f:Double) => { println("I saw a Double ", f); }
- :: (s:StringLiteralRef) => { println("I saw a string ", s); }
+ match(x, (i:Int) => { println("I saw an Int ", i); }
+ , (f:Double) => { println("I saw a Double ", f); }
+ , (s:StringLiteralRef) => { println("I saw a string ", s); }
+ );
}
bar(x) {
- match(x): (i:Int) => { println("I saw an Int ", i); }
- :: (x) => { println("I saw a non-Int ", x); }
+ match(x, (i:Int) => { println("I saw an Int ", i); }
+ , (x) => { println("I saw a non-Int ", x); }
+ );
}
main() {
View
18 test/lib-clay/lambdas/callsugar/main.clay
@@ -1,18 +0,0 @@
-import printer.(println);
-
-ifNonzero(x, ifTrue, ifFalse) {
- if (x != 0)
- return ..ifTrue(x);
- else
- return ..ifFalse();
-}
-
-main() {
- ifNonzero(1): x -> {
- println(x, " is not zero");
- } :: () -> {
- println("zero");
- }
-
- println(1, ifNonzero(1): x -> StringLiteralRef(" is not zero") :: () -> StringLiteralRef(" is zero"));
-}
View
2  test/lib-clay/lambdas/callsugar/out.txt
@@ -1,2 +0,0 @@
-1 is not zero
-1 is not zero
View
4 test/lib-clay/threads/locks/mutex/main.clay
@@ -7,9 +7,7 @@ var counter = Synchronized[UInt, Mutex](0u);
counterThread() {
for (x in range(1000))
- synchronized(counter): c -> {
- c +: 1;
- }
+ synchronized(counter, c -> {c +: 1;} );
}
main() {
View
4 test/lib-clay/threads/locks/spinlock/main.clay
@@ -7,9 +7,7 @@ var counter = Synchronized[UInt, Spinlock](0u);
counterThread() {
for (x in range(1000))
- synchronized(counter): c -> {
- c +: 1;
- }
+ synchronized(counter, c -> {c +: 1;} );
}
main() {
View
21 tools/bindgen.clay
@@ -416,12 +416,15 @@ visitToplevel(cursor:CXCursor, parent:CXCursor, data:CXClientData) : Int
else
printTo(g_bindingsOut, "cdecl");
- maybe(attributes.asmLabel): asmLabel -> {
- printTo(g_bindingsOut, ", ", stringRepr(asmLabel));
- } :: () -> {
- if (clayKeyword?(name))
- printTo(g_bindingsOut, ", ", stringRepr(name));
- }
+ maybe(attributes.asmLabel,
+ asmLabel -> {
+ printTo(g_bindingsOut, ", ", stringRepr(asmLabel));
+ },
+ () -> {
+ if (clayKeyword?(name))
+ printTo(g_bindingsOut, ", ", stringRepr(name));
+ }
+ );
printTo(g_bindingsOut, ") ", clayIdentifier(name), "(");
var argCount = clang_getNumArgTypes(type);
@@ -636,9 +639,9 @@ main(argc, argv)
try {
clang_argc, clang_argv, options = parseOptions(argc, argv);
- maybe(options.outputFileName): outputFileName -> {
- g_bindingsOut = File(outputFileName, CREATE);
- }
+ maybe(options.outputFileName,
+ outputFileName -> {g_bindingsOut = File(outputFileName, CREATE);}
+ );
} catch (ex:Usage) {
print(ex);
return 2;
Please sign in to comment.
Something went wrong with that request. Please try again.