Re: [fpc-pascal] Problem compiling

2012-08-06 Thread Marco van de Voort
In our previous episode, Jonas Maebe said:
  
  Free Pascal Compiler version 2.7.1 [2012/05/22] for i386 
  
  Anyone have
  an idea what could be wrong? 
 
 Building development versions of FPC always has been and always will be
 guaranteed to work only if you start with the latest *release* version.

Indeed. This is btw typically the error you get when compiling the fixes
branc with trunk
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Problem compiling

2012-08-06 Thread Nico Erfurth
On 05.08.12 23:46, dhkblas...@zeelandnet.nl wrote:

 I get:
 
 text.inc(199,34) Error: Illegal type conversion: Text to TextRec
 
 after updating the compiler sources from SVN.
 
 Free Pascal Compiler version 2.7.1 [2012/05/22] for i386
 
 Anyone have an idea what could be wrong?

You have to use the latest release version to compile svn-trunk, which
is 2.6.0.

Nico

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] printing each Friday the 13 using Pascal

2012-08-06 Thread ik
Hi list,

A friend of mine started a hobby project:
Printing every Friday the 13, in a range of 5
yearshttp://blogs.perl.org/users/sawyer_x/2012/07/yet-another-friday-the-13th.html
.

I lack of the time for doing it at the moment, and I wish to add to his
github https://github.com/xsawyerx/yet-another-friday-the-13th/ also
Pascal (and show how much simpler it is then C) implementation.
Is there anyone here that might be interested in this ?

Ido
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

[fpc-pascal] Re: printing each Friday the 13 using Pascal

2012-08-06 Thread leledumbo
Converting one of the answers there...

uses
  SysUtils;
const
  StartingYear = 2012;
var
  Year,Month: Byte;
  Date: TDateTime;
begin
  for Year in [0 .. 5] do begin
for Month in [1 .. 12] do begin
  Date := EncodeDate(Year,Month,13);
  if DayOfWeek(Date) = 5 then begin
WriteLn(FormatDateTime('-MM-DD',Date));
  end;
end;
  end;
end.



--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/printing-each-Friday-the-13-using-Pascal-tp5710496p5710497.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Re: printing each Friday the 13 using Pascal

2012-08-06 Thread leledumbo
Sorry, missing one thing: Date := EncodeDate(StartingYear + Year,Month,13); 



--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/printing-each-Friday-the-13-using-Pascal-tp5710496p5710498.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] printing each Friday the 13 using Pascal

2012-08-06 Thread Gerhard Scholz
a quick and dirty solution


- Original Message - 
From: ik
To: FPC-Pascal users discussions
Sent: Monday, August 06, 2012 1:19 PM
Subject: [fpc-pascal] printing each Friday the 13 using Pascal


Hi list,

A friend of mine started a hobby project:
Printing every Friday the 13, in a range of 5 years.

I lack of the time for doing it at the moment, and I wish to add to his
github also Pascal (and show how much simpler it is then C) implementation.
Is there anyone here that might be interested in this ?

Ido




___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Friday13.pas
Description: Binary data
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Re: printing each Friday the 13 using Pascal

2012-08-06 Thread Howard Page-Clark

On 06/8/12 1:32, leledumbo wrote:

Minor amendment needed to leledumbo's code to give Friday, and a five 
year range:


uses SysUtils;

const startYr: word = 2012;

var dt: TDateTime;
year, month: word;

begin
  for year in [0..4] do
   for month in [1..12] do
begin
  dt := EncodeDate(startYr + year, month, 13);
  if (DayOfWeek(dt) = 6) then
   begin
 writeln(FormatDateTime(', DD-MM-',dt));
   end;
end;
end.

Howard
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Rainer Stratmann
procedure p1;
begin
 ...
end;



How to get all caller adresses of p1 in a program before p1 is executed?

For example p1 is called from 20 different places in a program.
Then I need the 20 caller adresses.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Howard Page-Clark

On 06/8/12 3:26, Rainer Stratmann wrote:

procedure p1;
begin
  ...
end;



How to get all caller adresses of p1 in a program before p1 is executed?

For example p1 is called from 20 different places in a program.
Then I need the 20 caller adresses.


if by address you mean line number, then use the Find In Files dialog. 
Close all files in the Source Editor except the one containing p1 
procedures.

In the Text to Find field type p1.
In the Where radiogroup select Search all open files.
Should give you a list of every occurrence of p1.

Howard

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Martin

On 06/08/2012 15:26, Rainer Stratmann wrote:

procedure p1;
begin
  ...
end;



How to get all caller adresses of p1 in a program before p1 is executed?

For example p1 is called from 20 different places in a program.
Then I need the 20 caller adresses.



At run time, or design time?

at design time, there is find in files, codetools find references, or 
add deprecated and let compile and see the warnings.


At runtime, you can get the address, and if you have debug info, also 
the unit and line.

Run in debugger and use the stack window.
Or use (in your source code , needs console , or logfile) dumpstack();
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Rainer Stratmann
Am Monday 06 August 2012 18:43:04 schrieb Martin:
  How to get all caller adresses of p1 in a program before p1 is executed?
 
  For example p1 is called from 20 different places in a program.
  Then I need the 20 caller adresses.

 At run time, or design time?

At runtime.
I ment the (memory) caller adresses.

If p1 is executed I can get the caller adress with the rtl function:

get_caller_addr( get_frame );

But I want to scan the whole program before all p1's are called by the program 
to get all caller adresses of p1.

May be I write an own scan program to find all calling places which calls p1.

For that I need the memory adress where the program starts. And the length.

 At runtime, you can get the address, and if you have debug info, also
 the unit and line.
 Run in debugger and use the stack window.
 Or use (in your source code , needs console , or logfile) dumpstack();

I would like to do it without debug info.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Sven Barth

On 06.08.2012 19:28, Rainer Stratmann wrote:

Am Monday 06 August 2012 18:43:04 schrieb Martin:

How to get all caller adresses of p1 in a program before p1 is executed?

For example p1 is called from 20 different places in a program.
Then I need the 20 caller adresses.


At run time, or design time?


At runtime.
I ment the (memory) caller adresses.

If p1 is executed I can get the caller adress with the rtl function:

get_caller_addr( get_frame );

But I want to scan the whole program before all p1's are called by the program
to get all caller adresses of p1.

May be I write an own scan program to find all calling places which calls p1.

For that I need the memory adress where the program starts. And the length.



You know that scanning the binary code for calls is platform dependant? 
So you'd need to write that code for every CPU you want to support. Also 
this is much harder to do for CISC CPUs like x86 than for RISC CPUs 
(ARM, MIPS, etc), because the former have variable length opcodes. So 
you'd basically need to write a full blown dissembler...


Maybe it would be more interesting to know why you need this beforehand?

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Rainer Stratmann
Am Monday 06 August 2012 19:34:23 schrieb Sven Barth:

 You know that scanning the binary code for calls is platform dependant?
Yes.
[calling opcode] [calleradress]
calling opcode can differ and the byteorder of the adress can differ.

 So you'd need to write that code for every CPU you want to support. Also
 this is much harder to do for CISC CPUs like x86 than for RISC CPUs
 (ARM, MIPS, etc), because the former have variable length opcodes. So
 you'd basically need to write a full blown dissembler...
It seems hard. By now I support only 80x86 CPU's.

 Maybe it would be more interesting to know why you need this beforehand?

So you mean you can convince me to find another solution?

I need this for internationalisation.

p1( 'german snippet' );
is put in a table (caller adress and text) if calling the first time and 
translated in other languages.

If I have a list of all p1's I know which language snippet was already called 
and which snippet was not yet translated (called).

If there is a new snippet in the program and called at least one time it is 
added to the must be translated list.


Another method would be if it would be possible to inc a constant at compile 
time!

const counter = 0;

p1( [counter++](at compiletime!) , 'german snippet');

But this is an insurmountable obstacle for the compilerprogrammers I think.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Sven Barth

On 06.08.2012 19:56, Rainer Stratmann wrote:

Am Monday 06 August 2012 19:34:23 schrieb Sven Barth:


You know that scanning the binary code for calls is platform dependant?

Yes.
[calling opcode] [calleradress]
calling opcode can differ and the byteorder of the adress can differ.



The problem here is the following:

Let's suppose the opcode for calling a function on x86 CPUs is 0xCA11. 
Now you scan through the code looking for 0xCA11 followed by 4 bit. The 
problem now is that without knowing the context of a found location 
0xCA11 you don't know whether it is really a call opcode or some 
immediate data that was passed to some previous opcode. This is also an 
obstacle experienced by VM developers for x86 instructions (or CISC 
instructions in general). For RISC instruction sets this is less 
complex, but the problem exists there as well.



