This commit is contained in:
Lyon 2023-03-13 16:45:16 +08:00
commit 1766eb437b
122 changed files with 3905 additions and 1906 deletions

View File

@ -26,7 +26,7 @@
<a href="https://pikadoc.readthedocs.io/en/latest/%E5%95%86%E4%B8%9A%E5%90%88%E4%BD%9C%E6%96%B9%E5%BC%8F.html">Business</a>
</p>
[![image](document/image/147997370-ff37b6e7-25b2-4174-aa64-c1fb92cede04.png)](https://pikastech.github.io/pikapython/dev/bench/)
[![image](document/image/147997370-ff37b6e7-25b2-4174-aa64-c1fb92cede04.png)](https://pikastech.github.io/PikaPython/dev/bench/)
# 1. Abstract
@ -358,10 +358,10 @@ while True:
print(readBuff)
```
![Hnet-image (3)](document/image/132943365-0f7059b3-4f9d-4989-a5ec-2cce72b0cc96.gif)
</details>
![Hnet-image (3)](document/image/132943365-0f7059b3-4f9d-4989-a5ec-2cce72b0cc96.gif)
## Demo 03 ADC
@ -645,7 +645,14 @@ In addition to device drivers, developing custom Python modules for MCU is very
| Contribute log | Contributer |
| --- | --- |
|implement shell filter | [GorgonMeducer](https://github.com/GorgonMeducer) |
|修复socket模块在lwip中fcntl的参数数量错误|[梦程MI](https://gitee.com/dreamcmi) |
|support GPIO pika_hal for BLMCU|[codercmd](https://gitee.com/codercmd)|
|Fix Typo on PikaVM.c|[Ikko Eltociear Ashimine](https://gitee.com/eltociear)|
|Fix type assert on dataArgs.c|[itschina](https://gitee.com/itschina)|
|add examples/Device/KEY_POLL.PY|[codercmd](https://gitee.com/codercmd)|
| hmac hashlib base64 aes modules | [梦程MI](https://gitee.com/dreamcmi) |
|fix pikaCompiler build error on macos|[梦程MI](https://gitee.com/dreamcmi) |
<details><summary> Contribute Log On 2022 </summary>
| Contribute log | Contributer |
@ -656,6 +663,7 @@ In addition to device drivers, developing custom Python modules for MCU is very
| Donate500¥ | [edmund_wz](https://gitee.com/edmund_wz) |
| Donate500¥ | [Meco Jianting Man](https://github.com/mysterywolf) |
| Donate500¥ | [hardsofttech](https://gitee.com/hardsofttech) |
|PikaNN module| [Renzhihan](https://github.com/Renzhihan) |
| re module | [eglwang](https://gitee.com/eglwang) |
| PikaMath.Quaternion() | [purewind7](https://gitee.com/purewind7) |
| contrubute to PikaCV | [purewind7](https://gitee.com/purewind7) |

View File

@ -24,7 +24,7 @@
<a href="https://pikadoc.readthedocs.io/zh/latest/%E5%95%86%E4%B8%9A%E5%90%88%E4%BD%9C%E6%96%B9%E5%BC%8F.html">商业合作</a>
</p>
[![image](document/image/147997370-ff37b6e7-25b2-4174-aa64-c1fb92cede04.png)](https://pikastech.github.io/pikapython/dev/bench/)
[![image](document/image/147997370-ff37b6e7-25b2-4174-aa64-c1fb92cede04.png)](https://pikastech.github.io/PikaPython/dev/bench/)
# 1.简介
@ -400,10 +400,10 @@ while True:
```
![mmexport1631351523907](document/image/132944185-0a01b1ba-8cf7-4f9f-9d73-fe9cbcd52f0b.png)
</details>
![mmexport1631351523907](document/image/132944185-0a01b1ba-8cf7-4f9f-9d73-fe9cbcd52f0b.png)
## Demo 04 PWM output
<details><summary>查看代码</summary>
@ -660,7 +660,14 @@ while True:
| 贡献记录 | 贡献者 |
| --- | --- |
|implement shell filter | [GorgonMeducer](https://github.com/GorgonMeducer) |
|修复socket模块在lwip中fcntl的参数数量错误|[梦程MI](https://gitee.com/dreamcmi) |
|support GPIO pika_hal for BLMCU|[codercmd](https://gitee.com/codercmd)|
|Fix Typo on PikaVM.c|[Ikko Eltociear Ashimine](https://gitee.com/eltociear)|
|Fix type assert on dataArgs.c|[itschina](https://gitee.com/itschina)|
|add examples/Device/KEY_POLL.PY|[codercmd](https://gitee.com/codercmd)|
| hmac hashlib base64 aes modules | [梦程MI](https://gitee.com/dreamcmi) |
|fix pikaCompiler build error on macos|[梦程MI](https://gitee.com/dreamcmi) |
<details><summary>贡献记录 (2022 年)</summary>
@ -672,6 +679,7 @@ while True:
| Donate500¥ | [edmund_wz](https://gitee.com/edmund_wz) |
| Donate500¥ | [Meco Jianting Man](https://github.com/mysterywolf) |
| Donate500¥ | [hardsofttech](https://gitee.com/hardsofttech) |
|PikaNN module| [Renzhihan](https://github.com/Renzhihan) |
| re module | [eglwang](https://gitee.com/eglwang) |
| PikaMath.Quaternion() | [purewind7](https://gitee.com/purewind7) |
| contrubute to PikaCV | [purewind7](https://gitee.com/purewind7) |

View File

@ -26,7 +26,7 @@
<a href="https://pikadoc.readthedocs.io/en/latest/%E5%95%86%E4%B8%9A%E5%90%88%E4%BD%9C%E6%96%B9%E5%BC%8F.html">Business</a>
</p>
[![image](document/image/147997370-ff37b6e7-25b2-4174-aa64-c1fb92cede04.png)](https://pikastech.github.io/pikapython/dev/bench/)
[![image](document/image/147997370-ff37b6e7-25b2-4174-aa64-c1fb92cede04.png)](https://pikastech.github.io/PikaPython/dev/bench/)
# 1. Abstract
@ -247,10 +247,10 @@ while True:
print(readBuff)
```
![Hnet-image (3)](document/image/132943365-0f7059b3-4f9d-4989-a5ec-2cce72b0cc96.gif)
</details>
![Hnet-image (3)](document/image/132943365-0f7059b3-4f9d-4989-a5ec-2cce72b0cc96.gif)
## Demo 03 ADC

View File

@ -24,7 +24,7 @@
<a href="https://pikadoc.readthedocs.io/zh/latest/%E5%95%86%E4%B8%9A%E5%90%88%E4%BD%9C%E6%96%B9%E5%BC%8F.html">商业合作</a>
</p>
[![image](document/image/147997370-ff37b6e7-25b2-4174-aa64-c1fb92cede04.png)](https://pikastech.github.io/pikapython/dev/bench/)
[![image](document/image/147997370-ff37b6e7-25b2-4174-aa64-c1fb92cede04.png)](https://pikastech.github.io/PikaPython/dev/bench/)
# 1.简介
@ -289,10 +289,10 @@ while True:
```
![mmexport1631351523907](document/image/132944185-0a01b1ba-8cf7-4f9f-9d73-fe9cbcd52f0b.png)
</details>
![mmexport1631351523907](document/image/132944185-0a01b1ba-8cf7-4f9f-9d73-fe9cbcd52f0b.png)
## Demo 04 PWM output
<details><summary>查看代码</summary>

View File

@ -4,6 +4,7 @@
| Donate500¥ | [edmund_wz](https://gitee.com/edmund_wz) |
| Donate500¥ | [Meco Jianting Man](https://github.com/mysterywolf) |
| Donate500¥ | [hardsofttech](https://gitee.com/hardsofttech) |
|PikaNN module| [Renzhihan](https://github.com/Renzhihan) |
| re module | [eglwang](https://gitee.com/eglwang) |
| PikaMath.Quaternion() | [purewind7](https://gitee.com/purewind7) |
| contrubute to PikaCV | [purewind7](https://gitee.com/purewind7) |

View File

@ -1 +1,8 @@
| hmac hashlib base64 aes modules | [梦程MI](https://gitee.com/dreamcmi) |
|implement shell filter | [GorgonMeducer](https://github.com/GorgonMeducer) |
|修复socket模块在lwip中fcntl的参数数量错误|[梦程MI](https://gitee.com/dreamcmi) |
|support GPIO pika_hal for BLMCU|[codercmd](https://gitee.com/codercmd)|
|Fix Typo on PikaVM.c|[Ikko Eltociear Ashimine](https://gitee.com/eltociear)|
|Fix type assert on dataArgs.c|[itschina](https://gitee.com/itschina)|
|add examples/Device/KEY_POLL.PY|[codercmd](https://gitee.com/codercmd)|
| hmac hashlib base64 aes modules | [梦程MI](https://gitee.com/dreamcmi) |
|fix pikaCompiler build error on macos|[梦程MI](https://gitee.com/dreamcmi) |

View File

@ -21,6 +21,10 @@
#include "main.h"
#include "usart.h"
#include "gpio.h"
#ifdef USING_PERF_COUNTER
#include "perf_counter.h"
#endif
#include "PikaVM.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
@ -67,6 +71,28 @@ char __platform_getchar(void) {
}
static void prime_number_100_c(void) {
volatile int num = 0;
/* run */
for (volatile int i = 2; i < 100; i++) {
volatile int is_prime = 1;
for (volatile int j = 2; j < i; j++) {
if (i % j == 0) {
is_prime = 0;
break;
}
}
if (is_prime) {
num = num + i;
}
}
if ( num != 1060){
printf("[error] in benchmark prime_number_100_c \r\n");
}
}
/* USER CODE END 0 */
/**
@ -99,14 +125,97 @@ int main(void)
MX_GPIO_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
PikaObj *pikaMain = pikaScriptInit();
pikaScriptShell(pikaMain);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
/* user input buff */
PikaObj* pikaMain = NULL;
/* run unit test */
pikaMain = pikaScriptInit();
#ifdef USING_PERF_COUNTER
/* benchmark */
uint64_t nCycleUsed_c,nCycleUsed_pika = 0;
printf("[----------benchmark----------]\r\n");
__cycleof__("", {
nCycleUsed_c = _;
printf("[prime_number_100_c] Cycle Used %lld\r\n", _);
}) {
prime_number_100_c();
}
/* create pikaMain root obj */
pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
/* clang-format off */
PIKA_PYTHON(
num = 0
i = 2
for i in range(2,100):
j=2
is_prime = 1
for j in range(2,i):
if i%j==0 :
is_prime = 0
break
if is_prime:
num = num + i
)
/* clang-format on */
const uint8_t bytes[] = {
0xb4, 0x00, 0x00, 0x00, /* instruct array size */
0x00, 0x85, 0x01, 0x00, 0x00, 0x04, 0x03, 0x00, 0x00, 0x85, 0x07, 0x00,
0x00, 0x04, 0x09, 0x00, 0x20, 0x85, 0x07, 0x00, 0x20, 0x05, 0x0b, 0x00,
0x10, 0x02, 0x0f, 0x00, 0x00, 0x02, 0x15, 0x00, 0x00, 0x04, 0x1a, 0x00,
0x00, 0x82, 0x1e, 0x00, 0x00, 0x04, 0x09, 0x00, 0x00, 0x0d, 0x09, 0x00,
0x00, 0x07, 0x07, 0x00, 0x01, 0x85, 0x07, 0x00, 0x01, 0x04, 0x2b, 0x00,
0x01, 0x85, 0x2d, 0x00, 0x01, 0x04, 0x2f, 0x00, 0x21, 0x85, 0x07, 0x00,
0x21, 0x01, 0x09, 0x00, 0x11, 0x02, 0x0f, 0x00, 0x01, 0x02, 0x15, 0x00,
0x01, 0x04, 0x38, 0x00, 0x01, 0x82, 0x3c, 0x00, 0x01, 0x04, 0x2b, 0x00,
0x01, 0x0d, 0x2b, 0x00, 0x01, 0x07, 0x07, 0x00, 0x22, 0x81, 0x09, 0x00,
0x22, 0x01, 0x2b, 0x00, 0x12, 0x08, 0x49, 0x00, 0x12, 0x05, 0x01, 0x00,
0x02, 0x08, 0x4b, 0x00, 0x02, 0x07, 0x2d, 0x00, 0x03, 0x85, 0x01, 0x00,
0x03, 0x04, 0x2f, 0x00, 0x03, 0x8e, 0x00, 0x00, 0x01, 0x86, 0x4e, 0x00,
0x01, 0x8c, 0x38, 0x00, 0x01, 0x81, 0x2f, 0x00, 0x01, 0x07, 0x2d, 0x00,
0x12, 0x81, 0x03, 0x00, 0x12, 0x01, 0x09, 0x00, 0x02, 0x08, 0x51, 0x00,
0x02, 0x04, 0x03, 0x00, 0x00, 0x86, 0x4e, 0x00, 0x00, 0x8c, 0x1a, 0x00,
/* instruct array */
0x53, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x30, 0x00, 0x6e, 0x75, 0x6d, 0x00, 0x32, 0x00, 0x69, 0x00, 0x31, 0x30,
0x30, 0x00, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x69, 0x74, 0x65, 0x72,
0x00, 0x24, 0x6c, 0x30, 0x00, 0x24, 0x6c, 0x30, 0x2e, 0x5f, 0x5f, 0x6e,
0x65, 0x78, 0x74, 0x5f, 0x5f, 0x00, 0x6a, 0x00, 0x31, 0x00, 0x69, 0x73,
0x5f, 0x70, 0x72, 0x69, 0x6d, 0x65, 0x00, 0x24, 0x6c, 0x31, 0x00, 0x24,
0x6c, 0x31, 0x2e, 0x5f, 0x5f, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x5f, 0x00,
0x25, 0x00, 0x3d, 0x3d, 0x00, 0x2d, 0x31, 0x00, 0x2b, 0x00, /* const pool */
};
__cycleof__("", {
nCycleUsed_pika = _;
printf("[prime_number_100_pika] Cycle Used %lld\r\n", _);
}) {
/* run pika ByteCode */
pikaVM_runByteCode(pikaMain, (uint8_t*)bytes);
}
int num = obj_getInt(pikaMain, "num");
if ( num != 1060){
printf("[error] in benchmark prime_number_100_pika \r\n");
}
/* free the pikaMain obj */
obj_deinit(pikaMain);
uint64_t benchmark_result = ((double) nCycleUsed_c / (double)nCycleUsed_pika) * 100 * 100000;
printf("\r\n[------benchmark finished ---------]\r\n");
printf("benchmakr result :%lld\r\n", benchmark_result);
#endif
pikaScriptShell(pikaMain);
while (1)
{
}

View File

@ -74,14 +74,8 @@ RUN apt-get install -y liblua5.3-dev
RUN apt-get install -y lcov
RUN apt-get install -y wget
RUN wget https://gitee.com/Lyon1998/pikascript/attach_files/1213873/download -O code-server.deb
RUN dpkg -i code-server.deb
ADD code-server-config.yaml /root/.config/code-server/config.yaml
RUN cd root/pikascript && git remote add github https://github.com/pikastech/pikascript
# RUN code-server --install-extension ms-python.python
RUN code-server --install-extension llvm-vs-code-extensions.vscode-clangd
RUN code-server --install-extension vscodevim.vim
RUN code-server --install-extension zhuangtongfa.material-theme
RUN apt-get install clangd -y
RUN apt-get install libmbedtls-dev -y
RUN pip install -r /root/pikascript/docker/requirements.txt
RUN apt-get install clang-format -y

View File

@ -15,4 +15,4 @@ class Test:
test = Test()
while test._val != 3:
time.sleep(0.5)
time.sleep(0.1)

View File

@ -1,22 +1,34 @@
# Import modbus module
import modbus
# Create a ModBusRTU object, specify the send buffer and receive buffer size as 128 bytes
mb = modbus.ModBusRTU(128, 128)
# Set slave address to 1
mb.setSlave(1)
# Generate a request frame for reading registers, specify the start address as 0 and the quantity as 10
send_buff = mb.serializeReadRegisters(0, 10)
# Print the byte string of the request frame
print(send_buff)
# Parse a response frame for reading registers, return a list containing the values of the registers
host_regists = mb.deserializeReadRegisters(
b'\x01\x03\x14\x00\x00\x00\x00\x04\xD2\x00\x00\x00\x00\x00\x7B\x00\x00\x00\x00\x00\x00\x00\x00\xE5\x0B'
)
print(host_regists)
# Generate a request frame for reading input registers, specify the start address as 0 and the quantity as 2
mb.serializeReadInputRegisters(0, 2)
# Parse a response frame for reading input registers, return a list containing the values of the input registers
mb.deserializeReadInputRegisters(b'\x01\x04\x04\x00\x00\x08\xE6\x7D\xCE')
# Generate a request frame for writing a single register, specify the register address as 0 and the value as 0x1234
send_buff = mb.serializeWriteRegister(0, 0x1234)
print(send_buff)

View File

@ -134,6 +134,7 @@ class String:
def replace(self, old: str, new: str) -> str: ...
def strip(self, *chrs) -> str: ...
def format(self, *vars) -> str: ...
def join(self, val: any) -> str: ...
class ByteArray:

View File

@ -8,12 +8,14 @@
#include "dataStrs.h"
Arg* PikaStdData_Dict_get(PikaObj* self, char* key) {
pika_assert_obj_alive(self);
PikaDict* dict = obj_getPtr(self, "dict");
Arg* res = pikaDict_getArg(dict, key);
if (NULL == res) {
obj_setErrorCode(self, PIKA_RES_ERR_RUNTIME_ERROR);
__platform_printf("KeyError: %s\n", key);
}
pika_assert_arg_alive(res);
return arg_copy(res);
}
@ -271,7 +273,7 @@ void PikaStdData_Dict_update(PikaObj* self, PikaObj* other) {
const uint8_t
bytes[] =
{
0x40, 0x00, 0x00, 0x00,/* instruct array size */
0x40, 0x00, 0x00, 0x00, /* instruct array size */
0x10, 0x81, 0x01, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x04,
0x0d, 0x00, 0x00, 0x82, 0x11, 0x00, 0x00, 0x04, 0x1e, 0x00,
0x00, 0x0d, 0x1e, 0x00, 0x00, 0x07, 0x24, 0x00, 0x11, 0x81,
@ -279,7 +281,7 @@ void PikaStdData_Dict_update(PikaObj* self, PikaObj* other) {
0x21, 0x01, 0x1e, 0x00, 0x11, 0x1d, 0x00, 0x00, 0x01, 0x02,
0x2c, 0x00, 0x01, 0x04, 0x26, 0x00, 0x00, 0x86, 0x38, 0x00,
0x00, 0x8c, 0x0d, 0x00, /* instruct array */
0x3b, 0x00, 0x00, 0x00, /* const pool size */
0x3b, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x40, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x00, 0x69, 0x74,
0x65, 0x72, 0x00, 0x24, 0x6c, 0x30, 0x00, 0x24, 0x6c, 0x30,
0x2e, 0x5f, 0x5f, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x5f, 0x00,

View File

@ -1,6 +1,7 @@
#include "PikaStdData_String.h"
#include "PikaStdData_List.h"
#include "PikaStdData_String_Util.h"
#include "PikaStdLib_SysObj.h"
#include "PikaVM.h"
#include "dataStrs.h"
@ -813,3 +814,47 @@ char* PikaStdData_String_format(PikaObj* self, PikaTuple* vars) {
/* 'test{}'.format(123) */
return NULL;
}
char* PikaStdData_String_join(PikaObj* self, Arg* val) {
PikaObj* context = newNormalObj(New_PikaStdLib_SysObj);
obj_setArg(context, "@val", val);
obj_setStr(context, "@str", obj_getStr(self, "str"));
/* clang-format off */
PIKA_PYTHON(
@res_join = ""
@num = len(@val)
for i in range(@num):
@res_join += @val[i]
if i != @num - 1:
@res_join += @str
)
/* clang-format on */
const uint8_t bytes[] = {
0x84, 0x00, 0x00, 0x00, /* instruct array size */
0x00, 0x83, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x10, 0x81, 0x0b, 0x00,
0x00, 0x02, 0x10, 0x00, 0x00, 0x04, 0x14, 0x00, 0x20, 0x81, 0x14, 0x00,
0x10, 0x02, 0x19, 0x00, 0x00, 0x02, 0x1f, 0x00, 0x00, 0x04, 0x24, 0x00,
0x00, 0x82, 0x28, 0x00, 0x00, 0x04, 0x35, 0x00, 0x00, 0x0d, 0x35, 0x00,
0x00, 0x07, 0x37, 0x00, 0x11, 0x81, 0x01, 0x00, 0x31, 0x01, 0x0b, 0x00,
0x31, 0x01, 0x35, 0x00, 0x21, 0x1d, 0x00, 0x00, 0x11, 0x02, 0x00, 0x00,
0x01, 0x08, 0x39, 0x00, 0x01, 0x04, 0x01, 0x00, 0x11, 0x81, 0x35, 0x00,
0x21, 0x01, 0x14, 0x00, 0x21, 0x05, 0x3b, 0x00, 0x11, 0x08, 0x3d, 0x00,
0x01, 0x08, 0x3f, 0x00, 0x01, 0x07, 0x3b, 0x00, 0x12, 0x81, 0x01, 0x00,
0x22, 0x01, 0x42, 0x00, 0x12, 0x02, 0x00, 0x00, 0x02, 0x08, 0x39, 0x00,
0x02, 0x04, 0x01, 0x00, 0x00, 0x86, 0x47, 0x00, 0x00, 0x8c, 0x24, 0x00,
/* instruct array */
0x4a, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x40, 0x72, 0x65, 0x73, 0x5f, 0x6a, 0x6f, 0x69, 0x6e, 0x00, 0x40,
0x76, 0x61, 0x6c, 0x00, 0x6c, 0x65, 0x6e, 0x00, 0x40, 0x6e, 0x75, 0x6d,
0x00, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x69, 0x74, 0x65, 0x72, 0x00,
0x24, 0x6c, 0x30, 0x00, 0x24, 0x6c, 0x30, 0x2e, 0x5f, 0x5f, 0x6e, 0x65,
0x78, 0x74, 0x5f, 0x5f, 0x00, 0x69, 0x00, 0x32, 0x00, 0x2b, 0x00, 0x31,
0x00, 0x2d, 0x00, 0x21, 0x3d, 0x00, 0x40, 0x73, 0x74, 0x72, 0x00, 0x2d,
0x31, 0x00, /* const pool */
};
pikaVM_runByteCode(context, (uint8_t*)bytes);
char* sRes = obj_cacheStr(self, obj_getStr(context, "@res_join"));
obj_deinit(context);
return sRes;
}

View File

@ -134,6 +134,10 @@ class SysObj:
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def clear(): ...
@staticmethod
@PIKA_C_MACRO_IF("PIKA_GC_MARK_SWEEP_ENABLE")
def gcdump(): ...
@PIKA_C_MACRO_IF("0")
class RangeObj:

View File

@ -169,65 +169,64 @@ char* PikaStdLib_SysObj_str(PikaObj* self, Arg* arg) {
Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
/* object */
PIKA_BOOL is_temp = PIKA_FALSE;
PikaObj* arg_obj = _arg_to_obj(arg, &is_temp);
NewFun _clsptr = (NewFun)arg_obj->constructor;
PIKA_BOOL bIsTemp = PIKA_FALSE;
PikaObj* oArg = _arg_to_obj(arg, &bIsTemp);
NewFun _clsptr = (NewFun)oArg->constructor;
if (_clsptr == New_PikaStdLib_RangeObj) {
/* found RangeObj, return directly */
return arg_copy(arg);
}
// pikaVM_runAsm(arg_obj,
// "B0\n"
// "0 RUN __iter__\n"
// "0 OUT __res\n");
/* clang-format off */
PIKA_PYTHON(
@res_iter = __iter__()
)
/* clang-format on */
const uint8_t bytes[] = {
0x08, 0x00, 0x00, 0x00, /* instruct array size */
0x00, 0x82, 0x01, 0x00, 0x00, 0x04, 0x0a, 0x00, /* instruct array */
0x10, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x5f, 0x5f, 0x69, 0x74, 0x65, 0x72, 0x5f,
0x5f, 0x00, 0x5f, 0x5f, 0x72, 0x65, 0x73, 0x00, /* const pool */
0x14, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x5f, 0x5f, 0x69, 0x74, 0x65, 0x72, 0x5f, 0x5f, 0x00, 0x40,
0x72, 0x65, 0x73, 0x5f, 0x69, 0x74, 0x65, 0x72, 0x00, /* const pool */
};
pikaVM_runByteCode(arg_obj, (uint8_t*)bytes);
Arg* res = arg_copy(args_getArg(arg_obj->list, "__res"));
obj_removeArg(arg_obj, "__res");
if (is_temp) {
obj_refcntDec(arg_obj);
Arg* res = pikaVM_runByteCodeReturn(oArg, (uint8_t*)bytes, "@res_iter");
if (bIsTemp) {
obj_refcntDec(oArg);
}
return res;
}
Arg* PikaStdLib_SysObj_range(PikaObj* self, PikaTuple* ax) {
/* set template arg to create rangeObj */
Arg* obj_arg = arg_newDirectObj(New_PikaStdLib_RangeObj);
PikaObj* range_obj = arg_getPtr(obj_arg);
RangeData range_data = {0};
Arg* aRangeObj = arg_newDirectObj(New_PikaStdLib_RangeObj);
PikaObj* oRangeObj = arg_getPtr(aRangeObj);
RangeData tRangeData = {0};
if (pikaTuple_getSize(ax) == 1) {
int start = 0;
int end = arg_getInt(pikaTuple_getArg(ax, 0));
range_data.start = start;
range_data.end = end;
range_data.step = 1;
tRangeData.start = start;
tRangeData.end = end;
tRangeData.step = 1;
} else if (pikaTuple_getSize(ax) == 2) {
int start = arg_getInt(pikaTuple_getArg(ax, 0));
int end = arg_getInt(pikaTuple_getArg(ax, 1));
range_data.start = start;
range_data.end = end;
range_data.step = 1;
tRangeData.start = start;
tRangeData.end = end;
tRangeData.step = 1;
} else if (pikaTuple_getSize(ax) == 3) {
int start = arg_getInt(pikaTuple_getArg(ax, 0));
int end = arg_getInt(pikaTuple_getArg(ax, 1));
int step = arg_getInt(pikaTuple_getArg(ax, 2));
range_data.start = start;
range_data.end = end;
range_data.step = step;
tRangeData.start = start;
tRangeData.end = end;
tRangeData.step = step;
}
range_data.i = range_data.start;
obj_setStruct(range_obj, "_", range_data);
return obj_arg;
tRangeData.i = tRangeData.start;
obj_setStruct(oRangeObj, "_", tRangeData);
return aRangeObj;
}
Arg* PikaStdLib_SysObj___getitem__(PikaObj* self, Arg* obj, Arg* key) {
return __vm_get(NULL, self, key, obj);
return _vm_get(NULL, self, key, obj);
}
Arg* PikaStdLib_SysObj___setitem__(PikaObj* self,
@ -296,22 +295,22 @@ int PikaStdLib_SysObj_len(PikaObj* self, Arg* arg) {
Arg* method_arg = obj_getMethodArg(arg_obj, "__len__");
if (NULL != method_arg) {
arg_deinit(method_arg);
obj_removeArg(arg_obj, "@res_len");
/* clang-format off */
PIKA_PYTHON(
__res = __len__()
)
PIKA_PYTHON(
@res_len = __len__()
)
/* clang-format on */
const uint8_t bytes[] = {
0x08, 0x00, 0x00, 0x00, /* instruct array size */
0x00, 0x82, 0x01, 0x00, 0x00, 0x04, 0x09, 0x00, /* instruct
array */
0x0f, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x5f, 0x5f, 0x6c, 0x65, 0x6e, 0x5f, 0x5f, 0x00,
0x5f, 0x5f, 0x72, 0x65, 0x73, 0x00, /* const pool */
0x12, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x5f, 0x5f, 0x6c, 0x65, 0x6e, 0x5f, 0x5f, 0x00, 0x40,
0x72, 0x65, 0x73, 0x5f, 0x6c, 0x65, 0x6e, 0x00, /* const pool */
};
pikaVM_runByteCode(arg_obj, (uint8_t*)bytes);
return obj_getInt(arg_obj, "__res");
return obj_getInt(arg_obj, "@res_len");
}
}
@ -327,33 +326,33 @@ Arg* PikaStdLib_SysObj_list(PikaObj* self, PikaTuple* val) {
obj_setArg(self, "__list", in);
/* clang-format off */
PIKA_PYTHON(
__res = []
@res_list = []
for __item in __list:
__res.append(__item)
@res_list.append(__item)
del __item
del __list
)
/* clang-format on */
const uint8_t bytes[] = {
0x3c, 0x00, 0x00, 0x00, /* instruct array size */
0x00, 0x95, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x10, 0x81, 0x07,
0x00, 0x00, 0x02, 0x0e, 0x00, 0x00, 0x04, 0x13, 0x00, 0x00, 0x82,
0x17, 0x00, 0x00, 0x04, 0x24, 0x00, 0x00, 0x0d, 0x24, 0x00, 0x00,
0x07, 0x2b, 0x00, 0x11, 0x81, 0x24, 0x00, 0x01, 0x02, 0x2d, 0x00,
0x00, 0x86, 0x3a, 0x00, 0x00, 0x8c, 0x13, 0x00, 0x00, 0x8c, 0x24,
0x00, 0x00, 0x8c, 0x07, 0x00,
0x00, 0x95, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x10, 0x81, 0x0b,
0x00, 0x00, 0x02, 0x12, 0x00, 0x00, 0x04, 0x17, 0x00, 0x00, 0x82,
0x1b, 0x00, 0x00, 0x04, 0x28, 0x00, 0x00, 0x0d, 0x28, 0x00, 0x00,
0x07, 0x2f, 0x00, 0x11, 0x81, 0x28, 0x00, 0x01, 0x02, 0x31, 0x00,
0x00, 0x86, 0x42, 0x00, 0x00, 0x8c, 0x17, 0x00, 0x00, 0x8c, 0x28,
0x00, 0x00, 0x8c, 0x0b, 0x00,
/* instruct array */
0x3d, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x5f, 0x5f, 0x72, 0x65, 0x73, 0x00, 0x5f, 0x5f, 0x6c, 0x69,
0x73, 0x74, 0x00, 0x69, 0x74, 0x65, 0x72, 0x00, 0x24, 0x6c, 0x30,
0x00, 0x24, 0x6c, 0x30, 0x2e, 0x5f, 0x5f, 0x6e, 0x65, 0x78, 0x74,
0x5f, 0x5f, 0x00, 0x5f, 0x5f, 0x69, 0x74, 0x65, 0x6d, 0x00, 0x32,
0x00, 0x5f, 0x5f, 0x72, 0x65, 0x73, 0x2e, 0x61, 0x70, 0x70, 0x65,
0x6e, 0x64, 0x00, 0x2d, 0x31, 0x00,
/* const pool */
0x45, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x40, 0x72, 0x65, 0x73, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x00,
0x5f, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x00, 0x69, 0x74, 0x65, 0x72,
0x00, 0x24, 0x6c, 0x30, 0x00, 0x24, 0x6c, 0x30, 0x2e, 0x5f, 0x5f,
0x6e, 0x65, 0x78, 0x74, 0x5f, 0x5f, 0x00, 0x5f, 0x5f, 0x69, 0x74,
0x65, 0x6d, 0x00, 0x32, 0x00, 0x40, 0x72, 0x65, 0x73, 0x5f, 0x6c,
0x69, 0x73, 0x74, 0x2e, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x00,
0x2d, 0x31, 0x00, /* const pool */
};
pikaVM_runByteCode(self, (uint8_t*)bytes);
return arg_copy(obj_getArg(self, "__res"));
return pikaVM_runByteCodeReturn(self, (uint8_t*)bytes, "@res_list");
}
PikaObj* New_PikaStdData_List(Args * args);
return arg_newDirectObj(New_PikaStdData_List);
@ -532,8 +531,8 @@ PikaObj* PikaStdLib_SysObj_open(PikaObj* self, char* path, char* mode) {
}
/* __dir_each */
int32_t __dir_each(Arg* argEach, Args* context) {
PikaObj* list = args_getPtr(context, "list");
int32_t __dir_each(Arg* argEach, void* context) {
PikaObj* list = args_getPtr((Args*)context, "list");
if (argType_isCallable(arg_getType(argEach))) {
char name_buff[PIKA_LINE_BUFF_SIZE] = {0};
char* method_name =
@ -671,3 +670,7 @@ void PikaStdLib_SysObj_reboot(PikaObj* self) {
void PikaStdLib_SysObj_clear(PikaObj* self) {
pika_platform_clear();
}
void PikaStdLib_SysObj_gcdump(PikaObj* self) {
pikaGC_markDump();
}

View File

@ -1,5 +1,6 @@
#include "_thread.h"
#include "PikaVM.h"
#include "TinyObj.h"
typedef struct pika_thread_info {
Arg* function;
@ -22,7 +23,7 @@ static void _thread_func(void* arg) {
}
pika_debug("thread start");
pika_GIL_ENTER();
PikaObj* ctx = New_PikaObj();
PikaObj* ctx = New_TinyObj(NULL);
pika_thread_info* info = (pika_thread_info*)arg;
obj_setArg(ctx, "args", info->args);
obj_setArg(ctx, "thread", info->function);

33
packtool-test.cpp Normal file
View File

@ -0,0 +1,33 @@
#include "test_common.h"
TEST_START
#include "PikaCompiler.h"
TEST(packtool, unpack) {
PIKA_RES res = LibObj_unpackFileToPath("test/assets/a.pack", "test/out/unpackout");
EXPECT_EQ(res, PIKA_RES_OK);
}
TEST(packtool, packread) {
size_t n = 0;
//Arg* fileArg = NULL;
pikafs_FILE* pack_file = pikafs_fopen_pack("test/assets/a.pack", "main.py");
// pikafs_FILE* pack_file = pikafs_fopen_pack_new(&fileArg, "test/assets/a.pack", "main.py");
FILE* file = pika_platform_fopen("test/out/unpackout/main2.py", "wb+");
if (NULL == file) {
pika_platform_printf("open file: %s error\r\n", "test/out/unpackout/main2.py");
}
n = pika_platform_fwrite(pack_file->addr, pack_file->size, 1, file);
EXPECT_NE(n, 0);
//arg_deinit(fileArg);
pikaFree(pack_file, sizeof(pikafs_FILE));
pika_platform_fclose(file);
pack_file = NULL;
}
TEST_END

3
port/linux/.clang-format Normal file
View File

@ -0,0 +1,3 @@
Language: Cpp
BasedOnStyle: Chromium
IndentWidth: 4

View File

@ -6,6 +6,7 @@
"${workspaceFolder}/**",
"${workspaceFolder}/package/pikascript/pikascript-api/**",
"${workspaceFolder}/package/pikascript/pikascript-core/**",
"${workspaceFolder}/package/pikascript/pikascript-lib/PikaStdDevice",
"${workspaceFolder}/config/**",
"${workspaceFolder}/test/**",
"/usr/include/lua5.3"

View File

@ -11,7 +11,8 @@
"program": "${workspaceFolder}/build/test/pikascript_test",
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
"args": [
"--gtest_filter=vm.dir_print_arg"
// "--gtest_filter=pikaui.*"
// "--gtest_filter=*.csv*"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",

View File

@ -1,5 +1,8 @@
{
"C_Cpp.clang_format_style": "{ BasedOnStyle: Chromium, IndentWidth: 4}",
"C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json",
"editor.defaultFormatter": "xaver.clang-format",
"C_Cpp.intelliSenseEngine": "disabled",
"files.associations": {
"*.rs": "rust",
"pikastdlib_sysobj.h": "c",
@ -112,7 +115,14 @@
"pthread.h": "c",
"deque": "c",
"list": "c",
"vector": "c"
"vector": "c",
"datastrs.h": "c",
"__instruction_table.h": "c",
"assert.h": "c"
},
"python.formatting.provider": "autopep8",
"clangd.arguments": [
"-compile-commands-dir=build",
"-header-insertion=never"
]
}

View File

@ -5,6 +5,7 @@ IF(PIKA_CONFIG_ENABLE)
ADD_DEFINITIONS(-DPIKA_CONFIG_ENABLE)
ENDIF(PIKA_CONFIG_ENABLE)
ADD_DEFINITIONS(-DUSE_GOOGLE_TEST=1)
set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
# support lto
@ -21,6 +22,7 @@ SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-arcs
include_directories(package/pikascript/pikascript-core)
include_directories(package/pikascript/pikascript-api)
include_directories(package/pikascript/pikascript-lib/PikaNN/TinyMaix/include)
include_directories(package/pikascript/pikascript-lib/PikaStdDevice)
include_directories(test)
INCLUDE_DIRECTORIES(/usr/include/lua5.3)

View File

@ -2,4 +2,4 @@
rm build/test/pikascript_test -f
rm $(find build -name *.gcda)
sh make.sh
build/test/pikascript_test
build/test/pikascript_test

View File

@ -5,4 +5,7 @@
#define PIKA_READ_FILE_BUFF_SIZE 1024 * 40
#define PIKA_INSTRUCT_HOOK_ENABLE 1
#define PIKA_INSTRUCT_HOOK_PERIOD 1
#define PIKA_SHELL_FILTER_ENABLE 1
#define PIKA_SHELL_FILTER_ENABLE 1
#define PIKA_GC_MARK_SWEEP_ENABLE 1
#define PIKA_GC_MARK_SWEEP_THRESHOLD 1
#define PIKA_KERNAL_DEBUG_ENABLE 1

View File

@ -337,9 +337,9 @@ stack_init(&bs);
EXPECT_EQ(pikaMemNow(), 0);
}
extern PikaMemInfo pikaMemInfo;
extern PikaMemInfo g_PikaMemInfo;
TEST(parser, while_true_if_false_both_exit) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* bf = New_strBuff();
Stack bs;
stack_init(&bs);
@ -377,7 +377,7 @@ stack_init(&bs);
}
TEST(parser, multiLine) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines =(char *)
"while true:\n"
@ -414,7 +414,7 @@ TEST(parser, multiLine) {
}
TEST(parser, pikaPi) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
const char lines[] =
@ -533,7 +533,7 @@ TEST(parser, pikaPi) {
}
TEST(parser, add) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)"a = 1 + 1\n";
printf("%s", lines);
@ -550,7 +550,7 @@ TEST(parser, add) {
}
TEST(parser, add_3) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)"a = 1 + 2 + 3\n";
printf("%s", lines);
@ -569,7 +569,7 @@ TEST(parser, add_3) {
}
TEST(parser, add_a_pp) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)"a = a + 1\n";
printf("%s", lines);
@ -586,7 +586,7 @@ TEST(parser, add_a_pp) {
}
TEST(parser, while_a_pp) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)
"while a < 10:\n"
@ -618,7 +618,7 @@ TEST(parser, while_a_pp) {
}
TEST(parser, add_m2p3) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)"a = 1 * 2 + 3\n";
printf("%s", lines);
@ -637,7 +637,7 @@ TEST(parser, add_m2p3) {
}
TEST(parser, add_m2p3_) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)"a = 1 * (2 + 3)\n";
printf("%s", lines);
@ -657,7 +657,7 @@ TEST(parser, add_m2p3_) {
}
TEST(parser, add_m12p3_) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)"a = (1 + 2) * 3\n";
printf("%s", lines);
@ -677,7 +677,7 @@ TEST(parser, add_m12p3_) {
}
TEST(parser, method_equ) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)"if right.read() == 1:\n";
printf("%s", lines);
@ -694,7 +694,7 @@ TEST(parser, method_equ) {
}
TEST(parser, equ_method) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)"if 1 == right.read() :\n";
printf("%s", lines);
@ -711,7 +711,7 @@ TEST(parser, equ_method) {
}
TEST(parser, def_add) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)
"def add(a, b):\n"
@ -737,7 +737,7 @@ TEST(parser, def_add) {
}
TEST(parser, def_add_return) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)
"def add(a, b):\n"
@ -764,7 +764,7 @@ TEST(parser, def_add_return) {
}
TEST(parser, def_while_return) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)
"def add(a, b):\n"
@ -797,7 +797,7 @@ TEST(parser, def_while_return) {
}
TEST(parser, def_while_return_void) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)
"def add(a, b):\n"
@ -827,7 +827,7 @@ TEST(parser, def_while_return_void) {
}
TEST(parser, signed_num) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)"a = -1\n";
printf("%s", lines);
@ -843,7 +843,7 @@ TEST(parser, signed_num) {
}
TEST(parser, comp_signed_num) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)"if a > -1:\n";
printf("%s", lines);
@ -862,7 +862,7 @@ TEST(parser, comp_signed_num) {
TEST(lexser, symbol_add) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
/* run */
@ -881,7 +881,7 @@ TEST(lexser, symbol_add) {
TEST(lexser, symbol_1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
/* run */
@ -899,7 +899,7 @@ TEST(lexser, symbol_1) {
TEST(lexser, operator_not) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
/* run */
@ -917,7 +917,7 @@ TEST(lexser, operator_not) {
TEST(lexser, symbol_Nag) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
/* run */
@ -935,7 +935,7 @@ TEST(lexser, symbol_Nag) {
TEST(lexser, operator_all) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
/* run */
@ -967,7 +967,7 @@ TEST(lexser, operator_all) {
TEST(lexser, symbol_2) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
/* run */
@ -987,7 +987,7 @@ TEST(lexser, symbol_2) {
TEST(lexser, symbol_and) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
/* run */
@ -1007,7 +1007,7 @@ TEST(lexser, symbol_and) {
TEST(lexser, sting) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
/* run */
@ -1025,7 +1025,7 @@ TEST(lexser, sting) {
TEST(lexser, num_1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
/* run */
@ -1043,7 +1043,7 @@ TEST(lexser, num_1) {
TEST(lexser, jjcc) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
/* run */
@ -1074,7 +1074,7 @@ TEST(parser, pop_by_str) {
}
TEST(parser, mm) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)"a = a ** -1\n";
printf("%s", lines);
@ -1092,7 +1092,7 @@ TEST(parser, mm) {
}
TEST(parser, self_inc) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)
"a += -1\n"
@ -1156,7 +1156,7 @@ TEST(parser, self_inc) {
}
TEST(parser, n_n1) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)"a = ~-1\n";
printf("%s", lines);
@ -1173,7 +1173,7 @@ TEST(parser, n_n1) {
}
TEST(parser, or_) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = (char*)"( a>1) or (b<= 3)\n";
printf("%s", lines);

View File

@ -134,6 +134,7 @@ class String:
def replace(self, old: str, new: str) -> str: ...
def strip(self, *chrs) -> str: ...
def format(self, *vars) -> str: ...
def join(self, val: any) -> str: ...
class ByteArray:

View File

@ -134,6 +134,10 @@ class SysObj:
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def clear(): ...
@staticmethod
@PIKA_C_MACRO_IF("PIKA_GC_MARK_SWEEP_ENABLE")
def gcdump(): ...
@PIKA_C_MACRO_IF("0")
class RangeObj:

View File

@ -0,0 +1,218 @@
# SPDX-FileCopyrightText: 2003 Python Software Foundation
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2021 Alec Delaney
#
# SPDX-License-Identifier: MIT
# SPDX-License-Identifier: PSF-2.0
# SPDX-License-Identifier: 0BSD
"""
`pikapython_csv`
================================================================================
PikaPython helper library for working with CSV files
* Author(s): Alec Delaney
* Author(s): Lyon
"""
import re
class reader:
"""Basic CSV reader class that behaves like CPython's ``csv.reader()``
:param csvfile: The open file to read from
:type csvfile: io.TextIOWrapper
:param str delimiter: (Optional) The CSV delimiter, default is comma (,)
:param str quotechar: (Optional) The CSV quote character for encapsulating special characters
including the delimiter, default is double quotation mark (")
"""
def __init__(self, csvfile, delimiter=",", quotechar='"') -> None:
self.file_interator = csvfile
self.delimiter = delimiter
self.quotechar = quotechar
self._re_exp = "(\\{0}.+?\\{0}),|([^{1}]+)".format(quotechar, delimiter)
def __iter__(self):
return self
def __next__(self):
csv_value_list = []
row_string = self.file_interator.__next__()
while len(row_string) != 0:
if row_string.startswith(self.delimiter):
csv_value_list.append("")
row_string = row_string[1:]
continue
next_match = re.match(self._re_exp, row_string)
matches = next_match.groups()
if matches[0] is None:
latest_match = matches[1].strip("\r\n").strip("\n")
csv_value_list.append(latest_match.replace(self.quotechar * 2, self.quotechar))
else:
latest_match = matches[0].strip("\r\n").strip("\n")
csv_value_list.append(
latest_match[1:-1].replace(self.quotechar * 2, self.quotechar)
)
if len(row_string) != 0: # If anything is left in the list...
row_string = row_string[len(latest_match) :]
if row_string == self.delimiter:
csv_value_list.append("")
row_string = row_string[1:]
elif row_string == "\r\n" or row_string == "n":
row_string = ""
row_string = row_string[1:]
return csv_value_list
class writer:
"""Basic CSV writer class that behaves like CPython's ``csv.writer()``
:param csvfile: The open CSVfile to write to
:type csvfile: io.TextIOWrapper
:param str delimiter: (Optional) The CSV delimiter, default is comma (,)
:param str quotechar: (Optional) The CSV quote character for encapsulating special characters
including the delimiter, default is double quotation mark (")
"""
def __init__(self, csvfile, delimiter=",", quoterchar='"'):
self.file_iterator = csvfile
self.delimiter = delimiter
self.quotechar = quoterchar
self.newlinechar = "\r\n"
def writerow(self, seq):
"""Write a row to the CSV file
:param seq: The list of values to write, which must all be str or be able to
be cast to str
:type seq: Sequence[Any]
"""
str_seq = [str(entry) for entry in seq]
doub_quote_seq = [entry.replace(self.quotechar, self.quotechar * 2) for entry in str_seq]
quoted_seq = [self._apply_quotes(entry) for entry in doub_quote_seq]
parsed_str = (self.delimiter).join(quoted_seq)
self.file_iterator.write(parsed_str + self.newlinechar)
def writerows(self, rows):
"""Write multiple rows to the CSV file
:param rows: An iterable item that yields multiple rows to write (e.g., list)
:type rows: Iterable[Sequence[Any]]
"""
for row in rows:
self.writerow(row)
def _apply_quotes(self, entry):
"""Apply the quote character to entries as necessary
:param str entry: The entry to add the quote charcter to, if needed
"""
return (self.quotechar + entry + self.quotechar) if self.delimiter in entry else entry
# Ported from CPython's csv.py:
class DictReader:
"""CSV reader that maps rows to a dict according to given or inferred fieldnames,
it also accepts the delimiter and quotechar keywords
:param f: The open file to read from
:type f: io.TextIOWrapper
:param fieldnames: (Optional) The fieldnames for each of the columns, if none is given,
it will default to the whatever is in the first row of the CSV file
:type fieldnames: Sequence[str]
:param str restkey: (Optional) A key name for values that have no key (row is larger than
the length of fieldnames), default is None
:param restval: (Optional) A default value for keys that have no values (row is small
than the length of fieldnames, default is None
:type restval: Any
"""
def __init__(self, f, fieldnames=None, restkey=None, restval=None, **kwargs):
self.fieldnames = fieldnames
self.restkey = restkey
self.restval = restval
self.reader = reader(f, **kwargs)
self.line_num = 0
def __iter__(self):
return self
def __next__(self):
if self.line_num == 0:
if self.fieldnames is None:
self.fieldnames = next(self.reader)
row = next(self.reader)
row_dict = dict(zip(self.fieldnames, row))
length_fn = len(self.fieldnames)
length_row = len(row)
if length_fn < length_row:
row_dict[self.restkey] = row[length_fn:]
elif length_fn > length_row:
for key in self.fieldnames[length_row:]:
row_dict[key] = self.restval
self.line_num += 1
return row_dict
# Ported from CPython's csv.py
class DictWriter:
"""CSV writer that uses a dict to write the rows according fieldnames, it also accepts the
delimiter and quotechar keywords
:param f: The open file to write to
:type f: io.TextIOWrapper
:param fieldnames: The fieldnames for each of the comlumns
:type fieldnames: Sequence[str]
:param str restval: A default value for keys that have no values
:param str extrasaction: The action to perform if a key is encountered when parsing the dict
that is not included in the fieldnames parameter, either "raise" or "ignore". Ignore
raises a ValueError, and "ignore" simply ignore that key/value pair. Default behavior
is "raise"
"""
def __init__(self, f, fieldnames, restval="", extrasaction="raise", **kwargs):
self.fieldnames = fieldnames # list of keys for the dict
self.restval = restval # for writing short dicts
if extrasaction.lower() not in ("raise", "ignore"):
raise ValueError("extrasaction " "(%s)" " must be 'raise' or 'ignore'" % extrasaction)
self.extrasaction = extrasaction
self.writer = writer(f, **kwargs)
def writeheader(self):
"""Writes the header row to the CSV file"""
self.writerow(dict(zip(self.fieldnames, self.fieldnames)))
def _dict_to_tuple(self, rowdict):
if self.extrasaction == "raise":
wrong_fields = []
for field in rowdict.keys():
if field not in self.fieldnames:
wrong_fields.append(field)
if wrong_fields:
raise ValueError(
"dict contains fields not in fieldnames: "
+ ", ".join([repr(x) for x in wrong_fields])
)
return (rowdict.get(key, self.restval) for key in self.fieldnames)
def writerow(self, rowdict):
"""Writes a row to the CSV file
:param rowdict: The row to write as a dict, with keys of the DictWriter's
fieldnames parameter; values must be str or be able to be cast to str
:type rowdict: Dict[str, Any]
"""
return self.writer.writerow(self._dict_to_tuple(rowdict))
def writerows(self, rowdicts):
"""Writes multiple rows to the CSV files
:param rowdicts: An iterable item that yields multiple rows to write;
values in those rows must be str or be able to be cast to str
:type rowdicts: Iterable[Dict[str, Any]]
"""
return self.writer.writerows(map(self._dict_to_tuple, rowdicts))

View File

@ -8,12 +8,14 @@
#include "dataStrs.h"
Arg* PikaStdData_Dict_get(PikaObj* self, char* key) {
pika_assert_obj_alive(self);
PikaDict* dict = obj_getPtr(self, "dict");
Arg* res = pikaDict_getArg(dict, key);
if (NULL == res) {
obj_setErrorCode(self, PIKA_RES_ERR_RUNTIME_ERROR);
__platform_printf("KeyError: %s\n", key);
}
pika_assert_arg_alive(res);
return arg_copy(res);
}
@ -271,7 +273,7 @@ void PikaStdData_Dict_update(PikaObj* self, PikaObj* other) {
const uint8_t
bytes[] =
{
0x40, 0x00, 0x00, 0x00,/* instruct array size */
0x40, 0x00, 0x00, 0x00, /* instruct array size */
0x10, 0x81, 0x01, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x04,
0x0d, 0x00, 0x00, 0x82, 0x11, 0x00, 0x00, 0x04, 0x1e, 0x00,
0x00, 0x0d, 0x1e, 0x00, 0x00, 0x07, 0x24, 0x00, 0x11, 0x81,
@ -279,7 +281,7 @@ void PikaStdData_Dict_update(PikaObj* self, PikaObj* other) {
0x21, 0x01, 0x1e, 0x00, 0x11, 0x1d, 0x00, 0x00, 0x01, 0x02,
0x2c, 0x00, 0x01, 0x04, 0x26, 0x00, 0x00, 0x86, 0x38, 0x00,
0x00, 0x8c, 0x0d, 0x00, /* instruct array */
0x3b, 0x00, 0x00, 0x00, /* const pool size */
0x3b, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x40, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x00, 0x69, 0x74,
0x65, 0x72, 0x00, 0x24, 0x6c, 0x30, 0x00, 0x24, 0x6c, 0x30,
0x2e, 0x5f, 0x5f, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x5f, 0x00,

View File

@ -1,6 +1,7 @@
#include "PikaStdData_String.h"
#include "PikaStdData_List.h"
#include "PikaStdData_String_Util.h"
#include "PikaStdLib_SysObj.h"
#include "PikaVM.h"
#include "dataStrs.h"
@ -813,3 +814,47 @@ char* PikaStdData_String_format(PikaObj* self, PikaTuple* vars) {
/* 'test{}'.format(123) */
return NULL;
}
char* PikaStdData_String_join(PikaObj* self, Arg* val) {
PikaObj* context = newNormalObj(New_PikaStdLib_SysObj);
obj_setArg(context, "@val", val);
obj_setStr(context, "@str", obj_getStr(self, "str"));
/* clang-format off */
PIKA_PYTHON(
@res_join = ""
@num = len(@val)
for i in range(@num):
@res_join += @val[i]
if i != @num - 1:
@res_join += @str
)
/* clang-format on */
const uint8_t bytes[] = {
0x84, 0x00, 0x00, 0x00, /* instruct array size */
0x00, 0x83, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x10, 0x81, 0x0b, 0x00,
0x00, 0x02, 0x10, 0x00, 0x00, 0x04, 0x14, 0x00, 0x20, 0x81, 0x14, 0x00,
0x10, 0x02, 0x19, 0x00, 0x00, 0x02, 0x1f, 0x00, 0x00, 0x04, 0x24, 0x00,
0x00, 0x82, 0x28, 0x00, 0x00, 0x04, 0x35, 0x00, 0x00, 0x0d, 0x35, 0x00,
0x00, 0x07, 0x37, 0x00, 0x11, 0x81, 0x01, 0x00, 0x31, 0x01, 0x0b, 0x00,
0x31, 0x01, 0x35, 0x00, 0x21, 0x1d, 0x00, 0x00, 0x11, 0x02, 0x00, 0x00,
0x01, 0x08, 0x39, 0x00, 0x01, 0x04, 0x01, 0x00, 0x11, 0x81, 0x35, 0x00,
0x21, 0x01, 0x14, 0x00, 0x21, 0x05, 0x3b, 0x00, 0x11, 0x08, 0x3d, 0x00,
0x01, 0x08, 0x3f, 0x00, 0x01, 0x07, 0x3b, 0x00, 0x12, 0x81, 0x01, 0x00,
0x22, 0x01, 0x42, 0x00, 0x12, 0x02, 0x00, 0x00, 0x02, 0x08, 0x39, 0x00,
0x02, 0x04, 0x01, 0x00, 0x00, 0x86, 0x47, 0x00, 0x00, 0x8c, 0x24, 0x00,
/* instruct array */
0x4a, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x40, 0x72, 0x65, 0x73, 0x5f, 0x6a, 0x6f, 0x69, 0x6e, 0x00, 0x40,
0x76, 0x61, 0x6c, 0x00, 0x6c, 0x65, 0x6e, 0x00, 0x40, 0x6e, 0x75, 0x6d,
0x00, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x69, 0x74, 0x65, 0x72, 0x00,
0x24, 0x6c, 0x30, 0x00, 0x24, 0x6c, 0x30, 0x2e, 0x5f, 0x5f, 0x6e, 0x65,
0x78, 0x74, 0x5f, 0x5f, 0x00, 0x69, 0x00, 0x32, 0x00, 0x2b, 0x00, 0x31,
0x00, 0x2d, 0x00, 0x21, 0x3d, 0x00, 0x40, 0x73, 0x74, 0x72, 0x00, 0x2d,
0x31, 0x00, /* const pool */
};
pikaVM_runByteCode(context, (uint8_t*)bytes);
char* sRes = obj_cacheStr(self, obj_getStr(context, "@res_join"));
obj_deinit(context);
return sRes;
}

View File

@ -169,65 +169,64 @@ char* PikaStdLib_SysObj_str(PikaObj* self, Arg* arg) {
Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
/* object */
PIKA_BOOL is_temp = PIKA_FALSE;
PikaObj* arg_obj = _arg_to_obj(arg, &is_temp);
NewFun _clsptr = (NewFun)arg_obj->constructor;
PIKA_BOOL bIsTemp = PIKA_FALSE;
PikaObj* oArg = _arg_to_obj(arg, &bIsTemp);
NewFun _clsptr = (NewFun)oArg->constructor;
if (_clsptr == New_PikaStdLib_RangeObj) {
/* found RangeObj, return directly */
return arg_copy(arg);
}
// pikaVM_runAsm(arg_obj,
// "B0\n"
// "0 RUN __iter__\n"
// "0 OUT __res\n");
/* clang-format off */
PIKA_PYTHON(
@res_iter = __iter__()
)
/* clang-format on */
const uint8_t bytes[] = {
0x08, 0x00, 0x00, 0x00, /* instruct array size */
0x00, 0x82, 0x01, 0x00, 0x00, 0x04, 0x0a, 0x00, /* instruct array */
0x10, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x5f, 0x5f, 0x69, 0x74, 0x65, 0x72, 0x5f,
0x5f, 0x00, 0x5f, 0x5f, 0x72, 0x65, 0x73, 0x00, /* const pool */
0x14, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x5f, 0x5f, 0x69, 0x74, 0x65, 0x72, 0x5f, 0x5f, 0x00, 0x40,
0x72, 0x65, 0x73, 0x5f, 0x69, 0x74, 0x65, 0x72, 0x00, /* const pool */
};
pikaVM_runByteCode(arg_obj, (uint8_t*)bytes);
Arg* res = arg_copy(args_getArg(arg_obj->list, "__res"));
obj_removeArg(arg_obj, "__res");
if (is_temp) {
obj_refcntDec(arg_obj);
Arg* res = pikaVM_runByteCodeReturn(oArg, (uint8_t*)bytes, "@res_iter");
if (bIsTemp) {
obj_refcntDec(oArg);
}
return res;
}
Arg* PikaStdLib_SysObj_range(PikaObj* self, PikaTuple* ax) {
/* set template arg to create rangeObj */
Arg* obj_arg = arg_newDirectObj(New_PikaStdLib_RangeObj);
PikaObj* range_obj = arg_getPtr(obj_arg);
RangeData range_data = {0};
Arg* aRangeObj = arg_newDirectObj(New_PikaStdLib_RangeObj);
PikaObj* oRangeObj = arg_getPtr(aRangeObj);
RangeData tRangeData = {0};
if (pikaTuple_getSize(ax) == 1) {
int start = 0;
int end = arg_getInt(pikaTuple_getArg(ax, 0));
range_data.start = start;
range_data.end = end;
range_data.step = 1;
tRangeData.start = start;
tRangeData.end = end;
tRangeData.step = 1;
} else if (pikaTuple_getSize(ax) == 2) {
int start = arg_getInt(pikaTuple_getArg(ax, 0));
int end = arg_getInt(pikaTuple_getArg(ax, 1));
range_data.start = start;
range_data.end = end;
range_data.step = 1;
tRangeData.start = start;
tRangeData.end = end;
tRangeData.step = 1;
} else if (pikaTuple_getSize(ax) == 3) {
int start = arg_getInt(pikaTuple_getArg(ax, 0));
int end = arg_getInt(pikaTuple_getArg(ax, 1));
int step = arg_getInt(pikaTuple_getArg(ax, 2));
range_data.start = start;
range_data.end = end;
range_data.step = step;
tRangeData.start = start;
tRangeData.end = end;
tRangeData.step = step;
}
range_data.i = range_data.start;
obj_setStruct(range_obj, "_", range_data);
return obj_arg;
tRangeData.i = tRangeData.start;
obj_setStruct(oRangeObj, "_", tRangeData);
return aRangeObj;
}
Arg* PikaStdLib_SysObj___getitem__(PikaObj* self, Arg* obj, Arg* key) {
return __vm_get(NULL, self, key, obj);
return _vm_get(NULL, self, key, obj);
}
Arg* PikaStdLib_SysObj___setitem__(PikaObj* self,
@ -296,22 +295,22 @@ int PikaStdLib_SysObj_len(PikaObj* self, Arg* arg) {
Arg* method_arg = obj_getMethodArg(arg_obj, "__len__");
if (NULL != method_arg) {
arg_deinit(method_arg);
obj_removeArg(arg_obj, "@res_len");
/* clang-format off */
PIKA_PYTHON(
__res = __len__()
)
PIKA_PYTHON(
@res_len = __len__()
)
/* clang-format on */
const uint8_t bytes[] = {
0x08, 0x00, 0x00, 0x00, /* instruct array size */
0x00, 0x82, 0x01, 0x00, 0x00, 0x04, 0x09, 0x00, /* instruct
array */
0x0f, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x5f, 0x5f, 0x6c, 0x65, 0x6e, 0x5f, 0x5f, 0x00,
0x5f, 0x5f, 0x72, 0x65, 0x73, 0x00, /* const pool */
0x12, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x5f, 0x5f, 0x6c, 0x65, 0x6e, 0x5f, 0x5f, 0x00, 0x40,
0x72, 0x65, 0x73, 0x5f, 0x6c, 0x65, 0x6e, 0x00, /* const pool */
};
pikaVM_runByteCode(arg_obj, (uint8_t*)bytes);
return obj_getInt(arg_obj, "__res");
return obj_getInt(arg_obj, "@res_len");
}
}
@ -327,33 +326,33 @@ Arg* PikaStdLib_SysObj_list(PikaObj* self, PikaTuple* val) {
obj_setArg(self, "__list", in);
/* clang-format off */
PIKA_PYTHON(
__res = []
@res_list = []
for __item in __list:
__res.append(__item)
@res_list.append(__item)
del __item
del __list
)
/* clang-format on */
const uint8_t bytes[] = {
0x3c, 0x00, 0x00, 0x00, /* instruct array size */
0x00, 0x95, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x10, 0x81, 0x07,
0x00, 0x00, 0x02, 0x0e, 0x00, 0x00, 0x04, 0x13, 0x00, 0x00, 0x82,
0x17, 0x00, 0x00, 0x04, 0x24, 0x00, 0x00, 0x0d, 0x24, 0x00, 0x00,
0x07, 0x2b, 0x00, 0x11, 0x81, 0x24, 0x00, 0x01, 0x02, 0x2d, 0x00,
0x00, 0x86, 0x3a, 0x00, 0x00, 0x8c, 0x13, 0x00, 0x00, 0x8c, 0x24,
0x00, 0x00, 0x8c, 0x07, 0x00,
0x00, 0x95, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x10, 0x81, 0x0b,
0x00, 0x00, 0x02, 0x12, 0x00, 0x00, 0x04, 0x17, 0x00, 0x00, 0x82,
0x1b, 0x00, 0x00, 0x04, 0x28, 0x00, 0x00, 0x0d, 0x28, 0x00, 0x00,
0x07, 0x2f, 0x00, 0x11, 0x81, 0x28, 0x00, 0x01, 0x02, 0x31, 0x00,
0x00, 0x86, 0x42, 0x00, 0x00, 0x8c, 0x17, 0x00, 0x00, 0x8c, 0x28,
0x00, 0x00, 0x8c, 0x0b, 0x00,
/* instruct array */
0x3d, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x5f, 0x5f, 0x72, 0x65, 0x73, 0x00, 0x5f, 0x5f, 0x6c, 0x69,
0x73, 0x74, 0x00, 0x69, 0x74, 0x65, 0x72, 0x00, 0x24, 0x6c, 0x30,
0x00, 0x24, 0x6c, 0x30, 0x2e, 0x5f, 0x5f, 0x6e, 0x65, 0x78, 0x74,
0x5f, 0x5f, 0x00, 0x5f, 0x5f, 0x69, 0x74, 0x65, 0x6d, 0x00, 0x32,
0x00, 0x5f, 0x5f, 0x72, 0x65, 0x73, 0x2e, 0x61, 0x70, 0x70, 0x65,
0x6e, 0x64, 0x00, 0x2d, 0x31, 0x00,
/* const pool */
0x45, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x40, 0x72, 0x65, 0x73, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x00,
0x5f, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x00, 0x69, 0x74, 0x65, 0x72,
0x00, 0x24, 0x6c, 0x30, 0x00, 0x24, 0x6c, 0x30, 0x2e, 0x5f, 0x5f,
0x6e, 0x65, 0x78, 0x74, 0x5f, 0x5f, 0x00, 0x5f, 0x5f, 0x69, 0x74,
0x65, 0x6d, 0x00, 0x32, 0x00, 0x40, 0x72, 0x65, 0x73, 0x5f, 0x6c,
0x69, 0x73, 0x74, 0x2e, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x00,
0x2d, 0x31, 0x00, /* const pool */
};
pikaVM_runByteCode(self, (uint8_t*)bytes);
return arg_copy(obj_getArg(self, "__res"));
return pikaVM_runByteCodeReturn(self, (uint8_t*)bytes, "@res_list");
}
PikaObj* New_PikaStdData_List(Args * args);
return arg_newDirectObj(New_PikaStdData_List);
@ -532,8 +531,8 @@ PikaObj* PikaStdLib_SysObj_open(PikaObj* self, char* path, char* mode) {
}
/* __dir_each */
int32_t __dir_each(Arg* argEach, Args* context) {
PikaObj* list = args_getPtr(context, "list");
int32_t __dir_each(Arg* argEach, void* context) {
PikaObj* list = args_getPtr((Args*)context, "list");
if (argType_isCallable(arg_getType(argEach))) {
char name_buff[PIKA_LINE_BUFF_SIZE] = {0};
char* method_name =
@ -671,3 +670,7 @@ void PikaStdLib_SysObj_reboot(PikaObj* self) {
void PikaStdLib_SysObj_clear(PikaObj* self) {
pika_platform_clear();
}
void PikaStdLib_SysObj_gcdump(PikaObj* self) {
pikaGC_markDump();
}

View File

@ -1,5 +1,6 @@
#include "_thread.h"
#include "PikaVM.h"
#include "TinyObj.h"
typedef struct pika_thread_info {
Arg* function;
@ -22,7 +23,7 @@ static void _thread_func(void* arg) {
}
pika_debug("thread start");
pika_GIL_ENTER();
PikaObj* ctx = New_PikaObj();
PikaObj* ctx = New_TinyObj(NULL);
pika_thread_info* info = (pika_thread_info*)arg;
obj_setArg(ctx, "args", info->args);
obj_setArg(ctx, "thread", info->function);

View File

@ -29,11 +29,11 @@ int main(void) {
/* deinit */
obj_deinit(pikaMain);
#if PIKA_ARG_CACHE_ENABLE
extern PikaMemInfo pikaMemInfo;
extern PikaMemInfo g_PikaMemInfo;
printf("[ Info]: alloc times: %d, cached times: %d (%0.2f%%)\r\n",
pikaMemInfo.alloc_times, pikaMemInfo.alloc_times_cache,
((float)pikaMemInfo.alloc_times_cache /
(float)pikaMemInfo.alloc_times) *
g_PikaMemInfo.alloc_times, g_PikaMemInfo.alloc_times_cache,
((float)g_PikaMemInfo.alloc_times_cache /
(float)g_PikaMemInfo.alloc_times) *
100.0);
#endif
printf("[ Info]: time elapsed: %lfs\r\n",

View File

@ -1,9 +1,9 @@
sh only_make.sh
if [ $# == 0 ] ; then
valgrind -s --track-origins=yes --leak-check=full --show-leak-kinds=all --exit-on-first-error=yes --error-exitcode=1 build/test/pikascript_test --num-callers=50
valgrind -s --track-origins=yes --leak-check=full --show-leak-kinds=all --exit-on-first-error=yes --error-exitcode=1 --num-callers=50 build/test/pikascript_test
fi
if [ $# == 1 ] ; then
filter=$1
valgrind -s --track-origins=yes --leak-check=full --show-leak-kinds=all build/test/pikascript_test --gtest_filter=$filter --exit-on-first-error=yes --error-exitcode=1 --num-callers=50
valgrind -s --track-origins=yes --leak-check=full --show-leak-kinds=all --exit-on-first-error=yes --error-exitcode=1 --num-callers=50 build/test/pikascript_test --gtest_filter=$filter
fi

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*
@ -219,7 +219,7 @@ PIKA_RES pikaCompileFile(char* input_file_name) {
}
LibObj* New_LibObj(Args* args) {
LibObj* self = New_TinyObj(NULL);
LibObj* self = New_PikaObj();
return self;
}
@ -300,7 +300,7 @@ int LibObj_staticLinkFile(LibObj* self, char* input_file_name) {
return 0;
}
static int32_t __foreach_handler_listModules(Arg* argEach, Args* context) {
static int32_t __foreach_handler_listModules(Arg* argEach, void* context) {
if (arg_isObject(argEach)) {
PikaObj* module_obj = arg_getPtr(argEach);
pika_platform_printf("%s\r\n", obj_getStr(module_obj, "name"));
@ -312,8 +312,8 @@ void LibObj_listModules(LibObj* self) {
args_foreach(self->list, __foreach_handler_listModules, NULL);
}
static int32_t __foreach_handler_libWriteBytecode(Arg* argEach, Args* context) {
FILE* out_file = args_getPtr(context, "out_file");
static int32_t __foreach_handler_libWriteBytecode(Arg* argEach, void* context) {
FILE* out_file = args_getPtr((Args*)context, "out_file");
if (arg_isObject(argEach)) {
PikaObj* module_obj = arg_getPtr(argEach);
char* bytecode = obj_getPtr(module_obj, "bytecode");
@ -327,8 +327,9 @@ static int32_t __foreach_handler_libWriteBytecode(Arg* argEach, Args* context) {
return 0;
}
static int32_t __foreach_handler_libWriteIndex(Arg* argEach, Args* context) {
FILE* out_file = args_getPtr(context, "out_file");
static int32_t __foreach_handler_libWriteIndex(Arg* argEach, void* context) {
Args* args = context;
FILE* out_file = args_getPtr(args, "out_file");
Args buffs = {0};
if (arg_isObject(argEach)) {
PikaObj* module_obj = arg_getPtr(argEach);
@ -348,21 +349,22 @@ static int32_t __foreach_handler_libWriteIndex(Arg* argEach, Args* context) {
return 0;
}
static int32_t __foreach_handler_libSumSize(Arg* argEach, Args* context) {
static int32_t __foreach_handler_libSumSize(Arg* argEach, void* context) {
Args* args = context;
if (arg_isObject(argEach)) {
PikaObj* module_obj = arg_getPtr(argEach);
uint32_t bytecode_size = obj_getBytesSize(module_obj, "buff");
bytecode_size = aline_by(bytecode_size, sizeof(uint32_t));
args_setInt(context, "sum_size",
args_getInt(context, "sum_size") + bytecode_size);
args_setInt(args, "sum_size",
args_getInt(args, "sum_size") + bytecode_size);
}
return 0;
}
static int32_t __foreach_handler_getModuleNum(Arg* argEach, Args* context) {
static int32_t __foreach_handler_getModuleNum(Arg* argEach, void* context) {
Args* args = (Args*)context;
if (arg_isObject(argEach)) {
args_setInt(context, "module_num",
args_getInt(context, "module_num") + 1);
args_setInt(args, "module_num", args_getInt(args, "module_num") + 1);
}
return 0;
}
@ -493,6 +495,40 @@ PIKA_RES _loadModuleDataWithName(uint8_t* library_bytes,
return PIKA_RES_ERR_ARG_NO_FOUND;
}
/**
* @brief .pack pack library_bytes
*
* @param pikafs_FILE** fp pikafs_FILE
*
* @param Arg** f_arg
* @param char* pack_name pack
* @return PIKA_RES_OK when success, otherwise failed;
* @note if failed *fp if freed
*
*/
PIKA_RES _getPack_libraryBytes(pikafs_FILE** fp, Arg** f_arg, char* pack_name) {
if (NULL == pack_name) {
return PIKA_RES_ERR_INVALID_PTR;
}
*fp = (pikafs_FILE*)pikaMalloc(sizeof(pikafs_FILE));
if (NULL == *fp) {
pika_platform_printf("Error: malloc failed \r\n");
return PIKA_RES_ERR_OUT_OF_RANGE;
}
memset(*fp, 0, sizeof(pikafs_FILE));
*f_arg = arg_loadFile(NULL, pack_name);
if (NULL == *f_arg) {
pika_platform_printf("Error: Could not load file \'%s\'\r\n",
pack_name);
pikaFree(*fp, sizeof(pikafs_FILE));
// fp == NULL;
return PIKA_RES_ERR_IO_ERROR;
}
return PIKA_RES_OK;
}
int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes) {
int module_num = _getModuleNum(library_bytes);
if (module_num < 0) {
@ -510,7 +546,7 @@ int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes) {
return PIKA_RES_OK;
}
int32_t __foreach_handler_printModule(Arg* argEach, Args* context) {
int32_t __foreach_handler_printModule(Arg* argEach, void* context) {
if (arg_isObject(argEach)) {
PikaObj* module_obj = arg_getPtr(argEach);
char* module_name = obj_getStr(module_obj, "name");
@ -543,6 +579,60 @@ int LibObj_loadLibraryFile(LibObj* self, char* lib_file_name) {
return PIKA_RES_OK;
}
/**
* @brief unpack *.pack file to Specified path
*
* @param pack_name the name of *.pack file
* @param out_path output path
* @return
*/
PIKA_RES LibObj_unpackFileToPath(char* pack_name, char* out_path) {
PIKA_RES stat = PIKA_RES_OK;
Arg* file_arg = NULL;
uint8_t* library_bytes = NULL;
pikafs_FILE* fptr = NULL;
stat = _getPack_libraryBytes(&fptr, &file_arg, pack_name);
if (PIKA_RES_OK == stat) {
library_bytes = arg_getBytes(file_arg);
} else {
return stat;
}
int module_num = _getModuleNum(library_bytes);
if (module_num < 0) {
return (PIKA_RES)module_num;
}
Args buffs = {0};
char* output_file_path = NULL;
FILE* new_fp = NULL;
for (int i = 0; i < module_num; ++i) {
char* name = NULL;
uint8_t* addr = NULL;
size_t size = 0;
_loadModuleDataWithIndex(library_bytes, module_num, i, &name, &addr,
&size);
output_file_path = strsPathJoin(&buffs, out_path, name);
new_fp = pika_platform_fopen(output_file_path, "wb+");
if (NULL != new_fp) {
pika_platform_fwrite(addr, size, 1, new_fp);
pika_platform_fclose(new_fp);
pika_platform_printf("extract %s to %s\r\n", name,
output_file_path);
} else {
pika_platform_printf("can't open %s\r\n", output_file_path);
break;
}
}
arg_deinit(file_arg);
strsDeinit(&buffs);
pikaFree(fptr, sizeof(pikafs_FILE));
return PIKA_RES_OK;
}
size_t pika_fputs(char* str, FILE* fp) {
size_t size = strGetSize(str);
return pika_platform_fwrite(str, 1, size, fp);
@ -615,7 +705,7 @@ static PIKA_RES __Maker_compileModuleWithInfo(PikaMaker* self,
}
PikaMaker* New_PikaMaker(void) {
PikaMaker* self = New_TinyObj(NULL);
PikaMaker* self = New_PikaObj();
obj_setStr(self, "pwd", "");
obj_setInt(self, "err", 0);
LibObj* lib = New_LibObj(NULL);
@ -703,7 +793,7 @@ int pikaMaker_getDependencies(PikaMaker* self, char* module_name) {
if (NULL == ins_unit) {
goto exit;
}
if (instructUnit_getInstruct(ins_unit) == IMP) {
if (instructUnit_getInstructIndex(ins_unit) == IMP) {
char* imp_module_name =
constPool_getByOffset(const_pool, ins_unit->const_pool_index);
char* imp_module_path =
@ -783,7 +873,7 @@ exit:
return res;
}
int32_t __foreach_handler_printStates(Arg* argEach, Args* context) {
int32_t __foreach_handler_printStates(Arg* argEach, void* context) {
if (arg_isObject(argEach)) {
PikaObj* module_obj = arg_getPtr(argEach);
pika_platform_printf("%s: %s\r\n", obj_getStr(module_obj, "name"),
@ -796,17 +886,17 @@ void pikaMaker_printStates(PikaMaker* self) {
args_foreach(self->list, __foreach_handler_printStates, NULL);
}
int32_t __foreach_handler_getFirstNocompiled(Arg* argEach, Args* context) {
int32_t __foreach_handler_getFirstNocompiled(Arg* argEach, void* context) {
if (arg_isObject(argEach)) {
PikaObj* module_obj = arg_getPtr(argEach);
char* state = obj_getStr(module_obj, "state");
if (args_isArgExist(context, "res")) {
if (args_isArgExist((Args*)context, "res")) {
/* already get method */
return 0;
}
if (strEqu("nocompiled", state)) {
/* push module */
args_setStr(context, "res", obj_getStr(module_obj, "name"));
args_setStr((Args*)context, "res", obj_getStr(module_obj, "name"));
return 0;
}
}
@ -858,11 +948,11 @@ PIKA_RES pikaMaker_compileModuleWithDepends(PikaMaker* self,
return PIKA_RES_OK;
}
int32_t __foreach_handler_linkCompiledModules(Arg* argEach, Args* context) {
int32_t __foreach_handler_linkCompiledModules(Arg* argEach, void* context) {
Args buffs = {0};
if (arg_isObject(argEach)) {
LibObj* lib = args_getPtr(context, "@lib");
PikaMaker* maker = args_getPtr(context, "__maker");
LibObj* lib = args_getPtr((Args*)context, "@lib");
PikaMaker* maker = args_getPtr((Args*)context, "__maker");
PikaObj* module_obj = arg_getPtr(argEach);
char* module_name = obj_getStr(module_obj, "name");
char* state = obj_getStr(module_obj, "state");
@ -960,6 +1050,27 @@ pikafs_FILE* pikafs_fopen(char* file_name, char* mode) {
return f;
}
pikafs_FILE* pikafs_fopen_pack(char* pack_name, char* file_name) {
pikafs_FILE* f = NULL;
Arg* file_arg = NULL;
PIKA_RES stat = PIKA_RES_OK;
uint8_t* library_bytes = NULL;
stat = _getPack_libraryBytes(&f, &file_arg, pack_name);
if (PIKA_RES_OK == stat) {
library_bytes = arg_getBytes(file_arg);
} else {
return NULL;
}
if (PIKA_RES_OK !=
_loadModuleDataWithName(library_bytes, file_name, &f->addr, &f->size)) {
return NULL;
}
arg_deinit(file_arg);
return f;
}
/*
* @brief read file
* @param buf the buffer to read

View File

@ -19,6 +19,7 @@ int LibObj_staticLinkFile(LibObj* self, char* input_file_name);
void LibObj_listModules(LibObj* self);
int LibObj_saveLibraryFile(LibObj* self, char* output_file_name);
int LibObj_loadLibraryFile(LibObj* self, char* input_file_name);
PIKA_RES LibObj_unpackFileToPath(char* pack_name, char* out_path);
int Lib_loadLibraryFileToArray(char* origin_file_name, char* pikascript_root);
PikaMaker* New_PikaMaker(void);
void pikaMaker_setPWD(PikaMaker* self, char* pwd);
@ -55,6 +56,7 @@ typedef struct {
} pikafs_FILE;
pikafs_FILE* pikafs_fopen(char* file_name, char* mode);
pikafs_FILE* pikafs_fopen_pack(char* pack_name, char* file_name);
int pikafs_fread(void* buf, size_t size, size_t count, pikafs_FILE* file);
int pikafs_fwrite(void* buf, size_t size, size_t count, pikafs_FILE* file);
int pikafs_fclose(pikafs_FILE* file);

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*
@ -31,15 +31,36 @@
#include "BaseObj.h"
#include "PikaCompiler.h"
#include "PikaPlatform.h"
#include "dataArg.h"
#include "dataArgs.h"
#include "dataMemory.h"
#include "dataQueue.h"
#include "dataString.h"
#include "dataStrs.h"
extern volatile VMSignal PikaVMSignal;
static volatile Arg* _help_modules_cmodule = NULL;
static volatile PIKA_BOOL in_root_obj = PIKA_FALSE;
extern volatile VMSignal g_PikaVMSignal;
volatile PikaObjState g_PikaObjState = {
.helpModulesCmodule = NULL,
.inRootObj = PIKA_FALSE,
#if PIKA_GC_MARK_SWEEP_ENABLE
.objCnt = 0,
.objCntMax = 0,
.objCntLastGC = 0,
.gcChain = NULL,
.markSweepBusy = 0,
#endif
};
PikaObj* New_PikaStdData_Dict(Args* args);
PikaObj* New_PikaStdData_dict_keys(Args* args);
PikaObj* New_PikaStdData_List(Args* args);
PikaObj* New_PikaStdData_Tuple(Args* args);
void _mem_cache_deinit(void);
void _VMEvent_deinit(void);
void pikaGC_markObj(PikaGC* gc, PikaObj* self);
void _pikaGC_mark(PikaGC* gc);
void obj_dump(PikaObj* self);
void Locals_deinit(PikaObj* self);
static enum shellCTRL __obj_shellLineHandler_REPL(PikaObj* self,
char* input_line,
@ -109,14 +130,28 @@ char* fast_itoa(char* buf, uint32_t val) {
static int32_t obj_deinit_no_del(PikaObj* self) {
/* free the list */
Locals_deinit(self);
args_deinit(self->list);
#if PIKA_KERNAL_DEBUG_ENABLE
if (NULL != self->aName) {
arg_deinit(self->aName);
}
#endif
extern volatile PikaObj* __pikaMain;
/* remove self from gc chain */
obj_removeGcChain(self);
/* free the pointer */
pikaFree(self, sizeof(PikaObj));
self = NULL;
if (self == (PikaObj*)__pikaMain) {
__pikaMain = NULL;
}
return 0;
}
int obj_GC(PikaObj* self) {
if (!obj_checkAlive(self)) {
return 0;
}
obj_refcntDec(self);
int ref_cnt = obj_refcntNow(self);
if (ref_cnt <= 0) {
@ -126,6 +161,11 @@ int obj_GC(PikaObj* self) {
}
int32_t obj_deinit(PikaObj* self) {
pikaGC_lock();
PIKA_BOOL bisRoot = PIKA_FALSE;
#if PIKA_KERNAL_DEBUG_ENABLE
self->isAlive = PIKA_FALSE;
#endif
Arg* del = obj_getMethodArg(self, "__del__");
if (NULL != del) {
const uint8_t bytes[] = {
@ -140,19 +180,22 @@ int32_t obj_deinit(PikaObj* self) {
}
extern volatile PikaObj* __pikaMain;
if (self == (PikaObj*)__pikaMain) {
void _mem_cache_deinit(void);
void _VMEvent_deinit(void);
bisRoot = PIKA_TRUE;
_mem_cache_deinit();
#if PIKA_EVENT_ENABLE
_VMEvent_deinit();
#endif
if (NULL != _help_modules_cmodule) {
arg_deinit((Arg*)_help_modules_cmodule);
_help_modules_cmodule = NULL;
if (NULL != g_PikaObjState.helpModulesCmodule) {
arg_deinit(g_PikaObjState.helpModulesCmodule);
g_PikaObjState.helpModulesCmodule = NULL;
}
__pikaMain = NULL;
}
return obj_deinit_no_del(self);
int32_t ret = obj_deinit_no_del(self);
pikaGC_unlock();
if (bisRoot) {
pikaGC_markSweep();
}
return ret;
}
PIKA_RES obj_setInt(PikaObj* self, char* argPath, int64_t val) {
@ -249,6 +292,7 @@ PIKA_BOOL obj_getBool(PikaObj* self, char* argPath) {
}
Arg* obj_getArg(PikaObj* self, char* argPath) {
pika_assert(obj_checkAlive(self));
PIKA_BOOL is_temp = PIKA_FALSE;
PikaObj* obj = obj_getHostObjWithIsTemp(self, argPath, &is_temp);
if (NULL == obj) {
@ -296,34 +340,73 @@ size_t obj_loadBytes(PikaObj* self, char* argPath, uint8_t* out_buff) {
return size_mem;
}
static PIKA_RES __obj_setArg(PikaObj* self,
char* argPath,
Arg* arg,
uint8_t is_copy) {
void obj_setName(PikaObj* self, char* name) {
#if !PIKA_KERNAL_DEBUG_ENABLE
return;
#else
if (strEqu(name, "self")) {
return;
}
if (NULL != self->aName) {
if (!strstr(self->name, name)) {
self->aName = arg_strAppend(self->aName, "|");
self->aName = arg_strAppend(self->aName, name);
}
} else {
self->aName = arg_newStr(name);
}
self->name = arg_getStr(self->aName);
#endif
}
static PIKA_RES _obj_setArg(PikaObj* self,
char* argPath,
Arg* arg,
uint8_t is_copy) {
pika_assert(obj_checkAlive(self));
/* setArg would copy arg */
PikaObj* obj = obj_getHostObj(self, argPath);
if (NULL == obj) {
PikaObj* host = obj_getHostObj(self, argPath);
PikaObj* oNew = NULL;
PIKA_BOOL bNew = PIKA_FALSE;
if (NULL == host) {
/* object no found */
return PIKA_RES_ERR_ARG_NO_FOUND;
}
char* argName = strPointToLastToken(argPath, '.');
Arg* newArg;
char* sArgName = strPointToLastToken(argPath, '.');
Arg* aNew;
if (is_copy) {
newArg = arg_copy(arg);
aNew = arg_copy(arg);
} else {
newArg = arg;
aNew = arg;
}
aNew = arg_setName(aNew, sArgName);
if (arg_isObject(aNew)) {
oNew = arg_getPtr(aNew);
bNew = PIKA_TRUE;
pika_assert(obj_checkAlive(oNew));
#if PIKA_KERNAL_DEBUG_ENABLE
if (host != oNew) {
/* skip self ref */
oNew->parent = host;
}
#endif
obj_setName(oNew, sArgName);
}
args_setArg(host->list, aNew);
/* enable mark sweep to collect this object */
if (bNew) {
/* only enable mark sweep after setArg */
obj_enableGC(oNew);
}
newArg = arg_setName(newArg, argName);
args_setArg(obj->list, newArg);
return PIKA_RES_OK;
}
PIKA_RES obj_setArg(PikaObj* self, char* argPath, Arg* arg) {
return __obj_setArg(self, argPath, arg, 1);
return _obj_setArg(self, argPath, arg, 1);
};
PIKA_RES obj_setArg_noCopy(PikaObj* self, char* argPath, Arg* arg) {
return __obj_setArg(self, argPath, arg, 0);
return _obj_setArg(self, argPath, arg, 0);
}
void* obj_getPtr(PikaObj* self, char* argPath) {
@ -356,15 +439,13 @@ char* obj_getStr(PikaObj* self, char* argPath) {
return res;
}
PikaObj* obj_getClassObjByNewFun(PikaObj* context,
char* name,
NewFun newClassFun) {
Args* initArgs = New_args(NULL);
PikaObj* thisClass = newClassFun(initArgs);
thisClass->constructor = newClassFun;
thisClass->refcnt = 0;
args_deinit(initArgs);
return thisClass;
PikaObj* obj_newObjFromConstructor(PikaObj* context,
char* name,
NewFun constructor) {
PikaObj* self = constructor(NULL);
self->constructor = constructor;
self->refcnt = 1;
return self;
}
Arg* _obj_getProp(PikaObj* obj, char* name) {
@ -458,7 +539,7 @@ PikaObj* obj_getClassObj(PikaObj* obj) {
if (NULL == classPtr) {
return NULL;
}
PikaObj* classObj = obj_getClassObjByNewFun(obj, "", classPtr);
PikaObj* classObj = obj_newObjFromConstructor(obj, "", classPtr);
return classObj;
}
@ -478,8 +559,7 @@ PikaObj* removeMethodInfo(PikaObj* thisClass) {
}
PikaObj* newNormalObj(NewFun newObjFun) {
PikaObj* thisClass = obj_getClassObjByNewFun(NULL, "", newObjFun);
obj_refcntInc(thisClass);
PikaObj* thisClass = obj_newObjFromConstructor(NULL, "", newObjFun);
obj_setFlag(thisClass, OBJ_FLAG_ALREADY_INIT);
return removeMethodInfo(thisClass);
}
@ -517,7 +597,7 @@ static volatile uint8_t logo_printed = 0;
extern volatile PikaObj* __pikaMain;
PikaObj* newRootObj(char* name, NewFun newObjFun) {
in_root_obj = PIKA_TRUE;
g_PikaObjState.inRootObj = PIKA_TRUE;
#if PIKA_POOL_ENABLE
mem_pool_init();
#endif
@ -532,8 +612,14 @@ PikaObj* newRootObj(char* name, NewFun newObjFun) {
pika_platform_printf("~ pikascript.com ~\r\n");
pika_platform_printf("~~~~~~~~~~~~~~~~~~~~\r\n");
}
if (NULL != __pikaMain) {
pika_platform_printf("Error: root object already exists\r\n");
pika_platform_panic_handle();
return NULL;
}
__pikaMain = newObj;
in_root_obj = PIKA_FALSE;
obj_setName(newObj, name);
g_PikaObjState.inRootObj = PIKA_FALSE;
return newObj;
}
@ -554,23 +640,24 @@ Arg* obj_newObjInPackage(NewFun new_obj_fun) {
return arg_newDirectObj(new_obj_fun);
}
static PikaObj* __obj_initSubObj(PikaObj* obj, char* name) {
static PikaObj* _obj_initMetaObj(PikaObj* obj, char* name) {
PikaObj* res = NULL;
NewFun constructor = (NewFun)getNewClassObjFunByName(obj, name);
Args buffs = {0};
PikaObj* thisClass;
PikaObj* new_obj;
PikaObj* oNew;
if (NULL == constructor) {
/* no such object */
res = NULL;
goto exit;
}
thisClass = obj_getClassObjByNewFun(obj, name, constructor);
new_obj = removeMethodInfo(thisClass);
obj_refcntInc(new_obj);
obj_runNativeMethod(new_obj, "__init__", NULL);
args_setPtrWithType(obj->list, name, ARG_TYPE_OBJECT, new_obj);
thisClass = obj_newObjFromConstructor(obj, name, constructor);
oNew = removeMethodInfo(thisClass);
obj_setName(oNew, name);
obj_runNativeMethod(oNew, "__init__", NULL);
args_setPtrWithType(obj->list, name, ARG_TYPE_OBJECT, oNew);
res = obj_getPtr(obj, name);
// pikaGC_enable(res);
goto exit;
exit:
strsDeinit(&buffs);
@ -607,9 +694,9 @@ PikaObj* _arg_to_obj(Arg* self, PIKA_BOOL* pIsTemp) {
return NULL;
}
static PikaObj* __obj_getObjDirect(PikaObj* self,
char* name,
PIKA_BOOL* pIsTemp) {
static PikaObj* _obj_getObjDirect(PikaObj* self,
char* name,
PIKA_BOOL* pIsTemp) {
*pIsTemp = PIKA_FALSE;
if (NULL == self) {
return NULL;
@ -626,7 +713,7 @@ static PikaObj* __obj_getObjDirect(PikaObj* self,
type = arg_getType(arg_obj);
/* found meta Object */
if (type == ARG_TYPE_OBJECT_META) {
return __obj_initSubObj(self, name);
return _obj_initMetaObj(self, name);
}
/* found Objcet */
if (argType_isObject(type)) {
@ -651,10 +738,10 @@ static PikaObj* __obj_getObjDirect(PikaObj* self,
return _arg_to_obj(arg_obj, pIsTemp);
}
static PikaObj* __obj_getObjWithKeepDeepth(PikaObj* self,
char* objPath,
PIKA_BOOL* pIsTemp,
int32_t keepDeepth) {
static PikaObj* _obj_getObjWithKeepDeepth(PikaObj* self,
char* objPath,
PIKA_BOOL* pIsTemp,
int32_t keepDeepth) {
char objPath_buff[PIKA_PATH_BUFF_SIZE];
char* objPath_ptr = objPath_buff;
strcpy(objPath_buff, objPath);
@ -662,30 +749,33 @@ static PikaObj* __obj_getObjWithKeepDeepth(PikaObj* self,
PikaObj* obj = self;
for (int32_t i = 0; i < token_num - keepDeepth; i++) {
char* token = strPopFirstToken(&objPath_ptr, '.');
obj = __obj_getObjDirect(obj, token, pIsTemp);
obj = _obj_getObjDirect(obj, token, pIsTemp);
if (obj == NULL) {
goto exit;
}
}
goto exit;
exit:
if (NULL != obj) {
pika_assert(obj_checkAlive(obj));
}
return obj;
}
PikaObj* obj_getObj(PikaObj* self, char* objPath) {
PIKA_BOOL is_temp = PIKA_FALSE;
return __obj_getObjWithKeepDeepth(self, objPath, &is_temp, 0);
return _obj_getObjWithKeepDeepth(self, objPath, &is_temp, 0);
}
PikaObj* obj_getHostObj(PikaObj* self, char* objPath) {
PIKA_BOOL is_temp = PIKA_FALSE;
return __obj_getObjWithKeepDeepth(self, objPath, &is_temp, 1);
return _obj_getObjWithKeepDeepth(self, objPath, &is_temp, 1);
}
PikaObj* obj_getHostObjWithIsTemp(PikaObj* self,
char* objPath,
PIKA_BOOL* pIsTemp) {
return __obj_getObjWithKeepDeepth(self, objPath, pIsTemp, 1);
return _obj_getObjWithKeepDeepth(self, objPath, pIsTemp, 1);
}
Method methodArg_getPtr(Arg* method_arg) {
@ -1337,8 +1427,8 @@ enum shellCTRL _do_obj_runChar(PikaObj* self,
int16_t n = byte_count;
while (n--) {
PIKA_BOOL result = byteQueue_readOne(queue, (uint8_t*)&inputChar);
pika_assert(result != PIKA_FALSE);
result = byteQueue_readOne(queue, (uint8_t*)&inputChar);
pika_assert(PIKA_FALSE != result);
if (SHELL_CTRL_EXIT ==
_inner_do_obj_runChar(self, inputChar, shell)) {
@ -1654,13 +1744,345 @@ char* method_getStr(Args* args, char* argName) {
return args_getStr(args, argName);
}
#if PIKA_GC_MARK_SWEEP_ENABLE
PikaObj* pikaGC_getLast(PikaObj* self) {
PikaObj* obj = g_PikaObjState.gcChain;
PikaObj* last = NULL;
while (NULL != obj) {
if (obj == self) {
return last;
}
last = obj;
obj = obj->gcNext;
}
return NULL;
}
void pikaGC_clean(PikaGC* gc) {
PikaObj* obj = g_PikaObjState.gcChain;
while (NULL != obj) {
obj_clearFlag(obj, OBJ_FLAG_GC_MARKED);
// obj->gcRoot = NULL;
obj = obj->gcNext;
}
}
uint32_t pikaGC_count(void) {
uint32_t count = 0;
PikaObj* obj = g_PikaObjState.gcChain;
while (NULL != obj) {
count++;
obj = obj->gcNext;
}
return count;
}
uint32_t pikaGC_countMarked(void) {
uint32_t count = 0;
PikaObj* obj = g_PikaObjState.gcChain;
while (NULL != obj) {
if (obj_getFlag(obj, OBJ_FLAG_GC_MARKED)) {
count++;
}
obj = obj->gcNext;
}
return count;
}
uint32_t pikaGC_printFreeList(void) {
uint32_t count = 0;
PikaObj* obj = g_PikaObjState.gcChain;
pika_platform_printf("-----\r\n");
while (NULL != obj) {
if (!obj_getFlag(obj, OBJ_FLAG_GC_MARKED)) {
count++;
pika_platform_printf("gc free: ");
obj_dump(obj);
}
obj = obj->gcNext;
}
pika_platform_printf("-----\r\n");
return count;
}
void obj_dump(PikaObj* self) {
#if PIKA_KERNAL_DEBUG_ENABLE
pika_platform_printf("[\033[32m%s\033[0m]", self->name);
#endif
pika_platform_printf(" \033[36m@%p\033[0m", self);
pika_platform_printf("\r\n");
}
uint32_t pikaGC_markSweepOnce(PikaGC* gc) {
_pikaGC_mark(gc);
uint32_t count = 0;
PikaObj* freeList[16] = {0};
PikaObj* obj = g_PikaObjState.gcChain;
while (NULL != obj) {
if (!obj_getFlag(obj, OBJ_FLAG_GC_MARKED)) {
if (count > dimof(freeList) - 1) {
break;
}
freeList[count] = obj;
count++;
}
obj = obj->gcNext;
}
if (count > 0) {
// pikaGC_markDump();
// pikaGC_printFreeList();
for (uint32_t i = 0; i < count; i++) {
pika_platform_printf("GC Free:");
obj_dump(freeList[i]);
}
for (uint32_t i = 0; i < count; i++) {
obj_GC(freeList[i]);
}
}
return count;
}
int32_t _pikaGC_markHandler(Arg* argEach, void* context) {
PikaGC* gc = (PikaGC*)context;
if (arg_isObject(argEach)) {
PikaObj* obj = (PikaObj*)arg_getPtr(argEach);
#if PIKA_KERNAL_DEBUG_ENABLE
obj->gcRoot = (void*)gc->oThis;
#endif
pikaGC_markObj(gc, obj);
}
return 0;
}
void pikaGC_markObj(PikaGC* gc, PikaObj* self) {
gc->oThis = self;
gc->markDeepth++;
if (NULL == self) {
goto __exit;
}
if (obj_getFlag(self, OBJ_FLAG_GC_MARKED)) {
goto __exit;
}
obj_setFlag(self, OBJ_FLAG_GC_MARKED);
if (NULL != gc->onMarkObj) {
gc->onMarkObj(gc);
}
args_foreach(self->list, _pikaGC_markHandler, gc);
if (self->constructor == New_PikaStdData_Dict) {
PikaDict* dict = obj_getPtr(self, "dict");
if (NULL == dict) {
goto __exit;
}
args_foreach(&dict->super, _pikaGC_markHandler, (void*)gc);
goto __exit;
}
if (self->constructor == New_PikaStdData_List ||
self->constructor == New_PikaStdData_Tuple) {
PikaList* list = obj_getPtr(self, "list");
if (NULL == list) {
goto __exit;
}
args_foreach(&list->super, _pikaGC_markHandler, (void*)gc);
goto __exit;
}
__exit:
gc->markDeepth--;
return;
}
void _pikaGC_mark(PikaGC* gc) {
pikaGC_clean(gc);
PikaObj* root = g_PikaObjState.gcChain;
while (NULL != root) {
if (obj_getFlag(root, OBJ_FLAG_GC_ROOT)) {
pikaGC_markObj(gc, root);
}
root = root->gcNext;
}
}
void pikaGC_mark(void) {
PikaGC gc = {0};
_pikaGC_mark(&gc);
}
int _pikaGC_markDumpHandler(PikaGC* gc) {
for (uint32_t i = 0; i < gc->markDeepth - 1; i++) {
pika_platform_printf(" |");
}
if (gc->markDeepth != 1) {
pika_platform_printf("- ");
}
obj_dump(gc->oThis);
return 0;
}
#endif
PIKA_BOOL obj_checkAlive(PikaObj* self) {
#if !PIKA_GC_MARK_SWEEP_ENABLE
return PIKA_TRUE;
#else
PIKA_BOOL ret = PIKA_FALSE;
if (NULL == g_PikaObjState.gcChain) {
ret = PIKA_FALSE;
goto __exit;
}
PikaObj* obj = g_PikaObjState.gcChain;
while (NULL != obj) {
if (obj == self) {
ret = PIKA_TRUE;
goto __exit;
}
obj = obj->gcNext;
}
__exit:
#if PIKA_KERNAL_DEBUG_ENABLE
if (ret == PIKA_TRUE) {
self->isAlive = ret;
}
#endif
return ret;
#endif
}
uint32_t pikaGC_markSweep(void) {
#if !PIKA_GC_MARK_SWEEP_ENABLE
return 0;
#else
PikaGC gc = {0};
uint32_t count = 0;
if (pikaGC_islock()) {
return 0;
}
pikaGC_lock();
while (pikaGC_markSweepOnce(&gc) != 0) {
count++;
};
if (count > 0) {
// pikaGC_markDump();
}
/* update gc state */
g_PikaObjState.objCntLastGC = g_PikaObjState.objCnt;
pikaGC_unlock();
return count;
#endif
}
void pikaGC_markDump(void) {
#if !PIKA_GC_MARK_SWEEP_ENABLE
return;
#else
PikaGC gc = {0};
pika_platform_printf(
"\033[31m"
"========= PIKA GC DUMP =========\r\n"
"\033[0m");
gc.onMarkObj = _pikaGC_markDumpHandler;
_pikaGC_mark(&gc);
#endif
}
void pikaGC_checkThreshold(void) {
#if !PIKA_GC_MARK_SWEEP_ENABLE
return;
#else
if (g_PikaObjState.objCnt >
g_PikaObjState.objCntLastGC + PIKA_GC_MARK_SWEEP_THRESHOLD) {
pikaGC_markSweep();
}
#endif
}
void pikaGC_append(PikaObj* self) {
#if !PIKA_GC_MARK_SWEEP_ENABLE
return;
#else
g_PikaObjState.objCnt++;
if (g_PikaObjState.objCntMax < g_PikaObjState.objCnt) {
g_PikaObjState.objCntMax = g_PikaObjState.objCnt;
}
/* gc single chain */
if (NULL == g_PikaObjState.gcChain) {
g_PikaObjState.gcChain = self;
return;
}
/* append to head of gc chain */
self->gcNext = g_PikaObjState.gcChain;
g_PikaObjState.gcChain = self;
#endif
}
void obj_removeGcChain(PikaObj* self) {
#if !PIKA_GC_MARK_SWEEP_ENABLE
return;
#else
g_PikaObjState.objCnt--;
PikaObj* last = pikaGC_getLast(self);
if (NULL == last) {
/* remove head */
g_PikaObjState.gcChain = self->gcNext;
return;
}
last->gcNext = self->gcNext;
#endif
}
void obj_enableGC(PikaObj* self) {
#if !PIKA_GC_MARK_SWEEP_ENABLE
return;
#else
obj_clearFlag(self, OBJ_FLAG_GC_ROOT);
#endif
}
void pikaGC_lock(void) {
#if !PIKA_GC_MARK_SWEEP_ENABLE
return;
#else
g_PikaObjState.markSweepBusy++;
#endif
}
void pikaGC_unlock(void) {
#if !PIKA_GC_MARK_SWEEP_ENABLE
return;
#else
g_PikaObjState.markSweepBusy--;
#endif
}
PIKA_BOOL pikaGC_islock(void) {
#if !PIKA_GC_MARK_SWEEP_ENABLE
return PIKA_FALSE;
#else
return g_PikaObjState.markSweepBusy > 0;
#endif
}
PikaObj* New_PikaObj(void) {
PikaObj* self = pikaMalloc(sizeof(PikaObj));
/* List */
self->list = New_args(NULL);
self->refcnt = 0;
self->constructor = NULL;
self->constructor = New_PikaObj;
self->flag = 0;
#if PIKA_GC_MARK_SWEEP_ENABLE
self->gcNext = NULL;
obj_setFlag(self, OBJ_FLAG_GC_ROOT);
#endif
#if PIKA_KERNAL_DEBUG_ENABLE
self->aName = NULL;
self->name = "PikaObj";
self->parent = NULL;
self->isAlive = PIKA_TRUE;
#endif
#if PIKA_GC_MARK_SWEEP_ENABLE && PIKA_KERNAL_DEBUG_ENABLE
self->gcRoot = NULL;
#endif
/* append to gc chain */
pikaGC_append(self);
pikaGC_checkThreshold();
return self;
}
@ -1675,29 +2097,31 @@ Arg* arg_setRef(Arg* self, char* name, PikaObj* obj) {
}
int32_t obj_newDirectObj(PikaObj* self, char* objName, NewFun newFunPtr) {
Arg* new_obj = arg_newDirectObj(newFunPtr);
new_obj = arg_setName(new_obj, objName);
arg_setType(new_obj, ARG_TYPE_OBJECT);
args_setArg(self->list, new_obj);
Arg* aNewObj = arg_newDirectObj(newFunPtr);
aNewObj = arg_setName(aNewObj, objName);
obj_setName(arg_getPtr(aNewObj), objName);
arg_setType(aNewObj, ARG_TYPE_OBJECT);
// pikaGC_enable(arg_getPtr(aNewObj));
args_setArg(self->list, aNewObj);
return 0;
}
int32_t obj_newMetaObj(PikaObj* self, char* objName, NewFun newFunPtr) {
/* add meta Obj, no inited */
Arg* new_obj = arg_newMetaObj(newFunPtr);
new_obj = arg_setName(new_obj, objName);
args_setArg(self->list, new_obj);
Arg* aMetaObj = arg_newMetaObj(newFunPtr);
aMetaObj = arg_setName(aMetaObj, objName);
args_setArg(self->list, aMetaObj);
return 0;
}
static void _append_help(char* name) {
if (NULL == _help_modules_cmodule) {
_help_modules_cmodule = (volatile Arg*)arg_newStr("");
if (NULL == g_PikaObjState.helpModulesCmodule) {
g_PikaObjState.helpModulesCmodule = arg_newStr("");
}
Arg* _help = (Arg*)_help_modules_cmodule;
Arg* _help = g_PikaObjState.helpModulesCmodule;
_help = arg_strAppend(_help, name);
_help = arg_strAppend(_help, "\r\n");
_help_modules_cmodule = (volatile Arg*)_help;
g_PikaObjState.helpModulesCmodule = _help;
}
int32_t obj_newObj(PikaObj* self,
@ -1705,7 +2129,7 @@ int32_t obj_newObj(PikaObj* self,
char* className,
NewFun newFunPtr) {
/* before init root object */
if (in_root_obj) {
if (g_PikaObjState.inRootObj) {
_append_help(objName);
}
return obj_newMetaObj(self, objName, newFunPtr);
@ -1759,12 +2183,12 @@ PikaObj* obj_linkLibrary(PikaObj* self, uint8_t* library_bytes) {
void obj_printModules(PikaObj* self) {
LibObj* lib = obj_getObj(self, "@lib");
pika_platform_printf(arg_getStr((Arg*)_help_modules_cmodule));
pika_platform_printf(arg_getStr((Arg*)g_PikaObjState.helpModulesCmodule));
LibObj_printModules(lib);
}
PikaObj* obj_linkLibObj(PikaObj* self, LibObj* library) {
obj_setPtr(self, "@lib", library);
obj_setRef(self, "@lib", library);
return self;
}
@ -1804,26 +2228,25 @@ int obj_importModule(PikaObj* self, char* module_name) {
}
char* obj_toStr(PikaObj* self) {
/* clang-format off */
PIKA_PYTHON(
__res = __str__()
)
/* clang-format on */
/* check method arg */
Arg* method_arg = obj_getMethodArg(self, "__str__");
if (NULL != method_arg) {
arg_deinit(method_arg);
Arg* aMethod = obj_getMethodArg(self, "__str__");
if (NULL != aMethod) {
arg_deinit(aMethod);
/* clang-format off */
PIKA_PYTHON(
@res_str = __str__()
)
/* clang-format on */
const uint8_t bytes[] = {
0x08, 0x00, 0x00, 0x00, /* instruct array size */
0x00, 0x82, 0x01, 0x00, 0x00, 0x04, 0x09, 0x00, /* instruct
array */
0x0f, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x5f, 0x5f, 0x73, 0x74, 0x72, 0x5f, 0x5f, 0x00,
0x5f, 0x5f, 0x72, 0x65, 0x73, 0x00, /* const pool */
0x00, 0x82, 0x01, 0x00, 0x00, 0x04, 0x09, 0x00, /* instruct array */
0x12, 0x00, 0x00, 0x00, /* const pool size */
0x00, 0x5f, 0x5f, 0x73, 0x74, 0x72, 0x5f, 0x5f, 0x00, 0x40,
0x72, 0x65, 0x73, 0x5f, 0x73, 0x74, 0x72, 0x00, /* const pool */
};
pikaVM_runByteCode(self, (uint8_t*)bytes);
char* str_res = obj_getStr(self, "__res");
char* str_res = obj_cacheStr(self, obj_getStr(self, "@res_str"));
obj_removeArg(self, "@res_str");
return str_res;
}
@ -1831,9 +2254,9 @@ char* obj_toStr(PikaObj* self) {
Args buffs = {0};
char* str_res =
strsFormat(&buffs, PIKA_SPRINTF_BUFF_SIZE, "<object at %p>", self);
obj_setStr(self, "__res", str_res);
obj_setStr(self, "@res_str", str_res);
strsDeinit(&buffs);
return obj_getStr(self, "__res");
return obj_getStr(self, "@res_str");
}
void pks_eventListener_registEvent(PikaEventListener* self,
@ -1848,8 +2271,8 @@ void pks_eventListener_registEvent(PikaEventListener* self,
strsDeinit(&buffs);
}
Args buffs = {0};
void pks_eventListener_removeEvent(PikaEventListener* self, uint32_t eventId) {
Args buffs = {0};
char* event_name =
strsFormat(&buffs, PIKA_SPRINTF_BUFF_SIZE, "%ld", eventId);
obj_removeArg(self, event_name);
@ -1944,7 +2367,8 @@ void _do_pks_eventListener_send(PikaEventListener* self,
_VMEvent_pickupEvent();
}
}
if (PikaVMSignal.event_thread_inited) {
#if PIKA_EVENT_THREAD_ENABLE
if (g_PikaVMSignal.event_thread_inited) {
return;
}
/* using multi thread */
@ -1953,9 +2377,10 @@ void _do_pks_eventListener_send(PikaEventListener* self,
PIKA_THREAD_STACK_SIZE, PIKA_THREAD_PRIO,
PIKA_THREAD_TICK);
pika_debug("event thread init");
PikaVMSignal.event_thread_inited = 1;
g_PikaVMSignal.event_thread_inited = 1;
}
#endif
#endif
}
void pks_eventListener_send(PikaEventListener* self,
@ -1981,11 +2406,11 @@ Arg* pks_eventListener_sendSignalAwaitResult(PikaEventListener* self,
while (1) {
};
#else
extern volatile VMSignal PikaVMSignal;
int tail = PikaVMSignal.cq.tail;
extern volatile VMSignal g_PikaVMSignal;
int tail = g_PikaVMSignal.cq.tail;
pks_eventListener_sendSignal(self, eventId, eventSignal);
while (1) {
Arg* res = PikaVMSignal.cq.res[tail];
Arg* res = g_PikaVMSignal.cq.res[tail];
pika_platform_thread_delay();
if (NULL != res) {
return res;
@ -2007,6 +2432,7 @@ void pks_getVersion(char* buff) {
}
void* obj_getStruct(PikaObj* self, char* name) {
pika_assert(self != NULL);
return args_getStruct(self->list, name);
}

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*
@ -32,8 +32,8 @@
#include "dataArgs.h"
#include "dataLink.h"
#include "dataMemory.h"
#include "dataStrs.h"
#include "dataQueue.h"
#include "dataStrs.h"
typedef struct InstructUnit InstructUnit;
struct InstructUnit {
@ -78,11 +78,32 @@ struct NativeProperty {
typedef struct PikaObj PikaObj;
struct PikaObj {
Args* list;
uint8_t refcnt;
void* constructor;
#if PIKA_GC_MARK_SWEEP_ENABLE
PikaObj* gcNext;
#endif
#if PIKA_KERNAL_DEBUG_ENABLE
char* name;
Arg* aName;
PikaObj* parent;
PIKA_BOOL isAlive;
PIKA_BOOL isGCRoot;
#endif
#if PIKA_GC_MARK_SWEEP_ENABLE && PIKA_KERNAL_DEBUG_ENABLE
PikaObj* gcRoot;
#endif
uint8_t refcnt;
uint8_t flag;
};
typedef struct PikaGC PikaGC;
typedef int (*pikaGC_hook)(PikaGC* gc);
struct PikaGC {
uint32_t markDeepth;
pikaGC_hook onMarkObj;
PikaObj* oThis;
};
typedef struct RangeData RangeData;
struct RangeData {
int64_t start;
@ -91,12 +112,27 @@ struct RangeData {
int64_t i;
};
#define OBJ_FLAG_PROXY_GETATTRIBUTE 0x01
#define OBJ_FLAG_PROXY_GETATTR 0x02
#define OBJ_FLAG_PROXY_SETATTR 0x04
#define OBJ_FLAG_ALREADY_INIT 0x08
#define OBJ_FLAG_RUN_AS 0x16
#define OBJ_FLAG_GLOBALS 0x32
typedef struct PikaObjState PikaObjState;
struct PikaObjState {
Arg* helpModulesCmodule;
PIKA_BOOL inRootObj;
#if PIKA_GC_MARK_SWEEP_ENABLE
PikaObj* gcChain;
uint32_t objCnt;
uint32_t objCntMax;
uint32_t objCntLastGC;
uint32_t markSweepBusy;
#endif
};
#define OBJ_FLAG_PROXY_GETATTRIBUTE 1 << 0
#define OBJ_FLAG_PROXY_GETATTR 1 << 1
#define OBJ_FLAG_PROXY_SETATTR 1 << 2
#define OBJ_FLAG_ALREADY_INIT 1 << 3
#define OBJ_FLAG_RUN_AS 1 << 4
#define OBJ_FLAG_GLOBALS 1 << 5
#define OBJ_FLAG_GC_MARKED 1 << 6
#define OBJ_FLAG_GC_ROOT 1 << 7
#define KEY_UP 0x41
#define KEY_DOWN 0x42
@ -104,15 +140,27 @@ struct RangeData {
#define KEY_LEFT 0x44
static inline uint8_t obj_getFlag(PikaObj* self, uint8_t flag) {
pika_assert(self);
return (self->flag & flag) == flag;
}
static inline void obj_setFlag(PikaObj* self, uint8_t flag) {
pika_assert(self);
self->flag |= flag;
#if PIKA_KERNAL_DEBUG_ENABLE
if (flag == OBJ_FLAG_GC_ROOT) {
self->isGCRoot = PIKA_TRUE;
}
#endif
}
static inline void obj_clearFlag(PikaObj* self, uint8_t flag) {
self->flag &= ~flag;
#if PIKA_KERNAL_DEBUG_ENABLE
if (flag == OBJ_FLAG_GC_ROOT) {
self->isGCRoot = PIKA_FALSE;
}
#endif
}
typedef PikaObj* (*NewFun)(Args* args);
@ -228,7 +276,9 @@ int32_t class_defineRunTimeConstructor(PikaObj* self,
int32_t obj_removeArg(PikaObj* self, char* argPath);
int32_t obj_isArgExist(PikaObj* self, char* argPath);
PikaObj* obj_getClassObjByNewFun(PikaObj* self, char* name, NewFun newClassFun);
PikaObj* obj_newObjFromConstructor(PikaObj* self,
char* name,
NewFun newClassFun);
PikaObj* newRootObj(char* name, NewFun newObjFun);
PikaObj* obj_getClassObj(PikaObj* obj);
Arg* obj_getMethodArg(PikaObj* obj, char* methodPath);
@ -268,6 +318,7 @@ Method methodArg_getPtr(Arg* method_arg);
VMParameters* obj_run(PikaObj* self, char* cmd);
PikaObj* New_PikaObj(void);
PikaObj* New_PikaObj_noGC(void);
/* tools */
int64_t fast_atoi(char* src);
@ -281,7 +332,6 @@ typedef struct ShellConfig ShellConfig;
typedef enum shellCTRL (*sh_handler)(PikaObj*, char*, ShellConfig*);
typedef char (*sh_getchar)(void);
#if PIKA_SHELL_FILTER_ENABLE
typedef struct FilterFIFO {
ByteQueue queue;
@ -291,19 +341,19 @@ typedef struct FilterFIFO {
typedef struct FilterItem FilterItem;
typedef PIKA_BOOL FilterMessageHandler( FilterItem *msg,
PikaObj* self,
ShellConfig* shell);
typedef PIKA_BOOL FilterMessageHandler(FilterItem* msg,
PikaObj* self,
ShellConfig* shell);
struct FilterItem {
FilterMessageHandler *handler;
const uint8_t *message;
uint16_t size;
uint8_t is_visible : 1;
uint8_t is_case_insensitive : 1;
uint8_t : 6;
uint8_t ignore_mask;
uintptr_t target;
FilterMessageHandler* handler;
const uint8_t* message;
uint16_t size;
uint8_t is_visible : 1;
uint8_t is_case_insensitive : 1;
uint8_t : 6;
uint8_t ignore_mask;
uintptr_t target;
};
#endif
@ -311,9 +361,9 @@ struct FilterItem {
struct ShellConfig {
#if PIKA_SHELL_FILTER_ENABLE
FilterFIFO filter_fifo;
FilterItem *messages;
FilterItem* messages;
uint16_t message_count;
uint16_t : 16; /* padding to suppress warning*/
uint16_t : 16; /* padding to suppress warning*/
#endif
char* prefix;
sh_handler handler;
@ -346,6 +396,20 @@ PikaObj* newNormalObj(NewFun newObjFun);
Arg* arg_setRef(Arg* self, char* name, PikaObj* obj);
Arg* arg_setObj(Arg* self, char* name, PikaObj* obj);
static inline void arg_setObjFlag(Arg* self, uint8_t flag) {
if (!arg_isObject(self)) {
return;
}
obj_setFlag((PikaObj*)arg_getPtr(self), flag);
}
static inline void arg_clearObjFlag(Arg* self, uint8_t flag) {
if (!arg_isObject(self)) {
return;
}
obj_clearFlag((PikaObj*)arg_getPtr(self), flag);
}
static inline Arg* arg_newObj(PikaObj* obj) {
return arg_setObj(NULL, (char*)"", (obj));
}
@ -566,6 +630,36 @@ void obj_printModules(PikaObj* self);
} while (0)
#endif
#define pika_assert_arg_alive(__arg) \
do { \
if (NULL != (__arg)) { \
if (arg_isObject((__arg))) { \
pika_assert(obj_checkAlive(arg_getPtr((__arg)))); \
} \
} \
} while (0)
#define pika_assert_obj_alive(__obj) \
do { \
pika_assert(obj_checkAlive((__obj))); \
} while (0)
void obj_appendGcChain(PikaObj* self);
void obj_removeGcChain(PikaObj* self);
void obj_enableGC(PikaObj* self);
PIKA_BOOL obj_checkAlive(PikaObj* self);
void obj_setName(PikaObj* self, char* name);
void pikaGC_mark(void);
void pikaGC_markDump(void);
void pikaGC_lock(void);
void pikaGC_unlock(void);
PIKA_BOOL pikaGC_islock(void);
uint32_t pikaGC_count(void);
uint32_t pikaGC_countMarked(void);
uint32_t pikaGC_markSweep(void);
uint32_t pikaGC_printFreeList(void);
int pika_GIL_EXIT(void);
int pika_GIL_ENTER(void);

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*
@ -1812,7 +1812,7 @@ static int32_t Parser_getPyLineBlockDeepth(char* line) {
return -1;
}
char* Parser_removeAnnotation(char* line) {
char* Parser_removeComment(char* line) {
uint8_t is_annotation_exit = 0;
uint8_t is_in_single_quotes = 0;
uint8_t is_in_pika_float_quotes_deepth = 0;
@ -2015,7 +2015,7 @@ AST* AST_parseLine_withBlockStack_withBlockDeepth(char* line,
char* arg_in = strsPopToken(list_buffs, &line_buff, ' ');
AST_setNodeAttr(ast, "arg_in", arg_in);
strsPopToken(list_buffs, &line_buff, ' ');
char* list_in = strsPopToken(list_buffs, &line_buff, ':');
char* list_in = Cursor_splitCollect(list_buffs, line_buff, ":", 0);
list_in = strsAppend(list_buffs, "iter(", list_in);
list_in = strsAppend(list_buffs, list_in, ")");
list_in = strsCopy(&buffs, list_in);
@ -2419,7 +2419,7 @@ static char* Suger_import(Args* outbuffs, char* line) {
}
static char* Parser_linePreProcess(Args* outbuffs, char* line) {
line = Parser_removeAnnotation(line);
line = Parser_removeComment(line);
Arg* line_buff = NULL;
int line_num = 0;
/* check syntex error */
@ -2497,172 +2497,181 @@ static int Parser_isVoidLine(char* line) {
return 1;
}
static uint8_t Parser_checkIsMultiComment(char* line) {
for (uint32_t i = 0; i < strGetSize(line); i++) {
static uint8_t Parser_checkIsMultiComment(char* line, uint8_t* pbIsOneLine) {
uint8_t bIsMultiComment = 0;
uint32_t i = 0;
uint32_t uLineSize = strGetSize(line);
while (i + 2 < uLineSize) {
/* not match ' or " */
if ((line[i] != '\'') && (line[i] != '"')) {
i++;
continue;
}
/* not match ''' or """ */
if (!((line[i + 1] == line[i]) && (line[i + 2] == line[i]))) {
i++;
continue;
}
// /* check char befor the ''' or """ */
// if (!((0 == i) || (line[i - 1] == ' '))) {
// continue;
// }
// /* check char after the ''' or """ */
// if (!((line[i + 3] == ' ') || (line[i + 3] == 0))) {
// continue;
// }
/* mached */
return 1;
if (bIsMultiComment) {
*pbIsOneLine = 1;
}
bIsMultiComment = 1;
i += 3;
}
/* not mached */
return 0;
return bIsMultiComment;
}
static char* _Parser_linesToBytesOrAsm(Args* outBuffs,
ByteCodeFrame* bytecode_frame,
char* py_lines) {
Stack block_stack;
stack_init(&block_stack);
Arg* asm_buff = arg_newStr("");
uint32_t lines_offset = 0;
uint16_t lines_num = strCountSign(py_lines, '\n') + 1;
uint16_t lines_index = 0;
uint8_t is_in_multi_comment = 0;
Arg* line_connection_arg = arg_newStr("");
uint8_t is_line_connection = 0;
char* out_ASM = NULL;
char* single_ASM = NULL;
uint32_t line_size = 0;
char* sPyLines) {
Stack tBlockStack;
stack_init(&tBlockStack);
Arg* aAsm = arg_newStr("");
uint32_t uLinesOffset = 0;
uint16_t uLinesNum = strCountSign(sPyLines, '\n') + 1;
uint16_t uLinesIndex = 0;
uint8_t bIsInMultiComment = 0;
uint8_t bIsOneLineMultiComment = 0;
Arg* aLineConnection = arg_newStr("");
uint8_t bIsLineConnection = 0;
char* sOutASM = NULL;
char* sSingleASM = NULL;
uint32_t uLineSize = 0;
/* parse each line */
while (1) {
lines_index++;
uLinesIndex++;
Args buffs = {0};
char* line_origin = NULL;
char* line = NULL;
char* sLineOrigin = NULL;
char* sLine = NULL;
/* add void line to the end */
if (lines_index >= lines_num + 1) {
line = "";
if (uLinesIndex >= uLinesNum + 1) {
sLine = "";
goto parse_line;
}
/* get single line by pop multiline */
line_origin = strsGetFirstToken(&buffs, py_lines + lines_offset, '\n');
sLineOrigin = strsGetFirstToken(&buffs, sPyLines + uLinesOffset, '\n');
sLine = strsCopy(&buffs, sLineOrigin);
line = strsCopy(&buffs, line_origin);
/* line connection */
if (is_line_connection) {
is_line_connection = 0;
line_connection_arg = arg_strAppend(line_connection_arg, line);
line = strsCopy(&buffs, arg_getStr(line_connection_arg));
if (bIsLineConnection) {
bIsLineConnection = 0;
aLineConnection = arg_strAppend(aLineConnection, sLine);
sLine = strsCopy(&buffs, arg_getStr(aLineConnection));
/* reflash the line_connection_arg */
arg_deinit(line_connection_arg);
line_connection_arg = arg_newStr("");
arg_deinit(aLineConnection);
aLineConnection = arg_newStr("");
}
/* check connection */
if ('\\' == line[strGetSize(line) - 1]) {
if ('\\' == sLine[strGetSize(sLine) - 1]) {
/* remove the '\\' */
line[strGetSize(line) - 1] = '\0';
is_line_connection = 1;
line_connection_arg = arg_strAppend(line_connection_arg, line);
sLine[strGetSize(sLine) - 1] = '\0';
bIsLineConnection = 1;
aLineConnection = arg_strAppend(aLineConnection, sLine);
goto next_line;
}
Cursor_forEach(c, line) {
/* filter for not end \n */
if (Parser_isVoidLine(sLine)) {
goto next_line;
}
/* filter for multiline comment ''' or """ */
if (Parser_checkIsMultiComment(sLine, &bIsOneLineMultiComment)) {
bIsInMultiComment = ~bIsInMultiComment;
/* skip one line multiline comment */
if (bIsOneLineMultiComment) {
bIsInMultiComment = 0;
bIsOneLineMultiComment = 0;
}
goto next_line;
}
/* skip multiline comment */
if (bIsInMultiComment) {
goto next_line;
}
/* support Tab */
sLine = strsReplace(&buffs, sLine, "\t", " ");
/* remove \r */
sLine = strsReplace(&buffs, sLine, "\r", "");
/* check auto connection */
Cursor_forEach(c, sLine) {
Cursor_iterStart(&c);
Cursor_iterEnd(&c);
}
Cursor_deinit(&c);
/* auto connection */
if (lines_index < lines_num) {
if (uLinesIndex < uLinesNum) {
if (c.branket_deepth > 0) {
line_connection_arg = arg_strAppend(line_connection_arg, line);
is_line_connection = 1;
aLineConnection = arg_strAppend(aLineConnection, sLine);
bIsLineConnection = 1;
goto next_line;
}
}
/* branket match failed */
if (c.branket_deepth != 0) {
single_ASM = NULL;
sSingleASM = NULL;
goto parse_after;
}
/* support Tab */
line = strsReplace(&buffs, line, "\t", " ");
/* remove \r */
line = strsReplace(&buffs, line, "\r", "");
/* filter for not end \n */
if (Parser_isVoidLine(line)) {
goto next_line;
}
/* filter for multiline comment ''' or """ */
if (Parser_checkIsMultiComment(line)) {
is_in_multi_comment = ~is_in_multi_comment;
goto next_line;
}
/* skipe multiline comment */
if (is_in_multi_comment) {
goto next_line;
}
parse_line:
/* parse single Line to Asm */
single_ASM = Parser_LineToAsm(&buffs, line, &block_stack);
sSingleASM = Parser_LineToAsm(&buffs, sLine, &tBlockStack);
parse_after:
if (NULL == single_ASM) {
out_ASM = NULL;
if (NULL == sSingleASM) {
sOutASM = NULL;
pika_platform_printf(
"----------[%d]----------\r\n%s\r\n-------------------------"
"\r\n",
lines_index, line);
uLinesIndex, sLine);
strsDeinit(&buffs);
goto exit;
}
if (NULL == bytecode_frame) {
/* store ASM */
asm_buff = arg_strAppend(asm_buff, single_ASM);
aAsm = arg_strAppend(aAsm, sSingleASM);
} else if (NULL == outBuffs) {
/* store ByteCode */
byteCodeFrame_appendFromAsm(bytecode_frame, single_ASM);
byteCodeFrame_appendFromAsm(bytecode_frame, sSingleASM);
}
next_line:
if (lines_index < lines_num) {
line_size = strGetSize(line_origin);
lines_offset = lines_offset + line_size + 1;
if (uLinesIndex < uLinesNum) {
uLineSize = strGetSize(sLineOrigin);
uLinesOffset = uLinesOffset + uLineSize + 1;
}
strsDeinit(&buffs);
/* exit when finished */
if (lines_index >= lines_num + 1) {
if (uLinesIndex >= uLinesNum + 1) {
break;
}
}
if (NULL != outBuffs) {
/* load stored ASM */
out_ASM = strsCopy(outBuffs, arg_getStr(asm_buff));
sOutASM = strsCopy(outBuffs, arg_getStr(aAsm));
} else {
out_ASM = (char*)1;
sOutASM = (char*)1;
}
goto exit;
exit:
if (NULL != asm_buff) {
arg_deinit(asm_buff);
if (NULL != aAsm) {
arg_deinit(aAsm);
}
if (NULL != line_connection_arg) {
arg_deinit(line_connection_arg);
if (NULL != aLineConnection) {
arg_deinit(aLineConnection);
}
stack_deinit(&block_stack);
return out_ASM;
stack_deinit(&tBlockStack);
return sOutASM;
};
PIKA_RES Parser_linesToBytes(ByteCodeFrame* bf, char* py_lines) {
@ -2699,8 +2708,12 @@ char* Parser_fileToAsm(Args* outBuffs, char* filename) {
/* add '\n' at the end */
lines = strsAppend(&buffs, lines, "\n\n");
char* res = Parser_linesToAsm(&buffs, lines);
arg_deinit(file_arg);
if (NULL == res) {
goto __exit;
}
res = strsCopy(outBuffs, res);
__exit:
arg_deinit(file_arg);
strsDeinit(&buffs);
return res;
}

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*
@ -48,7 +48,7 @@
abort(); \
}
#else
#define pika_assert(...)
#define pika_assert(...) (void)0;
#endif
/* clang-format on */

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* http://github.com/pikastech/pikapython
*
* MIT License
*
@ -35,10 +35,12 @@
#include <setjmp.h>
#endif
enum Instruct {
enum InstructIndex {
#define __INS_ENUM
#include "__instruction_table.h"
__INSTRCUTION_CNT,
__INSTRUCTION_CNT,
__INSTRUCTION_INDEX_MAX = 0xFFFF,
__INSTRUCTION_UNKNOWN = 0xFFFF,
};
typedef enum {
@ -81,9 +83,8 @@ struct VMState {
uint32_t ins_cnt;
PIKA_BOOL in_super;
uint8_t super_invoke_deepth;
PikaObj* lreg[PIKA_REGIST_SIZE];
PIKA_BOOL ireg[PIKA_REGIST_SIZE];
RunState* run_state;
PIKA_BOOL ireg[PIKA_REGIST_SIZE];
};
typedef struct {
@ -154,6 +155,29 @@ struct VMSignal {
#endif
};
typedef Arg* (*VM_instruct_handler)(PikaObj* self,
VMState* vm,
char* data,
Arg* arg_ret_reg);
typedef struct VMInstruction VMInstruction;
struct VMInstruction {
VM_instruct_handler handler;
const char* op_str;
uint16_t op_idx;
uint16_t op_str_len : 4;
uint16_t : 12;
};
typedef struct VMInstructionSet VMInstructionSet;
struct VMInstructionSet {
const VMInstruction* instructions;
uint16_t count;
uint16_t signature;
uint16_t op_idx_start;
uint16_t op_idx_end;
};
VMParameters* pikaVM_run(PikaObj* self, char* pyLine);
VMParameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm);
VMParameters* pikaVM_runByteCodeFrame(PikaObj* self,
@ -167,8 +191,9 @@ static inline int instructUnit_getInvokeDeepth(InstructUnit* self) {
return self->deepth >> 4;
}
static inline enum Instruct instructUnit_getInstruct(InstructUnit* self) {
return (enum Instruct)(self->isNewLine_instruct & 0x7F);
static inline enum InstructIndex instructUnit_getInstructIndex(
InstructUnit* self) {
return (enum InstructIndex)(self->isNewLine_instruct & 0x7F);
}
static inline int instructUnit_getConstPoolIndex(InstructUnit* self) {
@ -202,7 +227,7 @@ static inline void instructUnit_setIsNewLine(InstructUnit* self, int val) {
InstructUnit* New_instructUnit(uint8_t data_size);
void instructUnit_deinit(InstructUnit* self);
enum Instruct pikaVM_getInstructFromAsm(char* line);
enum InstructIndex pikaVM_getInstructFromAsm(char* line);
void constPool_init(ConstPool* self);
void constPool_deinit(ConstPool* self);
@ -286,8 +311,19 @@ void instructArray_printAsArray(InstructArray* self);
void byteCodeFrame_loadByteCode(ByteCodeFrame* self, uint8_t* bytes);
void byteCodeFrame_printAsArray(ByteCodeFrame* self);
void byteCodeFrame_init(ByteCodeFrame* self);
PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet* ins_set);
VMParameters* pikaVM_runByteCode(PikaObj* self, const uint8_t* bytecode);
VMParameters* pikaVM_runByteCodeInconstant(PikaObj* self, uint8_t* bytecode);
Arg* pikaVM_runByteCodeReturn(PikaObj* self,
const uint8_t* bytecode,
char* returnName);
Arg* _do_pikaVM_runByteCodeReturn(PikaObj* self,
VMParameters* locals,
VMParameters* globals,
uint8_t* bytecode,
RunState* run_state,
PIKA_BOOL is_const_bytecode,
char* return_name);
InstructUnit* instructArray_getNow(InstructArray* self);
InstructUnit* instructArray_getNext(InstructArray* self);
VMParameters* pikaVM_runSingleFile(PikaObj* self, char* filename);
@ -309,7 +345,7 @@ VMParameters* _do_pikaVM_runByteCode(PikaObj* self,
void _do_byteCodeFrame_loadByteCode(ByteCodeFrame* self,
uint8_t* bytes,
PIKA_BOOL is_const);
Arg* __vm_get(VMState* vm, PikaObj* self, Arg* key, Arg* obj);
Arg* _vm_get(VMState* vm, PikaObj* self, Arg* key, Arg* obj);
void __vm_List_append(PikaObj* self, Arg* arg);
void __vm_List___init__(PikaObj* self);
void __vm_Dict_set(PikaObj* self, Arg* arg, char* key);
@ -329,4 +365,9 @@ void _VMEvent_pickupEvent(void);
void _pikaVM_yield(void);
int _VM_lock_init(void);
int _VM_is_first_lock(void);
typedef struct {
PikaObj* lreg[PIKA_REGIST_SIZE];
} VMLocals;
#endif

View File

@ -2,4 +2,4 @@
#define PIKA_VERSION_MINOR 12
#define PIKA_VERSION_MICRO 0
#define PIKA_EDIT_TIME "2023/02/18 20:34:52"
#define PIKA_EDIT_TIME "2023/03/08 09:54:07"

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*
@ -26,6 +26,7 @@
*/
#include "PikaObj.h"
#include "PikaVM.h"
const NativeProperty TinyObjNativeProp = {.super = NULL,
.methodGroup = NULL,
@ -33,5 +34,9 @@ const NativeProperty TinyObjNativeProp = {.super = NULL,
PikaObj* New_TinyObj(Args* args) {
PikaObj* self = New_PikaObj();
self->constructor = New_TinyObj;
#if PIKA_KERNAL_DEBUG_ENABLE
self->name = "TinyObj";
#endif
return self;
}

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*
@ -35,20 +35,31 @@
#define def_ins(__INS_NAME) [__INS_NAME] = &VM_instruction_handler_##__INS_NAME,
#endif
#if defined(__INS_COMPIRE)
#define def_ins(__INS_NAME) \
if (0 == strncmp(ins_str, "" #__INS_NAME "", 3)) { \
return __INS_NAME; \
#if defined(__INS_COMPARE)
#define def_ins(__INS_NAME) \
if (0 == strncmp(ins_str, "" #__INS_NAME "", 3)) { \
return __INS_NAME; \
}
#endif
#if defined(__INS_GET_INS_STR)
#define def_ins(__INS_NAME) \
if (__INS_NAME == instructUnit_getInstruct(self)){ \
#define def_ins(__INS_NAME) \
if (__INS_NAME == instructUnit_getInstructIndex(self)){ \
return ""#__INS_NAME""; \
}
#endif
#if defined(__INS_OPCODE)
#define def_ins(__INS_NAME) \
[__INS_NAME] = { \
.handler = &VM_instruction_handler_##__INS_NAME, \
.op_str = (const char []){#__INS_NAME}, \
.op_str_len = sizeof(#__INS_NAME) - 1, \
.op_idx = __INS_NAME, \
},
#endif
#undef __INS_ENUM
#undef __INS_TABLE
#undef __INS_COMPIRE
#undef __INS_COMPARE
#undef __INS_OPCODE

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*
@ -39,16 +39,16 @@ static PIKA_BOOL _arg_cache_push(Arg* self, uint32_t size) {
if (PIKA_FALSE == pika_hook_arg_cache_filter(self)) {
return PIKA_FALSE;
}
extern PikaMemInfo pikaMemInfo;
extern PikaMemInfo g_PikaMemInfo;
if (self->heap_size < PIKA_ARG_CACHE_SIZE ||
self->heap_size > 2 * PIKA_ARG_CACHE_SIZE) {
return PIKA_FALSE;
}
if (PIKA_ARG_CACHE_POOL_SIZE <= pikaMemInfo.cache_pool_top) {
if (PIKA_ARG_CACHE_POOL_SIZE <= g_PikaMemInfo.cache_pool_top) {
return PIKA_FALSE;
}
pikaMemInfo.cache_pool[pikaMemInfo.cache_pool_top++] = (uint8_t*)self;
pikaMemInfo.heapUsed -= mem_align(sizeof(Arg) + size);
g_PikaMemInfo.cache_pool[g_PikaMemInfo.cache_pool_top++] = (uint8_t*)self;
g_PikaMemInfo.heapUsed -= mem_align(sizeof(Arg) + size);
return PIKA_TRUE;
#endif
}
@ -58,16 +58,16 @@ static Arg* _arg_cache_pop(uint32_t size) {
return NULL;
#else
uint32_t req_heap_size = mem_align(sizeof(Arg) + size);
extern PikaMemInfo pikaMemInfo;
extern PikaMemInfo g_PikaMemInfo;
if (req_heap_size > PIKA_ARG_CACHE_SIZE) {
return NULL;
}
if (!(pikaMemInfo.cache_pool_top > 0)) {
if (!(g_PikaMemInfo.cache_pool_top > 0)) {
return NULL;
}
--pikaMemInfo.cache_pool_top;
Arg* self = (Arg*)pikaMemInfo.cache_pool[pikaMemInfo.cache_pool_top];
pikaMemInfo.heapUsed += mem_align(sizeof(Arg) + size);
--g_PikaMemInfo.cache_pool_top;
Arg* self = (Arg*)g_PikaMemInfo.cache_pool[g_PikaMemInfo.cache_pool_top];
g_PikaMemInfo.heapUsed += mem_align(sizeof(Arg) + size);
return self;
#endif
}
@ -118,15 +118,15 @@ static Arg* _arg_set_hash(Arg* self,
// if (heap_size < PIKA_ARG_CACHE_SIZE) {
// heap_size = PIKA_ARG_CACHE_SIZE;
// }
extern PikaMemInfo pikaMemInfo;
pikaMemInfo.alloc_times++;
pikaMemInfo.alloc_times_cache++;
extern PikaMemInfo g_PikaMemInfo;
g_PikaMemInfo.alloc_times++;
g_PikaMemInfo.alloc_times_cache++;
#endif
if (NULL == self) {
self = (Arg*)pikaMalloc(heap_size);
#if PIKA_ARG_CACHE_ENABLE
extern PikaMemInfo pikaMemInfo;
pikaMemInfo.alloc_times_cache--;
extern PikaMemInfo g_PikaMemInfo;
g_PikaMemInfo.alloc_times_cache--;
self->heap_size = mem_align(heap_size);
#endif
}
@ -550,9 +550,9 @@ Arg* arg_append(Arg* self, void* new_content, size_t new_size) {
if (self->heap_size > mem_align(sizeof(Arg) + old_size + new_size)) {
new_arg = self;
new_arg->size = old_size + new_size;
extern PikaMemInfo pikaMemInfo;
pikaMemInfo.heapUsed += mem_align(sizeof(Arg) + old_size + new_size) -
mem_align(sizeof(Arg) + old_size);
extern PikaMemInfo g_PikaMemInfo;
g_PikaMemInfo.heapUsed += mem_align(sizeof(Arg) + old_size + new_size) -
mem_align(sizeof(Arg) + old_size);
}
#endif
if (NULL == new_arg) {

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*
@ -103,7 +103,7 @@ static inline void arg_setType(Arg* self, ArgType type) {
}
static inline Hash arg_getNameHash(Arg* self) {
pika_assert(self != 0);
pika_assert(self != NULL);
return self->name_hash;
}

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*
@ -78,9 +78,10 @@ PIKA_RES args_setPtr(Args* self, char* name, void* argPointer) {
PIKA_RES args_setRef(Args* self, char* name, void* argPointer) {
PIKA_RES errCode = PIKA_RES_OK;
Arg* argNew = New_arg(NULL);
argNew = arg_setRef(argNew, name, argPointer);
args_setArg(self, argNew);
Arg* aNewRef = New_arg(NULL);
aNewRef = arg_setRef(aNewRef, name, argPointer);
// pikaGC_enable(arg_getPtr(aNewRef));
args_setArg(self, aNewRef);
return errCode;
}
@ -311,7 +312,7 @@ int32_t args_isArgExist(Args* self, char* name) {
return 0;
}
PIKA_RES __updateArg(Args* self, Arg* argNew) {
PIKA_RES _updateArg(Args* self, Arg* argNew) {
pika_assert(NULL != self);
pika_assert(NULL != argNew);
LinkNode* nodeToUpdate = NULL;
@ -361,7 +362,7 @@ exit:
PIKA_RES args_setArg(Args* self, Arg* arg) {
pika_assert(NULL != self);
pika_assert(NULL != arg);
if (PIKA_RES_OK == __updateArg(self, arg)) {
if (PIKA_RES_OK == _updateArg(self, arg)) {
return PIKA_RES_OK;
}
args_pushArg(self, arg);
@ -440,8 +441,8 @@ Arg* args_getArgByIndex(Args* self, int index) {
}
PIKA_RES args_foreach(Args* self,
int32_t (*eachHandle)(Arg* argEach, Args* context),
Args* context) {
int32_t (*eachHandle)(Arg* argEach, void* context),
void* context) {
if (NULL == self->firstNode) {
return PIKA_RES_OK;
}

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*
@ -107,8 +107,8 @@ PIKA_RES args_setPtrWithType(Args* self,
ArgType type,
void* objPtr);
PIKA_RES args_foreach(Args* self,
int32_t (*eachHandle)(Arg* argEach, Args* context),
Args* context);
int32_t (*eachHandle)(Arg* argEach, void* context),
void* context);
char* args_getBuff(Args* self, int32_t size);
PIKA_RES args_pushArg(Args* self, Arg* arg);

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*
@ -30,7 +30,7 @@
#include "dataLinkNode.h"
#include "dataMemory.h"
void __link_deinit_pyload(Link* self) {
void _link_deinit_pyload(Link* self) {
LinkNode* nowNode = self->firstNode;
while (NULL != nowNode) {
LinkNode* nodeNext = (LinkNode*)arg_getNext((Arg*)nowNode);
@ -42,12 +42,12 @@ void __link_deinit_pyload(Link* self) {
void link_deinit(Link* self) {
pika_assert(self != NULL);
__link_deinit_pyload(self);
_link_deinit_pyload(self);
pikaFree(self, sizeof(Link));
}
void link_deinit_stack(Link* self) {
__link_deinit_pyload(self);
_link_deinit_pyload(self);
}
void link_addNode(Link* self, void* content) {
@ -59,7 +59,7 @@ void link_addNode(Link* self, void* content) {
arg_setNext((Arg*)content, (Arg*)secondNode);
}
static void __link_removeNode(Link* self,
static void _link_removeNode(Link* self,
void* content,
uint8_t is_deinit_node) {
LinkNode* nodeToDelete = NULL;
@ -99,11 +99,11 @@ exit:
}
void link_removeNode(Link* self, void* content) {
__link_removeNode(self, content, 1);
_link_removeNode(self, content, 1);
}
void link_removeNode_notDeinitNode(Link* self, void* content) {
__link_removeNode(self, content, 0);
_link_removeNode(self, content, 0);
}
int32_t link_getSize(Link* self) {

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*
@ -29,7 +29,7 @@
#include "dataMemory.h"
#include "PikaPlatform.h"
volatile PikaMemInfo pikaMemInfo = {0};
volatile PikaMemInfo g_PikaMemInfo = {0};
void* pikaMalloc(uint32_t size) {
/* pika memory lock */
@ -43,15 +43,16 @@ void* pikaMalloc(uint32_t size) {
size = mem_align(size);
#endif
pikaMemInfo.heapUsed += size;
if (pikaMemInfo.heapUsedMax < pikaMemInfo.heapUsed) {
pikaMemInfo.heapUsedMax = pikaMemInfo.heapUsed;
g_PikaMemInfo.heapUsed += size;
if (g_PikaMemInfo.heapUsedMax < g_PikaMemInfo.heapUsed) {
g_PikaMemInfo.heapUsedMax = g_PikaMemInfo.heapUsed;
}
pika_platform_disable_irq_handle();
void* mem = pika_user_malloc(size);
pika_platform_enable_irq_handle();
if (NULL == mem) {
pika_platform_printf("Error: No heap space! Please reset the device.\r\n");
pika_platform_printf(
"Error: No heap space! Please reset the device.\r\n");
while (1) {
}
}
@ -72,20 +73,20 @@ void pikaFree(void* mem, uint32_t size) {
pika_platform_disable_irq_handle();
pika_user_free(mem, size);
pika_platform_enable_irq_handle();
pikaMemInfo.heapUsed -= size;
g_PikaMemInfo.heapUsed -= size;
}
uint32_t pikaMemNow(void) {
return pikaMemInfo.heapUsed;
return g_PikaMemInfo.heapUsed;
// return 0;
}
uint32_t pikaMemMax(void) {
return pikaMemInfo.heapUsedMax;
return g_PikaMemInfo.heapUsedMax;
}
void pikaMemMaxReset(void) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
}
uint32_t pool_getBlockIndex_byMemSize(Pool* pool, uint32_t size) {
@ -137,7 +138,7 @@ void pool_printBlocks(Pool* pool, uint32_t size_min, uint32_t size_max) {
break;
}
pika_platform_printf("0x%x\t: 0x%d", i * pool->aline,
(i + 15) * pool->aline);
(i + 15) * pool->aline);
for (uint32_t j = i; j < i + 16; j += 4) {
if (is_end) {
break;
@ -307,9 +308,10 @@ void mem_pool_init(void) {
void _mem_cache_deinit(void) {
#if PIKA_ARG_CACHE_ENABLE
while (pikaMemInfo.cache_pool_top) {
pika_user_free(pikaMemInfo.cache_pool[pikaMemInfo.cache_pool_top - 1], 0);
pikaMemInfo.cache_pool_top--;
while (g_PikaMemInfo.cache_pool_top) {
pika_user_free(
g_PikaMemInfo.cache_pool[g_PikaMemInfo.cache_pool_top - 1], 0);
g_PikaMemInfo.cache_pool_top--;
}
#endif
}

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*
@ -167,6 +167,9 @@ static int32_t _stack_pushArg(Stack* stack, Arg* arg, PIKA_BOOL is_alloc) {
int32_t stack_pushArg(Stack* stack, Arg* arg) {
pika_assert(arg != NULL);
if (arg_isObject(arg)) {
pika_assert(obj_checkAlive(arg_getPtr(arg)));
}
if (arg_isSerialized(arg)) {
return _stack_pushArg(stack, arg, PIKA_TRUE);
}

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*

View File

@ -1,6 +1,6 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
* This file is part of the PikaPython project.
* http://github.com/pikastech/pikapython
*
* MIT License
*
@ -76,6 +76,15 @@
#ifdef PIKA_TYPE_FULL_FEATURE_ENABLE
#define PIKA_TYPE_FULL_FEATURE_ENABLE 0
#endif
#ifndef PIKA_EVENT_THREAD_ENABLE
#define PIKA_EVENT_THREAD_ENABLE 0
#endif
#ifndef PIKA_GC_MARK_SWEEP_ENABLE
#define PIKA_GC_MARK_SWEEP_ENABLE 0
#endif
#endif
/* default optimize */
@ -304,6 +313,14 @@
#ifndef PIKA_INSTRUCT_YIELD_PERIOD
#define PIKA_INSTRUCT_YIELD_PERIOD 1
#endif
#ifndef PIKA_INSTRUCT_EXTENSION_ENABLE
#define PIKA_INSTRUCT_EXTENSION_ENABLE 1
#endif
#ifndef PIKA_INSTRUCT_SIGNATURE_DICT_COUNT
#define PIKA_INSTRUCT_SIGNATURE_DICT_COUNT 1
#endif
#ifndef PIKA_EXEC_ENABLE
#define PIKA_EXEC_ENABLE 1
@ -418,6 +435,22 @@
#define PIKA_TYPE_FULL_FEATURE_ENABLE 1
#endif
#ifndef PIKA_EVENT_THREAD_ENABLE
#define PIKA_EVENT_THREAD_ENABLE 1
#endif
#ifndef PIKA_GC_MARK_SWEEP_ENABLE
#define PIKA_GC_MARK_SWEEP_ENABLE 0
#endif
#ifndef PIKA_GC_MARK_SWEEP_THRESHOLD
#define PIKA_GC_MARK_SWEEP_THRESHOLD 20
#endif
#ifndef PIKA_KERNAL_DEBUG_ENABLE
#define PIKA_KERNAL_DEBUG_ENABLE 0
#endif
/* configuration validation */
#endif

View File

@ -4,7 +4,7 @@ TEST_START
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && (!PIKA_POOL_ENABLE)
TEST(PikaCV, test1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -19,7 +19,7 @@ TEST(PikaCV, test1) {
TEST(PikaCV, test2) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -34,7 +34,7 @@ TEST(PikaCV, test2) {
TEST(PikaCV, test3) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -49,7 +49,7 @@ TEST(PikaCV, test3) {
TEST(PikaCV, test4) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -64,7 +64,7 @@ TEST(PikaCV, test4) {
TEST(PikaCV, test5) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -79,7 +79,7 @@ TEST(PikaCV, test5) {
TEST(PikaCV, test6) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -94,7 +94,7 @@ TEST(PikaCV, test6) {
TEST(PikaCV, test7) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -109,7 +109,7 @@ TEST(PikaCV, test7) {
TEST(PikaCV, test8) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -124,7 +124,7 @@ TEST(PikaCV, test8) {
TEST(PikaCV, test9) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -139,7 +139,7 @@ TEST(PikaCV, test9) {
TEST(PikaCV, test10) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -154,7 +154,7 @@ TEST(PikaCV, test10) {
TEST(PikaCV, test11) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");

View File

@ -3,7 +3,7 @@ TEST_START
#if PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL
TEST(PikaMath, test1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -18,7 +18,7 @@ TEST(PikaMath, test1) {
TEST(PikaMath, quat_add) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain,
@ -49,7 +49,7 @@ TEST(PikaMath, quat_add) {
TEST(PikaMath, quat_sub) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain,
@ -80,7 +80,7 @@ TEST(PikaMath, quat_sub) {
TEST(PikaMath, quat_mul) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain,
@ -111,7 +111,7 @@ TEST(PikaMath, quat_mul) {
TEST(PikaMath, quat_set) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain,
@ -141,7 +141,7 @@ TEST(PikaMath, quat_set) {
TEST(PikaMath, quat_dot) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain,
@ -166,7 +166,7 @@ TEST(PikaMath, quat_dot) {
TEST(PikaMath, quat_inv) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain,
@ -196,7 +196,7 @@ TEST(PikaMath, quat_inv) {
TEST(PikaMath, quat_cross) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain,
@ -230,7 +230,7 @@ TEST(PikaMath, quat_cross) {
TEST(PikaMath, quat_toEuler) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain,
@ -259,7 +259,7 @@ TEST(PikaMath, quat_toEuler) {
TEST(PikaMath, quat_fromEuler) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain,

View File

@ -5,7 +5,7 @@ TEST_START
TEST(PikaNN, test1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");

View File

@ -149,9 +149,9 @@ TEST(VM, Run_add_1_2_3) {
EXPECT_EQ(pikaMemNow(), 0);
}
extern PikaMemInfo pikaMemInfo;
extern PikaMemInfo g_PikaMemInfo;
TEST(VM, WHILE) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines =(char *)
"a = 1\n"
@ -163,7 +163,7 @@ TEST(VM, WHILE) {
printf("%s", lines);
char* pikaAsm = Parser_linesToAsm(buffs, lines);
printf("%s", pikaAsm);
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* self = newRootObj("root", New_TinyObj);
VMParameters* globals = pikaVM_runAsm(self, pikaAsm);
EXPECT_EQ(args_getInt(globals->list, "a"), 0);
@ -657,13 +657,13 @@ TEST(InstructUnit, base) {
instructUnit_setBlockDeepth(&ins_unit, 2);
instructUnit_setIsNewLine(&ins_unit, 1);
instructUnit_setInvokeDeepth(&ins_unit, 3);
instructUnit_setInstruct(&ins_unit, (Instruct)4);
instructUnit_setInstruct(&ins_unit, (InstructIndex)4);
instructUnit_setConstPoolIndex(&ins_unit, 12);
EXPECT_EQ(instructUnit_getBlockDeepth(&ins_unit), 2);
EXPECT_EQ(instructUnit_getIsNewLine(&ins_unit), 1);
EXPECT_EQ(instructUnit_getInvokeDeepth(&ins_unit), 3);
EXPECT_EQ(instructUnit_getInstruct(&ins_unit), 4);
EXPECT_EQ(instructUnit_getInstructIndex(&ins_unit), 4);
EXPECT_EQ(instructUnit_getConstPoolIndex(&ins_unit), 12);
instructUnit_print(&ins_unit);
@ -714,7 +714,7 @@ TEST(InstructArray, set) {
instructUnit_setBlockDeepth(&ins_unit, 2);
instructUnit_setIsNewLine(&ins_unit, 1);
instructUnit_setInvokeDeepth(&ins_unit, 3);
instructUnit_setInstruct(&ins_unit, (Instruct)4);
instructUnit_setInstruct(&ins_unit, (InstructIndex)4);
instructUnit_setConstPoolIndex(&ins_unit, 12);
InstructArray ins_array;
@ -753,7 +753,7 @@ TEST(VM, bytecode_jjcc) {
}
TEST(VM, WHILE_byte) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines =(char *)
"a = 1\n"
@ -765,7 +765,7 @@ TEST(VM, WHILE_byte) {
printf("%s", lines);
char* pikaAsm = Parser_linesToAsm(buffs, lines);
printf("%s", pikaAsm);
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* self = newRootObj("root", New_TinyObj);
pikaVM_run(self, lines);
EXPECT_EQ(obj_getInt(self, "a"), 0);
@ -776,7 +776,7 @@ TEST(VM, WHILE_byte) {
}
TEST(VM, for_break_byte) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines =(char *)
"a = 0\n"
@ -788,7 +788,7 @@ TEST(VM, for_break_byte) {
printf("%s", lines);
char* pikaAsm = Parser_linesToAsm(buffs, lines);
printf("%s", pikaAsm);
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
pikaVM_run(self, lines);
/* assert */
@ -891,13 +891,13 @@ TEST(VM, load_static_bytes) {
}
TEST(VM, multi_jian) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = "a = (3-4) - 4\n";
printf("%s", lines);
char* pikaAsm = Parser_linesToAsm(buffs, lines);
printf("%s", pikaAsm);
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
pikaVM_run(self, lines);
/* assert */
@ -1309,7 +1309,7 @@ TEST(vm, class_keyword_mqtt) {
TEST(vm, vars_keyward) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1327,7 +1327,7 @@ TEST(vm, vars_keyward) {
TEST(vm, cb_1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1346,7 +1346,7 @@ TEST(vm, cb_1) {
TEST(vm, cb_2) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1369,7 +1369,7 @@ TEST(vm, cb_2) {
TEST(vm, cb_3) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1387,7 +1387,7 @@ TEST(vm, cb_3) {
#if !PIKA_NANO_ENABLE
TEST(vm, default_no_input) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1407,7 +1407,7 @@ TEST(vm, default_no_input) {
TEST(vm, default_1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1427,7 +1427,7 @@ TEST(vm, default_1) {
TEST(vm, default_2) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1447,7 +1447,7 @@ TEST(vm, default_2) {
TEST(vm, default_3) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1472,7 +1472,7 @@ TEST(vm, default_3) {
TEST(vm, default_4) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1500,7 +1500,7 @@ TEST(vm, default_4) {
TEST(vm, default_no_kw) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1526,7 +1526,7 @@ TEST(vm, default_no_kw) {
TEST(vm, none) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1544,7 +1544,7 @@ TEST(vm, none) {
#if !PIKA_NANO_ENABLE
TEST(vm, super_) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1571,7 +1571,7 @@ TEST(vm, super_) {
TEST(vm, super_val) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1600,7 +1600,7 @@ TEST(vm, super_val) {
TEST(vm, super_val_) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1633,7 +1633,7 @@ TEST(vm, super_val_) {
#if !PIKA_NANO_ENABLE
TEST(vm, multi_return) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1655,7 +1655,7 @@ TEST(vm, multi_return) {
#if !PIKA_NANO_ENABLE
TEST(vm, multi_return_fn) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1679,7 +1679,7 @@ TEST(vm, multi_return_fn) {
TEST(vm, range_1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1700,7 +1700,7 @@ TEST(vm, range_1) {
TEST(vm, rang_3) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1721,7 +1721,7 @@ TEST(vm, rang_3) {
TEST(vm, test64) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1742,7 +1742,7 @@ TEST(vm, test64) {
#if !PIKA_NANO_ENABLE
TEST(vm, exit) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1766,7 +1766,7 @@ TEST(vm, exit) {
TEST(vm, exit_fn) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1814,7 +1814,7 @@ void __gtest_hook_default_(void) {
void _vm_exit_fn_issue_1_item(int hook_cnt) {
g_hook_cnt_triggle = hook_cnt;
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1857,7 +1857,7 @@ TEST(vm, exit_fn_issue_1) {
TEST(vm, pass_) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1881,7 +1881,7 @@ TEST(vm, pass_) {
TEST(vm, test64_hex) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1901,7 +1901,7 @@ TEST(vm, test64_hex) {
TEST(vm, test64_hex_print) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1922,7 +1922,7 @@ TEST(vm, test64_hex_print) {
#if !PIKA_NANO_ENABLE
TEST(vm, call_dict_err) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1941,7 +1941,7 @@ TEST(vm, call_dict_err) {
TEST(vm, getattribute) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1963,7 +1963,7 @@ TEST(vm, getattribute) {
TEST(vm, getattr) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -1989,7 +1989,7 @@ TEST(vm, getattr) {
TEST(vm, setattr) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2015,7 +2015,7 @@ TEST(vm, setattr) {
TEST(vm, c_module_get_set_attr) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2040,7 +2040,7 @@ TEST(vm, c_module_get_set_attr) {
TEST(vm, class_attr_ref) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2060,7 +2060,7 @@ TEST(vm, class_attr_ref) {
TEST(vm, getattr_native) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2080,7 +2080,7 @@ TEST(vm, getattr_native) {
TEST(vm, issue_dict_update) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2097,7 +2097,7 @@ TEST(vm, issue_dict_update) {
TEST(vm, issue_big_dict_update) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2116,7 +2116,7 @@ TEST(vm, issue_big_dict_update) {
TEST(vm, i_pp) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2150,7 +2150,7 @@ TEST(vm, i_pp) {
TEST(vm, benchmark) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2288,7 +2288,7 @@ TEST(VM, bc_fn_file_cb2) {
#if !PIKA_NANO_ENABLE
TEST(vm, slice_str_end) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -2300,12 +2300,59 @@ TEST(vm, slice_str_end) {
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(vm, slice_list) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
obj_run(pikaMain, "[1,2,3][1:]");
/* collect */
/* assert */
EXPECT_STREQ(log_buff[0], "[2, 3]\r\n");
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(vm, slice_list_list) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
obj_run(pikaMain,
"l = "
"[[\"ID\",\"TCP_URL\",\"VERSION\",\"SENSOR_SCAN_s\",\"DATA_UPLOAD_"
"s\",\"ACT_LOGIC_SCAN_s\",\"NETWORK\",\"AUTO_ACT\",\"START_TIME\"],"
"[\"ABC123\",\"iot.365sn.cn/operate/h/"
"1234\",\"V1.1\",60,1800,0.5,\"4G\",\"TRUE\",1669017826]]\n"
"ll = l[1:]\n"
"print(len(l), l)\n"
"print(len(ll),ll)\n");
/* collect */
/* assert */
EXPECT_STREQ(log_buff[0],
"9 ['ABC123', 'iot.365sn.cn/operate/h/1234', 'V1.1', 60, "
"1800, 0.500000, '4G', 'TRUE', 1669017826]\r\n");
EXPECT_STREQ(log_buff[1],
"2 [['ID', 'TCP_URL', 'VERSION', 'SENSOR_SCAN_s', "
"'DATA_UPLOAD_s', 'ACT_LOGIC_SCAN_s', 'NETWORK', 'AUTO_ACT', "
"'START_TIME'], ['ABC123', 'iot.365sn.cn/operate/h/1234', "
"'V1.1', 60, 1800, 0.500000, '4G', 'TRUE', 1669017826]]\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
#if !PIKA_NANO_ENABLE
TEST(vm, fn_pos_kw) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -2323,7 +2370,7 @@ TEST(vm, fn_pos_kw) {
TEST(vm, fn_pos_kw2) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -2343,7 +2390,7 @@ TEST(vm, fn_pos_kw2) {
TEST(vm, fn_star) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -2360,7 +2407,7 @@ TEST(vm, fn_star) {
TEST(vm, fn_star_pos) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -2377,7 +2424,7 @@ TEST(vm, fn_star_pos) {
TEST(vm, fn_star_pos_2) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -2394,7 +2441,7 @@ TEST(vm, fn_star_pos_2) {
TEST(vm, fn_star_star) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -2460,7 +2507,7 @@ TEST(vm, def_not_in) {
TEST(vm, fn_pos_kw_issue1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -2478,7 +2525,7 @@ TEST(vm, fn_pos_kw_issue1) {
TEST(vm, fn_pos_kw_issue2) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -2496,7 +2543,7 @@ TEST(vm, fn_pos_kw_issue2) {
TEST(vm, num_issue_lakj) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -2511,7 +2558,7 @@ TEST(vm, num_issue_lakj) {
TEST(vm, dir_issue) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -2528,7 +2575,7 @@ TEST(vm, dir_issue) {
TEST(vm, dir_issue1lk) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2546,7 +2593,7 @@ TEST(vm, dir_issue1lk) {
TEST(vm, type_int) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2565,7 +2612,7 @@ TEST(vm, type_int) {
TEST(vm, method_int) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2584,7 +2631,7 @@ TEST(vm, method_int) {
TEST(vm, fn_method_int) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2606,7 +2653,7 @@ TEST(vm, fn_method_int) {
TEST(vm, kw_no_empty) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2626,7 +2673,7 @@ TEST(vm, kw_no_empty) {
TEST(vm, tuple_void) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2678,7 +2725,7 @@ TEST(vm, method_cb) {
TEST(vm, class_getattr) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2694,9 +2741,9 @@ TEST(vm, class_getattr) {
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(vm, type_fullfealure){
TEST(vm, type_fullfealure) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2712,10 +2759,9 @@ TEST(vm, type_fullfealure){
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(vm, dir_print_arg){
TEST(vm, dir_print_arg) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -2730,6 +2776,58 @@ TEST(vm, dir_print_arg){
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(vm, fn_pos_vars) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "test/python/builtin/fn_pos_vars.py");
/* collect */
/* assert */
EXPECT_STREQ(
log_buff[4],
"TypeError: log() takes 2 positional argument but 1 were given\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(vm, for_return) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "test/python/builtin/for_return.py");
/* collect */
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(vm, slice_issue) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "test/python/builtin/slice.py");
/* collect */
/* assert */
EXPECT_STREQ(log_buff[0], "PASS\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
TEST_END

View File

@ -4,7 +4,7 @@ TEST_START
#if PIKA_SYNTAX_SLICE_ENABLE
TEST(builtin, bytes) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -22,7 +22,7 @@ TEST(builtin, bytes) {
#if PIKA_BUILTIN_STRUCT_ENABLE
TEST(builtin, type1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -40,7 +40,7 @@ TEST(builtin, type1) {
#if PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL
TEST(builtin, seek) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -58,7 +58,7 @@ TEST(builtin, seek) {
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL)
TEST(builtin, file2) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -76,7 +76,7 @@ TEST(builtin, file2) {
#if PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL
TEST(builtin, file3) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -92,7 +92,7 @@ TEST(builtin, file3) {
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && !PIKA_POOL_ENABLE
TEST(builtin, bigfile) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -108,7 +108,7 @@ TEST(builtin, bigfile) {
TEST(builtin, nofound) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -123,7 +123,7 @@ TEST(builtin, nofound) {
#if PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL
TEST(builtin, callback_1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -141,7 +141,7 @@ TEST(builtin, callback_1) {
#if !PIKA_NANO_ENABLE
TEST(builtin, utf8) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -155,6 +155,23 @@ TEST(builtin, utf8) {
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(builtin, str_join) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "test/python/builtin/str_join.py");
/* collect */
/* assert */
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
EXPECT_STREQ(log_buff[0], "PASS\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
TEST_END

View File

@ -3,7 +3,7 @@ TEST_START
TEST(cJSON, parse_print) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
char testjson[] =
"{\n"
@ -32,7 +32,7 @@ TEST(cJSON, parse_print) {
TEST(cJSON, getItem) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
char testjson[] =
"{\n"
@ -65,7 +65,7 @@ TEST(cJSON, getItem) {
TEST(cJSON, next) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
char testjson[] =
"{\n"
@ -103,7 +103,7 @@ TEST(cJSON, next) {
TEST(cJSON, next_get_value) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
char testjson[] =
"{\n"
@ -144,7 +144,7 @@ TEST(cJSON, next_get_value) {
TEST(cJSON, item) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -189,7 +189,7 @@ TEST(cJSON, item) {
#if PIKA_SYNTAX_IMPORT_EX_ENABLE
TEST(cJSON, construct) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -228,7 +228,7 @@ TEST(cJSON, construct) {
TEST(cJSON, test1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -248,7 +248,7 @@ TEST(cJSON, test1) {
TEST(cJSON, test2) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -269,7 +269,7 @@ TEST(cJSON, test2) {
#if PIKA_SYNTAX_IMPORT_EX_ENABLE
TEST(cJSON, test3) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -292,7 +292,7 @@ TEST(cJSON, test3) {
TEST(cJSON, test4) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -318,7 +318,7 @@ TEST(cJSON, test4) {
TEST(cJSON, test5) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -348,7 +348,7 @@ TEST(cJSON, test5) {
TEST(cJSON, test6) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -380,7 +380,7 @@ TEST(cJSON, test6) {
TEST(cJSON, parse_failed) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
char testjson[] =
"{{\n"
@ -419,7 +419,7 @@ TEST(cJSON, parse_failed) {
#if PIKA_SYNTAX_IMPORT_EX_ENABLE
TEST(cJSON, test7) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -437,7 +437,7 @@ TEST(cJSON, test7) {
#if PIKA_SYNTAX_IMPORT_EX_ENABLE
TEST(cJSON, module) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);

View File

@ -3,7 +3,7 @@ TEST_START
TEST(chinese, test1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
pikaVM_runSingleFile(pikaMain, "../../examples/Chinese/test_operator.py");
obj_run(pikaMain, "test()");

View File

@ -4,7 +4,7 @@ TEST_START
#if !PIKA_NANO_ENABLE
TEST(class, class_par) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
/* run */
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
@ -23,7 +23,7 @@ TEST(class, class_par) {
TEST(class, classpar1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
/* run */
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
@ -41,7 +41,7 @@ TEST(class, classpar1) {
TEST(class, static_method) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
/* run */
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
@ -60,7 +60,7 @@ TEST(class, static_method) {
TEST(class, dir_) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
/* run */
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");

View File

@ -3,7 +3,7 @@ TEST_START
TEST(cmodule, print_) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain, "print('test', 'test2')\n");

View File

@ -391,7 +391,6 @@ TEST(lib, compile_link_import) {
/* asset */
EXPECT_STREQ(log_buff[0], "test_module_1_hello\r\n");
/* deinit */
LibObj_deinit(lib);
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
@ -459,7 +458,6 @@ TEST(lib, load_file) {
EXPECT_STREQ(log_buff[1], "test_module_2_hello\r\n");
EXPECT_STREQ(log_buff[0], "test_module_3_hello\r\n");
/* deinit */
LibObj_deinit(lib);
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
@ -549,13 +547,13 @@ TEST(make, compile_depend_all) {
// }
TEST(compiler, __str__) {
char* lines = "__res = __str__()";
char* lines = "@res_str = __str__()";
Parser_linesToArray(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, __len__) {
char* lines = "__res = __len__()";
char* lines = "@res_len = __len__()";
Parser_linesToArray(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
@ -585,25 +583,31 @@ TEST(compiler, __setitem__) {
}
TEST(compiler, __getitem__) {
char* lines = "__res = __getitem__(__key)";
char* lines = "@res_item = __getitem__(__key)";
Parser_linesToArray(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, __add__) {
char* lines = "__res = __add__(__others)";
char* lines = "@res_add = __add__(__others)";
Parser_linesToArray(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, __iter__) {
char* lines = "@res_iter = __iter__()";
Parser_linesToArray(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, __sub__) {
char* lines = "__res = __sub__(__others)";
char* lines = "@res_sub = __sub__(__others)";
Parser_linesToArray(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, __contains__) {
char* lines = "__res = __contains__(__others)";
char* lines = "@res_contains = __contains__(__others)";
Parser_linesToArray(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
@ -616,9 +620,9 @@ TEST(compiler, __callback) {
TEST(compiler, __list) {
char* lines =
"__res = []\n"
"@res_list = []\n"
"for __item in __list:\n"
" __res.append(__item)\n"
" @res_list.append(__item)\n"
"del __item\n"
"del __list\n";
Parser_linesToArray(lines);
@ -738,4 +742,16 @@ TEST(compiler, getattr_fn) {
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, str_join) {
char* lines =
"@res_join = \"\"\n"
"@num = len(@val)\n"
"for i in range(@num):\n"
" @res_join += @val[i]\n"
" if i != @num - 1:\n"
" @res_join += @str\n";
Parser_linesToArray(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST_END

View File

@ -17,7 +17,7 @@ TEST(configparser, test1) {
"ForwardX11 = no\n";
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -39,7 +39,7 @@ TEST(configparser, test1) {
#if PIKA_SYNTAX_SLICE_ENABLE
TEST(configparser, test2) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);

View File

@ -4,7 +4,7 @@ TEST_START
#if PIKA_SYNTAX_SLICE_ENABLE
TEST(ctypes, test1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/ctypes.py");
@ -20,7 +20,7 @@ TEST(ctypes, test1) {
#if !PIKA_NANO_ENABLE
TEST(ctypes, test2) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain,

View File

@ -68,7 +68,7 @@ TEST(event, remove_regist) {
EXPECT_EQ(testobj->refcnt, 1);
/* deinit */
obj_deinit(pikaMain);
obj_deinit(testobj);
obj_GC(testobj);
pks_eventListener_deinit(&g_pika_device_event_listener);
EXPECT_EQ(pikaMemNow(), 0);
}

View File

@ -4,7 +4,7 @@ TEST_START
#if PIKA_SYNTAX_EXCEPTION_ENABLE
TEST(except, try1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
@ -28,7 +28,7 @@ TEST(except, try1) {
TEST(except, def_none) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
@ -48,7 +48,7 @@ TEST(except, def_none) {
TEST(except, trydef1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
@ -65,7 +65,7 @@ TEST(except, trydef1) {
TEST(except, try1file) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
@ -82,7 +82,7 @@ TEST(except, try1file) {
TEST(except, for_loop) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
@ -108,7 +108,7 @@ TEST(except, for_loop) {
TEST(except, dict) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
@ -124,7 +124,7 @@ TEST(except, dict) {
TEST(except, len) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
@ -140,7 +140,7 @@ TEST(except, len) {
TEST(except, trycmodule1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
@ -163,7 +163,7 @@ TEST(except, trycmodule1) {
TEST(except, except_break) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
@ -189,7 +189,7 @@ TEST(except, except_break) {
TEST(except, while_try_while) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */

View File

@ -127,8 +127,55 @@ TEST(gc, heap_failed1) {
"iteri");
/* assert */
EXPECT_STREQ("128\r\n", log_buff[0]);
#if PIKA_GC_MARK_SWEEP_ENABLE
int cnt = pikaGC_count();
EXPECT_EQ(cnt != 0, 1);
pikaGC_markDump();
int cnt_marked = pikaGC_countMarked();
EXPECT_EQ(cnt, cnt_marked);
/* deinit */
#endif
obj_deinit(pikaMain);
#if PIKA_GC_MARK_SWEEP_ENABLE
cnt = pikaGC_count();
EXPECT_EQ(cnt, 0);
#endif
EXPECT_EQ(pikaMemNow(), 0);
}
#if PIKA_GC_MARK_SWEEP_ENABLE
TEST(gc, circle) {
/* init */
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
pikaVM_runSingleFile(pikaMain, "test/python/gc/gc_circle.py");
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(gc, circle2) {
/* init */
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
pikaVM_runSingleFile(pikaMain, "test/python/gc/gc_circle2.py");
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(gc, tree1) {
/* init */
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
pikaVM_runSingleFile(pikaMain, "test/python/gc/gc_tree1.py");
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
TEST_END

View File

@ -2,7 +2,7 @@
TEST(hashlib, new_) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);

View File

@ -3,7 +3,7 @@ TEST_START
#if !PIKA_NANO_ENABLE
TEST(json, loads) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -63,7 +63,7 @@ TEST(json, loads) {
#if PIKA_FLOAT_TYPE_DOUBLE
TEST(json, dumps) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);

View File

@ -6,7 +6,7 @@ extern "C" {
}
extern "C" {
void test_purec(void);
void test_purec(void);
}
int main(int argc, char** argv) {
@ -19,11 +19,16 @@ int main(int argc, char** argv) {
#endif
mem_pool_deinit();
#if PIKA_ARG_CACHE_ENABLE
extern PikaMemInfo pikaMemInfo;
extern PikaMemInfo g_PikaMemInfo;
#if PIKA_GC_MARK_SWEEP_ENABLE
extern PikaObjState g_PikaObjState;
printf("[ GC]: object num max: %d, last GC: %d\r\n",
g_PikaObjState.objCntMax, g_PikaObjState.objCntLastGC);
#endif
printf("[ Info]: alloc times: %d, cached times: %d (%0.2f%%)\r\n",
pikaMemInfo.alloc_times, pikaMemInfo.alloc_times_cache,
((float)pikaMemInfo.alloc_times_cache /
(float)pikaMemInfo.alloc_times) *
g_PikaMemInfo.alloc_times, g_PikaMemInfo.alloc_times_cache,
((float)g_PikaMemInfo.alloc_times_cache /
(float)g_PikaMemInfo.alloc_times) *
100.0);
#endif
return res;

View File

@ -4,7 +4,7 @@ TEST_START
#if PIKA_SYNTAX_IMPORT_EX_ENABLE
TEST(module, cmodule_import) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
@ -23,7 +23,7 @@ TEST(module, cmodule_import) {
TEST(module, while_loop) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -42,7 +42,7 @@ TEST(module, while_loop) {
TEST(module, for_loop) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -61,7 +61,7 @@ TEST(module, for_loop) {
TEST(module, script) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -78,7 +78,7 @@ TEST(module, script) {
TEST(module, __init__) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -97,7 +97,7 @@ TEST(module, __init__) {
#if PIKA_SYNTAX_IMPORT_EX_ENABLE
TEST(module, __init__2) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -117,7 +117,7 @@ TEST(module, __init__2) {
#if PIKA_SYNTAX_IMPORT_EX_ENABLE
TEST(module, import_as_issue1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -141,7 +141,7 @@ TEST(module, import_as_issue1) {
#if PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL
TEST(module, unittest_test1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -163,7 +163,7 @@ TEST(module, unittest_test1) {
#if PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL
TEST(module, unittest_test2) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -183,7 +183,7 @@ TEST(module, unittest_test2) {
TEST(module, unittest_test3) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -205,7 +205,7 @@ TEST(module, unittest_test3) {
TEST(socket, gethostname) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -223,7 +223,7 @@ TEST(socket, gethostname) {
#if !PIKA_NANO_ENABLE
TEST(socket, server_client) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -242,7 +242,7 @@ TEST(socket, server_client) {
TEST(socket, thread) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -264,7 +264,7 @@ TEST(socket, thread) {
#if PIKA_FLOAT_TYPE_DOUBLE
TEST(socket, json_issue) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -296,7 +296,7 @@ TEST(socket, json_issue) {
#if !PIKA_NANO_ENABLE
TEST(re, match) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -319,7 +319,7 @@ TEST(re, match) {
#if !PIKA_NANO_ENABLE
TEST(re, search) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -340,7 +340,7 @@ TEST(re, search) {
#if !PIKA_NANO_ENABLE
TEST(re, sub) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -361,7 +361,7 @@ TEST(re, sub) {
#if !PIKA_NANO_ENABLE
TEST(re, findall) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -387,7 +387,7 @@ TEST(re, findall) {
TEST(modbus, rtu_master) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -414,7 +414,7 @@ TEST(modbus, rtu_master) {
TEST(proxy, test1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -432,7 +432,7 @@ TEST(proxy, test1) {
TEST(issue, global) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -449,7 +449,7 @@ TEST(issue, global) {
TEST(module, mod1_mod2_mod1) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -468,7 +468,7 @@ TEST(module, mod1_mod2_mod1) {
TEST(module, improt_as_cmodule) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -497,7 +497,7 @@ void pikaScriptShell_withGetchar(PikaObj* self, sh_getchar getchar_fn);
TEST(module, REPL_runbytecode) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -517,7 +517,7 @@ TEST(module, REPL_runbytecode) {
TEST(module, REPL_script) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -536,7 +536,7 @@ TEST(module, REPL_script) {
TEST(module, REPL_script_2) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -555,7 +555,7 @@ TEST(module, REPL_script_2) {
TEST(module, REPL_big_script) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -576,7 +576,7 @@ TEST(module, REPL_big_script) {
TEST(module, REPL_stdtask) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);

View File

@ -74,7 +74,7 @@ int pika_hal_platform_WIFI_ioctl_others(pika_dev* dev,
}
TEST(network, scan) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -98,7 +98,7 @@ TEST(network, scan) {
}
TEST(network, connect) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
@ -127,7 +127,7 @@ TEST(network, connect) {
}
TEST(network, config) {
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);

37
test/packtool-test.cpp Normal file
View File

@ -0,0 +1,37 @@
#include "test_common.h"
TEST_START
#include "PikaCompiler.h"
#if 0 // TODO add a.pack
TEST(packtool, unpack) {
PIKA_RES res = LibObj_unpackFileToPath("test/assets/a.pack", "test/out/unpackout");
EXPECT_EQ(res, PIKA_RES_OK);
}
TEST(packtool, packread) {
size_t n = 0;
//Arg* fileArg = NULL;
pikafs_FILE* pack_file = pikafs_fopen_pack("test/assets/a.pack", "main.py");
// pikafs_FILE* pack_file = pikafs_fopen_pack_new(&fileArg, "test/assets/a.pack", "main.py");
FILE* file = pika_platform_fopen("test/out/unpackout/main2.py", "wb+");
if (NULL == file) {
pika_platform_printf("open file: %s error\r\n", "test/out/unpackout/main2.py");
}
n = pika_platform_fwrite(pack_file->addr, pack_file->size, 1, file);
EXPECT_NE(n, 0);
//arg_deinit(fileArg);
pikaFree(pack_file, sizeof(pikafs_FILE));
pika_platform_fclose(file);
pack_file = NULL;
}
#endif
TEST_END

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,4 @@
#define LOG_BUFF_MAX 100
#define LOG_SIZE 512
void mem_pool_init(void);
void mem_pool_deinit(void);
void mem_pool_deinit(void);
void mem_pool_init(void);

View File

@ -1,10 +1,11 @@
#include "test_common.h"
TEST_START
#if !PIKA_NANO_ENABLE
#if PIKA_GC_MARK_SWEEP_ENABLE
TEST(pikaui, page) {
/* init */
pikaMemInfo.heapUsedMax = 0;
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
@ -16,6 +17,5 @@ TEST(pikaui, page) {
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
TEST_END

Some files were not shown because too many files have changed in this diff Show More