mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
global replace
This commit is contained in:
parent
773a05e25c
commit
a55d3a5340
@ -43,8 +43,8 @@
|
||||
|
||||
/*************** internal settings ***************/
|
||||
|
||||
// This is the maximum size of the value stack in PyVar units
|
||||
// The actual size in bytes equals `sizeof(PyVar) * PK_VM_STACK_SIZE`
|
||||
// This is the maximum size of the value stack in py_TValue units
|
||||
// The actual size in bytes equals `sizeof(py_TValue) * PK_VM_STACK_SIZE`
|
||||
#define PK_VM_STACK_SIZE 16384
|
||||
|
||||
// This is the maximum number of local variables in a function
|
||||
|
@ -11,14 +11,14 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
PyVar* FastLocals__try_get_by_name(PyVar* locals, const CodeObject* co, py_Name name);
|
||||
pk_NameDict* FastLocals__to_namedict(PyVar* locals, const CodeObject* co);
|
||||
py_TValue* FastLocals__try_get_by_name(py_TValue* locals, const CodeObject* co, py_Name name);
|
||||
pk_NameDict* FastLocals__to_namedict(py_TValue* locals, const CodeObject* co);
|
||||
|
||||
typedef struct ValueStack {
|
||||
// We allocate extra PK_VM_STACK_SIZE/128 places to keep `_sp` valid when `is_overflow() == true`.
|
||||
PyVar* sp;
|
||||
PyVar* end;
|
||||
PyVar begin[PK_VM_STACK_SIZE + PK_VM_STACK_SIZE / 128];
|
||||
py_TValue* sp;
|
||||
py_TValue* end;
|
||||
py_TValue begin[PK_VM_STACK_SIZE + PK_VM_STACK_SIZE / 128];
|
||||
} ValueStack;
|
||||
|
||||
void ValueStack__ctor(ValueStack* self);
|
||||
@ -39,14 +39,14 @@ typedef struct Frame {
|
||||
const CodeObject* co;
|
||||
PyObject* module;
|
||||
PyObject* function; // a function object or NULL (global scope)
|
||||
PyVar* p0; // unwinding base
|
||||
PyVar* locals; // locals base
|
||||
py_TValue* p0; // unwinding base
|
||||
py_TValue* locals; // locals base
|
||||
const CodeObject* locals_co;
|
||||
UnwindTarget* uw_list;
|
||||
} Frame;
|
||||
|
||||
|
||||
Frame* Frame__new(const CodeObject* co, const PyVar* module, const PyVar* function, PyVar* p0, PyVar* locals, const CodeObject* locals_co);
|
||||
Frame* Frame__new(const CodeObject* co, const py_TValue* module, const py_TValue* function, py_TValue* p0, py_TValue* locals, const CodeObject* locals_co);
|
||||
void Frame__delete(Frame* self);
|
||||
|
||||
PK_INLINE int Frame__ip(const Frame* self){
|
||||
@ -67,11 +67,11 @@ PK_INLINE pk_NameDict* Frame__f_globals(Frame* self){
|
||||
return PyObject__dict(self->module);
|
||||
}
|
||||
|
||||
PK_INLINE PyVar* Frame__f_globals_try_get(Frame* self, py_Name name){
|
||||
PK_INLINE py_TValue* Frame__f_globals_try_get(Frame* self, py_Name name){
|
||||
return pk_NameDict__try_get(Frame__f_globals(self), name);
|
||||
}
|
||||
|
||||
PyVar* Frame__f_closure_try_get(Frame* self, py_Name name);
|
||||
py_TValue* Frame__f_closure_try_get(Frame* self, py_Name name);
|
||||
|
||||
int Frame__prepare_jump_exception_handler(Frame* self, ValueStack*);
|
||||
void Frame__prepare_jump_break(Frame* self, ValueStack*, int);
|
||||
@ -80,7 +80,7 @@ int Frame__exit_block(Frame* self, ValueStack*, int);
|
||||
|
||||
void Frame__gc_mark(Frame* self);
|
||||
UnwindTarget* Frame__find_unwind_target(Frame* self, int iblock);
|
||||
void Frame__set_unwind_target(Frame* self, PyVar* sp);
|
||||
void Frame__set_unwind_target(Frame* self, py_TValue* sp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@ -92,7 +92,7 @@ void Frame__set_unwind_target(Frame* self, PyVar* sp);
|
||||
#include "pocketpy/objects/codeobject.hpp"
|
||||
|
||||
extern "C"{
|
||||
inline PyVar* Frame__f_closure_try_get(Frame* self, StrName name){
|
||||
inline py_TValue* Frame__f_closure_try_get(Frame* self, StrName name){
|
||||
if(self->function == NULL) return NULL;
|
||||
pkpy::Function* fn = PyObject__as(pkpy::Function, self->function);
|
||||
if(fn->_closure == nullptr) return nullptr;
|
||||
|
@ -12,8 +12,8 @@ typedef struct pk_TypeInfo{
|
||||
py_Name name;
|
||||
py_Type base;
|
||||
|
||||
PyVar self; // the type object itself
|
||||
PyVar module; // the module where the type is defined
|
||||
py_TValue self; // the type object itself
|
||||
py_TValue module; // the module where the type is defined
|
||||
bool subclass_enabled;
|
||||
|
||||
void (*dtor)(void*);
|
||||
@ -38,7 +38,7 @@ typedef struct pk_TypeInfo{
|
||||
py_CFunction on_end_subclass; // for enum module
|
||||
} pk_TypeInfo;
|
||||
|
||||
void pk_TypeInfo__ctor(pk_TypeInfo* self, py_Name name, py_Type base, PyObject* obj, const PyVar* module, bool subclass_enabled);
|
||||
void pk_TypeInfo__ctor(pk_TypeInfo* self, py_Name name, py_Type base, PyObject* obj, const py_TValue* module, bool subclass_enabled);
|
||||
void pk_TypeInfo__dtor(pk_TypeInfo* self);
|
||||
|
||||
typedef struct pk_VM {
|
||||
@ -47,24 +47,24 @@ typedef struct pk_VM {
|
||||
pk_NameDict modules;
|
||||
c11_vector/*T=pk_TypeInfo*/ types;
|
||||
|
||||
PyVar StopIteration; // a special Exception class
|
||||
PyVar builtins; // builtins module
|
||||
PyVar main; // __main__ module
|
||||
py_TValue StopIteration; // a special Exception class
|
||||
py_TValue builtins; // builtins module
|
||||
py_TValue main; // __main__ module
|
||||
|
||||
void (*_ceval_on_step)(Frame*, Bytecode);
|
||||
unsigned char* (*_import_file)(const char*);
|
||||
void (*_stdout)(const char*);
|
||||
void (*_stderr)(const char*);
|
||||
void (*_stdout)(const char*, ...);
|
||||
void (*_stderr)(const char*, ...);
|
||||
|
||||
// singleton objects
|
||||
PyVar True, False, None, NotImplemented, Ellipsis;
|
||||
py_TValue True, False, None, NotImplemented, Ellipsis;
|
||||
// last error
|
||||
py_Error* last_error;
|
||||
|
||||
PyObject* __curr_class;
|
||||
PyObject* __cached_object_new;
|
||||
FuncDecl_ __dynamic_func_decl;
|
||||
PyVar __vectorcall_buffer[PK_MAX_CO_VARNAMES];
|
||||
py_TValue __vectorcall_buffer[PK_MAX_CO_VARNAMES];
|
||||
|
||||
pk_ManagedHeap heap;
|
||||
ValueStack stack; // put `stack` at the end for better cache locality
|
||||
@ -87,7 +87,7 @@ typedef enum pk_FrameResult{
|
||||
|
||||
pk_FrameResult pk_VM__run_top_frame(pk_VM* self);
|
||||
|
||||
py_Type pk_VM__new_type(pk_VM* self, const char* name, py_Type base, const PyVar* module, bool subclass_enabled);
|
||||
py_Type pk_VM__new_type(pk_VM* self, const char* name, py_Type base, const py_TValue* module, bool subclass_enabled);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -14,8 +14,9 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int16_t py_Type;
|
||||
typedef struct PyObject PyObject;
|
||||
|
||||
typedef struct PyVar{
|
||||
typedef struct py_TValue{
|
||||
py_Type type;
|
||||
bool is_ptr;
|
||||
int extra;
|
||||
@ -26,9 +27,9 @@ typedef struct PyVar{
|
||||
void* _ptr;
|
||||
// Vec2
|
||||
};
|
||||
} PyVar;
|
||||
} py_TValue;
|
||||
|
||||
static_assert(sizeof(PyVar) <= 16, "!sizeof(PyVar) <= 16");
|
||||
static_assert(sizeof(py_TValue) <= 16, "!sizeof(py_TValue) <= 16");
|
||||
|
||||
/* predefined vars */
|
||||
static const py_Type tp_object = {1}, tp_type = {2};
|
||||
@ -44,7 +45,7 @@ static const py_Type tp_ellipsis = {26};
|
||||
static const py_Type tp_op_call = {27}, tp_op_yield = {28};
|
||||
static const py_Type tp_syntax_error = {29}, tp_stop_iteration = {30};
|
||||
|
||||
extern PyVar PY_NULL, PY_OP_CALL, PY_OP_YIELD;
|
||||
extern py_TValue PY_NULL, PY_OP_CALL, PY_OP_YIELD;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ typedef struct CodeObject {
|
||||
c11_vector/*T=Bytecode*/ codes;
|
||||
c11_vector/*T=CodeObjectByteCodeEx*/ codes_ex;
|
||||
|
||||
c11_vector/*T=PyVar*/ consts; // constants
|
||||
c11_vector/*T=py_TValue*/ consts; // constants
|
||||
c11_vector/*T=StrName*/ varnames; // local variables
|
||||
int nlocals; // cached varnames.size()
|
||||
|
||||
@ -95,7 +95,7 @@ void CodeObject__gc_mark(const CodeObject* self);
|
||||
typedef struct FuncDeclKwArg{
|
||||
int index; // index in co->varnames
|
||||
uint16_t key; // name of this argument
|
||||
PyVar value; // default value
|
||||
py_TValue value; // default value
|
||||
} FuncDeclKwArg;
|
||||
|
||||
typedef struct FuncDecl {
|
||||
@ -119,7 +119,7 @@ typedef FuncDecl* FuncDecl_;
|
||||
|
||||
FuncDecl_ FuncDecl__rcnew(pk_SourceData_ src, c11_string name);
|
||||
void FuncDecl__dtor(FuncDecl* self);
|
||||
void FuncDecl__add_kwarg(FuncDecl* self, int index, uint16_t key, const PyVar* value);
|
||||
void FuncDecl__add_kwarg(FuncDecl* self, int index, uint16_t key, const py_TValue* value);
|
||||
void FuncDecl__gc_mark(const FuncDecl* self);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -49,7 +49,7 @@ pkpy_Dict pkpy_Dict__copy(const pkpy_Dict* self);
|
||||
* @param val value to set
|
||||
* @return `true` if the key is newly added, `false` if the key already exists
|
||||
*/
|
||||
bool pkpy_Dict__set(pkpy_Dict* self, PyVar key, PyVar val);
|
||||
bool pkpy_Dict__set(pkpy_Dict* self, py_TValue key, py_TValue val);
|
||||
|
||||
/**
|
||||
* @brief Check if a key exists in the `pkpy_Dict`
|
||||
@ -58,7 +58,7 @@ bool pkpy_Dict__set(pkpy_Dict* self, PyVar key, PyVar val);
|
||||
* @param key key to check
|
||||
* @return `true` if the key exists, `false` otherwise
|
||||
*/
|
||||
bool pkpy_Dict__contains(const pkpy_Dict* self, PyVar key);
|
||||
bool pkpy_Dict__contains(const pkpy_Dict* self, py_TValue key);
|
||||
|
||||
/**
|
||||
* @brief Remove a key from the `pkpy_Dict`
|
||||
@ -67,7 +67,7 @@ bool pkpy_Dict__contains(const pkpy_Dict* self, PyVar key);
|
||||
* @param key key to remove
|
||||
* @return `true` if the key was found and removed, `false` if the key doesn't exist
|
||||
*/
|
||||
bool pkpy_Dict__del(pkpy_Dict* self, PyVar key);
|
||||
bool pkpy_Dict__del(pkpy_Dict* self, py_TValue key);
|
||||
|
||||
/**
|
||||
* @brief Try to get a value from the `pkpy_Dict`
|
||||
@ -76,7 +76,7 @@ bool pkpy_Dict__del(pkpy_Dict* self, PyVar key);
|
||||
* @param key key to get
|
||||
* @return the value associated with the key, `NULL` if the key doesn't exist
|
||||
*/
|
||||
const PyVar* pkpy_Dict__try_get(const pkpy_Dict* self, PyVar key);
|
||||
const py_TValue* pkpy_Dict__try_get(const pkpy_Dict* self, py_TValue key);
|
||||
|
||||
/**
|
||||
* @brief Update the `pkpy_Dict` with another one
|
||||
@ -106,7 +106,7 @@ pkpy_DictIter pkpy_Dict__iter(const pkpy_Dict* self);
|
||||
* @param value value will be filled with the current value, can be `NULL` if not needed
|
||||
* @return `true` if the iteration is still valid, `false` otherwise
|
||||
*/
|
||||
bool pkpy_DictIter__next(pkpy_DictIter* self, PyVar* key, PyVar* value);
|
||||
bool pkpy_DictIter__next(pkpy_DictIter* self, py_TValue* key, py_TValue* value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ extern "C" {
|
||||
|
||||
#define SMALLMAP_T__HEADER
|
||||
#define K uint16_t
|
||||
#define V PyVar
|
||||
#define V py_TValue
|
||||
#define NAME pk_NameDict
|
||||
#include "pocketpy/xmacros/smallmap.h"
|
||||
#undef SMALLMAP_T__HEADER
|
||||
|
@ -22,18 +22,18 @@ typedef struct PyObject{
|
||||
|
||||
static_assert(sizeof(PyObject) <= 8, "!(sizeof(PyObject) <= 8)");
|
||||
|
||||
PyVar* PyObject__slots(PyObject* self);
|
||||
py_TValue* PyObject__slots(PyObject* self);
|
||||
pk_NameDict* PyObject__dict(PyObject* self);
|
||||
void* PyObject__value(PyObject* self);
|
||||
|
||||
#define PK_OBJ_HEADER_SIZE(slots) ((slots)>=0 ? 8+sizeof(PyVar)*(slots) : 8+sizeof(pk_NameDict))
|
||||
#define PK_OBJ_HEADER_SIZE(slots) ((slots)>=0 ? 8+sizeof(py_TValue)*(slots) : 8+sizeof(pk_NameDict))
|
||||
|
||||
PyObject* PyObject__new(py_Type type, int slots, int size);
|
||||
void PyObject__delete(PyObject* self);
|
||||
|
||||
PK_INLINE PyVar PyVar__fromobj(PyObject* obj){
|
||||
PK_INLINE py_TValue PyVar__fromobj(PyObject* obj){
|
||||
if(!obj) return PY_NULL;
|
||||
PyVar retval = {
|
||||
py_TValue retval = {
|
||||
.type = obj->type,
|
||||
.is_ptr = true,
|
||||
._obj = obj
|
||||
|
@ -4,12 +4,12 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
/************* Public Types *************/
|
||||
typedef struct PyObject PyObject;
|
||||
typedef struct PyVar PyVar;
|
||||
typedef struct py_TValue py_TValue;
|
||||
typedef struct pk_VM pk_VM;
|
||||
typedef uint16_t py_Name;
|
||||
typedef int16_t py_Type;
|
||||
typedef PyVar* py_Ref;
|
||||
typedef py_TValue* py_Ref;
|
||||
typedef struct py_Str py_Str;
|
||||
typedef int (*py_CFunction)(int argc, py_Ref argv);
|
||||
|
||||
typedef struct py_Error{
|
||||
@ -175,8 +175,8 @@ void py_dict__setitem(py_Ref self, const py_Ref key, const py_Ref val);
|
||||
void py_dict__delitem(py_Ref self, const py_Ref key);
|
||||
void py_dict__clear(py_Ref self);
|
||||
|
||||
int py_str(const py_Ref, char* out);
|
||||
int py_repr(const py_Ref, char* out);
|
||||
int py_str(const py_Ref, py_Str* out);
|
||||
int py_repr(const py_Ref, py_Str* out);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ typedef struct ImagExpr {
|
||||
|
||||
void ImagExpr__emit_(Expr* self_, Ctx* ctx) {
|
||||
ImagExpr* self = (ImagExpr*)self_;
|
||||
PyVar value;
|
||||
py_TValue value;
|
||||
py_newfloat(&value, self->value);
|
||||
int index = Ctx__add_const(ctx, &value);
|
||||
Ctx__emit_(ctx, OP_LOAD_CONST, index, self->line);
|
||||
@ -282,7 +282,7 @@ void LiteralExpr__emit_(Expr* self_, Ctx* ctx) {
|
||||
break;
|
||||
}
|
||||
case TokenValue_F64: {
|
||||
PyVar value;
|
||||
py_TValue value;
|
||||
py_newfloat(&value, self->value->_f64);
|
||||
int index = Ctx__add_const(ctx, &value);
|
||||
Ctx__emit_(ctx, OP_LOAD_CONST, index, self->line);
|
||||
@ -1331,7 +1331,7 @@ int Ctx__emit_int(Ctx* self, int64_t value, int line) {
|
||||
if(is_small_int(value)) {
|
||||
return Ctx__emit_(self, OP_LOAD_SMALL_INT, (uint16_t)value, line);
|
||||
} else {
|
||||
PyVar tmp;
|
||||
py_TValue tmp;
|
||||
py_newint(&tmp, value);
|
||||
return Ctx__emit_(self, OP_LOAD_CONST, Ctx__add_const(self, &tmp), line);
|
||||
}
|
||||
@ -1366,9 +1366,9 @@ int Ctx__add_const_string(Ctx* self, c11_string key) {
|
||||
if(val) {
|
||||
return *val;
|
||||
} else {
|
||||
PyVar tmp;
|
||||
py_TValue tmp;
|
||||
py_newstrn(&tmp, key.data, key.size);
|
||||
c11_vector__push(PyVar, &self->co->consts, tmp);
|
||||
c11_vector__push(py_TValue, &self->co->consts, tmp);
|
||||
int index = self->co->consts.count - 1;
|
||||
c11_smallmap_s2n__set(&self->co_consts_string_dedup_map,
|
||||
py_Str__sv(PyObject__value(tmp._obj)),
|
||||
@ -1379,7 +1379,7 @@ int Ctx__add_const_string(Ctx* self, c11_string key) {
|
||||
|
||||
int Ctx__add_const(Ctx* self, py_Ref v) {
|
||||
assert(v->type != tp_str);
|
||||
c11_vector__push(PyVar, &self->co->consts, *v);
|
||||
c11_vector__push(py_TValue, &self->co->consts, *v);
|
||||
return self->co->consts.count - 1;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
1151
src/interpreter/ceval.cpp
Normal file
1151
src/interpreter/ceval.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -10,16 +10,16 @@ void ValueStack__clear(ValueStack* self) {
|
||||
self->sp = self->begin;
|
||||
}
|
||||
|
||||
PyVar* FastLocals__try_get_by_name(PyVar* locals, const CodeObject* co, py_Name name){
|
||||
py_TValue* FastLocals__try_get_by_name(py_TValue* locals, const CodeObject* co, py_Name name){
|
||||
int index = c11_smallmap_n2i__get(&co->varnames_inv, name, -1);
|
||||
if(index == -1) return NULL;
|
||||
return &locals[index];
|
||||
}
|
||||
|
||||
pk_NameDict* FastLocals__to_namedict(PyVar* locals, const CodeObject* co) {
|
||||
pk_NameDict* FastLocals__to_namedict(py_TValue* locals, const CodeObject* co) {
|
||||
pk_NameDict* dict = pk_NameDict__new();
|
||||
c11__foreach(c11_smallmap_n2i_KV, &co->varnames_inv, entry) {
|
||||
PyVar value = locals[entry->value];
|
||||
py_TValue value = locals[entry->value];
|
||||
if(!py_isnull(&value)){
|
||||
pk_NameDict__set(dict, entry->key, value);
|
||||
}
|
||||
@ -39,7 +39,7 @@ void UnwindTarget__delete(UnwindTarget* self){
|
||||
free(self);
|
||||
}
|
||||
|
||||
Frame* Frame__new(const CodeObject* co, const PyVar* module, const PyVar* function, PyVar* p0, PyVar* locals, const CodeObject* locals_co){
|
||||
Frame* Frame__new(const CodeObject* co, const py_TValue* module, const py_TValue* function, py_TValue* p0, py_TValue* locals, const CodeObject* locals_co){
|
||||
static_assert(sizeof(Frame) <= kPoolFrameBlockSize, "!(sizeof(Frame) <= kPoolFrameBlockSize)");
|
||||
Frame* self = PoolFrame_alloc();
|
||||
self->f_back = NULL;
|
||||
@ -72,7 +72,7 @@ int Frame__prepare_jump_exception_handler(Frame* self, ValueStack* _s){
|
||||
iblock = block->parent;
|
||||
}
|
||||
if(iblock < 0) return -1;
|
||||
PyVar obj = *--_s->sp; // pop exception object
|
||||
py_TValue obj = *--_s->sp; // pop exception object
|
||||
UnwindTarget* uw = Frame__find_unwind_target(self, iblock);
|
||||
_s->sp = (self->locals + uw->offset); // unwind the stack
|
||||
*(_s->sp++) = obj; // push it back
|
||||
@ -121,7 +121,7 @@ UnwindTarget* Frame__find_unwind_target(Frame* self, int iblock){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Frame__set_unwind_target(Frame* self, PyVar* sp) {
|
||||
void Frame__set_unwind_target(Frame* self, py_TValue* sp) {
|
||||
int iblock = Frame__iblock(self);
|
||||
UnwindTarget* existing = Frame__find_unwind_target(self, iblock);
|
||||
if(existing) {
|
||||
|
@ -119,7 +119,7 @@ PyObject* PyObject__new(py_Type type, int slots, int size){
|
||||
// initialize slots or dict
|
||||
void* p = (char*)self + 8;
|
||||
if(slots >= 0){
|
||||
memset(p, 0, slots*sizeof(PyVar));
|
||||
memset(p, 0, slots*sizeof(py_TValue));
|
||||
}else{
|
||||
pk_NameDict__ctor(p);
|
||||
}
|
||||
|
@ -7,17 +7,23 @@ static unsigned char* pk_default_import_file(const char* path){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void pk_default_stdout(const char* s){
|
||||
fprintf(stdout, "%s", s);
|
||||
static void pk_default_stdout(const char* fmt, ...){
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vfprintf(stdout, fmt, args);
|
||||
va_end(args);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
static void pk_default_stderr(const char* s){
|
||||
fprintf(stderr, "%s", s);
|
||||
static void pk_default_stderr(const char* fmt, ...){
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
void pk_TypeInfo__ctor(pk_TypeInfo *self, py_Name name, py_Type base, PyObject* obj, const PyVar* module, bool subclass_enabled){
|
||||
void pk_TypeInfo__ctor(pk_TypeInfo *self, py_Name name, py_Type base, PyObject* obj, const py_TValue* module, bool subclass_enabled){
|
||||
memset(self, 0, sizeof(pk_TypeInfo));
|
||||
|
||||
self->name = name;
|
||||
@ -58,19 +64,19 @@ void pk_VM__ctor(pk_VM* self){
|
||||
pk_ManagedHeap__ctor(&self->heap, self);
|
||||
ValueStack__ctor(&self->stack);
|
||||
|
||||
self->True = (PyVar){.type=tp_bool, .is_ptr=true, .extra=1,
|
||||
self->True = (py_TValue){.type=tp_bool, .is_ptr=true, .extra=1,
|
||||
._obj=pk_ManagedHeap__gcnew(&self->heap, tp_bool, 0, 0),
|
||||
};
|
||||
self->False = (PyVar){.type=tp_bool, .is_ptr=true, .extra=0,
|
||||
self->False = (py_TValue){.type=tp_bool, .is_ptr=true, .extra=0,
|
||||
._obj=pk_ManagedHeap__gcnew(&self->heap, tp_bool, 0, 0),
|
||||
};
|
||||
self->None = (PyVar){.type=tp_none_type, .is_ptr=true,
|
||||
self->None = (py_TValue){.type=tp_none_type, .is_ptr=true,
|
||||
._obj=pk_ManagedHeap__gcnew(&self->heap, tp_none_type, 0, 0),
|
||||
};
|
||||
self->NotImplemented = (PyVar){.type=tp_not_implemented_type, .is_ptr=true,
|
||||
self->NotImplemented = (py_TValue){.type=tp_not_implemented_type, .is_ptr=true,
|
||||
._obj=pk_ManagedHeap__gcnew(&self->heap, tp_not_implemented_type, 0, 0),
|
||||
};
|
||||
self->Ellipsis = (PyVar){.type=tp_ellipsis, .is_ptr=true,
|
||||
self->Ellipsis = (py_TValue){.type=tp_ellipsis, .is_ptr=true,
|
||||
._obj=pk_ManagedHeap__gcnew(&self->heap, tp_ellipsis, 0, 0),
|
||||
};
|
||||
|
||||
@ -169,11 +175,7 @@ void pk_VM__pop_frame(pk_VM* self){
|
||||
Frame__delete(frame);
|
||||
}
|
||||
|
||||
pk_FrameResult pk_VM__run_top_frame(pk_VM* self){
|
||||
return RES_RETURN;
|
||||
}
|
||||
|
||||
py_Type pk_VM__new_type(pk_VM* self, const char* name, py_Type base, const PyVar* module, bool subclass_enabled){
|
||||
py_Type pk_VM__new_type(pk_VM* self, const char* name, py_Type base, const py_TValue* module, bool subclass_enabled){
|
||||
py_Type type = self->types.count;
|
||||
pk_TypeInfo* ti = c11_vector__emplace(&self->types);
|
||||
PyObject* typeobj = pk_ManagedHeap__gcnew(&self->heap, tp_type, -1, sizeof(py_Type));
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "pocketpy/objects/base.h"
|
||||
|
||||
PyVar PY_NULL = {.type=0, .is_ptr=false, .extra=0, ._i64=0};
|
||||
PyVar PY_OP_CALL = {.type=27, .is_ptr=false, .extra=0, ._i64=0};
|
||||
PyVar PY_OP_YIELD = {.type=28, .is_ptr=false, .extra=0, ._i64=0};
|
||||
py_TValue PY_NULL = {.type=0, .is_ptr=false, .extra=0, ._i64=0};
|
||||
py_TValue PY_OP_CALL = {.type=27, .is_ptr=false, .extra=0, ._i64=0};
|
||||
py_TValue PY_OP_YIELD = {.type=28, .is_ptr=false, .extra=0, ._i64=0};
|
||||
|
||||
|
@ -40,7 +40,7 @@ void FuncDecl__dtor(FuncDecl* self) {
|
||||
c11_smallmap_n2i__dtor(&self->kw_to_index);
|
||||
}
|
||||
|
||||
void FuncDecl__add_kwarg(FuncDecl* self, int index, uint16_t key, const PyVar* value) {
|
||||
void FuncDecl__add_kwarg(FuncDecl* self, int index, uint16_t key, const py_TValue* value) {
|
||||
c11_smallmap_n2i__set(&self->kw_to_index, key, index);
|
||||
FuncDeclKwArg item = {index, key, *value};
|
||||
c11_vector__push(FuncDeclKwArg, &self->kwargs, item);
|
||||
@ -54,7 +54,7 @@ void CodeObject__ctor(CodeObject* self, pk_SourceData_ src, c11_string name) {
|
||||
c11_vector__ctor(&self->codes, sizeof(Bytecode));
|
||||
c11_vector__ctor(&self->codes_ex, sizeof(BytecodeEx));
|
||||
|
||||
c11_vector__ctor(&self->consts, sizeof(PyVar));
|
||||
c11_vector__ctor(&self->consts, sizeof(py_TValue));
|
||||
c11_vector__ctor(&self->varnames, sizeof(uint16_t));
|
||||
self->nlocals = 0;
|
||||
|
||||
|
@ -13,8 +13,8 @@
|
||||
#define pkpy_Var__set_null(self) do { (self)->type = 0; } while(0)
|
||||
|
||||
struct pkpy_DictEntry {
|
||||
PyVar key;
|
||||
PyVar val;
|
||||
py_TValue key;
|
||||
py_TValue val;
|
||||
};
|
||||
|
||||
inline extern int pkpy_Dict__idx_size(const pkpy_Dict* self) {
|
||||
@ -79,7 +79,7 @@ static void pkpy_Dict__htset(pkpy_Dict* self, int h, int v) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static int pkpy_Dict__probe0(const pkpy_Dict* self, PyVar key, int hash) {
|
||||
static int pkpy_Dict__probe0(const pkpy_Dict* self, py_TValue key, int hash) {
|
||||
const int null = pkpy_Dict__idx_null(self);
|
||||
const int mask = self->_htcap - 1;
|
||||
for(int h = hash & mask;; h = DICT_HASH_NEXT(h) & mask) {
|
||||
@ -92,7 +92,7 @@ static int pkpy_Dict__probe0(const pkpy_Dict* self, PyVar key, int hash) {
|
||||
PK_UNREACHABLE();
|
||||
}
|
||||
|
||||
static int pkpy_Dict__probe1(const pkpy_Dict* self, PyVar key, int hash) {
|
||||
static int pkpy_Dict__probe1(const pkpy_Dict* self, py_TValue key, int hash) {
|
||||
const int null = pkpy_Dict__idx_null(self);
|
||||
const int mask = self->_htcap - 1;
|
||||
for(int h = hash & mask;; h = DICT_HASH_NEXT(h) & mask) {
|
||||
@ -124,7 +124,7 @@ static void pkpy_Dict__extendht(pkpy_Dict* self) {
|
||||
}
|
||||
}
|
||||
|
||||
bool pkpy_Dict__set(pkpy_Dict* self, PyVar key, PyVar val) {
|
||||
bool pkpy_Dict__set(pkpy_Dict* self, py_TValue key, py_TValue val) {
|
||||
int64_t out;
|
||||
int err = py_hash(&key, &out);
|
||||
int hash = DICT_HASH_TRANS(out);
|
||||
@ -161,7 +161,7 @@ bool pkpy_Dict__set(pkpy_Dict* self, PyVar key, PyVar val) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool pkpy_Dict__contains(const pkpy_Dict* self, PyVar key) {
|
||||
bool pkpy_Dict__contains(const pkpy_Dict* self, py_TValue key) {
|
||||
int64_t out;
|
||||
int err = py_hash(&key, &out);
|
||||
int hash = DICT_HASH_TRANS(out);
|
||||
@ -205,7 +205,7 @@ static bool pkpy_Dict__refactor(pkpy_Dict* self) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pkpy_Dict__del(pkpy_Dict* self, PyVar key) {
|
||||
bool pkpy_Dict__del(pkpy_Dict* self, py_TValue key) {
|
||||
int64_t out;
|
||||
int err = py_hash(&key, &out);
|
||||
int hash = DICT_HASH_TRANS(out);
|
||||
@ -220,7 +220,7 @@ bool pkpy_Dict__del(pkpy_Dict* self, PyVar key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const PyVar *pkpy_Dict__try_get(const pkpy_Dict* self, PyVar key) {
|
||||
const py_TValue *pkpy_Dict__try_get(const pkpy_Dict* self, py_TValue key) {
|
||||
int64_t out;
|
||||
int err = py_hash(&key, &out);
|
||||
int hash = DICT_HASH_TRANS(out);
|
||||
@ -263,7 +263,7 @@ pkpy_DictIter pkpy_Dict__iter(const pkpy_Dict *self) {
|
||||
};
|
||||
}
|
||||
|
||||
bool pkpy_DictIter__next(pkpy_DictIter *self, PyVar *key, PyVar *val) {
|
||||
bool pkpy_DictIter__next(pkpy_DictIter *self, py_TValue *key, py_TValue *val) {
|
||||
if(self->_index >= self->_dict->_entries.count) return false;
|
||||
|
||||
struct pkpy_DictEntry* entry = &c11__getitem(struct pkpy_DictEntry, &self->_dict->_entries, self->_index);
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#define SMALLMAP_T__SOURCE
|
||||
#define K uint16_t
|
||||
#define V PyVar
|
||||
#define V py_TValue
|
||||
#define NAME pk_NameDict
|
||||
#include "pocketpy/xmacros/smallmap.h"
|
||||
#undef SMALLMAP_T__SOURCE
|
||||
|
@ -11,7 +11,7 @@ pk_NameDict* PyObject__dict(PyObject* self){
|
||||
return (pk_NameDict*)((char*)self + 8);
|
||||
}
|
||||
|
||||
PyVar* PyObject__slots(PyObject* self){
|
||||
py_TValue* PyObject__slots(PyObject* self){
|
||||
assert(self->slots >= 0);
|
||||
return (PyVar*)((char*)self + 8);
|
||||
return (py_TValue*)((char*)self + 8);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user