Frankenstella, a PHP compiler
Sunday, June 27, 2004
 
Maybe Not... Chance: Advance to byte code
http://www.derickrethans.nl/vld.php
Thursday, June 24, 2004
 
back to square one
sighhhh... it's not workin :'(

aaaaarrghaarghhhhhh crap crap crap!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! < tears out hair >

it seems as if the zend.c file is not involved whatsoever!
forget printf("%s",bc_op_array->type); for starters
-it's not even seeing my lovely printf("can u seee meeeee"); statement

modifications were done and the CLI version was compiled. filled with anticipation, i get nothing. N-O-T-H-I-N-G. it just obliviously carried on as if i never even surgically altered its very source.

horrible horrible PHP developers...
Tuesday, June 22, 2004
 
Altering zend.c : Getting PHP bytecode
1. zend.c calls the compile_file function
2. php bytecode is returned
3. stored in active_op_array

print active_op_array to get the bytecode.

active_op_array is a struct.
next step: find where active_op_array is defined so it can be printed.

ok, so active_op_array is defined in zend.hmore variable types such as zend_uchar can be further clarified in zend_types.h
Sunday, June 06, 2004
 
The PHP Bytecode Generator Component
The plan for spewing out PHP bytecode is:
1. alter the php zend_execute file
2. get it to emit bytecode to STDOUT rather than executing
3. Use some sort of bytecode interpreter for Win32 to get assembly instructions (.asm file) and continue with intended architechture.

This approach seems very similar to how Parrot is being done. However, they are using their own assembly language.

So far, i haven't been able to locate a bytecode interpreter, may have to make one if it is unavailable.

However, several Linkers are available, esp for use within MS VC++. Kept in mind to be looked at later.

Conclusion: It seems like i'm creating a PHP Virtual Machine, similar to JVM. What do u think? I know it accomplishes the objective, but can it still be considered a true compiler?
Saturday, June 05, 2004
 
Creating a Win32 .obj file using NASM
1. Download NASM Windows binaries and the documentation.
2. Extract. Should end up with two files, nasmw.exe and ndisasmw.exe.
3. Put nasmw.exe in system directory.
4. Make a new Win32 Console Application project in Visual C++.
5. Put the files first.asm, asm_io.inc, asm_io.obj and driver.c into the project directory.
6. Add first.asm, driver.c, and asm_io.obj to your project.
7. In the file pane of Visual C++, right click on the first.asm file, and choose settings...
8. Bring up the Custom Build pane.
9. In the Commands window type nasmw.exe -f win32 -l first.lst first.asm
10.In the Outputs window type first.obj

* -f win32 command line option to nasmw.exe tells NASM to create a WIN32 .obj file from the .asm file
* -l first.lst command line option to nasmw.exe tells NASM to create a listing file as it is assembling -> first.lst for debugging.
 
Architecture
Posted by Hello

Thursday, June 03, 2004
 
The Plan
Did you know that deli france is an excellent place for ideas?! it's either that or the mint choc cake and frappes.

on the bytecode side of things this is wot u have to do
1. Make Win32 obj file
2. Use a existing Win32 Linker to make EXE



This would have been so easy to just tell u but since u're AWOL, these are the possible alternatives i see (BIG picture ofcourse)
1. bytecode ----> asm code ------>objcode [ a)using existing assembler b)build from scratch ]-------> executable code [Win32 Linker]

2. bytecode --------> target object code ( for this u might need to map bytecode to target machine instructions {only the compiler demon knows how you'd do that though, but my job is to suggest luckily & urs is to implement, unfortunately}

maybe approach 1. will aid approach 2.




 
Googling for PHP bytecode
I. Advanced PHP debugger
http://www.veoda.com/search/click/smartframe.cgi?http://www.php-library.com/pear_man/pecl.apd.html

II.PBC
http://pbc.sourceforge.net/

I wish u wouldn't fall asleep like that, um that is if u're not actually sick.

 
PHP bytecode Compiler

Cant make much sense of it...
Wednesday, June 02, 2004
 
Building PHP
Finally built PHP using Microsoft Visual C++ 6.0
Instructions from here.
It worked! <:o)
I built both the CGI and CLI versions in debug mode. So i managed to get some .obj files!! Which is a good thing.
But i'm not sure what to do with these files now... can't exactly read them.
Also have the list of files it went through when compiling the CLI... subject to availability, whether my comp is on or not!! If not, try my yahoo briefcase.
Tuesday, June 01, 2004
 
Compiling Zend!
compiling zend_language.scanner.c zend_language_parser.c

u have to have have all the files located in the Zend dir as well as the TSRM dir on the same level as the Zend dir.

I get as far as compiling to the stage where:
zend_language_scanner.l (165): error C2491: zend_save_lexical_state :definition of dllimport function not allowed
(few more errors of the similar nature are spewed out, varying only in terms of line number)

Now when it comes to the error, after googling, it seems that its a VC specific error.
After looking through MSDN i found Compiler Error C2491

So i figured i could probably change something in zend_language_scanner.l
Upon investgation of the specific line numbers (165,185,216,266,272,350,459) there lies a pattern... the prob seems to be in functions looking like

ZEND_API void zend_save_lexical_state(zend_lex_state *lex_state TSRMLS_DC)
{
memcpy(&lex_state->buffer_state, &YY_CURRENT_BUFFER, sizeof(YY_BUFFER_STATE));
lex_state->in = SCNG(yy_in);
lex_state->state = YYSTATE;
lex_state->filename = zend_get_compiled_filename(TSRMLS_C);
lex_state->lineno = CG(zend_lineno);
#ifdef ZEND_MULTIBYTE
lex_state->code = SCNG(code);
lex_state->code_size = SCNG(code_size);
lex_state->current_code = SCNG(current_code);
lex_state->current_code_size = SCNG(current_code_size);
lex_state->input_filter = SCNG(input_filter);
lex_state->output_filter = SCNG(output_filter);
lex_state->script_encoding = SCNG(script_encoding);
lex_state->internal_encoding = SCNG(internal_encoding);
#endif /* ZEND_MULTIBYTE */
}

So, ZEND_API must be defining the function as some sort of dllimport function. So comment out ZEND_API and recompile... Same errors. Tough Luck.

So maybe the problem is in the data type zend_lex_state, where is that defined? In none other than zend_language_scanner.h obviously... which looks fine... arrgghh...

Give up for now...


Powered by Blogger