mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 20:10:17 +00:00
some fix
This commit is contained in:
parent
841cc25a4e
commit
6ac3fdccdb
@ -49,8 +49,7 @@ c11_array c11_vector__submit(c11_vector* self);
|
|||||||
|
|
||||||
#define c11_vector__pop(self) (--(self)->count)
|
#define c11_vector__pop(self) (--(self)->count)
|
||||||
|
|
||||||
#define c11_vector__back(T, self) \
|
#define c11_vector__back(T, self) (((T*)(self)->data)[(self)->count - 1])
|
||||||
(((T*)(self)->data)[(self)->count - 1])
|
|
||||||
|
|
||||||
#define c11_vector__extend(T, self, p, size) \
|
#define c11_vector__extend(T, self, p, size) \
|
||||||
do { \
|
do { \
|
||||||
@ -59,7 +58,6 @@ c11_array c11_vector__submit(c11_vector* self);
|
|||||||
(self)->count += (size); \
|
(self)->count += (size); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
#define c11_vector__insert(T, self, index, elem) \
|
#define c11_vector__insert(T, self, index, elem) \
|
||||||
do { \
|
do { \
|
||||||
if((self)->count == (self)->capacity) c11_vector__reserve((self), (self)->capacity * 2); \
|
if((self)->count == (self)->capacity) c11_vector__reserve((self), (self)->capacity * 2); \
|
||||||
@ -81,13 +79,18 @@ c11_array c11_vector__submit(c11_vector* self);
|
|||||||
T* p = (T*)(self)->data + (start); \
|
T* p = (T*)(self)->data + (start); \
|
||||||
T* q = (T*)(self)->data + (end); \
|
T* q = (T*)(self)->data + (end); \
|
||||||
while(p < q) { \
|
while(p < q) { \
|
||||||
T tmp = *p; *p = *q; *q = tmp; \
|
T tmp = *p; \
|
||||||
p++; q--; \
|
*p = *q; \
|
||||||
|
*q = tmp; \
|
||||||
|
p++; \
|
||||||
|
q--; \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
|
// NOTE: here we do an extra NULL check for it to avoid UB
|
||||||
#define c11__foreach(T, self, it) \
|
#define c11__foreach(T, self, it) \
|
||||||
for(T* it = (T*)(self)->data; it != (T*)(self)->data + (self)->count; it++)
|
for(T* it = (self)->data; it && it != (T*)(self)->data + (self)->count; it++)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,8 @@ c11_vector c11_vector__copy(const c11_vector* self){
|
|||||||
void c11_vector__reserve(c11_vector* self, int capacity){
|
void c11_vector__reserve(c11_vector* self, int capacity){
|
||||||
if(capacity < 4) capacity = 4;
|
if(capacity < 4) capacity = 4;
|
||||||
if(capacity <= self->capacity) return;
|
if(capacity <= self->capacity) return;
|
||||||
|
self->data = realloc(self->data, self->elem_size * capacity);
|
||||||
self->capacity = capacity;
|
self->capacity = capacity;
|
||||||
self->data = realloc(self->data, self->elem_size * self->capacity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void c11_vector__clear(c11_vector* self){
|
void c11_vector__clear(c11_vector* self){
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "pocketpy/common/sstream.h"
|
#include "pocketpy/common/sstream.h"
|
||||||
#include "pocketpy/objects/codeobject.h"
|
#include "pocketpy/objects/codeobject.h"
|
||||||
#include "pocketpy/pocketpy.h"
|
#include "pocketpy/pocketpy.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
int UnboundLocalError(py_Name name) { return -1; }
|
int UnboundLocalError(py_Name name) { return -1; }
|
||||||
|
|
||||||
@ -604,6 +605,18 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) {
|
|||||||
// DISPATCH_JUMP_ABSOLUTE(target)
|
// DISPATCH_JUMP_ABSOLUTE(target)
|
||||||
// }
|
// }
|
||||||
/*****************************************/
|
/*****************************************/
|
||||||
|
case OP_FSTRING_EVAL: {
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
case OP_REPR: {
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
case OP_CALL: {
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
case OP_CALL_VARGS: {
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
case OP_RETURN_VALUE: {
|
case OP_RETURN_VALUE: {
|
||||||
if(byte.arg == BC_NOARG) {
|
if(byte.arg == BC_NOARG) {
|
||||||
self->last_retval = POPX();
|
self->last_retval = POPX();
|
||||||
|
@ -98,11 +98,13 @@ static bool _py_number__pow__(int argc, py_Ref argv) {
|
|||||||
py_newfloat(py_retval(), pow(lhs, rhs));
|
py_newfloat(py_retval(), pow(lhs, rhs));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// rhs >= 0
|
||||||
int64_t ret = 1;
|
int64_t ret = 1;
|
||||||
while(rhs) {
|
while(true){
|
||||||
if(rhs & 1) ret *= lhs;
|
if(rhs & 1) ret *= lhs;
|
||||||
lhs *= lhs;
|
|
||||||
rhs >>= 1;
|
rhs >>= 1;
|
||||||
|
if(!rhs) break;
|
||||||
|
lhs *= lhs; // place this here to avoid overflow
|
||||||
}
|
}
|
||||||
py_newint(py_retval(), ret);
|
py_newint(py_retval(), ret);
|
||||||
}
|
}
|
||||||
|
@ -70,9 +70,10 @@ static void disassemble(CodeObject* co) {
|
|||||||
snprintf(buf, sizeof(buf), "%-8s%-3s%-3d ", line, pointer, i);
|
snprintf(buf, sizeof(buf), "%-8s%-3s%-3d ", line, pointer, i);
|
||||||
c11_sbuf__write_cstr(&ss, buf);
|
c11_sbuf__write_cstr(&ss, buf);
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), " %-24s", OP_NAMES[byte.op]);
|
c11_sbuf__write_cstr(&ss, OP_NAMES[byte.op]);
|
||||||
c11_sbuf__write_cstr(&ss, buf);
|
|
||||||
c11_sbuf__write_char(&ss, ex.is_virtual ? '*' : ' ');
|
c11_sbuf__write_char(&ss, ex.is_virtual ? '*' : ' ');
|
||||||
|
int padding = 24 - strlen(OP_NAMES[byte.op]);
|
||||||
|
for(int j = 0; j < padding; j++) c11_sbuf__write_char(&ss, ' ');
|
||||||
|
|
||||||
// _opcode_argstr(this, i, byte, co);
|
// _opcode_argstr(this, i, byte, co);
|
||||||
do {
|
do {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user