/* CrossLang is a dynamically-typed scripting language built on TessesFramework, named in honor of Jesus's sacrifice. Copyright (C) 2026 Mike Nolan SPDX-License-Identifier: GPL-3.0-or-later WITH TessesFramework-Exception-1.0 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "CrossLang.hpp" namespace Tesses::CrossLang { TAssociativeArray *TAssociativeArray::Create(GCList &ls) { return ls.Create(); } TAssociativeArray *TAssociativeArray::Create(GCList *ls) { return ls->Create(); } void TAssociativeArray::Set(std::shared_ptr gc, TObject key, TObject value) { if (std::holds_alternative(key)) return; gc->BarrierBegin(); for (auto index = this->items.begin(); index < this->items.end(); index++) { auto first = index->first; gc->BarrierEnd(); auto eq = Equals(gc, key, first); gc->BarrierBegin(); if (eq) { if (std::holds_alternative(value)) { this->items.erase(index); } else { index->second = value; } gc->BarrierEnd(); return; } } this->items.push_back(std::pair(key, value)); gc->BarrierEnd(); } TObject TAssociativeArray::Get(std::shared_ptr gc, TObject key) { if (std::holds_alternative(key)) return Undefined(); gc->BarrierBegin(); for (auto &item : this->items) { auto first = item.first; gc->BarrierEnd(); auto eq = Equals(gc, key, first); gc->BarrierBegin(); if (eq) { gc->BarrierEnd(); return item.second; } } gc->BarrierEnd(); return Undefined(); } TObject TAssociativeArray::GetKey(int64_t index) { if (index >= 0 && index < (int64_t)this->items.size()) { return this->items[index].first; } return Undefined(); } TObject TAssociativeArray::GetValue(int64_t index) { if (index >= 0 && index < (int64_t)this->items.size()) { return this->items[index].second; } return Undefined(); } void TAssociativeArray::SetKey(int64_t index, TObject key) { if (std::holds_alternative(key)) return; if (index >= 0 && index < (int64_t)this->items.size()) { this->items[index].first = key; } } void TAssociativeArray::SetValue(int64_t index, TObject value) { if (std::holds_alternative(value)) return; if (index >= 0 && index < (int64_t)this->items.size()) { this->items[index].first = value; } } int64_t TAssociativeArray::Count() { return (int64_t)this->items.size(); } void TAssociativeArray::Mark() { if (this->marked) return; this->marked = true; for (auto &item : this->items) { GC::Mark(item.first); GC::Mark(item.second); } } } // namespace Tesses::CrossLang