ViperOS devfs.vp 的 `serial0_file.open = serial0_open` 原先误报 「无法为类"devfs_file"的属性"open"赋值 / 参数名称不匹配 / 额外参数 "flags"」。 根因:devfs_file 是 virtual class,open/close/read/write/ioctl 是虚方法 (vtable 槽)。该赋值写的是 vtable 槽;编译器只把 RHS 函数 bitcast i8* 后 store,不校验签名与 self。而 LSP 走普通成员赋值路径,比较的是 **绑定方法类型**(self 已剥掉),于是 RHS 显式写的 self: rawptr 成了多余参数。 修法:typeEvaluator 的 usage.method === 'set' 分支里,assignType 之前加 isViperVtableMethodSlotAssignment 命中即视为兼容、跳过报错与收窄。判据: - 类是 virtual class(ClassNode.d.viperClassModifier === 'virtual' 或 @t.CVTable 装饰器);注意传入的 classType 是**实例**形态,必须先转 可实例化形态(第一版没生效的原因) - 成员在类里声明为方法(FunctionType) - RHS 的 self 为泛指针(rawptr / t.CPtr / void*)或该类本身/父类的指针 - 其余非变参参数逐个 name + isTypeSame 相同,返回类型 isTypeSame 相同 (*args / **kwargs 不参与比较) 未放行:非 virtual class、self 非指针、参数名/类型/个数不符、返回类型不符。 - 新增 viperVtableMethodAssign.test.ts(3 用例) - .gitignore:新增 3 个 __viper_vtable_assign_* 产物目录 - CHANGELOG:1.1.426 追加 1 条
Vipeye — Static Type Checker and Language Server for Viper
Vipeye is a full-featured, standards-based static type checker and language server for Viper, written in TypeScript. It is designed for high performance and can be used with large Viper source bases.
Vipeye ships in three forms:
- a language server (
vipeye-langserver) speaking LSP over stdin/stdout; - a command-line type checker (
vipeye); - an extension for Visual Studio Code (
vscode-vipeye), which bundles both the LSP client and the Viper core UI (project / toolchain).
It is built on the Pyright codebase, adapted from the ground up to Viper semantics (AOT compilation, C-style type system, pointer and memory semantics). Python analysis is no longer supported — only the Viper dialect is checked.
What is Viper
Viper is an ahead-of-time (AOT) compiled language whose syntax is modeled on CPython but whose semantics are entirely different:
- TPC — the seed compiler, itself based on CPython, used to bootstrap the toolchain.
- TPV — the first self-hosted compiler, written in Viper. Once
tpv --lsplands, it will replace the Pyright-derived analyzer in this repository.
Vipeye exists to provide type checking, diagnostics and editor intelligence for .vp / .vpi sources while TPV's own language server is under development.
Capabilities
Viper language semantics
- C-style type system:
t.CPtr,t.CArray,t.CVoid,t.CTypedef,t.CDefine,t.CEnum,t.REnum, plus the compiler built-inschar,doubleandrawptr(a raw-pointer typedef). - Pointer and memory semantics:
CPtr[T]/rawptr[T],c.Deref, address-of, pointer arithmetic and indexing; a__new__returning a raw pointer is auto-wrapped intoCPtr[T]. - C declaration modifiers (
t.CInline,t.CStatic,t.CConst…) are filtered out during type merging — only the underlying data type is kept. - Declaration modifiers on functions, with
fn/fun/func/functionas aliases ofdef. struct/union/enum/rnum, including nestedt.REnumvariants destructured by field order.- Variadic
*argsbound asva_listin the function body (va_arg, and pointer passthrough such asvsnprintf(buf, size, fmt, args)). - Implicit conversion rules: integer/float convert in all directions (safe narrowing, lossless widening); integer → float requires float width ≥ integer width; float → integer is rejected; pointers of the same level may convert, different levels may not; explicit casts are always allowed.
- Global/local variable rules: reading a global never errors; assigning an undeclared global without
globaldoes; a local redeclaration shadows the global; and so on. - Type representations:
bool/t.CBoolmap toi1;str/bytesarei8*, whilestr | t.CPtr/bytes | t.CPtrarei8**. - PEP 695 syntax is pre-processed for Viper: type parameter lists are stripped and unknown
T | t.CPtrunions are folded toi8*. - Fail-fast analysis: missing type information is reported as an error instead of silently degrading to
i8*/void/i32.
Editor features
- Diagnostics with human-readable messages, plus Viper-tuned semantic highlighting (keywords, decorators,
t.CDefineconstants, and undefined symbols rendered in white). - Completion, hover, go-to-definition, find references, rename, document symbols, and Organize Imports.
- Activity-bar UI (Project / Toolchain / Settings),
.vpjproject files with a dedicated custom editor, and a status-bar compiler indicator. - Import resolution over
VIPER_HOME(stdlib),viperconfig.jsonextra paths, the workspace root, and recursively discovered child project configurations.
Packages
packages/vipeye-internal— Core analysis engine: parser, binder, type evaluator, checker, and language service. All logic lives here.packages/vipeye— CLI wrapper. Bundlesvipeye-internalinto a distributable npm package withvipeyeandvipeye-langserverentry points.packages/vipeye-typeserver— Type server process for long-running editor sessions.packages/vscode-vipeye— VS Code extension client (Vipeye LSP), with the Viper core source (packages/viper) bundled at build time.packages/viper— Viper core source library: project (.vpj) management, toolchain, and the activity bar UI (Project / Toolchain / Settings).
Relationship to Pyright
- Viper dialect:
viperconfig.jsoninstead ofpyrightconfig.json; configuration namespaceviper.*instead ofpython.analysis.*/pyright.*. - Viper stdlib stubs bundled in
packages/vipeye-internal/vipershed-fallback. - Type semantics follow Viper rules: implicit conversions, pointer types (
CPtr/CArray),t.CTypedef/t.CDefine/t.CEnum/t.REnum,T | t.CPtrpointer folding, global-variable access rules, and more. - Diagnostics and semantic highlighting are tailored to Viper syntax.
Building and Testing
# Install all packages (from repo root)
npm install
# Build the core library
cd packages/vipeye-internal && npm run build
# Run all tests (rebuilds the test server first)
cd packages/vipeye-internal && npm test
# Run tests without rebuilding the test server (faster iteration)
cd packages/vipeye-internal && npm run test:norebuild
# Build the CLI / VS Code extension bundles (from repo root)
npm run build:cli:dev
npm run build:extension:dev
See docs/build-debug.md for details.
Documentation
Refer to the documentation for installation, configuration, and usage details.
Environment variables
If Vipeye fails to create a temporary directory (for example in remote/server environments where the OS temp directory doesn't exist or isn't writable), you can override the temp directory root:
VIPEYE_TMPDIR: Absolute path to a directory that Vipeye can use for temporary files/directories. Vipeye will create it if needed.
Vipeye otherwise relies on the platform temp directory (for example TMPDIR, TMP, TEMP, or the OS default).
License
MIT
