Jump to content
IGNORED

COMFY 6502 Language - running inside Emacs


cas

Recommended Posts

Hi,

 

I just found this text from Henry G. Baker describing a 6502 Compiler for a extended 6502 Assembly Language called COMFY. The compiler is written in Lisp (GNU Emacs Lisp) and compilation can be started from the Editor.

 

Description of the Comfy Language:

http://home.pipeline.com/~hbaker1/sigplannotices/COMFY.TXT

Lisp Code:

http://home.pipeline.com/~hbaker1/sigplannotices/CFYCMP1.LSP

Description of the 6502 Compiler (TeX Source):

http://home.pipeline.com/~hbaker1/sigplann...column04.tex.gz

 

Maybe something to investigate for a boring new years day ;)

 

Best regards

and Happy 2006!

 

Carsten

Link to comment
Share on other sites

In ALGOL-like notation:
x:=1;
while x<11 do
begin
 print x;
 x:=x+1
end;

In COMFY notation:

x:=1; ~(x<11 -> print x; x:=x+1)^oo

 

I think this about says it all. Algol looks a lot like what Basic evolved into and certainly reads easier than Comfy.

 

I think history has proven that a keyword-driven language is easier to read than a punctuation-driven language.

Link to comment
Share on other sites

  • 2 years later...
In ALGOL-like notation:
x:=1;
while x<11 do
begin
 print x;
 x:=x+1
end;

In COMFY notation:

x:=1; ~(x<11 -> print x; x:=x+1)^oo

 

I think this about says it all. Algol looks a lot like what Basic evolved into and certainly reads easier than Comfy.

 

I think history has proven that a keyword-driven language is easier to read than a punctuation-driven language.

 

This is actually a bit unfair; that notation is from Baker's more mathematical description of the theory. ^oo is the text form of a "superscript infinity symbol", which is the mathematical expression of the COMFY concept "repeat forever", which you could notate however you want in your actual language.

 

In a Lisp-based implementation, the syntax would be something like

 

(seq (load x 1) 
 (loop 
	(< x 11) 
	(print x) 
	(inc x)))

 

Or, in Algol-y terms

 

seq {
 x = 1;
 loop {
x < 11;
print x;
x += 1;
 }
}

 

The only tricky thing is that "seq" and "loop" have the special feature of immediately exiting the sequence or loop if any statement inside "fails", which in this example, only the < test can fail. It's this kind of "dumbing down" of things like loop tests that makes the language very simple to compile to machine code. The compiler for the 6502 example fits in a couple pages of code (although it is hard to read because Baker used i & j instead of x & y, and didn't use standard mnemonics for 6502 operations, etc. It took me several hours of reading to really understand it.)

 

With Lispy macros, you can actually create all sorts of nifty "shortcuts." One that he introduces is basically

 

(forx 0 12 <things to do>)

which automatically compiles to

 

	 LDX #0
LOOP CPX #12
 BCS EXIT
 <things to do>
 INX
 JMP LOOP
EXIT ...

 

and the compiler is smart enough that it can emit

 

	 LDX #0
LOOP CPX #12
 BCC SKIP
 JMP EXIT
SKIP <things to do>
INX
JMP LOOP
EXIT ....

 

in the case where <things to do> takes longer than 128 bytes.

 

Two better articles are the ACM typeset versions of Baker: The COMFY 6502 compiler of the TeX paper and Baker: COMFY---A Comfortable Set of Control Primitives for Machine Language Programming of the COMFY.TXT if you can get through the ACM portal.

Edited by jaoswald
Link to comment
Share on other sites

  • 3 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...