Browse Source

Backing out of implicit import of system libraries: too costly at compile time.
Instead:
Builtin module has new method MkDummyMethodAndInsert to insert base methods in the system object class.
ClassMaker defines a new base method ObjectFeatures.
CompState holds a reference to the emitter, and wraps calls to emitter.ObjectFeatures().
JavaMaker and MsilMaker implement ObjectFeatures as required.

k_john_gough_cp 13 years ago
parent
commit
9b10a8cc4c
9 changed files with 325 additions and 194 deletions
  1. 3 1
      gpcp/Browse.cp
  2. 38 1
      gpcp/Builtin.cp
  3. 1 0
      gpcp/ClassMaker.cp
  4. 12 0
      gpcp/CompState.cp
  5. 220 189
      gpcp/JavaMaker.cp
  6. 32 0
      gpcp/MsilMaker.cp
  7. 9 1
      gpcp/NewSymFileRW.cp
  8. 9 2
      gpcp/RTS.cp
  9. 1 0
      gpcp/Target.cp

+ 3 - 1
gpcp/Browse.cp

@@ -578,7 +578,7 @@ MODULE Browse;
 (* ============================================================ *)
 (* ========		Symbol File Reader		======= *)
 (* ============================================================ *)
-
+(*
   PROCEDURE DiagnoseSymbol();
     VAR arg : ARRAY 24 OF CHAR;
   BEGIN
@@ -639,6 +639,8 @@ MODULE Browse;
     END;
     Console.WriteLn;
   END DiagnoseSymbol;
+*)
+(* ============================================================ *)
 
   PROCEDURE GetSym();
   BEGIN

+ 38 - 1
gpcp/Builtin.cp

@@ -14,7 +14,7 @@ MODULE Builtin;
 	CompState,
 	Symbols,
 	IdDesc,
-        LitValue,
+    LitValue,
 	Typ := TypeDesc;
 
 (* ============================================================ *)
@@ -165,6 +165,43 @@ MODULE Builtin;
     jnk := blk.symTb.enter(tId.hash, tId);
   END MkDummyClass;
 
+(* ------------------------------------------------------------	*)
+
+  PROCEDURE MkDummyMethodAndInsert*(IN namStr : ARRAY OF CHAR;
+                                       prcTyp : TypeDesc.Procedure;
+                                       hostTp : Symbols.Type;
+                                       scope  : IdDesc.BlkId;
+									   access : INTEGER;
+									   rcvFrm : INTEGER;
+                                       mthAtt : SET);
+    VAR mthD : IdDesc.MthId;
+	    recT : TypeDesc.Record;
+	    rcvD : IdDesc.ParId;
+		oldD : IdDesc.OvlId;
+        junk : BOOLEAN;
+  BEGIN
+    recT := hostTp.boundRecTp()(TypeDesc.Record);
+    prcTyp.receiver := hostTp;
+
+    mthD := IdDesc.newMthId();
+	mthD.SetMode(access);
+	mthD.setPrcKind(IdDesc.conMth);
+    mthD.hash := NameHash.enterStr(namStr);
+    mthD.dfScp := scope;
+	mthD.type := prcTyp;
+	mthD.bndType := hostTp;
+	mthD.mthAtt := mthAtt;
+
+    rcvD := IdDesc.newParId();
+    rcvD.varOrd := 0;
+	rcvD.parMod := rcvFrm;
+	rcvD.type := hostTp;
+
+	mthD.rcvFrm := rcvD;
+	TypeDesc.InsertInRec(mthD, recT, TRUE, oldD, junk);
+	Symbols.AppendIdnt(recT.methods, mthD);
+  END MkDummyMethodAndInsert;
+
 (* ------------------------------------------------------------	*)
 
   PROCEDURE MkDummyVar*(IN  nam : ARRAY OF CHAR;

+ 1 - 0
gpcp/ClassMaker.cp

@@ -28,6 +28,7 @@ MODULE ClassMaker;
 (* ============================================================ *)
 
   PROCEDURE (maker : ClassEmitter)Init*(),NEW,EMPTY;
+  PROCEDURE (maker : ClassEmitter)ObjectFeatures*(),NEW,EMPTY;
   PROCEDURE (maker : ClassEmitter)Emit*(),NEW,ABSTRACT;
   PROCEDURE (asmbl : Assembler)Assemble*(),NEW,EMPTY;
 

+ 12 - 0
gpcp/CompState.cp

@@ -22,6 +22,7 @@ MODULE CompState;
         CPascalS,
         NameHash,
         FileNames,
+		ClassMaker,
         CPascalErrors;
 
   CONST	prefix     = "#gpcp: ";
@@ -68,6 +69,7 @@ MODULE CompState;
     lstNam-   : FileNames.NameString;    (* name of the listing file    *)
 
     target-   : ARRAY 4 OF CHAR;
+	emitter-  : ClassMaker.ClassEmitter;
 
     cpSymX-,                             (* User supplied CPSYM name    *)
     binDir-,                             (* PE-file directory .NET only *)
@@ -133,6 +135,16 @@ MODULE CompState;
 	  sysLib := lib;
 	END SetSysLib;
 
+    PROCEDURE SetEmitter*(maker : ClassMaker.ClassEmitter);
+	BEGIN
+	  emitter := maker;
+	END SetEmitter;
+
+	PROCEDURE ImportObjectFeatures*();
+	BEGIN
+	  emitter.ObjectFeatures();
+	END ImportObjectFeatures;
+
     PROCEDURE SetQuiet*(); 
     BEGIN
       CPascalErrors.nowarn := TRUE;

File diff suppressed because it is too large
+ 220 - 189
gpcp/JavaMaker.cp


+ 32 - 0
gpcp/MsilMaker.cp

@@ -198,6 +198,38 @@ MODULE MsilMaker;
     CSt.prgArg := blk;
   END Init;
 
+(* ============================================================ *)
+
+  PROCEDURE (this : MsilEmitter)ObjectFeatures*();
+    VAR prcSig : Ty.Procedure; 
+        thePar : Id.ParId;
+  BEGIN
+	NEW(prcSig);
+    prcSig.retType := CSt.strId.type;
+    Id.InitParSeq(prcSig.formals, 2);
+    Bi.MkDummyMethodAndInsert("ToString", prcSig, CSt.ntvObj, CSt.sysLib, Sy.pubMode, Sy.var, Id.extns);
+
+	NEW(prcSig);
+    prcSig.retType := Bi.intTp;
+    Id.InitParSeq(prcSig.formals, 2);
+    Bi.MkDummyMethodAndInsert("GetHashCode", prcSig, CSt.ntvObj, CSt.sysLib, Sy.pubMode, Sy.var, Id.extns);
+
+	NEW(prcSig);
+    prcSig.retType := CSt.ntvObj;
+    Id.InitParSeq(prcSig.formals, 2);
+    Bi.MkDummyMethodAndInsert("MemberwiseClone", prcSig, CSt.ntvObj, CSt.sysLib, Sy.protect, Sy.var, Id.extns);
+
+	NEW(prcSig);
+	NEW(thePar);
+    prcSig.retType := Bi.boolTp;
+    Id.InitParSeq(prcSig.formals, 2);
+	thePar.parMod := Sy.val;
+	thePar.type := CSt.ntvObj;
+	thePar.varOrd := 1;
+	Id.AppendParam(prcSig.formals, thePar);
+    Builtin.MkDummyMethodAndInsert("Equals", prcSig, CSt.ntvObj, CSt.sysLib, Sy.pubMode, Sy.var, IdDesc.extns);
+  END ObjectFeatures;
+
 (* ============================================================ *)
 
    PROCEDURE (this : MsilEmitter)mkThreadAssign() : Sy.Stmt,NEW; 

+ 9 - 1
gpcp/NewSymFileRW.cp

@@ -2124,7 +2124,6 @@ MODULE NewSymFileRW;
         fScp : ImpResScope;
         rAll : ResolveAll;
   BEGIN
-    D.AppendScope(imps, CSt.sysLib);
    (*
     *  The list of scopes has been constructed by
     *  the parser, while reading the import list.
@@ -2153,6 +2152,15 @@ MODULE NewSymFileRW;
       END;
       INC(indx);
     END;
+   (*
+	* If sysLib has NOT been explicitly imported, then
+	* insert dummy definitions for the native object methods
+	* so that user code may explictly extend RTS.NativeObject
+	* and override these methods.
+	*)
+	IF ~(D.fixd IN CSt.sysLib.xAttr) THEN 
+	  CSt.ImportObjectFeatures();
+	END;
     FOR indx := 0 TO fScp.work.tide-1 DO
       blkI := fScp.work.a[indx](Id.BlkId);
       NEW(rAll);

+ 9 - 2
gpcp/RTS.cp

@@ -20,9 +20,10 @@ SYSTEM MODULE RTS;
       dblPosInfinity-   : REAL;
 
   TYPE  CharOpen*       = POINTER TO ARRAY OF CHAR;
+        CharVector*     = VECTOR OF CHAR;
 
-  TYPE  NativeType*	= POINTER TO ABSTRACT RECORD END;
-        NativeObject*   = POINTER TO ABSTRACT RECORD END;  
+  TYPE  NativeType*     = POINTER TO ABSTRACT RECORD END;
+        NativeObject*   = POINTER TO EXTENSIBLE RECORD END;  
         NativeString*   = POINTER TO RECORD END;
         NativeException*= POINTER TO EXTENSIBLE RECORD END;
 
@@ -102,6 +103,12 @@ SYSTEM MODULE RTS;
                         OUT ok : BOOLEAN);
   (** Parse array into a short REAL *)
 
+  (* ========================================================== *)
+  (* ==============  Operations on Native Types  ============== *)
+  (* ========================================================== *)
+
+  PROCEDURE TypeName*(typ : NativeType) : CharOpen;
+
   (* ========================================================== *)
   (* ============== Operations on Native Strings ============== *)
   (* ========================================================== *)

+ 1 - 0
gpcp/Target.cp

@@ -45,6 +45,7 @@ MODULE Target;
     ELSE
       CompState.Message("Unknown emitter name <" + str + ">");
     END;
+	CompState.SetEmitter(maker);
   END Select;
 
 (* ============================================================ *)

Some files were not shown because too many files changed in this diff