The Meta-Environment API

asf-actions.tb

Go to the documentation of this file.
00001 #ifndef __ASF_ACTIONS__
00002 #define __ASF_ACTIONS__
00003 
00004 #include <asf-utils.tb>
00005 #include <term-utils.tb>
00006 #include <undefined.h>
00007 #include <asf-pretty-print.tb>
00008 #include <sdf-pretty.tb>
00009 #include <sdf-utils.tb>
00010 #include <sdf-module-utils.tb>
00011 #include <lower-rstore.idef>
00012 #include <io-utils.tb>
00013 
00014 process AbortAsfeAction(EditorId : session-id) is
00015   snd-note(asfe-abort)
00016  
00017 process PrettyPrintSdfAction(EditorId : session-id) is
00018 let
00019   Tree : term,
00020   RTree : term,
00021   ModuleId: module-id,
00022   Path: str
00023 in
00024   GetModuleId(EditorId, ModuleId?)
00025   . GetPath(EditorId, Path?)
00026   . GetSDFParsetree(ModuleId, Tree?)
00027   .
00028   if not-equal(Tree, UNDEFINED) then
00029     PrettyPrintSdf(Path, Tree, RTree?)
00030     .
00031     if not-equal(RTree, UNDEFINED) then
00032       ReplaceFocus(EditorId, RTree)
00033       . MM-SetAttribute(ModuleId, SDF_NAMESPACE, "status", available)
00034     else 
00035       tau
00036     fi
00037   else
00038     tau
00039   fi
00040 endlet
00041 
00042 process PrettyPrintAction(EditorId : session-id, EditorType : term, Sort: str) is
00043 let
00044   Tree : term,
00045   RTree : term,
00046   ModuleId: module-id,
00047   Path: str
00048 in
00049   GetModuleId(EditorId, ModuleId?)
00050   . GetPath(EditorId, Path?)
00051   . GetTermParsetree(ModuleId, Path, Tree?)
00052   .
00053   if not-equal(Tree, UNDEFINED) then
00054     BoxAndPrettyPrint(ModuleId, Path, Tree, RTree?)
00055     . 
00056     if not-equal(RTree, UNDEFINED) then
00057       ReplaceFocus(EditorId, RTree)
00058     else 
00059       tau
00060     fi
00061   else tau
00062   fi
00063 endlet
00064 
00065 process DebugAction(EditorId : session-id) is
00066 let
00067   ModuleId : module-id,
00068   RunModuleId : module-id,
00069   Path: str,
00070   ResultTree: term,
00071   Sid: session-id,
00072   Pid: int,
00073   File: str
00074 in
00075   GetModuleId(EditorId, ModuleId?)
00076   . LookupFeatureModuleId(ModuleId,  "debug", RunModuleId?)
00077   .
00078   if not-equal(RunModuleId, UNDEFINED) then
00079     File := "debug.out"
00080     . GetPath(EditorId, Path?)
00081     . AddJob("Debugging while rewriting")
00082     . Reduce(RunModuleId, Path, off, ResultTree?)
00083     . 
00084     if not-equal(ResultTree, UNDEFINED) then
00085       snd-msg(em-get-session-by-path(File))
00086       .
00087       (
00088         rec-msg(em-session(File, Sid?))
00089         . DeleteSession(Sid)
00090       +
00091         rec-msg(em-no-such-session(File))
00092       )
00093       . ActivateEditorWithTree(ResultTree, ModuleId, File)
00094       . create(AmbiguityHandler(ResultTree, File), Pid?)
00095     else
00096       tau
00097     fi
00098     . JobDone("Debugging while rewriting")
00099   else
00100     tau
00101   fi
00102 endlet
00103 
00104 process RunAction(EditorId : session-id) is
00105 let
00106   ModuleId : module-id,
00107   RunModuleId : module-id,
00108   Path: str,
00109   ResultTree: term,
00110   Sid: session-id,
00111   Pid: int,
00112   File: str
00113 in
00114   GetModuleId(EditorId, ModuleId?)
00115   . LookupFeatureModuleId(ModuleId,  "run", RunModuleId?)
00116   .
00117   if not-equal(RunModuleId, UNDEFINED) then
00118     File := "run.out"
00119     . GetPath(EditorId, Path?)
00120     . AddJob("Running")
00121     . Reduce(RunModuleId, Path, off, ResultTree?)
00122     . 
00123     if not-equal(ResultTree, UNDEFINED) then
00124       snd-msg(em-get-session-by-path(File))
00125       .
00126       (
00127         rec-msg(em-session(File, Sid?))
00128         . DeleteSession(Sid)
00129       +
00130         rec-msg(em-no-such-session(File))
00131       )
00132       . ActivateEditorWithTree(ResultTree, ModuleId, File)
00133       . create(AmbiguityHandler(ResultTree, File), Pid?)
00134     else
00135       tau
00136     fi
00137     . JobDone("Running")
00138   else
00139     tau
00140   fi
00141 endlet
00142 
00143 process ExtractAction(EditorId : session-id) is
00144 let
00145   ModuleId : module-id,
00146   ExtractModuleId : module-id,
00147   Path: str,
00148   ResultTree: term,
00149   Pid: int,
00150   Language: str,
00151   ModuleName: str,
00152   RSId: int
00153 in
00154   GetModuleId(EditorId, ModuleId?)
00155   . LookupFeatureModuleId(ModuleId, "extract", ExtractModuleId?)
00156   .
00157   if not-equal(ExtractModuleId, UNDEFINED) then
00158     GetPath(EditorId, Path?)
00159     . MM-GetAttribute(ModuleId, SDF_NAMESPACE, "name", ModuleName?)
00160     . ComputeCanonicalLanguagename(ModuleName, Language?)
00161     . AddJob("Extracting")
00162     . Reduce(ExtractModuleId, Path, off, ResultTree?)
00163     . 
00164     if not-equal(ResultTree, UNDEFINED) then
00165       snd-msg(rs-lower-rstore(ResultTree))
00166       . rec-msg(rs-lowered-rstore(ResultTree?))
00167       . snd-msg(rc-load-rstore(Path, ResultTree))
00168     else
00169       snd-note(extract-rstore-failed(Language, Path))
00170     fi
00171     . JobDone("Extracting")
00172   else
00173     tau
00174   fi
00175 endlet
00176 
00177 process DrawAction(EditorId : session-id) is
00178 let
00179   ModuleId : module-id,
00180   DrawModuleId : module-id,
00181   Path: str,
00182   ResultTree: term,
00183   Pid: int,
00184   Language: str,
00185   ModuleName: str,
00186   CWD: str,
00187   File: str
00188 in
00189   GetModuleId(EditorId, ModuleId?)
00190   . LookupFeatureModuleId(ModuleId, "draw", DrawModuleId?)
00191   .
00192   if not-equal(DrawModuleId, UNDEFINED) then
00193     GetPath(EditorId, Path?)
00194     . MM-GetAttribute(ModuleId, SDF_NAMESPACE, "name", ModuleName?)
00195     . ComputeCanonicalLanguagename(ModuleName, Language?)
00196     . AddJob("Translating to SVG")
00197     . Reduce(DrawModuleId, Path, off, ResultTree?)
00198     . 
00199     if not-equal(ResultTree, UNDEFINED) then
00200       snd-msg(io-relative-to-absolute([library-path("CWD",".")]))
00201       . rec-msg(io-absolute-directories([library-path("CWD",CWD?)]))
00202       . WriteTreeToFile(ResultTree, "./result.svg")
00203       . File := concat(CWD, "/result.svg")
00204       . snd-msg(svg-display(Path, File))
00205     else
00206       printf("error: could not generate SVG picture")
00207     fi
00208     . JobDone("Translating to SVG")
00209   else
00210     tau
00211   fi
00212 endlet
00213 
00214 process DisplayAction(EditorId : session-id) is
00215 let
00216   ModuleId : module-id,
00217   DisplayModuleId : module-id,
00218   Path: str,
00219   ResultTree: term,
00220   Pid: int,
00221   Language: str,
00222   ModuleName: str,
00223   CWD: str,
00224   File: str
00225 in
00226   GetModuleId(EditorId, ModuleId?)
00227   . LookupFeatureModuleId(ModuleId, "display", DisplayModuleId?)
00228   .
00229   if not-equal(DisplayModuleId, UNDEFINED) then
00230     GetPath(EditorId, Path?)
00231     . MM-GetAttribute(ModuleId, SDF_NAMESPACE, "name", ModuleName?)
00232     . ComputeCanonicalLanguagename(ModuleName, Language?)
00233     . AddJob("Translating to SWIXML")
00234     . Reduce(DisplayModuleId, Path, off, ResultTree?)
00235     . 
00236     if not-equal(ResultTree, UNDEFINED) then
00237       snd-msg(io-relative-to-absolute([library-path("CWD",".")]))
00238       . rec-msg(io-absolute-directories([library-path("CWD",CWD?)]))
00239       . WriteTreeToFile(ResultTree, "./result.swixml")
00240       . File := concat(CWD, "/result.swixml")
00241       . snd-msg(swixml-display(Path, File))
00242     else
00243       printf("error: could not generate SWIXML GUI")
00244     fi
00245     . JobDone("Translating to SWIXML")
00246   else
00247     tau
00248   fi
00249 endlet
00250 
00251 process TestAction(EditorId : session-id) is
00252 let
00253   ModuleId : module-id,
00254   RunModuleId : module-id,
00255   Path: str,
00256   ResultTree: term,
00257   Summary: summary
00258 in
00259   GetModuleId(EditorId, ModuleId?)
00260   . LookupFeatureModuleId(ModuleId,  "test", RunModuleId?)
00261   .
00262   if not-equal(RunModuleId, UNDEFINED) then
00263     GetPath(EditorId, Path?)
00264     . AddJob("Testing")
00265     . Reduce(RunModuleId, Path, off, ResultTree?)
00266     . 
00267     if not-equal(ResultTree, UNDEFINED) then
00268       snd-msg(convert-feedback(ResultTree))
00269       . rec-msg(converted-feedback(Summary?))
00270       . RefreshSummary(Summary)
00271     else
00272       tau
00273     fi
00274     . JobDone("Testing")
00275   else
00276     tau
00277   fi
00278 endlet
00279 
00280 process CheckAction(EditorId : session-id) is
00281 let
00282   ModuleId : module-id,
00283   RunModuleId : module-id,
00284   Path: str,
00285   ResultTree: term,
00286   Summary: summary
00287 in
00288   GetModuleId(EditorId, ModuleId?)
00289   . LookupFeatureModuleId(ModuleId,  "check", RunModuleId?)
00290   .
00291   if not-equal(RunModuleId, UNDEFINED) then
00292     GetPath(EditorId, Path?)
00293     . AddJob("Checking")
00294     . Reduce(RunModuleId, Path, off, ResultTree?)
00295     . 
00296     if not-equal(ResultTree, UNDEFINED) then
00297       snd-msg(convert-feedback(ResultTree))
00298       . rec-msg(converted-feedback(Summary?))
00299       . RefreshSummary(Summary)
00300     else
00301       tau
00302     fi
00303     . JobDone("Checking")
00304   else
00305     tau
00306   fi
00307 endlet
00308 
00309 process ReduceAction(EditorId : session-id) is
00310 let
00311   ModuleId : module-id,
00312   Path: str,
00313   ResultTree: term,
00314   Sid: session-id,
00315   Pid: int
00316 in
00317   GetModuleId(EditorId, ModuleId?)
00318   . GetPath(EditorId, Path?)
00319   . AddJob("Rewriting")
00320   . Reduce(ModuleId, Path, off, ResultTree?)
00321   . 
00322   if not-equal(ResultTree, UNDEFINED) then
00323     snd-msg(em-get-session-by-path("reduct.out"))
00324     .
00325     (
00326       rec-msg(em-session("reduct.out", Sid?))
00327       . DeleteSession(Sid)
00328     +
00329       rec-msg(em-no-such-session("reduct.out"))
00330     )
00331     . ActivateEditorWithTree(ResultTree, ModuleId, "reduct.out")
00332     . create(AmbiguityHandler(ResultTree, "reduct.out"), Pid?)
00333   else
00334     tau
00335   fi
00336   . JobDone("Rewriting")
00337 endlet
00338 
00339 process DebugReduceAction(EditorId : session-id) is
00340 let
00341   ModuleId: module-id,
00342   Path: str,
00343   ResultTree: term
00344 in
00345   GetModuleId(EditorId, ModuleId?)
00346   . GetPath(EditorId, Path?)
00347   . Reduce(ModuleId, Path, on, ResultTree?)
00348   . ActivateEditorWithTree(ResultTree, ModuleId, "reduct.out")
00349 endlet
00350 
00351 process DumpEquationsAction(ModuleId : module-id) is
00352 let
00353   Cancel: bool,
00354   Path : str
00355 in
00356   PromptForFileWithExtension("Export Equations", [], ".eqs", Cancel?, Path?)
00357   .
00358   if equal(Cancel, true) then
00359     tau
00360   else
00361     DumpEquationsGivenFile(ModuleId, Path)
00362   fi
00363 endlet
00364 
00365 process CompileModuleAction(ModuleId : module-id) is
00366 let
00367   Cancel: bool,
00368   Path : str,
00369   NewPath : str
00370 in
00371   GetModulePath(ModuleId, SDF_NAMESPACE, Path?)
00372   . ReplaceExtension(Path, ".c", NewPath?) 
00373   . CompileModule(ModuleId, NewPath)
00374 endlet
00375 
00376 process RunAsfTestsAction(ModuleId : module-id) is
00377   TestAsfSpecification(ModuleId, off) 
00378 
00379 process DebugRunAsfTestsAction(ModuleId : module-id) is
00380   TestAsfSpecification(ModuleId, on)
00381 
00382 process EditorRunAsfTestsAction(EditorId : session-id) is
00383 let
00384   ModuleId : module-id
00385 in
00386   GetModuleId(EditorId, ModuleId?)
00387   . TestAsfSpecification(ModuleId, off)
00388 endlet
00389 
00390 process AsfSdfApiGenAction(ModuleId: module-id) is
00391 let
00392   Cancel: bool,
00393   Path: str,
00394   Paths: list
00395 in
00396   GetSearchPaths(Paths?)
00397   . PromptForFileWithExtension("Generate New Module", Paths, ".sdf", Cancel?, Path?)
00398   .
00399   if equal(Cancel, true) then
00400     tau
00401   else
00402     GenerateASFSDFApi(ModuleId, Path)
00403   fi
00404 endlet
00405 
00406 process PrintModuleAction(ModuleId : module-id) is
00407 let
00408   Cancel: bool,
00409   Path : str
00410 in
00411   PromptForFileWithExtension("Module Text (ASF+SDF)", [], ".txt", Cancel?, Path?)
00412   .
00413   if equal(Cancel, true) then
00414     tau
00415   else
00416     snd-msg(print-module(ModuleId, Path))
00417     . rec-msg(module-printed(ModuleId))
00418   fi
00419 endlet
00420 
00421 process DumpEquationsParseTableAction(ModuleId : module-id) is
00422 let
00423   Cancel: bool,
00424   Path : str
00425 in
00426   PromptForFileWithExtension("Export Equations ParseTable", [], ".asf.tbl", Cancel?, Path?)
00427   .
00428   if equal(Cancel, true) then
00429     tau
00430   else
00431     DumpParseTable(ModuleId, ASF_NAMESPACE, Path, eqs)
00432   fi
00433 endlet
00434 
00435 process EditorDumpEquationsParseTableAction(EditorId : session-id) is
00436 let
00437   Cancel: bool,
00438   Path : str,
00439   ModuleId : module-id
00440 in
00441   GetModuleId(EditorId, ModuleId?)
00442   . PromptForFileWithExtension("Export Equations ParseTable", [], ".asf.tbl", Cancel?, Path?)
00443   .
00444   if equal(Cancel, true) then
00445     tau
00446   else
00447     DumpParseTable(ModuleId, ASF_NAMESPACE, Path, eqs)
00448   fi
00449 endlet
00450 
00451 #endif /* __ASF_ACTIONS__ */

Generated on Fri Sep 12 13:16:07 2008 for asfsdf-meta by  doxygen 1.4.6