Created
November 20, 2015 10:24
-
-
Save leppie/add00f54e6bc180ea7d1 to your computer and use it in GitHub Desktop.
Tail call test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c:\Users\lpritcha\Downloads\IronScheme-115404\IronScheme>IronScheme.Console32-v2.exe | |
IronScheme TFS:115404 ironscheme.codeplex.com © 2007,2008,2009,2010,2011,2012,2013,2014,2015 Llewellyn Pritchard (.NET 2.0 32-bit) | |
> (import (tc))(test) | |
Unhandled exception during evaluation: | |
&assertion | |
&message: "moo" | |
&irritants: () | |
&stacktrace | |
[1] "ironscheme.exceptions::raise(obj)" | |
[2] "tc.test##even?$3(n)" | |
[3] "tc.test()" | |
[4] "IronScheme.Scripting.ScriptCode.Run(CodeContext codeContext, Boolean tryEvaluate)" | |
[5] "IronScheme.Scripting.ScriptCode.Run(ScriptModule module)" | |
[6] "IronScheme.Runtime.Builtins.<>c__DisplayClass11.<CompileCore>b__b()" | |
[7] "ironscheme.exceptions::dynamic-wind(in, proc, out)" | |
[8] "ironscheme.exceptions::dynamic-wind(in, proc, out)" | |
[9] "IronScheme.Runtime.Builtins.CallWithCurrentContinuation(fc1)" | |
[10] "IronScheme.Runtime.R6RS.Exceptions.WithClrExceptionHandler(handler, thunk)" | |
[11] "psyntax.main::eval-top-level(x)" | |
[12] "IronScheme.Scripting.ScriptCode.Run(CodeContext codeContext, Boolean tryEvaluate)" | |
[13] "IronScheme.Scripting.ScriptCode.Run(ScriptModule module)" | |
[14] "IronScheme.Scripting.Hosting.CompiledCode.Evaluate(IScriptModule module)" | |
[15] "IronScheme.Scripting.Hosting.ScriptEngine.ExecuteInteractiveCode(String code, IScriptModule module)" | |
[16] "IronScheme.Scripting.Hosting.ScriptEngine.ExecuteCommand(String code, IScriptModule module)" | |
[17] "IronScheme.Scripting.Shell.CommandLine.RunOneInteraction()" | |
[18] "IronScheme.Scripting.Shell.CommandLine.TryInteractiveAction()" | |
[19] "IronScheme.Scripting.Shell.CommandLine.RunInteractiveLoop()" | |
[20] "IronScheme.Scripting.Shell.CommandLine.RunInteractive()" | |
[21] "IronScheme.Scripting.Shell.CommandLine.Run()" | |
[22] "IronScheme.Scripting.Shell.CommandLine.Run(IScriptEngine engine, IConsole console, ConsoleOptions options)" | |
[23] "IronScheme.Scripting.Hosting.ConsoleHost.RunCommandLine(OptionsParser optionsParser)" | |
[24] "IronScheme.Scripting.Hosting.ConsoleHost.ExecuteInternal()" | |
[25] "IronScheme.Scripting.Hosting.ConsoleHost.Execute()" | |
[26] "IronScheme.Scripting.Hosting.ConsoleHost.Run(String[] args)" | |
[27] "IronScheme.Hosting.IronSchemeConsoleHost.Execute(String[] args)" | |
[28] "IronScheme.Runtime.Program.Main(String[] args)" | |
> ^Z | |
c:\Users\lpritcha\Downloads\IronScheme-115404\IronScheme>IronScheme.Console32-v4.exe | |
IronScheme TFS:115404 ironscheme.codeplex.com © 2007,2008,2009,2010,2011,2012,2013,2014,2015 Llewellyn Pritchard (.NET 4.0 32-bit) | |
> (import (tc))(test) | |
Unhandled exception during evaluation: | |
&assertion | |
&message: "moo" | |
&irritants: () | |
&stacktrace | |
[1] "ironscheme.exceptions::raise(obj)" | |
[2] "tc.test##even?$3(n)" | |
[3] "tc.test()" | |
[4] "IronScheme.Scripting.ScriptCode.Run(CodeContext codeContext, Boolean tryEvaluate)" | |
[5] "IronScheme.Scripting.ScriptCode.Run(ScriptModule module)" | |
[6] "IronScheme.Runtime.Builtins.<>c__DisplayClass11.<CompileCore>b__b()" | |
[7] "ironscheme.exceptions::dynamic-wind(in, proc, out)" | |
[8] "ironscheme.exceptions::dynamic-wind(in, proc, out)" | |
[9] "IronScheme.Runtime.Builtins.CallWithCurrentContinuation(fc1)" | |
[10] "IronScheme.Runtime.R6RS.Exceptions.WithClrExceptionHandler(handler, thunk)" | |
[11] "psyntax.main::eval-top-level(x)" | |
[12] "IronScheme.Scripting.ScriptCode.Run(CodeContext codeContext, Boolean tryEvaluate)" | |
[13] "IronScheme.Scripting.ScriptCode.Run(ScriptModule module)" | |
[14] "IronScheme.Scripting.Hosting.CompiledCode.Evaluate(IScriptModule module)" | |
[15] "IronScheme.Scripting.Hosting.ScriptEngine.ExecuteInteractiveCode(String code, IScriptModule module)" | |
[16] "IronScheme.Scripting.Hosting.ScriptEngine.ExecuteCommand(String code, IScriptModule module)" | |
[17] "IronScheme.Scripting.Shell.CommandLine.RunOneInteraction()" | |
[18] "IronScheme.Scripting.Shell.CommandLine.TryInteractiveAction()" | |
[19] "IronScheme.Scripting.Shell.CommandLine.RunInteractiveLoop()" | |
[20] "IronScheme.Scripting.Shell.CommandLine.RunInteractive()" | |
[21] "IronScheme.Scripting.Shell.CommandLine.Run()" | |
[22] "IronScheme.Scripting.Shell.CommandLine.Run(IScriptEngine engine, IConsole console, ConsoleOptions options)" | |
[23] "IronScheme.Scripting.Hosting.ConsoleHost.RunCommandLine(OptionsParser optionsParser)" | |
[24] "IronScheme.Scripting.Hosting.ConsoleHost.ExecuteInternal()" | |
[25] "IronScheme.Scripting.Hosting.ConsoleHost.Execute()" | |
[26] "IronScheme.Scripting.Hosting.ConsoleHost.Run(String[] args)" | |
[27] "IronScheme.Runtime.Program.Main(String[] args)" | |
> ^Z | |
c:\Users\lpritcha\Downloads\IronScheme-115404\IronScheme>IronScheme.Console-v2.exe | |
IronScheme TFS:115404 ironscheme.codeplex.com © 2007,2008,2009,2010,2011,2012,2013,2014,2015 Llewellyn Pritchard (.NET 2.0 64-bit) | |
> (import (tc))(test) | |
Unhandled exception during evaluation: | |
&assertion | |
&message: "moo" | |
&irritants: () | |
&stacktrace | |
[1] "ironscheme.exceptions::raise(obj)" | |
[2] "tc.test##even?$3(n)" | |
[3] "tc.test()" | |
[4] "ironscheme.exceptions::dynamic-wind(in, proc, out)" | |
[5] "ironscheme.exceptions::dynamic-wind(in, proc, out)" | |
[6] "IronScheme.Runtime.Builtins.CallWithCurrentContinuation(fc1)" | |
[7] "IronScheme.Runtime.R6RS.Exceptions.WithClrExceptionHandler(handler, thunk)" | |
[8] "IronScheme.Scripting.Hosting.CompiledCode.Evaluate(IScriptModule module)" | |
[9] "IronScheme.Scripting.Hosting.ScriptEngine.ExecuteInteractiveCode(String code, IScriptModule module)" | |
[10] "IronScheme.Scripting.Hosting.ScriptEngine.ExecuteCommand(String code, IScriptModule module)" | |
[11] "IronScheme.Scripting.Shell.CommandLine.RunOneInteraction()" | |
[12] "IronScheme.Scripting.Shell.CommandLine.TryInteractiveAction()" | |
[13] "IronScheme.Scripting.Shell.CommandLine.RunInteractiveLoop()" | |
[14] "IronScheme.Scripting.Shell.CommandLine.Run(IScriptEngine engine, IConsole console, ConsoleOptions options)" | |
[15] "IronScheme.Scripting.Hosting.ConsoleHost.RunCommandLine(OptionsParser optionsParser)" | |
[16] "IronScheme.Scripting.Hosting.ConsoleHost.ExecuteInternal()" | |
[17] "IronScheme.Scripting.Hosting.ConsoleHost.Run(String[] args)" | |
[18] "IronScheme.Runtime.Program.Main(String[] args)" | |
> ^Z | |
c:\Users\lpritcha\Downloads\IronScheme-115404\IronScheme>IronScheme.Console-v4.exe | |
IronScheme TFS:115404 ironscheme.codeplex.com © 2007,2008,2009,2010,2011,2012,2013,2014,2015 Llewellyn Pritchard (.NET 4.0 64-bit) | |
> (import (tc))(test) | |
Unhandled exception during evaluation: | |
&assertion | |
&message: "moo" | |
&irritants: () | |
&stacktrace | |
[1] "ironscheme.exceptions::raise(obj)" | |
[2] "tc.test()" | |
[3] "ironscheme.exceptions::dynamic-wind(in, proc, out)" | |
[4] "ironscheme.exceptions::dynamic-wind(in, proc, out)" | |
[5] "IronScheme.Runtime.Builtins.CallWithCurrentContinuation(fc1)" | |
[6] "IronScheme.Runtime.R6RS.Exceptions.WithClrExceptionHandler(handler, thunk)" | |
[7] "IronScheme.Scripting.Hosting.CompiledCode.Evaluate(IScriptModule module)" | |
[8] "IronScheme.Scripting.Hosting.ScriptEngine.ExecuteInteractiveCode(String code, IScriptModule module)" | |
[9] "IronScheme.Scripting.Hosting.ScriptEngine.ExecuteCommand(String code, IScriptModule module)" | |
[10] "IronScheme.Scripting.Shell.CommandLine.RunOneInteraction()" | |
[11] "IronScheme.Scripting.Shell.CommandLine.TryInteractiveAction()" | |
[12] "IronScheme.Scripting.Shell.CommandLine.RunInteractiveLoop()" | |
[13] "IronScheme.Scripting.Shell.CommandLine.Run(IScriptEngine engine, IConsole console, ConsoleOptions options)" | |
[14] "IronScheme.Scripting.Hosting.ConsoleHost.RunCommandLine(OptionsParser optionsParser)" | |
[15] "IronScheme.Scripting.Hosting.ConsoleHost.ExecuteInternal()" | |
[16] "IronScheme.Scripting.Hosting.ConsoleHost.Run(String[] args)" | |
[17] "IronScheme.Runtime.Program.Main(String[] args)" | |
> ^Z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(library (tc) | |
(export test) | |
(import (ironscheme)) | |
(define (test) | |
(display-stacktrace #t) | |
(letrec ((even? | |
(lambda (n) | |
(if (zero? n) | |
(assertion-violation #f "moo") | |
(odd? (- n 1))))) | |
(odd? | |
(lambda (n) | |
(if (zero? n) | |
#f | |
(even? (- n 1)))))) | |
(display (even? 88))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static object test() | |
{ | |
CodeContext _global_context = tc.__global_context; | |
$env1 $env; | |
Storage<$env1> $parent$; | |
($parent$ = new Storage<$env1>($env = new $env1())).Data.$parent$ = $parent$; | |
CodeContext @object = RuntimeHelpers.CreateNestedCodeContext($env.$parent$, _global_context); | |
Helpers.RequiresNotNull<Callable>(tc.g$display-stacktrace$29538$1wBMXo.CurrentValue).Call(RuntimeHelpers.True); | |
Callable callable = Closure.Create(new CallTarget1(@object.test##even?$3), 1); | |
Callable callable2 = Closure.Create(new CallTarget1(@object.test##odd?$4), 1); | |
Callable callable3 = callable; | |
$env.g$even?$11$1NF2oW = callable3; | |
callable3 = callable2; | |
$env.g$odd?$13$1NF2oW = callable3; | |
return #.ironscheme.generic-writer::display($env.g$even?$11$1NF2oW.Call(RuntimeHelpers.Int32ToObject(88))); | |
} | |
private static object test##even?$3(CodeContext $context, object n) | |
{ | |
Scope scope = $context.Scope; | |
$env1 storageData = RuntimeHelpers.GetStorageData<$env1>(scope); | |
if (Builtins.IsTrue(#.ironscheme.numbers::zero?(n))) | |
{ | |
return #.ironscheme.exceptions::assertion-violation+(RuntimeHelpers.False, "moo", Builtins.List()); | |
} | |
return storageData.g$odd?$13$1NF2oW.Call(#.ironscheme.primitive-numbers::-(n, RuntimeHelpers.Int32ToObject(1))); | |
} | |
private static object test##odd?$4(CodeContext $context, object n) | |
{ | |
Scope scope = $context.Scope; | |
$env1 storageData = RuntimeHelpers.GetStorageData<$env1>(scope); | |
if (Builtins.IsTrue(#.ironscheme.numbers::zero?(n))) | |
{ | |
return RuntimeHelpers.False; | |
} | |
return storageData.g$even?$11$1NF2oW.Call(#.ironscheme.primitive-numbers::-(n, RuntimeHelpers.Int32ToObject(1))); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.method private static | |
object 'test##even?$3' ( | |
class [IronScheme]IronScheme.Scripting.CodeContext $context, | |
object n | |
) cil managed | |
{ | |
// Method begins at RVA 0x2344 | |
// Code size 77 (0x4d) | |
.maxstack 6 | |
.locals init ( | |
[0] class [IronScheme]IronScheme.Scripting.Scope, | |
[1] class closure.$env1 | |
) | |
IL_0000: ldarg.0 | |
IL_0001: call instance class [IronScheme]IronScheme.Scripting.Scope [IronScheme]IronScheme.Scripting.CodeContext::get_Scope() | |
IL_0006: stloc.0 | |
IL_0007: ldloc.0 | |
IL_0008: call !!0 [IronScheme]IronScheme.Scripting.RuntimeHelpers::GetStorageData<class closure.$env1>(class [IronScheme]IronScheme.Scripting.Scope) | |
IL_000d: stloc.1 | |
IL_000e: ldarg.1 | |
IL_000f: call object [IronScheme]'#'::'ironscheme.numbers::zero?'(object) | |
IL_0014: call bool [IronScheme]IronScheme.Runtime.Builtins::IsTrue(object) | |
IL_0019: brfalse IL_0033 | |
IL_001e: ldsfld object [IronScheme]IronScheme.Scripting.RuntimeHelpers::False | |
IL_0023: ldstr "moo" | |
IL_0028: call object [IronScheme]IronScheme.Runtime.Builtins::List() | |
IL_002d: call object [IronScheme]'#'::'ironscheme.exceptions::assertion-violation+'(object, object, object) | |
IL_0032: ret | |
IL_0033: ldloc.1 | |
IL_0034: ldfld class [IronScheme]IronScheme.Runtime.Callable closure.$env1::g$odd?$13$1NF2oW | |
IL_0039: ldarg.1 | |
IL_003a: ldc.i4.1 | |
IL_003b: call object [IronScheme]IronScheme.Scripting.RuntimeHelpers::Int32ToObject(int32) | |
IL_0040: call object [IronScheme]'#'::'ironscheme.primitive-numbers::-'(object, object) | |
IL_0045: tail. | |
IL_0047: callvirt instance object [IronScheme]IronScheme.Runtime.Callable::Call(object) | |
IL_004c: ret | |
} // end of method tc::'test##even?$3' | |
.method private static | |
object 'test##odd?$4' ( | |
class [IronScheme]IronScheme.Scripting.CodeContext $context, | |
object n | |
) cil managed | |
{ | |
// Method begins at RVA 0x23a0 | |
// Code size 62 (0x3e) | |
.maxstack 4 | |
.locals init ( | |
[0] class [IronScheme]IronScheme.Scripting.Scope, | |
[1] class closure.$env1 | |
) | |
IL_0000: ldarg.0 | |
IL_0001: call instance class [IronScheme]IronScheme.Scripting.Scope [IronScheme]IronScheme.Scripting.CodeContext::get_Scope() | |
IL_0006: stloc.0 | |
IL_0007: ldloc.0 | |
IL_0008: call !!0 [IronScheme]IronScheme.Scripting.RuntimeHelpers::GetStorageData<class closure.$env1>(class [IronScheme]IronScheme.Scripting.Scope) | |
IL_000d: stloc.1 | |
IL_000e: ldarg.1 | |
IL_000f: call object [IronScheme]'#'::'ironscheme.numbers::zero?'(object) | |
IL_0014: call bool [IronScheme]IronScheme.Runtime.Builtins::IsTrue(object) | |
IL_0019: brfalse IL_0024 | |
IL_001e: ldsfld object [IronScheme]IronScheme.Scripting.RuntimeHelpers::False | |
IL_0023: ret | |
IL_0024: ldloc.1 | |
IL_0025: ldfld class [IronScheme]IronScheme.Runtime.Callable closure.$env1::g$even?$11$1NF2oW | |
IL_002a: ldarg.1 | |
IL_002b: ldc.i4.1 | |
IL_002c: call object [IronScheme]IronScheme.Scripting.RuntimeHelpers::Int32ToObject(int32) | |
IL_0031: call object [IronScheme]'#'::'ironscheme.primitive-numbers::-'(object, object) | |
IL_0036: tail. | |
IL_0038: callvirt instance object [IronScheme]IronScheme.Runtime.Callable::Call(object) | |
IL_003d: ret | |
} // end of method tc::'test##odd?$4' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One can clearly see the 64-bit JIT's using tail calls internally and liberally.