2
0
Эх сурвалжийг харах

[cpp] Change format outputput class list. Add some classes to help boot cppia code.

hughsando 10 жил өмнө
parent
commit
c859c9f89a

+ 17 - 7
gencpp.ml

@@ -3960,6 +3960,8 @@ let generate_class_files common_ctx member_types super_deps constructor_deps cla
       output_cpp ("#ifdef HXCPP_SCRIPTABLE\n\t__mClass->mMemberStorageInfo = sMemberStorageInfo;\n#endif\n");
       output_cpp ("#ifdef HXCPP_SCRIPTABLE\n\t__mClass->mStaticStorageInfo = sStaticStorageInfo;\n#endif\n");
       output_cpp ("\thx::RegisterClass(__mClass->mName, __mClass);\n");
+      if (scriptable) then
+         output_cpp ("  HX_SCRIPTABLE_REGISTER_CLASS(\""^class_name_text^"\"," ^ class_name ^ ");\n");
       output_cpp ("}\n\n");
 
    end else begin
@@ -5427,15 +5429,23 @@ let generate_source common_ctx =
 
    write_resources common_ctx;
 
-   (* Output class list if requested *)
+   (* Output class info if requested *)
    if (scriptable || (Common.defined common_ctx Define.DllExport) ) then begin
-      let filename = match Common.defined_value_safe common_ctx Define.DllExport with
-         | "" -> "exe.classes"
-         | x -> x
+      let filename =
+         try Common.defined_value common_ctx Define.DllExport
+         with Not_found -> "export_classes.info"
       in
-      let exeClasses = open_out filename in
-      List.iter (fun x -> output_string exeClasses ((join_class_path (fst x) ".") ^ "\n") ) !exe_classes;
-      close_out exeClasses;
+      if (filename <> "") then begin
+         let exeClasses = open_out filename in
+         List.iter (fun x -> output_string exeClasses ((join_class_path (fst x) ".") ^ "\n") ) !exe_classes;
+
+         (* Output file info top *)
+         List.iter ( fun file ->
+               let full_path = Common.get_full_path (try Common.find_file common_ctx file with Not_found -> file) in
+               output_string exeClasses (file^"|"^full_path^"\n") )
+            ( List.sort String.compare ( pmap_keys !file_info) );
+         close_out exeClasses;
+     end;
    end;
 
    let output_name = match  common_ctx.main_class with

+ 28 - 0
std/cpp/cppia/Host.hx

@@ -0,0 +1,28 @@
+package cpp.cppia;
+
+
+@:build(cpp.cppia.HostClasses.include())
+class Host
+{
+   public static function run(source:String)
+   {
+      untyped __global__.__scriptable_load_cppia(source);
+   }
+
+   public static function main()
+   {
+      var script = Sys.args()[0];
+      #if !scriptable
+      #error "Please define scriptable to use cppia"
+      #end
+      if (script==null)
+      {
+         Sys.println("Usage : Cppia scriptname");
+      }
+      else
+      {
+         var source = sys.io.File.getContent(script);
+         run(source);
+      }
+   }
+}

+ 200 - 0
std/cpp/cppia/HostClasses.hx

