mirror of
https://github.com/pocketpy/pocketpy
synced 2026-02-22 15:30:21 +00:00
Initial integration of deque in collections
This commit is contained in:
parent
7312afdad2
commit
af4f5ac10f
24
include/pocketpy/collections.h
Normal file
24
include/pocketpy/collections.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "obj.h"
|
||||
#include "common.h"
|
||||
#include "memory.h"
|
||||
#include "str.h"
|
||||
#include "cffi.h"
|
||||
|
||||
namespace pkpy
|
||||
{
|
||||
struct PyDeque
|
||||
{
|
||||
PY_CLASS(PyDeque, collections, deque);
|
||||
|
||||
// some fields can be defined here
|
||||
int len;
|
||||
|
||||
PyDeque() = default;
|
||||
void printHelloWorld();
|
||||
static void _register(VM *vm, PyObject *mod, PyObject *type);
|
||||
};
|
||||
|
||||
void add_module_mycollections(VM *vm);
|
||||
} // namespace pkpy
|
||||
@ -7,6 +7,7 @@
|
||||
#include "base64.h"
|
||||
#include "cffi.h"
|
||||
#include "linalg.h"
|
||||
#include "collections.h"
|
||||
#include "easing.h"
|
||||
#include "io.h"
|
||||
#include "vm.h"
|
||||
@ -14,6 +15,7 @@
|
||||
#include "random.h"
|
||||
#include "bindings.h"
|
||||
|
||||
|
||||
namespace pkpy {
|
||||
|
||||
void init_builtins(VM* _vm);
|
||||
|
||||
33
src/collections.cpp
Normal file
33
src/collections.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "pocketpy/collections.h"
|
||||
|
||||
namespace pkpy
|
||||
{
|
||||
void PyDeque::_register(VM *vm, PyObject *mod, PyObject *type)
|
||||
{
|
||||
vm->bind_default_constructor<PyDeque>(type);
|
||||
|
||||
vm->bind(type, "__len__(self) -> int",
|
||||
[](VM *vm, ArgsView args){
|
||||
PyDeque& self = _CAST(PyDeque&, args[0]);
|
||||
return VAR(self.len);
|
||||
});
|
||||
|
||||
vm->bind(type, "printHelloWorld(self) -> None",
|
||||
[](VM *vm, ArgsView args){
|
||||
PyDeque& self = _CAST(PyDeque&, args[0]);
|
||||
self.printHelloWorld();
|
||||
return vm->None;
|
||||
});
|
||||
}
|
||||
|
||||
void PyDeque::printHelloWorld()
|
||||
{
|
||||
printf("Hello World!\n");
|
||||
}
|
||||
|
||||
void add_module_mycollections(VM *vm)
|
||||
{
|
||||
PyObject *mycollections = vm->new_module("collections");
|
||||
PyDeque::register_class(vm, mycollections);
|
||||
}
|
||||
} // namespace pkpypkpy
|
||||
@ -1744,6 +1744,7 @@ void VM::post_init(){
|
||||
|
||||
add_module_linalg(this);
|
||||
add_module_easing(this);
|
||||
add_module_mycollections(this);
|
||||
|
||||
#ifdef PK_USE_BOX2D
|
||||
add_module_box2d(this);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user