a few more consts
This commit is contained in:
parent
4e91a66703
commit
4047c6811d
16
ml.cpp
16
ml.cpp
|
|
@ -152,7 +152,7 @@ class Error {
|
||||||
public:
|
public:
|
||||||
// Create an error with the value that caused the error,
|
// Create an error with the value that caused the error,
|
||||||
// the scope where the error was found, and the message.
|
// the scope where the error was found, and the message.
|
||||||
Error(Value v, Environment const &env, const char *msg);
|
Error(const Value &v, Environment const &env, const char *msg);
|
||||||
// Copy constructor is needed to prevent double frees
|
// Copy constructor is needed to prevent double frees
|
||||||
Error(Error const &other);
|
Error(Error const &other);
|
||||||
~Error();
|
~Error();
|
||||||
|
|
@ -183,7 +183,7 @@ public:
|
||||||
// Constructs a floating point value
|
// Constructs a floating point value
|
||||||
Value(double f) : type(FLOAT) { stack_data.f = f; }
|
Value(double f) : type(FLOAT) { stack_data.f = f; }
|
||||||
// Constructs a list
|
// Constructs a list
|
||||||
Value(std::vector<Value> list) : type(LIST), list(list) {}
|
Value(const std::vector<Value> &list) : type(LIST), list(list) {}
|
||||||
|
|
||||||
// Construct a quoted value
|
// Construct a quoted value
|
||||||
static Value quote(Value quoted) {
|
static Value quote(Value quoted) {
|
||||||
|
|
@ -197,7 +197,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct an atom
|
// Construct an atom
|
||||||
static Value atom(std::string s) {
|
static Value atom(const std::string &s) {
|
||||||
Value result;
|
Value result;
|
||||||
result.type = ATOM;
|
result.type = ATOM;
|
||||||
|
|
||||||
|
|
@ -207,7 +207,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct a string
|
// Construct a string
|
||||||
static Value string(std::string s) {
|
static Value string(const std::string &s) {
|
||||||
Value result;
|
Value result;
|
||||||
result.type = STRING;
|
result.type = STRING;
|
||||||
|
|
||||||
|
|
@ -217,7 +217,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct a lambda function
|
// Construct a lambda function
|
||||||
Value(std::vector<Value> params, Value ret, Environment const &env) : type(LAMBDA) {
|
Value(const std::vector<Value> ¶ms, Value ret, Environment const &env) : type(LAMBDA) {
|
||||||
// We store the params and the result in the list member
|
// We store the params and the result in the list member
|
||||||
// instead of having dedicated members. This is to save memory.
|
// instead of having dedicated members. This is to save memory.
|
||||||
list.push_back(Value(params));
|
list.push_back(Value(params));
|
||||||
|
|
@ -233,7 +233,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct a builtin function
|
// Construct a builtin function
|
||||||
Value(std::string name, Builtin b) : type(BUILTIN) {
|
Value(const std::string &name, Builtin b) : type(BUILTIN) {
|
||||||
// Store the name of the builtin function in the str member
|
// Store the name of the builtin function in the str member
|
||||||
// to save memory, and use the builtin function slot in the union
|
// to save memory, and use the builtin function slot in the union
|
||||||
// to store the function pointer.
|
// to store the function pointer.
|
||||||
|
|
@ -773,7 +773,7 @@ private:
|
||||||
Environment lambda_scope;
|
Environment lambda_scope;
|
||||||
};
|
};
|
||||||
|
|
||||||
Error::Error(Value v, Environment const &env, const char *msg) : env(env), msg(msg) {
|
Error::Error(const Value &v, Environment const &env, const char *msg) : env(env), msg(msg) {
|
||||||
cause = new Value;
|
cause = new Value;
|
||||||
*cause = v;
|
*cause = v;
|
||||||
}
|
}
|
||||||
|
|
@ -1014,7 +1014,7 @@ std::vector<Value> parse(std::string s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute code in an environment
|
// Execute code in an environment
|
||||||
Value run(std::string code, Environment &env) {
|
Value run(const std::string &code, Environment &env) {
|
||||||
// Parse the code
|
// Parse the code
|
||||||
std::vector<Value> parsed = parse(code);
|
std::vector<Value> parsed = parse(code);
|
||||||
// Iterate over the expressions and evaluate them
|
// Iterate over the expressions and evaluate them
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue