473,321 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Mixed types and variants

Notes:
- This email is about Mark Dufour's Shed Skin (SS)
(http://shed-skin.blogspot.com), but the errors/ingenuousness it
contains are mine. My experience with C++ is limited still.
- The following code comes from a discussion with Mark.
One of the purposes of SS is to produce fast-running programs
(compiling a subset of Python code to C++), to do this it accepts some
compromises in the type flexibility used by the programs, at the moment
is doesn't allow mixed types (like mixed typed dicts). A future version
of SS may support variant types, that are usually quite slow, but they
may allow SS to use mixed types. If a SSPython program processes a lot
of fixed typed data and few variants, the speed of this program can be
roughly the same, but the range of programs that SS can successfully
compile can be increased.

A variant type may allow SS to manage a dict like this too:
d = {1:"2", "1":2}
Or a list created dynamically like this:
l = [[1,2], [], [], [[3],[4]], [5,[6,7]]]
You can find some C++ variant types:
cdiggins::any
boost::any
boost::variant

But it seems that these only support 'value types', so how to put a
class pointer in such a variant and dynamically call a method?
Something like this fails:

#include "cdiggins.hpp"
#include <stdio.h>

class bert {
public:
int zooi() { return 345; }
};

int main() {
cdiggins::any a = 42;
a = new bert();
printf("%d\n", a.zooi() );
}
If this is not possible, such variants don't look very useful in
general for SS.

My possible answers:
- "Value" types only can be better than nothing, because such variants
can be used to make mixed dicts, those mixed lists, etc. Some
functionality reduction is better than an even bigger functionality
reduction.
- Maybe the boost::variant sourcecode can be modified to allow such
functionality too, or part of it. But this may require a LOT of work on
the C++ implementation (Mark's idea: maybe a better solution would be
to fall back to CPython classes somehow to implement variants...).
- Maybe someone here can suggest some other variant type, or some other
solution.

Bye and thank you,
bearophile

Nov 23 '05 #1
2 1574
> If this is not possible, such variants don't look very useful in
general for SS.

My possible answers:
- "Value" types only can be better than nothing, because such variants
can be used to make mixed dicts, those mixed lists, etc. Some
functionality reduction is better than an even bigger functionality
reduction.
- Maybe the boost::variant sourcecode can be modified to allow such
functionality too, or part of it. But this may require a LOT of work on
the C++ implementation (Mark's idea: maybe a better solution would be
to fall back to CPython classes somehow to implement variants...).
- Maybe someone here can suggest some other variant type, or some other
solution.


The problem is that C++ has no means of a dynamic method invocation. So
I guess the only thing that helps is to use some variant that has a
PyObject-type, and where calls on values of that type are basically
translated to python C-Api calls, delegating the execution to python
itself. Problem: return types aren't known - either handle them as
PyObjects, or have some cast/hinting in place that reduces them to known
native types like uniform lists.

my .2ç

Diez
Nov 23 '05 #2
In article <11**********************@z14g2000cwz.googlegroups .com>,
be************@lycos.com wrote:

...
- Maybe someone here can suggest some other variant type, or some other
solution.


Pyrex? Pyrex is mostly like Python with the possibility of C types. It
handles mixed types just like Python, and the C code it produces is sort
of readable.
__________________________________________________ ______________________
TonyN.:' *firstname*nlsnews@georgea*lastname*.com
' <http://www.georgeanelson.com/>
Nov 24 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
by: James Harris | last post by:
Before I embark on a new long-term project I'd appreciate your advice on how to split up long names. I would like to keep the standards for command names the same as that for variable names....
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
4
by: Lonewolf | last post by:
hi, I'm still in the process of transiting from MFC/VC6 to vs2005, and a lot of things are very alien to me. So hope you could bear with me if my question sounds stupid. Basically I have native...
8
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.