Skip to content

Commit

Permalink
EmptyPrimitive sends now #error: [TODO: tests]
Browse files Browse the repository at this point in the history
TODO:
 need to test stack behavior
 needs unit test to check that it works
Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Mar 17, 2020
1 parent 9de918f commit 0967fa0
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/som/vmobjects/SPrimitive.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public boolean isPrimitive() {
return true;
}

public SPrimitive(String signatureString, final Universe universe) {
public SPrimitive(final String signatureString, final Universe universe) {
signature = universe.symbolFor(signatureString);
}

Expand All @@ -52,7 +52,7 @@ public SClass getHolder() {
}

@Override
public void setHolder(SClass value) {
public void setHolder(final SClass value) {
holder = value;
}

Expand All @@ -66,16 +66,24 @@ public SClass getSOMClass(final Universe universe) {
return universe.primitiveClass;
}

public static SPrimitive getEmptyPrimitive(java.lang.String signatureString,
public static SPrimitive getEmptyPrimitive(final java.lang.String signatureString,
final Universe universe) {
// Return an empty primitive with the given signature
return (new SPrimitive(signatureString, universe) {

@Override
public void invoke(final Frame frame, final Interpreter interpreter) {
// Write a warning to the screen
Universe.println("Warning: undefined primitive "
+ this.getSignature().getEmbeddedString() + " called");
SAbstractObject receiver = null;
for (int i = 0; i < getSignature().getNumberOfSignatureArguments(); i++) {
receiver = frame.pop();
}

String msg = "Undefined primitive "
+ receiver.getSOMClass(universe).getName().getEmbeddedString() + ">>#"
+ this.getSignature().getEmbeddedString() + " called";
send("error:",
new SAbstractObject[] {receiver, universe.newString(msg)},
universe, interpreter);
}

@Override
Expand Down

0 comments on commit 0967fa0

Please sign in to comment.