diff --git a/plugins/ets/runtime/ets_coroutine.h b/plugins/ets/runtime/ets_coroutine.h index 778d8445d54da1ed355c224af28de9634565d7c4..103d9bfd2683642b47396cc42044c8d63d8d5d16 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 86427db288dfae9a7558d797bcf1aa0d91f1a7df..e223e1302b887c55ff87a0bc4cf2e28c27f616e3 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 560c903686f6fd9456f766926790cdd734871af7..5ea23a79a0fb4e6a906b6285128aac95d68ca195 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 441dc2cd141af2c3953cc468711089d82847c6cd..cb7042af63b329d0f5861ba95944bbdc5d683386 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 2c022d53af85a2af5fdea1847144709c1316a95f..ba099c2ec3e186dd05d392007233a250733425e5 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