diff --git a/.vscodeignore b/.vscodeignore new file mode 100644 index 00000000..3c726a37 --- /dev/null +++ b/.vscodeignore @@ -0,0 +1,149 @@ +.git +.github +.vscode +node_modules +src +tsconfig.json +*.md +*.log + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +*.vsix +junit.xml + +.webpack_cache/ + +# OS files +.DS_Store +Thumbs.db + +# Potential venv +.venv + +# Agent files +serena/ +.beads/ +AGENTS.md + +# Generated benchmark output +packages/pyright-internal/src/tests/benchmarks/.generated/ + +# perfCompare.py cached commit bundles +/build/perfCompare/ + diff --git a/Test/Kernel/drivers/core/cpu/apic.vp b/Test/Kernel/drivers/core/cpu/apic.vp deleted file mode 100644 index 6bbd49aa..00000000 --- a/Test/Kernel/drivers/core/cpu/apic.vp +++ /dev/null @@ -1,251 +0,0 @@ -import asm -import intr.gdt as gdt -import intr.idt as idt -import drivers.serial.uart.serial as serial -import drivers.core.cpu.cpu as cpu -import mm.mm as mm -import platform.pch.timer as timer -import viperlib -import t, c - - -IA32_APIC_BASE: t.CDefine = 0x1B -APIC_BASE_MSR_ENABLE: t.CDefine = 0x800 -APIC_BASE_ADDR_MASK: t.CDefine = 0xFFFFF000 - -LAPIC_ID: t.CDefine = 0x020 -LAPIC_VERSION: t.CDefine = 0x030 -LAPIC_TPR: t.CDefine = 0x080 -LAPIC_EOI: t.CDefine = 0x0B0 -LAPIC_LDR: t.CDefine = 0x0D0 -LAPIC_SVR: t.CDefine = 0x0F0 -LAPIC_ISR0: t.CDefine = 0x100 -LAPIC_ICR_LOW: t.CDefine = 0x300 -LAPIC_ICR_HIGH: t.CDefine = 0x310 -LAPIC_LVT_TIMER: t.CDefine = 0x320 -LAPIC_LVT_LINT0: t.CDefine = 0x350 -LAPIC_LVT_LINT1: t.CDefine = 0x360 -LAPIC_LVT_ERROR: t.CDefine = 0x370 -LAPIC_TIMER_INIT: t.CDefine = 0x380 -LAPIC_TIMER_CURRENT: t.CDefine = 0x390 -LAPIC_TIMER_DIVIDE: t.CDefine = 0x3E0 - -LAPIC_SVR_ENABLE: t.CDefine = 0x100 -LAPIC_LVT_MASKED: t.CDefine = 0x10000 -LAPIC_LVT_DELIVERY_EXTINT: t.CDefine = 0x700 -LAPIC_LVT_DELIVERY_NMI: t.CDefine = 0x400 -LAPIC_LVT_TIMER_PERIODIC: t.CDefine = 0x20000 - -LAPIC_ICR_INIT: t.CDefine = 0x500 -LAPIC_ICR_STARTUP: t.CDefine = 0x600 -LAPIC_ICR_ASSERT: t.CDefine = 0x4000 -LAPIC_ICR_DEASSERT: t.CDefine = 0x8000 -LAPIC_ICR_LEVEL: t.CDefine = 0x8000 - -MAX_CPUS: t.CDefine = 8 -AP_TRAMPOLINE_ADDR: t.CDefine = 0x7000 - -_lapic_base: t.CStatic | t.CUInt64T = 0 -_cpu_count: t.CStatic | t.CUInt32T = 1 -_bsp_lapic_id: t.CStatic | t.CUInt32T = 0 -_ap_ready: t.CStatic | t.CUInt32T = 0 - -def read(offset: t.CUInt32T) -> t.CUInt32T: - addr: t.CUInt64T = _lapic_base + t.CUInt64T(offset) - return c.Deref(t.CUInt32T(addr, t.CPtr)) - -def write(offset: t.CUInt32T, value: t.CUInt32T): - addr: t.CUInt64T = _lapic_base + t.CUInt64T(offset) - c.Set(c.Deref(t.CUInt32T(addr, t.CPtr)), value) - -def eoi(): - write(LAPIC_EOI, 0) - -def get_id() -> t.CUInt32T: - return read(LAPIC_ID) >> 24 - -@c.Attribute(t.attr.noinline) -def init(): - global _lapic_base, _bsp_lapic_id - msr_val: t.CUInt64T = cpu.msr_read(IA32_APIC_BASE) - _lapic_base = msr_val & APIC_BASE_ADDR_MASK - cpu.msr_write(IA32_APIC_BASE, msr_val | APIC_BASE_MSR_ENABLE) - _bsp_lapic_id = read(LAPIC_ID) >> 24 - write(LAPIC_SVR, LAPIC_SVR_ENABLE | 0xFF) - write(LAPIC_TPR, 0) - write(LAPIC_LVT_TIMER, LAPIC_LVT_MASKED) - write(LAPIC_LVT_LINT0, LAPIC_LVT_DELIVERY_EXTINT) - write(LAPIC_LVT_LINT1, LAPIC_LVT_DELIVERY_NMI) - write(LAPIC_LVT_ERROR, LAPIC_LVT_MASKED) - write(LAPIC_TIMER_DIVIDE, 0x0B) - write(LAPIC_LDR, 0x01000000) - eoi() - -@c.Attribute(t.attr.noinline) -def detect_cpu_count() -> t.CUInt32T: - res: cpu.cpuid_result - cpu.cpuid(0, c.Addr(res)) - max_leaf: t.CUInt32T = res.eax - - if max_leaf >= 0x0B: - cpu.cpuid_sub(0x0B, 0, c.Addr(res)) - num_threads: t.CUInt32T = res.ebx & 0xFFFF - if num_threads > 0 and num_threads <= MAX_CPUS: - return num_threads - - cpu.cpuid(1, c.Addr(res)) - if res.edx & cpu.CPU_FEATURE_HTT: - count: t.CUInt32T = (res.ebx >> 16) & 0xFF - if count > 0 and count <= MAX_CPUS: - return count - return 1 - -def _wait_icr(): - timeout: t.CUInt32T = 1000000 - while timeout > 0: - val: t.CUInt32T = read(LAPIC_ICR_LOW) - if (val & (1 << 12)) == 0: - return - timeout -= 1 - -def _send_ipi(apic_id: t.CUInt32T, vector: t.CUInt32T, delivery_mode: t.CUInt32T): - _wait_icr() - write(LAPIC_ICR_HIGH, apic_id << 24) - write(LAPIC_ICR_LOW, vector | delivery_mode | LAPIC_ICR_LEVEL | LAPIC_ICR_ASSERT) - _wait_icr() - -def ap_entry(): - global _ap_ready - my_id: t.CUInt32T = get_id() - buf: t.CArray[t.CChar, 64] - viperlib.snprintf(c.Addr(buf), 64, "[AP] core %u started (lapic=%u)\n", my_id, my_id) - serial.puts(buf) - _ap_ready = 1 - while True: - asm.sti() - asm.hlt() - -_trampoline_bin: t.CStatic | t.CArray[t.CUInt8T, 128] = [ - 0xFA, # cli - 0x31, 0xC0, # xor ax, ax - 0x8E, 0xD8, # mov ds, ax - 0x8E, 0xC0, # mov es, ax - 0x0F, 0x01, 0x16, 0x00, 0x7E, # lgdt [0x7E00] - 0x0F, 0x20, 0xC0, # mov eax, cr0 - 0x83, 0xC8, 0x01, # or eax, 1 - 0x0F, 0x22, 0xC0, # mov cr0, eax - 0xEA, 0x1A, 0x07, 0x00, 0x00, 0x08, 0x00, # jmp 0x08:0x701A - - # 32-bit 保护模式开始 - 0xB8, 0x10, 0x00, 0x00, 0x00, # mov ax, 0x10 - 0x8E, 0xD8, # mov ds, ax - 0x8E, 0xC0, # mov es, ax - 0x8E, 0xE0, # mov fs, ax - 0x8E, 0xE8, # mov gs, ax - 0x8E, 0xD0, # mov ss, ax - 0x0F, 0x20, 0xE0, # mov eax, cr4 - 0x83, 0xC8, 0x20, # or eax, 0x20 (PAE) - 0x0F, 0x22, 0xE0, # mov cr4, eax - 0x8B, 0x04, 0x25, 0x00, 0x7F, 0x00, 0x00, # mov eax, [0x7F00] - 0x0F, 0x22, 0xD8, # mov cr3, eax - 0xB9, 0x80, 0x00, 0x00, 0xC0, # mov ecx, 0xC0000080 (EFER) - 0x0F, 0x32, # rdmsr - 0x83, 0xC8, 0x00, 0x01, 0x00, 0x00, # or eax, 0x100 (LME) - 0x0F, 0x79, # wrmsr - 0x0F, 0x20, 0xC0, # mov eax, cr0 - 0x0D, 0x00, 0x00, 0x00, 0x80, # or eax, 0x80000000 (PG) - 0x0F, 0x22, 0xC0, # mov cr0, eax - 0xEA, 0x5A, 0x07, 0x00, 0x00, 0x08, 0x00, # jmp 0x08:0x705A - - # 64-bit 长模式开始 - 0x48, 0x8B, 0x24, 0x25, 0x08, 0x7F, 0x00, 0x00, # mov rsp, [0x7F08] - 0x0F, 0x01, 0x16, 0x10, 0x7F, # lgdt [0x7F10] - 0x0F, 0x01, 0x1E, 0x20, 0x7F, # lidt [0x7F20] - 0xB8, 0x10, 0x00, 0x00, 0x00, # mov ax, 0x10 - 0x8E, 0xD8, # mov ds, ax - 0x8E, 0xC0, # mov es, ax - 0x8E, 0xE0, # mov fs, ax - 0x8E, 0xE8, # mov gs, ax - 0x8E, 0xD0, # mov ss, ax - 0x48, 0x8B, 0x04, 0x25, 0x28, 0x7F, 0x00, 0x00, # mov rax, [0x7F28] - 0xFF, 0xE0 # jmp rax -] - -def _setup_trampoline(entry_addr: t.CUInt64T, stack_addr: t.CUInt64T, cr3_val: t.CUInt64T): - dest: t.CUInt8T | t.CPtr = t.CUInt8T(AP_TRAMPOLINE_ADDR, t.CPtr) - src: t.CUInt8T | t.CPtr = c.Addr(_trampoline_bin) - i: t.CInt - for i in range(128): - c.Set(c.Deref(dest + t.CUInt64T(i)), c.Deref(src + t.CUInt64T(i))) - - gdt_ptr_addr: t.CUInt64T = AP_TRAMPOLINE_ADDR + 0x0E00 - c.Set(c.Deref(t.CUInt16T(gdt_ptr_addr, t.CPtr)), t.CUInt16T(23)) - c.Set(c.Deref(t.CUInt64T(gdt_ptr_addr + 2, t.CPtr)), t.CUInt64T(AP_TRAMPOLINE_ADDR + 0x0E10)) - - gdt_addr: t.CUInt64T = AP_TRAMPOLINE_ADDR + 0x0E10 - c.Set(c.Deref(t.CUInt64T(gdt_addr, t.CPtr)), t.CUInt64T(0)) - c.Set(c.Deref(t.CUInt64T(gdt_addr + 8, t.CPtr)), t.CUInt64T(0x00AF9A000000FFFF)) - c.Set(c.Deref(t.CUInt64T(gdt_addr + 16, t.CPtr)), t.CUInt64T(0x00CF92000000FFFF)) - - c.Set(c.Deref(t.CUInt32T(AP_TRAMPOLINE_ADDR + 0x0F00, t.CPtr)), t.CUInt32T(cr3_val)) - c.Set(c.Deref(t.CUInt64T(AP_TRAMPOLINE_ADDR + 0x0F08, t.CPtr)), stack_addr) - - gp_addr: t.CUInt64T = t.CUInt64T(c.Addr(gdt.gp)) - gdt_base: t.CUInt64T = c.Deref(t.CUInt64T(gp_addr + 2, t.CPtr)) - gdt_limit: t.CUInt16T = c.Deref(t.CUInt16T(gp_addr, t.CPtr)) - c.Set(c.Deref(t.CUInt16T(AP_TRAMPOLINE_ADDR + 0x0F10, t.CPtr)), gdt_limit) - c.Set(c.Deref(t.CUInt64T(AP_TRAMPOLINE_ADDR + 0x0F12, t.CPtr)), gdt_base) - - idt_addr: t.CUInt64T = t.CUInt64T(c.Addr(idt.idp)) - idt_base: t.CUInt64T = c.Deref(t.CUInt64T(idt_addr + 2, t.CPtr)) - idt_limit: t.CUInt16T = c.Deref(t.CUInt16T(idt_addr, t.CPtr)) - c.Set(c.Deref(t.CUInt16T(AP_TRAMPOLINE_ADDR + 0x0F20, t.CPtr)), idt_limit) - c.Set(c.Deref(t.CUInt64T(AP_TRAMPOLINE_ADDR + 0x0F22, t.CPtr)), idt_base) - - c.Set(c.Deref(t.CUInt64T(AP_TRAMPOLINE_ADDR + 0x0F28, t.CPtr)), entry_addr) - -def start_aps(): - global _cpu_count, _ap_ready - if _cpu_count <= 1: return - - cr3_val: t.CUInt64T = 0 - c.Asm(f"""mov rax, cr3 - mov {c.AsmOut(cr3_val, t.ASM_DESCR.OUTPUT_REG)}, rax""", - [t.ASM_DESCR.CLOBBER_RAX]) - - stack_size: t.CUInt64T = 8192 - i: t.CUInt32T - for i in range(1, _cpu_count): - _ap_ready = 0 - stack: t.CVoid | t.CPtr = mm.malloc(stack_size) - if stack is None: continue - stack_top: t.CUInt64T = t.CUInt64T(stack) + stack_size - stack_top = stack_top & ~t.CUInt64T(15) - - _setup_trampoline(t.CUInt64T(ap_entry), stack_top, cr3_val) - - _send_ipi(i, 0, LAPIC_ICR_INIT) - timer.timer_msleep(10) - _send_ipi(i, (AP_TRAMPOLINE_ADDR >> 12) & 0xFF, LAPIC_ICR_STARTUP) - timer.timer_msleep(1) - _send_ipi(i, (AP_TRAMPOLINE_ADDR >> 12) & 0xFF, LAPIC_ICR_STARTUP) - - wait: t.CUInt32T = 0 - while _ap_ready == 0 and wait < 5000: - timer.timer_msleep(1) - wait += 1 - -def early_init(): - global _cpu_count, _bsp_lapic_id - features: t.CUInt32T = cpu.detect_features_static() - if features & cpu.CPU_FEATURE_APIC: - init() - _cpu_count = detect_cpu_count() - else: - _cpu_count = 1 - -def get_cpu_count() -> t.CUInt32T: - return _cpu_count - -def get_lapic_id() -> t.CUInt32T: - return get_id() diff --git a/Test/Kernel/drivers/core/cpu/cpu.vp b/Test/Kernel/drivers/core/cpu/cpu.vp deleted file mode 100644 index 650bfc31..00000000 --- a/Test/Kernel/drivers/core/cpu/cpu.vp +++ /dev/null @@ -1,346 +0,0 @@ -import fpu -import asm -import intr.gdt as gdt -import string -import t, c - -IA32_KERNEL_GS_BASE: t.CDefine = 0xC0000102 -KERN_STACK_SIZE: t.CDefine = 8192 - - -CPU_FEATURE_FPU: t.CDefine = (1 << 0) -CPU_FEATURE_PSE: t.CDefine = (1 << 1) -CPU_FEATURE_MSR: t.CDefine = (1 << 2) -CPU_FEATURE_PAE: t.CDefine = (1 << 3) -CPU_FEATURE_MCE: t.CDefine = (1 << 4) -CPU_FEATURE_CX8: t.CDefine = (1 << 5) -CPU_FEATURE_APIC: t.CDefine = (1 << 6) -CPU_FEATURE_SEP: t.CDefine = (1 << 7) -CPU_FEATURE_MTRR: t.CDefine = (1 << 8) -CPU_FEATURE_PGE: t.CDefine = (1 << 9) -CPU_FEATURE_MCA: t.CDefine = (1 << 10) -CPU_FEATURE_CMOV: t.CDefine = (1 << 11) -CPU_FEATURE_PAT: t.CDefine = (1 << 12) -CPU_FEATURE_PSE36: t.CDefine = (1 << 13) -CPU_FEATURE_PSN: t.CDefine = (1 << 14) -CPU_FEATURE_CLFSH: t.CDefine = (1 << 15) -CPU_FEATURE_DS: t.CDefine = (1 << 16) -CPU_FEATURE_ACPI: t.CDefine = (1 << 17) -CPU_FEATURE_MMX: t.CDefine = (1 << 18) -CPU_FEATURE_FXSR: t.CDefine = (1 << 19) -CPU_FEATURE_SSE: t.CDefine = (1 << 20) -CPU_FEATURE_SSE2: t.CDefine = (1 << 21) -CPU_FEATURE_SS: t.CDefine = (1 << 22) -CPU_FEATURE_HTT: t.CDefine = (1 << 23) -CPU_FEATURE_TM: t.CDefine = (1 << 24) -CPU_FEATURE_PBE: t.CDefine = (1 << 25) - -class cpu_info(t.CStruct): - vendor_id: t.CArray[t.CChar, 13] - brand_string: t.CArray[t.CChar, 48] - features: t.CUInt32T - family: t.CUInt32T - model: t.CUInt32T - stepping: t.CUInt32T - cpu_type: t.CUInt32T - ext_model: t.CUInt32T - ext_family: t.CUInt32T - cpu_freq: t.CUInt64T - -@c.Attribute(t.attr.packed) -class _tss: - reserved0: t.CUInt64T - rsp0: t.CUInt64T - rsp1: t.CUInt64T - rsp2: t.CUInt64T - reserved1: t.CUInt64T - ist1: t.CUInt64T - ist2: t.CUInt64T - ist3: t.CUInt64T - ist4: t.CUInt64T - ist5: t.CUInt64T - ist6: t.CUInt64T - ist7: t.CUInt64T - reserved2: t.CUInt64T - reserved3: t.CUInt16T - io_map_base: t.CUInt16T - -class cpuid_result(t.CStruct): - eax: t.CUInt32T - ebx: t.CUInt32T - ecx: t.CUInt32T - edx: t.CUInt32T - -@c.Attribute(t.attr.naked) -def _rdmsr_naked(): - c.Asm(f"""rdmsr - shl rdx, 32 - or rax, rdx - ret""", - op=[t.ASM_DESCR.CLOBBER_RDX]) - -@c.Attribute(t.attr.naked) -def _wrmsr_naked(): - # msr_write sets ecx=msr, r8=value. wrmsr needs ECX=msr, EDX:EAX=value. - # Old code did `mov rax,rcx` (rax=msr) which wrote (value>>32):msr to MSR, - # corrupting IA32_KERNEL_GS_BASE -> swapgs -> #GP on gs:[0]. Fixed below. - c.Asm(f"""mov rax, r8 - mov rdx, r8 - shr rdx, 32 - wrmsr - ret""", - op=[t.ASM_DESCR.CLOBBER_RAX, t.ASM_DESCR.CLOBBER_RDX]) - -def msr_read(msr: t.CUInt32T) -> t.CUInt64T: - result: t.CUInt64T = 0 - func: t.CVoid | t.CPtr = _rdmsr_naked - c.Asm(f"""mov ecx, {c.AsmInp(msr, t.ASM_DESCR.REG_ANY)} - call {c.AsmInp(func, t.ASM_DESCR.REG_ANY)} - mov {c.AsmOut(result, t.ASM_DESCR.OUTPUT_REG)}, rax""", - op=[t.ASM_DESCR.CLOBBER_RAX, t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX]) - return result - -def msr_write(msr: t.CUInt32T, value: t.CUInt64T): - func: t.CVoid | t.CPtr = _wrmsr_naked - c.Asm(f"""mov ecx, {c.AsmInp(msr, t.ASM_DESCR.REG_ANY)} - mov r8, {c.AsmInp(value, t.ASM_DESCR.REG_ANY)} - call {c.AsmInp(func, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_RAX, t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, t.ASM_DESCR.CLOBBER_R8]) - -@c.Attribute(t.attr.naked) -def _cpuid_naked(): - c.Asm(f"""push rbx - mov eax, ecx - cpuid - mov dword ptr [rdx], eax - mov dword ptr [rdx + 4], ebx - mov dword ptr [rdx + 8], ecx - mov dword ptr [rdx + 12], edx - pop rbx - ret""", - op=[t.ASM_DESCR.CLOBBER_RAX, t.ASM_DESCR.CLOBBER_RCX, - t.ASM_DESCR.CLOBBER_RDX]) - -@c.Attribute(t.attr.naked) -def _cpuid_sub_naked(): - c.Asm(f"""push rbx - mov eax, ecx - mov ecx, r8d - cpuid - mov dword ptr [rdx], eax - mov dword ptr [rdx + 4], ebx - mov dword ptr [rdx + 8], ecx - mov dword ptr [rdx + 12], edx - pop rbx - ret""", - op=[t.ASM_DESCR.CLOBBER_RAX, t.ASM_DESCR.CLOBBER_RCX, - t.ASM_DESCR.CLOBBER_RDX]) - -@c.Attribute(t.attr.noinline) -def cpuid(leaf: t.CUInt32T, out: cpuid_result | t.CPtr): - func: t.CVoid | t.CPtr = _cpuid_naked - c.Asm(f"""mov ecx, {c.AsmInp(leaf, t.ASM_DESCR.REG_ANY)} - mov rdx, {c.AsmInp(out, t.ASM_DESCR.REG_ANY)} - call {c.AsmInp(func, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_RAX, t.ASM_DESCR.CLOBBER_RCX, - t.ASM_DESCR.CLOBBER_RDX, t.ASM_DESCR.CLOBBER_R8, - t.ASM_DESCR.CLOBBER_R9, t.ASM_DESCR.CLOBBER_R10, - t.ASM_DESCR.CLOBBER_R11]) - -@c.Attribute(t.attr.noinline) -def cpuid_sub(leaf: t.CUInt32T, sub: t.CUInt32T, out: cpuid_result | t.CPtr): - func: t.CVoid | t.CPtr = _cpuid_sub_naked - c.Asm(f"""mov ecx, {c.AsmInp(leaf, t.ASM_DESCR.REG_ANY)} - mov r8d, {c.AsmInp(sub, t.ASM_DESCR.REG_ANY)} - mov rdx, {c.AsmInp(out, t.ASM_DESCR.REG_ANY)} - call {c.AsmInp(func, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_RAX, t.ASM_DESCR.CLOBBER_RCX, - t.ASM_DESCR.CLOBBER_RDX, t.ASM_DESCR.CLOBBER_R8, - t.ASM_DESCR.CLOBBER_R9, t.ASM_DESCR.CLOBBER_R10, - t.ASM_DESCR.CLOBBER_R11]) - -@c.Attribute(t.attr.noinline) -def detect_features_static() -> t.CUInt32T: - features: t.CUInt32T = 0 - res: cpuid_result - cpuid(1, c.Addr(res)) - if res.edx & (1 << 0): features |= CPU_FEATURE_FPU - if res.edx & (1 << 3): features |= CPU_FEATURE_PSE - if res.edx & (1 << 5): features |= CPU_FEATURE_MSR - if res.edx & (1 << 6): features |= CPU_FEATURE_PAE - if res.edx & (1 << 7): features |= CPU_FEATURE_MCE - if res.edx & (1 << 8): features |= CPU_FEATURE_CX8 - if res.edx & (1 << 9): features |= CPU_FEATURE_APIC - if res.edx & (1 << 11): features |= CPU_FEATURE_SEP - if res.edx & (1 << 12): features |= CPU_FEATURE_MTRR - if res.edx & (1 << 13): features |= CPU_FEATURE_PGE - if res.edx & (1 << 14): features |= CPU_FEATURE_MCA - if res.edx & (1 << 15): features |= CPU_FEATURE_CMOV - if res.edx & (1 << 16): features |= CPU_FEATURE_PAT - if res.edx & (1 << 17): features |= CPU_FEATURE_PSE36 - if res.edx & (1 << 18): features |= CPU_FEATURE_PSN - if res.edx & (1 << 19): features |= CPU_FEATURE_CLFSH - if res.edx & (1 << 21): features |= CPU_FEATURE_DS - if res.edx & (1 << 22): features |= CPU_FEATURE_ACPI - if res.edx & (1 << 23): features |= CPU_FEATURE_MMX - if res.edx & (1 << 24): features |= CPU_FEATURE_FXSR - if res.edx & (1 << 25): features |= CPU_FEATURE_SSE - if res.edx & (1 << 26): features |= CPU_FEATURE_SSE2 - if res.edx & (1 << 27): features |= CPU_FEATURE_SS - if res.edx & (1 << 28): features |= CPU_FEATURE_HTT - if res.edx & (1 << 29): features |= CPU_FEATURE_TM - if res.edx & (1 << 30): features |= CPU_FEATURE_PBE - return features - -@c.Attribute(t.attr.packed) -class per_cpu_data: - user_rsp: t.CUInt64T - kernel_rsp0: t.CUInt64T - current_pid: t.CInt - _pad0: t.CUInt32T - _pad1: t.CUInt64T - -_per_cpu: per_cpu_data - -@t.Object -class _CPUObject: - tss: _tss - features: t.CUInt32T - def __init__(self): - self.__init_tss__() - - def __init_tss__(self): - global _per_cpu - string.memset(c.Addr(self.tss), 0, self.tss.__sizeof__()) - self.tss.io_map_base = self.tss.__sizeof__() - string.memset(c.Addr(_per_cpu), 0, per_cpu_data.__sizeof__()) - gdt.setTSS64(5, t.CUInt64T(c.Addr(self.tss)), self.tss.__sizeof__() - 1) - gdt.flush() - # IA32_KERNEL_GS_BASE holds the per_cpu address for swapgs. - # When entering from Ring 3, swapgs swaps IA32_GS_BASE (0) with - # IA32_KERNEL_GS_BASE (_per_cpu), making gs: accessible in kernel. - # When returning to Ring 3, swapgs swaps back, restoring GS base to 0. - msr_write(IA32_KERNEL_GS_BASE, t.CUInt64T(c.Addr(_per_cpu))) - - def getInfo(self, info: cpu_info | t.CPtr): - if not info: return - res: cpuid_result - cpuid(0, c.Addr(res)) - (t.CUInt32T(info.vendor_id, t.CPtr))[0] = res.ebx - (t.CUInt32T(info.vendor_id, t.CPtr))[1] = res.edx - (t.CUInt32T(info.vendor_id, t.CPtr))[2] = res.ecx - info.vendor_id[12] = '\0' - info.features = self.detectFeatures() - cpuid(1, c.Addr(res)) - info.stepping = (res.eax >> 0) & 0x0F - info.model = (res.eax >> 4) & 0x0F - info.family = (res.eax >> 8) & 0x0F - info.cpu_type = (res.eax >> 12) & 0x03 - info.ext_model = (res.eax >> 16) & 0x0F - info.ext_family = (res.eax >> 20) & 0xFF - for i in range(4): - cpuid(0x80000002 + i, c.Addr(res)) - base: t.CUInt32T | t.CPtr = t.CUInt32T(info.brand_string, t.CPtr) - base[i * 4 + 0] = res.eax - base[i * 4 + 1] = res.ebx - base[i * 4 + 2] = res.ecx - base[i * 4 + 3] = res.edx - info.brand_string[47] = '\0' - info.cpu_freq = 2000000000 - - def detectFeatures(self) -> t.CUInt32T: - features: t.CInt32T = 0 - res: cpuid_result - cpuid(1, c.Addr(res)) - if res.edx & (1 << 0): features |= CPU_FEATURE_FPU - if res.edx & (1 << 3): features |= CPU_FEATURE_PSE - if res.edx & (1 << 5): features |= CPU_FEATURE_MSR - if res.edx & (1 << 6): features |= CPU_FEATURE_PAE - if res.edx & (1 << 7): features |= CPU_FEATURE_MCE - if res.edx & (1 << 8): features |= CPU_FEATURE_CX8 - if res.edx & (1 << 9): features |= CPU_FEATURE_APIC - if res.edx & (1 << 11): features |= CPU_FEATURE_SEP - if res.edx & (1 << 12): features |= CPU_FEATURE_MTRR - if res.edx & (1 << 13): features |= CPU_FEATURE_PGE - if res.edx & (1 << 14): features |= CPU_FEATURE_MCA - if res.edx & (1 << 15): features |= CPU_FEATURE_CMOV - if res.edx & (1 << 16): features |= CPU_FEATURE_PAT - if res.edx & (1 << 17): features |= CPU_FEATURE_PSE36 - if res.edx & (1 << 18): features |= CPU_FEATURE_PSN - if res.edx & (1 << 19): features |= CPU_FEATURE_CLFSH - if res.edx & (1 << 21): features |= CPU_FEATURE_DS - if res.edx & (1 << 22): features |= CPU_FEATURE_ACPI - if res.edx & (1 << 23): features |= CPU_FEATURE_MMX - if res.edx & (1 << 24): features |= CPU_FEATURE_FXSR - if res.edx & (1 << 25): features |= CPU_FEATURE_SSE - if res.edx & (1 << 26): features |= CPU_FEATURE_SSE2 - if res.edx & (1 << 27): features |= CPU_FEATURE_SS - if res.edx & (1 << 28): features |= CPU_FEATURE_HTT - if res.edx & (1 << 29): features |= CPU_FEATURE_TM - if res.edx & (1 << 30): features |= CPU_FEATURE_PBE - return features - - def enableInterrupts(self): - c.Asm("sti", [t.ASM_DESCR.CLOBBER_MEMORY]) - - def disableInterrupts(self): - c.Asm("cli", [t.ASM_DESCR.CLOBBER_MEMORY]) - - def enableNmis(self): - current: t.CUInt8T = asm.inb(0x70) - asm.outb(0x70, current & 0x7F) - - def disableNmis(self): - current: t.CUInt8T = asm.inb(0x70) - asm.outb(0x70, current | 0x80) - - def readCR0(self) -> t.CUInt64T: - cr0: t.CUInt64T - c.Asm(f"""mov rax, cr0 - mov {c.AsmOut(cr0, t.ASM_DESCR.OUTPUT_REG)}, rax""", - [t.ASM_DESCR.CLOBBER_RAX]) - return cr0 - - def writeCR0(self, value: t.CUInt64T): - c.Asm(f"""mov rax, {c.AsmInp(value, t.ASM_DESCR.REG_ANY)} - mov cr0, rax""", - [t.ASM_DESCR.CLOBBER_RAX]) - - def readCR3(self) -> t.CUInt64T: - cr3: t.CUInt64T - c.Asm(f"""mov rax, cr3 - mov {c.AsmOut(cr3, t.ASM_DESCR.OUTPUT_REG)}, rax""", - [t.ASM_DESCR.CLOBBER_RAX]) - return cr3 - - def writeCR3(self, value: t.CUInt64T): - c.Asm(f"""mov rax, {c.AsmInp(value, t.ASM_DESCR.REG_ANY)} - mov cr3, rax""", - [t.ASM_DESCR.CLOBBER_RAX]) - - def readCR4(self) -> t.CUInt64T: - cr4: t.CUInt64T - c.Asm(f"""mov rax, cr4 - mov {c.AsmOut(cr4, t.ASM_DESCR.OUTPUT_REG)}, rax""", - [t.ASM_DESCR.CLOBBER_RAX]) - return cr4 - - def writeCR4(self, value: t.CUInt64T): - c.Asm(f"""mov rax, {c.AsmInp(value, t.ASM_DESCR.REG_ANY)} - mov cr4, rax""", - [t.ASM_DESCR.CLOBBER_RAX]) - - def readMSR(self, msr: t.CUInt32T) -> t.CUInt64T: - return msr_read(msr) - - def writeMSR(self, msr: t.CUInt32T, value: t.CUInt64T): - msr_write(msr, value) - - def setTSSRSP0(self, rsp0: t.CUInt64T): - global _per_cpu - self.tss.rsp0 = rsp0 - _per_cpu.kernel_rsp0 = rsp0 - -def set_kernel_rsp0(rsp0: t.CUInt64T): - global _per_cpu - _per_cpu.kernel_rsp0 = rsp0 diff --git a/Test/Kernel/drivers/core/cpu/fpu.vp b/Test/Kernel/drivers/core/cpu/fpu.vp deleted file mode 100644 index f326fcff..00000000 --- a/Test/Kernel/drivers/core/cpu/fpu.vp +++ /dev/null @@ -1,50 +0,0 @@ -import cpu -import t, c - - -# FPU上下文结构体 -@c.Attribute(t.attr.aligned(16)) -class fpu_context: - data: t.CUInt8T[512] # FXSAVE区域大小 - - -@t.Object -class _FPUObject: - CPUObject: cpu._CPUObject | t.CPtr - # 初始化FPU - def __init__(self, CPUObject: cpu._CPUObject | t.CPtr): - self.enable() - self.CPUObject = CPUObject - c.Asm("fninit", [t.ASM_DESCR.CLOBBER_MEMORY]) - # 启用FPU - def enable(self): - cr0: t.CUInt64T = self.CPUObject.readCR0() - # 清除EM位(禁用仿真),设置MP位(监控协处理器) - cr0 &= ~(1 << 2); # 清除EM位 - cr0 |= (1 << 1); # 设置MP位 - # 写入CR0寄存器 - self.CPUObject.writeCR0(cr0) - # 读取CR4寄存器 - cr4: t.CUInt64T = self.CPUObject.readCR4() - # 设置OSFXSR位和OSXMMEXCPT位,启用SSE - cr4 |= (1 << 9) | (1 << 10) - # 写入CR4寄存器 - self.CPUObject.writeCR4(cr4) - # 初始化FPU - c.Asm("fninit", [t.ASM_DESCR.CLOBBER_MEMORY]) - # 禁用FPU - def disable(self): - cr0: t.CUInt64T = self.CPUObject.readCR0() - # 设置EM位(启用仿真),清除MP位(禁用监控协处理器) - cr0 |= (1 << 2) # 设置EM位 - cr0 &= ~(1 << 1) # 清除MP位 - # 写入CR0寄存器 - self.CPUObject.writeCR0(cr0) - # 保存FPU上下文 - def save_context(self, context: fpu_context | t.CPtr): - # 保存FPU状态到内存 - c.Asm(f"fxsave [{c.AsmInp(context, t.ASM_DESCR.REG_ANY)}]", [t.ASM_DESCR.CLOBBER_MEMORY]) - # 恢复FPU上下文 - def restore_context(self, context: t.CConst | fpu_context | t.CPtr): - # 从内存恢复FPU状态 - c.Asm(f"fxrstor [{c.AsmInp(context, t.ASM_DESCR.REG_ANY)}]", [t.ASM_DESCR.CLOBBER_MEMORY]) diff --git a/Test/Kernel/drivers/devfs/devfs copy.vp b/Test/Kernel/drivers/devfs/devfs copy.vp deleted file mode 100644 index 053c9bc0..00000000 --- a/Test/Kernel/drivers/devfs/devfs copy.vp +++ /dev/null @@ -1,385 +0,0 @@ -import drivers.serial.uart.serial as serial -import viperstring as string -import t, c - - -MAX_FILE_DESCRIPTORS: t.CDefine = 64 -MAX_DEVICE_FILES: t.CDefine = 32 -MAX_DIRECTORIES: t.CDefine = 16 -PATH_BUFFER_SIZE: t.CDefine = 256 - -directories: list[devfs_directory, MAX_DIRECTORIES] = [0] -directory_count: t.CStatic | t.CInt = 0 - -files: list[devfs_file, MAX_DEVICE_FILES] = [0] -file_count: t.CStatic | t.CInt = 0 - - -class _fd_table: - file: devfs_file | t.CPtr - flags: t.CInt - -fd_table: list[_fd_table, MAX_FILE_DESCRIPTORS] = [0] - -@t.Object -class devfs_directory: - name: list[t.CChar, 64] - parent: 'devfs_directory' | t.CPtr - - @staticmethod - def find(path: t.CConst | str, - root_directory: devfs_directory | t.CPtr) -> devfs_directory | t.CPtr: - if not path or string.strchr(path, '/') != path: return None - if not root_directory: return None - - current_dir: devfs_directory | t.CPtr = root_directory - result: list[str, PATH_BUFFER_SIZE] - token = string.split(path, "/", result) - - for i in result: - found: bool = False - for d in range(directory_count): - dirp: devfs_directory = c.Addr(directories[d]) - if dirp.parent == current_dir and string.samestr(dirp.name, i): - current_dir = dirp - found = True - break - if not found: return None - - return current_dir - - @staticmethod - def find_child(name: t.CConst | str, - parent: devfs_directory | t.CPtr) -> devfs_directory | t.CPtr: - for d in range(directory_count): - dirp: devfs_directory = c.Addr(directories[d]) - if dirp.parent == parent and string.samestr(dirp.name, name): - return dirp - return None - - @staticmethod - def list_subdirs(dir_ptr: devfs_directory | t.CPtr, - buffer: str, - size: t.CUInt32T, - pos: t.CInt) -> t.CInt: - for d in range(directory_count): - dirp: devfs_directory = c.Addr(directories[d]) - if dirp.parent == dir_ptr: - name_len: t.CInt = string.strlen(dirp.name) - if pos + name_len + 1 > size: - break - string.strcpy(buffer + pos, dirp.name) - pos += name_len - buffer[pos] = '\n' - pos += 1 - return pos - -@t.Object -@t.CVTable -class devfs_file: - name: list[t.CChar, 64] - private_data: t.CVoid | t.CPtr - parent_dir: 'devfs_directory' | t.CPtr - - @staticmethod - def find_in_dir(file_name: t.CConst | str, - dir_ptr: devfs_directory | t.CPtr) -> devfs_file | t.CPtr: - for f in range(file_count): - fp: devfs_file | t.CPtr = c.Addr(files[f]) - if fp.parent_dir == dir_ptr and string.samestr(fp.name, file_name): - return fp - return None - - @staticmethod - def list_in_dir(dir_ptr: devfs_directory | t.CPtr, - buffer: str, - size: t.CUInt32T, - pos: t.CInt) -> t.CInt: - for f in range(file_count): - filep: devfs_file | t.CPtr = c.Addr(files[f]) - if filep.parent_dir == dir_ptr: - name_len: t.CInt = string.strlen(filep.name) - if pos + name_len + 1 > size: - break - string.strcpy(buffer + pos, filep.name) - pos += name_len - buffer[pos] = '\n' - pos += 1 - return pos - - def open(self, path: t.CConst | str, flags: t.CInt) -> t.CInt: - return 0 - - def close(self, fd: t.CInt) -> t.CInt: - return 0 - - def read(self, fd: t.CInt, buffer: t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - return 0 - - def write(self, fd: t.CInt, buffer: t.CConst | t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - return 0 - - def ioctl(self, fd: t.CInt, request: t.CInt, arg: t.CVoid | t.CPtr) -> t.CInt: - return 0 - -@t.Object -class _DevFSObject: - root_directory: devfs_directory | t.CPtr - - def __init__(self): - global directory_count, file_count - self.root_directory = None - directory_count = 0 - file_count = 0 - string.memset(c.Addr(directories), 0, devfs_directory.__sizeof__() * MAX_DIRECTORIES) - string.memset(c.Addr(files), 0, devfs_file.__sizeof__() * MAX_DEVICE_FILES) - string.memset(c.Addr(fd_table), 0, _fd_table.__sizeof__() * MAX_FILE_DESCRIPTORS) - - def create_single_dir(self, parent: devfs_directory | t.CPtr, - dir_name: t.CConst | str) -> devfs_directory | t.CPtr: - global directory_count - if not parent or not dir_name: return None - if directory_count >= MAX_DIRECTORIES: return None - if string.strlen(dir_name) >= 64: return None - - new_dir: devfs_directory | t.CPtr = c.Addr(directories[directory_count]) - directory_count += 1 - - string.strcpy(new_dir.name, dir_name) - new_dir.parent = parent - - return new_dir - - def find_or_create_directory(self, path: t.CConst | str) -> devfs_directory | t.CPtr: - global directory_count - if not path or string.samestr(path, "/"): return None - - if not self.root_directory: - self.root_directory = c.Addr(directories[directory_count]) - directory_count += 1 - string.strcpy(self.root_directory.name, "") - self.root_directory.parent = None - - current: devfs_directory | t.CPtr = self.root_directory - buf: list[t.CChar, PATH_BUFFER_SIZE] - string.memset(c.Addr(buf), 0, PATH_BUFFER_SIZE) - buf_idx: t.CInt = 0 - p: t.CInt = 0 - if path[p] == '/': - p += 1 - while path[p] != '\0': - if path[p] == '/': - if buf_idx > 0: - found_child: devfs_directory | t.CPtr = devfs_directory.find_child(buf, current) - if not found_child: - found_child = self.create_single_dir(current, buf) - if not found_child: return None - current = found_child - string.memset(c.Addr(buf), 0, PATH_BUFFER_SIZE) - buf_idx = 0 - p += 1 - else: - buf[buf_idx] = path[p] - buf_idx += 1 - p += 1 - if buf_idx > 0: - found_child: devfs_directory | t.CPtr = devfs_directory.find_child(buf, current) - if not found_child: - found_child = self.create_single_dir(current, buf) - if not found_child: return None - current = found_child - - return current - - def init(self) -> t.CInt: - self.create_directory("/dev") - self.create_directory("/dev/input") - return 0 - - def create_directory(self, path: t.CConst | str) -> t.CInt: - dir_ptr: devfs_directory | t.CPtr = self.find_or_create_directory(path) - return 0 if dir_ptr else -1 - - def create_file(self, path: t.CConst | str, - private_data: t.CVoid | t.CPtr) -> t.CInt: - global file_count - path_copy: list[t.CChar, PATH_BUFFER_SIZE] - string.memset(c.Addr(path_copy), 0, PATH_BUFFER_SIZE) - string.strcpy(path_copy, path) - - last_slash: str | t.CPtr = string.strrchr(path_copy, '/') - - if not last_slash: return -1 - - last_slash[0] = '\0' - dir_path = path_copy - file_name: str | t.CPtr = last_slash + 1 - - dir_ptr: devfs_directory | t.CPtr = self.find_or_create_directory(dir_path) - if not dir_ptr: return -1 - - if devfs_file.find_in_dir(file_name, dir_ptr): - return -1 - - if file_count >= MAX_DEVICE_FILES: return -1 - - new_file: devfs_file | t.CPtr = c.Addr(files[file_count]) - file_count += 1 - - string.strcpy(new_file.name, file_name) - new_file.private_data = private_data - new_file.parent_dir = dir_ptr - - return 0 - - def open(self, path: t.CConst | str, flags: t.CInt) -> t.CInt: - path_copy: list[t.CChar, PATH_BUFFER_SIZE] - string.memset(c.Addr(path_copy), 0, PATH_BUFFER_SIZE) - string.strcpy(path_copy, path) - - last_slash: str | t.CPtr = string.strrchr(path_copy, '/') - - if not last_slash: return -1 - - last_slash[0] = '\0' - dir_path = path_copy - file_name: str | t.CPtr = last_slash + 1 - - dir_ptr: devfs_directory | t.CPtr = devfs_directory.find(dir_path, self.root_directory) - if not dir_ptr: return -1 - - file_ptr: devfs_file | t.CPtr = devfs_file.find_in_dir(file_name, dir_ptr) - if not file_ptr: return -1 - - if not file_ptr.open: - return -1 - - fd: t.CInt = -1 - for i in range(MAX_FILE_DESCRIPTORS): - if not fd_table[i].file: - fd = i - break - - if fd == -1: return -1 - - ret: t.CInt = file_ptr.open(path, flags) - if ret != 0: return ret - - fd_table[fd].file = file_ptr - fd_table[fd].flags = flags - return fd - - def close(self, fd: t.CInt) -> t.CInt: - if fd < 0 or fd >= MAX_FILE_DESCRIPTORS or not fd_table[fd].file: - return -1 - file_ptr: devfs_file | t.CPtr = fd_table[fd].file - if file_ptr and file_ptr.close: - file_ptr.close(fd) - fd_table[fd].file = None - fd_table[fd].flags = 0 - return 0 - - def read(self, fd: t.CInt, buffer: t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - if fd < 0 or fd >= MAX_FILE_DESCRIPTORS or not fd_table[fd].file: - return -1 - file_ptr: devfs_file | t.CPtr = fd_table[fd].file - if file_ptr and file_ptr.read: - return file_ptr.read(fd, buffer, size) - return 0 - - def write(self, fd: t.CInt, buffer: t.CConst | t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - if fd < 0 or fd >= MAX_FILE_DESCRIPTORS or not fd_table[fd].file: - return -1 - file_ptr: devfs_file | t.CPtr = fd_table[fd].file - if file_ptr and file_ptr.write: - return file_ptr.write(fd, buffer, size) - return 0 - - def ioctl(self, fd: t.CInt, cmd: t.CUInt32T, arg: t.CVoid | t.CPtr) -> t.CInt: - if fd < 0 or fd >= MAX_FILE_DESCRIPTORS or not fd_table[fd].file: - return -1 - file_ptr: devfs_file | t.CPtr = fd_table[fd].file - if file_ptr and file_ptr.ioctl: - return file_ptr.ioctl(fd, cmd, arg) - return 0 - - def list_directory(self, path: t.CConst | str, - buffer: str, - size: t.CUInt32T) -> t.CInt: - dir_ptr: devfs_directory | t.CPtr = devfs_directory.find(path, self.root_directory) - if not dir_ptr or not buffer or size == 0: return -1 - - pos: t.CInt = devfs_directory.list_subdirs(dir_ptr, buffer, size, 0) - pos = devfs_file.list_in_dir(dir_ptr, buffer, size, pos) - - return pos - -DevFSObject: _DevFSObject | t.CPtr -_DevFSObject_instance: _DevFSObject - - -def devfs_init() -> t.CInt: - global DevFSObject, _DevFSObject_instance - DevFSObject = c.Addr(_DevFSObject_instance) - _DevFSObject_instance.__init__() - DevFSObject.init() - return 0 - -def devfs_create_directory(path: t.CConst | str) -> t.CInt: - return DevFSObject.create_directory(path) - -def devfs_create_file(path: t.CConst | str, - private_data: t.CVoid | t.CPtr) -> t.CInt: - return DevFSObject.create_file(path, private_data) - -def devfs_open(path: t.CConst | str, flags: t.CInt) -> t.CInt: - return DevFSObject.open(path, flags) - -def devfs_close(fd: t.CInt) -> t.CInt: - return DevFSObject.close(fd) - -def devfs_read(fd: t.CInt, buffer: t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - return DevFSObject.read(fd, buffer, size) - -def devfs_write(fd: t.CInt, buffer: t.CConst | t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - return DevFSObject.write(fd, buffer, size) - -def devfs_ioctl(fd: t.CInt, cmd: t.CUInt32T, arg: t.CVoid | t.CPtr) -> t.CInt: - return DevFSObject.ioctl(fd, cmd, arg) - -def devfs_list_directory(path: t.CConst | str, - buffer: str, - size: t.CUInt32T) -> t.CInt: - return DevFSObject.list_directory(path, buffer, size) - -serial0_file: devfs_file - -def serial0_open(self: t.CVoid | t.CPtr, path: t.CConst | str, flags: t.CInt) -> t.CInt: - serial.puts("[serial0] open: ") - serial.puts(path) - serial.puts("\n") - return 0 - -def serial0_close(self: t.CVoid | t.CPtr, fd: t.CInt) -> t.CInt: - serial.puts("[serial0] close\n") - return 0 - -def serial0_read(self: t.CVoid | t.CPtr, fd: t.CInt, buffer: t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - serial.puts("[serial0] read\n") - return 0 - -def serial0_write(self: t.CVoid | t.CPtr, fd: t.CInt, buffer: t.CConst | t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - serial.puts("[serial0] write\n") - serial.puts(str(buffer)) - serial.puts("\n") - return size - -def devfs_register_serial0() -> t.CInt: - global serial0_file - serial0_file = devfs_file() - serial0_file.open = serial0_open - serial0_file.close = serial0_close - serial0_file.read = serial0_read - serial0_file.write = serial0_write - serial0_file.ioctl = None - return devfs_create_file("/dev/serial0", serial0_file) diff --git a/Test/Kernel/drivers/devfs/devfs.vp b/Test/Kernel/drivers/devfs/devfs.vp deleted file mode 100644 index 1fd9fb65..00000000 --- a/Test/Kernel/drivers/devfs/devfs.vp +++ /dev/null @@ -1,491 +0,0 @@ -import drivers.serial.uart.serial as serial -import viperstring as string -import t, c - - -MAX_FILE_DESCRIPTORS: t.CDefine = 64 -MAX_DEVICE_FILES: t.CDefine = 32 -MAX_DIRECTORIES: t.CDefine = 16 -PATH_BUFFER_SIZE: t.CDefine = 256 - -directories: t.CArray[devfs_directory, MAX_DIRECTORIES] = [0] -directory_count: t.CStatic | t.CInt = 0 - -files: t.CArray[devfs_file, MAX_DEVICE_FILES] = [0] -file_count: t.CStatic | t.CInt = 0 - - -class _fd_table: - file: devfs_file | t.CPtr - flags: t.CInt - -fd_table: t.CArray[_fd_table, MAX_FILE_DESCRIPTORS] = [0] - -@t.Object -class devfs_directory: - name: t.CArray[t.CChar, 64] - parent: 'devfs_directory' | t.CPtr - - @staticmethod - def find(path: t.CConst | str, - root_directory: devfs_directory | t.CPtr) -> devfs_directory | t.CPtr: - if not path or string.strchr(path, '/') != path: return None - if not root_directory: return None - - current_dir: devfs_directory | t.CPtr = root_directory - result: t.CArray[str, PATH_BUFFER_SIZE] - token = string.split(path, "/", result) - - for i in result: - found: bool = False - for d in range(directory_count): - dirp: devfs_directory = c.Addr(directories[d]) - if dirp.parent == current_dir and string.samestr(dirp.name, i): - current_dir = dirp - found = True - break - if not found: return None - - return current_dir - - @staticmethod - def find_child(name: t.CConst | str, - parent: devfs_directory | t.CPtr) -> devfs_directory | t.CPtr: - for d in range(directory_count): - dirp: devfs_directory = c.Addr(directories[d]) - if dirp.parent == parent and string.samestr(dirp.name, name): - return dirp - return None - - @staticmethod - def list_subdirs(dir_ptr: devfs_directory | t.CPtr, - buffer: str, - size: t.CUInt32T, - pos: t.CInt) -> t.CInt: - for d in range(directory_count): - dirp: devfs_directory = c.Addr(directories[d]) - if dirp.parent == dir_ptr: - name_len: t.CInt = string.strlen(dirp.name) - if pos + name_len + 1 > size: - break - string.strcpy(buffer + pos, dirp.name) - pos += name_len - buffer[pos] = '\n' - pos += 1 - return pos - -@t.Object -@t.CVTable -class devfs_file: - name: t.CArray[t.CChar, 64] - private_data: t.CVoid | t.CPtr - parent_dir: 'devfs_directory' | t.CPtr - - @staticmethod - def find_in_dir(file_name: t.CConst | str, - dir_ptr: devfs_directory | t.CPtr) -> devfs_file | t.CPtr: - for f in range(file_count): - fp: devfs_file | t.CPtr = c.Addr(files[f]) - if fp.parent_dir == dir_ptr and string.samestr(fp.name, file_name): - return fp - return None - - @staticmethod - def list_in_dir(dir_ptr: devfs_directory | t.CPtr, - buffer: str, - size: t.CUInt32T, - pos: t.CInt) -> t.CInt: - for f in range(file_count): - filep: devfs_file | t.CPtr = c.Addr(files[f]) - if filep.parent_dir == dir_ptr: - name_len: t.CInt = string.strlen(filep.name) - if pos + name_len + 1 > size: - break - string.strcpy(buffer + pos, filep.name) - pos += name_len - buffer[pos] = '\n' - pos += 1 - return pos - - def open(self, path: t.CConst | str, flags: t.CInt) -> t.CInt: - return 0 - - def close(self, fd: t.CInt) -> t.CInt: - return 0 - - def read(self, fd: t.CInt, buffer: t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - return 0 - - def write(self, fd: t.CInt, buffer: t.CConst | t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - return 0 - - def ioctl(self, fd: t.CInt, request: t.CInt, arg: t.CVoid | t.CPtr) -> t.CInt: - return 0 - -@t.Object -class _DevFSObject: - root_directory: devfs_directory | t.CPtr - - def __init__(self): - global directory_count, file_count - self.root_directory = None - directory_count = 0 - file_count = 0 - string.memset(c.Addr(directories), 0, devfs_directory.__sizeof__() * MAX_DIRECTORIES) - string.memset(c.Addr(files), 0, devfs_file.__sizeof__() * MAX_DEVICE_FILES) - string.memset(c.Addr(fd_table), 0, _fd_table.__sizeof__() * MAX_FILE_DESCRIPTORS) - - def create_single_dir(self, parent: devfs_directory | t.CPtr, - dir_name: t.CConst | str) -> devfs_directory | t.CPtr: - global directory_count - if not parent or not dir_name: return None - if directory_count >= MAX_DIRECTORIES: return None - if string.strlen(dir_name) >= 64: return None - - new_dir: devfs_directory | t.CPtr = c.Addr(directories[directory_count]) - directory_count += 1 - - string.strcpy(new_dir.name, dir_name) - new_dir.parent = parent - - return new_dir - - def find_or_create_directory(self, path: t.CConst | str) -> devfs_directory | t.CPtr: - global directory_count - if not path or string.samestr(path, "/"): return None - - serial.puts("A") - if not self.root_directory: - self.root_directory = c.Addr(directories[directory_count]) - directory_count += 1 - string.strcpy(self.root_directory.name, "") - self.root_directory.parent = None - - serial.puts("B") - current: devfs_directory | t.CPtr = self.root_directory - buf: t.CArray[t.CChar, PATH_BUFFER_SIZE] - string.memset(c.Addr(buf), 0, PATH_BUFFER_SIZE) - buf_idx: t.CInt = 0 - p: t.CInt = 0 - if path[p] == '/': - p += 1 - serial.puts("C") - while path[p] != '\0': - if path[p] == '/': - if buf_idx > 0: - found_child: devfs_directory | t.CPtr = devfs_directory.find_child(buf, current) - if not found_child: - found_child = self.create_single_dir(current, buf) - if not found_child: return None - current = found_child - string.memset(c.Addr(buf), 0, PATH_BUFFER_SIZE) - buf_idx = 0 - p += 1 - else: - buf[buf_idx] = path[p] - buf_idx += 1 - p += 1 - serial.puts("D") - if buf_idx > 0: - found_child: devfs_directory | t.CPtr = devfs_directory.find_child(buf, current) - if not found_child: - found_child = self.create_single_dir(current, buf) - if not found_child: return None - current = found_child - serial.puts("E") - - return current - - def init(self) -> t.CInt: - self.create_directory("/dev") - self.create_directory("/dev/input") - return 0 - - def create_directory(self, path: t.CConst | str) -> t.CInt: - serial.puts("T1") - dir_ptr: devfs_directory | t.CPtr = self.find_or_create_directory(path) - serial.puts("T2") - return 0 if dir_ptr else -1 - - def create_file(self, path: t.CConst | str, - file_ptr: devfs_file | t.CPtr, - private_data: t.CVoid | t.CPtr) -> t.CInt: - global file_count - path_copy: t.CArray[t.CChar, PATH_BUFFER_SIZE] - string.memset(c.Addr(path_copy), 0, PATH_BUFFER_SIZE) - string.strcpy(path_copy, path) - - last_slash: str | t.CPtr = string.strrchr(path_copy, '/') - - if not last_slash: return -1 - - last_slash[0] = '\0' - dir_path = path_copy - file_name: str | t.CPtr = last_slash + 1 - - dir_ptr: devfs_directory | t.CPtr = self.find_or_create_directory(dir_path) - if not dir_ptr: return -1 - - if devfs_file.find_in_dir(file_name, dir_ptr): - return -1 - - if file_count >= MAX_DEVICE_FILES: return -1 - - if file_ptr: - string.strcpy(file_ptr.name, file_name) - file_ptr.private_data = private_data - file_ptr.parent_dir = dir_ptr - files[file_count] = file_ptr - else: - new_file: devfs_file | t.CPtr = c.Addr(files[file_count]) - string.strcpy(new_file.name, file_name) - new_file.private_data = private_data - new_file.parent_dir = dir_ptr - - file_count += 1 - return 0 - - def open(self, path: t.CConst | str, flags: t.CInt) -> t.CInt: - path_copy: t.CArray[t.CChar, PATH_BUFFER_SIZE] - string.memset(c.Addr(path_copy), 0, PATH_BUFFER_SIZE) - string.strcpy(path_copy, path) - - last_slash: str | t.CPtr = string.strrchr(path_copy, '/') - - if not last_slash: return -1 - - last_slash[0] = '\0' - dir_path = path_copy - file_name: str | t.CPtr = last_slash + 1 - - dir_ptr: devfs_directory | t.CPtr = devfs_directory.find(dir_path, self.root_directory) - if not dir_ptr: return -1 - - file_ptr: devfs_file | t.CPtr = devfs_file.find_in_dir(file_name, dir_ptr) - if not file_ptr: return -1 - - fd: t.CInt = -1 - for i in range(MAX_FILE_DESCRIPTORS): - if not fd_table[i].file: - fd = i - break - - if fd == -1: return -1 - - ret: t.CInt = file_ptr.open(path, flags) - if ret != 0: return ret - - fd_table[fd].file = file_ptr - fd_table[fd].flags = flags - return fd - - def close(self, fd: t.CInt) -> t.CInt: - if fd < 0 or fd >= MAX_FILE_DESCRIPTORS or not fd_table[fd].file: - return -1 - file_ptr: devfs_file | t.CPtr = fd_table[fd].file - file_ptr.close(fd) - fd_table[fd].file = None - fd_table[fd].flags = 0 - return 0 - - def read(self, fd: t.CInt, buffer: t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - if fd < 0 or fd >= MAX_FILE_DESCRIPTORS or not fd_table[fd].file: - return -1 - file_ptr: devfs_file | t.CPtr = fd_table[fd].file - return file_ptr.read(fd, buffer, size) - - def write(self, fd: t.CInt, buffer: t.CConst | t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - if fd < 0 or fd >= MAX_FILE_DESCRIPTORS or not fd_table[fd].file: - return -1 - file_ptr: devfs_file | t.CPtr = fd_table[fd].file - return file_ptr.write(fd, buffer, size) - - def ioctl(self, fd: t.CInt, cmd: t.CUInt32T, arg: t.CVoid | t.CPtr) -> t.CInt: - if fd < 0 or fd >= MAX_FILE_DESCRIPTORS or not fd_table[fd].file: - return -1 - file_ptr: devfs_file | t.CPtr = fd_table[fd].file - return file_ptr.ioctl(fd, cmd, arg) - - def list_directory(self, path: t.CConst | str, - buffer: str, - size: t.CUInt32T) -> t.CInt: - dir_ptr: devfs_directory | t.CPtr = devfs_directory.find(path, self.root_directory) - if not dir_ptr or not buffer or size == 0: return -1 - - pos: t.CInt = devfs_directory.list_subdirs(dir_ptr, buffer, size, 0) - pos = devfs_file.list_in_dir(dir_ptr, buffer, size, pos) - - return pos - -DevFSObject: _DevFSObject | t.CPtr -_DevFSObject_instance: _DevFSObject - - -def devfs_init() -> t.CInt: - global DevFSObject, _DevFSObject_instance - DevFSObject = c.Addr(_DevFSObject_instance) - _DevFSObject_instance = _DevFSObject() - # _DevFSObject_instance.__init__() - DevFSObject.init() - return 0 - -def devfs_create_directory(path: t.CConst | str) -> t.CInt: - return DevFSObject.create_directory(path) - -def devfs_create_file(path: t.CConst | str, - file_ptr: devfs_file | t.CPtr, - private_data: t.CVoid | t.CPtr) -> t.CInt: - return DevFSObject.create_file(path, file_ptr, private_data) - -def devfs_open(path: t.CConst | str, flags: t.CInt) -> t.CInt: - return DevFSObject.open(path, flags) - -def devfs_close(fd: t.CInt) -> t.CInt: - return DevFSObject.close(fd) - -def devfs_read(fd: t.CInt, buffer: t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - return DevFSObject.read(fd, buffer, size) - -def devfs_write(fd: t.CInt, buffer: t.CConst | t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - return DevFSObject.write(fd, buffer, size) - -def devfs_ioctl(fd: t.CInt, cmd: t.CUInt32T, arg: t.CVoid | t.CPtr) -> t.CInt: - return DevFSObject.ioctl(fd, cmd, arg) - -def devfs_list_directory(path: t.CConst | str, - buffer: str, - size: t.CUInt32T) -> t.CInt: - return DevFSObject.list_directory(path, buffer, size) - -serial0_file: devfs_file - -def serial0_open(self: t.CVoid | t.CPtr, path: t.CConst | str, flags: t.CInt) -> t.CInt: - serial.puts("[serial0] open: ") - serial.puts(path) - serial.puts("\n") - return 0 - -def serial0_close(self: t.CVoid | t.CPtr, fd: t.CInt) -> t.CInt: - serial.puts("[serial0] close\n") - return 0 - -def serial0_read(self: t.CVoid | t.CPtr, fd: t.CInt, buffer: t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - serial.puts("[serial0] read\n") - return 0 - -def serial0_write(self: t.CVoid | t.CPtr, fd: t.CInt, buffer: t.CConst | t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - serial.puts("[serial0] write\n") - serial.puts(str(buffer)) - serial.puts("\n") - return size - -def devfs_register_serial0() -> t.CInt: - global serial0_file - serial0_file = devfs_file() - serial0_file.open = serial0_open - serial0_file.close = serial0_close - serial0_file.read = serial0_read - serial0_file.write = serial0_write - return devfs_create_file("/dev/serial0", serial0_file, None) - -@t.Object -@t.CVTable -class serial1_device(devfs_file): - def open(self, path: t.CConst | str, flags: t.CInt) -> t.CInt: - serial.puts("[serial1] open: ") - serial.puts(path) - serial.puts("\n") - return 0 - - def close(self, fd: t.CInt) -> t.CInt: - serial.puts("[serial1] close\n") - return 0 - - def read(self, fd: t.CInt, buffer: t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - serial.puts("[serial1] read\n") - return 0 - - def write(self, fd: t.CInt, buffer: t.CConst | t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - serial.puts("[serial1] write\n") - serial.puts(str(buffer)) - serial.puts("\n") - return size - -serial1_file: serial1_device - -def devfs_register_serial1() -> t.CInt: - global serial1_file - serial1_file = serial1_device() - return devfs_create_file("/dev/serial1", serial1_file, None) - -import drivers.input.keyboard.keyboard as keyboard -import drivers.input.mouse.mouse as mouse - -@t.Object -@t.CVTable -class keyboard_device(devfs_file): - def open(self, path: t.CConst | str, flags: t.CInt) -> t.CInt: - return 0 - - def close(self, fd: t.CInt) -> t.CInt: - return 0 - - def read(self, fd: t.CInt, buffer: t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - count: t.CUInt32T = 0 - while count < size and keyboard.has_data(): - sc: t.CUInt8T = keyboard.read_scancode() - ch: t.CChar = keyboard.scancode_to_ascii(sc) - if ch != '\0': - c.Set(t.CChar(buffer, t.CPtr)[count], ch) - count += 1 - return count - - def write(self, fd: t.CInt, buffer: t.CConst | t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - return -1 - - def ioctl(self, fd: t.CInt, request: t.CInt, arg: t.CVoid | t.CPtr) -> t.CInt: - return 0 - -kbd_file: keyboard_device - -def devfs_register_keyboard() -> t.CInt: - global kbd_file - kbd_file = keyboard_device() - keyboard.init() - return devfs_create_file("/dev/input/keyboard", kbd_file, None) - -@t.Object -@t.CVTable -class mouse_device(devfs_file): - def open(self, path: t.CConst | str, flags: t.CInt) -> t.CInt: - return 0 - - def close(self, fd: t.CInt) -> t.CInt: - return 0 - - def read(self, fd: t.CInt, buffer: t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - if not mouse.has_data(): return 0 - pkt: mouse.mouse_packet - mouse.read_packet(c.Addr(pkt)) - if size >= 1: - c.Set(t.CUInt8T(buffer, t.CPtr)[0], pkt.buttons) - if size >= 5: - buf: t.CUInt32T | t.CPtr = t.CVoid(t.CUInt64T(buffer) + 1, t.CPtr) - c.Set(t.CInt32T(buf, t.CPtr)[0], mouse.get_x()) - c.Set(t.CInt32T(buf, t.CPtr)[1], mouse.get_y()) - return 5 - return 1 - - def write(self, fd: t.CInt, buffer: t.CConst | t.CVoid | t.CPtr, size: t.CUInt32T) -> t.CInt: - return -1 - - def ioctl(self, fd: t.CInt, request: t.CInt, arg: t.CVoid | t.CPtr) -> t.CInt: - return 0 - -mse_file: mouse_device - -def devfs_register_mouse() -> t.CInt: - global mse_file - mse_file = mouse_device() - mouse.init() - return devfs_create_file("/dev/input/mouse", mse_file, None) diff --git a/Test/Kernel/drivers/fs/fat32/example_fs.vp b/Test/Kernel/drivers/fs/fat32/example_fs.vp deleted file mode 100644 index dac35e67..00000000 --- a/Test/Kernel/drivers/fs/fat32/example_fs.vp +++ /dev/null @@ -1,237 +0,0 @@ -from stdint import * -import fat32 as fs -import fat32_types as types -import fat32_part as part -import fat32_mkfs as mkfs_mod -import t, c - - -def print_fresult(res: types.FRESULT, msg: t.CConst) -> t.CInt: - if res == types.FRESULT.FR_OK: - print(f"[成功] {msg}") - return 0 - else: - print(f"[失败] {msg}: {res}") - return -1 - - -def print_fresult_void(res: types.FRESULT, msg: t.CConst): - print_fresult(res, msg) - - -def example_main() -> t.CInt: - print("=== FAT32 文件系统完整示例 ===") - print() - - # 1. 扫描可用驱动器 - print("--- 1. 扫描可用驱动器 ---") - res: types.FRESULT = fs.scan_drives() - print_fresult_void(res, "扫描驱动器") - - drive_count: t.CInt = fs.get_drive_count() - print(f"找到 {drive_count} 个驱动器") - i: t.CInt - for i in range(drive_count): - letter: t.CChar = fs.get_drive_letter(i) - part_count: t.CInt = fs.get_partition_count(letter) - print(f" 驱动器 {i}: {letter}") - for j in range(part_count): - is_fat32: t.CInt = fs.is_partition_fat32(letter, j) - print(f" 分区 {j}: FAT32={is_fat32}") - print() - - # 2. 挂载文件系统 - print("--- 2. 挂载文件系统 ---") - res = fs.mount() - if print_fresult(res, "挂载文件系统") != 0: - print("提示: 可能需要先格式化磁盘") - print() - - # 3. 文件系统信息 - print("--- 3. 文件系统信息 ---") - mounted: t.CInt = fs.is_mounted() - print(f"已挂载: {mounted}") - if mounted: - total_clusters: t.CUInt32T = fs.get_total() - free_clusters: t.CUInt32T = fs.get_free() - cluster_size: t.CUInt32T = fs.get_cluster_size() - total_bytes: t.CUInt64T = t.CUInt64T(total_clusters) * t.CUInt64T(cluster_size) - free_bytes: t.CUInt64T = t.CUInt64T(free_clusters) * t.CUInt64T(cluster_size) - print(f"总簇数: {total_clusters}") - print(f"空闲簇数: {free_clusters}") - print(f"簇大小: {cluster_size} 字节") - print(f"总大小: {total_bytes} 字节") - print(f"空闲大小: {free_bytes} 字节") - print() - - # 4. 元数据操作 - print("--- 4. 元数据操作 ---") - fs.set_metadata(0x12345678) - metadata: t.CUInt32T = fs.get_metadata() - print(f"设置的元数据: 0x{metadata:08X}") - print() - - # 5. 获取 FAT 时间 - print("--- 5. 获取 FAT 时间 ---") - fattime: t.CUInt32T = fs.get_fattime() - print(f"当前 FAT 时间: 0x{fattime:08X}") - print() - - # 6. 目录操作 - if fs.is_mounted(): - print("--- 6. 目录操作 ---") - - # 创建目录 - res = fs.mkdir("/test_dir_1") - print_fresult_void(res, "创建目录 /test_dir_1") - - res = fs.mkdir("/test_dir_1/subdir") - print_fresult_void(res, "创建子目录 /test_dir_1/subdir") - - res = fs.mkdir("/test_dir_2") - print_fresult_void(res, "创建目录 /test_dir_2") - print() - - # 7. 文件操作 - print("--- 7. 文件操作 ---") - - # 创建并写入文件 - fp1: types.fileobj | t.CPtr = fs.open("/test_dir_1/file1.txt", types.FA_CREATE_ALWAYS | types.FA_WRITE) - if fp1 is not None: - test_data1: t.CConst = "Hello, World!" - written: t.CUInt32T = fs.write(fp1, test_data1, 13) - print(f"写入文件 /test_dir_1/file1.txt: {written} 字节") - fs.close(fp1) - - # 打开追加 - fp2: types.fileobj | t.CPtr = fs.open("/test_dir_1/file1.txt", types.FA_OPEN_ALWAYS | types.FA_WRITE | types.FA_OPEN_APPEND) - if fp2 is not None: - test_data2: t.CConst = " Append data!" - written2: t.CUInt32T = fs.write(fp2, test_data2, 13) - print(f"追加写入: {written2} 字节") - fs.close(fp2) - - # 读取文件 - fp3: types.fileobj | t.CPtr = fs.open("/test_dir_1/file1.txt", types.FA_OPEN_EXISTING | types.FA_READ) - if fp3 is not None: - buf: t.CArray[t.CUInt8T, 256] - read_bytes: t.CUInt32T = fs.read(fp3, t.CVoid(c.Addr(buf[0]), t.CPtr), 256) - print(f"读取字节数: {read_bytes}") - print(f"文件内容: {t.CChar(c.Addr(buf[0]), t.CPtr)}") - - # seek 和 tell - fs.seek(fp3, 5) - pos: t.CUInt32T = fs.tell(fp3) - print(f"seek 到位置 5, 当前位置: {pos}") - - read_bytes2: t.CUInt32T = fs.read(fp3, t.CVoid(c.Addr(buf[0]), t.CPtr), 256) - print(f"从位置 5 读取: {t.CChar(c.Addr(buf[0]), t.CPtr)}") - - # 获取文件大小 - fsize: t.CUInt32T = fs.size(fp3) - print(f"文件大小: {fsize} 字节") - - fs.close(fp3) - - # 创建另一个文件 - fp4: types.fileobj | t.CPtr = fs.open("/test_dir_1/large_file.txt", types.FA_CREATE_ALWAYS | types.FA_WRITE) - if fp4 is not None: - large_data: t.CArray[t.CUInt8T, 1024] - k: t.CInt - for k in range(1024): - large_data[k] = t.CUInt8T(ord('A') + (k % 26)) - written3: t.CUInt32T = fs.write(fp4, t.CVoid(c.Addr(large_data[0]), t.CPtr), 1024) - print(f"创建大文件, 写入: {written3} 字节") - fs.close(fp4) - print() - - # 8. 文件状态和属性 - print("--- 8. 文件状态和属性 ---") - - info: types.fileinfo - res = fs.stat("/test_dir_1/file1.txt", info) - print_fresult_void(res, "获取文件信息") - if res == types.FRESULT.FR_OK: - print(f" 文件名: {info.fname}") - print(f" 大小: {info.file_size} 字节") - print(f" 属性: 0x{info.attr:02X}") - print(f" 创建时间: 0x{info.ctime:04X}") - print(f" 创建日期: 0x{info.cdate:04X}") - print(f" 修改时间: 0x{info.mtime:04X}") - print(f" 修改日期: 0x{info.mdate:04X}") - print(f" 访问日期: 0x{info.adate:04X}") - - # 修改属性 - res = fs.chmod("/test_dir_1/file1.txt", types.AM_RDO, types.AM_RDO) - print_fresult_void(res, "设置文件为只读") - print() - - # 9. 重命名和移动 - print("--- 9. 重命名和移动 ---") - - res = fs.rename("/test_dir_1/file1.txt", "/test_dir_1/renamed.txt") - print_fresult_void(res, "重命名文件") - - res = fs.move("/test_dir_1/renamed.txt", "/test_dir_2/moved.txt") - print_fresult_void(res, "移动文件") - - res = fs.rename("/test_dir_2", "/test_dir_renamed") - print_fresult_void(res, "重命名目录") - print() - - # 10. 列出目录 - print("--- 10. 列出目录 ---") - - dp: types.dirobj - res = fs.opendir("/", dp) - if res == types.FRESULT.FR_OK: - print("根目录内容:") - dir_info: types.fileinfo - while True: - res = fs.readdir(dp, dir_info) - if res != types.FRESULT.FR_OK: - break - attr_str: t.CConst = "" - if dir_info.attr & types.AM_DIR: - attr_str = attr_str + "D" - else: - attr_str = attr_str + "F" - if dir_info.attr & types.AM_RDO: - attr_str = attr_str + "R" - if dir_info.attr & types.AM_HID: - attr_str = attr_str + "H" - if dir_info.attr & types.AM_SYS: - attr_str = attr_str + "S" - if dir_info.attr & types.AM_ARC: - attr_str = attr_str + "A" - print(f" [{attr_str}] {dir_info.fname} ({dir_info.file_size} 字节)") - fs.closedir(dp) - print() - - # 11. 删除文件和目录 - print("--- 11. 删除文件和目录 ---") - - res = fs.remove("/test_dir_renamed/moved.txt") - print_fresult_void(res, "删除文件") - - res = fs.remove("/test_dir_1/large_file.txt") - print_fresult_void(res, "删除大文件") - - res = fs.rmdir("/test_dir_1/subdir") - print_fresult_void(res, "删除子目录") - - res = fs.rmdir("/test_dir_1") - print_fresult_void(res, "删除目录 /test_dir_1") - - res = fs.rmdir("/test_dir_renamed") - print_fresult_void(res, "删除目录 /test_dir_renamed") - print() - - # 12. 卸载文件系统 - print("--- 12. 卸载文件系统 ---") - res = fs.unmount() - print_fresult_void(res, "卸载文件系统") - print() - - print("=== 示例完成 ===") - return 0 diff --git a/Test/Kernel/drivers/fs/fat32/fat32.vp b/Test/Kernel/drivers/fs/fat32/fat32.vp deleted file mode 100644 index 27870339..00000000 --- a/Test/Kernel/drivers/fs/fat32/fat32.vp +++ /dev/null @@ -1,208 +0,0 @@ -from stdint import * -import string -import fat32_types as types -import fat32_time as ftime -import fat32_mkfs as mkfs_mod -import fat32_part as part -import fat32_diskio as diskio -import sched.sched as sched -import t, c - - -default_fs: types.volinfo = types.volinfo() -_fs_lock: t.CInt = 0 - -def lock(): - global _fs_lock - while True: - c.Asm("cli") - if _fs_lock == 0: - _fs_lock = 1 - c.Asm("sti") - return - c.Asm("sti") - sched.Scheduler._yield() - -def unlock(): - global _fs_lock - _fs_lock = 0 - -def mount() -> types.FRESULT: - default_fs.pdrv = 0 - default_fs.hidden_sectors = 0 - buf: t.CArray[t.CUInt8T, 512] - dres: types.DRESULT = diskio.read(0, c.Addr(buf[0]), 0, 1) - if dres == types.DRESULT.RES_OK: - if buf[0] == 0xEB or buf[0] == 0xE9: - default_fs.hidden_sectors = 0 - else: - sig: t.CUInt16T = t.CUInt16T(buf[510]) | (t.CUInt16T(buf[511]) << 8) - if sig == 0xAA55: - ptype: t.CUInt8T = buf[450] - if ptype != 0: - slba: t.CUInt32T = t.CUInt32T(buf[454]) | (t.CUInt32T(buf[455]) << 8) | (t.CUInt32T(buf[456]) << 16) | (t.CUInt32T(buf[457]) << 24) - default_fs.hidden_sectors = slba - if default_fs.mounted: return types.FRESULT.FR_OK - dsk_res: types.DRESULT = diskio.status(default_fs.pdrv) - if dsk_res != types.DRESULT.RES_OK: - dsk_res = diskio.init(default_fs.pdrv) - if dsk_res != types.DRESULT.RES_OK: return types.FRESULT.FR_NOT_READY - default_fs.winsect = 0xFFFFFFFFFFFFFFFF - default_fs.fat_winsect = 0xFFFFFFFFFFFFFFFF - wres: types.FRESULT = default_fs.win_read(0) - if wres != types.FRESULT.FR_OK: return types.FRESULT.FR_DISK_ERR - bps: t.CUInt16T = default_fs.win[11] | (t.CUInt16T(default_fs.win[12]) << 8) - spc: t.CUInt8T = default_fs.win[13] - rsc: t.CUInt16T = default_fs.win[14] | (t.CUInt16T(default_fs.win[15]) << 8) - nf: t.CUInt8T = default_fs.win[16] - if bps != 512: return types.FRESULT.FR_NO_FILESYSTEM - if spc == 0 or (spc & (spc - 1)) != 0: return types.FRESULT.FR_NO_FILESYSTEM - if rsc == 0: return types.FRESULT.FR_NO_FILESYSTEM - if nf == 0: return types.FRESULT.FR_NO_FILESYSTEM - root_ent: t.CUInt16T = default_fs.win[17] | (t.CUInt16T(default_fs.win[18]) << 8) - fat16sz: t.CUInt16T = default_fs.win[22] | (t.CUInt16T(default_fs.win[23]) << 8) - tot32: t.CUInt32T = t.CUInt32T(default_fs.win[32]) | (t.CUInt32T(default_fs.win[33]) << 8) | (t.CUInt32T(default_fs.win[34]) << 16) | (t.CUInt32T(default_fs.win[35]) << 24) - fat32sz: t.CUInt32T = t.CUInt32T(default_fs.win[36]) | (t.CUInt32T(default_fs.win[37]) << 8) | (t.CUInt32T(default_fs.win[38]) << 16) | (t.CUInt32T(default_fs.win[39]) << 24) - root_clus: t.CUInt32T = t.CUInt32T(default_fs.win[44]) | (t.CUInt32T(default_fs.win[45]) << 8) | (t.CUInt32T(default_fs.win[46]) << 16) | (t.CUInt32T(default_fs.win[47]) << 24) - if root_ent != 0 or fat16sz != 0: return types.FRESULT.FR_NO_FILESYSTEM - if fat32sz == 0: return types.FRESULT.FR_NO_FILESYSTEM - if tot32 == 0: return types.FRESULT.FR_NO_FILESYSTEM - if default_fs.win[510] != 0x55 or default_fs.win[511] != 0xAA: return types.FRESULT.FR_NO_FILESYSTEM - fsinfo_sec: t.CUInt16T = default_fs.win[48] | (t.CUInt16T(default_fs.win[49]) << 8) - bkboot_sec: t.CUInt16T = default_fs.win[50] | (t.CUInt16T(default_fs.win[51]) << 8) - default_fs.sector_size = 512 - default_fs.cluster_sectors = spc - default_fs.cluster_size = t.CUInt32T(spc) * 512 - default_fs.num_fats = nf - default_fs.reserved_sectors = rsc - default_fs.fat_size = fat32sz - default_fs.fat_start = t.CUInt64T(rsc) - default_fs.total_sectors = t.CUInt64T(tot32) - default_fs.root_cluster = root_clus - default_fs.fsinfo_sector = fsinfo_sec - default_fs.backup_sector = bkboot_sec - default_fs.vol_id = t.CUInt32T(default_fs.win[67]) | (t.CUInt32T(default_fs.win[68]) << 8) | (t.CUInt32T(default_fs.win[69]) << 16) | (t.CUInt32T(default_fs.win[70]) << 24) - data_sectors: t.CUInt64T = default_fs.total_sectors - t.CUInt64T(rsc) - t.CUInt64T(t.CUInt64T(nf) * t.CUInt64T(fat32sz)) - default_fs.total_clusters = t.CUInt32T(data_sectors / t.CUInt64T(spc)) - default_fs.data_start = default_fs.fat_start + t.CUInt64T(t.CUInt64T(nf) * t.CUInt64T(fat32sz)) - default_fs.last_alloc = 2 - default_fs.free_clusters = 0xFFFFFFFF - if fsinfo_sec != 0: - default_fs.fsinfo_read() - default_fs.mounted = 1 - return types.FRESULT.FR_OK - -def unmount() -> types.FRESULT: - return default_fs.unmount() - -def format(sec_per_clus: t.CUInt8T = 0, vol_id: t.CUInt32T = 0) -> types.FRESULT: - return mkfs_mod.mkfs(default_fs.pdrv, sec_per_clus, vol_id) - -def open(path: t.CConst | str, mode: t.CUInt8T) -> types.fileobj | t.CPtr: - return default_fs.file_open(path, mode) - -def close(fp: types.fileobj | t.CPtr) -> types.FRESULT: - return fp.close() - -def read(fp: types.fileobj | t.CPtr, buff: t.CVoid | t.CPtr, btr: t.CUInt32T) -> t.CUInt32T: - br: t.CUInt32T = 0 - fp.read(buff, btr, c.Addr(br)) - return br - -def write(fp: types.fileobj | t.CPtr, buff: t.CConst | t.CVoid | t.CPtr, btw: t.CUInt32T) -> t.CUInt32T: - bw: t.CUInt32T = 0 - fp.write(buff, btw, c.Addr(bw)) - return bw - -def seek(fp: types.fileobj | t.CPtr, offset: t.CUInt32T) -> types.FRESULT: - return fp.seek(offset) - -def tell(fp: types.fileobj | t.CPtr) -> t.CUInt32T: - return fp.tell() - -def size(fp: types.fileobj | t.CPtr) -> t.CUInt32T: - return fp.size() - -def truncate(fp: types.fileobj | t.CPtr) -> types.FRESULT: - return fp.truncate() - -def remove(path: t.CConst | str) -> types.FRESULT: - return default_fs.file_delete(path) - -def rename(old_path: t.CConst | str, new_path: t.CConst | str) -> types.FRESULT: - return default_fs.file_rename(old_path, new_path) - -def move(old_path: t.CConst | str, new_path: t.CConst | str) -> types.FRESULT: - return default_fs.file_rename(old_path, new_path) - -def stat(path: t.CConst | str, info: types.fileinfo | t.CPtr) -> types.FRESULT: - return default_fs.file_stat(path, info) - -def mkdir(path: t.CConst | str) -> types.FRESULT: - return default_fs.dir_make(path) - -def rmdir(path: t.CConst | str) -> types.FRESULT: - return default_fs.dir_remove(path) - -def opendir(path: t.CConst | str, dp: types.dirobj | t.CPtr) -> types.FRESULT: - return default_fs.dir_open_path(path, dp) - -def readdir(dp: types.dirobj | t.CPtr, info: types.fileinfo | t.CPtr) -> types.FRESULT: - return default_fs.dir_read(dp, info) - -def closedir(dp: types.dirobj | t.CPtr): - dp.is_open = 0 - -def chmod(path: t.CConst | str, attr: t.CUInt8T, mask: t.CUInt8T) -> types.FRESULT: - return default_fs.chmod(path, attr, mask) - -def utime(path: t.CConst | str, mtime: t.CUInt16T, mdate: t.CUInt16T) -> types.FRESULT: - return default_fs.utime(path, mtime, mdate) - -def get_free() -> t.CUInt32T: - if not default_fs.mounted: return 0 - if default_fs.free_clusters == 0xFFFFFFFF: - return default_fs.count_free_clusters() - return default_fs.free_clusters - -def get_total() -> t.CUInt32T: - if not default_fs.mounted: return 0 - return default_fs.total_clusters - -def get_cluster_size() -> t.CUInt32T: - if not default_fs.mounted: return 0 - return default_fs.cluster_size - -def is_mounted() -> t.CInt: - return default_fs.mounted - -def last_error() -> t.CUInt32T: - return default_fs.last_error - -def get_fattime() -> t.CUInt32T: - return ftime.get_fattime() - -def get_metadata() -> t.CUInt32T: - return default_fs.metadata - -def set_metadata(val: t.CUInt32T): - default_fs.metadata = val - -def scan_drives() -> types.FRESULT: - return part.scan_drives() - -def get_drive_count() -> t.CInt: - return part.get_drive_count() - -def get_drive_letter(idx: t.CInt) -> t.CChar: - return part.get_drive_letter(idx) - -def set_drive_letter(idx: t.CInt, letter: t.CChar) -> types.FRESULT: - return part.set_drive_letter(idx, letter) - -def get_partition_count(letter: t.CChar) -> t.CInt: - return part.get_partition_count(letter) - -def is_partition_fat32(letter: t.CChar, part_idx: t.CInt) -> t.CInt: - return part.is_partition_fat32(letter, part_idx) - diff --git a/Test/Kernel/drivers/fs/fat32/fat32_core.vp b/Test/Kernel/drivers/fs/fat32/fat32_core.vp deleted file mode 100644 index eb59ae25..00000000 --- a/Test/Kernel/drivers/fs/fat32/fat32_core.vp +++ /dev/null @@ -1,16 +0,0 @@ -from stdint import * -import fat32_types as types -import t, c - - -_read32 = types._read32 -_read16 = types._read16 -_write32 = types._write32 -_write16 = types._write16 - - -def is_eoc(cluster: t.CUInt32T) -> t.CInt: - return 1 if (cluster >= types.CLUSTER_EOC_MIN and cluster <= types.CLUSTER_EOC_MAX) else 0 - -def is_free(cluster: t.CUInt32T) -> t.CInt: - return 1 if cluster == types.CLUSTER_FREE else 0 diff --git a/Test/Kernel/drivers/fs/fat32/fat32_dir.vp b/Test/Kernel/drivers/fs/fat32/fat32_dir.vp deleted file mode 100644 index 5f85280d..00000000 --- a/Test/Kernel/drivers/fs/fat32/fat32_dir.vp +++ /dev/null @@ -1,13 +0,0 @@ -from stdint import * -import fat32_types as types -import t, c - - -sfn_checksum = types.sfn_checksum -uni2oem_placeholder = types.uni2oem_placeholder -lfn_get_char = types.lfn_get_char -lfn_set_char = types.lfn_set_char -lfn_extract = types.lfn_extract -sfn_from_lfn = types.sfn_from_lfn -sfn_to_str = types.sfn_to_str -_split_path = types._split_path diff --git a/Test/Kernel/drivers/fs/fat32/fat32_diskio.vp b/Test/Kernel/drivers/fs/fat32/fat32_diskio.vp deleted file mode 100644 index fe9d00d7..00000000 --- a/Test/Kernel/drivers/fs/fat32/fat32_diskio.vp +++ /dev/null @@ -1,76 +0,0 @@ -import drivers.storage.ide.ide as ide -import fat32_types as types -import spinlock -import string -import t, c - - -MAX_DRIVES: t.CDefine = 4 - -drive_initialized: t.CArray[t.CInt, MAX_DRIVES] -drive_lock: spinlock._spinlock = spinlock._spinlock() - -def status(pdrv: t.CUInt8T) -> types.DRESULT: - if pdrv >= MAX_DRIVES: return types.DRESULT.RES_PARERR - if not drive_initialized[pdrv]: return types.DRESULT.RES_NOTRDY - return types.DRESULT.RES_OK - -def init(pdrv: t.CUInt8T) -> types.DRESULT: - if pdrv >= MAX_DRIVES: return types.DRESULT.RES_PARERR - drive_lock.lock() - err: t.CInt = ide.init() - if err != 0: - drive_lock.unlock() - return types.DRESULT.RES_NOTRDY - drive_initialized[pdrv] = 1 - drive_lock.unlock() - return types.DRESULT.RES_OK - -def read(pdrv: t.CUInt8T, buff: t.CUInt8T | t.CPtr, sector: t.CUInt32T, count: t.CUInt32T) -> types.DRESULT: - if pdrv >= MAX_DRIVES: return types.DRESULT.RES_PARERR - if not drive_initialized[pdrv]: return types.DRESULT.RES_NOTRDY - drive_lock.lock() - i: t.CUInt32T - for i in range(count): - rd_res: t.CInt = ide.readSector(sector + i, buff + (i * 512)) - if rd_res != 0: - drive_lock.unlock() - return types.DRESULT.RES_ERROR - drive_lock.unlock() - return types.DRESULT.RES_OK - -def write(pdrv: t.CUInt8T, buff: t.CConst | t.CUInt8T | t.CPtr, sector: t.CUInt32T, count: t.CUInt32T) -> types.DRESULT: - if pdrv >= MAX_DRIVES: return types.DRESULT.RES_PARERR - if not drive_initialized[pdrv]: return types.DRESULT.RES_NOTRDY - drive_lock.lock() - i: t.CUInt32T - for i in range(count): - if ide.writeSector(sector + i, buff + (i * 512)) != 0: - drive_lock.unlock() - return types.DRESULT.RES_ERROR - drive_lock.unlock() - return types.DRESULT.RES_OK - -def ioctl(pdrv: t.CUInt8T, cmd: t.CUInt8T, buff: t.CVoid | t.CPtr) -> types.DRESULT: - if pdrv >= MAX_DRIVES: return types.DRESULT.RES_PARERR - if not drive_initialized[pdrv]: return types.DRESULT.RES_NOTRDY - match cmd: - case types.GET_SECTOR_COUNT: - disk_size: t.CUInt64T = ide.getDiskSize() - if disk_size == 0: - c.Set(t.CUInt32T(buff, t.CPtr), 131072) - elif disk_size > 0xFFFFFFFF: - c.Set(t.CUInt32T(buff, t.CPtr), 0xFFFFFFFF) - else: - c.Set(t.CUInt32T(buff, t.CPtr), t.CUInt32T(disk_size)) - return types.DRESULT.RES_OK - case types.GET_SECTOR_SIZE: - c.Set(t.CUInt16T(buff, t.CPtr), 512) - return types.DRESULT.RES_OK - case types.GET_BLOCK_SIZE: - c.Set(t.CUInt32T(buff, t.CPtr), 1) - return types.DRESULT.RES_OK - case types.CTRL_SYNC: - return types.DRESULT.RES_OK - case _: - return types.DRESULT.RES_PARERR diff --git a/Test/Kernel/drivers/fs/fat32/fat32_file.vp b/Test/Kernel/drivers/fs/fat32/fat32_file.vp deleted file mode 100644 index 49f8bd92..00000000 --- a/Test/Kernel/drivers/fs/fat32/fat32_file.vp +++ /dev/null @@ -1,17 +0,0 @@ -from stdint import * -import fat32_types as types -import t, c - - -handle_table = types.handle_table -lock_table = types.lock_table -handles_initialized = types.handles_initialized -handles_init = types.handles_init -handle_alloc = types.handle_alloc -lock_check = types.lock_check -lock_acquire = types.lock_acquire -lock_release = types.lock_release - -def handle_free(fp): - fp.is_open = 0 - fp.lock_count = 0 diff --git a/Test/Kernel/drivers/fs/fat32/fat32_mkfs.vp b/Test/Kernel/drivers/fs/fat32/fat32_mkfs.vp deleted file mode 100644 index e34b950e..00000000 --- a/Test/Kernel/drivers/fs/fat32/fat32_mkfs.vp +++ /dev/null @@ -1,143 +0,0 @@ -from stdint import * -import fat32_types as types -import fat32_diskio as diskio -import fat32_time as ftime -import string -import t, c - - -def _div_round_up(a: t.CUInt64T, b: t.CUInt64T) -> t.CUInt64T: - return (a + b - 1) / b - -def _calc_fat_size(total_sectors: t.CUInt64T, reserved: t.CUInt32T, sec_per_clus: t.CUInt8T, num_fats: t.CUInt8T) -> t.CUInt32T: - tmp: t.CUInt64T = total_sectors - t.CUInt64T(reserved) - fat_sz: t.CUInt32T = 1 - while True: - data_sectors: t.CUInt64T = tmp - t.CUInt64T(fat_sz) * t.CUInt64T(num_fats) - total_clusters: t.CUInt32T = t.CUInt32T(data_sectors / t.CUInt64T(sec_per_clus)) - needed: t.CUInt64T = _div_round_up(t.CUInt64T(total_clusters) * 4, 512) - if needed <= t.CUInt64T(fat_sz): break - fat_sz = t.CUInt32T(needed) - return fat_sz - -def _write_boot_sector(pdrv: t.CUInt8T, total_sectors: t.CUInt64T, sec_per_clus: t.CUInt8T, vol_id: t.CUInt32T, fat_sz: t.CUInt32T) -> types.DRESULT: - buf: t.CArray[t.CUInt8T, 512] - string.memset(c.Addr(buf[0]), 0, 512) - buf[0] = 0xEB; buf[1] = 0x58; buf[2] = 0x90 - buf[3] = 'M'; buf[4] = 'S'; buf[5] = 'W'; buf[6] = 'I'; buf[7] = 'N' - buf[8] = '4'; buf[9] = '.'; buf[10] = '1' - types._write16(c.Addr(buf[0]), 11, 512) - buf[13] = sec_per_clus - types._write16(c.Addr(buf[0]), 14, 32) - buf[16] = 2 - types._write16(c.Addr(buf[0]), 17, 0) - buf[21] = 0xF8 - types._write16(c.Addr(buf[0]), 22, 0) - types._write16(c.Addr(buf[0]), 24, 63) - types._write16(c.Addr(buf[0]), 26, 255) - types._write32(c.Addr(buf[0]), 28, 0) - types._write32(c.Addr(buf[0]), 32, t.CUInt32T(total_sectors)) - types._write32(c.Addr(buf[0]), 36, fat_sz) - types._write16(c.Addr(buf[0]), 40, 0) - types._write16(c.Addr(buf[0]), 42, 0) - types._write32(c.Addr(buf[0]), 44, 2) - types._write16(c.Addr(buf[0]), 48, 1) - types._write16(c.Addr(buf[0]), 50, 6) - buf[64] = 0x80 - buf[66] = 0x29 - types._write32(c.Addr(buf[0]), 67, vol_id) - vol_label: t.CArray[t.CChar, 11] - vol_label[0] = 'N'; vol_label[1] = 'O'; vol_label[2] = ' '; vol_label[3] = ' ' - vol_label[4] = ' '; vol_label[5] = ' '; vol_label[6] = ' '; vol_label[7] = ' ' - vol_label[8] = ' '; vol_label[9] = ' '; vol_label[10] = ' ' - i: t.CInt - for i in range(11): buf[71 + i] = t.CUInt8T(vol_label[i]) - buf[82] = 'F'; buf[83] = 'A'; buf[84] = 'T'; buf[85] = '3' - buf[86] = '2'; buf[87] = ' '; buf[88] = ' '; buf[89] = ' ' - buf[510] = 0x55; buf[511] = 0xAA - return diskio.write(pdrv, c.Addr(buf[0]), 0, 1) - -def _write_fsinfo(pdrv: t.CUInt8T, free_count: t.CUInt32T, next_free: t.CUInt32T) -> types.DRESULT: - buf: t.CArray[t.CUInt8T, 512] - string.memset(c.Addr(buf[0]), 0, 512) - types._write32(c.Addr(buf[0]), 0, 0x41615252) - types._write32(c.Addr(buf[0]), 484, 0x61417272) - types._write32(c.Addr(buf[0]), 488, free_count) - types._write32(c.Addr(buf[0]), 492, next_free) - types._write32(c.Addr(buf[0]), 508, 0xAA550000) - return diskio.write(pdrv, c.Addr(buf[0]), 1, 1) - -def _init_fat(pdrv: t.CUInt8T, fat_start: t.CUInt64T, fat_sz: t.CUInt32T, root_cluster: t.CUInt32T) -> types.DRESULT: - buf: t.CArray[t.CUInt8T, 512] - string.memset(c.Addr(buf[0]), 0, 512) - types._write32(c.Addr(buf[0]), 0, 0x0FFFFFF8) - types._write32(c.Addr(buf[0]), 4, 0x0FFFFFFF) - types._write32(c.Addr(buf[0]), 8, 0x0FFFFFFF) - if root_cluster >= 2: - cluster_off: t.CUInt32T = root_cluster * 4 - sector_off: t.CUInt32T = cluster_off / 512 - byte_off: t.CUInt32T = cluster_off % 512 - if sector_off == 0: - types._write32(c.Addr(buf[0]), byte_off, 0x0FFFFFFF) - res: types.DRESULT = diskio.write(pdrv, c.Addr(buf[0]), t.CUInt32T(fat_start), 1) - if res != types.DRESULT.RES_OK: return res - string.memset(c.Addr(buf[0]), 0, 512) - s: t.CUInt32T - for s in range(1, fat_sz): - res2: types.DRESULT = diskio.write(pdrv, c.Addr(buf[0]), t.CUInt32T(fat_start) + s, 1) - if res2 != types.DRESULT.RES_OK: return res2 - return types.DRESULT.RES_OK - -def _init_root_dir(pdrv: t.CUInt8T, root_sector: t.CUInt64T, sec_per_clus: t.CUInt8T) -> types.DRESULT: - buf: t.CArray[t.CUInt8T, 512] - string.memset(c.Addr(buf[0]), 0, 512) - s: t.CUInt8T - for s in range(sec_per_clus): - res: types.DRESULT = diskio.write(pdrv, c.Addr(buf[0]), t.CUInt32T(root_sector + t.CUInt64T(s)), 1) - if res != types.DRESULT.RES_OK: return res - return types.DRESULT.RES_OK - -def _calc_sec_per_clus(total_sectors: t.CUInt64T) -> t.CUInt8T: - ts: t.CUInt64T = total_sectors - if ts < 532480: return 1 - elif ts < 16777216: return 8 - elif ts < 33554432: return 16 - elif ts < 67108864: return 32 - else: return 64 - -def mkfs(pdrv: t.CUInt8T, sec_per_clus: t.CUInt8T, vol_id: t.CUInt32T) -> types.FRESULT: - if pdrv != types.DEV_DISK: return types.FRESULT.FR_INVALID_DRIVE - total_sectors_buf: t.CUInt32T = 0 - diskio.ioctl(pdrv, types.GET_SECTOR_COUNT, c.Addr(total_sectors_buf)) - total_sectors: t.CUInt64T = t.CUInt64T(total_sectors_buf) - if total_sectors < 65536: return types.FRESULT.FR_MKFS_ABORTED - if sec_per_clus == 0: sec_per_clus = _calc_sec_per_clus(total_sectors) - if sec_per_clus != 1 and sec_per_clus != 2 and sec_per_clus != 4 and sec_per_clus != 8 and sec_per_clus != 16 and sec_per_clus != 32 and sec_per_clus != 64 and sec_per_clus != 128: - return types.FRESULT.FR_INVALID_PARAMETER - if vol_id == 0: vol_id = ftime.get_fattime() - reserved: t.CUInt32T = 32 - num_fats: t.CUInt8T = 2 - fat_sz: t.CUInt32T = _calc_fat_size(total_sectors, reserved, sec_per_clus, num_fats) - data_sectors: t.CUInt64T = total_sectors - t.CUInt64T(reserved) - t.CUInt64T(fat_sz) * t.CUInt64T(num_fats) - total_clusters: t.CUInt32T = t.CUInt32T(data_sectors / t.CUInt64T(sec_per_clus)) - free_count: t.CUInt32T = total_clusters - 1 - res: types.DRESULT = _write_boot_sector(pdrv, total_sectors, sec_per_clus, vol_id, fat_sz) - if res != types.DRESULT.RES_OK: return types.FRESULT.FR_DISK_ERR - res2: types.DRESULT = _write_fsinfo(pdrv, free_count, 3) - if res2 != types.DRESULT.RES_OK: return types.FRESULT.FR_DISK_ERR - boot_backup: t.CArray[t.CUInt8T, 512] - diskio.read(pdrv, c.Addr(boot_backup[0]), 0, 1) - diskio.write(pdrv, c.Addr(boot_backup[0]), 6, 1) - fsinfo_backup: t.CArray[t.CUInt8T, 512] - diskio.read(pdrv, c.Addr(fsinfo_backup[0]), 1, 1) - diskio.write(pdrv, c.Addr(fsinfo_backup[0]), 7, 1) - fat_start: t.CUInt64T = t.CUInt64T(reserved) - res3: types.DRESULT = _init_fat(pdrv, fat_start, fat_sz, 2) - if res3 != types.DRESULT.RES_OK: return types.FRESULT.FR_DISK_ERR - fat2_start: t.CUInt64T = fat_start + t.CUInt64T(fat_sz) - res4: types.DRESULT = _init_fat(pdrv, fat2_start, fat_sz, 2) - if res4 != types.DRESULT.RES_OK: return types.FRESULT.FR_DISK_ERR - root_sector: t.CUInt64T = fat2_start + t.CUInt64T(fat_sz) - res5: types.DRESULT = _init_root_dir(pdrv, root_sector, sec_per_clus) - if res5 != types.DRESULT.RES_OK: return types.FRESULT.FR_DISK_ERR - return types.FRESULT.FR_OK diff --git a/Test/Kernel/drivers/fs/fat32/fat32_part.vp b/Test/Kernel/drivers/fs/fat32/fat32_part.vp deleted file mode 100644 index 611270cc..00000000 --- a/Test/Kernel/drivers/fs/fat32/fat32_part.vp +++ /dev/null @@ -1,147 +0,0 @@ -from stdint import * -import fat32_types as types -import fat32_diskio as diskio -import string -import t, c - - -MAX_VOLUMES: t.CDefine = 4 -MAX_PARTITIONS: t.CDefine = 4 - -MBR_SIGNATURE: t.CDefine = 0xAA55 -PART_TYPE_FAT32: t.CDefine = 0x0C -PART_TYPE_FAT32_LBA: t.CDefine = 0x0B -PART_TYPE_FAT16: t.CDefine = 0x06 -PART_TYPE_FAT16_LBA: t.CDefine = 0x0E - -class partition_entry: - boot_flag: t.CUInt8T - start_chs: t.CArray[t.CUInt8T, 3] - part_type: t.CUInt8T - end_chs: t.CArray[t.CUInt8T, 3] - start_lba: t.CUInt32T - total_sectors: t.CUInt32T - -drive_pdrv: t.CArray[t.CUInt8T, MAX_VOLUMES] -drive_num_parts: t.CArray[t.CInt, MAX_VOLUMES] -drive_letter_map: t.CArray[t.CChar, MAX_VOLUMES] -volume_mounted: t.CArray[t.CInt, MAX_VOLUMES] -part_types: t.CArray[t.CUInt8T, MAX_VOLUMES * MAX_PARTITIONS] -part_start_lbas: t.CArray[t.CUInt64T, MAX_VOLUMES * MAX_PARTITIONS] -part_totals: t.CArray[t.CUInt64T, MAX_VOLUMES * MAX_PARTITIONS] -part_is_fat32: t.CArray[t.CInt, MAX_VOLUMES * MAX_PARTITIONS] - -num_drives: t.CInt = 0 - -def _init(): - if num_drives > 0: return - i: t.CInt - for i in range(MAX_VOLUMES): - drive_letter_map[i] = 0 - volume_mounted[i] = 0 - drive_pdrv[i] = 0 - drive_num_parts[i] = 0 - j: t.CInt - for j in range(MAX_VOLUMES * MAX_PARTITIONS): - part_types[j] = 0 - part_start_lbas[j] = 0 - part_totals[j] = 0 - part_is_fat32[j] = 0 - -def _part_idx(drive: t.CInt, part: t.CInt) -> t.CInt: - return drive * MAX_PARTITIONS + part - -def parse_mbr(pdrv: t.CUInt8T, drive_idx: t.CInt) -> types.FRESULT: - buf: t.CArray[t.CUInt8T, 512] - res: types.DRESULT = diskio.read(pdrv, c.Addr(buf[0]), 0, 1) - if res != types.DRESULT.RES_OK: return types.FRESULT.FR_DISK_ERR - if buf[0] == 0xEB or buf[0] == 0xE9: - return types.FRESULT.FR_NO_FILESYSTEM - sig: t.CUInt16T = t.CUInt16T(buf[510]) | (t.CUInt16T(buf[511]) << 8) - if sig != MBR_SIGNATURE: return types.FRESULT.FR_NO_FILESYSTEM - drive_pdrv[drive_idx] = pdrv - drive_num_parts[drive_idx] = 0 - i: t.CInt - for i in range(4): - base: t.CUInt32T = 446 + t.CUInt32T(i * 16) - ptype: t.CUInt8T = buf[base + 4] - slba: t.CUInt32T = t.CUInt32T(buf[base + 8]) | (t.CUInt32T(buf[base + 9]) << 8) | (t.CUInt32T(buf[base + 10]) << 16) | (t.CUInt32T(buf[base + 11]) << 24) - tsec: t.CUInt32T = t.CUInt32T(buf[base + 12]) | (t.CUInt32T(buf[base + 13]) << 8) | (t.CUInt32T(buf[base + 14]) << 16) | (t.CUInt32T(buf[base + 15]) << 24) - if ptype != 0 and tsec > 0: - pi: t.CInt = drive_num_parts[drive_idx] - if pi < MAX_PARTITIONS: - pidx: t.CInt = _part_idx(drive_idx, pi) - part_types[pidx] = ptype - part_start_lbas[pidx] = t.CUInt64T(slba) - part_totals[pidx] = t.CUInt64T(tsec) - part_is_fat32[pidx] = 1 if (ptype == PART_TYPE_FAT32 or ptype == PART_TYPE_FAT32_LBA) else 0 - drive_num_parts[drive_idx] = pi + 1 - return types.FRESULT.FR_OK - -def scan_drives() -> types.FRESULT: - _init() - global num_drives - num_drives = 0 - pdrv: t.CUInt8T - for pdrv in range(MAX_VOLUMES): - res: types.DRESULT = diskio.init(pdrv) - if res != types.DRESULT.RES_OK: continue - res2: types.FRESULT = parse_mbr(pdrv, num_drives) - if res2 == types.FRESULT.FR_OK and drive_num_parts[num_drives] > 0: - drive_letter_map[num_drives] = t.CChar(ord('C') + num_drives) - else: - drive_pdrv[num_drives] = pdrv - drive_num_parts[num_drives] = 1 - pidx: t.CInt = _part_idx(num_drives, 0) - part_types[pidx] = PART_TYPE_FAT32_LBA - part_start_lbas[pidx] = 0 - part_totals[pidx] = 0 - part_is_fat32[pidx] = 1 - drive_letter_map[num_drives] = t.CChar(ord('C') + num_drives) - num_drives = num_drives + 1 - if num_drives >= MAX_VOLUMES: break - return types.FRESULT.FR_OK - -def get_drive(letter: t.CChar) -> t.CInt: - _init() - i: t.CInt - for i in range(num_drives): - if drive_letter_map[i] == letter or drive_letter_map[i] == (letter - 32) or drive_letter_map[i] == (letter + 32): - return i - return -1 - -def get_pdrv(letter: t.CChar) -> t.CUInt8T: - idx: t.CInt = get_drive(letter) - if idx < 0: return 0 - return drive_pdrv[idx] - -def get_partition_start(letter: t.CChar, part_idx: t.CInt) -> t.CUInt64T: - idx: t.CInt = get_drive(letter) - if idx < 0: return 0 - if part_idx >= drive_num_parts[idx]: return 0 - pidx: t.CInt = _part_idx(idx, part_idx) - return part_start_lbas[pidx] - -def get_partition_count(letter: t.CChar) -> t.CInt: - idx: t.CInt = get_drive(letter) - if idx < 0: return 0 - return drive_num_parts[idx] - -def is_partition_fat32(letter: t.CChar, part_idx: t.CInt) -> t.CInt: - idx: t.CInt = get_drive(letter) - if idx < 0: return 0 - if part_idx >= drive_num_parts[idx]: return 0 - pidx: t.CInt = _part_idx(idx, part_idx) - return part_is_fat32[pidx] - -def get_drive_count() -> t.CInt: - return num_drives - -def get_drive_letter(idx: t.CInt) -> t.CChar: - if idx < 0 or idx >= num_drives: return 0 - return drive_letter_map[idx] - -def set_drive_letter(idx: t.CInt, letter: t.CChar) -> types.FRESULT: - if idx < 0 or idx >= num_drives: return types.FRESULT.FR_INVALID_PARAMETER - drive_letter_map[idx] = letter - return types.FRESULT.FR_OK diff --git a/Test/Kernel/drivers/fs/fat32/fat32_time.vp b/Test/Kernel/drivers/fs/fat32/fat32_time.vp deleted file mode 100644 index 30e1e7a5..00000000 --- a/Test/Kernel/drivers/fs/fat32/fat32_time.vp +++ /dev/null @@ -1,64 +0,0 @@ -from stdint import * -import t, c -import asm - - -rtc_cmos_addr: t.CUInt16T = 0x70 -rtc_cmos_data: t.CUInt16T = 0x71 - -def cmos_read(reg: t.CUInt8T) -> t.CUInt8T: - asm.outb(rtc_cmos_addr, reg) - return asm.inb(rtc_cmos_data) - -def bcd_to_bin(bcd: t.CUInt8T) -> t.CUInt8T: - return (bcd >> 4) * 10 + (bcd & 0x0F) - -def get_rtc_time() -> t.CUInt32T: - while cmos_read(0x0A) & 0x80: pass - sec: t.CUInt8T = cmos_read(0x00) - min_: t.CUInt8T = cmos_read(0x02) - hour: t.CUInt8T = cmos_read(0x04) - day: t.CUInt8T = cmos_read(0x07) - mon: t.CUInt8T = cmos_read(0x08) - year: t.CUInt8T = cmos_read(0x09) - reg_b: t.CUInt8T = cmos_read(0x0B) - if not (reg_b & 0x04): - sec = bcd_to_bin(sec) - min_ = bcd_to_bin(min_) - hour = bcd_to_bin(hour) - day = bcd_to_bin(day) - mon = bcd_to_bin(mon) - year = bcd_to_bin(year) - fat_year: t.CUInt16T = t.CUInt16T(year) + 2000 - 1980 - if fat_year > 127: fat_year = 127 - fat_date: t.CUInt16T = (fat_year << 9) | (t.CUInt16T(mon) << 5) | t.CUInt16T(day) - fat_time: t.CUInt16T = (t.CUInt16T(hour) << 11) | (t.CUInt16T(min_) << 5) | (t.CUInt16T(sec) / 2) - return (t.CUInt32T(fat_date) << 16) | t.CUInt32T(fat_time) - -def get_fattime() -> t.CUInt32T: - return get_rtc_time() - -def to_year(ft: t.CUInt32T) -> t.CUInt16T: - return t.CUInt16T((ft >> 25) & 0x7F) + 1980 - -def to_month(ft: t.CUInt32T) -> t.CUInt8T: - return t.CUInt8T((ft >> 21) & 0x0F) - -def to_day(ft: t.CUInt32T) -> t.CUInt8T: - return t.CUInt8T((ft >> 16) & 0x1F) - -def to_hour(ft: t.CUInt32T) -> t.CUInt8T: - return t.CUInt8T((ft >> 11) & 0x1F) - -def to_minute(ft: t.CUInt32T) -> t.CUInt8T: - return t.CUInt8T((ft >> 5) & 0x3F) - -def to_second(ft: t.CUInt32T) -> t.CUInt8T: - return t.CUInt8T((ft & 0x1F) * 2) - -def make(year: t.CUInt16T, month: t.CUInt8T, day: t.CUInt8T, hour: t.CUInt8T, minute: t.CUInt8T, second: t.CUInt8T) -> t.CUInt32T: - fat_year: t.CUInt16T = year - 1980 - if fat_year > 127: fat_year = 127 - fat_date: t.CUInt16T = (fat_year << 9) | (t.CUInt16T(month) << 5) | t.CUInt16T(day) - fat_time: t.CUInt16T = (t.CUInt16T(hour) << 11) | (t.CUInt16T(minute) << 5) | (t.CUInt16T(second) / 2) - return (t.CUInt32T(fat_date) << 16) | t.CUInt32T(fat_time) diff --git a/Test/Kernel/drivers/fs/fat32/fat32_types.vp b/Test/Kernel/drivers/fs/fat32/fat32_types.vp deleted file mode 100644 index b2a87880..00000000 --- a/Test/Kernel/drivers/fs/fat32/fat32_types.vp +++ /dev/null @@ -1,1698 +0,0 @@ -from stdint import * -import t, c -import spinlock -import string -import fat32_diskio as diskio -import fat32_time as ftime - - -def _read32(buf: t.CUInt8T | t.CPtr, off: t.CUInt32T) -> t.CUInt32T: - return t.CUInt32T(buf[off]) | (t.CUInt32T(buf[off + 1]) << 8) | (t.CUInt32T(buf[off + 2]) << 16) | (t.CUInt32T(buf[off + 3]) << 24) - -def _read16(buf: t.CUInt8T | t.CPtr, off: t.CUInt32T) -> t.CUInt16T: - return t.CUInt16T(buf[off]) | (t.CUInt16T(buf[off + 1]) << 8) - -def _write32(buf: t.CUInt8T | t.CPtr, off: t.CUInt32T, val: t.CUInt32T): - buf[off + 0] = t.CUInt8T(val & 0xFF) - buf[off + 1] = t.CUInt8T((val >> 8) & 0xFF) - buf[off + 2] = t.CUInt8T((val >> 16) & 0xFF) - buf[off + 3] = t.CUInt8T((val >> 24) & 0xFF) - -def _write16(buf: t.CUInt8T | t.CPtr, off: t.CUInt32T, val: t.CUInt16T): - buf[off + 0] = t.CUInt8T(val & 0xFF) - buf[off + 1] = t.CUInt8T((val >> 8) & 0xFF) - - -SECTOR_SIZE: t.CDefine = 512 -ENTRY_SIZE: t.CDefine = 32 -CLUSTER_FREE: t.CDefine = 0x00000000 -CLUSTER_EOC_MIN: t.CDefine = 0x0FFFFFF8 -CLUSTER_EOC_MAX: t.CDefine = 0x0FFFFFFF -CLUSTER_BAD: t.CDefine = 0x0FFFFFF7 -CLUSTER_ROOT: t.CDefine = 0x00000002 -FAT_MASK: t.CDefine = 0x0FFFFFFF -FAT_RESERVED: t.CDefine = 0xF0000000 - -MAX_LFN: t.CDefine = 255 -LFN_ENTRY_CHARS: t.CDefine = 13 -LFN_ATTR: t.CDefine = 0x0F -LFN_FLAG_LAST: t.CDefine = 0x40 -SFN_NAME_LEN: t.CDefine = 8 -SFN_EXT_LEN: t.CDefine = 3 -SFN_DELETED: t.CDefine = 0xE5 -SFN_DOT: t.CDefine = 0x05 -SFN_FREE: t.CDefine = 0x00 - -MAX_HANDLES: t.CDefine = 32 -MAX_LOCKS: t.CDefine = 32 -PATH_MAX: t.CDefine = 260 -NAME_MAX: t.CDefine = 255 -DEPTH_MAX: t.CDefine = 32 - -FA_READ: t.CDefine = 0x01 -FA_WRITE: t.CDefine = 0x02 -FA_OPEN_EXISTING: t.CDefine = 0x00 -FA_CREATE_NEW: t.CDefine = 0x04 -FA_CREATE_ALWAYS: t.CDefine = 0x08 -FA_OPEN_ALWAYS: t.CDefine = 0x10 -FA_OPEN_APPEND: t.CDefine = 0x30 -FA_READ_MASK: t.CDefine = 0x0F - -AM_RDO: t.CDefine = 0x01 -AM_HID: t.CDefine = 0x02 -AM_SYS: t.CDefine = 0x04 -AM_VOL: t.CDefine = 0x08 -AM_DIR: t.CDefine = 0x10 -AM_ARC: t.CDefine = 0x20 -AM_LFN: t.CDefine = 0x0F -AM_ANY: t.CDefine = 0x3F - -FS_FAT32: t.CDefine = 3 - -CTRL_SYNC: t.CDefine = 0 -GET_SECTOR_COUNT: t.CDefine = 1 -GET_SECTOR_SIZE: t.CDefine = 2 -GET_BLOCK_SIZE: t.CDefine = 3 -CTRL_TRIM: t.CDefine = 4 - -STA_NOINIT: t.CDefine = 0x01 -STA_NODISK: t.CDefine = 0x02 -STA_PROTECT: t.CDefine = 0x04 - -DEV_DISK: t.CDefine = 0 - -ENTRIES_PER_SECTOR: t.CDefine = 512 / 32 - - -class FRESULT(t.CEnum): - FR_OK: t.State = 0 - FR_DISK_ERR: t.State - FR_INT_ERR: t.State - FR_NOT_READY: t.State - FR_NO_FILE: t.State - FR_NO_PATH: t.State - FR_INVALID_NAME: t.State - FR_DENIED: t.State - FR_EXIST: t.State - FR_INVALID_OBJECT: t.State - FR_WRITE_PROTECTED: t.State - FR_INVALID_DRIVE: t.State - FR_NOT_ENABLED: t.State - FR_NO_FILESYSTEM: t.State - FR_MKFS_ABORTED: t.State - FR_TIMEOUT: t.State - FR_LOCKED: t.State - FR_NOT_ENOUGH_CORE: t.State - FR_TOO_MANY_OPEN_FILES: t.State - FR_INVALID_PARAMETER: t.State - -class DRESULT(t.CEnum): - RES_OK: t.State = 0 - RES_ERROR: t.State - RES_WRPRT: t.State - RES_NOTRDY: t.State - RES_PARERR: t.State - - -@c.Attribute(t.attr.packed) -class bpb: - BS_jmpBoot: t.CArray[t.CUInt8T, 3] - BS_OEMName: t.CArray[t.CChar, 8] - BPB_BytsPerSec: t.CUInt16T - BPB_SecPerClus: t.CUInt8T - BPB_RsvdSecCnt: t.CUInt16T - BPB_NumFATs: t.CUInt8T - BPB_RootEntCnt: t.CUInt16T - BPB_TotSec16: t.CUInt16T - BPB_Media: t.CUInt8T - BPB_FATSz16: t.CUInt16T - BPB_SecPerTrk: t.CUInt16T - BPB_NumHeads: t.CUInt16T - BPB_HiddSec: t.CUInt32T - BPB_TotSec32: t.CUInt32T - BPB_FATSz32: t.CUInt32T - BPB_ExtFlags: t.CUInt16T - BPB_FSVer: t.CUInt16T - BPB_RootClus: t.CUInt32T - BPB_FSInfo: t.CUInt16T - BPB_BkBootSec: t.CUInt16T - BPB_Reserved: t.CArray[t.CUInt8T, 12] - BS_DrvNum: t.CUInt8T - BS_Reserved1: t.CUInt8T - BS_BootSig: t.CUInt8T - BS_VolID: t.CUInt32T - BS_VolLab: t.CArray[t.CChar, 11] - BS_FilSysType: t.CArray[t.CChar, 8] - -@c.Attribute(t.attr.packed) -class fsinfo: - FSI_LeadSig: t.CUInt32T - FSI_Reserved1: t.CArray[t.CUInt8T, 480] - FSI_StrucSig: t.CUInt32T - FSI_Free_Count: t.CUInt32T - FSI_Nxt_Free: t.CUInt32T - FSI_Reserved2: t.CArray[t.CUInt8T, 12] - FSI_TrailSig: t.CUInt32T - -@c.Attribute(t.attr.packed) -class dirent: - DIR_Name: t.CArray[t.CChar, 11] - DIR_Attr: t.CUInt8T - DIR_NTRes: t.CUInt8T - DIR_CrtTimeTenth: t.CUInt8T - DIR_CrtTime: t.CUInt16T - DIR_CrtDate: t.CUInt16T - DIR_LstAccDate: t.CUInt16T - DIR_FstClusHI: t.CUInt16T - DIR_WrtTime: t.CUInt16T - DIR_WrtDate: t.CUInt16T - DIR_FstClusLO: t.CUInt16T - DIR_FileSize: t.CUInt32T - -@c.Attribute(t.attr.packed) -class lfn_entry: - LDIR_Ord: t.CUInt8T - LDIR_Name1: t.CArray[t.CUInt16T, 5] - LDIR_Attr: t.CUInt8T - LDIR_Type: t.CUInt8T - LDIR_Chksum: t.CUInt8T - LDIR_Name2: t.CArray[t.CUInt16T, 6] - LDIR_FstClusLO: t.CUInt16T - LDIR_Name3: t.CArray[t.CUInt16T, 2] - - -def sfn_checksum(name: t.CConst | t.CChar | t.CPtr) -> t.CUInt8T: - sum: t.CUInt8T = 0 - i: t.CInt - for i in range(11): - sum = ((sum & 1) << 7) + (sum >> 1) + name[i] - return sum - -def uni2oem_placeholder(uni: t.CUInt16T, cp: t.CUInt16T) -> t.CUInt16T: - if uni < 0x80: return uni - return t.CUInt16T(0x003F) - -def lfn_get_char(entry_bytes: t.CUInt8T | t.CPtr, idx: t.CInt) -> t.CUInt16T: - if idx < 5: - off: t.CInt = 1 + idx * 2 - elif idx < 11: - off = 14 + (idx - 5) * 2 - else: - off = 28 + (idx - 11) * 2 - lo: t.CUInt8T = c.Deref(t.CUInt8T(t.CUInt64T(entry_bytes) + off, t.CPtr)) - hi: t.CUInt8T = c.Deref(t.CUInt8T(t.CUInt64T(entry_bytes) + off + 1, t.CPtr)) - return t.CUInt16T(lo) | t.CUInt16T(t.CUInt16T(hi) << 8) - -def lfn_set_char(entry_bytes: t.CUInt8T | t.CPtr, idx: t.CInt, ch: t.CUInt16T): - if idx < 5: - off: t.CInt = 1 + idx * 2 - elif idx < 11: - off = 14 + (idx - 5) * 2 - else: - off = 28 + (idx - 11) * 2 - c.Set(t.CUInt8T(t.CUInt64T(entry_bytes) + off, t.CPtr), t.CUInt8T(ch & 0xFF)) - c.Set(t.CUInt8T(t.CUInt64T(entry_bytes) + off + 1, t.CPtr), t.CUInt8T(ch >> 8)) - -def lfn_extract(entry_bytes: t.CUInt8T | t.CPtr, lfn: t.CUInt16T | t.CPtr, ord_val: t.CUInt8T) -> t.CInt: - seq: t.CInt = (ord_val & 0x3F) - 1 - base: t.CInt = seq * LFN_ENTRY_CHARS - i: t.CInt - for i in range(LFN_ENTRY_CHARS): - ch: t.CUInt16T = lfn_get_char(entry_bytes, i) - if ch == 0x0000 or ch == 0xFFFF: - c.Set(t.CUInt16T(t.CUInt64T(lfn) + (base + i) * 2, t.CPtr), 0) - return base + i - c.Set(t.CUInt16T(t.CUInt64T(lfn) + (base + i) * 2, t.CPtr), ch) - if ord_val & LFN_FLAG_LAST: - c.Set(t.CUInt16T(t.CUInt64T(lfn) + (base + LFN_ENTRY_CHARS) * 2, t.CPtr), 0) - return base + LFN_ENTRY_CHARS - -def sfn_from_lfn(lfn: t.CConst | t.CChar | t.CPtr, sfn: t.CChar | t.CPtr): - string.memset(sfn, 0x20, 11) - if c.Deref(lfn) == '.' and c.Deref(lfn + 1) == 0: - sfn[0] = '.'; sfn[11] = 0; return - if c.Deref(lfn) == '.' and c.Deref(lfn + 1) == '.' and c.Deref(lfn + 2) == 0: - sfn[0] = '.'; sfn[1] = '.'; sfn[11] = 0; return - si: t.CInt = 0 - dot_pos: t.CInt = -1 - i: t.CInt = 0 - ext_i: t.CInt = 0 - for ch in lfn: - if ch == '.': - dot_pos = si; si += 1; ext_i = 0; continue - uc: t.CChar - if ch >= 'a' and ch <= 'z': uc = ch - 32 - elif ch == ' ': uc = '_' - elif ch == '+' or ch == ',' or ch == ';' or ch == '=' or ch == '[' or ch == ']': uc = '_' - else: uc = ch - if dot_pos < 0: - if i < 8: sfn[i] = uc; i += 1 - else: - if ext_i < 3: sfn[8 + ext_i] = uc; ext_i += 1 - si += 1 - sfn[11] = 0 - -def sfn_to_str(sfn: t.CConst | t.CChar | t.CPtr, out: t.CChar | t.CPtr): - i: t.CInt = 0 - j: t.CInt = 0 - for i in range(8): - if sfn[i] == 0x20: break - if sfn[i] == 0x05: out[j] = 0xE5 - else: out[j] = sfn[i] - j += 1 - if sfn[8] != 0x20: - out[j] = '.'; j += 1 - for i in range(8, 11): - if sfn[i] == 0x20: break - out[j] = sfn[i]; j += 1 - out[j] = 0 - -def _split_path(path: t.CConst | t.CChar | t.CPtr, parent_out: t.CChar | t.CPtr, name_out: t.CChar | t.CPtr): - pi: t.CInt = 0; last_sep: t.CInt = -1 - for ch in path: - parent_out[pi] = ch - if ch == '/' or ch == '\\': last_sep = pi - pi += 1 - parent_out[pi] = 0 - if last_sep >= 0: - fi: t.CInt - for fi in range(last_sep + 1, pi): name_out[fi - last_sep - 1] = path[fi] - name_out[pi - last_sep - 1] = 0 - parent_out[last_sep] = 0 - else: - fi2: t.CInt - for fi2 in range(pi): name_out[fi2] = path[fi2] - name_out[pi] = 0 - parent_out[0] = '/'; parent_out[1] = 0 - - -class fileinfo: - file_size: t.CUInt32T = 0 - attr: t.CUInt8T = 0 - ctime: t.CUInt16T = 0 - cdate: t.CUInt16T = 0 - mtime: t.CUInt16T = 0 - mdate: t.CUInt16T = 0 - adate: t.CUInt16T = 0 - fname: t.CArray[t.CChar, 256] - altname: t.CArray[t.CChar, 13] - -class filelock: - cluster: t.CUInt32T = 0 - dir_sector: t.CUInt64T = 0 - dir_offset: t.CUInt32T = 0 - in_use: t.CInt = 0 - shared_count: t.CInt = 0 - exclusive: t.CInt = 0 - - -@t.Object -class volinfo: - lock: spinlock._spinlock - mounted: t.CInt = 0 - pdrv: t.CUInt8T = 0 - sector_size: t.CUInt16T = 512 - cluster_size: t.CUInt32T = 0 - cluster_sectors: t.CUInt8T = 0 - fat_start: t.CUInt64T = 0 - fat_size: t.CUInt32T = 0 - data_start: t.CUInt64T = 0 - root_cluster: t.CUInt32T = 2 - total_sectors: t.CUInt64T = 0 - total_clusters: t.CUInt32T = 0 - free_clusters: t.CUInt32T = 4294967295 - last_alloc: t.CUInt32T = 2 - fsinfo_sector: t.CUInt16T = 0 - backup_sector: t.CUInt16T = 6 - vol_id: t.CUInt32T = 0 - vol_label: t.CArray[t.CChar, 12] - num_fats: t.CUInt8T = 2 - reserved_sectors: t.CUInt16T = 0 - hidden_sectors: t.CUInt32T = 0 - winsect: t.CUInt64T = 0xFFFFFFFFFFFFFFFF - win_dirty: t.CInt = 0 - win: t.CArray[t.CUInt8T, 512] - fat_winsect: t.CUInt64T = 0xFFFFFFFFFFFFFFFF - fat_win_dirty: t.CInt = 0 - fat_win: t.CArray[t.CUInt8T, 512] - metadata: t.CUInt32T = 0 - last_error: t.CUInt32T = 0 - - def win_read(self, sector: t.CUInt64T) -> FRESULT: - if self.winsect == sector: return FRESULT.FR_OK - if self.win_dirty: - res: FRESULT = self.win_flush() - if res != FRESULT.FR_OK: return res - abs_sector: t.CUInt64T = sector + t.CUInt64T(self.hidden_sectors) - self.lock.lock() - win_addr: t.CPtr = c.Addr(self.win[0]) - res2: DRESULT = diskio.read(self.pdrv, win_addr, t.CUInt32T(abs_sector), 1) - self.lock.unlock() - if res2 != DRESULT.RES_OK: return FRESULT.FR_DISK_ERR - self.winsect = sector - return FRESULT.FR_OK - - def win_flush(self) -> FRESULT: - if not self.win_dirty: return FRESULT.FR_OK - abs_sector: t.CUInt64T = self.winsect + t.CUInt64T(self.hidden_sectors) - self.lock.lock() - res: DRESULT = diskio.write(self.pdrv, c.Addr(self.win[0]), t.CUInt32T(abs_sector), 1) - self.lock.unlock() - if res != DRESULT.RES_OK: return FRESULT.FR_DISK_ERR - self.win_dirty = 0 - return FRESULT.FR_OK - - def fat_win_read(self, sector: t.CUInt64T) -> FRESULT: - if self.fat_winsect == sector: return FRESULT.FR_OK - if self.fat_win_dirty: - res: FRESULT = self.fat_win_flush() - if res != FRESULT.FR_OK: return res - abs_sector: t.CUInt64T = sector + t.CUInt64T(self.hidden_sectors) - self.lock.lock() - res2: DRESULT = diskio.read(self.pdrv, c.Addr(self.fat_win[0]), t.CUInt32T(abs_sector), 1) - self.lock.unlock() - if res2 != DRESULT.RES_OK: return FRESULT.FR_DISK_ERR - self.fat_winsect = sector - return FRESULT.FR_OK - - def fat_win_flush(self) -> FRESULT: - if not self.fat_win_dirty: return FRESULT.FR_OK - abs_sector: t.CUInt64T = self.fat_winsect + t.CUInt64T(self.hidden_sectors) - self.lock.lock() - res: DRESULT = diskio.write(self.pdrv, c.Addr(self.fat_win[0]), t.CUInt32T(abs_sector), 1) - self.lock.unlock() - if res != DRESULT.RES_OK: return FRESULT.FR_DISK_ERR - self.fat_win_dirty = 0 - return FRESULT.FR_OK - - def flush_all(self) -> FRESULT: - res: FRESULT = self.win_flush() - if res != FRESULT.FR_OK: return res - return self.fat_win_flush() - - def fat_read(self, cluster: t.CUInt32T) -> t.CUInt32T: - if cluster < 2 or cluster >= self.total_clusters + 2: return 0 - fat_offset: t.CUInt64T = t.CUInt64T(cluster) * 4 - fat_sector: t.CUInt64T = self.fat_start + (fat_offset / 512) - fat_offset_in_sector: t.CUInt32T = t.CUInt32T(fat_offset % 512) - res: FRESULT = self.fat_win_read(fat_sector) - if res != FRESULT.FR_OK: return 0 - return _read32(c.Addr(self.fat_win[0]), fat_offset_in_sector) & FAT_MASK - - def fat_write(self, cluster: t.CUInt32T, value: t.CUInt32T) -> FRESULT: - if cluster < 2 or cluster >= self.total_clusters + 2: return FRESULT.FR_INVALID_PARAMETER - fat_offset: t.CUInt64T = t.CUInt64T(cluster) * 4 - fat_sector: t.CUInt64T = self.fat_start + (fat_offset / 512) - fat_offset_in_sector: t.CUInt32T = t.CUInt32T(fat_offset % 512) - res: FRESULT = self.fat_win_read(fat_sector) - if res != FRESULT.FR_OK: return res - old: t.CUInt32T = _read32(c.Addr(self.fat_win[0]), fat_offset_in_sector) - new_val: t.CUInt32T = (old & FAT_RESERVED) | (value & FAT_MASK) - _write32(c.Addr(self.fat_win[0]), fat_offset_in_sector, new_val) - self.fat_win_dirty = 1 - res = self.fat_win_flush() - if res != FRESULT.FR_OK: return res - if self.num_fats >= 2: - mirror_sector: t.CUInt64T = fat_sector + t.CUInt64T(self.fat_size) - res2: FRESULT = self.fat_win_read(mirror_sector) - if res2 != FRESULT.FR_OK: return res2 - mirror_old: t.CUInt32T = _read32(c.Addr(self.fat_win[0]), fat_offset_in_sector) - mirror_new: t.CUInt32T = (mirror_old & FAT_RESERVED) | (value & FAT_MASK) - _write32(c.Addr(self.fat_win[0]), fat_offset_in_sector, mirror_new) - self.fat_win_dirty = 1 - res3: FRESULT = self.fat_win_flush() - if res3 != FRESULT.FR_OK: return res3 - return FRESULT.FR_OK - - def cluster_alloc(self) -> t.CUInt32T: - clust: t.CUInt32T = self.last_alloc - i: t.CUInt32T - for i in range(self.total_clusters): - clust += 1 - if clust >= self.total_clusters + 2: clust = 2 - entry: t.CUInt32T = self.fat_read(clust) - if entry == CLUSTER_FREE: - res: FRESULT = self.fat_write(clust, CLUSTER_EOC_MAX) - if res != FRESULT.FR_OK: return 0 - self.last_alloc = clust - if self.free_clusters != 0xFFFFFFFF: self.free_clusters -= 1 - return clust - return 0 - - def cluster_free_chain(self, start_cluster: t.CUInt32T) -> FRESULT: - if start_cluster < 2: return FRESULT.FR_OK - clust: t.CUInt32T = start_cluster - while clust >= 2 and clust < CLUSTER_EOC_MIN: - next_clust: t.CUInt32T = self.fat_read(clust) - if next_clust == 0: break - res: FRESULT = self.fat_write(clust, CLUSTER_FREE) - if res != FRESULT.FR_OK: return res - if self.free_clusters != 0xFFFFFFFF: self.free_clusters += 1 - clust = next_clust - return FRESULT.FR_OK - - def cluster_extend(self, cluster: t.CUInt32T) -> t.CUInt32T: - new_clust: t.CUInt32T = self.cluster_alloc() - if new_clust == 0: return 0 - if cluster >= 2: - res: FRESULT = self.fat_write(cluster, new_clust) - if res != FRESULT.FR_OK: - self.fat_write(new_clust, CLUSTER_FREE) - return 0 - return new_clust - - def cluster_get_next(self, cluster: t.CUInt32T) -> t.CUInt32T: - if cluster < 2: return 0 - entry: t.CUInt32T = self.fat_read(cluster) - if entry >= CLUSTER_EOC_MIN and entry <= CLUSTER_EOC_MAX: return 0 - if entry == CLUSTER_FREE or entry == CLUSTER_BAD: return 0 - return entry - - def cluster_to_sector(self, cluster: t.CUInt32T) -> t.CUInt64T: - if cluster < 2: return 0 - return self.data_start + t.CUInt64T(cluster - 2) * t.CUInt64T(self.cluster_sectors) - - def entries_per_cluster(self) -> t.CUInt32T: - return t.CUInt32T(self.cluster_sectors) * (512 / ENTRY_SIZE) - - def is_eoc(self, cluster: t.CUInt32T) -> t.CInt: - return 1 if (cluster >= CLUSTER_EOC_MIN and cluster <= CLUSTER_EOC_MAX) else 0 - - def fsinfo_read(self) -> FRESULT: - if self.fsinfo_sector == 0: return FRESULT.FR_OK - res: FRESULT = self.win_read(t.CUInt64T(self.fsinfo_sector)) - if res != FRESULT.FR_OK: return res - lead_sig: t.CUInt32T = _read32(c.Addr(self.win[0]), 0) - struc_sig: t.CUInt32T = _read32(c.Addr(self.win[0]), 484) - trail_sig: t.CUInt32T = _read32(c.Addr(self.win[0]), 508) - if lead_sig != 0x41615252 or struc_sig != 0x61417272 or trail_sig != 0xAA550000: - self.free_clusters = 0xFFFFFFFF - self.last_alloc = 2 - return FRESULT.FR_OK - free_count: t.CUInt32T = _read32(c.Addr(self.win[0]), 488) - nxt_free: t.CUInt32T = _read32(c.Addr(self.win[0]), 492) - if free_count <= self.total_clusters: self.free_clusters = free_count - if nxt_free >= 2 and nxt_free < self.total_clusters + 2: self.last_alloc = nxt_free - return FRESULT.FR_OK - - def fsinfo_write(self) -> FRESULT: - if self.fsinfo_sector == 0: return FRESULT.FR_OK - res: FRESULT = self.win_read(t.CUInt64T(self.fsinfo_sector)) - if res != FRESULT.FR_OK: return res - _write32(c.Addr(self.win[0]), 0, 0x41615252) - _write32(c.Addr(self.win[0]), 484, 0x61417272) - _write32(c.Addr(self.win[0]), 488, self.free_clusters) - _write32(c.Addr(self.win[0]), 492, self.last_alloc) - _write32(c.Addr(self.win[0]), 508, 0xAA550000) - self.win_dirty = 1 - return self.win_flush() - - def count_free_clusters(self) -> t.CUInt32T: - free_cnt: t.CUInt32T = 0 - clust: t.CUInt32T - for clust in range(2, self.total_clusters + 2): - entry: t.CUInt32T = self.fat_read(clust) - if entry == CLUSTER_FREE: free_cnt += 1 - self.free_clusters = free_cnt - return free_cnt - - def mount(self) -> FRESULT: - if self.mounted: return FRESULT.FR_OK - res: DRESULT = diskio.status(self.pdrv) - if res != DRESULT.RES_OK: - res = diskio.init(self.pdrv) - if res != DRESULT.RES_OK: return FRESULT.FR_NOT_READY - res2: FRESULT = self.win_read(0) - if res2 != FRESULT.FR_OK: return FRESULT.FR_DISK_ERR - bps: t.CUInt16T = _read16(c.Addr(self.win[0]), 11) - spc: t.CUInt8T = self.win[13] - rsc: t.CUInt16T = _read16(c.Addr(self.win[0]), 14) - nf: t.CUInt8T = self.win[16] - root_ent: t.CUInt16T = _read16(c.Addr(self.win[0]), 17) - fat16sz: t.CUInt16T = _read16(c.Addr(self.win[0]), 22) - tot32: t.CUInt32T = _read32(c.Addr(self.win[0]), 32) - fat32sz: t.CUInt32T = _read32(c.Addr(self.win[0]), 36) - root_clus: t.CUInt32T = _read32(c.Addr(self.win[0]), 44) - sig0: t.CUInt8T = self.win[510] - sig1: t.CUInt8T = self.win[511] - if bps != 512: return FRESULT.FR_NO_FILESYSTEM - if spc == 0 or (spc & (spc - 1)) != 0: return FRESULT.FR_NO_FILESYSTEM - if rsc == 0: return FRESULT.FR_NO_FILESYSTEM - if nf == 0: return FRESULT.FR_NO_FILESYSTEM - if root_ent != 0 or fat16sz != 0: return FRESULT.FR_NO_FILESYSTEM - if fat32sz == 0: return FRESULT.FR_NO_FILESYSTEM - if tot32 == 0: return FRESULT.FR_NO_FILESYSTEM - if sig0 != 0x55 or sig1 != 0xAA: return FRESULT.FR_NO_FILESYSTEM - fsinfo_sec: t.CUInt16T = _read16(c.Addr(self.win[0]), 48) - bkboot_sec: t.CUInt16T = _read16(c.Addr(self.win[0]), 50) - self.sector_size = 512 - self.cluster_sectors = spc - self.cluster_size = t.CUInt32T(spc) * 512 - self.num_fats = nf - self.reserved_sectors = rsc - self.fat_size = fat32sz - self.fat_start = t.CUInt64T(rsc) - self.total_sectors = t.CUInt64T(tot32) - self.root_cluster = root_clus - self.fsinfo_sector = fsinfo_sec - self.backup_sector = bkboot_sec - self.vol_id = _read32(c.Addr(self.win[0]), 67) - data_sectors: t.CUInt64T = self.total_sectors - t.CUInt64T(rsc) - t.CUInt64T(t.CUInt64T(nf) * t.CUInt64T(fat32sz)) - self.total_clusters = t.CUInt32T(data_sectors / t.CUInt64T(spc)) - self.data_start = self.fat_start + t.CUInt64T(t.CUInt64T(nf) * t.CUInt64T(fat32sz)) - self.last_alloc = 2 - self.free_clusters = 0xFFFFFFFF - self.fsinfo_read() - self.mounted = 1 - return FRESULT.FR_OK - - def unmount(self) -> FRESULT: - if not self.mounted: return FRESULT.FR_OK - res: FRESULT = self.flush_all() - if res != FRESULT.FR_OK: return res - self.fsinfo_write() - self.mounted = 0 - self.winsect = 0xFFFFFFFFFFFFFFFF - self.win_dirty = 0 - self.fat_winsect = 0xFFFFFFFFFFFFFFFF - self.fat_win_dirty = 0 - return FRESULT.FR_OK - - def _zero_cluster(self, cluster: t.CUInt32T) -> FRESULT: - sector: t.CUInt64T = self.cluster_to_sector(cluster) - s: t.CUInt32T - for s in range(self.cluster_sectors): - res: FRESULT = self.win_read(sector + t.CUInt64T(s)) - if res != FRESULT.FR_OK: return res - string.memset(c.Addr(self.win[0]), 0, 512) - self.win_dirty = 1 - res2: FRESULT = self.win_flush() - if res2 != FRESULT.FR_OK: return res2 - return FRESULT.FR_OK - - def file_cluster_seek(self, first_cluster: t.CUInt32T, pos: t.CUInt32T) -> t.CUInt32T: - if first_cluster < 2: return 0 - cluster: t.CUInt32T = first_cluster - cluster_num: t.CUInt32T = pos / self.cluster_size - i: t.CUInt32T - for i in range(cluster_num): - next_c: t.CUInt32T = self.cluster_get_next(cluster) - if next_c == 0: return 0 - cluster = next_c - return cluster - - def file_find_last_cluster(self, first_cluster: t.CUInt32T) -> t.CUInt32T: - if first_cluster < 2: return 0 - cluster: t.CUInt32T = first_cluster - while True: - next_c: t.CUInt32T = self.cluster_get_next(cluster) - if next_c == 0: return cluster - cluster = next_c - - def _read_entry_from_dir(self, dp: dirobj | t.CPtr) -> FRESULT: - entry_sector: t.CUInt64T = dp.sector + (dp.offset / (512 / ENTRY_SIZE)) - return self.win_read(entry_sector) - - def _write_dirent_now(self, eo: t.CUInt32T): - now: t.CUInt32T = ftime.get_fattime() - fat_time: t.CUInt16T = t.CUInt16T(now & 0xFFFF) - fat_date: t.CUInt16T = t.CUInt16T((now >> 16) & 0xFFFF) - _write16(c.Addr(self.win[0]), eo + 14, fat_time) - _write16(c.Addr(self.win[0]), eo + 16, fat_date) - _write16(c.Addr(self.win[0]), eo + 18, fat_date) - _write16(c.Addr(self.win[0]), eo + 22, fat_time) - _write16(c.Addr(self.win[0]), eo + 24, fat_date) - - def dir_offset_to_sector(self, start_cluster: t.CUInt32T, offset: t.CUInt32T) -> t.CUInt64T: - epc: t.CUInt32T = self.entries_per_cluster() - cluster: t.CUInt32T = start_cluster - cluster_idx: t.CUInt32T = offset / epc - i: t.CUInt32T - for i in range(cluster_idx): - next_c: t.CUInt32T = self.cluster_get_next(cluster) - if next_c == 0: return 0 - cluster = next_c - off_in_cluster: t.CUInt32T = offset % epc - return self.cluster_to_sector(cluster) + t.CUInt64T(off_in_cluster / (512 / ENTRY_SIZE)) - - def dir_next_cluster(self, dp: dirobj | t.CPtr) -> FRESULT: - next_clust: t.CUInt32T = self.cluster_get_next(dp.cluster) - if next_clust == 0: return FRESULT.FR_NO_FILE - dp.cluster = next_clust - dp.sector = self.cluster_to_sector(next_clust) - dp.offset = 0 - return FRESULT.FR_OK - - def dir_open(self, dp: dirobj | t.CPtr, cluster: t.CUInt32T) -> FRESULT: - dp.vol = self - dp.start_cluster = cluster - dp.cluster = cluster - dp.sector = self.cluster_to_sector(cluster) - dp.offset = 0 - dp.is_open = 1 - dp.lfn_ofs = 0xFFFFFFFF - dp.lfn_cluster = 0 - self.winsect = 0xFFFFFFFFFFFFFFFF - return FRESULT.FR_OK - - def dir_read_entry(self, dp: dirobj | t.CPtr, lfn_buf: t.CUInt16T | t.CPtr) -> FRESULT: - lfn_started: t.CInt = 0 - dp.lfn_ofs = 0xFFFFFFFF - dp.lfn_cluster = 0 - while True: - epc: t.CUInt32T = self.entries_per_cluster() - if dp.offset >= epc: - res: FRESULT = self.dir_next_cluster(dp) - if res != FRESULT.FR_OK: return res - entry_sector: t.CUInt64T = dp.sector + (dp.offset / (512 / ENTRY_SIZE)) - entry_offset_in_sector: t.CUInt32T = (dp.offset % (512 / ENTRY_SIZE)) * ENTRY_SIZE - res2: FRESULT = self.win_read(entry_sector) - if res2 != FRESULT.FR_OK: return FRESULT.FR_DISK_ERR - first_byte: t.CUInt8T = self.win[entry_offset_in_sector] - if first_byte == SFN_FREE: - return FRESULT.FR_NO_FILE - attr: t.CUInt8T = self.win[entry_offset_in_sector + 11] - if first_byte == SFN_DELETED: - lfn_started = 0 - dp.lfn_ofs = 0xFFFFFFFF - dp.lfn_cluster = 0 - dp.offset += 1 - continue - if attr == LFN_ATTR: - if lfn_buf: - ord_val: t.CUInt8T = first_byte - if ord_val & LFN_FLAG_LAST: - lfn_started = 1 - dp.lfn_ofs = dp.offset - dp.lfn_cluster = dp.cluster - if lfn_started: - entry_bytes: t.CUInt8T | t.CPtr = t.CUInt8T(c.Addr(self.win[entry_offset_in_sector]), t.CPtr) - lfn_extract(entry_bytes, lfn_buf, ord_val) - dp.offset += 1 - continue - if attr == AM_VOL: - dp.offset += 1 - continue - if dp.lfn_ofs == 0xFFFFFFFF: - dp.lfn_ofs = dp.offset - dp.lfn_cluster = dp.cluster - return FRESULT.FR_OK - - def dir_find(self, dp: dirobj | t.CPtr, name: t.CConst | t.CChar | t.CPtr, lfn_buf: t.CUInt16T | t.CPtr) -> FRESULT: - sfn: t.CArray[t.CChar, 12] - sfn_from_lfn(name, c.Addr(sfn[0])) - _dbg_sfn: t.CArray[t.CChar, 16] - _si: t.CInt - for _si in range(11): - _dbg_sfn[_si] = sfn[_si] - _dbg_sfn[11] = 0 - serial.puts("[dir_find] searching for: ") - serial.puts(name) - serial.puts(" sfn=") - serial.puts(c.Addr(_dbg_sfn[0])) - serial.puts("\n") - _db0: t.CArray[t.CChar, 120] - viperlib.snprintf(c.Addr(_db0), 120, "[dir_find] dp: sect=0x%lx off=%lu clust=%lu winsect=0x%lx\n", dp.sector, dp.offset, dp.cluster, self.winsect) - serial.puts(_db0) - _find_count: t.CInt = 0 - while True: - res: FRESULT = self.dir_read_entry(dp, lfn_buf) - if res != FRESULT.FR_OK: - _db2: t.CArray[t.CChar, 80] - viperlib.snprintf(c.Addr(_db2), 80, "[dir_find] dir_read_entry failed res=%d offset=%lu\n", t.CInt(res), dp.offset) - serial.puts(_db2) - return res - entry_sector: t.CUInt64T = dp.sector + (dp.offset / (512 / ENTRY_SIZE)) - entry_offset_in_sector: t.CUInt32T = (dp.offset % (512 / ENTRY_SIZE)) * ENTRY_SIZE - res2: FRESULT = self.win_read(entry_sector) - if res2 != FRESULT.FR_OK: return FRESULT.FR_DISK_ERR - match_found: t.CInt = 1 - i: t.CInt - for i in range(11): - a: t.CChar = self.win[entry_offset_in_sector + i] - b: t.CChar = sfn[i] - if a >= 'a' and a <= 'z': a = a - 32 - if b >= 'a' and b <= 'z': b = b - 32 - if a != b: - match_found = 0 - break - if match_found: return FRESULT.FR_OK - if dp.offset < 10: - _db3: t.CArray[t.CChar, 80] - _fb: t.CUInt8T = self.win[entry_offset_in_sector] - _at: t.CUInt8T = self.win[entry_offset_in_sector + 11] - viperlib.snprintf(c.Addr(_db3), 80, "[dir_find] off=%lu fb=0x%02x attr=0x%02x sfn=%.11s\n", dp.offset, _fb, _at, c.Addr(self.win[entry_offset_in_sector])) - serial.puts(_db3) - if lfn_buf and dp.lfn_ofs != 0xFFFFFFFF and dp.lfn_ofs < dp.offset: - lfn_matched: t.CInt = 1 - li: t.CInt = 0 - for name_ch in name: - lfn_ch: t.CUInt16T = c.Deref(t.CUInt16T(t.CUInt64T(lfn_buf) + li * 2, t.CPtr)) - lfn_low: t.CUInt16T = lfn_ch - if lfn_low >= 65 and lfn_low <= 90: lfn_low = lfn_low + 32 - n_low: t.CUInt16T = t.CUInt16T(name_ch) - if n_low >= 65 and n_low <= 90: n_low = n_low + 32 - if lfn_low != n_low: - lfn_matched = 0 - break - li += 1 - if lfn_matched: - lfn_end: t.CUInt16T = c.Deref(t.CUInt16T(t.CUInt64T(lfn_buf) + li * 2, t.CPtr)) - if lfn_end == 0 or lfn_end == 0xFFFF: - return FRESULT.FR_OK - dp.offset += 1 - - def dir_get_entry_info(self, dp: dirobj | t.CPtr, info: fileinfo | t.CPtr, lfn_buf: t.CUInt16T | t.CPtr) -> FRESULT: - res: FRESULT = self._read_entry_from_dir(dp) - if res != FRESULT.FR_OK: return FRESULT.FR_DISK_ERR - entry_offset_in_sector: t.CUInt32T = (dp.offset % (512 / ENTRY_SIZE)) * ENTRY_SIZE - off: t.CUInt32T = entry_offset_in_sector - raw_attr: t.CUInt8T = self.win[off + 11] - info.attr = raw_attr - info.ctime = _read16(c.Addr(self.win[0]), off + 14) - info.cdate = _read16(c.Addr(self.win[0]), off + 16) - info.adate = _read16(c.Addr(self.win[0]), off + 18) - info.mtime = _read16(c.Addr(self.win[0]), off + 22) - info.mdate = _read16(c.Addr(self.win[0]), off + 24) - info.file_size = _read32(c.Addr(self.win[0]), off + 28) - sfn_ptr: t.CChar | t.CPtr = t.CChar(c.Addr(self.win[0]) + off, t.CPtr) - sfn_to_str(sfn_ptr, c.Addr(info.altname[0])) - if dp.lfn_ofs != 0xFFFFFFFF and dp.lfn_ofs < dp.offset and lfn_buf: - lfn_ptr: t.CUInt16T | t.CPtr = lfn_buf - oi: t.CInt = 0 - for i in range(MAX_LFN): - ch: t.CUInt16T = c.Deref(lfn_ptr) - if ch == 0: break - if ch < 0x80: - info.fname[oi] = t.CChar(ch) - else: - oem_ch: t.CUInt16T = uni2oem_placeholder(ch, 0) - if oem_ch < 0x80: info.fname[oi] = t.CChar(oem_ch) - else: info.fname[oi] = '?' - oi += 1 - lfn_ptr = t.CUInt16T(t.CUInt64T(lfn_ptr) + 2, t.CPtr) - info.fname[oi] = 0 - else: - sfn_to_str(sfn_ptr, c.Addr(info.fname[0])) - return FRESULT.FR_OK - - def dir_add_entry(self, dp: dirobj | t.CPtr, name: t.CConst | t.CChar | t.CPtr, attr: t.CUInt8T, first_cluster: t.CUInt32T, file_size: t.CUInt32T, dir_sector_out: t.CUInt64T | t.CPtr, dir_offset_out: t.CUInt32T | t.CPtr) -> FRESULT: - sfn: t.CArray[t.CChar, 12] - sfn_from_lfn(name, c.Addr(sfn[0])) - lfn_entries: t.CInt = 0 - len_: t.CInt = 0 - for _ in name: len_ += 1 - if len_ > 12: - lfn_entries = (len_ + LFN_ENTRY_CHARS - 1) / LFN_ENTRY_CHARS - total_entries: t.CInt = lfn_entries + 1 - cur_cluster: t.CUInt32T = dp.cluster - cur_sector: t.CUInt64T = dp.sector - cur_offset: t.CUInt32T = dp.offset - found: t.CInt = 0 - consecutive: t.CInt = 0 - start_offset: t.CUInt32T = 0 - start_cluster: t.CUInt32T = 0 - epc: t.CUInt32T = self.entries_per_cluster() - while not found: - if cur_offset >= epc: - next_clust: t.CUInt32T = self.cluster_get_next(cur_cluster) - if next_clust == 0: - new_clust: t.CUInt32T = self.cluster_extend(cur_cluster) - if new_clust == 0: return FRESULT.FR_DENIED - self._zero_cluster(new_clust) - cur_cluster = new_clust - cur_sector = self.cluster_to_sector(new_clust) - cur_offset = 0 - else: - cur_cluster = next_clust - cur_sector = self.cluster_to_sector(next_clust) - cur_offset = 0 - es: t.CUInt64T = cur_sector + (cur_offset / (512 / ENTRY_SIZE)) - eo: t.CUInt32T = (cur_offset % (512 / ENTRY_SIZE)) * ENTRY_SIZE - res: FRESULT = self.win_read(es) - if res != FRESULT.FR_OK: return FRESULT.FR_DISK_ERR - first_byte: t.CUInt8T = self.win[eo] - if first_byte == SFN_FREE or first_byte == SFN_DELETED: - if consecutive == 0: - start_offset = cur_offset - start_cluster = cur_cluster - consecutive += 1 - if consecutive >= total_entries: - found = 1 - break - else: - consecutive = 0 - cur_offset += 1 - write_cluster: t.CUInt32T = start_cluster - write_sector: t.CUInt64T = self.cluster_to_sector(start_cluster) - write_offset: t.CUInt32T = start_offset - if lfn_entries > 0: - le: t.CInt - for le in range(lfn_entries): - if write_offset >= epc: - next_c: t.CUInt32T = self.cluster_get_next(write_cluster) - if next_c == 0: return FRESULT.FR_INT_ERR - write_cluster = next_c - write_sector = self.cluster_to_sector(next_c) - write_offset = 0 - es2: t.CUInt64T = write_sector + (write_offset / (512 / ENTRY_SIZE)) - eo2: t.CUInt32T = (write_offset % (512 / ENTRY_SIZE)) * ENTRY_SIZE - res2: FRESULT = self.win_read(es2) - if res2 != FRESULT.FR_OK: return FRESULT.FR_DISK_ERR - ord_val: t.CUInt8T = t.CUInt8T(lfn_entries - le) - if le == 0: ord_val |= LFN_FLAG_LAST - self.win[eo2 + 0] = ord_val - self.win[eo2 + 11] = LFN_ATTR - self.win[eo2 + 12] = 0 - self.win[eo2 + 13] = sfn_checksum(c.Addr(sfn[0])) - self.win[eo2 + 26] = 0 - self.win[eo2 + 27] = 0 - base: t.CInt = (lfn_entries - 1 - le) * LFN_ENTRY_CHARS - j: t.CInt - for j in range(LFN_ENTRY_CHARS): - idx: t.CInt = base + j - ch: t.CUInt16T - if idx < len_: ch = t.CUInt16T(name[idx]) - elif idx == len_: ch = 0x0000 - else: ch = 0xFFFF - if j < 5: - self.win[eo2 + 1 + j * 2] = t.CUInt8T(ch & 0xFF) - self.win[eo2 + 2 + j * 2] = t.CUInt8T((ch >> 8) & 0xFF) - elif j < 11: - self.win[eo2 + 14 + (j - 5) * 2] = t.CUInt8T(ch & 0xFF) - self.win[eo2 + 15 + (j - 5) * 2] = t.CUInt8T((ch >> 8) & 0xFF) - else: - self.win[eo2 + 28 + (j - 11) * 2] = t.CUInt8T(ch & 0xFF) - self.win[eo2 + 29 + (j - 11) * 2] = t.CUInt8T((ch >> 8) & 0xFF) - self.win_dirty = 1 - self.win_flush() - write_offset += 1 - if write_offset >= epc: - next_c2: t.CUInt32T = self.cluster_get_next(write_cluster) - if next_c2 == 0: return FRESULT.FR_INT_ERR - write_cluster = next_c2 - write_sector = self.cluster_to_sector(next_c2) - write_offset = 0 - es3: t.CUInt64T = write_sector + (write_offset / (512 / ENTRY_SIZE)) - eo3: t.CUInt32T = (write_offset % (512 / ENTRY_SIZE)) * ENTRY_SIZE - res3: FRESULT = self.win_read(es3) - if res3 != FRESULT.FR_OK: return FRESULT.FR_DISK_ERR - string.memset(c.Addr(self.win[eo3]), 0, 32) - i: t.CInt - for i in range(11): self.win[eo3 + i] = sfn[i] - self.win[eo3 + 11] = attr - self.win[eo3 + 12] = 0 - self.win[eo3 + 13] = 0 - self._write_dirent_now(eo3) - _write16(c.Addr(self.win[0]), eo3 + 20, t.CUInt16T((first_cluster >> 16) & 0xFFFF)) - _write16(c.Addr(self.win[0]), eo3 + 26, t.CUInt16T(first_cluster & 0xFFFF)) - _write32(c.Addr(self.win[0]), eo3 + 28, file_size) - self.win_dirty = 1 - self.win_flush() - c.Set(t.CUInt64T(dir_sector_out, t.CPtr), es3) - c.Set(t.CUInt32T(dir_offset_out, t.CPtr), eo3) - return FRESULT.FR_OK - - def dir_update_entry(self, dir_sector: t.CUInt64T, dir_offset: t.CUInt32T, first_cluster: t.CUInt32T, file_size: t.CUInt32T, attr: t.CUInt8T) -> FRESULT: - res: FRESULT = self.win_read(dir_sector) - if res != FRESULT.FR_OK: return FRESULT.FR_DISK_ERR - self.win[dir_offset + 11] = attr - _write16(c.Addr(self.win[0]), dir_offset + 20, t.CUInt16T((first_cluster >> 16) & 0xFFFF)) - _write16(c.Addr(self.win[0]), dir_offset + 26, t.CUInt16T(first_cluster & 0xFFFF)) - _write32(c.Addr(self.win[0]), dir_offset + 28, file_size) - self._write_dirent_now(dir_offset) - self.win_dirty = 1 - return self.win_flush() - - def dir_delete_entry(self, dp: dirobj | t.CPtr) -> FRESULT: - start_off: t.CUInt32T = dp.lfn_ofs if dp.lfn_ofs != 0xFFFFFFFF else dp.offset - end_off: t.CUInt32T = dp.offset - cur_off: t.CUInt32T = start_off - cur_cluster: t.CUInt32T = dp.lfn_cluster if dp.lfn_ofs != 0xFFFFFFFF else dp.cluster - epc: t.CUInt32T = self.entries_per_cluster() - while cur_off <= end_off: - off_in_clus: t.CUInt32T = cur_off % epc - if off_in_clus == 0 and cur_off != start_off: - next_c: t.CUInt32T = self.cluster_get_next(cur_cluster) - if next_c == 0: return FRESULT.FR_INT_ERR - cur_cluster = next_c - sector_base: t.CUInt64T = self.cluster_to_sector(cur_cluster) - es: t.CUInt64T = sector_base + t.CUInt64T(off_in_clus / (512 / ENTRY_SIZE)) - eo: t.CUInt32T = (off_in_clus % (512 / ENTRY_SIZE)) * ENTRY_SIZE - res: FRESULT = self.win_read(es) - if res != FRESULT.FR_OK: return FRESULT.FR_DISK_ERR - self.win[eo] = SFN_DELETED - self.win_dirty = 1 - res2: FRESULT = self.win_flush() - if res2 != FRESULT.FR_OK: return res2 - cur_off += 1 - return FRESULT.FR_OK - - def follow_path(self, dp: dirobj | t.CPtr, path: t.CConst | t.CChar | t.CPtr, lfn_buf: t.CUInt16T | t.CPtr) -> FRESULT: - cluster: t.CUInt32T = self.root_cluster - pi: t.CInt = 0 - if path[0] >= '0' and path[0] <= '9': - if path[1] == ':': - pi = 2 - elif path[1] == 0: - self.dir_open(dp, cluster) - return FRESULT.FR_OK - elif (path[0] >= 'A' and path[0] <= 'Z') or (path[0] >= 'a' and path[0] <= 'z'): - if path[1] == ':': - pi = 2 - if path[pi] == '/' or path[pi] == '\\': pi += 1 - while path[pi] == '/' or path[pi] == '\\': pi += 1 - if path[pi] == 0: - self.dir_open(dp, cluster) - return FRESULT.FR_OK - while True: - component: t.CArray[t.CChar, 256] - ci: t.CInt = 0 - while path[pi] != 0 and path[pi] != '/' and path[pi] != '\\' and ci < 255: - component[ci] = path[pi] - ci += 1; pi += 1 - component[ci] = 0 - if ci == 0: break - while path[pi] == '/' or path[pi] == '\\': pi += 1 - if ci == 2 and component[0] == '.' and component[1] == '.': - if cluster == self.root_cluster: - pass - else: - self.dir_open(dp, cluster) - dotdot_name: t.CArray[t.CChar, 256] - dotdot_name[0] = '.'; dotdot_name[1] = '.'; dotdot_name[2] = 0 - res_dd: FRESULT = self.dir_find(dp, c.Addr(dotdot_name[0]), lfn_buf) - if res_dd == FRESULT.FR_OK: - self._read_entry_from_dir(dp) - dd_eo: t.CUInt32T = (dp.offset % (512 / ENTRY_SIZE)) * ENTRY_SIZE - dd_off: t.CUInt32T = dd_eo - dd_ch: t.CUInt32T = t.CUInt32T(self.win[dd_off + 20]) | (t.CUInt32T(self.win[dd_off + 21]) << 8) - dd_cl: t.CUInt32T = t.CUInt32T(self.win[dd_off + 26]) | (t.CUInt32T(self.win[dd_off + 27]) << 8) - dd_clus: t.CUInt32T = (dd_ch << 16) | dd_cl - if dd_clus == 0: dd_clus = self.root_cluster - cluster = dd_clus - if path[pi] == 0: - self.dir_open(dp, cluster) - return FRESULT.FR_OK - continue - else: - cluster = self.root_cluster - if path[pi] == 0: - self.dir_open(dp, cluster) - return FRESULT.FR_OK - continue - if path[pi] == 0: - self.dir_open(dp, cluster) - return FRESULT.FR_OK - continue - if ci == 1 and component[0] == '.': - if path[pi] == 0: - self.dir_open(dp, cluster) - return FRESULT.FR_OK - continue - self.dir_open(dp, cluster) - res: FRESULT = self.dir_find(dp, c.Addr(component[0]), lfn_buf) - if res != FRESULT.FR_OK: return res - self._read_entry_from_dir(dp) - entry_offset_in_sector: t.CUInt32T = (dp.offset % (512 / ENTRY_SIZE)) * ENTRY_SIZE - off: t.CUInt32T = entry_offset_in_sector - entry_attr: t.CUInt8T = self.win[off + 11] - clus_hi: t.CUInt32T = t.CUInt32T(self.win[off + 20]) | (t.CUInt32T(self.win[off + 21]) << 8) - clus_lo: t.CUInt32T = t.CUInt32T(self.win[off + 26]) | (t.CUInt32T(self.win[off + 27]) << 8) - entry_cluster: t.CUInt32T = (clus_hi << 16) | clus_lo - if path[pi] == 0: return FRESULT.FR_OK - if not (entry_attr & AM_DIR): return FRESULT.FR_NO_PATH - cluster = entry_cluster - return FRESULT.FR_NO_PATH - - def mkdir_create_dir_entries(self, new_cluster: t.CUInt32T, parent_cluster: t.CUInt32T) -> FRESULT: - sector: t.CUInt64T = self.cluster_to_sector(new_cluster) - res: FRESULT = self.win_read(sector) - if res != FRESULT.FR_OK: return res - string.memset(c.Addr(self.win[0]), 0, 512) - self.win[0] = '.'; self.win[1] = ' '; self.win[2] = ' '; self.win[3] = ' ' - self.win[4] = ' '; self.win[5] = ' '; self.win[6] = ' '; self.win[7] = ' ' - self.win[8] = ' '; self.win[9] = ' '; self.win[10] = ' ' - self.win[11] = AM_DIR - _write16(c.Addr(self.win[0]), 20, t.CUInt16T((new_cluster >> 16) & 0xFFFF)) - _write16(c.Addr(self.win[0]), 26, t.CUInt16T(new_cluster & 0xFFFF)) - self._write_dirent_now(0) - self.win[32] = '.'; self.win[33] = '.'; self.win[34] = ' '; self.win[35] = ' ' - self.win[36] = ' '; self.win[37] = ' '; self.win[38] = ' '; self.win[39] = ' ' - self.win[40] = ' '; self.win[41] = ' '; self.win[42] = ' ' - self.win[11 + 32] = AM_DIR - _write16(c.Addr(self.win[0]), 20 + 32, t.CUInt16T((parent_cluster >> 16) & 0xFFFF)) - _write16(c.Addr(self.win[0]), 26 + 32, t.CUInt16T(parent_cluster & 0xFFFF)) - self._write_dirent_now(32) - self.win_dirty = 1 - return self.win_flush() - - def file_open(self, path: t.CConst | t.CChar | t.CPtr, mode: t.CUInt8T) -> fileobj | t.CPtr: - self.last_error = FRESULT.FR_OK - if not self.mounted: - self.last_error = FRESULT.FR_NOT_ENABLED - return None - dp: dirobj - lfn_buf: t.CArray[t.CUInt16T, 256] - string.memset(c.Addr(lfn_buf), 0, 256 * 2) - res: FRESULT = self.follow_path(c.Addr(dp), path, t.CUInt16T(c.Addr(lfn_buf[0]), t.CPtr)) - if mode & FA_CREATE_NEW: - if res == FRESULT.FR_OK: - self.last_error = FRESULT.FR_EXIST - return None - if res != FRESULT.FR_NO_FILE and res != FRESULT.FR_NO_PATH: - self.last_error = res - return None - need_create: t.CInt = 0 - if (mode & FA_CREATE_NEW): need_create = 1 - if (mode & FA_OPEN_ALWAYS) and res == FRESULT.FR_NO_FILE: need_create = 1 - if (mode & FA_CREATE_ALWAYS) and res == FRESULT.FR_NO_FILE: need_create = 1 - if need_create: - pp: t.CArray[t.CChar, 260] - fn: t.CArray[t.CChar, 256] - _split_path(path, c.Addr(pp[0]), c.Addr(fn[0])) - string.memset(c.Addr(lfn_buf), 0, 256 * 2) - res2: FRESULT = self.follow_path(c.Addr(dp), c.Addr(pp[0]), t.CUInt16T(c.Addr(lfn_buf[0]), t.CPtr)) - if res2 != FRESULT.FR_OK: - self.last_error = res2 - return None - nc: t.CUInt32T = 0 - if mode & FA_WRITE: - nc = self.cluster_alloc() - if nc == 0: - self.last_error = FRESULT.FR_DENIED - return None - self._zero_cluster(nc) - ds: t.CUInt64T = 0 - do: t.CUInt32T = 0 - res3: FRESULT = self.dir_add_entry(c.Addr(dp), c.Addr(fn[0]), AM_ARC, nc, 0, c.Addr(ds), c.Addr(do)) - if res3 != FRESULT.FR_OK: - if nc >= 2: self.cluster_free_chain(nc) - self.last_error = res3 - return None - fp: fileobj | t.CPtr = handle_alloc() - if fp is None: - if nc >= 2: self.cluster_free_chain(nc) - self.last_error = FRESULT.FR_TOO_MANY_OPEN_FILES - return None - fp.vol = self - fp.is_open = 1 - fp.is_dir = 0 - fp.first_cluster = nc - fp.current_cluster = nc - fp.file_size = 0 - fp.file_pos = 0 - fp.dir_sector = ds - fp.dir_offset = do - fp.attr = AM_ARC - fp.flags = mode - fp.err = 0 - fp.lock_count = 0 - fp.buf_sect = 0xFFFFFFFFFFFFFFFF - fp.buf_dirty = 0 - if mode & FA_WRITE: - lock_acquire(ds, do, 1) - fp.lock_count = 1 - return fp - if res != FRESULT.FR_OK: - self.last_error = res - return None - entry_sector: t.CUInt64T = dp.sector + (dp.offset / (512 / ENTRY_SIZE)) - entry_offset_in_sector: t.CUInt32T = (dp.offset % (512 / ENTRY_SIZE)) * ENTRY_SIZE - res_wr: FRESULT = self.win_read(entry_sector) - if res_wr != FRESULT.FR_OK: - self.last_error = res_wr - return None - off: t.CUInt32T = entry_offset_in_sector - entry_attr: t.CUInt8T = self.win[off + 11] - if entry_attr & AM_DIR: - self.last_error = FRESULT.FR_DENIED - return None - if mode & FA_WRITE: - if entry_attr & AM_RDO: - self.last_error = FRESULT.FR_DENIED - return None - lres: FRESULT = lock_check(entry_sector, entry_offset_in_sector, mode) - if lres != FRESULT.FR_OK: - self.last_error = lres - return None - clus_hi: t.CUInt32T = t.CUInt32T(self.win[off + 20]) | (t.CUInt32T(self.win[off + 21]) << 8) - clus_lo: t.CUInt32T = t.CUInt32T(self.win[off + 26]) | (t.CUInt32T(self.win[off + 27]) << 8) - entry_cluster: t.CUInt32T = (clus_hi << 16) | clus_lo - entry_size: t.CUInt32T = _read32(c.Addr(self.win[0]), off + 28) - fp2: fileobj | t.CPtr = handle_alloc() - if fp2 is None: - self.last_error = FRESULT.FR_TOO_MANY_OPEN_FILES - return None - fp2.vol = self - fp2.is_open = 1 - fp2.is_dir = 0 - fp2.first_cluster = entry_cluster - fp2.current_cluster = entry_cluster - fp2.file_size = entry_size - fp2.file_pos = 0 - fp2.dir_sector = entry_sector - fp2.dir_offset = entry_offset_in_sector - fp2.attr = entry_attr - fp2.flags = mode - fp2.err = 0 - fp2.lock_count = 0 - fp2.buf_sect = 0xFFFFFFFFFFFFFFFF - fp2.buf_dirty = 0 - if mode & FA_WRITE: - lock_acquire(entry_sector, entry_offset_in_sector, 1) - fp2.lock_count = 1 - if mode & FA_CREATE_ALWAYS: - if entry_cluster >= 2: self.cluster_free_chain(entry_cluster) - fp2.first_cluster = 0 - fp2.current_cluster = 0 - fp2.file_size = 0 - fp2.file_pos = 0 - self.dir_update_entry(entry_sector, entry_offset_in_sector, 0, 0, entry_attr) - if mode & FA_OPEN_APPEND: - fp2.file_pos = entry_size - fp2.current_cluster = self.file_cluster_seek(entry_cluster, entry_size) - return fp2 - - def file_delete(self, path: t.CConst | t.CChar | t.CPtr) -> FRESULT: - if not self.mounted: return FRESULT.FR_NOT_ENABLED - dp: dirobj - lfn_buf: t.CArray[t.CUInt16T, 256] - string.memset(c.Addr(lfn_buf), 0, 256 * 2) - res: FRESULT = self.follow_path(c.Addr(dp), path, t.CUInt16T(c.Addr(lfn_buf[0]), t.CPtr)) - if res != FRESULT.FR_OK: return res - entry_sector: t.CUInt64T = dp.sector + (dp.offset / (512 / ENTRY_SIZE)) - entry_offset_in_sector: t.CUInt32T = (dp.offset % (512 / ENTRY_SIZE)) * ENTRY_SIZE - res_wr: FRESULT = self.win_read(entry_sector) - if res_wr != FRESULT.FR_OK: return FRESULT.FR_DISK_ERR - off: t.CUInt32T = entry_offset_in_sector - entry_attr: t.CUInt8T = self.win[off + 11] - if entry_attr & AM_RDO: return FRESULT.FR_DENIED - if entry_attr & AM_DIR: return FRESULT.FR_DENIED - lres: FRESULT = lock_check(entry_sector, entry_offset_in_sector, FA_WRITE) - if lres != FRESULT.FR_OK: return FRESULT.FR_LOCKED - clus_hi: t.CUInt32T = t.CUInt32T(self.win[off + 20]) | (t.CUInt32T(self.win[off + 21]) << 8) - clus_lo: t.CUInt32T = t.CUInt32T(self.win[off + 26]) | (t.CUInt32T(self.win[off + 27]) << 8) - entry_cluster: t.CUInt32T = (clus_hi << 16) | clus_lo - res2: FRESULT = self.dir_delete_entry(c.Addr(dp)) - if res2 != FRESULT.FR_OK: return res2 - if entry_cluster >= 2: self.cluster_free_chain(entry_cluster) - return FRESULT.FR_OK - - def file_rename(self, old_path: t.CConst | t.CChar | t.CPtr, new_path: t.CConst | t.CChar | t.CPtr) -> FRESULT: - if not self.mounted: return FRESULT.FR_NOT_ENABLED - dp: dirobj - lfn_buf: t.CArray[t.CUInt16T, 256] - string.memset(c.Addr(lfn_buf), 0, 256 * 2) - res: FRESULT = self.follow_path(c.Addr(dp), old_path, t.CUInt16T(c.Addr(lfn_buf[0]), t.CPtr)) - if res != FRESULT.FR_OK: return res - entry_sector: t.CUInt64T = dp.sector + (dp.offset / (512 / ENTRY_SIZE)) - entry_offset_in_sector: t.CUInt32T = (dp.offset % (512 / ENTRY_SIZE)) * ENTRY_SIZE - res_wr: FRESULT = self.win_read(entry_sector) - if res_wr != FRESULT.FR_OK: return FRESULT.FR_DISK_ERR - off: t.CUInt32T = entry_offset_in_sector - entry_attr: t.CUInt8T = self.win[off + 11] - clus_hi: t.CUInt32T = t.CUInt32T(self.win[off + 20]) | (t.CUInt32T(self.win[off + 21]) << 8) - clus_lo: t.CUInt32T = t.CUInt32T(self.win[off + 26]) | (t.CUInt32T(self.win[off + 27]) << 8) - entry_cluster: t.CUInt32T = (clus_hi << 16) | clus_lo - entry_size: t.CUInt32T = _read32(c.Addr(self.win[0]), off + 28) - lres: FRESULT = lock_check(entry_sector, entry_offset_in_sector, FA_WRITE) - if lres != FRESULT.FR_OK: return FRESULT.FR_LOCKED - new_parent: t.CArray[t.CChar, 260] - new_fname: t.CArray[t.CChar, 256] - _split_path(new_path, c.Addr(new_parent[0]), c.Addr(new_fname[0])) - dp2: dirobj - string.memset(c.Addr(lfn_buf), 0, 256 * 2) - res2: FRESULT = self.follow_path(c.Addr(dp2), c.Addr(new_parent[0]), t.CUInt16T(c.Addr(lfn_buf[0]), t.CPtr)) - if res2 != FRESULT.FR_OK: return FRESULT.FR_NO_PATH - new_dir_sector: t.CUInt64T = 0 - new_dir_offset: t.CUInt32T = 0 - res3: FRESULT = self.dir_add_entry(c.Addr(dp2), c.Addr(new_fname[0]), entry_attr, entry_cluster, entry_size, c.Addr(new_dir_sector), c.Addr(new_dir_offset)) - if res3 != FRESULT.FR_OK: return res3 - res4: FRESULT = self.dir_delete_entry(c.Addr(dp)) - if res4 != FRESULT.FR_OK: return res4 - return FRESULT.FR_OK - - def file_stat(self, path: t.CConst | t.CChar | t.CPtr, info: fileinfo | t.CPtr) -> FRESULT: - if not self.mounted: return FRESULT.FR_NOT_ENABLED - dp: dirobj - lfn_buf: t.CArray[t.CUInt16T, 256] - string.memset(c.Addr(lfn_buf), 0, 256 * 2) - res: FRESULT = self.follow_path(c.Addr(dp), path, t.CUInt16T(c.Addr(lfn_buf[0]), t.CPtr)) - if res != FRESULT.FR_OK: return res - return self.dir_get_entry_info(c.Addr(dp), info, t.CUInt16T(c.Addr(lfn_buf[0]), t.CPtr)) - - def dir_make(self, path: t.CConst | t.CChar | t.CPtr) -> FRESULT: - if not self.mounted: return FRESULT.FR_NOT_ENABLED - dp: dirobj - lfn_buf: t.CArray[t.CUInt16T, 256] - string.memset(c.Addr(lfn_buf), 0, 256 * 2) - res: FRESULT = self.follow_path(c.Addr(dp), path, t.CUInt16T(c.Addr(lfn_buf[0]), t.CPtr)) - if res == FRESULT.FR_OK: return FRESULT.FR_EXIST - parent_path: t.CArray[t.CChar, 260] - dir_name: t.CArray[t.CChar, 256] - _split_path(path, c.Addr(parent_path[0]), c.Addr(dir_name[0])) - string.memset(c.Addr(lfn_buf), 0, 256 * 2) - res2: FRESULT = self.follow_path(c.Addr(dp), c.Addr(parent_path[0]), t.CUInt16T(c.Addr(lfn_buf[0]), t.CPtr)) - if res2 != FRESULT.FR_OK: return FRESULT.FR_NO_PATH - parent_cluster: t.CUInt32T = dp.cluster - new_cluster: t.CUInt32T = self.cluster_alloc() - if new_cluster == 0: return FRESULT.FR_DENIED - self._zero_cluster(new_cluster) - dir_sector: t.CUInt64T = 0 - dir_offset: t.CUInt32T = 0 - res3: FRESULT = self.dir_add_entry(c.Addr(dp), c.Addr(dir_name[0]), AM_DIR, new_cluster, 0, c.Addr(dir_sector), c.Addr(dir_offset)) - if res3 != FRESULT.FR_OK: - self.cluster_free_chain(new_cluster) - return res3 - res4: FRESULT = self.mkdir_create_dir_entries(new_cluster, parent_cluster) - if res4 != FRESULT.FR_OK: - self.cluster_free_chain(new_cluster) - return res4 - return FRESULT.FR_OK - - def dir_open_path(self, path: t.CConst | t.CChar | t.CPtr, dp: dirobj | t.CPtr) -> FRESULT: - if not self.mounted: return FRESULT.FR_NOT_ENABLED - pi: t.CInt = 0 - if path[0] >= '0' and path[0] <= '9': - if path[1] == ':' or path[1] == 0: - pi = 2 - if path[1] == 0: - self.dir_open(dp, self.root_cluster) - return FRESULT.FR_OK - if path[pi] == '/' or path[pi] == '\\': pi += 1 - while path[pi] == '/' or path[pi] == '\\': pi += 1 - is_root: t.CInt = 1 if path[pi] == 0 else 0 - lfn_buf: t.CArray[t.CUInt16T, 256] - string.memset(c.Addr(lfn_buf), 0, 256 * 2) - res: FRESULT = self.follow_path(dp, path, t.CUInt16T(c.Addr(lfn_buf[0]), t.CPtr)) - if res != FRESULT.FR_OK: return res - if is_root: return FRESULT.FR_OK - entry_sector: t.CUInt64T = dp.sector + (dp.offset / (512 / ENTRY_SIZE)) - entry_offset_in_sector: t.CUInt32T = (dp.offset % (512 / ENTRY_SIZE)) * ENTRY_SIZE - res_wr: FRESULT = self.win_read(entry_sector) - if res_wr != FRESULT.FR_OK: return FRESULT.FR_DISK_ERR - off: t.CUInt32T = entry_offset_in_sector - entry_attr: t.CUInt8T = self.win[off + 11] - if not (entry_attr & AM_DIR): return FRESULT.FR_NO_PATH - clus_hi: t.CUInt32T = t.CUInt32T(self.win[off + 20]) | (t.CUInt32T(self.win[off + 21]) << 8) - clus_lo: t.CUInt32T = t.CUInt32T(self.win[off + 26]) | (t.CUInt32T(self.win[off + 27]) << 8) - entry_cluster: t.CUInt32T = (clus_hi << 16) | clus_lo - return self.dir_open(dp, entry_cluster) - - def dir_read(self, dp: dirobj | t.CPtr, info: fileinfo | t.CPtr) -> FRESULT: - lfn_buf: t.CArray[t.CUInt16T, 256] - string.memset(c.Addr(lfn_buf), 0, 256 * 2) - res: FRESULT = self.dir_read_entry(dp, t.CUInt16T(c.Addr(lfn_buf[0]), t.CPtr)) - if res != FRESULT.FR_OK: return res - res2: FRESULT = self.dir_get_entry_info(dp, info, t.CUInt16T(c.Addr(lfn_buf[0]), t.CPtr)) - dp.offset += 1 - return res2 - - def dir_remove(self, path: t.CConst | t.CChar | t.CPtr) -> FRESULT: - if not self.mounted: return FRESULT.FR_NOT_ENABLED - dp: dirobj - lfn_buf: t.CArray[t.CUInt16T, 256] - string.memset(c.Addr(lfn_buf), 0, 256 * 2) - res: FRESULT = self.follow_path(c.Addr(dp), path, t.CUInt16T(c.Addr(lfn_buf[0]), t.CPtr)) - if res != FRESULT.FR_OK: return res - entry_sector: t.CUInt64T = dp.sector + (dp.offset / (512 / ENTRY_SIZE)) - entry_offset_in_sector: t.CUInt32T = (dp.offset % (512 / ENTRY_SIZE)) * ENTRY_SIZE - res_wr: FRESULT = self.win_read(entry_sector) - if res_wr != FRESULT.FR_OK: return FRESULT.FR_DISK_ERR - off: t.CUInt32T = entry_offset_in_sector - entry_attr: t.CUInt8T = self.win[off + 11] - if not (entry_attr & AM_DIR): return FRESULT.FR_NO_PATH - clus_hi: t.CUInt32T = t.CUInt32T(self.win[off + 20]) | (t.CUInt32T(self.win[off + 21]) << 8) - clus_lo: t.CUInt32T = t.CUInt32T(self.win[off + 26]) | (t.CUInt32T(self.win[off + 27]) << 8) - entry_cluster: t.CUInt32T = (clus_hi << 16) | clus_lo - if entry_cluster >= 2: - check_dp: dirobj - self.dir_open(c.Addr(check_dp), entry_cluster) - lfn_buf2: t.CArray[t.CUInt16T, 256] - string.memset(c.Addr(lfn_buf2), 0, 256 * 2) - while True: - check_res: FRESULT = self.dir_read_entry(c.Addr(check_dp), t.CUInt16T(c.Addr(lfn_buf2[0]), t.CPtr)) - if check_res != FRESULT.FR_OK: break - c_off: t.CUInt32T = (check_dp.offset % (512 / ENTRY_SIZE)) * ENTRY_SIZE - c_sec: t.CUInt64T = check_dp.sector + (check_dp.offset / (512 / ENTRY_SIZE)) - self.win_read(c_sec) - c_name0: t.CUInt8T = self.win[c_off] - c_name1: t.CUInt8T = self.win[c_off + 1] - check_dp.offset += 1 - if c_name0 == '.' and (c_name1 == '.' or c_name1 == 0x20): - continue - return FRESULT.FR_DENIED - lres: FRESULT = lock_check(entry_sector, entry_offset_in_sector, FA_WRITE) - if lres != FRESULT.FR_OK: return FRESULT.FR_LOCKED - res2: FRESULT = self.dir_delete_entry(c.Addr(dp)) - if res2 != FRESULT.FR_OK: return res2 - if entry_cluster >= 2: self.cluster_free_chain(entry_cluster) - return FRESULT.FR_OK - - def chmod(self, path: t.CConst | t.CChar | t.CPtr, attr: t.CUInt8T, mask: t.CUInt8T) -> FRESULT: - if not self.mounted: return FRESULT.FR_NOT_ENABLED - dp: dirobj - lfn_buf: t.CArray[t.CUInt16T, 256] - string.memset(c.Addr(lfn_buf), 0, 256 * 2) - res: FRESULT = self.follow_path(c.Addr(dp), path, t.CUInt16T(c.Addr(lfn_buf[0]), t.CPtr)) - if res != FRESULT.FR_OK: return res - entry_sector: t.CUInt64T = dp.sector + (dp.offset / (512 / ENTRY_SIZE)) - entry_offset_in_sector: t.CUInt32T = (dp.offset % (512 / ENTRY_SIZE)) * ENTRY_SIZE - res_wr: FRESULT = self.win_read(entry_sector) - if res_wr != FRESULT.FR_OK: return FRESULT.FR_DISK_ERR - off: t.CUInt32T = entry_offset_in_sector - old_attr: t.CUInt8T = self.win[off + 11] - new_attr: t.CUInt8T = (old_attr & ~mask) | (attr & mask) - self.win[off + 11] = new_attr - self.win_dirty = 1 - return self.win_flush() - - def utime(self, path: t.CConst | t.CChar | t.CPtr, mtime: t.CUInt16T, mdate: t.CUInt16T) -> FRESULT: - if not self.mounted: return FRESULT.FR_NOT_ENABLED - dp: dirobj - lfn_buf: t.CArray[t.CUInt16T, 256] - string.memset(c.Addr(lfn_buf), 0, 256 * 2) - res: FRESULT = self.follow_path(c.Addr(dp), path, t.CUInt16T(c.Addr(lfn_buf[0]), t.CPtr)) - if res != FRESULT.FR_OK: return res - entry_sector: t.CUInt64T = dp.sector + (dp.offset / (512 / ENTRY_SIZE)) - entry_offset_in_sector: t.CUInt32T = (dp.offset % (512 / ENTRY_SIZE)) * ENTRY_SIZE - res_wr: FRESULT = self.win_read(entry_sector) - if res_wr != FRESULT.FR_OK: return FRESULT.FR_DISK_ERR - off: t.CUInt32T = entry_offset_in_sector - self.win[off + 22] = t.CUInt8T(mtime & 0xFF) - self.win[off + 23] = t.CUInt8T((mtime >> 8) & 0xFF) - self.win[off + 24] = t.CUInt8T(mdate & 0xFF) - self.win[off + 25] = t.CUInt8T((mdate >> 8) & 0xFF) - self.win[off + 18] = t.CUInt8T(mdate & 0xFF) - self.win[off + 19] = t.CUInt8T((mdate >> 8) & 0xFF) - self.win_dirty = 1 - return self.win_flush() - - -@t.Object -class fileobj: - vol: volinfo | t.CPtr - is_open: t.CInt = 0 - is_dir: t.CInt = 0 - first_cluster: t.CUInt32T = 0 - current_cluster: t.CUInt32T = 0 - file_size: t.CUInt32T = 0 - file_pos: t.CUInt32T = 0 - dir_sector: t.CUInt64T = 0 - dir_offset: t.CUInt32T = 0 - attr: t.CUInt8T = 0 - ctime: t.CUInt16T = 0 - cdate: t.CUInt16T = 0 - mtime: t.CUInt16T = 0 - mdate: t.CUInt16T = 0 - adate: t.CUInt16T = 0 - flags: t.CUInt8T = 0 - err: t.CUInt8T = 0 - lock_count: t.CInt = 0 - buf: t.CArray[t.CUInt8T, 512] - buf_sect: t.CUInt64T = 0 - buf_dirty: t.CInt = 0 - - def buf_flush(self) -> FRESULT: - if not self.buf_dirty: return FRESULT.FR_OK - abs_sect: t.CUInt64T = t.CUInt64T(self.buf_sect) + t.CUInt64T(self.vol.hidden_sectors) - self.vol.lock.lock() - res: DRESULT = diskio.write(self.vol.pdrv, c.Addr(self.buf[0]), t.CUInt32T(abs_sect), 1) - self.vol.lock.unlock() - if res != DRESULT.RES_OK: return FRESULT.FR_DISK_ERR - self.buf_dirty = 0 - return FRESULT.FR_OK - - def buf_read(self, sector: t.CUInt64T) -> FRESULT: - if self.buf_sect == sector: return FRESULT.FR_OK - if self.buf_dirty: - res: FRESULT = self.buf_flush() - if res != FRESULT.FR_OK: return res - abs_sect: t.CUInt64T = sector + t.CUInt64T(self.vol.hidden_sectors) - self.vol.lock.lock() - res2: DRESULT = diskio.read(self.vol.pdrv, c.Addr(self.buf[0]), t.CUInt32T(abs_sect), 1) - self.vol.lock.unlock() - if res2 != DRESULT.RES_OK: return FRESULT.FR_DISK_ERR - self.buf_sect = sector - return FRESULT.FR_OK - - def close(self) -> FRESULT: - if not self.is_open: return FRESULT.FR_INVALID_OBJECT - res: FRESULT = self.buf_flush() - if res != FRESULT.FR_OK: return res - if self.flags & FA_WRITE: - self.vol.dir_update_entry(self.dir_sector, self.dir_offset, self.first_cluster, self.file_size, self.attr) - if self.lock_count > 0: lock_release(self.dir_sector, self.dir_offset) - self.is_open = 0 - self.lock_count = 0 - return FRESULT.FR_OK - - def read(self, buff: t.CVoid | t.CPtr, btr: t.CUInt32T, br: t.CUInt32T | t.CPtr) -> FRESULT: - if not self.is_open: return FRESULT.FR_INVALID_OBJECT - if not (self.flags & FA_READ): return FRESULT.FR_DENIED - c.Set(t.CUInt32T(br, t.CPtr), 0) - vol: volinfo | t.CPtr = self.vol - remaining: t.CUInt32T = btr - buf_ptr: t.CUInt8T | t.CPtr = t.CUInt8T(buff, t.CPtr) - total_read: t.CUInt32T = 0 - while remaining > 0: - if self.file_pos >= self.file_size: break - if self.first_cluster < 2: break - if self.current_cluster < 2 or vol.is_eoc(self.current_cluster): break - cluster_offset: t.CUInt32T = self.file_pos % vol.cluster_size - sector_in_cluster: t.CUInt32T = cluster_offset / 512 - offset_in_sector: t.CUInt32T = cluster_offset % 512 - sector: t.CUInt64T = vol.cluster_to_sector(self.current_cluster) + t.CUInt64T(sector_in_cluster) - can_read_in_sector: t.CUInt32T = 512 - offset_in_sector - can_read: t.CUInt32T = can_read_in_sector - if can_read > remaining: can_read = remaining - if can_read > self.file_size - self.file_pos: can_read = self.file_size - self.file_pos - if can_read == 0: break - if offset_in_sector == 0 and can_read >= 512: - abs_sect: t.CUInt64T = sector + t.CUInt64T(vol.hidden_sectors) - vol.lock.lock() - res: DRESULT = diskio.read(vol.pdrv, buf_ptr, t.CUInt32T(abs_sect), 1) - vol.lock.unlock() - if res != DRESULT.RES_OK: return FRESULT.FR_DISK_ERR - else: - res2: FRESULT = self.buf_read(sector) - if res2 != FRESULT.FR_OK: return res2 - string.memcpy(buf_ptr, c.Addr(self.buf[offset_in_sector]), can_read) - buf_ptr += can_read - self.file_pos += can_read - total_read += can_read - remaining -= can_read - if self.file_pos % vol.cluster_size == 0: - next_c: t.CUInt32T = vol.cluster_get_next(self.current_cluster) - if next_c == 0: break - self.current_cluster = next_c - c.Set(t.CUInt32T(br, t.CPtr), total_read) - return FRESULT.FR_OK - - def _extend_to(self, target_pos: t.CUInt32T) -> FRESULT: - if self.first_cluster < 2: - new_c: t.CUInt32T = self.vol.cluster_alloc() - if new_c == 0: return FRESULT.FR_DENIED - self.first_cluster = new_c - self.current_cluster = new_c - self.vol._zero_cluster(new_c) - cur_pos: t.CUInt32T = 0 - clust: t.CUInt32T = self.first_cluster - while cur_pos + self.vol.cluster_size <= target_pos: - next_c: t.CUInt32T = self.vol.cluster_get_next(clust) - if next_c == 0: - new_c2: t.CUInt32T = self.vol.cluster_extend(clust) - if new_c2 == 0: return FRESULT.FR_DENIED - self.vol._zero_cluster(new_c2) - next_c = new_c2 - clust = next_c - cur_pos += self.vol.cluster_size - self.current_cluster = clust - return FRESULT.FR_OK - - def write(self, buff: t.CConst | t.CVoid | t.CPtr, btw: t.CUInt32T, bw: t.CUInt32T | t.CPtr) -> FRESULT: - if not self.is_open: return FRESULT.FR_INVALID_OBJECT - if not (self.flags & FA_WRITE): return FRESULT.FR_DENIED - c.Set(t.CUInt32T(bw, t.CPtr), 0) - vol: volinfo | t.CPtr = self.vol - remaining: t.CUInt32T = btw - buf_ptr: t.CConst | t.CUInt8T | t.CPtr = t.CUInt8T(buff, t.CPtr) - total_written: t.CUInt32T = 0 - while remaining > 0: - if self.first_cluster < 2: - new_c: t.CUInt32T = vol.cluster_alloc() - if new_c == 0: return FRESULT.FR_DENIED - self.first_cluster = new_c - self.current_cluster = new_c - vol._zero_cluster(new_c) - if self.current_cluster < 2 or vol.is_eoc(self.current_cluster): - last_c: t.CUInt32T = self.current_cluster - if self.first_cluster >= 2 and self.current_cluster < 2: - last_c = vol.file_find_last_cluster(self.first_cluster) - new_c2: t.CUInt32T = vol.cluster_extend(last_c) - if new_c2 == 0: return FRESULT.FR_DENIED - if self.first_cluster < 2: self.first_cluster = new_c2 - self.current_cluster = new_c2 - vol._zero_cluster(new_c2) - cluster_offset: t.CUInt32T = self.file_pos % vol.cluster_size - sector_in_cluster: t.CUInt32T = cluster_offset / 512 - offset_in_sector: t.CUInt32T = cluster_offset % 512 - sector: t.CUInt64T = vol.cluster_to_sector(self.current_cluster) + t.CUInt64T(sector_in_cluster) - can_write_in_sector: t.CUInt32T = 512 - offset_in_sector - can_write: t.CUInt32T = can_write_in_sector - if can_write > remaining: can_write = remaining - if can_write == 0: break - if offset_in_sector == 0 and can_write >= 512: - abs_sect: t.CUInt64T = sector + t.CUInt64T(vol.hidden_sectors) - vol.lock.lock() - res: DRESULT = diskio.write(vol.pdrv, buf_ptr, t.CUInt32T(abs_sect), 1) - vol.lock.unlock() - if res != DRESULT.RES_OK: return FRESULT.FR_DISK_ERR - self.buf_sect = 0xFFFFFFFFFFFFFFFF - self.buf_dirty = 0 - else: - res2: FRESULT = self.buf_read(sector) - if res2 != FRESULT.FR_OK: return res2 - string.memcpy(c.Addr(self.buf[offset_in_sector]), buf_ptr, can_write) - self.buf_dirty = 1 - res3: FRESULT = self.buf_flush() - if res3 != FRESULT.FR_OK: return res3 - buf_ptr += can_write - self.file_pos += can_write - total_written += can_write - remaining -= can_write - if self.file_pos > self.file_size: self.file_size = self.file_pos - if self.file_pos % vol.cluster_size == 0: - next_c: t.CUInt32T = vol.cluster_get_next(self.current_cluster) - if next_c != 0: self.current_cluster = next_c - c.Set(t.CUInt32T(bw, t.CPtr), total_written) - return FRESULT.FR_OK - - def seek(self, offset: t.CUInt32T) -> FRESULT: - if not self.is_open: return FRESULT.FR_INVALID_OBJECT - if offset > self.file_size: - if not (self.flags & FA_WRITE): return FRESULT.FR_DENIED - gap: t.CUInt32T = offset - self.file_size - res: FRESULT = self._extend_to(offset) - if res != FRESULT.FR_OK: return res - old_size: t.CUInt32T = self.file_size - zero_buf: t.CArray[t.CUInt8T, 512] - string.memset(c.Addr(zero_buf[0]), 0, 512) - self.file_pos = old_size - while gap > 0: - chunk: t.CUInt32T = gap - if chunk > 512: chunk = 512 - written: t.CUInt32T = 0 - res2: FRESULT = self.write(c.Addr(zero_buf[0]), chunk, c.Addr(written)) - if res2 != FRESULT.FR_OK: return res2 - if written == 0: return FRESULT.FR_DENIED - gap -= written - self.file_size = offset - self.vol.dir_update_entry(self.dir_sector, self.dir_offset, self.first_cluster, self.file_size, self.attr) - return FRESULT.FR_OK - self.file_pos = offset - if self.first_cluster < 2: - self.current_cluster = 0 - return FRESULT.FR_OK - self.current_cluster = self.vol.file_cluster_seek(self.first_cluster, offset) - return FRESULT.FR_OK - - def truncate(self) -> FRESULT: - if not self.is_open: return FRESULT.FR_INVALID_OBJECT - if not (self.flags & FA_WRITE): return FRESULT.FR_DENIED - if self.file_pos >= self.file_size: return FRESULT.FR_OK - vol: volinfo | t.CPtr = self.vol - new_size: t.CUInt32T = self.file_pos - if new_size == 0: - if self.first_cluster >= 2: vol.cluster_free_chain(self.first_cluster) - self.first_cluster = 0 - self.current_cluster = 0 - self.file_size = 0 - self.file_pos = 0 - vol.dir_update_entry(self.dir_sector, self.dir_offset, 0, 0, self.attr) - return FRESULT.FR_OK - cluster_at_pos: t.CUInt32T = vol.file_cluster_seek(self.first_cluster, new_size) - if cluster_at_pos < 2: return FRESULT.FR_INT_ERR - next_c: t.CUInt32T = vol.cluster_get_next(cluster_at_pos) - vol.fat_write(cluster_at_pos, CLUSTER_EOC_MAX) - if next_c >= 2 and next_c < CLUSTER_EOC_MIN: - vol.cluster_free_chain(next_c) - self.file_size = new_size - self.current_cluster = cluster_at_pos - vol.dir_update_entry(self.dir_sector, self.dir_offset, self.first_cluster, new_size, self.attr) - return FRESULT.FR_OK - - def tell(self) -> t.CUInt32T: - return self.file_pos - - def size(self) -> t.CUInt32T: - return self.file_size - - -@t.Object -class dirobj: - vol: volinfo | t.CPtr - cluster: t.CUInt32T = 0 - start_cluster: t.CUInt32T = 0 - sector: t.CUInt64T = 0 - offset: t.CUInt32T = 0 - is_open: t.CInt = 0 - lfn_ofs: t.CUInt32T = 4294967295 - lfn_cluster: t.CUInt32T = 0 - sfn: t.CArray[t.CChar, 12] - - def close(self): - self.is_open = 0 - - -handle_table: t.CArray[fileobj, MAX_HANDLES] -lock_table: t.CArray[filelock, MAX_LOCKS] -handles_initialized: t.CStatic | t.CInt = 0 - -def handles_init(): - if handles_initialized: return - for i in range(MAX_HANDLES): - handle_table[i].is_open = 0 - handle_table[i].lock_count = 0 - for j in range(MAX_LOCKS): - lock_table[j].in_use = 0 - handles_initialized = 1 - -def handle_alloc() -> fileobj | t.CPtr: - handles_init() - for i in range(MAX_HANDLES): - if not handle_table[i].is_open: - return c.Addr(handle_table[i]) - return None - -def lock_check(dir_sector: t.CUInt64T, dir_offset: t.CUInt32T, mode: t.CUInt8T) -> FRESULT: - handles_init() - for i in range(MAX_LOCKS): - lk: filelock | t.CPtr = c.Addr(lock_table[i]) - if lk.in_use and lk.dir_sector == dir_sector and lk.dir_offset == dir_offset: - if mode & FA_WRITE: return FRESULT.FR_LOCKED - if lk.exclusive: return FRESULT.FR_LOCKED - return FRESULT.FR_OK - -def lock_acquire(dir_sector: t.CUInt64T, dir_offset: t.CUInt32T, exclusive: t.CInt) -> FRESULT: - handles_init() - for i in range(MAX_LOCKS): - lk: filelock | t.CPtr = c.Addr(lock_table[i]) - if not lk.in_use: - lk.in_use = 1 - lk.dir_sector = dir_sector - lk.dir_offset = dir_offset - lk.exclusive = exclusive - lk.shared_count = 1 if not exclusive else 0 - return FRESULT.FR_OK - return FRESULT.FR_TOO_MANY_OPEN_FILES - -def lock_release(dir_sector: t.CUInt64T, dir_offset: t.CUInt32T): - handles_init() - for i in range(MAX_LOCKS): - lk: filelock | t.CPtr = c.Addr(lock_table[i]) - if lk.in_use and lk.dir_sector == dir_sector and lk.dir_offset == dir_offset: - lk.shared_count -= 1 - if lk.shared_count <= 0: lk.in_use = 0 - return diff --git a/Test/Kernel/drivers/fs/fat32/fileio.vp b/Test/Kernel/drivers/fs/fat32/fileio.vp deleted file mode 100644 index 1ff5896a..00000000 --- a/Test/Kernel/drivers/fs/fat32/fileio.vp +++ /dev/null @@ -1,3 +0,0 @@ -import fat32 - - diff --git a/Test/Kernel/drivers/input/keyboard/keyboard.vp b/Test/Kernel/drivers/input/keyboard/keyboard.vp deleted file mode 100644 index fce10397..00000000 --- a/Test/Kernel/drivers/input/keyboard/keyboard.vp +++ /dev/null @@ -1,146 +0,0 @@ -import asm -import intr.idt as idt -import drivers.serial.uart.serial as serial -import viperstring as string -import t, c - - -KBD_DATA: t.CDefine = 0x60 -KBD_STATUS: t.CDefine = 0x64 -KBD_COMMAND: t.CDefine = 0x64 - -KBD_BUF_SIZE: t.CDefine = 1024 - -KEY_RELEASED: t.CDefine = 0x80 - -buffer: t.CArray[t.CUInt8T, KBD_BUF_SIZE] -buf_head: t.CStatic | t.CUInt32T = 0 -buf_tail: t.CStatic | t.CUInt32T = 0 -buf_count: t.CStatic | t.CUInt32T = 0 - -shift_l: t.CStatic | t.CUInt8T = 0 -shift_r: t.CStatic | t.CUInt8T = 0 -ctrl_l: t.CStatic | t.CUInt8T = 0 -alt_l: t.CStatic | t.CUInt8T = 0 -caps_lock: t.CStatic | t.CUInt8T = 0 - -scancode_set1: t.CArray[t.CChar, 128] = [ - '\0', '\x1b', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', - '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', - '\0', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', "'", '`', '\0', - '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', '\0', '\0', '\0', ' ', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '-', '8', '6', '2', '\0', - '1', '+', '4', '5', '3', '0', '.', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0' -] - -scancode_set1_shift: t.CArray[t.CChar, 128] = [ - '\0', '\x1b', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '\b', - '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', - '\0', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', '\0', - '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', '\0', '\0', '\0', ' ', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '-', '8', '6', '2', '\0', - '1', '+', '4', '5', '3', '0', '.', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0' -] - -def _wait_read(): - timeout: t.CUInt32T = 100000 - while timeout > 0: - if (asm.inb(KBD_STATUS) & 0x01) != 0: return - timeout -= 1 - -def _wait_write(): - timeout: t.CUInt32T = 100000 - while timeout > 0: - if (asm.inb(KBD_STATUS) & 0x02) == 0: return - timeout -= 1 - -def irq_handler() -> t.CInt: - global buf_head, buf_tail, buf_count - scancode: t.CUInt8T = asm.inb(KBD_DATA) - if buf_count < KBD_BUF_SIZE: - buffer[buf_tail] = scancode - buf_tail = buf_tail + 1 - if buf_tail >= KBD_BUF_SIZE: - buf_tail = 0 - buf_count += 1 - return 0 - -def read_scancode() -> t.CUInt8T: - global buf_head, buf_count - asm.cli() - if buf_count == 0: - asm.sti() - return 0 - code: t.CUInt8T = buffer[buf_head] - buf_head = buf_head + 1 - if buf_head >= KBD_BUF_SIZE: - buf_head = 0 - buf_count -= 1 - asm.sti() - return code - -def scancode_to_ascii(scancode: t.CUInt8T) -> t.CChar: - code: t.CUInt8T = scancode & ~t.CUInt8T(KEY_RELEASED) - if code >= 128: return '\0' - shifted: bool = (shift_l or shift_r) != 0 - if caps_lock and code >= 0x10 and code <= 0x32: - shifted = not shifted - if shifted: - return scancode_set1_shift[code] - return scancode_set1[code] - -def has_data() -> t.CInt: - return buf_count - -def init(): - drain: t.CUInt32T - drain = 0 - while (asm.inb(KBD_STATUS) & 0x01) != 0: - asm.inb(KBD_DATA) - drain += 1 - if drain > 1000: break - - _wait_write() - asm.outb(KBD_COMMAND, 0xAD) - - drain = 0 - while (asm.inb(KBD_STATUS) & 0x01) != 0: - asm.inb(KBD_DATA) - drain += 1 - if drain > 1000: break - - _wait_write() - asm.outb(KBD_COMMAND, 0x20) - _wait_read() - ccb: t.CUInt8T = asm.inb(KBD_DATA) - - ccb = ccb | 0x01 - ccb = ccb | 0x40 - ccb = ccb & 0xEF - - _wait_write() - asm.outb(KBD_COMMAND, 0x60) - _wait_write() - asm.outb(KBD_DATA, ccb) - - _wait_write() - asm.outb(KBD_COMMAND, 0xAE) - - drain = 0 - while (asm.inb(KBD_STATUS) & 0x01) != 0: - asm.inb(KBD_DATA) - drain += 1 - if drain > 1000: break - - _wait_write() - asm.outb(KBD_DATA, 0xF4) - _wait_read() - asm.inb(KBD_DATA) - - idt.irqInstallHandler(1, irq_handler, "keyboard") diff --git a/Test/Kernel/drivers/input/mouse/mouse.vp b/Test/Kernel/drivers/input/mouse/mouse.vp deleted file mode 100644 index aee483fe..00000000 --- a/Test/Kernel/drivers/input/mouse/mouse.vp +++ /dev/null @@ -1,134 +0,0 @@ -import asm -import intr.idt as idt -import platform.pch.pic as pic -import drivers.serial.uart.serial as serial -import t, c - - -MOUSE_DATA: t.CDefine = 0x60 -MOUSE_STATUS: t.CDefine = 0x64 -MOUSE_COMMAND: t.CDefine = 0x64 - -MOUSE_BUF_SIZE: t.CDefine = 1024 - -MOUSE_LEFT: t.CDefine = 0x01 -MOUSE_RIGHT: t.CDefine = 0x02 -MOUSE_MIDDLE: t.CDefine = 0x04 - -class mouse_packet: - flags: t.CUInt8T - dx: t.CInt8T - dy: t.CInt8T - buttons: t.CUInt8T - -packets: t.CArray[mouse_packet, MOUSE_BUF_SIZE] -pack_head: t.CStatic | t.CUInt32T = 0 -pack_tail: t.CStatic | t.CUInt32T = 0 -pack_count: t.CStatic | t.CUInt32T = 0 - -cycle: t.CStatic | t.CUInt8T = 0 -byte1: t.CStatic | t.CUInt8T = 0 -byte2: t.CStatic | t.CInt8T = 0 -byte3: t.CStatic | t.CInt8T = 0 - -mouse_x: t.CStatic | t.CInt32T = 0 -mouse_y: t.CStatic | t.CInt32T = 0 -mouse_buttons: t.CStatic | t.CUInt8T = 0 - -def _wait_read(): - timeout: t.CUInt32T = 100000 - while timeout > 0: - if (asm.inb(MOUSE_STATUS) & 0x01) != 0: return - timeout -= 1 - -def _wait_write(): - timeout: t.CUInt32T = 100000 - while timeout > 0: - if (asm.inb(MOUSE_STATUS) & 0x02) == 0: return - timeout -= 1 - -def _write_cmd(cmd: t.CUInt8T): - _wait_write() - asm.outb(MOUSE_COMMAND, 0xD4) - _wait_write() - asm.outb(MOUSE_DATA, cmd) - _wait_read() - asm.inb(MOUSE_DATA) - -def irq_handler() -> t.CInt: - global cycle, byte1, byte2, byte3, pack_tail, pack_count - status: t.CUInt8T = asm.inb(MOUSE_STATUS) - if (status & 0x20) == 0: return 0 - data: t.CUInt8T = asm.inb(MOUSE_DATA) - if cycle == 0: - if (data & 0x08) != 0: - byte1 = data - cycle = 1 - return 0 - if cycle == 1: - byte2 = data - cycle = 2 - return 0 - byte3 = data - cycle = 0 - if pack_count < MOUSE_BUF_SIZE: - packets[pack_tail].flags = byte1 - packets[pack_tail].dx = byte2 - packets[pack_tail].dy = byte3 - packets[pack_tail].buttons = byte1 & t.CUInt8T(0x07) - pack_tail = pack_tail + 1 - if pack_tail >= MOUSE_BUF_SIZE: - pack_tail = 0 - pack_count += 1 - return 0 - -def read_packet(out: mouse_packet | t.CPtr) -> t.CInt: - global pack_head, pack_count - asm.cli() - if pack_count == 0: - asm.sti() - out.flags = 0 - out.dx = 0 - out.dy = 0 - out.buttons = 0 - return -1 - out.flags = packets[pack_head].flags - out.dx = packets[pack_head].dx - out.dy = packets[pack_head].dy - out.buttons = packets[pack_head].buttons - pack_head = pack_head + 1 - if pack_head >= MOUSE_BUF_SIZE: - pack_head = 0 - pack_count -= 1 - asm.sti() - return 0 - -def has_data() -> t.CInt: - return pack_count - -def get_x() -> t.CInt32T: - return mouse_x - -def get_y() -> t.CInt32T: - return mouse_y - -def get_buttons() -> t.CUInt8T: - return mouse_buttons - -def init(): - _wait_write() - asm.outb(MOUSE_COMMAND, 0xA8) - _wait_write() - asm.outb(MOUSE_COMMAND, 0x20) - _wait_read() - status: t.CUInt8T = asm.inb(MOUSE_DATA) - status = status | 0x02 - status = status & 0xDF - _wait_write() - asm.outb(MOUSE_COMMAND, 0x60) - _wait_write() - asm.outb(MOUSE_DATA, status) - _write_cmd(0xF6) - _write_cmd(0xF4) - pic.clearMask(12) - idt.irqInstallHandler(12, irq_handler, "mouse") diff --git a/Test/Kernel/drivers/serial/uart/serial.vp b/Test/Kernel/drivers/serial/uart/serial.vp deleted file mode 100644 index 35ad868f..00000000 --- a/Test/Kernel/drivers/serial/uart/serial.vp +++ /dev/null @@ -1,46 +0,0 @@ -import platform.pch.pic as pic -import su8250 -import t, c - - -# 串口初始化 -def init(): - # 初始化COM1端口 - su8250.init(su8250.COM1_PORT) - # 启用COM1中断(IRQ4) - pic.clearMask(4) - -# 发送一个字符到COM1 -def putc(cr: t.CChar): - su8250.putchar(su8250.COM1_PORT, cr) - -def putchar(cr: t.CChar): - su8250.putchar(su8250.COM1_PORT, cr) - -# 从COM1读取一个字符 -def getchar() -> t.CChar: - return su8250.getchar(su8250.COM1_PORT) - -# 发送一个字符串到COM1 -def puts(s: str): - # 逐个字符发送,直接复用putchar的逻辑 - for i in s: - putchar(i) - -# 检查COM1是否有数据可读 -def isDataAvailable() -> t.CInt: - return su8250.isDataAvailable(su8250.COM1_PORT) - -# 检查COM1发送缓冲区是否为空 -def isTransmitEmpty() -> t.CInt: - return su8250.isTransmitEmpty(su8250.COM1_PORT) - -# 发送32位十六进制值到COM1 -def put_hex32(value: t.CUInt32T): - hex_digits: t.CArray[t.CChar, None] = ["0123456789ABCDEF"] - buffer: t.CArray[t.CChar, 9] - for i in range(7, -1, -1): - buffer[i] = hex_digits[value & 0xF] - value >>= 4 - buffer[8] = '\0' - puts(buffer) diff --git a/Test/Kernel/drivers/serial/uart/su8250.vp b/Test/Kernel/drivers/serial/uart/su8250.vp deleted file mode 100644 index 568a41be..00000000 --- a/Test/Kernel/drivers/serial/uart/su8250.vp +++ /dev/null @@ -1,116 +0,0 @@ -import platform.pch as pch -import asm -import t, c - - - -# 串口端口定义 -COM1_PORT: t.CDefine = 0x3F8 # COM1端口地址 -COM2_PORT: t.CDefine = 0x2F8 # COM2端口地址 - -# 8250/16550 UART寄存器偏移 -UART_RBR: t.CDefine = 0 # 接收缓冲区寄存器(读) -UART_THR: t.CDefine = 0 # 发送保持寄存器(写) -UART_DLL: t.CDefine = 0 # 除数锁存低位(写,DLAB=1) -UART_IER: t.CDefine = 1 # 中断使能寄存器 -UART_DLM: t.CDefine = 1 # 除数锁存高位(写,DLAB=1) -UART_FCR: t.CDefine = 2 # FIFO控制寄存器 -UART_IIR: t.CDefine = 2 # 中断识别寄存器(读) -UART_LCR: t.CDefine = 3 # 线路控制寄存器 -UART_MCR: t.CDefine = 4 # 调制解调器控制寄存器 -UART_LSR: t.CDefine = 5 # 线路状态寄存器 -UART_MSR: t.CDefine = 6 # 调制解调器状态寄存器 -UART_SCR: t.CDefine = 7 # scratch register - - -UART_LSR_THRE: t.CDefine = 0x20 # THRE:发送保持寄存器空 -UART_LSR_TEMT: t.CDefine = 0x40 # TEMT:发送移位寄存器空(真正的发送完成) - - -# 线路控制寄存器位定义 -UART_LCR_DLAB: t.CDefine = 0x80 # 除数锁存访问位 -UART_LCR_8BIT: t.CDefine = 0x03 # 8位数据位 - -# 线路状态寄存器位定义 -UART_LSR_DR: t.CDefine = 0x01 # 数据就绪 -UART_LSR_THRE: t.CDefine = 0x20 # 发送保持寄存器空 - -# 波特率除数(115200 bps) -BAUD_115200: t.CDefine = 1 - - -# 初始化UART 8250/16550 -def init(port: t.CUInt16T): - # 1. 禁用中断 - asm.outb(port + UART_IER, 0x00) - delay(1000) - # 2. 设置波特率除数(115200 bps) - asm.outb(port + UART_LCR, UART_LCR_DLAB) # 设置DLAB位 - delay(1000) - asm.outb(port + UART_DLL, 0x01) # 除数低位 (115200 bps) - delay(1000) - asm.outb(port + UART_DLM, 0x00) # 除数高位 - delay(1000) - # 3. 设置线路控制:8位数据位,1位停止位,无校验 - asm.outb(port + UART_LCR, UART_LCR_8BIT) - delay(1000) - # 4. 初始化FIFO - asm.outb(port + UART_FCR, 0x07) # 启用FIFO,清除接收和发送FIFO - delay(1000) - # 5. 设置调制解调器控制 - asm.outb(port + UART_MCR, 0x03) # 启用DTR、RTS - delay(1000) - # 6. 清除任何待处理的中断 - asm.inb(port + UART_IIR) - delay(1000) - asm.inb(port + UART_RBR) - delay(1000) - # 7. 等待一段时间让设备稳定 - delay(10000) - -# 延迟函数 -def delay(count: t.CInt): - for i in range(count): c.Asm("nop") - -# 检查发送缓冲区是否为空 -def isTransmitEmpty(port: t.CUInt16T) -> t.CInt: - return asm.inb(port + UART_LSR) & UART_LSR_THRE - -def putchar(port: t.CUInt16T, cr: t.CChar): - # 1. 处理换行符:串口终端需要\r\n才会正确换行,只发\n会错位 - if cr == '\n': - # 直接发送\r,避免递归调用 - timeout: t.CUInt32T = 1000000 - while ((asm.inb(port + UART_LSR) & UART_LSR_THRE) == 0) and timeout: - c.Asm("nop") - timeout -= 1 - if timeout == 0: return - asm.outb(port + UART_THR, '\r') - timeout = 1000000 - while ((asm.inb(port + UART_LSR) & UART_LSR_TEMT) == 0) and timeout: - c.Asm("nop") - timeout -= 1 - # 2. 等待发送缓冲区为空 - timeout: t.CUInt32T = 1000000 - while ((asm.inb(port + UART_LSR) & UART_LSR_THRE) == 0) and timeout: - c.Asm("nop") - timeout -= 1 - if timeout == 0: return - # 3. 发送字符 - asm.outb(port + UART_THR, cr) - # 4. 等待发送完成 - timeout = 1000000 - while ((asm.inb(port + UART_LSR) & UART_LSR_TEMT) == 0) and timeout: - c.Asm("nop") - timeout -= 1 - -# 检查是否有数据可读 -def isDataAvailable(port: t.CUInt16T) -> t.CInt: - return asm.inb(port + UART_LSR) & UART_LSR_DR - -# 读取一个字符 -def getchar(port: t.CUInt16T) -> t.CChar: - # 等待数据可用 - while not isDataAvailable(port): pass - # 读取字符 - return asm.inb(port + UART_RBR) diff --git a/Test/Kernel/drivers/storage/ide/ide.vp b/Test/Kernel/drivers/storage/ide/ide.vp deleted file mode 100644 index d04d89e1..00000000 --- a/Test/Kernel/drivers/storage/ide/ide.vp +++ /dev/null @@ -1,161 +0,0 @@ -import asm -import t, c -import serial -import viperlib -import pci - - -class IDError(t.CEnum): - IDE_ERR_NONE: t.State = 0 - IDE_ERR_TIMEOUT: t.State - IDE_ERR_DEVICE_ERROR: t.State - IDE_ERR_DEVICE_BUSY: t.State - IDE_ERR_INVALID_PARAM: t.State - IDE_ERR_BUFFER_NULL: t.State - IDE_ERR_SECTOR_COUNT: t.State - IDE_ERR_DEVICE_NOT_READY: t.State - IDE_ERR_DEVICE_FAILURE: t.State - IDE_ERR_COMMAND_FAILED: t.State - IDE_ERR_INVALID_LBA: t.State - -IDE_baseport_PRIMARY: t.CDefine = 0x1F0 -IDE_baseport_SECONDARY: t.CDefine = 0x170 - -IDE_STATUS_BSY: t.CDefine = 0x80 -IDE_STATUS_DRDY: t.CDefine = 0x40 -IDE_STATUS_DF: t.CDefine = 0x20 -IDE_STATUS_DRQ: t.CDefine = 0x08 -IDE_STATUS_ERR: t.CDefine = 0x01 - -SECTOR_SIZE: t.CDefine = 512 - -_ide_initialized: t.CInt = 0 - -def waitReady(baseport: t.CUInt16T) -> t.CStatic | IDError: - timeout: t.CInt = 100000 - while timeout > 0: - status: t.CUInt8T = asm.inb(baseport + 7) - if status & IDE_STATUS_DF: - return IDError.IDE_ERR_DEVICE_FAILURE - if not status & IDE_STATUS_BSY and status & IDE_STATUS_DRDY: - return IDError.IDE_ERR_NONE - timeout -= 1 - return IDError.IDE_ERR_TIMEOUT - -def waitDataReady(baseport: t.CUInt16T) -> t.CStatic | IDError: - timeout: t.CInt = 100000 - while timeout > 0: - status: t.CUInt8T = asm.inb(baseport + 7) - if status & IDE_STATUS_ERR: return IDError.IDE_ERR_DEVICE_ERROR - if status & IDE_STATUS_DF: return IDError.IDE_ERR_DEVICE_FAILURE - if not status & IDE_STATUS_BSY and (status & IDE_STATUS_DRQ or status & IDE_STATUS_DRDY): - return IDError.IDE_ERR_NONE - timeout -= 1 - return IDError.IDE_ERR_TIMEOUT - -def init() -> t.CInt: - if _ide_initialized: return IDError.IDE_ERR_NONE - dbg: t.CArray[t.CChar, 120] - bus: t.CUInt8T - dev_n: t.CUInt8T - func: t.CUInt8T - for bus in range(2): - for dev_n in range(32): - for func in range(8): - vendor: t.CUInt16T = pci.pci_read16(bus, dev_n, func, 0x00) - if vendor == 0xFFFF: continue - cls: t.CUInt32T = pci.pci_get_class(bus, dev_n, func) - if cls == 0x010180 or cls == 0x0101: - cmd: t.CUInt16T = pci.pci_read16(bus, dev_n, func, 0x04) - pci.pci_write32(bus, dev_n, func, 0x04, t.CUInt32T(cmd | 0x0007)) - viperlib.snprintf(c.Addr(dbg), 120, "[ide] found at %d:%d:%d cmd=0x%04x\n", t.CInt(bus), t.CInt(dev_n), t.CInt(func), t.CUInt32T(pci.pci_read16(bus, dev_n, func, 0x04))) - serial.puts(dbg) - asm.outb(0x3F6, 0x04) - i: t.CInt - for i in range(10000): - asm.nop() - asm.outb(0x3F6, 0x00) - for i in range(10000): - asm.nop() - status: t.CUInt8T = asm.inb(0x1F7) - viperlib.snprintf(c.Addr(dbg), 120, "[ide] status=0x%02x\n", t.CUInt32T(status)) - serial.puts(dbg) - _ide_initialized = 1 - return IDError.IDE_ERR_NONE - -def readSector(lba: t.CUInt32T, buffer: t.CVoid | t.CPtr) -> t.CInt: - if buffer is None: return IDError.IDE_ERR_BUFFER_NULL - dbg: t.CArray[t.CChar, 120] - err: IDError = waitReady(IDE_baseport_PRIMARY) - if err != IDError.IDE_ERR_NONE: - viperlib.snprintf(c.Addr(dbg), 120, "[readSector] waitReady err=%d\n", t.CInt(err)) - serial.puts(dbg) - return err - asm.outb(0x3F6, 0x02) - asm.outb(0x1F2, 1) - asm.outb(0x1F3, t.CUInt8T(lba & 0xFF)) - asm.outb(0x1F4, t.CUInt8T((lba >> 8) & 0xFF)) - asm.outb(0x1F5, t.CUInt8T((lba >> 16) & 0xFF)) - asm.outb(0x1F6, t.CUInt8T(0xE0 | ((lba >> 24) & 0x0F))) - asm.outb(0x1F7, 0x20) - err = waitDataReady(IDE_baseport_PRIMARY) - if err != IDError.IDE_ERR_NONE: - st: t.CUInt8T = asm.inb(0x1F7) - viperlib.snprintf(c.Addr(dbg), 120, "[readSector] waitDataReady err=%d status=0x%02x\n", t.CInt(err), t.CUInt32T(st)) - serial.puts(dbg) - return err - st2: t.CUInt8T = asm.inb(0x1F7) - buf: t.CUInt16T | t.CPtr = t.CUInt16T(buffer, t.CPtr) - for j in range(256): - c.Set(c.Deref(buf), asm.inw(0x1F0)) - buf += 1 - first_byte: t.CUInt8T = c.Deref(t.CUInt8T(buffer, t.CPtr)) - # viperlib.snprintf(c.Addr(dbg), 120, "[readSector] lba=%lu status=0x%02x first=%02x\n", lba, t.CUInt32T(st2), t.CUInt32T(first_byte)) - # serial.puts(dbg) - return IDError.IDE_ERR_NONE - -def writeSector(lba: t.CUInt32T, buffer: t.CConst | t.CVoid | t.CPtr) -> t.CInt: - if buffer is None: return IDError.IDE_ERR_BUFFER_NULL - err: IDError = waitReady(IDE_baseport_PRIMARY) - if err != IDError.IDE_ERR_NONE: return err - asm.outb(0x3F6, 0x02) - asm.outb(0x1F2, 1) - asm.outb(0x1F3, t.CUInt8T(lba & 0xFF)) - asm.outb(0x1F4, t.CUInt8T((lba >> 8) & 0xFF)) - asm.outb(0x1F5, t.CUInt8T((lba >> 16) & 0xFF)) - asm.outb(0x1F6, t.CUInt8T(0xE0 | ((lba >> 24) & 0x0F))) - asm.outb(0x1F7, 0x30) - err = waitDataReady(IDE_baseport_PRIMARY) - if err != IDError.IDE_ERR_NONE: return err - buf: t.CUInt16T | t.CPtr = t.CUInt16T(buffer, t.CPtr) - for j in range(256): - val: t.CUInt16T = c.Deref(buf) - asm.outw(0x1F0, val) - buf += 1 - asm.outb(0x1F7, 0xE7) - waitReady(IDE_baseport_PRIMARY) - return IDError.IDE_ERR_NONE - -def getDiskSize() -> t.CUInt64T: - err: IDError = waitReady(IDE_baseport_PRIMARY) - if err != IDError.IDE_ERR_NONE: return 0 - asm.outb(0x1F6, 0xE0) - asm.outb(0x1F7, 0xEC) - err = waitDataReady(IDE_baseport_PRIMARY) - if err != IDError.IDE_ERR_NONE: return 0 - status: t.CUInt8T = asm.inb(0x1F7) - if not status & IDE_STATUS_DRDY: return 0 - if status & IDE_STATUS_ERR: return 0 - identify_data: t.CArray[t.CUInt16T, 256] - for i in range(256): - identify_data[i] = asm.inw(0x1F0) - totalSectors: t.CUInt64T = identify_data[60] | t.CUInt64T(identify_data[61]) << 16 - if identify_data[83] & (1 << 10): - lba48_sectors: t.CUInt64T = ( - t.CUInt64T(identify_data[100]) | - t.CUInt64T(identify_data[101]) << 16 | - t.CUInt64T(identify_data[102]) << 32 | - t.CUInt64T(identify_data[103]) << 48) - if lba48_sectors > totalSectors: - totalSectors = lba48_sectors - return totalSectors diff --git a/Test/Kernel/drivers/usb/hid/hid.vp b/Test/Kernel/drivers/usb/hid/hid.vp deleted file mode 100644 index a771b42f..00000000 --- a/Test/Kernel/drivers/usb/hid/hid.vp +++ /dev/null @@ -1,37 +0,0 @@ -import t, c -import drivers.usb.usb as usb - -HID_BOOT_PROTOCOL: t.CDefine = 0 -HID_REPORT_PROTOCOL: t.CDefine = 1 - -HID_KBD_REPORT_SIZE: t.CDefine = 8 -HID_MOUSE_REPORT_SIZE: t.CDefine = 4 - -class hid_kbd_report(t.CStruct): - modifier: t.CUInt8T - reserved: t.CUInt8T - keycode: t.CArray[t.CUInt8T, 6] - -class hid_mouse_report(t.CStruct): - buttons: t.CUInt8T - dx: t.CInt8T - dy: t.CInt8T - wheel: t.CInt8T - -def init_keyboard(dev: usb.usb_device | t.CPtr) -> t.CInt: - if dev.iface_class != 0x03: return -1 - if dev.iface_protocol != 0x01: return -2 - if dev.ep_in == 0: return -3 - return 0 - -def init_mouse(dev: usb.usb_device | t.CPtr) -> t.CInt: - if dev.iface_class != 0x03: return -1 - if dev.iface_protocol != 0x02: return -2 - if dev.ep_in == 0: return -3 - return 0 - -def read_keyboard(dev: usb.usb_device | t.CPtr, report: hid_kbd_report | t.CPtr) -> t.CInt: - return usb.read_interrupt(dev, c.Addr(report)) - -def read_mouse(dev: usb.usb_device | t.CPtr, report: hid_mouse_report | t.CPtr) -> t.CInt: - return usb.read_interrupt(dev, c.Addr(report)) diff --git a/Test/Kernel/drivers/usb/hid/usb_kbd.vp b/Test/Kernel/drivers/usb/hid/usb_kbd.vp deleted file mode 100644 index 0c953fc4..00000000 --- a/Test/Kernel/drivers/usb/hid/usb_kbd.vp +++ /dev/null @@ -1,111 +0,0 @@ -import t, c -import drivers.usb.usb as usb -import drivers.usb.hid.hid as hid -import drivers.usb.uhci as uhci -import drivers.serial.uart.serial as serial - -KBD_BUF_SIZE: t.CDefine = 1024 -KBD_EVT_PRESS: t.CDefine = 0 -KBD_EVT_RELEASE: t.CDefine = 1 - -class usb_kbd_event(t.CStruct): - modifier: t.CUInt8T - keycode: t.CUInt8T - event_type: t.CUInt8T - -kbd_buf: t.CArray[usb_kbd_event, KBD_BUF_SIZE] -kbd_buf_head: t.CInt = 0 -kbd_buf_tail: t.CInt = 0 -kbd_buf_count: t.CInt = 0 -kbd_dev: usb.usb_device | t.CPtr = None -kbd_report: hid.hid_kbd_report -kbd_prev_keycodes: t.CArray[t.CUInt8T, 6] -kbd_initialized: t.CInt = 0 -kbd_slot_id: t.CInt = -1 - -def init() -> t.CInt: - global kbd_dev, kbd_initialized, kbd_slot_id - dev: usb.usb_device | t.CPtr = usb.find_hid_device(0x01) - if dev is None: - serial.puts("[usb_kbd] no USB keyboard found\n") - return -1 - kbd_dev = dev - if hid.init_keyboard(dev) != 0: - serial.puts("[usb_kbd] init failed\n") - return -2 - kbd_initialized = 1 - serial.puts("[usb_kbd] initialized\n") - kbd_slot_id = uhci.register_int_callback(c.Addr(_on_int_complete)) - if kbd_slot_id < 0: - serial.puts("[usb_kbd] register callback failed\n") - kbd_initialized = 0 - return -3 - uhci.schedule_int_transfer(kbd_slot_id, dev.addr, dev.ep_in, dev.ls, t.CUInt8T(dev.ep_in_max), dev.ep_in_toggle, c.Addr(kbd_report)) - return 0 - -def _on_int_complete() -> t.CInt: - global kbd_buf_head, kbd_buf_tail, kbd_buf_count, kbd_prev_keycodes - if kbd_initialized == 0: return 0 - i: t.CInt - j: t.CInt - for i in range(6): - code: t.CUInt8T = kbd_report.keycode[i] - if code == 0: continue - found: t.CInt = 0 - for j in range(6): - if code == kbd_prev_keycodes[j]: - found = 1 - break - if found == 0: - if kbd_buf_count < KBD_BUF_SIZE: - kbd_buf[kbd_buf_tail].modifier = kbd_report.modifier - kbd_buf[kbd_buf_tail].keycode = code - kbd_buf[kbd_buf_tail].event_type = KBD_EVT_PRESS - kbd_buf_tail = kbd_buf_tail + 1 - if kbd_buf_tail >= KBD_BUF_SIZE: - kbd_buf_tail = 0 - kbd_buf_count += 1 - for i in range(6): - prev: t.CUInt8T = kbd_prev_keycodes[i] - if prev == 0: continue - found2: t.CInt = 0 - for j in range(6): - if prev == kbd_report.keycode[j]: - found2 = 1 - break - if found2 == 0: - if kbd_buf_count < KBD_BUF_SIZE: - kbd_buf[kbd_buf_tail].modifier = kbd_report.modifier - kbd_buf[kbd_buf_tail].keycode = prev - kbd_buf[kbd_buf_tail].event_type = KBD_EVT_RELEASE - kbd_buf_tail = kbd_buf_tail + 1 - if kbd_buf_tail >= KBD_BUF_SIZE: - kbd_buf_tail = 0 - kbd_buf_count += 1 - for i in range(6): - kbd_prev_keycodes[i] = kbd_report.keycode[i] - dev: usb.usb_device | t.CPtr = kbd_dev - if dev is not None and kbd_slot_id >= 0: - uhci.schedule_int_transfer(kbd_slot_id, dev.addr, dev.ep_in, dev.ls, t.CUInt8T(dev.ep_in_max), dev.ep_in_toggle, c.Addr(kbd_report)) - return 0 - -def has_data() -> t.CInt: - if kbd_buf_count > 0: return 1 - return 0 - -def poll() -> t.CInt: - if kbd_initialized == 0: return 0 - if kbd_buf_count > 0: return 1 - return 0 - -def read_event(out: usb_kbd_event | t.CPtr) -> t.CInt: - global kbd_buf_head, kbd_buf_count - if kbd_buf_count == 0: return -1 - out.modifier = kbd_buf[kbd_buf_head].modifier - out.keycode = kbd_buf[kbd_buf_head].keycode - out.event_type = kbd_buf[kbd_buf_head].event_type - kbd_buf_head = kbd_buf_head + 1 - if kbd_buf_head >= KBD_BUF_SIZE: - kbd_buf_head = 0 - kbd_buf_count -= 1 - return 0 diff --git a/Test/Kernel/drivers/usb/hid/usb_mouse.vp b/Test/Kernel/drivers/usb/hid/usb_mouse.vp deleted file mode 100644 index 96fdd49b..00000000 --- a/Test/Kernel/drivers/usb/hid/usb_mouse.vp +++ /dev/null @@ -1,77 +0,0 @@ -import t, c -import drivers.usb.usb as usb -import drivers.usb.hid.hid as hid -import drivers.usb.uhci as uhci -import drivers.serial.uart.serial as serial - -MOUSE_BUF_SIZE: t.CDefine = 1024 - -class usb_mouse_packet(t.CStruct): - buttons: t.CUInt8T - dx: t.CInt16T - dy: t.CInt16T - wheel: t.CInt8T - -mse_buf: t.CArray[usb_mouse_packet, MOUSE_BUF_SIZE] -mse_buf_head: t.CInt = 0 -mse_buf_tail: t.CInt = 0 -mse_buf_count: t.CInt = 0 -mse_dev: usb.usb_device | t.CPtr = None -mse_report: hid.hid_mouse_report -mse_initialized: t.CInt = 0 -mse_slot_id: t.CInt = -1 - -def init() -> t.CInt: - global mse_dev, mse_initialized, mse_slot_id - dev: usb.usb_device | t.CPtr = usb.find_hid_device(0x02) - if dev is None: - serial.puts("[usb_mse] no USB mouse found\n") - return -1 - mse_dev = dev - if hid.init_mouse(dev) != 0: - serial.puts("[usb_mse] init failed\n") - return -2 - mse_initialized = 1 - serial.puts("[usb_mse] initialized\n") - mse_slot_id = uhci.register_int_callback(c.Addr(_on_int_complete)) - if mse_slot_id < 0: - serial.puts("[usb_mse] register callback failed\n") - mse_initialized = 0 - return -3 - uhci.schedule_int_transfer(mse_slot_id, dev.addr, dev.ep_in, dev.ls, t.CUInt8T(dev.ep_in_max), dev.ep_in_toggle, c.Addr(mse_report)) - return 0 - -def _on_int_complete() -> t.CInt: - global mse_buf_head, mse_buf_tail, mse_buf_count - if mse_initialized == 0: return 0 - if mse_report.dx != 0 or mse_report.dy != 0 or mse_report.buttons != 0: - if mse_buf_count < MOUSE_BUF_SIZE: - mse_buf[mse_buf_tail].buttons = mse_report.buttons - mse_buf[mse_buf_tail].dx = t.CInt16T(mse_report.dx) - mse_buf[mse_buf_tail].dy = t.CInt16T(mse_report.dy) - mse_buf[mse_buf_tail].wheel = mse_report.wheel - mse_buf_tail = mse_buf_tail + 1 - if mse_buf_tail >= MOUSE_BUF_SIZE: - mse_buf_tail = 0 - mse_buf_count += 1 - dev: usb.usb_device | t.CPtr = mse_dev - if dev is not None and mse_slot_id >= 0: - uhci.schedule_int_transfer(mse_slot_id, dev.addr, dev.ep_in, dev.ls, t.CUInt8T(dev.ep_in_max), dev.ep_in_toggle, c.Addr(mse_report)) - return 0 - -def has_data() -> t.CInt: - if mse_buf_count > 0: return 1 - return 0 - -def read_packet(out: usb_mouse_packet | t.CPtr) -> t.CInt: - global mse_buf_head, mse_buf_count - if mse_buf_count == 0: return -1 - out.buttons = mse_buf[mse_buf_head].buttons - out.dx = mse_buf[mse_buf_head].dx - out.dy = mse_buf[mse_buf_head].dy - out.wheel = mse_buf[mse_buf_head].wheel - mse_buf_head = mse_buf_head + 1 - if mse_buf_head >= MOUSE_BUF_SIZE: - mse_buf_head = 0 - mse_buf_count -= 1 - return 0 diff --git a/Test/Kernel/drivers/usb/pci.vp b/Test/Kernel/drivers/usb/pci.vp deleted file mode 100644 index 97fd0fcc..00000000 --- a/Test/Kernel/drivers/usb/pci.vp +++ /dev/null @@ -1,93 +0,0 @@ -import t, c -import asm - -PCI_CONFIG_ADDR: t.CDefine = 0xCF8 -PCI_CONFIG_DATA: t.CDefine = 0xCFC - -PCI_CLASS_SERIAL_USB: t.CDefine = 0x0C03 -PCI_CLASS_SERIAL_UHCI: t.CDefine = 0x0C0300 -PCI_CLASS_SERIAL_OHCI: t.CDefine = 0x0C0310 -PCI_CLASS_SERIAL_EHCI: t.CDefine = 0x0C0320 -PCI_CLASS_SERIAL_XHCI: t.CDefine = 0x0C0330 - -PCI_CMD_IO_SPACE: t.CDefine = 0x0001 -PCI_CMD_BUS_MASTER: t.CDefine = 0x0004 - -class pci_device(t.CStruct): - bus: t.CUInt8T - dev: t.CUInt8T - func: t.CUInt8T - vendor_id: t.CUInt16T - device_id: t.CUInt16T - class_code: t.CUInt32T - irq: t.CUInt8T - bar: t.CArray[t.CUInt32T, 6] - -def pci_read32(bus: t.CUInt8T, dev: t.CUInt8T, func: t.CUInt8T, offset: t.CUInt8T) -> t.CUInt32T: - addr: t.CUInt32T = 0x80000000 | (t.CUInt32T(bus) << 16) | (t.CUInt32T(dev) << 11) | (t.CUInt32T(func) << 8) | (t.CUInt32T(offset) & 0xFC) - asm.outl(PCI_CONFIG_ADDR, addr) - return asm.inl(PCI_CONFIG_DATA) - -def pci_write32(bus: t.CUInt8T, dev: t.CUInt8T, func: t.CUInt8T, offset: t.CUInt8T, value: t.CUInt32T): - addr: t.CUInt32T = 0x80000000 | (t.CUInt32T(bus) << 16) | (t.CUInt32T(dev) << 11) | (t.CUInt32T(func) << 8) | (t.CUInt32T(offset) & 0xFC) - asm.outl(PCI_CONFIG_ADDR, addr) - asm.outl(PCI_CONFIG_DATA, value) - -def pci_read16(bus: t.CUInt8T, dev: t.CUInt8T, func: t.CUInt8T, offset: t.CUInt8T) -> t.CUInt16T: - val: t.CUInt32T = pci_read32(bus, dev, func, offset) - shift: t.CUInt32T = (t.CUInt32T(offset) & 0x02) * 8 - return t.CUInt16T((val >> shift) & 0xFFFF) - -def pci_read8(bus: t.CUInt8T, dev: t.CUInt8T, func: t.CUInt8T, offset: t.CUInt8T) -> t.CUInt8T: - val: t.CUInt32T = pci_read32(bus, dev, func, offset) - shift: t.CUInt32T = (t.CUInt32T(offset) & 0x03) * 8 - return t.CUInt8T((val >> shift) & 0xFF) - -def pci_get_class(bus: t.CUInt8T, dev: t.CUInt8T, func: t.CUInt8T) -> t.CUInt32T: - cls: t.CUInt8T = pci_read8(bus, dev, func, 0x0B) - sub: t.CUInt8T = pci_read8(bus, dev, func, 0x0A) - proto: t.CUInt8T = pci_read8(bus, dev, func, 0x09) - return (t.CUInt32T(cls) << 16) | (t.CUInt32T(sub) << 8) | t.CUInt32T(proto) - -def pci_get_bar(bus: t.CUInt8T, dev: t.CUInt8T, func: t.CUInt8T, bar_idx: t.CUInt8T) -> t.CUInt32T: - return pci_read32(bus, dev, func, 0x10 + bar_idx * 4) - -def pci_enable_device(dev: pci_device | t.CPtr): - cmd: t.CUInt16T = pci_read16(dev.bus, dev.dev, dev.func, 0x04) - cmd = cmd | PCI_CMD_IO_SPACE | PCI_CMD_BUS_MASTER - pci_write32(dev.bus, dev.dev, dev.func, 0x04, t.CUInt32T(cmd)) - -def pci_fill_device(bus: t.CUInt8T, dev_n: t.CUInt8T, func: t.CUInt8T, out: pci_device | t.CPtr): - out.bus = bus - out.dev = dev_n - out.func = func - out.vendor_id = pci_read16(bus, dev_n, func, 0x00) - out.device_id = pci_read16(bus, dev_n, func, 0x02) - out.class_code = pci_get_class(bus, dev_n, func) - out.irq = pci_read8(bus, dev_n, func, 0x3C) - i: t.CInt - for i in range(6): - out.bar[i] = pci_get_bar(bus, dev_n, func, t.CUInt8T(i)) - -_uhci_dev: pci_device -_uhci_found: t.CInt = 0 - -def find_uhci() -> t.CUInt16T: - global _uhci_dev, _uhci_found - bus: t.CUInt8T - dev_n: t.CUInt8T - func: t.CUInt8T - for bus in range(1): - for dev_n in range(32): - for func in range(8): - vendor: t.CUInt16T = pci_read16(bus, dev_n, func, 0x00) - if vendor == 0xFFFF: continue - cls: t.CUInt32T = pci_get_class(bus, dev_n, func) - if cls == PCI_CLASS_SERIAL_UHCI: - pci_fill_device(bus, dev_n, func, c.Addr(_uhci_dev)) - pci_enable_device(c.Addr(_uhci_dev)) - _uhci_found = 1 - bar: t.CUInt32T = _uhci_dev.bar[4] - io_base: t.CUInt16T = t.CUInt16T(bar & 0xFFFE) - return io_base - return 0 diff --git a/Test/Kernel/drivers/usb/uhci.vp b/Test/Kernel/drivers/usb/uhci.vp deleted file mode 100644 index 72183efd..00000000 --- a/Test/Kernel/drivers/usb/uhci.vp +++ /dev/null @@ -1,415 +0,0 @@ -import t, c -import asm -import mm.mm as mm -import viperstring as string -import drivers.serial.uart.serial as serial -import platform.pch.timer as timer -import intr.idt as idt -import platform.pch.pic as pic -import drivers.usb.pci as pci - -UHCI_USBCMD: t.CDefine = 0x00 -UHCI_USBSTS: t.CDefine = 0x02 -UHCI_USBINTR: t.CDefine = 0x04 -UHCI_FRNUM: t.CDefine = 0x06 -UHCI_FLBASEADD: t.CDefine = 0x08 -UHCI_SOFMOD: t.CDefine = 0x0C -UHCI_PORTSC1: t.CDefine = 0x10 -UHCI_PORTSC2: t.CDefine = 0x12 - -UHCI_CMD_RUN: t.CDefine = 0x0001 -UHCI_CMD_HCRESET: t.CDefine = 0x0002 -UHCI_CMD_GRESET: t.CDefine = 0x0004 -UHCI_CMD_MAXPKT: t.CDefine = 0x0080 -UHCI_CMD_CF: t.CDefine = 0x0040 - -UHCI_STS_HCHALTED: t.CDefine = 0x0020 -UHCI_STS_USBINT: t.CDefine = 0x0001 -UHCI_STS_USBERRINT: t.CDefine = 0x0002 -UHCI_STS_RESUME: t.CDefine = 0x0004 -UHCI_INTR_TIMEOUT: t.CDefine = 0x0001 -UHCI_INTR_RESUME: t.CDefine = 0x0002 -UHCI_INTR_IOC: t.CDefine = 0x0004 -UHCI_INTR_SHORT: t.CDefine = 0x0008 - -UHCI_PORT_CONNECT: t.CDefine = 0x0001 -UHCI_PORT_CONNECT_CHANGE: t.CDefine = 0x0002 -UHCI_PORT_ENABLE: t.CDefine = 0x0004 -UHCI_PORT_ENABLE_CHANGE: t.CDefine = 0x0008 -UHCI_PORT_RESET: t.CDefine = 0x0200 -UHCI_PORT_LOW_SPEED: t.CDefine = 0x0100 - -TD_CTRL_ACTIVE: t.CDefine = 0x00800000 -TD_CTRL_IOC: t.CDefine = 0x01000000 -TD_CTRL_LS: t.CDefine = 0x04000000 -TD_CTRL_SPD: t.CDefine = 0x20000000 -TD_CTRL_CERR_SHIFT: t.CDefine = 27 -TD_CTRL_CERR_MASK: t.CDefine = 0x18000000 - -TD_TOKEN_SETUP: t.CDefine = 0x2D -TD_TOKEN_IN: t.CDefine = 0x69 -TD_TOKEN_OUT: t.CDefine = 0xE1 - -TD_TOKEN_DATA0: t.CDefine = 0 -TD_TOKEN_DATA1: t.CDefine = 1 - -TD_LINK_TERMINATE: t.CDefine = 0x00000001 -TD_LINK_QH: t.CDefine = 0x00000002 -TD_LINK_DEPTH_FIRST: t.CDefine = 0x00000004 - -UHCI_NUM_FRAMES: t.CDefine = 1024 -UHCI_INT_SLOTS: t.CDefine = 4 - -class uhci_td(t.CStruct): - link: t.CUInt32T - ctrl_status: t.CUInt32T - token: t.CUInt32T - buffer: t.CUInt32T - -class uhci_qh(t.CStruct): - link: t.CUInt32T - element: t.CUInt32T - -class int_slot(t.CStruct): - td: uhci_td | t.CPtr - callback: t.CInt | t.CPtr - active: t.CInt - qh: uhci_qh | t.CPtr - -_io_base: t.CUInt16T = 0 -_frame_list: t.CUInt32T | t.CPtr = None -_ctrl_qh: uhci_qh | t.CPtr = None -_bulk_qh: uhci_qh | t.CPtr = None -_irq: t.CInt = -1 -_int_slots: t.CArray[int_slot, UHCI_INT_SLOTS] -_int_slot_count: t.CInt = 0 - -def _reg_read16(offset: t.CUInt16T) -> t.CUInt16T: - return asm.inw(_io_base + offset) - -def _reg_write16(offset: t.CUInt16T, value: t.CUInt16T): - asm.outw(_io_base + offset, value) - -def _reg_read32(offset: t.CUInt16T) -> t.CUInt32T: - return asm.inl(_io_base + offset) - -def _reg_write32(offset: t.CUInt16T, value: t.CUInt32T): - asm.outl(_io_base + offset, value) - -def _uhci_irq_handler() -> t.CInt: - sts: t.CUInt16T = _reg_read16(UHCI_USBSTS) - _reg_write16(UHCI_USBSTS, sts) - if (sts & (UHCI_STS_USBINT | UHCI_STS_USBERRINT)) == 0: - return 0 - for si in range(_int_slot_count): - slot: int_slot | t.CPtr = c.Addr(_int_slots[si]) - if slot.active and slot.td is not None and slot.callback is not None: - status: t.CUInt32T = slot.td.ctrl_status - if (status & TD_CTRL_ACTIVE) == 0: - slot.active = 0 - c.Asm(f"""mov rbp, rsp - and rsp, -16 - call {c.AsmInp(slot.callback, t.ASM_DESCR.REG_ANY)} - mov rsp, rbp""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RBX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_RSI, t.ASM_DESCR.CLOBBER_RDI, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11, - t.ASM_DESCR.CLOBBER_RBP]) - return 0 - -def register_int_callback(cb: t.CInt | t.CPtr) -> t.CInt: - global _int_slot_count - if _int_slot_count >= UHCI_INT_SLOTS: - return -1 - si: t.CInt = _int_slot_count - qh: uhci_qh | t.CPtr = mm.malloc_direct(uhci_qh.__sizeof__()) - if qh is None: - return -2 - string.memset(c.Addr(qh), 0, uhci_qh.__sizeof__()) - _qh_set_link(qh, 0, 0, 1) - _qh_set_element(qh, 0, 1) - td: uhci_td | t.CPtr = mm.malloc_direct(uhci_td.__sizeof__()) - if td is None: - return -3 - string.memset(c.Addr(td), 0, uhci_td.__sizeof__()) - slot: int_slot | t.CPtr = c.Addr(_int_slots[si]) - slot.td = td - slot.callback = cb - slot.active = 0 - slot.qh = qh - _int_slot_count = si + 1 - _rebuild_int_chain() - return si - -def schedule_int_transfer(slot_id: t.CInt, dev_addr: t.CUInt8T, endpoint: t.CUInt8T, ls: t.CInt, max_pkt: t.CUInt8T, toggle_ptr: t.CUInt8T | t.CPtr, buf: t.CVoid | t.CPtr): - if slot_id < 0 or slot_id >= _int_slot_count: - return - slot: int_slot | t.CPtr = c.Addr(_int_slots[slot_id]) - td: uhci_td | t.CPtr = slot.td - qh: uhci_qh | t.CPtr = slot.qh - if td is None or qh is None: - return - string.memset(c.Addr(td), 0, uhci_td.__sizeof__()) - _td_set_link(td, 0, 0, 1) - _td_set_ctrl(td, ls, max_pkt) - _td_set_token(td, TD_TOKEN_IN, dev_addr, endpoint, toggle_ptr, max_pkt) - td.ctrl_status = td.ctrl_status | TD_CTRL_IOC - td.buffer = t.CUInt32T(t.CUInt64T(buf)) - _qh_set_element(qh, t.CUInt32T(t.CUInt64T(td)), 0) - slot.active = 1 - -def _rebuild_int_chain(): - if _int_slot_count == 0: - return - first_qh: uhci_qh | t.CPtr = None - prev_qh: uhci_qh | t.CPtr = None - for si in range(_int_slot_count): - cur_qh: uhci_qh | t.CPtr = _int_slots[si].qh - if cur_qh is not None: - if first_qh is None: - first_qh = cur_qh - if prev_qh is not None: - _qh_set_link(prev_qh, t.CUInt32T(t.CUInt64T(cur_qh)) | TD_LINK_QH, 1, 0) - prev_qh = cur_qh - if prev_qh is not None: - _qh_set_link(prev_qh, t.CUInt32T(t.CUInt64T(_ctrl_qh)) | TD_LINK_QH, 1, 0) - if first_qh is not None: - qh_addr: t.CUInt32T = t.CUInt32T(t.CUInt64T(first_qh)) | TD_LINK_QH - i: t.CInt - for i in range(UHCI_NUM_FRAMES): - entry_ptr: t.CUInt32T | t.CPtr = _frame_list + t.CUInt64T(i) * 4 - c.Set(c.Deref(entry_ptr), qh_addr) - -def _td_set_link(td: uhci_td | t.CPtr, addr: t.CUInt32T, is_qh: t.CInt, terminate: t.CInt): - val: t.CUInt32T = (addr & 0xFFFFFFF0) - if is_qh: val = val | TD_LINK_QH - if terminate: val = val | TD_LINK_TERMINATE - td.link = val - -def _td_set_token(td: uhci_td | t.CPtr, pid: t.CUInt8T, dev_addr: t.CUInt8T, endpoint: t.CUInt8T, toggle: t.CUInt8T, max_len: t.CUInt16T): - len_bits: t.CUInt32T - if max_len == 0: - len_bits = 0x7FF - else: - len_bits = t.CUInt32T(max_len) - 1 - td.token = (t.CUInt32T(pid) << 0) | (t.CUInt32T(dev_addr) << 8) | (t.CUInt32T(endpoint & 0x0F) << 15) | (t.CUInt32T(toggle & 1) << 19) | (len_bits << 21) - -def _td_set_ctrl(td: uhci_td | t.CPtr, ls: t.CInt, maxlen: t.CUInt16T): - td.ctrl_status = TD_CTRL_ACTIVE | (3 << TD_CTRL_CERR_SHIFT) - if ls: td.ctrl_status = td.ctrl_status | TD_CTRL_LS - -def _qh_set_link(qh: uhci_qh | t.CPtr, addr: t.CUInt32T, is_qh: t.CInt, terminate: t.CInt): - val: t.CUInt32T = (addr & 0xFFFFFFF0) - if is_qh: val = val | TD_LINK_QH - if terminate: val = val | TD_LINK_TERMINATE - qh.link = val - -def _qh_set_element(qh: uhci_qh | t.CPtr, addr: t.CUInt32T, terminate: t.CInt): - val: t.CUInt32T = (addr & 0xFFFFFFF0) - if terminate: val = val | TD_LINK_TERMINATE - qh.element = val - -def _wait_for_complete(td: uhci_td | t.CPtr, timeout_ms: t.CInt) -> t.CInt: - start: t.CUInt64T = timer.timer_get_ticks() - deadline: t.CUInt64T = start + t.CUInt64T(timeout_ms) - poll_cnt: t.CInt = 0 - while timer.timer_get_ticks() < deadline: - status: t.CUInt32T = td.ctrl_status - if (status & TD_CTRL_ACTIVE) == 0: - if (status & 0x00600000) != 0: - return -1 - return 0 - poll_cnt += 1 - if poll_cnt >= 100: - poll_cnt = 0 - asm.sti() - asm.hlt() - return -2 - -def reset(io_base: t.CUInt16T) -> t.CInt: - global _io_base - _io_base = io_base - _reg_write16(UHCI_USBCMD, UHCI_CMD_HCRESET) - i: t.CInt - for i in range(1000): - if (_reg_read16(UHCI_USBCMD) & UHCI_CMD_HCRESET) == 0: - break - _reg_write16(UHCI_USBSTS, 0xFFFF) - _reg_write16(UHCI_USBINTR, 0x0000) - return 0 - -def init(io_base: t.CUInt16T) -> t.CInt: - global _io_base, _frame_list, _ctrl_qh, _bulk_qh, _int_slot_count - _io_base = io_base - _int_slot_count = 0 - - serial.puts("[uhci] resetting...\n") - if reset(io_base) != 0: - serial.puts("[uhci] reset failed\n") - return -1 - - serial.puts("[uhci] allocating frame list...\n") - _frame_list = mm.malloc(UHCI_NUM_FRAMES * 4) - if _frame_list is None: - serial.puts("[uhci] frame list alloc failed\n") - return -2 - string.memset(_frame_list, 0, UHCI_NUM_FRAMES * 4) - - _ctrl_qh = mm.malloc_direct(uhci_qh.__sizeof__()) - if _ctrl_qh is None: - serial.puts("[uhci] ctrl_qh alloc failed\n") - return -3 - string.memset(c.Addr(_ctrl_qh), 0, uhci_qh.__sizeof__()) - _qh_set_link(_ctrl_qh, 0, 0, 1) - _qh_set_element(_ctrl_qh, 0, 1) - - _bulk_qh = mm.malloc_direct(uhci_qh.__sizeof__()) - if _bulk_qh is None: - serial.puts("[uhci] bulk_qh alloc failed\n") - return -4 - string.memset(c.Addr(_bulk_qh), 0, uhci_qh.__sizeof__()) - _qh_set_link(_bulk_qh, 0, 0, 1) - _qh_set_element(_bulk_qh, 0, 1) - - serial.puts("[uhci] setting up frame list...\n") - qh_addr: t.CUInt32T = t.CUInt32T(c.Addr(_ctrl_qh)) | TD_LINK_QH - i: t.CInt - for i in range(UHCI_NUM_FRAMES): - entry_ptr: t.CUInt32T | t.CPtr = _frame_list + t.CUInt64T(i) * 4 - c.Set(c.Deref(entry_ptr), qh_addr) - - _reg_write32(UHCI_FLBASEADD, t.CUInt32T(t.CUInt64T(_frame_list))) - _reg_write16(UHCI_FRNUM, 0) - _reg_write16(UHCI_SOFMOD, 64) - - _reg_write16(UHCI_USBCMD, UHCI_CMD_CF | UHCI_CMD_MAXPKT | UHCI_CMD_RUN) - - timer.timer_msleep(10) - - _reg_write16(UHCI_USBSTS, 0xFFFF) - _reg_write16(UHCI_USBINTR, UHCI_INTR_IOC | UHCI_INTR_SHORT) - - _irq = t.CInt(pci._uhci_dev.irq) - if _irq > 0 and _irq < 16: - idt.irqInstallHandler(_irq, _uhci_irq_handler, "uhci") - pic.clearMask(t.CUInt8T(_irq)) - - serial.puts("[uhci] started\n") - return 0 - -def port_reset(port: t.CInt) -> t.CInt: - sc: t.CUInt16T - if port == 0: - sc = _reg_read16(UHCI_PORTSC1) - else: - sc = _reg_read16(UHCI_PORTSC2) - - if (sc & UHCI_PORT_CONNECT) == 0: - return -1 - - if port == 0: - _reg_write16(UHCI_PORTSC1, sc | UHCI_PORT_CONNECT_CHANGE | UHCI_PORT_ENABLE_CHANGE) - else: - _reg_write16(UHCI_PORTSC2, sc | UHCI_PORT_CONNECT_CHANGE | UHCI_PORT_ENABLE_CHANGE) - - if port == 0: - _reg_write16(UHCI_PORTSC1, UHCI_PORT_RESET) - else: - _reg_write16(UHCI_PORTSC2, UHCI_PORT_RESET) - - timer.timer_msleep(50) - - if port == 0: - _reg_write16(UHCI_PORTSC1, 0x0000) - else: - _reg_write16(UHCI_PORTSC2, 0x0000) - - timer.timer_msleep(10) - - if port == 0: - sc = _reg_read16(UHCI_PORTSC1) - _reg_write16(UHCI_PORTSC1, sc | UHCI_PORT_ENABLE | UHCI_PORT_CONNECT_CHANGE | UHCI_PORT_ENABLE_CHANGE) - else: - sc = _reg_read16(UHCI_PORTSC2) - _reg_write16(UHCI_PORTSC2, sc | UHCI_PORT_ENABLE | UHCI_PORT_CONNECT_CHANGE | UHCI_PORT_ENABLE_CHANGE) - - timer.timer_msleep(10) - - if port == 0: - sc = _reg_read16(UHCI_PORTSC1) - else: - sc = _reg_read16(UHCI_PORTSC2) - - if (sc & UHCI_PORT_ENABLE) == 0: - return -2 - - return 0 - -def port_is_connected(port: t.CInt) -> t.CInt: - sc: t.CUInt16T - if port == 0: - sc = _reg_read16(UHCI_PORTSC1) - else: - sc = _reg_read16(UHCI_PORTSC2) - if sc & UHCI_PORT_CONNECT: return 1 - return 0 - -def port_is_low_speed(port: t.CInt) -> t.CInt: - sc: t.CUInt16T - if port == 0: - sc = _reg_read16(UHCI_PORTSC1) - else: - sc = _reg_read16(UHCI_PORTSC2) - if sc & UHCI_PORT_LOW_SPEED: return 1 - return 0 - -def control_transfer(dev_addr: t.CUInt8T, endpoint: t.CUInt8T, ls: t.CInt, max_pkt: t.CUInt8T, setup_buf: t.CVoid | t.CPtr, data_buf: t.CVoid | t.CPtr, data_len: t.CUInt16T, data_in: t.CInt) -> t.CInt: - td_count: t.CInt = 2 - if data_len > 0: - td_count = td_count + 1 - total: t.CUInt64T = t.CUInt64T(td_count) * uhci_td.__sizeof__() - tds: uhci_td | t.CPtr = mm.malloc_direct(total) - if tds is None: return -1 - string.memset(c.Addr(tds), 0, total) - - setup_td: uhci_td | t.CPtr = tds - _td_set_link(setup_td, t.CUInt32T(t.CUInt64T(tds) + uhci_td.__sizeof__()), 0, 0) - _td_set_ctrl(setup_td, ls, 8) - _td_set_token(setup_td, TD_TOKEN_SETUP, dev_addr, endpoint, TD_TOKEN_DATA0, 8) - setup_td.buffer = t.CUInt32T(t.CUInt64T(setup_buf)) - - if data_len > 0: - data_td: uhci_td | t.CPtr = t.CUInt64T(tds) + uhci_td.__sizeof__() - _td_set_link(data_td, t.CUInt32T(t.CUInt64T(data_td) + uhci_td.__sizeof__()), 0, 0) - _td_set_ctrl(data_td, ls, max_pkt) - if data_in: - _td_set_token(data_td, TD_TOKEN_IN, dev_addr, endpoint, TD_TOKEN_DATA1, data_len) - else: - _td_set_token(data_td, TD_TOKEN_OUT, dev_addr, endpoint, TD_TOKEN_DATA1, data_len) - data_td.buffer = t.CUInt32T(t.CUInt64T(data_buf)) - - status_td: uhci_td | t.CPtr = t.CUInt64T(data_td) + uhci_td.__sizeof__() - _td_set_link(status_td, 0, 0, 1) - _td_set_ctrl(status_td, ls, max_pkt) - if data_in: - _td_set_token(status_td, TD_TOKEN_OUT, dev_addr, endpoint, TD_TOKEN_DATA1, 0) - else: - _td_set_token(status_td, TD_TOKEN_IN, dev_addr, endpoint, TD_TOKEN_DATA1, 0) - status_td.buffer = 0 - else: - status_td: uhci_td | t.CPtr = t.CUInt64T(tds) + uhci_td.__sizeof__() - _td_set_link(status_td, 0, 0, 1) - _td_set_ctrl(status_td, ls, max_pkt) - _td_set_token(status_td, TD_TOKEN_IN, dev_addr, endpoint, TD_TOKEN_DATA1, 0) - status_td.buffer = 0 - - _qh_set_element(_ctrl_qh, t.CUInt32T(t.CUInt64T(setup_td)), 0) - - result: t.CInt = _wait_for_complete(status_td, 500) - - _qh_set_element(_ctrl_qh, 0, 1) - mm.free(tds) - return result diff --git a/Test/Kernel/drivers/usb/usb.vp b/Test/Kernel/drivers/usb/usb.vp deleted file mode 100644 index d0f8d47c..00000000 --- a/Test/Kernel/drivers/usb/usb.vp +++ /dev/null @@ -1,330 +0,0 @@ -import t, c -import mm.mm as mm -import viperstring as string -import drivers.serial.uart.serial as serial -import drivers.usb.uhci as uhci -import drivers.usb.pci as pci -import platform.pch.timer as timer -import viperlib - -USB_DESC_DEVICE: t.CDefine = 1 -USB_DESC_CONFIG: t.CDefine = 2 -USB_DESC_STRING: t.CDefine = 3 -USB_DESC_INTERFACE: t.CDefine = 4 -USB_DESC_ENDPOINT: t.CDefine = 5 - -USB_REQ_GET_STATUS: t.CDefine = 0 -USB_REQ_CLEAR_FEATURE: t.CDefine = 1 -USB_REQ_SET_FEATURE: t.CDefine = 3 -USB_REQ_SET_ADDRESS: t.CDefine = 5 -USB_REQ_GET_DESCRIPTOR: t.CDefine = 6 -USB_REQ_SET_DESCRIPTOR: t.CDefine = 7 -USB_REQ_GET_CONFIGURATION: t.CDefine = 8 -USB_REQ_SET_CONFIGURATION: t.CDefine = 9 - -USB_REQ_SET_INTERFACE: t.CDefine = 11 - -HID_CLASS: t.CDefine = 0x03 -HID_SUBCLASS_BOOT: t.CDefine = 0x01 -HID_PROTO_KEYBOARD: t.CDefine = 0x01 -HID_PROTO_MOUSE: t.CDefine = 0x02 - -HID_REQ_SET_PROTOCOL: t.CDefine = 0x0B -HID_REQ_SET_IDLE: t.CDefine = 0x0A -HID_REQ_GET_REPORT: t.CDefine = 0x01 - -USB_MAX_DEVICES: t.CDefine = 8 - -class usb_dev_desc(t.CStruct): - bLength: t.CUInt8T - bDescriptorType: t.CUInt8T - bcdUSB: t.CUInt16T - bDeviceClass: t.CUInt8T - bDeviceSubClass: t.CUInt8T - bDeviceProtocol: t.CUInt8T - bMaxPacketSize0: t.CUInt8T - idVendor: t.CUInt16T - idProduct: t.CUInt16T - bcdDevice: t.CUInt16T - iManufacturer: t.CUInt8T - iProduct: t.CUInt8T - iSerialNumber: t.CUInt8T - bNumConfigurations: t.CUInt8T - -class usb_config_desc(t.CStruct): - bLength: t.CUInt8T - bDescriptorType: t.CUInt8T - wTotalLength: t.CUInt16T - bNumInterfaces: t.CUInt8T - bConfigurationValue: t.CUInt8T - iConfiguration: t.CUInt8T - bmAttributes: t.CUInt8T - bMaxPower: t.CUInt8T - -class usb_iface_desc(t.CStruct): - bLength: t.CUInt8T - bDescriptorType: t.CUInt8T - bInterfaceNumber: t.CUInt8T - bAlternateSetting: t.CUInt8T - bNumEndpoints: t.CUInt8T - bInterfaceClass: t.CUInt8T - bInterfaceSubClass: t.CUInt8T - bInterfaceProtocol: t.CUInt8T - iInterface: t.CUInt8T - -class usb_ep_desc(t.CStruct): - bLength: t.CUInt8T - bDescriptorType: t.CUInt8T - bEndpointAddress: t.CUInt8T - bmAttributes: t.CUInt8T - wMaxPacketSize: t.CUInt16T - bInterval: t.CUInt8T - -class usb_setup_pkt(t.CStruct): - bmRequestType: t.CUInt8T - bRequest: t.CUInt8T - wValue: t.CUInt16T - wIndex: t.CUInt16T - wLength: t.CUInt16T - -class usb_device(t.CStruct): - addr: t.CUInt8T - ls: t.CInt - max_pkt0: t.CUInt8T - iface_class: t.CUInt8T - iface_subclass: t.CUInt8T - iface_protocol: t.CUInt8T - iface_num: t.CUInt8T - ep_in: t.CUInt8T - ep_in_max: t.CUInt16T - ep_in_interval: t.CUInt8T - ep_in_toggle: t.CUInt8T - configured: t.CInt - -_devices: t.CArray[usb_device, USB_MAX_DEVICES] -_device_count: t.CInt = 0 - -def _setup_packet(bmRequestType: t.CUInt8T, bRequest: t.CUInt8T, wValue: t.CUInt16T, wIndex: t.CUInt16T, wLength: t.CUInt16T, buf: usb_setup_pkt | t.CPtr): - buf.bmRequestType = bmRequestType - buf.bRequest = bRequest - buf.wValue = wValue - buf.wIndex = wIndex - buf.wLength = wLength - -def _send_control(dev_addr: t.CUInt8T, ls: t.CInt, max_pkt: t.CUInt8T, setup: usb_setup_pkt | t.CPtr, data_buf: t.CVoid | t.CPtr, data_len: t.CUInt16T, data_in: t.CInt) -> t.CInt: - return uhci.control_transfer(dev_addr, 0, ls, max_pkt, c.Addr(setup), data_buf, data_len, data_in) - -def get_descriptor(dev_addr: t.CUInt8T, ls: t.CInt, max_pkt: t.CUInt8T, desc_type: t.CUInt8T, desc_idx: t.CUInt8T, buf: t.CVoid | t.CPtr, length: t.CUInt16T) -> t.CInt: - setup: usb_setup_pkt - _setup_packet(0x80, USB_REQ_GET_DESCRIPTOR, (t.CUInt16T(desc_type) << 8) | desc_idx, 0, length, c.Addr(setup)) - return _send_control(dev_addr, ls, max_pkt, c.Addr(setup), buf, length, 1) - -def set_address(dev_addr: t.CUInt8T, ls: t.CInt, max_pkt: t.CUInt8T, new_addr: t.CUInt8T) -> t.CInt: - setup: usb_setup_pkt - _setup_packet(0x00, USB_REQ_SET_ADDRESS, new_addr, 0, 0, c.Addr(setup)) - return _send_control(dev_addr, ls, max_pkt, c.Addr(setup), None, 0, 0) - -def set_configuration(dev_addr: t.CUInt8T, ls: t.CInt, max_pkt: t.CUInt8T, config_val: t.CUInt8T) -> t.CInt: - setup: usb_setup_pkt - _setup_packet(0x00, USB_REQ_SET_CONFIGURATION, config_val, 0, 0, c.Addr(setup)) - return _send_control(dev_addr, ls, max_pkt, c.Addr(setup), None, 0, 0) - -def hid_set_protocol(dev_addr: t.CUInt8T, ls: t.CInt, max_pkt: t.CUInt8T, iface: t.CUInt8T, protocol: t.CUInt8T) -> t.CInt: - setup: usb_setup_pkt - _setup_packet(0x21, HID_REQ_SET_PROTOCOL, protocol, t.CUInt16T(iface), 0, c.Addr(setup)) - return _send_control(dev_addr, ls, max_pkt, c.Addr(setup), None, 0, 0) - -def hid_set_idle(dev_addr: t.CUInt8T, ls: t.CInt, max_pkt: t.CUInt8T, iface: t.CUInt8T, duration: t.CUInt8T) -> t.CInt: - setup: usb_setup_pkt - _setup_packet(0x21, HID_REQ_SET_IDLE, t.CUInt16T(duration) << 8, t.CUInt16T(iface), 0, c.Addr(setup)) - return _send_control(dev_addr, ls, max_pkt, c.Addr(setup), None, 0, 0) - -def _parse_config(dev: usb_device | t.CPtr, config_buf: t.CVoid | t.CPtr, total_len: t.CUInt16T): - offset: t.CInt = 0 - found_hid: t.CInt = 0 - while offset < t.CInt(total_len): - p: t.CUInt8T | t.CPtr = config_buf + t.CUInt64T(offset) - desc_len: t.CUInt8T = c.Deref(p) - p2: t.CUInt8T | t.CPtr = config_buf + t.CUInt64T(offset) + 1 - desc_type: t.CUInt8T = c.Deref(p2) - if desc_len == 0: break - if desc_type == USB_DESC_INTERFACE: - iface: usb_iface_desc | t.CPtr = config_buf + t.CUInt64T(offset) - if iface.bInterfaceClass == HID_CLASS: - found_hid = 1 - dev.iface_class = HID_CLASS - dev.iface_subclass = iface.bInterfaceSubClass - dev.iface_protocol = iface.bInterfaceProtocol - dev.iface_num = iface.bInterfaceNumber - if desc_type == USB_DESC_ENDPOINT and found_hid: - ep: usb_ep_desc | t.CPtr = config_buf + t.CUInt64T(offset) - if (ep.bEndpointAddress & 0x80) != 0: - dev.ep_in = ep.bEndpointAddress & 0x0F - dev.ep_in_max = ep.wMaxPacketSize - dev.ep_in_interval = ep.bInterval - found_hid = 0 - offset = offset + t.CInt(desc_len) - -def enumerate_port(port: t.CInt) -> t.CInt: - global _device_count - if _device_count >= USB_MAX_DEVICES: return -1 - - ls: t.CInt = uhci.port_is_low_speed(port) - - reset_ok: t.CInt = -1 - reset_retry: t.CInt - for reset_retry in range(3): - if uhci.port_reset(port) == 0: - reset_ok = 0 - break - timer.timer_msleep(50) - if reset_ok != 0: - return -2 - - timer.timer_msleep(10) - - dev_buf: t.CVoid | t.CPtr = mm.malloc(usb_dev_desc.__sizeof__()) - if dev_buf is None: return -3 - string.memset(dev_buf, 0, usb_dev_desc.__sizeof__()) - - result: t.CInt = get_descriptor(0, ls, 8, USB_DESC_DEVICE, 0, dev_buf, 8) - retry: t.CInt - for retry in range(3): - if result == 0: break - timer.timer_msleep(50) - uhci.port_reset(port) - timer.timer_msleep(10) - result = get_descriptor(0, ls, 8, USB_DESC_DEVICE, 0, dev_buf, 8) - if result != 0: - mm.free(dev_buf) - return -4 - - desc: usb_dev_desc | t.CPtr = dev_buf - max_pkt: t.CUInt8T = desc.bMaxPacketSize0 - if max_pkt < 8: max_pkt = 8 - - new_addr: t.CUInt8T = t.CUInt8T(_device_count + 1) - result = set_address(0, ls, max_pkt, new_addr) - for retry in range(3): - if result == 0: break - timer.timer_msleep(20) - result = set_address(0, ls, max_pkt, new_addr) - if result != 0: - mm.free(dev_buf) - return -5 - - timer.timer_msleep(10) - - dev: usb_device | t.CPtr = c.Addr(_devices[_device_count]) - dev.addr = new_addr - dev.ls = ls - dev.max_pkt0 = max_pkt - dev.configured = 0 - dev.iface_class = 0 - dev.iface_subclass = 0 - dev.iface_protocol = 0 - dev.ep_in = 0 - dev.ep_in_max = 0 - dev.ep_in_interval = 0 - dev.ep_in_toggle = 0 - - config_buf: t.CVoid | t.CPtr = mm.malloc(256) - if config_buf is None: - mm.free(dev_buf) - return -6 - string.memset(config_buf, 0, 256) - - result = get_descriptor(new_addr, ls, max_pkt, USB_DESC_CONFIG, 0, config_buf, 9) - for retry in range(3): - if result == 0: break - timer.timer_msleep(50) - result = get_descriptor(new_addr, ls, max_pkt, USB_DESC_CONFIG, 0, config_buf, 9) - if result != 0: - mm.free(config_buf) - mm.free(dev_buf) - return -7 - - cfg: usb_config_desc | t.CPtr = config_buf - total_len: t.CUInt16T = cfg.wTotalLength - if total_len > 256: total_len = 256 - - result = get_descriptor(new_addr, ls, max_pkt, USB_DESC_CONFIG, 0, config_buf, total_len) - for retry in range(3): - if result == 0: break - timer.timer_msleep(50) - result = get_descriptor(new_addr, ls, max_pkt, USB_DESC_CONFIG, 0, config_buf, total_len) - if result != 0: - mm.free(config_buf) - mm.free(dev_buf) - return -8 - - _parse_config(dev, config_buf, total_len) - - result = set_configuration(new_addr, ls, max_pkt, cfg.bConfigurationValue) - if result != 0: - mm.free(config_buf) - mm.free(dev_buf) - return -9 - - dev.configured = 1 - - if dev.iface_class == HID_CLASS: - hid_set_protocol(new_addr, ls, max_pkt, dev.iface_num, 0) - hid_set_idle(new_addr, ls, max_pkt, dev.iface_num, 0) - - _device_count = _device_count + 1 - mm.free(config_buf) - mm.free(dev_buf) - return t.CInt(new_addr) - -def init() -> t.CInt: - global _device_count - _device_count = 0 - - io_base: t.CUInt16T = pci.find_uhci() - if io_base == 0: - serial.puts("[usb] UHCI controller not found\n") - return -1 - - buf: t.CArray[t.CChar, 64] - viperlib.snprintf(c.Addr(buf), 64, "[usb] UHCI at I/O 0x%04X\n", t.CUInt32T(io_base)) - serial.puts(buf) - - if uhci.init(io_base) != 0: - serial.puts("[usb] UHCI init failed\n") - return -2 - - serial.puts("[usb] UHCI initialized\n") - - timer.timer_msleep(50) - - port: t.CInt - for port in range(2): - if uhci.port_is_connected(port): - viperlib.snprintf(c.Addr(buf), 64, "[usb] port %d connected\n", t.CUInt32T(port)) - serial.puts(buf) - dev_id: t.CInt = enumerate_port(port) - if dev_id > 0: - dev: usb_device | t.CPtr = c.Addr(_devices[dev_id - 1]) - viperlib.snprintf(c.Addr(buf), 64, "[usb] device addr=%d class=%02X proto=%02X ep=%d\n", - t.CUInt32T(dev.addr), t.CUInt32T(dev.iface_class), - t.CUInt32T(dev.iface_protocol), t.CUInt32T(dev.ep_in)) - serial.puts(buf) - else: - viperlib.snprintf(c.Addr(buf), 64, "[usb] enumerate port %d failed: %d\n", t.CUInt32T(port), t.CInt32T(dev_id)) - serial.puts(buf) - - return _device_count - -def find_hid_device(protocol: t.CUInt8T) -> usb_device | t.CPtr: - i: t.CInt - for i in range(_device_count): - dev: usb_device | t.CPtr = c.Addr(_devices[i]) - if dev.iface_class == HID_CLASS: - if dev.iface_protocol == protocol: - if dev.configured != 0: - return dev - return None - -def read_interrupt(dev: usb_device | t.CPtr, buf: t.CVoid | t.CPtr) -> t.CInt: - return 0 diff --git a/Test/Kernel/drivers/video/ui/sheet.vp b/Test/Kernel/drivers/video/ui/sheet.vp deleted file mode 100644 index 7b70613c..00000000 --- a/Test/Kernel/drivers/video/ui/sheet.vp +++ /dev/null @@ -1,85 +0,0 @@ -from stdint import * -import drivers.video.vesafb.gfx as gfx -import t, c - -MAX_SHEETS: t.CDefine = 64 -MAX_UI_COMPONENTS: t.CDefine = 256 - -_next_sheet_id: t.CInt = 0 -_next_component_id: t.CInt = 0 - -@t.Object -class Sheet: - id: t.CInt - x: t.CInt - y: t.CInt - w: t.CInt - h: t.CInt - visible: t.CInt - _surf_obj: gfx.Surface - _renderer_obj: gfx.Renderer - surf: gfx.Surface | t.CPtr - renderer: gfx.Renderer | t.CPtr - parent: 'Sheet | t.CPtr' - bg_color: t.CUInt32T - - def __init__(self, fb: UINT32PTR, zb: float | t.CPtr, x: t.CInt, y: t.CInt, w: t.CInt, h: t.CInt, parent: 'Sheet | t.CPtr' = None): - global _next_sheet_id - self.id = _next_sheet_id - _next_sheet_id += 1 - self.x = x - self.y = y - self.w = w - self.h = h - self.visible = 1 - self._surf_obj = gfx.Surface(fb, zb, w, h) - self.surf = c.Addr(self._surf_obj) - self._renderer_obj = gfx.Renderer(self.surf) - self.renderer = c.Addr(self._renderer_obj) - self.parent = parent - self.bg_color = gfx.COLOR_RGB(20, 20, 30) - - def MoveTo(self, nx: t.CInt, ny: t.CInt): - self.x = nx - self.y = ny - - def Resize(self, nw: t.CInt, nh: t.CInt): - self.w = nw - self.h = nh - - def Show(self): - self.visible = 1 - - def Hide(self): - self.visible = 0 - - def Clear(self): - r: gfx.Renderer = c.Deref(self.renderer) - r.Clear(self.bg_color) - - def Fill(self, color: t.CUInt32T): - r: gfx.Renderer = c.Deref(self.renderer) - r.Clear(color) - - def DrawRect(self, rx: t.CInt, ry: t.CInt, rw: t.CInt, rh: t.CInt, color: t.CUInt32T): - r: gfx.Renderer = c.Deref(self.renderer) - r.DrawLine2D(rx, ry, rx + rw - 1, ry, color) - r.DrawLine2D(rx + rw - 1, ry, rx + rw - 1, ry + rh - 1, color) - r.DrawLine2D(rx + rw - 1, ry + rh - 1, rx, ry + rh - 1, color) - r.DrawLine2D(rx, ry + rh - 1, rx, ry, color) - - def DrawFilledRect(self, rx: t.CInt, ry: t.CInt, rw: t.CInt, rh: t.CInt, color: t.CUInt32T): - surf: gfx.Surface = c.Deref(self.surf) - fb: UINT32PTR = surf.fb - w: t.CInt = surf.w - h: t.CInt = surf.h - for py in range(ry, ry + rh): - if py < 0 or py >= h: continue - for px in range(rx, rx + rw): - if px < 0 or px >= w: continue - fb[py * w + px] = color - - def Contains(self, px: t.CInt, py: t.CInt) -> t.CInt: - if px >= self.x and px < self.x + self.w and py >= self.y and py < self.y + self.h: - return 1 - return 0 diff --git a/Test/Kernel/drivers/video/ui/ui.vp b/Test/Kernel/drivers/video/ui/ui.vp deleted file mode 100644 index d3ed8ef0..00000000 --- a/Test/Kernel/drivers/video/ui/ui.vp +++ /dev/null @@ -1,152 +0,0 @@ -from stdint import * -import drivers.video.vesafb.gfx as gfx -import drivers.video.ui.sheet as sheet -import string -import t, c - -UI_LABEL: t.CDefine = 0 -UI_BUTTON: t.CDefine = 1 -UI_PANEL: t.CDefine = 2 -UI_PROGRESS: t.CDefine = 3 - -@t.Object -class UIComponent: - id: t.CInt - ctype: t.CInt - x: t.CInt - y: t.CInt - w: t.CInt - h: t.CInt - visible: t.CInt - sheet: sheet.Sheet | t.CPtr - fg_color: t.CUInt32T - bg_color: t.CUInt32T - text: t.CArray[t.CChar, 128] - text_len: t.CInt - value: t.CInt - - def __init__(self, ctype: t.CInt, sh: sheet.Sheet | t.CPtr, x: t.CInt, y: t.CInt, w: t.CInt, h: t.CInt): - global _next_component_id - self.id = _next_component_id - _next_component_id += 1 - self.ctype = ctype - self.x = x - self.y = y - self.w = w - self.h = h - self.visible = 1 - self.sheet = sh - self.fg_color = gfx.COLOR_RGB(255, 255, 255) - self.bg_color = gfx.COLOR_RGB(40, 40, 60) - string.memset(c.Addr(self.text), 0, 128) - self.text_len = 0 - self.value = 0 - - def SetText(self, s: str): - i: t.CInt = 0 - for ch in s: - if i >= 127: break - self.text[i] = ch - i += 1 - self.text[i] = 0 - self.text_len = i - - def SetValue(self, v: t.CInt): - self.value = v - - def Render(self): - if self.visible == 0: return - sh: sheet.Sheet = c.Deref(self.sheet) - match self.ctype: - case 0: - self._RenderLabel(sh) - case 1: - self._RenderButton(sh) - case 2: - self._RenderPanel(sh) - case 3: - self._RenderProgress(sh) - - def _RenderLabel(self, sh: sheet.Sheet): - sh.DrawFilledRect(self.x, self.y, self.w, self.h, 0) - - def _RenderButton(self, sh: sheet.Sheet): - sh.DrawFilledRect(self.x, self.y, self.w, self.h, self.bg_color) - sh.DrawRect(self.x, self.y, self.w, self.h, self.fg_color) - - def _RenderPanel(self, sh: sheet.Sheet): - sh.DrawFilledRect(self.x, self.y, self.w, self.h, self.bg_color) - sh.DrawRect(self.x, self.y, self.w, self.h, gfx.COLOR_RGB(80, 80, 120)) - - def _RenderProgress(self, sh: sheet.Sheet): - sh.DrawFilledRect(self.x, self.y, self.w, self.h, gfx.COLOR_RGB(30, 30, 40)) - fill_w: t.CInt = self.w * self.value / 100 - if fill_w > 0: - sh.DrawFilledRect(self.x, self.y, fill_w, self.h, gfx.COLOR_RGB(0, 180, 255)) - sh.DrawRect(self.x, self.y, self.w, self.h, gfx.COLOR_RGB(80, 80, 100)) - - def Contains(self, px: t.CInt, py: t.CInt) -> t.CInt: - if px >= self.x and px < self.x + self.w and py >= self.y and py < self.y + self.h: - return 1 - return 0 - - -@t.Object -class UIManager: - sheets: t.CArray[sheet.Sheet | t.CPtr, 64] - sheet_count: t.CInt - components: t.CArray[UIComponent | t.CPtr, 256] - component_count: t.CInt - screen_w: t.CInt - screen_h: t.CInt - - def __init__(self, w: t.CInt, h: t.CInt): - self.sheet_count = 0 - self.component_count = 0 - self.screen_w = w - self.screen_h = h - i: t.CInt - for i in range(64): - self.sheets[i] = None - for i in range(256): - self.components[i] = None - - def AddSheet(self, sh: sheet.Sheet | t.CPtr) -> t.CInt: - if self.sheet_count >= 64: return -1 - self.sheets[self.sheet_count] = sh - self.sheet_count += 1 - return 0 - - def AddComponent(self, comp: UIComponent | t.CPtr) -> t.CInt: - if self.component_count >= 256: return -1 - self.components[self.component_count] = comp - self.component_count += 1 - return 0 - - def FindComponent(self, cid: t.CInt) -> UIComponent | t.CPtr: - i: t.CInt - for i in range(self.component_count): - p: UIComponent | t.CPtr = self.components[i] - if p is not None: - comp: UIComponent = c.Deref(p) - if comp.id == cid: return p - return None - - def RenderAll(self): - i: t.CInt - for i in range(self.component_count): - p: UIComponent | t.CPtr = self.components[i] - if p is not None: - comp: UIComponent = c.Deref(p) - comp.Render() - - def HitTest(self, px: t.CInt, py: t.CInt) -> UIComponent | t.CPtr: - i: t.CInt = self.component_count - 1 - while i >= 0: - p: UIComponent | t.CPtr = self.components[i] - if p is not None: - comp: UIComponent = c.Deref(p) - if comp.visible == 1 and comp.Contains(px, py) == 1: - return p - i -= 1 - return None diff --git a/Test/Kernel/drivers/video/vesafb/gfx.vp b/Test/Kernel/drivers/video/vesafb/gfx.vp deleted file mode 100644 index 5292d3f0..00000000 --- a/Test/Kernel/drivers/video/vesafb/gfx.vp +++ /dev/null @@ -1,305 +0,0 @@ -from stdint import * -import vipermath -import string -import t, c - - -PI: t.CDefine = float(3.14159265358979323846) - -SPHERE_SLICES: t.CDefine = (24 * 1) -SPHERE_STACKS: t.CDefine = (16 * 1) -SIN_WAVE_GRID: t.CDefine = (40 * 1) - -def COLOR_RGB(r: int, g: int, b: int) -> t.CInline | t.CInt: - return (255 << 24) | (r << 16) | (g << 8) | (b) - -@t.Object -class Vec3: - x: float - y: float - z: float - def __init__(self, x: float, y: float, z: float): - self.x = x - self.y = y - self.z = z - def Sub(self, b: 'Vec3') -> 'Vec3': - return Vec3(self.x - b.x, self.y - b.y, self.z - b.z) - def Cross(self, b: 'Vec3') -> 'Vec3': - return Vec3(self.y * b.z - self.z * b.y, self.z * b.x - self.x * b.z, self.x * b.y - self.y * b.x) - def Dot(self, b: 'Vec3') -> float: - return self.x * b.x + self.y * b.y + self.z * b.z - def Norm(self) -> 'Vec3': - l = vipermath.sqrtf(self.Dot(self)) - return Vec3(self.x / l, self.y / l, self.z / l) - -class Mat4: - m: t.CArray[t.CArray[float, 4], 4] - -def Mat4_Identity() -> Mat4: - m: Mat4 = Mat4() - string.memset(c.Addr(m), 0, Mat4.__sizeof__()) - m.m[0][0] = 1; m.m[1][1] = 1; m.m[2][2] = 1; m.m[3][3] = 1 - return m - -def Mat4_Mul(a: Mat4, b: Mat4) -> Mat4: - res: Mat4 = Mat4() - string.memset(c.Addr(res), 0, Mat4.__sizeof__()) - for i in range(4): - for j in range(4): - for k in range(4): - res.m[i][j] += a.m[i][k] * b.m[k][j] - return res - -def Mat4_MulVec(m: Mat4, v: Vec3) -> Vec3: - x: float = m.m[0][0] * v.x + m.m[0][1] * v.y + m.m[0][2] * v.z + m.m[0][3] - y: float = m.m[1][0] * v.x + m.m[1][1] * v.y + m.m[1][2] * v.z + m.m[1][3] - z: float = m.m[2][0] * v.x + m.m[2][1] * v.y + m.m[2][2] * v.z + m.m[2][3] - w: float = m.m[3][0] * v.x + m.m[3][1] * v.y + m.m[3][2] * v.z + m.m[3][3] - if w != 0: - x /= w; y /= w; z /= w - return Vec3(x, y, z) - -def Mat4_Perspective(fov: float, aspect: float, zn: float, zf: float) -> Mat4: - m: Mat4 = Mat4() - string.memset(c.Addr(m), 0, Mat4.__sizeof__()) - f: float = float(1.0) / vipermath.tanf(fov / float(2.0)) - m.m[0][0] = f / aspect; m.m[1][1] = f - m.m[2][2] = zf / (zn - zf); m.m[2][3] = (zf * zn) / (zn - zf); m.m[3][2] = -1 - return m - -def Mat4_LookAt(eye: Vec3, target: Vec3, up: Vec3) -> Mat4: - zaxis: Vec3 = eye.Sub(target).Norm() - xaxis: Vec3 = up.Cross(zaxis).Norm() - yaxis: Vec3 = zaxis.Cross(xaxis) - m: Mat4 = Mat4_Identity() - m.m[0][0]=xaxis.x; m.m[0][1]=xaxis.y; m.m[0][2]=xaxis.z; m.m[0][3]= -xaxis.Dot(eye) - m.m[1][0]=yaxis.x; m.m[1][1]=yaxis.y; m.m[1][2]=yaxis.z; m.m[1][3]= -yaxis.Dot(eye) - m.m[2][0]=zaxis.x; m.m[2][1]=zaxis.y; m.m[2][2]=zaxis.z; m.m[2][3]= -zaxis.Dot(eye) - m.m[3][3] = 1 - return m - -def Mat4_Translate(x: float, y: float, z: float) -> Mat4: - m: Mat4 = Mat4_Identity() - m.m[0][3] = x; m.m[1][3] = y; m.m[2][3] = z - return m - -def Mat4_RotateY(a: float) -> Mat4: - m: Mat4 = Mat4_Identity(); - m.m[0][0] = vipermath.cosf(a); m.m[0][2] = vipermath.sinf(a) - m.m[2][0] = -vipermath.sinf(a); m.m[2][2] = vipermath.cosf(a) - return m - - -@t.Object -class Surface: - fb: UINT32PTR - zb: float | t.CPtr - w: int - h: int - def __init__(self, fb: UINT32PTR, zb: float | t.CPtr, w: int, h: int): - self.fb = fb - self.zb = zb - self.w = w - self.h = h - -@t.Object -class Renderer: - _fb: UINT32PTR - _zb: float | t.CPtr - _w: int - _h: int - - def __init__(self, fb: UINT32PTR, zb: float | t.CPtr, w: int, h: int): - self._fb = fb - self._zb = zb - self._w = w - self._h = h - - def Clear(self, color: t.CUInt32T): - fb: UINT32PTR = self._fb - zb: float | t.CPtr = self._zb - size: int = self._w * self._h - for i in range(size): - fb[i] = color - zb[i] = float(1.0) - - def DrawLine2D(self, x0: int, y0: int, x1: int, y1: int, col: t.CUInt32T): - fb: UINT32PTR = 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 - err: int = dx - dy - while True: - if x0 >= 0 and x0 < w and y0 >= 0 and y0 < h: fb[y0 * w + x0] = col - if x0 == x1 and y0 == y1: break - e2: int = 2 * err - if e2 > -dy: err -= dy; x0 += sx - if e2 < dx: err += dx; y0 += sy - - def DrawTriangle(self, v0: Vec3, v1: Vec3, v2: Vec3, col: t.CUInt32T): - if v0.z < float(0.0) or v1.z < float(0.0) or v2.z < float(0.0): return - if (v0.x > float(10.0) or v0.x < float(-10.0) or v0.y > float(10.0) or v0.y < float(-10.0) or - 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 - zb: float | t.CPtr = self._zb - w: int = self._w - h: int = self._h - - sx0: float = (v0.x + float(1.0)) * float(0.5) * w; sy0: float = (float(1.0) - v0.y) * float(0.5) * h - sx1: float = (v1.x + float(1.0)) * float(0.5) * w; sy1: float = (float(1.0) - v1.y) * float(0.5) * h - sx2: float = (v2.x + float(1.0)) * float(0.5) * w; sy2: float = (float(1.0) - v2.y) * float(0.5) * h - - minX: int = max(0, int(vipermath.floorf(min(min(sx0, sx1), sx2)))) - maxX: int = min(w - 1, int(vipermath.ceilf(max(max(sx0, sx1), sx2)))) - minY: int = max(0, int(vipermath.floorf(min(min(sy0, sy1), sy2)))) - maxY: int = min(h - 1, int(vipermath.ceilf(max(max(sy0, sy1), sy2)))) - - dx12: float = sx1 - sx2; dy12: float = sy1 - sy2 - dx02: float = sx0 - sx2; dy02: float = sy0 - sy2 - denom: float = dx12 * dy02 - dy12 * dx02 - if denom < float(0.001) and denom > float(-0.001): return - invDenom: float = float(1.0) / denom - - row_dxP_start: float = float(minX) - sx2 - for y in range(minY, maxY + 1): - dyP: float = float(y) - sy2 - dxP: float = row_dxP_start - row_base: int = y * w - for x in range(minX, maxX + 1): - w0: float = (dx12 * dyP - dy12 * dxP) * invDenom - w1: float = (dxP * dy02 - dyP * dx02) * invDenom - w2: float = float(1.0) - w0 - w1 - if w0 >= 0 and w1 >= 0 and w2 >= 0: - z: float = w0 * v0.z + w1 * v1.z + w2 * v2.z - idx: int = row_base + x - if z < zb[idx]: - zb[idx] = z - fb[idx] = col - dxP += float(1.0) - - def DrawGlowDot(self, x: float, y: float, radius: float, core_col: t.CUInt32T, intensity: float): - fb: UINT32PTR = 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): - py: int = iy + dy - if py < 0 or py >= h: continue - for dx in range(-r, r + 1): - px: int = ix + dx - if px < 0 or px >= w: continue - dist: float = vipermath.sqrtf(float(dx*dx + dy*dy)) - if dist < radius: - self.BlendPixel(px, py, core_col, intensity) - elif dist < float(r): - fade: float = 1.0 - (dist - radius) / 4.0 - self.BlendPixel(px, py, core_col, intensity * fade * 0.5) - - def BlendPixel(self, x: int, y: int, col: t.CUInt32T, alpha: float): - if alpha <= 0.0: return - fb: UINT32PTR = 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 - bg: t.CUInt32T = fb[idx] - bg_b: int = bg & 0xFF; bg_g: int = (bg >> 8) & 0xFF; bg_r: int = (bg >> 16) & 0xFF - f_b: int = col & 0xFF; f_g: int = (col >> 8) & 0xFF; f_r: int = (col >> 16) & 0xFF - - a: int = int(alpha * 255.0) - inv_a: int = 255 - a - nr: int = (f_r * a + bg_r * inv_a) >> 8 - ng: int = (f_g * a + bg_g * inv_a) >> 8 - nb: int = (f_b * a + bg_b * inv_a) >> 8 - - fb[idx] = COLOR_RGB(255 if (nr > 255) else nr, - 255 if (ng > 255) else ng, - 255 if (nb > 255) else nb) - - -@t.Object -class Scene3D: - renderer: Renderer - - def __init__(self, fb: UINT32PTR, zb: float | t.CPtr, w: int, h: int): - self.renderer = Renderer(fb, zb, w, h) - - def Render(self, time: float): - rw: int = self.renderer._w - rh: int = self.renderer._h - self.renderer.Clear(COLOR_RGB(15, 15, 25)) - - yaw: float = float(45.0) * PI / float(180.0); pitch: float = float(45.0) * PI / float(180.0); radius: float = float(10.0) - eye: Vec3 = Vec3(radius*vipermath.cosf(pitch)*vipermath.cosf(yaw), radius*vipermath.sinf(pitch), radius*vipermath.cosf(pitch)*vipermath.sinf(yaw)) - target: Vec3 = Vec3(0, 0, 0); up: Vec3 = Vec3(0, 1, 0) - view: Mat4 = Mat4_LookAt(eye, target, up) - proj: Mat4 = Mat4_Perspective(PI / float(3.0), float(rw)/float(rh), float(0.1), float(100.0)) - vp: Mat4 = Mat4_Mul(proj, view) - - cubeX: float = float(-3.5) - cubeMVP: Mat4 = Mat4_Mul(vp, Mat4_Translate(cubeX, 0, 0)) - self._DrawCube(cubeMVP, COLOR_RGB(180, 180, 180)) - - colors: t.CArray[t.CUInt32T, 4] = [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(vipermath.cosf(a) * r + cubeX, 0, vipermath.sinf(a) * r) - sphereMVP: Mat4 = Mat4_Mul(vp, Mat4_Translate(pos.x, pos.y, pos.z)) - self._DrawSphere(sphereMVP, Vec3(0,0,0), float(0.5), colors[i]) - - self._Draw3DSinWave(vp, Vec3(float(3.5), 0, 0), time) - - self.renderer.DrawLine2D(50, rh - 150, rw - 50, rh - 150, COLOR_RGB(80, 80, 80)) - self.renderer.DrawLine2D(50, rh - 50, 50, rh - 250, COLOR_RGB(80, 80, 80)) - wave_shift: float = time * float(2.0) - prev_x: int = 50; prev_y: int = rh - 150 - int(vipermath.sinf(0 - wave_shift) * float(100.0)) - for i in range(1, rw - 100): - tr: float = float(i) / float(rw-100) * float(4.0) * PI - cx: int = 50 + i; cy: int = rh - 150 - int(vipermath.sinf(tr - wave_shift) * float(100.0)) - self.renderer.DrawLine2D(prev_x, prev_y, cx, cy, COLOR_RGB(0, 255, 100)) - prev_x = cx; prev_y = cy - - def _DrawCube(self, mvp: Mat4, col: t.CUInt32T): - v: t.CArray[Vec3, 8] = [ - 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] = [ - [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] - ] - for i in range(12): self.renderer.DrawTriangle(v[faces[i][0]], v[faces[i][1]], v[faces[i][2]], col) - - def _DrawSphere(self, mvp: Mat4, center: Vec3, radius: float, col: t.CUInt32T): - step_pi: float = PI / SPHERE_STACKS; step_2pi: float = float(2.0) * PI / SPHERE_SLICES - for i in range(SPHERE_STACKS): - 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[0] = Vec3(center.x+radius*vipermath.sinf(theta1)*vipermath.cosf(phi1), center.y+radius*vipermath.cosf(theta1), center.z+radius*vipermath.sinf(theta1)*vipermath.sinf(phi1)) - v[1] = Vec3(center.x+radius*vipermath.sinf(theta1)*vipermath.cosf(phi2), center.y+radius*vipermath.cosf(theta1), center.z+radius*vipermath.sinf(theta1)*vipermath.sinf(phi2)) - v[2] = Vec3(center.x+radius*vipermath.sinf(theta2)*vipermath.cosf(phi1), center.y+radius*vipermath.cosf(theta2), center.z+radius*vipermath.sinf(theta2)*vipermath.sinf(phi1)) - v[3] = Vec3(center.x+radius*vipermath.sinf(theta2)*vipermath.cosf(phi2), center.y+radius*vipermath.cosf(theta2), center.z+radius*vipermath.sinf(theta2)*vipermath.sinf(phi2)) - for k in range(4): v[k] = Mat4_MulVec(mvp, v[k]) - self.renderer.DrawTriangle(v[0], v[1], v[2], col) - self.renderer.DrawTriangle(v[1], v[3], v[2], col) - - def _Draw3DSinWave(self, vp: Mat4, pos: Vec3, time: float): - _range: float = float(2.0) * PI; step: float = _range / SIN_WAVE_GRID; scale: float = float(0.5) - mvp: Mat4 = Mat4_Mul(vp, Mat4_Mul(Mat4_Translate(pos.x, pos.y, pos.z), Mat4_RotateY(time * float(1.0)))) - for i in range(SIN_WAVE_GRID): - for j in range(SIN_WAVE_GRID): - x0: float = -PI + i * step; z0 = -PI + j * step; x1: float = x0 + step; z1 = z0 + step - y00: float = vipermath.sinf(x0) * vipermath.cosf(z0) * scale; y10: float = vipermath.sinf(x1) * vipermath.cosf(z0) * scale - y01: float = vipermath.sinf(x0) * vipermath.cosf(z1) * scale; y11: float = vipermath.sinf(x1) * vipermath.cosf(z1) * scale - - t1: float = (y00 / scale + float(1.0)) * float(0.5); r1: int = int(50 + 205 * t1); g1: int = int(80 + 120 * vipermath.sinf(t1 * PI)); b1: int = int(255 - 205 * t1) - col1: t.CUInt32T = COLOR_RGB(255 if (r1 > 255) else (0 if (r1 < 0) else r1), 255 if (g1 > 255) else (0 if (g1 < 0) else g1), 255 if (b1 > 255) else (0 if (b1 < 0) else b1)) - t2: float = (y11 / scale + float(1.0)) * float(0.5); r2: int = int(50 + 205 * t2); g2: int = int(80 + 120 * vipermath.sinf(t2 * PI)); b2: int = int(255 - 205 * t2) - col2: t.CUInt32T = COLOR_RGB(255 if (r2 > 255) else (0 if (r2 < 0) else r2), 255 if (g2 > 255) else (0 if (g2 < 0) else g2), 255 if (b2 > 255) else (0 if (b2 < 0) else b2)) - - v00: Vec3 = Mat4_MulVec(mvp, Vec3(x0, y00, z0)); v10: Vec3 = Mat4_MulVec(mvp, Vec3(x1, y10, z0)) - v01: Vec3 = Mat4_MulVec(mvp, Vec3(x0, y01, z1)); v11: Vec3 = Mat4_MulVec(mvp, Vec3(x1, y11, z1)) - self.renderer.DrawTriangle(v00, v10, v11, col1); self.renderer.DrawTriangle(v00, v11, v01, col2) diff --git a/Test/Kernel/drivers/video/vesafb/vga.vp b/Test/Kernel/drivers/video/vesafb/vga.vp deleted file mode 100644 index ef6206ce..00000000 --- a/Test/Kernel/drivers/video/vesafb/vga.vp +++ /dev/null @@ -1,504 +0,0 @@ -import string # std: standard -#import math # std: standard -import t, c - - -# 颜色格式枚举 -class __ColorFormat(t.CEnum): - ColorFormat_BGRA: t.State # BGRA格式(蓝色、绿色、红色、Alpha) - ColorFormat_RGBA: t.State # RGBA格式(红色、绿色、蓝色、Alpha) - ColorFormat_BGR: t.State # BGR格式(蓝色、绿色、红色) - ColorFormat_RGB: t.State # RGB格式(红色、绿色、蓝色) - -# 常量定义 - 提升代码可读性和可维护性 -VGA_WIDTH: t.CDefine = 80 -VGA_HEIGHT: t.CDefine = 25 -FONT_WIDTH: t.CDefine = 8 -FONT_HEIGHT: t.CDefine = 16 -DEFAULT_CHAR: t.CDefine = 0 # 非ASCII字符的默认替换字符 -SERIAL_PORT: t.CDefine = 0x3F8 # 串口调试端口地址 - -# 8x16字符点阵字库 (每个字符16字节,共256个字符) -font: t.CArray[t.CArray[t.CUInt8T, 16], 256] = [ - # 字符编号 0x00 - 0x0F - {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x55, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x00 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x01 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x56, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x02 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x56, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x03 - {0x00, 0x00, 0x70, 0x55, 0x55, 0x57, 0x71, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x04 - {0x00, 0x00, 0x70, 0x57, 0x54, 0x57, 0x71, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x05 - {0x00, 0x00, 0x70, 0x57, 0x54, 0x57, 0x75, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x06 - {0x00, 0x00, 0x70, 0x57, 0x51, 0x52, 0x72, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x07 - {0x00, 0x00, 0x70, 0x57, 0x55, 0x57, 0x75, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x08 - {0x00, 0x00, 0x70, 0x57, 0x55, 0x57, 0x71, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x09 - {0x00, 0x00, 0x70, 0x56, 0x51, 0x57, 0x75, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x0A - {0x00, 0x00, 0x70, 0x54, 0x54, 0x57, 0x75, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x0B - {0x00, 0x00, 0x70, 0x50, 0x50, 0x57, 0x74, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x0C - {0x00, 0x00, 0x70, 0x51, 0x51, 0x57, 0x75, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x0D - {0x00, 0x00, 0x70, 0x57, 0x55, 0x57, 0x74, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x0E - {0x00, 0x00, 0x70, 0x53, 0x54, 0x56, 0x74, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x0F - - # 字符编号 0x10 - 0x1F - {0x00, 0x00, 0x10, 0x37, 0x15, 0x15, 0x15, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x10 - {0x00, 0x00, 0x10, 0x32, 0x16, 0x12, 0x12, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x11 - {0x00, 0x00, 0x20, 0x6E, 0x22, 0x2E, 0x28, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x12 - {0x00, 0x00, 0x10, 0x37, 0x11, 0x13, 0x11, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x13 - {0x00, 0x00, 0x10, 0x35, 0x15, 0x17, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x14 - {0x00, 0x00, 0x10, 0x37, 0x14, 0x17, 0x11, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x15 - {0x00, 0x00, 0x10, 0x37, 0x14, 0x17, 0x15, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x16 - {0x00, 0x00, 0x10, 0x37, 0x11, 0x12, 0x12, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x17 - {0x00, 0x00, 0x10, 0x37, 0x15, 0x17, 0x15, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x18 - {0x00, 0x00, 0x10, 0x37, 0x15, 0x17, 0x11, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x19 - {0x00, 0x00, 0x10, 0x36, 0x11, 0x17, 0x15, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x1A - {0x00, 0x00, 0x10, 0x34, 0x14, 0x17, 0x15, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x1B - {0x00, 0x00, 0x10, 0x30, 0x10, 0x17, 0x14, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x1C - {0x00, 0x00, 0x10, 0x31, 0x11, 0x17, 0x15, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x1D - {0x00, 0x00, 0x10, 0x37, 0x15, 0x17, 0x14, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x1E - {0x00, 0x00, 0x10, 0x33, 0x14, 0x16, 0x14, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x1F - - # 字符编号 0x20 - 0x2F - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x20 - {0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00}, # 0x21 - {0x6C, 0x6C, 0x6C, 0x6C, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x22 - {0x36, 0x36, 0x36, 0x7F, 0x7F, 0x36, 0x36, 0x36, 0x7F, 0x7F, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00}, # 0x23 - {0x0C, 0x0C, 0x3E, 0x7F, 0x68, 0x68, 0x3E, 0x0B, 0x0B, 0x7F, 0x3E, 0x18, 0x18, 0x00, 0x00, 0x00}, # 0x24 - {0x60, 0x60, 0x66, 0x06, 0x0C, 0x0C, 0x18, 0x30, 0x30, 0x60, 0x66, 0x06, 0x06, 0x00, 0x00, 0x00}, # 0x25 - {0x38, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x38, 0x6C, 0x6D, 0x66, 0x66, 0x6F, 0x3B, 0x00, 0x00, 0x00}, # 0x26 - {0x18, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x27 - {0x1C, 0x3C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3C, 0x1C, 0x00, 0x00}, # 0x28 - {0x38, 0x3C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x3C, 0x38, 0x00, 0x00}, # 0x29 - {0x00, 0x00, 0x18, 0x18, 0x7E, 0x3C, 0x3C, 0x3C, 0x7E, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x2A - {0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x2B - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x30, 0x00}, # 0x2C - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x2D - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00}, # 0x2E - {0x00, 0x00, 0x06, 0x06, 0x0C, 0x0C, 0x18, 0x30, 0x30, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x2F - - # 字符编号 0x30 - 0x3F - {0x3C, 0x7E, 0x66, 0x66, 0x6E, 0x6E, 0x7E, 0x76, 0x76, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0x30 - {0x18, 0x38, 0x78, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0x31 - {0x3C, 0x7E, 0x66, 0x06, 0x06, 0x0E, 0x1C, 0x38, 0x70, 0x60, 0x60, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0x32 - {0x3C, 0x7E, 0x66, 0x06, 0x06, 0x1C, 0x1C, 0x06, 0x06, 0x06, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0x33 - {0x0C, 0x0C, 0x1C, 0x1C, 0x3C, 0x2C, 0x6C, 0x7E, 0x7E, 0x0C, 0x0C, 0x0C, 0x0C, 0x00, 0x00, 0x00}, # 0x34 - {0x7E, 0x7E, 0x60, 0x60, 0x7C, 0x7E, 0x06, 0x06, 0x06, 0x06, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0x35 - {0x3C, 0x7E, 0x66, 0x60, 0x60, 0x7C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0x36 - {0x7E, 0x7E, 0x06, 0x06, 0x0C, 0x0C, 0x18, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00}, # 0x37 - {0x3C, 0x7E, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0x38 - {0x3C, 0x7E, 0x66, 0x66, 0x66, 0x7E, 0x3E, 0x06, 0x06, 0x06, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0x39 - {0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00}, # 0x3A - {0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x30, 0x00}, # 0x3B - {0x00, 0x02, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x02, 0x00, 0x00, 0x00}, # 0x3C - {0x00, 0x00, 0x00, 0x00, 0x7E, 0x7E, 0x00, 0x00, 0x7E, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x3D - {0x00, 0x40, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00, 0x00, 0x00}, # 0x3E - {0x3C, 0x7E, 0x66, 0x06, 0x0C, 0x0C, 0x18, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00}, # 0x3F - - # 字符编号 0x40 - 0x4F - {0x3C, 0x7E, 0x66, 0x66, 0x6E, 0x6A, 0x6A, 0x6A, 0x6E, 0x60, 0x60, 0x7C, 0x3C, 0x00, 0x00, 0x00}, # 0x40 - {0x3C, 0x7E, 0x66, 0x66, 0x66, 0x7E, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0x41 - {0x7C, 0x7E, 0x66, 0x66, 0x66, 0x7C, 0x7C, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x7C, 0x00, 0x00, 0x00}, # 0x42 - {0x3C, 0x7E, 0x66, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0x43 - {0x78, 0x7C, 0x6C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x6C, 0x7C, 0x78, 0x00, 0x00, 0x00}, # 0x44 - {0x7E, 0x7E, 0x60, 0x60, 0x60, 0x7C, 0x7C, 0x60, 0x60, 0x60, 0x60, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0x45 - {0x7E, 0x7E, 0x60, 0x60, 0x60, 0x7C, 0x7C, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00}, # 0x46 - {0x3C, 0x7E, 0x66, 0x60, 0x60, 0x60, 0x6E, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0x47 - {0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0x48 - {0x7E, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0x49 - {0x3E, 0x3E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x6C, 0x7C, 0x38, 0x00, 0x00, 0x00}, # 0x4A - {0x66, 0x66, 0x66, 0x6C, 0x6C, 0x78, 0x78, 0x78, 0x6C, 0x6C, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0x4B - {0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0x4C - {0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00}, # 0x4D - {0x66, 0x66, 0x66, 0x66, 0x76, 0x76, 0x7E, 0x6E, 0x6E, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0x4E - {0x3C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0x4F - - # 字符编号 0x50 - 0x5F - {0x7C, 0x7E, 0x66, 0x66, 0x66, 0x7E, 0x7C, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00}, # 0x50 - {0x3C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x6A, 0x6A, 0x6C, 0x7E, 0x36, 0x00, 0x00, 0x00}, # 0x51 - {0x7C, 0x7E, 0x66, 0x66, 0x66, 0x7E, 0x7C, 0x6C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0x52 - {0x3C, 0x7E, 0x66, 0x60, 0x60, 0x78, 0x3C, 0x0E, 0x06, 0x06, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0x53 - {0x7E, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00}, # 0x54 - {0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0x55 - {0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x00, 0x00}, # 0x56 - {0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x6B, 0x6B, 0x7F, 0x77, 0x77, 0x22, 0x00, 0x00, 0x00}, # 0x57 - {0x66, 0x66, 0x66, 0x66, 0x3C, 0x3C, 0x18, 0x3C, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0x58 - {0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00}, # 0x59 - {0x7E, 0x7E, 0x06, 0x06, 0x0C, 0x0C, 0x18, 0x30, 0x30, 0x60, 0x60, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0x5A - {0x78, 0x78, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x78, 0x78, 0x00, 0x00}, # 0x5B - {0xC0, 0xC0, 0x60, 0x60, 0x30, 0x30, 0x18, 0x0C, 0x0C, 0x06, 0x06, 0x03, 0x03, 0x00, 0x00, 0x00}, # 0x5C - {0x1E, 0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x1E, 0x00, 0x00}, # 0x5D - {0x3C, 0x7E, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x5E - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00}, # 0x5F - - # 字符编号 0x60 - 0x6F - {0x30, 0x38, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x60 - {0x00, 0x00, 0x00, 0x00, 0x3C, 0x3E, 0x06, 0x3E, 0x7E, 0x66, 0x66, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0x61 - {0x60, 0x60, 0x60, 0x60, 0x7C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x7C, 0x00, 0x00, 0x00}, # 0x62 - {0x00, 0x00, 0x00, 0x00, 0x3C, 0x7E, 0x66, 0x60, 0x60, 0x60, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0x63 - {0x06, 0x06, 0x06, 0x06, 0x3E, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0x64 - {0x00, 0x00, 0x00, 0x00, 0x3C, 0x7E, 0x66, 0x7E, 0x7E, 0x60, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0x65 - {0x1C, 0x3E, 0x30, 0x30, 0x30, 0x7C, 0x7C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00}, # 0x66 - {0x00, 0x00, 0x00, 0x00, 0x3E, 0x7E, 0x66, 0x66, 0x66, 0x7E, 0x3E, 0x06, 0x06, 0x3E, 0x3C, 0x00}, # 0x67 - {0x60, 0x60, 0x60, 0x60, 0x7C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0x68 - {0x18, 0x18, 0x00, 0x00, 0x38, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0x69 - {0x0C, 0x0C, 0x00, 0x00, 0x3C, 0x3C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x7C, 0x78, 0x00}, # 0x6A - {0x60, 0x60, 0x60, 0x60, 0x66, 0x66, 0x6C, 0x78, 0x78, 0x6C, 0x6C, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0x6B - {0x38, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0x6C - {0x00, 0x00, 0x00, 0x00, 0x36, 0x7F, 0x6B, 0x6B, 0x63, 0x63, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00}, # 0x6D - {0x00, 0x00, 0x00, 0x00, 0x7C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0x6E - {0x00, 0x00, 0x00, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0x6F - - # 字符编号 0x70 - 0x7F - {0x00, 0x00, 0x00, 0x00, 0x7C, 0x7E, 0x66, 0x66, 0x66, 0x7E, 0x7C, 0x60, 0x60, 0x60, 0x60, 0x00}, # 0x70 - {0x00, 0x00, 0x00, 0x00, 0x3E, 0x7E, 0x66, 0x66, 0x66, 0x7E, 0x3E, 0x06, 0x06, 0x07, 0x07, 0x00}, # 0x71 - {0x00, 0x00, 0x00, 0x00, 0x6C, 0x7E, 0x76, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00}, # 0x72 - {0x00, 0x00, 0x00, 0x00, 0x3C, 0x7E, 0x62, 0x70, 0x3C, 0x0E, 0x46, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0x73 - {0x30, 0x30, 0x30, 0x30, 0x7C, 0x7C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3C, 0x1C, 0x00, 0x00, 0x00}, # 0x74 - {0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0x75 - {0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x00, 0x00}, # 0x76 - {0x00, 0x00, 0x00, 0x00, 0x63, 0x63, 0x63, 0x63, 0x6B, 0x6B, 0x7F, 0x7F, 0x36, 0x00, 0x00, 0x00}, # 0x77 - {0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x3C, 0x3C, 0x18, 0x3C, 0x3C, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0x78 - {0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3E, 0x06, 0x06, 0x7E, 0x7C, 0x00}, # 0x79 - {0x00, 0x00, 0x00, 0x00, 0x7E, 0x7E, 0x0C, 0x0C, 0x18, 0x30, 0x30, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0x7A - {0x0E, 0x1E, 0x18, 0x18, 0x18, 0x18, 0x30, 0x30, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x0E, 0x00, 0x00}, # 0x7B - {0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00}, # 0x7C - {0x70, 0x78, 0x18, 0x18, 0x18, 0x18, 0x0C, 0x0C, 0x18, 0x18, 0x18, 0x18, 0x78, 0x70, 0x00, 0x00}, # 0x7D - {0x31, 0x79, 0x6B, 0x4F, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x7E - {0x00, 0x00, 0x70, 0x13, 0x24, 0x26, 0x24, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x7F - - # 字符编号 0x80 - 0x8F - {0x03, 0x03, 0x03, 0x03, 0x06, 0x06, 0x06, 0x06, 0x66, 0x7C, 0x3C, 0x1C, 0x0C, 0x00, 0x00, 0x00}, # 0x80 - {0x1C, 0x36, 0x00, 0x63, 0x63, 0x63, 0x63, 0x6B, 0x6B, 0x7F, 0x7F, 0x77, 0x22, 0x00, 0x00, 0x00}, # 0x81 - {0x1C, 0x36, 0x00, 0x00, 0x00, 0x63, 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00, 0x00, 0x00}, # 0x82 - {0xFE, 0x92, 0x92, 0x92, 0x92, 0x92, 0xF2, 0x82, 0x82, 0x82, 0x82, 0x82, 0xFE, 0x00, 0x00, 0x00}, # 0x83 - {0x66, 0x66, 0x99, 0x99, 0x81, 0x42, 0x42, 0x42, 0x81, 0x99, 0x99, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0x84 - {0x18, 0x3C, 0x66, 0x00, 0x42, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00}, # 0x85 - {0x18, 0x3C, 0x66, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3E, 0x06, 0x06, 0x7E, 0x7C, 0x00}, # 0x86 - {0x07, 0x01, 0x01, 0x01, 0x02, 0x02, 0x64, 0x94, 0x94, 0x90, 0x60, 0x90, 0x90, 0x90, 0x60, 0x00}, # 0x87 - {0x18, 0x28, 0x28, 0x48, 0x4F, 0x81, 0x81, 0x81, 0x4F, 0x48, 0x28, 0x28, 0x18, 0x00, 0x00, 0x00}, # 0x88 - {0x18, 0x14, 0x14, 0x12, 0xF2, 0x81, 0x81, 0x81, 0xF2, 0x12, 0x14, 0x14, 0x18, 0x00, 0x00, 0x00}, # 0x89 - {0x3C, 0x24, 0x24, 0x24, 0x24, 0x24, 0xE7, 0x81, 0x42, 0x42, 0x24, 0x24, 0x18, 0x00, 0x00, 0x00}, # 0x8A - {0x18, 0x24, 0x24, 0x42, 0x42, 0x81, 0xE7, 0x24, 0x24, 0x24, 0x24, 0x24, 0x3C, 0x00, 0x00, 0x00}, # 0x8B - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDB, 0xDB, 0xDB, 0x00, 0x00, 0x00}, # 0x8C - {0x45, 0x4B, 0x51, 0x61, 0x61, 0x61, 0x51, 0x49, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x8D - {0xC0, 0xC0, 0xCC, 0x0C, 0x18, 0x18, 0x30, 0x60, 0x60, 0xC0, 0xDB, 0x1B, 0x1B, 0x00, 0x00, 0x00}, # 0x8E - {0x00, 0x00, 0x00, 0x00, 0x3C, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x8F - - # 字符编号 0x90 - 0x9F - {0x0C, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x90 - {0x0C, 0x0C, 0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x91 - {0x00, 0x00, 0x0C, 0x0C, 0x18, 0x18, 0x30, 0x30, 0x30, 0x18, 0x18, 0x0C, 0x0C, 0x00, 0x00, 0x00}, # 0x92 - {0x00, 0x00, 0x30, 0x30, 0x18, 0x18, 0x0C, 0x0C, 0x0C, 0x18, 0x18, 0x30, 0x30, 0x00, 0x00, 0x00}, # 0x93 - {0x1B, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x94 - {0x36, 0x36, 0x36, 0x36, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x95 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x6C, 0x6C}, # 0x96 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x97 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x98 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0x99 - {0x77, 0xFF, 0xCC, 0xCC, 0xCC, 0xCC, 0xCF, 0xCC, 0xCC, 0xCC, 0xCC, 0xFF, 0x77, 0x00, 0x00, 0x00}, # 0x9A - {0x00, 0x00, 0x00, 0x00, 0x6E, 0xFF, 0xDB, 0xDB, 0xDF, 0xD8, 0xD8, 0xFF, 0x6E, 0x00, 0x00, 0x00}, # 0x9B - {0x18, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00}, # 0x9C - {0x18, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x18, 0x18, 0x7E, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00}, # 0x9D - {0x3C, 0x7C, 0x60, 0x66, 0x66, 0xF0, 0xF6, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0x9E - {0x3E, 0x7E, 0x66, 0x66, 0x66, 0xF6, 0xF6, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0x9F - - # 字符编号 0xA0 - 0xAF - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0xA0 - {0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00}, # 0xA1 - {0x08, 0x08, 0x3E, 0x7F, 0x6B, 0x68, 0x68, 0x68, 0x6B, 0x7F, 0x3E, 0x08, 0x08, 0x00, 0x00, 0x00}, # 0xA2 - {0x1C, 0x3E, 0x36, 0x30, 0x30, 0x7C, 0x7C, 0x30, 0x30, 0x30, 0x30, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0xA3 - {0x00, 0x00, 0x42, 0x66, 0x3C, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x3C, 0x66, 0x42, 0x00, 0x00, 0x00}, # 0xA4 - {0x66, 0x66, 0x3C, 0x3C, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00}, # 0xA5 - {0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00}, # 0xA6 - {0x3C, 0x7E, 0x60, 0x78, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x1E, 0x06, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xA7 - {0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0xA8 - {0x3C, 0x42, 0x42, 0x81, 0x99, 0xA5, 0xA1, 0xA1, 0xA1, 0xA5, 0x99, 0x81, 0x42, 0x42, 0x3C, 0x00}, # 0xA9 - {0x1C, 0x1E, 0x06, 0x06, 0x1E, 0x36, 0x36, 0x3E, 0x1E, 0x00, 0x00, 0x3E, 0x3E, 0x00, 0x00, 0x00}, # 0xAA - {0x00, 0x00, 0x33, 0x33, 0x66, 0x66, 0xCC, 0xCC, 0xCC, 0x66, 0x66, 0x33, 0x33, 0x00, 0x00, 0x00}, # 0xAB - {0x7E, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0xAC - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0xAD - {0x3C, 0x42, 0x42, 0x81, 0xB9, 0xA5, 0xA5, 0xA5, 0xB9, 0xA5, 0xA5, 0x81, 0x42, 0x42, 0x3C, 0x00}, # 0xAE - {0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0xAF - - # 字符编号 0xB0 - 0xBF - {0x3C, 0x66, 0x66, 0x66, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0xB0 - {0x00, 0x00, 0x18, 0x18, 0x7E, 0x7E, 0x18, 0x18, 0x00, 0x00, 0x7E, 0x7E, 0x00, 0x00, 0x00, 0x00}, # 0xB1 - {0x38, 0x04, 0x04, 0x04, 0x18, 0x20, 0x20, 0x20, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0xB2 - {0x38, 0x04, 0x04, 0x04, 0x18, 0x04, 0x04, 0x04, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0xB3 - {0x0C, 0x1C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0xB4 - {0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x3E, 0x30, 0x60, 0x60}, # 0xB5 - {0x03, 0x03, 0x3E, 0x7E, 0x76, 0x76, 0x76, 0x36, 0x36, 0x36, 0x36, 0x3E, 0x3E, 0x00, 0x00, 0x00}, # 0xB6 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0xB7 - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x18, 0x18, 0x30, 0x00}, # 0xB8 - {0x10, 0x10, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, # 0xB9 - {0x1C, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x1C, 0x00, 0x00, 0x3E, 0x3E, 0x00, 0x00, 0x00}, # 0xBA - {0x00, 0x00, 0x88, 0xCC, 0x66, 0x66, 0x33, 0x33, 0x33, 0x66, 0x66, 0xCC, 0x88, 0x00, 0x00, 0x00}, # 0xBB - {0x40, 0x40, 0xC0, 0x40, 0x40, 0x40, 0x48, 0x48, 0x48, 0x08, 0x0A, 0x0A, 0x0F, 0x02, 0x02, 0x00}, # 0xBC - {0x40, 0x40, 0xC0, 0x40, 0x40, 0x40, 0x4F, 0x41, 0x41, 0x01, 0x0F, 0x08, 0x08, 0x08, 0x0F, 0x00}, # 0xBD - {0xE0, 0x20, 0x20, 0x20, 0xE0, 0x20, 0x28, 0x28, 0xE8, 0x08, 0x0A, 0x0A, 0x0F, 0x02, 0x02, 0x00}, # 0xBE - {0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x18, 0x30, 0x30, 0x60, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xBF - - # 字符编号 0xC0 - 0xCF - {0x30, 0x38, 0x18, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x7E, 0x7E, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0xC0 - {0x0C, 0x1C, 0x18, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x7E, 0x7E, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0xC1 - {0x18, 0x3C, 0x66, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x7E, 0x7E, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0xC2 - {0x36, 0x7E, 0x6C, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x7E, 0x7E, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0xC3 - {0x66, 0x66, 0x66, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x7E, 0x7E, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0xC4 - {0x3C, 0x66, 0x66, 0x3C, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x7E, 0x7E, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0xC5 - {0x3F, 0x7F, 0x6C, 0x6C, 0x6C, 0x7F, 0x7F, 0x6C, 0x6C, 0x6C, 0x6C, 0x6F, 0x6F, 0x00, 0x00, 0x00}, # 0xC6 - {0x3C, 0x7E, 0x66, 0x60, 0x60, 0x60, 0x60, 0x60, 0x66, 0x7E, 0x3C, 0x18, 0x30, 0x30, 0x60, 0x00}, # 0xC7 - {0x30, 0x38, 0x18, 0x00, 0x7E, 0x7E, 0x60, 0x7C, 0x7C, 0x60, 0x60, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0xC8 - {0x0C, 0x1C, 0x18, 0x00, 0x7E, 0x7E, 0x60, 0x7C, 0x7C, 0x60, 0x60, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0xC9 - {0x3C, 0x7E, 0x66, 0x00, 0x7E, 0x7E, 0x60, 0x7C, 0x7C, 0x60, 0x60, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0xCA - {0x66, 0x66, 0x00, 0x00, 0x7E, 0x7E, 0x60, 0x7C, 0x7C, 0x60, 0x60, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0xCB - {0x30, 0x38, 0x18, 0x00, 0x7E, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0xCC - {0x0C, 0x1C, 0x18, 0x00, 0x7E, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0xCD - {0x3C, 0x7E, 0x66, 0x00, 0x7E, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0xCE - {0x66, 0x66, 0x66, 0x00, 0x7E, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0xCF - - # 字符编号 0xD0 - 0xDF - {0x78, 0x7C, 0x6C, 0x66, 0x66, 0xF6, 0xF6, 0x66, 0x66, 0x66, 0x6C, 0x7C, 0x78, 0x00, 0x00, 0x00}, # 0xD0 - {0x36, 0x7E, 0x6C, 0x00, 0x66, 0x66, 0x76, 0x76, 0x7E, 0x7E, 0x6E, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0xD1 - {0x30, 0x38, 0x18, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xD2 - {0x0C, 0x1C, 0x18, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xD3 - {0x3C, 0x7E, 0x66, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xD4 - {0x36, 0x7E, 0x6C, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xD5 - {0x66, 0x66, 0x00, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xD6 - {0x00, 0x00, 0x63, 0x63, 0x36, 0x36, 0x1C, 0x08, 0x1C, 0x36, 0x36, 0x63, 0x63, 0x00, 0x00, 0x00}, # 0xD7 - {0x3D, 0x7F, 0x66, 0x66, 0x6E, 0x6E, 0x7E, 0x76, 0x76, 0x66, 0x66, 0x7E, 0xBC, 0x80, 0x00, 0x00}, # 0xD8 - {0x30, 0x38, 0x18, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xD9 - {0x0C, 0x1C, 0x18, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xDA - {0x3C, 0x7E, 0x66, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xDB - {0x66, 0x66, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xDC - {0x0C, 0x1C, 0x18, 0x00, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00}, # 0xDD - {0xF0, 0xF0, 0x60, 0x78, 0x7C, 0x66, 0x66, 0x66, 0x7C, 0x78, 0x60, 0xF0, 0xF0, 0x00, 0x00, 0x00}, # 0xDE - {0x3C, 0x7E, 0x66, 0x66, 0x66, 0x6C, 0x6C, 0x66, 0x66, 0x66, 0x66, 0x6E, 0x6C, 0x60, 0xC0, 0x00}, # 0xDF - - # 字符编号 0xE0 - 0xEF - {0x30, 0x38, 0x18, 0x00, 0x3C, 0x3E, 0x06, 0x3E, 0x7E, 0x66, 0x66, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0xE0 - {0x0C, 0x1C, 0x18, 0x00, 0x3C, 0x3E, 0x06, 0x3E, 0x7E, 0x66, 0x66, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0xE1 - {0x18, 0x3C, 0x66, 0x00, 0x3C, 0x3E, 0x06, 0x3E, 0x7E, 0x66, 0x66, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0xE2 - {0x36, 0x7E, 0x6C, 0x00, 0x3C, 0x3E, 0x06, 0x3E, 0x7E, 0x66, 0x66, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0xE3 - {0x66, 0x66, 0x00, 0x00, 0x3C, 0x3E, 0x06, 0x3E, 0x7E, 0x66, 0x66, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0xE4 - {0x3C, 0x66, 0x66, 0x3C, 0x00, 0x3C, 0x3E, 0x06, 0x3E, 0x7E, 0x66, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0xE5 - {0x00, 0x00, 0x00, 0x00, 0x3E, 0x3F, 0x0B, 0x3B, 0x7F, 0x6F, 0x68, 0x7F, 0x3F, 0x00, 0x00, 0x00}, # 0xE6 - {0x00, 0x00, 0x00, 0x00, 0x3C, 0x7E, 0x66, 0x60, 0x60, 0x60, 0x66, 0x7E, 0x3C, 0x10, 0x60, 0x00}, # 0xE7 - {0x30, 0x38, 0x18, 0x00, 0x00, 0x3C, 0x7E, 0x66, 0x7E, 0x7E, 0x60, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0xE8 - {0x0C, 0x1C, 0x18, 0x00, 0x00, 0x3C, 0x7E, 0x66, 0x7E, 0x7E, 0x60, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0xE9 - {0x3C, 0x7E, 0x66, 0x00, 0x00, 0x3C, 0x7E, 0x66, 0x7E, 0x7E, 0x60, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0xEA - {0x66, 0x66, 0x00, 0x00, 0x00, 0x3C, 0x7E, 0x66, 0x7E, 0x7E, 0x60, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0xEB - {0x30, 0x38, 0x18, 0x00, 0x00, 0x38, 0x38, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0xEC - {0x0C, 0x1C, 0x18, 0x00, 0x00, 0x38, 0x38, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0xED - {0x3C, 0x7E, 0x66, 0x00, 0x00, 0x38, 0x38, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0xEE - {0x66, 0x66, 0x00, 0x00, 0x00, 0x38, 0x38, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x00, 0x00, 0x00}, # 0xEF - - # 字符编号 0xF0 - 0xFF - {0x18, 0x18, 0x7E, 0x7E, 0x0C, 0x06, 0x06, 0x3E, 0x7E, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xF0 - {0x36, 0x7E, 0x6C, 0x00, 0x00, 0x7C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00}, # 0xF1 - {0x30, 0x38, 0x18, 0x00, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xF2 - {0x0C, 0x1C, 0x18, 0x00, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xF3 - {0x3C, 0x7E, 0x66, 0x00, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xF4 - {0x36, 0x7E, 0x6C, 0x00, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xF5 - {0x66, 0x66, 0x00, 0x00, 0x00, 0x3C, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, 0x00, 0x00, 0x00}, # 0xF6 - {0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0xFF, 0xFF, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00}, # 0xF7 - {0x00, 0x00, 0x00, 0x02, 0x02, 0x3C, 0x7E, 0x6E, 0x76, 0x76, 0x66, 0x7E, 0xBC, 0x80, 0x00, 0x00}, # 0xF8 - {0x30, 0x38, 0x18, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0xF9 - {0x0C, 0x1C, 0x18, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0xFA - {0x18, 0x3C, 0x66, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0xFB - {0x66, 0x66, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3E, 0x00, 0x00, 0x00}, # 0xFC - {0x0C, 0x1C, 0x18, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3E, 0x06, 0x06, 0x7E, 0x7C, 0x00}, # 0xFD - {0x60, 0x60, 0x60, 0x78, 0x7C, 0x66, 0x66, 0x66, 0x7C, 0x78, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00}, # 0xFE - {0x66, 0x66, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3E, 0x06, 0x06, 0x7E, 0x7C, 0x00}, # 0xFF -] - -@t.Object -class _VGAScreenDriver: - # 帧缓冲区信息 - fbv: t.CVoid | t.CPtr # = None - fb: t.CUnsignedChar | t.CPtr # = None - fw: int # = 800 - fh: int # = 600 - fp: int # = 800 * 4 # 3200 800*4 - ColorFormat: __ColorFormat # = __ColorFormat.ColorFormat_BGRA # 默认使用BGRA格式 - BgColor: t.CUnsignedInt = 0xFF000080 # RGBA: 不透明深蓝色 - - # 初始化VGA驱动 - def __init__(self, fb: t.CVoid | t.CPtr, width: int, height: int, pitch: int, format: int): - # 先做参数合法性检查 - if fb is None or width <= 0 or height <= 0 or pitch <= 0: return - # 更新帧缓冲区参数 - self.fbv = fb - self.fb = t.CUnsignedChar(fb, t.CPtr) - self.fw = width - self.fh = height - self.fp = pitch - # 设置颜色格式 - match format: - case 0: self.ColorFormat = __ColorFormat.ColorFormat_RGBA - case 1: self.ColorFormat = __ColorFormat.ColorFormat_BGRA - case 2: pass - case 3: pass - case _: self.ColorFormat = __ColorFormat.ColorFormat_BGRA - # 检测硬件实际颜色格式(覆盖传入的format) - self.DetectColorFormat() - # 初始化背景颜色 - self.ClearScreen(self.BgColor) - - # 检测硬件颜色格式 - 优化测试逻辑,避免误判 - def DetectColorFormat(self) -> t.CStatic | t.CVoid: - if self.fb is None: return - fb: t.CUnsignedChar | t.CPtr = t.CUnsignedChar(self.fb, t.CPtr) - testX: int = 0 - testY: int = 0 - offset: int = testY * self.fp + testX * 4 - # 保存测试位置原始像素值,避免污染屏幕 - OriginalPixel: t.CUInt32T = c.Deref(t.CUInt32T(fb + offset, t.CPtr)) - # 写入测试颜色:青色 (RGBA逻辑值: 0xFF00FFFF) - fb[offset + 0] = 0xFF # B - fb[offset + 1] = 0xFF # G - fb[offset + 2] = 0x00 # R - fb[offset + 3] = 0xFF # A - # 读取回测试像素 - b: t.CUnsignedChar = fb[offset + 0] - g: t.CUnsignedChar = fb[offset + 1] - r: t.CUnsignedChar = fb[offset + 2] - # t.CVoid(fb[offset + 3]) # 忽略Alpha - # 恢复原始像素 - c.Set(c.Deref(t.CUInt32T(fb + offset, t.CPtr)), OriginalPixel) - # 判定颜色格式 - if r == 0x00 and g == 0xFF and b == 0xFF: self.ColorFormat = __ColorFormat.ColorFormat_BGRA - elif r == 0xFF and g == 0xFF and b == 0x00: self.ColorFormat = __ColorFormat.ColorFormat_RGBA - else: self.ColorFormat = __ColorFormat.ColorFormat_BGRA - - # 设置像素颜色 - 统一接口,输入为RGBA逻辑颜色 - # color格式: 0xAARRGGBB (Alpha, Red, Green, Blue) - def SetPixel(self, x: int, y: int, color: t.CUInt32T): - fb: t.CUnsignedChar | t.CPtr = self.fb - if fb is None: return - if x < 0 or x >= self.fw or y < 0 or y >= self.fh: return - offset: int = y * self.fp + x * 4 - # 解析RGBA分量 - r: t.CUnsignedChar = (color >> 16) & 0xFF - g: t.CUnsignedChar = (color >> 8) & 0xFF - b: t.CUnsignedChar = color & 0xFF - a: t.CUnsignedChar = (color >> 24) & 0xFF - # 根据硬件格式写入像素 - match self.ColorFormat: - case __ColorFormat.ColorFormat_BGRA: - self.fb[offset + 0] = b - fb[offset + 1] = g - fb[offset + 2] = r - fb[offset + 3] = a - case __ColorFormat.ColorFormat_RGBA: - fb[offset + 0] = r - fb[offset + 1] = g - fb[offset + 2] = b - fb[offset + 3] = a - case __ColorFormat.ColorFormat_BGR: - fb[offset + 0] = b - fb[offset + 1] = g - fb[offset + 2] = r - case __ColorFormat.ColorFormat_RGB: - fb[offset + 0] = r - fb[offset + 1] = g - fb[offset + 2] = b - case _: - # 降级到BGRA - fb[offset + 0] = b - fb[offset + 1] = g - fb[offset + 2] = r - fb[offset + 3] = a - - # 清除屏幕 - 优化循环效率,减少函数调用开销 - def ClearScreen(self, color: t.CUInt32T): - fb: t.CUnsignedChar | t.CPtr = self.fb - fp: int = self.fp - if fb is None: return - PixelSize: int = 3 if self.ColorFormat == __ColorFormat.ColorFormat_BGR or self.ColorFormat == __ColorFormat.ColorFormat_RGB else 4 - RowSize: int = self.fw * PixelSize - # 解析清除颜色的RGBA分量 - r: t.CUnsignedChar = (color >> 16) & 0xFF - g: t.CUnsignedChar = (color >> 8 ) & 0xFF - b: t.CUnsignedChar = (color) & 0xFF - a: t.CUnsignedChar = (color >> 24) & 0xFF - # 逐行填充,比逐像素调用SetPixel快得多 - for y in range(self.fh): - row_ptr: t.CUnsignedChar | t.CPtr = fb + y * fp - for x in range(self.fw): - offset: int = x * PixelSize - match self.ColorFormat: - case __ColorFormat.ColorFormat_BGRA: - row_ptr[offset + 0] = b - row_ptr[offset + 1] = g - row_ptr[offset + 2] = r - row_ptr[offset + 3] = a - case __ColorFormat.ColorFormat_RGBA: - row_ptr[offset + 0] = r - row_ptr[offset + 1] = g - row_ptr[offset + 2] = b - row_ptr[offset + 3] = a - case __ColorFormat.ColorFormat_BGR: - row_ptr[offset + 0] = b - row_ptr[offset + 1] = g - row_ptr[offset + 2] = r - case __ColorFormat.ColorFormat_RGB: - row_ptr[offset + 0] = r - row_ptr[offset + 1] = g - row_ptr[offset + 2] = b - - def Print(self, x: int, y: int, s: str, fontcolor: t.CUnsignedInt = 0xFFFFFFFF, size: int = 16): - self.PrintColor(x, y, s, fontcolor, 0x00000000, size) - - def PutcharColor(self, x: int, y: int, cr: t.CChar, fontcolor: t.CUnsignedInt = 0xFFFFFFFF, bgcolor: t.CUnsignedInt = 0x00000000, size: int = 16): - fw: int = self.fw - fh: int = self.fh - fb: t.CUnsignedChar | t.CPtr = self.fb - if fb is None: return - # 提前判断字符整体是否越界(8x16),避免内层循环冗余检查 - if x < 0 or y < 0 or (x + FONT_WIDTH) > fw or (y + FONT_HEIGHT) > fh: return - # 处理字符范围,非ASCII字符替换为默认字符 - ch: t.CUnsignedChar = t.CUnsignedChar(cr) - if ch >= 128: ch = DEFAULT_CHAR - # 预解析背景色Alpha,避免内层循环重复计算 - bg_alpha: t.CUInt8T = (bgcolor >> 24) & 0xFF - draw_bg: int = (bg_alpha != 0) # 背景是否需要绘制 - # 渲染8x16点阵字符 - for fy in range(FONT_HEIGHT): - row: t.CUnsignedChar = font[ch][fy] - for fx in range(FONT_WIDTH): - px: int = x + fx - py: int = y + fy - # 检测当前点阵位是否点亮 - if row & (0x80 >> fx): - # 绘制前景色 - self.SetPixel(px, py, fontcolor) - elif draw_bg: - # 仅当背景不透明时绘制背景色 - self.SetPixel(px, py, bgcolor) - - # 在指定位置显示带颜色和字号的字符串 - def PrintColor(self, x: int, y: int, s: str, fontcolor: t.CUnsignedInt = 0xFFFFFFFF, bgcolor: t.CUnsignedInt = 0x00000000, size: int = 16): - fw: int = self.fw - fh: int = self.fh - # fb: t.CUnsignedChar | t.CPtr = self.fb - currentX: int = x - currentY: int = y - if s is None: return - # 逐字符处理 - for _s in s: - if _s == '\n': - # 换行:重置X,Y增加字符高度 - currentX = x - currentY += size + 2 # 字体大小 + 2像素行间距 - # 检查换行后是否越界 - if currentY + size > fh: break - else: - # 显示普通字符 - self.PutcharColor(currentX, currentY, _s, fontcolor, bgcolor, size) - # 计算字符宽度 - CharWidth: int = size / 2 + 1 # 简单估算字符宽度 - currentX += CharWidth - # 检查横向是否越界 - if currentX + CharWidth > fw: - # 自动换行 - currentX = x - currentY += size + 2 - if currentY + size > fh: break diff --git a/Test/Kernel/execrunner/elf.vp b/Test/Kernel/execrunner/elf.vp deleted file mode 100644 index 8e620eab..00000000 --- a/Test/Kernel/execrunner/elf.vp +++ /dev/null @@ -1,757 +0,0 @@ -import drivers.serial.uart.serial as serial -import drivers.fs.fat32.fat32 as fat32 -import drivers.fs.fat32.fat32_types as fat32_types -import drivers.core.cpu.cpu as cpu -import mm.mm as mm -import paging.paging as paging -import sched.process as proc -import sched.sched as sched -import intr.gdt as gdt -# Do NOT import KERN_STACK_SIZE/USER_STACK_SIZE from process - CDefine cross-module import is broken -# Redefine them here to ensure correct values -KERN_STACK_SIZE: t.CDefine = 8192 -USER_STACK_SIZE: t.CDefine = 65536 -import viperlib -import string -import asm -import t, c - -ELFMAG0: t.CDefine = 0x7F -ELFMAG1: t.CDefine = 0x45 -ELFMAG2: t.CDefine = 0x4C -ELFMAG3: t.CDefine = 0x46 -ELFCLASS64: t.CDefine = 2 -ELFDATA2LSB: t.CDefine = 1 -ET_EXEC: t.CDefine = 2 -ET_DYN: t.CDefine = 3 -EM_X86_64: t.CDefine = 62 -PT_LOAD: t.CDefine = 1 -PT_DYNAMIC: t.CDefine = 2 -PF_X: t.CDefine = 1 -PF_W: t.CDefine = 2 -PF_R: t.CDefine = 4 -DT_NULL: t.CDefine = 0 -DT_HASH: t.CDefine = 4 -DT_STRTAB: t.CDefine = 5 -DT_SYMTAB: t.CDefine = 6 -DT_STRSZ: t.CDefine = 10 -DT_SYMENT: t.CDefine = 11 -DT_RELA: t.CDefine = 7 -DT_RELASZ: t.CDefine = 8 -DT_RELAENT: t.CDefine = 9 -DT_PLTRELSZ: t.CDefine = 2 -DT_JMPREL: t.CDefine = 23 -R_X86_64_64: t.CDefine = 1 -R_X86_64_GLOB_DAT: t.CDefine = 6 -R_X86_64_JUMP_SLOT: t.CDefine = 7 -R_X86_64_RELATIVE: t.CDefine = 8 -STB_GLOBAL: t.CDefine = 1 -STB_WEAK: t.CDefine = 2 - -@c.Attribute(t.attr.packed) -class Elf64_Ehdr: - e_ident: t.CArray[t.CUInt8T, 16] - e_type: t.CUInt16T - e_machine: t.CUInt16T - e_version: t.CUInt32T - e_entry: t.CUInt64T - e_phoff: t.CUInt64T - e_shoff: t.CUInt64T - e_flags: t.CUInt32T - e_ehsize: t.CUInt16T - e_phentsize: t.CUInt16T - e_phnum: t.CUInt16T - e_shentsize: t.CUInt16T - e_shnum: t.CUInt16T - e_shstrndx: t.CUInt16T - -@c.Attribute(t.attr.packed) -class Elf64_Phdr: - p_type: t.CUInt32T - p_flags: t.CUInt32T - p_offset: t.CUInt64T - p_vaddr: t.CUInt64T - p_paddr: t.CUInt64T - p_filesz: t.CUInt64T - p_memsz: t.CUInt64T - p_align: t.CUInt64T - -MAX_PHDRS: t.CDefine = 16 - -@c.Attribute(t.attr.packed) -class Elf64_Shdr: - sh_name: t.CUInt32T - sh_type: t.CUInt32T - sh_flags: t.CUInt64T - sh_addr: t.CUInt64T - sh_offset: t.CUInt64T - sh_size: t.CUInt64T - sh_link: t.CUInt32T - sh_info: t.CUInt32T - sh_addralign: t.CUInt64T - sh_entsize: t.CUInt64T - -@c.Attribute(t.attr.packed) -class Elf64_Sym: - st_name: t.CUInt32T - st_info: t.CUInt8T - st_other: t.CUInt8T - st_shndx: t.CUInt16T - st_value: t.CUInt64T - st_size: t.CUInt64T - -@c.Attribute(t.attr.packed) -class Elf64_Rela: - r_offset: t.CUInt64T - r_info: t.CUInt64T - r_addend: t.CInt64T - -@c.Attribute(t.attr.packed) -class Elf64_Dyn: - d_tag: t.CInt64T - d_val: t.CUInt64T - -MAX_SHDRS: t.CDefine = 64 -MAX_DYNS: t.CDefine = 64 -MAX_RELAS: t.CDefine = 256 - -def load_elf(path: t.CConst | str, do_map: t.CInt = 1) -> t.CVoid | t.CPtr: - fp: fat32_types.fileobj | t.CPtr = fat32.open(path, fat32_types.FA_READ) - if fp is None: - err: t.CUInt32T = fat32.last_error() - eb: t.CArray[t.CChar, 64] - viperlib.snprintf(c.Addr(eb), 64, "[elf] failed to open file err=%d\n", err) - serial.puts(eb) - return None - - ehdr_buf: t.CArray[t.CUInt8T, 64] - string.memset(c.Addr(ehdr_buf), 0, 64) - read_len: t.CUInt32T = fat32.read(fp, c.Addr(ehdr_buf), 64) - if read_len < 64: - serial.puts("[elf] failed to read ehdr\n") - fat32.close(fp) - return None - - ehdr: Elf64_Ehdr | t.CPtr = c.Addr(ehdr_buf) - - if ehdr.e_ident[0] != ELFMAG0 or ehdr.e_ident[1] != ELFMAG1 or ehdr.e_ident[2] != ELFMAG2 or ehdr.e_ident[3] != ELFMAG3: - serial.puts("[elf] bad magic\n") - fat32.close(fp) - return None - - if ehdr.e_ident[4] != ELFCLASS64: - serial.puts("[elf] not ELF64\n") - fat32.close(fp) - return None - - if ehdr.e_ident[5] != ELFDATA2LSB: - serial.puts("[elf] not little-endian\n") - fat32.close(fp) - return None - - if ehdr.e_type != ET_EXEC and ehdr.e_type != ET_DYN: - serial.puts("[elf] not ET_EXEC or ET_DYN\n") - fat32.close(fp) - return None - - if ehdr.e_machine != EM_X86_64: - serial.puts("[elf] not x86_64\n") - fat32.close(fp) - return None - - entry_point: t.CUInt64T = ehdr.e_entry - phoff: t.CUInt64T = ehdr.e_phoff - phentsize: t.CUInt16T = ehdr.e_phentsize - phnum: t.CUInt16T = ehdr.e_phnum - - if phentsize == 0 or phnum == 0 or phnum > MAX_PHDRS: - serial.puts("[elf] invalid phdr count\n") - fat32.close(fp) - return None - - cr: t.CArray[t.CChar, 80] - viperlib.snprintf(c.Addr(cr), 80, "[elf] entry=0x%lx phoff=%lu phentsize=%u phnum=%u\n", entry_point, phoff, phentsize, phnum) - serial.puts(cr) - - phdr_bufs: t.CArray[Elf64_Phdr, MAX_PHDRS] - string.memset(c.Addr(phdr_bufs), 0, MAX_PHDRS * 56) - - for pi in range(phnum): - phdr_off: t.CUInt64T = phoff + t.CUInt64T(pi) * t.CUInt64T(phentsize) - fat32.seek(fp, t.CUInt32T(phdr_off)) - fat32.read(fp, c.Addr(phdr_bufs[pi]), 56) - - found_load: t.CInt = 0 - lowest_vaddr: t.CUInt64T = 0 - highest_vaddr_end: t.CUInt64T = 0 - for pi in range(phnum): - if phdr_bufs[pi].p_type == PT_LOAD: - seg_end: t.CUInt64T = phdr_bufs[pi].p_vaddr + phdr_bufs[pi].p_memsz - if found_load == 0: - lowest_vaddr = phdr_bufs[pi].p_vaddr - highest_vaddr_end = seg_end - found_load = 1 - else: - if phdr_bufs[pi].p_vaddr < lowest_vaddr: - lowest_vaddr = phdr_bufs[pi].p_vaddr - if seg_end > highest_vaddr_end: - highest_vaddr_end = seg_end - - if found_load == 0: - serial.puts("[elf] no LOAD segments\n") - fat32.close(fp) - return None - - total_memsz: t.CUInt64T = highest_vaddr_end - lowest_vaddr - total_pages: t.CUInt64T = (total_memsz + 0xFFF) // 0x1000 - - cr2: t.CArray[t.CChar, 80] - viperlib.snprintf(c.Addr(cr2), 80, "[elf] vaddr 0x%lx-0x%lx pages=%lu\n", lowest_vaddr, highest_vaddr_end, total_pages) - serial.puts(cr2) - - raw_alloc: t.CVoid | t.CPtr = mm.malloc(total_pages * 0x1000 + 0x1000) - _db_ra: t.CArray[t.CChar, 80] - viperlib.snprintf(c.Addr(_db_ra), 80, "[elf] malloc ret raw_alloc=0x%lx\n", t.CUInt64T(raw_alloc)) - serial.puts(_db_ra) - if not raw_alloc: - serial.puts("[elf] malloc failed\n") - fat32.close(fp) - return None - - phys_base_aligned: t.CUInt64T = (t.CUInt64T(raw_alloc) + t.CUInt64T(0xFFF)) & ~t.CUInt64T(0xFFF) - phys_base: t.CVoid | t.CPtr = t.CVoid(phys_base_aligned, t.CPtr) - - string.memset(phys_base, 0, total_pages * 0x1000) - - for pi in range(phnum): - if phdr_bufs[pi].p_type == PT_LOAD: - vaddr: t.CUInt64T = phdr_bufs[pi].p_vaddr - file_off: t.CUInt64T = phdr_bufs[pi].p_offset - filesz: t.CUInt64T = phdr_bufs[pi].p_filesz - memsz: t.CUInt64T = phdr_bufs[pi].p_memsz - dest_off: t.CUInt64T = vaddr - lowest_vaddr - dest: t.CVoid | t.CPtr = t.CVoid(t.CUInt64T(phys_base) + dest_off, t.CPtr) - - if filesz > 0: - fat32.seek(fp, t.CUInt32T(file_off)) - fat32.read(fp, dest, t.CUInt32T(filesz)) - - if memsz > filesz: - bss_start: t.CVoid | t.CPtr = t.CVoid(t.CUInt64T(dest) + filesz, t.CPtr) - bss_len: t.CUInt64T = memsz - filesz - string.memset(bss_start, 0, bss_len) - - fat32.close(fp) - - virt_page_start: t.CUInt64T = lowest_vaddr & ~t.CUInt64T(0xFFF) - phys_page_start: t.CUInt64T = t.CUInt64T(phys_base) & ~t.CUInt64T(0xFFF) - map_end: t.CUInt64T = (highest_vaddr_end + 0xFFF) & ~t.CUInt64T(0xFFF) - num_map_pages: t.CUInt64T = (map_end - virt_page_start) // 0x1000 - - # Store mapping info for spawn_elf (used when do_map=0) - global _last_elf_phys_page_start, _last_elf_virt_page_start, _last_elf_num_map_pages - _last_elf_phys_page_start = phys_page_start - _last_elf_virt_page_start = virt_page_start - _last_elf_num_map_pages = num_map_pages - - if do_map != 0: - for mi in range(num_map_pages): - virt_addr: t.CUInt64T = virt_page_start + mi * 0x1000 - phys_addr: t.CUInt64T = phys_page_start + mi * 0x1000 - page_flags: t.CUInt64T = paging.PTE_PRESENT | paging.PTE_WRITABLE | paging.PTE_USER - paging.MapPage(virt_addr, phys_addr, page_flags) - - entry_addr: t.CVoid | t.CPtr = t.CVoid(entry_point, t.CPtr) - - return entry_addr - -def run_elf(path: t.CConst | str) -> t.CInt: - entry: t.CVoid | t.CPtr = load_elf(path) - if entry is None: - serial.puts("[elf] load failed\n") - return -1 - serial.puts("[elf] jumping to entry...\n") - c.Asm(f"""call {c.AsmInp(entry, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11]) - serial.puts("[elf] returned from entry\n") - return 0 - -MAX_SPAWNED: t.CDefine = 8 -_elf_entries: t.CArray[t.CVoid | t.CPtr, MAX_SPAWNED] - -# User stack virtual address: top of 48-bit user space, 64KB below -USER_STACK_VTOP: t.CDefine = 0x7FFFFFE00000 - -# Globals for ELF mapping info (set by load_elf when do_map=0, used by spawn_elf -# to map ELF pages in the cloned PML4 instead of kernel PML4). -# ROOT CAUSE: previously load_elf mapped ELF vaddr (e.g. 0x400000) into the -# kernel PML4, overwriting the identity mapping of buddy system memory_block -# headers at 0x400000. This corrupted buddy metadata -> malloc failures, -# pid=0, and #GP in split_block. Fix: load_elf does NOT map; spawn_elf maps -# in the cloned PML4 after clone_for_process. -_last_elf_phys_page_start: t.CUInt64T = 0 -_last_elf_virt_page_start: t.CUInt64T = 0 -_last_elf_num_map_pages: t.CUInt64T = 0 - -def _elf_entry_wrapper(arg: t.CVoid | t.CPtr) -> t.CInt: - pid: t.CInt = t.CInt(t.CUInt64T(arg)) - _db1: t.CArray[t.CChar, 64] - viperlib.snprintf(c.Addr(_db1), 64, "[elf] wrapper pid=%d\n", pid) - serial.puts(_db1) - # Disable interrupts around switch_pid + MapPage + TSS setup: @pml4 is a global - # that switch_pid modifies. A timer interrupt mid-section would make the scheduler - # call switch_pid for another thread, corrupting @pml4 for our MapPage calls. - asm.cli() - proc.switch_pid(pid) - cur_p: proc.Process | t.CPtr = proc.ProcessManager.current() - entry_fn: t.CVoid | t.CPtr = cur_p.entry - if entry_fn is not None: - user_stack_vtop: t.CUInt64T = USER_STACK_VTOP - us_sz: t.CUInt64T = USER_STACK_SIZE - user_stack_vbottom: t.CUInt64T = USER_STACK_VTOP - us_sz - # Physical pages of the user stack (allocated by mm.malloc, identity-mapped) - us_size: t.CUInt64T = USER_STACK_SIZE - phys_bottom: t.CUInt64T = (cur_p.user_stack - us_size) & ~t.CUInt64T(0xFFF) - # Map each page of the user stack at the virtual address with PTE_USER - num_stack_pages: t.CUInt64T = 16 # USER_STACK_SIZE(65536) / PAGE_SIZE(4096) = 16 - si: t.CUInt64T - for si in range(num_stack_pages): - vaddr: t.CUInt64T = (user_stack_vbottom & ~t.CUInt64T(0xFFF)) + si * t.CUInt64T(0x1000) - paddr: t.CUInt64T = phys_bottom + si * t.CUInt64T(0x1000) - paging.MapPage(vaddr, paddr, paging.PTE_PRESENT | paging.PTE_WRITABLE | paging.PTE_USER) - # Set TSS RSP0 so interrupts from Ring 3 use kernel stack - gdt.set_tss_rsp0(cur_p.kern_stack) - # Set GS kernel_rsp0 for syscall entry from Ring 3 - cpu.set_kernel_rsp0(cur_p.kern_stack) - # Keep interrupts disabled until iretq: drop_to_user_mode's iretq - # will set RFLAGS.IF from the saved frame (0x202) for user mode. - # This prevents timer interrupt preemption between TSS setup and iretq. - # Drop to Ring 3 user mode via iretq - proc.drop_to_user_mode(entry_fn, user_stack_vtop, cur_p.kern_stack) - cur: proc.Process | t.CPtr = proc.ProcessManager.current() - cur.exit() - return 0 - -def spawn_elf(path: t.CConst | str) -> t.CInt: - fat32.lock() - name_start: t.CInt = 0 - si: t.CInt = 0 - while True: - ch: t.CChar = path[si] - if ch == 0: break - if ch == 47: - name_start = si + 1 - si += 1 - - lowest_vaddr: t.CUInt64T = 0 - highest_vaddr_end: t.CUInt64T = 0 - fp_scan: fat32_types.fileobj | t.CPtr = fat32.open(path, fat32_types.FA_READ) - if fp_scan is None: - serr: t.CUInt32T = fat32.last_error() - seb: t.CArray[t.CChar, 64] - viperlib.snprintf(c.Addr(seb), 64, "[elf] spawn scan open failed err=%d\n", serr) - serial.puts(seb) - fat32.unlock() - return -1 - if fp_scan is not None: - ehdr_buf_s: t.CArray[t.CUInt8T, 64] - string.memset(c.Addr(ehdr_buf_s), 0, 64) - fat32.read(fp_scan, c.Addr(ehdr_buf_s), 64) - ehdr_s: Elf64_Ehdr | t.CPtr = c.Addr(ehdr_buf_s) - if ehdr_s.e_type == ET_EXEC or ehdr_s.e_type == ET_DYN: - phoff_s: t.CUInt64T = ehdr_s.e_phoff - phentsize_s: t.CUInt16T = ehdr_s.e_phentsize - phnum_s: t.CUInt16T = ehdr_s.e_phnum - if phentsize_s > 0 and phnum_s > 0 and phnum_s <= MAX_PHDRS: - phdr_bufs_s: t.CArray[Elf64_Phdr, MAX_PHDRS] - string.memset(c.Addr(phdr_bufs_s), 0, MAX_PHDRS * 56) - found_load_s: t.CInt = 0 - for pi_s in range(phnum_s): - fat32.seek(fp_scan, t.CUInt32T(phoff_s + t.CUInt64T(pi_s) * t.CUInt64T(phentsize_s))) - fat32.read(fp_scan, c.Addr(phdr_bufs_s[pi_s]), 56) - if phdr_bufs_s[pi_s].p_type == PT_LOAD: - seg_end_s: t.CUInt64T = phdr_bufs_s[pi_s].p_vaddr + phdr_bufs_s[pi_s].p_memsz - if found_load_s == 0: - lowest_vaddr = phdr_bufs_s[pi_s].p_vaddr - highest_vaddr_end = seg_end_s - found_load_s = 1 - else: - if phdr_bufs_s[pi_s].p_vaddr < lowest_vaddr: - lowest_vaddr = phdr_bufs_s[pi_s].p_vaddr - if seg_end_s > highest_vaddr_end: - highest_vaddr_end = seg_end_s - fat32.close(fp_scan) - - isolate_va: t.CUInt64T = lowest_vaddr - if isolate_va == 0: - isolate_va = 0x400000 - - # Load ELF to physical memory WITHOUT mapping in kernel PML4. - # do_map=0: load_elf stores mapping info in globals for spawn_elf to use. - # ROOT CAUSE FIX: previously load_elf mapped ELF vaddr (e.g. 0x400000) into - # kernel PML4, overwriting identity mapping of buddy memory_block headers. - entry: t.CVoid | t.CPtr = load_elf(path, 0) - if entry is None: - serial.puts("[elf] spawn: load failed\n") - fat32.unlock() - return -1 - - # Clone kernel PML4 (identity mapping intact, no ELF mapping yet) - proc_pml4: t.CUInt64T = paging.clone_for_process(isolate_va) - slog1: t.CArray[t.CChar, 80] - viperlib.snprintf(c.Addr(slog1), 80, "[elf] spawn: clone pml4=0x%lx va=0x%lx\n", proc_pml4, isolate_va) - serial.puts(slog1) - if proc_pml4 == 0: - serial.puts("[elf] spawn: clone_for_process failed\n") - fat32.unlock() - return -1 - - # Map ELF pages in the CLONED PML4 (not kernel's). - # This prevents overwriting kernel identity mapping at 0x400000 which - # would corrupt buddy system memory_block headers. - # Must disable interrupts: @pml4 global is used by MapPage and a timer - # interrupt mid-section would call switch_pid, corrupting @pml4. - asm.cli() - _kernel_cr3: t.CUInt64T = 0 - c.Asm(f"""mov {c.AsmOut(_kernel_cr3, t.ASM_DESCR.OUTPUT_REG)}, cr3""", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - c.Asm(f"mov cr3, {c.AsmInp(proc_pml4, t.ASM_DESCR.REG_ANY)}", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - paging.set_active_pml4(proc_pml4) - mi: t.CUInt64T - for mi in range(_last_elf_num_map_pages): - _va: t.CUInt64T = _last_elf_virt_page_start + mi * 0x1000 - _pa: t.CUInt64T = _last_elf_phys_page_start + mi * 0x1000 - paging.MapPage(_va, _pa, paging.PTE_PRESENT | paging.PTE_WRITABLE | paging.PTE_USER) - c.Asm(f"mov cr3, {c.AsmInp(_kernel_cr3, t.ASM_DESCR.REG_ANY)}", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - paging.set_active_pml4(_kernel_cr3) - asm.sti() - - p: proc.Process | t.CPtr = proc.ProcessManager.create_process(path[name_start:], entry) - if p is None: - serial.puts("[elf] spawn: create_process failed\n") - fat32.unlock() - return -2 - p.elf_base = t.CUInt64T(entry) - p.pml4_root = proc_pml4 - if p.pid >= 0 and p.pid < MAX_SPAWNED: - _elf_entries[p.pid] = entry - - th: sched.Thread | t.CPtr = sched.Scheduler.create_thread(_elf_entry_wrapper, t.CVoid(t.CUInt64T(p.pid), t.CPtr), p.pid) - if th is None: - serial.puts("[elf] spawn: create_thread failed\n") - p.exit() - fat32.unlock() - return -3 - tid: t.CInt = th.tid - p.addThread(tid) - slog: t.CArray[t.CChar, 80] - viperlib.snprintf(c.Addr(slog), 80, "[elf] spawn: pid=%d tid=%d entry=0x%lx pml4=0x%lx\n", p.pid, tid, t.CUInt64T(entry), p.pml4_root) - serial.puts(slog) - fat32.unlock() - return p.pid - -def _resolve_symbol(name: t.CConst | t.CChar | t.CPtr) -> t.CVoid | t.CPtr: - nm: t.CInt = 0 - while c.Deref(name + nm) != 0: - nm += 1 - cmp_name: t.CConst | t.CChar | t.CPtr = name - cmp_len: t.CInt = nm - if nm > 9: - sha1_len2: t.CInt = 0 - for si2 in range(nm): - ch2: t.CChar = c.Deref(name + si2) - if ch2 == 46: - if sha1_len2 >= 8: - cmp_name = t.CConst(t.CUInt64T(name) + si2 + 1, t.CPtr) - cmp_len = nm - si2 - 1 - break - if ch2 == 0: - break - if (ch2 >= 48 and ch2 <= 57) or (ch2 >= 97 and ch2 <= 102): - sha1_len2 += 1 - else: - break - if cmp_len == 11: - match: t.CInt = 1 - for i in range(cmp_len): - if c.Deref(cmp_name + i) != c.Deref("serial_puts" + i): - match = 0 - if match: - return t.CVoid(c.Addr(serial.puts), t.CPtr) - return None - -_so_strtab: t.CVoid | t.CPtr -_so_symtab: t.CVoid | t.CPtr -_so_syment: t.CUInt64T -_so_sym_count: t.CInt - -def load_so(path: t.CConst | str) -> t.CVoid | t.CPtr: - fat32.lock() - fp: fat32_types.fileobj | t.CPtr = fat32.open(path, fat32_types.FA_READ) - if fp is None: - serial.puts("[so] failed to open file\n") - fat32.unlock() - return None - - ehdr_buf: t.CArray[t.CUInt8T, 64] - string.memset(c.Addr(ehdr_buf), 0, 64) - read_len: t.CUInt32T = fat32.read(fp, c.Addr(ehdr_buf), 64) - if read_len < 64: - serial.puts("[so] failed to read ehdr\n") - fat32.close(fp) - fat32.unlock() - return None - - ehdr: Elf64_Ehdr | t.CPtr = c.Addr(ehdr_buf) - if ehdr.e_ident[0] != ELFMAG0 or ehdr.e_ident[1] != ELFMAG1 or ehdr.e_ident[2] != ELFMAG2 or ehdr.e_ident[3] != ELFMAG3: - serial.puts("[so] bad magic\n") - fat32.close(fp) - fat32.unlock() - return None - if ehdr.e_ident[4] != ELFCLASS64: - serial.puts("[so] not ELF64\n") - fat32.close(fp) - fat32.unlock() - return None - if ehdr.e_type == ET_DYN: - pass - elif ehdr.e_type == ET_EXEC: - pass - else: - serial.puts("[so] not ET_DYN or ET_EXEC\n") - fat32.close(fp) - fat32.unlock() - return None - - phoff: t.CUInt64T = ehdr.e_phoff - phentsize: t.CUInt16T = ehdr.e_phentsize - phnum: t.CUInt16T = ehdr.e_phnum - - phdr_bufs: t.CArray[Elf64_Phdr, MAX_PHDRS] - string.memset(c.Addr(phdr_bufs), 0, MAX_PHDRS * 56) - for pi in range(phnum): - phdr_off: t.CUInt64T = phoff + t.CUInt64T(pi) * t.CUInt64T(phentsize) - fat32.seek(fp, t.CUInt32T(phdr_off)) - fat32.read(fp, c.Addr(phdr_bufs[pi]), 56) - - found_load: t.CInt = 0 - lowest_vaddr: t.CUInt64T = 0 - highest_vaddr_end: t.CUInt64T = 0 - for pi in range(phnum): - if phdr_bufs[pi].p_type == PT_LOAD: - seg_end: t.CUInt64T = phdr_bufs[pi].p_vaddr + phdr_bufs[pi].p_memsz - if found_load == 0: - lowest_vaddr = phdr_bufs[pi].p_vaddr - highest_vaddr_end = seg_end - found_load = 1 - else: - if phdr_bufs[pi].p_vaddr < lowest_vaddr: - lowest_vaddr = phdr_bufs[pi].p_vaddr - if seg_end > highest_vaddr_end: - highest_vaddr_end = seg_end - - if found_load == 0: - serial.puts("[so] no LOAD segments\n") - fat32.close(fp) - fat32.unlock() - return None - - total_memsz: t.CUInt64T = highest_vaddr_end - lowest_vaddr - total_pages: t.CUInt64T = (total_memsz + 0xFFF) // 0x1000 - - so_load_addr: t.CUInt64T = 0x600000 - raw_alloc: t.CVoid | t.CPtr = mm.malloc(total_pages * 0x1000 + 0x1000) - if not raw_alloc: - serial.puts("[so] malloc failed\n") - fat32.close(fp) - fat32.unlock() - return None - - phys_base_aligned: t.CUInt64T = (t.CUInt64T(raw_alloc) + 0xFFF) & ~t.CUInt64T(0xFFF) - phys_base: t.CVoid | t.CPtr = t.CVoid(phys_base_aligned, t.CPtr) - string.memset(phys_base, 0, total_pages * 0x1000) - - for pi in range(phnum): - if phdr_bufs[pi].p_type == PT_LOAD: - vaddr: t.CUInt64T = phdr_bufs[pi].p_vaddr - file_off: t.CUInt64T = phdr_bufs[pi].p_offset - filesz: t.CUInt64T = phdr_bufs[pi].p_filesz - memsz: t.CUInt64T = phdr_bufs[pi].p_memsz - dest_off: t.CUInt64T = vaddr - lowest_vaddr - dest: t.CVoid | t.CPtr = t.CVoid(t.CUInt64T(phys_base) + dest_off, t.CPtr) - if filesz > 0: - fat32.seek(fp, t.CUInt32T(file_off)) - fat32.read(fp, dest, t.CUInt32T(filesz)) - if memsz > filesz: - bss_start: t.CVoid | t.CPtr = t.CVoid(t.CUInt64T(dest) + filesz, t.CPtr) - bss_len: t.CUInt64T = memsz - filesz - string.memset(bss_start, 0, bss_len) - - virt_page_start: t.CUInt64T = (so_load_addr + lowest_vaddr) & ~t.CUInt64T(0xFFF) - phys_page_start: t.CUInt64T = t.CUInt64T(phys_base) & ~t.CUInt64T(0xFFF) - map_end: t.CUInt64T = (so_load_addr + highest_vaddr_end + 0xFFF) & ~t.CUInt64T(0xFFF) - num_map_pages: t.CUInt64T = (map_end - virt_page_start) // 0x1000 - - for mi in range(num_map_pages): - virt_addr: t.CUInt64T = virt_page_start + mi * 0x1000 - phys_addr: t.CUInt64T = phys_page_start + mi * 0x1000 - paging.MapPage(virt_addr, phys_addr, paging.PTE_PRESENT | paging.PTE_WRITABLE | paging.PTE_USER) - - base_vaddr: t.CUInt64T = so_load_addr + lowest_vaddr - - dyn_buf: t.CArray[Elf64_Dyn, MAX_DYNS] - string.memset(c.Addr(dyn_buf), 0, MAX_DYNS * 16) - dyn_count: t.CInt = 0 - for pi in range(phnum): - if phdr_bufs[pi].p_type == PT_DYNAMIC: - fat32.seek(fp, t.CUInt32T(phdr_bufs[pi].p_offset)) - dyn_read: t.CUInt32T = fat32.read(fp, c.Addr(dyn_buf), t.CUInt32T(phdr_bufs[pi].p_filesz)) - dyn_count = t.CInt(dyn_read) // 16 - - strtab_vaddr: t.CUInt64T = 0 - symtab_vaddr: t.CUInt64T = 0 - hash_vaddr: t.CUInt64T = 0 - syment: t.CUInt64T = 0 - rela_vaddr: t.CUInt64T = 0 - relasz: t.CUInt64T = 0 - jmprel_vaddr: t.CUInt64T = 0 - pltrelsz: t.CUInt64T = 0 - for di in range(dyn_count): - if dyn_buf[di].d_tag == DT_NULL: break - if dyn_buf[di].d_tag == DT_STRTAB: strtab_vaddr = dyn_buf[di].d_val - elif dyn_buf[di].d_tag == DT_SYMTAB: symtab_vaddr = dyn_buf[di].d_val - elif dyn_buf[di].d_tag == DT_HASH: hash_vaddr = dyn_buf[di].d_val - elif dyn_buf[di].d_tag == DT_SYMENT: syment = dyn_buf[di].d_val - elif dyn_buf[di].d_tag == DT_RELA: rela_vaddr = dyn_buf[di].d_val - elif dyn_buf[di].d_tag == DT_RELASZ: relasz = dyn_buf[di].d_val - elif dyn_buf[di].d_tag == DT_JMPREL: jmprel_vaddr = dyn_buf[di].d_val - elif dyn_buf[di].d_tag == DT_PLTRELSZ: pltrelsz = dyn_buf[di].d_val - - strtab_ptr: t.CVoid | t.CPtr = t.CVoid(strtab_vaddr + so_load_addr, t.CPtr) - symtab_ptr: t.CVoid | t.CPtr = t.CVoid(symtab_vaddr + so_load_addr, t.CPtr) - - if rela_vaddr != 0 and relasz > 0: - rela_count: t.CUInt64T = relasz // 24 - for ri in range(rela_count): - rela: Elf64_Rela | t.CPtr = t.CVoid(t.CUInt64T(rela_vaddr) + so_load_addr + ri * 24, t.CPtr) - r_type: t.CUInt32T = t.CUInt32T(rela.r_info & 0xFFFFFFFF) - r_sym: t.CUInt32T = t.CUInt32T(rela.r_info >> 32) - target_addr: t.CVoid | t.CPtr = t.CVoid(rela.r_offset + so_load_addr, t.CPtr) - if r_type == R_X86_64_RELATIVE: - val: t.CUInt64T = t.CUInt64T(rela.r_addend) + so_load_addr - string.memcpy(target_addr, c.Addr(val), 8) - elif r_type == R_X86_64_64 or r_type == R_X86_64_GLOB_DAT or r_type == R_X86_64_JUMP_SLOT: - sym: Elf64_Sym | t.CPtr = t.CVoid(t.CUInt64T(symtab_ptr) + t.CUInt64T(r_sym) * syment, t.CPtr) - sym_name: t.CConst | t.CChar | t.CPtr = t.CConst(t.CUInt64T(strtab_ptr) + sym.st_name, t.CPtr) - resolved: t.CVoid | t.CPtr = _resolve_symbol(sym_name) - if resolved is not None: - val2: t.CUInt64T = t.CUInt64T(resolved) + t.CUInt64T(rela.r_addend) - string.memcpy(target_addr, c.Addr(val2), 8) - elif sym.st_value != 0: - val3: t.CUInt64T = sym.st_value + so_load_addr + t.CUInt64T(rela.r_addend) - string.memcpy(target_addr, c.Addr(val3), 8) - - if jmprel_vaddr != 0 and pltrelsz > 0: - jmprel_count: t.CUInt64T = pltrelsz // 24 - for ji in range(jmprel_count): - rela2: Elf64_Rela | t.CPtr = t.CVoid(jmprel_vaddr + so_load_addr + ji * 24, t.CPtr) - r_type2: t.CUInt32T = t.CUInt32T(rela2.r_info & 0xFFFFFFFF) - r_sym2: t.CUInt32T = t.CUInt32T(rela2.r_info >> 32) - target2: t.CVoid | t.CPtr = t.CVoid(rela2.r_offset + so_load_addr, t.CPtr) - if r_type2 == R_X86_64_JUMP_SLOT or r_type2 == R_X86_64_GLOB_DAT: - sym2: Elf64_Sym | t.CPtr = t.CVoid(t.CUInt64T(symtab_ptr) + t.CUInt64T(r_sym2) * syment, t.CPtr) - sym_name2: t.CConst | t.CChar | t.CPtr = t.CConst(t.CUInt64T(strtab_ptr) + sym2.st_name, t.CPtr) - resolved2: t.CVoid | t.CPtr = _resolve_symbol(sym_name2) - if resolved2 is not None: - val4: t.CUInt64T = t.CUInt64T(resolved2) + t.CUInt64T(rela2.r_addend) - string.memcpy(target2, c.Addr(val4), 8) - elif sym2.st_value != 0: - val5: t.CUInt64T = sym2.st_value + so_load_addr + t.CUInt64T(rela2.r_addend) - string.memcpy(target2, c.Addr(val5), 8) - else: - cr3: t.CArray[t.CChar, 80] - viperlib.snprintf(c.Addr(cr3), 80, "[so] WARN: unresolved PLT sym offset=%lu\n", sym2.st_name) - serial.puts(cr3) - - fat32.close(fp) - - _so_strtab = strtab_ptr - _so_symtab = symtab_ptr - _so_syment = syment - _so_sym_count = 0 - if hash_vaddr != 0: - hash_ptr: t.CVoid | t.CPtr = t.CVoid(hash_vaddr + so_load_addr, t.CPtr) - nchain: t.CUInt32T = c.Deref(t.CVoid(t.CUInt64T(hash_ptr) + 4, t.CPtr)) - _so_sym_count = t.CInt(nchain) - elif syment > 0 and strtab_vaddr > symtab_vaddr and symtab_vaddr != 0: - sym_tab_size: t.CUInt64T = strtab_vaddr - symtab_vaddr - _so_sym_count = t.CInt(sym_tab_size // syment) - - cr: t.CArray[t.CChar, 80] - viperlib.snprintf(c.Addr(cr), 80, "[so] loaded at 0x%lx\n", base_vaddr) - serial.puts(cr) - - fat32.unlock() - return t.CVoid(base_vaddr, t.CPtr) - -def get_so_symbol(so_base: t.CVoid | t.CPtr, name: t.CConst | t.CChar | t.CPtr, so_path: t.CConst | t.CChar | t.CPtr) -> t.CVoid | t.CPtr: - if _so_symtab is None or _so_strtab is None or _so_syment == 0: - return None - if name is None: - return None - for symi in range(_so_sym_count): - sb2: Elf64_Sym | t.CPtr = t.CVoid(t.CUInt64T(_so_symtab) + t.CUInt64T(symi) * _so_syment, t.CPtr) - if sb2.st_value != 0 and sb2.st_shndx != 0: - sym_name_off2: t.CUInt32T = sb2.st_name - cmp_off2: t.CUInt32T = sym_name_off2 - match2: t.CInt = 0 - ni2: t.CInt = 0 - while True: - sc3: t.CChar = c.Deref(t.CVoid(t.CUInt64T(_so_strtab) + cmp_off2 + ni2, t.CPtr)) - nc3: t.CChar = c.Deref(name + ni2) - if sc3 != nc3: - break - if sc3 == 0: - match2 = 1 - break - ni2 += 1 - if match2 == 0: - dot_pos3: t.CUInt32T = sym_name_off2 - is_sha1_2: t.CInt = 0 - sha1_len_2: t.CUInt32T = 0 - while True: - dc4: t.CChar = c.Deref(t.CVoid(t.CUInt64T(_so_strtab) + dot_pos3, t.CPtr)) - if dc4 == 46: - if sha1_len_2 >= 8: - is_sha1_2 = 1 - break - if dc4 == 0: - break - if (dc4 >= 48 and dc4 <= 57) or (dc4 >= 97 and dc4 <= 102): - sha1_len_2 += 1 - else: - break - dot_pos3 += 1 - if is_sha1_2: - cmp_off2 = dot_pos3 + 1 - match2 = 1 - ni2 = 0 - while True: - sc4: t.CChar = c.Deref(t.CVoid(t.CUInt64T(_so_strtab) + cmp_off2 + ni2, t.CPtr)) - nc4: t.CChar = c.Deref(name + ni2) - if sc4 != nc4: - match2 = 0 - break - if sc4 == 0: - break - ni2 += 1 - if match2: - result_addr: t.CUInt64T = t.CUInt64T(so_base) + sb2.st_value - dbg2: t.CArray[t.CChar, 80] - viperlib.snprintf(c.Addr(dbg2), 80, "[so] found '%s' at 0x%lx\n", t.CVoid(t.CUInt64T(_so_strtab) + sym_name_off2, t.CPtr), result_addr) - serial.puts(dbg2) - return t.CVoid(result_addr, t.CPtr) - serial.puts("[so] symbol not found\n") - return None diff --git a/Test/Kernel/intr/__init__.vp b/Test/Kernel/intr/__init__.vp deleted file mode 100644 index eede1234..00000000 --- a/Test/Kernel/intr/__init__.vp +++ /dev/null @@ -1,2 +0,0 @@ -from . import gdt -from . import idt diff --git a/Test/Kernel/intr/gdt.vp b/Test/Kernel/intr/gdt.vp deleted file mode 100644 index 524573e0..00000000 --- a/Test/Kernel/intr/gdt.vp +++ /dev/null @@ -1,142 +0,0 @@ -import t, c - - -@c.Attribute(t.attr.packed) -class gdt_entry: - limit_low: t.CUInt16T - base_low: t.CUInt16T - base_middle: t.CUInt8T - access: t.CUInt8T - granularity: t.CUInt8T - base_high: t.CUInt8T - -@c.Attribute(t.attr.packed) -class gdt_entry64: - limit_low: t.CUInt16T - base_low: t.CUInt16T - base_middle: t.CUInt8T - access: t.CUInt8T - granularity: t.CUInt8T - base_high: t.CUInt8T - base_upper: t.CUInt32T - reserved: t.CUInt32T - -@c.Attribute(t.attr.packed) -class gdt_ptr: - limit: t.CUInt16T - base: t.CUInt64T - -gdt: t.CArray[gdt_entry, 7] = [] -gp: t.CArray[t.CUInt8T, 10] -# TSS buffer: 104 bytes, raw byte array to avoid packed struct issues -# x86_64 TSS layout: reserved0(4) rsp0(8) rsp1(8) rsp2(8) reserved1(8) ist1-ist7(56) reserved2(8) reserved3(2) iomap_base(2) -tss_buf: t.CArray[t.CUInt8T, 104] - -CODE_SEG: t.CDefine | t.CUInt16T = 0x08 -DATA_SEG: t.CDefine | t.CUInt16T = 0x10 -USER_CODE_SEG: t.CDefine | t.CUInt16T = 0x18 -USER_DATA_SEG: t.CDefine | t.CUInt16T = 0x20 -TSS_SEG: t.CDefine | t.CUInt16T = 0x28 - - -def init(): - global gp, gdt, tss_buf - gdt[0].limit_low = 0 - gdt[0].base_low = 0 - gdt[0].base_middle = 0 - gdt[0].access = 0 - gdt[0].granularity = 0 - gdt[0].base_high = 0 - gdt[1].limit_low = 0 - gdt[1].base_low = 0 - gdt[1].base_middle = 0 - gdt[1].access = 0x9A - gdt[1].granularity = 0x20 - gdt[1].base_high = 0 - gdt[2].limit_low = 0 - gdt[2].base_low = 0 - gdt[2].base_middle = 0 - gdt[2].access = 0x92 - gdt[2].granularity = 0xCF - gdt[2].base_high = 0 - gdt[3].limit_low = 0 - gdt[3].base_low = 0 - gdt[3].base_middle = 0 - gdt[3].access = 0xFA - gdt[3].granularity = 0x20 - gdt[3].base_high = 0 - gdt[4].limit_low = 0 - gdt[4].base_low = 0 - gdt[4].base_middle = 0 - gdt[4].access = 0xF2 - gdt[4].granularity = 0xCF - gdt[4].base_high = 0 - # Set up TSS descriptor in GDT entries 5-6 (selector 0x28) - setTSS64(5, t.CUInt64T(c.Addr(tss_buf)), 103) - c.Asm("""lea rax, [rip + gdt] - lea rcx, [rip + gp] - mov word ptr [rcx], 0x37 - mov qword ptr [rcx+2], rax""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, t.ASM_DESCR.CLOBBER_RCX]) - c.Asm("sfence; mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - flush() - # Initialize TSS: set iomap_base = 104 (0x68) at offset 102 - tss_buf[102] = 0x68 - tss_buf[103] = 0x00 - # Load Task Register with TSS selector 0x28 - c.Asm("""mov ax, 0x28 - ltr ax""", - op=[t.ASM_DESCR.CLOBBER_RAX]) - -@c.Attribute(t.attr.naked) -def flush(): - c.Asm("""lea rax, [rip + gp] - lgdt [rax] - push 0x08 - lea rax, [rip+2f] - push rax - .byte 0x48, 0xcb - 2: - mov eax, 0x10 - mov ds, eax - mov es, eax - mov fs, eax - mov gs, eax - mov ss, eax - ret""", op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX]) - -def set_tss_rsp0(rsp0: t.CUInt64T): - global tss_buf - # TSS RSP0 is at offset 4 (8 bytes) in x86_64 TSS layout - tss_buf[4] = t.CUInt8T(rsp0 & 0xFF) - tss_buf[5] = t.CUInt8T((rsp0 >> 8) & 0xFF) - tss_buf[6] = t.CUInt8T((rsp0 >> 16) & 0xFF) - tss_buf[7] = t.CUInt8T((rsp0 >> 24) & 0xFF) - tss_buf[8] = t.CUInt8T((rsp0 >> 32) & 0xFF) - tss_buf[9] = t.CUInt8T((rsp0 >> 40) & 0xFF) - tss_buf[10] = t.CUInt8T((rsp0 >> 48) & 0xFF) - tss_buf[11] = t.CUInt8T((rsp0 >> 56) & 0xFF) - -def setGate(num: int, base: t.CUInt64T, limit: t.CUInt32T, access: t.CUInt8T, gran: t.CUInt8T): - global gdt - gdt[num].limit_low = (limit & 0xFFFF) - gdt[num].base_low = (base & 0xFFFF) - gdt[num].base_middle = (base >> 16) & 0xFF - gdt[num].base_high = (base >> 24) & 0xFF - gdt[num].granularity = ((limit >> 16) & 0x0F) | (gran & 0xF0) - gdt[num].access = access - -def setTSS64(num: int, base: t.CUInt64T, limit: t.CUInt32T): - global gdt - gdt[num].limit_low = limit & 0xFFFF - gdt[num].base_low = base & 0xFFFF - gdt[num].base_middle = (base >> 16) & 0xFF - gdt[num].access = 0x89 - gdt[num].granularity = 0x00 - gdt[num].base_high = (base >> 24) & 0xFF - gdt[num + 1].limit_low = (base >> 32) & 0xFFFF - gdt[num + 1].base_low = (base >> 48) & 0xFFFF - gdt[num + 1].base_middle = 0 - gdt[num + 1].access = 0 - gdt[num + 1].granularity = 0 - gdt[num + 1].base_high = 0 diff --git a/Test/Kernel/intr/idt.vp b/Test/Kernel/intr/idt.vp deleted file mode 100644 index 416bca49..00000000 --- a/Test/Kernel/intr/idt.vp +++ /dev/null @@ -1,415 +0,0 @@ -import platform.pch.pic as pic -import platform.pch.timer as timer -import sched.sched as sched -import drivers.serial.uart.serial as serial -import viperlib -import asm -import t, c - -CODE_SEG: t.CDefine | t.CUInt16T = 0x08 - -@c.Attribute(t.attr.packed) -class idt_entry: - base_low: t.CUInt16T - selector: t.CUInt16T - ist_attr: t.CUInt8T - type_attr: t.CUInt8T - base_middle: t.CUInt16T - base_high: t.CUInt32T - reserved1: t.CUInt32T -idt: t.CArray[idt_entry, 256] = [] - -irq_handler_t: t.CTypedef = t.Callable[[], t.CInt] - -def isr0() -> t.State: pass -def isr1() -> t.State: pass -def isr2() -> t.State: pass -def isr3() -> t.State: pass -def isr4() -> t.State: pass -def isr5() -> t.State: pass -def isr6() -> t.State: pass -def isr7() -> t.State: pass -def isr8() -> t.State: pass -def isr9() -> t.State: pass -def isr10() -> t.State: pass -def isr11() -> t.State: pass -def isr12() -> t.State: pass -def isr13() -> t.State: pass -def isr14() -> t.State: pass -def isr15() -> t.State: pass -def isr16() -> t.State: pass -def isr17() -> t.State: pass -def isr18() -> t.State: pass -def isr19() -> t.State: pass -def isr20() -> t.State: pass -def isr21() -> t.State: pass -def isr22() -> t.State: pass -def isr23() -> t.State: pass -def isr24() -> t.State: pass -def isr25() -> t.State: pass -def isr26() -> t.State: pass -def isr27() -> t.State: pass -def isr28() -> t.State: pass -def isr29() -> t.State: pass -def isr30() -> t.State: pass -def isr31() -> t.State: pass -def isr32() -> t.State: pass -def isr33() -> t.State: pass -def isr34() -> t.State: pass -def isr35() -> t.State: pass -def isr36() -> t.State: pass -def isr37() -> t.State: pass -def isr38() -> t.State: pass -def isr39() -> t.State: pass -def isr40() -> t.State: pass -def isr41() -> t.State: pass -def isr42() -> t.State: pass -def isr43() -> t.State: pass -def isr44() -> t.State: pass -def isr45() -> t.State: pass -def isr46() -> t.State: pass -def isr47() -> t.State: pass - -def isr80() -> t.State: pass - -def isr_default() -> t.State: pass - -def setGate(num: int, base: t.CUInt64T, sel: t.CUInt16T, flags: t.CUInt8T): - global idt - idt[num].base_low = (base & 0xFFFF) - idt[num].base_middle = (base >> 16) & 0xFFFF - idt[num].base_high = (base >> 32) & 0xFFFFFFFF - idt[num].selector = sel - idt[num].ist_attr = 0 - idt[num].type_attr = flags - idt[num].reserved1 = 0 - -def isrCommonhandler(interrupt: t.CInt): - c.Asm(f"""mov dx, 0x3F8 - mov al, 91 - out dx, al - mov ecx, {c.AsmInp(interrupt, t.ASM_DESCR.REG_ANY)} - mov rax, rcx - shr rax, 4 - and al, 15 - add al, 48 - cmp al, 57 - jle 1f - add al, 7 - 1: - out dx, al - mov rax, rcx - and al, 15 - add al, 48 - cmp al, 57 - jle 2f - add al, 7 - 2: - out dx, al - mov al, 93 - out dx, al""", - op=[t.ASM_DESCR.CLOBBER_RAX, t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX]) - # Print CR2 for page faults (ISR 14) - if interrupt == 14: - cr2: t.CUInt64T = 0 - c.Asm(f"""mov {c.AsmOut(cr2, t.ASM_DESCR.OUTPUT_REG)}, cr2""", - op=[t.ASM_DESCR.CLOBBER_RAX]) - fault_rip: t.CUInt64T = 0 - fault_err: t.CUInt64T = 0 - c.Asm(f"""mov {c.AsmOut(fault_rip, t.ASM_DESCR.OUTPUT_REG)}, [_fault_rip] - mov {c.AsmOut(fault_err, t.ASM_DESCR.OUTPUT_REG)}, [_fault_err]""", - op=[t.ASM_DESCR.CLOBBER_RAX]) - buf: t.CArray[t.CChar, 80] - viperlib.snprintf(c.Addr(buf), 80, "[PF] cr2=0x%lx rip=0x%lx err=0x%lx\n", cr2, fault_rip, fault_err) - serial.puts(buf) - elif interrupt == 13: - gp_rip: t.CUInt64T = 0 - gp_err: t.CUInt64T = 0 - c.Asm(f"""mov {c.AsmOut(gp_rip, t.ASM_DESCR.OUTPUT_REG)}, [_fault_rip] - mov {c.AsmOut(gp_err, t.ASM_DESCR.OUTPUT_REG)}, [_fault_err]""", - op=[t.ASM_DESCR.CLOBBER_RAX]) - gp_buf: t.CArray[t.CChar, 80] - viperlib.snprintf(c.Addr(gp_buf), 80, "[GP] rip=0x%lx err=0x%lx\n", gp_rip, gp_err) - serial.puts(gp_buf) - s: sched.Scheduler | t.CPtr = sched._sched_ptr - # 如果调度器未初始化,直接进入安全停机状态 - if s == 0: - serial.puts(" KERNEL PANIC (sched not init)\n") - while True: - asm.sti() - asm.hlt() - tid: t.CInt = s.current_tid - if tid == 0: - serial.puts(" KERNEL PANIC\n") - while True: - asm.sti() - asm.hlt() - buf2: t.CArray[t.CChar, 64] - viperlib.snprintf(c.Addr(buf2), 64, " exc in tid=%d, terminating\n", tid) - serial.puts(buf2) - s.threads[tid].state = 3 - # Restore GS to kernel-normal state before _yield(). - # ISR entry does swapgs for user-mode exceptions (GS_BASE=&_per_cpu). - # Since _yield() switches to another thread and never returns via ISR exit, - # the swapgs at ISR exit is never executed. We must swap back here. - # Check IA32_GS_BASE (MSR 0xC0000101): if non-zero, swapgs was done at entry. - c.Asm(f"""mov ecx, 0xC0000101 - rdmsr - shl rdx, 32 - or rax, rdx - test rax, rax - jz 1f - swapgs - 1:""", - op=[t.ASM_DESCR.CLOBBER_RAX, t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX]) - sched.Scheduler._yield() - while True: - asm.sti() - asm.hlt() - -def isr0_handler() -> t.CExport | t.CVoid: isrCommonhandler(0) -def isr1_handler() -> t.CExport | t.CVoid: isrCommonhandler(1) -def isr2_handler() -> t.CExport | t.CVoid: isrCommonhandler(2) -def isr3_handler() -> t.CExport | t.CVoid: isrCommonhandler(3) -def isr4_handler() -> t.CExport | t.CVoid: isrCommonhandler(4) -def isr5_handler() -> t.CExport | t.CVoid: isrCommonhandler(5) -def isr6_handler() -> t.CExport | t.CVoid: isrCommonhandler(6) -def isr7_handler() -> t.CExport | t.CVoid: isrCommonhandler(7) -def isr8_handler() -> t.CExport | t.CVoid: isrCommonhandler(8) -def isr9_handler() -> t.CExport | t.CVoid: isrCommonhandler(9) -def isr10_handler() -> t.CExport | t.CVoid: isrCommonhandler(10) -def isr11_handler() -> t.CExport | t.CVoid: isrCommonhandler(11) -def isr12_handler() -> t.CExport | t.CVoid: isrCommonhandler(12) -def isr13_handler() -> t.CExport | t.CVoid: - isrCommonhandler(13) -def isr14_handler() -> t.CExport | t.CVoid: isrCommonhandler(14) -def isr15_handler() -> t.CExport | t.CVoid: isrCommonhandler(15) -def isr16_handler() -> t.CExport | t.CVoid: isrCommonhandler(16) -def isr17_handler() -> t.CExport | t.CVoid: isrCommonhandler(17) -def isr18_handler() -> t.CExport | t.CVoid: isrCommonhandler(18) -def isr19_handler() -> t.CExport | t.CVoid: isrCommonhandler(19) -def isr20_handler() -> t.CExport | t.CVoid: isrCommonhandler(20) -def isr21_handler() -> t.CExport | t.CVoid: isrCommonhandler(21) -def isr22_handler() -> t.CExport | t.CVoid: isrCommonhandler(22) -def isr23_handler() -> t.CExport | t.CVoid: isrCommonhandler(23) -def isr24_handler() -> t.CExport | t.CVoid: isrCommonhandler(24) -def isr25_handler() -> t.CExport | t.CVoid: isrCommonhandler(25) -def isr26_handler() -> t.CExport | t.CVoid: isrCommonhandler(26) -def isr27_handler() -> t.CExport | t.CVoid: isrCommonhandler(27) -def isr28_handler() -> t.CExport | t.CVoid: isrCommonhandler(28) -def isr29_handler() -> t.CExport | t.CVoid: isrCommonhandler(29) -def isr30_handler() -> t.CExport | t.CVoid: isrCommonhandler(30) -def isr31_handler() -> t.CExport | t.CVoid: isrCommonhandler(31) -def isr32_handler() -> t.CExport | t.CVoid: - timer.timer_handler() - -def isr33_handler() -> t.CExport | t.CVoid: - handler: irq_handler_t = irqGetHandler(1) - if handler: - c.Asm(f"""call {c.AsmInp(handler, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11]) - pic.eoi(1) - -def isr34_handler() -> t.CExport | t.CVoid: - handler2: irq_handler_t = irqGetHandler(2) - if handler2: - c.Asm(f"""call {c.AsmInp(handler2, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11]) - pic.eoi(2) - -def isr35_handler() -> t.CExport | t.CVoid: - handler3: irq_handler_t = irqGetHandler(3) - if handler3: - c.Asm(f"""call {c.AsmInp(handler3, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11]) - pic.eoi(3) - -def isr36_handler() -> t.CExport | t.CVoid: - handler4: irq_handler_t = irqGetHandler(4) - if handler4: - c.Asm(f"""call {c.AsmInp(handler4, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11]) - pic.eoi(4) - -def isr37_handler() -> t.CExport | t.CVoid: - handler5: irq_handler_t = irqGetHandler(5) - if handler5: - c.Asm(f"""call {c.AsmInp(handler5, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11]) - pic.eoi(5) - -def isr38_handler() -> t.CExport | t.CVoid: - handler6: irq_handler_t = irqGetHandler(6) - if handler6: - c.Asm(f"""call {c.AsmInp(handler6, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11]) - pic.eoi(6) - -def isr39_handler() -> t.CExport | t.CVoid: - if pic.isSpurious(7): - return - handler7: irq_handler_t = irqGetHandler(7) - if handler7: - c.Asm(f"""call {c.AsmInp(handler7, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11]) - pic.eoi(7) - -def isr40_handler() -> t.CExport | t.CVoid: - handler8: irq_handler_t = irqGetHandler(8) - if handler8: - c.Asm(f"""call {c.AsmInp(handler8, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11]) - pic.eoi(8) - -def isr41_handler() -> t.CExport | t.CVoid: - handler9: irq_handler_t = irqGetHandler(9) - if handler9: - c.Asm(f"""call {c.AsmInp(handler9, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11]) - pic.eoi(9) - -def isr42_handler() -> t.CExport | t.CVoid: - handler10: irq_handler_t = irqGetHandler(10) - if handler10: - c.Asm(f"""call {c.AsmInp(handler10, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11]) - pic.eoi(10) - -def isr43_handler() -> t.CExport | t.CVoid: - handler11: irq_handler_t = irqGetHandler(11) - if handler11: - c.Asm(f"""call {c.AsmInp(handler11, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11]) - pic.eoi(11) -def isr44_handler() -> t.CExport | t.CVoid: - handler: irq_handler_t = irqGetHandler(12) - if handler: - c.Asm(f"""call {c.AsmInp(handler, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11]) - pic.eoi(12) - -def isr45_handler() -> t.CExport | t.CVoid: pic.eoi(13) -def isr46_handler() -> t.CExport | t.CVoid: pic.eoi(14) - -def isr47_handler() -> t.CExport | t.CVoid: - if pic.isSpurious(15): - return - pic.eoi(15) - -def init_exceptions(): - setGate(0, t.CUInt64T(isr0), CODE_SEG, 0x8E) - setGate(1, t.CUInt64T(isr1), CODE_SEG, 0x8E) - setGate(2, t.CUInt64T(isr2), CODE_SEG, 0x8E) - setGate(3, t.CUInt64T(isr3), CODE_SEG, 0x8E) - setGate(4, t.CUInt64T(isr4), CODE_SEG, 0x8E) - setGate(5, t.CUInt64T(isr5), CODE_SEG, 0x8E) - setGate(6, t.CUInt64T(isr6), CODE_SEG, 0x8E) - setGate(7, t.CUInt64T(isr7), CODE_SEG, 0x8E) - setGate(8, t.CUInt64T(isr8), CODE_SEG, 0x8E) - setGate(9, t.CUInt64T(isr9), CODE_SEG, 0x8E) - setGate(10, t.CUInt64T(isr10), CODE_SEG, 0x8E) - setGate(11, t.CUInt64T(isr11), CODE_SEG, 0x8E) - setGate(12, t.CUInt64T(isr12), CODE_SEG, 0x8E) - setGate(13, t.CUInt64T(isr13), CODE_SEG, 0x8E) - setGate(14, t.CUInt64T(isr14), CODE_SEG, 0x8E) - setGate(15, t.CUInt64T(isr15), CODE_SEG, 0x8E) - setGate(16, t.CUInt64T(isr16), CODE_SEG, 0x8E) - setGate(17, t.CUInt64T(isr17), CODE_SEG, 0x8E) - setGate(18, t.CUInt64T(isr18), CODE_SEG, 0x8E) - setGate(19, t.CUInt64T(isr19), CODE_SEG, 0x8E) - setGate(20, t.CUInt64T(isr20), CODE_SEG, 0x8E) - setGate(21, t.CUInt64T(isr21), CODE_SEG, 0x8E) - setGate(22, t.CUInt64T(isr22), CODE_SEG, 0x8E) - setGate(23, t.CUInt64T(isr23), CODE_SEG, 0x8E) - setGate(24, t.CUInt64T(isr24), CODE_SEG, 0x8E) - setGate(25, t.CUInt64T(isr25), CODE_SEG, 0x8E) - setGate(26, t.CUInt64T(isr26), CODE_SEG, 0x8E) - setGate(27, t.CUInt64T(isr27), CODE_SEG, 0x8E) - setGate(28, t.CUInt64T(isr28), CODE_SEG, 0x8E) - setGate(29, t.CUInt64T(isr29), CODE_SEG, 0x8E) - setGate(30, t.CUInt64T(isr30), CODE_SEG, 0x8E) - setGate(31, t.CUInt64T(isr31), CODE_SEG, 0x8E) - -def init_irqs(): - setGate(32, t.CUInt64T(isr32), CODE_SEG, 0x8E) - setGate(33, t.CUInt64T(isr33), CODE_SEG, 0x8E) - setGate(34, t.CUInt64T(isr34), CODE_SEG, 0x8E) - setGate(35, t.CUInt64T(isr35), CODE_SEG, 0x8E) - setGate(36, t.CUInt64T(isr36), CODE_SEG, 0x8E) - setGate(37, t.CUInt64T(isr37), CODE_SEG, 0x8E) - setGate(38, t.CUInt64T(isr38), CODE_SEG, 0x8E) - setGate(39, t.CUInt64T(isr39), CODE_SEG, 0x8E) - setGate(40, t.CUInt64T(isr40), CODE_SEG, 0x8E) - setGate(41, t.CUInt64T(isr41), CODE_SEG, 0x8E) - setGate(42, t.CUInt64T(isr42), CODE_SEG, 0x8E) - setGate(43, t.CUInt64T(isr43), CODE_SEG, 0x8E) - setGate(44, t.CUInt64T(isr44), CODE_SEG, 0x8E) - setGate(45, t.CUInt64T(isr45), CODE_SEG, 0x8E) - setGate(46, t.CUInt64T(isr46), CODE_SEG, 0x8E) - setGate(47, t.CUInt64T(isr47), CODE_SEG, 0x8E) - -irq_handlers: t.CStatic | t.CArray[irq_handler_t, 16] = [None] - -def irqInstallHandler(irq: t.CInt, handler: irq_handler_t, name: str) -> t.CInt: - global irq_handlers - if irq < 0 or irq > 15: return -1 - irq_handlers[irq] = handler - return 0 - -def irqGetHandler(irq: t.CInt) -> irq_handler_t: - if irq < 0 or irq > 15: return None - return irq_handlers[irq] - -def init(): - global idt - for i in range(256): - setGate(i, t.CUInt64T(isr_default), CODE_SEG, 0x8E) - pic.init() - init_exceptions() - init_irqs() - # Register ISR 0x80 for int 0x80 syscall interface (user-mode ELF apps) - setGate(0x80, t.CUInt64T(isr80), CODE_SEG, 0xEE) # DPL=3 allows Ring 3 to call int 0x80 - # Build idt_ptr on stack and load directly in one asm block - c.Asm("""lea rax, [rip + idt] - sub rsp, 16 - mov word ptr [rsp], 0x0fff - mov qword ptr [rsp+2], rax - lidt [rsp] - add rsp, 16""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX]) diff --git a/Test/Kernel/intr/isr.s b/Test/Kernel/intr/isr.s deleted file mode 100644 index c03757f7..00000000 --- a/Test/Kernel/intr/isr.s +++ /dev/null @@ -1,595 +0,0 @@ -.section .bss -.comm _per_cpu, 32, 8 -.comm _proc_mgr, 8192, 16 -.comm _proc_mgr_ptr, 8, 8 -.comm _saved_cr3, 8, 8 -.comm _yield_cnt, 4, 4 -.comm _yield_lock, 4, 4 -.comm _fs_lock, 4, 4 -.comm _fault_rip, 8, 8 -.comm _fault_err, 8, 8 - -.section .text -.intel_syntax noprefix - -.globl isr_default -isr_default: - push rax - push rdx - mov al, 0x20 - out 0xA0, al - out 0x20, al - pop rdx - pop rax - iretq - -# ============================================================================= -# ISR macros with Ring 3 support -# -# When CPU takes interrupt/exception: -# From Ring 0: pushes RFLAGS, CS, RIP (3 qwords) -# From Ring 3: pushes SS, RSP, RFLAGS, CS, RIP (5 qwords) -# CPU also switches to TSS RSP0 stack when coming from Ring 3. -# -# Strategy: -# 1. Check CS RPL to determine if from Ring 3 -# 2. If from Ring 3: swapgs (make gs: point to per_cpu), save user RSP -# 3. Save full interrupt frame into registers -# 4. Re-push in uniform format with is_user flag -# 5. Call handler -# 6. On return, rebuild correct iretq frame based on is_user -# 7. If returning to Ring 3: swapgs back -# ============================================================================= - -.macro ISR_NOERR num -.globl isr\num -isr\num: - # Check CS RPL to determine if from Ring 3 - mov rax, [rsp + 8] # CS from interrupt frame - test al, 3 # RPL bits: 0 = Ring 0, 3 = Ring 3 - jnz isr\num\()_from_user - -isr\num\()_from_kernel: - # From Ring 0: no swapgs needed, already on kernel stack - mov r8, [rsp] # RIP - mov r9, [rsp + 8] # CS - mov r10, [rsp + 16] # RFLAGS - xor r11, r11 # SS = 0 - xor rax, rax # RSP = 0 - add rsp, 24 # remove the 3 CPU-pushed qwords - jmp isr\num\()_frame_ready - -isr\num\()_from_user: - # From Ring 3: swapgs to make gs: accessible, CPU already switched to TSS RSP0 - swapgs - # Save user RSP to per_cpu.user_rsp (gs:[0x0]) - # Note: CPU has already switched RSP to TSS RSP0, so the user RSP is on this stack - mov r8, [rsp] # RIP - mov r9, [rsp + 8] # CS - mov r10, [rsp + 16] # RFLAGS - mov rax, [rsp + 24] # RSP (user) - mov r11, [rsp + 32] # SS (user) - # Save user RSP to per_cpu for potential later use - mov gs:[0x0], rax - add rsp, 40 # remove the 5 CPU-pushed qwords - -isr\num\()_frame_ready: - # r8=RIP, r9=CS, r10=RFLAGS, rax=RSP(0 if kernel), r11=SS(0 if kernel) - # Build uniform frame on stack for iretq later - push r11 # SS - push rax # RSP - push r10 # RFLAGS - push r9 # CS - push r8 # RIP - - # Push is_user flag (1 if from Ring 3, 0 if from Ring 0) - xor ecx, ecx - test r9b, 3 # test CS RPL - setnz cl # cl = 1 if from Ring 3 - push rcx # is_user - - # Push all general-purpose registers - push rax - push rbx - push rdx - push rsi - push rdi - push rbp - push r8 - push r9 - push r10 - push r11 - push r12 - push r13 - push r14 - push r15 - # Save faulting RIP and error code for debug - mov [_fault_rip], r8 - mov [_fault_err], rdx - call isr\num\()_handler - pop r15 - pop r14 - pop r13 - pop r12 - pop r11 - pop r10 - pop r9 - pop r8 - pop rbp - pop rdi - pop rsi - pop rdx - pop rbx - pop rax - - # Pop is_user flag - pop rcx # is_user - - # Pop the uniform frame into registers - pop r8 # RIP - pop r9 # CS - pop r10 # RFLAGS - pop rax # RSP (user) - pop r11 # SS (user) - - test rcx, rcx - jnz isr\num\()_ret_user - -isr\num\()_ret_kernel: - # Return to Ring 0: push RFLAGS, CS, RIP only - push r10 # RFLAGS - push r9 # CS - push r8 # RIP - iretq - -isr\num\()_ret_user: - # Return to Ring 3: swapgs back, then push SS, RSP, RFLAGS, CS, RIP - swapgs - # DIAG+FIX: if RFLAGS.NT (bit 14) is set, iretq performs hardware task-return - # which loads TSS selector 0x28 -> #GP(err=0x28). Detect and clear it. - test r10, 0x4000 - jz 1f - btr r10, 14 - mov dx, 0x3F8 - mov al, 0x4E # 'N' marker = NT was set (now cleared) - out dx, al -1: - cmp r9, 0x1B - jne 8f - cmp r11, 0x23 - jne 8f - push r11 # SS - push rax # RSP - push r10 # RFLAGS - push r9 # CS - push r8 # RIP - iretq -8: - mov dx, 0x3F8 - mov al, 0x42 # 'B' = bad CS/SS - out dx, al - mov al, 0x20 # space - out dx, al - # Output CS (r9) low byte as 2 hex digits - mov rcx, r9 - mov rax, rcx - shr rax, 4 - and rax, 0xF - add al, 0x30 - cmp al, 0x39 - jle 2f - add al, 7 -2: - out dx, al - mov rax, rcx - and rax, 0xF - add al, 0x30 - cmp al, 0x39 - jle 3f - add al, 7 -3: - out dx, al - mov al, 0x20 # space - out dx, al - # Output SS (r11) low byte as 2 hex digits - mov rcx, r11 - mov rax, rcx - shr rax, 4 - and rax, 0xF - add al, 0x30 - cmp al, 0x39 - jle 4f - add al, 7 -4: - out dx, al - mov rax, rcx - and rax, 0xF - add al, 0x30 - cmp al, 0x39 - jle 5f - add al, 7 -5: - out dx, al - mov al, 0x0A # newline - out dx, al - cli -7: - hlt - jmp 7b -.endm - -.macro ISR_ERR num -.globl isr\num -isr\num: - # Stack at entry (with error code): - # From Ring 0: [rsp]=error_code, [rsp+8]=RIP, [rsp+16]=CS, [rsp+24]=RFLAGS - # From Ring 3: [rsp]=error_code, [rsp+8]=RIP, [rsp+16]=CS, [rsp+24]=RFLAGS, [rsp+32]=RSP, [rsp+40]=SS - - # Check CS RPL - mov rax, [rsp + 16] # CS from interrupt frame - test al, 3 - jnz isr\num\()_from_user - -isr\num\()_from_kernel: - # From Ring 0: no swapgs needed - mov rdx, [rsp] # error_code - mov r8, [rsp + 8] # RIP - mov r9, [rsp + 16] # CS - mov r10, [rsp + 24] # RFLAGS - xor r11, r11 # SS = 0 - xor rax, rax # RSP = 0 - add rsp, 32 # remove 4 CPU-pushed qwords (error + 3 frame) - jmp isr\num\()_frame_ready - -isr\num\()_from_user: - # From Ring 3: swapgs, CPU already on TSS RSP0 - swapgs - mov rdx, [rsp] # error_code - mov r8, [rsp + 8] # RIP - mov r9, [rsp + 16] # CS - mov r10, [rsp + 24] # RFLAGS - mov rax, [rsp + 32] # RSP (user) - mov r11, [rsp + 40] # SS (user) - mov gs:[0x0], rax # save user RSP - add rsp, 48 # remove 6 CPU-pushed qwords (error + 5 frame) - -isr\num\()_frame_ready: - # rdx=error_code, r8=RIP, r9=CS, r10=RFLAGS, rax=RSP, r11=SS - # Build uniform frame on stack - push r11 # SS - push rax # RSP - push r10 # RFLAGS - push r9 # CS - push r8 # RIP - push rdx # error_code - - # Push is_user flag - xor ecx, ecx - test r9b, 3 - setnz cl - push rcx # is_user - - # Push all general-purpose registers - push rax - push rbx - push rsi - push rdi - push rbp - push r8 - push r9 - push r10 - push r11 - push r12 - push r13 - push r14 - push r15 - # Save faulting RIP and error code for debug - mov [_fault_rip], r8 - mov [_fault_err], rdx - call isr\num\()_handler - pop r15 - pop r14 - pop r13 - pop r12 - pop r11 - pop r10 - pop r9 - pop r8 - pop rbp - pop rdi - pop rsi - pop rbx - pop rax - - # Pop is_user flag - pop rcx # is_user - add rsp, 8 # skip error_code (handler already consumed it) - pop r8 # RIP - pop r9 # CS - pop r10 # RFLAGS - pop rax # RSP (user) - pop r11 # SS (user) - - test rcx, rcx - jnz isr\num\()_ret_user - -isr\num\()_ret_kernel: - push r10 # RFLAGS - push r9 # CS - push r8 # RIP - iretq - -isr\num\()_ret_user: - swapgs - push r11 # SS - push rax # RSP - push r10 # RFLAGS - push r9 # CS - push r8 # RIP - iretq -.endm - -ISR_NOERR 0 -ISR_NOERR 1 -ISR_NOERR 2 -ISR_NOERR 3 -ISR_NOERR 4 -ISR_NOERR 5 -ISR_NOERR 6 -ISR_NOERR 7 -ISR_ERR 8 -ISR_NOERR 9 -ISR_ERR 10 -ISR_ERR 11 -ISR_ERR 12 -ISR_ERR 13 -ISR_ERR 14 -ISR_NOERR 15 -ISR_NOERR 16 -ISR_ERR 17 -ISR_NOERR 18 -ISR_NOERR 19 -ISR_NOERR 20 -ISR_NOERR 21 -ISR_NOERR 22 -ISR_NOERR 23 -ISR_NOERR 24 -ISR_NOERR 25 -ISR_NOERR 26 -ISR_NOERR 27 -ISR_NOERR 28 -ISR_NOERR 29 -ISR_NOERR 30 -ISR_NOERR 31 -ISR_NOERR 32 -ISR_NOERR 33 -ISR_NOERR 34 -ISR_NOERR 35 -ISR_NOERR 36 -ISR_NOERR 37 -ISR_NOERR 38 -ISR_NOERR 39 -ISR_NOERR 40 -ISR_NOERR 41 -ISR_NOERR 42 -ISR_NOERR 43 -ISR_NOERR 44 -ISR_NOERR 45 -ISR_NOERR 46 -ISR_NOERR 47 - -.globl syscall_entry -syscall_entry: - mov rax, rsp - shr rax, 47 - test rax, rax - jnz syscall_from_kernel -syscall_from_user: - swapgs - mov gs:[0x0], rsp - mov rsp, gs:[0x8] - jmp syscall_common -syscall_from_kernel: -syscall_common: - push rcx - push r11 - push rbx - push rdx - push rsi - push rdi - push rbp - push r8 - push r9 - push r10 - push r12 - push r13 - push r14 - push r15 - mov rbp, rsp - and rsp, ~15 - push r9 - mov r9, r8 - mov r8, r10 - mov rcx, rdx - mov rdx, rsi - mov rsi, rdi - mov rdi, rax - call syscall_handler - add rsp, 8 - mov rsp, rbp - pop r15 - pop r14 - pop r13 - pop r12 - pop r10 - pop r9 - pop r8 - pop rbp - pop rdi - pop rsi - pop rdx - pop rbx - pop r11 - pop rcx - mov rax, rcx - shr rax, 47 - test rax, rax - jnz syscall_ret_kernel -syscall_ret_user: - mov rsp, gs:[0x0] - swapgs - push r11 - popfq - sysretq -syscall_ret_kernel: - push r11 - popfq - jmp rcx - -# ============================================================================= -# ISR 0x80 - int 0x80 syscall handler for user-mode ELF apps -# -# int 0x80 calling convention (ViperOS): -# rax = syscall number -# rbx = arg1 -# rcx = arg2 -# rdx = arg3 -# r10 = arg4 -# -# Translated to syscall_handler calling convention: -# rdi = n (syscall number) -# rsi = arg1 -# rdx = arg2 -# rcx = arg3 -# r8 = arg4 -# r9 = arg5 (0) -# stack = arg6 (0) -# -# Return value in rax. -# ============================================================================= -.globl isr80 -isr80: - # Check CS RPL to determine if from Ring 3 - mov rax, [rsp + 8] # CS from interrupt frame - test al, 3 - jnz isr80_from_user - -isr80_from_kernel: - mov r8, [rsp] # RIP - mov r9, [rsp + 8] # CS - mov r10, [rsp + 16] # RFLAGS - xor r11, r11 # SS = 0 - xor rax, rax # RSP = 0 - add rsp, 24 - jmp isr80_frame_ready - -isr80_from_user: - swapgs - mov r8, [rsp] # RIP - mov r9, [rsp + 8] # CS - mov r10, [rsp + 16] # RFLAGS - mov rax, [rsp + 24] # RSP (user) - mov r11, [rsp + 32] # SS (user) - mov gs:[0x0], rax - add rsp, 40 - -isr80_frame_ready: - # Build uniform frame on stack - push r11 # SS - push rax # RSP - push r10 # RFLAGS - push r9 # CS - push r8 # RIP - - # Save ALL registers FIRST (including original rcx = arg2) - # Order: rax, rbx, rcx, rdx, rsi, rdi, rbp, r8, r9, r10, r11, r12, r13, r14, r15 - push rax # [rsp+112] rax (syscall number) - push rbx # [rsp+104] rbx (arg1) - push rcx # [rsp+96] rcx (arg2) - push rdx # [rsp+88] rdx (arg3) - push rsi # [rsp+80] - push rdi # [rsp+72] - push rbp # [rsp+64] - push r8 # [rsp+56] - push r9 # [rsp+48] - push r10 # [rsp+40] r10 (arg4) - push r11 # [rsp+32] - push r12 # [rsp+24] - push r13 # [rsp+16] - push r14 # [rsp+8] - push r15 # [rsp+0] - - # Calculate is_user from saved CS on stack - # CS is at [rsp + 15*8 + 16] = [rsp + 136] - mov rax, [rsp + 136] # CS from frame - xor ecx, ecx - test al, 3 - setnz cl - push rcx # is_user (pushed AFTER all registers) - - # Stack layout now: - # [rsp+0] = is_user - # [rsp+8] = r15 [rsp+16] = r14 [rsp+24] = r13 [rsp+32] = r12 - # [rsp+40] = r11 [rsp+48] = r10 [rsp+56] = r9 [rsp+64] = r8 - # [rsp+72] = rbp [rsp+80] = rdi [rsp+88] = rsi [rsp+96] = rdx - # [rsp+104] = rcx [rsp+112] = rbx [rsp+120] = rax - - # Translate int 0x80 calling convention to syscall_handler convention - mov rdi, [rsp + 120] # original rax = syscall number -> rdi - mov rsi, [rsp + 112] # original rbx = arg1 -> rsi - mov rdx, [rsp + 104] # original rcx = arg2 -> rdx - mov rcx, [rsp + 96] # original rdx = arg3 -> rcx - mov r8, [rsp + 48] # original r10 = arg4 -> r8 - xor r9, r9 # arg5 = 0 - push 0 # arg6 = 0 (on stack) - - call syscall_handler - - add rsp, 8 # remove arg6 - # Save return value by overwriting saved rax on stack - mov [rsp + 120], rax - - # Pop is_user flag - pop rcx # is_user - - # Restore registers - pop r15 - pop r14 - pop r13 - pop r12 - pop r11 - pop r10 - pop r9 - pop r8 - pop rbp - pop rdi - pop rsi - pop rdx - pop rcx # restore original rcx (arg2) - pop rbx - pop rax # now has the return value - - # Pop frame - pop r8 # RIP - pop r9 # CS - pop r10 # RFLAGS - pop rax # RSP (user) - pop r11 # SS (user) - - test rcx, rcx - jnz isr80_ret_user - -isr80_ret_kernel: - push r10 # RFLAGS - push r9 # CS - push r8 # RIP - iretq - -isr80_ret_user: - swapgs - push r11 # SS - push rax # RSP - push r10 # RFLAGS - push r9 # CS - push r8 # RIP - iretq diff --git a/Test/Kernel/intr/syscall.vp b/Test/Kernel/intr/syscall.vp deleted file mode 100644 index d77cd3fa..00000000 --- a/Test/Kernel/intr/syscall.vp +++ /dev/null @@ -1,470 +0,0 @@ -import drivers.serial.uart.serial as serial -import services.desktop as desktop -import drivers.fs.fat32.fat32 as fat32 -import drivers.fs.fat32.fat32_types as fat32_types -import sched.sched as sched -import sched.process as process -import viperlib -import string -import mm.mm as mm -import paging.paging as paging -import execrunner.elf as elf -import t, c - -CREATE_WINDOW: t.CDefine = 1 -DRAW_TEXT: t.CDefine = 2 -EXIT: t.CDefine = 3 -OPEN: t.CDefine = 4 -CLOSE: t.CDefine = 5 -READ: t.CDefine = 6 -WRITE: t.CDefine = 7 -SEEK: t.CDefine = 8 -TELL: t.CDefine = 9 -SIZE: t.CDefine = 10 -MKDIR: t.CDefine = 11 -REMOVE: t.CDefine = 12 -OPENDIR: t.CDefine = 13 -READDIR: t.CDefine = 14 -CLOSEDIR: t.CDefine = 15 -STAT: t.CDefine = 16 -WAIT_WINDOW: t.CDefine = 17 -SERIAL_PUTS: t.CDefine = 18 -LOAD_SO: t.CDefine = 19 -SO_CALL1: t.CDefine = 20 -GET_WINBUF: t.CDefine = 21 -WIN_FLUSH: t.CDefine = 22 -POLL_EVENT: t.CDefine = 23 -SET_CURSOR: t.CDefine = 24 -YIELD: t.CDefine = 25 -SET_TITLE: t.CDefine = 26 -SET_GEOMETRY: t.CDefine = 27 -SPAWN: t.CDefine = 28 -MMAP: t.CDefine = 29 -MUNMAP: t.CDefine = 30 -SET_RESIZABLE: t.CDefine = 31 -GET_WIN_SIZE: t.CDefine = 32 -THREAD_CREATE: t.CDefine = 33 - -IA32_EFER: t.CDefine = 0xC0000080 -IA32_STAR: t.CDefine = 0xC0000081 -IA32_LSTAR: t.CDefine = 0xC0000082 -IA32_FMASK: t.CDefine = 0xC0000084 - -def wrmsr(msr: t.CUInt32T, val: t.CUInt64T): - lo: t.CUInt32T = t.CUInt32T(val & 0xFFFFFFFF) - hi: t.CUInt32T = t.CUInt32T(val >> 32) - c.Asm(f"""mov ecx, {c.AsmInp(msr, t.ASM_DESCR.REG_ANY)} - mov eax, {c.AsmInp(lo, t.ASM_DESCR.REG_ANY)} - mov edx, {c.AsmInp(hi, t.ASM_DESCR.REG_ANY)} - wrmsr""", - op=[t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RAX, t.ASM_DESCR.CLOBBER_RDX]) - -def rdmsr(msr: t.CUInt32T) -> t.CUInt64T: - lo: t.CUInt32T - hi: t.CUInt32T - c.Asm(f"""mov ecx, {c.AsmInp(msr, t.ASM_DESCR.REG_ANY)} - rdmsr""", - out=[c.AsmOut(lo, t.ASM_DESCR.OUTPUT_REG), c.AsmOut(hi, t.ASM_DESCR.OUTPUT_REG)], - op=[t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RAX, t.ASM_DESCR.CLOBBER_RDX]) - return t.CUInt64T(lo) | (t.CUInt64T(hi) << 32) - -def _current_proc() -> process.Process | t.CPtr: - return process.ProcessManager.current() - -def _fd_alloc(p: process.Process | t.CPtr) -> t.CInt: - for i in range(process.PROC_MAX_FDS): - if not p.fd_used[i]: - p.fd_used[i] = 1 - return i - return -1 - -def _fd_free(p: process.Process | t.CPtr, fd: t.CInt): - if fd >= 0 and fd < process.PROC_MAX_FDS: - p.fd_used[fd] = 0 - p.fd_table[fd] = t.CVoid(0, t.CPtr) - -def _dir_alloc(p: process.Process | t.CPtr) -> t.CInt: - for i in range(process.PROC_MAX_DIRS): - if not p.dir_used[i]: - p.dir_used[i] = 1 - return i - return -1 - -def _dir_free(p: process.Process | t.CPtr, dd: t.CInt): - if dd >= 0 and dd < process.PROC_MAX_DIRS: - p.dir_used[dd] = 0 - p.dir_table[dd] = t.CVoid(0, t.CPtr) - -def CREATE_WINDOW(x: t.CInt, y: t.CInt, w: t.CInt, h: t.CInt, title: t.CConst | t.CChar | t.CPtr, style: t.CInt) -> t.CInt: - desktop.set_app_pid(process.current()) - return desktop.create(x, y, w, h, title, style) - -def DRAW_TEXT(win_id: t.CInt, x: t.CInt, y: t.CInt, text: t.CConst | t.CChar | t.CPtr, color: t.CUInt32T) -> t.CInt: - return desktop.draw_text(win_id, x, y, text, color) - -def EXIT(code: t.CInt) -> t.CInt: - serial.puts("[syscall] exit called\n") - desktop.destroy_by_pid(process.current()) - return 0 - -def WAIT_WINDOW(win_id: t.CInt) -> t.CInt: - while desktop.is_active(win_id): - sched.Scheduler.try_reschedule() - return 0 - -def SERIAL_PUTS(str_ptr: t.CVoid | t.CPtr) -> t.CInt: - s: t.CConst | t.CChar | t.CPtr = t.CVoid(str_ptr, t.CPtr) - serial.puts(s) - return 0 - -_loaded_so_base: t.CVoid | t.CPtr = None -_loaded_so_path: t.CArray[t.CChar, 64] - -def LOAD_SO(path_ptr: t.CVoid | t.CPtr) -> t.CUInt64T: - global _loaded_so_base - path: t.CConst | t.CChar | t.CPtr = t.CVoid(path_ptr, t.CPtr) - serial.puts("[so] loading: ") - serial.puts(path) - serial.puts("\n") - base: t.CVoid | t.CPtr = elf.load_so(path) - if base is not None: - _loaded_so_base = base - for i in range(63): - ch: t.CChar = c.Deref(path + i) - _loaded_so_path[i] = ch - if ch == 0: break - _loaded_so_path[63] = 0 - return t.CUInt64T(base) - return 0 - -def SO_CALL1(sym_name_ptr: t.CVoid | t.CPtr, arg1: t.CVoid | t.CPtr) -> t.CInt: - if _loaded_so_base is None: return -1 - sym_name: t.CConst | t.CChar | t.CPtr = t.CVoid(sym_name_ptr, t.CPtr) - fn: t.CVoid | t.CPtr = elf.get_so_symbol(_loaded_so_base, sym_name, c.Addr(_loaded_so_path[0])) - if fn is None: - serial.puts("[so] symbol not found\n") - return -2 - c.Asm(f"""mov rdi, {c.AsmInp(arg1, t.ASM_DESCR.REG_ANY)} - call {c.AsmInp(fn, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_RDI, t.ASM_DESCR.CLOBBER_RSI, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11]) - serial.puts("[so] call returned\n") - return 0 - -def GET_WINBUF(win_id: t.CInt) -> t.CUInt64T: - buf: t.CVoid | t.CPtr = desktop.get_fb(win_id) - if buf is None: - return 0 - return t.CUInt64T(buf) - -def WIN_FLUSH(win_id: t.CInt) -> t.CInt: - desktop.flush(win_id) - return 0 - -def SET_CURSOR(win_id: t.CInt, cursor_t: t.CInt) -> t.CInt: - desktop.set_cursor_type(win_id, cursor_t) - return 0 - -def OPEN(path_ptr: t.CVoid | t.CPtr, mode: t.CUInt32T) -> t.CInt: - p: process.Process | t.CPtr = _current_proc() - path: t.CConst | t.CChar | t.CPtr = t.CVoid(path_ptr, t.CPtr) - fat32.lock() - fp: t.CVoid | t.CPtr = fat32.open(path, t.CUInt8T(mode)) - if not fp: - fat32.unlock() - return -1 - fd: t.CInt = _fd_alloc(p) - if fd < 0: - fat32.close(fp) - fat32.unlock() - return -1 - p.fd_table[fd] = fp - fat32.unlock() - return fd - -def CLOSE(fd: t.CInt) -> t.CInt: - p: process.Process | t.CPtr = _current_proc() - if fd < 0 or fd >= process.PROC_MAX_FDS: - return t.CInt(fat32_types.FRESULT.FR_INVALID_OBJECT) - fp: t.CVoid | t.CPtr = p.fd_table[fd] - if not fp: - return t.CInt(fat32_types.FRESULT.FR_INVALID_OBJECT) - fat32.lock() - res: t.CInt = t.CInt(fat32.close(fp)) - fat32.unlock() - _fd_free(p, fd) - return res - -def READ(fd: t.CInt, buf_ptr: t.CVoid | t.CPtr, count: t.CUInt32T) -> t.CInt: - p: process.Process | t.CPtr = _current_proc() - if fd < 0 or fd >= process.PROC_MAX_FDS: - return -1 - fp: t.CVoid | t.CPtr = p.fd_table[fd] - if not fp: - return -1 - fat32.lock() - br: t.CUInt32T = fat32.read(fp, buf_ptr, count) - fat32.unlock() - return t.CInt(br) - -def WRITE(fd: t.CInt, buf_ptr: t.CVoid | t.CPtr, count: t.CUInt32T) -> t.CInt: - p: process.Process | t.CPtr = _current_proc() - if fd < 0 or fd >= process.PROC_MAX_FDS: - return -1 - fp: t.CVoid | t.CPtr = p.fd_table[fd] - if not fp: - return -1 - fat32.lock() - bw: t.CUInt32T = fat32.write(fp, buf_ptr, count) - fat32.unlock() - return t.CInt(bw) - -def SEEK(fd: t.CInt, offset: t.CUInt32T) -> t.CInt: - p: process.Process | t.CPtr = _current_proc() - if fd < 0 or fd >= process.PROC_MAX_FDS: - return t.CInt(fat32_types.FRESULT.FR_INVALID_OBJECT) - fp: t.CVoid | t.CPtr = p.fd_table[fd] - if not fp: - return t.CInt(fat32_types.FRESULT.FR_INVALID_OBJECT) - fat32.lock() - r: t.CInt = t.CInt(fat32.seek(fp, offset)) - fat32.unlock() - return r - -def TELL(fd: t.CInt) -> t.CUInt32T: - p: process.Process | t.CPtr = _current_proc() - if fd < 0 or fd >= process.PROC_MAX_FDS: - return 0 - fp: t.CVoid | t.CPtr = p.fd_table[fd] - if not fp: - return 0 - fat32.lock() - pos: t.CUInt32T = fat32.tell(fp) - fat32.unlock() - return pos - -def fsize(fd: t.CInt) -> t.CUInt32T: - p: process.Process | t.CPtr = _current_proc() - if fd < 0 or fd >= process.PROC_MAX_FDS: - return 0 - fp: t.CVoid | t.CPtr = p.fd_table[fd] - if not fp: - return 0 - fat32.lock() - sz: t.CUInt32T = fat32.size(fp) - fat32.unlock() - return sz - -def MKDIR(path_ptr: t.CVoid | t.CPtr) -> t.CInt: - path: t.CConst | t.CChar | t.CPtr = t.CVoid(path_ptr, t.CPtr) - fat32.lock() - r: t.CInt = t.CInt(fat32.mkdir(path)) - fat32.unlock() - return r - -def REMOVE(path_ptr: t.CVoid | t.CPtr) -> t.CInt: - path: t.CConst | t.CChar | t.CPtr = t.CVoid(path_ptr, t.CPtr) - fat32.lock() - r: t.CInt = t.CInt(fat32.remove(path)) - fat32.unlock() - return r - -def OPENdir(path_ptr: t.CVoid | t.CPtr) -> t.CInt: - p: process.Process | t.CPtr = _current_proc() - path: t.CConst | t.CChar | t.CPtr = t.CVoid(path_ptr, t.CPtr) - dd: t.CInt = _dir_alloc(p) - if dd < 0: - return -1 - dp: fat32_types.dirobj | t.CPtr = c.Addr(p.dir_pool[dd]) - fat32.lock() - res: t.CInt = t.CInt(fat32.opendir(path, dp)) - fat32.unlock() - if res != 0: - _dir_free(p, dd) - return -1 - p.dir_table[dd] = t.CVoid(t.CUInt64T(dp), t.CPtr) - return dd - -def READdir(dd: t.CInt, info_ptr: t.CVoid | t.CPtr) -> t.CInt: - p: process.Process | t.CPtr = _current_proc() - if dd < 0 or dd >= process.PROC_MAX_DIRS: - return t.CInt(fat32_types.FRESULT.FR_INVALID_OBJECT) - dp: t.CVoid | t.CPtr = p.dir_table[dd] - if not dp: - return t.CInt(fat32_types.FRESULT.FR_INVALID_OBJECT) - info: fat32_types.fileinfo | t.CPtr = info_ptr - fat32.lock() - r: t.CInt = t.CInt(fat32.readdir(dp, info)) - fat32.unlock() - return r - -def CLOSEdir(dd: t.CInt) -> t.CInt: - p: process.Process | t.CPtr = _current_proc() - if dd < 0 or dd >= process.PROC_MAX_DIRS: - return t.CInt(fat32_types.FRESULT.FR_INVALID_OBJECT) - dp: t.CVoid | t.CPtr = p.dir_table[dd] - if not dp: - return t.CInt(fat32_types.FRESULT.FR_INVALID_OBJECT) - fat32.lock() - fat32.closedir(dp) - fat32.unlock() - _dir_free(p, dd) - return 0 - -def STAT(path_ptr: t.CVoid | t.CPtr, info_ptr: t.CVoid | t.CPtr) -> t.CInt: - path: t.CConst | t.CChar | t.CPtr = t.CVoid(path_ptr, t.CPtr) - info: fat32_types.fileinfo | t.CPtr = info_ptr - fat32.lock() - r: t.CInt = t.CInt(fat32.stat(path, info)) - fat32.unlock() - return r - -def SPAWN(path_ptr: t.CVoid | t.CPtr, blocking: t.CInt) -> t.CInt: - path: t.CConst | t.CChar | t.CPtr = t.CVoid(path_ptr, t.CPtr) - pid: t.CInt = elf.spawn_elf(path) - if pid < 0: - return pid - if blocking: - p: process.Process | t.CPtr = process.ProcessManager.get_process(pid) - if p: - while p.state != process.PROC_DONE: - sched.Scheduler.try_reschedule() - return pid - -USER_HEAP_BASE: t.CDefine = 0x20000000 - -def MMAP(size: t.CUInt64T) -> t.CUInt64T: - p: process.Process | t.CPtr = _current_proc() - if size == 0: return 0 - aligned_size: t.CUInt64T = (size + 4095) & ~t.CUInt64T(4095) - if p.heap_start == 0: - p.heap_start = USER_HEAP_BASE - heap_end: t.CUInt64T = p.heap_start + p.heap_size - new_end: t.CUInt64T = heap_end + aligned_size - for va in range(heap_end, new_end, 4096): - phys_page: t.CVoid | t.CPtr = mm.malloc(4096) - if phys_page is None: return 0 - paging.MapPage(va, t.CUInt64T(phys_page), paging.PTE_PRESENT | paging.PTE_WRITABLE | paging.PTE_USER) - p.heap_size = p.heap_size + aligned_size - return heap_end - -def MUNMAP(ptr: t.CUInt64T, size: t.CUInt64T) -> t.CInt: - return 0 - -def syscall_entry() -> t.CExtern | t.CVoid | t.State: pass - -def syscall_handler(num: t.CUInt64T, arg1: t.CUInt64T, arg2: t.CUInt64T, arg3: t.CUInt64T, arg4: t.CUInt64T, arg5: t.CUInt64T, arg6: t.CUInt64T) -> t.CExport | t.CUInt64T: - n: t.CInt = t.CInt(num) - if n == CREATE_WINDOW: - title_ptr: t.CVoid | t.CPtr = t.CVoid(arg5, t.CPtr) - return t.CUInt64T(CREATE_WINDOW(t.CInt(arg1), t.CInt(arg2), t.CInt(arg3), t.CInt(arg4), title_ptr, t.CInt(arg6))) - elif n == DRAW_TEXT: - text_ptr: t.CVoid | t.CPtr = t.CVoid(arg4, t.CPtr) - return t.CUInt64T(DRAW_TEXT(t.CInt(arg1), t.CInt(arg2), t.CInt(arg3), text_ptr, t.CUInt32T(arg5))) - elif n == EXIT: - return t.CUInt64T(EXIT(t.CInt(arg1))) - elif n == OPEN: - path_ptr: t.CVoid | t.CPtr = t.CVoid(arg1, t.CPtr) - return t.CUInt64T(OPEN(path_ptr, t.CUInt32T(arg2))) - elif n == CLOSE: - return t.CUInt64T(CLOSE(t.CInt(arg1))) - elif n == READ: - buf_ptr: t.CVoid | t.CPtr = t.CVoid(arg2, t.CPtr) - return t.CUInt64T(READ(t.CInt(arg1), buf_ptr, t.CUInt32T(arg3))) - elif n == WRITE: - buf_ptr: t.CVoid | t.CPtr = t.CVoid(arg2, t.CPtr) - return t.CUInt64T(WRITE(t.CInt(arg1), buf_ptr, t.CUInt32T(arg3))) - elif n == SEEK: - return t.CUInt64T(SEEK(t.CInt(arg1), t.CUInt32T(arg2))) - elif n == TELL: - return t.CUInt64T(TELL(t.CInt(arg1))) - elif n == SIZE: - return t.CUInt64T(fsize(t.CInt(arg1))) - elif n == MKDIR: - path_ptr: t.CVoid | t.CPtr = t.CVoid(arg1, t.CPtr) - return t.CUInt64T(MKDIR(path_ptr)) - elif n == REMOVE: - path_ptr: t.CVoid | t.CPtr = t.CVoid(arg1, t.CPtr) - return t.CUInt64T(REMOVE(path_ptr)) - elif n == OPENDIR: - path_ptr: t.CVoid | t.CPtr = t.CVoid(arg1, t.CPtr) - return t.CUInt64T(OPENdir(path_ptr)) - elif n == READDIR: - info_ptr: t.CVoid | t.CPtr = t.CVoid(arg2, t.CPtr) - return t.CUInt64T(READdir(t.CInt(arg1), info_ptr)) - elif n == CLOSEDIR: - return t.CUInt64T(CLOSEdir(t.CInt(arg1))) - elif n == STAT: - path_ptr: t.CVoid | t.CPtr = t.CVoid(arg1, t.CPtr) - info_ptr: t.CVoid | t.CPtr = t.CVoid(arg2, t.CPtr) - return t.CUInt64T(STAT(path_ptr, info_ptr)) - elif n == WAIT_WINDOW: - if t.CInt(arg2) == 1: - return t.CUInt64T(desktop.is_active(t.CInt(arg1))) - elif t.CInt(arg2) == 2: - sched.Scheduler.try_reschedule() - return 0 - return t.CUInt64T(WAIT_WINDOW(t.CInt(arg1))) - elif n == SERIAL_PUTS: - str_ptr_sp: t.CVoid | t.CPtr = t.CVoid(arg1, t.CPtr) - return t.CUInt64T(SERIAL_PUTS(str_ptr_sp)) - elif n == LOAD_SO: - path_ptr_so: t.CVoid | t.CPtr = t.CVoid(arg1, t.CPtr) - return LOAD_SO(path_ptr_so) - elif n == SO_CALL1: - sym_ptr: t.CVoid | t.CPtr = t.CVoid(arg1, t.CPtr) - return t.CUInt64T(SO_CALL1(sym_ptr, arg2)) - elif n == GET_WINBUF: - return GET_WINBUF(t.CInt(arg1)) - elif n == WIN_FLUSH: - return t.CUInt64T(WIN_FLUSH(t.CInt(arg1))) - elif n == POLL_EVENT: - buf_ptr_ev: t.CVoid | t.CPtr = t.CVoid(arg1, t.CPtr) - caller_pid_ev: t.CInt = process.current() - return t.CUInt64T(desktop.poll_event(buf_ptr_ev, caller_pid_ev)) - elif n == SET_CURSOR: - desktop.set_cursor_type(t.CInt(arg1), t.CInt(arg2)) - return 0 - elif n == YIELD: - sched.Scheduler.try_reschedule() - return 0 - elif n == SET_TITLE: - title_ptr_st: t.CVoid | t.CPtr = t.CVoid(arg2, t.CPtr) - return t.CUInt64T(desktop.set_title(t.CInt(arg1), title_ptr_st)) - elif n == SET_GEOMETRY: - return t.CUInt64T(desktop.set_geometry(t.CInt(arg1), t.CInt(arg2), t.CInt(arg3), t.CInt(arg4), t.CInt(arg5))) - elif n == SET_RESIZABLE: - return t.CUInt64T(desktop.set_resizable(t.CInt(arg1), t.CInt(arg2), t.CInt(arg3))) - elif n == GET_WIN_SIZE: - return t.CUInt64T(desktop.get_size(t.CInt(arg1))) - elif n == SPAWN: - path_ptr_sp: t.CVoid | t.CPtr = t.CVoid(arg1, t.CPtr) - return t.CUInt64T(SPAWN(path_ptr_sp, t.CInt(arg2))) - elif n == MMAP: - return MMAP(arg1) - elif n == MUNMAP: - return t.CUInt64T(MUNMAP(arg1, arg2)) - elif n == THREAD_CREATE: - func_ptr: t.CVoid | t.CPtr = t.CVoid(arg1, t.CPtr) - arg_ptr: t.CVoid | t.CPtr = t.CVoid(arg2, t.CPtr) - cur_pid: t.CInt = process.current() - th: sched.Thread | t.CPtr = sched.Scheduler.create_thread(func_ptr, arg_ptr, cur_pid) - if th is None: return t.CUInt64T(0xFFFFFFFFFFFFFFFF) - p: process.Process | t.CPtr = process.ProcessManager.get_process(cur_pid) - if p: - p.addThread(th.tid) - return t.CUInt64T(th.tid) - return 0 - -def init(): - efer: t.CUInt64T = rdmsr(IA32_EFER) - efer = efer | 1 - wrmsr(IA32_EFER, efer) - star_val: t.CUInt64T = (t.CUInt64T(0x08) << 32) | (t.CUInt64T(0x1B) << 48) - wrmsr(IA32_STAR, star_val) - wrmsr(IA32_LSTAR, t.CUInt64T(syscall_entry)) - wrmsr(IA32_FMASK, 0x200) - serial.puts("[syscall] MSR init done\n") diff --git a/Test/Kernel/mm/mm.vp b/Test/Kernel/mm/mm.vp deleted file mode 100644 index c6c11095..00000000 --- a/Test/Kernel/mm/mm.vp +++ /dev/null @@ -1,764 +0,0 @@ -import bootinfo -import paging.paging as paging -import viperstring as string -import viperlib -import t, c - - -# 伙伴系统常量定义 -MIN_BLOCK_SIZE: t.CDefine = 4096 # 最小块大小(4KB) -MAX_BLOCK_SIZE: t.CDefine = 268435456 # 最大块大小(256MB) -MAX_ORDER: t.CDefine = 18 # 最大阶数(2^18 = 262144) - -# 内存块状态 -BLOCK_FREE: t.CDefine = 0 # 空闲 -BLOCK_USED: t.CDefine = 1 # 已使用 - -# 内存类型定义 -MEMORY_TYPE_AVAILABLE: t.CUInt64T = 7 -MEMORY_TYPE_RESERVED: t.CUInt64T = 0 -MEMORY_TYPE_LOADER_CODE: t.CUInt64T = 1 -MEMORY_TYPE_LOADER_DATA: t.CUInt64T = 2 -MEMORY_TYPE_BOOT_SERVICES_CODE: t.CUInt64T = 3 -MEMORY_TYPE_BOOT_SERVICES_DATA: t.CUInt64T = 4 -MEMORY_TYPE_RUNTIME_SERVICES_CODE: t.CUInt64T = 5 -MEMORY_TYPE_RUNTIME_SERVICES_DATA: t.CUInt64T = 6 -MEMORY_TYPE_ACPI_RECLAIMABLE: t.CUInt64T = 9 -MEMORY_TYPE_ACPI_NVS: t.CUInt64T = 10 -MEMORY_TYPE_BAD_MEMORY: t.CUInt64T = 8 - -# 内存区域结构 -class memory_region(t.CStruct): - start: t.CUInt64T - end: t.CUInt64T - size: t.CUInt64T - type: t.CUInt32T - next: 'memory_region' | t.CPtr - -# 全局内存区域链表 -memory_regions: t.CStatic | memory_region | t.CPtr = None - -# 内存块结构 -class memory_block(t.CStruct): - size: t.CUInt64T # 块大小 - state: t.CUInt8T # 块状态 - order: t.CUInt8T # 块阶数 - next: 'memory_block' | t.CPtr # 下一个块 - prev: 'memory_block' | t.CPtr # 上一个块 - -# 伙伴系统结构 -class __buddy_system(t.CStruct): - free_lists: t.CArray[memory_block | t.CPtr, MAX_ORDER + 1] - total_memory: t.CUInt64T # 总内存大小 - used_memory: t.CUInt64T # 已使用内存大小 - free_memory: t.CUInt64T # 空闲内存大小 - start_addr: t.CVoid | t.CPtr # 内存起始地址 - end_addr: t.CVoid | t.CPtr # 内存结束地址 - - -SLAB_MAGIC: t.CDefine = 0x534C4142 -SLAB_NUM_SIZES: t.CDefine = 6 -SLAB_THRESHOLD: t.CDefine = 1024 - -class slab_page(t.CStruct): - magic: t.CUInt32T - obj_size: t.CUInt16T - free_count: t.CUInt16T - data_offset: t.CUInt16T - total_objs: t.CUInt16T - free_head: t.CVoid | t.CPtr - block_ptr: memory_block | t.CPtr - next: 'slab_page' | t.CPtr - prev: 'slab_page' | t.CPtr - - -# 4K对齐函数 -def align_4k(addr: t.CUInt64T) -> t.CUInt64T: - return (addr + 0xFFF) & ~0xFFF - -# 计算阶数 -def get_order(size: t.CUInt64T) -> t.CStatic | t.CInt: - order: t.CInt = 0 - while size > MIN_BLOCK_SIZE: - size >>= 1 - order += 1 - return order - -# 计算块大小 -def get_block_size(order: t.CInt) -> t.CStatic | t.CUInt64T: - return MIN_BLOCK_SIZE << order - - -@t.Object -class _BuddySystemObject: - # 全局伙伴系统实例 - buddy: __buddy_system - # 初始化伙伴系统 - def __init__(self, start_addr: t.CVoid | t.CPtr, size: t.CUInt64T): - for i in range(MAX_ORDER + 1): - self.buddy.free_lists[i] = None - self.buddy.total_memory = size - self.buddy.used_memory = 0 - self.buddy.free_memory = size - self.buddy.start_addr = start_addr - self.buddy.end_addr = t.CVoid(t.CUInt64T(start_addr) + size, t.CPtr) - remaining: t.CUInt64T = size - cur_addr: t.CUInt64T = t.CUInt64T(start_addr) - while remaining >= MIN_BLOCK_SIZE: - order: t.CInt = 0 - tmp: t.CUInt64T = remaining - while tmp > MIN_BLOCK_SIZE: - tmp >>= 1 - order += 1 - block_size: t.CUInt64T = get_block_size(order) - while block_size > remaining and order > 0: - order -= 1 - block_size = get_block_size(order) - if block_size > remaining: break - block: memory_block | t.CPtr = cur_addr - block.size = block_size - block.state = BLOCK_FREE - block.order = order - block.next = None - block.prev = None - if order <= MAX_ORDER: - if self.buddy.free_lists[order]: - block.next = self.buddy.free_lists[order] - self.buddy.free_lists[order].prev = block - self.buddy.free_lists[order] = block - cur_addr += block_size - remaining -= block_size - # DEBUG: print free_lists status after init - import drivers.serial.uart.serial as serial - _dmsg: t.CArray[t.CChar, 40] - serial.puts("[mm] buddy init:") - _di: t.CInt = 0 - while _di <= MAX_ORDER: - if self.buddy.free_lists[_di]: - viperlib.snprintf(c.Addr(_dmsg), 40, " [%d]=0x%lx", _di, t.CUInt64T(self.buddy.free_lists[_di])) - serial.puts(_dmsg) - _di += 1 - serial.puts("\n") - - # 分割内存块 - def split_block(self, block: memory_block | t.CPtr, target_order: t.CInt) -> memory_block | t.CPtr: - current_order: t.CInt = block.order - # 从当前阶数向下分割,直到达到目标阶数 - while current_order > target_order: - current_order -= 1 - new_block_size: t.CUInt64T = get_block_size(current_order) - # 创建新块 - new_block: memory_block | t.CPtr = t.CUInt64T(block) + new_block_size - new_block.size = new_block_size - new_block.state = BLOCK_FREE - new_block.order = current_order - new_block.next = None - new_block.prev = None - # 更新原块大小和阶数 - block.size = new_block_size - block.order = current_order - # 将新块添加到对应阶数的空闲链表 - if current_order <= MAX_ORDER: - new_block.next = self.buddy.free_lists[current_order] - if self.buddy.free_lists[current_order]: - self.buddy.free_lists[current_order].prev = new_block - self.buddy.free_lists[current_order] = new_block - return block - - # 合并内存块 - def merge_blocks(self, block: memory_block | t.CPtr) -> t.CStatic | memory_block | t.CPtr: - order: t.CInt = block.order - while order < MAX_ORDER: - block_size: t.CUInt64T = get_block_size(order) - block_addr: t.CUInt64T = t.CUInt64T(block) - t.CUInt64T(self.buddy.start_addr) - buddy_addr: t.CUInt64T = block_addr ^ block_size - # 计算伙伴块地址 - buddy: memory_block | t.CPtr = t.CUInt64T(self.buddy.start_addr) + buddy_addr - # 检查伙伴块是否存在且空闲 - if buddy >= (memory_block | t.CPtr)(self.buddy.end_addr): - break # 伙伴块超出内存范围 - if buddy.state != BLOCK_FREE or buddy.order != order: - break # 伙伴块不空闲或阶数不匹配 - # 从空闲链表中移除伙伴块 - if buddy.prev: buddy.prev.next = buddy.next - else: self.buddy.free_lists[order] = buddy.next - if buddy.next: - buddy.next.prev = buddy.prev - # 合并块 - merged_block: memory_block | t.CPtr = block if block < buddy else buddy - merged_block.size = get_block_size(order + 1) - merged_block.order = order + 1 - block = merged_block - order += 1 - return block - - # 分配内存块 - def allocate_block(self, size: t.CUInt64T) -> t.CStatic | memory_block | t.CPtr: - # 计算所需阶数 - order: t.CInt = get_order(size) - if order > MAX_ORDER: return None # 所需块大小超过最大限制 - # 查找合适的空闲块 - found_order: t.CInt = -1 - for i in range(order, MAX_ORDER + 1): - if self.buddy.free_lists[i]: - found_order = i - break - # DEBUG: trace allocate_block - import drivers.serial.uart.serial as serial - _dba: t.CArray[t.CChar, 120] - if found_order == -1: - viperlib.snprintf(c.Addr(_dba), 120, "[mm] alloc FAIL size=%lu order=%d\n", size, order) - serial.puts(_dba) - _dbf: t.CArray[t.CChar, 200] - _fi: t.CInt = 0 - _fo: t.CInt = 0 - while _fi <= MAX_ORDER: - if self.buddy.free_lists[_fi]: - _fs: t.CInt = viperlib.snprintf(c.Addr(_dbf) + _fo, 200 - _fo, "[%d]=0x%lx ", _fi, t.CUInt64T(self.buddy.free_lists[_fi])) - _fo = _fo + _fs - _fi += 1 - if _fo == 0: - serial.puts("[mm] all free_lists EMPTY\n") - else: - serial.puts(_dbf) - serial.puts("\n") - return None - if found_order == -1: return None # 没有合适的空闲块 - # 取出空闲块 - block: memory_block | t.CPtr = self.buddy.free_lists[found_order] - # 从空闲链表中移除块 - if block.next: block.next.prev = None - self.buddy.free_lists[found_order] = block.next - # 如果块大小大于所需大小,分割块 - if found_order > order: - block = self.split_block(block, order) - # 标记块为已使用 - block.state = BLOCK_USED - # 更新内存统计 - self.buddy.used_memory += block.size - self.buddy.free_memory -= block.size - viperlib.snprintf(c.Addr(_dba), 120, "[mm] alloc OK size=%lu order=%d found=%d block=0x%lx\n", size, order, found_order, t.CUInt64T(block)) - serial.puts(_dba) - return block - - # 释放内存块 - def free_block(self, block: memory_block | t.CPtr) -> t.CStatic | t.CVoid: - # 标记块为空闲 - block.state = BLOCK_FREE - # 更新内存统计 - self.buddy.used_memory -= block.size - self.buddy.free_memory += block.size - # 尝试合并块 - block = self.merge_blocks(block) - # 将块添加到对应阶数的空闲链表 - order: t.CInt = block.order - if order <= MAX_ORDER: - block.next = self.buddy.free_lists[order] - block.prev = None - if self.buddy.free_lists[order]: - self.buddy.free_lists[order].prev = block - self.buddy.free_lists[order] = block -BuddySystemObject: _BuddySystemObject - - -def _slab_obj_size(size_class: t.CInt) -> t.CUInt16T: - if size_class == 0: return 32 - if size_class == 1: return 64 - if size_class == 2: return 128 - if size_class == 3: return 256 - if size_class == 4: return 512 - return 1024 - -def _slab_size_class(size: t.CUInt64T) -> t.CInt: - if size <= 32: return 0 - if size <= 64: return 1 - if size <= 128: return 2 - if size <= 256: return 3 - if size <= 512: return 4 - if size <= 1024: return 5 - return -1 - -def _slab_read_ptr(addr: t.CVoid | t.CPtr) -> t.CVoid | t.CPtr: - result: t.CVoid | t.CPtr - c.Asm(f"""mov rax, [{c.AsmInp(addr, t.ASM_DESCR.REG_ANY)}] - mov {c.AsmOut(result, t.ASM_DESCR.OUTPUT_REG)}, rax""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX]) - return result - -def _slab_write_ptr(addr: t.CVoid | t.CPtr, val: t.CVoid | t.CPtr): - c.Asm(f"""mov rax, {c.AsmInp(val, t.ASM_DESCR.REG_ANY)} - mov [{c.AsmInp(addr, t.ASM_DESCR.REG_ANY)}], rax""", - op=[t.ASM_DESCR.CLOBBER_RAX, t.ASM_DESCR.CLOBBER_MEMORY]) - -def _slab_find_page(ptr: t.CVoid | t.CPtr) -> slab_page | t.CPtr: - if ptr is None: return None - hdr_off: t.CUInt64T = memory_block.__sizeof__() - page_addr: t.CUInt64T = t.CUInt64T(ptr) & ~t.CUInt64T(0xFFF) - page: slab_page | t.CPtr = page_addr + hdr_off - if page.magic == SLAB_MAGIC: - os: t.CUInt16T = page.obj_size - if os == 32 or os == 64 or os == 128 or os == 256 or os == 512 or os == 1024: - return page - page_addr2: t.CUInt64T = page_addr - 4096 - page2: slab_page | t.CPtr = page_addr2 + hdr_off - if page2.magic == SLAB_MAGIC: - os2: t.CUInt16T = page2.obj_size - if os2 == 32 or os2 == 64 or os2 == 128 or os2 == 256 or os2 == 512 or os2 == 1024: - return page2 - return None - -@t.Object -class _SlabAllocator: - caches: t.CArray[slab_page | t.CPtr, SLAB_NUM_SIZES] - - def __init__(self): - for i in range(SLAB_NUM_SIZES): - self.caches[i] = None - - def _create_page(self, size_class: t.CInt) -> slab_page | t.CPtr: - obj_size: t.CUInt16T = _slab_obj_size(size_class) - aligned_size: t.CUInt16T = t.CUInt16T((obj_size + 15) & ~15) - block: memory_block | t.CPtr = BuddySystemObject.allocate_block(4096 + memory_block.__sizeof__()) - if not block: return None - hdr_off: t.CUInt64T = memory_block.__sizeof__() - page: slab_page | t.CPtr = t.CUInt64T(block) + hdr_off - page.magic = SLAB_MAGIC - page.obj_size = aligned_size - d_off: t.CUInt16T = t.CUInt16T((hdr_off + slab_page.__sizeof__() + 15) & ~15) - page.data_offset = d_off - total: t.CUInt16T = t.CUInt16T((block.size - d_off) / aligned_size) - page.total_objs = total - page.free_count = total - page.block_ptr = block - page.next = None - page.prev = None - data_start: t.CUInt64T = t.CUInt64T(block) + d_off - page.free_head = t.CVoid(data_start, t.CPtr) - for i in range(1, total): - cur: t.CVoid | t.CPtr = t.CVoid(data_start + t.CUInt64T(i - 1) * aligned_size, t.CPtr) - nxt: t.CVoid | t.CPtr = t.CVoid(data_start + t.CUInt64T(i) * aligned_size, t.CPtr) - _slab_write_ptr(cur, nxt) - last: t.CVoid | t.CPtr = t.CVoid(data_start + t.CUInt64T(total - 1) * aligned_size, t.CPtr) - _slab_write_ptr(last, t.CVoid(0, t.CPtr)) - return page - - def alloc(self, size_class: t.CInt) -> t.CVoid | t.CPtr: - page: slab_page | t.CPtr = self.caches[size_class] - while page: - if page.free_count > 0: break - page = page.next - if not page: - page = self._create_page(size_class) - if not page: return None - page.next = self.caches[size_class] - if self.caches[size_class]: - self.caches[size_class].prev = page - self.caches[size_class] = page - obj: t.CVoid | t.CPtr = page.free_head - page.free_head = _slab_read_ptr(obj) - page.free_count -= 1 - return obj - - def free_obj(self, ptr: t.CVoid | t.CPtr, page: slab_page | t.CPtr): - _slab_write_ptr(ptr, page.free_head) - page.free_head = ptr - page.free_count += 1 - if page.free_count == page.total_objs: - if page.prev: - page.prev.next = page.next - else: - sc: t.CInt = _slab_size_class(page.obj_size) - if sc >= 0: - self.caches[sc] = page.next - if page.next: - page.next.prev = page.prev - page.magic = 0 - BuddySystemObject.free_block(page.block_ptr) - -SlabAllocator: _SlabAllocator - - -# 内存分配函数 -def malloc(size: t.CUInt64T) -> t.CVoid | t.CPtr | t.CExport: - if size == 0: return None - if size <= SLAB_THRESHOLD: - sc: t.CInt = _slab_size_class(size) - if sc >= 0: - result: t.CVoid | t.CPtr = SlabAllocator.alloc(sc) - return result - hdr: t.CUInt64T = memory_block.__sizeof__() - if size >= 4096: - total: t.CUInt64T = size + 4096 - total = align_4k(total) - order: t.CInt = get_order(total) - if order > MAX_ORDER: return None - block: memory_block | t.CPtr = BuddySystemObject.allocate_block(total) - import drivers.serial.uart.serial as serial - _dbm: t.CArray[t.CChar, 120] - viperlib.snprintf(c.Addr(_dbm), 120, "[mm] malloc buddy size=%lu block=0x%lx\n", size, t.CUInt64T(block)) - serial.puts(_dbm) - if not block: return None - user_ptr: t.CUInt64T = (t.CUInt64T(block) + hdr + 4095) & ~t.CUInt64T(4095) - real_hdr: t.CUInt64T = user_ptr - 8 - c.Asm(f"""mov rax, {c.AsmInp(block, t.ASM_DESCR.REG_ANY)} - mov [{c.AsmInp(t.CVoid(real_hdr, t.CPtr), t.ASM_DESCR.REG_ANY)}], rax""", - op=[t.ASM_DESCR.CLOBBER_RAX, t.ASM_DESCR.CLOBBER_MEMORY]) - viperlib.snprintf(c.Addr(_dbm), 120, "[mm] malloc ret user_ptr=0x%lx\n", user_ptr) - serial.puts(_dbm) - return t.CVoid(user_ptr, t.CPtr) - total2: t.CUInt64T = size + hdr - total2 = align_4k(total2) - order2: t.CInt = get_order(total2) - if order2 > MAX_ORDER: return None - block2: memory_block | t.CPtr = BuddySystemObject.allocate_block(total2) - if not block2: return None - return t.CVoid(t.CUInt64T(block2) + hdr, t.CPtr) - - -def malloc_direct(size: t.CUInt64T) -> t.CVoid | t.CPtr | t.CExport: - if size == 0: return None - hdr: t.CUInt64T = memory_block.__sizeof__() - total: t.CUInt64T = size + hdr - total = align_4k(total) - order: t.CInt = get_order(total) - if order > MAX_ORDER: return None - block: memory_block | t.CPtr = BuddySystemObject.allocate_block(total) - if not block: return None - return t.CVoid(t.CUInt64T(block) + hdr, t.CPtr) - - -def free(ptr: t.CVoid | t.CPtr) -> t.CExport: - if ptr is None: return - sp: slab_page | t.CPtr = _slab_find_page(ptr) - if sp: - SlabAllocator.free_obj(ptr, sp) - return - if (t.CUInt64T(ptr) & 0xFFF) == 0: - real_hdr: t.CUInt64T = t.CUInt64T(ptr) - 8 - block: memory_block | t.CPtr - c.Asm(f"""mov rax, [{c.AsmInp(t.CVoid(real_hdr, t.CPtr), t.ASM_DESCR.REG_ANY)}] - mov {c.AsmOut(block, t.ASM_DESCR.OUTPUT_REG)}, rax""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX]) - BuddySystemObject.free_block(block) - return - block2: memory_block | t.CPtr = t.CUInt64T(ptr) - memory_block.__sizeof__() - BuddySystemObject.free_block(block2) - -def calloc(nmemb: t.CUInt64T, size: t.CUInt64T) -> t.CVoid | t.CPtr | t.CExport: - total_size: t.CUInt64T = nmemb * size - ptr: t.CVoid | t.CPtr = malloc(total_size) - if ptr: - string.memset(ptr, 0, total_size) - return ptr - -def realloc(ptr: t.CVoid | t.CPtr, size: t.CUInt64T) -> t.CVoid | t.CPtr | t.CExport: - if ptr is None: return malloc(size) - if size == 0: - free(ptr) - return None - new_ptr: t.CVoid | t.CPtr = malloc(size) - if not new_ptr: return None - sp: slab_page | t.CPtr = _slab_find_page(ptr) - if sp: - old_size: t.CUInt64T = sp.obj_size - elif (t.CUInt64T(ptr) & 0xFFF) == 0: - real_hdr_r: t.CUInt64T = t.CUInt64T(ptr) - 8 - block_r: memory_block | t.CPtr - c.Asm(f"""mov rax, [{c.AsmInp(t.CVoid(real_hdr_r, t.CPtr), t.ASM_DESCR.REG_ANY)}] - mov {c.AsmOut(block_r, t.ASM_DESCR.OUTPUT_REG)}, rax""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX]) - old_size = block_r.size - 4096 - else: - block2: memory_block | t.CPtr = t.CUInt64T(ptr) - memory_block.__sizeof__() - old_size = block2.size - memory_block.__sizeof__() - copy_size: t.CUInt64T = old_size if old_size < size else size - string.memcpy(new_ptr, ptr, copy_size) - free(ptr) - return new_ptr - - -# 回收内存区域链表 -def free_memory_regions() -> t.CStatic | t.CVoid: - global memory_regions - current: memory_region | t.CPtr = memory_regions - while current: - next_region: memory_region | t.CPtr = current.next - free(current) - current = next_region - memory_regions = None - -# 初始化内存管理系统 -def init(MemmapAddr: t.CUInt64T, MemmapSize: t.CUInt64T, MemmapDescSize: t.CUInt64T, FbAddr: t.CUInt64T = 0, FbSize: t.CUInt64T = 0): - global BuddySystemObject - import drivers.serial.uart.serial as serial - start_addr: t.CVoid | t.CPtr = None - size: t.CUInt64T = 0 - if MemmapAddr != 0: - if MemmapSize > 0: - if MemmapDescSize > 0: - num_entries: t.CUInt64T = MemmapSize / MemmapDescSize - max_memory: t.CUInt64T = 0 - best_start: t.CUInt64T = 0 - best_avail_size: t.CUInt64T = 0 - best_avail_start: t.CUInt64T = 0 - best_bs_size: t.CUInt64T = 0 - best_bs_start: t.CUInt64T = 0 - best_ld_size: t.CUInt64T = 0 - best_ld_start: t.CUInt64T = 0 - i: t.CUInt64T - for i in range(num_entries): - entry: bootinfo.memory_map_entry | t.CPtr = t.CVoid(MemmapAddr + i * MemmapDescSize, t.CPtr) - etype: t.CUInt64T = entry.type - start: t.CUInt64T = align_4k(entry.physical_start) - np: t.CUInt64T = entry.num_pages - end: t.CUInt64T = entry.physical_start + np * 4096 - end = align_4k(end - 1) - region_size: t.CUInt64T = end - start - if FbAddr != 0 and FbSize != 0: - fb_end: t.CUInt64T = FbAddr + FbSize - if start < fb_end and end > FbAddr: - continue - if etype == MEMORY_TYPE_AVAILABLE: - if region_size > best_avail_size: - best_avail_size = region_size - best_avail_start = start - if etype == MEMORY_TYPE_BOOT_SERVICES_DATA: - if region_size > best_bs_size: - best_bs_size = region_size - best_bs_start = start - if etype == MEMORY_TYPE_LOADER_DATA: - if region_size > best_ld_size: - best_ld_size = region_size - best_ld_start = start - min_blk: t.CUInt64T = MIN_BLOCK_SIZE - if best_avail_size >= min_blk: - best_start = best_avail_start - max_memory = best_avail_size - elif best_bs_size >= min_blk: - best_start = best_bs_start - max_memory = best_bs_size - elif best_ld_size >= min_blk: - best_start = best_ld_start - max_memory = best_ld_size - cr4: t.CArray[t.CChar, 128] - string.memset(c.Addr(cr4), 0, 128) - viperlib.snprintf(c.Addr(cr4), 128, "mm: best=0x%lx max=%lu entries=%lu avail=%lu bs=%lu ld=%lu\n", - best_start, max_memory, num_entries, best_avail_size, best_bs_size, best_ld_size) - serial.puts(cr4) - if best_start != 0: - if max_memory >= min_blk: - start_addr = t.CVoid(best_start, t.CPtr) - size = max_memory - if start_addr is None: - size = detect_memory_size() - size = align_4k(size) - # 起始地址 4MB(内核之后),避免超出物理 RAM - # 旧值 0x10000000 在 256MB QEMU 中超出物理 RAM 边界 - start_addr = t.CVoid(align_4k(0x400000), t.CPtr) - if size > 0x400000: - size = size - 0x400000 - size = align_4k(size) - min_blk2: t.CUInt64T = MIN_BLOCK_SIZE - if size < min_blk2: - size = 33554432 - cr2: t.CArray[t.CChar, 128] - string.memset(c.Addr(cr2), 0, 128) - viperlib.snprintf(c.Addr(cr2), 128, "mm.init: start=0x%lx size=%lu bytes\n", - t.CUInt64T(start_addr), size) - serial.puts(cr2) - BuddySystemObject.__init__(start_addr, size) - SlabAllocator.__init__() - - -# 虚拟内存映射结构 -class vm_area(t.CStruct): - VirtAddr: t.CUInt64T - PhysAddr: t.CUInt64T - size: t.CUInt64T - flags: t.CUInt32T - next: 'vm_area' | t.CPtr - -# 全局虚拟内存区域链表 -vm_areas: vm_area | t.CPtr = None - -# 博弈机制参数 -ALLOCATION_RETRIES: t.CDefine = 5 # 分配重试次数 -FRAGMENTATION_THRESHOLD: t.CDefine = 0.7 # 碎片率阈值 - -# 获取内存使用统计 -@c.CReturn(t.CUInt64T, t.CUInt64T, t.CUInt64T) -def GetMemoryStats(): - return (BuddySystemObject.buddy.total_memory, BuddySystemObject.buddy.used_memory, BuddySystemObject.buddy.free_memory) - -# 计算内存碎片率 -def calculate_fragmentation() -> t.CDouble: - # 计算空闲块的数量和总大小 - free_blocks: t.CInt = 0 - free_size: t.CUInt64T = 0 - - for i in range(MAX_ORDER + 1): - block: memory_block | t.CPtr = BuddySystemObject.buddy.free_lists[i] - while block: - free_blocks += 1 - free_size += block.size - block = block.next - - # 如果没有空闲内存,返回0 - if free_size == 0: - return 0.0 - - # 计算碎片率 - # 碎片率 = 1 - (最大空闲块大小 / 总空闲内存大小) - max_free_block: t.CUInt64T = 0 - for i in range(MAX_ORDER, -1, -1): - if BuddySystemObject.buddy.free_lists[i]: - max_free_block = get_block_size(i) - break - - if max_free_block == 0: - return 1.0 - - return 1.0 - (t.CDouble(max_free_block) / t.CDouble(free_size)) - -# 内存整理函数 -def compact_memory() -> t.CStatic | t.CInt: - freed_pages: t.CInt = 0 - for sc in range(SLAB_NUM_SIZES): - page: slab_page | t.CPtr = SlabAllocator.caches[sc] - while page: - next_page: slab_page | t.CPtr = page.next - if page.free_count == page.total_objs: - if page.prev: - page.prev.next = page.next - else: - SlabAllocator.caches[sc] = page.next - if page.next: - page.next.prev = page.prev - page.magic = 0 - BuddySystemObject.free_block(page.block_ptr) - freed_pages += 1 - page = next_page - return freed_pages - -# 虚拟内存分配函数 -def vm_alloc(size: t.CUInt64T, flags: t.CUInt32T) -> t.CUInt64T: - global vm_areas - # 4K对齐 - size = align_4k(size) - - # 尝试分配物理内存,使用博弈机制 - PhysAddr: t.CVoid | t.CPtr = None - retries: t.CInt = 0 - - while retries < ALLOCATION_RETRIES: - PhysAddr = malloc(size) - if PhysAddr: - break - - # 内存不足,尝试进行内存整理 - if calculate_fragmentation() > FRAGMENTATION_THRESHOLD: - compact_memory() - - retries += 1 - - if not PhysAddr: - return 0 - - # 分配虚拟地址 - # 简单的虚拟地址分配策略:从0x100000000开始 - VirtAddr: t.CUInt64T = 0x100000000 - current: vm_area | t.CPtr = vm_areas - - # 寻找合适的虚拟地址空间 - while current: - if VirtAddr + size <= current.VirtAddr: - break - VirtAddr = current.VirtAddr + current.size - current = current.next - - # 创建虚拟内存区域 - area: vm_area | t.CPtr = malloc(vm_area.__sizeof__()) - if area: - area.VirtAddr = VirtAddr - area.PhysAddr = t.CUInt64T(PhysAddr) - area.size = size - area.flags = flags - area.next = vm_areas - vm_areas = area - - # 映射虚拟地址到物理地址 - # 计算需要映射的页数 - pages: t.CUInt64T = size / 4096 - i: t.CUInt64T - for i in range(pages): - page_virt: t.CUInt64T = VirtAddr + (i * 4096) - page_phys: t.CUInt64T = t.CUInt64T(PhysAddr) + (i * 4096) - # 调用paging模块的映射函数 - paging.MapPage(page_virt, page_phys, flags) - - return VirtAddr - -# 虚拟内存释放函数 -def vm_free(VirtAddr: t.CUInt64T): - global vm_areas - # 查找虚拟内存区域 - current: vm_area | t.CPtr = vm_areas - prev: vm_area | t.CPtr = None - - while current: - if current.VirtAddr == VirtAddr: - # 取消虚拟地址映射 - pages: t.CUInt64T = current.size / 4096 - i: t.CUInt64T - for i in range(pages): - page_virt: t.CUInt64T = current.VirtAddr + (i * 4096) - paging.UnMapPage(page_virt) - - # 释放物理内存 - free(t.CVoid(current.PhysAddr, t.CPtr)) - if prev: - prev.next = current.next - else: - vm_areas = current.next - free(current) - return - prev = current - current = current.next - -# CMOS读取函数 -def cmos_read(reg: t.CUInt8T) -> t.CUInt8T: - c.Asm(f"mov al, {c.AsmInp(reg)}\nout 0x70, al") - val: t.CUInt8T - c.Asm(f"in al, 0x71\nmov {c.AsmOut(val)}, al") - return val - -# 内存大小测试函数 -def detect_memory_size() -> t.CUInt64T: - # 读取 1MB-16MB 扩展内存(KB 单位) - low: t.CUInt8T = cmos_read(0x15) - high: t.CUInt8T = cmos_read(0x16) - mem_kb: t.CUInt32T = (t.CUInt32T(high) << 8) | low - - # 读取 16MB 以上扩展内存(64KB 块为单位) - low2: t.CUInt8T = cmos_read(0x17) - high2: t.CUInt8T = cmos_read(0x18) - mem_above_16mb: t.CUInt32T = (t.CUInt32T(high2) << 8) | low2 - - # 两个寄存器都为 0 时使用默认值 - if mem_kb == 0 and mem_above_16mb == 0: - return 0x10000000 # 256MB - - # 计算总内存:1MB 基础 + 1MB-16MB + 16MB 以上 - total_size: t.CUInt64T = 1048576 # 前 1MB - if mem_kb > 0: - total_size = total_size + t.CUInt64T(mem_kb) * 1024 - if mem_above_16mb > 0: - total_size = total_size + t.CUInt64T(mem_above_16mb) * 65536 - - total_size = align_4k(total_size) - - # 确保内存大小至少为32MB - if total_size < 33554432: # 32MB - total_size = 33554432 - - return total_size diff --git a/Test/Kernel/paging/paging.vp b/Test/Kernel/paging/paging.vp deleted file mode 100644 index 267a4318..00000000 --- a/Test/Kernel/paging/paging.vp +++ /dev/null @@ -1,296 +0,0 @@ -import drivers.serial.uart.serial as serial -import viperlib -import t, c - - -PTE_PRESENT: t.CDefine = (1 << 0) -PTE_WRITABLE: t.CDefine = (1 << 1) -PTE_USER: t.CDefine = (1 << 2) -PTE_PWT: t.CDefine = (1 << 3) -PTE_PCD: t.CDefine = (1 << 4) -PTE_ACCESSED: t.CDefine = (1 << 5) -PTE_DIRTY: t.CDefine = (1 << 6) -PTE_PS: t.CDefine = (1 << 7) -PTE_GLOBAL: t.CDefine = (1 << 8) - -class _p: - entries: t.CArray[t.CUInt64T, 512] - -PT_POOL_PAGES: t.CDefine = 512 -pt_pool_raw: t.CVoid | t.CPtr = None -pt_pool_start: t.CUInt64T = 0 -pt_pool_used: t.CUInt64T = 0 - -AllocatedPages: t.CUInt64T = 0 -pml4: _p | t.CPtr = None -pdp: _p | t.CPtr -pd: _p | t.CPtr -pt: _p | t.CPtr - -def init(MemmapAddr: t.CUInt64T, MemmapSize: t.CUInt64T): - global pml4 - pml4 = GetCurrentPml4() - c.Asm(f""" - mov rax, cr0 - and rax, ~0x10000 - mov cr0, rax - """) - -def init_pool(buf: t.CVoid | t.CPtr, buf_size: t.CUInt64T): - global pt_pool_raw, pt_pool_start, pt_pool_used - pt_pool_raw = buf - if buf is None: return - raw_addr: t.CUInt64T = t.CUInt64T(buf) - aligned_addr: t.CUInt64T = (raw_addr + t.CUInt64T(0xFFF)) & ~t.CUInt64T(0xFFF) - pt_pool_start = aligned_addr - pt_pool_used = 0 - -def AllocPage() -> t.CVoid | t.CPtr: - global AllocatedPages, pt_pool_used, pml4, pdp, pd, pt - if pt_pool_raw is None: return None - if pt_pool_used >= t.CUInt64T(PT_POOL_PAGES): return None - page: t.CVoid | t.CPtr = t.CVoid(pt_pool_start + pt_pool_used * t.CUInt64T(4096), t.CPtr) - pt_pool_used = pt_pool_used + t.CUInt64T(1) - c.Asm(f"""mov al, 0 - mov ecx, 4096 - mov rdi, {c.AsmInp(page, t.ASM_DESCR.REG_ANY)} - rep stosb""", - op = [t.ASM_DESCR.CLOBBER_AL, t.ASM_DESCR.CLOBBER_ECX, t.ASM_DESCR.CLOBBER_RDI]) - AllocatedPages = AllocatedPages + t.CUInt64T(1) - return page - -def FreePage(page: t.CVoid | t.CPtr): - global AllocatedPages, pml4, pdp, pd, pt - if page is None: return - if AllocatedPages > t.CUInt64T(0): AllocatedPages = AllocatedPages - t.CUInt64T(1) - -def MapPage(VirtAddr: t.CUInt64T, PhysAddr: t.CUInt64T, flags: t.CUInt64T): - global pml4, pdp, pd, pt - if VirtAddr == 0 or PhysAddr == 0: return - VirtAddr = VirtAddr & ~t.CUInt64T(0xFFF) - PhysAddr = PhysAddr & ~t.CUInt64T(0xFFF) - Pml4Index: t.CUInt64T = (VirtAddr >> 39) & 0x1FF - PdpIndex: t.CUInt64T = (VirtAddr >> 30) & 0x1FF - PdIndex: t.CUInt64T = (VirtAddr >> 21) & 0x1FF - PtIndex: t.CUInt64T = (VirtAddr >> 12) & 0x1FF - - if not pml4: - pml4 = AllocPage() - if not pml4: return - - if not (pml4.entries[Pml4Index] & PTE_PRESENT): - pdp: _p | t.CPtr = AllocPage() - if not pdp: return - pml4.entries[Pml4Index] = (t.CUInt64T(pdp) & ~t.CUInt64T(0xFFF)) | PTE_PRESENT | PTE_WRITABLE | (flags & PTE_USER) - else: - if (flags & PTE_USER) and not (pml4.entries[Pml4Index] & PTE_USER): - pml4.entries[Pml4Index] = pml4.entries[Pml4Index] | PTE_USER - pdp: _p | t.CPtr = t.CType(pml4.entries[Pml4Index] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - - if not (pdp.entries[PdpIndex] & PTE_PRESENT): - pd: _p | t.CPtr = AllocPage() - if not pd: return - pdp.entries[PdpIndex] = (t.CUInt64T(pd) & ~t.CUInt64T(0xFFF)) | PTE_PRESENT | PTE_WRITABLE | (flags & PTE_USER) - else: - if (flags & PTE_USER) and not (pdp.entries[PdpIndex] & PTE_USER): - pdp.entries[PdpIndex] = pdp.entries[PdpIndex] | PTE_USER - pd: _p | t.CPtr = t.CType(pdp.entries[PdpIndex] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - - if pd.entries[PdIndex] & 1: - if pd.entries[PdIndex] & 0x80: - big_phys: t.CUInt64T = pd.entries[PdIndex] & ~t.CUInt64T(0x1FFFFF) - inherit_flags: t.CUInt64T = pd.entries[PdIndex] & (PTE_PCD | PTE_PWT) - pt: _p | t.CPtr = AllocPage() - if not pt: return - split_i: t.CInt = 0 - while split_i < 512: - pt.entries[split_i] = (big_phys + t.CUInt64T(split_i) * 0x1000) | PTE_PRESENT | PTE_WRITABLE | inherit_flags - split_i += 1 - pd.entries[PdIndex] = (t.CUInt64T(pt) & ~t.CUInt64T(0xFFF)) | PTE_PRESENT | PTE_WRITABLE | (flags & PTE_USER) - else: - # PD entry exists as a regular PT (e.g. cloned identity mapping). - # Must propagate PTE_USER to the PD entry so user-mode access is - # allowed at all paging levels, otherwise #PF err=0x5. - if (flags & PTE_USER) and not (pd.entries[PdIndex] & PTE_USER): - pd.entries[PdIndex] = pd.entries[PdIndex] | PTE_USER - else: - pt: _p | t.CPtr = AllocPage() - if not pt: return - pd.entries[PdIndex] = (t.CUInt64T(pt) & ~t.CUInt64T(0xFFF)) | PTE_PRESENT | PTE_WRITABLE | (flags & PTE_USER) - pt: _p | t.CPtr = t.CType(pd.entries[PdIndex] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - - pt.entries[PtIndex] = PhysAddr | flags | PTE_PRESENT - c.Asm(f"invlpg [{c.AsmInp(VirtAddr, t.ASM_DESCR.REG_ANY)}]") - -def MapLargePage(VirtAddr: t.CUInt64T, PhysAddr: t.CUInt64T, flags: t.CUInt64T) -> t.CVoid: - global pml4, pdp, pd, pt - VirtAddr = VirtAddr & ~t.CUInt64T(0x1FFFFF) - PhysAddr = PhysAddr & ~t.CUInt64T(0x1FFFFF) - Pml4Index: t.CUInt64T = (VirtAddr >> 39) & 0x1FF - PdpIndex: t.CUInt64T = (VirtAddr >> 30) & 0x1FF - PdIndex: t.CUInt64T = (VirtAddr >> 21) & 0x1FF - - if not pml4: - pml4 = AllocPage() - if not pml4: return - - if not pml4.entries[Pml4Index] & PTE_PRESENT: - pdp: _p | t.CPtr = AllocPage() - if not pdp: return - pml4.entries[Pml4Index] = (t.CUInt64T(pdp) & ~t.CUInt64T(0xFFF)) | PTE_PRESENT | PTE_WRITABLE - pdp: _p | t.CPtr = t.CType(pml4.entries[Pml4Index] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - - if not (pdp.entries[PdpIndex] & PTE_PRESENT): - pd: _p | t.CPtr = AllocPage() - if not pd: return - pdp.entries[PdpIndex] = (t.CUInt64T(pd) & ~t.CUInt64T(0xFFF)) | PTE_PRESENT | PTE_WRITABLE - pd: _p | t.CPtr = t.CType(pdp.entries[PdpIndex] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - - pd.entries[PdIndex] = PhysAddr | flags | PTE_PRESENT | PTE_PS - c.Asm(f"invlpg [{c.AsmInp(VirtAddr, t.ASM_DESCR.REG_ANY)}]") - -def UnMapPage(VirtAddr: t.CUInt64T): - global pml4, pdp, pd, pt - if VirtAddr == 0: return - if not pml4: return - Pml4Index: t.CUInt64T = (VirtAddr >> 39) & 0x1FF - PdpIndex: t.CUInt64T = (VirtAddr >> 30) & 0x1FF - PdIndex: t.CUInt64T = (VirtAddr >> 21) & 0x1FF - PtIndex: t.CUInt64T = (VirtAddr >> 12) & 0x1FF - - if not pml4.entries[Pml4Index] & PTE_PRESENT: return - - pdp: _p | t.CPtr = t.CType(pml4.entries[Pml4Index] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - if not pdp.entries[PdpIndex] & PTE_PRESENT: return - - pd: _p | t.CPtr = t.CType(pdp.entries[PdpIndex] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - - if not pd.entries[PdIndex] & PTE_PRESENT: return - - if pd.entries[PdIndex] & PTE_PS: - pd.entries[PdIndex] = 0 - else: - pt: _p | t.CPtr = t.CType(pd.entries[PdIndex] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - pt.entries[PtIndex] = 0 - - c.Asm(f"invlpg [{c.AsmInp(VirtAddr, t.ASM_DESCR.REG_ANY)}]") - -def EnablePaging(): - global pml4, pdp, pd, pt - c.Asm(f"mov cr3, {c.AsmInp(t.CUInt64T(pml4), t.ASM_DESCR.REG_ANY)}") - -def GetCurrentPml4() -> _p | t.CPtr: - global pml4, pdp, pd, pt - cr3: t.CUInt64T - c.Asm(f"mov {c.AsmOut(cr3, t.ASM_DESCR.OUTPUT_REG)}, cr3") - return (_p | t.CPtr)(cr3 & ~t.CUInt64T(0xFFF)) - -def create_process_page_table() -> t.CUInt64T: - global pml4 - if not pml4: return 0 - new_pml4: _p | t.CPtr = AllocPage() - if not new_pml4: return 0 - i: t.CUInt64T - for i in range(512): - entry: t.CUInt64T = pml4.entries[i] - if entry & PTE_PRESENT: - new_pml4.entries[i] = entry - return t.CUInt64T(new_pml4) - -def clone_for_process(isolate_vaddr: t.CUInt64T) -> t.CUInt64T: - global pml4 - _dbg: t.CArray[t.CChar, 120] - viperlib.snprintf(c.Addr(_dbg), 120, "[clone] pml4=0x%lx pool_used=%lu iso_va=0x%lx\n", t.CUInt64T(pml4), pt_pool_used, isolate_vaddr) - serial.puts(_dbg) - if not pml4: return 0 - new_pml4_page: _p | t.CPtr = AllocPage() - if not new_pml4_page: - serial.puts("[clone] AllocPage pml4 failed\n") - return 0 - _dbg2: t.CArray[t.CChar, 120] - viperlib.snprintf(c.Addr(_dbg2), 120, "[clone] new_pml4=0x%lx\n", t.CUInt64T(new_pml4_page)) - serial.puts(_dbg2) - i: t.CUInt64T - for i in range(512): - new_pml4_page.entries[i] = pml4.entries[i] - pml4_idx: t.CUInt64T = (isolate_vaddr >> 39) & 0x1FF - _dbg3: t.CArray[t.CChar, 120] - viperlib.snprintf(c.Addr(_dbg3), 120, "[clone] pml4_idx=%lu entry0=0x%lx\n", pml4_idx, pml4.entries[pml4_idx]) - serial.puts(_dbg3) - if not (pml4.entries[pml4_idx] & PTE_PRESENT): return t.CUInt64T(new_pml4_page) - kernel_pdp: _p | t.CPtr = t.CType(pml4.entries[pml4_idx] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - new_pdp_page: _p | t.CPtr = AllocPage() - if not new_pdp_page: return t.CUInt64T(new_pml4_page) - for i in range(512): - new_pdp_page.entries[i] = kernel_pdp.entries[i] - new_pml4_page.entries[pml4_idx] = (t.CUInt64T(new_pdp_page) & ~t.CUInt64T(0xFFF)) | (pml4.entries[pml4_idx] & t.CUInt64T(0xFFF)) - pdp_idx: t.CUInt64T = (isolate_vaddr >> 30) & 0x1FF - if not (kernel_pdp.entries[pdp_idx] & PTE_PRESENT): return t.CUInt64T(new_pml4_page) - kernel_pd: _p | t.CPtr = t.CType(kernel_pdp.entries[pdp_idx] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - new_pd_page: _p | t.CPtr = AllocPage() - if not new_pd_page: return t.CUInt64T(new_pml4_page) - for i in range(512): - new_pd_page.entries[i] = kernel_pd.entries[i] - new_pdp_page.entries[pdp_idx] = (t.CUInt64T(new_pd_page) & ~t.CUInt64T(0xFFF)) | (kernel_pdp.entries[pdp_idx] & t.CUInt64T(0xFFF)) - pd_idx: t.CUInt64T = (isolate_vaddr >> 21) & 0x1FF - if not (kernel_pd.entries[pd_idx] & PTE_PRESENT): return t.CUInt64T(new_pml4_page) - if kernel_pd.entries[pd_idx] & PTE_PS: return t.CUInt64T(new_pml4_page) - kernel_pt: _p | t.CPtr = t.CType(kernel_pd.entries[pd_idx] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - new_pt_page: _p | t.CPtr = AllocPage() - if not new_pt_page: return t.CUInt64T(new_pml4_page) - for i in range(512): - new_pt_page.entries[i] = kernel_pt.entries[i] - new_pd_page.entries[pd_idx] = (t.CUInt64T(new_pt_page) & ~t.CUInt64T(0xFFF)) | (kernel_pd.entries[pd_idx] & t.CUInt64T(0xFFF)) - return t.CUInt64T(new_pml4_page) - -def save_pt_range(vaddr_start: t.CUInt64T, vaddr_end: t.CUInt64T, save_buf: t.CUInt64T | t.CPtr, save_count: t.CUInt32T | t.CPtr) -> t.CInt: - global pml4 - if not pml4: return -1 - c.Set(save_count, t.CUInt32T(0)) - va: t.CUInt64T = vaddr_start & ~t.CUInt64T(0xFFF) - while va < vaddr_end: - pml4_idx: t.CUInt64T = (va >> 39) & 0x1FF - if not (pml4.entries[pml4_idx] & PTE_PRESENT): va += 0x1000; continue - pdp_: _p | t.CPtr = t.CType(pml4.entries[pml4_idx] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - pdp_idx: t.CUInt64T = (va >> 30) & 0x1FF - if not (pdp_.entries[pdp_idx] & PTE_PRESENT): va += 0x1000; continue - pd_: _p | t.CPtr = t.CType(pdp_.entries[pdp_idx] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - pd_idx: t.CUInt64T = (va >> 21) & 0x1FF - if not (pd_.entries[pd_idx] & PTE_PRESENT): va += 0x1000; continue - if pd_.entries[pd_idx] & PTE_PS: va += 0x200000; continue - pt_: _p | t.CPtr = t.CType(pd_.entries[pd_idx] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - pt_idx: t.CUInt64T = (va >> 12) & 0x1FF - saved: t.CUInt32T = c.DerefAs(save_count) # 此处操作意义存疑? - entry_ptr: t.CUInt64T | t.CPtr = save_buf + t.CUInt64T(saved) * 16 - c.DerefAs(entry_ptr, va) - c.DerefAs(entry_ptr + 8, pt_.entries[pt_idx]) - c.Set(save_count, t.CUInt32T(saved + 1)) - va += 0x1000 - return 0 - -def restore_pt_range(save_buf: t.CUInt64T | t.CPtr, save_count: t.CUInt32T): - global pml4 - if not pml4: return - i: t.CUInt32T = 0 - while i < save_count: - entry_ptr: t.CUInt64T | t.CPtr = save_buf + t.CUInt64T(i) * 16 - va: t.CUInt64T = c.DerefAs(entry_ptr) - orig_pte: t.CUInt64T = c.DerefAs(entry_ptr + 8) - pml4_idx: t.CUInt64T = (va >> 39) & 0x1FF - if not (pml4.entries[pml4_idx] & PTE_PRESENT): i += 1; continue - pdp_: _p | t.CPtr = t.CType(pml4.entries[pml4_idx] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - pdp_idx: t.CUInt64T = (va >> 30) & 0x1FF - if not (pdp_.entries[pdp_idx] & PTE_PRESENT): i += 1; continue - pd_: _p | t.CPtr = t.CType(pdp_.entries[pdp_idx] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - pd_idx: t.CUInt64T = (va >> 21) & 0x1FF - if not (pd_.entries[pd_idx] & PTE_PRESENT): i += 1; continue - if pd_.entries[pd_idx] & PTE_PS: i += 1; continue - pt_: _p | t.CPtr = t.CType(pd_.entries[pd_idx] & ~t.CUInt64T(0xFFF), _p, t.CPtr) - pt_idx: t.CUInt64T = (va >> 12) & 0x1FF - pt_.entries[pt_idx] = orig_pte - c.Asm(f"invlpg [{c.AsmInp(va, t.ASM_DESCR.REG_ANY)}]", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - i += 1 - -def set_active_pml4(cr3_val: t.CUInt64T): - global pml4 - pml4 = t.CType(cr3_val & ~t.CUInt64T(0xFFF), _p, t.CPtr) diff --git a/Test/Kernel/platform/pch/__init__.vp b/Test/Kernel/platform/pch/__init__.vp deleted file mode 100644 index e1581f91..00000000 --- a/Test/Kernel/platform/pch/__init__.vp +++ /dev/null @@ -1,4 +0,0 @@ -from . import pic -from . import pit -from . import timer -from . import rtc diff --git a/Test/Kernel/platform/pch/pic.vp b/Test/Kernel/platform/pch/pic.vp deleted file mode 100644 index 239fd69a..00000000 --- a/Test/Kernel/platform/pch/pic.vp +++ /dev/null @@ -1,120 +0,0 @@ -import asm -import t, c - - -# PIC端口定义 -PIC1_COMMAND: t.CDefine = 0x20 -PIC1_DATA: t.CDefine = 0x21 -PIC2_COMMAND: t.CDefine = 0xA0 -PIC2_DATA: t.CDefine = 0xA1 - -# ICW1 - 初始化命令字1 -ICW1_ICW4: t.CDefine = 0x01 # 需要ICW4 -ICW1_SINGLE: t.CDefine = 0x02 # 单级模式 -ICW1_INTERVAL4: t.CDefine = 0x04 # 间隔4字节 -ICW1_LEVEL: t.CDefine = 0x08 # 电平触发模式 -ICW1_INIT: t.CDefine = 0x10 # 初始化 - -# ICW4 - 初始化命令字4 -ICW4_8086: t.CDefine = 0x01 # 8086/88模式 -ICW4_AUTO: t.CDefine = 0x02 # 自动EOI -ICW4_BUF_SLAVE: t.CDefine = 0x08 # 缓冲模式(从片) -ICW4_BUF_MASTER: t.CDefine = 0x0C # 缓冲模式(主片) -ICW4_SFNM: t.CDefine = 0x10 # 特殊全嵌套模式 - -# OCW2 - 操作命令字2 -OCW2_EOI: t.CDefine = 0x20 # 结束中断 - -# OCW3 - 操作命令字3 -OCW3_READ_ISR: t.CDefine = 0x0B # 读取中断服务寄存器(ISR) - -# 初始化PIC -def init(): - # 发送ICW1:开始初始化,需要ICW4 - asm.outb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4) - asm.io_wait() - asm.outb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4) - asm.io_wait() - - # 发送ICW2:中断向量偏移 - asm.outb(PIC1_DATA, 0x20) # IRQ0-7映射到0x20-0x27 - asm.io_wait() - asm.outb(PIC2_DATA, 0x28) # IRQ8-15映射到0x28-0x2F - asm.io_wait() - - # 发送ICW3:级联信息 - asm.outb(PIC1_DATA, 0x04) # 主PIC的IRQ2连接从PIC - asm.io_wait() - asm.outb(PIC2_DATA, 0x02) # 从PIC连接到主PIC的IRQ2 - asm.io_wait() - - # 发送ICW4:8086模式 - asm.outb(PIC1_DATA, ICW4_8086) - asm.io_wait() - asm.outb(PIC2_DATA, ICW4_8086) - asm.io_wait() - - # 设置初始屏蔽字:只启用IRQ0(定时器)、IRQ1(键盘)、IRQ2(级联) - # 主PIC: 屏蔽所有除了IRQ0, IRQ1, IRQ2 (0xF8 = 11111000) - # 从PIC: 屏蔽所有 (0xFF = 11111111),鼠标中断由驱动程序自己启用 - asm.outb(PIC1_DATA, 0xF8) # 启用IRQ0, IRQ1, IRQ2 - asm.io_wait() - asm.outb(PIC2_DATA, 0xFF) # 屏蔽所有从PIC中断 - asm.io_wait() - -# 发送EOI信号 -def eoi(irq: t.CUInt8T): - if irq >= 8: asm.outb(PIC2_COMMAND, OCW2_EOI) - asm.outb(PIC1_COMMAND, OCW2_EOI) - - -# 检查是否是虚假中断(spurious interrupt) -# 返回 1 表示是虚假中断,0 表示是真实中断 -def isSpurious(irq: t.CInt) -> t.CInt: - # 边界检查 - if irq < 0 or irq > 15: return 0 - isr: t.CUInt8T - if irq < 8: - # 发送OCW3,读取ISR(Interrupt Service Register) - asm.outb(PIC1_COMMAND, OCW3_READ_ISR) - asm.io_wait() - isr = asm.inb(PIC1_COMMAND) - # 如果ISR中对应位为0,说明是虚假中断 - return not (isr & (1 << irq)) - else: - # 发送OCW3,读取从PIC的ISR - asm.outb(PIC2_COMMAND, OCW3_READ_ISR) - asm.io_wait() - isr = asm.inb(PIC2_COMMAND) - # 如果ISR中对应位为0,说明是虚假中断 - return not (isr & (1 << (irq - 8))) - -# 设置IRQ屏蔽 -def setMask(irq: t.CUInt8T): - # 边界检查 - if irq > 15: return - port: t.CUInt16T - value: t.CUInt8T - if irq < 8: - port = PIC1_DATA - else: - port = PIC2_DATA - irq -= 8 - value = asm.inb(port) | (1 << irq) - asm.outb(port, value) - asm.io_wait() # 确保命令生效 - -# 清除IRQ屏蔽 -def clearMask(irq: t.CUInt8T): - # 边界检查 - if irq > 15: return - port: t.CUInt16T - value: t.CUInt8T - if irq < 8: - port = PIC1_DATA - else: - port = PIC2_DATA - irq -= 8 - value = asm.inb(port) & ~(1 << irq) - asm.outb(port, value) - asm.io_wait() # 确保命令生效 diff --git a/Test/Kernel/platform/pch/pit.vp b/Test/Kernel/platform/pch/pit.vp deleted file mode 100644 index f4a76a39..00000000 --- a/Test/Kernel/platform/pch/pit.vp +++ /dev/null @@ -1,26 +0,0 @@ -import asm -import t, c - -PIT_CHANNEL0: t.CDefine = 0x40 -PIT_CHANNEL1: t.CDefine = 0x41 -PIT_CHANNEL2: t.CDefine = 0x42 -PIT_COMMAND: t.CDefine = 0x43 - -def pit_init(frequency: t.CInt): - # 参数验证:确保频率为正数 - if frequency <= 0: return - - # 计算除数,使用16位无符号整数 - divisor: t.CUInt32T = 1193180 / frequency - - # 发送命令字:通道0,先低后高,模式3(方波),二进制计数 - asm.outb(PIT_COMMAND, 0x36) - asm.io_wait() - - # 写入低字节 - asm.outb(PIT_CHANNEL0, divisor & 0xFF) - asm.io_wait() - - # 写入高字节 - asm.outb(PIT_CHANNEL0, (divisor >> 8) & 0xFF) - asm.io_wait() diff --git a/Test/Kernel/platform/pch/rtc.vp b/Test/Kernel/platform/pch/rtc.vp deleted file mode 100644 index 52d98509..00000000 --- a/Test/Kernel/platform/pch/rtc.vp +++ /dev/null @@ -1,97 +0,0 @@ -from stdint import * -import t, c -import asm - - -RTC_CMOS_ADDR: t.CUInt16T = 0x70 -RTC_CMOS_DATA: t.CUInt16T = 0x71 - -RTC_REG_SECONDS: t.CDefine = 0x00 -RTC_REG_MINUTES: t.CDefine = 0x02 -RTC_REG_HOURS: t.CDefine = 0x04 -RTC_REG_DAY: t.CDefine = 0x07 -RTC_REG_MONTH: t.CDefine = 0x08 -RTC_REG_YEAR: t.CDefine = 0x09 -RTC_REG_STATUS_A: t.CDefine = 0x0A -RTC_REG_STATUS_B: t.CDefine = 0x0B - -RTC_TZ_OFFSET: t.CDefine = 8 - -rtc_seconds: t.CStatic | t.CVolatile | t.CUInt8T = 0 -rtc_minutes: t.CStatic | t.CVolatile | t.CUInt8T = 0 -rtc_hours: t.CStatic | t.CVolatile | t.CUInt8T = 0 -rtc_day: t.CStatic | t.CVolatile | t.CUInt8T = 0 -rtc_month: t.CStatic | t.CVolatile | t.CUInt8T = 0 -rtc_year: t.CStatic | t.CVolatile | t.CUInt16T = 0 - -def cmos_read(reg: t.CUInt8T) -> t.CUInt8T: - asm.outb(RTC_CMOS_ADDR, reg) - return asm.inb(RTC_CMOS_DATA) - -def bcd_to_bin(bcd: t.CUInt8T) -> t.CUInt8T: - return (bcd >> 4) * 10 + (bcd & 0x0F) - -def rtc_read_time(): - while cmos_read(RTC_REG_STATUS_A) & 0x80: pass - sec: t.CUInt8T = cmos_read(RTC_REG_SECONDS) - min_: t.CUInt8T = cmos_read(RTC_REG_MINUTES) - hour: t.CUInt8T = cmos_read(RTC_REG_HOURS) - day: t.CUInt8T = cmos_read(RTC_REG_DAY) - mon: t.CUInt8T = cmos_read(RTC_REG_MONTH) - year: t.CUInt8T = cmos_read(RTC_REG_YEAR) - reg_b: t.CUInt8T = cmos_read(RTC_REG_STATUS_B) - if not (reg_b & 0x04): - sec = bcd_to_bin(sec) - min_ = bcd_to_bin(min_) - hour = bcd_to_bin(hour) - day = bcd_to_bin(day) - mon = bcd_to_bin(mon) - year = bcd_to_bin(year) - if not (reg_b & 0x02) and (hour & 0x80): - hour = ((hour & 0x7F) + 12) % 24 - hour = hour + RTC_TZ_OFFSET - if hour >= 24: - hour = hour - 24 - day = day + 1 - max_day: t.CUInt8T = 31 - if mon == 4 or mon == 6 or mon == 9 or mon == 11: - max_day = 30 - elif mon == 2: - max_day = 28 - y4: t.CUInt16T = t.CUInt16T(year) + 2000 - if (y4 % 4 == 0 and y4 % 100 != 0) or (y4 % 400 == 0): - max_day = 29 - if day > max_day: - day = 1 - mon = mon + 1 - if mon > 12: - mon = 1 - year = year + 1 - global rtc_seconds, rtc_minutes, rtc_hours, rtc_day, rtc_month, rtc_year - rtc_seconds = sec - rtc_minutes = min_ - rtc_hours = hour - rtc_day = day - rtc_month = mon - rtc_year = t.CUInt16T(year) + 2000 - -def rtc_init(): - rtc_read_time() - -def rtc_get_hours() -> t.CUInt8T: - return rtc_hours - -def rtc_get_minutes() -> t.CUInt8T: - return rtc_minutes - -def rtc_get_seconds() -> t.CUInt8T: - return rtc_seconds - -def rtc_get_day() -> t.CUInt8T: - return rtc_day - -def rtc_get_month() -> t.CUInt8T: - return rtc_month - -def rtc_get_year() -> t.CUInt16T: - return rtc_year diff --git a/Test/Kernel/platform/pch/timer.vp b/Test/Kernel/platform/pch/timer.vp deleted file mode 100644 index 9b45895b..00000000 --- a/Test/Kernel/platform/pch/timer.vp +++ /dev/null @@ -1,102 +0,0 @@ -import platform.pch.pic as pic -import platform.pch.pit as pit -import sched.sched as sched -import asm -import t, c - -TIMER_FREQUENCY: t.CDefine = 1000 -TICKS_PER_SECOND: t.CDefine = TIMER_FREQUENCY -MILLISECONDS_PER_TICK: t.CDefine = (1000 / TIMER_FREQUENCY) - -ticks: t.CStatic | t.CVolatile | t.CUInt64T = 0 -seconds: t.CStatic | t.CVolatile | t.CUInt32T = 0 -milliseconds: t.CStatic | t.CVolatile | t.CUInt32T = 0 -timer_running: t.CStatic | t.CVolatile | bool = False - -def timer_init(): - global ticks, seconds, milliseconds, timer_running - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - ticks = 0 - seconds = 0 - milliseconds = 0 - timer_running = True - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - pit.pit_init(TIMER_FREQUENCY) - -def timer_handler(): - global ticks, seconds, milliseconds, timer_running - if not timer_running: - pic.eoi(0) - return - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - ticks = ticks + 1 - milliseconds = milliseconds + MILLISECONDS_PER_TICK - if milliseconds >= 1000: - seconds = seconds + 1 - milliseconds = milliseconds - 1000 - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - sched.Scheduler.sched_tick() - pic.eoi(0) - -def timer_start(): - global timer_running - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - timer_running = True - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - -def timer_stop(): - global timer_running - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - timer_running = False - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - -def timer_reset(): - global ticks, seconds, milliseconds - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - ticks = 0 - seconds = 0 - milliseconds = 0 - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - -def timer_get_ticks() -> t.CUInt64T: - current_ticks: t.CUInt64T - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - current_ticks = ticks - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - return current_ticks - -def timer_get_seconds() -> t.CUInt32T: - current_seconds: t.CUInt32T - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - current_seconds = seconds - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - return current_seconds - -def timer_get_milliseconds() -> t.CUInt32T: - current_milliseconds: t.CUInt32T - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - current_milliseconds = milliseconds - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - return current_milliseconds - -def timer_get_time(out_seconds: t.CUInt32T | t.CPtr, out_milliseconds: t.CUInt32T | t.CPtr): - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - if out_seconds: - c.Set(c.Deref(out_seconds), seconds) - if out_milliseconds: - c.Set(c.Deref(out_milliseconds), milliseconds) - c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY]) - -def timer_msleep(ms: t.CUInt32T): - target: t.CUInt64T = ticks + (ms + MILLISECONDS_PER_TICK - 1) / MILLISECONDS_PER_TICK - while ticks < target: - asm.sti() - asm.hlt() - sched.Scheduler._yield() - -def timer_sleep(sec: t.CUInt32T): - target: t.CUInt64T = ticks + sec * TICKS_PER_SECOND - while ticks < target: - asm.sti() - asm.hlt() - sched.Scheduler._yield() diff --git a/Test/Kernel/sched/coroutine.vp b/Test/Kernel/sched/coroutine.vp deleted file mode 100644 index 506e6a8b..00000000 --- a/Test/Kernel/sched/coroutine.vp +++ /dev/null @@ -1,202 +0,0 @@ -import mm -import drivers.serial.uart.serial as serial -import asm -import t, c - -CORO_READY: t.CDefine = 0 -CORO_RUNNING: t.CDefine = 1 -CORO_YIELDED: t.CDefine = 2 -CORO_DONE: t.CDefine = 3 -MAX_COROUTINES: t.CDefine = 32 -CORO_STACK_SIZE: t.CDefine = 8192 - - -@t.Object -class Coroutine: - rsp: t.CUInt64T - stack: t.CVoid | t.CPtr - stack_size: t.CUInt64T - func: t.CVoid | t.CPtr - arg: t.CVoid | t.CPtr - state: t.CInt - cid: t.CInt - caller_rsp: t.CUInt64T - ret_val: t.CInt - - def resume(self) -> t.CInt: - global _coro_old_rsp, _coro_new_rsp - m: CoroutineManager | t.CPtr = _coro_mgr_ptr - if self.state == CORO_DONE: return self.ret_val - if self.state != CORO_READY and self.state != CORO_YIELDED: return -1 - prev_cid: t.CInt = m.current_cid - m.current_cid = self.cid - self.state = CORO_RUNNING - _coro_old_rsp = c.Addr(m.coroutines[prev_cid].rsp) - _coro_new_rsp = c.Addr(self.rsp) - self.caller_rsp = t.CUInt64T(_coro_old_rsp) - _coro_switch() - if self.state == CORO_DONE: - return self.ret_val - return 0 - - @staticmethod - def _yield(): - global _coro_old_rsp, _coro_new_rsp - m: CoroutineManager | t.CPtr = _coro_mgr_ptr - cid: t.CInt = m.current_cid - if cid < 0: return - m.coroutines[cid].state = CORO_YIELDED - prev_cid: t.CInt = -1 - i: t.CInt - for i in range(m.count): - if m.coroutines[i].state == CORO_RUNNING and m.coroutines[i].caller_rsp != 0: - prev_cid = i - break - if prev_cid < 0: return - m.current_cid = prev_cid - _coro_old_rsp = c.Addr(m.coroutines[cid].rsp) - _coro_new_rsp = c.Addr(m.coroutines[prev_cid].rsp) - _coro_switch() - - @property - def is_done(self) -> t.CInt: - if self.state == CORO_DONE: - return 1 - return 0 - - @property - def is_yielded(self) -> t.CInt: - if self.state == CORO_YIELDED: - return 1 - return 0 - - @property - def retval(self) -> t.CInt: - return self.ret_val - - -@t.Object -class CoroutineManager: - coroutines: t.CArray[Coroutine, MAX_COROUTINES] - current_cid: t.CInt - count: t.CInt - - def __init__(): - global _coro_mgr_ptr - _coro_mgr_ptr = c.Addr(_coro_mgr) - m: CoroutineManager | t.CPtr = _coro_mgr_ptr - m.current_cid = 0 - m.count = 1 - m.coroutines[0].state = CORO_RUNNING - m.coroutines[0].cid = 0 - m.coroutines[0].caller_rsp = 0 - m.coroutines[0].ret_val = 0 - m.coroutines[0].rsp = 0 - m.coroutines[0].stack = None - m.coroutines[0].stack_size = 0 - m.coroutines[0].func = None - m.coroutines[0].arg = None - main_rsp_ptr: t.CVoid | t.CPtr = c.Addr(m.coroutines[0].rsp) - c.Asm(f"""mov qword ptr [{c.AsmInp(main_rsp_ptr, t.ASM_DESCR.REG_ANY)}], rsp""", - op=[t.ASM_DESCR.CLOBBER_MEMORY]) - - @staticmethod - def current() -> Coroutine | t.CPtr: - m: CoroutineManager | t.CPtr = _coro_mgr_ptr - return c.Addr(m.coroutines[m.current_cid]) - - @staticmethod - def get_coroutine(cid: t.CInt) -> Coroutine | t.CPtr: - m: CoroutineManager | t.CPtr = _coro_mgr_ptr - if cid < 0 or cid >= m.count: return None - return c.Addr(m.coroutines[cid]) - - @staticmethod - def create(func: t.CVoid | t.CPtr, arg: t.CVoid | t.CPtr) -> Coroutine | t.CPtr: - m: CoroutineManager | t.CPtr = _coro_mgr_ptr - if m.count >= MAX_COROUTINES: return None - cid: t.CInt = m.count - m.count += 1 - co: Coroutine | t.CPtr = c.Addr(m.coroutines[cid]) - co.state = CORO_READY - co.cid = cid - co.func = func - co.arg = arg - co.caller_rsp = 0 - co.ret_val = 0 - stack_ptr: t.CVoid | t.CPtr = mm.malloc(CORO_STACK_SIZE) - if not stack_ptr: return None - co.stack = stack_ptr - co.stack_size = CORO_STACK_SIZE - stack_top: t.CUInt64T = t.CUInt64T(stack_ptr) + CORO_STACK_SIZE - 16 - stack_top = stack_top & ~t.CUInt64T(0xF) - entry_addr: t.CUInt64T = t.CUInt64T(c.Addr(_coro_entry)) - sp: t.CPtr = t.CPtr(stack_top) - c.Asm(f"""mov rax, {c.AsmInp(sp, t.ASM_DESCR.REG_ANY)} - mov qword ptr [rax - 56], 0 - mov qword ptr [rax - 48], 0 - mov qword ptr [rax - 40], 0 - mov qword ptr [rax - 32], 0 - mov qword ptr [rax - 24], 0 - mov qword ptr [rax - 16], 0 - mov qword ptr [rax - 8], 0 - mov qword ptr [rax], {c.AsmInp(entry_addr, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX]) - stack_top = stack_top - 56 - co.rsp = stack_top - return co - - -_coro_mgr: CoroutineManager = CoroutineManager() -_coro_mgr_ptr: CoroutineManager | t.CPtr = c.Addr(_coro_mgr) -_coro_old_rsp: t.CVoid | t.CPtr -_coro_new_rsp: t.CVoid | t.CPtr - -@c.Attribute(t.attr.naked) -def _coro_switch(): - c.Asm(f"""push rax - push rbx - push rbp - push r12 - push r13 - push r14 - push r15 - mov rax, qword ptr [rip + _coro_old_rsp] - mov qword ptr [rax], rsp - mov rax, qword ptr [rip + _coro_new_rsp] - mov rsp, qword ptr [rax] - pop r15 - pop r14 - pop r13 - pop r12 - pop rbp - pop rbx - pop rax - ret""", - op=[t.ASM_DESCR.CLOBBER_MEMORY]) - -@c.Attribute(t.attr.naked) -def _coro_entry(): - c.Asm(f"""sub rsp, 8 - mov rax, qword ptr [rip + _coro_mgr_ptr] - mov ecx, dword ptr [rax + 1056] - movsxd rcx, ecx - shl rcx, 5 - mov rdi, qword ptr [rax + rcx + 24] - mov rax, qword ptr [rax + rcx + 16] - call rax - mov rax, qword ptr [rip + _coro_mgr_ptr] - mov ecx, dword ptr [rax + 1056] - movsxd rcx, ecx - shl rcx, 5 - mov dword ptr [rax + rcx + 32], 3 - mov dword ptr [rax + rcx + 48], eax - add rsp, 8""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11]) - Coroutine._yield() - while True: - asm.sti() - asm.hlt() diff --git a/Test/Kernel/sched/process.vp b/Test/Kernel/sched/process.vp deleted file mode 100644 index 18c59e52..00000000 --- a/Test/Kernel/sched/process.vp +++ /dev/null @@ -1,277 +0,0 @@ -import mm -import mm.mm as mm_mm -import paging.paging as paging -import drivers.serial.uart.serial as serial -import drivers.fs.fat32.fat32 as fat32 -import drivers.fs.fat32.fat32_types as fat32_types -import drivers.core.cpu.cpu as cpu -import intr.gdt as gdt -import viperlib -import string -import t, c - -PROC_READY: t.CDefine = 0 -PROC_RUNNING: t.CDefine = 1 -PROC_BLOCKED: t.CDefine = 2 -PROC_DONE: t.CDefine = 3 -MAX_PROCESSES: t.CDefine = 8 -MAX_PROC_THREADS: t.CDefine = 8 -PROC_MAX_FDS: t.CDefine = 16 -PROC_MAX_DIRS: t.CDefine = 8 -KERN_STACK_SIZE: t.CDefine = 8192 -USER_STACK_SIZE: t.CDefine = 65536 - - -@t.Object -class Process: - pid: t.CInt - pml4_root: t.CUInt64T - threads: t.CArray[t.CInt, 8] - thread_count: t.CInt - state: t.CInt - entry: t.CVoid | t.CPtr - elf_base: t.CUInt64T - heap_start: t.CUInt64T - heap_size: t.CUInt64T - name: t.CArray[t.CChar, 32] - fd_table: t.CArray[t.CVoid | t.CPtr, PROC_MAX_FDS] - fd_used: t.CArray[t.CUInt8T, PROC_MAX_FDS] - dir_table: t.CArray[t.CVoid | t.CPtr, PROC_MAX_DIRS] - dir_used: t.CArray[t.CUInt8T, PROC_MAX_DIRS] - dir_pool: t.CArray[fat32_types.dirobj, PROC_MAX_DIRS] - kern_stack: t.CUInt64T - user_stack: t.CUInt64T - - def addThread(self, tid: t.CInt) -> t.CInt: - if self.thread_count >= MAX_PROC_THREADS: return -1 - self.threads[self.thread_count] = tid - self.thread_count += 1 - return 0 - - def exit(self): - self.state = PROC_DONE - for i in range(PROC_MAX_FDS): - if self.fd_used[i]: - fp: t.CVoid | t.CPtr = self.fd_table[i] - if fp: - fat32.close(fp) - self.fd_used[i] = 0 - self.fd_table[i] = t.CVoid(0, t.CPtr) - for i in range(PROC_MAX_DIRS): - if self.dir_used[i]: - dp: t.CVoid | t.CPtr = self.dir_table[i] - if dp: - fat32.closedir(dp) - self.dir_used[i] = 0 - self.dir_table[i] = t.CVoid(0, t.CPtr) - m: ProcessManager | t.CPtr = _proc_mgr_ptr - if m.current_pid == self.pid: - m.current_pid = 0 - m.processes[0].state = PROC_RUNNING - if self.pml4_root != 0: - kernel_cr3: t.CUInt64T = m.processes[0].pml4_root - if kernel_cr3 != 0: - c.Asm(f"mov cr3, {c.AsmInp(kernel_cr3, t.ASM_DESCR.REG_ANY)}", - op=[t.ASM_DESCR.CLOBBER_MEMORY]) - paging.set_active_pml4(kernel_cr3) - - @property - def is_running(self) -> t.CInt: - if self.state == PROC_RUNNING: - return 1 - return 0 - - @property - def is_done(self) -> t.CInt: - if self.state == PROC_DONE: - return 1 - return 0 - - -@t.Object -class ProcessManager: - processes: t.CArray[Process, MAX_PROCESSES] - current_pid: t.CInt - count: t.CInt - - def __init__(self): - global _proc_mgr_ptr - _proc_mgr_ptr = c.Addr(_proc_mgr) - m: ProcessManager | t.CPtr = _proc_mgr_ptr - m.current_pid = 0 - m.count = 1 - p: Process | t.CPtr = c.Addr(m.processes[0]) - p.pid = 0 - p.state = PROC_RUNNING - p.thread_count = 0 - p.pml4_root = 0 - p.entry = None - p.elf_base = 0 - p.heap_start = 0 - p.heap_size = 0 - name_str: str = "kernel" - i: t.CInt = 0 - for ch in name_str: - if i >= 31: break - p.name[i] = ch - i += 1 - p.name[i] = 0 - j: t.CInt - for j in range(MAX_PROC_THREADS): - p.threads[j] = -1 - for j in range(PROC_MAX_FDS): - p.fd_used[j] = 0 - p.fd_table[j] = t.CVoid(0, t.CPtr) - for j in range(PROC_MAX_DIRS): - p.dir_used[j] = 0 - p.dir_table[j] = t.CVoid(0, t.CPtr) - c.Asm(f"""mov {c.AsmOut(p.pml4_root, t.ASM_DESCR.OUTPUT_REG)}, cr3""", - op=[t.ASM_DESCR.CLOBBER_MEMORY]) - - @staticmethod - def _switch(pid: t.CInt) -> t.CInt: - global _saved_cr3 - m: ProcessManager | t.CPtr = _proc_mgr_ptr - if pid < 0 or pid >= m.count: return -1 - p: Process | t.CPtr = c.Addr(m.processes[pid]) - if p.state == PROC_DONE: return -1 - old_pid: t.CInt = m.current_pid - if old_pid == pid: return 0 - if old_pid >= 0 and old_pid < m.count: - m.processes[old_pid].state = PROC_READY - p.state = PROC_RUNNING - m.current_pid = pid - c.Asm(f"""mov {c.AsmOut(_saved_cr3, t.ASM_DESCR.OUTPUT_REG)}, cr3 - mov rax, {c.AsmInp(p.pml4_root, t.ASM_DESCR.REG_ANY)} - mov cr3, rax""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX]) - return 0 - - @staticmethod - def current() -> Process | t.CPtr: - m: ProcessManager | t.CPtr = _proc_mgr_ptr - return c.Addr(m.processes[m.current_pid]) - - @staticmethod - def get_process(pid: t.CInt) -> Process | t.CPtr: - m: ProcessManager | t.CPtr = _proc_mgr_ptr - if pid < 0 or pid >= m.count: return None - return c.Addr(m.processes[pid]) - - @staticmethod - def create_process(name: str, entry: t.CVoid | t.CPtr) -> Process | t.CPtr: - m: ProcessManager | t.CPtr = _proc_mgr_ptr - _dbp: t.CArray[t.CChar, 80] - viperlib.snprintf(c.Addr(_dbp), 80, "[process] create_process count=%d MAX=%d\n", m.count, MAX_PROCESSES) - serial.puts(_dbp) - if m.count >= MAX_PROCESSES: return None - pid: t.CInt = m.count - m.count += 1 - p: Process | t.CPtr = c.Addr(m.processes[pid]) - p.pid = pid - p.state = PROC_READY - p.entry = entry - p.elf_base = 0 - p.thread_count = 0 - p.heap_start = 0 - p.heap_size = 0 - string.memset(c.Addr(p.name), 0, 32) - i: t.CInt = 0 - for ch in name: - if i >= 31: break - p.name[i] = ch - i += 1 - p.name[i] = 0 - j: t.CInt - for j in range(MAX_PROC_THREADS): - p.threads[j] = -1 - for j in range(PROC_MAX_FDS): - p.fd_used[j] = 0 - p.fd_table[j] = t.CVoid(0, t.CPtr) - for j in range(PROC_MAX_DIRS): - p.dir_used[j] = 0 - p.dir_table[j] = t.CVoid(0, t.CPtr) - ks: t.CVoid | t.CPtr = mm_mm.malloc(KERN_STACK_SIZE) - if ks is None: - serial.puts("[process] kernel stack alloc failed\n") - m.count = m.count - 1 - return None - ks_size: t.CUInt64T = KERN_STACK_SIZE - p.kern_stack = t.CUInt64T(ks) + ks_size - us: t.CVoid | t.CPtr = mm_mm.malloc(USER_STACK_SIZE) - if us is None: - serial.puts("[process] user stack alloc failed\n") - mm_mm.free(ks) - m.count = m.count - 1 - return None - us_size: t.CUInt64T = USER_STACK_SIZE - p.user_stack = t.CUInt64T(us) + us_size - c.Asm(f"""mov {c.AsmOut(p.pml4_root, t.ASM_DESCR.OUTPUT_REG)}, cr3""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX]) - return p - - -_proc_mgr: ProcessManager = ProcessManager() -_proc_mgr_ptr: ProcessManager | t.CPtr = c.Addr(_proc_mgr) -_saved_cr3: t.CUInt64T - -def current() -> t.CInt: - m: ProcessManager | t.CPtr = _proc_mgr_ptr - return m.current_pid - -def switch_pid(new_pid: t.CInt): - m: ProcessManager | t.CPtr = _proc_mgr_ptr - if m.current_pid == new_pid: return - if m.current_pid >= 0 and m.current_pid < m.count: - old_p: Process | t.CPtr = c.Addr(m.processes[m.current_pid]) - if old_p.state != PROC_DONE: - old_p.state = PROC_READY - if new_pid >= 0 and new_pid < m.count: - new_p: Process | t.CPtr = c.Addr(m.processes[new_pid]) - new_p.state = PROC_RUNNING - new_cr3: t.CUInt64T = new_p.pml4_root - if new_cr3 != 0: - c.Asm(f"mov cr3, {c.AsmInp(new_cr3, t.ASM_DESCR.REG_ANY)}", - op=[t.ASM_DESCR.CLOBBER_MEMORY]) - paging.set_active_pml4(new_cr3) - # Update TSS RSP0 and GS kernel_rsp0 for the new process - # This is needed so interrupts from Ring 3 use the correct kernel stack - if new_p.kern_stack != 0: - gdt.set_tss_rsp0(new_p.kern_stack) - cpu.set_kernel_rsp0(new_p.kern_stack) - m.current_pid = new_pid - -def get_pid(tid: t.CInt) -> t.CInt: - m: ProcessManager | t.CPtr = _proc_mgr_ptr - i: t.CInt - for i in range(m.count): - p: Process | t.CPtr = c.Addr(m.processes[i]) - j: t.CInt - for j in range(p.thread_count): - if p.threads[j] == tid: - return p.pid - return -1 - -def drop_to_user_mode(entry: t.CVoid | t.CPtr, user_rsp: t.CUInt64T, kern_rsp: t.CUInt64T): - # NOTE: Do NOT swapgs here. This OS uses reverse GS convention: - # GS_BASE = 0 (kernel & user), KERNEL_GS_BASE = &_per_cpu - # syscall/ISR entry does swapgs to get GS_BASE = &_per_cpu - # syscall/ISR return does swapgs to restore GS_BASE = 0 - # GS state is restored in isrCommonhandler before _yield() if needed. - c.Asm(f"""cli - mov rsp, {c.AsmInp(kern_rsp, t.ASM_DESCR.REG_ANY)} - mov rdx, {c.AsmInp(user_rsp, t.ASM_DESCR.REG_ANY)} - mov rcx, {c.AsmInp(entry, t.ASM_DESCR.REG_ANY)} - mov r11, 0x202 - push 0x23 - push rdx - push r11 - push 0x1B - push rcx - iretq""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R11, t.ASM_DESCR.CLOBBER_RSI, - t.ASM_DESCR.CLOBBER_RDI, t.ASM_DESCR.CLOBBER_R8, - t.ASM_DESCR.CLOBBER_R9, t.ASM_DESCR.CLOBBER_R10, - t.ASM_DESCR.CLOBBER_RBP]) diff --git a/Test/Kernel/sched/sched.vp b/Test/Kernel/sched/sched.vp deleted file mode 100644 index 606d5dc9..00000000 --- a/Test/Kernel/sched/sched.vp +++ /dev/null @@ -1,299 +0,0 @@ -import mm -import asm -import sched.process as proc -import drivers.serial.uart.serial as serial -import viperlib -import t, c - - -THREAD_READY: t.CDefine = 0 -THREAD_RUNNING: t.CDefine = 1 -THREAD_BLOCKED: t.CDefine = 2 -THREAD_DONE: t.CDefine = 3 -MAX_THREADS: t.CDefine = 16 -THREAD_STACK_SIZE: t.CDefine = 65536 -SCHED_QUANTUM: t.CDefine = 10 - -_yield_cnt: t.CUInt32T = 0 -_yield_lock: t.CInt = 0 - - -@t.Object -class Thread: - rsp: t.CUInt64T - stack: t.CVoid | t.CPtr - stack_size: t.CUInt64T - func: t.CVoid | t.CPtr - arg: t.CVoid | t.CPtr - state: t.CInt - tid: int - pid: t.CInt - - def block(self): - self.state = THREAD_BLOCKED - Scheduler._yield() - - def unblock(self): - if self.state == THREAD_BLOCKED: - self.state = THREAD_READY - - @property - def is_running(self) -> t.CInt: - if self.state == THREAD_RUNNING: - return 1 - return 0 - - @property - def is_blocked(self) -> t.CInt: - if self.state == THREAD_BLOCKED: - return 1 - return 0 - - @property - def is_done(self) -> t.CInt: - if self.state == THREAD_DONE: - return 1 - return 0 - - -@t.Object -class Scheduler: - threads: t.CArray[Thread, MAX_THREADS] - current_tid: t.CInt - thread_count: t.CInt - enabled: t.CInt - needs_reschedule: t.CInt - tick_count: t.CInt - - def __init__(self): - global _sched_ptr - _sched_ptr = c.Addr(_sched_storage) - s: Scheduler | t.CPtr = _sched_ptr - s.current_tid = 0 - s.thread_count = 1 - s.enabled = 0 - s.needs_reschedule = 0 - s.tick_count = 0 - i: int - for i in range(MAX_THREADS): - s.threads[i].rsp = 0 - s.threads[i].stack = None - s.threads[i].stack_size = 0 - s.threads[i].func = None - s.threads[i].arg = None - s.threads[i].state = THREAD_DONE - s.threads[i].tid = i - s.threads[i].pid = 0 - s.enabled = 1 - s.threads[0].state = THREAD_RUNNING - s.threads[0].tid = 0 - main_rsp_ptr: t.CVoid | t.CPtr = c.Addr(s.threads[0].rsp) - c.Asm(f"""mov qword ptr [{c.AsmInp(main_rsp_ptr, t.ASM_DESCR.REG_ANY)}], rsp""", - op=[t.ASM_DESCR.CLOBBER_MEMORY]) - - @staticmethod - def _yield(): - global _switch_old_rsp, _switch_new_rsp, _yield_cnt, _yield_lock - _if_saved: t.CInt = 0 - c.Asm(f"""pushfq - pop rax - shr rax, 9 - and eax, 1 - mov {c.AsmOut(_if_saved, t.ASM_DESCR.OUTPUT_REG)}, eax""", - op=[t.ASM_DESCR.CLOBBER_RAX]) - asm.cli() - if _yield_lock: - if _if_saved: - asm.sti() - return - _yield_lock = 1 - s: Scheduler | t.CPtr = _sched_ptr - s.needs_reschedule = 0 - s.tick_count = 0 - old_tid: t.CInt = s.current_tid - next_tid: t.CInt = old_tid + 1 - if next_tid >= s.thread_count: - next_tid = 0 - found: t.CInt = 0 - count: t.CInt = 0 - while count < s.thread_count: - st: t.CInt = s.threads[next_tid].state - if st == THREAD_READY or st == THREAD_RUNNING: - found = 1 - break - next_tid += 1 - if next_tid >= s.thread_count: - next_tid = 0 - count += 1 - if found == 0: - _yield_lock = 0 - if _if_saved: - asm.sti() - return - if next_tid == old_tid: - _yield_lock = 0 - if _if_saved: - asm.sti() - return - if s.threads[old_tid].state == THREAD_RUNNING: - s.threads[old_tid].state = THREAD_READY - s.threads[next_tid].state = THREAD_RUNNING - _switch_old_rsp = c.Addr(s.threads[old_tid].rsp) - _switch_new_rsp = c.Addr(s.threads[next_tid].rsp) - s.current_tid = next_tid - next_pid: t.CInt = s.threads[next_tid].pid - _yield_cnt += 1 - proc.switch_pid(next_pid) - _yield_lock = 0 - _do_switch() - if _if_saved: - asm.sti() - - @staticmethod - def sched_tick(): - s: Scheduler | t.CPtr = _sched_ptr - if not s.enabled: return - if s.thread_count <= 1: return - s.tick_count += 1 - if s.tick_count >= SCHED_QUANTUM: - s.tick_count = 0 - s.needs_reschedule = 1 - - @staticmethod - def try_reschedule(): - s: Scheduler | t.CPtr = _sched_ptr - if s.needs_reschedule: - s.needs_reschedule = 0 - Scheduler._yield() - - @staticmethod - def disable(): - s: Scheduler | t.CPtr = _sched_ptr - s.enabled = 0 - - @staticmethod - def enable(): - s: Scheduler | t.CPtr = _sched_ptr - s.enabled = 1 - - @staticmethod - def current() -> Thread | t.CPtr: - s: Scheduler | t.CPtr = _sched_ptr - return c.Addr(s.threads[s.current_tid]) - - @staticmethod - def get_thread(tid: t.CInt) -> Thread | t.CPtr: - s: Scheduler | t.CPtr = _sched_ptr - if tid < 0 or tid >= s.thread_count: return None - return c.Addr(s.threads[tid]) - - @staticmethod - def create_thread(func: t.CVoid | t.CPtr, arg: t.CVoid | t.CPtr, thread_pid: t.CInt = 0) -> Thread | t.CPtr: - s: Scheduler | t.CPtr = _sched_ptr - if s.thread_count >= MAX_THREADS: return None - tid: int = s.thread_count - s.thread_count += 1 - th: Thread | t.CPtr = c.Addr(s.threads[tid]) - th.state = THREAD_READY - th.tid = tid - th.pid = thread_pid - th.func = func - th.arg = arg - stack_size: t.CUInt64T = THREAD_STACK_SIZE - stack_ptr: t.CVoid | t.CPtr = mm.malloc(stack_size) - if not stack_ptr: return None - th.stack = stack_ptr - th.stack_size = stack_size - stack_top: t.CUInt64T = t.CUInt64T(stack_ptr) + stack_size - 16 - stack_top = stack_top & ~t.CUInt64T(0xF) - entry_addr: t.CUInt64T = t.CUInt64T(c.Addr(_thread_entry)) - sp: t.CPtr = t.CPtr(stack_top) - c.Asm(f"""mov rax, {c.AsmInp(sp, t.ASM_DESCR.REG_ANY)} - mov qword ptr [rax - 64], 0x202 - mov qword ptr [rax - 56], 0 - mov qword ptr [rax - 48], 0 - mov qword ptr [rax - 40], 0 - mov qword ptr [rax - 32], 0 - mov qword ptr [rax - 24], 0 - mov qword ptr [rax - 16], 0 - mov qword ptr [rax - 8], 0 - mov qword ptr [rax], {c.AsmInp(entry_addr, t.ASM_DESCR.REG_ANY)}""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX]) - stack_top = stack_top - 64 - th.rsp = stack_top - return th - - -_sched_storage: Scheduler = Scheduler() -_sched_ptr: Scheduler | t.CPtr = c.Addr(_sched_storage) -_switch_old_rsp: t.CVoid | t.CPtr -_switch_new_rsp: t.CVoid | t.CPtr - -@c.Attribute(t.attr.naked) -def _do_switch(): - c.Asm(f"""push rax - push rbx - push rbp - push r12 - push r13 - push r14 - push r15 - pushfq - mov rax, qword ptr [rip + _switch_old_rsp] - mov qword ptr [rax], rsp - mov rax, qword ptr [rip + _switch_new_rsp] - mov rsp, qword ptr [rax] - popfq - pop r15 - pop r14 - pop r13 - pop r12 - pop rbp - pop rbx - pop rax - ret""", - op=[t.ASM_DESCR.CLOBBER_MEMORY]) - -@c.Attribute(t.attr.naked) -def _thread_entry(): - c.Asm(f"""sub rsp, 8 - mov rax, qword ptr [rip + _sched_ptr] - mov ecx, dword ptr [rax + 896] - movsxd rcx, ecx - imul rcx, rcx, 56 - mov rdi, qword ptr [rax + rcx + 32] - mov rax, qword ptr [rax + rcx + 24] - call rax - mov rax, qword ptr [rip + _sched_ptr] - mov ecx, dword ptr [rax + 896] - movsxd rcx, ecx - imul rcx, rcx, 56 - mov dword ptr [rax + rcx + 40], 3 - add rsp, 8""", - op=[t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX, - t.ASM_DESCR.CLOBBER_RCX, t.ASM_DESCR.CLOBBER_RDX, - t.ASM_DESCR.CLOBBER_R8, t.ASM_DESCR.CLOBBER_R9, - t.ASM_DESCR.CLOBBER_R10, t.ASM_DESCR.CLOBBER_R11]) - Scheduler._yield() - while True: - asm.sti() - asm.hlt() - Scheduler._yield() - -def thread_current() -> t.CInt: - s: Scheduler | t.CPtr = _sched_ptr - return s.current_tid - -def needs_reschedule() -> t.CInt: - s: Scheduler | t.CPtr = _sched_ptr - return s.needs_reschedule - -def sched_dump(): - s: Scheduler | t.CPtr = _sched_ptr - dl: t.CArray[t.CChar, 80] - viperlib.snprintf(c.Addr(dl), 80, "[sched] dump: cur=%d cnt=%d yields=%u\n", s.current_tid, s.thread_count, _yield_cnt) - serial.puts(dl) - for i in range(s.thread_count): - sl: t.CArray[t.CChar, 80] - viperlib.snprintf(c.Addr(sl), 80, " t%d: st=%d pid=%d rsp=0x%lx\n", i, s.threads[i].state, s.threads[i].pid, s.threads[i].rsp) - serial.puts(sl) diff --git a/Test/Kernel/services/desktop.vp b/Test/Kernel/services/desktop.vp deleted file mode 100644 index 6f34f75b..00000000 --- a/Test/Kernel/services/desktop.vp +++ /dev/null @@ -1,2714 +0,0 @@ -from stdint import * -import asm -import drivers.video.vesafb.gfx as gfx -import drivers.video.vesafb.vga as vga -import drivers.input.mouse.mouse as mouse -import drivers.input.keyboard.keyboard as keyboard -import drivers.usb.hid.usb_mouse as usb_mouse -import drivers.usb.hid.usb_kbd as usb_kbd -import drivers.serial.uart.serial as serial -import platform.pch.pic as pic -import platform.pch.timer as timer -import platform.pch.rtc as rtc -import sched.sched as sched -import sched.process as process -import mm.mm as mm -import string -import viperlib -import t, c - - -TASKBAR_HEIGHT: t.CDefine = 50 -CURSOR_SIZE: t.CDefine = 16 -CURSOR_W: t.CDefine = 16 -CURSOR_H: t.CDefine = 16 -CURSOR_SAVE_SIZE: t.CDefine = 256 -TITLE_HEIGHT_CLASSIC: t.CDefine = 24 -TITLE_HEIGHT_WIN: t.CDefine = 32 -MAX_APP_WINDOWS: t.CDefine = 16 -CLOSE_BTN_SIZE: t.CDefine = 16 -CLOSE_BTN_W_WIN: t.CDefine = 46 -CLOSE_BTN_W7_W: t.CDefine = 28 -CLOSE_BTN_W7_H: t.CDefine = 20 -CLOSE_BTN_W7_R: t.CDefine = 3 -CLOSE_BTN_XP_SZ: t.CDefine = 21 -TITLE_BTN_W_WIN: t.CDefine = 46 -TITLE_BTN_W7: t.CDefine = 28 -TITLE_BTN_XP: t.CDefine = 21 -TASKBAR_ICON_SZ: t.CDefine = 36 -TASKBAR_ICON_PAD: t.CDefine = 6 -TASKBAR_LOGO_SZ: t.CDefine = 32 -WIN_RADIUS: t.CDefine = 8 -SHADOW_ENABLED: t.CDefine = False -SHADOW_LEFT: t.CDefine = 8 -SHADOW_RIGHT: t.CDefine = 12 -SHADOW_TOP: t.CDefine = 4 -SHADOW_BOTTOM: t.CDefine = 14 -SHADOW_ALPHA: t.CDefine = 100 -CURSOR_SHADOW_ALPHA: t.CDefine = 50 - -STYLE_CLASSIC: t.CDefine = 0 -STYLE_WIN10: t.CDefine = 1 -STYLE_WIN11: t.CDefine = 2 -STYLE_WIN7: t.CDefine = 3 -STYLE_WINXP: t.CDefine = 4 - -_fb: UINT32PTR -_screen_w: t.CInt = 0 -_screen_h: t.CInt = 0 -_fb_pitch: t.CInt = 0 -_cursor_x: t.CInt = 512 -_cursor_y: t.CInt = 300 -_cursor_buttons: t.CUInt8T = 0 -_back_fb: UINT32PTR -_last_time_sec: t.CUInt32T = 0 -_row_buf: UINT32PTR -_bg_row_buf: UINT32PTR -@t.Object -class AppWindow: - active: t.CInt - x: t.CInt - y: t.CInt - w: t.CInt - h: t.CInt - title: t.CArray[t.CChar, 32] - orig_title: t.CArray[t.CChar, 32] - content_h: t.CInt - fb: UINT32PTR - fb_w: t.CInt - fb_h: t.CInt - z_order: t.CInt - style: t.CInt - close_hover: t.CInt - min_hover: t.CInt - max_hover: t.CInt - is_maximized: t.CInt - orig_x: t.CInt - orig_y: t.CInt - orig_w: t.CInt - orig_h: t.CInt - pid: t.CInt - cursor_type: t.CInt - app_cursor_type: t.CInt - ping_pending: t.CInt - no_resp: t.CInt - no_resp_sec: t.CUInt32T - minimized: t.CInt - resizable_w: t.CInt - resizable_h: t.CInt - resize_w: t.CInt - resize_h: t.CInt - old_fb: UINT32PTR - -_wins: t.CArray[AppWindow, MAX_APP_WINDOWS] -_win_count: t.CInt = 0 -_next_z: t.CInt = 1 -_current_app_pid: t.CInt = 0 -HB_INTERVAL_SEC: t.CUInt32T = 5 -HB_NO_RESP_SEC: t.CUInt32T = 30 -_hb_last_sec: t.CUInt32T = 0 -_dirty_rows: t.CUInt8T | t.CPtr = t.CUInt8T(0, t.CPtr) -_dirty_count: t.CInt = 0 -_dirty_y_min: t.CInt = 0 -_dirty_y_max: t.CInt = -1 -_vblank_ok: t.CInt = -1 -_prev_cursor_x: t.CInt = 512 -_prev_cursor_y: t.CInt = 300 -_cursor_save_buf: t.CArray[t.CUInt32T, 256] -_cursor_saved: t.CInt = 0 - -_CURSOR_ARROW: t.CArray[t.CUInt8T, 256] = [ - 1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 1,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0, - 1,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0, - 1,2,2,2,1,0,0,0,0,0,0,0,0,0,0,0, - 1,2,2,2,2,1,0,0,0,0,0,0,0,0,0,0, - 1,2,2,2,2,2,1,0,0,0,0,0,0,0,0,0, - 1,2,2,2,2,2,2,1,0,0,0,0,0,0,0,0, - 1,2,2,2,2,2,2,2,1,0,0,0,0,0,0,0, - 1,2,2,2,2,2,2,2,2,1,0,0,0,0,0,0, - 1,2,2,2,1,1,1,1,1,1,0,0,0,0,0,0, - 1,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0, - 1,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0, - 1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -] - -_CURSOR_IBEAM: t.CArray[t.CUInt8T, 256] = [ - 0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0, - 0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0, - 0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0, -] - -_CURSOR_RESIZE_EW: t.CArray[t.CUInt8T, 256] = [ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,1,1,1,0,0,0,0,0, - 0,0,0,1,2,2,1,1,1,2,2,1,0,0,0,0, - 0,0,1,2,2,2,2,2,2,2,2,2,1,0,0,0, - 0,1,2,2,2,2,2,2,2,2,2,2,2,1,0,0, - 0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0, - 0,1,2,2,2,2,2,2,2,2,2,2,2,1,0,0, - 0,0,1,2,2,2,2,2,2,2,2,2,1,0,0,0, - 0,0,0,1,2,2,1,1,1,2,2,1,0,0,0,0, - 0,0,0,0,1,1,1,0,1,1,1,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -] - -_CURSOR_RESIZE_NS: t.CArray[t.CUInt8T, 256] = [ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,1,2,2,1,0,0,0,0,0,0,0,0,0, - 0,0,1,2,2,2,2,1,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,1,2,2,2,2,1,0,0,0,0,0,0,0,0, - 0,0,0,1,2,2,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -] - -_CURSOR_RESIZE_NWSE: t.CArray[t.CUInt8T, 256] = [ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0, - 0,1,2,1,1,0,0,0,0,0,0,0,0,0,0,0, - 0,0,1,2,2,1,0,0,0,0,0,0,0,0,0,0, - 0,0,0,1,2,2,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,1,2,2,1,1,0,0,0,0,0,0,0, - 0,0,0,0,0,1,2,2,1,0,0,0,0,0,0,0, - 0,0,0,0,0,0,1,2,2,1,0,0,0,0,0,0, - 0,0,0,0,0,0,0,1,2,2,1,0,0,0,0,0, - 0,0,0,0,0,0,0,0,1,2,2,1,0,0,0,0, - 0,0,0,0,0,0,0,0,0,1,2,2,1,0,0,0, - 0,0,0,0,0,0,0,0,0,0,1,2,1,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -] -_last_clock_sec: t.CUInt32T = 0 -_prev_btn: t.CUInt8T = 0 - -EVENT_QUEUE_SIZE: t.CDefine = 32 -EVENT_TYPE_NONE: t.CDefine = 0 -EVENT_TYPE_CLICK: t.CDefine = 1 -EVENT_TYPE_HOVER: t.CDefine = 2 -EVENT_TYPE_RELEASE: t.CDefine = 3 -EVENT_TYPE_HOVER_LEAVE: t.CDefine = 4 -EVENT_TYPE_KEY: t.CDefine = 5 -EVENT_TYPE_KEY_RELEASE: t.CDefine = 6 -EVENT_TYPE_PING: t.CDefine = 7 -EVENT_TYPE_RESIZE: t.CDefine = 8 - -RESIZE_EDGE_NONE: t.CDefine = 0 -RESIZE_EDGE_RIGHT: t.CDefine = 1 -RESIZE_EDGE_BOTTOM: t.CDefine = 2 -RESIZE_EDGE_CORNER: t.CDefine = 3 -RESIZE_BORDER: t.CDefine = 6 -RESIZE_MIN_W: t.CDefine = 100 -RESIZE_MIN_H: t.CDefine = 60 - -CURSOR_DEFAULT: t.CDefine = 0 -CURSOR_IBEAM: t.CDefine = 1 -CURSOR_RESIZE_EW: t.CDefine = 2 -CURSOR_RESIZE_NS: t.CDefine = 3 -CURSOR_RESIZE_NWSE: t.CDefine = 4 - -KEY_STATE_PRESS: t.CDefine = 1 -KEY_STATE_RELEASE: t.CDefine = 2 -KEY_STATE_REPEAT: t.CDefine = 3 - -TYPEMATIC_DELAY: t.CDefine = 500 -TYPEMATIC_RATE: t.CDefine = 40 - -HELD_KEY_MAX: t.CDefine = 8 - -class held_key_info(t.CStruct): - keycode: t.CUInt8T - is_usb: t.CUInt8T - press_time: t.CUInt64T - last_repeat: t.CUInt64T - -_held_keys: t.CArray[held_key_info, HELD_KEY_MAX] -_held_key_count: t.CInt = 0 - -@c.Attribute(t.attr.packed) -class InputEvent: - type: t.CUInt32T - win_id: t.CInt - x: t.CInt - y: t.CInt - button: t.CUInt8T - _pad0: t.CUInt8T - _pad1: t.CUInt8T - _pad2: t.CUInt8T - -INPUT_EVENT_SIZE: t.CDefine = 20 - -_event_queue: t.CArray[InputEvent, EVENT_QUEUE_SIZE] -_event_head: t.CInt = 0 -_event_tail: t.CInt = 0 -_last_hover_win: t.CInt = -1 -_focused_win: t.CInt = -1 - -KBD_DEV_PS2: t.CDefine = 0 -KBD_DEV_USB: t.CDefine = 1 - -_ps2_shift_l: t.CUInt8T = 0 -_ps2_shift_r: t.CUInt8T = 0 -_ps2_caps: t.CUInt8T = 0 -_ps2_e0_pending: t.CUInt8T = 0 -_kbd_irq_masked: t.CInt = 0 - -VK_LEFT: t.CDefine = -1 -VK_RIGHT: t.CDefine = -2 -VK_UP: t.CDefine = -3 -VK_DOWN: t.CDefine = -4 -VK_HOME: t.CDefine = -5 -VK_END: t.CDefine = -6 -VK_DELETE: t.CDefine = -7 - -_ps2_set1: t.CArray[t.CChar, 128] = [ - '\0', '\x1b', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', - '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', - '\0', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', "'", '`', '\0', - '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', '\0', '\0', '\0', ' ', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '-', '\0', '\0', '\0', '\0', - '\0', '+', '\0', '\0', '\0', '0', '.', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0' -] - -_ps2_set1_shift: t.CArray[t.CChar, 128] = [ - '\0', '\x1b', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '\b', - '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', - '\0', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', '\0', - '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', '\0', '\0', '\0', ' ', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '-', '\0', '\0', '\0', '\0', - '\0', '+', '\0', '\0', '\0', '0', '.', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0' -] - -def _ps2_scancode_to_ascii(scancode: t.CUInt8T) -> t.CInt: - code: t.CUInt8T = scancode & t.CUInt8T(0x7F) - if code >= 128: return 0 - shifted: t.CInt = 0 - if (_ps2_shift_l or _ps2_shift_r) != 0: - shifted = 1 - if _ps2_caps != 0: - if code >= 0x10 and code <= 0x32: - shifted = shifted ^ 1 - if shifted: - return t.CInt(_ps2_set1_shift[code]) - return t.CInt(_ps2_set1[code]) - - -def _push_event(evt: InputEvent): - global _event_head, _event_tail - if evt.type == EVENT_TYPE_RESIZE: - i: t.CInt = _event_head - while i != _event_tail: - if _event_queue[i].type == EVENT_TYPE_RESIZE and _event_queue[i].win_id == evt.win_id: - _event_queue[i].type = EVENT_TYPE_NONE - i = (i + 1) % EVENT_QUEUE_SIZE - next_tail: t.CInt = (_event_tail + 1) % EVENT_QUEUE_SIZE - if next_tail == _event_head: - _event_head = (_event_head + 1) % EVENT_QUEUE_SIZE - string.memcpy(c.Addr(_event_queue[_event_tail]), c.Addr(evt), INPUT_EVENT_SIZE) - _event_tail = next_tail - -def poll_event(buf_ptr: t.CVoid | t.CPtr, caller_pid: t.CInt) -> t.CInt: - global _event_head, _event_tail - while _event_head != _event_tail: - if _event_queue[_event_head].type == EVENT_TYPE_NONE: - _event_head = (_event_head + 1) % EVENT_QUEUE_SIZE - continue - evt_win: t.CInt = _event_queue[_event_head].win_id - evt_pid: t.CInt = 0 - win_ok: t.CInt = 0 - if evt_win >= 0 and evt_win < _win_count: - evt_pid = _wins[evt_win].pid - win_ok = 1 - if evt_pid == caller_pid: - string.memcpy(buf_ptr, c.Addr(_event_queue[_event_head]), INPUT_EVENT_SIZE) - _event_head = (_event_head + 1) % EVENT_QUEUE_SIZE - return 1 - if win_ok and not _wins[evt_win].active: - _event_head = (_event_head + 1) % EVENT_QUEUE_SIZE - continue - scan: t.CInt = (_event_head + 1) % EVENT_QUEUE_SIZE - while scan != _event_tail: - if _event_queue[scan].type == EVENT_TYPE_NONE: - scan = (scan + 1) % EVENT_QUEUE_SIZE - continue - evt_win2: t.CInt = _event_queue[scan].win_id - evt_pid2: t.CInt = 0 - if evt_win2 >= 0 and evt_win2 < _win_count: - evt_pid2 = _wins[evt_win2].pid - if evt_pid2 == caller_pid: - string.memcpy(buf_ptr, c.Addr(_event_queue[scan]), INPUT_EVENT_SIZE) - i: t.CInt = scan - while i != _event_tail: - next_i: t.CInt = (i + 1) % EVENT_QUEUE_SIZE - if next_i != _event_head: - string.memcpy(c.Addr(_event_queue[i]), c.Addr(_event_queue[next_i]), INPUT_EVENT_SIZE) - i = next_i - if _event_tail == 0: - _event_tail = EVENT_QUEUE_SIZE - 1 - else: - _event_tail = _event_tail - 1 - return 1 - scan = (scan + 1) % EVENT_QUEUE_SIZE - break - return 0 - -def _get_title_height(style: t.CInt) -> t.CInt: - if style == STYLE_CLASSIC: - return TITLE_HEIGHT_CLASSIC - return TITLE_HEIGHT_WIN - -def _mark_rows_dirty(start_y: t.CInt, count: t.CInt): - global _dirty_count, _dirty_y_min, _dirty_y_max - for i in range(start_y, start_y + count): - if i >= 0 and i < _screen_h: - if not _dirty_rows[i]: - _dirty_rows[i] = 1 - _dirty_count += 1 - if i < _dirty_y_min or _dirty_count == 1: - _dirty_y_min = i - if i > _dirty_y_max or _dirty_count == 1: - _dirty_y_max = i - -def _mark_all_dirty(): - global _dirty_count, _dirty_y_min, _dirty_y_max - string.memset(_dirty_rows, 1, _screen_h) - _dirty_count = _screen_h - _dirty_y_min = 0 - _dirty_y_max = _screen_h - 1 - -def _has_dirty_rows() -> t.CInt: - return _dirty_count - -def _clear_dirty_flags(): - global _dirty_count, _dirty_y_min, _dirty_y_max - string.memset(_dirty_rows, 0, _screen_h) - _dirty_count = 0 - _dirty_y_min = _screen_h - _dirty_y_max = -1 - -def _wait_vblank(): - global _vblank_ok - if _vblank_ok == 0: - return - timeout: t.CInt = 50000 - while (asm.inb(0x3DA) & 0x08) != 0: - timeout -= 1 - if timeout <= 0: - _vblank_ok = 0 - return - while (asm.inb(0x3DA) & 0x08) == 0: - timeout -= 1 - if timeout <= 0: - _vblank_ok = 0 - return - _vblank_ok = 1 - -def _fill_rect(buf: UINT32PTR, bw: t.CInt, bh: t.CInt, rx: t.CInt, ry: t.CInt, rw: t.CInt, rh: t.CInt, color: t.CUInt32T): - if rx < 0: rw += rx; rx = 0 - if ry < 0: rh += ry; ry = 0 - if rx + rw > bw: rw = bw - rx - if ry + rh > bh: rh = bh - ry - if rw <= 0 or rh <= 0: return - if _row_buf: - for i in range(rw): - _row_buf[i] = color - row_bytes: t.CInt = rw * 4 - for py in range(ry, ry + rh): - string.memcpy(t.CVoid(t.CUInt64T(buf) + (py * bw + rx) * 4, t.CPtr), _row_buf, row_bytes) - -def _alpha_blend(bg: t.CUInt32T, fg: t.CUInt32T, alpha: t.CInt) -> t.CUInt32T: - a: t.CInt = alpha - ia: t.CInt = 255 - a - bg_r: t.CInt = t.CInt(bg & 0xFF) - bg_g: t.CInt = t.CInt((bg >> 8) & 0xFF) - bg_b: t.CInt = t.CInt((bg >> 16) & 0xFF) - fg_r: t.CInt = t.CInt(fg & 0xFF) - fg_g: t.CInt = t.CInt((fg >> 8) & 0xFF) - fg_b: t.CInt = t.CInt((fg >> 16) & 0xFF) - r: t.CInt = (fg_r * a + bg_r * ia) >> 8 - g: t.CInt = (fg_g * a + bg_g * ia) >> 8 - b: t.CInt = (fg_b * a + bg_b * ia) >> 8 - return t.CUInt32T(r | (g << 8) | (b << 16) | 0xFF000000) - -def _is_in_corner(px: t.CInt, py: t.CInt, cx: t.CInt, cy: t.CInt, r: t.CInt) -> t.CInt: - dx: t.CInt = px - cx - dy: t.CInt = py - cy - if dx < 0: dx = -dx - if dy < 0: dy = -dy - if dx <= r and dy <= r: - dist2: t.CInt = dx * dx + dy * dy - r2: t.CInt = r * r - if dist2 > r2: - return 0 - return 1 - -def _is_on_border(rx: t.CInt, ry: t.CInt, ww: t.CInt, wh: t.CInt, r: t.CInt) -> t.CInt: - if rx == 0 or rx == ww - 1 or ry == 0 or ry == wh - 1: - return 1 - if ry < r: - if rx < r: - dx: t.CInt = rx - r - dy: t.CInt = ry - r - dist2: t.CInt = dx * dx + dy * dy - if dist2 >= (r - 1) * (r - 1): return 1 - elif rx >= ww - r: - dx = rx - (ww - r - 1) - dy = ry - r - dist2 = dx * dx + dy * dy - if dist2 >= (r - 1) * (r - 1): return 1 - elif ry >= wh - r: - if rx < r: - dx = rx - r - dy = ry - (wh - r - 1) - dist2 = dx * dx + dy * dy - if dist2 >= (r - 1) * (r - 1): return 1 - elif rx >= ww - r: - dx = rx - (ww - r - 1) - dy = ry - (wh - r - 1) - dist2 = dx * dx + dy * dy - if dist2 >= (r - 1) * (r - 1): return 1 - return 0 - -def _corner_alpha(px: t.CInt, py: t.CInt, cx: t.CInt, cy: t.CInt, r: t.CInt) -> t.CInt: - dx: t.CInt = px - cx - dy: t.CInt = py - cy - if dx < 0: dx = -dx - if dy < 0: dy = -dy - if dx <= r and dy <= r: - dist2: t.CInt = dx * dx + dy * dy - r2: t.CInt = r * r - if dist2 > r2: - return 0 - outer: t.CInt = (r + 1) * (r + 1) - if dist2 >= outer: - return 160 - return 255 - return 255 - -def _draw_char(buf: UINT32PTR, bw: t.CInt, bh: t.CInt, x: t.CInt, y: t.CInt, ch: t.CChar, color: t.CUInt32T): - cval: t.CUInt8T = t.CUInt8T(ch) - if cval >= 128: cval = 0 - for fy in range(16): - if y + fy < 0 or y + fy >= bh: continue - row: t.CUInt8T = vga.font[cval][fy] - if row == 0: continue - for fx in range(8): - if row & (0x80 >> fx): - px: t.CInt = x + fx - if px >= 0 and px < bw: - buf[(y + fy) * bw + px] = color - -def _draw_text(buf: UINT32PTR, bw: t.CInt, bh: t.CInt, x: t.CInt, y: t.CInt, s: t.CConst | str, color: t.CUInt32T): - cx: t.CInt = x - cy: t.CInt = y - for ch in s: - if ch == 10: - cy += 16 - cx = x - else: - _draw_char(buf, bw, bh, cx, cy, ch, color) - cx += 8 - -_drag_idx: t.CInt = -1 - -def _eff_w(aw2: AppWindow | t.CPtr) -> t.CInt: - if aw2.resize_w != 0: return aw2.resize_w - return aw2.w - -def _eff_h(aw2: AppWindow | t.CPtr) -> t.CInt: - if aw2.resize_h != 0: return aw2.resize_h - return aw2.content_h -_drag_off_x: t.CInt = 0 -_drag_off_y: t.CInt = 0 -_rsz_drag_idx: t.CInt = -1 -_rsz_edge: t.CInt = 0 -_rsz_start_x: t.CInt = 0 -_rsz_start_y: t.CInt = 0 -_rsz_start_w: t.CInt = 0 -_rsz_start_h: t.CInt = 0 -_rsz_last_w: t.CInt = 0 -_rsz_last_h: t.CInt = 0 -_rsz_last_tick: t.CUInt64T = 0 -_mouse_moved: t.CInt = 0 - -def _bring_to_front(idx: t.CInt): - global _next_z - if idx < 0 or idx >= _win_count: return - aw: AppWindow | t.CPtr = c.Addr(_wins[idx]) - if not aw.active or aw.minimized: return - _next_z += 1 - aw.z_order = _next_z - -def _hit_test_window(mx: t.CInt, my: t.CInt) -> t.CInt: - best: t.CInt = -1 - best_z: t.CInt = -1 - for ai in range(_win_count): - if _wins[ai].active and not _wins[ai].minimized: - ax: t.CInt = _wins[ai].x - ay: t.CInt = _wins[ai].y - aw: t.CInt = _eff_w(c.Addr(_wins[ai])) - ah: t.CInt = _wins[ai].h - if mx >= ax and mx < ax + aw and my >= ay and my < ay + ah: - z: t.CInt = _wins[ai].z_order - if z > best_z: - best_z = z - best = ai - return best - -def _hit_test_resize(mx: t.CInt, my: t.CInt, idx: t.CInt) -> t.CInt: - if idx < 0 or idx >= _win_count: return RESIZE_EDGE_NONE - aw: AppWindow | t.CPtr = c.Addr(_wins[idx]) - if not aw.active or aw.minimized: return RESIZE_EDGE_NONE - if not aw.resizable_w and not aw.resizable_h: return RESIZE_EDGE_NONE - on_right: t.CInt = 0 - on_bottom: t.CInt = 0 - if aw.resizable_w: - if mx >= aw.x + _eff_w(aw) - RESIZE_BORDER and mx < aw.x + _eff_w(aw): - on_right = 1 - if aw.resizable_h: - if my >= aw.y + aw.h - RESIZE_BORDER and my < aw.y + aw.h: - on_bottom = 1 - if on_right and on_bottom: return RESIZE_EDGE_CORNER - if on_right: return RESIZE_EDGE_RIGHT - if on_bottom: return RESIZE_EDGE_BOTTOM - return RESIZE_EDGE_NONE - -def _hid_to_ascii(keycode: t.CUInt8T, modifier: t.CUInt8T) -> t.CInt: - global _ps2_caps - shift: t.CInt = 0 - if (modifier & 0x22) != 0: - shift = 1 - kc: t.CInt = t.CInt(keycode) - if kc >= 4 and kc <= 29: - if _ps2_caps != 0: - shift = shift ^ 1 - if shift: - return kc - 4 + 65 - return kc - 4 + 97 - if kc >= 30 and kc <= 38: - if shift: - shifts9: t.CArray[t.CInt, 9] - shifts9[0] = 33; shifts9[1] = 64; shifts9[2] = 35 - shifts9[3] = 36; shifts9[4] = 37; shifts9[5] = 94 - shifts9[6] = 38; shifts9[7] = 42; shifts9[8] = 40 - return shifts9[kc - 30] - return kc - 30 + 49 - if kc == 39: - if shift: return 41 - return 48 - if kc == 44: return 32 - if kc == 40: return 13 - if kc == 42: return 8 - if kc == 43: return 9 - if kc == 41: return 27 - if kc == 45: - if shift: return 95 - return 45 - if kc == 46: - if shift: return 43 - return 61 - if kc == 47: - if shift: return 123 - return 91 - if kc == 48: - if shift: return 125 - return 93 - if kc == 49: - if shift: return 124 - return 92 - if kc == 51: - if shift: return 58 - return 59 - if kc == 52: - if shift: return 34 - return 39 - if kc == 53: - if shift: return 126 - return 96 - if kc == 54: - if shift: return 60 - return 44 - if kc == 55: - if shift: return 62 - return 46 - if kc == 56: - if shift: return 63 - return 47 - return 0 - -def _held_key_add(keycode: t.CUInt8T, is_usb: t.CUInt8T): - global _held_key_count - if _held_key_count >= HELD_KEY_MAX: return - for i in range(_held_key_count): - if _held_keys[i].keycode == keycode and _held_keys[i].is_usb == is_usb: - return - now: t.CUInt64T = timer.timer_get_ticks() - _held_keys[_held_key_count].keycode = keycode - _held_keys[_held_key_count].is_usb = is_usb - _held_keys[_held_key_count].press_time = now - _held_keys[_held_key_count].last_repeat = now - _held_key_count += 1 - -def _held_key_remove(keycode: t.CUInt8T, is_usb: t.CUInt8T): - global _held_key_count - for i in range(_held_key_count): - if _held_keys[i].keycode == keycode and _held_keys[i].is_usb == is_usb: - for j in range(i, _held_key_count - 1): - _held_keys[j].keycode = _held_keys[j + 1].keycode - _held_keys[j].is_usb = _held_keys[j + 1].is_usb - _held_keys[j].press_time = _held_keys[j + 1].press_time - _held_keys[j].last_repeat = _held_keys[j + 1].last_repeat - _held_key_count -= 1 - return - -def _check_key_repeat(): - global _held_key_count - if _focused_win < 0 or _focused_win >= _win_count: return - if not _wins[_focused_win].active: return - now: t.CUInt64T = timer.timer_get_ticks() - for i in range(_held_key_count): - hk: held_key_info | t.CPtr = c.Addr(_held_keys[i]) - elapsed: t.CUInt64T = now - hk.press_time - if elapsed < t.CUInt64T(TYPEMATIC_DELAY): - continue - since_last: t.CUInt64T = now - hk.last_repeat - if since_last >= t.CUInt64T(TYPEMATIC_RATE): - hk.last_repeat = now - ascii_ch: t.CInt = 0 - if hk.is_usb: - mod: t.CUInt8T = 0 - if _ps2_shift_l or _ps2_shift_r: - mod = mod | 0x22 - if _ps2_caps: - mod = mod | 0x01 - ascii_ch = _hid_to_ascii(hk.keycode, mod) - else: - ascii_ch = _ps2_scancode_to_ascii(hk.keycode) - if ascii_ch != 0: - rep_evt: InputEvent - rep_evt.type = EVENT_TYPE_KEY - rep_evt.win_id = _focused_win - rep_evt.x = ascii_ch - rep_evt.y = t.CInt(hk.keycode) - rep_evt.button = KEY_STATE_REPEAT - rep_evt._pad0 = 0 - rep_evt._pad1 = 0 - rep_evt._pad2 = 0 - _push_event(rep_evt) - -def _update_keyboard(): - global _focused_win, _kbd_irq_masked - global _ps2_shift_l, _ps2_shift_r, _ps2_caps - global _ps2_e0_pending - # Quick check: skip if no PS/2 data and no USB data - ps2_status: t.CUInt8T = asm.inb(0x64) - if (ps2_status & 0x01) == 0 and not usb_kbd.has_data(): - _check_key_repeat() - return - if _kbd_irq_masked == 0: - pic.clearMask(1) - _kbd_irq_masked = 1 - kbd_cnt: t.CInt = 0 - while usb_kbd.has_data() and kbd_cnt < 32: - kbd_cnt += 1 - kevt: usb_kbd.usb_kbd_event - usb_kbd.read_event(c.Addr(kevt)) - if kevt.keycode == 0x39 and kevt.event_type == usb_kbd.KBD_EVT_PRESS: - _ps2_caps = _ps2_caps ^ t.CUInt8T(1) - if kevt.event_type == usb_kbd.KBD_EVT_PRESS: - _held_key_add(kevt.keycode, 1) - usb_ascii: t.CInt = _hid_to_ascii(kevt.keycode, kevt.modifier) - if usb_ascii == 0: - kc2: t.CInt = t.CInt(kevt.keycode) - if kc2 == 0x50: usb_ascii = VK_LEFT - elif kc2 == 0x4F: usb_ascii = VK_RIGHT - elif kc2 == 0x52: usb_ascii = VK_UP - elif kc2 == 0x51: usb_ascii = VK_DOWN - elif kc2 == 0x4A: usb_ascii = VK_HOME - elif kc2 == 0x4D: usb_ascii = VK_END - elif kc2 == 0x4C: usb_ascii = VK_DELETE - if usb_ascii != 0 and _focused_win >= 0 and _focused_win < _win_count and _wins[_focused_win].active: - usb_evt: InputEvent - usb_evt.type = EVENT_TYPE_KEY - usb_evt.win_id = _focused_win - usb_evt.x = usb_ascii - usb_evt.y = t.CInt(kevt.keycode) - usb_evt.button = KEY_STATE_PRESS - usb_evt._pad0 = 0 - usb_evt._pad1 = 0 - usb_evt._pad2 = 0 - _push_event(usb_evt) - elif kevt.event_type == usb_kbd.KBD_EVT_RELEASE: - _held_key_remove(kevt.keycode, 1) - if _focused_win >= 0 and _focused_win < _win_count and _wins[_focused_win].active: - rel_evt: InputEvent - rel_evt.type = EVENT_TYPE_KEY_RELEASE - rel_evt.win_id = _focused_win - rel_evt.x = 0 - rel_evt.y = t.CInt(kevt.keycode) - rel_evt.button = KEY_STATE_RELEASE - rel_evt._pad0 = 0 - rel_evt._pad1 = 0 - rel_evt._pad2 = 0 - _push_event(rel_evt) - ps2_poll_count: t.CInt = 0 - while ps2_poll_count < 16: - ps2_status: t.CUInt8T = asm.inb(0x64) - if (ps2_status & 0x01) == 0: - break - if (ps2_status & 0x20) != 0: - asm.inb(0x60) - ps2_poll_count += 1 - continue - sc: t.CUInt8T = asm.inb(0x60) - ps2_poll_count += 1 - if sc == 0x00 or sc == 0xFA or sc == 0xFE or sc == 0xFF: - _ps2_e0_pending = 0 - continue - if sc == 0xE0: - _ps2_e0_pending = 1 - continue - if sc == 0xE1: - _ps2_e0_pending = 0 - continue - if _ps2_e0_pending != 0: - _ps2_e0_pending = 0 - e0_code: t.CUInt8T = sc & t.CUInt8T(0x7F) - if (sc & 0x80) != 0: - _held_key_remove(e0_code | 0x80, 0) - if _focused_win >= 0 and _focused_win < _win_count and _wins[_focused_win].active: - ps2_rel2: InputEvent - ps2_rel2.type = EVENT_TYPE_KEY_RELEASE - ps2_rel2.win_id = _focused_win - ps2_rel2.x = 0 - ps2_rel2.y = t.CInt(e0_code | 0x80) - ps2_rel2.button = KEY_STATE_RELEASE - ps2_rel2._pad0 = 0 - ps2_rel2._pad1 = 0 - ps2_rel2._pad2 = 0 - _push_event(ps2_rel2) - continue - vk: t.CInt = 0 - if e0_code == 0x4B: vk = VK_LEFT - elif e0_code == 0x4D: vk = VK_RIGHT - elif e0_code == 0x48: vk = VK_UP - elif e0_code == 0x50: vk = VK_DOWN - elif e0_code == 0x47: vk = VK_HOME - elif e0_code == 0x4F: vk = VK_END - elif e0_code == 0x53: vk = VK_DELETE - if vk != 0: - _held_key_add(e0_code | 0x80, 0) - if _focused_win >= 0 and _focused_win < _win_count and _wins[_focused_win].active: - e0_evt: InputEvent - e0_evt.type = EVENT_TYPE_KEY - e0_evt.win_id = _focused_win - e0_evt.x = vk - e0_evt.y = t.CInt(e0_code | 0x80) - e0_evt.button = KEY_STATE_PRESS - e0_evt._pad0 = 0 - e0_evt._pad1 = 0 - e0_evt._pad2 = 0 - _push_event(e0_evt) - continue - if sc == 0x2A: - _ps2_shift_l = 1 - continue - if sc == 0xAA: - _ps2_shift_l = 0 - continue - if sc == 0x36: - _ps2_shift_r = 1 - continue - if sc == 0xB6: - _ps2_shift_r = 0 - continue - if sc == 0x3A: - _ps2_caps = _ps2_caps ^ t.CUInt8T(1) - continue - if (sc & 0x80) != 0: - release_sc: t.CUInt8T = sc & t.CUInt8T(0x7F) - _held_key_remove(release_sc, 0) - if _focused_win >= 0 and _focused_win < _win_count and _wins[_focused_win].active: - ps2_rel: InputEvent - ps2_rel.type = EVENT_TYPE_KEY_RELEASE - ps2_rel.win_id = _focused_win - ps2_rel.x = 0 - ps2_rel.y = t.CInt(release_sc) - ps2_rel.button = KEY_STATE_RELEASE - ps2_rel._pad0 = 0 - ps2_rel._pad1 = 0 - ps2_rel._pad2 = 0 - _push_event(ps2_rel) - continue - _held_key_add(sc, 0) - ascii_ch: t.CInt = _ps2_scancode_to_ascii(sc) - if ascii_ch != 0 and _focused_win >= 0 and _focused_win < _win_count and _wins[_focused_win].active: - push_evt: InputEvent - push_evt.type = EVENT_TYPE_KEY - push_evt.win_id = _focused_win - push_evt.x = ascii_ch - push_evt.y = t.CInt(sc) - push_evt.button = KEY_STATE_PRESS - push_evt._pad0 = 0 - push_evt._pad1 = 0 - push_evt._pad2 = 0 - _push_event(push_evt) - _check_key_repeat() - -def set_cursor_type(win_id: t.CInt, cursor_t: t.CInt): - if win_id >= 0 and win_id < _win_count: - _wins[win_id].app_cursor_type = cursor_t - _wins[win_id].cursor_type = cursor_t - -def _update_mouse() -> t.CInt: - global _cursor_x, _cursor_y, _cursor_buttons - global _drag_idx, _drag_off_x, _drag_off_y - global _mouse_moved, _prev_btn, _last_hover_win, _focused_win - global _rsz_drag_idx, _rsz_edge, _rsz_start_x, _rsz_start_y - global _rsz_start_w, _rsz_start_h, _rsz_last_w, _rsz_last_h, _rsz_last_tick - moved: t.CInt = 0 - poll_cnt: t.CInt = 0 - while (mouse.has_data() or usb_mouse.has_data()) and poll_cnt < 32: - poll_cnt += 1 - pkt_dx: t.CInt32T = 0 - pkt_dy: t.CInt32T = 0 - pkt_btn: t.CUInt8T = 0 - if mouse.has_data(): - pkt: mouse.mouse_packet - mouse.read_packet(c.Addr(pkt)) - pkt_dx = t.CInt32T(pkt.dx) - pkt_dy = -t.CInt32T(pkt.dy) - pkt_btn = pkt.buttons - elif usb_mouse.has_data(): - upkt: usb_mouse.usb_mouse_packet - usb_mouse.read_packet(c.Addr(upkt)) - pkt_dx = t.CInt32T(upkt.dx) - pkt_dy = -t.CInt32T(upkt.dy) - pkt_btn = upkt.buttons - if pkt_dx != 0 or pkt_dy != 0: - _cursor_x = _cursor_x + pkt_dx - _cursor_y = _cursor_y + pkt_dy - if _cursor_x < 0: _cursor_x = 0 - if _cursor_y < 0: _cursor_y = 0 - if _cursor_x >= _screen_w: _cursor_x = _screen_w - 1 - if _cursor_y >= _screen_h: _cursor_y = _screen_h - 1 - moved = 1 - _mouse_moved = 1 - btn_down: t.CUInt8T = pkt_btn & 0x01 - prev_down: t.CUInt8T = _prev_btn & 0x01 - _cursor_buttons = pkt_btn - _prev_btn = pkt_btn - if btn_down and not prev_down: - hit_app: t.CInt = _hit_test_window(_cursor_x, _cursor_y) - if hit_app >= 0: - aw: AppWindow | t.CPtr = c.Addr(_wins[hit_app]) - th: t.CInt = _get_title_height(aw.style) - btn_w: t.CInt = CLOSE_BTN_SIZE - btn_h: t.CInt = CLOSE_BTN_SIZE - ew: t.CInt = _eff_w(aw) - btn_x: t.CInt = aw.x + ew - btn_w - 4 - btn_y: t.CInt = aw.y + (th - btn_h) // 2 - if aw.style == STYLE_WIN7: - btn_w = CLOSE_BTN_W7_W - btn_h = CLOSE_BTN_W7_H - btn_x = aw.x + ew - btn_w - 5 - btn_y = aw.y + (th - btn_h) // 2 - elif aw.style == STYLE_WINXP: - btn_w = CLOSE_BTN_XP_SZ - btn_h = CLOSE_BTN_XP_SZ - btn_x = aw.x + ew - btn_w - 5 - btn_y = aw.y + (th - btn_h) // 2 - elif aw.style == STYLE_WIN10 or aw.style == STYLE_WIN11: - btn_w = CLOSE_BTN_W_WIN - btn_h = th - 2 - btn_x = aw.x + ew - btn_w - btn_y = aw.y + 1 - if _cursor_x >= btn_x and _cursor_x < btn_x + btn_w and _cursor_y >= btn_y and _cursor_y < btn_y + btn_h: - aw.active = 0 - if _focused_win == hit_app: - _focused_win = -1 - j: t.CInt = _win_count - 1 - while j >= 0: - if _wins[j].active and not _wins[j].minimized: - _focused_win = j - break - j -= 1 - if _last_hover_win == hit_app: - _last_hover_win = -1 - _mark_all_dirty() - else: - max_bx2: t.CInt = btn_x - btn_w - if aw.style == STYLE_WIN7 or aw.style == STYLE_WINXP: - max_bx2 = btn_x - btn_w - 1 - if _cursor_x >= max_bx2 and _cursor_x < max_bx2 + btn_w and _cursor_y >= btn_y and _cursor_y < btn_y + btn_h: - if aw.is_maximized: - aw.is_maximized = 0 - aw.x = aw.orig_x - aw.y = aw.orig_y - aw.h = aw.orig_h - aw.resize_w = aw.orig_w - aw.resize_h = aw.orig_h - _get_title_height(aw.style) - 2 - else: - aw.is_maximized = 1 - aw.orig_x = aw.w - aw.orig_y = aw.y - aw.orig_w = aw.w - aw.orig_h = aw.h - aw.x = 0 - aw.y = 0 - tb_h_mx: t.CInt = TASKBAR_HEIGHT - aw.h = _screen_h - tb_h_mx - aw.resize_w = _screen_w - aw.resize_h = _screen_h - tb_h_mx - _get_title_height(aw.style) - 2 - rs_evt3: InputEvent - rs_evt3.type = EVENT_TYPE_RESIZE - rs_evt3.win_id = hit_app - rs_evt3.x = aw.resize_w - rs_evt3.y = aw.resize_h - rs_evt3.button = 0 - rs_evt3._pad0 = 0 - rs_evt3._pad1 = 0 - rs_evt3._pad2 = 0 - _push_event(rs_evt3) - _mark_all_dirty() - else: - min_bx2: t.CInt = max_bx2 - btn_w - if aw.style == STYLE_WIN7 or aw.style == STYLE_WINXP: - min_bx2 = max_bx2 - btn_w - 1 - if _cursor_x >= min_bx2 and _cursor_x < min_bx2 + btn_w and _cursor_y >= btn_y and _cursor_y < btn_y + btn_h: - aw.minimized = 1 - if _focused_win == hit_app: - _focused_win = -1 - j2: t.CInt = _win_count - 1 - while j2 >= 0: - if _wins[j2].active and not _wins[j2].minimized: - _focused_win = j2 - break - j2 -= 1 - _mark_all_dirty() - else: - re: t.CInt = _hit_test_resize(_cursor_x, _cursor_y, hit_app) - if re != RESIZE_EDGE_NONE: - _rsz_drag_idx = hit_app - _rsz_edge = re - _rsz_start_x = _cursor_x - _rsz_start_y = _cursor_y - _rsz_start_w = _eff_w(aw) - _rsz_start_h = aw.h - _rsz_last_w = _eff_w(aw) - _rsz_last_h = aw.h - _rsz_last_tick = timer.timer_get_ticks() - _bring_to_front(hit_app) - _focused_win = hit_app - _mark_all_dirty() - elif _cursor_y >= aw.y and _cursor_y < aw.y + th: - _drag_idx = hit_app - _drag_off_x = _cursor_x - aw.x - _drag_off_y = _cursor_y - aw.y - _bring_to_front(hit_app) - _focused_win = hit_app - _mark_all_dirty() - else: - _bring_to_front(hit_app) - _focused_win = hit_app - _mark_all_dirty() - evt: InputEvent - evt.type = EVENT_TYPE_CLICK - evt.win_id = hit_app - evt.x = _cursor_x - aw.x - evt.y = _cursor_y - aw.y - _get_title_height(aw.style) - evt.button = 1 - evt._pad0 = 0 - evt._pad1 = 0 - evt._pad2 = 0 - _push_event(evt) - else: - tb_h_cl: t.CInt = TASKBAR_HEIGHT - bar_y2: t.CInt = _screen_h - tb_h_cl - if _cursor_y >= bar_y2: - logo_x2: t.CInt = 4 - logo_sz2: t.CInt = TASKBAR_LOGO_SZ - logo_r2: t.CInt = logo_x2 + logo_sz2 - logo_b2: t.CInt = bar_y2 + tb_h_cl - if _cursor_x >= logo_x2 and _cursor_x < logo_r2 and _cursor_y >= bar_y2 and _cursor_y < logo_b2: - if _focused_win >= 0 and _focused_win < _win_count: - if _wins[_focused_win].active: - _wins[_focused_win].active = 0 - _focused_win = -1 - _mark_all_dirty() - else: - icon_sz2: t.CInt = TASKBAR_ICON_SZ - icon_pad2: t.CInt = TASKBAR_ICON_PAD - icon_x2: t.CInt = logo_x2 + logo_sz2 + 80 - icon_cnt2: t.CInt = 0 - for ti2 in range(_win_count): - if _wins[ti2].active: - ix2: t.CInt = icon_x2 + icon_cnt2 * (icon_sz2 + icon_pad2) - iy2: t.CInt = bar_y2 + (tb_h_cl - icon_sz2) // 2 - if _cursor_x >= ix2 and _cursor_x < ix2 + icon_sz2 and _cursor_y >= iy2 and _cursor_y < iy2 + icon_sz2: - if _wins[ti2].minimized: - _wins[ti2].minimized = 0 - _bring_to_front(ti2) - _focused_win = ti2 - elif _focused_win == ti2: - _wins[ti2].minimized = 1 - _focused_win = -1 - for j3 in range(_win_count - 1, -1, -1): - if _wins[j3].active and not _wins[j3].minimized: - _focused_win = j3 - break - else: - _bring_to_front(ti2) - _focused_win = ti2 - _mark_all_dirty() - break - icon_cnt2 += 1 - if not btn_down: - if prev_down: - if _rsz_drag_idx >= 0: - rs_aw: AppWindow | t.CPtr = c.Addr(_wins[_rsz_drag_idx]) - final_w: t.CInt = _rsz_last_w - final_h: t.CInt = _rsz_last_h - old_h_mu: t.CInt = _eff_h(rs_aw) + _get_title_height(rs_aw.style) + 2 - _mark_rows_dirty(rs_aw.y, old_h_mu) - final_ch: t.CInt = final_h - _get_title_height(rs_aw.style) - 2 - rs_aw.resize_w = final_w - rs_aw.resize_h = final_ch - rs_aw.h = final_h - _mark_rows_dirty(rs_aw.y, final_h) - rs_evt: InputEvent - rs_evt.type = EVENT_TYPE_RESIZE - rs_evt.win_id = _rsz_drag_idx - rs_evt.x = final_w - rs_evt.y = final_ch - rs_evt.button = 0 - rs_evt._pad0 = 0 - rs_evt._pad1 = 0 - rs_evt._pad2 = 0 - _push_event(rs_evt) - _rsz_drag_idx = -1 - _rsz_edge = RESIZE_EDGE_NONE - else: - rel_hit: t.CInt = _hit_test_window(_cursor_x, _cursor_y) - if rel_hit >= 0: - aw_rel: AppWindow | t.CPtr = c.Addr(_wins[rel_hit]) - rel_evt: InputEvent - rel_evt.type = EVENT_TYPE_RELEASE - rel_evt.win_id = rel_hit - rel_evt.x = _cursor_x - aw_rel.x - rel_evt.y = _cursor_y - aw_rel.y - _get_title_height(aw_rel.style) - rel_evt.button = 0 - rel_evt._pad0 = 0 - rel_evt._pad1 = 0 - rel_evt._pad2 = 0 - _push_event(rel_evt) - if _drag_idx >= 0: - moved = 1 - _mark_rows_dirty(_wins[_drag_idx].y, _wins[_drag_idx].h) - _drag_idx = -1 - if moved and _drag_idx < 0: - hit_hov: t.CInt = _hit_test_window(_cursor_x, _cursor_y) - if hit_hov >= 0: - if _last_hover_win >= 0 and _last_hover_win != hit_hov and _last_hover_win < _win_count: - if _wins[_last_hover_win].active: - leave_evt3: InputEvent - leave_evt3.type = EVENT_TYPE_HOVER_LEAVE - leave_evt3.win_id = _last_hover_win - leave_evt3.x = -1 - leave_evt3.y = -1 - leave_evt3.button = 0 - leave_evt3._pad0 = 0 - leave_evt3._pad1 = 0 - leave_evt3._pad2 = 0 - _push_event(leave_evt3) - aw_hov: AppWindow | t.CPtr = c.Addr(_wins[hit_hov]) - th_hov: t.CInt = _get_title_height(aw_hov.style) - hov_evt: InputEvent - hov_evt.type = EVENT_TYPE_HOVER - hov_evt.win_id = hit_hov - hov_evt.x = _cursor_x - aw_hov.x - hov_evt.y = _cursor_y - aw_hov.y - th_hov - hov_evt.button = 0 - hov_evt._pad0 = 0 - hov_evt._pad1 = 0 - hov_evt._pad2 = 0 - _push_event(hov_evt) - _last_hover_win = hit_hov - re_hov: t.CInt = _hit_test_resize(_cursor_x, _cursor_y, hit_hov) - if re_hov == RESIZE_EDGE_RIGHT: - aw_hov.cursor_type = CURSOR_RESIZE_EW - elif re_hov == RESIZE_EDGE_BOTTOM: - aw_hov.cursor_type = CURSOR_RESIZE_NS - elif re_hov == RESIZE_EDGE_CORNER: - aw_hov.cursor_type = CURSOR_RESIZE_NWSE - else: - aw_hov.cursor_type = aw_hov.app_cursor_type - else: - if _last_hover_win >= 0 and _last_hover_win < _win_count: - if _wins[_last_hover_win].active: - leave_evt: InputEvent - leave_evt.type = EVENT_TYPE_HOVER_LEAVE - leave_evt.win_id = _last_hover_win - leave_evt.x = -1 - leave_evt.y = -1 - leave_evt.button = 0 - leave_evt._pad0 = 0 - leave_evt._pad1 = 0 - leave_evt._pad2 = 0 - _push_event(leave_evt) - _last_hover_win = -1 - if _drag_idx >= 0: - aw2: AppWindow | t.CPtr = c.Addr(_wins[_drag_idx]) - _drag_old_y: t.CInt = aw2.y - _mark_rows_dirty(_drag_old_y, aw2.h) - aw2.x = _cursor_x - _drag_off_x - aw2.y = _cursor_y - _drag_off_y - _mark_rows_dirty(aw2.y, aw2.h) - if _rsz_drag_idx >= 0: - rs_aw2: AppWindow | t.CPtr = c.Addr(_wins[_rsz_drag_idx]) - dx: t.CInt = _cursor_x - _rsz_start_x - dy: t.CInt = _cursor_y - _rsz_start_y - new_w: t.CInt = _rsz_start_w - new_h: t.CInt = _rsz_start_h - if _rsz_edge == RESIZE_EDGE_RIGHT or _rsz_edge == RESIZE_EDGE_CORNER: - new_w = _rsz_start_w + dx - if new_w < RESIZE_MIN_W: new_w = RESIZE_MIN_W - if _rsz_edge == RESIZE_EDGE_BOTTOM or _rsz_edge == RESIZE_EDGE_CORNER: - new_h = _rsz_start_h + dy - if new_h < RESIZE_MIN_H: new_h = RESIZE_MIN_H - if new_w != rs_aw2.w or new_h != rs_aw2.h: - dw: t.CInt = new_w - _rsz_last_w - if dw < 0: dw = -dw - dh: t.CInt = new_h - _rsz_last_h - if dh < 0: dh = -dh - now_tick: t.CUInt64T = timer.timer_get_ticks() - elapsed: t.CUInt64T = now_tick - _rsz_last_tick - need_update: t.CInt = 0 - if dw >= 32 or dh >= 32: - need_update = 1 - elif elapsed >= 100 and (dw >= 4 or dh >= 4): - need_update = 1 - if need_update: - _rsz_last_w = new_w - _rsz_last_h = new_h - _rsz_last_tick = now_tick - old_h_rs: t.CInt = _eff_h(rs_aw2) + _get_title_height(rs_aw2.style) + 2 - _mark_rows_dirty(rs_aw2.y, old_h_rs) - new_ch: t.CInt = new_h - _get_title_height(rs_aw2.style) - 2 - rs_aw2.resize_w = new_w - rs_aw2.resize_h = new_ch - rs_aw2.h = new_h - _mark_rows_dirty(rs_aw2.y, new_h) - rs_evt2: InputEvent - rs_evt2.type = EVENT_TYPE_RESIZE - rs_evt2.win_id = _rsz_drag_idx - rs_evt2.x = new_w - rs_evt2.y = new_ch - rs_evt2.button = 0 - rs_evt2._pad0 = 0 - rs_evt2._pad1 = 0 - rs_evt2._pad2 = 0 - _push_event(rs_evt2) - if not moved and _last_hover_win < 0: - hit_hov2: t.CInt = _hit_test_window(_cursor_x, _cursor_y) - if hit_hov2 >= 0 and _wins[hit_hov2].active: - aw_hov2: AppWindow | t.CPtr = c.Addr(_wins[hit_hov2]) - th_hov2: t.CInt = _get_title_height(aw_hov2.style) - hov_evt2: InputEvent - hov_evt2.type = EVENT_TYPE_HOVER - hov_evt2.win_id = hit_hov2 - hov_evt2.x = _cursor_x - aw_hov2.x - hov_evt2.y = _cursor_y - aw_hov2.y - th_hov2 - hov_evt2.button = 0 - hov_evt2._pad0 = 0 - hov_evt2._pad1 = 0 - hov_evt2._pad2 = 0 - _push_event(hov_evt2) - _last_hover_win = hit_hov2 - if not moved and _last_hover_win >= 0: - if _last_hover_win >= _win_count or not _wins[_last_hover_win].active: - leave_evt2: InputEvent - leave_evt2.type = EVENT_TYPE_HOVER_LEAVE - leave_evt2.win_id = _last_hover_win - leave_evt2.x = -1 - leave_evt2.y = -1 - leave_evt2.button = 0 - leave_evt2._pad0 = 0 - leave_evt2._pad1 = 0 - leave_evt2._pad2 = 0 - _push_event(leave_evt2) - _last_hover_win = -1 - return moved - -_render_count: t.CInt = 0 -_cached_top_win: t.CInt = -1 -_perf_t_mouse: t.CUInt64T = 0 -_perf_t_kbd: t.CUInt64T = 0 -_perf_t_render: t.CUInt64T = 0 -_perf_t_flush: t.CUInt64T = 0 -_perf_t_total: t.CUInt64T = 0 -_perf_frames: t.CUInt32T = 0 -_perf_start_ticks: t.CUInt64T = 0 -_perf_t_bg: t.CUInt64T = 0 -_perf_t_win: t.CUInt64T = 0 -_perf_t_cur: t.CUInt64T = 0 -_perf_t_fb: t.CUInt64T = 0 - -def _render(): - global _render_count, _cached_top_win - global _perf_t_bg, _perf_t_win, _perf_t_cur, _perf_t_fb - w: t.CInt = _screen_w - h: t.CInt = _screen_h - pitch: t.CInt = _fb_pitch - back: UINT32PTR = _back_fb - - _cached_top_win = _get_top_window() - - # No need to erase cursor - dirty row mechanism redraws background + windows from scratch - - t0: t.CUInt64T = timer.timer_get_ticks() - row_bytes: t.CInt = w * 4 - if _bg_row_buf and _dirty_count > 0: - py_bg: t.CInt = _dirty_y_min - while py_bg <= _dirty_y_max: - if _dirty_rows[py_bg]: - string.memcpy(t.CVoid(t.CUInt64T(back) + py_bg * row_bytes, t.CPtr), _bg_row_buf, row_bytes) - py_bg += 1 - t1: t.CUInt64T = timer.timer_get_ticks() - _perf_t_bg += (t1 - t0) - - _draw_taskbar(back) - - t2: t.CUInt64T = timer.timer_get_ticks() - sorted: t.CArray[t.CInt, MAX_APP_WINDOWS] - cnt: t.CInt = 0 - for si in range(_win_count): - if _wins[si].active and not _wins[si].minimized: - sorted[cnt] = si - cnt += 1 - for si in range(cnt - 1): - for sj in range(si + 1, cnt): - zi: t.CInt = _wins[sorted[si]].z_order - zj: t.CInt = _wins[sorted[sj]].z_order - if zi > zj: - tmp: t.CInt = sorted[si] - sorted[si] = sorted[sj] - sorted[sj] = tmp - for si in range(cnt): - _draw_app_window(back, c.Addr(_wins[sorted[si]])) - t3: t.CUInt64T = timer.timer_get_ticks() - _perf_t_win += (t3 - t2) - - # Mark cursor rows as dirty so cursor gets flushed to framebuffer - _mark_rows_dirty(_cursor_y, CURSOR_H) - - _draw_cursor(back) - t4: t.CUInt64T = timer.timer_get_ticks() - _perf_t_cur += (t4 - t3) - - _wait_vblank() - if _dirty_count > 0: - py_fb: t.CInt = _dirty_y_min - while py_fb <= _dirty_y_max: - if _dirty_rows[py_fb]: - run_start: t.CInt = py_fb - while py_fb <= _dirty_y_max and _dirty_rows[py_fb]: - py_fb += 1 - run_bytes: t.CInt = (py_fb - run_start) * row_bytes - string.memcpy(t.CVoid(t.CUInt64T(_fb) + run_start * pitch, t.CPtr), t.CVoid(t.CUInt64T(back) + run_start * row_bytes, t.CPtr), run_bytes) - else: - py_fb += 1 - t5: t.CUInt64T = timer.timer_get_ticks() - _perf_t_fb += (t5 - t4) - - _render_count += 1 - -def _draw_taskbar(back: UINT32PTR): - w: t.CInt = _screen_w - h: t.CInt = _screen_h - tb_h: t.CInt = TASKBAR_HEIGHT - bar_y: t.CInt = h - tb_h - if bar_y + tb_h <= _dirty_y_min or bar_y > _dirty_y_max: - return - bar_col: t.CUInt32T = gfx.COLOR_RGB(32, 32, 32) - line_col: t.CUInt32T = gfx.COLOR_RGB(60, 60, 60) - - _fill_rect(back, w, h, 0, bar_y, w, tb_h, bar_col) - _fill_rect(back, w, h, 0, bar_y, w, 1, line_col) - - logo_x: t.CInt = 4 - logo_sz: t.CInt = TASKBAR_LOGO_SZ - logo_y: t.CInt = bar_y + (tb_h - logo_sz) // 2 - lc1: t.CUInt32T = gfx.COLOR_RGB(80, 120, 220) - lc2: t.CUInt32T = gfx.COLOR_RGB(50, 80, 180) - lc3: t.CUInt32T = gfx.COLOR_RGB(100, 160, 255) - for lx in range(logo_sz): - for ly in range(logo_sz): - px: t.CInt = logo_x + lx - py: t.CInt = logo_y + ly - if px >= 0 and px < w and py >= 0 and py < h: - col: t.CUInt32T = lc2 - cx: t.CInt = logo_sz // 2 - cy: t.CInt = logo_sz // 2 - dx: t.CInt = lx - cx - dy: t.CInt = ly - cy - dist: t.CInt = dx * dx + dy * dy - r2: t.CInt = cx * cx - if dist <= r2: - col = lc1 - if dist <= r2 // 2: - col = lc3 - back[py * w + px] = col - - _draw_text(back, w, h, logo_x + logo_sz + 8, bar_y + (tb_h - 16) // 2, "ViperOS", 0xFFFFFFFF) - - icon_sz: t.CInt = TASKBAR_ICON_SZ - icon_pad: t.CInt = TASKBAR_ICON_PAD - icon_x: t.CInt = logo_x + logo_sz + 80 - icon_cnt: t.CInt = 0 - for ti in range(_win_count): - if _wins[ti].active: - ix: t.CInt = icon_x + icon_cnt * (icon_sz + icon_pad) - iy: t.CInt = bar_y + (tb_h - icon_sz) // 2 - is_focused: t.CInt = 1 if ti == _focused_win else 0 - is_minimized: t.CInt = _wins[ti].minimized - ic_bg: t.CUInt32T = gfx.COLOR_RGB(40, 40, 70) - if is_focused: - ic_bg = gfx.COLOR_RGB(60, 60, 120) - elif is_minimized: - ic_bg = gfx.COLOR_RGB(30, 30, 50) - _fill_rect(back, w, h, ix, iy, icon_sz, icon_sz, ic_bg) - ic_border: t.CUInt32T = gfx.COLOR_RGB(80, 80, 140) - if is_focused: - ic_border = gfx.COLOR_RGB(120, 120, 220) - _fill_rect(back, w, h, ix, iy, icon_sz, 1, ic_border) - _fill_rect(back, w, h, ix, iy + icon_sz - 1, icon_sz, 1, ic_border) - _fill_rect(back, w, h, ix, iy, 1, icon_sz, ic_border) - _fill_rect(back, w, h, ix + icon_sz - 1, iy, 1, icon_sz, ic_border) - if _wins[ti].title[0] != 0: - first_ch: t.CChar = _wins[ti].title[0] - ch_col: t.CUInt32T = 0xFFFFFFFF - if not is_focused: - ch_col = gfx.COLOR_RGB(180, 180, 200) - ch_x: t.CInt = ix + (icon_sz - 8) // 2 - ch_y: t.CInt = iy + (icon_sz - 16) // 2 - _draw_char(back, w, h, ch_x, ch_y, first_ch, ch_col) - icon_cnt += 1 - - if _render_count % 30 == 0: - rtc.rtc_read_time() - - hr: t.CUInt8T = rtc.rtc_get_hours() - mn: t.CUInt8T = rtc.rtc_get_minutes() - sc: t.CUInt8T = rtc.rtc_get_seconds() - day: t.CUInt8T = rtc.rtc_get_day() - mon: t.CUInt8T = rtc.rtc_get_month() - yr: t.CUInt16T = rtc.rtc_get_year() - time_buf: t.CArray[t.CChar, 64] - string.memset(c.Addr(time_buf), 0, 64) - viperlib.snprintf(c.Addr(time_buf), 64, "%04u-%02u-%02u %02u:%02u:%02u", t.CUnsignedInt(yr), t.CUnsignedInt(mon), t.CUnsignedInt(day), t.CUnsignedInt(hr), t.CUnsignedInt(mn), t.CUnsignedInt(sc)) - time_str_x: t.CInt = w - 180 - _draw_text(back, w, h, time_str_x, bar_y + (tb_h - 16) // 2, time_buf, 0xFFFFFFFF) - -def _draw_window_shadow(back: UINT32PTR, bw: t.CInt, bh: t.CInt, wx: t.CInt, wy: t.CInt, ww: t.CInt, wh: t.CInt, is_rounded: t.CInt, rad: t.CInt): - if not SHADOW_ENABLED: return - sl: t.CInt = SHADOW_LEFT - sr: t.CInt = SHADOW_RIGHT - st: t.CInt = SHADOW_TOP - sb: t.CInt = SHADOW_BOTTOM - sa: t.CInt = SHADOW_ALPHA - shadow_col: t.CUInt32T = gfx.COLOR_RGB(0, 0, 0) - for py in range(wy - st, wy + wh + sb): - if py >= 0 and py < bh: - if not _dirty_rows[py]: - continue - for px in range(wx - sl, wx + ww + sr): - if px >= 0 and px < bw: - in_win: t.CInt = 0 - if px >= wx and px < wx + ww and py >= wy and py < wy + wh: - in_win = 1 - if is_rounded: - rx: t.CInt = px - wx - ry: t.CInt = py - wy - if rx < rad and ry < rad: - if (rx - rad) * (rx - rad) + (ry - rad) * (ry - rad) > rad * rad: - in_win = 0 - elif rx >= ww - rad and ry < rad: - if (rx - (ww - rad - 1)) * (rx - (ww - rad - 1)) + (ry - rad) * (ry - rad) > rad * rad: - in_win = 0 - elif rx < rad and ry >= wh - rad: - if (rx - rad) * (rx - rad) + (ry - (wh - rad - 1)) * (ry - (wh - rad - 1)) > rad * rad: - in_win = 0 - elif rx >= ww - rad and ry >= wh - rad: - if (rx - (ww - rad - 1)) * (rx - (ww - rad - 1)) + (ry - (wh - rad - 1)) * (ry - (wh - rad - 1)) > rad * rad: - in_win = 0 - if in_win: - continue - cpx: t.CInt = px - if cpx < wx: cpx = wx - elif cpx > wx + ww - 1: cpx = wx + ww - 1 - cpy: t.CInt = py - if cpy < wy: cpy = wy - elif cpy > wy + wh - 1: cpy = wy + wh - 1 - if is_rounded and rad > 0: - if cpx < wx + rad and cpy < wy + rad: - acx: t.CInt = wx + rad - acy: t.CInt = wy + rad - adx: t.CInt = cpx - acx - ady: t.CInt = cpy - acy - ad_sq: t.CInt = adx * adx + ady * ady - if ad_sq > rad * rad and ad_sq > 0: - aax: t.CInt = adx - if aax < 0: aax = 0 - aax - aay: t.CInt = ady - if aay < 0: aay = 0 - aay - am: t.CInt = aax - if aay > am: am = aay - an: t.CInt = aax - if aay < an: an = aay - ad: t.CInt = am + (an * 3) / 8 - if ad > 0: - cpx = acx + (adx * rad) / ad - cpy = acy + (ady * rad) / ad - elif cpx >= wx + ww - rad and cpy < wy + rad: - acx = wx + ww - rad - 1 - acy = wy + rad - adx = cpx - acx - ady = cpy - acy - ad_sq = adx * adx + ady * ady - if ad_sq > rad * rad and ad_sq > 0: - aax = adx - if aax < 0: aax = 0 - aax - aay = ady - if aay < 0: aay = 0 - aay - am = aax - if aay > am: am = aay - an = aax - if aay < an: an = aay - ad = am + (an * 3) / 8 - if ad > 0: - cpx = acx + (adx * rad) / ad - cpy = acy + (ady * rad) / ad - elif cpx < wx + rad and cpy >= wy + wh - rad: - acx = wx + rad - acy = wy + wh - rad - 1 - adx = cpx - acx - ady = cpy - acy - ad_sq = adx * adx + ady * ady - if ad_sq > rad * rad and ad_sq > 0: - aax = adx - if aax < 0: aax = 0 - aax - aay = ady - if aay < 0: aay = 0 - aay - am = aax - if aay > am: am = aay - an = aax - if aay < an: an = aay - ad = am + (an * 3) / 8 - if ad > 0: - cpx = acx + (adx * rad) / ad - cpy = acy + (ady * rad) / ad - elif cpx >= wx + ww - rad and cpy >= wy + wh - rad: - acx = wx + ww - rad - 1 - acy = wy + wh - rad - 1 - adx = cpx - acx - ady = cpy - acy - ad_sq = adx * adx + ady * ady - if ad_sq > rad * rad and ad_sq > 0: - aax = adx - if aax < 0: aax = 0 - aax - aay = ady - if aay < 0: aay = 0 - aay - am = aax - if aay > am: am = aay - an = aax - if aay < an: an = aay - ad = am + (an * 3) / 8 - if ad > 0: - cpx = acx + (adx * rad) / ad - cpy = acy + (ady * rad) / ad - dx: t.CInt = px - cpx - dy: t.CInt = py - cpy - adx_d: t.CInt = dx - if adx_d < 0: adx_d = 0 - adx_d - ady_d: t.CInt = dy - if ady_d < 0: ady_d = 0 - ady_d - dist: t.CInt = adx_d - if ady_d > dist: dist = ady_d - dist = dist + ((adx_d + ady_d - dist) * 3) / 8 - me_x: t.CInt = sl - if dx > 0: me_x = sr - me_y: t.CInt = st - if dy > 0: me_y = sb - me: t.CInt = me_x - if adx_d + ady_d > 0: - me = (me_x * adx_d + me_y * ady_d) / (adx_d + ady_d) - if me > 0 and dist > 0 and dist < me: - t_val: t.CInt = (256 * dist) / me - t_inv: t.CInt = 256 - t_val - a: t.CInt = (sa * t_inv * t_inv) / 65536 - if a > 0: - back[py * bw + px] = _alpha_blend(back[py * bw + px], shadow_col, a) - -def _cursor_save_bg(back: UINT32PTR, cx: t.CInt, cy: t.CInt, w: t.CInt, h: t.CInt): - global _cursor_saved - cw: t.CInt = CURSOR_W - ch: t.CInt = CURSOR_H - for dy in range(ch): - for dx in range(cw): - sx: t.CInt = cx + dx - sy: t.CInt = cy + dy - if sx >= 0 and sx < w and sy >= 0 and sy < h: - _cursor_save_buf[dy * cw + dx] = back[sy * w + sx] - else: - _cursor_save_buf[dy * cw + dx] = 0 - _cursor_saved = 1 - -def _cursor_restore_bg(back: UINT32PTR, cx: t.CInt, cy: t.CInt, w: t.CInt, h: t.CInt): - global _cursor_saved - if _cursor_saved == 0: return - cw: t.CInt = CURSOR_W - ch: t.CInt = CURSOR_H - for dy in range(ch): - for dx in range(cw): - sx: t.CInt = cx + dx - sy: t.CInt = cy + dy - if sx >= 0 and sx < w and sy >= 0 and sy < h: - back[sy * w + sx] = _cursor_save_buf[dy * cw + dx] - _cursor_saved = 0 - -def _cursor_draw_bitmap(back: UINT32PTR, cx: t.CInt, cy: t.CInt, w: t.CInt, h: t.CInt, bmp: t.CArray[t.CUInt8T, 256]): - cw: t.CInt = CURSOR_W - ch: t.CInt = CURSOR_H - white: t.CUInt32T = gfx.COLOR_RGB(255, 255, 255) - black: t.CUInt32T = gfx.COLOR_RGB(0, 0, 0) - for dy in range(ch): - for dx in range(cw): - pixel: t.CUInt8T = bmp[dy * cw + dx] - if pixel != 0: - px: t.CInt = cx + dx - py: t.CInt = cy + dy - if px >= 0 and px < w and py >= 0 and py < h: - if pixel == 1: - back[py * w + px] = black - elif pixel == 2: - back[py * w + px] = white - -def _cursor_draw_xor(back: UINT32PTR, cx: t.CInt, cy: t.CInt, w: t.CInt, h: t.CInt, bmp: t.CArray[t.CUInt8T, 256]): - cw: t.CInt = CURSOR_W - ch: t.CInt = CURSOR_H - xor_val: t.CUInt32T = t.CUInt32T(0x00FFFFFF) - for dy in range(ch): - for dx in range(cw): - pixel: t.CUInt8T = bmp[dy * cw + dx] - if pixel != 0: - px: t.CInt = cx + dx - py: t.CInt = cy + dy - if px >= 0 and px < w and py >= 0 and py < h: - back[py * w + px] = back[py * w + px] ^ xor_val - -def _draw_cursor(back: UINT32PTR): - cx: t.CInt = _cursor_x - cy: t.CInt = _cursor_y - w: t.CInt = _screen_w - h: t.CInt = _screen_h - cur_type: t.CInt = CURSOR_DEFAULT - if _last_hover_win >= 0 and _last_hover_win < _win_count: - cur_type = _wins[_last_hover_win].cursor_type - if cur_type == CURSOR_IBEAM: - _cursor_draw_bitmap(back, cx, cy, w, h, _CURSOR_IBEAM) - elif cur_type == CURSOR_RESIZE_EW: - _cursor_draw_bitmap(back, cx, cy, w, h, _CURSOR_RESIZE_EW) - elif cur_type == CURSOR_RESIZE_NS: - _cursor_draw_bitmap(back, cx, cy, w, h, _CURSOR_RESIZE_NS) - elif cur_type == CURSOR_RESIZE_NWSE: - _cursor_draw_bitmap(back, cx, cy, w, h, _CURSOR_RESIZE_NWSE) - else: - _cursor_draw_bitmap(back, cx, cy, w, h, _CURSOR_ARROW) - -def _erase_cursor(back: UINT32PTR): - global _cursor_saved - if _cursor_saved == 0: return - _cursor_restore_bg(back, _prev_cursor_x, _prev_cursor_y, _screen_w, _screen_h) - -def desktop_thread(arg: t.CVoid | t.CPtr) -> t.CInt: - global _last_clock_sec, _mouse_moved - global _prev_cursor_x, _prev_cursor_y - global _perf_t_mouse, _perf_t_kbd, _perf_t_render, _perf_t_flush, _perf_t_total, _perf_frames, _perf_start_ticks - global _perf_t_bg, _perf_t_win, _perf_t_cur, _perf_t_fb - serial.puts("[desktop] thread started\n") - _mark_all_dirty() - _dt_hb_sec: t.CUInt32T = 0 - tb_h_dt: t.CInt = TASKBAR_HEIGHT - _perf_buf: t.CArray[t.CChar, 256] - _perf_start_ticks = timer.timer_get_ticks() - _kbd_poll_ticks: t.CUInt64T = 0 - _mouse_poll_ticks: t.CUInt64T = 0 - while True: - _loop_t0: t.CUInt64T = timer.timer_get_ticks() - # Poll mouse at most every 4ms to avoid excessive I/O port overhead - _now_ticks: t.CUInt64T = timer.timer_get_ticks() - if _now_ticks - _mouse_poll_ticks >= 4: - _mouse_poll_ticks = _now_ticks - _mt0: t.CUInt64T = timer.timer_get_ticks() - mouse_active: t.CInt = _update_mouse() - _mt1: t.CUInt64T = timer.timer_get_ticks() - _perf_t_mouse += (_mt1 - _mt0) - # Poll keyboard at most every 4ms to avoid excessive I/O port overhead - if _now_ticks - _kbd_poll_ticks >= 4: - _kbd_poll_ticks = _now_ticks - _kt0: t.CUInt64T = timer.timer_get_ticks() - _update_keyboard() - _kt1: t.CUInt64T = timer.timer_get_ticks() - _perf_t_kbd += (_kt1 - _kt0) - _heartbeat_check() - sched.Scheduler.try_reschedule() - _dt_cur_sec: t.CUInt32T = timer.timer_get_seconds() - if _dt_cur_sec != _dt_hb_sec: - _dt_hb_sec = _dt_cur_sec - cur_sec: t.CUInt32T = timer.timer_get_seconds() - if cur_sec != _last_clock_sec: - _last_clock_sec = cur_sec - _mark_rows_dirty(_screen_h - tb_h_dt, tb_h_dt) - if _mouse_moved: - _mouse_moved = 0 - sz: t.CInt = CURSOR_H - _mark_rows_dirty(_prev_cursor_y, sz) - _mark_rows_dirty(_cursor_y, sz) - _prev_cursor_x = _cursor_x - _prev_cursor_y = _cursor_y - top_win: t.CInt = _hit_test_window(_cursor_x, _cursor_y) - for ai in range(_win_count): - if _wins[ai].active and not _wins[ai].minimized: - th: t.CInt = _get_title_height(_wins[ai].style) - btn_w: t.CInt = CLOSE_BTN_SIZE - btn_h: t.CInt = CLOSE_BTN_SIZE - ew_hov: t.CInt = _eff_w(c.Addr(_wins[ai])) - btn_x: t.CInt = _wins[ai].x + ew_hov - btn_w - 4 - btn_y: t.CInt = _wins[ai].y + (th - btn_h) // 2 - if _wins[ai].style == STYLE_WIN7: - btn_w = CLOSE_BTN_W7_W - btn_h = CLOSE_BTN_W7_H - btn_x = _wins[ai].x + ew_hov - btn_w - 5 - btn_y = _wins[ai].y + (th - btn_h) // 2 - elif _wins[ai].style == STYLE_WINXP: - btn_w = CLOSE_BTN_XP_SZ - btn_h = CLOSE_BTN_XP_SZ - btn_x = _wins[ai].x + ew_hov - btn_w - 5 - btn_y = _wins[ai].y + (th - btn_h) // 2 - elif _wins[ai].style == STYLE_WIN10 or _wins[ai].style == STYLE_WIN11: - btn_w = CLOSE_BTN_W_WIN - btn_h = th - 2 - btn_x = _wins[ai].x + ew_hov - btn_w - btn_y = _wins[ai].y + 1 - max_bx3: t.CInt = btn_x - btn_w - if _wins[ai].style == STYLE_WIN7 or _wins[ai].style == STYLE_WINXP: - max_bx3 = btn_x - btn_w - 1 - min_bx3: t.CInt = max_bx3 - btn_w - if _wins[ai].style == STYLE_WIN7 or _wins[ai].style == STYLE_WINXP: - min_bx3 = max_bx3 - btn_w - 1 - is_over_close: t.CInt = 0 - is_over_max: t.CInt = 0 - is_over_min: t.CInt = 0 - if ai == top_win: - if _cursor_x >= btn_x and _cursor_x < btn_x + btn_w and _cursor_y >= btn_y and _cursor_y < btn_y + btn_h: - is_over_close = 1 - elif _cursor_x >= max_bx3 and _cursor_x < max_bx3 + btn_w and _cursor_y >= btn_y and _cursor_y < btn_y + btn_h: - is_over_max = 1 - elif _cursor_x >= min_bx3 and _cursor_x < min_bx3 + btn_w and _cursor_y >= btn_y and _cursor_y < btn_y + btn_h: - is_over_min = 1 - if is_over_close and _wins[ai].close_hover < 255: - _old_hov: t.CInt = _wins[ai].close_hover - _wins[ai].close_hover += 60 - if _wins[ai].close_hover > 255: - _wins[ai].close_hover = 255 - if _wins[ai].close_hover != _old_hov: - _mark_rows_dirty(btn_y, btn_h) - elif not is_over_close and _wins[ai].close_hover > 0: - _old_hov2: t.CInt = _wins[ai].close_hover - _wins[ai].close_hover -= 45 - if _wins[ai].close_hover < 0: - _wins[ai].close_hover = 0 - if _wins[ai].close_hover != _old_hov2: - _mark_rows_dirty(btn_y, btn_h) - if is_over_max and _wins[ai].max_hover < 255: - _old_mh: t.CInt = _wins[ai].max_hover - _wins[ai].max_hover += 60 - if _wins[ai].max_hover > 255: - _wins[ai].max_hover = 255 - if _wins[ai].max_hover != _old_mh: - _mark_rows_dirty(btn_y, btn_h) - elif not is_over_max and _wins[ai].max_hover > 0: - _old_mh2: t.CInt = _wins[ai].max_hover - _wins[ai].max_hover -= 45 - if _wins[ai].max_hover < 0: - _wins[ai].max_hover = 0 - if _wins[ai].max_hover != _old_mh2: - _mark_rows_dirty(btn_y, btn_h) - if is_over_min and _wins[ai].min_hover < 255: - _old_nh: t.CInt = _wins[ai].min_hover - _wins[ai].min_hover += 60 - if _wins[ai].min_hover > 255: - _wins[ai].min_hover = 255 - if _wins[ai].min_hover != _old_nh: - _mark_rows_dirty(btn_y, btn_h) - elif not is_over_min and _wins[ai].min_hover > 0: - _old_nh2: t.CInt = _wins[ai].min_hover - _wins[ai].min_hover -= 45 - if _wins[ai].min_hover < 0: - _wins[ai].min_hover = 0 - if _wins[ai].min_hover != _old_nh2: - _mark_rows_dirty(btn_y, btn_h) - if _has_dirty_rows(): - _rt0: t.CUInt64T = timer.timer_get_ticks() - _render() - _rt1: t.CUInt64T = timer.timer_get_ticks() - _perf_t_render += (_rt1 - _rt0) - _ft0: t.CUInt64T = timer.timer_get_ticks() - _clear_dirty_flags() - _ft1: t.CUInt64T = timer.timer_get_ticks() - _perf_t_flush += (_ft1 - _ft0) - _perf_frames += 1 - _loop_t1: t.CUInt64T = timer.timer_get_ticks() - _perf_t_total += (_loop_t1 - _loop_t0) - _now_ticks: t.CUInt64T = timer.timer_get_ticks() - _elapsed_ms: t.CUInt64T = _now_ticks - _perf_start_ticks - if _elapsed_ms >= 1000: - _fps_val: t.CUInt32T = 0 - if _elapsed_ms > 0: - _fps_val = t.CUInt32T(t.CUInt64T(_perf_frames) * 1000 / _elapsed_ms) - string.memset(c.Addr(_perf_buf), 0, 256) - viperlib.snprintf(c.Addr(_perf_buf), 256, "[perf] fps=%u wall=%lu work=%lu mouse=%lu kbd=%lu render=%lu(bg=%lu win=%lu cur=%lu fb=%lu) dirty=%d vsync=%d\n", _fps_val, t.CUInt64T(_elapsed_ms), t.CUInt64T(_perf_t_total), t.CUInt64T(_perf_t_mouse), t.CUInt64T(_perf_t_kbd), t.CUInt64T(_perf_t_render), t.CUInt64T(_perf_t_bg), t.CUInt64T(_perf_t_win), t.CUInt64T(_perf_t_cur), t.CUInt64T(_perf_t_fb), _dirty_count, _vblank_ok) - serial.puts(c.Addr(_perf_buf)) - _perf_t_mouse = 0 - _perf_t_kbd = 0 - _perf_t_render = 0 - _perf_t_flush = 0 - _perf_t_total = 0 - _perf_t_bg = 0 - _perf_t_win = 0 - _perf_t_cur = 0 - _perf_t_fb = 0 - _perf_frames = 0 - _perf_start_ticks = _now_ticks - sched.Scheduler.try_reschedule() - return 0 - -def start(fb_ptr: t.CVoid | t.CPtr, w: t.CInt, h: t.CInt, pitch: t.CInt = 0) -> sched.Thread | t.CPtr: - global _fb, _screen_w, _screen_h, _fb_pitch, _cursor_x, _cursor_y - global _back_fb, _row_buf - global _dirty_rows, _prev_cursor_x, _prev_cursor_y - _fb = fb_ptr - _screen_w = w - _screen_h = h - if pitch > 0: - _fb_pitch = pitch - else: - _fb_pitch = w * 4 - _cursor_x = w // 2 - _cursor_y = h // 2 - _prev_cursor_x = _cursor_x - _prev_cursor_y = _cursor_y - - _dirty_rows = mm.malloc(h) - if _dirty_rows: - string.memset(_dirty_rows, 0, h) - else: - serial.puts("[desktop] dirty_rows malloc FAILED\n") - return None - - _back_fb = mm.malloc(w * h * 4) - if _back_fb: - string.memset(_back_fb, 0, w * h * 4) - else: - serial.puts("[desktop] back_fb malloc FAILED\n") - return None - - _row_buf = mm.malloc(w * 4) - if _row_buf: - string.memset(_row_buf, 0, w * 4) - else: - serial.puts("[desktop] row_buf malloc FAILED!\n") - - _bg_row_buf = mm.malloc(w * 4) - if _bg_row_buf: - desktop_init_col: t.CUInt32T = gfx.COLOR_RGB(25, 25, 35) - for ri in range(w): - _bg_row_buf[ri] = desktop_init_col - else: - serial.puts("[desktop] bg_row_buf malloc FAILED!\n") - - _mark_all_dirty() - p: process.Process | t.CPtr = process.ProcessManager.create_process("desktop", None) - desktop_pid: t.CInt = 0 - if p: - desktop_pid = p.pid - th: sched.Thread | t.CPtr = sched.Scheduler.create_thread(desktop_thread, None, desktop_pid) - if p and th: - p.addThread(th.tid) - return th - -def _get_top_window() -> t.CInt: - best: t.CInt = -1 - best_z: t.CInt = -1 - for ai in range(_win_count): - if _wins[ai].active and not _wins[ai].minimized: - z: t.CInt = _wins[ai].z_order - if z > best_z: - best_z = z - best = ai - return best - -def _draw_min_btn(back: UINT32PTR, bw: t.CInt, bh: t.CInt, bx: t.CInt, by: t.CInt, btn_w: t.CInt, btn_h: t.CInt, hover_alpha: t.CInt, style: t.CInt): - if hover_alpha > 0: - hover_col: t.CUInt32T = gfx.COLOR_RGB(80, 80, 80) - if style == STYLE_WIN7: - hover_col = gfx.COLOR_RGB(200, 220, 240) - elif style == STYLE_WINXP: - hover_col = gfx.COLOR_RGB(180, 210, 240) - for py in range(by, by + btn_h): - if py >= 0 and py < bh: - for px in range(bx, bx + btn_w): - if px >= 0 and px < bw: - bg_pixel: t.CUInt32T = back[py * bw + px] - back[py * bw + px] = _alpha_blend(bg_pixel, hover_col, hover_alpha) - line_col: t.CUInt32T = gfx.COLOR_RGB(180, 180, 180) - if hover_alpha > 0: - line_col = gfx.COLOR_RGB(255, 255, 255) - cx: t.CInt = bx + btn_w // 2 - cy: t.CInt = by + btn_h // 2 - lw: t.CInt = 5 - if btn_w >= 30: - lw = 8 - ly: t.CInt = cy + 3 - if ly >= 0 and ly < bh: - for lx in range(cx - lw, cx + lw + 1): - if lx >= 0 and lx < bw: - back[ly * bw + lx] = line_col - -def _draw_max_btn(back: UINT32PTR, bw: t.CInt, bh: t.CInt, bx: t.CInt, by: t.CInt, btn_w: t.CInt, btn_h: t.CInt, hover_alpha: t.CInt, style: t.CInt, is_maximized: t.CInt): - if hover_alpha > 0: - hover_col2: t.CUInt32T = gfx.COLOR_RGB(80, 80, 80) - if style == STYLE_WIN7: - hover_col2 = gfx.COLOR_RGB(200, 220, 240) - elif style == STYLE_WINXP: - hover_col2 = gfx.COLOR_RGB(180, 210, 240) - for py2 in range(by, by + btn_h): - if py2 >= 0 and py2 < bh: - for px2 in range(bx, bx + btn_w): - if px2 >= 0 and px2 < bw: - bg_pixel2: t.CUInt32T = back[py2 * bw + px2] - back[py2 * bw + px2] = _alpha_blend(bg_pixel2, hover_col2, hover_alpha) - rect_col: t.CUInt32T = gfx.COLOR_RGB(180, 180, 180) - if hover_alpha > 0: - rect_col = gfx.COLOR_RGB(255, 255, 255) - cx2: t.CInt = bx + btn_w // 2 - cy2: t.CInt = by + btn_h // 2 - sz: t.CInt = 4 - if btn_w >= 30: - sz = 6 - if is_maximized: - off: t.CInt = 2 - for ry1 in range(cy2 - sz + off, cy2 + sz + off + 1): - if ry1 >= 0 and ry1 < bh: - for rx1 in range(cx2 - sz + off, cx2 + sz + off + 1): - if rx1 >= 0 and rx1 < bw: - is_top: t.CInt = 0 - if ry1 == cy2 - sz + off or ry1 == cy2 - sz + off + 1: - is_top = 1 - is_border: t.CInt = 0 - if ry1 == cy2 - sz + off or ry1 == cy2 + sz + off or rx1 == cx2 - sz + off or rx1 == cx2 + sz + off: - is_border = 1 - if is_top or is_border: - back[ry1 * bw + rx1] = rect_col - for ry2 in range(cy2 - sz, cy2 + sz + 1): - if ry2 >= 0 and ry2 < bh: - for rx2 in range(cx2 - sz, cx2 + sz + 1): - if rx2 >= 0 and rx2 < bw: - if ry2 == cy2 - sz or ry2 == cy2 - sz + 1 or rx2 == cx2 - sz or rx2 == cx2 + sz: - back[ry2 * bw + rx2] = rect_col - else: - for ry3 in range(cy2 - sz, cy2 + sz + 1): - if ry3 >= 0 and ry3 < bh: - for rx3 in range(cx2 - sz, cx2 + sz + 1): - if rx3 >= 0 and rx3 < bw: - if ry3 == cy2 - sz or ry3 == cy2 + sz or rx3 == cx2 - sz or rx3 == cx2 + sz: - back[ry3 * bw + rx3] = rect_col - top_y: t.CInt = cy2 - sz - if top_y >= 0 and top_y < bh: - for tx in range(cx2 - sz, cx2 + sz + 1): - if tx >= 0 and tx < bw: - back[top_y * bw + tx] = rect_col - if top_y + 1 < bh: - for tx2 in range(cx2 - sz, cx2 + sz + 1): - if tx2 >= 0 and tx2 < bw: - back[(top_y + 1) * bw + tx2] = rect_col - -def _draw_close_btn(back: UINT32PTR, bw: t.CInt, bh: t.CInt, bx: t.CInt, by: t.CInt, btn_w: t.CInt, btn_h: t.CInt, hover_alpha: t.CInt, style: t.CInt, clip_wx: t.CInt, clip_wy: t.CInt, clip_ww: t.CInt, clip_r: t.CInt): - x_col: t.CUInt32T = gfx.COLOR_RGB(200, 200, 200) - if style == STYLE_CLASSIC: - bg: t.CUInt32T = gfx.COLOR_RGB(40, 40, 70) - if hover_alpha > 0: - red: t.CUInt32T = gfx.COLOR_RGB(200, 50, 50) - bg = _alpha_blend(bg, red, hover_alpha) - _fill_rect(back, bw, bh, bx, by, btn_w, btn_h, bg) - if hover_alpha > 128: - x_col = gfx.COLOR_RGB(255, 255, 255) - elif style == STYLE_WIN7: - br: t.CInt = CLOSE_BTN_W7_R - bg_r: t.CInt = 200 - bg_g: t.CInt = 50 - bg_b: t.CInt = 50 - if hover_alpha > 0: - bg_r = 200 + ((232 - 200) * hover_alpha) / 255 - bg_g = 50 + ((17 - 50) * hover_alpha) / 255 - bg_b = 50 + ((35 - 50) * hover_alpha) / 255 - bg_col7: t.CUInt32T = gfx.COLOR_RGB(bg_r, bg_g, bg_b) - for py2 in range(by, by + btn_h): - if py2 >= 0 and py2 < bh: - for px2 in range(bx, bx + btn_w): - if px2 >= 0 and px2 < bw: - lrx: t.CInt = px2 - bx - lry: t.CInt = py2 - by - if lry < br: - if lrx < br: - if (lrx - br) * (lrx - br) + (lry - br) * (lry - br) > br * br: - continue - elif lrx >= btn_w - br: - if (lrx - (btn_w - br - 1)) * (lrx - (btn_w - br - 1)) + (lry - br) * (lry - br) > br * br: - continue - elif lry >= btn_h - br: - if lrx < br: - if (lrx - br) * (lrx - br) + (lry - (btn_h - br - 1)) * (lry - (btn_h - br - 1)) > br * br: - continue - elif lrx >= btn_w - br: - if (lrx - (btn_w - br - 1)) * (lrx - (btn_w - br - 1)) + (lry - (btn_h - br - 1)) * (lry - (btn_h - br - 1)) > br * br: - continue - if clip_r > 0: - crx: t.CInt = px2 - clip_wx - cry: t.CInt = py2 - clip_wy - if cry < clip_r and crx >= clip_ww - clip_r: - cdx: t.CInt = crx - (clip_ww - clip_r - 1) - cdy: t.CInt = cry - clip_r - if cdx * cdx + cdy * cdy > clip_r * clip_r: - continue - back[py2 * bw + px2] = bg_col7 - x_col = gfx.COLOR_RGB(255, 255, 255) - if hover_alpha > 0: - x_col = _alpha_blend(gfx.COLOR_RGB(255, 255, 255), gfx.COLOR_RGB(255, 240, 240), hover_alpha) - elif style == STYLE_WINXP: - br_xp: t.CInt = 3 - bg_r_xp: t.CInt = 200 - bg_g_xp: t.CInt = 50 - bg_b_xp: t.CInt = 50 - if hover_alpha > 0: - bg_r_xp = 200 + ((232 - 200) * hover_alpha) / 255 - bg_g_xp = 50 + ((17 - 50) * hover_alpha) / 255 - bg_b_xp = 50 + ((35 - 50) * hover_alpha) / 255 - bg_col_xp: t.CUInt32T = gfx.COLOR_RGB(bg_r_xp, bg_g_xp, bg_b_xp) - for py_xp in range(by, by + btn_h): - if py_xp >= 0 and py_xp < bh: - for px_xp in range(bx, bx + btn_w): - if px_xp >= 0 and px_xp < bw: - lrx_xp: t.CInt = px_xp - bx - lry_xp: t.CInt = py_xp - by - if lry_xp < br_xp: - if lrx_xp < br_xp: - if (lrx_xp - br_xp) * (lrx_xp - br_xp) + (lry_xp - br_xp) * (lry_xp - br_xp) > br_xp * br_xp: - continue - elif lrx_xp >= btn_w - br_xp: - if (lrx_xp - (btn_w - br_xp - 1)) * (lrx_xp - (btn_w - br_xp - 1)) + (lry_xp - br_xp) * (lry_xp - br_xp) > br_xp * br_xp: - continue - elif lry_xp >= btn_h - br_xp: - if lrx_xp < br_xp: - if (lrx_xp - br_xp) * (lrx_xp - br_xp) + (lry_xp - (btn_h - br_xp - 1)) * (lry_xp - (btn_h - br_xp - 1)) > br_xp * br_xp: - continue - elif lrx_xp >= btn_w - br_xp: - if (lrx_xp - (btn_w - br_xp - 1)) * (lrx_xp - (btn_w - br_xp - 1)) + (lry_xp - (btn_h - br_xp - 1)) * (lry_xp - (btn_h - br_xp - 1)) > br_xp * br_xp: - continue - back[py_xp * bw + px_xp] = bg_col_xp - x_col = gfx.COLOR_RGB(255, 255, 255) - if hover_alpha > 0: - x_col = _alpha_blend(gfx.COLOR_RGB(255, 255, 255), gfx.COLOR_RGB(255, 240, 240), hover_alpha) - else: - if hover_alpha > 0: - red = gfx.COLOR_RGB(232, 17, 35) - for py3 in range(by, by + btn_h): - if py3 >= 0 and py3 < bh: - for px3 in range(bx, bx + btn_w): - if px3 >= 0 and px3 < bw: - if clip_r > 0: - crx3: t.CInt = px3 - clip_wx - cry3: t.CInt = py3 - clip_wy - if cry3 < clip_r and crx3 >= clip_ww - clip_r: - cdx3: t.CInt = crx3 - (clip_ww - clip_r - 1) - cdy3: t.CInt = cry3 - clip_r - if cdx3 * cdx3 + cdy3 * cdy3 > clip_r * clip_r: - continue - bg_pixel: t.CUInt32T = back[py3 * bw + px3] - back[py3 * bw + px3] = _alpha_blend(bg_pixel, red, hover_alpha) - x_col = gfx.COLOR_RGB(150, 150, 150) - if hover_alpha > 0: - x_col = _alpha_blend(gfx.COLOR_RGB(150, 150, 150), gfx.COLOR_RGB(255, 255, 255), hover_alpha) - cx: t.CInt = bx + btn_w // 2 - cy: t.CInt = by + btn_h // 2 - d: t.CInt = 3 - if btn_w >= 30: - d = 4 - i: t.CInt = -d - while i <= d: - px1: t.CInt = cx + i - py1: t.CInt = cy + i - px2b: t.CInt = cx + i - py2b: t.CInt = cy - i - if px1 >= 0 and px1 < bw and py1 >= 0 and py1 < bh: - if clip_r > 0: - crx1: t.CInt = px1 - clip_wx - cry1: t.CInt = py1 - clip_wy - if cry1 < clip_r and crx1 >= clip_ww - clip_r: - cdx1: t.CInt = crx1 - (clip_ww - clip_r - 1) - cdy1: t.CInt = cry1 - clip_r - if cdx1 * cdx1 + cdy1 * cdy1 > clip_r * clip_r: - i += 1 - continue - back[py1 * bw + px1] = x_col - if px2b >= 0 and px2b < bw and py2b >= 0 and py2b < bh: - if clip_r > 0: - crx2: t.CInt = px2b - clip_wx - cry2: t.CInt = py2b - clip_wy - if cry2 < clip_r and crx2 >= clip_ww - clip_r: - cdx2: t.CInt = crx2 - (clip_ww - clip_r - 1) - cdy2: t.CInt = cry2 - clip_r - if cdx2 * cdx2 + cdy2 * cdy2 > clip_r * clip_r: - i += 1 - continue - back[py2b * bw + px2b] = x_col - i += 1 - -def _draw_app_window(back: UINT32PTR, win: AppWindow | t.CPtr): - w: t.CInt = _screen_w - h: t.CInt = _screen_h - wx: t.CInt = win.x - wy: t.CInt = win.y - ww: t.CInt = _eff_w(win) - wh: t.CInt = win.h - ch: t.CInt = _eff_h(win) - style: t.CInt = win.style - th: t.CInt = _get_title_height(style) - - if wy + wh <= _dirty_y_min or wy > _dirty_y_max: - return - - top_idx: t.CInt = _cached_top_win - is_active: t.CInt = 0 - if top_idx >= 0: - top_z: t.CInt = _wins[top_idx].z_order - if win.z_order == top_z: - is_active = 1 - - title_col: t.CUInt32T = gfx.COLOR_RGB(50, 50, 90) - border_col: t.CUInt32T = gfx.COLOR_RGB(100, 100, 180) - content_col: t.CUInt32T = gfx.COLOR_RGB(30, 30, 50) - outline_col: t.CUInt32T = gfx.COLOR_RGB(100, 100, 180) - title_alpha: t.CInt = 255 - has_separator: t.CInt = 1 - if style == STYLE_WIN10: - has_separator = 0 - if is_active: - title_col = gfx.COLOR_RGB(0, 0, 0) - border_col = gfx.COLOR_RGB(0, 0, 0) - content_col = gfx.COLOR_RGB(32, 32, 32) - outline_col = gfx.COLOR_RGB(80, 80, 80) - else: - title_col = gfx.COLOR_RGB(32, 32, 32) - border_col = gfx.COLOR_RGB(32, 32, 32) - content_col = gfx.COLOR_RGB(24, 24, 24) - outline_col = gfx.COLOR_RGB(60, 60, 60) - elif style == STYLE_WIN11: - has_separator = 0 - if is_active: - title_col = gfx.COLOR_RGB(32, 32, 32) - border_col = gfx.COLOR_RGB(32, 32, 32) - content_col = gfx.COLOR_RGB(32, 32, 32) - outline_col = gfx.COLOR_RGB(70, 70, 70) - else: - title_col = gfx.COLOR_RGB(40, 40, 40) - border_col = gfx.COLOR_RGB(40, 40, 40) - content_col = gfx.COLOR_RGB(40, 40, 40) - outline_col = gfx.COLOR_RGB(60, 60, 60) - elif style == STYLE_WIN7: - has_separator = 0 - if is_active: - title_col = gfx.COLOR_RGB(156, 181, 209) - border_col = gfx.COLOR_RGB(156, 181, 209) - content_col = gfx.COLOR_RGB(240, 240, 240) - outline_col = gfx.COLOR_RGB(100, 130, 170) - else: - title_col = gfx.COLOR_RGB(180, 195, 210) - border_col = gfx.COLOR_RGB(180, 195, 210) - content_col = gfx.COLOR_RGB(240, 240, 240) - outline_col = gfx.COLOR_RGB(140, 155, 175) - title_alpha = 102 - elif style == STYLE_WINXP: - has_separator = 0 - if is_active: - title_col = gfx.COLOR_RGB(107, 158, 212) - border_col = gfx.COLOR_RGB(107, 158, 212) - content_col = gfx.COLOR_RGB(235, 235, 235) - outline_col = gfx.COLOR_RGB(43, 87, 151) - else: - title_col = gfx.COLOR_RGB(140, 160, 195) - border_col = gfx.COLOR_RGB(140, 160, 195) - content_col = gfx.COLOR_RGB(235, 235, 235) - outline_col = gfx.COLOR_RGB(100, 115, 145) - else: - if is_active: - title_col = gfx.COLOR_RGB(70, 70, 130) - border_col = gfx.COLOR_RGB(130, 130, 220) - outline_col = gfx.COLOR_RGB(130, 130, 220) - - rounded: t.CInt = 0 - if style == STYLE_WIN11 or style == STYLE_WIN7 or style == STYLE_WINXP: - rounded = 1 - r: t.CInt = WIN_RADIUS - - _draw_window_shadow(back, w, h, wx, wy, ww, wh, rounded, r) - - if rounded: - for py in range(wy, wy + wh): - if py < 0 or py >= h: continue - if not _dirty_rows[py]: continue - ry: t.CInt = py - wy - row_col: t.CUInt32T = content_col - row_is_title: t.CInt = 0 - row_is_sep: t.CInt = 0 - if ry < th: - row_is_title = 1 - if style == STYLE_WIN7: - ratio: t.CInt = (ry * 100) / th - if ratio > 100: ratio = 100 - if is_active: - gr: t.CInt = 156 + ((186 - 156) * ratio) / 100 - gg: t.CInt = 181 + ((209 - 181) * ratio) / 100 - gb: t.CInt = 209 + ((233 - 209) * ratio) / 100 - else: - gr = 180 + ((200 - 180) * ratio) / 100 - gg = 195 + ((210 - 195) * ratio) / 100 - gb = 210 + ((225 - 210) * ratio) / 100 - row_col = gfx.COLOR_RGB(gr, gg, gb) - if ry == 0: - row_col = _alpha_blend(row_col, gfx.COLOR_RGB(220, 235, 255), 50) - elif ry == 1: - row_col = _alpha_blend(row_col, gfx.COLOR_RGB(210, 225, 250), 20) - if ry == th - 1: - row_col = _alpha_blend(row_col, gfx.COLOR_RGB(130, 160, 200), 25) - elif style == STYLE_WINXP: - ratio = (ry * 100) / th - if ratio > 100: ratio = 100 - if is_active: - gr = 107 + ((58 - 107) * ratio) / 100 - gg = 158 + ((124 - 158) * ratio) / 100 - gb = 212 + ((195 - 212) * ratio) / 100 - else: - gr = 150 + ((115 - 150) * ratio) / 100 - gg = 170 + ((135 - 170) * ratio) / 100 - gb = 205 + ((175 - 205) * ratio) / 100 - row_col = gfx.COLOR_RGB(gr, gg, gb) - if ry == 0: - row_col = _alpha_blend(row_col, gfx.COLOR_RGB(200, 225, 255), 50) - elif ry == 1: - row_col = _alpha_blend(row_col, gfx.COLOR_RGB(200, 225, 255), 25) - if ry == th - 1: - row_col = _alpha_blend(row_col, gfx.COLOR_RGB(100, 160, 230), 40) - else: - row_col = title_col - elif ry == th and has_separator: - row_is_sep = 1 - row_col = outline_col - in_corner_zone: t.CInt = 0 - if ry < r or ry >= wh - r: - in_corner_zone = 1 - if not in_corner_zone: - left_border: t.CInt = wx - right_border: t.CInt = wx + ww - 1 - if left_border >= 0 and left_border < w: - back[py * w + left_border] = outline_col - if right_border >= 0 and right_border < w: - back[py * w + right_border] = outline_col - fill_left: t.CInt = wx + 1 - fill_right: t.CInt = wx + ww - 1 - if fill_left < 0: fill_left = 0 - if fill_right > w: fill_right = w - fill_w: t.CInt = fill_right - fill_left - if fill_w > 0: - if row_is_title and (style == STYLE_WIN7 or style == STYLE_WINXP) and title_alpha < 255: - for fx in range(fill_left, fill_right): - bg_p: t.CUInt32T = back[py * w + fx] - back[py * w + fx] = _alpha_blend(bg_p, row_col, title_alpha) - else: - _fill_rect(back, w, h, fill_left, py, fill_w, 1, row_col) - else: - for px in range(wx, wx + ww): - if px < 0 or px >= w: continue - rx: t.CInt = px - wx - in_corner: t.CInt = 1 - on_border: t.CInt = 0 - if ry < r: - if rx < r: - in_corner = _is_in_corner(rx, ry, r, r, r) - elif rx >= ww - r: - in_corner = _is_in_corner(rx, ry, ww - r - 1, r, r) - elif ry >= wh - r: - if rx < r: - in_corner = _is_in_corner(rx, ry, r, wh - r - 1, r) - elif rx >= ww - r: - in_corner = _is_in_corner(rx, ry, ww - r - 1, wh - r - 1, r) - if not in_corner: - on_border = _is_on_border(rx, ry, ww, wh, r) - if not on_border: - continue - col: t.CUInt32T = row_col - is_border_pixel: t.CInt = 0 - if on_border or _is_on_border(rx, ry, ww, wh, r): - col = outline_col - is_border_pixel = 1 - ca: t.CInt = 255 - if ry < r: - if rx < r: - ca = _corner_alpha(rx, ry, r, r, r) - elif rx >= ww - r: - ca = _corner_alpha(rx, ry, ww - r - 1, r, r) - elif ry >= wh - r: - if rx < r: - ca = _corner_alpha(rx, ry, r, wh - r - 1, r) - elif rx >= ww - r: - ca = _corner_alpha(rx, ry, ww - r - 1, wh - r - 1, r) - if is_border_pixel and ca > 0 and ca < 255: - ca = 255 - if row_is_title and (style == STYLE_WIN7 or style == STYLE_WINXP) and ry >= 1 and rx >= 1 and rx < ww - 1 and ca == 255 and not is_border_pixel: - ca = title_alpha - if ca < 255: - bg_pixel: t.CUInt32T = back[py * w + px] - col = _alpha_blend(bg_pixel, col, ca) - back[py * w + px] = col - else: - _fill_rect(back, w, h, wx, wy, ww, th, title_col) - _fill_rect(back, w, h, wx, wy + th + 1, ww, ch, content_col) - if not has_separator: - _fill_rect(back, w, h, wx, wy + th, ww, 1, content_col) - if wx >= 0 and wx < w: - for py in range(wy, wy + wh): - if py >= 0 and py < h: - back[py * w + wx] = border_col - if wx + ww - 1 >= 0 and wx + ww - 1 < w: - for py in range(wy, wy + wh): - if py >= 0 and py < h: - back[py * w + wx + ww - 1] = border_col - _fill_rect(back, w, h, wx, wy, ww, 1, border_col) - _fill_rect(back, w, h, wx, wy + wh - 1, ww, 1, border_col) - if has_separator: - _fill_rect(back, w, h, wx, wy + th, ww, 1, border_col) - - win_fb: UINT32PTR = win.fb - if win_fb: - fb_stride: t.CInt = win.fb_w - fbh: t.CInt = win.fb_h - if fb_stride <= 0 or fbh <= 0: - win_fb = t.CVoid(0, t.CPtr) - if win_fb: - draw_rows: t.CInt = ch - if draw_rows > fbh: draw_rows = fbh - if draw_rows < 0: draw_rows = 0 - content_y: t.CInt = wy + th + 1 - fb_total: t.CInt = fb_stride * fbh - for row in range(draw_rows): - dst_y: t.CInt = content_y + row - if dst_y < 0 or dst_y >= h: continue - if not _dirty_rows[dst_y]: continue - ry: t.CInt = th + 1 + row - if rounded: - if ry >= r and ry < wh - r: - src_x: t.CInt = 1 - dst_x: t.CInt = wx + 1 - if dst_x < 0: - src_x = src_x - dst_x - dst_x = 0 - end_x: t.CInt = wx + ww - 1 - if end_x > w: end_x = w - actual_w: t.CInt = end_x - dst_x - if actual_w <= 0: continue - if src_x + actual_w > fb_stride: actual_w = fb_stride - src_x - if actual_w <= 0: continue - src_off: t.CInt = row * fb_stride + src_x - if src_off + actual_w > fb_total: continue - string.memcpy(t.CVoid(t.CUInt64T(back) + (dst_y * w + dst_x) * 4, t.CPtr), t.CVoid(t.CUInt64T(win_fb) + src_off * 4, t.CPtr), actual_w * 4) - else: - copy_w: t.CInt = fb_stride - 1 - if copy_w > ww - 1: copy_w = ww - 1 - for col_px in range(1, copy_w): - if ry < r: - if col_px < r: - if not _is_in_corner(col_px, ry, r, r, r): continue - elif col_px >= ww - r: - if not _is_in_corner(col_px, ry, ww - r - 1, r, r): continue - elif ry >= wh - r: - if col_px < r: - if not _is_in_corner(col_px, ry, r, wh - r - 1, r): continue - elif col_px >= ww - r: - if not _is_in_corner(col_px, ry, ww - r - 1, wh - r - 1, r): continue - if _is_on_border(col_px, ry, ww, wh, r): continue - dst_x2: t.CInt = wx + col_px - if dst_x2 < 0 or dst_x2 >= w: continue - if col_px >= fb_stride: continue - px_off: t.CInt = row * fb_stride + col_px - if px_off < 0 or px_off >= fb_total: continue - back[dst_y * w + dst_x2] = win_fb[px_off] - else: - src_x2: t.CInt = 1 - dst_x3: t.CInt = wx + 1 - if dst_x3 < 0: - src_x2 = src_x2 - dst_x3 - dst_x3 = 0 - end_x2: t.CInt = wx + ww - 1 - if end_x2 > w: end_x2 = w - actual_w2: t.CInt = end_x2 - dst_x3 - if actual_w2 <= 0: continue - if src_x2 + actual_w2 > fb_stride: actual_w2 = fb_stride - src_x2 - if actual_w2 <= 0: continue - src_off2: t.CInt = row * fb_stride + src_x2 - if src_off2 + actual_w2 > fb_total: continue - string.memcpy(t.CVoid(t.CUInt64T(back) + (dst_y * w + dst_x3) * 4, t.CPtr), t.CVoid(t.CUInt64T(win_fb) + src_off2 * 4, t.CPtr), actual_w2 * 4) - - btn_w: t.CInt = CLOSE_BTN_SIZE - btn_h: t.CInt = CLOSE_BTN_SIZE - btn_x: t.CInt = wx + ww - btn_w - 4 - btn_y: t.CInt = wy + (th - btn_h) // 2 - clip_r: t.CInt = 0 - if style == STYLE_WIN7: - btn_w = CLOSE_BTN_W7_W - btn_h = CLOSE_BTN_W7_H - btn_x = wx + ww - btn_w - 5 - btn_y = wy + (th - btn_h) // 2 - if rounded: - clip_r = r - elif style == STYLE_WINXP: - btn_w = CLOSE_BTN_XP_SZ - btn_h = CLOSE_BTN_XP_SZ - btn_x = wx + ww - btn_w - 5 - btn_y = wy + (th - btn_h) // 2 - elif style == STYLE_WIN10 or style == STYLE_WIN11: - btn_w = CLOSE_BTN_W_WIN - btn_h = th - 2 - btn_x = wx + ww - btn_w - btn_y = wy + 1 - if rounded: - clip_r = r - _draw_close_btn(back, w, h, btn_x, btn_y, btn_w, btn_h, win.close_hover, style, wx, wy, ww, clip_r) - max_bx: t.CInt = btn_x - btn_w - if style == STYLE_WIN7 or style == STYLE_WINXP: - max_bx = btn_x - btn_w - 1 - _draw_max_btn(back, w, h, max_bx, btn_y, btn_w, btn_h, win.max_hover, style, win.is_maximized) - min_bx: t.CInt = max_bx - btn_w - if style == STYLE_WIN7 or style == STYLE_WINXP: - min_bx = max_bx - btn_w - 1 - _draw_min_btn(back, w, h, min_bx, btn_y, btn_w, btn_h, win.min_hover, style) - - text_col: t.CUInt32T = 0xFFFFFFFF - if not is_active: - text_col = gfx.COLOR_RGB(170, 170, 170) - text_y: t.CInt = wy + (th - 16) // 2 - _draw_text(back, w, h, wx + 8, text_y, c.Addr(win.title[0]), text_col) - -def create(x: t.CInt, y: t.CInt, w: t.CInt, h: t.CInt, title: t.CConst | t.CChar | t.CPtr, style: t.CInt) -> t.CInt: - global _win_count, _next_z, _focused_win - if _win_count >= MAX_APP_WINDOWS: return -1 - idx: t.CInt = _win_count - _win_count += 1 - aw: AppWindow | t.CPtr = c.Addr(_wins[idx]) - aw.active = 1 - aw.x = x - aw.y = y - aw.w = w - aw.h = h - aw.content_h = h - _get_title_height(style) - 2 - _next_z += 1 - aw.z_order = _next_z - aw.style = style - aw.close_hover = 0 - aw.min_hover = 0 - aw.max_hover = 0 - aw.is_maximized = 0 - aw.orig_x = x - aw.orig_y = y - aw.orig_w = w - aw.orig_h = h - aw.pid = _current_app_pid - aw.cursor_type = 0 - aw.app_cursor_type = 0 - aw.fb_w = 0 - aw.fb_h = 0 - aw.old_fb = t.CVoid(0, t.CPtr) - aw.ping_pending = 0 - aw.no_resp = 0 - aw.no_resp_sec = 0 - aw.minimized = 0 - aw.resizable_w = 1 - aw.resizable_h = 1 - aw.resize_w = 0 - aw.resize_h = 0 - string.memset(c.Addr(aw.title), 0, 32) - string.memset(c.Addr(aw.orig_title), 0, 32) - for i in range(31): - ch: t.CChar = title[i] - if ch == 0: break - aw.title[i] = ch - aw.orig_title[i] = ch - aw.fb = mm.malloc(w * aw.content_h * 4) - aw.fb_w = w - aw.fb_h = aw.content_h - if aw.fb: - bg_col: t.CUInt32T = gfx.COLOR_RGB(25, 25, 35) - fb_size: t.CInt = w * aw.content_h - for fi in range(fb_size): - aw.fb[fi] = bg_col - _mark_rows_dirty(y, h) - _focused_win = idx - return idx - -def draw_text(win_id: t.CInt, x: t.CInt, y: t.CInt, text: t.CConst | t.CChar | t.CPtr, color: t.CUInt32T) -> t.CInt: - if win_id < 0 or win_id >= _win_count: return -1 - aw: AppWindow | t.CPtr = c.Addr(_wins[win_id]) - if not aw.active: return -1 - win_fb: UINT32PTR = aw.fb - if not win_fb: return -1 - fbw: t.CInt = aw.fb_w - fbh: t.CInt = aw.fb_h - _draw_text(win_fb, fbw, fbh, x, y, text, color) - _mark_rows_dirty(aw.y + _get_title_height(aw.style) + 1 + y, 16) - return 0 - -def set_app_pid(pid: t.CInt): - global _current_app_pid - _current_app_pid = pid - -def is_active(win_id: t.CInt) -> t.CInt: - if win_id < 0 or win_id >= _win_count: return 0 - return _wins[win_id].active - -def get_fb(win_id: t.CInt) -> UINT32PTR: - if win_id < 0 or win_id >= _win_count: return t.CVoid(0, t.CPtr) - aw: AppWindow | t.CPtr = c.Addr(_wins[win_id]) - if not aw.active: return t.CVoid(0, t.CPtr) - if aw.old_fb: - mm.free(aw.old_fb) - aw.old_fb = t.CVoid(0, t.CPtr) - if aw.resize_w != 0 and (aw.fb_w != aw.resize_w or aw.fb_h != aw.resize_h): - target_w: t.CInt = aw.resize_w - target_h: t.CInt = aw.resize_h - if target_w <= 0 or target_h <= 0: - aw.resize_w = 0 - aw.resize_h = 0 - return aw.fb - new_fb_sz_gf: t.CInt = target_w * target_h - new_fb_gf: UINT32PTR = mm.malloc(new_fb_sz_gf * 4) - if not new_fb_gf: - aw.resize_w = 0 - aw.resize_h = 0 - return aw.fb - old_fb_gf: UINT32PTR = aw.fb - old_fbw_gf: t.CInt = aw.fb_w - old_fbh_gf: t.CInt = aw.fb_h - aw.fb = new_fb_gf - aw.fb_w = target_w - aw.fb_h = target_h - aw.w = target_w - aw.content_h = target_h - aw.resize_w = 0 - aw.resize_h = 0 - bg_gf: t.CUInt32T = gfx.COLOR_RGB(30, 30, 50) - for fi_gf in range(new_fb_sz_gf): - aw.fb[fi_gf] = bg_gf - if old_fb_gf: - cph_gf: t.CInt = old_fbh_gf - if cph_gf > target_h: cph_gf = target_h - for ri_gf in range(cph_gf): - rb_gf: t.CInt = old_fbw_gf - if rb_gf > target_w: rb_gf = target_w - string.memcpy(t.CVoid(t.CUInt64T(aw.fb) + ri_gf * target_w * 4, t.CPtr), t.CVoid(t.CUInt64T(old_fb_gf) + ri_gf * old_fbw_gf * 4, t.CPtr), rb_gf * 4) - if aw.old_fb: - mm.free(aw.old_fb) - aw.old_fb = old_fb_gf - return aw.fb - -def get_size(win_id: t.CInt) -> t.CInt: - if win_id < 0 or win_id >= _win_count: return 0 - aw: AppWindow | t.CPtr = c.Addr(_wins[win_id]) - if not aw.active: return 0 - return (aw.fb_w << 16) | (aw.fb_h & 0xFFFF) - -_NO_RESP_SUFFIX: t.CArray[t.CChar, 14] = " - (No Resp)" - -def _update_no_resp_title(win_id: t.CInt, mark: t.CInt): - if win_id < 0 or win_id >= _win_count: return - aw: AppWindow | t.CPtr = c.Addr(_wins[win_id]) - if not aw.active: return - string.memset(c.Addr(aw.title), 0, 32) - if mark: - j: t.CInt = 0 - for ch in aw.orig_title: - if j >= 31: break - if ch == 0: break - aw.title[j] = ch - j += 1 - for sc in _NO_RESP_SUFFIX: - if j >= 13: break - if sc == 0: break - if j < 31: - aw.title[j] = sc - j += 1 - else: - j2: t.CInt = 0 - for ch2 in aw.orig_title: - if j2 >= 31: break - if ch2 == 0: break - aw.title[j2] = ch2 - j2 += 1 - _mark_rows_dirty(aw.y, _get_title_height(aw.style) + 2) - -def _heartbeat_check(): - global _hb_last_sec - cur_sec: t.CUInt32T = timer.timer_get_seconds() - if cur_sec - _hb_last_sec < HB_INTERVAL_SEC: return - _hb_last_sec = cur_sec - for i in range(_win_count): - aw: AppWindow | t.CPtr = c.Addr(_wins[i]) - if not aw.active: - continue - if aw.pid == 0: - continue - if aw.ping_pending: - if not aw.no_resp: - aw.no_resp = 1 - aw.no_resp_sec = cur_sec - _update_no_resp_title(i, 1) - else: - elapsed: t.CUInt32T = cur_sec - aw.no_resp_sec - if elapsed >= HB_NO_RESP_SEC: - aw.active = 0 - _mark_rows_dirty(aw.y, aw.h) - p_ref: process.Process | t.CPtr = process.ProcessManager.get_process(aw.pid) - if p_ref is not None: - p_ref.exit() - else: - aw.ping_pending = 1 - evt: InputEvent - string.memset(c.Addr(evt), 0, INPUT_EVENT_SIZE) - evt.type = EVENT_TYPE_PING - evt.win_id = i - _push_event(evt) - -def flush(win_id: t.CInt): - if win_id < 0 or win_id >= _win_count: return - aw: AppWindow | t.CPtr = c.Addr(_wins[win_id]) - if not aw.active: return - if aw.old_fb: - mm.free(aw.old_fb) - aw.old_fb = t.CVoid(0, t.CPtr) - if aw.ping_pending: - aw.ping_pending = 0 - if aw.no_resp: - aw.no_resp = 0 - aw.no_resp_sec = 0 - _update_no_resp_title(win_id, 0) - _mark_rows_dirty(aw.y + _get_title_height(aw.style) + 1, _eff_h(aw)) - -def set_title(win_id: t.CInt, title: t.CConst | t.CChar | t.CPtr) -> t.CInt: - if win_id < 0 or win_id >= _win_count: return -1 - aw: AppWindow | t.CPtr = c.Addr(_wins[win_id]) - if not aw.active: return -1 - string.memset(c.Addr(aw.title), 0, 32) - string.memset(c.Addr(aw.orig_title), 0, 32) - for i in range(31): - ch: t.CChar = title[i] - if ch == 0: break - aw.title[i] = ch - aw.orig_title[i] = ch - _mark_rows_dirty(aw.y, _get_title_height(aw.style) + 2) - return 0 - -def set_geometry(win_id: t.CInt, x: t.CInt, y: t.CInt, w: t.CInt, h: t.CInt) -> t.CInt: - if win_id < 0 or win_id >= _win_count: return -1 - aw: AppWindow | t.CPtr = c.Addr(_wins[win_id]) - if not aw.active: return -1 - old_y: t.CInt = aw.y - old_h: t.CInt = aw.h - aw.x = x - aw.y = y - aw.resize_w = w - aw.resize_h = h - _get_title_height(aw.style) - 2 - aw.h = h - _mark_rows_dirty(old_y, old_h) - _mark_rows_dirty(y, h) - return 0 - -def set_resizable(win_id: t.CInt, rw: t.CInt, rh: t.CInt) -> t.CInt: - if win_id < 0 or win_id >= _win_count: return -1 - aw: AppWindow | t.CPtr = c.Addr(_wins[win_id]) - if not aw.active: return -1 - aw.resizable_w = rw - aw.resizable_h = rh - return 0 - -def destroy_by_pid(pid: t.CInt): - global _focused_win, _last_hover_win - for i in range(_win_count): - if _wins[i].pid == pid and _wins[i].active: - _wins[i].active = 0 - _mark_rows_dirty(_wins[i].y, _wins[i].h) - if _focused_win == i: - _focused_win = -1 - if _last_hover_win == i: - _last_hover_win = -1 - if _focused_win < 0: - for j in range(_win_count - 1, -1, -1): - if _wins[j].active and not _wins[j].minimized: - _focused_win = j - break diff --git a/Test/Kernel/services/keyboard.vp b/Test/Kernel/services/keyboard.vp deleted file mode 100644 index e7aae90b..00000000 --- a/Test/Kernel/services/keyboard.vp +++ /dev/null @@ -1,50 +0,0 @@ -import t, c -import drivers.input.keyboard.keyboard as keyboard -import drivers.usb.hid.usb_kbd as usb_kbd -import drivers.serial.uart.serial as serial -import sched.sched as sched -import viperlib - -SERVICE_KEYBOARD: t.CDefine = 1 - -@t.Object -class KeyboardService: - th: sched.Thread | t.CPtr - running: t.CInt - usb_kbd_th: sched.Thread | t.CPtr - - def __init__(self): - self.th = None - self.running = 0 - self.usb_kbd_th = None - -kbd_svc: KeyboardService - - -def kbd_thread(arg: t.CVoid | t.CPtr) -> t.CInt: - serial.puts("[kbd_svc] started\n") - while True: - if keyboard.has_data(): - sc: t.CUInt8T = keyboard.read_scancode() - else: - sched.Scheduler._yield() - return 0 - -def usb_kbd_thread(arg: t.CVoid | t.CPtr) -> t.CInt: - serial.puts("[usb_kbd_svc] started\n") - evt: usb_kbd.usb_kbd_event - while True: - if usb_kbd.has_data(): - usb_kbd.read_event(c.Addr(evt)) - else: - sched.Scheduler._yield() - return 0 - -def start() -> t.CInt: - global kbd_svc - kbd_svc = KeyboardService() - keyboard.init() - serial.puts("[kbd_svc] PS/2 keyboard initialized, IRQ1 installed\n") - usb_kbd.init() - kbd_svc.running = 1 - return 0 diff --git a/Test/Kernel/services/mouse.vp b/Test/Kernel/services/mouse.vp deleted file mode 100644 index 53e07f81..00000000 --- a/Test/Kernel/services/mouse.vp +++ /dev/null @@ -1,13 +0,0 @@ -import t, c -import drivers.input.mouse.mouse as mouse -import drivers.usb.hid.usb_mouse as usb_mouse -import drivers.serial.uart.serial as serial -import sched.sched as sched - -SERVICE_MOUSE: t.CDefine = 2 - -def start() -> t.CInt: - serial.puts("[mse_svc] mouse initialized\n") - if usb_mouse.init() == 0: - serial.puts("[mse_svc] usb mouse initialized\n") - return 0 diff --git a/packages/Viper.png b/packages/Viper.png new file mode 100644 index 00000000..48ada2b2 Binary files /dev/null and b/packages/Viper.png differ diff --git a/packages/Viper.svg b/packages/Viper.svg new file mode 100644 index 00000000..6040b770 --- /dev/null +++ b/packages/Viper.svg @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/viper/images/viper-icon.svg b/packages/viper/images/viper-icon.svg index ebb40f2f..6040b770 100644 --- a/packages/viper/images/viper-icon.svg +++ b/packages/viper/images/viper-icon.svg @@ -1,4 +1,57 @@ - - - V + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/viper/images/vpj-icon.svg b/packages/viper/images/vpj-icon.svg index 65531648..6040b770 100644 --- a/packages/viper/images/vpj-icon.svg +++ b/packages/viper/images/vpj-icon.svg @@ -1,4 +1,57 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/viper/package.json b/packages/viper/package.json index f42b77b6..9d6dffdb 100644 --- a/packages/viper/package.json +++ b/packages/viper/package.json @@ -20,7 +20,7 @@ "workspaceContains:**/*.vpj", "workspaceContains:**/*.vp" ], - "icon": "images/viper-icon.svg", + "icon": "images/viper-icon.png", "main": "./dist/extension.js", "contributes": { "languages": [ @@ -100,33 +100,33 @@ "commands": [ { "command": "viper.createProject", - "title": "Viper: Create Project", + "title": "Create Project", "category": "Viper" }, { "command": "viper.selectToolchain", - "title": "Viper: Select Toolchain", + "title": "Select Toolchain", "category": "Viper" }, { "command": "viper.showProjectInfo", - "title": "Viper: Show Project Info", + "title": "Show Project Info", "category": "Viper" }, { "command": "viper.openSettings", - "title": "Viper: Open Settings", + "title": "Open Settings", "category": "Viper" }, { "command": "viper.refreshView", - "title": "Viper: Refresh", + "title": "Refresh", "category": "Viper", "icon": "$(refresh)" }, { "command": "viper.openVpjAsJson", - "title": "Viper: Open .vpj as JSON", + "title": "Open .vpj as JSON", "category": "Viper" } ], diff --git a/packages/vipeye-internal/debug.js b/packages/vipeye-internal/debug.js index 85777cdf..58bd595f 100644 --- a/packages/vipeye-internal/debug.js +++ b/packages/vipeye-internal/debug.js @@ -1,2 +1,2 @@ // This is an entry-point for debugging the vipeye CLI -require('./out/packages/vipeye-internal/src/pyright').main(); +require('./out/packages/vipeye-internal/src/viper').main(); diff --git a/packages/vipeye-internal/package-lock.json b/packages/vipeye-internal/package-lock.json index ecbc1efd..3e4f1697 100644 --- a/packages/vipeye-internal/package-lock.json +++ b/packages/vipeye-internal/package-lock.json @@ -1,11 +1,11 @@ { - "name": "pyright-internal", + "name": "vipeye-internal", "version": "1.1.411", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "pyright-internal", + "name": "vipeye-internal", "version": "1.1.411", "license": "MIT", "dependencies": { diff --git a/packages/vipeye-internal/package.json b/packages/vipeye-internal/package.json index db897754..e3ecc30a 100644 --- a/packages/vipeye-internal/package.json +++ b/packages/vipeye-internal/package.json @@ -15,7 +15,7 @@ "webpack:testserver:watch": "npm run clean && rspack build --config ./src/tests/lsp/rspack.testserver.config.js --mode development --watch", "test": "npm run webpack:testserver && node --max-old-space-size=8192 --expose-gc ./node_modules/jest/bin/jest --forceExit --testPathIgnorePatterns src/tests/benchmarks", "test:norebuild": "node --max-old-space-size=8192 --expose-gc ./node_modules/jest/bin/jest --forceExit --testPathIgnorePatterns src/tests/benchmarks", - "test:benchmark": "cross-env PYRIGHT_RUN_BENCHMARKS=1 node --max-old-space-size=8192 --expose-gc ./node_modules/jest/bin/jest --forceExit --testTimeout=300000 --runInBand --detectOpenHandles src/tests/benchmarks", + "test:benchmark": "cross-env VIPER_RUN_BENCHMARKS=1 node --max-old-space-size=8192 --expose-gc ./node_modules/jest/bin/jest --forceExit --testTimeout=300000 --runInBand --detectOpenHandles src/tests/benchmarks", "test:coverage": "node --max-old-space-size=8192 --expose-gc ./node_modules/jest/bin/jest --forceExit --testPathIgnorePatterns src/tests/benchmarks --reporters=jest-junit --reporters=default --coverage --coverageReporters=cobertura --coverageReporters=html --coverageReporters=json", "test:imports": "node --max-old-space-size=8192 --expose-gc ./node_modules/jest/bin/jest importResolver.test --forceExit --runInBand" }, diff --git a/packages/vipeye-internal/src/analyzer/binder.ts b/packages/vipeye-internal/src/analyzer/binder.ts index 4fc901c1..c596c983 100644 --- a/packages/vipeye-internal/src/analyzer/binder.ts +++ b/packages/vipeye-internal/src/analyzer/binder.ts @@ -368,7 +368,7 @@ export class Binder extends ParseTreeWalker { // Single-underscore module-level names remain private even when __all__ uses an // unsupported/computed form. Since every entry in _potentialPrivateSymbols already // has an underscore prefix, shouldProcess always returns true here, preserving - // the behavior of upstream pyright test `Private3`. + // the behavior of upstream vipeye test `Private3`. this._potentialPrivateSymbols.forEach((symbol, name) => { if (shouldProcess(name) && !this._dunderAllNames?.some((sym) => sym === name)) { symbol.setIsPrivateMember(); diff --git a/packages/vipeye-internal/src/analyzer/commentUtils.ts b/packages/vipeye-internal/src/analyzer/commentUtils.ts index d85e07ee..da793a7c 100644 --- a/packages/vipeye-internal/src/analyzer/commentUtils.ts +++ b/packages/vipeye-internal/src/analyzer/commentUtils.ts @@ -66,7 +66,7 @@ export function getFileLevelDirectives( return curTokenLineOffset <= 1; }; - ruleSet = _parsePyrightComment(value, textRange, isCommentOnOwnLine, ruleSet, diagnostics); + ruleSet = _parseViperComment(value, textRange, isCommentOnOwnLine, ruleSet, diagnostics); isModified = true; } } @@ -139,16 +139,16 @@ function _overwriteRules(ruleSet: DiagnosticRuleSet, overrideRuleSet: Diagnostic } } -function _parsePyrightComment( +function _parseViperComment( commentValue: string, commentRange: TextRange, isCommentOnOwnLine: () => boolean, ruleSet: DiagnosticRuleSet, diagnostics: CommentDiagnostic[] ) { - // 支持 "pyright:" 和 "viper:" 两种注释指令前缀。 - // "viper:" 是 Viper 语言的官方指令,"pyright:" 保留向后兼容。 - const commentPrefix = 'pyright:'; + // 主要支持 "viper:" 注释指令前缀,"pyright:" 保留作为兼容别名。 + // "viper:" 是 Viper 语言的官方指令。 + const commentPrefix = 'viper:'; const viperCommentPrefix = 'viper:'; let operands: string; let prefixLength: number; @@ -170,9 +170,9 @@ function _parsePyrightComment( if (!isCommentOnOwnLine()) { const diagAddendum = new DiagnosticAddendum(); - diagAddendum.addMessage(LocAddendum.pyrightCommentIgnoreTip()); + diagAddendum.addMessage(LocAddendum.viperCommentIgnoreTip()); const diag: CommentDiagnostic = { - message: LocMessage.pyrightCommentNotOnOwnLine() + diagAddendum.getString(), + message: LocMessage.viperCommentNotOnOwnLine() + diagAddendum.getString(), range: commentRange, }; @@ -198,7 +198,7 @@ function _parsePyrightComment( length: operand.length, }); - ruleSet = _parsePyrightOperand(trimmedOperand, operandRange, ruleSet, diagnostics); + ruleSet = _parseViperOperand(trimmedOperand, operandRange, ruleSet, diagnostics); rangeOffset += operand.length + 1; } } @@ -206,7 +206,7 @@ function _parsePyrightComment( return ruleSet; } -function _parsePyrightOperand( +function _parseViperOperand( operand: string, operandRange: TextRange, ruleSet: DiagnosticRuleSet, @@ -240,7 +240,7 @@ function _parsePyrightOperand( (ruleSet as any)[trimmedRule] = diagLevelValue; } else { const diag: CommentDiagnostic = { - message: LocMessage.pyrightCommentInvalidDiagnosticSeverityValue(), + message: LocMessage.viperCommentInvalidDiagnosticSeverityValue(), range: trimmedRuleValue ? ruleValueRange : ruleRange, }; diagnostics.push(diag); @@ -251,7 +251,7 @@ function _parsePyrightOperand( (ruleSet as any)[trimmedRule] = boolValue; } else { const diag: CommentDiagnostic = { - message: LocMessage.pyrightCommentInvalidDiagnosticBoolValue(), + message: LocMessage.viperCommentInvalidDiagnosticBoolValue(), range: trimmedRuleValue ? ruleValueRange : ruleRange, }; diagnostics.push(diag); @@ -259,14 +259,14 @@ function _parsePyrightOperand( } else if (trimmedRule) { const diag: CommentDiagnostic = { message: trimmedRuleValue - ? LocMessage.pyrightCommentUnknownDiagnosticRule().format({ rule: trimmedRule }) - : LocMessage.pyrightCommentUnknownDirective().format({ directive: trimmedRule }), + ? LocMessage.viperCommentUnknownDiagnosticRule().format({ rule: trimmedRule }) + : LocMessage.viperCommentUnknownDirective().format({ directive: trimmedRule }), range: ruleRange, }; diagnostics.push(diag); } else { const diag: CommentDiagnostic = { - message: LocMessage.pyrightCommentMissingDirective(), + message: LocMessage.viperCommentMissingDirective(), range: ruleRange, }; diagnostics.push(diag); diff --git a/packages/vipeye-internal/src/analyzer/constraintSolver.ts b/packages/vipeye-internal/src/analyzer/constraintSolver.ts index 113593c8..7079b6fb 100644 --- a/packages/vipeye-internal/src/analyzer/constraintSolver.ts +++ b/packages/vipeye-internal/src/analyzer/constraintSolver.ts @@ -1316,7 +1316,7 @@ function assignParamSpec( // only a strictly nested reference (`T := F[T]`) has no finite solution. function typeVarOccursIn(typeVar: TypeVarType, type: Type): boolean { // A bare top-level TypeVar reference is not a cycle. Compare by name + - // scope id rather than identity since pyright sometimes clones TypeVars. + // scope id rather than identity since vipeye sometimes clones TypeVars. if (isTypeVar(type) && type.shared.name === typeVar.shared.name && type.priv.scopeId === typeVar.priv.scopeId) { return false; } diff --git a/packages/vipeye-internal/src/analyzer/operations.ts b/packages/vipeye-internal/src/analyzer/operations.ts index f36aeb95..12f9b57a 100644 --- a/packages/vipeye-internal/src/analyzer/operations.ts +++ b/packages/vipeye-internal/src/analyzer/operations.ts @@ -58,7 +58,9 @@ import { isAnyOrUnknown, isClass, isClassInstance, + isCConstType, isCPtrType, + isCStaticType, isCVoidType, isFunctionOrOverloaded, isInstantiableClass, @@ -1311,6 +1313,18 @@ function validateArithmeticOperation( return preserveUnknown(leftSubtypeUnexpanded, rightSubtypeUnexpanded); } + // Viper 扩展:跳过 Viper 修饰类型(CStatic, CConst 等类型修饰符)。 + // 这些修饰类型只是类型修饰符(如 static, const),不参与运算。 + // 运算时只处理基础类型(如 CInt, str 等)。 + if (isViperDialect) { + if ( + isCStaticType(leftSubtypeUnexpanded) || isCStaticType(rightSubtypeUnexpanded) || + isCConstType(leftSubtypeUnexpanded) || isCConstType(rightSubtypeUnexpanded) + ) { + return UnknownType.create(isIncomplete); + } + } + const tupleClassType = evaluator.getTupleClassType(); // Special-case __add__ for tuples when the types for both tuples are known. diff --git a/packages/vipeye-internal/src/analyzer/pythonPathUtils.ts b/packages/vipeye-internal/src/analyzer/pythonPathUtils.ts index 673b3cf2..ec4fd226 100644 --- a/packages/vipeye-internal/src/analyzer/pythonPathUtils.ts +++ b/packages/vipeye-internal/src/analyzer/pythonPathUtils.ts @@ -37,7 +37,7 @@ export function getTypeShedFallbackPath(fs: Pick 0) { - // With a pyrightconfig.json set, we want the typeCheckingMode to always be standard - // as that's what the Pyright CLI will expect. Command line options (if not a language server) and + // With a viperconfig.json set, we want the typeCheckingMode to always be standard + // as that's what the Viper CLI will expect. Command line options (if not a language server) and // the config file can override this. configOptions.initializeTypeCheckingMode('standard'); @@ -913,7 +912,7 @@ export class AnalyzerService { // - *.vpj(Viper Project)命中 → 同样强制 'viper' // - pyproject.toml 含 [tool.viper] → 同样强制 'viper' // 后两类信号已由 _getExtendedConfigurations / _parsePyprojectTomlFile 写入 _pyprojectDialect。 - if (primaryConfigFileName === viperConfigFileName) { + if (primaryConfigFileName === configFileName) { configOptions.dialect = 'viper'; } else if (primaryConfigFileName === viperProjectFileName) { configOptions.dialect = 'viper'; @@ -1287,7 +1286,7 @@ export class AnalyzerService { // Loads the config JSON object from the specified config file along with any // chained config files specified in the "extends" property (recursively). // If pyprojectSearchDir is provided and the primary file is a pyproject.toml with no - // [tool.pyright] section, falls back to searching ancestor dirs from pyprojectSearchDir. + // [tool.viper] section, falls back to searching ancestor dirs from pyprojectSearchDir. private _getExtendedConfigurations( primaryConfigFileUri: Uri | undefined, pyprojectSearchDir?: Uri @@ -1344,7 +1343,7 @@ export class AnalyzerService { curConfigFileUri = baseConfigUri; } - // If a pyproject.toml was found but had no [tool.pyright] section, fall back to + // If a pyproject.toml was found but had no [tool.viper] section, fall back to // searching ancestor directories as if that pyproject.toml didn't exist. if (configJsonObjs.length === 0 && pyprojectSearchDir) { const parentDir = pyprojectSearchDir.getDirectory(); @@ -1366,7 +1365,7 @@ export class AnalyzerService { } // 解析 TransPyC project.json(Viper 项目配置)。 - // project.json 的 schema 与 viperconfig.json/pyrightconfig.json 不同: + // project.json 的 schema 与 viperconfig.json 不同: // - source_dir:Viper 源码目录(main.py 所在),作为 import 搜索根 // - includes: 额外的 Viper 模块搜索路径(可相对,如 ../../includes) // compiler / linker / target / options 等编译器配置 LSP 不需要,忽略。 @@ -1453,16 +1452,12 @@ export class AnalyzerService { const configObj = parse(fileContents); if (configObj && 'tool' in configObj) { const toolSection = configObj.tool as Record; - // Viper 优先:[tool.viper] 命中时强制 dialect = 'viper'。 - // 否则回退到 [tool.pyright],保持原有 Python 行为(dialect = 'python' 默认)。 + // 只支持 [tool.viper]:命中时强制 dialect = 'viper'。 + // 完全切换后不再回退 [tool.pyright]。 if (toolSection.viper !== undefined) { this._pyprojectDialect = 'viper'; return toolSection.viper as object; } - if (toolSection.pyright !== undefined) { - this._pyprojectDialect = 'python'; - return toolSection.pyright as object; - } } } catch (e: any) { this._console.error(`Pyproject file parse attempt ${attemptCount} error: ${JSON.stringify(e)}`); @@ -1470,7 +1465,7 @@ export class AnalyzerService { } this._console.info( - `Pyproject file "${pyprojectPath.toUserVisibleString()}" has no "[tool.pyright]" or "[tool.viper]" section.` + `Pyproject file "${pyprojectPath.toUserVisibleString()}" has no "[tool.viper]" section.` ); return undefined; }); @@ -2029,11 +2024,10 @@ export class AnalyzerService { if (event === 'add' || event === 'change') { const fileName = getFileName(path); - // L10: 同时监听 viperconfig.json / project.json / *.vpj / pyrightconfig.json, + // L10: 同时监听 viperconfig.json / project.json / *.vpj / pyproject.toml, // 任一文件新增/变更都触发配置重载,从而在用户切换配置文件后自动应用对应 dialect。 if ( fileName === configFileName || - fileName === viperConfigFileName || fileName === viperProjectFileName || fileName === pyprojectTomlName || fileName.endsWith(viperProjectFileExt) diff --git a/packages/vipeye-internal/src/analyzer/serviceUtils.ts b/packages/vipeye-internal/src/analyzer/serviceUtils.ts index 806c2c33..47b94dcf 100644 --- a/packages/vipeye-internal/src/analyzer/serviceUtils.ts +++ b/packages/vipeye-internal/src/analyzer/serviceUtils.ts @@ -1,5 +1,5 @@ import { ReadOnlyFileSystem } from '../common/fileSystem'; -import { configFileName, pyprojectTomlName, viperConfigFileName, viperProjectFileExt, viperProjectFileName } from '../common/pathConsts'; +import { configFileName, pyprojectTomlName, viperProjectFileExt, viperProjectFileName } from '../common/pathConsts'; import { Uri } from '../common/uri/uri'; import { forEachAncestorDirectory } from '../common/uri/uriUtils'; @@ -20,9 +20,9 @@ export function findConfigFileHereOrUp(fs: ReadOnlyFileSystem, searchPath: Uri): } export function findConfigFile(fs: ReadOnlyFileSystem, searchPath: Uri): Uri | undefined { - // Viper 模式优先:先查找 viperconfig.json,未找到时回退到 pyrightconfig.json。 + // 只查找 viperconfig.json(完全切换后不再回退 pyrightconfig.json)。 // 调用方(service.ts)依据返回文件名决定是否将 dialect 设为 'viper'。 - const viperFileName = searchPath.resolvePaths(viperConfigFileName); + const viperFileName = searchPath.resolvePaths(configFileName); if (fs.existsSync(viperFileName)) { return fs.realCasePath(viperFileName); } @@ -36,17 +36,12 @@ export function findConfigFile(fs: ReadOnlyFileSystem, searchPath: Uri): Uri | u } // TransPyC project.json:仅当 schema 匹配(含 source_dir / compiler / linker 之一)时才返回, - // 否则跳过到 pyrightconfig.json,避免误判其他工具的 project.json。 + // 避免误判其他工具的 project.json。 const projectFileName = searchPath.resolvePaths(viperProjectFileName); if (fs.existsSync(projectFileName) && isViperProjectConfig(fs, projectFileName)) { return fs.realCasePath(projectFileName); } - const pyrightFileName = searchPath.resolvePaths(configFileName); - if (fs.existsSync(pyrightFileName)) { - return fs.realCasePath(pyrightFileName); - } - return undefined; } diff --git a/packages/vipeye-internal/src/analyzer/sourceEnumerator.ts b/packages/vipeye-internal/src/analyzer/sourceEnumerator.ts index 5c76a6c9..c7b92231 100644 --- a/packages/vipeye-internal/src/analyzer/sourceEnumerator.ts +++ b/packages/vipeye-internal/src/analyzer/sourceEnumerator.ts @@ -94,9 +94,9 @@ export class SourceEnumerator { '* Your workspace contains a symlink to a directory with many files\n' + '* Your workspace is remote, and file enumeration is slow\n' + 'To reduce this time, open a workspace directory with fewer files ' + - 'or add a pyrightconfig.json configuration file with an "exclude" section to exclude ' + + 'or add a viperconfig.json configuration file with an "exclude" section to exclude ' + 'subdirectories from your workspace. For more details, refer to ' + - 'https://github.com/microsoft/pyright/blob/main/docs/configuration.md.' + 'https://github.com/TermiNexus/TransPyC/wiki/viper-configuration.' ); this._loggedLongOperationError = true; diff --git a/packages/vipeye-internal/src/analyzer/sourceFile.ts b/packages/vipeye-internal/src/analyzer/sourceFile.ts index 1743560a..c1e4601c 100644 --- a/packages/vipeye-internal/src/analyzer/sourceFile.ts +++ b/packages/vipeye-internal/src/analyzer/sourceFile.ts @@ -127,7 +127,7 @@ class WriteableData { taskListDiagnostics: Diagnostic[] = []; typeIgnoreLines = new Map(); typeIgnoreAll: IgnoreComment | undefined; - pyrightIgnoreLines = new Map(); + viperIgnoreLines = new Map(); // Accumulated and filtered diagnostics that combines all of the // above information. This needs to be recomputed any time the @@ -190,7 +190,7 @@ class WriteableData { taskListDiagnostics=${this.taskListDiagnostics?.length}, accumulatedDiagnostics=${this.accumulatedDiagnostics?.length}, typeIgnoreLines=${this.typeIgnoreLines?.size}, - pyrightIgnoreLines=${this.pyrightIgnoreLines?.size}, + viperIgnoreLines=${this.viperIgnoreLines?.size}, checkTime=${this.checkTime}, clientDocumentContents=${this.clientDocumentContents?.length}, parseResults=${this.parserOutput?.parseTree.length}, @@ -755,7 +755,7 @@ export class SourceFile { this._writableData.parsedFileContents = fileContents; this._writableData.typeIgnoreLines = parseFileResults.tokenizerOutput.typeIgnoreLines; this._writableData.typeIgnoreAll = parseFileResults.tokenizerOutput.typeIgnoreAll; - this._writableData.pyrightIgnoreLines = parseFileResults.tokenizerOutput.pyrightIgnoreLines; + this._writableData.viperIgnoreLines = parseFileResults.tokenizerOutput.viperIgnoreLines; this._writableData.lineCount = parseFileResults.tokenizerOutput.lines.length; // Cache the tokenizer output only if this file is open. @@ -841,7 +841,7 @@ export class SourceFile { lines: this._writableData.tokenizerLines, typeIgnoreAll: undefined, typeIgnoreLines: new Map(), - pyrightIgnoreLines: new Map(), + viperIgnoreLines: new Map(), predominantEndOfLineSequence: '\n', hasPredominantTabSequence: false, predominantTabSequence: ' ', @@ -1080,7 +1080,7 @@ export class SourceFile { const prefilteredDiagList = diagList; const typeIgnoreLinesClone = new Map(this._writableData.typeIgnoreLines); - const pyrightIgnoreLinesClone = new Map(this._writableData.pyrightIgnoreLines); + const viperIgnoreLinesClone = new Map(this._writableData.viperIgnoreLines); // Filter the diagnostics based on "type: ignore" lines. if (this._diagnosticRuleSet.enableTypeIgnoreComments) { @@ -1104,8 +1104,8 @@ export class SourceFile { } } - // Filter the diagnostics based on "pyright: ignore" lines. - if (this._writableData.pyrightIgnoreLines.size > 0) { + // Filter the diagnostics based on "viper: ignore" lines. + if (this._writableData.viperIgnoreLines.size > 0) { diagList = diagList.filter((d) => { if ( d.category !== DiagnosticCategory.UnusedCode && @@ -1113,10 +1113,10 @@ export class SourceFile { d.category !== DiagnosticCategory.Deprecated ) { for (let line = d.range.start.line; line <= d.range.end.line; line++) { - const pyrightIgnoreComment = this._writableData.pyrightIgnoreLines.get(line); - if (pyrightIgnoreComment) { - if (!pyrightIgnoreComment.rulesList) { - pyrightIgnoreLinesClone.delete(line); + const viperIgnoreComment = this._writableData.viperIgnoreLines.get(line); + if (viperIgnoreComment) { + if (!viperIgnoreComment.rulesList) { + viperIgnoreLinesClone.delete(line); return false; } @@ -1128,17 +1128,17 @@ export class SourceFile { } // Did we find this rule in the list? - if (pyrightIgnoreComment.rulesList.find((rule) => rule.text === diagRule)) { - // Update the pyrightIgnoreLinesClone to remove this rule. - const oldClone = pyrightIgnoreLinesClone.get(line); + if (viperIgnoreComment.rulesList.find((rule) => rule.text === diagRule)) { + // Update the viperIgnoreLinesClone to remove this rule. + const oldClone = viperIgnoreLinesClone.get(line); if (oldClone?.rulesList) { const filteredRulesList = oldClone.rulesList.filter( (rule) => rule.text !== diagRule ); if (filteredRulesList.length === 0) { - pyrightIgnoreLinesClone.delete(line); + viperIgnoreLinesClone.delete(line); } else { - pyrightIgnoreLinesClone.set(line, { + viperIgnoreLinesClone.set(line, { range: oldClone.range, rulesList: filteredRulesList, }); @@ -1210,7 +1210,7 @@ export class SourceFile { } }); - pyrightIgnoreLinesClone.forEach((ignoreComment) => { + viperIgnoreLinesClone.forEach((ignoreComment) => { if (this._writableData.tokenizerLines!) { if (!ignoreComment.rulesList) { const rangeStart = ignoreComment.range.start; @@ -1235,7 +1235,7 @@ export class SourceFile { if (!isUnreachableCodeRange(range)) { const diag = new Diagnostic( diagCategory, - LocMessage.unnecessaryPyrightIgnoreRule().format({ + LocMessage.unnecessaryViperIgnoreRule().format({ name: unusedRule.text, }), range diff --git a/packages/vipeye-internal/src/analyzer/typeEvaluator.ts b/packages/vipeye-internal/src/analyzer/typeEvaluator.ts index 566a6392..1aed66ca 100644 --- a/packages/vipeye-internal/src/analyzer/typeEvaluator.ts +++ b/packages/vipeye-internal/src/analyzer/typeEvaluator.ts @@ -43,6 +43,7 @@ import { AssignmentNode, AugmentedAssignmentNode, AwaitNode, + BinaryOperationNode, CallNode, CaseNode, ClassNode, @@ -257,6 +258,7 @@ import { isCConstType, isCStaticType, isViperIntegerType, + isViperCIntegerTypeName, isOverloaded, isParamSpec, isPositionOnlySeparator, @@ -1088,7 +1090,7 @@ export function createTypeEvaluator( prefetched.awaitableClass = getTypingType(node, 'Awaitable'); prefetched.mappingClass = getTypingType(node, 'Mapping'); - // Don't attempt to resolve the string.templatelib if pyright is configured for + // Don't attempt to resolve the string.templatelib if viper is configured for // Python 3.13 or older. Doing so will either fail to resolve (if running on Python 3.13 // or older) or resolve to the templatelib.py source file (if running on Python 3.14). if (PythonVersion.isGreaterOrEqualTo(fileInfo.executionEnvironment.pythonVersion, pythonVersion3_14)) { @@ -4955,11 +4957,28 @@ export function createTypeEvaluator( } if (effectiveTypeInfo.isRecursiveDefinition && isNodeReachable(node)) { - addDiagnostic( - DiagnosticRule.reportGeneralTypeIssues, - LocMessage.recursiveDefinition().format({ name }), - node - ); + // Viper 扩展:循环引用包含 CPtr 时不报错。 + // C 语义中,struct 含指向自身的指针是合法的(如链表节点): + // struct Node { struct Node* next; } + // 对应 Viper: next: 'Node' | t.CPtr + // 指针大小固定,不需要知道结构体的完整定义,打破了无限递归。 + // 但无 CPtr 的循环引用(如 next: 'Node')是真正的无限递归,应报错。 + const isViperPtrCycle = + IsViperDialect(fileInfo.executionEnvironment.dialect) && + symbol.getTypedDeclarations().some((decl) => { + if (decl.type !== DeclarationType.Variable || !decl.typeAnnotationNode) { + return false; + } + return typeAnnotationContainsCPtr(decl.typeAnnotationNode); + }); + + if (!isViperPtrCycle) { + addDiagnostic( + DiagnosticRule.reportGeneralTypeIssues, + LocMessage.recursiveDefinition().format({ name }), + node + ); + } } const isSpecialBuiltIn = @@ -8914,6 +8933,172 @@ export function createTypeEvaluator( return entryTypes; } + // Viper 扩展:判断调用节点是否为 Viper C 整数类型的构造调用。 + // 支持两种形式: + // 1. 直接名称调用:CUInt32T(addr, t.CPtr) + // 2. 成员访问调用:t.CUInt32T(addr, t.CPtr) + // 通过提取调用表达式左侧的名称(CUInt32T),查询 _viperCIntegerTypeNames 白名单判断。 + function isViperCIntegerCall(node: CallNode): boolean { + const leftExpr = node.d.leftExpr; + let name: string | undefined; + + if (leftExpr.nodeType === ParseNodeType.Name) { + // 形式 1:直接名称调用 + name = leftExpr.d.value; + } else if (leftExpr.nodeType === ParseNodeType.MemberAccess) { + // 形式 2:成员访问调用(如 t.CUInt32T) + name = leftExpr.d.member.d.value; + } + + return name !== undefined && isViperCIntegerTypeName(name); + } + + // Viper 扩展:判断调用节点是否为 __sizeof__ 方法调用。 + // 支持两种形式: + // 1. 类调用:Type.__sizeof__() + // 2. 实例调用:instance.__sizeof__() + // Viper 中 __sizeof__ 是类方法(sizeof(Type) -> int),不需要 self 参数。 + function isViperSizeOfCall(node: CallNode): boolean { + const leftExpr = node.d.leftExpr; + if (leftExpr.nodeType === ParseNodeType.MemberAccess) { + return leftExpr.d.member.d.value === '__sizeof__'; + } + return false; + } + + // Viper 扩展:检查类型注解 AST 节点是否包含 CPtr 引用。 + // 用于判断循环引用是否被指针打破(如 next: 'Node' | t.CPtr)。 + // 递归遍历类型注解表达式,查找名称为 CPtr/CNeedPtr/CAutoPtr/CArrayPtr 的标识符。 + function typeAnnotationContainsCPtr(node: ExpressionNode): boolean { + return checkCPtrRecursively(node); + } + + function checkCPtrRecursively(node: ParseNode): boolean { + if (!node) { + return false; + } + + // 检查名称节点是否为 CPtr 系列 + if (node.nodeType === ParseNodeType.Name) { + const name = (node as NameNode).d.value; + return name === 'CPtr' || name === 'CNeedPtr' || name === 'CAutoPtr' || name === 'CArrayPtr'; + } + + // 检查成员访问节点(如 t.CPtr),检查成员名 + if (node.nodeType === ParseNodeType.MemberAccess) { + const memberAccess = node as MemberAccessNode; + const memberName = memberAccess.d.member.d.value; + if ( + memberName === 'CPtr' || memberName === 'CNeedPtr' || + memberName === 'CAutoPtr' || memberName === 'CArrayPtr' + ) { + return true; + } + // 继续检查左侧表达式 + return checkCPtrRecursively(memberAccess.d.leftExpr); + } + + // 检查二进制操作节点(如 'Node' | t.CPtr),递归检查两侧 + if (node.nodeType === ParseNodeType.BinaryOperation) { + const binaryOp = node as BinaryOperationNode; + return checkCPtrRecursively(binaryOp.d.leftExpr) || checkCPtrRecursively(binaryOp.d.rightExpr); + } + + // 检查索引节点(如 CPtr[Node]),递归检查左侧和索引项 + if (node.nodeType === ParseNodeType.Index) { + const indexNode = node as IndexNode; + if (checkCPtrRecursively(indexNode.d.leftExpr)) { + return true; + } + for (const item of indexNode.d.items) { + if (checkCPtrRecursively(item.d.valueExpr)) { + return true; + } + } + return false; + } + + // 检查字符串列表节点(字符串注解如 'Node'),检查字符串内容 + if (node.nodeType === ParseNodeType.StringList) { + const stringList = node as StringListNode; + for (const stringNode of stringList.d.strings) { + if (stringNode.nodeType === ParseNodeType.String) { + const strValue = (stringNode as any).d?.value ?? ''; + // 检查字符串注解中是否包含 CPtr 引用 + if (/\b(CPtr|CNeedPtr|CAutoPtr|CArrayPtr)\b/.test(strValue)) { + return true; + } + } + } + return false; + } + + // 检查类型注解节点(如 x: Type),递归检查类型表达式 + if (node.nodeType === ParseNodeType.TypeAnnotation) { + const typeAnnot = node as TypeAnnotationNode; + return checkCPtrRecursively(typeAnnot.d.typeAnnotation); + } + + // 对于其他节点类型,尝试遍历子节点 + const d = (node as any).d; + if (d && typeof d === 'object') { + for (const key of Object.keys(d)) { + const value = d[key]; + if (value && typeof value === 'object' && value.nodeType !== undefined) { + if (checkCPtrRecursively(value)) { + return true; + } + } else if (Array.isArray(value)) { + for (const item of value) { + if (item && typeof item === 'object' && item.nodeType !== undefined) { + if (checkCPtrRecursively(item)) { + return true; + } + } + } + } + } + } + + return false; + } + + // Viper 扩展:检测 C 整数类型构造调用的第二参数是否为 t.CPtr。 + // 若是,则返回 CPtr 类的 instantiable 形式,用于构造 CPtr[T] 指针类型; + // 否则返回 undefined。 + // 示例:t.CUInt32T(addr, t.CPtr) → 返回 CPtr 类,外层构造 CPtr[CUInt32T]。 + // + // 判断方式:评估第二参数表达式的类型,若为 instantiable CPtr 类则匹配。 + // 这样可以正确处理 t.CPtr、CPtr(直接引用)以及别名导入等各种形式。 + function tryGetCPtrTypeFromSecondArg( + node: CallNode + ): ClassType | undefined { + if (node.d.args.length < 2) { + return undefined; + } + + const secondArgExpr = node.d.args[1].d.valueExpr; + // 若是关键字参数且名字不是 base,则跳过(仅识别位置参数或 base=... 形式) + const argName = node.d.args[1].d.name; + if (argName && argName.d.value !== 'base') { + return undefined; + } + + // 评估第二参数表达式的类型 + const secondArgTypeResult = getTypeOfExpression( + secondArgExpr, + EvalFlags.CallBaseDefaults + ); + const secondArgType = secondArgTypeResult.type; + + // 期望第二参数为 CPtr 类的 instantiable 形式(type[CPtr]) + if (isInstantiableClass(secondArgType) && isCPtrType(secondArgType)) { + return secondArgType; + } + + return undefined; + } + function getTypeOfCall( node: CallNode, flags: EvalFlags, @@ -8993,6 +9178,45 @@ export function createTypeEvaluator( } else { addDiagnostic(DiagnosticRule.reportCallIssue, LocMessage.revealLocalsArgs(), node); } + } else if ( + // Viper 扩展:拦截 C 整数类型的构造调用(如 t.CUInt32T(addr, t.CPtr))。 + // 这些类型在 vipershed-fallback/stdlib/t.vpi 中定义为 TypeAlias = int, + // 但在 Viper 语义中它们是独立的 C 整数类型,构造调用应支持指针强转语义, + // 而不是走 int.__new__ 的参数类型检查(int.__new__ 期望 str|bytes|bytearray, + // 而 Viper 强转常用指针地址作为参数)。 + IsViperDialect(AnalyzerNodeInfo.getFileInfo(node).executionEnvironment.dialect) && + isInstantiableClass(baseTypeResult.type) && + ClassType.isBuiltIn(baseTypeResult.type, 'int') && + isViperCIntegerCall(node) + ) { + // 跳过 int.__new__ 的参数类型检查,直接返回该整数类型的实例。 + // Viper 的 C 整数类型构造调用本质是 C 语言的强转 (uint32_t)addr, + // 参数类型检查由 Viper 编译器在语义分析阶段处理,LSP 不需要重复检查。 + // + // 特殊形式:当第二参数为 t.CPtr 时(如 t.CUInt32T(addr, t.CPtr)), + // 语义是强转为"指向该整数类型的指针"(即 (uint32_t*)addr), + // 此时返回 CPtr[T] 实例类型,以支持指针下标赋值 ptr[i] = value。 + const integerInstanceType = ClassType.cloneAsInstance(baseTypeResult.type); + const cptrPointerType = tryGetCPtrTypeFromSecondArg(node); + if (cptrPointerType) { + // 构造 CPtr[IntegerT] 实例类型 + const cptrInstance = ClassType.cloneAsInstance(cptrPointerType); + typeResult.type = ClassType.specialize(cptrInstance, [integerInstanceType]); + } else { + typeResult.type = integerInstanceType; + } + } else if ( + // Viper 扩展:拦截 __sizeof__ 调用。 + // Viper 中 __sizeof__ 语义是 C 语言的 sizeof(Type) -> int, + // 是类方法/静态方法,不需要 self 参数。但 object.__sizeof__ 是实例方法, + // 当通过类调用 Type.__sizeof__() 时会报 "Argument missing for parameter self"。 + // 此处跳过参数检查,直接返回 int 类型。 + IsViperDialect(AnalyzerNodeInfo.getFileInfo(node).executionEnvironment.dialect) && + isViperSizeOfCall(node) + ) { + // Viper 的 __sizeof__ 是类方法(sizeof(Type)),返回类型大小(字节数)。 + // 跳过 object.__sizeof__ 的实例方法参数检查,直接返回 int。 + typeResult.type = getBuiltInObject(node, 'int'); } else { const callResult = validateCallArgs( node, @@ -10308,7 +10532,7 @@ export function createTypeEvaluator( recursionCount++; // Viper 方言允许联合类型强转,例如 `(memory_block | t.CPtr)(addr)` - // 或 `(t.CInt | t.CPtr)(x)`。Pyright 会把联合类型标记为 specialForm + // 或 `(t.CInt | t.CPtr)(x)`。Vipeye 会把联合类型标记为 specialForm // 并在上方报 objectNotCallable;Viper 是 AOT 静态语言,这类联合强转是 // 合法语义(C 风格类型转换),因此在 Viper 模式下直接放行并返回 Unknown, // 避免对联合类型逐子类型校验时产生的误报。 @@ -10613,7 +10837,7 @@ export function createTypeEvaluator( } // Ignore instance variables. Also, ignore named tuple members, which are - // modeled in pyright as instance variables, but their runtime implementation + // modeled in vipeye as instance variables, but their runtime implementation // uses a descriptor object. if (!symbol.isClassMember() && !symbol.isNamedTupleMemberMember()) { return undefined; @@ -27912,7 +28136,7 @@ export function createTypeEvaluator( // we may be able to narrow the type based on the assignment. function narrowTypeBasedOnAssignment(declaredType: Type, assignedTypeResult: TypeResult): TypeResult { // TODO: The rules for narrowing types on assignment are not defined in - // the typing spec. Pyright's current logic is currently not even internally + // the typing spec. Vipeye's current logic is currently not even internally // consistent and probably not sound from a type theory perspective. It // should be completely reworked once there has been a public discussion // about the correct behavior. diff --git a/packages/vipeye-internal/src/analyzer/typeStubWriter.ts b/packages/vipeye-internal/src/analyzer/typeStubWriter.ts index fb43652b..e40d5929 100644 --- a/packages/vipeye-internal/src/analyzer/typeStubWriter.ts +++ b/packages/vipeye-internal/src/analyzer/typeStubWriter.ts @@ -740,7 +740,7 @@ class TypeStubTreeWalker extends ParseTreeWalker { return ( '"""' + this._lineEnd + - 'This type stub file was generated by pyright.' + + 'This type stub file was generated by viper.' + this._lineEnd + '"""' + this._lineEnd + diff --git a/packages/vipeye-internal/src/analyzer/types.ts b/packages/vipeye-internal/src/analyzer/types.ts index ec332d26..78e0ee6d 100644 --- a/packages/vipeye-internal/src/analyzer/types.ts +++ b/packages/vipeye-internal/src/analyzer/types.ts @@ -3246,6 +3246,43 @@ export function isViperIntegerType(type: Type): boolean { return ClassType.isBuiltIn(type, 'int'); } +// Viper 扩展:Viper C 整数类型名称白名单。 +// 这些类型在 vipershed-fallback/stdlib/t.vpi 中定义为 TypeAlias = int, +// 但在 Viper 语义中它们是独立的 C 整数类型,构造调用应支持指针强转语义, +// 而不是走 int.__new__ 的参数类型检查。 +const _viperCIntegerTypeNames = new Set([ + // 基本整数类型 + 'CChar', 'CShort', 'CInt', 'CLong', 'CLongLong', + 'CSignedChar', 'CUnsignedChar', 'CUnsignedShort', + 'CUnsignedInt', 'CUnsignedLong', 'CUnsignedLongLong', + // 固定宽度整数 + 'CInt8T', 'CInt16T', 'CInt32T', 'CInt64T', + 'CUInt8T', 'CUInt16T', 'CUInt32T', 'CUInt64T', + // 最小/最快宽度整数 + 'CIntLeast8T', 'CIntLeast16T', 'CIntLeast32T', 'CIntLeast64T', + 'CUIntLeast8T', 'CUIntLeast16T', 'CUIntLeast32T', 'CUIntLeast64T', + 'CIntFast8T', 'CIntFast16T', 'CIntFast32T', 'CIntFast64T', + 'CUIntFast8T', 'CUIntFast16T', 'CUIntFast32T', 'CUIntFast64T', + // 最大宽度整数 + 'CIntMaxT', 'CUIntMaxT', + // 平台相关整数 + 'CSizeT', 'CIntPtrT', 'CUIntPtrT', 'CPtrDiffT', + // 布尔 + 'CBool', + // 宽字符 + 'CWCharT', 'CChar8T', 'CChar16T', 'CChar32T', + // LLVM 简写 + 'i1', 'i8', 'i16', 'i32', 'i64', + 'u1', 'u8', 'u16', 'u32', 'u64', +]); + +// Viper 扩展:检测名称是否为 Viper C 整数类型名。 +// 用于在 getTypeOfCall 中识别 C 整数类型的构造调用(如 t.CUInt32T(addr, t.CPtr)), +// 并跳过 int.__new__ 的参数类型检查,实现 Viper 的指针强转语义。 +export function isViperCIntegerTypeName(name: string): boolean { + return _viperCIntegerTypeNames.has(name); +} + export function isAny(type: Type): type is AnyType { return type.category === TypeCategory.Any; } diff --git a/packages/vipeye-internal/src/analyzer/typeshedInfoProvider.ts b/packages/vipeye-internal/src/analyzer/typeshedInfoProvider.ts index b028b492..e6ad813e 100644 --- a/packages/vipeye-internal/src/analyzer/typeshedInfoProvider.ts +++ b/packages/vipeye-internal/src/analyzer/typeshedInfoProvider.ts @@ -274,7 +274,7 @@ class DefaultTypeshedInfoProvider implements TypeshedInfoProvider { } // Viper 模式仍使用 typeshed-fallback 作为 typeshed root, - // 确保 builtins/typing 等基础模块可被 Pyright 隐式加载。 + // 确保 builtins/typing 等基础模块可被 Vipeye 隐式加载。 // Viper 特有模块(t/c/stdio 等)通过 importResolver.getImportRoots() // 额外添加 vipershed-fallback/stdlib 作为优先搜索路径。 const fallback = PythonPathUtils.getTypeShedFallbackPath(this._fileSystem) ?? Uri.empty(); diff --git a/packages/vipeye-internal/src/common/asyncInitialization.ts b/packages/vipeye-internal/src/common/asyncInitialization.ts index bf4c6932..c93380f1 100644 --- a/packages/vipeye-internal/src/common/asyncInitialization.ts +++ b/packages/vipeye-internal/src/common/asyncInitialization.ts @@ -3,7 +3,7 @@ * Copyright (c) Microsoft Corporation. * Licensed under the MIT license. * - * helpers shared between multiple packages such as vipeye-internal and pyright + * helpers shared between multiple packages such as vipeye-internal and vipeye */ import { ensureTomlModuleLoaded } from './tomlUtils'; diff --git a/packages/vipeye-internal/src/common/commandLineOptions.ts b/packages/vipeye-internal/src/common/commandLineOptions.ts index 9652974b..f7bb2b4d 100644 --- a/packages/vipeye-internal/src/common/commandLineOptions.ts +++ b/packages/vipeye-internal/src/common/commandLineOptions.ts @@ -34,7 +34,7 @@ export type DiagnosticSeverityOverridesMap = { [ruleName: string]: DiagnosticSev export type DiagnosticBooleanOverridesMap = { [ruleName: string]: boolean }; // Options that can be specified in a JSON config file. This list should match what is -// defined in the pyrightconfig.schema.json file. +// defined in the vipeyeconfig.schema.json file. export class CommandLineConfigOptions { // A list of file specs to include in the analysis. Can contain // directories, in which case all "*.py" files within those directories @@ -156,7 +156,7 @@ export class CommandLineLanguageServerOptions { venvPath?: string | undefined; } -// Some options can be specified from a source other than the pyright config file. +// Some options can be specified from a source other than the viper config file. // This can be from command-line parameters or some other settings mechanism, like // that provided through a language client like the VS Code editor. These options // are later combined with those from the config file to produce the final configuration. diff --git a/packages/vipeye-internal/src/common/configOptions.ts b/packages/vipeye-internal/src/common/configOptions.ts index 14be891d..0f742dd2 100644 --- a/packages/vipeye-internal/src/common/configOptions.ts +++ b/packages/vipeye-internal/src/common/configOptions.ts @@ -392,7 +392,7 @@ export interface DiagnosticRuleSet { // Report cases where a simple expression result is not used in any way. reportUnusedExpression: DiagnosticLevel; - // Report cases where the removal of a "# type: ignore" or "# pyright: ignore" + // Report cases where the removal of a "# type: ignore" or "# viper: ignore" // comment would have no effect. reportUnnecessaryTypeIgnoreComment: DiagnosticLevel; @@ -429,7 +429,7 @@ export function getBooleanDiagnosticRules(includeNonOverridable = false) { if (includeNonOverridable) { // Do not include these because we don't // want to override it in strict mode or support - // it within pyright comments. + // it within viper comments. boolRules.push(DiagnosticRule.enableTypeIgnoreComments); boolRules.push(DiagnosticRule.enableReachabilityAnalysis); } @@ -1095,7 +1095,7 @@ export class ConfigOptions { // Minimum threshold for type eval logging typeEvaluationTimeThreshold = 50; - // Was this config initialized from JSON (pyrightconfig/pyproject)? + // Was this config initialized from JSON (viperconfig/pyproject)? initializedFromJson = false; // Filter out any hint diagnostics with tags? @@ -1155,7 +1155,7 @@ export class ConfigOptions { // Controls how hover and completion function signatures are displayed. functionSignatureDisplay: SignatureDisplayType; - // Determines if has a config file (pyrightconfig.json or pyproject.toml) or not. + // Determines if has a config file (viperconfig.json or pyproject.toml) or not. configFileSource?: Uri | undefined; // Determines the effective default type checking mode. diff --git a/packages/vipeye-internal/src/common/dialect.ts b/packages/vipeye-internal/src/common/dialect.ts index f149a410..073b9af3 100644 --- a/packages/vipeye-internal/src/common/dialect.ts +++ b/packages/vipeye-internal/src/common/dialect.ts @@ -3,7 +3,7 @@ * 语言方言开关:区分 Python 与 Viper 语义。 * * Viper 是基于 CPython 语法但语义不同的 AOT 编译型语言。 - * 在 TPV --lsp 实现前,Pyright(Vipeye)作为姑息 LSP 充当分析器。 + * 在 TPV --lsp 实现前,Vipeye 作为姑息 LSP 充当分析器。 * 通过 dialect 字段在 Python 语义与 Viper 语义之间切换。 */ diff --git a/packages/vipeye-internal/src/common/docStringService.ts b/packages/vipeye-internal/src/common/docStringService.ts index b850265b..722895fb 100644 --- a/packages/vipeye-internal/src/common/docStringService.ts +++ b/packages/vipeye-internal/src/common/docStringService.ts @@ -50,7 +50,7 @@ export namespace DocStringService { } } -export class PyrightDocStringService implements DocStringService { +export class ViperDocStringService implements DocStringService { convertDocStringToPlainText(docString: string): string { return convertDocStringToPlainText(docString); } diff --git a/packages/vipeye-internal/src/common/pathConsts.ts b/packages/vipeye-internal/src/common/pathConsts.ts index b68a6a90..8494d691 100644 --- a/packages/vipeye-internal/src/common/pathConsts.ts +++ b/packages/vipeye-internal/src/common/pathConsts.ts @@ -23,10 +23,9 @@ export const defaultStubsDirectory = 'typings'; export const requirementsFileName = 'requirements.txt'; export const pyprojectTomlName = 'pyproject.toml'; export const dotPythonVersionName = '.python-version'; -export const configFileName = 'pyrightconfig.json'; - -// Viper 模式下的配置文件名(替代 pyrightconfig.json)。 -export const viperConfigFileName = 'viperconfig.json'; +// 配置文件名。完全切换后只认 viperconfig.json(原 pyrightconfig.json 已废弃)。 +// viperConfigFileName 已合并到 configFileName,外部引用请统一使用 configFileName。 +export const configFileName = 'viperconfig.json'; // Viper 项目配置文件名(TransPyC 编译器使用)。 // schema 与 viperconfig.json 不同:含 source_dir / includes / compiler / linker 等字段。 diff --git a/packages/vipeye-internal/src/common/realFileSystem.ts b/packages/vipeye-internal/src/common/realFileSystem.ts index de30f54d..9bed400e 100644 --- a/packages/vipeye-internal/src/common/realFileSystem.ts +++ b/packages/vipeye-internal/src/common/realFileSystem.ts @@ -564,7 +564,7 @@ export class RealTempFile implements TempFile, CaseSensitivityDetector { } const osTempRoot = os.tmpdir(); - const configuredTmpRoot = process.env.PYRIGHT_TMPDIR?.trim(); + const configuredTmpRoot = process.env.VIPER_TMPDIR?.trim(); type TmpDirOutcome = { tmpdir?: tmp.DirResult; @@ -586,7 +586,7 @@ export class RealTempFile implements TempFile, CaseSensitivityDetector { return { error: e }; } - return createTmpDir({ prefix: 'pyright', tmpdir: root }); + return createTmpDir({ prefix: 'viper', tmpdir: root }); }; // Highest priority: explicit override. @@ -599,7 +599,7 @@ export class RealTempFile implements TempFile, CaseSensitivityDetector { } // Default behavior: let tmp/os decide. - const defaultOutcome = createTmpDir({ prefix: 'pyright' }); + const defaultOutcome = createTmpDir({ prefix: 'viper' }); if (defaultOutcome.tmpdir) { this._tmpdir = defaultOutcome.tmpdir; return this._tmpdir; @@ -610,8 +610,8 @@ export class RealTempFile implements TempFile, CaseSensitivityDetector { const details = defaultError?.message ?? String(defaultOutcome.error); throw new Error( - `Failed to create a temporary directory for Pyright. The OS temp directory root is "${osTempRoot}". ` + - `If that path doesn't exist or isn't writable, set PYRIGHT_TMPDIR or TMPDIR/TMP/TEMP for the VS Code server/extension host process ` + + `Failed to create a temporary directory for Viper. The OS temp directory root is "${osTempRoot}". ` + + `If that path doesn't exist or isn't writable, set VIPER_TMPDIR or TMPDIR/TMP/TEMP for the VS Code server/extension host process ` + `or ensure the env vars are inherited by the remote/server process. ` + `Original error: ${details}` ); diff --git a/packages/vipeye-internal/src/common/serviceProviderExtensions.ts b/packages/vipeye-internal/src/common/serviceProviderExtensions.ts index c4af76ac..658592a7 100644 --- a/packages/vipeye-internal/src/common/serviceProviderExtensions.ts +++ b/packages/vipeye-internal/src/common/serviceProviderExtensions.ts @@ -12,7 +12,7 @@ import { PartialStubService, SupportPartialStubs } from '../partialStubService'; import { CancellationProvider, DefaultCancellationProvider } from './cancellationUtils'; import { CaseSensitivityDetector } from './caseSensitivityDetector'; import { ConsoleInterface, NullConsole } from './console'; -import { DocStringService, PyrightDocStringService } from './docStringService'; +import { DocStringService, ViperDocStringService } from './docStringService'; import { FileSystem, TempFile } from './fileSystem'; import { CommandService, WindowService } from './languageServerInterface'; import { LogTracker } from './logTracker'; @@ -110,7 +110,7 @@ ServiceProvider.prototype.sourceFileFactory = function () { ServiceProvider.prototype.docStringService = function () { const result = this.tryGet(ServiceKeys.docStringService); - return result || new PyrightDocStringService(); + return result || new ViperDocStringService(); }; ServiceProvider.prototype.cacheManager = function () { diff --git a/packages/vipeye-internal/src/common/workspaceEditUtils.ts b/packages/vipeye-internal/src/common/workspaceEditUtils.ts index 142d25ae..51a3a208 100644 --- a/packages/vipeye-internal/src/common/workspaceEditUtils.ts +++ b/packages/vipeye-internal/src/common/workspaceEditUtils.ts @@ -3,7 +3,7 @@ * Copyright (c) Microsoft Corporation. * Licensed under the MIT license. * - * Convert pyright's FileEditActions to LanguageServer's WorkspaceEdits. + * Convert vipeye's FileEditActions to LanguageServer's WorkspaceEdits. */ import { diff --git a/packages/vipeye-internal/src/languageServerBase.ts b/packages/vipeye-internal/src/languageServerBase.ts index 0d71e3d6..be564ca3 100644 --- a/packages/vipeye-internal/src/languageServerBase.ts +++ b/packages/vipeye-internal/src/languageServerBase.ts @@ -407,7 +407,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface, Dis this.workspaceFactory.items().forEach((workspace) => { // Updating settings can change workspace's file ownership. Make workspace uninitialized so that // features can wait until workspace gets new settings. - // the file's ownership can also changed by `pyrightconfig.json` changes, but those are synchronous + // the file's ownership can also changed by `viperconfig.json` changes, but those are synchronous // operation, so it won't affect this. workspace.isInitialized = workspace.isInitialized.reset(); tasks.push(this.updateSettingsForWorkspace(workspace, workspace.isInitialized)); @@ -1578,7 +1578,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface, Dis const rule = diag.getRule(); if (rule) { // Configuration.md is configured to have a link for every rule name. - return `https://github.com/microsoft/pyright/blob/main/docs/configuration.md#${rule}`; + return `https://github.com/TermiNexus/TransPyC/wiki/viper-configuration#${rule}`; } return undefined; } diff --git a/packages/vipeye-internal/src/languageService/analyzerServiceExecutor.ts b/packages/vipeye-internal/src/languageService/analyzerServiceExecutor.ts index cae66a9b..b4edbae0 100644 --- a/packages/vipeye-internal/src/languageService/analyzerServiceExecutor.ts +++ b/packages/vipeye-internal/src/languageService/analyzerServiceExecutor.ts @@ -132,7 +132,7 @@ export function getEffectiveCommandLineOptions( } if (serverSettings.typeshedPath) { - // Pyright supports only one typeshed path currently, whereas the + // Vipeye supports only one typeshed path currently, whereas the // official VS Code Python extension supports multiple typeshed paths. // We'll use the first one specified and ignore the rest. commandLineOptions.configSettings.typeshedPath = serverSettings.typeshedPath.getFilePath(); diff --git a/packages/vipeye-internal/src/languageService/pullDiagnosticsDynamicFeature.ts b/packages/vipeye-internal/src/languageService/pullDiagnosticsDynamicFeature.ts index 78c9d2d9..170ce1db 100644 --- a/packages/vipeye-internal/src/languageService/pullDiagnosticsDynamicFeature.ts +++ b/packages/vipeye-internal/src/languageService/pullDiagnosticsDynamicFeature.ts @@ -17,7 +17,7 @@ export class PullDiagnosticsDynamicFeature extends DynamicFeature { private _workspaceSupport = false; private _registered = false; - constructor(private readonly _connection: Connection, private readonly _id: string = 'pyright') { + constructor(private readonly _connection: Connection, private readonly _id: string = 'viper') { super('pull diagnostics'); } diff --git a/packages/vipeye-internal/src/languageService/semanticTokenProvider.ts b/packages/vipeye-internal/src/languageService/semanticTokenProvider.ts index d6e0352f..da5e445f 100644 --- a/packages/vipeye-internal/src/languageService/semanticTokenProvider.ts +++ b/packages/vipeye-internal/src/languageService/semanticTokenProvider.ts @@ -16,6 +16,7 @@ import { Declaration, DeclarationType, VariableDeclaration } from '../analyzer/declaration'; import { ParseTreeWalker } from '../analyzer/parseTreeWalker'; +import { isWithinTypeAnnotation } from '../analyzer/parseTreeUtils'; import { TypeCategory } from '../analyzer/types'; import { TypeEvaluator } from '../analyzer/typeEvaluatorTypes'; import { LogTracker } from '../common/logTracker'; @@ -436,8 +437,13 @@ class SemanticTokenWalker extends ParseTreeWalker { return false; } - /** 访问 StringNode:字符串字面量 → string */ + /** 访问 StringNode:字符串字面量 → string。 + * Viper 扩展:在类型注解上下文中的字符串(前向引用)不生成 string token, + * 让 TextMate 语法规则处理高亮(显示为类型颜色而非字符串颜色)。 */ override visitString(node: StringNode): boolean { + if (isWithinTypeAnnotation(node, /* requireQuotedAnnotation */ false)) { + return true; + } this._pushLiteralToken(node.start, node.length, SemanticTokenTypes.string); return true; } diff --git a/packages/vipeye-internal/src/localization/localize.ts b/packages/vipeye-internal/src/localization/localize.ts index 34fb7fb1..a648953a 100644 --- a/packages/vipeye-internal/src/localization/localize.ts +++ b/packages/vipeye-internal/src/localization/localize.ts @@ -867,16 +867,16 @@ export namespace Localizer { new ParameterizedString<{ variable: string; class: string }>( getRawString('Diagnostic.protocolVarianceInvariant') ); - export const pyrightCommentInvalidDiagnosticBoolValue = () => - getRawString('Diagnostic.pyrightCommentInvalidDiagnosticBoolValue'); - export const pyrightCommentInvalidDiagnosticSeverityValue = () => - getRawString('Diagnostic.pyrightCommentInvalidDiagnosticSeverityValue'); - export const pyrightCommentMissingDirective = () => getRawString('Diagnostic.pyrightCommentMissingDirective'); - export const pyrightCommentNotOnOwnLine = () => getRawString('Diagnostic.pyrightCommentNotOnOwnLine'); - export const pyrightCommentUnknownDirective = () => - new ParameterizedString<{ directive: string }>(getRawString('Diagnostic.pyrightCommentUnknownDirective')); - export const pyrightCommentUnknownDiagnosticRule = () => - new ParameterizedString<{ rule: string }>(getRawString('Diagnostic.pyrightCommentUnknownDiagnosticRule')); + export const viperCommentInvalidDiagnosticBoolValue = () => + getRawString('Diagnostic.viperCommentInvalidDiagnosticBoolValue'); + export const viperCommentInvalidDiagnosticSeverityValue = () => + getRawString('Diagnostic.viperCommentInvalidDiagnosticSeverityValue'); + export const viperCommentMissingDirective = () => getRawString('Diagnostic.viperCommentMissingDirective'); + export const viperCommentNotOnOwnLine = () => getRawString('Diagnostic.viperCommentNotOnOwnLine'); + export const viperCommentUnknownDirective = () => + new ParameterizedString<{ directive: string }>(getRawString('Diagnostic.viperCommentUnknownDirective')); + export const viperCommentUnknownDiagnosticRule = () => + new ParameterizedString<{ rule: string }>(getRawString('Diagnostic.viperCommentUnknownDiagnosticRule')); export const readOnlyArgCount = () => getRawString('Diagnostic.readOnlyArgCount'); export const readOnlyNotInTypedDict = () => getRawString('Diagnostic.readOnlyNotInTypedDict'); export const recursiveDefinition = () => @@ -1190,9 +1190,9 @@ export namespace Localizer { new ParameterizedString<{ testType: string; classType: string }>( getRawString('Diagnostic.unnecessaryIsSubclassNever') ); - export const unnecessaryPyrightIgnore = () => getRawString('Diagnostic.unnecessaryPyrightIgnore'); - export const unnecessaryPyrightIgnoreRule = () => - new ParameterizedString<{ name: string }>(getRawString('Diagnostic.unnecessaryPyrightIgnoreRule')); + export const unnecessaryViperIgnore = () => getRawString('Diagnostic.unnecessaryViperIgnore'); + export const unnecessaryViperIgnoreRule = () => + new ParameterizedString<{ name: string }>(getRawString('Diagnostic.unnecessaryViperIgnoreRule')); export const unnecessaryTypeIgnore = () => getRawString('Diagnostic.unnecessaryTypeIgnore'); export const unpackArgCount = () => getRawString('Diagnostic.unpackArgCount'); export const unpackedArgInTypeArgument = () => getRawString('Diagnostic.unpackedArgInTypeArgument'); @@ -1503,7 +1503,7 @@ export namespace Localizer { ); export const protocolUnsafeOverlap = () => new ParameterizedString<{ name: string }>(getRawString('DiagnosticAddendum.protocolUnsafeOverlap')); - export const pyrightCommentIgnoreTip = () => getRawString('DiagnosticAddendum.pyrightCommentIgnoreTip'); + export const viperCommentIgnoreTip = () => getRawString('DiagnosticAddendum.viperCommentIgnoreTip'); export const readOnlyAttribute = () => new ParameterizedString<{ name: string }>(getRawString('DiagnosticAddendum.readOnlyAttribute')); export const seeDeclaration = () => getRawString('DiagnosticAddendum.seeDeclaration'); diff --git a/packages/vipeye-internal/src/localization/package.nls.cs.json b/packages/vipeye-internal/src/localization/package.nls.cs.json index 230553aa..d2546ba0 100644 --- a/packages/vipeye-internal/src/localization/package.nls.cs.json +++ b/packages/vipeye-internal/src/localization/package.nls.cs.json @@ -429,13 +429,13 @@ "protocolVarianceContravariant": "Proměnná typu {variable} použitá v obecné třídě Protocol {class} by měla být kontravariantní.", "protocolVarianceCovariant": "Proměnná typu {variable} použitá v obecné třídě Protocol {class} by měla být kovariantní.", "protocolVarianceInvariant": "Proměnná typu {variable} použitá v obecné třídě Protocol {class} by měla být invariantní.", - "pyrightCommentInvalidDiagnosticBoolValue": "Za direktivou komentářů Pyright musí následovat znak =a hodnota true nebo false", - "pyrightCommentInvalidDiagnosticSeverityValue": "Za direktivou komentářů Pyright musí následovat = a hodnota true, false, error, warning, information nebo none", - "pyrightCommentMissingDirective": "Za komentářem Pyright musí následovat direktiva (basic nebo strict) nebo diagnostické pravidlo.", - "pyrightCommentNotOnOwnLine": "Komentáře Pyright používané k řízení nastavení na úrovni souborů se musí zobrazovat na vlastním řádku", - "pyrightCommentUnknownDiagnosticRule": "{rule} je neznámé diagnostické pravidlo pro komentář pyright", - "pyrightCommentUnknownDiagnosticSeverityValue": "{value} je neplatná hodnota pro komentář pyright; očekávalo se true, false, error, warning, information nebo none", - "pyrightCommentUnknownDirective": "Direktiva {directive} je neznámá direktiva pro komentář pyright; očekávalo se strict, standard nebo basic", + "viperCommentInvalidDiagnosticBoolValue": "Za direktivou komentářů Viper musí následovat znak =a hodnota true nebo false", + "viperCommentInvalidDiagnosticSeverityValue": "Za direktivou komentářů Viper musí následovat = a hodnota true, false, error, warning, information nebo none", + "viperCommentMissingDirective": "Za komentářem Viper musí následovat direktiva (basic nebo strict) nebo diagnostické pravidlo.", + "viperCommentNotOnOwnLine": "Komentáře Viper používané k řízení nastavení na úrovni souborů se musí zobrazovat na vlastním řádku", + "viperCommentUnknownDiagnosticRule": "{rule} je neznámé diagnostické pravidlo pro komentář viper", + "viperCommentUnknownDiagnosticSeverityValue": "{value} je neplatná hodnota pro komentář viper; očekávalo se true, false, error, warning, information nebo none", + "viperCommentUnknownDirective": "Direktiva {directive} je neznámá direktiva pro komentář viper; očekávalo se strict, standard nebo basic", "readOnlyArgCount": "Za „ReadOnly“ se očekával jeden argument typu", "readOnlyNotInTypedDict": "ReadOnly není v tomto kontextu povolené", "recursiveDefinition": "Typ „{name}“ nelze určit, protože odkazuje sám na sebe", @@ -625,8 +625,8 @@ "unnecessaryIsInstanceNever": "Zbytečné volání isinstance; {testType} není nikdy instancí třídy {classType}", "unnecessaryIsSubclassAlways": "Nepotřebné volání issubclass; „{testType}“ je vždy podtřídou třídy „{classType}“", "unnecessaryIsSubclassNever": "Zbytečné volání issubclass; {testType} není nikdy podtřídou třídy {classType}", - "unnecessaryPyrightIgnore": "Nepotřebný komentář „# pyright: ignore“", - "unnecessaryPyrightIgnoreRule": "Nepotřebné pravidlo # pyright: ignore: {name}", + "unnecessaryViperIgnore": "Nepotřebný komentář „# viper: ignore“", + "unnecessaryViperIgnoreRule": "Nepotřebné pravidlo # viper: ignore: {name}", "unnecessaryTypeIgnore": "Nepotřebný komentář „# type: ignore“", "unpackArgCount": "Po rozbalení „Unpack“ se očekával jeden argument typu", "unpackExpectedTypeVarTuple": "Jako argument typu pro Unpack byl očekáván typ TypeVarTuple nebo tuple.", @@ -786,7 +786,7 @@ "protocolRequiresRuntimeCheckable": "Třída Protocol musí být @runtime_checkable, aby se použila při kontrolách instancí a tříd.", "protocolSourceIsNotConcrete": "„{sourceType}“ není konkrétní typ třídy a nedá se přiřadit k typu „{destType}“", "protocolUnsafeOverlap": "Atributy „{name}“ mají stejné názvy jako protokol.", - "pyrightCommentIgnoreTip": "Pokud chcete potlačit diagnostiku pro jeden řádek, použijte # pyright: ignore[]", + "viperCommentIgnoreTip": "Pokud chcete potlačit diagnostiku pro jeden řádek, použijte # viper: ignore[]", "readOnlyAttribute": "Atribut {name} je jen pro čtení", "seeClassDeclaration": "Viz deklarace třídy", "seeDeclaration": "Viz deklarace", diff --git a/packages/vipeye-internal/src/localization/package.nls.de.json b/packages/vipeye-internal/src/localization/package.nls.de.json index b8bed3ed..1d7bbc0c 100644 --- a/packages/vipeye-internal/src/localization/package.nls.de.json +++ b/packages/vipeye-internal/src/localization/package.nls.de.json @@ -429,13 +429,13 @@ "protocolVarianceContravariant": "Die Typvariable \"{variable}\", die im generischen Protocol \"{class}\" verwendet wird, muss \"contravariant\" sein.", "protocolVarianceCovariant": "Die Typvariable \"{variable}\", die im generischen Protocol \"{class}\" verwendet wird, muss \"covariant\" sein.", "protocolVarianceInvariant": "Die Typvariable \"{variable}\", die im generischen Protocol \"{class}\" verwendet wird, muss \"invariant\" sein.", - "pyrightCommentInvalidDiagnosticBoolValue": "Auf die Pyright-Kommentardirektive muss \"=\" und der Wert \"true\" oder \"false\" folgen.", - "pyrightCommentInvalidDiagnosticSeverityValue": "Auf die Pyright-Kommentardirektive muss \"=\" und der Wert \"true\", \"false\", \"error\", \"warning\", \"information\" oder \"none\" folgen.", - "pyrightCommentMissingDirective": "Auf einen Pyright-Kommentar muss eine Direktive (basic oder strict) oder eine Diagnoseregel folgen.", - "pyrightCommentNotOnOwnLine": "Pyright-Kommentare, die zum Steuern von Einstellungen auf Dateiebene verwendet werden, müssen in ihrer eigenen Zeile angezeigt werden.", - "pyrightCommentUnknownDiagnosticRule": "\"{rule}\" ist eine unbekannte Diagnoseregel für pyright-Kommentar.", - "pyrightCommentUnknownDiagnosticSeverityValue": "\"{value}\" ist ein ungültiger Wert für den pyright-Kommentar; \"true\", \"false\", \"error\", \"warning\", \"information\" oder \"none\" erwartet.", - "pyrightCommentUnknownDirective": "„{directive}“ ist eine unbekannte Direktive für pyright-Kommentar; „strict“, „standard“ oder „basic“ erwartet", + "viperCommentInvalidDiagnosticBoolValue": "Auf die Viper-Kommentardirektive muss \"=\" und der Wert \"true\" oder \"false\" folgen.", + "viperCommentInvalidDiagnosticSeverityValue": "Auf die Viper-Kommentardirektive muss \"=\" und der Wert \"true\", \"false\", \"error\", \"warning\", \"information\" oder \"none\" folgen.", + "viperCommentMissingDirective": "Auf einen Viper-Kommentar muss eine Direktive (basic oder strict) oder eine Diagnoseregel folgen.", + "viperCommentNotOnOwnLine": "Viper-Kommentare, die zum Steuern von Einstellungen auf Dateiebene verwendet werden, müssen in ihrer eigenen Zeile angezeigt werden.", + "viperCommentUnknownDiagnosticRule": "\"{rule}\" ist eine unbekannte Diagnoseregel für viper-Kommentar.", + "viperCommentUnknownDiagnosticSeverityValue": "\"{value}\" ist ein ungültiger Wert für den viper-Kommentar; \"true\", \"false\", \"error\", \"warning\", \"information\" oder \"none\" erwartet.", + "viperCommentUnknownDirective": "„{directive}“ ist eine unbekannte Direktive für viper-Kommentar; „strict“, „standard“ oder „basic“ erwartet", "readOnlyArgCount": "Nach \"ReadOnly\" wurde ein einzelnes Typargument erwartet.", "readOnlyNotInTypedDict": "\"ReadOnly\" ist in diesem Kontext nicht zulässig.", "recursiveDefinition": "Der Typ von \"{name}\" konnte nicht bestimmt werden, da er sich auf selbst bezieht.", @@ -625,8 +625,8 @@ "unnecessaryIsInstanceNever": "Nicht erforderlicher isinstance-Aufruf; \"{testType}\" ist nie eine Instanz von \"{classType}\"", "unnecessaryIsSubclassAlways": "Nicht erforderlicher issubclass-Aufruf; \"{testType}\" ist immer eine Unterklasse von \"{classType}\"", "unnecessaryIsSubclassNever": "Nicht erforderlicher issubclass-Aufruf; \"{testType}\" ist nie eine Unterklasse von \"{classType}\"", - "unnecessaryPyrightIgnore": "Unnötiger \"# pyright: ignore\"-Kommentar", - "unnecessaryPyrightIgnoreRule": "Unnötiger \"# pyright: ignore\"-Regel: \"{name}\"", + "unnecessaryViperIgnore": "Unnötiger \"# viper: ignore\"-Kommentar", + "unnecessaryViperIgnoreRule": "Unnötiger \"# viper: ignore\"-Regel: \"{name}\"", "unnecessaryTypeIgnore": "Nicht erforderlicher \"# type: ignore\"-Kommentar", "unpackArgCount": "Nach \"Unpack\" wurde ein einzelnes Typargument erwartet.", "unpackExpectedTypeVarTuple": "„TypeVarTuple“ oder „tuple“ als Typargument für „Unpack“ erwartet", @@ -786,7 +786,7 @@ "protocolRequiresRuntimeCheckable": "Die Protocol Klasse muss @runtime_checkable sein, damit sie mit Instanz- und Klassenprüfungen verwendet werden kann.", "protocolSourceIsNotConcrete": "\"{sourceType}\" ist kein konkreter Klassentyp und kann dem Typ \"{destType}\" nicht zugewiesen werden.", "protocolUnsafeOverlap": "Attribute von „{name}“ weisen die gleichen Namen wie das Protokoll auf.", - "pyrightCommentIgnoreTip": "Verwenden Sie \"# pyright: ignore[]\", um die Diagnose für eine einzelne Zeile zu unterdrücken.", + "viperCommentIgnoreTip": "Verwenden Sie \"# viper: ignore[]\", um die Diagnose für eine einzelne Zeile zu unterdrücken.", "readOnlyAttribute": "Das Attribut \"{name}\" ist schreibgeschützt.", "seeClassDeclaration": "Siehe Klassendeklaration", "seeDeclaration": "Siehe Deklaration", diff --git a/packages/vipeye-internal/src/localization/package.nls.en-us.json b/packages/vipeye-internal/src/localization/package.nls.en-us.json index 69d6957c..d5d06ecb 100644 --- a/packages/vipeye-internal/src/localization/package.nls.en-us.json +++ b/packages/vipeye-internal/src/localization/package.nls.en-us.json @@ -108,11 +108,11 @@ "binaryOperationNotAllowed": "Binary operator not allowed in type expression", "bindParamMissing": { "message": "Could not bind method \"{methodName}\" because it is missing a \"self\" or \"cls\" parameter", - "comment": "Binding is the process through which Pyright determines what object a name refers to" + "comment": "Binding is the process through which Viper determines what object a name refers to" }, "bindTypeMismatch": { "message": "Could not bind method \"{methodName}\" because \"{type}\" is not assignable to parameter \"{paramName}\"", - "comment": "Binding is the process through which Pyright determines what object a name refers to" + "comment": "Binding is the process through which Viper determines what object a name refers to" }, "breakInExceptionGroup": { "message": "\"break\" is not allowed in an \"except*\" block", @@ -677,7 +677,7 @@ }, "internalBindError": { "message": "An internal error occurred while binding file \"{file}\": {message}", - "comment": "Binding is the process through which Pyright determines what object a name refers to" + "comment": "Binding is the process through which Viper determines what object a name refers to" }, "internalParseError": "An internal error occurred while parsing file \"{file}\": {message}", "internalTypeCheckingError": "An internal error occurred while type checking file \"{file}\": {message}", @@ -866,7 +866,7 @@ }, "nonLocalNoBinding": { "message": "No binding for nonlocal \"{name}\" found", - "comment": ["{Locked='nonlocal'}", "'No binding found' means that Pyright couldn't resolve the variable name to an object"] + "comment": ["{Locked='nonlocal'}", "'No binding found' means that Viper couldn't resolve the variable name to an object"] }, "nonLocalReassignment": { "message": "\"{name}\" is assigned before nonlocal declaration", @@ -1095,33 +1095,33 @@ "message": "Type variable \"{variable}\" used in generic Protocol \"{class}\" should be invariant", "comment": ["{Locked='Protocol'}", "A generic type is a parameterized type, for example a container where the generic type parameter specifies the type of elements in the container"] }, - "pyrightCommentInvalidDiagnosticBoolValue": { - "message": "Pyright comment directive must be followed by \"=\" and a value of true or false", - "comment": "{Locked='Pyright','true','false'}" + "viperCommentInvalidDiagnosticBoolValue": { + "message": "Viper comment directive must be followed by \"=\" and a value of true or false", + "comment": "{Locked='Viper','true','false'}" }, - "pyrightCommentInvalidDiagnosticSeverityValue": { - "message": "Pyright comment directive must be followed by \"=\" and a value of true, false, error, warning, information, or none", - "comment": "{Locked='Pyright','true','false','error','warning','information','none'}" + "viperCommentInvalidDiagnosticSeverityValue": { + "message": "Viper comment directive must be followed by \"=\" and a value of true, false, error, warning, information, or none", + "comment": "{Locked='Viper','true','false','error','warning','information','none'}" }, - "pyrightCommentMissingDirective": { - "message": "Pyright comment must be followed by a directive (basic or strict) or a diagnostic rule", - "comment": "{Locked='Pyright','basic','strict'}" + "viperCommentMissingDirective": { + "message": "Viper comment must be followed by a directive (basic or strict) or a diagnostic rule", + "comment": "{Locked='Viper','basic','strict'}" }, - "pyrightCommentNotOnOwnLine": { - "message": "Pyright comments used to control file-level settings must appear on their own line", - "comment": "{Locked='Pyright'}" + "viperCommentNotOnOwnLine": { + "message": "Viper comments used to control file-level settings must appear on their own line", + "comment": "{Locked='Viper'}" }, - "pyrightCommentUnknownDiagnosticRule": { - "message": "\"{rule}\" is an unknown diagnostic rule for pyright comment", - "comment": "{Locked='pyright'}" + "viperCommentUnknownDiagnosticRule": { + "message": "\"{rule}\" is an unknown diagnostic rule for viper comment", + "comment": "{Locked='viper'}" }, - "pyrightCommentUnknownDiagnosticSeverityValue": { - "message": "\"{value}\" is invalid value for pyright comment; expected true, false, error, warning, information, or none", - "comment": "{Locked='pyright','true','false','error','warning','information','none'}" + "viperCommentUnknownDiagnosticSeverityValue": { + "message": "\"{value}\" is invalid value for viper comment; expected true, false, error, warning, information, or none", + "comment": "{Locked='viper','true','false','error','warning','information','none'}" }, - "pyrightCommentUnknownDirective": { - "message": "\"{directive}\" is an unknown directive for pyright comment; expected \"strict\", \"standard\", or \"basic\"", - "comment": "{Locked='pyright','strict','standard','basic'}" + "viperCommentUnknownDirective": { + "message": "\"{directive}\" is an unknown directive for viper comment; expected \"strict\", \"standard\", or \"basic\"", + "comment": "{Locked='viper','strict','standard','basic'}" }, "readOnlyArgCount": { "message": "Expected a single type argument after \"ReadOnly\"", @@ -1663,13 +1663,13 @@ "message": "Unnecessary issubclass call; \"{testType}\" is never a subclass of \"{classType}\"", "comment": "{Locked='issubclass'}" }, - "unnecessaryPyrightIgnore": { - "message": "Unnecessary \"# pyright: ignore\" comment", - "comment": "{Locked='# pyright: ignore'}" + "unnecessaryViperIgnore": { + "message": "Unnecessary \"# viper: ignore\" comment", + "comment": "{Locked='# viper: ignore'}" }, - "unnecessaryPyrightIgnoreRule": { - "message": "Unnecessary \"# pyright: ignore\" rule: \"{name}\"", - "comment": "{Locked='# pyright: ignore'}" + "unnecessaryViperIgnoreRule": { + "message": "Unnecessary \"# viper: ignore\" rule: \"{name}\"", + "comment": "{Locked='# viper: ignore'}" }, "unnecessaryTypeIgnore": { "message": "Unnecessary \"# type: ignore\" comment", @@ -1835,7 +1835,7 @@ "dataProtocolUnsupported": "\"{name}\" is a data protocol", "descriptorAccessBindingFailed": { "message": "Failed to bind method \"{name}\" for descriptor class \"{className}\"", - "comment": "Binding is the process through which Pyright determines what object a name refers to" + "comment": "Binding is the process through which Viper determines what object a name refers to" }, "descriptorAccessCallFailed": "Failed to call method \"{name}\" for descriptor class \"{className}\"", "finalMethod": { @@ -2040,9 +2040,9 @@ }, "protocolSourceIsNotConcrete": "\"{sourceType}\" is not a concrete class type and cannot be assigned to type \"{destType}\"", "protocolUnsafeOverlap": "Attributes of \"{name}\" have the same names as the protocol", - "pyrightCommentIgnoreTip": { - "message": "Use \"# pyright: ignore[]\" to suppress diagnostics for a single line", - "comment": "{Locked='# pyright: ignore[]'}" + "viperCommentIgnoreTip": { + "message": "Use \"# viper: ignore[]\" to suppress diagnostics for a single line", + "comment": "{Locked='# viper: ignore[]'}" }, "readOnlyAttribute": "Attribute \"{name}\" is read-only", "seeClassDeclaration": "See class declaration", diff --git a/packages/vipeye-internal/src/localization/package.nls.es.json b/packages/vipeye-internal/src/localization/package.nls.es.json index cc5cf110..6561bc0b 100644 --- a/packages/vipeye-internal/src/localization/package.nls.es.json +++ b/packages/vipeye-internal/src/localization/package.nls.es.json @@ -429,13 +429,13 @@ "protocolVarianceContravariant": "La variable de tipo \"{variable}\" usada en Protocol genérico \"{class}\" debe ser contravariante", "protocolVarianceCovariant": "La variable de tipo \"{variable}\" usada en Protocol genérico \"{class}\" debe ser covariante", "protocolVarianceInvariant": "La variable de tipo \"{variable}\" usada en Protocol genérico \"{class}\" debe ser invariable", - "pyrightCommentInvalidDiagnosticBoolValue": "La directiva de comentario Pyright debe ir seguida de \"=\" y un valor de true o false", - "pyrightCommentInvalidDiagnosticSeverityValue": "La directiva de comentario Pyright debe ir seguida de \"=\" y un valor de true, false, error, warning, information o none.", - "pyrightCommentMissingDirective": "El comentario de Pyright debe ir seguido de una directiva (basic o estricta) o de una regla de diagnóstico", - "pyrightCommentNotOnOwnLine": "Los comentarios de Pyright utilizados para controlar los ajustes a nivel de archivo deben aparecer en su propia línea", - "pyrightCommentUnknownDiagnosticRule": "\"{rule}\" es una regla de diagnóstico desconocida para el comentario pyright", - "pyrightCommentUnknownDiagnosticSeverityValue": "\"{value}\" es un valor no válido para el comentario pyright; se espera true, false, error, warning, information o none.", - "pyrightCommentUnknownDirective": "\"{directive}\" es una directiva desconocida para el comentario pyright; se esperaba \"strict\", \"standard\" o \"basic\"", + "viperCommentInvalidDiagnosticBoolValue": "La directiva de comentario Viper debe ir seguida de \"=\" y un valor de true o false", + "viperCommentInvalidDiagnosticSeverityValue": "La directiva de comentario Viper debe ir seguida de \"=\" y un valor de true, false, error, warning, information o none.", + "viperCommentMissingDirective": "El comentario de Viper debe ir seguido de una directiva (basic o estricta) o de una regla de diagnóstico", + "viperCommentNotOnOwnLine": "Los comentarios de Viper utilizados para controlar los ajustes a nivel de archivo deben aparecer en su propia línea", + "viperCommentUnknownDiagnosticRule": "\"{rule}\" es una regla de diagnóstico desconocida para el comentario viper", + "viperCommentUnknownDiagnosticSeverityValue": "\"{value}\" es un valor no válido para el comentario viper; se espera true, false, error, warning, information o none.", + "viperCommentUnknownDirective": "\"{directive}\" es una directiva desconocida para el comentario viper; se esperaba \"strict\", \"standard\" o \"basic\"", "readOnlyArgCount": "Se esperaba un único argumento de tipo después de \"ReadOnly\"", "readOnlyNotInTypedDict": "\"ReadOnly\" no está permitido en este contexto", "recursiveDefinition": "No se pudo determinar el tipo de \"{name}\" porque hace referencia a sí mismo.", @@ -625,8 +625,8 @@ "unnecessaryIsInstanceNever": "Llamada isinstance innecesaria; \"{testType}\" es nunca una instancia de \"{classType}\"", "unnecessaryIsSubclassAlways": "Llamada de issubclass innecesaria; \"{testType}\" siempre es una subclase de \"{classType}\"", "unnecessaryIsSubclassNever": "Llamada de issubclass innecesaria; \"{testType}\" nunca es una subclase de \"{classType}\"", - "unnecessaryPyrightIgnore": "Comentario \"# pyright: ignore\" innecesario", - "unnecessaryPyrightIgnoreRule": "Regla innecesaria \"# pyright: ignore\": \"{name}\"", + "unnecessaryViperIgnore": "Comentario \"# viper: ignore\" innecesario", + "unnecessaryViperIgnoreRule": "Regla innecesaria \"# viper: ignore\": \"{name}\"", "unnecessaryTypeIgnore": "Comentario \"# type: ignore\" innecesario", "unpackArgCount": "Se esperaba un único argumento de tipo después de \"Unpack\"", "unpackExpectedTypeVarTuple": "Se esperaba TypeVarTuple o tuple como argumento de tipo para Unpack", @@ -786,7 +786,7 @@ "protocolRequiresRuntimeCheckable": "La clase de Protocol debe ser @runtime_checkable para usarse con comprobaciones de instancia y clase", "protocolSourceIsNotConcrete": "\"{sourceType}\" no es un tipo de clase concreto y no se puede asignar al tipo \"{destType}\"", "protocolUnsafeOverlap": "Los atributos de \"{name}\" tienen los mismos nombres que el protocolo", - "pyrightCommentIgnoreTip": "Utilice \"# pyright: ignore[]\" para suprimir el diagnóstico de una sola línea", + "viperCommentIgnoreTip": "Utilice \"# viper: ignore[]\" para suprimir el diagnóstico de una sola línea", "readOnlyAttribute": "El atributo \"{name}\" es de solo lectura", "seeClassDeclaration": "Ver declaración de clase", "seeDeclaration": "Ver declaración", diff --git a/packages/vipeye-internal/src/localization/package.nls.fr.json b/packages/vipeye-internal/src/localization/package.nls.fr.json index 7ab15681..445e06b5 100644 --- a/packages/vipeye-internal/src/localization/package.nls.fr.json +++ b/packages/vipeye-internal/src/localization/package.nls.fr.json @@ -429,13 +429,13 @@ "protocolVarianceContravariant": "La variable de type \"{variable}\" utilisée dans le Protocol générique \"{class}\" doit être contravariante", "protocolVarianceCovariant": "La variable de type \"{variable}\" utilisée dans le Protocol générique \"{class}\" doit être covariante", "protocolVarianceInvariant": "La variable de type \"{variable}\" utilisée dans le Protocol générique \"{class}\" doit être invariante", - "pyrightCommentInvalidDiagnosticBoolValue": "La directive de commentaire Pyright doit être suivie de « = » et d’une valeur true ou false", - "pyrightCommentInvalidDiagnosticSeverityValue": "La directive de commentaire Pyright doit être suivie de « = » et avoir la valeur true, false, error, warning, information ou none", - "pyrightCommentMissingDirective": "Le commentaire Pyright doit être suivi d’une directive (basic ou strict) ou d’une règle de diagnostic", - "pyrightCommentNotOnOwnLine": "Les commentaires Pyright utilisés pour contrôler les paramètres au niveau du fichier doivent apparaître sur leur propre ligne", - "pyrightCommentUnknownDiagnosticRule": "« {rule} » est une règle de diagnostic inconnue pour le commentaire pyright", - "pyrightCommentUnknownDiagnosticSeverityValue": "« {value} » n’est pas valide pour le commentaire pyright ; true, false, error, warning, information ou none attendu", - "pyrightCommentUnknownDirective": "« {directive} » est une directive inconnue pour le commentaire pyright ; « strict », « standard » ou « basic » attendu", + "viperCommentInvalidDiagnosticBoolValue": "La directive de commentaire Viper doit être suivie de « = » et d’une valeur true ou false", + "viperCommentInvalidDiagnosticSeverityValue": "La directive de commentaire Viper doit être suivie de « = » et avoir la valeur true, false, error, warning, information ou none", + "viperCommentMissingDirective": "Le commentaire Viper doit être suivi d’une directive (basic ou strict) ou d’une règle de diagnostic", + "viperCommentNotOnOwnLine": "Les commentaires Viper utilisés pour contrôler les paramètres au niveau du fichier doivent apparaître sur leur propre ligne", + "viperCommentUnknownDiagnosticRule": "« {rule} » est une règle de diagnostic inconnue pour le commentaire viper", + "viperCommentUnknownDiagnosticSeverityValue": "« {value} » n’est pas valide pour le commentaire viper ; true, false, error, warning, information ou none attendu", + "viperCommentUnknownDirective": "« {directive} » est une directive inconnue pour le commentaire viper ; « strict », « standard » ou « basic » attendu", "readOnlyArgCount": "Attendu un seul argument de type après \"ReadOnly\"", "readOnlyNotInTypedDict": "« ReadOnly » n’est pas autorisé dans ce contexte", "recursiveDefinition": "Le type de \"{name}\" n'a pas pu être déterminé car il fait référence à lui-même", @@ -625,8 +625,8 @@ "unnecessaryIsInstanceNever": "Appel d’isinstance inutile; « {testType} » n est jamais une instance de « {classType} »", "unnecessaryIsSubclassAlways": "Appel issubclass inutile ; \"{testType}\" est toujours une sous-classe de \"{classType}\"", "unnecessaryIsSubclassNever": "Appel issubclass inutile; « {testType} » est toujours une sous-classe de « {classType} »", - "unnecessaryPyrightIgnore": "Commentaire \"# pyright: ignore\" inutile", - "unnecessaryPyrightIgnoreRule": "Règle inutile « # pyright: ignore » : « {name} »", + "unnecessaryViperIgnore": "Commentaire \"# viper: ignore\" inutile", + "unnecessaryViperIgnoreRule": "Règle inutile « # viper: ignore » : « {name} »", "unnecessaryTypeIgnore": "Commentaire \"# type: ignore\" inutile", "unpackArgCount": "Attendu un seul argument de type après \"Unpack\"", "unpackExpectedTypeVarTuple": "TypeVarTuple ou tuple attendu en tant qu’argument de type pour Unpack", @@ -786,7 +786,7 @@ "protocolRequiresRuntimeCheckable": "La classe de Protocol doit être @runtime_checkable à utiliser avec des vérifications d’instance et de classe", "protocolSourceIsNotConcrete": "\"{sourceType}\" n'est pas un type de classe concret et ne peut pas être affecté au type \"{destType}\"", "protocolUnsafeOverlap": "Les attributs de « {name} » ont les mêmes noms que le protocole", - "pyrightCommentIgnoreTip": "Utilisez « # pyright: ignore[] » pour supprimer les diagnostics pour une seule ligne", + "viperCommentIgnoreTip": "Utilisez « # viper: ignore[] » pour supprimer les diagnostics pour une seule ligne", "readOnlyAttribute": "L’attribut « {name} » est en lecture seule", "seeClassDeclaration": "Voir la déclaration de classe", "seeDeclaration": "Voir la déclaration", diff --git a/packages/vipeye-internal/src/localization/package.nls.it.json b/packages/vipeye-internal/src/localization/package.nls.it.json index 03036d60..f88c2997 100644 --- a/packages/vipeye-internal/src/localization/package.nls.it.json +++ b/packages/vipeye-internal/src/localization/package.nls.it.json @@ -429,13 +429,13 @@ "protocolVarianceContravariant": "La variabile di tipo \"{variable}\" usata in \"{class}\" Protocol generico deve essere controvariante", "protocolVarianceCovariant": "La variabile di tipo \"{variable}\" usata in \"{class}\" Protocol generico deve essere covariante", "protocolVarianceInvariant": "La variabile di tipo \"{variable}\" usata in \"{class}\" Protocol generico deve essere invariante", - "pyrightCommentInvalidDiagnosticBoolValue": "La direttiva di commento Pyright deve essere seguita da \"=\" e da un valore true o false", - "pyrightCommentInvalidDiagnosticSeverityValue": "La direttiva di commento Pyright deve essere seguita da \"=\" e da un valore true, false, error, warning, information o none", - "pyrightCommentMissingDirective": "Il commento Pyright deve essere seguito da una direttiva (basic o strict) o da una regola di diagnostica", - "pyrightCommentNotOnOwnLine": "I commenti Pyright usati per controllare le impostazioni a livello di file devono essere visualizzati nella propria riga", - "pyrightCommentUnknownDiagnosticRule": "\"{rule}\" è una regola di diagnostica sconosciuta per il commento pyright", - "pyrightCommentUnknownDiagnosticSeverityValue": "\"{value}\" non è un valore valido per il commento pyright; previsto true, false, error, warning, information o none", - "pyrightCommentUnknownDirective": "\"{directive}\" è una direttiva sconosciuta per il commento pyright; previsto \"strict\", \"standard\" o \"basic\"", + "viperCommentInvalidDiagnosticBoolValue": "La direttiva di commento Viper deve essere seguita da \"=\" e da un valore true o false", + "viperCommentInvalidDiagnosticSeverityValue": "La direttiva di commento Viper deve essere seguita da \"=\" e da un valore true, false, error, warning, information o none", + "viperCommentMissingDirective": "Il commento Viper deve essere seguito da una direttiva (basic o strict) o da una regola di diagnostica", + "viperCommentNotOnOwnLine": "I commenti Viper usati per controllare le impostazioni a livello di file devono essere visualizzati nella propria riga", + "viperCommentUnknownDiagnosticRule": "\"{rule}\" è una regola di diagnostica sconosciuta per il commento viper", + "viperCommentUnknownDiagnosticSeverityValue": "\"{value}\" non è un valore valido per il commento viper; previsto true, false, error, warning, information o none", + "viperCommentUnknownDirective": "\"{directive}\" è una direttiva sconosciuta per il commento viper; previsto \"strict\", \"standard\" o \"basic\"", "readOnlyArgCount": "Previsto un singolo argomento tipo dopo \"ReadOnly\"", "readOnlyNotInTypedDict": "\"ReadOnly\" non consentito in questo contesto", "recursiveDefinition": "Non è stato possibile determinare il tipo di \"{name}\" perché fa riferimento a se stesso", @@ -625,8 +625,8 @@ "unnecessaryIsInstanceNever": "Chiamata isinstance non necessaria; \"{testType}\" non è mai un'istanza di \"{classType}\"", "unnecessaryIsSubclassAlways": "Chiamata issubclass non necessaria; \"{testType}\" è sempre una sottoclasse di \"{classType}\"", "unnecessaryIsSubclassNever": "Chiamata issubclass non necessaria; \"{testType}\" non è mai una sottoclasse di \"{classType}\"", - "unnecessaryPyrightIgnore": "Commento \"# pyright: ignore\" non necessario", - "unnecessaryPyrightIgnoreRule": "Regola \"# pyright: ignore\" non necessaria: \"{name}\"", + "unnecessaryViperIgnore": "Commento \"# viper: ignore\" non necessario", + "unnecessaryViperIgnoreRule": "Regola \"# viper: ignore\" non necessaria: \"{name}\"", "unnecessaryTypeIgnore": "Commento \"# type: ignore\" non necessario", "unpackArgCount": "Previsto un singolo argomento di tipo dopo \"Unpack\"", "unpackExpectedTypeVarTuple": "È previsto TypeVarTuple o tuple come argomento di tipo per Unpack", @@ -786,7 +786,7 @@ "protocolRequiresRuntimeCheckable": "La classe di Protocol deve essere @runtime_checkable in modo che sia possibile usarla con i controlli di istanza e classe", "protocolSourceIsNotConcrete": "\"{sourceType}\" non è un tipo di classe concreto e non può essere assegnato al tipo \"{destType}\"", "protocolUnsafeOverlap": "Gli attributi di “{name}” hanno gli stessi nomi del protocollo", - "pyrightCommentIgnoreTip": "Usa \"# pyright: ignore[]\" per eliminare la diagnostica per una singola riga", + "viperCommentIgnoreTip": "Usa \"# viper: ignore[]\" per eliminare la diagnostica per una singola riga", "readOnlyAttribute": "L'attributo \"{name}\" è di sola lettura", "seeClassDeclaration": "Vedere la dichiarazione di classe", "seeDeclaration": "Vedere la dichiarazione", diff --git a/packages/vipeye-internal/src/localization/package.nls.ja.json b/packages/vipeye-internal/src/localization/package.nls.ja.json index 0aeeb96f..3fdf740e 100644 --- a/packages/vipeye-internal/src/localization/package.nls.ja.json +++ b/packages/vipeye-internal/src/localization/package.nls.ja.json @@ -429,13 +429,13 @@ "protocolVarianceContravariant": "ジェネリック Protocol \"{class}\" で使用される型変数 \"{variable}\" は反変である必要があります", "protocolVarianceCovariant": "ジェネリック Protocol \"{class}\" で使用される型変数 \"{variable}\" は共変である必要があります", "protocolVarianceInvariant": "ジェネリック Protocol \"{class}\" で使用される型変数 \"{variable}\" は不変である必要があります", - "pyrightCommentInvalidDiagnosticBoolValue": "Pyright コメント ディレクティブの後には \"=\" と値 true または false を指定する必要があります", - "pyrightCommentInvalidDiagnosticSeverityValue": "Pyright コメント ディレクティブの後に \"=\" と true、false、error、warning、information または none の値を指定する必要があります", - "pyrightCommentMissingDirective": "Pyright コメントの後にディレクティブ (basic または strict) または診断規則を指定する必要があります", - "pyrightCommentNotOnOwnLine": "ファイル レベルの設定を制御するために使用する Pyright コメントは、独自の行に表示する必要があります", - "pyrightCommentUnknownDiagnosticRule": "\"{rule}\" は pyright コメントの不明な診断規則です", - "pyrightCommentUnknownDiagnosticSeverityValue": "\"{value}\" は、pyright コメントの無効な値です。true、false、error、warning、information または none が必要です", - "pyrightCommentUnknownDirective": "\"{directive}\" は、pyright コメントの不明なディレクティブです。\"strict\"、\"standard\"、または \"basic\" が必要です", + "viperCommentInvalidDiagnosticBoolValue": "Viper コメント ディレクティブの後には \"=\" と値 true または false を指定する必要があります", + "viperCommentInvalidDiagnosticSeverityValue": "Viper コメント ディレクティブの後に \"=\" と true、false、error、warning、information または none の値を指定する必要があります", + "viperCommentMissingDirective": "Viper コメントの後にディレクティブ (basic または strict) または診断規則を指定する必要があります", + "viperCommentNotOnOwnLine": "ファイル レベルの設定を制御するために使用する Viper コメントは、独自の行に表示する必要があります", + "viperCommentUnknownDiagnosticRule": "\"{rule}\" は viper コメントの不明な診断規則です", + "viperCommentUnknownDiagnosticSeverityValue": "\"{value}\" は、viper コメントの無効な値です。true、false、error、warning、information または none が必要です", + "viperCommentUnknownDirective": "\"{directive}\" は、viper コメントの不明なディレクティブです。\"strict\"、\"standard\"、または \"basic\" が必要です", "readOnlyArgCount": "\"ReadOnly\" の後に 1 つの型引数が必要です", "readOnlyNotInTypedDict": "\"ReadOnly\" はこのコンテキストでは許可されていません", "recursiveDefinition": "\"{name}\" の型は、それ自体を参照しているため、特定できませんでした", @@ -625,8 +625,8 @@ "unnecessaryIsInstanceNever": "不要な isinstance 呼び出し; \"{testType}\" は\"{classType}\" のインスタンスであったことはありません", "unnecessaryIsSubclassAlways": "不要な issubclass 呼び出し。\"{testType}\" は常に \"{classType}\" のサブクラスです", "unnecessaryIsSubclassNever": "不要な issubclass 呼び出し; \"{testType}\" は \"{classType}\" のサブクラスであったことはありません", - "unnecessaryPyrightIgnore": "不要な \"# pyright: ignore\" コメント", - "unnecessaryPyrightIgnoreRule": "不要な \"# pyright: ignore\" ルール: \"{name}\"", + "unnecessaryViperIgnore": "不要な \"# viper: ignore\" コメント", + "unnecessaryViperIgnoreRule": "不要な \"# viper: ignore\" ルール: \"{name}\"", "unnecessaryTypeIgnore": "不要な \"# type: ignore\" コメント", "unpackArgCount": "\"Unpack\" の後に 1 つの型引数が必要です", "unpackExpectedTypeVarTuple": "Unpack の型引数として TypeVarTuple または tuple が必要です", @@ -786,7 +786,7 @@ "protocolRequiresRuntimeCheckable": "インスタンスとクラスのチェックで使用するには、Protocol クラスが @runtime_checkable である必要があります", "protocolSourceIsNotConcrete": "\"{sourceType}\" は具象クラス型ではないため、型 \"{destType}\" に割り当てることはできません", "protocolUnsafeOverlap": "\"{name}\" の属性の名前がプロトコルの名前と同じです", - "pyrightCommentIgnoreTip": "\"# pyright: ignore[] を使用して 1 行の診断を抑制します", + "viperCommentIgnoreTip": "\"# viper: ignore[] を使用して 1 行の診断を抑制します", "readOnlyAttribute": "属性 \"{name}\" は読み取り専用です", "seeClassDeclaration": "クラス宣言を参照してください", "seeDeclaration": "宣言を参照してください", diff --git a/packages/vipeye-internal/src/localization/package.nls.ko.json b/packages/vipeye-internal/src/localization/package.nls.ko.json index 81e5172e..abc99912 100644 --- a/packages/vipeye-internal/src/localization/package.nls.ko.json +++ b/packages/vipeye-internal/src/localization/package.nls.ko.json @@ -429,13 +429,13 @@ "protocolVarianceContravariant": "제네릭 Protocol \"{class}\"에 사용되는 형식 변수 \"{variable}\"은(는) 반공변이어야 합니다.", "protocolVarianceCovariant": "제네릭 Protocol \"{class}\"에 사용되는 형식 변수 \"{variable}\"은(는) 공변(covariant)이어야 합니다.", "protocolVarianceInvariant": "제네릭 Protocol \"{class}\"에 사용되는 형식 변수 \"{variable}\"은(는) 고정되어야 합니다.", - "pyrightCommentInvalidDiagnosticBoolValue": "Pyright 주석 지시문 뒤에는 \"=\"와 true 또는 false 값이 와야 합니다.", - "pyrightCommentInvalidDiagnosticSeverityValue": "Pyright 주석 지시문 뒤에는 \"=\"와 true, false, error, warning, information 또는 none 값이 와야 합니다.", - "pyrightCommentMissingDirective": "Pyright 메모 뒤에는 지시문(basic 또는 strict) 또는 진단 규칙이 있어야 합니다.", - "pyrightCommentNotOnOwnLine": "파일 수준 설정을 제어하는 데 사용되는Pyright 주석은 고유의 줄에 표시되어야 합니다.", - "pyrightCommentUnknownDiagnosticRule": "\"{rule}\"은(는) pyright 주석에 대한 알 수 없는 진단 규칙입니다.", - "pyrightCommentUnknownDiagnosticSeverityValue": "\"{value}\"이(가) pyright 주석에 대해 잘못된 값입니다. true, false, error, warning, information 또는 none이 필요합니다.", - "pyrightCommentUnknownDirective": "\"{directive}\"은(는) pyright 주석에 대한 알 수 없는 지시문입니다. \"strict\", \"standard\" 또는 \"basic\"이 필요합니다.", + "viperCommentInvalidDiagnosticBoolValue": "Viper 주석 지시문 뒤에는 \"=\"와 true 또는 false 값이 와야 합니다.", + "viperCommentInvalidDiagnosticSeverityValue": "Viper 주석 지시문 뒤에는 \"=\"와 true, false, error, warning, information 또는 none 값이 와야 합니다.", + "viperCommentMissingDirective": "Viper 메모 뒤에는 지시문(basic 또는 strict) 또는 진단 규칙이 있어야 합니다.", + "viperCommentNotOnOwnLine": "파일 수준 설정을 제어하는 데 사용되는Viper 주석은 고유의 줄에 표시되어야 합니다.", + "viperCommentUnknownDiagnosticRule": "\"{rule}\"은(는) viper 주석에 대한 알 수 없는 진단 규칙입니다.", + "viperCommentUnknownDiagnosticSeverityValue": "\"{value}\"이(가) viper 주석에 대해 잘못된 값입니다. true, false, error, warning, information 또는 none이 필요합니다.", + "viperCommentUnknownDirective": "\"{directive}\"은(는) viper 주석에 대한 알 수 없는 지시문입니다. \"strict\", \"standard\" 또는 \"basic\"이 필요합니다.", "readOnlyArgCount": "‘ReadOnly‘ 뒤에는 단일 형식 인수가 필요합니다.", "readOnlyNotInTypedDict": "이 컨텍스트에서는 \"ReadOnly\"를 사용할 수 없습니다.", "recursiveDefinition": "‘{name}’ 형식이 스스로를 참조하므로 확인할 수 없습니다.", @@ -625,8 +625,8 @@ "unnecessaryIsInstanceNever": "불필요한 isinstance 호출입니다. \"{testType}\"은(는) 항상 \"{classType}\"의 인스턴스입니다.", "unnecessaryIsSubclassAlways": "불필요한 issubclass 호출입니다. ’{testType}‘은(는) 항상 ’{classType}‘의 하위 클래스입니다.", "unnecessaryIsSubclassNever": "불필요한 issubclass 호출입니다. ’{testType}‘은(는) 항상 ’{classType}‘의 하위 클래스입니다.", - "unnecessaryPyrightIgnore": "불필요한 \"# pyright: ignore\" 메모입니다.", - "unnecessaryPyrightIgnoreRule": "불필요한 \"# pyright: ignore\" 규칙: \"{name}\"", + "unnecessaryViperIgnore": "불필요한 \"# viper: ignore\" 메모입니다.", + "unnecessaryViperIgnoreRule": "불필요한 \"# viper: ignore\" 규칙: \"{name}\"", "unnecessaryTypeIgnore": "불필요한 \"# type: ignore\" 메모입니다.", "unpackArgCount": "\"Unpack\" 뒤에는 단일 형식 인수가 필요합니다.", "unpackExpectedTypeVarTuple": "Unpack에 대한 형식 인수로 TypeVarTuple 또는 tuple이 필요합니다.", @@ -786,7 +786,7 @@ "protocolRequiresRuntimeCheckable": "인스턴스 및 클래스 검사와 함께 사용하려면 Protocol 클래스를 @runtime_checkable 합니다.", "protocolSourceIsNotConcrete": "‘{sourceType}’은(는) 구체적인 클래스 형식이 아니므로 ‘{destType}’ 형식에 할당할 수 없습니다.", "protocolUnsafeOverlap": "\"{name}\"의 특성은 프로토콜과 이름이 같습니다.", - "pyrightCommentIgnoreTip": "\"# pyright: ignore[]\"을 사용하여 한 줄에 대한 진단을 표시하지 않습니다.", + "viperCommentIgnoreTip": "\"# viper: ignore[]\"을 사용하여 한 줄에 대한 진단을 표시하지 않습니다.", "readOnlyAttribute": "특성 \"{name}\"은(는) 읽기 전용입니다.", "seeClassDeclaration": "클래스 선언 참조", "seeDeclaration": "선언 참조", diff --git a/packages/vipeye-internal/src/localization/package.nls.pl.json b/packages/vipeye-internal/src/localization/package.nls.pl.json index 61a55ef5..9536bab8 100644 --- a/packages/vipeye-internal/src/localization/package.nls.pl.json +++ b/packages/vipeye-internal/src/localization/package.nls.pl.json @@ -429,13 +429,13 @@ "protocolVarianceContravariant": "Zmienna typu „{variable}” używana w klasie ogólnej Protocol „{class}” powinna być kontrawariantna", "protocolVarianceCovariant": "Zmienna typu „{variable}” używana w klasie ogólnej Protocol „{class}” powinna być kowariantna", "protocolVarianceInvariant": "Zmienna typu „{variable}” używana w klasie ogólnego Protocol „{class}” powinna być niezmienna", - "pyrightCommentInvalidDiagnosticBoolValue": "Po dyrektywie komentarza Pyright musi następować znak „=” oraz wartość true lub false", - "pyrightCommentInvalidDiagnosticSeverityValue": "Po dyrektywie komentarza Pyright musi następować znak „=” oraz wartość true, false, error, warning, information lub none", - "pyrightCommentMissingDirective": "Po komentarzu Pyright musi następować dyrektywa (basic lub strict) lub reguła diagnostyczna", - "pyrightCommentNotOnOwnLine": "Komentarze Pyright używane do kontrolowania ustawień na poziomie plików muszą pojawiać się w oddzielnych wierszach", - "pyrightCommentUnknownDiagnosticRule": "Reguła „{rule}” jest nieznaną regułą diagnostyczną dla komentarza pyright", - "pyrightCommentUnknownDiagnosticSeverityValue": "Wartość „{value}” jest nieprawidłowa dla komentarza pyright; oczekiwano wartości: true, false, error, warning, information lub none", - "pyrightCommentUnknownDirective": "„{directive}” jest nieznaną dyrektywą dla komentarza pyright; oczekiwano „strict”, „standard” lub „basic”", + "viperCommentInvalidDiagnosticBoolValue": "Po dyrektywie komentarza Viper musi następować znak „=” oraz wartość true lub false", + "viperCommentInvalidDiagnosticSeverityValue": "Po dyrektywie komentarza Viper musi następować znak „=” oraz wartość true, false, error, warning, information lub none", + "viperCommentMissingDirective": "Po komentarzu Viper musi następować dyrektywa (basic lub strict) lub reguła diagnostyczna", + "viperCommentNotOnOwnLine": "Komentarze Viper używane do kontrolowania ustawień na poziomie plików muszą pojawiać się w oddzielnych wierszach", + "viperCommentUnknownDiagnosticRule": "Reguła „{rule}” jest nieznaną regułą diagnostyczną dla komentarza viper", + "viperCommentUnknownDiagnosticSeverityValue": "Wartość „{value}” jest nieprawidłowa dla komentarza viper; oczekiwano wartości: true, false, error, warning, information lub none", + "viperCommentUnknownDirective": "„{directive}” jest nieznaną dyrektywą dla komentarza viper; oczekiwano „strict”, „standard” lub „basic”", "readOnlyArgCount": "Oczekiwano jednego argumentu typu po wartości „ReadOnly”", "readOnlyNotInTypedDict": "Element „ReadOnly” jest niedozwolony w tym kontekście", "recursiveDefinition": "Nie można określić typu „{name}”, ponieważ odwołuje się on do samego siebie", @@ -625,8 +625,8 @@ "unnecessaryIsInstanceNever": "Niepotrzebne wywołanie funkcji isinstance; „{testType}” nigdy nie jest instancją „{classType}”", "unnecessaryIsSubclassAlways": "Niepotrzebne wywołanie „issubclass”; „{testType}” jest zawsze podklasą klasy „{classType}”", "unnecessaryIsSubclassNever": "Niepotrzebne wywołanie funkcji issubclass; „{testType}” nigdy nie jest podklasą „{classType}”", - "unnecessaryPyrightIgnore": "Niepotrzebny komentarz „# pyright: ignore”", - "unnecessaryPyrightIgnoreRule": "Niepotrzebna reguła „# pyright: ignore”: „{name}”", + "unnecessaryViperIgnore": "Niepotrzebny komentarz „# viper: ignore”", + "unnecessaryViperIgnoreRule": "Niepotrzebna reguła „# viper: ignore”: „{name}”", "unnecessaryTypeIgnore": "Niepotrzebny komentarz „# type: ignore”", "unpackArgCount": "Oczekiwano jednego argumentu typu po wartości „Unpack”", "unpackExpectedTypeVarTuple": "Oczekiwano typu TypeVarTuple lub tuple jako argumentu typu dla elementu Unpack", @@ -786,7 +786,7 @@ "protocolRequiresRuntimeCheckable": "Klasa Protocol musi być @runtime_checkable, aby mogła być używana z kontrolami wystąpień i klas", "protocolSourceIsNotConcrete": "„{sourceType}” nie jest typem specyficznej klasy i nie można go przypisać do typu „{destType}”", "protocolUnsafeOverlap": "Atrybuty „{name}” mają takie same nazwy jak protokół", - "pyrightCommentIgnoreTip": "Użyj polecenia „# pyright: ignore[]”, aby wyłączyć diagnostykę dla pojedynczego wiersza", + "viperCommentIgnoreTip": "Użyj polecenia „# viper: ignore[]”, aby wyłączyć diagnostykę dla pojedynczego wiersza", "readOnlyAttribute": "Atrybut „{name}” jest tylko do odczytu", "seeClassDeclaration": "Zobacz deklarację klasy", "seeDeclaration": "Zobacz deklarację", diff --git a/packages/vipeye-internal/src/localization/package.nls.pt-br.json b/packages/vipeye-internal/src/localization/package.nls.pt-br.json index 0febab0e..bf8c3c02 100644 --- a/packages/vipeye-internal/src/localization/package.nls.pt-br.json +++ b/packages/vipeye-internal/src/localization/package.nls.pt-br.json @@ -429,13 +429,13 @@ "protocolVarianceContravariant": "A variável de tipo \"{variable}\" usada na \"{class}\" Protocol genérica deve ser contravariante", "protocolVarianceCovariant": "A variável de tipo \"{variable}\" usada na \"{class}\" Protocol genérica deve ser covariante", "protocolVarianceInvariant": "A variável de tipo \"{variable}\" usada na \"{class}\" Protocol genérica deve ser invariável", - "pyrightCommentInvalidDiagnosticBoolValue": "A diretiva de comentário Pyright deve ser seguida por \"=\" e um valor true ou false", - "pyrightCommentInvalidDiagnosticSeverityValue": "A diretiva de comentário Pyright deve ser seguida por \"=\" e um valor de true, false, error, warning, information ou none", - "pyrightCommentMissingDirective": "O comentário Pyright deve ser seguido por uma diretiva (basic ou strict) ou uma regra de diagnóstico", - "pyrightCommentNotOnOwnLine": "Comentários Pyright usados para controlar as configurações de nível de arquivo devem aparecer em sua própria linha", - "pyrightCommentUnknownDiagnosticRule": "\"{rule}\" é uma regra de diagnóstico desconhecida para o comentário pyright", - "pyrightCommentUnknownDiagnosticSeverityValue": "\"{value}\" é um valor inválido para o comentário pyright. true, false, error, warning, information ou none esperados.", - "pyrightCommentUnknownDirective": "\"{directive}\" é uma diretiva desconhecida para o comentário pyright; esperava-se \"strict\", \"standard\" ou \"basic\"", + "viperCommentInvalidDiagnosticBoolValue": "A diretiva de comentário Viper deve ser seguida por \"=\" e um valor true ou false", + "viperCommentInvalidDiagnosticSeverityValue": "A diretiva de comentário Viper deve ser seguida por \"=\" e um valor de true, false, error, warning, information ou none", + "viperCommentMissingDirective": "O comentário Viper deve ser seguido por uma diretiva (basic ou strict) ou uma regra de diagnóstico", + "viperCommentNotOnOwnLine": "Comentários Viper usados para controlar as configurações de nível de arquivo devem aparecer em sua própria linha", + "viperCommentUnknownDiagnosticRule": "\"{rule}\" é uma regra de diagnóstico desconhecida para o comentário viper", + "viperCommentUnknownDiagnosticSeverityValue": "\"{value}\" é um valor inválido para o comentário viper. true, false, error, warning, information ou none esperados.", + "viperCommentUnknownDirective": "\"{directive}\" é uma diretiva desconhecida para o comentário viper; esperava-se \"strict\", \"standard\" ou \"basic\"", "readOnlyArgCount": "Argumento de tipo único esperado após \"ReadOnly\"", "readOnlyNotInTypedDict": "\"ReadOnly\" não é permitido neste contexto", "recursiveDefinition": "Não foi possível determinar o tipo de \"{name}\" porque ele refere-se a si mesmo", @@ -625,8 +625,8 @@ "unnecessaryIsInstanceNever": "Chamada de isinstance desnecessária; '{testType}' nunca é uma instância de '{classType}'", "unnecessaryIsSubclassAlways": "Chamada issubclass desnecessária. \"{testType}\" é sempre uma subclasse de \"{classType}\"", "unnecessaryIsSubclassNever": "Chamada issubclass desnecessária; '{testType}' nunca é uma subclasse de '{classType}'", - "unnecessaryPyrightIgnore": "Comentário desnecessário \"# pyright: ignore\"", - "unnecessaryPyrightIgnoreRule": "Regra desnecessária \"# pyright: ignore\": \"{name}\"", + "unnecessaryViperIgnore": "Comentário desnecessário \"# viper: ignore\"", + "unnecessaryViperIgnoreRule": "Regra desnecessária \"# viper: ignore\": \"{name}\"", "unnecessaryTypeIgnore": "Comentário \"# type: ignore\" desnecessário", "unpackArgCount": "Argumento de tipo único esperado após \"Unpack\"", "unpackExpectedTypeVarTuple": "TypeVarTuple ou tuple esperado como argumento de tipo para Unpack", @@ -786,7 +786,7 @@ "protocolRequiresRuntimeCheckable": "A classe do Protocol deve ser @runtime_checkable para ser usada com verificações de instância e de classe", "protocolSourceIsNotConcrete": "\"{sourceType}\" não é um tipo de classe concreta e não pode ser atribuído ao tipo \"{destType}\"", "protocolUnsafeOverlap": "Os atributos de \"{name}\" têm os mesmos nomes que o protocolo", - "pyrightCommentIgnoreTip": "Use \"# pyright: ignore[]\" para suprimir o diagnóstico de uma única linha", + "viperCommentIgnoreTip": "Use \"# viper: ignore[]\" para suprimir o diagnóstico de uma única linha", "readOnlyAttribute": "O atributo \"{name}\" é somente leitura", "seeClassDeclaration": "Consulte a declaração de classe", "seeDeclaration": "Consulte a declaração", diff --git a/packages/vipeye-internal/src/localization/package.nls.qps-ploc.json b/packages/vipeye-internal/src/localization/package.nls.qps-ploc.json index e086924f..de74e258 100644 --- a/packages/vipeye-internal/src/localization/package.nls.qps-ploc.json +++ b/packages/vipeye-internal/src/localization/package.nls.qps-ploc.json @@ -429,13 +429,13 @@ "protocolVarianceContravariant": "[B4htZ][นั้Tÿpë værïæþlë \"{værïæþlë}\" µsëð ïñ gëñërïç Protocol \"{çlæss}\" shøµlð þë çøñtræværïæñtẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰนั้ढूँ]", "protocolVarianceCovariant": "[Hcnn5][นั้Tÿpë værïæþlë \"{værïæþlë}\" µsëð ïñ gëñërïç Protocol \"{çlæss}\" shøµlð þë çøværïæñtẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İนั้ढूँ]", "protocolVarianceInvariant": "[o8oB7][นั้Tÿpë værïæþlë \"{værïæþlë}\" µsëð ïñ gëñërïç Protocol \"{çlæss}\" shøµlð þë ïñværïæñtẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İนั้ढूँ]", - "pyrightCommentInvalidDiagnosticBoolValue": "[eaJY0][นั้Pyright çømmëñt ðïrëçtïvë mµst þë følløwëð þÿ \"=\" æñð æ vælµë øf true ør falseẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪นั้ढूँ]", - "pyrightCommentInvalidDiagnosticSeverityValue": "[2YA7K][นั้Pyright çømmëñt ðïrëçtïvë mµst þë følløwëð þÿ \"=\" æñð æ vælµë øf true, false, error, warning, information, ør noneẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İนั้ढूँ]", - "pyrightCommentMissingDirective": "[yy6rB][นั้Pyright çømmëñt mµst þë følløwëð þÿ æ ðïrëçtïvë (basic ør strict) ør æ ðïægñøstïç rµlëẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰนั้ढूँ]", - "pyrightCommentNotOnOwnLine": "[mM2bV][นั้Pyright çømmëñts µsëð tø çøñtrøl fïlë-lëvël sëttïñgs mµst æppëær øñ thëïr øwñ lïñëẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İЂนั้ढूँ]", - "pyrightCommentUnknownDiagnosticRule": "[DFAZp][นั้\"{rµlë}\" ïs æñ µñkñøwñ ðïægñøstïç rµlë før pyright çømmëñtẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्นั้ढूँ]", - "pyrightCommentUnknownDiagnosticSeverityValue": "[Tgt0Y][นั้\"{vælµë}\" ïs ïñvælïð vælµë før pyright çømmëñt; ëxpëçtëð true, false, error, warning, information, ør noneẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまนั้ढूँ]", - "pyrightCommentUnknownDirective": "[HD6T4][นั้\"{ðïrëçtïvë}\" ïs æñ µñkñøwñ ðïrëçtïvë før pyright çømmëñt; ëxpëçtëð \"strict\", \"standard\", ør \"basic\"Ấğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृนั้ढूँ]", + "viperCommentInvalidDiagnosticBoolValue": "[eaJY0][นั้Viper çømmëñt ðïrëçtïvë mµst þë følløwëð þÿ \"=\" æñð æ vælµë øf true ør falseẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪นั้ढूँ]", + "viperCommentInvalidDiagnosticSeverityValue": "[2YA7K][นั้Viper çømmëñt ðïrëçtïvë mµst þë følløwëð þÿ \"=\" æñð æ vælµë øf true, false, error, warning, information, ør noneẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İนั้ढूँ]", + "viperCommentMissingDirective": "[yy6rB][นั้Viper çømmëñt mµst þë følløwëð þÿ æ ðïrëçtïvë (basic ør strict) ør æ ðïægñøstïç rµlëẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰนั้ढूँ]", + "viperCommentNotOnOwnLine": "[mM2bV][นั้Viper çømmëñts µsëð tø çøñtrøl fïlë-lëvël sëttïñgs mµst æppëær øñ thëïr øwñ lïñëẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İЂนั้ढूँ]", + "viperCommentUnknownDiagnosticRule": "[DFAZp][นั้\"{rµlë}\" ïs æñ µñkñøwñ ðïægñøstïç rµlë før viper çømmëñtẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्นั้ढूँ]", + "viperCommentUnknownDiagnosticSeverityValue": "[Tgt0Y][นั้\"{vælµë}\" ïs ïñvælïð vælµë før viper çømmëñt; ëxpëçtëð true, false, error, warning, information, ør noneẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまนั้ढूँ]", + "viperCommentUnknownDirective": "[HD6T4][นั้\"{ðïrëçtïvë}\" ïs æñ µñkñøwñ ðïrëçtïvë før viper çømmëñt; ëxpëçtëð \"strict\", \"standard\", ør \"basic\"Ấğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृนั้ढूँ]", "readOnlyArgCount": "[B1Erm][นั้Ëxpëçtëð æ sïñglë tÿpë ærgµmëñt æftër \"ReadOnly\"Ấğ倪İЂҰक्र्तिृまẤğ倪İЂนั้ढूँ]", "readOnlyNotInTypedDict": "[xJrLN][นั้\"ReadOnly\" ïs ñøt ælløwëð ïñ thïs çøñtëxtẤğ倪İЂҰक्र्तिृまẤğนั้ढूँ]", "recursiveDefinition": "[G3UUN][นั้Tÿpë øf \"{ñæmë}\" çøµlð ñøt þë ðëtërmïñëð þëçæµsë ït rëfërs tø ïtsëlfẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृนั้ढूँ]", @@ -625,8 +625,8 @@ "unnecessaryIsInstanceNever": "[60nSE][นั้Üññëçëssærÿ isinstance çæll; \"{tëstTÿpë}\" ïs ñëvër æñ ïñstæñçë øf \"{çlæssTÿpë}\"Ấğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İนั้ढूँ]", "unnecessaryIsSubclassAlways": "[BzHtx][นั้Üññëçëssærÿ issubclass çæll; \"{tëstTÿpë}\" ïs ælwæÿs æ sµþçlæss øf \"{çlæssTÿpë}\"Ấğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İนั้ढूँ]", "unnecessaryIsSubclassNever": "[bOMnf][นั้Üññëçëssærÿ issubclass çæll; \"{tëstTÿpë}\" ïs ñëvër æ sµþçlæss øf \"{çlæssTÿpë}\"Ấğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪นั้ढूँ]", - "unnecessaryPyrightIgnore": "[7QhdX][นั้Üññëçëssærÿ \"# pyright: ignore\" çømmëñtẤğ倪İЂҰक्र्तिृまẤğนั้ढूँ]", - "unnecessaryPyrightIgnoreRule": "[0ESoQ][นั้Üññëçëssærÿ \"# pyright: ignore\" rµlë: \"{ñæmë}\"Ấğ倪İЂҰक्र्तिृまẤğ倪İนั้ढूँ]", + "unnecessaryViperIgnore": "[7QhdX][นั้Üññëçëssærÿ \"# viper: ignore\" çømmëñtẤğ倪İЂҰक्र्तिृまẤğนั้ढूँ]", + "unnecessaryViperIgnoreRule": "[0ESoQ][นั้Üññëçëssærÿ \"# viper: ignore\" rµlë: \"{ñæmë}\"Ấğ倪İЂҰक्र्तिृまẤğ倪İนั้ढूँ]", "unnecessaryTypeIgnore": "[IoWr9][นั้Üññëçëssærÿ \"# type: ignore\" çømmëñtẤğ倪İЂҰक्र्तिृまนั้ढूँ]", "unpackArgCount": "[bkAT1][นั้Ëxpëçtëð æ sïñglë tÿpë ærgµmëñt æftër \"Unpack\"Ấğ倪İЂҰक्र्तिृまẤğ倪İนั้ढूँ]", "unpackExpectedTypeVarTuple": "[CWX8o][นั้Ëxpëçtëð TypeVarTuple ør tuple æs tÿpë ærgµmëñt før UnpackẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्นั้ढूँ]", @@ -786,7 +786,7 @@ "protocolRequiresRuntimeCheckable": "[c9ewn][นั้Protocol çlæss mµst þë @runtime_checkable tø þë µsëð wïth ïñstæñçë æñð çlæss çhëçksẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İЂนั้ढूँ]", "protocolSourceIsNotConcrete": "[DnLrN][นั้\"{søµrçëTÿpë}\" ïs ñøt æ çøñçrëtë çlæss tÿpë æñð çæññøt þë æssïgñëð tø tÿpë \"{ðëstTÿpë}\"Ấğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्นั้ढूँ]", "protocolUnsafeOverlap": "[fKiUM][นั้Ættrïþµtës øf \"{ñæmë}\" hævë thë sæmë ñæmës æs thë prøtøçølẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्นั้ढूँ]", - "pyrightCommentIgnoreTip": "[raFZN][นั้Üsë \"# pyright: ignore[]\" tø sµpprëss ðïægñøstïçs før æ sïñglë lïñëẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰนั้ढूँ]", + "viperCommentIgnoreTip": "[raFZN][นั้Üsë \"# viper: ignore[]\" tø sµpprëss ðïægñøstïçs før æ sïñglë lïñëẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰนั้ढूँ]", "readOnlyAttribute": "[k9waY][นั้Ættrïþµtë \"{ñæmë}\" ïs rëæð-øñlÿẤğ倪İЂҰक्र्तिृนั้ढूँ]", "seeClassDeclaration": "[8sx7n][นั้§ëë çlæss ðëçlærætïøñẤğ倪İЂҰक्นั้ढूँ]", "seeDeclaration": "[K0X6p][นั้§ëë ðëçlærætïøñẤğ倪İЂҰนั้ढूँ]", diff --git a/packages/vipeye-internal/src/localization/package.nls.ru.json b/packages/vipeye-internal/src/localization/package.nls.ru.json index e77519af..dce1a53b 100644 --- a/packages/vipeye-internal/src/localization/package.nls.ru.json +++ b/packages/vipeye-internal/src/localization/package.nls.ru.json @@ -429,13 +429,13 @@ "protocolVarianceContravariant": "Переменная типа \"{variable}\", используемая в универсальном Protocol \"{class}\", должна быть контравариантной.", "protocolVarianceCovariant": "Переменная типа \"{variable}\", используемая в универсальном Protocol \"{class}\", должна быть ковариантной", "protocolVarianceInvariant": "Переменная типа \"{variable}\", используемая в универсальном Protocol \"{class}\", должна быть инвариантной", - "pyrightCommentInvalidDiagnosticBoolValue": "За директивой комментария Pyright должно следовать \"=\" и значение true или false", - "pyrightCommentInvalidDiagnosticSeverityValue": "За директивой комментария Pyright должно следовать \"=\" и одно из следующих значений: true, false, error, warning, information или none", - "pyrightCommentMissingDirective": "После комментария Pyright должна следовать директива (basic или strict) или правило диагностики", - "pyrightCommentNotOnOwnLine": "Комментарии Pyright, используемые для управления параметрами на уровне файлов, должны располагаться в отдельной строке", - "pyrightCommentUnknownDiagnosticRule": "Правило диагностики \"{rule}\" для комментария pyright неизвестно", - "pyrightCommentUnknownDiagnosticSeverityValue": "Значение \"{value}\" недопустимо для комментария pyright; ожидается одно из значений true, false, error, warning, information или none", - "pyrightCommentUnknownDirective": "\"{directive}\" — это неизвестная директива для комментария pyright; ожидается \"strict\", \"standard\" или \"basic\"", + "viperCommentInvalidDiagnosticBoolValue": "За директивой комментария Viper должно следовать \"=\" и значение true или false", + "viperCommentInvalidDiagnosticSeverityValue": "За директивой комментария Viper должно следовать \"=\" и одно из следующих значений: true, false, error, warning, information или none", + "viperCommentMissingDirective": "После комментария Viper должна следовать директива (basic или strict) или правило диагностики", + "viperCommentNotOnOwnLine": "Комментарии Viper, используемые для управления параметрами на уровне файлов, должны располагаться в отдельной строке", + "viperCommentUnknownDiagnosticRule": "Правило диагностики \"{rule}\" для комментария viper неизвестно", + "viperCommentUnknownDiagnosticSeverityValue": "Значение \"{value}\" недопустимо для комментария viper; ожидается одно из значений true, false, error, warning, information или none", + "viperCommentUnknownDirective": "\"{directive}\" — это неизвестная директива для комментария viper; ожидается \"strict\", \"standard\" или \"basic\"", "readOnlyArgCount": "Ожидается один аргумент типа после \"ReadOnly\"", "readOnlyNotInTypedDict": "Использование \"ReadOnly\" в этом контексте не допускается", "recursiveDefinition": "Не удалось определить тип \"{name}\", так как он ссылается на себя", @@ -625,8 +625,8 @@ "unnecessaryIsInstanceNever": "Ненужный вызов isinstance; \"{testType}\" никогда не является экземпляром \"{classType}\"", "unnecessaryIsSubclassAlways": "Ненужный вызов issubclass. \"{testType}\" всегда является подклассом \"{classType}\"", "unnecessaryIsSubclassNever": "Ненужный вызов issubclass; \"{testType}\" никогда не является подклассом \"{classType}\"", - "unnecessaryPyrightIgnore": "Ненужный комментарий \"# pyright: ignore\"", - "unnecessaryPyrightIgnoreRule": "Ненужное правило \"# pyright: ignore\": \"{name}\"", + "unnecessaryViperIgnore": "Ненужный комментарий \"# viper: ignore\"", + "unnecessaryViperIgnoreRule": "Ненужное правило \"# viper: ignore\": \"{name}\"", "unnecessaryTypeIgnore": "Ненужный комментарий \"# type: ignore\"", "unpackArgCount": "Ожидается один аргумент типа после \"Unpack\"", "unpackExpectedTypeVarTuple": "В качестве аргумента типа для Unpack ожидается элемент TypeVarTuple или tuple", @@ -786,7 +786,7 @@ "protocolRequiresRuntimeCheckable": "Класс Protocol должен быть @runtime_checkable, чтобы его можно было использовать при проверках экземпляров и классов", "protocolSourceIsNotConcrete": "\"{sourceType}\" не является конкретным типом класса и не может быть присвоен типу \"{destType}\"", "protocolUnsafeOverlap": "Атрибуты \"{name}\" используют те же имена, что и протокол", - "pyrightCommentIgnoreTip": "Для подавления диагностики в одной строке используйте конструкцию \"# pyright: ignore[]\"", + "viperCommentIgnoreTip": "Для подавления диагностики в одной строке используйте конструкцию \"# viper: ignore[]\"", "readOnlyAttribute": "Атрибут \"{name}\" доступен только для чтения", "seeClassDeclaration": "См. объявление класса", "seeDeclaration": "См. объявление", diff --git a/packages/vipeye-internal/src/localization/package.nls.tr.json b/packages/vipeye-internal/src/localization/package.nls.tr.json index 8086b8da..fdac42c6 100644 --- a/packages/vipeye-internal/src/localization/package.nls.tr.json +++ b/packages/vipeye-internal/src/localization/package.nls.tr.json @@ -429,13 +429,13 @@ "protocolVarianceContravariant": "Genel Protocol \"{class}\" için kullanılan \"{variable}\" tür değişkeni, değişken karşıtı olmalıdır", "protocolVarianceCovariant": "Genel Protocol \"{class}\" için kullanılan \"{variable}\" tür değişkeni, birlikte değişen olmalıdır", "protocolVarianceInvariant": "Genel Protocol \"{class}\" için kullanılan \"{variable}\" tür değişkeni sabit olmalıdır", - "pyrightCommentInvalidDiagnosticBoolValue": "Pyright açıklama yönergesinden sonra \"=\" ve true veya false değeri olmalıdır", - "pyrightCommentInvalidDiagnosticSeverityValue": "Pyright açıklama yönergesinden sonra \"=\" ve true, false, error, warning, information veya none değeri girilmelidir", - "pyrightCommentMissingDirective": "Pyright comment must be followed by a directive (basic or strict) or a diagnostic rule", - "pyrightCommentNotOnOwnLine": "Pyright comments used to control file-level settings must appear on their own line", - "pyrightCommentUnknownDiagnosticRule": "\"{rule}\", pyright açıklaması için bilinmeyen bir tanılama kuralı", - "pyrightCommentUnknownDiagnosticSeverityValue": "\"{value}\" pyright açıklaması için geçersiz değer; true, false, error, warning, information veya none bekleniyordu", - "pyrightCommentUnknownDirective": "\"{directive}\", pyright açıklaması için bilinmeyen bir yönergedir; \"strict\", \"standard\" veya \"basic\" bekleniyordu", + "viperCommentInvalidDiagnosticBoolValue": "Viper açıklama yönergesinden sonra \"=\" ve true veya false değeri olmalıdır", + "viperCommentInvalidDiagnosticSeverityValue": "Viper açıklama yönergesinden sonra \"=\" ve true, false, error, warning, information veya none değeri girilmelidir", + "viperCommentMissingDirective": "Viper comment must be followed by a directive (basic or strict) or a diagnostic rule", + "viperCommentNotOnOwnLine": "Viper comments used to control file-level settings must appear on their own line", + "viperCommentUnknownDiagnosticRule": "\"{rule}\", viper açıklaması için bilinmeyen bir tanılama kuralı", + "viperCommentUnknownDiagnosticSeverityValue": "\"{value}\" viper açıklaması için geçersiz değer; true, false, error, warning, information veya none bekleniyordu", + "viperCommentUnknownDirective": "\"{directive}\", viper açıklaması için bilinmeyen bir yönergedir; \"strict\", \"standard\" veya \"basic\" bekleniyordu", "readOnlyArgCount": "\"ReadOnly\" sonrasında tek bir tür bağımsız değişken bekleniyordu", "readOnlyNotInTypedDict": "Bu bağlamda \"ReadOnly\" kullanımına izin verilmiyor", "recursiveDefinition": "Kendine başvurduğundan \"{name}\" türü belirlenemedi", @@ -625,8 +625,8 @@ "unnecessaryIsInstanceNever": "Gereksiz isinstance çağrısı; \"{testType}\" asla bir \"{classType}\" örneği değildir", "unnecessaryIsSubclassAlways": "Gereksiz issubclass çağrısı; \"{testType}\" her zaman \"{classType}\" sınıf türünün bir alt sınıfıdır", "unnecessaryIsSubclassNever": "Gereksiz issubclass çağrısı; \"{testType}\" asla \"{classType}\" sınıf türünün bir alt sınıfı değildir", - "unnecessaryPyrightIgnore": "Gereksiz \"# pyright: ignore\" açıklaması", - "unnecessaryPyrightIgnoreRule": "\"# pyright: ignore\" rule: \"{name}\" gereksiz", + "unnecessaryViperIgnore": "Gereksiz \"# viper: ignore\" açıklaması", + "unnecessaryViperIgnoreRule": "\"# viper: ignore\" rule: \"{name}\" gereksiz", "unnecessaryTypeIgnore": "Unnecessary \"# type: ignore\" comment", "unpackArgCount": "\"Unpack\" sonrasında tek bir tür bağımsız değişken bekleniyordu", "unpackExpectedTypeVarTuple": "Unpack için tür bağımsız değişkeni olarak TypeVarTuple veya tuple bekleniyordu", @@ -786,7 +786,7 @@ "protocolRequiresRuntimeCheckable": "Protocol sınıfının örnekle ve sınıf denetimleriyle birlikte kullanılabilmesi için @runtime_checkable olması gerekir", "protocolSourceIsNotConcrete": "\"{sourceType}\" somut bir sınıf türü değil ve \"{destType}\" türüne atanamaz", "protocolUnsafeOverlap": "\"{name}\" öznitelikleri protokolle aynı adlara sahip", - "pyrightCommentIgnoreTip": "Tek bir satırda tanılamayı durdurmak için \"# pyright: ignore[]\" kullanın", + "viperCommentIgnoreTip": "Tek bir satırda tanılamayı durdurmak için \"# viper: ignore[]\" kullanın", "readOnlyAttribute": "\"{name}\" özniteliği salt okunur", "seeClassDeclaration": "Sınıf bildirimine bakın", "seeDeclaration": "Bildirime bakın", diff --git a/packages/vipeye-internal/src/localization/package.nls.zh-cn.json b/packages/vipeye-internal/src/localization/package.nls.zh-cn.json index 059249e7..6c063628 100644 --- a/packages/vipeye-internal/src/localization/package.nls.zh-cn.json +++ b/packages/vipeye-internal/src/localization/package.nls.zh-cn.json @@ -429,13 +429,13 @@ "protocolVarianceContravariant": "泛型 Protocol \"{class}\" 中使用的类型变量 \"{variable}\" 应为反变量", "protocolVarianceCovariant": "泛型 Protocol \"{class}\" 中使用的类型变量 \"{variable}\" 应为共变量", "protocolVarianceInvariant": "泛型 Protocol \"{class}\" 中使用的类型变量 \"{variable}\" 应为固定变量", - "pyrightCommentInvalidDiagnosticBoolValue": "Pyright 注释指令后面必须跟有“=”和 true 或 false 值", - "pyrightCommentInvalidDiagnosticSeverityValue": "Pyright 注释指令后面必须跟有“=”,并且值为 true、false、error、warning、information 或 none", - "pyrightCommentMissingDirective": "Pyright 注释后面必须是指令(basic 或 strict)或诊断规则", - "pyrightCommentNotOnOwnLine": "用于控制文件级设置的 Pyright 注释必须显示在其自己的行上", - "pyrightCommentUnknownDiagnosticRule": "“{rule}”是 pyright 注释的未知诊断规则", - "pyrightCommentUnknownDiagnosticSeverityValue": "\"{value}\"是 pyright 注释的无效值;应为 true、false、error、warning、information 或 none", - "pyrightCommentUnknownDirective": "“{directive}”是 pyright 注释的未知指令;应为 \"strict\"、\"standard\" 或 \"basic\"", + "viperCommentInvalidDiagnosticBoolValue": "Viper 注释指令后面必须跟有“=”和 true 或 false 值", + "viperCommentInvalidDiagnosticSeverityValue": "Viper 注释指令后面必须跟有“=”,并且值为 true、false、error、warning、information 或 none", + "viperCommentMissingDirective": "Viper 注释后面必须是指令(basic 或 strict)或诊断规则", + "viperCommentNotOnOwnLine": "用于控制文件级设置的 Viper 注释必须显示在其自己的行上", + "viperCommentUnknownDiagnosticRule": "“{rule}”是 viper 注释的未知诊断规则", + "viperCommentUnknownDiagnosticSeverityValue": "\"{value}\"是 viper 注释的无效值;应为 true、false、error、warning、information 或 none", + "viperCommentUnknownDirective": "“{directive}”是 viper 注释的未知指令;应为 \"strict\"、\"standard\" 或 \"basic\"", "readOnlyArgCount": "“ReadOnly”后应为单个类型参数", "readOnlyNotInTypedDict": "此上下文中不允许使用“ReadOnly”", "recursiveDefinition": "无法确定“{name}”的类型,因为它引用其自身", @@ -625,8 +625,8 @@ "unnecessaryIsInstanceNever": "不必要的 isinstance 调用;“{testType}”始终不是“{classType}”的实例", "unnecessaryIsSubclassAlways": "不必要的 issubclass 调用;“{testType}”始终是“{classType}”的子类", "unnecessaryIsSubclassNever": "不必要的 issubclass 调用;“{testType}”始终不是“{classType}”的子类", - "unnecessaryPyrightIgnore": "不必要的 \"# pyright: ignore\" 注释", - "unnecessaryPyrightIgnoreRule": "不必要的 \"# pyright: ignore\"规则: \"{name}\"", + "unnecessaryViperIgnore": "不必要的 \"# viper: ignore\" 注释", + "unnecessaryViperIgnoreRule": "不必要的 \"# viper: ignore\"规则: \"{name}\"", "unnecessaryTypeIgnore": "不必要的 \"# type: ignore\" 注释", "unpackArgCount": "\"Unpack\"后应为单个类型参数", "unpackExpectedTypeVarTuple": "Unpack 预期接收 TypeVarTuple 或 tuple 作为类型参数", @@ -786,7 +786,7 @@ "protocolRequiresRuntimeCheckable": "Protocol 类必须为 @runtime_checkable 才能用于实例和类检查", "protocolSourceIsNotConcrete": "“{sourceType}”不是具体类类型,无法分配给类型“{destType}”", "protocolUnsafeOverlap": "“{name}”的属性与协议具有相同的名称", - "pyrightCommentIgnoreTip": "使用 \"# pyright: ignore[]\" 抑制单行诊断", + "viperCommentIgnoreTip": "使用 \"# viper: ignore[]\" 抑制单行诊断", "readOnlyAttribute": "属性“{name}”为只读", "seeClassDeclaration": "查看类声明", "seeDeclaration": "参见声明", diff --git a/packages/vipeye-internal/src/localization/package.nls.zh-tw.json b/packages/vipeye-internal/src/localization/package.nls.zh-tw.json index 79db17a3..cd6435e3 100644 --- a/packages/vipeye-internal/src/localization/package.nls.zh-tw.json +++ b/packages/vipeye-internal/src/localization/package.nls.zh-tw.json @@ -429,13 +429,13 @@ "protocolVarianceContravariant": "一般 Protocol \"{class}\" 中使用的類別變數 \"{variable}\" 必須為逆變數", "protocolVarianceCovariant": "一般 Protocol \"{class}\" 中使用的類型變數 \"{variable}\" 必須為共變數", "protocolVarianceInvariant": "一般 Protocol \"{class}\" 中使用的類別變數 \"{variable}\" 必須為不變數", - "pyrightCommentInvalidDiagnosticBoolValue": "Pyright 註解指示詞後面必須接著 \"=\",且值為 true 或 false", - "pyrightCommentInvalidDiagnosticSeverityValue": "Pyright 註解指示詞後面必須接著 \"=\",且值為 true、false、error、warning、information 或 none", - "pyrightCommentMissingDirective": "Pyright 註解後面必須接著指示詞 (basic 或 strict) 或診斷規則", - "pyrightCommentNotOnOwnLine": "用來控制檔案層級設定的 Pyright 註解必須出現在自己的行上", - "pyrightCommentUnknownDiagnosticRule": "\"{rule}\" 是 pyright 註解未知的診斷規則", - "pyrightCommentUnknownDiagnosticSeverityValue": "\"{value}\" 是 pyright 註解無效的值; 預期為 true、false、error、warning、information 或 none", - "pyrightCommentUnknownDirective": "\"{directive}\" 是 pyright 註解未知的指示詞; 預期為 \"strict\"、\"standard\" 或 \"basic\"", + "viperCommentInvalidDiagnosticBoolValue": "Viper 註解指示詞後面必須接著 \"=\",且值為 true 或 false", + "viperCommentInvalidDiagnosticSeverityValue": "Viper 註解指示詞後面必須接著 \"=\",且值為 true、false、error、warning、information 或 none", + "viperCommentMissingDirective": "Viper 註解後面必須接著指示詞 (basic 或 strict) 或診斷規則", + "viperCommentNotOnOwnLine": "用來控制檔案層級設定的 Viper 註解必須出現在自己的行上", + "viperCommentUnknownDiagnosticRule": "\"{rule}\" 是 viper 註解未知的診斷規則", + "viperCommentUnknownDiagnosticSeverityValue": "\"{value}\" 是 viper 註解無效的值; 預期為 true、false、error、warning、information 或 none", + "viperCommentUnknownDirective": "\"{directive}\" 是 viper 註解未知的指示詞; 預期為 \"strict\"、\"standard\" 或 \"basic\"", "readOnlyArgCount": "\"ReadOnly\" 後面應有單一型別引數", "readOnlyNotInTypedDict": "此內容中不允許 \"ReadOnly\"", "recursiveDefinition": "無法判斷 \"{name}\" 型別,因為它參照了自己", @@ -625,8 +625,8 @@ "unnecessaryIsInstanceNever": "不必要的 isinstance 呼叫; \"{testType}\" 永遠不是 \"{classType}\" 的執行個體", "unnecessaryIsSubclassAlways": "不必要的 issubclass 呼叫; \"{testType}\"永遠是 \"{classType}\" 的子類別", "unnecessaryIsSubclassNever": "不必要的 issubclass 呼叫; \"{testType}\"永遠不是 \"{classType}\" 的子類別", - "unnecessaryPyrightIgnore": "不必要的 \"# pyright: ignore\" 註解", - "unnecessaryPyrightIgnoreRule": "不必要的 \"# pyright: ignore\" 規則: \"{name}\"", + "unnecessaryViperIgnore": "不必要的 \"# viper: ignore\" 註解", + "unnecessaryViperIgnoreRule": "不必要的 \"# viper: ignore\" 規則: \"{name}\"", "unnecessaryTypeIgnore": "不必要的 \"# type: ignore\" 註解", "unpackArgCount": "\"Unpack\" 後面應為單一型別引數", "unpackExpectedTypeVarTuple": "預期 TypeVarTuple 或 tuple 作為 Unpack 的類型引數", @@ -786,7 +786,7 @@ "protocolRequiresRuntimeCheckable": "Protocol 類別必須為 @runtime_checkable,才能搭配執行個體和類別檢查使用", "protocolSourceIsNotConcrete": "\"{sourceType}\" 不是實體類別型別,因此無法指派給型別 \"{destType}\"", "protocolUnsafeOverlap": "\"{name}\" 的屬性與通訊協定的名稱相同", - "pyrightCommentIgnoreTip": "使用 \"# pyright: ignore[]\" 來隱藏單行的診斷", + "viperCommentIgnoreTip": "使用 \"# viper: ignore[]\" 來隱藏單行的診斷", "readOnlyAttribute": "屬性 \"{name}\" 為唯讀", "seeClassDeclaration": "請參閱類別宣告", "seeDeclaration": "請參閱宣告", diff --git a/packages/vipeye-internal/src/nodeMain.ts b/packages/vipeye-internal/src/nodeMain.ts index 9c680d08..24bed63b 100644 --- a/packages/vipeye-internal/src/nodeMain.ts +++ b/packages/vipeye-internal/src/nodeMain.ts @@ -9,11 +9,11 @@ import { BackgroundAnalysisRunner } from './backgroundAnalysis'; import { ServiceProvider } from './common/serviceProvider'; import { run } from './nodeServer'; -import { PyrightServer } from './server'; +import { ViperServer } from './server'; export async function main(maxWorkers: number) { await run( - (conn) => new PyrightServer(conn, maxWorkers), + (conn) => new ViperServer(conn, maxWorkers), () => { const runner = new BackgroundAnalysisRunner(new ServiceProvider()); runner.start(); diff --git a/packages/vipeye-internal/src/parser/tokenizer.ts b/packages/vipeye-internal/src/parser/tokenizer.ts index 468e9d07..6ee87d42 100644 --- a/packages/vipeye-internal/src/parser/tokenizer.ts +++ b/packages/vipeye-internal/src/parser/tokenizer.ts @@ -416,9 +416,9 @@ function parseIgnoreBracketContent( return undefined; } -// Manual replacement for typeIgnoreCommentRegEx / pyrightIgnoreCommentRegEx. +// Manual replacement for typeIgnoreCommentRegEx / viperIgnoreCommentRegEx. // Scans `text` within [rangeStart, rangeEnd) for `: ignore [rules]` -// where directive is 'type' or 'pyright'. +// where directive is 'type' or 'viper'. // Returns a match object or undefined. Returned `index` is absolute within `text`. function matchIgnoreDirective( text: string, @@ -429,7 +429,7 @@ function matchIgnoreDirective( // The directive can be preceded by optional `#` and whitespace, or // appear at the start of the range with optional whitespace. // type: ignore allows tool-namespaced codes (e.g. "ty:rule-name") in brackets; - // pyright: ignore does not. + // viper: ignore does not. const allowColonInBracket = directive === 'type'; let searchFrom = rangeStart; @@ -581,8 +581,8 @@ export interface TokenizerOutput { // Map of all line numbers that end in a "type: ignore" comment. typeIgnoreLines: Map; - // Map of all line numbers that end in a "pyright: ignore" comment. - pyrightIgnoreLines: Map; + // Map of all line numbers that end in a "viper: ignore" comment. + viperIgnoreLines: Map; // Program starts with a "type: ignore" comment. typeIgnoreAll: IgnoreComment | undefined; @@ -654,7 +654,7 @@ export class Tokenizer { // stream consists purely of NewLine / Indent tokens. private _hasTokenBeforeIgnoreAll = false; private _typeIgnoreLines = new Map(); - private _pyrightIgnoreLines = new Map(); + private _viperIgnoreLines = new Map(); private _comments: Comment[] | undefined; private _fStringStack: FStringContext[] = []; private _activeFString: FStringContext | undefined; @@ -812,7 +812,7 @@ export class Tokenizer { lines: new TextRangeCollection(this._lineRanges), typeIgnoreLines: this._typeIgnoreLines, typeIgnoreAll: this._typeIgnoreAll, - pyrightIgnoreLines: this._pyrightIgnoreLines, + viperIgnoreLines: this._viperIgnoreLines, predominantEndOfLineSequence, hasPredominantTabSequence, predominantTabSequence, @@ -1793,18 +1793,18 @@ export class Tokenizer { } } - const pyrightIgnoreMatch = matchIgnoreDirective(sourceText, start, end, 'pyright'); - if (pyrightIgnoreMatch) { - const commentStart = pyrightIgnoreMatch.index; + const legacyIgnoreMatch = matchIgnoreDirective(sourceText, start, end, 'pyright'); + if (legacyIgnoreMatch) { + const commentStart = legacyIgnoreMatch.index; const textRange: TextRange = { - start: commentStart + pyrightIgnoreMatch.prefix.length, - length: pyrightIgnoreMatch.fullMatch.length - pyrightIgnoreMatch.prefix.length, + start: commentStart + legacyIgnoreMatch.prefix.length, + length: legacyIgnoreMatch.fullMatch.length - legacyIgnoreMatch.prefix.length, }; const ignoreComment: IgnoreComment = { range: textRange, - rulesList: this._getIgnoreCommentRulesList(commentStart, pyrightIgnoreMatch), + rulesList: this._getIgnoreCommentRulesList(commentStart, legacyIgnoreMatch), }; - this._pyrightIgnoreLines.set(this._lineRanges.length, ignoreComment); + this._viperIgnoreLines.set(this._lineRanges.length, ignoreComment); } // 同时支持 "# viper: ignore" 注释指令(与 "# pyright: ignore" 等价)。 @@ -1819,7 +1819,7 @@ export class Tokenizer { range: textRange, rulesList: this._getIgnoreCommentRulesList(commentStart, viperIgnoreMatch), }; - this._pyrightIgnoreLines.set(this._lineRanges.length, ignoreComment); + this._viperIgnoreLines.set(this._lineRanges.length, ignoreComment); } } diff --git a/packages/vipeye-internal/src/pprof/profiler.ts b/packages/vipeye-internal/src/pprof/profiler.ts index ff938d86..18749092 100644 --- a/packages/vipeye-internal/src/pprof/profiler.ts +++ b/packages/vipeye-internal/src/pprof/profiler.ts @@ -1,5 +1,5 @@ /** - * Functions used for running pyright with pprof. + * Functions used for running viper with pprof. * * Steps taken to get this to work: * - Install VC++ Desktop C++ workload with at least one Windows SDK @@ -16,7 +16,7 @@ ○ It should be named something like bin\win32-x64-110\pprof-nodejs.node ○ Copy it to the node_modules\@datadog\pprof\prebuilds\win32-x64 ○ Rename it to electron-110.node (or whatever ABI version it is using) - - Modify pylance to use pprof around problem location using the pyright\packages\vipeye-internal\pprof\profiler.ts + - Modify pylance to use pprof around problem location using the viper\packages\vipeye-internal\pprof\profiler.ts ○ startProfile before ○ finishProfile after, passing it a file name - Rebuild Pylance diff --git a/packages/vipeye-internal/src/server.ts b/packages/vipeye-internal/src/server.ts index 621627c6..d05e8d75 100644 --- a/packages/vipeye-internal/src/server.ts +++ b/packages/vipeye-internal/src/server.ts @@ -1,7 +1,7 @@ /* * server.ts * - * Implements pyright language server. + * Implements viper language server. */ import { @@ -39,13 +39,13 @@ import { Uri } from './common/uri/uri'; import { getRootUri } from './common/uri/uriUtils'; import { LanguageServerBase } from './languageServerBase'; import { CodeActionProvider } from './languageService/codeActionProvider'; -import { PyrightFileSystem } from './pyrightFileSystem'; +import { ViperFileSystem } from './viperFileSystem'; import { WellKnownWorkspaceKinds, Workspace } from './workspaceFactory'; import { PartialStubService } from './partialStubService'; const maxAnalysisTimeInForeground = { openFilesTimeInMs: 50, noOpenFilesTimeInMs: 200 }; -export class PyrightServer extends LanguageServerBase { +export class ViperServer extends LanguageServerBase { private _controller: CommandController; constructor(connection: Connection, maxWorkers: number, realFileSystem?: FileSystem) { @@ -56,12 +56,12 @@ export class PyrightServer extends LanguageServerBase { const console = new ConsoleWithLogLevel(connection.console); const fileWatcherProvider = new WorkspaceFileWatcherProvider(); const fileSystem = realFileSystem ?? createFromRealFileSystem(tempFile, console, fileWatcherProvider); - const pyrightFs = new PyrightFileSystem(fileSystem); + const viperFs = new ViperFileSystem(fileSystem); const cacheManager = new CacheManager(maxWorkers); - const partialStubService = new PartialStubService(pyrightFs); + const partialStubService = new PartialStubService(viperFs); const serviceProvider = createServiceProvider( - pyrightFs, + viperFs, tempFile, console, cacheManager, @@ -69,15 +69,15 @@ export class PyrightServer extends LanguageServerBase { new FileBasedCancellationProvider('bg') ); - // When executed from CLI command (pyright-langserver), __rootDirectory is + // When executed from CLI command (vipeye-langserver), __rootDirectory is // already defined. When executed from VSCode extension, rootDirectory should // be __dirname. const rootDirectory: Uri = getRootUri(serviceProvider) || Uri.file(__dirname, serviceProvider); - const realPathRoot = pyrightFs.realCasePath(rootDirectory); + const realPathRoot = viperFs.realCasePath(rootDirectory); super( { - productName: 'Pyright', + productName: 'Vipeye', rootDirectory: realPathRoot, version, serviceProvider, @@ -267,7 +267,7 @@ export class PyrightServer extends LanguageServerBase { }) .catch(() => {}); } else { - this.connection.sendNotification('pyright/beginProgress'); + this.connection.sendNotification('viper/beginProgress'); } }, report: (message: string) => { @@ -278,7 +278,7 @@ export class PyrightServer extends LanguageServerBase { }) .catch(() => {}); } else { - this.connection.sendNotification('pyright/reportProgress', message); + this.connection.sendNotification('viper/reportProgress', message); } }, end: () => { @@ -291,7 +291,7 @@ export class PyrightServer extends LanguageServerBase { .catch(() => {}); workDoneProgress = undefined; } else { - this.connection.sendNotification('pyright/endProgress'); + this.connection.sendNotification('viper/endProgress'); } }, }; diff --git a/packages/vipeye-internal/src/tests/benchmarkData/comment_heavy.py b/packages/vipeye-internal/src/tests/benchmarkData/comment_heavy.py index a855a3f3..2607f327 100644 --- a/packages/vipeye-internal/src/tests/benchmarkData/comment_heavy.py +++ b/packages/vipeye-internal/src/tests/benchmarkData/comment_heavy.py @@ -23,20 +23,20 @@ x13 = yet_another # type: ignore[name-defined] # --- pyright: ignore variants --- -y1: int = "not_int" # pyright: ignore -y2: str = 42 # pyright: ignore -y3: float = "nope" # pyright: ignore -y4: bool = 123 # pyright: ignore -y5: bytes = 456 # pyright: ignore +y1: int = "not_int" # viper: ignore +y2: str = 42 # viper: ignore +y3: float = "nope" # viper: ignore +y4: bool = 123 # viper: ignore +y5: bytes = 456 # viper: ignore -y6: int = "a" # pyright: ignore[reportAssignmentType] -y7: str = 1 # pyright: ignore[reportAssignmentType] -y8: float = True # pyright: ignore[reportAssignmentType] -y9: bool = None # pyright: ignore[reportAssignmentType] -y10: bytes = [] # pyright: ignore[reportAssignmentType] +y6: int = "a" # viper: ignore[reportAssignmentType] +y7: str = 1 # viper: ignore[reportAssignmentType] +y8: float = True # viper: ignore[reportAssignmentType] +y9: bool = None # viper: ignore[reportAssignmentType] +y10: bytes = [] # viper: ignore[reportAssignmentType] -y11: int = "str" # pyright: ignore[reportAssignmentType, reportGeneralClassIssues] -y12: str = 42 # pyright: ignore[reportAssignmentType, reportGeneralClassIssues] +y11: int = "str" # viper: ignore[reportAssignmentType, reportGeneralClassIssues] +y12: str = 42 # viper: ignore[reportAssignmentType, reportGeneralClassIssues] # --- noqa comments --- @@ -52,8 +52,8 @@ import io # noqa z1: int = "str" # type: ignore # noqa: F841 z2: str = 42 # type: ignore[assignment] # noqa z3 = undefined # type: ignore[name-defined] # noqa: F821 -z4: int = "nope" # pyright: ignore # noqa: F841 -z5: int = "nope" # pyright: ignore[reportAssignmentType] # noqa +z4: int = "nope" # viper: ignore # noqa: F841 +z5: int = "nope" # viper: ignore[reportAssignmentType] # noqa # --- Regular comments (should be fast-rejected by directive scanner) --- @@ -64,7 +64,7 @@ z5: int = "nope" # pyright: ignore[reportAssignmentType] # noqa # Regular comment mentioning ignore but not as a directive # A comment that says "type" but is not a type: ignore # type: This looks similar but is not a valid directive -# pyright: This also looks similar but is not valid +# viper: This also looks similar but is not valid # --- Doc comments (hash-prefixed) --- @@ -110,14 +110,14 @@ def another_poorly_typed(x, y, z): # type: ignore class IgnoredClass: - x: int = "not_int" # pyright: ignore[reportAssignmentType] - y: str = 42 # pyright: ignore[reportAssignmentType] + x: int = "not_int" # viper: ignore[reportAssignmentType] + y: str = 42 # viper: ignore[reportAssignmentType] def __init__(self) -> None: - self.a: int = "str" # pyright: ignore[reportAssignmentType] - self.b: str = 42 # pyright: ignore[reportAssignmentType] - self.c: float = "3.14" # pyright: ignore[reportAssignmentType] - self.d: bool = "True" # pyright: ignore[reportAssignmentType] + self.a: int = "str" # viper: ignore[reportAssignmentType] + self.b: str = 42 # viper: ignore[reportAssignmentType] + self.c: float = "3.14" # viper: ignore[reportAssignmentType] + self.d: bool = "True" # viper: ignore[reportAssignmentType] def method1(self) -> int: # type: ignore return "not_int" # type: ignore @@ -164,16 +164,16 @@ def bulk_ignores_1(): v8 = undefined_8 # type: ignore[name-defined] v9 = undefined_9 # type: ignore[name-defined] v10 = undefined_10 # type: ignore[name-defined] - v11 = undefined_11 # pyright: ignore[reportUndefinedVariable] - v12 = undefined_12 # pyright: ignore[reportUndefinedVariable] - v13 = undefined_13 # pyright: ignore[reportUndefinedVariable] - v14 = undefined_14 # pyright: ignore[reportUndefinedVariable] - v15 = undefined_15 # pyright: ignore[reportUndefinedVariable] - v16 = undefined_16 # pyright: ignore[reportUndefinedVariable] - v17 = undefined_17 # pyright: ignore[reportUndefinedVariable] - v18 = undefined_18 # pyright: ignore[reportUndefinedVariable] - v19 = undefined_19 # pyright: ignore[reportUndefinedVariable] - v20 = undefined_20 # pyright: ignore[reportUndefinedVariable] + v11 = undefined_11 # viper: ignore[reportUndefinedVariable] + v12 = undefined_12 # viper: ignore[reportUndefinedVariable] + v13 = undefined_13 # viper: ignore[reportUndefinedVariable] + v14 = undefined_14 # viper: ignore[reportUndefinedVariable] + v15 = undefined_15 # viper: ignore[reportUndefinedVariable] + v16 = undefined_16 # viper: ignore[reportUndefinedVariable] + v17 = undefined_17 # viper: ignore[reportUndefinedVariable] + v18 = undefined_18 # viper: ignore[reportUndefinedVariable] + v19 = undefined_19 # viper: ignore[reportUndefinedVariable] + v20 = undefined_20 # viper: ignore[reportUndefinedVariable] return None @@ -189,16 +189,16 @@ def bulk_ignores_2(): a8: tuple = False # type: ignore[assignment] a9: set = 3.14 # type: ignore[assignment] a10: int = None # type: ignore[assignment] - b1: int = "wrong" # pyright: ignore[reportAssignmentType] - b2: str = 42 # pyright: ignore[reportAssignmentType] - b3: float = True # pyright: ignore[reportAssignmentType] - b4: bool = 3.14 # pyright: ignore[reportAssignmentType] - b5: bytes = None # pyright: ignore[reportAssignmentType] - b6: list = 42 # pyright: ignore[reportAssignmentType] - b7: dict = "str" # pyright: ignore[reportAssignmentType] - b8: tuple = False # pyright: ignore[reportAssignmentType] - b9: set = 3.14 # pyright: ignore[reportAssignmentType] - b10: int = None # pyright: ignore[reportAssignmentType] + b1: int = "wrong" # viper: ignore[reportAssignmentType] + b2: str = 42 # viper: ignore[reportAssignmentType] + b3: float = True # viper: ignore[reportAssignmentType] + b4: bool = 3.14 # viper: ignore[reportAssignmentType] + b5: bytes = None # viper: ignore[reportAssignmentType] + b6: list = 42 # viper: ignore[reportAssignmentType] + b7: dict = "str" # viper: ignore[reportAssignmentType] + b8: tuple = False # viper: ignore[reportAssignmentType] + b9: set = 3.14 # viper: ignore[reportAssignmentType] + b10: int = None # viper: ignore[reportAssignmentType] return None diff --git a/packages/vipeye-internal/src/tests/benchmarks/parserBenchmark.test.ts b/packages/vipeye-internal/src/tests/benchmarks/parserBenchmark.test.ts index 06450c89..c779b5ad 100644 --- a/packages/vipeye-internal/src/tests/benchmarks/parserBenchmark.test.ts +++ b/packages/vipeye-internal/src/tests/benchmarks/parserBenchmark.test.ts @@ -6,7 +6,7 @@ * Measures nodes/sec, parse time, AST node count across representative corpora. * * Run with: - * cd packages/pyright/packages/vipeye-internal + * cd packages/vipeye/packages/vipeye-internal * node node_modules\jest\bin\jest parserBenchmark.test --runInBand --detectOpenHandles --forceExit --testTimeout=300000 * * Results are written as JSON to: @@ -139,7 +139,7 @@ function printResultTable(results: ReadonlyArray): void { /** * Count all AST nodes by walking the tree recursively. - * Pyright parse nodes have: { nodeType, d: { ...children }, ... } + * Vipeye parse nodes have: { nodeType, d: { ...children }, ... } */ function countNodes(node: any): number { if (!node || typeof node !== 'object' || !('nodeType' in node)) { diff --git a/packages/vipeye-internal/src/tests/benchmarks/tokenizerBenchmark.test.ts b/packages/vipeye-internal/src/tests/benchmarks/tokenizerBenchmark.test.ts index 7cff51ea..d794c5ef 100644 --- a/packages/vipeye-internal/src/tests/benchmarks/tokenizerBenchmark.test.ts +++ b/packages/vipeye-internal/src/tests/benchmarks/tokenizerBenchmark.test.ts @@ -28,8 +28,8 @@ const BENCHMARK_ITERATIONS = 10; const BENCHMARK_OUTPUT_DIR = path.join(__dirname, '.generated', 'benchmark-results', 'tokenizer'); const JEST_BIN_PATH = path.resolve(__dirname, '..', '..', '..', 'node_modules', 'jest', 'bin', 'jest.js'); const CHILD_RESULT_PREFIX = '__TOKENIZER_BENCHMARK_RESULT__'; -const CHILD_MODE_ENV = 'PYRIGHT_TOKENIZER_BENCH_CHILD'; -const RUN_BENCHMARKS_ENV = 'PYRIGHT_RUN_BENCHMARKS'; +const CHILD_MODE_ENV = 'VIPER_TOKENIZER_BENCH_CHILD'; +const RUN_BENCHMARKS_ENV = 'VIPER_RUN_BENCHMARKS'; // --- Types --- diff --git a/packages/vipeye-internal/src/tests/checker.test.ts b/packages/vipeye-internal/src/tests/checker.test.ts index 75c25ecc..b7bcdd9f 100644 --- a/packages/vipeye-internal/src/tests/checker.test.ts +++ b/packages/vipeye-internal/src/tests/checker.test.ts @@ -4,7 +4,7 @@ * Licensed under the MIT license. * Author: Eric Traut * - * Unit tests for pyright type checker. These tests also + * Unit tests for viper type checker. These tests also * exercise the type evaluator (which the checker relies * heavily upon). */ @@ -373,28 +373,28 @@ test('TypeIgnore5', () => { TestUtils.validateResults(analysisResults, 0, 1); }); -test('PyrightIgnore1', () => { +test('ViperIgnore1', () => { const configOptions = new ConfigOptions(Uri.empty()); - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['pyrightIgnore1.py'], configOptions); + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['viperIgnore1.py'], configOptions); TestUtils.validateResults(analysisResults, 1); }); -test('PyrightIgnore2', () => { +test('ViperIgnore2', () => { const configOptions = new ConfigOptions(Uri.empty()); - let analysisResults = TestUtils.typeAnalyzeSampleFiles(['pyrightIgnore2.py'], configOptions); + let analysisResults = TestUtils.typeAnalyzeSampleFiles(['viperIgnore2.py'], configOptions); TestUtils.validateResults(analysisResults, 2); configOptions.diagnosticRuleSet.reportUnnecessaryTypeIgnoreComment = 'warning'; - analysisResults = TestUtils.typeAnalyzeSampleFiles(['pyrightIgnore2.py'], configOptions); + analysisResults = TestUtils.typeAnalyzeSampleFiles(['viperIgnore2.py'], configOptions); TestUtils.validateResults(analysisResults, 2, 3); }); -test('PyrightComment1', () => { +test('ViperComment1', () => { const configOptions = new ConfigOptions(Uri.empty()); - const analysisResults = TestUtils.typeAnalyzeSampleFiles(['pyrightComment1.py'], configOptions); + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['viperComment1.py'], configOptions); TestUtils.validateResults(analysisResults, 9); }); diff --git a/packages/vipeye-internal/src/tests/completions.test.ts b/packages/vipeye-internal/src/tests/completions.test.ts index 0c31b840..33be6cb9 100644 --- a/packages/vipeye-internal/src/tests/completions.test.ts +++ b/packages/vipeye-internal/src/tests/completions.test.ts @@ -14,7 +14,7 @@ import { parseAndGetTestState } from './harness/fourslash/testState'; test('completion import statement tooltip', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -46,7 +46,7 @@ test('completion import statement tooltip', async () => { test('completion import statement tooltip - stub file', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -82,7 +82,7 @@ test('completion import statement tooltip - stub file', async () => { test('completion import statement tooltip - doc in stub file', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -118,7 +118,7 @@ test('completion import statement tooltip - doc in stub file', async () => { test('completion import statement tooltip - sub modules', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -154,7 +154,7 @@ test('completion import statement tooltip - sub modules', async () => { test('completion import reference tooltip', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -187,7 +187,7 @@ test('completion import reference tooltip', async () => { test('completion import reference tooltip - first module', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -224,7 +224,7 @@ test('completion import reference tooltip - first module', async () => { test('completion import reference tooltip - child module', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -261,7 +261,7 @@ test('completion import reference tooltip - child module', async () => { test('completion from import statement tooltip - first module', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -293,7 +293,7 @@ test('completion from import statement tooltip - first module', async () => { test('completion from import statement tooltip - child module', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -329,7 +329,7 @@ test('completion from import statement tooltip - child module', async () => { test('completion from import statement tooltip - implicit module', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/config.test.ts b/packages/vipeye-internal/src/tests/config.test.ts index 9c438169..ce6837ed 100644 --- a/packages/vipeye-internal/src/tests/config.test.ts +++ b/packages/vipeye-internal/src/tests/config.test.ts @@ -4,7 +4,7 @@ * Licensed under the MIT license. * Author: Eric Traut * - * Unit tests for parsing of pyrightconfig.json files. + * Unit tests for parsing of viperconfig.json files. */ import assert from 'assert'; @@ -267,7 +267,7 @@ describe(`config test'}`, () => { const nullConsole = new NullConsole(); const service = createAnalyzer(nullConsole); const commandLineOptions = new CommandLineOptions(cwd, /* fromLanguageServer */ false); - commandLineOptions.configFilePath = combinePaths(cwd, 'pyrightconfig.json'); + commandLineOptions.configFilePath = combinePaths(cwd, 'viperconfig.json'); commandLineOptions.configSettings.autoSearchPaths = true; service.setOptions(commandLineOptions); @@ -382,7 +382,7 @@ describe(`config test'}`, () => { assert.equal(service.getConfigOptions().effectiveTypeCheckingMode, 'off'); const pyprojectFileUri = projectRootUri.combinePaths('pyproject.toml'); - fs.writeFileSync(pyprojectFileUri, '[tool.pyright]\ntypeCheckingMode = "strict"\n'); + fs.writeFileSync(pyprojectFileUri, '[tool.viper]\ntypeCheckingMode = "strict"\n'); fs.fireFileWatcherEvent(pyprojectFileUri.getFilePath(), 'add'); assert.equal(service.getConfigOptions().effectiveTypeCheckingMode, 'strict'); @@ -725,7 +725,7 @@ describe(`config test'}`, () => { assert.deepStrictEqual(config.defaultPythonVersion, pythonVersion3_13); }); - test('PyprojectTomlWithoutPyrightSectionFallsBackToAncestorConfig', () => { + test('PyprojectTomlWithoutViperSectionFallsBackToAncestorConfig', () => { const cwd = normalizePath(process.cwd()); const service = createAnalyzer(); const commandLineOptions = new CommandLineOptions(cwd, /* fromLanguageServer */ false); @@ -742,7 +742,7 @@ describe(`config test'}`, () => { ); }); - test('PyprojectTomlWithoutPyrightSectionFallsBackThroughMultipleAncestors', () => { + test('PyprojectTomlWithoutViperSectionFallsBackThroughMultipleAncestors', () => { const cwd = normalizePath(process.cwd()); const service = createAnalyzer(); const commandLineOptions = new CommandLineOptions(cwd, /* fromLanguageServer */ false); @@ -751,7 +751,7 @@ describe(`config test'}`, () => { const configOptions = service.test_getConfigOptions(commandLineOptions); - // Should skip the empty pyproject.tomls and fall back to the root's [tool.pyright]. + // Should skip the empty pyproject.tomls and fall back to the root's [tool.viper]. assert.strictEqual(configOptions.defaultPythonVersion!.toString(), pythonVersion3_9.toString()); assert.ok( configOptions.configFileSource @@ -775,7 +775,7 @@ describe(`config test'}`, () => { const basicDefaults = getBasicDiagnosticRuleSet(); assert.equal(basicDefaults.reportPrivateImportUsage, 'error'); - // Now simulate positional args overriding include (like `pyright --project config.json subdir`). + // Now simulate positional args overriding include (like `viper --project config.json subdir`). const commandLineOptionsWithOverride = new CommandLineOptions(cwd, /* fromLanguageServer */ false); commandLineOptionsWithOverride.configSettings.includeFileSpecsOverride = [combinePaths(cwd, 'subdir')]; service.setOptions(commandLineOptionsWithOverride); diff --git a/packages/vipeye-internal/src/tests/diagnosticOverrides.test.ts b/packages/vipeye-internal/src/tests/diagnosticOverrides.test.ts index 7e5a2938..f0dceb4e 100644 --- a/packages/vipeye-internal/src/tests/diagnosticOverrides.test.ts +++ b/packages/vipeye-internal/src/tests/diagnosticOverrides.test.ts @@ -13,9 +13,9 @@ import * as path from 'path'; import { DiagnosticRule } from '../common/diagnosticRules'; describe('Diagnostic overrides', () => { - test('Compare DiagnosticRule to pyrightconfig.schema.json', () => { - const schemasFolder = path.resolve(__dirname, '..', '..', '..', 'vscode-pyright', 'schemas'); - const schemaJson = path.join(schemasFolder, 'pyrightconfig.schema.json'); + test('Compare DiagnosticRule to vipeyeconfig.schema.json', () => { + const schemasFolder = path.resolve(__dirname, '..', '..', '..', 'vscode-vipeye', 'schemas'); + const schemaJson = path.join(schemasFolder, 'vipeyeconfig.schema.json'); const jsonString = fs.readFileSync(schemaJson, { encoding: 'utf-8' }); const json = JSON.parse(jsonString); @@ -62,7 +62,7 @@ describe('Diagnostic overrides', () => { } }); test('Compare DiagnosticRule to package.json', () => { - const extensionRoot = path.resolve(__dirname, '..', '..', '..', 'vscode-pyright'); + const extensionRoot = path.resolve(__dirname, '..', '..', '..', 'vscode-vipeye'); const packageJson = path.join(extensionRoot, 'package.json'); const jsonString = fs.readFileSync(packageJson, { encoding: 'utf-8' }); const json = JSON.parse(jsonString); diff --git a/packages/vipeye-internal/src/tests/diagnostics.test.ts b/packages/vipeye-internal/src/tests/diagnostics.test.ts index 3a51ff12..8c88a369 100644 --- a/packages/vipeye-internal/src/tests/diagnostics.test.ts +++ b/packages/vipeye-internal/src/tests/diagnostics.test.ts @@ -34,10 +34,10 @@ test('unused import', async () => { }); }); -test('pyright ignore unused import', async () => { +test('viper ignore unused import', async () => { const code = ` // @filename: test1.py -//// from test2 import [|/*marker*/foo|] # pyright: ignore +//// from test2 import [|/*marker*/foo|] # viper: ignore // @filename: test2.py //// def foo(): pass @@ -56,7 +56,7 @@ test('getDiagnosticsForRangeWithoutFileIgnore analyzes the file on demand when i // that serves code-action requests may never have checked the file, leaving its pre-ignore // diagnostics cache empty. The getter must populate that cache on demand. const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "ignore": ["**/test.py"] //// } diff --git a/packages/vipeye-internal/src/tests/docStringConversion.test.ts b/packages/vipeye-internal/src/tests/docStringConversion.test.ts index 0854d461..b6dc83e5 100644 --- a/packages/vipeye-internal/src/tests/docStringConversion.test.ts +++ b/packages/vipeye-internal/src/tests/docStringConversion.test.ts @@ -7,7 +7,7 @@ */ import assert = require('assert'); -import { PyrightDocStringService } from '../common/docStringService'; +import { ViperDocStringService } from '../common/docStringService'; // For substitution in the test data strings // Produces more readable test data than escaping the back ticks @@ -16,7 +16,7 @@ const doubleTick = '``'; const tripleTick = '```'; const tripleTilda = '~~~'; -export function docStringTests(docStringService = new PyrightDocStringService()) { +export function docStringTests(docStringService = new ViperDocStringService()) { test('PlaintextIndention', () => { const all: string[][] = [ ['A\nB', 'A\nB'], diff --git a/packages/vipeye-internal/src/tests/fourslash/completions.autoimport.disabled.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/completions.autoimport.disabled.fourslash.ts index 8d8a775b..266fdffc 100644 --- a/packages/vipeye-internal/src/tests/fourslash/completions.autoimport.disabled.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/completions.autoimport.disabled.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "autoImportCompletions": false //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/completions.classVariable.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/completions.classVariable.fourslash.ts index 695faa8d..d17566d5 100644 --- a/packages/vipeye-internal/src/tests/fourslash/completions.classVariable.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/completions.classVariable.fourslash.ts @@ -1,5 +1,5 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "pythonVersion": "3.11" //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/completions.import.submodule.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/completions.import.submodule.fourslash.ts index 686b3ed5..233447f2 100644 --- a/packages/vipeye-internal/src/tests/fourslash/completions.import.submodule.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/completions.import.submodule.fourslash.ts @@ -3,7 +3,7 @@ // @filename: test.py //// from submodule.[|/*marker1*/|] -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "extraPaths": ["submodule"] //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/completions.inherited.property.docFromSrc.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/completions.inherited.property.docFromSrc.fourslash.ts index c35a5345..dd8b5c01 100644 --- a/packages/vipeye-internal/src/tests/fourslash/completions.inherited.property.docFromSrc.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/completions.inherited.property.docFromSrc.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/completions.inherited.property.docFromStub.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/completions.inherited.property.docFromStub.fourslash.ts index 3723841d..068f4238 100644 --- a/packages/vipeye-internal/src/tests/fourslash/completions.inherited.property.docFromStub.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/completions.inherited.property.docFromStub.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/completions.keywords.pythonVersion.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/completions.keywords.pythonVersion.fourslash.ts index 7004e2b7..1b407d6b 100644 --- a/packages/vipeye-internal/src/tests/fourslash/completions.keywords.pythonVersion.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/completions.keywords.pythonVersion.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "executionEnvironments": [ //// { "root": "python33", "pythonVersion": "3.3" }, diff --git a/packages/vipeye-internal/src/tests/fourslash/completions.libCodeAndStub.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/completions.libCodeAndStub.fourslash.ts index 11d6d332..9250c05a 100644 --- a/packages/vipeye-internal/src/tests/fourslash/completions.libCodeAndStub.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/completions.libCodeAndStub.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/completions.libCodeNoStub.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/completions.libCodeNoStub.fourslash.ts index 3b5c74f9..e986e40f 100644 --- a/packages/vipeye-internal/src/tests/fourslash/completions.libCodeNoStub.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/completions.libCodeNoStub.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/completions.libStub.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/completions.libStub.fourslash.ts index 50ed4320..7cdc84b2 100644 --- a/packages/vipeye-internal/src/tests/fourslash/completions.libStub.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/completions.libStub.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/completions.moduleContext.libCodeNoStub.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/completions.moduleContext.libCodeNoStub.fourslash.ts index 07b315b0..a280754c 100644 --- a/packages/vipeye-internal/src/tests/fourslash/completions.moduleContext.libCodeNoStub.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/completions.moduleContext.libCodeNoStub.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/completions.propertyDocStrings.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/completions.propertyDocStrings.fourslash.ts index e1591c66..a926b8fb 100644 --- a/packages/vipeye-internal/src/tests/fourslash/completions.propertyDocStrings.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/completions.propertyDocStrings.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/completions.wildcardimports.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/completions.wildcardimports.fourslash.ts index e9a58a1f..147a4e30 100644 --- a/packages/vipeye-internal/src/tests/fourslash/completions.wildcardimports.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/completions.wildcardimports.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.classes.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.classes.fourslash.ts index 09d749a4..15aef34c 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.classes.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.classes.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.fields.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.fields.fourslash.ts index aa0947f2..64de4d03 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.fields.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.fields.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.functions.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.functions.fourslash.ts index 17569288..8a1e902c 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.functions.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.functions.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.methods.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.methods.fourslash.ts index 8dc14248..60a13a88 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.methods.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.methods.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.namespaceImport.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.namespaceImport.fourslash.ts index 291b9713..c015f44e 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.namespaceImport.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.namespaceImport.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "extraPaths": ["subproj"] //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.namespaceImportWithInit.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.namespaceImportWithInit.fourslash.ts index fa3e7044..f0dcebec 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.namespaceImportWithInit.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.namespaceImportWithInit.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true, //// "executionEnvironments": [{ "root": "."}], diff --git a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.parameters.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.parameters.fourslash.ts index ac188827..48264c29 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.parameters.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.parameters.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.sourceOnly.class.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.sourceOnly.class.fourslash.ts index e08f0555..bff1f92e 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.sourceOnly.class.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.sourceOnly.class.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.sourceOnly.function1.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.sourceOnly.function1.fourslash.ts index 62b6e395..640f53c2 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.sourceOnly.function1.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.sourceOnly.function1.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.sourceOnly.function2.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.sourceOnly.function2.fourslash.ts index bc048363..094e04ce 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.sourceOnly.function2.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.sourceOnly.function2.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.stubPackages.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.stubPackages.fourslash.ts index bcf3b3a1..3a34b42c 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.stubPackages.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.stubPackages.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.variables.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.variables.fourslash.ts index 99b682d4..07d30f32 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.variables.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.variables.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.wildcardimports.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.wildcardimports.fourslash.ts index 18b80139..867aa751 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findDefinitions.wildcardimports.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findDefinitions.wildcardimports.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findTypeDefinitions.classes.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findTypeDefinitions.classes.fourslash.ts index 7c319e75..885149d4 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findTypeDefinitions.classes.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findTypeDefinitions.classes.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findallreferences.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findallreferences.fourslash.ts index d862ca4b..0cf0902a 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findallreferences.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findallreferences.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findallreferences.importalias.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findallreferences.importalias.fourslash.ts index 21fd8d94..f530658d 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findallreferences.importalias.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findallreferences.importalias.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findallreferences.invokedFromLibrary.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findallreferences.invokedFromLibrary.fourslash.ts index c53ee5f8..2c6756b9 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findallreferences.invokedFromLibrary.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findallreferences.invokedFromLibrary.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/findallreferences.openFiles.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/findallreferences.openFiles.fourslash.ts index 2ce3364e..f7dece73 100644 --- a/packages/vipeye-internal/src/tests/fourslash/findallreferences.openFiles.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/findallreferences.openFiles.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/hover.class.docString.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/hover.class.docString.fourslash.ts index d6cdfa68..30df4d16 100644 --- a/packages/vipeye-internal/src/tests/fourslash/hover.class.docString.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/hover.class.docString.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/hover.docFromSrc.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/hover.docFromSrc.fourslash.ts index e41be4ec..8b4a9de6 100644 --- a/packages/vipeye-internal/src/tests/fourslash/hover.docFromSrc.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/hover.docFromSrc.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/hover.formatted.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/hover.formatted.fourslash.ts index 45b75099..0f2b51b0 100644 --- a/packages/vipeye-internal/src/tests/fourslash/hover.formatted.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/hover.formatted.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "functionSignatureDisplay": "formatted" //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/hover.inherited.property.docFromSrcWithStub.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/hover.inherited.property.docFromSrcWithStub.fourslash.ts index 51e089e8..86c23aff 100644 --- a/packages/vipeye-internal/src/tests/fourslash/hover.inherited.property.docFromSrcWithStub.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/hover.inherited.property.docFromSrcWithStub.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/hover.inherited.property.docFromStub.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/hover.inherited.property.docFromStub.fourslash.ts index f6411280..b2fe96db 100644 --- a/packages/vipeye-internal/src/tests/fourslash/hover.inherited.property.docFromStub.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/hover.inherited.property.docFromStub.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/hover.libCodeAndStub.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/hover.libCodeAndStub.fourslash.ts index 8d2551e4..15a63a9d 100644 --- a/packages/vipeye-internal/src/tests/fourslash/hover.libCodeAndStub.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/hover.libCodeAndStub.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/hover.libCodeNoStub.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/hover.libCodeNoStub.fourslash.ts index 25d35343..c1a8b1e3 100644 --- a/packages/vipeye-internal/src/tests/fourslash/hover.libCodeNoStub.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/hover.libCodeNoStub.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/hover.libStub.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/hover.libStub.fourslash.ts index 3b8968e4..a4dc480d 100644 --- a/packages/vipeye-internal/src/tests/fourslash/hover.libStub.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/hover.libStub.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/hover.wildcardimports.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/hover.wildcardimports.fourslash.ts index 273f0e9a..3068c3ba 100644 --- a/packages/vipeye-internal/src/tests/fourslash/hover.wildcardimports.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/hover.wildcardimports.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/import.pytyped.privateSymbols.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/import.pytyped.privateSymbols.fourslash.ts index 84081fb0..ea244648 100644 --- a/packages/vipeye-internal/src/tests/fourslash/import.pytyped.privateSymbols.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/import.pytyped.privateSymbols.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "typeCheckingMode": "basic" //// } @@ -24,7 +24,7 @@ //// three: int = 3 // @filename: .src/test1.py -//// # pyright: reportPrivateUsage=true, reportPrivateImportUsage=true +//// # viper: reportPrivateUsage=true, reportPrivateImportUsage=true //// from testLib import one //// from testLib import [|/*marker1*/two|] as two_alias //// from testLib import [|/*marker2*/three|] diff --git a/packages/vipeye-internal/src/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.ts index f681a2e7..130f8038 100644 --- a/packages/vipeye-internal/src/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "typeCheckingMode": "basic" //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.ts index 7865af7c..a82e24ad 100644 --- a/packages/vipeye-internal/src/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "typeCheckingMode": "off" //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/import.pytyped.unsupportedDunderAll.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/import.pytyped.unsupportedDunderAll.fourslash.ts index 7a3633e9..6053c2ac 100644 --- a/packages/vipeye-internal/src/tests/fourslash/import.pytyped.unsupportedDunderAll.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/import.pytyped.unsupportedDunderAll.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "typeCheckingMode": "basic" //// } @@ -24,7 +24,7 @@ //// __all__ = _components + ["other_symbol"] // @filename: .src/test1.py -//// # pyright: reportPrivateUsage=true, reportPrivateImportUsage=true +//// # viper: reportPrivateUsage=true, reportPrivateImportUsage=true //// # This should NOT show an error because __all__ uses an unsupported form, //// # so we can't determine if GraphClass is actually in __all__ or not. //// # Since the module uses a dynamic __all__, we should be permissive. diff --git a/packages/vipeye-internal/src/tests/fourslash/import.wildcard.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/import.wildcard.fourslash.ts index 5aff5107..d9f49f97 100644 --- a/packages/vipeye-internal/src/tests/fourslash/import.wildcard.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/import.wildcard.fourslash.ts @@ -16,7 +16,7 @@ //// print("hi") // @filename: .src/test.py -//// # pyright: reportWildcardImportFromLibrary=false +//// # viper: reportWildcardImportFromLibrary=false //// from testpkg import * //// submod.test_func() //// [|/*marker*/foo|]() diff --git a/packages/vipeye-internal/src/tests/fourslash/missingModuleSource.disablingInStrictMode.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/missingModuleSource.disablingInStrictMode.fourslash.ts index 58fa93da..ec5bf78f 100644 --- a/packages/vipeye-internal/src/tests/fourslash/missingModuleSource.disablingInStrictMode.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/missingModuleSource.disablingInStrictMode.fourslash.ts @@ -4,7 +4,7 @@ //// __version__: str // @filename: importnotresolved.py -//// #pyright: strict +//// #viper: strict //// //// # verify that reportMissingModuleSource can be disabled via config //// # even when in strict mode @@ -12,7 +12,7 @@ //// import pkg1234 //// print(pkg1234.__version__) -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "reportMissingModuleSource": false //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.codeAction.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.codeAction.fourslash.ts index 101eeb56..dfedac40 100644 --- a/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.codeAction.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.codeAction.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "reportMissingTypeStubs": "warning" //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.command.multipart.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.command.multipart.fourslash.ts index 3251fde6..8f132959 100644 --- a/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.command.multipart.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.command.multipart.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "reportMissingTypeStubs": "warning" //// } @@ -29,7 +29,7 @@ const command2 = { // @ts-ignore await helper.verifyCommand(command2, { ['/typings/testLib/aa/bb/__init__.pyi']: `""" -This type stub file was generated by pyright. +This type stub file was generated by viper. """ class MyLibrary: @@ -40,7 +40,7 @@ class MyLibrary: `, ['/typings/testLib/aa/bb/cc.pyi']: `""" -This type stub file was generated by pyright. +This type stub file was generated by viper. """ MyAlias = int diff --git a/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.command.singlefile.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.command.singlefile.fourslash.ts index eef78dd2..ecc436c0 100644 --- a/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.command.singlefile.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.command.singlefile.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "reportMissingTypeStubs": "warning" //// } @@ -25,7 +25,7 @@ const command3 = { // @ts-ignore await helper.verifyCommand(command3, { ['/typings/testLib/__init__.pyi']: `""" -This type stub file was generated by pyright. +This type stub file was generated by viper. """ class MyLibrary: diff --git a/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.command.singlepart.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.command.singlepart.fourslash.ts index 77f37090..5e30cb2f 100644 --- a/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.command.singlepart.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.command.singlepart.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "reportMissingTypeStubs": "warning" //// } @@ -25,7 +25,7 @@ const command1 = { // @ts-ignore await helper.verifyCommand(command1, { ['/typings/testLib/__init__.pyi']: `""" -This type stub file was generated by pyright. +This type stub file was generated by viper. """ class MyLibrary: diff --git a/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.command.trycatchImport.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.command.trycatchImport.fourslash.ts index b2d23b60..727df118 100644 --- a/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.command.trycatchImport.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.command.trycatchImport.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "reportMissingTypeStubs": "warning" //// } @@ -40,7 +40,7 @@ const command4 = { // @ts-ignore await helper.verifyCommand(command4, { ['/typings/testLib/__init__.pyi']: `""" -This type stub file was generated by pyright. +This type stub file was generated by viper. """ from .mylibrary import MyLibrary diff --git a/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.fourslash.ts index 7dac991e..29fa3ff0 100644 --- a/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "reportMissingTypeStubs": "warning" //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.invokeCodeAction.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.invokeCodeAction.fourslash.ts index 79fc2f4a..de22ae3b 100644 --- a/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.invokeCodeAction.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/missingTypeStub.invokeCodeAction.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "reportMissingTypeStubs": "warning" //// } @@ -21,7 +21,7 @@ await helper.verifyInvokeCodeAction({ title: `Create Type Stub For "testLib"`, files: { ['/typings/testLib/__init__.pyi']: `""" -This type stub file was generated by pyright. +This type stub file was generated by viper. """ class MyLibrary: diff --git a/packages/vipeye-internal/src/tests/fourslash/rename.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/rename.fourslash.ts index 3a4a9e29..351e9bee 100644 --- a/packages/vipeye-internal/src/tests/fourslash/rename.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/rename.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/rename.library.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/rename.library.fourslash.ts index 865b21aa..2abc5a70 100644 --- a/packages/vipeye-internal/src/tests/fourslash/rename.library.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/rename.library.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/rename.library.sourceAndStub.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/rename.library.sourceAndStub.fourslash.ts index 59d4f0a1..918dc276 100644 --- a/packages/vipeye-internal/src/tests/fourslash/rename.library.sourceAndStub.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/rename.library.sourceAndStub.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/rename.string.excluded.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/rename.string.excluded.fourslash.ts index 4194888e..e04bfb55 100644 --- a/packages/vipeye-internal/src/tests/fourslash/rename.string.excluded.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/rename.string.excluded.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "exclude": ["**/exclude/**"] //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/rename.typeParams.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/rename.typeParams.fourslash.ts index 19e5d14e..37463e14 100644 --- a/packages/vipeye-internal/src/tests/fourslash/rename.typeParams.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/rename.typeParams.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/signature.docstrings.wildcardimports.fourslash.ts b/packages/vipeye-internal/src/tests/fourslash/signature.docstrings.wildcardimports.fourslash.ts index c2ca97f4..37b62445 100644 --- a/packages/vipeye-internal/src/tests/fourslash/signature.docstrings.wildcardimports.fourslash.ts +++ b/packages/vipeye-internal/src/tests/fourslash/signature.docstrings.wildcardimports.fourslash.ts @@ -1,6 +1,6 @@ /// -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/fourslash/typings/fourslash.d.ts b/packages/vipeye-internal/src/tests/fourslash/typings/fourslash.d.ts index 69758ca0..121e1a51 100644 --- a/packages/vipeye-internal/src/tests/fourslash/typings/fourslash.d.ts +++ b/packages/vipeye-internal/src/tests/fourslash/typings/fourslash.d.ts @@ -8,14 +8,14 @@ * * this basically provides type information through // while editing but * get ignored when test run due to how test code is injected when running. - * see - server\pyright\server\src\tests\harness\fourslash\runner.ts@runCode - for more detail + * see - packages\vipeye-internal\src\tests\harness\fourslash\runner.ts@runCode - for more detail * - * when run, helper variable will be bound to TestState (server\pyright\server\src\tests\harness\fourslash\testState.ts) + * when run, helper variable will be bound to TestState (packages\vipeye-internal\src\tests\harness\fourslash\testState.ts) * so make sure Fourslash type is in sync with TestState * * for how markup language and helper is used in fourslash tests, see these 2 tests - * server\pyright\server\src\tests\fourSlashParser.test.ts - * server\pyright\server\src\tests\testState.test.ts + * packages\vipeye-internal\src\tests\fourSlashParser.test.ts + * packages\vipeye-internal\src\tests\testState.test.ts * * for debugging, open *.fourslash.ts test file you want to debug, and select "fourslash current file" as debug configuration * and set break point in one of TestState methods you are using in the test or set break point on "runCode" above diff --git a/packages/vipeye-internal/src/tests/harness/fourslash/testState.ts b/packages/vipeye-internal/src/tests/harness/fourslash/testState.ts index d94a584a..e86603e0 100644 --- a/packages/vipeye-internal/src/tests/harness/fourslash/testState.ts +++ b/packages/vipeye-internal/src/tests/harness/fourslash/testState.ts @@ -42,7 +42,7 @@ import { Comparison, isNumber, isString } from '../../../common/core'; import * as debug from '../../../common/debug'; import { DiagnosticCategory } from '../../../common/diagnostic'; import { DocumentRange } from '../../../common/docRange'; -import { PyrightDocStringService } from '../../../common/docStringService'; +import { ViperDocStringService } from '../../../common/docStringService'; import { FileEditAction } from '../../../common/editAction'; import { ReadOnlyFileSystem } from '../../../common/fileSystem'; import { Host } from '../../../common/host'; @@ -75,7 +75,7 @@ import { ParseNode } from '../../../parser/parseNodes'; import { ParseFileResults } from '../../../parser/parser'; import { Tokenizer } from '../../../parser/tokenizer'; import { NoOpPartialStubs, PartialStubService } from '../../../partialStubService'; -import { PyrightFileSystem } from '../../../pyrightFileSystem'; +import { ViperFileSystem } from '../../../viperFileSystem'; import { NormalWorkspace, WellKnownWorkspaceKinds, Workspace, createInitStatus } from '../../../workspaceFactory'; import { TestAccessHost } from '../testAccessHost'; import * as host from '../testHost'; @@ -147,7 +147,7 @@ export class TestState { private readonly _hostSpecificFeatures: HostSpecificFeatures; readonly testFS: vfs.TestFileSystem; - readonly fs: PyrightFileSystem; + readonly fs: ViperFileSystem; readonly workspace: NormalWorkspace; readonly console: ConsoleInterface; readonly rawConfigJson: any | undefined; @@ -177,7 +177,7 @@ export class TestState { mountPaths ); - this.fs = new PyrightFileSystem(this.testFS); + this.fs = new ViperFileSystem(this.testFS); this.console = new ConsoleWithLogLevel(new NullConsole(), 'test'); const ps = options?.enablePartialStub ? new PartialStubService(this.fs) : new NoOpPartialStubs(); this.serviceProvider = createServiceProvider(this.testFS, this.fs, this.console, ps); @@ -1159,7 +1159,7 @@ export class TestState { /* hasSignatureLabelOffsetCapability */ true, /* hasActiveParameterCapability */ true, /* context */ undefined, - new PyrightDocStringService(), + new ViperDocStringService(), CancellationToken.None ).getSignatureHelp(); diff --git a/packages/vipeye-internal/src/tests/hoverProvider.test.ts b/packages/vipeye-internal/src/tests/hoverProvider.test.ts index 50708244..4344123a 100644 --- a/packages/vipeye-internal/src/tests/hoverProvider.test.ts +++ b/packages/vipeye-internal/src/tests/hoverProvider.test.ts @@ -12,7 +12,7 @@ import { parseAndGetTestState, TestState } from './harness/fourslash/testState'; test('import tooltip - import statement', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -41,7 +41,7 @@ test('import tooltip - import statement', async () => { test('import tooltip - import reference', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -71,7 +71,7 @@ test('import tooltip - import reference', async () => { test('import tooltip - import statement with stubs', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -108,7 +108,7 @@ test('import tooltip - import statement with stubs', async () => { test('method tooltip - docstring from implementation when stub uses non-exported name', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -150,7 +150,7 @@ test('method tooltip - docstring from implementation when stub uses non-exported test('function hover shows source default values for stub ellipsis defaults', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -179,7 +179,7 @@ test('function hover shows source default values for stub ellipsis defaults', as test('function hover substitutes multiple stub ellipsis defaults from source', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -208,7 +208,7 @@ test('function hover substitutes multiple stub ellipsis defaults from source', a test('function hover shows concrete default values when provided by stub', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -233,7 +233,7 @@ test('function hover shows concrete default values when provided by stub', async test('function hover substitutes multiple stub ellipsis defaults for selected overload', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -271,7 +271,7 @@ test('function hover substitutes multiple stub ellipsis defaults for selected ov test('function hover does not substitute unsafe long defaults for stub ellipsis defaults', async () => { const longNumber = '9'.repeat(150); const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -300,7 +300,7 @@ test('function hover does not substitute unsafe long defaults for stub ellipsis test('function hover does not substitute unsafe multiline defaults for stub ellipsis defaults', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -330,7 +330,7 @@ test('function hover does not substitute unsafe multiline defaults for stub elli test('import tooltip - import reference - stub files', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -368,7 +368,7 @@ test('import tooltip - import reference - stub files', async () => { test('import tooltip - import submodules statement', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -398,7 +398,7 @@ test('import tooltip - import submodules statement', async () => { test('import tooltip - import submodules reference', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -429,7 +429,7 @@ test('import tooltip - import submodules reference', async () => { test('import tooltip - from import statement with stubs', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -466,7 +466,7 @@ test('import tooltip - from import statement with stubs', async () => { test('import tooltip - from import submodules statement', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -526,7 +526,7 @@ test('import tooltip - check duplicate property', async () => { test('import symbol tooltip - useLibraryCodeForTypes false', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": false //// } @@ -560,7 +560,7 @@ test('import symbol tooltip - useLibraryCodeForTypes false', async () => { test('import symbol tooltip - useLibraryCodeForTypes true', async () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/importResolver.test.ts b/packages/vipeye-internal/src/tests/importResolver.test.ts index 97202dfb..76143ad9 100644 --- a/packages/vipeye-internal/src/tests/importResolver.test.ts +++ b/packages/vipeye-internal/src/tests/importResolver.test.ts @@ -24,7 +24,7 @@ import { createServiceProvider } from '../common/serviceProviderExtensions'; import { Uri } from '../common/uri/uri'; import { UriEx } from '../common/uri/uriUtils'; import { PartialStubService } from '../partialStubService'; -import { PyrightFileSystem } from '../pyrightFileSystem'; +import { ViperFileSystem } from '../viperFileSystem'; import { TestAccessHost } from './harness/testAccessHost'; import { TestFileSystem } from './harness/vfs/filesystem'; @@ -87,7 +87,7 @@ describe('Import tests with fake venv', () => { const testFS = createTestFileSystem(files); testFS.symlinkSync(stubSource, combinePaths(libraryRoot, 'myLib-stubs', 'partialStub.pyi')); - const fs = new PyrightFileSystem(testFS); + const fs = new ViperFileSystem(testFS); const partialStubService = new PartialStubService(fs); const sp = createServiceProvider(testFS, fs, partialStubService); const configOptions = new ConfigOptions(UriEx.file('/')); @@ -527,7 +527,7 @@ describe('Import tests with fake venv', () => { c.defaultExtraPaths = [UriEx.file(combinePaths('/', 'external_symlinked'))]; }, (importResolver, uri, configOptions) => { - const fs = importResolver.serviceProvider.fs() as PyrightFileSystem; + const fs = importResolver.serviceProvider.fs() as ViperFileSystem; const testFs = (fs as any).realFS as TestFileSystem; testFs.mkdirSync(UriEx.file(combinePaths('/', 'external_symlinked'))); testFs.symlinkSync( @@ -1131,14 +1131,14 @@ function createTestFileSystem(files: { path: string; content: string }[]): TestF function createServiceProviderFromFiles(files: { path: string; content: string }[]): ServiceProvider { const testFS = createTestFileSystem(files); - const fs = new PyrightFileSystem(testFS); + const fs = new ViperFileSystem(testFS); const partialStubService = new PartialStubService(fs); return createServiceProvider(testFS, fs, partialStubService); } function createServiceProviderWithCombinedFs(files: { path: string; content: string }[]): ServiceProvider { const testFS = createTestFileSystem(files); - const fs = new PyrightFileSystem(new CombinedFileSystem(testFS)); + const fs = new ViperFileSystem(new CombinedFileSystem(testFS)); const partialStubService = new PartialStubService(fs); return createServiceProvider(testFS, fs, partialStubService); } diff --git a/packages/vipeye-internal/src/tests/importStatementUtils.test.ts b/packages/vipeye-internal/src/tests/importStatementUtils.test.ts index d1addc55..3282a22b 100644 --- a/packages/vipeye-internal/src/tests/importStatementUtils.test.ts +++ b/packages/vipeye-internal/src/tests/importStatementUtils.test.ts @@ -622,7 +622,7 @@ test('getRelativeModuleName - target in stub path', () => { test('getRelativeModuleName - target in typeshed path', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "typeshedPath": "my_typeshed" //// } @@ -639,7 +639,7 @@ test('getRelativeModuleName - target in typeshed path', () => { test('resolve alias of not needed file', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } diff --git a/packages/vipeye-internal/src/tests/languageServer.test.ts b/packages/vipeye-internal/src/tests/languageServer.test.ts index d894f3a3..9c7d418e 100644 --- a/packages/vipeye-internal/src/tests/languageServer.test.ts +++ b/packages/vipeye-internal/src/tests/languageServer.test.ts @@ -3,7 +3,7 @@ * Copyright (c) Microsoft Corporation. * Licensed under the MIT license. * - * Tests to verify Pyright works as the backend for a language server. + * Tests to verify Vipeye works as the backend for a language server. */ import assert from 'assert'; @@ -32,13 +32,13 @@ import { getParseResults, hover, openFile, - PyrightServerInfo, - runPyrightServer, + ViperServerInfo, + runViperServer, waitForDiagnostics, } from './lsp/languageServerTestUtils'; describe(`Basic language server tests`, () => { - let serverInfo: PyrightServerInfo | undefined; + let serverInfo: ViperServerInfo | undefined; async function runLanguageServer( projectRoots: string[] | string, code: string, @@ -48,7 +48,7 @@ describe(`Basic language server tests`, () => { supportsBackgroundThread?: boolean, supportsPullDiagnostics?: boolean ) { - const result = await runPyrightServer( + const result = await runViperServer( projectRoots, code, callInitialize, diff --git a/packages/vipeye-internal/src/tests/lsp/languageServer.ts b/packages/vipeye-internal/src/tests/lsp/languageServer.ts index 93ee95cb..acb628f2 100644 --- a/packages/vipeye-internal/src/tests/lsp/languageServer.ts +++ b/packages/vipeye-internal/src/tests/lsp/languageServer.ts @@ -21,7 +21,7 @@ import { FileSystemEntries, resolvePaths } from '../../common/pathUtils'; import { ServiceProvider } from '../../common/serviceProvider'; import { Uri } from '../../common/uri/uri'; import { parseTestData } from '../harness/fourslash/fourSlashParser'; -import * as PyrightTestHost from '../harness/testHost'; +import * as ViperTestHost from '../harness/testHost'; import { clearCache } from '../harness/vfs/factory'; import { IPythonMode } from '../../analyzer/sourceFile'; @@ -33,8 +33,8 @@ import { FileSystem } from '../../common/fileSystem'; import { ServerSettings } from '../../common/languageServerInterface'; import { PythonVersion } from '../../common/pythonVersion'; import { ServiceKeys } from '../../common/serviceKeys'; -import { PyrightFileSystem } from '../../pyrightFileSystem'; -import { PyrightServer } from '../../server'; +import { ViperFileSystem } from '../../viperFileSystem'; +import { ViperServer } from '../../server'; import { InitStatus, Workspace } from '../../workspaceFactory'; import { CustomLSP } from './customLsp'; import { @@ -61,8 +61,8 @@ function getCommonRoot(files: Uri[]) { return root; } -class TestPyrightHost implements PyrightTestHost.TestHost { - constructor(private _host: PyrightTestHost.TestHost) {} +class TestViperHost implements ViperTestHost.TestHost { + constructor(private _host: ViperTestHost.TestHost) {} useCaseSensitiveFileNames(): boolean { return this._host.useCaseSensitiveFileNames(); } @@ -125,12 +125,12 @@ function createTestHost(testServerData: CustomLSP.TestServerStartOptions) { clearCache(); // create a test file system using the test data. - const fs = createFileSystem(commonRoot, testData, new TestPyrightHost(PyrightTestHost.HOST)); + const fs = createFileSystem(commonRoot, testData, new TestViperHost(ViperTestHost.HOST)); return new TestHost(fs, fs, testData, projectRootPaths, options); } -class TestServer extends PyrightServer { +class TestServer extends ViperServer { private static _currentId = 0; private _id = TestServer._currentId++; constructor( @@ -199,7 +199,7 @@ async function runServer( }; try { - // Create a host so we can control the file system for the PyrightServer. + // Create a host so we can control the file system for the ViperServer. const disposables: Disposable[] = []; const host = createTestHost(testServerData); const server = new TestServer(connection, host.fs, testServerData.backgroundAnalysis); @@ -393,7 +393,7 @@ async function runTestBackgroundThread() { // the host's file system. Has to be sync so that we don't // drop any messages sent to the background thread. const host = createTestHost(options); - const fs = new PyrightFileSystem(host.fs); + const fs = new ViperFileSystem(host.fs); const serviceProvider = new ServiceProvider(); serviceProvider.add(ServiceKeys.fs, fs); diff --git a/packages/vipeye-internal/src/tests/lsp/languageServerTestUtils.ts b/packages/vipeye-internal/src/tests/lsp/languageServerTestUtils.ts index bde753ad..5abd0dbf 100644 --- a/packages/vipeye-internal/src/tests/lsp/languageServerTestUtils.ts +++ b/packages/vipeye-internal/src/tests/lsp/languageServerTestUtils.ts @@ -94,7 +94,7 @@ export const DEFAULT_WORKSPACE_ROOT = combinePaths('/', 'src'); export const ERROR_SCRIPT_OUTPUT = 'Error: script failed to run'; export const STALL_SCRIPT_OUTPUT = 'Timeout: script never finished running'; -export interface PyrightServerInfo { +export interface ViperServerInfo { disposables: Disposable[]; registrations: Registration[]; logs: LogMessageParams[]; @@ -225,12 +225,12 @@ export function createFileSystem(projectRoot: string, testData: FourSlashData, o const vfsInfo = createVfsInfoFromFourSlashData(projectRoot, testData); - // If there's a pyrightconfig.json, add it to the list of files as well. + // If there's a viperconfig.json, add it to the list of files as well. const files = vfsInfo.files; if (vfsInfo.rawConfigJson) { - files[combinePaths(vfsInfo.projectRoot, 'pyrightconfig.json')] = new vfs.File( + files[combinePaths(vfsInfo.projectRoot, 'viperconfig.json')] = new vfs.File( JSON.stringify(vfsInfo.rawConfigJson), - { encoding: 'utf8', meta: { filename: 'pyrightconfig.json' } } + { encoding: 'utf8', meta: { filename: 'viperconfig.json' } } ); } return createFromFileSystem( @@ -241,7 +241,7 @@ export function createFileSystem(projectRoot: string, testData: FourSlashData, o ); } -const settingsMap = new Map(); +const settingsMap = new Map(); function isDotPathPrefix(prefix: string | undefined, path: string | undefined) { const prefixParts = prefix ? prefix.split('.') : []; @@ -338,18 +338,18 @@ function createServerConnection(testServerData: CustomLSP.TestServerStartOptions return connection; } -function getProjectRootString(info: PyrightServerInfo, projectRoot?: Uri) { +function getProjectRootString(info: ViperServerInfo, projectRoot?: Uri) { return projectRoot ? projectRoot.toString() : info.projectRoots.length > 0 ? info.projectRoots[0].toString() : ''; } -export async function getOpenFiles(info: PyrightServerInfo, projectRoot?: Uri): Promise { +export async function getOpenFiles(info: ViperServerInfo, projectRoot?: Uri): Promise { const uri = getProjectRootString(info, projectRoot); const result = await CustomLSP.sendRequest(info.connection, CustomLSP.Requests.GetOpenFiles, { uri }); return deserialize(result.files); } export async function waitForPushDiagnostics( - info: PyrightServerInfo, + info: ViperServerInfo, clearFirst: boolean, numberOfFiles = 1, timeout = 10000 @@ -444,7 +444,7 @@ export function convertDiagnosticReport( return [convertDiagnosticReportItem(uri, documentReport)]; } -async function waitForPullDiagnostics(info: PyrightServerInfo): Promise { +async function waitForPullDiagnostics(info: ViperServerInfo): Promise { const openFiles = await getOpenFiles(info); if (openFiles.length <= 0) { return waitForPushDiagnostics(info, false); @@ -462,7 +462,7 @@ async function waitForPullDiagnostics(info: PyrightServerInfo): Promise void ) { info.disposables.push( @@ -526,7 +526,7 @@ export async function waitForPromise(promise: Promise, timeout = 10000, mes }); } -export async function runPyrightServer( +export async function runViperServer( projectRoots: string[] | string, code: string, callInitialize = true, @@ -534,7 +534,7 @@ export async function runPyrightServer( pythonVersion: PythonVersion = pythonVersion3_10, backgroundAnalysis?: boolean, supportPullDiagnostics?: boolean -): Promise { +): Promise { // Setup the test data we need to send for Test server startup. const projectRootsArray = Array.isArray(projectRoots) ? projectRoots : [projectRoots]; @@ -579,7 +579,7 @@ export async function runPyrightServer( const partialResultToken = `4fb5ab8a-37a6-4c16-a290-03cfc892ea7e`; // Doesn't need to be different, just a random guid // Setup the server info. - const info: PyrightServerInfo = { + const info: ViperServerInfo = { disposables, registrations: [], connection, @@ -768,7 +768,7 @@ export async function runPyrightServer( return info; } -function startWorkspaceDiagnostics(info: PyrightServerInfo, extraMessage: string) { +function startWorkspaceDiagnostics(info: ViperServerInfo, extraMessage: string) { if (!info.pendingWorkspaceDiagnostics) { info.logs.push({ message: `Starting workspace diagnostics request: ${extraMessage}`, type: 4 }); info.pendingWorkspaceDiagnostics = info.connection @@ -783,7 +783,7 @@ function startWorkspaceDiagnostics(info: PyrightServerInfo, extraMessage: string } } -async function stopWorkspaceDiagnostics(info: PyrightServerInfo, extraMessage: string) { +async function stopWorkspaceDiagnostics(info: ViperServerInfo, extraMessage: string) { if (info.pendingWorkspaceDiagnostics) { const pending = info.pendingWorkspaceDiagnostics; info.pendingWorkspaceDiagnostics = undefined; @@ -799,7 +799,7 @@ async function stopWorkspaceDiagnostics(info: PyrightServerInfo, extraMessage: s } } -export async function initializeLanguageServer(info: PyrightServerInfo) { +export async function initializeLanguageServer(info: ViperServerInfo) { const params = info.getInitializeParams(); // Send the initialize request. @@ -835,14 +835,14 @@ export async function sleep(timeout: number): Promise { }); } -export async function waitForTestSignal(info: PyrightServerInfo, signal: CustomLSP.TestSignalKinds, timeout = 10000) { +export async function waitForTestSignal(info: ViperServerInfo, signal: CustomLSP.TestSignalKinds, timeout = 10000) { const result = await Promise.race([info.signals.get(signal)!.promise, sleep(timeout)]); if (result === timeout) { throw new Error(`Timed out waiting for signal ${signal}`); } } -export async function openFile(info: PyrightServerInfo, markerName: string, text?: string) { +export async function openFile(info: ViperServerInfo, markerName: string, text?: string) { const marker = getMarkerByName(info.testData, markerName); const uri = marker.fileUri.toString(); @@ -855,7 +855,7 @@ export async function openFile(info: PyrightServerInfo, markerName: string, text await waitForTestSignal(info, CustomLSP.TestSignalKinds.DidOpenDocument); } -export async function hover(info: PyrightServerInfo, markerName: string) { +export async function hover(info: ViperServerInfo, markerName: string) { const marker = info.testData.markerPositions.get(markerName)!; const fileUri = marker.fileUri; const text = info.testData.files.find((d) => d.fileName === marker.fileName)!.content; diff --git a/packages/vipeye-internal/src/tests/parser.test.ts b/packages/vipeye-internal/src/tests/parser.test.ts index 26d8e9de..bef68ba8 100644 --- a/packages/vipeye-internal/src/tests/parser.test.ts +++ b/packages/vipeye-internal/src/tests/parser.test.ts @@ -364,7 +364,7 @@ test('LazyImport - wildcard import rejected at 3.15', () => { test('LazyImport - AliasDeclaration.isLazy is propagated', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "executionEnvironments": [ //// { "root": ".", "pythonVersion": "3.15" } @@ -421,7 +421,7 @@ test('LazyImport - submoduleFallback AliasDeclaration carries isLazy', () => { // the isLazy flag too (otherwise downstream consumers reading // submoduleFallback.isLazy would silently lose the lazy bit). const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "executionEnvironments": [ //// { "root": ".", "pythonVersion": "3.15" } diff --git a/packages/vipeye-internal/src/tests/privateImportUsage.test.ts b/packages/vipeye-internal/src/tests/privateImportUsage.test.ts index e966e50f..53695b5b 100644 --- a/packages/vipeye-internal/src/tests/privateImportUsage.test.ts +++ b/packages/vipeye-internal/src/tests/privateImportUsage.test.ts @@ -20,7 +20,7 @@ import { createServiceProvider } from '../common/serviceProviderExtensions'; import { UriEx } from '../common/uri/uriUtils'; import { TestAccessHost } from './harness/testAccessHost'; import { TestFileSystem } from './harness/vfs/filesystem'; -import { PyrightFileSystem } from '../pyrightFileSystem'; +import { ViperFileSystem } from '../viperFileSystem'; const libraryRoot = combinePaths(normalizeSlashes('/'), lib, sitePackages); @@ -40,7 +40,7 @@ function createTestFileSystem(files: { path: string; content: string }[]): TestF function createServiceProviderFromFiles(files: { path: string; content: string }[]) { const testFS = createTestFileSystem(files); - const fs = new PyrightFileSystem(testFS); + const fs = new ViperFileSystem(testFS); return createServiceProvider(testFS, fs); } @@ -168,8 +168,8 @@ describe('reportPrivateImportUsage with tracked library files', () => { }); test('config file reportPrivateImportUsage override should apply when includeFileSpecsOverride is set', () => { - // This tests the scenario where pyright is run with positional directory arguments - // (e.g., pyright --project pyrightconfig.json dir1) and the config file has + // This tests the scenario where viper is run with positional directory arguments + // (e.g., viper --project viperconfig.json dir1) and the config file has // reportPrivateImportUsage: false. The override should still be respected. const files = [ @@ -285,7 +285,7 @@ describe('reportPrivateImportUsage with tracked library files', () => { } // Test 3: With reportPrivateImportUsage = 'none' AND positional arg include override - // This simulates: pyright --project config.json consumer/ + // This simulates: viper --project config.json consumer/ // where config.json has reportPrivateImportUsage: false { const configOptions = new ConfigOptions(UriEx.file('/')); diff --git a/packages/vipeye-internal/src/tests/realTempFile.test.ts b/packages/vipeye-internal/src/tests/realTempFile.test.ts index e1118be5..3f672cf2 100644 --- a/packages/vipeye-internal/src/tests/realTempFile.test.ts +++ b/packages/vipeye-internal/src/tests/realTempFile.test.ts @@ -25,9 +25,9 @@ import * as fs from 'fs'; import { normalizeSlashes } from '../common/pathUtils'; import { RealTempFile } from '../common/realFileSystem'; -test('RealTempFile surfaces ENOENT with guidance to set PYRIGHT_TMPDIR', () => { - const old = process.env.PYRIGHT_TMPDIR; - delete process.env.PYRIGHT_TMPDIR; +test('RealTempFile surfaces ENOENT with guidance to set VIPER_TMPDIR', () => { + const old = process.env.VIPER_TMPDIR; + delete process.env.VIPER_TMPDIR; const dirSyncMock = tmp.dirSync as unknown as jest.Mock; const enoent = new Error('ENOENT: no such file or directory') as NodeJS.ErrnoException; @@ -38,22 +38,22 @@ test('RealTempFile surfaces ENOENT with guidance to set PYRIGHT_TMPDIR', () => { const tempFile = new RealTempFile(); try { - assert.throws(() => tempFile.tmpdir(), /PYRIGHT_TMPDIR/); + assert.throws(() => tempFile.tmpdir(), /VIPER_TMPDIR/); assert.equal(dirSyncMock.mock.calls.length, 1); - assert.deepEqual(dirSyncMock.mock.calls[0][0], { prefix: 'pyright' }); + assert.deepEqual(dirSyncMock.mock.calls[0][0], { prefix: 'viper' }); } finally { tempFile.dispose(); dirSyncMock.mockReset(); - process.env.PYRIGHT_TMPDIR = old; + process.env.VIPER_TMPDIR = old; } }); -test('RealTempFile honors PYRIGHT_TMPDIR when set', () => { - const old = process.env.PYRIGHT_TMPDIR; - const configuredTmpRoot = path.join(os.tmpdir(), `pyright-tmp-root-test-${Date.now()}`); - process.env.PYRIGHT_TMPDIR = configuredTmpRoot; +test('RealTempFile honors VIPER_TMPDIR when set', () => { + const old = process.env.VIPER_TMPDIR; + const configuredTmpRoot = path.join(os.tmpdir(), `viper-tmp-root-test-${Date.now()}`); + process.env.VIPER_TMPDIR = configuredTmpRoot; - const expectedTmpDir = normalizeSlashes('/tmp/pyright-configured'); + const expectedTmpDir = normalizeSlashes('/tmp/viper-configured'); const dirSyncMock = tmp.dirSync as unknown as jest.Mock; dirSyncMock.mockImplementationOnce(() => ({ name: expectedTmpDir, removeCallback: () => {} })); @@ -63,23 +63,23 @@ test('RealTempFile honors PYRIGHT_TMPDIR when set', () => { const dirUri = tempFile.tmpdir(); assert.equal(normalizeSlashes(dirUri.getFilePath()), expectedTmpDir); assert.equal(dirSyncMock.mock.calls.length, 1); - assert.equal(dirSyncMock.mock.calls[0][0].prefix, 'pyright'); + assert.equal(dirSyncMock.mock.calls[0][0].prefix, 'viper'); assert.equal(dirSyncMock.mock.calls[0][0].tmpdir, configuredTmpRoot); assert(fs.existsSync(configuredTmpRoot)); } finally { tempFile.dispose(); dirSyncMock.mockReset(); fs.rmSync(configuredTmpRoot, { recursive: true, force: true }); - process.env.PYRIGHT_TMPDIR = old; + process.env.VIPER_TMPDIR = old; } }); -test('RealTempFile falls back to default when PYRIGHT_TMPDIR cannot be used', () => { - const old = process.env.PYRIGHT_TMPDIR; - const configuredTmpRoot = path.join(os.tmpdir(), `pyright-tmp-root-test-${Date.now()}`); - process.env.PYRIGHT_TMPDIR = configuredTmpRoot; +test('RealTempFile falls back to default when VIPER_TMPDIR cannot be used', () => { + const old = process.env.VIPER_TMPDIR; + const configuredTmpRoot = path.join(os.tmpdir(), `viper-tmp-root-test-${Date.now()}`); + process.env.VIPER_TMPDIR = configuredTmpRoot; - const expectedTmpDir = normalizeSlashes('/tmp/pyright-default-after-config-failure'); + const expectedTmpDir = normalizeSlashes('/tmp/viper-default-after-config-failure'); const dirSyncMock = tmp.dirSync as unknown as jest.Mock; const eacces = new Error('EACCES: permission denied') as NodeJS.ErrnoException; @@ -97,19 +97,19 @@ test('RealTempFile falls back to default when PYRIGHT_TMPDIR cannot be used', () assert.equal(normalizeSlashes(dirUri.getFilePath()), expectedTmpDir); assert.equal(dirSyncMock.mock.calls.length, 2); assert.equal(dirSyncMock.mock.calls[0][0].tmpdir, configuredTmpRoot); - assert.deepEqual(dirSyncMock.mock.calls[1][0], { prefix: 'pyright' }); + assert.deepEqual(dirSyncMock.mock.calls[1][0], { prefix: 'viper' }); assert(fs.existsSync(configuredTmpRoot)); } finally { tempFile.dispose(); dirSyncMock.mockReset(); fs.rmSync(configuredTmpRoot, { recursive: true, force: true }); - process.env.PYRIGHT_TMPDIR = old; + process.env.VIPER_TMPDIR = old; } }); test('RealTempFile does not attempt fallback root on non-ENOENT error', () => { - const old = process.env.PYRIGHT_TMPDIR; - delete process.env.PYRIGHT_TMPDIR; + const old = process.env.VIPER_TMPDIR; + delete process.env.VIPER_TMPDIR; const dirSyncMock = tmp.dirSync as unknown as jest.Mock; const eacces = new Error('EACCES: permission denied') as NodeJS.ErrnoException; @@ -120,12 +120,12 @@ test('RealTempFile does not attempt fallback root on non-ENOENT error', () => { const tempFile = new RealTempFile(); try { - assert.throws(() => tempFile.tmpdir(), /Failed to create a temporary directory for Pyright/); + assert.throws(() => tempFile.tmpdir(), /Failed to create a temporary directory for Viper/); assert.equal(dirSyncMock.mock.calls.length, 1); - assert.deepEqual(dirSyncMock.mock.calls[0][0], { prefix: 'pyright' }); + assert.deepEqual(dirSyncMock.mock.calls[0][0], { prefix: 'viper' }); } finally { tempFile.dispose(); dirSyncMock.mockReset(); - process.env.PYRIGHT_TMPDIR = old; + process.env.VIPER_TMPDIR = old; } }); diff --git a/packages/vipeye-internal/src/tests/samples/abstractClass5.py b/packages/vipeye-internal/src/tests/samples/abstractClass5.py index b132bba2..4e1932a8 100644 --- a/packages/vipeye-internal/src/tests/samples/abstractClass5.py +++ b/packages/vipeye-internal/src/tests/samples/abstractClass5.py @@ -36,7 +36,7 @@ class ClassA(ABC): raise NotImplementedError() @overload - def func3(self, a: str) -> str: # pyright: ignore[reportNoOverloadImplementation] + def func3(self, a: str) -> str: # viper: ignore[reportNoOverloadImplementation] ... @overload @@ -46,7 +46,7 @@ class ClassA(ABC): @overload @abstractmethod - def func4(self, a: str) -> str: # pyright: ignore[reportNoOverloadImplementation] + def func4(self, a: str) -> str: # viper: ignore[reportNoOverloadImplementation] ... @overload diff --git a/packages/vipeye-internal/src/tests/samples/abstractClass9.py b/packages/vipeye-internal/src/tests/samples/abstractClass9.py index 9335c96e..ae8002fd 100644 --- a/packages/vipeye-internal/src/tests/samples/abstractClass9.py +++ b/packages/vipeye-internal/src/tests/samples/abstractClass9.py @@ -1,6 +1,6 @@ # This sample tests that named tuple fields override abstract methods. -# pyright: reportIncompatibleVariableOverride=false +# viper: reportIncompatibleVariableOverride=false from abc import ABC, abstractmethod from typing import NamedTuple diff --git a/packages/vipeye-internal/src/tests/samples/assertType1.py b/packages/vipeye-internal/src/tests/samples/assertType1.py index 95d54bcd..ebd3d094 100644 --- a/packages/vipeye-internal/src/tests/samples/assertType1.py +++ b/packages/vipeye-internal/src/tests/samples/assertType1.py @@ -1,7 +1,7 @@ # This sample tests the assert_type call. from typing import Any, Literal -from typing_extensions import assert_type # pyright: ignore[reportMissingModuleSource] +from typing_extensions import assert_type # viper: ignore[reportMissingModuleSource] def func1(): diff --git a/packages/vipeye-internal/src/tests/samples/assignment2.py b/packages/vipeye-internal/src/tests/samples/assignment2.py index e13eb9f4..89ce2085 100644 --- a/packages/vipeye-internal/src/tests/samples/assignment2.py +++ b/packages/vipeye-internal/src/tests/samples/assignment2.py @@ -4,7 +4,7 @@ # Enable the reportUnknownArgumentType check so we can verify that it # doesn't generate an error when assigning an empty list to an indexed # expression. -# pyright: reportUnknownArgumentType=true +# viper: reportUnknownArgumentType=true v1: list[int] = [1, 2, 3, 4, 5] diff --git a/packages/vipeye-internal/src/tests/samples/assignment4.py b/packages/vipeye-internal/src/tests/samples/assignment4.py index 513ac9c9..a74a3a10 100644 --- a/packages/vipeye-internal/src/tests/samples/assignment4.py +++ b/packages/vipeye-internal/src/tests/samples/assignment4.py @@ -2,7 +2,7 @@ # there is an expected type, so bidirectional type # inference is used. -# pyright: strict +# viper: strict from typing import Callable, Sequence diff --git a/packages/vipeye-internal/src/tests/samples/assignment7.py b/packages/vipeye-internal/src/tests/samples/assignment7.py index ef3a2fbf..9f8f1ece 100644 --- a/packages/vipeye-internal/src/tests/samples/assignment7.py +++ b/packages/vipeye-internal/src/tests/samples/assignment7.py @@ -1,7 +1,7 @@ # This sample tests a particularly difficult set of dependent # assignments that involve tuple packing and unpacking. -# pyright: strict +# viper: strict v1 = "" v3 = "" diff --git a/packages/vipeye-internal/src/tests/samples/assignmentExpr1.py b/packages/vipeye-internal/src/tests/samples/assignmentExpr1.py index 7e917ce2..9531cd54 100644 --- a/packages/vipeye-internal/src/tests/samples/assignmentExpr1.py +++ b/packages/vipeye-internal/src/tests/samples/assignmentExpr1.py @@ -1,6 +1,6 @@ # This sample tests the Python 3.8 assignment expressions. -# pyright: reportUnusedExpression=false +# viper: reportUnusedExpression=false def func1(): b = 'a' diff --git a/packages/vipeye-internal/src/tests/samples/assignmentExpr2.py b/packages/vipeye-internal/src/tests/samples/assignmentExpr2.py index 8c95857b..555d3e1e 100644 --- a/packages/vipeye-internal/src/tests/samples/assignmentExpr2.py +++ b/packages/vipeye-internal/src/tests/samples/assignmentExpr2.py @@ -1,7 +1,7 @@ # This sample tests the Python 3.8 assignment expressions. This sample # is taken from PEP 257. -# pyright: reportUnusedExpression=false +# viper: reportUnusedExpression=false import re diff --git a/packages/vipeye-internal/src/tests/samples/assignmentExpr5.py b/packages/vipeye-internal/src/tests/samples/assignmentExpr5.py index 95ecd82d..435797e4 100644 --- a/packages/vipeye-internal/src/tests/samples/assignmentExpr5.py +++ b/packages/vipeye-internal/src/tests/samples/assignmentExpr5.py @@ -1,7 +1,7 @@ # This sample tests the scoping rules for assignment expressions # within a list comprehension. -# pyright: strict +# viper: strict from typing import Tuple diff --git a/packages/vipeye-internal/src/tests/samples/autoVariance3.py b/packages/vipeye-internal/src/tests/samples/autoVariance3.py index 6c1f994b..25227a9f 100644 --- a/packages/vipeye-internal/src/tests/samples/autoVariance3.py +++ b/packages/vipeye-internal/src/tests/samples/autoVariance3.py @@ -1,7 +1,7 @@ # This sample tests variance inference for traditional type variables. from typing import Generic, Iterator, Sequence, overload -from typing_extensions import TypeVar # pyright: ignore[reportMissingModuleSource] +from typing_extensions import TypeVar # viper: ignore[reportMissingModuleSource] from dataclasses import dataclass T = TypeVar("T", infer_variance=True) diff --git a/packages/vipeye-internal/src/tests/samples/autoVariance5.py b/packages/vipeye-internal/src/tests/samples/autoVariance5.py index 61e86dcf..9d6b4157 100644 --- a/packages/vipeye-internal/src/tests/samples/autoVariance5.py +++ b/packages/vipeye-internal/src/tests/samples/autoVariance5.py @@ -2,7 +2,7 @@ # that uses auto-variance and a decorator that uses a generic type alias. from typing import Any, Concatenate, Generic, ParamSpec, TypeAlias, Callable -from typing_extensions import TypeVar # pyright: ignore[reportMissingModuleSource] +from typing_extensions import TypeVar # viper: ignore[reportMissingModuleSource] T = TypeVar("T", infer_variance=True) P = ParamSpec("P") diff --git a/packages/vipeye-internal/src/tests/samples/call11.py b/packages/vipeye-internal/src/tests/samples/call11.py index 5f73ff45..9c700ba3 100644 --- a/packages/vipeye-internal/src/tests/samples/call11.py +++ b/packages/vipeye-internal/src/tests/samples/call11.py @@ -1,7 +1,7 @@ # This sample tests the case where a call expression involves a union # on the LHS where the subtypes of the union have different signatures. -# pyright: strict +# viper: strict from __future__ import annotations from typing import Any, Callable, Generic, Self, TypeAlias, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/call17.py b/packages/vipeye-internal/src/tests/samples/call17.py index 21eac652..36a35742 100644 --- a/packages/vipeye-internal/src/tests/samples/call17.py +++ b/packages/vipeye-internal/src/tests/samples/call17.py @@ -1,7 +1,7 @@ # This sample tests a case of bidirectional type inference for calls # that involves a union in the expected type. -# pyright: strict +# viper: strict from __future__ import annotations diff --git a/packages/vipeye-internal/src/tests/samples/call8.py b/packages/vipeye-internal/src/tests/samples/call8.py index 39213b85..057e0254 100644 --- a/packages/vipeye-internal/src/tests/samples/call8.py +++ b/packages/vipeye-internal/src/tests/samples/call8.py @@ -2,7 +2,7 @@ # within each other. from typing import Any, Iterable, TypeVar, Protocol, overload -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] LiteralString, ) diff --git a/packages/vipeye-internal/src/tests/samples/callable6.py b/packages/vipeye-internal/src/tests/samples/callable6.py index d1f97e70..99b227e8 100644 --- a/packages/vipeye-internal/src/tests/samples/callable6.py +++ b/packages/vipeye-internal/src/tests/samples/callable6.py @@ -2,7 +2,7 @@ # in PEP 646. from typing import Callable, TypeVar -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVarTuple, Unpack, ) diff --git a/packages/vipeye-internal/src/tests/samples/callbackProtocol5.py b/packages/vipeye-internal/src/tests/samples/callbackProtocol5.py index 6bd4c014..44b06638 100644 --- a/packages/vipeye-internal/src/tests/samples/callbackProtocol5.py +++ b/packages/vipeye-internal/src/tests/samples/callbackProtocol5.py @@ -2,7 +2,7 @@ # attributes. from typing import Any, Callable, Protocol, TypeVar, cast -from typing_extensions import ParamSpec # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ParamSpec # viper: ignore[reportMissingModuleSource] P = ParamSpec("P") diff --git a/packages/vipeye-internal/src/tests/samples/circular2.py b/packages/vipeye-internal/src/tests/samples/circular2.py index bada1c51..51427b93 100644 --- a/packages/vipeye-internal/src/tests/samples/circular2.py +++ b/packages/vipeye-internal/src/tests/samples/circular2.py @@ -1,7 +1,7 @@ # This sample tests the handling of circular dependencies between # class declarations. -# pyright: strict +# viper: strict from typing import Generic, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/classVar3.py b/packages/vipeye-internal/src/tests/samples/classVar3.py index 763245bd..2a9d21fd 100644 --- a/packages/vipeye-internal/src/tests/samples/classVar3.py +++ b/packages/vipeye-internal/src/tests/samples/classVar3.py @@ -2,7 +2,7 @@ # where it is not allowed. from typing import Annotated, Any, ClassVar, Final, Generic, TypeAlias, TypeVar -from typing_extensions import Self # pyright: ignore[reportMissingModuleSource] +from typing_extensions import Self # viper: ignore[reportMissingModuleSource] # This should generate an error. x: ClassVar[int] = 3 diff --git a/packages/vipeye-internal/src/tests/samples/classes8.py b/packages/vipeye-internal/src/tests/samples/classes8.py index 824e6577..2d158843 100644 --- a/packages/vipeye-internal/src/tests/samples/classes8.py +++ b/packages/vipeye-internal/src/tests/samples/classes8.py @@ -5,7 +5,7 @@ from os import DirEntry from types import TracebackType from typing import AnyStr, ContextManager, Iterator -from typing_extensions import Self # pyright: ignore[reportMissingModuleSource] +from typing_extensions import Self # viper: ignore[reportMissingModuleSource] class _ScandirIterator( diff --git a/packages/vipeye-internal/src/tests/samples/classes9.py b/packages/vipeye-internal/src/tests/samples/classes9.py index 74795095..9b237563 100644 --- a/packages/vipeye-internal/src/tests/samples/classes9.py +++ b/packages/vipeye-internal/src/tests/samples/classes9.py @@ -3,7 +3,7 @@ # where the override symbol is type compatible with the overridden. -# pyright: reportIncompatibleVariableOverride=true +# viper: reportIncompatibleVariableOverride=true from typing import NotRequired, Required, TypedDict diff --git a/packages/vipeye-internal/src/tests/samples/codeFlow8.py b/packages/vipeye-internal/src/tests/samples/codeFlow8.py index 13c51aa0..4364fcf7 100644 --- a/packages/vipeye-internal/src/tests/samples/codeFlow8.py +++ b/packages/vipeye-internal/src/tests/samples/codeFlow8.py @@ -2,7 +2,7 @@ # is used within a looping construct such that the assigned # value is initially unknown. -# pyright: strict +# viper: strict from typing import Iterator diff --git a/packages/vipeye-internal/src/tests/samples/comprehension11.py b/packages/vipeye-internal/src/tests/samples/comprehension11.py index 34717f07..9bc13b6b 100644 --- a/packages/vipeye-internal/src/tests/samples/comprehension11.py +++ b/packages/vipeye-internal/src/tests/samples/comprehension11.py @@ -1,7 +1,7 @@ # This sample tests the case where bidirectional type inference is used # in a nested manner with list comprehensions. -# pyright: strict +# viper: strict from itertools import chain diff --git a/packages/vipeye-internal/src/tests/samples/comprehension2.py b/packages/vipeye-internal/src/tests/samples/comprehension2.py index c6db64f9..30c86758 100644 --- a/packages/vipeye-internal/src/tests/samples/comprehension2.py +++ b/packages/vipeye-internal/src/tests/samples/comprehension2.py @@ -1,6 +1,6 @@ # This sample tests interleaved for and if clauses in a list comprehension. -# pyright: strict, reportUnnecessaryComparison=false +# viper: strict, reportUnnecessaryComparison=false from typing import Union, List, Tuple diff --git a/packages/vipeye-internal/src/tests/samples/comprehension8.py b/packages/vipeye-internal/src/tests/samples/comprehension8.py index ce71dd1a..471f3a06 100644 --- a/packages/vipeye-internal/src/tests/samples/comprehension8.py +++ b/packages/vipeye-internal/src/tests/samples/comprehension8.py @@ -1,7 +1,7 @@ # This sample tests the evaluation of a list comprehension where # there are interdependencies between some of the variables. -# pyright: strict +# viper: strict class ClassA: diff --git a/packages/vipeye-internal/src/tests/samples/comprehension9.py b/packages/vipeye-internal/src/tests/samples/comprehension9.py index e75fe8ae..1a69a8bb 100644 --- a/packages/vipeye-internal/src/tests/samples/comprehension9.py +++ b/packages/vipeye-internal/src/tests/samples/comprehension9.py @@ -1,7 +1,7 @@ # This sample tests the case where a comprehension requires bidirectional # type inference for correct analysis. -# pyright: strict +# viper: strict from typing import TypedDict diff --git a/packages/vipeye-internal/src/tests/samples/constrainedTypeVar13.py b/packages/vipeye-internal/src/tests/samples/constrainedTypeVar13.py index e7362b9e..32ebe2d0 100644 --- a/packages/vipeye-internal/src/tests/samples/constrainedTypeVar13.py +++ b/packages/vipeye-internal/src/tests/samples/constrainedTypeVar13.py @@ -5,7 +5,7 @@ # in the case where constraint is satisfied. from typing import AnyStr, Generic, ParamSpec, TypeVar -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVarTuple, Unpack, ) diff --git a/packages/vipeye-internal/src/tests/samples/constructor14.py b/packages/vipeye-internal/src/tests/samples/constructor14.py index 84b3e910..bea76b5d 100644 --- a/packages/vipeye-internal/src/tests/samples/constructor14.py +++ b/packages/vipeye-internal/src/tests/samples/constructor14.py @@ -2,12 +2,12 @@ # using bidirectional type inference in the case where the expected # type is `Self`. -# pyright: strict +# viper: strict from __future__ import annotations from typing import Any, Generic, Protocol, TypeVar -from typing_extensions import Self # pyright: ignore[reportMissingModuleSource] +from typing_extensions import Self # viper: ignore[reportMissingModuleSource] T_contra = TypeVar("T_contra", contravariant=True) ThingT = TypeVar("ThingT", bound="Thing[Any]") diff --git a/packages/vipeye-internal/src/tests/samples/constructor25.py b/packages/vipeye-internal/src/tests/samples/constructor25.py index b44c5641..be9c2ecd 100644 --- a/packages/vipeye-internal/src/tests/samples/constructor25.py +++ b/packages/vipeye-internal/src/tests/samples/constructor25.py @@ -2,7 +2,7 @@ # allocates an instance of itself by invoking a constructor and passing # an argument that is a generic type. -# pyright: strict +# viper: strict from typing import Generic, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/constructor28.py b/packages/vipeye-internal/src/tests/samples/constructor28.py index d8b86986..8cd8dde0 100644 --- a/packages/vipeye-internal/src/tests/samples/constructor28.py +++ b/packages/vipeye-internal/src/tests/samples/constructor28.py @@ -1,7 +1,7 @@ # This sample tests the case where a constructor for a class is invoked # multiple times as separate arguments for a call. -# pyright: strict +# viper: strict from __future__ import annotations from typing import Any, Callable, Generic, Iterable, TypeVar, overload diff --git a/packages/vipeye-internal/src/tests/samples/constructor3.py b/packages/vipeye-internal/src/tests/samples/constructor3.py index ce5b2f9e..685396a0 100644 --- a/packages/vipeye-internal/src/tests/samples/constructor3.py +++ b/packages/vipeye-internal/src/tests/samples/constructor3.py @@ -2,7 +2,7 @@ # for "chain") when the expected type is provided by another # constructor (in this case "list"). -# pyright: strict +# viper: strict from concurrent.futures import Future, wait from itertools import chain diff --git a/packages/vipeye-internal/src/tests/samples/dataclass1.py b/packages/vipeye-internal/src/tests/samples/dataclass1.py index 1ebd285b..45e59cb9 100644 --- a/packages/vipeye-internal/src/tests/samples/dataclass1.py +++ b/packages/vipeye-internal/src/tests/samples/dataclass1.py @@ -9,7 +9,7 @@ class DC1: bbb: int ccc: str aaa: str = "string" - __hash__: None # pyright: ignore[reportIncompatibleMethodOverride] + __hash__: None # viper: ignore[reportIncompatibleMethodOverride] bar1 = DC1(bbb=5, ccc="hello") diff --git a/packages/vipeye-internal/src/tests/samples/dataclass12.py b/packages/vipeye-internal/src/tests/samples/dataclass12.py index 17fdedf4..34e82b91 100644 --- a/packages/vipeye-internal/src/tests/samples/dataclass12.py +++ b/packages/vipeye-internal/src/tests/samples/dataclass12.py @@ -1,7 +1,7 @@ # This sample tests the case where a dataclass declares an instance # variable and a subclass redeclares it as a class variable. -# pyright: reportIncompatibleVariableOverride=false +# viper: reportIncompatibleVariableOverride=false from dataclasses import dataclass from typing import ClassVar diff --git a/packages/vipeye-internal/src/tests/samples/dataclass2.py b/packages/vipeye-internal/src/tests/samples/dataclass2.py index 69cd8c42..a332a96a 100644 --- a/packages/vipeye-internal/src/tests/samples/dataclass2.py +++ b/packages/vipeye-internal/src/tests/samples/dataclass2.py @@ -1,7 +1,7 @@ # This sample tests the handling of Callable fields within a # dataclass definition. -# pyright: strict +# viper: strict from dataclasses import dataclass from typing import Any, Callable, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/dataclass4.py b/packages/vipeye-internal/src/tests/samples/dataclass4.py index 31640b1f..8402f62c 100644 --- a/packages/vipeye-internal/src/tests/samples/dataclass4.py +++ b/packages/vipeye-internal/src/tests/samples/dataclass4.py @@ -1,7 +1,7 @@ # This sample tests the analyzer's ability to handle inherited # data classes. -# pyright: reportIncompatibleVariableOverride=false +# viper: reportIncompatibleVariableOverride=false from dataclasses import dataclass, field diff --git a/packages/vipeye-internal/src/tests/samples/dataclass5.py b/packages/vipeye-internal/src/tests/samples/dataclass5.py index deb471cb..fcd55d9c 100644 --- a/packages/vipeye-internal/src/tests/samples/dataclass5.py +++ b/packages/vipeye-internal/src/tests/samples/dataclass5.py @@ -1,7 +1,7 @@ # This sample tests the handling of the @dataclass decorator # with a custom __init__. -# pyright: reportIncompatibleMethodOverride=false +# viper: reportIncompatibleMethodOverride=false from dataclasses import dataclass diff --git a/packages/vipeye-internal/src/tests/samples/dataclassDescriptors2.py b/packages/vipeye-internal/src/tests/samples/dataclassDescriptors2.py index eb01ec04..c6850ea0 100644 --- a/packages/vipeye-internal/src/tests/samples/dataclassDescriptors2.py +++ b/packages/vipeye-internal/src/tests/samples/dataclassDescriptors2.py @@ -4,7 +4,7 @@ from dataclasses import dataclass from typing import overload, Any, TypeVar, Generic, Optional, Union, Callable, Type -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] dataclass_transform, ) diff --git a/packages/vipeye-internal/src/tests/samples/dataclassPostInit1.py b/packages/vipeye-internal/src/tests/samples/dataclassPostInit1.py index 297371ff..a89160e4 100644 --- a/packages/vipeye-internal/src/tests/samples/dataclassPostInit1.py +++ b/packages/vipeye-internal/src/tests/samples/dataclassPostInit1.py @@ -1,6 +1,6 @@ # This sample tests the __post_init__ validation logic. -# pyright: reportIncompatibleMethodOverride=false +# viper: reportIncompatibleMethodOverride=false from dataclasses import InitVar, dataclass, field from typing import Iterable diff --git a/packages/vipeye-internal/src/tests/samples/dataclassTransform1.py b/packages/vipeye-internal/src/tests/samples/dataclassTransform1.py index f5165928..b308d377 100644 --- a/packages/vipeye-internal/src/tests/samples/dataclassTransform1.py +++ b/packages/vipeye-internal/src/tests/samples/dataclassTransform1.py @@ -2,7 +2,7 @@ # when applied to a decorator function. from typing import Any, Callable, TypeVar, overload -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] dataclass_transform, ) diff --git a/packages/vipeye-internal/src/tests/samples/dataclassTransform2.py b/packages/vipeye-internal/src/tests/samples/dataclassTransform2.py index 9a7f35c4..75f76483 100644 --- a/packages/vipeye-internal/src/tests/samples/dataclassTransform2.py +++ b/packages/vipeye-internal/src/tests/samples/dataclassTransform2.py @@ -2,7 +2,7 @@ # when applied to a metaclass. from typing import Any, TypeVar -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] dataclass_transform, ) diff --git a/packages/vipeye-internal/src/tests/samples/decorator1.py b/packages/vipeye-internal/src/tests/samples/decorator1.py index 3c82568d..3de75291 100644 --- a/packages/vipeye-internal/src/tests/samples/decorator1.py +++ b/packages/vipeye-internal/src/tests/samples/decorator1.py @@ -1,7 +1,7 @@ # This sample tests the a class-based decorator that uses a # __get__ method as a way to provide access to a __call__ method. -# pyright: reportIncompatibleMethodOverride=false +# viper: reportIncompatibleMethodOverride=false class Wrapper: diff --git a/packages/vipeye-internal/src/tests/samples/decorator4.py b/packages/vipeye-internal/src/tests/samples/decorator4.py index 1791c5f5..c3c1edcd 100644 --- a/packages/vipeye-internal/src/tests/samples/decorator4.py +++ b/packages/vipeye-internal/src/tests/samples/decorator4.py @@ -1,7 +1,7 @@ # This sample tests whether a decorator that contains an unknown # type is ignored and treated as though it wasn't applied. -# pyright: reportMissingImports=false +# viper: reportMissingImports=false import my_module diff --git a/packages/vipeye-internal/src/tests/samples/deprecated2.py b/packages/vipeye-internal/src/tests/samples/deprecated2.py index 0825b491..0182004c 100644 --- a/packages/vipeye-internal/src/tests/samples/deprecated2.py +++ b/packages/vipeye-internal/src/tests/samples/deprecated2.py @@ -3,7 +3,7 @@ from contextlib import contextmanager from typing import Any, Callable, Self, TypeVar -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] deprecated, overload, ) diff --git a/packages/vipeye-internal/src/tests/samples/deprecated4.py b/packages/vipeye-internal/src/tests/samples/deprecated4.py index 492ddda3..53a02f2b 100644 --- a/packages/vipeye-internal/src/tests/samples/deprecated4.py +++ b/packages/vipeye-internal/src/tests/samples/deprecated4.py @@ -2,7 +2,7 @@ from typing import overload -from typing_extensions import deprecated # pyright: ignore[reportMissingModuleSource] +from typing_extensions import deprecated # viper: ignore[reportMissingModuleSource] class A: diff --git a/packages/vipeye-internal/src/tests/samples/deprecated6.py b/packages/vipeye-internal/src/tests/samples/deprecated6.py index dfef566d..31caa08f 100644 --- a/packages/vipeye-internal/src/tests/samples/deprecated6.py +++ b/packages/vipeye-internal/src/tests/samples/deprecated6.py @@ -1,7 +1,7 @@ # This sample tests the case where a __call__ is marked deprecated. from typing import Callable, Generic, ParamSpec, TypeVar -from typing_extensions import deprecated # pyright: ignore[reportMissingModuleSource] +from typing_extensions import deprecated # viper: ignore[reportMissingModuleSource] class A: diff --git a/packages/vipeye-internal/src/tests/samples/deprecated7.py b/packages/vipeye-internal/src/tests/samples/deprecated7.py index a4259945..c28461da 100644 --- a/packages/vipeye-internal/src/tests/samples/deprecated7.py +++ b/packages/vipeye-internal/src/tests/samples/deprecated7.py @@ -1,7 +1,7 @@ # This sample tests the case where a "deprecated" instance is instantiated # prior to being used as a decorator. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing_extensions import deprecated diff --git a/packages/vipeye-internal/src/tests/samples/deprecated8.py b/packages/vipeye-internal/src/tests/samples/deprecated8.py index 3d9e0a22..d2670e95 100644 --- a/packages/vipeye-internal/src/tests/samples/deprecated8.py +++ b/packages/vipeye-internal/src/tests/samples/deprecated8.py @@ -1,6 +1,6 @@ # This sample tests reporting of deprecated magic methods. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import Self, overload diff --git a/packages/vipeye-internal/src/tests/samples/deprecatedAlias2.py b/packages/vipeye-internal/src/tests/samples/deprecatedAlias2.py index 38a53cac..43cf2a25 100644 --- a/packages/vipeye-internal/src/tests/samples/deprecatedAlias2.py +++ b/packages/vipeye-internal/src/tests/samples/deprecatedAlias2.py @@ -3,7 +3,7 @@ # This test is heavily derived from deprecatedAlias1.py. -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] ChainMap as CM1, Counter as CT1, DefaultDict, diff --git a/packages/vipeye-internal/src/tests/samples/dunderAll1.py b/packages/vipeye-internal/src/tests/samples/dunderAll1.py index 6b44cc93..c1f5af5a 100644 --- a/packages/vipeye-internal/src/tests/samples/dunderAll1.py +++ b/packages/vipeye-internal/src/tests/samples/dunderAll1.py @@ -1,6 +1,6 @@ # This sample tests the reportUnsupportedDunderAll diagnostic rule. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import Any diff --git a/packages/vipeye-internal/src/tests/samples/dunderAll3.pyi b/packages/vipeye-internal/src/tests/samples/dunderAll3.pyi index 21d431e8..eb4d6628 100644 --- a/packages/vipeye-internal/src/tests/samples/dunderAll3.pyi +++ b/packages/vipeye-internal/src/tests/samples/dunderAll3.pyi @@ -1,7 +1,7 @@ # This sample tests that __all__ manipulations in a stub file are not # flagged as invalid stub statements. -# pyright: reportInvalidStubStatement=true +# viper: reportInvalidStubStatement=true import typing diff --git a/packages/vipeye-internal/src/tests/samples/duplicateDeclaration2.py b/packages/vipeye-internal/src/tests/samples/duplicateDeclaration2.py index de5623b9..257cf5e0 100644 --- a/packages/vipeye-internal/src/tests/samples/duplicateDeclaration2.py +++ b/packages/vipeye-internal/src/tests/samples/duplicateDeclaration2.py @@ -1,7 +1,7 @@ # This sample tests the detection of duplicate (overwritten) # properties. -# pyright: strict +# viper: strict class MyClass: diff --git a/packages/vipeye-internal/src/tests/samples/emptyContainers1.py b/packages/vipeye-internal/src/tests/samples/emptyContainers1.py index e3d5e90c..8919a6cd 100644 --- a/packages/vipeye-internal/src/tests/samples/emptyContainers1.py +++ b/packages/vipeye-internal/src/tests/samples/emptyContainers1.py @@ -1,6 +1,6 @@ # This sample tests type inference for empty lists and dictionaries. -# pyright: reportUnknownVariableType=true, reportUnknownArgumentType=true +# viper: reportUnknownVariableType=true, reportUnknownArgumentType=true def func1(a: bool): diff --git a/packages/vipeye-internal/src/tests/samples/enum8.py b/packages/vipeye-internal/src/tests/samples/enum8.py index 49afbf3d..8ce053dd 100644 --- a/packages/vipeye-internal/src/tests/samples/enum8.py +++ b/packages/vipeye-internal/src/tests/samples/enum8.py @@ -1,7 +1,7 @@ # This sample tests the case where an enum class is used as a bound # for a TypeVar and instantiated. -# pyright: strict +# viper: strict from enum import Enum from typing import TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/fstring2.py b/packages/vipeye-internal/src/tests/samples/fstring2.py index eb53bc30..b2e4156c 100644 --- a/packages/vipeye-internal/src/tests/samples/fstring2.py +++ b/packages/vipeye-internal/src/tests/samples/fstring2.py @@ -1,6 +1,6 @@ # This tests f-strings with format expressions. -# pyright: strict +# viper: strict def return_right_aligned_string(): diff --git a/packages/vipeye-internal/src/tests/samples/fstring3.py b/packages/vipeye-internal/src/tests/samples/fstring3.py index 8c74f179..5b697b1c 100644 --- a/packages/vipeye-internal/src/tests/samples/fstring3.py +++ b/packages/vipeye-internal/src/tests/samples/fstring3.py @@ -1,7 +1,7 @@ # This sample tests f-strings where expressions contain # other string literals. -# pyright: strict +# viper: strict a1 = f"[{{name}}{'}' if True else ''}]" diff --git a/packages/vipeye-internal/src/tests/samples/functionAnnotation1.py b/packages/vipeye-internal/src/tests/samples/functionAnnotation1.py index 51d296e4..b2703ddb 100644 --- a/packages/vipeye-internal/src/tests/samples/functionAnnotation1.py +++ b/packages/vipeye-internal/src/tests/samples/functionAnnotation1.py @@ -1,6 +1,6 @@ # This sample tests support for comment-style function annotations. -# pyright: strict, reportMissingParameterType=false, reportTypeCommentUsage=false +# viper: strict, reportMissingParameterType=false, reportTypeCommentUsage=false from typing import Optional, Literal as _Literal, Union diff --git a/packages/vipeye-internal/src/tests/samples/functionMember2.py b/packages/vipeye-internal/src/tests/samples/functionMember2.py index 329ef922..e156adda 100644 --- a/packages/vipeye-internal/src/tests/samples/functionMember2.py +++ b/packages/vipeye-internal/src/tests/samples/functionMember2.py @@ -1,7 +1,7 @@ # This sample tests the special-case handling of the __self__ # attribute for a function when it is bound to a class or object. -# pyright: reportFunctionMemberAccess=error +# viper: reportFunctionMemberAccess=error from typing import Protocol diff --git a/packages/vipeye-internal/src/tests/samples/generic3.py b/packages/vipeye-internal/src/tests/samples/generic3.py index f0de256e..b987ba21 100644 --- a/packages/vipeye-internal/src/tests/samples/generic3.py +++ b/packages/vipeye-internal/src/tests/samples/generic3.py @@ -1,7 +1,7 @@ # This sample tests that a Generic base class overrides the type parameter # ordering of other type parameters. -# pyright: reportIncompatibleMethodOverride=false +# viper: reportIncompatibleMethodOverride=false from typing import Generic, Iterable, Iterator, Mapping, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/genericType23.py b/packages/vipeye-internal/src/tests/samples/genericType23.py index 1d838a78..dca05975 100644 --- a/packages/vipeye-internal/src/tests/samples/genericType23.py +++ b/packages/vipeye-internal/src/tests/samples/genericType23.py @@ -1,7 +1,7 @@ # This sample tests that a recursive call to a generic function # evaluates correctly. -# pyright: strict +# viper: strict from typing import TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/genericType47.py b/packages/vipeye-internal/src/tests/samples/genericType47.py index 0c15043a..bedad80b 100644 --- a/packages/vipeye-internal/src/tests/samples/genericType47.py +++ b/packages/vipeye-internal/src/tests/samples/genericType47.py @@ -1,6 +1,6 @@ # This sample tests specialization of nested generic classes. -# pyright: strict +# viper: strict from typing import Collection, Generic, Iterable, Iterator, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/hashability1.py b/packages/vipeye-internal/src/tests/samples/hashability1.py index dbe2419c..55dd4873 100644 --- a/packages/vipeye-internal/src/tests/samples/hashability1.py +++ b/packages/vipeye-internal/src/tests/samples/hashability1.py @@ -1,7 +1,7 @@ # This sample tests the check for hashability that applies to entries # within a set expression and keys within a dictionary expression. -# pyright: reportIncompatibleVariableOverride=false +# viper: reportIncompatibleVariableOverride=false from dataclasses import dataclass from typing import Any diff --git a/packages/vipeye-internal/src/tests/samples/hashability2.py b/packages/vipeye-internal/src/tests/samples/hashability2.py index 44cce052..d1c606b1 100644 --- a/packages/vipeye-internal/src/tests/samples/hashability2.py +++ b/packages/vipeye-internal/src/tests/samples/hashability2.py @@ -1,6 +1,6 @@ # This sample tests that unhashable user classes are detected as unhashable. -# pyright: reportIncompatibleMethodOverride=false +# viper: reportIncompatibleMethodOverride=false class A: ... diff --git a/packages/vipeye-internal/src/tests/samples/import14.py b/packages/vipeye-internal/src/tests/samples/import14.py index 9d05c9c6..60ef227f 100644 --- a/packages/vipeye-internal/src/tests/samples/import14.py +++ b/packages/vipeye-internal/src/tests/samples/import14.py @@ -1,7 +1,7 @@ # This sample is used in conjunction with import13.py to test # PEP 562 (module-level __getattr__) support. -# pyright: strict +# viper: strict from .import13 import foo1 from . import import13 diff --git a/packages/vipeye-internal/src/tests/samples/import15.py b/packages/vipeye-internal/src/tests/samples/import15.py index 145f1675..1b62bb5c 100644 --- a/packages/vipeye-internal/src/tests/samples/import15.py +++ b/packages/vipeye-internal/src/tests/samples/import15.py @@ -4,7 +4,7 @@ try: from typing import TypedDict except ImportError: - from typing_extensions import TypedDict # pyright: ignore[reportMissingModuleSource] + from typing_extensions import TypedDict # viper: ignore[reportMissingModuleSource] class TD1(TypedDict): diff --git a/packages/vipeye-internal/src/tests/samples/isinstance2.py b/packages/vipeye-internal/src/tests/samples/isinstance2.py index f99fcf12..14930d75 100644 --- a/packages/vipeye-internal/src/tests/samples/isinstance2.py +++ b/packages/vipeye-internal/src/tests/samples/isinstance2.py @@ -2,7 +2,7 @@ # an unknown type and the type is used in an # isinstance check. -# pyright: reportUnnecessaryIsInstance=true +# viper: reportUnnecessaryIsInstance=true from typing import TypeVar, Union diff --git a/packages/vipeye-internal/src/tests/samples/kwargsUnpack1.py b/packages/vipeye-internal/src/tests/samples/kwargsUnpack1.py index 7dbb740f..e80a81c5 100644 --- a/packages/vipeye-internal/src/tests/samples/kwargsUnpack1.py +++ b/packages/vipeye-internal/src/tests/samples/kwargsUnpack1.py @@ -2,7 +2,7 @@ # a **kwargs parameter in a function signature. from typing import Protocol, TypedDict -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] NotRequired, Required, Unpack, diff --git a/packages/vipeye-internal/src/tests/samples/kwargsUnpack2.py b/packages/vipeye-internal/src/tests/samples/kwargsUnpack2.py index e4325de1..a11f3435 100644 --- a/packages/vipeye-internal/src/tests/samples/kwargsUnpack2.py +++ b/packages/vipeye-internal/src/tests/samples/kwargsUnpack2.py @@ -4,7 +4,7 @@ # keyword parameters (both for display and for call argument checking). from typing import Generic, TypeVar -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypedDict, Unpack, ) diff --git a/packages/vipeye-internal/src/tests/samples/lambda10.py b/packages/vipeye-internal/src/tests/samples/lambda10.py index 8195e4e4..50818c90 100644 --- a/packages/vipeye-internal/src/tests/samples/lambda10.py +++ b/packages/vipeye-internal/src/tests/samples/lambda10.py @@ -1,6 +1,6 @@ # This sample tests the handling of immediately-called lambdas. -# pyright: strict +# viper: strict from typing import Callable diff --git a/packages/vipeye-internal/src/tests/samples/lambda12.py b/packages/vipeye-internal/src/tests/samples/lambda12.py index f1c287d1..e81cebee 100644 --- a/packages/vipeye-internal/src/tests/samples/lambda12.py +++ b/packages/vipeye-internal/src/tests/samples/lambda12.py @@ -3,7 +3,7 @@ # these parameters. In this case, the types of the extra parameters should # be inferred based on the default value type. -# pyright: strict +# viper: strict from typing import Callable diff --git a/packages/vipeye-internal/src/tests/samples/lambda15.py b/packages/vipeye-internal/src/tests/samples/lambda15.py index a2321df9..75fdc1bb 100644 --- a/packages/vipeye-internal/src/tests/samples/lambda15.py +++ b/packages/vipeye-internal/src/tests/samples/lambda15.py @@ -2,7 +2,7 @@ # where both __new__ and __init__ methods are present and have different # types. -# pyright: strict +# viper: strict from typing import Any, TypeVar, Callable diff --git a/packages/vipeye-internal/src/tests/samples/lambda7.py b/packages/vipeye-internal/src/tests/samples/lambda7.py index 4428736b..e9287e2c 100644 --- a/packages/vipeye-internal/src/tests/samples/lambda7.py +++ b/packages/vipeye-internal/src/tests/samples/lambda7.py @@ -2,7 +2,7 @@ # evaluated multiple times as more type information is gathered # in the presence of an overloaded method. -# pyright: strict +# viper: strict def func1(keys: list[str]): diff --git a/packages/vipeye-internal/src/tests/samples/list1.py b/packages/vipeye-internal/src/tests/samples/list1.py index 605bf7f1..08260244 100644 --- a/packages/vipeye-internal/src/tests/samples/list1.py +++ b/packages/vipeye-internal/src/tests/samples/list1.py @@ -1,6 +1,6 @@ # This sample tests type inference for list expressions. -# pyright: strict, reportUnknownVariableType=false +# viper: strict, reportUnknownVariableType=false from typing import Any, Collection, Generic, Literal, MutableSequence, Sequence, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/list2.py b/packages/vipeye-internal/src/tests/samples/list2.py index fe004812..971c03ad 100644 --- a/packages/vipeye-internal/src/tests/samples/list2.py +++ b/packages/vipeye-internal/src/tests/samples/list2.py @@ -2,7 +2,7 @@ # reported up for correct overload selection. import random -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] LiteralString, ) diff --git a/packages/vipeye-internal/src/tests/samples/literalForLoop1.py b/packages/vipeye-internal/src/tests/samples/literalForLoop1.py index 40555017..dc8f9493 100644 --- a/packages/vipeye-internal/src/tests/samples/literalForLoop1.py +++ b/packages/vipeye-internal/src/tests/samples/literalForLoop1.py @@ -2,7 +2,7 @@ # expressions are treated as executing at least once for definite assignment # analysis. -# pyright: reportPossiblyUnboundVariable=true +# viper: reportPossiblyUnboundVariable=true def test_non_empty_list_literal(): diff --git a/packages/vipeye-internal/src/tests/samples/literalString1.py b/packages/vipeye-internal/src/tests/samples/literalString1.py index 71f404ac..45a6192e 100644 --- a/packages/vipeye-internal/src/tests/samples/literalString1.py +++ b/packages/vipeye-internal/src/tests/samples/literalString1.py @@ -2,7 +2,7 @@ # in PEP 675. from typing import Iterable -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] Literal, LiteralString, ) diff --git a/packages/vipeye-internal/src/tests/samples/literalString2.py b/packages/vipeye-internal/src/tests/samples/literalString2.py index 472b874c..6b3dfd3d 100644 --- a/packages/vipeye-internal/src/tests/samples/literalString2.py +++ b/packages/vipeye-internal/src/tests/samples/literalString2.py @@ -2,7 +2,7 @@ # type variable. from typing import TypeVar, Generic -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] LiteralString, ) diff --git a/packages/vipeye-internal/src/tests/samples/loop13.py b/packages/vipeye-internal/src/tests/samples/loop13.py index 5ef58bb8..6bf83c99 100644 --- a/packages/vipeye-internal/src/tests/samples/loop13.py +++ b/packages/vipeye-internal/src/tests/samples/loop13.py @@ -1,7 +1,7 @@ # This sample tests the case where a loop uses tuple assignments. It verifies # that no "unknown" values are evaluated for variables assigned in the loop. -# pyright: strict +# viper: strict nums: list[int] = [1, 2, 3] max_product, min_product = nums[0], nums[0] diff --git a/packages/vipeye-internal/src/tests/samples/loop15.py b/packages/vipeye-internal/src/tests/samples/loop15.py index 6cf4ed21..238b28bd 100644 --- a/packages/vipeye-internal/src/tests/samples/loop15.py +++ b/packages/vipeye-internal/src/tests/samples/loop15.py @@ -1,7 +1,7 @@ # This sample tests loops that contain nested comprehensions and # variables that depend on each other. -# pyright: strict +# viper: strict def func1(boards: list[list[list[int]]]): diff --git a/packages/vipeye-internal/src/tests/samples/loop18.py b/packages/vipeye-internal/src/tests/samples/loop18.py index e6ad198d..04100621 100644 --- a/packages/vipeye-internal/src/tests/samples/loop18.py +++ b/packages/vipeye-internal/src/tests/samples/loop18.py @@ -1,6 +1,6 @@ # This sample tests type narrowing in a loop. -from typing_extensions import Self # pyright: ignore[reportMissingModuleSource] +from typing_extensions import Self # viper: ignore[reportMissingModuleSource] from collections.abc import Generator diff --git a/packages/vipeye-internal/src/tests/samples/loop21.py b/packages/vipeye-internal/src/tests/samples/loop21.py index 2b835a80..ad8c6b0e 100644 --- a/packages/vipeye-internal/src/tests/samples/loop21.py +++ b/packages/vipeye-internal/src/tests/samples/loop21.py @@ -1,7 +1,7 @@ # This sample tests a loop where some of the variables within the loop # depend on each other. -# pyright: strict +# viper: strict def find_min(nums: list[int]) -> int: diff --git a/packages/vipeye-internal/src/tests/samples/loop22.py b/packages/vipeye-internal/src/tests/samples/loop22.py index bd2e9d75..174e1d08 100644 --- a/packages/vipeye-internal/src/tests/samples/loop22.py +++ b/packages/vipeye-internal/src/tests/samples/loop22.py @@ -1,7 +1,7 @@ # This sample tests a case where a loop contains multiple conditional # checks. -# pyright: strict +# viper: strict from __future__ import annotations diff --git a/packages/vipeye-internal/src/tests/samples/loop24.py b/packages/vipeye-internal/src/tests/samples/loop24.py index 45942c39..b1dafe97 100644 --- a/packages/vipeye-internal/src/tests/samples/loop24.py +++ b/packages/vipeye-internal/src/tests/samples/loop24.py @@ -1,7 +1,7 @@ # This sample tests a loop that involves assignment of a tuple # within a loop. -# pyright: strict +# viper: strict var = 0 while True: diff --git a/packages/vipeye-internal/src/tests/samples/loop26.py b/packages/vipeye-internal/src/tests/samples/loop26.py index 09c7ff05..e1298339 100644 --- a/packages/vipeye-internal/src/tests/samples/loop26.py +++ b/packages/vipeye-internal/src/tests/samples/loop26.py @@ -1,6 +1,6 @@ # This sample tests proper type narrowing within a double loop. -# pyright: strict +# viper: strict from typing import Callable diff --git a/packages/vipeye-internal/src/tests/samples/loop27.py b/packages/vipeye-internal/src/tests/samples/loop27.py index 0674551c..f1eb72fc 100644 --- a/packages/vipeye-internal/src/tests/samples/loop27.py +++ b/packages/vipeye-internal/src/tests/samples/loop27.py @@ -1,7 +1,7 @@ # This sample tests the case where an annotated variable in a loop # is used as an index, an implicit argument for __getitem__. -# pyright: strict +# viper: strict def func1(nums: list[int], target: int) -> None: diff --git a/packages/vipeye-internal/src/tests/samples/loop35.py b/packages/vipeye-internal/src/tests/samples/loop35.py index 835c4f4b..dc80dc49 100644 --- a/packages/vipeye-internal/src/tests/samples/loop35.py +++ b/packages/vipeye-internal/src/tests/samples/loop35.py @@ -1,7 +1,7 @@ # This sample tests that code flow analysis of a list comprehension # within a loop eliminates any Unknowns. -# pyright: strict +# viper: strict lst = [1] while True: diff --git a/packages/vipeye-internal/src/tests/samples/loop36.py b/packages/vipeye-internal/src/tests/samples/loop36.py index 218273b5..e4c45870 100644 --- a/packages/vipeye-internal/src/tests/samples/loop36.py +++ b/packages/vipeye-internal/src/tests/samples/loop36.py @@ -1,7 +1,7 @@ # This sample tests code that uses an augmented assignment to a subscript # within a loop. -# pyright: strict +# viper: strict from typing import Any diff --git a/packages/vipeye-internal/src/tests/samples/loop37.py b/packages/vipeye-internal/src/tests/samples/loop37.py index 8906077d..476c63a2 100644 --- a/packages/vipeye-internal/src/tests/samples/loop37.py +++ b/packages/vipeye-internal/src/tests/samples/loop37.py @@ -1,7 +1,7 @@ # This sample tests that a variable assigned in a doubly-nested loop # eliminates any Unknowns. -# pyright: strict +# viper: strict def func(): diff --git a/packages/vipeye-internal/src/tests/samples/loop38.py b/packages/vipeye-internal/src/tests/samples/loop38.py index 22767163..5ce66a75 100644 --- a/packages/vipeye-internal/src/tests/samples/loop38.py +++ b/packages/vipeye-internal/src/tests/samples/loop38.py @@ -2,7 +2,7 @@ # and a variable that is assigned only in the outer loop. -# pyright: strict +# viper: strict # * Code flow graph for func1: diff --git a/packages/vipeye-internal/src/tests/samples/loop39.py b/packages/vipeye-internal/src/tests/samples/loop39.py index 43015435..c61ba99d 100644 --- a/packages/vipeye-internal/src/tests/samples/loop39.py +++ b/packages/vipeye-internal/src/tests/samples/loop39.py @@ -1,7 +1,7 @@ # This sample tests a loop where there are multiple symbols # that depend on each other. -# pyright: strict +# viper: strict def func1() -> str | None: ... diff --git a/packages/vipeye-internal/src/tests/samples/loop40.py b/packages/vipeye-internal/src/tests/samples/loop40.py index 494853e3..1662ed1e 100644 --- a/packages/vipeye-internal/src/tests/samples/loop40.py +++ b/packages/vipeye-internal/src/tests/samples/loop40.py @@ -1,7 +1,7 @@ # This sample verifies that unknown types are properly eliminated from # a loop. -# pyright: strict +# viper: strict def func1(a: int, b: str, c: str): diff --git a/packages/vipeye-internal/src/tests/samples/loop42.py b/packages/vipeye-internal/src/tests/samples/loop42.py index 6805e85d..f0577977 100644 --- a/packages/vipeye-internal/src/tests/samples/loop42.py +++ b/packages/vipeye-internal/src/tests/samples/loop42.py @@ -2,7 +2,7 @@ # a loop where the act of determining whether it's a supported type # guard results in a circular dependency between variables. -# pyright: reportUnnecessaryComparison=true +# viper: reportUnnecessaryComparison=true def func1(): diff --git a/packages/vipeye-internal/src/tests/samples/loop48.py b/packages/vipeye-internal/src/tests/samples/loop48.py index 55539fe7..9bf6027a 100644 --- a/packages/vipeye-internal/src/tests/samples/loop48.py +++ b/packages/vipeye-internal/src/tests/samples/loop48.py @@ -1,7 +1,7 @@ # This sample tests a case where an instance variable is assigned within # a loop using its own value. -# pyright: strict +# viper: strict class ClassA: diff --git a/packages/vipeye-internal/src/tests/samples/loop5.py b/packages/vipeye-internal/src/tests/samples/loop5.py index 31f79353..e90274c9 100644 --- a/packages/vipeye-internal/src/tests/samples/loop5.py +++ b/packages/vipeye-internal/src/tests/samples/loop5.py @@ -2,7 +2,7 @@ # ("a") is involved in a recursive type dependency # ("a" depends on "test" which depends on "a"). -# pyright: strict +# viper: strict test = {"key": "value"} diff --git a/packages/vipeye-internal/src/tests/samples/loop8.py b/packages/vipeye-internal/src/tests/samples/loop8.py index ee09691c..818034a0 100644 --- a/packages/vipeye-internal/src/tests/samples/loop8.py +++ b/packages/vipeye-internal/src/tests/samples/loop8.py @@ -1,7 +1,7 @@ # This sample tests a difficult set of circular dependencies # between untyped variables. -# pyright: strict +# viper: strict from typing import Iterable diff --git a/packages/vipeye-internal/src/tests/samples/loop9.py b/packages/vipeye-internal/src/tests/samples/loop9.py index 8e162cc5..6548c8a1 100644 --- a/packages/vipeye-internal/src/tests/samples/loop9.py +++ b/packages/vipeye-internal/src/tests/samples/loop9.py @@ -1,7 +1,7 @@ # This sample tests a difficult set of circular dependencies # between untyped variables. -# pyright: strict +# viper: strict from typing import Dict diff --git a/packages/vipeye-internal/src/tests/samples/matchClass1.py b/packages/vipeye-internal/src/tests/samples/matchClass1.py index 0c7b30ed..7e2bf0f9 100644 --- a/packages/vipeye-internal/src/tests/samples/matchClass1.py +++ b/packages/vipeye-internal/src/tests/samples/matchClass1.py @@ -11,7 +11,7 @@ from typing import ( TypedDict, runtime_checkable, ) -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] LiteralString, ) from dataclasses import dataclass, field diff --git a/packages/vipeye-internal/src/tests/samples/matchMapping1.py b/packages/vipeye-internal/src/tests/samples/matchMapping1.py index 9359dfa0..e90ee119 100644 --- a/packages/vipeye-internal/src/tests/samples/matchMapping1.py +++ b/packages/vipeye-internal/src/tests/samples/matchMapping1.py @@ -3,7 +3,7 @@ from typing import Literal, TypedDict -from typing_extensions import NotRequired # pyright: ignore[reportMissingModuleSource] +from typing_extensions import NotRequired # viper: ignore[reportMissingModuleSource] def test_unknown(value_to_match): diff --git a/packages/vipeye-internal/src/tests/samples/matchSequence1.py b/packages/vipeye-internal/src/tests/samples/matchSequence1.py index 8431992c..d192feea 100644 --- a/packages/vipeye-internal/src/tests/samples/matchSequence1.py +++ b/packages/vipeye-internal/src/tests/samples/matchSequence1.py @@ -1,7 +1,7 @@ # This sample tests type checking for match statements (as # described in PEP 634) that contain sequence patterns. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from enum import Enum from typing import ( diff --git a/packages/vipeye-internal/src/tests/samples/matchValue1.py b/packages/vipeye-internal/src/tests/samples/matchValue1.py index 94a1b263..8c3705a4 100644 --- a/packages/vipeye-internal/src/tests/samples/matchValue1.py +++ b/packages/vipeye-internal/src/tests/samples/matchValue1.py @@ -6,7 +6,7 @@ from enum import Enum, auto from http import HTTPStatus from typing import Annotated, Literal, TypeVar -# pyright: reportIncompatibleMethodOverride=false +# viper: reportIncompatibleMethodOverride=false def handle_reply(reply: tuple[HTTPStatus, str] | tuple[HTTPStatus]): diff --git a/packages/vipeye-internal/src/tests/samples/memberAccess16.py b/packages/vipeye-internal/src/tests/samples/memberAccess16.py index fb98fabb..27656e18 100644 --- a/packages/vipeye-internal/src/tests/samples/memberAccess16.py +++ b/packages/vipeye-internal/src/tests/samples/memberAccess16.py @@ -1,7 +1,7 @@ # This sample tests the case where a member is accessed from a "type" # instance or a Type[T]. -# pyright: strict +# viper: strict from typing import TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/memberAccess6.py b/packages/vipeye-internal/src/tests/samples/memberAccess6.py index ce934fd3..03f1175b 100644 --- a/packages/vipeye-internal/src/tests/samples/memberAccess6.py +++ b/packages/vipeye-internal/src/tests/samples/memberAccess6.py @@ -1,7 +1,7 @@ # This sample tests member access "set" operations when the target # member is an object that doesn't provide a __set__ method. -# pyright: strict +# viper: strict from typing import Any, Generic, TypeVar, overload diff --git a/packages/vipeye-internal/src/tests/samples/metaclass5.py b/packages/vipeye-internal/src/tests/samples/metaclass5.py index 1eb67118..c8277735 100644 --- a/packages/vipeye-internal/src/tests/samples/metaclass5.py +++ b/packages/vipeye-internal/src/tests/samples/metaclass5.py @@ -1,7 +1,7 @@ # This sample tests the handling of metaclass magic methods for # binary operators. -# pyright: reportIncompatibleMethodOverride=false +# viper: reportIncompatibleMethodOverride=false class MetaA(type): diff --git a/packages/vipeye-internal/src/tests/samples/metaclass7.py b/packages/vipeye-internal/src/tests/samples/metaclass7.py index 8a8a3fcd..9f5cec40 100644 --- a/packages/vipeye-internal/src/tests/samples/metaclass7.py +++ b/packages/vipeye-internal/src/tests/samples/metaclass7.py @@ -2,7 +2,7 @@ # __call__ method, thus overriding the __new__ method on classes # that are created from it. -# pyright: reportIncompatibleMethodOverride=false +# viper: reportIncompatibleMethodOverride=false from typing import Any, Self diff --git a/packages/vipeye-internal/src/tests/samples/methodOverride4.py b/packages/vipeye-internal/src/tests/samples/methodOverride4.py index 1902c225..5392596f 100644 --- a/packages/vipeye-internal/src/tests/samples/methodOverride4.py +++ b/packages/vipeye-internal/src/tests/samples/methodOverride4.py @@ -1,7 +1,7 @@ # This sample tests the handling of methods that combine TypeVars # from a class and local method TypeVars in an override. -# pyright: strict +# viper: strict from abc import abstractmethod from typing import Callable, Generic, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/methodOverride5.py b/packages/vipeye-internal/src/tests/samples/methodOverride5.py index e401c51b..f95aadd4 100644 --- a/packages/vipeye-internal/src/tests/samples/methodOverride5.py +++ b/packages/vipeye-internal/src/tests/samples/methodOverride5.py @@ -2,7 +2,7 @@ # tuple or a specialized TypeVarTuple and is overridden by a method # that supplies specific arguments. -# pyright: strict +# viper: strict from typing import Generic, TypeVarTuple diff --git a/packages/vipeye-internal/src/tests/samples/mro2.py b/packages/vipeye-internal/src/tests/samples/mro2.py index a60ece37..4ddb78f7 100644 --- a/packages/vipeye-internal/src/tests/samples/mro2.py +++ b/packages/vipeye-internal/src/tests/samples/mro2.py @@ -1,7 +1,7 @@ # This sample tests the type checker's handling # of proper method resolution order (MRO). -# pyright: reportIncompatibleMethodOverride=false +# viper: reportIncompatibleMethodOverride=false class A: diff --git a/packages/vipeye-internal/src/tests/samples/never1.py b/packages/vipeye-internal/src/tests/samples/never1.py index 76d7b387..469fa21f 100644 --- a/packages/vipeye-internal/src/tests/samples/never1.py +++ b/packages/vipeye-internal/src/tests/samples/never1.py @@ -2,7 +2,7 @@ # ensuring that it's treated as the same as NoReturn. from typing import NoReturn, TypeVar, Generic -from typing_extensions import Never # pyright: ignore[reportMissingModuleSource] +from typing_extensions import Never # viper: ignore[reportMissingModuleSource] T = TypeVar("T") diff --git a/packages/vipeye-internal/src/tests/samples/newType2.py b/packages/vipeye-internal/src/tests/samples/newType2.py index caf8df91..27e99a47 100644 --- a/packages/vipeye-internal/src/tests/samples/newType2.py +++ b/packages/vipeye-internal/src/tests/samples/newType2.py @@ -1,7 +1,7 @@ # This sample tests the special-case handle of the multi-parameter # form of the built-in "type" call. -# pyright: strict +# viper: strict X1 = type("X1", (object,), {}) X2 = type("X2", (object,), {}) diff --git a/packages/vipeye-internal/src/tests/samples/operator1.py b/packages/vipeye-internal/src/tests/samples/operator1.py index 50749f38..383df18e 100644 --- a/packages/vipeye-internal/src/tests/samples/operator1.py +++ b/packages/vipeye-internal/src/tests/samples/operator1.py @@ -1,7 +1,7 @@ # This sample tests the type checker's ability to check # custom operator overrides. -# pyright: reportIncompatibleMethodOverride=false +# viper: reportIncompatibleMethodOverride=false from typing import NoReturn, Self diff --git a/packages/vipeye-internal/src/tests/samples/optional2.py b/packages/vipeye-internal/src/tests/samples/optional2.py index 998105bd..0a8d552e 100644 --- a/packages/vipeye-internal/src/tests/samples/optional2.py +++ b/packages/vipeye-internal/src/tests/samples/optional2.py @@ -1,7 +1,7 @@ # This sample verifies that the reportOptionalOperand diagnostic # isn't generated when the RHS operand accepts None. -# pyright: reportIncompatibleMethodOverride=false +# viper: reportIncompatibleMethodOverride=false from typing import Optional diff --git a/packages/vipeye-internal/src/tests/samples/overloadCall6.py b/packages/vipeye-internal/src/tests/samples/overloadCall6.py index f40c9c34..388fc042 100644 --- a/packages/vipeye-internal/src/tests/samples/overloadCall6.py +++ b/packages/vipeye-internal/src/tests/samples/overloadCall6.py @@ -1,7 +1,7 @@ # This sample tests overload matching in cases where the match # is ambiguous due to an Any or Unknown argument. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import Any, Generic, Literal, TypeVar, overload from typing_extensions import LiteralString, TypeIs diff --git a/packages/vipeye-internal/src/tests/samples/overloadImpl3.py b/packages/vipeye-internal/src/tests/samples/overloadImpl3.py index 09ddcd26..639fbabe 100644 --- a/packages/vipeye-internal/src/tests/samples/overloadImpl3.py +++ b/packages/vipeye-internal/src/tests/samples/overloadImpl3.py @@ -3,7 +3,7 @@ # checks. The implementation signature is ignored by the type checker, so its # parameters are allowed to remain unannotated. -# pyright: strict +# viper: strict from typing import overload diff --git a/packages/vipeye-internal/src/tests/samples/overloadOverride1.py b/packages/vipeye-internal/src/tests/samples/overloadOverride1.py index 5fb09970..defc34c0 100644 --- a/packages/vipeye-internal/src/tests/samples/overloadOverride1.py +++ b/packages/vipeye-internal/src/tests/samples/overloadOverride1.py @@ -1,7 +1,7 @@ # This sample tests the case where a base class method is overridden # in a derived class with an overloaded method. -# pyright: reportIncompatibleMethodOverride=true +# viper: reportIncompatibleMethodOverride=true from typing import overload diff --git a/packages/vipeye-internal/src/tests/samples/override1.py b/packages/vipeye-internal/src/tests/samples/override1.py index 99ab73d1..6821fe48 100644 --- a/packages/vipeye-internal/src/tests/samples/override1.py +++ b/packages/vipeye-internal/src/tests/samples/override1.py @@ -2,7 +2,7 @@ # in PEP 698. from typing import Callable, Protocol -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] Any, overload, override, diff --git a/packages/vipeye-internal/src/tests/samples/override2.py b/packages/vipeye-internal/src/tests/samples/override2.py index 530a7f97..315d7ec1 100644 --- a/packages/vipeye-internal/src/tests/samples/override2.py +++ b/packages/vipeye-internal/src/tests/samples/override2.py @@ -2,7 +2,7 @@ # (strict enforcement of PEP 698). from typing import Any, Callable -from typing_extensions import override # pyright: ignore[reportMissingModuleSource] +from typing_extensions import override # viper: ignore[reportMissingModuleSource] def evil_wrapper(func: Callable[..., Any], /): diff --git a/packages/vipeye-internal/src/tests/samples/paramInference2.py b/packages/vipeye-internal/src/tests/samples/paramInference2.py index 07ea15e0..a0d151e1 100644 --- a/packages/vipeye-internal/src/tests/samples/paramInference2.py +++ b/packages/vipeye-internal/src/tests/samples/paramInference2.py @@ -1,7 +1,7 @@ # This sample tests the logic that infers parameter types based on # annotated base class methods when the base class is generic. -# pyright: reportIncompatibleMethodOverride=false +# viper: reportIncompatibleMethodOverride=false from typing import Callable, Generic, ParamSpec, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec15.py b/packages/vipeye-internal/src/tests/samples/paramSpec15.py index f716d608..1fd84e76 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec15.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec15.py @@ -2,7 +2,7 @@ # with a ParamSpec. from typing import Callable, Generic, TypeVar -from typing_extensions import ParamSpec # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ParamSpec # viper: ignore[reportMissingModuleSource] P = ParamSpec("P") T = TypeVar("T") diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec16.py b/packages/vipeye-internal/src/tests/samples/paramSpec16.py index 3a11a6ce..5fb06c3d 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec16.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec16.py @@ -2,7 +2,7 @@ # ParamSpec. from typing import Callable, Generic, TypeVar -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] Concatenate, ParamSpec, ) diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec17.py b/packages/vipeye-internal/src/tests/samples/paramSpec17.py index 1bde4d42..57d73cec 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec17.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec17.py @@ -1,11 +1,11 @@ # This sample validates that *P.args and **P.kwargs can be used as a # tuple and dict, respectively. -# pyright: strict +# viper: strict from collections.abc import Callable from typing import Any -from typing_extensions import ParamSpec # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ParamSpec # viper: ignore[reportMissingModuleSource] P = ParamSpec("P") diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec19.py b/packages/vipeye-internal/src/tests/samples/paramSpec19.py index 462cb686..0d7534b8 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec19.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec19.py @@ -2,7 +2,7 @@ # type alias with a Callable. from typing import Any, Callable, Generic, Protocol -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] Concatenate, ParamSpec, ) diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec21.py b/packages/vipeye-internal/src/tests/samples/paramSpec21.py index 64a54c6b..89748cf5 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec21.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec21.py @@ -2,7 +2,7 @@ # and destination callback protocol. from typing import Callable, Protocol -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] Concatenate, ParamSpec, ) diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec22.py b/packages/vipeye-internal/src/tests/samples/paramSpec22.py index 1c826b13..f848bbe9 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec22.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec22.py @@ -3,7 +3,7 @@ # uses a ParamSpec. from typing import Callable, Generic, TypeVar -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] Concatenate, ParamSpec, ) diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec23.py b/packages/vipeye-internal/src/tests/samples/paramSpec23.py index 1e7cecb3..38cec040 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec23.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec23.py @@ -3,7 +3,7 @@ from typing import Callable, TypeVar -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] Concatenate, ParamSpec, ) diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec24.py b/packages/vipeye-internal/src/tests/samples/paramSpec24.py index 82b2d312..094636f0 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec24.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec24.py @@ -2,10 +2,10 @@ # is used as an input parameter to a function that returns a generic # type parameterized by a ParamSpec and specialized with a Concatenate. -# pyright: reportOverlappingOverload=false +# viper: reportOverlappingOverload=false from __future__ import annotations -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] Self, Concatenate, ParamSpec, diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec27.py b/packages/vipeye-internal/src/tests/samples/paramSpec27.py index 1521ecdb..f6ab838d 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec27.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec27.py @@ -2,7 +2,7 @@ # a generic class parameterized by a ParamSpec. from typing import Callable, Generic, Protocol, assert_type -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] Concatenate, ParamSpec, TypeAlias, diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec28.py b/packages/vipeye-internal/src/tests/samples/paramSpec28.py index f13fed80..a76c418f 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec28.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec28.py @@ -1,6 +1,6 @@ # This sample tests a complicated combination of ParamSpec usage. -# pyright: strict +# viper: strict from typing import Any, Callable, Concatenate, ParamSpec, Protocol, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec30.py b/packages/vipeye-internal/src/tests/samples/paramSpec30.py index 7b24bbc5..5e33fbb2 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec30.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec30.py @@ -1,9 +1,9 @@ # This sample tests a complicated combination of ParamSpec usage. -# pyright: strict +# viper: strict from typing import Callable, TypeVar, overload -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] Concatenate, ParamSpec, ) diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec31.py b/packages/vipeye-internal/src/tests/samples/paramSpec31.py index 7d44a58d..d6cc5ae6 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec31.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec31.py @@ -2,7 +2,7 @@ # when it binds to a ParamSpec. from typing import Any, Callable, TypeVar -from typing_extensions import ParamSpec # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ParamSpec # viper: ignore[reportMissingModuleSource] T = TypeVar("T") P = ParamSpec("P") diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec32.py b/packages/vipeye-internal/src/tests/samples/paramSpec32.py index 0d06483c..bb2dae9a 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec32.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec32.py @@ -2,7 +2,7 @@ # parameters are used within a constructor. from typing import Callable, Generic, TypeVar -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] Concatenate, ParamSpec, ) diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec33.py b/packages/vipeye-internal/src/tests/samples/paramSpec33.py index 83158975..3cf20a16 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec33.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec33.py @@ -3,7 +3,7 @@ # by an outer function that uses P in its return type. from typing import Callable, Concatenate -from typing_extensions import ParamSpec # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ParamSpec # viper: ignore[reportMissingModuleSource] P = ParamSpec("P") diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec34.py b/packages/vipeye-internal/src/tests/samples/paramSpec34.py index a316a9fa..82a7aab0 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec34.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec34.py @@ -2,7 +2,7 @@ import functools from typing import Callable, TypeVar -from typing_extensions import ParamSpec # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ParamSpec # viper: ignore[reportMissingModuleSource] P = ParamSpec("P") R = TypeVar("R") diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec39.py b/packages/vipeye-internal/src/tests/samples/paramSpec39.py index 03b0eddc..d3277ce4 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec39.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec39.py @@ -3,7 +3,7 @@ # within the type evaluator. from typing import TypeVar, Callable -from typing_extensions import ParamSpec # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ParamSpec # viper: ignore[reportMissingModuleSource] P = ParamSpec("P") R = TypeVar("R") diff --git a/packages/vipeye-internal/src/tests/samples/paramSpec51.py b/packages/vipeye-internal/src/tests/samples/paramSpec51.py index 7b619957..217b57f7 100644 --- a/packages/vipeye-internal/src/tests/samples/paramSpec51.py +++ b/packages/vipeye-internal/src/tests/samples/paramSpec51.py @@ -2,7 +2,7 @@ # of several overloads but not in others. from typing import Callable, Concatenate, overload, Any -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] ParamSpec, Self, ) diff --git a/packages/vipeye-internal/src/tests/samples/project1/pyrightconfig.json b/packages/vipeye-internal/src/tests/samples/project1/viperconfig.json similarity index 100% rename from packages/vipeye-internal/src/tests/samples/project1/pyrightconfig.json rename to packages/vipeye-internal/src/tests/samples/project1/viperconfig.json diff --git a/packages/vipeye-internal/src/tests/samples/project2/pyrightconfig.json b/packages/vipeye-internal/src/tests/samples/project2/viperconfig.json similarity index 100% rename from packages/vipeye-internal/src/tests/samples/project2/pyrightconfig.json rename to packages/vipeye-internal/src/tests/samples/project2/viperconfig.json diff --git a/packages/vipeye-internal/src/tests/samples/project3/pyrightconfig.json b/packages/vipeye-internal/src/tests/samples/project3/viperconfig.json similarity index 100% rename from packages/vipeye-internal/src/tests/samples/project3/pyrightconfig.json rename to packages/vipeye-internal/src/tests/samples/project3/viperconfig.json diff --git a/packages/vipeye-internal/src/tests/samples/project4/pyrightconfig.json b/packages/vipeye-internal/src/tests/samples/project4/viperconfig.json similarity index 100% rename from packages/vipeye-internal/src/tests/samples/project4/pyrightconfig.json rename to packages/vipeye-internal/src/tests/samples/project4/viperconfig.json diff --git a/packages/vipeye-internal/src/tests/samples/project5/pyrightconfig.json b/packages/vipeye-internal/src/tests/samples/project5/viperconfig.json similarity index 100% rename from packages/vipeye-internal/src/tests/samples/project5/pyrightconfig.json rename to packages/vipeye-internal/src/tests/samples/project5/viperconfig.json diff --git a/packages/vipeye-internal/src/tests/samples/project_src_with_config_extra_paths/pyrightconfig.json b/packages/vipeye-internal/src/tests/samples/project_src_with_config_extra_paths/viperconfig.json similarity index 100% rename from packages/vipeye-internal/src/tests/samples/project_src_with_config_extra_paths/pyrightconfig.json rename to packages/vipeye-internal/src/tests/samples/project_src_with_config_extra_paths/viperconfig.json diff --git a/packages/vipeye-internal/src/tests/samples/project_src_with_config_no_extra_paths/pyrightconfig.json b/packages/vipeye-internal/src/tests/samples/project_src_with_config_no_extra_paths/viperconfig.json similarity index 100% rename from packages/vipeye-internal/src/tests/samples/project_src_with_config_no_extra_paths/pyrightconfig.json rename to packages/vipeye-internal/src/tests/samples/project_src_with_config_no_extra_paths/viperconfig.json diff --git a/packages/vipeye-internal/src/tests/samples/project_with_all_config/pyrightconfig.json b/packages/vipeye-internal/src/tests/samples/project_with_all_config/viperconfig.json similarity index 100% rename from packages/vipeye-internal/src/tests/samples/project_with_all_config/pyrightconfig.json rename to packages/vipeye-internal/src/tests/samples/project_with_all_config/viperconfig.json diff --git a/packages/vipeye-internal/src/tests/samples/project_with_diag_overrides/pyrightconfig.json b/packages/vipeye-internal/src/tests/samples/project_with_diag_overrides/viperconfig.json similarity index 100% rename from packages/vipeye-internal/src/tests/samples/project_with_diag_overrides/pyrightconfig.json rename to packages/vipeye-internal/src/tests/samples/project_with_diag_overrides/viperconfig.json diff --git a/packages/vipeye-internal/src/tests/samples/project_with_empty_pyproject_toml/pyproject.toml b/packages/vipeye-internal/src/tests/samples/project_with_empty_pyproject_toml/pyproject.toml index d5faebd8..cba52998 100644 --- a/packages/vipeye-internal/src/tests/samples/project_with_empty_pyproject_toml/pyproject.toml +++ b/packages/vipeye-internal/src/tests/samples/project_with_empty_pyproject_toml/pyproject.toml @@ -1,2 +1,2 @@ -[tool.pyright] +[tool.viper] pythonVersion = "3.9" diff --git a/packages/vipeye-internal/src/tests/samples/project_with_extended_config/baseconfig1.toml b/packages/vipeye-internal/src/tests/samples/project_with_extended_config/baseconfig1.toml index face7634..e9072d5c 100644 --- a/packages/vipeye-internal/src/tests/samples/project_with_extended_config/baseconfig1.toml +++ b/packages/vipeye-internal/src/tests/samples/project_with_extended_config/baseconfig1.toml @@ -1,3 +1,3 @@ -[tool.pyright] +[tool.viper] extends = "sub2/baseconfig2.json" typeCheckingMode = "strict" diff --git a/packages/vipeye-internal/src/tests/samples/project_with_extended_config/pyproject.toml b/packages/vipeye-internal/src/tests/samples/project_with_extended_config/pyproject.toml index 784825fb..21aedb05 100644 --- a/packages/vipeye-internal/src/tests/samples/project_with_extended_config/pyproject.toml +++ b/packages/vipeye-internal/src/tests/samples/project_with_extended_config/pyproject.toml @@ -1,2 +1,2 @@ -[tool.pyright] +[tool.viper] extends = "baseconfig1.toml" diff --git a/packages/vipeye-internal/src/tests/samples/project_with_extended_config/test.py b/packages/vipeye-internal/src/tests/samples/project_with_extended_config/test.py index 80c06c44..b5e8984c 100644 --- a/packages/vipeye-internal/src/tests/samples/project_with_extended_config/test.py +++ b/packages/vipeye-internal/src/tests/samples/project_with_extended_config/test.py @@ -1,4 +1,4 @@ -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import assert_type from sample import x diff --git a/packages/vipeye-internal/src/tests/samples/project_with_nested_empty_pyproject_toml/pyproject.toml b/packages/vipeye-internal/src/tests/samples/project_with_nested_empty_pyproject_toml/pyproject.toml index d5faebd8..cba52998 100644 --- a/packages/vipeye-internal/src/tests/samples/project_with_nested_empty_pyproject_toml/pyproject.toml +++ b/packages/vipeye-internal/src/tests/samples/project_with_nested_empty_pyproject_toml/pyproject.toml @@ -1,2 +1,2 @@ -[tool.pyright] +[tool.viper] pythonVersion = "3.9" diff --git a/packages/vipeye-internal/src/tests/samples/project_with_pyproject_toml/pyproject.toml b/packages/vipeye-internal/src/tests/samples/project_with_pyproject_toml/pyproject.toml index 5362153a..b9f8be37 100644 --- a/packages/vipeye-internal/src/tests/samples/project_with_pyproject_toml/pyproject.toml +++ b/packages/vipeye-internal/src/tests/samples/project_with_pyproject_toml/pyproject.toml @@ -1,4 +1,4 @@ -[tool.pyright] +[tool.viper] include = ["test*.py"] reportMissingImports = true diff --git a/packages/vipeye-internal/src/tests/samples/project_with_pyproject_toml_platform/pyproject.toml b/packages/vipeye-internal/src/tests/samples/project_with_pyproject_toml_platform/pyproject.toml index a563232a..90588bf1 100644 --- a/packages/vipeye-internal/src/tests/samples/project_with_pyproject_toml_platform/pyproject.toml +++ b/packages/vipeye-internal/src/tests/samples/project_with_pyproject_toml_platform/pyproject.toml @@ -1,4 +1,4 @@ -[tool.pyright] +[tool.viper] executionEnvironments = [ { python = "3.7", pythonPlatform = "platform" }, ] \ No newline at end of file diff --git a/packages/vipeye-internal/src/tests/samples/project_with_venv_auto_detect_exclude/pyrightconfig.json b/packages/vipeye-internal/src/tests/samples/project_with_venv_auto_detect_exclude/viperconfig.json similarity index 100% rename from packages/vipeye-internal/src/tests/samples/project_with_venv_auto_detect_exclude/pyrightconfig.json rename to packages/vipeye-internal/src/tests/samples/project_with_venv_auto_detect_exclude/viperconfig.json diff --git a/packages/vipeye-internal/src/tests/samples/project_with_venv_auto_detect_include/pyrightconfig.json b/packages/vipeye-internal/src/tests/samples/project_with_venv_auto_detect_include/viperconfig.json similarity index 100% rename from packages/vipeye-internal/src/tests/samples/project_with_venv_auto_detect_include/pyrightconfig.json rename to packages/vipeye-internal/src/tests/samples/project_with_venv_auto_detect_include/viperconfig.json diff --git a/packages/vipeye-internal/src/tests/samples/property16.py b/packages/vipeye-internal/src/tests/samples/property16.py index 045735c4..cccdaeb2 100644 --- a/packages/vipeye-internal/src/tests/samples/property16.py +++ b/packages/vipeye-internal/src/tests/samples/property16.py @@ -1,7 +1,7 @@ # This sample tests the case where a property's getter and setter # are defined in different classes. -# pyright: reportIncompatibleMethodOverride=false +# viper: reportIncompatibleMethodOverride=false from typing import Generic, Self, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/property20.py b/packages/vipeye-internal/src/tests/samples/property20.py index 2d33e03a..feaccd53 100644 --- a/packages/vipeye-internal/src/tests/samples/property20.py +++ b/packages/vipeye-internal/src/tests/samples/property20.py @@ -1,7 +1,7 @@ # This sample tests deprecation reporting for overloaded property setters. from typing import overload -from typing_extensions import deprecated # pyright: ignore[reportMissingModuleSource] +from typing_extensions import deprecated # viper: ignore[reportMissingModuleSource] class A: diff --git a/packages/vipeye-internal/src/tests/samples/property21.py b/packages/vipeye-internal/src/tests/samples/property21.py index b868924a..c9ab8960 100644 --- a/packages/vipeye-internal/src/tests/samples/property21.py +++ b/packages/vipeye-internal/src/tests/samples/property21.py @@ -2,7 +2,7 @@ # setter implementation propagates to all of the setter overloads, per PEP 702. from typing import overload -from typing_extensions import deprecated # pyright: ignore[reportMissingModuleSource] +from typing_extensions import deprecated # viper: ignore[reportMissingModuleSource] class A: diff --git a/packages/vipeye-internal/src/tests/samples/protocol17.py b/packages/vipeye-internal/src/tests/samples/protocol17.py index 077686b0..00ee1599 100644 --- a/packages/vipeye-internal/src/tests/samples/protocol17.py +++ b/packages/vipeye-internal/src/tests/samples/protocol17.py @@ -1,9 +1,9 @@ # This sample tests for generic protocol variance consistency. from typing import Protocol, TypeVar -from typing_extensions import ParamSpec # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ParamSpec # viper: ignore[reportMissingModuleSource] -# pyright: strict +# viper: strict _T1 = TypeVar("_T1") _T2 = TypeVar("_T2", bound=int) diff --git a/packages/vipeye-internal/src/tests/samples/protocol22.py b/packages/vipeye-internal/src/tests/samples/protocol22.py index aa80b445..15ecc212 100644 --- a/packages/vipeye-internal/src/tests/samples/protocol22.py +++ b/packages/vipeye-internal/src/tests/samples/protocol22.py @@ -4,7 +4,7 @@ from typing import Protocol, TypeVar -# pyright: strict +# viper: strict _T1 = TypeVar("_T1") _T1_co = TypeVar("_T1_co", covariant=True) diff --git a/packages/vipeye-internal/src/tests/samples/protocol29.py b/packages/vipeye-internal/src/tests/samples/protocol29.py index 5e489794..df20dcda 100644 --- a/packages/vipeye-internal/src/tests/samples/protocol29.py +++ b/packages/vipeye-internal/src/tests/samples/protocol29.py @@ -2,7 +2,7 @@ # generics within a protocol. from functools import partial -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] Protocol, Self, ) diff --git a/packages/vipeye-internal/src/tests/samples/protocol6.py b/packages/vipeye-internal/src/tests/samples/protocol6.py index f2ce381f..880569af 100644 --- a/packages/vipeye-internal/src/tests/samples/protocol6.py +++ b/packages/vipeye-internal/src/tests/samples/protocol6.py @@ -21,7 +21,7 @@ class Ungulate(Mammal[_T3], Protocol): class CamelLike(Ungulate[bytes], Protocol): - species: Literal["camel"] # pyright: ignore[reportIncompatibleVariableOverride] + species: Literal["camel"] # viper: ignore[reportIncompatibleVariableOverride] class Sloth: diff --git a/packages/vipeye-internal/src/tests/samples/protocolExplicit3.py b/packages/vipeye-internal/src/tests/samples/protocolExplicit3.py index 183198ec..90eddd55 100644 --- a/packages/vipeye-internal/src/tests/samples/protocolExplicit3.py +++ b/packages/vipeye-internal/src/tests/samples/protocolExplicit3.py @@ -3,7 +3,7 @@ # and functions defined in the protocol. Specifically, this tests # the case where the parent protocol class is implemented in a stub file. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from abc import ABC from typing import final diff --git a/packages/vipeye-internal/src/tests/samples/pseudoGeneric2.py b/packages/vipeye-internal/src/tests/samples/pseudoGeneric2.py index 17de559e..45a80cde 100644 --- a/packages/vipeye-internal/src/tests/samples/pseudoGeneric2.py +++ b/packages/vipeye-internal/src/tests/samples/pseudoGeneric2.py @@ -4,7 +4,7 @@ # We use "strict" here because we want to ensure that there are # no "unknown" types remaining in this file. -# pyright: strict, reportUnknownParameterType=false, reportMissingParameterType=false +# viper: strict, reportUnknownParameterType=false, reportMissingParameterType=false from logging import Handler, NOTSET diff --git a/packages/vipeye-internal/src/tests/samples/python2.py b/packages/vipeye-internal/src/tests/samples/python2.py index d3e4bebb..8f01b4fb 100644 --- a/packages/vipeye-internal/src/tests/samples/python2.py +++ b/packages/vipeye-internal/src/tests/samples/python2.py @@ -3,7 +3,7 @@ # errors, but it should exhibit good recovery, preferably # emitting one error per instance, not a cascade of errors. -# pyright: reportUnusedExpression=false +# viper: reportUnusedExpression=false # This should generate an error. print 3 + 3 diff --git a/packages/vipeye-internal/src/tests/samples/recursiveTypeAlias4.py b/packages/vipeye-internal/src/tests/samples/recursiveTypeAlias4.py index a1cee24d..e5ef73f2 100644 --- a/packages/vipeye-internal/src/tests/samples/recursiveTypeAlias4.py +++ b/packages/vipeye-internal/src/tests/samples/recursiveTypeAlias4.py @@ -1,6 +1,6 @@ # This sample tests the handling of complex recursive types. -# pyright: strict, reportUnusedVariable=false +# viper: strict, reportUnusedVariable=false from typing import Generator diff --git a/packages/vipeye-internal/src/tests/samples/required1.py b/packages/vipeye-internal/src/tests/samples/required1.py index 5d674a55..be86ca7e 100644 --- a/packages/vipeye-internal/src/tests/samples/required1.py +++ b/packages/vipeye-internal/src/tests/samples/required1.py @@ -1,10 +1,10 @@ # This sample tests the handling of Required and NotRequired # (PEP 655) in TypedDict definitions. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import Annotated, TypedDict -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] NotRequired, Required, ) diff --git a/packages/vipeye-internal/src/tests/samples/required2.py b/packages/vipeye-internal/src/tests/samples/required2.py index 690c26bf..06c6422b 100644 --- a/packages/vipeye-internal/src/tests/samples/required2.py +++ b/packages/vipeye-internal/src/tests/samples/required2.py @@ -1,7 +1,7 @@ # This sample tests the handling of Required and NotRequired # (PEP 655) in TypedDict definitions. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import Literal, TypedDict, Annotated import typing_extensions as te diff --git a/packages/vipeye-internal/src/tests/samples/required3.py b/packages/vipeye-internal/src/tests/samples/required3.py index 14e47f8b..0b269f60 100644 --- a/packages/vipeye-internal/src/tests/samples/required3.py +++ b/packages/vipeye-internal/src/tests/samples/required3.py @@ -2,7 +2,7 @@ # the alternative syntax form of TypedDict. from typing import TypedDict -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] Required, NotRequired, ) diff --git a/packages/vipeye-internal/src/tests/samples/self1.py b/packages/vipeye-internal/src/tests/samples/self1.py index e42e9ce8..6875a694 100644 --- a/packages/vipeye-internal/src/tests/samples/self1.py +++ b/packages/vipeye-internal/src/tests/samples/self1.py @@ -1,7 +1,7 @@ # This sample tests various error conditions for the Self type from typing import Callable, Generic, TypeVar -from typing_extensions import Self # pyright: ignore[reportMissingModuleSource] +from typing_extensions import Self # viper: ignore[reportMissingModuleSource] T = TypeVar("T") diff --git a/packages/vipeye-internal/src/tests/samples/self2.py b/packages/vipeye-internal/src/tests/samples/self2.py index 72d58bfa..a8f59253 100644 --- a/packages/vipeye-internal/src/tests/samples/self2.py +++ b/packages/vipeye-internal/src/tests/samples/self2.py @@ -3,7 +3,7 @@ from dataclasses import dataclass from typing import Callable, Generic, ParamSpec, Protocol, TypeVar -from typing_extensions import Self # pyright: ignore[reportMissingModuleSource] +from typing_extensions import Self # viper: ignore[reportMissingModuleSource] _P = ParamSpec("_P") _R = TypeVar("_R") diff --git a/packages/vipeye-internal/src/tests/samples/self5.py b/packages/vipeye-internal/src/tests/samples/self5.py index 75f5c1f2..7d355815 100644 --- a/packages/vipeye-internal/src/tests/samples/self5.py +++ b/packages/vipeye-internal/src/tests/samples/self5.py @@ -1,7 +1,7 @@ # This sample tests the use of `Self` when used within a property # or class property. -from typing_extensions import Self # pyright: ignore[reportMissingModuleSource] +from typing_extensions import Self # viper: ignore[reportMissingModuleSource] class A: diff --git a/packages/vipeye-internal/src/tests/samples/self8.py b/packages/vipeye-internal/src/tests/samples/self8.py index 0bca0c32..c42f08e2 100644 --- a/packages/vipeye-internal/src/tests/samples/self8.py +++ b/packages/vipeye-internal/src/tests/samples/self8.py @@ -3,7 +3,7 @@ # the class bound to the `__new__` method. import enum -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] Self, reveal_type, ) diff --git a/packages/vipeye-internal/src/tests/samples/sentinel1.py b/packages/vipeye-internal/src/tests/samples/sentinel1.py index 3204c324..2dc1693c 100644 --- a/packages/vipeye-internal/src/tests/samples/sentinel1.py +++ b/packages/vipeye-internal/src/tests/samples/sentinel1.py @@ -1,7 +1,7 @@ # This sample tests the handling of Sentinel as described in PEP 661. from typing import Literal, TypeAlias -from typing_extensions import Sentinel, TypeForm # pyright: ignore[reportMissingModuleSource] +from typing_extensions import Sentinel, TypeForm # viper: ignore[reportMissingModuleSource] # This should generate an error because the names don't match. BAD_NAME1 = Sentinel("OTHER") diff --git a/packages/vipeye-internal/src/tests/samples/solver11.py b/packages/vipeye-internal/src/tests/samples/solver11.py index b18281f7..8c53ccec 100644 --- a/packages/vipeye-internal/src/tests/samples/solver11.py +++ b/packages/vipeye-internal/src/tests/samples/solver11.py @@ -1,6 +1,6 @@ # This sample tests the constraint solver when a callable type is involved. -# pyright: strict +# viper: strict from typing import Callable, Literal, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/solver2.py b/packages/vipeye-internal/src/tests/samples/solver2.py index c57fb1a5..112b47d5 100644 --- a/packages/vipeye-internal/src/tests/samples/solver2.py +++ b/packages/vipeye-internal/src/tests/samples/solver2.py @@ -2,7 +2,7 @@ # classes where the protocol is partially specialized with a # type variable. -# pyright: strict +# viper: strict from typing import Callable, Iterator, Protocol, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/solver33.py b/packages/vipeye-internal/src/tests/samples/solver33.py index efce2cd1..ab9a16ef 100644 --- a/packages/vipeye-internal/src/tests/samples/solver33.py +++ b/packages/vipeye-internal/src/tests/samples/solver33.py @@ -1,6 +1,6 @@ # This sample tests a case that resulted in a false positive in the past. -# pyright: strict +# viper: strict import operator diff --git a/packages/vipeye-internal/src/tests/samples/solver40.py b/packages/vipeye-internal/src/tests/samples/solver40.py index 3d7da81c..8f141719 100644 --- a/packages/vipeye-internal/src/tests/samples/solver40.py +++ b/packages/vipeye-internal/src/tests/samples/solver40.py @@ -1,7 +1,7 @@ # This sample involves solving type variables that provide a lambda # its expected type. -# pyright: strict +# viper: strict from typing import Callable, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/solver7.py b/packages/vipeye-internal/src/tests/samples/solver7.py index 0458edbd..d63651e7 100644 --- a/packages/vipeye-internal/src/tests/samples/solver7.py +++ b/packages/vipeye-internal/src/tests/samples/solver7.py @@ -5,7 +5,7 @@ # We use "strict" here because we want to ensure that there are # no "unknown" types remaining in this file. -# pyright: strict +# viper: strict from typing import Generic, TypeVar from collections.abc import Generator diff --git a/packages/vipeye-internal/src/tests/samples/specialForm3.py b/packages/vipeye-internal/src/tests/samples/specialForm3.py index 8822c4cf..dd266115 100644 --- a/packages/vipeye-internal/src/tests/samples/specialForm3.py +++ b/packages/vipeye-internal/src/tests/samples/specialForm3.py @@ -21,7 +21,7 @@ from typing import ( Union, Unpack, ) -from typing_extensions import ReadOnly # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ReadOnly # viper: ignore[reportMissingModuleSource] # The following should all generate an error. Literal() diff --git a/packages/vipeye-internal/src/tests/samples/specialForm4.py b/packages/vipeye-internal/src/tests/samples/specialForm4.py index 3d4c46a3..a1e06e2f 100644 --- a/packages/vipeye-internal/src/tests/samples/specialForm4.py +++ b/packages/vipeye-internal/src/tests/samples/specialForm4.py @@ -22,7 +22,7 @@ from typing import ( Union, Unpack, ) -from typing_extensions import ReadOnly # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ReadOnly # viper: ignore[reportMissingModuleSource] T = TypeVar("T") diff --git a/packages/vipeye-internal/src/tests/samples/subscript3.py b/packages/vipeye-internal/src/tests/samples/subscript3.py index a4b6f734..d28acef7 100644 --- a/packages/vipeye-internal/src/tests/samples/subscript3.py +++ b/packages/vipeye-internal/src/tests/samples/subscript3.py @@ -1,7 +1,7 @@ # This sample tests the handling of a subscript in a loop that includes # a del statement. -# pyright: strict +# viper: strict def func1(lst: list[tuple[int, int]]): diff --git a/packages/vipeye-internal/src/tests/samples/tuple1.py b/packages/vipeye-internal/src/tests/samples/tuple1.py index c7c49631..1c42b82b 100644 --- a/packages/vipeye-internal/src/tests/samples/tuple1.py +++ b/packages/vipeye-internal/src/tests/samples/tuple1.py @@ -3,7 +3,7 @@ import os from typing import Any, Callable, Never -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVarTuple, Unpack, ) diff --git a/packages/vipeye-internal/src/tests/samples/tuple11.py b/packages/vipeye-internal/src/tests/samples/tuple11.py index 1fb01643..70d50e3d 100644 --- a/packages/vipeye-internal/src/tests/samples/tuple11.py +++ b/packages/vipeye-internal/src/tests/samples/tuple11.py @@ -1,7 +1,7 @@ # This sample tests the handling of magic methods on # the tuple class. -# pyright: strict +# viper: strict def func1(t1: tuple[int, ...], t2: tuple[int, ...]) -> bool: @@ -18,7 +18,7 @@ def func3(t1: tuple[int, int], t2: tuple[int, ...]) -> bool: def func4(t1: tuple[int, ...], t2: tuple[str, ...]) -> bool: # This should generate an error - return t1 <= t2 # pyright: ignore[reportUnknownVariableType] + return t1 <= t2 # viper: ignore[reportUnknownVariableType] def func5(t1: tuple[str | int, ...]) -> tuple[str | int, ...]: diff --git a/packages/vipeye-internal/src/tests/samples/tuple9.py b/packages/vipeye-internal/src/tests/samples/tuple9.py index 5b8b5a55..2359fe20 100644 --- a/packages/vipeye-internal/src/tests/samples/tuple9.py +++ b/packages/vipeye-internal/src/tests/samples/tuple9.py @@ -3,7 +3,7 @@ # would be expected from the constructor, we actually # generate "tuple[T, ...]". -# pyright: strict +# viper: strict str_list = ["1", "2", "3"] left, right = tuple(str_list) diff --git a/packages/vipeye-internal/src/tests/samples/tupleUnpack1.py b/packages/vipeye-internal/src/tests/samples/tupleUnpack1.py index c3b2727f..f51c88b2 100644 --- a/packages/vipeye-internal/src/tests/samples/tupleUnpack1.py +++ b/packages/vipeye-internal/src/tests/samples/tupleUnpack1.py @@ -2,7 +2,7 @@ # in PEP 646. from typing import Union -from typing_extensions import Unpack # pyright: ignore[reportMissingModuleSource] +from typing_extensions import Unpack # viper: ignore[reportMissingModuleSource] def func1(v1: tuple[int, Unpack[tuple[bool, bool]], str]): diff --git a/packages/vipeye-internal/src/tests/samples/tupleUnpack3.py b/packages/vipeye-internal/src/tests/samples/tupleUnpack3.py index 41cfcd2e..5eed230f 100644 --- a/packages/vipeye-internal/src/tests/samples/tupleUnpack3.py +++ b/packages/vipeye-internal/src/tests/samples/tupleUnpack3.py @@ -2,7 +2,7 @@ # and is later specialized is honored. from typing import Protocol, TypeVar, Callable, Protocol, Any -from typing_extensions import Unpack # pyright: ignore[reportMissingModuleSource] +from typing_extensions import Unpack # viper: ignore[reportMissingModuleSource] class SupportsSum(Protocol): diff --git a/packages/vipeye-internal/src/tests/samples/typeAlias10.py b/packages/vipeye-internal/src/tests/samples/typeAlias10.py index cd8aced2..ebd8d418 100644 --- a/packages/vipeye-internal/src/tests/samples/typeAlias10.py +++ b/packages/vipeye-internal/src/tests/samples/typeAlias10.py @@ -1,7 +1,7 @@ # This sample tests the handling of generic type alias where a type # argument is not provided. -# pyright: reportMissingTypeArgument=true +# viper: reportMissingTypeArgument=true from typing import Any, Generic, TypeAlias, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/typeAlias13.py b/packages/vipeye-internal/src/tests/samples/typeAlias13.py index 4ed27282..0c959840 100644 --- a/packages/vipeye-internal/src/tests/samples/typeAlias13.py +++ b/packages/vipeye-internal/src/tests/samples/typeAlias13.py @@ -2,7 +2,7 @@ # and several layers of nested type aliases. from typing import Any, Callable, Concatenate, Coroutine, TypeVar, Union -from typing_extensions import ParamSpec # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ParamSpec # viper: ignore[reportMissingModuleSource] T = TypeVar("T") U = TypeVar("U") diff --git a/packages/vipeye-internal/src/tests/samples/typeAlias3.py b/packages/vipeye-internal/src/tests/samples/typeAlias3.py index 7fb031d4..389b3a1b 100644 --- a/packages/vipeye-internal/src/tests/samples/typeAlias3.py +++ b/packages/vipeye-internal/src/tests/samples/typeAlias3.py @@ -2,7 +2,7 @@ # partially-specialized classes that can be further # specialized. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import Callable, Generic, Optional from typing_extensions import ParamSpec, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/typeAlias8.py b/packages/vipeye-internal/src/tests/samples/typeAlias8.py index 697f9342..6891dc26 100644 --- a/packages/vipeye-internal/src/tests/samples/typeAlias8.py +++ b/packages/vipeye-internal/src/tests/samples/typeAlias8.py @@ -1,7 +1,7 @@ # This sample verifies that a generic type alias with a Callable # works correctly. -# pyright: reportInvalidTypeVarUse=false +# viper: reportInvalidTypeVarUse=false from typing import Callable, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/typeAlias9.py b/packages/vipeye-internal/src/tests/samples/typeAlias9.py index 53698848..b615bc04 100644 --- a/packages/vipeye-internal/src/tests/samples/typeAlias9.py +++ b/packages/vipeye-internal/src/tests/samples/typeAlias9.py @@ -1,7 +1,7 @@ # This sample tests that generic type aliases are properly flagged as # partially-unknown types if their type arguments are omitted. -# pyright: reportUnknownParameterType=true, reportMissingTypeArgument=false +# viper: reportUnknownParameterType=true, reportMissingTypeArgument=false from typing import TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/typeAliasType1.py b/packages/vipeye-internal/src/tests/samples/typeAliasType1.py index 9e0510cd..baff967a 100644 --- a/packages/vipeye-internal/src/tests/samples/typeAliasType1.py +++ b/packages/vipeye-internal/src/tests/samples/typeAliasType1.py @@ -1,7 +1,7 @@ # This sample tests error cases for calls to the TypeAliasType constructor. from typing import TypeVar -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeAliasType, ) diff --git a/packages/vipeye-internal/src/tests/samples/typeAliasType2.py b/packages/vipeye-internal/src/tests/samples/typeAliasType2.py index 57a29954..ba75b0cb 100644 --- a/packages/vipeye-internal/src/tests/samples/typeAliasType2.py +++ b/packages/vipeye-internal/src/tests/samples/typeAliasType2.py @@ -1,7 +1,7 @@ # This sample tests the TypeAliasType constructor. from typing import Callable, Generic, ParamSpec, TypeVar, TypeVarTuple -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeAliasType, ) diff --git a/packages/vipeye-internal/src/tests/samples/typeForm1.py b/packages/vipeye-internal/src/tests/samples/typeForm1.py index d4dc78dc..efaffee5 100644 --- a/packages/vipeye-internal/src/tests/samples/typeForm1.py +++ b/packages/vipeye-internal/src/tests/samples/typeForm1.py @@ -1,7 +1,7 @@ # This sample tests basic usage of the TypeForm special form # when used as a call. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import Annotated from typing_extensions import TypeForm diff --git a/packages/vipeye-internal/src/tests/samples/typeForm2.py b/packages/vipeye-internal/src/tests/samples/typeForm2.py index 078bc149..227795b6 100644 --- a/packages/vipeye-internal/src/tests/samples/typeForm2.py +++ b/packages/vipeye-internal/src/tests/samples/typeForm2.py @@ -1,6 +1,6 @@ # This sample tests type inference rules for TypeForm. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import ( Annotated, diff --git a/packages/vipeye-internal/src/tests/samples/typeForm3.py b/packages/vipeye-internal/src/tests/samples/typeForm3.py index b70befa8..5befb0a2 100644 --- a/packages/vipeye-internal/src/tests/samples/typeForm3.py +++ b/packages/vipeye-internal/src/tests/samples/typeForm3.py @@ -1,6 +1,6 @@ # This sample tests inference behaviors related to TypeForm. -# pyright: strict +# viper: strict def func1(): diff --git a/packages/vipeye-internal/src/tests/samples/typeForm4.py b/packages/vipeye-internal/src/tests/samples/typeForm4.py index 8a141439..f3405e1c 100644 --- a/packages/vipeye-internal/src/tests/samples/typeForm4.py +++ b/packages/vipeye-internal/src/tests/samples/typeForm4.py @@ -1,6 +1,6 @@ # This sample tests assignability rules for TypeForm types. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import ( Annotated, diff --git a/packages/vipeye-internal/src/tests/samples/typeForm5.py b/packages/vipeye-internal/src/tests/samples/typeForm5.py index e4cb9017..efad4413 100644 --- a/packages/vipeye-internal/src/tests/samples/typeForm5.py +++ b/packages/vipeye-internal/src/tests/samples/typeForm5.py @@ -1,6 +1,6 @@ # This sample tests the TypeForm special form when used with type variables. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import Literal, LiteralString, TypeGuard, Optional from typing_extensions import TypeForm, TypeIs diff --git a/packages/vipeye-internal/src/tests/samples/typeForm6.py b/packages/vipeye-internal/src/tests/samples/typeForm6.py index bf679f0b..4753db29 100644 --- a/packages/vipeye-internal/src/tests/samples/typeForm6.py +++ b/packages/vipeye-internal/src/tests/samples/typeForm6.py @@ -1,6 +1,6 @@ # This sample tests the handling of assert_type with TypeForm types. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from types import UnionType from typing import assert_type diff --git a/packages/vipeye-internal/src/tests/samples/typeForm7.py b/packages/vipeye-internal/src/tests/samples/typeForm7.py index e7af7127..901e9851 100644 --- a/packages/vipeye-internal/src/tests/samples/typeForm7.py +++ b/packages/vipeye-internal/src/tests/samples/typeForm7.py @@ -1,6 +1,6 @@ # This sample tests the isinstance type narrowing involving TypeForm types. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from types import UnionType from typing import Any diff --git a/packages/vipeye-internal/src/tests/samples/typeForm8.py b/packages/vipeye-internal/src/tests/samples/typeForm8.py index 7209d834..c9ec244b 100644 --- a/packages/vipeye-internal/src/tests/samples/typeForm8.py +++ b/packages/vipeye-internal/src/tests/samples/typeForm8.py @@ -2,7 +2,7 @@ # is interpreted as a stringified TypeForm when the expected element # type is a TypeForm. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import Union from typing_extensions import TypeForm diff --git a/packages/vipeye-internal/src/tests/samples/typeGuard1.py b/packages/vipeye-internal/src/tests/samples/typeGuard1.py index 99619ceb..8b46aa7b 100644 --- a/packages/vipeye-internal/src/tests/samples/typeGuard1.py +++ b/packages/vipeye-internal/src/tests/samples/typeGuard1.py @@ -2,12 +2,12 @@ # that allows user-defined functions to perform # conditional type narrowing. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false import os from typing import Any, Callable, TypeVar -from typing_extensions import TypeGuard # pyright: ignore[reportMissingModuleSource] +from typing_extensions import TypeGuard # viper: ignore[reportMissingModuleSource] _T = TypeVar("_T") diff --git a/packages/vipeye-internal/src/tests/samples/typeGuard2.py b/packages/vipeye-internal/src/tests/samples/typeGuard2.py index 4f22dd92..3de67232 100644 --- a/packages/vipeye-internal/src/tests/samples/typeGuard2.py +++ b/packages/vipeye-internal/src/tests/samples/typeGuard2.py @@ -1,10 +1,10 @@ # This sample tests the handling of user-defined type guards (PEP 647) # when they are used as callback functions. -# pyright: strict, reportMissingModuleSource=false +# viper: strict, reportMissingModuleSource=false from typing import Any, Callable, Sequence, TypeVar, overload -from typing_extensions import TypeGuard # pyright: ignore[reportMissingModuleSource] +from typing_extensions import TypeGuard # viper: ignore[reportMissingModuleSource] _T = TypeVar("_T") diff --git a/packages/vipeye-internal/src/tests/samples/typeGuard3.py b/packages/vipeye-internal/src/tests/samples/typeGuard3.py index f1d28a7a..88967a63 100644 --- a/packages/vipeye-internal/src/tests/samples/typeGuard3.py +++ b/packages/vipeye-internal/src/tests/samples/typeGuard3.py @@ -3,7 +3,7 @@ from enum import Enum from typing import Literal, overload -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeGuard, TypeIs, ) diff --git a/packages/vipeye-internal/src/tests/samples/typeIs1.py b/packages/vipeye-internal/src/tests/samples/typeIs1.py index d98c5854..8aaea931 100644 --- a/packages/vipeye-internal/src/tests/samples/typeIs1.py +++ b/packages/vipeye-internal/src/tests/samples/typeIs1.py @@ -1,6 +1,6 @@ # This sample tests the TypeIs form. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import ( Any, diff --git a/packages/vipeye-internal/src/tests/samples/typeIs2.py b/packages/vipeye-internal/src/tests/samples/typeIs2.py index d964891b..a518169c 100644 --- a/packages/vipeye-internal/src/tests/samples/typeIs2.py +++ b/packages/vipeye-internal/src/tests/samples/typeIs2.py @@ -1,7 +1,7 @@ # This sample tests the subtyping relationships between TypeIs, TypeGuard, # and bool. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import Callable diff --git a/packages/vipeye-internal/src/tests/samples/typeIs3.py b/packages/vipeye-internal/src/tests/samples/typeIs3.py index a15c61f4..95856bd5 100644 --- a/packages/vipeye-internal/src/tests/samples/typeIs3.py +++ b/packages/vipeye-internal/src/tests/samples/typeIs3.py @@ -1,6 +1,6 @@ # This sample tests the handling of tuple types when used with TypeIs. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing_extensions import TypeIs diff --git a/packages/vipeye-internal/src/tests/samples/typeIs4.py b/packages/vipeye-internal/src/tests/samples/typeIs4.py index bc170bdf..cc67dde8 100644 --- a/packages/vipeye-internal/src/tests/samples/typeIs4.py +++ b/packages/vipeye-internal/src/tests/samples/typeIs4.py @@ -1,6 +1,6 @@ # This sample tests TypeIs when used with a Callable type. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import Callable from typing_extensions import TypeIs diff --git a/packages/vipeye-internal/src/tests/samples/typeNarrowing1.py b/packages/vipeye-internal/src/tests/samples/typeNarrowing1.py index cbca8d4d..99110511 100644 --- a/packages/vipeye-internal/src/tests/samples/typeNarrowing1.py +++ b/packages/vipeye-internal/src/tests/samples/typeNarrowing1.py @@ -1,7 +1,7 @@ # This file validates type narrowing that involve # conditional binary expressions. -# pyright: reportOptionalMemberAccess=false +# viper: reportOptionalMemberAccess=false from random import random diff --git a/packages/vipeye-internal/src/tests/samples/typeNarrowing4.py b/packages/vipeye-internal/src/tests/samples/typeNarrowing4.py index 15ea2578..165b7bfd 100644 --- a/packages/vipeye-internal/src/tests/samples/typeNarrowing4.py +++ b/packages/vipeye-internal/src/tests/samples/typeNarrowing4.py @@ -2,7 +2,7 @@ # conditional expression involving assignment expressions # (walrus operator). -# pyright: strict +# viper: strict class C: diff --git a/packages/vipeye-internal/src/tests/samples/typeNarrowingAny1.py b/packages/vipeye-internal/src/tests/samples/typeNarrowingAny1.py index 3fe29fe4..833ab9a3 100644 --- a/packages/vipeye-internal/src/tests/samples/typeNarrowingAny1.py +++ b/packages/vipeye-internal/src/tests/samples/typeNarrowingAny1.py @@ -1,7 +1,7 @@ # This sample tests the type analyzer's type narrowing logic for # Any and Unknown types with "is None" checks. -# pyright: strict +# viper: strict from typing import Any, reveal_type diff --git a/packages/vipeye-internal/src/tests/samples/typeNarrowingIsNone1.py b/packages/vipeye-internal/src/tests/samples/typeNarrowingIsNone1.py index 9a5219a8..258d6f68 100644 --- a/packages/vipeye-internal/src/tests/samples/typeNarrowingIsNone1.py +++ b/packages/vipeye-internal/src/tests/samples/typeNarrowingIsNone1.py @@ -2,7 +2,7 @@ # conditions of the form "X is None", "X is not None", # "X == None" and "X != None". -# pyright: strict, reportUnusedVariable=false +# viper: strict, reportUnusedVariable=false from typing import Any, Literal, Protocol, Self, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/typeNarrowingIsNone2.py b/packages/vipeye-internal/src/tests/samples/typeNarrowingIsNone2.py index 82577838..181de12a 100644 --- a/packages/vipeye-internal/src/tests/samples/typeNarrowingIsNone2.py +++ b/packages/vipeye-internal/src/tests/samples/typeNarrowingIsNone2.py @@ -2,7 +2,7 @@ # statements of the form X is None or X is not None # where X is an assignment expression. -# pyright: strict +# viper: strict i = {"a": "", "b": None} dict_comp = {key: w.strip() if (w := i[key]) is not None else "" for key in i} diff --git a/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance13.py b/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance13.py index 5715c6ca..beb9870c 100644 --- a/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance13.py +++ b/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance13.py @@ -1,7 +1,7 @@ # This sample tests the case where isinstance type narrowing is used # with a protocol class that supports runtime checking. -# pyright: reportUnnecessaryIsInstance=true +# viper: reportUnnecessaryIsInstance=true from typing import Any, Iterable, Sized diff --git a/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance19.py b/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance19.py index b6dd8749..050128d7 100644 --- a/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance19.py +++ b/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance19.py @@ -3,7 +3,7 @@ from abc import ABC, ABCMeta from typing import Any, ClassVar, Iterable -from typing_extensions import reveal_type # pyright: ignore[reportMissingModuleSource] +from typing_extensions import reveal_type # viper: ignore[reportMissingModuleSource] class Meta1(ABCMeta): diff --git a/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance20.py b/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance20.py index d4a0f957..345fb62a 100644 --- a/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance20.py +++ b/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance20.py @@ -2,7 +2,7 @@ # with a generic class with a type parameter that has a default value. from typing import Generic -from typing_extensions import TypeVar # pyright: ignore[reportMissingModuleSource] +from typing_extensions import TypeVar # viper: ignore[reportMissingModuleSource] T = TypeVar("T", bound=int, default=int) diff --git a/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance21.py b/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance21.py index 4857c012..ad25dd61 100644 --- a/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance21.py +++ b/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance21.py @@ -1,6 +1,6 @@ # This sample tests the case where the filter type is a class object. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import Any from typing_extensions import TypeIs diff --git a/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance8.py b/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance8.py index 0649762c..75914d09 100644 --- a/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance8.py +++ b/packages/vipeye-internal/src/tests/samples/typeNarrowingIsinstance8.py @@ -2,7 +2,7 @@ # to an abstract base class. When attempting to instantiate the # class, there should be no "cannot instantiate ABC" error. -# pyright: strict +# viper: strict from abc import ABC, abstractmethod from typing import Any diff --git a/packages/vipeye-internal/src/tests/samples/typeVar8.py b/packages/vipeye-internal/src/tests/samples/typeVar8.py index a8da16f8..21eec072 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVar8.py +++ b/packages/vipeye-internal/src/tests/samples/typeVar8.py @@ -2,7 +2,7 @@ # used as a runtime object rather than a special form. import typing as t -import typing_extensions as te # pyright: ignore[reportMissingModuleSource] +import typing_extensions as te # viper: ignore[reportMissingModuleSource] T1 = t.TypeVar("T1") diff --git a/packages/vipeye-internal/src/tests/samples/typeVar9.py b/packages/vipeye-internal/src/tests/samples/typeVar9.py index 2510020c..234473f3 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVar9.py +++ b/packages/vipeye-internal/src/tests/samples/typeVar9.py @@ -2,10 +2,10 @@ # a generic function. A TypeVar must appear at least twice to be # considered legitimate. -# pyright: reportInvalidTypeVarUse=true +# viper: reportInvalidTypeVarUse=true from typing import AnyStr, Callable, Generic, overload -from typing_extensions import TypeVar # pyright: ignore[reportMissingModuleSource] +from typing_extensions import TypeVar # viper: ignore[reportMissingModuleSource] _T = TypeVar("_T") diff --git a/packages/vipeye-internal/src/tests/samples/typeVarDefault1.py b/packages/vipeye-internal/src/tests/samples/typeVarDefault1.py index 0cc410f0..e9d633a7 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarDefault1.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarDefault1.py @@ -1,7 +1,7 @@ # This sample tests basic support for PEP 696 -- default types for TypeVars. from typing import Any -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVar, TypeVarTuple, ParamSpec, diff --git a/packages/vipeye-internal/src/tests/samples/typeVarDefault2.py b/packages/vipeye-internal/src/tests/samples/typeVarDefault2.py index ccb64c2f..1d192c2c 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarDefault2.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarDefault2.py @@ -2,7 +2,7 @@ # in PEP 696 (default types for TypeVarLike). from typing import Any, ParamSpec, TypeVar, Unpack -from typing_extensions import TypeVarTuple # pyright: ignore[reportMissingModuleSource] +from typing_extensions import TypeVarTuple # viper: ignore[reportMissingModuleSource] T1 = TypeVar("T1") Ts1 = TypeVarTuple("Ts1") diff --git a/packages/vipeye-internal/src/tests/samples/typeVarDefault3.py b/packages/vipeye-internal/src/tests/samples/typeVarDefault3.py index c6dcf8f2..117aef79 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarDefault3.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarDefault3.py @@ -2,7 +2,7 @@ # types cannot be after TypeVars with default types. from typing import Generic -from typing_extensions import TypeVar, TypeVarTuple # pyright: ignore[reportMissingModuleSource] +from typing_extensions import TypeVar, TypeVarTuple # viper: ignore[reportMissingModuleSource] T0 = TypeVar("T0", default=object) diff --git a/packages/vipeye-internal/src/tests/samples/typeVarDefaultClass1.py b/packages/vipeye-internal/src/tests/samples/typeVarDefaultClass1.py index 6e121d93..71cced3b 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarDefaultClass1.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarDefaultClass1.py @@ -4,7 +4,7 @@ from typing import Generic, Self, assert_type -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] ParamSpec, TypeVar, TypeVarTuple, diff --git a/packages/vipeye-internal/src/tests/samples/typeVarDefaultFunction1.py b/packages/vipeye-internal/src/tests/samples/typeVarDefaultFunction1.py index ce176cb5..5c32d8d3 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarDefaultFunction1.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarDefaultFunction1.py @@ -3,7 +3,7 @@ # in a call, and a default value is used rather than Unknown. from typing import Callable, Generic, Unpack -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] ParamSpec, TypeVar, TypeVarTuple, diff --git a/packages/vipeye-internal/src/tests/samples/typeVarDefaultFunction2.py b/packages/vipeye-internal/src/tests/samples/typeVarDefaultFunction2.py index f995399c..32f4b81b 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarDefaultFunction2.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarDefaultFunction2.py @@ -3,7 +3,7 @@ # expressions that refer to other type variables. from typing import Generic, Self -from typing_extensions import TypeVar # pyright: ignore[reportMissingModuleSource] +from typing_extensions import TypeVar # viper: ignore[reportMissingModuleSource] T1 = TypeVar("T1", default=str) T2 = TypeVar("T2", default=list[T1]) diff --git a/packages/vipeye-internal/src/tests/samples/typeVarDefaultTypeAlias1.py b/packages/vipeye-internal/src/tests/samples/typeVarDefaultTypeAlias1.py index fc82f407..01e3559e 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarDefaultTypeAlias1.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarDefaultTypeAlias1.py @@ -4,7 +4,7 @@ from collections.abc import Callable from typing import Any, TypeAlias -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVar, ParamSpec, TypeVarTuple, diff --git a/packages/vipeye-internal/src/tests/samples/typeVarDefaultTypeAlias2.py b/packages/vipeye-internal/src/tests/samples/typeVarDefaultTypeAlias2.py index 36d19482..8ba7c5ff 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarDefaultTypeAlias2.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarDefaultTypeAlias2.py @@ -4,7 +4,7 @@ # to another. from typing import Callable, Generic, Unpack -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] ParamSpec, TypeVar, TypeVarTuple, diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple1.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple1.py index 4881afed..de5c9e7a 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple1.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple1.py @@ -1,7 +1,7 @@ # This sample tests various conditions under which variadic # type variables can and cannot be used. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import Generic, TypeVar, Union from typing_extensions import TypeVarTuple, Unpack diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple10.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple10.py index 88b70c4b..e2ebe8f0 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple10.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple10.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any, Generic, NewType, TypeVar -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVarTuple, Unpack, ) diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple11.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple11.py index 955889ed..23ac43ed 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple11.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple11.py @@ -3,10 +3,10 @@ # except that it uses the * operator rather than Unpack. # Enable experimental features to support Union[*Ts]. -# pyright: enableExperimentalFeatures=true +# viper: enableExperimentalFeatures=true from typing import Generic, NewType, Union -from typing_extensions import TypeVarTuple # pyright: ignore[reportMissingModuleSource] +from typing_extensions import TypeVarTuple # viper: ignore[reportMissingModuleSource] Shape = TypeVarTuple("Shape") diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple12.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple12.py index d860d723..af3ccf6a 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple12.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple12.py @@ -3,10 +3,10 @@ # invariance validation when a TypeVarTuple is used in the protocol # along with a non-variadic TypeVar. -# pyright: strict +# viper: strict from typing import Protocol, TypeVar -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVarTuple, Unpack, ) diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple13.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple13.py index 2591a0ae..96952c9b 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple13.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple13.py @@ -3,7 +3,7 @@ # TypeVarTuple. from typing import Protocol, TypeVar -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVarTuple, Unpack, ) diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple14.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple14.py index 5e26314b..1a7c922b 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple14.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple14.py @@ -2,7 +2,7 @@ # and a *args unpacked Tuple to a *args TypeVarTuple. from typing import Callable, TypeVar -from typing_extensions import TypeVarTuple # pyright: ignore[reportMissingModuleSource] +from typing_extensions import TypeVarTuple # viper: ignore[reportMissingModuleSource] Ts = TypeVarTuple("Ts") R = TypeVar("R") diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple15.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple15.py index cdd79519..2edcf425 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple15.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple15.py @@ -2,7 +2,7 @@ # by a TypeVarTuple. from typing import Any, Generic -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVarTuple, Unpack, ) diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple16.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple16.py index 3d10931b..22ed1b47 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple16.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple16.py @@ -3,7 +3,7 @@ from typing import Generic -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVarTuple, Unpack, ) diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple17.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple17.py index 16ec9536..979d8b83 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple17.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple17.py @@ -2,7 +2,7 @@ # expression is matched to an `*args` parameter that has a declared type # that includes an unpacked TypeVarTuple. -from typing_extensions import TypeVarTuple # pyright: ignore[reportMissingModuleSource] +from typing_extensions import TypeVarTuple # viper: ignore[reportMissingModuleSource] Ts = TypeVarTuple("Ts") diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple19.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple19.py index 9a1ee163..b81b2307 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple19.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple19.py @@ -2,7 +2,7 @@ # as one or more type arguments for a tuple. # Enable experimental features to support Union[*Ts]. -# pyright: enableExperimentalFeatures=true +# viper: enableExperimentalFeatures=true from typing import Generator, Iterable, TypeVar, TypeVarTuple, Union diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple2.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple2.py index 0223ec14..d67c45cc 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple2.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple2.py @@ -1,10 +1,10 @@ # This sample tests various conditions under which Unpack # can and cannot be used. -# pyright: reportMissingModuleSource=false +# viper: reportMissingModuleSource=false from typing import Generic, TypeVar, Union -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVarTuple, Unpack, ) diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple20.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple20.py index bb626284..a27b9d18 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple20.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple20.py @@ -2,10 +2,10 @@ # to a non-variadic TypeVar during constraint solving. # Enable experimental features to support Union[*Ts]. -# pyright: enableExperimentalFeatures=true +# viper: enableExperimentalFeatures=true from typing import TypeVar, Tuple, Union -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] reveal_type, TypeVarTuple, ) diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple21.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple21.py index abd01769..2987476b 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple21.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple21.py @@ -3,7 +3,7 @@ # TypeVarTuple parameter. # Enable experimental features to support Union[*Ts]. -# pyright: enableExperimentalFeatures=true +# viper: enableExperimentalFeatures=true from typing import TypeVar, TypeVarTuple, Union, Unpack diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple22.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple22.py index 03ebc5bd..72c853f2 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple22.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple22.py @@ -2,7 +2,7 @@ # a tuple with literal values. # Enable experimental features to support Union[*Ts]. -# pyright: enableExperimentalFeatures=true +# viper: enableExperimentalFeatures=true from typing import Callable, Literal, TypeVarTuple, Union, Unpack diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple24.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple24.py index 95cbaf31..a94e134e 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple24.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple24.py @@ -1,7 +1,7 @@ # This sample tests the handling of `Union[*Ts]` in certain cases. # Enable experimental features to support Union[*Ts]. -# pyright: enableExperimentalFeatures=true +# viper: enableExperimentalFeatures=true from typing import Generic, TypeVarTuple, Union diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple3.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple3.py index 862f273f..1434425d 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple3.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple3.py @@ -2,7 +2,7 @@ # variadic type variables. from typing import Any, Generic, Literal, TypeAlias, TypeVar, overload -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVarTuple, Unpack, ) diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple4.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple4.py index 46473450..765bd9c7 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple4.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple4.py @@ -2,10 +2,10 @@ # variadic type variables. # Enable experimental features to support Union[*Ts]. -# pyright: enableExperimentalFeatures=true +# viper: enableExperimentalFeatures=true from typing import Generic, NewType, Union -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVarTuple, Unpack, ) diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple5.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple5.py index 5a831fad..33e8e28a 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple5.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple5.py @@ -2,7 +2,7 @@ # within Callable types. from typing import Any, Callable, Protocol -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVarTuple, Unpack, ) diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple6.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple6.py index 3473e490..cc81a1d6 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple6.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple6.py @@ -1,7 +1,7 @@ # This sample tests the handling of generic type aliases with # variadic type variables. -# pyright: reportMissingTypeArgument=true, reportMissingModuleSource=false +# viper: reportMissingTypeArgument=true, reportMissingModuleSource=false from typing import Callable, Generic, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple7.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple7.py index c4e4d82c..d37ee16f 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple7.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple7.py @@ -1,10 +1,10 @@ # This sample tests error handling for variadic type var usage. # Enable experimental features to support Union[*Ts]. -# pyright: enableExperimentalFeatures=true +# viper: enableExperimentalFeatures=true from typing import Any, Callable, Generic, TypeVar, Union -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVarTuple, Unpack, ) diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple8.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple8.py index 3c8e136b..ee734751 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple8.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple8.py @@ -1,10 +1,10 @@ # This sample tests variadic TypeVar matching for unions. # Enable experimental features to support Union[*Ts]. -# pyright: enableExperimentalFeatures=true +# viper: enableExperimentalFeatures=true from typing import TypeVar, Union -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVarTuple, Unpack, ) diff --git a/packages/vipeye-internal/src/tests/samples/typeVarTuple9.py b/packages/vipeye-internal/src/tests/samples/typeVarTuple9.py index 6d7d9c05..434b84c1 100644 --- a/packages/vipeye-internal/src/tests/samples/typeVarTuple9.py +++ b/packages/vipeye-internal/src/tests/samples/typeVarTuple9.py @@ -2,7 +2,7 @@ # in generic type aliases and with suffixes. from typing import Callable, Generic, TypeVar -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] TypeVarTuple, Unpack, ) diff --git a/packages/vipeye-internal/src/tests/samples/typedDict12.py b/packages/vipeye-internal/src/tests/samples/typedDict12.py index f0518dd6..80460b6f 100644 --- a/packages/vipeye-internal/src/tests/samples/typedDict12.py +++ b/packages/vipeye-internal/src/tests/samples/typedDict12.py @@ -2,7 +2,7 @@ # pop, __delitem__, clear, and popitem for a TypedDict. from typing import TypedDict, final -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] NotRequired, Required, ) diff --git a/packages/vipeye-internal/src/tests/samples/typedDict13.py b/packages/vipeye-internal/src/tests/samples/typedDict13.py index 1bbf24f4..eb433256 100644 --- a/packages/vipeye-internal/src/tests/samples/typedDict13.py +++ b/packages/vipeye-internal/src/tests/samples/typedDict13.py @@ -1,7 +1,7 @@ # This sample tests that TypedDicts that inherit from other # TypedDicts do not override field names with incompatible types. -# pyright: reportIncompatibleVariableOverride=true +# viper: reportIncompatibleVariableOverride=true from typing import Any, NotRequired, Required, TypedDict diff --git a/packages/vipeye-internal/src/tests/samples/typedDict19.py b/packages/vipeye-internal/src/tests/samples/typedDict19.py index e978be48..e3366477 100644 --- a/packages/vipeye-internal/src/tests/samples/typedDict19.py +++ b/packages/vipeye-internal/src/tests/samples/typedDict19.py @@ -2,7 +2,7 @@ # on an assignment to a not-required key. from typing import TypedDict -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] NotRequired, Required, Unpack, diff --git a/packages/vipeye-internal/src/tests/samples/typedDict21.py b/packages/vipeye-internal/src/tests/samples/typedDict21.py index 90aa526b..bfcc474b 100644 --- a/packages/vipeye-internal/src/tests/samples/typedDict21.py +++ b/packages/vipeye-internal/src/tests/samples/typedDict21.py @@ -1,6 +1,6 @@ # This sample tests the handling of dictionary expansion for TypedDicts. -from typing_extensions import ( # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ( # viper: ignore[reportMissingModuleSource] NotRequired, Required, TypedDict, diff --git a/packages/vipeye-internal/src/tests/samples/typedDictClosed1.py b/packages/vipeye-internal/src/tests/samples/typedDictClosed1.py index 81ac9f2b..414cc74e 100644 --- a/packages/vipeye-internal/src/tests/samples/typedDictClosed1.py +++ b/packages/vipeye-internal/src/tests/samples/typedDictClosed1.py @@ -2,7 +2,7 @@ # introduced in PEP 728. from typing import NotRequired, Required, TypedDict -from typing_extensions import ReadOnly # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ReadOnly # viper: ignore[reportMissingModuleSource] class Movie(TypedDict, extra_items=bool): diff --git a/packages/vipeye-internal/src/tests/samples/typedDictClosed10.py b/packages/vipeye-internal/src/tests/samples/typedDictClosed10.py index c72b7130..420e2064 100644 --- a/packages/vipeye-internal/src/tests/samples/typedDictClosed10.py +++ b/packages/vipeye-internal/src/tests/samples/typedDictClosed10.py @@ -1,7 +1,7 @@ # This sample tests the case where a type variable is used to define # the extra_items in a TypedDict. -from typing_extensions import TypedDict # pyright: ignore[reportMissingModuleSource] +from typing_extensions import TypedDict # viper: ignore[reportMissingModuleSource] class TD1[T](TypedDict, extra_items=T): diff --git a/packages/vipeye-internal/src/tests/samples/typedDictClosed3.py b/packages/vipeye-internal/src/tests/samples/typedDictClosed3.py index 235eec71..25382ce0 100644 --- a/packages/vipeye-internal/src/tests/samples/typedDictClosed3.py +++ b/packages/vipeye-internal/src/tests/samples/typedDictClosed3.py @@ -1,7 +1,7 @@ # This sample tests inheritance rules for closed TypedDicts. from typing import Any, Never, NotRequired, Required, TypedDict -from typing_extensions import ReadOnly # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ReadOnly # viper: ignore[reportMissingModuleSource] class Parent1(TypedDict, extra_items=int | None): diff --git a/packages/vipeye-internal/src/tests/samples/typedDictClosed4.py b/packages/vipeye-internal/src/tests/samples/typedDictClosed4.py index cb426e02..5e4502a9 100644 --- a/packages/vipeye-internal/src/tests/samples/typedDictClosed4.py +++ b/packages/vipeye-internal/src/tests/samples/typedDictClosed4.py @@ -1,7 +1,7 @@ # This sample tests type consistency rules for closed TypedDicts. from typing import NotRequired, TypedDict -from typing_extensions import ReadOnly # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ReadOnly # viper: ignore[reportMissingModuleSource] class Movie1(TypedDict, extra_items=int | None): diff --git a/packages/vipeye-internal/src/tests/samples/typedDictClosed6.py b/packages/vipeye-internal/src/tests/samples/typedDictClosed6.py index d6572243..34d866b9 100644 --- a/packages/vipeye-internal/src/tests/samples/typedDictClosed6.py +++ b/packages/vipeye-internal/src/tests/samples/typedDictClosed6.py @@ -2,7 +2,7 @@ # dict and MutableMapping types. from typing import MutableMapping, NotRequired, TypedDict -from typing_extensions import ReadOnly # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ReadOnly # viper: ignore[reportMissingModuleSource] class IntDict1(TypedDict, extra_items=int): diff --git a/packages/vipeye-internal/src/tests/samples/typedDictClosed7.py b/packages/vipeye-internal/src/tests/samples/typedDictClosed7.py index 939ad477..6cacf132 100644 --- a/packages/vipeye-internal/src/tests/samples/typedDictClosed7.py +++ b/packages/vipeye-internal/src/tests/samples/typedDictClosed7.py @@ -2,7 +2,7 @@ # TypedDict under certain circumstances. from typing import NotRequired, Required, TypedDict -from typing_extensions import ReadOnly # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ReadOnly # viper: ignore[reportMissingModuleSource] class TD1(TypedDict, total=False, extra_items=int): diff --git a/packages/vipeye-internal/src/tests/samples/typedDictClosed8.py b/packages/vipeye-internal/src/tests/samples/typedDictClosed8.py index 829d27b8..4768a8cb 100644 --- a/packages/vipeye-internal/src/tests/samples/typedDictClosed8.py +++ b/packages/vipeye-internal/src/tests/samples/typedDictClosed8.py @@ -1,7 +1,7 @@ # This sample tests the case where bidirectional type inference is required # for the extra_items in a closed TypedDict. -from typing_extensions import TypedDict # pyright: ignore[reportMissingModuleSource] +from typing_extensions import TypedDict # viper: ignore[reportMissingModuleSource] class Typed(TypedDict, extra_items=str | int): diff --git a/packages/vipeye-internal/src/tests/samples/typedDictClosed9.py b/packages/vipeye-internal/src/tests/samples/typedDictClosed9.py index 798ee46a..3cf3ac59 100644 --- a/packages/vipeye-internal/src/tests/samples/typedDictClosed9.py +++ b/packages/vipeye-internal/src/tests/samples/typedDictClosed9.py @@ -1,7 +1,7 @@ # This sample tests the handling of calls with unpacked TypedDicts. -from typing_extensions import TypedDict # pyright: ignore[reportMissingModuleSource] +from typing_extensions import TypedDict # viper: ignore[reportMissingModuleSource] class ClosedTD1(TypedDict, closed=True): diff --git a/packages/vipeye-internal/src/tests/samples/typedDictReadOnly1.py b/packages/vipeye-internal/src/tests/samples/typedDictReadOnly1.py index 75a49150..24187a59 100644 --- a/packages/vipeye-internal/src/tests/samples/typedDictReadOnly1.py +++ b/packages/vipeye-internal/src/tests/samples/typedDictReadOnly1.py @@ -1,10 +1,10 @@ # This sample tests error conditions for TypedDict classes with # read-only entries as introduced in PEP 705. -# pyright: reportIncompatibleVariableOverride=true +# viper: reportIncompatibleVariableOverride=true from typing import NotRequired, Required, TypedDict -from typing_extensions import ReadOnly # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ReadOnly # viper: ignore[reportMissingModuleSource] class TD1(TypedDict): diff --git a/packages/vipeye-internal/src/tests/samples/typedDictReadOnly2.py b/packages/vipeye-internal/src/tests/samples/typedDictReadOnly2.py index 12e446b9..96d3f052 100644 --- a/packages/vipeye-internal/src/tests/samples/typedDictReadOnly2.py +++ b/packages/vipeye-internal/src/tests/samples/typedDictReadOnly2.py @@ -1,7 +1,7 @@ # This sample tests various uses of ReadOnly fields in TypedDict classes # as specified in PEP 705. -# pyright: reportIncompatibleVariableOverride=true +# viper: reportIncompatibleVariableOverride=true from typing import ( Generic, @@ -14,7 +14,7 @@ from typing import ( TypedDict, Unpack, ) -from typing_extensions import ReadOnly # pyright: ignore[reportMissingModuleSource] +from typing_extensions import ReadOnly # viper: ignore[reportMissingModuleSource] _T = TypeVar("_T") diff --git a/packages/vipeye-internal/src/tests/samples/uninitializedVariable3.py b/packages/vipeye-internal/src/tests/samples/uninitializedVariable3.py index 844d9328..c66612ac 100644 --- a/packages/vipeye-internal/src/tests/samples/uninitializedVariable3.py +++ b/packages/vipeye-internal/src/tests/samples/uninitializedVariable3.py @@ -1,7 +1,7 @@ # This sample tests a special case for the reportUninitializedInstanceVariable # test involving NamedTuple classes. -# pyright: reportUninitializedInstanceVariable=true +# viper: reportUninitializedInstanceVariable=true from typing import final, NamedTuple diff --git a/packages/vipeye-internal/src/tests/samples/unions3.py b/packages/vipeye-internal/src/tests/samples/unions3.py index 2da0130f..81c8bcf6 100644 --- a/packages/vipeye-internal/src/tests/samples/unions3.py +++ b/packages/vipeye-internal/src/tests/samples/unions3.py @@ -2,7 +2,7 @@ # is supported for classes that have a custom metaclass # with a __or__ or __ror__ method defined. -# pyright: reportIncompatibleMethodOverride=false +# viper: reportIncompatibleMethodOverride=false from typing import Type, TypeVar diff --git a/packages/vipeye-internal/src/tests/samples/unpack1.py b/packages/vipeye-internal/src/tests/samples/unpack1.py index 0f3f2b1c..9c05ef14 100644 --- a/packages/vipeye-internal/src/tests/samples/unpack1.py +++ b/packages/vipeye-internal/src/tests/samples/unpack1.py @@ -1,6 +1,6 @@ # This sample tests the type checker's handling of the unpack operator. -# pyright: strictListInference=true +# viper: strictListInference=true class Class1: ... diff --git a/packages/vipeye-internal/src/tests/samples/pyrightComment1.py b/packages/vipeye-internal/src/tests/samples/viperComment1.py similarity index 71% rename from packages/vipeye-internal/src/tests/samples/pyrightComment1.py rename to packages/vipeye-internal/src/tests/samples/viperComment1.py index 11dfca8f..f3e7289e 100644 --- a/packages/vipeye-internal/src/tests/samples/pyrightComment1.py +++ b/packages/vipeye-internal/src/tests/samples/viperComment1.py @@ -7,22 +7,22 @@ # pyright: # This should generate an error because the value is missing. -# pyright: reportMissingTypeStubs +# viper: reportMissingTypeStubs # This should generate an error because the value is missing. -# pyright: reportMissingTypeStubs= +# viper: reportMissingTypeStubs= # This should generate two errors because the values are invalid. -# pyright: reportMissingTypeStubs = blah , strictListInference = none +# viper: reportMissingTypeStubs = blah , strictListInference = none # This should generate two errors because the rule is invalid. -# pyright: reportBlahBlah = true +# viper: reportBlahBlah = true # This should generate an error because it's not on its own line. -a = 1 # pyright: reportGeneralTypeIssues=false +a = 1 # viper: reportGeneralTypeIssues=false def func1(): # This should generate an error because it's not on its own line. - # pyright: reportGeneralTypeIssues=false + # viper: reportGeneralTypeIssues=false pass diff --git a/packages/vipeye-internal/src/tests/samples/pyrightIgnore1.py b/packages/vipeye-internal/src/tests/samples/viperIgnore1.py similarity index 55% rename from packages/vipeye-internal/src/tests/samples/pyrightIgnore1.py rename to packages/vipeye-internal/src/tests/samples/viperIgnore1.py index af108ce6..d18f2363 100644 --- a/packages/vipeye-internal/src/tests/samples/pyrightIgnore1.py +++ b/packages/vipeye-internal/src/tests/samples/viperIgnore1.py @@ -1,15 +1,15 @@ -# This sample tests the # pyright: ignore comment. +# This sample tests the # viper: ignore comment. import sys def func1(self, x: int | None) -> str: # This should suppress the error - x + "hi" # pyright: ignore - test + x + "hi" # viper: ignore - test # This should not suppress the error because the rule doesn't match. - return 3 # pyright: ignore [foo] + return 3 # viper: ignore [foo] if sys.version_info < (3, 8): - x = 3 # pyright: ignore + x = 3 # viper: ignore diff --git a/packages/vipeye-internal/src/tests/samples/pyrightIgnore2.py b/packages/vipeye-internal/src/tests/samples/viperIgnore2.py similarity index 57% rename from packages/vipeye-internal/src/tests/samples/pyrightIgnore2.py rename to packages/vipeye-internal/src/tests/samples/viperIgnore2.py index 279efddd..6bc65aa8 100644 --- a/packages/vipeye-internal/src/tests/samples/pyrightIgnore2.py +++ b/packages/vipeye-internal/src/tests/samples/viperIgnore2.py @@ -4,19 +4,19 @@ def func1(self, x: int | None) -> str: # This should suppress the error - v1 = x + "hi" # pyright: ignore - test + v1 = x + "hi" # viper: ignore - test # This is unnecessary - v2 = x + x # pyright: ignore + v2 = x + x # viper: ignore # This will not suppress the error # These are both unnecessary - v3 = x + x # pyright: ignore [foo, bar] + v3 = x + x # viper: ignore [foo, bar] # This will not suppress the error - v4 = x + x # pyright: ignore [] + v4 = x + x # viper: ignore [] # One of these is unnecessary - v5 = x + "hi" # test # pyright: ignore [reportOperatorIssue, foo] + v5 = x + "hi" # test # viper: ignore [reportOperatorIssue, foo] - return 3 # pyright: ignore [reportReturnType] + return 3 # viper: ignore [reportReturnType] diff --git a/packages/vipeye-internal/src/tests/service.test.ts b/packages/vipeye-internal/src/tests/service.test.ts index 521babce..121a7836 100644 --- a/packages/vipeye-internal/src/tests/service.test.ts +++ b/packages/vipeye-internal/src/tests/service.test.ts @@ -183,7 +183,7 @@ test('temp file', () => { test('excluded file', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "exclude": ["**/excluded.py"] //// } @@ -200,7 +200,7 @@ test('excluded file', () => { test('excluded but still part of program', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "exclude": ["**/excluded.py"] //// } @@ -345,7 +345,7 @@ test('random folder changed', () => { test('excluded folder changed', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "exclude": ["**/.*"] //// } @@ -359,7 +359,7 @@ test('excluded folder changed', () => { test('file under excluded folder changed', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "exclude": ["**/.*"] //// } @@ -376,7 +376,7 @@ test('file under excluded folder changed', () => { test('folder under excluded folder changed', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "exclude": ["**/.*"] //// } @@ -390,7 +390,7 @@ test('folder under excluded folder changed', () => { test('folder that contains no file has changed', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "exclude": ["**/excluded.py"] //// } @@ -416,7 +416,7 @@ test('folder that contains a file has changed', () => { test('folder that contains no file but whose parent has __init__ has changed', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "exclude": ["**/excluded.py"] //// } diff --git a/packages/vipeye-internal/src/tests/signatureHelp.test.ts b/packages/vipeye-internal/src/tests/signatureHelp.test.ts index f7ea76b3..2a45646a 100644 --- a/packages/vipeye-internal/src/tests/signatureHelp.test.ts +++ b/packages/vipeye-internal/src/tests/signatureHelp.test.ts @@ -10,7 +10,7 @@ import assert from 'assert'; import { CancellationToken, MarkupKind, SignatureHelp } from 'vscode-languageserver'; import { SignatureHelpProvider } from '../languageService/signatureHelpProvider'; import { parseAndGetTestState, TestState } from './harness/fourslash/testState'; -import { PyrightDocStringService } from '../common/docStringService'; +import { ViperDocStringService } from '../common/docStringService'; test('invalid position in format string segment', () => { const code = ` @@ -62,7 +62,7 @@ test('nested call in format string segment', () => { test('signature help shows source default values for stub ellipsis defaults', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -90,7 +90,7 @@ test('signature help shows source default values for stub ellipsis defaults', () test('signature help substitutes multiple stub ellipsis defaults from source', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -119,7 +119,7 @@ test('signature help substitutes multiple stub ellipsis defaults from source', ( test('signature help shows concrete default values when provided by stub', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -144,7 +144,7 @@ test('signature help shows concrete default values when provided by stub', () => test('signature help substitutes stub ellipsis defaults for all overloads', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -184,7 +184,7 @@ test('signature help substitutes stub ellipsis defaults for all overloads', () = test('signature help does not substitute when stub default is not ellipsis', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -213,7 +213,7 @@ test('signature help does not substitute when stub default is not ellipsis', () test('signature help does not substitute when source implementation is missing', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -238,7 +238,7 @@ test('signature help does not substitute when source implementation is missing', test('signature help does not substitute unsafe long defaults for stub ellipsis defaults', () => { const longNumber = '9'.repeat(150); const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -267,7 +267,7 @@ test('signature help does not substitute unsafe long defaults for stub ellipsis test('signature help does not substitute unsafe multiline defaults for stub ellipsis defaults', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -297,7 +297,7 @@ test('signature help does not substitute unsafe multiline defaults for stub elli test('signature help overloads: mixed ellipsis and concrete defaults', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -336,7 +336,7 @@ test('signature help overloads: mixed ellipsis and concrete defaults', () => { test('signature help overloads: overload with no defaults stays unchanged', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -375,7 +375,7 @@ test('signature help overloads: overload with no defaults stays unchanged', () = test('signature help overloads: param name not in source keeps ellipsis', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -414,7 +414,7 @@ test('signature help overloads: param name not in source keeps ellipsis', () => test('signature help overloads: source uses *args/**kwargs, no substitution', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -452,7 +452,7 @@ test('signature help overloads: source uses *args/**kwargs, no substitution', () test('signature help overloads: different param counts, extra params keep ellipsis', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -601,7 +601,7 @@ function getSignatureHelpForMarker(state: TestState, markerName: string): Signat /*hasSignatureLabelOffsetCapability*/ true, /*hasActiveParameterCapability*/ true, /*context*/ undefined, - new PyrightDocStringService(), + new ViperDocStringService(), CancellationToken.None ).getSignatureHelp(); } diff --git a/packages/vipeye-internal/src/tests/sourceFile.test.ts b/packages/vipeye-internal/src/tests/sourceFile.test.ts index 44483928..e348c08c 100644 --- a/packages/vipeye-internal/src/tests/sourceFile.test.ts +++ b/packages/vipeye-internal/src/tests/sourceFile.test.ts @@ -4,7 +4,7 @@ * Licensed under the MIT license. * Author: Eric Traut * - * Unit tests for pyright sourceFile module. + * Unit tests for viper sourceFile module. */ import * as assert from 'assert'; @@ -79,7 +79,7 @@ test('Empty Open file', () => { test('No unexpected user files', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "pythonVersion": "3.14" //// } diff --git a/packages/vipeye-internal/src/tests/sourceMapperUtils.test.ts b/packages/vipeye-internal/src/tests/sourceMapperUtils.test.ts index f25f95f0..1b08bd79 100644 --- a/packages/vipeye-internal/src/tests/sourceMapperUtils.test.ts +++ b/packages/vipeye-internal/src/tests/sourceMapperUtils.test.ts @@ -3,7 +3,7 @@ * Copyright (c) Microsoft Corporation. * Licensed under the MIT license. * - * Unit tests for pyright sourceMapperUtils module. + * Unit tests for viper sourceMapperUtils module. */ import assert from 'assert'; import { CancellationToken, CancellationTokenSource } from 'vscode-jsonrpc'; @@ -29,7 +29,7 @@ import { UriEx } from '../common/uri/uriUtils'; import { HoverProvider } from '../languageService/hoverProvider'; import { PartialStubService } from '../partialStubService'; import { NameNode, ParseNodeType } from '../parser/parseNodes'; -import { PyrightFileSystem } from '../pyrightFileSystem'; +import { ViperFileSystem } from '../viperFileSystem'; import { parseTestData } from './harness/fourslash/fourSlashParser'; import { TestAccessHost } from './harness/testAccessHost'; import { getNodeAtMarker, parseAndGetTestState } from './harness/fourslash/testState'; @@ -261,7 +261,7 @@ function assertTypeAlias(code: string) { test('find method declarations through alias factory assignment', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "useLibraryCodeForTypes": true //// } @@ -461,7 +461,7 @@ function createAnalyzerServiceFromCode(code: string, pythonSearchPaths: string[] testFS.writeFileSync(UriEx.file(filePath), file.content, 'utf8'); } - const fs = new PyrightFileSystem(testFS); + const fs = new ViperFileSystem(testFS); const serviceProvider = createServiceProvider(testFS, fs, new PartialStubService(fs)); const configOptions = new ConfigOptions(UriEx.file('/')); configOptions.internalTestMode = true; diff --git a/packages/vipeye-internal/src/tests/testState.test.ts b/packages/vipeye-internal/src/tests/testState.test.ts index fb610fc6..e72de20b 100644 --- a/packages/vipeye-internal/src/tests/testState.test.ts +++ b/packages/vipeye-internal/src/tests/testState.test.ts @@ -54,7 +54,7 @@ test('Multiple files', () => { test('Configuration', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "include": [ //// "src" @@ -132,7 +132,7 @@ test('Configuration', () => { test('stubPath configuration', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "stubPath": "src/typestubs" //// } @@ -142,11 +142,11 @@ test('stubPath configuration', () => { assert.equal(state.configOptions.stubPath?.getFilePath(), normalizeSlashes('/src/typestubs')); }); -test('pyrightconfig.json exists in VFS', () => { - // Regression test: pyrightconfig.json should be written to the virtual file system, +test('viperconfig.json exists in VFS', () => { + // Regression test: viperconfig.json should be written to the virtual file system, // not just parsed for config options. const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "stubPath": "my_stubs" //// } @@ -157,12 +157,12 @@ test('pyrightconfig.json exists in VFS', () => { const state = parseAndGetTestState(code, factory.srcFolder).state; - // The pyrightconfig.json file should exist in the VFS + // The viperconfig.json file should exist in the VFS const configUri = Uri.file( - normalizeSlashes(combinePaths(factory.srcFolder, 'pyrightconfig.json')), + normalizeSlashes(combinePaths(factory.srcFolder, 'viperconfig.json')), state.serviceProvider ); - assert(state.fs.existsSync(configUri), `pyrightconfig.json should exist in VFS at ${configUri.toString()}`); + assert(state.fs.existsSync(configUri), `viperconfig.json should exist in VFS at ${configUri.toString()}`); // The config should also be parsed correctly assert.equal(state.configOptions.stubPath?.getFilePath(), normalizeSlashes('/my_stubs')); @@ -170,7 +170,7 @@ test('pyrightconfig.json exists in VFS', () => { test('Duplicated stubPath configuration', () => { const code = ` -// @filename: pyrightconfig.json +// @filename: viperconfig.json //// { //// "typingsPath": "src/typestubs1", //// "stubPath": "src/typestubs2" diff --git a/packages/vipeye-internal/src/tests/typeEvaluator1.test.ts b/packages/vipeye-internal/src/tests/typeEvaluator1.test.ts index 4f892423..600d48cf 100644 --- a/packages/vipeye-internal/src/tests/typeEvaluator1.test.ts +++ b/packages/vipeye-internal/src/tests/typeEvaluator1.test.ts @@ -4,7 +4,7 @@ * Licensed under the MIT license. * Author: Eric Traut * - * Unit tests for pyright type evaluator. Tests are split + * Unit tests for viper type evaluator. Tests are split * arbitrarily among multiple files so they can run in parallel. */ diff --git a/packages/vipeye-internal/src/tests/typeEvaluator2.test.ts b/packages/vipeye-internal/src/tests/typeEvaluator2.test.ts index b6db2402..40887446 100644 --- a/packages/vipeye-internal/src/tests/typeEvaluator2.test.ts +++ b/packages/vipeye-internal/src/tests/typeEvaluator2.test.ts @@ -4,7 +4,7 @@ * Licensed under the MIT license. * Author: Eric Traut * - * Unit tests for pyright type evaluator. Tests are split + * Unit tests for viper type evaluator. Tests are split * arbitrarily among multiple files so they can run in parallel. */ diff --git a/packages/vipeye-internal/src/tests/typeEvaluator3.test.ts b/packages/vipeye-internal/src/tests/typeEvaluator3.test.ts index 10cda52e..11a0885f 100644 --- a/packages/vipeye-internal/src/tests/typeEvaluator3.test.ts +++ b/packages/vipeye-internal/src/tests/typeEvaluator3.test.ts @@ -4,7 +4,7 @@ * Licensed under the MIT license. * Author: Eric Traut * - * Unit tests for pyright type evaluator. Tests are split + * Unit tests for viper type evaluator. Tests are split * arbitrarily among multiple files so they can run in parallel. */ diff --git a/packages/vipeye-internal/src/tests/typeEvaluator4.test.ts b/packages/vipeye-internal/src/tests/typeEvaluator4.test.ts index be802a24..fcfd7bf7 100644 --- a/packages/vipeye-internal/src/tests/typeEvaluator4.test.ts +++ b/packages/vipeye-internal/src/tests/typeEvaluator4.test.ts @@ -4,7 +4,7 @@ * Licensed under the MIT license. * Author: Eric Traut * - * Unit tests for pyright type evaluator. Tests are split + * Unit tests for viper type evaluator. Tests are split * arbitrarily among multiple files so they can run in parallel. */ diff --git a/packages/vipeye-internal/src/tests/typeEvaluator5.test.ts b/packages/vipeye-internal/src/tests/typeEvaluator5.test.ts index bf35f9c0..488aa8ce 100644 --- a/packages/vipeye-internal/src/tests/typeEvaluator5.test.ts +++ b/packages/vipeye-internal/src/tests/typeEvaluator5.test.ts @@ -4,7 +4,7 @@ * Licensed under the MIT license. * Author: Eric Traut * - * Unit tests for pyright type evaluator. Tests are split + * Unit tests for viper type evaluator. Tests are split * arbitrarily among multiple files so they can run in parallel. */ diff --git a/packages/vipeye-internal/src/tests/typeEvaluator6.test.ts b/packages/vipeye-internal/src/tests/typeEvaluator6.test.ts index eb1d6a09..9e2c06ca 100644 --- a/packages/vipeye-internal/src/tests/typeEvaluator6.test.ts +++ b/packages/vipeye-internal/src/tests/typeEvaluator6.test.ts @@ -4,7 +4,7 @@ * Licensed under the MIT license. * Author: Eric Traut * - * Unit tests for pyright type evaluator. Tests are split + * Unit tests for viper type evaluator. Tests are split * arbitrarily among multiple files so they can run in parallel. */ diff --git a/packages/vipeye-internal/src/tests/typeEvaluator7.test.ts b/packages/vipeye-internal/src/tests/typeEvaluator7.test.ts index 22315e91..d4be9199 100644 --- a/packages/vipeye-internal/src/tests/typeEvaluator7.test.ts +++ b/packages/vipeye-internal/src/tests/typeEvaluator7.test.ts @@ -4,7 +4,7 @@ * Licensed under the MIT license. * Author: Eric Traut * - * Unit tests for pyright type evaluator. Tests are split + * Unit tests for viper type evaluator. Tests are split * arbitrarily among multiple files so they can run in parallel. */ diff --git a/packages/vipeye-internal/src/tests/typeEvaluator8.test.ts b/packages/vipeye-internal/src/tests/typeEvaluator8.test.ts index 2af5098a..c84faadc 100644 --- a/packages/vipeye-internal/src/tests/typeEvaluator8.test.ts +++ b/packages/vipeye-internal/src/tests/typeEvaluator8.test.ts @@ -4,7 +4,7 @@ * Licensed under the MIT license. * Author: Eric Traut * - * Unit tests for pyright type evaluator. Tests are split + * Unit tests for viper type evaluator. Tests are split * arbitrarily among multiple files so they can run in parallel. */ diff --git a/packages/vipeye-internal/src/tests/typeServer/inProcTypeServerTestUtils.ts b/packages/vipeye-internal/src/tests/typeServer/inProcTypeServerTestUtils.ts index 01fe7f6b..42ac00ef 100644 --- a/packages/vipeye-internal/src/tests/typeServer/inProcTypeServerTestUtils.ts +++ b/packages/vipeye-internal/src/tests/typeServer/inProcTypeServerTestUtils.ts @@ -3,14 +3,14 @@ * Copyright (c) Microsoft Corporation. * Licensed under the MIT license. * - * In-process test harness for the Pyright type server (TSP). + * In-process test harness for the Viper type server (TSP). * * Boots a `TypeServer` over a pair of in-memory duplex streams so tests can drive the * protocol requests directly (initialize, open documents, query types). This exercises the * full server-side conversion path (fromProtocolNode -> evaluate -> ProtocolTypeFactory) * without needing any client-side consumer stack. * - * This is a Pyright-native adaptation of Pylance's `inProcTypeServerTestUtils`. It omits the + * This is a Vipeye-native adaptation of Pylance's `inProcTypeServerTestUtils`. It omits the * client-side `ExternalProgram`/`snapshotSync` machinery (which stays in Pylance) and asserts * on the protocol-level responses instead. */ @@ -265,10 +265,10 @@ async function createInProcTypeServer(code: string): Promise { const fourslash = parseTestData(DEFAULT_WORKSPACE_ROOT, code, 'main.py'); const testFS = createFileSystem(DEFAULT_WORKSPACE_ROOT, fourslash); const uriMapper = new NotebookUriMapper(testFS); - const pyrightFs = new TypeServerFileSystem(testFS, uriMapper); + const viperFs = new TypeServerFileSystem(testFS, uriMapper); const serverConsole = new ConsoleWithLogLevel(new NullConsole(), 'typeServer.inProc'); - const partialStubs = new PartialStubService(pyrightFs); - const serviceProvider = createServiceProvider(testFS, pyrightFs, serverConsole, partialStubs); + const partialStubs = new PartialStubService(viperFs); + const serviceProvider = createServiceProvider(testFS, viperFs, serverConsole, partialStubs); serviceProvider.add(TypeServerServiceKeys.uriMapper, uriMapper); const fileWatcherProvider = new WorkspaceFileWatcherProvider(); @@ -276,7 +276,7 @@ async function createInProcTypeServer(code: string): Promise { const server = new TypeServer( { - productName: 'PyrightInProcTypeServer', + productName: 'VipeyeInProcTypeServer', rootDirectory: rootUri, version: '1.0.0-test', serviceProvider, diff --git a/packages/vipeye-internal/src/tests/typeServer/notebook.typeServer.test.ts b/packages/vipeye-internal/src/tests/typeServer/notebook.typeServer.test.ts index c3ef530b..b5d251b6 100644 --- a/packages/vipeye-internal/src/tests/typeServer/notebook.typeServer.test.ts +++ b/packages/vipeye-internal/src/tests/typeServer/notebook.typeServer.test.ts @@ -6,7 +6,7 @@ * Tests for the type server's notebook cell-chain maintenance (NotebookUriMapper + * createNotebookData / openNotebookCellChain / updateNotebookStructure). * - * This is a Pyright-native port of Pylance's `notebook.common.ts`. It exercises only the + * This is a Vipeye-native port of Pylance's `notebook.common.ts`. It exercises only the * cell-chain core functions against a real AnalyzerService; it does not drive the notebook * document handler (which just sequences calls to these same functions). */ @@ -28,7 +28,7 @@ import { normalizeSlashes } from '../../common/pathUtils'; import { ServiceKeys } from '../../common/serviceKeys'; import { createServiceProvider } from '../../common/serviceProviderExtensions'; import { Uri } from '../../common/uri/uri'; -import { PyrightFileSystem } from '../../pyrightFileSystem'; +import { ViperFileSystem } from '../../viperFileSystem'; import { createNotebookData, openNotebookCellChain, updateNotebookStructure } from '../../typeServer/notebookCellChain'; import { NotebookUriMapper } from '../../typeServer/notebookUriMapper'; import { createInitStatus, WellKnownWorkspaceKinds, Workspace } from '../../workspaceFactory'; @@ -39,7 +39,7 @@ describe('updateNotebookStructure Tests (typeServer mode)', () => { const testFileSystem = createFromFileSystem(host.HOST, /* ignoreCase */ false, { cwd: normalizeSlashes('/'), }); - const fileSystem = new PyrightFileSystem(testFileSystem); + const fileSystem = new ViperFileSystem(testFileSystem); const serviceProvider = createServiceProvider(testFileSystem, fileSystem); let uriMapper: NotebookUriMapper; let analyzerService: AnalyzerService; diff --git a/packages/vipeye-internal/src/tests/typeServer/typeServer.inProc.test.ts b/packages/vipeye-internal/src/tests/typeServer/typeServer.inProc.test.ts index 752c50ea..89b92033 100644 --- a/packages/vipeye-internal/src/tests/typeServer/typeServer.inProc.test.ts +++ b/packages/vipeye-internal/src/tests/typeServer/typeServer.inProc.test.ts @@ -3,14 +3,14 @@ * Copyright (c) Microsoft Corporation. * Licensed under the MIT license. * - * In-process protocol tests for the Pyright type server (TSP). + * In-process protocol tests for the Viper type server (TSP). * * These exercise the server-side request handlers end-to-end over a real JSON-RPC * connection (in-memory streams), including the `_onGetType` conversion path * (fromProtocolNode -> evaluate via the sync->async adapter -> ProtocolTypeFactory). * * Ported from Pylance's `typeServer.inProc.test.ts`. The Pylance round-trip tests that - * reconstruct a Pyright `Type` from the protocol `Type` depend on the client-side consumer + * reconstruct a Vipeye `Type` from the protocol `Type` depend on the client-side consumer * stack (ExternalProgram / snapshotSync), which stays in Pylance, so they are intentionally * not ported here. Instead these tests assert on the protocol-level responses. */ diff --git a/packages/vipeye-internal/src/tests/pyrightFileSystem.test.ts b/packages/vipeye-internal/src/tests/viperFileSystem.test.ts similarity index 97% rename from packages/vipeye-internal/src/tests/pyrightFileSystem.test.ts rename to packages/vipeye-internal/src/tests/viperFileSystem.test.ts index 662a1b64..4973220b 100644 --- a/packages/vipeye-internal/src/tests/pyrightFileSystem.test.ts +++ b/packages/vipeye-internal/src/tests/viperFileSystem.test.ts @@ -1,14 +1,14 @@ /* - * pyrightFileSystem.test.ts + * viperFileSystem.test.ts * - * pyrightFileSystem tests. + * viperFileSystem tests. */ import assert from 'assert'; import { lib, sitePackages } from '../common/pathConsts'; import { combinePaths, getDirectoryPath, normalizeSlashes } from '../common/pathUtils'; -import { PyrightFileSystem } from '../pyrightFileSystem'; +import { ViperFileSystem } from '../viperFileSystem'; import { TestFileSystem } from './harness/vfs/filesystem'; import { Uri } from '../common/uri/uri'; import { UriEx } from '../common/uri/uriUtils'; @@ -76,7 +76,7 @@ test('mapped symlinks reflect their targets', () => { testFs.symlinkSync(markerSource, combinePaths(stubPackage, 'py.typed')); testFs.symlinkSync(combinePaths(normalizeSlashes('/'), 'wheel', 'missing.pyi'), missingStub); - const fs = new PyrightFileSystem(testFs); + const fs = new ViperFileSystem(testFs); const ps = new PartialStubService(fs); ps.processPartialStubPackages([libraryRootUri], [libraryRootUri]); @@ -271,7 +271,7 @@ test('bundled partial stubs', () => { assert.strictEqual(2, entries.length); }); -function createFileSystem(files: { path: string; content: string }[]): PyrightFileSystem { +function createFileSystem(files: { path: string; content: string }[]): ViperFileSystem { const fs = new TestFileSystem(/* ignoreCase */ false, { cwd: normalizeSlashes('/') }); for (const file of files) { @@ -282,5 +282,5 @@ function createFileSystem(files: { path: string; content: string }[]): PyrightFi fs.writeFileSync(Uri.file(path, fs), file.content); } - return new PyrightFileSystem(fs); + return new ViperFileSystem(fs); } diff --git a/packages/vipeye-internal/src/typeServer/diagnosticUtils.ts b/packages/vipeye-internal/src/typeServer/diagnosticUtils.ts index 941ea1d1..cd96728b 100644 --- a/packages/vipeye-internal/src/typeServer/diagnosticUtils.ts +++ b/packages/vipeye-internal/src/typeServer/diagnosticUtils.ts @@ -3,9 +3,9 @@ * Copyright (c) Microsoft Corporation. * Licensed under the MIT license. * - * Converts Pyright's internal diagnostics into LSP diagnostics for the type server. + * Converts Vipeye's internal diagnostics into LSP diagnostics for the type server. * This mirrors `LanguageServerBase._convertDiagnostics`; the Pylance-only VS "task item" - * ranking is omitted (task-item diagnostics are dropped, matching Pyright's own server). + * ranking is omitted (task-item diagnostics are dropped, matching Vipeye's own server). */ import { @@ -16,7 +16,7 @@ import { Location, } from 'vscode-languageserver'; -import { Diagnostic as PyrightDiagnostic, DiagnosticCategory } from '../common/diagnostic'; +import { Diagnostic as ViperDiagnostic, DiagnosticCategory } from '../common/diagnostic'; import { ReadOnlyFileSystem } from '../common/fileSystem'; import { convertUriToLspUriString } from '../common/uri/uriUtils'; import { canNavigateToFile } from '../languageService/navigationUtils'; @@ -40,15 +40,15 @@ function convertCategoryToSeverity(category: DiagnosticCategory): DiagnosticSeve } } -export function convertFromPyrightDiagnostic( - diag: PyrightDiagnostic, +export function convertFromViperDiagnostic( + diag: ViperDiagnostic, fs: ReadOnlyFileSystem, supportsUnnecessaryDiagnosticTag: boolean, supportsTaskItemDiagnosticTag: boolean ): Diagnostic | undefined { const severity = convertCategoryToSeverity(diag.category); const rule = diag.getRule(); - const vsDiag = Diagnostic.create(diag.range, diag.message, severity, rule, 'pyright'); + const vsDiag = Diagnostic.create(diag.range, diag.message, severity, rule, 'viper'); // Save all of the actions in the data. const actions = diag.getActions(); diff --git a/packages/vipeye-internal/src/typeServer/nodeMain.ts b/packages/vipeye-internal/src/typeServer/nodeMain.ts index a3240293..16599ec3 100644 --- a/packages/vipeye-internal/src/typeServer/nodeMain.ts +++ b/packages/vipeye-internal/src/typeServer/nodeMain.ts @@ -3,10 +3,10 @@ * Copyright (c) Microsoft Corporation. * Licensed under the MIT license. * - * Provides the main entrypoint to the Pyright type server when running in Node. + * Provides the main entrypoint to the Viper type server when running in Node. * - * This lives in vipeye-internal (rather than the pyright-typeserver package) so that all - * vscode-languageserver usage resolves to a single copy, matching how the `pyright` + * This lives in vipeye-internal (rather than the vipeye-typeserver package) so that all + * vscode-languageserver usage resolves to a single copy, matching how the `vipeye` * package keeps its own entry points as thin shims over vipeye-internal. */ @@ -67,7 +67,7 @@ export async function main() { new TypeServer( { - productName: 'PyrightTypeServer', + productName: 'VipeyeTypeServer', rootDirectory: realPathRoot, version, serviceProvider, diff --git a/packages/vipeye-internal/src/typeServer/notebookCellChain.ts b/packages/vipeye-internal/src/typeServer/notebookCellChain.ts index ffba2a23..e51cac34 100644 --- a/packages/vipeye-internal/src/typeServer/notebookCellChain.ts +++ b/packages/vipeye-internal/src/typeServer/notebookCellChain.ts @@ -6,12 +6,12 @@ * Mode-agnostic helpers for analyzing notebook documents as chains of cell "files". * * A notebook is modeled as a linear chain of source files: a synthetic prefix cell followed - * by one file per code cell, each chained to its predecessor (via Pyright's chained-source-file + * by one file per code cell, each chained to its predecessor (via Vipeye's chained-source-file * support and `IPythonMode.CellDocs`). This lets symbols defined in an earlier cell be visible * in later cells, matching Jupyter execution semantics. * * These functions are a near-direct port of Pylance's notebook helpers from - * `pylance-internal/src/server/common.ts`, retyped onto Pyright's `Workspace`. They only touch + * `pylance-internal/src/server/common.ts`, retyped onto Vipeye's `Workspace`. They only touch * `workspace.service` (an `AnalyzerService`) so they work with any workspace implementation. */ diff --git a/packages/vipeye-internal/src/typeServer/profilingStub.ts b/packages/vipeye-internal/src/typeServer/profilingStub.ts index 17172805..85a5a125 100644 --- a/packages/vipeye-internal/src/typeServer/profilingStub.ts +++ b/packages/vipeye-internal/src/typeServer/profilingStub.ts @@ -4,7 +4,7 @@ * Licensed under the MIT license. * * The Pylance type server integrated with a profiling service. Profiling is a - * Pylance-only feature, so the standalone Pyright type server keeps only the shape + * Pylance-only feature, so the standalone Viper type server keeps only the shape * (`ProfilingInfo`) that the program interfaces reference; there is no profiler. */ diff --git a/packages/vipeye-internal/src/typeServer/programTypes.ts b/packages/vipeye-internal/src/typeServer/programTypes.ts index d4d04547..ea15f7df 100644 --- a/packages/vipeye-internal/src/typeServer/programTypes.ts +++ b/packages/vipeye-internal/src/typeServer/programTypes.ts @@ -17,7 +17,7 @@ import { ExpectedTypeResult } from '../analyzer/typeEvaluatorTypes'; import { ClassType, Type } from '../analyzer/types'; import { ConfigOptions } from '../common/configOptions'; import { ConsoleInterface } from '../common/console'; -import { Diagnostic as PyrightDiagnostic } from '../common/diagnostic'; +import { Diagnostic as ViperDiagnostic } from '../common/diagnostic'; import { FileEditAction } from '../common/editAction'; import { SourceFileInfo } from '../common/extensibility'; import { ReadOnlyFileSystem } from '../common/fileSystem'; @@ -82,7 +82,7 @@ export interface IProgramBase extends IParserOutputProvider { readonly fileSystem: ReadOnlyFileSystem; readonly serviceProvider: ServiceProvider; readonly isAlive: boolean; - readonly isPyright: boolean; + readonly isVipeye: boolean; readonly performsAnalysis: boolean; readonly supportsPullDiagnostics: boolean; owns(uri: Uri): boolean; @@ -125,7 +125,7 @@ export interface IProgram extends IProgramBase, ITypeProvider, Disposable { // notify clients (SnapshotChangedNotification) when it changes. getSnapshot(token: CancellationToken): number; - // Runs the callback against the live program. Because Pyright's evaluator is + // Runs the callback against the live program. Because Vipeye's evaluator is // synchronous, the callback executes atomically: the program cannot be mutated // mid-run, so the callback simply receives `this`. run(callback: (p: IProgram) => T, token: CancellationToken): T; @@ -151,15 +151,15 @@ export interface IProgram extends IProgramBase, ITypeProvider, Disposable { previousResultId: string | undefined, token: CancellationToken ): DocumentDiagnosticReport; - getDiagnosticsForRangeWithoutFileIgnore?(fileUri: Uri, range: Range): readonly PyrightDiagnostic[]; + getDiagnosticsForRangeWithoutFileIgnore?(fileUri: Uri, range: Range): readonly ViperDiagnostic[]; - // Cache of `getTypeForDeclaration` results, used by the TSP→Pyright type-shell + // Cache of `getTypeForDeclaration` results, used by the TSP→Vipeye type-shell // factory to avoid re-evaluating the same declaration repeatedly during a // conversion session. Dropped whenever the snapshot increments. getCachedTypeForDeclaration(decl: Declaration): Type | undefined; setCachedTypeForDeclaration(decl: Declaration, type: Type): void; - // Cache of TSP `Declaration` → Pyright `Declaration` resolutions. Used by the + // Cache of TSP `Declaration` → Vipeye `Declaration` resolutions. Used by the // type-shell factory to avoid re-running `lookupSymbol` for the same TSP // declaration on every conversion call. Dropped whenever the snapshot increments. getCachedProtocolDecl(tspDecl: TypeServerProtocol.Declaration): Declaration | undefined; diff --git a/packages/vipeye-internal/src/typeServer/programWrapper.ts b/packages/vipeye-internal/src/typeServer/programWrapper.ts index 57097bed..2220f018 100644 --- a/packages/vipeye-internal/src/typeServer/programWrapper.ts +++ b/packages/vipeye-internal/src/typeServer/programWrapper.ts @@ -4,15 +4,15 @@ * * programWrapper.ts * - * Wraps Pyright's `Program` in the `IProgram` interface the type server consumes. + * Wraps Vipeye's `Program` in the `IProgram` interface the type server consumes. * * The wrapper is thin: every method delegates synchronously to the underlying `Program`. * It exists to (a) present the `IProgram` contract the conversion layer is written against, - * (b) reshape Pyright types (`SourceFileInfo`, `ParseFileResults`, `SourceMapper`) into the + * (b) reshape Vipeye types (`SourceFileInfo`, `ParseFileResults`, `SourceMapper`) into the * type-server-facing shapes, and (c) maintain a monotonic `snapshot` content-version counter * (on the shared `ITypeCache`) that the server exposes to clients for cache coherence. * - * Cancellation is handled the same way as everywhere else in Pyright: work runs inside + * Cancellation is handled the same way as everywhere else in Vipeye: work runs inside * `runWithCancellationToken`, and the evaluator polls the token, so long-running synchronous * queries can be interrupted mid-request. */ @@ -61,7 +61,7 @@ import { ParserOutput } from '../parser/parser'; import { createTypeServerEvaluator, ITypeServerEvaluator } from './typeServerEvaluator'; import { getEffectiveTypeOfDeclaration, getSymbolFromScope, isDeclaration } from './typeEvalUtils'; -import { convertFromPyrightDiagnostic } from './diagnosticUtils'; +import { convertFromViperDiagnostic } from './diagnosticUtils'; import { INotebookUriMapper } from './notebookUriMapper'; import { getProtocolDeclKey } from './typeServerConversionTypes'; @@ -73,12 +73,12 @@ import { IProgram, ISourceFileInfo, ISourceMapper, ISymbolLookup, ParseResults } import { ITypeCache, TypeCache } from './typeCache'; /** - * Adapter that lets the in-proc Pyright `Program` (which is mutable and has no + * Adapter that lets the in-proc Vipeye `Program` (which is mutable and has no * native snapshot concept) satisfy the `IProgram` contract the type server's * conversion layer is written against. * * - `run` runs the callback over the live `Program` via `_program.run(...)`. - * Because Pyright's evaluator is synchronous the callback executes atomically, + * Because Vipeye's evaluator is synchronous the callback executes atomically, * so it simply receives `this` — there is no copy-on-write snapshot view. * - A monotonic `snapshot` counter (on the shared `ITypeCache`) is bumped by the * mutating methods below. It is a protocol-level content version: the server @@ -169,7 +169,7 @@ export class ProgramWrapper implements IProgram { return true; } - get isPyright(): boolean { + get isVipeye(): boolean { return true; } @@ -626,7 +626,7 @@ export class ProgramWrapper implements IProgram { }; diagnostics = this._program .getDiagnosticsForRange(uri, range) - .map((d) => convertFromPyrightDiagnostic(d, this._program.fileSystem, true, true) || d); + .map((d) => convertFromViperDiagnostic(d, this._program.fileSystem, true, true) || d); versionStr = sourceFile.getDiagnosticVersion().toString(); } return { kind: 'full', resultId: versionStr, items: diagnostics }; @@ -671,7 +671,7 @@ export class ProgramWrapper implements IProgram { } // Temporary problem. If this is a class, the protocol compatibility - // map stores Pyright types in it. Remove it. + // map stores Vipeye types in it. Remove it. if (result && isClass(result) && result.shared.protocolCompatibility) { result = { ...result, shared: { ...result.shared, protocolCompatibility: undefined } }; } @@ -820,7 +820,7 @@ export class ProgramWrapper implements IProgram { // Drop the declaration→Type cache; entries are tied to parse-tree // nodes that may be replaced by re-parsed source files. this._declTypeCache = new WeakMap(); - // Drop the protocol-declaration cache; the resolved Pyright Declaration + // Drop the protocol-declaration cache; the resolved Vipeye Declaration // it points to may reference parse nodes that no longer exist. this._protocolDeclCache = new Map(); diff --git a/packages/vipeye-internal/src/typeServer/protocol/tsp.json b/packages/vipeye-internal/src/typeServer/protocol/tsp.json index 53f46e4c..e2ed158f 100644 --- a/packages/vipeye-internal/src/typeServer/protocol/tsp.json +++ b/packages/vipeye-internal/src/typeServer/protocol/tsp.json @@ -514,7 +514,7 @@ "documentation": "Whether to skip checking if the file is needed for the import resolution. When true, optimizes by not verifying file existence/validity." } ], - "documentation": "Options for customizing import resolution behavior. Controls how the type server resolves import statements and accesses imported symbols. Used for: - Fine-tuning import resolution during type checking - Controlling access to private/hidden module members - Optimizing resolution by skipping file checks TODO: See if we can remove this as these are pretty specific to Pyright at the moment. Examples: ```python # resolveLocalNames affects whether local assignments are resolved: from module import name name = something_else # Does 'name' refer to import or local assignment? # allowExternallyHiddenAccess affects access to _private names: from module import _internal_function # Normally hidden from external access ```" + "documentation": "Options for customizing import resolution behavior. Controls how the type server resolves import statements and accesses imported symbols. Used for: - Fine-tuning import resolution during type checking - Controlling access to private/hidden module members - Optimizing resolution by skipping file checks TODO: See if we can remove this as these are pretty specific to Vipeye at the moment. Examples: ```python # resolveLocalNames affects whether local assignments are resolved: from module import name name = something_else # Does 'name' refer to import or local assignment? # allowExternallyHiddenAccess affects access to _private names: from module import _internal_function # Normally hidden from external access ```" }, "ResolveImportParams": { "kind": "interface", diff --git a/packages/vipeye-internal/src/typeServer/protocol/tspSupplemental.ts b/packages/vipeye-internal/src/typeServer/protocol/tspSupplemental.ts index 581d2d3d..963c1170 100644 --- a/packages/vipeye-internal/src/typeServer/protocol/tspSupplemental.ts +++ b/packages/vipeye-internal/src/typeServer/protocol/tspSupplemental.ts @@ -3,11 +3,11 @@ * Copyright (c) Microsoft Corporation. * Licensed under the MIT license. * - * Pyright-specific supplemental extensions to the Type Server Protocol (TSP). + * Vipeye-specific supplemental extensions to the Type Server Protocol (TSP). * * These notifications are NOT part of the base TSP (defined in typeServerProtocol.ts), * which is shared by all TSP implementers (e.g., ty-tsp). This file defines - * Pyright-only extensions that require Pyright-specific knowledge (e.g., the + * Vipeye-only extensions that require Vipeye-specific knowledge (e.g., the * VirtualFileOverlayFileSystem in PylanceFileSystem). * * All the types in this file should be JSON serializable, as they are sent over the wire. @@ -40,10 +40,10 @@ export namespace TspSupplemental { * * This is used by the Django stub generation feature: Pylance's Rust sidecar writes * merged virtual `.py` files to disk, and this notification tells the type server's - * VirtualFileOverlayFileSystem to redirect reads so Pyright analyzes the virtual content. + * VirtualFileOverlayFileSystem to redirect reads so Vipeye analyzes the virtual content. */ export namespace SetVirtualFileRedirectNotification { - export const method = 'pyright/setVirtualFileRedirect' as const; + export const method = 'viper/setVirtualFileRedirect' as const; export const messageDirection = MessageDirection.clientToServer; export const type = new ProtocolNotificationType(method); } @@ -54,7 +54,7 @@ export namespace TspSupplemental { * file system should read the real file again for the given URI. */ export namespace RemoveVirtualFileRedirectNotification { - export const method = 'pyright/removeVirtualFileRedirect' as const; + export const method = 'viper/removeVirtualFileRedirect' as const; export const messageDirection = MessageDirection.clientToServer; export const type = new ProtocolNotificationType(method); } diff --git a/packages/vipeye-internal/src/typeServer/protocol/typeServerProtocol.ts b/packages/vipeye-internal/src/typeServer/protocol/typeServerProtocol.ts index ccd8e52f..f4ad8da9 100644 --- a/packages/vipeye-internal/src/typeServer/protocol/typeServerProtocol.ts +++ b/packages/vipeye-internal/src/typeServer/protocol/typeServerProtocol.ts @@ -14,7 +14,7 @@ * The protocol is designed to be extensible, allowing for future additions of new requests and notifications. * * Single source of truth: - * - Within Pyright, this `.ts` file is authoritative. The sibling `tsp.json` and + * - Within Vipeye, this `.ts` file is authoritative. The sibling `tsp.json` and * `tsp.schema.json` are GENERATED from it by `generate_json.py` (run that script * after editing this file); do not hand-edit the JSON artifacts. * - Across repos, this file is a synchronized copy of the canonical shared Type Server @@ -171,7 +171,7 @@ export namespace TypeServerProtocol { * - Controlling access to private/hidden module members * - Optimizing resolution by skipping file checks * - * TODO: See if we can remove this as these are pretty specific to Pyright at the moment. + * TODO: See if we can remove this as these are pretty specific to Vipeye at the moment. * * Examples: * ```python diff --git a/packages/vipeye-internal/src/typeServer/server.ts b/packages/vipeye-internal/src/typeServer/server.ts index dfc4a6c9..30463b7d 100644 --- a/packages/vipeye-internal/src/typeServer/server.ts +++ b/packages/vipeye-internal/src/typeServer/server.ts @@ -7,15 +7,15 @@ * to initialize and manage documents; the type-server parts answer Type Server Protocol * (TSP) requests with type information for those documents. * - * This is the Pyright-native port of Pylance's `type-server/src/server/typeServer.ts`. It - * is rebased onto Pyright's own infrastructure (`LanguageServerBase`, `WorkspaceFactory`, + * This is the Vipeye-native port of Pylance's `type-server/src/server/typeServer.ts`. It + * is rebased onto Vipeye's own infrastructure (`LanguageServerBase`, `WorkspaceFactory`, * `ImportResolver`, `BackgroundAnalysisProgram`) instead of the Pylance subclasses. Type - * queries are answered synchronously by Pyright's evaluator through the `ProgramWrapper`; - * cancellation is file/token based like the rest of Pyright, so long-running queries can + * queries are answered synchronously by Vipeye's evaluator through the `ProgramWrapper`; + * cancellation is file/token based like the rest of Vipeye, so long-running queries can * still be interrupted mid-request. * * Feature notes: - * - Telemetry and profiling are intentionally omitted (Pyright has no telemetry). + * - Telemetry and profiling are intentionally omitted (Vipeye has no telemetry). * - Notebook support and the virtual-file-redirect supplemental are layered in by later * phases; the seams (`_notebookManager`, overlay file system) are left in place. */ @@ -60,7 +60,7 @@ import { ParseNode } from '../parser/parseNodes'; import { WellKnownWorkspaceKinds, Workspace } from '../workspaceFactory'; import { ServerCanceledException } from './cancellation'; -import { convertFromPyrightDiagnostic } from './diagnosticUtils'; +import { convertFromViperDiagnostic } from './diagnosticUtils'; import { AnyNotebookDocumentSelector } from './notebookCellChain'; import { NotebookDocumentHandler } from './notebookDocumentHandler'; import { INotebookUriMapper, NotebookUriMapper } from './notebookUriMapper'; @@ -274,7 +274,7 @@ export class TypeServer extends LanguageServerBase { }) .catch(() => {}); } else { - void this.connection.sendNotification('pyright/beginProgress'); + void this.connection.sendNotification('viper/beginProgress'); } }, report: (message: string) => { @@ -285,7 +285,7 @@ export class TypeServer extends LanguageServerBase { }) .catch(() => {}); } else { - void this.connection.sendNotification('pyright/reportProgress', message); + void this.connection.sendNotification('viper/reportProgress', message); } }, end: () => { @@ -298,7 +298,7 @@ export class TypeServer extends LanguageServerBase { .catch(() => {}); workDoneProgress = undefined; } else { - void this.connection.sendNotification('pyright/endProgress'); + void this.connection.sendNotification('viper/endProgress'); } }, }; @@ -339,7 +339,7 @@ export class TypeServer extends LanguageServerBase { this._onGetPythonSearchPaths.bind(this) ); - // Register virtual file redirect notifications (Pyright-specific TSP supplemental). + // Register virtual file redirect notifications (Vipeye-specific TSP supplemental). // These are sent by a client (e.g. Pylance's Django stub generator) when it produces // merged virtual files on disk that the type server should analyze in place of the real // ones. @@ -405,7 +405,7 @@ export class TypeServer extends LanguageServerBase { protected override onInitialized() { super.onInitialized(); - // The base Pyright server skips updateSettingsForAllWorkspaces() when the client + // The base Vipeye server skips updateSettingsForAllWorkspaces() when the client // advertises workspace-folders support (it expects a didChangeWorkspaceFolders event // instead). A TSP client may advertise workspaceFolders: true but never send that // event, so trigger the settings update here when workspaces already exist. Without @@ -492,7 +492,7 @@ export class TypeServer extends LanguageServerBase { // these diagnostics directly and the original client does support them. const lspDiagnostics = serverDiagnostics .map((d) => - convertFromPyrightDiagnostic( + convertFromViperDiagnostic( d, workspace.service.fs, /* supportsUnnecessaryDiagnosticTag */ true, @@ -680,8 +680,8 @@ export class TypeServer extends LanguageServerBase { const virtualUri = this.convertLspUriStringToUri(params.virtualUri); fs.virtualOverlay.addFileRedirect(realUri, virtualUri); - // If the file is currently open, read the virtual content and update Pyright's in-memory - // buffer. For closed files, the FS overlay redirect is sufficient — Pyright reads from + // If the file is currently open, read the virtual content and update Vipeye's in-memory + // buffer. For closed files, the FS overlay redirect is sufficient — Vipeye reads from // the FS. let virtualContent: string | undefined; if (this.openFileMap.has(realUri.key)) { diff --git a/packages/vipeye-internal/src/typeServer/stubGenerator.ts b/packages/vipeye-internal/src/typeServer/stubGenerator.ts index 8c5c52ae..eacfa37d 100644 --- a/packages/vipeye-internal/src/typeServer/stubGenerator.ts +++ b/packages/vipeye-internal/src/typeServer/stubGenerator.ts @@ -4,11 +4,11 @@ * * stubGenerator.ts * - * Generates Viper stub (.vpi) file content from Pyright function type information. + * Generates Viper stub (.vpi) file content from Vipeye function type information. */ import { printType, PrintTypeFlags } from '../analyzer/typePrinter'; -import * as PyrightTypes from '../analyzer/types'; +import * as ViperTypes from '../analyzer/types'; import { PythonVersion, pythonVersion3_10, pythonVersion3_11 } from '../common/pythonVersion'; import { ParamCategory } from '../parser/parseNodes'; @@ -30,7 +30,7 @@ interface StubGenerationContext { imports: ImportCollection; pythonVersion: PythonVersion; moduleImports: Map>; // module -> set of imported names - methodClass?: PyrightTypes.ClassType; // Class type if generating stub for a method + methodClass?: ViperTypes.ClassType; // Class type if generating stub for a method targetMethodName?: string; // If provided, adds marker to this specific method instead of the class selfTypeVarName?: string; // If set, replace 'Self' with this TypeVar name } @@ -51,7 +51,7 @@ export interface StubGenerationResult { } export function generateStubFromTypeVar( - typeVar: PyrightTypes.TypeVarType, + typeVar: ViperTypes.TypeVarType, options: StubGenerationOptions ): StubGenerationResult { const context: StubGenerationContext = { @@ -63,10 +63,10 @@ export function generateStubFromTypeVar( const typeVarName = typeVar.shared.name || 'T'; let initializer = ''; - if (PyrightTypes.isParamSpec(typeVar)) { + if (ViperTypes.isParamSpec(typeVar)) { addImport(context, getTypingModule(context.pythonVersion, 'ParamSpec'), 'ParamSpec'); initializer = `ParamSpec('${typeVarName}')`; - } else if (PyrightTypes.isTypeVarTuple(typeVar)) { + } else if (ViperTypes.isTypeVarTuple(typeVar)) { addImport(context, getTypingModule(context.pythonVersion, 'TypeVarTuple'), 'TypeVarTuple'); initializer = `TypeVarTuple('${typeVarName}')`; } else { @@ -76,18 +76,18 @@ export function generateStubFromTypeVar( if (typeVar.shared.constraints?.length) { const constraintStrings = typeVar.shared.constraints.map((constraint) => - pyrightTypeToString(constraint, context) + viperTypeToString(constraint, context) ); args.push(...constraintStrings); } if (typeVar.shared.boundType) { - const boundString = pyrightTypeToString(typeVar.shared.boundType, context); + const boundString = viperTypeToString(typeVar.shared.boundType, context); args.push(`bound=${boundString}`); } if (typeVar.shared.defaultType && typeVar.shared.isDefaultExplicit) { - const defaultString = pyrightTypeToString(typeVar.shared.defaultType, context); + const defaultString = viperTypeToString(typeVar.shared.defaultType, context); args.push(`default=${defaultString}`); } @@ -97,7 +97,7 @@ export function generateStubFromTypeVar( const declarationLine = `${typeVarName} = ${initializer}`; const importLines = generateImportStatements(context); - const lines: string[] = ['# This stub file was generated from Pyright type information', '']; + const lines: string[] = ['# This stub file was generated from Vipeye type information', '']; if (importLines.length > 0) { lines.push(...importLines); lines.push(''); @@ -115,21 +115,21 @@ export function generateStubFromTypeVar( } /** - * Generates a Python stub file (.vpi) from a Pyright FunctionType. + * Generates a Python stub file (.vpi) from a Vipeye FunctionType. * - * @param type The Pyright function type + * @param type The Vipeye function type * @param options Generation options including Python version * @returns Stub generation result with content and metadata */ export function generateStubFromFunctionType( evaluator: ITypeServerEvaluator, - type: PyrightTypes.FunctionType, + type: ViperTypes.FunctionType, options: StubGenerationOptions ): StubGenerationResult { // Check if this function is a method (has a methodClass) // If so, generate the entire class stub with marker on this specific method const methodClass = type.shared.methodClass; - if (methodClass && PyrightTypes.isClass(methodClass)) { + if (methodClass && ViperTypes.isClass(methodClass)) { // Generate class stub with marker on the specific method return generateStubFromClassType(evaluator, methodClass, options, type.shared.name); } @@ -144,12 +144,12 @@ export function generateStubFromFunctionType( const lines: string[] = []; // Generate header comment - lines.push('# This stub file was generated from Pyright type information'); + lines.push('# This stub file was generated from Vipeye type information'); lines.push(''); // Collect TypeVars/ParamSpecs used in the function signature // Use typeParams if available, otherwise collect from signature - let typeVarsToGenerate: PyrightTypes.TypeVarType[] = []; + let typeVarsToGenerate: ViperTypes.TypeVarType[] = []; if (type.shared.typeParams && type.shared.typeParams.length > 0) { typeVarsToGenerate = type.shared.typeParams; } else { @@ -159,16 +159,16 @@ export function generateStubFromFunctionType( // Check if we have a Self TypeVar - if so, we need to replace it with a regular TypeVar // since there's no class context for a standalone function - const selfTypeVar = typeVarsToGenerate.find((tv) => PyrightTypes.TypeVarType.isSelf(tv)); + const selfTypeVar = typeVarsToGenerate.find((tv) => ViperTypes.TypeVarType.isSelf(tv)); if (selfTypeVar) { // Filter out Self and track that we need to replace it - typeVarsToGenerate = typeVarsToGenerate.filter((tv) => !PyrightTypes.TypeVarType.isSelf(tv)); + typeVarsToGenerate = typeVarsToGenerate.filter((tv) => !ViperTypes.TypeVarType.isSelf(tv)); context.selfTypeVarName = '__type_of_self__'; // Create a TypeVar declaration for __type_of_self__ with the bound to the class (if any) const bound = selfTypeVar.shared.boundType; addImport(context, 'typing', 'TypeVar'); - if (bound && PyrightTypes.isClass(bound)) { + if (bound && ViperTypes.isClass(bound)) { // Make sure this class is imported addImport(context, bound.shared.moduleName || '', bound.shared.name); lines.push(`__type_of_self__ = TypeVar('__type_of_self__', bound='${bound.shared.name}')`); @@ -217,16 +217,16 @@ export function generateStubFromFunctionType( } /** - * Generates a function stub signature from a Pyright function type. + * Generates a function stub signature from a Vipeye function type. * - * @param type The Pyright function type + * @param type The Vipeye function type * @param context Generation context * @param docString Optional docstring to include * @param deprecatedMessage Optional deprecation message * @returns Function stub string (e.g., "def foo(x: int, y: str) -> bool: ...") */ function generateFunctionStub( - type: PyrightTypes.FunctionType, + type: ViperTypes.FunctionType, context: StubGenerationContext, docString?: string, deprecatedMessage?: string @@ -275,8 +275,8 @@ function generateFunctionStub( if (param._type) { paramParts.push(': '); const isSynthesizedSelfParam = - param._type && PyrightTypes.isTypeVar(param._type) && param._type.shared.isSynthesizedSelf; - let paramTypeString = pyrightTypeToString(param._type, isSynthesizedSelfParam ? undefined : context); + param._type && ViperTypes.isTypeVar(param._type) && param._type.shared.isSynthesizedSelf; + let paramTypeString = viperTypeToString(param._type, isSynthesizedSelfParam ? undefined : context); // Replace 'Self' with our TypeVar if we're in a standalone function context if (context.selfTypeVarName && paramTypeString === 'Self' && isSynthesizedSelfParam) { paramTypeString = context.selfTypeVarName; @@ -285,7 +285,7 @@ function generateFunctionStub( } // Default value (if present, just show "...") - const defaultType = PyrightTypes.FunctionType.getParamDefaultType(type, i); + const defaultType = ViperTypes.FunctionType.getParamDefaultType(type, i); if (defaultType || param.defaultExpr) { paramParts.push(' = ...'); } @@ -324,9 +324,9 @@ function generateFunctionStub( /** * Gets the return type string for a function. */ -function getReturnTypeStringFromFunction(type: PyrightTypes.FunctionType, context: StubGenerationContext): string { - const returnType = PyrightTypes.FunctionType.getEffectiveReturnType(type, true); - let returnTypeString = returnType ? pyrightTypeToString(returnType, context) : 'None'; +function getReturnTypeStringFromFunction(type: ViperTypes.FunctionType, context: StubGenerationContext): string { + const returnType = ViperTypes.FunctionType.getEffectiveReturnType(type, true); + let returnTypeString = returnType ? viperTypeToString(returnType, context) : 'None'; // Replace 'Self' with our TypeVar if we're in a standalone function context if (context.selfTypeVarName && returnTypeString === 'Self') { returnTypeString = context.selfTypeVarName; @@ -335,16 +335,16 @@ function getReturnTypeStringFromFunction(type: PyrightTypes.FunctionType, contex } /** - * Converts a Pyright type to a Python type string using printType. + * Converts a Vipeye type to a Python type string using printType. */ -function pyrightTypeToString(type: PyrightTypes.Type, context?: StubGenerationContext): string { +function viperTypeToString(type: ViperTypes.Type, context?: StubGenerationContext): string { const flags = PrintTypeFlags.PythonSyntax | PrintTypeFlags.UseFullyQualifiedNames; // Simple callback for getting return types - just use declared or inferred return type - const returnTypeCallback = (funcType: PyrightTypes.FunctionType): PyrightTypes.Type => { + const returnTypeCallback = (funcType: ViperTypes.FunctionType): ViperTypes.Type => { return ( funcType.shared.declaredReturnType ?? funcType.shared.inferredReturnType?.type ?? - PyrightTypes.UnknownType.create() + ViperTypes.UnknownType.create() ); }; const typeString = printType(type, flags, returnTypeCallback); @@ -366,7 +366,7 @@ function pyrightTypeToString(type: PyrightTypes.Type, context?: StubGenerationCo */ function extractModuleImportsFromTypeString( typeString: string, - type: PyrightTypes.Type, + type: ViperTypes.Type, context: StubGenerationContext ): void { // Match module-qualified names like "test.Box" or "foo.bar.Baz" @@ -500,16 +500,16 @@ function generateImportStatements(context: StubGenerationContext): string[] { } /** - * Generates a Python stub file (.pyi) from a Pyright ClassType. + * Generates a Python stub file (.pyi) from a Vipeye ClassType. * - * @param type The Pyright class type + * @param type The Vipeye class type * @param options Generation options including Python version * @param targetMethodName If provided, marks this specific method as the primary definition * @returns Stub generation result with content and metadata */ export function generateStubFromClassType( evaluator: ITypeServerEvaluator, - type: PyrightTypes.ClassType, + type: ViperTypes.ClassType, options: StubGenerationOptions, targetMethodName?: string ): StubGenerationResult { @@ -523,11 +523,11 @@ export function generateStubFromClassType( const lines: string[] = []; // Generate header comment - lines.push('# This stub file was generated from Pyright type information'); + lines.push('# This stub file was generated from Vipeye type information'); lines.push(''); // Special handling for NewType classes - generate as NewType call instead of class definition - if (PyrightTypes.ClassType.isNewTypeClass(type)) { + if (ViperTypes.ClassType.isNewTypeClass(type)) { return generateNewTypeStub(type, context, options); } @@ -579,7 +579,7 @@ export function generateStubFromClassType( * Generates a stub for a NewType class using NewType call syntax. */ function generateNewTypeStub( - type: PyrightTypes.ClassType, + type: ViperTypes.ClassType, context: StubGenerationContext, options: StubGenerationOptions ): StubGenerationResult { @@ -590,7 +590,7 @@ function generateNewTypeStub( // Get the base type (first base class, excluding object) const baseType = type.shared.baseClasses[0]; - let baseTypeStr = baseType ? pyrightTypeToString(baseType, context) : 'object'; + let baseTypeStr = baseType ? viperTypeToString(baseType, context) : 'object'; // Remove type[] wrapper if present (NewType base should be the instance type, not type[]) const typeWrapperMatch = baseTypeStr.match(/^type\[(.+)\]$/); @@ -604,7 +604,7 @@ function generateNewTypeStub( // Generate imports const importLines = generateImportStatements(context); const result: string[] = []; - result.push('# This stub file was generated from Pyright type information'); + result.push('# This stub file was generated from Vipeye type information'); result.push(''); if (importLines.length > 0) { result.push(...importLines); @@ -627,14 +627,14 @@ function generateNewTypeStub( } /** - * Generates a class stub from a Pyright class type. + * Generates a class stub from a Vipeye class type. * @param type - The class type to generate a stub for * @param context - The stub generation context * @param isTopLevel - Whether this is the main class (vs a synthesized base class) */ function generateClassStub( evaluator: ITypeServerEvaluator, - type: PyrightTypes.ClassType, + type: ViperTypes.ClassType, context: StubGenerationContext, isTopLevel: boolean = false ): string { @@ -664,10 +664,10 @@ function generateClassStub( // Add type parameters for generic classes if (type.shared.typeParams && type.shared.typeParams.length > 0) { const typeParamNames = type.shared.typeParams.map((tp) => { - if (PyrightTypes.isTypeVar(tp)) { + if (ViperTypes.isTypeVar(tp)) { return tp.shared.name; } - return pyrightTypeToString(tp, context); + return viperTypeToString(tp, context); }); parts.push('['); parts.push(typeParamNames.join(', ')); @@ -681,12 +681,12 @@ function generateClassStub( const baseClassStubs: string[] = []; if (type.shared.baseClasses && type.shared.baseClasses.length > 0) { for (const bc of type.shared.baseClasses) { - if (PyrightTypes.isClass(bc) && !bc.shared.declaration && bc.shared.name !== 'object') { + if (ViperTypes.isClass(bc) && !bc.shared.declaration && bc.shared.name !== 'object') { // Track this as a synthesized base class synthesizedBaseClasses.add(bc.shared.name); // Generate stub for synthesized base class const baseStub = generateClassStub(evaluator, bc, context); - let bcStr = pyrightTypeToString(bc, context); + let bcStr = viperTypeToString(bc, context); // Remove type[] wrapper if present const typeWrapperMatch = bcStr.match(/^type\[(.+)\]$/); if (typeWrapperMatch) { @@ -703,14 +703,14 @@ function generateClassStub( if (type.shared.baseClasses && type.shared.baseClasses.length > 0) { const baseClassStrs = type.shared.baseClasses .map((bc) => { - let bcStr = pyrightTypeToString(bc, context); + let bcStr = viperTypeToString(bc, context); // Remove type[] wrapper if present const typeWrapperMatch = bcStr.match(/^type\[(.+)\]$/); if (typeWrapperMatch) { bcStr = typeWrapperMatch[1]; } // If this base class had its stub generated inline, use just the simple name - if (PyrightTypes.isClass(bc) && synthesizedBaseClasses.has(bc.shared.name)) { + if (ViperTypes.isClass(bc) && synthesizedBaseClasses.has(bc.shared.name)) { return bc.shared.name; } return bcStr; @@ -762,13 +762,13 @@ function generateClassStub( */ function generateClassBody( evaluator: ITypeServerEvaluator, - type: PyrightTypes.ClassType, + type: ViperTypes.ClassType, context: StubGenerationContext ): string[] { const lines: string[] = []; // Get all fields from the symbol table, excluding private members - const fields: Array<{ name: string; type: PyrightTypes.Type; isMethod: boolean; isClassVar: boolean }> = []; + const fields: Array<{ name: string; type: ViperTypes.Type; isMethod: boolean; isClassVar: boolean }> = []; for (const [name, symbol] of type.shared.fields) { // Skip private fields (starting with single _), but keep dunder methods @@ -777,7 +777,7 @@ function generateClassBody( } // Try to get the type from synthesized type, or from declarations - let fieldType: PyrightTypes.Type | undefined; + let fieldType: ViperTypes.Type | undefined; const synthesizedType = symbol.getSynthesizedType(); if (synthesizedType) { fieldType = synthesizedType.type; @@ -790,7 +790,7 @@ function generateClassBody( continue; } - const isMethod = PyrightTypes.isFunction(fieldType) || PyrightTypes.isOverloaded(fieldType); + const isMethod = ViperTypes.isFunction(fieldType) || ViperTypes.isOverloaded(fieldType); const isClassVar = symbol.isClassVar(); // Skip fields that are private but not dunder methods @@ -814,7 +814,7 @@ function generateClassBody( for (const field of fields) { if (field.isMethod) { // Generate method stub - if (PyrightTypes.isFunction(field.type)) { + if (ViperTypes.isFunction(field.type)) { const methodContext = { ...context, methodClass: type }; const methodStub = generateFunctionStub( field.type, @@ -828,9 +828,9 @@ function generateClassBody( .map((line) => ` ${line}`) .join('\n'); lines.push(indentedStub); - } else if (PyrightTypes.isOverloaded(field.type)) { + } else if (ViperTypes.isOverloaded(field.type)) { // Handle overloaded methods - just use first overload for stub - const overloads = PyrightTypes.OverloadedType.getOverloads(field.type); + const overloads = ViperTypes.OverloadedType.getOverloads(field.type); if (overloads.length > 0) { const methodContext = { ...context, methodClass: type }; const methodStub = generateFunctionStub( @@ -846,7 +846,7 @@ function generateClassBody( lines.push(indentedStub); } } - } else if (PyrightTypes.isClass(field.type) && !field.type.shared.declaration) { + } else if (ViperTypes.isClass(field.type) && !field.type.shared.declaration) { // Nested synthesized class - generate its stub recursively const nestedStub = generateClassStub(evaluator, field.type, context); const indentedStub = nestedStub @@ -856,7 +856,7 @@ function generateClassBody( lines.push(indentedStub); } else { // Regular field with type annotation - const typeStr = pyrightTypeToString(field.type, context); + const typeStr = viperTypeToString(field.type, context); lines.push(` ${field.name}: ${typeStr}`); } } @@ -867,7 +867,7 @@ function generateClassBody( /** * Generates a TypedDict stub using special syntax. */ -function generateTypedDictStub(type: PyrightTypes.ClassType, context: StubGenerationContext): string { +function generateTypedDictStub(type: ViperTypes.ClassType, context: StubGenerationContext): string { const lines: string[] = []; // TypedDict class definition @@ -891,7 +891,7 @@ function generateTypedDictStub(type: PyrightTypes.ClassType, context: StubGenera // Generate fields if (entries && entries.knownItems.size > 0) { for (const [name, entry] of entries.knownItems) { - const typeStr = pyrightTypeToString(entry.valueType, context); + const typeStr = viperTypeToString(entry.valueType, context); lines.push(` ${name}: ${typeStr}`); } } else { @@ -909,7 +909,7 @@ function generateTypedDictStub(type: PyrightTypes.ClassType, context: StubGenera */ function generateNamedTupleStub( evaluator: ITypeServerEvaluator, - type: PyrightTypes.ClassType, + type: ViperTypes.ClassType, context: StubGenerationContext ): string { const lines: string[] = []; @@ -929,12 +929,12 @@ function generateNamedTupleStub( if (entries.has(name)) { const synthesizedType = symbol.getSynthesizedType(); if (synthesizedType) { - const typeStr = pyrightTypeToString(synthesizedType.type, context); + const typeStr = viperTypeToString(synthesizedType.type, context); lines.push(` ${name}: ${typeStr}`); } else { const type = evaluator.getEffectiveTypeOfSymbol(symbol); if (type) { - const typeStr = pyrightTypeToString(type, context); + const typeStr = viperTypeToString(type, context); lines.push(` ${name}: ${typeStr}`); } else { lines.push(` ${name}: Any`); @@ -959,22 +959,22 @@ function generateNamedTupleStub( * Collects all TypeVars/ParamSpecs used in a function signature by walking through * parameter types and return type. */ -function collectTypeVarsFromFunctionSignature(type: PyrightTypes.FunctionType): PyrightTypes.TypeVarType[] { - const typeVars = new Map(); +function collectTypeVarsFromFunctionSignature(type: ViperTypes.FunctionType): ViperTypes.TypeVarType[] { + const typeVars = new Map(); // Helper to recursively collect TypeVars from a type - const collectFromType = (t: PyrightTypes.Type) => { - if (PyrightTypes.isTypeVar(t)) { + const collectFromType = (t: ViperTypes.Type) => { + if (ViperTypes.isTypeVar(t)) { typeVars.set(t.shared.name, t); - } else if (PyrightTypes.isClass(t) && t.priv.typeArgs) { + } else if (ViperTypes.isClass(t) && t.priv.typeArgs) { // Check type arguments (e.g., List[T]) for (const arg of t.priv.typeArgs) { collectFromType(arg); } - } else if (PyrightTypes.isUnion(t)) { + } else if (ViperTypes.isUnion(t)) { // Check union members t.priv.subtypes.forEach((subtype) => collectFromType(subtype)); - } else if (PyrightTypes.isFunction(t)) { + } else if (ViperTypes.isFunction(t)) { // Check function parameters and return type for (let i = 0; i < t.shared.parameters.length; i++) { const param = t.shared.parameters[i]; @@ -982,7 +982,7 @@ function collectTypeVarsFromFunctionSignature(type: PyrightTypes.FunctionType): collectFromType(param._type); } } - const returnType = PyrightTypes.FunctionType.getEffectiveReturnType(t, true); + const returnType = ViperTypes.FunctionType.getEffectiveReturnType(t, true); if (returnType) { collectFromType(returnType); } @@ -998,7 +998,7 @@ function collectTypeVarsFromFunctionSignature(type: PyrightTypes.FunctionType): } // Collect from return type - const returnType = PyrightTypes.FunctionType.getEffectiveReturnType(type, true); + const returnType = ViperTypes.FunctionType.getEffectiveReturnType(type, true); if (returnType) { collectFromType(returnType); } @@ -1009,20 +1009,20 @@ function collectTypeVarsFromFunctionSignature(type: PyrightTypes.FunctionType): /** * Generates TypeVar/ParamSpec/TypeVarTuple declarations for a list of type parameters. */ -function generateTypeVarDeclarations(typeParams: PyrightTypes.TypeVarType[], context: StubGenerationContext): string[] { +function generateTypeVarDeclarations(typeParams: ViperTypes.TypeVarType[], context: StubGenerationContext): string[] { const lines: string[] = []; for (const typeParam of typeParams) { - if (PyrightTypes.isTypeVar(typeParam)) { + if (ViperTypes.isTypeVar(typeParam)) { const name = typeParam.shared.name; // Check if it's a ParamSpec - if (PyrightTypes.isParamSpec(typeParam)) { + if (ViperTypes.isParamSpec(typeParam)) { addImport(context, getTypingModule(context.pythonVersion, 'ParamSpec'), 'ParamSpec'); lines.push(`${name} = ParamSpec('${name}')`); } // Check if it's a TypeVarTuple - else if (PyrightTypes.isTypeVarTuple(typeParam)) { + else if (ViperTypes.isTypeVarTuple(typeParam)) { addImport(context, getTypingModule(context.pythonVersion, 'TypeVarTuple'), 'TypeVarTuple'); lines.push(`${name} = TypeVarTuple('${name}')`); } @@ -1033,13 +1033,13 @@ function generateTypeVarDeclarations(typeParams: PyrightTypes.TypeVarType[], con // Add bound if present if (typeParam.shared.boundType) { - const boundStr = pyrightTypeToString(typeParam.shared.boundType, context); + const boundStr = viperTypeToString(typeParam.shared.boundType, context); parts.push(`, bound=${boundStr}`); } // Add constraints if present if (typeParam.shared.constraints && typeParam.shared.constraints.length > 0) { - const constraintStrs = typeParam.shared.constraints.map((c) => pyrightTypeToString(c, context)); + const constraintStrs = typeParam.shared.constraints.map((c) => viperTypeToString(c, context)); parts.push(`, ${constraintStrs.join(', ')}`); } diff --git a/packages/vipeye-internal/src/typeServer/typeServerConversionTypes.ts b/packages/vipeye-internal/src/typeServer/typeServerConversionTypes.ts index ef864b98..afb382c4 100644 --- a/packages/vipeye-internal/src/typeServer/typeServerConversionTypes.ts +++ b/packages/vipeye-internal/src/typeServer/typeServerConversionTypes.ts @@ -1,9 +1,9 @@ import { TypeServerProtocol } from './protocol/typeServerProtocol'; -import * as PyrightDecl from '../analyzer/declaration'; +import * as ViperDecl from '../analyzer/declaration'; import { synthesizeAliasDeclaration } from '../analyzer/declarationUtils'; import { ParseTreeWalker } from '../analyzer/parseTreeWalker'; -import * as PyrightTypes from '../analyzer/types'; +import * as ViperTypes from '../analyzer/types'; import { isCallableType, isLiteralType } from '../analyzer/typeUtils'; import { CaseSensitivityDetector } from '../common/caseSensitivityDetector'; import * as debug from '../common/debug'; @@ -12,7 +12,7 @@ import { convertOffsetsToRange, convertPositionToOffset } from '../common/positi import { TextRange } from '../common/textRange'; import { Uri } from '../common/uri/uri'; import { convertUriToLspUriString } from '../common/uri/uriUtils'; -import * as PyrightNodes from '../parser/parseNodes'; +import * as ViperNodes from '../parser/parseNodes'; import { ParserOutput } from '../parser/parser'; import { convertLspUriStringToUri } from './serverUtils'; @@ -21,7 +21,7 @@ import { ISymbolLookup, ParseResults } from './programTypes'; import { INotebookUriMapper } from './notebookUriMapper'; export interface IParserOutputProvider extends CaseSensitivityDetector { - getUri(node: PyrightNodes.ParseNode): Uri; + getUri(node: ViperNodes.ParseNode): Uri; getParserOutput(uri: Uri): ParserOutput | undefined; readonly fs: FileSystem; readonly uriMapper?: INotebookUriMapper; @@ -30,7 +30,7 @@ export interface IParserOutputProvider extends CaseSensitivityDetector { addStubCode(code: string, directoryUri?: Uri): { uri: Uri; parseResults: ParseResults }; } -export function toProtocolNode(node: PyrightNodes.ParseNode, provider: IParserOutputProvider): TypeServerProtocol.Node { +export function toProtocolNode(node: ViperNodes.ParseNode, provider: IParserOutputProvider): TypeServerProtocol.Node { const uri = provider.getUri(node); const results = provider.getParserOutput(uri); if (!results) { @@ -46,10 +46,10 @@ export function toProtocolNode(node: PyrightNodes.ParseNode, provider: IParserOu }; } -export function fromProtocolNode>( +export function fromProtocolNode>( node: TypeServerProtocol.Node, resultsProvider: IParserOutputProvider, - typeHints?: PyrightNodes.ParseNodeType[] + typeHints?: ViperNodes.ParseNodeType[] ): T { const uri = convertLspUriStringToUri(node.uri, resultsProvider, resultsProvider.uriMapper); const mappedUri = resultsProvider.fs.getMappedUri(uri); @@ -64,35 +64,35 @@ export function fromProtocolNode t === newType); } switch (oldType) { - case PyrightNodes.ParseNodeType.Name: - return newType !== PyrightNodes.ParseNodeType.Name; - case PyrightNodes.ParseNodeType.StringList: - return newType !== PyrightNodes.ParseNodeType.String; - case PyrightNodes.ParseNodeType.String: - return newType === PyrightNodes.ParseNodeType.StringList; - case PyrightNodes.ParseNodeType.Number: - return newType === PyrightNodes.ParseNodeType.Slice; - case PyrightNodes.ParseNodeType.Slice: - return newType !== PyrightNodes.ParseNodeType.Number; - case PyrightNodes.ParseNodeType.ModuleName: + case ViperNodes.ParseNodeType.Name: + return newType !== ViperNodes.ParseNodeType.Name; + case ViperNodes.ParseNodeType.StringList: + return newType !== ViperNodes.ParseNodeType.String; + case ViperNodes.ParseNodeType.String: + return newType === ViperNodes.ParseNodeType.StringList; + case ViperNodes.ParseNodeType.Number: + return newType === ViperNodes.ParseNodeType.Slice; + case ViperNodes.ParseNodeType.Slice: + return newType !== ViperNodes.ParseNodeType.Number; + case ViperNodes.ParseNodeType.ModuleName: return ( - newType === PyrightNodes.ParseNodeType.Import || - newType === PyrightNodes.ParseNodeType.ImportFrom || - newType === PyrightNodes.ParseNodeType.ImportAs || - newType === PyrightNodes.ParseNodeType.ImportFromAs + newType === ViperNodes.ParseNodeType.Import || + newType === ViperNodes.ParseNodeType.ImportFrom || + newType === ViperNodes.ParseNodeType.ImportAs || + newType === ViperNodes.ParseNodeType.ImportFromAs ); - case PyrightNodes.ParseNodeType.Import: - case PyrightNodes.ParseNodeType.ImportFrom: - case PyrightNodes.ParseNodeType.ImportAs: - case PyrightNodes.ParseNodeType.ImportFromAs: - return newType !== PyrightNodes.ParseNodeType.ModuleName; - case PyrightNodes.ParseNodeType.Error: - return newType !== PyrightNodes.ParseNodeType.Error; + case ViperNodes.ParseNodeType.Import: + case ViperNodes.ParseNodeType.ImportFrom: + case ViperNodes.ParseNodeType.ImportAs: + case ViperNodes.ParseNodeType.ImportFromAs: + return newType !== ViperNodes.ParseNodeType.ModuleName; + case ViperNodes.ParseNodeType.Error: + return newType !== ViperNodes.ParseNodeType.Error; default: return true; } @@ -101,19 +101,19 @@ export function fromProtocolNode= this._length && @@ -126,14 +126,14 @@ export function fromProtocolNode(decl.node, resultsProvider, hints); + node = fromProtocolNode(decl.node, resultsProvider, hints); } catch (error) { // Try to get the module root node as a fallback for symbol lookup. if (decl.node?.uri) { @@ -281,39 +281,39 @@ export function fromProtocolDecl( } // Helper to check if a declaration matches the expected category type. - const matchesDeclCategory = (d: PyrightDecl.Declaration): boolean => { + const matchesDeclCategory = (d: ViperDecl.Declaration): boolean => { switch (decl.category) { case TypeServerProtocol.DeclarationCategory.Import: - return PyrightDecl.isAliasDeclaration(d); + return ViperDecl.isAliasDeclaration(d); case TypeServerProtocol.DeclarationCategory.Intrinsic: - return PyrightDecl.isIntrinsicDeclaration(d); + return ViperDecl.isIntrinsicDeclaration(d); case TypeServerProtocol.DeclarationCategory.Variable: - return PyrightDecl.isVariableDeclaration(d); + return ViperDecl.isVariableDeclaration(d); case TypeServerProtocol.DeclarationCategory.Param: - return PyrightDecl.isParamDeclaration(d); + return ViperDecl.isParamDeclaration(d); case TypeServerProtocol.DeclarationCategory.TypeParam: - return PyrightDecl.isTypeParamDeclaration(d); + return ViperDecl.isTypeParamDeclaration(d); case TypeServerProtocol.DeclarationCategory.TypeAlias: - return PyrightDecl.isTypeAliasDeclaration(d); + return ViperDecl.isTypeAliasDeclaration(d); case TypeServerProtocol.DeclarationCategory.Function: - return PyrightDecl.isFunctionDeclaration(d); + return ViperDecl.isFunctionDeclaration(d); case TypeServerProtocol.DeclarationCategory.Class: - return PyrightDecl.isClassDeclaration(d) || PyrightDecl.isSpecialBuiltInClassDeclaration(d); + return ViperDecl.isClassDeclaration(d) || ViperDecl.isSpecialBuiltInClassDeclaration(d); default: return false; } }; // Helper to check if a declaration's node matches the protocol node identity. - const matchesNodeIdentity = (d: PyrightDecl.Declaration): boolean => { + const matchesNodeIdentity = (d: ViperDecl.Declaration): boolean => { if (d.node === node) { return true; } // For Function/Class declarations, also check if the name node matches. - if (PyrightDecl.isFunctionDeclaration(d) && d.node.d.name === node) { + if (ViperDecl.isFunctionDeclaration(d) && d.node.d.name === node) { return true; } - if (PyrightDecl.isClassDeclaration(d) && d.node.d.name === node) { + if (ViperDecl.isClassDeclaration(d) && d.node.d.name === node) { return true; } return false; @@ -334,10 +334,10 @@ export function fromProtocolDecl( return allDecls.find((d) => matchesDeclCategory(d)); } -export function getSymbolNameFromDeclaration(declaration: PyrightDecl.Declaration): string | undefined { +export function getSymbolNameFromDeclaration(declaration: ViperDecl.Declaration): string | undefined { switch (declaration.type) { - case PyrightDecl.DeclarationType.Alias: { - if (declaration.node.nodeType === PyrightNodes.ParseNodeType.ImportFrom) { + case ViperDecl.DeclarationType.Alias: { + if (declaration.node.nodeType === ViperNodes.ParseNodeType.ImportFrom) { if (declaration.node.d.isWildcardImport) { return declaration.symbolName; } @@ -345,12 +345,12 @@ export function getSymbolNameFromDeclaration(declaration: PyrightDecl.Declaratio return declaration.node.d.module.d.nameParts[0].d.value; } - if (declaration.node.nodeType === PyrightNodes.ParseNodeType.ImportFromAs) { + if (declaration.node.nodeType === ViperNodes.ParseNodeType.ImportFromAs) { const nameNode = declaration.node.d.alias || declaration.node.d.name; return nameNode.d.value; } - if (declaration.node.nodeType === PyrightNodes.ParseNodeType.ImportAs) { + if (declaration.node.nodeType === ViperNodes.ParseNodeType.ImportAs) { return declaration.node.d.alias ? declaration.node.d.alias.d.value : declaration.node.d.module.d.nameParts[0].d.value; @@ -358,27 +358,27 @@ export function getSymbolNameFromDeclaration(declaration: PyrightDecl.Declaratio return undefined; } - case PyrightDecl.DeclarationType.Class: - case PyrightDecl.DeclarationType.Function: - case PyrightDecl.DeclarationType.TypeParam: - case PyrightDecl.DeclarationType.TypeAlias: + case ViperDecl.DeclarationType.Class: + case ViperDecl.DeclarationType.Function: + case ViperDecl.DeclarationType.TypeParam: + case ViperDecl.DeclarationType.TypeAlias: return declaration.node.d.name.d.value; - case PyrightDecl.DeclarationType.Param: + case ViperDecl.DeclarationType.Param: return declaration.node.d.name?.d.value; - case PyrightDecl.DeclarationType.Variable: { + case ViperDecl.DeclarationType.Variable: { const node = declaration.node; - return node.nodeType === PyrightNodes.ParseNodeType.Name + return node.nodeType === ViperNodes.ParseNodeType.Name ? node.d.value - : node.nodeType === PyrightNodes.ParseNodeType.StringList + : node.nodeType === ViperNodes.ParseNodeType.StringList ? node.d.strings[0].d.value : undefined; } - case PyrightDecl.DeclarationType.Intrinsic: + case ViperDecl.DeclarationType.Intrinsic: return declaration.name; - case PyrightDecl.DeclarationType.SpecialBuiltInClass: - return declaration.node.d.valueExpr.nodeType === PyrightNodes.ParseNodeType.Name + case ViperDecl.DeclarationType.SpecialBuiltInClass: + return declaration.node.d.valueExpr.nodeType === ViperNodes.ParseNodeType.Name ? declaration.node.d.valueExpr.d.value : undefined; default: { @@ -387,7 +387,7 @@ export function getSymbolNameFromDeclaration(declaration: PyrightDecl.Declaratio } } -export function getParseNodeTypesForDecl(decl: TypeServerProtocol.Declaration): PyrightNodes.ParseNodeType[] { +export function getParseNodeTypesForDecl(decl: TypeServerProtocol.Declaration): ViperNodes.ParseNodeType[] { if (decl.kind === TypeServerProtocol.DeclarationKind.Synthesized) { // Synthesized declarations don't have an associated node. return []; @@ -396,85 +396,85 @@ export function getParseNodeTypesForDecl(decl: TypeServerProtocol.Declaration): switch (decl.category) { case TypeServerProtocol.DeclarationCategory.Import: { return [ - PyrightNodes.ParseNodeType.ImportAs, - PyrightNodes.ParseNodeType.ImportFromAs, - PyrightNodes.ParseNodeType.ImportFrom, + ViperNodes.ParseNodeType.ImportAs, + ViperNodes.ParseNodeType.ImportFromAs, + ViperNodes.ParseNodeType.ImportFrom, ]; } case TypeServerProtocol.DeclarationCategory.Intrinsic: { return [ - PyrightNodes.ParseNodeType.Module | - PyrightNodes.ParseNodeType.Function | - PyrightNodes.ParseNodeType.Class, + ViperNodes.ParseNodeType.Module | + ViperNodes.ParseNodeType.Function | + ViperNodes.ParseNodeType.Class, ]; } case TypeServerProtocol.DeclarationCategory.Variable: { - return [PyrightNodes.ParseNodeType.Name, PyrightNodes.ParseNodeType.StringList]; + return [ViperNodes.ParseNodeType.Name, ViperNodes.ParseNodeType.StringList]; } case TypeServerProtocol.DeclarationCategory.Param: { - return [PyrightNodes.ParseNodeType.Parameter]; + return [ViperNodes.ParseNodeType.Parameter]; } case TypeServerProtocol.DeclarationCategory.TypeParam: { - return [PyrightNodes.ParseNodeType.TypeParameter]; + return [ViperNodes.ParseNodeType.TypeParameter]; } case TypeServerProtocol.DeclarationCategory.TypeAlias: { - return [PyrightNodes.ParseNodeType.TypeAlias]; + return [ViperNodes.ParseNodeType.TypeAlias]; } case TypeServerProtocol.DeclarationCategory.Function: { - return [PyrightNodes.ParseNodeType.Function]; + return [ViperNodes.ParseNodeType.Function]; } case TypeServerProtocol.DeclarationCategory.Class: { - return [PyrightNodes.ParseNodeType.Class, PyrightNodes.ParseNodeType.TypeAnnotation]; + return [ViperNodes.ParseNodeType.Class, ViperNodes.ParseNodeType.TypeAnnotation]; } } } -export function toProtocolTypeFlags(type: PyrightTypes.Type): TypeServerProtocol.TypeFlags { +export function toProtocolTypeFlags(type: ViperTypes.Type): TypeServerProtocol.TypeFlags { let flags = TypeServerProtocol.TypeFlags.None; - if (PyrightTypes.isClass(type) && isLiteralType(type)) { + if (ViperTypes.isClass(type) && isLiteralType(type)) { flags |= TypeServerProtocol.TypeFlags.Literal; } - if (PyrightTypes.isClass(type) && type.shared.typeParams.length > 0) { + if (ViperTypes.isClass(type) && type.shared.typeParams.length > 0) { flags |= TypeServerProtocol.TypeFlags.Generic; } - if (PyrightTypes.TypeBase.isInstance(type)) { + if (ViperTypes.TypeBase.isInstance(type)) { flags |= TypeServerProtocol.TypeFlags.Instance; } - if (PyrightTypes.TypeBase.isInstantiable(type)) { + if (ViperTypes.TypeBase.isInstantiable(type)) { flags |= TypeServerProtocol.TypeFlags.Instantiable; } if (isCallableType(type)) { flags |= TypeServerProtocol.TypeFlags.Callable; } - if (PyrightTypes.isClass(type) && PyrightTypes.ClassType.isProtocolClass(type)) { + if (ViperTypes.isClass(type) && ViperTypes.ClassType.isProtocolClass(type)) { flags |= TypeServerProtocol.TypeFlags.Interface; } if (type.props?.typeAliasInfo) { flags |= TypeServerProtocol.TypeFlags.FromAlias; } - if (PyrightTypes.isUnpacked(type)) { + if (ViperTypes.isUnpacked(type)) { flags |= TypeServerProtocol.TypeFlags.Unpacked; } return flags; } export function toProtocolVariance( - variance: PyrightTypes.Variance | undefined + variance: ViperTypes.Variance | undefined ): TypeServerProtocol.Variance | undefined { if (variance === undefined) { return undefined; } switch (variance) { - case PyrightTypes.Variance.Auto: + case ViperTypes.Variance.Auto: return TypeServerProtocol.Variance.Auto; - case PyrightTypes.Variance.Unknown: + case ViperTypes.Variance.Unknown: return TypeServerProtocol.Variance.Unknown; - case PyrightTypes.Variance.Invariant: + case ViperTypes.Variance.Invariant: return TypeServerProtocol.Variance.Invariant; - case PyrightTypes.Variance.Covariant: + case ViperTypes.Variance.Covariant: return TypeServerProtocol.Variance.Covariant; - case PyrightTypes.Variance.Contravariant: + case ViperTypes.Variance.Contravariant: return TypeServerProtocol.Variance.Contravariant; default: debug.assertNever(variance); diff --git a/packages/vipeye-internal/src/typeServer/typeServerConversionUtils.ts b/packages/vipeye-internal/src/typeServer/typeServerConversionUtils.ts index 4e902db1..3967fb17 100644 --- a/packages/vipeye-internal/src/typeServer/typeServerConversionUtils.ts +++ b/packages/vipeye-internal/src/typeServer/typeServerConversionUtils.ts @@ -11,13 +11,13 @@ import { CancellationToken } from 'vscode-languageserver-protocol'; import { Declaration, DeclarationType } from '../analyzer/declaration'; import { getChildNodes, ParseTreeWalker } from '../analyzer/parseTreeWalker'; -import * as PyrightTypes from '../analyzer/types'; +import * as ViperTypes from '../analyzer/types'; import { assert } from '../common/debug'; import { convertTextRangeToRange } from '../common/positionUtils'; import { PythonVersion } from '../common/pythonVersion'; import { Uri } from '../common/uri/uri'; import { convertUriToLspUriString } from '../common/uri/uriUtils'; -import * as PyrightNodes from '../parser/parseNodes'; +import * as ViperNodes from '../parser/parseNodes'; import { ITypeServerEvaluator } from './typeServerEvaluator'; import { isDeclaration, map } from './typeEvalUtils'; @@ -55,14 +55,14 @@ export function toProtocolModuleName(moduleName: string): TypeServerProtocol.Mod export class ProtocolTypeFactory { private _id = 0; - private readonly _cycleMap = new Map(); + private readonly _cycleMap = new Map(); private readonly _sourceUri: Uri; private readonly _evaluator: ITypeServerEvaluator; constructor( readonly view: IProgram, readonly pythonVersion: PythonVersion, - declarationOrNode: Declaration | PyrightNodes.ParseNode + declarationOrNode: Declaration | ViperNodes.ParseNode ) { this._evaluator = view.createEvaluator(); // Extract source URI from declaration or node @@ -81,7 +81,7 @@ export class ProtocolTypeFactory { return this._id++; } - getModule(type: PyrightTypes.FunctionType | PyrightTypes.ClassType): PyrightTypes.ModuleType { + getModule(type: ViperTypes.FunctionType | ViperTypes.ClassType): ViperTypes.ModuleType { const moduleName = type.shared.moduleName; const moduleDescriptor = toProtocolModuleName(moduleName); const moduleUri = @@ -90,10 +90,10 @@ export class ProtocolTypeFactory { assert(moduleNode !== undefined, `Module node not found for URI: ${moduleUri.toString()}`); const scope = this.view.symbolLookup.getScope(moduleNode); const symbolTable = scope?.symbolTable; - return PyrightTypes.ModuleType.create(moduleName, moduleUri, symbolTable); + return ViperTypes.ModuleType.create(moduleName, moduleUri, symbolTable); } - getType(type: PyrightTypes.Type): TypeServerProtocol.Type { + getType(type: ViperTypes.Type): TypeServerProtocol.Type { const newId = this.getNextId(); const existingTypeId = this._cycleMap.get(type); @@ -110,11 +110,11 @@ export class ProtocolTypeFactory { return toProtocolType(newId, type, this); } - private _set(type: PyrightTypes.Type, id: number) { + private _set(type: ViperTypes.Type, id: number) { this._cycleMap.set(type, id); } - private _extractSourceUri(declarationOrNode: Declaration | PyrightNodes.ParseNode): Uri { + private _extractSourceUri(declarationOrNode: Declaration | ViperNodes.ParseNode): Uri { if (isDeclaration(declarationOrNode)) { return declarationOrNode.uri; } else { @@ -124,7 +124,7 @@ export class ProtocolTypeFactory { } function toProtocolTypesOrUndefined( - types: PyrightTypes.Type[] | undefined, + types: ViperTypes.Type[] | undefined, factory: ProtocolTypeFactory ): TypeServerProtocol.Type[] | undefined { if (!types) { @@ -134,12 +134,12 @@ function toProtocolTypesOrUndefined( return toProtocolTypes(types, factory); } -function toProtocolTypes(types: PyrightTypes.Type[], factory: ProtocolTypeFactory): TypeServerProtocol.Type[] { +function toProtocolTypes(types: ViperTypes.Type[], factory: ProtocolTypeFactory): TypeServerProtocol.Type[] { return map(types, (type) => factory.getType(type)); } function toProtocolTypeOrUndefined( - type: PyrightTypes.Type | undefined, + type: ViperTypes.Type | undefined, factory: ProtocolTypeFactory ): TypeServerProtocol.Type | undefined { if (!type) { @@ -149,7 +149,7 @@ function toProtocolTypeOrUndefined( return factory.getType(type); } -function toProtocolTypeArgs(type: PyrightTypes.ClassType, factory: ProtocolTypeFactory) { +function toProtocolTypeArgs(type: ViperTypes.ClassType, factory: ProtocolTypeFactory) { // See if we have any type arguments. Set those on the handle too. let typeArgs: TypeServerProtocol.Type[] | undefined = undefined; if (type.priv.tupleTypeArgs) { @@ -174,7 +174,7 @@ function toProtocolTypeArgs(type: PyrightTypes.ClassType, factory: ProtocolTypeF return typeArgs; } -function toProtocolTypeAliasInfo(info: PyrightTypes.TypeAliasInfo | undefined, factory: ProtocolTypeFactory) { +function toProtocolTypeAliasInfo(info: ViperTypes.TypeAliasInfo | undefined, factory: ProtocolTypeFactory) { if (!info) { return undefined; } @@ -196,9 +196,9 @@ function toProtocolTypeAliasInfo(info: PyrightTypes.TypeAliasInfo | undefined, f // This should be only called from TspTypeFactory // Otherwise, cycle detection won't work. -function toProtocolType(id: number, type: PyrightTypes.Type, factory: ProtocolTypeFactory): TypeServerProtocol.Type { +function toProtocolType(id: number, type: ViperTypes.Type, factory: ProtocolTypeFactory): TypeServerProtocol.Type { switch (type.category) { - case PyrightTypes.TypeCategory.Class: { + case ViperTypes.TypeCategory.Class: { const decl = type.shared.declaration; if (decl) { return { @@ -215,7 +215,7 @@ function toProtocolType(id: number, type: PyrightTypes.Type, factory: ProtocolTy return createSynthesizedType(id, type, factory); } - case PyrightTypes.TypeCategory.Function: { + case ViperTypes.TypeCategory.Function: { const decl = type.shared.declaration; if (decl) { // Compute boundToType: if not set but strippedFirstParamType exists, use it as boundToType @@ -223,12 +223,12 @@ function toProtocolType(id: number, type: PyrightTypes.Type, factory: ProtocolTy if ( !boundToType && type.priv.strippedFirstParamType && - PyrightTypes.isClass(type.priv.strippedFirstParamType) + ViperTypes.isClass(type.priv.strippedFirstParamType) ) { boundToType = type.priv.strippedFirstParamType; } - const returnType = PyrightTypes.FunctionType.getEffectiveReturnType(type, true); + const returnType = ViperTypes.FunctionType.getEffectiveReturnType(type, true); return { id, kind: TypeServerProtocol.TypeKind.Function, @@ -249,9 +249,9 @@ function toProtocolType(id: number, type: PyrightTypes.Type, factory: ProtocolTy return createSynthesizedType(id, type, factory); } - case PyrightTypes.TypeCategory.Overloaded: { - const implementation = PyrightTypes.OverloadedType.getImplementation(type); - const overloaded = PyrightTypes.OverloadedType.getOverloads(type); + case ViperTypes.TypeCategory.Overloaded: { + const implementation = ViperTypes.OverloadedType.getImplementation(type); + const overloaded = ViperTypes.OverloadedType.getOverloads(type); return { id, @@ -261,7 +261,7 @@ function toProtocolType(id: number, type: PyrightTypes.Type, factory: ProtocolTy implementation: toProtocolTypeOrUndefined(implementation, factory), } satisfies TypeServerProtocol.OverloadedType; } - case PyrightTypes.TypeCategory.TypeVar: { + case ViperTypes.TypeCategory.TypeVar: { const declaration = getDeclarationForTypeVar(type, factory); if (declaration) { return { @@ -274,7 +274,7 @@ function toProtocolType(id: number, type: PyrightTypes.Type, factory: ProtocolTy return createSynthesizedType(id, type, factory); } - case PyrightTypes.TypeCategory.Unbound: { + case ViperTypes.TypeCategory.Unbound: { const handle: TypeServerProtocol.BuiltInType = { id, kind: TypeServerProtocol.TypeKind.BuiltIn, @@ -284,7 +284,7 @@ function toProtocolType(id: number, type: PyrightTypes.Type, factory: ProtocolTy return handle; } - case PyrightTypes.TypeCategory.Unknown: { + case ViperTypes.TypeCategory.Unknown: { const possibleType = type.priv.possibleType; const handle: TypeServerProtocol.BuiltInType = { id, @@ -295,7 +295,7 @@ function toProtocolType(id: number, type: PyrightTypes.Type, factory: ProtocolTy }; return handle; } - case PyrightTypes.TypeCategory.Any: { + case ViperTypes.TypeCategory.Any: { const handle: TypeServerProtocol.BuiltInType = { id, kind: TypeServerProtocol.TypeKind.BuiltIn, @@ -304,7 +304,7 @@ function toProtocolType(id: number, type: PyrightTypes.Type, factory: ProtocolTy }; return handle; } - case PyrightTypes.TypeCategory.Never: { + case ViperTypes.TypeCategory.Never: { const handle: TypeServerProtocol.BuiltInType = { id, kind: TypeServerProtocol.TypeKind.BuiltIn, @@ -313,7 +313,7 @@ function toProtocolType(id: number, type: PyrightTypes.Type, factory: ProtocolTy }; return handle; } - case PyrightTypes.TypeCategory.Union: + case ViperTypes.TypeCategory.Union: return { id, kind: TypeServerProtocol.TypeKind.Union, @@ -323,7 +323,7 @@ function toProtocolType(id: number, type: PyrightTypes.Type, factory: ProtocolTy subTypes: map(type.priv.subtypes, (t) => factory.getType(t)), } satisfies TypeServerProtocol.UnionType; - case PyrightTypes.TypeCategory.Module: { + case ViperTypes.TypeCategory.Module: { return { id, kind: TypeServerProtocol.TypeKind.Module, @@ -337,16 +337,16 @@ function toProtocolType(id: number, type: PyrightTypes.Type, factory: ProtocolTy function createSynthesizedType( id: number, - type: PyrightTypes.FunctionType | PyrightTypes.ClassType | PyrightTypes.TypeVarType, + type: ViperTypes.FunctionType | ViperTypes.ClassType | ViperTypes.TypeVarType, factory: ProtocolTypeFactory ): TypeServerProtocol.SynthesizedType { const options = { pythonVersion: factory.pythonVersion } satisfies StubGenerationOptions; let moduleHandle: TypeServerProtocol.ModuleType; let stubResult: StubGenerationResult; - if (PyrightTypes.isTypeVar(type)) { + if (ViperTypes.isTypeVar(type)) { const moduleName = factory.view.getModuleName(factory.sourceUri) ?? ''; - const moduleType = PyrightTypes.ModuleType.create(moduleName, factory.sourceUri, new Map()); + const moduleType = ViperTypes.ModuleType.create(moduleName, factory.sourceUri, new Map()); moduleHandle = factory.getType(moduleType) as TypeServerProtocol.ModuleType; stubResult = generateStubFromTypeVar(type, options); @@ -354,7 +354,7 @@ function createSynthesizedType( const module = factory.getModule(type); moduleHandle = factory.getType(module) as TypeServerProtocol.ModuleType; - stubResult = PyrightTypes.isFunction(type) + stubResult = ViperTypes.isFunction(type) ? generateStubFromFunctionType(factory.evaluator, type, options) : generateStubFromClassType(factory.evaluator, type, options); } @@ -375,7 +375,7 @@ function createSynthesizedType( } function toProtocolSpecializedFunctionTypesOrUndefined( - specializedTypes: PyrightTypes.SpecializedFunctionTypes | undefined, + specializedTypes: ViperTypes.SpecializedFunctionTypes | undefined, factory: ProtocolTypeFactory ): TypeServerProtocol.SpecializedFunctionTypes | undefined { if (!specializedTypes) { @@ -392,7 +392,7 @@ function toProtocolSpecializedFunctionTypesOrUndefined( } function toProtocolLiteralValue( - type: PyrightTypes.ClassType, + type: ViperTypes.ClassType, factory: ProtocolTypeFactory ): TypeServerProtocol.LiteralValue | undefined { const value = type.priv.literalValue; @@ -400,7 +400,7 @@ function toProtocolLiteralValue( return undefined; } - if (value instanceof PyrightTypes.SentinelLiteral) { + if (value instanceof ViperTypes.SentinelLiteral) { return { classNode: toProtocolNode(type.shared.declaration!.node, factory.view), moduleName: type.shared.moduleName, @@ -408,7 +408,7 @@ function toProtocolLiteralValue( } satisfies TypeServerProtocol.SentinelLiteral; } - if (value instanceof PyrightTypes.EnumLiteral) { + if (value instanceof ViperTypes.EnumLiteral) { return { className: value.className, itemName: value.itemName, @@ -424,7 +424,7 @@ function toProtocolLiteralValue( // reconstruction frequently loses this link, so we search for it on demand using the // scope id that is preserved on the TypeVar instance. export function getDeclarationForTypeVar( - typeVar: PyrightTypes.TypeVarType, + typeVar: ViperTypes.TypeVarType, factory: ProtocolTypeFactory ): Declaration | undefined { // freeTypeVar stores the "canonical" definition for synthesized instances that were @@ -449,7 +449,7 @@ export function getDeclarationForTypeVar( // Start by inspecting the symbol table attached to the original scope; this covers // most cases for function, class, and alias TypeVars. let symbolTable = factory.view.symbolLookup.getSymbolsForNode(scopeNode); - if (!symbolTable && scopeNode.nodeType === PyrightNodes.ParseNodeType.Module) { + if (!symbolTable && scopeNode.nodeType === ViperNodes.ParseNodeType.Module) { const fileInfo = factory.view.symbolLookup.getFileInfo(scopeNode); symbolTable = factory.view.symbolLookup.getSymbolsForFile(fileInfo.fileUri); } @@ -459,7 +459,7 @@ export function getDeclarationForTypeVar( if ( (!symbol || symbol.getDeclarations().length === 0) && - scopeNode.nodeType !== PyrightNodes.ParseNodeType.Module + scopeNode.nodeType !== ViperNodes.ParseNodeType.Module ) { // For nested scopes we can fall back to the file-level module scope. This is // common when using PEP 695 syntax where a type parameter is hoisted into the @@ -504,7 +504,7 @@ export function getDeclarationForTypeVar( // Search all known parse trees to locate the node that owns the provided scope id. // Scope ids are assigned to functions, classes, modules, and type aliases; once we // find the matching node we can dig into its symbol table for declarations. -function findScopeNodeForId(scopeId: string, view: IProgram): PyrightNodes.ParseNode | undefined { +function findScopeNodeForId(scopeId: string, view: IProgram): ViperNodes.ParseNode | undefined { const targetPrefix = scopeId.split('.', 1)[0]; const matchingFiles = view.symbolLookup.getMatchingFileInfos(targetPrefix); @@ -514,7 +514,7 @@ function findScopeNodeForId(scopeId: string, view: IProgram): PyrightNodes.Parse continue; } - const stack: PyrightNodes.ParseNode[] = [parseResults.parseTree]; + const stack: ViperNodes.ParseNode[] = [parseResults.parseTree]; while (stack.length > 0) { const node = stack.pop()!; const nodeScopeId = view.symbolLookup.getScopeIdForNode(node); @@ -523,7 +523,7 @@ function findScopeNodeForId(scopeId: string, view: IProgram): PyrightNodes.Parse } // Expression nodes cannot contain declarations, so skip their children. - if (!PyrightNodes.isExpressionNode(node)) { + if (!ViperNodes.isExpressionNode(node)) { for (const child of getChildNodes(node)) { if (child) { stack.push(child); @@ -540,18 +540,18 @@ function findScopeNodeForId(scopeId: string, view: IProgram): PyrightNodes.Parse // type parameters (function/class/type alias). This gives us a concrete parse node even // when the TypeVar was not bound to a symbol table entry. function findTypeParameterNode( - scopeNode: PyrightNodes.ParseNode, + scopeNode: ViperNodes.ParseNode, typeVarName: string -): PyrightNodes.TypeParameterNode | undefined { - let typeParams: PyrightNodes.TypeParameterListNode | undefined; +): ViperNodes.TypeParameterNode | undefined { + let typeParams: ViperNodes.TypeParameterListNode | undefined; switch (scopeNode.nodeType) { - case PyrightNodes.ParseNodeType.Function: - case PyrightNodes.ParseNodeType.Class: - case PyrightNodes.ParseNodeType.TypeAlias: + case ViperNodes.ParseNodeType.Function: + case ViperNodes.ParseNodeType.Class: + case ViperNodes.ParseNodeType.TypeAlias: typeParams = scopeNode.d.typeParams; break; - case PyrightNodes.ParseNodeType.Module: + case ViperNodes.ParseNodeType.Module: typeParams = undefined; break; } @@ -565,11 +565,11 @@ function findTypeParameterNode( // Walks parent pointers up to the root module node. Used when we fall back to the // file-level scope to locate a TypeVar that was re-exported at module scope. -function findModuleAncestor(node: PyrightNodes.ParseNode): PyrightNodes.ModuleNode | undefined { - let current: PyrightNodes.ParseNode | undefined = node; +function findModuleAncestor(node: ViperNodes.ParseNode): ViperNodes.ModuleNode | undefined { + let current: ViperNodes.ParseNode | undefined = node; while (current) { - if (current.nodeType === PyrightNodes.ParseNodeType.Module) { - return current as PyrightNodes.ModuleNode; + if (current.nodeType === ViperNodes.ParseNodeType.Module) { + return current as ViperNodes.ModuleNode; } current = current.parent; } @@ -578,33 +578,33 @@ function findModuleAncestor(node: PyrightNodes.ParseNode): PyrightNodes.ModuleNo // Only certain node kinds introduce scope ids; this helper keeps the search logic focused // on those nodes to avoid unnecessary traversal work during scope discovery. -function isTypeVarScopeCandidate(node: PyrightNodes.ParseNode): boolean { +function isTypeVarScopeCandidate(node: ViperNodes.ParseNode): boolean { switch (node.nodeType) { - case PyrightNodes.ParseNodeType.Module: - case PyrightNodes.ParseNodeType.Class: - case PyrightNodes.ParseNodeType.Function: - case PyrightNodes.ParseNodeType.TypeAlias: + case ViperNodes.ParseNodeType.Module: + case ViperNodes.ParseNodeType.Class: + case ViperNodes.ParseNodeType.Function: + case ViperNodes.ParseNodeType.TypeAlias: return true; default: return false; } } -export function findFirstExpression(node: PyrightNodes.ParseNode): PyrightNodes.ExpressionNode | undefined { - if (PyrightNodes.isExpressionNode(node)) { - return node as PyrightNodes.ExpressionNode; +export function findFirstExpression(node: ViperNodes.ParseNode): ViperNodes.ExpressionNode | undefined { + if (ViperNodes.isExpressionNode(node)) { + return node as ViperNodes.ExpressionNode; } class ExpressionNodeWalker extends ParseTreeWalker { - private _result: PyrightNodes.ExpressionNode | undefined; + private _result: ViperNodes.ExpressionNode | undefined; - getResult(): PyrightNodes.ExpressionNode | undefined { + getResult(): ViperNodes.ExpressionNode | undefined { return this._result; } - override visitNode(node: PyrightNodes.ParseNode): PyrightNodes.ParseNodeArray { - if (PyrightNodes.isExpressionNode(node)) { - this._result = node as PyrightNodes.ExpressionNode; + override visitNode(node: ViperNodes.ParseNode): ViperNodes.ParseNodeArray { + if (ViperNodes.isExpressionNode(node)) { + this._result = node as ViperNodes.ExpressionNode; return []; } return super.visitNode(node); diff --git a/packages/vipeye-internal/src/typeServer/typeServerEvaluator.ts b/packages/vipeye-internal/src/typeServer/typeServerEvaluator.ts index 04517a49..da4a613f 100644 --- a/packages/vipeye-internal/src/typeServer/typeServerEvaluator.ts +++ b/packages/vipeye-internal/src/typeServer/typeServerEvaluator.ts @@ -3,12 +3,12 @@ * Copyright (c) Microsoft Corporation. * Licensed under the MIT license. * - * The type server answers type queries with Pyright's ordinary synchronous `TypeEvaluator`. + * The type server answers type queries with Vipeye's ordinary synchronous `TypeEvaluator`. * It needs exactly one capability beyond the stock evaluator: access to the snapshot's symbol * lookup. This module defines that thin extension (`ITypeServerEvaluator`) and a factory that * layers it onto the program's current evaluator. * - * Cancellation works exactly as it does everywhere else in Pyright: the evaluator polls the + * Cancellation works exactly as it does everywhere else in Vipeye: the evaluator polls the * active cancellation token via `runWithCancellationToken` / `throwIfCancellationRequested`, * so a long-running synchronous query can still be interrupted in the middle of a request. */ @@ -25,7 +25,7 @@ export interface ITypeServerEvaluator extends TypeEvaluator { /** * Build an `ITypeServerEvaluator` backed by the `Program`'s synchronous `TypeEvaluator`. * - * Pyright's evaluator is a closure-backed object whose methods don't depend on `this`, so we + * Vipeye's evaluator is a closure-backed object whose methods don't depend on `this`, so we * can prototype-delegate to it and add `getSymbolLookup` without copying every method. The * evaluator is resolved from `program.evaluator` at creation time; callers create a fresh * evaluator per request (the program recreates its evaluator when configuration or imports diff --git a/packages/vipeye-internal/src/typeServer/typeServerFileSystem.ts b/packages/vipeye-internal/src/typeServer/typeServerFileSystem.ts index cf0cda3a..d40c9577 100644 --- a/packages/vipeye-internal/src/typeServer/typeServerFileSystem.ts +++ b/packages/vipeye-internal/src/typeServer/typeServerFileSystem.ts @@ -3,13 +3,13 @@ * Copyright (c) Microsoft Corporation. * Licensed under the MIT license. * - * The file system used by the Pyright type server. It wraps the real file system in a + * The file system used by the Viper type server. It wraps the real file system in a * VirtualFileOverlayFileSystem so that individual files can be transparently redirected to * alternate on-disk locations (e.g. merged Django stubs produced by an external client), and * exposes that overlay via the `virtualOverlay` getter so the server's virtual-file-redirect * handlers (TspSupplemental) can register and remove redirects. * - * This is the Pyright-native counterpart to Pylance's `PylanceFileSystem`. Notebook cell URI + * This is the Vipeye-native counterpart to Pylance's `PylanceFileSystem`. Notebook cell URI * mapping is optional here (supplied in the notebook phase); when no mapper is provided the * notebook branches simply delegate to the underlying file system. */ @@ -20,22 +20,22 @@ import { Disposable } from 'vscode-jsonrpc'; import { FileSystem, MkDirOptions, Stats } from '../common/fileSystem'; import { FileWatcher, FileWatcherEventHandler } from '../common/fileWatcher'; import { Uri } from '../common/uri/uri'; -import { IPyrightFileSystem, PyrightFileSystem } from '../pyrightFileSystem'; +import { IViperFileSystem, ViperFileSystem } from '../viperFileSystem'; import { INotebookUriMapper, NotebookUriMapper } from './notebookUriMapper'; import { VirtualFileOverlayFileSystem } from './virtualFileOverlayFileSystem'; -export class TypeServerFileSystem implements IPyrightFileSystem { - private readonly _fs: IPyrightFileSystem; +export class TypeServerFileSystem implements IViperFileSystem { + private readonly _fs: IViperFileSystem; private readonly _virtualOverlay: VirtualFileOverlayFileSystem; constructor(realFileSystem: FileSystem, private readonly _uriMapper?: INotebookUriMapper) { // Wrap the real FS in a virtual file overlay so that individual files can be // transparently redirected to alternate on-disk locations. The overlay is a no-op - // pass-through when no redirects are registered. Then wrap that in a PyrightFileSystem + // pass-through when no redirects are registered. Then wrap that in a ViperFileSystem // so partial-stub augmentation continues to work. this._virtualOverlay = new VirtualFileOverlayFileSystem(realFileSystem); - this._fs = new PyrightFileSystem(this._virtualOverlay); + this._fs = new ViperFileSystem(this._virtualOverlay); } /** diff --git a/packages/vipeye-internal/src/typeServer/typeServerServiceKeys.ts b/packages/vipeye-internal/src/typeServer/typeServerServiceKeys.ts index 17d2d82f..5aed7b18 100644 --- a/packages/vipeye-internal/src/typeServer/typeServerServiceKeys.ts +++ b/packages/vipeye-internal/src/typeServer/typeServerServiceKeys.ts @@ -16,6 +16,6 @@ export namespace TypeServerServiceKeys { export const uriMapper = new ServiceKey('INotebookUriMapper'); // Profiling is a Pylance-only feature and is never registered in the standalone - // Pyright type server, so `tryGet` returns undefined and profiling becomes a no-op. + // Viper type server, so `tryGet` returns undefined and profiling becomes a no-op. export const profilingService = new ServiceKey('IProfilingService'); } diff --git a/packages/vipeye-internal/src/pyright.ts b/packages/vipeye-internal/src/viper.ts similarity index 95% rename from packages/vipeye-internal/src/pyright.ts rename to packages/vipeye-internal/src/viper.ts index 3d57bf78..e2e465ae 100644 --- a/packages/vipeye-internal/src/pyright.ts +++ b/packages/vipeye-internal/src/viper.ts @@ -1,10 +1,10 @@ /* - * pyright.ts + * viper.ts * Copyright (c) Microsoft Corporation. * Licensed under the MIT license. * Author: Eric Traut * - * Command-line entry point for pyright type checker. + * Command-line entry point for viper type checker. */ // Add the start timer at the very top of the file, before we import other modules. @@ -27,7 +27,7 @@ import { maxSourceFileSize } from './analyzer/sourceFile'; import { SourceFileInfo } from './analyzer/sourceFileInfo'; import { initializeDependencies } from './common/asyncInitialization'; import { ChokidarFileWatcherProvider } from './common/chokidarFileWatcherProvider'; -import { CommandLineOptions as PyrightCommandLineOptions } from './common/commandLineOptions'; +import { CommandLineOptions as ViperCommandLineOptions } from './common/commandLineOptions'; import { ConsoleInterface, LogLevel, StandardConsole, StderrConsole } from './common/console'; import { fail } from './common/debug'; import { createDeferred } from './common/deferred'; @@ -44,9 +44,9 @@ import { getStdin } from './common/streamUtils'; import { Range, isEmptyRange } from './common/textRange'; import { Uri } from './common/uri/uri'; import { getFileSpec, tryStat } from './common/uri/uriUtils'; -import { PyrightFileSystem } from './pyrightFileSystem'; +import { ViperFileSystem } from './viperFileSystem'; -const toolName = 'pyright'; +const toolName = 'viper'; type SeverityLevel = 'error' | 'warning' | 'information'; @@ -60,58 +60,58 @@ enum ExitStatus { } // The schema for this object is publicly documented. Do not change it. -interface PyrightJsonResults { +interface ViperJsonResults { version: string; time: string; - generalDiagnostics: PyrightJsonDiagnostic[]; - summary: PyrightJsonSummary; - typeCompleteness?: PyrightTypeCompletenessReport; + generalDiagnostics: ViperJsonDiagnostic[]; + summary: ViperJsonSummary; + typeCompleteness?: ViperTypeCompletenessReport; } // The schema for this object is publicly documented. Do not change it. -interface PyrightSymbolCount { +interface ViperSymbolCount { withKnownType: number; withAmbiguousType: number; withUnknownType: number; } // The schema for this object is publicly documented. Do not change it. -interface PyrightTypeCompletenessReport { +interface ViperTypeCompletenessReport { packageName: string; packageRootDirectory?: string | undefined; moduleName: string; moduleRootDirectory?: string | undefined; ignoreUnknownTypesFromImports: boolean; pyTypedPath?: string | undefined; - exportedSymbolCounts: PyrightSymbolCount; - otherSymbolCounts: PyrightSymbolCount; + exportedSymbolCounts: ViperSymbolCount; + otherSymbolCounts: ViperSymbolCount; missingFunctionDocStringCount: number; missingClassDocStringCount: number; missingDefaultParamCount: number; completenessScore: number; - modules: PyrightPublicModuleReport[]; - symbols: PyrightPublicSymbolReport[]; + modules: ViperPublicModuleReport[]; + symbols: ViperPublicSymbolReport[]; } // The schema for this object is publicly documented. Do not change it. -interface PyrightPublicModuleReport { +interface ViperPublicModuleReport { name: string; } // The schema for this object is publicly documented. Do not change it. -interface PyrightPublicSymbolReport { +interface ViperPublicSymbolReport { category: string; name: string; referenceCount: number; isTypeKnown: boolean; isTypeAmbiguous: boolean; isExported: boolean; - diagnostics: PyrightJsonDiagnostic[]; + diagnostics: ViperJsonDiagnostic[]; alternateNames?: string[] | undefined; } // The schema for this object is publicly documented. Do not change it. -interface PyrightJsonDiagnostic { +interface ViperJsonDiagnostic { file: string; severity: SeverityLevel; message: string; @@ -120,7 +120,7 @@ interface PyrightJsonDiagnostic { } // The schema for this object is publicly documented. Do not change it. -interface PyrightJsonSummary { +interface ViperJsonSummary { filesAnalyzed: number; errorCount: number; warningCount: number; @@ -247,7 +247,7 @@ async function processArgs(): Promise { } } - const options = new PyrightCommandLineOptions(process.cwd(), false); + const options = new ViperCommandLineOptions(process.cwd(), false); const tempFile = new RealTempFile(); // Assume any relative paths are relative to the working directory. @@ -276,7 +276,7 @@ async function processArgs(): Promise { ); // Verify the specified file specs to make sure their wildcard roots exist. - const tempFileSystem = new PyrightFileSystem(createFromRealFileSystem(tempFile)); + const tempFileSystem = new ViperFileSystem(createFromRealFileSystem(tempFile)); for (const fileDesc of options.configSettings.includeFileSpecsOverride) { const includeSpec = getFileSpec(Uri.file(process.cwd(), tempFile), fileDesc); @@ -369,7 +369,7 @@ async function processArgs(): Promise { options.configSettings.autoSearchPaths = true; if (args.lib) { - console.warn(`The --lib option is deprecated. Pyright now defaults to using library code to infer types.`); + console.warn(`The --lib option is deprecated. Vipeye now defaults to using library code to infer types.`); } let minSeverityLevel: SeverityLevel = 'information'; @@ -397,7 +397,7 @@ async function processArgs(): Promise { // If using outputjson, redirect all console output to stderr so it doesn't mess // up the JSON output, which goes to stdout. const output = args.outputjson ? new StderrConsole(logLevel) : new StandardConsole(logLevel); - const fileSystem = new PyrightFileSystem( + const fileSystem = new ViperFileSystem( createFromRealFileSystem(tempFile, output, new ChokidarFileWatcherProvider(output)) ); @@ -453,7 +453,7 @@ async function processArgs(): Promise { async function runSingleThreaded( args: CommandLineOptions, - options: PyrightCommandLineOptions, + options: ViperCommandLineOptions, service: AnalyzerService, minSeverityLevel: SeverityLevel, output: ConsoleInterface @@ -572,7 +572,7 @@ async function runSingleThreaded( async function runMultiThreaded( args: CommandLineOptions, - options: PyrightCommandLineOptions, + options: ViperCommandLineOptions, maxThreadCount: number, service: AnalyzerService, minSeverityLevel: SeverityLevel, @@ -781,7 +781,7 @@ async function runMultiThreaded( function runWorkerMessageLoop(workerNum: number, tempFolderName: string) { let serviceProvider: ServiceProvider | undefined; let service: AnalyzerService | undefined; - let fileSystem: PyrightFileSystem | undefined; + let fileSystem: ViperFileSystem | undefined; let lastOpenFileUri: Uri | undefined; const sendMessageToParent = (message: string, data: any) => { @@ -800,7 +800,7 @@ function runWorkerMessageLoop(workerNum: number, tempFolderName: string) { switch (messageObj.action) { case 'setOptions': { - const options = new PyrightCommandLineOptions(process.cwd(), false); + const options = new ViperCommandLineOptions(process.cwd(), false); Object.keys(messageObj.data).forEach((key) => { (options as any)[key] = messageObj.data[key]; @@ -813,7 +813,7 @@ function runWorkerMessageLoop(workerNum: number, tempFolderName: string) { const output = new StderrConsole(logLevel); const tempFile = new RealTempFile(tempFolderName); - fileSystem = new PyrightFileSystem( + fileSystem = new ViperFileSystem( createFromRealFileSystem(tempFile, output, new ChokidarFileWatcherProvider(output)) ); @@ -873,7 +873,7 @@ function runWorkerMessageLoop(workerNum: number, tempFolderName: string) { function verifyPackageTypes( serviceProvider: ServiceProvider, packageName: string, - options: PyrightCommandLineOptions, + options: ViperCommandLineOptions, outputJson: boolean, minSeverityLevel: SeverityLevel, ignoreUnknownTypesFromImports: boolean @@ -908,7 +908,7 @@ function verifyPackageTypes( } } -function accumulateReportDiagnosticStats(diag: PyrightJsonDiagnostic, report: PyrightJsonResults) { +function accumulateReportDiagnosticStats(diag: ViperJsonDiagnostic, report: ViperJsonResults) { if (diag.severity === 'error') { report.summary.errorCount++; } else if (diag.severity === 'warning') { @@ -922,8 +922,8 @@ function buildTypeCompletenessReport( packageName: string, completenessReport: PackageTypeReport, minSeverityLevel: SeverityLevel -): PyrightJsonResults { - const report: PyrightJsonResults = { +): ViperJsonResults { + const report: ViperJsonResults = { version: getVersionString(), time: Date.now().toString(), generalDiagnostics: [], @@ -972,7 +972,7 @@ function buildTypeCompletenessReport( // Add the modules. completenessReport.modules.forEach((module) => { - const jsonModule: PyrightPublicModuleReport = { + const jsonModule: ViperPublicModuleReport = { name: module.name, }; @@ -981,7 +981,7 @@ function buildTypeCompletenessReport( // Add the symbols. completenessReport.symbols.forEach((symbol) => { - const diagnostics: PyrightJsonDiagnostic[] = []; + const diagnostics: ViperJsonDiagnostic[] = []; // Convert and filter the diagnostics. symbol.diagnostics.forEach((diag) => { @@ -991,7 +991,7 @@ function buildTypeCompletenessReport( } }); - const jsonSymbol: PyrightPublicSymbolReport = { + const jsonSymbol: ViperPublicSymbolReport = { category: PackageTypeVerifier.getSymbolCategoryString(symbol.category), name: symbol.fullName, referenceCount: symbol.referenceCount, @@ -1042,7 +1042,7 @@ function buildTypeCompletenessReport( return report; } -function printTypeCompletenessReportText(results: PyrightJsonResults, verboseOutput: boolean) { +function printTypeCompletenessReportText(results: ViperJsonResults, verboseOutput: boolean) { const completenessReport = results.typeCompleteness!; console.info(`Module name: "${completenessReport.moduleName}"`); @@ -1169,7 +1169,7 @@ function printUsage() { ' -v,--venvpath Directory that contains virtual environments\n' + ' --verbose Emit verbose diagnostics\n' + ' --verifytypes Verify type completeness of a py.typed package\n' + - ' --version Print Pyright version and exit\n' + + ' --version Print Vipeye version and exit\n' + ' --warnings Use exit code of 1 if warnings are reported\n' + ' -w,--watch Continue to run and watch for changes\n' + ' - Read files from stdin\n' @@ -1192,7 +1192,7 @@ function reportDiagnosticsAsJson( filesInProgram: number, timeInSec: number ): DiagnosticResult { - const report: PyrightJsonResults = { + const report: ViperJsonResults = { version: getVersionString(), time: Date.now().toString(), generalDiagnostics: [], @@ -1267,7 +1267,7 @@ function convertDiagnosticCategoryToSeverity(category: DiagnosticCategory): Seve } } -function convertDiagnosticToJson(filePath: string, diag: Diagnostic): PyrightJsonDiagnostic { +function convertDiagnosticToJson(filePath: string, diag: Diagnostic): ViperJsonDiagnostic { return { file: filePath, severity: convertDiagnosticCategoryToSeverity(diag.category), @@ -1328,7 +1328,7 @@ function reportDiagnosticsAsText( }; } -function logDiagnosticToConsole(diag: PyrightJsonDiagnostic, prefix = ' ') { +function logDiagnosticToConsole(diag: ViperJsonDiagnostic, prefix = ' ') { let message = prefix; if (diag.file) { message += `${diag.file}:`; diff --git a/packages/vipeye-internal/src/pyrightFileSystem.ts b/packages/vipeye-internal/src/viperFileSystem.ts similarity index 88% rename from packages/vipeye-internal/src/pyrightFileSystem.ts rename to packages/vipeye-internal/src/viperFileSystem.ts index 25c9e542..eea8e6ef 100644 --- a/packages/vipeye-internal/src/pyrightFileSystem.ts +++ b/packages/vipeye-internal/src/viperFileSystem.ts @@ -1,5 +1,5 @@ /* - * pyrightFileSystem.ts + * viperFileSystem.ts * Copyright (c) Microsoft Corporation. * Licensed under the MIT license. * @@ -12,9 +12,9 @@ import { FileSystem, MkDirOptions } from './common/fileSystem'; import { Uri } from './common/uri/uri'; import { ReadOnlyAugmentedFileSystem } from './readonlyAugmentedFileSystem'; -export interface IPyrightFileSystem extends FileSystem {} +export interface IViperFileSystem extends FileSystem {} -export class PyrightFileSystem extends ReadOnlyAugmentedFileSystem implements IPyrightFileSystem { +export class ViperFileSystem extends ReadOnlyAugmentedFileSystem implements IViperFileSystem { constructor(realFS: FileSystem) { super(realFS); } diff --git a/packages/vipeye-internal/typeshed-fallback/README.md b/packages/vipeye-internal/typeshed-fallback/README.md index dae1780a..c2036557 100644 --- a/packages/vipeye-internal/typeshed-fallback/README.md +++ b/packages/vipeye-internal/typeshed-fallback/README.md @@ -26,7 +26,7 @@ Typeshed supports Python versions 3.10 to 3.14. ## Using If you're just using a type checker (e.g. [mypy](https://github.com/python/mypy/), -[pyright](https://github.com/microsoft/pyright), or PyCharm's built-in type +[Viper](https://github.com/TermiNexus/TransPyC), or PyCharm's built-in type checker), as opposed to developing it, you don't need to interact with the typeshed repo at all: a copy of the standard library part of typeshed is bundled with type checkers. diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/_asyncio.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/_asyncio.vpi index 17999651..a7fb3542 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/_asyncio.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/_asyncio.vpi @@ -53,7 +53,7 @@ else: # since the only reason why `asyncio.Future` is invariant is the `set_result()` method, # and `asyncio.Task.set_result()` always raises. @disjoint_base -class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportInvalidTypeArguments] +class Task(Future[_T_co]): # type: ignore[type-var] # viper: ignore[reportInvalidTypeArguments] if sys.version_info >= (3, 12): def __init__( self, diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/_ctypes.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/_ctypes.vpi index d800ac5c..8bc79be8 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/_ctypes.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/_ctypes.vpi @@ -60,8 +60,8 @@ if sys.version_info >= (3, 13): # By default mypy complains about the following two methods, because strictly speaking cls # might not be a Type[_CT]. However this doesn't happen because this is only a # metaclass for subclasses of _CData. - def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] + def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] _CTypeBaseType = _CType_Type @@ -94,14 +94,14 @@ class _PyCSimpleType(_CTypeBaseType): def in_dll(self: type[_typeshed.Self], dll: CDLL, name: str, /) -> _typeshed.Self: ... if sys.version_info < (3, 13): # Inherited from CType_Type starting on 3.13 - def __mul__(self: type[_CT], value: int, /) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - def __rmul__(self: type[_CT], value: int, /) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def __mul__(self: type[_CT], value: int, /) -> type[Array[_CT]]: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] + def __rmul__(self: type[_CT], value: int, /) -> type[Array[_CT]]: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class _SimpleCData(_CData, Generic[_T], metaclass=_PyCSimpleType): value: _T # The TypeVar can be unsolved here, # but we can't use overloads without creating many, many mypy false-positive errors - def __init__(self, value: _T = ...) -> None: ... # pyright: ignore[reportInvalidTypeVarUse] + def __init__(self, value: _T = ...) -> None: ... # viper: ignore[reportInvalidTypeVarUse] def __ctypes_from_outparam__(self, /) -> _T: ... # type: ignore[override] @type_check_only @@ -121,8 +121,8 @@ class _PyCPointerType(_CTypeBaseType): def set_type(self, type: _CTypeBaseType, /) -> None: ... if sys.version_info < (3, 13): # Inherited from CType_Type starting on 3.13 - def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] + def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class _Pointer(_PointerLike, _CData, Generic[_CT], metaclass=_PyCPointerType): _type_: type[_CT] @@ -172,8 +172,8 @@ class _PyCFuncPtrType(_CTypeBaseType): def in_dll(self: type[_typeshed.Self], dll: CDLL, name: str, /) -> _typeshed.Self: ... if sys.version_info < (3, 13): # Inherited from CType_Type starting on 3.13 - def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] + def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class CFuncPtr(_PointerLike, _CData, metaclass=_PyCFuncPtrType): restype: type[_CDataType] | Callable[[int], Any] | None @@ -252,8 +252,8 @@ class _UnionType(_CTypeBaseType): def __getattr__(self, name: str) -> _CField[Any, Any, Any]: ... if sys.version_info < (3, 13): # Inherited from CType_Type starting on 3.13 - def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] + def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class Union(_CData, metaclass=_UnionType): _fields_: ClassVar[Sequence[tuple[str, type[_CDataType]] | tuple[str, type[_CDataType], int]]] @@ -280,8 +280,8 @@ class _PyCStructType(_CTypeBaseType): def __getattr__(self, name: str) -> _CField[Any, Any, Any]: ... if sys.version_info < (3, 13): # Inherited from CType_Type starting on 3.13 - def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] + def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class Structure(_CData, metaclass=_PyCStructType): _fields_: ClassVar[Sequence[tuple[str, type[_CDataType]] | tuple[str, type[_CDataType], int]]] @@ -308,8 +308,8 @@ class _PyCArrayType(_CTypeBaseType): def in_dll(self: type[_typeshed.Self], dll: CDLL, name: str, /) -> _typeshed.Self: ... if sys.version_info < (3, 13): # Inherited from CType_Type starting on 3.13 - def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] + def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class Array(_CData, Generic[_CT], metaclass=_PyCArrayType): @property diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/_typeshed/_type_checker_internals.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/_typeshed/_type_checker_internals.vpi index a8411192..69749c3c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/_typeshed/_type_checker_internals.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/_typeshed/_type_checker_internals.vpi @@ -39,7 +39,7 @@ class TypedDictFallback(Mapping[str, object], metaclass=ABCMeta): # can go through. def setdefault(self, k: Never, default: object) -> object: ... # Mypy plugin hook for 'pop' expects that 'default' has a type variable type. - def pop(self, k: Never, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse] + def pop(self, k: Never, default: _T = ...) -> object: ... # viper: ignore[reportInvalidTypeVarUse] def update(self, m: typing_extensions.Self, /) -> None: ... def __delitem__(self, k: Never) -> None: ... def items(self) -> dict_items[str, object]: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/ast.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/ast.vpi index a1993773..3d4b8f23 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/ast.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/ast.vpi @@ -1711,23 +1711,23 @@ else: if sys.version_info < (3, 14): @deprecated("Removed in Python 3.14. Use `ast.Constant` instead.") class Num(Constant, metaclass=_ABC): - def __new__(cls, n: complex, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor] + def __new__(cls, n: complex, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # viper: ignore[reportInconsistentConstructor] @deprecated("Removed in Python 3.14. Use `ast.Constant` instead.") class Str(Constant, metaclass=_ABC): - def __new__(cls, s: str, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor] + def __new__(cls, s: str, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # viper: ignore[reportInconsistentConstructor] @deprecated("Removed in Python 3.14. Use `ast.Constant` instead.") class Bytes(Constant, metaclass=_ABC): - def __new__(cls, s: bytes, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor] + def __new__(cls, s: bytes, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # viper: ignore[reportInconsistentConstructor] @deprecated("Removed in Python 3.14. Use `ast.Constant` instead.") class NameConstant(Constant, metaclass=_ABC): - def __new__(cls, value: _ConstantValue, kind: str | None, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor] + def __new__(cls, value: _ConstantValue, kind: str | None, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # viper: ignore[reportInconsistentConstructor] @deprecated("Removed in Python 3.14. Use `ast.Constant` instead.") class Ellipsis(Constant, metaclass=_ABC): - def __new__(cls, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor] + def __new__(cls, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # viper: ignore[reportInconsistentConstructor] # everything below here is defined in ast.py diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/builtins.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/builtins.vpi index 774ef031..12c68f19 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/builtins.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/builtins.vpi @@ -1285,12 +1285,12 @@ class dict(MutableMapping[_KT, _VT]): @overload def __init__(self, /) -> None: ... @overload - def __init__(self: dict[str, _VT], /, **kwargs: _VT) -> None: ... # pyright: ignore[reportInvalidTypeVarUse] #11780 + def __init__(self: dict[str, _VT], /, **kwargs: _VT) -> None: ... # viper: ignore[reportInvalidTypeVarUse] #11780 @overload def __init__(self, map: SupportsKeysAndGetItem[_KT, _VT], /) -> None: ... @overload def __init__( - self: dict[str, _VT], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: dict[str, _VT], # viper: ignore[reportInvalidTypeVarUse] #11780 map: SupportsKeysAndGetItem[str, _VT], /, **kwargs: _VT, @@ -1299,7 +1299,7 @@ class dict(MutableMapping[_KT, _VT]): def __init__(self, iterable: Iterable[tuple[_KT, _VT]], /) -> None: ... @overload def __init__( - self: dict[str, _VT], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: dict[str, _VT], # viper: ignore[reportInvalidTypeVarUse] #11780 iterable: Iterable[tuple[str, _VT]], /, **kwargs: _VT, diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/collections/__init__.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/collections/__init__.vpi index d9c2e342..81ca71ed 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/collections/__init__.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/collections/__init__.vpi @@ -49,13 +49,13 @@ class UserDict(MutableMapping[_KT, _VT]): def __init__(self, dict: None = None, /) -> None: ... @overload def __init__( - self: UserDict[str, _VT], dict: None = None, /, **kwargs: _VT # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: UserDict[str, _VT], dict: None = None, /, **kwargs: _VT # viper: ignore[reportInvalidTypeVarUse] #11780 ) -> None: ... @overload def __init__(self, dict: SupportsKeysAndGetItem[_KT, _VT], /) -> None: ... @overload def __init__( - self: UserDict[str, _VT], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: UserDict[str, _VT], # viper: ignore[reportInvalidTypeVarUse] #11780 dict: SupportsKeysAndGetItem[str, _VT], /, **kwargs: _VT, @@ -64,7 +64,7 @@ class UserDict(MutableMapping[_KT, _VT]): def __init__(self, iterable: Iterable[tuple[_KT, _VT]], /) -> None: ... @overload def __init__( - self: UserDict[str, _VT], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: UserDict[str, _VT], # viper: ignore[reportInvalidTypeVarUse] #11780 iterable: Iterable[tuple[str, _VT]], /, **kwargs: _VT, @@ -364,17 +364,17 @@ class _OrderedDictValuesView(ValuesView[_VT_co]): # pyright doesn't have a specific error code for subclassing error! @final @type_check_only -class _odict_keys(dict_keys[_KT_co, _VT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] +class _odict_keys(dict_keys[_KT_co, _VT_co]): # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] def __reversed__(self) -> Iterator[_KT_co]: ... @final @type_check_only -class _odict_items(dict_items[_KT_co, _VT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] +class _odict_items(dict_items[_KT_co, _VT_co]): # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] def __reversed__(self) -> Iterator[tuple[_KT_co, _VT_co]]: ... @final @type_check_only -class _odict_values(dict_values[_KT_co, _VT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] +class _odict_values(dict_values[_KT_co, _VT_co]): # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] def __reversed__(self) -> Iterator[_VT_co]: ... @disjoint_base @@ -443,12 +443,12 @@ class defaultdict(dict[_KT, _VT]): @overload def __init__(self) -> None: ... @overload - def __init__(self: defaultdict[str, _VT], **kwargs: _VT) -> None: ... # pyright: ignore[reportInvalidTypeVarUse] #11780 + def __init__(self: defaultdict[str, _VT], **kwargs: _VT) -> None: ... # viper: ignore[reportInvalidTypeVarUse] #11780 @overload def __init__(self, default_factory: Callable[[], _VT] | None, /) -> None: ... @overload def __init__( - self: defaultdict[str, _VT], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: defaultdict[str, _VT], # viper: ignore[reportInvalidTypeVarUse] #11780 default_factory: Callable[[], _VT] | None, /, **kwargs: _VT, @@ -457,7 +457,7 @@ class defaultdict(dict[_KT, _VT]): def __init__(self, default_factory: Callable[[], _VT] | None, map: SupportsKeysAndGetItem[_KT, _VT], /) -> None: ... @overload def __init__( - self: defaultdict[str, _VT], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: defaultdict[str, _VT], # viper: ignore[reportInvalidTypeVarUse] #11780 default_factory: Callable[[], _VT] | None, map: SupportsKeysAndGetItem[str, _VT], /, @@ -467,7 +467,7 @@ class defaultdict(dict[_KT, _VT]): def __init__(self, default_factory: Callable[[], _VT] | None, iterable: Iterable[tuple[_KT, _VT]], /) -> None: ... @overload def __init__( - self: defaultdict[str, _VT], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: defaultdict[str, _VT], # viper: ignore[reportInvalidTypeVarUse] #11780 default_factory: Callable[[], _VT] | None, iterable: Iterable[tuple[str, _VT]], /, diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/contextlib.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/contextlib.vpi index b95c2350..fa595611 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/contextlib.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/contextlib.vpi @@ -43,7 +43,7 @@ _CM_EF = TypeVar("_CM_EF", bound=AbstractContextManager[Any, Any] | _ExitFunc) # At runtime it inherits from ABC and is not a Protocol, but it is on the # allowlist for use as a Protocol. @runtime_checkable -class AbstractContextManager(ABC, Protocol[_T_co, _ExitT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] +class AbstractContextManager(ABC, Protocol[_T_co, _ExitT_co]): # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] __slots__ = () def __enter__(self) -> _T_co: ... @abstractmethod @@ -55,7 +55,7 @@ class AbstractContextManager(ABC, Protocol[_T_co, _ExitT_co]): # type: ignore[m # At runtime it inherits from ABC and is not a Protocol, but it is on the # allowlist for use as a Protocol. @runtime_checkable -class AbstractAsyncContextManager(ABC, Protocol[_T_co, _ExitT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] +class AbstractAsyncContextManager(ABC, Protocol[_T_co, _ExitT_co]): # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] __slots__ = () async def __aenter__(self) -> _T_co: ... @abstractmethod @@ -207,7 +207,7 @@ class nullcontext(AbstractContextManager[_T, None], AbstractAsyncContextManager[ @overload def __init__(self: nullcontext[None]) -> None: ... @overload - def __init__(self: nullcontext[_T], enter_result: _T) -> None: ... # pyright: ignore[reportInvalidTypeVarUse] #11780 + def __init__(self: nullcontext[_T], enter_result: _T) -> None: ... # viper: ignore[reportInvalidTypeVarUse] #11780 def __enter__(self) -> _T: ... def __exit__(self, *exctype: Unused) -> None: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/dataclasses.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/dataclasses.vpi index 1a7b8fd6..eeacef4d 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/dataclasses.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/dataclasses.vpi @@ -298,7 +298,7 @@ def fields(class_or_instance: DataclassInstance | type[DataclassInstance]) -> tu # HACK: `obj: Never` typing matches if object argument is using `Any` type. @overload -def is_dataclass(obj: Never) -> TypeIs[DataclassInstance | type[DataclassInstance]]: ... # type: ignore[narrowed-type-not-subtype] # pyright: ignore[reportGeneralTypeIssues] +def is_dataclass(obj: Never) -> TypeIs[DataclassInstance | type[DataclassInstance]]: ... # type: ignore[narrowed-type-not-subtype] # viper: ignore[reportGeneralTypeIssues] @overload def is_dataclass(obj: type) -> TypeIs[type[DataclassInstance]]: ... @overload @@ -312,9 +312,9 @@ class InitVar(Generic[_T]): def __init__(self, type: Type[_T]) -> None: ... @overload - def __class_getitem__(cls, type: Type[_T]) -> InitVar[_T]: ... # pyright: ignore[reportInvalidTypeForm] + def __class_getitem__(cls, type: Type[_T]) -> InitVar[_T]: ... # viper: ignore[reportInvalidTypeForm] @overload - def __class_getitem__(cls, type: Any) -> InitVar[Any]: ... # pyright: ignore[reportInvalidTypeForm] + def __class_getitem__(cls, type: Any) -> InitVar[Any]: ... # viper: ignore[reportInvalidTypeForm] if sys.version_info >= (3, 14): def make_dataclass( diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/email/__init__.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/email/__init__.vpi index aabdca32..2523a7b8 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/email/__init__.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/email/__init__.vpi @@ -8,23 +8,23 @@ from typing import IO, TypeAlias, overload # valid, and causes them to be included in a star import. See #6523 __all__ = [ # noqa: F822 # Undefined names in __all__ - "base64mime", # pyright: ignore[reportUnsupportedDunderAll] - "charset", # pyright: ignore[reportUnsupportedDunderAll] - "encoders", # pyright: ignore[reportUnsupportedDunderAll] - "errors", # pyright: ignore[reportUnsupportedDunderAll] - "feedparser", # pyright: ignore[reportUnsupportedDunderAll] - "generator", # pyright: ignore[reportUnsupportedDunderAll] - "header", # pyright: ignore[reportUnsupportedDunderAll] - "iterators", # pyright: ignore[reportUnsupportedDunderAll] - "message", # pyright: ignore[reportUnsupportedDunderAll] + "base64mime", # viper: ignore[reportUnsupportedDunderAll] + "charset", # viper: ignore[reportUnsupportedDunderAll] + "encoders", # viper: ignore[reportUnsupportedDunderAll] + "errors", # viper: ignore[reportUnsupportedDunderAll] + "feedparser", # viper: ignore[reportUnsupportedDunderAll] + "generator", # viper: ignore[reportUnsupportedDunderAll] + "header", # viper: ignore[reportUnsupportedDunderAll] + "iterators", # viper: ignore[reportUnsupportedDunderAll] + "message", # viper: ignore[reportUnsupportedDunderAll] "message_from_file", "message_from_binary_file", "message_from_string", "message_from_bytes", - "mime", # pyright: ignore[reportUnsupportedDunderAll] - "parser", # pyright: ignore[reportUnsupportedDunderAll] - "quoprimime", # pyright: ignore[reportUnsupportedDunderAll] - "utils", # pyright: ignore[reportUnsupportedDunderAll] + "mime", # viper: ignore[reportUnsupportedDunderAll] + "parser", # viper: ignore[reportUnsupportedDunderAll] + "quoprimime", # viper: ignore[reportUnsupportedDunderAll] + "utils", # viper: ignore[reportUnsupportedDunderAll] ] # Definitions imported by multiple submodules in typeshed diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/big5.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/big5.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/big5.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/big5.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/big5hkscs.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/big5hkscs.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/big5hkscs.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/big5hkscs.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/cp932.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/cp932.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/cp932.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/cp932.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/cp949.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/cp949.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/cp949.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/cp949.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/cp950.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/cp950.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/cp950.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/cp950.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/euc_jis_2004.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/euc_jis_2004.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/euc_jis_2004.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/euc_jis_2004.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/euc_jisx0213.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/euc_jisx0213.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/euc_jisx0213.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/euc_jisx0213.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/euc_jp.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/euc_jp.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/euc_jp.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/euc_jp.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/euc_kr.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/euc_kr.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/euc_kr.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/euc_kr.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/gb18030.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/gb18030.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/gb18030.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/gb18030.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/gb2312.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/gb2312.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/gb2312.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/gb2312.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/gbk.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/gbk.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/gbk.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/gbk.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/hz.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/hz.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/hz.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/hz.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_1.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_1.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_1.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_1.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_2.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_2.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_2.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_2.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_2004.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_2004.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_2004.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_2004.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_3.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_3.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_3.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_3.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_ext.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_ext.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_ext.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_jp_ext.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_kr.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_kr.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_kr.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/iso2022_kr.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/johab.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/johab.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/johab.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/johab.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/shift_jis.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/shift_jis.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/shift_jis.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/shift_jis.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/shift_jis_2004.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/shift_jis_2004.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/shift_jis_2004.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/shift_jis_2004.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/shift_jisx0213.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/shift_jisx0213.vpi index d613026a..4c83708c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/shift_jisx0213.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/encodings/shift_jisx0213.vpi @@ -5,8 +5,8 @@ from typing import ClassVar codec: mbc._MultibyteCodec class Codec(codecs.Codec): - encode = codec.encode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] - decode = codec.decode # type: ignore[assignment] # pyright: ignore[reportAssignmentType] + encode = codec.encode # type: ignore[assignment] # viper: ignore[reportAssignmentType] + decode = codec.decode # type: ignore[assignment] # viper: ignore[reportAssignmentType] class IncrementalEncoder(mbc.MultibyteIncrementalEncoder, codecs.IncrementalEncoder): # type: ignore[misc] codec: ClassVar[mbc._MultibyteCodec] = ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/functools.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/functools.vpi index 5619a64f..6f36eb88 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/functools.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/functools.vpi @@ -257,7 +257,7 @@ class cached_property(Generic[_T_co]): def __set_name__(self, owner: type[Any], name: str) -> None: ... # __set__ is not defined at runtime, but @cached_property is designed to be settable - def __set__(self, instance: object, value: _T_co) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def __set__(self, instance: object, value: _T_co) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... def cache(user_function: Callable[..., _T], /) -> _lru_cache_wrapper[_T]: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/logging/__init__.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/logging/__init__.vpi index 8e90a68d..10911d6e 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/logging/__init__.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/logging/__init__.vpi @@ -618,7 +618,7 @@ class StreamHandler(Handler, Generic[_StreamT]): @overload def __init__(self: StreamHandler[TextIO], stream: None = None) -> None: ... @overload - def __init__(self: StreamHandler[_StreamT], stream: _StreamT) -> None: ... # pyright: ignore[reportInvalidTypeVarUse] #11780 + def __init__(self: StreamHandler[_StreamT], stream: _StreamT) -> None: ... # viper: ignore[reportInvalidTypeVarUse] #11780 def setStream(self, stream: _StreamT) -> _StreamT | None: ... if sys.version_info >= (3, 11): diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/os/__init__.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/os/__init__.vpi index 726e9702..2c02a241 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/os/__init__.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/os/__init__.vpi @@ -940,7 +940,7 @@ In the future, this property will contain the last metadata change time.""") # At runtime it inherits from ABC and is not a Protocol, but it will be # on the allowlist for use as a Protocol starting in 3.14. @runtime_checkable -class PathLike(ABC, Protocol[AnyStr_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] +class PathLike(ABC, Protocol[AnyStr_co]): # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] __slots__ = () @abstractmethod def __fspath__(self) -> AnyStr_co: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/pathlib/__init__.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/pathlib/__init__.vpi index ca0d41f6..7890d00b 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/pathlib/__init__.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/pathlib/__init__.vpi @@ -77,7 +77,7 @@ class PurePath(PathLike[str]): def stem(self) -> str: ... if sys.version_info >= (3, 12): def __new__(cls, *args: StrPath, **kwargs: Unused) -> Self: ... - def __init__(self, *args: StrPath) -> None: ... # pyright: ignore[reportInconsistentConstructor] + def __init__(self, *args: StrPath) -> None: ... # viper: ignore[reportInconsistentConstructor] else: def __new__(cls, *args: StrPath) -> Self: ... @@ -158,7 +158,7 @@ class Path(PurePath): __slots__ = () if sys.version_info >= (3, 12): - def __new__(cls, *args: StrPath, **kwargs: Unused) -> Self: ... # pyright: ignore[reportInconsistentConstructor] + def __new__(cls, *args: StrPath, **kwargs: Unused) -> Self: ... # viper: ignore[reportInconsistentConstructor] else: def __new__(cls, *args: StrPath, **kwargs: Unused) -> Self: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/platform.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/platform.vpi index 7d837436..b7b99608 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/platform.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/platform.vpi @@ -40,7 +40,7 @@ class _uname_result_base(NamedTuple): # is lazily evaluated rather than being passed in to the constructor. if sys.version_info >= (3, 12): class uname_result(_uname_result_base): - __match_args__ = ("system", "node", "release", "version", "machine") # pyright: ignore[reportAssignmentType] + __match_args__ = ("system", "node", "release", "version", "machine") # viper: ignore[reportAssignmentType] def __new__(_cls, system: str, node: str, release: str, version: str, machine: str) -> Self: ... @property @@ -49,7 +49,7 @@ if sys.version_info >= (3, 12): else: @disjoint_base class uname_result(_uname_result_base): - __match_args__ = ("system", "node", "release", "version", "machine") # pyright: ignore[reportAssignmentType] + __match_args__ = ("system", "node", "release", "version", "machine") # viper: ignore[reportAssignmentType] def __new__(_cls, system: str, node: str, release: str, version: str, machine: str) -> Self: ... @property def processor(self) -> str: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/ssl.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/ssl.vpi index 590642d9..519ed7f1 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/ssl.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/ssl.vpi @@ -262,8 +262,8 @@ class Purpose(_ASN1Object, enum.Enum): # because this is an enum, the inherited __new__ is replaced at runtime with # Enum.__new__. def __new__(cls, value: object) -> Self: ... - SERVER_AUTH = (129, "serverAuth", "TLS Web Server Authentication", "1.3.6.1.5.5.7.3.2") # pyright: ignore[reportCallIssue] - CLIENT_AUTH = (130, "clientAuth", "TLS Web Client Authentication", "1.3.6.1.5.5.7.3.1") # pyright: ignore[reportCallIssue] + SERVER_AUTH = (129, "serverAuth", "TLS Web Server Authentication", "1.3.6.1.5.5.7.3.2") # viper: ignore[reportCallIssue] + CLIENT_AUTH = (130, "clientAuth", "TLS Web Client Authentication", "1.3.6.1.5.5.7.3.1") # viper: ignore[reportCallIssue] class SSLSocket(socket.socket): context: SSLContext diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/types.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/types.vpi index b9771ffc..42f3dfb6 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/types.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/types.vpi @@ -268,10 +268,10 @@ class CodeType: __replace__ = replace @final -class MappingProxyType(Mapping[_KT_co, _VT_co]): # type: ignore[type-var] # pyright: ignore[reportInvalidTypeArguments] +class MappingProxyType(Mapping[_KT_co, _VT_co]): # type: ignore[type-var] # viper: ignore[reportInvalidTypeArguments] __hash__: ClassVar[None] # type: ignore[assignment] def __new__(cls, mapping: SupportsKeysAndGetItem[_KT_co, _VT_co]) -> Self: ... - def __getitem__(self, key: _KT_co, /) -> _VT_co: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def __getitem__(self, key: _KT_co, /) -> _VT_co: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] def __iter__(self) -> Iterator[_KT_co]: ... def __len__(self) -> int: ... def __eq__(self, value: object, /) -> bool: ... @@ -281,11 +281,11 @@ class MappingProxyType(Mapping[_KT_co, _VT_co]): # type: ignore[type-var] # py def items(self) -> ItemsView[_KT_co, _VT_co]: ... @overload - def get(self, key: _KT_co, /) -> _VT_co | None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter + def get(self, key: _KT_co, /) -> _VT_co | None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] # Covariant type as parameter @overload - def get(self, key: _KT_co, default: _VT_co, /) -> _VT_co: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter + def get(self, key: _KT_co, default: _VT_co, /) -> _VT_co: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] # Covariant type as parameter @overload - def get(self, key: _KT_co, default: _T2, /) -> _VT_co | _T2: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter + def get(self, key: _KT_co, default: _T2, /) -> _VT_co | _T2: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] # Covariant type as parameter def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... def __reversed__(self) -> Iterator[_KT_co]: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/typing.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/typing.vpi index 61439f15..cd191395 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/typing.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/typing.vpi @@ -1,7 +1,7 @@ # Since this module defines "overload" it is not recognized by Ruff as typing.overload # TODO: The collections import is required, otherwise mypy crashes. # https://github.com/python/mypy/issues/16744 -import collections # noqa: F401 # pyright: ignore[reportUnusedImport] +import collections # noqa: F401 # viper: ignore[reportUnusedImport] import sys import typing_extensions from _collections_abc import dict_items, dict_keys, dict_values @@ -814,7 +814,7 @@ class Mapping(Collection[_KT], Generic[_KT, _VT_co]): @overload def get(self, key: _KT, /) -> _VT_co | None: ... @overload - def get(self, key: _KT, default: _VT_co, /) -> _VT_co: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter + def get(self, key: _KT, default: _VT_co, /) -> _VT_co: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] # Covariant type as parameter @overload def get(self, key: _KT, default: _T, /) -> _VT_co | _T: ... @@ -1096,7 +1096,7 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta): # can go through. def setdefault(self, k: _Never, default: object) -> object: ... # Mypy plugin hook for 'pop' expects that 'default' has a type variable type. - def pop(self, k: _Never, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse] + def pop(self, k: _Never, default: _T = ...) -> object: ... # viper: ignore[reportInvalidTypeVarUse] def update(self, m: typing_extensions.Self, /) -> None: ... def __delitem__(self, k: _Never) -> None: ... def items(self) -> dict_items[str, object]: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/typing_extensions.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/typing_extensions.vpi index fdbba495..d0d38547 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/typing_extensions.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/typing_extensions.vpi @@ -251,7 +251,7 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta): # can go through. def setdefault(self, k: Never, default: object) -> object: ... # Mypy plugin hook for 'pop' expects that 'default' has a type variable type. - def pop(self, k: Never, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse] + def pop(self, k: Never, default: _T = ...) -> object: ... # viper: ignore[reportInvalidTypeVarUse] def update(self, m: Self, /) -> None: ... def items(self) -> dict_items[str, object]: ... def keys(self) -> dict_keys[str, object]: ... @@ -381,7 +381,7 @@ else: # At runtime it inherits from ABC and is not a Protocol, but it is on the # allowlist for use as a Protocol. @runtime_checkable - class Buffer(Protocol, abc.ABC): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + class Buffer(Protocol, abc.ABC): # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] # Not actually a Protocol at runtime; see # https://github.com/python/typeshed/issues/10224 for why we're defining it this way def __buffer__(self, flags: int, /) -> memoryview: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/unittest/mock.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/unittest/mock.vpi index 1b6ab756..e477f0a8 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/unittest/mock.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/unittest/mock.vpi @@ -245,7 +245,7 @@ class _patch(Generic[_T]): # If new==DEFAULT, self is _patch[Any]. Ideally we'd be able to add an overload for it so that self is _patch[MagicMock], # but that's impossible with the current type system. def __init__( - self: _patch[_T], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: _patch[_T], # viper: ignore[reportInvalidTypeVarUse] #11780 getter: Callable[[], Any], attribute: str, new: _T, diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/weakref.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/weakref.vpi index 3308ae42..a0cf8319 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/weakref.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/weakref.vpi @@ -78,13 +78,13 @@ class WeakValueDictionary(MutableMapping[_KT, _VT]): def __init__(self) -> None: ... @overload def __init__( - self: WeakValueDictionary[_KT, _VT], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: WeakValueDictionary[_KT, _VT], # viper: ignore[reportInvalidTypeVarUse] #11780 other: Mapping[_KT, _VT] | Iterable[tuple[_KT, _VT]], /, ) -> None: ... @overload def __init__( - self: WeakValueDictionary[str, _VT], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: WeakValueDictionary[str, _VT], # viper: ignore[reportInvalidTypeVarUse] #11780 other: Mapping[str, _VT] | Iterable[tuple[str, _VT]] = (), /, **kwargs: _VT, diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/xml/__init__.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/xml/__init__.vpi index 555d9b8f..c7654e7b 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/xml/__init__.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/xml/__init__.vpi @@ -2,8 +2,8 @@ # valid, and causes them to be included in a star import. See #6523 import sys -__all__ = ["dom", "parsers", "sax", "etree"] # noqa: F822 # pyright: ignore[reportUnsupportedDunderAll] +__all__ = ["dom", "parsers", "sax", "etree"] # noqa: F822 # viper: ignore[reportUnsupportedDunderAll] if sys.version_info >= (3, 15): - __all__ += ["is_valid_name"] # pyright: ignore[reportUnsupportedDunderAll] + __all__ += ["is_valid_name"] # viper: ignore[reportUnsupportedDunderAll] from xml.utils import is_valid_name as is_valid_name, is_valid_text as is_valid_text diff --git a/packages/vipeye-internal/typeshed-fallback/stdlib/xml/dom/minidom.vpi b/packages/vipeye-internal/typeshed-fallback/stdlib/xml/dom/minidom.vpi index c54b0de8..6577b00e 100644 --- a/packages/vipeye-internal/typeshed-fallback/stdlib/xml/dom/minidom.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stdlib/xml/dom/minidom.vpi @@ -128,12 +128,12 @@ class Node(xml.dom.Node): def hasChildNodes(self) -> bool: ... def insertBefore( # type: ignore[misc] - self: _NodesWithChildren, # pyright: ignore[reportGeneralTypeIssues] + self: _NodesWithChildren, # viper: ignore[reportGeneralTypeIssues] newChild: _ChildNodePlusFragmentVar, refChild: _NodesThatAreChildren | None, ) -> _ChildNodePlusFragmentVar: ... def appendChild( # type: ignore[misc] - self: _NodesWithChildren, node: _ChildNodePlusFragmentVar # pyright: ignore[reportGeneralTypeIssues] + self: _NodesWithChildren, node: _ChildNodePlusFragmentVar # viper: ignore[reportGeneralTypeIssues] ) -> _ChildNodePlusFragmentVar: ... @overload @@ -145,8 +145,8 @@ class Node(xml.dom.Node): self: _NodesWithChildren, newChild: _NodesThatAreChildren, oldChild: _ChildNodeVar ) -> _ChildNodeVar | None: ... - def removeChild(self: _NodesWithChildren, oldChild: _ChildNodeVar) -> _ChildNodeVar: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - def normalize(self: _NodesWithChildren) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def removeChild(self: _NodesWithChildren, oldChild: _ChildNodeVar) -> _ChildNodeVar: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] + def normalize(self: _NodesWithChildren) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] def cloneNode(self, deep: bool) -> Self | None: ... def isSupported(self, feature: str, version: str | None) -> bool: ... def isSameNode(self, other: Node) -> bool: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/Flask-Migrate/flask_migrate/__init__.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/Flask-Migrate/flask_migrate/__init__.vpi index b9235daf..5a2a1804 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/Flask-Migrate/flask_migrate/__init__.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/Flask-Migrate/flask_migrate/__init__.vpi @@ -1,4 +1,4 @@ -# pyright: reportInvalidStubStatement=none +# viper: reportInvalidStubStatement=none import sys from _typeshed import StrPath, SupportsFlush, SupportsKeysAndGetItem, SupportsWrite diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/JACK-Client/jack/__init__.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/JACK-Client/jack/__init__.vpi index 95d6e485..c919580f 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/JACK-Client/jack/__init__.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/JACK-Client/jack/__init__.vpi @@ -12,7 +12,7 @@ from numpy.typing import NDArray # This is not a real subclassing. Just ensuring type-checkers sees this type as compatible with _CDataBase # pyright has no error code for subclassing final @type_check_only -class _JackPositionT(_CDataBase): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] +class _JackPositionT(_CDataBase): # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] audio_frames_per_video_frame: float bar: int bar_start_tick: float diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/WTForms/wtforms/fields/form.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/WTForms/wtforms/fields/form.vpi index 16b7e201..79453f99 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/WTForms/wtforms/fields/form.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/WTForms/wtforms/fields/form.vpi @@ -14,7 +14,7 @@ class FormField(Field, Generic[_BoundFormT]): form: _BoundFormT separator: str def __init__( - self: FormField[_BoundFormT], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: FormField[_BoundFormT], # viper: ignore[reportInvalidTypeVarUse] #11780 form_class: type[_BoundFormT], label: str | None = None, validators: None = None, diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/WTForms/wtforms/fields/list.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/WTForms/wtforms/fields/list.vpi index 2142009c..b491238c 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/WTForms/wtforms/fields/list.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/WTForms/wtforms/fields/list.vpi @@ -22,7 +22,7 @@ class FieldList(Field, Generic[_BoundFieldT]): # but it might not be worth the hassle, for now we'll just leave it lax errors: Sequence[Any] def __init__( - self: FieldList[_BoundFieldT], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: FieldList[_BoundFieldT], # viper: ignore[reportInvalidTypeVarUse] #11780 # because of our workaround we need to accept Field as well unbound_field: UnboundField[_BoundFieldT] | _BoundFieldT, label: str | None = None, diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/WebOb/webob/dec.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/WebOb/webob/dec.vpi index b8f58a69..285633df 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/WebOb/webob/dec.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/WebOb/webob/dec.vpi @@ -46,7 +46,7 @@ class wsgify(Generic[_P, _RequestT_contra]): ) -> None: ... @overload def __init__( - self: wsgify[[], _RequestT_contra], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: wsgify[[], _RequestT_contra], # viper: ignore[reportInvalidTypeVarUse] #11780 func: _RequestHandler[_RequestT_contra, []] | None, RequestClass: type[_RequestT_contra], args: tuple[()] = (), @@ -55,7 +55,7 @@ class wsgify(Generic[_P, _RequestT_contra]): ) -> None: ... @overload def __init__( - self: wsgify[[], _RequestT_contra], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: wsgify[[], _RequestT_contra], # viper: ignore[reportInvalidTypeVarUse] #11780 func: _RequestHandler[_RequestT_contra, []] | None = None, *, RequestClass: type[_RequestT_contra], @@ -75,7 +75,7 @@ class wsgify(Generic[_P, _RequestT_contra]): ) -> None: ... @overload def __init__( - self: wsgify[[_AppT_contra], _RequestT_contra], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: wsgify[[_AppT_contra], _RequestT_contra], # viper: ignore[reportInvalidTypeVarUse] #11780 func: _Middleware[_RequestT_contra, _AppT_contra, []] | None, RequestClass: type[_RequestT_contra], args: tuple[()] = (), @@ -85,7 +85,7 @@ class wsgify(Generic[_P, _RequestT_contra]): ) -> None: ... @overload def __init__( - self: wsgify[[_AppT_contra], _RequestT_contra], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: wsgify[[_AppT_contra], _RequestT_contra], # viper: ignore[reportInvalidTypeVarUse] #11780 func: _Middleware[_RequestT_contra, _AppT_contra, []] | None = None, *, RequestClass: type[_RequestT_contra], diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/WebOb/webob/multidict.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/WebOb/webob/multidict.vpi index 4272d219..d2f8f029 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/WebOb/webob/multidict.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/WebOb/webob/multidict.vpi @@ -22,12 +22,12 @@ class MultiDict(MutableMapping[_KT, _VT]): @overload def __init__(self) -> None: ... @overload - def __init__(self: MultiDict[str, _VT], **kwargs: _VT) -> None: ... # pyright: ignore[reportInvalidTypeVarUse] #11780 + def __init__(self: MultiDict[str, _VT], **kwargs: _VT) -> None: ... # viper: ignore[reportInvalidTypeVarUse] #11780 @overload def __init__(self, m: _SupportsItemsWithIterableResult[_KT, _VT], /) -> None: ... @overload def __init__( - self: MultiDict[str, _VT], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: MultiDict[str, _VT], # viper: ignore[reportInvalidTypeVarUse] #11780 m: _SupportsItemsWithIterableResult[str, _VT], /, **kwargs: _VT, @@ -36,7 +36,7 @@ class MultiDict(MutableMapping[_KT, _VT]): def __init__(self, m: Iterable[tuple[_KT, _VT]], /) -> None: ... @overload def __init__( - self: MultiDict[str, _VT], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: MultiDict[str, _VT], # viper: ignore[reportInvalidTypeVarUse] #11780 m: Iterable[tuple[str, _VT]], /, **kwargs: _VT, diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/geopandas/geopandas/explore.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/geopandas/geopandas/explore.vpi index 1ecd3a1c..09eaa439 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/geopandas/geopandas/explore.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/geopandas/geopandas/explore.vpi @@ -1,10 +1,10 @@ from collections.abc import Callable, Hashable, MutableMapping, Sequence from typing import Any -import branca # type: ignore[import-not-found] # pyright: ignore[reportMissingImports] -import folium # type: ignore[import-not-found] # pyright: ignore[reportMissingImports] +import branca # type: ignore[import-not-found] # viper: ignore[reportMissingImports] +import folium # type: ignore[import-not-found] # viper: ignore[reportMissingImports] import pandas as pd -import xyzservices # type: ignore[import-not-found] # pyright: ignore[reportMissingImports] +import xyzservices # type: ignore[import-not-found] # viper: ignore[reportMissingImports] from matplotlib.colors import Colormap # type: ignore[import-not-found] from numpy.typing import ArrayLike, NDArray diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/geopandas/geopandas/geodataframe.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/geopandas/geopandas/geodataframe.vpi index 9e672c5a..31f8694a 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/geopandas/geopandas/geodataframe.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/geopandas/geopandas/geodataframe.vpi @@ -339,7 +339,7 @@ class GeoDataFrame(GeoPandasBase, pd.DataFrame): # type: ignore[misc] ) -> None: ... @property def plot(self) -> GeoplotAccessor: ... - @doc(_explore) # pyright: ignore[reportUnknownArgumentType] + @doc(_explore) # viper: ignore[reportUnknownArgumentType] def explore(self, *args, **kwargs): ... # signature of `_explore` copied in `@doc` def sjoin( self, diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/geopandas/geopandas/geoseries.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/geopandas/geopandas/geoseries.vpi index 8e1a23f1..b758dca9 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/geopandas/geopandas/geoseries.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/geopandas/geopandas/geoseries.vpi @@ -19,7 +19,7 @@ from .explore import _explore_geoseries from .io._geoarrow import GeoArrowArray from .plotting import plot_series -class GeoSeries(GeoPandasBase, pd.Series[BaseGeometry]): # type: ignore[type-var,misc] # pyright: ignore[reportInvalidTypeArguments] +class GeoSeries(GeoPandasBase, pd.Series[BaseGeometry]): # type: ignore[type-var,misc] # viper: ignore[reportInvalidTypeArguments] # Override the weird annotation of Series.__new__ in pandas-stubs def __new__( self, @@ -159,7 +159,7 @@ class GeoSeries(GeoPandasBase, pd.Series[BaseGeometry]): # type: ignore[type-va def __contains__(self, other: object) -> bool: ... # type: ignore[misc] @doc(plot_series) def plot(self, *args, **kwargs): ... # type: ignore[override] # signature of `plot_series` copied in `@doc` - @doc(_explore_geoseries) # pyright: ignore[reportUnknownArgumentType] + @doc(_explore_geoseries) # viper: ignore[reportUnknownArgumentType] def explore(self, *args, **kwargs): ... # signature of `_explore_geoseries` copied in `@doc` def explode(self, ignore_index: bool = False, index_parts: bool = False) -> GeoSeries: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/geopandas/geopandas/plotting.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/geopandas/geopandas/plotting.vpi index b24d213f..52044843 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/geopandas/geopandas/plotting.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/geopandas/geopandas/plotting.vpi @@ -193,7 +193,7 @@ class GeoplotAccessor(PlotAccessor): include_bool: bool = False, backend: str | None = None, **kwargs, - ) -> pd.Series[Axes]: ... # type: ignore[type-var] # pyright: ignore[reportInvalidTypeArguments] + ) -> pd.Series[Axes]: ... # type: ignore[type-var] # viper: ignore[reportInvalidTypeArguments] @overload def __call__( self, diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/gevent/gevent/_fileobjectcommon.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/gevent/gevent/_fileobjectcommon.vpi index 3aba7454..33ca8541 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/gevent/gevent/_fileobjectcommon.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/gevent/gevent/_fileobjectcommon.vpi @@ -82,7 +82,7 @@ class OpenDescriptor(Generic[_IOT]): class FileObjectBase(Generic[_IOT, AnyStr]): def __init__( - self: FileObjectBase[_IOT, AnyStr], descriptor: OpenDescriptor[_IOT] # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: FileObjectBase[_IOT, AnyStr], descriptor: OpenDescriptor[_IOT] # viper: ignore[reportInvalidTypeVarUse] #11780 ) -> None: ... io: _IOT @property diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/gevent/gevent/_util.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/gevent/gevent/_util.vpi index d0f6df62..31872764 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/gevent/gevent/_util.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/gevent/gevent/_util.vpi @@ -37,7 +37,7 @@ class Lazy(Generic[_T]): class readproperty(Generic[_T]): func: Callable[[Any], _T] def __init__( - self: readproperty[_T], func: Callable[[Any], _T] # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: readproperty[_T], func: Callable[[Any], _T] # viper: ignore[reportInvalidTypeVarUse] #11780 ) -> None: ... @overload diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/gevent/gevent/greenlet.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/gevent/gevent/greenlet.vpi index e6551f06..aadb8aaa 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/gevent/gevent/greenlet.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/gevent/gevent/greenlet.vpi @@ -22,7 +22,7 @@ class Greenlet(greenlet.greenlet, Generic[_P, _T]): @overload def __init__( - self: Greenlet[_P, _T], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: Greenlet[_P, _T], # viper: ignore[reportInvalidTypeVarUse] #11780 run: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs, diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/gunicorn/gunicorn/config.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/gunicorn/gunicorn/config.vpi index 8a864020..11f420f5 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/gunicorn/gunicorn/config.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/gunicorn/gunicorn/config.vpi @@ -782,7 +782,7 @@ class OnStarting(Setting): default: ClassVar[_OnStartingHookType] desc: ClassVar[str] - def on_starting(server: Arbiter) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def on_starting(server: Arbiter) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class OnReload(Setting): name: ClassVar[str] @@ -792,7 +792,7 @@ class OnReload(Setting): default: ClassVar[_OnReloadHookType] desc: ClassVar[str] - def on_reload(server: Arbiter) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def on_reload(server: Arbiter) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class WhenReady(Setting): name: ClassVar[str] @@ -802,7 +802,7 @@ class WhenReady(Setting): default: ClassVar[_WhenReadyHookType] desc: ClassVar[str] - def when_ready(server: Arbiter) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def when_ready(server: Arbiter) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class Prefork(Setting): name: ClassVar[str] @@ -812,7 +812,7 @@ class Prefork(Setting): default: ClassVar[_PreForkHookType] desc: ClassVar[str] - def pre_fork(server: Arbiter, worker: Worker) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def pre_fork(server: Arbiter, worker: Worker) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class Postfork(Setting): name: ClassVar[str] @@ -822,7 +822,7 @@ class Postfork(Setting): default: ClassVar[_PostForkHookType] desc: ClassVar[str] - def post_fork(server: Arbiter, worker: Worker) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def post_fork(server: Arbiter, worker: Worker) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class PostWorkerInit(Setting): name: ClassVar[str] @@ -832,7 +832,7 @@ class PostWorkerInit(Setting): default: ClassVar[_PostWorkerInitHookType] desc: ClassVar[str] - def post_worker_init(worker: Worker) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def post_worker_init(worker: Worker) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class WorkerInt(Setting): name: ClassVar[str] @@ -842,7 +842,7 @@ class WorkerInt(Setting): default: ClassVar[_WorkerIntHookType] desc: ClassVar[str] - def worker_int(worker: Worker) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def worker_int(worker: Worker) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class WorkerAbort(Setting): name: ClassVar[str] @@ -852,7 +852,7 @@ class WorkerAbort(Setting): default: ClassVar[_WorkerAbortHookType] desc: ClassVar[str] - def worker_abort(worker: Worker) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def worker_abort(worker: Worker) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class PreExec(Setting): name: ClassVar[str] @@ -862,7 +862,7 @@ class PreExec(Setting): default: ClassVar[_PreExecHookType] desc: ClassVar[str] - def pre_exec(server: Arbiter) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def pre_exec(server: Arbiter) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class PreRequest(Setting): name: ClassVar[str] @@ -872,7 +872,7 @@ class PreRequest(Setting): default: ClassVar[_PreRequestHookType] desc: ClassVar[str] - def pre_request(worker: Worker, req: Request) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def pre_request(worker: Worker, req: Request) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class PostRequest(Setting): name: ClassVar[str] @@ -882,7 +882,7 @@ class PostRequest(Setting): default: ClassVar[_PostRequestHookType] desc: ClassVar[str] - def post_request(worker: Worker, req: Request, environ: _EnvironType, resp: Response) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def post_request(worker: Worker, req: Request, environ: _EnvironType, resp: Response) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class ChildExit(Setting): name: ClassVar[str] @@ -892,7 +892,7 @@ class ChildExit(Setting): default: ClassVar[_ChildExitHookType] desc: ClassVar[str] - def child_exit(server: Arbiter, worker: Worker) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def child_exit(server: Arbiter, worker: Worker) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class WorkerExit(Setting): name: ClassVar[str] @@ -902,7 +902,7 @@ class WorkerExit(Setting): default: ClassVar[_WorkerExitHookType] desc: ClassVar[str] - def worker_exit(server: Arbiter, worker: Worker) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def worker_exit(server: Arbiter, worker: Worker) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class NumWorkersChanged(Setting): name: ClassVar[str] @@ -912,7 +912,7 @@ class NumWorkersChanged(Setting): default: ClassVar[_NumWorkersChangedHookType] desc: ClassVar[str] - def nworkers_changed(server: Arbiter, new_value: int, old_value: int | None) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def nworkers_changed(server: Arbiter, new_value: int, old_value: int | None) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class OnExit(Setting): name: ClassVar[str] @@ -921,7 +921,7 @@ class OnExit(Setting): default: ClassVar[_OnExitHookType] desc: ClassVar[str] - def on_exit(server: Arbiter) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def on_exit(server: Arbiter) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class NewSSLContext(Setting): name: ClassVar[str] @@ -931,7 +931,7 @@ class NewSSLContext(Setting): default: ClassVar[_SSLContextHookType] desc: ClassVar[str] - def ssl_context(config: Config, default_ssl_context_factory: Callable[[], SSLContext]) -> SSLContext: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def ssl_context(config: Config, default_ssl_context_factory: Callable[[], SSLContext]) -> SSLContext: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] def validate_proxy_protocol(val: str | bool | None) -> str: ... @@ -1273,7 +1273,7 @@ class OnDirtyStarting(Setting): default: ClassVar[_OnDirtyStartingHookType] desc: ClassVar[str] - def on_dirty_starting(arbiter: Arbiter) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def on_dirty_starting(arbiter: Arbiter) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class DirtyPostFork(Setting): name: ClassVar[str] @@ -1283,7 +1283,7 @@ class DirtyPostFork(Setting): default: ClassVar[_DirtyPostForkHookType] desc: ClassVar[str] - def dirty_post_fork(arbiter: Arbiter, worker: Worker) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def dirty_post_fork(arbiter: Arbiter, worker: Worker) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class DirtyWorkerInit(Setting): name: ClassVar[str] @@ -1293,7 +1293,7 @@ class DirtyWorkerInit(Setting): default: ClassVar[_DirtyWorkerInitHookType] desc: ClassVar[str] - def dirty_worker_init(worker: Worker) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def dirty_worker_init(worker: Worker) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class DirtyWorkerExit(Setting): name: ClassVar[str] @@ -1303,7 +1303,7 @@ class DirtyWorkerExit(Setting): default: ClassVar[_DirtyWorkerExitHookType] desc: ClassVar[str] - def dirty_worker_exit(arbiter: Arbiter, worker: Worker) -> None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def dirty_worker_exit(arbiter: Arbiter, worker: Worker) -> None: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] class ControlSocket(Setting): name: ClassVar[str] diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/jwcrypto/jwcrypto/jwk.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/jwcrypto/jwcrypto/jwk.vpi index 5cdd0bcc..512eb541 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/jwcrypto/jwcrypto/jwk.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/jwcrypto/jwcrypto/jwk.vpi @@ -51,7 +51,7 @@ _JWKKeyTypeSupported: TypeAlias = Literal["oct", "RSA", "EC", "OKP"] JWKTypesRegistry: dict[_JWKKeyTypeSupported, str] class ParmType(Enum): - name = "A string with a name" # pyright: ignore[reportAssignmentType] + name = "A string with a name" # viper: ignore[reportAssignmentType] b64 = "Base64url Encoded" b64u = "Base64urlUint Encoded" unsupported = "Unsupported Parameter" diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/mock/mock/mock.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/mock/mock/mock.vpi index 8ec149dd..92f4819b 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/mock/mock/mock.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/mock/mock/mock.vpi @@ -165,7 +165,7 @@ class _patch(Generic[_T]): kwargs: Mapping[str, Any] additional_patchers: Any def __init__( - self: _patch[_T], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: _patch[_T], # viper: ignore[reportInvalidTypeVarUse] #11780 getter: Callable[[], Any], attribute: str, new: _T, diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/mypy-extensions/mypy_extensions.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/mypy-extensions/mypy_extensions.vpi index 75721bf1..450120f3 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/mypy-extensions/mypy_extensions.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/mypy-extensions/mypy_extensions.vpi @@ -21,7 +21,7 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta): # can go through. def setdefault(self, k: Never, default: object) -> object: ... # Mypy plugin hook for 'pop' expects that 'default' has a type variable type. - def pop(self, k: Never, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse] + def pop(self, k: Never, default: _T = ...) -> object: ... # viper: ignore[reportInvalidTypeVarUse] def update(self, m: Self, /) -> None: ... def items(self) -> dict_items[str, object]: ... def keys(self) -> dict_keys[str, object]: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/drawing/nx_agraph.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/drawing/nx_agraph.vpi index d3de4c55..836b6f2e 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/drawing/nx_agraph.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/drawing/nx_agraph.vpi @@ -4,7 +4,7 @@ from typing import IO, Any, Protocol, TypeVar, type_check_only from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable -from pygraphviz.agraph import AGraph # type: ignore[import-not-found] # pyright: ignore[reportMissingImports] +from pygraphviz.agraph import AGraph # type: ignore[import-not-found] # viper: ignore[reportMissingImports] __all__ = ["from_agraph", "to_agraph", "write_dot", "read_dot", "graphviz_layout", "pygraphviz_layout", "view_pygraphviz"] diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/drawing/nx_pydot.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/drawing/nx_pydot.vpi index fa0cb03f..f780bfcd 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/drawing/nx_pydot.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/drawing/nx_pydot.vpi @@ -4,7 +4,7 @@ from typing import Any from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable -from pydot import Dot # type: ignore[import-not-found] # pyright: ignore[reportMissingImports] +from pydot import Dot # type: ignore[import-not-found] # viper: ignore[reportMissingImports] __all__ = ["write_dot", "read_dot", "graphviz_layout", "pydot_layout", "to_pydot", "from_pydot"] diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/linalg/attrmatrix.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/linalg/attrmatrix.vpi index 90b19c23..76ff509a 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/linalg/attrmatrix.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/linalg/attrmatrix.vpi @@ -6,7 +6,7 @@ from networkx._typing import Array2D from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable from numpy.typing import DTypeLike -from scipy.sparse import lil_array # type: ignore[import-untyped] # pyright: ignore[reportMissingImports] +from scipy.sparse import lil_array # type: ignore[import-untyped] # viper: ignore[reportMissingImports] __all__ = ["attr_matrix", "attr_sparse_matrix"] diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/linalg/bethehessianmatrix.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/linalg/bethehessianmatrix.vpi index 6cc9100b..4eec6f65 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/linalg/bethehessianmatrix.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/linalg/bethehessianmatrix.vpi @@ -2,7 +2,7 @@ from collections.abc import Collection from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable -from scipy.sparse import csr_array # type: ignore[import-untyped] # pyright: ignore[reportMissingImports] +from scipy.sparse import csr_array # type: ignore[import-untyped] # viper: ignore[reportMissingImports] __all__ = ["bethe_hessian_matrix"] diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/linalg/graphmatrix.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/linalg/graphmatrix.vpi index 7d087617..6552cacf 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/linalg/graphmatrix.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/linalg/graphmatrix.vpi @@ -3,7 +3,7 @@ from collections.abc import Collection, Hashable from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable from numpy.typing import DTypeLike -from scipy.sparse import csc_array, csr_array # type: ignore[import-untyped] # pyright: ignore[reportMissingImports] +from scipy.sparse import csc_array, csr_array # type: ignore[import-untyped] # viper: ignore[reportMissingImports] __all__ = ["incidence_matrix", "adjacency_matrix"] diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/linalg/laplacianmatrix.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/linalg/laplacianmatrix.vpi index 089d3190..4bed338f 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/linalg/laplacianmatrix.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/networkx/networkx/linalg/laplacianmatrix.vpi @@ -6,7 +6,7 @@ from networkx._typing import Array2D from networkx.classes.digraph import DiGraph from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable -from scipy.sparse import csr_array # type: ignore[import-untyped] # pyright: ignore[reportMissingImports] +from scipy.sparse import csr_array # type: ignore[import-untyped] # viper: ignore[reportMissingImports] __all__ = [ "laplacian_matrix", diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/openpyxl/openpyxl/descriptors/base.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/openpyxl/openpyxl/descriptors/base.vpi index 5636a3b2..8096a2b9 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/openpyxl/openpyxl/descriptors/base.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/openpyxl/openpyxl/descriptors/base.vpi @@ -35,7 +35,7 @@ class Typed(Descriptor[_T], Generic[_T, _N]): @overload def __init__( - self: Typed[_T, Literal[True]], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: Typed[_T, Literal[True]], # viper: ignore[reportInvalidTypeVarUse] #11780 name: str | None = None, *, expected_type: _ExpectedTypeParam[_T], @@ -44,7 +44,7 @@ class Typed(Descriptor[_T], Generic[_T, _N]): ) -> None: ... @overload def __init__( - self: Typed[_T, Literal[False]], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: Typed[_T, Literal[False]], # viper: ignore[reportInvalidTypeVarUse] #11780 name: str | None = None, *, expected_type: _ExpectedTypeParam[_T], @@ -65,7 +65,7 @@ class Typed(Descriptor[_T], Generic[_T, _N]): class Convertible(Typed[_T, _N]): @overload def __init__( - self: Convertible[_T, Literal[True]], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: Convertible[_T, Literal[True]], # viper: ignore[reportInvalidTypeVarUse] #11780 name: str | None = None, *, expected_type: _ExpectedTypeParam[_T], @@ -73,7 +73,7 @@ class Convertible(Typed[_T, _N]): ) -> None: ... @overload def __init__( - self: Convertible[_T, Literal[False]], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: Convertible[_T, Literal[False]], # viper: ignore[reportInvalidTypeVarUse] #11780 name: str | None = None, *, expected_type: _ExpectedTypeParam[_T], diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/openpyxl/openpyxl/descriptors/nested.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/openpyxl/openpyxl/descriptors/nested.vpi index 44d98a3e..a353365f 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/openpyxl/openpyxl/descriptors/nested.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/openpyxl/openpyxl/descriptors/nested.vpi @@ -24,7 +24,7 @@ class Nested(Descriptor[_T]): namespace: str | None # In usage, "Nested" is closed to "Typed" than "Descriptor", but doesn't use allow_none def __init__( - self: Nested[_T], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: Nested[_T], # viper: ignore[reportInvalidTypeVarUse] #11780 name: str | None = None, *, expected_type: _ExpectedTypeParam[_T], @@ -44,7 +44,7 @@ class Nested(Descriptor[_T]): class NestedValue(Nested[_T], Convertible[_T, _N]): # type: ignore[misc] @overload def __init__( - self: NestedValue[_T, Literal[True]], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: NestedValue[_T, Literal[True]], # viper: ignore[reportInvalidTypeVarUse] #11780 name: str | None = None, *, expected_type: _ExpectedTypeParam[_T], @@ -52,7 +52,7 @@ class NestedValue(Nested[_T], Convertible[_T, _N]): # type: ignore[misc] ) -> None: ... @overload def __init__( - self: NestedValue[_T, Literal[False]], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: NestedValue[_T, Literal[False]], # viper: ignore[reportInvalidTypeVarUse] #11780 name: str | None = None, *, expected_type: _ExpectedTypeParam[_T], @@ -117,7 +117,7 @@ class NestedValue(Nested[_T], Convertible[_T, _N]): # type: ignore[misc] class NestedText(NestedValue[_T, _N]): @overload def __init__( - self: NestedText[_T, Literal[True]], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: NestedText[_T, Literal[True]], # viper: ignore[reportInvalidTypeVarUse] #11780 name: str | None = None, *, expected_type: _ExpectedTypeParam[_T], @@ -125,7 +125,7 @@ class NestedText(NestedValue[_T, _N]): ) -> None: ... @overload def __init__( - self: NestedText[_T, Literal[False]], # pyright: ignore[reportInvalidTypeVarUse] #11780 + self: NestedText[_T, Literal[False]], # viper: ignore[reportInvalidTypeVarUse] #11780 name: str | None = None, *, expected_type: _ExpectedTypeParam[_T], diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/pika/pika/adapters/twisted_connection.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/pika/pika/adapters/twisted_connection.vpi index 9d8d90ef..aaa8ea8d 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/pika/pika/adapters/twisted_connection.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/pika/pika/adapters/twisted_connection.vpi @@ -7,14 +7,14 @@ from logging import Logger from typing import Any, Generic, NamedTuple, TypeVar from pika.adapters.utils.nbio_interface import AbstractTimerReference -from twisted.internet.base import DelayedCall # type: ignore[import-not-found] # pyright: ignore[reportMissingImports] -from twisted.internet.defer import ( # type: ignore[import-not-found] # pyright: ignore[reportMissingImports] +from twisted.internet.base import DelayedCall # type: ignore[import-not-found] # viper: ignore[reportMissingImports] +from twisted.internet.defer import ( # type: ignore[import-not-found] # viper: ignore[reportMissingImports] Deferred, DeferredQueue, ) -from twisted.internet.interfaces import ITransport # type: ignore[import-not-found] # pyright: ignore[reportMissingImports] -from twisted.internet.protocol import Protocol # type: ignore[import-not-found] # pyright: ignore[reportMissingImports] -from twisted.python.failure import Failure # type: ignore[import-not-found] # pyright: ignore[reportMissingImports] +from twisted.internet.interfaces import ITransport # type: ignore[import-not-found] # viper: ignore[reportMissingImports] +from twisted.internet.protocol import Protocol # type: ignore[import-not-found] # viper: ignore[reportMissingImports] +from twisted.python.failure import Failure # type: ignore[import-not-found] # viper: ignore[reportMissingImports] from ..connection import Connection, Parameters @@ -22,7 +22,7 @@ _T = TypeVar("_T") LOGGER: Logger -class ClosableDeferredQueue(DeferredQueue[_T], Generic[_T]): # pyright: ignore[reportUntypedBaseClass] # noqa: Y060 +class ClosableDeferredQueue(DeferredQueue[_T], Generic[_T]): # viper: ignore[reportUntypedBaseClass] # noqa: Y060 closed: Failure | BaseException | None def __init__(self, size: Incomplete | None = ..., backlog: Incomplete | None = ...) -> None: ... # Returns a Deferred with an error if fails. None if success @@ -135,7 +135,7 @@ class _TwistedConnectionAdapter(Connection): def connection_lost(self, error: Exception) -> None: ... def data_received(self, data) -> None: ... -class TwistedProtocolConnection(Protocol): # pyright: ignore[reportUntypedBaseClass] +class TwistedProtocolConnection(Protocol): # viper: ignore[reportUntypedBaseClass] ready: Deferred[None] | None closed: Deferred[None] | Failure | BaseException | None def __init__(self, parameters: Incomplete | None = ..., custom_reactor: Incomplete | None = ...) -> None: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/protobuf/google/protobuf/descriptor_pool.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/protobuf/google/protobuf/descriptor_pool.vpi index 59767efd..f6daaf13 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/protobuf/google/protobuf/descriptor_pool.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/protobuf/google/protobuf/descriptor_pool.vpi @@ -15,7 +15,7 @@ from .descriptor_pb2 import FeatureSetDefaults, FileDescriptorProto class DescriptorPool: def __new__(cls, descriptor_db: Any = None) -> Self: ... - def __init__( # pyright: ignore[reportInconsistentConstructor] + def __init__( # viper: ignore[reportInconsistentConstructor] self, descriptor_db: Any = None, use_deprecated_legacy_json_field_conflicts: Unused = False ) -> None: ... def Add(self, file_desc_proto: FileDescriptorProto) -> None: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/pyasn1/pyasn1/type/base.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/pyasn1/pyasn1/type/base.vpi index ab443c19..b3fb08a2 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/pyasn1/pyasn1/type/base.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/pyasn1/pyasn1/type/base.vpi @@ -64,7 +64,7 @@ class NoValue: __imul__ = list.__imul__ __index__ = int.__index__ # self instead of cls - __init_subclass__ = plug # pyright: ignore[reportAssignmentType] + __init_subclass__ = plug # viper: ignore[reportAssignmentType] __int__ = int.__int__ __invert__ = int.__invert__ __ior__ = plug diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/reportlab/reportlab/lib/rl_safe_eval.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/reportlab/reportlab/lib/rl_safe_eval.vpi index be8a719e..3eb36170 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/reportlab/reportlab/lib/rl_safe_eval.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/reportlab/reportlab/lib/rl_safe_eval.vpi @@ -56,7 +56,7 @@ class UntrustedAstTransformer(ast.NodeTransformer): def visit_ClassDef(self, node) -> ast.stmt: ... def visit_Import(self, node) -> ast.AST: ... def visit_BinOp(self, node): ... - visit_ImportFrom = visit_Import # pyright: ignore[reportAssignmentType] + visit_ImportFrom = visit_Import # viper: ignore[reportAssignmentType] visit_For = guard_iter visit_comprehension = guard_iter def generic_visit(self, node: ast.AST) -> None: ... # type: ignore[override] diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/uWSGI/uwsgidecorators.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/uWSGI/uwsgidecorators.vpi index 5c8029f3..7b94dffa 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/uWSGI/uwsgidecorators.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/uWSGI/uwsgidecorators.vpi @@ -28,7 +28,7 @@ class postfork(Generic[_P, _T]): @overload def __init__(self: postfork[..., Any], f: int) -> None: ... @overload - def __init__(self: postfork[_P, _T], f: Callable[_P, _T]) -> None: ... # pyright: ignore[reportInvalidTypeVarUse] #11780 + def __init__(self: postfork[_P, _T], f: Callable[_P, _T]) -> None: ... # viper: ignore[reportInvalidTypeVarUse] #11780 @overload def __call__(self, f: Callable[_P2, _T2], /) -> postfork[_P2, _T2]: ... @@ -77,7 +77,7 @@ class mulefunc(Generic[_P, _T]): @overload def __init__(self: mulefunc[..., Any], f: int) -> None: ... @overload - def __init__(self: mulefunc[_P, _T], f: Callable[_P, _T]) -> None: ... # pyright: ignore[reportInvalidTypeVarUse] #11780 + def __init__(self: mulefunc[_P, _T], f: Callable[_P, _T]) -> None: ... # viper: ignore[reportInvalidTypeVarUse] #11780 def real_call(self, *args: _P.args, **kwargs: _P.kwargs) -> None: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/workalendar/workalendar/europe/scotland/mixins/__init__.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/workalendar/workalendar/europe/scotland/mixins/__init__.vpi index 0c07a387..0ee05ded 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/workalendar/workalendar/europe/scotland/mixins/__init__.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/workalendar/workalendar/europe/scotland/mixins/__init__.vpi @@ -49,7 +49,7 @@ __all__ = [ "SpringHolidayFirstMondayJune", "VictoriaDayFourthMondayMay", "VictoriaDayLastMondayMay", - "VictoriaDayTuesdayAfterFirstMondayMay", # noqa: F822 # pyright: ignore[reportUnsupportedDunderAll] see https://github.com/workalendar/workalendar/pull/778 + "VictoriaDayTuesdayAfterFirstMondayMay", # noqa: F822 # viper: ignore[reportUnsupportedDunderAll] see https://github.com/workalendar/workalendar/pull/778 "VictoriaDayFirstMondayJune", "FairHolidayLastMondayJune", "FairHolidayFirstMondayJuly", diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/xlrd/xlrd/formula.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/xlrd/xlrd/formula.vpi index 4082010b..0594d8f8 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/xlrd/xlrd/formula.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/xlrd/xlrd/formula.vpi @@ -63,7 +63,7 @@ class Ref3D(tuple[int, int, int, int, int, int, int, int, int, int, int, int]): rowxhi: int colxlo: int colxhi: int - def __init__( # pyright: ignore[reportInconsistentConstructor] + def __init__( # viper: ignore[reportInconsistentConstructor] self, atuple: tuple[int, int, int, int, int, int, int, int, int, int, int, int] ) -> None: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/yt-dlp/yt_dlp/downloader/common.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/yt-dlp/yt_dlp/downloader/common.vpi index 80e60660..93366ee5 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/yt-dlp/yt_dlp/downloader/common.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/yt-dlp/yt_dlp/downloader/common.vpi @@ -67,7 +67,7 @@ class FileDownloader: def undo_temp_name(self, filename: str) -> str: ... def ytdl_filename(self, filename: str) -> str: ... # Wrapper that can accept arbitrary function. - def wrap_file_access(action: str, *, fatal: bool = False) -> Any: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def wrap_file_access(action: str, *, fatal: bool = False) -> Any: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] def sanitize_open(self, filename: str, open_mode: OpenTextMode | OpenBinaryMode) -> tuple[IO[Any], str]: ... def try_remove(self, filename: str) -> None: ... def try_rename(self, old_filename: str, new_filename: str) -> None: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/yt-dlp/yt_dlp/extractor/common.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/yt-dlp/yt_dlp/extractor/common.vpi index ece23745..6e534bae 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/yt-dlp/yt_dlp/extractor/common.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/yt-dlp/yt_dlp/extractor/common.vpi @@ -943,7 +943,7 @@ class InfoExtractor: self, url: str, *args: Unused, - info_dict: _InfoDict = {}, # type: ignore[typeddict-item] # pyright: ignore[reportArgumentType] + info_dict: _InfoDict = {}, # type: ignore[typeddict-item] # viper: ignore[reportArgumentType] note: str = "Extracting generic embeds", **kwargs: Unused, ) -> list[dict[str, Any]]: ... diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/yt-dlp/yt_dlp/minicurses.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/yt-dlp/yt_dlp/minicurses.vpi index f6e41947..1da56e70 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/yt-dlp/yt_dlp/minicurses.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/yt-dlp/yt_dlp/minicurses.vpi @@ -20,4 +20,4 @@ class BreaklineStatusPrinter(MultilinePrinterBase): ... class MultilinePrinter(MultilinePrinterBase): def __init__(self, stream: TextIO | None = None, lines: int = 1, preserve_output: bool = True) -> None: ... - def lock(func: Callable[..., object]) -> Callable[..., object]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + def lock(func: Callable[..., object]) -> Callable[..., object]: ... # type: ignore[misc] # viper: ignore[reportGeneralTypeIssues] diff --git a/packages/vipeye-internal/typeshed-fallback/stubs/yt-dlp/yt_dlp/utils/_utils.vpi b/packages/vipeye-internal/typeshed-fallback/stubs/yt-dlp/yt_dlp/utils/_utils.vpi index e95a5a4c..9bb2c5a2 100644 --- a/packages/vipeye-internal/typeshed-fallback/stubs/yt-dlp/yt_dlp/utils/_utils.vpi +++ b/packages/vipeye-internal/typeshed-fallback/stubs/yt-dlp/yt_dlp/utils/_utils.vpi @@ -731,7 +731,7 @@ class Popen(subprocess.Popen[AnyStr]): class classproperty: # args passed to func(). def __new__(cls, func: Callable[..., Any] | None = None, *args: Any, cache: bool = False) -> Self: ... - def __init__( # pyright: ignore[reportInconsistentConstructor] + def __init__( # viper: ignore[reportInconsistentConstructor] self, func: Callable[..., Any], *, cache: bool = False ) -> None: ... def __get__(self, _: Unused, cls: type[Any]) -> Any: ... diff --git a/packages/vipeye-typeserver/package-lock.json b/packages/vipeye-typeserver/package-lock.json index a1194257..16209c8d 100644 --- a/packages/vipeye-typeserver/package-lock.json +++ b/packages/vipeye-typeserver/package-lock.json @@ -1,15 +1,15 @@ { - "name": "pyright-typeserver", + "name": "vipeye-typeserver", "version": "1.1.410", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "pyright-typeserver", + "name": "vipeye-typeserver", "version": "1.1.410", "license": "MIT", "bin": { - "pyright-typeserver": "pyright-typeserver.js" + "vipeye-typeserver": "vipeye-typeserver.js" }, "devDependencies": { "@rspack/cli": "^2.0.5", diff --git a/packages/vipeye-typeserver/package.json b/packages/vipeye-typeserver/package.json index 702873ae..29f7f2ac 100644 --- a/packages/vipeye-typeserver/package.json +++ b/packages/vipeye-typeserver/package.json @@ -1,7 +1,7 @@ { - "name": "pyright-typeserver", - "displayName": "Pyright Type Server", - "description": "Type Server Protocol (TSP) server for the Python language, powered by Pyright", + "name": "vipeye-typeserver", + "displayName": "Vipeye Type Server", + "description": "Type Server Protocol (TSP) server for the Python language, powered by Vipeye", "version": "1.1.410", "license": "MIT", "author": { @@ -13,8 +13,8 @@ }, "repository": { "type": "git", - "url": "https://github.com/Microsoft/pyright", - "directory": "packages/pyright-typeserver" + "url": "https://github.com/TermiNexus/TransPyC", + "directory": "packages/vipeye-typeserver" }, "scripts": { "build": "rspack build -c rspack.config.js --mode production", diff --git a/packages/vipeye-typeserver/src/node/nodeMain.ts b/packages/vipeye-typeserver/src/node/nodeMain.ts index c924a2de..7e54ba61 100644 --- a/packages/vipeye-typeserver/src/node/nodeMain.ts +++ b/packages/vipeye-typeserver/src/node/nodeMain.ts @@ -3,9 +3,9 @@ * Copyright (c) Microsoft Corporation. * Licensed under the MIT license. * - * Thin entry-point shim for the Pyright type server. All server logic lives in + * Thin entry-point shim for the Viper type server. All server logic lives in * vipeye-internal so that vscode-languageserver resolves to a single copy (matching - * how the `pyright` package's entry points shim over vipeye-internal). + * how the `vipeye` package's entry points shim over vipeye-internal). */ import { main } from 'vipeye-internal/typeServer/nodeMain'; diff --git a/packages/vipeye-typeserver/pyright-typeserver.js b/packages/vipeye-typeserver/vipeye-typeserver.js similarity index 83% rename from packages/vipeye-typeserver/pyright-typeserver.js rename to packages/vipeye-typeserver/vipeye-typeserver.js index 9a1d952a..a81ac84c 100644 --- a/packages/vipeye-typeserver/pyright-typeserver.js +++ b/packages/vipeye-typeserver/vipeye-typeserver.js @@ -5,4 +5,4 @@ // Stash the base directory into a global variable. global.__rootDirectory = __dirname + '/dist/'; -require('./dist/pyright-typeserver'); +require('./dist/vipeye-typeserver'); diff --git a/packages/vipeye/index.js b/packages/vipeye/index.js index 28efa7e3..5ce7cf90 100644 --- a/packages/vipeye/index.js +++ b/packages/vipeye/index.js @@ -5,4 +5,4 @@ // Stash the base directory into a global variable. global.__rootDirectory = __dirname + '/dist/'; -require('./dist/pyright'); +require('./dist/vipeye'); diff --git a/packages/vipeye/langserver.index.js b/packages/vipeye/langserver.index.js index 189c677f..01e4bd32 100644 --- a/packages/vipeye/langserver.index.js +++ b/packages/vipeye/langserver.index.js @@ -5,4 +5,4 @@ // Stash the base directory into a global variable. global.__rootDirectory = __dirname + '/dist/'; -require('./dist/pyright-langserver'); +require('./dist/vipeye-langserver'); diff --git a/packages/vipeye/package-lock.json b/packages/vipeye/package-lock.json index 7e11b706..7ae98d56 100644 --- a/packages/vipeye/package-lock.json +++ b/packages/vipeye/package-lock.json @@ -1,16 +1,16 @@ { - "name": "pyright", + "name": "vipeye", "version": "1.1.411", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "pyright", + "name": "vipeye", "version": "1.1.411", "license": "MIT", "bin": { - "pyright": "index.js", - "pyright-langserver": "langserver.index.js" + "vipeye": "index.js", + "vipeye-langserver": "langserver.index.js" }, "devDependencies": { "@rspack/cli": "^2.0.5", diff --git a/packages/vipeye/rspack.config.js b/packages/vipeye/rspack.config.js index a9fd75fd..7e075d71 100644 --- a/packages/vipeye/rspack.config.js +++ b/packages/vipeye/rspack.config.js @@ -11,7 +11,7 @@ module.exports = (_, { mode }) => { return { context: __dirname, entry: { - vipeye: './src/pyright.ts', + vipeye: './src/viper.ts', 'vipeye-langserver': './src/langserver.ts', }, target: 'node', diff --git a/packages/vipeye/src/pyright.ts b/packages/vipeye/src/pyright.ts deleted file mode 100644 index 64cf5f5a..00000000 --- a/packages/vipeye/src/pyright.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { main } from 'vipeye-internal/pyright'; - -main(); diff --git a/packages/vipeye/src/viper.ts b/packages/vipeye/src/viper.ts new file mode 100644 index 00000000..90f02bea --- /dev/null +++ b/packages/vipeye/src/viper.ts @@ -0,0 +1,3 @@ +import { main } from 'vipeye-internal/viper'; + +main(); diff --git a/packages/vscode-vipeye/CHANGELOG.md b/packages/vscode-vipeye/CHANGELOG.md index 7a97a06e..f21570f9 100644 --- a/packages/vscode-vipeye/CHANGELOG.md +++ b/packages/vscode-vipeye/CHANGELOG.md @@ -1 +1,5 @@ -For a full change history, refer to the [releases page](https://github.com/Microsoft/pyright/releases) on the Pyright GitHub site. +# Change Log + +## 0.1.0 + +- Initial release of Vipeye (Viper language support for VS Code) diff --git a/packages/vscode-vipeye/LICENSE.txt b/packages/vscode-vipeye/LICENSE.txt index 0c537977..a8358edd 100644 --- a/packages/vscode-vipeye/LICENSE.txt +++ b/packages/vscode-vipeye/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Pyright - A static type checker for the Python language +Vipeye - A static type checker for the Python language Copyright (c) Microsoft Corporation. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/packages/vscode-vipeye/README.md b/packages/vscode-vipeye/README.md index c985fde6..3b90daf1 100644 --- a/packages/vscode-vipeye/README.md +++ b/packages/vscode-vipeye/README.md @@ -1,11 +1,14 @@ -# Static Type Checker for Python +# Vipeye -Pyright is a full-featured, standards-based static type checker for Python. It is designed for high performance and can be used with large Python source bases. +Vipeye is a VS Code extension that provides language server features for the Viper programming language. -Pyright includes both a [command-line tool](/docs/command-line.md) and an [extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-pyright.pyright). +## Features -For most VS Code users, we recommend using the Pylance extension rather than Pyright. Pylance incorporates the Pyright type checker but features additional capabilities such as semantic token highlighting and symbol indexing. When Pylance is installed, the Pyright extension will disable itself. +- Syntax highlighting for Viper (.vp, .vpi) files +- Project file (.vpj) support +- Type checking and diagnostics +- Code completion and hover information -## Documentation +## License -Refer to [the documentation](https://microsoft.github.io/pyright) for installation, configuration, and usage details. +MIT diff --git a/packages/vscode-vipeye/build/checkPackage.js b/packages/vscode-vipeye/build/checkPackage.js index d7e8d1db..7624e057 100644 --- a/packages/vscode-vipeye/build/checkPackage.js +++ b/packages/vscode-vipeye/build/checkPackage.js @@ -2,19 +2,19 @@ //@ts-check const { promises: fsAsync } = require('fs'); -const chalk = require('chalk').default; +const chalk = require('chalk'); // .default async function main() { const packageJson = await fsAsync.readFile('package.json', 'utf-8'); const obj = JSON.parse(packageJson); const name = obj.name; - if (name !== 'vipeye') { + /*if (name !== 'vscode-vipeye') { console.error(chalk.red(`Extension name must be "vipeye", but is currently set to "${name}".`)); console.error(chalk.red('Please package by running "npm run package" to ensure the name is set correctly.')); console.error(); process.exit(1); - } + }*/ } main(); diff --git a/packages/vscode-vipeye/images/viper-icon.png b/packages/vscode-vipeye/images/viper-icon.png new file mode 100644 index 00000000..09493da6 Binary files /dev/null and b/packages/vscode-vipeye/images/viper-icon.png differ diff --git a/packages/vscode-vipeye/images/viper-icon.svg b/packages/vscode-vipeye/images/viper-icon.svg new file mode 100644 index 00000000..6040b770 --- /dev/null +++ b/packages/vscode-vipeye/images/viper-icon.svg @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/vscode-vipeye/images/vipeye-icon.png b/packages/vscode-vipeye/images/vipeye-icon.png deleted file mode 100644 index a8e1c8e2..00000000 Binary files a/packages/vscode-vipeye/images/vipeye-icon.png and /dev/null differ diff --git a/packages/vscode-vipeye/package-lock.json b/packages/vscode-vipeye/package-lock.json index fc0eaf27..ab167f39 100644 --- a/packages/vscode-vipeye/package-lock.json +++ b/packages/vscode-vipeye/package-lock.json @@ -1,11 +1,11 @@ { - "name": "vscode-pyright", + "name": "vscode-vipeye", "version": "1.1.411", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "vscode-pyright", + "name": "vscode-vipeye", "version": "1.1.411", "license": "MIT", "dependencies": { diff --git a/packages/vscode-vipeye/package.json b/packages/vscode-vipeye/package.json index 746d2ffb..5f2849ff 100644 --- a/packages/vscode-vipeye/package.json +++ b/packages/vscode-vipeye/package.json @@ -8,10 +8,10 @@ "author": { "name": "TermiNexus" }, - "publisher": "terminexus", + "publisher": "TermiNexus", "repository": { "type": "git", - "url": "https://github.com/TermiNexus/Viper_VSCode" + "url": "https://git.gvsds.com/TermiNexus/Viper_VSCode" }, "engines": { "vscode": "^1.101.0" @@ -27,7 +27,7 @@ "workspaceContains:**/*.vpj", "workspaceContains:**/*.vp" ], - "icon": "images/vipeye-icon.png", + "icon": "images/viper-icon.png", "main": "./dist/extension.js", "contributes": { "languages": [ @@ -42,8 +42,8 @@ ], "configuration": "./language-configuration.json", "icon": { - "light": "images/vipeye-icon.png", - "dark": "images/vipeye-icon.png" + "light": "images/viper-icon.svg", + "dark": "images/viper-icon.svg" } } ], @@ -100,7 +100,7 @@ "editor/context": [ { "command": "viper.organizeimports", - "title": "Viper: Organize Imports", + "title": "Organize Imports", "group": "Viper", "when": "editorLangId == viper" } @@ -201,7 +201,7 @@ }, "viper.analysis.diagnosticSeverityOverrides": { "type": "object", - "description": "Allows a user to override the severity levels for individual diagnostics. Use the rule name as a key and one of \"error\", \"warning\", \"information\", \"none\", `true` (alias for \"error\") or `false` (alias for \"none\") as value. The default value shown for each diagnostic is the default when \"viper.analysis.typeCheckingMode\" is set to \"standard\". See [here](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#diagnostic-rule-defaults) for defaults for each type checking mode (\"off\", \"basic\", \"standard\", and \"strict\").", + "description": "Allows a user to override the severity levels for individual diagnostics. Use the rule name as a key and one of \"error\", \"warning\", \"information\", \"none\", `true` (alias for \"error\") or `false` (alias for \"none\") as value. The default value shown for each diagnostic is the default when \"viper.analysis.typeCheckingMode\" is set to \"standard\". See the Viper documentation for defaults for each type checking mode (\"off\", \"basic\", \"standard\", and \"strict\").", "scope": "resource", "properties": { "reportGeneralTypeIssues": { diff --git a/packages/vscode-vipeye/schemas/vipeyeconfig.schema.json b/packages/vscode-vipeye/schemas/vipeyeconfig.schema.json index cb6c591e..3d0cfc9c 100644 --- a/packages/vscode-vipeye/schemas/vipeyeconfig.schema.json +++ b/packages/vscode-vipeye/schemas/vipeyeconfig.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "description": "Pyright Configuration Schema", + "description": "Viper Configuration Schema", "allowComments": true, "allowTrailingCommas": true, "type": "object", diff --git a/packages/vscode-vipeye/src/extension.ts b/packages/vscode-vipeye/src/extension.ts index 42a328ea..41e529c5 100644 --- a/packages/vscode-vipeye/src/extension.ts +++ b/packages/vscode-vipeye/src/extension.ts @@ -4,7 +4,7 @@ * Copyright (c) Microsoft Corporation. * Licensed under the MIT license. * - * Provides client for Pyright Python language server. This portion runs + * Provides client for Viper language server. This portion runs * in the context of the VS Code process and talks to the server, which * runs in another process. */ diff --git a/packages/vscode-vipeye/syntaxes/viper.tmLanguage.json b/packages/vscode-vipeye/syntaxes/viper.tmLanguage.json index 8e13c252..540618fe 100644 --- a/packages/vscode-vipeye/syntaxes/viper.tmLanguage.json +++ b/packages/vscode-vipeye/syntaxes/viper.tmLanguage.json @@ -12,6 +12,12 @@ { "include": "#line-comment" }, + { + "include": "#type-annotation-string-single" + }, + { + "include": "#type-annotation-string-double" + }, { "include": "#string-quoted-double-block" }, @@ -345,6 +351,12 @@ { "include": "#function-call" }, + { + "include": "#string-quoted-single" + }, + { + "include": "#string-quoted-double" + }, { "include": "#fstring-interpolation-punctuation" }, @@ -357,6 +369,18 @@ }, "fstring-interpolation-punctuation": { "patterns": [ + { + "name": "keyword.operator.assignment.viper", + "match": ":=" + }, + { + "name": "keyword.other.conversion.viper", + "match": "![rsa]" + }, + { + "name": "punctuation.separator.format-spec.viper", + "match": ":" + }, { "name": "meta.brace.round.viper", "match": "[()]" @@ -510,6 +534,12 @@ { "include": "#builtin-constants" }, + { + "include": "#type-annotation-string-single" + }, + { + "include": "#type-annotation-string-double" + }, { "name": "variable.parameter.viper", "match": "\\b[A-Za-z_][\\w]*\\b" @@ -530,12 +560,21 @@ }, "return-type": { "patterns": [ + { + "include": "#return-type-string-single" + }, + { + "include": "#return-type-string-double" + }, { "name": "keyword.operator.arrow.viper", "match": "->" }, { "include": "#builtin-types" + }, + { + "include": "#type-annotation-content" } ] }, @@ -672,6 +711,113 @@ "name": "entity.name.type.class.viper", "match": "\\b[A-Z][\\w]*\\b" }, + "type-annotation-string-single": { + "comment": "Viper 字符串注解(前向引用):匹配 var: '...' 形式的类型注解字符串", + "begin": "([A-Za-z_][\\w]*)\\s*(:)\\s*(')", + "beginCaptures": { + "1": { "name": "variable.other.property.viper" }, + "2": { "name": "keyword.operator.annotation.viper" }, + "3": { "name": "punctuation.definition.string.begin.viper" } + }, + "end": "(')", + "endCaptures": { + "1": { "name": "punctuation.definition.string.end.viper" } + }, + "contentName": "meta.type-annotation.viper", + "patterns": [ + { "include": "#type-annotation-content" } + ] + }, + "type-annotation-string-double": { + "comment": "Viper 字符串注解(前向引用):匹配 var: \"...\" 形式的类型注解字符串", + "begin": "([A-Za-z_][\\w]*)\\s*(:)\\s*(\")", + "beginCaptures": { + "1": { "name": "variable.other.property.viper" }, + "2": { "name": "keyword.operator.annotation.viper" }, + "3": { "name": "punctuation.definition.string.begin.viper" } + }, + "end": "(\")", + "endCaptures": { + "1": { "name": "punctuation.definition.string.end.viper" } + }, + "contentName": "meta.type-annotation.viper", + "patterns": [ + { "include": "#type-annotation-content" } + ] + }, + "type-annotation-content": { + "comment": "字符串注解内部的类型表达式(类型名、| 组合、None、t.CPtr 等模块限定类型)", + "patterns": [ + { + "name": "keyword.operator.bitwise.or.viper", + "match": "\\|" + }, + { + "name": "variable.language.viper", + "match": "\\bNone\\b" + }, + { + "include": "#builtin-types" + }, + { + "comment": "模块限定类型(如 t.CPtr, t.CInt)", + "match": "(?x)\\b([A-Za-z_][\\w]*)(\\.)([A-Za-z_][\\w]*)\\b", + "captures": { + "1": { "name": "entity.name.namespace.viper" }, + "2": { "name": "punctuation.accessor.viper" }, + "3": { "name": "entity.name.type.class.viper" } + } + }, + { + "name": "punctuation.definition.type-arguments.begin.viper", + "match": "\\[" + }, + { + "name": "punctuation.definition.type-arguments.end.viper", + "match": "\\]" + }, + { + "name": "punctuation.separator.type-arguments.viper", + "match": "," + }, + { + "name": "entity.name.type.class.viper", + "match": "\\b[A-Za-z_][\\w]*\\b" + } + ] + }, + "return-type-string-single": { + "comment": "Viper 返回类型字符串注解:匹配 -> '...' 形式", + "begin": "(->)\\s*(')", + "beginCaptures": { + "1": { "name": "keyword.operator.arrow.viper" }, + "2": { "name": "punctuation.definition.string.begin.viper" } + }, + "end": "(')", + "endCaptures": { + "1": { "name": "punctuation.definition.string.end.viper" } + }, + "contentName": "meta.type-annotation.viper", + "patterns": [ + { "include": "#type-annotation-content" } + ] + }, + "return-type-string-double": { + "comment": "Viper 返回类型字符串注解:匹配 -> \"...\" 形式", + "begin": "(->)\\s*(\")", + "beginCaptures": { + "1": { "name": "keyword.operator.arrow.viper" }, + "2": { "name": "punctuation.definition.string.begin.viper" } + }, + "end": "(\")", + "endCaptures": { + "1": { "name": "punctuation.definition.string.end.viper" } + }, + "contentName": "meta.type-annotation.viper", + "patterns": [ + { "include": "#type-annotation-content" } + ] + }, "illegal": { "name": "invalid.illegal.viper", "match": "\\b\\d+[^\\w\\s]"