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

Built-in primitives do not use proper error codes #162

Open
LinqLover opened this issue Feb 27, 2024 · 1 comment
Open

Built-in primitives do not use proper error codes #162

LinqLover opened this issue Feb 27, 2024 · 1 comment

Comments

@LinqLover
Copy link
Contributor

Forgive me if this statement is not true in its generality, but I found at least a couple of occurrences. For example, the perform primitives do not emit proper error codes at the moment such as #'bad number of arguments' or #'bad argument'. This is inconsistent with the OSVM and the image-side simulator and, if I did not overlook anything, the last reason after my recent PRs that keeps all the ContextTests from going green.

Would this be desired? Would this pattern be the right approach?

    primitivePerform: function(argCount) {
        var selector = this.stackValue(argCount-1);
        var rcvr = this.stackValue(argCount);
        var trueArgCount = argCount - 1;
        var entry = this.findSelectorInClass(selector, trueArgCount, this.getClass(rcvr), argCount);
        if (entry.selector === selector) {
            // selector has been found, rearrange stack
-             if (entry.argCount !== trueArgCount)
+             if (entry.argCount !== trueArgCount) {
+               this.vm.primFailCode = Squeak.PrimErrBadNumArgs;
                return false;
+             }
        var stack = this.activeContext.pointers; // slide eveything down...
            var selectorIndex = this.sp - trueArgCount;
        this.arrayCopy(stack, selectorIndex+1, stack, selectorIndex, trueArgCount);
        this.sp--; // adjust sp accordingly
        } else {
            // stack has already been arranged for #doesNotUnderstand:/#cannotInterpret:
            rcvr = this.stackValue(entry.argCount);
        }
        this.executeNewMethod(rcvr, entry.method, entry.argCount, entry.primIndex, entry.mClass, selector);
        return true;
    },
@codefrau
Copy link
Owner

Yes, this would be desirable, and this looks like the right way to do it ☺️

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

No branches or pull requests

2 participants