This commit is contained in:
blueloveTH 2024-08-06 13:31:41 +08:00
parent bf5fe3d898
commit f756bd813d
26 changed files with 12 additions and 183 deletions

View File

@ -1,10 +1,6 @@
#pragma once
// generated by prebuild.py
#ifdef __cplusplus
extern "C" {
#endif
const char* load_kPythonLib(const char* name);
extern const char kPythonLibs__enum[];
@ -22,7 +18,3 @@ extern const char kPythonLibs_operator[];
extern const char kPythonLibs_pickle[];
extern const char kPythonLibs_this[];
extern const char kPythonLibs_typing[];
#ifdef __cplusplus
} // extern "C"
#endif

View File

@ -2,10 +2,6 @@
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
#define c11__less(a, b) ((a) < (b))
#define c11__lower_bound(T, ptr, count, key, less, out_index) \
@ -42,8 +38,3 @@ bool c11__stable_sort(void* ptr,
int elem_size,
int (*f_lt)(const void* a, const void* b, void* extra),
void* extra);
#ifdef __cplusplus
}
#endif

View File

@ -1,9 +1,5 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#define kPoolExprBlockSize 128
#define kPoolFrameBlockSize 80
#define kPoolObjectBlockSize 80
@ -24,8 +20,3 @@ void PoolObject_dealloc(void* p);
void PoolObject_shrink_to_fit();
void Pools_debug_info(char* buffer, int size);
#ifdef __cplusplus
}
#endif

View File

@ -4,10 +4,6 @@
#include "pocketpy/common/str.h"
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SMALLMAP_T__HEADER
#define K uint16_t
#define V int
@ -24,7 +20,3 @@ extern "C" {
#define equal(a, b) (c11_sv__cmp((a), (b)) == 0)
#include "pocketpy/xmacros/smallmap.h"
#undef SMALLMAP_T__HEADER
#ifdef __cplusplus
}
#endif

View File

@ -6,10 +6,6 @@
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct c11_sbuf {
c11_vector data;
} c11_sbuf;
@ -34,7 +30,3 @@ void c11_sbuf__py_submit(c11_sbuf* self, py_Ref out);
void pk_vsprintf(c11_sbuf* ss, const char* fmt, va_list args);
void pk_sprintf(c11_sbuf* ss, const char* fmt, ...);
#ifdef __cplusplus
}
#endif

View File

@ -4,10 +4,6 @@
#include "pocketpy/common/utils.h"
#include "pocketpy/pocketpy.h"
#ifdef __cplusplus
extern "C" {
#endif
/* string */
typedef struct c11_string{
// int size | char[] | '\0'
@ -74,7 +70,3 @@ typedef enum IntParsingResult{
} IntParsingResult;
IntParsingResult c11__parse_uint(c11_sv text, int64_t* out, int base);
#ifdef __cplusplus
}
#endif

View File

@ -3,13 +3,5 @@
#include <stdint.h>
#include "pocketpy/common/str.h"
#ifdef __cplusplus
extern "C" {
#endif
void py_Name__initialize();
void py_Name__finalize();
#ifdef __cplusplus
}
#endif

View File

@ -3,10 +3,6 @@
#include "stdio.h"
#include "stdlib.h"
#ifdef __cplusplus
extern "C" {
#endif
#define PK_REGION(name) 1
#define PK_SLICE_LOOP(i, start, stop, step) \
@ -52,7 +48,3 @@ typedef struct RefCounted {
free(obj); \
} \
} while(0)
#ifdef __cplusplus
}
#endif

View File

@ -7,10 +7,6 @@
#include <stdbool.h>
#include <assert.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct c11_array {
void* data;
int count;
@ -92,7 +88,3 @@ c11_array c11_vector__submit(c11_vector* self);
// NOTE: here we do an extra NULL check for it to avoid UB
#define c11__foreach(T, self, it) \
for(T* it = (self)->data; it && it != (T*)(self)->data + (self)->count; it++)
#ifdef __cplusplus
}
#endif

View File

@ -5,12 +5,4 @@
#include "pocketpy/objects/sourcedata.h"
#include "pocketpy/objects/codeobject.h"
#ifdef __cplusplus
extern "C" {
#endif
Error* pk_compile(SourceData_ src, CodeObject* out);
#ifdef __cplusplus
}
#endif

View File

@ -6,10 +6,6 @@
#include "pocketpy/objects/error.h"
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
extern const char* TokenSymbols[];
typedef enum TokenIndex{
@ -95,7 +91,3 @@ Error* Lexer__process_and_dump(SourceData_ src, c11_string** out_string);
void TokenArray__dtor(TokenArray* self);
#define Token__sv(self) (c11_sv){(self)->start, (self)->length}
#ifdef __cplusplus
}
#endif

View File

@ -7,10 +7,6 @@
#include "pocketpy/common/config.h"
#include "pocketpy/common/strname.h"
#ifdef __cplusplus
extern "C" {
#endif
py_TValue* FastLocals__try_get_by_name(py_TValue* locals, const CodeObject* co, py_Name name);
NameDict* FastLocals__to_namedict(py_TValue* locals, const CodeObject* co);
@ -66,7 +62,3 @@ 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, py_TValue* sp);
#ifdef __cplusplus
}
#endif

View File

@ -1,10 +1,6 @@
#include "pocketpy/objects/object.h"
#include "pocketpy/common/config.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct ManagedHeap{
c11_vector no_gc;
c11_vector gen;
@ -28,7 +24,3 @@ PyObject* ManagedHeap__gcnew(ManagedHeap* self, py_Type type, int slots, int uds
// external implementation
void ManagedHeap__mark(ManagedHeap* self);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,2 @@
#pragma once

View File

@ -1,14 +1,6 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void pk__add_module_pkpy();
void pk__add_module_os();
void pk__add_module_math();
void pk__add_module_dis();
#ifdef __cplusplus
}
#endif

View File

@ -6,10 +6,6 @@
#include "pocketpy/interpreter/frame.h"
#include "pocketpy/interpreter/modules.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct py_TypeInfo {
py_Name name;
py_Type base;
@ -128,7 +124,3 @@ py_Type pk_staticmethod__register();
py_Type pk_classmethod__register();
py_TValue pk_builtins__register();
#ifdef __cplusplus
}
#endif

View File

@ -9,10 +9,6 @@
#include "pocketpy/common/utils.h"
#include "pocketpy/pocketpy.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct PyObject PyObject;
typedef struct VM VM;
extern VM* pk_current_vm;
@ -35,7 +31,3 @@ typedef struct py_TValue {
// 16 bytes to make py_arg() macro work
static_assert(sizeof(py_CFunction) <= 8, "sizeof(py_CFunction) > 8");
static_assert(sizeof(py_TValue) == 16, "sizeof(py_TValue) != 16");
#ifdef __cplusplus
}
#endif

View File

@ -10,10 +10,6 @@
#include "pocketpy/objects/namedict.h"
#include "pocketpy/pocketpy.h"
#ifdef __cplusplus
extern "C" {
#endif
#define BC_NOARG 0
#define BC_KEEPLINE -1
@ -144,8 +140,4 @@ typedef struct Function {
} Function;
void Function__ctor(Function* self, FuncDecl_ decl, py_TValue* module);
void Function__dtor(Function* self);
#ifdef __cplusplus
}
#endif
void Function__dtor(Function* self);

View File

@ -7,10 +7,6 @@
#include "pocketpy/objects/object.h"
#include "pocketpy/pocketpy.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct{
SourceData_ src;
int lineno;
@ -20,7 +16,3 @@ typedef struct{
void py_BaseException__set_lineno(py_Ref, int lineno, const CodeObject* code);
int py_BaseException__get_lineno(py_Ref, const CodeObject* code);
void py_BaseException__stpush(py_Ref, SourceData_ src, int lineno, const char* func_name);
#ifdef __cplusplus
}
#endif

View File

@ -5,10 +5,6 @@
#include "pocketpy/objects/base.h"
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SMALLMAP_T__HEADER
#define K uint16_t
#define V py_TValue
@ -16,6 +12,3 @@ extern "C" {
#include "pocketpy/xmacros/smallmap.h"
#undef SMALLMAP_T__HEADER
#ifdef __cplusplus
}
#endif

View File

@ -3,10 +3,6 @@
#include "pocketpy/objects/namedict.h"
#include "pocketpy/objects/base.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct PyObject {
py_Type type; // we have a duplicated type here for convenience
bool gc_is_large;
@ -29,7 +25,3 @@ void* PyObject__userdata(PyObject* self);
PyObject* PyObject__new(py_Type type, int slots, int size);
void PyObject__delete(PyObject* self);
#ifdef __cplusplus
}
#endif

View File

@ -6,10 +6,6 @@
#include "pocketpy/common/sstream.h"
#include "pocketpy/common/vector.h"
#ifdef __cplusplus
extern "C" {
#endif
struct SourceData {
RefCounted rc;
enum py_CompileMode mode;
@ -38,7 +34,3 @@ void SourceData__snapshot(const struct SourceData* self,
int lineno,
const char* cursor,
const char* name);
#ifdef __cplusplus
}
#endif

View File

@ -27,21 +27,12 @@ with open("include/pocketpy/common/_generated.h", "wt", encoding='utf-8', newlin
data = '''#pragma once
// generated by prebuild.py
#ifdef __cplusplus
extern "C" {
#endif
const char* load_kPythonLib(const char* name);
'''
for key in sorted(sources.keys()):
value = sources[key]
data += f'extern const char kPythonLibs_{key}[];\n'
data += '''
#ifdef __cplusplus
} // extern "C"
#endif
'''
f.write(data)
with open("src/common/_generated.c", "wt", encoding='utf-8', newline='\n') as f:

View File

@ -701,7 +701,9 @@ FrameResult VM__run_top_frame(VM* self) {
DISPATCH();
}
case OP_YIELD_VALUE: {
assert(false);
py_assign(py_retval(), TOP());
POP();
return RES_YIELD;
}
/////////
case OP_LIST_APPEND: {

View File

@ -0,0 +1 @@
#include "pocketpy/interpreter/generator.h"

View File

@ -435,9 +435,11 @@ FrameResult VM__vectorcall(VM* self, uint16_t argc, uint16_t kwargc, bool opcall
// submit the call
VM__push_frame(self, Frame__new(co, &fn->module, p0, p0, argv));
return opcall ? RES_CALL : VM__run_top_frame(self);
case FuncType_GENERATOR:
assert(false);
break;
case FuncType_GENERATOR: {
bool ok = prepare_py_call(self->__vectorcall_buffer, argv, p1, kwargc, fn->decl);
if(!ok) return RES_ERROR;
return RES_RETURN;
}
// prepare_py_call(__vectorcall_buffer, args, kwargs, fn.decl);
// s_data.reset(p0);
// callstack.emplace(nullptr, co, fn._module, callable.get(), nullptr);