RPA Toolkit
Added RJS to the project. Reduced the size of the rparecord_t.
authorMartin Stoilov <martin@rpasearch.com>
Mon, 25 Apr 2011 05:49:10 +0000 (22:49 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Mon, 25 Apr 2011 05:49:10 +0000 (22:49 -0700)
18 files changed:
build/linux/build.mk
rgrep/rpagrep.c
rjs/build/linux/rjs.mk [new file with mode: 0644]
rjs/build/linux/x86_64/Makefile [new file with mode: 0644]
rjs/ecma262.rpa [new file with mode: 0644]
rjs/linux/rjsrules.c [new file with mode: 0644]
rjs/linux/rjsrules.h [new file with mode: 0644]
rjs/rjs.c [new file with mode: 0644]
rjs/rjs.h [new file with mode: 0644]
rjs/rjsexec.c [new file with mode: 0644]
rjs/rjsparser.c [new file with mode: 0644]
rjs/rjsparser.h [new file with mode: 0644]
rpa2/rpadbex.c
rpa2/rparecord.h
rpa2/rpastat.c
rpa2/rpastat.h
rpa2/rpavm.c
testrpa2/rpacompiler-rulerec.c

index cf3c05d..05dd358 100644 (file)
@@ -4,6 +4,7 @@ all:
        +make -C $(SRCDIR)/rpa1/build/$(OS)/$(ARCHDIR) all
        +make -C $(SRCDIR)/rpa2/build/$(OS)/$(ARCHDIR) all
        +make -C $(SRCDIR)/rvm/build/$(OS)/$(ARCHDIR) all
+       +make -C $(SRCDIR)/rjs/build/$(OS)/$(ARCHDIR) all
        +make -C $(SRCDIR)/tests/build/$(OS)/$(ARCHDIR) all
        +make -C $(SRCDIR)/testrpa2/build/$(OS)/$(ARCHDIR) all
        +make -C $(SRCDIR)/rgrep/build/$(OS)/$(ARCHDIR) all
@@ -14,6 +15,7 @@ distclean: clean
        +make -C $(SRCDIR)/rpa1/build/$(OS)/$(ARCHDIR) distclean
        +make -C $(SRCDIR)/rpa2/build/$(OS)/$(ARCHDIR) distclean
        +make -C $(SRCDIR)/rvm/build/$(OS)/$(ARCHDIR) distclean
+       +make -C $(SRCDIR)/rjs/build/$(OS)/$(ARCHDIR) distclean
        +make -C $(SRCDIR)/tests/build/$(OS)/$(ARCHDIR) distclean
        +make -C $(SRCDIR)/testrpa2/build/$(OS)/$(ARCHDIR) distclean
        +make -C $(SRCDIR)/rgrep/build/$(OS)/$(ARCHDIR) distclean
@@ -24,6 +26,7 @@ clean:
        +make -C $(SRCDIR)/rpa1/build/$(OS)/$(ARCHDIR) clean
        +make -C $(SRCDIR)/rpa2/build/$(OS)/$(ARCHDIR) clean
        +make -C $(SRCDIR)/rvm/build/$(OS)/$(ARCHDIR) clean
+       +make -C $(SRCDIR)/rjs/build/$(OS)/$(ARCHDIR) clean
        +make -C $(SRCDIR)/tests/build/$(OS)/$(ARCHDIR) clean
        +make -C $(SRCDIR)/testrpa2/build/$(OS)/$(ARCHDIR) clean
        +make -C $(SRCDIR)/rgrep/build/$(OS)/$(ARCHDIR) clean
index 93ee6dc..f8cbd46 100644 (file)
@@ -215,7 +215,7 @@ int rpa_grep_parse(rpa_grep_t *pGrep, const char* buffer, unsigned long size)
        rlong i;
        rchar location[128];
        rpastat_t *hStat;
-       rarray_t *records;
+       rarray_t *records = NULL;
        rparecord_t *prec;
        const char *input = buffer, *start = buffer, *end = buffer + size;
 
@@ -224,7 +224,7 @@ int rpa_grep_parse(rpa_grep_t *pGrep, const char* buffer, unsigned long size)
                return -1;
        rpa_stat_encodingset(hStat, pGrep->encoding);
        hStat->debug = pGrep->execdebug;
-       records = rpa_stat_parse(hStat, pGrep->hPattern, input, start, end);
+       rpa_stat_parse(hStat, pGrep->hPattern, input, start, end, &records);
        if (records) {
                if (pGrep->greptype == RPA_GREPTYPE_PARSE) {
                        for (i = 0; i < r_array_length(records); i++) {
diff --git a/rjs/build/linux/rjs.mk b/rjs/build/linux/rjs.mk
new file mode 100644 (file)
index 0000000..b04b0b4
--- /dev/null
@@ -0,0 +1,64 @@
+RLIB_SRCDIR = $(SRCDIR)/rlib
+RVM_SRCDIR = $(SRCDIR)/rvm
+RPA_SRCDIR = $(SRCDIR)/rpa2
+RJS_SRCDIR = $(SRCDIR)/rjs
+RJS_LIB = $(OUTDIR)/librjs.a
+RJS_SO = $(OUTDIR)/librjs.so.1.0
+RJS_EXEC = $(OUTDIR)/rjsexec
+
+CFLAGS += -I$(RVM_SRCDIR)/config -I$(SRCDIR)/rlib -I$(RVM_SRCDIR) -I$(RPA_SRCDIR) -I$(RJS_SRCDIR) -I$(RJS_SRCDIR)/linux
+
+LIBS = -L$(RLIB_SRCDIR)/build/$(OS)/$(ARCHDIR)/out 
+LIBS += -L$(RVM_SRCDIR)/build/$(OS)/$(ARCHDIR)/out 
+LIBS += -L$(RPA_SRCDIR)/build/$(OS)/$(ARCHDIR)/out 
+LIBS += -L$(RJS_SRCDIR)/build/$(OS)/$(ARCHDIR)/out 
+LIBS += -lrjs -lrpa2 -lrvm -lrlib -lpthread -lm --static
+
+RJS_OBJECTS =  \
+       $(OUTDIR)/rjs.o \
+       $(OUTDIR)/rjsparser.o \
+       $(OUTDIR)/rjsrules.o \
+       $(OUTDIR)/ecma262.o \
+
+
+RJSEXEC_OBJECTS =      \
+       $(OUTDIR)/rjsexec.o \
+
+ifeq ($(OS), linux)
+all: $(OUTDIR) $(RJS_LIB) $(RJS_EXEC) $(RJS_SO)
+else
+all: $(OUTDIR) $(RJS_LIB)
+endif
+
+$(RJS_EXEC) : $(RJSEXEC_OBJECTS)
+       $(CC) $(ARCH) -o $@ $^ $(LIBS)
+
+$(OUTDIR)/%.o: $(RJS_SRCDIR)/%.c
+       $(CC) $(CFLAGS) -o $(OUTDIR)/$*.o -c $(RJS_SRCDIR)/$*.c
+
+$(OUTDIR)/%.o: $(RJS_SRCDIR)/linux/%.c
+       $(CC) $(CFLAGS) -o $(OUTDIR)/$*.o -c $(RJS_SRCDIR)/linux/$*.c
+
+$(RJS_LIB): $(RJS_OBJECTS)
+       $(AR) -cr $@ $^
+
+$(RJS_SO): $(RJS_OBJECTS)
+       $(CC) $(LDFLAGS) -shared -Wl,-soname,librjs.so -o $@ $^
+
+$(OUTDIR)/%.o: $(RJS_SRCDIR)/%.rpa
+       $(LD) -r -b binary -o $(OUTDIR)/$*.o $(RJS_SRCDIR)/$*.rpa
+
+$(OUTDIR):
+       @mkdir $(OUTDIR)
+
+distclean: clean
+       @rm -f .depend
+       @rm -rf $(OUTDIR)
+
+clean:
+       @rm -f $(RJS_LIB)
+       @rm -f $(RJS_SO)
+       @rm -f $(RJS_OBJECTS)
+       @rm -f *~
+       @rm -f $(SRCDIR)/*~
+
diff --git a/rjs/build/linux/x86_64/Makefile b/rjs/build/linux/x86_64/Makefile
new file mode 100644 (file)
index 0000000..91ff4e9
--- /dev/null
@@ -0,0 +1,25 @@
+SRCDIR = ../../../..
+ARCHDIR = $(shell basename $(shell pwd))
+OUTDIR = out
+OS = $(shell uname | tr "[:upper:]" "[:lower:]")
+INCLUDE = -I$(SRCDIR)/arch/$(OS)/$(ARCHDIR)
+
+CC = gcc
+AR = ar
+LD = ld
+
+ifeq ($(BLDCFG), release)
+CFLAGS := -fPIC -O3
+else
+CFLAGS := -fPIC -O0 -g -Wall 
+endif
+
+ifeq ($(CCBLD), yes)
+CFLAGS += -fprofile-arcs -ftest-coverage
+endif
+
+CFLAGS += $(MACH) $(INCLUDE)
+LDFLAGS := $(MACH)
+
+
+include ../rjs.mk
diff --git a/rjs/ecma262.rpa b/rjs/ecma262.rpa
new file mode 100644 (file)
index 0000000..a57efb8
--- /dev/null
@@ -0,0 +1,466 @@
+#!emitall
+#!emitnone
+#!emit BitwiseANDOp
+#!emit BitwiseXOROp
+#!emit BitwiseOROp
+#!emit AdditiveExpressionOp
+
+#!emit MultiplicativeExpressionOp
+#!emit ShiftExpressionOp
+#!emit EqualityExpressionOp
+#!emit RelationalExpressionOp
+#!emit LogicalOROp
+#!emit LogicalANDOp
+
+#!emit AssignmentOperator
+#!emit EqualityOperator
+#!emit RelationalOperator
+#!emit AdditiveOperator
+#!emit MultiplicativeOperator
+#!emit ShiftOperator
+#!emit BitwiseANDOperator
+#!emit BitwiseXOROperator
+#!emit BitwiseOROperator
+#!emit LogicalANDOperator
+#!emit LogicalOROperator
+#!emit LogicalNotOperator
+#!emit BitwiseNotOperator
+#!emit UnaryOperatorOpcode
+#!emit PrintOp
+
+
+#!emit PostfixOperator
+#!emit PostfixExpressionOp
+#!emit PrefixExpressionOp
+
+
+#!emit UnaryExpressionOp
+#!emit LogicalNotExpressionOp
+#!emit BitwiseNotExpressionOp
+
+#!emit DecimalIntegerLiteral
+#!emit DecimalNonIntegerLiteral
+#!emit BlockBegin
+#!emit BlockEnd
+
+#!emit DoKeyword
+#!emit IterationDo
+
+#!emit sqstring
+#!emit dqstring
+#!emit DoubleStringCharacters
+#!emit SingleStringCharacters
+#!emit Program
+#!emit Initialiser
+#!emit AssignmentExpressionOp
+
+#!emit VariableAllocate
+#!emit VariableAllocateAndInit
+
+#!emit ReturnOp
+
+#!emit SwiId
+#!emit SwiIdExist
+
+#!emit PostfixExpressionValOp
+#!emit LeftHandSideExpressionPush
+
+
+
+# 6 Source Text
+SourceCharacter                        ::= .
+
+# 7.2 White space
+WhiteSpace                             ::= [#0x0009] | [#0x000B] | [#0x000C] | [#0x0020] | [#0x00A0] | [#0xFEFF]
+
+# 7.3 Line Terminators
+LineTerminator                 ::= [#0x000D] [#0x000A] | ([#0x000A] | [#0x000D] | [#0x2028] | [#0x2029])
+LineTerminatorSequence ::= [#0x000D] [#0x000A] | [#0x000A] | [#0x000D] | [#0x2028] | [#0x2029]
+S                                              ::= ( <WhiteSpace> | <LineTerminator> )+
+SC                                             ::= <S>? ';' <S>?
+COMMA                                  ::= <S>? ',' <S>?
+EQ                                             ::= <S>? '=' <S>?
+
+# 7.4 Comments
+Comment                                        ::= <:MultiLineComment:> | <:SingleLineComment:>
+MultiLineComment               ::= '/*' <:MultiLineCommentChar:>* '*/'
+MultiLineCommentChar   ::= . - '*/'
+SingleLineComment              ::= '#' <:SingleLineCommentChar:>*
+SingleLineCommentChar  ::= <SourceCharacter> - <LineTerminator>
+
+# 7.5 Tokens
+Token                                  ::= <:IdentifierName:> |
+                                               <:NumericLiteral:> |
+                                               <:StringLiteral:>
+
+# 7.6 Identifier Names and Identifiers
+
+Identifier                             ::= <IdentifierName> - <ReservedWord> - <ReservedWord> <IdentifierPart>
+IdentifierName                 ::= <IdentifierStart> <IdentifierPart>*
+IdentifierStart                ::= <UnicodeLetter> | '$' | '_' | '\' <:UnicodeLetter:>
+UnicodeLetter                  ::= [#0x0041-#0x005A] | [#0x00C0-#0x00DE] | [#0x0100-#0x0232] | [#0x0061-#0x007A] | [#0x00C0-#0x00DE]       # <Lu> | <Ll>
+
+Lu                                             ::= [#0x0041-#0x005A] | [#0x00C0-#0x00DE] | [#0x0100-#0x0232]   # TBD
+Ll                                             ::= [#0x0061-#0x007A] | [#0x00C0-#0x00DE]                                               # TBD
+IdentifierPart                 ::= <IdentifierStart> | 
+                                               <:UnicodeDigit:> 
+UnicodeDigit                   ::= [0-9] | [#0x0660-#0x0669]                                   # TBD
+
+ReservedWord                   ::= <:Keyword:>
+                                                       <:FutureReservedWord:> |
+                                                       <:NullLiteral:> |
+                                                       <:BooleanLiteral:>
+
+Keyword                                        ::= 'instanceof' | 'typeof'     | 'break' |
+                                               'do' | 'new' | 'var' |
+                                               'case' | 'else' | 'return' | 'void' | 
+                                               'catch' | 'finally' | 'continue' | 'for' | 
+                                               'switch' | 'while' | 'this' | 'with' | 
+                                               'debugger' | 'function' | 'throw' | 'default' |  
+                                               'if' | 'try' | 'delete' | 'in'
+
+FutureReservedWord                     ::= 'class' | 'enum' | 'extends' | 'import' | 'const' | 'export' |
+                                                       'implements' | 'let' | 'private' | 'public' |
+                               'static' | 'interface' | 'package' | 'protected'
+
+NullLiteral                                    ::= 'null'
+BooleanLiteral                                 ::= 'true' | 'false'
+Literal                                        ::= <:NullLiteral:> |
+                                                       <:BooleanLiteral:> |
+                                                       <:NumericLiteral:> |
+                                                       <:StringLiteral:>
+                                                       
+LiteralOp                                      ::= <:Literal:>
+
+# 7.8.3 Numeric Literals
+
+NumericLiteral                                 ::= <:HexIntegerLiteral:> | <:DecimalNonIntegerLiteral:> | <:DecimalIntegerLiteral:>
+DecimalNonIntegerLiteral               ::= ('0' | <:NonZeroDigit:> <DecimalDigits>?) '.' <DecimalDigits>? <:ExponentPart:>? |
+                                                               '.' <:DecimalDigits:> <:ExponentPart:>? 
+DecimalIntegerLiteral                  ::= '0' | <:NonZeroDigit:> <:DecimalDigits:>? <:ExponentPart:>?
+DecimalDigits                                  ::= <:DecimalDigit:>+
+DecimalDigit                                   ::= [0-9]
+NonZeroDigit                                   ::= [1-9]
+ExponentPart                                   ::= <:ExponentIndicator:> <:SignedInteger:>
+ExponentIndicator                              ::= [eE]
+SignedInteger                                  ::= '-' <:DecimalDigits:> |
+                                                               '+' <:DecimalDigits:> |
+                                                               <:DecimalDigits:>
+HexIntegerLiteral                              ::= '0' [xX] <:HexDigit:>+
+HexDigit                                               ::= [0-9a-fA-F]
+
+# 7.8.4 String Literals
+StringLiteral                                  ::= '"' <:DoubleStringCharacters:>? '"' |
+                                                               "'" <:SingleStringCharacters:>? "'"
+
+DoubleStringCharacters                 ::= <DoubleStringCharacter>+
+SingleStringCharacters                 ::= <SingleStringCharacter>+
+
+DoubleStringCharacter                  ::= <:SourceCharacter:> - ('"' | '\\' | <:LineTerminator:>)
+
+SingleStringCharacter                  ::= <:SourceCharacter:> - ("'" | '\\' | <:LineTerminator:>)
+
+BracketExpressionOp                            ::= '(' <S>? <:Expression:> <S>? ')'
+ThisOp                                                 ::= 'this'
+
+PrimaryExpression                              ::= <:ThisOp:> | 
+                                                               '(' <S>? <:Expression:> <S>? ')' |
+                                                               <:LiteralOp:> |
+                                                               (<:SwiId:>) |
+                                                               <:IdentifierOp:>
+
+# The next line is mine
+IdentifierOp                                   ::= <:Identifier:> 
+SwiId                                                  ::= <:Identifier:> 
+SwiIdExist                                             ::= <SwiId> 
+
+
+ArrayLiteral                                   ::= '[' <S>? <:Elision:>? <S>? ']' |
+                                                               '[' <S>? <:ElementList:> <S>? ']' |
+                                                               '[' <S>? <:ElementList:> <S>? ',' <S>? <:Elision:> <S>? ']'
+ElementList                                            ::= <:Elision:>? <S>? <:AssignmentExpression:> (<S>? ',' <S>? <:Elision:>? <S>? <:AssignmentExpression:> )*
+Elision                                                        ::= ',' <S>? <:Elision:> | <S>? ','
+
+
+# 11.2 Left-Hand-Side Expressions
+NewKeyword                                             ::= 'new' - 'new' <IdentifierPart>
+LSB                                                            ::= <S>? '[' <S>?
+RSB                                                            ::= <S>? ']' <S>?
+dot                                                            ::= '.'
+MemberIdentifierNameOp                 ::= <:Identifier:>
+MemberIdentifierNameLookupOp   ::= <:Identifier:>
+MemberExpressionBaseOp                 ::= <:MemberExpression:>
+MemberExpressionIndexOp                        ::= <:MemberExpressionBaseOp:>  <:LSB:> <:Expression:> <:RSB:>
+MemberExpressionNameOp                 ::= <:MemberExpressionBaseOp:> <:dot:> <:MemberIdentifierNameOp:>
+MemberExpressionNewOp                  ::= <:NewKeyword:> <S>? <:CallExpression:>
+
+MemberExpression                               ::= <:MemberExpressionIndexOp:>  |
+                                                                       <:MemberExpressionNameOp:> |
+                                                                       <:FunctionExpression:> |
+                                                                       <:PrimaryExpression:>
+
+NewExpressionCallName                  ::= <:MemberExpression:>
+NewExpressionCallOp                            ::= <:NewKeyword:> <S>? <:NewExpressionCallName:> <S>? <:ArgumentsOp:>?
+NewArrayExpressionOp                   ::= <S>? 'new' <S> ( 'Array' | 'Object') <S>? <ArgumentsOp>?
+
+NewExpression                                  ::= <:NewArrayExpressionOp:> |
+                                                                       <:NewExpressionCallOp:> |
+                                                                       <:MemberExpression:>
+
+FunctionCallName                               ::= <:CallExpression:> | <:MemberExpression:>
+CallExpressionOp                               ::= <:FunctionCallName:> <S>? <:ArgumentsOp:>
+CallExpressionBaseOp                   ::= <:CallExpression:>
+CallExpressionIndexOp                  ::= <:CallExpressionBaseOp:> <S>? '[' <S>? <:Expression:> <S>? ']'
+CallExpressionNameOp                   ::= <:CallExpressionBaseOp:> '.' <:MemberIdentifierNameOp:>
+
+CallExpression                                 ::= <:CallExpressionIndexOp:> |
+                                                                       <:CallExpressionNameOp:> |
+                                                                       <:CallExpressionOp:>
+
+ArgumentsOp                                            ::= '(' <S>? ')' |
+                                                               '(' <S>? <:ArgumentList:> <S>? ')'
+ArgumentList                                   ::= <:ArgumentList:> <S>? ',' <S>? <:AssignmentExpression:> |
+                                                                       <:AssignmentExpression:>
+
+ArgumentList                                   ::= <:ArgumentList:> <S>? ',' <S>? <:FunctionCallParameter:> |
+                                                                       <:FunctionCallParameter:>
+FunctionCallParameter                  ::= <:AssignmentExpression:>
+                                                                       
+ValLeftHandSideExpression              ::= <:CallExpression:> | <:NewExpression:>
+AddressLeftHandSideExpression  ::= <:ValLeftHandSideExpression:>
+LeftHandSideExpression                 ::= <:AddressLeftHandSideExpression:>
+
+
+# 11.3 Postfix Expressions
+# RULE: LeftHandSideExpression always ends up in R0 (Let see if this would work)
+PostfixOperator                                ::= '++' | '--'
+PostfixExpressionOp                    ::= <:LeftHandSideExpression:> <:PostfixOperator:>
+PostfixExpressionValOp                 ::= <:ValLeftHandSideExpression:>
+PostfixExpression                              ::= <:PostfixExpressionOp:> |
+                                                                       <:PostfixExpressionValOp:> 
+
+PrefixOperator                                         ::= <:PostfixOperator:>
+PrefixExpressionOp                             ::= <:PrefixOperator:> <:LeftHandSideExpression:>
+PrefixExpression                               ::= <:PrefixExpressionOp:>
+
+# 11.4 Unary Operators
+UnaryOperatorOpcode                            ::= '~' | '!' | ('+' - '++') | ('-' - '--') | 'delete' | 'void' | 'typeof'
+UnaryOperator                          ::= <:UnaryOperatorOpcode:>
+UnaryExpressionOp                      ::=     <S>? <:UnaryOperator:> <S>? <:UnaryExpression:>
+UnaryExpression                                ::=     <:UnaryExpressionOp:> | <:PrefixExpression:> | <:PostfixExpression:>
+
+
+# 11.5 Multiplicative Operators
+MultiplicativeOperator                         ::= '*' | '/' | '%'
+MultiplicativeExpressionOp             ::= <:MultiplicativeExpression:> <S>? <:MultiplicativeOperator:> <S>? <:UnaryExpression:>
+MultiplicativeExpression               ::= <:MultiplicativeExpressionOp:> | 
+                                                                       <:UnaryExpression:>
+
+# 11.6 Additive Operators
+AdditiveOperator                               ::= '+' | '-'
+AdditiveExpressionOp                   ::= <:AdditiveExpression:> <S>? <:AdditiveOperator:> <S>? <:MultiplicativeExpression:>
+AdditiveExpression                             ::= <:AdditiveExpressionOp:> | 
+                                                                       <:MultiplicativeExpression:>
+
+
+11.7 Bitwise Shift Operators
+ShiftOperator                                  ::= '>>>' | '<<' | '>>'
+ShiftExpressionOp                              ::= <:ShiftExpression:> <S>? <:ShiftOperator:> <S>? <:AdditiveExpression:>
+ShiftExpression                                        ::= <:ShiftExpressionOp:> |
+                                                               <:AdditiveExpression:> 
+
+
+# 11.8 Relational Operators
+RelationalOperator                             ::= '<=' | '>=' | '<' | '>' | 'instanceof'
+RelationalExpressionOp                 ::= <:RelationalExpression:> <S>? <:RelationalOperator:> <S>? <:ShiftExpression:>
+RelationalExpression                   ::= <:RelationalExpressionOp:> |
+                                                               <:ShiftExpression:>
+
+# 11.9 Equality Operators
+EqualityOperator                               ::= '===' | '==' | '!==' | '!='
+EqualityExpressionOp                   ::= <:EqualityExpression:> <S>? <:EqualityOperator:> <S>? <:RelationalExpression:> 
+EqualityExpression                             ::= <:EqualityExpressionOp:> |
+                                                               <:RelationalExpression:>
+
+BitwiseANDOperator                             ::= '&' - '&&'
+BitwiseANDOp                                   ::= <:BitwiseANDExpression:> <S>? <:BitwiseANDOperator:> <S>? <:EqualityExpression:>
+BitwiseANDExpression                   ::= <:BitwiseANDOp:> |
+                                                               <:EqualityExpression:>
+
+BitwiseXOROperator                             ::= '^'
+BitwiseXOROp                                   ::= <:BitwiseXORExpression:> <S>? <:BitwiseXOROperator:> <S>? <:BitwiseANDExpression:>
+BitwiseXORExpression                   ::= <:BitwiseXOROp:> |
+                                                               <:BitwiseANDExpression:>
+
+BitwiseOROperator                              ::= '|' - '||'
+BitwiseOROp                                            ::= <:BitwiseORExpression:> <S>? <:BitwiseOROperator:> <S>? <:BitwiseXORExpression:>
+BitwiseORExpression                    ::= <:BitwiseOROp:> |
+                                                               <:BitwiseXORExpression:>
+
+# 11.11 Binary Logical Operators
+LogicalANDOperator                             ::= '&&'
+LogicalANDOp                                   ::= <:LogicalANDExpression:> <S>? <:LogicalANDOperator:>  <S>? <:BitwiseORExpression:>
+LogicalANDExpression                   ::= <:LogicalANDOp:> |
+                                                               <:BitwiseORExpression:>
+
+LogicalOROperator                              ::= '||'
+LogicalOROp                                            ::= <:LogicalORExpression:> <S>? <:LogicalOROperator:> <S>? <:LogicalANDExpression:>
+LogicalORExpression                    ::= <:LogicalOROp:> |
+                                                               <:LogicalANDExpression:>
+
+
+# 11.12 Conditional Operator ( ? : )
+AssignmentExpressionIfTrueOp           ::= <:AssignmentExpression:>
+AssignmentExpressionIfFalseOp          ::= <:AssignmentExpression:>
+QuestionMarkOp                                         ::= '?'
+ConditionalExpression                          ::= <:LogicalORExpression:> (<S>? <:QuestionMarkOp:> <S>? <:AssignmentExpressionIfTrueOp:> <S>? ':' <S>? <:AssignmentExpressionIfFalseOp:>)?
+
+# 11.13 Assignment Operators
+LeftHandSideExpressionPush             ::= <:LeftHandSideExpression:>
+IdentifierAddressPush                  ::= <:Identifier:>
+AssignmentExpressionOp                         ::= <:LeftHandSideExpressionPush:> <S>? <:AssignmentOperator:> <S>? <:AssignmentExpression:>
+AssignmentExpression                   ::= <:AssignmentExpressionOp:> | 
+                                                                       <:ConditionalExpression:>
+
+AssignmentExpressionNoIn               ::= <:LeftHandSideExpression:> <S>? <:AssignmentOperator:> <S>? <:AssignmentExpressionNoIn:>
+AssignmentOperator                             ::= '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '>>>=' | '&=' | '^=' | '|='
+
+
+# 11.14 Comma Operator         ( , )
+Expression                                     ::= <:AssignmentExpression:> ( <S>? ',' <S>? <:AssignmentExpression:> )*
+ExpressionNoIn                                 ::= <:AssignmentExpressionNoIn:> ( <S>? ',' <S>? <:AssignmentExpressionNoIn:> )*
+
+
+# 12 Statements
+Statement                                              ::= <:FunctionDefinitionStatement:> |
+                                                                       <:BreakStatement:> |
+                                                                       <:ContinueStatement:> |
+                                                                       <:Block:> |
+                                                               <:Comment:> |
+                                                               <:VariableStatement:> |
+                                                               <:EmptyStatement:> |
+                                                               <:ExpressionStatement:> |
+                                                               <:IfStatement:> |
+                                                               <:IterationStatement:> |
+                                                               <:ContinueStatement:> |
+                                                               <:BreakStatement:> |
+                                                               <:ReturnStatement:> |
+                                                               <:WithStatement:> |
+                                                               <:SwitchStatementOp:>
+
+# 12.1 Block
+BlockBegin                                                     ::= <S>? '{' <S>?
+BlockEnd                                                       ::= <S>? '}' <S>?
+Block                                                          ::= <:BlockBegin:> <:StatementList:>? <:BlockEnd:>
+StatementList                                          ::= (<S>? <:Statement:>)+
+
+# 12.2 Variable Statement
+VariableStatement                                      ::= 'var' <S>? <:VariableDeclarationList:> <:SC:>
+VariableDeclarationList                        ::= <:VariableDeclaration:> (<:COMMA:> <:VariableDeclaration:> )*
+VariableAllocate                                       ::= <:Identifier:>
+VariableAllocateAndInit                                ::= <:Identifier:>
+VariableDeclaration                                    ::= <:VariableAllocateAndInit:> <:Initialiser:> | <:VariableAllocate:>
+Initialiser                                                    ::= <:EQ:> <:AssignmentExpression:>
+
+
+# 12.3 Empty Statement
+EmptyStatement                                         ::= <:SC:>
+
+# 12.4 Expression Statement
+ExpressionStatement                            ::= (<:Expression:> - ('function' | '{')) <:SC:>
+
+
+# 12.5 The if Statement
+
+ElseOp                                                         ::= 'else'
+IfConditionOp                                          ::= 'if' <S>? '(' <S>? <:Expression:> <S>? ')'
+IfOp                                                           ::= <:IfConditionOp:> <S>? <:Statement:>
+IfElseOp                                                       ::= <:IfConditionOp:> <S>? <:Statement:> <S>? <:ElseOp:> <S>? <:Statement:>
+
+IfStatement                                                    ::= <:IfElseOp:> |
+                                                                               <:IfOp:>
+
+# 12.6 Iteration Statements
+# 12.6a Iteration do ... while() 
+WhileKeyword                                           ::= 'while'
+WhileExpression                                                ::= <:WhileKeyword:> <S>? '(' <S>? <:Expression:> <S>? ')'
+DoKeyword                                                      ::= 'do'
+IterationDo                                                    ::= <:DoKeyword:> <S>? <:Statement:> <S>? <:WhileExpression:> (<S>? ';')
+
+# 12.6b Iteration while()
+WhileConditionOp                                       ::= 'while' <S>? '(' <S>? <:Expression:> <S>? ')'
+IterationWhileOp                                       ::= <:WhileConditionOp:> <S>? <:Statement:>
+
+# 12.6c Iteration for ( ; ; )
+ForKeyword                                                     ::= 'for'
+ExpressionNoIn                                         ::= <:Expression:>
+ForExpressionInitOp                                    ::= ('var' <S>? <:VariableDeclarationList:>) | <:ExpressionNoIn:>
+ForExpressionCompareOp                         ::= <:Expression:>
+ForExpressionIncrementOp                       ::= <:Expression:>
+
+# The following & expression is done in order to swap the places of the code generated for the comparison and increment.
+# This is done by selectively turning on/off callbacks in both statement so that the final result appears as if the
+# <:ForExpressionCompareOp:> <:ForExpressionIncrementOp:> appear in the opposite order.
+ForIterationStatementOp                                ::= <:ForKeyword:> <S>? '(' <S>? <:ForExpressionInitOp:>? <S>? ';' <S>? <ForExpressionCompareOp>? <S>? ';' <S>? <:ForExpressionIncrementOp:>? <S>? ')'
+IterationForOp                                         ::= <:ForIterationStatementOp:> <S>? <:Statement:>
+
+
+IterationStatement                                     ::= <:IterationWhileOp:> |
+                                                                               <:IterationForOp:> |
+                                                                       <:IterationDo:>
+
+# 12.9 The return Statement
+ReturnOp                                                       ::= ('return' - 'return' <:IdentifierPart:>) <WhiteSpace>* <:AssignmentExpression:>? (<S>? ';')
+ReturnStatement                                                ::= <:ReturnOp:>
+
+# The Break Statement
+BreakOp                                                                ::= 'break' - 'break' <:IdentifierPart:>
+BreakStatement                                         ::= <S>? <:BreakOp:> <:SC:>
+
+# The Continue Statement
+ContinueOp                                                     ::= 'continue' - 'continue' <:IdentifierPart:>
+ContinueStatement                                      ::= <S>? <:ContinueOp:> <:SC:>
+
+
+
+# 12.10 The with Statement
+WithStatement                                          ::= 'with' <S>? '(' <S>? <:Expression:> <S>? ')' <S>? <:Statement:>
+
+
+# 12.11 The switch Statement
+SwitchExpressionOp                                     ::= ('switch' - 'switch' <IdentifierPart>) <S>? '(' <S>? <:Expression:> <S>? ')'
+SwitchStatementOp                                      ::= <:SwitchExpressionOp:> <S>? <:CaseBlock:>
+
+CaseBlock                                                      ::= '{' <S>? <:CaseClauses:>? <S>? <:DefaultClauseOp:>? <S>? <:CaseClauses:>? <S>? '}' |
+                                                                       '{' <S>? <:CaseClauses:>? <S>? '}'
+
+
+
+CaseClauses                                            ::= (<S>? <:CaseClauseOp:>)+
+CaseExpressionOp                                       ::= ('case' - 'case' <IdentifierPart>) <S>? <:Expression:> <S>? ':'
+CaseClauseOp                                           ::= <:CaseExpressionOp:> <S>? <:StatementList:>?
+DefaultKeywordOp                                       ::= 'default' - 'default' <IdentifierPart>
+DefaultClauseOp                                                ::= <:DefaultKeywordOp:> <S>? ':' <S>? <:StatementList:>?
+
+
+# 13 Function Definition
+FunctionName                                           ::= <:Identifier:>
+FunctionNameLookupAlloc                                ::= <:Identifier:>
+FunctionDefinition                                     ::= ('function' - 'function' <IdentifierPart>)<S>?<:FunctionName:><S>?'('<S>?<:FormalParameterList:>?<S>?')'
+FunctionDeclaration                                    ::= <:FunctionDefinition:><S>?'{'<S>?<:FunctionBody:>?<S>?'}'
+FunctionExpression                                     ::= ('function' - 'function'<IdentifierPart>)<S>?<:FunctionName:>?<S>?'('<S>?<:FormalParameterList:>?<S>?')'<S>?'{'<S>?<:FunctionBody:>?<S>?'}'
+FunctionParameter                                      ::= <:Identifier:>
+FormalParameterList                            ::= <:FunctionParameter:> ( <S>? ',' <S>? <:FunctionParameter:> )*
+FunctionDefinitionStatement                    ::= ('function' - 'function' <IdentifierPart>)<S>?<:FunctionNameLookupAlloc:><S>?'('<S>?<FormalParameterList>?<S>?')' <:SC:>
+FunctionBody                                           ::= <:SourceElements:>
+
+
+# 14 Program
+SourceElements                                         ::= (<S>? <:SourceElement:>)+
+SourceElement                                          ::= <:FunctionDeclaration:> |
+                                                                       <:Statement:>
+Program                                                        ::= <:SourceElements:>
+# The root rule, it is anonymous
+<:Program:>
+       
+
diff --git a/rjs/linux/rjsrules.c b/rjs/linux/rjsrules.c
new file mode 100644 (file)
index 0000000..e2d5894
--- /dev/null
@@ -0,0 +1,20 @@
+#include "rjsrules.h"
+
+
+extern char _binary_____________rjs_ecma262_rpa_start[];
+extern char _binary_____________rjs_ecma262_rpa_end[];
+extern unsigned long *_binary_____________rjs_ecma262_rpa_size;
+
+
+const rchar *rjs_rules_get()
+{
+       const rchar *rules = _binary_____________rjs_ecma262_rpa_start;
+       return rules;
+}
+
+
+rsize_t rjs_rules_size()
+{
+       rsize_t size = _binary_____________rjs_ecma262_rpa_end - _binary_____________rjs_ecma262_rpa_start;
+       return size;
+}
diff --git a/rjs/linux/rjsrules.h b/rjs/linux/rjsrules.h
new file mode 100644 (file)
index 0000000..78302bb
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef _RJSRULES_H_
+#define _RJSRULES_H_
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "rtypes.h"
+
+const rchar *rjs_rules_get();
+rsize_t rjs_rules_size();
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/rjs/rjs.c b/rjs/rjs.c
new file mode 100644 (file)
index 0000000..80e6c33
--- /dev/null
+++ b/rjs/rjs.c
@@ -0,0 +1,7 @@
+#include "rjs.h"
+
+
+const rchar *rjs_version()
+{
+       return RJS_VERSION_STRING;
+}
diff --git a/rjs/rjs.h b/rjs/rjs.h
new file mode 100644 (file)
index 0000000..8aa2391
--- /dev/null
+++ b/rjs/rjs.h
@@ -0,0 +1,24 @@
+#ifndef _RJS_H_
+#define _RJS_H_
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "rtypes.h"
+#include "rjsparser.h"
+
+#define RJS_VERSION_MAJOR 0
+#define RJS_VERSION_MINOR 51
+#define RJS_VERSION_MICRO 1
+#define RJS_VERSION_STRING "0.51.1"
+
+const rchar *rjs_version();
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/rjs/rjsexec.c b/rjs/rjsexec.c
new file mode 100644 (file)
index 0000000..0095a81
--- /dev/null
@@ -0,0 +1,107 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#include "rstring.h"
+#include "rmem.h"
+#include "rjs.h"
+#include "rparecord.h"
+
+
+
+void rjs_unmap_file(rstr_t *buf)
+{
+       if (buf) {
+               munmap(buf->str, buf->size);
+               r_free(buf);
+       }
+}
+
+
+rstr_t *rjs_map_file(const char *filename)
+{
+       struct stat st;
+       rstr_t *str;
+       char *buffer;
+
+
+       int fd = open(filename, O_RDONLY);
+       if (fd < 0) {
+               return (void*)0;
+       }
+       if (fstat(fd, &st) < 0) {
+               close(fd);
+               return (void*)0;
+       }
+       buffer = (char*)mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
+       if (buffer == (void*)-1) {
+               close(fd);
+               return (void*)0;
+       }
+       str = (rstr_t *)r_malloc(sizeof(*str));
+       if (!str)
+               goto error;
+       r_memset(str, 0, sizeof(*str));
+       str->str = buffer;
+       str->size = st.st_size;
+       close(fd);
+       return str;
+
+error:
+       munmap(buffer, st.st_size);
+       close(fd);
+       return str;
+}
+
+
+int main(int argc, char *argv[])
+{
+       rint i;
+       rlong res;
+       rstr_t *script = NULL, *unmapscript = NULL;
+       rjs_parser_t *parser = rjs_parser_create();
+       rarray_t *records = 0;
+
+       if (!parser)
+               return 1;
+       r_printf("JRS Version: %s\n", rjs_version());
+
+       for (i = 1; i < argc; i++) {
+               if (r_strcmp(argv[i], "-e") == 0) {
+                       if (++i < argc) {
+                               rstr_t script = { argv[i], r_strlen(argv[i]) };
+                               res = rjs_parser_exec(parser, script.str, script.size, &records);
+                       }
+                       goto exec;
+               }
+       }
+
+       for (i = 1; i < argc; i++) {
+               if (r_strcmp(argv[i], "-f") == 0) {
+                       if (++i < argc) {
+                               script = rjs_map_file(argv[i]);
+                               if (script) {
+                                       res = rjs_parser_exec(parser, script->str, script->size, &records);;
+                                       unmapscript = script;
+                               }
+                       }
+                       goto exec;
+               }
+       }
+
+exec:
+       if (records) {
+               rlong i;
+               for (i = 0; i < r_array_length(records); i++)
+                       rpa_record_dump(records, i);
+       }
+       rjs_parser_destroy(parser);
+       if (unmapscript)
+               rjs_unmap_file(unmapscript);
+       return 0;
+}
diff --git a/rjs/rjsparser.c b/rjs/rjsparser.c
new file mode 100644 (file)
index 0000000..4548a8f
--- /dev/null
@@ -0,0 +1,72 @@
+#include "rmem.h"
+#include "rjsrules.h"
+#include "rjsparser.h"
+
+
+void rjs_parser_dbex_error(rjs_parser_t *parser)
+{
+       rpa_errinfo_t err;
+       r_memset(&err, 0, sizeof(err));
+       rpa_dbex_getlasterrinfo(parser->dbex, &err);
+       r_printf("Failed to load RPA rules");
+       if (err.mask & RPA_ERRINFO_CODE) {
+               r_printf(", Error Code: %ld", err.code);
+       }
+       if (err.mask & RPA_ERRINFO_OFFSET) {
+               rlong line = 1, i;
+               const rchar *ptr = rjs_rules_get();
+               for (i = 0; i < err.offset; i++) {
+                       if (ptr[i] == '\n')
+                               line += 1;
+               }
+               r_printf(", Offset: %ld, Line: %ld", err.offset, line);
+       }
+       if (err.mask & RPA_ERRINFO_NAME) {
+               r_printf(", Rule Name: %s", err.name);
+       }
+       r_printf("\n");
+}
+
+
+rjs_parser_t *rjs_parser_create()
+{
+       rjs_parser_t *parser = (rjs_parser_t *) r_zmalloc(sizeof(*parser));
+
+       parser->dbex = rpa_dbex_create();
+       if (!parser) {
+               rjs_parser_destroy(parser);
+               return NULL;
+       }
+       rpa_dbex_open(parser->dbex);
+       if (rpa_dbex_load(parser->dbex, rjs_rules_get(), rjs_rules_size()) < 0) {
+               rjs_parser_dbex_error(parser);
+               rjs_parser_destroy(parser);
+               return NULL;
+       }
+       rpa_dbex_close(parser->dbex);
+       if (rpa_dbex_compile(parser->dbex) < 0) {
+               rjs_parser_dbex_error(parser);
+               rjs_parser_destroy(parser);
+               return NULL;
+       }
+       return parser;
+}
+
+
+void rjs_parser_destroy(rjs_parser_t *parser)
+{
+       if (parser) {
+               rpa_dbex_destroy(parser->dbex);
+               r_free(parser);
+       }
+}
+
+
+rlong rjs_parser_exec(rjs_parser_t *parser, const rchar *script, rsize_t size, rarray_t **ast)
+{
+       rlong res = 0;
+       rpastat_t *stat = rpa_stat_create(parser->dbex, 4096);
+       res = rpa_stat_parse(stat, rpa_dbex_default(parser->dbex), script, script, script + size, ast);
+       rpa_stat_destroy(stat);
+       return res;
+}
diff --git a/rjs/rjsparser.h b/rjs/rjsparser.h
new file mode 100644 (file)
index 0000000..ebfb690
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef _RJSPARSER_H_
+#define _RJSPARSER_H_
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "rtypes.h"
+#include "rarray.h"
+#include "rvmcpu.h"
+#include "rpa.h"
+
+
+typedef struct rjs_parser_s {
+       rpadbex_t *dbex;
+
+} rjs_parser_t;
+
+
+rjs_parser_t *rjs_parser_create();
+void rjs_parser_destroy(rjs_parser_t *parser);
+rlong rjs_parser_exec(rjs_parser_t *parser, const rchar *script, rsize_t size, rarray_t **ast);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index 7bf9ac4..6022de6 100644 (file)
@@ -17,7 +17,7 @@ typedef rint (*rpa_dbex_recordhandler)(rpadbex_t *dbex, rlong rec);
 #define RPA_DBEX_SETERRINFO_OFFSET(__d__, __o__) do { (__d__)->err.offset = __o__; (__d__)->err.mask |= RPA_ERRINFO_OFFSET; } while (0)
 #define RPA_DBEX_SETERRINFO_RULEID(__d__, __r__) do { (__d__)->err.ruleid = __r__; (__d__)->err.mask |= RPA_ERRINFO_RULEID; } while (0)
 #define RPA_DBEX_SETERRINFO_NAME(__d__, __n__, __s__) do { \
-       (__d__)->err.mask |= RPA_ERRINFO_RULEID; \
+       (__d__)->err.mask |= RPA_ERRINFO_NAME; \
        r_memset((__d__)->err.name, 0, sizeof((__d__)->err.name)); \
        r_strncpy((__d__)->err.name, __n__, R_MIN(__s__, (sizeof((__d__)->err.name) - 1)));  } while (0)
 
index d914d4f..dd1ff55 100644 (file)
@@ -21,17 +21,13 @@ extern "C" {
 #define RPA_RECORD_INVALID_UID ((ruint32)-1)
 
 typedef struct rparecord_s {
-       rlist_t head;
-       rlink_t lnk;
        rlong next;
-       rword loo;
-       const char *rule;
-       ruint32 ruleid;
+       const rchar *rule;
+       const rchar *input;
+       rsize_t inputsiz;
+       ruint32 type;
        ruint32 top;
        ruint32 size;
-       ruint32 type;
-       const char *input;
-       rsize_t inputsiz;
        ruint32 ruleuid;
        ruint32 usertype;
        rword userdata;
index 8c01310..8060c76 100644 (file)
@@ -222,21 +222,20 @@ rlong rpa_stat_match(rpastat_t *stat, rparule_t rid, const rchar *input, const r
 }
 
 
-rarray_t *rpa_stat_parse(rpastat_t *stat, rparule_t rid, const rchar *input, const rchar *start, const rchar *end)
+rlong rpa_stat_parse(rpastat_t *stat, rparule_t rid, const rchar *input, const rchar *start, const rchar *end, rarray_t **records)
 {
        rint res = 0;
-       rarray_t *records = NULL;
 
        if (!stat) {
-               return NULL;
+               return -1;
        }
 
        res = rpa_stat_exec_noinit(stat, rid, input, start, end);
-       if (res > 0 && !r_array_empty(stat->records)) {
-               records = stat->records;
+       if (res > 0 && !r_array_empty(stat->records) && records) {
+               *records = stat->records;
                stat->records = r_array_create(sizeof(rparecord_t));
        }
-       return records;
+       return res;
 }
 
 
index 7b432b0..db085d5 100644 (file)
@@ -55,7 +55,7 @@ rint rpa_stat_encodingset(rpastat_t *stat, ruint encoding);
 rlong rpa_stat_exec(rpastat_t *stat, rvm_asmins_t *prog, rword off);
 rlong rpa_stat_scan(rpastat_t *stat, rparule_t rid, const rchar *input, const rchar *start, const rchar *end, const rchar **where);
 rlong rpa_stat_match(rpastat_t *stat, rparule_t rid, const rchar *input, const rchar *start, const rchar *end);
-rarray_t *rpa_stat_parse(rpastat_t *stat, rparule_t rid, const rchar *input, const rchar *start, const rchar *end);
+rlong rpa_stat_parse(rpastat_t *stat, rparule_t rid, const rchar *input, const rchar *start, const rchar *end, rarray_t **records);
 rint rpa_stat_abort(rpastat_t *stat);
 
 rint rpa_stat_matchchr(rpastat_t *stat, rssize_t top, rulong wc);
index ffa7b71..7d4ff96 100644 (file)
@@ -263,7 +263,6 @@ static void rpavm_swi_emitstart(rvmcpu_t *cpu, rvm_asmins_t *ins)
        rec = (rparecord_t *)r_array_slot(stat->records, index);
        rec->rule = name.str;
        rec->top = tp;
-       rec->ruleid = ruledata->ruleid;
        rec->ruleuid = ruledata->ruleuid;
        rec->type = RPA_RECORD_START;
        rec->input = stat->instack[tp].input;
@@ -301,7 +300,6 @@ static void rpavm_swi_emitend(rvmcpu_t *cpu, rvm_asmins_t *ins)
        rec->top = tp;
        rec->size = tplen;
        rec->type = RPA_RECORD_END;
-       rec->ruleid = ruledata->ruleid;
        rec->ruleuid = ruledata->ruleuid;
        rec->input = stat->instack[tp].input;
        rec->inputsiz = stat->instack[tp + tplen].input - stat->instack[tp].input;
index 2925ef1..9559a5c 100644 (file)
@@ -104,7 +104,7 @@ int main(int argc, char *argv[])
 
        for (i = 0; i < r_array_length(stat->records); i++) {
                rparecord_t *rec = (rparecord_t *)r_array_slot(stat->records, i);
-               r_printf("%3d ( %7ld ): ", i, rec->ruleid);
+               r_printf("%3d : ", i);
                if (rec->type & RPA_RECORD_START)
                        r_printf("START ");
                if (rec->type & RPA_RECORD_MATCH)