Boot.hx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. package php;
  2. class Boot {
  3. static var qtypes;
  4. static var ttypes;
  5. static var tpaths;
  6. static var skip_constructor = false;
  7. static function __init__() : Void {
  8. untyped __php__("
  9. function _hx_anonymous($p = array()) {
  10. $o = new _hx_anonymous();
  11. foreach($p as $k => $v)
  12. $o->$k = $v;
  13. return $o;
  14. }
  15. function _hx_array() {
  16. return func_get_args();
  17. }
  18. function _hx_array_call(&$arr, $method, $params) {
  19. if(!is_array($arr)) return call_user_func_array(array($arr, $method), $params);
  20. switch($method) {
  21. case 'concat' : return array_merge($arr, $params[0]);
  22. case 'copy' : return _hx_array_copy($arr);
  23. case 'insert' : return _hx_array_insert($arr, $params[0], $params[1]);
  24. case 'iterator': return new _hx_array_iterator($arr);
  25. case 'join' : return join($params[0], $arr);
  26. case 'pop' : return array_pop($arr);
  27. case 'push' : return array_push($arr, $params[0]);
  28. case 'remove' : return _hx_array_remove($arr, $params[0]);
  29. case 'reverse' : return _hx_array_reverse($arr);
  30. case 'shift' : return array_shift($arr);
  31. case 'slice' : return _hx_array_slice($arr, $params[0], (_hx_len($params) > 1 ? $params[1] : null));
  32. case 'sort' : return _hx_array_sort($arr, $params[0]);
  33. case 'splice' : return _hx_array_splice($arr, $params[0], $params[1]);
  34. case 'unshift' : return array_unshift($arr, $params[0]);
  35. default : throw new HException('Invalid Operation: ' . $method);
  36. }
  37. }
  38. function _hx_array_copy($a) {
  39. return $a;
  40. }
  41. function _hx_array_empty() {
  42. return array();
  43. }
  44. function &_hx_array_get_ref(&$o, $index) {
  45. $r = null;
  46. if(isset($o[$index])) $r =& $o[$index];
  47. return $r;
  48. }
  49. function _hx_array_insert(&$arr, $pos, $x) {
  50. array_splice($arr, $pos, 0, array($x));
  51. }
  52. function _hx_array_iterator($arr) {
  53. return new _hx_array_iterator($arr);
  54. }
  55. function _hx_array_remove(&$arr, $x) {
  56. for($i = 0; $i < count($arr); $i++)
  57. if($arr[$i] === $x) {
  58. unset($arr[$i]);
  59. $arr = array_values($arr);
  60. return true;
  61. }
  62. return false;
  63. }
  64. function _hx_array_remove_at(&$arr, $pos) {
  65. if(array_key_exists($pos, $arr)) {
  66. unset($arr[$pos]);
  67. return true;
  68. } else
  69. return false;
  70. }
  71. function _hx_array_reverse(&$a) {
  72. $a = array_reverse($a, false);
  73. }
  74. function _hx_array_set(&$arr, $pos, $v) {
  75. if(is_int($pos)) {
  76. $l = count($arr);
  77. if($l < $pos)
  78. array_splice($arr, $l, 0, array_fill($l, $pos-$l, null));
  79. }
  80. return $arr[$pos] = $v;
  81. }
  82. function _hx_array_slice(&$arr, $pos, $end) {
  83. if($end == null)
  84. return array_slice($arr, $pos);
  85. else
  86. return array_slice($arr, $pos, $end-$pos);
  87. }
  88. function _hx_array_sort(&$arr, $f) {
  89. $i = 0;
  90. $l = count($arr);
  91. while($i < $l) {
  92. $swap = false;
  93. $j = 0;
  94. $max = $l - $i - 1;
  95. while($j < $max) {
  96. if(call_user_func($f, $arr[$j], $arr[$j+1]) > 0 ) {
  97. $tmp = $arr[$j+1];
  98. $arr[$j+1] = $arr[$j];
  99. $arr[$j] = $tmp;
  100. $swap = true;
  101. }
  102. $j += 1;
  103. }
  104. if(!$swap) break;
  105. $i += 1;
  106. }
  107. }
  108. function _hx_array_splice(&$arr, $pos, $len) {
  109. if($len < 0) $len = 0;
  110. return array_splice($arr, $pos, $len);
  111. }
  112. function _hx_char_code_at($s, $pos) {
  113. if(empty($s) || $pos >= strlen($s)) return null;
  114. return ord($s{$pos});
  115. }
  116. // TODO: optimization, remove as much as possible the calls to this function
  117. function _hx_closure($locals, $scope, $params, $body) {
  118. return array(new _hx_lambda($locals, $scope, $params, $body), 'execute'.count($params));
  119. }
  120. function _hx_deref(&$o) {
  121. return $o;
  122. }
  123. function _hx_equal($x, $y) {
  124. if(is_null($x)) {
  125. return is_null($y);
  126. } else {
  127. if(is_null($y)) {
  128. return false;
  129. } else {
  130. if((is_float($x) || is_int($x)) && (is_float($y) || is_int($y))) {
  131. return $x == $y;
  132. } else {
  133. return $x === $y;
  134. }
  135. }
  136. }
  137. }
  138. function _hx_error_handler($errno, $errmsg, $filename, $linenum, $vars) {
  139. $msg = $errmsg . ' (errno: ' . $errno . ') in ' . $filename . ' at line #' . $linenum;
  140. $e = new HException($msg, $errmsg, $errno, _hx_anonymous(array('fileName' => 'Boot.hx', 'lineNumber' => 41, 'className' => 'php.Boot', 'methodName' => '__error_handler')));
  141. $e->setFile($filename);
  142. $e->setLine($linenum);
  143. throw $e;
  144. return null;
  145. }
  146. function _hx_exception_handler($e) {
  147. $msg = '<pre>Uncaught exception: <b>' . $e->getMessage() . '</b>\nin file: <b>' . $e->getFile() . '</b> line <b>' . $e->getLine() . '</b>\n\n' . $e->getTraceAsString() . '</pre>';
  148. die($msg);
  149. }
  150. function _hx_field($o, $field) {
  151. if(_hx_has_field($o, $field)) {
  152. if($o instanceof _hx_type) {
  153. if(is_callable(array($o->__tname__, $field))) {
  154. return array($o->__tname__, $field);
  155. } else {
  156. return eval('return '.$o->__tname__.'::$'.$field.';');
  157. }
  158. } else {
  159. if(is_string($o)) {
  160. if($field == 'length') {
  161. return _hx_len($o);
  162. } else {
  163. switch($field) {
  164. case 'charAt' : return _hx_closure(array('o' => &$o), null, array('index'), 'return substr($o,$index,1);');
  165. case 'charCodeAt' : return _hx_closure(array('o' => &$o), null, array('index'), 'return ord(substr($o, $index, 1));');
  166. case 'indexOf' : return _hx_closure(array('o' => &$o), null, array('value','startIndex'), 'return _hx_index_of($o, $value, $startIndex);');
  167. case 'lastIndexOf': return _hx_closure(array('o' => &$o), null, array('value','startIndex'), 'return _hx_last_index_of($o, $value, $startIndex);');
  168. case 'split' : return _hx_closure(array('o' => &$o), null, array('delimiter'), 'return explode($delimiter, $o);');
  169. case 'substr' : return _hx_closure(array('o' => &$o), null, array('pos','len'), 'return _hx_substr($o, $pos, $len);');
  170. case 'toUpperCase': return _hx_closure(array('o' => &$o), null, array(), 'return strtoupper($o);');
  171. case 'toLowerCase': return _hx_closure(array('o' => &$o), null, array(), 'return strtolower($o);');
  172. case 'toString' : return _hx_closure(array('o' => &$o), null, array(), 'return $o;');
  173. }
  174. return null;
  175. }
  176. }
  177. else {
  178. if(is_array($o)) {
  179. if($field == 'length') {
  180. return _hx_len($o);
  181. } else {
  182. switch($field) {
  183. case 'concat' : return _hx_closure(array('o' => &$o), null, array('a'), 'return array_merge($o, $a);');
  184. case 'join' : return _hx_closure(array('o' => &$o), null, array('sep'), 'return join($sep,$o);');
  185. case 'pop' : return _hx_closure(array('o' => &$o), null, array(), 'return array_pop($o);');
  186. case 'push' : return _hx_closure(array('o' => &$o), null, array('x'), 'return array_push($o,$x);');
  187. case 'reverse' : return _hx_closure(array('o' => &$o), null, array(), 'return _hx_reverse($o);');
  188. case 'shift' : return _hx_closure(array('o' => &$o), null, array(), 'return array_shift($o);');
  189. case 'slice' : return _hx_closure(array('o' => &$o), null, array('pos','end'), 'return _hx_array_slice($o, $pos, $end);');
  190. case 'sort' : return _hx_closure(array('o' => &$o), null, array('f'), 'return _hx_array_sort($o,$f);');
  191. case 'splice' : return _hx_closure(array('o' => &$o), null, array('pos','len'), 'return _hx_array_splice($o, $pos, $len);');
  192. case 'toString': return _hx_closure(array('o' => &$o), null, array(), 'return \"[\".join(\", \", $o).\"]\";');
  193. case 'unshift' : return _hx_closure(array('o' => &$o), null, array('x'), 'return array_unshift($o,$x);');
  194. case 'insert' : return _hx_closure(array('o' => &$o), null, array('pos','x'), 'return _hx_array_insert($o, $pos, $x);');
  195. case 'remove' : return _hx_closure(array('o' => &$o), null, array('x'), '_hx_array_remove($o, $x);');
  196. case 'iterator': return _hx_closure(array('o' => &$o), null, array(), 'return new _hx_array_iterator($o);');
  197. case 'copy' : return _hx_closure(array('o' => &$o), null, array(), 'return $o;');
  198. }
  199. }
  200. return null;
  201. } else {
  202. if(property_exists($o, $field)) {
  203. if(is_array($o->$field) && is_callable($o->$field)) {
  204. return $o->$field;
  205. } else {
  206. if(is_string($o->$field) && _hx_is_lambda($o->$field)) {
  207. return array($o, $field);
  208. } else {
  209. return $o->$field;
  210. }
  211. }
  212. } else {
  213. return array($o, $field);
  214. }
  215. }
  216. }
  217. }
  218. } else {
  219. return null;
  220. }
  221. }
  222. function _hx_has_field($o, $field) {
  223. return
  224. (is_object($o) && (method_exists($o, $field) || isset($o->$field) || property_exists($o, $field)))
  225. ||
  226. (is_string($o) && (in_array($field, array('toUpperCase', 'toLowerCase', 'charAt', 'charCodeAt', 'indexOf', 'lastIndexOf', 'split', 'substr', 'toString', 'length'))))
  227. ||
  228. (is_array($o) && (in_array($field, array('concat', 'copy', 'insert', 'iterator', 'join', 'pop', 'push', 'remove', 'reverse', 'shift', 'slice', 'sort', 'splice', 'unshift', 'toString', 'length'))))
  229. ;
  230. }
  231. function _hx_index_of($s, $value, $startIndex) {
  232. $x = strpos($s, $value, $startIndex);
  233. if($x === false)
  234. return -1;
  235. else
  236. return $x;
  237. }
  238. function _hx_instanceof($v, $t) {
  239. if($t === null) {
  240. return false;
  241. }
  242. switch($t->__tname__) {
  243. case 'Array' : return is_array($v);
  244. case 'String' : return is_string($v) && !_hx_is_lambda($v);
  245. case 'Bool' : return is_bool($v);
  246. case 'Int' : return is_int($v);
  247. case 'Float' : return is_float($v) || is_int($v);
  248. case 'Dynamic': return true;
  249. case 'Class' : return $v instanceof _hx_class && $v->__tname__ != 'Enum';
  250. case 'Enum' : return $v instanceof _hx_enum;
  251. default : return is_a($v, $t->__tname__);
  252. }
  253. }
  254. function _hx_is_lambda($s) {
  255. return (is_string($s) && substr($s, 0, 8) == chr(0).'lambda_') || (is_array($s) && count($s) > 0 && is_a($s[0], '_hx_lambda'));
  256. }
  257. function _hx_last_index_of($s, $value, $startIndex) {
  258. $x = strrpos($s, $value, $startIndex === null ? null : strlen($s) - $startIndex);
  259. if($x === false)
  260. return -1;
  261. else
  262. return $x;
  263. }
  264. function _hx_len($o) {
  265. return is_array($o) ? count($o) : (is_string($o) ? strlen($o) : $o->length);
  266. }
  267. function _hx_null() {
  268. return null;
  269. }
  270. function _hx_qtype($n) {
  271. return isset(php_Boot::$qtypes[$n]) ? php_Boot::$qtypes[$n] : null;
  272. }
  273. function _hx_register_type($t) {
  274. php_Boot::$qtypes[$t->__qname__] = $t;
  275. php_Boot::$ttypes[$t->__tname__] = $t;
  276. if($t->__path__ !== null)
  277. php_Boot::$tpaths[$t->__tname__] = $t->__path__;
  278. }
  279. function _hx_shift_right($v, $n) {
  280. $z = 0x80000000;
  281. if ($z & $v) {
  282. $v = ($v>>1);
  283. $v &= (~$z);
  284. $v |= 0x40000000;
  285. $v = ($v>>($n-1));
  286. } else $v = ($v>>$n);
  287. return $v;
  288. }
  289. function _hx_string_call($s, $method, $params) {
  290. if(!is_string($s)) return call_user_func_array(array($s, $method), $params);
  291. switch($method) {
  292. case 'toUpperCase': return strtoupper($s);
  293. case 'toLowerCase': return strtolower($s);
  294. case 'charAt' : return substr($s, $params[0], 1);
  295. case 'charCodeAt' : return _hx_char_code_at($s, $params[0]);
  296. case 'indexOf' : return _hx_index_of($s, $params[0], (_hx_len($params) > 1 ? $params[1] : null));
  297. case 'lastIndexOf': return _hx_last_index_of($s, (_hx_len($params) > 1 ? $params[1] : null), null);
  298. case 'split' : return explode($params[0], $s);
  299. case 'substr' : return _hx_substr($s, $params[0], (_hx_len($params) > 1 ? $params[1] : null));
  300. default : throw new HException('Invalid Operation: ' . $method);
  301. }
  302. }
  303. function _hx_string_rec($o, $s) {
  304. if($o === null) return 'null';
  305. if(strlen($s) >= 5) return '<...>';
  306. if(is_int($o) || is_float($o)) return $o;
  307. if(is_bool($o)) return $o ? 'true' : 'false';
  308. if(is_object($o)) {
  309. $c = get_class($o);
  310. if($o instanceof Enum) {
  311. $b = $o->tag;
  312. if(!empty($o->params)) {
  313. $s .= \"\t\";
  314. $b .= '(';
  315. for($i = 0; $i < count($o->params); $i++) {
  316. if($i > 0)
  317. $b .= ', ' . _hx_string_rec($o->params[$i], $s);
  318. else
  319. $b .= _hx_string_rec($o->params[$i], $s);
  320. }
  321. $b .= ')';
  322. }
  323. return $b;
  324. } else {
  325. if($o instanceof _hx_anonymous) {
  326. $rfl = new ReflectionObject($o);
  327. $b2 = \"{\n\";
  328. $s .= \"\t\";
  329. $properties = $rfl->getProperties();
  330. for($i = 0; $i < count($properties); $i++) {
  331. $prop = $properties[$i];
  332. $f = $prop->getName();
  333. if($i > 0)
  334. $b2 .= \", \n\";
  335. $b2 .= $s . $f . ' : ' . _hx_string_rec($prop->getValue($o), $s);
  336. }
  337. $s = substr($s, 1);
  338. $b2 .= \"\n\" . $s . '}';
  339. return $b2;
  340. } else {
  341. if($o instanceof _hx_type)
  342. return $o->__qname__;
  343. else {
  344. if(is_callable(_hx_array($o, 'toString')))
  345. return $o->toString();
  346. else {
  347. if(is_callable(_hx_array($o, '__toString')))
  348. return $o->__toString();
  349. else
  350. return '[' . _hx_ttype($c) . ']';
  351. }
  352. }
  353. }
  354. }
  355. }
  356. if(is_string($o)) {
  357. if(_hx_is_lambda($o)) return '«function»';
  358. if(strlen($s) > 0) return '\"' . str_replace('\"', '\\\"', $o) . '\"';
  359. else return $o;
  360. }
  361. if(is_array($o)) {
  362. if(is_callable($o)) return '«function»';
  363. $str = '[';
  364. $s .= \"\t\";
  365. for($i = 0; $i < count($o); $i++)
  366. $str .= ($i > 0 ? ', ' : '') . _hx_string_rec($o[$i], $s);
  367. $str .= ']';
  368. return $str;
  369. }
  370. return '';
  371. }
  372. function _hx_substr($s, $pos, $len) {
  373. if($pos !== null && $pos !== 0 && $len !== null && $len < 0) return '';
  374. if($len === null) $len = strlen($s);
  375. if($pos < 0) {
  376. $pos = strlen($s) + $pos;
  377. if($pos < 0) $pos = 0;
  378. } else if($len < 0 )
  379. $len = strlen($s) + $len - $pos;
  380. $s = substr($s, $pos, $len);
  381. if($s === false)
  382. return '';
  383. else
  384. return $s;
  385. }
  386. function _hx_trace($v, $i) {
  387. $msg = $i !== null ? $i->fileName.':'.$i->lineNumber.': ' : '';
  388. echo $msg._hx_string_rec($v, '').\"\n\";
  389. }
  390. function _hx_ttype($n) {
  391. return isset(php_Boot::$ttypes[$n]) ? php_Boot::$ttypes[$n] : null;
  392. }
  393. class _hx_anonymous extends stdClass {
  394. public function __call($m, $a) {
  395. $v = $this->$m;
  396. try {
  397. return call_user_func_array($v, $a);
  398. } catch(Exception $e) {
  399. throw new HException('Unable to call «'.$m.'»');
  400. }
  401. }
  402. public function __set($n, $v) {
  403. $this->$n = $v;
  404. }
  405. public function &__get($n) {
  406. if(isset($this->$n))
  407. return $this->$n;
  408. $null = null;
  409. return $null;
  410. }
  411. public function __isset($n) {
  412. return isset($this->$n);
  413. }
  414. public function __unset($n) {
  415. unset($this->$n);
  416. }
  417. public function __toString() {
  418. $rfl = new ReflectionObject($this);
  419. $b = '{ ';
  420. $properties = $rfl->getProperties();
  421. $first = true;
  422. foreach($properties as $prop) {
  423. if($first)
  424. $first = false;
  425. else
  426. $b .= ', ';
  427. $f = $prop->getName();
  428. $b .= $f . ' => ' . $prop->getValue($this);
  429. }
  430. $b .= ' }';
  431. return $b;
  432. }
  433. }
  434. class _hx_type {
  435. public $__tname__;
  436. public $__qname__;
  437. public $__path__;
  438. public function __construct($cn, $qn, $path = null) {
  439. $this->__tname__ = $cn;
  440. $this->__qname__ = $qn;
  441. $this->__path__ = $path;
  442. }
  443. public function toString() { return $this->__toString(); }
  444. public function __toString() {
  445. return $this->__qname__;
  446. }
  447. private $rfl = false;
  448. public function __rfl__() {
  449. if($this->rfl !== false) return $this->rfl;
  450. if(class_exists($this->__tname__))
  451. $this->rfl = new ReflectionClass($this->__tname__);
  452. else
  453. $this->rfl = null;
  454. return $this->rfl;
  455. }
  456. public function __call($n, $a) {
  457. return call_user_func_array(array($this->__tname__, $n), $a);
  458. }
  459. public function __get($n) {
  460. if(($r = $this->__rfl__())==null) return null;
  461. if($r->hasProperty($n))
  462. return $r->getStaticPropertyValue($n);
  463. else if($r->hasMethod($n))
  464. return array($r, $n);
  465. else
  466. return null;
  467. }
  468. public function __set($n, $v) {
  469. if(($r = $this->__rfl__())==null) return null;
  470. return $r->setStaticPropertyValue($n, $v);
  471. }
  472. public function __isset($n) {
  473. if(($r = $this->__rfl__())==null) return null;
  474. return $r->hasProperty($n) || $r->hasMethod($n);
  475. }
  476. }
  477. class _hx_class extends _hx_type {}
  478. class _hx_enum extends _hx_type {}
  479. class _hx_interface extends _hx_type { }
  480. class _hx_array_iterator {
  481. private $a;
  482. private $i;
  483. public function __construct($a) {
  484. $this->a = $a;
  485. $this->i = 0;
  486. }
  487. public function next() {
  488. if(!$this->hasNext()) return null;
  489. return $this->a[$this->i++];
  490. }
  491. public function hasNext() {
  492. return $this->i < count($this->a);
  493. }
  494. }
  495. class HException extends Exception {
  496. public function __construct($e, $message = null, $code = null, $p = null) {
  497. $message = _hx_string_rec($e, '') . $message;
  498. parent::__construct($message,$code);
  499. $this->e = $e;
  500. $this->p = $p;
  501. }
  502. public $e;
  503. public $p;
  504. public function setLine($l) {
  505. $this->line = $l;
  506. }
  507. public function setFile($f) {
  508. $this->file = $f;
  509. }
  510. }
  511. class _hx_lambda {
  512. public function __construct($locals, $scope, $args, $body) {
  513. $this->locals = $locals;
  514. $this->scope = $scope;
  515. $this->args = $args;
  516. $this->body = $body;
  517. }
  518. public $locals;
  519. public $scope;
  520. public $args;
  521. public $body;
  522. public $params = array();
  523. public function execute() {
  524. $__this =& $this->scope;
  525. foreach(array_keys($this->locals) as ${'%k'})
  526. ${${'%k'}} =& $this->locals[${'%k'}];
  527. for(${'%i'} = 0; ${'%i'} < count($this->args); ${'%i'}++)
  528. ${$this->args[${'%i'}]} =& $this->params[${'%i'}];
  529. return eval($this->body);
  530. }
  531. public function makeArgs() {
  532. $this->params = array(func_get_args());
  533. return $this->execute();
  534. }
  535. public function execute0() {
  536. $this->params = array();
  537. return $this->execute();
  538. }
  539. public function execute1(&$_1) {
  540. if($this->scope == null) $this->scope= &$_1;
  541. $this->params = array(&$_1);
  542. return $this->execute();
  543. }
  544. public function execute2(&$_1, &$_2) {
  545. if($this->scope == null) $this->scope= &$_1;
  546. $this->params = array(&$_1, &$_2);
  547. return $this->execute();
  548. }
  549. public function execute3(&$_1, &$_2, &$_3) {
  550. if($this->scope == null) $this->scope= &$_1;
  551. $this->params = array(&$_1, &$_2, &$_3);
  552. return $this->execute();
  553. }
  554. public function execute4(&$_1, &$_2, &$_3, &$_4) {
  555. if($this->scope == null) $this->scope= &$_1;
  556. $this->params = array(&$_1, &$_2, &$_3, &$_4);
  557. return $this->execute();
  558. }
  559. public function execute5(&$_1, &$_2, &$_3, &$_4, &$_5) {
  560. if($this->scope == null) $this->scope= &$_1;
  561. $this->params = array(&$_1, &$_2, &$_3, &$_4, &$_5);
  562. return $this->execute();
  563. }
  564. public function execute6(&$_1, &$_2, &$_3, &$_4, &$_5, &$_6) {
  565. if($this->scope == null) $this->scope= &$_1;
  566. $this->params = array(&$_1, &$_2, &$_3, &$_4, &$_5, &$_6);
  567. return $this->execute();
  568. }
  569. public function execute7(&$_1, &$_2, &$_3, &$_4, &$_5, &$_6, &$_7) {
  570. if($this->scope == null) $this->scope= &$_1;
  571. $this->params = array(&$_1, &$_2, &$_3, &$_4, &$_5, &$_6, &$_7);
  572. return $this->execute();
  573. }
  574. }
  575. class Enum {
  576. public function __construct($tag, $index, $params = null) { $this->tag = $tag; $this->index = $index; $this->params = $params; }
  577. public $tag;
  578. public $index;
  579. public $params;
  580. public function __toString() {
  581. return $this->tag;
  582. }
  583. }
  584. set_error_handler('_hx_error_handler', E_ALL);
  585. set_exception_handler('_hx_exception_handler');
  586. php_Boot::$qtypes = array();
  587. php_Boot::$ttypes = array();
  588. php_Boot::$tpaths = array();
  589. _hx_register_type(new _hx_class('String', 'String'));
  590. _hx_register_type(new _hx_class('Array', 'Array'));
  591. _hx_register_type(new _hx_class('Int', 'Int'));
  592. _hx_register_type(new _hx_class('Float', 'Float'));
  593. _hx_register_type(new _hx_class('Class', 'Class'));
  594. _hx_register_type(new _hx_class('Enum', 'Enum'));
  595. _hx_register_type(new _hx_class('Dynamic', 'Dynamic'));
  596. _hx_register_type(new _hx_enum('Bool', 'Bool'));
  597. _hx_register_type(new _hx_enum('Void', 'Void'));
  598. $_hx_libdir = dirname(__FILE__) . '/..';
  599. $_hx_autload_cache_file = $_hx_libdir . '/../cache/haxe_autoload.php';
  600. if(!file_exists($_hx_autload_cache_file)) {
  601. function _hx_build_paths($d, &$_hx_types_array, $pack) {
  602. $h = opendir($d);
  603. while (false !== ($f = readdir($h))) {
  604. $p = $d.'/'.$f;
  605. if($f == '.' || $f == '..')
  606. continue;
  607. if(is_file($p) && substr($f, -4) == '.php') {
  608. $bn = basename($f, '.php');
  609. if(substr($bn, -6) == '.class') {
  610. $bn = substr($bn, 0, -6);
  611. $t = 0;
  612. } else if(substr($bn, -5) == '.enum') {
  613. $bn = substr($bn, 0, -5);
  614. $t = 1;
  615. } else if(substr($bn, -10) == '.interface') {
  616. $bn = substr($bn, 0, -10);
  617. $t = 2;
  618. } else if(substr($bn, -7) == '.extern') {
  619. $bn = substr($bn, 0, -7);
  620. $t = 3;
  621. } else
  622. continue;
  623. $qname = ($bn == 'HList' && empty($pack)) ? 'List' : join(array_merge($pack, array($bn)), '.');
  624. $_hx_types_array[] = array(
  625. 'path' => $p,
  626. 'name' => $bn,
  627. 'type' => $t,
  628. 'qname' => $qname,
  629. 'phpname' => join(array_merge($pack, array($bn)), '_')
  630. );
  631. } else if(is_dir($p))
  632. _hx_build_paths($p, $_hx_types_array, array_merge($pack, array($f)));
  633. }
  634. closedir($h);
  635. }
  636. $_hx_cache_content = '<?php\n\n';
  637. $_hx_types_array = array();
  638. _hx_build_paths($_hx_libdir, $_hx_types_array, array());
  639. for($i=0;$i<count($_hx_types_array);$i++) {
  640. $_hx_cache_content .= '_hx_register_type(new ';
  641. $t = null;
  642. if($_hx_types_array[$i]['type'] == 0) {
  643. $t = new _hx_class($_hx_types_array[$i]['phpname'], $_hx_types_array[$i]['qname'], $_hx_types_array[$i]['path']);
  644. $_hx_cache_content .= '_hx_class';
  645. } else if($_hx_types_array[$i]['type'] == 1) {
  646. $t = new _hx_enum($_hx_types_array[$i]['phpname'], $_hx_types_array[$i]['qname'], $_hx_types_array[$i]['path']);
  647. $_hx_cache_content .= '_hx_enum';
  648. } else if($_hx_types_array[$i]['type'] == 2) {
  649. $t = new _hx_interface($_hx_types_array[$i]['phpname'], $_hx_types_array[$i]['qname'], $_hx_types_array[$i]['path']);
  650. $_hx_cache_content .= '_hx_interface';
  651. } else if($_hx_types_array[$i]['type'] == 3) {
  652. $t = new _hx_class($_hx_types_array[$i]['name'], $_hx_types_array[$i]['qname'], $_hx_types_array[$i]['path']);
  653. $_hx_cache_content .= '_hx_class';
  654. }
  655. _hx_register_type($t);
  656. $_hx_cache_content .= '(\\''.($_hx_types_array[$i]['type'] == 3 ? $_hx_types_array[$i]['name'] : $_hx_types_array[$i]['phpname']).'\\', \\''.$_hx_types_array[$i]['qname'].'\\', \\''.$_hx_types_array[$i]['path'].'\\'));\n';
  657. }
  658. try {
  659. file_put_contents($_hx_autload_cache_file, $_hx_cache_content);
  660. } catch(Exception $e) {}
  661. unset($_hx_types_array);
  662. unset($_hx_cache_content);
  663. } else {
  664. require($_hx_autload_cache_file);
  665. }
  666. function _hx_autoload($name) {
  667. if(!isset(php_Boot::$tpaths[$name])) return false;
  668. require_once(php_Boot::$tpaths[$name]);
  669. return true;
  670. }
  671. spl_autoload_register('_hx_autoload')");
  672. }
  673. }