User:Dinsdale247/sandbox

JavaScript Interpreter Shell (Jsish or Jsi for short) is a glue language designed for use in embedded systems. Jsi is compliant to C99 which allows for a broad range of cross platform compatibility.

Design
Jsi is a JavaScript based glue language designed to be embedded in applications written in C or C++. The interpreter is optimized to be lightweight and easily embedded rather than seeking the highest possible runtime performance. While the overall goal is a small total footprint, Jsi is designed to include many of the major components that developers require such as a built in SQLite database support, compression, sockets and support for secure web communications, a lightweight web server and a built in debugger.

Jsi has also been designed to reduce or eliminate the need to write threaded software by taking advantage of the | Javascript Event Loop. Developers can hook into the event loop using setInverval and Event.Update and create complex applications where time sensitivity is not a factor.

History
Jsi was conceived based on Peter MacDonald's experience working with embedded applications. Peter noted that a large number of bugs in embedded software were in non-time-sensitive code and those bugs were usually simple in nature. These routines were often written in C or C++ due to necessity, rather than the language being a good choice for the task. It was also evident to Peter that most developers have some familiarity with Javascript due to the ubiquity of web development. It seemed natural then that a new language was required that wedded the familiarity people have with JavaScript, to the tool sets commonly used to embedded systems software.

Jsi began as a simple fork of the quad-wheel interpreter by ?. Much of the original code was replaced as the system was brought up to date with later revisions of ecmascript. The tokenization of the scripts was changed to be loosely modeled on the Tcl line based interpreter. Revision 1 was release in June 2016 after the code was stabalized on Ecmascript 5.1 and features such as SQLite, websockets and compression were added.

Jsi verison 2 was released in June 2017 with a large number of improvments and some additions from ecmascript 6. Version 2 also included an improved debugger, a web server and a web client interface to the debugger.

Syntax
See JavaScript Syntax.

ECMAScript Compliance
Jsi implements version 5.1 of the Ecma-script 262 standard, with the following deviations:


 * Semicolons are not auto-inserted.
 * Empty array/object elements are not supported, eg. [1,,3].
 * It is an error to use return inside of a try/catch body.
 * The Error object is unimplemented: the argument to catch is just a string.
 * The Date object is unimplemented: use strftime/strptime.
 * The value of typeof [] is "array" instead of "object".
 * UTF is currently not supported.

Extensions to the 5.1 standard include:


 * Function support for parameter types and defaults.
 * Support for Array of iterator, eg: for (var X of Y) (as in Ecma-script 6).
 * Partial support for Array forEach command, eg: lst.forEach(function(val){}).

Interpreter
Jsi is a byte code based interpreter.

Type Checking
Jsi supports type checking across function calls to reduce errors caused by implicit conversions when passing arguments.

Modules
Jsi Modules are a set of programmatic conventions that allow a script to be run from the command line or be "required" by another script for inclusion and use as an object. Modules provide command line option parsing and simple help output.

The 7 parts of a module are:

Here is an example module ./fileSize.jsi:

Invoked as:

./fileSize.jsi -debug true file1 file2 file3

Leading switches are passed in opts with the remaining arguments in fargs.

Note that options coming in from the command-line must be primitives.

C API
Jsi is intended to be embedded into other applications.

The following example creates Jsi commands in C, initializes an interpreter and then runs the C functions from within the JavaScript Interpeter

Additional tools
Jsi was designed to be convenient for embedded development. The base system contains a number of tools that make Jsi convenient to debug when using target hardware:

SQLite
Jsi contains a built in SQLite interface.

Debugger
The built in debugger used by calling a Jsi script from the command line using -d for the command line interface. If a GUI web browser is available the -D option can be used and the code can be browsed and debugged in a debugger.