Charj: add syntax for divcon language constructs
authorAaron Becker <akbecker@gmail.com>
Thu, 16 Sep 2010 21:13:08 +0000 (16:13 -0500)
committerAaron Becker <akbecker@gmail.com>
Thu, 16 Sep 2010 21:13:08 +0000 (16:13 -0500)
src/langs/charj/src/charj/translator/Charj.g
src/langs/charj/src/charj/translator/CharjASTModifier.g
src/langs/charj/src/charj/translator/CharjASTModifier2.g
src/langs/charj/src/charj/translator/CharjEmitter.g
src/langs/charj/src/charj/translator/CharjSemantics.g
src/langs/charj/src/charj/translator/InitPUPCollector.g
src/langs/charj/src/charj/translator/SymbolDefiner.g
src/langs/charj/src/charj/translator/SymbolResolver.g
src/langs/charj/tests/divcon/SimpleDivCon.cj [new file with mode: 0644]

index a2ee0850b0c7b3cacbfc0ed2f155105465c12a7b..16342b75a36357a78e3f8171d2c51ebb76bdcefe 100644 (file)
@@ -33,7 +33,9 @@ tokens {
     CHAR                    = 'char'            ;
     BYTE                    = 'byte'            ;
     SHORT                   = 'short'           ;
+    IN                      = 'in'              ;
     INT                     = 'int'             ;
+    LET                     = 'let'             ;
     LONG                    = 'long'            ;
     FLOAT                   = 'float'           ;
     DOUBLE                  = 'double'          ;
@@ -68,8 +70,8 @@ tokens {
     GETNUMPES               = 'getNumPes'       ;
     GETNUMNODES             = 'getNumNodes'     ;
 
-       THISINDEX                               = 'thisIndex'           ;
-       THISPROXY                               = 'thisProxy'           ;
+    THISINDEX              = 'thisIndex'       ;
+    THISPROXY              = 'thisProxy'       ;
 
     FOR                     = 'for'             ;
     WHILE                   = 'while'           ;
@@ -167,6 +169,7 @@ tokens {
     ARRAY_ELEMENT_ACCESS;
     ARRAY_INITIALIZER;
     BLOCK;
+    DIVCON_BLOCK;
     CAST_EXPR;
     CATCH_CLAUSE_LIST;
     CLASS_CONSTRUCTOR_CALL;
@@ -186,11 +189,13 @@ tokens {
     FORMAL_PARAM_STD_DECL;
     FORMAL_PARAM_VARARG_DECL;
     FUNCTION_METHOD_DECL;
+    DIVCON_METHOD_DECL;
     GENERIC_TYPE_ARG_LIST;
     GENERIC_TYPE_PARAM_LIST;
     INTERFACE_TOP_LEVEL_SCOPE;
     IMPLEMENTS_CLAUSE;
     LABELED_STATEMENT;
+    LET_ASSIGNMENT;
     CHARJ_SOURCE;
     METHOD_CALL;
     ENTRY_METHOD_CALL;
@@ -345,6 +350,8 @@ classScopeDeclaration
                 ->  ^(CONSTRUCTOR_DECL[$ident, "CONSTRUCTOR_DECL"] modifierList? genericTypeParameterList? IDENT
                         formalParameterList block)
             )
+        |   type IDENT formalParameterList divconBlock
+            ->  ^(DIVCON_METHOD_DECL modifierList? type IDENT formalParameterList divconBlock)
         |   simpleType classFieldDeclaratorList ';'
             ->  ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType classFieldDeclaratorList)
         |   objectType classFieldDeclaratorList ';'
@@ -592,6 +599,32 @@ sdagStatement
         -> ^(WHEN (IDENT expression? formalParameterList)* block)
     ;
 
+divconBlock
+    :   divconExpr
+        ->  ^(DIVCON_BLOCK divconExpr)
+    ;
+
+divconAssignment
+    :   IDENT '=' expression
+        -> ^(LET_ASSIGNMENT IDENT expression)
+    ;
+
+divconAssignmentList
+    :   divconAssignment (','! divconAssignment)*
+    ;
+
+divconExpr
+    :   IF parenthesizedExpression ifExpr=divconExpr
+        (   ELSE elseExpr=divconExpr
+            ->  ^(IF parenthesizedExpression $ifExpr $elseExpr)
+        |
+            ->  ^(IF parenthesizedExpression $ifExpr)
+        )
+    |   LET ^divconAssignmentList IN divconExpr
+    |   expression ';'!
+    |   '{'! divconExpr '}'!
+    ;
+
 nonBlockStatement
     :   'assert' expr1=expression 
         (   ':' expr2=expression ';'
index 350914d82bbde9435a80171cb7f361099afbb31c..c36be52ca38beabc4a32cf90bf62c1c394b2e566 100644 (file)
@@ -102,6 +102,7 @@ classScopeDeclaration
             genericTypeParameterList? type IDENT formalParameterList domainExpression? block?)
         -> ^(FUNCTION_METHOD_DECL modifierList? genericTypeParameterList? 
             type IDENT formalParameterList domainExpression? block?)
+    |   ^(DIVCON_METHOD_DECL modifierList? type IDENT formalParameterList divconBlock)
     |   ^(PRIMITIVE_VAR_DECLARATION m = modifierList? simpleType variableDeclaratorList)
         -> {$modifierList.tree != null}? ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType variableDeclaratorList)
         -> ^(PRIMITIVE_VAR_DECLARATION 
@@ -311,6 +312,24 @@ statement
     |   block
     ;
 
+divconBlock
+    :   ^(DIVCON_BLOCK divconExpr)
+    ;
+
+divconAssignment
+    :   ^(LET_ASSIGNMENT IDENT expression)
+    ;
+
+divconAssignmentList
+    :   divconAssignment+
+    ;
+
+divconExpr
+    :   ^(IF parenthesizedExpression divconExpr divconExpr?)
+    |   ^(LET divconAssignmentList IN divconExpr)
+    |   expression
+    ;
+
 sdagStatement
     :   ^(OVERLAP block)
     |   ^(WHEN (IDENT expression? formalParameterList)* block)
index 560cd87e16acb144a762beca315b5d8870b5348f..89adb2dc778dd91e3f0312ab412bbb4f89019f71 100644 (file)
@@ -99,6 +99,7 @@ classScopeDeclaration
             type IDENT formalParameterList domainExpression? b=block)
     |   ^(ENTRY_FUNCTION_DECL modifierList? genericTypeParameterList?
             type IDENT entryFormalParameterList domainExpression? b=block)
+    |   ^(DIVCON_METHOD_DECL modifierList? type IDENT formalParameterList divconBlock)
     |   ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType variableDeclaratorList)
             //^(VAR_DECLARATOR_LIST field[$simpleType.type]+))
     |   ^(OBJECT_VAR_DECLARATION modifierList? objectType variableDeclaratorList)
