Application program compiling method, and electronic device
By annotating unlabeled data types in TypeScript code and generating machine code before application startup, the problem of low startup efficiency of TypeScript code is solved and faster application startup speed and efficiency are achieved.
Patent Information
- Application Number
- PCT/CN2024/079724
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-03-15
- Filing Date
- 2024-03-01
- Publication Date
- 2024-09-19
AI Technical Summary
In the existing technology, TypeScript code needs to go through multiple compilation processes when starting an application, resulting in low startup efficiency. In particular, the code without annotated data types causes AOT processing to fail, affecting the startup speed of the application.
Before the application starts, unlabeled data types in the TypeScript code are obtained and marked, an abstract syntax tree is generated, and all codes marked with correct data types are compiled into machine code through AOT compilation processing, and these machine codes are directly called at startup.
Significantly speeds up application startup, improves startup efficiency, reduces the number of modifications, and improves modification efficiency.
Smart Images

Figure CN2024079724_19092024_PF_FP_ABST
Abstract
Description
Application compilation method and electronic device
[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on March 15, 2023, with application number 202310315086.6 and application name “Application Compilation Method and Electronic Device”, all contents of which are incorporated by reference into this application. Technical Field
[0002] 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
[0003] Compared with JavaScript (JS) code, TypeScript (TS) code has added static type function. The static type function of TS code means that data type labels can be added to some or all statements in 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 the electronic device can recognize, and the machine code must be run to start the application. It can be seen that starting the application requires going through multiple processes, and the efficiency of starting the application is low.
[0004] Summary of the Invention
[0005] 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.
[0006] To achieve the above objectives, the present invention adopts the following technical solutions:
[0007] 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 the correct data type in the 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 the TS code marked with the correct data type. Compiling 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.
[0008] 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. Subsequently, the first TS code that is not marked with the correct data type among the TS codes is obtained, and the correct data type is marked for the first TS code. By performing a compilation process 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. This can speed up the startup of the application and improve the startup efficiency of the application.
[0009] In conjunction with the first aspect, in one 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 the TS codes 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 TS code sentence 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.
[0010] In this solution, although the first TS codes in the first file are not labeled with the correct data type. However, when some first TS codes are labeled with the correct data type, it may affect other first TS codes so that the correct data type can be deduced. 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 labeled with the correct data type, thereby reducing the number of modifications and improving modification efficiency.
[0011] 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.
[0012] 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.
[0013] In combination with the first aspect, in one possible design, the preset condition includes that the first node has no parent node.
[0014] In conjunction with the first aspect, in one possible design, after determining that a first TS code is not labeled with a correct data type in at least one TS code sentence, a user may be prompted to modify the first TS code. Subsequently, 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.
[0015] 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 the correct data type label.
[0016] 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.
[0017] In combination with the first aspect, in one possible design, the first TS code includes a TS code indicating a data type error marked in the first file.
[0018] In a second aspect, embodiments of the present application provide an electronic device. The electronic device includes a memory and one or more processors, the memory and the processors being coupled; the memory is configured to store computer program code, the computer program code comprising 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.
[0019] In a third aspect, embodiments of the present application provide a chip system. The chip system includes one or more interface circuits and one or more processors. The interface circuits and processors are interconnected via wiring. The interface circuits are configured to receive signals from a memory of an electronic device and send signals to the processors. The signals include computer instructions stored in the memory. When the processors execute the computer instructions, the electronic device executes the method described in the first aspect and any possible design thereof.
[0020] In a fourth aspect, an embodiment of the present application provides a computer storage medium comprising 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.
[0021] In a fifth aspect, embodiments of the present application provide a computer program product that, when executed on a computer, causes the computer to execute the method described in the first aspect and any possible design thereof. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] FIG1 is a schematic diagram of a method for starting an application program provided in the prior art;
[0023] FIG2 is a hardware structure diagram of an electronic device provided in an embodiment of the present application;
[0024] FIG3 is a software structure block diagram of an electronic device provided in an embodiment of the present application;
[0025] FIG4 is a schematic diagram of a flow chart of a method for compiling an application program according to an embodiment of the present application;
[0026] FIG5 is a schematic diagram of the structure of an intermediate representation of a TS code provided in an embodiment of the present application;
[0027] FIG6 is a schematic diagram of the structure of an abstract syntax tree provided in an embodiment of the present application;
[0028] FIG7 is a schematic diagram of the structure of a compilation device provided in an embodiment of the present application;
[0029] FIG8 is a schematic diagram illustrating an execution method of a compilation method of an application provided in an embodiment of the present application;
[0030] FIG9 is a schematic structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0031] For ease of understanding, some examples of concepts related to the embodiments of this application are provided for reference as follows:
[0032] JS code: A lightweight, interpreted or just-in-time compiled programming language with a function-first approach. It can be used as a scripting language for browser development, but can also be used in non-browser environments.
[0033] TS code: This is built by adding static typing to JavaScript code. TS code can be compiled into JavaScript code using a compiler. The resulting JavaScript code can then be run on browsers and operating systems that support JavaScript code.
[0034] Machine code: Also known as machine language instructions or native code. It is code that electronic devices can directly execute.
[0035] Source code: Original code that has not been executed or compiled.
[0036] 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 called directly later.
[0037] Interpreted execution: Source code is directly input as a source program. During source code execution, the source code is translated into directly executable machine code line by line, running each line as it is translated. Furthermore, the translated, directly executable machine code is not stored in memory and is discarded after use.
[0038] Just-in-time (JIT) compilation: 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.
[0039] Assembly language: A low-level language, also known as a symbolic language, used in electronic devices, microprocessors, microcontrollers, and other programmable devices. In assembly language, mnemonics replace machine code opcodes, and address symbols or labels replace machine code addresses. Different electronic devices use different machine code sets for assembly language, which are 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.
[0040] Bytecode: The file generated after the source code is compiled by the virtual machine compiler.
[0041] A virtual machine is an abstraction layer between the machine and the compiler. It provides a common interface to the compiler on any platform. The compiler simply generates code (bytecode) for the virtual machine, which it can understand. The interpreter then converts the bytecode into machine code for the specific system.
[0042] 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 a compiler front-end, a compiler mid-end, and a 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 an intermediate representation (IR) that is convenient 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-dependent 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.
[0043] The following will describe the technical solutions in the embodiments of the present application 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 way to describe 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,
[0044] "Plurality" means two or more than two.
[0045] In the following, the terms "first" and "second" are used for descriptive purposes only and should not be understood to indicate or imply relative importance or implicitly specify the number of the technical features indicated. Therefore, 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.
[0046] TS code is a superset of JavaScript code and can be obtained by adding static typing to JavaScript. Adding static typing to JavaScript makes it easier to refactor code without significantly breaking it. It also makes the source code of large, complex applications easier to read. Because TS code is based on JavaScript, it can be used anywhere JavaScript can be used.
[0047] In a related technology, when an electronic device launches an application, it can use an interpreted execution method to run the TS code corresponding to the application. Referring to Figure 1, the electronic device can first compile the TS code corresponding to the application into JS code and input it into a virtual machine, which then compiles the JS code into machine code. During interpreted execution, each machine code is interpreted and executed. This results in slow application startup and low efficiency.
[0048] In a related technology, before launching an application, the electronic device can also perform AOT processing on the TS code corresponding to the application to compile the TS code into corresponding machine code and store the machine code in the electronic device's memory. When the electronic device launches the application, it can directly obtain the machine code corresponding to the application and run it.
[0049] However, performing AOT processing on TS code requires knowing the data type of each statement in the TS code. If there are statements with unknown data types in the TS code, AOT processing cannot be performed on the TS code.
[0050] In a related technology, when launching an application, the electronic device can interpret and execute the TS code corresponding to the application in a JS virtual machine (e.g., V8). During the interpretation and execution of the TS code, the JIT can retrieve frequently used hot statements in the TS code. After obtaining the data type and corresponding assembly language of the hot statement, the data type and corresponding assembly language of the hot statement can be stored in the memory of the electronic device.
[0051] 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.
[0052] 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 obtaining the machine code corresponding to the assembly language and executing the machine code during the execution of the assembly language, which will still affect the startup efficiency of the application.
[0053] 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.
[0054] FIG2 shows a schematic structural diagram of the electronic device 100 .
[0055] 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.
[0056] It should be understood that the structure illustrated in the embodiments 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, or may combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0057] The processor 110 may include one or more processing units. For example, the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU). The different processing units may be independent devices or integrated into one or more processors.
[0058] 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.
[0059] Processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 110. If processor 110 needs to use the same instruction or data again, it can directly access the memory. This avoids duplicate accesses, reduces processor 110 latency, and thus improves system efficiency.
[0060] In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit 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.
[0061] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 via the external memory interface 120 to implement data storage functions. For example, files such as music and videos can be stored on the external memory card.
[0062] 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 can 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 can 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.
[0063] 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.
[0064] Exemplarily, the internal memory 121 may also store a second file. The second file includes 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.
[0065] The software system of the electronic device 100 can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture. In the embodiment of the present invention, the Android system with a layered architecture is used as an example to illustrate the software structure of the electronic device 100.
[0066] FIG3 is a block diagram of the software structure of the electronic device 100 according to an embodiment of the present invention.
[0067] A layered architecture divides software into several layers, each with distinct roles and responsibilities. Layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers: the application layer, the application framework layer, the Android runtime and system libraries, and the kernel layer.
[0068] The application layer can include a series of application packages.
[0069] As shown in FIG3 , the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, and short message.
[0070] 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 embodiment of this application.
[0071] The application framework layer provides an application programming interface (API) and programming framework for applications in the application layer. The application framework layer includes some predefined functions.
[0072] As shown in FIG3 , the application framework layer may include a window manager, a content provider, a view system, a telephony manager, a resource manager, a notification manager, and the like.
[0073] The Android runtime includes the core library and the virtual machine. The Android runtime is responsible for scheduling and management of the Android system.
[0074] The core library consists of 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 embodiment of this application), and the other part is the core library of Android.
[0075] The application layer and application framework layer run in a virtual machine. The virtual machine executes Java files in the application layer and application framework layer as binary files. The virtual machine manages object lifecycles, stack management, thread management, security and exception management, and garbage collection.
[0076] 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.
[0077] The following describes a method for compiling an application program provided in an embodiment of the present application. Referring to FIG. 4 , the method includes steps S401 to S404:
[0078] S401: Obtain a first file, where the first file includes at least one TS code corresponding to a first application.
[0079] The content of a first file exemplified in this application is as follows:
[0080] 1 let a:numer=1;
[0081] 2 fun 1:number{return a+1};
[0082] 3 fun 2{return a*1};
[0083] 4 Let b:boolean = a + fun1();
[0084] 5 Let c=a+fun2();
[0085] The first file contains five lines of TS code. Each line of TS code can be considered a sentence of TS code. In the first line (or sentence), a represents a variable, numer 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 indicates that a = 1, and the data type of a is a number.
[0086] In the second line (or sentence) of the TS code, fun1 represents function 1 (or method 1). For example, fun1 can represent function 1 (or method 1) with xa = 1. a + 1 represents the step used to solve function 1 (or method 1). number {return a + 1} indicates that the result of the calculation of a + 1 is returned, and the data type of the calculation result is defined as numer (number).
[0087] In the third line (or sentence) of the TS code, fun2 represents function 2 (or method 2). For example, fun2 could represent function 2 (or method 1) x / a = 1. a*1 represents the steps used to solve function 2 (or method 2). {return a*1} means returning the result of a*1. Because fun2{return a*1} does not include a data type, the returned result of a*1 is also not labeled with a data type.
[0088] In the fourth line (or sentence) of the TS code, fun1() represents the result of the calculation based on fun 1:number{return a+1}. Combining Let b:boolean=a+fun1(), we know that b=a+a+1. Since a=1, we can also get b=3. Furthermore, the data type of b is boolean.
[0089] In the fifth line (or sentence) of the TS code, fun2() represents the calculation result based on fun2{return a*1}, which is not annotated with a data type. Combining Let c = a + fun2(), we know that c = a + a*1. And since a = 1, we can also get c = 2. Since neither fun2{return a*1} nor Let c = a + fun2() has a data type, the resulting c is also unannotated with a data type.
[0090] The above embodiment exemplifies the data types of type number and type boolean. In fact, data types may also include string, BigInt, any, etc., which are not limited in the present embodiment.
[0091] S402: Determine the first TS code among the TS codes.
[0092] 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.
[0093] In some embodiments, TS code without data type annotations may be shown as fun 2{return a*1}. Function 2 (or method 2) only defines the steps for solving function 2 (or method 2) without annotating the data type of the result. Therefore, the data type of the result cannot be determined. The data type of the result can be number, boolean, any, etc.
[0094] In some embodiments, the TS code for an incorrect data type can be represented by the following: let a:boolean=137.5 . Because a Boolean value can only be 1 (representing yes) or 0 (representing no), and cannot be a number or array with a decimal point, the data type of a in let a:boolean=137.5 is incorrect.
[0095] In some embodiments, the TS code marked with an incorrect data type may also be as shown in the fourth line of code Let b: boolean = a + fun1() in the TS code included in the first file in the above example. In the first line of code let a: numer = 1, the data type of a is numer (number), and the data type of the calculation result obtained based on the second line of code fun 1: number {return a + 1} is also numer (number). Since the fourth line of code Let b: boolean = a + fun1() can only calculate the result based on the first line of code let a: numer = 1 and the second line of code fun 1: number {return a + 1}. Therefore, the data type of the calculation result of the fourth line of code Let b: boolean = a + fun1() should also be numer (number). However, in the fourth line of code Let b: 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 incorrect.
[0096] 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 to which the AOT processing is performed needs to be annotated with the correct data type, it is possible to determine 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 before or when the AOT processing is performed on each sentence of TS code included in the first file.
[0097] 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.
[0098] 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.
[0099] Each TS code includes both assignment-type code and function (or method)-type code. For example, let a:numer=1 in the first file example above is assignment-type code; or, Let b:boolean=a+fun1() is also assignment-type code. fun1:number{return a+1} in the first file example above is function (or method)-type code; or, fun2{return a*1} is also function (or method)-type code.
[0100] The IR layer in the AOT compiler can identify whether both assignment-type code and function (or method)-type code are annotated with data types. However, the IR layer in the AOT compiler can only infer the data type of assignment-type code, not the data type of function (or method)-type code.
[0101] 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 represent the data type of the TS code.
[0102] Exemplarily, the intermediate representation of each TS code included in the first file may be as shown in FIG5 .
[0103] The first intermediate representation is the intermediate representation of fun 1:number{return a+1} (also referred to as 1-IR (type number) in the embodiment of the present application). The IR layer of the AOT compiler can infer that the data type annotated in the TS code is number.
[0104] The second intermediate representation is the intermediate representation of let a:numer=1 (also referred to as 2-IR (type number) 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.
[0105] The third intermediate representation is the intermediate representation of fun 2{return a*1} (also referred to as 3-IR (type any) in the embodiment of the present application). Since the data type is not marked in fun 2{return a*1}, the IR layer of the AOT compiler cannot recognize the data type marked in fun 2{return a*1}. And since fun 2 represents a function (or method), the IR layer of the AOT compiler cannot deduce the data type that should be marked in fun 2{return a*1}. The data type that should be marked in fun 2{return a*1} can be recorded as a preset type, such as any.
[0106] The fourth intermediate representation is the intermediate representation of Let b:boolean=a+fun1() (which may also be referred to as 4-IR (type any) in the embodiment of the present application). Since the data types marked in a and fun 1:number{return a+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 Let b:boolean=a+fun1() is boolean, it is inconsistent with the derived data type number. Therefore, the data type marked in Let b:boolean=a+fun1() can be recorded as a preset type, such as any.
[0107] The fifth intermediate representation is the intermediate representation of Let c=a+fun2() (it may also be referred to as 5-IR (type any) in the embodiment of the present application). The IR layer of the AOT compiler cannot recognize the data type annotated in Let c=a+fun2(). Moreover, since fun 2{return a*1} is not annotated with a data type. Therefore, even if the data type annotated in let a:numer=1 is known, the IR layer of the AOT compiler cannot deduce the data type that should be annotated in Let c=a+fun2(). Therefore, the data type that should be annotated in fun 2{return a*1} can be recorded as a preset type, such as any.
[0108] 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.
[0109] In some embodiments, since the second TS codes are all labeled with data types and the labeled data types are correct, the second TS codes can be subjected to AOT processing. Since the first TS codes are not labeled with data types or the labeled data types of the TS codes are incorrect, the first TS codes cannot be subjected to AOT processing. Before performing AOT processing on the first TS codes, the following step S403 needs to be performed to label the first TS codes with the correct data types.
[0110] S403: Modify the first TS code in the first file to obtain a modified first file.
[0111] Modifying the first TS code in the first file includes marking a correct data type for the first TS code in the first file.
[0112] For example, referring to FIG5 , based on the third intermediate representation 3-IR (type any), the fourth intermediate representation 4-IR (type any), and the fifth intermediate representation 5-IR (type any), the third line of code fun 2 {return a*1}, the fourth line of code Let b: boolean = a + fun1(), and the fifth line of code Let c = a + fun2() in the first file are not annotated with the correct data type. In other words, the third line of code fun 2 {return a*1}, the fourth line of code Let b: boolean = a + fun1(), and the fifth line of code Let c = a + fun2() are all first TS codes.
[0113] The third line of code, fun 2 {return a*1}, can be modified to fun 2: number {return a*1}. The fourth line of code, Let b: boolean = a + fun1(), can be modified to Let b: number = a + fun1(). The fifth line of code, Let c = a + fun2(), can be modified to Let c: number = a + fun2(). After the modification, the first file contains the following content:
[0114] 1 let a:numer=1;
[0115] 2 fun 1:number{return a+1};
[0116] 3 fun 2:number{return a*1};
[0117] 4 Let b:number=a+fun1();
[0118] 5 Let c:numer=a+fun2();
[0119] Each line of TS code is annotated with the correct data type, so each line of TS code can be processed AOT.
[0120] In some embodiments, although none of the first TS codes are annotated with data types or the data types annotated with the first TS codes are incorrect, when certain first TS codes (also referred to as third TS codes in the embodiments of the present application) are annotated with correct data types, this may affect other first TS codes, allowing them to be deduced with correct data types by the AOT editor.
[0121] Exemplarily, the modified first file includes the following content:
[0122] 1 let a:numer=1;
[0123] 2 fun 1:number{return a+1};
[0124] 3 fun 2:number{return a*1};
[0125] 4 Let b=a+fun1();
[0126] 5 Let c=a+fun2();
[0127] The first to third lines of TS code are all annotated with the correct data type. Although the fourth and fifth lines of TS code are not annotated with data types, the correct data types can be inferred based on the first to third lines of TS code. Therefore, each line of TS code in the modified first file can be processed AOT.
[0128] Therefore, in order to reduce the number of modifications and improve modification efficiency, an abstract syntax tree can be generated based on the execution order of each TS code; each TS code is located on 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 sentence of TS code in the first file. In this abstract syntax tree, the above-mentioned third TS code can be determined.
[0129] 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 of the following: @babel / parser parser, uglify-js parser, Esprima parser, acorn parser, espree parser, TypeScript parser, sucrase parser, swc parser, AST Explorer parser, or jscodeshift parser. This embodiment of the present application is not limited thereto.
[0130] Referring to Figure 6, the TS code included in the first file is still taken as the code shown in the aforementioned example. Since the first line of code let a:numer=1 is a TS code for defining the variable a. The second line of code fun 1:number{return a+1} and the third line of code fun 2{return a*1} are both TS codes for defining functions (or methods). The fourth line of code Let b=a+fun1() and the fifth line of code Let c=a+fun2() are TS codes for obtaining calculation results based on the variables, functions (or methods) defined above. Therefore, the first line of code let a:numer=1, the second line of code fun 1:number{return a+1} and the third line of code fun 2{return a*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 Let b=a+fun1() and the fifth line of code Let c=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.
[0131] It is understandable 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 sixth line of code, the seventh line of code, and the other lines of TS code can obtain the calculation result based on the fourth line of code Let b = a + fun1() and / or the fifth line of code Let c = a + fun2(). Then, the sixth line of code, the seventh line of code, and the other lines of TS code will also exist in the lower layer of the location where the fourth line of code Let b = a + fun1() and / or the fifth line of code Let c = a + fun2() are located. This embodiment of the present application is not limited.
[0132] Here, if we consider the location of each line of code as a node, since the fourth line of code Let b: boolean = a + fun1() can only calculate the result based on the first line of code let a: numer = 1 and the second line of code fun 1: number {return a + 1}, the first line of code let a: numer = 1 and the second line of code fun 1: number {return a + 1} are both parent nodes of the fourth line of code Let b: boolean = a + fun1(). In other words, the fourth line of code Let b: boolean = a + fun1() is a child node of the first line of code let a: numer = 1 and the second line of code fun 1: number {return a + 1}.
[0133] Since the fifth line of code, Let c = a + fun2(), can only calculate its result based on the first line of code, let a:numer = 1, and the third line of code, fun 2 {return a*1}, the first line of code, let a:numer = 1, and the third line of code, fun 2 {return a*1}, are the parent nodes of the fifth line of code, Let c = a + fun2(). In other words, the fifth line of code, Let c = a + fun2(), is the child node of the first line of code, let a:numer = 1, and the third line of code, fun 2 {return a*1}.
[0134] It is understandable that if there are more lines of TS code such as the sixth line of code, the seventh line of code, etc. in the above example. And the sixth line of code, the seventh line of code, etc. more lines of TS code can obtain the calculation result based on the fourth line of code Let b=a+fun1() and / or the fifth line of code Let c=a+fun2(). Then, the fourth line of code Let b=a+fun1() and / or the fifth line of code Let c=a+fun2() can be the parent node of the sixth line of code, the seventh line of code, etc. more lines of TS code. It can also be said that the sixth line of code, the seventh line of code, etc. more lines of TS code are child nodes of the fourth line of code Let b=a+fun1() and / or the fifth line of code Let c=a+fun2(). This embodiment of the present application is not limited.
[0135] 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 in the above example is let a:numer=1, the second line of code is fun 1:number{return a+1}, and the third line of code is fun 2{return a*1}), 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 in the above example is let a:numer=1).
[0136] 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 Let b: boolean = a + fun1() and the fifth line of code Let c = a + fun2() in the above example, and the node where the TS code is located can have multiple parent nodes at the same time.
[0137] 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, in the above example, 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 Let b=a+fun1() and / or the fifth line of code Let c=a+fun2(). Then the fourth line of code Let b:boolean=a+fun1() and the fifth line of code Let c=a+fun2() can exist both as parent nodes and as child nodes.
[0138] 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.
[0139] 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.
[0140] For example, continue to refer to Figure 6. The third line of code fun 2 {return a*1}, the fourth line of code Let b: boolean = a + fun1 () and the fifth line of code Let c = a + fun2 () are all first TS codes.
[0141] If the preset number is 1, the third line of code, fun 2 {return a*1}, corresponds to 1 child node. The fourth line of code, Let b: boolean = a + fun1(), corresponds to 0 child nodes. The fifth line of code, Let c = a + fun2(), corresponds to 0 child nodes. Therefore, the node where the third line of code, fun 2 {return a*1} resides can be the first node. The third line of code, fun 2 {return a*1}, is the third TS code.
[0142] In some embodiments, the preset condition includes that the first node corresponds to the largest number of child nodes.
[0143] For example, see Figure 6. Since the third line of code, fun 2 {return a*1}, corresponds to one child node, the fourth line of code, Let b: boolean = a + fun1(), corresponds to zero child nodes. The fifth line of code, Let c = a + fun2(), corresponds to zero child nodes. Therefore, the node where the third line of code, fun 2 {return a*1}, resides can be the first node. The third line of code, fun 2 {return a*1}, is the third TS code.
[0144] In some embodiments, the preset condition includes that the first node does not have a parent node. Continue to refer to Figure 6. Among them, the third line of code fun2{return a*1}, the fourth line of code Let b:boolean=a+fun1() and the fifth line of code Let c=a+fun2() are all first TS codes. Since the node where the third line of code fun 2{return a*1} is located does not have a parent node, the node where the fourth line of code Let b:boolean=a+fun1() is located and the node where the fifth line of code Let c=a+fun2() is located both have at least one parent node. Therefore, the node where the third line of code fun 2{return a*1} is located can be determined as the first node. The third line of code fun 2{return a*1} can be determined as the third TS code.
[0145] It is understood 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 marked with the correct data type can be displayed after determining the first TS code. The user can input a modification operation for the first TS code into 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.
[0146] S404: Compile the modified first file to generate a second file.
[0147] In some embodiments, performing a compilation process on the modified first file includes compiling the TS code in the modified first file into machine code.
[0148] Since the second TS code in the first file is annotated 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 running efficiency of the TS code included in the first file.
[0149] Because the modified first TS code in the first file is annotated with the correct data type, AOT processing can be performed on the modified first TS code using an 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.
[0150] 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.
[0151] 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 launched, 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 launched, executing the first machine code and the second machine code included in the second file greatly improves the startup speed of the first application compared to first compiling the TS code in the first file corresponding to the first application into machine code and then running the machine code.
[0152] In some embodiments, the second file may further include a fourth TS code. The fourth TS code is the unmodified first TS code.
[0153] For example, continue to refer to Figure 6. Among them, the third line of code fun 2{return a*1}, the fourth line of code Let b:boolean=a+fun1(), and the fifth line of code Let c=a+fun2() are all first TS codes. If only the third line of code fun 2{return a*1} is modified (marked with the correct data type, for example, modified to fun 2:number{return a*1}), the fourth line of code Let b:boolean=a+fun1() and the fifth line of code Let c=a+fun2() are not modified (marked with the correct data type). Because the fifth line of code Let c=a+fun2() is obtained based on the first line of code let a:number=1 and the modified third line of code fun 2:number{return a*1}. The first line of code, let a:number=1, and the modified third line of code, fun 2:number{return a*1}, are both annotated with the correct data type (both are number). Therefore, the data type of the fifth line of code, Let c=a+fun2(), can be deduced and annotated with the correct data type as the third line of code, fun 2{return a*1}, is modified. The fifth line of code, Let c=a+fun2(), can also be deduced and annotated with the correct data type. Afterwards, the fifth line of code, Let c=a+fun2(), can also be AOT-processed based on the AOT compiler and compiled into the corresponding second machine code.
[0154] Since the fourth line of code Let b: boolean = a + fun1() is not modified, the fourth line of code Let b: boolean = a + fun1() can be determined as the fourth TS code.
[0155] A 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. When the content included in the second file is executed, it can be determined in real time during the execution process whether the machine code or the TS code to be executed is the 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 a method such as interpreted execution.
[0156] In some embodiments, after modifying the first TS code in step S403, step S402 may be performed again to determine whether the modified first TS code is labeled with the correct data type. If so, the modified first TS code is determined as the second TS code. If not, the modified first TS code continues to be determined as the first TS code.
[0157] The modified first TS code that is re-determined as the first TS code may repeatedly execute step S403 until the modified first TS code is determined as the second TS code.
[0158] 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 limitation 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. Ordinary technicians in this field will think of many 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.
[0159] Furthermore, some steps in the method embodiments may be equivalently replaced with other possible steps. Alternatively, some steps in the method embodiments may be optional and may be deleted in certain usage scenarios. Alternatively, other possible steps may be added to the method embodiments.
[0160] Furthermore, the various method embodiments may be implemented separately or in combination.
[0161] 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 this application.
[0162] This embodiment can divide the electronic device into functional modules based on the above-mentioned method example. For example, each functional module can be divided according to its function, or two or more functions can be integrated into a single processing module. The above-mentioned integrated modules can be implemented in the form of hardware. It should be noted that the module division in this embodiment is illustrative and only represents a logical functional division. In actual implementation, other division methods may be used.
[0163] For example, an embodiment of the present application further provides a compilation device for an application. Referring to FIG7 , the compilation device 700 includes: a verification module 701, a modification module 702, a compilation module 703, and a synthesis module 704. The verification module 701 is used to determine the first TS code and the second TS code from among the TS codes 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 code. The synthesis module 704 generates a second file based on the machine code output by the compilation module 703.
[0164] In conjunction with the compilation device shown in Figure 7, see Figure 8. Various applications are installed in the electronic device, such as application 801, application 802, application 803, and application 804. The compilation 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, it can directly call the machine code corresponding to the application, which can improve the operating efficiency of the application.
[0165] Taking the embodiment of the present application as an example, the TS code included in the code file corresponding to the application 801 is compiled into the corresponding machine code. 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 to be the second TS code. If the TS code is not marked with the correct data type, the TS code is determined to be 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.
[0166] 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 code.
[0167] In another example, after the modification module 702 outputs the modified first TS code, the verification module 701 may also verify whether the modified first TS code is annotated with the correct data type, as shown in FIG8 . If so, the modified first TS code is determined as the second TS code. If not, the modified first TS code continues to be determined as the first TS code. The modification module 702 repeats the steps of modifying the first TS code.
[0168] In this example, the compiling module 703 , as shown in FIG8 , can compile the second TS code into corresponding machine code.
[0169] In some embodiments, the synthesis module 704 may obtain a synthesized file based on the machine code compiled by the compilation module 703 .
[0170] An embodiment of the present application further provides an electronic device, as shown in FIG9 , which may include one or more processors 901 , a memory 902 , and a communication interface 903 .
[0171] 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.
[0172] The communication interface 903 is used to transmit data 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 application compilation method in the embodiment of the present application.
[0173] Among them, the processor 901 can be a processor or a controller, for example, a central processing unit (CPU), a general-purpose 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 the various exemplary logic blocks, modules and circuits described in conjunction with the present disclosure. The processor can also be a combination that implements computing functions, for example, a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like. The processor can be used to support the electronic device to execute the method steps provided in the above embodiments. For example, the processor can be used to support the electronic device to execute S401-S404 in Figure 4.
[0174] 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, and the like. For ease of illustration, FIG9 shows only one thick line, but this does not mean that there is only one bus or only one type of bus.
[0175] 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.
[0176] Optionally, there may be one or more processors in the chip system. The processor may be implemented in hardware or software. When implemented in hardware, the processor may be a logic circuit, an integrated circuit, etc. When implemented in software, the processor may be a general-purpose processor implemented by reading software code stored in a memory.
[0177] Optionally, the memory in the chip system may be one or more. The memory may be integrated with the processor or may be provided separately from the processor, which is not limited in the embodiments of the present application. For example, 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 provided on different chips. The embodiments of the present application do not specifically limit the type of memory or the configuration of the memory and the processor.
[0178] Exemplarily, the chip system may 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 processor (DSP), a microcontroller unit (MCU), a programmable logic device (PLD) or other integrated chips.
[0179] It should be understood that each step in the above method embodiment can be completed by hardware integrated logic circuits in a processor or by software instructions. 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.
[0180] An embodiment of the present application further provides a computer-readable storage medium, in which computer program code is stored. When the processor executes the computer program code, the electronic device executes the relevant method steps in the above method embodiment.
[0181] An embodiment of the present application further provides a computer program product, which, when executed on a computer, enables the computer to execute the relevant method steps in the above method embodiment.
[0182] In addition, embodiments of the present application further provide a device. Specifically, the device may be a component or module, and may include one or more processors and a memory connected to each other. The memory is configured to store a computer program. When the computer program is executed by one or more processors, the device performs the scenario configuration method described in each of the above method embodiments.
[0183] The apparatus, computer-readable storage medium, computer program product, or chip provided in the embodiments of the present application are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects of the corresponding methods provided above, and will not be repeated here.
[0184] The steps of the method or algorithm described in conjunction with the disclosure 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, which 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 discs (CD-ROMs), or any other form of storage medium known in the art. An exemplary storage medium is coupled to the 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).
[0185] Through the description of the above embodiments, those skilled in the art will clearly understand that for the sake of convenience and brevity, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed; that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. The specific working processes of the above-mentioned systems, devices, and units can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0186] In the several embodiments provided in this 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 merely schematic. For example, the division of the modules or units is merely a logical function division. In actual implementation, there may be other division methods, 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 program, It is 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, It is 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, It is 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, It is 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, It is 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, It is 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, It is 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, It is 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, It is 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, It is 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, It is 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
Compiling method and compiling device
CN108920149A
Static compiling method and device for TypeScript
CN117032719A
Optimistically Assuming Types in a Dynamically Typed Language
US20150378694A1
Electronic device, compiling method and computer-readable recording medium
US20180203678A1
System for affecting recompilation of source code
US5394550A