So you'd need to write that code for every CPU you want to support. Also
this is much harder to do for CISC CPUs like x86 than for RISC CPUs
(ARM, MIPS, etc), because the former have variable length opcodes. So
you'd basically need to write a full blown dissembler...

It seems hard. By now I support only 80x86 CPU's.


Maybe it would be more interesting to know why you need this beforehand?


So you mean you can convince me to find another solution?

I need this for internationalisation.

p1( 'german snippet' );
is put in a table (caller adress and text) if calling the first time and
translated in other languages.

If I have a list of all p1's I know which language snippet was already called
and which snippet was not yet translated (called).

If there is a new snippet in the program and called at least one time it is
added to the must be translated list.


Another method would be if it would be possible to inc a constant at compile
time!

const counter = 0;

p1( [counter++](at compiletime!) , 'german snippet');

But this is an insurmountable obstacle for the compilerprogrammers I think.


Out of curiosity: why don't you use resourcestrings?

And why do you need the count of calls (or usages)?

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Sven Barth

On 06.08.2012 21:48, Rainer Stratmann wrote:

Out of curiosity: why don't you use resourcestrings?


It seems that is has not the flexibility and simplicity (in its entirety)
that I want.


I would not call your method simple

It may is in the beginning more difficult to implement, but if it runs once I
would say this can not get much more simpler.

You only have to put p1( ) around your text snippet. That is it!
The function returns the right language.


Somehow this sounds like the GNU GetText function _() works. With the 
exception that the text which has to be translated is simply searched by 
looking through the source code for _(some text)...


Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Martin

On 06/08/2012 20:18, Rainer Stratmann wrote:

I do not understand this ...
What is the content of the stack?
Which file 'f'?
Is it read from or write to file 'f'?



f is just the STDOUT or logfile where the list of addresses is written 
to. You would likely use an array instead...


But let me say: I am with everyone else. Using stack/caller info is the 
wrong(est) way.


And if you need to ask What is the content of the stack? Then you 
should not use it.
All this functions are very low level. Usinc this kind of data implies 
having a very good understanding of the way the stack is organized.


---

Why do you not keep al ist of all the snippets you have seen (keep a 
copy of the text (strings are copy on write, so you do not need a real 
copy, just a 2nd string of the same text).

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Marco van de Voort
In our previous episode, Sven Barth said:
  The function returns the right language.
 
 Somehow this sounds like the GNU GetText function _() works. With the 
 exception that the text which has to be translated is simply searched by 
 looking through the source code for _(some text)...

Note that one of the problems of this is that it makes your text also the
key that identifies an unique piece of text. 

While I use (dx)gettext myself, I still think that is one of the
disadvantages.

P.s. the _() is not necessary with D2009+ anymore
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Aleksa Todorovic
On Mon, Aug 6, 2012 at 9:48 PM, Rainer Stratmann
rainerstratm...@t-online.de wrote:
 Am Monday 06 August 2012 21:26:24 schrieb Jonas Maebe:
 It doesn't work like that. Regular calls use relative offsets on most (if
 not all) architectures we support. And in some cases we generate
 position-independent code, so then you'll have look at GOT entries to
 figure out the address. Then there are of course calls via procedure
 variables. And there's probably a ton more special cases I'm not thinking
 of right now.

 Would it then be possible to implement a counter (const) which is increased at
 compile time?
 p1( increasedcounteratcompiletime , 'Textsnippet' ) ?

 I guess it is not possible.

  Out of curiosity: why don't you use resourcestrings?
 
  It seems that is has not the flexibility and simplicity (in its entirety)
  that I want.

 I would not call your method simple
 It may is in the beginning more difficult to implement, but if it runs once I
 would say this can not get much more simpler.

 You only have to put p1( ) around your text snippet. That is it!
 The function returns the right language.

 and would also strongly recommend to
 use resourcestrings instead. Their purpose is exactly to make it easy to
 translate the strings in a program.
 That means more work to give every text snippet explicitly a name which is not
 necessary with my solution. And that means also less flexibility.

 The resourcestring solution does not record the date and time when a text was
 changed and so on...

How about using memory for string constant to store pointer to
localized version - something like example below? Note: target
platform needs to support writable string constants, and there should
be enought ~ characters at the beginning of the string to store value
of pointer (4x~ for 32-bit pointers, 8x~ for 64bit pointers). If you
can meet these two conditions, you don't need to know internals of
compiler or any implementation detail.

