Boot.hx 22 KB

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