Application program compiling method and electronic equipment

By marking and compiling the data types in the TS code and generating machine code before the application starts, the problem of low startup efficiency of the TS code in the existing technology is solved, and a method of quickly starting the application is realized.

CN118672585APending Publication Date: 2024-09-20HUAWEI TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202310315086.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-03-15
Publication Date
2024-09-20

AI Technical Summary

Technical Problem

In the existing technology, when starting an application, the TS code needs to go through multiple compilation and interpretation execution processes, resulting in low startup efficiency. In particular, the TS code without annotated data types cannot directly perform AOT processing, which affects the startup speed of the application.

Method used

Before the application starts, obtain and mark the unmarked data types in the TS code, generate an abstract syntax tree, compile all TS codes into machine code through AOT compilation processing, and call these machine codes directly at startup to improve the efficiency of the application. Startup efficiency.

Benefits of technology

By marking data types in advance and compiling TS code, multiple compilations and interpretations during the startup process are reduced, which significantly speeds up application startup and improves startup efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118672585A
    Figure CN118672585A
Patent Text Reader

Abstract

The embodiment of the invention provides a compiling method of an application program and electronic equipment, relates to the technical field of terminals, and can accelerate the starting speed of the application program and improve the starting efficiency of the application program. In the method, a first file can be obtained before a first application program is started, and the first file comprises at least one sentence of TS code corresponding to the first application program. And then, obtaining a first TS code which is not marked with a correct data type in each TS code, and marking the correct data type for the first TS code. Compiling processing such as AOT is executed on the TS codes marked with the correct data types, and all the TS codes marked with the correct data types are compiled into machine codes. When the first application program is started, the machine codes can be directly called and executed. The TS code compiling method and device are applied to the process that the electronic equipment compiles the TS codes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of terminal technology, and in particular to a method for compiling an application and an electronic device. Background Art

[0002] Compared with JavaScript (JS) code, TypeScript (TS) code adds a static type function. The static type function of TS code means that data type tags can be added to some or all statements in the TS code. When an electronic device starts an application, it will run the TS code corresponding to the application. In the process of running the TS code, the electronic device needs to compile the statements in the TS code into JS code. After that, the obtained JS code needs to be translated into machine code that can be recognized by the electronic device, and the machine code must be run to start the application. It can be seen that starting the application requires multiple processes, and the efficiency of starting the application is low. Summary of the invention

[0003] The embodiments of the present application provide a method for compiling an application and an electronic device, which can improve the startup efficiency of the application.

[0004] In order to achieve the above purpose, the embodiment of the present application adopts the following technical solution:

[0005] In a first aspect, an embodiment of the present application provides a method for compiling an application, which can be applied to an electronic device. The method includes: obtaining a first file, the first file including at least one TS code corresponding to a first application. Determining a first TS code that is not marked with a correct data type in at least one TS code. Modifying the first TS code in the first file to obtain the modified first file. The modified first file includes a TS code marked with a correct data type. Compiling the modified first file to generate a second file. The second file includes a machine code corresponding to the TS code in the modified first file.

[0006] In the method of the present application, before the first application is started, a first file including at least one TS code corresponding to the first application can be obtained. Afterwards, the first TS code that is not marked with the correct data type in each TS code is obtained, and the correct data type is marked for the first TS code. By performing compilation processing such as AOT on the TS code marked with the correct data type, all TS codes marked with the correct data type are compiled into machine code. When the first application is started, these machine codes can be directly called and executed. It can speed up the startup speed of the application and improve the startup efficiency of the application.

[0007] In combination with the first aspect, in a possible design, in the process of modifying the first TS code in the first file to obtain the modified first file, an abstract syntax tree can be generated based on the execution order of each TS code in the first file. The abstract syntax tree is used to represent the logical relationship between the TS codes in the first file, and the abstract syntax tree includes multiple nodes, each node is used to represent a sentence of TS code in the first file. The first TS code represented by the first node is modified. The first node is a node in the abstract syntax tree that meets a preset condition.

[0008] In this solution, although the first TS codes in the first file are not marked with the correct data type. However, when some first TS codes are marked with the correct data type, it may affect other first TS codes so that the correct data type can be derived. Therefore, based on the execution order of each TS code in the first file, an abstract syntax tree can be generated to obtain the logical relationship between each TS code in the first file. Afterwards, the first TS code represented by the first node in the abstract syntax tree can be obtained and modified so that all first TS codes included in the first file are marked with the correct data type, thereby reducing the number of modifications and improving modification efficiency.

[0009] In combination with the first aspect, in one possible design, the preset condition includes that the number of child nodes corresponding to the first node is greater than or equal to a preset number.

[0010] In combination with the first aspect, in one possible design, the preset condition includes that the first node corresponds to the largest number of child nodes.

[0011] In combination with the first aspect, in a possible design, the preset condition includes that the first node has no parent node.

[0012] In combination with the first aspect, in a possible design, after determining that a first TS code is not marked with a correct data type in at least one TS code, the user may be prompted to modify the first TS code. Afterwards, a modification operation for the first TS code input by the user is received. In response to the modification operation, the first TS code is modified in the first file to obtain a modified first file.

[0013] In this solution, after the electronic device determines the first TS code, it can prompt the user to modify the first TS code. The user can independently label the first TS code with a correct data type label.

[0014] In combination with the first aspect, in one possible design, the first TS code includes a TS code in the first file that is not marked with a data type.

[0015] In combination with the first aspect, in one possible design, the first TS code includes a TS code of a data type error marked in the first file.

[0016] In a second aspect, an embodiment of the present application provides an electronic device. The electronic device includes a memory and one or more processors, the memory and the processor are coupled; the memory is used to store computer program code, the computer program code includes computer instructions, and when the processor executes the computer instructions, the electronic device executes the method described in the first aspect and any possible design thereof.

