Interrupt processing method and device for programming language, electronic equipment and medium
By converting functions in programming language programs into generator functions and executing them with thread instances, the problem that cross-platform interpreters cannot interrupt the execution of programming language programs is solved, and debugging and development efficiency is improved.
Patent Information
- Application Number
- CN202411487654.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-23
- Publication Date
- 2025-01-03
AI Technical Summary
The prior art cannot pause or interrupt the execution of programming language programs through cross-platform interpreters, resulting in reduced flexibility and development efficiency in debugging programming languages.
The functions in the programming language program are converted into generator functions through a preset control instance, and the generator function is executed using a thread instance, interrupt processing is performed when the preset interrupt condition is triggered, and execution is resumed after the interrupt.
It realizes the pause or interruption of the execution of programming language programs of cross-platform interpreters, improving the flexibility and development efficiency of debugging programming languages.
Smart Images

Figure CN119248454A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of programming languages, and in particular to an interrupt processing method, device, electronic device and medium of a programming language. Background Art
[0002] When debugging a programming language program, it is usually necessary to use breakpoint debugging to debug the current value of each variable in the program step by step in the paused execution flow. In the case of a variable error, debug the erroneous program for analysis to find the program error or loophole. In addition, in the C++ language, functions that trigger terminal input are also a method of interrupting execution. These functions wait for external input and continue to execute other programs after the input is completed.
[0003] Currently, during the execution of the program, it is impossible to pause or interrupt the execution of the programming language program through the cross-platform interpreter, nor is it possible to interrupt the thread of the cross-platform interpreter's execution of the programming language program through the sleep method, which reduces the flexibility of debugging the programming language and further reduces the development efficiency of the programming language. Summary of the invention
[0004] In view of this, the purpose of the present application is to provide a method, device, electronic device and medium for interrupt processing of a programming language, which converts a function in a programming language program into a generator function through a preset control instance, and executes the generator function using a thread instance in the control instance, so that the program is executed through multiple threads. When a preset interrupt condition is triggered, the thread instance execution program is interrupted and the execution is resumed at any time after the interruption, thereby realizing the suspension or interruption of the execution of the programming language program by a cross-platform interpreter, improving the flexibility of debugging the programming language, and thereby improving the development efficiency of the programming language.
[0005] The present application provides an interrupt processing method for a programming language, the interrupt processing method comprising:
[0006] Obtaining an externally input programming language program, and calling a preset control instance to convert at least one objective function in the programming language program into a corresponding generator function;
[0007] Utilize at least one thread instance in the control instance to respectively execute at least one of the generator functions;
[0008] In response to the existence of at least one target generator function in the generator function triggering a preset interrupt condition, the calling of the loop method corresponding to the target generator function is stopped to interrupt the execution of the target generator function.
[0009] Furthermore, the method further comprises:
[0010] In response to at least one target generator function in the generator function triggering a preset asynchronous sleep condition, calling a preset sleep method to control the target thread instance corresponding to the target generator function to stop executing;
[0011] After the stop duration of the target thread instance reaches a time threshold corresponding to the asynchronous sleep condition, a preset method handle is called to continue executing the target generator function.
[0012] Further, the step of obtaining an externally input programming language program and calling a preset control instance to convert at least one objective function in the programming language program into a corresponding generator function includes:
[0013] Obtaining a programming language program including at least one objective function as external input;
[0014] Calling the target function using the object calling method in the preset control instance to obtain at least one generator object returned by the call;
[0015] Based on the generator object, the target function is called, and a generator function corresponding to at least one target function returned by the call is obtained.
[0016] Further, the using at least one thread instance in the regulation instance to respectively execute at least one of the generator functions includes:
[0017] Using a preset running component to obtain an entry main function in the target function, and determining a first generator function corresponding to the entry main function;
[0018] Executing the first generator function using a first thread instance in the control instance;
[0019] In response to triggering a preset suspension condition during the execution of the first generator function, determining whether there is at least one second target function in the target function;
[0020] If so, determine the second generator function corresponding to the second objective function, and use the second thread instance in the control instance to execute the second generator function.
[0021] Further, the using the first thread instance in the regulation instance to execute the first generator function includes:
[0022] Based on the first generator function, determine a generator component corresponding to the first generator function;
[0023] The generator component is transferred to the first thread instance in the control instance, and it is determined whether the current execution condition meets the preset requirements;
[0024] If so, the first generator function is executed using the execution method in the first thread instance.
[0025] Further, the following steps are performed to determine whether at least one target generator function in the generator function triggers a preset interruption condition:
[0026] In response to an interrupt signal obtained from an external input for at least one target generator function, a preset interrupt method is called, and a return variable corresponding to the interrupt method is adjusted to a first preset variable;
[0027] Based on the return variable corresponding to the interrupt method being a first preset variable, it is determined that at least one target generator function triggers a preset interrupt condition.
[0028] Furthermore, the step of determining that there is at least one target generator function in the generator function that triggers a preset interruption condition further includes:
[0029] In response to the data format returned by the acquired at least one target generator function being a preset asynchronous format, it is determined that the at least one target generator function triggers a preset interrupt condition.
[0030] The embodiment of the present application further provides an interrupt processing device of a programming language, the interrupt processing device comprising:
[0031] A program conversion module, used to obtain an externally input programming language program, and call a preset control instance to convert at least one objective function in the programming language program into a corresponding generator function;
[0032] A program execution module, used to respectively execute at least one of the generator functions using at least one thread instance in the control instance;
[0033] An interrupt processing module is used to stop calling the loop method corresponding to the target generator function in response to the existence of at least one target generator function in the generator function triggering a preset interrupt condition, so as to interrupt the execution of the target generator function.
[0034] Furthermore, the interrupt processing device further includes an asynchronous sleep module, and the asynchronous sleep module is used for:
[0035] In response to at least one target generator function in the generator function triggering a preset asynchronous sleep condition, calling a preset sleep method to control the target thread instance corresponding to the target generator function to stop executing;
[0036] After the stop duration of the target thread instance reaches a time threshold corresponding to the asynchronous sleep condition, a preset method handle is called to continue executing the target generator function.
[0037] Furthermore, when the program conversion module is used to obtain an externally input programming language program and call a preset control instance to convert at least one objective function in the programming language program into a corresponding generator function, the program conversion module is used to:
[0038] Obtaining a programming language program including at least one objective function as external input;
[0039] Calling the target function using the object calling method in the preset control instance to obtain at least one generator object returned by the call;
[0040] Based on the generator object, the target function is called, and a generator function corresponding to at least one target function returned by the call is obtained.
[0041] Further, when the program execution module is used to respectively execute at least one of the generator functions using at least one thread instance in the regulation instance, the program execution module is used to:
[0042] Using a preset running component to obtain an entry main function in the target function, and determining a first generator function corresponding to the entry main function;
[0043] Executing the first generator function using a first thread instance in the control instance;
[0044] In response to triggering a preset suspension condition during the execution of the first generator function, determining whether there is at least one second target function in the target function;
[0045] If so, determine the second generator function corresponding to the second objective function, and use the second thread instance in the control instance to execute the second generator function.
[0046] Further, when the program execution module is used to execute the first generator function using the first thread instance in the regulation instance, the program execution module is used to:
[0047] Based on the first generator function, determine a generator component corresponding to the first generator function;
[0048] The generator component is transferred to the first thread instance in the control instance, and it is determined whether the current execution condition meets the preset requirements;
[0049] If so, the first generator function is executed using the execution method in the first thread instance.
[0050] Further, when the interrupt processing module is used to determine that there is at least one target generator function in the generator function that triggers a preset interrupt condition, the interrupt processing module is used to:
[0051] In response to an interrupt signal obtained from an external input for at least one target generator function, a preset interrupt method is called, and a return variable corresponding to the interrupt method is adjusted to a first preset variable;
[0052] Based on the return variable corresponding to the interrupt method being a first preset variable, it is determined that at least one target generator function triggers a preset interrupt condition.
[0053] Further, when the interrupt processing module is used to determine that there is at least one target generator function in the generator function that triggers a preset interrupt condition, the interrupt processing module is also used to:
[0054] In response to the data format returned by the acquired at least one target generator function being a preset asynchronous format, it is determined that the at least one target generator function triggers a preset interrupt condition.
[0055] An embodiment of the present application also provides an electronic device, comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate through the bus, and when the machine-readable instructions are executed by the processor, the steps of the interrupt handling method in the above-mentioned programming language are performed.
[0056] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the interrupt processing method in the programming language described above are executed.
[0057] The embodiments of the present application provide an interrupt processing method, device, electronic device and medium for a programming language. The interrupt processing method includes: obtaining an externally input programming language program, and calling a preset control instance to convert at least one target function in the programming language program into a corresponding generator function; using at least one thread instance in the control instance to respectively execute at least one of the generator functions; in response to the existence of at least one target generator function in the generator function that triggers a preset interrupt condition, stopping calling the loop method corresponding to the target generator function to interrupt the execution of the target generator function.
[0058] Compared with the method of directly interpreting and executing programming language programs in the prior art, the function in the programming language program is converted into a generator function through a preset control instance, and the generator function is executed using a thread instance in the control instance, so that the program is executed through multiple threads. When a preset interrupt condition is triggered, the thread instance execution program is interrupted and the execution is resumed at any time after the interruption, thereby realizing the cross-platform interpreter to pause or interrupt the execution of the programming language program, improving the flexibility of debugging the programming language, and thereby improving the development efficiency of the programming language.
[0059] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0061] Figure 1 One of the flowcharts of an interrupt processing method of a programming language provided in an embodiment of the present application;
[0062] Figure 2 A second flowchart of an interrupt processing method of a programming language provided in an embodiment of the present application;
[0063] Figure 3 One of the structural schematic diagrams of an interrupt processing device of a programming language provided in an embodiment of the present application;
[0064] Figure 4 A second structural diagram of an interrupt processing device for a programming language provided in an embodiment of the present application;
[0065] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0066] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application usually described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, each other embodiment obtained by those skilled in the art without making creative work belongs to the scope of protection of the present application.
[0067] Research has found that, currently, during the execution of a program, it is not possible to pause or interrupt the execution of a programming language program through a cross-platform interpreter, nor is it possible to interrupt the thread of the cross-platform interpreter's execution of a programming language program through the sleep method, which reduces the flexibility of debugging the programming language and, in turn, reduces the efficiency of programming language development.
[0068] Based on this, an embodiment of the present application provides an interrupt processing method for a programming language, which converts a function in a programming language program into a generator function through a preset control instance, and executes the generator function using a thread instance in the control instance, so that the program is executed through multiple threads. When a preset interrupt condition is triggered, the thread instance execution program is interrupted and execution can be resumed at any time after the interruption, thereby improving the flexibility of debugging the programming language and thereby improving the development efficiency of the programming language.
[0069] See also Figure 1 , Figure 1 This is one of the flowcharts of an interrupt processing method of a programming language provided in an embodiment of the present application. Figure 1 As shown in , the interrupt processing method of the programming language provided in the embodiment of the present application includes:
[0070] S101. Obtain an externally input programming language program, and call a preset control instance to convert at least one objective function in the programming language program into a corresponding generator function.
[0071] It should be noted that the interrupt handling method of the programming language provided in the embodiment of the present application is generally applied to a programming language interpreter that can run in a JavaScript environment, so as to achieve cross-platform operation through the cross-platform characteristics of the Web in the JavaScript environment, and unify the language interface under multiple platforms. For example, the programming language interpreter supports running on the browser of the Pad, or executing in WeChat H5.
[0072] The programming language interpreter running in the JavaScript environment refers to a tool or library that can convert codes of other programming languages into JavaScript codes and execute them in the JavaScript runtime environment.
[0073] In the embodiment of the present application, the programming language program includes but is not limited to C language program, C++ language program, C# language program, Python language program and Java program, etc.
[0074] In an embodiment of the present application, before obtaining an externally input programming language program, it is necessary to use a preset cross-platform parsing tool to parse and convert the input programming language program; the preset cross-platform parsing tool includes a PEG.js tool, a JavaScript parser generator, which provides a PEG.js language (Parser ExpressionGrammar JavaScript), which is a language used to define a grammar parser and generate parser code that can be used directly in JavaScript; for example, to generate a js file, you must first define a PEG.js grammar rule, and then use the PEG.js compiler to compile it into JavaScript code.
[0075] In this way, the PEG.js tool can parse the compiled file to generate a cross-platform programming language program according to the Parsing Expression Grammar (PEG) provided by the PEG.js tool.
[0076] In an embodiment of the present application, a preset control instance is set in the interpreted execution flow of the programming language, and the control instance is used to coordinate the execution units in the execution flow, which can be understood as the control instance using functions or other logical units to control the execution flow of the program.
[0077] Furthermore, the generator function uses keywords to generate a series of target values, is defined using the "function" syntax, and can use the ".next()" method to iteratively generate target values; for example, the generator function can use a "for" loop to iteratively generate target values; the generator function can also be used to generate Fibonacci numbers, process asynchronous operations, etc., as well as process tasks such as reading files and sending network requests.
[0078] Here, the generator function is a feature in the programming language, which allows the expressions in the function to be executed step by step and can be called line by line when called; since the generator function allows the function to pause execution and save its state, it can be restored to the paused position and continue execution when it is called again in the future. Therefore, when interrupt processing is performed on the programming language program, converting the target function into a generator function can achieve the technical effect of interrupt processing.
[0079] In one implementation of the present application, during specific implementation, step S101 may include:
[0080] S1011. Obtain an externally input programming language program including at least one target function.
[0081] In this step, a programming language program input by a user in a compile area of the programming language interpreter is obtained through a programming language interpreter, wherein the programming language program includes at least one objective function.
[0082] Here, the at least one target function includes an entry main function. In addition, the programming language program may not include other target functions, and may also include at least one other function except the entry main function; that is, when the programming language program includes only one target function, the target function is the entry main function; when the programming language program includes multiple target functions, the target functions are the entry main function and other functions.
[0083] As an example including at least one function other than the entry main function, when the "cin>>a" statement in the entry main function is executed, the target function also includes other built-in functions in the C++ language program, such as the externalInvokingFunction function.
[0084] S1012: Call the target function using the object calling method in the preset control instance to obtain at least one generator object returned by the call.
[0085] In this step, during the specific implementation, first, call the preset control instance; then, call at least one objective function using the object calling method in the control instance; finally, obtain at least one generator object corresponding to at least one objective function returned by calling the objective function.
[0086] S1013. Based on the generator object, call the target function and obtain a generator function corresponding to at least one target function returned by the call.
[0087] In this step, at least one objective function is called in segments using a generator object to obtain generator functions corresponding to at least one objective function returned by the call.
[0088] S102. Utilize at least one thread instance in the control instance to respectively execute at least one of the generator functions.
[0089] In an embodiment of the present application, a startup method is predefined in a preset running component, and a control instance is called in the startup method; wherein the control instance includes at least one thread instance, and the at least one thread instance represents a pseudo-thread, and thread maintenance is performed through a preset array.
[0090] Specifically, when maintaining threads using a preset array, for example, maintaining the startup, synchronization, and waiting behaviors of threads, the array can not only pre-allocate the vector space of the threads to dynamically add or remove threads, but also manage the operation of the threads in the loop statement corresponding to the array.
[0091] As an example of using at least one thread instance in a control instance to respectively execute at least one generator function, a start method is predefined in a preset run component through the statement "start(genFunc:any,defSteps:any)"; the statement "this.stop()" ensures that any existing thread can be stopped before starting to execute a new thread; a control instance (Procedure instance) is created through the statement "const thread=new Procedure({step:defSteps,id:this.generateThreadId()"; the newly created thread instance is added to the preset array "this.threads" through the statement "this.threads.push(thread)"; the run method on the thread instance is called through the statement "thread.run(this,genFunc)" to start executing the thread instance, and the current context (this) and a generator component (genFunc) corresponding to a generator function are passed as parameters.
[0092] In one implementation of the present application, during specific implementation, step S102 may include:
[0093] S1021. Obtain an entry main function in the target function using a preset running component, and determine a first generator function corresponding to the entry main function.
[0094] In this step, an entry main function that must be included in at least one target function is obtained using an acquisition method in a preset running component; then, based on a conversion method for converting the target function into a generator function, a first generator function corresponding to the entry main function is determined.
[0095] S1022. Utilize the first thread instance in the control instance to execute the first generator function.
[0096] In one implementation of the present application, during specific implementation, step S1022 may include:
[0097] S10221. Based on the first generator function, determine the generator component corresponding to the first generator function.
[0098] S10222. Pass the generator component to the first thread instance in the control instance, and determine whether the current execution condition meets the preset requirements.
[0099] In an embodiment of the present application, when a first thread instance for executing a first generator function is run, a generator component corresponding to the first generator function is passed to the first thread instance. Here, the first thread instance is an empty thread. After the first thread instance receives the generator component corresponding to the first generator function, it determines whether the current execution conditions meet the preset requirements.
[0100] Here, the preset requirements may include execution requirements set according to actual compilation requirements and actual content of the programming language program.
[0101] S10223. If it meets the requirements, execute the first generator function using the execution method in the first thread instance.
[0102] In this step, when the current execution condition meets the preset requirements, the first generator function is executed using the execution method in the first thread instance.
[0103] S1023. In response to triggering a preset suspension condition during the execution of the first generator function, determine whether there is at least one second target function in the target function.
[0104] In an embodiment of the present application, during the actual execution and debugging of the programming language, in response to triggering a preset suspension condition during the execution of the first generator function, it is necessary to determine whether there is at least one second target function in the target function so that the external program can directly and actively call the second target function.
[0105] Here, the preset suspension condition includes the existence of at least one external program actively calling the at least one target function.
[0106] For example, in the statement "void externalInvokingFunction(){cout<<"invoking cout";}intmain(){cin>>a;cout<<a;return 0;}", after the entry main function (main) starts to be called, the programming language program is executed in the first thread instance. When it executes to the statement "cin>>a", the first thread instance will wait for external input. Since the first thread instance is in a suspended state, when the second target function "externalInvokingFunction" is called separately, the second target function will be executed through the second thread instance.
[0107] Among them, the statement "cin>>a" means that when the entry main function is executed, it will only read the part before the next whitespace character (space, tab, or newline).
[0108] S1024. If it exists, determine the second generator function corresponding to the second target function, and use the second thread instance in the regulation instance to execute the second generator function.
[0109] In this step, when there is at least one second target function in the target function, first, use the acquisition method in the running component to acquire the second target function and determine the second generator function corresponding to the second target function; then, pass the generator component corresponding to the second generator function to the second thread instance, and determine whether the current execution condition meets the preset requirements; if it meets, use the execution method in the second thread instance to execute the second generator function.
[0110] Furthermore, when there is no at least one second target function in the target function, continue to execute the first generator function corresponding to the entry main function.
[0111] S103. In response to at least one target generator function in the generator function triggering a preset interruption condition, stop calling the loop method corresponding to the target generator function to perform interruption processing on the execution of the target generator function.
[0112] In the embodiment of the present application, the preset interruption condition includes the interruption condition corresponding to the target function set according to the actual compilation requirements and the actual content of the programming language program.
[0113] Here, based on the boolean value returned by calling the "getIsStoppedConfidtion" method, determine whether there is at least one target generator function triggering the preset interruption condition according to the attribute of the boolean value.
[0114] As an example of interrupting the execution of a target generator function in response to the existence of at least one target generator triggering a preset interrupt condition, the statement "while(true){this.step=mainGen.next();const stopCondition=this.getIsStoppedConfidtion(this);if(stopCondition){break;}" is executed in an infinite loop. Each iteration obtains the next execution step from the loop method "mainGen" corresponding to the target generator function, and checks whether the preset interrupt condition is triggered. If it is satisfied, the loop method corresponding to the target generator function is stopped from being called to interrupt the execution of the target generator function.
[0115] In one embodiment of the present application, in a specific implementation, the step of determining in step S103 that there is at least one target generator function in the generator function that triggers a preset interruption condition may include:
[0116] S1031. In response to an interrupt signal obtained from external input for at least one target generator function, a preset interrupt method is called, and a return variable corresponding to the interrupt method is adjusted to a first preset variable.
[0117] In this step, in response to an interrupt signal obtained from external input for at least one target generator function, a method for determining the interrupt condition is called based on the interrupt signal by externally accessing the first thread instance; and the property of the internal return variable in the first thread instance is changed to a first preset variable.
[0118] Here, when the first thread instance is set to stop, the return variable corresponding to the interrupt method is adjusted to a first preset variable.
[0119] Exemplarily, when the "stop" method in the current first thread instance is accessed externally, the internal properties of the "stop" method are changed to change the property of the internal return variable "stopped" in the first thread instance to the first preset variable "true".
[0120] S1032. Based on the return variable corresponding to the interrupt method being a first preset variable, determine that at least one target generator function triggers a preset interrupt condition.
[0121] In this step, when the return variable corresponding to the interrupt method is the first preset variable, it is determined that at least one target generator function triggers a preset interrupt condition, and the calling of the loop method corresponding to the target generator function can be further stopped to interrupt the execution of the target generator function.
[0122] In one embodiment of the present application, in a specific implementation, the step of determining in step S103 that there is at least one target generator function in the generator function that triggers a preset interruption condition further includes:
[0123] S1033. In response to the data format returned by the acquired at least one target generator function being a preset asynchronous format, determine that the at least one target generator function triggers a preset interrupt condition.
[0124] In this step, it is determined whether the data format returned by the at least one target generator function is a preset asynchronous format; in response to the returned data format being the preset asynchronous format, it is determined that the at least one target generator function triggers a preset interrupt condition.
[0125] Among them, the preset asynchronous format may include the existence of asynchronous functionality in the target generator function in the programming language program.
[0126] Exemplarily, the built-in method of the C++ engine is used to determine whether the data format returned by at least one target generator function is the preset asynchronous format "Promise". Assuming that after the call, the data format of the return value is "promise", it is determined that the target generator function triggers the preset interrupt condition; further, after waiting for the "promise.then" return call, continue to execute the target generator function "step.next()".
[0127] Here, when the loop method corresponding to the target generator function is stopped, that is, when the execution of the target generator function is interrupted, the common memory variables of at least one thread instance are in a synchronized reference relationship, that is, when the second thread instance continues to execute, it is possible that the referenced variable is a variable that has been changed by the first thread instance.
[0128] Optional, see Figure 2 , Figure 2 This is a flowchart of a method for interrupt handling in a programming language provided in an embodiment of the present application. Figure 2 As shown in, in addition to the interrupt handling method of the programming language described in steps S101 to S103, steps S104 to S105 are also included. Specifically, steps S104 to S105 are used to illustrate a method for controlling the target thread instance to stop executing when there is at least one target generator function in the generator function that triggers a preset asynchronous sleep condition, so as to meet the needs of program interruption in the asynchronous sleep scenario.
[0129] S104. In response to the existence of at least one target generator function in the generator function triggering a preset asynchronous sleep condition, a preset sleep method is called to control the target thread instance corresponding to the target generator function to stop execution.
[0130] S105. After the stop duration of the target thread instance reaches a time threshold corresponding to the asynchronous sleep condition, call a preset method handle to continue executing the target generator function.
[0131] In an embodiment of the present application, first, when the target generator function executed by the programming language interpreter is an asynchronous sleep function, it is determined that the target generator function triggers a preset asynchronous sleep condition; then, the preset sleep method is called to control the target thread instance corresponding to the target iteration generator to stop executing; finally, the stop duration of the target thread instance is obtained.
[0132] Furthermore, after the stop duration of the target thread instance reaches a time threshold corresponding to the asynchronous sleep condition, a preset method handle is called to continue executing the target generator function.
[0133] The interrupt processing method of the programming language provided in the embodiment of the present application converts the function in the programming language program into a generator function through a preset control instance, and executes the generator function using the thread instance in the control instance, so as to execute the program through multiple threads. When the preset interrupt condition is triggered, the thread instance execution program is interrupted and the execution is resumed at any time after the interruption, thereby improving the flexibility of debugging the programming language and further improving the development efficiency of the programming language.
[0134] See also Figure 3 , Figure 4 , Figure 3 This is one of the structural schematic diagrams of an interrupt processing device of a programming language provided in an embodiment of the present application, Figure 4 The second structural diagram of an interrupt processing device of a programming language provided in an embodiment of the present application. Figure 3 As shown in , the interrupt processing device 300 includes:
[0135] A program conversion module 310 is used to obtain an externally input programming language program and call a preset control instance to convert at least one objective function in the programming language program into a corresponding generator function;
[0136] A program execution module 320, configured to respectively execute at least one of the generator functions using at least one thread instance in the control instance;
[0137] The interrupt processing module 330 is used to stop calling the loop method corresponding to the target generator function in response to the existence of at least one target generator function in the generator function triggering a preset interrupt condition, so as to interrupt the execution of the target generator function.
[0138] Further, such as Figure 4As shown in , the interrupt processing device 300 further includes an asynchronous sleep module 340, and the asynchronous sleep module 340 is used to:
[0139] In response to at least one target generator function in the generator functions triggering a preset asynchronous sleep condition, calling a preset sleep method to control the target thread instance corresponding to the target generator function to stop executing;
[0140] After the stop duration of the target thread instance reaches a time threshold corresponding to the asynchronous sleep condition, a preset method handle is called to continue executing the target generator function.
[0141] Further, when the program conversion module 310 is used to obtain an externally input programming language program and call a preset control instance to convert at least one objective function in the programming language program into a corresponding generator function, the program conversion module 310 is used to:
[0142] Obtaining a programming language program including at least one objective function as external input;
[0143] Calling the target function using the object calling method in the preset control instance to obtain at least one generator object returned by the call;
[0144] Based on the generator object, the target function is called, and a generator function corresponding to at least one target function returned by the call is obtained.
[0145] Further, when the program execution module 320 is used to respectively execute at least one of the generator functions using at least one thread instance in the regulation instance, the program execution module 320 is used to:
[0146] Using a preset running component to obtain an entry main function in the target function, and determining a first generator function corresponding to the entry main function;
[0147] Executing the first generator function using a first thread instance in the control instance;
[0148] In response to triggering a preset suspension condition during the execution of the first generator function, determining whether there is at least one second target function in the target function;
[0149] If so, determine the second generator function corresponding to the second objective function, and use the second thread instance in the control instance to execute the second generator function.
[0150] Further, when the program execution module 320 is used to execute the first generator function using the first thread instance in the regulation instance, the program execution module 320 is used to:
[0151] Based on the first generator function, determine a generator component corresponding to the first generator function;
[0152] The generator component is transferred to the first thread instance in the control instance, and it is determined whether the current execution condition meets the preset requirements;
[0153] If so, the first generator function is executed using the execution method in the first thread instance.
[0154] Further, when the interrupt processing module 330 is used to determine that there is at least one target generator function in the generator function that triggers a preset interrupt condition, the interrupt processing module 330 is used to:
[0155] In response to an interrupt signal obtained from an external input for at least one target generator function, a preset interrupt method is called, and a return variable corresponding to the interrupt method is adjusted to a first preset variable;
[0156] Based on the return variable corresponding to the interrupt method being a first preset variable, it is determined that at least one target generator function triggers a preset interrupt condition.
[0157] Further, when the interrupt processing module 330 is used to determine that there is at least one target generator function in the generator function that triggers a preset interrupt condition, the interrupt processing module 330 is also used to:
[0158] In response to the data format returned by the acquired at least one target generator function being a preset asynchronous format, it is determined that the at least one target generator function triggers a preset interrupt condition.
[0159] The interrupt processing device of the programming language provided in the embodiment of the present application converts the function in the programming language program into a generator function through a preset control instance, and executes the generator function using the thread instance in the control instance, so as to execute the program through multiple threads. When the preset interrupt condition is triggered, the thread instance execution program is interrupted and the execution is resumed at any time after the interruption, thereby improving the flexibility of debugging the programming language and further improving the development efficiency of the programming language.
[0160] See also Figure 5 , Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 5 As shown in , the electronic device 500 includes a processor 510 , a memory 520 and a bus 530 .
[0161] The memory 520 stores machine-readable instructions executable by the processor 510. When the electronic device 500 is running, the processor 510 communicates with the memory 520 via the bus 530. When the machine-readable instructions are executed by the processor 510, the above-mentioned Figure 1 as well as Figure 2 The specific implementation of the steps of the interrupt processing method of the programming language in the method embodiment shown can be found in the method embodiment, which will not be repeated here.
[0162] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the computer program can execute the above-mentioned Figure 1 as well as Figure 2 The specific implementation of the steps of the interrupt processing method of the programming language in the method embodiment shown can be found in the method embodiment, which will not be repeated here.
[0163] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0164] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0165] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0166] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0167] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present application can essentially be embodied in the form of a software product, or in other words, the part that contributes to the prior art or the part of the technical solution. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0168] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-mentioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-mentioned embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A method for interrupt processing in a programming language, characterized in that: The interrupt processing method comprises: Obtaining an externally input programming language program, and calling a preset control instance to convert at least one objective function in the programming language program into a corresponding generator function; Utilize at least one thread instance in the control instance to respectively execute at least one of the generator functions; In response to the existence of at least one target generator function in the generator function triggering a preset interrupt condition, the calling of the loop method corresponding to the target generator function is stopped to interrupt the execution of the target generator function.
2. The method according to claim 1, characterized in that The method further comprises: In response to at least one target generator function in the generator function triggering a preset asynchronous sleep condition, calling a preset sleep method to control the target thread instance corresponding to the target generator function to stop executing; After the stop duration of the target thread instance reaches a time threshold corresponding to the asynchronous sleep condition, a preset method handle is called to continue executing the target generator function.
3. The method according to claim 1, characterized in that The step of obtaining an externally input programming language program and calling a preset control instance to convert at least one objective function in the programming language program into a corresponding generator function includes: Obtaining a programming language program including at least one objective function as external input; Calling the target function using the object calling method in the preset control instance to obtain at least one generator object returned by the call; Based on the generator object, the target function is called, and a generator function corresponding to at least one target function returned by the call is obtained.
4. The method according to claim 1, characterized in that: The using at least one thread instance in the regulation instance to respectively execute at least one of the generator functions comprises: Using a preset running component to obtain an entry main function in the target function, and determining a first generator function corresponding to the entry main function; Executing the first generator function using a first thread instance in the control instance; In response to triggering a preset suspension condition during the execution of the first generator function, determining whether there is at least one second target function in the target function; If so, determine the second generator function corresponding to the second objective function, and use the second thread instance in the control instance to execute the second generator function.
5. The method according to claim 4, characterized in that The using the first thread instance in the regulation instance to execute the first generator function comprises: Based on the first generator function, determine a generator component corresponding to the first generator function; The generator component is transferred to the first thread instance in the control instance, and it is determined whether the current execution condition meets the preset requirements; If so, the first generator function is executed using the execution method in the first thread instance.
6. The method according to claim 1, characterized in that Determine that there is at least one target generator function in the generator function that triggers a preset interruption condition by the following steps: In response to an interrupt signal obtained from an external input for at least one target generator function, a preset interrupt method is called, and a return variable corresponding to the interrupt method is adjusted to a first preset variable; Based on the return variable corresponding to the interrupt method being a first preset variable, it is determined that at least one target generator function triggers a preset interrupt condition.
7. The method according to claim 6, characterized in that The step of determining that there is at least one target generator function in the generator function triggering a preset interruption condition also includes: In response to the data format returned by the acquired at least one target generator function being a preset asynchronous format, it is determined that the at least one target generator function triggers a preset interrupt condition.
8. An interrupt processing device for a programming language, characterized in that: The interrupt processing device comprises: A program conversion module, used to obtain an externally input programming language program, and call a preset control instance to convert at least one objective function in the programming language program into a corresponding generator function; A program execution module, used to respectively execute at least one of the generator functions using at least one thread instance in the control instance; An interrupt processing module is used to stop calling the loop method corresponding to the target generator function in response to the existence of at least one target generator function in the generator function triggering a preset interrupt condition, so as to interrupt the execution of the target generator function.
9. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and the machine-readable instructions are executed by the processor to execute the steps of the interrupt processing method of the programming language as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the interrupt processing method in a programming language as claimed in any one of claims 1 to 7 are executed.
