Skip to content

Commit

Permalink
MxConfig: Move HOST_OS_TYPE and HOST_WORD_SIZE
Browse files Browse the repository at this point in the history
from constants in generated .i3, to function calls that
delegate to C. This removes system specific backend output.
Granted, these specific ones might be a losing battle,
but they are near the important HOST which will be handled shortly.
Make them return enums usually, but retain TEXT as an option.
That is, before:
 CONST HOST_OS_TYPE: TEXT;
 CONST WORD_SIZE: TEXT;
after:
 TYPE OS_TYPE = {POSIX, WIN32};
 PROCEDURE HOST_OS_TYPE(): OS_TYPE;
 PROCEDURE HOST_OS_TYPE_TEXT(): TEXT;
 PROCEDURE HOST_WORD_SIZE(): INTEGER; (* 32 or 64 *)
 PROCEDURE HOST_WORD_SIZE_TEXT(): TEXT;

And a bunch of Text.Equals goes away.

This is "bad", if a new OS_TYPE is introduced,
causing all consumers to recompile, whereas TEXT
is a never changing always available type, but ok.

Normally I'd name these OsType, WordSize,
OsTypeAsText, WordSizeAsText, maybe with "Get" but probably not,
but keeping fewer names and fewer names through
time helps search. You can continue to search for
os_type and word_size and find all relevant uses and definitions.
  • Loading branch information
jaykrell committed Mar 24, 2021
1 parent 82b047d commit 3921370
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 24 deletions.
6 changes: 3 additions & 3 deletions elego/compactrc/src/MiniEnv.m3
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(*--------------------------------------------------------------------------*)
MODULE MiniEnv;

IMPORT ASCII, Env, MxConfig, Pathname, Text, Process, Rd, Thread;
IMPORT ASCII, Env, MxConfig, Pathname, Process, Rd, Thread;
IMPORT SMsg AS Msg, TextUtils, FSUtils, PathRepr, System;
IMPORT CompactEnvName;
(* IMPORT IO; *)
Expand Down Expand Up @@ -60,8 +60,8 @@ VAR
"/"
};
BEGIN
isPosix := Text.Equal(MxConfig.HOST_OS_TYPE, "POSIX");
isWin32 := Text.Equal(MxConfig.HOST_OS_TYPE, "WIN32");
isPosix := MxConfig.HOST_OS_TYPE() = MxConfig.OS_TYPE.POSIX;
isWin32 := MxConfig.HOST_OS_TYPE() = MxConfig.OS_TYPE.WIN32;

tmpdir := Env.Get("TMPDIR");
IF tmpdir = NIL THEN
Expand Down
6 changes: 3 additions & 3 deletions elego/fileinfo/src/APN.m3
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ PROCEDURE ReplaceExt(pn: T; ext: TEXT): T =

(*--------------------------------------------------------------------------*)
VAR
posix := Text.Equal(MxConfig.HOST_OS_TYPE, "POSIX");
win32 := Text.Equal(MxConfig.HOST_OS_TYPE, "WIN32");
posix := MxConfig.HOST_OS_TYPE() = MxConfig.OS_TYPE.POSIX;
win32 := MxConfig.HOST_OS_TYPE() = MxConfig.OS_TYPE.WIN32;
BEGIN
caseSensitivePathnames := NOT Text.Equal(MxConfig.HOST_OS_TYPE, "WIN32");
caseSensitivePathnames := NOT win32;
END APN.

4 changes: 2 additions & 2 deletions elego/pkg_vc/src/CVS_st.m3
Original file line number Diff line number Diff line change
Expand Up @@ -3611,12 +3611,12 @@ VAR
fileSuffixC := 'a';
nullDev : File.T;
nullDevName : TEXT;
win32 := Text.Equal(MxConfig.HOST_OS_TYPE, "WIN32");
win32 := MxConfig.HOST_OS_TYPE() = MxConfig.OS_TYPE.WIN32;
cvsDisableVM := win32;
tmp : TEXT := NIL;
debugFindCVSFiles := FALSE;
BEGIN
IF Text.Equal(MxConfig.HOST_OS_TYPE, "POSIX") THEN
IF MxConfig.HOST_OS_TYPE() = MxConfig.OS_TYPE.POSIX THEN
nullDevName := "/dev/null";
ELSE
nullDevName := "nul";
Expand Down
2 changes: 1 addition & 1 deletion elego/prjbase/src/ChangeSet.m3
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ PROCEDURE LogText(self : T) : TEXT =

VAR NL := "\n";
BEGIN
IF Text.Equal(MxConfig.HOST_OS_TYPE, "WIN32") THEN
IF MxConfig.HOST_OS_TYPE() = MxConfig.OS_TYPE.WIN32 THEN
NL := "\r\n";
END;
END ChangeSet.
2 changes: 1 addition & 1 deletion elego/prjbase/src/PrjDesc.m3
Original file line number Diff line number Diff line change
Expand Up @@ -2818,7 +2818,7 @@ PROCEDURE InvalidateCachedBuildInfo(self : T) RAISES {Error} =
(*---------------------------------------------------------------------------*)
VAR NL := "\n";
BEGIN
IF Text.Equal(MxConfig.HOST_OS_TYPE, "WIN32") THEN
IF MxConfig.HOST_OS_TYPE() = MxConfig.OS_TYPE.WIN32 THEN
NL := "\r\n";
END;
END PrjDesc.
4 changes: 2 additions & 2 deletions elego/prjbase/src/RCS_Date.m3
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ PROCEDURE FromTime(t: Time.T): T =
PROCEDURE ToTime(d: T): Time.T
RAISES {Error} =
BEGIN
IF Text.Equal(MxConfig.HOST_OS_TYPE, "WIN32") THEN
IF MxConfig.HOST_OS_TYPE() = MxConfig.OS_TYPE.WIN32 THEN
RETURN ToTimeWin32(d);
ELSE
RETURN ToTimePOSIX(d);
Expand All @@ -124,7 +124,7 @@ PROCEDURE ToTime(d: T): Time.T

