{"action":"created","issue":{"url":"https://api.github.com/repos/jruby/jruby/issues/3172","labels_url":"https://api.github.com/repos/jruby/jruby/issues/3172/labels{/name}","comments_url":"https://api.github.com/repos/jruby/jruby/issues/3172/comments","events_url":"https://api.github.com/repos/jruby/jruby/issues/3172/events","html_url":"https://github.com/jruby/jruby/pull/3172","id":96929283,"number":3172,"title":"[Truffle] OM DSL","user":{"login":"chrisseaton","id":341094,"avatar_url":"https://avatars.githubusercontent.com/u/341094?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisseaton","html_url":"https://github.com/chrisseaton","followers_url":"https://api.github.com/users/chrisseaton/followers","following_url":"https://api.github.com/users/chrisseaton/following{/other_user}","gists_url":"https://api.github.com/users/chrisseaton/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisseaton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisseaton/subscriptions","organizations_url":"https://api.github.com/users/chrisseaton/orgs","repos_url":"https://api.github.com/users/chrisseaton/repos","events_url":"https://api.github.com/users/chrisseaton/events{/privacy}","received_events_url":"https://api.github.com/users/chrisseaton/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jruby/jruby/labels/truffle","name":"truffle","color":"fbca04"}],"state":"open","locked":false,"assignee":{"login":"chrisseaton","id":341094,"avatar_url":"https://avatars.githubusercontent.com/u/341094?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisseaton","html_url":"https://github.com/chrisseaton","followers_url":"https://api.github.com/users/chrisseaton/followers","following_url":"https://api.github.com/users/chrisseaton/following{/other_user}","gists_url":"https://api.github.com/users/chrisseaton/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisseaton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisseaton/subscriptions","organizations_url":"https://api.github.com/users/chrisseaton/orgs","repos_url":"https://api.github.com/users/chrisseaton/repos","events_url":"https://api.github.com/users/chrisseaton/events{/privacy}","received_events_url":"https://api.github.com/users/chrisseaton/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/jruby/jruby/milestones/34","html_url":"https://github.com/jruby/jruby/milestones/truffle-dev","labels_url":"https://api.github.com/repos/jruby/jruby/milestones/34/labels","id":1009959,"number":34,"title":"truffle-dev","description":null,"creator":{"login":"chrisseaton","id":341094,"avatar_url":"https://avatars.githubusercontent.com/u/341094?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisseaton","html_url":"https://github.com/chrisseaton","followers_url":"https://api.github.com/users/chrisseaton/followers","following_url":"https://api.github.com/users/chrisseaton/following{/other_user}","gists_url":"https://api.github.com/users/chrisseaton/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisseaton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisseaton/subscriptions","organizations_url":"https://api.github.com/users/chrisseaton/orgs","repos_url":"https://api.github.com/users/chrisseaton/repos","events_url":"https://api.github.com/users/chrisseaton/events{/privacy}","received_events_url":"https://api.github.com/users/chrisseaton/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":189,"state":"open","created_at":"2015-03-06T21:20:23Z","updated_at":"2015-07-30T16:11:59Z","due_on":null,"closed_at":null},"comments":8,"created_at":"2015-07-23T23:53:41Z","updated_at":"2015-08-02T07:38:53Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/jruby/jruby/pulls/3172","html_url":"https://github.com/jruby/jruby/pull/3172","diff_url":"https://github.com/jruby/jruby/pull/3172.diff","patch_url":"https://github.com/jruby/jruby/pull/3172.patch"},"body":"This is the next piece in the puzzle for the transition to pure `DynamicObject` and OM. Instead of specifying properties manually for all our existing core classes, this DSL generates them for you from an interface which makes it look a bit more like there's a real class there.\r\n\r\n@nirvdrum @pitr-ch @eregon @woess @thomaswue please review.\r\n\r\nAs you can't see the generated code in the PR, it converts this:\r\n\r\n```java\r\n@Layout\r\npublic interface ArrayLayout {\r\n\r\n    DynamicObject createArray(Object store, int size);\r\n\r\n    boolean isArray(DynamicObject object);\r\n\r\n    Object getStore(DynamicObject object);\r\n\r\n    void setStore(DynamicObject object, Object store);\r\n\r\n    int getSize(DynamicObject object);\r\n\r\n    void setSize(DynamicObject object, int size);\r\n\r\n}\r\n```\r\n\r\nTo this:\r\n\r\n```java\r\npackage org.jruby.truffle.nodes.core.array;\r\n\r\nimport java.util.EnumSet;\r\nimport com.oracle.truffle.api.object.*;\r\nimport org.jruby.truffle.om.dsl.api.UnexpectedLayoutRefusalException;\r\nimport org.jruby.truffle.nodes.core.array.ArrayNodes.ArrayLayout;\r\n\r\npublic class ArrayLayoutImpl implements ArrayLayout {\r\n    \r\n    public static final ArrayLayout INSTANCE = new ArrayLayoutImpl();\r\n    \r\n    private static class ArrayType extends ObjectType {\r\n        \r\n    }\r\n    \r\n    private final ArrayType ARRAY_TYPE = new ArrayType();\r\n    \r\n    private final HiddenKey STORE_IDENTIFIER = new HiddenKey(\"store\");\r\n    private final Property STORE_PROPERTY;\r\n    \r\n    private final HiddenKey SIZE_IDENTIFIER = new HiddenKey(\"size\");\r\n    private final Property SIZE_PROPERTY;\r\n    \r\n    private final DynamicObjectFactory ARRAY_FACTORY;\r\n    \r\n    private ArrayLayoutImpl() {\r\n        final Layout layout = Layout.createLayout(Layout.INT_TO_LONG);\r\n        final Shape.Allocator allocator = layout.createAllocator();\r\n        \r\n        STORE_PROPERTY = Property.create(STORE_IDENTIFIER, allocator.locationForType(java.lang.Object.class, EnumSet.of(LocationModifier.NonNull)), 0);\r\n        SIZE_PROPERTY = Property.create(SIZE_IDENTIFIER, allocator.locationForType(int.class, EnumSet.of(LocationModifier.NonNull)), 0);\r\n        \r\n        final Shape shape = layout.createShape(ARRAY_TYPE)\r\n            .addProperty(STORE_PROPERTY)\r\n            .addProperty(SIZE_PROPERTY);\r\n        \r\n        ARRAY_FACTORY = shape.createFactory();\r\n    }\r\n    \r\n    @Override\r\n    public DynamicObject createArray(java.lang.Object store,\r\n            int size) {\r\n        return ARRAY_FACTORY.newInstance(store,\r\n            size);\r\n    }\r\n    \r\n    @Override\r\n    public boolean isArray(DynamicObject object) {\r\n        return object.getShape().getObjectType() == ARRAY_TYPE;\r\n    }\r\n    \r\n    @Override\r\n    public java.lang.Object getStore(DynamicObject object) {\r\n        assert isArray(object);\r\n        assert object.getShape().hasProperty(STORE_IDENTIFIER);\r\n        \r\n        return (java.lang.Object) STORE_PROPERTY.get(object, true);\r\n    }\r\n    \r\n    @Override\r\n    public void setStore(DynamicObject object, java.lang.Object value) {\r\n        assert isArray(object);\r\n        assert object.getShape().hasProperty(STORE_IDENTIFIER);\r\n        \r\n        try {\r\n            STORE_PROPERTY.set(object, value, object.getShape());\r\n        } catch (IncompatibleLocationException | FinalLocationException e) {\r\n            throw new UnexpectedLayoutRefusalException(e);\r\n        }\r\n    }\r\n    \r\n    @Override\r\n    public int getSize(DynamicObject object) {\r\n        assert isArray(object);\r\n        assert object.getShape().hasProperty(SIZE_IDENTIFIER);\r\n        \r\n        return (int) SIZE_PROPERTY.get(object, true);\r\n    }\r\n    \r\n    @Override\r\n    public void setSize(DynamicObject object, int value) {\r\n        assert isArray(object);\r\n        assert object.getShape().hasProperty(SIZE_IDENTIFIER);\r\n        \r\n        try {\r\n            SIZE_PROPERTY.set(object, value, object.getShape());\r\n        } catch (IncompatibleLocationException | FinalLocationException e) {\r\n            throw new UnexpectedLayoutRefusalException(e);\r\n        }\r\n    }\r\n    \r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/jruby/jruby/issues/comments/126996977","html_url":"https://github.com/jruby/jruby/pull/3172#issuecomment-126996977","issue_url":"https://api.github.com/repos/jruby/jruby/issues/3172","id":126996977,"user":{"login":"jtulach","id":1842422,"avatar_url":"https://avatars.githubusercontent.com/u/1842422?v=3","gravatar_id":"","url":"https://api.github.com/users/jtulach","html_url":"https://github.com/jtulach","followers_url":"https://api.github.com/users/jtulach/followers","following_url":"https://api.github.com/users/jtulach/following{/other_user}","gists_url":"https://api.github.com/users/jtulach/gists{/gist_id}","starred_url":"https://api.github.com/users/jtulach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jtulach/subscriptions","organizations_url":"https://api.github.com/users/jtulach/orgs","repos_url":"https://api.github.com/users/jtulach/repos","events_url":"https://api.github.com/users/jtulach/events{/privacy}","received_events_url":"https://api.github.com/users/jtulach/received_events","type":"User","site_admin":false},"created_at":"2015-08-02T07:38:53Z","updated_at":"2015-08-02T07:38:53Z","body":"I expanded the stackoverflow answer a bit. It should be possible to get access to all elements in a package even in case of incremental compilation."}}