|
|
@@ -1,12 +1,9 @@
|
|
|
#pragma once
|
|
|
|
|
|
-#include "stdint.h"
|
|
|
-#include "stdbool.h"
|
|
|
-
|
|
|
-#ifdef __cplusplus
|
|
|
-extern "C" {
|
|
|
-#endif
|
|
|
+#include <stdint.h>
|
|
|
+#include <stdbool.h>
|
|
|
|
|
|
+/************* Public Types *************/
|
|
|
typedef struct PyObject PyObject;
|
|
|
typedef struct PyVar PyVar;
|
|
|
typedef struct pk_VM pk_VM;
|
|
|
@@ -27,38 +24,28 @@ typedef enum BindType {
|
|
|
BindType_CLASSMETHOD,
|
|
|
} BindType;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
extern pk_VM* pk_current_vm;
|
|
|
|
|
|
-
|
|
|
+/************* Global VMs *************/
|
|
|
void py_initialize();
|
|
|
-// void py_switch_vm(const char* name);
|
|
|
void py_finalize();
|
|
|
|
|
|
-int py_exec_simple(const char*);
|
|
|
-int py_eval_simple(const char*, py_Ref);
|
|
|
-
|
|
|
-/* py_error */
|
|
|
-py_Error* py_getlasterror();
|
|
|
-void py_Error__print(py_Error*);
|
|
|
-
|
|
|
-int py_eq(const py_Ref, const py_Ref);
|
|
|
-int py_le(const py_Ref, const py_Ref);
|
|
|
-int py_hash(const py_Ref, int64_t* out);
|
|
|
+int py_exec(const char*);
|
|
|
+int py_eval(const char*);
|
|
|
|
|
|
-/* py_var */
|
|
|
+/************* Values Creation *************/
|
|
|
void py_newint(py_Ref, int64_t);
|
|
|
void py_newfloat(py_Ref, double);
|
|
|
void py_newbool(py_Ref, bool);
|
|
|
void py_newstr(py_Ref, const char*);
|
|
|
void py_newstrn(py_Ref, const char*, int);
|
|
|
// void py_newfstr(py_Ref, const char*, ...);
|
|
|
-void py_newbytes(py_Ref, const uint8_t*, int);
|
|
|
+// void py_newbytes(py_Ref, const uint8_t*, int);
|
|
|
void py_newnone(py_Ref);
|
|
|
void py_newnull(py_Ref);
|
|
|
|
|
|
void py_newtuple(py_Ref, int);
|
|
|
+// void py_newlist(py_Ref);
|
|
|
|
|
|
// new style decl-based function
|
|
|
void py_newfunction(py_Ref, py_CFunction, const char* sig, BindType bt);
|
|
|
@@ -67,48 +54,55 @@ void py_newfunction2(py_Ref, py_CFunction, const char* sig, BindType bt, const c
|
|
|
void py_newnativefunc(py_Ref, py_CFunction, int argc, BindType bt);
|
|
|
void py_newnativefunc2(py_Ref, py_CFunction, int argc, BindType bt, const char* docstring, const py_Ref userdata);
|
|
|
|
|
|
-
|
|
|
-py_Ref py_newmodule(const char* name, const char* package);
|
|
|
-py_Ref py_getmodule(const char* name);
|
|
|
-const py_Ref py_import(const char* name);
|
|
|
-
|
|
|
-#define py_isnull(self) ((self)->type == 0)
|
|
|
-
|
|
|
-
|
|
|
-/// Sets the name of the object to the given value.
|
|
|
-void py_setdict(py_Ref self, py_Name name, const py_Ref val);
|
|
|
-/// Returns a reference to the name of the object.
|
|
|
+/************* References *************/
|
|
|
py_Ref py_getdict(const py_Ref self, py_Name name);
|
|
|
+void py_setdict(py_Ref self, py_Name name, const py_Ref val);
|
|
|
|
|
|
-/// Sets the i-th slot of the object to the given value.
|
|
|
-void py_setslot(py_Ref self, int i, const py_Ref val);
|
|
|
-/// Returns a reference to the i-th slot of the object.
|
|
|
py_Ref py_getslot(const py_Ref self, int i);
|
|
|
+void py_setslot(py_Ref self, int i, const py_Ref val);
|
|
|
|
|
|
-/// Equivalent to `self.name = val`.
|
|
|
-/// Returns 0 | err
|
|
|
-int py_setattr(py_Ref self, py_Name name, const py_Ref val);
|
|
|
+// int py_getattr(const py_Ref self, py_Name name, py_Ref out);
|
|
|
+// int py_setattr(py_Ref self, py_Name name, const py_Ref val);
|
|
|
|
|
|
-/// Equivalent to `self.name`.
|
|
|
-/// Returns 0 | err
|
|
|
-int py_getattr(const py_Ref self, py_Name name, py_Ref out);
|
|
|
+/// Copies src to dst.
|
|
|
+void py_copyref(const py_Ref src, py_Ref dst);
|
|
|
|
|
|
+/************* Stack Operations *************/
|
|
|
+py_Ref py_gettop();
|
|
|
+void py_settop(const py_Ref);
|
|
|
+py_Ref py_getsecond();
|
|
|
+void py_setsecond(const py_Ref);
|
|
|
/// Returns a reference to the i-th object from the top of the stack.
|
|
|
/// i should be negative, e.g. (-1) means TOS.
|
|
|
-py_Ref py_stack(int i);
|
|
|
-/// Returns a reference to the i-th register.
|
|
|
-py_Ref py_reg(int i);
|
|
|
-/// Returns a reference to the i-th system register.
|
|
|
-py_Ref py_sysreg(int i);
|
|
|
+py_Ref py_peek(int i);
|
|
|
/// Prepares a push and returns an uninitialized reference.
|
|
|
py_Ref py_push();
|
|
|
-
|
|
|
+/// Pops an object from the stack.
|
|
|
+void py_pop();
|
|
|
+void py_shrink(int n);
|
|
|
|
|
|
/// Pushes the object to the stack.
|
|
|
void py_pushref(const py_Ref src);
|
|
|
-/// Pops the object from the stack.
|
|
|
-void py_copyref(const py_Ref src, py_Ref dst);
|
|
|
|
|
|
+/// Get a temporary variable from the stack and returns the reference to it.
|
|
|
+py_Ref py_pushtmp();
|
|
|
+/// Free n temporary variable.
|
|
|
+void py_poptmp(int n);
|
|
|
+
|
|
|
+/************* Modules *************/
|
|
|
+py_Ref py_newmodule(const char* name, const char* package);
|
|
|
+py_Ref py_getmodule(const char* name);
|
|
|
+void py_import(const char* name, py_Ref out);
|
|
|
+
|
|
|
+/************* Errors *************/
|
|
|
+py_Error* py_getlasterror();
|
|
|
+void py_Error__print(py_Error*);
|
|
|
+
|
|
|
+int py_eq(const py_Ref, const py_Ref);
|
|
|
+int py_le(const py_Ref, const py_Ref);
|
|
|
+int py_hash(const py_Ref, int64_t* out);
|
|
|
+
|
|
|
+#define py_isnull(self) ((self)->type == 0)
|
|
|
|
|
|
/* tuple */
|
|
|
|