mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 20:10:17 +00:00
up
This commit is contained in:
parent
b24b6599ab
commit
5a9448dca1
@ -2,7 +2,7 @@ with open("src/opcodes.h", "rt", encoding='utf-8') as f:
|
||||
OPCODES_TEXT = f.read()
|
||||
|
||||
pipeline = [
|
||||
["__stl__.h", "str.h", "safestl.h", "builtins.h", "error.h"],
|
||||
["__stl__.h", "shared_ptr.h", "str.h", "safestl.h", "builtins.h", "error.h"],
|
||||
["obj.h", "iter.h", "parser.h", "pointer.h", "codeobject.h"],
|
||||
["vm.h", "compiler.h", "repl.h"],
|
||||
["pocketpy.h"]
|
||||
|
@ -15,10 +15,10 @@
|
||||
} \
|
||||
});
|
||||
|
||||
#define BIND_NUM_LOGICAL_OPT(name, op, fallback) \
|
||||
#define BIND_NUM_LOGICAL_OPT(name, op, is_eq) \
|
||||
_vm->bindMethodMulti({"int","float"}, #name, [](VM* vm, const pkpy::ArgList& args){ \
|
||||
if(!vm->isIntOrFloat(args[0], args[1])){ \
|
||||
if constexpr(fallback) return vm->PyBool(args[0] op args[1]); \
|
||||
if constexpr(is_eq) return vm->PyBool(args[0] == args[1]); \
|
||||
vm->typeError("unsupported operand type(s) for " #op ); \
|
||||
} \
|
||||
return vm->PyBool(vm->numToFloat(args[0]) op vm->numToFloat(args[1])); \
|
||||
|
@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "__stl__.h"
|
||||
#include "shared_ptr.h"
|
||||
#include "str.h"
|
||||
|
||||
struct PyObject;
|
||||
typedef std::shared_ptr<PyObject> PyVar;
|
||||
typedef pkpy::shared_ptr<PyObject> PyVar;
|
||||
typedef PyVar PyVarOrNull;
|
||||
|
||||
class PyVarList: public std::vector<PyVar> {
|
||||
|
@ -16,6 +16,13 @@ namespace pkpy{
|
||||
public:
|
||||
shared_ptr() : count(nullptr), ptr(nullptr) {}
|
||||
shared_ptr(T* ptr) : count(new int(1)), ptr(ptr) {}
|
||||
shared_ptr(const shared_ptr& other) : count(other.count), ptr(other.ptr) {
|
||||
if(count) (*count)++;
|
||||
}
|
||||
shared_ptr(shared_ptr&& other) : count(other.count), ptr(other.ptr) {
|
||||
other.count = nullptr;
|
||||
other.ptr = nullptr;
|
||||
}
|
||||
~shared_ptr() {
|
||||
if (count && --(*count) == 0) _delete();
|
||||
}
|
||||
@ -69,6 +76,12 @@ namespace pkpy{
|
||||
int use_count() const {
|
||||
return count ? *count : 0;
|
||||
}
|
||||
|
||||
void reset(){
|
||||
if (count && --(*count) == 0) _delete();
|
||||
count = nullptr;
|
||||
ptr = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename... Args>
|
||||
|
8
src/vm.h
8
src/vm.h
@ -599,7 +599,7 @@ public:
|
||||
|
||||
PyVar newClassType(_Str name, PyVar base=nullptr) {
|
||||
if(base == nullptr) base = _tp_object;
|
||||
PyVar obj = std::make_shared<PyObject>((_Int)0);
|
||||
PyVar obj = pkpy::make_shared<PyObject>((_Int)0);
|
||||
obj->setType(_tp_type);
|
||||
setAttr(obj, __base__, base);
|
||||
_types[name] = obj;
|
||||
@ -608,7 +608,7 @@ public:
|
||||
|
||||
PyVar newObject(PyVar type, _Value _native) {
|
||||
__checkType(type, _tp_type);
|
||||
PyVar obj = std::make_shared<PyObject>(_native);
|
||||
PyVar obj = pkpy::make_shared<PyObject>(_native);
|
||||
obj->setType(type);
|
||||
return obj;
|
||||
}
|
||||
@ -794,8 +794,8 @@ public:
|
||||
inline const PyVar& PyBool(bool value){return value ? True : False;}
|
||||
|
||||
void initializeBuiltinClasses(){
|
||||
_tp_object = std::make_shared<PyObject>((_Int)0);
|
||||
_tp_type = std::make_shared<PyObject>((_Int)0);
|
||||
_tp_object = pkpy::make_shared<PyObject>((_Int)0);
|
||||
_tp_type = pkpy::make_shared<PyObject>((_Int)0);
|
||||
|
||||
_types["object"] = _tp_object;
|
||||
_types["type"] = _tp_type;
|
||||
|
Loading…
x
Reference in New Issue
Block a user