6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Sep 21, 2024 11:35 am

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Mon Jan 04, 2016 2:16 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Rob Finch wrote:
It's quite a feat to get a compiler working.

I'm struggling to discover where, but somewhere recently I found someone intending to embark on a compiler for the 65816, I think, and mulling about whether to aim for Pascal, or Modula 2, or even Oberon[1].

Anyhow, I came across this post: Want to Write a Compiler? Just Read These Two Papers and thought it could be useful. The two papers are:
Quote:
- A Nanopass Framework for Compiler Education [PDF] by Sarkar, Waddell, and Dybvig
and
- Jack Crenshaw's series, Let's Build a Compiler!


[Rob's quote is from this thread and the Nanopass technique has been mentioned in this thread. In the first of those, MichaelM offers an additional pointer:
Quote:
I have been porting the Pascal compiler written by Ronald Mak, which is described in his first book: "Writing Compilers and Interpreters - An Applied Approach". The compiler is written in C
]

[1]I would guess Oberon is a good choice - it is free and completely documented. The Oberon compiler lives within the Oberon OS. Downloads here and see nearby links for more info including Wirth's book on Compiler Construction.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 04, 2016 3:42 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
I was mulling it over on my blog. I concluded that Modular-2 was probably the simplest. Standard Pascal doesn't like peeking and poking around in memory and although Oberon 2 has a simpler grammar (allegedly) it's OO features, module initialisers and garbage collection make its implementation harder IMHO.

I'm investigating ways of bootstrapping M2 using other M2 compilers. These is open code for a multi pass compiler but it hard on the eyes (and brain).

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Last edited by BitWise on Mon Jan 04, 2016 6:29 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 04, 2016 3:44 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Ah! Thanks. Searched my RSS feeds, couldn't find it... ah, saw it on g+. Subscribed now.

I see your point about Modula-2 being simpler. I bet it's fun to do the bootstrapping thing.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 04, 2016 4:46 pm 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
The nanopass article is what led me to writing the Tinkerer's Assembler (viewtopic.php?f=2&t=3548). After the experience, I can say it is a "low complexity, low performance" way of doing things - far easier to understand than all the grammar stuff, but with serious drawbacks like speed.

(One thing I'd now consider is using a language that allows for easy concurrency (Google Go or Clojure come to mind) instead of Python with its GIL because I'm sure there are various steps that can be handled in parallel, such as translation of instructions without operands.)

ADDED LATER: Just what should the higher-level language be able to do? Your blog says that Forth is not what you want, how about something with a very simple core and well-defined higher functions such as Scheme then?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 04, 2016 4:51 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
That would be quite exciting - goroutines running the passes in parallel, as best they are able.


Top
 Profile  
Reply with quote  
PostPosted: Sun May 22, 2016 4:06 am 
Offline

Joined: Sun May 22, 2016 3:56 am
Posts: 2
BigEd wrote:
Rob Finch wrote:
It's quite a feat to get a compiler working.

I'm struggling to discover where, but somewhere recently I found someone intending to embark on a compiler for the 65816, I think, and mulling about whether to aim for Pascal, or Modula 2, or even Oberon[1].

Anyhow, I came across this post: Want to Write a Compiler? Just Read These Two Papers and thought it could be useful. The two papers are:
Quote:
- A Nanopass Framework for Compiler Education [PDF] by Sarkar, Waddell, and Dybvig
and
- Jack Crenshaw's series, Let's Build a Compiler!


[Rob's quote is from this thread and the Nanopass technique has been mentioned in this thread. In the first of those, MichaelM offers an additional pointer:
Quote:
I have been porting the Pascal compiler written by Ronald Mak, which is described in his first book: "Writing Compilers and Interpreters - An Applied Approach". The compiler is written in C
]

[1]I would guess Oberon is a good choice - it is free and completely documented. The Oberon compiler lives within the Oberon OS. Downloads here and see nearby links for more info including Wirth's book on Compiler Construction.


How about these two pages right here:

Literally a complete WORKING little language for the PIC microcontrollers written by Professor Wirth...in TWO files. All in @700 lines of code...including rs232 uploading functionality! Actually, I think it's amounts to @ ten pages or 'screenfulls'.

Two files:
PICL.Mod and PICS.Mod (PIC-L-inker and PIC-S-canner)

https://www.inf.ethz.ch/personal/wirth/PICL/index.html


Top
 Profile  
Reply with quote  
PostPosted: Sun May 22, 2016 7:18 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Welcome, captbill. Very interesting find. Wirth as ever seems very clear:
"Whereas the syntax of PICL is to provide the conveniences of high-level languages, its semantics are to mirror the facilities and limitations of the processor clearly and honestly."


Top
 Profile  
Reply with quote  
PostPosted: Sun May 22, 2016 7:40 pm 
Offline

Joined: Sun May 22, 2016 3:56 am
Posts: 2
BigEd wrote:
Welcome, captbill. Very interesting find. Wirth as ever seems very clear:
"Whereas the syntax of PICL is to provide the conveniences of high-level languages, its semantics are to mirror the facilities and limitations of the processor clearly and honestly."


BigEd wrote:
Welcome, captbill. Very interesting find. Wirth as ever seems very clear:
"Whereas the syntax of PICL is to provide the conveniences of high-level languages, its semantics are to mirror the facilities and limitations of the processor clearly and honestly."


Hi BigEd,
Perhaps you should take a look at Saanlima.com at the bitfile projects that run on the Pipistrello and the Pepino boards. I am quite sure there are all kinds of implementations of 6502 based system you might be able to draw from if you are building a compiler. Or shall I say, here goes a good way you might do compiler construction using an FPGA as a 'testbench'. I know there is Nes_MarioBrothers, Pacman, Doom, Vic20 and many more. Take a look here at 'bitfiles' to see the full Xilinx projects you can start with:http://pipistrello.saanlima.com/index.php?title=Welcome_to_Pipistrello#Bit_files_.28see_below_for_complete_Xilinx_projects.29

The 'Pepino' is the new board that is more specifically geared to accommodate ProjectOberon. Magnus at Saanlima has been knocking it out of the park in the hardware department. ProjectOberon requires a fast 10ns SRAM arrangement which you don't find on typical 'fpga dev boards'. The Pepino is the new board that accommodates Oberon beautifully! Or any other FPGA based design benefiting from a nice ram interface onboard.

http://www.saanlima.com/pepino/index.php?title=Welcome_to_Pepino

You have to keep an eye on Magnus. Look at what he has going in the last few days:

https://github.com/Saanlima/Pepino/tree/master/Projects

Magnus has not one but three experimental branches of Oberon happening. I just caught it last night.

Also, worth a thread of it's own, is his OpenBenchLogicSniffer project. It is a full implementation of a SUMP logic analyzer that captures at 200mhz and 64mb deep. Try and find that in a 'consumer USB logic sniffer'. For under $200 you can have a logic analyzer that performs 'like' the high end units costing thousands of dollars.

Also have a look at Andreas' ExperimentalOberon. He is doing some neat enhancements. Look at the videos. It give you a feel for ProjectOberon in action. It is surprisingly fast/snappy. https://github.com/andreaspirklbauer/Oberon-experimental

I wish there were more video around more specific but here is the 'PlusToo_SCSI' project. It is a complete resurrection of the good ol' MacPlus running on FPGA. I even have 'ThinkPascal' going with the networking libraries ready to roll. If anyone wants a super fast MacPlus with WiFi, all the parts are there. Here it is running on the SDL based emulator:

https://youtu.be/GM59aJmsZ4g

Hopefully this will give you some ideas of the possibilities we have now before us. Just know that ProjectOberon is not a lot of talk. Everything is WORKING, and working well and looks to be gaining momentum.

One note: I haven't tried the OberonStation but you won't go wrong there either, I'm sure. It is much like the Pepino. If you are over in Europe you might give it a go.

Cheers,
Bill


Top
 Profile  
Reply with quote  
PostPosted: Mon May 23, 2016 6:57 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
Having written compilers in the past, they can be very exciting.

In truth, simple compilers are not particularly difficult, especially one with an established grammar. Creating something out of whole cloth can be a challenge, specifically deriving an appropriate grammar, but given a simple grammar (like Pascal), creating a recursive decent compiler is straight forward.

With modern languages, and modern libraries, with easy access to common data structures, the process is even simpler. Writing a compiler in, say, raw C is a pain simply because of having to tool up the compiler runtime by building things that we take for granted today, like hash maps and trees, etc. It's just work.

The core expression in the language tends to be the most complicated thing to get working, especially grammatically. Once you conquer that, the rest is pretty much rote work.

Now, of course, creating a GOOD compiler, with optimizations and what not, that's a bit more of a trick -- but adding basic optimizations to a simple compiler is not arduous.

Outside of the compiler there's the rest of the toolchain, notably things like linkers and loaders. But you could build your compiler against, say, the cc65 toolchain which provides those facilities. Or you can simply "include" all of your code in one big file and create a memory image and be done with it. Your multi-GHz host won't really notice the extra source lines.

You can't get much simpler than Pascal. If you're worried about low level access, you can always hack around it. You can create a runtime procedure such as "function setpointer(int address): ^byte" that will give you a pointer to any place in the memory space, then the generic Pascal semantics will take over from there.

Modula-2 is more complicated because of its module sharing imports and exports and what not. I do not recommend Oberon, as it has a garbage collector among other things.


Top
 Profile  
Reply with quote  
PostPosted: Wed May 25, 2016 1:22 pm 
Offline
User avatar

Joined: Fri Oct 31, 2003 10:00 pm
Posts: 200
Deleted


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 30 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: