rochus-keller / Oberon

Oberon parser, code model & browser, compiler and IDE with debugger, and an implementation of the Oberon+ programming language
GNU General Public License v2.0
451 stars 29 forks source link

write a text file #57

Closed tarkonian closed 5 months ago

tarkonian commented 5 months ago

I am using as example the oakwood3.obx to write a simple set of number in a file, but without success. Maybe i am making a stupid mistake. The code i used to test is

module filewritetest

import F := Files

var f : F.File r : F.Rider a : int32 b : real c : int64 d : longreal

begin a:= 2 b:=3.1415 c:=100 d:=0.002

f := F.New("teste.txt")

F.Set(r,f,0) F.WriteInt(r,a) F.WriteLInt(r,c) F.WriteReal(r,b) F.WriteLReal(r,d) F.Register(f) F.Close(f)

end filewritetest

rochus-keller commented 5 months ago

I just run your code an get the following output file (in the build directory): teste.txt

What issue do you observe? Is there no file, or does it have the wrong content? Which version of ObxIDE on which platform are you using?

tarkonian commented 5 months ago

I used the zip version for Win64 in your main page. The code produce the file, but the content is:

 d ๖䁉ꧼ틱才㽠

rochus-keller commented 5 months ago

The reason is that binary format (not text format) numbers are written. See also e.g. http://www.edm2.com/index.php/The_Oakwood_Guidelines_for_Oberon-2_Compiler_Developers#Writing

tarkonian commented 5 months ago

Ok and how I write numbers to the text file? It is possible in the current implementation of oberon+? In A2 oberon I use the following code

MODULE FileWriteTest;

IMPORT Files;

PROCEDURE T1*;

VAR f:Files.File; w:Files.Writer; (ch:CHAR;) a:SIGNED64; b:FLOAT64; BEGIN a:= 1; b:=2.0;

f:=Files.New("Test.txt");

IF f # NIL THEN Files.OpenWriter(w,f,0); w.String("Isto eh um teste"); w.Ln; w.Int(a,0); w.Ln; w.Float(b,0); w.Update; Files.Register(f); END; END T1;

BEGIN END FileWriteTest.

rochus-keller commented 5 months ago

I have no decent standard library yet, but had a look at the standard libraries of other Oberon and Modula compilers which could be migrated with acceptable effort. In any case all functions you are looking for have already been implemented in one or many versions of the Oberon system (see e.g. https://github.com/rochus-keller/OberonSystem3). Personally I often use the Oberon+ FFI and just integrate an existing C library which has all features I need for a project.

tarkonian commented 5 months ago

Thank you. In general 90% of my use in programming is to solve a set of non linear differential equations and save the result (a table) in a txt like file that can be used to plot calling gnuplot or some other program. I am send to you see (when you have time) two libraries that I am using in the oberon+. One file isa extended math library with special functions, distributions and basic statistics. The other is based in the A2 CAPO library to create a better formatted print procedure (in the future I want something like the rust macro println! that print everything). EXMath.zip Print.zip

rochus-keller commented 5 months ago

EXMath.zip, Print.zip

Wow, this is impressive. And the ExMath module ideed looks like Oberon+, not traditional Oberon. Are you using the Mono version for number crunching, or do you export and compile C code? How is the performance?

tarkonian commented 5 months ago

I am using the mono version. Before testing the performance I will test each procedure to verify if it is all right. I have two version one for oberon+ and other for ecs. I will work in a library for differential equations solvers. I have a few suggestions:

Em seg., 1 de abr. de 2024 às 20:06, Rochus Keller @.***> escreveu:

EXMath.zip, Print.zip

Wow, this is impressive. And the ExMath module ideed looks like Oberon+, not traditional Oberon. Are you using the Mono version for number crunching, or do you export and compile C code? How is the performance?

— Reply to this email directly, view it on GitHub https://github.com/rochus-keller/Oberon/issues/57#issuecomment-2030752845, or unsubscribe https://github.com/notifications/unsubscribe-auth/BB5ZKOOUWQZBIJ45PSPTSILY3HR6VAVCNFSM6AAAAABFQVPRC2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZQG42TEOBUGU . You are receiving this because you modified the open/close state.Message ID: @.***>

rochus-keller commented 5 months ago

find/replace in the editor.

The current IDE might not be the final one; I was thinking about using LeanCreator also for Oberon+; I will very likely use it for Micron. LeanCreator has a much more sophisticated editor than the ObxIDE.

alias int16,int32... maybe also create a real32, real64.

Micron has F32 and F64; I could add this or FLOAT32 and FLOAT64; REAL already has a dedicated meaning.

A Pascal like writeln would be fantastic.

There ist a PRINTLN function, but it is not part of the language, but only for debugging purpose, and it only accepts one argument.

tarkonian commented 5 months ago

Your println is really good (is something like trace?). I like your approach for micron. Please think seriously about eliminating the begin from proc like is in for,if, etc... Then you will have a more clean language with keywork-end for everything. Also let variable initialization everywhere. The rust like aliases for types (i32,u32,f32...) are really good. FLOAT32 etc.. in my opinion is better than using real or longreal (i like the symmetry int32 - float32, etc...). It is better to reserve integer and real to be machine dependent (ie. 32 bits in a 32 bits machine and 64 in a 64) in the future if we have a 128 bits it will automatically assume this maximum range. I have two curiosity:

Em seg., 1 de abr. de 2024 às 22:12, Rochus Keller @.***> escreveu:

find/replace in the editor.

The current IDE might not be the final one; I was thinking about using LeanCreator also for Oberon+; I will very likely use it for Micron. LeanCreator has a much more sophisticated editor than the ObxIDE.

alias int16,int32... maybe also create a real32, real64.

Micron has F32 and F64; I could add this or FLOAT32 and FLOAT64; REAL already has a dedicated meaning.

A Pascal like writeln would be fantastic.

There ist a PRINTLN function, but it is not part of the language, but only for debugging purpose, and it only accepts one argument.

— Reply to this email directly, view it on GitHub https://github.com/rochus-keller/Oberon/issues/57#issuecomment-2030900335, or unsubscribe https://github.com/notifications/unsubscribe-auth/BB5ZKOPVYFNXDELUPRGVU23Y3IAZRAVCNFSM6AAAAABFQVPRC2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZQHEYDAMZTGU . You are receiving this because you modified the open/close state.Message ID: @.***>

rochus-keller commented 5 months ago

Please think seriously about eliminating the begin from proc

Well, it separates declarations from the body which from my perspective is more convenient than the Algol approach. Anyway, the current idea is to create something with an Oberon (or Pascal) look and feel. But I'm still on the drawing board; to find out whether the language is practical I first have to migrate some notably big C projects to Micron. This will take some time.

let variable initialization everywhere

This is an issue with a one-pass compiler as Micron intends to do it. Actually there is already Free Pascal which already has a lot of such features, or e.g. Go. I try to avoid just rebuilding these pre-existing languages.

when I open the ide a have the following message in the output

But it's only a warning, isn't it? There are still a lot of pending improvements; the current IDE is just a bare MVP; as I said, it's likely that it will be replaced in future.

you implement your GC from the mono or your implementation has two GC (from oberon+ and from mono)?

No. The generated CIL code assumes the CIL GC (which is required by the standard). The generated C code assumes the Boehm GC. I might use MPS in future for the generated C code as an alternative to Boehm.

tarkonian commented 5 months ago

"But it's only a warning, isn't it?" Yes it is only a warning. Not a problem.

Em ter., 2 de abr. de 2024 às 09:19, Rochus Keller @.***> escreveu:

Please think seriously about eliminating the begin from proc

Well, it separates declarations from the body which from my perspective is more convenient than the Algol approach. Anyway, the current idea is to create something with an Oberon (or Pascal) look and feel. But I'm still on the drawing board; to find out whether the language is practical I first have to migrate some notably big C projects to Micron. This will take some time.

let variable initialization everywhere

This is an issue with a one-pass compiler as Micron intends to do it. Actually there is already Free Pascal which already has a lot of such features, or e.g. Go. I try to avoid just rebuilding these pre-existing languages.

when I open the ide a have the following message in the output

But it's only a warning, isn't it? There are still a lot of pending improvements; the current IDE is just a bare MVP; as I said, it's likely that it will be replaced in future.

you implement your GC from the mono or your implementation has two GC (from oberon+ and from mono)?

No. The generated CIL code assumes the CIL GC (which is required by the standard). The generated C code assumes the Boehm GC. I might use MPS in future for the generated C code as an alternative to Boehm.

— Reply to this email directly, view it on GitHub https://github.com/rochus-keller/Oberon/issues/57#issuecomment-2031893228, or unsubscribe https://github.com/notifications/unsubscribe-auth/BB5ZKOJDYYU4XB3NLPF6AATY3KO5VAVCNFSM6AAAAABFQVPRC2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZRHA4TGMRSHA . You are receiving this because you modified the open/close state.Message ID: @.***>