x-procedure2: + dict_lookup() primitive

This commit is contained in:
Roland Conybeare 2026-03-16 00:57:17 -05:00
commit f1594aab13
18 changed files with 464 additions and 2 deletions

View file

@ -4,6 +4,7 @@
**/
#include "ObjectPrimitives.hpp"
#include <xo/object2/RuntimeError.hpp>
#include <xo/object2/Dictionary.hpp>
#include <xo/object2/Sequence.hpp>
#include <xo/object2/List.hpp>
@ -100,6 +101,35 @@ namespace xo {
return DPrimitive_gco_0::_make(mm, "dict_make", &xfer_dict_make);
}
// ----- dict_at -----
obj<AGCObject>
xfer_dict_lookup(obj<ARuntimeContext> rcx,
obj<AGCObject,DDictionary> dict,
obj<AGCObject,DString> key)
{
auto opt = dict->lookup(key.data());
if (opt) {
return opt.value();
} else {
DString * src_fn = DString::from_cstr(rcx.allocator(), "dict_lookup");
DString * error = DString::printf(rcx.allocator(),
100,
"no value in dict for key [%s]", key.data()->data());
return obj<AGCObject,DRuntimeError>
(DRuntimeError::_make(rcx.allocator(),
src_fn, error));
}
}
DPrimitive_gco_2_dict_string *
ObjectPrimitives::make_dict_lookup_pm(obj<AAllocator> mm)
{
return DPrimitive_gco_2_dict_string::_make(mm, "dict_lookup", &xfer_dict_lookup);
}
// ----- dict_upsert -----
obj<AGCObject>