CN113971027A - Code conversion method and device, computer equipment and storage medium - Google Patents

Code conversion method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN113971027A
CN113971027A CN202111250749.8A CN202111250749A CN113971027A CN 113971027 A CN113971027 A CN 113971027A CN 202111250749 A CN202111250749 A CN 202111250749A CN 113971027 A CN113971027 A CN 113971027A
Authority
CN
China
Prior art keywords
code
target
runtime
subcode
syntax specification
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111250749.8A
Other languages
Chinese (zh)
Inventor
向松涛
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing ByteDance Network Technology Co Ltd
Original Assignee
Beijing ByteDance Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing ByteDance Network Technology Co Ltd filed Critical Beijing ByteDance Network Technology Co Ltd
Priority to CN202111250749.8A priority Critical patent/CN113971027A/en
Publication of CN113971027A publication Critical patent/CN113971027A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The present disclosure provides a transcoding method, apparatus, computer device and storage medium, wherein the method comprises: acquiring a runtime code corresponding to a target runtime environment in a server; the runtime code includes a back-end code formed based on the first syntax specification and a front-end code formed based on the second syntax specification; the target operation environment is used for realizing the calling of the front terminal code to the rear terminal code; converting the post-terminal code into a target sub-code matching the second syntax specification based on the second syntax specification; determining a conversion code corresponding to the runtime code based on the target subcode and the front-end subcode; wherein the translation code is for running in a browser. The method and the device for converting the code into the browser code can accurately convert the code in the running process into the code capable of running in the browser, and ensure the accuracy of the obtained converted code.

Description

