@@ -1010,6 +1010,7 @@ impl Executor {
10101010 // Generate a instance of object
10111011 "instance" => {
10121012 let data = self . pop_stack ( ) . get_list ( ) ;
1013+ let mut methods = self . pop_stack ( ) . get_list ( ) ;
10131014 let mut class = self . pop_stack ( ) . get_list ( ) ;
10141015 let mut object: HashMap < String , Type > = HashMap :: new ( ) ;
10151016 let name = class[ 0 ] . get_string ( ) ;
@@ -1018,6 +1019,11 @@ impl Executor {
10181019 object. insert ( name. to_owned ( ) . get_string ( ) , element) ;
10191020 }
10201021
1022+ for item in & mut methods {
1023+ let item = item. get_list ( ) ;
1024+ object. insert ( item[ 0 ] . clone ( ) . get_string ( ) , item[ 1 ] . clone ( ) ) ;
1025+ }
1026+
10211027 self . stack . push ( Type :: Object ( name, object) )
10221028 }
10231029
@@ -1034,6 +1040,28 @@ impl Executor {
10341040 }
10351041 }
10361042
1043+ // Call the method of object
1044+ "method" => {
1045+ let method = self . pop_stack ( ) . get_string ( ) ;
1046+ match self . pop_stack ( ) {
1047+ Type :: Object ( name, value) => {
1048+ let data = Type :: Object ( name, value. clone ( ) ) ;
1049+ self . memory
1050+ . entry ( "self" . to_string ( ) )
1051+ . and_modify ( |value| * value = data. clone ( ) )
1052+ . or_insert ( data) ;
1053+
1054+ let program: String = match value. get ( & method) {
1055+ Some ( i) => i. to_owned ( ) . get_string ( ) . to_string ( ) ,
1056+ None => "" . to_string ( ) ,
1057+ } ;
1058+
1059+ self . evaluate_program ( program)
1060+ }
1061+ _ => self . stack . push ( Type :: Error ( "not-object" . to_string ( ) ) ) ,
1062+ }
1063+ }
1064+
10371065 // Get all of properties
10381066 "all" => match self . pop_stack ( ) {
10391067 Type :: Object ( _, data) => self . stack . push ( Type :: List (
0 commit comments