CN113220277A - Embedded service development method and device - Google Patents

Embedded service development method and device Download PDF

Info

Publication number
CN113220277A
CN113220277A CN202110611631.7A CN202110611631A CN113220277A CN 113220277 A CN113220277 A CN 113220277A CN 202110611631 A CN202110611631 A CN 202110611631A CN 113220277 A CN113220277 A CN 113220277A
Authority
CN
China
Prior art keywords
esvclisp
embedded
expression
reading
source code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202110611631.7A
Other languages
Chinese (zh)
Other versions
CN113220277B (en
Inventor
杜承烈
陈进朝
王思奥
孙丙坤
刘一帆
尤涛
王丽芳
蒋泽军
白璐
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Northwestern Polytechnical University
Original Assignee
Northwestern Polytechnical University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Northwestern Polytechnical University filed Critical Northwestern Polytechnical University
Priority to CN202110611631.7A priority Critical patent/CN113220277B/en
Publication of CN113220277A publication Critical patent/CN113220277A/en
Application granted granted Critical
Publication of CN113220277B publication Critical patent/CN113220277B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/20Software design
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis

Abstract

The invention discloses a development method and a device for embedded service, and relates to the technical field of embedded development. The method is used for solving the problems of high development cost and low efficiency in the development of the embedded service due to the fact that the development process of the embedded service in the prior art is complex. The method comprises the following steps: reading ESvcLisp source codes for realizing embedded services, reading character streams included by the ESvcLisp source codes according to a left-to-right sequence, and converting the character streams into mark streams according to a word formation rule; identifying various grammar components included in the marking stream according to grammar rules of a source language to obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression; and evaluating the second expression according to an evaluation rule, and outputting an evaluation result so as to enable the embedded equipment to execute the result and realize the embedded service.

Description

Embedded service development method and device
Technical Field
The invention relates to the technical field of embedded development, in particular to a development method and a device for embedded service.
Background
The embedded system is a special computer system which is customized and implanted into the controlled device according to a specific application scene, and is widely applied, but the resources are severely limited. If a great number of embedded devices can be interconnected through a network, and the embedded devices are used as a computing cluster to share system resources, the computing resources which can be output by the cluster become inconspicuous. For a single embedded device, the resources it can utilize are no longer localized, but are the sum of the resources of all the embedded devices interconnected to it, as long as it meets the most basic communication requirements. The practicability of the embedded system is undoubtedly greatly improved, the defects of the embedded system are effectively overcome while the advantages of the embedded system are exerted, so that the full potential of the embedded device can be exerted, and the embedded system is a good thing for the development of the embedded system.
The service is an independent program entity, can respond to and return user requests, can be independently deployed, operated and migrated, and has the characteristics of flexibility and light weight. The services are communicated by adopting a lightweight message protocol, and the cooperative work is realized through communication. The service running on the embedded device is an embedded service, and the process of abstracting the function of the embedded device into the service is embedded service. The realization of the service architecture on the embedded equipment can effectively utilize the resources of the embedded equipment, thereby realizing the cooperative work of the embedded equipment. The embedded system is connected from isolation and is cooperative and beneficial from resource limitation, so that the application scene of the embedded system is greatly widened, the development of the embedded system is promoted, and the contra-feeding of the embedded system to the development progress of human life is finally realized.
In summary, the development process of the embedded service in the prior art is complex, which causes the problems of high development cost and low efficiency in the development of the embedded service.
Disclosure of Invention
The embodiment of the invention provides a development method and a device for embedded services, which are used for solving the problems of high development cost and low efficiency in the development of embedded services due to the fact that the development process of the embedded services is complex in the prior art.
The embodiment of the invention provides an embedded service development method, which comprises the following steps:
reading ESvcLisp source codes for realizing embedded services, reading character streams included by the ESvcLisp source codes according to a left-to-right sequence, and converting the character streams into mark streams according to a word formation rule;
identifying various grammar components included in the marking stream according to grammar rules of a source language to obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression;
and evaluating the second expression according to an evaluation rule, and outputting an evaluation result so as to enable the embedded equipment to execute the result and realize the embedded service.
Preferably, the character stream of the ESvcLisp source code includes numbers, letters, parentheses, spaces, special symbols;
converting the character stream into a mark stream according to a word formation rule specifically comprises:
and respectively taking the blank and the bracket as separators, carrying out segmentation marks on the character stream according to the separators, and converting the character stream into a mark stream according to the segmentation marks.
Preferably, the evaluation rule comprises any one or more of the following in combination:
for a constant atom, the evaluation result is the constant atom itself;
for a symbol, searching a value corresponding to the symbol according to the environment to which the symbol belongs;
for function calls, the various parameters included within the function are evaluated in the current context, and the function is then called.
Preferably, the evaluating the second expression according to an evaluation rule further includes:
and recovering the garbage generated in the evaluation phase by adopting a garbage recovery strategy of mixing a reference counting mechanism and a Mark & sweet mechanism.
Preferably, the reading of the ESvcLisp source code ESvcLisp for implementing the embedded service specifically includes:
reading the ESvcLisp source code input by a user in real time from a command line interactive interface; or
Reading the ESvcLisp source code into a memory from an equipment file to wait for execution; or
And acquiring the ESvcLisp source code from the network port.
The embodiment of the invention also provides an embedded service development device, which comprises:
the conversion unit is used for reading ESvcLisp source codes for realizing embedded services, reading character streams included by the ESvcLisp source codes according to a left-to-right sequence, and converting the character streams into mark streams according to a word formation rule;
the obtaining unit is used for identifying various grammar components included in the marking flow according to grammar rules of the source language to obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression;
and the realization unit is used for evaluating the second expression according to the evaluation rule and outputting an evaluation result so as to enable the embedded equipment to execute the result and realize the embedded service.
Preferably, the character stream of the ESvcLisp source code includes numbers, letters, parentheses, spaces, special symbols;
converting the character stream into a mark stream according to a word formation rule specifically comprises:
and respectively taking the blank and the bracket as separators, carrying out segmentation marks on the character stream according to the separators, and converting the character stream into a mark stream according to the segmentation marks.
Preferably, the evaluation rule comprises any one or more of the following in combination:
for a constant atom, the evaluation result is the constant atom itself;
for a symbol, searching a value corresponding to the symbol according to the environment to which the symbol belongs;
for function calls, the various parameters included within the function are evaluated in the current context, and the function is then called.
Preferably, the implementation unit is further configured to:
and recovering the garbage generated in the evaluation phase by adopting a garbage recovery strategy of mixing a reference counting mechanism and a Mark & sweet mechanism.
Preferably, in particular for:
reading the ESvcLisp source code input by a user in real time from a command line interactive interface; or
Reading the ESvcLisp source code into a memory from an equipment file to wait for execution; or
And acquiring the ESvcLisp source code from the network port.
The embodiment of the invention provides a development method and a device of embedded service, wherein the method comprises the following steps: reading ESvcLisp source codes for realizing embedded services, reading character streams included by the ESvcLisp source codes according to a left-to-right sequence, and converting the character streams into mark streams according to a word formation rule; identifying various grammar components included in the marking stream according to grammar rules of a source language to obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression; and evaluating the second expression according to an evaluation rule, and outputting an evaluation result so as to enable the embedded equipment to execute the result and realize the embedded service. Compared with the existing common language C or C + + for embedded service development, the code provided by the method is simple and has strong expression capability, and can help embedded service developers to rapidly develop the embedded service.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1is a schematic flowchart of a development method for embedded services according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of an embedded service development device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 exemplarily shows a flowchart of a development method of embedded services according to an embodiment of the present invention.
As shown in fig. 1, the method mainly comprises the following steps:
step 101, reading an ESvcLisp source code for realizing embedded service, reading a character stream included by the ESvcLisp source code according to a left-to-right sequence, and converting the character stream into a tag stream according to a word formation rule; ESvcLispESvcLisp
102, identifying various grammar components included in the marking stream according to grammar rules of a source language to obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression;
and 103, evaluating the second expression according to an evaluation rule, and outputting an evaluation result so that the embedded equipment executes the result to realize the embedded service.
Before the development method of embedded services provided by the embodiment of the present invention is introduced, ESvcLisp, which is a service language facing an embedded system provided by the embodiment of the present invention, is introduced.
In terms of language design, the ESvcLisp includes two parts, an interpreter and a compiling module. The interpreter is responsible for interpreting and executing the code flow, and the compiling module is responsible for generating auxiliary information. Such as binary messages communicated between embedded services, bytecodes for composite services, and machine code for compute-intensive modules, etc.
In terms of application interfaces, ESvcLisp provides many supports for embedded service development, such as grammatical sugar designed for embedded service development at a grammatical level, garbage collection at a resource management level, and the like.
ESvcLisp language design
The general idea of ESvcLisp language design is that for a general business process, ESvcLisp provides a flexible dynamic language for description, and the business process can be developed quickly. For the key parts with strict performance requirements and severely limited resources, a compiling module can be adopted to compile the key parts into a special format capable of accelerating the running speed. In terms of data structure, ESvcLisp contains two basic data structures: tables and atoms, which constitute the program and data of the ESvcLisp.
1.1ESvcLisp interpreter
The ESvcLisp interpreter component is responsible for interpreting the executing ESvcLisp code. ESvcLisp is a LISP dialect, inherits many features of LISP, and adds innovation on servization. The ESvcLisp is a functional programming language and is composed of expressions, and the calculation process is realized by expression evaluation. From a concrete form, the program expression of ESvcLisp is a prefix expression. For example, the four arithmetic expressions in mathematics are as follows: 1+2
In esvclip can be written: (+12)
Wherein, the atoms in the ESvcLisp include symbol atoms and number atoms.
Specifically, a symbol atom refers to a character string composed of a limited number of letters, special characters, and numbers; unlike classical LISP, in ESvcLisp all atoms that cannot be interpreted as number atoms are considered symbol atoms, some of which have special meaning in practical applications, e.g. nil symbol atom represents a null type and # t and # f symbol atoms represent logical true and logical false, respectively.
A number atom is a string of numbers, the sign of which indicates the sign. For example, 100, 1.2, 1.2e10, -2, 0x1fff, 0b10001000, etc. are all numbers of atoms.
Further, for atoms 1mnzw and 1234567.s, which contain numbers, they cannot be interpreted as numbers, since they contain letters inside, and are both symbolic atoms.
Further, a table may contain not only an atom but also another table. For example, in expression (+ (+ 12) (+ 34)) (+ 12) is a table and (+ 34) is also a table, the expression itself is a nested table. The size of the table is not limited in esvclip, and the smallest table is an empty table ().
The table is a very important constituent element in ESvcLisp, and operations on the table are usually performed by fetching a header, merging the table, accessing an element in the table, and the like. These operations can be performed as a function of the ESvcLisp built-in operation table, which is fully optimized to fit the underlying platform, functions and examples as in table 1.
TABLE 1 Table operation in ESvcLisp
Figure BDA0003094841540000071
The basic operations provided in Table 1 may be combined into more complex operations, implementing various operations on the table. Such as: expression (car (cdr (123))), whose output is 2, implements the second element of the fetch list.
To the extent that the embedded service development work itself is done, it is writing a program for the purpose of processing data. Program and data are two major elements in programming, and in ESvcLisp, both are represented by tables, with similarities. If the embedded service developer writes a table in the ESvcLisp source code, the ESvcLisp interpreter evaluates the table. For example, an expression is written in esvclip: after (+ 12), the esvclip interpreter will evaluate it, returning a value of 3; but for the expression: (123) if the above expression is entered in the esvclip interpreter, an error is obtained: error: 1is invalid as a function means that 1is not a usable function.
In all tables, the first atom is always a function, representing an operation, instruction, command. And the following atoms or tables are all parameters, meaning descriptions of operations. Namely, the expression: (+ 12) represents 1+2, and the expression: (-43) represents 4-3.
ESvcLisp will evaluate all tables but if one wants to use the table itself as data, it can be prevented from evaluating by just one simple operator, that is the' (prime) operator.
1.2 syntax of classical LISP inherited by ESvcLisp
The syntax of ESvcLisp inherits the classical LISP, in which there are two basic components, namely a variable and a value, which can exist independently of the variable, i.e. without binding the value of the variable, such as a one-time function generated by a lambda expression; a variable may also exist independently of a value, when the variable is a special element, namely Symbol, the Symbol to which the value is bound is the variable, which is added to the environment.
For example, the expression: environment: [ { symbol: value } ], which represents a context, i.e., a set of symbol-value pairs. Each set of such symbol-value pairs constitutes a variable.
TABLE 2 syntax of ESvcLisp inherited classic LISP
Figure BDA0003094841540000081
Figure BDA0003094841540000091
ESvcLisp provides a series of basic operators, which are divided into mathematical operators, logical operators, etc. for performing mathematical operations and logical operations, respectively, as shown in table 3.
TABLE 3 operators in ESvcLisp
Figure BDA0003094841540000092
Figure BDA0003094841540000101
1.3 New syntax introduced by ESvcLisp
TABLE 4 ESvcLisp-introduced New syntax
Figure BDA0003094841540000102
The purpose of introducing the switch expression into the ESvcLisp is to match various conditions, avoid the unclear nesting if expression and facilitate the embedded service developers in the conventional C language to quickly start. Unlike C, a switch expression will continue to match backwards only if a value does not match. Otherwise, as soon as a matching value is found, the switch expression returns the expression corresponding to the branch. That is, a switch in esvclip implies break.
For historical reasons, the popularity of the C-system language influences the writing habits of people in the programming language, and the prefix expression used by the LISP language is inconsistent with the habits of the public. For function calls, people are more accustomed to writing foo (bar) than writing (foo bar).
For this reason, esvclip generalizes the concept of "such a prepended notation in LISP to denote a modifier, introducing the concept of a prefix atom, compatible with this notation similar to a function call in the C-system language, to reduce migration costs for developers. Therefore, foo (bar) is also a legitimate ESvcLisp code. Wherein, foo will be recognized as prefix atom in lexical analysis stage, and remove grammatical sugar according to corresponding rule in grammar analysis stage, become (foo bar).
Another purpose of introducing prefix atoms is to simplify the ESvcLisp expression. These prefix atoms are often very short and consist of special characters, indicating a special meaning. The existence of the ESvcLisp can simplify complex expressions, so that ESvcLisp codes are clearer and simpler, and the development efficiency is improved.
For example, ESvcLisp provides several classical prefix tags' as a prefix tag, read as "quote" in LISP, that are compatible with LISP, and represents that the table element decorated by the prefix tag is not a function call but a static list, a collection of elements. For example, the expression: ' (1234) will be identified as the prefix of the modifier list (1234) during the lexical analysis stage, and expanded into (quote 1234) during the syntactic analysis stage, returning a table atom containing four number atoms.
In order to facilitate embedded service development, the ESvcLisp provides a series of new prefix atoms, which are usually composed of special symbols, and are short and bold, so that the intention of a service developer can be better expressed, and the development efficiency is improved. The partial prefix atoms are as in table 5.
TABLE 5 Prefix atom Table in ESvcLisp
Figure BDA0003094841540000111
Figure BDA0003094841540000121
Among them, classical prefix atoms like', and, @ etc. are also supported among ESvcLisp.
1.4ESvcLisp compilation module
The ESvcLisp compiling module is expressed in a built-in function in form, and the compiling module is started through function calling. These modules may be written by a developer to process incoming ESvcLisp values.
The ESvcLisp compilation module functions in two situations: first, network communications often require the generation of specific message formats, whether JSON, XML or special binary messages. The ESvcLisp compiling module enables ESvcLisp data to be compiled into data in different formats for network transmission, adapts to different targets, and hides the process from developers, so that the mental burden of the developers is reduced.
The esvclip compiling module can accelerate performance bottleneck, and esvclip as an interpreted language is often inferior in performance compared with a compiled language directly compiled to a target platform machine code. In order to fully utilize the computing power of the embedded device, the method adapts to the fact that the resources of the embedded device are limited. For the key codes which are repeatedly executed, the ESvcLisp compiling module can start instant compiling, generate machine codes corresponding to the target platform and accelerate the execution speed. The ESvcLisp compiling module can also directly import fully optimized machine codes to solve performance bottlenecks or utilize existing libraries of other languages.
2. Application interface
ESvcLisp presents developers with support for embedded services in several ways:
ESvcLisp provides a service interface to developers that is similar to a function. The service calling is used as a remote procedure calling, is close to function calling in syntax, and reduces the mental burden of programmers.
The esvclip provides macro and grammar sugar, can conveniently extend the grammar of the esvclip, and is suitable for simplifying service implementation. Meanwhile, the kernel of the ESvcLisp language is kept simple and easy to realize, and the embedded service resource is convenient to fit the reality of cross-platform and limited embedded service resources.
The ESvcLisp provides a garbage recycling mechanism, can effectively manage memory resources, and is suitable for the reality that resources of an embedded system are limited.
ESvcLisp provides pattern matching process call data so that embedded service developers do not have to be bothered with the cumbersome processing of data formats.
2.1 service interfaces similar to functions
In ESvcLisp, services are semantically close to functions, and the calling of the services does not have side effects. The declaration of a service is similar to the declaration of a function, the definition of a service is similar to the definition of a service, and the invocation of a service is similar to the invocation of a function. The relationship and difference between them are shown in Table 6.
TABLE 6 ESvcLisp function vs. service comparison
Figure BDA0003094841540000131
It should be noted that the prefix atomic% # written before the service invocation table may be omitted, and its main role is to emphasize that the invocation is a service invocation. If not, the ESvcLisp interpreter will call the variable bound to the symbol ser itself, and if the value of the variable is a function, the call is a function call. If the value of the variable binds to a service, the call is a service call.
2.2 Macro and grammar sugar
The ESvcLisp inherits the powerful grammar extension function of the LISP system language, and besides the built-in grammar sugar which is convenient to develop, the ESvcLisp provides a macro mechanism which enables developers to customize grammar sugar belonging to the ESP, so that the ESvcLisp has great significance for service development.
ESvcLisp can be defined by a defmacro expression, such as (defmacro-name macro-body), where macro-body is a lambda expression, but unlike the usual function definition, the mechanism of the lambda expression corresponding to the macro is to expand rather than to call, i.e. the macro does not evaluate the argument passed to it, but directly replaces it. The replaced expression is further expanded until it is completely expanded into the basic form. The macro-expanded expression is then evaluated in place.
For development convenience, ESvcLisp provides a series of grammatical saccharides that are expanded after the parsing stage, before the evaluation stage, and then the expanded expressions are evaluated.
For example, a conventional function definition function body can only be a single expression, and to include multiple expressions in the function body, begin expressions must be used for packing. However, the large occurrence of begin expression is actually a kind of redundancy of information. The presence of grammatical saccharides can enable developers to omit begins when writing function definitions and then automatically patch programmers during the development phase.
Therefore, the simplification of the program kernel is ensured, and the embedded platform with limited resources can be operated. Meanwhile, the method also ensures the simplicity and convenience of grammar, so that embedded service developers can develop conveniently.
2.3 garbage reclamation and resource management
As is well known, the resources of embedded devices are often severely limited, and the memory resources are used as a precious system resource, which needs to be managed effectively to avoid memory leakage.
However, manual memory management is too complicated, errors are prone to occur, the burden on a developer is too heavy, and development of embedded services is not facilitated. To this end, ESvcLisp introduces a garbage recycling mechanism. The use condition of the memory can be monitored with lower cost, useless memory is released at proper time, and precious memory resources are saved, so that the reality that embedded service resources are limited is met.
2.4 Pattern matching
Pattern matching is a common function of modern programming languages. The pattern matching provides a convenient way for deconstructing the data structure, and the deconstruction based on the pattern matching and the construction of algebraic data types are similar in form and have consistency, so that the mental burden of developers can be greatly reduced.
The following is an example to illustrate the effect of pattern matching on expressions
(match'(1 2 3)
[(list a b c)a])
Then after pattern matching is complete, a has a value of 1, b has a value of 2, and c has a value of 3. This process is consistent with the construction of the list in the ESvcLisp, e.g. it is possible to use
(define a 1)
(define b 2)
(define c 3)
(list a b c)
And returning to the list (1, 2, 3) after evaluation, wherein the construction process is symmetrical to the process of pattern matching, and the formal consistency of the two processes is beneficial to reducing the complexity of the language and facilitating the learning of developers.
The introduction of the mode matching function is beneficial to writing the embedded service by utilizing the ESvcLisp to process the received calling data. Generally speaking, due to the requirement of network transmission, the call data received by the embedded service has a certain structure and a specific format, and the format and the structure are often different from the data structure of the embedded service itself, that is, the call data needs to be processed by parsing and converting the native data form of the programmed embedded service. Through the pattern matching mechanism of the ESvcLisp, the analysis process is hidden for developers, the developers can directly and reasonably describe the structure of data, the variables of the computing module are directly bound to the received request data, and the analysis and conversion processes are automatically completed, so that the program is simple and clear, and the development efficiency is improved.
The role of ESvcLisp pattern matching for embedded service development is illustrated below by way of a simple example. Assuming that the XORService receives a call message encapsulated in a special data format, which contains two boolean values, the XORService has a main task of parsing the call message, converting the pair of boolean values into special symbol atoms # t and # f of which ESvcLisp represents the boolean value, then performing an exclusive-or operation on the pair of boolean variables, and returning the result. If the received call information is recorded as the variable recv-data and the return value is recorded as the return-data, then
Figure BDA0003094841540000161
Res is a calculation result, and the calculation process of the service can be easily described by matching with the concise message data construction grammar of the ESvcLisp, so that the representation is strong.
In step 101, reading an ESvcLisp source code, reading a character stream included in the ESvcLisp source code according to a left-to-right sequence, and converting the character stream into a tag stream according to a word formation rule.
Reading the ESvcLisp source code in the following three modes:
firstly, reading ESvcLisp source codes input by a user in real time from a command line interactive interface, and developing a 'reading-evaluating-outputting' loop.
Secondly, reading the ESvcLisp source code into the memory from the equipment file to be interpreted and executed as a character string.
Thirdly, the esvclip interpreter itself, as an embedded service, monitors a specific port, processes a specific message, and obtains an esvclip source code from a network port, thereby implementing remote deployment and migration of the service.
In practical applications, lexical analysis is the process of converting character sequences into token sequences in computer science. The task of this stage is to read in the esvclip source code from left to right, character by character, i.e. to scan the character stream comprised by the esvclip source code and then to identify the markers according to the construction rules.
In an embodiment of the present invention, the character stream of the ESvcLisp source code may include numbers, letters, parentheses, spaces, special symbols, and the like. Furthermore, in the character stream, spaces and parentheses may be used as separators, that is, segmentation marks are made on the character stream according to the separators, and the character stream is converted into a mark stream according to the segmentation marks.
In practical applications, ESvcLisp supports three brackets, namely curly brackets { }, square brackets [ ] and round brackets (). These three brackets are semantically equivalent and can be mixed in the code, but it must be noted that the brackets are used to match, namely, the left curly bracket { can only match with the right curly bracket }, correspondingly, the left curly bracket [ can only match with the right curly bracket ], and the left curly bracket (can only match with the right curly bracket); otherwise, an error is reported.
It should be noted that, in the ESvcLisp lexical analysis stage, each token is classified according to the word formation rule. For example, for a label that can be interpreted as a number, its category is the number, corresponding to the number atom in ESvcLisp. In particular, if a marker ends in left brackets, the marker may be a prefix atom. If the token cannot be interpreted as a number, but as a symbol, the class of the token is a prefix token, corresponding to the prefix atom in ESvcLisp: the identification of prefix atoms is done at the lexical analysis stage.
In step 102, identifying various grammar components included in the markup stream according to grammar rules of a source language to obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression;
in the embodiment of the invention, the grammar analysis is used for identifying various grammar components from the tag sequence output in the lexical analysis stage according to the grammar rules of the source language. The parsing stage of the ESvcLisp language is similar to that of the classic LISP language, and is not described here again.
It should be noted that prefix atoms introduced by ESvcLisp affect the behavior of ESvcLisp in the parsing stage. For example, some embedded services require system commands or other local programs that invoke the embedded platform. In order to simplify the process, developers can conveniently interact with the system like writing shell scripts, ESvcLisp provides a special prefix atom% $ modifies a table, and therefore a shell command is formally simulated.
Such as: in the Linux platform, when all files in a certain folder dir are to be viewed, the following commands can be directly input into the shell:
ls-l/usr/dir
while in other languages, such as C, it is necessary to write:
system("ls-l/usr/dir");
executing commands in this manner requires developers to convert the commands into character strings through various methods for execution, thereby increasing development costs virtually. In some cases, this process is very cumbersome. Such as: if "/usr/dir" is deposited in the variable mydir, the developer has to expand mydir into "/usr/dir" for direct transfer. In contrast, it is possible to write directly in ESvcLisp
%$(ls-l mydir)
mydir stores a string quantity "/usr/dir" as a common variable in an esvclip environment. After the "% $ is used as a prefix expression and is recognized by the lexical analysis module and the syntactic analysis module, for each atom in the table, due to the effect of prefix modification, if a corresponding variable can be found in the current environment, the atom is replaced by a value corresponding to the variable, otherwise, the atom is converted into a character string, and the literal value of the symbol atom is the converted constant of the character string. For atoms of non-string type, such as a number atom, the number atom is converted into its string representation, and the converted atoms separated by the last space are concatenated into a string to generate an expression for ESvcLisp to make system calls
(system“ls-l/usr/dir”)
Further, after each grammar component included in the markup stream is identified according to the grammar rule, the first expression can be obtained, wherein the first expression can be a complete sentence or a sentence with some grammar components omitted. If the first expression is a complete sentence, evaluation and output operation can be carried out on the complete sentence; if the first expression is an incomplete sentence, grammatical sugar reduction needs to be carried out on the incomplete sentence to obtain a second expression, and the complete sentence is obtained.
In the embodiment of the present invention, the grammar sugar reduction is the first expression development stage, for example, a function including a plurality of expressions is packed into a begin expression, a function definition without a lambda expression is reduced into a function definition with a lambda expression, and the like. The main purpose of this stage is to reduce the expression to the basic form.
This stage also processes the macro definition, which is defined using the defmacro expression, similarly to the function definition, and the parameters and macro body of the macro are packed and recorded. The main differences between the procedure of macro unrolling and the procedure of function calling are two points:
first, the macro expansion does not evaluate the parameters, but instead brings in post expansion.
Second, the scope of the function is static. The scope of the macro is dynamic.
The result of the macro expansion is an expression which is expanded to the basic form and then evaluated at the position of the macro expansion, thereby playing the role of expanding the grammar.
This stage also checks the syntax of the code and if a non-syntax-compliant expression is encountered, the expression is rejected from execution and syntax errors are reported.
In step 103, the second expression is evaluated according to an evaluation rule. Specifically, the esvclip evaluation phase evaluates the expression, generally as follows: for a constant atom, return itself directly; for the symbol, searching a value corresponding to the symbol according to the current environment and returning; for function call, each parameter is evaluated in the current environment, and then function call is carried out; the process of the function call creates a new environment that constructs the symbolic value pairs with the function arguments as symbols and the arguments as values. The process of function evaluation evaluates the body of the function within this constructed function call environment.
When the evaluation of the second expression is completed, the evaluation result may be output. The result delivery phase is the process of displaying the evaluated result, or expressing the side effects (e.g., IO) evaluated as a result.
It should be noted that garbage collection is also performed in the function evaluation stage. In particular, since the ESvcLisp mainly plays a role in developing embedded services, the embedded services as a service have a certain idle time to wait for network requests, and the waiting for network requests results from evaluating network request expressions, garbage collection can be performed at this time without slowing service responses. Moreover, the evaluation phase involves the invalidation of old values and the generation of new values, and the memory resources are subject to change, so that this phase is suitable for starting the garbage collection process.
ESvcLisp employs a garbage collection strategy that mixes the two mechanisms reference counting and Mark & sweet. Each ESvcLisp value is set to 1 at the beginning of the new creation. When this Lisp value is referenced by another Lisp value, such as when an atom or table becomes a constituent element of another table, the reference count is incremented by 1. Whenever a new value is created, the memory resource usage will increase and this change will be recorded. When values are released, memory resource usage is reduced and the process is tracked. Therefore, the ESvcLisp environment can sense the change of the memory resource in time. And when the available memory resources are reduced to the lower limit of the preset threshold, the garbage recycling process can be automatically started, the reference counts of all the recorded values are reduced by one, and the memory resources occupied by the values with the reference counts changed into 0 are released. I.e. values that are only referenced by the esvclip environment itself.
In particular, for a value containing a sub-value, such as the ordinary ESvcLisp table, when it is recycled, the reference count of its sub-value is also decremented by 1, and then it is checked whether the reference count of the sub-value is 0, and if it is 0, the sub-value is also recycled.
For self-contained cases, ESvcLisp employs another mechanism to solve the problem of circular referencing. After the first garbage recovery, the self-contained or circularly-referenced value itself is not recovered, and becomes a missing fish under the mechanism. At this point, the garbage collection mechanism will begin a second round of collection, which will attempt to decrement the reference count of all values by one, at which point only the values still referenced by ESvcLisp have reference counts other than 0.
It should be noted that a reference count of 0 at this time does not indicate that the value is inaccessible, and does not mean that the value can be recycled. As the values that can be referenced by ESvcLisp in part can still be accessed. At this time, the esvclip will temporarily mark the value of these references counting as 0 as reclaimed. Subsequently, the ESvcLisp will traverse those values whose reference count is still greater than 0, access their child values, and if their child values are marked as reclaimed, then cancel the marking. In this way, the values that are ultimately marked as reclaimed are all values that cannot be accessed by other values that do not require reclamation, and are reclaimed.
It is worth mentioning that for some system critical values, such as # t, # f as symbolic atoms, they are created dynamically at interpreter initialization, but should not be reclaimed at any time. For these values, their reference counts are locked to negative numbers, as are the reference counts of the child values that are referenced by them. For values where the referencing technique is negative, no reclamation is done all the way through.
Based on the same inventive concept, the embodiment of the invention provides an embedded service development device, and as the principle of the device for solving the technical problem is similar to that of an embedded service development method, the implementation of the device can refer to the implementation of the method, and repeated parts are not described again.
Fig. 2 is a schematic structural diagram of an embedded service development device according to an embodiment of the present invention, and as shown in fig. 2, the device mainly includes: a conversion unit 201, a derivation unit 202 and an implementation unit 203.
A conversion unit 201, configured to read in an ESvcLisp source code for implementing an embedded service, read a character stream included in the ESvcLisp source code according to a left-to-right sequence, and convert the character stream into a tag stream according to a word formation rule;
an obtaining unit 202, configured to identify, according to a grammar rule of the source language, various grammar components included in the markup stream, and obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression;
the implementation unit 203 is configured to evaluate the second expression according to an evaluation rule, and output an evaluation result, so that the embedded device executes the result to implement the embedded service.
Preferably, the character stream of the ESvcLisp source code includes numbers, letters, parentheses, spaces, special symbols;
converting the character stream into a mark stream according to a word formation rule specifically comprises:
and respectively taking the blank and the bracket as separators, carrying out segmentation marks on the character stream according to the separators, and converting the character stream into a mark stream according to the segmentation marks.
Preferably, the evaluation rule comprises any one or more of the following in combination:
for a constant atom, the evaluation result is the constant atom itself;
for a symbol, searching a value corresponding to the symbol according to the environment to which the symbol belongs;
for function calls, the various parameters included within the function are evaluated in the current context, and the function is then called.
Preferably, the implementing unit 203 is further configured to:
and recovering the garbage generated in the evaluation phase by adopting a garbage recovery strategy of mixing a reference counting mechanism and a Mark & sweet mechanism.
Preferably, the conversion unit 201 is specifically configured to:
reading the ESvcLisp source code input by a user in real time from a command line interactive interface; or
Reading the ESvcLisp source code into a memory from an equipment file to wait for execution; or
And acquiring the ESvcLisp source code from the network port.
It should be understood that the above embedded service development device includes only logical division units according to the functions implemented by the apparatus device, and in practical applications, the above units may be stacked or split. The functions implemented by the embedded service development device provided in this embodiment correspond to the embedded service development methods provided in the above embodiments one to one, and for a more detailed processing flow implemented by the device, detailed description is already made in the above method embodiment, and detailed description is not given here.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.

Claims (10)

1. A development method of embedded service is characterized by comprising the following steps:
reading ESvcLisp source codes for realizing embedded services, reading character streams included by the ESvcLisp source codes according to a left-to-right sequence, and converting the character streams into mark streams according to a word formation rule;
identifying various grammar components included in the marking stream according to grammar rules of a source language to obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression;
and evaluating the second expression according to an evaluation rule, and outputting an evaluation result so as to enable the embedded equipment to execute the result and realize the embedded service.
2. The method of claim 1, wherein the stream of characters of the ESvcLisp source code includes numbers, letters, brackets, spaces, special symbols;
converting the character stream into a mark stream according to a word formation rule specifically comprises:
and respectively taking the blank and the bracket as separators, carrying out segmentation marks on the character stream according to the separators, and converting the character stream into a mark stream according to the segmentation marks.
3. The method of claim 1, wherein the evaluation rule comprises any one or more of the following in combination:
for a constant atom, the evaluation result is the constant atom itself;
for a symbol, searching a value corresponding to the symbol according to the environment to which the symbol belongs;
for function calls, the various parameters included within the function are evaluated in the current context, and the function is then called.
4. The method of claim 1, wherein said evaluating said second expression according to an evaluation rule, further comprises:
and recovering the garbage generated in the evaluation phase by adopting a garbage recovery strategy of mixing a reference counting mechanism and a Mark & sweet mechanism.
5. The method according to claim 1, wherein reading in an ESvcLisp source code ESvcLisp used to implement the embedded service specifically comprises:
reading the ESvcLisp source code input by a user in real time from a command line interactive interface; or
Reading the ESvcLisp source code into a memory from an equipment file to wait for execution; or
And acquiring the ESvcLisp source code from the network port.
6. An embedded servitization development device, comprising:
the conversion unit is used for reading ESvcLisp source codes for realizing embedded services, reading character streams included by the ESvcLisp source codes according to a left-to-right sequence, and converting the character streams into mark streams according to a word formation rule;
the obtaining unit is used for identifying various grammar components included in the marking flow according to grammar rules of the source language to obtain a first expression; reducing grammatical sugar contained in the first expression to obtain a second expression;
and the realization unit is used for evaluating the second expression according to the evaluation rule and outputting an evaluation result so as to enable the embedded equipment to execute the result and realize the embedded service.
7. The apparatus of claim 6, wherein the stream of characters of the ESvcLisp source code includes numbers, letters, brackets, spaces, special symbols;
converting the character stream into a mark stream according to a word formation rule specifically comprises:
and respectively taking the blank and the bracket as separators, carrying out segmentation marks on the character stream according to the separators, and converting the character stream into a mark stream according to the segmentation marks.
8. The apparatus of claim 6, wherein the evaluation rule comprises any one or more of the following in combination:
for a constant atom, the evaluation result is the constant atom itself;
for a symbol, searching a value corresponding to the symbol according to the environment to which the symbol belongs;
for function calls, the various parameters included within the function are evaluated in the current context, and the function is then called.
9. The apparatus of claim 6, wherein the means for implementing is further configured to:
and recovering the garbage generated in the evaluation phase by adopting a garbage recovery strategy of mixing a reference counting mechanism and a Mark & sweet mechanism.
10. The apparatus as claimed in claim 6, wherein said conversion unit is specifically configured to:
reading the ESvcLisp source code input by a user in real time from a command line interactive interface; or
Reading the ESvcLisp source code into a memory from an equipment file to wait for execution; or
And acquiring the ESvcLisp source code from the network port.
CN202110611631.7A 2021-06-01 2021-06-01 Development method and device for embedded service Active CN113220277B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110611631.7A CN113220277B (en) 2021-06-01 2021-06-01 Development method and device for embedded service

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110611631.7A CN113220277B (en) 2021-06-01 2021-06-01 Development method and device for embedded service

Publications (2)

Publication Number Publication Date
CN113220277A true CN113220277A (en) 2021-08-06
CN113220277B CN113220277B (en) 2023-12-19

Family

ID=77082720

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110611631.7A Active CN113220277B (en) 2021-06-01 2021-06-01 Development method and device for embedded service

Country Status (1)

Country Link
CN (1) CN113220277B (en)

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4931928A (en) * 1988-11-09 1990-06-05 Greenfeld Norton R Apparatus for analyzing source code
US20020042707A1 (en) * 2000-06-19 2002-04-11 Gang Zhao Grammar-packaged parsing
US6473896B1 (en) * 1998-10-13 2002-10-29 Parasoft, Corp. Method and system for graphically generating user-defined rules for checking language quality
US20070055966A1 (en) * 2005-09-08 2007-03-08 Lucent Technologies Inc. Yet another transformation language (YATL)
WO2007051531A2 (en) * 2005-11-02 2007-05-10 Georg-August-Universität Göttingen - Stiftung Öffentlichen Rechts Method and device for call oriented programming
US20160350084A1 (en) * 2015-05-29 2016-12-01 Intentional Software Corporation System and method for combining text editing and tree encoding for computer programs
US20170329582A1 (en) * 2016-05-15 2017-11-16 Synopsys, Inc. Systems and Methods for Model-Based Analysis of Software
CN110007926A (en) * 2019-04-17 2019-07-12 广东三维家信息科技有限公司 Language transfer method and device
CN112632924A (en) * 2020-12-18 2021-04-09 上海明略人工智能(集团)有限公司 Method, system, electronic device and storage medium for labeling regularized execution sequence
CN112748914A (en) * 2020-03-18 2021-05-04 腾讯科技(深圳)有限公司 Application program development method and device, electronic equipment and storage medium

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4931928A (en) * 1988-11-09 1990-06-05 Greenfeld Norton R Apparatus for analyzing source code
US6473896B1 (en) * 1998-10-13 2002-10-29 Parasoft, Corp. Method and system for graphically generating user-defined rules for checking language quality
US20020042707A1 (en) * 2000-06-19 2002-04-11 Gang Zhao Grammar-packaged parsing
US20070055966A1 (en) * 2005-09-08 2007-03-08 Lucent Technologies Inc. Yet another transformation language (YATL)
WO2007051531A2 (en) * 2005-11-02 2007-05-10 Georg-August-Universität Göttingen - Stiftung Öffentlichen Rechts Method and device for call oriented programming
US20160350084A1 (en) * 2015-05-29 2016-12-01 Intentional Software Corporation System and method for combining text editing and tree encoding for computer programs
US20170329582A1 (en) * 2016-05-15 2017-11-16 Synopsys, Inc. Systems and Methods for Model-Based Analysis of Software
CN110007926A (en) * 2019-04-17 2019-07-12 广东三维家信息科技有限公司 Language transfer method and device
CN112748914A (en) * 2020-03-18 2021-05-04 腾讯科技(深圳)有限公司 Application program development method and device, electronic equipment and storage medium
CN112632924A (en) * 2020-12-18 2021-04-09 上海明略人工智能(集团)有限公司 Method, system, electronic device and storage medium for labeling regularized execution sequence

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
廖媛媛等: "基于C/C++的词法分析器的设计与实现", 《现代计算机(专业版)》 *
徐玉坤等: "建模语言中的文本表面语法分析方法研究", 《计算机应用研究》 *

Also Published As

Publication number Publication date
CN113220277B (en) 2023-12-19

Similar Documents

Publication Publication Date Title
Giacalone et al. Facile: A symmetric integration of concurrent and functional programming
US7665073B2 (en) Compile time meta-object protocol systems and methods
US8850414B2 (en) Direct access of language metadata
US6854123B1 (en) Method, system, and program for mapping standard application program interfaces (APIs) to user interface APIs
US11474797B2 (en) Generating closures from abstract representation of source code
WO2007035545A2 (en) Apparatus, method and system for building software by composition
Fredriksson et al. Seamless distributed computing from the geometry of interaction
Kreitz The Nuprl Proof Development System, Version 5: Reference Manual and User’s Guide
Nordlander Polymorphic subtyping in O'Haskell
Pierce et al. A typed higher-order programming language based on the pi-calculus
CN113220277B (en) Development method and device for embedded service
Haller et al. A reduction semantics for direct-style asynchronous observables
Van Tendeloo et al. Modelverse specification
JPH11296359A (en) Program development support tool
Díaz Pernil et al. P-lingua: A programming language for membrane computing
Weelden Putting types to good use
JP2002132502A (en) Automatic creating system and method of distributed object with interpretation of language function
Lee et al. A Study on the Source Translator for Generating the Android Game Source from the WIPI Game Source
Feldman Edward W. Czeck
Wilmet The glib/gtk+ development platform
Berthomieu Process calculi at work—an account of the LCS project
Wenger Design and implementation of a compiler for a fog and IoT programming language
Wielemaker SWI-Prolog 3.2
Yamazaki et al. A Study of Protocol-Checking and Memory-Management Techniques for Assisting Library Development
Watson et al. Practicalities of Syntax Analysis

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant