Permalink
Browse files

Fixed division using double, returning double from zephir_floor

  • Loading branch information...
andresgutierrez committed Apr 9, 2015
1 parent 775f74b commit fd7f8db25595b7878f488c13ad1c780e83cfa54b
@@ -412,6 +412,15 @@ public function compile($expression, CompilationContext $compilationContext)
}
break;
case 'double':
$compilationContext->headersManager->add('kernel/operators');
if ($variableLeft->isLocalOnly()) {
return new CompiledExpression('double', 'zephir_safe_div_zval_double(&' . $variableLeft->getName() . ', ' . $variableRight->getName() . ' TSRMLS_CC)', $expression);
} else {
return new CompiledExpression('double', 'zephir_safe_div_zval_double(' . $variableLeft->getName() . ', ' . $variableRight->getName() . ' TSRMLS_CC)', $expression);
}
break;
/* a(var) + a(bool) */
case 'bool':
$compilationContext->headersManager->add('kernel/operators');
@@ -508,6 +517,15 @@ public function compile($expression, CompilationContext $compilationContext)
}
break;
case 'double':
$compilationContext->headersManager->add('kernel/operators');
if ($variableLeft->isLocalOnly()) {
return new CompiledExpression('double', 'zephir_safe_div_zval_double(&' . $variableLeft->getName() . ', ' . $variableRight->getName() . ' TSRMLS_CC)', $expression);
} else {
return new CompiledExpression('double', 'zephir_safe_div_zval_double(' . $variableLeft->getName() . ', ' . $variableRight->getName() . ' TSRMLS_CC)', $expression);
}
break;
case 'bool':
$compilationContext->headersManager->add('kernel/operators');
if ($variableLeft->isLocalOnly()) {
@@ -49,25 +49,9 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
return false;
}
/**
* Process the expected symbol to be returned
*/
$call->processExpectedReturn($context);
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->headersManager->add('kernel/operators');
$symbolVariable->setDynamicTypes('double');
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
$context->codePrinter->output('zephir_floor(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ' TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
return new CompiledExpression('double', 'zephir_floor(' . $resolvedParams[0] . ' TSRMLS_CC)', $expression);
}
}
@@ -89,6 +89,54 @@ void zephir_concat_sssssss(zval **result, const char *op1, zend_uint op1_len, co
}
void zephir_concat_ssv(zval **result, const char *op1, zend_uint op1_len, const char *op2, zend_uint op2_len, zval *op3, int self_var TSRMLS_DC){
zval result_copy, op3_copy;
int use_copy = 0, use_copy3 = 0;
uint offset = 0, length;
if (Z_TYPE_P(op3) != IS_STRING) {
zend_make_printable_zval(op3, &op3_copy, &use_copy3);
if (use_copy3) {
op3 = &op3_copy;
}
}
length = op1_len + op2_len + Z_STRLEN_P(op3);
if (self_var) {
if (Z_TYPE_PP(result) != IS_STRING) {
zend_make_printable_zval(*result, &result_copy, &use_copy);
if (use_copy) {
ZEPHIR_CPY_WRT_CTOR(*result, (&result_copy));
}
}
offset = Z_STRLEN_PP(result);
length += offset;
Z_STRVAL_PP(result) = (char *) str_erealloc(Z_STRVAL_PP(result), length + 1);
} else {
Z_STRVAL_PP(result) = (char *) emalloc(length + 1);
}
memcpy(Z_STRVAL_PP(result) + offset, op1, op1_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len, op2, op2_len);
memcpy(Z_STRVAL_PP(result) + offset + op1_len + op2_len, Z_STRVAL_P(op3), Z_STRLEN_P(op3));
Z_STRVAL_PP(result)[length] = 0;
Z_TYPE_PP(result) = IS_STRING;
Z_STRLEN_PP(result) = length;
if (use_copy3) {
zval_dtor(op3);
}
if (use_copy) {
zval_dtor(&result_copy);
}
}
void zephir_concat_sv(zval **result, const char *op1, zend_uint op1_len, zval *op2, int self_var TSRMLS_DC){
zval result_copy, op2_copy;
@@ -15,6 +15,11 @@
#define ZEPHIR_SCONCAT_SSSSSSS(result, op1, op2, op3, op4, op5, op6, op7) \
zephir_concat_sssssss(&result, op1, sizeof(op1)-1, op2, sizeof(op2)-1, op3, sizeof(op3)-1, op4, sizeof(op4)-1, op5, sizeof(op5)-1, op6, sizeof(op6)-1, op7, sizeof(op7)-1, 1 TSRMLS_CC);
#define ZEPHIR_CONCAT_SSV(result, op1, op2, op3) \
zephir_concat_ssv(&result, op1, sizeof(op1)-1, op2, sizeof(op2)-1, op3, 0 TSRMLS_CC);
#define ZEPHIR_SCONCAT_SSV(result, op1, op2, op3) \
zephir_concat_ssv(&result, op1, sizeof(op1)-1, op2, sizeof(op2)-1, op3, 1 TSRMLS_CC);
#define ZEPHIR_CONCAT_SV(result, op1, op2) \
zephir_concat_sv(&result, op1, sizeof(op1)-1, op2, 0 TSRMLS_CC);
#define ZEPHIR_SCONCAT_SV(result, op1, op2) \
@@ -43,6 +48,7 @@
void zephir_concat_ss(zval **result, const char *op1, zend_uint op1_len, const char *op2, zend_uint op2_len, int self_var TSRMLS_DC);
void zephir_concat_sssssss(zval **result, const char *op1, zend_uint op1_len, const char *op2, zend_uint op2_len, const char *op3, zend_uint op3_len, const char *op4, zend_uint op4_len, const char *op5, zend_uint op5_len, const char *op6, zend_uint op6_len, const char *op7, zend_uint op7_len, int self_var TSRMLS_DC);
void zephir_concat_ssv(zval **result, const char *op1, zend_uint op1_len, const char *op2, zend_uint op2_len, zval *op3, int self_var TSRMLS_DC);
void zephir_concat_sv(zval **result, const char *op1, zend_uint op1_len, zval *op2, int self_var TSRMLS_DC);
void zephir_concat_svs(zval **result, const char *op1, zend_uint op1_len, zval *op2, const char *op3, zend_uint op3_len, int self_var TSRMLS_DC);
void zephir_concat_vs(zval **result, zval *op1, const char *op2, zend_uint op2_len, int self_var TSRMLS_DC);
@@ -893,17 +893,17 @@ double zephir_safe_div_double_zval(double op1, zval *op2 TSRMLS_DC) {
return op1 / ((double) zephir_get_numberval(op2));
}
void zephir_floor(zval *return_value, zval *op1 TSRMLS_DC)
double zephir_floor(zval *op1 TSRMLS_DC)
{
convert_scalar_to_number_ex(&op1);
if (Z_TYPE_PP(&op1) == IS_DOUBLE) {
RETURN_DOUBLE(floor(Z_DVAL_PP(&op1)));
return floor(Z_DVAL_PP(&op1));
} else if (Z_TYPE_PP(&op1) == IS_LONG) {
convert_to_double_ex(&op1);
RETURN_DOUBLE(Z_DVAL_PP(&op1));
return Z_DVAL_PP(&op1);
}
RETURN_FALSE;
return 0;
}
/**
@@ -166,7 +166,7 @@ long zephir_safe_mod_zval_double(zval *op1, double op2 TSRMLS_DC);
long zephir_safe_mod_long_zval(long op1, zval *op2 TSRMLS_DC);
long zephir_safe_mod_double_zval(double op1, zval *op2 TSRMLS_DC);
void zephir_floor(zval *return_value, zval *op1 TSRMLS_DC);
double zephir_floor(zval *op1 TSRMLS_DC);
void zephir_ceil(zval *return_value, zval *op1 TSRMLS_DC);
void zephir_round(zval *return_value, zval *op1, zval *op2, zval *op3 TSRMLS_DC);
void zephir_pow(zval *return_value, zval *op1, zval *op2 TSRMLS_DC);
@@ -14,7 +14,7 @@
#define PHP_TEST_VERSION "1.0.0"
#define PHP_TEST_EXTNAME "test"
#define PHP_TEST_AUTHOR "Zephir Team and contributors"
#define PHP_TEST_ZEPVERSION "0.6.1a"
#define PHP_TEST_ZEPVERSION "0.6.2a"
#define PHP_TEST_DESCRIPTION "Description test for<br/>Test Extension"
typedef struct _zephir_struct_test {

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -7,9 +7,9 @@ namespace Test;
class Assign
{
protected testVar {get};
protected testVar { get };
protected myArray {get};
protected myArray { get };
protected static testVarStatic;
@@ -17,14 +17,29 @@ class Concat
public function testConcat1()
{
var url;
let url = "test";
let url = "append" . url;
return url;
}
public function testConcat10()
public function testConcat2()
{
var url;
let url = "test";
let url = "append" . url;
let url = "append" . url . "other";
let url = "append" . "other";
let url = "append" . "other" . url;
return url;
}
public function testConcatSelf1()
{
var url = "";
let url .= "test";
let url .= "append" . url . "other";
let url .= "append" . "other";
let url .= "append" . "other" . url;
return url;
}
}
}
@@ -86,7 +86,6 @@ class Constants extends ConstantsParent
{
var a;
let a = PHP_VERSION;
return a;
}
}

0 comments on commit fd7f8db

Please sign in to comment.