Browse Source

haxe3 compatibility

Nicolas Cannasse 13 years ago
parent
commit
5f8cb2d13b

+ 7 - 4
std/neko/vm/Module.hx

@@ -177,16 +177,19 @@ class Module {
 	public static function readGlobalsNames( i : haxe.io.Input ) {
 	public static function readGlobalsNames( i : haxe.io.Input ) {
 		if( i.readByte() != 0x4E || i.readByte() != 0x45 || i.readByte() != 0x4B || i.readByte() != 0x4F )
 		if( i.readByte() != 0x4E || i.readByte() != 0x45 || i.readByte() != 0x4B || i.readByte() != 0x4F )
 			throw "Not a neko file";
 			throw "Not a neko file";
-		var nglobals = i.readUInt30();
-		var nfields = i.readUInt30();
-		var codesize = i.readUInt30();
+		function readInt() {
+			return #if haxe3 i.readInt32() #else i.readUInt30() #end;
+		}
+		var nglobals = readInt();
+		var nfields = readInt();
+		var codesize = readInt();
 		var a = new Array();
 		var a = new Array();
 		for( k in 0...nglobals ) {
 		for( k in 0...nglobals ) {
 			switch(i.readByte()) {
 			switch(i.readByte()) {
 			case 1:
 			case 1:
 				a.push(i.readUntil(0));
 				a.push(i.readUntil(0));
 			case 2:
 			case 2:
-				a.push("<fun:"+(i.readUInt30()&0xFFFFFF)+">");
+				a.push("<fun:"+(readInt()&0xFFFFFF)+">");
 			case 3:
 			case 3:
 				a.push("STRING:"+i.readString(i.readUInt16()));
 				a.push("STRING:"+i.readString(i.readUInt16()));
 			case 4:
 			case 4:

+ 5 - 0
std/neko/zip/CRC32.hx

@@ -23,6 +23,9 @@
  * DAMAGE.
  * DAMAGE.
  */
  */
 package neko.zip;
 package neko.zip;
+
+#if !haxe3
+
 import haxe.Int32;
 import haxe.Int32;
 
 
 class CRC32 {
 class CRC32 {
@@ -50,3 +53,5 @@ class CRC32 {
 		return Int32.xor(crc, init);
 		return Int32.xor(crc, init);
 	}
 	}
 }
 }
+
+#end

+ 5 - 1
std/neko/zip/Reader.hx

@@ -24,6 +24,8 @@
  */
  */
 package neko.zip;
 package neko.zip;
 
 
+#if !haxe3
+
 typedef ZipEntry = {
 typedef ZipEntry = {
 	var fileName : String;
 	var fileName : String;
 	var fileSize : Int;
 	var fileSize : Int;
@@ -280,4 +282,6 @@ class Reader {
 		return i;
 		return i;
 	}
 	}
 
 
-}
+}
+
+#end

+ 5 - 1
std/neko/zip/Writer.hx

@@ -24,6 +24,8 @@
  */
  */
 package neko.zip;
 package neko.zip;
 
 
+#if !haxe3
+
 class Writer {
 class Writer {
 
 
 	/*
 	/*
@@ -131,4 +133,6 @@ class Writer {
 	}
 	}
 
 
 
 
-}
+}
+
+#end

+ 3 - 3
std/tools/haxedoc/HtmlPrinter.hx

@@ -6,12 +6,12 @@ class HtmlPrinter {
 	static function loadTemplate() {
 	static function loadTemplate() {
 		var hdata = try
 		var hdata = try
 			// load in current local/web directory
 			// load in current local/web directory
-			neko.io.File.getContent(neko.Web.getCwd()+"template.xml")
+			sys.io.File.getContent(neko.Web.getCwd()+"template.xml")
 		catch( e : Dynamic ) try {
 		catch( e : Dynamic ) try {
 			// load in haxe subdirectory (TODO : make it work on linux/osx)
 			// load in haxe subdirectory (TODO : make it work on linux/osx)
-			var p = ~/[\/\\]/g.split(neko.Sys.executablePath());
+			var p = ~/[\/\\]/g.split(Sys.executablePath());
 			p.pop();
 			p.pop();
-			neko.io.File.getContent(p.join("/")+"/std/tools/template.xml");
+			sys.io.File.getContent(p.join("/")+"/std/tools/template.xml");
 		} catch( e : Dynamic )
 		} catch( e : Dynamic )
 			default_template;
 			default_template;
 		return Xml.parse(hdata);
 		return Xml.parse(hdata);

+ 10 - 10
std/tools/haxedoc/Main.hx

@@ -30,7 +30,7 @@ class Main {
 	static var parser = new haxe.rtti.XmlParser();
 	static var parser = new haxe.rtti.XmlParser();
 
 
 	static function loadFile(file,platform,?remap) {
 	static function loadFile(file,platform,?remap) {
-		var data = neko.io.File.getContent(neko.Web.getCwd()+file);
+		var data = sys.io.File.getContent(neko.Web.getCwd()+file);
 		var x = Xml.parse(data).firstElement();
 		var x = Xml.parse(data).firstElement();
 		if( remap != null )
 		if( remap != null )
 			transformPackage(x,remap,platform);
 			transformPackage(x,remap,platform);
@@ -50,7 +50,7 @@ class Main {
 	}
 	}
 
 
 	static function save(html : HtmlPrinter,x,file) {
 	static function save(html : HtmlPrinter,x,file) {
-		var f = neko.io.File.write(file,true);
+		var f = sys.io.File.write(file,true);
 		html.output = f.writeString;
 		html.output = f.writeString;
 		html.process(x);
 		html.process(x);
 		f.close();
 		f.close();
@@ -65,7 +65,7 @@ class Main {
 			var old = html.baseUrl;
 			var old = html.baseUrl;
 			html.baseUrl = "../"+html.baseUrl;
 			html.baseUrl = "../"+html.baseUrl;
 			path += name + "/";
 			path += name + "/";
-			try neko.FileSystem.createDirectory(path) catch( e : Dynamic ) { }
+			try sys.FileSystem.createDirectory(path) catch( e : Dynamic ) { }
 			for( e in entries )
 			for( e in entries )
 				generateEntry(html,e,path);
 				generateEntry(html,e,path);
 			html.baseUrl = old;
 			html.baseUrl = old;
@@ -85,7 +85,7 @@ class Main {
 			html.addFilter(f);
 			html.addFilter(f);
 		save(html,TPackage("root","root",parser.root),"index.html");
 		save(html,TPackage("root","root",parser.root),"index.html");
 		html.baseUrl = "";
 		html.baseUrl = "";
-		try neko.FileSystem.createDirectory("content") catch( e : Dynamic ) { }
+		try sys.FileSystem.createDirectory("content") catch( e : Dynamic ) { }
 		for( e in parser.root )
 		for( e in parser.root )
 			generateEntry(html,e,"content/");
 			generateEntry(html,e,"content/");
 	}
 	}
@@ -94,7 +94,7 @@ class Main {
 		if( neko.Web.isModNeko ) {
 		if( neko.Web.isModNeko ) {
 			var h = neko.Web.getParams();
 			var h = neko.Web.getParams();
 			var dataFile = neko.Web.getCwd()+".data";
 			var dataFile = neko.Web.getCwd()+".data";
-			var data : TypeRoot = try neko.Lib.unserialize(neko.io.File.getBytes(dataFile)) catch( e : Dynamic ) null;
+			var data : TypeRoot = try neko.Lib.unserialize(sys.io.File.getBytes(dataFile)) catch( e : Dynamic ) null;
 			if( h.get("reload") != null || data == null ) {
 			if( h.get("reload") != null || data == null ) {
 				var baseDir = "../data/media/";
 				var baseDir = "../data/media/";
 				loadFile(baseDir+"flash.xml","flash");
 				loadFile(baseDir+"flash.xml","flash");
@@ -105,7 +105,7 @@ class Main {
 				parser.sort();
 				parser.sort();
 				data = parser.root;
 				data = parser.root;
 				var bytes = neko.Lib.serialize(data);
 				var bytes = neko.Lib.serialize(data);
-				var f = neko.io.File.write(dataFile,true);
+				var f = sys.io.File.write(dataFile,true);
 				f.write(bytes);
 				f.write(bytes);
 				f.close();
 				f.close();
 			}
 			}
@@ -126,7 +126,7 @@ class Main {
 			var filter = false;
 			var filter = false;
 			var filters = new List();
 			var filters = new List();
 			var pf = null;
 			var pf = null;
-			for( x in neko.Sys.args() ) {
+			for( x in Sys.args() ) {
 				if( x == "-f" )
 				if( x == "-f" )
 					filter = true;
 					filter = true;
 				else if( x == "-v" )
 				else if( x == "-v" )
@@ -145,9 +145,9 @@ class Main {
 			}
 			}
 			parser.sort();
 			parser.sort();
 			if( parser.root.length == 0 ) {
 			if( parser.root.length == 0 ) {
-				neko.Lib.println("Haxe Doc Generator 2.0 - (c)2006 Motion-Twin");
-				neko.Lib.println(" Usage : haxedoc [xml files] [-f filter]");
-				neko.Sys.exit(1);
+				Sys.println("Haxe Doc Generator 2.0 - (c)2006 Motion-Twin");
+				Sys.println(" Usage : haxedoc [xml files] [-f filter]");
+				Sys.exit(1);
 			}
 			}
 			generateAll(filters);
 			generateAll(filters);
 		}
 		}

+ 1 - 0
std/tools/haxedoc/haxedoc.hxml

@@ -2,3 +2,4 @@
 -neko haxedoc.n
 -neko haxedoc.n
 -main tools.haxedoc.Main
 -main tools.haxedoc.Main
 -cmd nekotools boot haxedoc.n
 -cmd nekotools boot haxedoc.n
+-D haxe3

+ 11 - 5
std/tools/haxelib/Datas.hx

@@ -1,6 +1,12 @@
 package tools.haxelib;
 package tools.haxelib;
-
+#if haxe3
+import haxe.zip.Reader;
+import haxe.zip.Entry;
+#else
 import neko.zip.Reader;
 import neko.zip.Reader;
+private typedef Entry = ZipEntry;
+#end
+
 import haxe.xml.Check;
 import haxe.xml.Check;
 
 
 typedef UserInfos = {
 typedef UserInfos = {
@@ -82,18 +88,18 @@ class Datas {
 		return safe(lib)+"-"+safe(ver)+".zip";
 		return safe(lib)+"-"+safe(ver)+".zip";
 	}
 	}
 
 
-	public static function readDoc( zip : List<ZipEntry> ) : String {
+	public static function readDoc( zip : List<Entry> ) : String {
 		for( f in zip )
 		for( f in zip )
 			if( StringTools.endsWith(f.fileName,DOCXML) )
 			if( StringTools.endsWith(f.fileName,DOCXML) )
-				return neko.zip.Reader.unzip(f).toString();
+				return Reader.unzip(f).toString();
 		return null;
 		return null;
 	}
 	}
 
 
-	public static function readInfos( zip : List<ZipEntry>, check : Bool ) : XmlInfos {
+	public static function readInfos( zip : List<Entry>, check : Bool ) : XmlInfos {
 		var xmldata = null;
 		var xmldata = null;
 		for( f in zip )
 		for( f in zip )
 			if( StringTools.endsWith(f.fileName,XML) ) {
 			if( StringTools.endsWith(f.fileName,XML) ) {
-				xmldata = neko.zip.Reader.unzip(f).toString();
+				xmldata = Reader.unzip(f).toString();
 				break;
 				break;
 			}
 			}
 		if( xmldata == null )
 		if( xmldata == null )

+ 17 - 21
std/tools/haxelib/Main.hx

@@ -1,4 +1,9 @@
 package tools.haxelib;
 package tools.haxelib;
+#if haxe3
+import haxe.zip.Reader;
+#else
+import neko.zip.Reader;
+#end
 
 
 enum Answer {
 enum Answer {
 	Yes;
 	Yes;
@@ -301,7 +306,7 @@ class Main {
 	function submit() {
 	function submit() {
 		var file = param("Package");
 		var file = param("Package");
 		var data = sys.io.File.getBytes(file);
 		var data = sys.io.File.getBytes(file);
-		var zip = neko.zip.Reader.readZip(new haxe.io.BytesInput(data));
+		var zip = Reader.readZip(new haxe.io.BytesInput(data));
 		var infos = Datas.readInfos(zip,true);
 		var infos = Datas.readInfos(zip,true);
 		var user = infos.developers.first();
 		var user = infos.developers.first();
 		var password;
 		var password;
@@ -415,7 +420,7 @@ class Main {
 
 
 		// read zip content
 		// read zip content
 		var f = sys.io.File.read(filepath,true);
 		var f = sys.io.File.read(filepath,true);
-		var zip = neko.zip.Reader.readZip(f);
+		var zip = Reader.readZip(f);
 		f.close();
 		f.close();
 		var infos = Datas.readInfos(zip,false);
 		var infos = Datas.readInfos(zip,false);
 
 
@@ -460,7 +465,7 @@ class Main {
 				}
 				}
 				path += file;
 				path += file;
 				print("  Install "+path);
 				print("  Install "+path);
-				var data = neko.zip.Reader.unzip(zipfile);
+				var data = Reader.unzip(zipfile);
 				sys.io.File.saveBytes(target+path,data);
 				sys.io.File.saveBytes(target+path,data);
 			}
 			}
 		}
 		}
@@ -500,25 +505,18 @@ class Main {
 	}
 	}
 
 
 	function safeDelete( file ) {
 	function safeDelete( file ) {
-		try
-		{
+		try {
 			sys.FileSystem.deleteFile(file);
 			sys.FileSystem.deleteFile(file);
 			return true;
 			return true;
-		}
-		catch (e:Dynamic)
-		{
-			if (neko.Sys.systemName() == "Windows")
-			{
-				try
-				{
-					neko.Sys.command("attrib -R \"" +file+ "\"");
+		} catch (e:Dynamic) {
+			if( Sys.systemName() == "Windows") {
+				try {
+					Sys.command("attrib -R \"" +file+ "\"");
 					sys.FileSystem.deleteFile(file);
 					sys.FileSystem.deleteFile(file);
 					return true;
 					return true;
-				} catch (e:Dynamic)
-				{
+				} catch (e:Dynamic) {
 				}
 				}
 			}
 			}
-
 			return false;
 			return false;
 		}
 		}
 	}
 	}
@@ -847,14 +845,12 @@ class Main {
 			null;
 			null;
 
 
 		print("Installing " +libName + " from " +gitPath);
 		print("Installing " +libName + " from " +gitPath);
-		if (neko.Sys.command("git clone \"" +gitPath + "\" \"" +libPath + "\"") != 0)
-		{
+		if( Sys.command("git clone \"" +gitPath + "\" \"" +libPath + "\"") != 0 ) {
 			print("Could not clone git repository");
 			print("Could not clone git repository");
 			return;
 			return;
 		}
 		}
 		Sys.setCwd(libPath);
 		Sys.setCwd(libPath);
-		if (rev != null)
-		{
+		if (rev != null) {
 			var ret = command("git", ["checkout", rev]);
 			var ret = command("git", ["checkout", rev]);
 			if (ret.code != 0)
 			if (ret.code != 0)
 			{
 			{
@@ -916,7 +912,7 @@ class Main {
 	}
 	}
 
 
 	function command( cmd:String, args:Array<String> ) {
 	function command( cmd:String, args:Array<String> ) {
-		var p = new neko.io.Process(cmd, args);
+		var p = new sys.io.Process(cmd, args);
 		var code = p.exitCode();
 		var code = p.exitCode();
 		return { code:code, out: code == 0 ? p.stdout.readAll().toString() : p.stderr.readAll().toString() };
 		return { code:code, out: code == 0 ? p.stdout.readAll().toString() : p.stderr.readAll().toString() };
 	}
 	}

+ 8 - 8
std/tools/haxelib/Site.hx

@@ -22,16 +22,16 @@ class Site {
 	}
 	}
 
 
 	static function run() {
 	static function run() {
-		if( !neko.FileSystem.exists(TMP_DIR) )
-			neko.FileSystem.createDirectory(TMP_DIR);
-		if( !neko.FileSystem.exists(REP_DIR) )
-			neko.FileSystem.createDirectory(REP_DIR);
+		if( !sys.FileSystem.exists(TMP_DIR) )
+			sys.FileSystem.createDirectory(TMP_DIR);
+		if( !sys.FileSystem.exists(REP_DIR) )
+			sys.FileSystem.createDirectory(REP_DIR);
 
 
 		var ctx = new haxe.remoting.Context();
 		var ctx = new haxe.remoting.Context();
 		ctx.addObject("api",new SiteApi(db));
 		ctx.addObject("api",new SiteApi(db));
 		if( haxe.remoting.HttpConnection.handleRequest(ctx) )
 		if( haxe.remoting.HttpConnection.handleRequest(ctx) )
 			return;
 			return;
-		if( neko.Sys.args()[0] == "setup" ) {
+		if( Sys.args()[0] == "setup" ) {
 			setup();
 			setup();
 			neko.Lib.print("Setup done\n");
 			neko.Lib.print("Setup done\n");
 			return;
 			return;
@@ -42,7 +42,7 @@ class Site {
 		neko.Web.parseMultipart(function(p,filename) {
 		neko.Web.parseMultipart(function(p,filename) {
 			if( p == "file" ) {
 			if( p == "file" ) {
 				sid = Std.parseInt(filename);
 				sid = Std.parseInt(filename);
-				file = neko.io.File.write(TMP_DIR+"/"+sid+".tmp",true);
+				file = sys.io.File.write(TMP_DIR+"/"+sid+".tmp",true);
 			} else
 			} else
 				throw p+" not accepted";
 				throw p+" not accepted";
 		},function(data,pos,len) {
 		},function(data,pos,len) {
@@ -58,7 +58,7 @@ class Site {
 	}
 	}
 
 
 	static function display() {
 	static function display() {
-		var data = neko.io.File.getContent(CWD + "website.mtt");
+		var data = sys.io.File.getContent(CWD + "website.mtt");
 		var page = new haxe.Template(data);
 		var page = new haxe.Template(data);
 		var ctx : Dynamic = {};
 		var ctx : Dynamic = {};
 		var macros = {
 		var macros = {
@@ -195,7 +195,7 @@ class Site {
 			root.addChild(e);
 			root.addChild(e);
 			return e;
 			return e;
 		}
 		}
-		neko.Sys.setTimeLocale("en_US.UTF8");
+		Sys.setTimeLocale("en_US.UTF8");
 		var url = "http://"+neko.Web.getClientHeader("Host");
 		var url = "http://"+neko.Web.getClientHeader("Host");
 		var rss = Xml.createElement("rss");
 		var rss = Xml.createElement("rss");
 		rss.set("version","2.0");
 		rss.set("version","2.0");

+ 4 - 4
std/tools/haxelib/SiteApi.hx

@@ -90,8 +90,8 @@ class SiteApi {
 	public function processSubmit( id : String, user : String, pass : String ) : String {
 	public function processSubmit( id : String, user : String, pass : String ) : String {
 		var path = Site.TMP_DIR+"/"+Std.parseInt(id)+".tmp";
 		var path = Site.TMP_DIR+"/"+Std.parseInt(id)+".tmp";
 
 
-		var file = try neko.io.File.read(path,true) catch( e : Dynamic ) throw "Invalid file id #"+id;
-		var zip = try neko.zip.Reader.readZip(file) catch( e : Dynamic ) { file.close(); neko.Lib.rethrow(e); };
+		var file = try sys.io.File.read(path,true) catch( e : Dynamic ) throw "Invalid file id #"+id;
+		var zip = try haxe.zip.Reader.readZip(file) catch( e : Dynamic ) { file.close(); neko.Lib.rethrow(e); };
 		file.close();
 		file.close();
 
 
 		var infos = Datas.readInfos(zip,true);
 		var infos = Datas.readInfos(zip,true);
@@ -213,8 +213,8 @@ class SiteApi {
 
 
 		// update file
 		// update file
 		var target = Site.REP_DIR+"/"+Datas.fileName(p.name,infos.version);
 		var target = Site.REP_DIR+"/"+Datas.fileName(p.name,infos.version);
-		if( current != null ) neko.FileSystem.deleteFile(target);
-		neko.FileSystem.rename(path,target);
+		if( current != null ) sys.FileSystem.deleteFile(target);
+		sys.FileSystem.rename(path,target);
 
 
 		// update existing version
 		// update existing version
 		if( current != null ) {
 		if( current != null ) {

+ 2 - 0
std/tools/haxelib/haxelib.hxml

@@ -1,6 +1,8 @@
 -neko index.n
 -neko index.n
 -main tools.haxelib.Site
 -main tools.haxelib.Site
+-D haxe3
 --next
 --next
 -neko haxelib.n
 -neko haxelib.n
 -main tools.haxelib.Main
 -main tools.haxelib.Main
 -cmd "nekotools boot haxelib.n"
 -cmd "nekotools boot haxelib.n"
+-D haxe3

+ 1 - 1
std/tools/haxelib/haxelib.hxproj

@@ -23,7 +23,7 @@
     <option flashStrict="False" />
     <option flashStrict="False" />
     <option mainClass="tools.haxelib.Site" />
     <option mainClass="tools.haxelib.Site" />
     <option enabledebug="False" />
     <option enabledebug="False" />
-    <option additional="--next&#xA;-neko haxelib.n&#xA;&#xA;-main tools.haxelib.Main&#xA;&#xA;-cmd nekotools boot haxelib.n" />
+    <option additional="-D haxe3&#xA;--next&#xA;-neko haxelib.n&#xA;-main tools.haxelib.Main&#xA;-cmd nekotools boot haxelib.n&#xA;-D haxe3" />
   </build>
   </build>
   <!-- haxelib libraries -->
   <!-- haxelib libraries -->
   <haxelib>
   <haxelib>

+ 17 - 2
std/tools/hxinst/Main.hx

@@ -313,7 +313,22 @@ class Main {
 
 
 	function unzip( file ) {
 	function unzip( file ) {
 		var ch = sys.io.File.read(file,true);
 		var ch = sys.io.File.read(file,true);
-		var entries = if( haxe.io.Path.extension(file) == "zip" ) neko.zip.Reader.readZip(ch) else neko.zip.Reader.readTar(ch,true);
+		var entries;
+		if( haxe.io.Path.extension(file) == "zip" )
+			entries = haxe.zip.Reader.readZip(ch);
+		else {
+			entries = new List();
+			for( f in new format.tgz.Reader(ch).read() )
+				entries.add({
+					fileName : f.fileName,
+					fileTime : f.fileTime,
+					fileSize : f.fileSize,
+					data : f.data,
+					dataSize : f.data.length,
+					compressed : false,
+					crc32 : null,
+				});
+		}
 		ch.close();
 		ch.close();
 		return entries;
 		return entries;
 	}
 	}
@@ -344,7 +359,7 @@ class Main {
 			}
 			}
 			var filename = dir + "/" + path.join("/");
 			var filename = dir + "/" + path.join("/");
 			var ch = sys.io.File.write(filename,true);
 			var ch = sys.io.File.write(filename,true);
-			ch.write(neko.zip.Reader.unzip(f));
+			ch.write(haxe.zip.Reader.unzip(f));
 			ch.close();
 			ch.close();
 			if( SYS != "Windows" ) {
 			if( SYS != "Windows" ) {
 				var exe = haxe.io.Path.extension(filename) == "";
 				var exe = haxe.io.Path.extension(filename) == "";

+ 2 - 0
std/tools/hxinst/hxinst.hxml

@@ -1,4 +1,6 @@
 # Neko
 # Neko
+-D haxe3
+-lib format
 -neko hxinst.n
 -neko hxinst.n
 -main tools.hxinst.Main
 -main tools.hxinst.Main
 -lib xcross
 -lib xcross