Browse Source

Sys class + sys.io package

Nicolas Cannasse 13 years ago
parent
commit
62e56506db

+ 2 - 0
doc/CHANGES.txt

@@ -33,6 +33,8 @@
 	flash : added @:file("a.dat") class File extends flash.utils.ByteArray
 	js : added --js-modern for wrapping output in a closure and ES5 strict mode
 	all : null, true and false are now keywords
+	all : neko.io.Path, cpp.io.Path and php.io.Path are now haxe.io.Path
+	neko, cpp, php : added Sys class and sys.io package
 
 2011-09-25: 2.08
 	js : added js.JQuery

+ 135 - 0
std/Sys.hx

@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2005-2012, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+/**
+	This class gives you access to many base functionalities of system platforms. Looks in [sys] sub packages for more system APIs.
+**/
+extern class Sys {
+
+	/**
+		Print any value on the standard output.
+	**/
+	static function print( v : Dynamic ) : Void;
+
+	/**
+		Print any value on the standard output, followed by a newline
+	**/
+	static function println( v : Dynamic ) : Void;
+
+	/**
+		Returns all the arguments that were passed by the commandline.
+	**/
+	static function args() : Array<String>;
+
+	/**
+		Returns the value of the given environment variable.
+	**/
+	static function getEnv( s : String ) : String;
+
+	/**
+		Set the value of the given environment variable.
+	**/
+	static function putEnv( s : String, v : String ) : Void;
+
+	/**
+		Returns the whole environement variables.
+	**/
+	static function environment() : Hash<String>;
+
+	/**
+		Suspend the current execution for the given time (in seconds).
+	**/
+	static function sleep( seconds : Float ) : Void;
+
+	/**
+		Change the current time locale, which will affect [DateTools.format] date formating.
+		Returns true if the locale was successfully changed
+	**/
+	static function setTimeLocale( loc : String ) : Bool;
+
+	/**
+		Get the current working directory (usually the one in which the program was started)
+	**/
+	static function getCwd() : String;
+
+	/**
+		Change the current working directory.
+	**/
+	static function setCwd( s : String ) : Void;
+
+	/**
+		Returns the name of the system you are running on. For instance :
+			"Windows", "Linux", "BSD" and "Mac" depending on your desktop OS.
+	**/
+	static function systemName() : String;
+
+	/**
+		Run the given command with the list of arguments. The command output will be printed on the same output as the current process.
+		The current process will block until the command terminates and it will return the command result (0 if there was no error).
+		Read the [sys.io.Process] api for a more complete way to start background processes.
+	**/
+	static function command( cmd : String, ?args : Array<String> ) : Int;
+
+	/**
+		Exit the current process with the given error code.
+	**/
+	static function exit( code : Int ) : Void;
+
+	/**
+		Gives the most precise timestamp value (in seconds).
+	**/
+	static function time() : Float;
+
+	/**
+		Gives the most precise timestamp value (in seconds) but only account for the actual time spent running on the CPU for the current thread/process.
+	**/
+	static function cpuTime() : Float;
+
+	/**
+		Returns the path to the current executable that we are running.
+	**/
+	static function executablePath() : String;
+
+	/**
+		Read a single input character from the standard input (without blocking) and returns it. Setting [echo] to true will also display it on the output.
+	**/
+	static function getChar( echo : Bool ) : Int;
+
+	/**
+		Returns the process standard input, from which you can read what user enters. Usually it will block until the user send a full input line. See [getChar] for an alternative.
+	**/
+	static function stdin() : haxe.io.Input;
+
+	/**
+		Returns the process standard output on which you can write.
+	**/
+	static function stdout() : haxe.io.Output;
+
+	/**
+		Returns the process standard error on which you can write.
+	**/
+	static function stderr() : haxe.io.Output;
+
+}

+ 0 - 104
std/cpp/Sys.hx

@@ -1,104 +0,0 @@
-package cpp;
-
-class Sys {
-
-	public static function args() : Array<String> untyped {
-		return __global__.__get_args();
-	}
-
-	public static function getEnv( s : String ):String {
-		var v = get_env(s);
-		if( v == null )
-			return null;
-		return v;
-	}
-
-	public static function putEnv( s : String, v : String ) {
-		put_env(s,v);
-	}
-
-	public static function sleep( seconds : Float ) {
-		_sleep(seconds);
-	}
-
-	public static function setTimeLocale( loc : String ) : Bool {
-		return set_time_locale(loc);
-	}
-
-	public static function getCwd() : String {
-		return new String(get_cwd());
-	}
-
-	public static function setCwd( s : String ) {
-		set_cwd(s);
-	}
-
-	public static function systemName() : String {
-		return sys_string();
-	}
-
-	public static function escapeArgument( arg : String ) : String {
-		var ok = true;
-		for( i in 0...arg.length )
-			switch( arg.charCodeAt(i) ) {
-			case 32, 34: // [space] "
-				ok = false;
-			case 0, 13, 10: // [eof] [cr] [lf]
-				arg = arg.substr(0,i);
-			}
-		if( ok )
-			return arg;
-		return '"'+arg.split('"').join('\\"')+'"';
-	}
-
-	public static function command( cmd : String, ?args : Array<String> ) : Int {
-		if( args != null ) {
-			cmd = escapeArgument(cmd);
-			for( a in args )
-				cmd += " "+escapeArgument(a);
-		}
-		return sys_command(cmd);
-	}
-
-	public static function exit( code : Int ) {
-		sys_exit(code);
-	}
-
-	public static function time() : Float {
-		return sys_time();
-	}
-
-	public static function cpuTime() : Float {
-		return sys_cpu_time();
-	}
-
-	public static function executablePath() : String {
-		return new String(sys_exe_path());
-	}
-
-	public static function environment() : Hash<String> {
-		var vars:Array<String> = sys_env();
-		var result = new Hash<String>();
-		var i = 0;
-		while(i<vars.length) {
-			result.set( vars[i], vars[i+1] );
-			i+=2;
-		}
-		return result;
-	}
-
-	private static var get_env = Lib.load("std","get_env",1);
-	private static var put_env = Lib.load("std","put_env",2);
-	private static var _sleep = Lib.load("std","sys_sleep",1);
-	private static var set_time_locale = Lib.load("std","set_time_locale",1);
-	private static var get_cwd = Lib.load("std","get_cwd",0);
-	private static var set_cwd = Lib.load("std","set_cwd",1);
-	private static var sys_string = Lib.load("std","sys_string",0);
-	private static var sys_command = Lib.load("std","sys_command",1);
-	private static var sys_exit = Lib.load("std","sys_exit",1);
-	private static var sys_time = Lib.load("std","sys_time",0);
-	private static var sys_cpu_time = Lib.load("std","sys_cpu_time",0);
-	private static var sys_exe_path = Lib.load("std","sys_exe_path",0);
-	private static var sys_env = Lib.load("std","sys_env",0);
-
-}

+ 157 - 0
std/cpp/_std/Sys.hx

