tmg icon indicating copy to clipboard operation
tmg copied to clipboard

nt build

Open bpotvin opened this issue 4 years ago • 3 comments

You mentioned preparing a windows build in your readme. I wanted to let you know that it built ok for me using the Microsoft 32-bit compiler (19.16.27040). There were two changes that I made:

  • the symbol_t struct in tmgc.h has a gcc-specific packed attribute that I ifdef'd on _MSC_VER, using a pack,1 pragma for msc, otherwise the gcc attribute.

  • the build script asks gcc to align functions. The msvc compiler doesn't support function alignment.

I built a few of the examples by hand and they worked as expected. It'd be fairly simple to make nt-batch file versions of the bash scripts, then run all the test bits.

It's very cool that you took the time to do this.

bpotvin avatar May 31 '20 07:05 bpotvin

Thanks for sharing. Can you post your code for the pragma part? Or, maybe, you could send me a pull request for the Windows-related improvements.

Thanks! It was a fun project.

amakukha avatar May 31 '20 13:05 amakukha

Sure. Originally, this is what I did:

// symbol table entry layout (Records in tables.)
#ifdef _MSC_VER
#pragma pack(push, 1)
typedef struct symbol {
. . .
} symbol_t;
#pragma pack(pop)
#else
typedef struct symbol {
. . .


} __attribute__((packed)) symbol_t;
#endif

But, it appears that gcc supports the same pragma's as msc:

https://gcc.gnu.org/onlinedocs/gcc/Structure-Layout-Pragmas.html

So, instead of the _MSC_VER ifdef, switching to the pragma would work:

// symbol table entry layout (Records in tables.)
#pragma pack(push, 1)
typedef struct symbol {
    tword custom;           // word 0 is for customer. (User-accessible table data.)
    tuword lptr;            // index of next entry on tree to left
    tuword rptr;            // index of next entry to right
    char* sptr;             // first character of string in this entry
                            // next char is in *(sptr+1), etc.
} symbol_t;
#pragma pack(pop)

Apologies for not knowing that; I almost never use gcc, so I'm not very familiar with it.

I did a 'build' batch and attached it. I had to give it a .txt extension. I'll try to do a batch version of the tmg.sh script later today/tonight. I was looking at it earlier and, because you have two 'phases', it made me think of the early 'cc', which basically just runs the compiler stages,

cc -> /lib/c0 -> /lib/c1 -> [/lib/c2 ->] /bin/as [-> /bin/ld]

It might be interesting to do a 'tmgcc' thing that does the same. Then that led me to think about how nice it would be to use the old 'ar' utility, which wasn't tied to executable image files. I tried that earlier and it works just fine:

# ar cq tmgx.a tmga.c tmgb.h tmgc.h tmgl.h tmgl1.h tmgl2.h libs.h

# ar tv tmgx.a
rw-rw-rw-  0/0   19818 May 30 09:14 2020 tmga.c
rw-rw-rw-  0/0   31242 May 30 09:14 2020 tmgb.h
rw-rw-rw-  0/0    7332 May 31 15:04 2020 tmgc.h
rw-rw-rw-  0/0   55788 May 30 09:14 2020 tmgl.h
rw-rw-rw-  0/0   56433 May 30 09:14 2020 tmgl1.h
rw-rw-rw-  0/0   60564 May 30 09:14 2020 tmgl2.h
rw-rw-rw-  0/0   37126 May 31 12:56 2020 libs.h

Then, tmgx.a could be put next to tmg.sh, or somewhere like /usr/local/lib, and then copied to the build directory and extracted when needed, instead of having to find the source. The ar I use is a port I did of the 7th edition source.

I'll get the tmg.cmd batch done as quickly as possible and do a pull request. I've got source from an earlier S/360 version of tmg that I'll include; it's just three 360 assembler files. I've got a PDF of McClure's original paper also. It would be great to find the original IBM 7090/7040 source, but that's likely long gone.

Another interesting compiler-compiler from those days is XPL, which is a dialect of PL/1.

build.txt

bpotvin avatar Jun 01 '20 00:06 bpotvin

Excellent! Maybe, you can include the pragma part into the pull request as well then.

As for the library archive utility, the idea is neat and efficient (if it helps to reduce the amount of code that needs to be recompiled by C). After all, that's how it worked originally. But on the other side, this code is so small by today's standards and, probably, so rarely used that, personally, I wouldn't invest time in this.

S/360 code could be interesting, though it's probably not directly related to this Unix v2 dialect. And I hope that it's in public domain (just like OS/360).

As for the McClure's article, I have it as well, but I'm pretty sure it's still protected by copyright. Unless we obtain a permission from copyright holders, I wouldn't want to include it into the repo explicitly.

amakukha avatar Jun 01 '20 09:06 amakukha