Skip to content

Commit

Permalink
Update api
Browse files Browse the repository at this point in the history
  • Loading branch information
qubka committed Sep 29, 2024
1 parent 4a09701 commit 537afa8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ set(GOLM_PCH_FILE "src/pch.h")
add_library(${PROJECT_NAME} SHARED ${GOLM_SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)

set(GOLM_LINK_LIBRARIES plugify::plugify plugify::plugify-function plugify::plugify-assembly plugify::plugify-assembly asmjit::asmjit dyncall_s)
set(GOLM_LINK_LIBRARIES plugify::plugify plugify::plugify-assembly asmjit::asmjit dyncall_s dyncallback_s)

if(NOT COMPILER_SUPPORTS_FORMAT)
set(GOLM_LINK_LIBRARIES ${GOLM_LINK_LIBRARIES} fmt::fmt-header-only)
Expand Down
82 changes: 41 additions & 41 deletions src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,13 @@ LoadResult GoLanguageModule::OnPluginLoad(PluginRef plugin) {
if (IsMethodPrimitive(method)) {
methods.emplace_back(method, func);
} else {
auto function = std::make_unique<Function>(_rt);
func = function->GetJitFunc(method, &InternalCall, func);
JitCallback callback(_rt);
func = callback.GetJitFunc(method, &InternalCall, func);
if (!func) {
funcErrors.emplace_back(method.GetName());
continue;
}
_functions.emplace_back(std::move(function));
_functions.emplace_back(std::move(callback));
methods.emplace_back(method, func);
}
} else {
Expand Down Expand Up @@ -402,7 +402,7 @@ void GoLanguageModule::GetNativeMethod(std::string_view methodName, plugify::Mem
}

// C++ to Go
void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parameters* p, uint8_t count, const ReturnValue* ret) {
void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const JitCallback::Parameters* p, uint8_t count, const JitCallback::Return* ret) {
PropertyRef retProp = method.GetReturnType();
ValueType retType = retProp.GetType();
std::span<const PropertyRef> paramProps = method.GetParamTypes();
Expand Down Expand Up @@ -699,244 +699,244 @@ void GoLanguageModule::InternalCall(MethodRef method, MemAddr addr, const Parame
}
case ValueType::Bool: {
bool val = dcCallBool(vm, addr);
ret->SetReturnPtr(val);
ret->SetReturn(val);
break;
}
case ValueType::Char8: {
char16_t val = static_cast<char16_t>(dcCallChar(vm, addr));
ret->SetReturnPtr(val);
ret->SetReturn(val);
break;
}
case ValueType::Char16: {
char16_t val = static_cast<char16_t>(dcCallShort(vm, addr));
ret->SetReturnPtr(val);
ret->SetReturn(val);
break;
}
case ValueType::Int8: {
int8_t val = dcCallChar(vm, addr);
ret->SetReturnPtr(val);
ret->SetReturn(val);
break;
}
case ValueType::Int16: {
int16_t val = dcCallShort(vm, addr);
ret->SetReturnPtr(val);
ret->SetReturn(val);
break;
}
case ValueType::Int32: {
int32_t val = dcCallInt(vm, addr);
ret->SetReturnPtr(val);
ret->SetReturn(val);
break;
}
case ValueType::Int64: {
int64_t val = dcCallLongLong(vm, addr);
ret->SetReturnPtr(val);
ret->SetReturn(val);
break;
}
case ValueType::UInt8: {
uint8_t val = static_cast<uint8_t>(dcCallChar(vm, addr));
ret->SetReturnPtr(val);
ret->SetReturn(val);
break;
}
case ValueType::UInt16: {
uint16_t val = static_cast<uint16_t>(dcCallShort(vm, addr));
ret->SetReturnPtr(val);
ret->SetReturn(val);
break;
}
case ValueType::UInt32: {
uint32_t val = static_cast<uint32_t>(dcCallInt(vm, addr));
ret->SetReturnPtr(val);
ret->SetReturn(val);
break;
}
case ValueType::UInt64: {
uint64_t val = static_cast<uint64_t>(dcCallLongLong(vm, addr));
ret->SetReturnPtr(val);
ret->SetReturn(val);
break;
}
case ValueType::Pointer: {
void* val = dcCallPointer(vm, addr);
ret->SetReturnPtr(val);
ret->SetReturn(val);
break;
}
case ValueType::Float: {
float val = dcCallFloat(vm, addr);
ret->SetReturnPtr(val);
ret->SetReturn(val);
break;
}
case ValueType::Double: {
double val = dcCallDouble(vm, addr);
ret->SetReturnPtr(val);
ret->SetReturn(val);
break;
}
case ValueType::Function: {
void* val = dcCallPointer(vm, addr);
ret->SetReturnPtr(val);
ret->SetReturn(val);
break;
}
case ValueType::Vector2: {
Vector2 source;
dcCallAggr(vm, addr, ag, &source);
ret->SetReturnPtr(source);
ret->SetReturn(source);
break;
}
#if GOLM_PLATFORM_WINDOWS
case ValueType::Vector3: {
auto* dest = p->GetArgument<Vector3*>(0);
dcCallAggr(vm, addr, ag, dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::Vector4: {
auto* dest = p->GetArgument<Vector4*>(0);
dcCallAggr(vm, addr, ag, dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
#else
case ValueType::Vector3: {
Vector3 source;
dcCallAggr(vm, addr, ag, &source);
ret->SetReturnPtr(source);
ret->SetReturn(source);
break;
}
case ValueType::Vector4: {
Vector4 source;
dcCallAggr(vm, addr, ag, &source);
ret->SetReturnPtr(source);
ret->SetReturn(source);
break;
}
#endif
case ValueType::Matrix4x4: {
auto* dest = p->GetArgument<Matrix4x4*>(0);
dcCallAggr(vm, addr, ag, dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::String: {
auto* dest = p->GetArgument<plg::string*>(0);
GoString source;
dcCallAggr(vm, addr, ag, &source);
CopyGoStringToStringReturn(source, *dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::ArrayBool: {
auto* dest = p->GetArgument<std::vector<bool>*>(0);
GoSlice source;
dcCallAggr(vm, addr, ag, &source);
CopyGoSliceToVectorReturn(source, *dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::ArrayChar8: {
auto* dest = p->GetArgument<std::vector<char>*>(0);
GoSlice source;
dcCallAggr(vm, addr, ag, &source);
CopyGoSliceToVectorReturn(source, *dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::ArrayChar16: {
auto* dest = p->GetArgument<std::vector<char16_t>*>(0);
GoSlice source;
dcCallAggr(vm, addr, ag, &source);
CopyGoSliceToVectorReturn(source, *dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::ArrayInt8: {
auto* dest = p->GetArgument<std::vector<int8_t>*>(0);
GoSlice source;
dcCallAggr(vm, addr, ag, &source);
CopyGoSliceToVectorReturn(source, *dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::ArrayInt16: {
auto* dest = p->GetArgument<std::vector<int16_t>*>(0);
GoSlice source;
dcCallAggr(vm, addr, ag, &source);
CopyGoSliceToVectorReturn(source, *dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::ArrayInt32: {
auto* dest = p->GetArgument<std::vector<int32_t>*>(0);
GoSlice source;
dcCallAggr(vm, addr, ag, &source);
CopyGoSliceToVectorReturn(source, *dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::ArrayInt64: {
auto* dest = p->GetArgument<std::vector<int64_t>*>(0);
GoSlice source;
dcCallAggr(vm, addr, ag, &source);
CopyGoSliceToVectorReturn(source, *dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::ArrayUInt8: {
auto* dest = p->GetArgument<std::vector<uint8_t>*>(0);
GoSlice source;
dcCallAggr(vm, addr, ag, &source);
CopyGoSliceToVectorReturn(source, *dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::ArrayUInt16: {
auto* dest = p->GetArgument<std::vector<uint16_t>*>(0);
GoSlice source;
dcCallAggr(vm, addr, ag, &source);
CopyGoSliceToVectorReturn(source, *dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::ArrayUInt32: {
auto* dest = p->GetArgument<std::vector<uint32_t>*>(0);
GoSlice source;
dcCallAggr(vm, addr, ag, &source);
CopyGoSliceToVectorReturn(source, *dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::ArrayUInt64: {
auto* dest = p->GetArgument<std::vector<uint64_t>*>(0);
GoSlice source;
dcCallAggr(vm, addr, ag, &source);
CopyGoSliceToVectorReturn(source, *dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::ArrayPointer: {
auto* dest = p->GetArgument<std::vector<uintptr_t>*>(0);
GoSlice source;
dcCallAggr(vm, addr, ag, &source);
CopyGoSliceToVectorReturn(source, *dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::ArrayFloat: {
auto* dest = p->GetArgument<std::vector<float>*>(0);
GoSlice source;
dcCallAggr(vm, addr, ag, &source);
CopyGoSliceToVectorReturn(source, *dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::ArrayDouble: {
auto* dest = p->GetArgument<std::vector<double>*>(0);
GoSlice source;
dcCallAggr(vm, addr, ag, &source);
CopyGoSliceToVectorReturn(source, *dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
case ValueType::ArrayString: {
auto* dest = p->GetArgument<std::vector<plg::string>*>(0);
GoSlice source;
dcCallAggr(vm, addr, ag, &source);
CopyGoSliceToVectorReturn(source, *dest);
ret->SetReturnPtr(dest);
ret->SetReturn(dest);
break;
}
default:
Expand Down
6 changes: 3 additions & 3 deletions src/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <asmjit/asmjit.h>
#include <module_export.h>
#include <plugify/assembly.h>
#include <plugify/function.h>
#include <plugify/jit/callback.h>
#include <plugify/language_module.h>
#include <plugify/module.h>

Expand Down Expand Up @@ -106,7 +106,7 @@ namespace golm {
void GetNativeMethod(std::string_view methodName, plugify::MemAddr* addressDest);

private:
static void InternalCall(plugify::MethodRef method, plugify::MemAddr data, const plugify::Parameters* params, uint8_t count, const plugify::ReturnValue* ret);
static void InternalCall(plugify::MethodRef method, plugify::MemAddr data, const plugify::JitCallback::Parameters* params, uint8_t count, const plugify::JitCallback::Return* ret);
static void DetectLeaks();

private:
Expand All @@ -116,7 +116,7 @@ namespace golm {
std::map<plugify::UniqueId, AssemblyHolder> _assemblyMap;
std::unordered_map<std::string, plugify::MemAddr, string_hash, std::equal_to<>> _nativesMap;

std::vector<std::unique_ptr<plugify::Function>> _functions;
std::vector<plugify::JitCallback> _functions;
std::vector<plugify::MemAddr*> _addresses;

static const std::array<void*, 35> _pluginApi;
Expand Down

0 comments on commit 537afa8

Please sign in to comment.