[0017] In a third aspect, an embodiment of the present application provides a chip system. The chip system includes one or more interface circuits and one or more processors. The interface circuit and the processor are interconnected by a line, and the interface circuit is used to receive a signal from a memory of an electronic device and send a signal to the processor, the signal including a computer instruction stored in the memory, and when the processor executes the computer instruction, the electronic device executes the method described in the first aspect and any possible design thereof.

[0018] In a fourth aspect, an embodiment of the present application provides a computer storage medium, including computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the method described in the first aspect and any possible design thereof.

[0019] In a fifth aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on a computer, the computer is caused to execute the method described in the first aspect and any possible design thereof. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 A schematic diagram of a method for starting an application provided by the prior art;

[0021] Figure 2 A hardware structure diagram of an electronic device provided in an embodiment of the present application;

[0022] Figure 3 A software structure block diagram of an electronic device provided in an embodiment of the present application;

[0023] Figure 4 A flowchart of a method for compiling an application provided in an embodiment of the present application;

[0024] Figure 5 A schematic diagram of the structure of a TS code intermediate representation provided in an embodiment of the present application;

[0025] Figure 6 A schematic diagram of the structure of an abstract syntax tree provided in an embodiment of the present application;

[0026] Figure 7 A schematic diagram of the structure of a compilation device provided in an embodiment of the present application;

[0027] Figure 8 A schematic diagram of an execution method of compiling an application provided in an embodiment of the present application;

[0028] Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0029] For ease of understanding, some examples of concepts related to the embodiments of the present application are provided for reference, as shown below:

[0030] JS code: It is a lightweight, interpreted or just-in-time compiled programming language with function priority. It can be used as a scripting language for browser development and can also be used in non-browser environments.

[0031] TS code: It is built by adding static type functions to JS code. TS code can be compiled into JS code by the corresponding compiler, and the compiled JS code can be run in browsers, operating systems, etc. that meet the JS code running environment.

[0032] Machine code: It can also be called machine language instructions or native code. It is the code that electronic devices can directly execute.

[0033] Source code: Original code that has not been executed or compiled.

[0034] AOT processing: that is, ahead of time compilation processing, which can compile the source code into the corresponding machine code in advance, and store the obtained machine code in memory, which can be directly called later.

[0035] Interpretation and execution: The source code is directly input as the source program, and when the source code is executed, the source code is translated into machine code that can be directly executed one by one, and the machine code that can be directly executed after translation will not be stored in the memory and will be discarded after use.

[0036] Just-in-time (JIT): Compiles frequently used hot statements in the source code into machine code that can be directly executed, saves it to memory, and can be called directly later.

[0037] Assembly language: It is a low-level language used in electronic devices, microprocessors, microcontrollers or other programmable devices, also known as symbolic language. In assembly language, mnemonics are used instead of machine code opcodes, and address symbols or labels are used instead of machine code addresses. In different electronic devices, assembly language corresponds to different machine code sets and is converted into machine code through the assembly process. There is a one-to-one correspondence between a specific assembly language and a specific machine code set.

[0038] Bytecode: The file generated after the source code is compiled by the virtual machine compiler.

[0039] Virtual machine: an abstract virtual machine is added between the machine and the compiler. The virtual machine provides a common interface to the compiler on any platform. The compiler only needs to face the virtual machine and generate code (bytecode) that the virtual machine can understand, and then the interpreter converts the bytecode into machine code for a specific system for execution.

[0040] Compiler: It is a functional module that converts one language into another language. Among them, most compilers are functional modules that translate source code into machine code. In order to reduce the difficulty of compiler code implementation and improve the scalability of the compiler, the compiler can be divided into compiler front-end, compiler mid-end, and compiler back-end during implementation, and the compiler front-end, compiler mid-end, and compiler back-end are implemented independently. Among them, the compiler front-end is mainly responsible for preprocessing, lexical analysis, syntax analysis, semantic analysis, and generating intermediate representations (IR) for subsequent processing; the compiler mid-end performs analysis and various optimizations, such as constant folding, dead code elimination, etc.; the compiler back-end is responsible for generating target code (compiled code or machine code), and the target code is platform-related assembly code. Among them, if there is only one compiler in the program processing process, the compiler will further translate the assembly code into machine code after generating the target code.

[0041] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.

[0042] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of this embodiment, unless otherwise specified, "plurality" means two or more.

[0043] TS code is a superset of JS code and can be obtained by adding static type functions to JS code. Adding static type functions to JS code makes it easier to refactor the code without seriously damaging the code. It also makes large and complex application source code easier to read. Since TS code is based on JS code, TS code can be used anywhere JS code can be used.

[0044] In a related technology, when an electronic device starts an application, it can use an interpreted execution method to run the TS code corresponding to the application. Figure 1 , the electronic device can first compile the TS code corresponding to the application into JS code and input it into the virtual machine to further compile the JS code into machine code. During the interpretation and execution, each machine code is interpreted and the interpreted machine code is run. The speed of starting the application is slow and the efficiency is low.

[0045] In a related technology, the electronic device can also perform AOT processing on the TS code corresponding to the application before starting the application to compile the TS code into the corresponding machine code and store the machine code in the memory of the electronic device. When the electronic device starts the application, the machine code corresponding to the application can be directly obtained and run.

[0046] However, performing AOT processing on TS code requires knowing the data type of each statement in the TS code. If there are statements of unknown data types in the TS code, AOT processing cannot be performed on the TS code.

[0047] In a related technology, the electronic device can also interpret and execute the TS code corresponding to the application in the JS virtual machine (such as V8) when starting the application, and obtain the hotspot statements in the TS code that are frequently used through JIT during the process of interpreting and executing the TS code. After obtaining the data type and the corresponding assembly language of the hotspot statement, the data type and the corresponding assembly language of the hotspot statement can be stored in the memory of the electronic device.

