CN107515739A - Improve the method and device of code execution performance - Google Patents

Improve the method and device of code execution performance Download PDF

Info

Publication number
CN107515739A
CN107515739A CN201610430445.2A CN201610430445A CN107515739A CN 107515739 A CN107515739 A CN 107515739A CN 201610430445 A CN201610430445 A CN 201610430445A CN 107515739 A CN107515739 A CN 107515739A
Authority
CN
China
Prior art keywords
sentence
type
corresponding relation
variable
source code
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.)
Granted
Application number
CN201610430445.2A
Other languages
Chinese (zh)
Other versions
CN107515739B (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.)
Banma Zhixing Network Hongkong Co Ltd
Original Assignee
Alibaba Group Holding 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 Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Priority to CN201610430445.2A priority Critical patent/CN107515739B/en
Publication of CN107515739A publication Critical patent/CN107515739A/en
Application granted granted Critical
Publication of CN107515739B publication Critical patent/CN107515739B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation
    • G06F8/4434Reducing the memory space required by the program code
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation
    • G06F8/4441Reducing the execution time required by the program code
    • 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)
  • Devices For Executing Special Programs (AREA)

Abstract

This application discloses a kind of method and device for improving code execution performance, also discloses a kind of method and device for generating marking variable and the corresponding relation of type, and a kind of method and device for being used to generate the source code of containing type mark sentence.The method for improving code execution performance includes:Obtain previously generated for source code, marking variable and the corresponding relation of type;According to the corresponding relation, the compilation of source code stored with grammer tree format is generated into the executable code after carrying out types of variables restriction.Using the above method, types of variables can be defined according to the corresponding relation previously generated when compiling source code and generate the executable code after carrying out types of variables restriction, so as to reduce the memory headroom of executable code occupancy, and due to reducing the process for being directed to various possible types and being judged, therefore the execution speed of the executable code is also mutually due for promotion, and is improved overall execution performance.

Description

