1
This commit is contained in:
parent
8a1cc4a75a
commit
24625f05d1
32
a8/lisp.cc
32
a8/lisp.cc
@ -106,48 +106,48 @@ namespace a8
|
||||
"+",
|
||||
[] (const List& params) -> std::shared_ptr<Value>
|
||||
{
|
||||
Atom result;
|
||||
double result = 0;
|
||||
for (auto param : *params) {
|
||||
Atom&& atom = std::any_cast<Atom>(param->value);
|
||||
result.val += atom.val;
|
||||
result += atom.val;
|
||||
}
|
||||
return std::make_shared<Value>(result);
|
||||
return std::make_shared<Value>(Atom(result));
|
||||
});
|
||||
RegisterCProc
|
||||
(
|
||||
"-",
|
||||
[] (const List& params) -> std::shared_ptr<Value>
|
||||
{
|
||||
Atom result;
|
||||
double result = 0;
|
||||
for (auto param : *params) {
|
||||
Atom&& atom = std::any_cast<Atom>(param->value);
|
||||
result.val -= atom.val;
|
||||
result -= atom.val;
|
||||
}
|
||||
return std::make_shared<Value>(result);
|
||||
return std::make_shared<Value>(Atom(result));
|
||||
});
|
||||
RegisterCProc
|
||||
(
|
||||
"*",
|
||||
[] (const List& params) -> std::shared_ptr<Value>
|
||||
{
|
||||
Atom result;
|
||||
double result = 0;
|
||||
for (auto param : *params) {
|
||||
Atom&& atom = std::any_cast<Atom>(param->value);
|
||||
result.val *= atom.val;
|
||||
result *= atom.val;
|
||||
}
|
||||
return std::make_shared<Value>(result);
|
||||
return std::make_shared<Value>(Atom(result));
|
||||
});
|
||||
RegisterCProc
|
||||
(
|
||||
"/",
|
||||
[] (const List& params) -> std::shared_ptr<Value>
|
||||
{
|
||||
Atom result;
|
||||
double result = 0;
|
||||
for (auto param : *params) {
|
||||
Atom&& atom = std::any_cast<Atom>(param->value);
|
||||
result.val /= atom.val;
|
||||
result /= atom.val;
|
||||
}
|
||||
return std::make_shared<Value>(result);
|
||||
return std::make_shared<Value>(Atom(result));
|
||||
});
|
||||
}
|
||||
|
||||
@ -177,9 +177,7 @@ namespace a8
|
||||
}
|
||||
double val = 0.0f;
|
||||
if (sscanf(token.c_str(), "%lf", &val) == 1) {
|
||||
Atom atom;
|
||||
atom.val = val;
|
||||
stack.at(depth)->push_back(std::make_shared<Value>(atom));
|
||||
stack.at(depth)->push_back(std::make_shared<Value>(Atom(val)));
|
||||
} else {
|
||||
auto symbol = env->Find(token);
|
||||
if (symbol) {
|
||||
@ -188,9 +186,7 @@ namespace a8
|
||||
}
|
||||
stack.at(depth)->push_back(symbol);
|
||||
} else {
|
||||
Symbol symbol;
|
||||
symbol.name = token;
|
||||
stack.at(depth)->push_back(std::make_shared<Value>(symbol));
|
||||
stack.at(depth)->push_back(std::make_shared<Value>(Symbol(token)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,13 +27,14 @@ namespace a8
|
||||
{
|
||||
double val = 0;
|
||||
|
||||
Atom() {};
|
||||
Atom(double val) { this->val = val; }
|
||||
};
|
||||
|
||||
struct Symbol
|
||||
{
|
||||
std::string name;
|
||||
|
||||
Symbol(const std::string& name) { this->name = name; }
|
||||
};
|
||||
|
||||
struct Value
|
||||
@ -57,6 +58,7 @@ namespace a8
|
||||
public:
|
||||
std::shared_ptr<Value> Find(const std::string& name);
|
||||
void RegisterCProc(const std::string& name, CProc proc);
|
||||
virtual ~Scope() {};
|
||||
|
||||
private:
|
||||
std::map<std::string, std::shared_ptr<Value>> vars_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user