[0048] When the electronic device runs the TS code again or runs other TS codes, if a statement with the same data type as the stored hotspot statement appears, the assembly language corresponding to the hotspot statement is directly executed to improve the startup efficiency of the application.

[0049] However, the above method requires collecting the data type and corresponding assembly statement of the hot statement during the interpretation and execution process, and subsequently in the process of executing the assembly language, it is also necessary to obtain the machine code corresponding to the assembly language and execute the machine code, which will still affect the startup efficiency of the application.

[0050] Based on the above problems, an embodiment of the present application provides a method for compiling an application. In this method, before the first application is started, a first file can be obtained, and the first file includes at least one TS code corresponding to the first application. Afterwards, the first TS code that is not marked with the correct data type in each TS code is obtained, and the correct data type is marked for the first TS code. By performing processing such as AOT on the TS code marked with the correct data type, all TS codes marked with the correct data type are compiled into machine code. When the first application is started, these machine codes can be directly called and executed, thereby speeding up the startup speed of the application and improving the startup efficiency of the application.

[0051] Figure 2 A schematic structural diagram of an electronic device 100 is shown.

[0052] The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc.

[0053] It is to be understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or separate some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0054] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), a controller, a memory, a video codec, a digital signal processor (digital signal processor, DSP), a baseband processor, and / or a neural network processor (neural-network processing unit, NPU), etc. Among them, different processing units may be independent devices or integrated in one or more processors.

[0055] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.

[0056] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0057] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuits sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0058] The external memory interface 120 can be used to connect an external memory card, such as a MicroSD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.

[0059] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.

[0060] Exemplarily, the internal memory 121 may store a first file. The first file includes at least one TS code corresponding to the first application. When the electronic device 100 starts the first application, the processor 110 may call the first file and execute the TS code included in the first file.

[0061] Exemplarily, the internal memory 121 may also store a second file. The second file includes the machine code corresponding to the TS code included in the first file in the above example. When the electronic device 100 starts the first application, the processor 110 may call the second file and execute the machine code included in the second file.

[0062] The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. In the embodiment of the present invention, the Android system of the layered architecture is taken as an example to exemplify the software structure of the electronic device 100.

[0063] Figure 3 1 is a software structure block diagram of the electronic device 100 according to an embodiment of the present invention.

[0064] The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: the application layer, the application framework layer, the Android runtime (Android runtime) and the system library, and the kernel layer.

[0065] The application layer can include a series of application packages.

[0066] like Figure 3 As shown, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.

[0067] Among them, the above-mentioned camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications can all be regarded as the first application in the embodiments of the present application.

[0068] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.

[0069] like Figure 3 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.

[0070] Android runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.

[0071] The core library includes two parts: one part is the functional functions that need to be called by the Java language (also referred to as functions or methods in the embodiments of the present application), and the other part is the core library of Android.

[0072] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0073] The system library may include multiple functional modules. For example: a verification module, a modification module, a compilation module, and a synthesis module. Among them, the verification module is used to determine the first TS code and the second TS code in each TS code included in the first file. The modification module is used to modify the first TS code in the first file. The compilation module is used to compile the second TS code and the modified first TS code into corresponding machine code. The synthesis module generates a second file based on the machine code output by the compilation module. When the electronic device starts the application corresponding to the code file, the second file can be directly called, which can improve the startup efficiency of the application.

[0074] The following is an explanation of the method for compiling an application program provided in the embodiment of the present application. Figure 4 , the method comprises steps S401-S404:

[0075] S401: Obtain a first file, where the first file includes at least one TS code corresponding to a first application.

[0076] The content of a first file exemplified in this application is as follows:

[0077] 1leta:numer=1;

[0078] 2fun1:number{returna+1};

[0079] 3fun2{returna*1};

[0080] 4Let b:boolean = a + fun1();

[0081] 5Letc=a+fun2();

[0082] The first file includes five lines of TS code. Each line of TS code can be regarded as a sentence of TS code. In the first line (or the first sentence) of TS code, a is represented as a variable, numer (number) is the data type of variable a, and 1 is the specific value assigned to variable a. That is, the first line of TS code represents a=1 and the data type of a is a number.

[0083] In the second line (or second sentence) of TS code, fun1 represents function 1 (or method 1). For example, fun1 can represent function 1 (or method 1) xa=1. a+1 represents the step for solving function 1 (or method 1). number{returna+1} represents returning the calculation result of a+1, and the data type of the calculation result is defined as numer (number).

[0084] In the third line (or the third sentence) of TS code, fun2 represents function 2 (or method 2). For example, fun2 can represent function 2 (or method 1) x / a=1. a*1 represents the steps used to solve function 2 (or method 2). {returna*1} represents returning the calculation result of a*1. Since fun2{returna*1} does not include a data type, the calculation result of a*1 returned is not labeled with a data type.

[0085] In the fourth line (or fourth sentence) of TS code, fun1() represents the calculation result based on fun1:number{returna+1}. Combined with Letb:boolean=a+fun1(), we know that b=a+a+1. And since a=1, we can get b=3. And the data type of b is boolean (Boolean value).

[0086] In the fifth line (or fifth sentence) of TS code, fun2() represents the calculation result based on fun2{returna*1}, which is not marked with a data type. Combined with Letc=a+fun2(), we can see that c=a+a*1. And since a=1, we can get c=2. Since fun2{returna*1} and Letc=a+fun2() are not marked with data types, the obtained c is also not marked with a data type.

[0087] The above embodiment exemplarily gives the data type of number (digit) class and the data type of boolean (Boolean value). In fact, the data type may also include string (string), BigInt (big number), any (any), etc., which is not limited in the embodiment of the present application.

