Update Files

This commit is contained in:
2025-01-22 16:18:30 +01:00
parent ed4603cf95
commit a36294b518
16718 changed files with 2960346 additions and 0 deletions

View File

@ -0,0 +1,150 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko;
@:dox(hide)
@:keep
class Boot {
private static function __tmp_str() {
return untyped "<...>".__s;
}
private static function __enum_str(e:Dynamic) {
if (e.args == null)
return e.tag;
var s:String = e.tag + untyped "(".__s;
var i = 0;
var l = untyped __dollar__asize(e.args);
var old = e.__string;
e.__string = __tmp_str;
while (i < l) {
if (i != 0)
s += untyped ",".__s;
try {
s += untyped __dollar__string(e.args[i]);
} catch (err:Dynamic) {
s += __tmp_str();
}
i += 1;
}
e.__string = old;
return s + untyped ")".__s;
}
private static function __interfLoop(cc:Dynamic, cl:Dynamic) {
if (cc == null)
return false;
if (cc == cl)
return true;
var intf:Dynamic = cc.__interfaces__;
if (intf != null)
for (i in 0...intf.length) {
var i = intf[i];
if (i == cl || __interfLoop(i, cl))
return true;
}
return __interfLoop(cc.__super__, cl);
}
@:ifFeature("typed_catch")
private static function __instanceof(o:Dynamic, cl:Dynamic) {
untyped {
if (cl == Dynamic)
return o != null;
switch (__dollar__typeof(o)) {
case 1:
return (cl == Int || cl == Float);
case 2:
return cl == Float || (cl == Int && __dollar__int(o) == o);
case 3:
return cl == Bool;
case 5:
if (cl == null)
return false;
return __interfLoop(o.__class__, cl) || (o.__enum__ == cl) || (cl == Class && o.__name__ != null) || (cl == Enum && o.__ename__ != null);
default:
return false;
}
}
}
private static function __serialize(o) {
untyped {
if (o.__class__ != null) {
var n = o.__class__.__name__;
var x = __dollar__amake(n.length);
for (i in 0...n.length)
x[i] = n[i].__s;
return x;
}
if (o.__enum__ != null) {
var n = o.__enum__.__ename__;
var x = __dollar__amake(n.length);
for (i in 0...n.length)
x[i] = n[i].__s;
return x;
}
throw "Can't serialize";
}
}
private static function __tagserialize(o:Dynamic)
untyped {
var n = o.__enum__.__ename__;
var x = __dollar__amake(n.length + 1);
for (i in 0...n.length)
x[i] = n[i].__s;
x[n.length] = o.tag;
return x;
}
private static function __unserialize(v:Dynamic) {
untyped {
if (__dollar__typeof(v) != __dollar__tarray)
throw "Invalid serialized class data";
for (i in 0...__dollar__asize(v))
if (__dollar__typeof(v[i]) != __dollar__tstring)
throw "Invalid serialized class data";
var cl = neko.Boot.__classes;
for (i in 0...__dollar__asize(v)) {
cl = __dollar__objget(cl, __dollar__hash(v[i]));
if (cl == null)
throw("Class not found " + Std.string(v));
}
if (__dollar__typeof(cl) == __dollar__tobject) {
if (cl.__name__ != null || cl.__ename__ != null)
return cl.prototype;
if (cl.__enum__ != null && __dollar__typeof(cl.tag) == __dollar__tstring)
return cl;
}
throw "Invalid class " + Std.string(v);
}
}
private static function __init() {
untyped {
__dollar__exports.__unserialize = __unserialize;
__dollar__exports.__classes = neko.Boot.__classes;
}
}
}

View File

@ -0,0 +1,204 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko;
/**
Platform-specific Neko Library. Provides some platform-specific functions
for the Neko target, such as conversion from Haxe types to native types
and vice-versa.
**/
class Lib {
/**
Load and return a Neko primitive from a NDLL library.
**/
public static function load(lib:String, prim:String, nargs:Int):Dynamic {
return untyped __dollar__loader.loadprim((lib + "@" + prim).__s, nargs);
}
public static function loadLazy(lib, prim, nargs):Dynamic {
try {
return load(lib, prim, nargs);
} catch (e:Dynamic) {
return untyped __dollar__varargs(function(_) {
throw e;
});
}
}
/**
Print the specified value on the default output.
**/
public static function print(v:Dynamic):Void {
untyped __dollar__print(v);
}
/**
Print the specified value on the default output followed by a newline character.
**/
public static function println(v:Dynamic):Void {
untyped __dollar__print(v, "\n");
}
/**
Rethrow an exception. This is useful when manually filtering an exception in order
to keep the previous exception stack.
**/
public static function rethrow(e:Dynamic):Dynamic {
return untyped __dollar__rethrow(e);
}
/**
Serialize using native Neko serialization. This will return a Binary string that can be
stored for long term usage. The serialized data is optimized for speed and not for size.
**/
public static function serialize(v:Dynamic):haxe.io.Bytes {
return haxe.io.Bytes.ofData(__serialize(v));
}
/**
Unserialize a string using native Neko serialization. See `serialize`.
**/
public static function unserialize(s:haxe.io.Bytes):Dynamic {
return untyped __unserialize(s.getData(), __dollar__loader);
}
/**
Unserialize a string using native Neko serialization. See `serialize`.
This function assume that all the serialized data was serialized with current
module, even if the module name was different. This can happen if you are unserializing
some data into mod_neko that was serialized on a different server using a different
file path.
**/
public static function localUnserialize(s:haxe.io.Bytes):Dynamic {
return untyped __unserialize(s.getData(), {
loadmodule: function(m, l) {
return __dollar__exports;
},
loadprim: function(p, n) {
return __dollar__loader.loadprim(p, n);
}
});
}
/**
Converts a Neko value to its Haxe equivalent. Used for wrapping String and Arrays raw values into Haxe Objects.
**/
public static function nekoToHaxe(v:Dynamic):Dynamic
untyped {
switch (__dollar__typeof(v)) {
case 0:
return v;
case 1:
return v;
case 2:
return v;
case 3:
return v;
case 4:
return new String(v);
case 6:
var a = Array.new1(v, __dollar__asize(v));
for (i in 0...a.length)
a[i] = nekoToHaxe(a[i]);
return a;
case 5:
var f = __dollar__objfields(v);
var i = 0;
var l = __dollar__asize(f);
var o = __dollar__new(v);
if (__dollar__objgetproto(v) != null)
throw "Can't convert object prototype";
while (i < l) {
__dollar__objset(o, f[i], nekoToHaxe(__dollar__objget(v, f[i])));
i += 1;
}
return o;
default:
throw "Can't convert " + string(v);
}
}
/**
Converts a Haxe value to its Neko equivalent. Used to unwrap String and Arrays Objects into raw Neko values.
**/
public static function haxeToNeko(v:Dynamic):Dynamic
untyped {
switch (__dollar__typeof(v)) {
case 0:
return v;
case 1:
return v;
case 2:
return v;
case 3:
return v;
case 5:
var cl = v.__class__;
if (cl == String)
return v.__s;
if (cl == Array) {
var a = untyped __dollar__amake(v.length);
for (i in 0...v.length)
a[i] = haxeToNeko(v[i]);
return a;
}
if (cl != null || __dollar__objgetproto(v) != null)
throw "Can't convert " + string(v);
var f = __dollar__objfields(v);
var i = 0;
var l = __dollar__asize(f);
var o = __dollar__new(v);
while (i < l) {
__dollar__objset(o, f[i], haxeToNeko(__dollar__objget(v, f[i])));
i += 1;
}
return o;
default:
throw "Can't convert " + string(v);
}
}
/**
Returns an object containing all compiled packages and classes.
**/
public static function getClasses():Dynamic {
return untyped neko.Boot.__classes;
}
/**
Returns a string referencing the data contains in bytes.
**/
public inline static function stringReference(b:haxe.io.Bytes) {
return new String(cast b.getData());
}
/**
Returns bytes referencing the content of a string.
**/
public inline static function bytesReference(s:String):haxe.io.Bytes {
return untyped new haxe.io.Bytes(s.length, s.__s);
}
static var __serialize = load("std", "serialize", 1);
static var __unserialize = load("std", "unserialize", 2);
}

View File

@ -0,0 +1,53 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko;
class NativeArray<T> implements ArrayAccess<T> {
public static inline function alloc<T>(length:Int):NativeArray<T> {
return untyped __dollar__amake(length);
}
public static inline function blit<T>(dst:NativeArray<T>, dstPos:Int, src:NativeArray<T>, srcPos:Int, length:Int) {
untyped __dollar__ablit(dst, dstPos, src, srcPos, length);
}
public static inline function ofArrayCopy<T>(a:Array<T>):NativeArray<T> {
return untyped a.__neko();
}
public static inline function ofArrayRef<T>(a:Array<T>):NativeArray<T> {
return untyped a.__a;
}
public static inline function sub<T>(a:NativeArray<T>, pos:Int, len:Int):NativeArray<T> {
return untyped __dollar__asub(a, pos, len);
}
public static inline function toArray<T>(a:NativeArray<T>):Array<T> {
return untyped Array.new1(a, __dollar__asize(a));
}
public static inline function length(a:NativeArray<Dynamic>):Int {
return untyped __dollar__asize(a);
}
}

View File

@ -0,0 +1,41 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko;
class NativeString {
public static inline function ofString(s:String):NativeString {
return untyped s.__s;
}
public static inline function toString(s:NativeString):String {
return new String(cast s);
}
public static inline function length(s:NativeString):Int {
return untyped $ssize(s);
}
public static inline function alloc(size:Int):NativeString {
return untyped $smake(size);
}
}

View File

@ -0,0 +1,424 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko;
enum abstract XmlType(String) {}
typedef NativeXml = Xml;
class Xml {
public static var Element(default, never):XmlType;
public static var PCData(default, never):XmlType;
public static var CData(default, never):XmlType;
public static var Comment(default, never):XmlType;
public static var DocType(default, never):XmlType;
public static var ProcessingInstruction(default, never):XmlType;
public static var Document(default, never):XmlType;
public var nodeName(get, set):String;
public var nodeValue(get, set):String;
public var parent(get, null):Xml;
public var nodeType(default, null):XmlType;
private var _nodeName:String;
private var _nodeValue:String;
private var _attributes:Dynamic<String>;
private var _children:Array<Xml>;
private var _parent:Xml;
private function new():Void {}
private static var _parse = neko.Lib.load("std", "parse_xml", 2);
public static function parse(str:String):Xml {
var x = new Xml();
x._children = new Array();
var parser = {
cur: x,
add: function(x:Dynamic) {
untyped __this__.cur._children.push(x);
},
xml: function(name, att) {
var x:Dynamic = new Xml();
x._parent = untyped __this__.cur;
x.nodeType = Xml.Element;
x._nodeName = new String(name);
x._attributes = att;
x._children = new Array();
untyped {
var f = __dollar__objfields(att);
var i = 0;
var l = __dollar__asize(f);
while (i < l) {
__dollar__objset(att, f[i], new String(__dollar__objget(att, f[i])));
i++;
}
__this__.add(x);
__this__.cur = x;
}
},
cdata: function(text) {
var x:Dynamic = new Xml();
x._parent = untyped __this__.cur;
x.nodeType = Xml.CData;
x._nodeValue = new String(text);
untyped __this__.add(x);
},
pcdata: function(text) {
var x:Dynamic = new Xml();
x._parent = untyped __this__.cur;
x.nodeType = Xml.PCData;
x._nodeValue = new String(text);
untyped __this__.add(x);
},
comment: function(text) {
var x:Dynamic = new Xml();
x._parent = untyped __this__.cur;
if (untyped __dollar__sget(text, 0) == 63) {
x.nodeType = Xml.ProcessingInstruction;
text = new String(text);
text = text.substr(1, text.length - 2);
} else {
x.nodeType = Xml.Comment;
text = new String(text);
}
x._nodeValue = text;
untyped __this__.add(x);
},
doctype: function(text) {
var x:Dynamic = new Xml();
x._parent = untyped __this__.cur;
x.nodeType = Xml.DocType;
x._nodeValue = new String(text).substr(1);
var p:Xml = untyped __this__.cur;
p.addChild(x);
},
done: function() {
untyped __this__.cur = __this__.cur._parent;
}
};
untyped _parse(str.__s, parser);
x.nodeType = Xml.Document;
return x;
}
public static function createElement(name:String):Xml {
var r = new Xml();
r.nodeType = Xml.Element;
r._nodeName = name;
r._attributes = untyped __dollar__new(null);
r._children = new Array();
return r;
}
public static function createPCData(data:String):Xml {
var r = new Xml();
r.nodeType = Xml.PCData;
r._nodeValue = data;
return r;
}
public static function createCData(data:String):Xml {
var r = new Xml();
r.nodeType = Xml.CData;
r._nodeValue = data;
return r;
}
public static function createComment(data:String):Xml {
var r = new Xml();
r.nodeType = Xml.Comment;
r._nodeValue = data;
return r;
}
public static function createDocType(data:String):Xml {
var r = new Xml();
r.nodeType = Xml.DocType;
r._nodeValue = data;
return r;
}
public static function createProcessingInstruction(data:String):Xml {
var r = new Xml();
r.nodeType = Xml.ProcessingInstruction;
r._nodeValue = data;
return r;
}
public static function createDocument():Xml {
var r = new Xml();
r.nodeType = Xml.Document;
r._children = new Array();
return r;
}
private function get_nodeName():String {
if (nodeType != Xml.Element)
throw "bad nodeType";
return _nodeName;
}
private function set_nodeName(n:String):String {
if (nodeType != Xml.Element)
throw "bad nodeType";
return _nodeName = n;
}
private function get_nodeValue():String {
if (nodeType == Xml.Element || nodeType == Xml.Document)
throw "bad nodeType";
return _nodeValue;
}
private function set_nodeValue(v:String):String {
if (nodeType == Xml.Element || nodeType == Xml.Document)
throw "bad nodeType";
return _nodeValue = v;
}
private function get_parent():Xml {
return _parent;
}
public function get(att:String):String {
if (nodeType != Xml.Element)
throw "bad nodeType";
return Reflect.field(_attributes, att);
}
public function set(att:String, value:String):Void {
if (nodeType != Xml.Element)
throw "bad nodeType";
Reflect.setField(_attributes, att, value);
}
public function remove(att:String):Void {
if (nodeType != Xml.Element)
throw "bad nodeType";
Reflect.deleteField(_attributes, att);
}
public function exists(att:String):Bool {
if (nodeType != Xml.Element)
throw "bad nodeType";
return Reflect.hasField(_attributes, att);
}
public function attributes():Iterator<String> {
if (nodeType != Xml.Element)
throw "bad nodeType";
return Reflect.fields(_attributes).iterator();
}
public function iterator():Iterator<Xml> {
if (_children == null)
throw "bad nodetype";
return untyped {
cur: 0,
x: this._children,
hasNext: function() {
return __this__.cur < __this__.x.length;
},
next: function() {
return __this__.x[__this__.cur++];
}
}
}
public function elements():Iterator<Xml> {
if (_children == null)
throw "bad nodetype";
return untyped {
cur: 0,
x: this._children,
hasNext: function() {
var k = __this__.cur;
var l = __this__.x.length;
while (k < l) {
if (__this__.x[k].nodeType == Xml.Element)
break;
k += 1;
}
__this__.cur = k;
return k < l;
},
next: function() {
var k = __this__.cur;
var l = __this__.x.length;
while (k < l) {
var n = __this__.x[k];
k += 1;
if (n.nodeType == Xml.Element) {
__this__.cur = k;
return n;
}
}
return null;
}
}
}
public function elementsNamed(name:String):Iterator<Xml> {
if (_children == null)
throw "bad nodetype";
return untyped {
cur: 0,
x: this._children,
hasNext: function() {
var k = __this__.cur;
var l = __this__.x.length;
while (k < l) {
var n = __this__.x[k];
if (n.nodeType == Xml.Element && n._nodeName == name)
break;
k++;
}
__this__.cur = k;
return k < l;
},
next: function() {
var k = __this__.cur;
var l = __this__.x.length;
while (k < l) {
var n = __this__.x[k];
k++;
if (n.nodeType == Xml.Element && n._nodeName == name) {
__this__.cur = k;
return n;
}
}
return null;
}
}
}
public function firstChild():Xml {
if (_children == null)
throw "bad nodetype";
return _children[0];
}
public function firstElement():Xml {
if (_children == null)
throw "bad nodetype";
for (cur in 0..._children.length) {
var n = _children[cur];
if (n.nodeType == Xml.Element)
return n;
}
return null;
}
public function addChild(x:Xml):Void {
if (_children == null)
throw "bad nodetype";
if (x._parent != null)
x._parent._children.remove(x);
x._parent = this;
_children.push(x);
}
public function removeChild(x:Xml):Bool {
if (_children == null)
throw "bad nodetype";
var b = _children.remove(x);
if (b)
x._parent = null;
return b;
}
public function insertChild(x:Xml, pos:Int):Void {
if (_children == null)
throw "bad nodetype";
if (x._parent != null)
x._parent._children.remove(x);
x._parent = this;
_children.insert(pos, x);
}
public function toString():String {
var s = new StringBuf();
toStringRec(s);
return s.toString();
}
function toStringRec(s:StringBuf):Void {
switch (nodeType) {
case Xml.Document:
for (x in _children)
x.toStringRec(s);
case Xml.Element:
s.addChar("<".code);
s.add(_nodeName);
for (k in Reflect.fields(_attributes)) {
s.addChar(" ".code);
s.add(k);
s.addChar("=".code);
s.addChar("\"".code);
s.add(Reflect.field(_attributes, k));
s.addChar("\"".code);
}
if (_children.length == 0) {
s.addChar("/".code);
s.addChar(">".code);
return;
}
s.addChar(">".code);
for (x in _children)
x.toStringRec(s);
s.addChar("<".code);
s.addChar("/".code);
s.add(_nodeName);
s.addChar(">".code);
case Xml.PCData:
s.add(StringTools.htmlEscape(_nodeValue));
case Xml.CData:
s.add("<![CDATA[");
s.add(_nodeValue);
s.add("]]>");
case Xml.Comment:
s.add("<!--");
s.add(_nodeValue);
s.add("-->");
case Xml.DocType:
s.add("<!DOCTYPE ");
s.add(_nodeValue);
s.add(">");
case Xml.ProcessingInstruction:
s.add("<?");
s.add(_nodeValue);
s.add("?>");
}
}
static function __init__():Void
untyped {
Xml.Element = "element";
Xml.PCData = "pcdata";
Xml.CData = "cdata";
Xml.Comment = "comment";
Xml.DocType = "doctype";
Xml.ProcessingInstruction = "processingInstruction";
Xml.Document = "document";
}
}

View File

@ -0,0 +1,63 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko;
/**
A seeded pseudo-random generator.
**/
class Random {
var r:Dynamic;
/**
Create a new random with random seed.
**/
public function new() {
r = random_new();
}
/**
Set the generator seed.
**/
public function setSeed(s:Int) {
random_set_seed(r, s);
}
/**
Return a random integer modulo max.
**/
public function int(max:Int):Int {
return random_int(r, max);
}
/**
Return a random float.
**/
public function float():Float {
return random_float(r);
}
static var random_new = Lib.load("std", "random_new", 0);
static var random_set_seed = Lib.load("std", "random_set_seed", 2);
static var random_int = Lib.load("std", "random_int", 2);
static var random_float = Lib.load("std", "random_float", 1);
}

View File

@ -0,0 +1,106 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko;
@:coreApi
class Utf8 {
var __b:Dynamic;
public function new(?size:Int):Void {
__b = utf8_buf_alloc(if (size == null) 1 else size);
}
public function addChar(c:Int):Void {
utf8_buf_add(__b, c);
}
public function toString():String {
return new String(utf8_buf_content(__b));
}
public static function encode(s:String):String {
s = untyped s.__s;
var sl = untyped __dollar__ssize(s);
var buf:Dynamic = utf8_buf_alloc(sl);
var i = 0;
while (i < sl) {
utf8_buf_add(buf, untyped __dollar__sget(s, i));
i += 1;
}
return new String(utf8_buf_content(buf));
}
public static function decode(s:String):String {
s = untyped s.__s;
var sl = untyped __dollar__ssize(s);
var ret = untyped __dollar__smake(sl);
var i = 0;
utf8_iter(s, function(c) {
if (c == 8364) // euro symbol
c = 164;
else if (c == 0xFEFF) // BOM
return;
else if (c > 255)
throw "Utf8::decode invalid character (" + c + ")";
untyped __dollar__sset(ret, i, c);
i += 1;
});
return new String(untyped __dollar__ssub(ret, 0, i));
}
public static function iter(s:String, chars:Int->Void):Void {
utf8_iter(untyped s.__s, chars);
}
public static function charCodeAt(s:String, index:Int):Int {
return utf8_get(untyped s.__s, index);
}
public static function validate(s:String):Bool {
return utf8_validate(untyped s.__s);
}
public static function length(s:String):Int {
return utf8_length(untyped s.__s);
}
public static function compare(a:String, b:String):Int {
return utf8_compare(untyped a.__s, untyped b.__s);
}
public static function sub(s:String, pos:Int, len:Int):String {
return new String(utf8_sub(untyped s.__s, pos, len));
}
static var utf8_buf_alloc = neko.Lib.load("std", "utf8_buf_alloc", 1);
static var utf8_buf_add = neko.Lib.load("std", "utf8_buf_add", 2);
static var utf8_buf_content = neko.Lib.load("std", "utf8_buf_content", 1);
static var utf8_buf_length = neko.Lib.load("std", "utf8_buf_length", 1);
static var utf8_iter = neko.Lib.load("std", "utf8_iter", 2);
static var utf8_get = neko.Lib.load("std", "utf8_get", 2);
static var utf8_validate = neko.Lib.load("std", "utf8_validate", 1);
static var utf8_length = neko.Lib.load("std", "utf8_length", 1);
static var utf8_compare = neko.Lib.load("std", "utf8_compare", 2);
static var utf8_sub = neko.Lib.load("std", "utf8_sub", 3);
}

View File

