@@ -6,7 +6,7 @@ use noise::{NoiseFn, Simplex};
66use widestring:: { U16Str , u16str} ;
77
88use super :: {
9- Constants , LogicVM , VMLoadError , VMLoadResult ,
9+ Constants , LogicVM , VMLoadError , VMLoadResult , borrow_data ,
1010 buildings:: BuildingData ,
1111 processor:: { MAX_TEXT_BUFFER , ProcessorState } ,
1212 variables:: { Content , LValue , LVar , RAD_DEG } ,
@@ -376,9 +376,9 @@ impl SimpleInstructionTrait for Read {
376376 let address = self . address . get ( state) ;
377377
378378 let result = match self . target . get ( state) {
379- LValue :: Building ( building) => building . borrow_data (
380- state ,
381- | state| match address. clone ( ) {
379+ LValue :: Building ( building) => borrow_data ! (
380+ building . data ,
381+ state => match address {
382382 // read variable with name, returning null for constants and undefined
383383 LValue :: String ( name) => {
384384 if * name == u16str!( "@counter" ) {
@@ -391,7 +391,7 @@ impl SimpleInstructionTrait for Read {
391391 // no-op if the address is not a string
392392 _ => None ,
393393 } ,
394- | data| match data {
394+ data => match data {
395395 // read value at index
396396 BuildingData :: Memory ( memory) => {
397397 // coerce the address to a number, and return null if the address is not in range
@@ -433,19 +433,19 @@ impl SimpleInstructionTrait for Write {
433433 let address = self . address . get ( state) ;
434434 let value = self . value . get ( state) ;
435435
436- building . borrow_data_mut (
437- state ,
438- | state| match address. clone ( ) {
436+ borrow_data ! (
437+ mut building . data ,
438+ state => match address {
439439 LValue :: String ( name) if * name == u16str!( "@counter" ) => {
440- state. try_set_counter ( value. clone ( ) ) ;
440+ state. try_set_counter( value) ;
441441 state. set_stopped( false ) ;
442442 }
443443 LValue :: String ( name) if state. variables. contains_key( & * name) => {
444- state. variables [ & * name] = value. clone ( ) ;
444+ state. variables[ & * name] = value;
445445 }
446446 _ => { }
447447 } ,
448- | data| {
448+ data => {
449449 if let BuildingData :: Memory ( memory) = data
450450 && let Ok ( address) = address. num_usize( )
451451 && address < memory. len( )
@@ -608,10 +608,10 @@ impl SimpleInstructionTrait for Control {
608608 let enabled = self . p1 . get ( state) ;
609609 if !enabled. isobj ( ) {
610610 let enabled = enabled. numf ( ) != 0. ;
611- building . borrow_data_mut (
612- state ,
613- | state| state. set_enabled ( enabled) ,
614- | data| {
611+ borrow_data ! (
612+ mut building . data ,
613+ state => state. set_enabled( enabled) ,
614+ data => {
615615 if let BuildingData :: Switch ( value) = data {
616616 * value = enabled;
617617 }
@@ -706,13 +706,13 @@ impl SimpleInstructionTrait for Sensor {
706706 FirstItem => LValue :: Null ,
707707 PayloadType => LValue :: Null ,
708708
709- _ => building . borrow_data (
710- state ,
711- | state| match sensor {
709+ _ => borrow_data ! (
710+ building . data ,
711+ state => match sensor {
712712 LAccess :: Enabled => state. enabled( ) . into( ) ,
713713 _ => LValue :: Null ,
714714 } ,
715- | data| match data {
715+ data => match data {
716716 BuildingData :: Memory ( memory) => match sensor {
717717 MemoryCapacity => memory. len( ) . into( ) ,
718718 Enabled => true . into( ) ,
0 commit comments