[0088] S402: Determine the first TS code among the TS codes.

[0089] The first TS code includes a TS code in the first file that is not marked with a data type, and / or the first TS code includes a TS code in the first file that is marked with an incorrect data type.

[0090] In some embodiments, the TS code without marking the data type may be shown as fun2{returna*1}. Function 2 (or method 2) only defines the steps for solving function 2 (or method 2), but does not mark the data type of the obtained calculation result. Therefore, the data type of the obtained calculation result cannot be determined. The data type of the obtained calculation result may be number, boolean, any, etc.

[0091] In some embodiments, the TS code of the data type error marked may be shown as leta:boolean=137.5. Since a boolean (Boolean value) can only be 1 (representing yes) or 0 (representing no), and cannot be a number or array with a decimal point. Therefore, the data type marked for a in leta:boolean=137.5 is wrong.

[0092] In some embodiments, the TS code with the wrong data type marked may also be shown as the fourth line of code Letb:boolean=a+fun1() in the TS code included in the first file in the above example. Among them, the data type of a in the first line of code leta:numer=1 is numer (number), and the data type of the calculation result obtained based on the second line of code fun1:number{returna+1} is also numer (number). Since the fourth line of code Letb:boolean=a+fun1() can only calculate the result based on the first line of code leta:numer=1 and the second line of code fun1:number{returna+1}. Therefore, the data type of the calculation result of the fourth line of code Letb:boolean=a+fun1() should also be numer (number). However, in the fourth line of code Letb:boolean=a+fun1(), the data type of the calculation result is defined as boolean (Boolean value). Therefore, the data type marked in the fourth line of code is wrong.

[0093] In an embodiment of the present application, in order to improve the speed of the TS code included in the first file at runtime, AOT processing can be performed on the TS code included in the first file in advance. However, since the TS code that performs AOT processing needs to be annotated with the correct data type. Therefore, before performing AOT processing on each sentence of TS code included in the first file or when performing AOT processing on each sentence of TS code included in the first file, it can be determined whether each sentence of TS code included in the first file is annotated with a data type and whether the annotated data type is correct.

[0094] In some embodiments, the first file may further include a second TS code. The second TS code is a TS code in the first file marked with a correct data type.

[0095] In some embodiments, since TS codes without data types marked cannot be processed by AOT, it is possible to identify and / or deduce whether each TS code included in the first file is marked with a data type or whether the marked data type is correct based on the IR layer in the AOT compiler.

[0096] Each TS code includes assignment code and function (or method) code. For example, leta:numer=1 in the first file example is an assignment code; or, Letb:boolean=a+fun1() is also an assignment code. fun1:number{returna+1} in the first file example is a function (or method) code; or, fun2{returna*1} is also a function (or method) code.

[0097] The IR layer in the AOT compiler can identify whether the assignment code and function (or method) code are annotated with data types. However, the IR layer in the AOT compiler can only deduce the data type of the assignment code, but cannot deduce the data type of the function (or method) code.

[0098] Still taking the TS code included in the first file as the code shown in the above example as an example, when the AOT compiler performs AOT processing on the TS code included in the first file, an intermediate representation of each TS code can be obtained. The intermediate representation of the TS code can be used to characterize the data type of the TS code.

[0099] Exemplarily, the intermediate representation of each TS code included in the first file can be as follows Figure 5 shown.

[0100] The first intermediate representation is the intermediate representation of fun1:number{returna+1} (also referred to as 1-IR(typenumber) in the embodiment of the present application). The IR layer of the AOT compiler can deduce that the data type marked in the TS code is number.

[0101] The second intermediate representation is the intermediate representation of leta:numer=1 (also referred to as 2-IR (typenumber) in the embodiment of the present application). The IR layer of the AOT compiler can deduce that the data type marked in the TS code is number.

[0102] The third intermediate representation is the intermediate representation of fun2{returna*1} (it may also be referred to as 3-IR (type any) in the embodiment of the present application). Since the data type is not marked in fun2{returna*1}, the IR layer of the AOT compiler cannot recognize the data type marked in fun2{returna*1}. And since fun2 represents a function (or method), the IR layer of the AOT compiler cannot deduce the data type that should be marked in fun2{returna*1}. The data type that should be marked in fun2{returna*1} can be recorded as a preset type, such as any.

[0103] The fourth intermediate representation is the intermediate representation of Letb:boolean=a+fun1() (it may also be referred to as 4-IR(typeany) in the embodiment of the present application). Since the data types marked in a and fun1:number{returna+1} are known and consistent (both are number), the IR layer of the AOT compiler can deduce that the data type marked in this sentence of TS code is number. However, since the IR layer of the AOT compiler recognizes that the data type marked in Letb:boolean=a+fun1() is boolean, it is inconsistent with the derived data type number. Therefore, the data type marked in Letb:boolean=a+fun1() can be recorded as a preset type, such as any.

[0104] The fifth intermediate representation is the intermediate representation of Letc=a+fun2() (it may also be referred to as 5-IR(typeany) in the embodiment of the present application). The IR layer of the AOT compiler cannot recognize the data type marked in Letc=a+fun2(). Moreover, since fun2{return a*1} is not marked with a data type. Therefore, even if the data type marked in leta:numer=1 is known, the IR layer of the AOT compiler cannot deduce the data type that should be marked in Letc=a+fun2(). Therefore, the data type that should be marked in fun2{returna*1} can be recorded as a preset type, such as any.

[0105] In some embodiments, a TS code marked as a preset type (eg, any type) may be determined as a first TS code, and the remaining TS codes may be determined as a second TS code.

[0106] In some embodiments, since the second TS codes are all marked with data types and the marked data types are correct, the second TS codes can be AOT processed. Since the first TS codes are not marked with data types or the data types marked with the TS codes are wrong, the first TS codes cannot be AOT processed. Before performing AOT processing on the first TS codes, the following step S403 needs to be performed to mark the correct data type for the first TS codes.

[0107] S403: Modify the first TS code in the first file to obtain a modified first file.

[0108] Modifying the first TS code in the first file includes marking a correct data type for the first TS code in the first file.

[0109] For example, see Figure 5Based on the third intermediate representation 3-IR (typeany), the fourth intermediate representation 4-IR (type any) and the fifth intermediate representation 5-IR (typeany), it can be seen that the third line of code fun2 {return a*1}, the fourth line of code Letb: boolean = a + fun1() and the fifth line of code Letc = a + fun2() included in the first file are not marked with the correct data type. That is, the third line of code fun2 {return a*1}, the fourth line of code Letb: boolean = a + fun1() and the fifth line of code Letc = a + fun2() are all first TS codes.

[0110] The third line of code fun2{returna*1} can be modified to fun2:number{returna*1}. The fourth line of code Letb:boolean=a+fun1() can be modified to Letb:number=a+fun1(). The fifth line of code Letc=a+fun2() can be modified to Letc:numer=a+fun2(). After modification, the first file includes the following content:

[0111] 1leta:numer=1;

[0112] 2fun1:number{returna+1};

[0113] 3fun2:number{returna*1};

[0114] 4Let b:number = a + fun1();

[0115] 5Let c:numer=a+fun2();

[0116] Each line of TS code is annotated with the correct data type, so each line of TS code can be processed by AOT.

[0117] In some embodiments, although the first TS codes are not annotated with data types or the first TS codes are annotated with wrong data types, when some first TS codes (also referred to as third TS codes in the embodiments of the present application) are annotated with correct data types, other first TS codes may be affected so that the correct data types can be deduced by the AOT editor.

[0118] Exemplarily, the modified first file includes the following content:

[0119] 1leta:numer=1;

[0120] 2fun1:number{returna+1};

[0121] 3fun2:number{returna*1};

[0122] 4Let b = a + fun1();

[0123] 5Letc=a+fun2();

[0124] Among them, the first line of TS code to the third line of TS code are all marked with the correct data type. Although the fourth line of TS code and the fifth line of TS code are not marked with data types, the correct data types can be derived based on the first line of TS code to the third line of TS code. Therefore, each line of TS code in the modified first file can be processed by AOT.

[0125] Therefore, in order to reduce the number of modifications and improve the modification efficiency, an abstract syntax tree can be generated based on the execution order of each TS code; each TS code is located at a different node of the syntax tree. Among them, the abstract syntax tree is used to represent the logical relationship (also known as structural relationship) of each TS code in the first file. The abstract syntax tree includes multiple nodes, each node is used to represent a TS code in the first file. In the abstract syntax tree, the above-mentioned third TS code can be determined.

[0126] In some embodiments, a syntax parser can be used to parse each TS code in the first file to generate an abstract syntax tree (AST). The syntax parser can be any one of the following: @babel / parser parser, uglify□js parser, Esprima parser, acorn parser, espree parser, TypeScript parser, sucrase parser, swc parser, ASTExplorer parser or jscodeshift parser. This embodiment of the present application is not limited.

[0127] See also Figure 6, still taking the TS code included in the first file as the code shown in the above example as an example. Since the first line of code leta:numer=1 is a TS code for defining the variable a. The second line of code fun1:number{returna+1} and the third line of code fun2{returna*1} are both TS codes for defining functions (or methods). The fourth line of code Letb=a+fun1() and the fifth line of code Letc=a+fun2() are TS codes for obtaining calculation results based on the variables, functions (or methods) defined above. Therefore, the first line of code leta:numer=1, the second line of code fun1:number{returna+1} and the third line of code fun2{returna*1} are all located at the topmost layer (also referred to as the first layer) of the abstract syntax tree. The fourth line of code Letb=a+fun1() and the fifth line of code Letc=a+fun2() are both located at the next layer (also referred to as the second layer) of the first layer of the abstract syntax tree.

[0128] It is understandable that if there are more TS lines such as the sixth line of code and the seventh line of code in the above example. And the calculation results can be obtained based on the fourth line of code Letb=a+fun1() and / or the fifth line of code Letc=a+fun2(). Then, the sixth line of code, the seventh line of code and other more TS lines will also exist in the lower layer of the location where the fourth line of code Letb=a+fun1() and / or the fifth line of code Letc=a+fun2() are located. This is not limited by the embodiments of the present application.

[0129] Among them, if the location of each line of code is regarded as a node. Since the fourth line of code Letb:boolean=a+fun1() can only calculate the result based on the first line of code leta:numer=1 and the second line of code fun1:number{returna+1}. Therefore, the first line of code leta:numer=1 and the second line of code fun1:number{returna+1} are both the parent nodes of the fourth line of code Letb:boolean=a+fun1(). In other words, the fourth line of code Letb:boolean=a+fun1() is the child node of the first line of code leta:numer=1 and the second line of code fun1:number{returna+1}.

[0130] Since the fifth line of code Letc=a+fun2() can only calculate the result based on the first line of code leta:numer=1 and the third line of code fun2{return a*1}. Therefore, the first line of code leta:numer=1 and the third line of code fun2{return a*1} are the parent nodes of the fifth line of code Letc=a+fun2(). It can also be said that the fifth line of code Letc=a+fun2() is the child node of the first line of code leta:numer=1 and the third line of code fun2{return a*1}.

[0131] It can be understood that if there are more lines of TS code such as the sixth line of code and the seventh line of code in the above example. And the calculation results of more lines of TS code such as the sixth line of code and the seventh line of code can be obtained based on the fourth line of code Letb=a+fun1() and / or the fifth line of code Letc=a+fun2(). Then, the fourth line of code Letb=a+fun1() and / or the fifth line of code Letc=a+fun2() can be the parent node of the sixth line of code, the seventh line of code and more lines of TS code. It can also be said that the sixth line of code, the seventh line of code and more lines of TS code are child nodes of the fourth line of code Letb=a+fun1() and / or the fifth line of code Let c=a+fun2(). This embodiment of the present application is not limited.

[0132] Based on the above examples, it can be seen that the node corresponding to each TS code in the abstract syntax tree can only exist as the parent node of other nodes (for example, the first line of code leta:numer=1, the second line of code fun1:number{returna+1} and the third line of code fun2{returna*1} in the above example), and the node corresponding to the TS code can be the common parent node of multiple child nodes (for example, the first line of code leta:numer=1 in the above example).

[0133] Alternatively, the nodes corresponding to each TS code in the abstract syntax tree can exist only as child nodes of other nodes (for example, the fourth line of code Letb: boolean = a + fun1() and the fifth line of code Letc = a + fun2() in the above example, and the node where the TS code is located can have multiple parent nodes at the same time.

[0134] Alternatively, the nodes corresponding to each TS code in the abstract syntax tree can exist both as parent nodes of other nodes and as child nodes of other nodes. For example, the above example describes that there are more lines of TS code such as the sixth line of code, the seventh line of code, etc. And the sixth line of code, the seventh line of code, and more lines of TS code can obtain the calculation results based on the fourth line of code Letb=a+fun1() and / or the fifth line of code Letc=a+fun2(). Then the fourth line of code Letb:boolean=a+fun1() and the fifth line of code Letc=a+fun2() can exist both as parent nodes and as child nodes.

[0135] In some embodiments, the node where the third TS code is located is the first node, and the first node is a node that meets a preset condition.

[0136] In some embodiments, the preset condition includes that the number of child nodes corresponding to the first node is greater than or equal to a preset number.

[0137] For example, see Figure 6 Among them, the third line of code fun2{returna*1}, the fourth line of code Letb:boolean=a+fun1() and the fifth line of code Letc=a+fun2() are all the first TS codes.

[0138] If the preset number is 1. Among them, the third line of code fun2{return a*1} corresponds to 1 child node. The fourth line of code Letb:boolean=a+fun1() corresponds to 0 child nodes. The fifth line of code Letc=a+fun2() corresponds to 0 child nodes. Therefore, the node where the third line of code fun2{return a*1} is located can be the first node. The third line of code fun2{return a*1} is the third TS code.

[0139] In some embodiments, the preset condition includes that the first node corresponds to the largest number of child nodes.

[0140] For example, see Figure 6 . Since the third line of code fun2{returna*1} corresponds to 1 child node. The fourth line of code Letb:boolean=a+fun1() corresponds to 0 child nodes. The fifth line of code Letc=a+fun2() corresponds to 0 child nodes. Therefore, the node where the third line of code fun2{returna*1} is located can be the first node. The third line of code fun2{returna*1} is the third TS code.

[0141] In some embodiments, the preset condition includes that the first node does not have a parent node. Figure 6. Among them, the third line of code fun2{returna*1}, the fourth line of code Letb:boolean=a+fun1() and the fifth line of code Letc=a+fun2() are all the first TS codes. Since the node where the third line of code fun2{returna*1} is located does not have a parent node, the node where the fourth line of code Letb:boolean=a+fun1() is located and the node where the fifth line of code Letc=a+fun2() is located both have at least one parent node. Therefore, the node where the third line of code fun2{returna*1} is located can be determined as the first node. The third line of code fun2{returna*1} can be determined as the third TS code.

[0142] It is understandable that the modification of the first TS code in this step can be completed by the electronic device itself, or an interface for prompting the user that the first TS code is not annotated with the correct data type can be displayed after the first TS code is determined. The user can input a modification operation for the first TS code to the electronic device, and the electronic device modifies the first TS code in response to the user's modification operation. The embodiment of the present application does not limit the method of modifying the first TS code.

[0143] S404: Compile the modified first file to generate a second file.

[0144] In some embodiments, performing a compilation process on the modified first file includes compiling the TS code in the modified first file into a machine code.

[0145] Among them, since the second TS code in the first file is marked with the correct data type, AOT processing can be performed on the second TS code based on the AOT compiler to compile the second TS code into the first machine code. When the first application is started, the first machine code can be directly called to improve the operating efficiency of the TS code included in the first file.

[0146] Since the modified first TS code in the first file is annotated with the correct data type, the modified first TS code can be AOT processed based on the AOT compiler to compile the first TS code into the second machine code. When the first application is started, the second machine code can be directly called to improve the running efficiency of the TS code included in the first file.

[0147] In some embodiments, the first machine code and the second machine code may be merged to generate a second file. The second file includes the first machine code and the second machine code arranged in an execution order.

[0148] In some embodiments, a correspondence between the second file and the first application can be established, and the second file can be stored in the internal memory of the electronic device. When the first application is started, the second file can be directly obtained, and the first machine code and the second machine code included in the second file can be executed. When the first application is started, the execution of the first machine code and the second machine code included in the second file greatly improves the startup speed of the first application compared with first compiling the TS code in the first file corresponding to the first application into machine code and then running the machine code.

[0149] In some embodiments, the second file may further include a fourth TS code. The fourth TS code is the unmodified first TS code.

[0150] For example, see Figure 6 . Among them, the third line of code fun2{returna*1}, the fourth line of code Letb:boolean=a+fun1() and the fifth line of code Letc=a+fun2() are all the first TS codes. If only the third line of code fun2{returna*1} is modified (marked with the correct data type, for example, modified to fun2:number{returna*1}), the fourth line of code Letb:boolean=a+fun1() and the fifth line of code Letc=a+fun2() are not modified (marked with the correct data type). Since the fifth line of code Letc=a+fun2() is obtained based on the first line of code leta:number=1 and the modified third line of code fun2:number{returna*1}. The first line of code leta:number=1 and the modified third line of code fun2:number{returna*1} are both marked with the correct data type (both are number), therefore, the data type of the fifth line of code Letc=a+fun2() can be deduced, which is also number. The fifth line of code Letc=a+fun2() can also be deduced and annotated with the correct data type as the third line of code fun2{returna*1} is modified. Afterwards, the fifth line of code Letc=a+fun2() can also be AOT processed based on the AOT compiler and compiled into the corresponding second machine code.

[0151] Since the fourth line of code Letb:boolean=a+fun1() is not modified, the fourth line of code Letb:boolean=a+fun1() can be determined as the fourth TS code.

[0152] The second file can be obtained based on the first machine code, the second machine code and the fourth TS code. When the first application is started, the content included in the second file can be directly executed. Wherein, when executing the content included in the second file, it can be determined in real time during the execution process whether the machine code or the TS code to be executed is a machine code. If the machine code to be executed is (for example, the first machine code or the second machine code), it can be executed directly. If the TS code to be executed is (for example: the fourth TS code), the TS code can be executed based on methods such as interpreted execution.

[0153] In some embodiments, after the first TS code is modified in the above step S403, step S402 may be performed again to determine whether the modified first TS code is marked with the correct data type. If the correct data type is marked, the modified first TS code is determined as the second TS code. If the correct data type is not marked, the modified first TS code continues to be determined as the first TS code.

[0154] The modified first TS code that is re-determined as the first TS code may repeatedly execute the above step S403 until the modified first TS code is determined as the second TS code.

[0155] In some schemes, multiple embodiments of the present application can be combined, and the combined scheme can be implemented. Optionally, some operations in the process of each method embodiment are optionally combined, and / or the order of some operations is optionally changed. In addition, the execution order between the steps of each process is only exemplary and does not constitute a restriction on the execution order between the steps. There can also be other execution orders between the steps. It is not intended to indicate that the execution order is the only order in which these operations can be performed. A person of ordinary skill in the art will think of a variety of ways to reorder the operations described herein. In addition, it should be noted that the process details involved in a certain embodiment of this article are also applicable to other embodiments in a similar manner, or different embodiments can be used in combination.

[0156] In addition, some steps in the method embodiment may be equivalently replaced by other possible steps. Alternatively, some steps in the method embodiment may be optional and may be deleted in certain usage scenarios. Alternatively, other possible steps may be added to the method embodiment.

[0157] Furthermore, the various method embodiments may be implemented separately or in combination.

[0158] It is understandable that in order to implement the above functions, the electronic device includes hardware and / or software modules corresponding to the execution of each function. In combination with the algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in combination with the embodiments, but such implementation should not be considered to be beyond the scope of the present application.

[0159] In this embodiment, the electronic device can be divided into functional modules according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware. It should be noted that the division of modules in this embodiment is schematic and is only a logical function division. There may be other division methods in actual implementation.

[0160] Exemplarily, the present application embodiment also provides a device for compiling an application program. Figure 7 , the compilation device 700 includes: a verification module 701, a modification module 702, a compilation module 703 and a synthesis module 704. Among them, the verification module 701 is used to determine the first TS code and the second TS code in each TS code included in the first file. The modification module 702 is used to modify the first TS code. The compilation module 703 is used to compile the second TS code and the modified first TS code into corresponding machine codes. The synthesis module 704 generates a second file based on the machine code output by the compilation module 703.

[0161] Combination Figure 7 The compilation device shown is shown in Figure 8 . Various applications are installed in the electronic device, such as application 801, application 802, application 803, and application 804. The compiling device provided in the embodiment of the present application can compile the TS code included in the code file corresponding to each application into the corresponding machine code before each application is run. Afterwards, when the electronic device runs the application, the machine code corresponding to the application can be directly called, which can improve the running efficiency of the application.

[0162] Take the embodiment of the present application to compile the TS code included in the code file corresponding to the application 801 into the corresponding machine code as an example. After the verification module 701 obtains the code file corresponding to the application 801, it can verify whether the TS code included in the code file is marked with the correct data type. If the TS code is marked with the correct data type, the TS code is determined as the second TS code. If the TS code is not marked with the correct data type, the TS code is determined as the first TS code. Afterwards, the modification module 702 can modify the first TS code to mark the data type in the first TS code.

[0163] In an example, after the modification module 702 outputs the modified first TS code, the compilation module 703 can directly compile the second TS code and the modified first TS code into corresponding machine codes.

[0164] In another example, after the modification module 702 outputs the modified first TS code, the verification module 701 may also Figure 8 The modified first TS code is checked to see whether it is marked with the correct data type. If it is satisfied, the modified first TS code is determined as the second TS code. If not, the modified first TS code is continued to be determined as the first TS code. The step of modifying the first TS code by the modification module 702 is repeated.

[0165] In this example, the compilation module 703 is as follows Figure 8 As shown, the second TS code can be compiled into corresponding machine code.

[0166] In some embodiments, the synthesis module 704 may obtain a synthesis file based on the machine code compiled by the compilation module 703 .

[0167] The present application also provides an electronic device, such as Fig. 9 As shown, the electronic device may include one or more processors 901 , a memory 902 and a communication interface 903 .

[0168] The memory 902 and the communication interface 903 are coupled to the processor 901. For example, the memory 902, the communication interface 903 and the processor 901 may be coupled together via a bus 904.

[0169] The communication interface 903 is used for data transmission with other devices. The memory 902 stores computer program code. The computer program code includes computer instructions. When the computer instructions are executed by the processor 901, the electronic device executes the method for compiling the application program in the embodiment of the present application.

[0170] Among them, the processor 901 can be a processor or a controller, for example, it can be a central processing unit (CPU), a general processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It can implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the contents of this disclosure. The processor can also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of DSP and microprocessors, and so on. The processor can be used to support electronic devices to execute the method steps provided in the above embodiments. For example, the processor can be used to support electronic devices to execute Figure 4 S401-S404 in.

[0171] The bus 904 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus 904 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig. 9 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0172] An embodiment of the present application also provides a chip system, including: a processor, the processor is coupled to a memory, the memory is used to store programs or instructions, when the program or instructions are executed by the processor, the chip system implements the method in any of the above method embodiments.

[0173] Optionally, the processor in the chip system may be one or more. The processor may be implemented by hardware or by software. When implemented by hardware, the processor may be a logic circuit, an integrated circuit, etc. When implemented by software, the processor may be a general-purpose processor implemented by reading software code stored in a memory.

[0174] Optionally, the memory in the chip system may also be one or more. The memory may be integrated with the processor or may be separately arranged with the processor, which is not limited in the embodiments of the present application. Exemplarily, the memory may be a non-transient processor, such as a read-only memory ROM, which may be integrated with the processor on the same chip or may be arranged on different chips respectively. The embodiments of the present application do not specifically limit the type of memory and the arrangement of the memory and the processor.

[0175] Exemplarily, the chip system can be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), a central processor unit (CPU), a network processor (NP), a digital signal processing circuit (DSP), a microcontroller unit (MCU), a programmable logic device (PLD) or other integrated chips.

[0176] It should be understood that each step in the above method embodiment can be completed by an integrated logic circuit of hardware in a processor or by instructions in the form of software. The method steps disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware processor, or by a combination of hardware and software modules in a processor.

[0177] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program code is stored. When the processor executes the computer program code, the electronic device executes the relevant method steps in the method embodiment.

[0178] The embodiment of the present application also provides a computer program product. When the computer program product is run on a computer, it enables the computer to execute the relevant method steps in the above method embodiment.

[0179] In addition, an embodiment of the present application further provides a device. The device may be a component or a module, and the device may include one or more processors and a memory connected to each other. The memory is used to store a computer program. When the computer program is executed by one or more processors, the device performs the scene configuration method in the above-mentioned method embodiments.

[0180] Among them, the device, computer-readable storage medium, computer program product or chip provided in the embodiments of the present application are used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.

[0181] The steps of the method or algorithm described in conjunction with the disclosed content of the embodiments of the present application can be implemented in hardware or by executing software instructions by a processor. The software instructions can be composed of corresponding software modules, and the software modules can be stored in random access memory (RAM), flash memory, read-only memory (ROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, mobile hard disks, read-only compact disks (CD-ROMs) or any other form of storage medium known in the art. An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC).

[0182] Through the description of the above implementation methods, those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above functional modules is used as an example. In practical applications, the above functions can be assigned to different functional modules as needed; that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0183] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

Claims

1. A method for compiling an application, characterized in that: include: Obtain a first file, wherein the first file includes at least one TS code corresponding to the first application; Determining a first TS code that is not marked with a correct data type in the at least one TS code; Modify the first TS code in the first file to obtain the modified first file; The modified first file includes TS codes marked with correct data types; Compile the modified first file to generate a second file; the second file includes machine code corresponding to the TS code in the modified first file.

2. The method according to claim 1, characterized in that The step of modifying the first TS code in the first file to obtain the modified first file includes: Based on the execution order of each TS code in the first file, an abstract syntax tree is generated; the abstract syntax tree is used to represent the logical relationship between the TS codes in the first file, and the abstract syntax tree includes a plurality of nodes, each of which is used to represent a sentence of TS code in the first file; Modify the first TS code represented by the first node; the first node is a node in the abstract syntax tree that meets a preset condition.

3. The method according to claim 2, characterized in that The preset condition includes that the number of child nodes corresponding to the first node is greater than or equal to a preset number.

4. The method according to claim 2, characterized in that: The preset condition includes that the first node corresponds to the largest number of child nodes.

5. The method according to claim 2, characterized in that: The preset condition includes that the first node has no parent node.

6. The method according to any one of claims 1 to 5, characterized in that: After determining the first TS code that is not marked with a correct data type in the at least one TS code, the method further includes: Prompting the user to modify the first TS code; The step of modifying the first TS code in the first file to obtain the modified first file further includes: receiving a modification operation input by a user for the first TS code; In response to the modification operation, the first TS code is modified in the first file to obtain the modified first file.

7. The method according to any one of claims 1 to 6, characterized in that: The first TS code includes a TS code in the first file that is not marked with a data type.

8. The method according to any one of claims 1 to 7, characterized in that: The first TS code includes a TS code of a data type error marked in the first file.

9. An electronic device, characterized in that: include: A memory and one or more processors; the memory is coupled to the processor; wherein the memory stores computer program code, the computer program code includes computer instructions, and when the computer instructions are executed by the processor, the electronic device executes the method as described in any one of claims 1-8.

10. A computer storage medium comprising computer instructions, characterized in that: When the computer instructions are executed on an electronic device, the electronic device is caused to execute the method as claimed in any one of claims 1 to 8.

11. A computer program product, characterized in that When the computer program product is run on a computer, the computer is caused to execute the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Application program development method, device, equipment and medium

    CN110716715A

  • Code generation method and device, storage medium and server

    CN115145574A

  • Optimistically Assuming Types in a Dynamically Typed Language

    US20150378694A1

  • Electronic device, compiling method and computer-readable recording medium

    US20180203678A1