@@ -325,6 +326,24 @@ statement
     | block
     ;
 
+divconBlock
+    :   ^(DIVCON_BLOCK divconExpr)
+    ;
+
+divconAssignment
+    :   ^(LET_ASSIGNMENT IDENT expression)
+    ;
+
+divconAssignmentList
+    :   divconAssignment+
+    ;
+
+divconExpr
+    :   ^(IF parenthesizedExpression divconExpr divconExpr?)
+    |   ^(LET divconAssignmentList IN divconExpr)
+    |   expression
+    ;
+
 sdagStatement
     :   ^(OVERLAP block)
     |   ^(WHEN (IDENT expression? formalParameterList)* block)
index 08c508c580a62730c46f3785efb3ad4ded8b98c1..f4a70bda92d980192eddc44743273bc0fe52a6d3 100644 (file)
@@ -292,6 +292,7 @@ classScopeDeclaration
                 fpl={$f.st}, 
                 block={$b.st})
         ->
+    |   ^(DIVCON_METHOD_DECL modifierList? type IDENT formalParameterList divconBlock)
     |   ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType variableDeclaratorList[null])
         -> {emitH()}? class_var_decl(
             modl={$modifierList.st},
@@ -692,6 +693,24 @@ statement
         -> {$block.st}
     ;
 
+divconBlock
+    :   ^(DIVCON_BLOCK divconExpr)
+    ;
+
+divconAssignment
+    :   ^(LET_ASSIGNMENT IDENT expression)
+    ;
+
+divconAssignmentList
+    :   divconAssignment+
+    ;
+
+divconExpr
+    :   ^(IF parenthesizedExpression divconExpr divconExpr?)
+    |   ^(LET divconAssignmentList IN divconExpr)
+    |   expression
+    ;
+
 sdagStatement
     :   ^(OVERLAP block)
         -> template(b={$block.st}) "} overlap <b> atomic {"
index affae75ff738a04253c657abd52eaa838f0fbc7b..bdc3da6ea33fb8ee15286c41d0376e2d14ed0793 100644 (file)
@@ -172,6 +172,7 @@ scope ScopeStack;
             ty=type IDENT formalParameterList a=arrayDeclaratorList? b=block)
         {
         }
+    |   ^(DIVCON_METHOD_DECL modifierList? type IDENT formalParameterList divconBlock)
     |   ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType
             ^(VAR_DECLARATOR_LIST field[$simpleType.type, false]+))
     |   ^(OBJECT_VAR_DECLARATION modifierList? objectType
@@ -410,6 +411,25 @@ localVariableDeclaration
         }
     ;
 
