This commit is contained in:
blueloveTH 2023-05-21 18:32:50 +08:00
parent 62a66339c5
commit fadb1dfcf2
6 changed files with 10 additions and 23 deletions

View File

@ -65,8 +65,6 @@ struct CodeObject {
NameDictInt labels;
std::vector<FuncDecl_> func_decls;
void optimize(VM* vm);
void _gc_mark() const {
for(PyObject* v : consts) OBJ_MARK(v);
for(auto& decl: func_decls) decl->_gc_mark();

View File

@ -161,7 +161,4 @@ inline PyObject* const PY_BEGIN_CALL = (PyObject*)0b010011;
inline PyObject* const PY_OP_CALL = (PyObject*)0b100011;
inline PyObject* const PY_OP_YIELD = (PyObject*)0b110011;
struct Expr;
typedef std::unique_ptr<Expr> Expr_;
} // namespace pkpy

View File

@ -67,7 +67,7 @@ class Compiler {
// however, this is buggy...since there may be a jump to the end (out of bound) even if the last opcode is a return
ctx()->emit(OP_LOAD_NONE, BC_NOARG, BC_KEEPLINE);
ctx()->emit(OP_RETURN_VALUE, BC_NOARG, BC_KEEPLINE);
ctx()->co->optimize(vm);
// ctx()->co->optimize(vm);
if(ctx()->co->varnames.size() > PK_MAX_CO_VARNAMES){
SyntaxError("maximum number of local variables exceeded");
}

View File

@ -6,11 +6,12 @@
#include "error.h"
#include "ceval.h"
#include "str.h"
#include <algorithm>
namespace pkpy{
struct CodeEmitContext;
struct Expr;
typedef std::unique_ptr<Expr> Expr_;
struct Expr{
int line = 0;

View File

@ -204,14 +204,6 @@ struct Mat3x3{
}
/*************** affine transformations ***************/
static Mat3x3 rotate(float radian){
float cr = cosf(radian);
float sr = sinf(radian);
return Mat3x3(cr, -sr, 0.0f,
sr, cr, 0.0f,
0.0f, 0.0f, 1.0f);
}
static Mat3x3 trs(Vec2 t, float radian, Vec2 s){
float cr = cosf(radian);
float sr = sinf(radian);
@ -350,7 +342,12 @@ struct PyVec2: Vec2 {
vm->bind_method<1>(type, "rotate", [](VM* vm, ArgsView args){
Vec2 self = _CAST(PyVec2&, args[0]);
float radian = vm->num_to_float(args[1]);
self = Mat3x3::rotate(radian).transform_vector(self);
float cr = cosf(radian);
float sr = sinf(radian);
Mat3x3 rotate(cr, -sr, 0.0f,
sr, cr, 0.0f,
0.0f, 0.0f, 1.0f);
self = rotate.transform_vector(self);
return VAR(self);
});

View File

@ -591,7 +591,7 @@ public:
inline PyObject* NativeFunc::operator()(VM* vm, ArgsView args) const{
int args_size = args.size() - (int)method; // remove self
if(argc != -1 && args_size != argc) {
if(args_size != argc && argc != -1) {
vm->TypeError(fmt("expected ", argc, " arguments, but got ", args_size));
}
#if DEBUG_EXTRA_CHECK
@ -600,12 +600,6 @@ inline PyObject* NativeFunc::operator()(VM* vm, ArgsView args) const{
return f(vm, args);
}
inline void CodeObject::optimize(VM* vm){
// uint32_t base_n = (uint32_t)(names.size() / kLocalsLoadFactor + 0.5);
// perfect_locals_capacity = std::max(find_next_capacity(base_n), NameDict::__Capacity);
// perfect_hash_seed = find_perfect_hash_seed(perfect_locals_capacity, names);
}
DEF_NATIVE_2(Str, tp_str)
DEF_NATIVE_2(List, tp_list)
DEF_NATIVE_2(Tuple, tp_tuple)