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

Upgrade Python language bindings to v1.2.x #2315

Merged
merged 33 commits into from
Oct 8, 2023
Merged

Conversation

blueloveTH
Copy link
Contributor

@blueloveTH blueloveTH commented Sep 27, 2023

Description

TIC-80's Python implementation, pocketpy v1.0.0 was a bit outdated.

I am upgrading the interpreter into the latest version v1.2.x. When this pr is completed, I will remove (WIP).

Related Issues

New Features Up to v1.2.x

Feature Description Version
(TIC-80's current) - 1.0.0
cascading assignment a=b=1 1.0.3
cascading comparasion a<b<c 1.0.3
keyword arguments def f(**kwargs): pass 1.0.3
unpacking builder for list/tuple/dict/set [*a, *b, 1, 2] 1.0.3
traceback module msg: str = traceback.format_exc() 1.0.3
1-element tuple (1,) 1.0.4
pickle module see pickle module 1.0.4
long type for arbitrary sized integers see long type 1.0.4
reversed operators __radd__, __rsub__, __rmul__ 1.0.4
cmake build support see CMakeLists.txt 1.0.9
dict remembers its insertion order behave the same as cpython 3.8+ 1.0.9
~ and @ operator a.k.a. __invert__ and __matmul__ 1.0.9
platform identifier support print(sys.platform) 1.0.9
bytes literal b'\xff\x12' 1.0.9
load dynamic module __import__('libtest.so') 1.0.9
colorsys module import colorsys 1.1.3
__all__ variable from xx import * will read __all__ if exists 1.1.3
optional box2d module see box2d module 1.1.3
line continuation character \ can be used for line continuation 1.1.4
for..else and while..else behave the same as cpython 1.1.6
improved import system relative/absolute import statements in directory and sub-directories 1.1.7
typing module from typing import List, Tuple, Any 1.1.8
datetime module get datetime of today and now 1.1.8
improved f-string support most of the f-string usages in cpython are added 1.2.0
super() shorthand support super().__init__(...) 1.2.0
improved type annotation most type annotations up to python 3.11 are added 1.2.0
64-bit integers int is always 64-bit, even in 32-bit platforms 1.2.1
float accuracy improvement with a new design, the accuracy of float was improved. 1.2.2
goto/label feature (stable) https://pocketpy.dev/features/goto/ 1.2.3
improved str.format '{k}={v}'.format(k='a', v=1) 1.2.4

The Cheatsheet

You can check this Cheatsheet for a quick overview of the supported features between cpython and pocketpy.

@blueloveTH blueloveTH mentioned this pull request Sep 28, 2023
@blueloveTH
Copy link
Contributor Author

This pr can solve #2296. Because v1.2.x implements automatic float cast inside the api.

@blueloveTH blueloveTH marked this pull request as ready for review September 28, 2023 03:37
@blueloveTH
Copy link
Contributor Author

blueloveTH commented Sep 28, 2023

All syntax errors were solved. The branch is able to pass all checks except windows-mingw.
Now it is time to review semantic issues for each functions. Add your reviews in this pr.

UPDATE:
windows-mingw build may fail due to lack of memory. So I made some changes in build.yml according to actions/runner-images#2642 (comment).

If you don't like it you can delete it.

@blueloveTH
Copy link
Contributor Author

blueloveTH commented Sep 28, 2023

Take this if you need a type annotation file for VSCode.

def btn(id: int) -> bool: ...
def btnp(id: int, hold=-1, period=-1) -> bool: ...
def circ(x: int, y: int, radius: int, color: int): ...
def circb(x: int, y: int, radius: int, color: int): ...
def clip(x: int, y: int, width: int, height: int): ...
def cls(color=0): ...
def elli(x: int, y: int, a: int, b: int, color: int): ...
def ellib(x: int, y: int, a: int, b: int, color: int): ...
def exit(): ...
def fget(sprite_id: int, flag: int) -> bool: ...
def fset(sprite_id: int, flag: int, b: bool): ...
def font(text: str, x: int, y: int, chromakey: int, char_width=8, char_height=8, fixed=False, scale=1, alt=False) -> int: ...
def key(code=-1) -> bool: ...
def keyp(code=-1, hold=-1, period=-17) -> int: ...
def line(x0: int, y0: int, x1: int, y1: int, color: int): ...
def map(x=0, y=0, w=30, h=17, sx=0, sy=0, colorkey=-1, scale=1, remap=None): ...
def memcpy(dest: int, source: int, size: int): ...
def memset(dest: int, value: int, size: int): ...
def mget(x: int, y: int) -> int: ...
def mset(x: int, y: int, tile_id: int): ...
def mouse() -> tuple[int, int, bool, bool, bool, int, int]: ...
def music(track=-1, frame=-1, row=-1, loop=True, sustain=False, tempo=-1, speed=-1): ...
def peek(addr: int, bits=8) -> int: ...
def peek1(addr: int) -> int: ...
def peek2(addr: int) -> int: ...
def peek4(addr: int) -> int: ...
def pix(x: int, y: int, color: int=None) -> int | None: ...
def pmem(index: int, value: int=None) -> int: ...
def poke(addr: int, value: int, bits=8): ...
def poke1(addr: int, value: int): ...
def poke2(addr: int, value: int): ...
def poke4(addr: int, value: int): ...
def print(text, x=0, y=0, color=15, fixed=False, scale=1, alt=False): ...
def rect(x: int, y: int, w: int, h: int, color: int): ...
def rectb(x: int, y: int, w: int, h: int, color: int): ...
def reset(): ...
def sfx(id: int, note=-1, duration=-1, channel=0, volume=15, speed=0): ...
def spr(id: int, x: int, y: int, colorkey=-1, scale=1, flip=0, rotate=0, w=1, h=1): ...
def sync(mask=0, bank=0, tocart=False): ...
def ttri(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, u1: float, v1: float, u2: float, v2: float, u3: float, v3: float, texsrc=0, chromakey=-1, z1=0.0, z2=0.0, z3=0.0): ...
def time() -> int: ...
def trace(message, color=15): ...
def tri(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, color: int): ...
def trib(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, color: int): ...
def tstamp() -> int: ...
def vbank(bank: int=None) -> int: ...

Update CMakeLists.txt

Update CMakeLists.txt
@blueloveTH
Copy link
Contributor Author

Done.

@blueloveTH blueloveTH changed the title Upgrade Python language bindings to v1.2.x (WIP) Upgrade Python language bindings to v1.2.x Sep 28, 2023
@Skeptim
Copy link
Contributor

Skeptim commented Sep 28, 2023

Hi,
Thanks a lot for your work, that's great to have python on TIC-80!
I quickly mentioned pocketpy on the wiki with a link to the documentation https://github.com/nesbox/TIC-80/wiki/supported-languages#python-integration but I don't know much about it.
Feel free to modify or add anything useful there.

@nesbox nesbox merged commit 6d6f8ae into nesbox:main Oct 8, 2023
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants