@@ -337,75 +337,80 @@ 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 )
392
-
397
+ -> Lift. bool (a = 0 )
393
398
| _ -> default ()
394
399
end
395
400
396
401
397
402
| [Lconst a ; Lconst b] ->
398
403
begin match prim, a, b with
399
404
| Pbintcomp (_, cmp), Const_base (Const_int32 a), Const_base (Const_int32 b)
400
- -> lift_bool (comparison cmp a b)
405
+ -> Lift. bool (comparison cmp a b)
401
406
| Pbintcomp (_, cmp), Const_base (Const_int64 a), Const_base (Const_int64 b)
402
- -> lift_bool (comparison cmp a b)
407
+ -> Lift. bool (comparison cmp a b)
403
408
| Pbintcomp (_, cmp), Const_base (Const_nativeint a), Const_base (Const_nativeint b)
404
- -> lift_bool (comparison cmp a b)
409
+ -> Lift. bool (comparison cmp a b)
405
410
| Pfloatcomp cmp, Const_base (Const_nativeint a), Const_base (Const_nativeint b)
406
- -> lift_bool (comparison cmp a b)
411
+ -> Lift. bool (comparison cmp a b)
407
412
| Pintcomp cmp , Const_base (Const_int a), Const_base (Const_int b)
408
- -> lift_bool (comparison cmp a b)
413
+ -> Lift. bool (comparison cmp a b)
409
414
410
415
| (Paddint
411
416
| Psubint
@@ -421,7 +426,7 @@ let prim ~primitive:(prim : Prim.t) ~args:(ll : t list) : t =
421
426
->
422
427
(* WE SHOULD keep it as [int], to preserve types *)
423
428
let aa,bb = Int32. of_int a, Int32. of_int b in
424
- let int_ v = lift_int (Int32. to_int v ) in
429
+ let int_ v = Lift. int (Int32. to_int v ) in
425
430
begin match prim with
426
431
| Paddint -> int_ (Int32. add aa bb)
427
432
| Psubint -> int_ (Int32. sub aa bb)
@@ -451,22 +456,22 @@ let prim ~primitive:(prim : Prim.t) ~args:(ll : t list) : t =
451
456
), Const_base (Const_int32 aa), Const_base (Const_int32 bb)
452
457
->
453
458
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)
459
+ | Paddbint _ -> Lift. int32 (Int32. add aa bb)
460
+ | Psubbint _ -> Lift. int32 (Int32. sub aa bb)
461
+ | Pmulbint _ -> Lift. int32 (Int32. mul aa bb)
462
+ | Pdivbint _ -> (try Lift. int32 (Int32. div aa bb) with _ -> default () )
463
+ | Pmodbint _ -> (try Lift. int32 (Int32. rem aa bb) with _ -> default () )
464
+ | Pandbint _ -> Lift. int32 (Int32. logand aa bb)
465
+ | Porbint _ -> Lift. int32 (Int32. logor aa bb)
466
+ | Pxorbint _ -> Lift. int32 (Int32. logxor aa bb)
462
467
| _ -> default ()
463
468
end
464
469
| Plslbint Pint32 , Const_base (Const_int32 aa), Const_base (Const_int b)
465
- -> lift_int32 (Int32. shift_left aa b )
470
+ -> Lift. int32 (Int32. shift_left aa b )
466
471
| Plsrbint Pint32 , Const_base (Const_int32 aa), Const_base (Const_int b)
467
- -> lift_int32 (Int32. shift_right_logical aa b )
472
+ -> Lift. int32 (Int32. shift_right_logical aa b )
468
473
| Pasrbint Pint32 , Const_base (Const_int32 aa), Const_base (Const_int b)
469
- -> lift_int32 (Int32. shift_right aa b )
474
+ -> Lift. int32 (Int32. shift_right aa b )
470
475
471
476
| (Paddbint Pint64
472
477
| Psubbint Pint64
@@ -479,28 +484,38 @@ let prim ~primitive:(prim : Prim.t) ~args:(ll : t list) : t =
479
484
), Const_base (Const_int64 aa), Const_base (Const_int64 bb)
480
485
->
481
486
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)
487
+ | Paddbint _ -> Lift. int64 (Int64. add aa bb)
488
+ | Psubbint _ -> Lift. int64 (Int64. sub aa bb)
489
+ | Pmulbint _ -> Lift. int64 (Int64. mul aa bb)
490
+ | Pdivbint _ -> (try Lift. int64 (Int64. div aa bb) with _ -> default () )
491
+ | Pmodbint _ -> (try Lift. int64 (Int64. rem aa bb) with _ -> default () )
492
+ | Pandbint _ -> Lift. int64 (Int64. logand aa bb)
493
+ | Porbint _ -> Lift. int64 (Int64. logor aa bb)
494
+ | Pxorbint _ -> Lift. int64 (Int64. logxor aa bb)
490
495
| _ -> default ()
491
496
end
492
497
| Plslbint Pint64 , Const_base (Const_int64 aa), Const_base (Const_int b)
493
- -> lift_int64 (Int64. shift_left aa b )
498
+ -> Lift. int64 (Int64. shift_left aa b )
494
499
| Plsrbint Pint64 , Const_base (Const_int64 aa), Const_base (Const_int b)
495
- -> lift_int64 (Int64. shift_right_logical aa b )
500
+ -> Lift. int64 (Int64. shift_right_logical aa b )
496
501
| Pasrbint Pint64 , Const_base (Const_int64 aa), Const_base (Const_int b)
497
- -> lift_int64 (Int64. shift_right aa b )
502
+ -> Lift. int64 (Int64. shift_right aa b )
498
503
| Psequand , Const_pointer (a, _), Const_pointer ( b, _)
499
504
->
500
- lift_bool (a = 1 && b = 1 )
505
+ Lift. bool (a = 1 && b = 1 )
501
506
| Psequor , Const_pointer (a, _), Const_pointer ( b, _)
502
507
->
503
- lift_bool (a = 1 || b = 1 )
508
+ Lift. bool (a = 1 || b = 1 )
509
+ | Pstringadd , Const_base (Const_string (a, None )),
510
+ Const_base (Const_string (b,None ))
511
+ ->
512
+ Lift. string (a ^ b)
513
+ | (Pstringrefs | Pstringrefu ), Const_base (Const_string (a,None )),
514
+ (Const_base (Const_int b)| Const_pointer (b,_))
515
+ ->
516
+ begin try Lift. char (String. get a b)
517
+ with _ -> default ()
518
+ end
504
519
| _ -> default ()
505
520
end
506
521
@@ -661,7 +676,13 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args : t =
661
676
| Pbigstring_set_16 x -> prim ~primitive: (Pbigstring_set_16 x) ~args
662
677
| Pbigstring_set_32 x -> prim ~primitive: (Pbigstring_set_32 x) ~args
663
678
| Pbigstring_set_64 x -> prim ~primitive: (Pbigstring_set_64 x) ~args
664
- | Pctconst x -> prim ~primitive: (Pctconst x) ~args
679
+ | Pctconst x ->
680
+ begin match x with
681
+ | Word_size ->
682
+ Lift. int 32 (* TODO: documentation*)
683
+ | _ -> prim ~primitive: (Pctconst x) ~args
684
+ end
685
+
665
686
| Pbbswap x -> prim ~primitive: (Pbbswap x) ~args
666
687
| Pcvtbint (a ,b ) -> prim ~primitive: (Pcvtbint (a,b)) ~args
667
688
| Pbintcomp (a ,b ) -> prim ~primitive: (Pbintcomp (a,b)) ~args
0 commit comments