Comments (3)
Yes, in general subclassing the built-ins does work since they expect their internal bit representation to be very specific and get horribly confused when you invoke one of the inherited built-in methods on the derived type.
I haven't implemented this yet, but my tentative plan is to just seal the built-in types and make it a runtime error to subclass them. Most of the functionality you'd want to inherit is in the (as-yet-undocumented!) Sequence
class, which you can subclass, so subclassing List
doesn't buy you much.
Thank you for filing this bug, though. It's absolutely a bug that it silently lets you try to do this and then vomits all over itself.
from wren.
I thought that this issue would be an easy task to start contributing with wren, but my analytical powers seem to be fading as I cannot quite find out the superclass name/type.
Questions:
- What built-ins should may NOT be subclassed?
[?] all where type > OBJ_CLASS
[ ] other: ....
- Where should the afrore mentioned runtime-error should be triggered:
[?] wren_vm.c/runInterpreter inside CASE_CODE(IS).
[ ] wren_value.c/wrenNewXXX
[ ] wren_value.c/initObj
[ ] wren_value.c/wrenBindSuperclass
[ ] other: ....
- What is the best way to find out the type of the requested superclass? It seems that everwhere I point my debugger to, the type is OBJ_CLASS.
I feel so stupid, that I cannot fullfill this task that seemed to be so trivial. But now that I started to dig in, I want to know more. Any pointers or tips are greatly appreciated.
from wren.
- What built-ins should may NOT be subclassed?
Basically, the ones that are backed by a C object whose type is not OBJ_INSTANCE
. That's:
OBJ_CLASS,
OBJ_CLOSURE,
OBJ_FIBER,
OBJ_FN,
OBJ_LIST,
OBJ_MAP,
OBJ_RANGE,
OBJ_STRING
- Where should the afrore mentioned runtime-error should be triggered:
Probably in CASE_CODE(CLASS):
, right after:
// TODO: Handle the superclass not being a class object!
:)
- What is the best way to find out the type of the requested superclass? It seems that everwhere I point my debugger to, the type is OBJ_CLASS.
The superclass is a class. Even the built-in types still have actual class objects for their classes, which is where their methods are defined. The problem with inheriting from a built-in type isn't that they don't have a real superclass—they do.
It's that the methods defined in that superclass assume the instance is a specific kind of C object. They will fail horribly if the receiver is an OBJ_INSTANCE
instead.
So what you'll need to check is, "Is the superclass the class of one of the forbidden built-in types?" To do that, it's probably just:
if (superclass == vm->classClass ||
superclass == vm->fnClass ||
...)
{
// Runtime error...
}
You may run into some weird corner case behavior when bootstrapping the core library on this, but hopefully not.
I feel so stupid, that I cannot fullfill this task that seemed to be so trivial.
Lots of things seem trivial before you know a lot of details. This definitely isn't a trivial task. You're pretty deep in the bowels of a C implementation of a programming language's metaobject protocol. It's tricky enough that I procrastinated doing it, after all. :)
from wren.
Related Issues (20)
- [Feature] Pipe Operator for Function Calls HOT 53
- [RFC] Object.responds(_) method HOT 10
- [RFC] Add routines for degrees/radians conversions HOT 21
- [RFC] Adding a `Tuple` with language support HOT 11
- [RFC] Adding `const` versions of `Object`s. HOT 9
- Class reflection for embedding HOT 3
- [RFC] `veery` lang transpiler to `wren` lang HOT 3
- [RFC] Object method message passing syntax HOT 28
- [RFC] Add `static Object.typeOf(_)` (and deprecate `Object.type` ?) HOT 9
- How can i stop wren script running? HOT 3
- Calling wren method handle from inside a bound foreign method body HOT 5
- Whitespace bugs? HOT 4
- Serialize (suspended) fibers or serialize the vm HOT 4
- wren_debug.c should use vm->config.writeFn instead of printf HOT 1
- Should we document this aspect of for loop control variable behavior?
- How do I pass a foreign object to a function call? HOT 3
- is Wren dead? HOT 2
- Where causes code to be called twice HOT 3
- How to return other foreign class obj from a foreign class ? HOT 7
- wrenCall -> foreign call causes memory corruption HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wren.