C++ "native" target.

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

C++ "native" target.

Slav
Hello. At first, I want to say thank you for this useful and interesting project and want to get some advices on how can I apply him on my sort of tasks.

Currently (correct me if I am wrong) HaXe is developed and used to compile full target applications (and has the “main()” function). I do not know HaXe well in this sort of tasks and found it for precise my one: generally speaking, to write limited code chunk which will be executed only as part of the whole application which is absolutely differently implemented on each platform: I intend to implemented real-time multiplayer game where game logic has to be executed both on server and client; on server (C++) for multiplayer purpose and on client (C# for now but may be AS3 if adobe will, finally, introduce UDP-sockets) for ping compensation and traffic minimization (for client-side prediction). I tried to use Lua, Ruby and Python as scripting languages but it was too slow (10 ms on client to call script’s function and pretty fast on C++ server but for intended hudreds of simultaneous clients it’s slow too), so I found the solution which is “write this game logic code on some abstract language and then (after each it’s modification) convert it into each target platform” which will just include generated files along with platform specific ones. And then I found HaXe (what, honesly, was miracle), wrote C++ generator and started to use it (it's not fully implemented yet).
There already was the C++ target generator but it emulated dynamically typed language which is perfect for general purpose realization but was a little slow for mine - for this I was had to refuse “Dynamic” types usage and some other accompanying features and it’s not fatal for my sort of tasks if to take into account that all platform-specific code is written directly in target platform’s language and HaXe sources used along with it.
Along with that home-work I intend to introduce HaXe usage in my job where we make games and rewrite them from scratch for each platform (somewhere between C++, AS3, Java, WME...) but if there could be a way to write overall game logic on HaXe and then use it just as part of target platform’s sources.
So, is it possible and match with the whole HaXe’ design to do some work in this direction - use HaXe to write just parts of a target program (for example, compile code without “main()” function and introduce some new features such as “virtual APIs” and so on), or did I missed something - maybe there already exist something like that within HaXe or it's not impossible?
And, well, it can, then, perfectly fit for scripting langauge which will not require a virtual machine to execute on but will just compile into target platform's code and will be as fast as possible (at least faster than under VM)?

Anywat, it fits well for my current target but it will be good if someone will use it too - I will be glad if you let me into official SVN repository and will make any improvements. I uploaded several affected "HaXe" sources to temporary project http://code.google.com/p/hxcppn/ . I am new to OCaml, so, please, refer indulgently to my code.

Thank you.
--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: C++ "native" target.

davidedc
Nice one.

Did you include garbage collection or was that left out?

Can't seem to find any reference to it browsing the code.

Cheers,
Davide

Pardon any typos, sent from my mobile.

On 1 Oct 2011, at 12:41, Slav <[hidden email]> wrote:

Hello. At first, I want to say thank you for this useful and interesting project and want to get some advices on how can I apply him on my sort of tasks.

Currently (correct me if I am wrong) HaXe is developed and used to compile full target applications (and has the “main()” function). I do not know HaXe well in this sort of tasks and found it for precise my one: generally speaking, to write limited code chunk which will be executed only as part of the whole application which is absolutely differently implemented on each platform: I intend to implemented real-time multiplayer game where game logic has to be executed both on server and client; on server (C++) for multiplayer purpose and on client (C# for now but may be AS3 if adobe will, finally, introduce UDP-sockets) for ping compensation and traffic minimization (for client-side prediction). I tried to use Lua, Ruby and Python as scripting languages but it was too slow (10 ms on client to call script’s function and pretty fast on C++ server but for intended hudreds of simultaneous clients it’s slow too), so I found the solution which is “write this game logic code on some abstract language and then (after each it’s modification) convert it into each target platform” which will just include generated files along with platform specific ones. And then I found HaXe (what, honesly, was miracle), wrote C++ generator and started to use it (it's not fully implemented yet).
There already was the C++ target generator but it emulated dynamically typed language which is perfect for general purpose realization but was a little slow for mine - for this I was had to refuse “Dynamic” types usage and some other accompanying features and it’s not fatal for my sort of tasks if to take into account that all platform-specific code is written directly in target platform’s language and HaXe sources used along with it.
Along with that home-work I intend to introduce HaXe usage in my job where we make games and rewrite them from scratch for each platform (somewhere between C++, AS3, Java, WME...) but if there could be a way to write overall game logic on HaXe and then use it just as part of target platform’s sources.
So, is it possible and match with the whole HaXe’ design to do some work in this direction - use HaXe to write just parts of a target program (for example, compile code without “main()” function and introduce some new features such as “virtual APIs” and so on), or did I missed something - maybe there already exist something like that within HaXe or it's not impossible?
And, well, it can, then, perfectly fit for scripting langauge which will not require a virtual machine to execute on but will just compile into target platform's code and will be as fast as possible (at least faster than under VM)?

Anywat, it fits well for my current target but it will be good if someone will use it too - I will be glad if you let me into official SVN repository and will make any improvements. I uploaded several affected "HaXe" sources to temporary project http://code.google.com/p/hxcppn/ . I am new to OCaml, so, please, refer indulgently to my code.

Thank you.
--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: C++ "native" target.

Slav
Thank you.
I used boost::shared_ptr for automatic memory management - did not found how to do it more "native".

Target code generation file sources: http://code.google.com/p/hxcppn/source/browse/trunk/gencppn.ml

2011/10/1 Davide Della Casa <[hidden email]>
Nice one.

Did you include garbage collection or was that left out?

Can't seem to find any reference to it browsing the code.

Cheers,
Davide

Pardon any typos, sent from my mobile.

On 1 Oct 2011, at 12:41, Slav <[hidden email]> wrote:

Hello. At first, I want to say thank you for this useful and interesting project and want to get some advices on how can I apply him on my sort of tasks.

Currently (correct me if I am wrong) HaXe is developed and used to compile full target applications (and has the “main()” function). I do not know HaXe well in this sort of tasks and found it for precise my one: generally speaking, to write limited code chunk which will be executed only as part of the whole application which is absolutely differently implemented on each platform: I intend to implemented real-time multiplayer game where game logic has to be executed both on server and client; on server (C++) for multiplayer purpose and on client (C# for now but may be AS3 if adobe will, finally, introduce UDP-sockets) for ping compensation and traffic minimization (for client-side prediction). I tried to use Lua, Ruby and Python as scripting languages but it was too slow (10 ms on client to call script’s function and pretty fast on C++ server but for intended hudreds of simultaneous clients it’s slow too), so I found the solution which is “write this game logic code on some abstract language and then (after each it’s modification) convert it into each target platform” which will just include generated files along with platform specific ones. And then I found HaXe (what, honesly, was miracle), wrote C++ generator and started to use it (it's not fully implemented yet).
There already was the C++ target generator but it emulated dynamically typed language which is perfect for general purpose realization but was a little slow for mine - for this I was had to refuse “Dynamic” types usage and some other accompanying features and it’s not fatal for my sort of tasks if to take into account that all platform-specific code is written directly in target platform’s language and HaXe sources used along with it.
Along with that home-work I intend to introduce HaXe usage in my job where we make games and rewrite them from scratch for each platform (somewhere between C++, AS3, Java, WME...) but if there could be a way to write overall game logic on HaXe and then use it just as part of target platform’s sources.
So, is it possible and match with the whole HaXe’ design to do some work in this direction - use HaXe to write just parts of a target program (for example, compile code without “main()” function and introduce some new features such as “virtual APIs” and so on), or did I missed something - maybe there already exist something like that within HaXe or it's not impossible?
And, well, it can, then, perfectly fit for scripting langauge which will not require a virtual machine to execute on but will just compile into target platform's code and will be as fast as possible (at least faster than under VM)?

Anywat, it fits well for my current target but it will be good if someone will use it too - I will be glad if you let me into official SVN repository and will make any improvements. I uploaded several affected "HaXe" sources to temporary project http://code.google.com/p/hxcppn/ . I am new to OCaml, so, please, refer indulgently to my code.

Thank you.
--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: C++ "native" target.

davidedc
Ah ok I see.

So would you say that your runtime is lighter than the haxecpp runtime?

What if you *don't* use any Dynamic types, is your implementation still faster?

Do you break "unreachable" memory loops in some automatic way or are those never garbage-collected?

I'm intrigued by this project! Have you got sample snippets of code that work and don't work, with the respective translated c++ code?

Cheers,
Davide

Pardon any typos, sent from my mobile.

On 1 Oct 2011, at 13:08, Slav <[hidden email]> wrote:

Thank you.
I used boost::shared_ptr for automatic memory management - did not found how to do it more "native".

Target code generation file sources: http://code.google.com/p/hxcppn/source/browse/trunk/gencppn.ml

2011/10/1 Davide Della Casa <[hidden email]>
Nice one.

Did you include garbage collection or was that left out?

Can't seem to find any reference to it browsing the code.

Cheers,
Davide

Pardon any typos, sent from my mobile.

On 1 Oct 2011, at 12:41, Slav <[hidden email]> wrote:

Hello. At first, I want to say thank you for this useful and interesting project and want to get some advices on how can I apply him on my sort of tasks.

Currently (correct me if I am wrong) HaXe is developed and used to compile full target applications (and has the “main()” function). I do not know HaXe well in this sort of tasks and found it for precise my one: generally speaking, to write limited code chunk which will be executed only as part of the whole application which is absolutely differently implemented on each platform: I intend to implemented real-time multiplayer game where game logic has to be executed both on server and client; on server (C++) for multiplayer purpose and on client (C# for now but may be AS3 if adobe will, finally, introduce UDP-sockets) for ping compensation and traffic minimization (for client-side prediction). I tried to use Lua, Ruby and Python as scripting languages but it was too slow (10 ms on client to call script’s function and pretty fast on C++ server but for intended hudreds of simultaneous clients it’s slow too), so I found the solution which is “write this game logic code on some abstract language and then (after each it’s modification) convert it into each target platform” which will just include generated files along with platform specific ones. And then I found HaXe (what, honesly, was miracle), wrote C++ generator and started to use it (it's not fully implemented yet).
There already was the C++ target generator but it emulated dynamically typed language which is perfect for general purpose realization but was a little slow for mine - for this I was had to refuse “Dynamic” types usage and some other accompanying features and it’s not fatal for my sort of tasks if to take into account that all platform-specific code is written directly in target platform’s language and HaXe sources used along with it.
Along with that home-work I intend to introduce HaXe usage in my job where we make games and rewrite them from scratch for each platform (somewhere between C++, AS3, Java, WME...) but if there could be a way to write overall game logic on HaXe and then use it just as part of target platform’s sources.
So, is it possible and match with the whole HaXe’ design to do some work in this direction - use HaXe to write just parts of a target program (for example, compile code without “main()” function and introduce some new features such as “virtual APIs” and so on), or did I missed something - maybe there already exist something like that within HaXe or it's not impossible?
And, well, it can, then, perfectly fit for scripting langauge which will not require a virtual machine to execute on but will just compile into target platform's code and will be as fast as possible (at least faster than under VM)?

Anywat, it fits well for my current target but it will be good if someone will use it too - I will be glad if you let me into official SVN repository and will make any improvements. I uploaded several affected "HaXe" sources to temporary project http://code.google.com/p/hxcppn/ . I am new to OCaml, so, please, refer indulgently to my code.

Thank you.
--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: C++ "native" target.

Cauê W.
Hey Slav!

Great initiative! But I'm a little intrigued as well... You could use hxcpp-compiled as libraries just by defining the code to be compiled as a library. There are some examples on how you'd compile to have it run as a static library - which is what is needed for example for iphone. We've developed some projects that has to use native objective-c code with hxcpp. The only thing is that you have to take care to define correct GC roots if you are holding up any pointers from haxe within your code. You have to communicate through the cffi, though. But it works fine! And as a bonus you can define NEKO_GLUE when working with the cffi and it will also generate the neko primitives from your same cffi ndll, which is kind of magical!

I also intend to work on a way to hack into cpp generated code with a post-build command that will be able to accept direct externs from hxcpp with native c/cpp code . (By now you'll have to go trough the cffi)

Anyway, if you avoid dynamics on haxe, hxcpp can be almost as fast as c++. Hugh has made some benchmarks on his website, gamehaxe.com . About boost::shared_ptr - correct me if I'm wrong, but doesn't it work with reference counting? If it does, normal haxe code might leak very badly with reference counting, as they don't detect cyclic references!

Cheers!
Cauê




2011/10/1 Davide Della Casa <[hidden email]>
Ah ok I see.

So would you say that your runtime is lighter than the haxecpp runtime?

What if you *don't* use any Dynamic types, is your implementation still faster?

Do you break "unreachable" memory loops in some automatic way or are those never garbage-collected?

I'm intrigued by this project! Have you got sample snippets of code that work and don't work, with the respective translated c++ code?

Cheers,
Davide

Pardon any typos, sent from my mobile.

On 1 Oct 2011, at 13:08, Slav <[hidden email]> wrote:

Thank you.
I used boost::shared_ptr for automatic memory management - did not found how to do it more "native".

Target code generation file sources: http://code.google.com/p/hxcppn/source/browse/trunk/gencppn.ml

2011/10/1 Davide Della Casa <[hidden email][hidden email]>
Nice one.

Did you include garbage collection or was that left out?

Can't seem to find any reference to it browsing the code.

Cheers,
Davide

Pardon any typos, sent from my mobile.

On 1 Oct 2011, at 12:41, Slav <[hidden email][hidden email]> wrote:

Hello. At first, I want to say thank you for this useful and interesting project and want to get some advices on how can I apply him on my sort of tasks.

Currently (correct me if I am wrong) HaXe is developed and used to compile full target applications (and has the “main()” function). I do not know HaXe well in this sort of tasks and found it for precise my one: generally speaking, to write limited code chunk which will be executed only as part of the whole application which is absolutely differently implemented on each platform: I intend to implemented real-time multiplayer game where game logic has to be executed both on server and client; on server (C++) for multiplayer purpose and on client (C# for now but may be AS3 if adobe will, finally, introduce UDP-sockets) for ping compensation and traffic minimization (for client-side prediction). I tried to use Lua, Ruby and Python as scripting languages but it was too slow (10 ms on client to call script’s function and pretty fast on C++ server but for intended hudreds of simultaneous clients it’s slow too), so I found the solution which is “write this game logic code on some abstract language and then (after each it’s modification) convert it into each target platform” which will just include generated files along with platform specific ones. And then I found HaXe (what, honesly, was miracle), wrote C++ generator and started to use it (it's not fully implemented yet).
There already was the C++ target generator but it emulated dynamically typed language which is perfect for general purpose realization but was a little slow for mine - for this I was had to refuse “Dynamic” types usage and some other accompanying features and it’s not fatal for my sort of tasks if to take into account that all platform-specific code is written directly in target platform’s language and HaXe sources used along with it.
Along with that home-work I intend to introduce HaXe usage in my job where we make games and rewrite them from scratch for each platform (somewhere between C++, AS3, Java, WME...) but if there could be a way to write overall game logic on HaXe and then use it just as part of target platform’s sources.
So, is it possible and match with the whole HaXe’ design to do some work in this direction - use HaXe to write just parts of a target program (for example, compile code without “main()” function and introduce some new features such as “virtual APIs” and so on), or did I missed something - maybe there already exist something like that within HaXe or it's not impossible?
And, well, it can, then, perfectly fit for scripting langauge which will not require a virtual machine to execute on but will just compile into target platform's code and will be as fast as possible (at least faster than under VM)?

Anywat, it fits well for my current target but it will be good if someone will use it too - I will be glad if you let me into official SVN repository and will make any improvements. I uploaded several affected "HaXe" sources to temporary project http://code.google.com/p/hxcppn/ . I am new to OCaml, so, please, refer indulgently to my code.

Thank you.
--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: C++ "native" target.

Slav
In reply to this post by davidedc
I just started to implement it and many things was not done yet (i.e. "String" is just "const char*" and "Array" was not touched at all because I don't even know yet how they implied within HaXe - is it std::vector-like or more std::map-like).
For my current intention (server for realtime MMO with hundreds player within single game world with 15 FPS) execution time is crucial, so it's need to write code as fast as possible instead of it's elegancy and comfor.
As I know, "haxecpp" generates classes where methods and fields are literals so that each object is dynamic which fits well into whole HaXe design (is I understood it well), so the example:


class Sum
{
    public var what:Int;
   
    public function new()
    {
        what = 5;
    }
   
    public function Do(with:Int): Int
    {
        return what + with;
    }
   
    public static function main(): Int
    {
        return 0;
    }
}


compiles into:
#include <hxcpp.h>

#ifndef INCLUDED_Sum
#include <Sum.h>
#endif

Void Sum_obj::__construct()
{
{
    HX_SOURCE_POS("Sum.hx",8)
    this->what = (int)5;
}
;
    return null();
}

Sum_obj::~Sum_obj() { }

Dynamic Sum_obj::__CreateEmpty() { return  new Sum_obj; }
hx::ObjectPtr< Sum_obj > Sum_obj::__new()
{  hx::ObjectPtr< Sum_obj > result = new Sum_obj();
    result->__construct();
    return result;}

Dynamic Sum_obj::__Create(hx::DynamicArray inArgs)
{  hx::ObjectPtr< Sum_obj > result = new Sum_obj();
    result->__construct();
    return result;}

int Sum_obj::Do( int with){
    HX_SOURCE_PUSH("Sum_obj::Do")
    HX_SOURCE_POS("Sum.hx",13)
    return (this->what + with);
}


HX_DEFINE_DYNAMIC_FUNC1(Sum_obj,Do,return )

int Sum_obj::main( ){
    HX_SOURCE_PUSH("Sum_obj::main")
    HX_SOURCE_POS("Sum.hx",18)
    return (int)0;
}


STATIC_HX_DEFINE_DYNAMIC_FUNC0(Sum_obj,main,return )


Sum_obj::Sum_obj()
{
}

void Sum_obj::__Mark(HX_MARK_PARAMS)
{
    HX_MARK_BEGIN_CLASS(Sum);
    HX_MARK_MEMBER_NAME(what,"what");
    HX_MARK_END_CLASS();
}

Dynamic Sum_obj::__Field(const ::String &inName)
{
    switch(inName.length) {
    case 2:
        if (HX_FIELD_EQ(inName,"Do") ) { return Do_dyn(); }
        break;
    case 4:
        if (HX_FIELD_EQ(inName,"main") ) { return main_dyn(); }
        if (HX_FIELD_EQ(inName,"what") ) { return what; }
    }
    return super::__Field(inName);
}

Dynamic Sum_obj::__SetField(const ::String &inName,const Dynamic &inValue)
{
    switch(inName.length) {
    case 4:
        if (HX_FIELD_EQ(inName,"what") ) { what=inValue.Cast< int >(); return inValue; }
    }
    return super::__SetField(inName,inValue);
}

void Sum_obj::__GetFields(Array< ::String> &outFields)
{
    outFields->push(HX_CSTRING("what"));
    super::__GetFields(outFields);
};

static ::String sStaticFields[] = {
    HX_CSTRING("main"),
    String(null()) };

static ::String sMemberFields[] = {
    HX_CSTRING("what"),
    HX_CSTRING("Do"),
    String(null()) };

static void sMarkStatics(HX_MARK_PARAMS) {
};

Class Sum_obj::__mClass;

void Sum_obj::__register()
{
    Static(__mClass) = hx::RegisterClass(HX_CSTRING("Sum"), hx::TCanCast< Sum_obj> ,sStaticFields,sMemberFields,
    &__CreateEmpty, &__Create,
    &super::__SGetClass(), 0, sMarkStatics);
}

void Sum_obj::__boot()
{
}



but in my way it compiles into:

Sum::Sum()
{
  this->what = 5;
}

int Sum::Do(int with)
{
  return this->what + with;
}

as so that it was written directly in C++.
Currently, I need write just very much of code where implemented physical interactions between game objects, AI and so on, so that I need just a way to translate arithmetical operations, for/while cycles and switches into both C++ and C# (or AS3).

There are much other tasks about which I did not thought yet (multithreading, interfaces (function calls from within HaXe of classes which does not exists) and so on) - anything that can permit use HaXe as embedding language for writing algorithms.


2011/10/1 Davide Della Casa <[hidden email]>
Ah ok I see.

So would you say that your runtime is lighter than the haxecpp runtime?

What if you *don't* use any Dynamic types, is your implementation still faster?

Do you break "unreachable" memory loops in some automatic way or are those never garbage-collected?

I'm intrigued by this project! Have you got sample snippets of code that work and don't work, with the respective translated c++ code?

Cheers,
Davide

Pardon any typos, sent from my mobile.

On 1 Oct 2011, at 13:08, Slav <[hidden email]> wrote:

Thank you.
I used boost::shared_ptr for automatic memory management - did not found how to do it more "native".

Target code generation file sources: http://code.google.com/p/hxcppn/source/browse/trunk/gencppn.ml

2011/10/1 Davide Della Casa <[hidden email][hidden email]>
Nice one.

Did you include garbage collection or was that left out?

Can't seem to find any reference to it browsing the code.

Cheers,
Davide

Pardon any typos, sent from my mobile.

On 1 Oct 2011, at 12:41, Slav <[hidden email][hidden email]> wrote:

Hello. At first, I want to say thank you for this useful and interesting project and want to get some advices on how can I apply him on my sort of tasks.

Currently (correct me if I am wrong) HaXe is developed and used to compile full target applications (and has the “main()” function). I do not know HaXe well in this sort of tasks and found it for precise my one: generally speaking, to write limited code chunk which will be executed only as part of the whole application which is absolutely differently implemented on each platform: I intend to implemented real-time multiplayer game where game logic has to be executed both on server and client; on server (C++) for multiplayer purpose and on client (C# for now but may be AS3 if adobe will, finally, introduce UDP-sockets) for ping compensation and traffic minimization (for client-side prediction). I tried to use Lua, Ruby and Python as scripting languages but it was too slow (10 ms on client to call script’s function and pretty fast on C++ server but for intended hudreds of simultaneous clients it’s slow too), so I found the solution which is “write this game logic code on some abstract language and then (after each it’s modification) convert it into each target platform” which will just include generated files along with platform specific ones. And then I found HaXe (what, honesly, was miracle), wrote C++ generator and started to use it (it's not fully implemented yet).
There already was the C++ target generator but it emulated dynamically typed language which is perfect for general purpose realization but was a little slow for mine - for this I was had to refuse “Dynamic” types usage and some other accompanying features and it’s not fatal for my sort of tasks if to take into account that all platform-specific code is written directly in target platform’s language and HaXe sources used along with it.
Along with that home-work I intend to introduce HaXe usage in my job where we make games and rewrite them from scratch for each platform (somewhere between C++, AS3, Java, WME...) but if there could be a way to write overall game logic on HaXe and then use it just as part of target platform’s sources.
So, is it possible and match with the whole HaXe’ design to do some work in this direction - use HaXe to write just parts of a target program (for example, compile code without “main()” function and introduce some new features such as “virtual APIs” and so on), or did I missed something - maybe there already exist something like that within HaXe or it's not impossible?
And, well, it can, then, perfectly fit for scripting langauge which will not require a virtual machine to execute on but will just compile into target platform's code and will be as fast as possible (at least faster than under VM)?

Anywat, it fits well for my current target but it will be good if someone will use it too - I will be glad if you let me into official SVN repository and will make any improvements. I uploaded several affected "HaXe" sources to temporary project http://code.google.com/p/hxcppn/ . I am new to OCaml, so, please, refer indulgently to my code.

Thank you.
--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: C++ "native" target.

Nicolas Cannasse
> As I know, "haxecpp" generates classes where methods and fields are
> literals so that each object is dynamic which fits well into whole HaXe
> design (is I understood it well), so the example:
[...]

This is not exactly true. hxcpp generates additional code that you can
_still_ use your object as Dynamic or with reflection api. But that does
not prevent you from using it directly.

For instance look at :

int Sum_obj::Do( int with){
      HX_SOURCE_PUSH("Sum_obj::Do")
      HX_SOURCE_POS("Sum.hx",13)
      return (this->what + with);
}

HX_SOURCE is just some debug informations that does not get compiled
when you're in "release" mode so in the end it's doing pretty much the
same as what you would write in "native c++" but automatically generates
also additional methods that enable Dynamic/Reflection support - which
are not used when the object is correctly typed. This scheme should not
affect the hxcpp performances when things are well-typed, and still
allows to implement+run all the haXe language features.

Could you detail what kind of actual optimization you're making in your
native code generator ?

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: C++ "native" target.

Slav
In reply to this post by Slav
@Cauê Waneck, such cycles within boost::shared_ptr user, then, will
have to resolve by himself implementing something like "destructors"
where he will must call "shared_ptr_to_something.reset()". Or there
will be some "mental" destruction function which user will have to
call each time when he thinks that object has to be removed. Or it's
need to introduce weak pointers.


2011/10/1 Slav <[hidden email]>

>
> I just started to implement it and many things was not done yet (i.e. "String" is just "const char*" and "Array" was not touched at all because I don't even know yet how they implied within HaXe - is it std::vector-like or more std::map-like).
> For my current intention (server for realtime MMO with hundreds player within single game world with 15 FPS) execution time is crucial, so it's need to write code as fast as possible instead of it's elegancy and comfor.
> As I know, "haxecpp" generates classes where methods and fields are literals so that each object is dynamic which fits well into whole HaXe design (is I understood it well), so the example:
>
>
> class Sum
> {
>     public var what:Int;
>
>     public function new()
>     {
>         what = 5;
>     }
>
>     public function Do(with:Int): Int
>     {
>         return what + with;
>     }
>
>     public static function main(): Int
>     {
>         return 0;
>     }
> }
>
>
> compiles into:
> #include <hxcpp.h>
>
> #ifndef INCLUDED_Sum
> #include <Sum.h>
> #endif
>
> Void Sum_obj::__construct()
> {
> {
>     HX_SOURCE_POS("Sum.hx",8)
>     this->what = (int)5;
> }
> ;
>     return null();
> }
>
> Sum_obj::~Sum_obj() { }
>
> Dynamic Sum_obj::__CreateEmpty() { return  new Sum_obj; }
> hx::ObjectPtr< Sum_obj > Sum_obj::__new()
> {  hx::ObjectPtr< Sum_obj > result = new Sum_obj();
>     result->__construct();
>     return result;}
>
> Dynamic Sum_obj::__Create(hx::DynamicArray inArgs)
> {  hx::ObjectPtr< Sum_obj > result = new Sum_obj();
>     result->__construct();
>     return result;}
>
> int Sum_obj::Do( int with){
>     HX_SOURCE_PUSH("Sum_obj::Do")
>     HX_SOURCE_POS("Sum.hx",13)
>     return (this->what + with);
> }
>
>
> HX_DEFINE_DYNAMIC_FUNC1(Sum_obj,Do,return )
>
> int Sum_obj::main( ){
>     HX_SOURCE_PUSH("Sum_obj::main")
>     HX_SOURCE_POS("Sum.hx",18)
>     return (int)0;
> }
>
>
> STATIC_HX_DEFINE_DYNAMIC_FUNC0(Sum_obj,main,return )
>
>
> Sum_obj::Sum_obj()
> {
> }
>
> void Sum_obj::__Mark(HX_MARK_PARAMS)
> {
>     HX_MARK_BEGIN_CLASS(Sum);
>     HX_MARK_MEMBER_NAME(what,"what");
>     HX_MARK_END_CLASS();
> }
>
> Dynamic Sum_obj::__Field(const ::String &inName)
> {
>     switch(inName.length) {
>     case 2:
>         if (HX_FIELD_EQ(inName,"Do") ) { return Do_dyn(); }
>         break;
>     case 4:
>         if (HX_FIELD_EQ(inName,"main") ) { return main_dyn(); }
>         if (HX_FIELD_EQ(inName,"what") ) { return what; }
>     }
>     return super::__Field(inName);
> }
>
> Dynamic Sum_obj::__SetField(const ::String &inName,const Dynamic &inValue)
> {
>     switch(inName.length) {
>     case 4:
>         if (HX_FIELD_EQ(inName,"what") ) { what=inValue.Cast< int >(); return inValue; }
>     }
>     return super::__SetField(inName,inValue);
> }
>
> void Sum_obj::__GetFields(Array< ::String> &outFields)
> {
>     outFields->push(HX_CSTRING("what"));
>     super::__GetFields(outFields);
> };
>
> static ::String sStaticFields[] = {
>     HX_CSTRING("main"),
>     String(null()) };
>
> static ::String sMemberFields[] = {
>     HX_CSTRING("what"),
>     HX_CSTRING("Do"),
>     String(null()) };
>
> static void sMarkStatics(HX_MARK_PARAMS) {
> };
>
> Class Sum_obj::__mClass;
>
> void Sum_obj::__register()
> {
>     Static(__mClass) = hx::RegisterClass(HX_CSTRING("Sum"), hx::TCanCast< Sum_obj> ,sStaticFields,sMemberFields,
>     &__CreateEmpty, &__Create,
>     &super::__SGetClass(), 0, sMarkStatics);
> }
>
> void Sum_obj::__boot()
> {
> }
>
>
>
> but in my way it compiles into:
>
> Sum::Sum()
> {
>   this->what = 5;
> }
>
> int Sum::Do(int with)
> {
>   return this->what + with;
> }
>
> as so that it was written directly in C++.
> Currently, I need write just very much of code where implemented physical interactions between game objects, AI and so on, so that I need just a way to translate arithmetical operations, for/while cycles and switches into both C++ and C# (or AS3).
>
> There are much other tasks about which I did not thought yet (multithreading, interfaces (function calls from within HaXe of classes which does not exists) and so on) - anything that can permit use HaXe as embedding language for writing algorithms.
>
>
> 2011/10/1 Davide Della Casa <[hidden email]>
>>
>> Ah ok I see.
>> So would you say that your runtime is lighter than the haxecpp runtime?
>> What if you *don't* use any Dynamic types, is your implementation still faster?
>>
>> Do you break "unreachable" memory loops in some automatic way or are those never garbage-collected?
>> I'm intrigued by this project! Have you got sample snippets of code that work and don't work, with the respective translated c++ code?
>> Cheers,
>> Davide
>> Pardon any typos, sent from my mobile.
>> On 1 Oct 2011, at 13:08, Slav <[hidden email]> wrote:
>>
>> Thank you.
>> I used boost::shared_ptr for automatic memory management - did not found how to do it more "native".
>>
>> Target code generation file sources: http://code.google.com/p/hxcppn/source/browse/trunk/gencppn.ml
>>
>> 2011/10/1 Davide Della Casa <[hidden email]>
>>>
>>> Nice one.
>>> Did you include garbage collection or was that left out?
>>> Can't seem to find any reference to it browsing the code.
>>> Cheers,
>>> Davide
>>>
>>> Pardon any typos, sent from my mobile.
>>> On 1 Oct 2011, at 12:41, Slav <[hidden email]> wrote:
>>>
>>> Hello. At first, I want to say thank you for this useful and interesting project and want to get some advices on how can I apply him on my sort of tasks.
>>>
>>> Currently (correct me if I am wrong) HaXe is developed and used to compile full target applications (and has the “main()” function). I do not know HaXe well in this sort of tasks and found it for precise my one: generally speaking, to write limited code chunk which will be executed only as part of the whole application which is absolutely differently implemented on each platform: I intend to implemented real-time multiplayer game where game logic has to be executed both on server and client; on server (C++) for multiplayer purpose and on client (C# for now but may be AS3 if adobe will, finally, introduce UDP-sockets) for ping compensation and traffic minimization (for client-side prediction). I tried to use Lua, Ruby and Python as scripting languages but it was too slow (10 ms on client to call script’s function and pretty fast on C++ server but for intended hudreds of simultaneous clients it’s slow too), so I found the solution which is “write this game logic code on some abstract language and then (after each it’s modification) convert it into each target platform” which will just include generated files along with platform specific ones. And then I found HaXe (what, honesly, was miracle), wrote C++ generator and started to use it (it's not fully implemented yet).
>>> There already was the C++ target generator but it emulated dynamically typed language which is perfect for general purpose realization but was a little slow for mine - for this I was had to refuse “Dynamic” types usage and some other accompanying features and it’s not fatal for my sort of tasks if to take into account that all platform-specific code is written directly in target platform’s language and HaXe sources used along with it.
>>> Along with that home-work I intend to introduce HaXe usage in my job where we make games and rewrite them from scratch for each platform (somewhere between C++, AS3, Java, WME...) but if there could be a way to write overall game logic on HaXe and then use it just as part of target platform’s sources.
>>> So, is it possible and match with the whole HaXe’ design to do some work in this direction - use HaXe to write just parts of a target program (for example, compile code without “main()” function and introduce some new features such as “virtual APIs” and so on), or did I missed something - maybe there already exist something like that within HaXe or it's not impossible?
>>> And, well, it can, then, perfectly fit for scripting langauge which will not require a virtual machine to execute on but will just compile into target platform's code and will be as fast as possible (at least faster than under VM)?
>>>
>>> Anywat, it fits well for my current target but it will be good if someone will use it too - I will be glad if you let me into official SVN repository and will make any improvements. I uploaded several affected "HaXe" sources to temporary project http://code.google.com/p/hxcppn/ . I am new to OCaml, so, please, refer indulgently to my code.
>>>
>>> Thank you.
>>>
>>> --
>>> haXe - an open source web programming language
>>> http://haxe.org
>>>
>>> --
>>> haXe - an open source web programming language
>>> http://haxe.org
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: C++ "native" target.

Slav
Well, then what I did is useless :)
But why you call "cpp" target "experimental"? Is it need to do
something for that to make it released?

2011/10/1 Slav <[hidden email]>:

> @Cauê Waneck, such cycles within boost::shared_ptr user, then, will
> have to resolve by himself implementing something like "destructors"
> where he will must call "shared_ptr_to_something.reset()". Or there
> will be some "mental" destruction function which user will have to
> call each time when he thinks that object has to be removed. Or it's
> need to introduce weak pointers.
>
>
> 2011/10/1 Slav <[hidden email]>
>>
>> I just started to implement it and many things was not done yet (i.e. "String" is just "const char*" and "Array" was not touched at all because I don't even know yet how they implied within HaXe - is it std::vector-like or more std::map-like).
>> For my current intention (server for realtime MMO with hundreds player within single game world with 15 FPS) execution time is crucial, so it's need to write code as fast as possible instead of it's elegancy and comfor.
>> As I know, "haxecpp" generates classes where methods and fields are literals so that each object is dynamic which fits well into whole HaXe design (is I understood it well), so the example:
>>
>>
>> class Sum
>> {
>>     public var what:Int;
>>
>>     public function new()
>>     {
>>         what = 5;
>>     }
>>
>>     public function Do(with:Int): Int
>>     {
>>         return what + with;
>>     }
>>
>>     public static function main(): Int
>>     {
>>         return 0;
>>     }
>> }
>>
>>
>> compiles into:
>> #include <hxcpp.h>
>>
>> #ifndef INCLUDED_Sum
>> #include <Sum.h>
>> #endif
>>
>> Void Sum_obj::__construct()
>> {
>> {
>>     HX_SOURCE_POS("Sum.hx",8)
>>     this->what = (int)5;
>> }
>> ;
>>     return null();
>> }
>>
>> Sum_obj::~Sum_obj() { }
>>
>> Dynamic Sum_obj::__CreateEmpty() { return  new Sum_obj; }
>> hx::ObjectPtr< Sum_obj > Sum_obj::__new()
>> {  hx::ObjectPtr< Sum_obj > result = new Sum_obj();
>>     result->__construct();
>>     return result;}
>>
>> Dynamic Sum_obj::__Create(hx::DynamicArray inArgs)
>> {  hx::ObjectPtr< Sum_obj > result = new Sum_obj();
>>     result->__construct();
>>     return result;}
>>
>> int Sum_obj::Do( int with){
>>     HX_SOURCE_PUSH("Sum_obj::Do")
>>     HX_SOURCE_POS("Sum.hx",13)
>>     return (this->what + with);
>> }
>>
>>
>> HX_DEFINE_DYNAMIC_FUNC1(Sum_obj,Do,return )
>>
>> int Sum_obj::main( ){
>>     HX_SOURCE_PUSH("Sum_obj::main")
>>     HX_SOURCE_POS("Sum.hx",18)
>>     return (int)0;
>> }
>>
>>
>> STATIC_HX_DEFINE_DYNAMIC_FUNC0(Sum_obj,main,return )
>>
>>
>> Sum_obj::Sum_obj()
>> {
>> }
>>
>> void Sum_obj::__Mark(HX_MARK_PARAMS)
>> {
>>     HX_MARK_BEGIN_CLASS(Sum);
>>     HX_MARK_MEMBER_NAME(what,"what");
>>     HX_MARK_END_CLASS();
>> }
>>
>> Dynamic Sum_obj::__Field(const ::String &inName)
>> {
>>     switch(inName.length) {
>>     case 2:
>>         if (HX_FIELD_EQ(inName,"Do") ) { return Do_dyn(); }
>>         break;
>>     case 4:
>>         if (HX_FIELD_EQ(inName,"main") ) { return main_dyn(); }
>>         if (HX_FIELD_EQ(inName,"what") ) { return what; }
>>     }
>>     return super::__Field(inName);
>> }
>>
>> Dynamic Sum_obj::__SetField(const ::String &inName,const Dynamic &inValue)
>> {
>>     switch(inName.length) {
>>     case 4:
>>         if (HX_FIELD_EQ(inName,"what") ) { what=inValue.Cast< int >(); return inValue; }
>>     }
>>     return super::__SetField(inName,inValue);
>> }
>>
>> void Sum_obj::__GetFields(Array< ::String> &outFields)
>> {
>>     outFields->push(HX_CSTRING("what"));
>>     super::__GetFields(outFields);
>> };
>>
>> static ::String sStaticFields[] = {
>>     HX_CSTRING("main"),
>>     String(null()) };
>>
>> static ::String sMemberFields[] = {
>>     HX_CSTRING("what"),
>>     HX_CSTRING("Do"),
>>     String(null()) };
>>
>> static void sMarkStatics(HX_MARK_PARAMS) {
>> };
>>
>> Class Sum_obj::__mClass;
>>
>> void Sum_obj::__register()
>> {
>>     Static(__mClass) = hx::RegisterClass(HX_CSTRING("Sum"), hx::TCanCast< Sum_obj> ,sStaticFields,sMemberFields,
>>     &__CreateEmpty, &__Create,
>>     &super::__SGetClass(), 0, sMarkStatics);
>> }
>>
>> void Sum_obj::__boot()
>> {
>> }
>>
>>
>>
>> but in my way it compiles into:
>>
>> Sum::Sum()
>> {
>>   this->what = 5;
>> }
>>
>> int Sum::Do(int with)
>> {
>>   return this->what + with;
>> }
>>
>> as so that it was written directly in C++.
>> Currently, I need write just very much of code where implemented physical interactions between game objects, AI and so on, so that I need just a way to translate arithmetical operations, for/while cycles and switches into both C++ and C# (or AS3).
>>
>> There are much other tasks about which I did not thought yet (multithreading, interfaces (function calls from within HaXe of classes which does not exists) and so on) - anything that can permit use HaXe as embedding language for writing algorithms.
>>
>>
>> 2011/10/1 Davide Della Casa <[hidden email]>
>>>
>>> Ah ok I see.
>>> So would you say that your runtime is lighter than the haxecpp runtime?
>>> What if you *don't* use any Dynamic types, is your implementation still faster?
>>>
>>> Do you break "unreachable" memory loops in some automatic way or are those never garbage-collected?
>>> I'm intrigued by this project! Have you got sample snippets of code that work and don't work, with the respective translated c++ code?
>>> Cheers,
>>> Davide
>>> Pardon any typos, sent from my mobile.
>>> On 1 Oct 2011, at 13:08, Slav <[hidden email]> wrote:
>>>
>>> Thank you.
>>> I used boost::shared_ptr for automatic memory management - did not found how to do it more "native".
>>>
>>> Target code generation file sources: http://code.google.com/p/hxcppn/source/browse/trunk/gencppn.ml
>>>
>>> 2011/10/1 Davide Della Casa <[hidden email]>
>>>>
>>>> Nice one.
>>>> Did you include garbage collection or was that left out?
>>>> Can't seem to find any reference to it browsing the code.
>>>> Cheers,
>>>> Davide
>>>>
>>>> Pardon any typos, sent from my mobile.
>>>> On 1 Oct 2011, at 12:41, Slav <[hidden email]> wrote:
>>>>
>>>> Hello. At first, I want to say thank you for this useful and interesting project and want to get some advices on how can I apply him on my sort of tasks.
>>>>
>>>> Currently (correct me if I am wrong) HaXe is developed and used to compile full target applications (and has the “main()” function). I do not know HaXe well in this sort of tasks and found it for precise my one: generally speaking, to write limited code chunk which will be executed only as part of the whole application which is absolutely differently implemented on each platform: I intend to implemented real-time multiplayer game where game logic has to be executed both on server and client; on server (C++) for multiplayer purpose and on client (C# for now but may be AS3 if adobe will, finally, introduce UDP-sockets) for ping compensation and traffic minimization (for client-side prediction). I tried to use Lua, Ruby and Python as scripting languages but it was too slow (10 ms on client to call script’s function and pretty fast on C++ server but for intended hudreds of simultaneous clients it’s slow too), so I found the solution which is “write this game logic code on some abstract language and then (after each it’s modification) convert it into each target platform” which will just include generated files along with platform specific ones. And then I found HaXe (what, honesly, was miracle), wrote C++ generator and started to use it (it's not fully implemented yet).
>>>> There already was the C++ target generator but it emulated dynamically typed language which is perfect for general purpose realization but was a little slow for mine - for this I was had to refuse “Dynamic” types usage and some other accompanying features and it’s not fatal for my sort of tasks if to take into account that all platform-specific code is written directly in target platform’s language and HaXe sources used along with it.
>>>> Along with that home-work I intend to introduce HaXe usage in my job where we make games and rewrite them from scratch for each platform (somewhere between C++, AS3, Java, WME...) but if there could be a way to write overall game logic on HaXe and then use it just as part of target platform’s sources.
>>>> So, is it possible and match with the whole HaXe’ design to do some work in this direction - use HaXe to write just parts of a target program (for example, compile code without “main()” function and introduce some new features such as “virtual APIs” and so on), or did I missed something - maybe there already exist something like that within HaXe or it's not impossible?
>>>> And, well, it can, then, perfectly fit for scripting langauge which will not require a virtual machine to execute on but will just compile into target platform's code and will be as fast as possible (at least faster than under VM)?
>>>>
>>>> Anywat, it fits well for my current target but it will be good if someone will use it too - I will be glad if you let me into official SVN repository and will make any improvements. I uploaded several affected "HaXe" sources to temporary project http://code.google.com/p/hxcppn/ . I am new to OCaml, so, please, refer indulgently to my code.
>>>>
>>>> Thank you.
>>>>
>>>> --
>>>> haXe - an open source web programming language
>>>> http://haxe.org
>>>>
>>>> --
>>>> haXe - an open source web programming language
>>>> http://haxe.org
>>>
>>> --
>>> haXe - an open source web programming language
>>> http://haxe.org
>>>
>>> --
>>> haXe - an open source web programming language
>>> http://haxe.org
>>
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: C++ "native" target.

davidedc
Hey Slav,

I think that if your implementation is simpler then the current hxcpp implementation, then this is very valuable for me for learning something about c++ code generation. I would not adventure into robust complex code that handles all edge cases, but I will adventure in yours if it's simpler.

So thanks for that, I think it's useful.

Cheers,
Davide

Pardon any typos, sent from my mobile.

On 1 Oct 2011, at 16:32, Slav <[hidden email]> wrote:

> Well, then what I did is useless :)
> But why you call "cpp" target "experimental"? Is it need to do
> something for that to make it released?
>
> 2011/10/1 Slav <[hidden email]>:
>> @Cauê Waneck, such cycles within boost::shared_ptr user, then, will
>> have to resolve by himself implementing something like "destructors"
>> where he will must call "shared_ptr_to_something.reset()". Or there
>> will be some "mental" destruction function which user will have to
>> call each time when he thinks that object has to be removed. Or it's
>> need to introduce weak pointers.
>>
>>
>> 2011/10/1 Slav <[hidden email]>
>>>
>>> I just started to implement it and many things was not done yet (i.e. "String" is just "const char*" and "Array" was not touched at all because I don't even know yet how they implied within HaXe - is it std::vector-like or more std::map-like).
>>> For my current intention (server for realtime MMO with hundreds player within single game world with 15 FPS) execution time is crucial, so it's need to write code as fast as possible instead of it's elegancy and comfor.
>>> As I know, "haxecpp" generates classes where methods and fields are literals so that each object is dynamic which fits well into whole HaXe design (is I understood it well), so the example:
>>>
>>>
>>> class Sum
>>> {
>>>     public var what:Int;
>>>
>>>     public function new()
>>>     {
>>>         what = 5;
>>>     }
>>>
>>>     public function Do(with:Int): Int
>>>     {
>>>         return what + with;
>>>     }
>>>
>>>     public static function main(): Int
>>>     {
>>>         return 0;
>>>     }
>>> }
>>>
>>>
>>> compiles into:
>>> #include <hxcpp.h>
>>>
>>> #ifndef INCLUDED_Sum
>>> #include <Sum.h>
>>> #endif
>>>
>>> Void Sum_obj::__construct()
>>> {
>>> {
>>>     HX_SOURCE_POS("Sum.hx",8)
>>>     this->what = (int)5;
>>> }
>>> ;
>>>     return null();
>>> }
>>>
>>> Sum_obj::~Sum_obj() { }
>>>
>>> Dynamic Sum_obj::__CreateEmpty() { return  new Sum_obj; }
>>> hx::ObjectPtr< Sum_obj > Sum_obj::__new()
>>> {  hx::ObjectPtr< Sum_obj > result = new Sum_obj();
>>>     result->__construct();
>>>     return result;}
>>>
>>> Dynamic Sum_obj::__Create(hx::DynamicArray inArgs)
>>> {  hx::ObjectPtr< Sum_obj > result = new Sum_obj();
>>>     result->__construct();
>>>     return result;}
>>>
>>> int Sum_obj::Do( int with){
>>>     HX_SOURCE_PUSH("Sum_obj::Do")
>>>     HX_SOURCE_POS("Sum.hx",13)
>>>     return (this->what + with);
>>> }
>>>
>>>
>>> HX_DEFINE_DYNAMIC_FUNC1(Sum_obj,Do,return )
>>>
>>> int Sum_obj::main( ){
>>>     HX_SOURCE_PUSH("Sum_obj::main")
>>>     HX_SOURCE_POS("Sum.hx",18)
>>>     return (int)0;
>>> }
>>>
>>>
>>> STATIC_HX_DEFINE_DYNAMIC_FUNC0(Sum_obj,main,return )
>>>
>>>
>>> Sum_obj::Sum_obj()
>>> {
>>> }
>>>
>>> void Sum_obj::__Mark(HX_MARK_PARAMS)
>>> {
>>>     HX_MARK_BEGIN_CLASS(Sum);
>>>     HX_MARK_MEMBER_NAME(what,"what");
>>>     HX_MARK_END_CLASS();
>>> }
>>>
>>> Dynamic Sum_obj::__Field(const ::String &inName)
>>> {
>>>     switch(inName.length) {
>>>     case 2:
>>>         if (HX_FIELD_EQ(inName,"Do") ) { return Do_dyn(); }
>>>         break;
>>>     case 4:
>>>         if (HX_FIELD_EQ(inName,"main") ) { return main_dyn(); }
>>>         if (HX_FIELD_EQ(inName,"what") ) { return what; }
>>>     }
>>>     return super::__Field(inName);
>>> }
>>>
>>> Dynamic Sum_obj::__SetField(const ::String &inName,const Dynamic &inValue)
>>> {
>>>     switch(inName.length) {
>>>     case 4:
>>>         if (HX_FIELD_EQ(inName,"what") ) { what=inValue.Cast< int >(); return inValue; }
>>>     }
>>>     return super::__SetField(inName,inValue);
>>> }
>>>
>>> void Sum_obj::__GetFields(Array< ::String> &outFields)
>>> {
>>>     outFields->push(HX_CSTRING("what"));
>>>     super::__GetFields(outFields);
>>> };
>>>
>>> static ::String sStaticFields[] = {
>>>     HX_CSTRING("main"),
>>>     String(null()) };
>>>
>>> static ::String sMemberFields[] = {
>>>     HX_CSTRING("what"),
>>>     HX_CSTRING("Do"),
>>>     String(null()) };
>>>
>>> static void sMarkStatics(HX_MARK_PARAMS) {
>>> };
>>>
>>> Class Sum_obj::__mClass;
>>>
>>> void Sum_obj::__register()
>>> {
>>>     Static(__mClass) = hx::RegisterClass(HX_CSTRING("Sum"), hx::TCanCast< Sum_obj> ,sStaticFields,sMemberFields,
>>>     &__CreateEmpty, &__Create,
>>>     &super::__SGetClass(), 0, sMarkStatics);
>>> }
>>>
>>> void Sum_obj::__boot()
>>> {
>>> }
>>>
>>>
>>>
>>> but in my way it compiles into:
>>>
>>> Sum::Sum()
>>> {
>>>   this->what = 5;
>>> }
>>>
>>> int Sum::Do(int with)
>>> {
>>>   return this->what + with;
>>> }
>>>
>>> as so that it was written directly in C++.
>>> Currently, I need write just very much of code where implemented physical interactions between game objects, AI and so on, so that I need just a way to translate arithmetical operations, for/while cycles and switches into both C++ and C# (or AS3).
>>>
>>> There are much other tasks about which I did not thought yet (multithreading, interfaces (function calls from within HaXe of classes which does not exists) and so on) - anything that can permit use HaXe as embedding language for writing algorithms.
>>>
>>>
>>> 2011/10/1 Davide Della Casa <[hidden email]>
>>>>
>>>> Ah ok I see.
>>>> So would you say that your runtime is lighter than the haxecpp runtime?
>>>> What if you *don't* use any Dynamic types, is your implementation still faster?
>>>>
>>>> Do you break "unreachable" memory loops in some automatic way or are those never garbage-collected?
>>>> I'm intrigued by this project! Have you got sample snippets of code that work and don't work, with the respective translated c++ code?
>>>> Cheers,
>>>> Davide
>>>> Pardon any typos, sent from my mobile.
>>>> On 1 Oct 2011, at 13:08, Slav <[hidden email]> wrote:
>>>>
>>>> Thank you.
>>>> I used boost::shared_ptr for automatic memory management - did not found how to do it more "native".
>>>>
>>>> Target code generation file sources: http://code.google.com/p/hxcppn/source/browse/trunk/gencppn.ml
>>>>
>>>> 2011/10/1 Davide Della Casa <[hidden email]>
>>>>>
>>>>> Nice one.
>>>>> Did you include garbage collection or was that left out?
>>>>> Can't seem to find any reference to it browsing the code.
>>>>> Cheers,
>>>>> Davide
>>>>>
>>>>> Pardon any typos, sent from my mobile.
>>>>> On 1 Oct 2011, at 12:41, Slav <[hidden email]> wrote:
>>>>>
>>>>> Hello. At first, I want to say thank you for this useful and interesting project and want to get some advices on how can I apply him on my sort of tasks.
>>>>>
>>>>> Currently (correct me if I am wrong) HaXe is developed and used to compile full target applications (and has the “main()” function). I do not know HaXe well in this sort of tasks and found it for precise my one: generally speaking, to write limited code chunk which will be executed only as part of the whole application which is absolutely differently implemented on each platform: I intend to implemented real-time multiplayer game where game logic has to be executed both on server and client; on server (C++) for multiplayer purpose and on client (C# for now but may be AS3 if adobe will, finally, introduce UDP-sockets) for ping compensation and traffic minimization (for client-side prediction). I tried to use Lua, Ruby and Python as scripting languages but it was too slow (10 ms on client to call script’s function and pretty fast on C++ server but for intended hudreds of simultaneous clients it’s slow too), so I found the solution which is “write this game logic code on some abstract language and then (after each it’s modification) convert it into each target platform” which will just include generated files along with platform specific ones. And then I found HaXe (what, honesly, was miracle), wrote C++ generator and started to use it (it's not fully implemented yet).
>>>>> There already was the C++ target generator but it emulated dynamically typed language which is perfect for general purpose realization but was a little slow for mine - for this I was had to refuse “Dynamic” types usage and some other accompanying features and it’s not fatal for my sort of tasks if to take into account that all platform-specific code is written directly in target platform’s language and HaXe sources used along with it.
>>>>> Along with that home-work I intend to introduce HaXe usage in my job where we make games and rewrite them from scratch for each platform (somewhere between C++, AS3, Java, WME...) but if there could be a way to write overall game logic on HaXe and then use it just as part of target platform’s sources.
>>>>> So, is it possible and match with the whole HaXe’ design to do some work in this direction - use HaXe to write just parts of a target program (for example, compile code without “main()” function and introduce some new features such as “virtual APIs” and so on), or did I missed something - maybe there already exist something like that within HaXe or it's not impossible?
>>>>> And, well, it can, then, perfectly fit for scripting langauge which will not require a virtual machine to execute on but will just compile into target platform's code and will be as fast as possible (at least faster than under VM)?
>>>>>
>>>>> Anywat, it fits well for my current target but it will be good if someone will use it too - I will be glad if you let me into official SVN repository and will make any improvements. I uploaded several affected "HaXe" sources to temporary project http://code.google.com/p/hxcppn/ . I am new to OCaml, so, please, refer indulgently to my code.
>>>>>
>>>>> Thank you.
>>>>>
>>>>> --
>>>>> haXe - an open source web programming language
>>>>> http://haxe.org
>>>>>
>>>>> --
>>>>> haXe - an open source web programming language
>>>>> http://haxe.org
>>>>
>>>> --
>>>> haXe - an open source web programming language
>>>> http://haxe.org
>>>>
>>>> --
>>>> haXe - an open source web programming language
>>>> http://haxe.org
>>>
>>
>
> --
> haXe - an open source web programming language
> http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: C++ "native" target.

Slav
Anyway, it was enjoyable to do. Scripting languages and compilers are
always interesting theme for me.
What about C# target? It's written on http://haxe.org that it will be
soon. Sorry for annoying question but how soon? Is there a way to get
developing sources or help somehow to develop it?

2011/10/1 Davide Della Casa <[hidden email]>:

> Hey Slav,
>
> I think that if your implementation is simpler then the current hxcpp implementation, then this is very valuable for me for learning something about c++ code generation. I would not adventure into robust complex code that handles all edge cases, but I will adventure in yours if it's simpler.
>
> So thanks for that, I think it's useful.
>
> Cheers,
> Davide
>
> Pardon any typos, sent from my mobile.
>
> On 1 Oct 2011, at 16:32, Slav <[hidden email]> wrote:
>
>> Well, then what I did is useless :)
>> But why you call "cpp" target "experimental"? Is it need to do
>> something for that to make it released?
>>
>> 2011/10/1 Slav <[hidden email]>:
>>> @Cauê Waneck, such cycles within boost::shared_ptr user, then, will
>>> have to resolve by himself implementing something like "destructors"
>>> where he will must call "shared_ptr_to_something.reset()". Or there
>>> will be some "mental" destruction function which user will have to
>>> call each time when he thinks that object has to be removed. Or it's
>>> need to introduce weak pointers.
>>>
>>>
>>> 2011/10/1 Slav <[hidden email]>
>>>>
>>>> I just started to implement it and many things was not done yet (i.e. "String" is just "const char*" and "Array" was not touched at all because I don't even know yet how they implied within HaXe - is it std::vector-like or more std::map-like).
>>>> For my current intention (server for realtime MMO with hundreds player within single game world with 15 FPS) execution time is crucial, so it's need to write code as fast as possible instead of it's elegancy and comfor.
>>>> As I know, "haxecpp" generates classes where methods and fields are literals so that each object is dynamic which fits well into whole HaXe design (is I understood it well), so the example:
>>>>
>>>>
>>>> class Sum
>>>> {
>>>>     public var what:Int;
>>>>
>>>>     public function new()
>>>>     {
>>>>         what = 5;
>>>>     }
>>>>
>>>>     public function Do(with:Int): Int
>>>>     {
>>>>         return what + with;
>>>>     }
>>>>
>>>>     public static function main(): Int
>>>>     {
>>>>         return 0;
>>>>     }
>>>> }
>>>>
>>>>
>>>> compiles into:
>>>> #include <hxcpp.h>
>>>>
>>>> #ifndef INCLUDED_Sum
>>>> #include <Sum.h>
>>>> #endif
>>>>
>>>> Void Sum_obj::__construct()
>>>> {
>>>> {
>>>>     HX_SOURCE_POS("Sum.hx",8)
>>>>     this->what = (int)5;
>>>> }
>>>> ;
>>>>     return null();
>>>> }
>>>>
>>>> Sum_obj::~Sum_obj() { }
>>>>
>>>> Dynamic Sum_obj::__CreateEmpty() { return  new Sum_obj; }
>>>> hx::ObjectPtr< Sum_obj > Sum_obj::__new()
>>>> {  hx::ObjectPtr< Sum_obj > result = new Sum_obj();
>>>>     result->__construct();
>>>>     return result;}
>>>>
>>>> Dynamic Sum_obj::__Create(hx::DynamicArray inArgs)
>>>> {  hx::ObjectPtr< Sum_obj > result = new Sum_obj();
>>>>     result->__construct();
>>>>     return result;}
>>>>
>>>> int Sum_obj::Do( int with){
>>>>     HX_SOURCE_PUSH("Sum_obj::Do")
>>>>     HX_SOURCE_POS("Sum.hx",13)
>>>>     return (this->what + with);
>>>> }
>>>>
>>>>
>>>> HX_DEFINE_DYNAMIC_FUNC1(Sum_obj,Do,return )
>>>>
>>>> int Sum_obj::main( ){
>>>>     HX_SOURCE_PUSH("Sum_obj::main")
>>>>     HX_SOURCE_POS("Sum.hx",18)
>>>>     return (int)0;
>>>> }
>>>>
>>>>
>>>> STATIC_HX_DEFINE_DYNAMIC_FUNC0(Sum_obj,main,return )
>>>>
>>>>
>>>> Sum_obj::Sum_obj()
>>>> {
>>>> }
>>>>
>>>> void Sum_obj::__Mark(HX_MARK_PARAMS)
>>>> {
>>>>     HX_MARK_BEGIN_CLASS(Sum);
>>>>     HX_MARK_MEMBER_NAME(what,"what");
>>>>     HX_MARK_END_CLASS();
>>>> }
>>>>
>>>> Dynamic Sum_obj::__Field(const ::String &inName)
>>>> {
>>>>     switch(inName.length) {
>>>>     case 2:
>>>>         if (HX_FIELD_EQ(inName,"Do") ) { return Do_dyn(); }
>>>>         break;
>>>>     case 4:
>>>>         if (HX_FIELD_EQ(inName,"main") ) { return main_dyn(); }
>>>>         if (HX_FIELD_EQ(inName,"what") ) { return what; }
>>>>     }
>>>>     return super::__Field(inName);
>>>> }
>>>>
>>>> Dynamic Sum_obj::__SetField(const ::String &inName,const Dynamic &inValue)
>>>> {
>>>>     switch(inName.length) {
>>>>     case 4:
>>>>         if (HX_FIELD_EQ(inName,"what") ) { what=inValue.Cast< int >(); return inValue; }
>>>>     }
>>>>     return super::__SetField(inName,inValue);
>>>> }
>>>>
>>>> void Sum_obj::__GetFields(Array< ::String> &outFields)
>>>> {
>>>>     outFields->push(HX_CSTRING("what"));
>>>>     super::__GetFields(outFields);
>>>> };
>>>>
>>>> static ::String sStaticFields[] = {
>>>>     HX_CSTRING("main"),
>>>>     String(null()) };
>>>>
>>>> static ::String sMemberFields[] = {
>>>>     HX_CSTRING("what"),
>>>>     HX_CSTRING("Do"),
>>>>     String(null()) };
>>>>
>>>> static void sMarkStatics(HX_MARK_PARAMS) {
>>>> };
>>>>
>>>> Class Sum_obj::__mClass;
>>>>
>>>> void Sum_obj::__register()
>>>> {
>>>>     Static(__mClass) = hx::RegisterClass(HX_CSTRING("Sum"), hx::TCanCast< Sum_obj> ,sStaticFields,sMemberFields,
>>>>     &__CreateEmpty, &__Create,
>>>>     &super::__SGetClass(), 0, sMarkStatics);
>>>> }
>>>>
>>>> void Sum_obj::__boot()
>>>> {
>>>> }
>>>>
>>>>
>>>>
>>>> but in my way it compiles into:
>>>>
>>>> Sum::Sum()
>>>> {
>>>>   this->what = 5;
>>>> }
>>>>
>>>> int Sum::Do(int with)
>>>> {
>>>>   return this->what + with;
>>>> }
>>>>
>>>> as so that it was written directly in C++.
>>>> Currently, I need write just very much of code where implemented physical interactions between game objects, AI and so on, so that I need just a way to translate arithmetical operations, for/while cycles and switches into both C++ and C# (or AS3).
>>>>
>>>> There are much other tasks about which I did not thought yet (multithreading, interfaces (function calls from within HaXe of classes which does not exists) and so on) - anything that can permit use HaXe as embedding language for writing algorithms.
>>>>
>>>>
>>>> 2011/10/1 Davide Della Casa <[hidden email]>
>>>>>
>>>>> Ah ok I see.
>>>>> So would you say that your runtime is lighter than the haxecpp runtime?
>>>>> What if you *don't* use any Dynamic types, is your implementation still faster?
>>>>>
>>>>> Do you break "unreachable" memory loops in some automatic way or are those never garbage-collected?
>>>>> I'm intrigued by this project! Have you got sample snippets of code that work and don't work, with the respective translated c++ code?
>>>>> Cheers,
>>>>> Davide
>>>>> Pardon any typos, sent from my mobile.
>>>>> On 1 Oct 2011, at 13:08, Slav <[hidden email]> wrote:
>>>>>
>>>>> Thank you.
>>>>> I used boost::shared_ptr for automatic memory management - did not found how to do it more "native".
>>>>>
>>>>> Target code generation file sources: http://code.google.com/p/hxcppn/source/browse/trunk/gencppn.ml
>>>>>
>>>>> 2011/10/1 Davide Della Casa <[hidden email]>
>>>>>>
>>>>>> Nice one.
>>>>>> Did you include garbage collection or was that left out?
>>>>>> Can't seem to find any reference to it browsing the code.
>>>>>> Cheers,
>>>>>> Davide
>>>>>>
>>>>>> Pardon any typos, sent from my mobile.
>>>>>> On 1 Oct 2011, at 12:41, Slav <[hidden email]> wrote:
>>>>>>
>>>>>> Hello. At first, I want to say thank you for this useful and interesting project and want to get some advices on how can I apply him on my sort of tasks.
>>>>>>
>>>>>> Currently (correct me if I am wrong) HaXe is developed and used to compile full target applications (and has the “main()” function). I do not know HaXe well in this sort of tasks and found it for precise my one: generally speaking, to write limited code chunk which will be executed only as part of the whole application which is absolutely differently implemented on each platform: I intend to implemented real-time multiplayer game where game logic has to be executed both on server and client; on server (C++) for multiplayer purpose and on client (C# for now but may be AS3 if adobe will, finally, introduce UDP-sockets) for ping compensation and traffic minimization (for client-side prediction). I tried to use Lua, Ruby and Python as scripting languages but it was too slow (10 ms on client to call script’s function and pretty fast on C++ server but for intended hudreds of simultaneous clients it’s slow too), so I found the solution which is “write this game logic code on some abstract language and then (after each it’s modification) convert it into each target platform” which will just include generated files along with platform specific ones. And then I found HaXe (what, honesly, was miracle), wrote C++ generator and started to use it (it's not fully implemented yet).
>>>>>> There already was the C++ target generator but it emulated dynamically typed language which is perfect for general purpose realization but was a little slow for mine - for this I was had to refuse “Dynamic” types usage and some other accompanying features and it’s not fatal for my sort of tasks if to take into account that all platform-specific code is written directly in target platform’s language and HaXe sources used along with it.
>>>>>> Along with that home-work I intend to introduce HaXe usage in my job where we make games and rewrite them from scratch for each platform (somewhere between C++, AS3, Java, WME...) but if there could be a way to write overall game logic on HaXe and then use it just as part of target platform’s sources.
>>>>>> So, is it possible and match with the whole HaXe’ design to do some work in this direction - use HaXe to write just parts of a target program (for example, compile code without “main()” function and introduce some new features such as “virtual APIs” and so on), or did I missed something - maybe there already exist something like that within HaXe or it's not impossible?
>>>>>> And, well, it can, then, perfectly fit for scripting langauge which will not require a virtual machine to execute on but will just compile into target platform's code and will be as fast as possible (at least faster than under VM)?
>>>>>>
>>>>>> Anywat, it fits well for my current target but it will be good if someone will use it too - I will be glad if you let me into official SVN repository and will make any improvements. I uploaded several affected "HaXe" sources to temporary project http://code.google.com/p/hxcppn/ . I am new to OCaml, so, please, refer indulgently to my code.
>>>>>>
>>>>>> Thank you.
>>>>>>
>>>>>> --
>>>>>> haXe - an open source web programming language
>>>>>> http://haxe.org
>>>>>>
>>>>>> --
>>>>>> haXe - an open source web programming language
>>>>>> http://haxe.org
>>>>>
>>>>> --
>>>>> haXe - an open source web programming language
>>>>> http://haxe.org
>>>>>
>>>>> --
>>>>> haXe - an open source web programming language
>>>>> http://haxe.org
>>>>
>>>
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org