Re: switch statement, was compiler, status...



On Jul 20, 6:41 pm, "Rod Pemberton" <do_not_h...@xxxxxxxxxxx> wrote:
<s_dubrov...@xxxxxxxxx> wrote in message

news:1184951612.460230.84460@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I've already decided to work from the original Cain version, simple
stack machine by comparison. Primary Register, Secondary Register,
Stack, and abit of storage does it. Putc snd Getc are the only system
hooks, and the assembler backend is pretty isolated from the rest,
handy for retargeting to nasm.

Nice and simple, but I never got that far into it. It sounds similar to
some of Fabrice Bellard's early compilers FBCC, OTCC, TCC and one or two in
the obfuscated C contest.

For Small-C, I had some questions about copyrights. I recall that some

Well there's this list of changes...FWIW.
/************************************************/
/* */
/* small-c compiler */
/* */
/* by Ron Cain */
/* and James Van Zandt */
/* */
/************************************************/

#define VERSION " 2 August 1984"
/* history...
2 Aug 84 Allocating symbol table and literal
pool from heap.
31 Jul 84 No GLOBAL directives for macros.
30 Jul 84 Input file extension capitalized.
29 Jul 84 Displaying input file names.
28 Jul 84 Getting file names and options from
command line.
14 Jul 84 outdec() is now recursive & smaller.
raise() not called, since ZMAC converts
to upper case. When profiling, the
appropriate GLOBAL statements are
automagically emitted.
28 Jun 84 Adding CR after GLOBAL statement.
25 Jun 84 In addglb(), generating GLOBAL
statement. Generating 9 character labels (so 1st 8
characters in a c symbol name are significant).
Allowing 800 bytes of literals per function.
2 Sept 83 In doreturn(), changed 'ccleavin'
to 'ccleavi'. Introduced 'leave'. 'numeric' &
'outbyte' optimized. Optimized: 'nch', 'gch', 'keepch',
'streq', 'astreq', 'raise'.
1 Sept 83 Initializing firstfct & lastfct
after calling ask(). Trace & profile enabled together.
27 Aug 83 Allowing 3 bytes for call count.
26 Aug 83 renamed: leaving => ccleavi,
registe => ccregis. Added code to link the call count
cells (main, header, trailer, newfunction).
22 Aug 83 converted "," to "'", corrected
loading of name pointer.
21 Aug 83 Trace and profile are available.
Using clibv.h & a:float.h
1 Aug 83 6 function names are now
"nospread", A now set to # words on stack rather
than adding another parameter.
29 Mar 83 "callfunction" now reserves
symsize bytes rather than namesize bytes for sym.
When "printf" is called, the top word on the stack
points to the first argument.
7 Mar 83 "callfunction" now adds pointer
to first argument for nospread functions. "nospread"
introduced (returns true only for "printf").
10 Nov 82 Rewrote "an" for speed.
24 Oct 82 In "preprocess", searching macro
table only with strings beginning with alpha. (Allows
long numeric literals.) Rewrote "alpha" for speed.
10 Oct 82 Updated date in signon message.
Coersing function values to proper type.
4 Sept 82 Generating colons again.
3 Sep 82 "#includ"ing floating point
library.
30 Aug 82 Changed "number" calling sequence
back. Colons are optional.
12 Aug 82 Changed "number" calling sequence.
11 Aug 82 Allowing typed function
declarations.
7 Aug 82 Correct length of double in
local variables, preserving calling addr when
calling through TOS & using double argument.
5 Aug 82 Started installing floating point
3 Aug 82 generating no colons
after labels. Generating only 7 character labels.
20 Jul 82 Removed the unused
variable "iptr".
18 Jul 82 Changed comment
recognizer per J. E. Hendrix (ddj n56 p6).
17 Jul 82 Implemented \" and
\' sequences. Corrected newfunc & getarg per
P. L. Woods (ddj n52 p32) & J. E. Hendrix (ddj n56 p6).
14 Jul 82 "#include"ing
clibv.asm & c80v-2.c
28 Jun 82 Skipping first byte
in macro table, so index won't be zero.
27 Jun 82 Masking out high
order bits of characters extracted from
a symbol table entry.
21 Jun 82 Dumping literals
at end of each function, per Rodney Black
(DDJ n61 p51).
19 Jun 82 Updated symtabsiz.
Updated dumpglbs to handle new symbol table.
Placing macro names in global symbol table,
using smaller macro table.
16 Jun 82 using hash table
for global symbols.
18 Apr 81 Changed names so
first 5 characters are unique:
heir10 => heira heir11 => heirb
input2 => inpt2 errorsum => errsum
*/
The above from a package from the old Simtel Archives, the SIGM #224,
which I had gotten from retroarchive.org I list this because it shows
the DDJ refs. of some enhancements/or errata. It has the name of Dr
James Van Zandt, whom Hendrix acknowledges for hash searching
suggestions in the citation:

