Skip to content

Commit 6e836ef

Browse files
committed
VM: conpress structs
1 parent 198fb66 commit 6e836ef

8 files changed

Lines changed: 84 additions & 21 deletions

File tree

include/openminecraft/vm/pixeltower/om_pixeltower_class_structdef.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ namespace openminecraft::vm::pixeltower
1212
{
1313
enum OMFieldType
1414
{
15+
Bytes1,
16+
Bytes2,
1517
Bytes4,
1618
Bytes8,
1719
BytesP

src/vm/pixeltower/om_pixeltower.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,15 @@ std::string OMPixelTower::printInstanceData(void *block, int layer, bool isArray
146146
auto arr = (OMArrayHeader *)block;
147147
if (block == nullptr)
148148
{
149-
return pref + fmt::format("{}> ???{}", OMLogAnsiBlackLight, OMLogAnsiReset);
149+
return pref + fmt::format("{}???{}", OMLogAnsiBlackLight, OMLogAnsiReset);
150150
}
151151
else if (arr->classifierPointer == &ARRAY_TYPE)
152152
{
153153
std::string target = "";
154-
target += pref + fmt::format("> length: {}\n", arr->length);
154+
target += pref + fmt::format("length: {}\n", arr->length);
155155
for (int i = 0; i < arr->length; i++)
156156
{
157-
target += pref + fmt::format("> {}[{}]{} ", OMLogAnsiBlueLight, i, OMLogAnsiReset);
157+
target += pref + fmt::format("{}[{}]{} ", OMLogAnsiBlueLight, i, OMLogAnsiReset);
158158
switch (arr->type)
159159
{
160160
case Byte:
@@ -226,7 +226,7 @@ std::string OMPixelTower::printInstanceData(void *block, int layer, bool isArray
226226
break;
227227
}
228228
target +=
229-
pref + fmt::format("> field {2}{0}{3}: {1}\n", field->name, item, OMLogAnsiCyanLight, OMLogAnsiReset);
229+
pref + fmt::format("field {2}{0}{3}: {1}\n", field->name, item, OMLogAnsiCyanLight, OMLogAnsiReset);
230230
}
231231
}
232232

src/vm/pixeltower/om_pixeltower_class.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ void OMClass::calcFieldOffsets()
3737

3838
switch (field->type)
3939
{
40+
case Bytes1:
41+
*length += 1 - (*length % 1);
42+
break;
43+
case Bytes2:
44+
*length += 2 - (*length % 2);
45+
break;
4046
case Bytes4:
4147
*length += 4 - (*length % 4);
4248
break;

src/vm/pixeltower/om_pixeltower_classloader.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ void OMClassLoader::loadClass(std::shared_ptr<OMClassFile> file)
5555
switch (m[0])
5656
{
5757
case 'Z':
58-
case 'I':
58+
case 'C':
5959
case 'B':
60+
f->type = Bytes1;
61+
break;
6062
case 'S':
63+
f->type = Bytes2;
64+
break;
65+
case 'I':
6166
case 'F':
62-
case 'C':
6367
f->type = Bytes4;
6468
break;
6569
case 'J':

src/vm/pixeltower/om_pixeltower_interpreter.cpp

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,14 @@ void OMInterpreter::execute(std::shared_ptr<OMClass> clazz, std::shared_ptr<OMMe
282282

283283
default: {
284284
tower.debugStackStatus();
285-
throw err::OMValidationError{err::Instructions, "instructions not implemented",
285+
throw err::OMValidationError{err::Instructions, "we hitted the azure bounary (unknown instruction)",
286286
fetchCurrentPosition(frame)};
287287
}
288288
}
289289
}
290290
}
291291

292-
throw err::OMValidationError{err::Instructions, "code heap overflow!", fetchCurrentPosition(frame)};
292+
throw err::OMValidationError{err::Instructions, "what are you executing?", fetchCurrentPosition(frame)};
293293
}
294294
void OMInterpreter::checkType(std::shared_ptr<OMFrameMetadata> frame, std::any data, std::string desc)
295295
{
@@ -495,24 +495,47 @@ std::string OMInterpreter::fetchName(OMArrayType type)
495495
return "ref";
496496
}
497497
}
498-
// TODO: other types
499498
void OMInterpreter::writeStackTop(void *target, std::string desc, std::shared_ptr<OMFrameMetadata> frame)
500499
{
501500
STACK_CHECK;
502501
auto it = std::type_index(STACK_ACCESS.top().type());
503502

504-
if (it == std::type_index(typeid(int)))
503+
int temp = 0;
504+
auto descparsed = bytecode::descriptor::decodeType(desc, &temp);
505+
if (descparsed.type == util::Err)
505506
{
506-
*((int *)target) = std::any_cast<int>(STACK_ACCESS.top());
507+
throw err::OMValidationError{err::Instructions,
508+
fmt::format("unknown field descriptor, {}", descparsed.unwrap_err()),
509+
fetchCurrentPosition(frame)};
507510
}
508-
else if (it == std::type_index(typeid(void *)))
511+
512+
checkType(frame, STACK_ACCESS.top(), descparsed.unwrap());
513+
514+
switch (hash_compile_time(descparsed.unwrap().c_str()))
509515
{
516+
case "boolean"_hash:
517+
case "char"_hash:
518+
case "byte"_hash:
519+
*((char *)target) = std::any_cast<int>(STACK_ACCESS.top());
520+
break;
521+
case "short"_hash:
522+
*((short *)target) = std::any_cast<int>(STACK_ACCESS.top());
523+
break;
524+
case "int"_hash:
525+
*((int *)target) = std::any_cast<int>(STACK_ACCESS.top());
526+
break;
527+
case "long"_hash:
528+
*((int64_t *)target) = std::any_cast<int64_t>(STACK_ACCESS.top());
529+
break;
530+
case "float"_hash:
531+
*((float *)target) = std::any_cast<float>(STACK_ACCESS.top());
532+
break;
533+
case "double"_hash:
534+
*((double *)target) = std::any_cast<double>(STACK_ACCESS.top());
535+
break;
536+
default:
510537
*((void **)target) = std::any_cast<void *>(STACK_ACCESS.top());
511-
}
512-
else
513-
{
514-
throw err::OMValidationError{err::Instructions, fmt::format("unknown stack top data"),
515-
fetchCurrentPosition(frame)};
538+
break;
516539
}
517540

518541
SAFE_STACK_POP;

vmstd/compile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ recursive_listdir("./src")
2222

2323
def compile(s):
2424
print(f"Compiling {s} ...")
25-
ret = os.system(f"javac -Xlint:-options --release 8 {s} -d out")
25+
ret = os.system(f"javac -Xlint:-options --release 8 {s} -cp src -d out")
2626

2727
if not ret == 0:
2828
print(f"{s} compilation failed")

vmstd/src/java/io/PrintStream.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
package java.io;
22

33
public class PrintStream {
4+
public PrintStream() {
5+
6+
}
7+
8+
public void println(boolean b) {}
9+
public void println(int i) {}
10+
public void println(byte b) {}
411
public void println(char c) {}
5-
public void println(long c) {}
6-
public void println(float c) {}
7-
public void println(double c) {}
12+
public void println(long l) {}
13+
public void println(float f) {}
14+
public void println(double d) {}
15+
public void println(String s) {}
816
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package vmstd.internal;
2+
3+
import java.io.PrintStream;
4+
5+
public class SystemPrintStream extends PrintStream {
6+
public final int fd;
7+
public SystemPrintStream(int fd) {
8+
super();
9+
this.fd = fd;
10+
}
11+
12+
public native void println(boolean b);
13+
public native void println(int i);
14+
public native void println(byte b);
15+
public native void println(char c);
16+
public native void println(long l);
17+
public native void println(float f);
18+
public native void println(double d);
19+
public native void println(String s);
20+
}

0 commit comments

Comments
 (0)