Commissioning

The compiler costs money. A reasonable amount, so it's not the end of the world, but still, if you pay for something, you want to see how it runs. IF it runs at all. So I decided to try and compile some sources with it and see how it fares.
I knew this, but I refound it again: Mocka is a fine compiler, but it deviates from the standard in quite a few ways. So the first few tests failed. The MHC compiler is more like the FST compiler than line Mocka. Still, I managed to dig up some interesting sources to test.

Fractions

Part of the PIM book that I have on my shelf is this program, called 'Fractions'. Here is the source:

MODULE Fractions;

FROM  InOut  IMPORT  Write, WriteLn, WriteString, WriteInt;
  
CONST  Base = 10;
          N = 32;


VAR    i, j, m, rem       : INTEGER;
       d                  : ARRAY [1..N] OF INTEGER;
       x                  : ARRAY [0..N] OF INTEGER;
			 

BEGIN
   FOR i := 2 TO N DO
      FOR j := 0 TO i - 1 DO  x[j] := 0  END;
      m := 0;
      rem := 1;
      REPEAT
         INC (m);
	 x[rem] := m;	 
         rem := Base * rem;
	 d[m] := rem DIV i;
	 rem := rem MOD i
      UNTIL x[rem] # 0;
      WriteInt (i, 6);
      WriteString (" 0.");
      FOR  j := 1  TO  x[rem] - 1  DO  Write (CHR (d[j] + ORD ("0")))  END;
      Write ("'");
      FOR  j := x[rem]  TO  m  DO  Write (CHR (d[j] + ORD ("0")))  END;
      WriteLn
   END
END Fractions.
   
This program shows the repeating decimals in a fraction. As we know, 1/3 comes down to 1.3333 with an infinte number of 3's. This program noties it as 0.'3 where everything between the ' and the end of line is repeated indefinitely.

First we compile it with Mocka to make a Linux executable and run it:
jan@Beryllium:~/modula/Wirth/PIM$ mocka
Mocka 0608m
>> p Fractions
.. Compiling Program Module Fractions I/0001 II/0001
.. Linking Fractions
>> q
jan@Beryllium:~/modula/Wirth/PIM$ Fractions
     2 0.5'0
     3 0.'3
     4 0.25'0
     5 0.2'0
     6 0.1'6
     7 0.'142857
     8 0.125'0
     9 0.'1
    10 0.1'0
    11 0.'09
    12 0.08'3
    13 0.'076923
    14 0.0'714285
    15 0.0'6
    16 0.0625'0
    17 0.'0588235294117647
    18 0.0'5
    19 0.'052631578947368421
    20 0.05'0
    21 0.'047619
    22 0.0'45
    23 0.'0434782608695652173913
    24 0.041'6
    25 0.04'0
    26 0.0'384615
    27 0.'037
    28 0.03'571428
    29 0.'0344827586206896551724137931
    30 0.0'3
    31 0.'032258064516129
    32 0.03125'0
jan@Beryllium:~/modula/Wirth/PIM$
   
Well, this seems to do the trick. No see how the Java compiler version does it:
jan@Beryllium:~/modula/Wirth/PIM$ mhc Fractions
Modula-2 2.5.67 (c) 1998-2006 J.Neuhoff (www.mhccorp.com)
Unlicenced time-limited evaluation version
Compiling: /home/com.mhccorp/mhc/runtime/mod/SYSTEM.mod
Compiling: /home/com.mhccorp/mhc/runtime/mod/FileSystem.def
Compiling: /home/com.mhccorp/mhc/runtime/mod/Strings.def
Compiling: /home/com.mhccorp/mhc/runtime/mod/Strings.mod
Compiling: /home/com.mhccorp/mhc/runtime/mod/FileSystem.mod
Compiling: /home/com.mhccorp/mhc/runtime/mod/InOut.def
Compiling: /home/com.mhccorp/mhc/runtime/mod/Conversions.def
Compiling: /home/com.mhccorp/mhc/runtime/mod/Conversions.mod
Compiling: /home/com.mhccorp/mhc/runtime/mod/InOut.mod
Compiling: Fractions.mod
Compilation done: Fractions.mod
jan@Beryllium:~/modula/Wirth/PIM$ javac *.java
SYSTEM.java:1095: warning: non-varargs call of varargs method with inexact argument type for last parameter;
cast to java.lang.Object for a varargs call
cast to java.lang.Object[] for a non-varargs call and to suppress this warning
            arrayobj[i] = clone_method.invoke( arrayobj[i], null );
                                                            ^
Note: SYSTEM.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 warning
jan@Beryllium:~/modula/Wirth/PIM$ java Fractions
     2 0.5'0
     3 0.'3
     4 0.25'0
     5 0.2'0
     6 0.1'6
     7 0.'142857
     8 0.125'0
     9 0.'1
    10 0.1'0
    11 0.'09
    12 0.08'3
    13 0.'076923
    14 0.0'714285
    15 0.0'6
    16 0.0625'0
    17 0.'0588235294117647
    18 0.0'5
    19 0.'052631578947368421
    20 0.05'0
    21 0.'047619
    22 0.0'45
    23 0.'0434782608695652173913
    24 0.041'6
    25 0.04'0
    26 0.0'384615
    27 0.'037
    28 0.03'571428
    29 0.'0344827586206896551724137931
    30 0.0'3
    31 0.'032258064516129
    32 0.03125'0
jan@Beryllium:~/modula/Wirth/PIM$
   
Not too bad eh? The java compiler issues a warning but it does not seem to be too heavy.

Page created on 27 June 2010 and

Page equipped with FroogleBuster technology