Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sometimes Object() == Object. #13

Closed
ghost opened this issue Jun 4, 2011 · 1 comment
Closed

Sometimes Object() == Object. #13

ghost opened this issue Jun 4, 2011 · 1 comment

Comments

@ghost
Copy link

ghost commented Jun 4, 2011

>> Object()
=> <Object a50f0>
>> Object()
=> <Object a5a78>
>> Object
=> Object
>> Object()
=> <Object a8640>
>> Object()
=> <Object a8fc8>

However,

while (Object != Object()):.

runs forever.

@rurban
Copy link
Member

rurban commented Oct 10, 2013

Not a bug. ctor vs object.

Try this:

$ bin/potion -Dt -e'Object()
Object
Object()
Object()!=Object'
-- run-time --
[ 1] self     1     ; Lobby
[ 2] loadk    0 0   ; Object
[ 3] msg      0 1   ; Object
[ 4] call     0 1   ; <Object 7ffca42d26d8>
[ 5] self     1     ; Lobby
[ 6] loadk    0 0   ; Object
[ 7] bind     0 1   ; function Object()
[ 8] loadpn   2 0   ; nil
[ 9] call     0 2   ; Object
[10] self     1     ; Lobby
[11] loadk    0 0   ; Object
[12] msg      0 1   ; Object
[13] call     0 1   ; <Object 7ffca42d2860>
[14] self     1     ; Lobby
[15] loadk    0 0   ; Object
[16] msg      0 1   ; Object
[17] call     0 1   ; <Object 7ffca42d2948>
[18] self     2     ; Lobby
[19] loadk    1 0   ; Object
[20] bind     1 2   ; function Object()
[21] loadpn   3 0   ; nil
[22] call     1 3   ; Object
[23] neq      0 1   ; <Object 7ffca42d2948>!=Object ; true
[24] return   0     ; true

With -Dvt even more.

Object() creates a new Object instance, it is the ctor ("constructor").
That's the first VTABLE path in OP_CALL in the vm, calling potion_object_new(), and then falling thru to the 2nd closure path.

Object returns the current Object.
That's running only the second CLOSURE path in OP_CALL in the vm, just calling the
closure without creating a new object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant