Code running method and device for cross-platform programming language, equipment and medium

By using script identification and deserialization of preset cache libraries in code operation in cross-platform programming languages, combined with the annotation processing of the objective function library, the cross-platform code operation problems are solved, and efficient and accurate code operation is achieved.

CN119806636APending Publication Date: 2025-04-11SUZHOU TONGYUAN SOFT CONTROL INFORMATION TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411870197.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-18
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

In the prior art, when codes in cross-platform programming languages ​​run between different platforms, they need to be manually re-written, resulting in large development workloads, low operation efficiency, and difficulty in ensuring the consistency of the code, affecting the correctness of the operation results.

Method used

By responding to the operation of the source code to be run based on the second programming language, its script identification is determined, and a binary file associated with the script identification is found in the preset cache library, deserializing the process to obtain the pending code. Then, based on the objective function library corresponding to the first programming language, the to-process code is annotated and the annotated code is run on the target platform to obtain the target operation result.

Benefits of technology

It realizes that when running code between different platforms, reduces code processing costs, improves the efficiency and correctness of code operation, avoids the process of manually rewriting code, and improves compilation and operation efficiency and code interpretation accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119806636A_ABST
    Figure CN119806636A_ABST
Patent Text Reader

Abstract

The invention discloses a code running method and device for a cross-platform programming language, equipment and a medium. The method comprises the steps of determining a script identifier of a to-be-run source code in response to a running operation on the to-be-run source code based on a second programming language; under the condition that the binary file associated with the script identifier is found in a preset cache library, deserializing the found binary file to obtain a to-be-processed code; and based on a target function library corresponding to the first programming language, performing annotation processing on the to-be-processed code, and running the to-be-processed code subjected to annotation processing on the target platform to obtain a target running result. The problems of low code processing efficiency, high cost and poor running result accuracy caused by rewriting a set of codes according to the programming language specification of another platform in the prior art are solved, and the effect of improving the code running efficiency and correctness of the cross-platform programming language is achieved while the code processing cost is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer processing technology, and in particular to a method, device, equipment and medium for running code in a cross-platform programming language. Background Art

[0002] With the development of computer technology, more and more code development platforms have emerged. It is usually necessary to transfer the code in one platform to another platform for running. However, if the programming languages ​​of the two platforms are different, the code in one platform cannot be directly run on the other platform.

[0003] At present, the way to run code across platforms is usually to manually rewrite a set of code based on the code under the programming language specification of one platform and the programming language specification of another platform so that the rewritten code can run on the other platform. This method not only has a large development workload and low operating efficiency, but also makes it difficult to ensure the consistency of the two sets of code, affecting the correctness of the code running results. Summary of the invention

[0004] The present invention provides a method, device, equipment and medium for running code in a cross-platform programming language, so as to achieve the technical effect of achieving high efficiency and correctness of code running in a cross-platform programming language while reducing code processing costs.

[0005] According to one aspect of the present invention, a method for running code in a cross-platform programming language is provided. The method is applied to a target platform, the target platform corresponds to a first programming language, and the method comprises:

[0006] In response to a running operation on the source code to be run based on the second programming language, determining a script identifier of the source code to be run;

[0007] In the case where a binary file associated with the script identifier is found in the preset cache library, the found binary file is deserialized to obtain a code to be processed; wherein the code to be processed is an intermediate representation obtained after compiling and optimizing the abstract syntax tree of the source code to be run;

[0008] Based on the target function library corresponding to the first programming language, the code to be processed is annotated, and the annotated code to be processed is run on the target platform to obtain a target running result.

[0009] According to another aspect of the present invention, there is provided a device for executing code in a cross-platform programming language, the device being configured on a target platform corresponding to a first programming language; the device comprising:

[0010] A script identification determination module, configured to determine a script identification of the source code to be executed in response to an operation of executing the source code to be executed based on the second programming language;

[0011] A module for determining code to be processed, for deserializing the binary file found to obtain code to be processed when a binary file associated with the script identifier is found in a preset cache library; wherein the code to be processed is an intermediate representation obtained after compiling and optimizing the abstract syntax tree of the source code to be run;

[0012] The target operation result determination module is used to annotate the code to be processed based on the target function library corresponding to the first programming language, and run the annotated code to be processed on the target platform to obtain the target operation result.

[0013] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:

[0014] at least one processor; and a memory in communication with the at least one processor; wherein,

[0015] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the code running method of the cross-platform programming language described in any embodiment of the present invention.

[0016] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the code running method of a cross-platform programming language described in any embodiment of the present invention when executed.

[0017] According to another aspect of the present invention, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the code running method of a cross-platform programming language as described in any embodiment of the present invention.

[0018] The technical solution of the embodiment of the present invention determines the script identifier of the source code to be run in response to the running operation of the source code to be run based on the second programming language; when the binary file associated with the script identifier is found from the preset cache library, the found binary file is deserialized to obtain the code to be processed; based on the target function library corresponding to the first programming language, the code to be processed is annotated, and the annotated code to be processed is run on the target platform to obtain the target running result, which solves the problem of rewriting a set of codes according to the programming language specification of another platform in the prior art, resulting in low code processing efficiency, high cost and poor running result accuracy, and realizes that when running the source code to be run based on the second programming language, according to the script identifier of the source code to be run, the code to be processed obtained by pre-compiling and optimizing the abstract syntax tree of the source code to be run is found from the preset cache library, thereby improving the compilation and running efficiency while improving the code interpretation accuracy. Furthermore, there is no need to convert the code. It is only necessary to add annotation information to the code to be processed through the target function library corresponding to the first programming language, so that the annotated code to be processed can be correctly and efficiently executed by the target platform to obtain the target running result, thereby achieving the effect of improving the code running efficiency and correctness of the cross-platform programming language while reducing the code processing cost.

[0019] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0021] Figure 1 is a flowchart of a code running method of a cross-platform programming language provided according to Embodiment 1 of the present invention;

[0022] Figure 2 is a schematic diagram of a code running method of a cross-platform programming language provided in Embodiment 1 of the present invention;

[0023] Figure 3 This is a schematic diagram of the structure of a code running device for a cross-platform programming language provided according to a second embodiment of the present invention;

[0024] Figure 4It is a schematic diagram of the structure of an electronic device for implementing the code running method of a cross-platform programming language according to an embodiment of the present invention. DETAILED DESCRIPTION

[0025] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0027] Before introducing the technical solution, an exemplary description of the application scenario can be given first. The technical solution can be applied in a scenario where a code developed based on a platform programming language is run on a platform of another programming language. For example, after developing source code based on a programming language, when the developed source code needs to be imported into a platform of another programming language to run the source code, the technical solution provided by the embodiment of the present disclosure can be adopted. The other programming language is the following first programming language, and the platform of the first programming language is the target platform. In other words, the programming language of the target platform is different from the programming language used by the source code to be run. In the current technology, the target platform is the environment in which the first programming language runs, and the target platform cannot directly compile and run the source code of other programming languages. For example, the target platform can be a Syslab platform, and its first programming language is the Julia language. The programming language different from the first programming language can be called the second programming language, and the platform of the second programming language is other platforms different from the target platform. For example, other platforms can be MATLAB platforms, and its second programming language is M language. The technical solution provided by the embodiment of the present disclosure can realize running the code developed based on the MATLAB platform M language on the Syslab platform to obtain the running result.

[0028] Embodiment 1

[0029] Figure 1 This is a flowchart of a method for running a code in a cross-platform programming language according to a first embodiment of the present invention. This embodiment is applicable to the case of running a code in a cross-platform programming language. The method can be executed by a code running device in a cross-platform programming language. The code running device in a cross-platform programming language can be implemented in the form of hardware and / or software. The code running device in a cross-platform programming language can be configured on a target platform, and the target platform corresponds to a first programming language. Figure 1 As shown, the method includes:

[0030] S110: In response to an operation of executing a source code to be executed based on a second programming language, a script identifier of the source code to be executed is determined.

[0031] The second programming language is different from the first programming language. The source code to be run may refer to the code to be run that is developed based on the second programming language. The script identifier may be used to identify the uniqueness of the source code to be run. For example, the script identifier may be the name, version number, creation date, hash value, or other data that can uniquely identify the source code.

[0032] In this embodiment, the source code developed based on the second programming language can be imported into the target platform. On the target platform, when the run control in the target platform is triggered for the source code, or when the command line for running the source code is input, it is considered that the run operation of the source code is detected. The source code is the source code to be run, and then the script identifier of the source code to be run can be parsed to find out whether there is a file pre-compiled and optimized for the source code to be run based on the script identifier.

[0033] S120: When a binary file associated with the script identifier is found in the preset cache library, the found binary file is deserialized to obtain a code to be processed.

[0034] Among them, the preset cache library is used to store the binary file of the code obtained after the abstract syntax tree of different source codes under the second programming language is compiled and optimized, and the source code script identifier associated with the binary file. The code to be processed is based on the intermediate representation obtained after the abstract syntax tree of the source code to be run is compiled and optimized. The abstract syntax tree is an abstract representation of the grammatical structure of the source code to be run, which represents the grammatical structure of the source code in a tree structure. Each node in the abstract syntax tree can represent a grammatical element in the source code to be run, such as a function, variable, variable declaration, expression or statement, etc. The nodes are connected by a parent-child relationship to form a tree.

[0035] In this embodiment, the script identifier of the source code to be run can be compared with the various script identifier information in the preset cache library. If there is script identifier information consistent with the script identifier, the binary file associated with the consistent script identifier information is used as the found binary file. This binary file is a binary format file obtained after serialization. The data content in the binary file can be converted back to its original format (that is, the code format obtained after compiling and optimizing the abstract syntax tree of the source code to be run), thereby obtaining the code to be processed, so that the code to be processed can be compiled and run subsequently, thereby improving the accuracy and efficiency of code running. For example, see Figure 2 After determining the script identifier of the source code to be run, it can be determined whether a binary file associated with the script identifier exists in the preset cache library; if so, the binary file is deserialized to obtain the code to be processed.

[0036] In this embodiment, when there is no binary file associated with the script identifier in the preset cache library, an abstract syntax tree corresponding to the source code to be run is determined; based on the data structure corresponding to the first programming language, the abstract syntax tree is context-processed to obtain an intermediate representation; the intermediate representation is serialized to obtain a binary file, and the binary file and the script identifier of the source code are associated and stored in the preset cache library, so as to retrieve the binary file from the preset cache library based on the script identifier.

[0037] Among them, the intermediate representation (IR) is the code obtained by compiling and optimizing the abstract syntax tree of the source code to be run. The intermediate representation is a representation between the first programming language and the second programming language, which is closer to the data result of the target platform, but still retains the high-level semantic information of the source code.

[0038] Specifically, when there is no binary file associated with the script identifier in the preset cache library, a compiler or interpreter can be used to read the source code to be run, and convert it into an abstract syntax tree through lexical analysis and syntax analysis. Further, the abstract syntax tree can be subjected to context analysis, such as but not limited to semantic analysis, lexical analysis, syntax analysis, data type checking, scope resolution, etc. between parent and child nodes, and context information is added to each node in the abstract syntax tree according to the data structure corresponding to the first programming language, such as converting the function name in the node into the function name required in the data structure, and converting the function parameter in the node into an address index, thereby converting the abstract syntax tree into an intermediate representation. This intermediate representation contains more information about the source code to be run, such as data type information, scope information, etc. Optionally, the intermediate representation includes but is not limited to at least one of the following forms: Three-Address Code (TAC); Static Single Assignment Form (SSA): each variable is assigned only once in each code block. High-Level Intermediate Representation (HLIR): an intermediate representation that retains more advanced semantic information in the source code, such as loops, conditional judgments, etc. Furthermore, the intermediate representation can be serialized and converted into a binary file, which is a binary file. The binary file and the script identifier of the source code to be run are associated and stored in a preset cache library, so that when the source code to be run is run next time, the corresponding binary file can be quickly retrieved from the preset cache library through its script identifier to obtain the compiled and optimized intermediate representation as the code to be processed. For example, see Figure 2 , when it is determined that there is no binary file associated with the script identifier in the preset cache library, an abstract syntax tree of the source code to be run is determined, context processing is performed on the abstract syntax tree to obtain an intermediate representation, and the intermediate representation is used as the code to be processed.

[0039] The technical solution provided in this embodiment can obtain an intermediate representation after compiling and optimizing the abstract syntax tree of the source code to be run when there is no binary file associated with the script identifier in the preset cache library. The source code compilation is time-consuming, and the compiled and optimized intermediate representation is saved as a binary file and stored in the cache library. In this way, the cache library can be directly called later and the intermediate representation can be restored by deserialization to skip the compilation step, which can improve the execution efficiency of the code, reduce the compilation time, and improve the accuracy of source code operation.

[0040] S130: Annotate the code to be processed based on the target function library corresponding to the first programming language.

[0041] Among them, the target function library can be a collection of objects (objects include but are not limited to functions, function parameters (such as variables), interfaces or libraries) developed based on the first programming language. The target function library can also include conversion information of which object developed in the first programming language the object in the second programming language needs to be converted into. The two objects in the conversion information are equivalent objects, such as the M variable type is equivalent to the Julia variable type, the Julia variable type can be recognized by the target platform, and the M variable type cannot be recognized in the target platform. The code to be processed can be obtained by deserializing from a binary file, or by directly compiling and optimizing the abstract syntax tree of the source code to be run.

[0042] In this embodiment, objects that need to be converted can be found from the code to be processed according to the conversion information in the target function library, and the object to be converted can be determined according to the conversion information. The object to be converted can be written as annotation information to the object to be converted in the corresponding code to be processed to obtain the code to be processed after annotation processing. The purpose of annotation processing is to ensure that the code after annotation processing can be correctly compiled and executed on the target platform.

[0043] In this embodiment, based on the target function library corresponding to the first programming language, the code to be processed is annotated, including: for each line of code in the code to be processed, when the current line of code contains the object to be mapped, determining whether there is a target call object corresponding to the object to be mapped in the target function library corresponding to the first programming language; if so, establishing a mapping relationship between the object to be mapped and its corresponding target call object, and adding the mapping relationship as annotation information to the object to be mapped in the current line of code to obtain the annotated code to be processed.

[0044] Among them, the target function library includes conversion information that objects in the second programming language need to be converted into objects developed in the first programming language. The object to be mapped is an object developed in the second programming language. The object to be mapped includes a function name and / or function parameters, or other objects that can be mapped to objects in the target function library. The function name can be an identifier used to uniquely identify a function. In a computer program, the function can be called by the function name and the code inside it can be executed. Define a function named add to calculate the sum of two numbers. Function parameters can be variables inside the function body, which can participate in calculations, logical judgments and other operations. The target call object is an object developed in the first programming language, that is, the target call object refers to a function, variable, method or interface that can be run on the target platform.

[0045] Specifically, each line of code to be processed can be traversed, and whether there are objects such as function names or function parameters in each line of code can be identified line by line, and the existing objects such as function names or function parameters can be used as objects to be mapped. If the current line of code contains an object to be mapped, it can be found from the target function library whether there is an object to be mapped that needs to be converted into object information. If it exists, the object information can be used as the target call object. And a mapping relationship between the object to be mapped and its corresponding target call object is established, the established mapping relationship is used as annotation information, and the annotation information is added to the object to be mapped in the current line of code. Correspondingly, a code to be processed containing annotation information can be obtained. The advantage of this setting is that by adding comments to the code, annotation information can be used to mark which object to be mapped needs to be converted into the corresponding target call object, so that the annotation information can be used to efficiently utilize the target function library to realize the operation of the source code to be run under the second programming language on the target platform, without the need for code conversion, while improving the efficiency of code operation and ensuring the correctness of code operation.

[0046] Exemplarily, the code to be processed includes a function name A in the second programming language, and function name A needs to be replaced with function name B in the first programming language. An annotation information "function name A is converted to function name B" can be added to function name A in the code to be processed.

[0047] S140, running the annotated code to be processed on the target platform to obtain a target running result.

[0048] The target execution result is consistent with the output or result generated after executing the source code to be executed. For example, the target execution result can be the return value of a function, a calculated value, a set of data, a graph, a message printed to the console, or any other form of data.

[0049] Continue to see Figure 2 , the code to be processed can be run on the target platform according to the annotation information of the corresponding object to be mapped in the code to be processed after annotation processing, so that the code to be processed can be correctly interpreted and executed on the target platform to obtain the target running result.

[0050] In this embodiment, the code to be processed after annotation processing is run on the target platform to obtain the target running result, including: running the code to be processed after annotation processing on the target platform; if there is annotation information in the current code line in the running code to be processed, and the target call object in the mapping relationship corresponding to the annotation information is a function name, then calling the target function corresponding to the target call object to obtain the return object corresponding to the target function; if there is annotation information in the current code line in the running code to be processed, and the target call object in the mapping relationship corresponding to the annotation information is a function parameter, then converting the corresponding object to be mapped in the current code line under the mapping relationship into the target call object; based on the last return object obtained, determining the target running result.

[0051] The target function is a function in the target function library. The return object is the result of the target function operation. The return object can be the input of subsequent processing or a part of the final result. The return object can be any type of data, which depends on the implementation of the function and the input parameters.

[0052] In the process of running the code to be processed after annotation processing on the target platform, if there is annotation information in the current code line in the running code to be processed, the target call object in the mapping relationship corresponding to the annotation information can be parsed to see whether it is a function name or a function parameter. If the target call object is a function name, the target function corresponding to the target call object can be called from the target function library. After the target function is executed, an object is returned, and this object is the return object corresponding to the target function. If the target call object is a function parameter, the object to be mapped in the current code line can be converted to a data type consistent with the target call object. For example, the MATLAB data type (i.e., the data type of the object to be mapped) is converted into the Julia data type (i.e., the data type of the target call object), such as converting the double type of MATLAB into the Float64 of Julia, and converting the complex number 1+2i of MATLAB into the 1+2im of Julia, etc. After processing all the code lines containing annotation information, the target running result can be determined based on the last return object in the code to be processed.

[0053] In this embodiment, if the current code line in the running code to be processed includes an object to be mapped that is a function name, and there is no annotation information in the object to be mapped, the general language function corresponding to the object to be mapped is called to obtain the return object corresponding to the general language function.

[0054] Among them, the general language function is a function that is applicable to both the target platform and the platform to which the second programming language belongs, that is, a function in a built-in function library, such as the sin function.

[0055] Specifically, when the current code line of the code to be processed is run, it can be detected whether the code line contains the object to be mapped. If the object to be mapped is included, and the object to be mapped is a function name, and there is no annotation information in the object to be mapped, it means that the function corresponding to the function name is a general function, and the general language function corresponding to the object to be mapped can be directly called to execute the logic defined by it and return an object as the return object corresponding to the general language function.

[0056] In this embodiment, the target execution result is determined based on the last returned object obtained, including: if the last returned object is obtained based on a general language function, the last returned object is used as the target execution result; if the last returned object is obtained based on a target function, the last returned object is converted based on the object type of the object to be mapped mapped by the target calling object corresponding to the target function to obtain the target execution result.

[0057] Among them, object type refers to data type, such as string, integer, floating point number, list, dictionary, Boolean and other data types.

[0058] Specifically, if the last return object is obtained by calling a general language function, then this return object can be directly used as the target operation result. In this case, no additional conversion or processing is required because the result returned by the general language function also corresponds to the data in the second programming language. If the last return object is obtained by calling the target function, then the return object can be converted according to the object type of the object to be mapped mapped by the target call object corresponding to the target function, and the data type of the return object is converted to the object type. For example, MATLAB data types are converted to Julia data types, such as MATLAB double types are converted to Julia Float64, MATLAB complex numbers 1+2i are converted to Julia 1+2im, and so on. The converted return object is used as the target operation result, and the target operation result at this time corresponds to the data in the second programming language. The advantage of this is that the target operation result can be made consistent with the output result corresponding to the source code to be executed on the platform based on the second programming language, meeting the user's result acquisition requirements for executing other platform codes on the target platform, and finally obtaining the target operation result that meets the expected requirements.

[0059] In this embodiment, the annotated code to be processed can also be run on the target platform, and after obtaining the target running result, the drawing function in the target platform is called; a running image corresponding to the target running result is drawn based on the drawing function, and the running image is displayed on the result display page in the target platform.

[0060] The result display page is used to display the image generated by the drawing function.

[0061] Specifically, some built-in or available drawing functions can be set in advance in the target platform, and these drawing functions can be used to generate charts, graphs or other visual representations. After calling the drawing function in the target platform, the called drawing function can be used to draw the corresponding image according to the target running result as the running image. The running image may include but is not limited to line graphs, bar graphs, pie charts, scatter graphs, different shapes drawn, etc. Further, the running image can be displayed on the result display page in the target platform, so that the user can analyze the target running result by intuitively viewing the running image.

[0062] The technical solution of this embodiment determines the script identifier of the source code to be run in response to the running operation of the source code to be run based on the second programming language; when the binary file associated with the script identifier is found from the preset cache library, the found binary file is deserialized to obtain the code to be processed; based on the target function library corresponding to the first programming language, the code to be processed is annotated, and the annotated code to be processed is run on the target platform to obtain the target running result, which solves the problem of rewriting a set of codes according to the programming language specification of another platform in the prior art, resulting in low code processing efficiency, high cost and poor running result accuracy. When running the source code to be run based on the second programming language, the code to be run obtained by compiling and optimizing the abstract syntax tree of the source code to be run in advance is found from the preset cache library according to the script identifier of the source code to be run, thereby improving the compilation and running efficiency while improving the accuracy of code interpretation. Furthermore, there is no need to convert the code. It is only necessary to add annotation information to the code to be processed through the target function library corresponding to the first programming language, so that the annotated code to be processed can be correctly and efficiently executed by the target platform to obtain the target running result, thereby achieving the effect of improving the efficiency and correctness of code running in cross-platform programming languages ​​while reducing the code processing cost.

[0063] Embodiment 2

[0064] Figure 3 1 is a schematic diagram of a cross-platform programming language code execution device according to the second embodiment of the present invention. The device is configured on a target platform, and the target platform corresponds to a first programming language. Figure 3 As shown, the device includes: a script identification determination module 210, a to-be-processed code determination module 220 and a target operation result determination module 230.

[0065] Among them, the script identifier determination module 210 is used to determine the script identifier of the source code to be run in response to the running operation of the source code to be run based on the second programming language; the code to be processed determination module 220 is used to deserialize the binary file found when the binary file associated with the script identifier is found from the preset cache library to obtain the code to be processed; wherein the code to be processed is an intermediate representation obtained after compiling and optimizing the abstract syntax tree of the source code to be run; the target running result determination module 230 is used to annotate the code to be processed based on the target function library corresponding to the first programming language, and run the annotated code to be processed on the target platform to obtain the target running result.

[0066] The technical solution of this embodiment determines the script identifier of the source code to be run in response to the running operation of the source code to be run based on the second programming language; when the binary file associated with the script identifier is found from the preset cache library, the found binary file is deserialized to obtain the code to be processed; based on the target function library corresponding to the first programming language, the code to be processed is annotated, and the annotated code to be processed is run on the target platform to obtain the target running result, which solves the problem of rewriting a set of codes according to the programming language specification of another platform in the prior art, resulting in low code processing efficiency, high cost and poor running result accuracy. When running the source code to be run based on the second programming language, the code to be run obtained by compiling and optimizing the abstract syntax tree of the source code to be run in advance is found from the preset cache library according to the script identifier of the source code to be run, thereby improving the compilation and running efficiency while improving the accuracy of code interpretation. Furthermore, there is no need to convert the code. It is only necessary to annotate the code to be processed through the target function library corresponding to the first programming language, so that the annotated code to be processed can be correctly and efficiently executed by the target platform to obtain the target running result, thereby achieving the effect of improving the code running efficiency and correctness of the cross-platform programming language while reducing the code processing cost.

