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

perform:withArguments probably shouldn't work with the wrong number of arguments #43

Open
ltratt opened this issue Jun 12, 2020 · 1 comment

Comments

@ltratt
Copy link

ltratt commented Jun 12, 2020

This program:

perform_witharguments_wrong = (
    run = (
        self perform: #f:b:c: withArguments: #(5 6).
    )

    f: a b: b c: c = (
        a println.
        b println.
        c println.
    )
)

prints:

instance of perform_witharguments_wrong
5
6

on Java SOM. This program:

perform_witharguments_wrong = (
    run = (
        self perform: #f:b:c: withArguments: #(5).
    )

    f: a b: b c: c = (
        a println.
        b println.
        c println.
    )
)

leads to:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 8
	at som.interpreter.Frame.getStackElement(Frame.java:165)
	at som.interpreter.Frame.copyArgumentsFrom(Frame.java:216)
	at som.vmobjects.SMethod.invoke(SMethod.java:124)
	at som.primitives.ObjectPrimitives$6.invoke(ObjectPrimitives.java:130)
	at som.interpreter.Interpreter.send(Interpreter.java:386)
	at som.interpreter.Interpreter.doSend(Interpreter.java:216)
	at som.interpreter.Interpreter.start(Interpreter.java:302)
	at som.vm.Universe.interpretMethod(Universe.java:332)
	at som.vm.Universe.initialize(Universe.java:303)
	at som.vm.Universe.interpret(Universe.java:78)
	at som.vm.Universe.main(Universe.java:64)

I suspect it would be good to require that perform:withArguments checks this and throws an error if the number of arguments doesn't match.

@smarr
Copy link
Member

smarr commented Jun 12, 2020

Yes, indeed.

ltratt added a commit to ltratt/yksom that referenced this issue Jun 12, 2020
This requires a few more changes than might appear immediately necessary.

First, to make things a bit nicer, I've (slightly tortuously) added an "iter"
method to both types of Array. Then, in order to avoid the problem that Java SOM
has (SOM-st/SOM#43 (comment)), we have to
check the number of arguments passed, which means storing those in methods.
bors bot added a commit to softdevteam/yksom that referenced this issue Jun 15, 2020
149: Implement the 'perform:WithArguments' and friends primitives. r=vext01 a=ltratt

This PR implements the various `perform:withArguments` primitives.

Some of the complexity in ef599ea is to make sure that yksom doesn't suffer from the same problems as JavaSOM (see SOM-st/SOM#43 (comment)). bf02eaa is then a simple general optimisation opened up by the first commit. I then factored out the common `perform` code in d58f3e8 which made implementing the other primitives relatively simple.

Co-authored-by: Laurence Tratt <[email protected]>
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

2 participants