Recent

Author Topic: SetJmp / LongJmp results in Illegal Instruction: 4  (Read 2189 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 14372
  • Sensorship about opinions does not belong here.
Re: SetJmp / LongJmp results in Illegal Instruction: 4
« Reply #15 on: May 24, 2022, 01:04:06 pm »
Z80 is already supported in trunk.
See https://wiki.freepascal.org/Z80 and the fpc-devel mailing list
« Last Edit: May 24, 2022, 01:08:24 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

pleumann

  • Jr. Member
  • **
  • Posts: 94
Re: SetJmp / LongJmp results in Illegal Instruction: 4
« Reply #16 on: May 24, 2022, 01:10:53 pm »
Sounds like a perfect match then time/technology-wise. I am doing recursive-descent-single-pass-stack-machine, which probably puts me somewhere deep in the early 80s, late 70s. ;)

Recursive descent is entirely adequate IMO. The only reason alternative algorithms gained significant traction is that academics (and unskilled language designers) kept turning up cases which it couldn't handle efficiently.

My position on that, after many years of consideration, is that diplomats use English and French for unambiguous communication rather than Arabic and Navaho. A language which can't be parsed without jumping through complex or difficult-to-maintain hoops isn't fit for purpose.

MarkMLl

Agreed. I tried a couple of things throughout the years, even generators. In the end I always find recursive descent the most intuitive mapping from a grammar to working code, and I cannot remember a single case where I missed a feature (how could I - it's all context-free grammars anyway).

MarkMLl

  • Hero Member
  • *****
  • Posts: 6686
Re: SetJmp / LongJmp results in Illegal Instruction: 4
« Reply #17 on: May 24, 2022, 01:11:16 pm »
Z80 is already supported in trunk I believe.
See https://wiki.freepascal.org/Z80 and the fpc-devel mailing list

But not self-hosted. I'm not sure how close anybody has come to replicating the original Z80 Turbo Pascal, noting the positive publicity it got comparatively recently from Chris Fenton http://www.chrisfenton.com/the-zedripper-part-1/

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

pleumann

  • Jr. Member
  • **
  • Posts: 94
Re: SetJmp / LongJmp results in Illegal Instruction: 4
« Reply #18 on: May 24, 2022, 01:12:44 pm »
Sure. It's a super-simple Pascal compiler targeting Z80, a pet project I've been working on for a while now. The supported language is that of TP 3.0 initially, I might raise that a bit later. One goal (hope?) is for the compiler to be self-hosting, so I restrict myself to features that were available in 3.0. Hence no exceptions for error handling, which would have been convenient, but LongJmp is something I could see myself supporting on Z80.
That sounds very interesting.  Do you plan on sharing the source ? :) it would be nice to be able to look at how you implemented it.

I probably will at some point. But it will need a bit of cleanup to ensure it's not too embarrassing. :)

MarkMLl

  • Hero Member
  • *****
  • Posts: 6686
Re: SetJmp / LongJmp results in Illegal Instruction: 4
« Reply #19 on: May 24, 2022, 01:18:08 pm »
Agreed. I tried a couple of things throughout the years, even generators. In the end I always find recursive descent the most intuitive mapping from a grammar to working code, and I cannot remember a single case where I missed a feature (how could I - it's all context-free grammars anyway).

Apropos generators, while I use Meta-2 I'd suggest that Tree Meta is very much worth looking at since it demonstrates how even excessively-complex emissions from the recursive descent frontend can be promptly resolved to sensible code for the backend assembler.

Unfortunately, somebody who did a lot of good work using it at HP in the 70s or 80s had his home destroyed in one of the California fires... I'm not sure whether it was https://hackaday.com/2020/09/17/closely-examining-how-a-pge-transmission-line-claimed-85-lives-in-the-2018-camp-fire/ but I consider both the effects and the cause equally tragic.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 5469
  • Compiler Developer
Re: SetJmp / LongJmp results in Illegal Instruction: 4
« Reply #20 on: May 24, 2022, 01:21:26 pm »
Also, as I mentioned, I use a display, so I might have to save/restore the pointer for the level I am jumping to.

What is a display in this context?


Quote
nested procedures and the display,

I don't believe that FPC uses a display as such, instead it chains stackframes. In fact the only times I've seen the term used is in the Hisoft/FTL compilers and before that on Burroughs mainframes (to which the compiler writer might have been exposed, since there were several in the Australia/NZ region in which he was based).

MarkMLl

Sounds like a perfect match then time/technology-wise. I am doing recursive-descent-single-pass-stack-machine, which probably puts me somewhere deep in the early 80s, late 70s. ;)

