[pure-lang-svn] SF.net SVN: pure-lang: [30] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-05-02 09:04:10
|
Revision: 30 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=30&view=rev Author: agraef Date: 2008-05-02 02:04:18 -0700 (Fri, 02 May 2008) Log Message: ----------- Added syntactic equality. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/lib/prelude.pure pure/trunk/lib/primitives.pure pure/trunk/runtime.cc pure/trunk/runtime.h Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-05-02 07:09:21 UTC (rev 29) +++ pure/trunk/ChangeLog 2008-05-02 09:04:18 UTC (rev 30) @@ -1,5 +1,8 @@ 2008-05-02 Albert Graef <Dr....@t-...> + * runtime.cc (same): Added a syntactic equality test. Requested by + Eddie Rucker. + * Makefile: Add $(LDFLAGS) and $(LIBS) to the link line, so that the user can easily add his own linker options and local libraries. Modified: pure/trunk/lib/prelude.pure =================================================================== --- pure/trunk/lib/prelude.pure 2008-05-02 07:09:21 UTC (rev 29) +++ pure/trunk/lib/prelude.pure 2008-05-02 09:04:18 UTC (rev 30) @@ -41,6 +41,7 @@ infixr 3 && ; // logical and (short-circuit) prefix 3 not ; // logical negation infix 4 < > <= >= == != ; // relations +infix 4 === !== ; // syntactic equality infixr 4 : ; // list cons infixl 5 << >> ; // bit shifts infixl 6 + - | ; // addition, bitwise or Modified: pure/trunk/lib/primitives.pure =================================================================== --- pure/trunk/lib/primitives.pure 2008-05-02 07:09:21 UTC (rev 29) +++ pure/trunk/lib/primitives.pure 2008-05-02 09:04:18 UTC (rev 30) @@ -24,6 +24,12 @@ extern void pure_throw(expr*); // IMPURE! throw x = pure_throw x; +/* Syntactic equality. */ + +extern bool same(expr* x, expr* y); +x === y = same x y; +x !== y = not same x y; + /* Predicates to check for the built-in types. */ intp x = case x of _::int = 1; _ = 0 end; Modified: pure/trunk/runtime.cc =================================================================== --- pure/trunk/runtime.cc 2008-05-02 07:09:21 UTC (rev 29) +++ pure/trunk/runtime.cc 2008-05-02 09:04:18 UTC (rev 30) @@ -1059,6 +1059,42 @@ } extern "C" +bool same(const pure_expr *x, const pure_expr *y) +{ + char test; + if (x == y) + return 1; + else if (x->tag >= 0 && y->tag >= 0) + if (x->data.clos && y->data.clos) + return x->tag == y->tag && x->data.clos->fp == y->data.clos->fp; + else + return x->tag == y->tag && x->data.clos == y->data.clos; + else if (x->tag != y->tag) + return 0; + else { + switch (x->tag) { + case EXPR::APP: { + checkstk(test); + return same(x->data.x[0], y->data.x[0]) && + same(x->data.x[1], y->data.x[1]); + } + case EXPR::INT: + return x->data.i == y->data.i; + case EXPR::BIGINT: + return mpz_cmp(x->data.z, y->data.z) == 0; + case EXPR::DBL: + return x->data.d == y->data.d; + case EXPR::STR: + return strcmp(x->data.s, y->data.s) == 0; + case EXPR::PTR: + return x->data.p == y->data.p; + default: + return 1; + } + } +} + +extern "C" int32_t pointer_get_byte(void *ptr) { uint8_t *p = (uint8_t*)ptr; Modified: pure/trunk/runtime.h =================================================================== --- pure/trunk/runtime.h 2008-05-02 07:09:21 UTC (rev 29) +++ pure/trunk/runtime.h 2008-05-02 09:04:18 UTC (rev 30) @@ -252,6 +252,10 @@ pure_expr *str(const pure_expr *x); pure_expr *eval(const char *s); +/* Check whether two objects are the "same" (syntactically). */ + +bool same(const pure_expr *x, const pure_expr *y); + /* Direct memory accesses. */ int32_t pointer_get_byte(void *ptr); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |