External Compilation
Mon Jan 28 18:08:31 WET 2008 Miguel Vilaca <jmvilaca@di.uminho.pt>
* External Compilation
{
hunk ./Makefile 296
+src/INTextualUI.o : src/INTextualUI.hs
+src/INTextualUI.o : src/PersistentDocument.hi
+src/INTextualUI.o : src/State.hi
+src/INTextualUI.o : src/InfoKind.hi
+src/INTextualUI.o : src/INTextual.hi
+src/INTextualUI.o : src/SafetyNet.hi
+src/INTextualUI.o : src/Operations.hi
hunk ./Makefile 423
-src/INTextualUI.o : src/INTextualUI.hs
-src/INTextualUI.o : src/PersistentDocument.hi
-src/INTextualUI.o : src/State.hi
-src/INTextualUI.o : src/InfoKind.hi
-src/INTextualUI.o : src/INTextual.hi
-src/INTextualUI.o : src/SafetyNet.hi
-src/INTextualUI.o : src/Operations.hi
hunk ./Makefile 424
+src/Main.o : src/CommonUI.hi
+src/Main.o : src/INChecksUI.hi
+src/Main.o : src/SafetyNet.hi
hunk ./Makefile 428
+src/Main.o : src/INTextual.hi
+src/Main.o : src/PersistentDocument.hi
hunk ./src/INTextualUI.hs 3
+ , changeExt
hunk ./src/INTextualUI.hs 41
- let filename = aux tool . span (/= '.') $ fromMaybe "" inName [_$_]
+ let filename = changeExt ".INblobs" ('-':show tool ++ ".net") $ fromMaybe "" inName
hunk ./src/INTextualUI.hs 58
- aux tool (str,"") = str ++ '-':show tool ++ ".net"
- aux tool (str,".INblobs") = str ++ '-':show tool ++ ".net"
- aux tool (str1, str2) = let (str3,str4) = span (/='.') (tail str2)
- in aux tool (str1 ++ '.':str3, str4)
+
+-- | Change file extension and suffix filename.
+changeExt :: String -- ^ \".INblobs\"
+ -> String -- ^ \"-TOOL.net\"
+ -> String -- ^ file.INblobs
+ -> String -- ^ file-TOOL.net
+changeExt old suffix = aux . span (/= '.')
+ where
+ aux (str,"") = str ++ suffix
+ aux (str1, str2)
+ | str2 == old = str1 ++ suffix
+ | otherwise = let (str3,str4) = span (/='.') (tail str2)
+ in aux (str1 ++ '.':str3, str4)
hunk ./src/Main.hs 5
+import Graphics.UI.WXCore
hunk ./src/Main.hs 14
-import Maybe (fromJust)
-
+import Maybe (fromJust, fromMaybe)
+import qualified PersistentDocument as PD
+import INTextual
hunk ./src/Main.hs 18
+import SafetyNet
+import INChecksUI
+import CommonUI
+
+import Text.XML.HaXml.XmlContent (XmlContent)
+
+import System.Cmd
+import System.Exit
+
hunk ./src/Main.hs 49
+ , ("Compile through external compiler", compilePIN)
hunk ./src/Main.hs 69
+compilePIN :: (InfoKind n g, InfoKind e g, XmlContent g, Show g) => IOOp g n e
+compilePIN doc state =
+ do
+ logMessage "Compiling in PIN"
+ pDoc <- getDocument state
+ inName <- PD.getFileName pDoc
+ theFrame <- getNetworkFrame state
+
+ let fn = changeExt ".INblobs" "-PIN" $ fromMaybe "" inName
+ fnN = fn ++ ".net"
+ fnI = fn ++ ".INblobs"
+
+ writeFile fnI . showRepresentation PIN . simplify $ doc2net doc
+ comm <- textDialog theFrame "Command to invoque external compiler.\nThis special tokens can be used:\n#i for FILE.net\n#o for FILE.INblobs" "Compiling through external compiler" "java pin.compiler.Main #i"
+ when (not $ null comm) $
+ do
+ let command = subst fnN fnI comm
+ putStrLn command [_$_]
+ ec <- system command
+ case ec of
+ ExitSuccess ->
+ safetyNet theFrame $
+ openNetworkFile fnI state (Just theFrame)
+ >> singleCheckOverIN iNCheck state
+ ExitFailure n -> errorDialog theFrame "Compiling through external compiler"
+ $ "Error compiling through external compiler:\n"
+ ++ show ec
+ where subst inp out [] = []
+ subst inp out ('#':'i':str) = inp ++ subst inp out str
+ subst inp out ('#':'o':str) = out ++ subst inp out str
+ subst inp out (c:str) = c : subst inp out str
+
+
}