@@ -337,58 +337,64 @@ let comparison (cmp : Lambda.comparison) a b : bool =
337
337
| Clt -> a < b
338
338
| Cge -> a > = b
339
339
340
- let lift_int i : t =
341
- Lconst (Const_base (Const_int i))
340
+ module Lift = struct
341
+ let int i : t =
342
+ Lconst (Const_base (Const_int i))
342
343
343
344
344
- let int32 i : t =
345
- Lconst (Const_base (Const_int32 i))
345
+ let int32 i : t =
346
+ Lconst (Const_base (Const_int32 i))
346
347
347
- let lift_bool b = if b then true_ else false_
348
+ let bool b = if b then true_ else false_
348
349
349
- (* ATTENTION: [float, nativeint] constant propogaton is not done
350
- yet , due to cross platform problem
351
- *)
352
- let lift_float b : t =
353
- Lconst (Const_base (Const_float b))
350
+ (* ATTENTION: [float, nativeint] constant propogaton is not done
351
+ yet , due to cross platform problem
352
+ *)
353
+ let float b : t =
354
+ Lconst (Const_base (Const_float b))
354
355
355
- let lift_nativeint b : t =
356
- Lconst (Const_base (Const_nativeint b))
356
+ let nativeint b : t =
357
+ Lconst (Const_base (Const_nativeint b))
357
358
358
- let lift_int32 b : t =
359
- Lconst (Const_base (Const_int32 b))
359
+ let int32 b : t =
360
+ Lconst (Const_base (Const_int32 b))
360
361
361
- let lift_int64 b : t =
362
- Lconst (Const_base (Const_int64 b))
362
+ let int64 b : t =
363
+ Lconst (Const_base (Const_int64 b))
364
+ let string b : t =
365
+ Lconst (Const_base (Const_string (b, None )))
366
+ let char b : t =
367
+ Lconst (Const_base (Const_char b))
368
+ end
363
369
364
370
let prim ~primitive :(prim : Prim.t ) ~args :(ll : t list ) : t =
365
371
let default () : t = Lprim { primitive = prim ;args = ll } in
366
372
match ll with
367
373
| [Lconst a] ->
368
374
begin match prim, a with
369
375
| Pnegint , (Const_base (Const_int a))
370
- -> lift_int (- a)
376
+ -> Lift. int (- a)
371
377
(* | Pfloatofint, (Const_base (Const_int a)) *)
372
- (* -> lift_float (float_of_int a) *)
378
+ (* -> Lift.float (float_of_int a) *)
373
379
| Pintoffloat , (Const_base (Const_float a))
374
380
->
375
- lift_int (int_of_float (float_of_string a))
376
- (* | Pnegfloat -> lift_float (-. a) *)
377
- (* | Pabsfloat -> lift_float (abs_float a) *)
381
+ Lift. int (int_of_float (float_of_string a))
382
+ (* | Pnegfloat -> Lift.float (-. a) *)
383
+ (* | Pabsfloat -> Lift.float (abs_float a) *)
378
384
| Pstringlength , (Const_base (Const_string (a,_)) )
379
385
->
380
- lift_int (String. length a)
386
+ Lift. int (String. length a)
381
387
(* | Pnegbint Pnativeint, (Const_base (Const_nativeint i)) *)
382
388
(* -> *)
383
- (* lift_nativeint (Nativeint.neg i) *)
389
+ (* Lift.nativeint (Nativeint.neg i) *)
384
390
| Pnegbint Pint32 , (Const_base (Const_int32 a))
385
391
->
386
- lift_int32 (Int32. neg a)
392
+ Lift. int32 (Int32. neg a)
387
393
| Pnegbint Pint64 , (Const_base (Const_int64 a))
388
394
->
389
- lift_int64 (Int64. neg a)
395
+ Lift. int64 (Int64. neg a)
390
396
| Pnot , Const_pointer (a,_)
391
- -> lift_bool (a = 0 )
397
+ -> Lift. bool (a = 0 )
392
398
393
399
| _ -> default ()
394
400
end
@@ -397,15 +403,15 @@ let prim ~primitive:(prim : Prim.t) ~args:(ll : t list) : t =
397
403
| [Lconst a ; Lconst b] ->
398
404
begin match prim, a, b with
399
405
| Pbintcomp (_, cmp), Const_base (Const_int32 a), Const_base (Const_int32 b)
400
- -> lift_bool (comparison cmp a b)
406
+ -> Lift. bool (comparison cmp a b)
401
407
| Pbintcomp (_, cmp), Const_base (Const_int64 a), Const_base (Const_int64 b)
402
- -> lift_bool (comparison cmp a b)
408
+ -> Lift. bool (comparison cmp a b)
403
409
| Pbintcomp (_, cmp), Const_base (Const_nativeint a), Const_base (Const_nativeint b)
404
- -> lift_bool (comparison cmp a b)
410
+ -> Lift. bool (comparison cmp a b)
405
411
| Pfloatcomp cmp, Const_base (Const_nativeint a), Const_base (Const_nativeint b)
406
- -> lift_bool (comparison cmp a b)
412
+ -> Lift. bool (comparison cmp a b)
407
413
| Pintcomp cmp , Const_base (Const_int a), Const_base (Const_int b)
408
- -> lift_bool (comparison cmp a b)
414
+ -> Lift. bool (comparison cmp a b)
409
415
410
416
| (Paddint
411
417
| Psubint
@@ -421,7 +427,7 @@ let prim ~primitive:(prim : Prim.t) ~args:(ll : t list) : t =
421
427
->
422
428
(* WE SHOULD keep it as [int], to preserve types *)
423
429
let aa,bb = Int32. of_int a, Int32. of_int b in
424
- let int_ v = lift_int (Int32. to_int v ) in
430
+ let int_ v = Lift. int (Int32. to_int v ) in
425
431
begin match prim with
426
432
| Paddint -> int_ (Int32. add aa bb)
427
433
| Psubint -> int_ (Int32. sub aa bb)
@@ -451,22 +457,22 @@ let prim ~primitive:(prim : Prim.t) ~args:(ll : t list) : t =
451
457
), Const_base (Const_int32 aa), Const_base (Const_int32 bb)
452
458
->
453
459
begin match prim with
454
- | Paddbint _ -> lift_int32 (Int32. add aa bb)
455
- | Psubbint _ -> lift_int32 (Int32. sub aa bb)
456
- | Pmulbint _ -> lift_int32 (Int32. mul aa bb)
457
- | Pdivbint _ -> (try lift_int32 (Int32. div aa bb) with _ -> default () )
458
- | Pmodbint _ -> (try lift_int32 (Int32. rem aa bb) with _ -> default () )
459
- | Pandbint _ -> lift_int32 (Int32. logand aa bb)
460
- | Porbint _ -> lift_int32 (Int32. logor aa bb)
461
- | Pxorbint _ -> lift_int32 (Int32. logxor aa bb)
460
+ | Paddbint _ -> Lift. int32 (Int32. add aa bb)
461
+ | Psubbint _ -> Lift. int32 (Int32. sub aa bb)
462
+ | Pmulbint _ -> Lift. int32 (Int32. mul aa bb)
463
+ | Pdivbint _ -> (try Lift. int32 (Int32. div aa bb) with _ -> default () )
464
+ | Pmodbint _ -> (try Lift. int32 (Int32. rem aa bb) with _ -> default () )
465
+ | Pandbint _ -> Lift. int32 (Int32. logand aa bb)
466
+ | Porbint _ -> Lift. int32 (Int32. logor aa bb)
467
+ | Pxorbint _ -> Lift. int32 (Int32. logxor aa bb)
462
468
| _ -> default ()
463
469
end
464
470
| Plslbint Pint32 , Const_base (Const_int32 aa), Const_base (Const_int b)
465
- -> lift_int32 (Int32. shift_left aa b )
471
+ -> Lift. int32 (Int32. shift_left aa b )
466
472
| Plsrbint Pint32 , Const_base (Const_int32 aa), Const_base (Const_int b)
467
- -> lift_int32 (Int32. shift_right_logical aa b )
473
+ -> Lift. int32 (Int32. shift_right_logical aa b )
468
474
| Pasrbint Pint32 , Const_base (Const_int32 aa), Const_base (Const_int b)
469
- -> lift_int32 (Int32. shift_right aa b )
475
+ -> Lift. int32 (Int32. shift_right aa b )
470
476
471
477
| (Paddbint Pint64
472
478
| Psubbint Pint64
@@ -479,28 +485,38 @@ let prim ~primitive:(prim : Prim.t) ~args:(ll : t list) : t =
479
485
), Const_base (Const_int64 aa), Const_base (Const_int64 bb)
480
486
->
481
487
begin match prim with
482
- | Paddbint _ -> lift_int64 (Int64. add aa bb)
483
- | Psubbint _ -> lift_int64 (Int64. sub aa bb)
484
- | Pmulbint _ -> lift_int64 (Int64. mul aa bb)
485
- | Pdivbint _ -> (try lift_int64 (Int64. div aa bb) with _ -> default () )
486
- | Pmodbint _ -> (try lift_int64 (Int64. rem aa bb) with _ -> default () )
487
- | Pandbint _ -> lift_int64 (Int64. logand aa bb)
488
- | Porbint _ -> lift_int64 (Int64. logor aa bb)
489
- | Pxorbint _ -> lift_int64 (Int64. logxor aa bb)
488
+ | Paddbint _ -> Lift. int64 (Int64. add aa bb)
489
+ | Psubbint _ -> Lift. int64 (Int64. sub aa bb)
490
+ | Pmulbint _ -> Lift. int64 (Int64. mul aa bb)
491
+ | Pdivbint _ -> (try Lift. int64 (Int64. div aa bb) with _ -> default () )
492
+ | Pmodbint _ -> (try Lift. int64 (Int64. rem aa bb) with _ -> default () )
493
+ | Pandbint _ -> Lift. int64 (Int64. logand aa bb)
494
+ | Porbint _ -> Lift. int64 (Int64. logor aa bb)
495
+ | Pxorbint _ -> Lift. int64 (Int64. logxor aa bb)
490
496
| _ -> default ()
491
497
end
492
498
| Plslbint Pint64 , Const_base (Const_int64 aa), Const_base (Const_int b)
493
- -> lift_int64 (Int64. shift_left aa b )
499
+ -> Lift. int64 (Int64. shift_left aa b )
494
500
| Plsrbint Pint64 , Const_base (Const_int64 aa), Const_base (Const_int b)
495
- -> lift_int64 (Int64. shift_right_logical aa b )
501
+ -> Lift. int64 (Int64. shift_right_logical aa b )
496
502
| Pasrbint Pint64 , Const_base (Const_int64 aa), Const_base (Const_int b)
497
- -> lift_int64 (Int64. shift_right aa b )
503
+ -> Lift. int64 (Int64. shift_right aa b )
498
504
| Psequand , Const_pointer (a, _), Const_pointer ( b, _)
499
505
->
500
- lift_bool (a = 1 && b = 1 )
506
+ Lift. bool (a = 1 && b = 1 )
501
507
| Psequor , Const_pointer (a, _), Const_pointer ( b, _)
502
508
->
503
- lift_bool (a = 1 || b = 1 )
509
+ Lift. bool (a = 1 || b = 1 )
510
+ | Pstringadd , Const_base (Const_string (a, None )),
511
+ Const_base (Const_string (b,None ))
512
+ ->
513
+ Lift. string (a ^ b)
514
+ | (Pstringrefs | Pstringrefu ), Const_base (Const_string (a,None )),
515
+ (Const_base (Const_int b)| Const_pointer (b,_))
516
+ ->
517
+ begin try Lift. char (String. get a b)
518
+ with _ -> default ()
519
+ end
504
520
| _ -> default ()
505
521
end
506
522
0 commit comments