blueloveTH 2 years ago
parent
commit
a187e5bcdb
2 changed files with 8 additions and 5 deletions
  1. 1 0
      src/codeobject.h
  2. 7 5
      src/obj.h

+ 1 - 0
src/codeobject.h

@@ -60,6 +60,7 @@ struct CodeObject {
     std::set<StrName> global_names;
     std::vector<CodeBlock> blocks = { CodeBlock{NO_BLOCK, -1} };
     std::map<StrName, int> labels;
+    std::vector<FunctionDecl> functions;
 
     // may be.. just use a large NameDict?
     uint32_t perfect_locals_capacity = 2;

+ 7 - 5
src/obj.h

@@ -24,7 +24,7 @@ struct NativeFunc {
     PyObject* operator()(VM* vm, Args& args) const;
 };
 
-struct Function {
+struct FunctionDecl {
     StrName name;
     CodeObject_ code;
     std::vector<StrName> args;
@@ -32,10 +32,6 @@ struct Function {
     NameDict kwargs;              // empty if no k=v
     std::vector<StrName> kwargs_order;
 
-    // runtime settings
-    PyObject* _module = nullptr;
-    NameDict_ _closure = nullptr;
-
     bool has_name(StrName val) const {
         bool _0 = std::find(args.begin(), args.end(), val) != args.end();
         bool _1 = starred_arg == val;
@@ -44,6 +40,12 @@ struct Function {
     }
 };
 
+struct Function{
+    const FunctionDecl* decl;
+    PyObject* _module = nullptr;
+    NameDict_ _closure = nullptr;
+};
+
 struct BoundMethod {
     PyObject* obj;
     PyObject* method;