FPC is a handwritten recursive descent single pass compiler (at least as far as parsing is concerned) ;)

pleumann

  • Jr. Member
  • **
  • Posts: 94
Re: SetJmp / LongJmp results in Illegal Instruction: 4
« Reply #21 on: May 24, 2022, 01:22:12 pm »
Z80 is already supported in trunk I believe.
See https://wiki.freepascal.org/Z80 and the fpc-devel mailing list

But not self-hosted. I'm not sure how close anybody has come to replicating the original Z80 Turbo Pascal, noting the positive publicity it got comparatively recently from Chris Fenton http://www.chrisfenton.com/the-zedripper-part-1/

MarkMLl

Also, this project it not about _having_ a Pascal compiler for Z80, but about _building_ one. I've been involved in a couple of parser/compiler/language projects throughout my career, but never had a chance to work on things from end-to-end. So I really enjoy doing this, especially the code generation part, which was new to me.

Interesting link, btw. What a beast of a CP/M machine. :)

pleumann

  • Jr. Member
  • **
  • Posts: 94
Re: SetJmp / LongJmp results in Illegal Instruction: 4
« Reply #22 on: May 24, 2022, 01:40:21 pm »
Also, as I mentioned, I use a display, so I might have to save/restore the pointer for the level I am jumping to.

What is a display in this context?


Quote
nested procedures and the display,

I don't believe that FPC uses a display as such, instead it chains stackframes. In fact the only times I've seen the term used is in the Hisoft/FTL compilers and before that on Burroughs mainframes (to which the compiler writer might have been exposed, since there were several in the Australia/NZ region in which he was based).

MarkMLl

Sounds like a perfect match then time/technology-wise. I am doing recursive-descent-single-pass-stack-machine, which probably puts me somewhere deep in the early 80s, late 70s. ;)

FPC is a handwritten recursive descent single pass compiler (at least as far as parsing is concerned) ;)

That's interesting. I think Niklaus Wirth shaped us all then. :)

The display, in this context, and I hope I use and explain the term correctly, is one of two common ways to handle the context in nested procedures, where the inner procedure would access the variables from the enclosing one, but from the right activation record on the stack (think recursive cases!). You could follow the chain of invocations whenever an outer variable is accessed or you can maintain a global so-called display of outermost activation records for each nesting level. The latter has a bit of overhead on each procedure entry/exit, but makes the actual variable accesses quite fast. Not fully sure it pays off, though, because in the end you probably never go beyond a single level of nesting.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6686
Re: SetJmp / LongJmp results in Illegal Instruction: 4
« Reply #23 on: May 24, 2022, 02:06:15 pm »
The display, in this context, and I hope I use and explain the term correctly, is one of two common ways to handle the context in nested procedures, where the inner procedure would access the variables from the enclosing one, but from the right activation record on the stack (think recursive cases!). You could follow the chain of invocations whenever an outer variable is accessed or you can maintain a global so-called display of outermost activation records for each nesting level. The latter has a bit of overhead on each procedure entry/exit, but makes the actual variable accesses quite fast. Not fully sure it pays off, though, because in the end you probably never go beyond a single level of nesting.

I've got a vague recollection that typical display implementations were problematic since they had a fixed number of elements... but everything I've ever worked on directly had sufficient index registers to use chained stackframes. I've also got an extremely vague recollection of a top-end mainframe which used a display for internal addressing and had a /very/ large "display" mounted in the middle of the computer room to show people it was busy... I don't know whether there was any direct connection, or if that was just a CPU usage scoreboard.

In any event, as CPUs got faster than memory anything that demanded extra cycles on function entry/exit was frowned upon: you only have to look at the way that Intel introduced pusha/popa in the '186 but that they were mostly ignored since even low-end compilers gained the ability to decide which registers needed to be saved and restored at about the same time.

I agree that Chris Fenton's system is a bit of a brute. I'm intermittently using a V20 as a target system to decode the output from a logic analyser, and considering the state of FPGAs etc. today it would be comparatively easy to replace that with something that implemented both x86 and Z80 opcodes (as distinct from the 8080 opcodes that the V20 is limited to).

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

MarkMLl

  • Hero Member
  • *****
  • Posts: 6686
Re: SetJmp / LongJmp results in Illegal Instruction: 4
« Reply #24 on: June 21, 2022, 02:27:13 pm »
In the older language implementations I used SetJmp/LongJmp for error handling, but in Delphi or later it's trivial to replace that with an exception

You appear to be quoting something I wrote a couple of months ago...

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018