GithubHelp home page GithubHelp logo

uros-stegic / jawe Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 0.0 2.69 MB

Javascript compiler that outputs LLVM IR for WebAssembly target

License: GNU General Public License v3.0

CMake 1.07% Shell 0.10% Lex 2.87% C++ 85.34% JavaScript 10.00% Makefile 0.57% C 0.05%

jawe's Introduction

jawe compiler

jawe compiles Javascript into Web Assembly. It's primary goal is to compile Javascript to LLVM, from which it can be then compiled into Web Assembly via various toolchains.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for developmet and testing purposes. This project is still in it's early phase and if you notice any bugs or strange behaviour, please submit an issue.

Prerequisites

In order to successfuly compile jawe, you'll need to install the following:

  • gcc - GNU compiler for C/C++ (tested on gcc 7.2)
  • make - build system from GNU (tested on: 4.2.1)
  • cmake - cross-platform build system (min: 3.7.2)
  • boost - set of C++ libraries (tested on: 1.65.1-1)
  • flex - lexical analyzer generator (min: 2.5.35)
  • bison - general-purpose parser generator from GNU (min: 2.4.1)

Compiling

After ensuring that all of the dependencies are met, you need to clone this repository. After you fetched the code, position your self into this folder and run these commands

mkdir build
cd build
cmake ..
make

Alternatively, you can run only make command from the project root and it will automatically create build folder and run cmake from within that folder. After that it'll run make and run jawe with one of the javascript files from tests folder.

Usage

Since this is still a premature stage of development, no real output is provided. Only two thigs can be done at this point:

  • print parsed file to the standard output
  • print AST to the standard output
[uros: build> jawe --help
Usage: jawe [OPTION]... --input-file program.js:
  -h [ --help ]              prints this help message
  -v [ --version ]           prints version info
  --verbose                  prints verbose parsing information
  --dump-ast                 prints parsed abstract syntax tree
  --print                    prints input program back to the output
  --memory					 shows memory address of each node and its parent node
  --input-file arg           input filename
  --output-file arg (=a.out) output filename

Only --input-file followed by path to Javascript file is required. If --dump-ast flag is present, jawe will print abstract syntax tree. It is also possible to print detailed output from bison parser by including --verbose flag. For debugging purposes, it's possible to print out memory address for each node in AST with flag --memory.

Example:

// file: test.js
let b = 10;
const y = [b, 11, 12];
var z = b += 1;
[uros: build> jawe --input-file test.js --dump-ast
command-block
    Declaration [let]
        operator [=]
            Variable [b]
            Number [10]
    Declaration [const]
        operator [=]
            Variable [y]
            Array(3)
                Variable [b]
                Number [11]
                Number [12]
    Declaration [var]
        operator [=]
            Variable [z]
            operator [+=]
                Variable [b]
                Number [1]

Last words

Like i said earlier, this project is still in it's early phase so any comments, suggestions and bug reports are more than welcome. If you have any questions feel free to contact me.

Good luck coding! :)

Authors

License

This project is licensed under the GNU GPL-3 License - see the LICENSE file for details

jawe's People

Contributors

uros-stegic avatar branislavazivkovic13 avatar

Stargazers

John Lindal avatar ratijas avatar  avatar Stevan avatar

Watchers

James Cloos avatar  avatar  avatar Stevan avatar

jawe's Issues

rewire hoisting

Finish hoisting:

  1. Descend into arrays and objects
  2. Order function after variables
  3. Fix ordering

KeyVal --dump-ast

Incorrect tabulation in printing object's key-val pairs. (see tests/semantics/empty.js)

pretty print

Print code with indentation when --print is present.

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.