this repo has no description
1// Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com)
2#include "builtins.h"
3#include "bytecode.h"
4#include "dict-builtins.h"
5#include "module-builtins.h"
6#include "objects.h"
7#include "runtime.h"
8
9namespace py {
10
11void FUNC(_bytecode_utils, __init_module__)(Thread* thread,
12 const Module& module,
13 View<byte> bytecode) {
14 HandleScope scope(thread);
15
16 // Add module variables
17 {
18 Object co_optimized(&scope, SmallInt::fromWord(Code::Flags::kOptimized));
19 moduleAtPutByCStr(thread, module, "CO_OPTIMIZED", co_optimized);
20
21 Object co_newlocals(&scope, SmallInt::fromWord(Code::Flags::kNewlocals));
22 moduleAtPutByCStr(thread, module, "CO_NEWLOCALS", co_newlocals);
23
24 Object co_nofree(&scope, SmallInt::fromWord(Code::Flags::kNofree));
25 moduleAtPutByCStr(thread, module, "CO_NOFREE", co_nofree);
26
27 Dict opmap(&scope, thread->runtime()->newDict());
28 moduleAtPutByCStr(thread, module, "opmap", opmap);
29
30 Object opname(&scope, Str::empty());
31 Object opnum(&scope, Str::empty());
32 const char prefix[] = "UNUSED_";
33 word prefix_len = std::strlen(prefix);
34 for (word i = 0; i < kNumBytecodes; i++) {
35 const char* opname_cstr = kBytecodeNames[i];
36 if (std::strncmp(prefix, opname_cstr, prefix_len) == 0) {
37 // Do not add opcodes that begin with UNUSED_
38 continue;
39 }
40 opname = Runtime::internStrFromCStr(thread, opname_cstr);
41 opnum = SmallInt::fromWord(i);
42 dictAtPutByStr(thread, opmap, opname, opnum);
43 }
44 }
45
46 executeFrozenModule(thread, module, bytecode);
47}
48} // namespace py