program test_str_36;

uses
  sysutils;

function s(str: pchar): pchar;
var
  str2: pchar;
begin
  if str[0] = '~' then
  begin
// string is not localized
str2 := strnew('numero'); // localized version
ppchar(str)^ := str2;
  end;
  result := ppchar(str)^;
end;

var
  i: integer;
begin
  for i := 1 to 10 do
  begin
writeln(s('number'), ' ', i);
  end;
end.


 ___
 fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
 http://lists.freepascal.org/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Rainer Stratmann
Am Monday 06 August 2012 22:17:11 schrieb Martin:
 But let me say: I am with everyone else. Using stack/caller info is the
 wrong(est) way.
I fully agree.
 And if you need to ask What is the content of the stack? Then you
 should not use it.
 All this functions are very low level. Usinc this kind of data implies
 having a very good understanding of the way the stack is organized.


 Why do you not keep al ist of all the snippets you have seen (keep a
 copy of the text (strings are copy on write, so you do not need a real
 copy, just a 2nd string of the same text).

Can you explain it more?
I want not search through the sourcecode, because it makes it less easy.


All I need is all caller adresses of p1 in the program.
Or an incremented counter at compiletime.
Both seems impossible by now.

If p1 is called then I can see which snippet was not yet called.
If the compilerincremented counter at the end is 500, then I need 500 snippet 
entries and I can see which entry already was called by the program during 
execution.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Martin

On 06/08/2012 21:39, Rainer Stratmann wrote

Can you explain it more?
I want not search through the sourcecode, because it makes it less easy.

How does an address like $040012a help you find the source?


All I need is all caller adresses of p1 in the program.
Or an incremented counter at compiletime.
Both seems impossible by now.

If p1 is called then I can see which snippet was not yet called.
If the compilerincremented counter at the end is 500, then I need 500 snippet
entries and I can see which entry already was called by the program during
execution.



I am still trying to understand what exactly you try to archive.

What I understand sofar:

-  your program has a fixed amount of text snippets in a given language
  QUESTION: are those snippets unique? Or can there be 2 individual 
snippets, that have the same text, but must be treated as different?

-  you want to implement a method that translates them
- you want to ensure this method was called exactly (or is it at least?) 
once, for each snippet.


For some reason that I do not understand yet, you need a unique 
identifier for each snippet.


Well if the text of the snippets is unique, then you can use the text 
itself.

So instead of using $040012a as token, you can use 'hello world'

--
That is, I still do not see, why you go this way at all.
You must have a list of all translations somewhere, and somehow you 
translate each snippet. For updating translations, you can

1) add each snippet that has no translation to a list
2) mark each translation, once it was used, and when the app finishes 
list all translations that where not used.


---
Or explain again what you try to do?


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Rainer Stratmann
Am Monday 06 August 2012 22:37:08 schrieb Aleksa Todorovic:
 program test_str_36;

 uses
   sysutils;

 function s(str: pchar): pchar;
 var
   str2: pchar;
 begin
   if str[0] = '~' then
   begin
 // string is not localized
 str2 := strnew('numero'); // localized version
 ppchar(str)^ := str2;
   end;
   result := ppchar(str)^;
 end;

 var
   i: integer;
const prestr = '';
 begin
   for i := 1 to 10 do
   begin
 writeln( s( prestr + 'number' ),  ' ' ,   i);
   end;
 end.

That seems somehow interesting.
But you have to put it everywhere in front.
May be a macro can do it so that you have only s() left.
And may be (but not very likely when reading the statement of Jonas) you can 
search the whole program for '' to get the caller adresses of s().
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Martin

On 06/08/2012 21:57, Martin wrote:


I am still trying to understand what exactly you try to archive.


Ok, I read one of the other posts: Do you need to ensure to handle each 
snippet only once?



Are *ALL* snippets constants?
either
  const t1 = 'abc';
or
  foo('text')

and NEVER result of
- a function snip := copy('aaa',1,2) or snip := foo();
- any operation, such as concatenation: snip := s1+s2;


If the are: use the address of the first char in the snippet
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Rainer Stratmann
Am Monday 06 August 2012 22:57:42 schrieb Martin:
 On 06/08/2012 21:39, Rainer Stratmann wrote

  Can you explain it more?
  I want not search through the sourcecode, because it makes it less easy.

 How does an address like $040012a help you find the source?

