[phc-internals] [phc commit] r1814 - in trunk: src/codegen src/process_ast test/subjects/codegen

codesite-noreply at google.com codesite-noreply at google.com
Sat Oct 25 20:00:23 IST 2008


Author: paul.biggar
Date: Sat Oct 25 11:59:34 2008
New Revision: 1814

Added:
    trunk/test/subjects/codegen/real_representation.php
Modified:
    trunk/src/codegen/Generate_C.cpp
    trunk/src/process_ast/Strip_unparser_attributes.cpp
    trunk/src/process_ast/Strip_unparser_attributes.h

Log:
Remove the phc.codegen.source_rep attribute, and replace run-time parsing  
of double values with creating a representation in the generated C code. We  
weren't sure how to do this, which is why the source_rep hack was still in  
place. This fixes the tests that failed as a result of having no source_rep.


Modified: trunk/src/codegen/Generate_C.cpp
==============================================================================
--- trunk/src/codegen/Generate_C.cpp	(original)
+++ trunk/src/codegen/Generate_C.cpp	Sat Oct 25 11:59:34 2008
@@ -1081,7 +1081,7 @@

  				prologue << "zval* " << var << ";\n";
  				finalizations << "zval_ptr_dtor (&" << var << ");\n";
-				initializations << "ALLOC_INIT_ZVAL (" << var << ")\n";
+				initializations << "ALLOC_INIT_ZVAL (" << var << ");\n";
  				initialize (initializations, var);
  			}
  			code
@@ -1126,16 +1126,25 @@
  	}
  };

-class Pattern_assign_lit_real : public Pattern_assign_literal<REAL, string>
+class Pattern_assign_lit_real : public Pattern_assign_literal<REAL, double>
  {
  	string prefix () { return "phc_const_pool_real_"; }
-	string key () { return  
*(dynamic_cast<String*>(rhs->value->attrs->get("phc.codegen.source_rep")));  
}
+	double key () { return rhs->value->value; }

  	void initialize (ostream& os, string var)
  	{
-		os	<< "zend_eval_string(\"" << key() << ";\","
-			<<		var << ", "
-			<<		"\"literal\" TSRMLS_CC);\n";
+		os << "{\n";
+		// Construct the value a byte at a time from our representation in  
memory.
+		unsigned char* values_bytes = (unsigned char*)(&rhs->value->value);
+		os << "unsigned char val[] = {";
+		for (unsigned int i = 0; i < sizeof (double); i++)
+		{
+			os << (unsigned int)(values_bytes[i]) << ", ";
+		}
+		os << "};\n";
+
+		os << "ZVAL_DOUBLE (" << var << ", *(double*)(val));\n";
+		os << "}\n";
  	}
  };


Modified: trunk/src/process_ast/Strip_unparser_attributes.cpp
==============================================================================
--- trunk/src/process_ast/Strip_unparser_attributes.cpp	(original)
+++ trunk/src/process_ast/Strip_unparser_attributes.cpp	Sat Oct 25 11:59:34  
2008
@@ -9,12 +9,6 @@

  using namespace AST;

-void Strip_unparser_attributes::pre_real (REAL* in)
-{
-	// we need the source_rep for codegen for REALs.
-	in->attrs->set ("phc.codegen.source_rep", in->attrs->get  
("phc.unparser.source_rep"));
-}
-
  void Strip_unparser_attributes::post_node (Node* in)
  {
  	in->attrs->erase_with_prefix ("phc.unparser");

Modified: trunk/src/process_ast/Strip_unparser_attributes.h
==============================================================================
--- trunk/src/process_ast/Strip_unparser_attributes.h	(original)
+++ trunk/src/process_ast/Strip_unparser_attributes.h	Sat Oct 25 11:59:34  
2008
@@ -12,7 +12,6 @@

  class Strip_unparser_attributes : public virtual AST::Visitor, virtual  
public GC_obj
  {
-	void pre_real (AST::REAL* in);
  	void post_node (AST::Node* in);
  };


Added: trunk/test/subjects/codegen/real_representation.php
==============================================================================
--- (empty file)
+++ trunk/test/subjects/codegen/real_representation.php	Sat Oct 25 11:59:34  
2008
@@ -0,0 +1,25 @@
+<?php
+
+	// For this, I generally searched for examples of floats people had  
problems with.
+
+	var_dump (0.1);
+	var_dump (0.98);
+	var_dump (0.98 * 4.56);
+
+	var_dump (10.1 + 10.1 +10.1 +10.1 +10.1 +10.1 +10.1 +10.1 +10.1 +10.1  
+10.1 +10.1 +10.1);
+
+	var_dump (0.000000010, 0.000010000, 100000000.0, 300000000.0);
+
+	var_dump (1/5);
+	var_dump (1/3);
+	var_dump (1/10);
+
+	var_dump (5 - 3/4);
+	var_dump (2 - 7/8);
+	var_dump (5 - 3/4);
+	var_dump (63/64);
+
+	var_dump (1.2349999);
+	var_dump (1.2350001);
+	var_dump (1.2350000);
+?>


More information about the phc-internals mailing list