Skip to content

Commit

Permalink
merge remote-tracking branch 'rreverser/javascript'
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Thurston committed Jan 28, 2016
2 parents 611d2b9 + 0b72bf4 commit 662617b
Show file tree
Hide file tree
Showing 9 changed files with 563 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ EXTRA_DIST = \
rlhc-ocaml.lm \
rlhc-crack.lm \
rlhc-julia.lm \
rlhc-js.lm \
ragel-c.lm \
ragel-crack.lm \
ragel-ruby.lm \
Expand Down Expand Up @@ -103,7 +104,8 @@ RLHC = \
rlhc-rust.lm \
rlhc-ocaml.lm \
rlhc-crack.lm \
rlhc-julia.lm
rlhc-julia.lm \
rlhc-js.lm

rlhc.c: rlhc.lm $(RLHC) $(COLM_BINDEP)
$(COLM) -c -b rlhc_object -o $@ $<
Expand Down
22 changes: 22 additions & 0 deletions src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ HostType hostTypesJulia[] =
{ "u8", 0, "byte", true, true, false, 0, UCHAR_MAX, 4 },
};

HostType hostTypesJS[] =
{
{ "s8", 0, "int8", true, true, false, CHAR_MIN, CHAR_MAX, 1 },
{ "u8", 0, "uint8", false, true, false, 0, UCHAR_MAX, 1 },
{ "s16", 0, "int16", true, true, false, SHRT_MIN, SHRT_MAX, 2 },
{ "u16", 0, "uint16", false, true, false, 0, USHRT_MAX, 2 },
{ "i32", 0, "int32", true, true, false, INT_MIN, INT_MAX, 4 },
{ "u32", 0, "uint32", false, true, false, 0, UINT_MAX, 4 },
{ "number", 0, "number", true, true, false, LONG_MIN, LONG_MAX, 8 },
};

const HostLang hostLangC = {
"C",
Expand Down Expand Up @@ -239,6 +249,17 @@ const HostLang hostLangJulia = {
"julia"
};

const HostLang hostLangJS = {
"JavaScript",
"-P",
HostLang::JS,
hostTypesJS, 7,
hostTypesJS+1,
false,
true,
"js"
};

const HostLang *hostLangs[] = {
&hostLangC,
&hostLangAsm,
Expand All @@ -251,6 +272,7 @@ const HostLang *hostLangs[] = {
&hostLangRust,
&hostLangCrack,
&hostLangJulia,
&hostLangJS,
};


Expand Down
4 changes: 3 additions & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ struct HostLang
Crack,
Asm,
Rust,
Julia
Julia,
JS
};

const char *name;
Expand All @@ -236,6 +237,7 @@ extern const HostLang hostLangCrack;
extern const HostLang hostLangAsm;
extern const HostLang hostLangRust;
extern const HostLang hostLangJulia;
extern const HostLang hostLangJS;

extern const HostLang *hostLangs[];
extern const int numHostLangs;
Expand Down
11 changes: 11 additions & 0 deletions src/inputdata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ void InputData::juliaDefaultFileName( const char *inputFile )
outputFileName = fileNameFromStem( inputFile, ".jl" );
}

void InputData::jsDefaultFileName( const char *inputFile )
{
/* If the output format is code and no output file name is given, then
* make a default. */
if ( outputFileName == 0 )
outputFileName = fileNameFromStem( inputFile, ".js" );
}

void InputData::makeDefaultFileName()
{
switch ( hostLang->lang ) {
Expand Down Expand Up @@ -172,6 +180,9 @@ void InputData::makeDefaultFileName()
case HostLang::Julia:
juliaDefaultFileName( inputFileName );
break;
case HostLang::JS:
jsDefaultFileName( inputFileName );
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/inputdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ struct InputData
void asmDefaultFileName( const char *inputFile );
void rustDefaultFileName( const char *inputFile );
void juliaDefaultFileName( const char *inputFile );
void jsDefaultFileName( const char *inputFile );

void writeOutput( InputItem *ii );
void writeLanguage( std::ostream &out );
Expand Down
7 changes: 6 additions & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ void usage()
" -T0 code style supported\n"
" -K The host language is Crack\n"
" -T0 code style supported\n"
" -P The host language is JavaScript\n"
" -T0 code style supported\n"
"line directives:\n"
" -L Inhibit writing of #line directives\n"
"code style:\n"
Expand Down Expand Up @@ -244,7 +246,7 @@ void escapeLineDirectivePath( std::ostream &out, char *path )

void InputData::parseArgs( int argc, const char **argv )
{
ParamCheck pc( "xo:dnmleabjkS:M:I:CDEJZRAOKUYvHh?-:sT:F:G:LpV", argc, argv );
ParamCheck pc( "xo:dnmleabjkS:M:I:CDEJZRAOKUYPvHh?-:sT:F:G:LpV", argc, argv );

/* Decide if we were invoked using a path variable, or with an explicit path. */
const char *lastSlash = strrchr( argv[0], '/' );
Expand Down Expand Up @@ -385,6 +387,9 @@ void InputData::parseArgs( int argc, const char **argv )
case 'Y':
hostLang = &hostLangJulia;
break;
case 'P':
hostLang = &hostLangJS;
break;

/* Version and help. */
case 'v':
Expand Down
Loading

0 comments on commit 662617b

Please sign in to comment.