Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Modula 3 > Re: ****ting CM...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 4 Topic 110 of 149
Post > Topic >>

Re: ****ting CM3 to StrongArm-SA1100 - endian problem

by Izo <I@[EMAIL PROTECTED] > Jan 14, 2005 at 08:57 PM

This is a multi-part message in MIME format.
--------------060204040302020705080303
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit



Izo wrote:
> 
> 
> Izo wrote:
> 
>>
>> I want to build std set of cm3 packages .....
> 
> 
> Packages (except of the ones dealing with the graphics, which I do not 
> have/need for my StrongARM system) build OK. Though, I have not yet 
> tested them.

I have tested garbage collection, exception handling and threads using 
attached program. Behaviour on the StrongARM based machine is exactly 
the same as on the LINUXLIBC6 target - I just suppose that this means 
correct behaviour.

Iztok


--------------060204040302020705080303
Content-Type: text/plain;
 name="Main.m3"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="Main.m3"

UNSAFE MODULE Main; (* EX****TS Main; *)
(*IM****T Wr, Stdio;*)
IM****T IO;
IM****T Time;
IM****T Utime;
IM****T Ctypes;
IM****T LongRealRep;
IM****T RealRep;
IM****T Thread;

PROCEDURE DoHello() =
BEGIN
(*  Wr.PutText(Stdio.stdout, "Hello World\n"); *)
  IO.Put("Hello World\n");
END DoHello;

PROCEDURE Calc() =
VAR lr1, lr2, lr3 : LONGREAL;
    r1,  r2, r3 : REAL;
BEGIN
  lr1 := FLOAT(1.234, LONGREAL);
  lr2 := FLOAT(76.234, LONGREAL);
  IO.PutReal(FLOAT(lr1+lr2, REAL));
  IO.PutChar(' ');
  
  lr3 := lr1 + lr2;
  IO.PutReal(FLOAT(lr3, REAL));
  IO.PutChar(' ');
  
  r1 := 1.234;
  r2 := 76.234;
  IO.PutReal(FLOAT(lr1+lr2, REAL));
  IO.PutChar(' ');
  
  r3 := r1 + r2;
  IO.PutReal(r3);
  IO.PutChar(' ');
  
  IO.PutChar('\n');
END Calc;

PROCEDURE CheckTime() =
VAR tv: Utime.struct_timeval;
    tz: Utime.struct_timezone;
    n : Ctypes.int;
    now : LONGREAL;
(*    rep : LongRealRep.T; *)
BEGIN
  FOR i := 0 TO 10 DO
    now := Time.Now();
    n := Utime.gettimeofday(tv,tz);
    
    IO.PutReal(FLOAT(now, REAL));
    IO.Put(" (");
    WITH rep = LOOPHOLE(now, LongRealRep.T) DO
      IO.PutInt(rep.sign); IO.PutChar(' ');
      IO.PutInt(rep.exponent); IO.PutChar(' ');
      IO.PutInt(rep.significand0); IO.PutChar(' ');
      IO.PutInt(rep.significand1); IO.PutChar(' ');
    END;
    IO.Put("), ");
    
    IO.PutInt(tv.tv_sec); IO.PutChar(':'); IO.PutInt(tv.tv_usec);
    IO.Put(", ");
    IO.PutReal(FLOAT(FLOAT(tv.tv_sec, LONGREAL), REAL)); IO.PutChar('+');
      IO.PutReal(FLOAT(FLOAT(tv.tv_usec, LONGREAL) / 1.0D6, REAL));
IO.Put(" or ");
      IO.PutReal(FLOAT(tv.tv_usec, REAL) / FLOAT(1.0D6, REAL));
    IO.PutChar('\n');
  END;
END CheckTime;

PROCEDURE LFloatRep() =
VAR r : REAL;
    lr : LONGREAL;
(*    xr : EXTENDED; *)
    i : INTEGER;
