49 lines
1.1 KiB
C
Raw Normal View History

2025-12-02 06:54:32 +01:00
#include "fastframe.h"
#include <string.h>
FastFrame_t rava_frame_pool[RAVA_MAX_CALL_DEPTH];
size_t rava_frame_depth = 0;
void rava_fastframe_init(void) {
rava_frame_depth = 0;
memset(rava_frame_pool, 0, sizeof(rava_frame_pool));
}
FastFrame_t* rava_fastframe_push(RavaMethod_t* method, int local_count) {
if (rava_frame_depth >= RAVA_MAX_CALL_DEPTH) {
return NULL;
}
FastFrame_t* frame = &rava_frame_pool[rava_frame_depth++];
frame->method = method;
frame->stack_top = 0;
frame->pc = 0;
frame->has_this = false;
frame->this_ref = rava_nanbox_null();
if (local_count > 0 && local_count <= RAVA_MAX_LOCALS_FIXED) {
memset(frame->locals, 0, (size_t)local_count * sizeof(RavaNanboxValue_t));
}
return frame;
}
void rava_fastframe_pop(void) {
if (rava_frame_depth > 0) {
rava_frame_depth--;
}
}
FastFrame_t* rava_fastframe_current(void) {
if (rava_frame_depth == 0) return NULL;
return &rava_frame_pool[rava_frame_depth - 1];
}
size_t rava_fastframe_get_depth(void) {
return rava_frame_depth;
}
void rava_fastframe_reset(void) {
rava_frame_depth = 0;
}