+
+divconBlock
+    :   ^(DIVCON_BLOCK divconExpr)
+    ;
+
+divconAssignment
+    :   ^(LET_ASSIGNMENT IDENT expression)
+    ;
+
+divconAssignmentList
+    :   divconAssignment+
+    ;
+
+divconExpr
+    :   ^(IF parenthesizedExpression divconExpr divconExpr?)
+    |   ^(LET divconAssignmentList IN divconExpr)
+    |   expression
+    ;
+
 statement
     : nonBlockStatement
     | block
index 21daa1398cc82f447cb98822f4311c048bd404c8..5bd286357bd0774ae5d1be63e0144b145d9587d2 100644 (file)
@@ -42,7 +42,7 @@ enterClass
     :   ^(TYPE classType IDENT
         (^('extends' .*))?
         (^('implements' .*))?
-        (^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL | PRIMITIVE_VAR_DECLARATION |
+        (^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL | DIVCON_METHOD_DECL | PRIMITIVE_VAR_DECLARATION
             OBJECT_VAR_DECLARATION | CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL) .*))*)
         {
             currentClass = (ClassSymbol)$IDENT.def.type;
index 0c1a5e20ee2ad8d50c8414ffe307e9e0e31dc73e..52f8ade1ff99679a6285aea6674162a115b039f2 100644 (file)
@@ -161,7 +161,7 @@ enterClass
     :   ^(TYPE classType IDENT
             (^('extends' parent=type))?
             (^('implements' type+))?
-            (^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL | PRIMITIVE_VAR_DECLARATION |
+            (^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL | DIVCON_METHOD_DECL | PRIMITIVE_VAR_DECLARATION |
                 OBJECT_VAR_DECLARATION | CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL) .*))*)
         {
             ClassSymbol sym = new ClassSymbol(symtab, $IDENT.text,
@@ -200,7 +200,7 @@ exitClass
     :   ^(TYPE classType IDENT
             (^('extends' parent=type))?
             (^('implements' type+))?
-            (^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL | PRIMITIVE_VAR_DECLARATION |
+            (^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL |  DIVCON_METHOD_DECL | PRIMITIVE_VAR_DECLARATION |
                 OBJECT_VAR_DECLARATION | CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL) .*))*)
         {
             //System.out.println("class " + currentScope);
index 217c0eaf5ff6bd44066ff533334810439f67b8a3..149345d1b40d664d6ae98425e50c6cb418861484 100644 (file)
@@ -64,7 +64,7 @@ enterClass
     :   ^(TYPE classType IDENT
             (^('extends' parent=type))?
             (^('implements' type+))?
-            (^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL | PRIMITIVE_VAR_DECLARATION |
+            (^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL | DIVCON_METHOD_DECL |  PRIMITIVE_VAR_DECLARATION |
                 OBJECT_VAR_DECLARATION | CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL) .*))*)
         {
             $IDENT.def.type = (ClassSymbol)$IDENT.def;
@@ -77,7 +77,7 @@ exitClass
     :   ^(TYPE classType IDENT
             (^('extends' parent=type))?
             (^('implements' type+))?
-            (^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL | PRIMITIVE_VAR_DECLARATION |
+            (^((FUNCTION_METHOD_DECL | ENTRY_FUNCTION_DECL | DIVCON_METHOD_DECL |  PRIMITIVE_VAR_DECLARATION |
                 OBJECT_VAR_DECLARATION | CONSTRUCTOR_DECL | ENTRY_CONSTRUCTOR_DECL) .*))*)
         { currentClass = null; }
     ;
diff --git a/src/langs/charj/tests/divcon/SimpleDivCon.cj b/src/langs/charj/tests/divcon/SimpleDivCon.cj
new file mode 100644 (file)
index 0000000..c3a0acc
--- /dev/null
@@ -0,0 +1,42 @@
+
+package tests;
+
+readonly Main@ main;
+
+public mainchare Main {
+    public entry Main(CkArgMsg m) { }
+}
+
+// Simple example of divcon use, directly translated from TMS example
+// (https://charm.cs.uiuc.edu/private/tms/listlog.php?param=834)
+public chare DivCon {
+    private int M;
+
+    public entry DivCon() {
+        M = 10;
+    }
+
+    private int f(int x) { return x; }
+    private int g(int x, int y) { return x; }
+
+    private int a(int x) { return x; }
+    private int b(int x, int y) { return x; }
+    private int c(int x) { return x; }
+    private int d(int x) { return x; }
+
+    public int f(int n) {
+        if (n < M) {
+            let
+                x1 = a(n),
+                x2 = b(x1, n)
+            in
+                f(x1 + x2);
+        } else {
+            let
+                x1 = c(n),
+                x2 = d(n)
+            in
+                g(x1, x2);
+        }
+    }
+}