From c40a472633636032a09e4460240ce57d9ffe314a Mon Sep 17 00:00:00 2001 From: Mitkin Kirill Date: Mon, 24 Jul 2023 20:25:55 +0300 Subject: [PATCH] implement generic type info prototype Signed-off-by: Mitkin Kirill add generic type info Signed-off-by: Mitkin Kirill add rethrowing generic context Signed-off-by: Mitkin Kirill remove reflect type from runtime Signed-off-by: Mitkin Kirill refactor code Signed-off-by: Mitkin Kirill --- plugins/ets/runtime/ets_coroutine.h | 11 ++++++ plugins/ets/runtime/ets_libbase_runtime.yaml | 34 +++++++++++++++++++ .../ets/runtime/intrinsics/std_core_Type.cpp | 29 ++++++++++++++++ plugins/ets/stdlib/std/core/Field.ets | 7 ++-- plugins/ets/stdlib/std/core/Type.ets | 11 +++++- 5 files changed, 87 insertions(+), 5 deletions(-) diff --git a/plugins/ets/runtime/ets_coroutine.h b/plugins/ets/runtime/ets_coroutine.h index 778d8445d..103d9bfd2 100644 --- a/plugins/ets/runtime/ets_coroutine.h +++ b/plugins/ets/runtime/ets_coroutine.h @@ -21,6 +21,7 @@ namespace panda::ets { class PandaEtsVM; +class EtsObjectArray; /** * \brief The eTS coroutine. It is aware of the native interface and reference storage existance. @@ -70,6 +71,11 @@ public: promise_class_ptr_ = promise_class; } + void SetTypeParams(EtsObjectArray * type_class) + { + type_params_ = type_class; + } + static constexpr uint32_t GetTlsPromiseClassPointerOffset() { return MEMBER_OFFSET(EtsCoroutine, promise_class_ptr_); @@ -82,6 +88,10 @@ public: return ets_napi_env_.get(); } + EtsObjectArray * GetTypeParams() const { + return type_params_; + } + void Initialize() override; void RequestCompletion(Value return_value) override; void FreeInternalMemory() override; @@ -97,6 +107,7 @@ private: std::unique_ptr ets_napi_env_; void *promise_class_ptr_ {nullptr}; + EtsObjectArray* type_params_; // Allocator calls our protected ctor friend class mem::Allocator; diff --git a/plugins/ets/runtime/ets_libbase_runtime.yaml b/plugins/ets/runtime/ets_libbase_runtime.yaml index 86427db28..e223e1302 100644 --- a/plugins/ets/runtime/ets_libbase_runtime.yaml +++ b/plugins/ets/runtime/ets_libbase_runtime.yaml @@ -1611,6 +1611,40 @@ intrinsics: ret: std.core.String args: [ std.core.String ] impl: panda::ets::intrinsics::TypeAPIGetBaseType + clear_flags: [ ] + + - name: StdCoreTypeStoreTypeParamDescriptors + space: ets + class_name: std.core.ETSGLOBAL + method_name: StoreTypeParamDescriptors + static: true + signature: + ret: void + args: [ 'std.core.String[]' ] + impl: panda::ets::intrinsics::TypeAPIStoreTypeParamDescriptors + clear_flags: [ ] + + - name: StdCoreTypeLoadTypeParamDescriptors + space: ets + class_name: std.core.ETSGLOBAL + method_name: LoadTypeParamDescriptors + static: true + signature: + ret: std.core.String[] + args: [] + impl: panda::ets::intrinsics::TypeAPILoadTypeParamDescriptors + clear_flags: [ ] + + - name: StdCoreTypeGetGenericTypeDesc + space: ets + class_name: std.core.ETSGLOBAL + method_name: GetGenericTypeDesc + static: true + signature: + ret: std.core.String + args: [] + impl: panda::ets::intrinsics::TypeAPIGetGenericTypeDesc + clear_flags: [ ] ################# # std.core.Char # diff --git a/plugins/ets/runtime/intrinsics/std_core_Type.cpp b/plugins/ets/runtime/intrinsics/std_core_Type.cpp index 560c90368..5ea23a79a 100644 --- a/plugins/ets/runtime/intrinsics/std_core_Type.cpp +++ b/plugins/ets/runtime/intrinsics/std_core_Type.cpp @@ -22,6 +22,9 @@ #include "intrinsics.h" #include "mem/mem.h" #include "mem/vm_handle.h" +#include "ets_coroutine.h" +#include "ets_vm.h" +#include "macros.h" #include "plugins/ets/runtime/types/ets_object.h" #include "plugins/ets/runtime/types/ets_string.h" #include "plugins/ets/runtime/ets_panda_file_items.h" @@ -34,6 +37,8 @@ #include "types/ets_typeapi_feature.h" #include "types/ets_typeapi_field.h" #include "types/ets_typeapi_method.h" +#include "plugins/ets/runtime/napi/ets_scoped_objects_fix.h" +#include "runtime/handle_scope-inl.h" namespace panda::ets::intrinsics { @@ -351,4 +356,28 @@ EtsString *TypeAPIGetBaseType(EtsString *td) } return EtsString::CreateFromMUtf8(base_class->GetDescriptor()); } + +void TypeAPIStoreTypeParamDescriptors(ObjectHeader *obj) +{ + auto arr = EtsObjectArray::FromCoreType(obj); + EtsCoroutine::GetCurrent()->SetTypeParams(arr); +} + +ObjectHeader *TypeAPILoadTypeParamDescriptors() +{ + return EtsCoroutine::GetCurrent()->GetTypeParams()->GetCoreType(); +} + +EtsString *TypeAPIGetGenericTypeDesc() +{ + auto params = EtsCoroutine::GetCurrent()->GetTypeParams(); + ASSERT(params->GetLength() == 1); + PandaString assembler_type; + auto type = EtsString::FromEtsObject(params->Get(0)); + assembler_type += CLASS_TYPE_PREFIX; + assembler_type += type->GetMutf8(); + assembler_type += TYPE_DESC_DELIMITER; + return EtsString::CreateFromMUtf8(assembler_type.c_str()); +} + } // namespace panda::ets::intrinsics diff --git a/plugins/ets/stdlib/std/core/Field.ets b/plugins/ets/stdlib/std/core/Field.ets index 441dc2cd1..cb7042af6 100644 --- a/plugins/ets/stdlib/std/core/Field.ets +++ b/plugins/ets/stdlib/std/core/Field.ets @@ -16,11 +16,10 @@ package std.core; export final class Field extends Object { - private td: string - private name: string - private accessMod: byte + private td: string + private name: string private attributes: int - + private accessMod: byte public getType(): Type { return Type.resolve(this.td) diff --git a/plugins/ets/stdlib/std/core/Type.ets b/plugins/ets/stdlib/std/core/Type.ets index 2c022d53a..ba099c2ec 100644 --- a/plugins/ets/stdlib/std/core/Type.ets +++ b/plugins/ets/stdlib/std/core/Type.ets @@ -47,6 +47,16 @@ native function TypeAPIMakeArrayInstance(td: TypeDesc, len: long): Object native function TypeAPIGetBaseType(td: TypeDesc): TypeDesc +native function StoreTypeParamDescriptors(typ: string[]): void + +native function LoadTypeParamDescriptors(): TypeDesc[] + +native function GetGenericTypeDesc(): TypeDesc + +export function GetGenericType(): Type { + return Type.resolve(GetGenericTypeDesc()) +} + // TODO(shumilov-petr): replace to enum, enum not available now export type TypeKind = byte @@ -1228,7 +1238,6 @@ export final class FunctionType extends Type { } } - export final class StringType extends Type { private static inst: StringType | null = null -- Gitee