@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2005-2012, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+@:core_api class Sys {
+
+	public static function print( v : Dynamic ) : Void {
+		untyped __global__.__hxcpp_print(v);
+	}
+
+	public static function println( v : Dynamic ) : Void {
+		print(v);
+		print("\n");
+	}
+
+	public static function stdin() : haxe.io.Input {
+		return untyped new sys.io.FileInput(file_stdin());
+	}
+
+	public static function stdout() : haxe.io.Output {
+		return untyped new sys.io.FileOutput(file_stdout());
+	}
+
+	public static function stderr() : haxe.io.Output {
+		return untyped new sys.io.FileOutput(file_stderr());
+	}
+
+	public static function getChar( echo : Bool ) : Int {
+		return getch(echo);
+	}
+
+	public static function args() : Array<String> untyped {
+		return __global__.__get_args();
+	}
+
+	public static function getEnv( s : String ):String {
+		var v = get_env(s);
+		if( v == null )
+			return null;
+		return v;
+	}
+
+	public static function putEnv( s : String, v : String ) : Void {
+		put_env(s,v);
+	}
+
+	public static function sleep( seconds : Float ) : Void {
+		_sleep(seconds);
+	}
+
+	public static function setTimeLocale( loc : String ) : Bool {
+		return set_time_locale(loc);
+	}
+
+	public static function getCwd() : String {
+		return new String(get_cwd());
+	}
+
+	public static function setCwd( s : String ) : Void {
+		set_cwd(s);
+	}
+
+	public static function systemName() : String {
+		return sys_string();
+	}
+
+	static function escapeArgument( arg : String ) : String {
+		var ok = true;
+		for( i in 0...arg.length )
+			switch( arg.charCodeAt(i) ) {
+			case 32, 34: // [space] "
+				ok = false;
+			case 0, 13, 10: // [eof] [cr] [lf]
+				arg = arg.substr(0,i);
+			}
+		if( ok )
+			return arg;
+		return '"'+arg.split('"').join('\\"')+'"';
+	}
+
+	public static function command( cmd : String, ?args : Array<String> ) : Int {
+		if( args != null ) {
+			cmd = escapeArgument(cmd);
+			for( a in args )
+				cmd += " "+escapeArgument(a);
+		}
+		return sys_command(cmd);
+	}
+
+	public static function exit( code : Int ) : Void {
+		sys_exit(code);
+	}
+
+	public static function time() : Float {
+		return sys_time();
+	}
+
+	public static function cpuTime() : Float {
+		return sys_cpu_time();
+	}
+
+	public static function executablePath() : String {
+		return new String(sys_exe_path());
+	}
+
+	public static function environment() : Hash<String> {
+		var vars:Array<String> = sys_env();
+		var result = new Hash<String>();
+		var i = 0;
+		while(i<vars.length) {
+			result.set( vars[i], vars[i+1] );
+			i+=2;
+		}
+		return result;
+	}
+
+	private static var get_env = cpp.Lib.load("std","get_env",1);
+	private static var put_env = cpp.Lib.load("std","put_env",2);
+	private static var _sleep = cpp.Lib.load("std","sys_sleep",1);
+	private static var set_time_locale = cpp.Lib.load("std","set_time_locale",1);
+	private static var get_cwd = cpp.Lib.load("std","get_cwd",0);
+	private static var set_cwd = cpp.Lib.load("std","set_cwd",1);
+	private static var sys_string = cpp.Lib.load("std","sys_string",0);
+	private static var sys_command = cpp.Lib.load("std","sys_command",1);
+	private static var sys_exit = cpp.Lib.load("std","sys_exit",1);
+	private static var sys_time = cpp.Lib.load("std","sys_time",0);
+	private static var sys_cpu_time = cpp.Lib.load("std","sys_cpu_time",0);
+	private static var sys_exe_path = cpp.Lib.load("std","sys_exe_path",0);
+	private static var sys_env = cpp.Lib.load("std","sys_env",0);
+
+	private static var file_stdin = cpp.Lib.load("std","file_stdin",0);
+	private static var file_stdout = cpp.Lib.load("std","file_stdout",0);
+	private static var file_stderr = cpp.Lib.load("std","file_stderr",0);
+
+	private static var getch = cpp.Lib.load("std","sys_getch",1);
+}

+ 22 - 41
std/cpp/io/File.hx → std/cpp/_std/sys/io/File.hx

@@ -22,22 +22,12 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  */
-package cpp.io;
+package sys.io;
 
