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

Твердыня модульных языков
Текущее время: 17 июн 2025, 23:49

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




Начать новую тему Ответить на тему  [ Сообщений: 24 ]  На страницу Пред.  1, 2, 3  След.
Автор Сообщение
 Заголовок сообщения: [Solved] Proper initialization of Oberon modules
СообщениеДобавлено: 16 авг 2013, 19:16 
Не в сети

Сообщения: 104
hi here is a sample that crashes the speccy


Вложения:
Комментарий к файлу: this will crash speccy
bughunt.zip [143.65 КБ]
Скачиваний: 1024
Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: [Solved] Proper initialization of Oberon modules
СообщениеДобавлено: 16 авг 2013, 21:34 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
Dear slenkar,
Код: "ASM"
;hi.c:16: export main(int argc, char **argv)
; ---------------------------------
; Function main
; ---------------------------------
_main_start::
_main:
;hi.c:20: __IMPORT(five);
call _five__init

Код: "OBERON"
  1. MODULE five;IMPORT B := Basic,SYSTEM,tw:=two,th:=three,fo:=four,si:=six;
  2. VAR
  3. BEGIN (*sdgfk*)B.PRSTR("FIVE-");END five.
Here you are using a procedure from module Basic WITHOUT initialization (before calling Basic_Init())

Shame on me, I didn't use Basic__init (changed it to manual initializing by calling Basic_Init()). But in your case it rises the problem.

At first remove from Basic.h the line:
Код: "C"
#define Basic__init()
and put there the line:
Код: "C"
#define Basic__init()  Basic_Init()
and rebuild the project. Probably I'll do the same change (if I will not think a better idea). Write me about results, please.

Also please use entry point for programs that use more than one module (to start a program always from main() function).


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: [Solved] Proper initialization of Oberon modules
СообщениеДобавлено: 16 авг 2013, 21:47 
Не в сети

Сообщения: 104
I replaced the line in basic.h
it just resets this time, so it is different
This is what my hi.mod looks like now:

Код: "OBERON"
  1.  
  2. MODULE hi;
  3. IMPORT B := Basic,SYSTEM,tw:=two,th:=three,fo:=four,fi:=five,si:=six;
  4. CONST
  5. wall=2;
  6. floor=3;
  7. BEGIN (*$MAIN*)
  8. B.Init; B.BORDER(B.Blue);
  9. B.PAPER(B.White);
  10. B.INK(B.Black);
  11. B.PRSTR("IRST-");
  12.  
  13. B.PAUSE(B.WaitAKey);
  14. B.Quit;
  15.  
  16.  
  17.  
  18. END hi.
  19.  


heres the line i use to compile:
/root/sdcc/bin/sdcc $(targetname).c -mz80 --code-loc 25000 --data-loc 49000 --no-std-crt0 --opt-code-size --funsigned-char --disable-warning 126 -I Lib -I Obj Lib/z80/Basic.lib Lib/z80/XDev.lib $(OBJECTS)

I also tried putting
B.Init;
in every module but it resets in the same way


Do you think it could be too many function calls within each other? So the stack or heap is being overloaded? (whatever the spectrum uses to keep track of multiple function calls within other function calls)


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: [Solved] Proper initialization of Oberon modules
СообщениеДобавлено: 16 авг 2013, 22:10 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
slenkar, I see that your module "four" imports module "six", and module "six" imports module "four":
Код: "OBERON"
  1. MODULE four;IMPORT B := Basic,SYSTEM,tw:=two,th:=three,si:=six;
  2. VAR
  3. BEGIN (*sdgfk*)B.PRSTR("FOUR-");END four.
Код: "OBERON"
  1. MODULE six;IMPORT B := Basic,SYSTEM,tw:=two,th:=three,fo:=four;VAR
  2. BEGIN (*sdgfk*)B.PRSTR("SIX");END six.
You can do this in C, but you can't do this in Oberon. The Oberon modules has hierarchically structure and cannot be "cross-linked" in this manner.

So remove this cross-linking (because you have something like this):
Код: "ASM"
four__init: CALL six__init
six__init: CALL four__init
So as result you have stack overflow and reset.


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: [Solved] Proper initialization of Oberon modules
СообщениеДобавлено: 17 авг 2013, 00:13 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
Modules interdependence - why it's bad? At first, it obscures the causes of modules, because it gives rise to the urgent problem of the chicken and egg (what was first?). You even cannot compile such modules in a normal Oberon environment (and in Ofront too) without tricks. To compile module "A" you must have symbol file of module "B", hence you need to compile the module "B" first. But to compile the module "B" you need to have the symbol file of the module "A"! And never end. Yes, we know such sort of tricks with different snapshots of a symfile, but why? And we can have a lot of crooked *.h files interdependent on each other, working in C, but it breaks the hierarchical structure of a software system. Oberon does not allow us to have the bad designed structure of the system. If your two modules need each other, maybe is it reason to join them to one?

