void BlockEnvironment::lock_scope(STATE) { if(scope() && !scope()->nil_p()) { scope()->set_locked(state); } if(top_scope() && !top_scope()->nil_p()) { top_scope()->set_locked(state); } }
extern "C" POETCode* make_varRef(POETCode* name, int config) { try { ASTFactory* fac = ASTFactory::inst(); if (name == fac->make_any()) return name; switch (config) { case CODE_VAR: return curfile->make_codeRef(name, 0); case XFORM_VAR: return curfile->make_xformVar(name); case CODE_OR_XFORM_VAR: { POETCode* res = find_code_or_xform_var(name); if (res != 0) return res; CODE_OR_XFORM_UNDEFINED(name->toString()); } case GLOBAL_SCOPE: { POETCode* res = find_code_or_xform_var(name); if (res != 0) return res; res = find_global_var(name); if (res != 0) return res; SYM_UNDEFINED(name->toString()); } case GLOBAL_VAR: { POETCode* res = find_code_or_xform_var(name); if (res != 0) return res; res = find_global_var(name); if (res != 0) return res; return curfile->make_evalVar(name); } case ID_DEFAULT: { LvarSymbolTable* local = top_scope(); POETCode* res = find_code_or_xform_var(name); if (res != 0) return res; if (local == 0) { res = find_global_var(name); if (res != 0) return res; return curfile->make_evalVar(name); } return POETProgram::make_localVar(local, name, LVAR_REG); } case ASSIGN_VAR: { LvarSymbolTable* local = top_scope(); POETCode* res = find_code_or_xform_var(name); if (res != 0) VAR_ASSIGN_ERROR(name->toString()); if (local == 0) { res = find_global_var(name); if (res != 0) return res; return curfile->make_evalVar(name); } return POETProgram::make_localVar(local, name, LVAR_REG); } default: std::cerr << "something is wrong with variable creation config: " << name->toString() << " config = " << config << "\n"; std::cerr << "At line " << yylineno << " of file " << curfile->get_filename() << "\n"; assert(0); } } catch (Error err) { std::cerr << "At line " << yylineno << " of file " << curfile->get_filename() << "\n"; exit(1); } }
extern "C" POETCode* set_local_static(POETCode* id, POETCode* code, LocalVarType t, POETCode* restr, bool insert) { assert(id != 0); try { LvarSymbolTable* local = top_scope(); LocalVar* lvar = curfile->set_local_static(local,id, t, code, restr, insert); return lvar; } catch (Error err) { std::cerr << "\nAt line " << yylineno << " of file " << curfile->get_filename() << "\n"; exit(1); } }
BlockEnvironment* BlockEnvironment::dup(STATE) { BlockEnvironment* be = state->memory()->new_object<BlockEnvironment>(state, G(blokenv)); be->scope(state, scope()); be->top_scope(state, top_scope()); be->compiled_code(state, compiled_code()); be->constant_scope(state, constant_scope()); be->module(state, nil<Module>()); return be; }
// TODO: Should symbols defined by '[import]' use the current scope? bool template_stack::add(template_symbol const& ts) { BOOST_ASSERT(!scopes.empty()); if (this->find_top_scope(ts.identifier)) { return false; } template_symbol symbol(ts); if(!ts.parent) symbol.parent = &top_scope(); boost::spirit::classic::add(scopes.front().symbols, ts.identifier.c_str(), symbol); return true; }
extern "C" POETCode* make_localPar(POETCode* id, POETCode* restr, LocalVarType type) { try { LvarSymbolTable* local = top_scope(); assert(local != 0); LocalVar* res = local->insert(id, type); POETCode* restr1 = res->get_entry().get_restr(); if (restr != 0 && restr1 != 0 && restr != restr1 && !match_AST(restr,restr1, MATCH_AST_EQ)) { SYM_DIFF_DEFINED(id->toString() + ":" + restr->get_className() + ":" + restr->toString(),restr1->get_className() + ":" + restr1->toString()); return res; } if (restr != 0) res->get_entry().set_restr(restr); return res; } catch (Error err) { std::cerr << "\nAt line " << yylineno << " of file " << curfile->get_filename() << "\n"; exit(1); } }