[pure-lang-svn] SF.net SVN: pure-lang: [40] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-05-03 22:02:19
|
Revision: 40 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=40&view=rev Author: agraef Date: 2008-05-03 15:02:26 -0700 (Sat, 03 May 2008) Log Message: ----------- Add operations to check for and deconstruct function applications. Modified Paths: -------------- pure/trunk/lib/primitives.pure pure/trunk/runtime.cc pure/trunk/runtime.h Modified: pure/trunk/lib/primitives.pure =================================================================== --- pure/trunk/lib/primitives.pure 2008-05-03 21:06:12 UTC (rev 39) +++ pure/trunk/lib/primitives.pure 2008-05-03 22:02:26 UTC (rev 40) @@ -38,8 +38,11 @@ stringp x = case x of _::string = 1; _ = 0 end; pointerp x = case x of _::pointer = 1; _ = 0 end; -/* Predicates to check for proper lists and tuples. */ +/* Predicates to check for function applications and proper lists and + tuples. */ +extern bool applp(expr*); + listp [] = 1; listp (x:xs) = listp xs; listp _ = 0 otherwise; @@ -48,6 +51,10 @@ tuplep (x,xs) = 1; tuplep _ = 0 otherwise; +/* Operations to return the function and the argument in an application. */ + +extern expr* fun(expr*), expr* arg(expr*); + /* Conversions between the different numeric and pointer types. */ extern expr* pure_intval(expr*), expr* pure_dblval(expr*), Modified: pure/trunk/runtime.cc =================================================================== --- pure/trunk/runtime.cc 2008-05-03 21:06:12 UTC (rev 39) +++ pure/trunk/runtime.cc 2008-05-03 22:02:26 UTC (rev 40) @@ -1095,6 +1095,30 @@ } extern "C" +bool applp(const pure_expr *x) +{ + return (x->tag == EXPR::APP); +} + +extern "C" +pure_expr *fun(const pure_expr *x) +{ + if (x->tag == EXPR::APP) + return x->data.x[0]; + else + return 0; +} + +extern "C" +pure_expr *arg(const pure_expr *x) +{ + if (x->tag == EXPR::APP) + return x->data.x[1]; + else + return 0; +} + +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-03 21:06:12 UTC (rev 39) +++ pure/trunk/runtime.h 2008-05-03 22:02:26 UTC (rev 40) @@ -256,6 +256,16 @@ bool same(const pure_expr *x, const pure_expr *y); +/* Check whether an object is a function application, and return the function + and the argument of an application. Note that these operations can't be + defined in Pure because of the "head is function" rule which means that in + a pattern of the form f x, f is always a literal function symbol and not a + variable. */ + +bool applp(const pure_expr *x); +pure_expr *fun(const pure_expr *x); +pure_expr *arg(const pure_expr *x); + /* 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. |