Browse Source

Minor patches for command line compiler

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6470 8c9fc860-2736-0410-a75d-ab315db34111
felixf 9 years ago
parent
commit
3d34517a30

+ 0 - 18
source/Generic.Modules.Mod

@@ -326,22 +326,6 @@ VAR callagain: BOOLEAN;
 PROCEDURE Initialize0*(module: Module);
 VAR new: BOOLEAN;
 BEGIN
-	(*
-	(* don't use trace here, Trace might be uninitialized ! *)
-
-	Trace.String("init module "); Trace.String(module.name); Trace.Ln;
-	module.published := TRUE;
-	module.next := root; root := module;
-	module.refcnt := 0;
-	(*
-		SortProcTable(module);
-		SelectionSort(module.exTable);
-	*)
-	body := SYSTEM.VAL(ADDRESS, module.body);
-	IF module.body # NIL THEN module.body END;
-	module.init := TRUE;
-	*)
-	(*TRACE("TODO", module, module.name);*)
 	Publish (module, new);
 	callagain := FALSE;
 	IF new THEN
@@ -352,9 +336,7 @@ BEGIN
 		IF module.body # NIL THEN module.body END;
 		IF callagain THEN
 			PublishRegisteredModules (* does not return on intel architecture. Returns on ARM but looses procedure stack frame: we are not allowed to refer to local variables after this *)
-			(*; HALT(400)*)
 		ELSE
-			(*TRACE('INITIALIZED', module, module.name);*)
 			module.init := TRUE;
 		END;
 	END;

+ 3 - 0
source/Generic.Win32.Kernel32.Mod

@@ -347,6 +347,8 @@ VAR
 
 	(** The AllocConsole function allocates a new console for the calling process. *)
 	AllocConsole-: PROCEDURE {WINAPI} ( ): BOOL;
+	(** The AttachConsole function attaches the calling process to the console of the specified process. *)
+	AttachConsole-: PROCEDURE {WINAPI} (in: LONGINT): BOOL;
 	(**The Beep function generates simple tones on the speaker. The function is synchronous; it does not return control to its caller until the sound finishes.*)
 	Beep-: PROCEDURE {WINAPI} ( dwFreq, dwDuration: LONGINT ): BOOL;
 	(** The ClearCommBreak function restores character transmission for a specified communications device and places the transmission line in a nonbreak state. *)
@@ -800,6 +802,7 @@ VAR
 		Shutdown := ShutdownP;
 		mod := LoadLibrary("Kernel32.DLL");
 		GetProcAddress(mod, "AllocConsole",SYSTEM.VAL(ADDRESS,AllocConsole));
+		GetProcAddress(mod, "AttachConsole",SYSTEM.VAL(ADDRESS,AttachConsole));
 		GetProcAddress(mod, "Beep",SYSTEM.VAL(ADDRESS,Beep));
 		GetProcAddress(mod, "ClearCommBreak",SYSTEM.VAL(ADDRESS,ClearCommBreak));
 		GetProcAddress(mod, "ClearCommError",SYSTEM.VAL(ADDRESS,ClearCommError));

+ 1 - 1
source/GenericLoader.Mod

@@ -448,7 +448,7 @@ TYPE
 			END;
 
 			IF adr = 0 THEN
-				D.String("Fatal: did not find block in module via fingerprint  "); s := identifier.name; D.String(s); D.Ln;
+				D.String("GenericLoader Fatal error: did not find block "); s := identifier.name; D.String(s); D.Ln;
 				RETURN NIL;
 			ELSE (* found *)
 				importBlock.identifier.fingerprint := identifier.fingerprint; importBlock.address := adr

+ 8 - 6
source/Win32.WinFS.Mod

@@ -827,16 +827,18 @@ VAR
 		p: Files.Parameters; namebuf1, namebuf2: FileName;  size, snum, mlen, sysfl: LONGINT;
 		res: LONGINT; prefix: ARRAY 256 OF CHAR;
 	BEGIN
-		IF (context = NIL) THEN
-			NEW(context, NIL, NIL, NIL, NIL, NIL);
-		END;
-		NEW(p, context.in, context.arg, context.out, context.error, context.caller);
 		COPY(drive,prefix);
 		size := LEN( namebuf1 );  res := Kernel32.GetVolumeInformation( prefix, namebuf1, size, snum, mlen, sysfl, namebuf2, size );
 		IF res = 0 THEN
-			context.error.String("Not mounted (no volume information): "); context.error.String(prefix); context.error.Ln;
-			context.error.Update;
+			IF context# NIL THEN
+				context.error.String("Not mounted (no volume information): "); context.error.String(prefix); context.error.Ln;
+				context.error.Update;
+			END;
 		ELSE
+			IF (context = NIL) THEN
+				NEW(context, NIL, NIL, NIL, NIL, NIL);
+			END;
+			NEW(p, context.in, context.arg, context.out, context.error, context.caller);
 			IF TraceMounting THEN
 				context.out.String( "Mounting: " );  context.out.String( drive );
 				context.out.String( " (" );  context.out.String( namebuf1 );  context.out.String( "), fs = " );

+ 7 - 5
source/Win32.WinTrace.Mod

@@ -13,8 +13,6 @@ PROCEDURE Send* (CONST buf: ARRAY OF CHAR; ofs, len: LONGINT; propagate: BOOLEAN
 BEGIN
 	IF mode # none THEN
 		Kernel32.WriteFile (hout, buf[ofs], len, len, NIL);
-	END;
-	IF mode = file THEN
 		Kernel32.FlushFileBuffers(hout);
 	END;
 END Send;
@@ -34,8 +32,8 @@ PROCEDURE Close*;
 VAR res: LONGINT;
 BEGIN
 	IF mode = console THEN
-		res := Kernel32.FreeConsole ();
 		Kernel32.CloseHandle(hout);
+		res := Kernel32.FreeConsole ();
 	ELSIF mode = file THEN
 		Kernel32.CloseHandle(hout);
 	END;
@@ -46,8 +44,12 @@ END Close;
 PROCEDURE OpenConsole*;
 VAR res: LONGINT;
 BEGIN
-	Close;
-	res := Kernel32.AllocConsole ();
+	IF mode = console THEN RETURN 
+	ELSIF mode = file THEN Close
+	END;
+	IF Kernel32.AttachConsole(-1) = Kernel32.False THEN
+		res := Kernel32.AllocConsole ();
+	END;
 
 	hin := Kernel32.GetStdHandle (Kernel32.STDInput);
 	ASSERT ((hin) # (Kernel32.InvalidHandleValue));