Author: jbevain
Date: 2007-05-11 20:16:46 -0400 (Fri, 11 May 2007)
New Revision: 77272
Added:
trunk/cecil/bat/Mono.Bat/WriteAssemblyScript.cs
Modified:
trunk/cecil/bat/Mono.Bat.csproj
trunk/cecil/bat/Mono.Bat/AbstractAssemblyTestFixture.cs
trunk/cecil/bat/Mono.Bat/ReadAssemblyScript.cs
trunk/cecil/bat/Mono.Bat/ScriptCompiler.cs
Log:
add a write assembly script
Modified: trunk/cecil/bat/Mono.Bat/AbstractAssemblyTestFixture.cs
===================================================================
--- trunk/cecil/bat/Mono.Bat/AbstractAssemblyTestFixture.cs 2007-05-11
23:59:35 UTC (rev 77271)
+++ trunk/cecil/bat/Mono.Bat/AbstractAssemblyTestFixture.cs 2007-05-12
00:16:46 UTC (rev 77272)
@@ -39,27 +39,39 @@
protected void RunReadAssemblyTestCase (string file)
{
- string boo = GetTestCasePath (file + ".boo");
- ScriptCompiler<ReadAssemblyScript> sc = new
ScriptCompiler<ReadAssemblyScript> (boo);
- ReadAssemblyScript ras = sc.Compile ();
+ string boo = GetBooFile (file);
+ ReadAssemblyScript ras =
CompileBooFile<ReadAssemblyScript> (boo);
ras.ASM = FindCandidateAssembly (file);
- RunAndAssertOutput (boo, ras);
+ RunAndAssertOutput (boo, delegate { ras.Run (); });
}
+ string GetBooFile (string file)
+ {
+ return GetTestCasePath (file + ".boo");
+ }
+
protected AssemblyDefinition RunWriteAssemblyTestCase (string
file)
{
- return null;
+ string boo = GetBooFile (file);
+ string asm = Path.GetTempFileName ();
+ WriteAssemblyScript was =
CompileBooFile<WriteAssemblyScript> (boo);
+ was.DefineAssembly (file);
+ was.Run ();
+ AssemblyFactory.SaveAssembly (was.ASM, asm);
+ RunAndAssertOutput(boo, delegate {
AppDomain.CurrentDomain.ExecuteAssembly (asm); });
+ return was.ASM;
}
- protected AssemblyDefinition RunReadWriteAssemblyTestCase
(string file)
+ static TScript CompileBooFile<TScript> (string file) where
TScript : IScript
{
- return null;
+ ScriptCompiler<TScript> compiler = new
ScriptCompiler<TScript> (file);
+ return compiler.Compile ();
}
- static void RunAndAssertOutput (string file, IScript script)
+ static void RunAndAssertOutput (string file, Action a)
{
StringWriter sw = new StringWriter ();
- ChangeStandardOutput (sw, delegate { script.Run (); });
+ ChangeStandardOutput (sw, a);
AssertScriptOutput (file, sw.ToString ());
}
Modified: trunk/cecil/bat/Mono.Bat/ReadAssemblyScript.cs
===================================================================
--- trunk/cecil/bat/Mono.Bat/ReadAssemblyScript.cs 2007-05-11 23:59:35 UTC
(rev 77271)
+++ trunk/cecil/bat/Mono.Bat/ReadAssemblyScript.cs 2007-05-12 00:16:46 UTC
(rev 77272)
@@ -1,5 +1,5 @@
//
-// ReadAssembly.cs
+// ReadAssemblyScript.cs
//
// Author:
// Jb Evain ([EMAIL PROTECTED])
Modified: trunk/cecil/bat/Mono.Bat/ScriptCompiler.cs
===================================================================
--- trunk/cecil/bat/Mono.Bat/ScriptCompiler.cs 2007-05-11 23:59:35 UTC (rev
77271)
+++ trunk/cecil/bat/Mono.Bat/ScriptCompiler.cs 2007-05-12 00:16:46 UTC (rev
77272)
@@ -30,6 +30,7 @@
using Boo.Lang.Compiler;
using Boo.Lang.Compiler.IO;
using Boo.Lang.Compiler.Pipelines;
+using NUnit.Framework;
namespace Mono.Bat {
@@ -47,10 +48,16 @@
public TScript Compile ()
{
- _compiler.Run ();
+ CompilerContext result = _compiler.Run ();
+ AssertCompilerResult (result);
return _instantiater.Script;
}
+ static void AssertCompilerResult (CompilerContext result)
+ {
+ Assert.AreEqual (0, result.Errors.Count,
result.Errors.ToString (true));
+ }
+
void SetupCompiler (CompilerPipeline pipeline)
{
_compiler = new BooCompiler ();
Added: trunk/cecil/bat/Mono.Bat/WriteAssemblyScript.cs
===================================================================
--- trunk/cecil/bat/Mono.Bat/WriteAssemblyScript.cs 2007-05-11 23:59:35 UTC
(rev 77271)
+++ trunk/cecil/bat/Mono.Bat/WriteAssemblyScript.cs 2007-05-12 00:16:46 UTC
(rev 77272)
@@ -0,0 +1,80 @@
+//
+// WriteAssemblyScript.cs
+//
+// Author:
+// Jb Evain ([EMAIL PROTECTED])
+//
+// (C) 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+
+namespace Mono.Bat {
+
+ public abstract class WriteAssemblyScript : ReadAssemblyScript {
+
+ MethodBody _main;
+
+ public MethodBody Main {
+ get { return _main; }
+ set { _main = value; }
+ }
+
+ public void DefineAssembly (string name)
+ {
+ ASM = AssemblyFactory.DefineAssembly (name,
AssemblyKind.Console);
+
+ TypeDefinition prog = new TypeDefinition ("Program",
string.Empty, TypeAttributes.NotPublic, Import (typeof (object)));
+
+ MethodDefinition main = new MethodDefinition ("Main",
MethodAttributes.Static | MethodAttributes.Private, Import (typeof (void)));
+ main.Parameters.Add (new ParameterDefinition (Import
(typeof (string []))));
+
+ prog.Methods.Add (main);
+
+ ASM.MainModule.Types.Add(prog);
+ ASM.EntryPoint = main;
+ _main = main.Body;
+ }
+
+ protected MethodReference ImportConsoleWriteLine ()
+ {
+ return Import (typeof (Console).GetMethod ("WriteLine",
new Type [] { typeof (string) }));
+ }
+
+ protected TypeReference Import (Type type)
+ {
+ return ASM.MainModule.Import(type);
+ }
+
+ protected MethodReference Import (System.Reflection.MethodBase
method)
+ {
+ return ASM.MainModule.Import(method);
+ }
+
+ protected FieldReference Import (System.Reflection.FieldInfo
field)
+ {
+ return ASM.MainModule.Import(field);
+ }
+ }
+}
Property changes on: trunk/cecil/bat/Mono.Bat/WriteAssemblyScript.cs
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/cecil/bat/Mono.Bat.csproj
===================================================================
--- trunk/cecil/bat/Mono.Bat.csproj 2007-05-11 23:59:35 UTC (rev 77271)
+++ trunk/cecil/bat/Mono.Bat.csproj 2007-05-12 00:16:46 UTC (rev 77272)
@@ -54,6 +54,7 @@
<Compile Include="Mono.Bat\PrepareScript.cs" />
<Compile Include="Mono.Bat\InstantiateScript.cs" />
<Compile Include="Mono.Bat\ScriptCompiler.cs" />
+ <Compile Include="Mono.Bat\WriteAssemblyScript.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\lib\Mono.Cecil.csproj">
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches