Package org.jruby.truffle.runtime.core

Examples of org.jruby.truffle.runtime.core.RubyModule


    protected void lookup(VirtualFrame frame) {
        CompilerAsserts.neverPartOfCompilation();

        // TODO: this is wrong, we need the lexically enclosing method (or define_method)'s module
        final RubyModule declaringModule = RubyCallStack.getCurrentMethod().getDeclaringModule();
        final RubyClass selfMetaClass = getContext().getCoreLibrary().box(RubyArguments.getSelf(frame.getArguments())).getMetaClass();

        method = ModuleOperations.lookupSuperMethod(declaringModule, name, selfMetaClass);

        if (method == null || method.isUndefined()) {
            method = null;
            // TODO: should add " for #{receiver.inspect}" in error message
            throw new RaiseException(getContext().getCoreLibrary().noMethodError("super: no superclass method `"+name+"'", this));
        }

        final DirectCallNode newCallNode = Truffle.getRuntime().createDirectCallNode(method.getCallTarget());

        if (callNode == null) {
            callNode = insert(newCallNode);
        } else {
            callNode.replace(newCallNode);
        }

        unmodifiedAssumption = declaringModule.getUnmodifiedAssumption();
    }
View Full Code Here


        assert rubyObjectClass != null;
        assert methodDetails != null;

        final RubyContext context = rubyObjectClass.getContext();

        RubyModule module;

        if (methodDetails.getClassAnnotation().name().equals("main")) {
            module = context.getCoreLibrary().getMainObject().getSingletonClass(null);
        } else {
            module = rubyObjectClass;

            for (String moduleName : methodDetails.getClassAnnotation().name().split("::")) {
                module = (RubyModule) ModuleOperations.lookupConstant(context, LexicalScope.NONE, module, moduleName).getValue();
            }
        }

        assert module != null : methodDetails.getClassAnnotation().name();

        final CoreMethod anno = methodDetails.getMethodAnnotation();

        final List<String> names = Arrays.asList(anno.names());
        assert names.size() >= 1;

        final String canonicalName = names.get(0);
        final List<String> aliases = names.subList(1, names.size());

        final Visibility visibility = anno.visibility();

        if (anno.isModuleFunction()) {
            if (visibility != Visibility.PUBLIC) {
                System.err.println("WARNING: visibility ignored when isModuleFunction in " + methodDetails.getIndicativeName());
            }
            if (anno.onSingleton()) {
                System.err.println("WARNING: Either onSingleton or isModuleFunction for " + methodDetails.getIndicativeName());
            }
        }

        // Do not use needsSelf=true in module functions, it is either the module/class or the instance.
        // Usage of needsSelf is quite rare for singleton methods (except constructors).
        final boolean needsSelf = !anno.isModuleFunction() && !anno.onSingleton() && anno.needsSelf();

        final RubyRootNode rootNode = makeGenericMethod(context, methodDetails, needsSelf);

        final RubyMethod method = new RubyMethod(rootNode.getSharedMethodInfo(), canonicalName, module, visibility, false,
                Truffle.getRuntime().createCallTarget(rootNode), null);

        if (anno.isModuleFunction()) {
            addMethod(module, method, aliases, Visibility.PRIVATE);
            addMethod(module.getSingletonClass(null), method, aliases, Visibility.PUBLIC);
        } else if (anno.onSingleton()) {
            addMethod(module.getSingletonClass(null), method, aliases, visibility);
        } else {
            addMethod(module, method, aliases, visibility);
        }
    }
View Full Code Here

    @Override
    public void executeVoid(VirtualFrame frame) {
        notDesignedForCompilation();

        final RubyModule moduleObject;

        try {
            moduleObject = module.executeRubyModule(frame);
        } catch (UnexpectedResultException e) {
            throw new RuntimeException(e);
        }

        moduleObject.undefMethod(this, name);
    }
View Full Code Here

    @Override
    public Object execute(VirtualFrame frame) {
        notDesignedForCompilation();

        // TODO(CS): cast
        final RubyModule module = (RubyModule) definingModule.execute(frame);

        LexicalScope lexicalScope = definitionMethod.getSharedMethodInfo().getLexicalScope();
        lexicalScope.setLiveModule(module);
        lexicalScope.getParent().getLiveModule().addLexicalDependent(module);
View Full Code Here

            }

            throw e;
        }

        RubyModule module = (RubyModule) receiverObject; // TODO(cs): cast
        RubyConstant constant = ModuleOperations.lookupConstant(context, lexicalScope, module, name);

        if (constant == null || !constant.isVisibleTo(context, lexicalScope, module)) {
            return getContext().getCoreLibrary().getNilObject();
        } else {
View Full Code Here

TOP

Related Classes of org.jruby.truffle.runtime.core.RubyModule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.