Types & Literals
Primitive Types
Section titled “Primitive Types”Primitive types are built into vctx. N can be any counting number (positive integers). N is always read with base 10.
uN: Unsigned integer of width N (u1, u16, etc)
sN: Signed integer of width N (s1, s16, etc)
bool: Boolean value (true or false)
Booleans are essentially like using a u1, but it can be more readable to write code using true or false instead of 0 or 1.
Either way, you only need 1 bit to represent a boolean.
Literals
Section titled “Literals”Type Inference
Section titled “Type Inference”Literals are always untyped, and inferred from context.
420xFFThis means you can work with numbers the way you expect, and the compiler will tell you if something is wrong.
Examples:
wire a: u8 = 42 // OK: inferred as u8wire b: u16 = 42 // OK: inferred as u16wire c: u16 = 42 as u8 // NOT OK: casting using `as` will change 42 to a u8wire d: u1 = 42 // NOT OK: you need at least 6 bits to store the value 42Numbers will retain their sign, and be extended with zeros automatically to retain the same value.
Literal Formats
Section titled “Literal Formats”When using literals, vctx supports common formats for defining numeric values. Literals will have the same behavior, regardless of what syntax or formatting you use. Underscores get ignored, but can be useful for formatting code.
Decimal: 123, 1000, 1_000
Hex: starts with 0x, like 0xFF, 0x10_FF
Binary: starts with 0b, like 0b1011, 0b1100_0011
Boolean: true, false
String: inside double quotes, "text goes here"
String Literals
Section titled “String Literals”For now, only ascii strings are supported. Strings will get converted so each character is the numeric value for the letter.
wire message : u16 = "hi"Need an offline copy? Download Full Manual (.md)