diff --git a/Apps/HelloWorld/main.vp b/Apps/HelloWorld/main.vp index c0b929e..a28c191 100644 --- a/Apps/HelloWorld/main.vp +++ b/Apps/HelloWorld/main.vp @@ -2,10 +2,7 @@ import vpsdk.vpui as vpui import vpsdk.window as window import vpsdk.process as process import vpsdk.dynlib as dynlib -import vpsdk.stdlib as stdlib -import vpsdk.stdio as stdio from stdint import * -import t, c @__attribute__(section(".text.startup"), aligned(16)) export def _start() -> int: @@ -33,7 +30,7 @@ export def _start() -> int: lbl: vpui.Label = vpui.Label(master, "Name:", 0xFFFFFFFF) root.pack(2, vpui.PACK_TOP, 0, 0, 20, 0) - btn: vpui.Button = vpui.Button(master, 100, 36, "Submit", &_on_submit) + btn: vpui.Button = vpui.Button(master, 100, 36, "Submit", _on_submit) root.pack(3, vpui.PACK_TOP, 0, 0, 0, 10) root2: vpui.Tk = vpui.Tk() diff --git a/Apps/Scene3D/gfx.vp b/Apps/Scene3D/gfx.vp index 337c512..94efd2e 100644 --- a/Apps/Scene3D/gfx.vp +++ b/Apps/Scene3D/gfx.vp @@ -1,17 +1,14 @@ -from stdint import * -import math import string -import t, c +import math -define PI = float(3.14159265358979323846) +define PI: float = 3.14159265358979323846 define SPHERE_SLICES = (24 * 1) define SPHERE_STACKS = (16 * 1) define SIN_WAVE_GRID = (40 * 1) -def COLOR_RGB(r: int, g: int, b: int) -> t.CInline | int: - return (255 << 24) | (r << 16) | (g << 8) | (b) +define COLOR_RGB(r: int, g: int, b: int) -> int: return (255 << 24) | (r << 16) | (g << 8) | (b) class Vec3: x: float @@ -32,7 +29,7 @@ class Vec3: return Vec3(self.x / l, self.y / l, self.z / l) class Mat4: - m: t.CArray[t.CArray[float, 4], 4] + m: [4][4]float def Mat4_Identity() -> Mat4: m: Mat4 = Mat4() @@ -90,31 +87,30 @@ def Mat4_RotateY(a: float) -> Mat4: class Surface: - fb: UINT32PTR + fb: uint32* zb: float* w: int h: int - def __init__(self, fb: UINT32PTR, zb: float*, w: int, h: int): + def __init__(self, fb: uint32*, zb: float*, w: int, h: int): self.fb = fb self.zb = zb self.w = w self.h = h -@t.Object class Renderer: - _fb: UINT32PTR + _fb: uint32* _zb: float* _w: int _h: int - def __init__(self, fb: UINT32PTR, zb: float*, w: int, h: int): + def __init__(self, fb: uint32*, zb: float*, w: int, h: int): self._fb = fb self._zb = zb self._w = w self._h = h def Clear(self, color: uint32): - fb: UINT32PTR = self._fb + fb: uint32* = self._fb zb: float* = self._zb size: int = self._w * self._h for i in range(size): @@ -125,7 +121,7 @@ class Renderer: zb[i] = float(2.0) def DrawLine2D(self, x0: int, y0: int, x1: int, y1: int, col: uint32): - fb: UINT32PTR = self._fb + fb: uint32* = self._fb w: int = self._w; h: int = self._h dx: int = abs(x1-x0); dy: int = abs(y1-y0) sx: int = 1 if x0 < x1 else -1; sy: int = 1 if y0 < y1 else -1 @@ -143,7 +139,7 @@ class Renderer: v1.x > float(10.0) or v1.x < float(-10.0) or v1.y > float(10.0) or v1.y < float(-10.0) or v2.x > float(10.0) or v2.x < float(-10.0) or v2.y > float(10.0) or v2.y < float(-10.0)): return - fb: UINT32PTR = self._fb + fb: uint32* = self._fb zb: float* = self._zb w: int = self._w h: int = self._h @@ -181,7 +177,7 @@ class Renderer: dxP += float(1.0) def DrawGlowDot(self, x: float, y: float, radius: float, core_col: uint32, intensity: float): - fb: UINT32PTR = self._fb; w: int = self._w; h: int = self._h + fb: uint32* = self._fb; w: int = self._w; h: int = self._h r: int = int(radius) + 4 ix: int = int(x); iy: int = int(y) for dy in range(-r, r + 1): @@ -199,7 +195,7 @@ class Renderer: def BlendPixel(self, x: int, y: int, col: uint32, alpha: float): if alpha <= 0.0: return - fb: UINT32PTR = self._fb; w: int = self._w; h: int = self._h + fb: uint32* = self._fb; w: int = self._w; h: int = self._h if x < 0 or x >= w or y < 0 or y >= h: return idx: int = y * w + x @@ -218,11 +214,10 @@ class Renderer: 255 if (nb > 255) else nb) -@t.Object class Scene3D: renderer: Renderer - def __init__(self, fb: UINT32PTR, zb: float*, w: int, h: int): + def __init__(self, fb: uint32*, zb: float*, w: int, h: int): self.renderer = Renderer(fb, zb, w, h) def Render(self, time: float): @@ -241,7 +236,7 @@ class Scene3D: cubeMVP: Mat4 = Mat4_Mul(vp, Mat4_Translate(cubeX, 0, 0)) self._DrawCube(cubeMVP, COLOR_RGB(180, 180, 180)) - colors: t.CArray[uint32, 4] = [COLOR_RGB(255,50,50), COLOR_RGB(50,50,255), COLOR_RGB(255,255,50), COLOR_RGB(50,255,255)] + colors: [4]uint32 = [COLOR_RGB(255,50,50), COLOR_RGB(50,50,255), COLOR_RGB(255,255,50), COLOR_RGB(50,255,255)] for i in range(4): a: float = time * float(1.5) + i * (PI / float(2.0)); r: float = float(3.0) pos: Vec3 = Vec3(math.cosf(a) * r + cubeX, 0, math.sinf(a) * r) @@ -261,12 +256,12 @@ class Scene3D: prev_x = cx; prev_y = cy def _DrawCube(self, mvp: Mat4, col: uint32): - v: t.CArray[Vec3, 8] = [ + v: [8]Vec3 = [ Vec3(-1, -1, -1), Vec3(-1, -1, 1), Vec3(-1, 1, -1), Vec3(-1, 1, 1), Vec3( 1, -1, -1), Vec3( 1, -1, 1), Vec3( 1, 1, -1), Vec3( 1, 1, 1) ] for i in range(8): v[i] = Mat4_MulVec(mvp, v[i]) - faces: t.CArray[t.CArray[int, 3], 12] = [ + faces: [12][3]int = [ [0, 2, 1], [1, 2, 3], [4, 1, 5], [4, 0, 1], [6, 3, 2], [6, 7, 3], [4, 6, 0], [0, 6, 2], [5, 7, 4], [4, 7, 6], [1, 3, 5], [5, 3, 7] ] @@ -278,7 +273,7 @@ class Scene3D: for j in range(SPHERE_SLICES): theta1: float = i * step_pi; theta2: float = (i + 1) * step_pi phi1: float = j * step_2pi; phi2: float = (j + 1) * step_2pi - v: t.CArray[Vec3, 4] + v: [4]Vec3 = [] v[0] = Vec3(center.x+radius*math.sinf(theta1)*math.cosf(phi1), center.y+radius*math.cosf(theta1), center.z+radius*math.sinf(theta1)*math.sinf(phi1)) v[1] = Vec3(center.x+radius*math.sinf(theta1)*math.cosf(phi2), center.y+radius*math.cosf(theta1), center.z+radius*math.sinf(theta1)*math.sinf(phi2)) v[2] = Vec3(center.x+radius*math.sinf(theta2)*math.cosf(phi1), center.y+radius*math.cosf(theta2), center.z+radius*math.sinf(theta2)*math.sinf(phi1)) diff --git a/Apps/Scene3D/main.vp b/Apps/Scene3D/main.vp index f1146f1..4b8903a 100644 --- a/Apps/Scene3D/main.vp +++ b/Apps/Scene3D/main.vp @@ -1,20 +1,15 @@ import vpsdk.window as window import vpsdk.process as process import vpsdk.vpui as vpui -import vpsdk.stdlib as stdlib -import vpsdk.stdio as stdio -import vpsdk.syscall as syscall import string -import math from stdint import * import gfx -import t, c define SCENE_W = 640 define SCENE_H = 360 -_zbuf_mem: t.CArray[uint8, SCENE_W * SCENE_H * 8] -_fb_mem: t.CArray[uint32, SCENE_W * SCENE_H] +_zbuf_mem: [SCENE_W * SCENE_H * 8]uint8 = [] +_fb_mem: [SCENE_W * SCENE_H]uint32 = [] _root_ptr: vpui.Tk* _canvas_ptr: vpui.FBCanvas* @@ -25,26 +20,6 @@ _time_val: float = float(0.0) # (x 变大后相邻采样点的相位差被量化 ⇒ 曲线塌成一条平线、热力图颜色失去层次)。 define TIME_WRAP = float(12.566370614359172) -# [临时探针] 每帧打印 time 与两个 sinf 采样值的位模式: -# 正常时 a/b 随 time 变化且互不相同;"曲线变平"时应能看到 a==b(相位被量化)或三者一起冻结。定位后删除。 -_tk_hex: t.CArray[char, 17] = "0123456789ABCDEF" - -def _dbg_puts(s: const str): - syscall._syscall1(uint64(syscall.SERIAL_PUTS), uint64(s)) - -def _dbg_hex32(slot: char, val: uint32): - buf: t.CArray[char, 12] - buf[0] = slot - buf[1] = '=' - i: int = 7 - while i >= 0: - buf[2 + i] = _tk_hex[int(val & uint32(0xF))] - val = val >> 4 - i -= 1 - buf[10] = ' ' - buf[11] = 0 - _dbg_puts(&buf[0]) - def _render_thread(arg: t.CPtr): global _time_val root: vpui.Tk* = _root_ptr @@ -56,18 +31,9 @@ def _render_thread(arg: t.CPtr): if _time_val >= TIME_WRAP: _time_val = _time_val - TIME_WRAP root.update() process.yield_cpu() - # [临时探针] 每帧打印:time / sinf(0.5-ws) / sinf(3.0-ws) 的位模式(定位后删除) - ws: float = _time_val * float(2.0) - sa: float = math.sinf(float(0.5) - ws) - sb: float = math.sinf(float(3.0) - ws) - _dbg_puts("[s3d] ") - _dbg_hex32('t', *(uint32*(&_time_val))) - _dbg_hex32('a', *(uint32*(&sa))) - _dbg_hex32('b', *(uint32*(&sb))) - _dbg_puts("\n") -@c.Attribute(t.attr.section(".text.startup"), t.attr.aligned(16)) -def _start() -> int | t.CExport: +@__attribute__(section(".text.startup"), aligned(16)) +export def _start() -> int: root: vpui.Tk = vpui.Tk() root.title("3D Scene") root.set_style(window.STYLE_WIN11) diff --git a/Apps/Terminal/main.vp b/Apps/Terminal/main.vp index 102b6f1..21a513a 100644 --- a/Apps/Terminal/main.vp +++ b/Apps/Terminal/main.vp @@ -10,8 +10,8 @@ import viperlib from stdint import * import t, c -@c.Attribute(t.attr.section(".text.startup"), t.attr.aligned(16)) -def _start() -> int | t.CExport: +@__attribute__(section(".text.startup"), aligned(16)) +export def _start() -> int: root: vpui.Tk = vpui.Tk() root.title("Terminal") root.set_style(window.STYLE_WIN7) @@ -24,7 +24,7 @@ def _start() -> int | t.CExport: _sdbg("[term] start\n") - _cwd: t.CArray[char, 64] + _cwd: [64]char _cwd[0] = 47 for i in range(1, 64): _cwd[i] = 0 @@ -38,7 +38,7 @@ def _start() -> int | t.CExport: term.insert("Type 'help' for commands.") term.insert("") - term.yscrollbar = t.CType(sbar, vpui.Widget, t.CPtr) + term.yscrollbar = vpui.Widget*(sbar) def _on_scroll(): act: int = sbar.action @@ -63,7 +63,7 @@ def _start() -> int | t.CExport: if term.scroll_offset > max_off: term.scroll_offset = max_off term._update_scrollbar() - sbar.command = &_on_scroll + sbar.command = _on_scroll def _startswith(s: str, prefix: str) -> int: plen: sizet = string.strlen(prefix) @@ -78,21 +78,21 @@ def _start() -> int | t.CExport: i: int = 0 for i in range(63): ch: char = _cwd[i] - c.DerefAs(out + i, ch) + *(out + i) = ch if ch == 0: break cwd_len: int = i if cwd_len > 0 and _cwd[cwd_len - 1] != 47: - c.DerefAs(out + cwd_len, char(47)) + *(out + cwd_len) = char(47) cwd_len += 1 j: int = 0 for j in range(out_size - 1 - cwd_len): ch2: char = *(rel + j) - c.DerefAs(out + cwd_len + j, ch2) + *(out + cwd_len + j) = ch2 if ch2 == 0: break - c.DerefAs(out + out_size - 1, char(0)) + *(out + out_size - 1) = char(0) def _print_dir_entry(name: str, is_dir: int): - buf: t.CArray[char, 80] + buf: [80]char j: int = 0 for j in range(78): ch: char = *(name + j) @@ -110,7 +110,7 @@ def _start() -> int | t.CExport: for i in range(1, 64): _cwd[i] = 0 return - full: t.CArray[char, 256] + full: [256]char _build_path(&full[0], 256, path) dd: int = fs.opendir(&full[0]) if dd < 0: @@ -125,7 +125,7 @@ def _start() -> int | t.CExport: if dd < 0: term.insert("Error: cannot open dir") return - info: t.CArray[char, 320] + info: [320]char string.memset(&info[0], 0, 320) while True: result: int = fs.readdir(dd, &info[0]) @@ -149,13 +149,13 @@ def _start() -> int | t.CExport: fs.closedir(dd) def _cmd_cat(path: str): - full: t.CArray[char, 256] + full: [256]char _build_path(&full[0], 256, path) fd: int = fs.open(&full[0], fs.O_RDONLY) if fd < 0: term.insert("Error: file not found") return - buf: t.CArray[char, 80] + buf: [80]char while True: string.memset(&buf[0], 0, 80) n: int = fs.read(fd, &buf[0], 78) @@ -166,7 +166,7 @@ def _start() -> int | t.CExport: fs.close(fd) def _cmd_mkdir(path: str): - full: t.CArray[char, 256] + full: [256]char _build_path(&full[0], 256, path) result: int = fs.mkdir(&full[0]) if result < 0: @@ -175,7 +175,7 @@ def _start() -> int | t.CExport: term.insert("Directory created") def _cmd_rm(path: str): - full: t.CArray[char, 256] + full: [256]char _build_path(&full[0], 256, path) result: int = fs.remove(&full[0]) if result < 0: @@ -184,7 +184,7 @@ def _start() -> int | t.CExport: term.insert("Removed") def _cmd_touch(path: str): - full: t.CArray[char, 256] + full: [256]char _build_path(&full[0], 256, path) fd: int = fs.open(&full[0], fs.O_WRONLY | fs.O_CREAT) if fd < 0: @@ -199,20 +199,20 @@ def _start() -> int | t.CExport: term.insert("Compiler: TransPyC") def _cmd_hexdump(path: str): - full: t.CArray[char, 256] + full: [256]char _build_path(&full[0], 256, path) fd: int = fs.open(&full[0], fs.O_RDONLY) if fd < 0: term.insert("Error: file not found") return offset: int = 0 - buf: t.CArray[char, 16] + buf: [16]char while True: string.memset(&buf[0], 0, 16) n: int = fs.read(fd, &buf[0], 16) if n <= 0: break if n > 16: n = 16 - line: t.CArray[char, 80] + line: [80]char string.memset(&line[0], 0, 80) viperlib.snprintf(&line[0], 80, "%08x: ", offset) pos: int = 10 @@ -257,7 +257,7 @@ def _start() -> int | t.CExport: fs.close(fd) def _cmd_run(path: str, blocking: int): - full: t.CArray[char, 256] + full: [256]char _build_path(&full[0], 256, path) pid: int = process.spawn(&full[0], blocking) if pid < 0: @@ -265,7 +265,7 @@ def _start() -> int | t.CExport: elif blocking: term.insert("Process exited") else: - msg: t.CArray[char, 32] + msg: [32]char viperlib.snprintf(&msg[0], 32, "Spawned pid=%d", pid) term.insert_ptr(&msg[0]) @@ -320,7 +320,7 @@ def _start() -> int | t.CExport: term.insert("Unknown command. Type 'help'.") return 0 - term.on_command = &_on_command + term.on_command = _on_command root.mainloop() process.exit(0) diff --git a/vpsdk/dynlib.vp b/vpsdk/dynlib.vp index dc84f1f..7b49803 100644 --- a/vpsdk/dynlib.vp +++ b/vpsdk/dynlib.vp @@ -1,6 +1,6 @@ -import t, c from . import syscall as syscall + def load_so(path: const str) -> uint64: return syscall._syscall1(uint64(syscall.LOAD_SO), uint64(path)) diff --git a/vpsdk/fs.vp b/vpsdk/fs.vp index 057b632..6555f42 100644 --- a/vpsdk/fs.vp +++ b/vpsdk/fs.vp @@ -1,6 +1,6 @@ -import t, c from . import syscall as syscall + define O_RDONLY = 0x01 define O_WRONLY = 0x02 define O_RDWR = 0x03 @@ -22,10 +22,10 @@ def open(path: const str, flags: uint32) -> int: def close(fd: int) -> int: return int(syscall._syscall1(uint64(syscall.CLOSE), uint64(fd))) -def read(fd: int, buf: t.CPtr, count: uint32) -> int: +def read(fd: int, buf: rawptr, count: uint32) -> int: return int(syscall._syscall3(uint64(syscall.READ), uint64(fd), uint64(buf), uint64(count))) -def write(fd: int, buf: t.CPtr, count: uint32) -> int: +def write(fd: int, buf: rawptr, count: uint32) -> int: return int(syscall._syscall3(uint64(syscall.WRITE), uint64(fd), uint64(buf), uint64(count))) def seek(fd: int, offset: uint32) -> int: @@ -46,16 +46,15 @@ def remove(path: const str) -> int: def opendir(path: const str) -> int: return int(syscall._syscall3(uint64(syscall.OPENDIR), uint64(path), 0, 0)) -def readdir(dd: int, info: t.CPtr) -> int: +def readdir(dd: int, info: rawptr) -> int: return int(syscall._syscall3(uint64(syscall.READDIR), uint64(dd), uint64(info), 0)) def closedir(dd: int) -> int: return int(syscall._syscall1(uint64(syscall.CLOSEDIR), uint64(dd))) -def stat(path: const str, info: t.CPtr) -> int: +def stat(path: const str, info: rawptr) -> int: return int(syscall._syscall3(uint64(syscall.STAT), uint64(path), uint64(info), 0)) -@t.Object class FileIO: _fd: int _pos: uint32 @@ -70,14 +69,14 @@ class FileIO: self._size = fsize(fd) self._closed = 0 - def read(self, buf: t.CPtr, count: uint32) -> int: + def read(self, buf: rawptr, count: uint32) -> int: if self._closed: return -1 n: int = read(self._fd, buf, count) if n > 0: self._pos = self._pos + uint32(n) return n - def write(self, buf: t.CPtr, count: uint32) -> int: + def write(self, buf: rawptr, count: uint32) -> int: if self._closed: return -1 n: int = write(self._fd, buf, count) if n > 0: @@ -107,7 +106,6 @@ class FileIO: def is_closed(self) -> int: return self._closed -@t.Object class DirIO: _dd: int _closed: int @@ -116,7 +114,7 @@ class DirIO: self._dd = dd self._closed = 0 - def read(self, info: t.CPtr) -> int: + def read(self, info: rawptr) -> int: if self._closed: return -1 return readdir(self._dd, info) @@ -128,14 +126,12 @@ class DirIO: def is_closed(self) -> int: return self._closed -def open_file(path: const str, flags: uint32) -> FileIO*: +def open_file(path: const str, flags: uint32) -> FileIO: fd: int = open(path, flags) - if fd < 0: - return None + if fd < 0: return None return FileIO(fd, flags) -def open_dir(path: const str) -> DirIO*: +def open_dir(path: const str) -> DirIO: dd: int = opendir(path) - if dd < 0: - return None + if dd < 0: return None return DirIO(dd) diff --git a/vpsdk/process.vp b/vpsdk/process.vp index 51894f2..83bd3d4 100644 --- a/vpsdk/process.vp +++ b/vpsdk/process.vp @@ -1,6 +1,6 @@ -import t, c from . import syscall as syscall + def exit(code: int): syscall._syscall1(uint64(syscall.EXIT), uint64(code)) @@ -14,17 +14,17 @@ def yield_cpu(): def spawn(path: const str, blocking: int = 0) -> int: return int(syscall._syscall2(uint64(syscall.SPAWN), uint64(path), uint64(blocking))) -def thread_create(func: t.CPtr, arg: t.CPtr = None) -> int: +def thread_create(func: rawptr, arg: rawptr = None) -> int: return int(syscall._syscall2(uint64(syscall.THREAD_CREATE), uint64(func), uint64(arg))) -@t.Object + class Thread: _tid: int - _func: t.CPtr - _arg: t.CPtr + _func: rawptr + _arg: rawptr _running: int - def __init__(self, func: t.CPtr, arg: t.CPtr = None): + def __init__(self, func: rawptr, arg: rawptr = None): self._func = func self._arg = arg self._tid = -1 @@ -43,10 +43,10 @@ class Thread: def get_tid(self) -> int: return self._tid -@t.Object + class Process: _pid: int - _path: t.CArray[char, 128] + _path: [128]char def __init__(self, path: const str): self._pid = -1 diff --git a/vpsdk/stdio.vp b/vpsdk/stdio.vp index d223ff9..29fd1da 100644 --- a/vpsdk/stdio.vp +++ b/vpsdk/stdio.vp @@ -1,5 +1,4 @@ import vpsdk.syscall as _syscall -import t, c import viperlib # ============================================================ @@ -14,7 +13,7 @@ export def printf(fmt: const str, *args) -> int: """格式化输出到串口(SERIAL_PUTS syscall),返回输出字节数""" if fmt is None: return 0 - buf: t.CArray[char, 1024] + buf: [1024]char n: int = viperlib.vsnprintf(&buf, 1024, fmt, args) _syscall._syscall1(uint64(_syscall.SERIAL_PUTS), uint64(&buf)) return n @@ -24,7 +23,7 @@ export def exit(status: int): _syscall._syscall1(uint64(_syscall.EXIT), uint64(status)) -export def fflush(stream: const t.CPtr) -> int: +export def fflush(stream: const rawptr) -> int: """刷新输出流:串口/控制台输出都是直写,无缓冲可刷,空操作返回 0 覆盖 libc fflush 的裸机缺失(includes/memhub.vp 的诊断/终止路径 call @fflush); diff --git a/vpsdk/syscall.vp b/vpsdk/syscall.vp index 3c97293..bafcbff 100644 --- a/vpsdk/syscall.vp +++ b/vpsdk/syscall.vp @@ -1,5 +1,3 @@ -import t, c - define CREATE_WINDOW = 1 define DRAW_TEXT = 2 define EXIT = 3 @@ -33,7 +31,7 @@ define MMAP = 29 define MUNMAP = 30 define SET_RESIZABLE = 31 define GET_WIN_SIZE = 32 -define THREAD_CREATE = 33 +define THREAD_CREATE = 33 define THREAD_EXIT = 34 # SYSCALL_* 别名(vpsdk.stdlib 等模块引用;数值与内核 VKernel/intr/syscall.vp 一致) @@ -41,78 +39,78 @@ define SYSCALL_MMAP = 29 def _syscall0(num: uint64) -> uint64: ret: uint64 - c.Asm(f"""mov rax, {c.AsmInp(num, t.ASM_DESCR.REG_ANY)} + __asm__(f"""mov rax, {asminp(num, ASM_DESCR.REG_ANY)} syscall""", - out=[asmout(ret, t.ASM_DESCR.OUTPUT_REG)], - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RCX, - t.ASM_DESCR.CLOBBER_R11]) + out=[asmout(ret, ASM_DESCR.OUTPUT_REG)], + op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX, + ASM_DESCR.CLOBBER_R11]) return ret def _syscall1(num: uint64, a1: uint64) -> uint64: ret: uint64 - c.Asm(f"""mov rdi, {c.AsmInp(a1, t.ASM_DESCR.REG_ANY)} - mov rax, {c.AsmInp(num, t.ASM_DESCR.REG_ANY)} + __asm__(f"""mov rdi, {asminp(a1, ASM_DESCR.REG_ANY)} + mov rax, {asminp(num, ASM_DESCR.REG_ANY)} syscall""", - out=[asmout(ret, t.ASM_DESCR.OUTPUT_REG)], - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RCX, - t.ASM_DESCR.CLOBBER_R11, t.ASM_DESCR.CLOBBER_RDI]) + out=[asmout(ret, ASM_DESCR.OUTPUT_REG)], + op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX, + ASM_DESCR.CLOBBER_R11, ASM_DESCR.CLOBBER_RDI]) return ret def _syscall2(num: uint64, a1: uint64, a2: uint64) -> uint64: ret: uint64 - c.Asm(f"""mov rdi, {c.AsmInp(a1, t.ASM_DESCR.REG_ANY)} - mov rsi, {c.AsmInp(a2, t.ASM_DESCR.REG_ANY)} - mov rax, {c.AsmInp(num, t.ASM_DESCR.REG_ANY)} + __asm__(f"""mov rdi, {asminp(a1, ASM_DESCR.REG_ANY)} + mov rsi, {asminp(a2, ASM_DESCR.REG_ANY)} + mov rax, {asminp(num, ASM_DESCR.REG_ANY)} syscall""", - out=[asmout(ret, t.ASM_DESCR.OUTPUT_REG)], - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RCX, - t.ASM_DESCR.CLOBBER_R11, t.ASM_DESCR.CLOBBER_RDI, - t.ASM_DESCR.CLOBBER_RSI]) + out=[asmout(ret, ASM_DESCR.OUTPUT_REG)], + op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX, + ASM_DESCR.CLOBBER_R11, ASM_DESCR.CLOBBER_RDI, + ASM_DESCR.CLOBBER_RSI]) return ret def _syscall3(num: uint64, a1: uint64, a2: uint64, a3: uint64) -> uint64: ret: uint64 - c.Asm(f"""mov rdi, {c.AsmInp(a1, t.ASM_DESCR.REG_ANY)} - mov rsi, {c.AsmInp(a2, t.ASM_DESCR.REG_ANY)} - mov rdx, {c.AsmInp(a3, t.ASM_DESCR.REG_ANY)} - mov rax, {c.AsmInp(num, t.ASM_DESCR.REG_ANY)} + __asm__(f"""mov rdi, {asminp(a1, ASM_DESCR.REG_ANY)} + mov rsi, {asminp(a2, ASM_DESCR.REG_ANY)} + mov rdx, {asminp(a3, ASM_DESCR.REG_ANY)} + mov rax, {asminp(num, ASM_DESCR.REG_ANY)} syscall""", - out=[asmout(ret, t.ASM_DESCR.OUTPUT_REG)], - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RCX, - t.ASM_DESCR.CLOBBER_R11, t.ASM_DESCR.CLOBBER_RDI, - t.ASM_DESCR.CLOBBER_RSI, t.ASM_DESCR.CLOBBER_RDX]) + out=[asmout(ret, ASM_DESCR.OUTPUT_REG)], + op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX, + ASM_DESCR.CLOBBER_R11, ASM_DESCR.CLOBBER_RDI, + ASM_DESCR.CLOBBER_RSI, ASM_DESCR.CLOBBER_RDX]) return ret def _syscall5(num: uint64, a1: uint64, a2: uint64, a3: uint64, a4: uint64, a5: uint64) -> uint64: ret: uint64 - c.Asm(f"""mov rdi, {c.AsmInp(a1, t.ASM_DESCR.REG_ANY)} - mov rsi, {c.AsmInp(a2, t.ASM_DESCR.REG_ANY)} - mov rdx, {c.AsmInp(a3, t.ASM_DESCR.REG_ANY)} - mov r10, {c.AsmInp(a4, t.ASM_DESCR.REG_ANY)} - mov r8, {c.AsmInp(a5, t.ASM_DESCR.REG_ANY)} - mov rax, {c.AsmInp(num, t.ASM_DESCR.REG_ANY)} + __asm__(f"""mov rdi, {asminp(a1, ASM_DESCR.REG_ANY)} + mov rsi, {asminp(a2, ASM_DESCR.REG_ANY)} + mov rdx, {asminp(a3, ASM_DESCR.REG_ANY)} + mov r10, {asminp(a4, ASM_DESCR.REG_ANY)} + mov r8, {asminp(a5, ASM_DESCR.REG_ANY)} + mov rax, {asminp(num, ASM_DESCR.REG_ANY)} syscall""", - out=[asmout(ret, t.ASM_DESCR.OUTPUT_REG)], - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RCX, - t.ASM_DESCR.CLOBBER_R11, t.ASM_DESCR.CLOBBER_RDI, - t.ASM_DESCR.CLOBBER_RSI, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R8]) + out=[asmout(ret, ASM_DESCR.OUTPUT_REG)], + op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX, + ASM_DESCR.CLOBBER_R11, ASM_DESCR.CLOBBER_RDI, + ASM_DESCR.CLOBBER_RSI, ASM_DESCR.CLOBBER_RDX, + ASM_DESCR.CLOBBER_R10, ASM_DESCR.CLOBBER_R8]) return ret def _syscall6(num: uint64, a1: uint64, a2: uint64, a3: uint64, a4: uint64, a5: uint64, a6: uint64) -> uint64: ret: uint64 - c.Asm(f"""mov rdi, {c.AsmInp(a1, t.ASM_DESCR.REG_ANY)} - mov rsi, {c.AsmInp(a2, t.ASM_DESCR.REG_ANY)} - mov rdx, {c.AsmInp(a3, t.ASM_DESCR.REG_ANY)} - mov r10, {c.AsmInp(a4, t.ASM_DESCR.REG_ANY)} - mov r8, {c.AsmInp(a5, t.ASM_DESCR.REG_ANY)} - mov r9, {c.AsmInp(a6, t.ASM_DESCR.REG_ANY)} - mov rax, {c.AsmInp(num, t.ASM_DESCR.REG_ANY)} + __asm__(f"""mov rdi, {asminp(a1, ASM_DESCR.REG_ANY)} + mov rsi, {asminp(a2, ASM_DESCR.REG_ANY)} + mov rdx, {asminp(a3, ASM_DESCR.REG_ANY)} + mov r10, {asminp(a4, ASM_DESCR.REG_ANY)} + mov r8, {asminp(a5, ASM_DESCR.REG_ANY)} + mov r9, {asminp(a6, ASM_DESCR.REG_ANY)} + mov rax, {asminp(num, ASM_DESCR.REG_ANY)} syscall""", - out=[asmout(ret, t.ASM_DESCR.OUTPUT_REG)], - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RCX, - t.ASM_DESCR.CLOBBER_R11, t.ASM_DESCR.CLOBBER_RDI, - t.ASM_DESCR.CLOBBER_RSI, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R8, - t.ASM_DESCR.CLOBBER_R9]) + out=[asmout(ret, ASM_DESCR.OUTPUT_REG)], + op=[ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RCX, + ASM_DESCR.CLOBBER_R11, ASM_DESCR.CLOBBER_RDI, + ASM_DESCR.CLOBBER_RSI, ASM_DESCR.CLOBBER_RDX, + ASM_DESCR.CLOBBER_R10, ASM_DESCR.CLOBBER_R8, + ASM_DESCR.CLOBBER_R9]) return ret diff --git a/vpsdk/window.vp b/vpsdk/window.vp index 20b2287..a72387e 100644 --- a/vpsdk/window.vp +++ b/vpsdk/window.vp @@ -1,7 +1,6 @@ -import t, c from . import syscall as syscall import vpsdk.stdlib as stdlib -from stdint import * + define STYLE_CLASSIC = 0 define STYLE_WIN10 = 1 @@ -39,9 +38,8 @@ define VK_DELETE = -7 define VK_PRIOR = -8 define VK_NEXT = -9 -@c.Attribute(t.attr.packed) -@t.Object -class InputEvent: +@__attribute__(packed) +struct InputEvent: type: uint32 win_id: int x: int @@ -64,21 +62,21 @@ def draw_text(win_id: int, x: int, y: int, text: const str, color: uint32) -> in # 让缓冲只有几字节,随后内核 memcpy 240KB 就会越界读(三重故障的根)。4MB。 define WINBUF_MAX_BYTES = 4194304 -_winbufs: t.CArray[uint64, 64] +_winbufs: [64]uint64 -def get_winbuf(win_id: int) -> UINT32PTR: +def get_winbuf(win_id: int) -> uint32*: if win_id < 0 or win_id >= 64: return None if _winbufs[win_id] == 0: - p: t.CPtr = stdlib.malloc(WINBUF_MAX_BYTES) + p: rawptr = stdlib.malloc(WINBUF_MAX_BYTES) if p is None: return None _winbufs[win_id] = uint64(p) - return t.CPtr(_winbufs[win_id]) + return uint32*(_winbufs[win_id]) def get_win_size(win_id: int) -> int: return int(syscall._syscall2(uint64(syscall.GET_WIN_SIZE), uint64(win_id), 0)) def flush(win_id: int): - buf: UINT32PTR = get_winbuf(win_id) # 确保缓冲已分配 + buf: uint32* = get_winbuf(win_id) syscall._syscall3(uint64(syscall.WIN_FLUSH), uint64(win_id), uint64(buf)) def mainloop(win_id: int):