Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start adding Primitive Arithmetic. 3+4 WORKS! :-)
- Loading branch information
Showing
7 changed files
with
1,017 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
enum Bytecode { | ||
/** | ||
Page 618/619 arithmeticSelectorPrimitive | ||
*/ | ||
FirstArithmeticSelectorPrimitive = 176, | ||
PrimitiveAdd = 176, | ||
PrimitiveSubtract = 177, | ||
PrimitiveLessThan = 178, | ||
PrimitiveGreaterThan = 179, | ||
PrimitiveLessOrEqual = 180, | ||
PrimitiveGreaterOrEqual = 181, | ||
PrimitiveEqual = 182, | ||
PrimitiveNotEqual = 183, | ||
PrimitiveMultiply = 184, | ||
PrimitiveDivide = 185, | ||
PrimitiveMod = 186, | ||
PrimitiveMakePoint = 187, | ||
PrimitiveBitShift = 188, | ||
PrimitiveDiv = 189, | ||
PrimitiveBitAnd = 190, | ||
PrimitiveBitOr = 191, | ||
LastArithmeticSelectorPrimitive = 191, | ||
|
||
/** | ||
Page 681 routes codes 192-207 through commonSelectorPrimitive but that method | ||
seems to only handle 198 - 202 and does the same thing for 201 and 202. Maybe | ||
it'll be clearer later but for now, just going what I see on 681 */ | ||
FirstCommonSelectorPrimitive = 192, | ||
/* 192, 193, 194, 195, 196, 197? */ | ||
PrimitiveEquivalent = 198, | ||
PrimitiveClass = 199, | ||
PrimitiveBlockCopy = 200, | ||
PrimitiveValue1 = 201, | ||
PrimitiveValue2 = 202, | ||
/* 203, 204, 205, 206, 207 */ | ||
LastCommonSelectorPrimitive = 207 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
#include "Interpreter.h" | ||
#include "Interpreter_PrimArith.h" | ||
#include <stdio.h> | ||
|
||
Bool Interpreter_dispatchArithmeticPrimitives( int primitiveIndex ) { | ||
if( primitiveIndex < 20 ) { | ||
return Interpreter_dispatchIntegerPrimitives( primitiveIndex ); | ||
} | ||
/* if( primitiveIndex < 40 ) { | ||
return Interpreter_dispatchLargeIntegerPrimitives( primitiveIndex ); | ||
} | ||
if( primitiveIndex < 60 ) { | ||
return Interpreter_dispatchFloatPrimitives( primitiveIndex ); | ||
}*/ | ||
return NO; | ||
} | ||
|
||
Bool Interpreter_dispatchIntegerPrimitives( int primitiveIndex ) { | ||
switch( primitiveIndex ) { | ||
case 1: return Interpreter_primitiveAdd(); | ||
case 2: return Interpreter_primitiveSubtract(); | ||
case 3: return Interpreter_primitiveLessThan(); | ||
case 4: return Interpreter_primitiveGreaterThan(); | ||
case 5: return Interpreter_primitiveLessOrEqual(); | ||
case 6: return Interpreter_primitiveGreaterOrEqual(); | ||
case 7: return Interpreter_primitiveEqual(); | ||
case 8: return Interpreter_primitiveNotEqual(); | ||
case 9: return Interpreter_primitiveMultiply(); | ||
case 10: return Interpreter_primitiveDivide(); | ||
case 11: return Interpreter_primitiveMod(); | ||
case 12: return Interpreter_primitiveDiv(); | ||
case 13: return Interpreter_primitiveQuo(); | ||
case 14: return Interpreter_primitiveBitAnd(); | ||
case 15: return Interpreter_primitiveBitOr(); | ||
case 16: return Interpreter_primitiveBitXor(); | ||
case 17: return Interpreter_primitiveBitShift(); | ||
case 18: return Interpreter_primitiveMakePoint(); | ||
} | ||
return NO; | ||
} | ||
|
||
Bool Interpreter_primitiveAdd(void) { | ||
short integerArgument = Interpreter_popInteger(); | ||
short integerReceiver = Interpreter_popInteger(); | ||
short integerResult = 0; | ||
if( Interpreter_success() == YES ) { | ||
integerResult = integerReceiver + integerArgument; | ||
Interpreter_success_( ObjectMemory_isIntegerValue(integerResult ) ); | ||
} | ||
if( Interpreter_success() == YES ) { | ||
Interpreter_pushInteger(integerResult); | ||
} else { | ||
Interpreter_unPop(2); | ||
} | ||
return Interpreter_success(); | ||
} | ||
|
||
Bool Interpreter_primitiveSubtract(void) { | ||
short integerArgument = Interpreter_popInteger(); | ||
short integerReceiver = Interpreter_popInteger(); | ||
short integerResult = 0; | ||
if( Interpreter_success() == YES ) { | ||
integerResult = integerReceiver - integerArgument; | ||
Interpreter_success_( ObjectMemory_isIntegerValue(integerResult ) ); | ||
} | ||
if( Interpreter_success() == YES ) { | ||
Interpreter_pushInteger(integerResult); | ||
} else { | ||
Interpreter_unPop(2); | ||
} | ||
return Interpreter_success(); | ||
} | ||
|
||
Bool Interpreter_primitiveLessThan(void) { | ||
return NO; | ||
} | ||
|
||
Bool Interpreter_primitiveGreaterThan(void) { | ||
return NO; | ||
} | ||
|
||
Bool Interpreter_primitiveLessOrEqual(void) { | ||
return NO; | ||
} | ||
|
||
Bool Interpreter_primitiveGreaterOrEqual(void) { | ||
return NO; | ||
} | ||
|
||
Bool Interpreter_primitiveEqual(void) { | ||
return NO; | ||
} | ||
|
||
Bool Interpreter_primitiveNotEqual(void) { | ||
return NO; | ||
} | ||
|
||
Bool Interpreter_primitiveMultiply(void) { | ||
short integerArgument = Interpreter_popInteger(); | ||
short integerReceiver = Interpreter_popInteger(); | ||
short integerResult = 0; | ||
if( Interpreter_success() == YES ) { | ||
integerResult = integerReceiver * integerArgument; | ||
Interpreter_success_( ObjectMemory_isIntegerValue(integerResult ) ); | ||
} | ||
if( Interpreter_success() == YES ) { | ||
Interpreter_pushInteger(integerResult); | ||
} else { | ||
Interpreter_unPop(2); | ||
} | ||
return Interpreter_success(); | ||
} | ||
|
||
Bool Interpreter_primitiveDivide(void) { | ||
short integerArgument = Interpreter_popInteger(); | ||
short integerReceiver = Interpreter_popInteger(); | ||
short integerResult = 0; | ||
short integerRemainder = 0; | ||
|
||
/* We only succeed of an integer division can happen cleanly */ | ||
if( Interpreter_success() == YES ) { | ||
integerRemainder = integerReceiver % integerArgument; | ||
Interpreter_success_( integerRemainder == 0 ); | ||
} | ||
|
||
if( Interpreter_success() == YES ) { | ||
integerResult = integerReceiver / integerArgument; | ||
Interpreter_success_( ObjectMemory_isIntegerValue(integerResult ) ); | ||
} | ||
|
||
if( Interpreter_success() == YES ) { | ||
Interpreter_pushInteger(integerResult); | ||
} else { | ||
Interpreter_unPop(2); | ||
} | ||
return Interpreter_success(); | ||
} | ||
|
||
Bool Interpreter_primitiveMod(void) { | ||
return NO; | ||
} | ||
|
||
Bool Interpreter_primitiveDiv(void) { | ||
return NO; | ||
} | ||
|
||
Bool Interpreter_primitiveQuo(void) { | ||
return NO; | ||
} | ||
|
||
Bool Interpreter_primitiveBitAnd(void) { | ||
return NO; | ||
} | ||
|
||
Bool Interpreter_primitiveBitOr(void) { | ||
return NO; | ||
} | ||
|
||
Bool Interpreter_primitiveBitXor(void) { | ||
return NO; | ||
} | ||
|
||
Bool Interpreter_primitiveBitShift(void) { | ||
return NO; | ||
} | ||
|
||
Bool Interpreter_primitiveMakePoint(void) { | ||
return NO; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "types.h" | ||
|
||
Bool Interpreter_dispatchArithmeticPrimitives( int primitiveIndex ); | ||
Bool Interpreter_dispatchIntegerPrimitives( int primitiveIndex ); | ||
|
||
Bool Interpreter_primitiveAdd(void); | ||
Bool Interpreter_primitiveSubtract(void); | ||
Bool Interpreter_primitiveLessThan(void); | ||
Bool Interpreter_primitiveGreaterThan(void); | ||
Bool Interpreter_primitiveLessOrEqual(void); | ||
Bool Interpreter_primitiveGreaterOrEqual(void); | ||
Bool Interpreter_primitiveEqual(void); | ||
Bool Interpreter_primitiveNotEqual(void); | ||
Bool Interpreter_primitiveMultiply(void); | ||
Bool Interpreter_primitiveDivide(void); | ||
Bool Interpreter_primitiveMod(void); | ||
Bool Interpreter_primitiveDiv(void); | ||
Bool Interpreter_primitiveQuo(void); | ||
Bool Interpreter_primitiveBitAnd(void); | ||
Bool Interpreter_primitiveBitOr(void); | ||
Bool Interpreter_primitiveBitXor(void); | ||
Bool Interpreter_primitiveBitShift(void); | ||
Bool Interpreter_primitiveMakePoint(void); |
Oops, something went wrong.