this repo has no description
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 "handles-decl.h"
7#include "objects.h"
8#include "symbols.h"
9#include "view.h"
10
11#define FUNC(module, name) module##_##name##_func
12#define METH(type, name) type##_##name##_meth
13
14namespace py {
15
16class Thread;
17
18// Function pointer stored in RawCode::code() for builtin functions.
19using BuiltinFunction = RawObject (*)(Thread* thread, Arguments args);
20
21// Function pointer stored in RawFunction::intrinsic() for intrinsic functions.
22using IntrinsicFunction = bool (*)(Thread* thread);
23
24using ModuleInitFunc = void (*)(Thread* thread, const Module& module,
25 View<byte> bytecode);
26
27struct BuiltinType {
28 SymbolId name;
29 LayoutId type;
30};
31
32struct FrozenModule {
33 const char* name;
34 word marshalled_code_length;
35 const byte* marshalled_code;
36 ModuleInitFunc init;
37 bool is_package;
38};
39
40RawObject ensureBuiltinModule(Thread* thread, const Str& name);
41
42RawObject ensureBuiltinModuleById(Thread* thread, SymbolId id);
43
44// Execute a frozen module by marshalling it into a code object and then
45// executing it. Aborts if module execution is unsuccessful.
46void executeFrozenModule(Thread* thread, const Module& module,
47 View<byte> bytecode);
48
49// Execute the code object that represents the code for the top-level module
50// (eg the result of compiling some_file.py). Return the result.
51NODISCARD RawObject executeModule(Thread* thread, const Code& code,
52 const Module& module);
53
54// Exposed for use by the tests. We may be able to remove this later.
55NODISCARD RawObject executeModuleFromCode(Thread* thread, const Code& code,
56 const Object& name);
57
58// Returns `true` if there is a frozen module with name `name`.
59bool isFrozenModule(const Str& name);
60
61// Returns `true` if there is a frozen package with name `name`.
62bool isFrozenPackage(const Str& name);
63
64// Return the FrozenModule with the given name.
65// If there is no such frozen module, return nullptr.
66const FrozenModule* frozenModuleByName(const Str& name);
67
68} // namespace py