How to use entry point. Just remove --no-std-crt0 from your makefile. +3 bytes of code, but no problems with starting main() function in future. :)

slenkar писал(а):
Do you think it could be too many function calls within each other? So the stack or heap is being overloaded?
With this cross-linked calls the all memory lower from stack pointer just filled completely and absolutely, there was no chance to keep at least one free byte for your program. ;)


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: [Solved] Proper initialization of Oberon modules
СообщениеДобавлено: 17 авг 2013, 22:40 
Не в сети

Сообщения: 104
I took out the cross dependencies but
I think it also crashes when there are too many modules,

instead of this:
__IMPORT(Dungeon);

could we have
if (dungeon_imported==0)
{
__IMPORT(Dungeon);
dungeon_jmported=1;
}

If you look at the files that I gave you, if a file is imported by more than one other module it will do everything in its BEGIN function more than once.

Take away a few files like five.mod and six.mod
and you will see the modules printing their module name more than once.
They are not importing each other
Изображение


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: [Solved] Proper initialization of Oberon modules
СообщениеДобавлено: 18 авг 2013, 01:28 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
slenkar, you are absolutely right, it's a bug.

I tried to reproduce your code in WinDev (tcc) and have well worked code.

http://wiki.answers.com/Q/What_is_the_difference_between_static_and_extern
Цитата:
The static storage class is used to declare an identifier that is a local variable either to a function or a file and that exists and retains its value after control passes from where it was declared. This storage class has a duration that is permanent. A variable declared of this class retains its value from one call of the function to the next. The scope is local. A variable is known only by the function it is declared within or if declared globally in a file, it is known or seen only by the functions within that file. This storage class guarantees that declaration of the variable also initializes the variable to zero or all bits off.
SDCC initializes the static variables to zero. But SDCC does not save value of the exists static variable (and breaks "exists and retains its value after control passes from where it was declared").

So this is a bug in SDCC! Or, at least, the non-standard behavior.

We must deal with it. I'll contact developers of SDCC in the near future, and I advise you to try the latest build of SDCC - may be the problem is already fixed there.


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: [Solved] Proper initialization of Oberon modules
СообщениеДобавлено: 18 авг 2013, 03:01 
Не в сети

Сообщения: 104
what stops the __import functions from being called more than once?

in __import it says
SYSTEM_INCREF(name##__init()

does this try to stop it being called more than once?


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: [Solved] Proper initialization of Oberon modules
СообщениеДобавлено: 18 авг 2013, 09:50 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
This code must prevent the initializing more than once:
Код: "C"
#  define __DEFMOD	static  char m; if(m!=0)return
# define __REGMOD(name, enum) m=1
Код: "C"
export void *two__init(void)
{
__DEFMOD; // static char m; if(m!=0)return;
__IMPORT(Basic__init);
__REGMOD("two", 0); // m=1;
...
}
__DEFMOD defines variable m, that must be set to zero, but only first time. Other second times m!=0 and already initialized function returns here.
If function was runned first time, __IMPORT does initialize other modules, but after it the current module marks as already initialized by __REGMOD.

And it works in tcc:


Вложения:
bughunt.png
bughunt.png [ 17.58 КБ | Просмотров: 19041 ]
Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: [Solved] Proper initialization of Oberon modules
СообщениеДобавлено: 18 авг 2013, 09:55 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
But it not works in SDCC:
Код: "C"
export void *two__init(void)
{
__DEFMOD; // SDCC says at this line: two.c:13: warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG
__IMPORT(Basic__init);
__REGMOD("two", 0);
...
}
Код: "ASM"
;	---------------------------------
; Function two__init
; ---------------------------------
_two__init_start::
_two__init:
;two.c:15: __REGMOD("two", 0);
ld hl,#_two__init_m_1_61 + 0
ld (hl), #0x01

So SDCC optimizes:
Код: "C"
static  char m; if(m!=0)return;
to absolute nothing.

Well - do you still not believe me that this is a bug in SDCC? :)


Вернуться к началу
 Профиль  
Ответить с цитатой  
Показать сообщения за:  Поле сортировки  
Начать новую тему Ответить на тему  [ Сообщений: 24 ]  На страницу Пред.  1, 2, 3  След.

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


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

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


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

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