Commit c4118bc5 authored by Juergen Nickelsen's avatar Juergen Nickelsen
Browse files

two new builtins reminder and shiftright

parent a3d6f42f
org/jnil/files/FileIO.class
org/jnil/functions/Builtin.class
org/jnil/functions/BuiltinFunction.class
org/jnil/functions/Builtins$AndBuiltin.class
org/jnil/functions/Builtins$ApplyBuiltin.class
org/jnil/functions/Builtins$AtomBuiltin.class
org/jnil/functions/Builtins$CarBuiltin.class
org/jnil/functions/Builtins$CdrBuiltin.class
org/jnil/functions/Builtins$ConsBuiltin.class
org/jnil/functions/Builtins$DefspecialBuiltin.class
org/jnil/functions/Builtins$DefunBuiltin.class
org/jnil/functions/Builtins$DescribeBuiltin.class
org/jnil/functions/Builtins$DivideBuiltin.class
org/jnil/functions/Builtins$EltBuiltin.class
org/jnil/functions/Builtins$EqBuiltin.class
org/jnil/functions/Builtins$EqvBuiltin.class
org/jnil/functions/Builtins$ErrorBuiltin.class
org/jnil/functions/Builtins$ErrsetBuiltin.class
org/jnil/functions/Builtins$EvalBuiltin.class
org/jnil/functions/Builtins$FletBuiltin.class
org/jnil/functions/Builtins$FMakUnboundBuiltin.class
org/jnil/functions/Builtins$FormatBuiltin.class
org/jnil/functions/Builtins$FsetBuiltin.class
org/jnil/functions/Builtins$FuncallBuiltin.class
org/jnil/functions/Builtins$IdentityBuiltin.class
org/jnil/functions/Builtins$IfBuiltin.class
org/jnil/functions/Builtins$IgnoreBuiltin.class
org/jnil/functions/Builtins$InternBuiltin.class
org/jnil/functions/Builtins$LambdaBuiltin.class
org/jnil/functions/Builtins$LengthBuiltin.class
org/jnil/functions/Builtins$LetBuiltin.class
org/jnil/functions/Builtins$LetStarBuiltin.class
org/jnil/functions/Builtins$ListBuiltin.class
org/jnil/functions/Builtins$LoadBuiltin.class
org/jnil/functions/Builtins$MakUnboundBuiltin.class
org/jnil/functions/Builtins$MapcarBuiltin.class
org/jnil/functions/Builtins$MinusBuiltin.class
org/jnil/functions/Builtins$NreverseBuiltin.class
org/jnil/functions/Builtins$NullBuiltin.class
org/jnil/functions/Builtins$NumericEqvBuiltin.class
org/jnil/functions/Builtins$NumericGeBuiltin.class
org/jnil/functions/Builtins$NumericGtBuiltin.class
org/jnil/functions/Builtins$NumericLeBuiltin.class
org/jnil/functions/Builtins$NumericLtBuiltin.class
org/jnil/functions/Builtins$OblistBuiltin.class
org/jnil/functions/Builtins$OrBuiltin.class
org/jnil/functions/Builtins$PlusBuiltin.class
org/jnil/functions/Builtins$PrincBuiltin.class
org/jnil/functions/Builtins$PrincfBuiltin.class
org/jnil/functions/Builtins$PrincToStringBuiltin.class
org/jnil/functions/Builtins$PrintBuiltin.class
org/jnil/functions/Builtins$PrintToStringBuiltin.class
org/jnil/functions/Builtins$PrognBuiltin.class
org/jnil/functions/Builtins$QuoteBuiltin.class
org/jnil/functions/Builtins$ReplaceInStringBuiltin.class
org/jnil/functions/Builtins$RplacaBuiltin.class
org/jnil/functions/Builtins$RplacdBuiltin.class
org/jnil/functions/Builtins$SetqBuiltin.class
org/jnil/functions/Builtins$SplitStringBuiltin.class
org/jnil/functions/Builtins$SubstringBuiltin.class
org/jnil/functions/Builtins$SymbolFunctionBuiltin.class
org/jnil/functions/Builtins$TerpriBuiltin.class
org/jnil/functions/Builtins.class
org/jnil/functions/Builtins$TimesBuiltin.class
org/jnil/functions/Builtins$TypeofBuiltin.class
org/jnil/functions/Builtins$WhileBuiltin.class
org/jnil/functions/Builtins$ZeropBuiltin.class
org/jnil/functions/BuiltinSpecial.class
org/jnil/functions/Function.class
org/jnil/functions/Helpers.class
org/jnil/functions/RegisterBuiltins.class
org/jnil/functions/Special.class
org/jnil/objects/Array.class
org/jnil/objects/Atom.class
org/jnil/objects/CharAtom.class
org/jnil/objects/Cons$LispListIterator.class
org/jnil/objects/Cons.class
org/jnil/objects/Environment.class
org/jnil/objects/Fixnum.class
org/jnil/objects/Flonum.class
org/jnil/objects/Globals.class
org/jnil/objects/LispList.class
org/jnil/objects/LispMap.class
org/jnil/objects/LispObject.class
org/jnil/objects/Nil.class
org/jnil/objects/NumberAtom.class
org/jnil/objects/StringAtom.class
org/jnil/objects/Symbol.class
org/jnil/objects/T.class
org/jnil/reader/Lexer$1.class
org/jnil/reader/Lexer$A.class
org/jnil/reader/Lexer$C.class
org/jnil/reader/Lexer$S.class
org/jnil/reader/Lexer.class
org/jnil/reader/LispReader$1.class
org/jnil/reader/LispReader.class
org/jnil/reader/ReaderException.class
org/jnil/reader/Token$1.class
org/jnil/reader/Token$Type.class
org/jnil/reader/Token.class
org/jnil/EvalException.class
org/jnil/Evaluator.class
org/jnil/Jnil.class
org/jnil/Tokens.class
org/jnil/Tools.class
File deleted
......@@ -6,6 +6,39 @@
# %P: parameter declarations
# %C: code
N: Remainder
T: f
F: %
D=
Return remainder of NUM1 divided by NUM2 (which must be fixnums).
EOD
P: num1 num2
C=
return ((NumberAtom) num1).remainder(num2);
EOC
---
N: ShiftRight
T: f
F: >>
D=
Shift N right by BITS.
EOD
P: n bits
C=
return ((NumberAtom) n).shiftRight(bits);
EOC
---
N: ShiftLeft
T: f
F: <<
D=
Shift N left by BITS.
EOD
P: n bits
C=
return ((NumberAtom) n).shiftLeft(bits);
EOC
---
N: Print
T: f
F: print
......
......@@ -79,6 +79,19 @@ public class Fixnum extends NumberAtom {
}
}
/** Remainder.
* @param operand the right-side operand of the operation.
* @return the result of the operation, with possibly a different NumberAtom
* type.
*/
public NumberAtom remainder(LispObject operand) throws EvalException {
if (operand instanceof Fixnum) {
return new Fixnum(value % ((Fixnum) operand).value) ;
} else {
throw new EvalException("operand is not a fixnum: %s", operand) ;
}
}
/** Division.
* @param operand the right-side operand of the operation.
* @return the result of the operation, with possibly a different NumberAtom
......@@ -94,6 +107,32 @@ public class Fixnum extends NumberAtom {
}
}
/** Shift right.
* @param operand the right-side operand of the operation.
* @return the result of the operation, with possibly a different NumberAtom
* type.
*/
public NumberAtom shiftRight(LispObject operand) throws EvalException {
if (operand instanceof Fixnum) {
return new Fixnum(value >> ((Fixnum) operand).value) ;
} else {
throw new EvalException("operand is not a fixnum: %s", operand) ;
}
}
/** Shift left.
* @param operand the right-side operand of the operation.
* @return the result of the operation, with possibly a different NumberAtom
* type.
*/
public NumberAtom shiftLeft(LispObject operand) throws EvalException {
if (operand instanceof Fixnum) {
return new Fixnum(value << ((Fixnum) operand).value) ;
} else {
throw new EvalException("operand is not a fixnum: %s", operand) ;
}
}
/** Return true iff the argument is equal to this.
* @param other the object to compare with.
* @return true iff the argument is equal to this.
......
......@@ -94,6 +94,24 @@ public class Flonum extends NumberAtom {
}
}
/** Shift right.
* @param operand the right-side operand of the operation.
* @return throw an exception, as we do this only for integers
* type.
*/
public NumberAtom shiftRight(LispObject operand) throws EvalException {
throw new EvalException("operand is not a fixnum: %s", this) ;
}
/** Shift left.
* @param operand the right-side operand of the operation.
* @return throw an exception, as we do this only for integers
* type.
*/
public NumberAtom shiftLeft(LispObject operand) throws EvalException {
throw new EvalException("operand is not a fixnum: %s", this) ;
}
public LispObject gt(LispObject operand) throws EvalException {
if (operand instanceof Fixnum) {
return value > ((Fixnum) operand).value ? T.t : Nil.nil ;
......
......@@ -65,4 +65,8 @@ public abstract class NumberAtom extends Atom {
* type.
*/
abstract public NumberAtom divide(LispObject operand) throws EvalException ;
abstract public NumberAtom shiftLeft(LispObject operand) throws EvalException ;
abstract public NumberAtom shiftRight(LispObject operand) throws EvalException ;
abstract public NumberAtom remainder(LispObject operand) throws EvalException ;
}
......@@ -50,7 +50,7 @@ public class StringAtom extends Atom {
public static LispObject newObject(Token token) {
if (token.type != Token.Type.String) {
new IllegalArgumentException("Token " + token
+ " is not of type Stringß") ;
+ " is not of type String") ;
}
return new StringAtom(token.contents) ;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment