[pure-lang-svn] SF.net SVN: pure-lang:[817] pure/trunk
Status: Beta
Brought to you by:
agraef
|
From: <ag...@us...> - 2008-09-21 12:42:44
|
Revision: 817
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=817&view=rev
Author: agraef
Date: 2008-09-21 12:42:34 +0000 (Sun, 21 Sep 2008)
Log Message:
-----------
Eliminate broken complex number marshalling support. No easy way to make this work.
Modified Paths:
--------------
pure/trunk/interpreter.cc
pure/trunk/interpreter.hh
pure/trunk/runtime.cc
pure/trunk/runtime.h
Modified: pure/trunk/interpreter.cc
===================================================================
--- pure/trunk/interpreter.cc 2008-09-21 07:44:02 UTC (rev 816)
+++ pure/trunk/interpreter.cc 2008-09-21 12:42:34 UTC (rev 817)
@@ -133,7 +133,9 @@
// Complex numbers (complex double).
{
std::vector<const Type*> elts;
- elts.push_back(ArrayType::get(Type::DoubleTy, 2));
+ //elts.push_back(ArrayType::get(Type::DoubleTy, 2));
+ elts.push_back(Type::DoubleTy);
+ elts.push_back(Type::DoubleTy);
ComplexTy = StructType::get(elts);
ComplexPtrTy = PointerType::get(ComplexTy, 0);
}
@@ -375,16 +377,6 @@
declare_extern((void*)pure_get_matrix,
"pure_get_matrix", "void*", 1, "expr*");
-#if COMPLEX_NUMBERS
- /* Marshalling of complex numbers. This doesn't work yet and is disabled. */
- declare_extern((void*)pure_complex,
- "pure_complex", "expr*", 1, "complex");
- declare_extern((void*)pure_is_complex,
- "pure_is_complex", "bool", 1, "expr*");
- declare_extern((void*)pure_get_complex,
- "pure_get_complex", "complex", 1, "expr*");
-#endif
-
declare_extern((void*)pure_catch,
"pure_catch", "expr*", 2, "expr*", "expr*");
declare_extern((void*)pure_throw,
@@ -3673,10 +3665,6 @@
return Type::FloatTy;
else if (name == "double")
return Type::DoubleTy;
-#if COMPLEX_NUMBERS
- else if (name == "complex")
- return ComplexTy;
-#endif
else if (name == "char*")
return CharPtrTy;
else if (name == "short*")
@@ -3687,10 +3675,6 @@
return PointerType::get(Type::Int64Ty, 0);
else if (name == "double*")
return PointerType::get(Type::DoubleTy, 0);
-#if COMPLEX_NUMBERS
- else if (name == "complex*")
- return ComplexPtrTy;
-#endif
else if (name == "expr*")
return ExprPtrTy;
else if (name == "expr**")
@@ -3730,10 +3714,6 @@
return "float";
else if (type == Type::DoubleTy)
return "double";
-#if COMPLEX_NUMBERS
- else if (type == ComplexTy)
- return "complex";
-#endif
else if (type == CharPtrTy)
return "char*";
else if (type == PointerType::get(Type::Int16Ty, 0))
@@ -3744,10 +3724,6 @@
return "long*";
else if (type == PointerType::get(Type::DoubleTy, 0))
return "double*";
-#if COMPLEX_NUMBERS
- else if (type == ComplexPtrTy)
- return "complex*";
-#endif
else if (type == ExprPtrTy)
return "expr*";
else if (type == ExprPtrPtrTy)
@@ -4093,19 +4069,6 @@
idx[1] = ValFldIndex;
Value *dv = b.CreateLoad(b.CreateGEP(pv, idx, idx+2), "dblval");
unboxed[i] = dv;
-#if COMPLEX_NUMBERS
- } else if (argt[i] == ComplexTy) {
- BasicBlock *okbb = BasicBlock::Create("ok");
- // Pure's complex values are a special algebraic data type defined in
- // math.pure, hence we have to go to some lengths here to get these
- // values.
- Value *chk = b.CreateCall(module->getFunction("pure_is_complex"), x);
- b.CreateCondBr(chk, okbb, failedbb);
- f->getBasicBlockList().push_back(okbb);
- b.SetInsertPoint(okbb);
- Value *cv = b.CreateCall(module->getFunction("pure_get_complex"), x);
- unboxed[i] = cv;
-#endif
} else if (argt[i] == CharPtrTy) {
BasicBlock *okbb = BasicBlock::Create("ok");
Value *idx[2] = { Zero, Zero };
@@ -4120,11 +4083,7 @@
argt[i] == PointerType::get(Type::Int32Ty, 0) ||
argt[i] == PointerType::get(Type::Int64Ty, 0) ||
argt[i] == PointerType::get(Type::FloatTy, 0) ||
- argt[i] == PointerType::get(Type::DoubleTy, 0)
-#if COMPLEX_NUMBERS
- || argt[i] == ComplexPtrTy
-#endif
- ) {
+ argt[i] == PointerType::get(Type::DoubleTy, 0)) {
BasicBlock *okbb = BasicBlock::Create("ok");
Value *idx[2] = { Zero, Zero };
Value *tagv = b.CreateLoad(b.CreateGEP(x, idx, idx+2), "tag");
@@ -4230,21 +4189,13 @@
b.CreateFPExt(u, Type::DoubleTy));
else if (type == Type::DoubleTy)
u = b.CreateCall(module->getFunction("pure_double"), u);
-#if COMPLEX_NUMBERS
- else if (type == ComplexTy)
- u = b.CreateCall(module->getFunction("pure_complex"), u);
-#endif
else if (type == CharPtrTy)
u = b.CreateCall(module->getFunction("pure_cstring_dup"), u);
else if (type == PointerType::get(Type::Int16Ty, 0) ||
type == PointerType::get(Type::Int32Ty, 0) ||
type == PointerType::get(Type::Int64Ty, 0) ||
type == PointerType::get(Type::FloatTy, 0) ||
- type == PointerType::get(Type::DoubleTy, 0)
-#if COMPLEX_NUMBERS
- || type == ComplexPtrTy
-#endif
- )
+ type == PointerType::get(Type::DoubleTy, 0))
u = b.CreateCall(module->getFunction("pure_pointer"),
b.CreateBitCast(u, VoidPtrTy));
else if (type == GSLMatrixPtrTy)
Modified: pure/trunk/interpreter.hh
===================================================================
--- pure/trunk/interpreter.hh 2008-09-21 07:44:02 UTC (rev 816)
+++ pure/trunk/interpreter.hh 2008-09-21 12:42:34 UTC (rev 817)
@@ -41,13 +41,6 @@
default, use 0 to disable this option). */
#define LIST_KLUDGE 10
-/* Experimental support for marshalling of complex numbers in the C
- interface. This doesn't work right now and is disabled. LLVM doesn't seem
- to provide a transparent way to handle complex values in function calls
- yet, and maybe this isn't even possible because different compilers might
- specify different ABIs to do that kind of thing. */
-#define COMPLEX_NUMBERS 0
-
using namespace std;
/* The Pure interpreter. */
Modified: pure/trunk/runtime.cc
===================================================================
--- pure/trunk/runtime.cc 2008-09-21 07:44:02 UTC (rev 816)
+++ pure/trunk/runtime.cc 2008-09-21 12:42:34 UTC (rev 817)
@@ -2048,6 +2048,26 @@
}
extern "C"
+pure_expr *pure_complex(double c[2])
+{
+ return make_complex(c[0], c[1]);
+}
+
+extern "C"
+bool pure_is_complex(pure_expr *x, double *c)
+{
+ double a, b;
+ if (get_complex(x, a, b)) {
+ if (c) {
+ c[0] = a;
+ c[1] = b;
+ }
+ return true;
+ } else
+ return false;
+}
+
+extern "C"
pure_expr *pure_new(pure_expr *x)
{
return pure_new_internal(x);
@@ -2543,33 +2563,7 @@
return &x->data.z;
}
-#if COMPLEX_NUMBERS
extern "C"
-pure_expr *pure_complex(__complex_double c)
-{
- return make_complex(c.x[0], c.x[1]);
-}
-
-extern "C"
-bool pure_is_complex(pure_expr *x)
-{
- return is_complex(x);
-}
-
-extern "C"
-__complex_double pure_get_complex(pure_expr *x)
-{
- __complex_double res = {{0.0,0.0}};
- double a, b;
- if (get_complex(x, a, b)) {
- res.x[0] = a;
- res.x[1] = b;
- }
- return res;
-}
-#endif
-
-extern "C"
void *pure_get_matrix(pure_expr *x)
{
assert(x && x->tag == EXPR::MATRIX || x->tag == EXPR::DMATRIX ||
Modified: pure/trunk/runtime.h
===================================================================
--- pure/trunk/runtime.h 2008-09-21 07:44:02 UTC (rev 816)
+++ pure/trunk/runtime.h 2008-09-21 12:42:34 UTC (rev 817)
@@ -290,6 +290,15 @@
bool pure_is_listv(pure_expr *x, size_t *size, pure_expr ***elems);
bool pure_is_tuplev(pure_expr *x, size_t *size, pure_expr ***elems);
+/* Complex number support. These are actually defined as an algebraic type in
+ math.pure, but some applications may require access to these values in the
+ C interface. Note that we don't want to rely on ISOC99 complex number
+ support or any kind of third-party library here, so this API represents
+ complex values simply as a double[2]. */
+
+pure_expr *pure_complex(double c[2]);
+bool pure_is_complex(pure_expr *x, double *c);
+
/* Memory management. */
/* Count a new reference to an expression. This should be called whenever you
@@ -438,21 +447,6 @@
int64_t pure_get_long(pure_expr *x);
int32_t pure_get_int(pure_expr *x);
-#if 0
-// This stuff is disabled right now as it doesn't work yet.
-/* Marshall complex numbers. These are actually defined as an algebraic type
- in math.pure, but we need some basic support for these values in the C
- interface. */
-
-/* We don't want to rely on ISO complex number support here. The following
- should do the job on all supported systems. */
-typedef struct { double x[2]; } __complex_double;
-
-pure_expr *pure_complex(__complex_double c);
-bool pure_is_complex(pure_expr *x);
-__complex_double pure_get_complex(pure_expr *x);
-#endif
-
/* Convert a matrix expression to a pointer to the corresponding GSL matrix
struct. This is used to marshall matrix arguments in the C interface. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|