Browse Source

haXe/PHP integration

Nicolas Cannasse 17 years ago
parent
commit
7cd3f8763d
10 changed files with 297 additions and 236 deletions
  1. 4 2
      Makefile.win
  2. 7 3
      doc/CHANGES.txt
  3. 28 21
      haxe.vcproj
  4. 8 14
      std/DateTools.hx
  5. 7 0
      std/all.hxml
  6. 34 6
      std/haxe/ImportAll.hx
  7. 5 4
      std/haxe/remoting/SyncSocketConnection.hx
  8. 184 184
      std/php/Curl.hx
  9. 17 2
      tests/unit/unit.hxml
  10. 3 0
      tests/unit/unit.hxp

+ 4 - 2
Makefile.win

@@ -10,7 +10,7 @@ OUTPUT=sed 's/File "\([^"]\+\)", line \([0-9]\+\), \(.*\)/\1(\2): \3/' tmp.cmi
 FILES = ast.cmx lexer.cmx type.cmx common.cmx parser.cmx typecore.cmx \
 FILES = ast.cmx lexer.cmx type.cmx common.cmx parser.cmx typecore.cmx \
 	genxml.cmx typeload.cmx codegen.cmx typer.cmx \
 	genxml.cmx typeload.cmx codegen.cmx typer.cmx \
 	../neko/libs/include/ocaml/nast.cmx ../neko/libs/include/ocaml/binast.cmx ../neko/libs/include/ocaml/nxml.cmx \
 	../neko/libs/include/ocaml/nast.cmx ../neko/libs/include/ocaml/binast.cmx ../neko/libs/include/ocaml/nxml.cmx \
-	genneko.cmx genas3.cmx genjs.cmx genswf8.cmx genswf9.cmx genswf.cmx \
+	genneko.cmx genas3.cmx genjs.cmx genswf8.cmx genswf9.cmx genswf.cmx genphp.cmx \
 	main.cmx
 	main.cmx
 	
 	
 all: haxe.exe
 all: haxe.exe
@@ -34,6 +34,8 @@ genas3.cmx: type.cmx codegen.cmx ../../mtcvs/swflib/swfParser.cmx ../../mtcvs/sw
 
 
 genjs.cmx: type.cmx codegen.cmx lexer.cmx common.cmx ast.cmx
 genjs.cmx: type.cmx codegen.cmx lexer.cmx common.cmx ast.cmx
 
 
+genphp.cmx: type.cmx codegen.cmx lexer.cmx common.cmx ast.cmx
+
 genswf.cmx: type.cmx codegen.cmx ../../mtcvs/swflib/swfZip.cmx ../../mtcvs/swflib/swfParser.cmx ../../mtcvs/swflib/swf.cmx genswf9.cmx genswf8.cmx common.cmx ast.cmx ../../mtcvs/swflib/as3hlparse.cmx ../../mtcvs/swflib/as3hl.cmi ../../mtcvs/swflib/as3.cmi
 genswf.cmx: type.cmx codegen.cmx ../../mtcvs/swflib/swfZip.cmx ../../mtcvs/swflib/swfParser.cmx ../../mtcvs/swflib/swf.cmx genswf9.cmx genswf8.cmx common.cmx ast.cmx ../../mtcvs/swflib/as3hlparse.cmx ../../mtcvs/swflib/as3hl.cmi ../../mtcvs/swflib/as3.cmi
 
 
 genswf8.cmx: type.cmx codegen.cmx ../../mtcvs/swflib/swf.cmx lexer.cmx common.cmx ast.cmx ../../mtcvs/swflib/actionScript.cmx
 genswf8.cmx: type.cmx codegen.cmx ../../mtcvs/swflib/swf.cmx lexer.cmx common.cmx ast.cmx ../../mtcvs/swflib/actionScript.cmx
@@ -48,7 +50,7 @@ lexer.cmx: ast.cmx
 
 
 main.cmx: typer.cmx typeload.cmx typecore.cmx type.cmx parser.cmx lexer.cmx genxml.cmx genswf.cmx genneko.cmx genjs.cmx genas3.cmx common.cmx ast.cmx
 main.cmx: typer.cmx typeload.cmx typecore.cmx type.cmx parser.cmx lexer.cmx genxml.cmx genswf.cmx genneko.cmx genjs.cmx genas3.cmx common.cmx ast.cmx
 
 
-parser.cmx: lexer.cmx common.cmx ast.cmx
+parser.cmx: parser.ml lexer.cmx common.cmx ast.cmx
 	(ocamlopt -pp camlp4o $(CFLAGS) -c parser.ml 2>tmp.cmi && $(OUTPUT)) || ($(OUTPUT) && exit 1)
 	(ocamlopt -pp camlp4o $(CFLAGS) -c parser.ml 2>tmp.cmi && $(OUTPUT)) || ($(OUTPUT) && exit 1)
 
 
 type.cmx: ast.cmx
 type.cmx: ast.cmx

+ 7 - 3
doc/CHANGES.txt

@@ -6,6 +6,13 @@ TODO optimizer : move multiple statics access into local variables
 TODO inlining : allow inlined getter/setter
 TODO inlining : allow inlined getter/setter
 TODO inlining : substitute class+function type parameters in order to have fully typed expressions
 TODO inlining : substitute class+function type parameters in order to have fully typed expressions
 
 
+2008-??-??: 2.0
+	fixed current package bug in inherited constructor type
+	delayed type-parameter constraints check (allow mutual rec extends for SPOD)
+	improved unclosed macro error reporting
+	haxe/PHP integeration
+	renamed NekoSocketConnection to SyncSocketConnection (php support)
+
 2008-07-17: 2.0-RC1
 2008-07-17: 2.0-RC1
 	genneko : remove big array error (fixed in neko 1.7.1)
 	genneko : remove big array error (fixed in neko 1.7.1)
 	fixed neko.net.ThreadRemotingServer.onXML
 	fixed neko.net.ThreadRemotingServer.onXML
@@ -52,9 +59,6 @@ TODO inlining : substitute class+function type parameters in order to have fully
 	added Type.createEnum
 	added Type.createEnum
 	check that local variables get correctly initialized before usage
 	check that local variables get correctly initialized before usage
 	haxe.Stack support for flash9
 	haxe.Stack support for flash9
-	fixed current package bug in inherited constructor type
-	delayed type-parameter constraints check (allow mutual rec extends for SPOD)
-	improved unclosed macro error reporting
 
 
 2008-04-05: 1.19
 2008-04-05: 1.19
 	fixed flash9 Array.toString
 	fixed flash9 Array.toString

+ 28 - 21
haxe.vcproj

@@ -44,9 +44,6 @@
 			<File
 			<File
 				RelativePath="..\neko\libs\include\ocaml\binast.ml">
 				RelativePath="..\neko\libs\include\ocaml\binast.ml">
 			</File>
 			</File>
-			<File
-				RelativePath=".\genneko.ml">
-			</File>
 			<File
 			<File
 				RelativePath="..\neko\libs\include\ocaml\nast.ml">
 				RelativePath="..\neko\libs\include\ocaml\nast.ml">
 			</File>
 			</File>
@@ -64,6 +61,34 @@
 				RelativePath="..\..\mtcvs\swflib\as3hl.mli">
 				RelativePath="..\..\mtcvs\swflib\as3hl.mli">
 			</File>
 			</File>
 		</Filter>
 		</Filter>
+		<Filter
+			Name="gen"
+			Filter="">
+			<File
+				RelativePath=".\genas3.ml">
+			</File>
+			<File
+				RelativePath=".\genjs.ml">
+			</File>
+			<File
+				RelativePath=".\genneko.ml">
+			</File>
+			<File
+				RelativePath=".\genphp.ml">
+			</File>
+			<File
+				RelativePath=".\genswf.ml">
+			</File>
+			<File
+				RelativePath=".\genswf8.ml">
+			</File>
+			<File
+				RelativePath=".\genswf9.ml">
+			</File>
+			<File
+				RelativePath=".\genxml.ml">
+			</File>
+		</Filter>
 		<File
 		<File
 			RelativePath=".\ast.ml">
 			RelativePath=".\ast.ml">
 		</File>
 		</File>
@@ -73,24 +98,6 @@
 		<File
 		<File
 			RelativePath=".\common.ml">
 			RelativePath=".\common.ml">
 		</File>
 		</File>
-		<File
-			RelativePath=".\genas3.ml">
-		</File>
-		<File
-			RelativePath=".\genjs.ml">
-		</File>
-		<File
-			RelativePath=".\genswf.ml">
-		</File>
-		<File
-			RelativePath=".\genswf8.ml">
-		</File>
-		<File
-			RelativePath=".\genswf9.ml">
-		</File>
-		<File
-			RelativePath=".\genxml.ml">
-		</File>
 		<File
 		<File
 			RelativePath=".\lexer.mll">
 			RelativePath=".\lexer.mll">
 		</File>
 		</File>

+ 8 - 14
std/DateTools.hx

