mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
some fix
This commit is contained in:
parent
4542f23143
commit
2540205b77
@ -1,22 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "pocketpy/pocketpy.h"
|
|
||||||
#include "pocketpy/common/str.h"
|
#include "pocketpy/common/str.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef uint16_t StrName;
|
uint16_t py_name2(c11_sv name);
|
||||||
|
c11_sv py_name2sv(uint16_t index);
|
||||||
|
|
||||||
uint16_t pk_StrName__map(const char*);
|
void py_Name__initialize();
|
||||||
uint16_t pk_StrName__map2(c11_sv);
|
void py_Name__finalize();
|
||||||
const char* pk_StrName__rmap(uint16_t index);
|
|
||||||
c11_sv pk_StrName__rmap2(uint16_t index);
|
|
||||||
|
|
||||||
void pk_StrName__initialize();
|
|
||||||
void pk_StrName__finalize();
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ typedef struct pk_TypeInfo {
|
|||||||
void (*dtor)(void*);
|
void (*dtor)(void*);
|
||||||
void (*gc_mark)(void*);
|
void (*gc_mark)(void*);
|
||||||
|
|
||||||
c11_vector /*T=StrName*/ annotated_fields;
|
c11_vector /*T=py_Name*/ annotated_fields;
|
||||||
|
|
||||||
py_CFunction on_end_subclass; // backdoor for enum module
|
py_CFunction on_end_subclass; // backdoor for enum module
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ typedef struct CodeObject {
|
|||||||
c11_vector/*T=CodeObjectByteCodeEx*/ codes_ex;
|
c11_vector/*T=CodeObjectByteCodeEx*/ codes_ex;
|
||||||
|
|
||||||
c11_vector/*T=py_TValue*/ consts; // constants
|
c11_vector/*T=py_TValue*/ consts; // constants
|
||||||
c11_vector/*T=StrName*/ varnames; // local variables
|
c11_vector/*T=py_Name*/ varnames; // local variables
|
||||||
int nlocals; // cached varnames.size()
|
int nlocals; // cached varnames.size()
|
||||||
|
|
||||||
c11_smallmap_n2i varnames_inv;
|
c11_smallmap_n2i varnames_inv;
|
||||||
|
@ -17,7 +17,7 @@ extern "C" {
|
|||||||
// } pkpy_ExceptionFrame;
|
// } pkpy_ExceptionFrame;
|
||||||
|
|
||||||
// typedef struct pkpy_Exception {
|
// typedef struct pkpy_Exception {
|
||||||
// StrName type;
|
// py_Name type;
|
||||||
// py_Str msg;
|
// py_Str msg;
|
||||||
// bool is_re;
|
// bool is_re;
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ extern "C" {
|
|||||||
// c11_vector/*T=pkpy_ExceptionFrame*/ stacktrace;
|
// c11_vector/*T=pkpy_ExceptionFrame*/ stacktrace;
|
||||||
// } pkpy_Exception;
|
// } pkpy_Exception;
|
||||||
|
|
||||||
// void pkpy_Exception__ctor(pkpy_Exception* self, StrName type);
|
// void pkpy_Exception__ctor(pkpy_Exception* self, py_Name type);
|
||||||
// void pkpy_Exception__dtor(pkpy_Exception* self);
|
// void pkpy_Exception__dtor(pkpy_Exception* self);
|
||||||
// void pkpy_Exception__stpush(pkpy_Exception* self, pk_SourceData_ src, int lineno, const char* cursor, const char* name);
|
// void pkpy_Exception__stpush(pkpy_Exception* self, pk_SourceData_ src, int lineno, const char* cursor, const char* name);
|
||||||
// py_Str pkpy_Exception__summary(pkpy_Exception* self);
|
// py_Str pkpy_Exception__summary(pkpy_Exception* self);
|
||||||
|
@ -11,7 +11,7 @@ static c11_smallmap_s2n _interned;
|
|||||||
static c11_vector /*T=char* */ _r_interned;
|
static c11_vector /*T=char* */ _r_interned;
|
||||||
static bool _initialized = false;
|
static bool _initialized = false;
|
||||||
|
|
||||||
void pk_StrName__initialize() {
|
void py_Name__initialize() {
|
||||||
if(_initialized) return;
|
if(_initialized) return;
|
||||||
c11_smallmap_s2n__ctor(&_interned);
|
c11_smallmap_s2n__ctor(&_interned);
|
||||||
for(int i = 0; i < _r_interned.count; i++) {
|
for(int i = 0; i < _r_interned.count; i++) {
|
||||||
@ -30,7 +30,7 @@ void pk_StrName__initialize() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pk_StrName__finalize() {
|
void py_Name__finalize() {
|
||||||
if(!_initialized) return;
|
if(!_initialized) return;
|
||||||
// free all char*
|
// free all char*
|
||||||
for(int i = 0; i < _r_interned.count; i++) {
|
for(int i = 0; i < _r_interned.count; i++) {
|
||||||
@ -40,19 +40,19 @@ void pk_StrName__finalize() {
|
|||||||
c11_vector__dtor(&_r_interned);
|
c11_vector__dtor(&_r_interned);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t pk_StrName__map(const char* name) {
|
py_Name py_name(const char* name) {
|
||||||
return pk_StrName__map2((c11_sv){name, strlen(name)});
|
return py_name2((c11_sv){name, strlen(name)});
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t pk_StrName__map2(c11_sv name) {
|
py_Name py_name2(c11_sv name) {
|
||||||
// TODO: PK_GLOBAL_SCOPE_LOCK()
|
// TODO: PK_GLOBAL_SCOPE_LOCK()
|
||||||
if(!_initialized) {
|
if(!_initialized) {
|
||||||
pk_StrName__initialize(); // lazy init
|
py_Name__initialize(); // lazy init
|
||||||
}
|
}
|
||||||
uint16_t index = c11_smallmap_s2n__get(&_interned, name, 0);
|
uint16_t index = c11_smallmap_s2n__get(&_interned, name, 0);
|
||||||
if(index != 0) return index;
|
if(index != 0) return index;
|
||||||
// generate new index
|
// generate new index
|
||||||
if(_interned.count > 65530) { PK_FATAL_ERROR("StrName index overflow\n"); }
|
if(_interned.count > 65530) { PK_FATAL_ERROR("py_Name index overflow\n"); }
|
||||||
// NOTE: we must allocate the string in the heap so iterators are not invalidated
|
// NOTE: we must allocate the string in the heap so iterators are not invalidated
|
||||||
char* p = malloc(name.size + 1);
|
char* p = malloc(name.size + 1);
|
||||||
memcpy(p, name.data, name.size);
|
memcpy(p, name.data, name.size);
|
||||||
@ -65,24 +65,17 @@ uint16_t pk_StrName__map2(c11_sv name) {
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* pk_StrName__rmap(uint16_t index) {
|
const char* py_name2str(py_Name index) {
|
||||||
assert(_initialized);
|
assert(_initialized);
|
||||||
assert(index > 0 && index <= _interned.count);
|
assert(index > 0 && index <= _interned.count);
|
||||||
return c11__getitem(char*, &_r_interned, index - 1);
|
return c11__getitem(char*, &_r_interned, index - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
c11_sv pk_StrName__rmap2(uint16_t index) {
|
c11_sv py_name2sv(py_Name index) {
|
||||||
const char* p = pk_StrName__rmap(index);
|
const char* p = py_name2str(index);
|
||||||
return (c11_sv){p, strlen(p)};
|
return (c11_sv){p, strlen(p)};
|
||||||
}
|
}
|
||||||
|
|
||||||
py_Name py_name(const char* name) {
|
|
||||||
return pk_StrName__map(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* py_name2str(py_Name name) {
|
|
||||||
return pk_StrName__rmap(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool py_ismagicname(py_Name name){
|
bool py_ismagicname(py_Name name){
|
||||||
return name <= __missing__;
|
return name <= __missing__;
|
||||||
|
@ -64,7 +64,7 @@ typedef struct Ctx {
|
|||||||
int curr_iblock;
|
int curr_iblock;
|
||||||
bool is_compiling_class;
|
bool is_compiling_class;
|
||||||
c11_vector /*T=Expr* */ s_expr;
|
c11_vector /*T=Expr* */ s_expr;
|
||||||
c11_vector /*T=StrName*/ global_names;
|
c11_vector /*T=py_Name*/ global_names;
|
||||||
c11_smallmap_s2n co_consts_string_dedup_map;
|
c11_smallmap_s2n co_consts_string_dedup_map;
|
||||||
} Ctx;
|
} Ctx;
|
||||||
|
|
||||||
@ -80,11 +80,11 @@ int Ctx__emit_virtual(Ctx* self, Opcode opcode, uint16_t arg, int line, bool vir
|
|||||||
void Ctx__revert_last_emit_(Ctx* self);
|
void Ctx__revert_last_emit_(Ctx* self);
|
||||||
int Ctx__emit_int(Ctx* self, int64_t value, int line);
|
int Ctx__emit_int(Ctx* self, int64_t value, int line);
|
||||||
void Ctx__patch_jump(Ctx* self, int index);
|
void Ctx__patch_jump(Ctx* self, int index);
|
||||||
bool Ctx__add_label(Ctx* self, StrName name);
|
bool Ctx__add_label(Ctx* self, py_Name name);
|
||||||
int Ctx__add_varname(Ctx* self, StrName name);
|
int Ctx__add_varname(Ctx* self, py_Name name);
|
||||||
int Ctx__add_const(Ctx* self, py_Ref);
|
int Ctx__add_const(Ctx* self, py_Ref);
|
||||||
int Ctx__add_const_string(Ctx* self, c11_sv);
|
int Ctx__add_const_string(Ctx* self, c11_sv);
|
||||||
void Ctx__emit_store_name(Ctx* self, NameScope scope, StrName name, int line);
|
void Ctx__emit_store_name(Ctx* self, NameScope scope, py_Name name, int line);
|
||||||
void Ctx__try_merge_for_iter_store(Ctx* self, int);
|
void Ctx__try_merge_for_iter_store(Ctx* self, int);
|
||||||
void Ctx__s_emit_top(Ctx*); // emit top -> pop -> delete
|
void Ctx__s_emit_top(Ctx*); // emit top -> pop -> delete
|
||||||
void Ctx__s_push(Ctx*, Expr*); // push
|
void Ctx__s_push(Ctx*, Expr*); // push
|
||||||
@ -97,7 +97,7 @@ void Ctx__s_emit_decorators(Ctx*, int count);
|
|||||||
/* expr.c */
|
/* expr.c */
|
||||||
typedef struct NameExpr {
|
typedef struct NameExpr {
|
||||||
EXPR_COMMON_HEADER
|
EXPR_COMMON_HEADER
|
||||||
StrName name;
|
py_Name name;
|
||||||
NameScope scope;
|
NameScope scope;
|
||||||
} NameExpr;
|
} NameExpr;
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ bool NameExpr__emit_store(Expr* self_, Ctx* ctx) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
NameExpr* NameExpr__new(int line, StrName name, NameScope scope) {
|
NameExpr* NameExpr__new(int line, py_Name name, NameScope scope) {
|
||||||
const static ExprVt Vt = {.emit_ = NameExpr__emit_,
|
const static ExprVt Vt = {.emit_ = NameExpr__emit_,
|
||||||
.emit_del = NameExpr__emit_del,
|
.emit_del = NameExpr__emit_del,
|
||||||
.emit_store = NameExpr__emit_store,
|
.emit_store = NameExpr__emit_store,
|
||||||
@ -630,8 +630,8 @@ static void _load_simple_expr(Ctx* ctx, c11_sv expr, int line) {
|
|||||||
// name or name.name
|
// name or name.name
|
||||||
bool is_fastpath = false;
|
bool is_fastpath = false;
|
||||||
if(is_identifier(expr)) {
|
if(is_identifier(expr)) {
|
||||||
// ctx->emit_(OP_LOAD_NAME, StrName(expr.sv()).index, line);
|
// ctx->emit_(OP_LOAD_NAME, py_Name(expr.sv()).index, line);
|
||||||
Ctx__emit_(ctx, OP_LOAD_NAME, pk_StrName__map2(expr), line);
|
Ctx__emit_(ctx, OP_LOAD_NAME, py_name2(expr), line);
|
||||||
is_fastpath = true;
|
is_fastpath = true;
|
||||||
} else {
|
} else {
|
||||||
int dot = c11_sv__index(expr, '.');
|
int dot = c11_sv__index(expr, '.');
|
||||||
@ -639,8 +639,8 @@ static void _load_simple_expr(Ctx* ctx, c11_sv expr, int line) {
|
|||||||
c11_sv a = {expr.data, dot}; // expr[:dot]
|
c11_sv a = {expr.data, dot}; // expr[:dot]
|
||||||
c11_sv b = {expr.data + (dot + 1), expr.size - (dot + 1)}; // expr[dot+1:]
|
c11_sv b = {expr.data + (dot + 1), expr.size - (dot + 1)}; // expr[dot+1:]
|
||||||
if(is_identifier(a) && is_identifier(b)) {
|
if(is_identifier(a) && is_identifier(b)) {
|
||||||
Ctx__emit_(ctx, OP_LOAD_NAME, pk_StrName__map2(a), line);
|
Ctx__emit_(ctx, OP_LOAD_NAME, py_name2(a), line);
|
||||||
Ctx__emit_(ctx, OP_LOAD_ATTR, pk_StrName__map2(b), line);
|
Ctx__emit_(ctx, OP_LOAD_ATTR, py_name2(b), line);
|
||||||
is_fastpath = true;
|
is_fastpath = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1073,7 +1073,7 @@ SubscrExpr* SubscrExpr__new(int line) {
|
|||||||
typedef struct AttribExpr {
|
typedef struct AttribExpr {
|
||||||
EXPR_COMMON_HEADER
|
EXPR_COMMON_HEADER
|
||||||
Expr* child;
|
Expr* child;
|
||||||
StrName name;
|
py_Name name;
|
||||||
} AttribExpr;
|
} AttribExpr;
|
||||||
|
|
||||||
void AttribExpr__emit_(Expr* self_, Ctx* ctx) {
|
void AttribExpr__emit_(Expr* self_, Ctx* ctx) {
|
||||||
@ -1111,7 +1111,7 @@ bool AttribExpr__emit_istore(Expr* self_, Ctx* ctx) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
AttribExpr* AttribExpr__new(int line, Expr* child, StrName name) {
|
AttribExpr* AttribExpr__new(int line, Expr* child, py_Name name) {
|
||||||
const static ExprVt Vt = {.emit_ = AttribExpr__emit_,
|
const static ExprVt Vt = {.emit_ = AttribExpr__emit_,
|
||||||
.emit_del = AttribExpr__emit_del,
|
.emit_del = AttribExpr__emit_del,
|
||||||
.emit_store = AttribExpr__emit_store,
|
.emit_store = AttribExpr__emit_store,
|
||||||
@ -1128,7 +1128,7 @@ AttribExpr* AttribExpr__new(int line, Expr* child, StrName name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef struct CallExprKwArg {
|
typedef struct CallExprKwArg {
|
||||||
StrName key;
|
py_Name key;
|
||||||
Expr* val;
|
Expr* val;
|
||||||
} CallExprKwArg;
|
} CallExprKwArg;
|
||||||
|
|
||||||
@ -1209,7 +1209,7 @@ void Ctx__ctor(Ctx* self, CodeObject* co, FuncDecl* func, int level) {
|
|||||||
self->curr_iblock = 0;
|
self->curr_iblock = 0;
|
||||||
self->is_compiling_class = false;
|
self->is_compiling_class = false;
|
||||||
c11_vector__ctor(&self->s_expr, sizeof(Expr*));
|
c11_vector__ctor(&self->s_expr, sizeof(Expr*));
|
||||||
c11_vector__ctor(&self->global_names, sizeof(StrName));
|
c11_vector__ctor(&self->global_names, sizeof(py_Name));
|
||||||
c11_smallmap_s2n__ctor(&self->co_consts_string_dedup_map);
|
c11_smallmap_s2n__ctor(&self->co_consts_string_dedup_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1326,14 +1326,14 @@ void Ctx__patch_jump(Ctx* self, int index) {
|
|||||||
Bytecode__set_signed_arg(&co_codes[index], target - index);
|
Bytecode__set_signed_arg(&co_codes[index], target - index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ctx__add_label(Ctx* self, StrName name) {
|
bool Ctx__add_label(Ctx* self, py_Name name) {
|
||||||
bool ok = c11_smallmap_n2i__contains(&self->co->labels, name);
|
bool ok = c11_smallmap_n2i__contains(&self->co->labels, name);
|
||||||
if(ok) return false;
|
if(ok) return false;
|
||||||
c11_smallmap_n2i__set(&self->co->labels, name, self->co->codes.count);
|
c11_smallmap_n2i__set(&self->co->labels, name, self->co->codes.count);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Ctx__add_varname(Ctx* self, StrName name) {
|
int Ctx__add_varname(Ctx* self, py_Name name) {
|
||||||
// PK_MAX_CO_VARNAMES will be checked when pop_context(), not here
|
// PK_MAX_CO_VARNAMES will be checked when pop_context(), not here
|
||||||
int index = c11_smallmap_n2i__get(&self->co->varnames_inv, name, -1);
|
int index = c11_smallmap_n2i__get(&self->co->varnames_inv, name, -1);
|
||||||
if(index >= 0) return index;
|
if(index >= 0) return index;
|
||||||
@ -1366,7 +1366,7 @@ int Ctx__add_const(Ctx* self, py_Ref v) {
|
|||||||
return self->co->consts.count - 1;
|
return self->co->consts.count - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ctx__emit_store_name(Ctx* self, NameScope scope, StrName name, int line) {
|
void Ctx__emit_store_name(Ctx* self, NameScope scope, py_Name name, int line) {
|
||||||
switch(scope) {
|
switch(scope) {
|
||||||
case NAME_LOCAL: Ctx__emit_(self, OP_STORE_FAST, Ctx__add_varname(self, name), line); break;
|
case NAME_LOCAL: Ctx__emit_(self, OP_STORE_FAST, Ctx__add_varname(self, name), line); break;
|
||||||
case NAME_GLOBAL: Ctx__emit_(self, OP_STORE_GLOBAL, name, line); break;
|
case NAME_GLOBAL: Ctx__emit_(self, OP_STORE_GLOBAL, name, line); break;
|
||||||
@ -1795,11 +1795,11 @@ static Error* exprGroup(Compiler* self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Error* exprName(Compiler* self) {
|
static Error* exprName(Compiler* self) {
|
||||||
StrName name = pk_StrName__map2(Token__sv(prev()));
|
py_Name name = py_name2(Token__sv(prev()));
|
||||||
NameScope scope = name_scope(self);
|
NameScope scope = name_scope(self);
|
||||||
// promote this name to global scope if needed
|
// promote this name to global scope if needed
|
||||||
c11_vector* global_names = &ctx()->global_names;
|
c11_vector* global_names = &ctx()->global_names;
|
||||||
c11__foreach(StrName, global_names, it) {
|
c11__foreach(py_Name, global_names, it) {
|
||||||
if(*it == name) scope = NAME_GLOBAL;
|
if(*it == name) scope = NAME_GLOBAL;
|
||||||
}
|
}
|
||||||
NameExpr* e = NameExpr__new(prev()->line, name, scope);
|
NameExpr* e = NameExpr__new(prev()->line, name, scope);
|
||||||
@ -1809,7 +1809,7 @@ static Error* exprName(Compiler* self) {
|
|||||||
|
|
||||||
static Error* exprAttrib(Compiler* self) {
|
static Error* exprAttrib(Compiler* self) {
|
||||||
consume(TK_ID);
|
consume(TK_ID);
|
||||||
StrName name = pk_StrName__map2(Token__sv(prev()));
|
py_Name name = py_name2(Token__sv(prev()));
|
||||||
AttribExpr* e = AttribExpr__new(prev()->line, Ctx__s_popx(ctx()), name);
|
AttribExpr* e = AttribExpr__new(prev()->line, Ctx__s_popx(ctx()), name);
|
||||||
Ctx__s_push(ctx(), (Expr*)e);
|
Ctx__s_push(ctx(), (Expr*)e);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1922,7 +1922,7 @@ static Error* exprCall(Compiler* self) {
|
|||||||
if(curr()->type == TK_RPAREN) break;
|
if(curr()->type == TK_RPAREN) break;
|
||||||
if(curr()->type == TK_ID && next()->type == TK_ASSIGN) {
|
if(curr()->type == TK_ID && next()->type == TK_ASSIGN) {
|
||||||
consume(TK_ID);
|
consume(TK_ID);
|
||||||
StrName key = pk_StrName__map2(Token__sv(prev()));
|
py_Name key = py_name2(Token__sv(prev()));
|
||||||
consume(TK_ASSIGN);
|
consume(TK_ASSIGN);
|
||||||
check(EXPR(self));
|
check(EXPR(self));
|
||||||
CallExprKwArg kw = {key, Ctx__s_popx(ctx())};
|
CallExprKwArg kw = {key, Ctx__s_popx(ctx())};
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// #include "pocketpy/common/strname.h"
|
// #include "pocketpy/common/strname.h"
|
||||||
// #include "pocketpy/common/sstream.h"
|
// #include "pocketpy/common/sstream.h"
|
||||||
|
|
||||||
// void pkpy_Exception__ctor(pkpy_Exception* self, StrName type){
|
// void pkpy_Exception__ctor(pkpy_Exception* self, py_Name type){
|
||||||
// self->type = type;
|
// self->type = type;
|
||||||
// self->is_re = true;
|
// self->is_re = true;
|
||||||
// self->_ip_on_error = -1;
|
// self->_ip_on_error = -1;
|
||||||
@ -48,7 +48,7 @@
|
|||||||
// c11_sbuf__write_cstr(&ss, "\n");
|
// c11_sbuf__write_cstr(&ss, "\n");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// const char* name = pk_StrName__rmap(self->type);
|
// const char* name = py_Name__rmap(self->type);
|
||||||
// c11_sbuf__write_cstr(&ss, name);
|
// c11_sbuf__write_cstr(&ss, name);
|
||||||
|
|
||||||
// if(self->msg.size > 0){
|
// if(self->msg.size > 0){
|
||||||
|
@ -138,7 +138,7 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) {
|
|||||||
// obj =
|
// obj =
|
||||||
// new_object<Function>(tp_function, decl, frame->_module, nullptr,
|
// new_object<Function>(tp_function, decl, frame->_module, nullptr,
|
||||||
// captured);
|
// captured);
|
||||||
// uint16_t name = pk_StrName__map2(py_Str__sv(&decl->code->name));
|
// uint16_t name = py_Name__map2(py_Str__sv(&decl->code->name));
|
||||||
// captured->set(name, obj);
|
// captured->set(name, obj);
|
||||||
// } else {
|
// } else {
|
||||||
// obj = new_object<Function>(tp_function, decl, frame->_module, nullptr,
|
// obj = new_object<Function>(tp_function, decl, frame->_module, nullptr,
|
||||||
@ -340,7 +340,7 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) {
|
|||||||
DISPATCH();
|
DISPATCH();
|
||||||
}
|
}
|
||||||
case OP_DELETE_NAME: {
|
case OP_DELETE_NAME: {
|
||||||
StrName name = byte.arg;
|
py_Name name = byte.arg;
|
||||||
if(frame->function) {
|
if(frame->function) {
|
||||||
py_TValue* slot = Frame__f_locals_try_get(frame, name);
|
py_TValue* slot = Frame__f_locals_try_get(frame, name);
|
||||||
if(slot) {
|
if(slot) {
|
||||||
@ -366,7 +366,7 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) {
|
|||||||
DISPATCH();
|
DISPATCH();
|
||||||
}
|
}
|
||||||
case OP_DELETE_GLOBAL: {
|
case OP_DELETE_GLOBAL: {
|
||||||
StrName name = byte.arg;
|
py_Name name = byte.arg;
|
||||||
bool ok = pk_NameDict__del(Frame__f_globals(frame), name);
|
bool ok = pk_NameDict__del(Frame__f_globals(frame), name);
|
||||||
if(!ok) {
|
if(!ok) {
|
||||||
NameError(name);
|
NameError(name);
|
||||||
@ -598,7 +598,7 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) {
|
|||||||
DISPATCH_JUMP_ABSOLUTE(target);
|
DISPATCH_JUMP_ABSOLUTE(target);
|
||||||
}
|
}
|
||||||
// case OP_GOTO: {
|
// case OP_GOTO: {
|
||||||
// StrName _name(byte.arg);
|
// py_Name _name(byte.arg);
|
||||||
// int target = c11_smallmap_n2i__get(&frame->co->labels, byte.arg, -1);
|
// int target = c11_smallmap_n2i__get(&frame->co->labels, byte.arg, -1);
|
||||||
// if(target < 0) RuntimeError(_S("label ", _name.escape(), " not found"));
|
// if(target < 0) RuntimeError(_S("label ", _name.escape(), " not found"));
|
||||||
// frame->prepare_jump_break(&s_data, target);
|
// frame->prepare_jump_break(&s_data, target);
|
||||||
|
@ -132,7 +132,7 @@ void Frame__set_unwind_target(Frame* self, py_TValue* sp) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
py_TValue* Frame__f_closure_try_get(Frame* self, StrName name){
|
py_TValue* Frame__f_closure_try_get(Frame* self, py_Name name){
|
||||||
// if(self->function == NULL) return NULL;
|
// if(self->function == NULL) return NULL;
|
||||||
// pkpy::Function* fn = PyObject__as(pkpy::Function, self->function);
|
// pkpy::Function* fn = PyObject__as(pkpy::Function, self->function);
|
||||||
// if(fn->_closure == nullptr) return nullptr;
|
// if(fn->_closure == nullptr) return nullptr;
|
||||||
|
@ -11,7 +11,7 @@ static pk_VM pk_default_vm;
|
|||||||
|
|
||||||
void py_initialize() {
|
void py_initialize() {
|
||||||
pk_MemoryPools__initialize();
|
pk_MemoryPools__initialize();
|
||||||
pk_StrName__initialize();
|
py_Name__initialize();
|
||||||
pk_current_vm = &pk_default_vm;
|
pk_current_vm = &pk_default_vm;
|
||||||
pk_VM__ctor(&pk_default_vm);
|
pk_VM__ctor(&pk_default_vm);
|
||||||
}
|
}
|
||||||
@ -19,7 +19,7 @@ void py_initialize() {
|
|||||||
void py_finalize() {
|
void py_finalize() {
|
||||||
pk_VM__dtor(&pk_default_vm);
|
pk_VM__dtor(&pk_default_vm);
|
||||||
pk_current_vm = NULL;
|
pk_current_vm = NULL;
|
||||||
pk_StrName__finalize();
|
py_Name__finalize();
|
||||||
pk_MemoryPools__finalize();
|
pk_MemoryPools__finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user