Author Topic: [Email suggestion No. 2] libraries and build system suggestions  (Read 6799 times)

magnusi

  • Newbie
  • *
  • Posts: 17
    • View Profile
The introduction of the library system was a great addition which basically turned C2 from an interesting toy that proves some improvement concepts to an interesting usable language. However, there could be some tiny additions make it easier to work with:


2.1 Allow targets to specify additional, perhaps local to the project, C2 libs directory
. In C and C++, it is also common to have more include paths, so allowing something like this:

Code: [Select]
target trg
     $generate-c
     $libdir ./myotherinterfacefiles
     file1.c2
     file2.c2
end

could be a great addition to the library system.

2.2 Ability to recognize a prefix in in .c2i files
. When there is a header that exposes the following functions:

Code: [Select]
void thislib_function1();
void thislib_function2();
void thislib_function3();
Then typing it as thislib.thislib_function1(); in C2 is not nice on the eyes. My suggestion is to the use of a prefix value in the toml manifest file for the library in the following manner:
Code: [Select]
//manifest file for the thislib
[library]
language = "C"
prefix = "thislib_"

Code: [Select]
[[modules]]
name = "thislib"
header = "thislib.h"

Code: [Select]
//thislib.c2i
func void thislib_function1();
func void thislib_function2();
func void thislib_function3();

In other words, the .c2i files would still contain the prefix, but when used in C2 code, one would use thislib.function1(); which is shorter and more sane.

admin

  • Administrator
  • Newbie
  • *****
  • Posts: 11
    • View Profile
Re: [Email suggestion No. 2] libraries and build system suggestions
« Reply #1 on: July 21, 2016, 08:29:54 AM »
see also this post (http://www.c2lang.org/forum/index.php?topic=56.msg154#msg154).

The library system is currently undergoing an overhaul. In the current system, there would be an interface
file, for example stdio.c2i (in c2libs/libc/). In the libc manifest file there would be an entry also naming
(for C libs) an header file name. During compilation, the header file name would be generated in C-code.
Then during the compilation of the generated C-code, this (system) header (stdio.h) would actually be
used.

In the new system, headers are generated from the c2 interface file. And this generated header would be
used (so #include "stdio.h" (notice the double quotes "" instead of <>). This has the advantage that the
header is guaranteed to be the same as the interface file.

magnusi

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: [Email suggestion No. 2] libraries and build system suggestions
« Reply #2 on: July 21, 2016, 02:29:54 PM »
see also this post (http://www.c2lang.org/forum/index.php?topic=56.msg154#msg154).

The library system is currently undergoing an overhaul. In the current system, there would be an interface
file, for example stdio.c2i (in c2libs/libc/). In the libc manifest file there would be an entry also naming
(for C libs) an header file name. During compilation, the header file name would be generated in C-code.
Then during the compilation of the generated C-code, this (system) header (stdio.h) would actually be
used.

In the new system, headers are generated from the c2 interface file. And this generated header would be
used (so #include "stdio.h" (notice the double quotes "" instead of <>). This has the advantage that the
header is guaranteed to be the same as the interface file.


I like this idea very much, amazing addition!