Improve the method and device of code execution performance
Technical field
The application is related to technical field of software development, and in particular to a kind of method and device for improving code execution performance. The application is related to a kind of method and device for generating marking variable and the corresponding relation of type simultaneously, and a kind of for generating bag The method and device of the source code of the mark sentence containing type.
Background technology
Programming language (programming language), is the formal language for defining computer program, is commonly called as " meter Calculation machine language ", species is varied, and some language belong to weak type language, and some language belong to strongly typed language.In strongly-typed In language, types of variables has a variety of, such as int, char, float, boolean etc., and its class is clearly specified in defined variable Type;And weak type language, the usual not specifying variable type in defined variable, and also can not accurately derive change in compiling Measure type." weak type " due to without specifying variable type, therefore for developer code development phase bring flexibly and It is convenient, but effectively optimizing can not be carried out to respective code by the same time also resulting in.
By taking JavaScript scripts as an example, because it has simple, dynamic, based on prototype and the spy such as cross-platform Property have been widely used in Web application and developments, variable generally use var or const in JavaScript language are crucial Word defines, but not clear and definite type information, therefore falls within weak type language.Perform JavaScript's for explaining Interpreter is commonly known as JavaScript engine (abbreviation JS engines), for the execution efficiency of Optimized code, at this stage generally The JS engines (such as JS V8) used possess the ability that JS code compilations are explained to execution into executable code and then again immediately. It is weak type language yet with JS, type of variables is uncertain and variable at any time, and JS engines generally have to be directed to All possible type, the processing code of complexity being generated, this executable code for resulting in generation does not only take up a large amount of internal memories, and And time-consuming, efficiency is low for execution, overall execution performance is by extreme influence.
The content of the invention
The embodiment of the present application provides a kind of method and apparatus for improving code execution performance, to solve existing weak type language Say the problem of execution performance is low.The embodiment of the present application also provide a kind of corresponding relation for generating marking variable and type method and Device, and a kind of method and device for being used to generate the source code of containing type mark sentence.
The application provides a kind of method for improving code execution performance, including:
Obtain previously generated for source code, marking variable and the corresponding relation of type;
According to the corresponding relation, the compilation of source code stored with grammer tree format is generated and carries out types of variables limit Executable code after fixed.
Optionally, before the corresponding relation for obtaining previously generated for source code, marking variable and type, bag Include:
The type mark sentence of the preset format contained according at least to the source code package, generates the marking variable and type Corresponding relation.
Optionally, the type mark sentence of the preset format contained according at least to the source code package, generates the variable mark Know the corresponding relation with type, including:
The sentence in the source code is read sentence by sentence, and operations described below is performed for each sentence:
Judge the sentence whether be preset format type mark sentence;
If so, perform operations described below:Generated according to the marking variable and respective type information extracted from the sentence Corresponding relation entry, and be added in the marking variable and the corresponding relation of type.
Optionally, the type mark sentence of the preset format contained according at least to the source code package, generates the variable mark Know the corresponding relation with type, including:
The sentence in the source code is read sentence by sentence, and operations described below is performed for each sentence:
Judge the sentence whether be preset format type mark sentence;
If so, perform operations described below:Type information is extracted from the sentence;Defined according to the sentence and relevant variable The position relationship of sentence, read corresponding variable-definition sentence and obtain the marking variable corresponding with the type information extracted; The marking variable and type will be added to by the marking variable that obtains and the corresponding relation entry that respective type information forms In corresponding relation.
Optionally, the sentence and the position relationship of relevant variable definition statement, including:
The sentence is adjacent with relevant variable definition statement and before the variable-definition sentence or afterwards.
Optionally, the form of the type mark sentence includes:Character string statement, or comment statement.
Optionally, during the source code stored with grammer tree format is generated by syntax parsing, extremely The type mark sentence of few preset format contained according to the source code package, generates marking variable pass corresponding with type System.
Optionally, it is described according to the corresponding relation, by the compilation of source code stored with grammer tree format generate into Executable code after the restriction of row types of variables, including:
Read sentence by sentence with the sentence in the source code of grammer tree format storage, and following behaviour are performed for each sentence Make:
Judge whether the sentence meets following condition:The sentence is for variable arithmetic statement and wherein at least in the presence of one Individual computing variable has corresponding type information in the corresponding relation;
If satisfied, the computing type of variables information included according to sentence obtained from the corresponding relation, described, raw Executable code into after for sentence progress types of variables restriction;
Otherwise, the executable code of types of variables restriction is not carried out for sentence generation.
Optionally, methods described also includes:
Perform the executable code.
Optionally, the source code is write with weak type language, and the weak type language includes:JavaScript languages Speech.
Accordingly, the application also provides a kind of device for improving code execution performance, including:
Corresponding relation acquiring unit, for obtaining, being previously generated for source code, marking variable is corresponding with type closes System;
Executable code generation unit, for according to the corresponding relation, the source generation that will be stored with grammer tree format Code compiling generation carries out the executable code after types of variables restriction.
Optionally, described device also includes:Corresponding relation generation unit;
The corresponding relation generation unit, the type of the preset format for containing according at least to the source code package mark language Sentence, generates the marking variable and the corresponding relation of type.
Optionally, the corresponding relation generation unit, including:
Code is read and loop control subelement, for reading the sentence in the source code sentence by sentence, and is directed to each language Sentence triggers following subelement work;
Type mark sentence judgment sub-unit, for judge the sentence whether be preset format type mark sentence;
First corresponding relation entry generates and addition subelement, for marking the defeated of sentence judgment sub-unit when the type When going out to be, corresponding relation entry is generated according to the marking variable and respective type information extracted from the sentence, and add It is added in the marking variable and the corresponding relation of type.
Optionally, the corresponding relation generation unit, including:
Code is read and loop control subelement, for reading the sentence in the source code sentence by sentence, and is directed to each language Sentence triggers following subelement work;
Type mark sentence judgment sub-unit, for judge the sentence whether be preset format type mark sentence;
Type information extracts subelement, and the output for marking sentence judgment sub-unit when the type is when being, from institute Type information is extracted in predicate sentence;
Marking variable obtains subelement, for the position relationship according to the sentence and relevant variable definition statement, reads Corresponding variable-definition sentence simultaneously obtains the marking variable corresponding with the type information extracted;
Second corresponding relation entry generates and addition subelement, for by by the marking variable that obtains and respective type information The corresponding relation entry of composition is added in the marking variable and the corresponding relation of type.
Optionally, the corresponding relation generation unit, specifically for described with syntax tree lattice by syntax parsing generation During the source code of formula storage, the type mark sentence of the preset format contained according at least to the source code package is raw Into the marking variable and the corresponding relation of type.
Optionally, the executable code generation unit, including:
Loop control subelement, for reading sentence by sentence with the sentence in the source code of grammer tree format storage, and pin Following subelement work is triggered to each sentence;
Optimal conditions judgment sub-unit, for judging whether the sentence meets following condition:The sentence is transported for variable Calculating sentence and a computing variable being wherein at least present has corresponding type information in the corresponding relation;
Optimized code generates subelement, for when the output of the optimal conditions judgment sub-unit is is, according to from institute The computing type of variables information that sentence obtained in corresponding relation, described includes is stated, generation carries out variable for the sentence Executable code after type restriction;
Conventional code generate subelement, for when the optimal conditions judgment sub-unit output for it is no when, for described Sentence generates the executable code for not carrying out types of variables restriction.
Optionally, described device also includes:
Executable code execution unit, for performing the executable code.
In addition, the application also provides a kind of method for generating marking variable and the corresponding relation of type, including:
The type mark sentence of the preset format contained according at least to source code package, generation marking variable is corresponding with type to close System, during for being compiled for the source code generation carry out the executable code after types of variables restriction.
Optionally, the type mark sentence of the preset format contained according at least to source code package, generates the variable mark Know the corresponding relation with type, including:
The sentence in the source code is read sentence by sentence, and operations described below is performed for each sentence:
Judge the sentence whether be preset format type mark sentence;
If so, perform operations described below:Generated according to the marking variable and respective type information extracted from the sentence Corresponding relation entry, and be added in the marking variable and the corresponding relation of type.
Optionally, the preset format contained according at least to source code package type mark sentence, generate the variable with The corresponding relation of type, including:
The sentence in the source code is read sentence by sentence, and operations described below is performed for each sentence:
Judge the sentence whether be preset format type mark sentence;
If so, perform operations described below:Type information is extracted from the sentence;Defined according to the sentence and relevant variable The position relationship of sentence, read corresponding variable-definition sentence and obtain the marking variable corresponding with the type information extracted; The marking variable and type will be added to by the marking variable that obtains and the corresponding relation entry that respective type information forms In corresponding relation.
Optionally, the sentence and the position relationship of relevant variable definition statement include:
The sentence is adjacent with relevant variable definition statement and before the variable-definition sentence or afterwards.
Optionally, the form of the type mark sentence includes:Character string statement, or comment statement.
Optionally, during being generated by syntax parsing with the source code of grammer tree format storage, according at least to institute The type mark sentence for the preset format that source code package contains is stated, marking variable and the corresponding relation of type are generated, for for institute State generation when source code is compiled and carry out the executable code after types of variables restriction.
Accordingly, the application also provides a kind of device for generating marking variable and the corresponding relation of type, including:
Corresponding relation generation unit, the type of the preset format for containing according at least to source code package mark sentence, generation The corresponding relation of marking variable and type;
Correspondence relation storage, for storing the corresponding relation of the marking variable generated and type, for for institute State generation when source code is compiled and carry out the executable code after types of variables restriction.
Optionally, the corresponding relation generation unit includes:
Code is read and loop control subelement, for reading the sentence in the source code sentence by sentence, and is directed to each language Sentence triggers following subelement work;
Type marks sentence judgment sub-unit, for judging whether the sentence is type mark sentence;
First corresponding relation entry generates and addition subelement, for marking the defeated of sentence judgment sub-unit when the type When going out to be, corresponding relation entry is generated according to the marking variable and respective type information extracted from the sentence, and add It is added in the marking variable and the corresponding relation of type.
Optionally, the corresponding relation generation unit includes:
Code is read and loop control subelement, for reading the sentence in the source code sentence by sentence, and is directed to each language Sentence triggers following subelement work;
Type mark sentence judgment sub-unit, for judge the sentence whether be preset format type mark sentence;
Type information extracts subelement, and the output for marking sentence judgment sub-unit when the type is when being, from institute Type information is extracted in predicate sentence;
Marking variable obtains subelement, for the position relationship according to the sentence and relevant variable definition statement, reads Corresponding variable-definition sentence simultaneously obtains the marking variable corresponding with the type information extracted;
Second corresponding relation entry generates and addition subelement, for by by the marking variable that obtains and respective type information The corresponding relation list item of composition is added in the marking variable and the corresponding relation of type.
Optionally, the corresponding relation generation unit, specifically for being deposited with grammer tree format being generated by syntax parsing During the source code of storage, the type mark sentence of the preset format contained according at least to the source code package, variable mark is generated Know with the corresponding relation of type, during for being compiled for the source code generation carry out executable after types of variables restriction Code.
In addition, the application also provides a kind of method for being used to generate the source code of containing type mark sentence, including:
Receive type for source code input, for specifying variable type and mark sentence;
According to the type mark sentence received and its input position in the source code, the type is marked Sentence is stored into the source code;
Wherein, the type mark sentence is preset format.
Optionally, the form of the type mark sentence includes:Character string statement, or comment statement.
Optionally, the source code is write using weak type language, and the weak type language includes:JavaScript languages Speech.
Accordingly, the application also provides a kind of device for being used to generate the source code of containing type markup information, including:
Type marks sentence receiving unit, for receiving type for source code input, for specifying variable type Sentence is marked, wherein, the type mark sentence is preset format;
Type marks sentence memory cell, for according to the type mark sentence received and its in the source code Input position, by the type mark sentence storage into the source code.
Compared with prior art, the application has advantages below:
That a kind of method for raising code execution performance that the application provides, first acquisition previously generate for source code, The corresponding relation of marking variable and type, then according to the corresponding relation, the source code that will be stored with grammer tree format Compiling generation carries out the executable code after types of variables restriction.Using the above method, due to previously generated marking variable with The corresponding relation of type, therefore types of variables can be defined and be given birth to according to the corresponding relation when compiling source code Executable code into after progress types of variables restriction, so as to reduce the memory headroom of executable code occupancy, Er Qieyou In reducing the process that is judged for various possible types, therefore the execution speed of the executable code is also mutually deserved To lifting, improved overall execution performance.
Brief description of the drawings
Fig. 1 is a kind of flow for being used to generate the embodiment of the method for the source code of containing type mark sentence of the application Figure;
Fig. 2 is a kind of signal for being used to generate the embodiment of the device of the source code of containing type mark sentence of the application Figure;
Fig. 3 be the application a kind of generation marking variable and type corresponding relation embodiment of the method flow chart;
Fig. 4 is the process chart for sentence generation corresponding relation entry that the embodiment of the present application provides;
Fig. 5 be the application a kind of generation marking variable and type corresponding relation device embodiment schematic diagram;
Fig. 6 is a kind of flow chart of the embodiment of the method for raising code execution performance of the application;
Fig. 7 is the process chart for sentence generation executable code that the embodiment of the present application provides;
Fig. 8 is a kind of schematic diagram of the device embodiment of raising code execution performance of the application.
Embodiment
Many details are elaborated in the following description in order to fully understand the application.But the application can To be much different from other manner described here to implement, those skilled in the art can be in the feelings without prejudice to the application intension Similar popularization is done under condition, therefore, the application is not limited by following public specific implementation.
In this application, a kind of method and device for improving code execution performance, one kind generation variable mark are each provided Know the method and device with the corresponding relation of type, and a kind of method for being used to generate the source code of containing type mark sentence And device, it is described in detail one by one in the following embodiments.Before embodiment is described, first to the skill of the application Art scheme is briefly described.
Weak type language, refer to not possess the grammer of description types of variables and can not accurately derive variable in compiling The programming language of type.Using weak type language often to developer written in code process bring some flexibly and It is convenient, but also result in simultaneously efficient code optimization can not be carried out towards implementation procedure, therefore write using weak type language Code execution performance generally than relatively low.By taking JavaScript (abbreviation JS) language as an example, for JS codes:Z=x+y;By It is weak type in JS, JS engines (such as V8 engines) for it when generating executable code, it usually needs consideration is possible to Types of variables computing, therefore generate executable code pseudo-code it is as follows:
If x is integer, operations described below is performed:
If y is integer, add z, x, y are performed;
If y is double-precision floating point type, addf z, x, y are performed;
If y is character string, y is first converted into integer value y_int, then performs add z, x, y_int;
If y is object, y is first converted into shaping value y_int, then performs add z, x, y_int;
If x is double-precision floating pointses, operations described below is performed:
......
As can be seen here, JS engines all generate corresponding branch and in each branch for every kind of possible types of variables It is lower to handle code comprising corresponding, therefore the executable code so generated generally takes up substantial amounts of memory headroom, and holding Repeatedly judged due to needing during row, therefore execution speed is slow, causes overall execution performance comparision poor.Although arrange above For be the example of JS language, but the problem of above-mentioned identical generally all be present for weak type language.
Although weak type language, which can not be variable, specifies clear and definite type, actually using what weak type language was developed During, developer is to have clear and definite " type tendency " in the case of the overwhelming majority, i.e.,:The variable that developer defines is usually constructed with Determine specific type and will not random alternative types, simply in weak type language can not specifying variable type.
For above-mentioned present situation, present applicant proposes a kind of method for improving code execution performance, its core is:For treating The source code of compiling, can by certain type of marking variable and its class record in corresponding relation, when compiling source code, Type information generation in the corresponding relation carries out the executable code after types of variables restriction, i.e.,:It is excellent to generate type Executable code after change.In this way, largely branch is judged due to reducing, so as to can both reduce executable generation The memory headroom that code takes, and the execution speed of the executable code generated also can mutually be due for promotion, so that overall Execution performance is improved.
The corresponding relation of the marking variable and type, comprising several corresponding relation entries, each corresponding relation entry Middle comprising variable mark and corresponding type information.The corresponding relation can be stored in internal memory in the form of tables of data, or Person stores hereof.
When it is implemented, preset format can be added during code is write using weak type language by developer Type mark sentence, and the application provide be used for generate containing type mark sentence source code method, pass through reception The source code of the above-mentioned sentence generation containing type mark sentence of developer's input, the life that can then utilize the application to provide Into the method for marking variable and the corresponding relation of type, the source code that sentence is marked according to the containing type generates marking variable With the corresponding relation of type, and the method for the raising code execution performance provided using the application utilizes the corresponding pass generated System, generation carry out the executable code after types of variables restriction for the source code.
Because the type mark sentence added in source code meets weak type language syntax rule, therefore JS need not be changed Language (such as:Addition carries out the keyword of type definition), so as to which weak type language can't be changed over by force from speech level Type language, therefore can still retain the flexibility of weak type language, developer still can practise according to original programming It is used to write source code, it is only necessary to the place addition type mark sentence of types of variables can be specified, it is possible to which realization is compiling Stage carries out the purpose of types of variables restriction.
The form of type mark sentence can be character string sentence or comment statement or other forms, no Influence the code statement that source code function is realized.The comment statement refers to the effect without the realization of any function, is only The sentence illustrated to source code, two examples of comment statement in JavaScript language are provided here:
The code statement is different from comment statement, typically refers to the sentence for realizing source code function, such as:Variable Definition statement, variable arithmetic statement etc., source code are typically to be made up of comment statement and code statement.Implementing the technical program When, the code statement for not influenceing the realization of source code function can be used, such as:Language is marked as type using character string statement Sentence.
In order to make it easy to understand, below in an example emphasis using use character string statement as type mark sentence as Example, is illustrated to the embodiment of the technical program.As for the code statement using other forms or using comment statement Sentence is marked as type, can also be practiced based on identical principle.
Embodiments herein is described in detail below, in order to make it easy to understand, the one kind for first describing the application is used for Generate the embodiment of the method for the source code of containing type mark sentence.
Fig. 1 is refer to, it is a kind of reality for being used to generate the method for the source code that containing type marks sentence of the application Apply the flow chart of example.Methods described comprises the following steps:
Step 101, receive type mark sentence for source code input, for specifying variable type.
Source code described in this step can be a code snippet, wherein can include function realize code, Or the whole codes realized in code or source file for realizing some allomeric function of several functions.
The mode that developer adds the type mark sentence for specifying variable type in source code can be advance Set, also in compliance with identical predetermined manner when extracting the corresponding relation of scalar mark and type subsequently from source code.Example Such as:Sentence can be marked to some or some variables that are defined in this function using type in the beginning of function Type clearly specify, and the variable-definition sentence that can also be directed in function adds corresponding type mark sentence.Consider The second way is more directly perceived, is easy to developer to operate, therefore typically developer adds the preferred of type mark sentence Mode.
Using aforesaid way, developer can add the type mark language in the position adjacent with variable-definition sentence Sentence, such as:Before variable-definition sentence, or after variable-definition sentence, the type for specifying variable type is added Mark sentence.
Also, the class of in relevant variable definition statement, at least one variable is comprised at least in the type mark sentence Type information.If the definition of n variable is included in variable-definition sentence, then for the type of variable-definition sentence addition Mark sentence can include wherein each type of variables information, can also only include the class of wherein some or several variables Type information, as long as correct corresponding relation can be set up between variable and type information to be just all possible.
The form of the type mark sentence is typically set in advance, such as:Type mark sentence uses predetermined symbol Beginning, for different type of variables information default separator can be used to be separated from each other, the default separator can be:Point Number, comma or other symbols, such as:@.The preset format that the present embodiment does not mark sentence to type is defined, as long as energy Type mark sentence is identified in the sentence enough contained by preset format from source code package and extracts type information.
Illustrated below exemplified by type mark sentence is added in the source code using written in JavaScript, under In the specific example in face, the type mark sentence of preset format is:Using "@" character or "<-@" characters are as beginning character Character string statement.Wherein, beginning character is that "@" represents that type is added before variable-definition sentence marks sentence, "<-@" tables Show and type mark sentence is added after variable-definition sentence.
It is not added with the source code of type mark sentence:
Var num=1;
Const str=" hello ", isTrue=true;
Var func=function (num, str) { };
1) type mark sentence (being added in different code lines) is added before variable-definition sentence:
“@int”;
Var num=1;
“@string,@boolean”;
Const str=" hello ", isTrue=true;
“@boolean function(@int,@string)”;
Var func=function () { };
2) type mark sentence (being added in identical code line) is added before variable-definition sentence:
“@int”;Var num=1;
“@string,@boolean”;Const str=" hello ", isTrue=true;
“@boolean function(@int,@string)”;Var func=function (num, str) { };
3) type mark sentence is added after variable-definition sentence:
Var num=1;“<-@int”;
Const str=" hello ", isTrue=true;“<-@string,@boolean”;
Var func=function (num, str) { };“<-@boolean function(@int,@string)”;
Above-mentioned three specific examples for 1), 2), 3) each providing addition type mark sentence, in these three specific examples The effect of the type mark sentence of middle addition is identical:Num types of variables are appointed as int, str types of variables are referred to It is set to string, isTrue types of variables is appointed as boolean, func types of variables is appointed as function.
The type of the Partial Variable in relevant variable definition statement can also be only specified in type mark sentence, for example, it is following The source code of type mark sentence is with the addition of, wherein the type information before first separator is sky, shows not to be corresponding Num variable specified types, behind have type information before two separators, i.e.,:It is for variable str specified types String, it is that variable i sTrue specified types are boolean.
“@object{,@string,@boolean}”;
Const obj={ num:1,str:“hello”,isTrue:true};
In the specific implementation, marking variable can also be clearly write in type mark sentence, i.e.,:Can in type mark sentence With including one or two tuples that more than one is made up of marking variable and respective type information, such as:
“@object{@str:string,@isTrue:boolean}”;
Const obj={ num:1,str:“hello”,isTrue:true};
In the specific implementation, it generally can in the editing window load and show source code, developer is in editor Input cursor at input the type mark sentence of preset format in the manner described above, this step correspondingly received will arrive the class Type marks sentence and knows input position of the type received the mark sentence in source code.
The type mark sentence and its input position in the source code that step 102, basis receive, by described in Type mark sentence storage is into the source code.
This step is according to the type mark sentence received and its input position in the source code, by type mark Sentence storage is noted into the source code, so as to generate the source code of containing type mark sentence.
In the specific implementation, the type that step 101 receives can be marked under sentence and its input position information cache Come, and after storage order is received, the type of caching is marked into sentence and arrives the source generation according to the storage of its input position information In code.
Above by taking JavaScript as an example, the embodiment of the present embodiment is described in detail.People in the art Member can also be applied in the source code write using other weak type languages, institute it should be understood that the method for the present embodiment description Stating weak type language includes:PHP, Lua etc..
In the specific implementation, the preset format of type mark sentence and the position of addition can be according to weak type languages Syntax rule and actual demand preset, as long as can identify that type mark and refers to sentence according to preset format Determining the corresponding relation between variable and type is just all possible.On the basis of type mark sentence is added in source code, When needing to perform the source code, it is possible to which the preset format that sentence is marked according to type extracts marking variable and pair of type It should be related to, and the executable code after carrying out types of variables restriction is generated according to corresponding relation.
The embodiment of the present embodiment is illustrated by using exemplified by character string statement above.In other embodiment In, type mark sentence can also use the form of comment statement, can equally add in the beginning of function, or addition Before or after variable-definition sentence.Several specific examples are given below.
1)//@string,@boolean
Const str=" hello ", isTrue=true;
2)/*@int*/var num=1;
3) const str=" hello ", isTrue=true;//<-@string,@boolean
In summary, the method for being used to generate the source code that containing type marks sentence that the present embodiment provides, by connecing Narrow and sentence is marked to the type of source code input and stores type mark sentence into the source code, generate and include Type marks the source code of sentence.So as to make up weak type language can not specifying variable type the defects of, to be subsequently generated The executable code for carrying out types of variables restriction provides possibility.The mode of sentence is marked as a result of addition type, no Need to modify to original code statement in source code, be easy to developer's implementation;Especially with variable-definition language The mode of the corresponding addition of sentence, it is only necessary to add a type mark sentence for variable-definition is corresponding, not only corresponding relation Clearly, and the mark workload of developer can be reduced.
In the above-described embodiment, there is provided a kind of method for being used to generate the source code of containing type mark sentence, with It is corresponding, the application also provide it is a kind of be used for generate containing type mark sentence source code device.It refer to Fig. 2, It is a kind of schematic diagram for being used to generate the embodiment of the device for the source code that containing type marks sentence of the application.Due to dress Put embodiment and be substantially similar to embodiment of the method, so describing fairly simple, referring to the part of embodiment of the method in place of correlation Explanation.Device embodiment described below is only schematical.
A kind of device for being used to generate the source code of containing type mark sentence of the present embodiment, including:Type marks language Sentence receiving unit 201, sentence is marked for receiving type for source code input, for specifying variable type, wherein, institute It is preset format to state type mark sentence, and this unit can be used for performing the step 101 in above-mentioned correlation method embodiment;
Type mark sentence memory cell 202, for according to the type mark sentence received and its in the source code In input position, by the type mark sentence storage into the source code, this unit can be used for perform above-mentioned respective party Step 102 in method embodiment.
In addition, the application also provides a kind of method for generating marking variable and the corresponding relation of type, Fig. 3 is refer to, its For the application provide a kind of generation marking variable and type corresponding relation embodiment of the method flow chart, the present embodiment with Each embodiment content identical part provided before repeats no more, below emphasis difference is described.The one of the application offer The method of kind generation marking variable and the corresponding relation of type includes:
Step 301, the type of the preset format contained according at least to source code package mark sentence, generate marking variable and type Corresponding relation, during for being compiled for the source code generation carry out the executable code after types of variables restriction.
Before this step is performed, the source code of the type mark sentence comprising preset format has generally been generated, this Step generates marking variable and the corresponding relation of type on the basis of the type mark sentence in reading source code, so that The executable code after carrying out types of variables restriction can be generated according to the type information in corresponding relation during compiling.
This step can mark the preset format of sentence according to type, identify that type marks language from the source code Sentence, and the corresponding relation is generated on this basis.The preset format of type mark sentence is different, the processing procedure of this step Can be different.
If the beginning of function is set in advance in using type mark sentence to the variable that is defined in this function Type clearly specify, then this step can read the type mark sentence in function beginning, correspondingly generate The corresponding relation entry of marking variable and type, and be added in marking variable and the corresponding relation of type.
If type mark sentence is preset for being wrapped in the addition of variable-definition sentence and type mark sentence Containing marking variable and corresponding type information, then this step can read each sentence in source code sentence by sentence, if identification The sentence for going out reading marks sentence for the type of preset format, then the marking variable extracted according to being marked from the type in sentence And respective type information generation corresponding relation entry, and be added in marking variable and the corresponding relation of type.
If preset type mark sentence to mark in sentence not for the addition of variable-definition sentence and type Comprising variable identifies, then needs to mark position relationship of the sentence with corresponding variable-definition sentence according to type, generate variable mark Know the corresponding relation entry with type, and be added in marking variable and the corresponding relation of type.With reference to a concrete example Son illustrates to this mode.
In the specific example, character string forms are with the addition of before or after the variable-definition sentence in source code Type mark sentence, this step reads each sentence in the source code sentence by sentence, and is handled for each sentence, locate Reason process includes step 301-1 to step 301-5, is described in detail with reference to Fig. 4.
Step 301-1, judge the sentence whether be preset format type mark sentence;If so, perform step 301- 2。
Whether this step can meet the preset format of type mark sentence according to the sentence, whether judge the sentence Sentence is marked for type.In the specific example, the type mark sentence of preset format is:Using "@" character or "<-@” Character string statement of the character as beginning character, then this step can judge as follows:Whether the sentence is character string language Sentence and with@" or "<Beginning characters of-the@" as character string, if the sentence currently read meets the requirement, illustrate institute Predicate sentence is type mark sentence, then performs step 301-2.
Step 301-2, type information is extracted from the sentence.
This step can mark the preset format of sentence according to type, extract type information, such as:According to the finger of separator Show extraction type information.
Step 301-3, according to the sentence and the position relationship of relevant variable definition statement, corresponding variable-definition is read Sentence simultaneously obtains the marking variable corresponding with the type information extracted.
The type mark sentence and the position relationship of relevant variable definition statement, can be in developer into source code It is just pre-set during addition type definition sentence, such as:Preset type and mark sentence before variable-definition sentence, So this step read positioned at the type mark sentence after next variable-definition sentence (by taking Java Script as an example, Variable-definition sentence can be var sentences or const sentences);If presetting type marks sentence in variable-definition language After sentence, then this step reads the upper variable-definition sentence before type mark sentence.
The type mark sentence and the position relationship of relevant variable definition statement, can also be marked in sentence by type Presupposed information specify, in the specific example, if type mark sentence using "@" character start, represent type mark Sentence is before variable-definition sentence;If type mark sentence using "<-@" characters start, then represent type mark sentence and exist After variable-definition sentence, then this step can mark all characters of sentence character string according to type, read corresponding become Measure definition statement.
After the relevant variable definition statement for reading the type mark sentence, further it can be marked according to type in sentence Type and relevant variable definition statement in variable corresponding relation, obtain relative with the type information that step 301-2 is extracted The marking variable answered, the marking variable are the identification informations for referring to the variable in source code described in unique identification.If institute It is a function to state source code, because the variable name of each variable defined in function is all unique, therefore can be with from institute The variable name extracted in variable-definition sentence is stated as marking variable;If the source code includes two or more Function, for the variable defined in function, then it can be used as and become by the use of " function name+extracted from variable-definition sentence variable name " Amount mark.
Step 301-4, institute will be added to by the marking variable obtained and the corresponding relation entry that respective type information forms State in marking variable and the corresponding relation of type.
This step is gone to, according to the type identification sentence and corresponding variable-definition sentence, obtains change Amount mark and type information corresponding with the marking variable, therefore this step can be formed according to the information obtained and corresponded to Relationship entries, and the corresponding relation entry is added in marking variable and the corresponding relation of type.
For example, the type mark sentence read is:“@string,@boolean”;Corresponding variable-definition sentence is Const str=" hello ", isTrue=true;So this step generates two corresponding relation entries as follows, and can So that the two entries to be added in marking variable and the corresponding relation of type.
1)str:string
2)isTrue:boolean
For each sentence in the source code, above-mentioned steps 301-1 is performed to 301-4, and the corresponding of generation is closed It is that entry is all added in marking variable and the corresponding relation of type, then the sentence in the source code is all disposed Afterwards, marking variable and the corresponding relation of type just are generated for the source code.
So far, the generating process of marking variable and the corresponding relation of type is said by a specific example It is bright.In the specific implementation, because the position that type mark sentence is added in source code may be different, type mark sentence pre- If form may also be different, therefore the embodiment for generating the corresponding relation can also have differences, in actual applications, It can accordingly be changed, be adjusted as the case may be on the basis of above-mentioned example.
For example, the form of type mark sentence is character string statement, in other embodiments, type in the above example The form of comment statement can also be used by marking sentence, in this case, can be judged as follows in step 301-1:Institute Predicate sentence whether be comment statement and with@" or "<Beginning characters of-the@" as annotation information.If the sentence currently read Meet the requirement, then it is type mark sentence to illustrate the sentence.The embodiment of other steps is similar with character string statement , here is omitted.
It should be noted that generation marking variable and the method for the corresponding relation of type that the present embodiment provides, can be only It is vertical to implement, it can also implement during being generated by syntax parsing with the source code of grammer tree format storage.I.e.:Passing through During syntax parsing generation is with the source code of grammer tree format storage, the preset format that contains according at least to the source code package Type mark sentence, generate the corresponding relation of marking variable and type.This embodiment is illustrated below.
Generally before source code is performed, syntax parsing can be first carried out.During syntax parsing, source is read sentence by sentence Sentence in code simultaneously determines whether to generate corresponding syntax tree or grammer for the sentence currently read according to preset strategy Tree node.Source code is disposed using aforesaid way, then the source code is converted to the storage of grammer tree format Source code, the source code stored with grammer tree format is compiled, it is possible to generate executable code.
The generation marking variable and the method for the corresponding relation of type that the present embodiment provides, can be merged in above-mentioned grammer solution Completed during analysis.
For example, during being generated by syntax parsing with the source code of grammer tree format storage, for reading sentence by sentence Each sentence, not only perform the processing related to generative grammar tree and operate, also perform operations described below:Whether judge the sentence Sentence is marked for the type of preset format;If so, according to the marking variable extracted from type mark sentence and accordingly Type information generates corresponding relation entry, and is added in the marking variable and the corresponding relation of type.
For another example, during being generated by syntax parsing with the source code of grammer tree format storage, for reading sentence by sentence Each sentence, not only perform the processing related to generative grammar tree and operate, also perform operations described below:Whether judge the sentence Sentence is marked for the type of preset format;If so, extract type information from the sentence;According to the sentence and relevant variable The position relationship of definition statement, read corresponding variable-definition sentence and obtain the variable mark corresponding with the type information extracted Know;The marking variable and type will be added to by the marking variable obtained and the corresponding relation entry that respective type information forms Corresponding relation in.
Using above-mentioned embodiment, by carrying out syntax parsing (process is also commonly referred to as Parse processes) to source code, The source code stored with grammer tree format is not only generated, while also creates marking variable and the corresponding relation of type, so as to Without in order to generate the operation that the corresponding relation additionally performs reading code, being improved in the technical scheme provided using the application While code execution performance, the extra occupancy to processor resource is avoided, parsing is not interfered with, compiles the globality of source code Energy.
By above description as can be seen that the side for generating marking variable and the corresponding relation of type that the present embodiment provides Method, on the basis of the type mark sentence that source code package contains is read, marking variable and type are generated for the source code Corresponding relation, so as to be compiled the executable code that generation carried out after types of variables restriction to be follow-up for source code and carry out Preparation.Due to having extracted the corresponding relation of marking variable and type in advance, compilation process need not performance variable again The parsing operation of type, type of variables information is obtained directly from the correspondence set, can be improved compiled The efficiency of journey.
In the above-described embodiment, there is provided a kind of method for the corresponding relation for generating marking variable and type, therewith phase Corresponding, the application also provides a kind of device for generating marking variable and the corresponding relation of type.Fig. 5 is refer to, it is this Shen A kind of generation marking variable and the schematic diagram of the embodiment of the device of the corresponding relation of type please.Because device embodiment is basic Similar in appearance to embodiment of the method, so describing fairly simple, the relevent part can refer to the partial explaination of embodiments of method.It is following The device embodiment of description is only schematical.
A kind of device of the generation marking variable of the present embodiment and the corresponding relation of type, including:Corresponding relation generation is single Member 501, the type of the preset format for containing according at least to source code package mark sentence, and generation marking variable is corresponding with type Relation, this unit can be used for performing the step 301 in above-mentioned correlation method embodiment;
Correspondence relation storage 502, for storing the corresponding relation of the marking variable that has generated and type, for for Generation carries out the executable code after types of variables restriction when the source code is compiled.
Optionally, the corresponding relation generation unit includes:
Code is read and loop control subelement, for reading the sentence in the source code sentence by sentence, and is directed to each language Sentence triggers following subelement work;
Type marks sentence judgment sub-unit, for judging whether the sentence is type mark sentence;
First corresponding relation entry generates and addition subelement, for marking the defeated of sentence judgment sub-unit when the type When going out to be, corresponding relation entry is generated according to the marking variable and respective type information extracted from the sentence, and add It is added in the marking variable and the corresponding relation of type.
Optionally, the corresponding relation generation unit includes:
Code is read and loop control subelement, for reading the sentence in the source code sentence by sentence, and is directed to each language Sentence triggers following subelement work;
Type mark sentence judgment sub-unit, for judge the sentence whether be preset format type mark sentence;
Type information extracts subelement, and the output for marking sentence judgment sub-unit when the type is when being, from institute Type information is extracted in predicate sentence;
Marking variable obtains subelement, for the position relationship according to the sentence and relevant variable definition statement, reads Corresponding variable-definition sentence simultaneously obtains the marking variable corresponding with the type information extracted;
Second corresponding relation entry generates and addition subelement, for by by the marking variable that obtains and respective type information The corresponding relation list item of composition is added in the marking variable and the corresponding relation of type.
Optionally, the corresponding relation generation unit, specifically for being deposited with grammer tree format being generated by syntax parsing During the source code of storage, the type mark sentence of the preset format contained according at least to the source code package, variable mark is generated Know with the corresponding relation of type, during for being compiled for the source code generation carry out executable after types of variables restriction Code.
In addition, the application also provides a kind of method for improving code execution performance, Fig. 6 is refer to, it is the application A kind of flow chart of the embodiment of the method for the raising code execution performance provided, the present embodiment is therewith in each embodiment of preceding offer Hold identical part to repeat no more, below emphasis difference is described.A kind of raising code execution performance that the application provides Method includes:
Step 601, obtain previously generated for source code, marking variable and the corresponding relation of type.
Before this step is performed, generally marking variable pass corresponding with type is generated for source code in advance System, several corresponding relation entries are generally comprised in the corresponding relation, comprising variable identifies in each corresponding relation entry And corresponding type information.The corresponding relation can be stored in internal memory or be in disk file, and this step is for institute State before source code is compiled, the corresponding relation can be obtained by reading the modes such as internal memory or disk file.
Step 602, according to the corresponding relation, the compilation of source code stored with grammer tree format generation is become Measure the executable code after type limits.
Due to obtaining the corresponding relation of the marking variable previously generated for source code and type in step 601, because This, can be according to the corresponding relation to variable during the source code to being stored with grammer tree format is compiled Type is defined, and generates the executable code after carrying out types of variables restriction, i.e.,:Carry out the executable generation after type optimization Code.
Due to limiting types of variables primarily directed to variable arithmetic statement, thus the present embodiment using variable arithmetic statement as Emphasis, the process for generating executable code is illustrated, in the specific implementation, other can also be directed to using similar method The sentence of type carries out type optimization.
This step can be successively read with each sentence in the source code of grammer tree format storage, and for each Sentence generates corresponding executable code by following steps 602-1 to 602-3, is described in detail with reference to Fig. 7.
Step 602-1, judge whether the sentence meets following condition:The sentence is variable arithmetic statement and wherein A computing variable at least be present has corresponding type information in the corresponding relation, if satisfied, step 602-2 is performed, Otherwise 602-3 is performed.
The main task of this step is:Judge whether to carry out types of variables restriction for the sentence currently read.
Can first identify whether the sentence is variable arithmetic statement, so-called variable arithmetic statement refer to comprising operator and The sentence of computing variable, wherein the operator can be monocular, binocular either ternary operator, corresponding computing variable Number can be one, two or three.
If variable arithmetic statement, then determine whether the variable arithmetic statement at least has a computing and become Amount has corresponding type information in the corresponding relation.When it is implemented, each computing that can be included according to the sentence Variable is searched in the corresponding relation that step 601 obtains, if with the marking variable of certain computing variable corresponding to it is corresponding Relationship entries, then read type information therein.After performing above-mentioned search operation, if at least one computing variable is described There is corresponding type information in corresponding relation, then can performs step 602-2.
If the sentence is unsatisfactory for above-mentioned two condition, step 602-3 is performed.
Step 602-2, the computing type of variables letter included according to sentence obtained from the corresponding relation, described Breath, generation carry out the executable code after types of variables restriction for the sentence.
Go to this step, explanation can be directed to the sentence and carry out types of variables restriction, therefore this step is according to from institute The computing type of variables information that sentence obtained in corresponding relation, described includes is stated, after generation carries out types of variables restriction Executable code.
In the specific implementation, the efficient finger for the type that platform can be selected to provide according to computing type of variables Order, such as on certain platform, integer adds computing to be instructed using add, and floating type adds computing to be instructed using addf, to have in this specification The z=x+y that body embodiment beginning provides;Exemplified by arithmetic statement, this step can obtain according to from the corresponding relation X, y type of variables taken generates corresponding executable code, for example, understanding that x is integer and y is whole according to the corresponding relation Type, i.e., x and y type are defined, then generating corresponding executable code is:add z,x,y;For another example, according to institute X knowable to stating corresponding relation is integer, y is double-precision floating point type, then generating corresponding executable code is:addf z,x,y.
As can be seen here, z=x+y arithmetic statements are directed to what is above provided in this specification embodiment beginning The executable code of generation compares, carry out the executable code that generates after types of variables restriction there is no substantial amounts of branch to judge with And the different instruction code for each branch, but only generate an executable code, and using with computing class The special efficient operational order that type matches, therefore the memory headroom of executable statement occupancy is not only reduced, and can be with The execution speed of executable code is improved, so that overall execution performance is improved.
It should be noted that above for readily appreciating, given only for add operation after carrying out types of variables restriction A schematical example of executable code is generated, can be according to platform and arithmetic type when actually implementing this method Difference, be selected differently from other above-mentioned powerful instructions and generate corresponding executable code.
Step 602-3, the executable code of types of variables restriction is not carried out for sentence generation.
Go to this step, illustrate the sentence be not variable arithmetic statement or be variable arithmetic statement but wherein Comprising computing variable in the corresponding relation all without corresponding type information, in such a case, it is possible to using conventional Mode generates the executable code for not carrying out types of variables restriction.
For each sentence in the source code that is stored with grammer tree format, above-mentioned steps 602-1 is performed extremely successively 602-3 processing, so as to the corresponding relation obtained using step 601, the source generation that will be stored with grammer tree format Code compiling generation carries out the executable code after types of variables restriction.
In the specific implementation, can be with after generation executable code (being referred to as intermediate code or local code) The executable code is directly run by the compiler or engine of implementation this method, other actuators can also be called to run institute State executable code.Because during the executable code is generated, the type information in corresponding relation is to corresponding Type of variables is defined, therefore the executable code generated not only diminishes in committed memory space, and performs speed Can accordingly it accelerate, overall execution performance significantly improves.
In the above-described embodiment, there is provided a kind of method for improving code execution performance, corresponding, the application A kind of device for improving code execution performance is also provided.Fig. 8 is refer to, it is a kind of raising code execution performance of the application The schematic diagram of the embodiment of device.Because device embodiment is substantially similar to embodiment of the method, so describe fairly simple, phase Part is closed referring to the part of embodiment of the method to illustrate.Device embodiment described below is only schematical.
A kind of device of the raising code execution performance of the present embodiment, including:Corresponding relation acquiring unit 801, for obtaining Previously generated for source code, marking variable and the corresponding relation of type are taken, this unit can be used for performing above-mentioned correlation method Step 601 in embodiment;
Executable code generation unit 802, for according to the corresponding relation, the source that will be stored with grammer tree format Code compilation generation carries out the executable code after types of variables restriction, and this unit can be used for performing above-mentioned correlation method embodiment In step 602.
Optionally, described device also includes:Corresponding relation generation unit;
The corresponding relation generation unit, the type of the preset format for containing according at least to the source code package mark language Sentence, generates the marking variable and the corresponding relation of type.
Optionally, the corresponding relation generation unit, including:
Code is read and loop control subelement, for reading the sentence in the source code sentence by sentence, and is directed to each language Sentence triggers following subelement work;
Type mark sentence judgment sub-unit, for judge the sentence whether be preset format type mark sentence;
First corresponding relation entry generates and addition subelement, for marking the defeated of sentence judgment sub-unit when the type When going out to be, corresponding relation entry is generated according to the marking variable and respective type information extracted from the sentence, and add It is added in the marking variable and the corresponding relation of type.
Optionally, the corresponding relation generation unit, including:
Code is read and loop control subelement, for reading the sentence in the source code sentence by sentence, and is directed to each language Sentence triggers following subelement work;
Type mark sentence judgment sub-unit, for judge the sentence whether be preset format type mark sentence;
Type information extracts subelement, and the output for marking sentence judgment sub-unit when the type is when being, from institute Type information is extracted in predicate sentence;
Marking variable obtains subelement, for the position relationship according to the sentence and relevant variable definition statement, reads Corresponding variable-definition sentence simultaneously obtains the marking variable corresponding with the type information extracted;
Second corresponding relation entry generates and addition subelement, for by by the marking variable that obtains and respective type information The corresponding relation entry of composition is added in the marking variable and the corresponding relation of type.
Optionally, the corresponding relation generation unit, specifically for described with syntax tree lattice by syntax parsing generation During the source code of formula storage, the type mark sentence of the preset format contained according at least to the source code package is raw Into the marking variable and the corresponding relation of type.
Optionally, the executable code generation unit, including:
Loop control subelement, for reading sentence by sentence with the sentence in the source code of grammer tree format storage, and pin Following subelement work is triggered to each sentence;
Optimal conditions judgment sub-unit, for judging whether the sentence meets following condition:The sentence is transported for variable Calculating sentence and a computing variable being wherein at least present has corresponding type information in the corresponding relation;
Optimized code generates subelement, for when the output of the optimal conditions judgment sub-unit is is, according to from institute The computing type of variables information that sentence obtained in corresponding relation, described includes is stated, generation carries out variable for the sentence Executable code after type restriction;
Conventional code generate subelement, for when the optimal conditions judgment sub-unit output for it is no when, for described Sentence generates the executable code for not carrying out types of variables restriction.
Optionally, described device also includes:
Executable code execution unit, for performing the executable code.
Although the application is disclosed as above with preferred embodiment, it is not for limiting the application, any this area skill Art personnel are not being departed from spirit and scope, can make possible variation and modification, therefore the guarantor of the application Shield scope should be defined by the scope that the application claim is defined.
In a typical configuration, computing device includes one or more processors (CPU), input/output interface, net Network interface and internal memory.
Internal memory may include computer-readable medium in volatile memory, random access memory (RAM) and/or The forms such as Nonvolatile memory, such as read-only storage (ROM) or flash memory (flash RAM).Internal memory is computer-readable medium Example.
1st, computer-readable medium can be by any side including permanent and non-permanent, removable and non-removable media Method or technology realize that information stores.Information can be computer-readable instruction, data structure, the module of program or other numbers According to.The example of the storage medium of computer includes, but are not limited to phase transition internal memory (PRAM), static RAM (SRAM), dynamic random access memory (DRAM), other kinds of random access memory (RAM), read-only storage (ROM), Electrically Erasable Read Only Memory (EEPROM), fast flash memory bank or other memory techniques, read-only optical disc are read-only Memory (CD-ROM), digital versatile disc (DVD) or other optical storages, magnetic cassette tape, tape magnetic rigid disk storage or Other magnetic storage apparatus or any other non-transmission medium, the information that can be accessed by a computing device available for storage.According to Herein defines, and computer-readable medium does not include non-temporary computer readable media (transitory media), such as modulates Data-signal and carrier wave.
2nd, it will be understood by those skilled in the art that embodiments herein can be provided as method, system or computer program production Product.Therefore, the application can use the embodiment in terms of complete hardware embodiment, complete software embodiment or combination software and hardware Form.Moreover, the application can use the computer for wherein including computer usable program code in one or more can use The computer program product that storage medium is implemented on (including but is not limited to magnetic disk storage, CD-ROM, optical memory etc.) Form.