Code conversion method and device, computer equipment and storage medium
Technical Field
The present disclosure relates to the field of transcoding technologies, and in particular, to a transcoding method and apparatus, a computer device, and a storage medium.
Background
When Nodejs is used as a cross-platform JavaScript, the Nodejs comprises a front JavaScript code and a rear C + + code, a code module or application developed by the Nodejs can run in each operating system corresponding to a server, and the code module or application developed by the Nodejs cannot run in a browser accurately because the C + + code cannot be perfectly compatible in the browser.
In the prior art, in order to solve the above problem, a building tool (such as an abstract syntax tree) is generally used to convert the JavaScript code corresponding to the code module and the C + + code together into a code that can be run by the browser. However, since the JavaScript code is a dynamic language, the behavior of analyzing the JavaScript code by directly using the construction tool is a static analysis, which may result in that an accurate value of a part of dynamic variables in the JavaScript code may not be obtained, and further result in that an operation result of the converted code does not match an operation result corresponding to the original code module, thereby reducing the accuracy of code operation.
Disclosure of Invention
The embodiment of the disclosure at least provides a code conversion method, a code conversion device, computer equipment and a storage medium.
In a first aspect, an embodiment of the present disclosure provides a transcoding method, including:
acquiring a runtime code corresponding to a target runtime environment in a server; the runtime code includes a back-end code formed based on a first syntax specification and a front-end code formed based on a second syntax specification; the target operation environment is used for realizing the calling of the front terminal code to the rear terminal code;
converting the post-terminal code into a target sub-code matching the second syntax specification based on the second syntax specification;
determining conversion codes corresponding to the runtime codes based on the target subcodes and the front-end subcodes; wherein the translation code is for running in a browser.
In one possible embodiment, after determining the translation code, the method further comprises:
acquiring a target file corresponding to the target subcode from a server;
and storing the target file in an internal file system corresponding to the browser, so that the browser acquires the target file from the internal file system in the process of running the conversion code.
In a possible implementation, the converting the post-terminal code into a target sub-code matching the second syntax specification based on the second syntax specification includes:
and converting the post-terminal code into a target subcode matched with the second grammar specification based on the conversion relation between the second grammar specification and the first grammar specification by utilizing a preset code conversion tool.
In a possible implementation, the determining, based on the target subcode and the front-end subcode, a translation code corresponding to the runtime code includes:
and creating a code running environment corresponding to the running code, and determining the conversion code based on the code running environment, the target subcode and the front end subcode.
In a possible implementation manner, the creating a code execution environment corresponding to the runtime code includes:
determining at least one Application Program Interface (API) corresponding to the rear terminal code, and creating an independent operating environment corresponding to each API;
and creating a code operating environment corresponding to the operating code based on the independent operating environment corresponding to each API.
In a possible implementation, before the converting, based on the second syntax specification, the post-terminal code into a target sub-code matching the second syntax specification, the method further includes:
determining a target variable corresponding to the runtime code;
the determining, based on the target subcode and the front-end subcode, a translation code corresponding to the runtime code includes:
creating a Require demand module corresponding to the target variable;
and determining a conversion code corresponding to the runtime code based on the target subcode, the front-end subcode and the Require demand module.
In one possible implementation, the first syntax specification comprises a C + + syntax specification and the second syntax specification comprises a JavaScript syntax specification.
In a second aspect, an embodiment of the present disclosure further provides a transcoding apparatus, including:
the acquisition module is used for acquiring a runtime code corresponding to a target runtime environment in the server; the runtime code includes a back-end code formed based on a first syntax specification and a front-end code formed based on a second syntax specification; the target operation environment is used for realizing the calling of the front terminal code to the rear terminal code;
a conversion module for converting the post-terminal code into a target sub-code matching the second syntax specification based on the second syntax specification;
a first determining module, configured to determine, based on the target subcode and the front-end subcode, a conversion code corresponding to the runtime code; wherein the translation code is for running in a browser.
In a possible embodiment, the apparatus further comprises:
the storage module is used for acquiring a target file corresponding to the target subcode from a server after the conversion code is determined;
and storing the target file in an internal file system corresponding to the browser, so that the browser acquires the target file from the internal file system in the process of running the conversion code.
In a possible implementation manner, the conversion module is configured to convert the post-terminal code into a target sub-code matching the second syntax specification based on a conversion relationship between the second syntax specification and the first syntax specification by using a preset code conversion tool.
In a possible implementation manner, the first determining module is configured to create a code execution environment corresponding to the runtime code, and determine the conversion code based on the code execution environment, the target subcode, and the front-end subcode.
In a possible implementation manner, the first determining module is configured to determine at least one application program interface API corresponding to the backend code, and create, for each API, an independent operating environment corresponding to the API;
and creating a code operating environment corresponding to the operating code based on the independent operating environment corresponding to each API.
In one possible implementation, the apparatus further includes a second determining module:
the second determining module is configured to determine a target variable corresponding to the runtime code before the post-terminal code is converted into a target sub-code matching the second syntax specification based on the second syntax specification;
the first determining module is used for creating a Require demand module corresponding to the target variable;
and determining a conversion code corresponding to the runtime code based on the target subcode, the front-end subcode and the Require demand module.
In a third aspect, this disclosure also provides a computer device, a processor, and a memory, where the memory stores machine-readable instructions executable by the processor, and the processor is configured to execute the machine-readable instructions stored in the memory, and when the machine-readable instructions are executed by the processor, the machine-readable instructions are executed by the processor to perform the steps in the first aspect or any one of the possible implementations of the first aspect.
In a fourth aspect, this disclosure also provides a computer-readable storage medium having a computer program stored thereon, where the computer program is executed to perform the steps in the first aspect or any one of the possible implementation manners of the first aspect.
For the description of the effects of the transcoding apparatus, the computer device, and the computer-readable storage medium, reference is made to the description of the transcoding method, which is not repeated herein.
According to the code conversion method, the code conversion device, the computer equipment and the storage medium, the post-terminal codes formed based on the first grammar specification in the runtime codes are converted into the target subcodes matched with the second grammar specification, so that the converted target subcodes can run in a browser; then, conversion codes are obtained based on the target subcodes and the front-end subcodes, so that the codes during operation are converted into the conversion codes which support the operation in the browser, the front-end subcodes can be reserved, and the step of static analysis is avoided; the method is beneficial to accurately acquiring each dynamic variable corresponding to the front terminal code in the code conversion process, and the accuracy of the converted code obtained by conversion is improved.
In order to make the aforementioned objects, features and advantages of the present disclosure more comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings required for use in the embodiments will be briefly described below, and the drawings herein incorporated in and forming a part of the specification illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the technical solutions of the present disclosure. It is appreciated that the following drawings depict only certain embodiments of the disclosure and are therefore not to be considered limiting of its scope, for those skilled in the art will be able to derive additional related drawings therefrom without the benefit of the inventive faculty.
Fig. 1 shows a flowchart of a transcoding method provided by an embodiment of the present disclosure;
FIG. 2 is a flowchart illustrating an embodiment of transcoding provided by an embodiment of the present disclosure;
fig. 3 is a schematic diagram illustrating a transcoding device provided by an embodiment of the present disclosure;
fig. 4 shows a schematic structural diagram of a computer device provided by an embodiment of the present disclosure.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be described clearly and completely with reference to the drawings in the embodiments of the present disclosure, and it is obvious that the described embodiments are only a part of the embodiments of the present disclosure, not all of the embodiments. The components of embodiments of the present disclosure, as generally described and illustrated herein, may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present disclosure is not intended to limit the scope of the disclosure, as claimed, but is merely representative of selected embodiments of the disclosure. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the disclosure without making creative efforts, shall fall within the protection scope of the disclosure.
Furthermore, the terms "first," "second," and the like in the description and in the claims, and in the drawings described above, in the embodiments of the present disclosure are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It will be appreciated that the data so used may be interchanged under appropriate circumstances such that the embodiments described herein may be practiced otherwise than as specifically illustrated or described herein.
Reference herein to "a plurality or a number" means two or more. "and/or" describes the association relationship of the associated objects, meaning that there may be three relationships, e.g., a and/or B, which may mean: a exists alone, A and B exist simultaneously, and B exists alone. The character "/" generally indicates that the former and latter associated objects are in an "or" relationship.
Research shows that when Nodejs is used as a cross-platform JavaScript, the Nodejs comprises front-end JavaScript codes and rear-end C + + codes, a code module or application developed by the Nodejs can run in each operating system corresponding to a server, and the C + + codes cannot be perfectly compatible in a browser, so that the code module or application developed by the Nodejs cannot accurately run in the browser.
In the prior art, in order to solve the above problem, a building tool (such as an abstract syntax tree) is generally used to convert the JavaScript code corresponding to the code module and the C + + code together into a code that can be run by the browser. However, since the JavaScript code is a dynamic language, the behavior of analyzing the JavaScript code by directly using the construction tool is a static analysis, which may result in that an accurate value of a part of dynamic variables in the JavaScript code may not be obtained, and further result in that an operation result of the converted code does not match an operation result corresponding to the original code module, thereby reducing the accuracy of code operation.
Based on the above research, the present disclosure provides a code conversion method, apparatus, computer device, and storage medium, which may enable a target sub-code obtained by conversion to run on a browser by converting a back-end sub-code formed based on a first syntax specification in a run-time code into a target sub-code matching a second syntax specification; then, conversion codes are obtained based on the target subcodes and the front-end subcodes, so that the codes during operation are converted into the conversion codes which support the operation in the browser, the front-end subcodes can be reserved, and the step of static analysis is avoided; the method is beneficial to accurately acquiring each dynamic variable corresponding to the front terminal code in the code conversion process, and the accuracy of the converted code obtained by conversion is improved.
The above-mentioned drawbacks are the results of the inventor after practical and careful study, and therefore, the discovery process of the above-mentioned problems and the solutions proposed by the present disclosure to the above-mentioned problems should be the contribution of the inventor in the process of the present disclosure.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
It should be noted that specific terms mentioned in the embodiments of the present disclosure include:
js: the JavaScript operating environment based on Chrome V8 engine, node. js and applications or modules constructed by node. js can run in each operating system, but cannot run completely on a browser side.
And (3) iframe: is a tag of the hypertext markup language that acts as a document within a document, or as a floating frame. The iframe element may create an inline frame (i.e., inline frame) that contains another document;
webworker: as a new characteristic of the browser, the method has the function of creating a multi-thread environment for JavaScript, and can run in the browser;
serviceworker: having the role of acting as a proxy between the web application and the browser;
sharedworker: is a special webworker that may have communication functionality that supports multiple browser contexts, such as multiple windows, iframes.
To facilitate understanding of the present embodiment, a code conversion method disclosed in the embodiments of the present disclosure is first described in detail, where an execution subject of the code conversion method provided in the embodiments of the present disclosure is generally a computer device with certain computing capability, and in some possible implementations, the code conversion method may be implemented by a processor calling a computer-readable instruction stored in a memory.
The transcoding method provided by the embodiments of the present disclosure is described in detail below.
As shown in fig. 1, a flowchart of a transcoding method provided for an embodiment of the present disclosure may include the following steps:
s101: acquiring a runtime code corresponding to a target runtime environment in a server; the runtime code includes a back-end code formed based on the first syntax specification and a front-end code formed based on the second syntax specification; the target operating environment is used for realizing the calling of the front terminal code to the back terminal code.
Here, the target operating environment may be an operating environment corresponding to node. js, and is configured to implement calling of the front end code to the back end code, that is, when the front end code is executed in the target operating environment corresponding to the server, the front end code may call the back end code to obtain the information. The server is one end capable of running the runtime code corresponding to the target runtime environment.
The runtime code may be node.js code developed by a developer, for example, the runtime code may be code corresponding to a node.js application developed by the developer, code corresponding to a node.js module, and the like, and specifically, the runtime code may include a back-end code formed based on the first syntax specification and a front-end code formed based on the second syntax specification.
When the rear terminal code runs at the rear end, the rear end can communicate with an operating system corresponding to the service end, and when the front terminal code runs at the front end, the front end cannot directly communicate with the operating system corresponding to the service end. In a specific application, the front end and the back end can communicate with each other by using internalBindings. The internalBindings is a bridge for connecting a C + + end and a Javascript end in a Node standard library.
In one embodiment, the first syntax specification may include a c + + syntax specification, the code formed based on the c + + syntax specification has a function of communicating with an operating system, and the second syntax specification includes a JavaScript syntax specification. Here, since the code formed based on the c + + syntax specification has a function of communicating with the operating system corresponding to the server side, and the backend code in the node.
The browser does not support the running of the codes formed based on the first syntax specification, so that the running codes corresponding to the target running environment in the server cannot run in the browser.
In specific implementation, when there is a need to run the runtime code capable of being run by the server in the browser, the runtime code may be obtained first, and the runtime code may be converted by using subsequent steps, so that the converted runtime code may run in the browser.
S102: and converting the post-terminal code into a target sub-code matched with the second grammar specification based on the second grammar specification.
Here, the target subcode is a code obtained by transcoding the post-terminal code and having the same function as the post-terminal code, and is supported to run in the browser.
In specific implementation, after the runtime code is obtained, the backend terminal code in the runtime code may be determined, then, a conversion relationship between the second syntax specification and the first syntax specification is determined, and based on the conversion relationship, the backend terminal code is converted into the target subcode matched with the second syntax specification, that is, the backend terminal code is converted into the target subcode formed based on the second syntax specification.
S103: determining a conversion code corresponding to the runtime code based on the target subcode and the front-end subcode; wherein the translation code is for running in a browser.
Here, the converted code is a code obtained by converting the runtime code and having the same function as the runtime code, and can be run in the browser.
In specific implementation, the target sub-code and the front-end sub-code may be merged, and the merged code may be used as a conversion code.
Therefore, the rear terminal codes formed based on the first grammar specification in the runtime codes are converted into the target sub codes matched with the second grammar specification, the converted target sub codes can be operated in the browser, and the converted codes are obtained based on the target sub codes and the front terminal codes, so that the runtime codes are converted into the converted codes supporting the operation in the browser, the reservation of the front terminal codes can be realized, the step of static analysis is avoided, each dynamic variable corresponding to the front terminal codes can be accurately obtained in the code conversion process, and the accuracy of the converted codes is improved.
In an embodiment, after the translation code is determined, an object file corresponding to the object subcode may be further obtained from the server.
Here, the server stores an object file corresponding to the object sub-code, that is, stores an object file corresponding to the rear sub-code; the target file is a local file of the server, can be acquired by a back end corresponding to a back-end code formed based on the first syntax specification, and is a file required by the operation of the unconverted runtime code. Specifically, the target file may include a variable file, a data file, and the like, and also a file required for operating the target subcode and the front subcode corresponding to the conversion code.
In specific implementation, since the translation code needs to be run in the browser and the target file is not stored in the memory corresponding to the browser, in order to ensure that the translation code can be accurately run in the browser, the target file corresponding to the target subcode needs to be acquired from the server.
Further, the target file may be stored in an internal file system corresponding to the browser, so that the browser obtains the target file from the internal file system in the process of running the conversion code.
Here, the internal file system is a system for implementing file storage, and can be applied to a browser, and specifically, the internal file system may be a file system obtained by using memfs technology. The memfs is equal to a memory-file system, and a memory file system is a disk operating system simulated in a memory, and because the speed of reading a disk is much slower than that of reading the memory, the memory file system can be used as a storage medium in a scene that files need to be read and written frequently.
The file system obtained by using the memfs technology and the node.js fs proprietary API (Application Programming Interface) part corresponding to the target subcode have the same implementation, that is, have the same function as the node.js fs proprietary API part. Node.js fs is equal to node.js file system, and corresponds to the proprietary API of node.js, which can be used for calling node.js fs at the back end to obtain files.
In specific implementation, after the target file is obtained, the target file can be stored in an internal file system corresponding to the browser, so that the target file is stored in the browser, and the target file can be directly obtained from the internal file system in the process of running the conversion code by the subsequent browser, so that the accurate running of the conversion code is realized.
In addition, the steps of acquiring the target file and storing the target file in the internal file system corresponding to the browser provided by the embodiment of the present disclosure are not limited to being executed after the converted code is obtained, and may also be executed at any time after the post-terminal code is determined, and are not limited herein.
In one embodiment, for S102, the post-terminal code may be converted into a target sub-code matching the second syntax specification based on a conversion relationship between the second syntax specification and the first syntax specification by using a preset code conversion tool.
Here, the preset transcoding tool may be any transcoding tool having transcoding capability, and is not limited herein. In specific implementation, after the post-terminal code is determined, the post-terminal code may be input to a preset code conversion tool, and the post-terminal code is converted into a target sub-code matched with the second syntax specification based on a conversion relation between the second syntax specification and the first syntax specification by using the preset code conversion tool.
Alternatively, in one embodiment, after the post-end code is obtained, the post-end code may be manually converted into the target sub-code by a developer based on a conversion relationship between the second syntax specification and the first syntax specification.
In one embodiment, for S103, after obtaining the target subcode, a code execution environment corresponding to the runtime code may be created, and the conversion code may be determined based on the code execution environment, the target subcode, and the front-end subcode.
Here, the code execution environment is used for characterizing the operation process of the runtime code when the runtime code runs on the server side. In particular implementations, the code execution environment may include, but is not limited to, the following: and generating protection of global variables corresponding to the runtime codes and the proprietary API of the node.
In specific implementation, after the target subcode is obtained, a code running environment of the runtime code when running at the server can be determined, specifically, a global variable corresponding to the runtime code and a proprietary API of node. Then, a global variable corresponding to the runtime code can be generated and the proprietary API of node. Then, the target subcode and the front-end subcode can be merged based on the code running environment to obtain the conversion code.
In an embodiment, the step of protecting the node.js fs proprietary API in the code runtime environment corresponding to the runtime code may be implemented according to the following steps:
step one, determining at least one application program interface API corresponding to the rear terminal code, and aiming at each API, creating an independent operation environment corresponding to the API.
Here, the application program interface API corresponding to the backend code may be a proprietary API of node. The independent operation environment is an API operation environment which can be provided by the browser, and in the API operation environment provided by the browser, the API corresponding to the rear terminal code can be operated independently. Specifically, the independent operation environment may be an iframe, a webworker, a serviceworker, a sharedworker, or the like.
In specific implementation, after the back-end terminal code is obtained, the sub-code may be analyzed to determine that the back-end terminal code corresponds to each node module and a node.js fs specific API that each node module needs to use, so that at least one application program interface API corresponding to the back-end terminal code may be obtained.
Then, for each API, an independent operating environment corresponding to the API when the server runs may be determined, and then the independent operating environment corresponding to the API when the server runs may be converted into an independent operating environment that can be provided by the browser, so as to complete the creation of the independent operating environment corresponding to the API.
Therefore, based on the created independent operation environment, on the basis of ensuring that the API can independently operate in the browser, the protection of the API corresponding to the rear terminal code can be realized.
And secondly, creating a code operating environment corresponding to the operating code based on the independent operating environment corresponding to each API.
Here, the created independent runtime environment corresponding to each API may be used as a code runtime environment corresponding to the runtime code.
In one embodiment, before converting the post-terminal code into the target subcode, determining a target variable corresponding to the runtime code is further included.
Here, the target variable corresponding to the runtime code is each variable included in the runtime code, and a value corresponding to the target variable may change dynamically during the runtime code. Different target variables may correspond to different node modules.
In specific implementation, the runtime code may be analyzed to determine each target variable included in the runtime code.
Further, translation code corresponding to the runtime code may be determined based on the target variable, the target subcode, and the front-end subcode. Specifically, for each target variable, a Require demand module corresponding to the target variable may be created, that is, a Require module of a node module corresponding to the target variable is created, so as to load the node module in the browser, and after the Require demand module corresponding to the target variable is created, the Require demand module may be initialized.
The requiredemand module can include a module code, and the requiredemand module can be used for loading a node module corresponding to the conversion code. In addition, the step of creating the Require demand module corresponding to the target variable may be performed after the target variable is determined.
And then, combining the module code, the front terminal code and the rear terminal code corresponding to the created Require demand module to obtain a conversion code corresponding to the runtime code.
As shown in fig. 2, a flowchart for implementing transcoding provided by an embodiment of the present disclosure may include the following steps:
s201: and acquiring a runtime code corresponding to the target runtime environment in the server.
Wherein the runtime code includes a back-end code formed based on the first syntax specification and a front-end code formed based on the second syntax specification.
S202: and determining a target variable corresponding to the runtime code, and creating a demand module corresponding to the target variable.
During specific implementation, the runtime code may be analyzed, each target variable included in the runtime code is determined, and a Require demand module corresponding to the target variable is created.
S203: and converting the rear terminal code into a target subcode matched with the second grammar specification based on the conversion relation between the second grammar specification and the first grammar specification by utilizing a preset code conversion tool.
S204: and determining at least one Application Program Interface (API) corresponding to the rear terminal code, and creating an independent operating environment corresponding to each API.
S205: and creating a code operating environment corresponding to the operating code based on the independent operating environment corresponding to each API.
S206: and determining conversion codes corresponding to the runtime codes based on the target subcodes, the front-end subcodes and the requirement modules.
S207: and acquiring a target file corresponding to the target subcode from the server, and storing the target file in an internal file system corresponding to the browser, so that the browser acquires the target file from the internal file system in the process of running the conversion code.
Here, S207 and S202 to S206 are not strictly performed in this order.
For specific implementation processes of S201 to S207, reference may be made to the above embodiments, and details are not described here.
It will be understood by those skilled in the art that in the method of the present invention, the order of writing the steps does not imply a strict order of execution and any limitations on the implementation, and the specific order of execution of the steps should be determined by their function and possible inherent logic.
Based on the same inventive concept, a code conversion apparatus corresponding to the code conversion method is also provided in the embodiments of the present disclosure, and since the principle of the apparatus in the embodiments of the present disclosure for solving the problem is similar to the code conversion method described above in the embodiments of the present disclosure, the implementation of the apparatus may refer to the implementation of the method, and repeated details are not described again.
As shown in fig. 3, a schematic diagram of a transcoding device provided for an embodiment of the present disclosure includes:
an obtaining module 301, configured to obtain a runtime code corresponding to a target runtime environment in a server; the runtime code comprises a back-end code formed based on a first syntax specification and the front-end code formed based on a second syntax specification; the target operation environment is used for realizing the calling of the front terminal code to the rear terminal code;
a conversion module 302, configured to convert the post-terminal code into a target sub-code matching the second syntax specification based on the second syntax specification;
a first determining module 303, configured to determine, based on the target subcode and the front-end subcode, a conversion code corresponding to the runtime code; wherein the translation code is for running in a browser.
In a possible embodiment, the apparatus further comprises:
the storage module 304 is configured to obtain, from the server, a target file corresponding to the target sub-code after determining the conversion code;
and storing the target file in an internal file system corresponding to the browser, so that the browser acquires the target file from the internal file system in the process of running the conversion code.
In a possible implementation manner, the converting module 302 is configured to convert the post-terminal code into a target sub-code matching the second syntax specification based on a conversion relationship between the second syntax specification and the first syntax specification by using a preset code conversion tool.
In a possible implementation manner, the first determining module 303 is configured to create a code execution environment corresponding to the runtime code, and determine the conversion code based on the code execution environment, the target subcode, and the front-end subcode.
In a possible implementation manner, the first determining module 303 is configured to determine at least one application program interface API corresponding to the backend code, and create, for each API, an independent operating environment corresponding to the API;
and creating a code operating environment corresponding to the operating code based on the independent operating environment corresponding to each API.
In a possible implementation, the apparatus further includes a second determining module 305:
the second determining module 305 is configured to determine a target variable corresponding to the runtime code before the post-terminal code is converted into a target sub-code matching the second syntax specification based on the second syntax specification;
the first determining module 303 is configured to create a Require demand module corresponding to the target variable;
and determining a conversion code corresponding to the runtime code based on the target subcode, the front-end subcode and the Require demand module.
The description of the processing flow of each module in the device and the interaction flow between the modules may refer to the related description in the above method embodiments, and will not be described in detail here.
An embodiment of the present disclosure further provides a computer device, as shown in fig. 4, which is a schematic structural diagram of a computer device provided in an embodiment of the present disclosure, and the computer device includes:
a processor 41 and a memory 42; the memory 42 stores machine-readable instructions executable by the processor 41, the processor 41 being configured to execute the machine-readable instructions stored in the memory 42, the processor 41 performing the following steps when the machine-readable instructions are executed by the processor 41: s101: acquiring a runtime code corresponding to a target runtime environment in a server; the runtime code includes a back-end code formed based on the first syntax specification and a front-end code formed based on the second syntax specification; the target operation environment is used for realizing the calling of the front terminal code to the rear terminal code; s102: based on the second syntax specification, the post-terminal code is converted into a target sub-code matching the second syntax specification and S103: determining a conversion code corresponding to the runtime code based on the target subcode and the front-end subcode; wherein the translation code is for running in a browser.
The storage 42 includes a memory 421 and an external storage 422; the memory 421 is also referred to as an internal memory, and temporarily stores operation data in the processor 41 and data exchanged with the external memory 422 such as a hard disk, and the processor 41 exchanges data with the external memory 422 via the memory 421.
For the specific execution process of the above instruction, reference may be made to the steps of the code conversion method described in the embodiments of the present disclosure, and details are not described here.
The embodiments of the present disclosure also provide a computer-readable storage medium, on which a computer program is stored, where the computer program is executed by a processor to perform the steps of the code conversion method described in the above method embodiments. The storage medium may be a volatile or non-volatile computer-readable storage medium.
The computer program product of the transcoding method provided in the embodiments of the present disclosure includes a computer-readable storage medium storing a program code, where instructions included in the program code may be used to execute steps of the transcoding method described in the above method embodiments, which may be referred to specifically in the above method embodiments, and are not described herein again.
The computer program product may be embodied in hardware, software or a combination thereof. In an alternative embodiment, the computer program product is embodied in a computer storage medium, and in another alternative embodiment, the computer program product is embodied in a Software product, such as a Software Development Kit (SDK), or the like.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working process of the apparatus described above may refer to the corresponding process in the foregoing method embodiment, and is not described herein again. In the several embodiments provided in the present disclosure, it should be understood that the disclosed apparatus and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implementing, and for example, a plurality of units or components may be combined, or some features may be omitted, or not implemented. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present disclosure may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such understanding, the technical solution of the present disclosure may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present disclosure. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
Finally, it should be noted that: the above-mentioned embodiments are merely specific embodiments of the present disclosure, which are used for illustrating the technical solutions of the present disclosure and not for limiting the same, and the scope of the present disclosure is not limited thereto, and although the present disclosure is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can modify or easily conceive of the technical solutions described in the foregoing embodiments or equivalent technical features thereof within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present disclosure, and should be construed as being included therein. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.

