PlayScriptRedux / playscript

PlayScript is an ActionScript compatible compiler and Flash compatible runtime that runs in the Mono/.NET environment
Other
17 stars 9 forks source link

System.InvalidProgramException: Invalid IL code in XXX() IL_0023: brfalse IL_00ba #64

Closed sushihangover closed 9 years ago

sushihangover commented 9 years ago

The following:

if( _width && _height ){

Where _width and _height are ActionScript Numbers and is producing the following invalid IL

    IL_001c:  nop 
    IL_001d:  ldarg.0 
    IL_001e:  ldfld float64 away3d.containers.View3D::_width
    IL_0023:  brfalse IL_00ba
System.InvalidProgramException: Invalid IL code in away3d.containers.View3D:updateBackBuffer (): IL_0023: brfalse   IL_00ba

  at away3d.containers.View3D.render () [0x0002a] in /Users/administrator/Documents/Code/playscript/playscriptredux/away3d-core-fp11/src/away3d/containers/View3D.as:603
  at _root.Basic_View._onEnterFrame (flash.events.Event e) [0x00022] in /Users/administrator/Documents/Code/playscript/playscriptredux/away3d-examples-fp11/src/Basic_View.as:99
  at PlayScript.InvokerA`1[flash.events.Event].InvokeOverrideA1 (System.Object a1) [0x0000d] in /Users/administrator/Documents/Code/playscript/playscriptredux/playscript/mcs/class/PlayScript.Dynamic/PlayScript/Invoker.cs:1005
  at flash.events.EventDispatcher.dispatchEvent (flash.events.Event ev) [0x00085] in /Users/administrator/Documents/Code/playscript/playscriptredux/playscript/mcs/class/pscorlib/flash/events/EventDispatcher.cs:129
sushihangover commented 9 years ago

New test: as/test-debug-as-I64.as

// Compiler options: -psstrict-
package {
    public class Foo {

        static var x:Number = 0.0;
        static var y:Number = 0.0;

        public static function Main():int {
                if ( x && y ) {
                        trace(x);
                        trace(y);
                        return 1;
                }
                return 0;
        }
    }
}
./pcompile as/test-debug-as-I64.as
./run as/test-debug-as-I64.exe
Unhandled Exception:
System.InvalidProgramException: Invalid IL code in _root.Foo:Main (): IL_0005: brfalse   IL_0034
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidProgramException: Invalid IL code in _root.Foo:Main (): IL_0005: brfalse   IL_0034
Exit Code : 1
sushihangover commented 9 years ago

Bad IL generation code from as/test-debug-as-I64.exe

    // method line 2
    .method public static hidebysig
           default int32 Main ()  cil managed
    {
        // Method begins at RVA 0x2058
    .entrypoint
    // Code size 54 (0x36)
    .maxstack 8
    IL_0000:  ldsfld float64 _root.Foo::x
    IL_0005:  brfalse IL_0034

    IL_000a:  ldsfld float64 _root.Foo::y
    IL_000f:  brfalse IL_0034

    IL_0014:  ldsfld float64 _root.Foo::x
    IL_0019:  box [mscorlib]System.Double
    IL_001e:  call void class [pscorlib_aot]_root.trace_fn::trace(object)
    IL_0023:  ldsfld float64 _root.Foo::y
    IL_0028:  box [mscorlib]System.Double
    IL_002d:  call void class [pscorlib_aot]_root.trace_fn::trace(object)
    IL_0032:  ldc.i4.1
    IL_0033:  ret
    IL_0034:  ldc.i4.0
    IL_0035:  ret
    } // end of method Foo::Main
sushihangover commented 9 years ago

Previous IL code:

// method line 2
    .method public static hidebysig
           default int32 Main ()  cil managed
    {
        // Method begins at RVA 0x2058
    .entrypoint
    // Code size 72 (0x48)
    .maxstack 2
    IL_0000:  ldsfld float64 _root.Foo::x
    IL_0005:  ldc.r8 0.
    IL_000e:  beq IL_0046

    IL_0013:  ldsfld float64 _root.Foo::y
    IL_0018:  ldc.r8 0.
    IL_0021:  beq IL_0046

    IL_0026:  ldsfld float64 _root.Foo::x
    IL_002b:  box [mscorlib]System.Double
    IL_0030:  call void class [pscorlib_aot]_root.trace_fn::trace(object)
    IL_0035:  ldsfld float64 _root.Foo::y
    IL_003a:  box [mscorlib]System.Double
    IL_003f:  call void class [pscorlib_aot]_root.trace_fn::trace(object)
    IL_0044:  ldc.i4.1
    IL_0045:  ret
    IL_0046:  ldc.i4.0
    IL_0047:  ret
    } // end of method Foo::Main
sushihangover commented 9 years ago

commit c917249c75ad6cb0eea1ecf46f406b81b6671373 Author: SushiHangover sushihangover@outlook.com Date: Sun Aug 16 13:32:28 2015 -0700

Fixes #64 - Logical && and || on doubles now get the doubles compared
to zero via bne and bne.un vs the failing brfalse