@@ -34,7 +34,7 @@ class DateTools {
 	#if neko
 	#if neko
 	static var date_format = neko.Lib.load("std","date_format",2);
 	static var date_format = neko.Lib.load("std","date_format",2);
 	#else
 	#else
-	private static function __jsflash_format_get( d : Date, e : String ) : String {
+	private static function __format_get( d : Date, e : String ) : String {
 		return switch( e ){
 		return switch( e ){
 			case "%":
 			case "%":
 				"%";
 				"%";
@@ -43,7 +43,7 @@ class DateTools {
 			case "d":
 			case "d":
 				untyped StringTools.lpad(Std.string(d.getDate()),"0",2);
 				untyped StringTools.lpad(Std.string(d.getDate()),"0",2);
 			case "D":
 			case "D":
-				__jsflash_format(d,"%m/%d/%y");
+				__format(d,"%m/%d/%y");
 			case "e":
 			case "e":
 				untyped Std.string(d.getDate());
 				untyped Std.string(d.getDate());
 			case "H","k":
 			case "H","k":
@@ -60,9 +60,9 @@ class DateTools {
 			case "p":
 			case "p":
 				untyped if( d.getHours() > 11 ) "PM"; else "AM";
 				untyped if( d.getHours() > 11 ) "PM"; else "AM";
 			case "r":
 			case "r":
-				__jsflash_format(d,"%I:%M:%S %p");
+				__format(d,"%I:%M:%S %p");
 			case "R":
 			case "R":
-				__jsflash_format(d,"%H:%M");
+				__format(d,"%H:%M");
 			case "s":
 			case "s":
 				Std.string(Std.int(d.getTime()/1000));
 				Std.string(Std.int(d.getTime()/1000));
 			case "S":
 			case "S":
@@ -70,7 +70,7 @@ class DateTools {
 			case "t":
 			case "t":
 				"\t";
 				"\t";
 			case "T":
 			case "T":
-				__jsflash_format(d,"%H:%M:%S");
+				__format(d,"%H:%M:%S");
 			case "u":
 			case "u":
 				untyped{
 				untyped{
 					var t = d.getDay();
 					var t = d.getDay();
@@ -87,7 +87,7 @@ class DateTools {
 		}
 		}
 	}
 	}
 
 
-	private static function __jsflash_format( d : Date, f : String ) : String {
+	private static function __format( d : Date, f : String ) : String {
 		var r = new StringBuf();
 		var r = new StringBuf();
 		var p = 0;
 		var p = 0;
 		while( true ){
 		while( true ){
@@ -96,7 +96,7 @@ class DateTools {
 				break;
 				break;
 
 
 			r.addSub(f,p,np-p);
 			r.addSub(f,p,np-p);
-			r.add( __jsflash_format_get(d, f.substr(np+1,1) ) );
+			r.add( __format_get(d, f.substr(np+1,1) ) );
 
 
 			p = np+2;
 			p = np+2;
 		}
 		}
@@ -115,14 +115,8 @@ class DateTools {
 	public static function format( d : Date, f : String ) : String {
 	public static function format( d : Date, f : String ) : String {
 		#if neko
 		#if neko
 			untyped return new String(date_format(d.__t, f.__s));
 			untyped return new String(date_format(d.__t, f.__s));
-		#elseif js
-			return __jsflash_format(d, f );
-		#elseif flash
-			return __jsflash_format(d, f );
-		#elseif php
-			return __jsflash_format(d, f );
 		#else
 		#else
-			return null;
+			return __format(d,f);
 		#end
 		#end
 	}
 	}
 
 

+ 7 - 0
std/all.hxml

@@ -39,5 +39,12 @@ haxe.ImportAll
 
 
 --next
 --next
 
 
+-php all_php
+--no-output
+-xml php.xml
+haxe.ImportAll
+
+--next
+
 -xml cross.xml
 -xml cross.xml
 haxe.ImportAll
 haxe.ImportAll

+ 34 - 6
std/haxe/ImportAll.hx

@@ -46,9 +46,7 @@ import Type;
 import Xml;
 import Xml;
 
 
 import haxe.FastList;
 import haxe.FastList;
-#if !neko
 import haxe.Firebug;
 import haxe.Firebug;
-#end
 import haxe.Http;
 import haxe.Http;
 import haxe.ImportAll;
 import haxe.ImportAll;
 import haxe.Log;
 import haxe.Log;
@@ -87,8 +85,8 @@ import haxe.remoting.AsyncProxy;
 import haxe.remoting.LocalConnection;
 import haxe.remoting.LocalConnection;
 import haxe.remoting.DelayedConnection;
 import haxe.remoting.DelayedConnection;
 import haxe.remoting.FlashJsConnection;
 import haxe.remoting.FlashJsConnection;
-#if neko
-import haxe.remoting.NekoSocketConnection;
+#if (neko || php)
+import haxe.remoting.SyncSocketConnection;
 #else
 #else
 import haxe.remoting.SocketConnection;
 import haxe.remoting.SocketConnection;
 #end
 #end
@@ -444,7 +442,7 @@ import js.XMLSocket;
 import tools.haxedoc.Main;
 import tools.haxedoc.Main;
 import tools.haxelib.Main;
 import tools.haxelib.Main;
 import tools.haxelib.Site;
 import tools.haxelib.Site;
-//import tools.hxinst.Main -> needs xCross
+import tools.hxinst.Main;
 
 
 #end
 #end
 
 
@@ -530,4 +528,34 @@ import flash.ui.ContextMenuClipboardItems;
 import flash.ui.MouseCursor;
 import flash.ui.MouseCursor;
 
 
 import flash.system.JPEGLoaderContext;
 import flash.system.JPEGLoaderContext;
-#end
+#end
+
+#if php
+
+import php.Curl;
+import php.Exception;
+import php.FileSystem;
+import php.HException;
+import php.IniHash;
+import php.Lib;
+import php.Session;
+import php.Sys;
+import php.Utf8;
+import php.Web;
+
+import php.db.Connection;
+import php.db.DBase;
+import php.db.Manager;
+import php.db.Mysql;
+import php.db.Object;
+import php.db.ResultSet;
+import php.db.Sqlite;
+
+import php.io.File;
+import php.io.FileInput;
+import php.io.FileOutput;
+import php.io.Path;
+import php.io.Process;
+
+#end
+

+ 5 - 4
std/haxe/remoting/NekoSocketConnection.hx → std/haxe/remoting/SyncSocketConnection.hx

@@ -23,8 +23,9 @@
  * DAMAGE.
  * DAMAGE.
  */
  */
 package haxe.remoting;
 package haxe.remoting;
+import haxe.remoting.SocketProtocol.Socket;
 
 
-class NekoSocketConnection implements Connection, implements Dynamic<Connection> {
+class SyncSocketConnection implements Connection, implements Dynamic<Connection> {
 
 
 	var __path : Array<String>;
 	var __path : Array<String>;
 	var __proto : SocketProtocol;
 	var __proto : SocketProtocol;
@@ -35,7 +36,7 @@ class NekoSocketConnection implements Connection, implements Dynamic<Connection>
 	}
 	}
 
 
 	public function resolve( name ) : Connection {
 	public function resolve( name ) : Connection {
-		var s = new NekoSocketConnection(__proto,__path.copy());
+		var s = new SyncSocketConnection(__proto,__path.copy());
 		s.__path.push(name);
 		s.__path.push(name);
 		return s;
 		return s;
 	}
 	}
@@ -78,8 +79,8 @@ class NekoSocketConnection implements Connection, implements Dynamic<Connection>
 		try __proto.socket.close() catch( e : Dynamic ) { };
 		try __proto.socket.close() catch( e : Dynamic ) { };
 	}
 	}
 
 
-	public static function create( s : neko.net.Socket, ?ctx : Context ) {
-		return new NekoSocketConnection(new SocketProtocol(s,ctx),[]);
+	public static function create( s : Socket, ?ctx : Context ) {
+		return new SyncSocketConnection(new SocketProtocol(s,ctx),[]);
 	}
 	}
 
 
 }
 }

File diff suppressed because it is too large
+ 184 - 184
std/php/Curl.hx


+ 17 - 2
tests/unit/unit.hxml

@@ -8,8 +8,7 @@
 
 
 --next
 --next
 # Flash9
 # Flash9
--swf unit9.swf
--swf-version 9
+-swf9 unit9.swf
 -main unit.Test
 -main unit.Test
 -debug
 -debug
 -cp ..
 -cp ..
@@ -24,6 +23,14 @@ unit.Test
 -resource res1.txt
 -resource res1.txt
 -resource res2.bin
 -resource res2.bin
 
 
+--next
+# Php
+-php out
+-main unit.Test
+-cp ..
+-resource res1.txt
+-resource res2.bin
+
 --next
 --next
 # Neko
 # Neko
 -neko unit.n
 -neko unit.n
@@ -38,3 +45,11 @@ unit.Test
 -neko remoting.n
 -neko remoting.n
 -main unit.RemotingServer
 -main unit.RemotingServer
 -cp ..
 -cp ..
+
+--next
+# PHP
+-php php
+-main unit.Test
+-cp ..
+-resource res1.txt
+-resource res2.bin

+ 3 - 0
tests/unit/unit.hxp

@@ -21,6 +21,9 @@
 -resource res2.bin
 -resource res2.bin
 </output>
 </output>
   <output name="RemotingServer" mode="neko" out="remoting.n" class="unit.RemotingServer" lib="" cmd="" main="True" debug="False">-cp ..</output>
   <output name="RemotingServer" mode="neko" out="remoting.n" class="unit.RemotingServer" lib="" cmd="" main="True" debug="False">-cp ..</output>
+  <output name="PHP" mode="php" out="php" class="unit.Test" lib="" cmd="" main="True" debug="False">-cp ..
+-resource res1.txt
+-resource res2.bin</output>
   <files path="/">
   <files path="/">
     <file path="MyClass.hx" />
     <file path="MyClass.hx" />
     <file path="MyEnum.hx" />
     <file path="MyEnum.hx" />

Some files were not shown because too many files changed in this diff