Compare commits
No commits in common. "master" and "v1.0.1" have entirely different histories.
|
@ -1,29 +0,0 @@
|
||||||
|
|
||||||
name: Publish PHP Package
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
docker:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Get tag name
|
|
||||||
run: echo "TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: zip and send
|
|
||||||
run: |
|
|
||||||
ls -la
|
|
||||||
apt-get update -y
|
|
||||||
apt-get install -y zip
|
|
||||||
cd ../
|
|
||||||
zip -r ${{ gitea.event.repository.name }}.zip ${{ gitea.event.repository.name }} -x '*.git*'
|
|
||||||
curl -v \
|
|
||||||
--user composer-pbl:${{ secrets.COMPOSER_PSWD }} \
|
|
||||||
--upload-file ${{ gitea.event.repository.name }}.zip \
|
|
||||||
https://git.bit5.ru/api/packages/bit/composer?version=${{ env.TAG }}
|
|
|
@ -1 +0,0 @@
|
||||||
tags
|
|
582
bhl.inc.php
582
bhl.inc.php
|
@ -12,354 +12,414 @@ task('bhl_clean_cache', function()
|
||||||
bhl_clean_cache();
|
bhl_clean_cache();
|
||||||
});
|
});
|
||||||
|
|
||||||
class BhlProj
|
function bhl_build_dll()
|
||||||
{
|
{
|
||||||
public static ?BhlProj $active = null;
|
global $GAME_ROOT;
|
||||||
|
|
||||||
public string $file_path;
|
$mcs_bin = mono_mcs_bin();
|
||||||
public array $inc_dirs = array();
|
$dll_file = "$GAME_ROOT/unity/Assets/Plugins/game_bhl.dll";
|
||||||
public array $src_dirs = array();
|
|
||||||
public array $defines = array();
|
|
||||||
public array $bindings_sources;
|
|
||||||
public array $postproc_sources;
|
|
||||||
public string $postproc_dll;
|
|
||||||
public string $bindings_dll;
|
|
||||||
public string $result_file;
|
|
||||||
public string $error_file;
|
|
||||||
public string $tmp_dir;
|
|
||||||
public int $max_threads;
|
|
||||||
public bool $deterministic;
|
|
||||||
|
|
||||||
function getIncPath() : array
|
bhl_shell_ensure("build_back_dll $mcs_bin $dll_file " . (is_dev() ? '-debug' : ''));
|
||||||
{
|
|
||||||
if($this->inc_dirs)
|
return $dll_file;
|
||||||
return $this->inc_dirs;
|
|
||||||
return $this->src_dirs;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function bhl_proj_file() : string
|
task('bhl_try', function($args = [])
|
||||||
{
|
{
|
||||||
return get('BHL_PROJ_FILE');
|
global $GAME_ROOT;
|
||||||
|
|
||||||
|
$all_files = array($args[0]);
|
||||||
|
|
||||||
|
$bhl_inc_dir = config_base_dir();
|
||||||
|
$res_file = "$GAME_ROOT/build/bhl.try";
|
||||||
|
|
||||||
|
bhl_run_ex(
|
||||||
|
$bhl_inc_dir,
|
||||||
|
$all_files,
|
||||||
|
$res_file,
|
||||||
|
false/*not debug*/,
|
||||||
|
true/*force*/
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
task('bhl_callstack', ['alias' => 'bhc'], function(array $args)
|
||||||
|
{
|
||||||
|
global $GAME_ROOT;
|
||||||
|
|
||||||
|
if(count($args) < 1)
|
||||||
|
{
|
||||||
|
echo "Usage: ./gamectl bhl_callstack \"<callstack>\"";
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function bhl_proj_load(string $proj_file) : BhlProj
|
$items = explode("\n", $args[0]);
|
||||||
|
|
||||||
|
foreach($items as $item)
|
||||||
{
|
{
|
||||||
$arr = json_decode(ensure_read($proj_file), true);
|
$item = trim($item);
|
||||||
if(!$arr)
|
if(!$item)
|
||||||
throw new Exception("Bad bhl project file: $proj_file");
|
continue;
|
||||||
|
|
||||||
$proj = new BhlProj();
|
if(preg_match('~(\d+)\s+\(\)\s+\(at (\d+):(\d+)\)~', $item, $m))
|
||||||
foreach($arr as $k => $v)
|
|
||||||
$proj->{$k} = $v;
|
|
||||||
|
|
||||||
//NOTE: adding path to the file for further convenience
|
|
||||||
$proj->file_path = $proj_file;
|
|
||||||
|
|
||||||
foreach($proj->inc_dirs as $k => $v)
|
|
||||||
$proj->inc_dirs[$k] = _bhl_make_abs_path($proj_file, $v);
|
|
||||||
|
|
||||||
foreach($proj->src_dirs as $k => $v)
|
|
||||||
$proj->src_dirs[$k] = _bhl_make_abs_path($proj_file, $v);
|
|
||||||
|
|
||||||
foreach($proj->bindings_sources as $k => $v)
|
|
||||||
$proj->bindings_sources[$k] = _bhl_make_abs_path($proj_file, $v);
|
|
||||||
$proj->bindings_dll = _bhl_make_abs_path($proj_file, $proj->bindings_dll);
|
|
||||||
|
|
||||||
if(isset($proj->postproc_sources))
|
|
||||||
{
|
{
|
||||||
foreach($proj->postproc_sources as $k => $v)
|
$func_hash = (int)$m[1];
|
||||||
$proj->postproc_sources[$k] = _bhl_make_abs_path($proj_file, $v);
|
$file_hash = (int)$m[2];
|
||||||
}
|
$line_num = (int)$m[3];
|
||||||
|
|
||||||
if(isset($proj->postproc_dll))
|
$func_name = key(bhl_find_name_hash($func_hash));
|
||||||
$proj->postproc_dll = _bhl_make_abs_path($proj_file, $proj->postproc_dll);
|
|
||||||
|
|
||||||
$proj->result_file = _bhl_make_abs_path($proj_file, $proj->result_file);
|
$file_name = bhl_find_module($file_hash);
|
||||||
$proj->error_file = _bhl_make_abs_path($proj_file, $proj->error_file);
|
if(!$file_name)
|
||||||
$proj->tmp_dir = _bhl_make_abs_path($proj_file, $proj->tmp_dir);
|
$file_name = "?";
|
||||||
|
|
||||||
return $proj;
|
|
||||||
}
|
|
||||||
|
|
||||||
function bhl_proj_set_active(BhlProj $proj) : ?BhlProj
|
|
||||||
{
|
|
||||||
$prev = BhlProj::$active;
|
|
||||||
BhlProj::$active = $proj;
|
|
||||||
return $prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
function bhl_proj() : BhlProj
|
|
||||||
{
|
|
||||||
if(BhlProj::$active == null)
|
|
||||||
{
|
|
||||||
$proj = bhl_proj_load(bhl_proj_file());
|
|
||||||
BhlProj::$active = $proj;
|
|
||||||
}
|
|
||||||
return BhlProj::$active;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _bhl_make_abs_path(string $proj_file, string $path) : string
|
|
||||||
{
|
|
||||||
if($path && $path[0] == '.')
|
|
||||||
return dirname($proj_file) . '/' . $path;
|
|
||||||
else
|
else
|
||||||
return $path;
|
$file_name = normalize_path($file_name, true);
|
||||||
}
|
|
||||||
|
|
||||||
function bhl_result_file() : string
|
echo ($func_name ? $func_name : $func_hash) . "() in $file_name@$line_num \n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
task('bhl_callstack_file', function(array $args)
|
||||||
{
|
{
|
||||||
return bhl_proj()->result_file;
|
global $GAME_ROOT;
|
||||||
|
|
||||||
|
if(count($args) < 1)
|
||||||
|
{
|
||||||
|
echo "Usage: ./gamectl bhl_callstack_file \"<path_to_callstack_file>\"";
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function bhl_dir() : string
|
$callstack = ensure_read($args[0]);
|
||||||
|
run('bhl_callstack', [$callstack]);
|
||||||
|
});
|
||||||
|
|
||||||
|
function bhl_find_name_hash($hash)
|
||||||
|
{
|
||||||
|
global $GAME_ROOT;
|
||||||
|
|
||||||
|
$result = array();
|
||||||
|
|
||||||
|
$files = scan_files_rec(array(config_base_dir()), array('bhl'));
|
||||||
|
foreach($files as $file)
|
||||||
|
{
|
||||||
|
$cont = file_get_contents($file);
|
||||||
|
if(preg_match_all('/(\w+)/', $cont, $ms))
|
||||||
|
{
|
||||||
|
foreach($ms[1] as $name)
|
||||||
|
{
|
||||||
|
$name = trim($name, '"');
|
||||||
|
$var_hash = crc32($name) & 0xFFFFFFF;
|
||||||
|
if($var_hash === $hash)
|
||||||
|
{
|
||||||
|
if(!isset($result[$name]))
|
||||||
|
$result[$name] = array();
|
||||||
|
$result[$name][$file] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
task('bhl_find_module', function(array $args)
|
||||||
|
{
|
||||||
|
if(count($args) < 1)
|
||||||
|
{
|
||||||
|
echo "Usage: ./gamectl bhl_find_module <mod_id>";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mod_id = (int)$args[0];
|
||||||
|
$bhl_file = bhl_find_module($mod_id);
|
||||||
|
if($bhl_file)
|
||||||
|
echo "Found '$bhl_file'\n";
|
||||||
|
});
|
||||||
|
|
||||||
|
function bhl_find_module($mod_id)
|
||||||
|
{
|
||||||
|
global $GAME_ROOT;
|
||||||
|
|
||||||
|
$files = scan_files_rec(array(config_base_dir()), array('.bhl'));
|
||||||
|
|
||||||
|
$conf_dir = normalize_path(config_base_dir(), true);
|
||||||
|
|
||||||
|
foreach($files as $bhl_file)
|
||||||
|
{
|
||||||
|
$module_path = str_replace($conf_dir, '', $bhl_file);
|
||||||
|
$module_path = ltrim(substr($module_path, 0, strlen($module_path)-4), '/');
|
||||||
|
if(crc32($module_path) === $mod_id)
|
||||||
|
return $bhl_file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function bhl_result_file()
|
||||||
|
{
|
||||||
|
global $GAME_ROOT;
|
||||||
|
return "$GAME_ROOT/build/ext_config/bhl.bytes";
|
||||||
|
}
|
||||||
|
|
||||||
|
function bhl_dir()
|
||||||
{
|
{
|
||||||
global $GAME_ROOT;
|
global $GAME_ROOT;
|
||||||
return "$GAME_ROOT/composer/vendor/bit/bhl";
|
return "$GAME_ROOT/composer/vendor/bit/bhl";
|
||||||
}
|
}
|
||||||
|
|
||||||
function bhl_shell(string $cmd, &$ret_var, &$ret_out)
|
function bhl_shell($cmd, &$ret_var, &$ret_out)
|
||||||
|
{
|
||||||
|
$prev_path = mono_try_override_path();
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
shell_try(bhl_dir()."/bhl $cmd", $ret_var, $ret_out);
|
shell_try(bhl_dir()."/bhl $cmd", $ret_var, $ret_out);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
mono_try_restore_path($prev_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function bhl_shell_ensure(string $cmd)
|
function bhl_shell_ensure($cmd)
|
||||||
{
|
{
|
||||||
bhl_shell($cmd, $ret_var, $ret_out);
|
bhl_shell($cmd, $ret_var, $ret_out);
|
||||||
if($ret_var !== 0)
|
if($ret_var !== 0)
|
||||||
throw new Exception("Error executing shell cmd: $ret_var");
|
throw new Exception("Error executing shell cmd: $ret_var");
|
||||||
}
|
}
|
||||||
|
|
||||||
function bhl_scan_files() : array
|
function bhl_run($debug = true, $force = false, $check_deps = true, $exit_on_err = true)
|
||||||
{
|
|
||||||
return scan_files_rec(bhl_proj()->src_dirs, array('.bhl'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function bhl_run(bool $debug = true, bool $force = false, bool $exit_on_err = true)
|
|
||||||
{
|
{
|
||||||
global $GAME_ROOT;
|
global $GAME_ROOT;
|
||||||
|
|
||||||
$bhl_proj = bhl_proj();
|
$bhl_inc_dir = config_base_dir();
|
||||||
$result_file = $bhl_proj->result_file;
|
|
||||||
|
|
||||||
if($force || need_to_regen($result_file, bhl_scan_files()))
|
$all_files = scan_files_rec(array(config_base_dir()), array('.bhl'));
|
||||||
|
$res_file = bhl_result_file();
|
||||||
|
|
||||||
|
_bhl_shuffle_files($all_files);
|
||||||
|
|
||||||
|
$res_file = bhl_result_file();
|
||||||
|
$res = bhl_run_ex($bhl_inc_dir, $all_files, $res_file, $debug, $force, $check_deps, $exit_on_err);
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _bhl_shuffle_files(&$files)
|
||||||
{
|
{
|
||||||
bhl_shell("compile -p " . $bhl_proj->file_path . " " .
|
shuffle($files);
|
||||||
|
}
|
||||||
|
|
||||||
|
function bhl_run_ex($bhl_inc_dir, array $bhl_files, $result_file, $debug = true, $force = false, $check_deps = true, $exit_on_err = true)
|
||||||
|
{
|
||||||
|
global $GAME_ROOT;
|
||||||
|
|
||||||
|
ensure_mkdir("$GAME_ROOT/build");
|
||||||
|
|
||||||
|
$post_proc_file = "$GAME_ROOT/build/bhl.post.".crc32($result_file);
|
||||||
|
$err_file = "$GAME_ROOT/build/bhl.error";
|
||||||
|
ensure_rm($err_file);
|
||||||
|
|
||||||
|
$user_sources = array(
|
||||||
|
"$GAME_ROOT/unity/Assets/Scripts/bhl/register.cs",
|
||||||
|
"$GAME_ROOT/dll_src/bhl/autobind.cs",
|
||||||
|
"$GAME_ROOT/unity/Assets/Scripts/bhl/autobind.cs"
|
||||||
|
);
|
||||||
|
|
||||||
|
$postproc_sources = array(
|
||||||
|
"$GAME_ROOT/dll_src/bhl/postproc.cs",
|
||||||
|
"$GAME_ROOT/dll_src/bhl/result.cs"
|
||||||
|
);
|
||||||
|
|
||||||
|
$bhl_deps = $bhl_files;
|
||||||
|
$bhl_deps = array_merge($bhl_deps, $user_sources);
|
||||||
|
$bhl_deps = array_merge($bhl_deps, $postproc_sources);
|
||||||
|
$bhl_deps = array_merge($bhl_deps, scan_files_rec(array(bhl_dir()), array(".cs")));
|
||||||
|
|
||||||
|
if($force || need_to_regen($result_file, $bhl_deps) || need_to_regen($post_proc_file, $bhl_deps))
|
||||||
|
{
|
||||||
|
$bhl_file_list = "$GAME_ROOT/build/bhl/file_list.tmp";
|
||||||
|
ensure_write($bhl_file_list, implode("\n", $bhl_files));
|
||||||
|
|
||||||
|
putenv("POSTPROC_PROJ_ROOT=$GAME_ROOT");
|
||||||
|
putenv("POSTPROC_RESULT=$post_proc_file");
|
||||||
|
if($force)
|
||||||
|
putenv("POSTPROC_FORCE=1");
|
||||||
|
|
||||||
|
$bhl_dir = bhl_dir();
|
||||||
|
|
||||||
|
bhl_shell("run " .
|
||||||
|
"--user-sources=".implode(",",$user_sources)." --postproc-sources=".implode(",",$postproc_sources)." " .
|
||||||
|
"--dir=$bhl_inc_dir --files=$bhl_file_list --result=$result_file " .
|
||||||
|
"--cache_dir=$GAME_ROOT/build/bhl/ " .
|
||||||
|
"--error=$GAME_ROOT/build/bhl.error " .
|
||||||
|
"--deterministic " .
|
||||||
|
"--threads=" . (is_win() ? 1 : 4) . " " .
|
||||||
($debug ? " -d" : "") . " " .
|
($debug ? " -d" : "") . " " .
|
||||||
($force || !getor("BHL_USE_CACHE", true) ? " -C" : ""),
|
($force ? " -C" : "") . " ".
|
||||||
|
(!$check_deps ? " -N" : "") . " ",
|
||||||
$ret_var, $ret_out
|
$ret_var, $ret_out
|
||||||
);
|
);
|
||||||
|
|
||||||
if($ret_var != 0)
|
if($ret_var != 0)
|
||||||
{
|
{
|
||||||
bhl_handle_error_result($ret_out, $bhl_proj->error_file, $exit_on_err);
|
bhl_handle_error_result($ret_out, $err_file, $exit_on_err);
|
||||||
if(!$exit_on_err)
|
if(!$exit_on_err)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if($debug)
|
else
|
||||||
echo "BHL BUNDLE: total " . kb_len(filesize($result_file)) . ", CRC " . hexdec(hash_file('CRC32', $result_file, false)) . "\n";
|
echo "BHL BUNDLE: total " . kb_len(filesize($result_file)) . "\n";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function bhl_handle_error_result(array $ret_out, string $err_file, bool $exit = true)
|
@touch($result_file);
|
||||||
|
@touch($post_proc_file);
|
||||||
|
$res = bhl_ast_post_proc($result_file, $post_proc_file);
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bhl_handle_error_result(array $ret_out, $err_file, $exit = true)
|
||||||
{
|
{
|
||||||
if(!is_file($err_file))
|
if(!is_file($err_file))
|
||||||
{
|
{
|
||||||
stderr("Something went wrong: " . implode("\n", $ret_out));
|
stderr("Something went wrong: " . (is_array($ret_out) ? implode("\n", $ret_out) : "????"));
|
||||||
if($exit)
|
if($exit)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$history = array();
|
$err = file_get_contents($err_file);
|
||||||
$err_lines = file($err_file);
|
|
||||||
$err_count = 0;
|
|
||||||
foreach($err_lines as $err)
|
|
||||||
{
|
|
||||||
$jerr = json_decode($err);
|
$jerr = json_decode($err);
|
||||||
if(!$jerr)
|
if(!$jerr)
|
||||||
{
|
{
|
||||||
stderr("Something went wrong, bhl error is in invalid format: $err\n");
|
stderr("Something went wrong, bhl error is in invalid format: $err");
|
||||||
continue;
|
if($exit)
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
$file = $jerr->file;
|
||||||
|
|
||||||
|
$err_line = null;
|
||||||
|
$err_row = null;
|
||||||
|
if(preg_match('~@\((\d+),(\d+)\)~', $jerr->error, $merr))
|
||||||
|
{
|
||||||
|
$err_line = (int)$merr[1];
|
||||||
|
$err_row = (int)$merr[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = $jerr->file;
|
stderr("BHL ERROR: \n" .
|
||||||
//let's show only one error per file's line
|
$jerr->error .
|
||||||
if(isset($history[$file.$jerr->line]))
|
//substr($jerr->error, 0, 500) .
|
||||||
continue;
|
" \nin '$file'\n");
|
||||||
$history[$file.$jerr->line] = true;
|
if($err_line !== null && $err_row !== null)
|
||||||
++$err_count;
|
stderr(bhl_show_position($err_line, $err_row, file($file)) . "\n");
|
||||||
stderr("BHL ERROR (#$err_count): " . $jerr->error . " \nin '$file', line {$jerr->line}\n");
|
if($exit)
|
||||||
if(file_exists($file))
|
|
||||||
stderr(bhl_show_position($jerr->line, $jerr->column, file($file)) . "\n");
|
|
||||||
}
|
|
||||||
if($err_lines && $exit)
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BhlAstProcResult
|
||||||
|
{
|
||||||
|
var $res_file;
|
||||||
|
var $func2assets_deep = array();
|
||||||
|
var $func2refs_deep = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
function bhl_ast_post_proc($res_file, $post_proc_file)
|
||||||
|
{
|
||||||
|
$res = new BhlAstProcResult();
|
||||||
|
$res->res_file = $res_file;
|
||||||
|
$data = config_msgpack_unpack(ensure_read($post_proc_file));
|
||||||
|
if(!$data)
|
||||||
|
return $res;
|
||||||
|
|
||||||
|
$func2assets = $data[0];
|
||||||
|
foreach($func2assets as $item)
|
||||||
|
{
|
||||||
|
list($func1, $func2, $assets) = $item;
|
||||||
|
$func = ($func2 << 31) | $func1;
|
||||||
|
$res->func2assets_deep[$func] = array_flip($assets);
|
||||||
|
}
|
||||||
|
|
||||||
|
$func2crefs = $data[1];
|
||||||
|
foreach($func2crefs as $item)
|
||||||
|
{
|
||||||
|
list($func1, $func2, $crefs) = $item;
|
||||||
|
$func = ($func2 << 31) | $func1;
|
||||||
|
$res->func2refs_deep[$func] = array_flip($crefs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
function bhl_clean()
|
function bhl_clean()
|
||||||
{
|
{
|
||||||
|
global $GAME_ROOT;
|
||||||
|
|
||||||
|
$files = scan_files_rec(array(config_base_dir()), array('js', 'gen.bhl'));
|
||||||
|
foreach($files as $file)
|
||||||
|
{
|
||||||
|
$is_conf = strpos($file, '.gen.bhl') === false;
|
||||||
|
|
||||||
|
if($is_conf)
|
||||||
|
{
|
||||||
|
//skipping .def.js files
|
||||||
|
if(strpos($file, '.def.js') !== false)
|
||||||
|
continue;
|
||||||
|
@touch($file);
|
||||||
|
}
|
||||||
|
else if(!$is_conf)
|
||||||
|
{
|
||||||
|
ensure_rm($file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bhl_clean_cache();
|
bhl_clean_cache();
|
||||||
bhl_shell("clean", $ret, $out);
|
|
||||||
|
bhl_shell_ensure("clean");
|
||||||
}
|
}
|
||||||
|
|
||||||
function bhl_clean_cache()
|
function bhl_clean_cache()
|
||||||
{
|
{
|
||||||
ensure_rm(bhl_proj()->tmp_dir);
|
global $GAME_ROOT;
|
||||||
|
ensure_rm("$GAME_ROOT/build/bhl/");
|
||||||
}
|
}
|
||||||
|
|
||||||
function bhl_show_position(int $line, int $row, array $lines) : string
|
function bhl_show_position($line, $row, array $lines)
|
||||||
{
|
{
|
||||||
if($line > 0 && $line <= count($lines))
|
if($line < count($lines))
|
||||||
{
|
{
|
||||||
//handling tabs
|
$txt = $lines[$line-1];
|
||||||
$hint = str_replace("\t", " ", $lines[$line-1]);
|
$c = str_repeat('-', $row);
|
||||||
for($c=0;$c<$row;++$c)
|
return "{$txt}{$c}^";
|
||||||
{
|
|
||||||
if($lines[$line-1][$c] === "\t")
|
|
||||||
$hint .= "----";
|
|
||||||
else
|
|
||||||
$hint .= "-";
|
|
||||||
}
|
}
|
||||||
$hint .= "^";
|
//weird special case
|
||||||
return $hint;
|
else if($line-1 == count($lines))
|
||||||
|
{
|
||||||
|
$txt = $lines[count($lines)-1];
|
||||||
|
$c = str_repeat('-', $row);
|
||||||
|
return "{$txt}{$c}^";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return "??? @($line:$row)";
|
return "???";
|
||||||
}
|
}
|
||||||
|
|
||||||
function bhl_line_row_to_pos(string $file, int $line, int $row) : ?int
|
function bhl_get_past_input($c, $in, $context_chars)
|
||||||
|
{
|
||||||
|
$past = substr($in, 0, $c+1);
|
||||||
|
return (strlen($past) > $context_chars ? '...' : '') . substr($past, -$context_chars);
|
||||||
|
}
|
||||||
|
|
||||||
|
function bhl_get_upcoming_input($c, $in, $context_chars)
|
||||||
|
{
|
||||||
|
$next = substr($in, $c+1);
|
||||||
|
return substr($next, 0, $context_chars) . (strlen($next) > $context_chars ? '...' : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
function bhl_line_row_to_pos($file, $line, $row)
|
||||||
{
|
{
|
||||||
$pos = 0;
|
$pos = 0;
|
||||||
$lines = file($file);
|
$lines = file($file);
|
||||||
//something went wrong
|
//something went wrong
|
||||||
if($line <= 0 || $line > count($lines))
|
if(count($lines) < $line)
|
||||||
return null;
|
return null;
|
||||||
for($i=0;$i<($line-1);++$i)
|
for($i=0;$i<($line-1);++$i)
|
||||||
$pos += strlen($lines[$i]);
|
$pos += strlen($lines[$i]);
|
||||||
$pos += $row;
|
$pos += $row;
|
||||||
return $pos;
|
return $pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
function bhl_map_module_to_file(string $module) : ?string
|
|
||||||
{
|
|
||||||
$bhl_proj = bhl_proj();
|
|
||||||
foreach($bhl_proj->getIncPath() as $dir)
|
|
||||||
{
|
|
||||||
$tmp = $dir.'/'.$module.'.bhl';
|
|
||||||
if(file_exists($tmp))
|
|
||||||
return $tmp;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function bhl_validate_func_ref(string $module_file, string $func_full_name, array $signature)
|
|
||||||
{
|
|
||||||
if(sizeof($signature) == 0)
|
|
||||||
throw new Exception("Signature is invalid");
|
|
||||||
|
|
||||||
$name_items = explode('.', $func_full_name);
|
|
||||||
$func = array_pop($name_items);
|
|
||||||
$namespace = implode('.', $name_items);
|
|
||||||
|
|
||||||
$module_src = file_get_contents($module_file);
|
|
||||||
$module_src = _bhl_remove_comments($module_src);
|
|
||||||
|
|
||||||
if(!$module_src)
|
|
||||||
throw new Exception("Bad module file '{$module_file}'");
|
|
||||||
|
|
||||||
$ns_chunks = _bhl_split_by_namespaces($module_src);
|
|
||||||
|
|
||||||
$module_chunks = array();
|
|
||||||
if($namespace)
|
|
||||||
{
|
|
||||||
if(!isset($ns_chunks[$namespace]))
|
|
||||||
throw new Exception("No namespace '$namespace' found in '$module_file'");
|
|
||||||
|
|
||||||
foreach($ns_chunks[$namespace] as $ns_src)
|
|
||||||
$module_chunks[] = $ns_src;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(!isset($ns_chunks['']))
|
|
||||||
throw new Exception("No global namespace found in '$module_file'");
|
|
||||||
|
|
||||||
foreach($ns_chunks[''] as $ns_src)
|
|
||||||
$module_chunks[] = $ns_src;
|
|
||||||
}
|
|
||||||
|
|
||||||
$signature_pattern = '';
|
|
||||||
$signature_pattern .= '~func\s+';
|
|
||||||
if($signature[0] !== 'void')
|
|
||||||
{
|
|
||||||
$signature_pattern .= preg_quote($signature[0]);
|
|
||||||
$signature_pattern .= '\s+';
|
|
||||||
}
|
|
||||||
$signature_pattern .= $func;
|
|
||||||
$signature_pattern .= '\s*\(';
|
|
||||||
array_shift($signature);
|
|
||||||
foreach($signature as $type)
|
|
||||||
{
|
|
||||||
$signature_pattern .= '\s*';
|
|
||||||
$signature_pattern .= preg_quote($type);
|
|
||||||
$signature_pattern .= '\s*\S+';
|
|
||||||
$signature_pattern .= '\s*,';
|
|
||||||
}
|
|
||||||
$signature_pattern = rtrim($signature_pattern, '\s*,');
|
|
||||||
$signature_pattern .= '\s*\)';
|
|
||||||
$signature_pattern .= '~';
|
|
||||||
|
|
||||||
foreach($module_chunks as $module_chunk_src)
|
|
||||||
{
|
|
||||||
if(preg_match($signature_pattern, $module_chunk_src))
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Exception("Func '$func_full_name(".implode(',', $signature).")' not found in '$module_file'");
|
|
||||||
}
|
|
||||||
|
|
||||||
function _bhl_remove_comments(string $txt) : string
|
|
||||||
{
|
|
||||||
//block comments
|
|
||||||
if(strpos($txt, '/*') !== false)
|
|
||||||
{
|
|
||||||
$regex = '~/\*.*?\*/~s';
|
|
||||||
$txt = preg_replace_callback(
|
|
||||||
$regex,
|
|
||||||
//preserve the new lines for better error reporting
|
|
||||||
function($m) { return str_repeat("\n", substr_count($m[0], "\n")); },
|
|
||||||
$txt);
|
|
||||||
}
|
|
||||||
//line comments
|
|
||||||
$txt = preg_replace("~\s*(?<!:)//.*~", "\n", $txt);
|
|
||||||
return $txt;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _bhl_split_by_namespaces(string $src) : array
|
|
||||||
{
|
|
||||||
$nss = array();
|
|
||||||
|
|
||||||
$chunks = preg_split('~^\s*(namespace\s+[^\{]+){~m', $src, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
|
||||||
|
|
||||||
for($i=0;$i<count($chunks);)
|
|
||||||
{
|
|
||||||
$chunk = $chunks[$i];
|
|
||||||
if(strpos(ltrim($chunk), 'namespace ') === 0)
|
|
||||||
{
|
|
||||||
$ns = trim(substr(ltrim($chunk), 9));
|
|
||||||
$body = $chunks[$i+1];
|
|
||||||
if(!isset($nss[$ns]))
|
|
||||||
$nss[$ns] = array();
|
|
||||||
$nss[$ns][] = $body;
|
|
||||||
$i+=2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(!isset($nss['']))
|
|
||||||
$nss[''] = array();
|
|
||||||
$nss[''][] = $chunk;
|
|
||||||
++$i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $nss;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace metagen_php;
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
function flt_bhl_ref($val, $name, $data, $str_args)
|
|
||||||
{
|
|
||||||
if(!$val)
|
|
||||||
return $val;
|
|
||||||
|
|
||||||
if(!isset($val['module']))
|
|
||||||
throw new Exception("Missing 'module'");
|
|
||||||
|
|
||||||
$module_file = \taskman\bhl_map_module_to_file($val['module']);
|
|
||||||
if(!$module_file)
|
|
||||||
throw new Exception("Module not found '{$val['module']}");
|
|
||||||
|
|
||||||
if(!isset($val['fn']))
|
|
||||||
throw new Exception("Missing 'fn'");
|
|
||||||
|
|
||||||
$args = explode(",", $str_args);
|
|
||||||
|
|
||||||
\taskman\bhl_validate_func_ref($module_file, $val['fn'], $args);
|
|
||||||
|
|
||||||
return $val;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @global
|
|
||||||
*/
|
|
||||||
function macro_BHL_REF($proc, $module, $func, $signature_json = '')
|
|
||||||
{
|
|
||||||
//check if it's a relative path
|
|
||||||
if($module[0] == '.')
|
|
||||||
{
|
|
||||||
$abs_module = \taskman\normalize_path(dirname($proc->getRootFile()) . '/' . $module);
|
|
||||||
$mapped = false;
|
|
||||||
|
|
||||||
$bhl_proj = \taskman\bhl_proj();
|
|
||||||
$inc_path = $bhl_proj->getIncPath();
|
|
||||||
|
|
||||||
foreach($inc_path as $dir)
|
|
||||||
{
|
|
||||||
$rel_module = str_replace(\taskman\normalize_path($dir), '', $abs_module);
|
|
||||||
if($rel_module != $abs_module)
|
|
||||||
{
|
|
||||||
$mapped = true;
|
|
||||||
$rel_module = str_replace('\\', '/', $rel_module);
|
|
||||||
$module = "/" . $rel_module;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!$mapped)
|
|
||||||
throw new Exception("Could not map relative module: $module");
|
|
||||||
}
|
|
||||||
|
|
||||||
$module_file = \taskman\bhl_map_module_to_file($module);
|
|
||||||
if(!$module_file)
|
|
||||||
throw new Exception("Module not found '{$module}'");
|
|
||||||
|
|
||||||
//validate signature only if it's explicitely passed
|
|
||||||
if($signature_json)
|
|
||||||
{
|
|
||||||
$signature = json_decode($signature_json, false);
|
|
||||||
if(!is_array($signature))
|
|
||||||
throw new Exception("Signature is invalid '$module'");
|
|
||||||
\taskman\bhl_validate_func_ref($module_file, $func, $signature);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array('module' => ltrim($module, '/'), 'fn' => $func);
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,5 +4,8 @@
|
||||||
"homepage": "https://git.bit5.ru/composer/taskman_bhl",
|
"homepage": "https://git.bit5.ru/composer/taskman_bhl",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.4"
|
"php": ">=7.4"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"classmap": ["bhl.inc.php"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue