@@ -281,7 +281,6 @@ enum Type {
281
281
Bool ( bool ) ,
282
282
List ( Vec < Type > ) ,
283
283
Matrix ( Vec < Fraction > , ( usize , usize ) ) ,
284
- Object ( String , HashMap < String , Type > ) ,
285
284
Error ( String ) ,
286
285
}
287
286
@@ -331,7 +330,6 @@ impl Type {
331
330
format ! ( "[{}]" , result. join( " " ) )
332
331
}
333
332
Type :: Error ( err) => format ! ( "error:{err}" ) ,
334
- Type :: Object ( name, _) => format ! ( "Object<{name}>" ) ,
335
333
Type :: Matrix ( mx, ( _, length) ) => Type :: to_matrix ( mx, * length) ,
336
334
}
337
335
}
@@ -344,7 +342,6 @@ impl Type {
344
342
Type :: Bool ( b) => b. to_string ( ) ,
345
343
Type :: List ( l) => Type :: List ( l. to_owned ( ) ) . display ( ) ,
346
344
Type :: Error ( err) => format ! ( "error:{err}" ) ,
347
- Type :: Object ( name, _) => format ! ( "Object<{name}>" ) ,
348
345
Type :: Matrix ( mx, ( _, length) ) => Type :: to_matrix ( mx, * length) ,
349
346
}
350
347
}
@@ -363,7 +360,6 @@ impl Type {
363
360
}
364
361
Type :: List ( l) => Fraction :: new ( l. len ( ) as f64 ) ,
365
362
Type :: Error ( e) => Fraction :: new ( e. parse ( ) . unwrap_or ( 0f64 ) ) ,
366
- Type :: Object ( _, object) => Fraction :: new ( object. len ( ) as f64 ) ,
367
363
_ => Fraction :: new ( 0f64 ) ,
368
364
}
369
365
}
@@ -376,7 +372,6 @@ impl Type {
376
372
Type :: Bool ( b) => * b,
377
373
Type :: List ( l) => !l. is_empty ( ) ,
378
374
Type :: Error ( e) => e. parse ( ) . unwrap_or ( false ) ,
379
- Type :: Object ( _, object) => object. is_empty ( ) ,
380
375
_ => false ,
381
376
}
382
377
}
@@ -393,7 +388,6 @@ impl Type {
393
388
Type :: Bool ( b) => vec ! [ Type :: Bool ( * b) ] ,
394
389
Type :: List ( l) => l. to_vec ( ) ,
395
390
Type :: Error ( e) => vec ! [ Type :: Error ( e. to_string( ) ) ] ,
396
- Type :: Object ( _, object) => object. values ( ) . map ( |x| x. to_owned ( ) ) . collect :: < Vec < Type > > ( ) ,
397
391
Type :: Matrix ( l, _) => l
398
392
. to_owned ( )
399
393
. iter ( )
@@ -1155,14 +1149,16 @@ impl Executor {
1155
1149
1156
1150
// Generate a range
1157
1151
"range" => {
1158
- let step = self . pop_stack ( ) . get_number ( ) . to_f64 ( ) ;
1159
- let max = self . pop_stack ( ) . get_number ( ) . to_f64 ( ) ;
1160
- let min = self . pop_stack ( ) . get_number ( ) . to_f64 ( ) ;
1152
+ let step = self . pop_stack ( ) . get_number ( ) ;
1153
+ let max = self . pop_stack ( ) . get_number ( ) ;
1154
+ let min = self . pop_stack ( ) . get_number ( ) ;
1161
1155
1162
1156
let mut range: Vec < Type > = Vec :: new ( ) ;
1157
+ let mut i = min;
1163
1158
1164
- for i in ( min as usize ..max as usize ) . step_by ( step as usize ) {
1165
- range. push ( Type :: Number ( Fraction :: new ( i as f64 ) ) ) ;
1159
+ while i < max {
1160
+ range. push ( Type :: Number ( i) ) ;
1161
+ i += step;
1166
1162
}
1167
1163
1168
1164
self . stack . push ( Type :: List ( range) ) ;
@@ -1296,7 +1292,6 @@ impl Executor {
1296
1292
Type :: List ( _) => "list" . to_string ( ) ,
1297
1293
Type :: Error ( _) => "error" . to_string ( ) ,
1298
1294
Type :: Matrix ( _, _) => "matrix" . to_string ( ) ,
1299
- Type :: Object ( name, _) => name. to_string ( ) ,
1300
1295
} ;
1301
1296
1302
1297
self . stack . push ( Type :: String ( result) ) ;
@@ -1364,114 +1359,6 @@ impl Executor {
1364
1359
self . pop_stack ( ) . get_number ( ) . to_f64 ( ) ,
1365
1360
) ) ,
1366
1361
1367
- // Commands of object oriented system
1368
-
1369
- // Generate a instance of object
1370
- "instance" => {
1371
- let data = self . pop_stack ( ) . get_list ( ) ;
1372
- let mut class = self . pop_stack ( ) . get_list ( ) ;
1373
- let mut object: HashMap < String , Type > = HashMap :: new ( ) ;
1374
-
1375
- let name = if !class. is_empty ( ) {
1376
- class[ 0 ] . get_string ( )
1377
- } else {
1378
- self . log_print ( "Error! the type name is not found." . to_string ( ) ) ;
1379
- self . stack . push ( Type :: Error ( "instance-name" . to_string ( ) ) ) ;
1380
- return ;
1381
- } ;
1382
-
1383
- let mut index = 0 ;
1384
- for item in & mut class. to_owned ( ) [ 1 ..class. len ( ) ] . iter ( ) {
1385
- let mut item = item. to_owned ( ) ;
1386
- if item. get_list ( ) . len ( ) == 1 {
1387
- let element = match data. get ( index) {
1388
- Some ( value) => value,
1389
- None => {
1390
- self . log_print ( "Error! initial data is shortage\n " . to_string ( ) ) ;
1391
- self . stack
1392
- . push ( Type :: Error ( "instance-shortage" . to_string ( ) ) ) ;
1393
- return ;
1394
- }
1395
- } ;
1396
- object. insert (
1397
- item. get_list ( ) [ 0 ] . to_owned ( ) . get_string ( ) ,
1398
- element. to_owned ( ) ,
1399
- ) ;
1400
- index += 1 ;
1401
- } else if item. get_list ( ) . len ( ) >= 2 {
1402
- let item = item. get_list ( ) ;
1403
- object. insert ( item[ 0 ] . clone ( ) . get_string ( ) , item[ 1 ] . clone ( ) ) ;
1404
- } else {
1405
- self . log_print ( "Error! the class data structure is wrong." . to_string ( ) ) ;
1406
- self . stack . push ( Type :: Error ( "instance-default" . to_string ( ) ) ) ;
1407
- }
1408
- }
1409
-
1410
- self . stack . push ( Type :: Object ( name, object) )
1411
- }
1412
-
1413
- // Get property of object
1414
- "property" => {
1415
- let name = self . pop_stack ( ) . get_string ( ) ;
1416
- match self . pop_stack ( ) {
1417
- Type :: Object ( _, data) => self . stack . push (
1418
- data. get ( name. as_str ( ) )
1419
- . unwrap_or ( & Type :: Error ( "property" . to_string ( ) ) )
1420
- . clone ( ) ,
1421
- ) ,
1422
- _ => self . stack . push ( Type :: Error ( "not-object" . to_string ( ) ) ) ,
1423
- }
1424
- }
1425
-
1426
- // Call the method of object
1427
- "method" => {
1428
- let method = self . pop_stack ( ) . get_string ( ) ;
1429
- match self . pop_stack ( ) {
1430
- Type :: Object ( name, value) => {
1431
- let data = Type :: Object ( name, value. clone ( ) ) ;
1432
- self . memory
1433
- . entry ( "self" . to_string ( ) )
1434
- . and_modify ( |value| * value = data. clone ( ) )
1435
- . or_insert ( data) ;
1436
-
1437
- let program: String = match value. get ( & method) {
1438
- Some ( i) => i. to_owned ( ) . get_string ( ) . to_string ( ) ,
1439
- None => "" . to_string ( ) ,
1440
- } ;
1441
-
1442
- self . evaluate_program ( program)
1443
- }
1444
- _ => self . stack . push ( Type :: Error ( "not-object" . to_string ( ) ) ) ,
1445
- }
1446
- }
1447
-
1448
- // Modify the property of object
1449
- "modify" => {
1450
- let data = self . pop_stack ( ) ;
1451
- let property = self . pop_stack ( ) . get_string ( ) ;
1452
- match self . pop_stack ( ) {
1453
- Type :: Object ( name, mut value) => {
1454
- value
1455
- . entry ( property)
1456
- . and_modify ( |value| * value = data. clone ( ) )
1457
- . or_insert ( data. clone ( ) ) ;
1458
-
1459
- self . stack . push ( Type :: Object ( name, value) )
1460
- }
1461
- _ => self . stack . push ( Type :: Error ( "not-object" . to_string ( ) ) ) ,
1462
- }
1463
- }
1464
-
1465
- // Get all of properties
1466
- "all" => match self . pop_stack ( ) {
1467
- Type :: Object ( _, data) => self . stack . push ( Type :: List (
1468
- data. keys ( )
1469
- . map ( |x| Type :: String ( x. to_owned ( ) ) )
1470
- . collect :: < Vec < Type > > ( ) ,
1471
- ) ) ,
1472
- _ => self . stack . push ( Type :: Error ( "not-object" . to_string ( ) ) ) ,
1473
- } ,
1474
-
1475
1362
// Commands of matrix
1476
1363
"scalar-mul" => {
1477
1364
let number = self . pop_stack ( ) . get_number ( ) . to_f64 ( ) ;
0 commit comments