namespace macros import Boo.Lang.Compiler import Boo.Lang.Compiler.Ast import Boo.Lang.Compiler.MetaProgramming class WithMacro(AbstractAstMacro): override def Expand(node as MacroStatement): print "I'm in the macro" expression = node.Arguments[0] temp = uniqueReference() return [| block: $temp = $expression as System.IDisposable try: $(node.Block) ensure: if $temp is not null: $temp.Dispose() $temp = null |].Block def uniqueReference(): return ReferenceExpression("__temp${Context.AllocIndex()}") code = [| import macros import System.IO with reader = File.OpenText("warning.txt"): print reader.ReadLine() |] module = compile(code) print "after compile" module.EntryPoint.Invoke(null, (null,)) #print code.ToCodeString()