3 ms·
from 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:
by fm77 6y ago
from 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...)
- sim_card_map 6y agoInteresting! Isn't original TP7 source code available? https://github.com/shidel/DustyTP7 https://github.com/shidel/DustyTP7
- elvis70 6y agoYou have linked a source code repository of programs and units written for TP7. The sources of TP6 have leaked a few years ago. Search for exmortis on HN.
- geofft 6y agoIf I understood right - this is a "white box" reimplementation of the real Turbo Pascal, which uses the same algorithms and structures and control flow as the real one (and therefore should be bug-for-bug compatible) but is written in Pascal instead of assembly? That is, the "DX" argument there isn't actually passed in register DX, but it represents a function call in real Turbo Pascal that passed the same semantic contents in register DX?
- fm77 6y agoI don't know what a "white box" reimplementation is (white-box cryptography?) but I guess you meant a clean room implementation (https://en.wikipedia.org/wiki/Clean_room_design https://en.wikipedia.org/wiki/Clean_room_design) which I believe this is not the case here (I am wild guessing though). For a clean room implementation you need at least two guys, one reverse engineer who writes down his findings and a guy who takes that information and reimplements the same functionality according to the information the reverse-engineer provides. But you are right in that it uses the same algorithms, structures and control flow as the real Turbo Pascal and therefore should be bug-for-bug compatible but is written in Pascal instead of assembly.
- elvis70 6y agoAlso, the default buffer size of Text and file (without specifying a type) types is 128 bytes as well for the same historical reason: CP/M, where files are divided in records of 128 bytes.