BEGIN
  IO.Put("Float representations of 1E6\n");
  IO.Put("REAL Constant: ");
  IO.PutReal(FLOAT(1.0D6));
  IO.Put(": ");
  WITH rep = LOOPHOLE(FLOAT(1.0D6, REAL), RealRep.T) DO
    IO.PutInt(rep.sign); IO.PutChar(' ');
    IO.PutInt(rep.exponent); IO.PutChar(' ');
    IO.PutInt(rep.significand); IO.PutChar(' ');
  END;
  IO.PutChar('\n');
  
  IO.Put("LONGREAL Constant: ");
  IO.PutReal(FLOAT(1.0D6));
  IO.Put(": ");
  WITH rep = LOOPHOLE(1.0D6, LongRealRep.T) DO
    IO.PutInt(rep.sign); IO.PutChar(' ');
    IO.PutInt(rep.exponent); IO.PutChar(' ');
    IO.PutInt(rep.significand0); IO.PutChar(' ');
    IO.PutInt(rep.significand1); IO.PutChar(' ');
  END;
  IO.PutChar('\n');
  
  IO.Put("REAL: ");
  r := FLOAT(1.0D6);
  IO.PutReal(r);
  IO.Put(": ");
  WITH rep = LOOPHOLE(r, RealRep.T) DO
    IO.PutInt(rep.sign); IO.PutChar(' ');
    IO.PutInt(rep.exponent); IO.PutChar(' ');
    IO.PutInt(rep.significand); IO.PutChar(' ');
  END;
  IO.PutChar('\n');
  
  IO.Put("LONGREAL: ");
  lr := 1.0D6;
  IO.PutReal(FLOAT(lr, REAL));
  IO.Put(": ");
  WITH rep = LOOPHOLE(lr, LongRealRep.T) DO
    IO.PutInt(rep.sign); IO.PutChar(' ');
    IO.PutInt(rep.exponent); IO.PutChar(' ');
    IO.PutInt(rep.significand0); IO.PutChar(' ');
    IO.PutInt(rep.significand1); IO.PutChar(' ');
  END;
  IO.PutChar('\n');

  IO.Put("REAL from INT: ");
  i := 1000000;
  r := FLOAT(i, REAL);
  IO.PutReal(r);
  IO.Put(": ");
  WITH rep = LOOPHOLE(r, RealRep.T) DO
    IO.PutInt(rep.sign); IO.PutChar(' ');
    IO.PutInt(rep.exponent); IO.PutChar(' ');
    IO.PutInt(rep.significand); IO.PutChar(' ');
  END;
  IO.PutChar('\n');
  
END LFloatRep;

PROCEDURE PutGrain() =
BEGIN
  IO.Put("Grain=");
  IO.PutReal(FLOAT(Time.Grain, REAL));
  IO.PutChar('\n');
END PutGrain;


EXCEPTION TestException;

PROCEDURE TryFinallyExcept() RAISES {TestException} =
BEGIN
  TRY
    TRY
      IO.Put("Try - Raise now\n");
      RAISE TestException;
      IO.Put("Try - After Raise\n");
    FINALLY
      IO.Put("Finally\n");
    END;
  EXCEPT
    TestException => IO.Put("Caught TestException\n"); RAISE
TestException;
  ELSE
    IO.Put("Caught Unknown Exception\n");
  END;
END TryFinallyExcept;

TYPE TT = RECORD
            a : CARDINAL;
            b : CHAR;
          END;

PROCEDURE CheckGarbage() =
VAR ptt : REF TT;
    ptt1 : UNTRACED REF TT;
BEGIN
  ptt := NEW(REF TT);
  ptt1 := NEW(UNTRACED REF TT); 
END CheckGarbage;


VAR counter : INTEGER := 0;
CONST C_LIMIT = 50;
PROCEDURE CounterNext() : INTEGER =
BEGIN
  INC(counter);
  RETURN counter-1;
END CounterNext;
PROCEDURE ThreadA(<*UNUSED*> arg: REFANY): REFANY =
BEGIN
 LOOP
  IO.Put("Thread A got ");
  IO.PutInt(CounterNext());
  IO.PutChar('\n');
  IF counter > C_LIMIT THEN EXIT END;
  Thread.Pause(1.123D0);
 END;
 RETURN NEW(REF CHAR);
END ThreadA;
PROCEDURE ThreadB(<*UNUSED*> arg: REFANY): REFANY =
BEGIN
 LOOP
  IO.Put("Thread B got ");
  IO.PutInt(CounterNext());
  IO.PutChar('\n');
  IF counter > C_LIMIT THEN EXIT END;
  Thread.Pause(3.0D0);
 END;
 RETURN NEW(REF CHAR);
END ThreadB;
PROCEDURE CheckThreads() =
VAR threadA, threadB : Thread.T;
    rc : REFANY;
BEGIN
  threadA := Thread.Fork (NEW (Thread.Closure, apply := ThreadA));
  threadB := Thread.Fork (NEW (Thread.Closure, apply := ThreadB));
  rc := Thread.Join(threadB);
END CheckThreads;

BEGIN
  DoHello();
  PutGrain();
  Calc();
  CheckTime();
  LFloatRep();
  TRY
    TryFinallyExcept();
  EXCEPT
    TestException => IO.Put("Caught TestException in Main\n"); (*RAISE
TestException;*)
  ELSE
    IO.Put("Caught Unknown Exception in Main\n");
  END;
  CheckThreads();
  LOOP
    CheckGarbage();
  END;
END Main.

--------------060204040302020705080303--
 




 4 Posts in Topic:
Re: Porting CM3 to StrongArm-SA1100 - endian problem
"Jomu" <drag  2005-01-07 09:47:08 
Re: Porting CM3 to StrongArm-SA1100 - endian problem
Izo <izo@[EMAIL PROTEC  2005-01-07 23:22:18 
Re: Porting CM3 to StrongArm-SA1100 - endian problem
Izo <I@[EMAIL PROTECTE  2005-01-11 09:31:29 
Re: Porting CM3 to StrongArm-SA1100 - endian problem
Izo <I@[EMAIL PROTECTE  2005-01-14 20:57:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 23:49:33 CDT 2008.