goby-lang / goby

Goby - Yet another programming language written in Go
MIT License
3.49k stars 171 forks source link

The top level main object should be printed as "main" #425

Closed hanachin closed 7 years ago

hanachin commented 7 years ago

Before you submit the issue, please provide us following information:

in MRI, the top level main object is printed as "main"

% ruby -e 'puts self'
main

But goby doesn't

% goby -i
Goby 0.1.3 🤣 😹 😶
» puts self
#» <Instance of: Object>
st0012 commented 7 years ago

https://github.com/ruby/ruby/blob/c08f7b80889b531865e74bc5f573df8fa27f2088/eval.c#L1919

hanachin commented 7 years ago
Init_top_self(void)
{
    rb_vm_t *vm = GET_VM();

    vm->top_self = rb_obj_alloc(rb_cObject);
    rb_define_singleton_method(rb_vm_top_self(), "to_s", main_to_s, 0);
    rb_define_alias(rb_singleton_class(rb_vm_top_self()), "inspect", "to_s");
}

https://github.com/ruby/ruby/blob/c08f7b80889b531865e74bc5f573df8fa27f2088/vm.c#L3169,L3177