Skip to content

Commit

Permalink
заготовки для продолжения работы над pass3
Browse files Browse the repository at this point in the history
  • Loading branch information
JustSkiv committed Oct 12, 2017
1 parent 534d213 commit 81c2a15
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,29 @@ public function assemble($ast)
{
$commands = [];

if (self::isTrivialOperation($ast)) {
$commands[] = self::commandLoad($ast['a']);
if (self::isOperation($ast)) {
// work with arg A
if (self::isTrivial($ast['a'])) {
$commands[] = self::commandLoad($ast['a']);
} else {
// assemble this arg
$subCommands = $this->assemble($ast['a']);

// TODO: need to do smth with older results (swap etc)
$commands = array_merge($commands, $subCommands);

// TODO: mb, it better to place at end of funtion?
$commands[] = 'PU';
}

$commands[] = 'SW';

$commands[] = self::commandLoad($ast['b']);
// work with arg B
if (self::isTrivial($ast['b'])) {
$commands[] = self::commandLoad($ast['b']);
} else {
return false;
}

$commands[] = self::commandForOperation($ast);
}
Expand All @@ -319,7 +336,7 @@ public function assemble($ast)

public static function commandLoad($ast)
{
if(!self::isTrivial($ast)){
if (!self::isTrivial($ast)) {
return false;
}

Expand All @@ -341,7 +358,7 @@ public static function commandLoad($ast)

public static function commandForOperation($ast)
{
if(!self::isOperation($ast)){
if (!self::isOperation($ast)) {
return false;
}
$command = false;
Expand Down

0 comments on commit 81c2a15

Please sign in to comment.