@@ -1010,6 +1010,7 @@ impl Executor {
1010
1010
// Generate a instance of object
1011
1011
"instance" => {
1012
1012
let data = self . pop_stack ( ) . get_list ( ) ;
1013
+ let mut methods = self . pop_stack ( ) . get_list ( ) ;
1013
1014
let mut class = self . pop_stack ( ) . get_list ( ) ;
1014
1015
let mut object: HashMap < String , Type > = HashMap :: new ( ) ;
1015
1016
let name = class[ 0 ] . get_string ( ) ;
@@ -1018,6 +1019,11 @@ impl Executor {
1018
1019
object. insert ( name. to_owned ( ) . get_string ( ) , element) ;
1019
1020
}
1020
1021
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
+
1021
1027
self . stack . push ( Type :: Object ( name, object) )
1022
1028
}
1023
1029
@@ -1034,6 +1040,28 @@ impl Executor {
1034
1040
}
1035
1041
}
1036
1042
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
+
1037
1065
// Get all of properties
1038
1066
"all" => match self . pop_stack ( ) {
1039
1067
Type :: Object ( _, data) => self . stack . push ( Type :: List (
0 commit comments