Python

Room rules: sopython.com/chatroom Code formatting guide: tinyu...
Jul 5, 2022 00:24
here's a long shpiel on why this library should exist: github.com/trinodb/trino/discussions/10410
Jul 5, 2022 00:23
here's the library as-of right now: github.com/OneRaynyDay/treeno without a visitor
Jul 5, 2022 00:20
looks like it is, but it also comes w/ its own custom grammar language just like ANTLR
Jul 5, 2022 00:19
one sec, checking if it's codegened
Jul 5, 2022 00:19
I'm actually not sure if this is how python's libast works, since they also have visitX for every node
Jul 5, 2022 00:18
they would initially do pass as it's meant to be an interface that others can specify behavior for
Jul 5, 2022 00:14
and then you can also do the same thing on the visitor class with some metaclass B that keeps track of all nodes X,Y,Z and setattr on the visitor to generate visitX(), visitY(), visitZ()
Jul 5, 2022 00:13
these would be the def visit(visitor) functions required from a visitor
Jul 5, 2022 00:13
@Aran-Fey if you have nodes X,Y,Z, you can have a metaclass A that they all inherit from where you can override __new__ and modify the classdict to include extra fns, or just setattr() the created class with this fn
Jul 5, 2022 00:11
I totally understand @ jobs and other obligations :) I don't expect anyone to e.g. make a parser and implement the 3 options and get back to me on what is the optimal approach. Just wanted to know if anyone has run into this and can save me significant regret by sharing their experience

regarding the 3 options, I worked on compilers at work and we don't mainly use visitors to, e.g. transform 1 AST to another. I've taken some compiler classes (a long time ago) where I wrote the visitor by hand and it was pretty painful. I also tried 1) already and wasn't too happy w/ the lack of ide support
Jul 4, 2022 23:59
My expectation was that the python SO chat would be people eager to give out advice without some monetary compensation in mind (I've lurked here about 4-5 years ago), but perhaps that prior has become less accurate over time
Jul 4, 2022 23:58
:shrug: i don't know, have a fixed rate you're interested in?
Jul 4, 2022 23:56
the visitor is a means to an end, and I'd like a one-shot recommendation and understand its quirks and unknown tradeoffs later on. If that's significant tech debt I can always come back and redo it in another option
Jul 4, 2022 23:55
I would ideally like to do that but there's some time constraints - I took some PTO from work to play around with this toy project and PTO is a finite resource :(
Jul 4, 2022 23:53
I know ANTLR opts for 2), but they also have a full fledged parser grammar, has multiple language targets, and is much greater of an effort than what I'm working on. :shrug:
Jul 4, 2022 23:51
3. Don't be lazy and specify all of the nodes myself (pro: readable and predictable, con: I am a human, missing nodes to visit is somewhat expected)
Jul 4, 2022 23:50
2. Use the same thing above^ to codegen a python file containing the visitor (pro: IDE's will find this, con: autogen code is more work and the build steps will require autogen before packaging)
Jul 4, 2022 23:49
1. Have some metaclass hook or __init_subclass__ magic to detect the existence of nodes and create those functions dynamically (pro: pretty easy to do, con: IDE's will not find this)
Jul 4, 2022 23:48
Suppose there are many nodes in the AST. There are a few ways to create a visitor class that allows you to visit those nodes, classic parser stuff. The problem is how clever I want to be:
Jul 4, 2022 23:47
on the topic of dark magic, was hoping someone could give me a stern recommendation for an AST library I'm working on
 

Lounge<C++>

Today we're daydreaming about C++26 reflection
Jun 17, 2020 08:18
I've heard horrible tales about them but I started doing actual C++ when C++11 hit so I would say I'm pretty fortunate to never have worked w them
Jun 17, 2020 08:18
@Mikhail thank god they're not about near and far pointers
Jun 17, 2020 06:00
I also think the dunders(double underscores) imply builtins or C typing, which C++ naming doesnt mesh well with
Jun 17, 2020 06:00
@Mikhail just the syntax - you're not allowed a main, which makes sense if you're doing some compiling on the fly
Jun 17, 2020 03:30
Man, openCL is weird
Jun 17, 2020 03:29
Jun 17, 2020 03:24
Disclaimer: I'm not an openCL expert. I'm doing some work in clang tooling and I came across an "address space casting" for openCL
Jun 17, 2020 03:24
Wow, wack. But yeah looks similar to JIT'ing
Jun 17, 2020 03:22
Hmm, okay but you still have to compile it right?
Jun 17, 2020 03:21
It's been a while since I've heard compile and runtime in the same time. You mean you JIT it?
Jun 17, 2020 03:19
It seems like the address space scope stuff with __global and stuff are supposedly supported by OpenCL, right?
Jun 17, 2020 03:19
Do you know why this piece of code is running in clang v8 but not trunk? godbolt.org/z/nGvxAC
Jun 17, 2020 03:18
@Mikhail do you use OpenCL by the way?
Jun 6, 2020 00:07
@Mikhail yeah that's what I'm planning to do. But that one doesn't require any data structures to hold intermediate data.
Jun 5, 2020 23:26
there might be some misunderstanding here
Jun 5, 2020 23:26
Jun 5, 2020 23:25
- by making a pseudo-inferior chicken to lay the eggs so the eggs can hatch the standard library chicken
Jun 5, 2020 23:25
yes. I'm gonna have to just reimplement a few containers and we can probably avoid this issue
Jun 5, 2020 23:24
but that is in fact what I did here: github.com/OneRaynyDay/Erata so far.
Jun 5, 2020 23:24
@Mikhail that's a carrot or a stick situation. I don't think many people would opt in when I bash them w/ a stick and say "use my containers or else"
Jun 5, 2020 23:23
So... unless I'm missing something, this is the right level of abstraction, it's just the most PITA level as well
Jun 5, 2020 23:23
@Mikhail unfortunately I want to capture more than just new use cases. Imagine someone wrote a cudaMallocator (that you might want to use in particular), and they don't call new and just calls cudaMalloc in the allocate(size_t n, size_t align) function for the allocator API. What happens then? I'd be leaking allocation information. In fact, I'd say most people using custom allocators are the ones who might find some use with my custom allocator code :-)
Jun 5, 2020 23:19
FWIW IIRC new in gcc is by default jemalloc
Jun 5, 2020 23:19
yes but that's not the level I'm dealing with. I'm providing an alternative implementation of std::allocator which is the source of the chicken-or-the-egg problem
Jun 5, 2020 23:17
i.e. it's a level higher than new, malloc, etc
Jun 5, 2020 23:17
I mean the std::allocator which dispatches either of those two or others (i.e. on-stack arena memory for example)
Jun 5, 2020 23:17
@Mikhail you must be thinking of the actual implementations of malloc(jemalloc/tcmalloc), new, etc
Jun 5, 2020 23:15
out of the entire toolchain for gcc, the only part I'm changing is the allocator implementation and there's no way to move allocators out of the dependencies of the stl containers that I'd be using
Jun 5, 2020 23:13
well actually that's what I mean - libstdc++-v3