@@ -0,0 +1,200 @@
+package cpp.cppia;
+
+import haxe.macro.Compiler;
+import haxe.macro.Context;
+import haxe.macro.Type;
+
+#if (!cppia)
+import Sys;
+#end
+
+#if !macro
+  #if cppia
+  @:build(cpp.cppia.HostClasses.exclude())
+  #end
+class HostClasses { }
+#else
+
+@:noPackageRestrict
+class HostClasses
+{
+   static var classes = [
+   "cpp.Lib",
+   "cpp.NativeArray",
+   "cpp.NativeString",
+   "cpp.vm.Debugger",
+   "cpp.vm.Deque",
+   "cpp.vm.ExecutionTrace",
+   "cpp.vm.Gc",
+   "cpp.vm.Lock",
+   "cpp.vm.Mutex",
+   "cpp.vm.Profiler",
+   "cpp.vm.Thread",
+   "cpp.vm.Tls",
+   "cpp.vm.Unsafe",
+   "cpp.vm.WeakRef",
+   "cpp.Object",
+   "cpp.Int64",
+   "Std",
+   "StringBuf",
+   "sys.db.Mysql",
+   "sys.db.Sqlite",
+   "sys.db.Object",
+   "sys.db.Manager",
+   "sys.FileSystem",
+   "sys.io.File",
+   "sys.io.FileInput",
+   "sys.net.Socket",
+   "Enum",
+   "EnumValue",
+   //"Sys",
+   "Type",
+   "Xml",
+   "Date",
+   "DateTools",
+   "List",
+   "Math",
+   "Reflect",
+   "StringBuf",
+   "StringTools",
+
+   "haxe.ds.IntMap",
+   "haxe.ds.ObjectMap",
+   "haxe.ds.StringMap",
+   "haxe.CallStack",
+   "haxe.Serializer",
+   "haxe.Unserializer",
+   "haxe.Resource",
+   "haxe.Template",
+   "haxe.Utf8",
+   "haxe.Log",
+   "haxe.zip.Uncompress",
+
+   "haxe.crypto.BaseCode",
+   "haxe.crypto.Sha256",
+   "haxe.crypto.Hmac",
+   "haxe.crypto.Crc32",
+   "haxe.crypto.Base64",
+   "haxe.crypto.Adler32",
+   "haxe.crypto.Md5",
+   "haxe.crypto.Sha1",
+ 
+   "haxe.io.BufferInput",
+   "haxe.io.Bytes",
+   "haxe.io.BytesBuffer",
+   "haxe.io.BytesData",
+   "haxe.io.BytesInput",
+   "haxe.io.BytesOutput",
+   "haxe.io.Eof",
+   "haxe.io.Error",
+   "haxe.io.FPHelper",
+   "haxe.io.Input",
+   "haxe.io.Output",
+   "haxe.io.Path",
+   "haxe.io.StringInput",
+   "haxe.xml.Parser",
+   "haxe.Json",
+
+   "haxe.CallStack",
+   "haxe.Resource",
+   "haxe.Utf8",
+   "haxe.Int64",
+   "haxe.Serializer",
+   "haxe.Unserializer",
+
+
+   "haxe.ds.ArraySort",
+   "haxe.ds.GenericStack",
+   "haxe.ds.ObjectMap",
+   "haxe.ds.Vector",
+   "haxe.ds.BalancedTree",
+   "haxe.ds.HashMap",
+   "haxe.ds.Option",
+   "haxe.ds.WeakMap",
+   "haxe.ds.EnumValueMap",
+   "haxe.ds.IntMap",
+   "haxe.ds.StringMap",
+
+   "StdTypes",
+   "Array",
+   "Class",
+   "Date",
+   "EReg",
+   "Enum",
+   "EnumValue",
+   "IntIterator",
+   "List",
+   "Map",
+   "String",
+
+
+   ];
+
+
+   static function onGenerateCppia(types:Array<Type>):Void
+   {
+      var externs = new Map<String,Bool>();
+      externs.set("Sys",true);
+      for(e in classes)
+         externs.set(e,true);
+      for(path in Context.getClassPath())
+      {
+         var filename = path + "/export_classes.info";
+         if (sys.FileSystem.exists(filename))
+         {
+            try
+            {
+               var contents = sys.io.File.getContent(filename);
+               contents = contents.split("\r").join("");
+               for(cls in contents.split("\n"))
+               {
+                  if (cls!="")
+                  {
+                     var parts = cls.split("|");
+                     if (parts.length==1)
+                        externs.set(cls,true);
+                  }
+               }
+            } catch( e : Dynamic ) { }
+         }
+      }
+      for(type in types)
+      {
+         switch(type)
+         {
+            case TInst(classRef, params):
+               if (externs.exists(classRef.toString()))
+                    classRef.get().exclude();
+            case TEnum(enumRef, params):
+               if (externs.exists(enumRef.toString()))
+                    enumRef.get().exclude();
+            default:
+         }
+      }
+   }
+
+   // Exclude the standard classes, and any described in 'export_classes.info' files found in the classpath
+   public static function exclude()
+   {
+      if (Context.defined("cppia"))
+         Context.onGenerate(onGenerateCppia);
+      else
+         Context.error("cpp.cppia.excludeHostFiles is only for cppia code", Context.currentPos());
+      return Context.getBuildFields();
+   }
+
+
+   // Ensure that the standard classes are included in the host
+   public static function include()
+   {
+      for(cls in classes)
+      {
+         Context.getModule(cls);
+         Compiler.keep(cls);
+      }
+      return Context.getBuildFields();
+   }
+}
+#end
+
+

+ 6 - 0
tests/unit/compile-cppia-host.hxml

@@ -0,0 +1,6 @@
+-main cpp.cppia.Host
+-D scriptable
+-D dll_export=""
+-debug
+-dce no
+-cpp bin/cppia

+ 6 - 0
tests/unit/compile-cppia.hxml

@@ -0,0 +1,6 @@
+compile-each.hxml
+-main unit.Test
+-cpp unit.cppia
+-D cppia
+-D NO_PRECOMPILED_HEADERS
+--macro cpp.cppia.HostClasses.exclude()