PROCEDURE ToTimeApprox(d: T): Time.T =
BEGIN
IF Text.Equal(MxConfig.HOST_OS_TYPE, "WIN32") THEN
IF MxConfig.HOST_OS_TYPE() = MxConfig.OS_TYPE.WIN32 THEN
RETURN ToTimeWin32(d, exceptions := FALSE); <* NOWARN *>
ELSE
RETURN ToTimePOSIX(d, exceptions := FALSE); <* NOWARN *>
Expand Down
2 changes: 1 addition & 1 deletion elego/prjbase/src/Snapshots.m3
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ PROCEDURE EverythingUnderVersionControl(self : T) RAISES {Error} =
(*---------------------------------------------------------------------------*)
VAR NL := "\n";
BEGIN
IF Text.Equal(MxConfig.HOST_OS_TYPE, "WIN32") THEN
IF MxConfig.HOST_OS_TYPE() = MxConfig.OS_TYPE.WIN32 THEN
NL := "\r\n";
END;
END Snapshots.
2 changes: 1 addition & 1 deletion m3-obliq/obliqrt/src/Obliq.m3
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ FROM ObValue IMPORT Error, Exception;
TRY
env := NewEnv("hostName", NewText(ObValue.machineAddress), env);
env := NewEnv("target", NewText(MxConfig.HOST), env);
env := NewEnv("osType", NewText(MxConfig.HOST_OS_TYPE), env);
env := NewEnv("osType", NewText(MxConfig.HOST_OS_TYPE_TEXT()), env);
env := NewEnv("pathSep", NewText(MxConfig.HOST_PATH_SEP), env);
env := NewEnv("searchPathSep",
NewText(Text.FromChar(ObPathSep.SearchPathSeparator)),
Expand Down
6 changes: 3 additions & 3 deletions m3-sys/cm3/src/Main.m3
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ VAR defs: TextTextTbl.T;
(* DefineIfNotDefined: overridable from command line with -D *)

DefineIfNotDefined (mach, "TARGET", MxConfig.HOST);
DefineIfNotDefined (mach, "OS_TYPE", MxConfig.HOST_OS_TYPE);
DefineIfNotDefined (mach, "WORD_SIZE", MxConfig.HOST_WORD_SIZE);
DefineIfNotDefined (mach, "OS_TYPE", MxConfig.HOST_OS_TYPE_TEXT());
DefineIfNotDefined (mach, "WORD_SIZE", MxConfig.HOST_WORD_SIZE_TEXT());

(* Even if the config file overrides the defaults, such as to do
a cross build, the host characteristics are still available. *)
Expand All @@ -76,7 +76,7 @@ VAR defs: TextTextTbl.T;
don't make sense to ever override from command line. *)

Quake.Define(mach, "HOST", MxConfig.HOST);
Quake.Define(mach, "HOST_OS_TYPE", MxConfig.HOST_OS_TYPE);
Quake.Define(mach, "HOST_OS_TYPE", MxConfig.HOST_OS_TYPE_TEXT());

(* define the site configuration *)
Msg.Verbose ("EVAL (\"", config, "\")");
Expand Down
9 changes: 7 additions & 2 deletions m3-sys/m3quake/src/MxConfig.i3
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ INTERFACE MxConfig;

IMPORT M3xConfig; (* generated by m3makefile, the ok static part of the former M3Config *)

TYPE OS_TYPE = {POSIX, WIN32};

CONST
Filename = "cm3.cfg";
HOST = M3xConfig.HOST;
HOST_OS_TYPE = M3xConfig.HOST_OS_TYPE;
HOST_WORD_SIZE = M3xConfig.HOST_WORD_SIZE;
HOST_PATH_SEP = M3xConfig.HOST_PATH_SEP;

PROCEDURE HOST_OS_TYPE() : OS_TYPE;
PROCEDURE HOST_OS_TYPE_TEXT() : TEXT;
PROCEDURE HOST_WORD_SIZE() : INTEGER;
PROCEDURE HOST_WORD_SIZE_TEXT() : TEXT;

PROCEDURE FindFile (): TEXT;
(* Returns a path to the current configuration file. If no
configuration file is found, "NIL" is returned. *)
Expand Down
39 changes: 38 additions & 1 deletion m3-sys/m3quake/src/MxConfig.m3
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ MODULE MxConfig;

IMPORT Env, Params, Pathname, M3File, M3ID, Quake, RTIO, Text, Thread;
IMPORT QMachine;
IMPORT MxConfigC;

VAR
mu : MUTEX := NEW (MUTEX);
Expand Down Expand Up @@ -41,7 +42,6 @@ PROCEDURE EnableQuakeTrace() =
trace := TRUE;
END EnableQuakeTrace;


(*----------------------------------------------------------- internal ---*)

PROCEDURE FindConfig () =
Expand Down Expand Up @@ -161,5 +161,42 @@ PROCEDURE ID2Txt (i: Quake.ID): TEXT =
RETURN M3ID.ToText (i);
END ID2Txt;

(* porting: Other OS_TYPESs? *)
PROCEDURE HOST_OS_TYPE() : OS_TYPE =
VAR os_type := MxConfigC.os_type;
BEGIN
<* ASSERT os_type = ORD(OS_TYPE.POSIX) OR os_type = ORD(OS_TYPE.WIN32) *>
RETURN VAL(MxConfigC.os_type, OS_TYPE);
END HOST_OS_TYPE;

(* porting: Other word sizes? *)
(* TODO Generate const TEXT in C. *)
PROCEDURE HOST_OS_TYPE_TEXT() : TEXT =
VAR os_type := HOST_OS_TYPE();
BEGIN
IF os_type = OS_TYPE.WIN32 THEN
RETURN "WIN32";
END;
RETURN "POSIX";
END HOST_OS_TYPE_TEXT;

(* porting *)
PROCEDURE HOST_WORD_SIZE() : INTEGER =
BEGIN
RETURN VAL(MxConfigC.word_size, INTEGER);
END HOST_WORD_SIZE;

(* porting: Other word sizes? *)
(* TODO Generate const TEXT in C. *)
PROCEDURE HOST_WORD_SIZE_TEXT() : TEXT =
VAR wordSize := HOST_WORD_SIZE();
BEGIN
<* ASSERT wordSize = 32 OR wordSize = 64 *>
IF wordSize = 32 THEN
RETURN "32";
END;
RETURN "64";
END HOST_WORD_SIZE_TEXT;

BEGIN
END MxConfig.
19 changes: 19 additions & 0 deletions m3-sys/m3quake/src/MxConfigC.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This file is possibly subject to porting work,
// i.e. if there are systems that are not Win32 or Posix, or
// word sizes other than 32 or 64, etc.
//
// Code should avoid depending on this stuff though too.
#include "m3core.h"

M3_EXTERN_C_BEGIN

// porting: Just Posix and Win32 or more?
#ifdef _WIN32
EXTERN_CONST int MxConfig__os_type = 1;
#else
EXTERN_CONST int MxConfig__os_type = 0;
#endif

EXTERN_CONST int MxConfig__word_size = sizeof(INTEGER) * 8;

M3_EXTERN_C_END
8 changes: 8 additions & 0 deletions m3-sys/m3quake/src/MxConfigC.i3
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
INTERFACE MxConfigC;

IMPORT Ctypes;

<*EXTERNAL "MxConfig__os_type"*> VAR os_type: Ctypes.int; (*MxConfig.OS_TYPE*)
<*EXTERNAL "MxConfig__word_size"*> VAR word_size: Ctypes.int;

END MxConfigC.
4 changes: 2 additions & 2 deletions m3-sys/m3quake/src/m3makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ readonly M3xConfig_body = [
"",
"CONST (* misc. configuration *)",
" HOST = \"" & TARGET & "\";",
" HOST_OS_TYPE = \"" & OS_TYPE & "\";",
" HOST_WORD_SIZE = \"" & WORD_SIZE & "\";",
" HOST_PATH_SEP = \"/\";",
"",
"END M3xConfig."
Expand All @@ -64,6 +62,8 @@ end

derived_interface ("M3xConfig", HIDDEN)

interface("MxConfigC")
c_source("MxConfigC")

build_standalone ()
Library("m3quake")
Expand Down
4 changes: 2 additions & 2 deletions m3-tools/m3tohtml/src/Msg.m3
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MODULE Msg;

IMPORT Wr, Stdio, MxConfig, Text, Process;
IMPORT Wr, Stdio, MxConfig, Process;

PROCEDURE M(a, b, c, d, e, f : TEXT := NIL) =
BEGIN
Expand Down Expand Up @@ -35,7 +35,7 @@ PROCEDURE F(a, b, c, d, e, f : TEXT := NIL) =
VAR
EOL : TEXT := "\n";
BEGIN
IF Text.Equal(MxConfig.HOST_OS_TYPE, "WIN32") THEN
IF MxConfig.HOST_OS_TYPE() = MxConfig.OS_TYPE.WIN32 THEN
EOL := "\r\n";
END;
END Msg.

0 comments on commit 3921370

Please sign in to comment.