this repo has no description
at trunk 129 lines 5.2 kB view raw
1/* Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) */ 2#pragma once 3 4#include "frame.h" 5#include "globals.h" 6#include "objects.h" 7#include "runtime.h" 8#include "thread.h" 9 10namespace py { 11 12// Allocate dict.indices() of size `num_indices` and dict.data() accordingly. 13void dictAllocateArrays(Thread* thread, const Dict& dict, word num_indices); 14 15// Return true if an item is found at `*index` or after and sets index to the 16// next index to probe, key_out to the found key and value_out to the found 17// value. Returns false otherwise. 18bool dictNextItem(const Dict& dict, word* index, Object* key_out, 19 Object* value_out); 20 21bool dictNextItemHash(const Dict& dict, word* index, Object* key_out, 22 Object* value_out, word* hash_out); 23 24bool dictNextKey(const Dict& dict, word* index, Object* key_out); 25 26bool dictNextValue(const Dict& dict, word* index, Object* value_out); 27 28bool dictNextKeyHash(const Dict& dict, word* index, Object* key_out, 29 word* hash_out); 30 31// Associate a value with the supplied key. 32// 33// This handles growing the backing Tuple if needed. 34RawObject dictAtPut(Thread* thread, const Dict& dict, const Object& key, 35 word hash, const Object& value); 36 37// Does the same as `dictAtPut` but only works for `key` being a `str` 38// instance. It must not be used with instances of a `str` subclass. 39// `dict` is supposed to contain only `str` keys. 40void dictAtPutByStr(Thread* thread, const Dict& dict, const Object& name, 41 const Object& value); 42 43// Does the same as `dictAtPut` but uses symbol `id` (converted to a string) 44// as key. 45// `dict` is supposed to contain only `str` keys. 46void dictAtPutById(Thread* thread, const Dict& dict, SymbolId id, 47 const Object& value); 48 49// Look up the value associated with `key`. Returns the associated value or 50// `Error::notFound()`. 51RawObject dictAt(Thread* thread, const Dict& dict, const Object& key, 52 word hash); 53 54// Look up the value associated with `name`. `name` must be an instance of 55// `str` but not of a subclass. Returns the associated value or 56// `Error::notFound()`. 57RawObject dictAtByStr(Thread* thread, const Dict& dict, const Object& name); 58 59// Look up the value associated with `id`. Returns the associated value or 60// `Error::notFound()`. 61RawObject dictAtById(Thread* thread, const Dict& dict, SymbolId id); 62 63// Stores value in a ValueCell associated with `name`. Reuses an existing 64// value cell when possible. 65RawObject dictAtPutInValueCellByStr(Thread* thread, const Dict& dict, 66 const Object& name, const Object& value); 67 68// Remove all items from a Dict. 69void dictClear(Thread* thread, const Dict& dict); 70 71// Returns true if the dict contains the specified key. 72RawObject dictIncludes(Thread* thread, const Dict& dict, const Object& key, 73 word hash); 74 75// Try to remove entry associated with `key` from `dict`. 76// Returns the value that was associated before deletion or 77// `Error:notFound()`. 78RawObject dictRemove(Thread* thread, const Dict& dict, const Object& key, 79 word hash); 80 81// Try to remove entry associated with `name` from `dict`. 82// Returns the value that was associated before deletion or 83// `Error:notFound()`. 84RawObject dictRemoveByStr(Thread* thread, const Dict& dict, const Object& name); 85 86RawObject dictKeys(Thread* thread, const Dict& dict); 87 88// Creates a new dict with shallow copies of the given dict's elements. 89RawObject dictCopy(Thread* thread, const Dict& dict); 90 91// Update a dict from another dict or an iterator, overwriting existing keys if 92// duplicates exist. 93// 94// Returns None on success, or an Error object if an exception was raised. 95RawObject dictMergeOverride(Thread* thread, const Dict& dict, 96 const Object& mapping); 97 98// Merges a dict with another dict or a mapping, raising an exception on 99// duplicate keys. 100// 101// Returns None on success, or an Error object if an exception was raised. 102RawObject dictMergeError(Thread* thread, const Dict& dict, 103 const Object& mapping); 104 105// Update a dict from another dict or a mapping, ignoring existing keys if 106// duplicates exist. 107// 108// Returns None on success, or an Error object if an exception was raised. 109RawObject dictMergeIgnore(Thread* thread, const Dict& dict, 110 const Object& mapping); 111 112// Returns a value consistent with the semantics of 'left == right' in Python. 113RawObject dictEq(Thread* thread, const Dict& left, const Dict& right); 114 115// Returns next item in the dict as (key, value) tuple (Tuple) 116// Returns Error::object() if there are no more objects 117RawObject dictItemIteratorNext(Thread* thread, const DictItemIterator& iter); 118 119// Returns next key in the dict 120// Returns Error::object() if there are no more objects 121RawObject dictKeyIteratorNext(Thread* thread, const DictKeyIterator& iter); 122 123// Returns next value in the dict 124// Returns Error::object() if there are no more objects 125RawObject dictValueIteratorNext(Thread* thread, const DictValueIterator& iter); 126 127void initializeDictTypes(Thread* thread); 128 129} // namespace py