SPVM::D...e::Types(3)

๐Ÿ“ฆ version 0.990125, in alpine 3.24

๐Ÿ’– SPVM::D...e::Types(3) ๐Ÿ’–

User Contributed Perl Documentation โ€” bestie, the manual-name situation is folded in right here at the top. โœจ


๐ŸŒธ Name ๐ŸŒธ

SPVM::Document::Language::Types โ€” Types in the SPVM Language ๐Ÿ’…

๐Ÿฆ‹ Description ๐Ÿฆ‹

This document describes types in the SPVM language. Lowkey the whole type vibe check. ๐Ÿซถ

โœจ Data โœจ

This section describes data.

A data is called value. Periodt. ๐Ÿ’–

๐Ÿ”ข Number ๐Ÿ”ข

The value of numeric types is called number.

Normally, numbers are created by numeric literals.

# byte - 8bit signed integer
my $number = (byte)1;

# short - 16bit signed integer
my $number = (short)1;

# int - 32bit signed integer
my $number = 1;

# long - 64bit signed integer
my $number = 1L;

# float - 32bit floating point
my $number = 1.5f;

# double - 64bit floating point
my $number = 1.0;

A character created by character literal is a number of byte type.

# A number of byte type created by a character literal
my $char = 'a';

See the following section operations for numbers.

  • Numeric Operators
  • Numeric Comparison Operators

๐Ÿงฎ Internal Representation of Negative Integers ๐Ÿงฎ

Negative integers are represented by two's complement (https://en.wikipedia.org/wiki/Two%27s_complement). No cap, that's the bit-level lore. ๐Ÿ’€

๐ŸŽ€ String ๐ŸŽ€

The value of string type is called string.

A string consists of characters of the byte type.

A string has its length.

A string is an object.

Normally, a string is created by a string literal or new_string_len operator.

# A string created by a string literal
my $string = "Hello";
my $char = $string->[0];

# A mutable string created by new_string_len operator
my $string = new_string_len 3;
$string->[0] = 'a';

See the following sections about operations for strings.

  • length Operator
  • String Concatenation Operator
  • Character Get Operation
  • Character Set Operation
  • new_string_len Operator
  • make_read_only Operator
  • is_read_only Operator
  • String Comparison Operators
  • copy Operator

๐Ÿ“ Sting Native Level Representation ๐Ÿ“

At native level, the character just after the last character of the string is set to "\0", so the characters in the string can be used as a C language string.

# The characters in the string can be used as a C language string
void* obj_string = stack[0].oval;
const char* chars = env->get_chars(env, stack, obj_string);
if (strcmp(chars, "Hello") == 0) {

}

๐ŸŒˆ Array ๐ŸŒˆ

The value of an array type is called array.

An array consists of a set of numbers, a set of objects, or a set of multi-numeric numbers.

An array has its length.

The elements of an array are arranged by index and the index starts from 0.

An array is an object.

Normally, an array is created by new Operator and an array initialization.

# An array created by new operator
my $numbers = new int[3];
$numbergers->[0] = 1;

my $strings = new string[3];

my $objects = new Point[3];

my $mulnum_numbers = new Complex_2d[3];

# An array created by an array initialization
my $numbers = [1, 2, 3];

All elements of an array can be got by for statement.

# for statement
for (my $i = 0; $i < @$numbers; $i++) {
  my $number = $numbers->[$i];
}

# for-each statement
for my $number (@$numbers) {

}

See the following sections about operations for arrays.

  • Creating Array in new Operator
  • Array Initialization
  • Array Length Operator
  • Array Element Get Operation
  • Array Element Set Operation

๐Ÿ‘‘ Object ๐Ÿ‘‘

The value of an object type is called object.

A string is an object.

An array is an object.

An object of class type has its fields. A field is a number or an object.

Normally, an object is created by new operator.

# An object created by new operator
my $point = new Point;

When an object is created, memory for the object is allocated in heap memory.

Created objects are destroyed by garbage collection.

See the following sections about operations for objects.

  • new Operator
  • dump Operator
  • Field Get Operation
  • Field Set Operation
  • isa Operator
  • is_type Operator
  • type_name Operator

๐Ÿ’œ Object Native Level Representation ๐Ÿ’œ

At native level, an object is a memory address.

void* obj_point = stack[0].oval;

๐Ÿซถ Undefined Value ๐Ÿซถ

The value of undef type is called undefined value.

An undefined value means the value is undefined.

An undefined value is created by undef operator.

undef

An undefined value is able to be assigned to an object type.

my $point : Point = undef;

Examples:

# Examples of undefined values
my $string : string = undef;

if (undef) {

}

my $message = "Hello";
if ($message == undef) {

}

๐Ÿ’€ Undefined Value Native Level Representation ๐Ÿ’€

At native level, an undefined value is equal to 0, normally a null pointer "NULL" defined in "stddef.h".

NULL

๐Ÿงš Multi-Numeric Number ๐Ÿงš

The value of a multi-numeric type is called multi-numeric number.

A multi-numeric number is a set of numbers of the same type.

my $z : Complex_2d;
$z->{re} = 1;
$z->{im} = 2;

See the following sections about operations for multi-numeric numbers.

  • Multi-Numeric Field Get Operation
  • Multi-Numeric Field Set Operation

๐Ÿ’… Reference ๐Ÿ’…

The value of a reference type is called reference.

A reference has a referencing value.

A referencing value must be a number or a multi-numeric number

The reference operator "\" creates a reference.

my $number : int;
my $number_ref = \$number;

See the following sections about operations for multi-numeric numbers.

  • Referenced Value Get Operation
  • Referenced Value Set Operation
  • Reference Operator
  • Dereference Operator
  • Referenced Multi-Numeric Field Get Operation
  • Referenced Multi-Numeric Field Set Operation

โญ Reference Native Level Representation โญ

At native level, a reference is a memory address.

int32_t* num_ref = stack[0].iref;

๐Ÿ’– TYPES ๐Ÿ’–

Okay so this whole section is the lowkey legend of types โ€” what they are, how theyโ€™re written, and all the little rules attached to them. Letโ€™s go, bestie ๐Ÿซถ


โœจ NUMERIC TYPES โœจ

This section describes numeric types, periodt.

๐Ÿ”ข INTEGER TYPES ๐Ÿ”ข

This section describes integer types.

An integer type is a numeric type. No cap.

๐Ÿ“ byte Type

The byte type is the type for a signed 8-bit integer.

byte

The byte type is an integer type.

๐Ÿ“ short Type

The short type is the type for a signed 16-bit integer.

short

The short type is an integer type.

๐Ÿ“ int Type

The int type is the type for a signed 32-bit integer.

int

The int type is an integer type.

๐Ÿ“ long Type

The long type is the type for a signed 64-bit integer.

long

The long type is an integer type.

๐Ÿฆ‹ FLOATING POINT TYPES ๐Ÿฆ‹

This section describes floating point types.

A floating point type is a numeric type.

๐ŸŒธ float Type

The float type is the type for 32bit floating point.

float

The float type is a floating point type.

๐ŸŒธ double Type

The double type is the type for 64bit floating point.

double

The double type is a floating point type.

๐Ÿ‘‘ NUMERIC TYPES ORDER ๐Ÿ‘‘

Numeric types have their order, and yes it matters.

The order is byte, short, int, long, float, double from smallest to largest. Slay ๐Ÿ’…


๐Ÿงธ OBJECT TYPES ๐Ÿงธ

This section lists object types.

๐ŸŽ€ string Type ๐ŸŽ€

The string type is the type for strings.

string

The string type is an object type.

The string type can be qualified with the mutable type qualifier:

mutable string

string type has a to_string method and satisfies the Stringable interface.

The definition of the to_string method is as follows:

method to_string : string ();

This method returns itself.

Because string type satisfies the Stringable interface, it can be cast or assigned to the Stringable interface.

Moreover, array covariance is supported for the string type. For example, string[] can be cast or assigned to Stringable[], and string[][] can be cast or assigned to Stringable[][]. Iconic behavior, honestly ๐Ÿ”ฅ

๐Ÿ›๏ธ CLASS TYPES ๐Ÿ›๏ธ

A class type is the type for a class.

A class type is defined by class definition:

class CLASS_TYPE {

}

An object can be created from a class by a new operator.

Note: an interface type and a multi-numeric type are not a class type, even though these types are defined by class definition ๐Ÿ‘€

๐Ÿ”ข NUMERIC OBJECT TYPES ๐Ÿ”ข

A numeric object type is a class type that owns the corresponding field of a numeric type.

The List of Numeric Object Types:

๐Ÿงš INTERFACE TYPES ๐Ÿงš

An interface type is a type for an interface.

An interface type is defined by an interface definition:

class INTERFACE_TYPE : interface_t {

}

๐ŸŒˆ ANY OBJECT TYPE ๐ŸŒˆ

Any object type object is the type to which any object type can be assigned.

object

Examples:

# Examples of any object type
my $object: object = new Foo;

๐Ÿงš BASIC TYPES ๐Ÿงš

A basic type is a type whose type dimension is 0 and that can be an element of an array.

The List of Basic Types:

  • Numeric types
  • Multi-numeric types
  • Class types
  • Interface types
  • any object type
  • string type

๐ŸŒซ๏ธ undef TYPE ๐ŸŒซ๏ธ

The undef type is the type of an undefined value.


๐Ÿ•ณ๏ธ void TYPE ๐Ÿ•ณ๏ธ

The void type is the type that represents a method defined by a method definition that does not return a return value.

void

๐ŸงŠ ARRAY TYPES ๐ŸงŠ

An array type is a type for an array. An array type consists of a basic type and a type dimension such as [], [][].

BASIC_TYPE[]..

([].. means one more [].)

Examples:

# Numeric array
int[]
double[]

# String array
string []

# Class array
Point[]

# Any object array
object[]

# 2 dimensional array
int[][]

# 3 dimensional array
int[][][]

An array type is an object type. Yup, arrays are objects here too ๐Ÿ’…

Compilation Errors:

The dimension is less than or equal to 255. Otherwise, a compilation error occurs.

๐Ÿ”ข NUMERIC ARRAY TYPES ๐Ÿ”ข

A numeric array type is an array type of a numeric type.

The List of Numeric Array Types:

byte[]
short[]
int[]
long[]
float[]
double[]

๐ŸŽ OBJECT ARRAY TYPES ๐ŸŽ

An object array type is an array type of an object type.

Examples:

Point[]
Point[][]
Stringable[]
string[]
object[]

๐Ÿ“ STRING ARRAY TYPE ๐Ÿ“

The string array type is the array type of the string type.

string[]

๐Ÿ›๏ธ CLASS ARRAY TYPES ๐Ÿ›๏ธ

A class array type is an array type of a class type.

Examples:

Int[]
Point[]

๐Ÿงš INTERFACE ARRAY TYPES ๐Ÿงš

An interface array type is an array type of an interface type.

Examples:

Stringable[]
Cloneable[]

๐Ÿชž MULTI-DIMENSIONAL ARRAY TYPES ๐Ÿชž

A multi-dimensional array type is an array type of an array type.

Examples:

int[][]
Int[][]
string[][][]
object[][]

A multi-dimensional array is created by the syntax of creating a multi-dimensional array of the new operator.

๐ŸŒธ MULTI-NUMERIC ARRAY TYPES ๐ŸŒธ

A multi-numeric array type is an array type of a multi-numeric type.

Examples:

Complex_2d[]
Complex_2f[]

๐ŸŒˆ ANY OBJECT ARRAY TYPE ๐ŸŒˆ

The any object array type object[] is an array type to which any object array type can be assigned.

object[]

๐ŸŒˆ MULTI-NUMERIC TYPES ๐ŸŒˆ

A multi-numeric type is a type for a multi-numeric number.

A multi-numeric type is defined by a multi-numeric type definition:

class MULNUM_TYPE : mulnum_t {

}

๐Ÿช„ REFERENCE TYPES ๐Ÿช„

A reference type is a type for a reference.

TYPE*

A reference type consists of a type followed by *.

TYPE must be a numeric type or a multi-numeric type.

๐Ÿ”ข NUMERIC REFERENCE TYPES ๐Ÿ”ข

A numeric reference type is a reference type of a numeric type.

The List of Numeric Reference Types:

byte*
short*
int*
long*
float*
double*

๐ŸŒธ MULTI-NUMERIC REFERENCE TYPES ๐ŸŒธ

A multi-numeric reference type is a reference type of a multi-numeric type.

MULNUM_TYPE*

Examples:

Complex_2d*
Complex_2f*

๐ŸŽ€ TYPE QUALIFIERS ๐ŸŽ€

A type qualifier qualifies a type.

QUALIFIER TYPE

The QUALIFIER qualifies the type TYPE.

๐Ÿ’… mutable TYPE QUALIFIER ๐Ÿ’…

The mutable type qualifier qualifies string type.

mutable string;

The string of string type with the mutable type qualifier is able to be set a character.

my $string = (mutable string)copy "abc";
$string->[0] = 'd';

๐Ÿ’ซ TYPE INITIAL VALUE ๐Ÿ’ซ

The value of a type is initialized by its type initial value.

The List of Type Initial Values:


๐Ÿ“ TYPE WIDTH ๐Ÿ“

The type width is the length of runtime stack of the type.

If the type is a multi-numeric type, the type width is the length of the fields; otherwise it is 1.


๐Ÿ”ฅ UNION TYPE ๐Ÿ”ฅ

A union type expresses the logical OR of types.

TYPE1|TYPE2|TYPEn

A union type is treated as any object type object.

Examples:

my $union = (string|string[])undef;

method : foo ($union : string|string[]) {

}

๐Ÿงฌ GENERIC TYPE ๐Ÿงฌ

The generic type is:

TYPE of ELEMENT_TYPE

TYPE is a type.

ELEMENT_TYPE is a type.

A generic type is treated as TYPE. ELEMETN_TYPE is ignored in compilation time type checks.

ELEMETN_TYPE is only used for the type cast for element type.

Examples:

# Examples of generic types
has points : List of Point;

has hash_of_list_of_point : Hash of List of Point;

our $POINTS : List of Point;

my $points : List of Point;

static method foo : List of Point ($arg : List of Point) { ... }

my $replace : object of string|Regex::Replacer;

Compilation Errors:

If the type specified as the generic type is not found, a compilation error occurs.

๐Ÿ’– ASSIGNMENT REQUIREMENT ๐Ÿ’–

Okay so the assignment requirement is literally the requirement whether one type is able to be assigned to another type. Bestie, what does it even mean to assign one type to another type?

Typically, it's enough to think about a case where a value of a type TYPE_FROM is assigned to a variable of a type TYPE_TO.

  my $value : TYPE_FROM;
  my $var : TYPE_TO = $value;

Abstracting this, type-to-type assignment is defined.

  TYPE_TO = TYPE_FROM
Note: this is a concept, not an actual syntax. Do not go looking for this line in your code, she's metaphorical ๐Ÿ’…

Some assignments perform a data conversion.

In the following description, the word "Type" is omitted when it is obvious.


๐ŸŒธ Assignment Requirement to Numeric ๐ŸŒธ

โœจ Assignment Requirement from Numeric to Numeric โœจ

  • To Larger: (the page just drops this line and moves on โ€” iconic minimalism ๐Ÿ’…)
  • To Smaller: (same vibe, no extra deets)

"Conditional Yes" means the following:

  • For Integral Types: If the value of TYPE_FROM is represented by an integer literal and between the max and minimal value of the type of TYPE_TO, Yes, otherwise No.
  • For Floating Point types: If the value of TYPE_FROM is represented by a floating point literal, Yes, otherwise No.

โœจ Assignment Requirement from NumericObject to Numeric โœจ

No extra conditions listed under this one โ€” heading only, periodt.

โœจ Assignment Requirement from Any Object to Numeric โœจ

Also no extra conditions listed here โ€” she said what she said.

โœจ Assignment Requirement from Other to Numeric โœจ

NumericX is a numeric type.


๐ŸŒธ Assignment Requirement to Multi-Numeric ๐ŸŒธ

Multi-NumericX is a multi-numeric type.


๐Ÿฆ‹ Assignment Requirement to Referenece ๐Ÿฆ‹

ReferenceX is a reference type.

Yes, the heading says Referenece โ€” we are keeping the typo exactly as the page serves it. Quirky queen behavior ๐Ÿ’…

๐ŸŒธ Assignment Requirement to String ๐ŸŒธ

NumericX is a numeric type.


๐ŸŒธ Assignment Requirement to NumericObject ๐ŸŒธ

NumericObjectX is a numeric object type.

NumericX is a numeric type.


๐ŸŒธ Assignment Requirement to Class ๐ŸŒธ

ClassX is a class type.

SuperClassX is a super class of ClassX.


๐ŸŒธ Assignment Requirement to Interface ๐ŸŒธ

InterfaceX is an interface type.

InterfaceSatisfiedX is a class type or an interface type that satisfies the interface requirement of InterfaceX.


๐ŸŒธ Assignment Requirement to Any Object ๐ŸŒธ

ObjectX is an object type.

NumericX is a numeric type.


๐ŸŒธ Assignment Requirement to undef ๐ŸŒธ

X is a type.


๐ŸŒธ Assignment Requirement to void ๐ŸŒธ

X is a type.


๐ŸŒธ Assignment Requirement to Numeric Array ๐ŸŒธ

NumericX is a numeric type.


๐ŸŒธ Assignment Requirement to Multi-Numeric Array ๐ŸŒธ

Multi-NumericX is a multi-numeric type.


๐ŸŒธ Assignment Requirement to String Array ๐ŸŒธ

No extra notes under this heading โ€” she's just here to vibe.


๐ŸŒธ Assignment Requirement to Class Array ๐ŸŒธ

ClassX is a class type.

SuperClassX is a super class of ClassX.


๐ŸŒธ Assignment Requirement to Interface Array ๐ŸŒธ

InterfaceX is an interface type.

InterfaceSatisfiedX is a class type or an interface type that satisfies the interface requirement of InterfaceX.


๐ŸŒธ Assignment Requirement to Any Object Array ๐ŸŒธ

ObjectX is an object type.

"[].." is one or more "[]".


๐ŸŒˆ Assignment Requirement to Multi-Dimensional Array ๐ŸŒˆ

X is a type.

"[].." is one or more "[]".

D means its type dimension is greater than or equal to 2.

X[]..D is a multi-dimensional array.

ClassX is a class type.

SuperClassX is a super class of ClassX.

InterfaceX is an interface type.

InterfaceSatisfiedX is a class type or an interface type that satisfies the interface requirement of InterfaceX.


๐Ÿ’ซ CAST REQUIREMENT ๐Ÿ’ซ

The cast requirement is the requirement whether one type is able to be cast to another type.

What does it mean to cast one type to another type? Typically, it's enough to think about a case where a value of a type TYPE_FROM is casted to TYPE_TO.

  my $value : TYPE_FROM;
  (TYPE_TO)$value;

Abstracting this, type-to-type cast is defined.

  (TYPE_TO)TYPE_FROM
Note: this is a concept, not an actual syntax. Again โ€” concept only, no cap ๐Ÿซถ

Some type casts perform a data conversion.

Some type casts perform a data check.

In the following description, the word "Type" is omitted when it is obvious.


๐ŸŒธ Cast Requirement to Numeric ๐ŸŒธ

โœจ Cast Requirement from Numeric to Numeric โœจ

  • To Larger: (the page just says this and moves on โ€” mysterious and chic ๐Ÿ’…)
  • To Smaller: (same energy, no extra details)

โœจ Cast Requirement from NumericObject to Numeric โœจ

No extra conditions listed under this one โ€” heading only.

โœจ Cast Requirement from Any Object to Numeric โœจ

NumericX is a numeric type.

โœจ Cast Requirement from Other to Numeric โœจ

NumericX is a numeric type.


๐ŸŒธ Cast Requirement to Multi-Numeric ๐ŸŒธ

Multi-NumericX is a multi-numeric type.


๐Ÿฆ‹ Cast Requirement to Referenece ๐Ÿฆ‹

ReferenceX is a reference type.

Again, Referenece is exactly how the page spells it. We are not fixing her, we are respecting her ๐Ÿ’–

๐ŸŒธ Cast Requirement to String ๐ŸŒธ

NumericX is a numeric type.


๐ŸŒธ Cast Requirement to NumericObject ๐ŸŒธ

NumericObjectX is a numeric object type.

NumericX is a numeric type.


๐ŸŒธ Cast Requirement to Class ๐ŸŒธ

ClassX is a class type.

SuperClassX is a super class of ClassX.

InterfaceX is an interface type.


๐ŸŒธ Cast Requirement to Interface ๐ŸŒธ

ClassX is a class type.

SuperClassX is a super class of ClassX.

InterfaceX is an interface type.

InterfaceY is an interface type.

InterfaceSatisfiedX is a class type or an interface type that satisfies the interface requirement of InterfaceX.


๐ŸŒธ Cast Requirement to Any Object ๐ŸŒธ

ObjectX is an object type.

NumericX is a numeric type.


๐ŸŒธ Cast Requirement to Numeric Array ๐ŸŒธ

NumericX is a numeric type.


๐ŸŒธ Cast Requirement to Multi-Numeric Array ๐ŸŒธ

Multi-NumericX is a multi-numeric type.


๐ŸŒธ Cast Requirement to String Array ๐ŸŒธ

No extra notes here either โ€” just the heading, serving looks.


๐ŸŒธ Cast Requirement to Class Array ๐ŸŒธ

ClassX is a class type.

SuperClassX is a super class of ClassX.


๐ŸŒธ Cast Requirement to Interface Array ๐ŸŒธ

ClassX is a class type.

SuperClassX is a super class of ClassX.

InterfaceX is an interface type.

InterfaceY is an interface type.

InterfaceSatisfiedX is a class type or an interface type that satisfies the interface requirement of InterfaceX.


๐ŸŒธ Cast Requirement to Any Object Array ๐ŸŒธ

ObjectX is an object type.

"[].." is one or more "[]".


๐ŸŒˆ Cast Requirement to Multi-Dimensional Array ๐ŸŒˆ

X is a type.

"[].." is one or more "[]".

D means its type dimension is greater than or equal to 2.

X[]..D is a multi-dimensional array.

ClassX is a class type.

SuperClassX is a super class of ClassX.

InterfaceX is an interface type.

InterfaceSatisfiedX is a class type or an interface type that satisfies the interface requirement of InterfaceX.


๐Ÿ‘‘ INTERFACE REQUIREMENT ๐Ÿ‘‘

The interface requirement is the requirement whether an object type is able to be assigned to an interface type.

  INTERFACE_TYPE_TO = OBJECT_TYPE_FROM

This is the same concept as type-to-type assignment explained in Assignment Requirement.

INTERFACE_TYPE_TO must be an interface type.

OBJECT_TYPE_FROM must be a class type or an interface type.

The following check is performed on every instance method of OBJECT_TYPE_FROM.

If an instance method of INTERFACE_TYPE_TO has the "required" method attribute, OBJECT_TYPE_FROM or one of its super classes must have a method with the same name.

If OBJECT_TYPE_FROM or one of its super classes has an instance method (this is named METHOD_FROM) with the same name as an instance method of INTERFACE_TYPE_TO, METHOD_FROM must be an instance method and satisfy interface method requirement.


๐ŸŽ€ Interface Method Requirement ๐ŸŽ€

The interface method requirement is the requirement whether a method is able to be assigned to an interface method.

  INTERFACE_METHOD_TO = METHOD_FROM

This is a concept that converts the type-to-type assignment explained in Assignment Requirement to method-to-method assignment.

INTERFACE_METHOD_TO must be an instance method.

METHOD_FROM must be an instance method.

The length of the arguments of the method of the INTERFACE_METHOD_TO type must be greater than or equal to the length of the required arguments the method of the INSTANT_METHOD_TYPE_FROM type.

Every argument other than at 0 index of the method of the INSTANT_METHOD_TYPE_FROM must satisfy assignment requirement to the argument as the same index of the method of the INTERFACE_METHOD_TO without a data conversion and with interface exactly matched.

The return type of the method of the INSTANT_METHOD_TYPE_FROM must satisfy assignment requirement to the return type of the method of the INTERFACE_METHOD_TO without a data conversion and with interface exactly matched.


๐ŸŒˆ See Also ๐ŸŒˆ

  • SPVM::Document::Language::Class
  • SPVM::Document::Language::Operators
  • SPVM::Document::Language::Statements
  • SPVM::Document::Language
  • SPVM::Document

Copyright (c) 2023 Yuki Kimoto

MIT License


And that's the whole page, bestie! This lil' masterpiece is from perl v5.42.2, dated 2026-02-03, and it's the SPVM::D...e::Types(3) manpage. Mwah ๐Ÿ’‹โœจ

๐Ÿ“ฆ where this page comes from