Skip to content

Commit

Permalink
Improve classpath and add some system properties
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandezseb committed Mar 28, 2024
1 parent 26780ee commit 3813787
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/ClassLoader/ClassLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ ClassInfo* ClassLoader::readClass(const char* className, Memory* memory, [[maybe
char name[300] = {0};
snprintf(name, 300, "%s.class", className);

PHYSFS_addToSearchPath(".", 1);
PHYSFS_addToSearchPath("extern/classpath/rt.jar/rt.jar", 1);
if (classPath != nullptr && strlen(classPath) > 0) {
PHYSFS_addToSearchPath(classPath, 1);
Expand Down
17 changes: 12 additions & 5 deletions src/Library/java/lang/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,24 @@ JCALL void lib_java_lang_System_arraycopy(const NativeArgs& args)
lengthVar.data * bytes);
}

static void setProperty(const NativeArgs& args, Variable propertiesObjectRef, ClassInfo* classInfo, const MethodInfo* methodInfo, const char* key, const char* value)
{
args.thread->pushStackFrameWithoutParams(classInfo, methodInfo);
args.thread->m_currentFrame->localVariables[0] = propertiesObjectRef;
args.thread->m_currentFrame->localVariables[1] = Variable{VariableType_REFERENCE,args.heap->createString(key, args.vm)};
args.thread->m_currentFrame->localVariables[2] = Variable{VariableType_REFERENCE,args.heap->createString(value, args.vm)};
args.vm->executeLoop(args.thread);
}

JCALL void lib_java_lang_System_initProperties(const NativeArgs& args)
{
const Variable propertiesObjectRef = args.thread->m_currentFrame->localVariables[0];
const Object* properties = args.heap->getObject(propertiesObjectRef.data);
const MethodInfo* entryPoint = properties->classInfo->findMethodWithNameAndDescriptor("setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;");

args.thread->pushStackFrameWithoutParams(properties->classInfo, entryPoint);
args.thread->m_currentFrame->localVariables[0] = propertiesObjectRef;
args.thread->m_currentFrame->localVariables[1] = Variable{VariableType_REFERENCE,args.heap->createString("file.encoding", args.vm)};
args.thread->m_currentFrame->localVariables[2] = Variable{VariableType_REFERENCE,args.heap->createString("UTF-8", args.vm)};
args.vm->executeLoop(args.thread);
setProperty(args, propertiesObjectRef, properties->classInfo, entryPoint, "file.encoding", "UTF-8");
setProperty(args, propertiesObjectRef, properties->classInfo, entryPoint, "user.dir", args.vm->userDir.c_str());
setProperty(args, propertiesObjectRef, properties->classInfo, entryPoint, "sun.jnu.encoding", "Cp1252");

args.thread->returnVar(propertiesObjectRef);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Library/vigur/lang/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ JCALL void lib_vigur_lang_System_registerNatives(const NativeArgs& args)

JCALL void lib_vigur_lang_System_printLnString(const NativeArgs& args)
{
Variable strVar = args.thread->m_currentFrame->localVariables[0];
const Variable strVar = args.thread->m_currentFrame->localVariables[0];
const Object* obj = args.heap->getObject(strVar.data);
const FieldData* charArrRef = obj->getField("value", "[C", args.heap);
const Array* charArr = args.heap->getArray(charArrRef->data[0].data);
Platform::print((const char*)charArr->data, charArr->length);
Platform::print(reinterpret_cast<const char*>(charArr->data), charArr->length);
Platform::print("\n", 1);
}
7 changes: 6 additions & 1 deletion src/VM/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ void VM::start(std::string_view commandLineName)
{
Platform::initialize();
PHYSFS_init(commandLineName.data());
PHYSFS_permitSymbolicLinks(1);
PHYSFS_permitSymbolicLinks(0);

const size_t backSlash = commandLineName.find_last_of('\\');
const size_t forwardSlash = commandLineName.find_last_of('/');
userDir = commandLineName.substr(0, backSlash < forwardSlash ? backSlash : forwardSlash);
PHYSFS_addToSearchPath(userDir.c_str(), 1);

registerBuiltinRegisterNatives();
getClass("java/lang/OutOfMemoryError", &m_mainThread);
Expand Down
1 change: 1 addition & 0 deletions src/VM/VM.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class VM {
}
bool isSubclass(VMThread* thread, const ClassInfo* targetClass, ClassInfo* subClass);
FieldInfo* findField(ClassInfo* classInfo, const char* name, const char* descriptor, VMThread* thread);
std::string userDir;
private:
void initSystemClass(ClassInfo* class_info, VMThread* vm_thread);
static constexpr std::array<Instruction,131> m_instructions{{
Expand Down

0 comments on commit 3813787

Please sign in to comment.