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