a few more consts

This commit is contained in:
VaclavT 2021-02-09 17:44:38 +01:00
parent 4e91a66703
commit 4047c6811d
1 changed files with 8 additions and 8 deletions

16
ml.cpp
View File

@ -152,7 +152,7 @@ class Error {
public:
// Create an error with the value that caused the error,
// 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
Error(Error const &other);
~Error();
@ -183,7 +183,7 @@ public:
// Constructs a floating point value
Value(double f) : type(FLOAT) { stack_data.f = f; }
// 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
static Value quote(Value quoted) {
@ -197,7 +197,7 @@ public:
}
// Construct an atom
static Value atom(std::string s) {
static Value atom(const std::string &s) {
Value result;
result.type = ATOM;
@ -207,7 +207,7 @@ public:
}
// Construct a string
static Value string(std::string s) {
static Value string(const std::string &s) {
Value result;
result.type = STRING;
@ -217,7 +217,7 @@ public:
}
// Construct a lambda function
Value(std::vector<Value> params, Value ret, Environment const &env) : type(LAMBDA) {
Value(const std::vector<Value> &params, Value ret, Environment const &env) : type(LAMBDA) {
// We store the params and the result in the list member
// instead of having dedicated members. This is to save memory.
list.push_back(Value(params));
@ -233,7 +233,7 @@ public:
}
// 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
// to save memory, and use the builtin function slot in the union
// to store the function pointer.
@ -773,7 +773,7 @@ private:
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 = v;
}
@ -1014,7 +1014,7 @@ std::vector<Value> parse(std::string s) {
}
// Execute code in an environment
Value run(std::string code, Environment &env) {
Value run(const std::string &code, Environment &env) {
// Parse the code
std::vector<Value> parsed = parse(code);
// Iterate over the expressions and evaluate them