|
From: <da...@us...> - 2003-08-04 00:48:41
|
Update of /cvsroot/binaryphp/binaryphp
In directory sc8-pr-cvs1:/tmp/cvs-serv18640
Modified Files:
convert.php functions.php php_var.cpp testfile.php
tokenflow.php
Log Message:
Concatenation works. === and !== work.
Index: convert.php
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/convert.php,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** convert.php 3 Aug 2003 06:29:12 -0000 1.15
--- convert.php 4 Aug 2003 00:48:37 -0000 1.16
***************
*** 1,5 ****
<?php
error_reporting(E_ALL);
! define('DEBUG', false);
if(!empty($_SERVER['DOCUMENT_ROOT']))
header('Content-Type: text/plain');
--- 1,13 ----
<?php
+ if (substr(PHP_OS, 0, 3) == 'WIN') {
+ define('BINARYPHP_OS', 'Windows');
+ } else {
+ define('BINARYPHP_OS', 'Unix');
+ }
error_reporting(E_ALL);
! if(@$_SERVER['argv'][1]=='debug')
! define('DEBUG', true);
! else
! define('DEBUG', false);
if(!empty($_SERVER['DOCUMENT_ROOT']))
header('Content-Type: text/plain');
***************
*** 8,29 ****
require_once 'functions.php';
$tokenizer = new Tokenizer();
! $tokenizer->Parse('testfile2.php');
$tokenizer->Strip();
$gen = new Generator($tokenizer);
list($code, $flags) = $gen->Convert();
! echo $code;
! $fp = fopen('test.cpp', 'w');
fwrite($fp, $code);
fclose($fp);
echo "\n\n", 'Compiling:', "\n";
touch('log');
! $comp = 'g++ -o test test.cpp ' . $flags . ' >> log 2>> log';
! echo $comp, "\n\n";
! shell_exec($comp);
echo implode(null, file('log'));
unlink('log');
echo "\n\n", 'Running:', "\n";
! passthru('./test');
! // unlink('test');
! unlink('test.cpp');
! ?>
--- 16,65 ----
require_once 'functions.php';
$tokenizer = new Tokenizer();
! $tokenizer->Parse('testfile.php');
$tokenizer->Strip();
$gen = new Generator($tokenizer);
list($code, $flags) = $gen->Convert();
! $lines = explode("\n", $code);
! foreach($lines as $line => $cod)
! echo $line + 1, ': ', $cod, "\n";
! $fp = fopen('test.cpp', 'wt');
fwrite($fp, $code);
fclose($fp);
echo "\n\n", 'Compiling:', "\n";
touch('log');
! if(BINARYPHP_OS == 'Windows') {
! $comp = 'cl -c /nologo /MT /W3 /GX /FD -DWIN32 /Fotest.obj test.cpp >> log';
! echo $comp, "\n\n";
! shell_exec($comp);
! if(DEBUG==true)
! $opt='-debug';
! else
! $opt='-release';
! $comp = 'link test.obj -nologo '.$opt.' -incremental:no -opt:ref '.$flags.' -out:test.exe >> log';
! echo $comp, "\n\n";
! shell_exec($comp);
! } else {
! $comp = 'g++ -o test test.cpp ' . $flags . ' >> log 2>> log';
! echo $comp, "\n\n";
! shell_exec($comp);
! }
echo implode(null, file('log'));
unlink('log');
echo "\n\n", 'Running:', "\n";
! if(BINARYPHP_OS == 'Windows') {
! passthru('test.exe');
! if(!DEBUG) {
! unlink('test.exe');
! shell_exec('del *.obj');
! shell_exec('del *.idb');
! if(is_file('test.pdb'))
! unlink('test.pdb');
! }
! } else {
! passthru('./test');
! if(!DEBUG)
! unlink('test');
! }
! if(!DEBUG)
! unlink('test.cpp');
! ?>
\ No newline at end of file
Index: functions.php
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/functions.php,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** functions.php 3 Aug 2003 06:29:12 -0000 1.33
--- functions.php 4 Aug 2003 00:48:37 -0000 1.34
***************
*** 54,57 ****
--- 54,60 ----
'readdir' => array(array('cstdio', 'dirent.h'), 'readdir.cpp'),
'closedir' => array(array('cstdio', 'dirent.h'), 'closedir.cpp'),
+ 'glClear' => array(array('GL/gl.h', 'GL/glu.h'), null, array('GLU', 'GL')),
+ 'glutWireCube' => array('GL/glut.h', null, array('GLU', 'GL', 'glut')),
+ 'glLightfv' => array(array('GL/gl.h', 'GL/glu.h'), 'glLightfv'),
null
);
Index: php_var.cpp
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/php_var.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** php_var.cpp 3 Aug 2003 06:29:12 -0000 1.19
--- php_var.cpp 4 Aug 2003 00:48:37 -0000 1.20
***************
*** 10,15 ****
#define PHP_OBJECT 6
- class test;
-
char* intstring(long i)
{
--- 10,13 ----
***************
*** 108,111 ****
--- 106,113 ----
return atof(container.c_str());
}
+ operator float()
+ {
+ return atof(container.c_str());
+ }
operator int()
{
***************
*** 430,431 ****
--- 432,434 ----
return(v < i);
}
+ #define is_identical(var, varb) (((var) == (varb) && (var).type == (varb).type) ? (php_var)true : (php_var)false)
\ No newline at end of file
Index: testfile.php
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/testfile.php,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** testfile.php 2 Aug 2003 04:23:48 -0000 1.40
--- testfile.php 4 Aug 2003 00:48:37 -0000 1.41
***************
*** 1,19 ****
<?php
- $var = socket_create(AF_INET, SOCK_STREAM, 0);
- if($var == false)
- echo "Couldn't create.";
- if(socket_connect($var, 'irc.freenode.net', 6667) == false)
- echo "Couldn't connect.\n";
- $buf = true;
- while($buf != false)
- {
- $buf = socket_read($var, 1024);
- echo $buf;
- }
- if(socket_write($var, "USER daek daek daek :daek\r\n") == false)
- echo "Couldn't write. 1\n";
- if(socket_write($var, "NICK Daek\r\n") == false)
- echo "Couldn't write. 2\n";
- if(socket_write($var, "JOIN #phpfreaks\r\n") == false)
- echo "Couldn't write. 3\n";
?>
--- 1,2 ----
Index: tokenflow.php
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/tokenflow.php,v
retrieving revision 1.45
retrieving revision 1.46
diff -C2 -d -r1.45 -r1.46
*** tokenflow.php 3 Aug 2003 06:29:12 -0000 1.45
--- tokenflow.php 4 Aug 2003 00:48:37 -0000 1.46
***************
*** 28,33 ****
global $funcs;
$this->code = array('main' => array());
! $this->prototypes = array('main' => array('int', array('void')));
$this->namespace = 'std';
$parameters = array();
$i = -1;
--- 28,34 ----
global $funcs;
$this->code = array('main' => array());
! $this->prototypes = array('main' => array('int', array('int *_argc', 'char **_argv')));
$this->namespace = 'std';
+ $this->includes[] = 'sstream';
$parameters = array();
$i = -1;
***************
*** 37,43 ****
for($a = 0; $a < count($tokenizer->tokens); ++$a)
{
! if(is_array($tokenizer->tokens[$a]) && $tokenizer->tokens[$a][0] == T_GLOBAL && !in_array('_' . substr($tokenizer->tokens[$a + 1][1], 1), $this->globals))
! $this->globals[] = '_' . substr($tokenizer->tokens[$a + 1][1], 1);
}
$this->scope[] = $this->globals;
for($a = 0; $a < count($tokenizer->tokens); ++$a)
--- 38,46 ----
for($a = 0; $a < count($tokenizer->tokens); ++$a)
{
! if(is_array($tokenizer->tokens[$a]) && $tokenizer->tokens[$a][0] == T_GLOBAL && !in_array(substr($tokenizer->tokens[$a + 1][1], 1), $this->globals))
! $this->globals[] = substr($tokenizer->tokens[$a + 1][1], 1);
}
+ $this->globals[] = 'argc';
+ $this->globals[] = 'argv';
$this->scope[] = $this->globals;
for($a = 0; $a < count($tokenizer->tokens); ++$a)
***************
*** 95,98 ****
--- 98,102 ----
case T_GLOBAL:
$this->scope[$this->curfunction][] = substr($tokenizer->tokens[$a + 1][1], 1);
+ echo $tokenizer->tokens[$a + 1][1], "\n";
$a += 3;
break;
***************
*** 114,122 ****
$this->code[$data] = array();
$a = $z + 1;
! // ++$this->tabs;
}
elseif(is_array($tokenizer->tokens[$a - 1]) && $tokenizer->tokens[$a - 1][0] == T_CLASS)
{
! $this->classes[$data] = array('public' => array(), 'private' => array());
$this->curclass = $data;
$this->inclass = true;
--- 118,127 ----
$this->code[$data] = array();
$a = $z + 1;
! if(DEBUG)
! echo 'In function: ', $data, "\n";
}
elseif(is_array($tokenizer->tokens[$a - 1]) && $tokenizer->tokens[$a - 1][0] == T_CLASS)
{
! $this->classes[$data] = array('public' => array(), 'private' => array(), 'funcs' => array());
$this->curclass = $data;
$this->inclass = true;
***************
*** 198,203 ****
break;
case T_ELSE:
! if($tokenizer->tokens[$a - 1] != '}')
--$this->tabs;
$this->AddCode('else');
if($tokenizer->tokens[$a + 1] != '{')
--- 203,211 ----
break;
case T_ELSE:
! if($temptabs !== false)
! {
--$this->tabs;
+ $temptabs = false;
+ }
$this->AddCode('else');
if($tokenizer->tokens[$a + 1] != '{')
***************
*** 327,331 ****
break;
case '}':
- echo $this->functions[$this->curfunction], ' - ', $this->tabs, "\n";
if($this->tabs == 0)
{
--- 335,338 ----
***************
*** 347,356 ****
if($this->switched[$this->inswitch] == true)
$this->AddCode('}');
! $this->AddCode('_end_' . $this->inswitch-- . ':');
}
else
$this->AddCode('}');
! if($this->tabs == 0 && $this->curfunction > 0)
$this->curfunction = 0;
}
break;
--- 354,365 ----
if($this->switched[$this->inswitch] == true)
$this->AddCode('}');
! $this->AddCode('_end_' . $this->inswitch . ':');
}
else
$this->AddCode('}');
! if($this->tabs == 0 && $this->curfunction > 0 && $this->inswitch == 0)
$this->curfunction = 0;
+ if($this->inswitch != 0)
+ ++$this->inswitch;
}
break;
***************
*** 392,397 ****
if(strtolower($data) == 'true' || strtolower($data) == 'false' || strtolower($data) == 'null')
$param = '(php_var) ' . strtolower($data);
! elseif(isset($this->defines[$data]))
! $param = $data;
else
list($param, $i) = $this->parse_function($tokenizer, $i);
--- 401,406 ----
if(strtolower($data) == 'true' || strtolower($data) == 'false' || strtolower($data) == 'null')
$param = '(php_var) ' . strtolower($data);
! elseif($tokenizer->tokens[$i + 1] != '(')
! list($param, $i) = $this->parse_statement($tokenizer, $i);
else
list($param, $i) = $this->parse_function($tokenizer, $i);
***************
*** 400,403 ****
--- 409,418 ----
$parameters[] = $param;
break;
+ case '(':
+ list($param, $i) = $this->parse_statement($tokenizer, $i);
+ if($tokenizer->tokens[$token_][0] == T_ARRAY && count($parameters) % 2 == 0 && (is_array($tokenizer->tokens[$i + 1]) && $tokenizer->tokens[$i + 1][1] != '=>'))
+ $parameters[] = -1;
+ $parameters[] = $param;
+ break;
case T_CONSTANT_ENCAPSED_STRING:
if($tokenizer->tokens[$token_][0] == T_ARRAY && count($parameters) % 2 == 0 && (is_array($tokenizer->tokens[$i + 1]) && $tokenizer->tokens[$i + 1][1] != '=>'))
***************
*** 408,413 ****
--- 423,432 ----
$parameters[] = '(php_var)"' . str_replace('"', '\\"', substr($data, 1, -1) ) . '"';
break;
+ case ',':
+ break;
case T_DEC:
case T_INC:
+ case T_DNUMBER:
+ case T_LNUMBER:
case T_VARIABLE:
if($tokenizer->tokens[$token_][0] == T_ARRAY && count($parameters) % 2 == 0 && (is_array($tokenizer->tokens[$i + 1]) && $tokenizer->tokens[$i + 1][1] != '=>'))
***************
*** 417,429 ****
$parameters[count($parameters) - 1] = $parameters[count($parameters) - 1];
break;
- case T_DNUMBER:
- case T_LNUMBER:
- if($tokenizer->tokens[$token_][0] == T_ARRAY && count($parameters) % 2 == 0 && (is_array($tokenizer->tokens[$i + 1]) && $tokenizer->tokens[$i + 1][1] != '=>'))
- $parameters[] = -1;
- if(strtolower($funcname) == 'define')
- $parameters[] = $data;
- else
- $parameters[] = '(php_var) ' . $data;
- break;
case ';':
case ')':
--- 436,439 ----
***************
*** 519,522 ****
--- 529,535 ----
$code = (string) null;
$in = 0;
+ $pre = $post = (string)null;
+ $params = array();
+ $inconcat = false;
for($i = $token; $i < count($tokens); ++$i)
{
***************
*** 535,538 ****
--- 548,553 ----
else
{
+ if(DEBUG)
+ echo "\t", $data_, "\n";
$code .= 'php_var _' . substr($data_, 1);
$this->scope[$this->curfunction][] = substr($data_, 1);
***************
*** 541,547 ****
case T_ARRAY:
case T_STRING:
if(strtolower($data_) == 'true' || strtolower($data_) == 'false' || strtolower($data_) == 'null')
$code .= '(php_var) ' . strtolower($data_);
! elseif(isset($this->defines[$data_]))
$code .= $data_;
elseif(is_array($tokenizer->tokens[$i - 1]) && $tokenizer->tokens[$i - 1][0] == T_NEW)
--- 556,564 ----
case T_ARRAY:
case T_STRING:
+ if($inconcat == true)
+ $code .= '(string)';
if(strtolower($data_) == 'true' || strtolower($data_) == 'false' || strtolower($data_) == 'null')
$code .= '(php_var) ' . strtolower($data_);
! elseif($tokenizer->tokens[$i + 1] != '(')
$code .= $data_;
elseif(is_array($tokenizer->tokens[$i - 1]) && $tokenizer->tokens[$i - 1][0] == T_NEW)
***************
*** 553,557 ****
{
list($t, $i) = $this->parse_function($tokenizer, $i);
! $code .= $t;
}
break;
--- 570,574 ----
{
list($t, $i) = $this->parse_function($tokenizer, $i);
! $code .= '(php_var)' . $t;
}
break;
***************
*** 560,564 ****
break;
case '=':
! $code .= ' = ';
break;
case T_PLUS_EQUAL:
--- 577,583 ----
break;
case '=':
! $params[] = $pre . $code . $post;
! $pre = $post = $code = (string) null;
! $inconcat = false;
break;
case T_PLUS_EQUAL:
***************
*** 569,577 ****
break;
case T_CONSTANT_ENCAPSED_STRING:
$code .= '"' . str_replace('"', '\\"', substr($data_, 1, -1) ). '"';
break;
case T_DNUMBER:
case T_LNUMBER:
! $code .= $data_;
break;
case T_DEC:
--- 588,600 ----
break;
case T_CONSTANT_ENCAPSED_STRING:
+ if($inconcat == true)
+ $code .= '(string)';
$code .= '"' . str_replace('"', '\\"', substr($data_, 1, -1) ). '"';
break;
case T_DNUMBER:
case T_LNUMBER:
! if($inconcat == true)
! $code .= '(string)';
! $code .= '(php_var)' . $data_;
break;
case T_DEC:
***************
*** 616,619 ****
--- 639,650 ----
$code .= ' == ';
break;
+ case T_IS_NOT_IDENTICAL:
+ $code = '!is_identical(' . $code . ', ';
+ $post = ')';
+ break;
+ case T_IS_IDENTICAL:
+ $code = 'is_identical(' . $code . ', ';
+ $post = ')';
+ break;
case '^':
$code .= ' ^ ';
***************
*** 637,647 ****
$code .= ' / ';
break;
default:
break;
}
}
if(isset($tokens[$i]) && ((!is_array($tokens[$i]) && $tokens[$i] != ',') || $in < 0))
--$i;
! return array($code, $i);
}
function debug_token(&$tokenizer, $token)
--- 668,686 ----
$code .= ' / ';
break;
+ case '|':
+ $code .= ' | ';
+ break;
+ case '.':
+ $code .= ' + ';
+ $inconcat = true;
+ break;
default:
break;
}
}
+ $params[] = $pre . $code . $post;
if(isset($tokens[$i]) && ((!is_array($tokens[$i]) && $tokens[$i] != ',') || $in < 0))
--$i;
! return array(implode(' = ', $params), $i);
}
function debug_token(&$tokenizer, $token)
***************
*** 699,703 ****
}
foreach($this->globals as $glob)
! $code .= 'php_var ' . $glob . ';' . "\n";
foreach($this->defines as $def => $val)
$code .= '#define ' . $def . ' ' . $val . "\n";
--- 738,742 ----
}
foreach($this->globals as $glob)
! $code .= 'php_var _' . $glob . ';' . "\n";
foreach($this->defines as $def => $val)
$code .= '#define ' . $def . ' ' . $val . "\n";
|