Оберон-клуб «ВЄДАsoft»

Твердыня модульных языков
Текущее время: 28 мар 2024, 17:50

Часовой пояс: UTC + 2 часа




Начать новую тему Ответить на тему  [ Сообщений: 5 ] 
Автор Сообщение
СообщениеДобавлено: 17 фев 2014, 16:28 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
Oleg N. Cher писал(а):
Dear Josef, dear Norayr,

After years of working in Oberon language and a good understanding of its features and problems, let me propose you a new feature that you can add to Ofront and voc: IN parameters of procedures as in Component Pascal.

An Oberon developer, choosing a method of passing a string inside a procedure, must choose between using direct parameter (with duplicating the entire array or record, which can be not so small), or using VAR-parameter which does not guarantee the passed structure or an array of unwanted changes, and also does not allow an immediate string value, but only a variable or a pointer.

But yeah, you know it well. It was one of the annoying problems of Oberon and Oberon-2. And BlackBox guys, using Oberon-2 for industrial applications, also encountered this. That this problem was not resolved in time, generated a lot of incompatible decisions:


The Oakwood Guidelines, 5.13 Read only VAR parameters

There have been many requests to make ARRAY and RECORD parameters read-only to achieve the efficiency of passing by reference without the associated possibility for corruption of the calling parameter.
An attempt to make an assignment to any component of such a read only parameter is a compile-time error. Such parameters could be marked with the standard read only "-" symbol. For example:

Код: "OBERON"
  1. PROCEDURE Print (theText-: ARRAY OF CHAR) ;
Discussions with ETH suggest this is really a compiler code optimisation issue and on this basis it is recommended that this extension is not implemented.


Amiga-Oberon v3.11, F. Siebert / A+L AG:
Код: "OBERON"
  1. PROCEDURE Print (theText: ARRAY OF CHAR); (* $CopyArrays- *)
Ofront:
Код: "OBERON"
  1. PROCEDURE Print (theText: ARRAY[1] OF CHAR) ; (* Good, but the feature is SYSTEM and incompatible with other Oberon compilers *)
Eventually Wirth also added this capability to Revised Oberon:

Oberon-07:
Код: "OBERON"
  1. PROCEDURE Print (CONST theText: ARRAY OF CHAR) ;

In many other implementations of Oberon-2 this problem was not solved.

After comparing all the suggestions, I chose the option that is implemented in Component Pascal (BlackBox, GPCP) in order to also implement the symmetric parameters OUT in future.

I am really sure that the strength of Oberon is a clear regulation of interprocedural and intermodular interactions, and we have no right to lose this valuable feature. But certainly we should not miss the opportunity to raise the visibility of module interfaces. What we can tell by looking at parameter VAR? What is it? Input value? Output value? Is this changeable value? Does a developer really wants to pass input value and want to have output value, or uses VAR here only for optimization?

All these considerations lead to the conclusion that the IN and OUT-parameters is not such a bad idea. I can assure you that compiler's complication with this feature enough slightly - one additional procedure, and only a couple dozen lines of code. But I'm sure that if we rewrite Ofront using IN-parameters, its efficiency will be significantly improved.

Here are commits that implements IN-parameters. Thank you.

https://github.com/Oleg-N-Cher/Ofront/commit/c50a1ee95854ea7f7187a879b888156b79ee70d0
https://github.com/Oleg-N-Cher/Ofront/commit/de1061d27a1e25cee0bda89cf93a63d3f8ce94d5
https://github.com/Oleg-N-Cher/Ofront/commit/5aa4232bc9d94b0db63c6998429812cc8f732ef2

Test of IN-parameters:

https://github.com/Oleg-N-Cher/BB-XDev/commit/7fb3d4b789cdb32c8216e2823a2c1b4dce1b9c49

I tested that code a few days, and indeed most of the code is taken from BlackBox, but if you notice a problem, let me know.


--
Oleg N. Cher
VEDAsoft Oberon Club
https://zx.oberon.org


Вернуться к началу
 Профиль  
Ответить с цитатой  
СообщениеДобавлено: 18 фев 2014, 01:48 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
Любопытный казус описан в теме «Ошибка компилятора: семантика IN». Предлагаемый мною фикс Ofront'а подвержен тому же поведению. Надо обдумать.


Вернуться к началу
 Профиль  
Ответить с цитатой  
СообщениеДобавлено: 18 фев 2014, 12:57 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
Josef Templ писал(а):
Oleg,
thanks for the info. I have to check this out in more detail.
In general, as far as I remember, BlackBox introduced the
additional parameter modifiers for better integration with COM.
For passing read-only parameters, I would prefer Wirth's approach
of using the keyword CONST.

- Josef


Oleg N. Cher писал(а):
Dear Josef,

I don't agree that IN-parameters are good only for better integration with COM. I don't use COM at all, but actively use IN-parameters. I also prefer OUT-parameters. IN- and OUT-parameters supported in Gardens Point Component Pascal, that hasn't any reason to support COM.

I don't think that using of keyword CONST at this context is a good idea. Semantic of CONST is "unchangeable value". By proposed in Revised Oberon way, a variable must assigning to value marked as CONST. It looks at least strange.

So supporting IN- and OUT-parameters at the same manner increasing source compatibility between Ofront and BlackBox/GPCP that looks preferable for me than Oberon-07.

Anyway, changing the proposed code to work with keyword "CONST" instead of "IN" is easy. But I have not plans to support "CONST" instead of "IN" in XDev. I don't like Revised Oberon. Ofront now supports not Revised Oberon, and Oberon-2, and good Oberon-2 is Component Pascal.

Thanks.


Вернуться к началу
 Профиль  
Ответить с цитатой  
СообщениеДобавлено: 18 фев 2014, 22:38 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
Oleg N. Cher писал(а):
Dear Josef,

I learned today that the latest revision of Oberon-07 not uses keyword CONST for marking read-only procedure parameters. Instead of it, all non-VAR parameters are read-only in Revised Oberon.

All this looks not bad, but if you would like to improve Ofront in the same manner, it will breaks Ofront's compatibility with Oberon-2 and all existing sources.

So Prof.Wirth not only offered the word CONST to mark read-only parameters, but he already refused it recently.


Вернуться к началу
 Профиль  
Ответить с цитатой  
СообщениеДобавлено: 28 фев 2014, 19:35 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
По моей вине вкралась ошибка с рекурсивным определением совместимости параметров-типов массивов, которую и исправляю:

https://github.com/Oleg-N-Cher/Ofront/commit/d1c1738432a2485dde0cd1f9f32bd0cbd3302e47

А также исправлена проблема с супервызовом и возможным повреждением записи только для чтения (IN-параметр как VAR-параметр), описанная в теме в теме «Ошибка компилятора: семантика IN». Огромное спасибо Wening Luo, предложившему исправление! :)

Внесены правки как в сборку XDev, так и в форк Ofront'а:

https://github.com/Oleg-N-Cher/BB-XDev/commit/d4418a62f2d5321ca91f5df0eb8a948470f77c50
https://github.com/Oleg-N-Cher/Ofront/commit/ce035f98d906670e80e6f2e6e0f6699104eaf223

Отныне параметры IN считаю достаточно отлаженным и пригодным к употреблению (в XDev) средством. Йозеф (Ofront) и Норайр (voc) не очень заинтересовались этой фичей, ну да это их дело.

Со временем надо будет реализовать и параметры OUT.


Вернуться к началу
 Профиль  
Ответить с цитатой  
Показать сообщения за:  Поле сортировки  
Начать новую тему Ответить на тему  [ Сообщений: 5 ] 

Часовой пояс: UTC + 2 часа


Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 6


Вы не можете начинать темы
Вы не можете отвечать на сообщения
Вы не можете редактировать свои сообщения
Вы не можете удалять свои сообщения
Вы не можете добавлять вложения

Найти:
Перейти:  
cron
Создано на основе phpBB® Forum Software © phpBB Group
© VEDAsoft Oberon Club