Skip to content

Commit f222e99

Browse files
committed
WIP commit
1 parent 1660b96 commit f222e99

11 files changed

Lines changed: 41 additions & 34 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
namespace PHPJava\Bridge\java\lang;
3+
4+
use PHPJava\Kernel\Structures\_Utf8;
5+
6+
class ArrayIndexOutOfBoundsException extends \Exception
7+
{
8+
9+
}

src/core/JavaClassInvoker.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ public function __construct(JavaClass $javaClass)
3434
*/
3535
$methodName = $cpInfo[$methodInfo->getNameIndex()]->getString();
3636

37-
if ($methodInfo->getAccessFlag() === 0) {
38-
$this->hiddenMethods[$methodName] = $methodInfo;
39-
} elseif (($methodInfo->getAccessFlag() & AccessFlag::_Public) !== 0) {
37+
if ($methodInfo->getAccessFlag() === 0 || ($methodInfo->getAccessFlag() & AccessFlag::_Public) !== 0) {
4038
$this->dynamicMethods[$methodName] = $methodInfo;
4139
} elseif (($methodInfo->getAccessFlag() & AccessFlag::_Static) !== 0) {
4240
$this->staticMethods[$methodName] = $methodInfo;

src/core/jvm/invoker/Invokable.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,7 @@ public function __call($name, $arguments)
4949

5050
$reader = new BinaryReader($handle);
5151

52-
$localStorage = [
53-
$this->javaClassInvoker->getJavaClass(),
54-
$arguments[0] ?? null,
55-
$arguments[1] ?? null,
56-
$arguments[2] ?? null,
57-
];
52+
$localStorage = array_slice($arguments, 0, 4);
5853

5954
$stacks = [];
6055
$opcodeMap = new OpCode();
@@ -68,7 +63,7 @@ public function __call($name, $arguments)
6863

6964
$fullName = '\\PHPJava\\Kernel\\OpCode\\' . $opcode;
7065

71-
echo $opcode . "\n";
66+
echo 'Mnemonic: ' . $opcode . "\n";
7267

7368
/**
7469
* @var OpCodeInterface|Accumulator|ConstantPool $executor

src/kernel/opcode/_aaload.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public function execute(): void
1616
{
1717
$index = $this->getStack();
1818
$arrayref = $this->getStack();
19-
19+
2020
if (!isset($arrayref[$index])) {
21-
throw new JavaArrayIndexOutOfBoundsException($this->getMethodName() . ': ' . $index . ' of array index');
21+
throw new \PHPJava\Bridge\java\lang\ArrayIndexOutOfBoundsException('Array Index ' . $index . ' out of bounds.');
2222
}
2323

2424
$this->pushStack($arrayref[$index]);

src/kernel/opcode/_aload.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ final class _aload implements OpCodeInterface
1515
public function execute(): void
1616
{
1717
$index = $this->readByte();
18-
1918
$this->pushStack($this->getLocalStorage($index));
2019
}
2120
}

src/kernel/opcode/_iadd.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function execute(): void
1313
{
1414
$leftValue = $this->getStack();
1515
$rightValue = $this->getStack();
16-
16+
1717
$this->pushStack(BinaryTool::add($leftValue, $rightValue, 4));
1818
}
1919
}

src/kernel/opcode/_invokespecial.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,31 @@ final class _invokespecial implements OpCodeInterface
1313
public function execute(): void
1414
{
1515
$cpInfo = $this->getConstantPool()->getEntries();
16-
17-
18-
$cp = $cpInfo[$this->readUnsignedShort()];
1916

20-
// $invokeClassName = '\\' . str_replace('/', '\\', $cpList[$class->getClassIndex()]->getString());
17+
$cp = $cpInfo[$this->readUnsignedShort()];
2118

22-
2319
$nameAndTypeIndex = $cpInfo[$cp->getNameAndTypeIndex()];
2420

2521
// signature
2622
$signature = Formatter::parseSignature($cpInfo[$nameAndTypeIndex->getDescriptorIndex()]->getString());
2723

28-
$invokeClassName = $this->getStack();
24+
$invokerClassName = $this->getStack();
2925

3026
$arguments = [];
3127

3228
for ($i = 0; $i < $signature['argumentsCount']; $i++) {
3329
$arguments[] = $this->getStack();
3430
}
31+
32+
$methodName = $cpInfo[$nameAndTypeIndex->getNameIndex()]->getString();
33+
34+
// $result = call_user_func_array(
35+
// [$this->javaClassInvoker->getDynamicMethods(), $methodName],
36+
// $arguments
37+
// );
38+
//
39+
// if ($signature[0]['type'] !== 'void') {
40+
// $this->pushStack($result);
41+
// }
3542
}
3643
}

src/kernel/opcode/_tableswitch.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function execute(): void
3333
return;
3434
}
3535

36+
3637
// goto default
3738
$this->setOffset($this->getPointer() + $offsets['default']);
3839
}

tools/Test.class

-165 Bytes
Binary file not shown.

tools/test.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TestEmulates {
55
class Test {
66

77
long z = -22222222222222222L;
8-
static int c = 100;
8+
static int c = 5;
99
static String b = "Hello World";
1010

1111
/**
@@ -157,6 +157,11 @@ public static void main (String[] args) {
157157
t2 += 1;
158158
t2 = 1;
159159

160+
161+
System.out.println(args[0]);
162+
System.out.println(args[1]);
163+
System.out.println(args[2]);
164+
160165
/*boolean _b = false;
161166
_b = true && true;
162167
_b = true && false;
@@ -209,31 +214,24 @@ public static void main (String[] args) {
209214
System.out.println("ぬるぷっぷー");
210215

211216
}
212-
217+
213218
String[] test = {"4", "5", "6"};
214219
for (String i : test) {
215-
220+
216221
System.out.println(i);
217222

218223
}
219-
224+
220225
int[] test2 = {1, 2, 3};
221226
for (int i : test2) {
222-
227+
223228
System.out.println(i);
224229

225230
}
226-
231+
227232
long[] test3 = {1L, 2L, 3L};
228233
for (long i : test3) {
229-
230-
System.out.println(i);
231234

232-
}
233-
234-
double[] test4 = {3.4, 3.5, 3.6, 81263.12312321, -99};
235-
for (double i : test4) {
236-
237235
System.out.println(i);
238236

239237
}

0 commit comments

Comments
 (0)