Recent

Author Topic: Programs writing programs? What?? :o :o  (Read 3071 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 8186
Re: Programs writing programs? What?? :o :o
« Reply #15 on: January 18, 2025, 09:33:16 am »
P-code is NOT the same as interpreted. Early Pascal started life as a p-code compiler often mistakenly referred to as P-code interpreter, which is merely the runtime. Think of p-code (or java byte code and wasm for that matter) as compiling for a virtual CPU. P-code has many traits of natively compiled code and nothing to do with dynamic, true interpreted languages. Things like reflection for compiled languages(.net, java, pascal rtti) were not yet known at the time.

I didn't say it was, and I'm fully aware of the history. I'm also adequately aware of the technology behind other early (and for that matter later) Wirth languages, what equipment he used, and some of the other people he involved (specifically, some early symbol table work is informally traceable to Knuth).

So even if Euler and early versions of Pascal could possibly have had access to the symbol table in at least some implementations, Wirth had the good sense not to allow that since he recognised that it would not have been universally portable.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

cdbc

  • Hero Member
  • *****
  • Posts: 1808
    • http://www.cdbc.dk
Re: Programs writing programs? What?? :o :o
« Reply #16 on: January 18, 2025, 09:36:56 am »
Hi
Just in case TS/OP is aiming in this direction, Hallvard Vassbotn has written about 'generating / executing code on the fly' amo. HERE. ...just scroll down a little.
Our own @PascalDragon has also discussed it with others HERE
I concur, the description is a wee bit vague...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Thaddy

  • Hero Member
  • *****
  • Posts: 16520
  • Kallstadt seems a good place to evict Trump to.
Re: Programs writing programs? What?? :o :o
« Reply #17 on: January 18, 2025, 09:56:17 am »
More in general:programs that write programs or part of it (code generators) are probably just a week "younger" than the programming language: most professionals of us have written code generators to solve repetitive tasks may times. Or use compiler generators, which is the same in a more advanced way. See the calculator example in the wiki. Other examples in the same family are the RegEx engines. And the compiler itself. A self-hosting compiler is a compiler that writes itself...
Another example, predating AI, are the rule based languages, where you define rules in almost natural language and the compiler obeys.
« Last Edit: January 18, 2025, 10:06:46 am by Thaddy »
But I am sure they don't want the Trumps back...

Thaddy

  • Hero Member
  • *****
  • Posts: 16520
  • Kallstadt seems a good place to evict Trump to.
Re: Programs writing programs? What?? :o :o
« Reply #18 on: January 18, 2025, 10:09:05 am »
Knuth, also known as Canut, the first viking king of England?  :o
But I am sure they don't want the Trumps back...

cdbc

  • Hero Member
  • *****
  • Posts: 1808
    • http://www.cdbc.dk
Re: Programs writing programs? What?? :o :o
« Reply #19 on: January 18, 2025, 10:19:59 am »
Hehehe, You're right.
"Canut" is an actual word in old/ancient Danish, spelled 'Kanut' and meaning 'Dude' / 'Fell(ar)(ow)'.
Take it from a fellow viking  ;D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

gidesa

  • Full Member
  • ***
  • Posts: 158
Re: Programs writing programs? What?? :o :o
« Reply #20 on: January 18, 2025, 12:31:17 pm »
A complete example using extended RTTI on record. Require FPC 3.3.1 or newer.
Note the directive $RTTI that  insert record fields type info in program. Without that, no
type info is added.
Code: Pascal  [Select][+][-]
  1. program txRttiRecord;
  2. {$RTTI EXPLICIT FIELDS([vcPublic])}
  3. uses
  4.   SysUtils, Classes,   Rtti;
  5.  
  6. type
  7.   TMyRecord = record
  8.     var1: string;
  9.     var2: string;
  10.     var3: string;
  11.     var4: string;
  12.     var5: string;
  13.   end;
  14.  
  15. function GetFieldValue(const aRecord: TMyRecord; const aField: TRttiField; var aValue: TValue): Boolean;
  16. begin
  17.   Result:=False;
  18.   writeln('field: ', afield.Name, ' of type: ', afield.FieldType.Name);
  19.   aValue := aField.GetValue(@arecord);
  20.   Result:=True;
  21. end;
  22.  
  23.  
  24. function GetFields(const aRecord: TMyRecord): TStringList;
  25. var
  26.   C: TRttiContext;
  27.   rttiType: TRttiType;
  28.   LField: TRttiField;
  29.   fval: TValue;
  30. begin
  31.   Result:=nil;
  32.   rttiType := C.GetType(TypeInfo(TMyRecord));
  33.   for LField in rttiType.GetFields do
  34.     begin
  35.        if Result = nil then
  36.        begin
  37.           Result:=TStringList.Create;
  38.        end;
  39.        if GetFieldValue(aRecord, LField, fval) then
  40.        begin
  41.            Result.Add(fval.AsString);
  42.        end;
  43.     end;
  44. end;
  45.  
  46. var
  47.   rc: TMyRecord;
  48.   sl: TStringList;
  49.   ss: string;
  50. begin
  51.   try
  52.     rc.var1:='primo';
  53.     rc.var2:='secondo';
  54.     rc.var3:='terzo';
  55.     rc.var4:='quarto';
  56.     rc.var5:='quinto';
  57.  
  58.     sl:=GetFields(rc);
  59.     writeln('Values of current fields: ');
  60.     if sl<>nil then
  61.     begin
  62.       for ss in sl do
  63.         Writeln(ss);
  64.       sl.Free;
  65.     end;
  66.     Readln;
  67.   except
  68.     on E: Exception do
  69.       Writeln(E.ClassName, ': ', E.Message);
  70.   end;
  71. end.
  72.  
  73. end.                                          
  74.  

PascalDragon

  • Hero Member
  • *****
  • Posts: 5851
  • Compiler Developer
Re: Programs writing programs? What?? :o :o
« Reply #21 on: January 18, 2025, 04:49:18 pm »
Pascal is not an interpreted (*) language,

Most of the early implementations were interpreted. Anything that targets .Net or Javascript arguably still is.

Both .Net and JavaScript use Just-In-Time compilation (at least nowadays), not interpretation and at least the former also uses Ahead-Of-Time compilation.

Just in case TS/OP is aiming in this direction, Hallvard Vassbotn has written about 'generating / executing code on the fly' amo. HERE. ...just scroll down a little.
Our own @PascalDragon has also discussed it with others HERE
I concur, the description is a wee bit vague...

From what I see reworking the code so that one can use a loop or at least RTTI is a better approach than manually creating machine code and executing that (which is what my post had been about).

MarkMLl

  • Hero Member
  • *****
  • Posts: 8186
Re: Programs writing programs? What?? :o :o
« Reply #22 on: January 18, 2025, 05:06:41 pm »
Both .Net and JavaScript use Just-In-Time compilation (at least nowadays), not interpretation and at least the former also uses Ahead-Of-Time compilation.

Yes, I know (and .Net was oriented towards JITC from its earliest days, unlike Java). But compared with the length of time that bytecode interpretation has been around (early '60s), that sort of thing is a /very/ recent development.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

gidesa

  • Full Member
  • ***
  • Posts: 158
Re: Programs writing programs? What?? :o :o
« Reply #23 on: January 18, 2025, 06:40:42 pm »
Pascal is not an interpreted (*) language,
Most of the early implementations were interpreted. Anything that targets .Net or Javascript arguably still is.

Pure interpreted language are rare. I remember that also Commodore 64 Basic first translated keywords to numeric "tokens", when saving program to memory!  :D
« Last Edit: January 18, 2025, 06:56:44 pm by gidesa »

MarkMLl

  • Hero Member
  • *****
  • Posts: 8186
Re: Programs writing programs? What?? :o :o
« Reply #24 on: January 18, 2025, 07:50:40 pm »
Pure interpreted language are rare. I remember that also Commodore 64 Basic first translated keywords to numeric "tokens", when saving program to memory!  :D

Yes, that was standard for MS BASIC.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018