vishapoberon / compiler

vishap oberon compiler
http://oberon.vishap.am
GNU General Public License v3.0
186 stars 25 forks source link

Hello world module compiling but not working! #21

Closed snayaksnayak closed 8 years ago

snayaksnayak commented 8 years ago

I compiled and installed Vishop Oberon compiler 1.1 on my linux. Below is my Hello.Mod file collected from net. I compiled the file using voc -m. It went fine. When I tried to run the module using ./Hello, I see nothing. :-( What is that I missed? Why it is not working?

~# cat Hello.Mod MODULE Hello; IMPORT Oberon, Texts; VAR W: Texts.Writer; PROCEDURE World*; BEGIN Texts.WriteString(W, "Hello World!"); Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf); END World;

BEGIN Texts.OpenWriter(W); END Hello.

norayr commented 8 years ago

Hey hey, Srinivas!

I am glad you are trying to use voc!

First remark - it's better to use git version, not the release. Git version has many improvements and fixes.

And now - regarding your code.

You have found hello world code for Oberon system, which is more complicated. With voc, it's much easier like this

MODULE Hello;
  IMPORT Console;
BEGIN
  Console.String("hello"); Console.Ln
END Hello.

I'll write more comments regarding your code a little bit later. It's also possible to write a Hello world in Oberon system way, but a little bit differently.

norayr commented 8 years ago

Hey, Srinias.

With today's update, this code

MODULE Hello;
 IMPORT Oberon, Texts;
   VAR W: Texts.Writer;
 PROCEDURE World*;
   BEGIN
     Texts.WriteString(W, "Hello World!");
     Texts.WriteLn(W);
     Texts.Append(Oberon.Log, W.buf);
     Oberon.DumpLog;
  END World;

 BEGIN
   Texts.OpenWriter(W);
   World
 END Hello.

works fine.

There are two small differences with Oberon system version:

Writing to Oberon.Log might be considered a more portable way, because not all systems have a console (windows?) and Oberon.Log can be dumped to the necessary space or control on screen.

snayaksnayak commented 8 years ago

Agree. Linux has one entry point starting at BEGIN. So one has to call World inside BEGIN. Fine. Yes, Oberon.DumpLog inside World procedure is good. One can even dump Log to windows command prompt.