[Oberon] Procedure Types (was: objects and jewels)

Chris Burrows chris at cfbsoftware.com
Thu Feb 21 08:27:40 CET 2013


> -----Original Message-----
> From: Frans-Pieter Vonck [mailto:fp at vonck.nl]
> Sent: Thursday, 21 February 2013 3:29 AM
> To: chris at cfbsoftware.com; ETH Oberon and related systems
> Subject: Re: [Oberon] objects and jewels
> 
> I remember in the module Serial you used procedure types for writing to
> the UART0. The LPC2148 has two uarts and I adpted the code in a new module
> to use the other UART. Now I understand procedure types are a way to
> select the desired IO device. Do I recall correctly that you rewrote
> Serial to meet this flexibility?
> 

Something like that - it is a good simple example of the usefulness of
Procedure types. PutCh is a procedure variable declared in the general
purpose Astrobe output module 'Out'. It is expected to write one character
to an arbitrary output device and is defined as:

TYPE 
  PutCharProc* = PROCEDURE (ch: CHAR);
  
VAR
  PutCh: PutCharProc;

There is an Init procedure in the Out module which can be used to assign the
actual procedure at runtime:

  PROCEDURE Init*(p: PutCharProc);
  BEGIN
    PutCh := p
  END Init;

If the programmer wants to send all subsequent output (e.g. using Out.Int,
Out.String etc) from an application to UART0 (e.g. to send to a PC via a COM
port), all he has to do first is call:

  Out.Init(Serial.PutCh)

Similarly, if he later wants to redirect all subsequent output to a
Nokia-style LCD display connected to the microcontroller he just has to
call:

  Out.Init(Display.PutCh)

Regards,
Chris

--
Chris Burrows
CFB Software
http://www.astrobe.com





 




More information about the Oberon mailing list