[pure-lang-svn] SF.net SVN: pure-lang:[517] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-08-17 09:51:05
|
Revision: 517 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=517&view=rev Author: agraef Date: 2008-08-17 09:51:09 +0000 (Sun, 17 Aug 2008) Log Message: ----------- Add compilation flag values to expr data structure. Modified Paths: -------------- pure/trunk/expr.hh pure/trunk/interpreter.cc Modified: pure/trunk/expr.hh =================================================================== --- pure/trunk/expr.hh 2008-08-16 23:34:50 UTC (rev 516) +++ pure/trunk/expr.hh 2008-08-17 09:51:09 UTC (rev 517) @@ -115,6 +115,11 @@ WITH = -12, // with expression }; + // special flag values used during compilation: + enum { + OVF = 1, // overflowed int constant -> bigint + }; + uint32_t refc; // reference counter int32_t tag; // type tag or nullary symbol @@ -143,8 +148,8 @@ // matching automaton (LAMBDA, CASE; vector for WHEN): matcher *m; - // KLUDGE: overflowed int constant, needed to properly handle -0x8000000 - bool c; + // compilation flags: + uint16_t flags; // extra built-in type tag used in code generation: int8_t ttag; @@ -159,54 +164,54 @@ static EXPR *newref(EXPR *x) { return x?x->incref():0; } EXPR(int32_t _tag) : - refc(0), tag(_tag), m(0), c(false), ttag(0), astag(0), aspath(0) { } + refc(0), tag(_tag), m(0), flags(0), ttag(0), astag(0), aspath(0) { } EXPR(int32_t _tag, int32_t _vtag, uint8_t _idx, int8_t _ttag = 0, const path& _p = path()) : - refc(0), tag(_tag), m(0), c(false), ttag(_ttag), astag(0), aspath(0) + refc(0), tag(_tag), m(0), flags(0), ttag(_ttag), astag(0), aspath(0) { assert(_tag == VAR || _tag == FVAR); data.v.vtag = _vtag; data.v.idx = _idx; data.v.p = (_tag == VAR)?new path(_p):0; } EXPR(int32_t _tag, int32_t _i) : - refc(0), tag(_tag), m(0), c(false), ttag(_tag), astag(0), aspath(0) + refc(0), tag(_tag), m(0), flags(0), ttag(_tag), astag(0), aspath(0) { assert(_tag == INT); data.i = _i; } - EXPR(int32_t _tag, mpz_t _z, bool _c = false) : - refc(0), tag(_tag), m(0), c(_c), ttag(_tag), astag(0), aspath(0) + EXPR(int32_t _tag, mpz_t _z, bool c = false) : + refc(0), tag(_tag), m(0), flags(c?OVF:0), ttag(_tag), astag(0), aspath(0) { assert(_tag == BIGINT); mpz_init_set(data.z, _z); mpz_clear(_z); } EXPR(int32_t _tag, double _d) : - refc(0), tag(_tag), m(0), c(false), ttag(_tag), astag(0), aspath(0) + refc(0), tag(_tag), m(0), flags(0), ttag(_tag), astag(0), aspath(0) { assert(_tag == DBL); data.d = _d; } explicit EXPR(int32_t _tag, char *_s) : - refc(0), tag(_tag), m(0), c(false), ttag(_tag), astag(0), aspath(0) + refc(0), tag(_tag), m(0), flags(0), ttag(_tag), astag(0), aspath(0) { assert(_tag == STR); data.s = _s; } explicit EXPR(int32_t _tag, void *_p) : - refc(0), tag(_tag), m(0), c(false), ttag(_tag), astag(0), aspath(0) + refc(0), tag(_tag), m(0), flags(0), ttag(_tag), astag(0), aspath(0) { assert(_tag == PTR); data.p = _p; } EXPR(int32_t _tag, EXPR *_arg1, EXPR *_arg2, EXPR *_arg3) : - refc(0), tag(_tag), m(0), c(false), ttag(0), astag(0), aspath(0) + refc(0), tag(_tag), m(0), flags(0), ttag(0), astag(0), aspath(0) { assert(_tag == COND); data.x[0] = newref(_arg1); data.x[1] = newref(_arg2); data.x[2] = newref(_arg3); } EXPR(int32_t _tag, EXPR *_arg, EXPR *_body) : - refc(0), tag(_tag), m(0), c(false), ttag(0), astag(0), aspath(0) + refc(0), tag(_tag), m(0), flags(0), ttag(0), astag(0), aspath(0) { assert(_tag == LAMBDA); data.x[0] = newref(_arg); data.x[1] = newref(_body); } EXPR(int32_t _tag, EXPR *_arg, rulel *_rules) : - refc(0), tag(_tag), m(0), c(false), ttag(0), astag(0), aspath(0) + refc(0), tag(_tag), m(0), flags(0), ttag(0), astag(0), aspath(0) { assert(_tag == CASE || _tag == WHEN); data.c.x = newref(_arg); data.c.r = _rules; } EXPR(int32_t _tag, EXPR *_arg, env *_e) : - refc(0), tag(_tag), m(0), c(false), ttag(0), astag(0), aspath(0) + refc(0), tag(_tag), m(0), flags(0), ttag(0), astag(0), aspath(0) { assert(_tag == WITH); data.c.x = newref(_arg); data.c.e = _e; } EXPR(EXPR *_fun, EXPR *_arg) : - refc(0), tag(APP), m(0), c(false), ttag(0), astag(0), aspath(0) + refc(0), tag(APP), m(0), flags(0), ttag(0), astag(0), aspath(0) { data.x[0] = newref(_fun); data.x[1] = newref(_arg); } EXPR(EXPR *_fun, EXPR *_arg1, EXPR *_arg2) : - refc(0), tag(APP), m(0), c(false), ttag(0), astag(0), aspath(0) + refc(0), tag(APP), m(0), flags(0), ttag(0), astag(0), aspath(0) { data.x[0] = new EXPR(_fun, _arg1); data.x[0]->incref(); data.x[1] = newref(_arg2); } EXPR(EXPR *_fun, EXPR *_arg1, EXPR *_arg2, EXPR *_arg3) : - refc(0), tag(APP), m(0), c(false), ttag(0), astag(0), aspath(0) + refc(0), tag(APP), m(0), flags(0), ttag(0), astag(0), aspath(0) { data.x[0] = new EXPR(_fun, _arg1, _arg2); data.x[0]->incref(); data.x[1] = newref(_arg3); } @@ -340,7 +345,7 @@ p->tag == EXPR::CASE || p->tag == EXPR::WHEN); return p->m; } - bool cint() const { return p->c; } + uint16_t&flags() const { return p->flags; } int32_t astag() const { return p->astag; } path &aspath() const { assert(p->aspath); return *p->aspath; } Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-08-16 23:34:50 UTC (rev 516) +++ pure/trunk/interpreter.cc 2008-08-17 09:51:09 UTC (rev 517) @@ -1748,7 +1748,7 @@ } expr *y; // handle special case of a numeric argument - if (x->tag() == EXPR::BIGINT && x->cint() && + if (x->tag() == EXPR::BIGINT && (x->flags()&EXPR::OVF) && mpz_cmp_ui(x->zval(), 0x80000000U) == 0) // The negated int 0x80000000 can actually be represented as a machine int // value, we convert it back on the fly here. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |