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,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);
}