code-generation

How can I dynamically execute function in current scope and add it as property of the calling function?

≡放荡痞女 提交于 2020-01-25 11:08:33
问题 I have some code like this: def f1(): <some stuff here> . . . @mylib.codegen def f2(args): f1() <some more stuff here> mylib.py : def codegen(fn): src = inspect.getsource(fn) original_ast = ast.parse(src) new_ast = transform_ast(original_ast) code_obj = compile(new_ast, '<auto-generated>', 'exec') myscope = {} exec code_obj in myscope fn.generated_fn = myscope['name'] # Where name is the binding created by execing code_obj To summarize, mylib.codegen is a decorator which parses code of f,

How can I dynamically execute function in current scope and add it as property of the calling function?

≡放荡痞女 提交于 2020-01-25 11:06:22
问题 I have some code like this: def f1(): <some stuff here> . . . @mylib.codegen def f2(args): f1() <some more stuff here> mylib.py : def codegen(fn): src = inspect.getsource(fn) original_ast = ast.parse(src) new_ast = transform_ast(original_ast) code_obj = compile(new_ast, '<auto-generated>', 'exec') myscope = {} exec code_obj in myscope fn.generated_fn = myscope['name'] # Where name is the binding created by execing code_obj To summarize, mylib.codegen is a decorator which parses code of f,

Reflect, generate, compile, execute, disassemble, decompile, reflect

安稳与你 提交于 2020-01-17 07:01:12
问题 Before heading back to business, I decided to take a few days off for recreational coding. A few 30-hour days without fresh air? Sounds fantastic, for a change. I've struggled with managed code generation over time and always wondered if there is a circular relationship between C# code, reflection and codedom. Never got around to exploring it sadly. So the goal is to create useless and annoyingly complex classes with nested generics, constraints, anonymous methods, delegates, nested complex

Dynamically loading and unloading a a dll generated using CSharpCodeProvider

点点圈 提交于 2020-01-14 10:38:09
问题 I have an app that uses some code scripts to generate dll's at run-time and invoke them as needed and have run into some questions before i go ahead and code it ! Is it possible to unload them from memory when not needed ? If not - what would be the performance impact of loading them into separate appdomains and invoking the calls using some ipc etc. - btw, this needs to be highly performant/real-time Alternatively, how about loading multiple instances of the generated assembly ( with

Automake, generated source files and VPATH builds

强颜欢笑 提交于 2020-01-14 08:55:13
问题 I'm doing VPATH builds with automake. I'm now also using generated source, with SWIG. I've got rules in Makefile.am like: dist_noinst_DATA = whatever.swig whatever.cpp: whatever.swig swig -c++ -php $^ Then the file gets used later: myprogram_SOURCES = ... whatever.cpp It works fine when $builddir == $srcdir . But when doing VPATH builds (e.g. mkdir build; cd build; ../configure; make ), I get error messages about missing whatever.cpp . Should generated source files go to $builddir or $srcdir

Can't override the standard skeleton views in Symfony2 GeneratorBundle

我们两清 提交于 2020-01-14 08:53:24
问题 I don't manage to override the skeleton views of the generatorBundle. I've first tried by adding my view in /app/Resources/SensioGeneratorBundle/skeleton/crud/views/index.html.twig It didn't worked so I tried to create a new Bundle extending SensioGeneratorBundle and copy the my view in its Resources folder. I already manage to use themes for twig forms, but I need to personalize the views generated by the doctrine:generate:crud command. 回答1: First of all: The corresponding skeleton views are

Replacing // comments with /* comments */ in PHP

我们两清 提交于 2020-01-14 05:12:07
问题 I'm creating a CSS generator in PHP which uses CSSX (yep, they are my idea) files (with a special syntax). One feature is 'short comments': body { font-family: Georgia; //I really like this font! } Now I want to replace this comment with a /* ... */ comment, so the output is like this: body { font-family: Georgia; /*I really like this font!*/ } How can I do this? Thanks, P.S. The complete CSSX file is read into one string variable. P.P.S This q is answered. To fix the url('//server/etc.cssx')

XmlCodeExporter and nullable types

╄→尐↘猪︶ㄣ 提交于 2020-01-13 07:36:07
问题 System.Xml.Serialization.XmlCodeExporter generates code (in code CodeDom form) from an XSD schema. But it does it with some quirks. For example an optional element: <xs:element name="Something" type="xs:decimal" minOccurs="0" maxOccurs="1"/> I would expect this to generate a corresponding code member of type Nullable<decimal> , but it actually creates a member of type decimal , and then a separate SomethingSpecified field which should be toggled separately to indicate a null value. This is

What are good resources on compilation? [duplicate]

こ雲淡風輕ζ 提交于 2020-01-11 19:51:57
问题 This question already has answers here : Learning Resources on Parsers, Interpreters, and Compilers [closed] (12 answers) Closed 5 years ago . Summary for the impatient: I'm searching for good references on generating code for common language constructs but not parsing. I am interested in programming languages and try to read the literature as much as possible. But most of them covers the topic in a functional and theoretical perspective that, I find them hard to understand let alone

What are good resources on compilation? [duplicate]

余生长醉 提交于 2020-01-11 19:50:30
问题 This question already has answers here : Learning Resources on Parsers, Interpreters, and Compilers [closed] (12 answers) Closed 5 years ago . Summary for the impatient: I'm searching for good references on generating code for common language constructs but not parsing. I am interested in programming languages and try to read the literature as much as possible. But most of them covers the topic in a functional and theoretical perspective that, I find them hard to understand let alone