Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b9b244512 |
+24
-18
@@ -4,11 +4,10 @@ os:
|
|||||||
- linux
|
- linux
|
||||||
- osx
|
- osx
|
||||||
|
|
||||||
dist: bionic
|
osx_image: xcode6.4
|
||||||
|
|
||||||
haxe:
|
haxe:
|
||||||
- "3.4.7"
|
- "3.2.1"
|
||||||
- "4.0.3"
|
|
||||||
- development
|
- development
|
||||||
|
|
||||||
addons:
|
addons:
|
||||||
@@ -20,34 +19,44 @@ addons:
|
|||||||
# Python
|
# Python
|
||||||
- python3
|
- python3
|
||||||
# PHP
|
# PHP
|
||||||
- php-cli
|
- php5-cli
|
||||||
- php-mbstring
|
|
||||||
# C#
|
# C#
|
||||||
- mono-devel
|
- mono-devel
|
||||||
- mono-mcs
|
- mono-mcs
|
||||||
|
# Flash
|
||||||
|
- libcurl3:i386
|
||||||
|
- libglib2.0-0:i386
|
||||||
|
- libx11-6:i386
|
||||||
|
- libxext6:i386
|
||||||
|
- libxt6:i386
|
||||||
|
- libxcursor1:i386
|
||||||
|
- libnss3:i386
|
||||||
|
- libgtk2.0-0:i386
|
||||||
|
|
||||||
install:
|
install:
|
||||||
# os-specific config
|
# os-specific config
|
||||||
- if [ "${TRAVIS_OS_NAME}" = "osx" ]; then
|
- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
|
||||||
|
export DISPLAY=:99.0;
|
||||||
|
export AUDIODEV=null;
|
||||||
|
elif [ "${TRAVIS_OS_NAME}" = "osx" ]; then
|
||||||
brew update;
|
brew update;
|
||||||
brew install mono;
|
brew install mono;
|
||||||
brew install php;
|
brew install python3;
|
||||||
fi
|
fi
|
||||||
|
# Download and setup a standalone flash player debugger
|
||||||
|
- haxe flash/install.hxml
|
||||||
# Install haxelibs
|
# Install haxelibs
|
||||||
- if [ "${TRAVIS_HAXE_VERSION}" = "development" ]; then
|
- if [ "${TRAVIS_HAXE_VERSION}" = "development" ]; then
|
||||||
haxelib git hxcpp https://github.com/HaxeFoundation/hxcpp.git;
|
haxelib git hxcpp https://github.com/HaxeFoundation/hxcpp.git;
|
||||||
else
|
|
||||||
haxelib install hxcpp;
|
|
||||||
fi
|
|
||||||
- if [ "${TRAVIS_HAXE_VERSION}" = "development" ] || [ "${TRAVIS_HAXE_VERSION}" = "3.2.1" ]; then
|
|
||||||
pushd $(haxelib path hxcpp | head -1);
|
pushd $(haxelib path hxcpp | head -1);
|
||||||
pushd tools/hxcpp; haxe compile.hxml; popd;
|
pushd tools/hxcpp; haxe compile.hxml; popd;
|
||||||
pushd project; neko build.n; popd;
|
pushd project; neko build.n; popd;
|
||||||
popd;
|
popd;
|
||||||
|
else
|
||||||
|
haxelib install hxcpp;
|
||||||
fi
|
fi
|
||||||
- haxelib install hxjava
|
- haxelib install hxjava
|
||||||
- haxelib install hxcs
|
- haxelib install hxcs
|
||||||
- haxelib install hx3compat
|
|
||||||
- haxelib dev hscript .
|
- haxelib dev hscript .
|
||||||
- haxelib list
|
- haxelib list
|
||||||
|
|
||||||
@@ -56,14 +65,11 @@ script:
|
|||||||
haxe build.hxml &&
|
haxe build.hxml &&
|
||||||
popd
|
popd
|
||||||
- haxe bin/build-interp.hxml
|
- haxe bin/build-interp.hxml
|
||||||
- haxe bin/build-interp.hxml -D hscriptPos
|
|
||||||
- haxe bin/build-neko.hxml && neko bin/Test.n
|
- haxe bin/build-neko.hxml && neko bin/Test.n
|
||||||
- haxe bin/build-js.hxml && node bin/Test.js
|
- haxe bin/build-js.hxml && node bin/Test.js
|
||||||
- haxe bin/build-java.hxml && java -jar bin/Test.jar
|
- haxe bin/build-java.hxml && java -jar bin/Test.jar
|
||||||
# Only test C# for Haxe 4+
|
- haxe bin/build-cs.hxml && mono bin/bin/Test.exe
|
||||||
- if [[ $(haxe -version 2&>1 | head -c 1) > 3 ]]; then
|
|
||||||
haxe bin/build-cs.hxml && mono bin/bin/Test.exe;
|
|
||||||
fi
|
|
||||||
- haxe bin/build-cpp.hxml && ./bin/Test
|
- haxe bin/build-cpp.hxml && ./bin/Test
|
||||||
- haxe bin/build-php.hxml -D php7 && php bin/index.php
|
- haxe bin/build-flash.hxml -D fdb && haxe flash/run.hxml bin/Test.swf
|
||||||
|
- haxe bin/build-php.hxml && php bin/index.php
|
||||||
- haxe bin/build-python.hxml && python3 bin/Test.py
|
- haxe bin/build-python.hxml && python3 bin/Test.py
|
||||||
|
|||||||
Vendored
-16
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
// Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
|
|
||||||
// Pointez pour afficher la description des attributs existants.
|
|
||||||
// Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "HashLink (launch)",
|
|
||||||
"request": "launch",
|
|
||||||
"type": "hl",
|
|
||||||
"hxml": "hscript.hxml",
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"preLaunchTask": "Build"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Vendored
-16
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
|
||||||
// for the documentation about the tasks.json format
|
|
||||||
"version": "2.0.0",
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
"label": "Build",
|
|
||||||
"type": "hxml",
|
|
||||||
"file": "hscript.hxml",
|
|
||||||
"group": {
|
|
||||||
"kind": "build",
|
|
||||||
"isDefault": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
The MIT License
|
|
||||||
|
|
||||||
Copyright (C)2008-2017 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.
|
|
||||||
|
|
||||||
@@ -64,40 +64,26 @@ You can use `parser.allowJSON` to allow JSON data.
|
|||||||
|
|
||||||
You can use `parser.allowTypes` to parse types for local vars, exceptions, function args and return types. Types are ignored by the interpreter.
|
You can use `parser.allowTypes` to parse types for local vars, exceptions, function args and return types. Types are ignored by the interpreter.
|
||||||
|
|
||||||
You can use `parser.allowMetadata` to parse metadata before expressions on in anonymous types. Metadata are ignored by the interpreter.
|
|
||||||
|
|
||||||
You can use `new hscript.Macro(pos).convert(ast)` to convert an hscript AST to a Haxe macros one.
|
You can use `new hscript.Macro(pos).convert(ast)` to convert an hscript AST to a Haxe macros one.
|
||||||
|
|
||||||
You can use `hscript.Checker` in order to type check and even get completion, using `haxe -xml` output for type information.
|
|
||||||
|
|
||||||
Limitations
|
Limitations
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
Compared to Haxe, limitations are :
|
Compared to Haxe, limitations are :
|
||||||
|
|
||||||
|
- no type declarations (classes, enums, typedefs) : only expressions
|
||||||
- `switch` construct is supported but not pattern matching (no variable capture, we use strict equality to compare `case` values and `switch` value)
|
- `switch` construct is supported but not pattern matching (no variable capture, we use strict equality to compare `case` values and `switch` value)
|
||||||
- only one variable declaration is allowed in `var`
|
- only one variable declaration is allowed in `var`
|
||||||
- the parser supports optional types for `var` and `function` if `allowTypes` is set, but the interpreter ignores them
|
- the parser supports optional types for `var` and `function` if `allowTypes` is set, but the interpreter ignores them
|
||||||
- you can enable per-expression position tracking by compiling with `-D hscriptPos`
|
- you can enable per-expression position tracking by compiling with `-D hscriptPos`
|
||||||
- you can parse some type declarations (import, class, typedef, etc.) with parseModule
|
|
||||||
|
|
||||||
Install
|
Install
|
||||||
-------
|
-------
|
||||||
|
|
||||||
In order to install Haxe Script, use `haxelib install hscript` and compile your program with `-lib hscript`.
|
In order to install Haxe Script, use `haxelib install hscript` and compile your program with `-lib hscript`.
|
||||||
|
|
||||||
These are the main required files in hscript :
|
There are only three files in hscript :
|
||||||
|
|
||||||
- `hscript.Expr` : contains enums declarations
|
- `hscript.Expr` : contains enums declarations
|
||||||
- `hscript.Parser` : a small parser that turns a string into an expression structure (AST)
|
- `hscript.Parser` : a small parser that turns a string into an expression structure (AST)
|
||||||
- `hscript.Interp` : a small interpreter that execute the AST and returns the latest evaluated value
|
- `hscript.Interp` : a small interpreter that execute the AST and returns the latest evaluated value
|
||||||
|
|
||||||
Some other optional files :
|
|
||||||
|
|
||||||
- `hscript.Async` : converts Expr into asynchronous version
|
|
||||||
- `hscript.Bytes` : Expr serializer/unserializer
|
|
||||||
- `hscript.Checker` : type checking and completion for hscript Expr
|
|
||||||
- `hscript.Macro` : convert Haxe macro into hscript Expr
|
|
||||||
- `hscript.Printer` : convert hscript Expr to String
|
|
||||||
- `hscript.Tools` : utility functions (map/iter)
|
|
||||||
|
|
||||||
@@ -1,14 +1,10 @@
|
|||||||
import haxe.ds.EnumValueMap;
|
import haxe.ds.EnumValueMap;
|
||||||
import haxe.ds.Option;
|
import haxe.ds.Option;
|
||||||
import hscript.Macro;
|
import hscript.Macro;
|
||||||
import hscript.Tools;
|
|
||||||
import hscript.Async;
|
|
||||||
import hscript.Printer;
|
|
||||||
import hscript.Checker;
|
|
||||||
import haxe.unit.*;
|
import haxe.unit.*;
|
||||||
|
|
||||||
class TestHScript extends TestCase {
|
class Test extends TestCase {
|
||||||
function assertScript(x,v:Dynamic,?vars : Dynamic, allowTypes=false, ?pos:haxe.PosInfos) {
|
function assertScript(x,v:Dynamic,?vars : Dynamic,allowTypes=false) {
|
||||||
var p = new hscript.Parser();
|
var p = new hscript.Parser();
|
||||||
p.allowTypes = allowTypes;
|
p.allowTypes = allowTypes;
|
||||||
var program = p.parseString(x);
|
var program = p.parseString(x);
|
||||||
@@ -19,21 +15,14 @@ class TestHScript extends TestCase {
|
|||||||
for( v in Reflect.fields(vars) )
|
for( v in Reflect.fields(vars) )
|
||||||
interp.variables.set(v,Reflect.field(vars,v));
|
interp.variables.set(v,Reflect.field(vars,v));
|
||||||
var ret : Dynamic = interp.execute(program);
|
var ret : Dynamic = interp.execute(program);
|
||||||
assertEquals(v, ret, pos);
|
assertEquals(v, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
function test():Void {
|
function test():Void {
|
||||||
assertScript("0",0);
|
assertScript("0",0);
|
||||||
assertScript("0xFF", 255);
|
assertScript("0xFF", 255);
|
||||||
#if !(php || python)
|
assertScript("0xBFFFFFFF", 0xBFFFFFFF);
|
||||||
#if haxe3
|
assertScript("0x7FFFFFFF", 0x7FFFFFFF);
|
||||||
assertScript("0xBFFFFFFF", 0xBFFFFFFF);
|
|
||||||
assertScript("0x7FFFFFFF", 0x7FFFFFFF);
|
|
||||||
#elseif !neko
|
|
||||||
assertScript("n(0xBFFFFFFF)", 0xBFFFFFFF, { n : haxe.Int32.toNativeInt });
|
|
||||||
assertScript("n(0x7FFFFFFF)", 0x7FFFFFFF, { n : haxe.Int32.toNativeInt } );
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
assertScript("-123",-123);
|
assertScript("-123",-123);
|
||||||
assertScript("- 123",-123);
|
assertScript("- 123",-123);
|
||||||
assertScript("1.546",1.546);
|
assertScript("1.546",1.546);
|
||||||
@@ -100,21 +89,8 @@ class TestHScript extends TestCase {
|
|||||||
assertScript("var a:Array<Dynamic>=[1,2,4]; a[2]", 4, null, true);
|
assertScript("var a:Array<Dynamic>=[1,2,4]; a[2]", 4, null, true);
|
||||||
assertScript("/**/0", 0);
|
assertScript("/**/0", 0);
|
||||||
assertScript("x=1;x*=-2", -2);
|
assertScript("x=1;x*=-2", -2);
|
||||||
assertScript("var f = x -> x + 1; f(3)", 4);
|
|
||||||
assertScript("var f = () -> 55; f()", 55);
|
|
||||||
assertScript("var f = (x) -> x + 1; f(3)", 4);
|
|
||||||
assertScript("var f = (x:Int) -> x + 1; f(3)", 4);
|
|
||||||
assertScript("var f = (x,y) -> x + y; f(3,1)", 4);
|
|
||||||
assertScript("var f = (x,y:Int) -> x + y; f(3,1)", 4);
|
|
||||||
assertScript("var f = (x:Int,y:Int) -> x + y; f(3,1)", 4);
|
|
||||||
assertScript("var f:Int->Int->Int = (x:Int,y:Int) -> x + y; f(3,1)", 4, null, true);
|
|
||||||
assertScript("var f:(x:Int, y:Int)->Int = (x:Int,y:Int) -> x + y; f(3,1)", 4, null, true);
|
|
||||||
assertScript("var f:(x:Int)->(y:Int, z:Int)->Int = (x:Int) -> (y:Int, z:Int) -> x + y + z; f(3)(1, 2)", 6, null, true);
|
|
||||||
assertScript("var f:(x:Int)->(Int, Int)->Int = (x:Int) -> (y:Int, z:Int) -> x + y + z; f(3)(1, 2)", 6, null, true);
|
|
||||||
assertScript("var a = 10; var b = 5; a - -b", 15);
|
|
||||||
assertScript("var a = 10; var b = 5; a - b / 2", 7.5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testMap():Void {
|
function testMap():Void {
|
||||||
var objKey = { ok:true };
|
var objKey = { ok:true };
|
||||||
var vars = {
|
var vars = {
|
||||||
@@ -127,7 +103,7 @@ class TestHScript extends TestCase {
|
|||||||
stringIntMap: ["foo" => 100]
|
stringIntMap: ["foo" => 100]
|
||||||
}
|
}
|
||||||
vars.enumMap.set(vars.enumKey, "ok");
|
vars.enumMap.set(vars.enumKey, "ok");
|
||||||
|
|
||||||
assertScript('stringMap["foo"]', "Foo", vars);
|
assertScript('stringMap["foo"]', "Foo", vars);
|
||||||
assertScript('intMap[100]', "one hundred", vars);
|
assertScript('intMap[100]', "one hundred", vars);
|
||||||
assertScript('objMap[objKey]', "ok", vars);
|
assertScript('objMap[objKey]', "ok", vars);
|
||||||
@@ -166,16 +142,9 @@ class TestHScript extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static function main() {
|
static function main() {
|
||||||
#if ((haxe_ver < 4) && php)
|
|
||||||
// uncaught exception: The each() function is deprecated. This message will be suppressed on further calls (errno: 8192)
|
|
||||||
// in file: /Users/travis/build/andyli/hscript/bin/lib/Type.class.php line 178
|
|
||||||
untyped __php__("error_reporting(E_ALL ^ E_DEPRECATED);");
|
|
||||||
#end
|
|
||||||
|
|
||||||
var runner = new TestRunner();
|
var runner = new TestRunner();
|
||||||
runner.add(new TestHScript());
|
runner.add(new Test());
|
||||||
var succeed = runner.run();
|
var succeed = runner.run();
|
||||||
|
|
||||||
#if sys
|
#if sys
|
||||||
Sys.exit(succeed ? 0 : 1);
|
Sys.exit(succeed ? 0 : 1);
|
||||||
#elseif flash
|
#elseif flash
|
||||||
+10
-7
@@ -5,19 +5,20 @@ environment:
|
|||||||
HAXELIB_ROOT: C:\projects\haxelib
|
HAXELIB_ROOT: C:\projects\haxelib
|
||||||
|
|
||||||
install:
|
install:
|
||||||
# http://help.appveyor.com/discussions/problems/5616-not-able-to-build-due-to-problem-in-chocolateyinstallps1
|
|
||||||
- ps: Set-Service wuauserv -StartupType Manual
|
|
||||||
# Install the haxe chocolatey package (https://chocolatey.org/packages/haxe)
|
# Install the haxe chocolatey package (https://chocolatey.org/packages/haxe)
|
||||||
- cinst haxe -version 4.0.3 -y
|
- cinst haxe -version 3.2.1 -y
|
||||||
- RefreshEnv
|
- RefreshEnv
|
||||||
# Setup haxelib
|
# Setup haxelib
|
||||||
- mkdir "%HAXELIB_ROOT%"
|
- mkdir "%HAXELIB_ROOT%"
|
||||||
- haxelib setup "%HAXELIB_ROOT%"
|
- haxelib setup "%HAXELIB_ROOT%"
|
||||||
|
# Install test dependencies
|
||||||
|
- cinst php -y
|
||||||
|
# Download and setup a standalone flash player debugger
|
||||||
|
- haxe flash/install.hxml
|
||||||
# Install project dependencies
|
# Install project dependencies
|
||||||
- haxelib install hxcpp > log.txt || type log.txt && cmd /C exit 1
|
- haxelib install hxcpp > log.txt || type log.txt && cmd /C exit 1
|
||||||
- haxelib install hxjava > log.txt || type log.txt && cmd /C exit 1
|
- haxelib install hxjava > log.txt || type log.txt && cmd /C exit 1
|
||||||
- haxelib install hxcs > log.txt || type log.txt && cmd /C exit 1
|
- haxelib install hxcs > log.txt || type log.txt && cmd /C exit 1
|
||||||
- haxelib install hx3compat > log.txt || type log.txt && cmd /C exit 1
|
|
||||||
- haxelib dev hscript .
|
- haxelib dev hscript .
|
||||||
- haxelib list
|
- haxelib list
|
||||||
|
|
||||||
@@ -33,4 +34,6 @@ test_script:
|
|||||||
- haxe bin/build-java.hxml && java -jar bin\Test.jar
|
- haxe bin/build-java.hxml && java -jar bin\Test.jar
|
||||||
- haxe bin/build-cs.hxml && bin\bin\Test.exe
|
- haxe bin/build-cs.hxml && bin\bin\Test.exe
|
||||||
- haxe bin/build-cpp.hxml && bin\Test.exe
|
- haxe bin/build-cpp.hxml && bin\Test.exe
|
||||||
|
- haxe bin/build-flash.hxml -D fdb && haxe flash\run.hxml bin\Test.swf
|
||||||
|
- haxe bin/build-php.hxml && C:\tools\php\php.exe bin\index.php
|
||||||
- haxe bin/build-python.hxml && C:\Python34-x64\python.exe bin\Test.py
|
- haxe bin/build-python.hxml && C:\Python34-x64\python.exe bin\Test.py
|
||||||
+1
-2
@@ -1,3 +1,2 @@
|
|||||||
-main TestHScript
|
-main Test
|
||||||
-dce no
|
-dce no
|
||||||
-lib hx3compat
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
*.exe
|
||||||
|
*.app
|
||||||
|
flashplayerdebugger
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
import Sys.*;
|
||||||
|
import sys.io.File.*;
|
||||||
|
import haxe.*;
|
||||||
|
import haxe.io.*;
|
||||||
|
|
||||||
|
class Install {
|
||||||
|
// https://www.adobe.com/support/flashplayer/downloads.html
|
||||||
|
static var fpDownload(default, never) = switch (systemName()) {
|
||||||
|
case "Linux":
|
||||||
|
"https://fpdownload.macromedia.com/pub/flashplayer/updaters/11/flashplayer_11_sa_debug.i386.tar.gz";
|
||||||
|
case "Mac":
|
||||||
|
"https://fpdownload.macromedia.com/pub/flashplayer/updaters/21/flashplayer_21_sa_debug.dmg";
|
||||||
|
case "Windows":
|
||||||
|
"http://fpdownload.macromedia.com/pub/flashplayer/updaters/21/flashplayer_21_sa_debug.exe";
|
||||||
|
case _:
|
||||||
|
throw "unsupported system";
|
||||||
|
}
|
||||||
|
// https://helpx.adobe.com/flash-player/kb/configure-debugger-version-flash-player.html
|
||||||
|
static var mmcfg(default, never) = switch (systemName()) {
|
||||||
|
case "Linux":
|
||||||
|
Path.join([getEnv("HOME"), "mm.cfg"]);
|
||||||
|
case "Mac":
|
||||||
|
"/Library/Application Support/Macromedia/mm.cfg";
|
||||||
|
case "Windows":
|
||||||
|
Path.join([getEnv("HOMEDRIVE") + getEnv("HOMEPATH"), "mm.cfg"]);
|
||||||
|
case _:
|
||||||
|
throw "unsupported system";
|
||||||
|
}
|
||||||
|
// http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7c95.html
|
||||||
|
static var fpTrust(default, never) = switch (systemName()) {
|
||||||
|
case "Linux":
|
||||||
|
Path.join([getEnv("HOME"), ".macromedia/Flash_Player/#Security/FlashPlayerTrust"]);
|
||||||
|
case "Mac":
|
||||||
|
"/Library/Application Support/Macromedia/FlashPlayerTrust";
|
||||||
|
case "Windows":
|
||||||
|
Path.join([getEnv("SYSTEMROOT"), "system32", "Macromed", "Flash", "FlashPlayerTrust"]);
|
||||||
|
case _:
|
||||||
|
throw "unsupported system";
|
||||||
|
}
|
||||||
|
static function main() {
|
||||||
|
switch (systemName()) {
|
||||||
|
case "Linux":
|
||||||
|
// Download and unzip flash player
|
||||||
|
if (command("wget", [fpDownload]) != 0)
|
||||||
|
throw "failed to download flash player";
|
||||||
|
if (command("tar", ["-xf", Path.withoutDirectory(fpDownload), "-C", "flash"]) != 0)
|
||||||
|
throw "failed to extract flash player";
|
||||||
|
case "Mac":
|
||||||
|
if (command("brew", ["tap", "caskroom/versions"]) != 0)
|
||||||
|
throw "failed to brew tap caskroom/versions";
|
||||||
|
if (command("brew", ["cask", "install", "flash-player-debugger"]) != 0)
|
||||||
|
throw "failed to install flash-player-debugger";
|
||||||
|
case "Windows":
|
||||||
|
// Download flash player
|
||||||
|
download(fpDownload, "flash\\flashplayer.exe");
|
||||||
|
case _:
|
||||||
|
throw "unsupported system";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Create a configuration file so the trace log is enabled
|
||||||
|
createDirectory(Path.directory(mmcfg));
|
||||||
|
saveContent(mmcfg, "ErrorReportingEnable=1\nTraceOutputFileEnable=1");
|
||||||
|
|
||||||
|
// Add the current directory as trusted, so exit() can be used
|
||||||
|
createDirectory(fpTrust);
|
||||||
|
saveContent(Path.join([fpTrust, "test.cfg"]), getCwd());
|
||||||
|
}
|
||||||
|
static function download(url:String, saveAs:String):Void {
|
||||||
|
var http = new Http(url);
|
||||||
|
http.onError = function(e) {
|
||||||
|
throw e;
|
||||||
|
};
|
||||||
|
http.customRequest(false, write(saveAs));
|
||||||
|
}
|
||||||
|
static function createDirectory(dir:String):Void {
|
||||||
|
try {
|
||||||
|
sys.FileSystem.createDirectory(dir);
|
||||||
|
} catch(e:Dynamic) {
|
||||||
|
switch (systemName()) {
|
||||||
|
case "Mac", "Linux":
|
||||||
|
if (command("sudo", ["mkdir", "-p", dir]) != 0)
|
||||||
|
throw 'cannot create $dir';
|
||||||
|
if (command("sudo", ["chmod", "a+rw", dir]) != 0)
|
||||||
|
throw 'cannot set permission of $dir';
|
||||||
|
case _:
|
||||||
|
neko.Lib.rethrow(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import Sys.*;
|
||||||
|
import sys.FileSystem.*;
|
||||||
|
import sys.io.File.*;
|
||||||
|
import haxe.io.*;
|
||||||
|
|
||||||
|
class Run {
|
||||||
|
// https://helpx.adobe.com/flash-player/kb/configure-debugger-version-flash-player.html
|
||||||
|
static var flashlog(default, never) = switch (systemName()) {
|
||||||
|
case "Linux":
|
||||||
|
Path.join([getEnv("HOME"), ".macromedia/Flash_Player/Logs/flashlog.txt"]);
|
||||||
|
case "Mac":
|
||||||
|
Path.join([getEnv("HOME"), "Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt"]);
|
||||||
|
case "Windows":
|
||||||
|
Path.join([getEnv("APPDATA"), "Macromedia", "Flash Player", "Logs", "flashlog.txt"]);
|
||||||
|
case _:
|
||||||
|
throw "unsupported system";
|
||||||
|
}
|
||||||
|
static function main() {
|
||||||
|
var args = args();
|
||||||
|
var swf = args[0];
|
||||||
|
var exitCode = switch (systemName()) {
|
||||||
|
case "Linux":
|
||||||
|
// The flash player has some issues with unexplained crashes,
|
||||||
|
// but if it runs about 8 times, it should succeed one of those...
|
||||||
|
var c = -1;
|
||||||
|
for (i in 0...8) {
|
||||||
|
if ((c = command("xvfb-run", ["flash/flashplayerdebugger", swf])) == 0)
|
||||||
|
break;
|
||||||
|
println('retry... (${i+1})');
|
||||||
|
}
|
||||||
|
c;
|
||||||
|
case "Mac":
|
||||||
|
command("/Applications/Flash Player Debugger.app/Contents/MacOS/Flash Player Debugger", [fullPath(swf)]);
|
||||||
|
case "Windows":
|
||||||
|
command("flash\\flashplayer.exe", [fullPath(swf)]);
|
||||||
|
case _:
|
||||||
|
throw "unsupported platform";
|
||||||
|
}
|
||||||
|
if (exists(flashlog))
|
||||||
|
println(getContent(flashlog));
|
||||||
|
else {
|
||||||
|
println('does not exist: $flashlog');
|
||||||
|
var parts = Path.normalize(flashlog).split("/");
|
||||||
|
println(parts);
|
||||||
|
for (i in 0...parts.length-1) {
|
||||||
|
var path = parts.splice(0, i+1).join("/");
|
||||||
|
println('ls $path');
|
||||||
|
command("ls", [path]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exit(exitCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
-cp flash
|
||||||
|
--run Install
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
-cp flash
|
||||||
|
--run Run
|
||||||
+9
-9
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "hscript",
|
"name": "hscript",
|
||||||
"url": "https://github.com/HaxeFoundation/hscript",
|
"url": "https://github.com/HaxeFoundation/hscript",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "Haxe Script is a scripting engine for a subset of the Haxe language",
|
"description": "Haxe Script is a scripting engine for a subset of the Haxe language",
|
||||||
"version": "2.4.0",
|
"version": "2.0.7",
|
||||||
"releasenote": "Haxe 4.0 final + type checking/completion (hscript.Checker)",
|
"releasenote": "fixes for haxe 3.3, use property access by default",
|
||||||
"contributors": ["ncannasse","HaxeFoundation"]
|
"contributors": ["ncannasse"]
|
||||||
}
|
}
|
||||||
+1
-2
@@ -1,2 +1 @@
|
|||||||
bin/build-each.hxml
|
bin/build-flash.hxml
|
||||||
-hl bin/Test.hl
|
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<project version="2">
|
||||||
|
<!-- Output SWF options -->
|
||||||
|
<output>
|
||||||
|
<movie outputType="Application" />
|
||||||
|
<movie input="" />
|
||||||
|
<movie path="hscript.swf" />
|
||||||
|
<movie fps="30" />
|
||||||
|
<movie width="800" />
|
||||||
|
<movie height="600" />
|
||||||
|
<movie version="9" />
|
||||||
|
<movie minorVersion="0" />
|
||||||
|
<movie platform="Flash Player" />
|
||||||
|
<movie background="#FFFFFF" />
|
||||||
|
</output>
|
||||||
|
<!-- Other classes to be compiled into your SWF -->
|
||||||
|
<classpaths>
|
||||||
|
<!-- example: <class path="..." /> -->
|
||||||
|
</classpaths>
|
||||||
|
<!-- Build options -->
|
||||||
|
<build>
|
||||||
|
<option directives="" />
|
||||||
|
<option flashStrict="True" />
|
||||||
|
<option noInlineOnDebug="False" />
|
||||||
|
<option mainClass="Test" />
|
||||||
|
<option enabledebug="False" />
|
||||||
|
<option additional="-dce no" />
|
||||||
|
</build>
|
||||||
|
<!-- haxelib libraries -->
|
||||||
|
<haxelib>
|
||||||
|
<!-- example: <library name="..." /> -->
|
||||||
|
</haxelib>
|
||||||
|
<!-- Class files to compile (other referenced classes will automatically be included) -->
|
||||||
|
<compileTargets>
|
||||||
|
<!-- example: <compile path="..." /> -->
|
||||||
|
</compileTargets>
|
||||||
|
<!-- Assets to embed into the output SWF -->
|
||||||
|
<library>
|
||||||
|
<!-- example: <asset path="..." id="..." update="..." glyphs="..." mode="..." place="..." sharepoint="..." /> -->
|
||||||
|
</library>
|
||||||
|
<!-- Paths to exclude from the Project Explorer tree -->
|
||||||
|
<hiddenPaths>
|
||||||
|
<hidden path="haxelib.xml" />
|
||||||
|
<hidden path="hscript.hxml" />
|
||||||
|
<hidden path="hscript.js" />
|
||||||
|
<hidden path="hscript.n" />
|
||||||
|
<hidden path="hscript.swf" />
|
||||||
|
<hidden path="hscript9.swf" />
|
||||||
|
<hidden path="release.bat" />
|
||||||
|
<hidden path="release.zip" />
|
||||||
|
<hidden path="obj" />
|
||||||
|
</hiddenPaths>
|
||||||
|
<!-- Executed before build -->
|
||||||
|
<preBuildCommand />
|
||||||
|
<!-- Executed after build -->
|
||||||
|
<postBuildCommand alwaysRun="False" />
|
||||||
|
<!-- Other project options -->
|
||||||
|
<options>
|
||||||
|
<option showHiddenPaths="False" />
|
||||||
|
<option testMovie="Default" />
|
||||||
|
<option testMovieCommand="" />
|
||||||
|
</options>
|
||||||
|
<!-- Plugin storage -->
|
||||||
|
<storage />
|
||||||
|
</project>
|
||||||
@@ -1,536 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C)2008-2017 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 hscript;
|
|
||||||
import hscript.Expr;
|
|
||||||
|
|
||||||
|
|
||||||
enum VarMode {
|
|
||||||
Defined;
|
|
||||||
ForceSync;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Async {
|
|
||||||
|
|
||||||
var definedVars : Array<{ n : String, prev : Null<VarMode> }>;
|
|
||||||
var vars : Map<String,VarMode>;
|
|
||||||
var currentFun : String;
|
|
||||||
var currentLoop : Expr;
|
|
||||||
var currentBreak : Expr -> Expr;
|
|
||||||
var uid = 0;
|
|
||||||
public var asyncIdents : Map<String,Bool>;
|
|
||||||
|
|
||||||
static var nullExpr : Expr = #if hscriptPos { e : null, pmin : 0, pmax : 0, origin : "<null>", line : 0 } #else null #end;
|
|
||||||
static var nullId = mk(EIdent("null"), nullExpr);
|
|
||||||
|
|
||||||
inline static function expr( e : Expr ) {
|
|
||||||
return #if hscriptPos e.e #else e #end;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static function mk( e, inf : Expr ) : Expr {
|
|
||||||
return #if hscriptPos { e : e, pmin : inf.pmin, pmax : inf.pmax, origin : inf.origin, line : inf.line } #else e #end;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Convert a script into asynchronous one.
|
|
||||||
- calls such as foo(a,b,c) are translated to a_foo(function(r) ...rest, a,b,c) where r is the result value
|
|
||||||
- object access such obj.bar(a,b,c) are translated to obj.a_bar(function(r) ...rest, a, b, c)
|
|
||||||
- @async expr will execute the expression but continue without waiting for it to finish
|
|
||||||
- @split [ e1, e2, e3 ] is transformed to split(function(_) ...rest, [e1, e2, e3]) which
|
|
||||||
should execute asynchronously all expressions - until they return - before continuing the execution
|
|
||||||
- for(i in v) block; loops are translated to the following:
|
|
||||||
var _i = makeIterator(v);
|
|
||||||
function _loop() {
|
|
||||||
if( !_i.hasNext() ) return;
|
|
||||||
var v = _i.next();
|
|
||||||
block(function(_) _loop());
|
|
||||||
}
|
|
||||||
_loop()
|
|
||||||
- while loops are translated similar to for loops
|
|
||||||
- break and continue are correctly handled
|
|
||||||
- you can use @sync <expr> to disable async transformation in some code parts (for performance reason)
|
|
||||||
- a few expressions are still not supported (complex calls, try/catch, and a few others)
|
|
||||||
|
|
||||||
In these examples ...rest represents the continuation of execution of the script after the expression
|
|
||||||
**/
|
|
||||||
public static function toAsync( e : Expr, topLevelSync = false ) {
|
|
||||||
var a = new Async();
|
|
||||||
return a.build(e, topLevelSync);
|
|
||||||
}
|
|
||||||
|
|
||||||
public dynamic function getTopLevelEnd() {
|
|
||||||
return ignore();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function build( e : Expr, topLevelSync = false ) {
|
|
||||||
if( topLevelSync ) {
|
|
||||||
return buildSync(e,null);
|
|
||||||
} else {
|
|
||||||
var end = getTopLevelEnd();
|
|
||||||
return toCps(e, end, end);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function defineVar( v : String, mode ) {
|
|
||||||
definedVars.push({ n : v, prev : vars.get(v) });
|
|
||||||
vars.set(v, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
function lookupFunctions( el : Array<Expr> ) {
|
|
||||||
for( e in el )
|
|
||||||
switch( expr(e) ) {
|
|
||||||
case EFunction(_, _, name, _) if( name != null ): defineVar(name, Defined);
|
|
||||||
case EMeta("sync",_,expr(_) => EFunction(_,_,name,_)) if( name != null ): defineVar(name, ForceSync);
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildSync( e : Expr, exit : Expr ) : Expr {
|
|
||||||
switch( expr(e) ) {
|
|
||||||
case EFunction(_,_,name,_):
|
|
||||||
if( name != null )
|
|
||||||
return toCps(e, null, null);
|
|
||||||
return e;
|
|
||||||
case EBlock(el):
|
|
||||||
var v = saveVars();
|
|
||||||
lookupFunctions(el);
|
|
||||||
var e = block([for(e in el) buildSync(e,exit)], e);
|
|
||||||
restoreVars(v);
|
|
||||||
return e;
|
|
||||||
case EMeta("async", _, e):
|
|
||||||
return toCps(e, ignore(), ignore());
|
|
||||||
case EMeta("sync", args, ef = expr(_) => EFunction(fargs, body, name, ret)):
|
|
||||||
return mk(EMeta("sync",args,mk(EFunction(fargs, buildSync(body,null), name, ret),ef)),e);
|
|
||||||
case EBreak if( currentBreak != null ):
|
|
||||||
return currentBreak(e);
|
|
||||||
case EContinue if( currentLoop != null ):
|
|
||||||
return block([retNull(currentLoop, e), mk(EReturn(),e)],e);
|
|
||||||
case EFor(_), EWhile(_):
|
|
||||||
var oldLoop = currentLoop, oldBreak = currentBreak;
|
|
||||||
currentLoop = null;
|
|
||||||
currentBreak = null;
|
|
||||||
e = Tools.map(e, buildSync.bind(_, exit));
|
|
||||||
currentLoop = oldLoop;
|
|
||||||
currentBreak = oldBreak;
|
|
||||||
return e;
|
|
||||||
case EReturn(eret) if( exit != null ):
|
|
||||||
return block([eret == null ? retNull(exit, e) : call(exit,[eret], e), mk(EReturn(),e)], e);
|
|
||||||
default:
|
|
||||||
return Tools.map(e, buildSync.bind(_, exit));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
vars = new Map();
|
|
||||||
definedVars = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
function ignore(?e) : Expr {
|
|
||||||
var inf = e == null ? nullExpr : e;
|
|
||||||
return fun("_", block(e == null ? [] : [e],inf));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline function ident(str, e) {
|
|
||||||
return mk(EIdent(str), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline function fun(arg:String, e, ?name) {
|
|
||||||
return mk(EFunction([{ name : arg, t : null }], e, name), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline function funs(arg:Array<String>, e, ?name) {
|
|
||||||
return mk(EFunction([for( a in arg ) { name : a, t : null }], e, name), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline function block(arr:Array<Expr>, e) {
|
|
||||||
if( arr.length == 1 && expr(arr[0]).match(EBlock(_)) )
|
|
||||||
return arr[0];
|
|
||||||
return mk(EBlock(arr), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline function field(e, f, inf) {
|
|
||||||
return mk(EField(e, f), inf);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline function binop(op, e1, e2, inf) {
|
|
||||||
return mk(EBinop(op, e1, e2), inf);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline function call(e, args, inf) {
|
|
||||||
return mk(ECall(e, args), inf);
|
|
||||||
}
|
|
||||||
|
|
||||||
function retNull(e:Expr,?pos) : Expr {
|
|
||||||
switch( expr(e) ) {
|
|
||||||
case EFunction([{name:"_"}], e, _, _): return e;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
return call(e, [nullId], pos == null ? e : pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeCall( ecall, args : Array<Expr>, rest : Expr, exit, sync = false ) {
|
|
||||||
var names = [for( i in 0...args.length ) "_a"+uid++];
|
|
||||||
var rargs = [for( i in 0...args.length ) ident(names[i],ecall)];
|
|
||||||
if( !sync )
|
|
||||||
rargs.unshift(rest);
|
|
||||||
var rest = mk(sync ? ECall(rest,[call(ecall, rargs,ecall)]) : ECall(ecall, rargs), ecall);
|
|
||||||
var i = args.length - 1;
|
|
||||||
while( i >= 0 ) {
|
|
||||||
rest = toCps(args[i], fun(names[i], rest), exit);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
return rest;
|
|
||||||
}
|
|
||||||
|
|
||||||
var syncFlag : Bool;
|
|
||||||
|
|
||||||
function isSync( e : Expr ) {
|
|
||||||
syncFlag = true;
|
|
||||||
checkSync(e);
|
|
||||||
return syncFlag;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline function isAsyncIdent( id : String ) {
|
|
||||||
return asyncIdents == null || asyncIdents.exists(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkSync( e : Expr ) {
|
|
||||||
if( !syncFlag )
|
|
||||||
return;
|
|
||||||
switch( expr(e) ) {
|
|
||||||
case ECall(expr(_) => EIdent(i),_) if( isAsyncIdent(i) || vars.get(i) == Defined ):
|
|
||||||
syncFlag = false;
|
|
||||||
case ECall(expr(_) => EField(_,i),_) if( isAsyncIdent(i) ):
|
|
||||||
syncFlag = false;
|
|
||||||
case EFunction(_,_,name,_) if( name != null ):
|
|
||||||
syncFlag = false;
|
|
||||||
case EMeta("sync" | "async", _, _):
|
|
||||||
// isolated from the sync part
|
|
||||||
default:
|
|
||||||
Tools.iter(e, checkSync);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function saveVars() {
|
|
||||||
return definedVars.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
function restoreVars(k) {
|
|
||||||
while( definedVars.length > k ) {
|
|
||||||
var v = definedVars.pop();
|
|
||||||
if( v.prev == null ) vars.remove(v.n) else vars.set(v.n, v.prev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toCps( e : Expr, rest : Expr, exit : Expr ) : Expr {
|
|
||||||
if( isSync(e) )
|
|
||||||
return call(rest, [buildSync(e, exit)],e);
|
|
||||||
switch( expr(e) ) {
|
|
||||||
case EBlock(el):
|
|
||||||
var el = el.copy();
|
|
||||||
var vold = saveVars();
|
|
||||||
lookupFunctions(el);
|
|
||||||
while( el.length > 0 ) {
|
|
||||||
var e = toCps(el.pop(), rest, exit);
|
|
||||||
rest = ignore(e);
|
|
||||||
}
|
|
||||||
restoreVars(vold);
|
|
||||||
return retNull(rest);
|
|
||||||
case EFunction(args, body, name, t):
|
|
||||||
var vold = saveVars();
|
|
||||||
if( name != null )
|
|
||||||
defineVar(name, Defined);
|
|
||||||
for( a in args )
|
|
||||||
defineVar(a.name, Defined);
|
|
||||||
args.unshift( { name : "_onEnd", t : null } );
|
|
||||||
var frest = ident("_onEnd",e);
|
|
||||||
var oldFun = currentFun;
|
|
||||||
currentFun = name;
|
|
||||||
var body = toCps(body, frest, frest);
|
|
||||||
var f = mk(EFunction(args, body, name, t),e);
|
|
||||||
restoreVars(vold);
|
|
||||||
return rest == null ? f : call(rest, [f],e);
|
|
||||||
case EParent(e):
|
|
||||||
return mk(EParent(toCps(e, rest, exit)),e);
|
|
||||||
case EMeta("sync", _, e):
|
|
||||||
return call(rest,[buildSync(e,exit)],e);
|
|
||||||
case EMeta("async", _, e):
|
|
||||||
var nothing = ignore();
|
|
||||||
return block([toCps(e,nothing,nothing),retNull(rest)],e);
|
|
||||||
case EMeta("split", _, e):
|
|
||||||
var args = switch( expr(e) ) { case EArrayDecl(el): el; default: throw "@split expression should be an array"; };
|
|
||||||
var args = [for( a in args ) fun("_rest", toCps(block([a],a), ident("_rest",a), exit))];
|
|
||||||
return call(ident("split",e), [rest, mk(EArrayDecl(args),e)],e);
|
|
||||||
case ECall(expr(_) => EIdent(i), args):
|
|
||||||
var mode = vars.get(i);
|
|
||||||
return makeCall( ident( mode != null ? i : "a_" + i,e) , args, rest, exit, mode == ForceSync);
|
|
||||||
case ECall(expr(_) => EField(e, f), args):
|
|
||||||
return makeCall(field(e,"a_"+f,e), args, rest, exit);
|
|
||||||
case EFor(v, eit, eloop):
|
|
||||||
var id = ++uid;
|
|
||||||
var it = ident("_i" + id,e);
|
|
||||||
var oldLoop = currentLoop, oldBreak = currentBreak;
|
|
||||||
var loop = ident("_loop" + id,e);
|
|
||||||
currentLoop = loop;
|
|
||||||
currentBreak = function(inf) return block([retNull(rest, inf), mk(EReturn(),inf)], inf);
|
|
||||||
var efor = block([
|
|
||||||
mk(EVar("_i" + id, call(ident("makeIterator",eit),[eit],eit)),eit),
|
|
||||||
fun("_", block([
|
|
||||||
mk(EIf(mk(EUnop("!", true, call( field(it, "hasNext", it), [], it)),it), currentBreak(it)),it),
|
|
||||||
mk(EVar(v, call(field(it, "next",it), [], it)), it),
|
|
||||||
toCps(eloop, loop, exit),
|
|
||||||
], it),"_loop" + id),
|
|
||||||
retNull(loop, e),
|
|
||||||
], e);
|
|
||||||
currentLoop = oldLoop;
|
|
||||||
currentBreak = oldBreak;
|
|
||||||
return efor;
|
|
||||||
case EUnop(op = "!", prefix, eop):
|
|
||||||
return toCps(eop, fun("_r",call(rest, [mk(EUnop(op, prefix, ident("_r",e)),e)], e)), exit);
|
|
||||||
case EBinop(op, e1, e2):
|
|
||||||
switch( op ) {
|
|
||||||
case "=", "+=", "-=", "/=", "*=", "%=", "&=", "|=", "^=":
|
|
||||||
switch( expr(e1) ) {
|
|
||||||
case EIdent(_):
|
|
||||||
var id = "_r" + uid++;
|
|
||||||
return toCps(e2, fun(id, call(rest, [binop(op, e1, ident(id,e1),e1)], e1)), exit);
|
|
||||||
case EField(ef1, f):
|
|
||||||
var id1 = "_r" + uid++;
|
|
||||||
var id2 = "_r" + uid++;
|
|
||||||
return toCps(ef1, fun(id1, toCps(e2, fun(id2, call(rest, [binop(op, field(ident(id1, e1), f, ef1), ident(id2, e2), e)], e)), exit)), exit);
|
|
||||||
case EArray(earr, eindex):
|
|
||||||
var idArr = "_r" + uid++;
|
|
||||||
var idIndex = "_r" + uid++;
|
|
||||||
var idVal = "_r" + uid++;
|
|
||||||
return toCps(earr,fun(idArr, toCps(eindex, fun(idIndex, toCps(e2,
|
|
||||||
fun(idVal, call(rest, [binop(op, mk(EArray(ident(idArr,earr), ident(idIndex,eindex)),e1), ident(idVal,e1), e)], e))
|
|
||||||
, exit)), exit)),exit);
|
|
||||||
default:
|
|
||||||
throw "assert " + e1;
|
|
||||||
}
|
|
||||||
case "||":
|
|
||||||
var id1 = "_r" + uid++;
|
|
||||||
var id2 = "_r" + uid++;
|
|
||||||
return toCps(e1, fun(id1, mk(EIf(binop("==", ident(id1,e1), ident("true",e1), e1),call(rest,[ident("true",e1)],e1),toCps(e2, rest, exit)),e)), exit);
|
|
||||||
case "&&":
|
|
||||||
var id1 = "_r" + uid++;
|
|
||||||
var id2 = "_r" + uid++;
|
|
||||||
return toCps(e1, fun(id1, mk(EIf(binop("!=", ident(id1,e1), ident("true",e1), e1),call(rest,[ident("false",e1)],e1),toCps(e2, rest, exit)),e)), exit);
|
|
||||||
default:
|
|
||||||
var id1 = "_r" + uid++;
|
|
||||||
var id2 = "_r" + uid++;
|
|
||||||
return toCps(e1, fun(id1, toCps(e2, fun(id2, call(rest, [binop(op, ident(id1,e1), ident(id2,e2), e)], e)), exit)), exit);
|
|
||||||
}
|
|
||||||
case EIf(cond, e1, e2), ETernary(cond, e1, e2):
|
|
||||||
return toCps(cond, fun("_c", mk(EIf(ident("_c",cond), toCps(e1, rest, exit), e2 == null ? retNull(rest) : toCps(e2, rest, exit)),e)), exit);
|
|
||||||
case EWhile(cond, ewh):
|
|
||||||
var id = ++uid;
|
|
||||||
var loop = ident("_loop" + id, cond);
|
|
||||||
var oldLoop = currentLoop, oldBreak = currentBreak;
|
|
||||||
currentLoop = loop;
|
|
||||||
currentBreak = function(e) return block([retNull(rest,e), mk(EReturn(),e)],e);
|
|
||||||
var ewhile = block([
|
|
||||||
fun("_r",
|
|
||||||
toCps(cond, fun("_c", mk(EIf(ident("_c", cond), toCps(ewh, loop, exit), retNull(rest,cond)),cond)), exit)
|
|
||||||
, "_loop"+id),
|
|
||||||
retNull(loop, cond),
|
|
||||||
],e);
|
|
||||||
currentLoop = oldLoop;
|
|
||||||
currentBreak = oldBreak;
|
|
||||||
return ewhile;
|
|
||||||
case EReturn(eret):
|
|
||||||
return eret == null ? retNull(exit, e) : toCps(eret, exit, exit);
|
|
||||||
case EObject(fields):
|
|
||||||
var id = "_o" + uid++;
|
|
||||||
var rest = call(rest, [ident(id,e)], e);
|
|
||||||
fields.reverse();
|
|
||||||
for( f in fields )
|
|
||||||
rest = toCps(f.e, fun("_r", block([
|
|
||||||
binop("=", mk(EField(ident(id,f.e), f.name),f.e), ident("_r",f.e), f.e),
|
|
||||||
rest,
|
|
||||||
],f.e)),exit);
|
|
||||||
return block([
|
|
||||||
mk(EVar(id, mk(EObject([]),e)),e),
|
|
||||||
rest,
|
|
||||||
],e);
|
|
||||||
case EArrayDecl(el):
|
|
||||||
var id = "_a" + uid++;
|
|
||||||
var rest = call(rest, [ident(id,e)], e);
|
|
||||||
var i = el.length - 1;
|
|
||||||
while( i >= 0 ) {
|
|
||||||
var e = el[i];
|
|
||||||
rest = toCps(e, fun("_r", block([
|
|
||||||
binop("=", mk(EArray(ident(id,e), mk(EConst(CInt(i)),e)),e), ident("_r",e), e),
|
|
||||||
rest,
|
|
||||||
],e)), exit);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
return block([
|
|
||||||
mk(EVar(id, mk(EArrayDecl([]),e)),e),
|
|
||||||
rest,
|
|
||||||
],e);
|
|
||||||
case EArray(earr, eindex):
|
|
||||||
var id1 = "_r" + uid++;
|
|
||||||
var id2 = "_r" + uid++;
|
|
||||||
return toCps(earr, fun(id1, toCps(eindex, fun(id2, call(rest, [mk(EArray(ident(id1,e), ident(id2,e)),e)], e)), exit)), exit);
|
|
||||||
case EVar(v, t, ev):
|
|
||||||
if( ev == null )
|
|
||||||
return block([e, retNull(rest, e)], e);
|
|
||||||
return block([
|
|
||||||
mk(EVar(v, t),e),
|
|
||||||
toCps(ev, fun("_r", block([binop("=", ident(v,e), ident("_r",e), e), retNull(rest,e)], e)), exit),
|
|
||||||
],e);
|
|
||||||
case EConst(_), EIdent(_), EUnop(_), EField(_):
|
|
||||||
return call(rest, [e], e);
|
|
||||||
case ENew(cl, args):
|
|
||||||
var names = [for( i in 0...args.length ) "_a"+uid++];
|
|
||||||
var rargs = [for( i in 0...args.length ) ident(names[i], args[i])];
|
|
||||||
var rest = call(rest,[mk(ENew(cl, rargs),e)],e);
|
|
||||||
var i = args.length - 1;
|
|
||||||
while( i >= 0 ) {
|
|
||||||
rest = toCps(args[i], fun(names[i], rest), exit);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
return rest;
|
|
||||||
case EBreak:
|
|
||||||
if( currentBreak == null ) throw "Break outside loop";
|
|
||||||
return currentBreak(e);
|
|
||||||
case EContinue:
|
|
||||||
if( currentLoop == null ) throw "Continue outside loop";
|
|
||||||
return block([retNull(currentLoop, e), mk(EReturn(),e)], e);
|
|
||||||
case ESwitch(v, cases, def):
|
|
||||||
var cases = [for( c in cases ) { values : c.values, expr : toCps(c.expr, rest, exit) } ];
|
|
||||||
return toCps(v, mk(EFunction([ { name : "_c", t : null } ], mk(ESwitch(ident("_c",v), cases, def == null ? retNull(rest) : toCps(def, rest, exit)),e)),e), exit );
|
|
||||||
case EThrow(v):
|
|
||||||
return toCps(v, mk(EFunction([ { name : "_v", t : null } ], mk(EThrow(v),v)), v), exit);
|
|
||||||
case EMeta(name,_,e) if( name.charCodeAt(0) == ":".code ): // ignore custom ":" metadata
|
|
||||||
return toCps(e, rest, exit);
|
|
||||||
//case EDoWhile(_), ETry(_), ECall(_):
|
|
||||||
default:
|
|
||||||
throw "Unsupported async expression " + Printer.toString(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class AsyncInterp extends Interp {
|
|
||||||
|
|
||||||
public function setContext( api : Dynamic ) {
|
|
||||||
|
|
||||||
var funs = new Array();
|
|
||||||
for( v in variables.keys() )
|
|
||||||
if( Reflect.isFunction(variables.get(v)) )
|
|
||||||
funs.push({ v : v, obj : null });
|
|
||||||
|
|
||||||
variables.set("split", split);
|
|
||||||
variables.set("makeIterator", makeIterator);
|
|
||||||
|
|
||||||
var c = Type.getClass(api);
|
|
||||||
for( f in (c == null ? Reflect.fields(api) : Type.getInstanceFields(c)) ) {
|
|
||||||
var fv = Reflect.field(api, f);
|
|
||||||
if( !Reflect.isFunction(fv) ) continue;
|
|
||||||
if( f.charCodeAt(0) == "_".code ) f = f.substr(1);
|
|
||||||
variables.set(f, fv);
|
|
||||||
// create the async wrapper if doesn't exists
|
|
||||||
if( f.substr(0, 2) != "a_" )
|
|
||||||
funs.push({ v : f, obj : api });
|
|
||||||
}
|
|
||||||
|
|
||||||
for( v in funs ) {
|
|
||||||
if( variables.exists("a_" + v.v) ) continue;
|
|
||||||
var fv : Dynamic = variables.get(v.v);
|
|
||||||
var obj = v.obj;
|
|
||||||
variables.set("a_" + v.v, Reflect.makeVarArgs(function(args:Array<Dynamic>) {
|
|
||||||
var onEnd = args.shift();
|
|
||||||
onEnd(Reflect.callMethod(obj, fv, args));
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasMethod( name : String ) {
|
|
||||||
var v = variables.get(name);
|
|
||||||
return v != null && Reflect.isFunction(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function callValue( value : Dynamic, args : Array<Dynamic>, ?onResult : Dynamic -> Void, ?vthis : {} ) {
|
|
||||||
var oldThis = variables.get("this");
|
|
||||||
if( vthis != null )
|
|
||||||
variables.set("this", vthis);
|
|
||||||
if( onResult == null )
|
|
||||||
onResult = function(_) {};
|
|
||||||
args.unshift(onResult);
|
|
||||||
Reflect.callMethod(null, value, args);
|
|
||||||
variables.set("this", oldThis);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function callAsync( id : String, args, ?onResult, ?vthis : {} ) {
|
|
||||||
var v = variables.get(id);
|
|
||||||
if( v == null )
|
|
||||||
throw "Missing function " + id + "()";
|
|
||||||
callValue(v, args, onResult, vthis);
|
|
||||||
}
|
|
||||||
|
|
||||||
function split( rest : Dynamic -> Void, args : Array<Dynamic> ) {
|
|
||||||
if( args.length == 0 )
|
|
||||||
rest(null);
|
|
||||||
else {
|
|
||||||
var count = args.length;
|
|
||||||
function next(_) {
|
|
||||||
if( --count == 0 ) rest(null);
|
|
||||||
}
|
|
||||||
for( a in args )
|
|
||||||
a(next);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override function fcall( o : Dynamic, f : String, args : Array<Dynamic> ) : Dynamic {
|
|
||||||
var m = Reflect.field(o, f);
|
|
||||||
if( m == null ) {
|
|
||||||
if( f.substr(0, 2) == "a_" ) {
|
|
||||||
m = Reflect.field(o, f.substr(2));
|
|
||||||
// fallback on sync version
|
|
||||||
if( m != null ) {
|
|
||||||
var onEnd = args.shift();
|
|
||||||
onEnd(call(o, m, args));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// fallback on generic script
|
|
||||||
m = Reflect.field(o, "scriptCall");
|
|
||||||
if( m != null ) {
|
|
||||||
call(o, m, [args.shift(), f.substr(2), args]);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// fallback on generic script
|
|
||||||
m = Reflect.field(o, "scriptCall");
|
|
||||||
if( m != null ) {
|
|
||||||
var result : Dynamic = null;
|
|
||||||
call(o, m, [function(r) result = r, f, args]);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
error(ECustom(o + " has no method " + f));
|
|
||||||
}
|
|
||||||
return call(o, m, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+25
-41
@@ -1,23 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C)2008-2017 Haxe Foundation
|
* Copyright (c) 2008, Nicolas Cannasse
|
||||||
|
* All rights reserved.
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* - Redistributions of source code must retain the above copyright
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* to deal in the Software without restriction, including without limitation
|
* - Redistributions in binary form must reproduce the above copyright
|
||||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* and/or sell copies of the Software, and to permit persons to whom the
|
* documentation and/or other materials provided with the distribution.
|
||||||
* Software is furnished to do so, subject to the following conditions:
|
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
|
||||||
* all copies or substantial portions of the Software.
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
*
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
* DEALINGS IN THE SOFTWARE.
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
* DAMAGE.
|
||||||
*/
|
*/
|
||||||
package hscript;
|
package hscript;
|
||||||
import hscript.Expr;
|
import hscript.Expr;
|
||||||
@@ -72,7 +75,10 @@ class Bytes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function doEncodeInt(v: Int) {
|
function doEncodeInt(v: Int) {
|
||||||
bout.addInt32(v);
|
bout.addByte(v & 0xFF);
|
||||||
|
bout.addByte((v >> 8) & 0xFF);
|
||||||
|
bout.addByte((v >> 16) & 0xFF);
|
||||||
|
bout.addByte(v >>> 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
function doEncodeConst( c : Const ) {
|
function doEncodeConst( c : Const ) {
|
||||||
@@ -104,7 +110,7 @@ class Bytes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function doDecodeInt() {
|
function doDecodeInt() {
|
||||||
var i = bin.getInt32(pin);
|
var i = bin.get(pin) | (bin.get(pin+1) << 8) | (bin.get(pin+2) << 16) | (bin.get(pin+3) << 24);
|
||||||
pin += 4;
|
pin += 4;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -140,10 +146,6 @@ class Bytes {
|
|||||||
#end
|
#end
|
||||||
bout.addByte(Type.enumIndex(e));
|
bout.addByte(Type.enumIndex(e));
|
||||||
switch( e ) {
|
switch( e ) {
|
||||||
case EImport(c):
|
|
||||||
// TODO
|
|
||||||
case EClass(_, _, _, _):
|
|
||||||
// TODO
|
|
||||||
case EConst(c):
|
case EConst(c):
|
||||||
doEncodeConst(c);
|
doEncodeConst(c);
|
||||||
case EIdent(v):
|
case EIdent(v):
|
||||||
@@ -245,22 +247,11 @@ class Bytes {
|
|||||||
}
|
}
|
||||||
bout.addByte(255);
|
bout.addByte(255);
|
||||||
if( def == null ) bout.addByte(255) else doEncode(def);
|
if( def == null ) bout.addByte(255) else doEncode(def);
|
||||||
case EMeta(name,args,e):
|
|
||||||
doEncodeString(name);
|
|
||||||
bout.addByte(args == null ? 0 : args.length + 1);
|
|
||||||
if( args != null ) for( e in args ) doEncode(e);
|
|
||||||
doEncode(e);
|
|
||||||
case ECheckType(e,_):
|
|
||||||
doEncode(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function doDecode() : Expr {
|
function doDecode() : Expr {
|
||||||
#if hscriptPos
|
#if hscriptPos
|
||||||
if (bin.get(pin) == 255) {
|
|
||||||
pin++;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var origin = doDecodeString();
|
var origin = doDecodeString();
|
||||||
var line = doDecodeInt();
|
var line = doDecodeInt();
|
||||||
return { e : _doDecode(), pmin : 0, pmax : 0, origin : origin, line : line };
|
return { e : _doDecode(), pmin : 0, pmax : 0, origin : origin, line : line };
|
||||||
@@ -375,13 +366,6 @@ class Bytes {
|
|||||||
case 24:
|
case 24:
|
||||||
var cond = doDecode();
|
var cond = doDecode();
|
||||||
EDoWhile(cond,doDecode());
|
EDoWhile(cond,doDecode());
|
||||||
case 25:
|
|
||||||
var name = doDecodeString();
|
|
||||||
var count = bin.get(pin++);
|
|
||||||
var args = count == 0 ? null : [for( i in 0...count - 1 ) doDecode()];
|
|
||||||
EMeta(name, args, doDecode());
|
|
||||||
case 26:
|
|
||||||
ECheckType(doDecode(), CTPath(["Void"]));
|
|
||||||
case 255:
|
case 255:
|
||||||
null;
|
null;
|
||||||
default:
|
default:
|
||||||
|
|||||||
-1241
File diff suppressed because it is too large
Load Diff
@@ -1,105 +0,0 @@
|
|||||||
package hscript;
|
|
||||||
|
|
||||||
using StringTools;
|
|
||||||
|
|
||||||
class CustomClassHandler implements IHScriptCustomConstructor {
|
|
||||||
public static var staticHandler = new StaticHandler();
|
|
||||||
|
|
||||||
public var ogInterp:Interp;
|
|
||||||
public var name:String;
|
|
||||||
public var fields:Array<Expr>;
|
|
||||||
public var extend:String;
|
|
||||||
public var interfaces:Array<String>;
|
|
||||||
|
|
||||||
public function new(ogInterp:Interp, name:String, fields:Array<Expr>, ?extend:String, ?interfaces:Array<String>) {
|
|
||||||
this.ogInterp = ogInterp;
|
|
||||||
this.name = name;
|
|
||||||
this.fields = fields;
|
|
||||||
this.extend = extend;
|
|
||||||
this.interfaces = interfaces;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hnew(args:Array<Dynamic>):Dynamic {
|
|
||||||
var interp = new Interp();
|
|
||||||
|
|
||||||
interp.errorHandler = ogInterp.errorHandler;
|
|
||||||
|
|
||||||
var cl = extend == null ? TemplateClass : Type.resolveClass('${extend}_HSX');
|
|
||||||
var _class = Type.createInstance(cl, args);
|
|
||||||
|
|
||||||
var __capturedLocals = ogInterp.duplicate(ogInterp.locals);
|
|
||||||
var capturedLocals:Map<String, {r:Dynamic, depth:Int}> = [];
|
|
||||||
for(k=>e in __capturedLocals)
|
|
||||||
if (e != null && e.depth <= 0)
|
|
||||||
capturedLocals.set(k, e);
|
|
||||||
|
|
||||||
var disallowCopy = Type.getInstanceFields(cl);
|
|
||||||
|
|
||||||
//trace("Locals");
|
|
||||||
for (key => value in capturedLocals) {
|
|
||||||
if(!disallowCopy.contains(key)) {
|
|
||||||
interp.locals.set(key, {r: value, depth: -1});
|
|
||||||
//trace(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//trace("Variables");
|
|
||||||
for (key => value in ogInterp.variables) {
|
|
||||||
if(!disallowCopy.contains(key)) {
|
|
||||||
interp.variables.set(key, value);
|
|
||||||
//trace(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(expr in fields) {
|
|
||||||
@:privateAccess
|
|
||||||
interp.exprReturn(expr);
|
|
||||||
}
|
|
||||||
|
|
||||||
interp.variables.set("super", staticHandler);
|
|
||||||
|
|
||||||
_class.__interp = interp;
|
|
||||||
interp.scriptObject = _class;
|
|
||||||
|
|
||||||
var newFunc = interp.variables.get("new");
|
|
||||||
if(newFunc != null) {
|
|
||||||
Reflect.callMethod(null, newFunc, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(variable => value in interp.variables) {
|
|
||||||
if(variable == "this") continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toString():String {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TemplateClass implements IHScriptCustomBehaviour {
|
|
||||||
public var __interp:Interp;
|
|
||||||
|
|
||||||
public function hset(name:String, val:Dynamic):Dynamic {
|
|
||||||
if(this.__interp.variables.exists("set_" + name)) {
|
|
||||||
return this.__interp.variables.get("set_" + name)(val); // TODO: Prevent recursion from setting it in the function
|
|
||||||
}
|
|
||||||
if (this.__interp.variables.exists(name)) {
|
|
||||||
this.__interp.variables.set(name, val);
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
Reflect.setProperty(this, name, val);
|
|
||||||
return Reflect.field(this, name);
|
|
||||||
}
|
|
||||||
public function hget(name:String):Dynamic {
|
|
||||||
if(this.__interp.variables.exists("get_" + name))
|
|
||||||
return this.__interp.variables.get("get_" + name)();
|
|
||||||
if (this.__interp.variables.exists(name))
|
|
||||||
return this.__interp.variables.get(name);
|
|
||||||
return Reflect.getProperty(this, name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class StaticHandler {
|
|
||||||
public function new() {}
|
|
||||||
}
|
|
||||||
+59
-99
@@ -1,23 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C)2008-2017 Haxe Foundation
|
* Copyright (c) 2008, Nicolas Cannasse
|
||||||
|
* All rights reserved.
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* - Redistributions of source code must retain the above copyright
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* to deal in the Software without restriction, including without limitation
|
* - Redistributions in binary form must reproduce the above copyright
|
||||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* and/or sell copies of the Software, and to permit persons to whom the
|
* documentation and/or other materials provided with the distribution.
|
||||||
* Software is furnished to do so, subject to the following conditions:
|
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
|
||||||
* all copies or substantial portions of the Software.
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
*
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
* DEALINGS IN THE SOFTWARE.
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
* DAMAGE.
|
||||||
*/
|
*/
|
||||||
package hscript;
|
package hscript;
|
||||||
|
|
||||||
@@ -40,15 +43,14 @@ typedef Expr = {
|
|||||||
}
|
}
|
||||||
enum ExprDef {
|
enum ExprDef {
|
||||||
#else
|
#else
|
||||||
typedef ExprDef = Expr;
|
|
||||||
enum Expr {
|
enum Expr {
|
||||||
#end
|
#end
|
||||||
EConst( c : Const );
|
EConst( c : Const );
|
||||||
EIdent( v : String );
|
EIdent( v : String );
|
||||||
EVar( n : String, ?t : CType, ?e : Expr, ?isPublic : Bool, ?isStatic : Bool );
|
EVar( n : String, ?t : CType, ?e : Expr );
|
||||||
EParent( e : Expr );
|
EParent( e : Expr );
|
||||||
EBlock( e : Array<Expr> );
|
EBlock( e : Array<Expr> );
|
||||||
EField( e : Expr, f : String , ?safe : Bool );
|
EField( e : Expr, f : String );
|
||||||
EBinop( op : String, e1 : Expr, e2 : Expr );
|
EBinop( op : String, e1 : Expr, e2 : Expr );
|
||||||
EUnop( op : String, prefix : Bool, e : Expr );
|
EUnop( op : String, prefix : Bool, e : Expr );
|
||||||
ECall( e : Expr, params : Array<Expr> );
|
ECall( e : Expr, params : Array<Expr> );
|
||||||
@@ -57,35 +59,26 @@ enum Expr {
|
|||||||
EFor( v : String, it : Expr, e : Expr );
|
EFor( v : String, it : Expr, e : Expr );
|
||||||
EBreak;
|
EBreak;
|
||||||
EContinue;
|
EContinue;
|
||||||
EFunction( args : Array<Argument>, e : Expr, ?name : String, ?ret : CType, ?isPublic : Bool, ?isStatic : Bool, ?isOverride : Bool );
|
EFunction( args : Array<Argument>, e : Expr, ?name : String, ?ret : CType );
|
||||||
EReturn( ?e : Expr );
|
EReturn( ?e : Expr );
|
||||||
EArray( e : Expr, index : Expr );
|
EArray( e : Expr, index : Expr );
|
||||||
EArrayDecl( e : Array<Expr>, ?wantedType: CType );
|
EArrayDecl( e : Array<Expr> );
|
||||||
ENew( cl : String, params : Array<Expr> );
|
ENew( cl : String, params : Array<Expr> );
|
||||||
EThrow( e : Expr );
|
EThrow( e : Expr );
|
||||||
ETry( e : Expr, v : String, t : Null<CType>, ecatch : Expr );
|
ETry( e : Expr, v : String, t : Null<CType>, ecatch : Expr );
|
||||||
EObject( fl : Array<{ name : String, e : Expr }> );
|
EObject( fl : Array<{ name : String, e : Expr }> );
|
||||||
ETernary( cond : Expr, e1 : Expr, e2 : Expr );
|
ETernary( cond : Expr, e1 : Expr, e2 : Expr );
|
||||||
ESwitch( e : Expr, cases : Array<{ values : Array<Expr>, expr : Expr }>, ?defaultExpr : Expr );
|
ESwitch( e : Expr, cases : Array<{ values : Array<Expr>, expr : Expr }>, ?defaultExpr : Expr);
|
||||||
EDoWhile( cond : Expr, e : Expr);
|
EDoWhile( cond : Expr, e : Expr);
|
||||||
EMeta( name : String, args : Array<Expr>, e : Expr );
|
|
||||||
ECheckType( e : Expr, t : CType );
|
|
||||||
|
|
||||||
EImport( c : String, ?asname:String );
|
|
||||||
EClass( name:String, fields:Array<Expr>, ?extend:String, interfaces:Array<String> );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef Argument = { name : String, ?t : CType, ?opt : Bool, ?value : Expr };
|
typedef Argument = { name : String, ?t : CType, ?opt : Bool };
|
||||||
|
|
||||||
typedef Metadata = Array<{ name : String, params : Array<Expr> }>;
|
|
||||||
|
|
||||||
enum CType {
|
enum CType {
|
||||||
CTPath( path : Array<String>, ?params : Array<CType> );
|
CTPath( path : Array<String>, ?params : Array<CType> );
|
||||||
CTFun( args : Array<CType>, ret : CType );
|
CTFun( args : Array<CType>, ret : CType );
|
||||||
CTAnon( fields : Array<{ name : String, t : CType, ?meta : Metadata }> );
|
CTAnon( fields : Array<{ name : String, t : CType }> );
|
||||||
CTParent( t : CType );
|
CTParent( t : CType );
|
||||||
CTOpt( t : CType );
|
|
||||||
CTNamed( n : String, t : CType );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if hscriptPos
|
#if hscriptPos
|
||||||
@@ -102,8 +95,39 @@ class Error {
|
|||||||
this.origin = origin;
|
this.origin = origin;
|
||||||
this.line = line;
|
this.line = line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function errorDefToString(): String {
|
||||||
|
switch (e) {
|
||||||
|
case EInvalidChar(c):
|
||||||
|
return "Invalid character: '"+c+"'";
|
||||||
|
|
||||||
|
case EUnexpected(s):
|
||||||
|
return "Unexpected token: \""+s+"\"";
|
||||||
|
|
||||||
|
case EUnterminatedString:
|
||||||
|
return "Unterminated string";
|
||||||
|
|
||||||
|
case EUnterminatedComment:
|
||||||
|
return "Unterminated comment";
|
||||||
|
|
||||||
|
case EUnknownVariable(v):
|
||||||
|
return "Unknown variable: "+v;
|
||||||
|
|
||||||
|
case EInvalidIterator(v):
|
||||||
|
return "Invalid iterator: "+v;
|
||||||
|
|
||||||
|
case EInvalidOp(op):
|
||||||
|
return "Invalid operator: "+op;
|
||||||
|
|
||||||
|
case EInvalidAccess(f):
|
||||||
|
return "Invalid access to field "+f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function toString(): String {
|
public function toString(): String {
|
||||||
return Printer.errorToString(this);
|
var message = errorDefToString();
|
||||||
|
message = origin + ":" + line + ": " + message;
|
||||||
|
return message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enum ErrorDef {
|
enum ErrorDef {
|
||||||
@@ -114,72 +138,8 @@ enum Error {
|
|||||||
EUnexpected( s : String );
|
EUnexpected( s : String );
|
||||||
EUnterminatedString;
|
EUnterminatedString;
|
||||||
EUnterminatedComment;
|
EUnterminatedComment;
|
||||||
EInvalidPreprocessor( msg : String );
|
|
||||||
EUnknownVariable( v : String );
|
EUnknownVariable( v : String );
|
||||||
EInvalidIterator( v : String );
|
EInvalidIterator( v : String );
|
||||||
EInvalidOp( op : String );
|
EInvalidOp( op : String );
|
||||||
EInvalidAccess( f : String );
|
EInvalidAccess( f : String );
|
||||||
ECustom( msg : String );
|
|
||||||
EInvalidClass( className : String);
|
|
||||||
EAlreadyExistingClass( className : String);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
enum ModuleDecl {
|
|
||||||
DPackage( path : Array<String> );
|
|
||||||
DImport( path : Array<String>, ?everything : Bool );
|
|
||||||
DClass( c : ClassDecl );
|
|
||||||
DTypedef( c : TypeDecl );
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef ModuleType = {
|
|
||||||
var name : String;
|
|
||||||
var params : {}; // TODO : not yet parsed
|
|
||||||
var meta : Metadata;
|
|
||||||
var isPrivate : Bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef ClassDecl = {> ModuleType,
|
|
||||||
var extend : Null<CType>;
|
|
||||||
var implement : Array<CType>;
|
|
||||||
var fields : Array<FieldDecl>;
|
|
||||||
var isExtern : Bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef TypeDecl = {> ModuleType,
|
|
||||||
var t : CType;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef FieldDecl = {
|
|
||||||
var name : String;
|
|
||||||
var meta : Metadata;
|
|
||||||
var kind : FieldKind;
|
|
||||||
var access : Array<FieldAccess>;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum FieldAccess {
|
|
||||||
APublic;
|
|
||||||
APrivate;
|
|
||||||
AInline;
|
|
||||||
AOverride;
|
|
||||||
AStatic;
|
|
||||||
AMacro;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum FieldKind {
|
|
||||||
KFunction( f : FunctionDecl );
|
|
||||||
KVar( v : VarDecl );
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef FunctionDecl = {
|
|
||||||
var args : Array<Argument>;
|
|
||||||
var expr : Expr;
|
|
||||||
var ret : Null<CType>;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef VarDecl = {
|
|
||||||
var get : Null<String>;
|
|
||||||
var set : Null<String>;
|
|
||||||
var expr : Null<Expr>;
|
|
||||||
var type : Null<CType>;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
package hscript;
|
|
||||||
|
|
||||||
interface IHScriptCustomBehaviour {
|
|
||||||
public function hset(name:String, val:Dynamic):Dynamic;
|
|
||||||
public function hget(name:String):Dynamic;
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package hscript;
|
|
||||||
|
|
||||||
interface IHScriptCustomConstructor {
|
|
||||||
public function hnew(args:Array<Dynamic>):Dynamic;
|
|
||||||
}
|
|
||||||
+492
-838
File diff suppressed because it is too large
Load Diff
+30
-51
@@ -1,23 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C)2008-2017 Haxe Foundation
|
* Copyright (c) 2011, Nicolas Cannasse
|
||||||
|
* All rights reserved.
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* - Redistributions of source code must retain the above copyright
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* to deal in the Software without restriction, including without limitation
|
* - Redistributions in binary form must reproduce the above copyright
|
||||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* and/or sell copies of the Software, and to permit persons to whom the
|
* documentation and/or other materials provided with the distribution.
|
||||||
* Software is furnished to do so, subject to the following conditions:
|
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
|
||||||
* all copies or substantial portions of the Software.
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
*
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
* DEALINGS IN THE SOFTWARE.
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
* DAMAGE.
|
||||||
*/
|
*/
|
||||||
package hscript;
|
package hscript;
|
||||||
import hscript.Expr.Error;
|
import hscript.Expr.Error;
|
||||||
@@ -76,11 +79,6 @@ class Macro {
|
|||||||
#if haxe3
|
#if haxe3
|
||||||
case OpArrow: "=>";
|
case OpArrow: "=>";
|
||||||
#end
|
#end
|
||||||
#if (haxe_ver >= 4)
|
|
||||||
case OpIn: "in";
|
|
||||||
#end
|
|
||||||
default:
|
|
||||||
continue;
|
|
||||||
};
|
};
|
||||||
binops.set(str, op);
|
binops.set(str, op);
|
||||||
if( assign )
|
if( assign )
|
||||||
@@ -94,9 +92,6 @@ class Macro {
|
|||||||
case OpNegBits: "~";
|
case OpNegBits: "~";
|
||||||
case OpIncrement: "++";
|
case OpIncrement: "++";
|
||||||
case OpDecrement: "--";
|
case OpDecrement: "--";
|
||||||
#if (haxe_ver >= 4.2)
|
|
||||||
case OpSpread: continue;
|
|
||||||
#end
|
|
||||||
}
|
}
|
||||||
unops.set(str, op);
|
unops.set(str, op);
|
||||||
}
|
}
|
||||||
@@ -118,7 +113,6 @@ class Macro {
|
|||||||
|
|
||||||
function convertType( t : Expr.CType ) : ComplexType {
|
function convertType( t : Expr.CType ) : ComplexType {
|
||||||
return switch( t ) {
|
return switch( t ) {
|
||||||
case CTOpt(t): TOptional(convertType(t));
|
|
||||||
case CTPath(pack, args):
|
case CTPath(pack, args):
|
||||||
var params = [];
|
var params = [];
|
||||||
if( args != null )
|
if( args != null )
|
||||||
@@ -133,18 +127,10 @@ class Macro {
|
|||||||
case CTParent(t): TParent(convertType(t));
|
case CTParent(t): TParent(convertType(t));
|
||||||
case CTFun(args, ret):
|
case CTFun(args, ret):
|
||||||
TFunction(map(args,convertType), convertType(ret));
|
TFunction(map(args,convertType), convertType(ret));
|
||||||
case CTNamed(name, convertType(_) => ct):
|
|
||||||
#if (haxe_ver >= 4)
|
|
||||||
TNamed(name, ct);
|
|
||||||
#else
|
|
||||||
ct;
|
|
||||||
#end
|
|
||||||
case CTAnon(fields):
|
case CTAnon(fields):
|
||||||
var tf = [];
|
var tf = [];
|
||||||
for( f in fields ) {
|
for( f in fields )
|
||||||
var meta = f.meta == null ? [] : [for( m in f.meta ) { name : m.name, params : m.params == null ? [] : [for( e in m.params ) convert(e)], pos : p }];
|
tf.push( { name : f.name, meta : [], doc : null, access : [], kind : FVar(convertType(f.t),null), pos : p } );
|
||||||
tf.push( { name : f.name, meta : meta, doc : null, access : [], kind : FVar(convertType(f.t), null), pos : p } );
|
|
||||||
}
|
|
||||||
TAnonymous(tf);
|
TAnonymous(tf);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -196,16 +182,14 @@ class Macro {
|
|||||||
EWhile(convert(c), convert(e), true);
|
EWhile(convert(c), convert(e), true);
|
||||||
case EDoWhile(c, e):
|
case EDoWhile(c, e):
|
||||||
EWhile(convert(c), convert(e), false);
|
EWhile(convert(c), convert(e), false);
|
||||||
|
#if (haxe_211 || haxe3)
|
||||||
case EFor(v, it, efor):
|
case EFor(v, it, efor):
|
||||||
#if (haxe_ver >= 4)
|
var p = #if hscriptPos { file : p.file, min : e.pmin, max : e.pmax } #else p #end;
|
||||||
var p = #if hscriptPos { file : p.file, min : e.pmin, max : e.pmax } #else p #end;
|
EFor({ expr : EIn({ expr : EConst(CIdent(v)), pos : p },convert(it)), pos : p }, convert(efor));
|
||||||
EFor({ expr : EBinop(OpIn,{ expr : EConst(CIdent(v)), pos : p },convert(it)), pos : p }, convert(efor));
|
#else
|
||||||
#elseif (haxe_211 || haxe3)
|
case EFor(v, it, e):
|
||||||
var p = #if hscriptPos { file : p.file, min : e.pmin, max : e.pmax } #else p #end;
|
EFor(v, convert(it), convert(e));
|
||||||
EFor({ expr : EIn({ expr : EConst(CIdent(v)), pos : p },convert(it)), pos : p }, convert(efor));
|
#end
|
||||||
#else
|
|
||||||
EFor(v, convert(it), convert(efor));
|
|
||||||
#end
|
|
||||||
case EBreak:
|
case EBreak:
|
||||||
EBreak;
|
EBreak;
|
||||||
case EContinue:
|
case EContinue:
|
||||||
@@ -219,7 +203,7 @@ class Macro {
|
|||||||
opt : false,
|
opt : false,
|
||||||
value : null,
|
value : null,
|
||||||
});
|
});
|
||||||
EFunction(#if haxe4 FNamed(name,false) #else name #end, {
|
EFunction(name, {
|
||||||
params : [],
|
params : [],
|
||||||
args : targs,
|
args : targs,
|
||||||
expr : convert(e),
|
expr : convert(e),
|
||||||
@@ -247,11 +231,6 @@ class Macro {
|
|||||||
ETernary(convert(cond), convert(e1), convert(e2));
|
ETernary(convert(cond), convert(e1), convert(e2));
|
||||||
case ESwitch(e, cases, edef):
|
case ESwitch(e, cases, edef):
|
||||||
ESwitch(convert(e), [for( c in cases ) { values : [for( v in c.values ) convert(v)], expr : convert(c.expr) } ], edef == null ? null : convert(edef));
|
ESwitch(convert(e), [for( c in cases ) { values : [for( v in c.values ) convert(v)], expr : convert(c.expr) } ], edef == null ? null : convert(edef));
|
||||||
case EMeta(m, params, esub):
|
|
||||||
var mpos = #if hscriptPos { file : p.file, min : e.pmin, max : e.pmax } #else p #end;
|
|
||||||
EMeta({ name : m, params : params == null ? [] : [for( p in params ) convert(p)], pos : mpos }, convert(esub));
|
|
||||||
case ECheckType(e, t):
|
|
||||||
ECheckType(convert(e), convertType(t));
|
|
||||||
}, pos : #if hscriptPos { file : p.file, min : e.pmin, max : e.pmax } #else p #end }
|
}, pos : #if hscriptPos { file : p.file, min : e.pmin, max : e.pmax } #else p #end }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+440
-1329
File diff suppressed because it is too large
Load Diff
+6
-112
@@ -1,24 +1,3 @@
|
|||||||
/*
|
|
||||||
* Copyright (C)2008-2017 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 hscript;
|
package hscript;
|
||||||
import hscript.Expr;
|
import hscript.Expr;
|
||||||
|
|
||||||
@@ -37,20 +16,10 @@ class Printer {
|
|||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function typeToString( t : CType ) {
|
|
||||||
buf = new StringBuf();
|
|
||||||
tabs = "";
|
|
||||||
type(t);
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline function add<T>(s:T) buf.add(s);
|
inline function add<T>(s:T) buf.add(s);
|
||||||
|
|
||||||
function type( t : CType ) {
|
function type( t : CType ) {
|
||||||
switch( t ) {
|
switch( t ) {
|
||||||
case CTOpt(t):
|
|
||||||
add('?');
|
|
||||||
type(t);
|
|
||||||
case CTPath(path, params):
|
case CTPath(path, params):
|
||||||
add(path.join("."));
|
add(path.join("."));
|
||||||
if( params != null ) {
|
if( params != null ) {
|
||||||
@@ -62,19 +31,6 @@ class Printer {
|
|||||||
}
|
}
|
||||||
add(">");
|
add(">");
|
||||||
}
|
}
|
||||||
case CTNamed(name, t):
|
|
||||||
add(name);
|
|
||||||
add(':');
|
|
||||||
type(t);
|
|
||||||
case CTFun(args, ret) if (Lambda.exists(args, function (a) return a.match(CTNamed(_, _)))):
|
|
||||||
add('(');
|
|
||||||
for (a in args)
|
|
||||||
switch a {
|
|
||||||
case CTNamed(_, _): type(a);
|
|
||||||
default: type(CTNamed('_', a));
|
|
||||||
}
|
|
||||||
add(')->');
|
|
||||||
type(ret);
|
|
||||||
case CTFun(args, ret):
|
case CTFun(args, ret):
|
||||||
if( args.length == 0 )
|
if( args.length == 0 )
|
||||||
add("Void -> ");
|
add("Void -> ");
|
||||||
@@ -114,25 +70,6 @@ class Printer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch( #if hscriptPos e.e #else e #end ) {
|
switch( #if hscriptPos e.e #else e #end ) {
|
||||||
case EImport(c, n):
|
|
||||||
add("import " + c);
|
|
||||||
if(n != null)
|
|
||||||
add(' as $n');
|
|
||||||
case EClass(name, fields, extend, interfaces):
|
|
||||||
add('class $name');
|
|
||||||
if (extend != null)
|
|
||||||
add(' extends $extend');
|
|
||||||
for(_interface in interfaces) {
|
|
||||||
add(' implements $_interface');
|
|
||||||
}
|
|
||||||
add(' {\n');
|
|
||||||
tabs += "\t";
|
|
||||||
//for(field in fields) {
|
|
||||||
// expr(field);
|
|
||||||
//}
|
|
||||||
|
|
||||||
tabs = tabs.substr(1);
|
|
||||||
add("}");
|
|
||||||
case EConst(c):
|
case EConst(c):
|
||||||
switch( c ) {
|
switch( c ) {
|
||||||
case CInt(i): add(i);
|
case CInt(i): add(i);
|
||||||
@@ -141,7 +78,7 @@ class Printer {
|
|||||||
}
|
}
|
||||||
case EIdent(v):
|
case EIdent(v):
|
||||||
add(v);
|
add(v);
|
||||||
case EVar(n, t, e): // TODO: static, public, override
|
case EVar(n, t, e):
|
||||||
add("var " + n);
|
add("var " + n);
|
||||||
addType(t);
|
addType(t);
|
||||||
if( e != null ) {
|
if( e != null ) {
|
||||||
@@ -164,9 +101,9 @@ class Printer {
|
|||||||
tabs = tabs.substr(1);
|
tabs = tabs.substr(1);
|
||||||
add("}");
|
add("}");
|
||||||
}
|
}
|
||||||
case EField(e, f, s):
|
case EField(e, f):
|
||||||
expr(e);
|
expr(e);
|
||||||
add((s == true ? "?." : ".") + f);
|
add("." + f);
|
||||||
case EBinop(op, e1, e2):
|
case EBinop(op, e1, e2):
|
||||||
expr(e1);
|
expr(e1);
|
||||||
add(" " + op + " ");
|
add(" " + op + " ");
|
||||||
@@ -226,7 +163,7 @@ class Printer {
|
|||||||
add("break");
|
add("break");
|
||||||
case EContinue:
|
case EContinue:
|
||||||
add("continue");
|
add("continue");
|
||||||
case EFunction(params, e, name, ret): // TODO: static, public, override
|
case EFunction(params, e, name, ret):
|
||||||
add("function");
|
add("function");
|
||||||
if( name != null )
|
if( name != null )
|
||||||
add(" " + name);
|
add(" " + name);
|
||||||
@@ -253,7 +190,7 @@ class Printer {
|
|||||||
add("[");
|
add("[");
|
||||||
expr(index);
|
expr(index);
|
||||||
add("]");
|
add("]");
|
||||||
case EArrayDecl(el, _):
|
case EArrayDecl(el):
|
||||||
add("[");
|
add("[");
|
||||||
var first = true;
|
var first = true;
|
||||||
for( e in el ) {
|
for( e in el ) {
|
||||||
@@ -321,26 +258,6 @@ class Printer {
|
|||||||
add(";\n");
|
add(";\n");
|
||||||
}
|
}
|
||||||
add("}");
|
add("}");
|
||||||
case EMeta(name, args, e):
|
|
||||||
add("@");
|
|
||||||
add(name);
|
|
||||||
if( args != null && args.length > 0 ) {
|
|
||||||
add("(");
|
|
||||||
var first = true;
|
|
||||||
for( a in args ) {
|
|
||||||
if( first ) first = false else add(", ");
|
|
||||||
expr(e);
|
|
||||||
}
|
|
||||||
add(")");
|
|
||||||
}
|
|
||||||
add(" ");
|
|
||||||
expr(e);
|
|
||||||
case ECheckType(e, t):
|
|
||||||
add("(");
|
|
||||||
expr(e);
|
|
||||||
add(" : ");
|
|
||||||
addType(t);
|
|
||||||
add(")");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,27 +265,4 @@ class Printer {
|
|||||||
return new Printer().exprToString(e);
|
return new Printer().exprToString(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function errorToString( e : Expr.Error ) {
|
}
|
||||||
var message = switch( #if hscriptPos e.e #else e #end ) {
|
|
||||||
case EInvalidChar(c): "Invalid character: '"+(StringTools.isEof(c) ? "EOF (End Of File)" : String.fromCharCode(c))+"' ("+c+")";
|
|
||||||
case EUnexpected(s): "Unexpected token: \""+s+"\"";
|
|
||||||
case EUnterminatedString: "Unterminated string";
|
|
||||||
case EUnterminatedComment: "Unterminated comment";
|
|
||||||
case EInvalidPreprocessor(str): "Invalid preprocessor (" + str + ")";
|
|
||||||
case EUnknownVariable(v): "Unknown variable: "+v;
|
|
||||||
case EInvalidIterator(v): "Invalid iterator: "+v;
|
|
||||||
case EInvalidOp(op): "Invalid operator: "+op;
|
|
||||||
case EInvalidAccess(f): "Invalid access to field " + f;
|
|
||||||
case ECustom(msg): msg;
|
|
||||||
case EInvalidClass(cla): "Invalid class: " + cla + " was not found.";
|
|
||||||
case EAlreadyExistingClass(cla): 'Custom Class named $cla already exists.';
|
|
||||||
};
|
|
||||||
#if hscriptPos
|
|
||||||
return e.origin + ":" + e.line + ": " + message;
|
|
||||||
#else
|
|
||||||
return message;
|
|
||||||
#end
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
+4
-50
@@ -1,34 +1,11 @@
|
|||||||
/*
|
|
||||||
* Copyright (C)2008-2017 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 hscript;
|
package hscript;
|
||||||
import hscript.Expr;
|
import hscript.Expr;
|
||||||
|
|
||||||
class Tools {
|
class Tools {
|
||||||
|
|
||||||
public static function iter( e : Expr, f : Expr -> Void ) {
|
public static function iter( e : Expr, f : Expr -> Void ) {
|
||||||
switch( expr(e) ) {
|
switch( e ) {
|
||||||
case EConst(_), EIdent(_):
|
case EConst(_), EIdent(_):
|
||||||
case EImport(c): f(e);
|
|
||||||
case EClass(_, e, _, _): for( a in e ) f(a);
|
|
||||||
case EVar(_, _, e): if( e != null ) f(e);
|
case EVar(_, _, e): if( e != null ) f(e);
|
||||||
case EParent(e): f(e);
|
case EParent(e): f(e);
|
||||||
case EBlock(el): for( e in el ) f(e);
|
case EBlock(el): for( e in el ) f(e);
|
||||||
@@ -57,15 +34,12 @@ class Tools {
|
|||||||
f(c.expr);
|
f(c.expr);
|
||||||
}
|
}
|
||||||
if( def != null ) f(def);
|
if( def != null ) f(def);
|
||||||
case EMeta(name, args, e): if( args != null ) for( a in args ) f(a); f(e);
|
|
||||||
case ECheckType(e,_): f(e);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function map( e : Expr, f : Expr -> Expr ) {
|
public static function map( e : Expr, f : Expr -> Expr ) {
|
||||||
var edef = switch( expr(e) ) {
|
return switch( e ) {
|
||||||
case EConst(_), EIdent(_), EBreak, EContinue: expr(e);
|
case EConst(_), EIdent(_): e;
|
||||||
case EVar(n, t, e): EVar(n, t, if( e != null ) f(e) else null);
|
case EVar(n, t, e): EVar(n, t, if( e != null ) f(e) else null);
|
||||||
case EParent(e): EParent(f(e));
|
case EParent(e): EParent(f(e));
|
||||||
case EBlock(el): EBlock([for( e in el ) f(e)]);
|
case EBlock(el): EBlock([for( e in el ) f(e)]);
|
||||||
@@ -77,6 +51,7 @@ class Tools {
|
|||||||
case EWhile(c, e): EWhile(f(c),f(e));
|
case EWhile(c, e): EWhile(f(c),f(e));
|
||||||
case EDoWhile(c, e): EDoWhile(f(c),f(e));
|
case EDoWhile(c, e): EDoWhile(f(c),f(e));
|
||||||
case EFor(v, it, e): EFor(v, f(it), f(e));
|
case EFor(v, it, e): EFor(v, f(it), f(e));
|
||||||
|
case EBreak, EContinue: e;
|
||||||
case EFunction(args, e, name, t): EFunction(args, f(e), name, t);
|
case EFunction(args, e, name, t): EFunction(args, f(e), name, t);
|
||||||
case EReturn(e): EReturn(if( e != null ) f(e) else null);
|
case EReturn(e): EReturn(if( e != null ) f(e) else null);
|
||||||
case EArray(e, i): EArray(f(e),f(i));
|
case EArray(e, i): EArray(f(e),f(i));
|
||||||
@@ -87,28 +62,7 @@ class Tools {
|
|||||||
case EObject(fl): EObject([for( fi in fl ) { name : fi.name, e : f(fi.e) }]);
|
case EObject(fl): EObject([for( fi in fl ) { name : fi.name, e : f(fi.e) }]);
|
||||||
case ETernary(c, e1, e2): ETernary(f(c), f(e1), f(e2));
|
case ETernary(c, e1, e2): ETernary(f(c), f(e1), f(e2));
|
||||||
case ESwitch(e, cases, def): ESwitch(f(e), [for( c in cases ) { values : [for( v in c.values ) f(v)], expr : f(c.expr) } ], def == null ? null : f(def));
|
case ESwitch(e, cases, def): ESwitch(f(e), [for( c in cases ) { values : [for( v in c.values ) f(v)], expr : f(c.expr) } ], def == null ? null : f(def));
|
||||||
case EMeta(name, args, e): EMeta(name, args == null ? null : [for( a in args ) f(a)], f(e));
|
|
||||||
case ECheckType(e,t): ECheckType(f(e), t);
|
|
||||||
case EImport(c): EImport(c);
|
|
||||||
case EClass(name, el, extend, interfaces): EClass(name, [for( e in el ) f(e)], extend, interfaces);
|
|
||||||
}
|
}
|
||||||
return mk(edef, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static inline function expr( e : Expr ) : ExprDef {
|
|
||||||
#if hscriptPos
|
|
||||||
return e.e;
|
|
||||||
#else
|
|
||||||
return e;
|
|
||||||
#end
|
|
||||||
}
|
|
||||||
|
|
||||||
public static inline function mk( e : ExprDef, p : Expr ) {
|
|
||||||
#if hscriptPos
|
|
||||||
return { e : e, pmin : p.pmin, pmax : p.pmax, origin : p.origin, line : p.line };
|
|
||||||
#else
|
|
||||||
return e;
|
|
||||||
#end
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,308 +0,0 @@
|
|||||||
package hscript;
|
|
||||||
|
|
||||||
import Type.ValueType;
|
|
||||||
import haxe.macro.ComplexTypeTools;
|
|
||||||
#if macro
|
|
||||||
import haxe.macro.Expr;
|
|
||||||
import haxe.macro.Context;
|
|
||||||
import haxe.macro.Printer;
|
|
||||||
import haxe.macro.Compiler;
|
|
||||||
|
|
||||||
using StringTools;
|
|
||||||
|
|
||||||
class UsingHandler {
|
|
||||||
public var usedClass:Class<Dynamic>;
|
|
||||||
public var className:String;
|
|
||||||
|
|
||||||
public function new(className:String, usedClass:Class<Dynamic>) {
|
|
||||||
this.className = className;
|
|
||||||
this.usedClass = usedClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function init() {
|
|
||||||
Compiler.addGlobalMetadata('flixel', '@:build(hscript.UsingHandler.build())');
|
|
||||||
Compiler.addGlobalMetadata('openfl.display.BlendMode', '@:build(hscript.UsingHandler.build())');
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function build():Array<Field> {
|
|
||||||
var fields = Context.getBuildFields();
|
|
||||||
var clRef = Context.getLocalClass();
|
|
||||||
if (clRef == null) return fields;
|
|
||||||
var cl = clRef.get();
|
|
||||||
|
|
||||||
if (/* cl.name.startsWith("Flx") && */ cl.name.endsWith("_Impl_") && cl.params.length <= 0 && !cl.meta.has(":multiType")) {
|
|
||||||
var metas = cl.meta.get();
|
|
||||||
|
|
||||||
var shadowClass = macro class {
|
|
||||||
|
|
||||||
};
|
|
||||||
shadowClass.kind = TDClass();
|
|
||||||
shadowClass.params = switch(cl.params.length) {
|
|
||||||
case 0:
|
|
||||||
null;
|
|
||||||
case 1:
|
|
||||||
[
|
|
||||||
{
|
|
||||||
name: "T",
|
|
||||||
}
|
|
||||||
];
|
|
||||||
default:
|
|
||||||
[for(k=>e in cl.params) {
|
|
||||||
name: "T" + Std.int(k+1)
|
|
||||||
}];
|
|
||||||
};
|
|
||||||
shadowClass.name = '${cl.name.substr(0, cl.name.length - 6)}_HSC';
|
|
||||||
|
|
||||||
var imports = Context.getLocalImports().copy();
|
|
||||||
setupMetas(shadowClass, imports);
|
|
||||||
|
|
||||||
for(f in fields)
|
|
||||||
switch(f.kind) {
|
|
||||||
case FFun(fun):
|
|
||||||
if (f.access.contains(AStatic)) {
|
|
||||||
if (fun.expr != null)
|
|
||||||
shadowClass.fields.push(f);
|
|
||||||
}
|
|
||||||
case FProp(get, set, t, e):
|
|
||||||
if (get == "default" && (set == "never" || set == "null"))
|
|
||||||
shadowClass.fields.push(f);
|
|
||||||
case FVar(t, e):
|
|
||||||
if (f.access.contains(AStatic) || cl.meta.has(":enum") || f.name.toUpperCase() == f.name) {
|
|
||||||
var name:String = f.name;
|
|
||||||
var enumType:String = cl.name;
|
|
||||||
var pack = cl.module.split(".");
|
|
||||||
pack.pop();
|
|
||||||
var complexType:ComplexType = t != null ? t : (name.contains("REGEX") ? TPath({
|
|
||||||
name: "EReg",
|
|
||||||
pack: []
|
|
||||||
}) : TPath({
|
|
||||||
name: cl.name.substr(0, cl.name.length - 6),
|
|
||||||
pack: pack}));
|
|
||||||
var field:Field = {
|
|
||||||
pos: f.pos,
|
|
||||||
name: f.name,
|
|
||||||
meta: f.meta,
|
|
||||||
kind: FVar(complexType, {
|
|
||||||
pos: Context.currentPos(),
|
|
||||||
expr: ECast(e, complexType)
|
|
||||||
}),
|
|
||||||
doc: f.doc,
|
|
||||||
access: [APublic, AStatic]
|
|
||||||
}
|
|
||||||
|
|
||||||
shadowClass.fields.push(field);
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
Context.defineModule(cl.module + "_HSC", [shadowClass], imports);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function fixStdTypes(type:ComplexType) {
|
|
||||||
switch(type) {
|
|
||||||
case TPath({name: "StdTypes"}):
|
|
||||||
var a:TypePath = type.getParameters()[0];
|
|
||||||
a.name = a.sub;
|
|
||||||
a.sub = null;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function setupMetas(shadowClass:TypeDefinition, imports) {
|
|
||||||
shadowClass.meta = [{
|
|
||||||
name: ':dox',
|
|
||||||
pos: Context.currentPos(),
|
|
||||||
params: [
|
|
||||||
{
|
|
||||||
expr: EConst(CIdent("hide")),
|
|
||||||
pos: Context.currentPos()
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}];
|
|
||||||
var module = Context.getModule(Context.getLocalModule());
|
|
||||||
for(t in module) {
|
|
||||||
switch(t) {
|
|
||||||
case TInst(t, params):
|
|
||||||
if (t != null) {
|
|
||||||
var e = t.get();
|
|
||||||
processModule(shadowClass, e.module, e.name);
|
|
||||||
processImport(imports, e.module, e.name);
|
|
||||||
}
|
|
||||||
case TEnum(t, params):
|
|
||||||
if (t != null) {
|
|
||||||
var e = t.get();
|
|
||||||
processModule(shadowClass, e.module, e.name);
|
|
||||||
processImport(imports, e.module, e.name);
|
|
||||||
}
|
|
||||||
case TType(t, params):
|
|
||||||
if (t != null) {
|
|
||||||
var e = t.get();
|
|
||||||
processModule(shadowClass, e.module, e.name);
|
|
||||||
processImport(imports, e.module, e.name);
|
|
||||||
}
|
|
||||||
case TAbstract(t, params):
|
|
||||||
if (t != null) {
|
|
||||||
var e = t.get();
|
|
||||||
processModule(shadowClass, e.module, e.name);
|
|
||||||
processImport(imports, e.module, e.name);
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
// not needed?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function processModule(shadowClass:TypeDefinition, module:String, n:String) {
|
|
||||||
if (n.endsWith("_Impl_"))
|
|
||||||
n = n.substr(0, n.length - 6);
|
|
||||||
if (module.endsWith("_Impl_"))
|
|
||||||
module = module.substr(0, module.length - 6);
|
|
||||||
|
|
||||||
shadowClass.meta.push(
|
|
||||||
{
|
|
||||||
name: ':access',
|
|
||||||
params: [
|
|
||||||
Context.parse(fixModuleName(module.endsWith('.${n}') ? module : '${module}.${n}'), Context.currentPos())
|
|
||||||
],
|
|
||||||
pos: Context.currentPos()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*public static function getModuleName(path:Type) {
|
|
||||||
switch(path) {
|
|
||||||
case TPath(name, pack):// | TDClass(name, pack):
|
|
||||||
var str = "";
|
|
||||||
for(p in pack) {
|
|
||||||
str += p + ".";
|
|
||||||
}
|
|
||||||
str += name;
|
|
||||||
return str;
|
|
||||||
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
return "INVALID";
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public static function fixModuleName(name:String) {
|
|
||||||
return [for(s in name.split(".")) if (s.charAt(0) == "_") s.substr(1) else s].join(".");
|
|
||||||
}
|
|
||||||
public static function processImport(imports:Array<ImportExpr>, module:String, n:String) {
|
|
||||||
if (n.endsWith("_Impl_"))
|
|
||||||
n = n.substr(0, n.length - 6);
|
|
||||||
module = fixModuleName(module);
|
|
||||||
if (module.endsWith("_Impl_"))
|
|
||||||
module = module.substr(0, module.length - 6);
|
|
||||||
|
|
||||||
imports.push({
|
|
||||||
path: [for(m in module.split(".")) {
|
|
||||||
name: m,
|
|
||||||
pos: Context.currentPos()
|
|
||||||
}],
|
|
||||||
mode: INormal
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function cleanExpr(expr:Expr, oldFunc:String, newFunc:String) {
|
|
||||||
if (expr == null) return;
|
|
||||||
if (expr.expr == null) return;
|
|
||||||
switch(expr.expr) {
|
|
||||||
case EConst(c):
|
|
||||||
switch(c) {
|
|
||||||
case CIdent(s):
|
|
||||||
if (s == oldFunc)
|
|
||||||
expr.expr = EConst(CIdent(newFunc));
|
|
||||||
case CString(s, b):
|
|
||||||
if (s == oldFunc)
|
|
||||||
expr.expr = EConst(CString(s, b));
|
|
||||||
default:
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
case EField(e, field):
|
|
||||||
if (field == oldFunc && e != null) {
|
|
||||||
switch(e.expr) {
|
|
||||||
case EConst(c):
|
|
||||||
switch(c) {
|
|
||||||
case CIdent(s):
|
|
||||||
if (s == "super")
|
|
||||||
expr.expr = EField(e, newFunc);
|
|
||||||
default:
|
|
||||||
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case EParenthesis(e):
|
|
||||||
cleanExpr(e, oldFunc, newFunc);
|
|
||||||
case EObjectDecl(fields):
|
|
||||||
for(f in fields) {
|
|
||||||
cleanExpr(f.expr, oldFunc, newFunc);
|
|
||||||
}
|
|
||||||
case EArrayDecl(values):
|
|
||||||
for(a in values) {
|
|
||||||
cleanExpr(a, oldFunc, newFunc);
|
|
||||||
}
|
|
||||||
case ECall(e, params):
|
|
||||||
cleanExpr(e, oldFunc, newFunc);
|
|
||||||
case EBlock(exprs):
|
|
||||||
for(e in exprs)
|
|
||||||
cleanExpr(e, oldFunc, newFunc);
|
|
||||||
case EFor(it, expr):
|
|
||||||
cleanExpr(it, oldFunc, newFunc);
|
|
||||||
cleanExpr(expr, oldFunc, newFunc);
|
|
||||||
case EIf(econd, eif, eelse):
|
|
||||||
cleanExpr(econd, oldFunc, newFunc);
|
|
||||||
cleanExpr(eif, oldFunc, newFunc);
|
|
||||||
cleanExpr(eelse, oldFunc, newFunc);
|
|
||||||
case EWhile(econd, e, normalWhile):
|
|
||||||
cleanExpr(econd, oldFunc, newFunc);
|
|
||||||
cleanExpr(e, oldFunc, newFunc);
|
|
||||||
case ECast(e, t):
|
|
||||||
cleanExpr(e, oldFunc, newFunc);
|
|
||||||
case ECheckType(e, t):
|
|
||||||
cleanExpr(e, oldFunc, newFunc);
|
|
||||||
case ETry(e, catches):
|
|
||||||
cleanExpr(e, oldFunc, newFunc);
|
|
||||||
for(c in catches) {
|
|
||||||
cleanExpr(c.expr, oldFunc, newFunc);
|
|
||||||
}
|
|
||||||
case EThrow(e):
|
|
||||||
cleanExpr(e, oldFunc, newFunc);
|
|
||||||
case ETernary(econd, eif, eelse):
|
|
||||||
cleanExpr(econd, oldFunc, newFunc);
|
|
||||||
cleanExpr(eif, oldFunc, newFunc);
|
|
||||||
cleanExpr(eelse, oldFunc, newFunc);
|
|
||||||
case ESwitch(e, cases, edef):
|
|
||||||
cleanExpr(e, oldFunc, newFunc);
|
|
||||||
for(c in cases) {
|
|
||||||
cleanExpr(c.expr, oldFunc, newFunc);
|
|
||||||
}
|
|
||||||
cleanExpr(edef, oldFunc, newFunc);
|
|
||||||
case EReturn(e):
|
|
||||||
cleanExpr(e, oldFunc, newFunc);
|
|
||||||
case EIs(e, t):
|
|
||||||
cleanExpr(e, oldFunc, newFunc);
|
|
||||||
case EVars(vars):
|
|
||||||
for(v in vars) {
|
|
||||||
cleanExpr(v.expr, oldFunc, newFunc);
|
|
||||||
}
|
|
||||||
case ENew(t, params):
|
|
||||||
for(p in params) {
|
|
||||||
cleanExpr(p, oldFunc, newFunc);
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
class UsingHandler {
|
|
||||||
public var usedClass:Class<Dynamic>;
|
|
||||||
public var className:String;
|
|
||||||
}
|
|
||||||
#end
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
@echo off
|
@echo off
|
||||||
set PATH="C:\Program Files\7-Zip";%PATH%
|
|
||||||
rm -rf release
|
rm -rf release
|
||||||
mkdir release
|
mkdir release
|
||||||
cp haxelib.json README.md extraParams.hxml release
|
cp haxelib.json README.md extraParams.hxml release
|
||||||
|
|||||||
Reference in New Issue
Block a user