• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <iostream>
17 #include <string_view>
18 #include "plugins/ets/runtime/ets_vm.h"
19 #include "plugins/ets/runtime/types/ets_string.h"
20 #include "plugins/ets/runtime/types/ets_void.h"
21 #include "libpandabase/utils/utf.h"
22 
23 #include "intrinsics.h"
24 
25 namespace panda::ets::intrinsics {
26 
StdConsolePrintln(ObjectHeader * header)27 extern "C" EtsVoid *StdConsolePrintln(ObjectHeader *header [[maybe_unused]])
28 {
29     std::cout << std::endl;
30     return EtsVoid::GetInstance();
31 }
32 
StdConsolePrintBool(ObjectHeader * header,uint8_t b)33 extern "C" EtsVoid *StdConsolePrintBool([[maybe_unused]] ObjectHeader *header, uint8_t b)
34 {
35     if (b != 0U) {
36         std::cout << "true";
37     } else {
38         std::cout << "false";
39     }
40     return EtsVoid::GetInstance();
41 }
42 
StdConsolePrintChar(ObjectHeader * header,uint16_t c)43 extern "C" EtsVoid *StdConsolePrintChar([[maybe_unused]] ObjectHeader *header, uint16_t c)
44 {
45     const utf::Utf8Char utf8Ch = utf::ConvertUtf16ToUtf8(c, 0, false);
46     std::cout << std::string_view(reinterpret_cast<const char *>(utf8Ch.ch.data()), utf8Ch.n);
47     return EtsVoid::GetInstance();
48 }
49 
StdConsolePrintString(ObjectHeader * header,EtsString * str)50 extern "C" EtsVoid *StdConsolePrintString([[maybe_unused]] ObjectHeader *header, EtsString *str)
51 {
52     panda::intrinsics::PrintString(str->GetCoreType());
53     return EtsVoid::GetInstance();
54 }
55 
StdConsolePrintI32(ObjectHeader * header,int32_t v)56 extern "C" EtsVoid *StdConsolePrintI32([[maybe_unused]] ObjectHeader *header, int32_t v)
57 {
58     panda::intrinsics::PrintI32(v);
59     return EtsVoid::GetInstance();
60 }
61 
StdConsolePrintI16(ObjectHeader * header,int16_t v)62 extern "C" EtsVoid *StdConsolePrintI16([[maybe_unused]] ObjectHeader *header, int16_t v)
63 {
64     panda::intrinsics::PrintI32(v);
65     return EtsVoid::GetInstance();
66 }
67 
StdConsolePrintI8(ObjectHeader * header,int8_t v)68 extern "C" EtsVoid *StdConsolePrintI8([[maybe_unused]] ObjectHeader *header, int8_t v)
69 {
70     panda::intrinsics::PrintI32(v);
71     return EtsVoid::GetInstance();
72 }
73 
StdConsolePrintI64(ObjectHeader * header,int64_t v)74 extern "C" EtsVoid *StdConsolePrintI64([[maybe_unused]] ObjectHeader *header, int64_t v)
75 {
76     panda::intrinsics::PrintI64(v);
77     return EtsVoid::GetInstance();
78 }
79 
80 }  // namespace panda::ets::intrinsics
81