Claims (31)

  1. A kind of 1. method for improving code execution performance, it is characterised in that including:
    Obtain previously generated for source code, marking variable and the corresponding relation of type;
    According to the corresponding relation, the compilation of source code stored with grammer tree format is generated after carrying out types of variables restriction Executable code.
  2. 2. according to the method for claim 1, it is characterised in that obtain previously generated for source code, variable described Before the corresponding relation of mark and type, including:
    The type mark sentence of the preset format contained according at least to the source code package, generates the marking variable and pair of type It should be related to.
  3. 3. according to the method for claim 2, it is characterised in that the class of the preset format contained according at least to the source code package Type marks sentence, generates the marking variable and the corresponding relation of type, including:
    The sentence in the source code is read sentence by sentence, and operations described below is performed for each sentence:
    Judge the sentence whether be preset format type mark sentence;
    If so, perform operations described below:Generated according to the marking variable and respective type information extracted from the sentence corresponding Relationship entries, and be added in the marking variable and the corresponding relation of type.
  4. 4. according to the method for claim 2, it is characterised in that the class of the preset format contained according at least to the source code package Type marks sentence, generates the marking variable and the corresponding relation of type, including:
    The sentence in the source code is read sentence by sentence, and operations described below is performed for each sentence:
    Judge the sentence whether be preset format type mark sentence;
    If so, perform operations described below:Type information is extracted from the sentence;According to the sentence and relevant variable definition statement Position relationship, read corresponding variable-definition sentence and obtain the corresponding marking variable of type information with extraction;Will be by The marking variable of acquisition and the corresponding relation entry that respective type information forms are added to the corresponding of the marking variable and type In relation.
  5. 5. according to the method for claim 4, it is characterised in that the sentence and the position of relevant variable definition statement are closed System, including:
    The sentence is adjacent with relevant variable definition statement and before the variable-definition sentence or afterwards.
  6. 6. the method according to claim 3 or 4, it is characterised in that the form of the type mark sentence includes:Character string Sentence, or comment statement.
  7. 7. according to the method for claim 2, it is characterised in that deposited by the way that syntax parsing generation is described with grammer tree format During the source code of storage, the type mark sentence of the preset format contained according at least to the source code package, institute is generated State marking variable and the corresponding relation of type.
  8. 8. according to the method for claim 1, it is characterised in that it is described according to the corresponding relation, will be with grammer tree format The compilation of source code generation of storage carries out the executable code after types of variables restriction, including:
    Read sentence by sentence with the sentence in the source code of grammer tree format storage, and operations described below is performed for each sentence:
    Judge whether the sentence meets following condition:The sentence is variable arithmetic statement and a fortune wherein at least be present Calculate variable has corresponding type information in the corresponding relation;
    If satisfied, the computing type of variables information included according to sentence obtained from the corresponding relation, described, generates pin Executable code after types of variables restriction is carried out to the sentence;
    Otherwise, the executable code of types of variables restriction is not carried out for sentence generation.
  9. 9. according to the method for claim 1, it is characterised in that also include:
    Perform the executable code.
  10. 10. according to the method described in claim any one of 1-9, it is characterised in that the source code is compiled with weak type language Write;The weak type language includes:JavaScript language.
  11. A kind of 11. device for improving code execution performance, it is characterised in that including:
    Corresponding relation acquiring unit, for obtaining the corresponding relation of previously generated for source code, marking variable and type;
    Executable code generation unit, for according to the corresponding relation, the source code stored with grammer tree format to be compiled Translate generation and carry out the executable code after types of variables restriction.
  12. 12. device according to claim 11, it is characterised in that also include:Corresponding relation generation unit;
    The corresponding relation generation unit, the type of the preset format for containing according at least to the source code package mark sentence, Generate the marking variable and the corresponding relation of type.
  13. 13. device according to claim 12, it is characterised in that the corresponding relation generation unit, including:
    Code is read and loop control subelement, is touched for reading the sentence in the source code sentence by sentence, and for each sentence Give the work of row subelement;
    Type mark sentence judgment sub-unit, for judge the sentence whether be preset format type mark sentence;
    First corresponding relation entry generates and addition subelement, for being when the output of type mark sentence judgment sub-unit When being, corresponding relation entry is generated according to the marking variable and respective type information extracted from the sentence, and be added to In the marking variable and the corresponding relation of type.
  14. 14. device according to claim 12, it is characterised in that the corresponding relation generation unit, including:
    Code is read and loop control subelement, is touched for reading the sentence in the source code sentence by sentence, and for each sentence Give the work of row subelement;
    Type mark sentence judgment sub-unit, for judge the sentence whether be preset format type mark sentence;
    Type information extracts subelement, and the output for marking sentence judgment sub-unit when the type is when being, from institute's predicate Type information is extracted in sentence;
    Marking variable obtains subelement, for the position relationship according to the sentence and relevant variable definition statement, reads corresponding Variable-definition sentence and obtain the corresponding marking variable of type information with extraction;
    Second corresponding relation entry generates and addition subelement, for will be made up of the marking variable obtained with respective type information Corresponding relation entry be added in the marking variable and the corresponding relation of type.
  15. 15. device according to claim 12, it is characterised in that the corresponding relation generation unit, specifically for logical During crossing the syntax parsing generation source code stored with grammer tree format, contain according at least to the source code package Preset format type mark sentence, generate the marking variable and the corresponding relation of type.
  16. 16. device according to claim 11, it is characterised in that the executable code generation unit, including:
    Loop control subelement, for reading sentence by sentence with the sentence in the source code of grammer tree format storage, and for every Individual sentence triggers following subelement work;
    Optimal conditions judgment sub-unit, for judging whether the sentence meets following condition:The sentence is variable computing language Sentence and a computing variable wherein at least be present there is corresponding type information in the corresponding relation;
    Optimized code generates subelement, for when the output of the optimal conditions judgment sub-unit is is, according to from described right Computing type of variables information that middle acquisition should be related to, that the sentence includes, generation carry out types of variables for the sentence Executable code after restriction;
    Conventional code generate subelement, for when the optimal conditions judgment sub-unit output for it is no when, for the sentence Generation does not carry out the executable code of types of variables restriction.
  17. 17. device according to claim 11, it is characterised in that also include:
    Executable code execution unit, for performing the executable code.
  18. A kind of 18. method for generating marking variable and the corresponding relation of type, it is characterised in that including:
    The type mark sentence of the preset format contained according at least to source code package, generates marking variable and the corresponding relation of type, Generation carries out the executable code after types of variables restriction during for being compiled for the source code.
  19. 19. according to the method for claim 18, it is characterised in that the preset format contained according at least to source code package Type marks sentence, generates the marking variable and the corresponding relation of type, including:
    The sentence in the source code is read sentence by sentence, and operations described below is performed for each sentence:
    Judge the sentence whether be preset format type mark sentence;
    If so, perform operations described below:Generated according to the marking variable and respective type information extracted from the sentence corresponding Relationship entries, and be added in the marking variable and the corresponding relation of type.
  20. 20. according to the method for claim 18, it is characterised in that the preset format contained according at least to source code package Type marks sentence, generates the variable and the corresponding relation of type, including:
    The sentence in the source code is read sentence by sentence, and operations described below is performed for each sentence:
    Judge the sentence whether be preset format type mark sentence;
    If so, perform operations described below:Type information is extracted from the sentence;According to the sentence and relevant variable definition statement Position relationship, read corresponding variable-definition sentence and obtain the corresponding marking variable of type information with extraction;Will be by The marking variable of acquisition and the corresponding relation entry that respective type information forms are added to the corresponding of the marking variable and type In relation.
  21. 21. according to the method for claim 20, it is characterised in that the sentence and the position of relevant variable definition statement are closed System includes:
    The sentence is adjacent with relevant variable definition statement and before the variable-definition sentence or afterwards.
  22. 22. the method according to claim 19 or 20, it is characterised in that the form of the type mark sentence includes:Word Accord with string statement, or comment statement.
  23. 23. according to the method for claim 18, it is characterised in that stored being generated by syntax parsing with grammer tree format Source code during, the type of the preset format contained according at least to the source code package mark sentence, generate marking variable With the corresponding relation of type, during for being compiled for the source code generation carry out the executable generation after types of variables restriction Code.
  24. A kind of 24. device for generating marking variable and the corresponding relation of type, it is characterised in that including:
    Corresponding relation generation unit, the type of the preset format for containing according at least to source code package mark sentence, generate variable The corresponding relation of mark and type;
    Correspondence relation storage, for storing the corresponding relation of the marking variable generated and type, for for the source Generation carries out the executable code after types of variables restriction when code is compiled.
  25. 25. device according to claim 24, it is characterised in that the corresponding relation generation unit includes:
    Code is read and loop control subelement, is touched for reading the sentence in the source code sentence by sentence, and for each sentence Give the work of row subelement;
    Type marks sentence judgment sub-unit, for judging whether the sentence is type mark sentence;
    First corresponding relation entry generates and addition subelement, for being when the output of type mark sentence judgment sub-unit When being, corresponding relation entry is generated according to the marking variable and respective type information extracted from the sentence, and be added to In the marking variable and the corresponding relation of type.
  26. 26. device according to claim 24, it is characterised in that the corresponding relation generation unit includes:
    Code is read and loop control subelement, is touched for reading the sentence in the source code sentence by sentence, and for each sentence Give the work of row subelement;
    Type mark sentence judgment sub-unit, for judge the sentence whether be preset format type mark sentence;
    Type information extracts subelement, and the output for marking sentence judgment sub-unit when the type is when being, from institute's predicate Type information is extracted in sentence;
    Marking variable obtains subelement, for the position relationship according to the sentence and relevant variable definition statement, reads corresponding Variable-definition sentence and obtain the corresponding marking variable of type information with extraction;
    Second corresponding relation entry generates and addition subelement, for will be made up of the marking variable obtained with respective type information Corresponding relation list item be added in the marking variable and the corresponding relation of type.
  27. 27. device according to claim 24, it is characterised in that the corresponding relation generation unit, specifically for logical During syntax parsing generation is crossed with the source code of grammer tree format storage, the default lattice that contain according at least to the source code package The type mark sentence of formula, generates marking variable and the corresponding relation of type, for being given birth to when being compiled for the source code Executable code into after progress types of variables restriction.
  28. A kind of 28. method for being used to generate the source code of containing type mark sentence, it is characterised in that including:
    Receive type for source code input, for specifying variable type and mark sentence;
    According to the type mark sentence received and its input position in the source code, the type is marked into sentence Store in the source code;
    Wherein, the type mark sentence is preset format.
  29. 29. according to the method for claim 28, it is characterised in that the form of the type mark sentence includes:Character string Sentence, or comment statement.
  30. 30. the method according to claim 28 or 29, it is characterised in that the source code is write using weak type language 's;The weak type language includes:JavaScript language.
  31. A kind of 31. device for being used to generate the source code of containing type markup information, it is characterised in that including:
    Type marks sentence receiving unit, is marked for receiving type for source code input, for specifying variable type Sentence, wherein, the type mark sentence is preset format;
    Type marks sentence memory cell, for according to the type mark sentence and its defeated in the source code received Enter position, by type mark sentence storage into the source code.
CN201610430445.2A 2016-06-16 2016-06-16 Method and device for improving code execution performance Active CN107515739B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610430445.2A CN107515739B (en) 2016-06-16 2016-06-16 Method and device for improving code execution performance

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610430445.2A CN107515739B (en) 2016-06-16 2016-06-16 Method and device for improving code execution performance

Publications (2)

Publication Number Publication Date
CN107515739A true CN107515739A (en) 2017-12-26
CN107515739B CN107515739B (en) 2021-02-26

Family

ID=60720486

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610430445.2A Active CN107515739B (en) 2016-06-16 2016-06-16 Method and device for improving code execution performance

Country Status (1)

Country Link
CN (1) CN107515739B (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109710304A (en) * 2018-12-27 2019-05-03 潍柴动力股份有限公司 A kind of Format adjusting method and device
CN110018829A (en) * 2019-04-01 2019-07-16 北京东方国信科技股份有限公司 Improve the method and device of PL/SQL language interpreter execution efficiency
CN110347576A (en) * 2018-04-04 2019-10-18 阿里巴巴集团控股有限公司 Pseudocode adjustment method and device
CN110659200A (en) * 2018-06-29 2020-01-07 中国航发商用航空发动机有限责任公司 Method and system for comparing and analyzing source code and target code of airborne software
CN113157256A (en) * 2021-03-25 2021-07-23 北京达佳互联信息技术有限公司 Interface code generation method and device, electronic equipment, storage medium and product
CN114489859A (en) * 2022-02-11 2022-05-13 浙江吉利控股集团有限公司 Script code execution method and device, storage medium and equipment

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2007082830A1 (en) * 2006-01-17 2007-07-26 International Business Machines Corporation System and method for storing text annotations with associated type information in a structured data store
CN101689112A (en) * 2007-06-21 2010-03-31 微软公司 Late bound programmatic assistance
CN104115120A (en) * 2012-02-07 2014-10-22 微软公司 Transferring program execution from compiled code to interpreted code
CN106133684A (en) * 2014-03-27 2016-11-16 微软技术许可有限责任公司 Support the dynamic behaviour in static compilation program

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2007082830A1 (en) * 2006-01-17 2007-07-26 International Business Machines Corporation System and method for storing text annotations with associated type information in a structured data store
CN101689112A (en) * 2007-06-21 2010-03-31 微软公司 Late bound programmatic assistance
CN104115120A (en) * 2012-02-07 2014-10-22 微软公司 Transferring program execution from compiled code to interpreted code
CN106133684A (en) * 2014-03-27 2016-11-16 微软技术许可有限责任公司 Support the dynamic behaviour in static compilation program

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110347576A (en) * 2018-04-04 2019-10-18 阿里巴巴集团控股有限公司 Pseudocode adjustment method and device
CN110347576B (en) * 2018-04-04 2023-09-12 创新先进技术有限公司 Pseudo code debugging method and device
CN110659200A (en) * 2018-06-29 2020-01-07 中国航发商用航空发动机有限责任公司 Method and system for comparing and analyzing source code and target code of airborne software
CN109710304A (en) * 2018-12-27 2019-05-03 潍柴动力股份有限公司 A kind of Format adjusting method and device
CN109710304B (en) * 2018-12-27 2022-06-24 潍柴动力股份有限公司 Format adjustment method and device
CN110018829A (en) * 2019-04-01 2019-07-16 北京东方国信科技股份有限公司 Improve the method and device of PL/SQL language interpreter execution efficiency
CN110018829B (en) * 2019-04-01 2022-11-11 北京东方国信科技股份有限公司 Method and device for improving execution efficiency of PL/SQL language interpreter
CN113157256A (en) * 2021-03-25 2021-07-23 北京达佳互联信息技术有限公司 Interface code generation method and device, electronic equipment, storage medium and product
CN113157256B (en) * 2021-03-25 2024-03-19 北京达佳互联信息技术有限公司 Method and device for generating interface code, electronic equipment, storage medium and product
CN114489859A (en) * 2022-02-11 2022-05-13 浙江吉利控股集团有限公司 Script code execution method and device, storage medium and equipment

Also Published As

Publication number Publication date
CN107515739B (en) 2021-02-26

Similar Documents

Publication Publication Date Title
Kuchaiev et al. Nemo: a toolkit for building ai applications using neural modules
CN107515739A (en) Improve the method and device of code execution performance
CN112100054B (en) Data management and control oriented program static analysis method and system
EP3631618B1 (en) Automated dependency analyzer for heterogeneously programmed data processing system
CN104536898B (en) The detection method of c program parallel regions
CN109491658A (en) The generation method and device of computer-executable code data
CN107704382B (en) Python-oriented function call path generation method and system
US7917899B2 (en) Program development apparatus, method for developing a program, and a computer program product for executing an application for a program development apparatus
CN107943691A (en) A kind of method and device for the functional test page for automatically generating intelligent contract
CN110149800A (en) It is a kind of for handling the device of abstract syntax tree associated with the source code of source program
CN109634869A (en) Binary translation intermediate representation correctness test method and device based on semantic equivalence verifying
Roesch et al. Relay: A high-level compiler for deep learning
CN108563561B (en) Program implicit constraint extraction method and system
CN107015841A (en) The preprocess method and program compiling equipment of a kind of program compiling
CN113031932A (en) Project development method and device, electronic equipment and storage medium
CN106598828A (en) Method and device for determining invalid class in source code
CN110096264A (en) A kind of code operation method and device
CN110032363A (en) A kind of data structure construction method and system for robotic programming
Pleban Compiler prototyping using formal semantics
CN109032946B (en) Test method and device and computer readable storage medium
Murawski et al. A contextual equivalence checker for IMJ
Cogumbreiro et al. Memory access protocols: certified data-race freedom for GPU kernels
CN109960497A (en) Call method and device between a kind of script file
CN113448874A (en) Method and device for generating unit test script
CN109117142A (en) A kind of fundamental type reconstructing method based on variable association tree

Legal Events

Date Code Title Description
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 1248345

Country of ref document: HK

TA01 Transfer of patent application right

Effective date of registration: 20201130

Address after: Room 603, 6 / F, Roche Plaza, 788 Cheung Sha Wan Road, Kowloon, China

Applicant after: Zebra smart travel network (Hong Kong) Limited

Address before: A four-storey 847 mailbox in Grand Cayman Capital Building, British Cayman Islands

Applicant before: Alibaba Group Holding Ltd.

TA01 Transfer of patent application right
GR01 Patent grant
GR01 Patent grant