7 ms·
Nim compiler — Pascal source code
- skulk 6y agoIf you squint really hard, it looks like Nim! (this is coming from someone who never learned Pascal)
- TurboHaskal 6y agoAnd if you ever programmed in Pascal, you can tell its influence on Nim just by reading Nim source code. The idiomatic way to write enums made me chuckle.
- eterps 6y agoThe source for scanner.pas looks recognizably like an implementation inspired by Niklaus Wirth's compiler books.
- keyle 6y agoI'm not sure what the OP was trying to show with this. It's certainly cool and interesting to see that nim(rod) was written in pascal 11 years ago? I love Pascal, I just give up on it too fast. But man it's fast, compiles fast, "easy" to use, until you start doing real world stuff.
- pjmlp 6y agoHaving used all Borland compilers since Turbo Pascal 3 all the way up to around the first set of Delphi versions, and a couple of UNIX Pascal compilers as well, I wonder what is so hard for real world stuff.
- HacklesRaised 6y agoI read "I couldn't find libraries that did most of what I needed and I couldn't be bothered to contribute said libraries"
- pjmlp 6y agoNot even written in C? Because language interop is a thing, unless one is religously following the mantra of being a X-lang developer instead of embracing polyglot skills.
- cy_hauser 6y agoOr unless you're coding simply because you enjoy the experience and don't care about the interop and making a wide use language at that point.
- pjmlp 6y agoWhen I find a issue that could be more practical do in C++ instead of Java or .NET, instead of throwing away my productivity out of the window and rewrite everything into something else, I just write a tiny wrapper for what is missing and write everything else in Java or .NET languages. Just like I used to call Windows DLLs or COM libraries from TPW and Delphi. Which incidently is how Google pushes everyone to write native code on Android, as little as possible, just tiny native libraries. Even the NativeActivity is just a regular Java Activity implementation with predefined native methods declarations that the shared object is expected to fill in, to be properly called from the framework.
- ksec 6y agoI continue to wonder if we have even exceed Delphi in terms of RAD today. There are so many things that were better in its field, domain or niche but simple got washed out in History. It was only the other day someone commented Rails, despite its similarity in concept and execution, it is still not as good as good old Enterprise Objects Framework from NeXT.
- jpcooper 6y agoWhat was so good about Enterprise Objects Framework? I don’t know much about Rails either, by the way.
- pjmlp 6y agoIt was a proper object entity relationship mapping framework to relation databases, already available in 1990's NeXTSTEP. http://www.kevra.org/TheBestOfNext/page570/page571/page573/page573.html http://www.kevra.org/TheBestOfNext/page570/page571/page573/p...
- jpcooper 6y agoThanks. Will have a read.
- pjmlp 6y agoDepends on how you look at it, I certainly feel like using Delphi when doing .NET and Java development, which are also the development stacks that took the spotlight away from Delphi (alongside Borland's mismanagement). What they miss in regard to Delphi is proper AOT to native code capabilities, something that they should have supported (from my point of view) since version 1.0. Java had it via commercial JDKs (which only enterprises cared about), .NET via NGEN, mono aot and some research stuff like CosmOS, Singularity or Midori. However now 20 years later they are finally realising that must be an option, but that is mostly thanks to the competion from Go, Rust, Swift and friends than anything else. Interesting that you mention EOF, it eventually became WebObjects (in Java) and it was due to NeXT / Sun collaboration that J2EE was born. Many Java bashers don't realise how much influence Objective-C had in the Java ecosystem, in language features, language runtime, and yes J2EE. Regarding things being washed out of history, check out on Burroughs, VMS, Solo Pascal, Mesa, Multics, PL.8 for examples of systems programming before C was at all relevant outside Bell Labs walls, the Xerox PARS Workstations namely Interlisp-D, Mesa, Mesa/Cedar, Smalltalk or Wirths linage of Modula-2 and Oberon derived work based on Xerox PARC work. Unfortunely computer history isn't something that most computing degrees spend time on.
- k__ 6y agoNice. I'm still dreaming of a world where Rust had Nim syntax.
- gameswithgo 6y agoIf you are hoping for the lack of curly braces in particular, there is F#, which is sort of Rust with the minor matter of having a garbage collector, and inefficient iterators.
- arc619 6y agoWhy not just use Nim? The language is rapidly converging on an ownership model similar to rust anyway and has better metaprogramming, more compile targets and a high development velocity (plus faster compile times). Rust has a bigger ecosystem of course, but Nim's is pretty decent and you can use C, C++ and JS libs natively for anything else.
- fwsgonzo 6y agoWe really need a simpler language that has the same ownership model. I like Nim because I can compile it without threading support, and for RISC-V (albeit 64-bit, wish it had 32-bit support too..). Overall, I like it, but I could not justify using it in an enterprise setting without knowing that the direction of the language is going towards what is now the established minimum safety, which is borrow checking and no UB.
- gameswithgo 6y agoif you have borrow checking, you are going to inherit a lot of complexity in order to deal with the limitations it imposes. you could be simpler than rust, for sure, but bot as simple as say C or Go. Zig might be a language you are interested in. Simple like C with sensible ways of dealing with UB and bounds checking, as well as options instead of Nulls.
- planetis 6y agoZig is interesting but still very immature. Its memory model is manual management thus has no advantages over rust or nim. So it's marketed as better C (not any more than that).
- fm77 6y agofrom nim-lang/nim/nim/scanner.pas // This scanner is handwritten for efficiency. I used an elegant buffering // scheme which I have not seen anywhere else: // We guarantee that a whole line is in the buffer. Thus only when scanning // the \n or \r character we have to check wether we need to read in the next // chunk. Turbo Pascal uses the same buffering scheme, see https://turbopascal.org/processing-source-line-characters https://turbopascal.org/processing-source-line-characters Turbo Pascal though needs the crlf within the first 128 bytes otherwise the compiler quits with an error „Line too long".
- pjmlp 6y agoNo it doesn't. That isn't the official source code of Turbo Pascal. "Because of my interest in Pascal programming language and compilers I created a Turbo Pascal compiler written in Turbo Pascal - TPC16. This is a compiler compatible with the original Borland Turbo Pascal 7 command line compiler tpc.exe. Later I modified this compiler to compile under Delphi - TPC32. On the foundations of this compiler I later created Turbo51 - Pascal compiler for 8051 microcontrollers. Then I decided to publish the secrets of the first compiler I have created and this website was born. Here you can find the internals, algorithms and data structures of the Turbo Pascal 7 command-line compiler. You can also download the executable file of the TPC16 compiler. I created the compiler from scratch, but credits for the beauty of the language and for the exceptional elegance of the compiler go to Niklaus Wirth, Anders Hejlsberg and Borland." https://direct.turbopascal.org/about https://direct.turbopascal.org/about
- fm77 6y agoThis may sound like a contradiction to you because you are right, this is not the official source code of Turbo Pascal, but it is the source code of Turbo Pascal.... :-) Barry also stated this 5 years ago, see https://news.ycombinator.com/item?id=10202563 https://news.ycombinator.com/item?id=10202563 but that is not true. How can I be so sure? I reverse-engineered pretty much all Turbo Pascal versions starting with v4.0 all the way up to v8.0 (Delphi v1.0). I even disassembled the beta versions of Delphi, v7.9h and v7.9k, to see and study the transition from Turbo Pascal to Delphi. That being said, what you are looking at at turbopascal.org is an absolute mind-blowing reverse-engineering job. One hint is when you look for example at Procedure AddReferenceRecordForTypedConstant (UnitSegment, BlockRecord: Word; ReferenceFlags: TReferenceFlagSet; DX, TypedConstantOffset: Word); https://turbopascal.org/processing-typed-constants https://turbopascal.org/processing-typed-constants at the bottom of the page - where the author couldn't come up with a proper name for the DX register, so he left that identifier unchanged. If you disassemble Turbo Pascal "tpc.exe" and look for that subroutine you'll see that Anders Hejlsberg really used the DX register.... (I know, not really convincing...)
- zyxzevn 6y agoNow we need Nim with the super easy Lazarus user interface.
- squarefoot 6y agoThat one would be a game changer. Lazarus has been ported everywhere, from x86 PCs to ARM64 embedded boards.
- tonetheman 6y agoI have on and off played with Nim and independent of this article and this code had thought that it reminded me greatly of Pascal. With some Python thrown in there too.
- auxym 6y agoThe syntax makes it look like Python at a first glance. When you write it however, the type system makes it feel much more like Pascal.