Zigscript: an alternate implementation of zig language

I have been working on a potential feature for the zig language which I call the “annotation system”. The Pitch:

  1. Any KNOWLEDGE that can be derived from ‘looking at the code’, will be derivable through the annotation system (ideally).
  2. Such knowledge will be provided at comptime, and can be use to add arbitrary CONSTRAINT to the code.
  3. Each constraint is effectively either a PROOF or a compile error.
  4. An ANNOTATION on an expression represent a constraint application, these are like “comments that runs”; They work cooperatively to make STATEMENTs about the code.
  5. The statements are effectively TAGs, not available for regular comptime evaluation, but can be themself be used by the annotation system and query by ‘external tools’ (build system, source gen…)
    (…)

This would allow, in it’s primal form, doing thing like custom control flow analysis, resource lifetime tracing, distinct types, anytype refinement, enforce architecture code… all in user code. It’s like an add-on over the type system.

To do so, I’m working on a from scratch implementation of zig language using zig. The code should be public in a few weeks from now. It will mostly be an interpreter.

Why?

  • Simpler codebase
  • Simpler AST representation + api
  • More easily work on the main compiler (debug execution flow)
  • Try out, to see how it can be improved

How

  • Using zig
  • Heavily abuse comptime
  • Focus is on “front end”: parsing, semantic analysis, RLS… (some “low level” related behavior might be off in first releases…)
  • Priority is more on agility than on performance

What: to expect on the long run

  • Interpret zig code (comptime and runtime).
  • REPL: to enable interactive dev env
  • Code intelligence via the “annotation system”, like grep but better suited for a language like zig
  • Provide a simple way for external tools (like LSP) to understand zig’s (comptime) code evaluation
  • Integrate with zig at specific compilation phases (ZIR and AIR)
  • Other features under a --experimental flag?
1 Like

To do so, I’m working on a from scratch implementation of zig language using zig. The code should be public in a few weeks from now. It will mostly be an interpreter.

Will your alternate implementation interpret only stable zig like zig 0.14.0? Or it can compile unstable zig like zig git?

I plan to link each zigscript stable versions with the zig stable ones. So it will depend on how many change where made after each version and how disruptive they are. If the changes are syntactic, minor behavioral changes or in std, it will likely be possible.