"Small C Compiler, v.2", copyright 1982, DDJ #74, Dec. 1982. by J. E.
Hendrix.

Hendrix acknowledges Cain's guidance as well on ver. 2, in the
article. Written at the end of the DDJ article, I quote:
"Availability
This version of Small-C is copyrighted as a revision to Ron Cain's
original work. It is, nevertheless, available to the general public
for use without formal restrictions. Take it, use it, copy it, modify
it, and give it away as you please. If you capitalize on it for
profit, I ask only that you compensate the principal authors in a
manner that seems fair to you. Machine-readable copies are available
on North Star and 8-inch single density CP/M diskettes. CP/M versions
contain just the source code as listed here and are available for
$25. DOS versions with Small_VM, Small-Shell, and documentation cost
$45. My software tools (written in Small-C for use with Small-VM) are
also available, with documentation, for $45. "

HTH.
The Vitchev version of small c, smc386c.c, carries the initials of;
RDK, rj, and gtf who is Glen Fisher of Code Works.

; ========================================
; I/O subroutines for CP/M
; By Glen Fisher
; The Code Works(tm)
; ========================================
;
A reference from another Small-C source , v 1.1 with the cp/m io
library.

Code Works was mentioned by Cain in the original DDJ#45 Ron Cain
article, as a possible distributor. Cain states in the article he
didn't want to get caught up in selling it because he would have to
support it on a number of various machines, he decided to give it away
for free. The article is a great read. To imagine what the early
guys, tried to do.. and succeeded, with less than 64 kilobytes of
memory to work with...

Internet site had a bunch of versions for many cpu's. After looking at the
source some said they were copyrighted and others said they weren't... I
couldn't determine if any applied to Hendrix's or Cain's code or both or
some other unlisted author(s). That was also the reason I haven't released
the changes I made to the Evgueniy Vitchev version (although I offered to
you). Vitchev didn't mention copyrights either. So, what do I release mine
changes as? And, if I did mention PD or GPL, etc., how would that affect
portions that weren't mine since I don't know how or if they were
copyrighted? The best I could tell was to not mention any copyrights
either...

Thanks for the offer, my email addr is valid as the spammer well know.

Another little compiler of interest (again uncertain about copyrights,
Croatia) is "Calculator Compiler" by Senko Rasik. Technically, it compiles
a calculator like language, but it is extremely close to C. Very small, it
works, compiles clean...

http://software.senko.net/projects.phphttp://software.senko.net/pub/calcc-0.2.tar.gz

Anyway, I did more work with a compiler called WCC, "A C Subset Compiler",
by Lutz Hamel for VAX-11 originally from DECUS. These were originally
Public Domain contributions, but it seems DECUS may be selling access to the
compilation of programs... The files in these archives seemed to have
disappeared. I ran into problems with the orthogonal registers to
non-orthogonal x86. In many places, he used two "sections" of code to
generate a VAX instruction, however for x86, the second could only be used
some of the time. I ended up emitting two x86 instructions - one redudant
half the time... And, the code was lex/yacc based and used a "typical" Yacc
struct to pass information to be used in the syntax tree. Although his
compiler seemed to work quite well, this didn't meet my needs and would've
needed much rework.

The description, but not the code, is here:http://www.decus.org/libcatalog/description_html/v00281.html

I've some checking to do in the
recursive descent parser, and some design decisions, the nasm output
seems ok at this point. Cain's small-c is strictly a subset of K&R C
at the outset, for those who don't know.

comp.compilers is probably a group to subscribe to. It's moderated
(comments added...) and requires a legit email address (why I haven't posted
there...). Otherwise, I'd say bounce some ideas of off cr88192... :)

Mostly, I've wanted a reason to poke around Cain's Small-C, and having
a little easy, quick, success with coercing nasm syntax out of it has
given me alittle motivation. In general, I prefer assembler. There
is abit of allure to C, and HLL's in general, but I generally don't
feel all that comfortable with them like I do with assembler. C's
indirection, pointer syntax, is problematic. In other languages, dead
ones I might add, curiously, the address of a variable is an attribute
indicated by symbol marker. i.e., variable x, it's location as ^x, its
value as x, simple. Or, variable Y, it's location as Y', (a prime
mark). In C, what's p? If it's a p it must be a pointer, right? Oh,
how did you declare it? Oh, it's not declared there, what scope is it
in? Oh, you better find its declaration scope, it's gotta be extern
somewhere, because if you didn't declare it as a pointer type, it's
gonna default on you to an Int, and a signed one at that! -- anyway,
you get my sarcasm, er, that should be scar-chasm.

I've written a few simple parsers with differing goals. So far, each has
some advantages, but also reached some limitation which I haven't figured
out how to overcome or decided to terminate the code... Some of the issues
I've run into could've been solved with better or simpler language design.
I'm moving towards the idea of a simple compiler in the C style, but not
entirely C, based on what I've seen. I'm thinking about working backwards
from NASM x86 to "C whatever-ish" instead of from C to NASM x86.

I understand the underlying desire, and share it, there is something
that doesn't quite mesh between the desire to express programming
design and HLL's ability to implement that expression in a chafeless
way. So there is a natural desire to roll your own "C whatever-ish". -
at least then the blame knows where to go.

Actually I do appreciate aspects of C, the block structure, & control
structures .. quite abit of it all actually. ..if only.. but to
change it is to orphan it to other users. Well, if I were to create
yet another small language, I've decided to call it K for Klingon,
where brute force programming is an admired attribute! 8-)

Steve

Rod Pemberton


.



Relevant Pages

  • Re: How function calls work
    ... > I'm interested in how the compiler implements function calls, ... > know where these are in memory relative to the current stack pointer ... typical to return things that fit in a register or register pair by ... > int a,b; ...
    (comp.lang.cpp)
  • Re: next mystery: 32 vs 64 bits...
    ... etc. Stack and register reorganization are always ... (this is not too much of a problem in my compiler, I just resort back to the ... given the newer way I am handling memory references (better ... 'on stack' typically, is not 'in memory'. ...
    (alt.lang.asm)
  • Re: Lock-free reference counting
    ... that they are all requiring "explicit help from the compiler". ... it will notice that object `a' is in a register on a threads ... A register on a stack?! ... Without compiler help, the object that `a' points to will be hot until the ...
    (comp.programming)
  • Re: Detailfrage zur cdecl
    ... Parameterzahl alles auf dem Stack zu uebergeben. ... in einem Register einen Pointer auf einen ... wenn man den mit diesem Compiler erzeugten Code mit Code mischen ...
    (de.comp.lang.c)
  • Re: Detailfrage zur cdecl
    ... dass die auf dem Stack liegen? ... Parameterzahl die ersten N Parameter in Registern zu uebergeben (wobei ... Compiler so implementiert) waere auch, in einem Register einen Pointer ...
    (de.comp.lang.c)