-void CYScope::Add(CYContext &context, CYIdentifierAddressVector &external) {
- for (CYIdentifierAddressVector::const_iterator i(external.begin()); i != external.end(); ++i) {
- std::pair<CYIdentifierAddressSet::iterator, bool> insert(identifiers_.insert(*i));
- if (!insert.second)
- (*i)->replace_ = *insert.first;
+CYExpression *CYRubyBlock::Replace(CYContext &context) {
+ // XXX: this needs to do something much more epic to handle return
+ return call_->AddArgument(context, proc_->Replace(context));
+}
+
+CYExpression *CYRubyProc::Replace(CYContext &context) {
+ CYFunctionExpression *function($ CYFunctionExpression(NULL, parameters_, code_));
+ function->nonlocal_ = context.nextlocal_;
+ return function;
+}
+
+CYScope::CYScope(CYScopeType type, CYContext &context, CYStatement *&statements) :
+ type_(type),
+ context_(context),
+ statements_(statements),
+ parent_(context.scope_)
+{
+ context_.scope_ = this;
+}
+
+CYScope::~CYScope() {
+}
+
+void CYScope::Close() {
+ context_.scope_ = parent_;
+ Scope(context_, statements_);
+}
+
+void CYScope::Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierFlags flags) {
+ if (type_ == CYScopeCatch && flags != CYIdentifierCatch)
+ parent_->Declare(context, identifier, flags);
+ else
+ internal_.insert(CYIdentifierAddressFlagsMap::value_type(identifier, flags));
+}
+
+CYIdentifier *CYScope::Lookup(CYContext &context, CYIdentifier *identifier) {
+ std::pair<CYIdentifierValueSet::iterator, bool> insert(identifiers_.insert(identifier));
+ return *insert.first;
+}
+
+void CYScope::Merge(CYContext &context, CYIdentifier *identifier) {
+ std::pair<CYIdentifierValueSet::iterator, bool> insert(identifiers_.insert(identifier));
+ if (!insert.second) {
+ if ((*insert.first)->offset_ < identifier->offset_)
+ (*insert.first)->offset_ = identifier->offset_;
+ identifier->replace_ = *insert.first;
+ (*insert.first)->usage_ += identifier->usage_ + 1;