Giter VIP home page Giter VIP logo

jsc's Introduction

Javascript compiler targeting C++/V8

Building

Requires Node.

$ yarn

Example

$ yarn tsc
$ node build/jsc.js tests/tco.js
$ node bin/index.js
12586269025

Features

  • Functions and function calls
    • Basic tail-call optimization
  • Var, const, let declarations
  • For, do, while statements
  • Basic primitive operations
  • Basic import support
  • Number, string, boolean and null literals
  • Basic value unboxing

Not (yet) supported

  • Prototype functions
  • Nested functions
  • Closures
  • And much, much more!

Code produced

The following:

function fib(n: number, a: number, b: number) {
    if (n == 0) {
        return a;
    }

    if (n == 1) {
        return b;
    }

    return fib(n - 1, b, a + b);
}

Gets compiled to:

void tco_fib(const FunctionCallbackInfo<Value> &args) {
  Isolate *isolate = args.GetIsolate();
  double tco_n = toNumber(args[0]);
  double tco_a = toNumber(args[1]);
  double tco_b = toNumber(args[2]);

tail_recurse_1:

    ;

  bool sym_if_test_58 = (tco_n == 0);
  if (sym_if_test_58) {
    args.GetReturnValue().Set(Number::New(isolate, tco_a));
    return;
  }

  bool sym_if_test_70 = (tco_n == 1);
  if (sym_if_test_70) {
    args.GetReturnValue().Set(Number::New(isolate, tco_b));
    return;
  }

  Local<Value> sym_arg_83 = Number::New(isolate, (tco_n - 1));
  Local<Value> sym_arg_92 = Number::New(isolate, (tco_a + tco_b));
  tco_n = toNumber(sym_arg_83);
  tco_a = tco_b;
  tco_b = toNumber(sym_arg_92);
  goto tail_recurse_1;
}

jsc's People

Contributors

dependabot[bot] avatar eatonphil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsc's Issues

Setup instructions

Hi, thanks for creating this project! Could you please clarify the build instructions for jsc. I have installed both yarn and node and they're on my PATH. However, when I try to run yarn inside the jsc folder, it just gives me the message: ERROR: There are no scenarios; must have at least one. I tried running yarn tsc as well but then it gave me the error: ERROR: No such file or directory 'run'.

Could you let me know the set of commands I need to run to setup the jsc compiler?

dead?

It seems that it is no longer maintained.

Name collision with JavaScriptCore

Hey, cool project! So I thought I'd just give you a heads up if you weren't already aware that jsc is (and has always been extensively used as the name for the compiler/interpreter/assembler in Apple's JavaScriptCore library, which is fairly ubiquitous since it's used in Safari and it is the only JS engine allowed on iOS. I'm not trying to be melodramatic, but in all seriousness, there's an executable distributed with the library (usually at JavaScriptCore.framework/Versions/A/Helpers/jsc which is effectively a drop-in for calling the node executable (or what have you):

Usage: jsc [options] [files] [-- arguments]
  -d         Dumps bytecode (debug builds only)
  -e         Evaluate argument as script code
  -f         Specifies a source file (deprecated)
  -h|--help  Prints this help message
  -i         Enables interactive mode (default if no files are specified)
  -m         Execute as a module
  -s         Installs signal handlers that exit on a crash (Unix platforms only)
  -p <file>  Outputs profiling data to a file
  -x         Output exit code before terminating
  --sample                   Collects and outputs sampling profiler data
  --test262-async            Check that some script calls the print function with the string 'Test262:AsyncTestComplete'
  --strict-file=<file>       Parse the given file as if it were in strict mode (this option may be passed more than once)
  --module-file=<file>       Parse and evaluate the given file as module (this option may be passed more than once)
  --exception=<name>         Check the last script exits with an uncaught exception with the specified name
  --watchdog-exception-ok    Uncaught watchdog exceptions exit with success
  --dumpException            Dump uncaught exception text
  --footprint                Dump memory footprint after done executing
  --options                  Dumps all JSC VM options and exits
  --dumpOptions              Dumps all non-default JSC VM options before continuing
  --<jsc VM option>=<value>  Sets the specified JSC VM option
  --destroy-vm               Destroy VM before exiting
Files with a .mjs extension will always be evaluated as modules.

Additionally, the JavaScriptCore source uses "JSC" as well almost exclusively, like to JSC::JSObject::putDirectIndex(JSC::JSGlobalObject *, unsigned int, JSC::JSValue, unsigned int, JSC::PutDirectIndexMode).

So, just a thought, you may want to rename while still in development if you don't want to clash with Apple down the road.

Cheers,

Geoff

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.