Claims (10)

1. A method of transcoding, comprising:
acquiring a runtime code corresponding to a target runtime environment in a server; the runtime code includes a back-end code formed based on a first syntax specification and a front-end code formed based on a second syntax specification; the target operation environment is used for realizing the calling of the front terminal code to the rear terminal code;
converting the post-terminal code into a target sub-code matching the second syntax specification based on the second syntax specification;
determining conversion codes corresponding to the runtime codes based on the target subcodes and the front-end subcodes; wherein the translation code is for running in a browser.
2. The method of claim 1, wherein after determining the translation code, the method further comprises:
acquiring a target file corresponding to the target subcode from a server;
and storing the target file in an internal file system corresponding to the browser, so that the browser acquires the target file from the internal file system in the process of running the conversion code.
3. The method of claim 1, wherein said converting the post-end code into a target sub-code matching the second syntax specification based on the second syntax specification comprises:
and converting the post-terminal code into a target subcode matched with the second grammar specification based on the conversion relation between the second grammar specification and the first grammar specification by utilizing a preset code conversion tool.
4. The method of claim 1, wherein determining translation code corresponding to the runtime code based on the target subcode and the front-end subcode comprises:
and creating a code running environment corresponding to the running code, and determining the conversion code based on the code running environment, the target subcode and the front end subcode.
5. The method of claim 4, wherein the creating a code runtime environment corresponding to the runtime code comprises:
determining at least one Application Program Interface (API) corresponding to the rear terminal code, and creating an independent operating environment corresponding to each API;
and creating a code operating environment corresponding to the operating code based on the independent operating environment corresponding to each API.
6. The method of claim 1, wherein prior to said converting the post-end code to a target sub-code matching the second syntax specification based on the second syntax specification, further comprising:
determining a target variable corresponding to the runtime code;
the determining, based on the target subcode and the front-end subcode, a translation code corresponding to the runtime code includes:
creating a Require demand module corresponding to the target variable;
and determining a conversion code corresponding to the runtime code based on the target subcode, the front-end subcode and the Require demand module.
7. The method of claim 1, wherein the first syntax specification comprises a C + + syntax specification and wherein the second syntax specification comprises a JavaScript syntax specification.
8. A transcoding apparatus, comprising:
the acquisition module is used for acquiring a runtime code corresponding to a target runtime environment in the server; the runtime code includes a back-end code formed based on a first syntax specification and a front-end code formed based on a second syntax specification; the target operation environment is used for realizing the calling of the front terminal code to the rear terminal code;
a conversion module for converting the post-terminal code into a target sub-code matching the second syntax specification based on the second syntax specification;
a first determining module, configured to determine, based on the target subcode and the front-end subcode, a conversion code corresponding to the runtime code; wherein the translation code is for running in a browser.
9. A computer device, comprising: a processor, a memory storing machine-readable instructions executable by the processor, the processor for executing the machine-readable instructions stored in the memory, the processor performing the steps of the transcoding method of any of claims 1 to 7 when the machine-readable instructions are executed by the processor.
10. A computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, which computer program, when executed by a computer device, performs the steps of the transcoding method of any of claims 1 to 7.
CN202111250749.8A 2021-10-26 2021-10-26 Code conversion method and device, computer equipment and storage medium Pending CN113971027A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111250749.8A CN113971027A (en) 2021-10-26 2021-10-26 Code conversion method and device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111250749.8A CN113971027A (en) 2021-10-26 2021-10-26 Code conversion method and device, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN113971027A true CN113971027A (en) 2022-01-25

Family

ID=79588472

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111250749.8A Pending CN113971027A (en) 2021-10-26 2021-10-26 Code conversion method and device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113971027A (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104463002A (en) * 2014-12-24 2015-03-25 北京奇虎科技有限公司 APK reinforcing method and device and APK reinforcing client and server
CN108388454A (en) * 2018-01-24 2018-08-10 广州市动景计算机科技有限公司 Dynamic provides the method, apparatus and terminal device of compatible JS content for script
CN108494742A (en) * 2018-03-05 2018-09-04 杭州泰酷科技有限公司 A kind of web data encrypted transmission mode applied to browser
CN110889054A (en) * 2019-11-22 2020-03-17 苏州浪潮智能科技有限公司 Online preview method and device for front-end and back-end separation Web system
CN111651165A (en) * 2020-05-18 2020-09-11 深圳市大富网络技术有限公司 Integration method of programming language, programming software system and electronic device
CN112015430A (en) * 2020-09-07 2020-12-01 平安国际智慧城市科技股份有限公司 JavaScript code translation method and device, computer equipment and storage medium
CN112379917A (en) * 2020-11-19 2021-02-19 康键信息技术(深圳)有限公司 Browser compatibility improving method, device, equipment and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104463002A (en) * 2014-12-24 2015-03-25 北京奇虎科技有限公司 APK reinforcing method and device and APK reinforcing client and server
CN108388454A (en) * 2018-01-24 2018-08-10 广州市动景计算机科技有限公司 Dynamic provides the method, apparatus and terminal device of compatible JS content for script
CN108494742A (en) * 2018-03-05 2018-09-04 杭州泰酷科技有限公司 A kind of web data encrypted transmission mode applied to browser
CN110889054A (en) * 2019-11-22 2020-03-17 苏州浪潮智能科技有限公司 Online preview method and device for front-end and back-end separation Web system
CN111651165A (en) * 2020-05-18 2020-09-11 深圳市大富网络技术有限公司 Integration method of programming language, programming software system and electronic device
CN112015430A (en) * 2020-09-07 2020-12-01 平安国际智慧城市科技股份有限公司 JavaScript code translation method and device, computer equipment and storage medium
CN112379917A (en) * 2020-11-19 2021-02-19 康键信息技术(深圳)有限公司 Browser compatibility improving method, device, equipment and storage medium

Similar Documents

Publication Publication Date Title
US9678726B1 (en) Automatic generation of plugins for development tools
CN110580147B (en) Application program development method and device
CN107402746B (en) Method and device for automatically generating code file
CN109086215B (en) Embedded software unit test case generation method and system
CN110502520B (en) Method, system and equipment for data warehousing and computer readable storage medium
US20150269052A1 (en) Method and apparatus for supporting performance analysis
CN110955409B (en) Method and device for creating resources on cloud platform
CN110888645A (en) Method, device and storage medium for converting into small program
CN111880801A (en) Application program dynamic method and device and electronic equipment
CN113918195A (en) Application interface updating method and device, electronic equipment and readable storage medium
CN111736812A (en) Document code execution method and device, computer equipment and storage medium
CN110737431B (en) Software development method, development platform, terminal device and storage medium
CN113760266B (en) Method and device for creating function module file and electronic equipment
US11604662B2 (en) System and method for accelerating modernization of user interfaces in a computing environment
CN112925523B (en) Object comparison method, device, equipment and computer readable medium
CN112328241B (en) Method and device for creating Android library module dependency relationship in application program development
CN113934429A (en) Design draft conversion method and device, computer equipment and storage medium
CN107025233B (en) Data feature processing method and device
CN113971027A (en) Code conversion method and device, computer equipment and storage medium
KR20150047940A (en) Method and device for analyzing an application
CN114968200A (en) Software development kit assembly method, related device and computer program product
CN116150527A (en) Component style isolation method, device, equipment, storage medium and product
CN115757287A (en) Target file construction method and device and storage medium
CN114706586A (en) Code compiling method, code running method, code compiling device, code running device, computer equipment and storage medium
CN115048082A (en) Micro front-end system construction method and device, server and readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information
CB02 Change of applicant information

Address after: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant after: Douyin Vision Co.,Ltd.

Address before: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant before: Tiktok vision (Beijing) Co.,Ltd.

Address after: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant after: Tiktok vision (Beijing) Co.,Ltd.

Address before: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant before: BEIJING BYTEDANCE NETWORK TECHNOLOGY Co.,Ltd.