Code Monkey home page Code Monkey logo

jslang's Introduction

##Purpose

I began to find a Javascript AOT compiler more than a month ago, I wonder whether there is a Javascript AOT compiler base on V8, since it is really a good Javascript JIT compiler, and then I know about JXCORE.

I decided to wirte a Javascript AOT compiler at the end of August 2014, and a month later I write a rudiment about it--It support part syntax and can compile signal *.js file to *.obj file on windows, and then, the object file can be linked to *.exe by link.exe in Visual Studio. It work well but slowly.

After discussed with my wife when we had dinner yesterday, I decide to release the whole project under Mozilla license, regard to Brendan Eich, the creator of Javascript, the co-founder of Mozilla.

Before upload the whole project, I need to send a mail, because I use some code with modified from anther prject, and I need clean up my code too.

Introduction

=====

jslang is a Javascript AOT compiler base on LLVM(yes, it's named acording to clang). There are about three parts in this project:

  • generate codes
    • use flex and bison to generate lexical and syntax code
    • use clang to generate IR code
  • compile to object files
    • load IR code before compile, parse *.js to AST with the lexer and parser which is generated in part i, and then transcode AST to IR code, now both the generated code and the parsed Javascript file are in IR code mode, transcode IR code to object file like llc(the LLVM Native Code Generator)
  • link object files
    • because the compiler has to use some platform dependent functions, or some third-party libraries, wrap them in buildin types(for example, there are many struct types in pthread, it's a boring job to declare them in IR code, even generate with clang, so you can wrap the functions with buildin types: int double, array, pointer, or simple struct types), and compile them to object files with your host compiler, then link the object file(s) together to a binary file.

Document

=====

Roadmap

=====

  • replace property hashmap to hidden class, I tried but failed, I write a type tree to record all types and all relationship of them, I have no idea to record the real type of each value in compiler "world", they are objects, but I can't find it is a NumberObject or a BooleanObject.

  • split generated IR code to two parts, one for load(almost all types), one for link(almost all functions), to speed up the compiling.

  • remove garbage collector: all memory allocations are bound to object(record and analysis all objects which are alloced in each region, destory them when leave the region, the objects returned to upper region should be marked to the real region, use refrence count if needed)

  • write a new lexer and syntax parser to replace flex and bison generated codes, I modify ecmascript.y base on WebKit/JavaScriptCore/parser/Grammy.y(yes, they drop it later), and write ecmascript.l acording it, They are easy to use, and Grammy.y is very robusty, but they don't have good performance actually, maybe this is the reason for WebKit droped it.

  • implement exception, it should work well on both *NUX and Windows platform.

  • implement closure, record varibles of linear predeceesor for closure, since it's an AOT compiler, I purpose just set the varibles whitch are used in closure only.

  • find and record a suitable Instruction when create a function, to insert variable Alloca Instructions before it if we need create some variables, for example, arguments

  • optimize code for runtime, shorten the time of fibnacci(40) to one second.

  • implement and improve the platform dependent code, porting the project to linux and some platforms else

  • implement cross complie feature for jslang(though jslang just is a front-end of LLVM, but it still has some work to do)

jslang's People

Contributors

eddid 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

jslang's Issues

Platform Support!

PTW32_DLLPORT int PTW32_CDECL pthread_setconcurrency (int);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1089:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_getconcurrency (void);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1094:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_init(pthread_rwlock_t *lock,
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1097:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_destroy(pthread_rwlock_t *lock);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1099:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_tryrdlock(pthread_rwlock_t *);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1101:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_trywrlock(pthread_rwlock_t *);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1103:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_rdlock(pthread_rwlock_t *lock);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1105:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedrdlock(pthread_rwlock_t *lock,
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1108:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_wrlock(pthread_rwlock_t *lock);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1110:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedwrlock(pthread_rwlock_t *lock,
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1113:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_unlock(pthread_rwlock_t *lock);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1115:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_init (pthread_rwlockattr_t * attr);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1117:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1119:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * attr,
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1122:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr,
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1131:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_kill(pthread_t thread, int sig);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1140:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setkind_np(pthread_mutexattr_t * attr,
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1142:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getkind_np(pthread_mutexattr_t * attr,
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1148:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_delay_np (struct timespec * interval);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1149:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_num_processors_np(void);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1155:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_attach_np(void);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1156:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_detach_np(void);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1157:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_attach_np(void);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1158:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_detach_np(void);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1163:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthread_win32_test_features_np(int);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1164:1: warning: empty declaration
 enum ptw32_features {
 ^~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1177:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT void * PTW32_CDECL pthread_timechange_handler_np(void *);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1186:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT HANDLE PTW32_CDECL pthread_getw32threadhandle_np(pthread_t thread);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1204:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthreadCancelableWait (HANDLE waitHandle);
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1205:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT int PTW32_CDECL pthreadCancelableTimedWait (HANDLE waitHandle,
 ^~~~~~~~~~~~~
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:538:27: error: expected declaration specifiers before ‘__declspec’
 #    define PTW32_DLLPORT __declspec (dllexport)
                           ^
/home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.h:1285:1: note: in expansion of macro ‘PTW32_DLLPORT’
 PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void);
 ^~~~~~~~~~~~~
In file included from /home/guest/Gits/Compiler/jslang/third_party/pthreads/pthread.c:40:0:
/home/guest/Gits/Compiler/jslang/third_party/pthreads/implement.h:46:10: fatal error: windows.h: No such file or directory
 #include <windows.h>
          ^~~~~~~~~~~

Not Support Linux?

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.