Rat Javascript - small javascript/ecmascript interpreter

RATJS is a small javascript/ecmascript interpreter implemented in C language. You can use it to run your own JavaScript programs, or you can embed it as a script engine into a program you develop.

download

https://gitee.com/gongke1978/ratjs

characteristic

  • Compatible with ECMA262 standard version 14
    • Symbol
    • Generator
    • Promise
    • Async function
    • Arrow function
    • Async module
    • Big integer
    • Typed array
    • Array buffer/Shared array buffer
    • DataView
    • Atomics
    • Map/Set/WeakSet/WeakMap
    • WeakRef/FinalizationRegistry
    • Private identifier
    • Multiply realm
    • Module/Async module
  • Expand
    • Hash bang Comments
    • Native module
    • JSON module
    • File system functions
    • FileState object
    • File object
    • Directory object
  • Completely implemented in C language
  • Low space footprint
  • Rich configuration options

rely

  • icu4c : This library is required when the configuration option is set ENC_CONV=icu
  • gmp : This library is required when the configuration option is set ENABLE_BIG_INT=gmp

Construct

RATJS uses GNU make as the code building tool. The following libraries and corresponding header files need to be installed when building:

  • c-json
  • libyaml : If you need to generate test262 test program, you need this library

Configuration options

Show all configuration options:

$ make help

Build in Linux system

Project configuration.

$ make config

Generate RATJS link library and executable program.

$ make

Install the RATJS connection library and executable program.

$ make install

Clear build intermediate files.

$ make clean

Clear the build directory.

$ make dist-clean

Build on Windows

Building on Windows systems requires the MinGW development environment to be installed.

Project configuration.

$ make ARCH=win config

Generate RATJS link library and executable program.

$ make

Install the RATJS connection library and executable program.

$ make install

Clear build intermediate files.

$ make clean

Clear the build directory.

$ make dist-clean

use

execute javascript

Run the executable program "ratjs" to interpret your javascript script.

Run the "js" script:

$ ratjs -s your_script.js arguments...

"ratjs" will be there and run the script "your_script.js". If the function "main" is defined in the script, the "main" function will be called and "arguments" will be passed in as arguments to the function.

Run the "js" script as an ECMA262 module:

$ ratjs your_module.js arguments

"ratjs" will load, link and execute the module "your_module.js". If the function "main" is defined in the module, the "main" function will be called and "arguments" will be passed in as the function parameters.

Run the parameter string as script source code by calling "eval()":

$ ratjs -e "script_string"

Show all options for the executable "ratjs":

$ ratjs --help

embed program

First, include the header file "ratjs.h" in your program. The javascript script is then loaded and executed by calling the RATJS API.

#include <ratjs.h>

...

RJS_Runtime *rt;
RJS_Value   *source, *script;

rt = rjs_runtime_new();
rjs_realm_load_extension(rt, NULL);

source = rjs_value_stack_push(rt);
script = rjs_value_stack_push(rt);

rjs_string_from_enc_chars(rt, source, "print(\"hello, world!\")", -1, NULL);
rjs_script_from_string(rt, script, source, NULL, RJS_FALSE);
rjs_script_evaluation(rt, script, NULL);

rjs_runtime_free(rt);

Connect your program to the library "libratjs".

$ gcc -o your_program -lratjs -lm your_program_source.c

Run the command "doxygen" to generate RATJS API documentation.

You can refer to the sample program in the "demo" directory to learn how to embed RATJS into your program.

license

RATJS is released under the MIT license .

Fined 200 yuan and more than 1 million yuan confiscated You Yuxi: The importance of high-quality Chinese documents Musk’s hard-core migration of servers TCP congestion control saved the Internet Apache OpenOffice is a de facto “unmaintained” project Google celebrates its 25th anniversary Microsoft open source windows-drivers-rs, use Rust to develop Windows drivers Raspberry Pi 5 will be released at the end of October, priced from $60 macOS Containers: Use Docker to run macOS images on macOS IntelliJ IDEA 2023.3 EAP released
{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/6929349/blog/10114674