diff --git a/ml.cpp b/ml.cpp index 143f4bb..47a0fa6 100644 --- a/ml.cpp +++ b/ml.cpp @@ -1,8 +1,7 @@ // Comment this define out to drop support for standard library functions. // This allows the program to run without a runtime. -#define USE_STD -// Comment this define out to drop support for libm functions + #ifdef HAS_LIBM #include #else @@ -13,10 +12,6 @@ #include "ml.h" -//////////////////////////////////////////////////////////////////////////////// -/// REQUIRED INCLUDES ////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// - #include #include #include @@ -30,7 +25,6 @@ #include #include #include -#include #endif @@ -39,9 +33,6 @@ #include "sslclient.h" #include "json11.h" -//////////////////////////////////////////////////////////////////////////////// -/// ERROR MESSAGES ///////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// #define TOO_FEW_ARGS "too few arguments to function" #define TOO_MANY_ARGS "too many arguments to function" @@ -59,9 +50,6 @@ #define INDEX_OUT_OF_RANGE "index out of range" #define MALFORMED_PROGRAM "malformed program" -//////////////////////////////////////////////////////////////////////////////// -/// TYPE NAMES ///////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// #define STRING_TYPE "string" #define INT_TYPE "int" @@ -72,9 +60,6 @@ #define QUOTE_TYPE "quote" #define LIST_TYPE "list" -//////////////////////////////////////////////////////////////////////////////// -/// HELPER FUNCTIONS /////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// #ifdef USE_STD @@ -118,16 +103,10 @@ bool is_symbol(char ch) { } -//////////////////////////////////////////////////////////////////////////////// -/// LISP CONSTRUCTS //////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// - - MlValue::MlValue() : type(UNIT) {} - MlValue::MlValue(int i) : type(INT) { stack_data.i = i; } MlValue::MlValue(double f) : type(FLOAT) { stack_data.f = f; } @@ -187,9 +166,6 @@ MlValue::MlValue(const std::string &name, Builtin b) : type(BUILTIN) { stack_data.b = b; } -//////////////////////////////////////////////////////////////////////////////// -/// C++ INTEROP METHODS //////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// // Get all of the atoms used in a given MlValue std::vector MlValue::get_used_atoms() { @@ -296,9 +272,6 @@ MlValue MlValue::pop() { return result; } -//////////////////////////////////////////////////////////////////////////////// -/// TYPECASTING METHODS //////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// // Cast this to an integer value MlValue MlValue::cast_to_int() const { @@ -326,9 +299,6 @@ MlValue MlValue::cast_to_float() const { } } -//////////////////////////////////////////////////////////////////////////////// -/// COMPARISON OPERATIONS ////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// bool MlValue::operator==(MlValue other) const { // If either of these values are floats, promote the @@ -368,9 +338,6 @@ bool MlValue::operator!=(const MlValue &other) const { return !(*this == other); } -//////////////////////////////////////////////////////////////////////////////// -/// ORDERING OPERATIONS //////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// bool MlValue::operator>=(const MlValue &other) const { return !(*this < other); @@ -405,9 +372,6 @@ bool MlValue::operator<(const MlValue &other) const { } } -//////////////////////////////////////////////////////////////////////////////// -/// ARITHMETIC OPERATIONS ////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// // This function adds two lisp values, and returns the lisp value result. MlValue MlValue::operator+(const MlValue &other) const { @@ -564,12 +528,11 @@ MlValue MlValue::operator%(const MlValue &other) const { // If we support libm, we can find the remainder of floating point values. #ifdef HAS_LIBM case FLOAT: - return MlValue(fmod(stack_data.f, other.cast_to_float().stack_data.f)); - case INT: - if (other.type == FLOAT) - return MlValue(fmod(cast_to_float().stack_data.f, other.stack_data.f)); - else return MlValue(stack_data.i % other.stack_data.i); - + return MlValue(fmod(stack_data.f, other.cast_to_float().stack_data.f)); + case INT: + if (other.type == FLOAT) + return MlValue(fmod(cast_to_float().stack_data.f, other.stack_data.f)); + else return MlValue(stack_data.i % other.stack_data.i); #else case INT: // If we do not support libm, we have to throw errors for floating point values. @@ -1224,7 +1187,7 @@ namespace builtin { std::string cmd = args[0].as_string(); - std::string cmd_output = ""; + std::string cmd_output; int stat; // TODO better parameter here @@ -1705,7 +1668,7 @@ bool MlEnvironment::has(std::string name) const { if (itr != defs.end()) // If it was found return true; - else if (parent_scope != NULL) + else if (parent_scope != nullptr) // If it was not found in the current environment, // try to find it in the parent environment return parent_scope->has(name); diff --git a/ml.h b/ml.h index 10da210..433c39b 100644 --- a/ml.h +++ b/ml.h @@ -4,6 +4,8 @@ // This allows the program to run without a runtime. #define USE_STD +// Comment this define out to drop support for libm functions +#define HAS_LIBM #include #include