3 ms·
Pascal in Forth (1983)
- dbrower 3y agoAh, an ancestor of Typescript!
- 082349872349872 3y agoBuilding a reduced Pascal and a full Forth demonstrates why the latter was popular on tiny machines: the former will be roughly half compiler and half machinery to deal with Pascal having a grammar. (less if you're into definitely-non-Wirthian optimising compilers; more if you're into attempting to provide useful-to-newbies error messaging)
- throwaway17_17 3y agoI enjoyed reading the transcription, it is always nice to know I’m not just being a crazy lone implementer of unconventional programming language constructs. This reminds me of what the language I use for work does, in some respects. The primary difference between the article’s subject and mine is that (using the article’s case) the ‘Forth’ is a strongly, statically typed language and the ‘macros’ representing the ‘Pascal’ syntax are typed constructs in the language. This enables both better compiler messages (error, expansion-relative info, etc) and ensures the surface ‘syntax’ is type correct before going through what could be complex expansion/alterations via the macro. The place I use it most often as a macro-implemented-syntax is in Type expressions in definitions (with long or complicated math formulas coming in second), for a simple example: Macro — (type of str_longer_than) -:[ Str_nt -> u32 -> Bool ]:- Actual Syntax — {() || Str_nt || ({() || u32 || Bool} Pi)} Pi It is just a convenience feature for me, because the macros are just a derivative feature of the language being multi-staged via modalities.
- deleted 3y ago[deleted]
- sph 3y agoI am trying to design a language based on Ian Piumarta's metaprogrammable object model [1] (i.e. a Smalltalk-like where two methods are defined "a priori" in the entire system, everything else is late bound and can be changed at runtime — believe it or not, more flexible than any Lisp) and I was trying to figure out how to implement the basic stuff like number addition in the language, when nothing has been defined yet. Piumarta shows that with his model any function/closure/method can in theory and very easily be written in any language, so at first I was thinking of having tagged asm blocks: Number + other = {.asm. mov rbx, [self] mov rcx, [other] add rbx, rcx mov [self], rbx } assert: { 5+6 } equals: 11 But then I would have to write an assembler, in the bootstrapping language (currently C which I've grown to dislike). So I thought about Forth: Number + other = {.forth. ( self other -- self ) @ over @ + ! } Which seems so elegant, portable, the bootstrapping language can be Forth (the Forth interpreter itself written in asm), and I don't have to write an x86_64 assembler in C. Win win win. And during my research I came across this, running Pascal in Forth. Time is a circle and computer science keeps reinventing itself :-) I like the opinion of the author that a great platform is one that lets you choose the perfect language to the problem at hand. My (ideal) language is fully late bound, based on message passing, which is extremely flexible, but not ideal for number crunching. Is this much of a problem, if a user can drop down to FORTRAN in the hot loops? I feel that is a much better idea than creating a multi-paradigm language that does everything but the kitchen sink (cough C++ and Rust), and is either mediocre like the former, or very complex like the latter. IMO, we need simpler languages, based on the next level of abstraction — communication and not computation. 1: https://www.piumarta.com/software/id-objmodel/ https://www.piumarta.com/software/id-objmodel/ See also COLA: https://www.piumarta.com/software/cola/ https://www.piumarta.com/software/cola/ based on this model, but still too advanced for my brain to digest. --- If anyone reading is familiar with Piumarta's COLA/object model and/or very late bound minimal systems, please drop me a line, I would be happy to pick your brain.
- pyinstallwoes 3y agoThis seems relevant to my open ended curiosity around the question 'what is the irreducible form of compute?' I've been thinking of solving it with Forth, as well, coincidentally. I basically want to build a bootstrappable Forth as a meta-transpiler over a Forth VM that initially starts out in the earliest stage as the most minimum possible representation and add from there. In my research things that led to this being possible but I haven't sussed out: 1. Mov based architecture 2. Transport Triggered Architecture 3. Some two push-down automata based on some operation that assumes stack operations for left and right to manage params/addresses.
- guenthert 3y agoUh, a Pascal-like extension to FORTH, not a Pascal compiler in FORTH.
- sph 3y agoWhat is a compiler? This actually parses a subset of Pascal and translates it into another representation. Perhaps you can call it an interpreter. Compiler = parse + codegen — Later, the OS executes. Interpreter = parse + execute On metaprogrammable languages like Forth, what is the point of compiling to disk, if the final goal is to execute it anyway? ;)
- astrobe_ 3y ago> This actually parses a subset of Pascal and translates it into another representation. Perhaps you can call it an interpreter. I didn't read TFA thoroughly, but traditionally a compiler that translates not to machine code but into another language (source level) is called a "transpiler". > On metaprogrammable languages like Forth, what is the point of compiling to disk, if the final goal is to execute it anyway? ;) Lua and probably other languages do have a "pre-compiler", something that parses and compiles to bytecode. This reminds of image-based systems, except it is only one half of them (the other half being the value of variables, stack state, etc.). It must be much more rare for Forth dialects, as the parsing step is really simple - almost trivial. It has nothing to do with metaprogramming, though - actually, it adds a tiny bot of complexity (must check the "immediate" flag when compiling).
- JonChesterfield 3y ago> The philosophy behind this idea is in the widely held view that, while most languages are good for some things few, if any, are good at everything and instead of trying to design new all embracing wonder-languages, it might be more productive to develop multilingual programming environments! This still sounds right to me. So far it's been a bit of a disaster everywhere I've tried it - the interface between languages is usually a mess and most developers have negative feelings about swapping back and forth between different languages within a single project (or a single source file). Text editors are a bit wtf about it too. I think there's something fundamentally right about the many languages on one VM approach of jvm/.net in terms of sane marshalling of information between languages. Writing one language in macros on a other makes it very hard to get sane compiler front end diagnostics to the programmer. I think there's something to implementing the languages as macros on the one true language substrate, and separately implementing compiler front end / linter things that tell people about problems in their code, though I really hated visual studio using inconsistent language front ends in the IDE and the compiler proper back around 2010. Interesting design space.
- whartung 3y agoFor the curious where this came from, it’s from a FIG (Forth Interest Group) publication. FIG publications typically consisted of a colored card stock cover stapled to a stack of photocopied pages. This was how they produced their famous FIG Forth listings for the various CPUs (6502, PDP-11, 8088, etc.). I recall my friend picking this up at our local technical book store. They carried all sorts of arcane stuff like the FIG listings. Definitely in the deep end in that book store compared to you local B. Dalton. A very cool time where it was anything goes in terms of computing.
- cobrin 3y agoMany years ago, I worked with the Pascal Compiler team at Sperry Network Systems, they Forth-based compiler for the Sperry DCP Minicomputers, used in Air Traffic Control (I believe). Jan E Jonak wrote the compiler and Wim Morrison was the architecture expert. This help our sister team led by Les Arnott who implemented an OS written in Pascal, to allow us to run and debug a Monolithic program which used to be uploaded directly via a Univac Mainframe. I helped write the Assembler and Pascal Debugger back in the 80s. We also had a student write an assembler code optimiser in Prolog. refs: - https://dl.acm.org/doi/10.1145/988316.988320 https://dl.acm.org/doi/10.1145/988316.988320 - https://dl.acm.org/doi/pdf/10.1145/15022.15025 https://dl.acm.org/doi/pdf/10.1145/15022.15025
- transfire 3y agoThanks for this.