Module PyEnv.DataStack

In Python, everything is an object, and the interpreter maintains a stack of references to such objects. Pushing and popping on the stack are always references to objets that leave in a heap. There is no need to model this heap, but the data stack is quite important.

type cell =
  1. | Const of FFI.Constant.t
    (*

    constant from co_consts

    *)
  2. | Name of {
    1. global : bool;
    2. name : string;
    }
    (*

    reference to a name, from co_names.

    *)
  3. | VarName of string
    (*

    reference to a local name, fromco_varnames

    *)
  4. | Temp of T.Ident.t
    (*

    SSA variable

    *)
  5. | Code of {
    1. fun_or_class : bool;
    2. code_name : string;
    3. code : FFI.Code.t;
    }
    (*

    code Python object with its name. It can be a function, class, closure, ...

    *)
  6. | List of PyBuiltin.builder * cell list
    (*

    Light encoding of raw Python tuples/lists.

    *)
  7. | Map of (T.Exp.t * cell) list
    (*

    Light encoding of raw Python maps/dicts.

    *)
  8. | BuiltinBuildClass
    (*

    see Python's LOAD_BUILD_CLASS

    *)
  9. | Import of {
    1. import_path : Ident.t;
    2. from_list : string list;
    }
    (*

    imported module path, with optional names of symbols from that module

    *)
  10. | ImportFrom of {
    1. import_path : Ident.t;
    2. imported_name : string;
    }
    (*

    imported symbol from a module. Must have been loaded via Import first

    *)
  11. | ImportCall of {
    1. id : Ident.t;
    2. loc : T.Location.t;
    }
    (*

    Static call to export definition

    *)
  12. | MethodCall of {
    1. receiver : T.Exp.t;
    2. name : T.QualifiedProcName.t;
    }
    (*

    Virtual call, usually of a method of a class. Could be an access to a closure that is called straight away

    *)
  13. | StaticCall of {
    1. call_name : T.QualifiedProcName.t;
    2. receiver : T.Exp.t option;
    }
    (*

    call to static method in class. Because we turn some method calls into static ones, we have to keep the receiver around, just in case.

    *)
  14. | Super
    (*

    special name to refer to the parent class, like in super().__init__()

    *)
  15. | Path of Ident.t
    (*

    Qualified path for sequence of imports, attribute accesses, ...

    *)
  16. | WithContext of T.Ident.t
    (*

    value to be used for calling __enter__ and __exit__ with the `with context` statement

    *)
  17. | NoException
    (*

    Special NONE symbol pushed by the exception infra to express that no exception has been raised

    *)
val pp_cell : Stdlib.Format.formatter -> cell -> unit
val as_code : cell -> FFI.Code.t option
val as_name : cell -> string option
val as_id : cell -> Ident.t option
val is_path : cell -> bool
val is_no_exception : cell -> bool
type t = cell list