mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-05 19:20:17 +00:00
Compare commits
No commits in common. "2d682b24d8a6d8bb164e84a4cd455c4fa80be265" and "f4b2cd4a5f93cc83be5a0953172450b2309baf0e" have entirely different histories.
2d682b24d8
...
f4b2cd4a5f
@ -24,5 +24,3 @@ void LineProfiler__begin(LineProfiler* self);
|
|||||||
void LineProfiler__tracefunc_line(LineProfiler* self, py_Frame* frame);
|
void LineProfiler__tracefunc_line(LineProfiler* self, py_Frame* frame);
|
||||||
void LineProfiler__end(LineProfiler* self);
|
void LineProfiler__end(LineProfiler* self);
|
||||||
void LineProfiler__reset(LineProfiler* self);
|
void LineProfiler__reset(LineProfiler* self);
|
||||||
|
|
||||||
void LineProfiler__tracefunc(py_Frame* frame, enum py_TraceEvent event);
|
|
||||||
@ -105,6 +105,9 @@ FrameResult VM__run_top_frame(VM* self) {
|
|||||||
PK_INCREF(loc.src);
|
PK_INCREF(loc.src);
|
||||||
self->trace_info.prev_loc = loc;
|
self->trace_info.prev_loc = loc;
|
||||||
self->trace_info.func(frame, TRACE_EVENT_LINE);
|
self->trace_info.func(frame, TRACE_EVENT_LINE);
|
||||||
|
if(self->line_profiler.enabled) {
|
||||||
|
LineProfiler__tracefunc_line(&self->line_profiler, frame);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -32,11 +32,6 @@ static void pk_default_print(const char* data) { printf("%s", data); }
|
|||||||
|
|
||||||
static void pk_default_flush() { fflush(stdout); }
|
static void pk_default_flush() { fflush(stdout); }
|
||||||
|
|
||||||
void LineProfiler__tracefunc(py_Frame* frame, enum py_TraceEvent event) {
|
|
||||||
LineProfiler* self = &pk_current_vm->line_profiler;
|
|
||||||
if(self->enabled && event == TRACE_EVENT_LINE) { LineProfiler__tracefunc_line(self, frame); }
|
|
||||||
}
|
|
||||||
|
|
||||||
static void py_TypeInfo__ctor(py_TypeInfo* self,
|
static void py_TypeInfo__ctor(py_TypeInfo* self,
|
||||||
py_Name name,
|
py_Name name,
|
||||||
py_Type index,
|
py_Type index,
|
||||||
|
|||||||
55
src2/main.c
55
src2/main.c
@ -6,9 +6,28 @@
|
|||||||
|
|
||||||
#include "pocketpy.h"
|
#include "pocketpy.h"
|
||||||
|
|
||||||
|
#define py_interrupt()
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
static BOOL WINAPI sigint_handler(DWORD dwCtrlType) {
|
||||||
|
if(dwCtrlType == CTRL_C_EVENT) {
|
||||||
|
py_interrupt();
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
// set ctrl+c handler
|
||||||
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
static void sigint_handler(int sig) { py_interrupt(); }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char* read_file(const char* path) {
|
static char* read_file(const char* path) {
|
||||||
@ -26,35 +45,57 @@ static char* read_file(const char* path) {
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// void LineProfiler__tracefunc(py_Frame* frame, enum py_TraceEvent event);
|
static void tracefunc(py_Frame* frame, enum py_TraceEvent event) {
|
||||||
|
int line;
|
||||||
|
const char* filename = py_Frame_sourceloc(frame, &line);
|
||||||
|
const char* event_str;
|
||||||
|
switch(event) {
|
||||||
|
case TRACE_EVENT_LINE:
|
||||||
|
event_str = "line";
|
||||||
|
break;
|
||||||
|
case TRACE_EVENT_EXCEPTION:
|
||||||
|
event_str = "exception";
|
||||||
|
break;
|
||||||
|
case TRACE_EVENT_PUSH:
|
||||||
|
event_str = "push";
|
||||||
|
break;
|
||||||
|
case TRACE_EVENT_POP:
|
||||||
|
event_str = "pop";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
printf("\x1b[30m%s:%d, event=%s\x1b[0m\n", filename, line, event_str);
|
||||||
|
}
|
||||||
|
|
||||||
static char buf[2048];
|
static char buf[2048];
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
SetConsoleCP(CP_UTF8);
|
SetConsoleCP(CP_UTF8);
|
||||||
SetConsoleOutputCP(CP_UTF8);
|
SetConsoleOutputCP(CP_UTF8);
|
||||||
|
// SetConsoleCtrlHandler((PHANDLER_ROUTINE)sigint_handler, TRUE);
|
||||||
|
#else
|
||||||
|
// signal(SIGINT, sigint_handler);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool profile = false;
|
bool trace = false;
|
||||||
const char* filename = NULL;
|
const char* filename = NULL;
|
||||||
|
|
||||||
for(int i = 1; i < argc; i++) {
|
for(int i = 1; i < argc; i++) {
|
||||||
if(strcmp(argv[i], "--profile") == 0) {
|
if(strcmp(argv[i], "--trace") == 0) {
|
||||||
profile = true;
|
trace = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(filename == NULL) {
|
if(filename == NULL) {
|
||||||
filename = argv[i];
|
filename = argv[i];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
printf("Usage: pocketpy [--profile] filename\n");
|
printf("Usage: pocketpy [--trace] filename\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
py_initialize();
|
py_initialize();
|
||||||
py_sys_setargv(argc, argv);
|
py_sys_setargv(argc, argv);
|
||||||
|
|
||||||
assert(!profile); // not implemented yet
|
if(trace) py_sys_settrace(tracefunc, true);
|
||||||
// if(profile) py_sys_settrace(LineProfiler__tracefunc, true);
|
|
||||||
|
|
||||||
if(filename == NULL) {
|
if(filename == NULL) {
|
||||||
printf("pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ") ");
|
printf("pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ") ");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user