Recent

Author Topic: Defintion code of keywords [SOLVED]  (Read 7341 times)

pascal111

  • Sr. Member
  • ****
  • Posts: 356
  • Un trabajo en equipo para programas serias.
Defintion code of keywords [SOLVED]
« on: May 20, 2021, 03:24:23 pm »
في الكود التالي ضغطت alt برِفقة زِر السهم إلى أعلى عندما كانت المؤشّرة تحت كلمة integer ففُتحت نافذة للكود المصدر الخاص بـ integer وفعلتُ نفس الشيء مع كلمة string ولكن لم يحدث هذه المرّة شيء ولم تُفتح نافذة لمعاينة الكود المصدر لـ string.

google translate:

"In the following code, I pressed the alt with the arrow button "key" up when the cursor was under the word integer, so a window was opened for the source code of the integer, and I did the same thing with the word string, but this time nothing happened and a window did not open to preview the source code for string."

Code: Pascal  [Select][+][-]
  1. var
  2.   i:integer;
  3.   s:string;
  4.  

objpas file:
Code: Pascal  [Select][+][-]
  1.  type
  2.        Integer  = longint;
  3.        PInteger = ^Integer;  
  4.  
« Last Edit: May 20, 2021, 06:52:24 pm by pascal111 »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Defintion code of keywords
« Reply #1 on: May 20, 2021, 04:20:35 pm »
That is because ObjPas redefines Integer to be an alias for LongInt, while String is (still) an intrinsic type.

You'll notice that in the IDE the word "String" is in bold-type, while "Integer" is in normal one: the first is a reserved word but the last is not. 
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

pascal111

  • Sr. Member
  • ****
  • Posts: 356
  • Un trabajo en equipo para programas serias.
Re: Defintion code of keywords
« Reply #2 on: May 20, 2021, 04:32:34 pm »
That is because ObjPas redefines Integer to be an alias for LongInt, while String is (still) an intrinsic type.

You'll notice that in the IDE the word "String" is in bold-type, while "Integer" is in normal one: the first is a reserved word but the last is not.

هل نفهم أنّ الكلمات المُسجّلة لا يُمكننا عرض الكود المصدر لها أو بمعنى آخر هناكـ كلمات يُمكن عرض أكوادها باعتبارها مبنيّة من غيرها أي بأدوات اللغة الأساسيّة بينما هناكـ كلمات لا يُمكن عرض أكواد المصدر الخاصّة بها ﻷنّ هذه الكلمات هي الوحدات الأوليّة والأساسيّة الداخلة في بناء غيرها؟

google translate:

"Do we understand that the registered "reserved" words cannot display the source code for them, or in other words there are words whose codes can be displayed as being constructed from others, i.e. (by mean) with basic language tools while there are words whose source codes cannot be displayed because these words are the primary and basic units involved in building others?"

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Defintion code of keywords
« Reply #3 on: May 20, 2021, 05:00:21 pm »
More or less, yes, though note that there is a difference between "reserved words" and what we might term "names" of types. Basically, the former cannot be redefined by the programmer, while the later can be more or less freely aliased to other types.

For example, you could do something like:
Code: Pascal  [Select][+][-]
  1. type
  2.   LongInt = Shortstring;
  3.   { from here on, type LongInt is used as String[255] }
  4.  
  5. var
  6.   a: LongInt;
  7.  
  8. begin
  9.   a := 'Makes no sense whatever, does it?';
  10.   WriteLn(a);
  11. end.
and the compiler will happily compile it and it'll run without a hitch. Note, though, that the same can not be done with String, because "String" is in fact a reserved word, not just a type name.

In the case of Integer, for example, its meaning depends on the mode (and target CPU): base modes (TP, FPC, ...) use the basic definition in System:
Code: Pascal  [Select][+][-]
  1. Integer = SmallInt;
while OOP modes (objfpc, delphi, etc) automatically include ObjPas and so use that definition you found:
Code: Pascal  [Select][+][-]
  1. Integer = LongInt;
.

ETA: All this, of course, is a very basic explanation; there are some nuances which can be seen in the docs and the source code.
« Last Edit: May 20, 2021, 05:23:11 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

pascal111

  • Sr. Member
  • ****
  • Posts: 356
  • Un trabajo en equipo para programas serias.
Re: Defintion code of keywords
« Reply #4 on: May 20, 2021, 05:29:01 pm »
حسناً! هذا بخصوص مثلاً أنواع البيانات type ولكن هاكـ مثالٌ آخر فمثلاً لا يُوجد كود مصدر يُعرض للكلمة المُسجّلة str ولكن هناكـ كود مصدر يُعرض لـ inttostr.

google translate:

"Okay! This is regarding, for example, types of data, but here is another example, for example, there is no source code displayed for the recorded "reserved" word str, but there is a source code displayed for inttostr."



Code: Pascal  [Select][+][-]
  1. function IntToStr(Value: Longint): string; {$ifdef SYSUTILSINLINE}inline;{$ENDIF}
  2. function IntToStr(Value: Int64): string; {$ifdef SYSUTILSINLINE}inline;{$ENDIF}
  3. function IntToStr(Value: QWord): string; {$ifdef SYSUTILSINLINE}inline;{$ENDIF}                
  4.  

Handoko

  • Hero Member
  • *****
  • Posts: 4327
  • My goal: build my own game engine using Lazarus
Re: Defintion code of keywords
« Reply #5 on: May 20, 2021, 05:35:52 pm »
Usually (I think: not always), the Pascal reserved words do not have source code.
https://wiki.freepascal.org/Reserved_words

And some 'special' commands (procedures/functions) do not have source code too. Like: write, writeln, read, readln, copy, concat, dec, inc, assigned, low, high, length, new, ord, succ, pred, ...
« Last Edit: May 20, 2021, 06:04:09 pm by Handoko »

pascal111

  • Sr. Member
  • ****
  • Posts: 356
  • Un trabajo en equipo para programas serias.
Re: Defintion code of keywords
« Reply #6 on: May 20, 2021, 06:04:06 pm »
Usually (I think: not always), the Pascal reserved words do not have source code.
https://wiki.freepascal.org/Reserved_words

And some 'special' commands (procedures/functions) do not have source code too. Like: write, writeln, read, readln, copy, concat, dec, inc, assigned, low, high, length, new, ord, succ, pred ...

كلامٌ منطقي!

google translate:

"Logical words!"

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Defintion code of keywords
« Reply #7 on: May 20, 2021, 07:17:24 pm »
And some 'special' commands (procedures/functions) do not have source code too. Like: write, writeln, read, readln, copy, concat, dec, inc, assigned, low, high, length, new, ord, succ, pred, ...

Mostly those are routines which can be called with many different types or a variable number of arguments (like Write, WriteLn, etc) and they are managed internally by the compiler, which takes them to the appropiate intrinsic or subroutines in System, if they are not inlined directly. They do have "source" (everything has!), only it's not as easy as opening a source file and looking for a function/procedure definition. ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

pascal111

  • Sr. Member
  • ****
  • Posts: 356
  • Un trabajo en equipo para programas serias.
Re: Defintion code of keywords
« Reply #8 on: May 20, 2021, 07:53:04 pm »
And some 'special' commands (procedures/functions) do not have source code too. Like: write, writeln, read, readln, copy, concat, dec, inc, assigned, low, high, length, new, ord, succ, pred, ...

Mostly those are routines which can be called with many different types or a variable number of arguments (like Write, WriteLn, etc) and they are managed internally by the compiler, which takes them to the appropiate intrinsic or subroutines in System, if they are not inlined directly. They do have "source" (everything has!), only it's not as easy as opening a source file and looking for a function/procedure definition. ;)

هل كلّ أكواد المصدر الخّاصة بالكلمات المُختلفة مكتوبة بالباسكال أم أنّ هناكـ كلمات مصادرها مكتوبة بلغة التجميع مثلاً أو بلغة الآلة.

google translate:

"Are all source codes for different words written in Pascal, or are there "ones whose" their source words written in assembly language, for example, or in machine language."

winni

  • Hero Member
  • *****
  • Posts: 2662
Re: Defintion code of keywords [SOLVED]
« Reply #9 on: May 20, 2021, 08:36:31 pm »
Hi!

If you a realy interested in the internal stuff of the intrinsics you can download the complete sources from

https://sourceforge.net/projects/freepascal/files/Source/3.2.0/

This contains also the compiler and the different platforms.

Winni

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Defintion code of keywords
« Reply #10 on: May 20, 2021, 09:43:31 pm »
Are all source codes for different words written in Pascal, or are there "ones whose" their source words written in assembly language, for example, or in machine language.

There is some assembly in the source (actually, quite a lot, which is normal for this kind of projects), but an overwhelming majority is written in Pascal itself. Note also that with a few "pure assembler" exceptions, most of the assembler is inside "Pascal" source files, using asm blocks or assembler routines.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

pascal111

  • Sr. Member
  • ****
  • Posts: 356
  • Un trabajo en equipo para programas serias.
Re: Defintion code of keywords [SOLVED]
« Reply #11 on: May 20, 2021, 10:15:21 pm »
Hi!

If you a realy interested in the internal stuff of the intrinsics you can download the complete sources from

https://sourceforge.net/projects/freepascal/files/Source/3.2.0/

This contains also the compiler and the different platforms.

Winni

حسناً! لستُ مؤهلاً بعد لفهم هذا المستوى ولكن من باب أخذ فكرةٍ عن الأمر فقد حمّلتُ الملف "fpc-3.2.0-x86_64-linux.tar" إن كان هذا ما تعنيه وفككت بعض الملفات المضغوطة والتي تحمل اسم "unit" في بداية اسمها ولكن لم أُشاهد أيّ كود بل بيانات غير مفهومة وهذا لمّا عرضتُ هذه الملفات بـ gedit Text Editor ولكن إنْ أردتَّ أنْ تزوّدني ببعض المعلومات عن كيفيّة عرض بعض الكود المصدر فسأكون شاكراً وكما ذكرتُ من قبل فلست مؤهلاً لفهم هذا المُستوى ولكن آخذُ فكرةً عن الأمر.

google translate:

"Okay! I am not qualified yet to understand this level, but for the sake of getting an idea about it, I downloaded the file "fpc-3.2.0-x86_64-linux.tar" if that was what it "you" meant and unzipped some compressed files with the name "unit" at the beginning of its name, but I did not see Any code, but incomprehensible data, and this is when I showed these files in the gedit Text Editor, but if you want to provide me with some information on how to display some of the source code, I will be thankful and as I mentioned before, I am not qualified to understand this level, but I take an idea about it."

pascal111

  • Sr. Member
  • ****
  • Posts: 356
  • Un trabajo en equipo para programas serias.
Re: Defintion code of keywords
« Reply #12 on: May 20, 2021, 10:27:26 pm »
Are all source codes for different words written in Pascal, or are there "ones whose" their source words written in assembly language, for example, or in machine language.

There is some assembly in the source (actually, quite a lot, which is normal for this kind of projects), but an overwhelming majority is written in Pascal itself. Note also that with a few "pure assembler" exceptions, most of the assembler is inside "Pascal" source files, using asm blocks or assembler routines.

من الذكي جدّاً والبديع أنّ اللغة تبني نفسها بنفسها.

google translate:

"It is very smart and wonderful that language builds itself (by itself)."

 

TinyPortal © 2005-2018