Source code that is used to create software applications may be compiled in a dynamic environment. In a dynamic environment, contextual information (e.g., the number and content of external references) that is needed by the compiler to successfully compile the source code can change. As a result, the contextual information may not easily be captured in a static (e.g., unchanging) context. Compilers typically require a programmer to provide all context information up front, i.e. prior to source code compilation. This context information typically includes a set of references and a number of compiler options. If the source code includes a token that is not found in the set of references provided to the compiler, the compilation process may fail unless additional (e.g., dynamic) information is provided to the compiler. However, it may be inconvenient and inefficient to generate all possible dynamic context information each time a compiler compiles source code that includes tokens associated with dynamic references.
The present disclosure describes dynamic resolution of tokens present in source code (e.g., references to types, namespaces, and variables) during source code compilation. A compiler that performs source code compilation may have an associated static context (e.g., source files, reference assemblies, and compiler options) and an associated dynamic context. Rather than providing all dynamic context information to the compiler up front (e.g., “pushing” all of the dynamic information), an initial dynamic context may be kept small. During compilation, relevant dynamic context items (i.e., items that are referenced by the source code being compiled) may be provided to the compiler as needed (e.g., the compiler “pulls” the dynamic information related to source code segments, as needed). In one implementation, token resolution interfaces, such as a type resolution interface and a variable resolution interface, are provided to users (e.g., software developers) as part of a compiler. Users may create custom classes that implement the interfaces. For example, the custom classes may identify dynamic context items that may be used to resolve tokens. When the compiler encounters a token that the compiler does not “understand” (e.g., the token is not a reserved keyword of the compiler), the compiler queries the static context and the dynamic context. The static and dynamic contexts may return one or more lookup results of the token. A particular returned lookup result is selected and used to resolve the token. The particular lookup result used to resolve the token is selected independently of whether the particular lookup result was sourced from the static context or from the dynamic context.
This Summary is provided to introduce a selection of concepts in a simplified form that are further described below in the Detailed Description. This Summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
In a particular embodiment, a computer-implemented method includes, during compilation of a portion of source code at a compiler, initiating token resolution with respect to a token included in the portion of source code. The method also includes querying a static context of the compiler and a dynamic context of the compiler to identify one or more lookup results of the token. The method further includes selecting a particular lookup result to resolve the token based on one or more semantic rules of the compiler. The particular lookup result is selected independently of whether the particular lookup result is sourced from the static context or from the dynamic context. The method includes resolving the token based on the selected particular lookup result.
In another particular embodiment, a computer system includes a processor and a compiler executable by the processor to initiate compilation of a portion of source code. The compiler is also executable to initiate token resolution with respect to a first token and a second token included in the portion of the source code. The compiler is further executable to query a static context of the compiler and a dynamic context of the compiler to identify one or more lookup results of the first token. The compiler is also executable to query the static context and the dynamic context to identify one or more lookup results of the second token. The compiler is executable to select a first particular lookup result of the first token based on one or more semantic rules of the compiler. The first particular lookup result is selected independently of whether the first particular lookup result is sourced from the static context or from the dynamic context. The compiler is further executable to select a second particular lookup result of the second token based on one or more semantic rules of the compiler. The second particular lookup result is selected independently of whether the second particular lookup result is sourced from the static context or from the dynamic context. The compiler is also executable to resolve the first token based on the selected first particular lookup result and to resolve the second token based on the selected second particular lookup result. The compiler is further executable to generate a compilation result.
In another particular embodiment, a computer-readable storage medium includes instructions that when executed by a computer system, cause the computer system to, during compilation of a portion of source code at a compiler, initiate token resolution with respect to a token included in the portion of source code. The instructions also cause the computer system to query a static context of the compiler and a dynamic context of the compiler to identify one or more lookup results of the token. The instructions further cause the computer system to select a particular lookup result to resolve the token based on one or more semantic rules of the compiler. The particular lookup result is selected independently of whether the particular lookup result is sourced from the static context or from the dynamic context. The instructions cause the computer system to resolve the token based on the particular lookup result.
Referring to
The static context 110 of the compiler 140 may include one or more reference assemblies 112, one or more source files 114, one or more compiler options 116, other types of static context items, or any combination thereof. For example, the one or more reference assemblies 112 may include user-provided reference assemblies, default reference assemblies, or any combination thereof.
The dynamic context 120 of the compiler 140 may generally include context items that are not easily captured in the static context 110 of the compiler 140. Dynamic token resolution as disclosed herein may be performed based on implementations (e.g., user-defined implementations) of one or more token resolution interfaces. In a particular embodiment, the one or more token resolution interfaces include a type resolution interface and a variable resolution interface (e.g., provided by the compiler 140). For example, the dynamic context 120 may include one or more token resolution interface implementations 122.
The compiler 140 may include token lookup logic 144 and token resolution logic 146. In a particular embodiment, the token lookup logic 144 is operable to query the static context 110 and the dynamic context 120 (e.g., in response to determining that a particular token is not a reserved keyword of the compiler 140). For example, querying the static context 110 may result in one or more static context items 118. As another example, querying the dynamic context 120 may result in one or more dynamic context items 126. In a particular embodiment, querying the dynamic context 120 results in the creation of the dynamic context items 126, where the dynamic context items 126 are identified by the token resolution interface implementations 122. The created dynamic context items 126 may optionally be cached, so that the compiler 140 may subsequently resolve the token without further querying of the token resolution interface implementations 122. The static context items 118 and the dynamic context items 126 may be aggregated to form the lookup results 130. The token resolution logic 146 may select a particular lookup result of the lookup results 130 to resolve the token, where the particular lookup result is selected independently of whether the particular lookup result was sourced from the static context 110 or from the dynamic context 120. The token lookup logic 144 and the token resolution logic 146 may operate in accordance with semantic rules of the compiler 142.
In a particular embodiment, operation at the system 100 may include the compiler 140 compiling one or more source code portions 102. The source code portions 102 may represent one or more complete source files (e.g., the source files 114) or portions of one or more source files. The source code portions 102 may include one or more tokens 104 that undergo a token resolution process during compilation by the compiler 140. In a particular embodiment, token resolution is initiated for tokens that are not reserved keywords of the compiler 140. For example, upon initiation of the token resolution process, the token lookup logic 144 may query the static context 110 and the dynamic context 120. The token lookup logic 144 may make the queries in accordance with semantic rules 142 of the compiler 140. In response to the queries, the compiler 140 may receive one or more static context items 118 and one or more dynamic context items 126. The one or more static context items 118 and one or more dynamic context items 126 may be aggregated to form the lookup results 130 of the tokens 104.
The token resolution logic 146 may select, for each of the tokens 104, a particular lookup result from the returned lookup results 130 based on the semantic rules 142 of the compiler 140. For example, the lookup results 130 may include a potential type, a potential namespace, and/or a potential variable that the token could be referring to. The semantic rules 142 may indicate how to select between the potential type, the potential namespace, and/or the potential variable (e.g., based on the location of the token in the source code or based on how the token is being used in the source code). The particular lookup results are selected independent of source (i.e., independently of whether they were returned by the static context 110 or by the dynamic context 120). The selected particular lookup results may be used by the compiler 140 in generating a compiler result 150, where the compiler result 150 includes representations 152 of the resolved tokens 104. A compiler result 150 may be created for each of the source code portions 102. For example, the source code portions 102 may include N (where N is a positive integer) class source files and the compiler 140 may generate a separate compiled class binary for each of the N class source files.
The dynamic context items 126 may include namespaces, types, variables, and other dynamic context items. The dynamic context items 126 may be used to resolve the tokens 104. For example, the dynamic context items 126 may include definitions or other syntactical/semantic information of the tokens 104. In a particular embodiment, when a “new” (e.g., previously unencountered) dynamic context item is returned by the token resolution interface implementations 122, the “new” dynamic context item is cached at the dynamic context 120. Cached dynamic context items may be available to the compiler 140 for the remainder of the compilation process and may be used to resolve subsequently encountered tokens, thereby reducing a total number of queries of the token resolution interface implementations. Thus, the dynamic context 120 may “grow” as needed during the compilation process.
For example, there may be a type, a variable, and a namespace each having the name “x.” The first time “x” is encountered during compilation, three dynamic context items may be returned: a type, a variable, and a namespace. Each of the three dynamic context items may be cached. Subsequent queries for “x” may return all three cached dynamic context items. Each time another instance of “x” is encountered, the appropriate cached dynamic context item (type, variable, or namespace) may be selected, based on the semantic rules 142 of the compiler, to resolve that particular instance of “x.”
It should be noted that the descriptions of operation at the system 100 provided herein are for exemplary purposes only and are not to be limiting. The system 100 may also include other embodiments and operations. For example, querying the static context 110 and the dynamic context 120 for a particular token may result in both static context items and dynamic context items, one of static context items or dynamic context items but not the other, or neither static context items nor dynamic context items. When neither static context items nor dynamic context items are returned, the compiler 140 may use an alternate lookup procedure in accordance with the semantic rules 142 or may return a compiler error. The compiler 140 may also use an alternate lookup procedure in accordance with the semantic rules 142 or may return a compiler error when ambiguous lookup results are returned. In yet another embodiment, even though static context item(s) and/or dynamic context item(s) are returned, the semantic rules 142 may indicate that none of the returned context items are appropriate to resolve the token.
In one embodiment, the source code portions 102 include Visual Basic .Net source code. In the case of Visual Basic .Net source code, the source code portions 102 may include one or more extensible markup language (XML) expressions, one or more language integrated query (LINQ) expressions, or any combination thereof. It should be noted that Visual Basic .Net is merely an example of a computer language. Dynamic token resolution as disclosed herein may be performed in conjunction with any computer language.
As an illustrative example, one or more of the source code portions 102 may include “MyType.MySharedMember,” and the token resolution interface implementations 122 may describe how to resolve the token “MyType.” The following sample code illustrates a particular embodiment of an implementation of a type resolution interface “ITypeScope.” The type resolution interface “ITypeScope” may be provided by a compiler, and a user (e.g., a programmer) may choose whether or not to implement the type resolution interface.
As another illustrative example, one or more of the source code portions 102 may include the source code “x+2,” and the token resolution interface implementations 122 may describe how to resolve the token “x.” The following sample code illustrates a particular embodiment of an implementation of a variable resolution interface “IScriptScope.” The variable resolution interface “IScriptScope” may be provided by a compiler, and a user (e.g., a programmer) may choose whether or not to implement the variable resolution interface.
It will be appreciated that the system 100 of
It will also be appreciated that dynamic token resolution as illustrated in
Referring to
The method 200 includes, during compilation of a portion of source code at a compiler, initiating token resolution with respect to a token included in the portion of source code based on one or more semantic rules of the compiler, at 202. For example, in
The method 200 includes querying a static context of the compiler for first possible lookup result(s) of the token, at 204, and querying a dynamic context of the compiler for second possible lookup result(s) of the token, at 206. In a particular embodiment, the static context includes reference assemblies, source code, and compiler options. In a particular embodiment, the dynamic context includes implementations of one or more token resolution interfaces. The queries may result in zero or more static context items and zero or more dynamic context items. When neither static context items nor dynamic context items are returned, the method 200 may include executing some other token lookup procedure or outputting a compiler error in accordance with the semantic rules of the compiler. Alternately, the queries may result in only static context item(s) being returned, only dynamic context item(s) being returned, or both static context item(s) and dynamic context item(s) being returned. To illustrate, a dynamic context item identified by the implementation of “ITypeScope” described with reference to
When the queries return at least one lookup result (e.g., at least one static context item or at least one dynamic context item), the method 200 further includes selecting a particular lookup result to resolve the token based on one or more semantic rules of the compiler, at 208. The particular lookup result is selected independently of whether the particular lookup result is sourced from the static context or from the dynamic context. For example, in
The method 200 includes resolving the token based on the selected particular lookup result, at 210. During compilation, the compiler may encounter additional tokens that are to be resolved. The method 200 may return to 202 when such additional tokens are encountered. For example, a second token (e.g., “x”) included in the portion of source code may be encountered. The compiler may query the static context and the dynamic context for lookup results of the second token. When at least one lookup result of the second token is returned, a second particular lookup result may be selected to resolve the second token based on the semantic rules of the compiler. To illustrate, when the token is “x,” the second particular lookup result may be provided by the implementation of “IScriptScope” described with reference to
The method 200 includes generating a compilation result, at 212. In a particular embodiment, the compilation result includes representation(s) of resolved token(s). For example, in
It will be appreciated that the method 200 of
The computing device 310 includes at least one processor 320 and a system memory 330. Depending on the configuration and type of computing device, the system memory 330 may be volatile (such as random access memory or “RAM”), non-volatile (such as read-only memory or “ROM,” flash memory, and similar memory devices that maintain stored data even when power is not provided), or some combination of the two. The system memory 330 typically includes an operating system 331, one or more application platforms 332, one or more applications 333, and other program instructions. The system memory 330 also includes a compiler 334, source code 335, token resolution interface implementations 336, one or more static context items 337, and one or more dynamic context items 338. For example, the compiler 334 may include the compiler 140 of
The computing device 310 may also have additional features or functionality. For example, the computing device 310 may also include removable and/or non-removable additional data storage devices, such as magnetic disks, optical disks, tape, and standard-sized or flash memory cards. Such additional storage is illustrated in
The computing device 310 may also have input device(s) 360, such as a keyboard, mouse, pen, voice input device, touch input device, etc. Output device(s) 370, such as a display, speakers, a printer, etc. may also be included. The computing device 310 also contains one or more communication connections 380 that allow the computing device 310 to communicate with other computing devices 390 over a wired or a wireless network.
It will be appreciated that not all of the components or devices illustrated in
The illustrations of the embodiments described herein are intended to provide a general understanding of the structure of the various embodiments. The illustrations are not intended to serve as a complete description of all of the elements and features of apparatus and systems that utilize the structures or methods described herein. Many other embodiments may be apparent to those of skill in the art upon reviewing the disclosure. Other embodiments may be utilized and derived from the disclosure, such that structural and logical substitutions and changes may be made without departing from the scope of the disclosure. Accordingly, the disclosure and the figures are to be regarded as illustrative rather than restrictive.
Those of skill would further appreciate that the various illustrative logical blocks, configurations, modules, and process steps or instructions described in connection with the embodiments disclosed herein may be implemented as electronic hardware or computer software. Various illustrative components, blocks, configurations, modules, or steps have been described generally in terms of their functionality. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the overall system. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present disclosure.
The steps of a method described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in computer readable media, such as random access memory (RAM), flash memory, read only memory (ROM), registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art. An exemplary storage medium is coupled to a processor such that the processor can read information from, and write information to, the storage medium. In the alternative, the storage medium may be integral to the processor or the processor and the storage medium may reside as discrete components in a computing device or computer system.
Although specific embodiments have been illustrated and described herein, it should be appreciated that any subsequent arrangement designed to achieve the same or similar purpose may be substituted for the specific embodiments shown. This disclosure is intended to cover any and all subsequent adaptations or variations of various embodiments.
The Abstract of the Disclosure is provided with the understanding that it will not be used to interpret or limit the scope or meaning of the claims. In addition, in the foregoing Detailed Description, various features may be grouped together or described in a single embodiment for the purpose of streamlining the disclosure. This disclosure is not to be interpreted as reflecting an intention that the claimed embodiments require more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive subject matter may be directed to less than all of the features of any of the disclosed embodiments.
The previous description of the embodiments is provided to enable a person skilled in the art to make or use the embodiments. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the scope of the disclosure. Thus, the present disclosure is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope possible consistent with the principles and novel features as defined by the following claims.
Number | Name | Date | Kind |
---|---|---|---|
6530075 | Beadle et al. | Mar 2003 | B1 |
6973646 | Bordawekar et al. | Dec 2005 | B1 |
8191038 | Samuel et al. | May 2012 | B1 |
20010034743 | Thomas | Oct 2001 | A1 |
20040255268 | Meijer et al. | Dec 2004 | A1 |
20060080648 | Anwar et al. | Apr 2006 | A1 |
20060288353 | King et al. | Dec 2006 | A1 |
20070038981 | Hanson et al. | Feb 2007 | A1 |
20070201654 | Shenfield | Aug 2007 | A1 |
20100088669 | Cwalina et al. | Apr 2010 | A1 |
20100299660 | Torgersen et al. | Nov 2010 | A1 |
20110138190 | Chase et al. | Jun 2011 | A1 |
Entry |
---|
Auslander, et al., “Fast, Effective Dynamic Compilation”, Retrieved at << http://www.cs.washington.edu/research/dyncomp/Papers/pldi96.pdf >>, In the proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), May 1996, pp. 1-11. |
Lee, et al., “Optimizing ML with Run-Time Code Generation”, Retrieved at << http://www.cs.tufts.edu/comp/150CMP/papers/Iee96optimizingml.pdf >>, Conference on Programming Language Design and Implementation, Proceedings of the ACM SIGPLAN 1996 conference on Programming language design and implementation, May 21-24, 1996, pp. 137-148. |
Sandoval, et al., “Dynamic Compilation for Component-Based High Performance Computing”, Retrieved at << http://compframe.org/cbhpc2009/proceedings/articles/paper15-Sandoval.pdf >>, Conference on High Performance Networking and Computing, Proceedings of the 2009 Workshop on Component-Based High Performance Computing, Nov. 15-16, 2009, pp. 4. |
“Byte Compilation”, Retrieved at << http://www.zvon.org/other/elisp/Output/SEC198.html >>, pp. 10. |
“Unified Expression Language Support”, Requirements for Unified Expression Language (EL) Support WTP 2.0/JSF 1.0 tooling, from Eclipsepedia, 2010, 9 pages. |
Mac Dev Center: Xcode Debugging Guide: Modifying Running Code, Retrieved from http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/Xcode, Retrieved on Mar. 29, 2010, 3 pages. |
Number | Date | Country | |
---|---|---|---|
20110276953 A1 | Nov 2011 | US |