CN108920133B - Cross-language programming method and device, electronic equipment and storage medium - Google Patents

Cross-language programming method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN108920133B
CN108920133B CN201810615055.1A CN201810615055A CN108920133B CN 108920133 B CN108920133 B CN 108920133B CN 201810615055 A CN201810615055 A CN 201810615055A CN 108920133 B CN108920133 B CN 108920133B
Authority
CN
China
Prior art keywords
language
runtime
information
meta
runtime environment
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.)
Active
Application number
CN201810615055.1A
Other languages
Chinese (zh)
Other versions
CN108920133A (en
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 Sankuai Online Technology Co Ltd
Original Assignee
Beijing Sankuai Online 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 Sankuai Online Technology Co Ltd filed Critical Beijing Sankuai Online Technology Co Ltd
Priority to CN201810615055.1A priority Critical patent/CN108920133B/en
Publication of CN108920133A publication Critical patent/CN108920133A/en
Priority to PCT/CN2018/121763 priority patent/WO2019237701A1/en
Application granted granted Critical
Publication of CN108920133B publication Critical patent/CN108920133B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/20Software design
    • G06F8/24Object-oriented

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The application discloses a cross-language programming method, belongs to the technical field of computers, and solves the problem that in the prior art, the cross-language programming method has low coding efficiency. The cross-language programming method disclosed by the embodiment of the application comprises the following steps: the method comprises the steps of obtaining running time meta-information of a first language program included in a target file, mapping the running time meta-information to a running time environment constructed based on a second language, and calling the running time meta-information mapped in the running time environment through the second language in the running time environment. According to the cross-language programming method disclosed by the embodiment of the application, the built runtime environment is used for packaging and mapping the calling of the meta-information such as the functions or methods of different languages, so that an additional language conversion tool is not needed during cross-language programming, the development process of the cross-language programming is simplified, and the efficiency of the cross-language programming is improved.

Description

Cross-language programming method and device, electronic equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a cross-language programming method and apparatus, an electronic device, and a storage medium.
Background
With the development of computer technology, programming languages and hardware platforms are in a wide range, and different modules of an application program can be generally realized by programming in different languages, so that cross-language programming is always an urgent problem to be solved in the field of computers. A common cross-language programming method in the prior art is to implement a set of grammar rules of a specific language to write software, and convert the specific language into other languages by a conversion tool through abstracting the same thought part of multiple languages, so as to finally obtain a target file of the same language.
Therefore, the cross-language programming method in the prior art needs an additional conversion tool to perform source program conversion, which is not beneficial to improving the coding efficiency.
Disclosure of Invention
The application provides a cross-language programming method, which at least solves the problem of low coding efficiency of the cross-language programming method in the prior art.
In order to solve the above problem, in a first aspect, an embodiment of the present application provides a cross-language programming method, including:
acquiring running time meta information of a first language program included in a target file;
mapping the runtime meta information to a runtime environment constructed based on a second language;
invoking the runtime meta-information mapped in the runtime environment through a second language in the runtime environment.
In a second aspect, an embodiment of the present application provides a cross-language programming apparatus, including:
the running meta-information acquisition module is used for acquiring running meta-information of a first language program included in the target file;
the meta-information mapping module is used for mapping the runtime meta-information to a runtime environment constructed based on a second language;
and the runtime environment working module is used for calling the runtime meta-information mapped in the runtime environment through a second language in the runtime environment.
In a third aspect, an embodiment of the present application further discloses an electronic device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor, where the processor implements the cross-language programming method described in the embodiment of the present application when executing the computer program.
In a fourth aspect, the present application provides a computer-readable storage medium, on which a computer program is stored, which, when executed by a processor, performs the steps of the cross-language programming method disclosed in the embodiments of the present application.
According to the cross-language programming method disclosed by the embodiment of the application, the running time meta-information of the first language program included in the target file is acquired and mapped to the running time environment constructed based on the second language, and the running time meta-information mapped in the running time environment is called through the second language in the running time environment, so that cross-language program calling is realized, and the problem that the cross-language programming method in the prior art is low in coding efficiency is solved. According to the cross-language programming method disclosed by the embodiment of the application, the built runtime environment is used for packaging and mapping the calling of the meta-information such as the functions or methods of different languages, so that an additional language conversion tool is not needed during cross-language programming, the development process of the cross-language programming is simplified, and the efficiency of the cross-language programming is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
FIG. 1 is a flowchart of a cross-language programming method according to a first embodiment of the present application;
FIG. 2 is a flowchart of a cross-language programming method according to a second embodiment of the present application;
FIG. 3 is a flowchart of a cross-language programming method according to a third embodiment of the present application;
FIG. 4 is a schematic structural diagram of a cross-language programming device according to a fourth embodiment of the present application;
fig. 5 is a second schematic structural diagram of a cross-language programming device according to a fourth embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some, but not all, embodiments of the present application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Example one
As shown in fig. 1, the cross-language programming method disclosed in this embodiment includes: step 110 to step 130.
Step 110, obtaining the runtime meta information of the first language program included in the target file.
In the prior art, a runtime environment (runtime environment) refers to an environment in which semi-compiled execution code is executed on a target machine, and currently, some interpreted languages can be executed and dynamically updated through the runtime environment. The runtime environment and the application program described in the embodiments of the present application are released in an integrated manner, and an environment for realizing cross-language calling is created by executing a section of cross-platform language code. When the method is specifically implemented, a runtime environment is constructed and used for managing the meta-information of different language types in the application program when the application program runs, so that cross-language calling is realized.
The first language and the second language described in the embodiments of the present application generally refer to two different languages, and the first language program refers to a program written in the first language. When the application is implemented, firstly, a runtime environment needs to be constructed based on a second language (such as a cross-platform language C), including: defining and constructing a data structure meeting the requirement of storing at least one type of running time meta-information of the first language, defining a memory model, realizing a calling interface corresponding to the first language according to the grammatical characteristics of the first language, constructing a second language method calling rule and the like. For the first language with reflective capabilities, reflective capabilities also need to be created.
The runtime meta information described in the embodiments of the present application includes: the basic unit called when the programs such as functions, classes, methods and the like run. In specific implementation, it is assumed that an application program is developed based on two languages, and program codes of each language are stored in different program source program files. After the source program files of different languages are compiled, different target files are generated, and in this embodiment, target files corresponding to two languages are generated. In specific implementation, after a program source program file is compiled, a compiler generates runtime meta information included in the source program file, such as a list of functions, methods, and the like included in the source program file, and the runtime meta information included in the source program file can be obtained by analyzing the file generated by the compiler and compiled into a prediction data segment of a target file. If the source program file cannot be obtained, for example, for a library file, a general library file or an interface opened to the library file through a corresponding header file is declared, in specific implementation, the runtime meta information of the corresponding language source program included in the library file may be obtained according to the header file corresponding to the library file, and further, a bridge file from the library file to a runtime environment is generated based on the runtime meta information, where the bridge file includes function name mapping, method encapsulation, and the like, and the bridge file is compiled into a target file.
And in the running process of the application program, analyzing the target file of the application program through the guide device to obtain the running time meta-information.
And step 120, mapping the runtime meta information to a runtime environment constructed based on a second language.
In specific implementation, the runtime environment constructed based on the second language is assigned with the runtime meta-information of the first language, and the runtime meta-information of the first language is mapped to the runtime environment constructed based on the second language.
Step 130, invoking the runtime meta information mapped in the runtime environment through a second language in the runtime environment.
Then, the runtime meta information of different languages mapped in the runtime environment is called by executing codes written in a second language corresponding to the runtime environment, so that cross-language program calling is realized.
According to the cross-language programming method disclosed by the embodiment of the application, the running time meta-information of the first language program included in the target file is acquired and mapped to the running time environment constructed based on the second language, and the running time meta-information mapped in the running time environment is called through the second language in the running time environment, so that cross-language program calling is realized, and the problem that the cross-language programming method in the prior art is low in coding efficiency is solved. According to the cross-language programming method disclosed by the embodiment of the application, the built runtime environment is used for packaging and mapping the calling of the meta-information such as the functions or methods of different languages, so that an additional language conversion tool is not needed during cross-language programming, the development process of the cross-language programming is simplified, and the efficiency of the cross-language programming is improved.
Example two
As shown in fig. 2, the cross-language programming method disclosed in this embodiment includes: step 210 to step 270.
Step 210, building a runtime environment based on the second language.
The runtime environment and the application program described in the embodiments of the present application are released in an integrated manner, and an environment for realizing cross-language calling is created by executing a section of cross-platform language code. When the method is specifically implemented, a runtime environment is constructed and used for managing the meta-information of different language types in the application program when the application program runs, so that cross-language calling is realized. The first language and the second language described in the embodiments of the present application broadly refer to two different languages.
In specific implementation, before mapping the runtime meta information to a runtime environment constructed based on a second language, the method further includes: a runtime environment is constructed based on the second language. In specific implementation, the building of the runtime environment based on the second language further includes executing the following operations based on the second language: constructing a data structure which stores the runtime meta information of at least one first language; defining a memory model; according to the grammatical features of the first language, realizing a calling interface corresponding to the first language; creating a reflective capability; and constructing a second language method calling rule. In specific implementation, the second language is a cross-platform language.
When the runtime environment is constructed, firstly, the thought and the grammatical characteristics of each language are analyzed for a plurality of programming languages used by the current application program, and a union set is taken, so that a corresponding calling or analyzing interface is set in the runtime environment.
Then, a generic data structure that can satisfy the requirements for storing runtime meta information of the several programming languages, a memory model for defining columns, calling rules, etc. are defined.
In defining a common data structure that satisfies the requirements for storing runtime meta information for the plurality of programming languages, the method may include defining: and the structures comprise a class sc _ class, an interface sc _ interface, a function sc _ method, a variable sc _ ivar and the like. The sc _ class structure comprises information such as class names, variable lists, method lists and the like; the sc _ interface structure comprises information such as interface names, interface methods and the like; sc _ method contains information such as method name and function address; sc _ ivar contains information such as variable name and variable type. The data structure may be represented as follows:
Figure BDA0001696698610000051
Figure BDA0001696698610000061
defining the memory model of the classes, and enabling the classes to have the capabilities of inheritance, polymorphism and the like.
For languages with reflective capabilities, reflective capabilities need to be created, including: defining methods such as creating class, instantiating class object, adding class method, adding instance variable, etc. for executing dynamic operation language in runtime. For example, a class is defined by the following code:
bool sc_define_method(SCClass cls,const char*name,SC_METHOD_IMP imp)。
the class method is defined by the following code:
bool sc_define_class_method(SCClass cls,const char*name,SC_METHOD_IMP imp)。
example variables are defined by the following code:
void sc_define_attr(SCClass cls,const char*name)。
in specific implementation, for a characteristic method unique to a certain language, a calling interface is realized and provided through second language coding.
In specific implementation, when constructing the second language method invocation rule, the method may include: for function call initiated to any instance object, firstly, searching whether 'function address' exists in a method list of the class structure sc _ class, and if so, immediately calling; if not, searching 'function address' from the method list of the parent class layer by layer, and recursing in sequence until the base class is searched. If no method is found until the base class, a method-missing handling routine is called or an exception is thrown.
Step 220, generating a data structure of the runtime environment according to the first language source program by customizing the compiler front-end.
Before the obtaining of the runtime meta information of the first language program included in the target file, the method further includes: a data structure of a runtime environment is generated from a first language source program by customizing a compiler front-end. In specific implementation, the generating, by the customized compiler front end, the data structure of the runtime environment according to the first language source program includes: mapping the runtime meta information in the first language source program to a data structure of the runtime environment, and compiling the data structure to a preset data segment of a target file of the first language source program.
A "customized compiler front-end" is a compiler front-end for each of several programming languages that are used by the current application. Customizing the process from a source program to a runtime environment language, mapping information such as class structures, interfaces and the like to a structural body of a general runtime environment, and compiling the information to a custom binary segment of a target file. In specific implementation, mapping runtime meta information in a first language source program to a data structure of the runtime environment, including but not limited to: writing list information of all classes in the first language source program into an '__ sc _ class' section of the runtime environment, converting the structure of the classes in the first language source program into an sc _ class of the runtime environment definition, converting the structure of the functions in the first language source program into a method sc _ method of the runtime environment definition, and converting the structure of the instance variables in the first language source program into variables sc _ ivar of the runtime environment definition.
In specific implementation, for the class inherited from the first language library, except for compiling through the "customized compiler front end", the class structure of the first language still needs to be generated and compiled into the binary segment of the source language target file. For a method inheriting a class from a first language library, the input parameters are of a first language object and need to be converted to runtime objects; for a class method in the first language, the input parameters are run-time objects and need to be converted to the first language object.
And mapping the function call or message forwarding of the first language to a call entry "_ sc _ funcminvoke" of the universal runtime according to the call rule for constructing the second language method.
In this embodiment, the first language is taken as a C + + language for example, and assuming that the first language source program storage file is foo.
Figure BDA0001696698610000081
After the first language source program passes through the front end of the customized compiler, Foo type information in the source program is written into an __ sc _ classlst segment according to the sc _ class structure, a method "hello" of the Foo type is written into a __ sc _ methodist segment according to the sc _ method structure, and a method call f.hello () in the first language source program is mapped to a call entry "_ sc _ funcvanswer" of a runtime environment. Finally, codes and data structures of the Foo.cpp and the runtime environment are compiled through a customized compiler front end to generate an intermediate language file Foo.ll, and a target file Foo.o is generated through a compiler rear end.
In specific implementation, when a code of a certain programming language of an application program includes a binary file such as a library file, before the obtaining of the runtime meta information of the first language program included in the target file, the method further includes:
step 230, generating a bridging source program of the runtime environment calling runtime meta information in the library file according to an interface definition file of a first language library file;
and 240, compiling the bridging source program through a preset compiler to obtain a target file comprising the running time meta information of the first language program.
In a specific implementation, each library file corresponds to a header file for declaring an open interface, for example, the header file bar.h of the following library file bar.lib.
Figure BDA0001696698610000082
Figure BDA0001696698610000091
Through the header files corresponding to the library files, the running meta-information of classes, functions, methods and the like in the library files can be obtained. Lib includes class Bar and method func, for example. In specific implementation, transparent forwarding of method calls inside the runtime environment to the library file can be realized through the interface bridge. An "interface bridge" is used to bridge the existing interface of each 'library file' to the runtime environment so that the runtime environment can call methods into the library file. In specific implementation, according to an interface definition file of a first language library file, generating a bridging source program of the runtime environment calling runtime meta information in the library file: the method comprises the following steps: acquiring an abstract syntax tree of a library file interface, traversing the abstract syntax tree, sequentially traversing each class, and realizing each open interface through a second language; performing positive and negative bidirectional conversion on the runtime object and the first language object structure; combining a first language object in the runtime object structure, and simultaneously creating a first language object consistent with a first language memory structure when creating the runtime object; when the first language object is needed, unpacking the runtime object, and when the runtime object is needed, packing the first language object. Finally, a second language source code file containing the implementation is generated.
For example, bar.h is bridged, an abstract syntax tree of bar.h is firstly obtained, two classes of Base and Bar are analyzed, then an open interface of the two classes is realized, and Cpp objects and runtime objects are converted for input parameters and output parameters. Scb, a second language source code file bar, is generated, for example as follows:
Figure BDA0001696698610000092
Figure BDA0001696698610000101
and then compiling the bridging source program through a preset compiler to obtain a target file comprising the running time meta information of the first language program. In specific implementation, the bridge source program can be compiled through a customized interface bridge compiler front end to generate a target file. The customized interface bridge compiler front end compiles the class information directly defined by the second language source program file according to the compiling mode of the customized compiler front end, so that the bridged class is registered in the runtime environment. For the method implementation, the calling mode of the first language is kept unchanged, so that the calling can be transparently forwarded to the first language library.
For example, bar.scb is compiled, and Bar class is compiled in a mode of 'customizing compiler front end', so that the Bar class is registered in a runtime environment; and for the compilation of the func method, transmitting the translated version to the func (cppb), still forwarding the translated version to Bar.lib according to the calling mode of cpp, and finally, outputting the bar.o of the target file after compiling.
Step 250, acquiring the running time meta information of the first language program included in the target file.
The runtime meta information of the first language program refers to meta information, such as a function, called at runtime by a program written in the first language. The acquiring the runtime meta information of the first language program included in the target file includes: and analyzing to obtain the running time meta-information of the first language program according to the data of the preset data segment in the target file. Taking the target file as a binary file as an example, the class information in the binary file is static. When the application program runs, after the binary file is loaded into the memory, the user-defined guide device can register the class information structure body in the binary file into a running environment, and the class information structure body becomes dynamically modifiable so as to be dynamically interacted during running. The construction of the guider comprises the following steps: the "__ sc _ classlst" segment and the "__ sc _ methodlist" segment information generated by the "customizing compiler front end" are read from the binary data of the executable file and the library file.
When the target file includes a target file generated from a library file implemented by a certain programming language, the obtaining the runtime meta information of the first language program included in the target file includes: and analyzing to obtain the running time meta-information of the first language program according to the target file. The target file generated according to the header file of the binary file such as the library file comprises an open interface of the library file. In specific implementation, according to the compiling strategy of the customized interface bridge compiler front end, the target file corresponding to the binary file is analyzed, and the running time meta-information of the function, class, method and the like of the first language program included in the target file is obtained.
And step 260, mapping the runtime meta-information to a runtime environment constructed based on a second language.
In specific implementation, the mapping the runtime meta-information to a runtime environment constructed based on a second language includes: registering the runtime meta information of at least one first language program to a runtime environment constructed based on a second language.
After the director acquires the runtime meta-information of the first language, loading a class list of the runtime meta-information into a memory. Then, traversing the class list information, and constructing a memory structure of each class, wherein the memory structure comprises the following steps: method lists, variable lists, repudiation interfaces, etc. Finally, information for each class is registered with the runtime environment, e.g., runtime meta-information in a first language, and values are assigned to data structures of the runtime environment constructed based on a second language.
To this end, classes in the source program file (e.g., Foo) and classes in the binary file such as the library file (e.g., Bar) are registered by the director at runtime into the common runtime environment. The runtime environment includes addresses of meta information such as functions, classes, methods, etc. in the source program written in each programming language of the current application program.
Step 270, invoking the runtime meta information mapped in the runtime environment through a second language in the runtime environment.
After the runtime environment is started, if a function or a method implemented by one programming language of the application program needs to be called, the called function or method can be determined by a second language method calling rule in the runtime environment, so as to implement cross-language program calling.
The cross-language programming method disclosed by the embodiment of the application executes the following operations based on the second language: constructing a data structure which meets the requirement of storing at least one running element time information of the first language, defining a memory model, realizing a calling interface corresponding to the first language according to the grammatical characteristics of the first language, creating a reflection capability, and constructing a second language method calling rule; then, by customizing the data structure of the runtime environment according to the first language source program, in the running process of the application program, obtaining the running time meta-information of the first language program included in the target file, mapping the running time meta-information to the runtime environment constructed based on the second language, and calling the running time meta-information mapped in the runtime environment through the second language in the runtime environment to realize cross-language program calling, the problem that the cross-language programming method in the prior art has low coding efficiency is solved. According to the cross-language programming method disclosed by the embodiment of the application, the built runtime environment is used for packaging and mapping the calling of the meta-information such as the functions or methods of different languages, so that an additional language conversion tool is not needed during cross-language programming, the development process of the cross-language programming is simplified, and the efficiency of the cross-language programming is improved. For the condition that a new language and an old language exist simultaneously in the software development process, the zero-cost migration of the old language program to the new language program can be realized through the runtime environment. Meanwhile, the runtime environment is created through the cross-platform language, so that the platform compatibility of the cross-language coding can be improved.
EXAMPLE III
In the cross-language programming method disclosed in this embodiment, as shown in fig. 3, based on the runtime environment implemented in the second embodiment, by combining the interpretable language interpreter and the custom interface for converting between the interpretable language and the runtime information of the runtime environment, the hot update of the first language can be further implemented.
In specific implementation, after mapping the runtime meta information to a runtime environment constructed based on a second language, the method further includes: step 280 and step 290.
Step 280, converting the first language source program into an interpretable language code corresponding to a preset interpreter.
In specific implementation, if a part of code of the source program in the first language needs to be modified, for example, a class of the cpp file needs to be modified or added, the class to be modified or added may be implemented by using the first language (e.g., C + + language), and then, the source program implemented by using the locale language is converted into a dynamic language (e.g., JavaScript and Ruby) with interpretive execution capability by using a preset syntax converter, so as to facilitate dynamic update and execution.
The grammar converter is generated based on an abstract grammar tree, is used for mutual conversion between different language grammars, and can convert a source language into a dynamic language with interpretive execution capacity. The construction of the grammar converter is divided into the following steps: firstly, generating an abstract syntax tree by a code of a source language; second, the abstract syntax tree is traversed for each type of syntax node such as: declaring, assigning, function calling, closing and the like are converted into a grammar form of a target language and linked in a linked list form; and finally, traversing the linked list to generate a source program file of the converted target language.
Step 290, updating the program corresponding to the interface in the runtime environment with the interpreted language program by registering the interface in the runtime environment with the context object of the preset interpreter.
The dynamic language obtained by conversion can be interpreted and executed through a dynamic language interpreter.
In the specific implementation of the present application, because the meta information of the first language registered in the runtime environment needs to be updated by the dynamic language obtained through the conversion, object conversion, parameter transmission, method invocation, and the like between the runtime environment and the dynamic language are needed, and the program corresponding to the interface in the runtime environment is updated by the interpreted language program.
In specific implementation, registering an interface in the runtime environment to a context object of a preset interpreter, and updating a program corresponding to the interface in the runtime environment with the interpreted language program may include: creating a context object for the dynamic language interpreter; registering interfaces such as class definitions, instantiation objects, add/delete methods, etc. into context objects; the dynamic language interpreter invokes an interface of the runtime environment through the context object.
In specific implementation, an interpreter of a dynamic language such as JavaScript, Ruby, etc. needs to be built in an application program or a platform together with a runtime environment.
According to the cross-language programming method disclosed by the embodiment, the static language-based runtime environment is further combined with the interpretable language interpreter and the conversion interface between the customized interpretable language and the runtime environment, so that the hot update of the static language can be further realized, and the programming efficiency is further improved.
On the other hand, for the interpretable language, in order to improve the operating efficiency of the interpretable language, the interpretable language program can be compiled into a target file in advance and loaded for execution, when the interpretable language program needs to be updated thermally, the method disclosed by the embodiment is further used for updating, and on the premise of keeping the thermal updating characteristic of the interpretable language, the operating efficiency of the interpretable language is improved.
Example four
In this embodiment, a cross-language programming apparatus is disclosed, as shown in fig. 4, the apparatus includes:
a runtime meta information obtaining module 410, configured to obtain runtime meta information of a first language program included in a target file;
a meta-information mapping module 420, configured to map the runtime meta-information to a runtime environment constructed based on a second language;
a runtime environment working module 430, configured to invoke the runtime meta information mapped in the runtime environment through a second language in the runtime environment.
According to the cross-language programming device disclosed by the embodiment of the application, the running time meta-information of the first language program included in the target file is acquired and mapped to the running time environment constructed based on the second language, and the running time meta-information mapped in the running time environment is called through the second language in the running time environment, so that cross-language program calling is realized, and the problem that the cross-language programming method in the prior art is low in coding efficiency is solved. According to the cross-language programming device disclosed by the embodiment of the application, the built runtime environment is used for packaging and mapping the calling of the meta-information such as the functions or methods of different languages, so that an additional language conversion tool is not needed during cross-language programming, the development process of the cross-language programming is simplified, and the efficiency of the cross-language programming is improved.
Optionally, as shown in fig. 5, the apparatus further includes:
a runtime environment build module 440 for building a runtime environment based on the second language;
optionally, the runtime environment building module 440 is further configured to perform the following operations based on the second language:
constructing a data structure which stores the runtime meta information of at least one first language;
defining a memory model;
according to the grammatical features of the first language, realizing a calling interface corresponding to the first language;
creating a reflective capability;
and constructing a second language method calling rule.
Optionally, the runtime meta-information obtaining module 410 is further configured to:
and analyzing to obtain the running time meta-information of the first language program according to the data of the preset data segment in the target file.
Optionally, as shown in fig. 5, the apparatus further includes:
the first customized compiling module 450 is configured to generate a data structure of the runtime environment according to the first language source program through the customized compiler front end.
Optionally, the runtime meta-information obtaining module 410 is further configured to:
and analyzing to obtain the running time meta-information of the first language program according to the target file.
Optionally, as shown in fig. 5, the apparatus further includes:
the library file bridging module 460 is configured to generate a bridging source program for invoking runtime meta information in the library file by the runtime environment according to the interface definition file of the first language library file;
the second customized compiling module 470 is configured to compile the bridge source program through a preset compiler, so as to obtain a target file including the runtime meta information of the first language program.
Optionally, the meta information mapping module 420 is further configured to:
registering the runtime meta information of at least one first language program to a runtime environment constructed based on a second language.
The cross-language programming device disclosed in the embodiment of the application performs the following operations based on the second language: constructing a data structure which meets the requirement of storing at least one type of running time meta-information of the first language, defining a memory model, realizing a calling interface corresponding to the first language according to the grammatical characteristics of the first language, creating a reflection capability, and constructing a second language method calling rule; then, by customizing the data structure of the runtime environment according to the first language source program, in the running process of the application program, obtaining the running time meta-information of the first language program included in the target file, mapping the running time meta-information to the runtime environment constructed based on the second language, and calling the running time meta-information mapped in the runtime environment through the second language in the runtime environment to realize cross-language program calling, the problem that the cross-language programming method in the prior art has low coding efficiency is solved. According to the cross-language programming device disclosed by the embodiment of the application, the built runtime environment is used for packaging and mapping the calling of the meta-information such as the functions or methods of different languages, so that an additional language conversion tool is not needed during cross-language programming, the development process of the cross-language programming is simplified, and the efficiency of the cross-language programming is improved. For the condition that a new language and an old language exist simultaneously in the software development process, the zero-cost migration of the old language program to the new language program can be realized through the runtime environment. Meanwhile, the runtime environment is created through the cross-platform language, so that the platform compatibility of the cross-language coding can be improved.
Optionally, as shown in fig. 5, the apparatus further includes:
an interpretable language conversion module 480, configured to convert the first language source program into an interpretable language code corresponding to a preset interpreter;
a runtime environment bridging module 490, configured to update, with the interpreted language program, a program corresponding to an interface in the runtime environment by registering the interface in the runtime environment with a context object of the preset interpreter.
Optionally, the second language is a cross-platform language.
The cross-language programming device disclosed in this embodiment is used to implement the cross-language programming method described in the first to third embodiments, and specific implementation manners of each module of the device refer to specific implementation manners of corresponding steps in the first to third embodiments, which are not described again in this embodiment.
The cross-language programming device disclosed in this embodiment further combines the interpretable language interpreter and the custom interface for converting the interpretable language and the runtime information of the runtime environment through the runtime environment based on the static language, so as to further implement hot update of the static language and further improve the programming efficiency.
On the other hand, for the interpretable language, in order to improve the operating efficiency of the interpretable language, the interpretable language program can be compiled into a target file in advance and loaded for execution, and when the interpretable language program needs to be updated thermally, the device disclosed by the embodiment is further updated, so that the operating efficiency of the interpretable language is improved on the premise of keeping the thermal updating characteristic of the interpretable language.
Correspondingly, the application also discloses an electronic device, which comprises a memory, a processor and a computer program stored on the memory and capable of running on the processor, wherein the processor executes the computer program to realize the cross-language programming method according to the first embodiment to the third embodiment of the application. The electronic device can be a PC, a mobile terminal, a personal digital assistant, a tablet computer and the like.
The present application further discloses a computer-readable storage medium, on which a computer program is stored, which when executed by a processor implements the steps of the cross-language programming method as described in embodiments one to three of the present application.
The embodiments in the present specification are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other. For the device embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, refer to the partial description of the method embodiment.
The foregoing describes in detail a cross-language programming method and apparatus provided by the present application, and specific examples are applied herein to explain the principles and embodiments of the present application, and the descriptions of the foregoing examples are only used to help understand the method and core ideas of the present application; meanwhile, for a person skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.

Claims (10)

1. A cross-language dynamic programming method, comprising:
generating a data structure of a runtime environment according to a first language source program through a front end of a customized compiler, and compiling the data structure to a preset data segment of a target file of the first language source program;
acquiring running time meta information of the first language source program included in the target file;
mapping the runtime meta information to a runtime environment constructed based on a second language;
calling the runtime meta-information of different languages mapped in the runtime environment by executing codes written in a second language corresponding to the runtime environment;
before the step of mapping the runtime meta information to the runtime environment constructed based on the second language, the following operations are further performed based on the second language:
constructing a data structure which stores the runtime meta information of at least one first language;
defining a memory model;
according to the grammatical features of the first language, realizing a calling interface corresponding to the first language;
creating a reflective capability;
and constructing a second language method calling rule.
2. The method according to claim 1, wherein the step of obtaining runtime meta information of the first language source program included in the target file comprises:
and analyzing to obtain the running time meta-information of the first language program according to the data of the preset data segment in the target file.
3. The method according to claim 1, wherein the step of obtaining runtime meta information of the first language source program included in the target file comprises:
and analyzing to obtain the running time meta-information of the first language program according to the target file.
4. The method according to claim 3, wherein the step of obtaining runtime meta information of the first language source program included in the target file is preceded by the step of:
generating a bridging source program of the runtime metadata in the library file called by the runtime environment according to an interface definition file of a first language library file;
and compiling the bridging source program through a preset compiler to obtain a target file comprising the running meta-information of the first language program.
5. The method of claim 1, wherein the step of mapping the runtime meta information to a runtime environment built based on a second language comprises:
registering the runtime meta information of at least one first language program to a runtime environment constructed based on a second language.
6. The method of claim 1, wherein after the step of mapping the runtime meta information to a runtime environment constructed based on a second language, further comprising:
converting the first language source program into an interpretable language code corresponding to a preset interpreter;
and updating a program corresponding to the interface in the runtime environment by the interpretable language program by registering the interface in the runtime environment with a context object of the preset interpreter.
7. The method of any of claims 1 to 6, wherein the second language is a cross-platform language.
8. A cross-language programming apparatus, comprising:
the system comprises a target file generation module, a data compiling module and a data compiling module, wherein the target file generation module is used for generating a data structure of a runtime environment according to a first language source program through the front end of a customized compiler and compiling the data structure to a preset data segment of a target file of the first language source program;
the running meta-information acquisition module is used for acquiring running meta-information of the first language source program included in the target file;
the meta-information mapping module is used for mapping the runtime meta-information to a runtime environment constructed based on a second language;
the runtime environment working module calls runtime meta-information of different languages mapped in the runtime environment by executing codes written in a second language corresponding to the runtime environment so as to realize cross-language program calling;
before the step of mapping the runtime meta information to the runtime environment constructed based on the second language, the following operations are further performed based on the second language:
constructing a data structure which stores the runtime meta information of at least one first language;
defining a memory model;
according to the grammatical features of the first language, realizing a calling interface corresponding to the first language;
creating a reflective capability;
and constructing a second language method calling rule.
9. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor implements the cross-language programming method of any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, on which a computer program is stored, which program, when being executed by a processor, carries out the steps of the cross-language programming method according to any one of claims 1 to 7.
CN201810615055.1A 2018-06-14 2018-06-14 Cross-language programming method and device, electronic equipment and storage medium Active CN108920133B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201810615055.1A CN108920133B (en) 2018-06-14 2018-06-14 Cross-language programming method and device, electronic equipment and storage medium
PCT/CN2018/121763 WO2019237701A1 (en) 2018-06-14 2018-12-18 Cross-language programming

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810615055.1A CN108920133B (en) 2018-06-14 2018-06-14 Cross-language programming method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN108920133A CN108920133A (en) 2018-11-30
CN108920133B true CN108920133B (en) 2021-06-18

Family

ID=64421563

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810615055.1A Active CN108920133B (en) 2018-06-14 2018-06-14 Cross-language programming method and device, electronic equipment and storage medium

Country Status (2)

Country Link
CN (1) CN108920133B (en)
WO (1) WO2019237701A1 (en)

Families Citing this family (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108920133B (en) * 2018-06-14 2021-06-18 北京三快在线科技有限公司 Cross-language programming method and device, electronic equipment and storage medium
CN111488140B (en) * 2019-01-29 2023-10-27 杭州海康威视数字技术股份有限公司 Method, device and computer equipment for supporting multiple programming libraries in multiple programming languages
CN111580821B (en) * 2019-02-15 2022-10-25 厦门雅基软件有限公司 Script binding method and device, electronic equipment and computer readable storage medium
CN110377289A (en) * 2019-07-01 2019-10-25 北京字节跳动网络技术有限公司 A kind of data analysis method, device, medium and electronic equipment
CN111736840A (en) * 2019-09-19 2020-10-02 北京沃东天骏信息技术有限公司 Compiling method and running method of applet, storage medium and electronic equipment
CN111026401A (en) * 2019-12-05 2020-04-17 杭州有赞科技有限公司 Mobile terminal thermal restoration method
CN111381817A (en) * 2020-03-25 2020-07-07 北京字节跳动网络技术有限公司 Method, device, medium and electronic equipment for realizing cross-platform multi-language development
CN111142876B (en) * 2020-04-02 2020-08-18 华控清交信息科技(北京)有限公司 Compiling processing method and device and compiling processing device
CN111625243B (en) * 2020-05-13 2023-07-18 北京字节跳动网络技术有限公司 Cross-language task processing method and device and electronic equipment
CN111625224B (en) * 2020-05-28 2023-11-24 北京百度网讯科技有限公司 Code generation method, device, equipment and storage medium
CN114327497A (en) * 2020-09-30 2022-04-12 华为技术有限公司 Code processing method, device and equipment
CN112256351B (en) * 2020-10-26 2023-11-17 卫宁健康科技集团股份有限公司 Method for realizing Feign component, method and device for calling micro-service
CN112346732B (en) * 2020-10-30 2024-01-12 深圳市优必选科技股份有限公司 Cross-language calling method and device for application program, electronic equipment and storage medium
CN113032169B (en) * 2021-05-25 2021-08-24 北京小米移动软件有限公司 Resource calling method, equipment and storage medium of cross-language software system

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1661554A (en) * 2004-02-27 2005-08-31 捷讯研究有限公司 System and method for building wireless applications
US6978018B2 (en) * 2001-09-28 2005-12-20 Intel Corporation Technique to support co-location and certification of executable content from a pre-boot space into an operating system runtime environment
CN1725178A (en) * 2004-07-20 2006-01-25 英业达股份有限公司 Development platform of multilanguage software program
CN103870287A (en) * 2006-09-29 2014-06-18 西门子公司 System for generating and operating a software application for medical image generation
CN105164641A (en) * 2012-12-31 2015-12-16 微软技术许可有限责任公司 Extending development environment
CN105718251A (en) * 2014-12-03 2016-06-29 苏宁云商集团股份有限公司 Multilanguage SDK (software development kit) automatic implementation method and system

Family Cites Families (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6957439B1 (en) * 2000-05-09 2005-10-18 International Business Machines Corporation Method, system, and program for mapping objects in different language formats
US7992140B2 (en) * 2005-07-29 2011-08-02 Microsoft Corporation Compiler supporting programs as data objects
US8695021B2 (en) * 2011-08-31 2014-04-08 Microsoft Corporation Projecting native application programming interfaces of an operating system into other programming languages
US9411558B2 (en) * 2012-10-20 2016-08-09 Luke Hutchison Systems and methods for parallelization of program code, interactive data visualization, and graphically-augmented code editing
CN103778061B (en) * 2014-01-17 2016-08-24 南京航空航天大学 Automatically detection and the bearing calibration of Array Bound mistake
CN104199642B (en) * 2014-08-05 2018-05-01 青岛海信移动通信技术股份有限公司 A kind of implementation method and device in target platform operation original platform code
US10656919B2 (en) * 2016-10-25 2020-05-19 Paypal, Inc. Matching programming variables across different data domains
CN106843888B (en) * 2017-01-23 2020-03-17 恒生电子股份有限公司 Method and device for solving field conflict in multi-language development system
CN107506381A (en) * 2017-07-21 2017-12-22 中国建设银行股份有限公司 A kind of big data distributed scheduling analysis method, system and device and storage medium
CN108920133B (en) * 2018-06-14 2021-06-18 北京三快在线科技有限公司 Cross-language programming method and device, electronic equipment and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6978018B2 (en) * 2001-09-28 2005-12-20 Intel Corporation Technique to support co-location and certification of executable content from a pre-boot space into an operating system runtime environment
CN1661554A (en) * 2004-02-27 2005-08-31 捷讯研究有限公司 System and method for building wireless applications
CN1725178A (en) * 2004-07-20 2006-01-25 英业达股份有限公司 Development platform of multilanguage software program
CN103870287A (en) * 2006-09-29 2014-06-18 西门子公司 System for generating and operating a software application for medical image generation
CN105164641A (en) * 2012-12-31 2015-12-16 微软技术许可有限责任公司 Extending development environment
CN105718251A (en) * 2014-12-03 2016-06-29 苏宁云商集团股份有限公司 Multilanguage SDK (software development kit) automatic implementation method and system

Also Published As

Publication number Publication date
CN108920133A (en) 2018-11-30
WO2019237701A1 (en) 2019-12-19

Similar Documents

Publication Publication Date Title
CN108920133B (en) Cross-language programming method and device, electronic equipment and storage medium
US10146522B1 (en) Live code updates
CN106415495B (en) Programming system and language for application development
US9965259B2 (en) System for translating diverse programming languages
US9086931B2 (en) System for translating diverse programming languages
Bracha et al. Modules as objects in Newspeak
KR101795844B1 (en) Runtime system
CN110149800B (en) Apparatus for processing abstract syntax tree associated with source code of source program
TWI536263B (en) Projecting native application programming interfaces of an operating system into other programming languages
US20060225053A1 (en) Programming language improvements
Zakrzewski Towards verification of Ethereum smart contracts: a formalization of core of Solidity
WO2014062950A1 (en) Code dependency calculation
US20040268301A1 (en) Adding new compiler methods to an integrated development environment
WO2024045379A1 (en) Compiling method, compiler, and wasm virtual machine
US11687388B2 (en) Implementing optional specialization when executing code
WO2024045382A1 (en) Implementation of reflective mechanism in blockchain
JP2022545489A (en) Smart contract client program generation method, system, device, and medium
CN111506314B (en) Project development method, device, server and medium
US8606766B2 (en) Method and system to handle java class versioning
EP1452962B1 (en) System and method for defining and using subclasses declaratively within markup
US10387142B2 (en) Using annotation processors defined by modules with annotation processors defined by non-module code
US10983771B1 (en) Quality checking inferred types in a set of code
US20050119993A1 (en) System and method for declaring a resource within a markup document
CN115390846A (en) Compiling construction method and device, electronic equipment and storage medium
Veiga Light programming language

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
GR01 Patent grant
GR01 Patent grant