1
This commit is contained in:
parent
ff2878a50a
commit
df13a1e451
18
a8/lisp.cc
18
a8/lisp.cc
@ -99,9 +99,7 @@ namespace a8
|
||||
|
||||
std::shared_ptr<Value> Expr::Compile(const std::string& script, std::shared_ptr<Scope> env)
|
||||
{
|
||||
#if 0
|
||||
std::vector<List> lists;
|
||||
|
||||
std::vector<List> stack;
|
||||
int pos = 0;
|
||||
int depth = -1;
|
||||
while (true) {
|
||||
@ -111,8 +109,9 @@ namespace a8
|
||||
break;
|
||||
}
|
||||
if (token == "(") {
|
||||
List new_list = std::make_shared<std::vector<std::shared_ptr<Value>>>();
|
||||
stack.push_back(new_list);
|
||||
++depth;
|
||||
lists.push_back(List());
|
||||
} else if (token == ")") {
|
||||
--depth;
|
||||
} else {
|
||||
@ -123,14 +122,14 @@ namespace a8
|
||||
if (sscanf(token.c_str(), "%lf", &val) == 1) {
|
||||
Atom atom;
|
||||
atom.val = val;
|
||||
lists.at(depth).push_back(std::make_shared<Value>(atom));
|
||||
stack.at(depth)->push_back(std::make_shared<Value>(atom));
|
||||
} else {
|
||||
auto symbol = env->Find(token);
|
||||
if (symbol) {
|
||||
if (!symbol->IsType(ValueType::kCProc)) {
|
||||
abort();
|
||||
}
|
||||
lists.at(depth).push_back(symbol);
|
||||
stack.at(depth)->push_back(symbol);
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
@ -140,11 +139,10 @@ namespace a8
|
||||
if (depth != -1) {
|
||||
abort();
|
||||
}
|
||||
if (lists.empty()) {
|
||||
if (stack.empty()) {
|
||||
abort();
|
||||
}
|
||||
//return std::make_shared<Value>(list);
|
||||
#endif
|
||||
return std::make_shared<Value>(stack[0]);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -211,7 +209,7 @@ namespace a8
|
||||
return cproc(exps);
|
||||
} else {
|
||||
CProc&& cproc = std::any_cast<CProc>(Eval(leader, env)->value);
|
||||
List exps;
|
||||
List exps = std::make_shared<std::vector<std::shared_ptr<Value>>>();
|
||||
for (auto itr = list->begin() + 1; itr != list->end(); ++itr) {
|
||||
exps->push_back(Eval(*itr, env));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user