If I have a list with all caller adresses then I know which one was already 
called and I can faster search this if only handle the adress (speed reason).

  All I need is all caller adresses of p1 in the program.
  Or an incremented counter at compiletime.
  Both seems impossible by now.
 
  If p1 is called then I can see which snippet was not yet called.
  If the compilerincremented counter at the end is 500, then I need 500
  snippet entries and I can see which entry already was called by the
  program during execution.

 I am still trying to understand what exactly you try to archive.

I am sure you mean achieve :-)

 What I understand sofar:

 -  your program has a fixed amount of text snippets in a given language
yes
QUESTION: are those snippets unique? Or can there be 2 individual
 snippets, that have the same text, but must be treated as different?
both, I will able to handle it p1, p_unique, and so on.
 -  you want to implement a method that translates them
yes
 - you want to ensure this method was called exactly (or is it at least?)
 once, for each snippet.
No.
I want to register a call.
I (fast) search through the adress-table every time. If the adress is in the 
table then I have already the translated pchar at array nr x. If not I have 
to translate the string and add the caller adress to the table and the pchar 
to the translated string.
Further on I can do with the table and string snippets what I want. If I have 
an Idea in the future I can implement. For example adding date and time of 
changes and so on.

 For some reason that I do not understand yet, you need a unique
 identifier for each snippet.
 Well if the text of the snippets is unique, then you can use the text
 itself.
 So instead of using $040012a as token, you can use 'hello world'
see above.

 --
 That is, I still do not see, why you go this way at all.
 You must have a list of all translations somewhere, and somehow you
 translate each snippet.
I want the text to stay in the sourcecode and not want to have some kind of 
excel-list.
 For updating translations, you can 
 1) add each snippet that has no translation to a list
 2) mark each translation, once it was used, and when the app finishes
 list all translations that where not used.
For that I have to call every s() in the program, because I do not have a 
fixed list.
To know if every s() in the program was called it would be good to know every 
presence of s().
I tried also a kind of excel list with unique identifyer for each snippet, but 
for me it seems not flexible enough and much work instead of putting s() 
around every snippet.

 ---
 Or explain again what you try to do?
The translation should be done by a web based interface from the inhabitant of 
every country (simplicity, less work for me). So I need a registration and I 
need to be flexible. Snippets can change, and so on. It would be good to save  
the older snippets if one has changed... All this can be implemented. Date  
Timestamp...
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Rainer Stratmann
Am Monday 06 August 2012 23:36:10 schrieb Martin:
 On 06/08/2012 21:57, Martin wrote:
  I am still trying to understand what exactly you try to archive.

 Ok, I read one of the other posts: Do you need to ensure to handle each
 snippet only once?


 Are *ALL* snippets constants?
yes, but they are most time immediately in s( 'snippet' );
 either
const t1 = 'abc';
 or
foo('text')
Foo I don't know by now. So guess I will not use it.

 and NEVER result of
 - a function snip := copy('aaa',1,2) or snip := foo();
 - any operation, such as concatenation: snip := s1+s2;
right.

 If the are: use the address of the first char in the snippet
?
But then I do not have a list of all caller adresses of s() which I try to 
get.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Sven Barth

On 06.08.2012 22:22, Marco van de Voort wrote:

In our previous episode, Sven Barth said:

The function returns the right language.


Somehow this sounds like the GNU GetText function _() works. With the
exception that the text which has to be translated is simply searched by
looking through the source code for _(some text)...


Note that one of the problems of this is that it makes your text also the
key that identifies an unique piece of text.

While I use (dx)gettext myself, I still think that is one of the
disadvantages.

P.s. the _() is not necessary with D2009+ anymore


Which reminds me: Delphi uses a different style of resource string 
system. In FPC you can set up the resourcestrings table based while in 
Delphi a LoadResString function is used each time a resourcestring is 
accessed. You can override the default functionality by setting a 
corresponding procedure variable. See also here 
http://docwiki.embarcadero.com/Libraries/en/System.LoadResString


It wouldn't solve the problem of declaring a resourcestring though and 
also the function doesn't get the resource string identifier as the 
table based function in FPC currently gets... so in that regard the 
system seems more limited (while it has some positive aspects as well).


Regards,
Sven

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Martin

On 06/08/2012 22:46, Rainer Stratmann wrote:

If the are: use the address of the first char in the snippet

?
But then I do not have a list of all caller adresses of s() which I try to
get.



