Permalink
Browse files

Fixed some state problems, a memory leak and hopefully a floating poi…

…nt error but really I don't know what I'm looking for as of yet.
  • Loading branch information...
1 parent 2cdf365 commit 18830495b68db694e8b8a16702b4737f48d33f86 @djdrzzy committed Jan 31, 2011
Showing with 7 additions and 6 deletions.
  1. +3 −2 Classes/Instructions/Arithmetic/VCInstructionDivideDelegate.m
  2. +4 −4 Classes/VCRegisters.m
@@ -51,11 +51,12 @@ -(void)runWithInstruction:(VCInstruction*)instruction {
int finalValue = 0;
if(valueOne != 0) {
- finalValue = valueZero / valueOne;
+ finalValue = (int)((float)valueZero / (float)valueOne);
} else {
finalValue = 0;
}
-
+
+
[registers setValueOfRegister:fieldTwo withValue:finalValue];
@@ -106,7 +106,7 @@ -(int)valueOfRegister:(NSUInteger)theRegister {
int valueToReturn =
[[registers objectAtIndex:((NSUInteger)theRegister % [registers count])] intValue];
- return valueToReturn;
+ return (int)valueToReturn;
}
-(int) valueOfInputRegister {
@@ -125,9 +125,9 @@ -(void) setValueOfOutputRegister:(int)valueToPush {
-(NSDictionary*) state {
NSMutableDictionary *dictionaryToReturn = [[[NSMutableDictionary alloc] init] autorelease];
- [dictionaryToReturn setValue:[self.registers copy] forKey:REGISTER_STATE_KEY];
- [dictionaryToReturn setValue:[self.inputRegister copy] forKey:INPUT_STATE_KEY];
- [dictionaryToReturn setValue:[self.outputRegister copy] forKey:OUTPUT_STATE_KEY];
+ [dictionaryToReturn setValue:[[self.registers copy] autorelease] forKey:REGISTER_STATE_KEY];
+ [dictionaryToReturn setValue:[[self.inputRegister copy] autorelease] forKey:INPUT_STATE_KEY];
+ [dictionaryToReturn setValue:[[self.outputRegister copy] autorelease] forKey:OUTPUT_STATE_KEY];
[dictionaryToReturn setValue:[NSNumber numberWithInt:self.programCounter] forKey:PROGRAM_COUNTER_STATE_KEY];
[dictionaryToReturn setValue:[NSNumber numberWithBool:self.haltedFlag] forKey:HALT_FLAG_STATE_KEY];
return dictionaryToReturn;

0 comments on commit 1883049

Please sign in to comment.