[0067] On the basis of the above device, optionally, the device further includes:

[0068] An abstract syntax tree determining unit is used to determine an abstract syntax tree corresponding to the source code when there is no binary file associated with the script identifier in a preset cache library;

[0069] an intermediate representation determining unit, configured to perform context processing on the abstract syntax tree based on a data structure corresponding to the first programming language to obtain an intermediate representation;

[0070] The binary file determination unit is used to serialize the intermediate representation to obtain a binary file, and associate the binary file with the script identifier of the source code and store it in a preset cache library, so as to retrieve the binary file from the preset cache library based on the script identifier.

[0071] Based on the above device, optionally, the target operation result determination module 230 includes:

[0072] a target calling object judging unit, for each line of code in the code to be processed, when the current line of code contains an object to be mapped, determining whether there is a target calling object corresponding to the object to be mapped in the target function library corresponding to the first programming language; wherein the object to be mapped includes a function name and / or function parameters;

[0073] The annotation information determination unit is used to establish a mapping relationship between the object to be mapped and its corresponding target calling object if it exists, and to establish annotation information based on the mapping relationship and add it to the object to be mapped in the current line of code to obtain the code to be processed after annotation processing.

[0074] Based on the above device, optionally, the target operation result determination module 230 includes:

[0075] A running unit, used for running the code to be processed after annotation processing on the target platform;

[0076] a return object determination unit, configured to, if annotation information exists in a current code line in the running code to be processed, and the target calling object in the mapping relationship corresponding to the annotation information is a function name, call a target function corresponding to the target calling object to obtain a return object corresponding to the target function;

[0077] An object conversion unit, configured to convert the object to be mapped corresponding to the mapping relationship in the current code line into the target calling object if annotation information exists in the current code line in the running code to be processed, and the target calling object in the mapping relationship corresponding to the annotation information is a function parameter;

[0078] The target operation result determination unit is used to determine the target operation result based on the last returned object obtained.

[0079] On the basis of the above device, optionally, the device further includes:

[0080] A universal language function calling unit is used to call the universal language function corresponding to the object to be mapped if the current code line in the code to be processed includes an object to be mapped as a function name and there is no annotation information in the object to be mapped, so as to obtain a return object corresponding to the universal language function.

[0081] On the basis of the above-mentioned device, optionally, a target execution result determination unit is used to, if the last return object is obtained based on a general language function, use the last return object as the target execution result; if the last return object is obtained based on a target function, convert the last return object based on the object type of the object to be mapped mapped by the target calling object corresponding to the target function to obtain the target execution result.

[0082] On the basis of the above device, optionally, the device further includes:

[0083] A drawing function calling unit, used for calling the drawing function in the target platform;

[0084] A running image display unit is used to draw a running image corresponding to the target running result based on the drawing function, and display the running image on a result display page in the target platform.

[0085] The cross-platform programming language code execution device provided in the embodiment of the present invention can execute the cross-platform programming language code execution method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0086] Embodiment 3

[0087] Figure 4 It is a structural diagram of an electronic device that implements the code running method of the cross-platform programming language of an embodiment of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are only examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0088] like Figure 4As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0089] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0090] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The processor 11 executes the various methods and processes described above, such as a code running method of a cross-platform programming language.

[0091] In some embodiments, the code running method of the cross-platform programming language may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the code running method of the cross-platform programming language described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the code running method of the cross-platform programming language in any other appropriate manner (e.g., by means of firmware).

[0092] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0093] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0094] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0095] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0096] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0097] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0098] An embodiment of the present invention further provides a computer program product, including a computer program, which, when executed by a processor, implements a code running method in a cross-platform programming language as provided in any embodiment of the present invention.

[0099] In the process of implementation, the computer program product can be written in one or more programming languages ​​or a combination thereof to perform the computer program code of the present invention, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).

[0100] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0101] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A code running method of a cross-platform programming language, characterized in that: Applied to a target platform, the target platform corresponding to a first programming language, the method comprising: In response to a running operation on the source code to be run based on the second programming language, determining a script identifier of the source code to be run; In the case where a binary file associated with the script identifier is found in the preset cache library, the found binary file is deserialized to obtain a code to be processed; wherein the code to be processed is an intermediate representation obtained after compiling and optimizing the abstract syntax tree of the source code to be run; Based on the target function library corresponding to the first programming language, the code to be processed is annotated, and the annotated code to be processed is run on the target platform to obtain a target running result.

2. The method according to claim 1, characterized in that The method further comprises: In the case that there is no binary file associated with the script identifier in the preset cache library, determining an abstract syntax tree corresponding to the source code; Based on a data structure corresponding to the first programming language, context processing is performed on the abstract syntax tree to obtain an intermediate representation; The intermediate representation is serialized to obtain a binary file, and the binary file is associated with a script identifier of the source code and stored in a preset cache library, so that the binary file can be retrieved from the preset cache library based on the script identifier.

3. The method according to claim 1, characterized in that The step of performing annotation processing on the code to be processed based on a target function library corresponding to the first programming language includes: For each line of code in the code to be processed, if the current line of code contains an object to be mapped, determining whether there is a target calling object corresponding to the object to be mapped in the target function library corresponding to the first programming language; wherein the object to be mapped includes a function name and / or function parameters; If so, a mapping relationship between the object to be mapped and its corresponding target calling object is established, and annotation information is established based on the mapping relationship and added to the object to be mapped in the current line of code to obtain the code to be processed after annotation processing.

4. The method according to claim 3, characterized in that The step of running the code to be processed after annotation processing on the target platform to obtain a target running result includes: Running the code to be processed after annotation processing on the target platform; If there is annotation information in the current code line in the running code to be processed, and the target calling object in the mapping relationship corresponding to the annotation information is a function name, then calling the target function corresponding to the target calling object to obtain the return object corresponding to the target function; If annotation information exists in the current code line in the running code to be processed, and the target call object in the mapping relationship corresponding to the annotation information is a function parameter, the object to be mapped corresponding to the mapping relationship in the current code line is converted into the target call object; Based on the last returned object, the target running result is determined.

5. The method according to claim 4, characterized in that The method further comprises: If the current code line in the executed code to be processed includes an object to be mapped which is a function name, and there is no annotation information in the object to be mapped, a universal language function corresponding to the object to be mapped is called to obtain a return object corresponding to the universal language function.

6. The method according to claim 4 or 5, characterized in that: The step of determining the target operation result based on the last returned object obtained includes: If the last returned object is obtained based on the general language function, the last returned object is used as the target running result; If the last returned object is obtained based on the target function, the last returned object is converted based on the object type of the object to be mapped mapped by the target calling object corresponding to the target function to obtain the target running result.

7. The method according to claim 1, characterized in that After running the code to be processed after annotation processing on the target platform and obtaining a target running result, the method further includes: Calling a drawing function in the target platform; A running image corresponding to the target running result is drawn based on the drawing function, and the running image is displayed on a result display page in the target platform.

8. A code running device for a cross-platform programming language, characterized in that: The device is configured on a target platform, the target platform corresponds to a first programming language; the device comprises: A script identification determination module, configured to determine a script identification of the source code to be executed in response to an operation of executing the source code to be executed based on the second programming language; A module for determining code to be processed, for deserializing the binary file found to obtain code to be processed when a binary file associated with the script identifier is found in a preset cache library; wherein the code to be processed is an intermediate representation obtained after compiling and optimizing the abstract syntax tree of the source code to be run; The target operation result determination module is used to annotate the code to be processed based on the target function library corresponding to the first programming language, and run the annotated code to be processed on the target platform to obtain the target operation result.

9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory in communication with the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the code running method of the cross-platform programming language according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the code running method of a cross-platform programming language according to any one of claims 1 to 7 when executing the computer instructions.

Citation Information

Cited By

  • Code language conversion verification method and device, electronic equipment, storage medium and computer program product

    CN120803464A