2009-07-24 08:35:21 +00:00
|
|
|
#ifndef _PYC_CODE_H
|
|
|
|
#define _PYC_CODE_H
|
|
|
|
|
2011-10-23 17:48:10 -07:00
|
|
|
#include "pyc_sequence.h"
|
|
|
|
#include "pyc_string.h"
|
2022-12-02 14:16:18 -08:00
|
|
|
#include <vector>
|
2009-07-24 08:35:21 +00:00
|
|
|
|
2023-01-19 13:05:06 -08:00
|
|
|
class PycData;
|
|
|
|
class PycModule;
|
|
|
|
|
2009-07-24 08:35:21 +00:00
|
|
|
class PycCode : public PycObject {
|
|
|
|
public:
|
2022-12-02 14:16:18 -08:00
|
|
|
typedef std::vector<PycRef<PycString>> globals_t;
|
2009-07-26 10:07:13 +00:00
|
|
|
enum CodeFlags {
|
|
|
|
CO_OPTIMIZED = 0x1,
|
|
|
|
CO_NEWLOCALS = 0x2,
|
|
|
|
CO_VARARGS = 0x4,
|
|
|
|
CO_VARKEYWORDS = 0x8,
|
|
|
|
CO_NESTED = 0x10,
|
|
|
|
CO_GENERATOR = 0x20,
|
|
|
|
CO_NOFREE = 0x40,
|
2015-10-01 16:06:09 -07:00
|
|
|
CO_COROUTINE = 0x80,
|
|
|
|
CO_ITERABLE_COROUTINE = 0x100,
|
2009-07-26 10:07:13 +00:00
|
|
|
CO_GENERATOR_ALLOWED = 0x1000,
|
|
|
|
CO_FUTURE_DIVISION = 0x2000,
|
|
|
|
CO_FUTURE_ABSOLUTE_IMPORT = 0x4000,
|
|
|
|
CO_FUTURE_WITH_STATEMENT = 0x8000,
|
|
|
|
CO_FUTURE_PRINT_FUNCTION = 0x10000,
|
|
|
|
CO_FUTURE_UNICODE_LITERALS = 0x20000,
|
|
|
|
CO_FUTURE_BARRY_AS_BDFL = 0x40000,
|
2015-10-01 16:06:09 -07:00
|
|
|
CO_FUTURE_GENERATOR_STOP = 0x80000,
|
2009-07-26 10:07:13 +00:00
|
|
|
};
|
|
|
|
|
2024-03-12 22:55:56 +02:00
|
|
|
PycCode(int type = TYPE_CODE)
|
|
|
|
: PycObject(type), m_argCount(), m_posOnlyArgCount(), m_kwOnlyArgCount(),
|
2019-02-08 16:06:55 -08:00
|
|
|
m_numLocals(), m_stackSize(), m_flags(), m_firstLine() { }
|
2009-07-24 08:35:21 +00:00
|
|
|
|
2023-01-19 13:05:06 -08:00
|
|
|
void load(PycData* stream, PycModule* mod) override;
|
2009-07-24 08:35:21 +00:00
|
|
|
|
|
|
|
int argCount() const { return m_argCount; }
|
2019-02-08 16:06:55 -08:00
|
|
|
int posOnlyArgCount() const { return m_posOnlyArgCount; }
|
2009-07-24 08:35:21 +00:00
|
|
|
int kwOnlyArgCount() const { return m_kwOnlyArgCount; }
|
|
|
|
int numLocals() const { return m_numLocals; }
|
|
|
|
int stackSize() const { return m_stackSize; }
|
|
|
|
int flags() const { return m_flags; }
|
|
|
|
PycRef<PycString> code() const { return m_code; }
|
2009-07-24 23:19:46 +00:00
|
|
|
PycRef<PycSequence> consts() const { return m_consts; }
|
|
|
|
PycRef<PycSequence> names() const { return m_names; }
|
2023-01-19 11:20:06 -08:00
|
|
|
PycRef<PycSequence> localNames() const { return m_localNames; }
|
|
|
|
PycRef<PycString> localKinds() const { return m_localKinds; }
|
2009-07-24 23:19:46 +00:00
|
|
|
PycRef<PycSequence> freeVars() const { return m_freeVars; }
|
|
|
|
PycRef<PycSequence> cellVars() const { return m_cellVars; }
|
2009-07-24 08:35:21 +00:00
|
|
|
PycRef<PycString> fileName() const { return m_fileName; }
|
|
|
|
PycRef<PycString> name() const { return m_name; }
|
2022-12-02 16:34:58 -08:00
|
|
|
PycRef<PycString> qualName() const { return m_qualName; }
|
2009-07-24 08:35:21 +00:00
|
|
|
int firstLine() const { return m_firstLine; }
|
|
|
|
PycRef<PycString> lnTable() const { return m_lnTable; }
|
2022-12-02 16:34:58 -08:00
|
|
|
PycRef<PycString> exceptTable() const { return m_exceptTable; }
|
2009-07-24 08:35:21 +00:00
|
|
|
|
2009-07-24 19:52:47 +00:00
|
|
|
PycRef<PycObject> getConst(int idx) const
|
2019-02-08 16:06:55 -08:00
|
|
|
{
|
|
|
|
return m_consts->get(idx);
|
|
|
|
}
|
2009-07-24 19:52:47 +00:00
|
|
|
|
|
|
|
PycRef<PycString> getName(int idx) const
|
2019-02-08 16:06:55 -08:00
|
|
|
{
|
2022-12-01 16:13:31 -08:00
|
|
|
return m_names->get(idx).cast<PycString>();
|
2019-02-08 16:06:55 -08:00
|
|
|
}
|
2009-07-24 19:52:47 +00:00
|
|
|
|
2023-01-19 11:20:06 -08:00
|
|
|
PycRef<PycString> getLocal(int idx) const
|
2019-02-08 16:06:55 -08:00
|
|
|
{
|
2023-01-19 11:20:06 -08:00
|
|
|
return m_localNames->get(idx).cast<PycString>();
|
2019-02-08 16:06:55 -08:00
|
|
|
}
|
2009-07-24 19:52:47 +00:00
|
|
|
|
2023-01-19 13:05:06 -08:00
|
|
|
PycRef<PycString> getCellVar(PycModule* mod, int idx) const;
|
2009-07-24 19:52:47 +00:00
|
|
|
|
2011-10-23 00:21:17 -07:00
|
|
|
const globals_t& getGlobals() const { return m_globalsUsed; }
|
2011-10-09 23:42:34 -07:00
|
|
|
|
2011-10-23 00:21:17 -07:00
|
|
|
void markGlobal(PycRef<PycString> varname)
|
|
|
|
{
|
2022-12-02 14:16:18 -08:00
|
|
|
m_globalsUsed.emplace_back(std::move(varname));
|
2011-10-09 23:42:34 -07:00
|
|
|
}
|
|
|
|
|
2009-07-24 08:35:21 +00:00
|
|
|
private:
|
2019-02-08 16:06:55 -08:00
|
|
|
int m_argCount, m_posOnlyArgCount, m_kwOnlyArgCount, m_numLocals;
|
|
|
|
int m_stackSize, m_flags;
|
2009-07-24 08:35:21 +00:00
|
|
|
PycRef<PycString> m_code;
|
2009-07-24 23:19:46 +00:00
|
|
|
PycRef<PycSequence> m_consts;
|
|
|
|
PycRef<PycSequence> m_names;
|
2023-01-19 11:20:06 -08:00
|
|
|
PycRef<PycSequence> m_localNames;
|
|
|
|
PycRef<PycString> m_localKinds;
|
2009-07-24 23:19:46 +00:00
|
|
|
PycRef<PycSequence> m_freeVars;
|
|
|
|
PycRef<PycSequence> m_cellVars;
|
2009-07-24 08:35:21 +00:00
|
|
|
PycRef<PycString> m_fileName;
|
|
|
|
PycRef<PycString> m_name;
|
2022-12-02 16:34:58 -08:00
|
|
|
PycRef<PycString> m_qualName;
|
2009-07-24 08:35:21 +00:00
|
|
|
int m_firstLine;
|
|
|
|
PycRef<PycString> m_lnTable;
|
2022-12-02 16:34:58 -08:00
|
|
|
PycRef<PycString> m_exceptTable;
|
2011-10-09 23:42:34 -07:00
|
|
|
globals_t m_globalsUsed; /* Global vars used in this code */
|
2009-07-24 08:35:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|