Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update pocketpy from v1.x to v2.0.1 #2714

Merged
merged 33 commits into from
Nov 11, 2024
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b0dc078
unchange python.c
PrimedErwin Oct 31, 2024
2cfe30a
add pkpy2 submodule
PrimedErwin Oct 31, 2024
bb7517a
pyfunc not updated
PrimedErwin Nov 2, 2024
c38a639
added debug feature
PrimedErwin Nov 2, 2024
efb376e
[dev]boot returns emptyp
PrimedErwin Nov 3, 2024
f25830d
[dev]basic func finished
PrimedErwin Nov 3, 2024
823924e
[dev]hello world enabled
PrimedErwin Nov 3, 2024
d0ea8c9
[dev]..
PrimedErwin Nov 3, 2024
7d598d2
[dev]all bind
PrimedErwin Nov 4, 2024
bdcb3c6
[dev]add valueError
PrimedErwin Nov 4, 2024
71bfec0
[dev]fix some bug
PrimedErwin Nov 4, 2024
926411f
[dev]fix some bugs
PrimedErwin Nov 4, 2024
0279784
[dev]all api test pass
PrimedErwin Nov 5, 2024
5c7bec8
Merge pull request #1 from PrimedErwin/master201
PrimedErwin Nov 5, 2024
fbb64e5
[release]..
PrimedErwin Nov 5, 2024
3a46c09
Merge pull request #2 from PrimedErwin/master201
PrimedErwin Nov 5, 2024
6e332b4
[release]pkpy update to v2
PrimedErwin Nov 3, 2024
a6e3b90
[dev]core unchange
PrimedErwin Nov 5, 2024
68970e5
[dev].
PrimedErwin Nov 5, 2024
b5d9319
[dev]castfloat+core saved+exception raise
PrimedErwin Nov 5, 2024
df4fe51
[dev]fixed mouse()
PrimedErwin Nov 5, 2024
fdf8864
[dev]fixed mouse() alloc
PrimedErwin Nov 6, 2024
2357968
[dev]delete tmp in mouse()
PrimedErwin Nov 6, 2024
4efd34a
[dev]add assert, update pkpy.cmake
PrimedErwin Nov 7, 2024
c3fe29b
[dev]update pkpy submodule
PrimedErwin Nov 7, 2024
3044c3e
some fix
blueloveTH Nov 8, 2024
758c84a
some fix
blueloveTH Nov 8, 2024
9e0f8b1
fix IPO issue
blueloveTH Nov 8, 2024
fa0a967
fix time.c
blueloveTH Nov 8, 2024
1093fda
fix time.c
blueloveTH Nov 8, 2024
fd8fcf2
fix time.c
blueloveTH Nov 8, 2024
d4725f2
fix time.c
blueloveTH Nov 8, 2024
1952005
[dev]assign none to retval() as default
PrimedErwin Nov 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[dev]boot returns emptyp
  • Loading branch information
PrimedErwin committed Nov 3, 2024
commit efb376ed90215ce7940a6b45121c7a17474625ce
150 changes: 140 additions & 10 deletions src/api/python.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
#include "core/core.h"

#include "pocketpy.h"
#include "pocketpy/objects/base.h"
PrimedErwin marked this conversation as resolved.
Show resolved Hide resolved
#include <stdio.h>
#include <string.h>

/***************DEBUG SESSION*************/
//cmake -A x64 -DCMAKE_BUILD_TYPE=MinSizeRel -DBUILD_SDLGPU=On -DBUILD_STATIC=On -DBUILD_WITH_ALL=Off -DBUILD_WITH_PYTHON=On ..
//
//for debug
//cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=MinSizeRel -DBUILD_SDLGPU=On -DBUILD_WITH_ALL=On ..
//
//for release
extern bool parse_note(const char* noteStr, s32* note, s32* octave);

struct names
PrimedErwin marked this conversation as resolved.
Show resolved Hide resolved
{
py_Name _tic_core;
py_Name len;
py_Name __getitem__;
py_Name TIC;
py_Name BOOT;
py_Name SCN;
py_Name BDR;
py_Name MENU;
}N;

//set value of "name" to stack.top
Expand Down Expand Up @@ -67,6 +75,8 @@ static int prepare_colorindex(int index, u8* buffer)
}
}

/*****************TIC-80 API BEGIN*****************/

static bool py_btn(int argc, py_Ref argv)
{
int button_id;
Expand Down Expand Up @@ -104,6 +114,14 @@ static bool py_btnp(int argc, py_Ref argv)
return 1;
}

/*************TIC-80 MISC BEGIN****************/

static void throw_error(tic_core* core, const char* msg)
{
core->data->error(core->data->data, msg);

}

static bool bind_pkpy_v2()
{
py_GlobalRef mod = py_getmodule("__main__");
Expand All @@ -126,26 +144,138 @@ void close_pkpy_v2(tic_mem* tic)
static bool init_pkpy_v2(tic_mem* tic, const char *code)
{
//maybe some config here
//N._tic_core = py_name("_tic_core");
//N.len = py_name("len");
//N.__getitem__ = py_name("__getitem__");
//N.TIC = py_name("TIC");
//N.BOOT = py_name("BOOT");
//N.SCN = py_name("SCN");
//N.BDR = py_name("BDR");
//N.MENU = py_name("MENU");


tic_core* core = (tic_core*)tic;
close_pkpy_v2(tic);
py_initialize();
setup_core(core);
core->currentVM = pk_current_vm;
if (!bind_pkpy_v2())
{
//throw error

throw_error(core, "Binding func failed!");
return false;
}
if (!py_exec(code, "main.py", EXEC_MODE, NULL))
{
//throw error

throw_error(core, "Executing code failed!");
return false;
}
return true;
}

void tick_pkpy_v2(tic_mem* tic)
{
tic_core* core = (tic_core*)tic;
if (!core->currentVM) return;//no vm

py_GlobalRef py_tick = py_getglobal(N.TIC);
py_push(py_tick);
py_pushnil();
if (!py_vectorcall(0, 0))
{
throw_error(core, "TIC running error!");
}
else
{
auto test = py_retval();
}
}

void boot_pkpy_v2(tic_mem* tic)
{
tic_core* core = (tic_core*)tic;
if (!core->currentVM) return; //no vm

py_GlobalRef py_boot = py_getglobal(py_name("BOOT"));
py_push(py_boot);
py_pushnil();
if (!py_vectorcall(0, 0))
{
throw_error(core, "BOOT running error!");
}
else
{
auto test = py_retval();
}
}

void callback_scanline(tic_mem* tic, s32 row, void* data)
{
tic_core* core = (tic_core*)tic;
if (!core->currentVM) return; //no vm

py_GlobalRef py_scn = py_getglobal(py_name("SCN"));
py_push(py_scn);
py_pushnil();
py_Ref py_row = (py_Ref)malloc(sizeof(py_Ref));
py_newint(py_row, row);
py_push(py_row);
if (!py_vectorcall(1, 0))
{
throw_error(core, "SCANLINE running error!");
}
else
{
auto test = py_retval();
}
free(py_row);
}

void callback_border(tic_mem* tic, s32 row, void* data)
{
tic_core* core = (tic_core*)tic;
if (!core->currentVM) return; //no vm

py_GlobalRef py_bdr = py_getglobal(py_name("BDR"));
py_push(py_bdr);
py_pushnil();
py_Ref py_row = (py_Ref)malloc(sizeof(py_Ref));
py_newint(py_row, row);
py_push(py_row);
if (!py_vectorcall(1, 0))
{
throw_error(core, "BORDER running error!");
}
else
{
auto test = py_retval();
}
free(py_row);
}
void callback_menu(tic_mem* tic, s32 index, void* data)
{
tic_core* core = (tic_core*)tic;
if (!core->currentVM) return; //no vm

py_GlobalRef py_menu = py_getglobal(py_name("MENU"));
py_push(py_menu);
py_pushnil();
py_Ref py_idx = (py_Ref)malloc(sizeof(py_Ref));
py_newint(py_idx, index);
py_push(py_idx);
if (!py_vectorcall(1, 0))
{
throw_error(core, "MENU running error!");
}
else
{
auto test = py_retval();
}
free(py_idx);
}


static const char* const PythonKeywords[] =
{
"is not", "not in", "yield from",
Expand All @@ -171,19 +301,19 @@ TIC_EXPORT const tic_script EXPORT_SCRIPT(Python) =
.projectComment = "#",
.init = init_pkpy_v2,
.close = close_pkpy_v2,
.tick = NULL,
.boot = NULL,
.tick = tick_pkpy_v2,
.boot = boot_pkpy_v2,

.callback =
{
.scanline = NULL,
.border = NULL,
.menu = NULL,
.scanline = callback_scanline,
.border = callback_border,
.menu = callback_menu,
},

.getOutline = NULL,
.eval = NULL,

//above is a must need
.blockCommentStart = NULL,
.blockCommentEnd = NULL,
.blockCommentStart2 = NULL,
Expand Down