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,28 @@
/*
* 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 python.internal;
@:native("_hx_AnonObject")
class AnonObject {
public function new(fields:python.Dict<String, Dynamic>) {}
}

View File

@ -0,0 +1,206 @@
/*
* 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 python.internal;
import python.lib.Functools;
@:allow(Array)
class ArrayImpl {
@:ifFeature("dynamic_read.length", "anon_optional_read.length", "python.internal.ArrayImpl.length")
public static inline function get_length<T>(x:Array<T>):Int
return UBuiltins.len(x);
@:ifFeature("dynamic_read.concat", "anon_optional_read.concat", "python.internal.ArrayImpl.concat")
public static inline function concat<T>(a1:Array<T>, a2:Array<T>):Array<T> {
return Syntax.binop(a1, "+", a2);
}
@:ifFeature("dynamic_read.copy", "anon_optional_read.copy", "python.internal.ArrayImpl.copy")
public static inline function copy<T>(x:Array<T>):Array<T> {
return UBuiltins.list(x);
}
@:ifFeature("dynamic_read.iterator", "anon_optional_read.iterator", "python.internal.ArrayImpl.iterator")
public static inline function iterator<T>(x:Array<T>):Iterator<T> {
return new HaxeIterator(Syntax.callField(x, "__iter__"));
}
@:ifFeature("dynamic_read.keyValueIterator", "anon_optional_read.keyValueIterator", "python.internal.ArrayImpl.keyValueIterator")
public static inline function keyValueIterator<T>(x:Array<T>) : KeyValueIterator<Int, T> {
return new haxe.iterators.ArrayKeyValueIterator(x);
}
@:ifFeature("dynamic_read.indexOf", "anon_optional_read.indexOf", "python.internal.ArrayImpl.indexOf")
public static function indexOf<T>(a:Array<T>, x:T, ?fromIndex:Int):Int {
var len = a.length;
var l = if (fromIndex == null) 0 else if (fromIndex < 0) len + fromIndex else fromIndex;
if (l < 0)
l = 0;
for (i in l...len) {
if (unsafeGet(a, i) == x)
return i;
}
return -1;
}
@:ifFeature("dynamic_read.lastIndexOf", "anon_optional_read.lastIndexOf", "python.internal.ArrayImpl.lastIndexOf")
public static function lastIndexOf<T>(a:Array<T>, x:T, ?fromIndex:Int):Int {
var len = a.length;
var l = if (fromIndex == null) len else if (fromIndex < 0) len + fromIndex + 1 else fromIndex + 1;
if (l > len)
l = len;
while (--l > -1) {
if (unsafeGet(a, l) == x)
return l;
}
return -1;
}
@:access(python.Boot)
@:ifFeature("dynamic_read.join", "anon_optional_read.join", "python.internal.ArrayImpl.join")
public static inline function join<T>(x:Array<T>, sep:String):String {
return Boot.arrayJoin(x, sep);
}
@:ifFeature("dynamic_read.toString", "anon_optional_read.toString", "python.internal.ArrayImpl.toString")
public static inline function toString<T>(x:Array<T>):String {
return "[" + join(x, ",") + "]";
}
@:ifFeature("dynamic_read.pop", "anon_optional_read.pop", "python.internal.ArrayImpl.pop")
public static inline function pop<T>(x:Array<T>):Null<T> {
return if (x.length == 0) null else Syntax.callField(x, "pop");
}
@:ifFeature("dynamic_read.push", "anon_optional_read.push", "python.internal.ArrayImpl.push")
public static inline function push<T>(x:Array<T>, e:T):Int {
Syntax.callField(x, "append", e);
return x.length;
}
@:ifFeature("dynamic_read.unshift", "anon_optional_read.unshift", "python.internal.ArrayImpl.unshift")
public static inline function unshift<T>(x:Array<T>, e:T):Void {
x.insert(0, e);
}
@:ifFeature("dynamic_read.remove", "anon_optional_read.remove", "python.internal.ArrayImpl.remove")
public static function remove<T>(x:Array<T>, e:T):Bool {
try {
Syntax.callField(x, "remove", e);
return true;
} catch (e:Dynamic) {
return false;
}
}
@:ifFeature("dynamic_read.contains", "anon_optional_read.contains", "python.internal.ArrayImpl.contains")
public static inline function contains<T>(x:Array<T>,e : T) : Bool {
return Syntax.isIn(e, x);
}
@:ifFeature("dynamic_read.shift", "anon_optional_read.shift", "python.internal.ArrayImpl.shift")
public static inline function shift<T>(x:Array<T>):Null<T> {
if (x.length == 0)
return null;
return Syntax.callField(x, "pop", 0);
}
@:ifFeature("dynamic_read.slice", "anon_optional_read.slice", "python.internal.ArrayImpl.slice")
public static inline function slice<T>(x:Array<T>, pos:Int, ?end:Int):Array<T> {
return Syntax.arrayAccess(x, pos, end);
}
@:ifFeature("dynamic_read.sort", "anon_optional_read.sort", "python.internal.ArrayImpl.sort")
public static inline function sort<T>(x:Array<T>, f:T->T->Int):Void {
Syntax.callNamedUntyped(Syntax.field(x, "sort"), {key: Functools.cmp_to_key(f)});
}
@:ifFeature("dynamic_read.splice", "anon_optional_read.splice", "python.internal.ArrayImpl.splice")
public static inline function splice<T>(x:Array<T>, pos:Int, len:Int):Array<T> {
if (pos < 0)
pos = x.length + pos;
if (pos < 0)
pos = 0;
var res = Syntax.arrayAccess(x, pos, pos + len);
Syntax.delete((Syntax.arrayAccess(x, pos, pos + len)));
return res;
}
@:ifFeature("dynamic_read.map", "anon_optional_read.map", "python.internal.ArrayImpl.map")
public static inline function map<S, T>(x:Array<T>, f:T->S):Array<S> {
return UBuiltins.list(UBuiltins.map(f, cast x));
}
@:ifFeature("dynamic_read.filter", "anon_optional_read.filter", "python.internal.ArrayImpl.filter")
public static inline function filter<T>(x:Array<T>, f:T->Bool):Array<T> {
return UBuiltins.list(UBuiltins.filter(f, cast x));
}
@:ifFeature("dynamic_read.insert", "anon_optional_read.insert", "python.internal.ArrayImpl.insert")
public static inline function insert<T>(a:Array<T>, pos:Int, x:T):Void {
Syntax.callField(a, "insert", pos, x);
}
@:ifFeature("dynamic_read.reverse", "anon_optional_read.reverse", "python.internal.ArrayImpl.reverse")
public static inline function reverse<T>(a:Array<T>):Void {
Syntax.callField(a, "reverse");
}
@:ifFeature("array_read")
private static inline function _get<T>(x:Array<T>, idx:Int):T {
return if (idx > -1 && idx < x.length) unsafeGet(x, idx) else null;
}
@:ifFeature("array_write")
private static inline function _set<T>(x:Array<T>, idx:Int, v:T):T {
var l = x.length;
while (l < idx) {
x.push(null);
l += 1;
}
if (l == idx) {
x.push(v);
} else {
Syntax.assign(Syntax.arrayAccess(x, idx), v);
}
return v;
}
public static inline function unsafeGet<T>(x:Array<T>, idx:Int):T {
return Syntax.arrayAccess(x, idx);
}
public static inline function unsafeSet<T>(x:Array<T>, idx:Int, val:T):T {
Syntax.assign(Syntax.arrayAccess(x, idx), val);
return val;
}
public static inline function resize<T>(x:Array<T>, len:Int):Void {
var l = x.length;
if (l < len) {
_set(x, len - 1, null);
} else if (l > len) {
splice(x, len, l - len);
}
}
}

View File

@ -0,0 +1,52 @@
/*
* 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 python.internal;
@:ifFeature("has_enum", "Enum.*")
@:native("Enum")
class EnumImpl {
@:ifFeature("has_enum", "Enum.*")
public var tag:String;
@:ifFeature("has_enum", "Enum.*")
public var index:Int;
@:ifFeature("has_enum", "Enum.*")
public var params:Tuple<Dynamic>;
@:ifFeature("has_enum", "Enum.*")
public function new(tag, index, params) {
this.tag = tag;
this.index = index;
this.params = params;
}
@:ifFeature("has_enum", "Enum.*")
function __str__() {
return if (params == null) {
tag;
} else {
python.Syntax.code("{0} + '(' + (', '.join(str(v) for v in {1})) + ')'", tag, params);
}
}
}

View File

@ -0,0 +1,229 @@
/*
* 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 python.internal;
import python.Syntax;
import python.Syntax.code in py;
@:noDoc
@:native("HxOverrides")
@:access(python.internal.ArrayImpl)
@:access(python.Boot)
class HxOverrides {
// this two cases iterator and shift are like all methods in String and Array and are already handled in Reflect
// we need to modify the transformer to call Reflect directly
@:ifFeature("dynamic_read.iterator", "anon_optional_read.iterator", "anon_read.iterator")
static public function iterator(x) {
if (Boot.isArray(x)) {
return (x : Array<Dynamic>).iterator();
}
return Syntax.callField(x, "iterator");
}
@:ifFeature("dynamic_read.keyValueIterator", "anon_optional_read.keyValueIterator", "anon_read.keyValueIterator")
static public function keyValueIterator(x) {
if (Boot.isArray(x)) {
return (x:Array<Dynamic>).keyValueIterator();
}
return Syntax.callField(x, "keyValueIterator");
}
@:ifFeature("dynamic_binop_==", "dynamic_binop_!=", "type_param_binop_==", "type_param_binop_!=")
static function eq(a:Dynamic, b:Dynamic):Bool {
if (Boot.isArray(a) || Boot.isArray(b)) {
return Syntax.code('a is b');
}
return Syntax.binop(a, "==", b);
}
@:ifFeature("unsafe_string_concat")
static function stringOrNull(s:String):String {
return if (s == null) "null" else s;
}
@:ifFeature("dynamic_read.shift", "anon_optional_read.shift", "anon_read.shift")
static public function shift(x) {
if (Boot.isArray(x)) {
return (x : Array<Dynamic>).shift();
}
return Syntax.callField(x, "shift");
}
@:ifFeature("dynamic_read.pop", "anon_optional_read.pop", "anon_read.pop")
static public function pop(x) {
if (Boot.isArray(x)) {
return (x : Array<Dynamic>).pop();
}
return Syntax.callField(x, "pop");
}
@:ifFeature("dynamic_read.push", "anon_optional_read.push", "anon_read.push")
static public function push(x:Dynamic, e:Dynamic) {
if (Boot.isArray(x)) {
return (x : Array<Dynamic>).push(e);
}
return Syntax.callField(x, "push", e);
}
@:ifFeature("dynamic_read.join", "anon_optional_read.join", "anon_read.join")
static public function join(x, sep) {
if (Boot.isArray(x)) {
return (x : Array<Dynamic>).join(sep);
}
return Syntax.callField(x, "join", sep);
}
@:ifFeature("dynamic_read.filter", "anon_optional_read.filter", "anon_read.filter")
static public function filter(x, f) {
if (Boot.isArray(x)) {
return (x : Array<Dynamic>).filter(f);
}
return Syntax.callField(x, "filter", f);
}
@:ifFeature("dynamic_read.map", "anon_optional_read.map", "anon_read.map")
static public function map(x:Dynamic, f:Dynamic) {
if (Boot.isArray(x)) {
return (x : Array<Dynamic>).map(f);
}
return Syntax.callField(x, "map", f);
}
@:ifFeature("dynamic_read.toUpperCase", "anon_optional_read.toUpperCase", "anon_read.toUpperCase")
static public function toUpperCase(x) {
if (Boot.isString(x)) {
return (x : String).toUpperCase();
}
return Syntax.callField(x, "toUpperCase");
}
@:ifFeature("dynamic_read.toLowerCase", "anon_optional_read.toLowerCase", "anon_read.toLowerCase")
static public function toLowerCase(x) {
if (Boot.isString(x)) {
return (x : String).toLowerCase();
}
return Syntax.callField(x, "toLowerCase");
}
@:ifFeature("dynamic_read.split", "anon_optional_read.split", "anon_read.split")
static public function split(x:Dynamic, delimiter:String) {
if (Boot.isString(x)) {
return (x : String).split(delimiter);
}
return Syntax.callField(x, "split", delimiter);
}
@:ifFeature("dynamic_read.length", "anon_optional_read.length", "anon_read.length")
static public function length(x:Dynamic) {
if (Boot.isString(x)) {
return (x : String).length;
} else if (Boot.isArray(x)) {
return (x : Array<Dynamic>).length;
}
return Syntax.field(x, "length");
}
@:ifFeature("binop_>>>")
static public function rshift(val:Int, n:Int) {
return Syntax.binop(Syntax.binop(val, "%", Syntax.code("0x100000000")), ">>", n);
}
@:ifFeature("binop_%")
static public function modf(a:Float, b:Float) {
if(b == 0.0) {
return Syntax.code("float('nan')");
} else if(a < 0) {
if(b < 0) {
return Syntax.code("-(-{0} % (-{1}))", a, b);
} else {
return Syntax.code("-(-{0} % {1})", a, b);
}
} else if(b < 0) {
return Syntax.code("{0} % (-{1})", a, b);
} else {
return Syntax.code("{0} % {1}", a, b);
}
}
@:ifFeature("binop_%")
static public function mod(a:Int, b:Int) {
if(a < 0) {
if(b < 0) {
return Syntax.code("-(-{0} % (-{1}))", a, b);
} else {
return Syntax.code("-(-{0} % {1})", a, b);
}
} else if(b < 0) {
return Syntax.code("{0} % (-{1})", a, b);
} else {
return Syntax.code("{0} % {1}", a, b);
}
}
@:ifFeature("dynamic_array_read")
static public function arrayGet<T>(a:Dynamic, i:Int):Dynamic {
if (Boot.isArray(a)) {
return ArrayImpl._get(a, i);
} else {
return Syntax.arrayAccess(a, i);
}
}
@:ifFeature("dynamic_array_write")
static public function arraySet(a:Dynamic, i:Int, v:Dynamic) {
if (Boot.isArray(a)) {
return ArrayImpl._set(a, i, v);
} else {
Syntax.assign(Syntax.arrayAccess(a, i), v);
return v;
}
}
@:ifFeature("python._KwArgs.KwArgs_Impl_.fromT")
static public function mapKwArgs(a:{}, v:Dict<String, String>) {
var a = python.Lib.dictAsAnon(python.Lib.anonToDict(a));
for (k in v.keys()) {
var val = v.get(k);
if (Syntax.code('{0}._hx_hasattr({1})', a, k)) {
var x = UBuiltins.getattr(a, k);
UBuiltins.setattr(a, val, x);
UBuiltins.delattr(a, k);
}
}
return a;
}
@:ifFeature("python._KwArgs.KwArgs_Impl_.toDictHelper")
static public function reverseMapKwArgs(a:Dict<String, Dynamic>, v:Dict<String, String>) {
var a = a.copy();
for (k in v.keys()) {
var val = v.get(k);
if (a.hasKey(val)) {
var x = a.get(val, null);
a.set(k, x);
a.remove(val);
}
}
return a;
}
}

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 python.internal;
#if macro
import haxe.macro.Context;
import haxe.macro.Expr;
#end
@:noPackageRestrict
class Internal {
#if macro
static var _prefix = "_hx_";
static var _className = _prefix + "class_name";
static var _class = _prefix + "class";
static var _fields = _prefix + "fields";
static var _super = _prefix + "super";
static var _methods = _prefix + "methods";
static var _statics = _prefix + "statics";
static var _interfaces = _prefix + "interfaces";
static var _emptyInit = _prefix + "empty_init";
static var _constructs = _prefix + "constructs";
static var _classes = _prefix + "classes";
static var _dict = "__dict__";
static function _getPrefixed(x:Expr):Expr {
return switch (x.expr) {
case EConst(CString(x)): macro @:pos(Context.currentPos()) $v{_prefix + x};
case _: macro @:pos(Context.currentPos()) (python.Syntax.binop($v{_prefix}, "+", $x) : String);
}
}
static function withPos(x:String):Expr {
return macro @:pos(Context.currentPos()) $v{x};
}
static function fieldWithPos(o:Expr, x:String):Expr {
return macro @:pos(Context.currentPos()) (untyped __define_feature__($v{"python." + x}, python.Syntax.field($o, $v{x})));
}
static function has(o:Expr, field:String):Expr {
return macro(untyped __define_feature__($v{"python." + field}, python.internal.UBuiltins.hasattr($o, $v{field})) : Bool);
}
#end
macro public static function getPrefixed(x:ExprOf<String>):Expr {
return switch (x.expr) {
case EConst(CString(x)): macro @:pos(Context.currentPos()) $v{_prefix + x};
case _: macro @:pos(Context.currentPos()) (python.Syntax.binop($v{_prefix}, "+", $x) : String);
}
}
macro public static function classRegistry():Expr {
return macro(untyped __define_feature__($v{"python." + _classes}, python.Syntax.code($v{_classes})) : python.Dict<String, Class<Dynamic>>);
}
macro public static function callFieldPrefixed(o:Expr, x:String, params:Array<Expr>):Expr {
var args = [o, macro @:pos(Context.currentPos()) $v{_prefix + x}].concat(params);
return macro @:pos(Context.currentPos()) python.Syntax.callField($a{args});
}
macro public static function fieldPrefixed(o:Expr, x:String):Expr {
var args = [o, macro @:pos(Context.currentPos()) $v{_prefix + x}];
return macro @:pos(Context.currentPos()) python.Syntax.field($a{args});
}
macro public static function hasAttrPrefixed(o:Expr, x:String):Expr {
var args = [o, macro @:pos(Context.currentPos()) $v{_prefix + x}];
return macro @:pos(Context.currentPos()) python.Syntax.field($a{args});
}
macro public static function importAsPrefixed(o:String, x:String) {
return macro @:pos(Context.currentPos()) python.Syntax.importAs($v{o}, $v{_prefix + x});
}
macro public static function prefix():Expr {
return macro @:pos(Context.currentPos()) $v{_prefix};
}
macro public static function pythonCodePrefixed(x:String):Expr {
return macro python.Syntax.code($v{_prefix + x});
}
macro public static function hasClassName(o:Expr):Expr {
return has(o, _className);
}
macro public static function hasInterfaces(o:Expr):Expr {
return has(o, _interfaces);
}
macro public static function hasClass(o:Expr):Expr {
return has(o, _class);
}
macro public static function hasConstructs(o:Expr):Expr {
return has(o, _constructs);
}
macro public static function hasEmptyInit(o:Expr):Expr {
return has(o, _emptyInit);
}
macro public static function hasMethods(o:Expr):Expr {
return has(o, _methods);
}
macro public static function hasFields(o:Expr):Expr {
return has(o, _fields);
}
macro public static function hasSuper(o:Expr):Expr {
return has(o, _super);
}
macro public static function hasStatics(o:Expr):Expr {
return has(o, _statics);
}
macro public static function classNameVal():Expr {
return withPos(_className);
}
macro public static function methodsVal():Expr {
return withPos(_methods);
}
macro public static function classVal():Expr {
return withPos(_className);
}
macro public static function superVal():Expr {
return withPos(_super);
}
macro public static function interfacesVal():Expr {
return withPos(_interfaces);
}
macro public static function fieldsVal():Expr {
return withPos(_fields);
}
macro public static function staticsVal():Expr {
return withPos(_statics);
}
macro public static function constructsVal():Expr {
return withPos(_constructs);
}
macro public static function emptyInitVal():Expr {
return withPos(_emptyInit);
}
macro public static function fieldClassName(o:Expr):Expr {
return fieldWithPos(o, _className);
}
macro public static function fieldInterfaces(o:Expr):Expr {
return fieldWithPos(o, _interfaces);
}
macro public static function fieldClass(o:Expr):Expr {
return fieldWithPos(o, _class);
}
macro public static function fieldSuper(o:Expr):Expr {
return fieldWithPos(o, _super);
}
macro public static function fieldStatics(o:Expr):Expr {
return fieldWithPos(o, _statics);
}
macro public static function fieldMethods(o:Expr):Expr {
return fieldWithPos(o, _methods);
}
macro public static function fieldFields(o:Expr):Expr {
return fieldWithPos(o, _fields);
}
macro public static function fieldConstructs(o:Expr):Expr {
return fieldWithPos(o, _constructs);
}
macro public static function fieldDict(o:Expr):Expr {
return macro @:pos(Context.currentPos()) python.Syntax.field($o, $v{_dict});
}
macro public static function fieldEmptyInit(o:Expr):Expr {
return fieldWithPos(o, _emptyInit);
}
macro public static function callEmptyInit(o:Expr, instance:Expr):Expr {
return macro @:pos(Context.currentPos()) python.Syntax.callField($o, $v{_emptyInit}, $instance);
}
}

View File

@ -0,0 +1,37 @@
/*
* 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 python.internal;
class MethodClosure {
@:allow(Reflect) var obj:Dynamic;
@:allow(Reflect) var func:haxe.Constraints.Function;
public function new(obj:Dynamic, func:haxe.Constraints.Function) {
this.obj = obj;
this.func = func;
}
@:keep public function __call__(args:VarArgs<Dynamic>) {
return this.func(this.obj, args);
}
}

View File

@ -0,0 +1,148 @@
/*
* 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 python.internal;
import python.internal.Internal;
@:native("HxString")
class StringImpl {
@:ifFeature("dynamic_read.split", "anon_optional_read.split", "python.internal.StringImpl.split")
public static inline function split(s:String, d:String) {
return if (d == "") UBuiltins.list(s) else Syntax.callField(s, "split", d);
}
@:ifFeature("dynamic_read.charCodeAt", "anon_optional_read.charCodeAt", "python.internal.StringImpl.charCodeAt")
public static function charCodeAt(s:String, index:Int) {
return if (s == null || s.length == 0 || index < 0 || index >= s.length) null else UBuiltins.ord(Syntax.arrayAccess(s, index));
}
@:ifFeature("dynamic_read.charAt", "anon_optional_read.charAt", "python.internal.StringImpl.charAt")
public static inline function charAt(s:String, index:Int) {
return if (index < 0 || index >= s.length) "" else Syntax.arrayAccess(s, index);
}
@:ifFeature("dynamic_read.lastIndexOf", "anon_optional_read.lastIndexOf", "python.internal.StringImpl.lastIndexOf")
public static inline function lastIndexOf(s:String, str:String, ?startIndex:Int):Int {
if (startIndex == null) {
return Syntax.callField(s, "rfind", str, 0, s.length);
} else if(str == "") {
var length = s.length;
if(startIndex < 0) {
startIndex = length + startIndex;
if(startIndex < 0) startIndex = 0;
}
return startIndex > length ? length : startIndex;
} else {
var i = Syntax.callField(s, "rfind", str, 0, startIndex + 1);
var startLeft = i == -1 ? UBuiltins.max(0, startIndex + 1 - str.length) : i + 1;
var check = Syntax.callField(s, "find", str, startLeft, s.length);
if (check > i && check <= startIndex) {
return check;
} else {
return i;
}
}
}
@:ifFeature("dynamic_read.toUpperCase", "anon_optional_read.toUpperCase", "python.internal.StringImpl.toUpperCase")
public static inline function toUpperCase(s:String) {
return Syntax.callField(s, "upper");
}
@:ifFeature("dynamic_read.toLowerCase", "anon_optional_read.toLowerCase", "python.internal.StringImpl.toLowerCase")
public static inline function toLowerCase(s:String) {
return Syntax.callField(s, "lower");
}
@:ifFeature("dynamic_read.indexOf", "anon_optional_read.indexOf", "python.internal.StringImpl.indexOf")
public static inline function indexOf(s:String, str:String, ?startIndex:Int) {
if (startIndex == null)
return Syntax.callField(s, "find", str);
else
return indexOfImpl(s, str, startIndex);
}
static function indexOfImpl(s:String, str:String, startIndex:Int) {
if(str == "") {
var length = s.length;
if(startIndex < 0) {
startIndex = length + startIndex;
if(startIndex < 0) startIndex = 0;
}
return startIndex > length ? length : startIndex;
}
return Syntax.callField(s, "find", str, startIndex);
}
@:ifFeature("dynamic_read.toString", "anon_optional_read.toString", "python.internal.StringImpl.toString")
public static inline function toString(s:String) {
return s;
}
@:ifFeature("dynamic_read.length", "anon_optional_read.length", "python.internal.StringImpl.length")
public static inline function get_length(s:String) {
return UBuiltins.len(s);
}
@:ifFeature("dynamic_read.fromCharCode", "anon_optional_read.fromCharCode", "python.internal.StringImpl.fromCharCode")
public static inline function fromCharCode(code:Int):String {
#if doc_gen
return "";
#else
return Syntax.callField('', "join", UBuiltins.map(UBuiltins.chr, cast [code])); // TODO: check cast
#end
}
@:ifFeature("dynamic_read.substring", "anon_optional_read.substring", "python.internal.StringImpl.substring")
public static function substring(s:String, startIndex:Int, ?endIndex:Int):String {
if (startIndex < 0)
startIndex = 0;
if (endIndex == null) {
return Syntax.arrayAccessWithTrailingColon(s, startIndex);
} else {
if (endIndex < 0)
endIndex = 0;
if (endIndex < startIndex) {
return Syntax.arrayAccess(s, endIndex, startIndex);
} else {
return Syntax.arrayAccess(s, startIndex, endIndex);
}
}
}
@:ifFeature("dynamic_read.substr", "anon_optional_read.substr", "python.internal.StringImpl.substr")
public static function substr(s:String, startIndex:Int, ?len:Int):String {
if (len == null) {
return Syntax.arrayAccessWithTrailingColon(s, startIndex);
} else {
if (len == 0)
return "";
if (startIndex < 0) {
startIndex = s.length + startIndex;
if (startIndex < 0)
startIndex = 0;
}
return Syntax.arrayAccess(s, startIndex, startIndex + len);
}
}
}

View File

@ -0,0 +1,51 @@
/*
* 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 python.internal;
/**
This class provides unqualified access to python builtins that are safe to use in haxe/python code.
Fields listed here must be synchronized with genpy's KeywordHandler.kwds2 list to be properly escaped.
**/
extern class UBuiltins {
static function id(x:Dynamic):String;
static function len(x:Dynamic):Int;
static function isinstance(o:Dynamic, c:Dynamic):Bool;
static function str(o:Dynamic):String;
static function bool(o:Dynamic):Bool;
static function float(o:Dynamic):Float;
static function int(o:Dynamic, ?base:Int):Int;
static function list<T>(o:Dynamic):Array<T>;
static function min<T>(a:T, b:T):T;
static function max<T>(a:T, b:T):T;
static function hasattr(o:Dynamic, a:String):Bool;
static function getattr(o:Dynamic, a:String, ?def:Dynamic):Dynamic;
static function setattr(o:Dynamic, a:String, v:Dynamic):Void;
static function delattr(o:Dynamic, attr:String):Void;
static function callable(x:Dynamic):Bool;
static function type(o:Dynamic):Dynamic;
static function ord(s:String):Int;
static function chr(c:Int):String;
static function map<T, S>(f:T->S, a:Array<T>):Array<S>;
static function filter<T>(f:T->Bool, a:Array<T>):Array<T>;
static function iter<T>(o:python.NativeIterable<T>):python.NativeIterator<T>;
}