Skip to content

Commit f8c6719

Browse files
committed
WIP commit
1 parent 518ce90 commit f8c6719

6 files changed

Lines changed: 29 additions & 6 deletions

File tree

src/core/jvm/field/StaticField.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,29 @@
22
namespace PHPJava\Core\JVM\Field;
33

44
use PHPJava\Core\JavaClassInvoker;
5+
use PHPJava\Imitation\java\lang\_String;
6+
use PHPJava\Imitation\java\lang\NoSuchFieldException;
57

68
class StaticField
79
{
810
private static $fields = [];
911

10-
public function __get($name)
12+
/**
13+
* @param $name
14+
* @return mixed
15+
* @throws NoSuchFieldException
16+
*/
17+
public function get($name)
1118
{
19+
if (!isset(static::$fields[$name])) {
20+
throw new NoSuchFieldException('Get to undefined static field ' . $name);
21+
}
22+
if (static::$fields[$name] instanceof _String) {
23+
return (string) static::$fields[$name];
24+
}
1225
return static::$fields[$name];
1326
}
14-
public function __set($name, $value)
27+
public function set($name, $value)
1528
{
1629
static::$fields[$name] = $value;
1730
}

src/core/jvm/invoker/Invokable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function call(string $name, ...$arguments)
5555
*/
5656
$method = $this->methods[$name] ?? null;
5757
if ($method === null) {
58-
throw new UndefinedMethodException('Undefined ' . $name . ' method.');
58+
throw new UndefinedMethodException('Call to undefined ' . $name . ' method.');
5959
}
6060

6161
$codeAttribute = $getCodeAttribute($method->getAttributes());
@@ -95,7 +95,7 @@ public function call(string $name, ...$arguments)
9595
$mnemonic = $mnemonicMap->getName($opcode);
9696

9797
if ($mnemonic === null) {
98-
throw new UndefinedOpCodeException('Undefined OpCode ' . sprintf('0x%X', $cursor) . '.');
98+
throw new UndefinedOpCodeException('Call to undefined OpCode ' . sprintf('0x%X', $cursor) . '.');
9999
}
100100
$pointer = $reader->getOffset() - 1;
101101

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace PHPJava\Imitation\java\lang;
3+
4+
class NoSuchFieldException extends ReflectiveOperationException
5+
{
6+
7+
}

src/kernel/mnemonics/_getstatic.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function execute(): void
3232

3333
// push stack
3434
$fieldName = $cpInfo[$field->getNameIndex()]->getString();
35-
$this->pushStack($this->javaClassInvoker->getStaticFields()->$fieldName);
35+
$this->pushStack($this->javaClassInvoker->getStaticFields()->get($fieldName));
3636
return;
3737
}
3838
}

src/kernel/mnemonics/_putstatic.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public function execute(): void
1818
$class = $cpInfo[$cp->getNameAndTypeIndex()];
1919
$fieldName = $cpInfo[$class->getNameIndex()]->getString();
2020

21-
($this->javaClassInvoker->getStaticFields())->$fieldName = $this->getStack();
21+
$this->javaClassInvoker->getStaticFields()->set($fieldName, $this->getStack());
2222
}
2323
}

tools/test.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@
1414
[99999, 55555, 333333]
1515
);
1616

17+
var_dump($javaClass->getInvoker()->getStaticFields()->get('c'));
18+
var_dump($javaClass->getInvoker()->getStaticFields()->get('b'));
19+
1720
$javaClass->debug();

0 commit comments

Comments
 (0)