Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ce054e1

Browse files
committed
clean up
1 parent ad2d3af commit ce054e1

File tree

28 files changed

+3597
-4147
lines changed

28 files changed

+3597
-4147
lines changed

‎PHP.js

Lines changed: 1832 additions & 2013 deletions
Large diffs are not rendered by default.

‎src/compiler/expr.js

Lines changed: 73 additions & 76 deletions
Large diffs are not rendered by default.

‎src/compiler/stmt.js

Lines changed: 139 additions & 147 deletions
Large diffs are not rendered by default.

‎src/core.js

Lines changed: 90 additions & 90 deletions
Large diffs are not rendered by default.

‎src/modules/control_structures/foreach.js

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/*
2-
* @author Niklas von Hertzen <niklas at hertzen.com>
3-
* @created 30.6.2012
4-
* @website http://hertzen.com
5-
*/
61
PHP.Modules.prototype.$foreachInit = function( expr, ctx ) {
72

83
var COMPILER = PHP.Compiler.prototype,
@@ -30,14 +25,14 @@ PHP.Modules.prototype.$foreachInit = function( expr, ctx ) {
3025
if ( objectValue[ PHP.VM.Class.INTERFACES ].indexOf("Traversable") !== -1 ) {
3126

3227
var iterator = objectValue;
33-
28+
3429
try {
3530
while( (iterator instanceof PHP.VM.ClassPrototype) && iterator[ PHP.VM.Class.INTERFACES ].indexOf("Iterator") === -1 ) {
36-
iterator = iterator[ COMPILER.METHOD_CALL ]( this, "getIterator" )[ COMPILER.VARIABLE_VALUE ];
31+
iterator = iterator[ COMPILER.METHOD_CALL ]( this, "getIterator" )[ COMPILER.VARIABLE_VALUE ];
3732
}
3833
}catch(e) {
39-
40-
}
34+
35+
}
4136
if ( !(iterator instanceof PHP.VM.ClassPrototype) || iterator[ PHP.VM.Class.INTERFACES ].indexOf("Iterator") === -1) {
4237
this[ COMPILER.ERROR ]( "Objects returned by " + objectValue[ COMPILER.CLASS_NAME ] + "::getIterator() must be traversable or implement interface Iterator", PHP.Constants.E_ERROR, true );
4338
return;
@@ -62,28 +57,28 @@ PHP.Modules.prototype.$foreachInit = function( expr, ctx ) {
6257

6358
needReorder = false;
6459
for (var key in objectValue) {
65-
60+
6661
if ( key.substring(0, classProperty.length ) === classProperty) {
67-
62+
6863
var name = key.substring( classProperty.length );
69-
64+
7065
if (PHP.Utils.Visible.call( this, name, objectValue, ctx )) {
7166
items.push( name );
7267
}
7368

7469
}
75-
70+
7671
if (((objectValue[ PHP.VM.Class.PROPERTY_TYPE + name ] & PHP.VM.Class.PUBLIC) === PHP.VM.Class.PUBLIC) || objectValue[ PHP.VM.Class.PROPERTY_TYPE + name ] === undefined) {
7772

78-
73+
7974
} else {
8075
needReorder = true;
8176
}
8277
}
8378
if ( needReorder ) {
84-
items.sort();
79+
items.sort();
8580
}
86-
81+
8782
return items;
8883
}.bind(this))( objectValue )
8984

@@ -125,52 +120,25 @@ PHP.Modules.prototype.foreach = function( iterator, byRef, value, key ) {
125120
}
126121

127122
if ( expr[ VAR.TYPE ] === VAR.ARRAY ) {
128-
129-
130-
131-
/*
132-
if ( iterator.expr[ VAR.IS_REF ] !== true ) {
133-
expr = iterator.clone;
134-
} else {
135-
expr = expr[ COMPILER.VARIABLE_VALUE ];
136-
}
137-
*/
138123
var clonedValues = iterator.clone[ PHP.VM.Class.PROPERTY + ARRAY.VALUES ][ COMPILER.VARIABLE_VALUE ],
139124
clonedKeys = iterator.clone[ PHP.VM.Class.PROPERTY + ARRAY.KEYS ][ COMPILER.VARIABLE_VALUE ],
140125
origValues = expr[ COMPILER.VARIABLE_VALUE ][ PHP.VM.Class.PROPERTY + ARRAY.VALUES ][ COMPILER.VARIABLE_VALUE ],
141126
origKeys = expr[ COMPILER.VARIABLE_VALUE ][ PHP.VM.Class.PROPERTY + ARRAY.KEYS ][ COMPILER.VARIABLE_VALUE ],
142127
len = ( byRef === true || iterator.expr[ VAR.IS_REF ] === true ) ? origValues.length : iterator.len,
143128
pointer = (( byRef === true || iterator.expr[ VAR.IS_REF ] === true) ? expr[ COMPILER.VARIABLE_VALUE ] : iterator.clone )[ PHP.VM.Class.PROPERTY + ARRAY.POINTER];
144129

145-
146-
// clean unset elements off array
147-
/*
148-
if ( byRef === true ) {
149-
origValues.forEach(function( variable, index ) {
150-
if ( variable[ VAR.DEFINED ] !== true ) {
151-
origValues.splice( index, 1 );
152-
origKeys.splice( index, 1 );
153-
console.log(origValues);
154-
}
155-
});
156-
}*/
157-
158130
var compareTo = (byRef === true || iterator.expr[ VAR.IS_REF ] === true) ? origValues : clonedValues,
159131
result;
160132

161-
162133
var index, lowerLoop = function( index ) {
163134
while( compareTo [ --index ] === undefined && index > 0 ) {}
164135
return index;
165136
}
166137

167-
168138
if ( iterator.breakNext === true) {
169-
170139
return false;
171140
}
172141

173-
174142
if ( pointer[ COMPILER.VARIABLE_VALUE ] !== iterator.count ) {
175143
if ( iterator.last !== undefined && iterator.last !== compareTo [ pointer[ COMPILER.VARIABLE_VALUE ] ] ) {
176144
index = pointer[ COMPILER.VARIABLE_VALUE ];
@@ -293,15 +261,9 @@ PHP.Modules.prototype.foreach = function( iterator, byRef, value, key ) {
293261
return true;
294262
}
295263
return false;
296-
297264
}
298-
299-
300265
} else {
301266
this[ COMPILER.ERROR ]( "Invalid argument supplied for foreach()", PHP.Constants.E_CORE_WARNING, true );
302267
return false;
303268
}
304-
305-
306-
307269
};

‎src/modules/control_structures/include.js

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,44 @@
1-
/*
2-
* @author Niklas von Hertzen <niklas at hertzen.com>
3-
* @created 3.7.2012
4-
* @website http://hertzen.com
5-
*/
6-
71
PHP.Modules.prototype.$include = function( $, $Static, file ) {
8-
2+
93
var COMPILER = PHP.Compiler.prototype,
104
filename = file[ COMPILER.VARIABLE_VALUE ];
11-
12-
5+
6+
137
var path = this[ COMPILER.FILE_PATH ];
14-
15-
8+
9+
1610
var loaded_file = (/^(.:|\/)/.test( filename ) ) ? filename : path + "/" + filename;
1711
var $this = this;
1812
this.$Included.Include( loaded_file );
1913
try {
2014
var source = this[ COMPILER.FILESYSTEM ].readFileSync( loaded_file );
2115
}
2216
catch( e ) {
23-
17+
2418
$this.ENV[ COMPILER.ERROR ]("include(" + filename + "): failed to open stream: No such file or directory", PHP.Constants.E_CORE_WARNING, true );
25-
$this.ENV[ COMPILER.ERROR ]("include(): Failed opening '" + filename + "' for inclusion (include_path='" + path + "')", PHP.Constants.E_CORE_WARNING, true );
19+
$this.ENV[ COMPILER.ERROR ]("include(): Failed opening '" + filename + "' for inclusion (include_path='" + path + "')", PHP.Constants.E_CORE_WARNING, true );
2620
}
27-
21+
2822
var COMPILER = PHP.Compiler.prototype;
29-
23+
3024
// tokenizer
3125
var tokens = new PHP.Lexer( source );
32-
26+
3327
// build ast tree
34-
28+
3529
var AST = new PHP.Parser( tokens );
36-
30+
3731
// compile tree into JS
3832
var compiler = new PHP.Compiler( AST );
39-
40-
console.log( compiler.src );
33+
4134
// execture code in current context ($)
4235
var exec = new Function( "$$", "$", "ENV", "$Static", compiler.src );
43-
36+
4437
this[ COMPILER.FILE_PATH ] = PHP.Utils.Path( loaded_file );
4538

4639
exec.call(this, function( arg ) {
4740
return new PHP.VM.Variable( arg );
4841
}, $, this, $Static);
49-
/*
50-
this needs to be fixed
51-
console.log("changing back");
52-
this[ COMPILER.FILE_PATH ] = path;
53-
*/
5442
};
5543

5644

‎src/modules/filesystem/dirname.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
/*
2-
* @author Niklas von Hertzen <niklas at hertzen.com>
3-
* @created 12.7.2012
4-
* @website http://hertzen.com
5-
*/
6-
7-
8-
91
PHP.Modules.prototype.dirname = function( path ) {
102
var COMPILER = PHP.Compiler.prototype,
113
dir = PHP.Utils.Path( path[ COMPILER.VARIABLE_VALUE ] )
12-
console.log( dir, path );
134
return new PHP.VM.Variable( dir );
145
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /