Data Types

 

Primitives | Compounds | Objects

 

Slag has three categories of data types.

Primitives

Primitives are simple numbers and are used individually as well as being the basic building blocks of compounds and classes.  Primitives are assigned by-value.  There are 7 primitive types:

Name Description Literal Values
Int64 A 64-bit signed integer.  In general use Int32 instead. Int64(348), 0xffff0000ff00ff00
Int32 A 32-bit signed integer with a range of +/- 2.15 billion.  Use this for general purpose whole numbers. 6, -2, 0xffff8000, 0b11010
Char A 16-bit unsigned integer used primarily to represent Unicode characters.  Range is 0..65535.  Prints out as a symbol instead of as a character code. 'A', Char(65)
Byte An 8-bit unsigned integer with range 0..255.  Used primarily for storing raw binary data. Byte(255)
Real64 A 64-bit double-precision floating point number.  Use this for general purpose real numbers. -2.0, 3.14
Real32 A 32-bit single-precision floating point number.  Use this in favor of Real64 only if significant space can be conserved. Real32(6.28)
Logical A ternary data type with values true, false, and void.  These values may also be written as gt, eq, and lt.  Most of the time you will use Logical values exactly like Java true/false Boolean values.  When saying "if (setting)", the result will be true if setting is true and false if it's false or void.  To distinguish between false and void values, write "if (setting == false)" or "if (setting == void)".

true / gt,
false / eq,
void / lt

 

Compounds

Example:

compound Vector2( Real64 x, Real64 y )
...
local Vector2 a, b(0,0)
println( a == b )   # prints: true
b.x = 5   # ERROR - can't reassign compound elements
b = Vector2( 5, b.y )

Compound basics

  • Compounds are composite groups ("clumps") of primitives and other compounds - no references are allowed.  Compounds cannot be codependent - if A contains a B, then B can't contain an A.
  • Compounds are by-value types.  Assigning "x = y" makes a copy of compound y and stores it as x.
  • Compound members can be individually read but not individually written - to alter a compound, it must be reassigned as a compound with different values.
  • Compounds are useful when:
    • There are a small number of members (2 or 3).
    • There is a large amount of data (e.g. 10,000 Vector2 values).
    • Multiple references to the same data are unnecessary.
  • Compounds cannot contain methods but there is a trick to allow something similar.  See Compound Managers in the Singletons section.

 

Technical notes

  • No object references are allowed because primitives and compounds are kept on a data stack while objects are kept on a separate reference stack.  Allowing compounds to store references would make garbage collection much more complex.
  • Allowing compound elements to be reassigned would introduce a huge pitfall: commands like "hero.position().x = 5" would compile fine but the "x = 5" would be altering the temporary value returned on the stack, not the hero's actual position.

 

Objects

Objects are bundles of data and methods (functionality) that operate on that data.  Objects are dynamically allocated, assigned by-reference, and can be composed of primitives, compounds, and other object references.  See the section on classes and objects for more information.