A Quick Introduction to Virgil - Primitives

This is part of a basic introduction to programming in Virgil and gives an overview of the language, its syntax, and its structures. This page focuses on the basic primitive types; their values and their operators.

Primitives

Virgil provides four main primitive types: int, boolean, char and the raw types (which are discussed here). Primitive types have value semantics, meaning that that are always passed by value, never by reference. Thus a value of a primitive type is never affected by side effects; 1 is always 1 and 'C' is always 'C'.

Booleans

local x: boolean = true;
local y: boolean = false;

The boolean type is the simplest of all of Virgil's types. The boolean type has only two values: true and false, and is the required type for conditional expressions in branches and loops. The boolean type has three main operators: and, or, and !. For more information on these basic operators, see the operators page.

Integers

local x: int = -238;
local y: int = 12299;

The int type represents a fairly standard finite set of integer values in Virgil. Literal positive and negative numbers written in decimal have type int, while hexadecimal, octal, and binary have raw types. Integers can be as large as 2147483647 and as small as -2147483648 (i.e. they represent the same set of values as C or Java's 32-bit signed integers). Integers in Virgil support the familiar set of binary and unary operators, such as add, subtract multiply, divide modulus, and negation. Similarly they support comparison operators such as less than, greater than, etc. For more information see the operators page.

(Note: Unlike C or Java, the int type in Virgil does not support the bitwise operators such as |. Instead, these operators are defined on the raw types.)

Characters

local x: char = 'c';
local y: char = '\n';

Virgil supports the primitive type char that represents characters encoded using the ASCII character set. Virgil supports a similar syntax to Java for declaring character literals. The char type supports a limited set of operations that are related to character comparison; for more details, see the page on operators.

Go back to the tutorial.