I still do not understand what is so special about the caller address? 
Furthermore, you said yourself, you do not need it. You can also live 
withe a number that the compiler generates at compilation time.


so if you had
p(next_compile_time_number, 'text');

then all p gets is 109, 'text'
if that 109 does help, why not the address of the 1st char?


---
I know there is still something about your idea that I havent got 
which makes this a bit hard.


Lets take a step back:

Why do you not just store all snippets in a stringlist, if p saw them? 
(speed should not be a reason, that can be dealt with)


You can always extend the list to store additional info per field.

---
ps
foo = placeholder
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Mark Morgan Lloyd

Rainer Stratmann wrote:


All I need is all caller adresses of p1 in the program.


You might be able to do that sort of thing by running the program with a 
profiler and analyzing all captured stacks. But it would be a vast 
amount of effort, and unless you could guarantee 100% coverage (i.e. 
feeding the program all possible input states etc.) you'd probably miss 
combinations.


You're left with the options of learning how to use resourcestrings 
effectively, or using a language such as Smalltalk where the senders of 
a message are known in advance.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] virtual class var?

2012-08-06 Thread Andrew Haines
Hi, is it possible to have a virtual class variable? I want to have a
pointer available per class that can be a different value.
Something like this:

  TA = class
class var Foo: TObject; virtual;
  end;

  TB = class(TA)
class var Foo: TSpecialObject; override;
  end;
 

I have in mind multiple levels of inheritance. I am storing a vmt like
record/object in the variable, so the variable the child class overrides
will be compatible with the ancestor class. It's possible there may be
many instances of the objects so I do not want to create an variable per
instance if I can help it.

Regards,

Andrew
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] virtual class var?

2012-08-06 Thread Andrew Haines
My current idea for a solution is here:

http://pastebin.com/P3JsDQ03

Can anyone think of something with less code? I guess I could save a
little if I skip the property and directly use GetVMT and SetVMT.

Regards,

Andrew
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] virtual class var?

2012-08-06 Thread Paul Ishenin

07.08.12, 8:18, Andrew Haines wrote:

Hi, is it possible to have a virtual class variable? I want to have a
pointer available per class that can be a different value.
Something like this:

   TA = class
 class var Foo: TObject; virtual;
   end;

   TB = class(TA)
 class var Foo: TSpecialObject; override;
   end;


Class variable is stored the same way as a regular variable and has the 
only difference is that it can be accessible with the class name prefix. 
The thing you need requires different implementation - something like 
storing a virtual class variable in VMT. There is no implementation for 
that.


Best regards,
Paul Ishenin
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] virtual class var?

2012-08-06 Thread Andrew Haines
On 08/06/12 23:02, Paul Ishenin wrote:

 
 Class variable is stored the same way as a regular variable and has the
 only difference is that it can be accessible with the class name prefix.
 The thing you need requires different implementation - something like
 storing a virtual class variable in VMT. There is no implementation for
 that.
 
 Best regards,
 Paul Ishenin

What is the current implementation?

I would guess that class vars are stored in the vmt already...

Please correct me if I've got this wrong.

Current classes have a structure containing partially the following:

TClassInstance = record
vmt: Pointer;
{Space for parent class variables are stored here followed by variables
declared for this object}
variable1: SomeType;
variable2: SomeType;
etc.
end;


TClassVMT = record
  parent_class_vmt: Pointer;
  virtual_procs: array[0..n] of pointer;
  class_var_1: Sometype;
  class_var_2: Sometype;
  etc...
end;

Is this right?

Thanks,

Andrew
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] virtual class var?

2012-08-06 Thread Paul Ishenin

07.08.12, 11:24, Andrew Haines wrote:

What is the current implementation?

I would guess that class vars are stored in the vmt already...


No, class var and regular variable has no difference except the scope. 
It is a static variable which is shared between all instances and 
descendants - so why should it be stored in vmt or near it?


Best regards,
Paul Ishenin

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] virtual class var?

2012-08-06 Thread Andrew Haines
Ahhh ok I understand now. , Thank you.
-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

Paul Ishenin paul.ishe...@gmail.com wrote:

07.08.12, 11:24, Andrew Haines wrote:
 What is the current implementation?

 I would guess that class vars are stored in the vmt already...

No, class var and regular variable has no difference except the scope. 
It is a static variable which is shared between all instances and 
descendants - so why should it be stored in vmt or near it?

Best regards,
Paul Ishenin

_

fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal