开发者

A self modifying code?

开发者 https://www.devze.com 2023-04-13 02:41 出处:网络
I would like to do the following . I have declared a structure in my program and in run t开发者_运维知识库ime when the program is being executed, if there is a user input, I should be able to create a

I would like to do the following . I have declared a structure in my program and in run t开发者_运维知识库ime when the program is being executed, if there is a user input, I should be able to create another new structure/edit that structure in my code. How can we do that? Is this what "A self modifying code"? Please clarify .Please give some examples .Thanks

Let me give an idea of what I wish to do , I have a "Structure/Class " called "student", which contains variables like "int roll_no" and "int reg_no". If the user wishes to add a new variable like "char name" in run time how can it be done?


Have a look on this:

http://bracha.org/Site/Talks.html

There is talk about reflection, which is probably what you want - reflection is not only about introspection (which most of developers already knows) but also about changing meaning of language constructs and runtime code manipulation.

Best languages for this kind of stuff are probably ruby and smalltalk.

If your language does not support these capabilities, you have still option to leverage code-generation - which is possible in almost every programming language but it is much easier in dynamic ones with "eval" support. For example this kind of stuff is possible even in C/C++ but your app has to embed compiler.

Java is good choice too (thx to classloaders and a lot of libraries for bytecode manipulation)

Oh, I've almost forgot, have a look on lisp and metacircular evaluation.


Sounds like you don't need to modify the existing code, but rather emit some new code in runtime. It is easy to do with any environment where your compiler is present in runtime. It is true for .NET, for JVM-based environments, various Lisps, etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号