Commit 37faa993 authored by daarond's avatar daarond

more debugging

parent 5e7f92ce
......@@ -48,8 +48,6 @@ Blockly.PHP.addReservedWords(
'__halt_compiler,abstract,and,array,as,break,callable,case,catch,class,clone,const,continue,declare,default,die,do,echo,else,elseif,empty,enddeclare,endfor,endforeach,endif,endswitch,endwhile,eval,exit,extends,final,for,foreach,function,global,goto,if,implements,include,include_once,instanceof,insteadof,interface,isset,list,namespace,new,or,print,private,protected,public,require,require_once,return,static,switch,throw,trait,try,unset,use,var,while,xor,' +
// http://php.net/manual/en/reserved.constants.php
'PHP_VERSION,PHP_MAJOR_VERSION,PHP_MINOR_VERSION,PHP_RELEASE_VERSION,PHP_VERSION_ID,PHP_EXTRA_VERSION,PHP_ZTS,PHP_DEBUG,PHP_MAXPATHLEN,PHP_OS,PHP_SAPI,PHP_EOL,PHP_INT_MAX,PHP_INT_SIZE,DEFAULT_INCLUDE_PATH,PEAR_INSTALL_DIR,PEAR_EXTENSION_DIR,PHP_EXTENSION_DIR,PHP_PREFIX,PHP_BINDIR,PHP_BINARY,PHP_MANDIR,PHP_LIBDIR,PHP_DATADIR,PHP_SYSCONFDIR,PHP_LOCALSTATEDIR,PHP_CONFIG_FILE_PATH,PHP_CONFIG_FILE_SCAN_DIR,PHP_SHLIB_SUFFIX,E_ERROR,E_WARNING,E_PARSE,E_NOTICE,E_CORE_ERROR,E_CORE_WARNING,E_COMPILE_ERROR,E_COMPILE_WARNING,E_USER_ERROR,E_USER_WARNING,E_USER_NOTICE,E_DEPRECATED,E_USER_DEPRECATED,E_ALL,E_STRICT,__COMPILER_HALT_OFFSET__,TRUE,FALSE,NULL,__CLASS__,__DIR__,__FILE__,__FUNCTION__,__LINE__,__METHOD__,__NAMESPACE__,__TRAIT__');
// there are more than 9,000 internal functions in http://php.net/manual/en/indexes.functions.php
// do we really need to list them here?
/**
* Order of operation ENUMs.
......@@ -58,6 +56,7 @@ Blockly.PHP.addReservedWords(
Blockly.PHP.ORDER_ATOMIC = 0; // 0 "" ...
Blockly.PHP.ORDER_CLONE = 1; // clone
Blockly.PHP.ORDER_NEW = 1; // new
Blockly.PHP.ORDER_MEMBER = 2; // ()
Blockly.PHP.ORDER_FUNCTION_CALL = 2; // ()
Blockly.PHP.ORDER_INCREMENT = 3; // ++
Blockly.PHP.ORDER_DECREMENT = 3; // --
......@@ -110,13 +109,14 @@ Blockly.PHP.init = function(workspace) {
Blockly.PHP.getDistinctName = function(name, type) {
var safeName = this.variableDB_.safeName_(name);
var i = '';
while (this.variableDB_.dbReverse_[safeName + i] ||
(safeName + i) in this.variableDB_.reservedDict_) {
while ((type == Blockly.Procedures.NAME_TYPE && (safeName + i) in this.variableDB_.reservedDict_)
|| this.variableDB_.dbReverse_[safeName + i]) {
// Collision with existing name. Create a unique name.
i = i ? i + 1 : 2;
}
safeName += i;
this.variableDB_.dbReverse_[safeName] = true;
if (type === Blockly.Procedures.NAME_TYPE) return safeName;
return '$' + safeName;
};
......
......@@ -64,7 +64,7 @@ Blockly.PHP['colour_rgb'] = function(block) {
' $hex .= str_pad(dechex($b), 2, "0", STR_PAD_LEFT);',
' return $hex;',
'}']);
var code = functionName + '($' + red + ', $' + green + ', $' + blue + ')';
var code = functionName + '(' + red + ', ' + green + ', ' + blue + ')';
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
};
......@@ -96,6 +96,6 @@ Blockly.PHP['colour_blend'] = function(block) {
' $hex .= str_pad(dechex($b), 2, "0", STR_PAD_LEFT);',
' return $hex;',
'}']);
var code = functionName + '($' + c1 + ', $' + c2 + ', $' + ratio + ')';
var code = functionName + '(' + c1 + ', ' + c2 + ', ' + ratio + ')';
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
};
......@@ -50,10 +50,10 @@ Blockly.PHP['lists_repeat'] = function(block) {
var functionName = Blockly.PHP.provideFunction_(
'lists_repeat',
[ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ +
'($value, $n) {',
'($value, $count) {',
' $array = array();',
' for ($i = 0; $i < $n; $i++) {',
' $array[i] = $value;',
' for ($index = 0; $index < $count; $index++) {',
' $array[] = $value;',
' }',
' return $array;',
'}']);
......@@ -69,14 +69,14 @@ Blockly.PHP['lists_length'] = function(block) {
// List length.
var argument0 = Blockly.PHP.valueToCode(block, 'VALUE',
Blockly.PHP.ORDER_FUNCTION_CALL) || '[]';
return ['count(' + argument0 + ')', Blockly.PHP.ORDER_MEMBER];
return ['count(' + argument0 + ')', Blockly.PHP.ORDER_FUNCTION_CALL];
};
Blockly.PHP['lists_isEmpty'] = function(block) {
// Is the list empty?
var argument0 = Blockly.PHP.valueToCode(block, 'VALUE',
Blockly.PHP.ORDER_MEMBER) || '[]';
return ['empty(' + argument0 + ')', Blockly.PHP.ORDER_LOGICAL_NOT];
Blockly.PHP.ORDER_FUNCTION_CALL) || '[]';
return ['empty(' + argument0 + ')', Blockly.PHP.ORDER_FUNCTION_CALL];
};
Blockly.PHP['lists_indexOf'] = function(block) {
......@@ -84,11 +84,11 @@ Blockly.PHP['lists_indexOf'] = function(block) {
var operator = block.getFieldValue('END') == 'FIRST' ?
'indexOf' : 'lastIndexOf';
var argument0 = Blockly.PHP.valueToCode(block, 'FIND',
Blockly.PHP.ORDER_NONE) || '\'\'';
Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
var argument1 = Blockly.PHP.valueToCode(block, 'VALUE',
Blockly.PHP.ORDER_MEMBER) || '[]';
Blockly.PHP.ORDER_FUNCTION_CALL) || '[]';
var code = argument1 + '.' + operator + '(' + argument0 + ') + 1';
return [code, Blockly.PHP.ORDER_MEMBER];
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
};
Blockly.PHP['lists_getIndex'] = function(block) {
......@@ -99,27 +99,27 @@ Blockly.PHP['lists_getIndex'] = function(block) {
var at = Blockly.PHP.valueToCode(block, 'AT',
Blockly.PHP.ORDER_UNARY_NEGATION) || '1';
var list = Blockly.PHP.valueToCode(block, 'VALUE',
Blockly.PHP.ORDER_MEMBER) || '[]';
Blockly.PHP.ORDER_FUNCTION_CALL) || '[]';
if (where == 'FIRST') {
if (mode == 'GET') {
var code = list + '[0]';
return [code, Blockly.PHP.ORDER_MEMBER];
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
} else if (mode == 'GET_REMOVE') {
var code = list + '.shift()';
return [code, Blockly.PHP.ORDER_MEMBER];
var code = 'array_shift(' + list + ', 1)';
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
} else if (mode == 'REMOVE') {
return list + '.shift();\n';
var code = 'array_shift(' + list + ', 1)';
}
} else if (where == 'LAST') {
if (mode == 'GET') {
var code = list + '.slice(-1)[0]';
return [code, Blockly.PHP.ORDER_MEMBER];
var code = 'end(' + list + ')';
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
} else if (mode == 'GET_REMOVE') {
var code = list + '.pop()';
return [code, Blockly.PHP.ORDER_MEMBER];
var code = 'array_pop(' + list + ')';
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
} else if (mode == 'REMOVE') {
return list + '.pop();\n';
return 'array_pop(' + list + ');\n';
}
} else if (where == 'FROM_START') {
// Blockly uses one-based indicies.
......@@ -132,24 +132,23 @@ Blockly.PHP['lists_getIndex'] = function(block) {
}
if (mode == 'GET') {
var code = list + '[' + at + ']';
return [code, Blockly.PHP.ORDER_MEMBER];
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
} else if (mode == 'GET_REMOVE') {
var code = list + '.splice(' + at + ', 1)[0]';
var code = 'array_splice(' + list + ', ' + at + ', 1)[0]';
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
} else if (mode == 'REMOVE') {
return list + '.splice(' + at + ', 1);\n';
return 'array_splice(' + list + ', ' + at + ', 1);\n';
}
} else if (where == 'FROM_END') {
if (mode == 'GET') {
var code = list + '.slice(-' + at + ')[0]';
var code = 'array_slice(' + list + ', -' + at + ', 1)[0]';
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
} else if (mode == 'GET_REMOVE' || mode == 'REMOVE') {
var functionName = Blockly.PHP.provideFunction_(
'lists_remove_from_end',
[ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ +
'(list, x) {',
' x = list.length - x;',
' return list.splice(x, 1)[0];',
'($list, $position) {',
' return array_splice($list, count($list) - $position, 1)[0];',
'}']);
code = functionName + '(' + list + ', ' + at + ')';
if (mode == 'GET_REMOVE') {
......@@ -162,13 +161,9 @@ Blockly.PHP['lists_getIndex'] = function(block) {
var functionName = Blockly.PHP.provideFunction_(
'lists_get_random_item',
[ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ +
'(list, remove) {',
' var x = Math.floor(Math.random() * list.length);',
' if (remove) {',
' return list.splice(x, 1)[0];',
' } else {',
' return list[x];',
' }',
'($list, $remove) {',
' $x = rand(0,count($list)-1);',
' return $remove ? array_splice($list, $x, 1)[0] : $list[$x];',
'}']);
code = functionName + '(' + list + ', ' + (mode != 'GET') + ')';
if (mode == 'GET' || mode == 'GET_REMOVE') {
......@@ -199,7 +194,7 @@ Blockly.PHP['lists_setIndex'] = function(block) {
}
var listVar = Blockly.PHP.getDistinctName(
'tmp_list', Blockly.Variables.NAME_TYPE);
var code = 'var ' + listVar + ' = ' + list + ';\n';
var code = listVar + ' = ' + list + ';\n';
list = listVar;
return code;
}
......@@ -207,15 +202,15 @@ Blockly.PHP['lists_setIndex'] = function(block) {
if (mode == 'SET') {
return list + '[0] = ' + value + ';\n';
} else if (mode == 'INSERT') {
return list + '.unshift(' + value + ');\n';
return 'array_unshift(' + list + ', ' + value + ');\n';
}
} else if (where == 'LAST') {
if (mode == 'SET') {
var code = cacheList();
code += list + '[' + list + '.length - 1] = ' + value + ';\n';
code += list + '[count(' + list + ') - 1] = ' + value + ';\n';
return code;
} else if (mode == 'INSERT') {
return list + '.push(' + value + ');\n';
return list + 'array_push(' + list + ', ' + value + ');\n';
}
} else if (where == 'FROM_START') {
// Blockly uses one-based indicies.
......@@ -229,29 +224,27 @@ Blockly.PHP['lists_setIndex'] = function(block) {
if (mode == 'SET') {
return list + '[' + at + '] = ' + value + ';\n';
} else if (mode == 'INSERT') {
return list + '.splice(' + at + ', 0, ' + value + ');\n';
return 'array_splice(' + list + ', ' + at + ', 0, ' + value + ');\n';
}
} else if (where == 'FROM_END') {
var code = cacheList();
if (mode == 'SET') {
code += list + '[' + list + '.length - ' + at + '] = ' + value + ';\n';
code += list + '[count(' + list + ') - ' + at + '] = ' + value + ';\n';
return code;
} else if (mode == 'INSERT') {
code += list + '.splice(' + list + '.length - ' + at + ', 0, ' + value +
');\n';
code += 'array_splice(' + list + ', count(' + list + ') - ' + at + ', 0, ' + value + ');\n';
return code;
}
} else if (where == 'RANDOM') {
var code = cacheList();
var xVar = Blockly.PHP.getDistinctName(
'tmp_x', Blockly.Variables.NAME_TYPE);
code += 'var ' + xVar + ' = Math.floor(Math.random() * ' + list +
'.length);\n';
code += xVar + ' = rand(0, count(' + list + ')-1);\n';
if (mode == 'SET') {
code += list + '[' + xVar + '] = ' + value + ';\n';
return code;
} else if (mode == 'INSERT') {
code += list + '.splice(' + xVar + ', 0, ' + value + ');\n';
code += 'array_splice(' + list + ', ' + xVar + ', 0, ' + value + ');\n';
return code;
}
}
......@@ -274,24 +267,29 @@ Blockly.PHP['lists_getSublist'] = function(block) {
var functionName = Blockly.PHP.provideFunction_(
'lists_get_sublist',
[ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ +
'(list, where1, at1, where2, at2) {',
' function getAt(where, at) {',
' if (where == \'FROM_START\') {',
' at--;',
' } else if (where == \'FROM_END\') {',
' at = list.length - at;',
' } else if (where == \'FIRST\') {',
' at = 0;',
' } else if (where == \'LAST\') {',
' at = list.length - 1;',
' } else {',
' throw \'Unhandled option (lists_getSublist).\';',
' }',
' return at;',
' }',
' at1 = getAt(where1, at1);',
' at2 = getAt(where2, at2) + 1;',
' return list.slice(at1, at2);',
'($list, $where1, $at1, $where2, $at2) {',
' if ($where1 == \'FROM_START\') {',
' $at1--;',
' } else if ($where1 == \'FROM_END\') {',
' $at1 = count($list) - $at1;',
' } else if ($where1 == \'FIRST\') {',
' $at1 = 0;',
' } else if ($where1 == \'LAST\') {',
' $at1 = count($list) - 1;',
' } else {',
' throw \'Unhandled option (lists_getSublist).\';',
' }',
' if ($where2 == \'FROM_START\') {',
' } else if ($where2 == \'FROM_END\') {',
' $at2 = count($list) - $at2;',
' } else if ($where2 == \'FIRST\') {',
' $at2 = 0;',
' } else if ($where2 == \'LAST\') {',
' $at2 = count($list);',
' } else {',
' throw \'Unhandled option (lists_getSublist).\';',
' }',
' return array_slice($list, $at1, $at2)[0];',
'}']);
var code = functionName + '(' + list + ', \'' +
where1 + '\', ' + at1 + ', \'' + where2 + '\', ' + at2 + ')';
......@@ -310,15 +308,15 @@ Blockly.PHP['lists_split'] = function(block) {
if (!value_input) {
value_input = '\'\'';
}
var functionName = 'split';
var functionName = 'explode';
} else if (mode == 'JOIN') {
if (!value_input) {
value_input = '[]';
}
var functionName = 'join';
var functionName = 'implode';
} else {
throw 'Unknown mode: ' + mode;
}
var code = value_input + '.' + functionName + '(' + value_delim + ')';
var code = functionName + '('+ value_delim + ', ' + value_input + ')';
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
};
......@@ -199,8 +199,7 @@ Blockly.PHP['math_change'] = function(block) {
Blockly.PHP.ORDER_ADDITION) || '0';
var varName = Blockly.PHP.getName(
block.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE);
return varName + ' = (typeof ' + varName + ' == \'number\' ? ' + varName +
' : 0) + ' + argument0 + ';\n';
return varName + ' += ' + argument0 + ';\n';
};
// Rounding functions have a single operand.
......@@ -215,17 +214,17 @@ Blockly.PHP['math_on_list'] = function(block) {
switch (func) {
case 'SUM':
list = Blockly.PHP.valueToCode(block, 'LIST',
Blockly.PHP.ORDER_MEMBER) || 'array()';
Blockly.PHP.ORDER_FUNCTION_CALL) || 'array()';
code = 'array_sum(' + list + ')';
break;
case 'MIN':
list = Blockly.PHP.valueToCode(block, 'LIST',
Blockly.PHP.ORDER_COMMA) || 'array()';
Blockly.PHP.ORDER_FUNCTION_CALL) || 'array()';
code = 'min(' + list + ')';
break;
case 'MAX':
list = Blockly.PHP.valueToCode(block, 'LIST',
Blockly.PHP.ORDER_COMMA) || 'array()';
Blockly.PHP.ORDER_FUNCTION_CALL) || 'array()';
code = 'max(' + list + ')';
break;
case 'AVERAGE':
......@@ -328,10 +327,7 @@ Blockly.PHP['math_random_int'] = function(block) {
[ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ +
'($a, $b) {',
' if ($a > $b) {',
' // Swap a and b to ensure a is smaller.',
' $c = $a;',
' $a = $b;',
' $b = $c;',
' return rand($b, $a);',
' }',
' return rand($a, $b);',
'}']);
......
......@@ -28,7 +28,6 @@ goog.provide('Blockly.PHP.procedures');
goog.require('Blockly.PHP');
Blockly.PHP['procedures_defreturn'] = function(block) {
// Define a procedure with a return value.
var funcName = Blockly.PHP.getName(
......
......@@ -69,7 +69,7 @@ Blockly.PHP['text_append'] = function(block) {
block.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE);
var argument0 = Blockly.PHP.valueToCode(block, 'TEXT',
Blockly.PHP.ORDER_NONE) || '\'\'';
return varName + ' = ' + varName + ' . ' + argument0 + ';\n';
return varName + ' .= ' + argument0 + ';\n';
};
Blockly.PHP['text_length'] = function(block) {
......@@ -82,7 +82,7 @@ Blockly.PHP['text_length'] = function(block) {
Blockly.PHP['text_isEmpty'] = function(block) {
// Is the string null?
var argument0 = Blockly.PHP.valueToCode(block, 'VALUE',
Blockly.PHP.ORDER_MEMBER) || '\'\'';
Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
return ['empty(' + argument0 + ')', Blockly.PHP.ORDER_FUNCTION_CALL];
};
......@@ -91,20 +91,20 @@ Blockly.PHP['text_indexOf'] = function(block) {
var operator = block.getFieldValue('END') == 'FIRST' ?
'strpos' : 'strrpos';
var argument0 = Blockly.PHP.valueToCode(block, 'FIND',
Blockly.PHP.ORDER_NONE) || '\'\'';
Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
var argument1 = Blockly.PHP.valueToCode(block, 'VALUE',
Blockly.PHP.ORDER_MEMBER) || '\'\'';
Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
var code = operator + '(' + argument0 + ', ' + argument1 + ') + 1';
return [code, Blockly.PHP.ORDER_MEMBER];
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
};
Blockly.PHP['text_charAt'] = function(block) {
// Get letter at index.
var where = block.getFieldValue('WHERE') || 'FROM_START';
var at = Blockly.PHP.valueToCode(block, 'AT',
Blockly.PHP.ORDER_UNARY_NEGATION) || '1';
Blockly.PHP.ORDER_FUNCTION_CALL) || '0';
var text = Blockly.PHP.valueToCode(block, 'VALUE',
Blockly.PHP.ORDER_MEMBER) || '\'\'';
Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
switch (where) {
case 'FIRST':
var code = text + '[0]';
......@@ -142,13 +142,13 @@ Blockly.PHP['text_charAt'] = function(block) {
Blockly.PHP['text_getSubstring'] = function(block) {
// Get substring.
var text = Blockly.PHP.valueToCode(block, 'STRING',
Blockly.PHP.ORDER_MEMBER) || '\'\'';
Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
var where1 = block.getFieldValue('WHERE1');
var where2 = block.getFieldValue('WHERE2');
var at1 = Blockly.PHP.valueToCode(block, 'AT1',
Blockly.PHP.ORDER_NONE) || '1';
Blockly.PHP.ORDER_FUNCTION_CALL) || '0';
var at2 = Blockly.PHP.valueToCode(block, 'AT2',
Blockly.PHP.ORDER_NONE) || '1';
Blockly.PHP.ORDER_FUNCTION_CALL) || '0';
if (where1 == 'FIRST' && where2 == 'LAST') {
var code = text;
} else {
......@@ -159,23 +159,20 @@ Blockly.PHP['text_getSubstring'] = function(block) {
' if ($where1 == \'FROM_START\') {',
' $at1--;',
' } else if ($where1 == \'FROM_END\') {',
' $at1 = strlen($text) - $at;',
' $at1 = strlen($text) - $at1;',
' } else if ($where1 == \'FIRST\') {',
' $at1 = 0;',
' } else if (where1 == \'LAST\') {',
' } else if ($where1 == \'LAST\') {',
' $at1 = strlen($text) - 1;',
' } else { $at1 = 0; }',
' if ($where2 == \'FROM_START\') {',
' $at2--;',
' } else if ($where2 == \'FROM_END\') {',
' $at2 = strlen($text) - $at;',
' $at2 = strlen($text) - $at2;',
' } else if ($where2 == \'FIRST\') {',
' $at2 = 0;',
' } else if (where2 == \'LAST\') {',
' $at2 = strlen($text) - 1;',
' } else if ($where2 == \'LAST\') {',
' $at2 = strlen($text);',
' } else { $at2 = 0; }',
' $at1 = getAt($where1, $at1);',
' $at2 = getAt($where2, $at2) + 1;',
' return substr($text, $at1, $at2);',
'}']);
var code = functionName + '(' + text + ', \'' +
......@@ -189,15 +186,15 @@ Blockly.PHP['text_changeCase'] = function(block) {
var code;
if (block.getFieldValue('CASE')=='UPPERCASE') {
var argument0 = Blockly.PHP.valueToCode(block, 'TEXT',
Blockly.PHP.ORDER_MEMBER) || '\'\'';
Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
code = 'strtoupper(' + argument0 + ')';
} else if (block.getFieldValue('CASE')=='LOWERCASE') {
var argument0 = Blockly.PHP.valueToCode(block, 'TEXT',
Blockly.PHP.ORDER_MEMBER) || '\'\'';
Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
code = 'strtolower(' + argument0 + ')';
} else if (block.getFieldValue('CASE')=='TITLECASE') {
var argument0 = Blockly.PHP.valueToCode(block, 'TEXT',
Blockly.PHP.ORDER_MEMBER) || '\'\'';
Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
code = 'ucwords(' + argument0 + ')';
}
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
......@@ -212,14 +209,14 @@ Blockly.PHP['text_trim'] = function(block) {
};
var operator = OPERATORS[block.getFieldValue('MODE')];
var argument0 = Blockly.PHP.valueToCode(block, 'TEXT',
Blockly.PHP.ORDER_MEMBER) || '\'\'';
return [ operator + '(' + argument0 + ')', Blockly.PHP.ORDER_FUNCTION_CALL];
Blockly.PHP.ORDER_ATOMIC) || '\'\'';
return [ operator + '(' + argument0 + ')', Blockly.PHP.ORDER_ATOMIC];
};
Blockly.PHP['text_print'] = function(block) {
// Print statement.
var argument0 = Blockly.PHP.valueToCode(block, 'TEXT',
Blockly.PHP.ORDER_NONE) || '\'\'';
Blockly.PHP.ORDER_FUNCTION_CALL) || '\'\'';
return 'print(' + argument0 + ');\n';
};
......@@ -231,17 +228,17 @@ Blockly.PHP['text_prompt'] = function(block) {
if (toNumber) {
code = 'floatval(' + code + ')';
}
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
return [code, Blockly.PHP.ORDER_ATOMIC];
};
Blockly.PHP['text_prompt_ext'] = function(block) {
// Prompt function (external message).
var msg = Blockly.PHP.valueToCode(block, 'TEXT',
Blockly.PHP.ORDER_NONE) || '\'\'';
Blockly.PHP.ORDER_ATOMIC) || '\'\'';
var code = 'readline(' + msg + ')';
var toNumber = block.getFieldValue('TYPE') == 'NUMBER';
if (toNumber) {
code = 'floatval(' + code + ')';
}
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
return [code, Blockly.PHP.ORDER_ATOMIC];
};
......@@ -39,7 +39,7 @@ Blockly.PHP['variables_set'] = function(block) {
// Variable setter.
var argument0 = Blockly.PHP.valueToCode(block, 'VALUE',
Blockly.PHP.ORDER_ASSIGNMENT) || '0';
var varName = Blockly.PHP.variableDB_.getName(
var varName = Blockly.PHP.getName(
block.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE);
return '$' + varName + ' = ' + argument0 + ';\n';
return varName + ' = ' + argument0 + ';\n';
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment