Skip to content

Latest commit

 

History

History
853 lines (628 loc) · 18.5 KB

File metadata and controls

853 lines (628 loc) · 18.5 KB

🌌 Vayu Language Syntax

Python-inspired syntax · Static type checking · Native-language foundations

This document describes the language surface currently represented by the Vayu compiler, interpreter, VM, native compiler, runtime, and current tests/examples. It also records the command-line tooling and editor-facing features currently present in the repository. Backend-specific limitations are called out where relevant.

Official source extension: .vyu

For the latest roadmap and benchmark information, visit the official Vayu website.


1. Source Files

Vayu source files use .vyu:

hello.vyu
main.vyu
control.vyu
fib.vyu
classes.vyu

Blocks are indentation-based and Python-inspired.

2. Comments

# This is a comment
name = "Vayu"  # Inline comment

3. Variables & Types

Type inference:

x = 5
y = 3.14
name = "Vayu"
flag = true

Explicit annotations:

x: int = 10
y: float = 2.5
name: str = "Vayu"
flag: bool = true

Current demonstrated types include int, float, bool, str, None, list<T>, map values, struct/class types, and function values. Integer-to-float promotion is supported where applicable.

4. Strings & Printing

name = "Vayu"
message = "Hello, " + name
print(message)
print("value:", 42)
print(str(42))

Current string functionality also demonstrates strip(), lower(), upper(), split(), join(), replace(), find(), contains(), starts_with(), ends_with(), is_digit(), is_alpha(), is_space(), and char_at().

5. Functions

def add(a: int, b: int) -> int:
    return a + b

print(add(2, 3))

Typed parameters, return types, None returns, bare return, and recursion are supported.

def fib(n: int) -> int:
    if n < 2:
        return n
    return fib(n - 1) + fib(n - 2)

6. Conditions

if x < 0:
    print("negative")
elif x == 0:
    print("zero")
elif x < 10:
    print("small")
else:
    print("big")

7. Loops

while and for loops are supported:

i = 5
while i > 0:
    print(i)
    i = i - 1

for color in ["red", "green", "blue"]:
    print(color)

range() supports one, two, and three arguments:

range(5)
range(2, 8)
range(0, 10, 2)

Nested loops, break, and continue are supported.

8. Arithmetic

Operator Meaning
+ addition
- subtraction / unary negative
* multiplication
/ division
// floor/integer division
% modulo
** exponentiation

Example:

print(1 + 2)
print(10 - 3)
print(4 * 5)
print(7 / 2)
print(7 // 2)
print(7 % 3)
print(2 ** 10)
print(-5)
print(- -5)

Exponentiation is right-associative:

print(2 ** 3 ** 2)

Output:

512

Equivalent to 2 ** (3 ** 2).

9. Comparisons & Logic

Comparison operators:

==  !=  <  <=  >  >=

Logical operators:

and  or  not

Examples:

print(2 < 3)
print(1 == 1)
print(true and false)
print(true or false)
print(not true)

10. Operator Precedence

Parentheses control evaluation order:

print(1 + 2 * 3)       # 7
print((1 + 2) * 3)     # 9

Exponentiation is evaluated right-to-left, while normal arithmetic, comparison, and logical precedence applies to the currently implemented operators.

11. Lists

nums = [1, 2, 3, 4, 5]

The current implementation demonstrates:

  • zero-based indexing
  • negative indexing
  • element assignment
  • len()
  • append()
  • pop()
  • insert()
  • contains()
  • in
  • concatenation with +
  • repetition with *
  • nested lists
  • iteration
nums[0] = 100
nums.append(6)
last = nums.pop()
nums.insert(0, 50)
print(nums[-1])
print(3 in nums)
print(len(nums))

List slicing is implemented. Python-style slicing is currently supported for lists, tuples, and strings across the parser, AST/type-checking, VM/runtime, and native code-generation paths.

12. Maps

ages = {
    "alice": 30,
    "bob": 25
}

print(ages["alice"])
ages["carol"] = 40
ages.put("dave", 22)
ages.remove("bob")
print("alice" in ages)
print(ages.keys())
print(len(ages))

Map indexing, assignment, put(), remove(), contains(), keys(), len(), membership, and iteration over keys are demonstrated by the current implementation.

13. Tuples & Sets

Tuples and sets are now first-class collection types.

Tuples support creation/conversion, indexing, iteration, stringification, slicing, and concatenation. Sets support creation/conversion, iteration, stringification, and set operations such as add(), remove(), and union().

a = (1, 2, 3)
b = (4, 5)
c = a + b
s = set([1, 2, 3])
s.add(4)

14. Structs

Structs provide named fields:

struct Player:
    name: str
    score: int

p = Player("NotY", 100)
print(p.name)
p.score = 200

Positional and keyword construction, field access/modification, and nested structs are demonstrated.

15. Classes & Inheritance

Classes support fields, __init__, self, methods, inheritance, overriding, and super().

class Player:
    def __init__(self, name: str):
        self.name = name

    def greet(self) -> None:
        print("Hello, " + self.name)

p = Player("Vayu")
p.greet()

Inheritance and multi-level inheritance are demonstrated by the current examples.

16. Lambdas & Higher-Order Functions

The current implementation demonstrates function values, lambdas, closures, higher-order calls, and:

map()
filter()
reduce()
sorted()
any()
all()
sum()

17. Exceptions

Vayu supports try, except, finally, and raise:

try:
    x = 10 / 0
except ZeroDivisionError as e:
    print(e.message)
finally:
    print("done")

The current implementation demonstrates Exception, RuntimeError, TypeError, ValueError, and ZeroDivisionError, plus exception variables, multiple handlers, bare except, nested exceptions, re-raising, raising another exception, and raising a string.

18. Modules

import math_helpers
import math_helpers as math
from math_helpers import helper
from math_helpers import helper as h

Module constants, functions, structs, aliases, and chained member access are demonstrated. Modules use .vyu files.

19. Math Library

Current math functionality includes:

sqrt()
floor()
ceil()
sin()
cos()
exp()
log()
log10()
log2()
pi
e
abs()

20. Expressions & Attribute Access

Expression statements, attribute chains, and indexing are supported:

player.stats.score
items[0]
grid[0][1]

21. Type Checking

Vayu includes a type-checking stage for explicit annotations and supported type relationships.

x: int = "hello"

This is invalid because a string cannot be assigned to an int.

22. AST

The compiler can generate/dump an AST representation for supported programs. The AST is used as a structured representation between parsing and later compiler stages.

23. Verification Examples

Arithmetic has been exercised with:

print(1 + 2)
print(10 - 3)
print(4 * 5)
print(7 / 2)
print(7 // 2)
print(7 % 3)
print(2 ** 10)
print(-5)
print(- -5)
print(1 + 2 * 3)
print((1 + 2) * 3)
print(2 ** 3 ** 2)

The demonstrated results include 3, 7, 20, 3.5, 3, 1, 1024, -5, 5, 7, 9, and 512.

Control-flow verification includes if/elif/else, while, for over ranges and lists, nested loops, break, continue, and loop-based accumulation.

total = 0
for n in range(1, 11):
    total = total + n
print("sum 1..10 =", total)

Output:

sum 1..10 = 55

24. Current Syntax Status

The reference documents implemented or demonstrated behavior only. Current areas include variables, types, functions, recursion, conditions, loops, arithmetic, comparisons, logical expressions, collections, structs, classes, inheritance, lambdas/closures, exceptions, modules, math functionality, type checking, AST generation, and VM-oriented execution.

Known limitations remain documented until the corresponding compiler features are implemented and tested. Some syntax is accepted through parser-level handling while its backend/runtime support can still be more limited than the frontend syntax suggests.

The official Vayu source extension is .vyu.


25. Complete Syntax Index

This section organizes the current language surface by category so the syntax reference can be used as a quick lookup.

Source and lexical syntax

  • .vyu source files
  • indentation-based blocks
  • spaces and tabs for indentation
  • # comments
  • blank lines
  • newline / indent / dedent structural tokens
  • single-quoted and double-quoted strings
  • character literals
  • decimal, binary, octal, hexadecimal, and exponent-form numeric literals
  • true / false / none plus True / False / None

Declarations

def name(...):
struct Name:
class Name:
const NAME = value
enum Name:
extern "C":

Variables and assignment

name = value
name: Type = value
name += value
name -= value
name *= value
name /= value
name %= value
name **= value
name //= value
name &= value
name |= value
name ^= value
name <<= value
name >>= value

Control flow

if condition:
elif condition:
else:
while condition:
for item in iterable:
break
continue
pass

Functions

def name(a: Type, b: Type) -> ReturnType:
    ...

return value
return

Function values, lambdas, closures, recursion, higher-order calls, and generic/type-parameter metadata are part of the current compiler architecture.

Expressions

literal
identifier
(a + b)
object.member
object[index]
object[start:end]
call(arg)
lambda x: expression

Collections

[1, 2, 3]
{"name": "Vayu"}
(1, 2, 3)
set([1, 2, 3])

Supported collection families include list, map, tuple, set, and string operations, with indexing and slicing where implemented.

Operators

Arithmetic: + - * / // % **

Comparison: == != < > <= >=

Logic and membership: and or not in is

Bitwise: & | ^ ~ << >>

Compound assignment: += -= *= /= %= **= //= &= |= ^= <<= >>=

Unary/native-oriented: +x -x not x ~x &x *x

Object-oriented syntax

class Child(Parent):
    field: Type

    def __init__(self, value: Type):
        self.field = value

    def method(self) -> None:
        ...

Supported class-related concepts include inheritance, overriding, constructors, methods, self, super, static members, and visibility metadata.

Exceptions

try:
    ...
except ExceptionType as e:
    ...
finally:
    ...

raise ExceptionType("message")

Modules

import module
import module as alias
from module import name
from module import name as alias

Generators

def values():
    yield value

Generator support includes suspension, resume, next, completion, and exception propagation in the VM implementation.

Low-level syntax

ptr<Type>
ref<Type>
unique<Type>
shared<Type>
weak<Type>

&value
*pointer
malloc(...)
free(...)

Native FFI also provides an extern C declaration path and native function-pointer/library integration.

Runtime utility surface

The current runtime/native implementation contains utility families for reflection, numeric helpers, iteration, collections, functional operations, filesystem/OS work, networking, crypto, randomness, regular expressions, threading, time, JSON, and Python interoperability.

Parser and AST coverage

Expression nodes

IntLit FloatLit StringLit CharLit BoolLit NoneLit
NameRef Unary Binary Grouping Call Attr Index
ListLit MapLit Lambda GenericType TupleLit SetLit Slice

Statement nodes

Expr Assign AnnotAssign If While Def Return
Struct Class For Try Raise Import FromImport
Pass Break Continue Const Enum Yield Block Extern

The parser also contains dedicated paths for match, with, unsafe handling, namespace handling, visibility modifiers, and compound assignment.

Lexer keyword policy

Hard-reserved words currently include:

def return if elif else while for break continue pass
class struct enum interface new delete import from as
try except finally with raise unsafe spawn wait task async await
and or not in is lambda yield true false none
True False None int float bool str char bytes
ptr ref unique shared weak const extern

Words such as match, case, defer, namespace, static, public, protected, and private are handled through parser-level logic rather than being reserved by the lexer in the same way.

Compiler execution modes

vayuc file.vyu
vayuc file.vyu --vm
vayuc file.vyu --native
vayuc file.vyu --native-out output.exe
vayuc file.vyu --check
vayuc file.vyu --dump-tokens
vayuc file.vyu --dump-ast
vayuc file.vyu --dump-bytecode
vayuc file.vyu --dump-ir
vayuc file.vyu --bench 10
vayuc --emit-runtime runtime.c

Debugging flags also include --no-check and --no-opt.

Backend boundary

The current project contains tree-walking, bytecode/VM, and native compilation paths. C FFI, raw native integration, and the CPython bridge are native-oriented features.

VCB is the companion backend project that now provides the native machine-code and executable-generation layer:

Vayu Source
  -> Frontend
  -> Vayu IR
  -> VCB
  -> Native Assembly
  -> Executable

Developer Tooling

The current repository also contains dedicated tooling around the language:

vayuc   Vayu compiler
vls     Vayu Language Server
vfmt    Vayu formatter
vlint   Vayu linter

The official VS Code extension integrates .vyu files with the language server and exposes editor-side language features including syntax highlighting, diagnostics, hover, completion, go-to-definition, references, rename, signature help, formatting, and linting.

VS Code extension: https://marketplace.visualstudio.com/items?itemName=Fliczo.vayu

Visual Studio Community support is provided by vscommunity-vayu-Extention as a native VSIX/TextMate package.

Direct VS Code installation URI: vscode:extension/Fliczo.vayu

Compiler CLI

The current compiler command-line modes include:

vayuc file.vyu
vayuc file.vyu --vm
vayuc file.vyu --native
vayuc file.vyu --native-out output.exe
vayuc file.vyu --check
vayuc file.vyu --dump-tokens
vayuc file.vyu --dump-ast
vayuc file.vyu --dump-bytecode
vayuc file.vyu --dump-ir
vayuc file.vyu --bench [N]
vayuc --emit-runtime runtime.c

Current compiler flags also include:

--opt <0-3>
--no-check
--no-opt
--emit-runtime <path>

--opt controls the native optimization level used by the native compilation path. --no-opt disables the VM bytecode optimizer; these are separate controls.

Native / Backend Boundary

The current repository contains tree-walking/interpreter, bytecode/VM, and native compilation paths. Native compilation now uses VCB for direct native code generation and executable emission.

The intended long-term architecture is:

Vayu Source
  -> Frontend
  -> Vayu IR
  -> VCB
  -> Native Assembly / Machine Code
  -> Executable

For architecture and roadmap information, see Documentation.md and docs/vision.md.

26. Native Raster & 3D Graphics

The native compiler exposes a raster module for framebuffer and 3D rendering work. Raster functionality is native-only and integrates with the existing gui canvas/window layer.

Framebuffers

import raster

fb: int = raster.fb_new(640, 480)
raster.fb_enable_depth(fb)
raster.fb_clear(fb, 0xFF101018)
raster.fb_clear_depth(fb)
raster.fb_present(fb, canvas, 0, 0)
raster.fb_free(fb)

Framebuffer operations include creation/freeing, depth enable/disable/clear, clear, pixel access, and presentation.

4x4 Matrices

Matrices use the Q16.16 fixed-point convention:

m: int = raster.mat_new()
raster.mat_identity(m)
raster.mat_translate(m, x, y, z)
raster.mat_rotate_x(m, degrees)
raster.mat_rotate_y(m, degrees)
raster.mat_rotate_z(m, degrees)
raster.mat_perspective(m, fov, aspect, near, far)
raster.mat_look_at(m, ex, ey, ez, tx, ty, tz, ux, uy, uz)
raster.mat_mul(dst, a, b)
raster.mat_free(m)

Meshes

mesh: int = raster.mesh_new()
raster.mesh_add_vert(mesh, x, y, z, u, v)
raster.mesh_add_vert_lit(mesh, x, y, z, nx, ny, nz, u, v)
raster.mesh_set_normal(mesh, index, nx, ny, nz)
raster.mesh_add_tri(mesh, i0, i1, i2)
raster.mesh_clear(mesh)
raster.mesh_free(mesh)

Meshes support dynamic vertices, normals, UVs and triangle indices.

Textures

tex: int = raster.tex_new(64, 64)
raster.tex_set(tex, x, y, 0xFFFFFFFF)
raster.tex_set_filter(tex, 2)
raster.tex_gen_mipmaps(tex)
width: int = raster.tex_width(tex)
height: int = raster.tex_height(tex)
raster.tex_free(tex)

The native texture path supports nearest, bilinear and trilinear filtering, mipmap generation and LOD selection. A framebuffer can be converted to a texture with tex_from_fb, and a texture can be presented to a GUI canvas with tex_present.

Lighting and 3D Rendering

raster.set_ambient(0xFF202020)
raster.light_clear()
raster.light_set(0, kind, x, y, z, color, intensity)
raster.draw_mesh(fb, mesh, mvp, tex, 0xFFFFFFFF)
raster.draw_mesh_lit(fb, mesh, mvp, model, tex, shade_mode, tint,
                     eye_x, eye_y, eye_z)

The rasterizer provides perspective-correct textured triangles, depth testing, ambient/directional lighting, per-vertex normals, Gouraud/Phong-style lighting and specular support.

Post-processing

raster.post_gamma(tex, gamma)
raster.post_invert(tex)
raster.post_tint(tex, color)
raster.post_brightness(tex, delta)
raster.post_threshold(tex, threshold)

These effects operate in-place on the level-0 texture.

GUI Integration

Raster output is displayed through the native GUI canvas:

c: int = gui.canvas_from_window()
raster.fb_present(fb, c, 0, 0)
gui.canvas_free(c)

Current examples include raster_tri.vyu, raster_cube.vyu, raster_lit_cube.vyu, and raster_postfx.vyu.

Numeric Convention

Raster matrix, position, normal, UV and lighting values use the native Q16.16/fixed-point conventions. Colors use packed ARGB-style integers. Native resource APIs perform bounds and handle validation.

27. Current Syntax Status

The current syntax is shared across the Vayu frontend and its execution paths. Native float literals, mixed integer/float expressions, float()/int()/str() conversions, math.*, list<float>, and map<str, float> are implemented. Native compilation now lowers through VCB. Phase 27 Parts 1–17 are complete, covering the ELF writer, Linux runtime, PE correctness, validation, and backend hardening. The WDAC structural fix is done but remains intermittent for some binaries. Signing is removed from the roadmap. Phase 28 next moves native output toward COFF/ELF object emission and external linking. gui and raster remain native-oriented modules.