@ -0,0 +1,409 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko;
import haxe.ds.List;
/**
This class is used for accessing the local Web server and the current
client request and information.
**/
class Web {
/**
Returns the GET and POST parameters.
**/
public static function getParams() {
var p = _get_params();
var h = new haxe.ds.StringMap<String>();
var k = "";
while (p != null) {
untyped k.__s = p[0];
h.set(k, new String(p[1]));
p = untyped p[2];
}
return h;
}
/**
Returns an Array of Strings built using GET / POST values.
If the URL contains the parameters `[a[]=foo;a[]=hello;a[5]=bar;a[3]=baz]` then
`neko.Web.getParamValues("a")` will return `["foo","hello",null,"baz",null,"bar"]`
**/
public static function getParamValues(param:String):Array<String> {
var reg = new EReg("^" + param + "(\\[|%5B)([0-9]*?)(\\]|%5D)=(.*?)$", "");
var res = new Array<String>();
var explore = function(data:String) {
if (data == null || data.length == 0)
return;
for (part in data.split("&")) {
if (reg.match(part)) {
var idx = reg.matched(2);
var val = StringTools.urlDecode(reg.matched(4));
if (idx == "")
res.push(val);
else
res[Std.parseInt(idx)] = val;
}
}
}
explore(StringTools.replace(getParamsString(), ";", "&"));
explore(getPostData());
if (res.length == 0)
return null;
return res;
}
/**
Returns the local server host name.
**/
public static function getHostName() {
return new String(_get_host_name());
}
/**
Surprisingly returns the client IP address.
**/
public static function getClientIP() {
return new String(_get_client_ip());
}
/**
Returns the original request URL (before any server internal redirections)
**/
public static function getURI() {
return new String(_get_uri());
}
/**
Tell the client to redirect to the given url ("Location" header)
**/
public static function redirect(url:String) {
_cgi_redirect(untyped url.__s);
}
/**
Set an output header value. If some data have been printed, the headers have
already been sent so this will raise an exception.
**/
public static function setHeader(h:String, v:String) {
_cgi_set_header(untyped h.__s, untyped v.__s);
}
/**
Set the HTTP return code. Same remark as setHeader.
**/
public static function setReturnCode(r:Int) {
_set_return_code(r);
}
/**
Retrieve a client header value sent with the request.
**/
public static function getClientHeader(k:String) {
var v = _get_client_header(untyped k.__s);
if (v == null)
return null;
return new String(v);
}
/**
Retrieve all the client headers.
**/
public static function getClientHeaders() {
var v = _get_client_headers();
var a = new List();
while (v != null) {
a.add({header: new String(v[0]), value: new String(v[1])});
v = cast v[2];
}
return a;
}
/**
Returns all the GET parameters String.
**/
public static function getParamsString() {
var p = _get_params_string();
return if (p == null) "" else new String(p);
}
/**
Returns all the POST data. POST Data is always parsed as
being `application/x-www-form-urlencoded` and is stored into
the getParams hashtable. POST Data is maximimized to 256K
unless the content type is `multipart/form-data`. In that
case, you will have to use `getMultipart` or `parseMultipart`
methods.
**/
public static function getPostData() {
var v = _get_post_data();
if (v == null)
return null;
return new String(v);
}
/**
Returns an hashtable of all Cookies sent by the client.
Modifying the hashtable will not modify the cookie, use `setCookie` instead.
**/
public static function getCookies():Map<String, String> {
var p = _get_cookies();
var h = new haxe.ds.StringMap<String>();
var k = "";
while (p != null) {
untyped k.__s = p[0];
h.set(k, new String(p[1]));
p = untyped p[2];
}
return h;
}
/**
Set a Cookie value in the HTTP headers. Same remark as `setHeader`.
**/
public static function setCookie(key:String, value:String, ?expire:Date, ?domain:String, ?path:String, ?secure:Bool, ?httpOnly:Bool) {
var buf = new StringBuf();
buf.add(value);
if (expire != null)
addPair(buf, "expires=", DateTools.format(expire, "%a, %d-%b-%Y %H:%M:%S GMT"));
addPair(buf, "domain=", domain);
addPair(buf, "path=", path);
if (secure)
addPair(buf, "secure", "");
if (httpOnly)
addPair(buf, "HttpOnly", "");
var v = buf.toString();
_set_cookie(untyped key.__s, untyped v.__s);
}
static function addPair(buf:StringBuf, name:String, value:String) {
if (value == null)
return;
buf.add("; ");
buf.add(name);
buf.add(value);
}
/**
Returns an object with the authorization sent by the client (Basic scheme only).
**/
public static function getAuthorization():{user:String, pass:String} {
var h = getClientHeader("Authorization");
var reg = ~/^Basic ([^=]+)=*$/;
if (h != null && reg.match(h)) {
var val = reg.matched(1);
untyped val = new String(_base_decode(val.__s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".__s));
var a = val.split(":");
if (a.length != 2) {
throw "Unable to decode authorization.";
}
return {user: a[0], pass: a[1]};
}
return null;
}
/**
Get the current script directory in the local filesystem.
**/
public static function getCwd() {
return new String(_get_cwd());
}
/**
Set the main entry point function used to handle requests.
Setting it back to null will disable code caching.
**/
public static function cacheModule(f:Void->Void) {
_set_main(f);
}
/**
Get the multipart parameters as an hashtable. The data
cannot exceed the maximum size specified.
**/
public static function getMultipart(maxSize:Int):Map<String, String> {
var h = new haxe.ds.StringMap();
var buf:haxe.io.BytesBuffer = null;
var curname = null;
parseMultipart(function(p, _) {
if (curname != null)
h.set(curname, neko.Lib.stringReference(buf.getBytes()));
curname = p;
buf = new haxe.io.BytesBuffer();
maxSize -= p.length;
if (maxSize < 0)
throw "Maximum size reached";
}, function(str, pos, len) {
maxSize -= len;
if (maxSize < 0)
throw "Maximum size reached";
buf.addBytes(str, pos, len);
});
if (curname != null)
h.set(curname, neko.Lib.stringReference(buf.getBytes()));
return h;
}
/**
Parse the multipart data. Call `onPart` when a new part is found
with the part name and the filename if present
and `onData` when some part data is read. You can this way
directly save the data on hard drive in the case of a file upload.
**/
public static function parseMultipart(onPart:String->String->Void, onData:haxe.io.Bytes->Int->Int->Void):Void {
_parse_multipart(function(p, f) {
onPart(new String(p), if (f == null) null else new String(f));
}, function(buf, pos, len) {
onData(untyped new haxe.io.Bytes(__dollar__ssize(buf), buf), pos, len);
});
}
/**
Flush the data sent to the client. By default on Apache, outgoing data is buffered so
this can be useful for displaying some long operation progress.
**/
public static function flush():Void {
_flush();
}
/**
Get the HTTP method used by the client. This API requires Neko 1.7.1+.
**/
public static function getMethod():String {
return new String(_get_http_method());
}
/**
Write a message into the web server log file. This API requires Neko 1.7.1+.
**/
public static function logMessage(msg:String) {
_log_message(untyped msg.__s);
}
public static var isModNeko(default, null):Bool;
public static var isTora(default, null):Bool;
static var _set_main:Dynamic;
static var _get_host_name:Dynamic;
static var _get_client_ip:Dynamic;
static var _get_uri:Dynamic;
static var _cgi_redirect:Dynamic;
static var _cgi_set_header:Dynamic;
static var _set_return_code:Dynamic;
static var _get_client_header:Dynamic;
static var _get_params_string:Dynamic;
static var _get_post_data:Dynamic;
static var _get_params:Dynamic;
static var _get_cookies:Dynamic;
static var _set_cookie:Dynamic;
static var _get_cwd:Dynamic;
static var _parse_multipart:Dynamic;
static var _flush:Dynamic;
static var _get_client_headers:Dynamic;
static var _get_http_method:Dynamic;
static var _base_decode = Lib.load("std", "base_decode", 2);
static var _log_message:Dynamic;
static function __init__() {
var get_env = Lib.load("std", "get_env", 1);
var ver = untyped get_env("MOD_NEKO".__s);
untyped isModNeko = (ver != null);
if (isModNeko) {
var lib = "mod_neko" + if (ver == untyped "1".__s) "" else ver;
_set_main = Lib.load(lib, "cgi_set_main", 1);
_get_host_name = Lib.load(lib, "get_host_name", 0);
_get_client_ip = Lib.load(lib, "get_client_ip", 0);
_get_uri = Lib.load(lib, "get_uri", 0);
_cgi_redirect = Lib.load(lib, "redirect", 1);
_cgi_set_header = Lib.load(lib, "set_header", 2);
_set_return_code = Lib.load(lib, "set_return_code", 1);
_get_client_header = Lib.load(lib, "get_client_header", 1);
_get_params_string = Lib.load(lib, "get_params_string", 0);
_get_post_data = Lib.load(lib, "get_post_data", 0);
_get_params = Lib.load(lib, "get_params", 0);
_get_cookies = Lib.load(lib, "get_cookies", 0);
_set_cookie = Lib.load(lib, "set_cookie", 2);
_get_cwd = Lib.load(lib, "cgi_get_cwd", 0);
_get_http_method = Lib.loadLazy(lib, "get_http_method", 0);
_parse_multipart = Lib.loadLazy(lib, "parse_multipart_data", 2);
_flush = Lib.loadLazy(lib, "cgi_flush", 0);
_get_client_headers = Lib.loadLazy(lib, "get_client_headers", 0);
_log_message = Lib.loadLazy(lib, "log_message", 1);
isTora = try Lib.load(lib, "tora_infos", 0) != null catch (e:Dynamic) false;
} else {
var a0 = untyped __dollar__loader.args[0];
if (a0 != null)
a0 = new String(a0);
_set_main = function(f) {};
_get_host_name = function() {
return untyped "localhost".__s;
};
_get_client_ip = function() {
return untyped "127.0.0.1".__s;
};
_get_uri = function() {
return untyped (if (a0 == null) "/" else a0).__s;
};
_cgi_redirect = function(v) {
Lib.print("Location: " + v + "\n");
};
_cgi_set_header = function(h, v) {};
_set_return_code = function(i) {};
_get_client_header = function(h) {
return null;
};
_get_client_headers = function() {
return null;
};
_get_params_string = function() {
return untyped (if (a0 == null) "" else a0).__s;
};
_get_post_data = function() {
return null;
};
_get_params = function() {
var l = null;
if (a0 == null)
return null;
for (p in a0.split(";")) {
var k = p.split("=");
if (k.length == 2)
l = untyped [k[0].__s, k[1].__s, l];
}
return l;
};
_get_cookies = function() {
return null;
}
_set_cookie = function(k, v) {};
_get_cwd = Lib.load("std", "get_cwd", 0);
_get_http_method = function() return untyped "GET".__s;
_parse_multipart = function(a, b) {
throw "Not supported";
};
_flush = function() {};
_log_message = function(s) {};
isTora = false;
}
}
}

View File

@ -0,0 +1,386 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
import haxe.iterators.ArrayKeyValueIterator;
@:coreApi final class Array<T> {
private var __a:neko.NativeArray<T>;
public var length(default, null):Int;
public function new():Void {
this.__a = neko.NativeArray.alloc(0);
this.length = 0;
}
private static function new1<T>(a:neko.NativeArray<T>, l:Int):Array<T> {
var inst = new Array<T>();
inst.__a = a;
inst.length = l;
return inst;
}
public function concat(a:Array<T>):Array<T> {
var a1 = this.__a;
var a2 = a.__a;
var s1 = this.length;
var s2 = a.length;
var a = neko.NativeArray.alloc(s1 + s2);
neko.NativeArray.blit(a, 0, a1, 0, s1);
neko.NativeArray.blit(a, s1, a2, 0, s2);
return new1(a, s1 + s2);
}
public function copy():Array<T> {
return new1(neko.NativeArray.sub(this.__a, 0, this.length), this.length);
}
public inline function iterator():haxe.iterators.ArrayIterator<T> {
return new haxe.iterators.ArrayIterator(this);
}
public inline function keyValueIterator():ArrayKeyValueIterator<T> {
return new ArrayKeyValueIterator(this);
}
public function insert(pos:Int, x:T):Void {
var l = this.length;
if (pos < 0) {
pos = l + pos;
if (pos < 0)
pos = 0;
}
if (pos > l)
pos = l;
this.__grow(l + 1);
var a = this.__a;
neko.NativeArray.blit(a, pos + 1, a, pos, l - pos);
a[pos] = x;
}
public function join(sep:String):String {
var s = new StringBuf();
var a = this.__a;
var max = this.length - 1;
for (p in 0...this.length) {
s.add(a[p]);
if (p != max)
s.add(sep);
}
return s.toString();
}
static var __hx_toString_depth = 0;
public function toString():String {
if (__hx_toString_depth >= 5) {
return "...";
}
var s = new StringBuf();
s.add("[");
var it = iterator();
__hx_toString_depth++;
try {
for (i in it) {
s.add(i);
if (it.hasNext())
s.addChar(",".code);
}
__hx_toString_depth--;
} catch (e:Dynamic) {
__hx_toString_depth--;
neko.Lib.rethrow(e);
}
s.add("]");
return s.toString();
}
public function pop():Null<T> {
if (this.length == 0)
return null;
this.length -= 1;
var x = this.__a[this.length];
this.__a[this.length] = null;
return x;
}
public function push(x:T):Int {
var l = this.length;
this.__grow(l + 1);
this.__a[l] = x;
return l + 1;
}
public function unshift(x:T):Void {
var l = this.length;
this.__grow(l + 1);
var a = this.__a;
neko.NativeArray.blit(a, 1, a, 0, l);
a[0] = x;
}
public function remove(x:T):Bool {
var i = 0;
var l = this.length;
var a = this.__a;
while (i < l) {
if (a[i] == x) {
neko.NativeArray.blit(a, i, a, i + 1, l - i - 1);
l -= 1;
this.length = l;
a[l] = null;
return true;
}
i += 1;
}
return false;
}
public function contains(x:T):Bool {
var i = 0;
var l = this.length;
var a = this.__a;
while (i < l) {
if (a[i] == x) {
return true;
}
i += 1;
}
return false;
}
public function indexOf(x:T, ?fromIndex:Int):Int {
var len = length;
var i:Int = (fromIndex != null) ? fromIndex : 0;
var a = __a;
if (i < 0) {
i += len;
if (i < 0)
i = 0;
}
while (i < len) {
if (a[i] == x)
return i;
i++;
}
return -1;
}
public function lastIndexOf(x:T, ?fromIndex:Int):Int {
var len = length;
var i:Int = (fromIndex != null) ? fromIndex : len - 1;
var a = __a;
if (i >= len)
i = len - 1;
else if (i < 0)
i += len;
while (i >= 0) {
if (a[i] == x)
return i;
i--;
}
return -1;
}
public function reverse():Void {
var i = 0;
var l = this.length;
var a = this.__a;
var half = l >> 1;
l -= 1;
while (i < half) {
var tmp = a[i];
a[i] = a[l - i];
a[l - i] = tmp;
i += 1;
}
}
public function shift():Null<T> {
var l = this.length;
if (l == 0)
return null;
var a = this.__a;
var x = a[0];
l -= 1;
neko.NativeArray.blit(a, 0, a, 1, l);
a[l] = null;
this.length = l;
return x;
}
public function slice(pos:Int, ?end:Int):Array<T> {
if (pos < 0) {
pos = this.length + pos;
if (pos < 0)
pos = 0;
}
if (end == null)
end = this.length;
else if (end < 0)
end = this.length + end;
if (end > this.length)
end = this.length;
var len = end - pos;
if (len < 0)
return new Array();
return new1(neko.NativeArray.sub(this.__a, pos, len), len);
}
public function sort(f:T->T->Int):Void {
var a = this.__a;
var i = 0;
var l = this.length;
while (i < l) {
var swap = false;
var j = 0;
var max = l - i - 1;
while (j < max) {
if (f(a[j], a[j + 1]) > 0) {
var tmp = a[j + 1];
a[j + 1] = a[j];
a[j] = tmp;
swap = true;
}
j += 1;
}
if (!swap)
break;
i += 1;
}
}
public function splice(pos:Int, len:Int):Array<T> {
if (len < 0)
return new Array();
if (pos < 0) {
pos = this.length + pos;
if (pos < 0)
pos = 0;
}
if (pos > this.length) {
pos = 0;
len = 0;
} else if (pos + len > this.length) {
len = this.length - pos;
if (len < 0)
len = 0;
}
var a = this.__a;
var ret = new1(neko.NativeArray.sub(a, pos, len), len);
var end = pos + len;
neko.NativeArray.blit(a, pos, a, end, this.length - end);
this.length -= len;
while (--len >= 0)
a[this.length + len] = null;
return ret;
}
public inline function map<S>(f:T->S):Array<S> {
var l = length;
var ret = new1(neko.NativeArray.alloc(l), l);
for (i in 0...l) {
ret[i] = f(this[i]);
}
return ret;
}
public inline function filter(f:T->Bool):Array<T> {
var ret = [];
for (elt in this)
if (f(elt))
ret.push(elt);
return ret;
}
public function resize(len:Int):Void {
if (length < len) {
__set(len - 1, null);
} else if (length > len) {
for (i in len...length) {
__a[i] = null;
}
this.length = len;
}
}
/* NEKO INTERNAL */
private function __get(pos:Int):T {
return this.__a[pos];
}
private function __set(pos:Int, v:T):T {
var a = this.__a;
if (this.length <= pos) {
var l = pos + 1;
var dlen = l - neko.NativeArray.length(a);
if (dlen > 0) {
if (dlen == 1) {
this.__grow(l);
a = this.__a;
} else {
a = neko.NativeArray.alloc(l);
neko.NativeArray.blit(a, 0, this.__a, 0, this.length);
this.__a = a;
}
}
this.length = l;
}
a[pos] = v;
return v;
}
private function __grow(l:Int):Void {
var a = this.__a;
var sz = neko.NativeArray.length(a);
if (sz >= l) {
this.length = l;
return;
}
var big = (sz * 3) >> 1;
if (big < l)
big = l;
var a2 = neko.NativeArray.alloc(big);
neko.NativeArray.blit(a2, 0, a, 0, this.length);
this.__a = a2;
this.length = l;
}
private function __neko():neko.NativeArray<T> {
var a = this.__a;
var sz = neko.NativeArray.length(a);
if (sz != this.length) {
a = neko.NativeArray.sub(a, 0, this.length);
this.__a = a;
}
return a;
}
#if !(macro || interp)
static function __init__():Void {
try {
var msort:Dynamic = neko.Lib.load("std", "merge_sort", 3);
untyped Array.prototype.sort = function(cmp) msort(__this__.__a, __this__.length, cmp);
} catch (e:Dynamic) {}
}
#end
}

View File

@ -0,0 +1,141 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
import neko.Lib;
@:coreApi final class Date {
private var __t:Dynamic;
public function new(year:Int, month:Int, day:Int, hour:Int, min:Int, sec:Int):Void {
__t = date_set_day(0, year, month + 1, day);
__t = date_set_hour(__t, hour, min, sec);
}
public function getTime():Float {
return int32_to_float(__t) * 1000;
}
public function getFullYear():Int {
return date_get_day(__t).y;
}
public function getMonth():Int {
return date_get_day(__t).m - 1;
}
public function getDate():Int {
return date_get_day(__t).d;
}
public function getHours():Int {
return date_get_hour(__t).h;
}
public function getMinutes():Int {
return date_get_hour(__t).m;
}
public function getSeconds():Int {
return date_get_hour(__t).s;
}
public function getDay():Int {
return Std.parseInt(new String(date_format(__t, untyped "%w".__s)));
}
public function getUTCFullYear():Int {
return date_get_utc_day(__t).y;
}
public function getUTCMonth():Int {
return date_get_utc_day(__t).m - 1;
}
public function getUTCDate():Int {
return date_get_utc_day(__t).d;
}
public function getUTCHours():Int {
return date_get_utc_hour(__t).h;
}
public function getUTCMinutes():Int {
return date_get_utc_hour(__t).m;
}
public function getUTCSeconds():Int {
return date_get_utc_hour(__t).s;
}
public function getUTCDay():Int {
return Std.parseInt(new String(date_utc_format(__t, untyped "%w".__s)));
}
public function getTimezoneOffset():Int {
return -date_get_tz(__t);
}
@:keep public function toString():String {
return new String(date_format(__t, null));
}
public static function now():Date {
return new1(date_now());
}
public static function fromTime(t:Float):Date {
t /= 1000;
var i1 = untyped __dollar__int((t % 65536));
var i2 = untyped __dollar__int(t / 65536);
var i = int32_add(i1, int32_shl(i2, 16));
return new1(i);
}
public static function fromString(s:String):Date {
return new1(date_new(untyped s.__s));
}
private static function new1(t:Dynamic):Date {
var d = new Date(2005, 1, 1, 0, 0, 0);
d.__t = t;
return d;
}
static var date_new = Lib.load("std", "date_new", 1);
static var date_now = Lib.load("std", "date_now", 0);
static var date_format = Lib.load("std", "date_format", 2);
static var date_utc_format = Lib.load("std", "date_utc_format", 2);
static var date_set_hour = Lib.load("std", "date_set_hour", 4);
static var date_set_day = Lib.load("std", "date_set_day", 4);
static var date_get_day:Dynamic->{y: Int, m: Int, d: Int} = Lib.load("std", "date_get_day", 1);
static var date_get_hour:Dynamic->{h: Int, m: Int, s: Int} = Lib.load("std", "date_get_hour", 1);
static var date_get_utc_day:Dynamic->{y: Int, m: Int, d: Int} = Lib.load("std", "date_get_utc_day", 1);
static var date_get_utc_hour:Dynamic->{h: Int, m: Int, s: Int} = Lib.load("std", "date_get_utc_hour", 1);
static var date_get_tz = Lib.load("std", "date_get_tz", 1);
static var int32_to_float = Lib.load("std", "int32_to_float", 1);
static var int32_add = Lib.load("std", "int32_add", 2);
static var int32_shl = Lib.load("std", "int32_shl", 2);
@:keep static function __string():String {
return untyped "Date".__s;
}
}

View File

@ -0,0 +1,209 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
@:coreApi final class EReg {
var r:Dynamic;
var last:String;
var global:Bool;
public function new(r:String, opt:String):Void {
var a = opt.split("g");
global = a.length > 1;
if (global)
opt = a.join("");
this.r = regexp_new_options(untyped r.__s, untyped opt.__s);
}
public function match(s:String):Bool {
var p = regexp_match(r, untyped s.__s, 0, s.length);
if (p)
last = s;
else
last = null;
return p;
}
public function matched(n:Int):String {
var m = regexp_matched(r, n);
return (m == null) ? null : new String(m);
}
public function matchedLeft():String {
var p = regexp_matched_pos(r, 0);
return last.substr(0, p.pos);
}
public function matchedRight():String {
var p = regexp_matched_pos(r, 0);
var sz = p.pos + p.len;
return last.substr(sz, last.length - sz);
}
public function matchedPos():{pos:Int, len:Int} {
return regexp_matched_pos(r, 0);
}
public function matchSub(s:String, pos:Int, len:Int = -1):Bool {
var p = regexp_match(r, untyped s.__s, pos, len < 0 ? s.length - pos : len);
if (p)
last = s;
else
last = null;
return p;
}
public function split(s:String):Array<String> {
var pos = 0;
var len = s.length;
var a = new Array();
var first = true;
do {
if (!regexp_match(r, untyped s.__s, pos, len))
break;
var p = regexp_matched_pos(r, 0);
if (p.len == 0 && !first) {
if (p.pos == s.length)
break;
p.pos += 1;
}
a.push(s.substr(pos, p.pos - pos));
var tot = p.pos + p.len - pos;
pos += tot;
len -= tot;
first = false;
} while (global);
a.push(s.substr(pos, len));
return a;
}
public function replace(s:String, by:String):String {
var b = new StringBuf();
var pos = 0;
var len = s.length;
var a = by.split("$");
var first = true;
do {
if (!regexp_match(r, untyped s.__s, pos, len))
break;
var p = regexp_matched_pos(r, 0);
if (p.len == 0 && !first) {
if (p.pos == s.length)
break;
p.pos += 1;
}
b.addSub(s, pos, p.pos - pos);
if (a.length > 0)
b.add(a[0]);
var i = 1;
while (i < a.length) {
var k = a[i];
var c = k.charCodeAt(0);
// 1...9
if (c >= 49 && c <= 57) {
var p = try regexp_matched_pos(r, Std.int(c) - 48) catch (e:String) null;
if (p == null) {
b.add("$");
b.add(k);
} else {
if (p.pos >= 0)
b.addSub(s, p.pos, p.len);
b.addSub(k, 1, k.length - 1);
}
} else if (c == null) {
b.add("$");
i++;
var k2 = a[i];
if (k2 != null && k2.length > 0)
b.add(k2);
} else
b.add("$" + k);
i++;
}
var tot = p.pos + p.len - pos;
pos += tot;
len -= tot;
first = false;
} while (global);
b.addSub(s, pos, len);
return b.toString();
}
// public function map( s : String, f : EReg -> String ) : String {
// var b = new StringBuf();
// var pos = 0;
// var len = s.length;
// var first = true;
// last = s;
// do {
// if( !regexp_match(r,untyped s.__s,pos,len) )
// break;
// var p = regexp_matched_pos(r,0);
// if( p.len == 0 && !first ) {
// if( p.pos == s.length )
// break;
// p.pos += 1;
// }
// b.addSub(s,pos,p.pos-pos);
// b.add(f(this));
// var tot = p.pos + p.len - pos;
// pos += tot;
// len -= tot;
// first = false;
// } while( global );
// b.addSub(s,pos,len);
// return b.toString();
// }
public function map(s:String, f:EReg->String):String {
var offset = 0;
var buf = new StringBuf();
do {
if (offset >= s.length)
break;
else if (!matchSub(s, offset)) {
buf.add(s.substr(offset));
break;
}
var p = regexp_matched_pos(r, 0);
buf.add(s.substr(offset, p.pos - offset));
buf.add(f(this));
if (p.len == 0) {
buf.add(s.substr(p.pos, 1));
offset = p.pos + 1;
} else
offset = p.pos + p.len;
} while (global);
if (!global && offset > 0 && offset < s.length)
buf.add(s.substr(offset));
return buf.toString();
}
public static function escape(s:String):String {
return escapeRegExpRe.map(s, function(r) return "\\" + r.matched(0));
}
static var escapeRegExpRe = ~/[\[\]{}()*+?.\\\^$|]/g;
static var regexp_new_options = neko.Lib.load("regexp", "regexp_new_options", 2);
static var regexp_match = neko.Lib.load("regexp", "regexp_match", 4);
static var regexp_matched = neko.Lib.load("regexp", "regexp_matched", 2);
static var regexp_matched_pos:Dynamic->Int->{pos: Int, len: Int} = neko.Lib.load("regexp", "regexp_matched_pos", 2);
}

View File

@ -0,0 +1,110 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
import neko.Lib;
@:native("Math")
@:keep
private class MathImpl {
static var __rnd:Dynamic;
static var _rand_float = Lib.load("std", "random_float", 1);
static var _rand_int = Lib.load("std", "random_int", 2);
public static function min(a:Float, b:Float):Float {
return if (a < b) a else if (untyped $isnan(a)) a else b;
}
public static function max(a:Float, b:Float):Float {
return if (a < b) b else if (untyped $isnan(b)) b else a;
}
public static function random():Float {
return _rand_float(__rnd);
}
public static function isNaN(f:Float):Bool {
return untyped __dollar__isnan(f);
}
public static function isFinite(f:Float):Bool {
return !untyped (__dollar__isinfinite(f) || __dollar__isnan(f));
}
static function __init__():Void {
var M:Dynamic = MathImpl;
__rnd = Lib.load("std", "random_new", 0)();
M.PI = Lib.load("std", "math_pi", 0)();
M.NaN = 0.0 / 0.0;
M.POSITIVE_INFINITY = 1.0 / 0.0;
M.NEGATIVE_INFINITY = -M.POSITIVE_INFINITY;
M.abs = Lib.load("std", "math_abs", 1);
M.sin = Lib.load("std", "math_sin", 1);
M.cos = Lib.load("std", "math_cos", 1);
M.atan2 = Lib.load("std", "math_atan2", 2);
M.tan = Lib.load("std", "math_tan", 1);
M.exp = Lib.load("std", "math_exp", 1);
M.log = Lib.load("std", "math_log", 1);
M.sqrt = Lib.load("std", "math_sqrt", 1);
M.round = Lib.load("std", "math_round", 1);
M.floor = Lib.load("std", "math_floor", 1);
M.ceil = Lib.load("std", "math_ceil", 1);
M.atan = Lib.load("std", "math_atan", 1);
M.asin = Lib.load("std", "math_asin", 1);
M.acos = Lib.load("std", "math_acos", 1);
M.pow = Lib.load("std", "math_pow", 2);
M.fceil = try Lib.load("std", "math_fceil", 1) catch (e:Dynamic) M.ceil;
M.ffloor = try Lib.load("std", "math_ffloor", 1) catch (e:Dynamic) M.floor;
M.fround = try Lib.load("std", "math_fround", 1) catch (e:Dynamic) M.round;
}
}
@:coreApi
extern final class Math {
public static var PI(default, null):Float;
public static var NaN(default, null):Float;
public static var POSITIVE_INFINITY(default, null):Float;
public static var NEGATIVE_INFINITY(default, null):Float;
public static function min(a:Float, b:Float):Float;
public static function max(a:Float, b:Float):Float;
public static function abs(v:Float):Float;
public static function sin(v:Float):Float;
public static function cos(v:Float):Float;
public static function atan2(y:Float, x:Float):Float;
public static function tan(v:Float):Float;
public static function exp(v:Float):Float;
public static function log(v:Float):Float;
public static function sqrt(v:Float):Float;
public static function round(v:Float):Int;
public static function floor(v:Float):Int;
public static function ceil(v:Float):Int;
public static function atan(v:Float):Float;
public static function asin(v:Float):Float;
public static function acos(v:Float):Float;
public static function pow(v:Float, exp:Float):Float;
public static function fround(v:Float):Float;
public static function ffloor(v:Float):Float;
public static function fceil(v:Float):Float;
public static function random():Float;
public static function isNaN(f:Float):Bool;
public static function isFinite(f:Float):Bool;
}

View File

@ -0,0 +1,136 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
@:coreApi class Reflect {
public static function hasField(o:Dynamic, field:String):Bool
untyped {
return $typeof(o) == $tobject && $objfield(o, $fasthash(field.__s));
}
public inline static function field(o:Dynamic, field:String):Dynamic
untyped {
return if ($typeof(o) != $tobject) null else $objget(o, $fasthash(field.__s));
}
public inline static function setField(o:Dynamic, field:String, value:Dynamic):Void
untyped {
if ($typeof(o) == $tobject)
$objset(o, $hash(field.__s), value);
}
public static inline function getProperty(o:Dynamic, field:String):Dynamic
untyped {
var tmp;
return if ($typeof(o) != $tobject) null else if (o.__properties__ != null
&& (tmp = $objget(o.__properties__, $fasthash("get_".__s + field.__s))) != null) $call($objget(o, $fasthash(tmp)), o, $array()) else $objget(o,
$fasthash(field.__s));
}
public static inline function setProperty(o:Dynamic, field:String, value:Dynamic):Void
untyped {
if ($typeof(o) == $tobject) {
var tmp;
if (o.__properties__ != null && (tmp = $objget(o.__properties__, $fasthash("set_".__s + field.__s))) != null)
$call($objget(o, $fasthash(tmp)), o, $array(value))
else
$objset(o, $hash(field.__s), value);
}
}
public static function callMethod(o:Dynamic, func:haxe.Constraints.Function, args:Array<Dynamic>):Dynamic
untyped {
var a = args.__neko();
// pad missing args with null's
var n = $nargs(func);
if (n > $asize(a)) {
var a2 = $amake(n);
$ablit(a2, 0, a, 0, $asize(a));
a = a2;
}
return $call(func, o, a);
}
public static function fields(o:Dynamic):Array<String>
untyped {
if ($typeof(o) != $tobject)
return new Array<String>();
else {
var a:neko.NativeArray<Int> = $objfields(o);
var i = 0;
var hasid = false;
var l = $asize(a);
while (i < l) {
var fid = a[i];
if (fid == -190054693)
hasid = true; // $hash("__id__")
a[i] = new String($field(fid));
i++;
}
var a:Array<String> = Array.new1(a, l);
if (hasid)
a.remove("__id__");
return a;
}
}
public static function isFunction(f:Dynamic):Bool
untyped {
return $typeof(f) == $tfunction;
}
public inline static function compare<T>(a:T, b:T):Int {
return untyped $compare(a, b);
}
public inline static function compareMethods(f1:Dynamic, f2:Dynamic):Bool {
return same_closure(f1, f2);
}
public static function isObject(v:Dynamic):Bool
untyped {
return $typeof(v) == $tobject && v.__enum__ == null;
}
public static function isEnumValue(v:Dynamic):Bool
untyped {
return $typeof(v) == $tobject && v.__enum__ != null;
}
public inline static function deleteField(o:Dynamic, field:String):Bool
untyped {
return $objremove(o, $fasthash(field.__s));
}
public static function copy<T>(o:Null<T>):Null<T> {
if (o == null)
return null;
return untyped $new(o);
}
@:overload(function(f:Array<Dynamic>->Void):Dynamic {})
public static function makeVarArgs(f:Array<Dynamic>->Dynamic):Dynamic {
return untyped $varargs(function(a) {
return f(Array.new1(a, $asize(a)));
});
}
static var same_closure = try neko.Lib.load("std", "same_closure", 2) catch (e:Dynamic) function(f1, f2) return f1 == f2;
}

View File

@ -0,0 +1,94 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
@:coreApi class Std {
@:ifFeature("typed_cast")
@:deprecated('Std.is is deprecated. Use Std.isOfType instead.')
public static inline function is(v:Dynamic, t:Dynamic):Bool {
return isOfType(v, t);
}
public static function isOfType(v:Dynamic, t:Dynamic):Bool {
return untyped neko.Boot.__instanceof(v, t);
}
public static function downcast<T:{}, S:T>(value:T, c:Class<S>):S {
return Std.isOfType(value, c) ? cast value : null;
}
@:deprecated('Std.instance() is deprecated. Use Std.downcast() instead.')
public static function instance<T:{}, S:T>(value:T, c:Class<S>):S {
return inline downcast(value, c);
}
public static function string(s:Dynamic):String {
return new String(untyped __dollar__string(s));
}
public static function int(x:Float):Int {
if (x < 0)
return Math.ceil(x);
return Math.floor(x);
}
public static function parseInt(x:String):Null<Int>
untyped {
var t = __dollar__typeof(x);
if (t == __dollar__tint)
return x;
if (t == __dollar__tfloat)
return __dollar__int(x);
if (t != __dollar__tobject)
return null;
return __dollar__int(x.__s);
}
public static function parseFloat(x:String):Float
untyped {
if (x == null)
return Math.NaN;
var t = __dollar__float(x.__s);
if (t == null)
t = Math.NaN;
return t;
}
public static function random(x:Int):Int {
return untyped Math._rand_int(Math.__rnd, x);
}
static function __init__():Void
untyped {
Int = {__name__: ["Int"]};
Float = {__name__: ["Float"]};
Bool = {__ename__: ["Bool"]};
Dynamic = {__name__: ["Dynamic"]};
Class = {__name__: ["Class"]};
Enum = {};
var cl = neko.Boot.__classes;
cl.Int = Int;
cl.Float = Float;
cl.Bool = Bool;
cl.Dynamic = Dynamic;
cl.Class = Class;
cl.Enum = Enum;
}
}

View File

@ -0,0 +1,221 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
@:coreApi final class String {
static var __is_String = true;
private static var __split:Dynamic = neko.Lib.load("std", "string_split", 2);
static function __init__():Void {
__is_String = true;
}
public var length(default, null):Int;
public function new(string:String):Void {
untyped {
if (__dollar__typeof(string) != __dollar__tstring)
string = __dollar__string(string);
this.__s = string;
this.length = __dollar__ssize(string);
}
}
public function charAt(index:Int):String {
untyped {
try {
var s = __dollar__smake(1);
__dollar__sset(s, 0, __dollar__sget(this.__s, index));
return new String(s);
} catch (e:Dynamic) {
return "";
}
}
}
public function charCodeAt(index:Int):Null<Int> {
untyped {
return __dollar__sget(this.__s, index);
}
}
public function indexOf(str:String, ?startIndex:Int):Int {
untyped {
var l = __dollar__ssize(this.__s);
if (startIndex == null || startIndex < -l)
startIndex = 0;
if (str == '' && startIndex >= l) {
return l;
}
if (startIndex > l)
return -1;
if (__dollar__ssize(str.__s) == 0)
return startIndex < 0 ? l + startIndex : startIndex;
var p = try __dollar__sfind(this.__s, startIndex, str.__s) catch (e:Dynamic) null;
if (p == null)
return -1;
return p;
}
}
public function lastIndexOf(str:String, ?startIndex:Int):Int {
untyped {
var last = -1;
var l = __dollar__ssize(this.__s);
if (startIndex == null)
startIndex = l;
if (__dollar__ssize(str.__s) == 0)
return startIndex > l ? l : startIndex;
while (true) {
var p = try __dollar__sfind(this.__s, last + 1, str.__s) catch (e:Dynamic) null;
if (p == null || p > startIndex)
return last;
last = p;
}
}
}
public function split(delimiter:String):Array<String> {
untyped {
var l = __split(this.__s, delimiter.__s);
var a = new Array<String>();
if (l == null) {
a.push("");
return a;
}
do {
a.push(new String(l[0]));
l = l[1];
} while (l != null);
return a;
}
}
public function substr(pos:Int, ?len:Int):String {
if (len == 0)
return "";
var sl = length;
if (len == null)
len = sl;
if (pos == null)
pos = 0;
if (pos != 0 && len < 0) {
return "";
}
if (pos < 0) {
pos = sl + pos;
if (pos < 0)
pos = 0;
} else if (len < 0) {
len = sl + len - pos;
}
if (pos + len > sl) {
len = sl - pos;
}
if (pos < 0 || len <= 0)
return "";
return new String(untyped __dollar__ssub(this.__s, pos, len));
}
public function substring(startIndex:Int, ?endIndex:Int):String {
if (endIndex == null) {
endIndex = length;
} else if (endIndex < 0) {
endIndex = 0;
} else if (endIndex > length) {
endIndex = length;
}
if (startIndex < 0) {
startIndex = 0;
} else if (startIndex > length) {
startIndex = length;
}
if (startIndex > endIndex) {
var tmp = startIndex;
startIndex = endIndex;
endIndex = tmp;
}
return substr(startIndex, endIndex - startIndex);
}
public function toLowerCase():String {
untyped {
var s = this.__s;
var l = this.length;
var s2 = __dollar__scopy(s);
var i = 0;
while (i < l) {
var c = __dollar__sget(s, i);
if (c >= 65 && c <= 90)
__dollar__sset(s2, i, c - 65 + 97);
i++;
}
return new String(s2);
}
}
public function toUpperCase():String {
untyped {
var s = this.__s;
var l = this.length;
var s2 = __dollar__scopy(s);
var i = 0;
while (i < l) {
var c = __dollar__sget(s, i);
if (c >= 97 && c <= 122)
__dollar__sset(s2, i, c - 97 + 65);
i++;
}
return new String(s2);
}
}
public function toString():String {
return this;
}
/* NEKO INTERNALS */
private function __compare(o:String):Int {
return untyped __dollar__compare(this.__s, o.__s);
}
private function __add(s:Dynamic):String {
return new String(untyped this.__s + __dollar__string(s));
}
private function __radd(s:Dynamic):String {
return new String(untyped __dollar__string(s) + this.__s);
}
public static function fromCharCode(code:Int):String
untyped {
var s = __dollar__smake(1);
__dollar__sset(s, 0, code);
return new String(s);
}
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
@:coreApi class StringBuf {
private var b:Dynamic;
public var length(get, never):Int;
public function new():Void {
b = __make();
}
function get_length():Int {
return __get_length == null ? untyped __dollar__ssize(__to_string(b)) : __get_length(b);
}
public inline function add<T>(x:T):Void {
__add(b, x);
}
public inline function addSub(s:String, pos:Int, ?len:Int):Void {
__add_sub(b, untyped s.__s, pos, len == null ? s.length - pos : len);
}
public inline function addChar(c:Int):Void
untyped {
__add_char(b, c);
}
public inline function toString():String {
return new String(__to_string(b));
}
static var __make:Dynamic = neko.Lib.load("std", "buffer_new", 0);
static var __add:Dynamic = neko.Lib.load("std", "buffer_add", 2);
static var __add_char:Dynamic = neko.Lib.load("std", "buffer_add_char", 2);
static var __add_sub:Dynamic = neko.Lib.load("std", "buffer_add_sub", 4);
static var __to_string:Dynamic = neko.Lib.load("std", "buffer_string", 1);
static var __get_length:Dynamic = try neko.Lib.load("std", "buffer_get_length", 1) catch (e:Dynamic) null;
}

View File

@ -0,0 +1,200 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
import haxe.SysTools;
@:coreApi 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());
}
public static function command( cmd : String, ?args : Array<String> ) : Int {
if (args == null) {
return sys_command(untyped cmd.__s);
} else {
switch (systemName()) {
case "Windows":
cmd = [
for (a in [StringTools.replace(cmd, "/", "\\")].concat(args))
SysTools.quoteWinArg(a, true)
].join(" ");
return sys_command(untyped cmd.__s);
case _:
cmd = [cmd].concat(args).map(SysTools.quoteUnixArg).join(" ");
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();
}
@:deprecated("Use programPath instead") public static function executablePath() : String {
return new String(sys_exe_path());
}
public static function programPath() : String {
#if macro
return null;
#elseif interp
return new String(sys_program_path());
#else
return sys_program_path;
#end
}
public static function environment() : Map<String,String> {
var l : Array<Dynamic> = sys_env();
var h = new haxe.ds.StringMap();
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);
#if interp
private static var sys_program_path = neko.Lib.load("std","sys_program_path",0);
#elseif !macro
// It has to be initialized before any call to loadModule or Sys.setCwd()...
private static var sys_program_path = {
var m = neko.vm.Module.local().name;
if (m == "") { // it is likely neko embedded in an exe
var exe = new String(sys_exe_path());
try {
sys.FileSystem.fullPath(exe);
} catch (e:Dynamic) {
exe;
}
} else {
try {
sys.FileSystem.fullPath(m);
} catch (e:Dynamic) {
// maybe the neko module name was supplied without .n extension...
if (!StringTools.endsWith(m, ".n")) {
try {
sys.FileSystem.fullPath(m + ".n");
} catch (e:Dynamic) {
m;
}
} else {
m;
}
}
}
}
#end
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);
}

View File

@ -0,0 +1,235 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
enum ValueType {
TNull;
TInt;
TFloat;
TBool;
TObject;
TFunction;
TClass( c : Class<Dynamic> );
TEnum( e : Enum<Dynamic> );
TUnknown;
}
@:coreApi class Type {
public static function getClass<T>( o : T ) : Class<T> untyped {
if( __dollar__typeof(o) != __dollar__tobject )
return null;
var p = __dollar__objgetproto(o);
if( p == null )
return null;
return p.__class__;
}
public static function getEnum( o : EnumValue ) : Enum<Dynamic> untyped {
if( __dollar__typeof(o) != __dollar__tobject )
return null;
return o.__enum__;
}
public static function getSuperClass( c : Class<Dynamic> ) : Class<Dynamic> untyped {
return c.__super__;
}
public static function getClassName( c : Class<Dynamic> ) : String {
if( c == null )
return null;
var a : Array<String> = untyped c.__name__;
return a.join(".");
}
public static function getEnumName( e : Enum<Dynamic> ) : String {
var a : Array<String> = untyped e.__ename__;
return a.join(".");
}
public static function resolveClass( name : String ) : Class<Dynamic> untyped {
var path = name.split(".");
var cl = Reflect.field(untyped neko.Boot.__classes,path[0]);
var i = 1;
while( cl != null && i < path.length ) {
cl = Reflect.field(cl,path[i]);
i += 1;
}
// ensure that this is a class
if( cl == null || cl.__name__ == null )
return null;
return cl;
}
public static function resolveEnum( name : String ) : Enum<Dynamic> untyped {
var path = name.split(".");
var e = Reflect.field(neko.Boot.__classes,path[0]);
var i = 1;
while( e != null && i < path.length ) {
e = Reflect.field(e,path[i]);
i += 1;
}
// ensure that this is an enum
if( e == null || e.__ename__ == null )
return null;
return e;
}
public static function createInstance<T>( cl : Class<T>, args : Array<Dynamic> ) : T untyped {
var fnew = $objget(cl,$hash("new".__s));
var a = args.__neko();
// pad missing args with null's
var n = $nargs(fnew);
if( n > $asize(a) ) {
var a2 = $amake(n);
$ablit(a2,0,a,0,$asize(a));
a = a2;
}
return $call(fnew,cl,a);
}
public static function createEmptyInstance<T>( cl : Class<T> ) : T untyped {
var o = __dollar__new(null);
__dollar__objsetproto(o,cl.prototype);
return o;
}
public static function createEnum<T>( e : Enum<T>, constr : String, ?params : Array<Dynamic> ) : T {
var f:Dynamic = Reflect.field(e,constr);
if( f == null ) throw "No such constructor "+constr;
if( Reflect.isFunction(f) ) {
if( params == null ) throw "Constructor "+constr+" need parameters";
return Reflect.callMethod(e,f,params);
}
if( params != null && params.length != 0 )
throw "Constructor "+constr+" does not need parameters";
return f;
}
public static function createEnumIndex<T>( e : Enum<T>, index : Int, ?params : Array<Dynamic> ) : T {
var c : String = (untyped e.__constructs__)[index];
if( c == null ) throw index+" is not a valid enum constructor index";
return createEnum(e,c,params);
}
public static function getInstanceFields( c : Class<Dynamic> ) : Array<String> {
var a = Reflect.fields(untyped c.prototype);
c = untyped c.__super__;
while( c != null ) {
for( f in Reflect.fields(untyped c.prototype) ) {
a.remove(f);
a.push(f);
}
c = untyped c.__super__;
}
a.remove("__class__");
a.remove("__serialize");
a.remove("__string");
a.remove("__properties__");
return a;
}
public static function getClassFields( c : Class<Dynamic> ) : Array<String> {
var a = Reflect.fields(c);
a.remove("__name__");
a.remove("__interfaces__");
a.remove("__super__");
a.remove("__string");
a.remove("__construct__");
a.remove("__properties__");
a.remove("prototype");
a.remove("new");
#if (macro || interp)
a.remove("__ct__");
#end
return a;
}
public static function getEnumConstructs( e : Enum<Dynamic> ) : Array<String> {
var a : Array<String> = untyped e.__constructs__;
return a.copy();
}
public static function typeof( v : Dynamic ) : ValueType untyped {
return switch( __dollar__typeof(v) ) {
case 0: TNull;
case 1: TInt;
case 2: TFloat;
case 3: TBool;
case 7: TFunction;
case 5:
var c = v.__class__;
if( c != null )
TClass(c);
else {
var e = v.__enum__;
if( e != null )
TEnum(e);
else
TObject;
}
default: TUnknown;
}
}
public static function enumEq<T>( a : T, b : T ) : Bool untyped {
if( a == b )
return true;
try {
if( a.__enum__ == null || a.index != b.index )
return false;
} catch( e : Dynamic ) {
return false;
}
for( i in 0...__dollar__asize(a.args) )
if( !enumEq(a.args[i],b.args[i]) )
return false;
return true;
}
public static function enumConstructor( e : EnumValue ) : String {
return new String(untyped e.tag);
}
public static function enumParameters( e : EnumValue ) : Array<Dynamic> {
return untyped if( e.args == null ) [] else Array.new1(e.args,__dollar__asize(e.args));
}
public inline static function enumIndex( e : EnumValue ) : Int {
return untyped e.index;
}
public static function allEnums<T>( e : Enum<T> ) : Array<T> {
var all = [];
var cst : Array<String> = untyped e.__constructs__;
for( c in cst ) {
var v = Reflect.field(e,c);
if( !Reflect.isFunction(v) )
all.push(v);
}
return all;
}
}

View File

@ -0,0 +1,85 @@
package haxe;
@:coreApi
class Exception {
public var message(get,never):String;
public var stack(get,never):CallStack;
public var previous(get,never):Null<Exception>;
public var native(get,never):Any;
@:noCompletion var __exceptionMessage:String;
@:noCompletion var __exceptionStack:Null<CallStack>;
@:noCompletion var __nativeStack:Any;
@:noCompletion @:ifFeature("haxe.Exception.get_stack") var __skipStack:Int = 0;
@:noCompletion var __nativeException:Any;
@:noCompletion var __previousException:Null<Exception>;
static function caught(value:Any):Exception {
if(Std.isOfType(value, Exception)) {
return value;
} else {
return new ValueException(value, null, value);
}
}
static function thrown(value:Any):Any {
if(Std.isOfType(value, Exception)) {
return (value:Exception).native;
} else {
var e = new ValueException(value);
e.__shiftStack();
return e;
}
}
public function new(message:String, ?previous:Exception, ?native:Any) {
__exceptionMessage = message;
__previousException = previous;
if(native != null) {
__nativeStack = NativeStackTrace.exceptionStack();
__nativeException = native;
} else {
__nativeStack = NativeStackTrace.callStack();
__shiftStack();
__nativeException = this;
}
}
function unwrap():Any {
return __nativeException;
}
public function toString():String {
return message;
}
public function details():String {
return inline CallStack.exceptionToString(this);
}
@:noCompletion
@:ifFeature("haxe.Exception.get_stack")
inline function __shiftStack():Void {
__skipStack++;
}
function get_message():String {
return __exceptionMessage;
}
function get_previous():Null<Exception> {
return __previousException;
}
final function get_native():Any {
return __nativeException;
}
function get_stack():CallStack {
return switch __exceptionStack {
case null:
__exceptionStack = NativeStackTrace.toHaxe(__nativeStack, __skipStack);
case s: s;
}
}
}

View File

@ -0,0 +1,51 @@
package haxe;
import haxe.CallStack.StackItem;
private typedef NativeTrace = {
final skip:Int;
final stack:Dynamic;
}
/**
Do not use manually.
**/
@:dox(hide)
@:noCompletion
class NativeStackTrace {
@:ifFeature('haxe.NativeStackTrace.exceptionStack')
static public inline function saveStack(exception:Any):Void {
}
static public inline function callStack():NativeTrace {
return { skip:1, stack:untyped __dollar__callstack() };
}
static public function exceptionStack():NativeTrace {
return { skip:0, stack:untyped __dollar__excstack() };
}
static public function toHaxe(native:NativeTrace, skip:Int = 0):Array<StackItem> {
skip += native.skip;
var a = new Array();
var l = untyped __dollar__asize(native.stack);
var i = 0;
while (i < l) {
var x = native.stack[l - i - 1];
//skip all CFunctions until we skip required amount of hx entries
if(x == null && skip > i) {
skip++;
}
if(skip > i++) {
continue;
}
if (x == null)
a.push(CFunction);
else if (untyped __dollar__typeof(x) == __dollar__tstring)
a.push(Module(new String(x)));
else
a.push(FilePos(null, new String(untyped x[0]), untyped x[1]));
}
return a;
}
}

View File

@ -0,0 +1,53 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe;
@:coreApi
class Resource {
static var content:Array<{name:String, data:String, str:String}>;
public static function listNames():Array<String> {
return [for (x in content) x.name];
}
public static function getString(name:String):String {
for (x in content)
if (x.name == name) {
return new String(x.data);
}
return null;
}
public static function getBytes(name:String):haxe.io.Bytes {
for (x in content)
if (x.name == name) {
return haxe.io.Bytes.ofData(cast x.data);
}
return null;
}
static function __init__() : Void {
var tmp = untyped __resources__();
content = untyped Array.new1(tmp, __dollar__asize(tmp));
}
}

View File

@ -0,0 +1,107 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe;
@:coreApi
@:deprecated('haxe.Utf8 is deprecated. Use UnicodeString instead.')
class Utf8 {
var __b:Dynamic;
public function new(?size:Int):Void {
__b = utf8_buf_alloc(if (size == null) 1 else size);
}
public function addChar(c:Int):Void {
utf8_buf_add(__b, c);
}
public function toString():String {
return new String(utf8_buf_content(__b));
}
public static function encode(s:String):String {
s = untyped s.__s;
var sl = untyped __dollar__ssize(s);
var buf:Dynamic = utf8_buf_alloc(sl);
var i = 0;
while (i < sl) {
utf8_buf_add(buf, untyped __dollar__sget(s, i));
i += 1;
}
return new String(utf8_buf_content(buf));
}
public static function decode(s:String):String {
s = untyped s.__s;
var sl = untyped __dollar__ssize(s);
var ret = untyped __dollar__smake(sl);
var i = 0;
utf8_iter(s, function(c) {
if (c == 8364) // euro symbol
c = 164;
else if (c == 0xFEFF) // BOM
return;
else if (c > 255)
throw "Utf8::decode invalid character (" + c + ")";
untyped __dollar__sset(ret, i, c);
i += 1;
});
return new String(untyped __dollar__ssub(ret, 0, i));
}
public static function iter(s:String, chars:Int->Void):Void {
utf8_iter(untyped s.__s, chars);
}
public static function charCodeAt(s:String, index:Int):Int {
return utf8_get(untyped s.__s, index);
}
public static function validate(s:String):Bool {
return utf8_validate(untyped s.__s);
}
public static function length(s:String):Int {
return utf8_length(untyped s.__s);
}
public static function compare(a:String, b:String):Int {
return utf8_compare(untyped a.__s, untyped b.__s);
}
public static function sub(s:String, pos:Int, len:Int):String {
return new String(utf8_sub(untyped s.__s, pos, len));
}
static var utf8_buf_alloc = neko.Lib.load("std", "utf8_buf_alloc", 1);
static var utf8_buf_add = neko.Lib.load("std", "utf8_buf_add", 2);
static var utf8_buf_content = neko.Lib.load("std", "utf8_buf_content", 1);
static var utf8_buf_length = neko.Lib.load("std", "utf8_buf_length", 1);
static var utf8_iter = neko.Lib.load("std", "utf8_iter", 2);
static var utf8_get = neko.Lib.load("std", "utf8_get", 2);
static var utf8_validate = neko.Lib.load("std", "utf8_validate", 1);
static var utf8_length = neko.Lib.load("std", "utf8_length", 1);
static var utf8_compare = neko.Lib.load("std", "utf8_compare", 2);
static var utf8_sub = neko.Lib.load("std", "utf8_sub", 3);
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.crypto;
class Md5 {
public static function encode(s:String):String {
return untyped new String(base_encode(make_md5(s.__s), "0123456789abcdef".__s));
}
public static function make(b:haxe.io.Bytes):haxe.io.Bytes {
return haxe.io.Bytes.ofData(make_md5(b.getData()));
}
static var base_encode = neko.Lib.load("std", "base_encode", 2);
static var make_md5 = neko.Lib.load("std", "make_md5", 1);
}

View File

@ -0,0 +1,93 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.ds;
@:coreApi class IntMap<T> implements haxe.Constraints.IMap<Int, T> {
private var h:Dynamic;
public function new():Void {
h = untyped __dollar__hnew(0);
}
public inline function set(key:Int, value:T):Void {
untyped __dollar__hset(h, key, value, null);
}
public function get(key:Int):Null<T> {
return untyped __dollar__hget(h, key, null);
}
public inline function exists(key:Int):Bool {
return untyped __dollar__hmem(h, key, null);
}
public inline function remove(key:Int):Bool {
return untyped __dollar__hremove(h, key, null);
}
public function keys():Iterator<Int> {
var l = new List<Int>();
untyped __dollar__hiter(h, function(k, _) {
l.push(k);
});
return l.iterator();
}
public function iterator():Iterator<T> {
var l = new List<T>();
untyped __dollar__hiter(h, function(_, v) {
l.push(v);
});
return l.iterator();
}
@:runtime public inline function keyValueIterator():KeyValueIterator<Int, T> {
return new haxe.iterators.MapKeyValueIterator(this);
}
public function copy():IntMap<T> {
var copied = new IntMap();
for (key in keys())
copied.set(key, get(key));
return copied;
}
public function toString():String {
var s = new StringBuf();
s.add("{");
var it = keys();
for (i in it) {
s.add(i);
s.add(" => ");
s.add(Std.string(get(i)));
if (it.hasNext())
s.add(", ");
}
s.add("}");
return s.toString();
}
public inline function clear():Void {
h = untyped __dollar__hnew(0);
}
}

View File

@ -0,0 +1,114 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of h software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and h permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.ds;
@:coreApi
class ObjectMap<K:{}, V> implements haxe.Constraints.IMap<K, V> {
static var count = 0;
static inline function assignId(obj:{}):Int {
var newId = count++;
untyped obj.__id__ = newId;
return newId;
}
static inline function getId(obj:{}):Int {
return untyped obj.__id__;
}
var h:{};
var k:{};
public function new():Void {
h = untyped __dollar__hnew(0);
k = untyped __dollar__hnew(0);
}
public inline function set(key:K, value:V):Void
untyped {
var id = key.__id__ != null ? key.__id__ : assignId(key);
untyped __dollar__hset(h, id, value, null);
untyped __dollar__hset(k, id, key, null);
}
public function get(key:K):Null<V> {
return untyped __dollar__hget(h, getId(key), null);
}
public inline function exists(key:K):Bool {
return untyped __dollar__hmem(h, getId(key), null);
}
public function remove(key:K):Bool {
var id = getId(key);
untyped __dollar__hremove(h, id, null);
return untyped __dollar__hremove(k, id, null);
}
public function keys():Iterator<K> {
var l = new List<K>();
untyped __dollar__hiter(k, function(_, v) {
l.push(v);
});
return l.iterator();
}
public function iterator():Iterator<V> {
var l = new List<V>();
untyped __dollar__hiter(h, function(_, v) {
l.push(v);
});
return l.iterator();
}
@:runtime public inline function keyValueIterator():KeyValueIterator<K, V> {
return new haxe.iterators.MapKeyValueIterator(this);
}
public function copy():ObjectMap<K, V> {
var copied = new ObjectMap();
for (key in keys())
copied.set(key, get(key));
return copied;
}
public function toString():String {
var s = new StringBuf();
s.add("{");
var it = keys();
for (i in it) {
s.add(Std.string(i));
s.add(" => ");
s.add(Std.string(get(i)));
if (it.hasNext())
s.add(", ");
}
s.add("}");
return s.toString();
}
public inline function clear():Void {
h = untyped __dollar__hnew(0);
k = untyped __dollar__hnew(0);
}
}

View File

@ -0,0 +1,93 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.ds;
@:coreApi class StringMap<T> implements haxe.Constraints.IMap<String, T> {
private var h:Dynamic;
public function new():Void {
h = untyped __dollar__hnew(0);
}
public inline function set(key:String, value:T):Void {
untyped __dollar__hset(h, key.__s, value, null);
}
public inline function get(key:String):Null<T> {
return untyped __dollar__hget(h, key.__s, null);
}
public inline function exists(key:String):Bool {
return untyped __dollar__hmem(h, key.__s, null);
}
public inline function remove(key:String):Bool {
return untyped __dollar__hremove(h, key.__s, null);
}
public function keys():Iterator<String> {
var l = new List<String>();
untyped __dollar__hiter(h, function(k, _) {
l.push(new String(k));
});
return l.iterator();
}
public function iterator():Iterator<T> {
var l = new List<T>();
untyped __dollar__hiter(h, function(_, v) {
l.push(v);
});
return l.iterator();
}
@:runtime public inline function keyValueIterator():KeyValueIterator<String, T> {
return new haxe.iterators.MapKeyValueIterator(this);
}
public function copy():StringMap<T> {
var copied = new StringMap();
for (key in keys())
copied.set(key, get(key));
return copied;
}
public function toString():String {
var s = new StringBuf();
s.add("{");
var it = keys();
for (i in it) {
s.add(i);
s.add(" => ");
s.add(Std.string(get(i)));
if (it.hasNext())
s.add(", ");
}
s.add("}");
return s.toString();
}
public inline function clear():Void {
h = untyped __dollar__hnew(0);
}
}

View File

@ -0,0 +1,29 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.io;
class StringInput extends BytesInput {
public function new(s:String) {
super(neko.Lib.bytesReference(s));
}
}

View File

@ -0,0 +1,64 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.iterators;
class StringIteratorUnicode {
var byteOffset:Int = 0;
var s:String;
public inline function new(s:String) {
this.s = s;
}
public inline function hasNext() {
return byteOffset < s.length;
}
public inline function next() {
var code:Int = codeAt(byteOffset);
if (code < 0xC0) {
byteOffset++;
} else if (code < 0xE0) {
code = ((code - 0xC0) << 6) + codeAt(byteOffset + 1) - 0x80;
byteOffset += 2;
} else if (code < 0xF0) {
code = ((code - 0xE0) << 12) + ((codeAt(byteOffset + 1) - 0x80) << 6) + codeAt(byteOffset + 2) - 0x80;
byteOffset += 3;
} else {
code = ((code - 0xF0) << 18)
+ ((codeAt(byteOffset + 1) - 0x80) << 12)
+ ((codeAt(byteOffset + 2) - 0x80) << 6)
+ codeAt(byteOffset + 3)
- 0x80;
byteOffset += 4;
}
return code;
}
inline function codeAt(index:Int):Int {
return untyped $sget(s.__s, index);
}
static public inline function unicodeIterator(s:String) {
return new StringIteratorUnicode(s);
}
}

View File

@ -0,0 +1,65 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.iterators;
class StringKeyValueIteratorUnicode {
var byteOffset:Int = 0;
var charOffset:Int = 0;
var s:String;
public inline function new(s:String) {
this.s = s;
}
public inline function hasNext() {
return byteOffset < s.length;
}
public inline function next() {
var code:Int = codeAt(byteOffset);
if (code < 0xC0) {
byteOffset++;
} else if (code < 0xE0) {
code = ((code - 0xC0) << 6) + codeAt(byteOffset + 1) - 0x80;
byteOffset += 2;
} else if (code < 0xF0) {
code = ((code - 0xE0) << 12) + ((codeAt(byteOffset + 1) - 0x80) << 6) + codeAt(byteOffset + 2) - 0x80;
byteOffset += 3;
} else {
code = ((code - 0xF0) << 18)
+ ((codeAt(byteOffset + 1) - 0x80) << 12)
+ ((codeAt(byteOffset + 2) - 0x80) << 6)
+ codeAt(byteOffset + 3)
- 0x80;
byteOffset += 4;
}
return {key: charOffset++, value: code};
}
inline function codeAt(index:Int):Int {
return untyped $sget(s.__s, index);
}
static public inline function unicodeKeyValueIterator(s:String) {
return new StringKeyValueIteratorUnicode(s);
}
}

View File

@ -0,0 +1,61 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.zip;
@:coreApi
class Compress {
var s:Dynamic;
public function new(level:Int):Void {
s = _deflate_init(level);
}
public function execute(src:haxe.io.Bytes, srcPos:Int, dst:haxe.io.Bytes, dstPos:Int):{done:Bool, read:Int, write:Int} {
return _deflate_buffer(s, src.getData(), srcPos, dst.getData(), dstPos);
}
public function setFlushMode(f:FlushMode):Void {
_set_flush_mode(s, untyped Std.string(f).__s);
}
public function close():Void {
_deflate_end(s);
}
public static function run(s:haxe.io.Bytes, level:Int):haxe.io.Bytes {
var c = new Compress(level);
c.setFlushMode(FlushMode.FINISH);
var out = haxe.io.Bytes.alloc(_deflate_bound(c.s, s.length));
var r = c.execute(s, 0, out, 0);
c.close();
if (!r.done || r.read != s.length)
throw "Compression failed";
return out.sub(0, r.write);
}
static var _deflate_init = neko.Lib.load("zlib", "deflate_init", 1);
static var _deflate_bound = neko.Lib.load("zlib", "deflate_bound", 2);
static var _deflate_buffer = neko.Lib.load("zlib", "deflate_buffer", 5);
static var _deflate_end = neko.Lib.load("zlib", "deflate_end", 1);
static var _set_flush_mode = neko.Lib.load("zlib", "set_flush_mode", 2);
}

View File

@ -0,0 +1,68 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.zip;
@:coreApi
class Uncompress {
var s:Dynamic;
public function new(?windowBits:Int):Void {
s = _inflate_init(windowBits);
}
public function execute(src:haxe.io.Bytes, srcPos:Int, dst:haxe.io.Bytes, dstPos:Int):{done:Bool, read:Int, write:Int} {
return _inflate_buffer(s, src.getData(), srcPos, dst.getData(), dstPos);
}
public function setFlushMode(f:FlushMode):Void {
_set_flush_mode(s, untyped Std.string(f).__s);
}
public function close():Void {
_inflate_end(s);
}
public static function run(src:haxe.io.Bytes, ?bufsize:Int):haxe.io.Bytes {
var u = new Uncompress(null);
if (bufsize == null)
bufsize = 1 << 16; // 64K
var tmp = haxe.io.Bytes.alloc(bufsize);
var b = new haxe.io.BytesBuffer();
var pos = 0;
u.setFlushMode(FlushMode.SYNC);
while (true) {
var r = u.execute(src, pos, tmp, 0);
b.addBytes(tmp, 0, r.write);
pos += r.read;
if (r.done)
break;
}
u.close();
return b.getBytes();
}
static var _inflate_init = neko.Lib.load("zlib", "inflate_init", 1);
static var _inflate_buffer = neko.Lib.load("zlib", "inflate_buffer", 5);
static var _inflate_end = neko.Lib.load("zlib", "inflate_end", 1);
static var _set_flush_mode = neko.Lib.load("zlib", "set_flush_mode", 2);
}

View File

@ -0,0 +1,123 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys;
private enum FileKind {
kdir;
kfile;
kother(k:String);
}
@:coreApi
class FileSystem {
public static function exists(path:String):Bool {
return sys_exists(untyped (makeCompatiblePath(path)).__s);
}
public static function rename(path:String, newPath:String):Void {
untyped sys_rename(path.__s, newPath.__s);
}
public static function stat(path:String):FileStat {
var s:FileStat = sys_stat(untyped (makeCompatiblePath(path)).__s);
s.atime = untyped Date.new1(s.atime);
s.mtime = untyped Date.new1(s.mtime);
s.ctime = untyped Date.new1(s.ctime);
return s;
}
public static function fullPath(relPath:String):String {
return new String(file_full_path(untyped relPath.__s));
}
public static function absolutePath(relPath:String):String {
if (haxe.io.Path.isAbsolute(relPath))
return relPath;
return haxe.io.Path.join([Sys.getCwd(), relPath]);
}
static function kind(path:String):FileKind {
var k = new String(sys_file_type(untyped (makeCompatiblePath(path)).__s));
return switch (k) {
case "file": kfile;
case "dir": kdir;
default: kother(k);
}
}
public static inline function isDirectory(path:String):Bool {
return kind(path) == kdir;
}
public static function createDirectory(path:String):Void {
var path = haxe.io.Path.addTrailingSlash(path);
var _p = null;
var parts = [];
while (path != (_p = haxe.io.Path.directory(path))) {
parts.unshift(path);
path = _p;
}
for (part in parts) {
if (part.charCodeAt(part.length - 1) != ":".code && !exists(part))
sys_create_dir(untyped part.__s, 493);
}
}
public static function deleteFile(path:String):Void {
file_delete(untyped path.__s);
}
public static function deleteDirectory(path:String):Void {
sys_remove_dir(untyped path.__s);
}
public static function readDirectory(path:String):Array<String> {
var l:Array<Dynamic> = sys_read_dir(untyped path.__s);
var a = new Array();
while (l != null) {
a.push(new String(l[0]));
l = l[1];
}
return a;
}
private static inline function makeCompatiblePath(path:String):String {
return if (path.charCodeAt(1) == ":".code && path.length <= 3) {
haxe.io.Path.addTrailingSlash(path);
} else if (path == "/") {
"/";
} else {
haxe.io.Path.removeTrailingSlashes(path);
}
}
private static var sys_exists = neko.Lib.load("std", "sys_exists", 1);
private static var file_delete = neko.Lib.load("std", "file_delete", 1);
private static var sys_rename = neko.Lib.load("std", "sys_rename", 2);
private static var sys_stat = neko.Lib.load("std", "sys_stat", 1);
private static var sys_file_type = neko.Lib.load("std", "sys_file_type", 1);
private static var sys_create_dir = neko.Lib.load("std", "sys_create_dir", 2);
private static var sys_remove_dir = neko.Lib.load("std", "sys_remove_dir", 1);
private static var sys_read_dir = neko.Lib.load("std", "sys_read_dir", 1);
private static var file_full_path = neko.Lib.load("std", "file_full_path", 1);
}

View File

@ -0,0 +1,213 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.db;
private class D {
static function load(fun, args):Dynamic {
return neko.Lib.load(lib, fun, args);
}
static var lib = try {
neko.Lib.load("mysql5", "connect", 1);
"mysql5";
} catch (e:Dynamic) "mysql";
public static var connect = load("connect", 1);
public static var select_db = load("select_db", 2);
public static var request = load("request", 2);
public static var close = load("close", 1);
public static var escape = load("escape", 2);
public static var set_conv_funs = load("set_conv_funs", 4);
public static var result_get_length = load("result_get_length", 1);
public static var result_get_nfields = load("result_get_nfields", 1);
public static var result_next = load("result_next", 1);
public static var result_get = load("result_get", 2);
public static var result_get_int = load("result_get_int", 2);
public static var result_get_float = load("result_get_float", 2);
public static var result_fields_names = neko.Lib.loadLazy(lib, "result_get_fields_names", 1);
}
private class MysqlResultSet implements sys.db.ResultSet {
public var length(get, null):Int;
public var nfields(get, null):Int;
private var __r:Dynamic;
private var cache:Dynamic;
public function new(r) {
__r = r;
}
private function get_length() {
return D.result_get_length(__r);
}
private function get_nfields() {
return D.result_get_nfields(__r);
}
public function hasNext() {
if (cache == null)
cache = next();
return (cache != null);
}
public function next():Dynamic {
var c = cache;
if (c != null) {
cache = null;
return c;
}
c = D.result_next(__r);
return c;
}
public function results():List<Dynamic> {
var l = new List();
while (hasNext())
l.add(next());
return l;
}
public function getResult(n:Int) {
return new String(D.result_get(__r, n));
}
public function getIntResult(n:Int):Int {
return D.result_get_int(__r, n);
}
public function getFloatResult(n:Int):Float {
return D.result_get_float(__r, n);
}
public function getFieldsNames():Array<String> {
var a = D.result_fields_names(__r);
untyped {
var i = 0;
var l = __dollar__asize(a);
while (i < l) {
a[i] = new String(a[i]);
i += 1;
}
a = Array.new1(cast a, l);
}
return a;
}
}
private class MysqlConnection implements sys.db.Connection {
private var __c:Dynamic;
public function new(c) {
__c = c;
D.set_conv_funs(c, function(s) return new String(s), function(d) return untyped Date.new1(d), function(b) return haxe.io.Bytes.ofData(b));
}
public function request(s:String):sys.db.ResultSet {
try {
var r = D.request(this.__c, untyped s.__s);
return new MysqlResultSet(r);
} catch (e:Dynamic) {
untyped if (__dollar__typeof(e) == __dollar__tobject && __dollar__typeof(e.msg) == __dollar__tstring)
e = e.msg;
untyped __dollar__rethrow(e);
return null;
}
}
public function close() {
D.close(__c);
}
public function escape(s:String) {
return new String(D.escape(__c, untyped s.__s));
}
public function quote(s:String) {
return "'" + escape(s) + "'";
}
public function addValue(s:StringBuf, v:Dynamic) {
var t = untyped __dollar__typeof(v);
if (untyped (t == __dollar__tint || t == __dollar__tnull))
s.add(v);
else if (untyped t == __dollar__tbool)
s.addChar(if (v) "1".code else "0".code);
else {
s.addChar("'".code);
s.add(escape(Std.string(v)));
s.addChar("'".code);
}
}
public function lastInsertId() {
return request("SELECT LAST_INSERT_ID()").getIntResult(0);
}
public function dbName() {
return "MySQL";
}
public function startTransaction() {
request("START TRANSACTION");
}
public function commit() {
request("COMMIT");
}
public function rollback() {
request("ROLLBACK");
}
private static var __use_date = Date;
}
@:coreApi class Mysql {
public static function connect(params:{
host:String,
?port:Int,
user:String,
pass:String,
?socket:String,
?database:String
}):sys.db.Connection {
var o = untyped {
host: params.host.__s,
port: if (params.port == null) 3306 else params.port,
user: params.user.__s,
pass: params.pass.__s,
socket: if (params.socket == null) null else params.socket.__s
};
var c = D.connect(o);
if (params.database != null) {
try {
D.select_db(c, untyped params.database.__s);
} catch (e:Dynamic) {
D.close(c);
neko.Lib.rethrow(e);
}
}
return new MysqlConnection(c);
}
}

View File

@ -0,0 +1,199 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.db;
private class SqliteConnection implements Connection {
var c:Dynamic;
public function new(file:String) {
c = _connect(untyped file.__s);
}
public function close() {
_close(c);
}
public function request(s:String):ResultSet {
try {
return new SqliteResultSet(_request(c, untyped s.__s));
} catch (e:String) {
throw "Error while executing " + s + " (" + e + ")";
}
}
public function escape(s:String) {
return s.split("'").join("''");
}
public function quote(s:String) {
if (s.indexOf("\000") >= 0)
return "x'" + new String(untyped _encode(s.__s, "0123456789ABCDEF".__s)) + "'";
return "'" + s.split("'").join("''") + "'";
}
public function addValue(s:StringBuf, v:Dynamic) {
var t = untyped __dollar__typeof(v);
if (untyped (t == __dollar__tint || t == __dollar__tnull))
s.add(v);
else if (untyped t == __dollar__tbool)
s.add(if (v) 1 else 0);
else
s.add(quote(Std.string(v)));
}
public function lastInsertId() {
return _last_id(c);
}
public function dbName() {
return "SQLite";
}
public function startTransaction() {
request("BEGIN TRANSACTION");
}
public function commit() {
request("COMMIT");
}
public function rollback() {
request("ROLLBACK");
}
static var _encode = neko.Lib.load("std", "base_encode", 2);
static var _connect = neko.Lib.load("sqlite", "connect", 1);
static var _close = neko.Lib.load("sqlite", "close", 1);
static var _request = neko.Lib.load("sqlite", "request", 2);
static var _last_id = neko.Lib.load("sqlite", "last_insert_id", 1);
}
private class SqliteResultSet implements ResultSet {
public var length(get, null):Int;
public var nfields(get, null):Int;
var r:Dynamic;
var cache:List<Dynamic>;
public function new(r) {
cache = new List();
this.r = r;
hasNext(); // execute the request
}
function get_length() {
if (nfields != 0) {
while (true) {
var c = doNext();
if (c == null)
break;
cache.add(c);
}
return cache.length;
}
return result_get_length(r);
}
function get_nfields() {
return result_get_nfields(r);
}
public function hasNext() {
var c = next();
if (c == null)
return false;
cache.push(c);
return true;
}
public function next():Dynamic {
var c = cache.pop();
if (c != null)
return c;
return doNext();
}
private function doNext():Dynamic {
var c = result_next(r);
if (c == null)
return null;
untyped {
var f = __dollar__objfields(c);
var i = 0;
var l = __dollar__asize(f);
while (i < l) {
var v = __dollar__objget(c, f[i]);
if (__dollar__typeof(v) == __dollar__tstring)
__dollar__objset(c, f[i], new String(v));
i = i + 1;
}
}
return c;
}
public function results():List<Dynamic> {
var l = new List();
while (true) {
var c = next();
if (c == null)
break;
l.add(c);
}
return l;
}
public function getResult(n:Int) {
return new String(result_get(r, n));
}
public function getIntResult(n:Int):Int {
return result_get_int(r, n);
}
public function getFloatResult(n:Int):Float {
return result_get_float(r, n);
}
public function getFieldsNames():Array<String> {
if(hasNext()) {
return switch cache.first() {
case null: null;
case row: Reflect.fields(row);
}
}
return null;
}
static var result_next = neko.Lib.load("sqlite", "result_next", 1);
static var result_get_length = neko.Lib.load("sqlite", "result_get_length", 1);
static var result_get_nfields = neko.Lib.load("sqlite", "result_get_nfields", 1);
static var result_get = neko.Lib.load("sqlite", "result_get", 2);
static var result_get_int = neko.Lib.load("sqlite", "result_get_int", 2);
static var result_get_float = neko.Lib.load("sqlite", "result_get_float", 2);
}
@:coreApi class Sqlite {
public static function open(file:String):Connection {
return new SqliteConnection(file);
}
}

View File

@ -0,0 +1,77 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.io;
enum FileHandle {}
@:coreApi class File {
public static function getContent(path:String):String {
return new String(file_contents(untyped path.__s));
}
public static function getBytes(path:String):haxe.io.Bytes {
return neko.Lib.bytesReference(getContent(path));
}
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.__s, (if (binary) "rb" else "r").__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 append(path:String, binary:Bool = true):FileOutput {
return untyped new FileOutput(file_open(path.__s, (if (binary) "ab" else "a").__s));
}
public static function update(path:String, binary:Bool = true):FileOutput {
if (!FileSystem.exists(path)) {
write(path).close();
}
return untyped new FileOutput(file_open(path.__s, (if (binary) "rb+" else "r+").__s));
}
public static function copy(srcPath:String, dstPath:String):Void {
var s = read(srcPath, true);
var d = write(dstPath, true);
d.writeInput(s);
s.close();
d.close();
}
private static var file_contents = neko.Lib.load("std", "file_contents", 1);
private static var file_open = neko.Lib.load("std", "file_open", 2);
}

View File

@ -0,0 +1,83 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.io;
@:coreApi class FileInput extends haxe.io.Input {
private var __f:File.FileHandle;
function new(f:File.FileHandle):Void {
__f = f;
}
public override function readByte():Int {
return try {
file_read_char(__f);
} catch (e:Dynamic) {
if (untyped __dollar__typeof(e) == __dollar__tarray)
throw new haxe.io.Eof();
else
throw haxe.io.Error.Custom(e);
}
}
public override function readBytes(s:haxe.io.Bytes, p:Int, l:Int):Int {
return try {
file_read(__f, s.getData(), p, l);
} catch (e:Dynamic) {
if (untyped __dollar__typeof(e) == __dollar__tarray)
throw new haxe.io.Eof();
else
throw haxe.io.Error.Custom(e);
}
}
public override function close():Void {
super.close();
file_close(__f);
}
public function seek(p:Int, pos:FileSeek):Void {
file_seek(__f, p, switch (pos) {
case SeekBegin: 0;
case SeekCur: 1;
case SeekEnd: 2;
});
}
public function tell():Int {
return file_tell(__f);
}
public function eof():Bool {
return file_eof(__f);
}
private static var file_eof = neko.Lib.load("std", "file_eof", 1);
private static var file_read = neko.Lib.load("std", "file_read", 4);
private static var file_read_char = neko.Lib.load("std", "file_read_char", 1);
private static var file_close = neko.Lib.load("std", "file_close", 1);
private static var file_seek = neko.Lib.load("std", "file_seek", 3);
private static var file_tell = neko.Lib.load("std", "file_tell", 1);
}

View File

@ -0,0 +1,71 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.io;
@:coreApi class FileOutput extends haxe.io.Output {
private var __f:File.FileHandle;
function new(f:File.FileHandle):Void {
__f = f;
}
public override function writeByte(c:Int):Void {
try
file_write_char(__f, c)
catch (e:Dynamic)
throw haxe.io.Error.Custom(e);
}
public override function writeBytes(s:haxe.io.Bytes, p:Int, l:Int):Int {
return try file_write(__f, s.getData(), p, l) catch (e:Dynamic) throw haxe.io.Error.Custom(e);
}
public override function flush():Void {
file_flush(__f);
}
public override function close():Void {
super.close();
file_close(__f);
}
public function seek(p:Int, pos:FileSeek):Void {
file_seek(__f, p, switch (pos) {
case SeekBegin: 0;
case SeekCur: 1;
case SeekEnd: 2;
});
}
public function tell():Int {
return file_tell(__f);
}
private static var file_close = neko.Lib.load("std", "file_close", 1);
private static var file_seek = neko.Lib.load("std", "file_seek", 3);
private static var file_tell = neko.Lib.load("std", "file_tell", 1);
private static var file_flush = neko.Lib.load("std", "file_flush", 1);
private static var file_write = neko.Lib.load("std", "file_write", 4);
private static var file_write_char = neko.Lib.load("std", "file_write_char", 2);
}

View File

@ -0,0 +1,124 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.io;
private class Stdin extends haxe.io.Output {
var p:Dynamic;
var buf:haxe.io.Bytes;
public function new(p:Dynamic) {
this.p = p;
buf = haxe.io.Bytes.alloc(1);
}
public override function close() {
super.close();
_stdin_close(p);
}
public override function writeByte(c) {
buf.set(0, c);
writeBytes(buf, 0, 1);
}
public override function writeBytes(buf:haxe.io.Bytes, pos:Int, len:Int):Int {
try {
return _stdin_write(p, buf.getData(), pos, len);
} catch (e:Dynamic) {
throw new haxe.io.Eof();
}
}
static var _stdin_write = neko.Lib.load("std", "process_stdin_write", 4);
static var _stdin_close = neko.Lib.load("std", "process_stdin_close", 1);
}
private class Stdout extends haxe.io.Input {
var p:Dynamic;
var out:Bool;
var buf:haxe.io.Bytes;
public function new(p:Dynamic, out) {
this.p = p;
this.out = out;
buf = haxe.io.Bytes.alloc(1);
}
public override function readByte() {
if (readBytes(buf, 0, 1) == 0)
throw haxe.io.Error.Blocked;
return buf.get(0);
}
public override function readBytes(str:haxe.io.Bytes, pos:Int, len:Int):Int {
try {
return (out ? _stdout_read : _stderr_read)(p, str.getData(), pos, len);
} catch (e:Dynamic) {
throw new haxe.io.Eof();
}
}
static var _stdout_read = neko.Lib.load("std", "process_stdout_read", 4);
static var _stderr_read = neko.Lib.load("std", "process_stderr_read", 4);
}
@:coreApi class Process {
var p:Dynamic;
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>, ?detached:Bool):Void {
if (detached)
throw "Detached process is not supported on this platform";
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);
stderr = new Stdout(p, false);
}
public function getPid():Int {
return _pid(p);
}
public function exitCode(block:Bool = true):Null<Int> {
if (block == false)
throw "Non blocking exitCode() not supported on this platform";
return _exit(p);
}
public function close():Void {
_close(p);
}
public function kill():Void {
_kill(p);
}
static var _run = neko.Lib.load("std", "process_run", 2);
static var _exit = neko.Lib.load("std", "process_exit", 1);
static var _pid = neko.Lib.load("std", "process_pid", 1);
static var _close = neko.Lib.loadLazy("std", "process_close", 1);
static var _kill = neko.Lib.loadLazy("std", "process_kill", 1);
}

