@ -456,13 +456,13 @@ impl<'b> ByteCompiler<'b> {
}
#[ inline ]
fn compile_access ( node : & ' _ Node ) -> Access < ' _ > {
fn compile_access ( node : & Node ) -> Option < Access < ' _ > > {
match node {
Node ::Identifier ( name ) = > Access ::Variable { name : name . sym ( ) } ,
Node ::GetConstField ( node ) = > Access ::ByName { node } ,
Node ::GetField ( node ) = > Access ::ByValue { node } ,
Node ::This = > Access ::This ,
_ = > unreachable! ( ) ,
Node ::Identifier ( name ) = > Some ( Access ::Variable { name : name . sym ( ) } ) ,
Node ::GetConstField ( node ) = > Some ( Access ::ByName { node } ) ,
Node ::GetField ( node ) = > Some ( Access ::ByValue { node } ) ,
Node ::This = > Some ( Access ::This ) ,
_ = > None ,
}
}
@ -571,7 +571,10 @@ impl<'b> ByteCompiler<'b> {
self . compile_expr ( unary . target ( ) , true ) ? ;
self . emit ( Opcode ::Inc , & [ ] ) ;
let access = Self ::compile_access ( unary . target ( ) ) ;
let access = Self ::compile_access ( unary . target ( ) ) . ok_or_else ( | | {
self . context
. construct_syntax_error ( "Invalid increment operand" )
} ) ? ;
self . access_set ( access , None , true ) ? ;
None
}
@ -579,7 +582,10 @@ impl<'b> ByteCompiler<'b> {
self . compile_expr ( unary . target ( ) , true ) ? ;
self . emit ( Opcode ::Dec , & [ ] ) ;
let access = Self ::compile_access ( unary . target ( ) ) ;
let access = Self ::compile_access ( unary . target ( ) ) . ok_or_else ( | | {
self . context
. construct_syntax_error ( "Invalid decrement operand" )
} ) ? ;
self . access_set ( access , None , true ) ? ;
None
}
@ -587,7 +593,11 @@ impl<'b> ByteCompiler<'b> {
self . compile_expr ( unary . target ( ) , true ) ? ;
self . emit ( Opcode ::Dup , & [ ] ) ;
self . emit ( Opcode ::Inc , & [ ] ) ;
let access = Self ::compile_access ( unary . target ( ) ) ;
let access = Self ::compile_access ( unary . target ( ) ) . ok_or_else ( | | {
self . context
. construct_syntax_error ( "Invalid increment operand" )
} ) ? ;
self . access_set ( access , None , false ) ? ;
None
@ -596,7 +606,11 @@ impl<'b> ByteCompiler<'b> {
self . compile_expr ( unary . target ( ) , true ) ? ;
self . emit ( Opcode ::Dup , & [ ] ) ;
self . emit ( Opcode ::Dec , & [ ] ) ;
let access = Self ::compile_access ( unary . target ( ) ) ;
let access = Self ::compile_access ( unary . target ( ) ) . ok_or_else ( | | {
self . context
. construct_syntax_error ( "Invalid decrement operand" )
} ) ? ;
self . access_set ( access , None , false ) ? ;
None
@ -744,7 +758,12 @@ impl<'b> ByteCompiler<'b> {
AssignOp ::BoolAnd = > {
let exit = self . jump_with_custom_opcode ( Opcode ::LogicalAnd ) ;
self . compile_expr ( binary . rhs ( ) , true ) ? ;
let access = Self ::compile_access ( binary . lhs ( ) ) ;
let access =
Self ::compile_access ( binary . lhs ( ) ) . ok_or_else ( | | {
self . context . construct_syntax_error (
"Invalid left-hand side in assignment" ,
)
} ) ? ;
self . access_set ( access , None , use_expr ) ? ;
self . patch_jump ( exit ) ;
None
@ -752,7 +771,12 @@ impl<'b> ByteCompiler<'b> {
AssignOp ::BoolOr = > {
let exit = self . jump_with_custom_opcode ( Opcode ::LogicalOr ) ;
self . compile_expr ( binary . rhs ( ) , true ) ? ;
let access = Self ::compile_access ( binary . lhs ( ) ) ;
let access =
Self ::compile_access ( binary . lhs ( ) ) . ok_or_else ( | | {
self . context . construct_syntax_error (
"Invalid left-hand side in assignment" ,
)
} ) ? ;
self . access_set ( access , None , use_expr ) ? ;
self . patch_jump ( exit ) ;
None
@ -760,7 +784,12 @@ impl<'b> ByteCompiler<'b> {
AssignOp ::Coalesce = > {
let exit = self . jump_with_custom_opcode ( Opcode ::Coalesce ) ;
self . compile_expr ( binary . rhs ( ) , true ) ? ;
let access = Self ::compile_access ( binary . lhs ( ) ) ;
let access =
Self ::compile_access ( binary . lhs ( ) ) . ok_or_else ( | | {
self . context . construct_syntax_error (
"Invalid left-hand side in assignment" ,
)
} ) ? ;
self . access_set ( access , None , use_expr ) ? ;
self . patch_jump ( exit ) ;
None
@ -770,7 +799,10 @@ impl<'b> ByteCompiler<'b> {
if let Some ( opcode ) = opcode {
self . compile_expr ( binary . rhs ( ) , true ) ? ;
self . emit ( opcode , & [ ] ) ;
let access = Self ::compile_access ( binary . lhs ( ) ) ;
let access = Self ::compile_access ( binary . lhs ( ) ) . ok_or_else ( | | {
self . context
. construct_syntax_error ( "Invalid left-hand side in assignment" )
} ) ? ;
self . access_set ( access , None , use_expr ) ? ;
}
}
@ -903,7 +935,10 @@ impl<'b> ByteCompiler<'b> {
if let Node ::Object ( _ ) = assign . lhs ( ) {
self . emit_opcode ( Opcode ::PushUndefined ) ;
} else {
let access = Self ::compile_access ( assign . lhs ( ) ) ;
let access = Self ::compile_access ( assign . lhs ( ) ) . ok_or_else ( | | {
self . context
. construct_syntax_error ( "Invalid left-hand side in assignment" )
} ) ? ;
self . access_set ( access , Some ( assign . rhs ( ) ) , use_expr ) ? ;
}
}