Code compiling method and device, electronic equipment and storage medium
By analyzing and instrumenting the source code of JavaScript or TypeScript languages, identifying and processing resource information, and generating object codes that adapt to the target device, the type checking and resource management problems of dynamic type languages during compilation are solved, and efficient resource management and code adaptation are achieved.
Patent Information
- Application Number
- CN202311851232.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-28
- Publication Date
- 2025-07-01
AI Technical Summary
As a dynamic typed language, the existing JavaScript language cannot perform type checking at compile time, resulting in messy code and difficulty in debugging. Although the TypeScript language introduces static type checking, it cannot meet the resource management needs of developers.
By analyzing the source code using the first programming language, identifying and inserting code elements with object annotations, generating object codes of the second programming language, efficient management of resource information and improving the degree of customization during the compilation process.
It realizes efficient management of resources, improves the degree of customization of resource management during compilation, adapts to different code operation needs, and enhances the applicability of the first programming language.
Smart Images

Figure CN120234004A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and particularly to a code compilation method, apparatus, electronic device, and storage medium. Background Art
[0002] Currently, programming languages can be divided into statically typed languages and dynamically typed languages according to the way of handling variable types. In a statically typed language, the type of a variable is determined at compile time, so relatively complete type checking can be performed at compile time, reducing runtime errors; while in a dynamically typed language, the type of a variable is not determined until the program runs and the variable is assigned a value, and the type of the variable does not need to be declared before use. One of the most well-known programming languages in the front-end field is the JavaScript language. The application scenarios of the JavaScript language can include early website front-end development, as well as current server-side development, command-line tool development, desktop applications, mobile development, plug-in development, etc. The JavaScript language has advantages such as simplicity, security, dynamism, and cross-platformness. However, as a dynamically typed language, the JavaScript language still has some defects, such as inability to merge types, lack of error checking at compile time, messy code in large project development, and difficult debugging.
[0003] To solve these defects, the TypeScript language came into being. The TypeScript language is a superset of the JavaScript language, including all elements of the JavaScript language, can load and run JavaScript code, and extends the syntax of JavaScript, adding concepts such as static types, classes, modules, interfaces, and generics. The TypeScript language can refer to JavaScript language with static types, meaning that the compiled TypeScript language can be used anywhere where the JavaScript language can be used. The definition of types and the introduction of a compiler in the TypeScript language enable the TypeScript language to avoid the defect of inability to merge types in JavaScript and can perform type checking at compile time. However, the current TypeScript language cannot meet the development needs of developers. Summary of the Invention
[0004] Embodiments of this application disclose a code compilation method, apparatus, electronic device, and storage medium, which can improve the degree of customization of resource management during compilation, thereby meeting the needs of developers in terms of resource management.
[0005] Embodiments of this application disclose a code compilation method, the method comprising:
[0006] Analyze the source code in the first programming language to identify one or more code elements in the source code that have target annotations, where the target annotations are used to identify resource information corresponding to the code elements;
[0007] Perform instrumentation operations on each of the code elements according to the target annotations corresponding to each of the code elements;
[0008] Generate target code in the second programming language based on the code obtained after the instrumentation operation.
[0009] An embodiment of the present application discloses a code compilation device, the device includes:
[0010] An identification module, configured to analyze the source code in the first programming language to identify one or more code elements in the source code that have target annotations, where the target annotations are used to identify resource information corresponding to the code elements;
[0011] An instrumentation module, configured to perform instrumentation operations on each of the code elements according to the target annotations corresponding to each of the code elements;
[0012] A generation module, configured to generate target code in the second programming language based on the code obtained after the instrumentation operation.
[0013] An embodiment of the present application discloses an electronic device, including a memory and a processor, where a computer program is stored in the memory, and when the computer program is executed by the processor, the processor implements the method in any one of the embodiments disclosed in the embodiments of the present application.
[0014] An embodiment of the present application discloses a computer-readable storage medium, which stores a computer program, where the computer program causes a computer to execute the method in any one of the embodiments disclosed in the embodiments of the present application.
[0015] Compared with the related art, an embodiment of the present application discloses a code compilation method, device, electronic device and storage medium, which has the following beneficial effects:
[0016] Analyze the source code in the first programming language to identify one or more code elements with target annotations in the source code; perform instrumentation operations on each code element according to the corresponding target annotation of each code element; generate target code in the second programming language based on the code obtained after the instrumentation operation. The first programming language can identify the resource information corresponding to the code elements in the source code through the target annotation, so that the code elements corresponding to the resource information can be identified through the target annotation during the compilation of the source code, and instrumentation operations can be performed on the code elements to process the resource information. Through the first programming language, efficient management of resources can be achieved, the degree of customization of resource management during compilation can be improved, so as to meet the needs of developers in resource management. Moreover, the source code of the first programming language can be compiled into the target code of the second programming language, which can adapt to different code running requirements and improve the applicability of the first programming language. Brief Description of the Drawings
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0018] Figure 1 is a schematic structural diagram of a compiler in an embodiment;
[0019] Figure 2 is a schematic flowchart of a code compilation method in an embodiment;
[0020] Figure 3 is a schematic flowchart of a code compilation method in another embodiment;
[0021] Figure 4 is a schematic structural diagram of a compiler in another embodiment;
[0022] Figure 5 is a schematic flowchart of a code compilation method in another embodiment;
[0023] Figure 6 is a schematic structural diagram of a code compilation device in an embodiment;
[0024] Figure 7 is a schematic structural diagram of an electronic device in an embodiment. Detailed Embodiments
[0025] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts shall fall within the protection scope of the present application.
[0026] It should be noted that the terms "including" and "having" and any variations thereof in the embodiments of the present application and the accompanying drawings are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally further include unlisted steps or units, or may optionally further include other steps or units inherent to these processes, methods, products, or devices.
[0027] In the related art, in order to manage the user interface, a declarative user interface (UI) syntax can be extended on the basis of the TypeScript language to obtain a declarative user interface management programming language. Specifically, the compilation process of the declarative user interface management programming language may be to first compile the source code using this programming language into JavaScript (JS) code, and at the same time translate the decorator syntax and user interface components in the source code into a specific form, and then compile the JavaScript code into a bytecode (abc) file, and optimize the bytecode file and generate machine code, so that the application on the target device can directly run the optimized machine code. However, the declarative user interface management programming language can be adapted to very few operating environments and does not support all the features of the TypeScript language, which affects the usage experience during code operation.
[0028] The embodiments of the present application disclose a code compilation method, device, electronic device, and storage medium, which can improve the degree of customization of resource management during compilation, so as to meet the needs of developers in resource management. The following will be described in detail respectively.
[0029] Please refer to Figure 1 , Figure 1 which is a schematic structural diagram of a compiler in an embodiment. As Figure 1 shown, the compiler may include a compilation front end 10, a stub generator 20, and a compilation back end 30.
[0030] The compiler can be used to convert the source code into target code that can be run on the target device.
[0031] The compiler can run on an electronic device, which may include but is not limited to laptops, palmtop computers, ultra-mobile personal computers (UMPCs), netbooks, personal computers (PCs), servers, etc. Optionally, the compiler can run on the operating system of the electronic device, and the operating system may include but is not limited to Windows, macOS, Linux, etc.
[0032] The execution subject of the code compilation method provided by the embodiments of this application can be the above-mentioned electronic device, or a functional module and / or functional entity in the electronic device that can implement the code compilation method, which can be specifically determined according to actual usage requirements, and the embodiments of this application do not make limitations.
[0033] The electronic device running the compiler is usually the electronic device used by developers to write, test, and compile code. The target device can be a user device. After the developers complete the code development, they can deploy the target code generated by the compiler to the electronic device actually used by the user for the user to use.
[0034] Among them, the target device may include but is not limited to electronic devices such as mobile phones, tablet computers, laptops, palmtop computers, in-vehicle terminal devices, wearable devices, netbooks, or personal digital assistants (PDAs), personal computers (PCs), etc.
[0035] The compilation front end 10 is used to perform lexical analysis and syntactic analysis on the source code. Lexical analysis decomposes the source code into multiple lexical units (tokens), such as keywords, identifiers, operators, etc.; syntactic analysis analyzes and combines multiple lexical units according to certain syntax rules to construct an intermediate representation (Intermediate Representation, IR), and the intermediate representation can be an abstract representation of the source code syntax structure. When processing the source code, the code compiler can improve the accuracy and efficiency of analyzing the source code and generating the target code by processing the intermediate representation. Optionally, the intermediate representation may include but is not limited to abstract syntax trees (ASTs), intermediate code, three-address code, control flow graphs, and static single assignment forms, etc.
[0036] The stub generator 20 is used to perform stubbing operations on the source code. The stubbing operations may include, but are not limited to, inserting a piece of code into the source code or replacing part of the code in the source code.
[0037] The compilation backend 30 is used to perform code optimization and generate target code on the code obtained after the stubbing operation. Code optimization may include constant folding, loop unrolling, function inlining, etc., to improve the execution efficiency of the code. Among them, constant folding may refer to directly replacing some computable constant expressions with the results during compilation; loop unrolling may refer to unrolling loops with a small number of loop body execution times into multiple times to reduce the overhead of loop control; function inlining may refer to expanding the function at the call site to reduce the overhead of function calls. The generation of target code is to convert the optimized code into target code that can be run on the target device, that is, the machine language code of the target device.
[0038] In some embodiments, the electronic device can compile the source code into target code through a compiler. Specifically, the electronic device can analyze the source code in the first programming language through the compilation frontend 10 to identify one or more code elements with target annotations in the source code; the electronic device can perform stubbing operations on each code element through the stub generator 20 according to the target annotations corresponding to each code element; the electronic device can generate target code in the second programming language through the compilation backend 30 according to the code obtained after the stubbing operation.
[0039] Please refer further to Figure 2 , Figure 2 which is a schematic flowchart of a code compilation method in an embodiment; this code compilation method can be applied to the above-mentioned electronic device. As Figure 2 shown, this code compilation method may include the following steps:
[0040] 201. Analyze the source code in the first programming language to identify one or more code elements with target annotations in the source code.
[0041] In some embodiments, the first programming language may be a declarative programming language and is a domain-specific language (DSL) for a specific task. The first programming language may be a DSL for resource management, that is, a DSL for declarative resource management.
[0042] Resource management may refer to the management of resources such as the memory, storage, and network of the electronic device. Further, it may include application resource management, which may be the management of various resources used during the execution of an application program, such as memory resources, storage resources, network resources, etc.
[0043] In some embodiments, the first programming language can provide rich resource description methods, such as tags, decorators, custom scenarios, abstract resource description mechanisms, etc. These resource description methods can also be combined with the resource management classes, event methods, attribute methods, etc. built into the application development framework to jointly form the basis of resource operations.
[0044] Since the core features of declarative programming languages include declarative description and declarative abstraction, declarative programming languages express the goals or expected results of a program through declarative description and hide the specific implementation details of the problem through declarative abstraction. As a declarative programming language for device resource operations, the first programming language provides developers with a concise, efficient, and modular device resource programming method through resource description and resource abstraction, making the program easier to understand, maintain, and expand.
[0045] In some embodiments, the first programming language can implement resource management through scenario description functions and describe resources through abstract resource objects. The scenario description functions included in the first programming language can be functions annotated with target annotations, and the target annotations can endow these scenario description functions with the ability to manage resources. In the scenario description function, there can also be resource variables annotated with target annotations. The resource variables can be used to construct abstract resource objects, and the target annotations can endow the abstract resource objects constructed by the resource variables with the ability to describe resources, thereby realizing the management of resources. Further, the abstract resource object can be used to describe the static attributes and action attributes of resources.
[0046] In some embodiments, the static attributes of resources can include device types, component types in the device, etc. For example, device types can include mobile phones, tablets, or wearable devices, etc.; component types in the device can include camera components, microphone components, positioning components, storage components, etc. in the device. The action attributes of resources can include actions such as turning on, running, and turning off the device, or actions such as turning on, running, and turning off components in the device.
[0047] The first programming language can comprehensively describe resources through scenario description functions and abstract resource objects, covering the characteristics, behaviors of resources, and how to use these resources in different scenarios, enabling developers to more easily manage and manipulate resources, thereby improving development efficiency. In summary, as a declarative device resource operation language, the first programming language can bring many beneficial effects to developers, from improving development efficiency to optimizing application performance, and this programming language will help change the way of device resource management, providing more convenient and efficient solutions for a wide range of scenarios and fields. The first programming language provides resource abstraction and resource description for device resource management, enabling developers to more effectively manage resources such as memory, storage, and network on mobile devices, optimize application performance, and improve the user experience; at the same time, the first programming language allows developers to describe resource operations and management through concise syntax, which can reduce the cognitive burden of developers and improve coding speed and efficiency.
[0048] In some embodiments, the first programming language includes a domain-specific language DSL extended from the TypeScript language. As a DSL for application resource management, the first programming language is extended from the TypeScript language, is a superset of the TypeScript language, inherits all the features of the TypeScript language, and extends the ability of declarative resource management on the basis of the TypeScript language, allowing developers to develop application resources of electronic devices in a more concise and efficient manner.
[0049] Optionally, the first programming language can be called a Resource-awareness Script (RaScript).
[0050] In summary, the first programming language is a superset of the TypeScript language, allowing developers to utilize all the functions of the TypeScript language, while providing dedicated functions for device resource management, making the first programming language highly scalable and flexible, and capable of adapting to different application scenarios and requirements.
[0051] Source code is the code used for developing applications. Developers develop application programs by writing source code, and the source code can describe the logic and behavior of the application program.
[0052] The source code in the first programming language may include one or more code elements with target annotations. The code elements may include, but are not limited to, functions, variables, etc. in the code, such as the scenario description function annotated by the target annotation and the resource variable annotated by the target annotation mentioned above. The target annotation is used to identify the resource information corresponding to the code element and can be used to decorate functions or variables. Optionally, the resource information may include, but is not limited to, resource scenarios and resource descriptions, etc. In some embodiments, the resource scenario may refer to the application scenario of the resource, and the resource description may refer to the static attributes and action attributes of the resources used in the resource scenario.
[0053] For example, assuming the resource scenario is a photo-taking scenario, then the resources used in this resource scenario refer to the resources used to perform the photo-taking operation through the photo-taking application. The resource description may refer to the attributes and actions of the resources used to perform the photo-taking operation through the photo-taking application. For example, the attributes of the resources may refer to which cameras in which electronic devices are controlled, and which cameras in the electronic devices are controlled to take pictures; the actions of the resources may refer to actions such as controlling the camera to start taking pictures and stop taking pictures.
[0054] Identifying the resource information corresponding to the code element through the target annotation enables the code element with the target annotation to be used to describe and manage resources.
[0055] In some embodiments, the electronic device analyzes the source code in the first programming language through a compiler. It can perform lexical analysis and syntactic analysis on the source code in the first programming language, decompose the source code into multiple lexical units, and combine multiple lexical units according to certain syntactic rules to generate an intermediate representation form; traverse and analyze the intermediate representation form to identify one or more code elements with target annotations.
[0056] 202. Perform a stubbing operation on each code element according to the target annotation corresponding to each code element.
[0057] After identifying the target annotation, the electronic device can perform a stubbing operation on each code element marked with the target annotation through the compiler. The stubbing operation may include, but is not limited to, replacing and modifying the code element, etc., so as to process the resource information and improve the customization degree of resource management during the compilation process.
[0058] The stubbing operation may include, but is not limited to, inserting a section of code into the source code or replacing part of the code in the source code.
[0059] In some embodiments, the code elements may include functions or variables. Instrumenting each code element may involve replacing the entire function marked with the target annotation with a function having other resource management functions to change all the resource management functions of the function; alternatively, modifying some of the code in the function marked with the target annotation to change some of the resource management functions in the function; or, modifying the variable marked with the target annotation to a variable with a different resource description, thereby changing the resource description and the resource management functions.
[0060] 203. Generate target code in a second programming language based on the code obtained after the instrumentation operation.
[0061] The code obtained after the instrumentation operation has resource management functions. To adapt to the operating environment of the target device, the code obtained after the instrumentation operation can be converted into target code in a second programming language that the target device can run.
[0062] Assume the target device is a mobile phone. When the user uses the mobile phone, certain functions can be implemented through the applications in the mobile phone. Specifically, the user can trigger the corresponding functions through the virtual buttons in the application user interface. The target device can call application resources by executing the target code in a second programming language, thereby implementing the functions of the application triggered by the user.
[0063] In some embodiments, the second programming language may include multiple programming languages adapted to the operating environment of the target device. Therefore, according to the operating requirements of the target device, the first programming language can be compiled into any programming language that matches the operating requirements of the target device.
[0064] As an alternative implementation, the second programming language may include the TypeScript language or the JavaScript language. The TypeScript language or the JavaScript language can support the operating environment of the target device. The TypeScript language is a superset of the JavaScript language. When the application runs on the target device, it can execute the target code in the TypeScript language or the JavaScript language. The TypeScript language or the JavaScript language has cross-platform characteristics and can run on various operating systems and devices. Therefore, the code compilation method in the embodiments of the present application can convert the declarative extension language of the TypeScript language into the general TypeScript language or the JavaScript language.
[0065] Therefore, the source code of the first programming language can be compiled into target code in the second programming language, which can adapt to different code running requirements and improve the applicability of the first programming language.
[0066] In the embodiments of the present application, the source code in the first programming language is analyzed to identify one or more code elements with target annotations in the source code; according to the target annotations corresponding to each code element, an instrumentation operation is performed on each code element; according to the code obtained after the instrumentation operation, target code in the second programming language is generated. The first programming language can identify the resource information corresponding to the code elements in the source code through the target annotations, so that during the compilation of the source code, the code elements corresponding to the resource information can be identified through the target annotations, and an instrumentation operation is performed on the code elements to process the resource information. Through the first programming language, efficient management of resources can be achieved, the customization degree of resource management during the compilation process is improved, thereby meeting the needs of developers in resource management. Moreover, the source code of the first programming language can be compiled into the target code of the second programming language, which can adapt to different code running requirements and improve the applicability of the first programming language.
[0067] Please further refer to Figure 3 , Figure 3 which is a schematic flowchart of a code compilation method in another embodiment. This code compilation method can be applied to the above-mentioned electronic device, such as Figure 3 shown in the figure. This code compilation method may include the following steps:
[0068] 301. Analyze the source code in the first programming language to generate an abstract syntax tree corresponding to the source code.
[0069] In some embodiments, when the electronic device analyzes the source code in the first programming language through a compiler, it may perform lexical analysis and syntax analysis on the source code in the first programming language, decompose the source code into multiple lexical units, and combine multiple lexical units according to certain syntax rules to generate an abstract syntax tree.
[0070] The electronic device can traverse and analyze the generated abstract syntax tree to identify one or more code elements with target annotations.
[0071] The abstract syntax tree is an abstract representation of the syntax structure of the source code, which shows the syntax structure of the source code in a tree-like form. Each node in the abstract syntax tree represents a syntax structure in the source code, such as expressions (assignment expressions, arithmetic expressions, logical expressions, function calls, etc.), statements (conditional statements, loop statements, declaration statements, return statements, etc.), declarations (variable declarations, function declarations, class declarations), functions (function bodies, parameter lists, function names, etc.), comments, etc. It can be seen that the abstract syntax tree may include nodes for comments to represent the comment content in the code.
[0072] Optionally, the way for the electronic device to traverse and analyze the generated abstract syntax tree through the compiler may include traversing the abstract syntax tree through the visitor pattern to identify one or more code elements with target annotations in the source code. Specifically, traversing the abstract syntax tree through the visitor pattern may be to define a visitor object, define the access methods of each node in the abstract syntax tree through the visitor object, and access and analyze each node by calling the visitor object.
[0073] Therefore, the source code is decomposed into individual nodes through the abstract syntax tree, and each node can represent a different syntactic structure, enabling traversal, access, and analysis of the source code at the node level, improving the efficiency of source code detection and analysis, and allowing for dedicated analysis and processing of code with specific syntactic structures. For example, nodes containing comments can be identified, and one or more code elements with target annotations can be identified from the nodes containing comments, improving the efficiency of identifying one or more code elements with target annotations, and thus improving the efficiency of refactoring, optimizing, or replacing code elements.
[0074] In some embodiments, analyzing the source code in the first programming language to identify one or more code elements with target annotations in the source code includes the following steps: analyzing the source code in the first programming language to generate an abstract syntax tree corresponding to the source code; traversing each node included in the abstract syntax tree and determining whether the annotation variable included in the decorator in each node is the target annotation; if the annotation variable included in the decorator in the first node is the target annotation, determining that the code element corresponding to the first node is the code element with the target annotation, where the first node is any node.
[0075] The code element corresponding to the first node refers to the code element whose abstract syntactic structure is the first node.
[0076] In some embodiments, the target annotation may include a decorator, and the decorator can be used to decorate code elements such as functions or variables. By decorating the code element, the characteristics and behaviors of the code element can be concisely described. At compile time, the compiler can convert the decorator into target code in the second programming language. By using the decorator, the characteristics and behaviors can be added or modified without modifying the code element.
[0077] The decorator may include an annotation variable, and the annotation variable is used to describe the annotation added by the decorator to the code element. Therefore, the electronic device can analyze the decorators of each node in the abstract syntax tree through the compiler and determine whether the annotation variable in the decorator is consistent with the target annotation. If the annotation variable included in the decorator in the first node is the target annotation, it is determined that the code element corresponding to the first node is the code element with the target annotation.
[0078] Such asFigure 4 As shown Figure 4 is a schematic structural diagram of a compiler in another embodiment. As Figure 4 shown, the compiler may include a compilation front end 10, a stub generator 20, and a compilation back end 30.
[0079] The compilation front end 10 can also be used to convert the source code in the first programming language into an un-stubbed abstract syntax tree; the stub generator 20 can be used to perform stubbing operations on the un-stubbed abstract syntax tree to generate a stubbed abstract syntax tree; the compilation back end 30 can generate the target code in the second programming language according to the stubbed abstract syntax tree.
[0080] Optionally, since the first programming language is a superset of the transcript language, the electronic device can convert the source code into an abstract syntax tree through the ts.createSourceFile function provided by the TypeScript compiler (tsc).
[0081] 302. Traverse each node included in the abstract syntax tree.
[0082] 303. Determine whether the annotation variable included in the decorator in each node is the target annotation; if so, execute step 304, if not, execute step 305.
[0083] Among them, the target annotation is used to identify the resource information corresponding to the code element.
[0084] 304. Determine that the code element corresponding to the current node is a code element with the target annotation.
[0085] 305. Determine whether there is a next node; if so, execute step 303; if not, execute step 306.
[0086] In some embodiments, in order to identify one or more code elements with the target annotation in the source code, the source code in the first programming language can be analyzed to generate an abstract syntax tree corresponding to the source code; traverse each node included in the abstract syntax tree, and determine whether the annotation variable included in the decorator in each node is the target annotation; if the annotation variable included in the decorator in the first node is the target annotation, determine that the code element corresponding to the first node is a code element with the target annotation, and the first node is any node.
[0087] 306. Perform a stubbing operation matching the annotation type of the corresponding target annotation on each code element according to the annotation type of the target annotation corresponding to each code element.
[0088] For the code elements marked with different target annotations, the electronic device uses different stubbing operations.
[0089] In some embodiments, the annotation types may include, but are not limited to, scenario annotations, resource annotations, and property annotations. Scenario annotations are used to label the resource scenarios corresponding to code elements, resource annotations are used to label the resource descriptions corresponding to code elements, the resource descriptions may include the attributes of resources, actions of resources, etc., and property annotations may be used to label the attributes of resources. Among them, the descriptions of resource scenarios, the attributes of resources, and the actions of resources may refer to the above embodiments and will not be elaborated herein.
[0090] Exemplarily, the target annotations may be represented as @Scenarios, @Device, @Res, etc. Among them, the scenario annotation may be represented as @Scenarios, the resource annotation may be represented as @Device, and the property annotation may be represented as @Res.
[0091] In some embodiments, the first source code includes a scenario description function corresponding to a resource scenario, and the scenario description function contains one or more abstract resource objects corresponding to the resource scenario, and the abstract resource objects can be used to describe resources.
[0092] The scenario description function may be a function capable of managing the resources in the resource scenario. For example, the scenario description function may include a startRecording() function for starting recording, a takePhoto() function for starting taking pictures, etc.
[0093] Therefore, resource management can be implemented through the scenario description function, and resources can be described through the abstract resource objects.
[0094] In some embodiments, after the target annotation is recognized, the electronic device may perform a stubbing operation on the abstract syntax tree through a compiler to implement functions related to resource management. The stubbing operation may include inserting new nodes into the abstract syntax tree or modifying existing nodes.
[0095] Optionally, since the first programming language is a superset of the Transcript language, the electronic device can modify and optimize the abstract syntax tree through the transform interface provided by the TypeScript compiler (tsc). The transform interface provides lifecycle hook functions, which are functions triggered at different lifecycles (such as before compilation, during compilation, and after compilation). Among them, the hook function before compilation can obtain the abstract syntax tree of the Transcript language and directly operate on the abstract syntax tree of the Transcript language. By using the hook function before compilation through the compiler, the electronic device can achieve the ability to modify the abstract syntax tree, complete the replacement of corresponding new nodes according to the type of the target annotation in the nodes of the abstract syntax tree. This step may involve further optimizing the structure of the abstract syntax tree, deleting useless code, or applying performance optimization to certain specific structures, etc.
[0096] The following is an example of the source code in the first programming language before compilation:
[0097]
[0098] As can be seen from the above code, @Scenarios is a scenario annotation, and function takePhoto() is a scenario description function. @Scenarios is used to mark function takePhoto(), and this scenario description function can manage the resources of the photo-taking resource scenario. var camera_photo is a resource variable, which can be used to construct an abstract resource object. The abstract resource object constructed by the resource variable var camera_photo is R_CameraManager. R_CameraManager is an abstract resource object, which can be used to describe the resources of the photo-taking resource scenario. @Device is a resource annotation, which is used to mark the resource variable var camera_photo, so as to describe the resources of the abstract resource object R_CameraManager corresponding to the resource variable var camera_photo. The attribute variables of the abstract resource object include a static attribute attr, which can be used to describe the device type of the resources in the photo-taking resource scenario, the component type in the device, etc. For example, the number of cameras that need to be called in the photo-taking resource scenario and which cameras in the electronic device need to be called, etc.; the attribute variables of the abstract resource object include an action attribute action, which can be used to describe the actions of the resources in the photo-taking resource scenario. For example, onPhoto:(result:Bitmap) is used to represent starting photo-taking and obtaining the image obtained by photo-taking. @res is an attribute annotation, which is used to mark the attribute variable attr.
[0099] The following is an example of the abstract syntax tree during compilation:
[0100]
[0101]
[0102] As can be seen from the above code, Function Declaration{} is a node of the abstract syntax tree, and the syntax structure it represents is a function declaration; VaraiableStatement{} is also a node of the abstract syntax tree, and the syntax structure it represents is a variable declaration. A node can include a decorator, and the decorator can include an annotation variable escapedText. Therefore, by traversing each node in the abstract syntax tree and determining whether there is a decorator in the node, if there is a decorator, it can be determined whether the annotation variable in the decorator is the target annotation. Assume that the target annotations are @Scenarios, @Device, @Res. If the annotation variable escapedText: "Senarios", escapedText: "Device", escapedText: "Res", it means that a node with the target annotation has been recognized.
[0103] The electronic device traverses the abstract syntax tree through the compiler, identifies the decorator field of each node in the abstract syntax tree, and determines whether the escapedText field of each node is the target annotation name, such as Scenarios, Device, Res, etc., so as to identify the nodes with the target annotations (such as @Scenarios, @Device, @Res, etc.). As shown in the above code, escapedText: "Senarios", escapedText: "Device" can indicate that the nodes of the abstract syntax tree have the target annotations @Senarios and @Device respectively.
[0104] In some embodiments, the annotation type includes a scenario annotation, the code element includes a scenario description function, and the scenario annotation is used to mark the resource scenario corresponding to the scenario description function; the instrumentation operations matching the scenario annotation include: identifying one or more abstract resource objects corresponding to the resource scenario in the scenario description function, and constructing and / or invoking each abstract resource object.
[0105] The scenario description function is decorated by the scenario annotation and is given the ability to manage resources.
[0106] In some embodiments, the scenario annotation is used to mark the resource scenario corresponding to the scenario description function, and the scenario annotation can be represented as @Scenarios. After @Scenarios, parameters can be input to specify the resource scenario, such as call: call scenario; EnerySaving: energy-saving scenario.
[0107] For example, if the scenario annotation is @Scenarios(EnerySaving), it indicates that the current resource scenario is an energy-saving scenario. Therefore, the startRecording() function annotated with @Scenarios(EnerySaving) can be a function that only implements the recording function. If the scenario annotation is @Scenarios, i.e., in the form without parameters, it indicates that the current resource scenario is a normal scenario and does not belong to special scenarios such as energy-saving scenarios. Therefore, the startRecording() function annotated with @Scenarios can be a function that implements the positioning function while implementing the recording function.
[0108] The electronic device can identify one or more abstract resource objects corresponding to the resource scenario in the scenario description function annotated with the scenario annotation, and construct and / or call each abstract resource object, so as to construct and / or call the abstract resource objects in the resource scenario annotated with the scenario annotation.
[0109] In some embodiments, the annotation type further includes a resource annotation, and the code element includes a resource variable; the resource annotation is used to annotate the resource description of the first abstract resource object corresponding to the resource variable; the instrumentation operation matched by the resource annotation includes: constructing an abstract resource corresponding to the first abstract resource object according to the resource description.
[0110] In the scenario description function, decorating the abstract resource object with the resource annotation can achieve the management and description of the resource. The resource variable is used to construct the abstract resource object.
[0111] In some embodiments, the resource annotation can be expressed as @Device. The resource annotation is used to annotate the resource description of the first abstract resource object corresponding to the resource variable, and the resource description may include but is not limited to the behavior of the resource, the attributes of the resource, etc. The first abstract resource object is any abstract resource object.
[0112] The first abstract resource object corresponding to the resource variable refers to the abstract resource object constructed by the resource variable.
[0113] In some embodiments, various abstract resource objects included in the scenario description function can be used to describe the static attributes (attr) and action attributes (action) of the resource.
[0114] The static attribute is used to describe the attributes of the resource, such as the device type, the component type in the device, etc. For example, the device type may include a mobile phone, a tablet computer, or a wearable device, etc.; the component type in the device may include a camera component, a microphone component, a positioning component, a storage component, etc.
[0115] In some embodiments, the configuration of the static attribute can be in<resconfig>It can be defined within the tag. Attribute definition can be done directly, or it can be set in the form of chained calls. For the configuration name prefixes of different abstract resource objects and the types of static attributes within the configuration block, refer to the static attribute configuration document. After configuring the static attributes, the configuration of the static attributes can be referenced in the way of @resconfig.XX.
[0116] Action attributes are used to describe the actions of resources, such as opening and closing. For example, the actions of resources can include actions such as turning on, running, and turning off a device, or actions such as turning on, running, and turning off components within a device. The configuration of action attributes can be done directly by defining attributes or in the form of chained calls. To configure action attributes, refer to the corresponding abstract resource management class document.
[0117] Therefore, in the embodiments of the present application, resource management is implemented through a scenario description function, and abstract resource objects are used to describe the static attributes and action attributes of resources.
[0118] Through these description methods, the source code of the first programming language can be used to comprehensively describe resources, covering the characteristics, behaviors of resources, and how to use these resources in different scenarios, enabling developers to more easily manage and manipulate resources, thereby improving development efficiency.
[0119] In some embodiments, the annotation type also includes attribute annotations, and the code element includes an attribute variable; the attribute annotation is used to mark the static attribute of the second abstract resource object to which the attribute variable belongs; the instrumentation operation matching the attribute annotation includes: replacing the static attribute of the second abstract resource object with the static attribute of the resource configuration class.
[0120] An abstract resource object includes attribute variables, and the attribute variables include static attributes and action attributes.
[0121] The attribute annotation is used to mark the static attribute of the second abstract resource object to which the attribute variable belongs. The second abstract resource object is any abstract resource object. The second abstract resource object to which the attribute variable belongs is the abstract resource object described by the attribute variable.
[0122] A resource configuration class refers to a class used to manage resource configurations in an application. The static attributes of the resource configuration class can be used to store and manage information related to resource configurations, such as configuration items in an application, such as database connection information, Uniform Resource Locator (URL), authentication keys, resource paths, application programming interface (API) ports, etc. Static attributes are usually used to store information that does not change with the instantiation of the class and can be directly accessed through the class name without creating an instance of the class.
[0123] Replace the static attributes of the second abstract resource object with the static attributes of the resource configuration class, so that the resource information can be conveniently adjusted and modified by modifying the static attributes, improving the configurability and maintainability of the resources.
[0124] In some embodiments, the electronic device constructs and / or invokes abstract resource objects within the resource scenario according to the scenario annotation @Scenarios, where the abstract resource objects to be constructed can be identified by the resource annotation @Device. For the attribute annotation @res, the electronic device can first <resconfig>The label is compiled into a resource management class (resconfig class). <resconfig>Labels describe the static attributes of abstract resource objects and can reference the static attributes in the resconfig class. Therefore, the electronic device can modify the abstract resource objects marked by the resource annotation @Device within the scenario description function marked by the scenario annotation @Scenarios. It can be modifying the attribute variables of the abstract resource object, including static attributes and action attributes. For the attribute variables marked by the attribute annotation @res, the attribute variable can be replaced with the corresponding static attribute of the resource management class. In the embodiments of the present application, the source code of the first programming language is used to abstract and describe the resources of the resource scenario by declaring one or more abstract resource objects included in the resource scenario. The declarative programming language expresses the goal or expected result of the program through declarative descriptions, and hides the specific implementation details of the problem abstractly through declarations. The core features of the declarative programming language mainly include declarative description and declarative abstraction. As a declarative programming language for device resource operations, the first programming language can provide developers with a simple, efficient, and modular device resource programming method through resource description and resource abstraction, making the program easier to understand, maintain, and expand. Therefore, the design of a general declarative programming language for resource operations of electronic devices can provide developers with a unified, simple, and efficient resource management method, thereby improving development efficiency and being applied in a wider range of scenarios and fields.
[0125] After the instrumentation operation on the abstract syntax tree is completed, a new abstract syntax tree can be generated, which contains the modified nodes. In this way, the nodes of the newly generated abstract syntax tree have the functions related to resource management.
[0126] 307. Generate the target code in the second programming language according to the code obtained after the instrumentation operation.
[0127] In some embodiments, the second programming language can be the TypeScript language, and the electronic device can convert the newly generated abstract syntax tree into the corresponding target code in the TypeScript language. Optionally, the electronic device can create a Printer object through the ts.createPrinter function provided by the TypeScript compiler (tsc), and the printNode function of the Printer object can convert the nodes of the abstract syntax tree into the target code in the string form of the TypeScript language.
[0128] Further, to adapt to the operating environment of the target device, the second programming language can be the JavaScript language. The electronic device can first convert the newly generated abstract syntax tree into corresponding code in the TypeScript language, and then further convert the code in the TypeScript language into target code in the JavaScript language.
[0129] The following is an example of the target code in the second programming language after compilation. The second programming language used by the target code is the TypeScript language.
[0130]
[0131]
[0132] It can be seen that the declarative extension language of the TypeScript language can be converted into the general TypeScript language.
[0133] The code compilation method of the embodiments of the present application introduces target annotations, on-demand refactoring of the abstract syntax tree, and flexible @ syntax processing, which is more efficient, flexible, and convenient in mobile device resource management. Specifically, it is reflected in the following aspects:
[0134] (1) Introduction of target annotations: A series of target annotations (such as @Scenarios, @Device, @Res, etc.) are introduced to identify and process different mobile application resource management scenarios. These annotations enable the implementation of a highly customized compilation process to meet the needs of developers in mobile device resource management.
[0135] (2) On-demand refactoring of the abstract syntax tree: By traversing the abstract syntax tree, after identifying the target annotations, stubbing operations are performed on the abstract syntax tree to generate new nodes to replace the original nodes. This compilation design enhances flexibility, enabling the compilation process to be customized and adjusted according to actual needs.
[0136] (3) Flexible @ syntax processing: The processing of the @ syntax is different from the original @ decorator processing method of TypeScript. The @ decorator of TypeScript is usually processed in the form of a function closure, while the compiler provided by the embodiments of the present application directly changes the compilation process to achieve specific resource management requirements. This method provides more control, enabling the compilation process to be flexibly adjusted.
[0137] Please refer further to Figure 5 , Figure 5 which is a schematic flowchart of the code compilation method in another embodiment; this code compilation method can be applied to the above-mentioned electronic device. As Figure 5 As shown in the figure, the code compilation method may include the following steps:
[0138] 501. Analyze the source code in the first programming language to identify one or more code elements in the source code that have target annotations.
[0139] Among them, the target annotation is used to identify the resource information corresponding to the code element.
[0140] 502. Perform instrumentation operations on each code element according to the target annotation corresponding to each code element.
[0141] 503. Convert the code obtained after the instrumentation operation into resource management code in the second programming language.
[0142] The resource management code is the code in the second programming language obtained by converting the source code in the first programming language. The resource management code can refer to lines 1-10 of the compiled target code in the second programming language exemplified above.
[0143] 504. Find the resource management class corresponding to each abstract resource object in the framework layer, and generate the execution code in the second programming language corresponding to each abstract resource object according to the resource management class corresponding to each abstract resource object.
[0144] The framework layer can provide various resource management classes for the declarative resource programming framework, such as the camera resource management class RCameraManager, the speaker resource management class RSpeakerManager, the microphone resource management class RMicManager, etc. Therefore, the framework layer provides rich resource management functions through multiple resource management classes, simplifies the processing of common tasks, improves development efficiency, and splits the code into modular multiple resource management classes, which can improve the reusability and maintainability of the code.
[0145] The execution code can refer to the compiled target code in the second programming language exemplified above, as follows:
[0146] RCameraManager.build(Device_camera_photo.attr,Device_camera_photo.action).
[0147] Finding the resource management class corresponding to the abstract resource object in the framework layer and generating the execution code in the second programming language corresponding to the abstract resource object according to the resource management class can, when the target device is actually running, call and manage the resources described by the abstract resource object by executing the corresponding execution code.
[0148] 505. Generate target code in the second programming language according to the resource management code and the execution code corresponding to each abstract resource object.
[0149] The resource management code is used to describe the abstract resource object, and the execution code is used to call and manage the resources corresponding to the abstract resource object.
[0150] The code compilation method of the embodiments of the present application provides greater flexibility for developers, making mobile application resource management more efficient and convenient, and having the following beneficial effects:
[0151] (1) High customization: It brings a highly customized experience to mobile application resource management. Developers can use special annotations (such as @Scenarios, @Device, @Res, etc.) to achieve customized management for specific scenarios, devices, and resources. In this way, developers can make flexible adjustments according to different requirements, so as to create a better and more demand-compliant resource management solution for mobile applications.
[0152] (2) Optimize the development experience: It does not impose any restrictions on the language features and runtime requirements of the TypeScript language, provides broader language feature support and runtime support, and helps to improve the development experience of developers.
[0153] (3) Improve resource management efficiency: It specifically optimizes mobile application resource management, so as to better meet the needs of mobile device resource management. For example, resource adaptation for different devices is achieved through special annotations, the resource loading strategy is optimized, resource redundancy and waste are reduced, and application performance is improved. These optimizations help to enhance the overall experience of mobile applications and at the same time improve the work efficiency of developers in resource management.
[0154] In some embodiments, during the actual compilation process, the generated target code can be further optimized to generate more readable and efficient code. The positions of the instrumentation operations and the nodes of the generated abstract syntax tree can apply static analysis tools for common compilation optimization operations. The programming language of the target code can be other programming languages in addition to TypeScript and JavaScript. Therefore, the first programming language can be compiled into any required language to match the needs of different running scenarios.
[0155] Please refer to Figure 6 , Figure 6 is a schematic structural diagram of a code compilation device in an embodiment. This device can be applied to the above-mentioned electronic device. As Figure 6 shown, the code compilation device 600 may include: an identification module 610, an instrumentation module 620, and a generation module 630.
[0156] An identification module 610, configured to analyze source code in a first programming language to identify one or more code elements in the source code with target annotations, where the target annotations are used to identify resource information corresponding to the code elements;
[0157] An instrumentation module 620, configured to perform instrumentation operations on each code element according to the target annotation corresponding to each code element;
[0158] A generation module 630, configured to generate target code in a second programming language according to the code obtained after the instrumentation operation.
[0159] In one embodiment, the identification module 610 is further configured to analyze source code in a first programming language to generate an abstract syntax tree corresponding to the source code; traverse each node included in the abstract syntax tree, and determine whether the annotation variable included in the decorator in each node is a target annotation; if the annotation variable included in the decorator in the first node is a target annotation, determine that the code element corresponding to the first node is a code element with a target annotation, where the first node is any node.
[0160] In one embodiment, the instrumentation module 620 is further configured to perform an instrumentation operation matching the annotation type of the corresponding target annotation on each code element according to the annotation type of the target annotation corresponding to each code element.
[0161] In one embodiment, the annotation type includes a scenario annotation, the code element includes a scenario description function, and the scenario annotation is used to mark the resource scenario corresponding to the scenario description function; the instrumentation operation matching the scenario annotation includes: identifying one or more abstract resource objects corresponding to the resource scenario in the scenario description function, and constructing and / or calling each abstract resource object.
[0162] In one embodiment, the annotation type further includes a resource annotation, and the code element includes a resource variable; the resource annotation is used to mark the resource description of the first abstract resource object corresponding to the resource variable; the instrumentation operation matching the resource annotation includes: constructing an abstract resource corresponding to the first abstract resource object according to the resource description.
[0163] In one embodiment, the annotation type further includes an attribute annotation, and the code element includes an attribute variable; the attribute annotation is used to mark the static attribute of the second abstract resource object to which the attribute variable belongs; the instrumentation operation matching the attribute annotation includes: replacing the static attribute of the second abstract resource object with the static attribute of the resource configuration class.
[0164] In one embodiment, the generation module 630 is further configured to convert the code obtained after the instrumentation operation into resource management code in a second programming language; find resource management classes corresponding to each abstract resource object in the framework layer, and generate execution code in the second programming language corresponding to each abstract resource object according to the resource management classes corresponding to each abstract resource object; and generate target code in the second programming language according to the resource management code and the execution code corresponding to each abstract resource object.
[0165] In one embodiment, the first programming language includes a domain-specific language (DSL) extended based on the TypeScript language, and the second programming language includes the TypeScript language or the JavaScript language.
[0166] In the embodiments of the present application, the source code in the first programming language is analyzed to identify one or more code elements with target annotations in the source code; instrumentation operations are performed on each code element according to the target annotations corresponding to each code element; target code in the second programming language is generated according to the code obtained after the instrumentation operation. The first programming language can identify the resource information corresponding to the code elements in the source code through the target annotations, so that the code elements corresponding to the resource information can be identified through the target annotations during the compilation of the source code, and instrumentation operations are performed on the code elements to process the resource information. Through the first programming language, efficient management of resources can be achieved, the degree of customization of resource management during compilation is improved, so as to meet the needs of developers in resource management. Moreover, the source code in the first programming language can be compiled into target code in the second programming language, which can adapt to different code running requirements and improve the applicability of the first programming language.
[0167] Please refer to Figure 7 , Figure 7 which is a schematic structural diagram of an electronic device in one embodiment. As Figure 7 shown, the electronic device 700 may include: a memory 710 storing executable program code; a processor 720 coupled to the memory 710; wherein, the processor 720 calls the executable program code stored in the memory 710 to execute any code compilation method disclosed in the embodiments of the present application.
[0168] The embodiments of the present application disclose a computer-readable storage medium storing a computer program, wherein when the computer program is executed by the processor, the processor implements any code compilation method disclosed in the embodiments of the present application.
[0169] It should be understood that the "one embodiment" or "an embodiment" mentioned throughout the specification means that the specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, the "in one embodiment" or "in an embodiment" that appears throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. Those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily essential to the present application.
[0170] In various embodiments of the present application, it should be understood that the size of the serial numbers of the above processes does not necessarily mean the inevitable sequence of execution. The execution sequence of each process should be determined by its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present application. The units described as separate components above may or may not be physically separated. The components shown as units may or may not be physical units, that is, they can be located in one place, or can be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment. In addition, the functional units in each embodiment of the present application can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units.
[0171] If the above integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-accessible memory. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions for causing a computer device (which can be a personal computer, a server or a network device, etc., specifically, the processor in the computer device) to execute some or all of the steps of the above methods in each embodiment of the present application.
[0172] Those of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing relevant hardware through a program, and this program can be stored in a computer-readable storage medium. The storage medium includes read-only memory (ROM), random access memory (RAM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), one-time programmable read-only memory (OTPROM), electrically-erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc memories, magnetic disk memories, tape memories, or any other computer-readable medium capable of carrying or storing data.
[0173] The above has introduced in detail a code compilation method, device, electronic device, and storage medium disclosed in the embodiments of the present application. Specific examples are used herein to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application. At the same time, for those of ordinary skill in the art, according to the idea of the present application, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation on the present application.< / resconfig> < / resconfig> < / resconfig>
Claims
1. A code compilation method, characterized in that, The method includes: Analyze the source code in the first programming language to identify one or more code elements in the source code with target annotations, where the target annotations are used to identify the resource information corresponding to the code elements; Perform a stubbing operation on each of the code elements according to the target annotations corresponding to each of the code elements; Generate target code in the second programming language based on the code obtained after the stubbing operation.
2. The method according to claim 1, wherein The analyzing the source code in the first programming language to identify one or more code elements in the source code with target annotations includes: Analyze the source code in the first programming language to generate an abstract syntax tree corresponding to the source code; Traverse each node included in the abstract syntax tree, and determine whether the annotation variable included in the decorator in each node is the target annotation; If the annotation variable included in the decorator in the first node is the target annotation, determine that the code element corresponding to the first node is a code element with the target annotation, where the first node is any one of the nodes.
3. The method according to claim 1, characterized in that The performing a stubbing operation on each of the code elements according to the target annotations corresponding to each of the code elements includes: Perform a stubbing operation matching the annotation type of the corresponding target annotation on each of the code elements according to the annotation type of the target annotation corresponding to each of the code elements.
4. The method according to claim 3, wherein The annotation type includes a scenario annotation, the code element includes a scenario description function, and the scenario annotation is used to label the resource scenario corresponding to the scenario description function; The stubbing operation matching the scenario annotation includes: identifying one or more abstract resource objects corresponding to the resource scenario in the scenario description function, and constructing and / or calling each of the abstract resource objects.
5. The method according to claim 4, wherein The annotation type further includes a resource annotation, the code element includes a resource variable; the resource annotation is used to label the resource description of the first abstract resource object corresponding to the resource variable; The stubbing operation matching the resource annotation includes: constructing an abstract resource corresponding to the first abstract resource object according to the resource description.
6. The method according to claim 4, characterized in that, The annotation type further includes an attribute annotation, the code element includes an attribute variable; the attribute annotation is used to label the static attribute of the second abstract resource object to which the attribute variable belongs; The stubbing operation matching the attribute annotation includes: replacing the static attribute of the second abstract resource object with the static attribute of a resource configuration class.
7. The method according to claim 4, characterized in that The generating target code in the second programming language based on the code obtained after the stubbing operation includes: Convert the code obtained after the stubbing operation into resource management code in the second programming language; Find the resource management class corresponding to each of the abstract resource objects from the framework layer, and generate execution code in the second programming language corresponding to each of the abstract resource objects according to the resource management class corresponding to each of the abstract resource objects; Generate target code in the second programming language based on the resource management code and the execution code corresponding to each of the abstract resource objects.
8. The method according to claim 1, wherein The first programming language includes a domain-specific language (DSL) extended from the TypeScript language, and the second programming language includes the TypeScript language or the JavaScript language.
9. A code compilation device, characterized in that, The apparatus includes: an identification module configured to analyze source code in the first programming language to identify one or more code elements having target annotations in the source code, where the target annotations are used to identify resource information corresponding to the code elements; an instrumentation module configured to perform an instrumentation operation on each of the code elements according to the target annotation corresponding to each of the code elements; a generation module configured to generate target code in the second programming language according to the code obtained after the instrumentation operation.
10. An electronic device, characterized in that, It includes a memory and a processor. When a computer program stored in the memory is executed by the processor, the processor implements the method according to any one of claims 1 to 8.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the method according to any one of claims 1 to 8.