Otterkit COBOL Dev Update 1: First successful compilation #7
Replies: 4 comments 14 replies
-
I still highly suggest to use the standard "combined location" form, which is supported in several tools "out of the box"; including vscode, vim, emacs, ... Statements: I highly suggest to add in-line and out-of-line Speaking of those: What is the output of And - just for interest - is there any source-level debugging available yet? |
Beta Was this translation helpful? Give feedback.
-
... and now I remember: WSL2 works with As an alternative: you can get the instructions also with Intel's pin tool (if you have an Intel Processor) or with callgrind (gets you much more for much more time spend). |
Beta Was this translation helpful? Give feedback.
-
Nothing beats profiling cpu and memory :-)
Note: GnuCOBOL does much more than necessary for a simple ACCEPT DATE - as we streamlined all date/function calls into a single function chain (which is also used for fine grained, locale aware functions and handles partial/full adjustment via override setting). After profiling an application and having seen that this takes most of a loop doing ACCEPT TIME this was adjusted since weeks ago to do the "big" lookup only if necessary, then only adjust the nanoseconds to minutes the next call - and everything was back to a reasonable time.
Most of the computation and memory in date/time is about the locale tzdata, which may be completely loaded into memory in the first call, and possibly also checked (as it is in glibc) each time when a datetime function is called.
|
Beta Was this translation helpful? Give feedback.
-
@GitMensch Hey Simon, I found this article talking about the TZ environment variable on Linux and how it could cause thousands of system calls. This might be the cause of the 15000 allocations, I don't really see how a single C# datetime call would cause it by itself (from ~150 to 15000 allocs). If this is indeed the cause then maybe setting the TZ environment variable at runtime could fix the issue. This also seems to be a Linux only issue. |
Beta Was this translation helpful? Give feedback.
-
Dev Update 1: First successful compilation:
Development on the Otterkit compiler is progressing quite well, and this month we've been working on all parts of the compiler pipeline trying to get it to successfully compile a small program on its own.
This was the first program that we successfully compiled, just a very simple COBOL program with 3 working-storage variables, two accept statements to get the current date and current time, and then displaying all 3.
This in the output from the compiled program. It's just a simple program, but having the compiler pipeline working will make development and testing go much more smoothly:
Compiler options:
We've also added a couple of compiler options, and as you might have seen from the previous image the "build and run" command is:
With that command the compiler will generate C# code from COBOL source code, call the dotnet compiler to turn it into a standalone executable, and then call the compiled executable.
Other build commands are this one for "parse only" which displays a list of tokens:
And the "build only" which builds the executable, but doesn't run it:
Additional options are
-cl
for custom column length limit (default is 80) and of course the--free
and--fixed
for fixed and free source formats:There's also a
new
command which works similarly to thedotnet new
command. With the module template for generating a COBOL library and app for standalone executables:Those two commands will generate the project files needed by the dotnet compiler to compile the generated C# code. Those files will stay in a folder called
.otterkit
, and the compiled executable will be in the.otterkit/Build
directoryThe preprocessor:
We've also started working on the preprocessor, and we're aiming to support all directives from the latest COBOL standard. Currently the preprocessor only implements the
>>SOURCE FORMAT
directive:Switching source formats on each line like this is incredibly cursed but the standard requires that functionality, and it's also a nice way to stress test the preprocessor on the constant source format switching.
The parser and error messages:
We're using a hand written variation of a recursive descent parser. It's not a pure recursive descent because that would be a really bad experience with COBOL's huge list of reserved words, but it's a custom variation to make parsing COBOL easier.
The reason behind using a hand written parser instead of a generated one is the possibility of showing much better error messages than what the usual parser generator is capable of:
This allows us to define exactly on which token to show the error (in case the parser has already moved to the next token), show a custom written error message that hopefully will help with fixing the issue, and a snippet of the source code to show where the error occurred. We'll be adding more and better error messages as we progress with development.
Project file maybe?
We are experimenting with ways to make a project file, but specifically for COBOL projects. This might help with a possible future package manager, and also a way to statically store compiler options. Something similar to C#'s
csproj
file and NodeJS'package.json
file.Let us know if you have any feedback on the idea of a project file, or if you'd like us to implement a specific feature for them.
Totally working alpha build:
We uploaded an alpha build to Nuget as a dotnet CLI tool. This build has extremely limited (and possibly broken) features, the program you saw above is basically as far as the current codegen will go. All it has currently is:
The parser is capable of parsing group items, 30 more statements and FUNCTION-IDs, but the codegen for those is not ready yet. We'll keep updating this same package on Nuget as we progress with the parser and codegen:
https://www.nuget.org/packages/Otterkit/
https://www.nuget.org/packages/Otterkit.Templates/
The templates package is used for generating the COBOL projects with the
new
command. You'll need to install that one as well to try this alpha build.Project repos:
If you'd like to check the source code and possibly help us with the compiler's development, feel free to check our GitHub repos:
https://github.com/otterkit/otterkit
https://github.com/otterkit/libotterkit
The compiler is split into two repos, the main one and the
libotterkit
repo, which is where the runtime library lives. It is free and open source, licensed under the Apache License 2.0.This is a long term project, and our goal is to make a production-ready modern COBOL compiler that supports features from the latest COBOL standard. We'll try to improve the COBOL ecosystem and the general developer experience as we continue development. We believe that COBOL can have a nicer developer experience, with better tooling, and a compiler with more modern features than what it currently has. In our opinion, COBOL is just lacking a bit of love ❤️
Beta Was this translation helpful? Give feedback.
All reactions