View File

@ -0,0 +1,57 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.net;
@:coreApi
@:keepInit
class Host {
public var host(default, null):String;
public var ip(default, null):Int;
public function new(name:String):Void {
host = name;
ip = host_resolve(untyped name.__s);
}
public function toString():String {
return new String(host_to_string(ip));
}
public function reverse():String {
return new String(host_reverse(ip));
}
public static function localhost():String {
return new String(host_local());
}
static function __init__():Void {
neko.Lib.load("std", "socket_init", 0)();
}
private static var host_resolve = neko.Lib.load("std", "host_resolve", 1);
private static var host_reverse = neko.Lib.load("std", "host_reverse", 1);
private static var host_to_string = neko.Lib.load("std", "host_to_string", 1);
private static var host_local = neko.Lib.load("std", "host_local", 0);
}

View File

@ -0,0 +1,284 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.net;
import haxe.io.Error;
@:callable
@:coreType
abstract SocketHandle {}
private class SocketOutput extends haxe.io.Output {
var __s:SocketHandle;
public function new(s) {
__s = s;
}
public override function writeByte(c:Int) {
try {
socket_send_char(__s, c);
} catch (e:Dynamic) {
if (e == "Blocking")
throw Blocked;
else if (e == "EOF")
throw new haxe.io.Eof();
else
throw Custom(e);
}
}
public override function writeBytes(buf:haxe.io.Bytes, pos:Int, len:Int):Int {
return try {
socket_send(__s, buf.getData(), pos, len);
} catch (e:Dynamic) {
if (e == "Blocking")
throw Blocked;
else
throw Custom(e);
}
}
public override function close() {
super.close();
if (__s != null)
socket_close(__s);
}
private static var socket_close = neko.Lib.load("std", "socket_close", 1);
private static var socket_send_char = neko.Lib.load("std", "socket_send_char", 2);
private static var socket_send = neko.Lib.load("std", "socket_send", 4);
}
private class SocketInput extends haxe.io.Input {
var __s:SocketHandle;
public function new(s) {
__s = s;
}
public override function readByte():Int {
return try {
socket_recv_char(__s);
} catch (e:Dynamic) {
if (e == "Blocking")
throw Blocked;
else if (__s == null)
throw Custom(e);
else
throw new haxe.io.Eof();
}
}
public override function readBytes(buf:haxe.io.Bytes, pos:Int, len:Int):Int {
var r;
try {
r = socket_recv(__s, buf.getData(), pos, len);
} catch (e:Dynamic) {
if (e == "Blocking")
throw Blocked;
else
throw Custom(e);
}
if (r == 0)
throw new haxe.io.Eof();
return r;
}
public override function close() {
super.close();
if (__s != null)
socket_close(__s);
}
private static var socket_recv = neko.Lib.load("std", "socket_recv", 4);
private static var socket_recv_char = neko.Lib.load("std", "socket_recv_char", 1);
private static var socket_close = neko.Lib.load("std", "socket_close", 1);
}
@:coreApi
class Socket {
private var __s:SocketHandle;
public var input(default, null):haxe.io.Input;
public var output(default, null):haxe.io.Output;
public var custom:Dynamic;
public function new():Void {
init();
}
private function init():Void {
if (__s == null)
__s = socket_new(false);
input = new SocketInput(__s);
output = new SocketOutput(__s);
}
public function close():Void {
socket_close(__s);
untyped {
input.__s = null;
output.__s = null;
}
input.close();
output.close();
}
public function read():String {
return new String(socket_read(__s));
}
public function write(content:String):Void {
socket_write(__s, untyped content.__s);
}
public function connect(host:Host, port:Int):Void {
try {
socket_connect(__s, host.ip, port);
} catch (s:String) {
if (s == "std@socket_connect")
throw "Failed to connect on " + host.toString() + ":" + port;
else if (s == "Blocking") {
// Do nothing, this is not a real error, it simply indicates
// that a non-blocking connect is in progress
} else
neko.Lib.rethrow(s);
}
}
public function listen(connections:Int):Void {
socket_listen(__s, connections);
}
public function shutdown(read:Bool, write:Bool):Void {
socket_shutdown(__s, read, write);
}
public function bind(host:Host, port:Int):Void {
socket_bind(__s, host.ip, port);
}
public function accept():Socket {
var c = socket_accept(__s);
var s = Type.createEmptyInstance(Socket);
s.__s = c;
s.input = new SocketInput(c);
s.output = new SocketOutput(c);
return s;
}
public function peer():{host:Host, port:Int} {
var a:Dynamic = socket_peer(__s);
if (a == null) {
return null;
}
var h = new Host("127.0.0.1");
untyped h.ip = a[0];
return {host: h, port: a[1]};
}
public function host():{host:Host, port:Int} {
var a:Dynamic = socket_host(__s);
if (a == null) {
return null;
}
var h = new Host("127.0.0.1");
untyped h.ip = a[0];
return {host: h, port: a[1]};
}
public function setTimeout(timeout:Float):Void {
socket_set_timeout(__s, timeout);
}
public function waitForRead():Void {
select([this], null, null, null);
}
public function setBlocking(b:Bool):Void {
socket_set_blocking(__s, b);
}
public function setFastSend(b:Bool):Void {
socket_set_fast_send(__s, b);
}
public static function select(read:Array<Socket>, write:Array<Socket>, others:Array<Socket>,
?timeout:Float):{read:Array<Socket>, write:Array<Socket>, others:Array<Socket>} {
var c = untyped __dollar__hnew(1);
var f = function(a:Array<Socket>) {
if (a == null)
return null;
untyped {
var r = __dollar__amake(a.length);
var i = 0;
while (i < a.length) {
r[i] = a[i].__s;
__dollar__hadd(c, a[i].__s, a[i]);
i += 1;
}
return r;
}
}
var neko_array = socket_select(f(read), f(write), f(others), timeout);
var g = function(a):Array<Socket> {
if (a == null)
return null;
var r = new Array();
var i = 0;
while (i < untyped __dollar__asize(a)) {
var t = untyped __dollar__hget(c, a[i], null);
if (t == null)
throw "Socket object not found.";
r[i] = t;
i += 1;
}
return r;
}
return {
read: g(neko_array[0]),
write: g(neko_array[1]),
others: g(neko_array[2])
};
}
private static var socket_new = neko.Lib.load("std", "socket_new", 1);
private static var socket_close = neko.Lib.load("std", "socket_close", 1);
private static var socket_write = neko.Lib.load("std", "socket_write", 2);
private static var socket_read = neko.Lib.load("std", "socket_read", 1);
private static var socket_connect = neko.Lib.load("std", "socket_connect", 3);
private static var socket_listen = neko.Lib.load("std", "socket_listen", 2);
private static var socket_select = neko.Lib.load("std", "socket_select", 4);
private static var socket_bind = neko.Lib.load("std", "socket_bind", 3);
private static var socket_accept = neko.Lib.load("std", "socket_accept", 1);
private static var socket_peer = neko.Lib.load("std", "socket_peer", 1);
private static var socket_host = neko.Lib.load("std", "socket_host", 1);
private static var socket_set_timeout = neko.Lib.load("std", "socket_set_timeout", 2);
private static var socket_shutdown = neko.Lib.load("std", "socket_shutdown", 3);
private static var socket_set_blocking = neko.Lib.load("std", "socket_set_blocking", 2);
private static var socket_set_fast_send = neko.Lib.loadLazy("std", "socket_set_fast_send", 2);
}

View File

@ -0,0 +1,67 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.net;
import haxe.io.Error;
@:coreApi
class UdpSocket extends Socket {
private override function init():Void {
__s = Socket.socket_new(true);
super.init();
}
public function sendTo(buf:haxe.io.Bytes, pos:Int, len:Int, addr:Address):Int {
return try {
socket_send_to(__s, buf.getData(), pos, len, addr);
} catch (e:Dynamic) {
if (e == "Blocking")
throw Blocked;
else
throw Custom(e);
}
}
public function readFrom(buf:haxe.io.Bytes, pos:Int, len:Int, addr:Address):Int {
var r;
try {
r = socket_recv_from(__s, buf.getData(), pos, len, addr);
} catch (e:Dynamic) {
if (e == "Blocking")
throw Blocked;
else
throw Custom(e);
}
if (r == 0)
throw new haxe.io.Eof();
return r;
}
public function setBroadcast(b:Bool):Void {
socket_set_broadcast(__s, b);
}
static var socket_recv_from = neko.Lib.loadLazy("std", "socket_recv_from", 5);
static var socket_send_to = neko.Lib.loadLazy("std", "socket_send_to", 5);
static var socket_set_broadcast = neko.Lib.loadLazy("std", "socket_set_broadcast", 2);
}

View File

@ -0,0 +1,150 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.ssl;
@:coreApi
class Certificate {
var __h:Null<Certificate>;
var __x:Dynamic;
@:allow(sys.ssl.Socket)
function new(x:Dynamic, ?h:Certificate) {
__x = x;
__h = h;
}
public static function loadFile(file:String):Certificate {
return new Certificate(cert_load_file(untyped file.__s));
}
public static function loadPath(path:String):Certificate {
return new Certificate(cert_load_path(untyped path.__s));
}
public static function fromString(str:String):Certificate {
return new Certificate(cert_add_pem(null, untyped str.__s));
}
public static function loadDefaults():Certificate {
var x = cert_load_defaults();
if (x != null)
return new Certificate(x);
var defPaths = null;
switch (Sys.systemName()) {
case "Linux":
defPaths = [
"/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo etc.
"/etc/pki/tls/certs/ca-bundle.crt", // Fedora/RHEL
"/etc/ssl/ca-bundle.pem", // OpenSUSE
"/etc/pki/tls/cacert.pem", // OpenELEC
"/etc/ssl/certs", // SLES10/SLES11
"/system/etc/security/cacerts" // Android
];
case "BSD":
defPaths = [
"/usr/local/share/certs/ca-root-nss.crt", // FreeBSD/DragonFly
"/etc/ssl/cert.pem", // OpenBSD
"/etc/openssl/certs/ca-certificates.crt", // NetBSD
];
case "Android":
defPaths = ["/system/etc/security/cacerts"];
default:
}
if (defPaths != null) {
for (path in defPaths) {
if (sys.FileSystem.exists(path)) {
if (sys.FileSystem.isDirectory(path))
return loadPath(path);
else
return loadFile(path);
}
}
}
return null;
}
public var commonName(get, null):Null<String>;
public var altNames(get, null):Array<String>;
public var notBefore(get, null):Date;
public var notAfter(get, null):Date;
function get_commonName():Null<String> {
return subject("CN");
}
function get_altNames():Array<String> {
var l:Dynamic = cert_get_altnames(__x);
var a = new Array<String>();
while (l != null) {
a.push(new String(l[0]));
l = l[1];
}
return a;
}
public function subject(field:String):Null<String> {
var s = cert_get_subject(__x, untyped field.__s);
return s == null ? null : new String(cast s);
}
public function issuer(field:String):Null<String> {
var s = cert_get_issuer(__x, untyped field.__s);
return s == null ? null : new String(cast s);
}
function get_notBefore():Date {
var a = cert_get_notbefore(__x);
return new Date(a[0], a[1] - 1, a[2], a[3], a[4], a[5]);
}
function get_notAfter():Date {
var a = cert_get_notafter(__x);
return new Date(a[0], a[1] - 1, a[2], a[3], a[4], a[5]);
}
public function next():Null<Certificate> {
var n = cert_get_next(__x);
return n == null ? null : new Certificate(n, __h == null ? this : __h);
}
public function add(pem:String):Void {
cert_add_pem(__x, untyped pem.__s);
}
public function addDER(der:haxe.io.Bytes):Void {
cert_add_der(__x, der.getData());
}
private static var cert_load_defaults = neko.Lib.loadLazy("ssl", "cert_load_defaults", 0);
private static var cert_load_file = neko.Lib.loadLazy("ssl", "cert_load_file", 1);
private static var cert_load_path = neko.Lib.loadLazy("ssl", "cert_load_path", 1);
private static var cert_get_subject = neko.Lib.loadLazy("ssl", "cert_get_subject", 2);
private static var cert_get_issuer = neko.Lib.loadLazy("ssl", "cert_get_issuer", 2);
private static var cert_get_altnames = neko.Lib.loadLazy("ssl", "cert_get_altnames", 1);
private static var cert_get_notbefore = neko.Lib.loadLazy("ssl", "cert_get_notbefore", 1);
private static var cert_get_notafter = neko.Lib.loadLazy("ssl", "cert_get_notafter", 1);
private static var cert_get_next = neko.Lib.loadLazy("ssl", "cert_get_next", 1);
private static var cert_add_pem = neko.Lib.loadLazy("ssl", "cert_add_pem", 2);
private static var cert_add_der = neko.Lib.loadLazy("ssl", "cert_add_der", 2);
}

View File

@ -0,0 +1,42 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.ssl;
@:coreApi
class Digest {
public static function make(data:haxe.io.Bytes, alg:DigestAlgorithm):haxe.io.Bytes {
return haxe.io.Bytes.ofData(dgst_make(data.getData(), untyped alg.__s));
}
public static function sign(data:haxe.io.Bytes, privKey:Key, alg:DigestAlgorithm):haxe.io.Bytes {
return haxe.io.Bytes.ofData(dgst_sign(data.getData(), @:privateAccess privKey.__k, untyped alg.__s));
}
public static function verify(data:haxe.io.Bytes, signature:haxe.io.Bytes, pubKey:Key, alg:DigestAlgorithm):Bool {
return dgst_verify(data.getData(), signature.getData(), @:privateAccess pubKey.__k, untyped alg.__s);
}
private static var dgst_make = neko.Lib.loadLazy("ssl", "dgst_make", 2);
private static var dgst_sign = neko.Lib.loadLazy("ssl", "dgst_sign", 3);
private static var dgst_verify = neko.Lib.loadLazy("ssl", "dgst_verify", 4);
}

View File

@ -0,0 +1,54 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.ssl;
private typedef PKEY = Dynamic;
@:coreApi
class Key {
private var __k:PKEY;
private function new(k:PKEY) {
__k = k;
}
public static function loadFile(file:String, ?isPublic:Bool, ?pass:String):Key {
var data = sys.io.File.getBytes(file);
var str = neko.Lib.stringReference(data);
if (str.indexOf("-----BEGIN ") >= 0)
return readPEM(str, isPublic == true, pass);
else
return readDER(data, isPublic == true);
}
public static function readPEM(data:String, isPublic:Bool, ?pass:String):Key {
return new Key(key_from_pem(untyped data.__s, isPublic, pass == null ? null : untyped pass.__s));
}
public static function readDER(data:haxe.io.Bytes, isPublic:Bool):Key {
return new Key(key_from_der(data.getData(), isPublic));
}
private static var key_from_pem = neko.Lib.loadLazy("ssl", "key_from_pem", 3);
private static var key_from_der = neko.Lib.loadLazy("ssl", "key_from_der", 2);
}

View File

@ -0,0 +1,316 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.ssl;
private typedef SocketHandle = Dynamic;
private typedef CTX = Dynamic;
private typedef SSL = Dynamic;
private class SocketInput extends haxe.io.Input {
@:allow(sys.ssl.Socket) private var __s:Socket;
public function new(s:Socket) {
this.__s = s;
}
public override function readByte() {
return try {
__s.handshake();
ssl_recv_char(@:privateAccess __s.ssl);
} catch (e:Dynamic) {
if (e == "Blocking")
throw haxe.io.Error.Blocked;
else if (__s == null)
throw haxe.io.Error.Custom(e);
else
throw new haxe.io.Eof();
}
}
public override function readBytes(buf:haxe.io.Bytes, pos:Int, len:Int):Int {
var r:Int;
if (__s == null)
throw "Invalid handle";
try {
__s.handshake();
r = ssl_recv(@:privateAccess __s.ssl, buf.getData(), pos, len);
} catch (e:Dynamic) {
if (e == "Blocking")
throw haxe.io.Error.Blocked;
else
throw haxe.io.Error.Custom(e);
}
if (r == 0)
throw new haxe.io.Eof();
return r;
}
public override function close() {
super.close();
if (__s != null)
__s.close();
}
private static var ssl_recv = neko.Lib.loadLazy("ssl", "ssl_recv", 4);
private static var ssl_recv_char = neko.Lib.loadLazy("ssl", "ssl_recv_char", 1);
}
private class SocketOutput extends haxe.io.Output {
@:allow(sys.ssl.Socket) private var __s:Socket;
public function new(s:Socket) {
this.__s = s;
}
public override function writeByte(c:Int) {
if (__s == null)
throw "Invalid handle";
try {
__s.handshake();
ssl_send_char(@:privateAccess __s.ssl, c);
} catch (e:Dynamic) {
if (e == "Blocking")
throw haxe.io.Error.Blocked;
else
throw haxe.io.Error.Custom(e);
}
}
public override function writeBytes(buf:haxe.io.Bytes, pos:Int, len:Int):Int {
return try {
__s.handshake();
ssl_send(@:privateAccess __s.ssl, buf.getData(), pos, len);
} catch (e:Dynamic) {
if (e == "Blocking")
throw haxe.io.Error.Blocked;
else
throw haxe.io.Error.Custom(e);
}
}
public override function close() {
super.close();
if (__s != null)
__s.close();
}
private static var ssl_send_char = neko.Lib.loadLazy("ssl", "ssl_send_char", 2);
private static var ssl_send = neko.Lib.loadLazy("ssl", "ssl_send", 4);
}
@:coreApi
class Socket extends sys.net.Socket {
public static var DEFAULT_VERIFY_CERT:Null<Bool> = true;
public static var DEFAULT_CA:Null<Certificate>;
private var ctx:CTX;
private var ssl:SSL;
public var verifyCert:Null<Bool>;
private var caCert:Null<Certificate>;
private var hostname:String;
private var ownCert:Null<Certificate>;
private var ownKey:Null<Key>;
private var altSNIContexts:Null<Array<{match:String->Bool, key:Key, cert:Certificate}>>;
private var sniCallback:Dynamic;
private var handshakeDone:Bool;
private override function init():Void {
__s = socket_new(false);
input = new SocketInput(this);
output = new SocketOutput(this);
if (DEFAULT_VERIFY_CERT && DEFAULT_CA == null) {
try {
DEFAULT_CA = Certificate.loadDefaults();
} catch (e:Dynamic) {}
}
verifyCert = DEFAULT_VERIFY_CERT;
caCert = DEFAULT_CA;
}
public override function connect(host:sys.net.Host, port:Int):Void {
try {
ctx = buildSSLContext(false);
ssl = ssl_new(ctx);
ssl_set_socket(ssl, __s);
handshakeDone = false;
if (hostname == null)
hostname = host.host;
if (hostname != null)
ssl_set_hostname(ssl, untyped hostname.__s);
socket_connect(__s, host.ip, port);
handshake();
} catch (s:String) {
if (s == "std@socket_connect")
throw "Failed to connect on " + host.host + ":" + port;
else
neko.Lib.rethrow(s);
} catch (e:Dynamic) {
neko.Lib.rethrow(e);
}
}
public function handshake():Void {
if (!handshakeDone) {
try {
ssl_handshake(ssl);
handshakeDone = true;
} catch (e:Dynamic) {
if (e == "Blocking")
throw haxe.io.Error.Blocked;
else
neko.Lib.rethrow(e);
}
}
}
public function setCA(cert:Certificate):Void {
caCert = cert;
}
public function setHostname(name:String):Void {
hostname = name;
}
public function setCertificate(cert:Certificate, key:Key):Void {
ownCert = cert;
ownKey = key;
}
public override function read():String {
handshake();
var b = ssl_read(ssl);
if (b == null)
return "";
return new String(cast b);
}
public override function write(content:String):Void {
handshake();
ssl_write(ssl, untyped content.__s);
}
public override function close():Void {
if (ssl != null)
ssl_close(ssl);
if (ctx != null)
conf_close(ctx);
if (altSNIContexts != null)
sniCallback = null;
socket_close(__s);
var input:SocketInput = cast input;
var output:SocketOutput = cast output;
@:privateAccess input.__s = output.__s = null;
input.close();
output.close();
}
public function addSNICertificate(cbServernameMatch:String->Bool, cert:Certificate, key:Key):Void {
if (altSNIContexts == null)
altSNIContexts = [];
altSNIContexts.push({match: cbServernameMatch, cert: cert, key: key});
}
public override function bind(host:sys.net.Host, port:Int):Void {
ctx = buildSSLContext(true);
socket_bind(__s, host.ip, port);
}
public override function accept():Socket {
var c = socket_accept(__s);
var ssl = ssl_new(ctx);
ssl_set_socket(ssl, c);
var s = Type.createEmptyInstance(sys.ssl.Socket);
s.__s = c;
s.ssl = ssl;
s.input = new SocketInput(s);
s.output = new SocketOutput(s);
s.handshakeDone = false;
return s;
}
public function peerCertificate():sys.ssl.Certificate {
var x = ssl_get_peer_certificate(ssl);
return x == null ? null : new sys.ssl.Certificate(x);
}
private function buildSSLContext(server:Bool):CTX {
var ctx:CTX = conf_new(server);
if (ownCert != null && ownKey != null)
conf_set_cert(ctx, @:privateAccess ownCert.__x, @:privateAccess ownKey.__k);
if (altSNIContexts != null) {
sniCallback = function(servername) {
var servername = new String(cast servername);
for (c in altSNIContexts) {
if (c.match(servername))
return @:privateAccess {
key:c.key.__k, cert:c.cert.__x
};
}
if (ownKey != null && ownCert != null)
return @:privateAccess {
key:ownKey.__k, cert:ownCert.__x
};
return null;
}
conf_set_servername_callback(ctx, sniCallback);
}
if (caCert != null)
conf_set_ca(ctx, caCert == null ? null : @:privateAccess caCert.__x);
conf_set_verify(ctx, verifyCert);
return ctx;
}
private static var ssl_new = neko.Lib.loadLazy("ssl", "ssl_new", 1);
private static var ssl_close = neko.Lib.loadLazy("ssl", "ssl_close", 1);
private static var ssl_handshake = neko.Lib.loadLazy("ssl", "ssl_handshake", 1);
private static var ssl_set_socket = neko.Lib.loadLazy("ssl", "ssl_set_socket", 2);
private static var ssl_set_hostname = neko.Lib.loadLazy("ssl", "ssl_set_hostname", 2);
private static var ssl_get_peer_certificate = neko.Lib.loadLazy("ssl", "ssl_get_peer_certificate", 1);
private static var ssl_read = neko.Lib.loadLazy("ssl", "ssl_read", 1);
private static var ssl_write = neko.Lib.loadLazy("ssl", "ssl_write", 2);
private static var conf_new = neko.Lib.loadLazy("ssl", "conf_new", 1);
private static var conf_close = neko.Lib.loadLazy("ssl", "conf_close", 1);
private static var conf_set_ca = neko.Lib.loadLazy("ssl", "conf_set_ca", 2);
private static var conf_set_verify = neko.Lib.loadLazy("ssl", "conf_set_verify", 2);
private static var conf_set_cert = neko.Lib.loadLazy("ssl", "conf_set_cert", 3);
private static var conf_set_servername_callback = neko.Lib.loadLazy("ssl", "conf_set_servername_callback", 2);
private static var socket_new = neko.Lib.load("std", "socket_new", 1);
private static var socket_close = neko.Lib.load("std", "socket_close", 1);
private static var socket_connect = neko.Lib.load("std", "socket_connect", 3);
private static var socket_bind = neko.Lib.load("std", "socket_bind", 3);
private static var socket_accept = neko.Lib.load("std", "socket_accept", 1);
}

View File

@ -0,0 +1,49 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.thread;
@:coreApi
class Deque<T> {
var q:Dynamic;
public function new() {
q = deque_create();
}
public function add(i:T):Void {
deque_add(q, i);
}
public function push(i:T):Void {
deque_push(q, i);
}
public function pop(block:Bool):Null<T> {
return deque_pop(q, block);
}
static var deque_create = neko.Lib.loadLazy("std", "deque_create", 0);
static var deque_add = neko.Lib.loadLazy("std", "deque_add", 2);
static var deque_push = neko.Lib.loadLazy("std", "deque_push", 2);
static var deque_pop = neko.Lib.loadLazy("std", "deque_pop", 2);
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.thread;
@:coreApi
class Lock {
var l:Dynamic;
public function new() {
l = lock_create();
}
public function wait(?timeout:Float):Bool {
return lock_wait(l, timeout);
}
public function release():Void {
lock_release(l);
}
static var lock_create = neko.Lib.load("std", "lock_create", 0);
static var lock_release = neko.Lib.load("std", "lock_release", 1);
static var lock_wait = neko.Lib.load("std", "lock_wait", 2);
}

View File

@ -0,0 +1,49 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.thread;
@:coreApi
class Mutex {
var m:Dynamic;
public function new():Void {
m = mutex_create();
}
public function acquire():Void {
mutex_acquire(m);
}
public function tryAcquire():Bool {
return mutex_try(m);
}
public function release():Void {
mutex_release(m);
}
static var mutex_create = neko.Lib.loadLazy("std", "mutex_create", 0);
static var mutex_release = neko.Lib.loadLazy("std", "mutex_release", 1);
static var mutex_acquire = neko.Lib.loadLazy("std", "mutex_acquire", 1);
static var mutex_try = neko.Lib.loadLazy("std", "mutex_try", 1);
}

View File

@ -0,0 +1,188 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.thread;
private typedef ThreadImpl = HaxeThread;
abstract Thread(ThreadImpl) from ThreadImpl {
public var events(get,never):EventLoop;
public inline function sendMessage(msg:Dynamic):Void {
this.sendMessage(msg);
}
public static inline function current():Thread {
return HaxeThread.current();
}
public static inline function create(job:()->Void):Thread {
return HaxeThread.create(job, false);
}
public static inline function runWithEventLoop(job:()->Void):Void {
HaxeThread.runWithEventLoop(job);
}
public static inline function createWithEventLoop(job:()->Void):Thread {
return HaxeThread.create(job, true);
}
public static inline function readMessage(block:Bool):Dynamic {
return HaxeThread.readMessage(block);
}
function get_events():EventLoop {
if(this.events == null)
throw new NoEventLoopException();
return this.events;
}
@:keep
static function processEvents() {
HaxeThread.current().events.loop();
}
}
@:callable
@:coreType
private abstract NativeThreadHandle {}
private typedef ThreadHandle = NativeThreadHandle;
private class HaxeThread {
static var thread_create:(callb:(_:Dynamic)->Void, _:Dynamic)->ThreadHandle;
static var thread_current:()->ThreadHandle;
static var thread_send:(handle:ThreadHandle, msg:Dynamic)->Void;
static var thread_read_message:(block:Bool)->Dynamic;
static var mainThreadHandle:ThreadHandle;
static var mainThread:HaxeThread;
static var threads:Array<{thread:HaxeThread, handle:ThreadHandle}>;
static var threadsMutex:Mutex;
static function __init__() {
thread_create = neko.Lib.load("std", "thread_create", 2);
thread_current = neko.Lib.load("std", "thread_current", 0);
thread_send = neko.Lib.load("std", "thread_send", 2);
thread_read_message = neko.Lib.load("std", "thread_read_message", 1);
mainThreadHandle = thread_current();
mainThread = new HaxeThread(mainThreadHandle);
mainThread.events = new EventLoop();
threads = [];
threadsMutex = new Mutex();
}
public var events(default,null):Null<EventLoop>;
public var handle:ThreadHandle;
static public function current():HaxeThread {
var handle = thread_current();
if(handle == mainThreadHandle) {
return mainThread;
}
threadsMutex.acquire();
var thread = null;
for(item in threads) {
if(item.handle == handle) {
thread = item.thread;
break;
}
}
if(thread == null) {
thread = new HaxeThread(handle);
threads.push({thread:thread, handle:handle});
}
threadsMutex.release();
return thread;
}
public static function create(callb:()->Void, withEventLoop:Bool):Thread {
var item = {handle:null, thread:new HaxeThread(null)};
threadsMutex.acquire();
threads.push(item);
threadsMutex.release();
if(withEventLoop)
item.thread.events = new EventLoop();
item.handle = thread_create(_ -> {
if(item.thread.handle == null) {
item.handle = thread_current();
item.thread.handle = item.handle;
}
try {
callb();
if(withEventLoop)
item.thread.events.loop();
} catch(e) {
dropThread(item);
throw e;
}
dropThread(item);
}, null);
item.thread.handle = item.handle;
return item.thread;
}
public static function runWithEventLoop(job:()->Void):Void {
var thread = current();
if(thread.events == null) {
thread.events = new EventLoop();
try {
job();
thread.events.loop();
thread.events = null;
} catch(e) {
thread.events = null;
throw e;
}
} else {
job();
}
}
static function dropThread(deleteItem) {
threadsMutex.acquire();
for(i => item in threads) {
if(item == deleteItem) {
threads.splice(i, 1);
break;
}
}
threadsMutex.release();
}
public static inline function readMessage(block:Bool):Dynamic {
return thread_read_message(block);
}
public function new(handle:ThreadHandle) {
this.handle = handle;
}
public function sendMessage(msg:Dynamic) {
thread_send(handle, msg);
}
}

View File

@ -0,0 +1,47 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package sys.thread;
@:coreApi
class Tls<T> {
var t:Dynamic;
public var value(get, set):T;
public function new() {
t = tls_create();
}
function get_value():T {
return tls_get(t);
}
function set_value(v:T):T {
tls_set(t, v);
return v;
}
static var tls_create = neko.Lib.load("std", "tls_create", 0);
static var tls_get = neko.Lib.load("std", "tls_get", 1);
static var tls_set = neko.Lib.load("std", "tls_set", 2);
}

View File

@ -0,0 +1,25 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko.vm;
@:deprecated typedef Deque<T> = sys.thread.Deque<T>;

View File

@ -0,0 +1,46 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko.vm;
/**
Neko garbage collector utility.
*/
class Gc {
/**
Run the Neko garbage collector.
**/
public static function run(major:Bool) {
_run(major);
}
/**
Return the size of the GC heap and the among of free space,
in bytes.
**/
public static function stats():{heap:Int, free:Int} {
return _stats();
}
static var _run = neko.Lib.load("std", "run_gc", 1);
static var _stats = neko.Lib.load("std", "gc_stats", 0);
}

View File

@ -0,0 +1,162 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko.vm;
/**
The Neko object that implements the loader.
**/
@:callable
@:coreType
abstract LoaderHandle {}
/**
Loaders can be used to dynamically load Neko primitives stored in NDLL libraries.
Loaders can be used to dynamically load other Neko modules (.n bytecode files).
Modules are referenced by names. To lookup the corresponding bytecode file, the
default loader first look in its cache, then eventually adds the .n extension
to the name and lookup the bytecode in its path.
Loaders can be used for sandbox security. When a Module is loaded with a given
Loader, this loader can manager the module security by filtering which
primitives can be loaded by this module or by rewrapping them at loading-time
with custom secured versions. Loaders are inherited in loaded submodules.
**/
class Loader {
/**
The abstract handle.
**/
public var l:LoaderHandle;
public function new(l) {
this.l = l;
}
/**
The default loader contains a search path in its `path` field. It's a
linked list of Neko strings that is a parsed version of the `NEKOPATH`.
This path is used to lookup for modules and libraries.
**/
public function getPath() {
var p = untyped l.path;
var path = new Array<String>();
while (p != null) {
path.push(new String(p[0]));
p = cast p[1];
}
return path;
}
/**
Adds a directory to the search path. See `getPath`.
**/
public function addPath(s:String) {
untyped l.path = __dollar__array(s.__s, l.path);
}
/**
The default loader contains a cache of already loaded modules. It's
ensuring that the same module does not get loaded twice when circular
references are occurring. The same module can eventually be loaded twice
but with different names, for example with two relative paths representing
the same file, since the cache is done on a by-name basic.
**/
public function getCache():Map<String, Module> {
var h = new haxe.ds.StringMap<Module>();
var cache = untyped l.cache;
for (f in Reflect.fields(cache))
h.set(f, new Module(Reflect.field(cache, f)));
return h;
}
/**
Set a module in the loader cache.
**/
public function setCache(name:String, m:Module) {
if (m == null)
Reflect.deleteField(untyped l.cache, name);
else
Reflect.setField(untyped l.cache, name, m.m);
}
/**
Change the cache value and returns the old value. This can be used
to backup the loader cache and restore it later.
**/
public function backupCache(c:Dynamic):Dynamic {
var old = untyped l.cache;
untyped l.cache = c;
return old;
}
function __compare(other:Loader) {
return untyped __dollar__compare(this.l, other.l);
}
/**
Loads a neko primitive. By default, the name is of the form `[library@method]`.
The primitive might not be used directly in Haxe since some of the Neko values
needs an object wrapper in Haxe.
**/
public function loadPrimitive(prim:String, nargs:Int):Dynamic {
return untyped l.loadprim(prim.__s, nargs);
}
/**
Loads a Module with the given name. If `loader` is defined, this will be
this Module loader, else this loader will be inherited. When loaded this
way, the module is directly executed.
**/
public function loadModule(modName:String, ?loader:Loader):Module {
var exp = untyped l.loadmodule(modName.__s, if (loader == null) l else loader.l);
return new Module(exp.__module);
}
/**
Returns the local Loader. This is the loader that was used to load the
module in which the code is defined.
**/
public static function local() {
return new Loader(untyped __dollar__loader);
}
/**
Creates a loader using two methods. This loader will not have an accessible cache or path,
although you can implement such mechanism in the methods body.
**/
public static function make(loadPrim:String->Int->Dynamic, loadModule:String->Loader->Module) {
var l = {
loadprim: function(prim, nargs) {
return loadPrim(new String(prim), nargs);
},
loadmodule: function(mname, loader) {
return loadModule(new String(mname), new Loader(loader)).exportsTable();
},
args: untyped __dollar__amake(0),
cache: {},
};
return new Loader(cast l);
}
}

View File

@ -0,0 +1,25 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko.vm;
@:deprecated typedef Lock = sys.thread.Lock;

View File

@ -0,0 +1,222 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko.vm;
/**
The abstract Neko module handle.
**/
@:callable
@:coreType
abstract ModuleHandle {}
/**
A Neko Module represent a execution unit for the Neko Virtual Machine.
Each compiled `.n` bytecode file is a module once loaded by the NekoVM.
**/
class Module {
/**
The abstract handle.
**/
public var m:ModuleHandle;
public var name(get, set):String;
public function new(m) {
this.m = m;
}
/**
Execute a module and returns its result (the latest evaluated expression).
A module can be executed several times but its globals are only initialized once
the first time the Module is loaded.
**/
public function execute():Dynamic {
return _module_exec(m);
}
function get_name() {
return new String(_module_name(m));
}
function set_name(n:String) {
_module_set_name(m, untyped n.__s);
return n;
}
/**
Returns the Loader that this Module was loaded with.
**/
public function loader() {
return new Loader(_module_loader(m));
}
/**
Returns the codeSize of the Module.
**/
public function codeSize():Int {
return _module_code_size(m);
}
/**
Returns the number of globals in this Module global table.
**/
public function globalsCount():Int {
return _module_nglobals(m);
}
/**
Get a Module global value.
**/
public function getGlobal(n:Int):Dynamic {
return _module_global_get(m, n);
}
/**
Set a Module global value.
**/
public function setGlobal(n:Int, v:Dynamic) {
_module_global_set(m, n, v);
}
public function toString() {
return "[Module:" + name + "]";
}
/**
Each Module has an export table which can be useful to transfert
values between modules.
**/
public function getExports():Map<String, Dynamic> {
var h = new haxe.ds.StringMap();
var exp = _module_exports(m);
for (f in Reflect.fields(exp))
h.set(f, Reflect.field(exp, f));
return h;
}
/**
The raw export table.
**/
public function exportsTable():Dynamic {
return _module_exports(m);
}
/**
Set a value in the Module export table.
**/
public function setExport(name:String, value:Dynamic) {
var exp = _module_exports(m);
Reflect.setField(exp, name, value);
}
/**
Returns the local Module, which is the one in which this
method is included.
**/
public static function local() {
return new Module(untyped __dollar__exports.__module);
}
/**
Reads a module from an Input by using the given Loader.
The module is initialized but has not yet been executed.
**/
public static function read(i:haxe.io.Input, l:Loader):Module {
var m = _module_read(function(buf, pos, len) {
return i.readBytes(untyped new haxe.io.Bytes(len, buf), pos, len);
}, l.l);
return new Module(m);
}
/**
Reads a module from Bytes using the given Loader.
The module is initialized but has not yet been executed.
**/
public static function readBytes(b:haxe.io.Bytes, loader:Loader):Module {
return new Module(_module_read_string(b.getData(), loader.l));
}
/**
Reads a module from a name and using the specified seach path and loader.
The module is initialized but has not yet been executed.
**/
public static function readPath(name:String, path:Array<String>, loader:Loader) {
var p = null;
var i = path.length;
while (--i >= 0)
p = untyped __dollar__array(path[i].__s, p);
var m = _module_read_path(p, untyped name.__s, loader.l);
return new Module(m);
}
/**
Extract the globals names from the given module
**/
public static function readGlobalsNames(i:haxe.io.Input) {
if (i.readByte() != 0x4E || i.readByte() != 0x45 || i.readByte() != 0x4B || i.readByte() != 0x4F)
throw "Not a neko file";
function readInt() {
return i.readInt32();
}
var nglobals = readInt();
/*var nfields =*/ readInt();
/*var codesize =*/ readInt();
var a = new Array();
for (k in 0...nglobals) {
switch (i.readByte()) {
case 1:
a.push(i.readUntil(0));
case 2:
a.push("<fun:" + (readInt() & 0xFFFFFF) + ">");
case 3:
a.push("STRING:" + i.readString(i.readUInt16()));
case 4:
a.push("FLOAT:" + i.readUntil(0));
case 5:
a.push("DEBUG");
case 6:
a.push("VERSION " + i.readByte());
default:
throw "assert";
}
}
return a;
}
function __compare(other:Module) {
return untyped __dollar__compare(this.m, other.m);
}
static var _module_read = neko.Lib.load("std", "module_read", 2);
static var _module_read_path = neko.Lib.load("std", "module_read_path", 3);
static var _module_exec = neko.Lib.load("std", "module_exec", 1);
static var _module_name = neko.Lib.load("std", "module_name", 1);
static var _module_exports = neko.Lib.load("std", "module_exports", 1);
static var _module_loader = neko.Lib.load("std", "module_loader", 1);
static var _module_code_size = neko.Lib.load("std", "module_code_size", 1);
static var _module_nglobals = neko.Lib.load("std", "module_nglobals", 1);
static var _module_global_get = neko.Lib.load("std", "module_global_get", 2);
static var _module_global_set = neko.Lib.load("std", "module_global_set", 3);
static var _module_read_string = neko.Lib.loadLazy("std", "module_read_string", 2);
static var _module_set_name = neko.Lib.loadLazy("std", "module_set_name", 2);
}

View File

@ -0,0 +1,25 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko.vm;
@:deprecated typedef Mutex = sys.thread.Mutex;

View File

@ -0,0 +1,25 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko.vm;
@:deprecated typedef Thread = sys.thread.Thread;

View File

@ -0,0 +1,25 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko.vm;
@:deprecated typedef Tls<T> = sys.thread.Tls<T>;

View File

@ -0,0 +1,88 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko.vm;
/**
Core native User Interface support. This API uses native WIN32 API
on Windows, Carbon API on OSX, and GTK2 on Linux.
*/
class Ui {
/**
Tells if the current thread is the main loop thread or not.
The main loop thread is the one in which the first "ui"
library primitive has been loaded.
**/
public static function isMainThread() {
return _is_main_thread();
}
/**
Starts the native UI event loop. This method can only be called
from the main thread.
**/
public static function loop() {
_loop();
}
/**
Stop the native UI event loop. This method can only be called
from the main thread.
**/
public static function stopLoop() {
_sync(_stop_loop);
}
/**
Queue a method call callb to be executed by the main thread while
running the UI event loop. This can be used to perform UI updates
in the UI thread using results processed by another thread.
**/
public static function sync(f:Void->Void) {
_sync(f);
}
public static function syncResult<T>(f:Void->T):T {
if (isMainThread())
return f();
var l = new Lock();
var tmp = null;
var exc = null;
_sync(function() {
try {
tmp = f();
} catch (e:Dynamic) {
exc = {v: e};
}
l.release();
});
l.wait();
if (exc != null)
throw exc.v;
return tmp;
}
static var _is_main_thread = neko.Lib.load("ui", "ui_is_main", 0);
static var _loop = neko.Lib.load("ui", "ui_loop", 0);
static var _stop_loop = neko.Lib.load("ui", "ui_stop_loop", 0);
static var _sync = neko.Lib.load("ui", "ui_sync", 1);
}

View File

@ -0,0 +1,25 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko.zip;
typedef Compress = haxe.zip.Compress;

View File

@ -0,0 +1,25 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko.zip;
typedef Flush = haxe.zip.FlushMode;

View File

@ -0,0 +1,25 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package neko.zip;
typedef Uncompress = haxe.zip.Uncompress;