@@ -344,31 +344,35 @@ let compile cmd env imports code =
344
344
( env'#push y,
345
345
(* Dynamic check that cmp operators has correct argument types (numbers or pointers) *)
346
346
(match op with
347
- | "==" | "!=" -> [ ]
348
- | " <" | "<=" | ">=" | ">" ->
349
- [Push (eax);
350
- Push (edx);
351
- Mov (y, eax);
352
- Binop (" &&" , L (1 ), eax);
353
- Mov (x, edx);
354
- Binop (" &&" , L (1 ), edx);
355
- Binop (" cmp" , eax, edx);
356
- CJmp (" nz" , " _ERROR2" );
357
- Pop (edx);
358
- Pop (eax)]
359
- (* | "+" | "-" | "*" | "/" -> *)
360
- | _ -> (* Forbid pointer arithmetics *)
361
- [Mov (y, eax);
362
- Binop (" &&" , L (1 ), eax);
363
- Binop (" cmp" , L (0 ), eax);
364
- CJmp (" z" , " _ERROR" );
365
- Mov (x, eax);
366
- Binop (" &&" , L (1 ), eax);
367
- Binop (" cmp" , L (0 ), eax);
368
- CJmp (" z" , " _ERROR" )]
369
- )
370
- (* END: dynamic check *)
371
- @
347
+ | "==" | "!=" -> []
348
+ | "<" | "<=" | ">=" | ">" ->
349
+ [
350
+ Push eax;
351
+ Push edx;
352
+ Mov (y, eax);
353
+ Binop (" &&" , L 1 , eax);
354
+ Mov (x, edx);
355
+ Binop (" &&" , L 1 , edx);
356
+ Binop (" cmp" , eax, edx);
357
+ (* CJmp ("nz", "_ERROR2"); *)
358
+ Pop edx;
359
+ Pop eax;
360
+ ]
361
+ (* | "+" | "-" | "*" | "/" -> *)
362
+ | _ ->
363
+ (* Forbid pointer arithmetics *)
364
+ [
365
+ Mov (y, eax);
366
+ Binop (" &&" , L 1 , eax);
367
+ Binop (" cmp" , L 0 , eax);
368
+ CJmp (" z" , " _ERROR" );
369
+ Mov (x, eax);
370
+ Binop (" &&" , L 1 , eax);
371
+ Binop (" cmp" , L 0 , eax);
372
+ CJmp (" z" , " _ERROR" );
373
+ ])
374
+ (* END: dynamic check *)
375
+ @
372
376
match op with
373
377
| "/" ->
374
378
[
@@ -501,11 +505,11 @@ let compile cmd env imports code =
501
505
in
502
506
names
503
507
@ (if names = [] then []
504
- else
505
- [
506
- Meta
507
- (Printf. sprintf " \t .stabn 192,0,0,%s-%s" scope.blab f);
508
- ])
508
+ else
509
+ [
510
+ Meta
511
+ (Printf. sprintf " \t .stabn 192,0,0,%s-%s" scope.blab f);
512
+ ])
509
513
@ (List. flatten @@ List. map stabs_scope scope.subs)
510
514
@
511
515
if names = [] then []
@@ -525,38 +529,38 @@ let compile cmd env imports code =
525
529
( env,
526
530
[ Meta (Printf. sprintf " \t .type %s, @function" name) ]
527
531
@ (if f = " main" then []
528
- else
529
- [
530
- Meta
531
- (Printf. sprintf " \t .stabs \" %s:F1\" ,36,0,0,%s" name f);
532
- ]
533
- @ List. mapi
534
- (fun i a ->
535
- Meta
536
- (Printf. sprintf " \t .stabs \" %s:p1\" ,160,0,0,%d" a
537
- ((i * 4 ) + 8 )))
538
- args
539
- @ List. flatten
540
- @@ List. map stabs_scope scopes)
532
+ else
533
+ [
534
+ Meta
535
+ (Printf. sprintf " \t .stabs \" %s:F1\" ,36,0,0,%s" name f);
536
+ ]
537
+ @ List. mapi
538
+ (fun i a ->
539
+ Meta
540
+ (Printf. sprintf " \t .stabs \" %s:p1\" ,160,0,0,%d" a
541
+ ((i * 4 ) + 8 )))
542
+ args
543
+ @ List. flatten
544
+ @@ List. map stabs_scope scopes)
541
545
@ [ Meta " \t .cfi_startproc" ]
542
546
@ (if has_closure then [ Push edx ] else [] )
543
547
(* TODO: WTF ?!? *)
544
548
@ (if f = cmd#topname then
545
- [
546
- Mov (M " _init" , eax);
547
- Binop (" test" , eax, eax);
548
- CJmp (" z" , " _continue" );
549
- Ret ;
550
- Label " _ERROR" ;
551
- Call " Lbinoperror" ;
552
- Ret ;
553
- Label " _ERROR2" ;
554
- Call " Lbinoperror2" ;
555
- Ret ;
556
- Label " _continue" ;
557
- Mov (L 1 , M " _init" );
558
- ]
559
- else [] )
549
+ [
550
+ Mov (M " _init" , eax);
551
+ Binop (" test" , eax, eax);
552
+ CJmp (" z" , " _continue" );
553
+ Ret ;
554
+ Label " _ERROR" ;
555
+ Call " Lbinoperror" ;
556
+ Ret ;
557
+ Label " _ERROR2" ;
558
+ Call " Lbinoperror2" ;
559
+ Ret ;
560
+ Label " _continue" ;
561
+ Mov (L 1 , M " _init" );
562
+ ]
563
+ else [] )
560
564
@ [
561
565
Push ebp;
562
566
Meta
@@ -574,14 +578,14 @@ let compile cmd env imports code =
574
578
Repmovsl ;
575
579
]
576
580
@ (if f = " main" then
577
- [
578
- Call " __gc_init" ;
579
- Push (I (12 , ebp));
580
- Push (I (8 , ebp));
581
- Call " set_args" ;
582
- Binop (" +" , L 8 , esp);
583
- ]
584
- else [] )
581
+ [
582
+ Call " __gc_init" ;
583
+ Push (I (12 , ebp));
584
+ Push (I (8 , ebp));
585
+ Call " set_args" ;
586
+ Binop (" +" , L 8 , esp);
587
+ ]
588
+ else [] )
585
589
@
586
590
if f = cmd#topname then
587
591
List. map
@@ -904,8 +908,8 @@ class env prg =
904
908
[ Meta (Printf. sprintf " \t .stabn 68,0,%d,%s" line lab); Label lab ]
905
909
else
906
910
(if first_line then
907
- [ Meta (Printf. sprintf " \t .stabn 68,0,%d,0" line) ]
908
- else [] )
911
+ [ Meta (Printf. sprintf " \t .stabn 68,0,%d,0" line) ]
912
+ else [] )
909
913
@ [
910
914
Meta (Printf. sprintf " \t .stabn 68,0,%d,%s-%s" line lab fname);
911
915
Label lab;
0 commit comments