Introduces various instruction additions to the base engine.
Created \RTEX\Objects\Program\Instructions > Sum Created \RTEX\Objects\Program\Instructions > Subtract Created \RTEX\Objects\Program\Instructions > Power Created \RTEX\Objects\Program\Instructions > Multiply Created \RTEX\Objects\Program\Instructions > Modulo Created \RTEX\Objects\Program\Instructions > LessThanOrEquals Created \RTEX\Objects\Program\Instructions > LessThan Created \RTEX\Objects\Program\Instructions > Invoke Created \RTEX\Objects\Program\Instructions > GreaterThanOrEquals Created \RTEX\Objects\Program\Instructions > GreaterThan Created \RTEX\Objects\Program\Instructions > Equals Created \RTEX\Objects\Program\Instructions > Divide Created \RTEX\Objects\Program\Instructions > ArrayGet Refactored \RTEX\Objects\Program\Instructions > SetVariable Refactored \RTEX\Objects\Program\Instructions > GetVariable
This commit is contained in:
parent
68b50a1a21
commit
08c4b3079e
15 changed files with 1965 additions and 90 deletions
|
@ -1,10 +1,14 @@
|
|||
<?php
|
||||
|
||||
/** @noinspection PhpMissingFieldTypeInspection */
|
||||
|
||||
namespace RTEX\Objects\Program\Instructions;
|
||||
|
||||
use RTEX\Abstracts\InstructionType;
|
||||
use RTEX\Classes\InstructionBuilder;
|
||||
use RTEX\Classes\Utilities;
|
||||
use RTEX\Engine;
|
||||
use RTEX\Exceptions\Core\MalformedInstructionException;
|
||||
use RTEX\Exceptions\Core\UnsupportedVariableType;
|
||||
use RTEX\Interfaces\InstructionInterface;
|
||||
|
||||
|
@ -13,7 +17,7 @@
|
|||
/**
|
||||
* The name of the variable to select
|
||||
*
|
||||
* @var string|integer|boolean|float|null|InstructionInterface|InstructionInterface[]
|
||||
* @var mixed
|
||||
*/
|
||||
private $Variable;
|
||||
|
||||
|
@ -28,27 +32,12 @@
|
|||
return InstructionType::GetVariable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array representation of the object
|
||||
*
|
||||
* @return array
|
||||
* @throws UnsupportedVariableType
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'type' => $this->getType(),
|
||||
'_' => [
|
||||
'variable' => Utilities::toArray($this->Variable)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns
|
||||
*
|
||||
* @return bool|float|int|InstructionInterface|string|null
|
||||
* @return mixed
|
||||
* @noinspection PhpMissingReturnTypeInspection
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
public function getVariable()
|
||||
{
|
||||
|
@ -56,34 +45,19 @@
|
|||
}
|
||||
|
||||
/**
|
||||
* @param bool|float|int|InstructionInterface|string|null $variable
|
||||
* @param mixed $variable
|
||||
* @throws MalformedInstructionException
|
||||
* @throws UnsupportedVariableType
|
||||
* @noinspection PhpMissingParamTypeInspection
|
||||
*/
|
||||
public function setVariable($variable): void
|
||||
{
|
||||
switch(Utilities::determineType($variable))
|
||||
{
|
||||
|
||||
|
||||
default:
|
||||
$this->Variable = $variable;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new GetVariable instruction from an array representation
|
||||
*
|
||||
* @throws UnsupportedVariableType
|
||||
*/
|
||||
public static function fromArray(array $data): InstructionInterface
|
||||
{
|
||||
$instruction = new GetVariable();
|
||||
$instruction->setVariable($data['variable'] ?? null);
|
||||
return $instruction;
|
||||
$this->Variable = InstructionBuilder::fromRaw($variable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @throws UnsupportedVariableType
|
||||
*/
|
||||
public function eval(Engine $engine)
|
||||
{
|
||||
|
@ -91,4 +65,45 @@
|
|||
$engine->eval($this->Variable)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array representation of the object
|
||||
*
|
||||
* @return array
|
||||
* @throws UnsupportedVariableType
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return InstructionBuilder::toRaw(self::getType(), [
|
||||
'variable' => $this->Variable
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new GetVariable instruction from an array representation
|
||||
*
|
||||
* @param array $data
|
||||
* @return InstructionInterface
|
||||
* @throws MalformedInstructionException
|
||||
* @throws UnsupportedVariableType
|
||||
*/
|
||||
public static function fromArray(array $data): InstructionInterface
|
||||
{
|
||||
$instruction = new self();
|
||||
$instruction->setVariable($data['variable'] ?? null);
|
||||
|
||||
return $instruction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @throws UnsupportedVariableType
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
return sprintf(
|
||||
self::getType() . ' (variable: %s)',
|
||||
Utilities::entityToString($this->Variable)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue