JavaScript/EcmaScript interpreter
Hi. I am Lach Sławomir from Poland, Bytom. I am beginner developer in C/C++, Python, TypeScript, EcmaScript, etc. I'm wonder how wonderful stuff can be done if GNU Compilers Collection allow developers to use JavaScript inside other language code as preprocessor. - Developer could use arrays - Developer could use more generalized functions - Developer could use custom code analyze (as compiler extensions) - JavaScript will be ran in sandbox, so maybe use it instead configure scripts and instead make? - Developer could use JavaScript regular expressions to replace text in files - Possible many others I think, you could use modified version of node.js as C/other language preprocessor. I don't have idea how things should be done yet, but I'm ready for discussions. One example: #JS_DEFINE("UNPACK",['string','string'], function(a, b) { unpacked_symbols[unpacked_symbols.length] = b; document.write("#define b a . b"); }) #JS_DEFINE("}", [], function() { for (a in unpacked_symbols) { document.write("#undef a"); } delete unpacked_symbols; } That's very simple example. Could it be useful? Best regards, Lach Sławomir.
Re: JavaScript/EcmaScript interpreter
Sorry, but my code have two bugs. I correct it in this mail. Sławomir Lach. W dniu 17.04.2017, pon o godzinie 10∶20 +0200, użytkownik Sławomir Lach napisał: > Hi. > > I am Lach Sławomir from Poland, Bytom. I am beginner developer in > C/C++, Python, TypeScript, EcmaScript, etc. > > I'm wonder how wonderful stuff can be done if GNU Compilers > Collection > allow developers to use JavaScript inside other language code as > preprocessor. > > - Developer could use arrays > - Developer could use more generalized functions > - Developer could use custom code analyze (as compiler extensions) > - JavaScript will be ran in sandbox, so maybe use it instead > configure > scripts and instead make? > - Developer could use JavaScript regular expressions to replace text > in > files > - Possible many others > > I think, you could use modified version of node.js as C/other > language > preprocessor. I don't have idea how things should be done yet, but > I'm > ready for discussions. > > One example: > #JS_DEFINE("UNPACK",['string','string'], function(a, b) > { > unpacked_symbols[unpacked_symbols.length] = b; > document.write("#define b a . b"); > }) > > #JS_DEFINE("}", [], function() { > > for (a in unpacked_symbols) > { > document.write("#undef" + a); > } > delete unpacked_symbols; > document.write("}"); > } > > That's very simple example. Could it be useful? > > Best regards, > Lach Sławomir.
About new possibilities.
This message (https://gcc.gnu.org/ml/gcc/2018-07/msg00233.html) just reminder me about my idea to allow using JavaScript with regular expression with connection to C preprocessor to make things easier in C? For example - define macro-definition, with adds builds structure definition based on information gained before structure definition. Currently it's quite umplesant. It will allow to do in C things like with usage of Class/Function templates from C++. For example: /* File a.h */ #js generate-struct(name) { let output = "struct " + name + '}'; if (definied(name # "_is_list") { output += "struct " + name + " *next;"; list_types[list_types.length] = "struct " + name; } return output; } /* Another file */ #include "a.h" #js put_all_list_procedure { let output = ''; for (a in list_types) { // We now create prepend, append, get_next, etc. functions, for example output += list_types[a] + "*get_next(" + list_types[a] +"*prev) { return prev->next; }"; } return output; } I can work on it, but I'm lack of free time, resources and good hardware. I have downloaded gcc sources previousle and there's too many files - compiling it will take eras! And of course - somebody should give me a free hand. -- Pozdrawiam, Lach Sławomir.
C language extension - Automatically cast
In desperation made by programming in GTK+ I realized, some of object languages could been implemented in C, but only these not require to made changes in programs in runtime (compiler output). One of items is automatically cast. For example I declared variable called Button of GtkButton and pass it to function requires GtkWidget. Why do not automatically cast to GtkWidget (like in class hierarchy or conversion operator in C++ or some extra constructors)? But .. it's rather conversion operator. It could looks like: __gcc_parent_type GtkWidget __gcc_parent_type_for GtkButton, GtkLabel, GtkTextView __gcc_parent_type GtkBin __gcc_parent_type_for GtkWindow, GtkBox What do you think? It makes sense, because in this case there's no way to made mistake by avoiding extra conversion. Function expected any of GtkWidget (for example), so passing GtkButton is good. Code would be cleaner, hands will be in better shape and we save programmers time.
Save/Store information, which variable are not initialized
I known, IDE will detect cases, whereas variable is not initialized, but some developers still have problems with variable initialization. I suppose gcc do not support any run-time sanitizer, because I do not found any information. So: gcc will introduce hidden array of variables for each context. One bit stores information about one variable in current scope. So, if it is set - variable was initialized. In other case, variable is not initialized. When new scope is created, gcc will allocate this array and set each element to 0. When program set variable, also bit is set. Each structure will contains this array at top of self. GCC must hack access to this struct in some way. That is big problem to handle this case, because some languages allow to free memory access. Maybe for struct store information about fields state in different part of memory? Idea was inspired by way to detect cases, where return address was written. Programmer should compile program with special switch to enable this mode. GDB could support this feature of gcc and read, which variable was not set.
Learning hardware optimization patch
I am wonder if this will be good choice to allow gcc to generate AI data about best optimization approach on user computer. Yes. GCC team will provide source code for some examples and (once low hardware consumption) made gcc to compile these sources with various optimization patch. It will take avg run time of each patch. Of course - it will run compilation once there is many free resources on computer. Why? To allow user select --best-optimiation-speed-for-my-machine or another optimization criteria, which will depends on AI data sheet. What do you think? Another idea is to allow adding feature point to program. Program will report that user is using some feature. In next step, linker could made optimization based on this - by simply, compiles only functionality, which is used by user. Rest functions will be put into shared objects and special code to load this shared object could been injected to executable. I am not very good in programming, but have had crazy ideas about lot of stuff. Best regards, Lach Sławomir.
Re: Learning hardware optimization patch
Dnia wtorek, 15 listopada 2022 19:42:13 CET Sławomir Lach pisze: > I am wonder if this will be good choice to allow gcc to generate AI data > about best optimization approach on user computer. > > Yes. GCC team will provide source code for some examples and (once low > hardware consumption) made gcc to compile these sources with various > optimization patch. It will take avg run time of each patch. Of course - it > will run compilation once there is many free resources on computer. > Not patch, but path - sorry. Applying different patch, which have optimization is bad idea, because it forces developer to carry out many path :-D . > Why? To allow user select --best-optimiation-speed-for-my-machine or another > optimization criteria, which will depends on AI data sheet. > > What do you think? > > Another idea is to allow adding feature point to program. Program will > report that user is using some feature. In next step, linker could made > optimization based on this - by simply, compiles only functionality, which > is used by user. Rest functions will be put into shared objects and special > code to load this shared object could been injected to executable. > > I am not very good in programming, but have had crazy ideas about lot of > stuff. > > Best regards, > Lach Sławomir.
can-be-null can-not-be-null break-instruction for better handling pointers.
I am not C expert, so be polity. I do not see something similar in C world, but similar techniques in other languages, such like Vala. I suggest to create two new pointer type: 1. can-be-null 2. cannot-be-null (You must find other words to describe it behavior). First enforces to compiler checking it is not null, when it was used (by -> operator) or used, when cannot-be-null is excepted. Of course, user can cast to cannot-be-null to avoid checking. So: 1. Usage with -> operator, or * must be placed inside conditional block, with contains null check in condition 2. Passing as cannot-be-null (except explicit conversion) will requires to put in block as above The same restrictions apply to put normal pointer in case, when cannot-be-null excepted. Additionally, break-instruction word will be reserved for functions, so exit will be traded as end of control-flow and further code will be traded as checked. Imagine assert will be traded as break-ins This code: int get_vector_size(struct vector cannot-be-null *vec) { assert(vec != NULL) return vec->size; } Will be correct, because assert macro will (possible) be extended to: if (!(vec != NULL)) { puts("assertion error: vec != NULL"); exit(1); } And exit will be break-instruction. We could use cannot-be-null in some cases, such like: int year; scanf("How old are you:%d", &year); But user could pass NULL as second parameter. When pointers in scanf parameters are cannot-be-null, the compiler will disallow pass null by us. Of course - inside scanf must check if each parameter are not NULL. Another code: void error(const char *message) { perror(message); } And perror will have cannot-be-null word describe one's parameter. This will cause compile-time-error, because message was passed to function, which parameter is cannot-be-null. Programmer should do: void error(const char *message) { if (NULL != message) perror(message); } What do you think. This will solve a lot of problems, It could be also great to introduce function checking if any of it parameter are null, but I do not known how to make it good-quality (simple in usage). Programer should propably pass number of passed parameters, or type of parameter before each.