mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
reduce ram usage of stack
This commit is contained in:
parent
a29fa66117
commit
d8698d5cac
2
port/linux/.vscode/launch.json
vendored
2
port/linux/.vscode/launch.json
vendored
@ -11,7 +11,7 @@
|
|||||||
"program": "${workspaceFolder}/build/test/pikascript_test",
|
"program": "${workspaceFolder}/build/test/pikascript_test",
|
||||||
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
||||||
"args": [
|
"args": [
|
||||||
"--gtest_filter=str.big_slice"
|
"--gtest_filter=vm.*"
|
||||||
],
|
],
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
#define PIKA_STACK_BUFF_SIZE 1024 * 1024
|
#define PIKA_STACK_BUFF_SIZE 1024 * 4
|
||||||
#define PIKA_ASSERT_ENABLE 1
|
#define PIKA_ASSERT_ENABLE 1
|
||||||
#define PIKA_MATH_ENABLE 1
|
#define PIKA_MATH_ENABLE 1
|
@ -1,4 +1,4 @@
|
|||||||
#define PIKA_STACK_BUFF_SIZE 1024 * 1024
|
#define PIKA_STACK_BUFF_SIZE 1024 * 4
|
||||||
#define PIKA_ASSERT_ENABLE 1
|
#define PIKA_ASSERT_ENABLE 1
|
||||||
#define PIKA_MATH_ENABLE 1
|
#define PIKA_MATH_ENABLE 1
|
||||||
#define PIKA_FLOAT_TYPE_DOUBLE 0
|
#define PIKA_FLOAT_TYPE_DOUBLE 0
|
@ -1,3 +1,3 @@
|
|||||||
#define PIKA_OPTIMIZE PIKA_OPTIMIZE_SPEED
|
#define PIKA_OPTIMIZE PIKA_OPTIMIZE_SPEED
|
||||||
#define PIKA_STACK_BUFF_SIZE 1024 * 1024
|
#define PIKA_STACK_BUFF_SIZE 1024 * 4
|
||||||
#define PIKA_ASSERT_ENABLE 1
|
#define PIKA_ASSERT_ENABLE 1
|
@ -1,4 +1,4 @@
|
|||||||
#define PIKA_STACK_BUFF_SIZE 1024 * 10
|
#define PIKA_STACK_BUFF_SIZE 1024 * 4
|
||||||
#define PIKA_POOL_ENABLE 1
|
#define PIKA_POOL_ENABLE 1
|
||||||
#define PIKA_POOL_SIZE 1024 * 1024 * 10
|
#define PIKA_POOL_SIZE 1024 * 1024 * 10
|
||||||
#define PIKA_ASSERT_ENABLE 1
|
#define PIKA_ASSERT_ENABLE 1
|
@ -1,3 +1,3 @@
|
|||||||
#define PIKA_NANO_ENABLE 1
|
#define PIKA_NANO_ENABLE 1
|
||||||
#define PIKA_STACK_BUFF_SIZE 1024 * 1024
|
#define PIKA_STACK_BUFF_SIZE 1024 * 4
|
||||||
#define PIKA_ASSERT_ENABLE 1
|
#define PIKA_ASSERT_ENABLE 1
|
@ -2,4 +2,4 @@
|
|||||||
#define PIKA_VERSION_MINOR 11
|
#define PIKA_VERSION_MINOR 11
|
||||||
#define PIKA_VERSION_MICRO 2
|
#define PIKA_VERSION_MICRO 2
|
||||||
|
|
||||||
#define PIKA_EDIT_TIME "2022/10/01 14:03:55"
|
#define PIKA_EDIT_TIME "2022/10/02 00:00:51"
|
||||||
|
@ -275,7 +275,14 @@ pika_float arg_getFloat(Arg* self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Arg* arg_setPtr(Arg* self, char* name, ArgType type, void* pointer) {
|
Arg* arg_setPtr(Arg* self, char* name, ArgType type, void* pointer) {
|
||||||
return arg_init(name, type, (uint8_t*)&pointer, sizeof(uintptr_t), NULL);
|
if (NULL == self) {
|
||||||
|
return arg_init(name, type, (uint8_t*)&pointer, sizeof(uintptr_t),
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
self = arg_setContent(self, (uint8_t*)&pointer, sizeof(pointer));
|
||||||
|
self = arg_setType(self, type);
|
||||||
|
self = arg_setName(self, name);
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
Arg* arg_setStr(Arg* self, char* name, char* string) {
|
Arg* arg_setStr(Arg* self, char* name, char* string) {
|
||||||
|
@ -40,6 +40,7 @@ typedef enum {
|
|||||||
ARG_TYPE_STRING,
|
ARG_TYPE_STRING,
|
||||||
ARG_TYPE_BYTES,
|
ARG_TYPE_BYTES,
|
||||||
ARG_TYPE_POINTER,
|
ARG_TYPE_POINTER,
|
||||||
|
ARG_TYPE_BIG_ARG_PTR,
|
||||||
ARG_TYPE_OBJECT,
|
ARG_TYPE_OBJECT,
|
||||||
ARG_TYPE_OBJECT_META,
|
ARG_TYPE_OBJECT_META,
|
||||||
ARG_TYPE_OBJECT_NEW,
|
ARG_TYPE_OBJECT_NEW,
|
||||||
|
@ -92,9 +92,10 @@ uint8_t* stack_popPyload(Stack* stack, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int32_t _stack_pushArg(Stack* stack, Arg* arg, PIKA_BOOL is_alloc) {
|
static int32_t _stack_pushArg(Stack* stack, Arg* arg, PIKA_BOOL is_alloc) {
|
||||||
|
PIKA_BOOL is_big_arg = PIKA_FALSE;
|
||||||
|
arg_newReg(big_arg_ref, PIKA_ARG_BUFF_SIZE);
|
||||||
stack->top++;
|
stack->top++;
|
||||||
size_t size = arg_getTotleSize(arg);
|
size_t size = arg_getTotleSize(arg);
|
||||||
|
|
||||||
//! if you unsure about the __impl_pikaMalloc, uncomment this to force alignment
|
//! if you unsure about the __impl_pikaMalloc, uncomment this to force alignment
|
||||||
#if PIKA_ARG_ALIGN_ENABLE
|
#if PIKA_ARG_ALIGN_ENABLE
|
||||||
/* force alignment to avoid unaligned access */
|
/* force alignment to avoid unaligned access */
|
||||||
@ -104,13 +105,25 @@ static int32_t _stack_pushArg(Stack* stack, Arg* arg, PIKA_BOOL is_alloc) {
|
|||||||
if (argType_isObject(arg_getType(arg))) {
|
if (argType_isObject(arg_getType(arg))) {
|
||||||
obj_refcntInc((PikaObj*)arg_getPtr(arg));
|
obj_refcntInc((PikaObj*)arg_getPtr(arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (arg_getSerialized(arg) && size > PIKA_BIG_ARG_SIZE) {
|
||||||
|
is_big_arg = PIKA_TRUE;
|
||||||
|
arg_setPtr(&big_arg_ref, "", ARG_TYPE_BIG_ARG_PTR, arg);
|
||||||
|
arg = &big_arg_ref;
|
||||||
|
size = arg_getTotleSize(arg);
|
||||||
|
}
|
||||||
|
|
||||||
stack_pushSize(stack, size);
|
stack_pushSize(stack, size);
|
||||||
stack_pushPyload(stack, arg, size);
|
stack_pushPyload(stack, arg, size);
|
||||||
|
|
||||||
|
if (is_big_arg) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (is_alloc) {
|
if (is_alloc) {
|
||||||
arg_deinit(arg);
|
arg_deinit(arg);
|
||||||
} else {
|
return 0;
|
||||||
arg_deinitHeap(arg);
|
|
||||||
}
|
}
|
||||||
|
arg_deinitHeap(arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,18 +147,27 @@ Arg* _stack_popArg(Stack* stack, Arg* arg_dict, PIKA_BOOL is_alloc) {
|
|||||||
stack->top--;
|
stack->top--;
|
||||||
int32_t size = stack_popSize(stack);
|
int32_t size = stack_popSize(stack);
|
||||||
Arg* arg = NULL;
|
Arg* arg = NULL;
|
||||||
|
Arg* arg_res = NULL;
|
||||||
if (is_alloc) {
|
if (is_alloc) {
|
||||||
arg = arg_copy((Arg*)stack_popPyload(stack, size));
|
arg = arg_copy((Arg*)stack_popPyload(stack, size));
|
||||||
} else {
|
} else {
|
||||||
arg = arg_copy_noalloc((Arg*)stack_popPyload(stack, size), arg_dict);
|
arg = arg_copy_noalloc((Arg*)stack_popPyload(stack, size), arg_dict);
|
||||||
}
|
}
|
||||||
ArgType type = arg_getType(arg);
|
ArgType type = arg_getType(arg);
|
||||||
|
arg_res = arg;
|
||||||
|
if (type == ARG_TYPE_BIG_ARG_PTR) {
|
||||||
|
arg_res = arg_getPtr(arg);
|
||||||
|
if (is_alloc) {
|
||||||
|
arg_deinit(arg);
|
||||||
|
}
|
||||||
|
type = arg_getType(arg_res);
|
||||||
|
}
|
||||||
/* decrase ref_cnt */
|
/* decrase ref_cnt */
|
||||||
if (argType_isObject(type)) {
|
if (argType_isObject(type)) {
|
||||||
obj_refcntDec((PikaObj*)arg_getPtr(arg));
|
obj_refcntDec((PikaObj*)arg_getPtr(arg_res));
|
||||||
}
|
}
|
||||||
pika_assert(arg->flag < ARG_FLAG_MAX);
|
pika_assert(arg_res->flag < ARG_FLAG_MAX);
|
||||||
return arg;
|
return arg_res;
|
||||||
}
|
}
|
||||||
|
|
||||||
Arg* stack_popArg_alloc(Stack* stack) {
|
Arg* stack_popArg_alloc(Stack* stack) {
|
||||||
|
@ -309,6 +309,10 @@
|
|||||||
#define PIKA_FLOAT_TYPE_DOUBLE 1
|
#define PIKA_FLOAT_TYPE_DOUBLE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef PIKA_BIG_ARG_SIZE
|
||||||
|
#define PIKA_BIG_ARG_SIZE 64
|
||||||
|
#endif
|
||||||
|
|
||||||
/* configuration validation */
|
/* configuration validation */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include "test_common.h"
|
#include "test_common.h"
|
||||||
|
|
||||||
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && (!PIKA_POOL_ENABLE) && \
|
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && (!PIKA_POOL_ENABLE)
|
||||||
(PIKA_STACK_BUFF_SIZE > 0x1000)
|
|
||||||
TEST(PikaCV, test1) {
|
TEST(PikaCV, test1) {
|
||||||
/* init */
|
/* init */
|
||||||
pikaMemInfo.heapUsedMax = 0;
|
pikaMemInfo.heapUsedMax = 0;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include "test_common.h"
|
#include "test_common.h"
|
||||||
|
|
||||||
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && (!PIKA_POOL_ENABLE) && \
|
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && (!PIKA_POOL_ENABLE)
|
||||||
(PIKA_STACK_BUFF_SIZE > 0x6000)
|
|
||||||
|
|
||||||
TEST(PikaNN, test1) {
|
TEST(PikaNN, test1) {
|
||||||
/* init */
|
/* init */
|
||||||
|
@ -54,8 +54,7 @@ TEST(builtin, seek) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && \
|
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL)
|
||||||
(PIKA_STACK_BUFF_SIZE >= 0x1000)
|
|
||||||
TEST(builtin, file2) {
|
TEST(builtin, file2) {
|
||||||
/* init */
|
/* init */
|
||||||
pikaMemInfo.heapUsedMax = 0;
|
pikaMemInfo.heapUsedMax = 0;
|
||||||
@ -89,8 +88,7 @@ TEST(builtin, file3) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && !PIKA_POOL_ENABLE && \
|
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && !PIKA_POOL_ENABLE
|
||||||
(PIKA_STACK_BUFF_SIZE >= 0x1000)
|
|
||||||
TEST(builtin, bigfile) {
|
TEST(builtin, bigfile) {
|
||||||
/* init */
|
/* init */
|
||||||
pikaMemInfo.heapUsedMax = 0;
|
pikaMemInfo.heapUsedMax = 0;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include "test_common.h"
|
#include "test_common.h"
|
||||||
|
|
||||||
#if PIKA_STACK_BUFF_SIZE >= 0x1000
|
|
||||||
TEST(cJSON, parse_print) {
|
TEST(cJSON, parse_print) {
|
||||||
/* init */
|
/* init */
|
||||||
pikaMemInfo.heapUsedMax = 0;
|
pikaMemInfo.heapUsedMax = 0;
|
||||||
@ -455,5 +454,3 @@ TEST(cJSON, module) {
|
|||||||
EXPECT_EQ(pikaMemNow(), 0);
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
|
@ -1,5 +1,4 @@
|
|||||||
#include "test_common.h"
|
#include "test_common.h"
|
||||||
#if PIKA_STACK_BUFF_SIZE >= 0x1000
|
|
||||||
#if PIKA_SYNTAX_SLICE_ENABLE
|
#if PIKA_SYNTAX_SLICE_ENABLE
|
||||||
TEST(configparser, test1) {
|
TEST(configparser, test1) {
|
||||||
char* s =
|
char* s =
|
||||||
@ -54,4 +53,3 @@ TEST(configparser, test2) {
|
|||||||
EXPECT_EQ(pikaMemNow(), 0);
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
@ -85,7 +85,7 @@ TEST(stddata, encode_decode) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if PIKA_FILEIO_ENABLE && PIKA_STACK_BUFF_SIZE > 0x1000
|
#if PIKA_FILEIO_ENABLE
|
||||||
TEST(stddata, fileio) {
|
TEST(stddata, fileio) {
|
||||||
/* init */
|
/* init */
|
||||||
pikaMemInfo.heapUsedMax = 0;
|
pikaMemInfo.heapUsedMax = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user