HaxeFoundation / hxcpp

Runtime files for c++ backend for haxe
Other
298 stars 190 forks source link

error: expected primary-expression before ‘;’ token #193

Closed ibilon closed 9 years ago

ibilon commented 9 years ago

When I tried HaxePunk with haxe 3.2, the new openfl/lime and hxcpp 3.2.37 I get this error:

Error: ./src/com/haxepunk/HaxePunkLogo.cpp: In member function ‘Void com::haxepunk::HaxePunkLogo_obj::__construct(int, int, Dynamic, Dynamic)::_Function_2_1::run(lime::graphics::Image)’:
./src/com/haxepunk/HaxePunkLogo.cpp:136:34: error: expected primary-expression before ‘;’ token
         int tmp22 = (Dynamic())++;  HX_STACK_VAR(tmp22,"tmp22");
hughsando commented 9 years ago

I tried the haxepunk empty project with openfl 2.2.2 (3 beta did not compile) and it does not generate a HaxePunkLogo.cpp file. Any more info of a project, or a reference to the HaxePunkLogo.hx file?

ibilon commented 9 years ago

This is the haxe code (https://github.com/HaxePunk/HaxePunk/blob/dev/com/haxepunk/Preloader.hx), commenting it prevent the error from happening.

@:bitmap("assets/graphics/preloader/haxepunk.png")
class HaxePunkLogo extends BitmapData {}

Here's the c++ file, https://gist.github.com/ibilon/5f448bf2403a65df40b0, in case it's useful.

hughsando commented 9 years ago

It looks like you are using openfl 3.0beta? But I can't get haxepunk to compile with this: C:/HaxeToolkit/haxe/lib/HaxePunk/git/com/haxepunk/HXP.hx:1223: characters 2-18 :flash.display.Stage has no field resize (Suggestion: __resize) Or with the non-git version. It does look like something that is coming from lime - and there is a lot of strange code there where it looks like it has inlined "null" into quite a few spots. Maybe the code that would construct this is: var x = null++; And some combination of macro/abstract is generating something a bit funky here.

On Sun, Mar 22, 2015 at 4:01 PM, Valentin Lemière notifications@github.com wrote:

This is the haxe code ( https://github.com/HaxePunk/HaxePunk/blob/dev/com/haxepunk/Preloader.hx), commenting it prevent the error from happening.

@:bitmap("assets/graphics/preloader/haxepunk.png") class HaxePunkLogo extends BitmapData {}

Here's the c++ file, https://gist.github.com/ibilon/5f448bf2403a65df40b0, in case it's useful.

— Reply to this email directly or view it on GitHub https://github.com/HaxeFoundation/hxcpp/issues/193#issuecomment-84551230 .

ibilon commented 9 years ago

Yes I'm trying openfl 3.

I've reproduced it with the openfl sample DisplayingABitmap (more simple to test since haxepunk isn't ready yet) by adding

@:bitmap("Assets/openfl.png")
class HaxePunkLogo extends BitmapData {}

same error

g++ -Iinclude -c -fvisibility=hidden -g -fpic -fPIC -DHX_LINUX -DHXCPP_DEBUG -DHXCPP_M64 -DHXCPP_VISIT_ALLOCS -DHXCPP_API_LEVEL=321 -m64 -DHXCPP_M64 -I/usr/lib/haxe/lib/hxcpp/3,2,37/include -x c++ -frtti -Wno-invalid-offsetof ./src/HaxePunkLogo.cpp -oobj/linux64-debug/2af284d7_HaxePunkLogo.o
Error: ./src/HaxePunkLogo.cpp: In member function ‘Void HaxePunkLogo_obj::__construct(int, int, Dynamic, Dynamic)::_Function_2_1::run(lime::graphics::Image)’:
./src/HaxePunkLogo.cpp:134:34: error: expected primary-expression before ‘;’ token
         int tmp22 = (Dynamic())++;  HX_STACK_VAR(tmp22,"tmp22");

works with openfl 2.2.8 so it may not be a hxcpp error after all.

I'll try figuring out what code process the @:bitmap.

hughsando commented 9 years ago

If you remove the inline from BitmapData.__fromBytes, I think it should work. This is big-ish routine, and I think inlining is only going to make your exe bigger, not faster. That said, It looks like the problem comes from a "var constructor = macro {" construct, which then calls an inline-function and inlines "null". I think the inlined value is evaluated int the macro context as null, not in the application context, which might not be null at runtime. So maybe this is a compiler problem. And that said, there is a problem with hxcpp, where it shortcuts inlined null-field access to an empty statement, which does not work well with "++" (on gcc, msvc is ok). eg:

import haxe.macro.Context;
import haxe.macro.Expr;

#if !macro
@:build(Test.build())
#end
class Test
{
   var field:Int;

   inline function incField()  field++;

   inline static function doInc(t:Test) t.incField();

   macro public static function build ():Array<Field> {
      var fields = Context.getBuildFields();
      var newField = macro { 
        doInc(null);
      };
      fields.push ({ name: "genField", access: [ APublic ], kind: FFun({ args: [], expr: newField, params: [], ret: null }), pos: Context.currentPos() });
      return fields;
   }
   public static function main() { }
}