UNIT type removed
This commit is contained in:
parent
3d54ed9fb3
commit
d54c2ee79b
|
|
@ -125,8 +125,7 @@ namespace json11 {
|
||||||
////////////////////////
|
////////////////////////
|
||||||
|
|
||||||
static MlValue ivalualize(NullStruct) {
|
static MlValue ivalualize(NullStruct) {
|
||||||
MlValue null;
|
return MlValue::nil();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static MlValue ivalualize(double value) {
|
static MlValue ivalualize(double value) {
|
||||||
|
|
|
||||||
11
debug.lsp
11
debug.lsp
|
|
@ -1,8 +1,3 @@
|
||||||
;; (print
|
(define json_list (parse-json "{\"k1\":\"v1\", \"k2\":42, \"k3\":[\"a\",123,true,false,null]}"))
|
||||||
;; "ahoj"
|
(print json_list)
|
||||||
;; ; this comment is problem
|
(for x json_list (print x))
|
||||||
;; )
|
|
||||||
;; (print "lisp")
|
|
||||||
|
|
||||||
; (define l '(1 2 2 2 3 4 5 4 4 1 2 2 2 3 4 5 4 4 61 2 2 2 3 4 5 4 4 66)
|
|
||||||
|
|
||||||
54
ml.cpp
54
ml.cpp
|
|
@ -22,6 +22,7 @@
|
||||||
#define TOO_FEW_ARGS "too few arguments to function"
|
#define TOO_FEW_ARGS "too few arguments to function"
|
||||||
#define TOO_MANY_ARGS "too many arguments to function"
|
#define TOO_MANY_ARGS "too many arguments to function"
|
||||||
#define INVALID_ARGUMENT "invalid argument"
|
#define INVALID_ARGUMENT "invalid argument"
|
||||||
|
#define INVALID_ARGUMENT_NIL "invalid nil argument"
|
||||||
#define MISMATCHED_TYPES "mismatched types"
|
#define MISMATCHED_TYPES "mismatched types"
|
||||||
#define CALL_NON_FUNCTION "called non-function"
|
#define CALL_NON_FUNCTION "called non-function"
|
||||||
#define UNKNOWN_ERROR "unknown exception"
|
#define UNKNOWN_ERROR "unknown exception"
|
||||||
|
|
@ -38,7 +39,6 @@
|
||||||
#define STRING_TYPE "string"
|
#define STRING_TYPE "string"
|
||||||
#define INT_TYPE "int"
|
#define INT_TYPE "int"
|
||||||
#define FLOAT_TYPE "float"
|
#define FLOAT_TYPE "float"
|
||||||
#define UNIT_TYPE "unit"
|
|
||||||
#define NIL_TYPE "nil"
|
#define NIL_TYPE "nil"
|
||||||
#define FUNCTION_TYPE "function"
|
#define FUNCTION_TYPE "function"
|
||||||
#define ATOM_TYPE "atom"
|
#define ATOM_TYPE "atom"
|
||||||
|
|
@ -57,7 +57,7 @@ bool is_symbol(char ch) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MlValue::MlValue() : type(UNIT) {}
|
MlValue::MlValue() : type(NIL) {}
|
||||||
|
|
||||||
MlValue::MlValue(int i) : type(INT) { stack_data.i = i; }
|
MlValue::MlValue(int i) : type(INT) { stack_data.i = i; }
|
||||||
|
|
||||||
|
|
@ -335,10 +335,8 @@ bool MlValue::operator<(const MlValue &other) const {
|
||||||
|
|
||||||
// This function adds two lisp values, and returns the lisp value result.
|
// This function adds two lisp values, and returns the lisp value result.
|
||||||
MlValue MlValue::operator+(const MlValue &other) const {
|
MlValue MlValue::operator+(const MlValue &other) const {
|
||||||
// If the other value's type is the unit type,
|
if (other.type == NIL)
|
||||||
// don't even bother continuing.
|
throw MlError(*this, MlEnvironment(), INVALID_ARGUMENT_NIL);
|
||||||
// Unit types consume all arithmetic operations.
|
|
||||||
if (other.type == UNIT) return other;
|
|
||||||
|
|
||||||
// Other type must be a float or an int
|
// Other type must be a float or an int
|
||||||
if ((is_number() || other.is_number()) &&
|
if ((is_number() || other.is_number()) &&
|
||||||
|
|
@ -374,8 +372,6 @@ MlValue MlValue::operator+(const MlValue &other) const {
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
} else throw MlError(*this, MlEnvironment(), INVALID_BIN_OP);
|
} else throw MlError(*this, MlEnvironment(), INVALID_BIN_OP);
|
||||||
case UNIT:
|
|
||||||
return *this;
|
|
||||||
default:
|
default:
|
||||||
throw MlError(*this, MlEnvironment(), INVALID_BIN_OP);
|
throw MlError(*this, MlEnvironment(), INVALID_BIN_OP);
|
||||||
}
|
}
|
||||||
|
|
@ -383,10 +379,8 @@ MlValue MlValue::operator+(const MlValue &other) const {
|
||||||
|
|
||||||
// This function subtracts two lisp values, and returns the lisp value result.
|
// This function subtracts two lisp values, and returns the lisp value result.
|
||||||
MlValue MlValue::operator-(const MlValue &other) const {
|
MlValue MlValue::operator-(const MlValue &other) const {
|
||||||
// If the other value's type is the unit type,
|
if (other.type == NIL)
|
||||||
// don't even bother continuing.
|
throw MlError(*this, MlEnvironment(), INVALID_ARGUMENT_NIL);
|
||||||
// Unit types consume all arithmetic operations.
|
|
||||||
if (other.type == UNIT) return other;
|
|
||||||
|
|
||||||
// Other type must be a float or an int
|
// Other type must be a float or an int
|
||||||
if (other.type != FLOAT && other.type != INT)
|
if (other.type != FLOAT && other.type != INT)
|
||||||
|
|
@ -404,9 +398,6 @@ MlValue MlValue::operator-(const MlValue &other) const {
|
||||||
return MlValue(cast_to_float().stack_data.f - other.stack_data.f);
|
return MlValue(cast_to_float().stack_data.f - other.stack_data.f);
|
||||||
// Otherwise, do integer subtraction.
|
// Otherwise, do integer subtraction.
|
||||||
else return MlValue(stack_data.i - other.stack_data.i);
|
else return MlValue(stack_data.i - other.stack_data.i);
|
||||||
case UNIT:
|
|
||||||
// Unit types consume all arithmetic operations.
|
|
||||||
return *this;
|
|
||||||
default:
|
default:
|
||||||
// This operation was done on an unsupported type
|
// This operation was done on an unsupported type
|
||||||
throw MlError(*this, MlEnvironment(), INVALID_BIN_OP);
|
throw MlError(*this, MlEnvironment(), INVALID_BIN_OP);
|
||||||
|
|
@ -415,10 +406,8 @@ MlValue MlValue::operator-(const MlValue &other) const {
|
||||||
|
|
||||||
// This function multiplies two lisp values, and returns the lisp value result.
|
// This function multiplies two lisp values, and returns the lisp value result.
|
||||||
MlValue MlValue::operator*(const MlValue &other) const {
|
MlValue MlValue::operator*(const MlValue &other) const {
|
||||||
// If the other value's type is the unit type,
|
if (other.type == NIL)
|
||||||
// don't even bother continuing.
|
throw MlError(*this, MlEnvironment(), INVALID_ARGUMENT_NIL);
|
||||||
// Unit types consume all arithmetic operations.
|
|
||||||
if (other.type == UNIT) return other;
|
|
||||||
|
|
||||||
// Other type must be a float or an int
|
// Other type must be a float or an int
|
||||||
if (other.type != FLOAT && other.type != INT)
|
if (other.type != FLOAT && other.type != INT)
|
||||||
|
|
@ -434,9 +423,6 @@ MlValue MlValue::operator*(const MlValue &other) const {
|
||||||
return MlValue(cast_to_float().stack_data.f * other.stack_data.f);
|
return MlValue(cast_to_float().stack_data.f * other.stack_data.f);
|
||||||
// Otherwise, do integer multiplication.
|
// Otherwise, do integer multiplication.
|
||||||
else return MlValue(stack_data.i * other.stack_data.i);
|
else return MlValue(stack_data.i * other.stack_data.i);
|
||||||
case UNIT:
|
|
||||||
// Unit types consume all arithmetic operations.
|
|
||||||
return *this;
|
|
||||||
default:
|
default:
|
||||||
// This operation was done on an unsupported type
|
// This operation was done on an unsupported type
|
||||||
throw MlError(*this, MlEnvironment(), INVALID_BIN_OP);
|
throw MlError(*this, MlEnvironment(), INVALID_BIN_OP);
|
||||||
|
|
@ -445,10 +431,8 @@ MlValue MlValue::operator*(const MlValue &other) const {
|
||||||
|
|
||||||
// This function divides two lisp values, and returns the lisp value result.
|
// This function divides two lisp values, and returns the lisp value result.
|
||||||
MlValue MlValue::operator/(const MlValue &other) const {
|
MlValue MlValue::operator/(const MlValue &other) const {
|
||||||
// If the other value's type is the unit type,
|
if (other.type == NIL)
|
||||||
// don't even bother continuing.
|
throw MlError(*this, MlEnvironment(), INVALID_ARGUMENT_NIL);
|
||||||
// Unit types consume all arithmetic operations.
|
|
||||||
if (other.type == UNIT) return other;
|
|
||||||
|
|
||||||
// Other type must be a float or an int
|
// Other type must be a float or an int
|
||||||
if (other.type != FLOAT && other.type != INT)
|
if (other.type != FLOAT && other.type != INT)
|
||||||
|
|
@ -464,9 +448,6 @@ MlValue MlValue::operator/(const MlValue &other) const {
|
||||||
return MlValue(cast_to_float().stack_data.f / other.stack_data.f);
|
return MlValue(cast_to_float().stack_data.f / other.stack_data.f);
|
||||||
// Otherwise, do integer multiplication.
|
// Otherwise, do integer multiplication.
|
||||||
else return MlValue(stack_data.i / other.stack_data.i);
|
else return MlValue(stack_data.i / other.stack_data.i);
|
||||||
case UNIT:
|
|
||||||
// Unit types consume all arithmetic operations.
|
|
||||||
return *this;
|
|
||||||
default:
|
default:
|
||||||
// This operation was done on an unsupported type
|
// This operation was done on an unsupported type
|
||||||
throw MlError(*this, MlEnvironment(), INVALID_BIN_OP);
|
throw MlError(*this, MlEnvironment(), INVALID_BIN_OP);
|
||||||
|
|
@ -475,10 +456,8 @@ MlValue MlValue::operator/(const MlValue &other) const {
|
||||||
|
|
||||||
// This function finds the remainder of two lisp values, and returns the lisp value result.
|
// This function finds the remainder of two lisp values, and returns the lisp value result.
|
||||||
MlValue MlValue::operator%(const MlValue &other) const {
|
MlValue MlValue::operator%(const MlValue &other) const {
|
||||||
// If the other value's type is the unit type,
|
if (other.type == NIL)
|
||||||
// don't even bother continuing.
|
throw MlError(*this, MlEnvironment(), INVALID_ARGUMENT_NIL);
|
||||||
// Unit types consume all arithmetic operations.
|
|
||||||
if (other.type == UNIT) return other;
|
|
||||||
|
|
||||||
// Other type must be a float or an int
|
// Other type must be a float or an int
|
||||||
if (other.type != FLOAT && other.type != INT)
|
if (other.type != FLOAT && other.type != INT)
|
||||||
|
|
@ -492,9 +471,6 @@ MlValue MlValue::operator%(const MlValue &other) const {
|
||||||
if (other.type == FLOAT)
|
if (other.type == FLOAT)
|
||||||
return MlValue(fmod(cast_to_float().stack_data.f, other.stack_data.f));
|
return MlValue(fmod(cast_to_float().stack_data.f, other.stack_data.f));
|
||||||
else return MlValue(stack_data.i % other.stack_data.i);
|
else return MlValue(stack_data.i % other.stack_data.i);
|
||||||
case UNIT:
|
|
||||||
// Unit types consume all arithmetic operations.
|
|
||||||
return *this;
|
|
||||||
default:
|
default:
|
||||||
// This operation was done on an unsupported type
|
// This operation was done on an unsupported type
|
||||||
throw MlError(*this, MlEnvironment(), INVALID_BIN_OP);
|
throw MlError(*this, MlEnvironment(), INVALID_BIN_OP);
|
||||||
|
|
@ -522,8 +498,6 @@ std::string MlValue::get_type_name() {
|
||||||
// lambda and builtin types, we group them together.
|
// lambda and builtin types, we group them together.
|
||||||
// This is because they are both callable.
|
// This is because they are both callable.
|
||||||
return FUNCTION_TYPE;
|
return FUNCTION_TYPE;
|
||||||
case UNIT:
|
|
||||||
return UNIT_TYPE;
|
|
||||||
case NIL:
|
case NIL:
|
||||||
return NIL_TYPE;
|
return NIL_TYPE;
|
||||||
default:
|
default:
|
||||||
|
|
@ -561,8 +535,6 @@ std::string MlValue::display() const {
|
||||||
return "(" + result + ")";
|
return "(" + result + ")";
|
||||||
case BUILTIN:
|
case BUILTIN:
|
||||||
return "<" + str + " at " + to_string(long(stack_data.b)) + ">";
|
return "<" + str + " at " + to_string(long(stack_data.b)) + ">";
|
||||||
case UNIT:
|
|
||||||
return "@";
|
|
||||||
case NIL:
|
case NIL:
|
||||||
return "nil";
|
return "nil";
|
||||||
default:
|
default:
|
||||||
|
|
@ -604,8 +576,6 @@ std::string MlValue::debug() const {
|
||||||
return "(" + result + ")";
|
return "(" + result + ")";
|
||||||
case BUILTIN:
|
case BUILTIN:
|
||||||
return "<" + str + " at " + to_string(long(stack_data.b)) + ">";
|
return "<" + str + " at " + to_string(long(stack_data.b)) + ">";
|
||||||
case UNIT:
|
|
||||||
return "@";
|
|
||||||
case NIL:
|
case NIL:
|
||||||
return "nil";
|
return "nil";
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
3
ml.h
3
ml.h
|
|
@ -77,7 +77,7 @@ typedef MlValue (*Builtin)(std::vector<MlValue>, MlEnvironment &);
|
||||||
class MlValue {
|
class MlValue {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructs a unit value
|
// Constructs a nil value
|
||||||
MlValue();
|
MlValue();
|
||||||
|
|
||||||
// Constructs an integer
|
// Constructs an integer
|
||||||
|
|
@ -200,7 +200,6 @@ private:
|
||||||
STRING,
|
STRING,
|
||||||
LAMBDA,
|
LAMBDA,
|
||||||
BUILTIN,
|
BUILTIN,
|
||||||
UNIT,
|
|
||||||
NIL
|
NIL
|
||||||
} type;
|
} type;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue