#include "tlib.hh"
Go to the source code of this file.
Functions | |
Tree | pushValueDef (Tree id, Tree def, Tree lenv) |
Push a new layer and add a single definition. | |
bool | searchIdDef (Tree id, Tree &def, Tree lenv) |
Search the environment for the definition of a symbol ID and return it. | |
Tree | pushMultiClosureDefs (Tree ldefs, Tree visited, Tree lenv) |
Push a new layer with multiple definitions creating the appropriate closures. | |
Tree | copyEnvReplaceDefs (Tree anEnv, Tree ldefs, Tree visited, Tree curEnv) |
Create a new environment by copying an existing one and replacing some definitions. |
Create a new environment by copying an existing one and replacing some definitions.
xenv | existing environment we will copy | |
ldefs | list of pairs (symbol id x definition) that will replace old definitions | |
visited | set of visited symbols (used for recursive definition detection) | |
lenv | the current environment to evaluate the definitions |
Definition at line 137 of file environment.cpp.
References CTree::branch(), closure(), CTree::exportProperties(), hd(), isBoxCase(), isNil(), nil, pushNewLayer(), setDefNameProperty(), setProperty(), tl(), and updateClosures().
Referenced by realeval().
00138 { 00139 vector<Tree> ids, clos; 00140 Tree copyEnv; 00141 00142 anEnv->exportProperties(ids, clos); // get the definitions of the environment 00143 copyEnv = pushNewLayer(anEnv->branch(0)); // create new environment with same stack 00144 updateClosures(clos, anEnv, copyEnv); // update the closures replacing oldEnv with newEnv 00145 00146 for (unsigned int i=0; i < clos.size(); i++) { // transfers the updated definitions to the new environment 00147 setProperty(copyEnv, ids[i], clos[i]); 00148 } 00149 00150 while (!isNil(ldefs)) { // replace the old definitions with the new ones 00151 Tree def = hd(ldefs); 00152 Tree id = hd(def); 00153 Tree rhs= tl(def); 00154 Tree cl = closure(rhs,nil,visited,curEnv); 00155 stringstream s; s << boxpp(id); 00156 if (!isBoxCase(rhs)) setDefNameProperty(cl,s.str()); 00157 setProperty(copyEnv, id, cl); 00158 ldefs = tl(ldefs); 00159 } 00160 return copyEnv; 00161 }
Push a new layer with multiple definitions creating the appropriate closures.
ldefs | list of pairs (symbol id x definition) to be binded to the symbol id | |
visited | set of visited symbols (used for recursive definition detection) | |
lenv | the environment where to push the layer and add all the definitions |
Definition at line 79 of file environment.cpp.
References addLayerDef(), closure(), hd(), isBoxCase(), isNil(), nil, pushNewLayer(), setDefNameProperty(), and tl().
Referenced by evaldocexpr(), evalprocess(), and realeval().
00080 { 00081 Tree lenv2 = pushNewLayer(lenv); 00082 while (!isNil(ldefs)) { 00083 Tree def = hd(ldefs); 00084 Tree id = hd(def); 00085 Tree rhs= tl(def); 00086 Tree cl = closure(tl(def),nil,visited,lenv2); 00087 stringstream s; s << boxpp(id); 00088 if (!isBoxCase(rhs)) setDefNameProperty(cl,s.str()); 00089 addLayerDef( id, cl, lenv2 ); 00090 ldefs = tl(ldefs); 00091 } 00092 return lenv2; 00093 }
Push a new layer and add a single definition.
id | the symbol id to be defined | |
def | the definition to be binded to the symbol id | |
lenv | the environment where to push the layer and add the definition |
Definition at line 64 of file environment.cpp.
00065 { 00066 Tree lenv2 = pushNewLayer(lenv); 00067 addLayerDef(id, def, lenv2); 00068 return lenv2; 00069 }
Search the environment for the definition of a symbol ID and return it.
id | the symbol ID to search | |
def | where to store the definition if any | |
lenv | the environment |
Definition at line 104 of file environment.cpp.
00105 { 00106 // search the environment until a definition is found 00107 // or nil (the empty environment) is reached 00108 while (!isNil(lenv) && !getProperty(lenv, id, def)) { 00109 lenv = lenv->branch(0); 00110 } 00111 return !isNil(lenv); 00112 }