Recent

Author Topic: light pascal  (Read 22345 times)

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: light pascal
« Reply #15 on: December 23, 2019, 08:33:39 pm »
i get Hard Fault in line " buf^ := p^ "
Any attempt to write to 'buf ^' results in an error.

The notation something^ applies only to a pointer: it's meant to dereference it. Your buf variable, though, is an array: you should access/set it by using an index into the array, as in:
buf[x] := p^

In C it's different because an "array" is almost exactly the same as a pointer.
« Last Edit: December 23, 2019, 08:36:35 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.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: light pascal
« Reply #16 on: December 23, 2019, 08:37:22 pm »
I have written a similar program in C for uC Cortex-M0. And my point is that in Pascal I haven't even achieved half of the functionality, and I'm already exceeding 5kB Flash more than the one written in C.
With such constraints you indeed need to lay off the automated types. (though I would avoid textual I/O in microcontrollers in general)
Quote
It worries me very much
I am slowly beginning to come to the conclusion that Pascal is not suitable for writing in microcontrollers.
Pascal and C are nearly equivalent in theoretical performance. The difference is more in the amount and quality of compilers and what their optimization targets are.
Free Pascal's Object Pascal is like C++. It is high level language, but the lowlevel (in C++ case: C) still lives there.
Just like that, rock bottom Pascal is like C without macros. (iow #define only for constants).
You will need to learn to adjust the level
Quote
I have big problems writing in this language ... I do the same thing as in C, and yet I encounter Hard Fault more often than I did in C.
It could be a compiler bug, but 9 to 10 this is some mistake you made. If you are less proficient in embedded Pascal that can happen. Stay critical and try to isolate the problem. It could be as little as translating char  buff[5] into array[0..5] of char; {1 char more!}
Older and simpler Pascal implementations prior to Free Pascal would be more appropriate to beat C results in this case?

MarkMLl

  • Hero Member
  • *****
  • Posts: 8515
Re: light pascal
« Reply #17 on: December 23, 2019, 09:32:43 pm »
Older and simpler Pascal implementations prior to Free Pascal would be more appropriate to beat C results in this case?

No, because Pascal has always- from day one- had up-level addressing and better handling of strings than C has.

I think it would be interesting, though, if there were some way of /completely/ disabling "Delphi-style" strings, and running FPC (with a subset of units/packages) with only "classical" Pascal strings (size predeclared, length in element
  • , absolute limit of 256 8-bit characters) and possibly with no compiler support for finalisation blocks and exceptions. /If/ that could be done, then it would be possible to compare against say TP5 and against various Modula-2 compilers which as I understand it had well-regarded optimisation (because the user was giving the compiler a bit more information about what he was trying to do).


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

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12572
  • FPC developer.
Re: light pascal
« Reply #18 on: December 23, 2019, 10:36:54 pm »
Older and simpler Pascal implementations prior to Free Pascal would be more appropriate to beat C results in this case?

First, there is no universal "C". Some C compilers optimize for size (e.g. Keile), some not.

And no. My remark was primarily about using the optimal subsets, and only secondarily about compiler selection. If you use the wrong subset (e.g. TP4 has a string[] and goes back to 1989 or so), then you still will be bulky.

FPK

  • Full Member
  • ***
  • Posts: 118
Re: light pascal
« Reply #19 on: December 24, 2019, 12:21:31 am »
*sigh* again the myth of the large binaries. An empty program for avr25 results in

<fpc trunk for avr> -Wpattiny28 tavr.pp -O4
Free Pascal Compiler version 3.3.1 [2019/12/24] for avr
Copyright (c) 1993-2019 by Florian Klaempfl and others
Target OS: Embedded
Compiling tavr.pp
Assembling program
Linking tavr
2 lines compiled, 0.0 sec, 38 bytes code, 0 bytes data

The 38 bytes come from the interrupt handlers.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8515
Re: light pascal
« Reply #20 on: December 24, 2019, 09:35:14 am »
*sigh* again the myth of the large binaries. An empty program for avr25 results in
...
Linking tavr
2 lines compiled, 0.0 sec, 38 bytes code, 0 bytes data

The 38 bytes come from the interrupt handlers.

No myth at all: his complaint was about ARM. Somebody else made the point that perhaps comparing with AVR would be worthwhile.

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

Thaddy

  • Hero Member
  • *****
  • Posts: 18529
  • Here stood a man who saw the Elbe and jumped it.
Re: light pascal
« Reply #21 on: December 24, 2019, 09:46:58 am »
No myth at all: his complaint was about ARM. Somebody else made the point that perhaps comparing with AVR would be worthwhile.

MarkMLl
ARM embedded has similar sizes. But don't expect a Raspberry Pi with a full Debian as embedded. It will have the same overhead that comes with a full OS.
That's a trap less experienced programmers always fall into,
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8515
Re: light pascal
« Reply #22 on: December 24, 2019, 10:10:14 am »
@Thaddy: Good point.

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

PascalDragon

  • Hero Member
  • *****
  • Posts: 6238
  • Compiler Developer
Re: light pascal
« Reply #23 on: December 24, 2019, 10:36:06 am »
I think it would be interesting, though, if there were some way of /completely/ disabling "Delphi-style" strings, and running FPC (with a subset of units/packages) with only "classical" Pascal strings (size predeclared, length in element
  • , absolute limit of 256 8-bit characters) and possibly with no compiler support for finalisation blocks and exceptions. /If/ that could be done, then it would be possible to compare against say TP5 and against various Modula-2 compilers which as I understand it had well-regarded optimisation (because the user was giving the compiler a bit more information about what he was trying to do).
You don't need some way to disable Delphi-style strings, because if you don't use them, then the compiler and linker won't include the corresponding functionality (this is especially true for the embedded target). Same for implicit exception frames: if you don't use managed types then the implicit frames won't be generated.
Also for the embedded target one can explicitely decide which features should be enabled when compiling the RTL (take a look at $fpcdir/rtl/embedded/system.cfg), thus avoiding that it's used by accident.

i get Hard Fault in line " buf^ := p^ "
Any attempt to write to 'buf ^' results in an error.

The notation something^ applies only to a pointer: it's meant to dereference it. Your buf variable, though, is an array: you should access/set it by using an index into the array, as in:
buf[x] := p^

In C it's different because an "array" is almost exactly the same as a pointer.
Take a look at the code again. buf is an input argument of type PChar and p is a pointer to the local array buff.

*sigh* again the myth of the large binaries. An empty program for avr25 results in

<fpc trunk for avr> -Wpattiny28 tavr.pp -O4
Free Pascal Compiler version 3.3.1 [2019/12/24] for avr
Copyright (c) 1993-2019 by Florian Klaempfl and others
Target OS: Embedded
Compiling tavr.pp
Assembling program
Linking tavr
2 lines compiled, 0.0 sec, 38 bytes code, 0 bytes data

The 38 bytes come from the interrupt handlers.

The point you mentioned is empty program. But once users start to use more features that size obviously increases. So they need to monitor what they use so that they don't break any size constraints.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: light pascal
« Reply #24 on: December 24, 2019, 11:41:35 am »
i get Hard Fault in line " buf^ := p^ "
Any attempt to write to 'buf ^' results in an error.

The notation something^ applies only to a pointer: it's meant to dereference it. Your buf variable, though, is an array: you should access/set it by using an index into the array, as in:
buf[x] := p^

In C it's different because an "array" is almost exactly the same as a pointer.
Take a look at the code again. buf is an input argument of type PChar and p is a pointer to the local array buff.

Oops! You're right, of course. I mistook buff and buf :-[
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.

julkas

  • Guest
Re: light pascal
« Reply #25 on: December 24, 2019, 11:47:32 am »
*sigh* again the myth of the large binaries. An empty program for avr25 results in

<fpc trunk for avr> -Wpattiny28 tavr.pp -O4
Free Pascal Compiler version 3.3.1 [2019/12/24] for avr
Copyright (c) 1993-2019 by Florian Klaempfl and others
Target OS: Embedded
Compiling tavr.pp
Assembling program
Linking tavr
2 lines compiled, 0.0 sec, 38 bytes code, 0 bytes data

The 38 bytes come from the interrupt handlers.
I think without real life project (working code) we can't make objective discussion.

Hartmut

  • Hero Member
  • *****
  • Posts: 1028
Re: light pascal
« Reply #26 on: December 24, 2019, 12:13:25 pm »
Also for the embedded target one can explicitely decide which features should be enabled when compiling the RTL (take a look at $fpcdir/rtl/embedded/system.cfg), thus avoiding that it's used by accident.

In FPC 3.0.4 I did not find a system.cfg in this folder, but a rtl.cfg. Do you mean this?

julkas

  • Guest
Re: light pascal
« Reply #27 on: December 24, 2019, 12:27:50 pm »
Also for the embedded target one can explicitely decide which features should be enabled when compiling the RTL (take a look at $fpcdir/rtl/embedded/system.cfg), thus avoiding that it's used by accident.

In FPC 3.0.4 I did not find a system.cfg in this folder, but a rtl.cfg. Do you mean this?
Check trunk

devport

  • New Member
  • *
  • Posts: 26
Re: light pascal
« Reply #28 on: December 24, 2019, 12:51:43 pm »
OKEY

Gentlemen, and perhaps Lady's, I have already partly understood the operation of the FPC compiler and this action is beginning to suit me. I wouldn't want to create an unnecessary storm here. From now on, I check 2x how the code I write affects the size of the output.
It was my inexperience with this compiler that gave rise to this topic. I apologize in advance.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8515
Re: light pascal
« Reply #29 on: December 24, 2019, 12:59:41 pm »
It was my inexperience with this compiler that gave rise to this topic. I apologize in advance.

Don't. Unless it really is an FAQ, raising an issue which results in core developers updating the rest of us on the state of the art is always valuable.

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