Category:Jsish: Difference between revisions

From Rosetta Code
Content added Content deleted
m (version update to 2.8)
m (spacing and some prose change)
Line 21: Line 21:
* Function definitions can use type specifiers and default values.
* Function definitions can use type specifiers and default values.



While '''Jsish''' can honestly be called a Javascript interpreter, the extensions and differences from standard, form what is, realistically, a different language.
While '''Jsish''' can honestly be called a Javascript interpreter, the extensions and differences from standard, form what is, realistically, a different language. For instance:


nodejs> [1,2] + [2,1]
nodejs> [1,2] + [2,1]
"1,22,1"
"1,22,1"

jsish> [1,2] + [2,1];
jsish# [1,2] + [2,1];
0
0

Typed parameters for functions also sets Jsi apart from other ECMAScript implementations.


prompt$ jsish
prompt$ jsish
Line 33: Line 36:
# function foo (a:number, b:string="ok"):number { return a+1; }
# function foo (a:number, b:string="ok"):number { return a+1; }
variable
variable

/* Demonstrate parameterized types */
/* Demonstrate parameterized types */
# foo('a', 1, 2)
# foo('a', 1, 2);
warn: got 3 args, expected 1-2, calling function foo(a:number, b="ok"):number (at or near "a")
warn: got 3 args, expected 1-2, calling function foo(a:number, b="ok"):number (at or near "a")
warn: type mismatch for argument arg 1 'a': expected "number" but got "string", in call to 'foo' <a>. (at or near "a")
warn: type mismatch for argument arg 1 'a': expected "number" but got "string", in call to 'foo' <a>. (at or near "a")
Line 41: Line 44:
warn: type mismatch returned from 'foo': expected "number" but got "string", in call to 'foo' <a1>. (at or near "a")
warn: type mismatch returned from 'foo': expected "number" but got "string", in call to 'foo' <a1>. (at or near "a")
"a1"
"a1"

# foo(1)
# foo(1);
2
2
#
#

Revision as of 04:32, 6 March 2019

Language
Jsish
This programming language may be used to instruct a computer to perform a task.
Official website
Garbage collected: Yes
Parameter passing methods: By value
Type strength: Weak (assistive)
Type expression: Implicit
Type checking: Dynamic
See Also:


Listed below are all of the tasks on Rosetta Code which have been solved using Jsish.

Jsish is a scripting language based on ECMAScript syntax, influenced by Tcl internals, extended for Web development, and designed for embedded use. Developed by Peter MacDonald, the creator of the first stand alone GNU/Linux distribution, SLS, Softlanding Linux System (circa 1992).

Jsish (JavaScript Interpreter SHell, Jsi for short) syntax is based on ECMAScript 5.1, but deviates in some key areas:

  • No automatic semicolon insertion.
  • Empty array/object elements are not supported.
  • It is an error to use return inside of a try/catch body.
  • The Error object is not implemented: the argument to catch() is a string.
  • The Date object is not implemented: strftime/strptime are provided to replace the functionality.
  • UTF is not supported.
  • The typeof [] is "array" instead of "object".
  • Function definitions can use type specifiers and default values.


While Jsish can honestly be called a Javascript interpreter, the extensions and differences from standard, form what is, realistically, a different language. For instance:

   nodejs> [1,2] + [2,1]
   "1,22,1"
   
   jsish# [1,2] + [2,1];
   0

Typed parameters for functions also sets Jsi apart from other ECMAScript implementations.

   prompt$ jsish
   Jsish interactive: see 'help [cmd]'
   # function foo (a:number, b:string="ok"):number { return a+1; }
   variable
   
   /* Demonstrate parameterized types */
   # foo('a', 1, 2);
   warn: got 3 args, expected 1-2, calling function foo(a:number, b="ok"):number    (at or near "a")
   warn: type mismatch for argument arg 1 'a': expected "number" but got "string", in call to 'foo' <a>.    (at or near "a")
   warn: type mismatch for argument arg 2 'b': expected "string" but got "number", in call to 'foo' <1>.    (at or near "a")
   warn: type mismatch returned from 'foo': expected "number" but got "string", in call to 'foo' <a1>.    (at or near "a")
   "a1"
   
   # foo(1);
   2
   #

The jsish executable evaluates scripts by interpreter directive or from files given as command line arguments.

Unit testing is built into the interpreter, assisted by Jsi syntax allowing for type specifiers, and with =!EXPECTSTART!=, =!EXPECTEND!= source code markers inside comments (along with =!INPUTSTART/END!= pairs) used for validation during test run capture. Unit test mode is initiated when jsish is invoked with a -u command line option.

For example:

<lang javascript>#!/usr/local/bin/jsish -u %s

var a = { abc: "abc", def: "123" };

puts(a.abc); puts(a.def); puts(JSON.stringify(a));

/* !=EXPECTSTART=! abc 123 { "abc":"abc", "def":"123" } !=EXPECTEND=!

  • /</lang>
Output:
prompt$ jsish sampler.jsi
abc
123
{ "abc":"abc", "def":"123" }

prompt$ jsish -u sampler.jsi
[PASS] sampler.jsi

prompt$ chmod +x sampler.jsi
prompt$ ./sampler.jsi
[PASS] sampler.jsi

The operating system interpreter directive in sampler.jsi includes -u, so testing mode is the default run state for that script.

Embedding in C or C++ applications is by including a single amalgamated C source jsi.c, similar to the SQLite model. The sources are crafted to support compilation by either C or C++, not just extern "C" blocks.

Jsish includes database and websocket modules; SQLite, MySQL, libwebsockets. The interpreter also includes Zlib compressed Virtual File System features; support modules are included in an archive appended to the executable and mounted as '/zvfs/'.

Jsish first appeared in 2015. Jsish was considered feature stable with the December 2017 release of version 2.4. Development is still active at time of writing, version 2.8 released in February 2019.

Subcategories

This category has only the following subcategory.

@

Pages in category "Jsish"

The following 137 pages are in this category, out of 137 total.