Skip to content
January 25, 2009 / Abe Pralle

86 Int16, Int8; unified Logical type

While giving a presentation the other day, someone asked me why Slag had so many primitive types.  I’d never really thought about it before – I just started out with equivalents of Java’s 8 types as a baseline and added two more I was keen on (unsigned 8-bit Byte and Ternary types).

The question got me thinking though, and I realized that two of my types were dead weights: Int16 and Int8.  No one really uses them – I don’t use them.  They just complicate the compiler and VM by having two kinds of 16-bit values (Int16, Char) and two kinds of 8-bit values (Int8, Byte).  So they’re gone: I’m taking them out of my gen2 stuff right now.

Furthermore, I’ve decided to combine the Boolean and Ternary types to create a unified Logical type.  A true/false Boolean is useful for the usual reasons, and then the yes/no/void Ternary only became useful when I allowed it to be used in any place where a Boolean is expected.  With that being the case, there’s really no reason to have both.

My new Logical type can have values of true, false, and void (with alternate literal names gt, eq, and lt).  void means “not applicable”, essentially.  Any logical operation like and, or, or not will treat both false and void as false – the only difference will be that “==false” and “==void” (or !=…) will give different answers.  Note that using Logical in place of Boolean will work exactly the same as you’re used to; it’s only when “void” values may be involved that you have to be a little careful about comparing things to false versus void.

After the dust settles, here’s a quick run-down of the remaining 7 primitive types:

  • Int64 – a 64-bit signed (can be positive or negative) integer.  Useful for random numbers, timestamps, and for indexing and counting data more than 2 GB in size (the upper limit of an Int32).
  • Int32 – the standard signed integer made popular by generations of 32-bit CPUs.  Big enough to store most whole numbers you would want to work with while taking up half the space of an Int64.
  • Char – an unsigned (non-negative) 16-bit value.  Used to represent character codes from the Unicode table.  Each text string is made up of an array of Chars.
  • Byte – an unsigned 8-bit value.  Files and RAM are made of bytes.
  • Real64 – a 64-bit real number (aka “double”).  The standard for calculations involving real numbers.
  • Real32 – aka “float”.  Not nearly as precise as Real64, but still used heavily to store 3D game models and terrain since that’s a lot of data and it only takes half the space that Real64 data would.
  • Logical – a qualitative rather than quantitative type, Logical can have the values true, false, and void.  For example, a checkbox could be true if checked, false if not checked, or void if disabled.  “not true” is “false” while “not false” and “not void” both result in “true”, allowing Logical to be used in the same way as Java’s Boolean type when desired.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: