support hook_instruct

This commit is contained in:
pikastech 2022-08-06 15:56:27 +08:00
parent 874f3ff7ed
commit 1d97f4b34e
6 changed files with 23 additions and 1 deletions

View File

@ -191,3 +191,7 @@ PIKA_WEAK long __platform_ftell(FILE* stream) {
}
#endif
}
PIKA_WEAK void __pks_hook_instruct(void) {
return;
}

View File

@ -158,4 +158,6 @@ long __platform_ftell(FILE* stream);
/* error */
void __platform_error_handle(void);
void __pks_hook_instruct(void);
#endif

View File

@ -2203,6 +2203,7 @@ static VMParameters* __pikaVM_runByteCodeFrameWithState(
.line_error_code = PIKA_RES_OK,
.try_error_code = PIKA_RES_OK,
.try_info = try_info,
.ins_cnt = 0,
};
stack_init(&(vs.stack));
VMState_initReg(&vs);
@ -2218,6 +2219,12 @@ static VMParameters* __pikaVM_runByteCodeFrameWithState(
vs.line_error_code = 0;
}
vs.pc = pikaVM_runInstructUnit(self, &vs, this_ins_unit);
vs.ins_cnt++;
#if PIKA_INSTRUCT_HOOK_ENABLE
if (vs.ins_cnt % PIKA_INSTRUCT_HOOK_PERIOD == 0) {
__pks_hook_instruct();
}
#endif
if (0 != vs.error_code) {
vs.line_error_code = vs.error_code;
InstructUnit* head_ins_unit = this_ins_unit;

View File

@ -76,6 +76,7 @@ struct VMState {
uint8_t error_code;
uint8_t line_error_code;
uint8_t try_error_code;
uint32_t ins_cnt;
PikaObj* lreg[PIKA_REGIST_SIZE];
PIKA_BOOL ireg[PIKA_REGIST_SIZE];
TryInfo* try_info;

View File

@ -2,4 +2,4 @@
#define PIKA_VERSION_MINOR 10
#define PIKA_VERSION_MICRO 0
#define PIKA_EDIT_TIME "2022/08/05 22:39:41"
#define PIKA_EDIT_TIME "2022/08/06 15:56:22"

View File

@ -254,6 +254,14 @@
#define PIKA_ARG_BUFF_SIZE 8
#endif
#ifndef PIKA_INSTRUCT_HOOK_ENABLE
#define PIKA_INSTRUCT_HOOK_ENABLE 0
#endif
#ifndef PIKA_INSTRUCT_HOOK_PERIOD
#define PIKA_INSTRUCT_HOOK_PERIOD 50
#endif
/* configuration validation */
#endif