Skip to content
brett hartshorn edited this page Jan 18, 2015 · 2 revisions

Many requests have come in for a Haxe backend for Rusthon. Here is why that is not going to happen. Head over to haxe.org and you will not find many or any examples of the code generated by Haxe, why? because Haxe generates an unreadable mess, that is simply not practical to use in the real world where you need to merge your translated code with handwritten code. Other programmers are going to be working in the backend target language, and will need to read the code you are merging, and may need to subclass from classes you have defined. In short, using Haxe at your day job is going to be a very hard sell to your boss who wants clean and readable code in the target language.

Rusthon vs Haxe

Below is an example of the difference between the C++ output of Rusthon and Haxe. A class in Rusthon maps directly to a C++ class, the input is 3 lines long, and the output is 7 lines of C++.

Rusthon Input

class HelloWorld:
	def mymethod(self):
		print("hello world")

Rusthon C++ Output

note the Rusthon helper functions (not used here) are not included below, they total about 100 lines of extra C++ code.

class HelloWorld {
  public:
	void mymethod();
};
void HelloWorld::mymethod() {
	std::cout << std::string("hello world") << std::endl;
}

Haxe Input

The same class in Haxe is 5 lines long, and expands to 104 lines of C++.

class HelloWorld {
  static public function main():Void {
    trace("Hello World");
  }
}

Haxe C++ Output

Haxe generates 15 different files, build files, includes and C++ source files, in total 24kB. Only HelloWorld.cpp is shown below.

#include <hxcpp.h>

#ifndef INCLUDED_HelloWorld
#include <HelloWorld.h>
#endif
#ifndef INCLUDED_haxe_Log
#include <haxe/Log.h>
#endif

Void HelloWorld_obj::__construct()
{
	return null();
}

//HelloWorld_obj::~HelloWorld_obj() { }

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

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

Void HelloWorld_obj::main( ){
{
		HX_STACK_FRAME("HelloWorld","main",0x5383b167,"HelloWorld.main","HelloWorld.hx",3,0x00bb8cbe)
		HX_STACK_LINE(3)
		::haxe::Log_obj::trace(HX_CSTRING("Hello World"),hx::SourceInfo(HX_CSTRING("HelloWorld.hx"),3,HX_CSTRING("HelloWorld"),HX_CSTRING("main")));
	}
return null();
}


STATIC_HX_DEFINE_DYNAMIC_FUNC0(HelloWorld_obj,main,(void))


HelloWorld_obj::HelloWorld_obj()
{
}

Dynamic HelloWorld_obj::__Field(const ::String &inName,bool inCallProp)
{
	switch(inName.length) {
	case 4:
		if (HX_FIELD_EQ(inName,"main") ) { return main_dyn(); }
	}
	return super::__Field(inName,inCallProp);
}

Dynamic HelloWorld_obj::__SetField(const ::String &inName,const Dynamic &inValue,bool inCallProp)
{
	return super::__SetField(inName,inValue,inCallProp);
}

void HelloWorld_obj::__GetFields(Array< ::String> &outFields)
{
	super::__GetFields(outFields);
};

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

#if HXCPP_SCRIPTABLE
static hx::StorageInfo *sMemberStorageInfo = 0;
#endif

static ::String sMemberFields[] = {
	String(null()) };

static void sMarkStatics(HX_MARK_PARAMS) {
	HX_MARK_MEMBER_NAME(HelloWorld_obj::__mClass,"__mClass");
};

#ifdef HXCPP_VISIT_ALLOCS
static void sVisitStatics(HX_VISIT_PARAMS) {
	HX_VISIT_MEMBER_NAME(HelloWorld_obj::__mClass,"__mClass");
};

#endif

Class HelloWorld_obj::__mClass;

void HelloWorld_obj::__register()
{
	hx::Static(__mClass) = hx::RegisterClass(HX_CSTRING("HelloWorld"), hx::TCanCast< HelloWorld_obj> ,sStaticFields,sMemberFields,
	&__CreateEmpty, &__Create,
	&super::__SGetClass(), 0, sMarkStatics
#ifdef HXCPP_VISIT_ALLOCS
    , sVisitStatics
#endif
#ifdef HXCPP_SCRIPTABLE
    , sMemberStorageInfo
#endif
);
}

void HelloWorld_obj::__boot()
{
}

Sidebar

Clone this wiki locally