ONLINE CODE COMPILATION

Embodiments of the invention are directed to providing code compilation. Aspects include receiving, via a web browser, a source code in a first computing language from a user, converting the source code to a JavaScript, and creating a mapping between the source code and the JavaScript. Aspects also include executing the JavaScript and based on an error occurring during the execution of the JavaScript, identifying via the mapping a portion of the source code corresponding to the error and transmitting a notification to the user, the notification including the portion of the source code.

BACKGROUND

The present invention relates in general to compiling source code, and more specifically, to computing systems, computer-implemented methods, and computer program products for providing an online compilation of source code.

Software development kits (SDKs) are software tools that are used to compile, execute, and debug software source code. In many cases, programmers, and students, especially find it challenging to install and run SDKs on their computer systems. As a result, online program compilers became popular because the online compilers allow users to compile, execute, and debug software source code without the hassle of installing any SDKs on their local computer system.

While online program compilers are convenient and easy to use for end-users (i.e., people writing and testing source code), existing online program compilers are computationally intensive, in part because the online program compilers need to maintain multiple virtual machines in memory that are each configured to execute different types of source code. In addition, if the online program compiler does not include a proper sandbox environment for the execution of the user's software code, there's a risk of user programs injecting malicious code into the server.

SUMMARY

Embodiments of the invention provide a computer-implemented method for providing code compilation. The method includes receiving, via a web browser, source code in a first computing language from a user, converting the source code to a JavaScript, and creating a mapping between the source code and the JavaScript. The method also includes executing the JavaScript and based on an error occurring during the execution of the JavaScript, identifying via the mapping a portion of the source code corresponding to the error and transmitting a notification to the user, the notification including the portion of the source code.

Embodiments of the invention also provide computer-implemented methods and/or computer program products having substantially the same features as the computer system described above.

Additional features and advantages are realized through techniques described herein. Other embodiments and aspects are described in detail herein. For a better understanding, refer to the description and to the drawings.

DETAILED DESCRIPTION

As described above, while online program compilers are convenient and easy to use for end-users, existing online program compilers are computationally intensive and need to maintain multiple virtual machines in memory that are each configured to execute different types of source code. Accordingly, an online program compiler is needed that is convenient for end-users and that is not as computationally intensive as existing online program compilers.

Embodiments include methods, systems, and computer program products for online compilation of source code. In exemplary embodiments, the online program compiler is configured as a website that includes a user interface for a user to input a source code from a user in a first programming language to be compiled and executed. When the website is loaded onto a web browser (i.e., Mozilla Firefox, Google Chrome, etc.) of the user device, several modules, or JavaScript libraries, are loaded as the part of the website through same origin (domain) or through remote server where the JavaScript libraries are hosted. These modules include a source-to-source compiler module, a code execution module, an error mapper module, and an output translation module.

In exemplary embodiments, after a user has provided source code for compilation the source-to-source compiler module is configured to convert the provided source code to a JavaScript, which the web browser is configured to execute. In addition, the source-to-source compiler module creates a mapping between the user provided source code and the JavaScript. The JavaScript is then executed by the code execution module of the web browser. The code execution module of the web browser may be an embedded JavaScript execution engine such as SpiderMonkey, Chakra, V8 Engine, or the like.

If the JavaScript executes without encountering an error, the output translation module converts the JavaScript output back into an output format associated with the programming language of the source code, and the translated output is provided to the user. However, if an error is encountered during the execution of the JavaScript, the error mapper module identifies a portion of the user provided source code that corresponds to the error and provides a notification of the error and the portion of the user provided source code that corresponds to the error to the user. The disclosed online code compilation methods offload the computational work of compiling and executing the source code from the server to the user's machine, thereby significantly reducing the computational load on the server.

FIG. 1 depicts an example computing environment 100 that can be used to implement aspects of the invention. Computing environment 100 contains an example of an environment for the execution of at least some of the computer code involved in performing the inventive methods, such as online code compilation, as shown at block 150. In addition to block 150, computing environment 100 includes, for example, computer 101, wide area network (WAN) 102, end-user device (EUD) 103, remote server 104, public cloud 105, and private cloud 106. In this embodiment, computer 101 includes processor set 11 (including processing circuitry 120 and cache 121), communication fabric 111, volatile memory 112, persistent storage 113 (including operating system 122 and block 150, as identified above), peripheral device set 114 (including user interface (UI) device set 123, storage 124, and Internet of Things (IoT) sensor set 125), and network module 115. Remote server 104 includes remote database 130. Public cloud 105 includes gateway 140, cloud orchestration module 141, host physical machine set 142, virtual machine set 143, and container set 144.

PROCESSOR SET 11 includes one, or more, computer processors of any type now known or to be developed in the future. Processing circuitry 120 may be distributed over multiple packages, for example, multiple, coordinated integrated circuit chips. Processing circuitry 120 may implement multiple processor threads and/or multiple processor cores. Cache 121 is memory that is located in the processor chip package(s) and is typically used for data or code that should be available for rapid access by the threads or cores running on processor set 11. Cache memories are typically organized into multiple levels depending upon relative proximity to the processing circuitry. Alternatively, some, or all, of the cache for the processor set may be located “off chip.” In some computing environments, processor set 11 may be designed for working with qubits and performing quantum computing.

Turning now to a more detailed description of the aspects of the invention, FIG. 2 depicts a block diagram illustrating a web browser 200 configured to perform online code compilation according to embodiments of the invention. In exemplary embodiments, when the web browser 200 loads a code compilation website several modules, such as JavaScript libraries, may be loaded into the web browser 200. These libraries can be hosted on the same website or on a remote server. The libraries are then included in the website's HTML page using a script tag. This way, the website has all the necessary JavaScript scripts for source-to-source compilation, error mapping, code execution, and other functions. Alternatively, one or more of the depicted modules may be provided as part of the web browser 200. These modules include a source-to-source conversion module 208, a code execution module 210, an error mapper module 214, and an output translation module 216.

In exemplary embodiments, the web browser 200 includes a user interface 204 that is configured to receive a user provided source code 206. The user provided source code 206 is provided in a first programming language, such as Java, Python, Dart, C#, Scala, or Kotlin. In exemplary embodiments, once the user provided source code 206 has been received, the user provided source code 206 is provided to the source-to-source conversion module 208, which is configured to translate or convert the user provided source code 206 into a JavaScript. In addition, the source-to-source conversion module 208 is configured to create a mapping between the created JavaScript and the user provided source code 206. In one embodiment, the mapping includes a line-to-line correspondence between the JavaScript and the user provided source code 206.

After the JavaScript has been created from the user provided source code 206, the JavaScript is provided to the code execution module 210, which executes the JavaScript. In exemplary embodiments, the code execution module 210 of the web browser 200 may be an embedded JavaScript execution engine such as SpiderMonkey, Chakra, V8 Engine, or the like. Once the JavaScript has been executed, it is determined whether an error occurred during the execution. If an error occurs during the execution of the JavaScript, the error mapper module 214 is configured to identity a location in the user provided source code 206 and to display an error notification via the user interface 204. The error notification includes the location of the error in the user provided source code 206 and may also include an indication of the type of the error that occurred. In exemplary embodiments, the error mapper module 214 receives an identification of a line of the JavaScript that corresponds to the error and utilizes the mapping between the created JavaScript and the user provided source code 206 to determine the location in the user provided source code 206 that corresponds to the error.

In exemplary embodiments, if no error occurred during the execution of the JavaScript, the output translation module 214 is configured to translate or convert the output of the JavaScript into an output format corresponding to the first computing language, i.e., the computing language of the user provided source code 206. The output translation module 214 is further configured to display, via the user interface 204, the converted output.

Referring now to FIG. 3, a user interface 204 of a web browser configured to perform online code compilation according to embodiments of the invention is shown. The user interface 204 includes a source code input area 222 in which a user is able to input a user provided source code 206. In exemplary embodiments, the user interface 204 also includes a source code language selector 220 that is configured to receive a user provided identification of the programing language associated with the user provided source code 206. In one embodiment, the source code language selector 220 is a drop-down menu that includes a list of programming languages that the source-to-source conversion module 208 is configured to convert into JavaScript. The user interface 204 also includes an icon 224 that is configured to initiate the complication and execution of the user provided source code 206. In exemplary embodiments, the user interface 204 is further configured to display one or more of an output of the execution of the user provided source code 206 and an error notification associated with the execution of the user provided source code 206.

Referring now to FIGS. 4 and 5, a JavaScript 400 and a mapping 500 generated by the source-to-source conversion module 208 of the online code compiler according to embodiments of the invention is shown. In exemplary embodiments, the source-to-source conversion module 208 receives the user provided source code 206, which in the illustrated example is written in JAVA and generates JavaScript 400 and the mapping 500. All programming languages have their own syntax, but the basic operations are similar. For example, to throw an error in Java, we use ‘throw new Exception( )’, while in JavaScript, we use ‘throw new Error( )’. These are different syntaxes but have the same meaning. To convert code from one language to another, like Java to JavaScript, a step-by-step approach is followed. The step-by-step approach includes parsing the original code line by line and replacing Java syntax and keywords with their JavaScript equivalent literals and keywords. This process continues until the entire file is converted, resulting in the equivalent JavaScript code.

The mapping 500 includes a line-to-line correspondence 502 between the JavaScript 400 and the user provided source code 206. For example, line 1 of the JavaScript 400 corresponds to line 4 of the user provided source code 206. In one embodiment, the source-to-source conversion module 208 generates the line-to-line correspondence 502 of the mapping 500 as each line of the user provided source code 206 is converted to JavaScript 400. In another embodiment, the source-to-source conversion module 208 generates the line-to-line correspondence 502 of the mapping 500 after the user provided source code 206 is converted to JavaScript 400 by performing a comparison between the user provided source code 206 is converted to JavaScript 400.

Referring now to FIG. 6, a flowchart diagram of a method for performing online code compilation according to embodiments of the invention. In exemplary embodiments, the method 600 is performed by a computing environment 100, such as the one shown in FIG. 1.

At block 602, the method 600 includes receiving, via a web browser, a source code in a first computing language from a user. In exemplary embodiments, the first computing language is one of Java, Python, Dart, C#, Scala, and Kotlin. In one embodiment, the source code is received with an indication of the first computing language from the user. Next, as shown at block 604, the method 600 includes converting the source code to a JavaScript. In exemplary embodiments, the source code is converted to a JavaScript by a source-to-source conversion module that is loaded into the web browser.

The method 600 also includes creating a mapping between the source code and the JavaScript, as shown at block 606. In one embodiment, the mapping includes a line-to-line correspondence between the user provided source code and the JavaScript. In exemplary embodiments, the mapping is created by a source-to-source conversion module that is loaded into the web browser. Next, as shown at block 606, the method 600 includes executing the JavaScript. In one embodiment, the JavaScript is executed by a code execution module of the web browser, such as an embedded JavaScript execution engine such as SpiderMonkey, Chakra, V8 Engine, or the like.

At decision block 610, the method 600 includes determining whether an error occurred during the execution of the JavaScript. If an error occurred during the execution of the JavaScript, the method 600 proceeds to block 610 and the method 600 includes identifying via the mapping a portion of the source code corresponding to the error. Next, at block 614 the method 600 includes transmitting a notification to the user, the notification including the portion of the source code. In exemplary embodiments, the notification further includes an identification of a type of the error that occurred.

If no error occurred during the execution of the JavaScript, the method 600 proceeds to block 616 and the method 600 includes converting an output of the JavaScript into an output format corresponding to the first computing language. Next, at block 618 the method 600 includes transmitting the converted output to the user.

Additionally, the term “exemplary” and variations thereof are used herein to mean “serving as an example, instance or illustration.” Any embodiment or design described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments or designs. The terms “at least one,” “one or more,” and variations thereof, can include any integer number greater than or equal to one, i.e. one, two, three, four, etc. The terms “a plurality” and variations thereof can include any integer number greater than or equal to two, i.e., two, three, four, five, etc. The term “connection” and variations thereof can include both an indirect “connection” and a direct “connection.”

The phrases “in signal communication”, “in communication with,” “communicatively coupled to,” “electronically coupled to” and variations thereof can be used interchangeably herein and can refer to any coupling, connection, or interaction using electrical signals to exchange information or data, using any system, hardware, software, protocol, or format, regardless of whether the exchange occurs wirelessly or over a wired connection.

It will be understood that those skilled in the art, both now and in the future, may make various improvements and enhancements which fall within the scope of the claims which follow.