-typedef FileHandle = Dynamic;
-
-enum FileSeek {
-	SeekBegin;
-	SeekCur;
-	SeekEnd;
-}
-
-/**
-	API for reading and writing to files.
-**/
+@:core_api
 class File {
 
-	public static function getContent( path : String ) {
+	public static function getContent( path : String ) : String {
 		var b = getBytes(path);
 		return b.toString();
 	}
@@ -47,19 +37,31 @@ class File {
 		return haxe.io.Bytes.ofData(data);
 	}
 
-	public static function read( path : String, binary : Bool = true ) {
-		return new FileInput(file_open(path,(if( binary ) "rb" else "r")));
+	public static function saveContent( path : String, content : String ) : Void {
+		var f = write(path);
+		f.writeString(content);
+		f.close();
+	}
+
+	public static function saveBytes( path : String, bytes : haxe.io.Bytes ) : Void {
+		var f = write(path);
+		f.write(bytes);
+		f.close();
+	}
+
+	public static function read( path : String, binary : Bool = true ) : FileInput {
+		return untyped new FileInput(file_open(path,(if( binary ) "rb" else "r")));
 	}
 
-	public static function write( path : String, binary : Bool = true ) {
-		return new FileOutput(file_open(path,(if( binary ) "wb" else "w")));
+	public static function write( path : String, binary : Bool = true ) : FileOutput {
+		return untyped new FileOutput(file_open(path,(if( binary ) "wb" else "w")));
 	}
 
-	public static function append( path : String, binary : Bool = true ) {
-		return new FileOutput(file_open(path,(if( binary ) "ab" else "a")));
+	public static function append( path : String, binary : Bool = true ) : FileOutput {
+		return untyped new FileOutput(file_open(path,(if( binary ) "ab" else "a")));
 	}
 
-	public static function copy( src : String, dst : String ) {
+	public static function copy( src : String, dst : String ) : Void {
 		var s = read(src,true);
 		var d = write(dst,true);
 		d.writeInput(s);
@@ -67,29 +69,8 @@ class File {
 		d.close();
 	}
 
-	public static function stdin() {
-		return new FileInput(file_stdin());
-	}
-
-	public static function stdout() {
-		return new FileOutput(file_stdout());
-	}
-
-	public static function stderr() {
-		return new FileOutput(file_stderr());
-	}
-
-	public static function getChar( echo : Bool ) : Int {
-		return getch(echo);
-	}
-
-	private static var file_stdin = cpp.Lib.load("std","file_stdin",0);
-	private static var file_stdout = cpp.Lib.load("std","file_stdout",0);
-	private static var file_stderr = cpp.Lib.load("std","file_stderr",0);
-
 	private static var file_contents = cpp.Lib.load("std","file_contents",1);
 	private static var file_open = cpp.Lib.load("std","file_open",2);
 
-	private static var getch = cpp.Lib.load("std","sys_getch",1);
 
 }

+ 7 - 9
std/cpp/io/FileInput.hx → std/cpp/_std/sys/io/FileInput.hx

@@ -22,17 +22,15 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  */
-package cpp.io;
-import cpp.io.File;
+package sys.io;
+import sys.io.FileSeek;
 
-/**
-	Use [cpp.io.File.read] to create a [FileInput]
-**/
+@:core_api
 class FileInput extends haxe.io.Input {
 
-	private var __f : FileHandle;
+	private var __f : Dynamic;
 
-	public function new(f) {
+	function new(f:Dynamic) : Void {
 		__f = f;
 	}
 
@@ -58,12 +56,12 @@ class FileInput extends haxe.io.Input {
 		}
 	}
 
-	public override function close() {
+	public override function close() : Void {
 		super.close();
 		file_close(__f);
 	}
 
-	public function seek( p : Int, pos : FileSeek ) {
+	public function seek( p : Int, pos : FileSeek ) : Void {
 		file_seek(__f,p,pos==SeekBegin ? 0 : pos==SeekCur ? 1 :  2 );
 	}
 

+ 9 - 11
std/cpp/io/FileOutput.hx → std/cpp/_std/sys/io/FileOutput.hx

@@ -22,21 +22,19 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  */
-package cpp.io;
-import cpp.io.File;
+package sys.io;
+import sys.io.FileSeek;
 
-/**
-	Use [cpp.io.File.write] to create a [FileOutput]
-**/
+@:core_api
 class FileOutput extends haxe.io.Output {
 
-	private var __f : FileHandle;
+	private var __f : Dynamic;
 
-	public function new(f) {
+	function new(f:Dynamic) : Void {
 		__f = f;
 	}
 
-	public override function writeByte( c : Int ) {
+	public override function writeByte( c : Int ) : Void {
 		try file_write_char(__f,c) catch( e : Dynamic ) throw haxe.io.Error.Custom(e);
 	}
 
@@ -44,16 +42,16 @@ class FileOutput extends haxe.io.Output {
 		return try file_write(__f,s.getData(),p,l) catch( e : Dynamic ) throw haxe.io.Error.Custom(e);
 	}
 
-	public override function flush() {
+	public override function flush() : Void {
 		file_flush(__f);
 	}
 
-	public override function close() {
+	public override function close() : Void {
 		super.close();
 		file_close(__f);
 	}
 
-	public function seek( p : Int, pos : FileSeek ) {
+	public function seek( p : Int, pos : FileSeek ) : Void {
 		file_seek(__f,p, pos == SeekBegin ? 0 : pos ==  SeekCur ? 1 : 2);
 	}
 

+ 8 - 3
std/cpp/io/Process.hx → std/cpp/_std/sys/io/Process.hx

@@ -22,7 +22,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  */
-package cpp.io;
+package sys.io;
 
 private class Stdin extends haxe.io.Output {
 
@@ -92,6 +92,7 @@ private class Stdout extends haxe.io.Input {
 
 }
 
+@:core_api
 class Process {
 
 	var p : Dynamic;
@@ -99,7 +100,7 @@ class Process {
 	public var stderr(default,null) : haxe.io.Input;
 	public var stdin(default,null) : haxe.io.Output;
 
-	public function new( cmd : String, args : Array<String> ) {
+	public function new( cmd : String, args : Array<String> ) : Void {
 		p = try _run(cmd,args) catch( e : Dynamic ) throw "Process creation failure : "+cmd;
 		stdin = new Stdin(p);
 		stdout = new Stdout(p,true);
@@ -114,10 +115,14 @@ class Process {
 		return _exit(p);
 	}
 
-	public function close() {
+	public function close() : Void {
 		_close(p);
 	}
 
+	public function kill() : Void {
+		throw "Not implemented";
+	}
+
 	static var _run = cpp.Lib.load("std","process_run",2);
 	static var _exit = cpp.Lib.load("std","process_exit",1);
 	static var _pid = cpp.Lib.load("std","process_pid",1);

+ 2 - 4
std/haxe/Timer.hx

@@ -83,10 +83,8 @@ class Timer {
 	public static function stamp() : Float {
 		#if flash
 			return flash.Lib.getTimer() / 1000;
-		#elseif neko
-			return neko.Sys.time();
-		#elseif php
-			return php.Sys.time();
+		#elseif (neko || php)
+			return Sys.time();
 		#elseif js
 			return Date.now().getTime() / 1000;
 		#elseif cpp

+ 2 - 2
std/haxe/macro/Compiler.hx

@@ -132,7 +132,7 @@ class Compiler {
 	**/
 	public static function excludeFile( fileName : String ) {
 		fileName = Context.resolvePath(fileName);
-		var f = neko.io.File.read(fileName,true);
+		var f = sys.io.File.read(fileName,true);
 		var classes = new Hash();
 		try {
 			while( true ) {
@@ -159,7 +159,7 @@ class Compiler {
 	**/
 	public static function patchTypes( file : String ) : Void {
 		var file = Context.resolvePath(file);
-		var f = neko.io.File.read(file, true);
+		var f = sys.io.File.read(file, true);
 		try {
 			while( true ) {
 				var r = StringTools.trim(f.readLine());

+ 1 - 3
std/haxe/macro/ExampleJSGenerator.hx

@@ -253,9 +253,7 @@ class ExampleJSGenerator {
 			genExpr(api.main);
 			newline();
 		}
-		var file = neko.io.File.write(api.outputFile, true);
-		file.writeString(buf.toString());
-		file.close();
+		sys.io.File.saveContent(api.outputFile, buf.toString());
 	}
 
 	#if macro

+ 1 - 1
std/haxe/macro/Tools.hx

@@ -23,7 +23,7 @@ class Tools {
 		default: null;
 		}
 		if( str == null ) Context.error("Should be a constant string", fileName.pos);
-		var f = try neko.io.File.getContent(Context.resolvePath(str)) catch( e : Dynamic ) Context.error(Std.string(e), fileName.pos);
+		var f = try sys.io.File.getContent(Context.resolvePath(str)) catch( e : Dynamic ) Context.error(Std.string(e), fileName.pos);
 		var p = Context.currentPos();
 		return { expr : EUntyped( { expr : ECall( { expr : EConst(CIdent("__js__")), pos : p }, [ { expr : EConst(CString(f)), pos : p } ]), pos : p } ), pos : p };
 	}

+ 166 - 138
std/neko/Sys.hx → std/neko/_std/Sys.hx

@@ -1,138 +1,166 @@
-/*
- * Copyright (c) 2005, The haXe Project Contributors
- * All rights reserved.
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *   - Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   - Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- */
-package neko;
-
-class Sys {
-
-	public static function args() : Array<String> untyped {
-		var a = __dollar__loader.args;
-		if( __dollar__typeof(a) != __dollar__tarray )
-			return [];
-		var r = new Array();
-		var i = 0;
-		var l = __dollar__asize(a);
-		while( i <  l ) {
-			if( __dollar__typeof(a[i]) == __dollar__tstring )
-				r.push(new String(a[i]));
-			i += 1;
-		}
-		return r;
-	}
-
-	public static function getEnv( s : String ) {
-		var v = get_env(untyped s.__s);
-		if( v == null )
-			return null;
-		return new String(v);
-	}
-
-	public static function putEnv( s : String, v : String ) {
-		untyped put_env(s.__s,if( v == null ) null else v.__s);
-	}
-
-	public static function sleep( seconds : Float ) {
-		_sleep(seconds);
-	}
-
-	public static function setTimeLocale( loc : String ) : Bool {
-		return set_time_locale(untyped loc.__s);
-	}
-
-	public static function getCwd() : String {
-		return new String(get_cwd());
-	}
-
-	public static function setCwd( s : String ) {
-		set_cwd(untyped s.__s);
-	}
-
-	public static function systemName() : String {
-		return new String(sys_string());
-	}
-
-	public static function escapeArgument( arg : String ) : String {
-		var ok = true;
-		for( i in 0...arg.length )
-			switch( arg.charCodeAt(i) ) {
-			case 32, 34: // [space] "
-				ok = false;
-			case 0, 13, 10: // [eof] [cr] [lf]
-				arg = arg.substr(0,i);
-			}
-		if( ok )
-			return arg;
-		return '"'+arg.split('"').join('\\"')+'"';
-	}
-
-	public static function command( cmd : String, ?args : Array<String> ) : Int {
-		if( args != null ) {
-			cmd = escapeArgument(cmd);
-			for( a in args )
-				cmd += " "+escapeArgument(a);
-		}
-		return sys_command(untyped cmd.__s);
-	}
-
-	public static function exit( code : Int ) {
-		sys_exit(code);
-	}
-
-	public static function time() : Float {
-		return sys_time();
-	}
-
-	public static function cpuTime() : Float {
-		return sys_cpu_time();
-	}
-
-	public static function executablePath() : String {
-		return new String(sys_exe_path());
-	}
-
-	public static function environment() : Hash<String> {
-		var l : Array<Dynamic> = sys_env();
-		var h = new Hash();
-		while( l != null ) {
-			h.set(new String(l[0]),new String(l[1]));
-			l = l[2];
-		}
-		return h;
-	}
-
-	private static var get_env = Lib.load("std","get_env",1);
-	private static var put_env = Lib.load("std","put_env",2);
-	private static var _sleep = Lib.load("std","sys_sleep",1);
-	private static var set_time_locale = Lib.load("std","set_time_locale",1);
-	private static var get_cwd = Lib.load("std","get_cwd",0);
-	private static var set_cwd = Lib.load("std","set_cwd",1);
-	private static var sys_string = Lib.load("std","sys_string",0);
-	private static var sys_command = Lib.load("std","sys_command",1);
-	private static var sys_exit = Lib.load("std","sys_exit",1);
-	private static var sys_time = Lib.load("std","sys_time",0);
-	private static var sys_cpu_time = Lib.load("std","sys_cpu_time",0);
-	private static var sys_exe_path = Lib.load("std","sys_exe_path",0);
-	private static var sys_env = Lib.load("std","sys_env",0);
-
-}
+/*
+ * Copyright (c) 2005-2012, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+@:core_api class Sys {
+
+	public static function print( v : Dynamic ) : Void {
+		untyped __dollar__print(v);
+	}
+
+	public static function println( v : Dynamic ) : Void {
+		untyped __dollar__print(v,"\n");
+	}
+
+	public static function getChar( echo : Bool ) : Int {
+		return getch(echo);
+	}
+
+	public static function stdin() : haxe.io.Input {
+		return untyped new sys.io.FileInput(file_stdin());
+	}
+
+	public static function stdout() : haxe.io.Output {
+		return untyped new sys.io.FileOutput(file_stdout());
+	}
+
+	public static function stderr() : haxe.io.Output {
+		return untyped new sys.io.FileOutput(file_stderr());
+	}
+
+	public static function args() : Array<String> untyped {
+		var a = __dollar__loader.args;
+		if( __dollar__typeof(a) != __dollar__tarray )
+			return [];
+		var r = new Array();
+		var i = 0;
+		var l = __dollar__asize(a);
+		while( i <  l ) {
+			if( __dollar__typeof(a[i]) == __dollar__tstring )
+				r.push(new String(a[i]));
+			i += 1;
+		}
+		return r;
+	}
+
+	public static function getEnv( s : String ) : String {
+		var v = get_env(untyped s.__s);
+		if( v == null )
+			return null;
+		return new String(v);
+	}
+
+	public static function putEnv( s : String, v : String ) : Void {
+		untyped put_env(s.__s,if( v == null ) null else v.__s);
+	}
+
+	public static function sleep( seconds : Float ) : Void {
+		_sleep(seconds);
+	}
+
+	public static function setTimeLocale( loc : String ) : Bool {
+		return set_time_locale(untyped loc.__s);
+	}
+
+	public static function getCwd() : String {
+		return new String(get_cwd());
+	}
+
+	public static function setCwd( s : String ) : Void {
+		set_cwd(untyped s.__s);
+	}
+
+	public static function systemName() : String {
+		return new String(sys_string());
+	}
+
+	static function escapeArgument( arg : String ) : String {
+		var ok = true;
+		for( i in 0...arg.length )
+			switch( arg.charCodeAt(i) ) {
+			case 32, 34: // [space] "
+				ok = false;
+			case 0, 13, 10: // [eof] [cr] [lf]
+				arg = arg.substr(0,i);
+			}
+		if( ok )
+			return arg;
+		return '"'+arg.split('"').join('\\"')+'"';
+	}
+
+	public static function command( cmd : String, ?args : Array<String> ) : Int {
+		if( args != null ) {
+			cmd = escapeArgument(cmd);
+			for( a in args )
+				cmd += " "+escapeArgument(a);
+		}
+		return sys_command(untyped cmd.__s);
+	}
+
+	public static function exit( code : Int ) : Void {
+		sys_exit(code);
+	}
+
+	public static function time() : Float {
+		return sys_time();
+	}
+
+	public static function cpuTime() : Float {
+		return sys_cpu_time();
+	}
+
+	public static function executablePath() : String {
+		return new String(sys_exe_path());
+	}
+
+	public static function environment() : Hash<String> {
+		var l : Array<Dynamic> = sys_env();
+		var h = new Hash();
+		while( l != null ) {
+			h.set(new String(l[0]),new String(l[1]));
+			l = l[2];
+		}
+		return h;
+	}
+
+	private static var get_env = neko.Lib.load("std","get_env",1);
+	private static var put_env = neko.Lib.load("std","put_env",2);
+	private static var _sleep = neko.Lib.load("std","sys_sleep",1);
+	private static var set_time_locale = neko.Lib.load("std","set_time_locale",1);
+	private static var get_cwd = neko.Lib.load("std","get_cwd",0);
+	private static var set_cwd = neko.Lib.load("std","set_cwd",1);
+	private static var sys_string = neko.Lib.load("std","sys_string",0);
+	private static var sys_command = neko.Lib.load("std","sys_command",1);
+	private static var sys_exit = neko.Lib.load("std","sys_exit",1);
+	private static var sys_time = neko.Lib.load("std","sys_time",0);
+	private static var sys_cpu_time = neko.Lib.load("std","sys_cpu_time",0);
+	private static var sys_exe_path = neko.Lib.load("std","sys_exe_path",0);
+	private static var sys_env = neko.Lib.load("std","sys_env",0);
+
+	private static var file_stdin = neko.Lib.load("std","file_stdin",0);
+	private static var file_stdout = neko.Lib.load("std","file_stdout",0);
+	private static var file_stderr = neko.Lib.load("std","file_stderr",0);
+	private static var getch = neko.Lib.load("std","sys_getch",1);
+
+}

+ 23 - 38
std/neko/io/File.hx → std/neko/_std/sys/io/File.hx

@@ -22,43 +22,49 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  */
-package neko.io;
+package sys.io;
 
 enum FileHandle {
 }
 
-enum FileSeek {
-	SeekBegin;
-	SeekCur;
-	SeekEnd;
-}
-
 /**
 	API for reading and writing to files.
 **/
-class File {
+@:core_api class File {
 
-	public static function getContent( path : String ) {
+	public static function getContent( path : String ) : String {
 		return new String(file_contents(untyped path.__s));
 	}
 
-	public static function getBytes( path : String ) {
+	public static function getBytes( path : String ) : haxe.io.Bytes {
 		return neko.Lib.bytesReference(getContent(path));
 	}
 
-	public static function read( path : String, binary : Bool = true ) {
-		return new FileInput(untyped file_open(path.__s,(if( binary ) "rb" else "r").__s));
+	public static function saveContent( path : String, content : String ) : Void {
+		var f = write(path);
+		f.writeString(content);
+		f.close();
+	}
+
+	public static function saveBytes( path : String, bytes : haxe.io.Bytes ) : Void {
+		var f = write(path);
+		f.write(bytes);
+		f.close();
 	}
 
-	public static function write( path : String, binary : Bool = true ) {
-		return new FileOutput(untyped file_open(path.__s,(if( binary ) "wb" else "w").__s));
+	public static function read( path : String, binary : Bool = true ) : FileInput {
+		return untyped new FileInput(file_open(path.__s,(if( binary ) "rb" else "r").__s));
 	}
 
-	public static function append( path : String, binary : Bool = true ) {
-		return new FileOutput(untyped file_open(path.__s,(if( binary ) "ab" else "a").__s));
+	public static function write( path : String, binary : Bool = true ) : FileOutput {
+		return untyped new FileOutput(file_open(path.__s,(if( binary ) "wb" else "w").__s));
 	}
 
-	public static function copy( src : String, dst : String ) {
+	public static function append( path : String, binary : Bool = true ) : FileOutput {
+		return untyped new FileOutput(file_open(path.__s,(if( binary ) "ab" else "a").__s));
+	}
+
+	public static function copy( src : String, dst : String ) : Void {
 		var s = read(src,true);
 		var d = write(dst,true);
 		d.writeInput(s);
@@ -66,29 +72,8 @@ class File {
 		d.close();
 	}
 
-	public static function stdin() {
-		return new FileInput(file_stdin());
-	}
-
-	public static function stdout() {
-		return new FileOutput(file_stdout());
-	}
-
-	public static function stderr() {
-		return new FileOutput(file_stderr());
-	}
-
-	public static function getChar( echo : Bool ) : Int {
-		return getch(echo);
-	}
-
-	private static var file_stdin = neko.Lib.load("std","file_stdin",0);
-	private static var file_stdout = neko.Lib.load("std","file_stdout",0);
-	private static var file_stderr = neko.Lib.load("std","file_stderr",0);
-
 	private static var file_contents = neko.Lib.load("std","file_contents",1);
 	private static var file_open = neko.Lib.load("std","file_open",2);
 
-	private static var getch = neko.Lib.load("std","sys_getch",1);
 
 }

+ 6 - 10
std/neko/io/FileInput.hx → std/neko/_std/sys/io/FileInput.hx

@@ -22,17 +22,13 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  */
-package neko.io;
-import neko.io.File;
+package sys.io;
 
-/**
-	Use [neko.io.File.read] to create a [FileInput]
-**/
-class FileInput extends haxe.io.Input {
+@:core_api class FileInput extends haxe.io.Input {
 
-	private var __f : FileHandle;
+	private var __f : File.FileHandle;
 
-	public function new(f) {
+	function new(f:File.FileHandle) : Void {
 		__f = f;
 	}
 
@@ -58,12 +54,12 @@ class FileInput extends haxe.io.Input {
 		}
 	}
 
-	public override function close() {
+	public override function close() : Void {
 		super.close();
 		file_close(__f);
 	}
 
-	public function seek( p : Int, pos : FileSeek ) {
+	public function seek( p : Int, pos : FileSeek ) : Void {
 		file_seek(__f,p,switch( pos ) { case SeekBegin: 0; case SeekCur: 1; case SeekEnd: 2; });
 	}
 

+ 8 - 12
std/neko/io/FileOutput.hx → std/neko/_std/sys/io/FileOutput.hx

@@ -22,21 +22,17 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  */
-package neko.io;
-import neko.io.File;
+package sys.io;
 
-/**
-	Use [neko.io.File.write] to create a [FileOutput]
-**/
-class FileOutput extends haxe.io.Output {
+@:core_api class FileOutput extends haxe.io.Output {
 
-	private var __f : FileHandle;
+	private var __f : File.FileHandle;
 
-	public function new(f) {
+	function new(f:File.FileHandle) : Void {
 		__f = f;
 	}
 
-	public override function writeByte( c : Int ) {
+	public override function writeByte( c : Int ) : Void {
 		try file_write_char(__f,c) catch( e : Dynamic ) throw haxe.io.Error.Custom(e);
 	}
 
@@ -44,16 +40,16 @@ class FileOutput extends haxe.io.Output {
 		return try file_write(__f,s.getData(),p,l) catch( e : Dynamic ) throw haxe.io.Error.Custom(e);
 	}
 
-	public override function flush() {
+	public override function flush() : Void {
 		file_flush(__f);
 	}
 
-	public override function close() {
+	public override function close() : Void {
 		super.close();
 		file_close(__f);
 	}
 
-	public function seek( p : Int, pos : FileSeek ) {
+	public function seek( p : Int, pos : FileSeek ) : Void {
 		file_seek(__f,p,switch( pos ) { case SeekBegin: 0; case SeekCur: 1; case SeekEnd: 2; });
 	}
 

+ 5 - 5
std/neko/io/Process.hx → std/neko/_std/sys/io/Process.hx

@@ -22,7 +22,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  */
-package neko.io;
+package sys.io;
 
 private class Stdin extends haxe.io.Output {
 
@@ -88,14 +88,14 @@ private class Stdout extends haxe.io.Input {
 
 }
 
-class Process {
+@:core_api class Process {
 
 	var p : Void;
 	public var stdout(default,null) : haxe.io.Input;
 	public var stderr(default,null) : haxe.io.Input;
 	public var stdin(default,null) : haxe.io.Output;
 
-	public function new( cmd : String, args : Array<String> ) {
+	public function new( cmd : String, args : Array<String> ) : Void {
 		p = try _run(untyped cmd.__s,neko.Lib.haxeToNeko(args)) catch( e : Dynamic ) throw "Process creation failure : "+cmd;
 		stdin = new Stdin(p);
 		stdout = new Stdout(p,true);
@@ -110,11 +110,11 @@ class Process {
 		return _exit(p);
 	}
 
-	public function close() {
+	public function close() : Void {
 		_close(p);
 	}
 
-	public function kill() {
+	public function kill() : Void {
 		_kill(p);
 	}
 

+ 9 - 9
std/neko/net/ProxyDetect.hx

@@ -70,7 +70,7 @@ class ProxyDetect {
 			}
 		if( profile == null )
 			return null;
-		var prefs = neko.io.File.getContent(basedir+"/"+profile+"/prefs.js");
+		var prefs = sys.io.File.getContent(basedir+"/"+profile+"/prefs.js");
 		// enabled ?
 		var r = ~/user_pref\("network\.proxy\.type", 1\);/;
 		if( !r.match(prefs) )
@@ -88,16 +88,16 @@ class ProxyDetect {
 	}
 
 	static function detectIE() {
-		var dir = neko.Sys.getEnv("TMP");
+		var dir = Sys.getEnv("TMP");
 		if( dir == null )
 			dir = ".";
 		var temp = dir + "/proxy.txt";
-		if( neko.Sys.command('regedit /E "'+temp+'" "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"') != 0 ) {
+		if( Sys.command('regedit /E "'+temp+'" "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"') != 0 ) {
 			// might fail without appropriate rights
 			return null;
 		}
 		// it's possible that if registry access was disabled the proxy file is not created
-		var content = try neko.io.File.getContent(temp) catch( e : Dynamic ) return null;
+		var content = try sys.io.File.getContent(temp) catch( e : Dynamic ) return null;
 		neko.FileSystem.deleteFile(temp);
 		// turn 16-bit string into 8-bit one
 		var b = new StringBuf();
@@ -153,7 +153,7 @@ class ProxyDetect {
 	}
 
 	static function detectOSX() {
-		var prefs = neko.io.File.getContent("/Library/Preferences/SystemConfiguration/preferences.plist");
+		var prefs = sys.io.File.getContent("/Library/Preferences/SystemConfiguration/preferences.plist");
 		var xml = Xml.parse(prefs).firstElement().firstElement(); // plist/dict
 		var data : Dynamic = parseOSXConfiguration(xml);
 		for( nsname in Reflect.fields(data.NetworkServices) ) {
@@ -165,10 +165,10 @@ class ProxyDetect {
 	}
 
 	static function detectAll() : ProxySettings {
-		switch( neko.Sys.systemName() ) {
+		switch( Sys.systemName() ) {
 		case "Windows":
 			try {
-				var ffdir = neko.Sys.getEnv("APPDATA")+"/Mozilla/Firefox/Profiles";
+				var ffdir = Sys.getEnv("APPDATA")+"/Mozilla/Firefox/Profiles";
 				var p = detectFF(ffdir);
 				if( p == null )
 					throw "No Firefox proxy";
@@ -180,10 +180,10 @@ class ProxyDetect {
 			var p = detectOSX();
 			if( p != null )
 				return p;
-			var ffdir = neko.Sys.getEnv("HOME")+"/Library/Application Support/Firefox/Profiles";
+			var ffdir = Sys.getEnv("HOME")+"/Library/Application Support/Firefox/Profiles";
 			return detectFF(ffdir);
 		case "Linux":
-			var ffdir = neko.Sys.getEnv("HOME")+"/.mozilla/firefox";
+			var ffdir = Sys.getEnv("HOME")+"/.mozilla/firefox";
 			return detectFF(ffdir);
 		default:
 			throw "This system is not supported";

+ 2 - 2
std/neko/net/ThreadServer.hx

@@ -57,11 +57,11 @@ class ThreadServer<Client,Message> {
 
 	public function new() {
 		threads = new Array();
-		nthreads = if( neko.Sys.systemName() == "Windows" ) 150 else 10;
+		nthreads = if( Sys.systemName() == "Windows" ) 150 else 10;
 		messageHeaderSize = 1;
 		listen = 10;
 		connectLag = 0.5;
-		errorOutput = neko.io.File.stderr();
+		errorOutput = Sys.stderr();
 		initialBufferSize = (1 << 10);
 		maxBufferSize = (1 << 16);
 		maxSockPerThread = 64;

+ 0 - 88
std/php/Sys.hx

@@ -1,88 +0,0 @@
-package php;
-
-
-class Sys {
-	public static function args() : Array<String> {
-		return untyped __call__('array_key_exists', 'argv', __var__('_SERVER')) ? __call__('new _hx_array', __call__('array_slice', __var__('_SERVER', 'argv'), 1)) : [];
-	}
-
-	public static function getEnv( s : String ) : String {
-		return untyped __call__("getenv", s);
-	}
-
-	public static function putEnv( s : String, v : String ) : Void {
-		return untyped __call__("putenv", s + "=" + v);
-	}
-
-	public static function sleep( seconds : Float ) {
-		return untyped __call__("usleep", seconds*1000000);
-	}
-
-	public static function setTimeLocale( loc : String ) : Bool {
-		return untyped __call__("setlocale", __php__("LC_TIME"), loc) != false;
-	}
-
-	public static function getCwd() : String {
-		var cwd : String = untyped __call__("getcwd");
-		var l = cwd.substr(-1);
-		return cwd + (l == '/' || l == '\\' ? '' : '/');
-	}
-
-	public static function setCwd( s : String ) {
-		return untyped __call__("chdir", s);
-	}
-
-	public static function systemName() : String {
-		var s : String = untyped __call__("php_uname", "s");
-		var p : Int;
-		if((p = s.indexOf(" ")) >= 0)
-			return s.substr(0, p);
-		else
-			return s;
-	}
-
-	public static function escapeArgument( arg : String ) : String {
-		var ok = true;
-		for( i in 0...arg.length )
-			switch( arg.charCodeAt(i) ) {
-			case 32, 34: // [space] "
-				ok = false;
-			case 0, 13, 10: // [eof] [cr] [lf]
-				arg = arg.substr(0,i);
-			}
-		if( ok )
-			return arg;
-		return '"'+arg.split('"').join('\\"')+'"';
-	}
-
-	public static function command( cmd : String, ?args : Array<String> ) : Int {
-		if( args != null ) {
-			cmd = escapeArgument(cmd);
-			for( a in args )
-				cmd += " "+escapeArgument(a);
-		}
-		var result = 0;
-		untyped __call__("system", cmd, result);
-		return result;
-	}
-
-	public static function exit( code : Int ) {
-		return untyped __call__("exit", code);
-	}
-
-	public static function time() : Float {
-		return untyped __call__("microtime", true);
-	}
-
-	public static function cpuTime() : Float {
-		return untyped __call__("microtime", true) - __php__("$_SERVER['REQUEST_TIME']");
-	}
-
-	public static function executablePath() : String {
-		return untyped __php__("$_SERVER['SCRIPT_FILENAME']");
-	}
-
-	public static function environment() : Hash<String> {
-		return Lib.hashOfAssociativeArray(untyped __php__("$_SERVER"));
-	}
-}

+ 140 - 0
std/php/_std/Sys.hx

@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2005-2012, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+@:core_api class Sys {
+
+	public static function print( v : Dynamic ) : Void {
+		untyped __call__("echo", Std.string(v));
+	}
+
+	public static function println( v : Dynamic ) : Void {
+		print(v);
+		print("\n");
+	}
+
+	public static function args() : Array<String> {
+		return untyped __call__('array_key_exists', 'argv', __var__('_SERVER')) ? __call__('new _hx_array', __call__('array_slice', __var__('_SERVER', 'argv'), 1)) : [];
+	}
+
+	public static function getEnv( s : String ) : String {
+		return untyped __call__("getenv", s);
+	}
+
+	public static function putEnv( s : String, v : String ) : Void {
+		return untyped __call__("putenv", s + "=" + v);
+	}
+
+	public static function sleep( seconds : Float ) : Void {
+		return untyped __call__("usleep", seconds*1000000);
+	}
+
+	public static function setTimeLocale( loc : String ) : Bool {
+		return untyped __call__("setlocale", __php__("LC_TIME"), loc) != false;
+	}
+
+	public static function getCwd() : String {
+		var cwd : String = untyped __call__("getcwd");
+		var l = cwd.substr(-1);
+		return cwd + (l == '/' || l == '\\' ? '' : '/');
+	}
+
+	public static function setCwd( s : String ) : Void {
+		untyped __call__("chdir", s);
+	}
+
+	public static function systemName() : String {
+		var s : String = untyped __call__("php_uname", "s");
+		var p : Int;
+		if((p = s.indexOf(" ")) >= 0)
+			return s.substr(0, p);
+		else
+			return s;
+	}
+
+	static function escapeArgument( arg : String ) : String {
+		var ok = true;
+		for( i in 0...arg.length )
+			switch( arg.charCodeAt(i) ) {
+			case 32, 34: // [space] "
+				ok = false;
+			case 0, 13, 10: // [eof] [cr] [lf]
+				arg = arg.substr(0,i);
+			}
+		if( ok )
+			return arg;
+		return '"'+arg.split('"').join('\\"')+'"';
+	}
+
+	public static function command( cmd : String, ?args : Array<String> ) : Int {
+		if( args != null ) {
+			cmd = escapeArgument(cmd);
+			for( a in args )
+				cmd += " "+escapeArgument(a);
+		}
+		var result = 0;
+		untyped __call__("system", cmd, result);
+		return result;
+	}
+
+	public static function exit( code : Int ) : Void {
+		untyped __call__("exit", code);
+	}
+
+	public static function time() : Float {
+		return untyped __call__("microtime", true);
+	}
+
+	public static function cpuTime() : Float {
+		return untyped __call__("microtime", true) - __php__("$_SERVER['REQUEST_TIME']");
+	}
+
+	public static function executablePath() : String {
+		return untyped __php__("$_SERVER['SCRIPT_FILENAME']");
+	}
+
+	public static function environment() : Hash<String> {
+		return php.Lib.hashOfAssociativeArray(untyped __php__("$_SERVER"));
+	}
+
+	public static function stdin() : haxe.io.Input {
+		return untyped new sys.io.FileInput(__call__('fopen', 'php://stdin', "r"));
+	}
+
+	public static function stdout() : haxe.io.Output {
+		return untyped new sys.io.FileOutput(__call__('fopen', 'php://stdout', "w"));
+	}
+
+	public static function stderr() : haxe.io.Output {
+		return untyped new sys.io.FileOutput(__call__('fopen', 'php://stderr', "w"));
+	}
+
+	public static function getChar( echo : Bool ) : Int {
+		var v : Int = untyped __call__("fgetc", __php__("STDIN"));
+		if(echo)
+			untyped __call__('echo', v);
+		return v;
+	}
+
+}

+ 2 - 2
std/php/_std/haxe/Resource.hx

@@ -47,11 +47,11 @@ class Resource {
 	}
 
 	public static function getString( name : String ) : String {
-		return php.io.File.getContent(getPath(name));
+		return sys.io.File.getContent(getPath(name));
 	}
 
 	public static function getBytes( name : String ) : haxe.io.Bytes {
-		return php.io.File.getBytes(getPath(name));
+		return sys.io.File.getBytes(getPath(name));
 	}
 
 }

+ 17 - 38
std/php/io/File.hx → std/php/_std/sys/io/File.hx

@@ -22,66 +22,45 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  */
-package php.io;
+package sys.io;
 
 enum FileHandle {
 }
 
-enum FileSeek {
-	SeekBegin;
-	SeekCur;
-	SeekEnd;
-}
-
-/**
-	API for reading and writing to files.
-**/
-class File {
+@:core_api class File {
 
 	public static function getContent( path : String ) : String {
 		return untyped __call__("file_get_contents", path);
 	}
 
-	public static function getBytes( path : String ) {
+	public static function getBytes( path : String ) : haxe.io.Bytes {
 		return haxe.io.Bytes.ofString(getContent(path));
 	}
 
-	public static function putContent( path : String, content : String) : Int {
-		return untyped __call__("file_put_contents", path, content);
+	public static function saveContent( path : String, content : String) : Void {
+		untyped __call__("file_put_contents", path, content);
 	}
 
-	public static function read( path : String, binary : Bool = true ) {
-		return new FileInput(untyped __call__('fopen', path, binary ? "rb" : "r"));
+	public static function saveBytes( path : String, bytes : haxe.io.Bytes ) : Void {
+		var f = write(path);
+		f.write(bytes);
+		f.close();
 	}
 
-	public static function write( path : String, binary : Bool = true ) {
-		return new FileOutput(untyped __call__('fopen', path, binary ? "wb" : "w"));
+	public static function read( path : String, binary : Bool = true ) : FileInput {
+		return untyped new FileInput(__call__('fopen', path, binary ? "rb" : "r"));
 	}
 
-	public static function append( path : String, binary : Bool = true ) {
-		return new FileOutput(untyped __call__('fopen', path, binary ? "ab" : "a"));
-	}
-
-	public static function copy( src : String, dst : String ) {
-		untyped __call__("copy", src, dst);
+	public static function write( path : String, binary : Bool = true ) : FileOutput {
+		return untyped new FileOutput(untyped __call__('fopen', path, binary ? "wb" : "w"));
 	}
 
-	public static function stdin() {
-		return new FileInput(untyped __call__('fopen', 'php://stdin', "r"));
+	public static function append( path : String, binary : Bool = true ) : FileOutput {
+		return untyped new FileOutput(untyped __call__('fopen', path, binary ? "ab" : "a"));
 	}
 
-	public static function stdout() {
-		return new FileOutput(untyped __call__('fopen', 'php://stdout', "w"));
-	}
-
-	public static function stderr() {
-		return new FileOutput(untyped __call__('fopen', 'php://stderr', "w"));
+	public static function copy( src : String, dst : String ) : Void {
+		untyped __call__("copy", src, dst);
 	}
 
-	public static function getChar( echo : Bool ) : Int {
-		var v : Int = untyped __call__("fgetc", __php__("STDIN"));
-		if(echo)
-			untyped __call__('echo', v);
-		return v;
-	}
 }

+ 10 - 9
std/php/io/FileInput.hx → std/php/_std/sys/io/FileInput.hx

@@ -22,18 +22,15 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  */
-package php.io;
+package sys.io;
 import haxe.io.Eof;
-import php.io.File;
 
-/**
-	Use [php.io.File.read] to create a [FileInput]
-**/
+@:core_api
 class FileInput extends haxe.io.Input {
 
-	private var __f : FileHandle;
+	private var __f : File.FileHandle;
 
-	public function new(f) {
+	function new(f:File.FileHandle) : Void {
 		__f = f;
 	}
 
@@ -53,12 +50,12 @@ class FileInput extends haxe.io.Input {
 		return r.length;
 	}
 
-	public override function close() {
+	public override function close() : Void {
 		super.close();
 		if(__f != null)	untyped __call__('fclose', __f);
 	}
 
-	public function seek( p : Int, pos : FileSeek ) {
+	public function seek( p : Int, pos : FileSeek ) : Void {
 		var w;
 		switch( pos ) {
 			case SeekBegin: w = untyped __php__('SEEK_SET');
@@ -75,6 +72,10 @@ class FileInput extends haxe.io.Input {
 		return cast r;
 	}
 
+	public function eof() : Bool {
+		return untyped __call__('feof', __f);
+	}
+
 	override function readLine() : String {
 		var r : String = untyped __call__('fgets', __f);
 		if (untyped __physeq__(false, r))

+ 10 - 17
std/php/io/FileOutput.hx → std/php/_std/sys/io/FileOutput.hx

@@ -22,23 +22,19 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  */
-package php.io;
-import php.io.File;
+package sys.io;
 
-/**
-	Use [php.io.File.write] to create a [FileOutput]
-**/
+@:core_api
 class FileOutput extends haxe.io.Output {
-	private var __f : FileHandle;
+	private var __f : File.FileHandle;
 
-	public function new(f) {
+	function new(f:File.FileHandle) : Void {
 		__f = f;
 	}
 
-	public override function writeByte( c : Int ) {
+	public override function writeByte( c : Int ) : Void {
 		var r = untyped __call__('fwrite', __f, __call__('chr', c));
-		if(untyped __physeq__(r, false)) return throw haxe.io.Error.Custom('An error occurred');
-		return r;
+		if(untyped __physeq__(r, false)) throw haxe.io.Error.Custom('An error occurred');
 	}
 
 	public override function writeBytes( b : haxe.io.Bytes, p : Int, l : Int ) : Int {
@@ -49,19 +45,19 @@ class FileOutput extends haxe.io.Output {
 		return r;
 	}
 
-	public override function flush() {
+	public override function flush() : Void {
 		var r = untyped __call__('fflush', __f);
 		if(untyped __physeq__(r, false)) throw haxe.io.Error.Custom('An error occurred');
 	}
 
-	public override function close() {
+	public override function close() : Void {
 		super.close();
 		if(__f != null)	untyped __call__('fclose', __f);
 	}
 
-	public function seek( p : Int, pos : FileSeek ) {
+	public function seek( p : Int, pos : FileSeek ) : Void {
 		var w;
-		switch( pos ) { 
+		switch( pos ) {
 			case SeekBegin: w = untyped __php__('SEEK_SET');
 			case SeekCur  : w = untyped __php__('SEEK_CUR');
 			case SeekEnd  : w = untyped __php__('SEEK_END');
@@ -76,7 +72,4 @@ class FileOutput extends haxe.io.Output {
 		return cast r;
 	}
 
-	public function eof() : Bool {
-		return untyped __call__('feof', __f);
-	}
 }

+ 12 - 7
std/php/io/Process.hx → std/php/_std/sys/io/Process.hx

@@ -22,7 +22,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  */
-package php.io;
+package sys.io;
 import php.NativeArray;
 
 private class Stdin extends haxe.io.Output {
@@ -79,6 +79,7 @@ private class Stdout extends haxe.io.Input {
 	}
 }
 
+@:core_api
 class Process {
 	var p : Void;
 	var st : NativeArray;
@@ -87,7 +88,7 @@ class Process {
 	public var stderr(default,null) : haxe.io.Input;
 	public var stdin(default,null) : haxe.io.Output;
 
-	public function new( cmd : String, args : Array<String> ) {
+	public function new( cmd : String, args : Array<String> ) : Void {
 		var pipes = untyped __call__("array");
 		var descriptorspec = untyped __php__("array(
 			array('pipe', 'r'),
@@ -100,8 +101,8 @@ class Process {
 		stdout = new Stdout(pipes[1]);
 		stderr = new Stdout(pipes[2]);
 	}
-	
-	public function close() {
+
+	public function close() : Void {
 		if(null == st)
 			st = untyped __call__('proc_get_status', p);
 		replaceStream(stderr);
@@ -109,7 +110,7 @@ class Process {
 		cl = untyped __call__('proc_close', p);
 	}
 
-	function sargs(args : Array<String>) {
+	function sargs(args : Array<String>) : String {
 		var b = '';
 		for(arg in args) {
 			arg = arg.split('"').join('\"');
@@ -125,7 +126,11 @@ class Process {
 		return r[untyped 'pid'];
 	}
 
-	function replaceStream(input : haxe.io.Input) {
+	public function kill() : Void {
+		untyped __call__('proc_terminate',p);
+	}
+
+	function replaceStream(input : haxe.io.Input) : Void {
 		var fp = untyped __call__("fopen", "php://memory", "r+");
 		while(true) {
 			var s = untyped __call__("fread", untyped input.p, 8192);
@@ -141,7 +146,7 @@ class Process {
 		{
 			st = untyped __call__('proc_get_status', p);
 			while(st[untyped 'running']) {
-				php.Sys.sleep(0.01);
+				Sys.sleep(0.01);
 				st = untyped __call__('proc_get_status', p);
 			}
 			close();

+ 0 - 1
std/php/db/PDO.hx

@@ -83,7 +83,6 @@ extern class PDOStatement
 }
 
 import php.Lib;
-import php.Sys;
 
 private class PDOConnection implements Connection {
 

+ 5 - 5
std/php/net/Socket.hx

@@ -26,9 +26,9 @@
  */
 package php.net;
 
-import php.io.File;
+import sys.io.File;
 
-typedef SocketHandle = php.io.FileHandle;
+typedef SocketHandle = FileHandle;
 
 class Socket {
 	private var __s : SocketHandle;
@@ -40,8 +40,8 @@ class Socket {
 
 	public function new( ?s ) {
 		__s = s;
-		input = new SocketInput(__s);
-		output = new SocketOutput(__s);
+		input = untyped new SocketInput(__s);
+		output = untyped new SocketOutput(__s);
 		protocol = "tcp";
 	}
 
@@ -151,7 +151,7 @@ class Socket {
 		s.protocol = "udp";
 		return s;
 	}
-	
+
 	public static function newSslSocket() {
 		var s = new Socket();
 		s.protocol = "ssl";

+ 1 - 1
std/php/net/SocketInput.hx

@@ -24,4 +24,4 @@
  */
 package php.net;
 
-typedef SocketInput = php.io.FileInput;
+typedef SocketInput = sys.io.FileInput;

+ 1 - 1
std/php/net/SocketOutput.hx

@@ -24,4 +24,4 @@
  */
 package php.net;
 
-typedef SocketOutput = php.io.FileOutput;
+typedef SocketOutput = sys.io.FileOutput;