Module Simula

Class RTS_RTObject

java.lang.Object
simula.runtime.RTS_RTObject
Direct Known Subclasses:
RTS_ENVIRONMENT, RTS_TEXTOBJ

public abstract class RTS_RTObject extends Object
This class is the main superclass used to form all other Simula classes

Link to GitHub: Source File.

Author:
Øystein Myhre Andersen
  • Field Details

    • _INPUT_LINELENGTH

      static final int _INPUT_LINELENGTH
      The default input line length. I.e. BASICIO'INPUT_LINELENGTH
      See Also:
    • _OUTPUT_LINELENGTH

      static final int _OUTPUT_LINELENGTH
      The default output line length. I.e. BASICIO'OUTPUT_LINELENGTH
      See Also:
    • _SYSIN

      static RTS_Infile _SYSIN
      The variable SYSIN.
    • _SYSOUT

      public static RTS_Printfile _SYSOUT
      The intenal pointer to sysout.
    • startTimeMs

      private static long startTimeMs
      Execution stat time in millis
    • _STATE

      This object's Operational State.
      See Also:
    • _CORUT

      public RTS_Coroutine _CORUT
      This is a pointer to the Coroutine in which this block instance is running.
      If this block instance is detached it is used to save the complete reactivation point (call stack and the continuation point).
    • _CTX

      public static final RTS_BASICIO _CTX
      Outmost Block Instance
    • _CUR

      public static RTS_RTObject _CUR
      Current Block Instance
    • _JTX

      public int _JTX
      Jump Table Index used by _STM()
    • _SL

      public RTS_RTObject _SL
      This is a pointer to the object of the nearest textually enclosing block instance, also called 'static link'.
    • _DL

      If this block instance is attached this is a pointer to the object of the block instance to which the instance is attached (also called dynamic link), i.e. it points to the block instance which called this one.
    • NOTEXT

      public static final RTS_TXT NOTEXT
      Utility constant NOTEXT
  • Constructor Details

    • RTS_RTObject

      public RTS_RTObject(RTS_RTObject SL)
      Constructor
      Parameters:
      SL - Static Link, may be null when creating CONTEXT, TEXTOBJ and TXTREF
  • Method Details

    • sysin

      public static RTS_Infile sysin()
      Implementation of Simula's Procedure sysin.
      Returns:
      a pointer to _SYSIN
    • sysout

      public static RTS_Printfile sysout()
      Implementation of Simula's Procedure sysout.
      Returns:
      a pointer to _SYSOUT
    • isQPSystemBlock

      public boolean isQPSystemBlock()
      This is a static property generated by the compiler.
      It will return true for Block or Prefixed Block with local classes.
      This method is redefined in every subclass which represent a Simula Block.
      Returns:
      true: this object is a QPS System block
    • isDetachUsed

      public boolean isDetachUsed()
      This is a static property generated by the compiler.
      It will return true for Blocks in which 'detach' is used.
      This method is redefined in every subclass which represent a Simula Block.
      Returns:
      true: this object is a QPS System block
    • arrayValue

      public RTS_ARRAY arrayValue(Object par)
      Utility method to support Parameter Transmission in case of Formal/Virtual Procedure Call.

      If the parameter is 'by name' the parameter is evaluated.

      See simula.compiler.declaration.ProcedureDeclaration#doCodePrepareFormal

      Parameters:
      par - an Object
      Returns:
      a RTS_ARRAY value
    • procValue

      public RTS_PRCQNT procValue(Object par)
      Utility method to support Parameter Transmission in case of Formal/Virtual Procedure Call.

      If the parameter is 'by name' the parameter is evaluated.

      See simula.compiler.declaration.ProcedureDeclaration#doCodePrepareFormal

      Parameters:
      par - an Object
      Returns:
      a RTS_PRCQNT value
    • objectValue

      public Object objectValue(Object par)
      Utility method to support Parameter Transmission in case of Formal/Virtual Procedure Call.

      If the parameter is 'by name' the parameter is evaluated.

      If the parameter is a RTS_PRCQNT that procedure is called

      See simula.compiler.declaration.ProcedureDeclaration#doCodePrepareFormal

      Parameters:
      par - an Object
      Returns:
      a Object value
    • intValue

      public int intValue(Object par)
      Utility method to support Parameter Transmission in case of Formal/Virtual Procedure Call.

      If the parameter is 'by name' the parameter is evaluated.

      If the parameter is a _PRCQNT that procedure is called

      If the parameter is a Float or Double they are casted to Integer

      See simula.compiler.declaration.ProcedureDeclaration#doCodePrepareFormal

      Parameters:
      par - an Object
      Returns:
      an Integer value
    • floatValue

      public float floatValue(Object par)
      Utility method to support Parameter Transmission in case of Formal/Virtual Procedure Call.

      If the parameter is 'by name' the parameter is evaluated.

      If the parameter is a _PRCQNT that procedure is called

      If the parameter is a Integer or Double they are casted to Float

      See simula.compiler.declaration.ProcedureDeclaration#doCodePrepareFormal

      Parameters:
      par - an Object
      Returns:
      a Float value
    • doubleValue

      public double doubleValue(Object par)
      Utility method to support Parameter Transmission in case of Formal/Virtual Procedure Call.

      If the parameter is 'by name' the parameter is evaluated.

      If the parameter is a _PRCQNT that procedure is called

      If the parameter is an Integer or Float they are casted to Double

      See simula.compiler.declaration.ProcedureDeclaration#doCodePrepareFormal

      Parameters:
      par - an Object
      Returns:
      a Double value
    • copy

      public static RTS_TXT copy(RTS_TXT T)
       text procedure copy(T); text T;
                  if T =/= notext
                  then begin text U;
                     U.OBJ    :- new TEXTOBJ(T.LENGTH,false);
                     U.START  := 1;
                     U.LENGTH := T.LENGTH;
                     U.POS    := 1;
                     U        := T;
                     copy     :- U
                  end copy;
       
      "copy(T)", with T =/= notext, references a new alterable main frame which contains a text value identical to that of T.
      Parameters:
      T - the text object to be copied
      Returns:
      a copy of T
    • CONC

      public RTS_TXT CONC(RTS_TXT T1, RTS_TXT T2)
      The operator & permits text concatenation.
      Parameters:
      T1 - the first text to be concatenated
      T2 - the second text to be concatenated
      Returns:
      the concatenated text
    • blanks

      public static RTS_TXT blanks(int n)
       text procedure blanks(n); integer n;
                  if        n < 0 then error("..." ! Parm. to blanks < 0;)
                  else if   n > 0
                  then begin text T;
                     T.OBJ    :- new TEXTOBJ(n,false);
                     T.START  := 1;
                     T.LENGTH := n;
                     T.POS    := 1;
                     T        := notext;    ! blank-fill, see 4.1.2;
                     blanks   :- T
                  end blanks;
       
      "blanks(n)", with n > 0, references a new alterable main frame of length n, containing only blank characters. "blanks(0)" references notext.
      Parameters:
      n - the number of space characters
      Returns:
      a text object conraining n space characters
    • _ASGTXT

      public static RTS_TXT _ASGTXT(RTS_TXT T, RTS_TXT U)
      Text value assignment.
      Parameters:
      T - the from text
      U - the target text
      Returns:
      the resulting text
    • _ASGSTR

      public RTS_TXT _ASGSTR(RTS_TXT T, String s)
      Text value assignment from String.
      Parameters:
      T - the from text
      s - the target text
      Returns:
      the resulting text
    • _TXTREL_LT

      public static boolean _TXTREL_LT(RTS_TXT left, RTS_TXT right)
      Text value relation - LT
      Parameters:
      left - left hand side
      right - right hand side
      Returns:
      true if relation holds
    • _TXTREL_EQ

      public boolean _TXTREL_EQ(RTS_TXT left, RTS_TXT right)
      Text value relation - EQ
      Parameters:
      left - left hand side
      right - right hand side
      Returns:
      true if relation holds
    • _TXTREL_LE

      public boolean _TXTREL_LE(RTS_TXT left, RTS_TXT right)
      Text value relation - LE
      Parameters:
      left - left hand side
      right - right hand side
      Returns:
      true if relation holds
    • _TXTREL_GT

      public boolean _TXTREL_GT(RTS_TXT left, RTS_TXT right)
      Text value relation - GT
      Parameters:
      left - left hand side
      right - right hand side
      Returns:
      true if relation holds
    • _TXTREL_NE

      public boolean _TXTREL_NE(RTS_TXT left, RTS_TXT right)
      Text value relation - NE
      Parameters:
      left - left hand side
      right - right hand side
      Returns:
      true if relation holds
    • _TXTREL_GE

      public boolean _TXTREL_GE(RTS_TXT left, RTS_TXT right)
      Text value relation - GE
      Parameters:
      left - left hand side
      right - right hand side
      Returns:
      true if relation holds
    • TXTREL

      private static boolean TXTREL(RTS_TXT left, RTS_TXT right, int code)
      Text value relation
      Parameters:
      left - left hand side
      right - right hand side
      code - relational code
      Returns:
      true if relation holds
    • TRF_EQ

      public boolean TRF_EQ(RTS_TXT left, RTS_TXT right)
      Text reference equal relation
      Parameters:
      left - left hand side
      right - right hand side
      Returns:
      true if relation holds
    • TRF_NE

      public boolean TRF_NE(RTS_TXT left, RTS_TXT right)
      Text reference not equal relation
      Parameters:
      left - left hand side
      right - right hand side
      Returns:
      true if relation holds
    • _VALUE

      public boolean _VALUE(boolean cond)
      Used in Conditional Statement to prevent 'dead code removal'.
      Parameters:
      cond - a boolean condition
      Returns:
      the same conditional
    • _PRE_LABEL

      public static void _PRE_LABEL()
      Method meant for Byte-Code Engineering.
      During Byte-Code Engineering this method-call is used to signal the occurrence of a Simula Label.
    • _LABEL

      public static void _LABEL(int labelIndex, String ident)
      Method meant for Byte-Code Engineering.
      During Byte-Code Engineering this method-call is used to signal the occurrence of a Simula Label. The bytecode address is collected and some instruction are removed. The parameter 'labelIndex' is the label's ordinal number.

      deprecated This method will be removed when java.lang.classfile becomes available.

      Parameters:
      labelIndex - the label's ordinal number.
      ident - the label's identifier
    • _SIM_LABEL

      public static void _SIM_LABEL(int labelIndex)
      Method meant for Byte-Code Engineering.
      During Byte-Code Engineering this method-call is used to signal the occurrence of a Simula Label. A pseudo label instruction is added some instruction are removed. The parameter 'labelIndex' is the label's ordinal number.
      Parameters:
      labelIndex - the label's ordinal number.
    • _PRE_TABLE

      public static void _PRE_TABLE()
      Method meant for Byte-Code Engineering.
      This method-call is a placeholder for where to put in a Jump-Table.
      See Mapping Simula to Java (runtime design) Sect. 6.1.2 Byte Code Engineering.
    • _JUMPTABLE

      public static void _JUMPTABLE(int labelIndex, int tableSize)
      Method meant for Byte-Code Engineering.
      This method-call is a placeholder for where to put in a Jump-Table.
      See Mapping Simula to Java (runtime design) Sect. 6.1.2 Byte Code Engineering.
      Parameters:
      labelIndex - the label index
      tableSize - the jumptable size
    • _JUMPTABLE

      public static void _JUMPTABLE(int labelIndex)
      Method meant for Byte-Code Engineering.

      deprecated This method will be removed when java.lang.classfile becomes available.

      Parameters:
      labelIndex - the label index
    • _GOTO

      public void _GOTO(RTS_RTObject.RTS_LABEL q)
      Utility method to avoid Java-error: "Unreachable code" after GOTO
      Parameters:
      q - the RTS_LABEL
    • TRACE_GOTO

      public static void TRACE_GOTO(String msg, RTS_RTObject.RTS_LABEL label)
      Utility method to trace GOTO Statements
      Parameters:
      msg - a descriptive message
      label - the label quant
    • getErrorMessage

      public static String getErrorMessage(Throwable e)
      Utility to convert a Throwable message to Simula message.
      Parameters:
      e - a Throwable
      Returns:
      converted message
    • terminate_program

      public static void terminate_program()
      Implementation of Simula's Procedure terminate_program.
    • BPRG

      public void BPRG(String ident)
      The begin program routine (BPRG) is the runtime system initialization routine. It will initiate the global data in the runtime system.
      Parameters:
      ident - the program identifier
    • BBLK

      public void BBLK()
      This routine is used to initiate a block instance. Its functions are:
      • Attach the block to its dynamic environment.
      • Update the current instance pointer(_CUR).
    • EBLK

      public void EBLK()
      End Block.

      This routine is used to terminate a block instance when control passes through the final end (of the outermost prefix for class and prefixed block).

      According to the different categories of block instances, we have the following cases:

      • Terminate prefixed block instance.

        Update the '_CUR' pointer and return to Compiler generated code.

      • Terminate class instance.

        The object is marked 'terminated' and the '_CUR' pointer is updated.

      If the class instance is detached: The instance is marked as terminated. The sub-block or prefixed block representing the quasiparallel system of which the instance was a component is located. The main program of the system is then 'resumed'.

      Finally; Yield continuation and return to Compiler generated code.

      However; If the program passes through its final end sysout.outimage is called. The the entire program is terminated.

    • detach

      public void detach()
      Standard procedure 'detach'.

      Consider a call of the detach attribute of a block instance X.

      If X is an instance of a prefixed block the detach statement has no effect. Assume that X is a class object. The following cases arise:

      1. X is an attached object.
        If X is not operating the detach statement constitutes an error. Assume X is operating. The effect of the detach statement is:
        • X becomes detached and thereby (the head of) a new non-operative object component, its reactivation point positioned immediately after the detach statement. As a consequence, that part of the operating chain which is dynamically enclosed by X becomes the (non-operating) reactivation chain of X.
        • The PSC returns to the block instance to which X was attached and execution continues immediately after the associated object generator or call statement (see 7.3.2).
        If X is local to a system head, the new component becomes a member of the associated system. It is a consequence of the language definition that, prior to the execution of the detach statement, X was dynamically enclosed by the head of the operative component of this system. The operative component remains operative.
      2. X is a detached object.
        The detach statement then constitutes an error.
      3. X is a resumed object.
        X is then (the head of) an operative system component. Let S be the associated system. It is a consequence of the language definition that X must be operating. The effect of the detach statement is:
        • X enters the detached state and becomes non-operative, its reactivation point positioned immediately after the detach statement. As a consequence, that part of the operating chain which is dynamically enclosed by X becomes the (non-operating) reactivation chain of X.
        • The PSC is moved to the current reactivation point of the main component of S, whereby this main component becomes operative and operating. As a consequence, all block instances on the reactivation chain of the main component also become operating.
      4. X is a terminated object.
        The detach statement then constitutes an error.
    • detach

      public static void detach(RTS_RTObject SL)
      Parameters:
      SL - The object to be Detached
    • detach

      public void detach(int sourceLine)
      Parameters:
      sourceLine - the sourceline of the call
    • call

      public void call(RTS_RTObject ins)
      Standard procedure 'call'.

      "call" is formally a procedure with one object reference parameter qualified by a fictitious class 'CLASS' including all classes. Let Y denote the object referenced by a call statement.

      If Y is terminated, attached or resumed, or Y == none, the call statement constitutes an error.

      Assume Y is a detached object. The effect of the call statement is:

      • Y becomes attached to the block instance containing the call statement, whereby Y loses its status as a component head. As a consequence the system to which Y belongs (if any) loses the associated component.
      • The PSC is moved to the (former) reactivation point of Y. As a consequence, all block instances on the reactivation chain of Y become operating.
      Parameters:
      ins - The object to be Called (Coroutine)
    • call

      public void call(RTS_RTObject ins, int sourceLine)
      Parameters:
      ins - The object to be Called (Coroutine)
      sourceLine - the sourceline of the call
    • resume

      public void resume(RTS_RTObject ins)

      "resume" is formally a procedure with one object reference parameter qualified by a fictitious class 'CLASS' including all classes. Let Y denote the object referenced by a resume statement.

      If Y is not local to a system head, i.e. if Y is local to a class object or an instance of a procedure body, the resume statement constitutes an error.

      If Y is terminated or attached, or Y==none, the resume statement constitutes an error.

      If Y is a resumed object, the resume statement has no effect (it is a consequence of the language definition that Y must then be operating.)

      Assume Y is a detached object being (the head of) a non-operative system component. Let S be the associated system and let X denote (the head of) the current operative component of S. It is a consequence of the language definition that X must be operating, and that X is either the main component of S or local to the head of S. The effect of the resume statement is:

      • X becomes non-operative, its reactivation point positioned immediately after the resume statement. As a consequence, that part of the operating chain which is dynamically enclosed by X becomes the (non-operating) reactivation chain of X. If X is an object component its head enters the detached state.
      • The PSC is moved to the reactivation point of Y, whereby Y enters the resumed state and becomes operative and operating. As a consequence, all block instances on the reactivation chain of Y also become operating.
      Parameters:
      ins - The object to be Resumed
    • resume

      public void resume(RTS_RTObject ins, int sourceLine)
      Parameters:
      ins - The object to be Resumed
      sourceLine - the sourceline of the call
    • resume

      public void resume(RTS_RTObject ins, boolean doSwap)
      Parameters:
      ins - The object to be Resumed
      doSwap - decides whether Coroutines should be swapped
    • _STM

      public RTS_RTObject _STM()
      Method representing the Statements in this Block
      This method is virtual and must be redefined in blocks.
      Returns:
      a pointer to this _RTObject
    • endProgram

      private static void endProgram(int exitValue)
      End of Simula program execution.
      Parameters:
      exitValue - the exit value
    • swapCoroutines

      static void swapCoroutines()
      Utility: Swap Coroutines.
    • objectTraceIdentifier

      public static RTS_TXT objectTraceIdentifier(RTS_RTObject staticLink)
      Utility to support trace and debugging.

      An edited string identifier of the static link object is formed.

      Parameters:
      staticLink - a reference to the static link object
      Returns:
      an edited string
    • objectTraceIdentifier

      public RTS_TXT objectTraceIdentifier()
      Utility to support trace and debugging.

      An edited string identifier of this object is formed.

      Returns:
      an edited string
    • edObjectIdent

      public String edObjectIdent()
      Utility to support trace and debugging.

      An edited string identifier of this object's class is formed.

      Returns:
      an edited string
    • edObjectAttributes

      public String edObjectAttributes()
      Utility to support trace and debugging.

      An edited string identifier of this object's main attributes is formed.

      Returns:
      an edited string
    • toString

      public String toString()
      Returns a string representation of the object.
      Overrides:
      toString in class Object