Changeset 420


Ignore:
Timestamp:
Jun 11, 2010 9:40:39 AM (14 years ago)
Author:
Anya Helene Bagge
Message:
  • Reduce dependency on concrete syntax
  • Interface with Java module loader
Location:
MetaXa/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • MetaXa/src/MagnoliaCompile.rsc

    r403 r420  
    11module MagnoliaCompile
    2 import MagnoliaFront;
    3 import Magnolia;
    42import String;
    53import IO;
     
    86import XaLib;
    97import XaTree;
    10 import MagnoliaCxxBack;
    118
    129data MagnoliaEnv = environ(rel[Name, XaTree] members);
     
    3532}
    3633
    37 public Tree compileMagnolia(loc file) {
    38         Tree parsed = parseMagnolia(file);
    39         //Tree desugared = desugarMagnolia(parsed);
    40 
    41         decls = loadTree(parsed, file);
    42         return flattenConcepts(parsed, decls);
    43 }
    44 public str flattenModule(loc path, str project) {
    45         <tree, ctx> = loadFile(path, project);
    46         path.path = replaceLast(path.path, "\\.mg", "-flattened.mg");
     34//public Tree compileMagnolia(loc file) {
     35//      Tree parsed = parseMagnolia(file);
     36//      //Tree desugared = desugarMagnolia(parsed);
     37//
     38//      decls = loadTree(parsed, file);
     39//      return flattenConcepts(parsed, decls);
     40//}
     41//public str flattenModule(loc path, str project) {
     42//      <tree, ctx> = loadFile(path, project);
     43//      return unparse(reindent(flattenConcepts(tree, ctx)));
     44//}
     45public str flattenModule(XaTree tree, MagnoliaEnv ctx) {
    4746        return unparse(reindent(flattenConcepts(tree, ctx)));
    4847}
    49 
    50 public void flattenModule(str moduleName, str project) {
    51         path = findInPath("<moduleName>.mg", project);
    52         <tree, ctx> = loadFile(path);
    53         path.path = replaceLast(path.path, "\\.mg", "-flattened.mg");
    54         println("Writing flattened module to <path>");
    55         writeFile(path, unparse(reindent(flattenConcepts(tree, ctx))));
    56 }
    57 
    58 public void flattenModuleToCxx(str moduleName, str project) {
    59         path = findInPath("<moduleName>.mg", project);
    60         <tree, ctx> = loadFile(path, project);
    61         path.path = replaceLast(path.path, "\\.mg", ".cc");
    62         println("Writing flattened module to <path>");
    63         writeFile(path, unparse(reindent(cxxFormat(flattenConcepts(tree, ctx)))));
    64 }
    65 
    66 public tuple[XaTree, MagnoliaEnv] loadModule(str moduleName, str project) {
    67         path = findInPath("<moduleName>.mg", project);
    68         println("Loading module <moduleName> from <path>");
    69         return loadFile(path, project);
    70 }
    71 
    72 public tuple[XaTree, MagnoliaEnv] loadFile(loc moduleLoc, str project) {
     48//public void flattenModule(str moduleName, str project) {
     49//      path = findInPath("<moduleName>.mg", project);
     50//      <tree, ctx> = loadFile(path);
     51//      path.path = replaceLast(path.path, "\\.mg", "-flattened.mg");
     52//      println("Writing flattened module to <path>");
     53//      writeFile(path, unparse(reindent(flattenConcepts(tree, ctx))));
     54//}
     55
     56//public void flattenModuleToCxx(str moduleName, str project) {
     57//      path = findInPath("<moduleName>.mg", project);
     58//      <tree, ctx> = loadFile(path, project);
     59//      path.path = replaceLast(path.path, "\\.mg", ".cc");
     60//      println("Writing flattened module to <path>");
     61//      writeFile(path, unparse(reindent(cxxFormat(flattenConcepts(tree, ctx)))));
     62//}
     63
     64//public tuple[XaTree, MagnoliaEnv] loadModule(str moduleName, str project) {
     65//      path = findInPath("<moduleName>.mg", project);
     66//      println("Loading module <moduleName> from <path>");
     67//      return loadFile(path, project);
     68//}
     69
     70//public tuple[XaTree, MagnoliaEnv] loadFile(loc moduleLoc, str project) {
     71//      result = newEnv();
     72//      XaTree tree = parseMagnolia(moduleLoc);
     73//      if(cons("MagnoliaTree", [cons("ModuleHead", [NAME, seq(CLAUSES,_)], _), seq(DECLS,_)], _) := tree) {
     74//              for(clause <- CLAUSES) {
     75//                      switch(clause) {
     76//                              case cons("Imports", [seq(MODULES, _)], _):
     77//                                      for(cons("ImportAll", [m], _) <- MODULES) {
     78//                                              result = joinEnv(result, loadModule(unparse(m), project)[1]);
     79//                                      }
     80//                      }
     81//              }
     82//              for(decl <- DECLS) {
     83//                      // println(decl);
     84//                      switch(decl) {
     85//                              case cons("DefDecl", [cons("ConceptClause", [CONCEPT], _), _, cons(_, [seq(CONTENTS,_)], _)], _): {
     86//                                      result.members += {name(unparse(CONCEPT))} * toSet(CONTENTS);
     87//                              }
     88//                      }
     89//              }
     90//      }
     91//      return <tree, result>;
     92//}
     93
     94public MagnoliaEnv loadTrees(list[XaTree] trees) {
    7395        result = newEnv();
    74         XaTree tree = parseMagnolia(moduleLoc);
     96        for(tree <- trees)
     97                result = loadTree(tree, result);
     98        return result;
     99}
     100
     101public MagnoliaEnv loadTree(XaTree tree, MagnoliaEnv result) {
    75102        if(cons("MagnoliaTree", [cons("ModuleHead", [NAME, seq(CLAUSES,_)], _), seq(DECLS,_)], _) := tree) {
    76                 for(clause <- CLAUSES) {
    77                         switch(clause) {
    78                                 case cons("Imports", [seq(MODULES, _)], _):
    79                                         for(cons("ImportAll", [m], _) <- MODULES) {
    80                                                 result = joinEnv(result, loadModule(unparse(m), project)[1]);
    81                                         }
    82                         }
    83                 }
    84103                for(decl <- DECLS) {
    85104                        // println(decl);
    86105                        switch(decl) {
    87106                                case cons("DefDecl", [cons("ConceptClause", [CONCEPT], _), _, cons(_, [seq(CONTENTS,_)], _)], _): {
     107                                        println(name(unparse(CONCEPT)));
    88108                                        result.members += {name(unparse(CONCEPT))} * toSet(CONTENTS);
    89109                                }
     
    91111                }
    92112        }
    93         return <tree, result>;
     113        return result;
    94114}
    95115
    96116public XaTree flattenConcepts(XaTree tree, MagnoliaEnv env) {
    97117        return top-down-break visit(tree) {
    98                 case cDecl : cons("DefDecl", [cons("ConceptClause", [CONCEPT], ccsort), seq(SUBCLAUSES,scsort), cons("DeclBody", [seq(CONTENTS,_)], _)], _) : {
    99                         //      println("Looking at <unparse(CONCEPT)>: ");
     118                case cDecl : cons("DefDecl", [cons("ConceptClause", [CONCEPT], _), seq(SUBCLAUSES,_), cons("DeclBody", [seq(CONTENTS,_)], _)], _) : {
     119                        println("Looking at <unparse(CONCEPT)>: ");
    100120                        set[XaTree] decls = {};
    101121                        for(decl <- CONTENTS) {
    102                                 //      println("  Decl: ", decl);
     122                                println("  Decl: ", decl);
    103123                                switch(decl) {
    104124                                        case cons("Requires", [seq(reqs, _)], _):
    105125                                                for(req  <- reqs) {
    106                                                         // println("  <unparse(CONCEPT)> requires <unparse(req)>:");
     126                                                        println("  <unparse(CONCEPT)> requires <unparse(req)>:");
    107127                                                        <ds, env> = getConcept(req, env);
    108128                                                        decls += ds;
     
    140160                        insert decl;
    141161                }
    142                 case cDecl: cons(c,as,"Decl") => cDecl
     162                //case cDecl: cons(c,as,"Decl") => cDecl
    143163        }
    144164}
  • MetaXa/src/XaTree.rsc

    r413 r420  
    3131        implodeOptions(bool foldInjections, bool addConcrete, bool addLocation, list[str] varConses);
    3232
    33 XaImplodeOpts defaultOpts = implodeOptions(true, true, false, ["RascalVar", "RascalListVar"]);
     33XaImplodeOpts defaultOpts = implodeOptions(true, false, false, ["RascalVar", "RascalListVar"]);
    3434
    3535public XaTree implodeTree(Tree t) { return implodeTree(t, defaultOpts); }
     
    138138                                case cf(opt(layout())): {
    139139                                        l = unparse(ts[i]);
    140                                         if(/^<before:\s*><com:\S(.|\r|\n)*\S><after:\s*>$/ := l) {
     140                                        if(false && /^<before:\s*><com:\S(.|\r|\n)*\S><after:\s*>$/ := l) {
    141141                                                if(before != "")
    142142                                                        cstArgs += layout(before);
  • MetaXa/src/gen-tbl

    r407 r420  
    1 LD_LIBRARY_PATH=/home/anya/eclipse/plugins/rascal_fragment_linux_0.1.5/installed/lib/ /home/anya/eclipse/plugins/rascal_fragment_linux_0.1.5/installed/bin/sdf2table -c -m Magnolia -o Magnolia.tbl
     1if [ -d /home/anya/eclipse/ ]; then
     2        ECLIPSE=/home/anya/eclipse
     3elif [ -d /usr/local/eclipse/ ]; then
     4        ECLIPSE=/usr/local/eclipse
     5fi
     6
     7LD_LIBRARY_PATH=$ECLIPSE/plugins/rascal_fragment_linux_0.1.5/installed/lib/ $ECLIPSE/plugins/rascal_fragment_linux_0.1.5/installed/bin/sdf2table -c -m Magnolia -o Magnolia.tbl
     8
Note: See TracChangeset for help on using the changeset viewer.