SPVM::D...perators(3)

๐Ÿ“ฆ version 0.990125, in alpine 3.24

okay so bestie, welcome to SPVM::Document::Language::Operators โ€” it's from the User Contributed Perl Documentation, that's the 3 section of the manual (iykyk), and it's literally the whole guide to operators in the SPVM language. grab a snack, we're going through every single one ๐Ÿ’…โœจ


๐ŸŽ€ NAME ๐ŸŽ€

SPVM::Document::Language::Operators โ€” Operators in the SPVM Language

๐ŸŒธ DESCRIPTION ๐ŸŒธ

So this document describes operators in the SPVM language. that's the whole vibe. no cap. ๐Ÿฆ‹

๐Ÿ’– OPERATORS ๐Ÿ’–

An operator is a basic instruction that, normally, returns a value. like, it does a little thing and hands you back a value. that's it, that's the definition โœจ

๐Ÿงš NUMERIC OPERATORS ๐Ÿงš

โญ Unary Plus Operator

The unary plus operator "+" is a unary operator that just... returns its operand. it's giving "I add nothing but I'm still here" energy ๐Ÿ’€

+OPERAND

This operator performs integer promotional conversion on the operand OPERAND, and returns it.

The return type is the type after the conversion is performed.

Compilation Errors:

The type of OPERAND must be a numeric type. Otherwise, a compilation error occurs.

Examples:

# Examples of the unary plus operator
my $num = +10;

๐Ÿ”ฅ Unary Minus Operator

The unary minus operator "-" is a unary operator that returns the negated value of its operand. flip it and reverse it, periodt ๐Ÿ‘‘

-OPERAND

This operator performs integer promotional conversion on the operand OPERAND, negates it, and returns it.

The return type is the type after the conversion is performed.

Compilation Errors:

The type of OPERAND must be a numeric type. Otherwise, a compilation error occurs.

Examples:

# Examples of the unary minus operator
my $num = -10;

โž• Addition Operator

The addition operator "+" adds two operands together. classic. iconic. math's main character ๐Ÿซถ

LEFT_OPERAND + RIGHT_OPERAND

This operator performs binary numeric conversion on the left operand LEFT_OPERAND and the right operand RIGHT_OPERAND.

And it performs the same operation as the following C language operation, and returns its return value.

LEFT_OPERAND + RIGHT_OPERAND

The return type is the type after binary numeric conversion is performed.

Compilation Errors:

The type of LEFT_OPERAND must be a numeric type. Otherwise, a compilation error occurs.

The type of RIGHT_OPERAND must be a numeric type. Otherwise, a compilation error occurs.

Examples:

# Examples of addition operator
my $result = 1 + 2;

โž– Subtraction Operator

The subtraction operator "-" subtracts its right operand from its left operand. left minus right, always, don't get it twisted ๐Ÿ’…

LEFT_OPERAND - RIGHT_OPERAND

This operator performs binary numeric conversion on the left operand LEFT_OPERAND and the right operand RIGHT_OPERAND.

And it performs the same operation as the following C language operation, and returns its return value.

LEFT_OPERAND - RIGHT_OPERAND

The return type is the type after binary numeric conversion is performed.

Compilation Errors:

The type of LEFT_OPERAND must be a numeric type. Otherwise, a compilation error occurs.

The type of RIGHT_OPERAND must be a numeric type. Otherwise, a compilation error occurs.

Examples:

# Examples of subtraction operator
my $result = 1 - 2;

โœ–๏ธ Multiplication Operator

The multiplication operator "*" multiplies two operands. times-ing, if you will ๐ŸŒˆ

LEFT_OPERAND * RIGHT_OPERAND

This operator performs binary numeric conversion on the left operand LEFT_OPERAND and the right operand RIGHT_OPERAND.

And it performs the same operation as the following C language operation, and returns its return value.

LEFT_OPERAND * RIGHT_OPERAND

The return type is the type after binary numeric conversion is performed.

Compilation Errors:

The type of LEFT_OPERAND must be a numeric type. Otherwise, a compilation error occurs.

The type of RIGHT_OPERAND must be a numeric type. Otherwise, a compilation error occurs.

Examples:

# Examples of multiplication operator
my $result = 1 * 2;

โž— Division Operator

The division operator "/" divides its left operand by its right operand. the way it splits things... obsessed ๐Ÿ’œ

LEFT_OPERAND / RIGHT_OPERAND

This operator performs binary numeric conversion on the left operand LEFT_OPERAND and the right operand RIGHT_OPERAND.

And it performs the same operation as the following C language operation, and returns its return value.

LEFT_OPERAND / RIGHT_OPERAND

The return type is the type after binary numeric conversion is performed.

Exceptions:

If the left operand type LEFT_OPERAND and the right operand RIGHT_OPERAND are an integer type and RIGHT_OPERAND is 0, an exception is thrown.

bestie do NOT divide an integer by 0. it throws. that's not a vibe, that's an exception ๐Ÿ˜ญ

Compilation Errors:

The type of LEFT_OPERAND must be a numeric type. Otherwise, a compilation error occurs.

The type of RIGHT_OPERAND must be a numeric type. Otherwise, a compilation error occurs.

Examples:

# Examples of division operator
my $result = 1 / 2;

๐Ÿงฎ Division Unsigned Int Operator

The division unsigned int operator "div_uint" interprets its two operands as unsigned 32bit integers, and divides its left operand by its right operand. two ints walk in, get read as unsigned 32bit, and one divides the other ๐ŸŽ€

LEFT_OPERAND div_uint RIGHT_OPERAND

This operator performs the same operation as the following C language operation, and returns its return value.

(uint32_t)LEFT_OPERAND / (uint32_t)RIGHT_OPERAND

The return type is int type.

Exceptions:

If RIGHT_OPERAND is 0, an exception is thrown.

Compilation Errors:

The type of LEFT_OPERAND must be int type. Otherwise, a compilation error occurs.

The type of RIGHT_OPERAND must be int type. Otherwise, a compilation error occurs.

Examples:

# Examples of the division unsigned int operator
my $result = 1 div_uint 2;

๐Ÿงฎ Division Unsigned Long Operator

The division unsigned long operator "div_ulong" interprets its two operands as unsigned 64bit integers, and divides its left operand by its right operand. it's the same slay as div_uint but bigger โ€” 64 whole bits of it ๐Ÿ‘‘

LEFT_OPERAND div_ulong RIGHT_OPERAND

This operator performs the same operation as the following C language operation, and returns its return value.

(uint64_t)LEFT_OPERAND / (uint64_t)RIGHT_OPERAND

The return type is long type.

Exceptions:

If RIGHT_OPERAND is 0, an exception is thrown.

Compilation Errors:

The type of LEFT_OPERAND must be long type. Otherwise, a compilation error occurs.

The type of RIGHT_OPERAND must be long type. Otherwise, a compilation error occurs.

Examples:

# Examples of the division unsigned long operator
my $result = 1L div_ulong 2L;

๐Ÿ”ข Modulo Operator

The modulo operator "%" calculates the modulo of the division of its two operands. it's the leftover queen, she stays with the remainder ๐Ÿ’…

LEFT_OPERAND % RIGHT_OPERAND

This operator performs binary numeric conversion on the left operand LEFT_OPERAND and the right operand RIGHT_OPERAND.

And it performs the same operation as the following C language operation, and returns its return value.

RETURN_VALUE = LEFT_OPERAND % RIGHT_OPERAND;
if ((LEFT_OPERAND < 0) != (RIGHT_OPERAND < 0) && RETURN_VALUE) { RETURN_VALUE += RIGHT_OPERAND; }

The return type is the type after binary numeric conversion is performed.

Exceptions:

If RIGHT_OPERAND is 0, an exception is thrown.

Compilation Errors:

The type of LEFT_OPERAND must be an integer type. Otherwise, a compilation error occurs.

The type of RIGHT_OPERAND must be an integer type. Otherwise, a compilation error occurs.

Examples:

# Examples of modulo operator
my $result = 1 % 2;

๐Ÿ”ข Modulo Unsigned Int Operator

The modulo unsigned int operator "mod_uint" interprets its two operands as unsigned 32bit integers, and calculates the modulo of the division of its two operands. reminder that it re-reads both operands as unsigned 32bit first, fr fr โœจ

LEFT_OPERAND mod_uint RIGHT_OPERAND

This operator performs the same operation as the following C language operation, and returns its return value.

(uint32_t)LEFT_OPERAND % (uint32_t)RIGHT_OPERAND

The return type is int type.

Exceptions:

If RIGHT_OPERAND is 0, an exception is thrown.

Compilation Errors:

The type of LEFT_OPERAND must be int type. Otherwise, a compilation error occurs.

The type of RIGHT_OPERAND must be int type. Otherwise, a compilation error occurs.

Examples:

# Examples of the modulo unsigned int operator
my $result = 1 mod_uint 2;

๐Ÿ”ข Modulo Unsigned Long Operator

The modulo unsigned long operator "mod_ulong" interprets its two operands as unsigned 64bit integers, and calculates the modulo of the division of its two operands. same energy, 64 bits, no skips ๐Ÿฆ‹

LEFT_OPERAND mod_ulong RIGHT_OPERAND

This operator performs the same operation as the following C language operation, and returns its return value.

(uint64_t)LEFT_OPERAND % (uint64_t)RIGHT_OPERAND

The return type is long type.

Exceptions:

If RIGHT_OPERAND is 0, an exception is thrown.

Compilation Errors:

The type of LEFT_OPERAND must be long type. Otherwise, a compilation error occurs.

The type of RIGHT_OPERAND must be long type. Otherwise, a compilation error occurs.

Examples:

# Examples of the modulo unsigned long operator
my $result = 1L mod_ulong 2L;

๐Ÿš€ INCREMENT OPERATORS ๐Ÿš€

โฌ†๏ธ Pre-Increment Operator

The pre-increment operator "++" increases the value of an operand by 1, and returns it. plus one first, hand it back after. pre means the value is already updated when you get it back ๐Ÿ‘‘

++OPERAND

This operator increases the value of the operand OPERAND by 1 using additonal operator, performs a type cast to the type of OPERAND on it, and returns it.

The return type is the type of OPERAND.

Compilation Errors:

OPERAND must be a local variable, a class variable, a field access, an element access, a dereference. Otherwise, a compilation error occurs.

The type of OPERAND must be a numeric type. Otherwise, a compilation error occurs.

Examples:

# Examples of the pre-increment operator

# A local variable
++$num;

# A class variable
++$NUM;

# A field access
++$point->{x};

# An element access
++$nums->[0];

# A dereference
++$$num_ref;

โฌ†๏ธ Post-Increment Operator

The post-increment operator "++" increases the value of an operand by 1, and returns the value before performing the incrementation. sneaky little thing โ€” you get the old value back, the +1 happens after ๐Ÿ™ˆ

OPERAND++

This operator increases the value of the operand OPERAND by 1 using additonal operator, performs a type cast to the type of OPERAND on it, assigns it on OPERAND, and returns OPERAND before performing the incrementation.

The return type is the type of OPERAND.

Compilation Errors:

OPERAND must be a local variable, a class variable, a field access, an element access, a dereference. Otherwise, a compilation error occurs.

The type of OPERAND must be a numeric type. Otherwise, a compilation error occurs.

Examples:

# Examples of the post-increment operator

# A local variable
$num++;

# A class variable
$NUM++;

# A field access
$point->{x}++;

# An element access
$nums->[0]++;

# A dereference
$$num_ref++;

๐Ÿฆ‹ DECREMENT OPERATORS ๐Ÿฆ‹

โฌ‡๏ธ Pre-Decrement Operator

The pre-decrement operator "--" decreases the value of an operand by 1, and returns it. same deal as pre-increment but going down instead of up ๐Ÿซถ

--OPERAND

(part 1 of 10 โ€” more coming, don't go anywhere ๐Ÿ’…)

So this operator? It decreases the value of the operand OPERAND by 1 using the subtraction operator, then performs a type cast to the type of OPERAND on the result, and returns it. That's it, that's the whole vibe. ๐Ÿ’…

The return type is the type of OPERAND. โœจ

Compilation Errors

  • OPERAND must be a local variable, a class variable, a field access, an element access, or a dereference. Anything else and boom โ€” compilation error. ๐Ÿ˜ญ
  • The type of OPERAND must be a numeric type. Otherwise, compilation error. No exceptions, no cap.

Examples

# Examples of the pre-decrement operator

# A local variable
--$num;

# A class variable
--$NUM;

# A field access
--$point->{x};

# An element access
--$nums->[0];

# A dereferenced value
--$$num_ref;

Post-Decrement Operator

Okay so the post-decrement operator -- decreases the value of an operand by 1, and returns the value from before the decrementation happened. It's giving "you get the old version, the new one drops later." ๐ŸŽ€

OPERAND--

This operator decreases the value of the operand OPERAND by 1 using the subtraction operator, performs a type cast to the type of OPERAND on it, assigns it on OPERAND, and returns OPERAND as it was before the decrementation. ๐Ÿฆ‹

The return type is the type of OPERAND.

Compilation Errors

  • OPERAND must be a local variable, a class variable, a field access, an element access, or a dereference. Otherwise, a compilation error occurs. ๐Ÿ™ˆ
  • The type of OPERAND must be a numeric type. Otherwise, a compilation error occurs.

Examples

# Examples of the post-decrement operator

# A local variable
$num--;

# A class variable
$NUM--;

# A field access
$point->{x}--;

# An element access
$nums->[0]--;

# A dereference
$$num_ref--;

Bitwise Operators

Bitwise AND Operator

The bitwise AND operator & performs the bitwise AND operation โ€” https://en.wikipedia.org/wiki/Bitwise_operation#AND โ€” and it is so good at it. ๐ŸŒˆ

LEFT_OPERAND & RIGHT_OPERAND

This operator performs binary numeric conversion on the left operand LEFT_OPERAND and the right operand RIGHT_OPERAND. Both of them. Together. Iconic. ๐Ÿ‘‘

And then it performs the exact same operation as this C language operation, and returns its return value:

LEFT_OPERAND & RIGHT_OPERAND

The return type is the type after binary numeric conversion is performed.

Compilation Errors

  • The type of LEFT_OPERAND must be an integer type. Otherwise, a compilation error occurs.
  • The type of RIGHT_OPERAND must be an integer type. Otherwise, a compilation error occurs.

Examples

# Examples of bitwise AND operator
my $num1 = 0xff;
my $num2 = 0x12;
my $result = $num1 & $num2;

Bitwise OR Operator

The bitwise OR operator | performs the bitwise OR operation โ€” https://en.wikipedia.org/wiki/Bitwise_operation#OR. Honestly? Ate. ๐Ÿ’…

LEFT_OPERAND | RIGHT_OPERAND

This operator performs binary numeric conversion on the left operand LEFT_OPERAND and the right operand RIGHT_OPERAND.

And it performs the same operation as the following C language operation, and returns its return value:

LEFT_OPERAND | RIGHT_OPERAND

The return type is the type after binary numeric conversion is performed.

Compilation Errors

  • The type of LEFT_OPERAND must be an integer type. Otherwise, a compilation error occurs.
  • The type of RIGHT_OPERAND must be an integer type. Otherwise, a compilation error occurs.

Examples

# Examples of the bitwise OR operator
my $num1 = 0xff;
my $num2 = 0x12;
my $result = $num1 | $num2;

Bitwise NOT Operator

The bitwise NOT operator ~ performs the bitwise NOT operation โ€” https://en.wikipedia.org/wiki/Bitwise_operation#NOT. One operand energy, and it's doing the most. โœจ

~OPERAND

This operator performs numeric widening conversion on the operand OPERAND.

And it performs the same operation as the following C language operation, and returns its return value:

~OPERAND

The return type is the type that numeric widening conversion is performed.

Compilation Errors

  • The type of OPERAND must be an integer type. Otherwise, a compilation error occurs.

Examples

# Examples of bitwise NOT operator
my $result = ~0xFF0A;

Shift Operators

Left Shift Operator

The left shift operator << performs an arithmetic left shift โ€” https://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift. Scoot over, bits. ๐Ÿš—

LEFT_OPERAND << RIGHT_OPERAND

This operator performs numeric widening conversion on the left operand LEFT_OPERAND.

And it performs numeric widening conversion on the right operand RIGHT_OPERAND.

And it performs the same operation as the following C language operation, and returns its return value:

LEFT_OPERAND << RIGHT_OPERAND

The return type is the type of LEFT_OPERAND.

Compilation Errors

  • The type of LEFT_OPERAND must be an integer type. Otherwise, a compilation error occurs.
  • The type of RIGHT_OPERAND must be an integer type within int. Otherwise, a compilation error occurs.

Examples

# Examples of left shift operator
my $result = 0xFF0A << 3;

Arithmetic Right Shift Operator

The arithmetic right shift operator >> performs an arithmetic right shift โ€” https://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift. Same energy, opposite direction. ๐Ÿฆ‹

LEFT_OPERAND >> RIGHT_OPERAND

This operator performs numeric widening conversion on the left operand LEFT_OPERAND.

And it performs numeric widening conversion on the right operand RIGHT_OPERAND.

And it performs the same operation as the following C language operation, and returns its return value. Yes, the semicolon is part of the original, don't @ me ๐Ÿ’€:

LEFT_OPERAND >> RIGHT_OPERAND;

The return type is the type of LEFT_OPERAND.

Compilation Errors

  • The type of LEFT_OPERAND must be an integer type. Otherwise, a compilation error occurs.
  • The type of RIGHT_OPERAND must be an integer type within int. Otherwise, a compilation error occurs.

Examples

# Examples of arithmetic right shift operator
my $result = 0xFF0A >> 3;

Logical Right Shift Operator

The logical right shift operator >>> performs a logical right shift โ€” https://en.wikipedia.org/wiki/Bitwise_operation#Logical_shift. Three arrows, zero apologies. ๐Ÿ”ฅ

LEFT_OPERAND >>> RIGHT_OPERAND

This operator performs numeric widening conversion on the left operand LEFT_OPERAND.

And it performs numeric widening conversion on the right operand RIGHT_OPERAND.

And if the type of LEFT_OPERAND is int type, it performs the same operation as the following C language operation:

(uint32_t)LEFT_OPERAND >> RIGHT_OPERAND

If the type of LEFT_OPERAND is long type, it performs the same operation as the following C language operation:

(uint64_t)LEFT_OPERAND >> RIGHT_OPERAND

And it returns its return value.

The return type is the type of LEFT_OPERAND.

Compilation Errors

  • The type of LEFT_OPERAND must be an integer type. Otherwise, a compilation error occurs.
  • The type of RIGHT_OPERAND must be an integer type within int. Otherwise, a compilation error occurs.

Examples

# Examples of logical right shift operator
my $result = 0xFF0A >>> 3;

Logical Operators

Logical AND Operator

The logical AND operator && performs a logical AND operation. Both sides gotta show up, or nobody's getting in. ๐ŸŽŸ๏ธ

LEFT_OPERAND && RIGHT_OPERAND

This operator performs condition evaluation on the left operand LEFT_OPERAND.

If the evaluated value is 0, it returns 0. Otherwise, it performs condition evaluation on the right operand RIGHT_OPERAND.

And it returns the evaluated value of RIGHT_OPERAND.

The return type is int type. ๐Ÿ’–

Examples

# Examples of logical AND operator
if (1 && 0) {

}

Logical OR Operator

The logical OR operator || performs a logical OR operation.

# logical OR operator
LEFT_OPERAND || RIGHT_OPERAND

The logical OR operator performs condition evaluation on the left operand LEFT_OPERAND.

If the evaluated value is not 0, it returns the evaluated value. Otherwise, it performs condition evaluation on the right operand RIGHT_OPERAND.

And it returns the evaluated value of RIGHT_OPERAND.

The return type is int type.

Examples

# Examples of logical OR operator
if (1 || 0) {

}

Logical NOT Operator

The logical NOT operator ! performs a logical NOT operation. Flip it and reverse it, no cap. ๐Ÿ”„

!OPERAND

The logical NOT operator performs condition evaluation on the operand OPERAND.

If the evaluated value is 0, it returns 1, otherwise it returns 0.

The return type is int type.

# Examples of logical NOT operator
if (!1) {

}

Defined-OR Operator

The defined-OR operator // performs a defined-OR operation. This is the "bestie, if you're not there I'll use the backup" operator, fr fr. ๐Ÿซถ

# defined-OR operator
LEFT_OPERAND // RIGHT_OPERAND

The defined-OR operator performs condition evaluation on the left operand LEFT_OPERAND.

If the evaluated value is not 0, it returns the evaluated value. Otherwise, it returns RIGHT_OPERAND.

The return type is the type of LEFT_OPERAND.

Compilation Errors

  • The left operand type of the defined-OR operator // must be an object type. Otherwise, a compilation error occurs.

Examples

# Examples of defined-OR operator
my $value = "foo";
my $default = "default";
my $ret = $value // $default;

Ternary Operator

The ternary operator performs a ternary operation. Three parts, one result, main character energy honestly. ๐Ÿ‘‘

# ternary operator
CONDITION ? LEFT_OPERAND : RIGHT_OPERAND

The type of LEFT_OPERAND and RIGHT_OPERAND must satisfy the assignment requirement to any object type.

CONDITION is evaluated by condition evaluation.

If the evaluated value is not 0, it returns LEFT_OPERAND. Otherwise, it returns RIGHT_OPERAND.

The return type is the type of LEFT_OPERAND.

Compilation Errors

This section is empty in the original โ€” nothing listed here, so don't go hunting for hidden rules. ๐Ÿ•ต๏ธโ€โ™€๏ธ

Examples

# Examples of ternary operator
my $flag = 1;
my $left = "foo";
my $right = "default";
my $ret = $flag ? $left : $right;

Condition Evaluation

Okay so condition evaluation is the operation performed on the operand at a conditional part of an if statement, a while statement, and the logical operators. It's the whole "is this true or not" vibe check. ๐Ÿงš

Condition evaluation performs the following operations corresponding to the operand type.

The return type is int type.

  • byte:
  • short:
  • int:
    • The integer promotional conversion is performed on the operand.
    • And it returns the value after conversion.
  • undef:
    • Returns 0.
  • BOOL:
    • Returns the "value" field in the Bool object.
  • long:
  • float:
  • double:
  • a reference type:
    • Performs the following C language operation, and returns it:
!!OPERAND
  • an object type:
    • If the compile type of the operand is not the Bool class, it performs the following C language operation, and returns it:
!!OPERAND

Compilation Errors

Like, the operand type of the condition evaluation has to be a numeric type, an object type, a reference type, or the undef type. Anything else? Compilation error, bestie. No vibes pass, it's giving "type check said no" ๐Ÿ˜ญ

Examples:

# Examples of the condition evaluation
if (1) {
  # ok
}

if (0) {
  # not ok
}

if (1.5) {
  # ok
}

if (0.0) {
  # not ok
}

if (true) {
  # ok
}

if (Bool->TRUE) {
  # ok
}

if (false) {
  # not ok
}

if (Bool->FALSE) {
  # not ok
}

my $object = SPVM::Int->new(1);

if ($object) {
  # ok
}

$object = undef;
if ($object) {
  # not ok
}

my $value = 1;
my $ref = \$value;

if ($ref) {
  # ok
}

if (undef) {
  # not ok
}

๐ŸŽ€ Array Length Operator ๐ŸŽ€

Okay so the array length operator "@" gets the length of an array. She's tiny but she knows things โœจ

@OPERAND
@{OPERAND}

This operator returns the length the array OPERAND.

The return type is int type.

If OPERAND is a class type or an interface type, this operation is replaced with "length" method call of Countable interface.

OPERAND->length

Exceptions:

  • OPERAND must be defined. Otherwise, an exception is thrown. ๐Ÿซถ

Compilation Errors:

  • The type of OPERAND must be an array type or a class with Countable interface. Otherwise, a compilation error occurs.

Examples:

# Examples of the array length operator
my $nums = new int[10];
my $length = @$nums;

๐ŸŒธ scalar Operator ๐ŸŒธ

The "scalar" operator returns its operand. That's it. That's the whole job. Iconic low-effort queen ๐Ÿ‘‘

scalar OPERAND

This operator returns the operand OPERAND. OPERAND must be array length operator.

This operator exists only for readability. Literally just for the vibes, no cap.

The return type is int type.

Compilation Errors:

  • OPERAND must be array length operator. Otherwise, a compilation error occurs.

Examples:

# Examples of scalar operator
my $nums = new int[3];
say scalar @$nums;

๐Ÿ’… Sequential Operator ๐Ÿ’…

The sequential operator is an operator with the following syntax.

(OPERAND1, OPERAND2, ..., OPERANDn)

This operator evaluates operands "OPERAND1", "OPERAND1" ... "OPERANDn" from left to right, and returns the value of the rightmost operand "OPERANDn".

The return type is the type of "OPERANDn".

The if statement "IF_STATEMENT" can place directory before "OPERANDn".

(OPERAND1, OPERAND2, ..., IF_STATEMENT, OPERANDn)

Examples:

# Examples of sequential operator

# 3 is assigned to $foo
my $foo = (1, 2, 3);

# $x is 3, $ret is 5
my $x = 1;
my $y = 2;
my $result = ($x += 2, $x + $y);

# Peseud ternary operator
{
  my $condition = 1;
  my $ret = (my $_ = 0, if ($condition) { $_ = 3; } else { $_ = 5; }, $_);
}

๐Ÿ”ฅ Comparison Operators ๐Ÿ”ฅ

Comparison operators compare two operands. Head-to-head, no drama, just facts โœจ

๐Ÿ’œ Numeric Comparison Operators ๐Ÿ’œ

Numeric comparison operators compare two numbers or two addresses of objects.

LEFT_OPERAND == RIGHT_OPERAND
LEFT_OPERAND != RIGHT_OPERAND
LEFT_OPERAND > RIGHT_OPERAND
LEFT_OPERAND >= RIGHT_OPERAND
LEFT_OPERAND < RIGHT_OPERAND
LEFT_OPERAND <= RIGHT_OPERAND
LEFT_OPERAND <=> RIGHT_OPERAND

This operator performs binary numeric conversion on the left operand LEFT_OPERAND and the right operand RIGHT_OPERAND.

And it performs the same operation as the following C language operation, and returns its return value.

(int32_t)(LEFT_OPERAND == RIGHT_OPERAND);
(int32_t)(LEFT_OPERAND != RIGHT_OPERAND);
(int32_t)(LEFT_OPERAND > RIGHT_OPERAND);
(int32_t)(LEFT_OPERAND >= RIGHT_OPERAND);
(int32_t)(LEFT_OPERAND < RIGHT_OPERAND);
(int32_t)(LEFT_OPERAND <= RIGHT_OPERAND);
(int32_t)(LEFT_OPERAND > RIGHT_OPERAND ? 1 : LEFT_OPERAND < RIGHT_OPERAND ? -1 : 0);

The return type is int type.

Compilation Errors:

"==", "!="

  • The type of the LEFT_OPERAND must be a numeric type, an object type, a reference type, or the undef type. Otherwise, a compilation error occurs.
  • The type of the RIGHT_OPERAND must be a numeric type, an object type, a reference type, or the undef type. Otherwise, a compilation error occurs.
  • If the type of the LEFT_OPERAND is a numeric type, the type of the RIGHT_OPERAND must be a numeric type. Otherwise, a compilation error occurs.
  • If the type of the LEFT_OPERAND is an object type, the type of the RIGHT_OPERAND must be an object type or the undef type. Otherwise, a compilation error occurs.
  • If the type of the LEFT_OPERAND is the undef type, the type of the RIGHT_OPERAND must be an object type or the undef type. Otherwise, a compilation error occurs.
  • If the type of the LEFT_OPERAND is a reference type, the type of the RIGHT_OPERAND must be a reference type or undef type. Otherwise, a compilation error occurs.

"<", "<=", ">", ">=", "<=>"

  • The type of the LEFT_OPERAND must be a numeric type. Otherwise, a compilation error occurs.
  • The type of the RIGHT_OPERAND must be a numeric type. Otherwise, a compilation error occurs.

๐Ÿฆ‹ String Comparison Operators ๐Ÿฆ‹

String comparison operators compare tow strings in the dictionary order.

LEFT_OPERAND eq RIGHT_OPERAND
LEFT_OPERAND ne RIGHT_OPERAND
LEFT_OPERAND gt RIGHT_OPERAND
LEFT_OPERAND ge RIGHT_OPERAND
LEFT_OPERAND lt RIGHT_OPERAND
LEFT_OPERAND le RIGHT_OPERAND
LEFT_OPERAND cmp RIGHT_OPERAND

These operators perform the following operations.

The return type is int type.

Compilation Errors.

  • The type of LEFT_OPERAND must be string type or the byte[] type. Otherwise, a compilation error occurs.
  • The type of RIGHT_OPERAND must be string type or the byte[] type. Otherwise, a compilation error occurs.

โญ Constant Operator โญ

The constant operator gets a constant value represented by a literal. Like, the plainest, most honest operator out there ๐Ÿซถ

LITERAL

LITERAL is a literal.

The return type is the type of LITERAL.

Compilation Errors:

  • Compilation errors casued by literal syntax could occur.

๐Ÿ“ length Operator ๐Ÿ“

The "length" operator gets the length of a string. String measurement era ๐Ÿ’…

length OPERAND

If the string OPERAND is defind, this operator returns the length of OPERAND. Note that this length is in bytes, not the number of UTF-8 characters.

If OPERAND is not defined, returns 0.

The return type is int type.

Compilation Errors:

  • The type of OPERAND must be string type. Otherwise, a compilation error occurs.

Examples:

# Examples of The length operator

# The length is 5
my $message = "Hello";
my $length = length $message;

# The length is 9
my $message = "ใ‚ใ„ใ†";
my $length = length $message;
Bestie fr fr, clock that byte-vs-character thing ๐Ÿ‘€ "ใ‚ใ„ใ†" is three whole characters but the length there is 9, because bytes. That's not a bug, that's the tea.

๐ŸŒˆ capacity Operator ๐ŸŒˆ

The "capacity" operator gets the capacity of a string or an array.

capacity OPERAND

This operator returns the capacity of OPERAND.

The return type is int type.

Exceptions:

  • OPERAND must be defined. Otherwise, an exception is thrown.

Compilation Errors:

  • The type of OPERAND must be string type or an array type. Otherwise, a compilation error occurs.

Examples:

# Examples of capacity operator

# The capacity is 5
my $message = "Hello";
my $capacity = capacity $message;

๐Ÿ’– String Concatenation Operator ๐Ÿ’–

The string concatenation operator "." concats two strings. Gluing era, we love to see it โœจ

LEFT_OPERAND . RIGHT_OPERAND

This operator performs numeric-to-string conversion on the left operand LEFT_OPERAND if the type of LEFT_OPERAND is a numeric type.

And it performs numeric-to-string conversion on the right operand RIGHT_OPERAND if the type of RIGHT_OPERAND is a numeric type.

And it concats LEFT_OPERAND and RIGHT_OPERAND, and returns its return value.

The type of LEFT_OPERAND and RIGHT_OPERAND are allowed to be the byte[] type.

The return type is string type.

Exceptions:

  • LEFT_OPERAND must be defined. Otherwise, an exception is thrown.
  • RIGHT_OPERAND must be defined. Otherwise, an exception is thrown.

Compilation Errors:

  • The type of LEFT_OPERAND must be string type, the byte[] type, or a numeric type. Otherwise, a compilation error occurs.
  • The type of RIGHT_OPERAND must be string type, the byte[] type, or a numeric type. Otherwise, a compilation error occurs.

Examples:

# Examples of the string concatenation operator
my $result = "abc" . "def";
my $result = "def" . 34;

๐Ÿงš new_string_len Operator ๐Ÿงš

The "new_string_len" operator creates a new string with a length. Fresh string, zero vibes, all \0 ๐Ÿ’€

new_string_len OPERAND

This operator performs integer promotional conversion on the length OPERAND.

And creates a new string with the length, fills all characters in the string with "\0", and returns it.

The return type is mutable string type.

Exceptions:

  • OPERAND must be greater than or equal to 0. Otherwise, an exception is thrown.

Compilation Errors:

  • The type of OPERAND must be an integer type within int. Otherwise, a compilation error occurs.

Examples:

# Examples of new_string_len operator
my $message = new_string_len 5;

๐ŸŽ€ make_read_only Operator ๐ŸŽ€

The "make_read_only" operator makes a string read-only. Locking her down, respectfully ๐Ÿ”’

make_read_only OPERAND

If the string OPERAND is defined, this operator makes OPERAND read-only.

A read-only string cannnot be cast to mutable string type. If so, an exception is thrown.

The return type is the void type.

Compilation Errors:

  • OPERAND must be string type. Otherwise, a compilation error occurs.

Examples:

# Examples of make_read_only operator

# A string
my $string = new_string_len 3;

# Make the string read-only
make_read_only $string;

# The conversion to the mutable string type throw an exception.
my $string_mutable = (mutable string)$string;
That last line? Compilation-error-adjacent behaviour, the cast to mutable string type throws an exception. Don't do it unless you want the drama ๐Ÿ˜ญ

๐Ÿ‘‘ make_fixed_length Operator ๐Ÿ‘‘

The "make_fixed_length" operator makes a string or an array fixed length. Set in her ways, periodt ๐Ÿ’…

make_fixed_length OPERAND

If OPERAND is defined, this operator makes OPERAND fixed length.

A fixed length string or array cannnot change its length and capacity. If so, an exception is thrown.

The return type is the void type.

Compilation Errors:

  • OPERAND must be string or an array type. Otherwise, a compilation error occurs.

Examples:

# Examples of make_fixed_length operator

# A string
my $string = new_string_len 3;

# Make the string read-only
make_fixed_length $string;

๐ŸŒŸ enable_options Operator ๐ŸŒŸ

The "enable_options" operator enables "options" flag of an object. Flipping switches, we stan ๐Ÿซถ

enable_options OPERAND

The type of object OPERAND must be an object type.

If OPERAND is defined and its type is any object array type "object[]", this operator enables "options" flag of OPERAND.

The return type is void type.

Compilation Errors:

The type of OPERAND must be an object type. Otherwise, a compilation error occurs.

Examples:

# Examples of enable_options operator
my $options = [(object)max => 1, title => "Hello"];
enable_options $options;

๐Ÿ’… disable_options Operator

The disable_options operator does the exact opposite of its sibling โ€” it disables the options flag on an object. Turning it off, bestie. Switched off. Bye ๐Ÿ‘‹

disable_options OPERAND

The type of object OPERAND must be an object type ๐Ÿซถ

If OPERAND is defined, this operator disables the options flag of OPERAND.

The return type is void type.

Compilation Errors:

The type of OPERAND must be an object type. Otherwise, a compilation error occurs.

Examples:

# Examples of disable_options operator
my $options = {max => 1, title => "Hello"};
disable_options $options;

๐Ÿฆ‹ is_options Operator

The is_options operator is the little vibe check โ€” it peeks at an object's options flag and tells you if it's enabled or not ๐Ÿ‘‘

is_options OPERAND

The type of object OPERAND must be an object type.

If OPERAND is defined and the options flag of OPERAND is enabled, the is_options operator returns 1; otherwise it returns 0. Very yes/no of it โœจ

The return type is int type.

Compilation Errors:

The type of OPERAND must be an object type. Otherwise, a compilation error occurs.

Examples:

# Examples of is_options operator
my $options = {max => 1, title => "Hello"};
my $is_options = is_options $options;

๐ŸŒธ is_read_only Operator

The is_read_only operator checks whether a string is read-only โ€” aka is it locked down and untouchable ๐Ÿ”’

is_read_only OPERAND

If the string OPERAND is defined and read-only, the is_read_only operator returns 1, otherwise it returns 0.

The return type is int type.

Compilation Errors:

OPERAND must be string type. Otherwise, a compilation error occurs.

Examples:

# Examples of is_read_only operator
my $message = "Hello";
my $is_read_only = is_read_only $message;

๐ŸŽ€ is_fixed_length Operator

The is_fixed_length operator checks if a string or an array is read-only. Yeah โ€” this one covers both, she's versatile like that ๐Ÿ’…

is_fixed_length OPERAND

If OPERAND is defined and fixed length, the is_fixed_length operator returns 1, otherwise it returns 0.

The return type is int type.

Compilation Errors:

OPERAND must be string or an array type. Otherwise, a compilation error occurs.

Examples:

# Examples of is_fixed_length operator
my $message = (mutable string)copy "Hello";
my $is_fixed_length = is_fixed_length $message;

The print operator prints a string to standard output. Classic. Iconic. The original ๐Ÿ’–

print OPERAND
print STDERR OPERAND

This operator outputs the string OPERAND to SPVM's standard output.

If OPERAND is not defined, this operator outputs nothing. Not even a sneaky space. Nothing. ๐Ÿ™ˆ

The return type is void type.

If STDERR is specified, prints the output to SPVM's standard error.

Compilation Errors:

OPERAND must be string type. Otherwise, a compilation error occurs.


๐ŸŒˆ say Operator

The say operator is print's extroverted cousin โ€” same thing, but she always adds a newline at the end ๐Ÿ’ซ

say OPERAND
say STDERR OPERAND

This operator outputs the string OPERAND to SPVM's standard output with a newline "\n".

If OPERAND is not defined, this operator outputs a newline "\n" โ€” that's it, just a lil line break, and honestly? valid.

The return type is void type.

If STDERR is specified, prints the output to SPVM's standard error.

Compilation Errors:

OPERAND must be string type. Otherwise, a compilation error occurs.


โš ๏ธ warn Operator

The warn operator prints a string to standard error with a stack trace attached. It's giving "hey bestie, something's up, and here's exactly where" ๐Ÿšจ

warn
warn OPERAND

If OPERAND is omitted, OPERAND is set to the string "Warning".

This operator outputs OPERAND to SPVM's standard error.

If OPERAND is not defined, this operator outputs the string "undef".

If the type of OPERAND is string type and OPERAND is defined, this operator outputs OPERAND.

If the type of OPERAND is an object type except for string type and OPERAND is defined, this operator outputs the type name and the address of OPERAND, such as "Point(0x55d8a44ed090)".

If the type of OPERAND is a reference type, this operator outputs the return value of address Operator such as "0x55d8a44ed090".

This operator outputs a newline, two tabs and a stack trace information following the output above.

A stack trace information consists of the current method name, file name, and line number.

MyClass->test at path/MyClass.spvm line 33

The return type is void type.

Compilation Errors:

The type of OPERAND must be a numeric type, an object type, or a reference type. Otherwise, a compilation error occurs.

Examples:

warn;
warn "Something is wrong.";

# Point(0x55d8a44ed090)
my $point = Point->new;
warn $point;

๐Ÿ”ฅ warn_level Operator

The warn_level operator is the multi-tool of warnings โ€” she warns, or dies, or does absolutely nothing, all depending on a LEVEL ๐Ÿ’€

warn_level OPERAND, LEVEL

This operator expects two operands. OPERAND is a message, and LEVEL is an integer value that determines the behavior.

This operator behaves differently depending on the value of LEVEL:

  • If LEVEL is a negative value (less than 0), this operator does nothing.
  • If LEVEL is 0, this operator calls warn Operator with OPERAND.
  • If LEVEL is a positive value (greater than 0), this operator calls die statement with OPERAND.

If OPERAND is not defined, it is treated the same way as in warn Operator or die statement.

The return type is void type.

Compilation Errors:

The type of OPERAND must be a numeric type, an object type, or a reference type. Otherwise, a compilation error occurs.

The type of LEVEL must be an integer type. Otherwise, a compilation error occurs.

Examples:

# Ignore
warn_level "This is ignored.", -1;

# Same as warn "This is a warning.";
warn_level "This is a warning.", 0;

# Same as die "This is a fatal error.";
warn_level "This is a fatal error.", 1;

๐Ÿฉบ diag Operator

Same as warn operator. That's it. That's the whole vibe. She's a rebrand of an icon ๐Ÿ’œ


๐Ÿ“ address Operator

The address operator gets the address of an object or a reference as a hex string โ€” like a lil name tag for exactly where it lives in memory ๐Ÿ 

address OPERAND

This operator gets the address of OPERAND and converts it to a hex string (such as 0x7ffee23b8ac4), and returns it.

The return type is string type.

The type of OPERAND must be an object type or a reference type.

Compilation Errors:

The type of OPERAND must be an object type or a reference type. Otherwise compilation error occurs.


๐Ÿ“ __FILE__ Operator

The __FILE__ operator gets the path of the file where the current class is defined. Nosy? maybe. Useful? absolutely ๐Ÿ’–

__FILE__

This operator creates a string with the path of the file where the current class is defined, and returns it.

The return type is string type.

The return value can be changed by file directive.

Examples:

# Examples of __FILE__ operator
class Foo::Bar {
  static method baz : void () {
    # path/SPVM/Foo/Bar.spvm
    my $file_name = __FILE__;
  }
}

๐Ÿ”ข __LINE__ Operator

The __LINE__ operator gets the current line number. Literally just tells you where you are, no cap ๐Ÿงญ

__LINE__

This operator returns the current line number.

The return type is int type.

Examples:

# Examples of __LINE__ operator
class Foo::Bar {
  static method baz : void () {
    my $line = __LINE__;
  }
}

๐Ÿ‘‘ __PACKAGE__ Operator

The __PACKAGE__ operator gets the name of the outmost class. The main character's name, if you will ๐ŸŒŸ

__PACKAGE__

This operator creates a string with the name of outmost class, and returns it.

The return type is string type.

Examples:

class Foo::Bar {
  static method baz : void () {
    # Foo::Bar
    my $outmost_class_name = __PACKAGE__;

    my $anon_method = method : void () {
      # Foo::Bar
      my $outmost_class_name = __PACKAGE__;
    };
  }
}

โœจ new Operator

The new operator creates a new object, a new array, and a new multi-dimensional array. She builds everything. She's the whole construction crew ๐Ÿ—๏ธ๐Ÿ’…

See also use statement about the way to load classes.

See also SPVM::Document::Language::GarbageCollection about garbage collection of objects.

๐ŸŽ€ Creating an Object

The following syntax of new operator creates a new object.

new CLASS_TYPE;

The class type CLASS_TYPE must be a loaded class type.

This operator creates a new object of CLASS_TYPE, and returns it.

The fields of the new object are initialized by its type initial value.

The return type is CLASS_TYPE.

Compilation Errors:

CLASS_TYPE must be a loaded class type. Otherwise, a compilation error occurs.

Examples:

# Examples of new operator - Creating a new object
my $object = new Foo;

๐Ÿฆ‹ Creating an Array

The following syntax of new operator creates a new array.

new BASIC_TYPE[LENGTH]

The basic type BASIC_TYPE must be a loaded basic type.

This operator performs integer promotional conversion on the length LENGTH.

And creates a new array of the length LENGTH which element type is BASIC_TYPE.

And all elements of the new array are initialized by its type initial value.

And returns the new array.

The return type is BASIC_TYPE[].

Exceptions:

LENGTH must be greater than or equal to 0. Otherwise, an exception is thrown.

Compilation Errors:

LENGTH must be an integer type within int. Otherwise, a compilation error occurs.

Examples:

# Examples of new operator - Creating a new array
my $values = new int[3];
my $objects = new Foo[3];
my $objects = new object[3];
my $mulnum_values = new Complex_2d[3]

๐ŸŒˆ Creating a Multi-Dimensional Array

The following syntax of new operator creates a new multi-dimensional array.

new BASIC_TYPE[]..[LENGTH]

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

The basic type BASIC_TYPE must be a loaded basic type.

This operator performs integer promotional conversion on the length LENGTH.

And creates a new multi-dimensional array of the length LENGTH which element type is BASIC_TYPE[]...

And all elements of the new multi-dimensional array are initialized by its type initial value.

And returns the new multi-dimensional array.

The return type is BASIC_TYPE[]..[].

Exceptions:

LENGTH must be greater than or equal to 0. Otherwise, an exception is thrown.

Compilation Errors:

LENGTH must be an integer type within int. Otherwise, a compilation error occurs.

The type dimension must be less than or equal to 255. Otherwise, a compilation error occurs.

Examples:

# Examples of new operator - Creating a new multi-dimensional array

# 2 dimentional int array
my $muldim_values = new int[][3];

# 3 dimentional int array
my $muldim_values = new int[][][3];

๐Ÿฆ‹ Array Initialization

The syntax of the array initialization creates a new array, sets the elements, and hands you back that brand new array. It's giving "fresh out the box" energy โœจ

[ELEMENT1, ELEMENT2, .., ELEMENTn]

And bestie, this is literally expanded to the following code:

(
  # Create a new array
  my $array = new ELEMENT1_TYPE[n],

  # Set elements
  $array->[0] = ELEMENT1,
  $array->[1] = ELEMENT2,
  ...,
  $array->[n - 1] = ELEMENTn,
  $array,
)

ELEMENT1_TYPE is the type of ELEMENT1. That's the whole vibe check.

If elements does not exist, ELEMENT1_TYPE is the any object type object, n is 0, and setting elements is not performed. Empty array, no notes ๐Ÿ’…

The return type is ELEMENT1_TYPE[].

Compilation Errors:

If the type of ELEMENT1 is the undef type, a compilation error occurs. Not the move, fr fr.

Examples:

# Examples of the array initialization

# int array
my $nums = [1, 2, 3];

# double array
my $nums = [1.5, 2.6, 3.7];

# string array
my $strings = ["foo", "bar", "baz"];

The int array example is expanded to the following code.

# int array
my $nums = new int[3];
$nums->[0] = 1;
$nums->[1] = 2;
$nums->[2] = 3;

๐ŸŽ€ Key-Value Array Initialization

The syntax of the key-value array initialization creates a new array, sets the elements with key-value pairs, and returns the new array.

{ELEMENT1, ELEMENT2, ELEMENT3, ELEMENT4}

This syntax is the same as "Array Initialization", but the return type is always any object array type object[]. Always. No exceptions, periodt.

And the length of the elements must be an even number. Odd numbers? Compilation error, sorry babe ๐Ÿ™ˆ

The array created in this way is called "Options" and options flag of this object is enabled.

Compilation Errors:

The length of the elements must be an even number, a compilation error occurs.

Examples:

# Examples of the key-value array initialization

# Empty
my $key_values = {};

# Key values
my $key_values = {foo => 1, bar => "Hello"};

๐ŸŒธ Options

The object of object[] type created by "Key-Value Array Initialization" is called "Options".

# Called "Options"
{foo => 1, bar => 2}

๐Ÿงš Anon Method Operator

An anon method operator creates an object of an anon method class. Iconic behavior, honestly.

ANON_METHOD_CLASS_DEFINTION

This operator defines an anon method class using anon method class definition ANON_METHOD_CLASS_DEFINTION, creates a new object from the class, and returns it. (The original page says "retunrs", we love a typo moment ๐Ÿ˜ญ)

If the anon method class field definition in ANON_METHOD_CLASS_DEFINTION has field default values, the fields of the anon method object are set to these values.

Examples:

# Examples of the anon method operator
my $comparator = (Comparator)method : int ($x1 : object, $x2 : object) {
  my $point1 = (Point)$x1;
  my $point2 = (Point)$x2;

  return $point1->x <=> $point2->x;
};

# With an anon method class field definition
my $num = 1;
my $comparator = [$num : int] (Comparator)method : int ($x1 : object, $x2 : object) {
  my $point1 = (Point)$x1;
  my $point2 = (Point)$x2;

  say $num;

  return $point1->x <=> $point2->x;
};

๐Ÿ’œ undef Operator

The undef operator returns an undefined value. That's it. That's the whole job. Nothing. Void. The absence of everything ๐Ÿ’€

undef

The return type is undef type.

Examples:

# Examples of undef operator
my $string = (string)undef;

if (undef) {

}

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

}

๐Ÿ“ copy Operator

The copy operator copies a numeric array, a multi-numeric array or a string. Dupe it, bestie ๐Ÿ’…

copy OPERAND

If the operand OPERAND is not an undefined value, this operator creates a new object of the same type as the operand OPERAND, and copies the elements of the array or the characters of the string into the new object, and returns it.

If OPERAND is not defined, this operator returns an undefined value. Undefined in, undefined out, that's the rule โœจ

The read-only flag of the string is not copied. Just so we're clear.

The return type is the type of OPERAND.

Compilation Errors:

The operand type must be string type, a numeric array type, or a multi-numeric array type. Otherwise, a compilation error occurs.

Examples:

# Exampels of copy operator
my $message = copy "abc";

๐Ÿ”ฅ dump Operator

The dump operator gets the string representation dumping the data contained in the object. It's like a little x-ray for your object, ngl ๐Ÿ”

dump OPERAND

This operator creates a new string with the string representation dumping the data contained in the object OPERAND and returns it.

The following is an example of the return value the dump operator.

# An return vlaue of dump operator
TestCase::Operator::DumpTest1 (0x55f21f7e6050) {
  byte_value => 1,
  short_value => 2,
  int_value => 3,
  long_value => 4,
  float_value => 1.1,
  double_value => 1.2,
  string_value => "a",
  int_array => [
    1,
    2,
    3
  ] : int[](0x55f21fb9b8d0),
  object_value => TestCase::Operator::DumpTest1 (0x55f21f764640) {
    byte_value => 0,
    short_value => 0,
    int_value => 0,
    long_value => 0,
    float_value => 0,
    double_value => 0,
    string_value => undef,
    int_array => undef,
    object_value => undef
  }
}

The return type is string type.

Okay so hear me โ€” the string representation might be changed to make it more readable. So don't use the dump operator for the purpose of the data serialization. Ever. It's not that girl, it's not a stable format, do NOT serialize with it ๐Ÿ˜ญ

Compilation Errors:

OPERAND must be an object type, otherwise a compilation error occurs.


๐Ÿฆ‹ Reference Operator

The reference operator \ creates the reference to the value owned by a variable. Pointing at things, iconic.

\VARIALBE

This operator creates the reference to the value owned by the variable VARIALBE, and returns it.

VARIALBE is must be a local variable of a numeric type or a multi-numeric type.

The return type is Reference Types of VARIALBE.

Compilation Errors:

VARIALBE must be a local variable of a numeric type or a multi-numeric type. Otherwise, a compilation error occurs.

Examples:

# Examples of reference operator

# Create a reference of a numeric type
my $num : int;
my $num_ref = \$num;

# Create a reference of a multi-numeric type
my $z : Complex_2d;
my $z_ref = \$z;

๐Ÿ‘‘ Dereference Operator

The dereference operator $ gets a referenced value. Follow the pointer, bestie, it's a scavenger hunt ๐Ÿ—บ๏ธ

$VARIABLE

This operator returns the value referenced by the variable VARIABLE of a reference type.

The return type is the type of the value referenced by VARIABLE.

Compilation Errors:

The type of VARIABLE must be a reference type. Otherwise, a compilation error occurs.

Exceptions:

If VARIABLE is undef, an exception is thrown. Buckle up ๐Ÿ’€

Examples:

# Examples of dereference operator
my $num : int;
my $num_ref = \$num;
my $num_deref = $$num_ref;

my $z : Complex_2d;
my $z_ref = \$z;
my $z_deref = $$z_ref;

๐ŸŒˆ Assignment Operator

The assignment operator = performs an assignment. The moment we've all been waiting for.

LEFT_OPERAND = RIGHTH_OPERAND

A data conversion described in Assignment Requirement is performed on RIGHTH_OPERAND if necessary.

And assignment operator performs different operations depending on the left operand LEFT_OPERAND.

  • If LEFT_OPERAND is a local variable, this operator performs the operation that sets a local variable.
  • If LEFT_OPERAND is a class variable, this operator performs the operation that sets a class variable.
  • If LEFT_OPERAND is an element access, this operator performs the operation that sets an array element.
  • If LEFT_OPERAND is a field access, this operator performs the operation that sets a field.
  • If LEFT_OPERAND is a dereference, this operator performs the operation that sets a referenced value.
  • If LEFT_OPERAND is the exception variable, this operator performs the operation that sets the exception variable.

See also "Assignment" in SPVM::Document::Language::GarbageCollection about how assignment operator changes the reference counts of LEFT_OPERAND and RIGHTH_OPERAND. Important lore, go read it ๐Ÿซถ

Examples:

# Examples of assignment operator

# A local variable
$num = 1;

# A class variable
$NUM = 1;

# A field access
$point->{x} = 1;

# An element access
$nums->[0] = 1;

# A dereference
$$num_ref = 1;

# The exception variable
$@ = 2;

โญ Special Assignment Operators

A special assignment operator is the combination of an operator such as +, - and assignment operator =. Glow-up combo move โœจ

LEFT_OPERAND OPERATOR= RIGHTH_OPERAND

A special assignment operator is expanded to the following code.

LEFT_OPERAND = (TYPE_OF_LEFT_OPERAND)(LEFT_OPERAND OPERATOR RIGHTH_OPERAND)

See the following code using a special assignment operator +=. $x is int type.

$x += 2;

This is expanded to the following code.

$x = (int)($x + 2)

List of Special Assignment Operators:

Examples:

# Special assignment operators
$x += 1;
$x -= 1;
$x *= 1;
$x /= 1;
$x &= 1;
$x |= 1;
$x ^= 1;
$x %= 1;
$x <<= 1;
$x >>= 1;
$x >>>= 1;
$x .= "abc";

๐ŸŽ€ Get and Set Operations

๐Ÿ’– Local Variable Get Operation

The operation of getting local variable gets the value of a local variable.

$var

$var is a local variable access.

This operation returns the value of $var.

The return type is the type of $var.

Compilation Errors:

Compilation errors caused by the syntax of local variable access could occur.

Examples:

$var;

๐Ÿฉท Local Variable Set Operation

The operation of setting a local variable sets a local variable.

$var = OPERAND

$var is a local variable access.

This operation sets $var to OPERAND using assignment operator, and returns the value after setting. Yes, it gives you the value back, cute right?

The return value is the type of $var.

Compilation Errors:

Compilation errors caused by the syntax of local variable access could occur.

The assignment must satisfy assignment requirement. Otherwise, a compilation error occurs.

Examples:

$var = 3;

๐ŸŒธ Local Variable Access

The local variable access has the following syntax.

VAR_NAME

See Variable Name Resolution about VAR_NAME and the resolution of a local variable name.

Examples:

$var

๐ŸŒŸ Class Variable Get Operation

The operation of getting a class variable gets the value of a class variable.

$VAR

$VAR is a class variable access.

This operation returns the value of $VAR.

The return type is the type of $VAR.

Compilation Errors:

Compilation errors caused by the syntax of class variable access could occur.

Examples:

and here's the example for that class-variable-get section, exact as ever, bestie:

# Examples of getting a class variable
class Foo {
  our $VAR : int;

  static method bar : int () {

    my $var1 = $Foo::VAR;

    # $Foo::VAR
    my $var2 = $VAR;

    my $anon_method = method : void () {
      # $Foo::BAR
      $VAR;
    }
  }
}

๐Ÿ’… Class Variable Set Operation

Setting a class variable is literally the assignment flex:

$VAR = OPERAND

$VAR is a class variable access.

This operation sets $VAR to OPERAND using the assignment operator, and returns the value after setting.

The return type is the type of $VAR.

Compilation Errors:

  • Compilation errors caused by the syntax of class variable access could occur.
  • The assignment must satisfy assignment requirement. Otherwise, a compilation error occurs.

Examples:

# Examples of setting a class variable
class Foo {
  our $VAR : int;

  static method bar : int () {
    $Foo::VAR = 1;

    # $Foo::VAR = 3
    $VAR = 3;
  }
  my $anon_method = method : void () {
    # $Foo::VAR = 5
    $VAR = 5;
  }
}

โœจ Class Variable Access โœจ

The class variable access has this syntax, no cap:

VAR_NAME
CLASS_TYPE::VAR_NAME

See Variable Name Resolution about VAR_NAME, CLASS_TYPE, and the resolution of a class variable name.

Examples:

$VAR
$MyClass::VAR

๐ŸŽ€ Array Element Get Operation ๐ŸŽ€

The operation of getting an array element gets an element of an array. It's giving "gimme that one specific thing":

ARRAY->[INDEX]

ARRAY->[INDEX] is an element access.

This operator performs integer promotional conversion on INDEX.

And returns the element of ARRAY at INDEX.

The return type is the element type of ARRAY.

Exceptions:

  • ARRAY must be defined. Otherwise, an exception is thrown.
  • INDEX must be greater than or equal to 0. Otherwise, an exception is thrown.

Compilation Errors:

  • Compilation errors caused by the syntax of element access could occur.

Examples:

my $nums = new int[3];
my $num = $nums->[1];

my $points = new Point[3];
my $point = $points->[1];

๐ŸŒธ Array Element Set Operation ๐ŸŒธ

The operation of setting array element sets an element of an array. Assignment era:

ARRAY->[INDEX] = OPERAND

ARRAY->[INDEX] is an element access.

This operator performs integer promotional conversion on INDEX.

And sets the element of ARRAY at INDEX to OPERAND using assignment operator, and returns the element after setting.

The return type is the element type.

Exceptions:

  • ARRAY must be defined. Otherwise, an exception is thrown.
  • INDEX must be greater than or equal to 0. Otherwise, an exception is thrown.

Compilation Errors:

  • Compilation errors caused by the syntax of element access could occur.
  • The assignment must satisfy assignment requirement. Otherwise, a compilation error occurs.

Examples:

my $nums = new int[3];
$nums->[1] = 3;

my $points = new Point[3];
$points->[1] = Point->new(1, 2);

๐Ÿฆ‹ List Element Get Operation ๐Ÿฆ‹

The list element get operation gets an element of a list object with an index:

INVOCANT->[INDEX_OPERAND]

INVOCANT->[INDEX_OPERAND] is a array element access.

This operation is replaced with "get" method call:

INVOCANT->get(INDEX_OPERAND)

Compilation Errors:

  • Compilation errors caused by the syntax of array element access could occur.

Examples:

my $list = List->new([1, 2]);
my $x = $list->[1];

๐Ÿ’– List Element Set Operation ๐Ÿ’–

The list element set operation sets an element of a list object with an index:

INVOCANT->[INDEX_OPERAND] = OPERAND

INVOCANT->[INDEX_OPERAND] is a array element access.

This operation is replaced with "set" method call:

INVOCANT->set(INDEX_OPERAND, OPERAND)

Compilation Errors:

  • Compilation errors caused by the syntax of array element access could occur.
  • The assignment must satisfy assignment requirement. Otherwise, a compilation error occurs.

Examples:

my $list = List->new([1, 2]);
$list->[1] = 3;

๐Ÿซถ Array Element Access ๐Ÿซถ

The element access has the following syntax:

ARRAY->[INDEX]

The type of the array ARRAY is an array type.

The type of the index INDEX is an integer type within int.

If INDEX is a minus value, it is set to INDEX plus the length of the array.

Exceptions:

  • If INDEX is less than 0 or more than or equal to the length of the array, an exception is thrown.

Compilation Errors:

  • ARRAY must be an array type, string type, a class type, or an interface type. Otherwise, a compilation error occurs.
  • INDEX must be an integer type within int. Otherwise, a compilation error occurs.

๐Ÿ˜ญ Character Get Operation ๐Ÿ˜ญ

The operation of getting a character gets a character of a string:

STRING->[INDEX]

STRING->[INDEX] is a character access.

The type of STRING is string type.

This operator performs integer promotional conversion on INDEX.

And returns the character of STRING at INDEX.

The return type is byte type.

Exceptions:

  • STRING must be defined. Otherwise, an exception is thrown.
  • INDEX must be greater than or equal to 0. Otherwise, an exception is thrown.

Compilation Errors:

  • Compilation errors caused by the syntax of character access could occur.

Examples:

my $string = "abc";
my $char = $string->[0];

๐Ÿ”ฅ Character Set Operation ๐Ÿ”ฅ

The operation of setting a character sets the character of a string:

STRING->[INDEX] = OPERAND

STRING->[INDEX] is a character access.

This operator performs integer promotional conversion on INDEX.

And sets the character of STRING at INDEX to OPERAND using assignment operator, and returns the character after setting.

The return type is byte type.

Exceptions:

  • STRING must be defined. Otherwise, an exception is thrown.
  • INDEX must be greater than or equal to 0. Otherwise, an exception is thrown.
  • If STRING is not a mutable string, an exception is thrown.

Compilation Errors:

  • Compilation errors caused by the syntax of character access could occur.
  • The assignment must satisfy assignment requirement. Otherwise, a compilation error occurs.

Examples:

my $string = new_string_len 3;
$string->[0] = 'a';

๐Ÿ‘‘ Character Access ๐Ÿ‘‘

The character access has the following syntax:

STRING->[INDEX]

The type of the string STRING is string type.

The type of the index INDEX is an integer type within int.

Compilation Errors:

  • STRING must be string type. Otherwise, a compilation error occurs.
  • INDEX must be an integer type within int. Otherwise, a compilation error occurs.

๐ŸŒˆ Field Get Operation ๐ŸŒˆ

The operation of getting field gets the value of a field of a class type:

INVOCANT->{FIELD_NAME}

INVOCANT->{FIELD_NAME} is a field access.

This operation gets the value of the field specified by FIELD_NAME of the type of INVOCANT.

The return type is the type of the field.

Compilation Errors:

  • Compilation errors caused by the syntax of field access could occur.

Examples:

my $point = Point->new;
my $x = $point->{x};

โญ Field Set Operation โญ

The operation of setting field sets the field of a class type:

INVOCANT->{FIELD_NAME} = OPERAND

INVOCANT->{FIELD_NAME} is a field access.

The type of INVOCANT is a class type.

This operation sets the field specified by FIELD_NAME of the type of INVOCANT to OPERAND using assignment operator, and returns the value of the field after setting.

The return type is the field type.

Compilation Errors:

  • Compilation errors caused by the syntax of field access could occur.
  • The assignment must satisfy assignment requirement. Otherwise, a compilation error occurs.

Examples:

my $point = Point->new;
$point->{x} = 1;

๐Ÿ’€ Multi-Numeric Field Get Operation ๐Ÿ’€

The operation of getting a multi-numeric field gets the value of a field of a multi-numeric type:

INVOCANT->{FIELD_NAME}

INVOCANT->{FIELD_NAME} is a field access.

The type of INVOCANT is a multi-numeric type.

This operation gets the value of the field specified by FIELD_NAME of the type of INVOCANT.

The return type is the type of the field.

Compilation Errors:

  • Compilation errors caused by the syntax of field access could occur.

Examples:

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

๐Ÿ™ˆ Multi-Numeric Field Set Operation ๐Ÿ™ˆ

The operation of setting multi-numeric field sets the field of multi-numeric type:

INVOCANT->{FIELD_NAME} = OPERAND

INVOCANT->{FIELD_NAME} is a field access.

The type of INVOCANT is a multi-numeric type.

This operation sets the field specified by FIELD_NAME of the type of INVOCANT to OPERAND using assignment operator, and returns the value of the field after setting.

The return type is the field type.

Compilation Errors:

  • Compilation errors caused by the syntax of field access could occur.
  • The assignment must satisfy assignment requirement. Otherwise, a compilation error occurs.

Examples:

my $z : Complex_2d;
$z->{re} = 2.5;

๐Ÿ“ Referenced Multi-Numeric Field Get Operation ๐Ÿ“

The operation of getting a multi-numeric field gets the value of a field of a multi-numeric type referenced by a multi-numeric Reference Types.

This operation is expanded to the following code:

($INVOCANT)->{FIELD_NAME}

The type of INVOCANT is a multi-numeric reference type.

Compilation Errors:

  • Compilation errors caused by the syntax of field access could occur.
  • Compilation errors caused by dereference operator could occur.

Exceptions:

  • If INVOCANT is undef, an exception is thrown.

Examples:

my $z : Complex_2d;
my $z_ref = \$z;
my $re = $z_ref->{re};

๐Ÿงš Referenced Multi-Numeric Field Set Operation ๐Ÿงš

The operation of setting a multi-numeric field sets the value of a field of a multi-numeric type referenced by a multi-numeric Reference Types.

This operation is expanded to the following code:

($INVOCANT)->{FIELD_NAME} = OPERAND

The type of INVOCANT is a multi-numeric reference type.

Compilation Errors:

  • Compilation errors caused by the syntax of field access could occur.
  • Compilation errors caused by dereference operator could occur.
  • The assignment must satisfy assignment requirement. Otherwise, a compilation error occurs.

Exceptions:

  • If INVOCANT is undef, an exception is thrown.

Examples:

my $z : Complex_2d;
my $z_ref = \$z;
$z_ref->{re} = 2.5;

๐Ÿ’œ Hash Value Get Operation ๐Ÿ’œ

The operation of getting field gets the value of a field of a class type:

INVOCANT->{KEY_OPERAND}

is a hash value access, bestie ๐Ÿ’… and the compiler straight-up swaps it out for a get method call:

INVOCANT->get(KEY_OPERAND)

Compilation errors: yep, you can absolutely get compilation errors from the syntax of a hash value access. It's giving "the vibes were off" ๐Ÿ˜ญ

Examples:

my $hash = Hash->new({x => 1});
my $x = $hash->{"x"};

Hash Value Set Operation

Okay so the setting-field operation sets the field of a class type โœจ

INVOCANT->{KEY_OPERAND} = OPERAND

INVOCANT->{KEY_OPERAND} is a hash value access (same girl as before, different outfit).

This whole thing gets replaced with a set method call ๐Ÿซถ

INVOCANT->set(KEY_OPERAND, OPERAND)

Compilation errors:

  • Compiliation errors caused by the syntax of hash value access could occur. Yep, same deal as the get version.
  • The assignment must satisfy assignment requirement. Otherwise, a compilation error occurs. No cheating the assignment requirements, periodt ๐Ÿ’€

Examples:

my $hash = Hash->new({x => 1});
$hash->{"x"} = 2;

Field Access

The field access has this syntax:

INVOCANT->{FIELD_NAME}

See Field Access Resolution for the whole story about INVOCANT, FIELD_NAME, and how a field access gets resolved ๐Ÿ‘‘

Examples:

$point->{x}

Hash Value Access

The hash value access has this syntax:

INVOCANT->{KEY_OPERAND}

The type of INVOCANT is a class type or an interface type โ€” both are valid, she's flexible ๐Ÿ’–

The type of KEY_OPERAND is string type.

Examples:

$hash->{"x"};

Compilation errors:

  • The type of INVOCANT must be a class type or an interface type. Otherwise a compilation error occurs. Bestie, if it's neither, we're cooked.
  • The type of KEY_OPERAND must be string type. Otherwise a compilation error occurs. Strings only, no cap.

Referenced Value Get Operation

The operation of getting the referenced value gets a referenced value. Iconic, self-explanatory, we love a circular definition that somehow makes sense ๐ŸŒธ

See dereference operator for the details.

Referenced Value Set Operation

The operation of setting the referenced value sets a referenced value โœจ

$VARIABLE = OPERAND

Thie operation sets the value referenced by the reference VARIABLE to OPERAND using assignment operator, and returns the value after setting. So it does the thing and hands you back the result โ€” main character energy, honestly ๐Ÿ‘‘

The return type is the type of the referenced value.

Compilation errors:

  • The type of VARIABLE must be a reference type. Otherwise, a compilation error occurs.
  • The assignment must satisfy assignment requirement. Otherwise, a compilation error occurs. Again โ€” the assignment requirement is non-negotiable, fr fr.

Examples:

my $num : int;
my $num_ref : int* = \$num;
$$num_ref = 1;

my $z : Complex_2d;
my $z_ref : Complex_2d* = \$z;

my $z2 : Complex_2d;

$$z_ref = $z2;

Exception Variable Get Operation

The operation of getting the exception variable gets the string stored in exception variable. It's the $@ girlie ๐Ÿ’…

$@

This operator returns the string stored in the exception variable.

The return type is string type.

Examples:

# Examples of getting the exception variable
my $message = $@;

Exception Variable Set Operation

The operation of setting the exception variable sets exception variable. Yep, we're writing to $@ now ๐Ÿ˜ญ

$@ = OPERAND

This operator sets the exception variable to OPERAND using assignment operator.

The return type is string type.

Compilation errors:

  • The assignment must satisfy assignment requirement. Otherwise, a compilation error occurs.

Examples:

# Examples of setting the exception variable
$@ = "Error";

โœจ Data Conversions โœจ

This section describes data conversions. Buckle up bestie, it's a whole journey ๐Ÿฆ‹

Numeric Widening Conversion

The numeric widening conversion is the data conversion from a numeric type to a larger numeric type. Growing, thriving, leveling up ๐ŸŒฑ

See numeric types order about the order of numeric types.

This conversion performs the same operation as the C language type cast:

(TYPE)OPERAND

byte to short:

(int16_t)OPERAND_int8_t;

byte to int:

(int32_t)OPERAND_int8_t;

byte to long:

(int64_t)OPERAND_int8_t;

byte to float:

(float)OPERAND_int8_t;

byte to double:

(double)OPERAND_int8_t;

short to int:

(int32_t)OPERAND_int16_t;

short to long:

(int64_t)OPERAND_int16_t;

short to float:

(float)OPERAND_int16_t;

short to double:

(double)OPERAND_int16_t;

int to long:

(int64_t)OPERAND_int32_t;

int to float:

(float)OPERAND_int32_t;

int to double:

(double)OPERAND_int32_t;

long to float:

(float)OPERAND_int64_t;

long to double:

(double)OPERAND_int64_t;

float to double:

(double)OPERAND_float;

Integer Promotional Conversion

The integer promotional conversion is the data conversion from an integer type within int to int type using numeric widening conversion. It's the glow-up from "small int" to "the int" ๐Ÿ‘‘

Numeric Narrowing Conversion

The numeric narrowing conversion is the data conversion from a numeric type to a smaller numeric type. Shrinking. Cozy. Potentially lossy โ€” handle with care ๐Ÿ™ˆ

See numeric types order about the order of numeric types.

This conversion performs the same operation as the C language type cast:

(TYPE)OPERAND

double to float:

(float)OPERAND_double;

double to long:

(int64_t)OPERAND_double;

double to int:

(int32_t)OPERAND_double;

double to short:

(int16_t)OPERAND_double;

double to byte:

(int8_t)OPERAND_double;

float to long:

(int64_t)OPERAND_float;

float to int:

(int32_t)OPERAND_float;

float to short:

(int16_t)OPERAND_float;

float to byte:

(int8_t)OPERAND_float;

long to int:

(int32_)OPERAND_int64_t;

long to short:

(int16_t)OPERAND_int64_t;

long to byte:

(int8_t)OPERAND_int64_t;

int to short:

(int16_t)OPERAND_int32_t;

int to byte:

(int16_t)OPERAND_int32_t;

short to byte:

(int8_t)OPERAND_int16_t;

Binary Numeric Conversion

The binary numeric conversion is the data conversion to upgrade the numeric type of the left operand and the right operand of a binary operator. Matchmaker energy: it's gonna get these two on the same level ๐Ÿ’ž

This conversion performs the following operations:

  • If the left operand type is smaller than the right operand, numeric widening conversion from the left operand type to the right operand type is performed on the left operand.
  • If the right operand type is smaller than the left operand, numeric widening conversion from the right operand type to the left operand type is performed on the right operand.
  • If the converted type of the left operand is the smaller than int type, numeric widening conversion from the left operand type to int type is performed on the left operand.
  • If the converted type of the right operand is the smaller than int type, numeric widening conversion from the right operand type to int type is performed on the right operand.

Numeric-to-String Conversion

The numeric-to-string conversion is the data conversion from a numeric type to string type. Numbers getting a whole new personality as text ๐Ÿ’…

This conversion performs the same operation as the C language sprintf.

byte to string:

sprintf(RETURN_VALUE, "%" PRId8, OPERAND_byte);

short to string:

sprintf(RETURN_VALUE, "%" PRId16, OPERAND_short);

int to string:

sprintf(RETURN_VALUE, "%" PRId32, OPERAND_int);

long to string:

sprintf(RETURN_VALUE, "%" PRId64, OPERAND_long);

float to string:

sprintf(RETURN_VALUE, "%g", OPERAND_float);

double to string:

sprintf(RETURN_VALUE, "%g", OPERAND_double);

Examples:

# Examples of the numeric-to-string conversion
my $byte = (byte)1;
my $string_byte = (string)$byte;

my $short = (short)2;
my $string_short = (string)$short;

my $int = 3;
my $string_int = (string)$int;

my $long = 4L;
my $string_long = (string)$long;

my $float = 2.5f;
my $string_float = (string)$float;

my $double = 3.3;
my $string_double = (string)$double;

String-to-Numeric Conversion

The string-to-numeric conversion is the data conversion from string type to a numeric type. Text turning into numbers, the reverse glow-up โœจ

string to byte:

  • If the string is not defined, it returns 0.
  • If it is defined, it is coverted to a number by the strtoll function in the C language.
  • The number is greater than INT8_MAX, the number is set to INT8_MAX.
  • The number is less than INT8_MIN, the number is set to INT8_MIN.
  • And returns the number.

string to short:

  • If the string is not defined, it returns 0.
  • If it is defined, it is coverted to a number by the strtoll function in the C language.
  • The number is greater than INT16_MAX, the number is set to INT16_MAX.
  • The number is less than INT16_MIN, the number is set to INT16_MIN.
  • And returns the number.

string to int:

  • If the string is not defined, it returns 0.
  • If it is defined, it is coverted to a number by the strtoll function in the C language.
  • The number is greater than INT32_MAX, the number is set to INT32_MAX.
  • The number is less than INT32_MIN, the number is set to INT32_MIN.
  • And returns the number.

string to long:

  • If the string is not defined, it returns 0.
  • If it is defined, it is coverted to a number by the strtoll function in the C language.
  • And returns the number.

Note: no clamping here, bestie โ€” long just takes the number as-is ๐Ÿซถ

string to float:

  • If the string is not defined, it returns 0.
  • If it is defined, it is coverted to a number by the strtof function in the C language.
  • And returns the number.

string to double:

  • If the string is not defined, it returns 0.
  • If it is defined, it is coverted to a number by the strtod function in the C language.
  • And returns the number.

Exampels: (yes, the source says "Exampels", we're keeping the whole vibe ๐Ÿ˜ญ)

# Examples of string to numeric conversions

# string to byte
my $string : string = "Hello";
my $number : byte = (byte)$string;

# string to short
my $string : string = "Hello";
my $number : short = (short)$string;

# string to int
my $string : string = "Hello";
my $number : int = (int)$string;

# string to long
my $string : string = "Hello";
my $number : long = (long)$string;

# string to float
my $string : string = "Hello";
my $float : float = (float)$string;

# string to double
my $string : string = "Hello";
my $number : double = (double)$string;

String-to-byte[] Conversion

The string-to-byte[] conversion is the data conversion from string type to the byte[] type ๐ŸŒˆ

This conversion creates a new array which type is the byte[] type, copies all characters in the string to the elements of the new array, and returns the new array. Brand new array, freshly copied, no sharing ๐Ÿ’–

If the string is not defined, it returns undef.

Examples:

# Examples of the string-to-byte[] conversion
my $string : string = "Hello";
my $bytes : byte[] = (byte[])$string;

byte[]-to-string Conversion

The byte[]-to-string conversion is the data conversion from the byte[] type to string type.

okay so this conversion builds a brand-new string, copies every single element of the array (the one whose type is the byte[] type) into the characters of that new string, and hands you back the new string. ๐Ÿ’–

And if the array is not defined? it returns undef. that's it, that's the whole vibe.

# Examples of the byte[]-to-string conversion
my $bytes : byte[] = new byte[3];
$bytes->[0] = 'a';
$bytes->[1] = 'b';
$bytes->[2] = 'c';
my $string : string = (string)$bytes;

๐ŸŽ€ Boxing Conversion ๐ŸŽ€

the boxing conversion is the type conversion from a numeric type to its corresponding numeric object type. bestie it's giving "put it in a box" and honestly that's exactly what it is ๐Ÿ“ฆโœจ

so a boxing conversion creates a new numeric object corresponding to its numeric type, copies the value of the numeric type into the value field of that new numeric object, and returns the new numeric object. slay.

๐ŸŒธ Unboxing Conversion ๐ŸŒธ

the unboxing conversion is the type conversion from an object of a numeric object type to the value of its corresponding numeric type. it's the reverse glow-up โ€” you take it back out of the box ๐Ÿ’…

  • if the destination numeric type is bigger than the source numeric type, Numeric Widening Conversion is performed.
  • if the destination numeric type is smaller than the source numeric type, Numeric Narrowing Conversion is performed.

(those two are their own whole sections in the Operators doc, iykyk โ€” go read Numeric Widening Conversion and Numeric Narrowing Conversion if you want the deep lore.)

an unboxing conversion could be performed on the object of any object type object. ๐Ÿ‘‘

if the source type is undef type, 0 is returned. okay so undef unboxes to zero, noted. ๐Ÿซถ

Exceptions:

if the type of the object is not its corresponding numeric type, an exception is thrown. ๐Ÿ˜ญ no cap, it will absolutely yell at you.

and here's where these conversions sneak in implicitly:

  • the right operand of assignment operator.
  • arguments given to a method call
  • a return value given to return statement

what type combinations cause implicit data conversions is explained in assignment requirement. (go check that section, it's the receipts ๐Ÿ“œ)

Examples:

# Assignment operators
# int to double
my $number : double = 5;

# double to Double
my $number_object : Double = 5.1;

# Double to double
my $number : double = Double->new(5.1);

# int to string
my $string : string = 4;

# Method call
# int to double
my $double_object = Double->new(3);

# Return value
method my_method : double () {

  # int to double
  return 3;
}

๐Ÿ’ซ Type Cast ๐Ÿ’ซ

a type cast converts a value from its type to another type. it's giving transformation era ๐Ÿฆ‹

# A type cast
(TYPE)OPERAND

# A postfix type cast
OPERAND->(TYPE)

the return type is TYPE.

if a data conversion is needed in the type cast, a type cast performs a data conversion on OPERAND, and returns the value after the data conversion. otherwise it returns OPERAND. simple.

if a data check is needed in the type cast, a type cast performs a data check on OPERAND. ๐Ÿ‘€

data conversions and data checks in type casts are explained in Cast Requirement. (that's the section with the actual rules, bestie, don't skip it.)

Exceptions:

if a data check returns 0, an exception is thrown. ๐Ÿšจ

Compilation Errors:

OPERAND must satisfy cast requirement. otherwise, a compilation error occurs.

Examples:

# Examples of the type cast

# long to int
my $num = (int)123L;

# byte[] to string
my $num = (string)new byte[3];

# string to byte[]
my $num = (byte[])"Hello";

# Postfix type cast
my $stringable = Point->new->(Stringable);

๐Ÿ” isa Operator ๐Ÿ”

the isa operator checks whether an operand can be assigned to a type. vibe check on assignability, basically โœจ

OPERAND isa TYPE
$@      isa TYPE_WITHOUT_STRING

if the type TYPE is a numeric type, a multi-numeric type, or a reference type, this operator checks assignment requirement without data conversion.

if the assignment requirement is satisfied, this operator returns 1, otherwise returns 0. boom. ๐ŸŽฏ

if TYPE is an object type, this operator checks assignment requirement at runtime.

if the assignment requirement at runtime is satisfied, this operator returns 1, otherwise returns 0.

the return type is int type.

if the left operand is $@ and the right type is not string type, a special interpretation is applied. ๐Ÿ‘€

$@ isa TYPE_WITHOUT_STRING

is replaced with

$@ && eval_error_id isa_error TYPE_WITHOUT_STRING

see also "eval_error_id Operator" and "isa_error Operator".

Compilation Errors:

the right type TYPE of isa operator must not be any object type. otherwise, a compilation error occurs.

the left operand type OPERAND of isa operator must be an object type. otherwise, a compilation error occurs.

Examples:

if ($value isa int) {

}

if ($value isa Point) {

}

if ($value isa Point3D) {

}

if ($value isa Stringable) {

}

if ($value isa int) {

}

if ($@ isa Error::System) {

}

๐Ÿงš is_type Operator ๐Ÿงš

the is_type operator checks if the type of an operand is equal to a type. it's the strict version, no "close enough" energy ๐Ÿ’…

OPERAND is_type TYPE
$@      is_type TYPE_WITHOUT_STRING

if the type TYPE is a numeric type, a multi-numeric type, or a reference type, this operator checks if the compilation type of OPERAND is equal to TYPE.

if the check is true, this operator returns 1, otherwise returns 0.

if TYPE is an object type, this operator checks if the runtime type of OPERAND is equal to TYPE at runtime.

if it is true, this operator returns 1, otherwise returns 0.

the return type is int type.

if the left operand is $@ and the right type is not string type, a special interpretation is applied.

$@ is_type TYPE_WITHOUT_STRING

is replaced with

$@ && eval_error_id is_error TYPE_WITHOUT_STRING

see also "eval_error_id Operator" and "is_error Operator".

Compilation Errors:

the right type TYPE of is_type operator must not be any object type. otherwise, a compilation error occurs.

the left operand type OPERAND of is_type operator must be an object type. otherwise, a compilation error occurs.

Examples:

if ($object is_type int) {

}

if ($object is_type Point) {

}

if ($object is_type int[]) {

}

if ($object is_type Stringable[]) {

}

if ($@ is_type Error::System) {

}

๐Ÿฆ‹ is_compile_type Operator ๐Ÿฆ‹

the is_compile_type operator checks whether the compilation type of an operand is equal to a type. compile-time only, bestie, no runtime surprises โญ

OPERAND is_compile_type TYPE

if the compilation type of OPERAND is equal to the type with type modifier TYPE, it returns 1.

if TYPE is a generic type and TYPE matches partially the compilation type of OPERAND from the top, it returns 1. (partial match from the top, iconic.)

TYPE must not contain union types.

otherwise it returns 0.

the return type is int type.

Examples:

{
  my $value : int;
  if ($value is_compile_type int) {
    # Pass
  }
}

{
  my $object : object = new TestCase::Minimal;
  if ($object is_compile_type object) {
    # Pass
  }
}

{
  my $value : Stringer = method : string () { return "aaa"; };
  if ($value is_compile_type Stringer) {
    # Pass
  }
}

{
  my $value : string;
  if ($value is_compile_type string) {
    # Pass
  }
}

{
  my $value : mutable string;
  if ($value is_compile_type mutable string) {
    # Pass
  }
}

{
  my $object = (Hash of List of string)undef;
  if ($object is_compile_type Hash of List of string) {
    # Pass
  }
}

{
  my $object = (Hash of List of string)undef;
  if ($object is_compile_type Hash of List) {
    # Pass
  }
}

{
  my $object = (Hash of List of string)undef;
  if ($object is_compile_type Hash) {
    # Pass
  }
}

๐Ÿšจ isa_error Operator ๐Ÿšจ

the isa_error operator checks whether the type specified by a basic type ID can be assigned to a class type. this operator is normally used for error classes to check "eval_error_id Operator". it's the error-handling bestie fr fr ๐Ÿ˜ญ

OPERAND isa_error TYPE

this operator performs integer promotional conversion on the operand OPERAND.

and this operator checks whether the type specified by the basic type ID OPERAND satisfies assignment requirement without data conversion to the type TYPE.

if it is satisfied, this operator returns 1, otherwise returns 0.

the return type is int type.

Compilation Errors:

OPERAND must be an integer type within int. otherwise, a compilation error occurs.

TYPE must be a class type. otherwise, a compilation error occurs.

Examples:

if (eval_error_id isa_error Error) {

}

if (eval_error_id isa_error Error::System) {

}

๐Ÿ’œ is_error Operator ๐Ÿ’œ

the is_error operator checks whether the type specified by a basic type ID is equal to a class type. this operator is normally used for error classes to check "eval_error_id Operator". strict equality this time, not assignability ๐Ÿ‘‘

OPERAND is_error TYPE

this operator performs integer promotional conversion on the operand OPERAND.

and this operator checks whether the type specified by the basic type ID OPERAND is equal to the type TYPE.

if it is, this operator returns 1, otherwise returns 0.

the return type is int type.

Compilation Errors:

OPERAND must be an integer type within int. otherwise, a compilation error occurs.

TYPE must be a class type. otherwise, a compilation error occurs.

Examples:

if (eval_error_id is_error Error) {

}

if (eval_error_id is_error Error::System) {

}

๐ŸŒˆ type_name Operator ๐ŸŒˆ

the type_name operator gets the type name of the object. name reveal moment โœจ

type_name OPERAND

if the object OPERAND is defined, it creates a string with the type name of OPERAND and returns it. otherwise, it returns an undefined value.

the return type is string type.

Compilation Errors.

OPERAND must be an object type. otherwise, a compilation error occurs.

Examples:

# "Point"
my $point = Point->new;
my $type_name = type_name $point;

# "Point"
my $point = (object)Point->new;
my $type_name = type_name $point;

๐ŸŽ€ compile_type_name Operator ๐ŸŽ€

the compile_type_name operator gets the compilation type of the operand OPERAND. it's the compile-time twin of type_name, we stan a duo ๐Ÿ’–

compile_type_name OPERAND

this operator creates a new string with the compilation type name of OPERAND and returns it.

the return type is string type.

Examples:

# Point
my $point = Point->new;
my $compile_type_name = type_name $point;

# object
my $point = (object)Point->new;
my $compile_type_name = type_name $point;

# mutable string
my $string = (mutable string)copy "abc";
my $compile_type_name = compile_type_name $string;
okay bestie, yes, those examples say type_name inside the compile_type_name section โ€” copy them exactly as shown, don't go "fixing" them, we keep the source verbatim around here ๐Ÿซถ

...and the rest of the compile_type_name examples, bestie, because we love a full set:

# Hash of List of string
my $object = (Hash of List of string)undef;
my $compile_type_name = compile_type_name $object;

๐Ÿ’œ basic_type_id Operator

This one grabs the basic type ID of a type. It's giving "ID card check" energy.

basic_type_id TYPE

It returns the basic type ID of the type TYPE.

The return type? int, obviously. ๐Ÿ”ฅ

Examples, periodt:

my $basic_type_id = basic_type_id int;

my $basic_type_id = basic_type_id int[];

my $error_basic_type_id = basic_type_id Error;

๐Ÿฆ‹ can Operator

Okay so this one checks if a method can actually be called. Vibe check for methods, basically.

OPERAND can METHOD_NAME

If OPERAND is able to call the method given by METHOD_NAME, it returns 1. Otherwise it returns 0. That's it. ๐Ÿ’…

METHOD_NAME is a method name or an empty string "".

The return type is int type.

Compilation Errors:

  • The type of OPERAND must be the class type or interface type. Otherwise, a compilation error occurs. no cap.
  • The METHOD_NAME must be a method name or an empty string "". Otherwise, a compilation error occurs.

Examples:

my $stringable = (Stringable)Point->new(1, 2);

if ($stringable can to_string) {
  # ...
}

if ($stringable can "") {
  # ...
}

โœจ args_width Operator

Gets the stack length of the arguments passed to the method. Like, the actual width on the stack, not the number of args you typed. ๐Ÿ™ˆ

args_width
Note that the stack length of the arguments is different from the length of the arguments. iykyk.

If the method call is the instance method call, the stack length of the arguments is the length of the arguments + 1 for the invocant.

If an argument is a multi-numeric type, the stack length of the argument becomes the length of the fields.

Examples, because seeing it is believing:

static method my_static_method : int ($args : int, $bar : int = 0) {
  my $args_width = args_width;

  return $args_width;
};

# 1
&my_static_method(1);

# 2
&my_static_method(1, 2);

static method my_instance_method : int ($args : int, $bar : int = 0) {
  my $args_width = args_width;

  return $args_width;
};

# 2 (1 + the invocant)
&my_instance_method(1);

# 3 (2 + the invocant)
&my_instance_method(1, 2);

static method my_mulnum_method : int ($z : Complex_2d, $bar : int = 0) {
  my $args_width = args_width;

  return $args_width;
};

# 2 (The length of the fields of Complex_2d)
my $z : Complex_2d;
&my_mulnum_method($z);

# 3 (The length of the fields of Complex_2d + 1)
my $z : Complex_2d;
&my_mulnum_method($z, 2);

๐ŸŽ€ eval_error_id Operator

The eval_error_id operator gets the value of "eval_error_id". Short and slay.

eval_error_id

See SPVM::Document::Language::ExceptionHandling about the way to use the eval_error_id operator. Go read it, babe, it's important. ๐Ÿซถ


๐ŸŒธ weaken Operator

The weaken operator enables a weak reference. Yes, the name is literally the whole personality.

weaken INVOCANT->{FIELD_NAME};

INVOCANT->{FIELD_NAME} is a field access.

This operator enables a weak reference of the field specified by FIELD_NAME of the type of INVOCANT.

The return type is the void type.

Compilation Errors:

  • Compiliation errors caused by the syntax of field access could occur. ๐Ÿ˜ญ
  • The incovant of the field access must be a class type.
  • The type of INVOCANT->{FIELD_NAME} must be an object type. Otherwise, a compilation error occurs.

Examples:

# Exmaples of weaken operator
weaken $object->{point};

๐Ÿ’€ unweaken Operator

The unweaken operator disables a weak reference. The reverse card of weaken, iconic.

unweaken INVOCANT->{FIELD_NAME};

INVOCANT->{FIELD_NAME} is a field access.

This operator turns off the weak reference of the field specified by FIELD_NAME of the type of INVOCANT.

The return type is the void type.

Compilation Errors:

  • Compiliation errors caused by the syntax of field access could occur. ๐Ÿ™ˆ
  • The incovant of the field access must be a class type.
  • The type of INVOCANT->{FIELD_NAME} must be an object type. Otherwise, a compilation error occurs.

Examples:

# Exmaples of unweaken operator
unweaken $object->{point};

โญ isweak Operator

Checks if the weak reference of a field is enabled. Detective mode activated. ๐Ÿ”

isweak INVOCANT->{FIELD_NAME};

INVOCANT->{FIELD_NAME} is a field access.

If the field specified by FIELD_NAME of the object INVOCANT is weaken, this operator returns 1, otherwise returns 0.

The return type is int type.

Compilation Errors:

  • Compiliation errors caused by the syntax of field access could occur.
  • The incovant of the field access must be a class type.
  • The type of INVOCANT->{FIELD_NAME} must be an object type. Otherwise, a compilation error occurs.

Examples:

# Exmaples of isweak operator
my $isweak = isweak $object->{point};

๐Ÿ“ exists Operator

Checks if a field value exists. Does it exist? Is it real? Are we real? Big questions.

exists INVOCANT->{FIELD_NAME};

INVOCANT->{FIELD_NAME} is a field access.

If the field specified by FIELD_NAME of the object INVOCANT exists, this operator returns 1, otherwise returns 0.

The return type is int type.

Compilation Errors:

  • Compiliation errors caused by the syntax of field access could occur.
  • The incovant of the field access must be a class type.
  • The type of INVOCANT->{FIELD_NAME} must be an object type or a numeric type. Otherwise, a compilation error occurs.

Examples:

# Exmaples of exists operator
my $exists = exists $object->{point};

๐Ÿงš delete Operator

Deletes a field value. Gone. Poof. Not me deleting your whole field. ๐Ÿ’€

delete INVOCANT->{FIELD_NAME};

The field existence flag is set to 0, and the value of the field is set to 0 in the case of numeric types or undef in the case of object types.

INVOCANT->{FIELD_NAME} is a field access.

The return type is the void type.

Compilation Errors:

  • Compiliation errors caused by the syntax of field access could occur.
  • The incovant of the field access must be a class type.
  • The type of INVOCANT->{FIELD_NAME} must be an object type or a numeric type. Otherwise, a compilation error occurs.

Examples:

# Exmaples of delete operator
delete $object->{point};

๐ŸŒˆ copy_fields Operator

Copies fields. All of them. Like a full wardrobe transfer bestie. ๐Ÿ‘‘

copy_fields DIST_OPERAND, SRC_OPERAND, TYPE;

The type of TYPE must be a class type.

The copy_fields operator copies every field from SRC_OPERAND to DIST_OPERAND using all the field names defined in TYPE class.

For example, if the field names defined in TYPE class are "x", "y", and "z", then copy_field operator is expanded to the following codes:

if (exists SRC_OPERAND->{x}) {
  DIST_OPERAND->{x} = SRC_OPERAND->{x};
}
if (exists SRC_OPERAND->{y}) {
  DIST_OPERAND->{y} = SRC_OPERAND->{y};
}
if (exists SRC_OPERAND->{z}) {
  DIST_OPERAND->{z} = SRC_OPERAND->{z};
}

Compilation Errors:

  • The type of TYPE must be a class type. Otherwise, a compilation error occurs.

Examples:

# Exampels of copy_fields operator
my $object = MyClass->new;

my $object_child = MyClass::Child->new;

copy_fields $object_child, $object, MyClass;

๐ŸŽ€ set_length Operator

Sets the length of a string or an array. Sizing things up, literally.

set_length(OBJECT_OPERAND, LENGTH_OPERAND);

The type of OBJECT_OPERAND must be a string or an array.

The type of LENGTH_OPERAND is an integer value with "int".

If the length is extended, "set_capacity Operator" is called if needed.

If the length is extended, the extended elements are set to its default value.

If the length is shorten, unused elements is destroyed. rip to those elements ๐Ÿซก

Compilation Errors:

  • OBJECT_OPERAND type must be an array type or string type. Otherwise a compilation error occurs.
  • OBJECT_OPERAND type must be an integer type. Otherwise a compilation error occurs.
  • LENGTH_OPERAND type must be an integer type. Otherwise a compilation error occurs.

Exceptions:

  • OBJECT_OPERAND must be defined. Otherwise an exception is thrown.
  • the type of OBJECT_OPERAND must be string type or an array type. Otherwise an exception is thrown.
  • OBJECT_OPERAND must not be a fixed length object. If so, an exception is thrown.

Examples:

# Examples of set_length operator
my $string = (mutable string)copy "abc";

set_length($string, 4);

๐Ÿ’– set_capacity Operator

Sets the capacity of a string or an array. Capacity is not length, bestie, don't mix them up. ๐Ÿ”ฅ

set_capacity(OBJECT_OPERAND, CAPACITY_OPERAND);

The type of OBJECT_OPERAND must be a string or an array.

The type of CAPACITY_OPERAND is an integer value with "int".

The new capacity is allocated and old elements are copied on it.

Compilation Errors:

  • OBJECT_OPERAND type must be an array type or string type. Otherwise a compilation error occurs.
  • OBJECT_OPERAND type must be an integer type. Otherwise a compilation error occurs.
  • CAPACITY_OPERAND type must be an integer type. Otherwise a compilation error occurs.

Exceptions:

  • OBJECT_OPERAND must be defined. Otherwise an exception is thrown.
  • The type of OBJECT_OPERAND must be string type or an array type. Otherwise an exception is thrown.
  • OBJECT_OPERAND must not be a fixed capacity object. If so, an exception is thrown.
  • If this operator cannot allocate memory, an exception is thrown.
  • If CAPACITY_OPERAND is smaller capacity than its length plus 1, an exception is thrown.

Examples:

# Examples of set_capacity operator
my $string = (mutable string)copy "abc";

set_capacity($string, 4);

๐Ÿ‘‘ caller Operator

Gets the info of whoever called the current method. Main character energy for your stack frames. โœจ

caller LEVEL
caller

This operator returns a CallerInfo object that contains the information of the caller at the level specified by LEVEL.

If LEVEL is omitted, it is treated as 0.

If the level is 0, it returns the information of the caller of the current method.

The return type is CallerInfo class.

Exceptions:

  • If LEVEL is less than 0, an exception is thrown.
  • If LEVEL exceeds the call depth of methods, an exception is thrown.

Compilation Errors:

  • The type of LEVEL must be an integer type within int. Otherwise, a compilation error occurs.

Examples:

# Examples of the caller operator
use CallerInfo;

# Get the caller information of the current method
my $caller_info = caller;

# Get the absolute method name of the caller
my $method_abs_name = $caller_info->method_abs_name;

# Get the file name of the caller
my $file = $caller_info->file;

# Get the line number of the caller
my $line = $caller_info->line;

๐Ÿ› break_point Operator

Sets a break point for debugging. Your future self will thank you. ๐Ÿ’…

break_point;

Okay so this operator pauses the program execution as a break point and waits for a user input from the standard input.

If the user input is a newline character "\n" or an EOF(End of File), the program execution resumes.

Otherwise, the program waits for a user input again.

The return type is void type.

Examples:

# Set a break point for debugging
break_point;

๐Ÿงญ Scope Operations

See the doc of scope about scope operations โ€” it's giving required reading, fr.

๐Ÿ“ž Method Call

A method call is an operator to call a method. Literally the main character of calling stuff.

A method call resolves to one of the three types of method calls, a class method call, a static instance method call, and an instance method call by method call resolution.

If the method call is a static instance method call or an instance method call, the invocant is prepended to the given arguments.

The method call performs method call execution given the arguments.

๐Ÿซ Class Method Call

A class method call calls a class method.

CLASS_TYPE->METHOD_NAME
CLASS_TYPE->METHOD_NAME(OPT_ARGS)
&METHOD_NAME
&METHOD_NAME(OPT_ARGS)

See Class Method Call Resolution about CLASS_TYPE, METHOD_NAME, OPT_ARGS, "&", and the resolution of a class method call.

Examples:

# Examples of static instance method calls
my $point3d = Point3D->new;

$point3d->Point::clear;

$point3d->SUPER::clear;

๐Ÿง Static Instance Method Call

A static instance method call calls an instance method specifying a class.

INVOCANT->CLASS_TYPE::METHOD_NAME
INVOCANT->CLASS_TYPE::METHOD_NAME(OPT_ARGS)

See Static Instance Method Call Resolution about INVOCANT, CLASS_TYPE, METHOD_NAME, OPT_ARGS, and the resolution of a static instance method call.

Examples:

# Examples of static instance method calls
$object->SUPER::bar(5, 3. 6);

$point3d->Point::clear;

๐Ÿซถ Instance Method Call

An instance method call calls an instance method.

INVOCANT->METHOD_NAME
INVOCANT->METHOD_NAME(OPT_ARGS)

See Instance Method Call Resolution about INVOCANT, CLASS_TYPE, METHOD_NAME, OPT_ARGS, and the resolution of an instance method call.

Examples:

# Examples of instance method calls

my $point = Point->new;

$point->clear;

my $stringable = (Stringable)$point;

my $string = $strinble->to_string;

โš™๏ธ Method Call Execution

Okay bestie, here's the step-by-step of method call execution, no cap:

  1. The argument width is stored to runtime stack.
  2. The call stack depth stored in runtime stack is incremented by 1.
  3. If the call stack depth is greater than 1000, an exception is thrown.
  4. If the method call is not a class method call, the arguments of the object type are checked whether the following isa operator returns a true value.
ARG isa TYPE_OF_ARG

ARG is an argument. TYPE_OF_ARG is the type of the corresponding argument of the method.

If the return value is not a true value, an exception is thrown.

  1. If the method is a INIT method and it is already called, nothing is performed.
  2. If the method is a native method, a native method call execution is performed.
  3. Otherwise if the method is a precompilation method, a precompilation method call execution is performed.
  4. Otherwise a VM method call execution is performed.
  5. If an exception is thrown by the method call execution, the exception is thrown.
  6. If the return type of the method is an object type, the object is pushed to native mortal stack.
  7. The call stack depth stored in runtime stack is decremented by 1. This restore is always performed even if an exception is thrown.

๐Ÿ–ฅ๏ธ VM Method Call Execution

  • Heap memories for local variables are allocated.
  • The enter_scope native API is called.
  • SPVM operation codes generated from method implementation are executed.
  • The leave_scope native API is called.
  • Heap memories for local variables are released.

๐Ÿงช Precompilation Method Call Execution

  • If a set of the machine codes of the precompilation method is loaded, the program executes it.
  • Otherwise if is_precompile_fallback native API returns a true value, the program executes "VM Method Call Execution".
  • Otherwise an exception is thrown.

๐Ÿ”Œ Native Method Call Execution

  • The enter_scope native API is called.
  • If a set of the machine codes of native function of the native method is loaded, the program executes it.
  • Otherwise an exception is thrown after executing the following code.
  • The leave_scope native API is called.

๐Ÿ‘€ See Also

  • Class Definition
  • Class Definition
  • Types
  • Exception Handling
  • Garbage Collection
  • SPVM::Document::Language
  • SPVM::Document

Copyright (c) 2023 Yuki Kimoto

MIT License


That's the whole vibe check, bestie ๐Ÿ’– This page was brought to you by perl v5.42.2, dated 2026-02-03. Slay. โœจ๐Ÿ’…๐Ÿซถ

๐Ÿ“ฆ where this page comes from