FIX: nested block scopes.
parent
aaeedb1ba9
commit
12f42a86f6
|
@ -1,2 +1,14 @@
|
||||||
(assert-eq? 6 (: 2 4 6))
|
(assert-eq? 6 (: 2 4 6))
|
||||||
(assert-eq? 9 (: 2 4 (: 3 0 9)))
|
(assert-eq? 9 (: 2 4 (: 3 0 9)))
|
||||||
|
|
||||||
|
(:
|
||||||
|
($ a 4)
|
||||||
|
(assert-eq? 4 a)
|
||||||
|
|
||||||
|
(:
|
||||||
|
($ a 7)
|
||||||
|
(assert-eq? 7 a)
|
||||||
|
)
|
||||||
|
|
||||||
|
(assert-eq? 4 a)
|
||||||
|
)
|
|
@ -54,8 +54,6 @@ namespace grino
|
||||||
program.push_instr(OPCODE_POP);
|
program.push_instr(OPCODE_POP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "-------------------------" << std::endl;
|
|
||||||
std::cout << sym.string() << std::endl;
|
|
||||||
|
|
||||||
leave_scope();
|
leave_scope();
|
||||||
sym.purge(m_scope.size());
|
sym.purge(m_scope.size());
|
||||||
|
@ -86,7 +84,7 @@ namespace grino
|
||||||
case NODE_LAMBDA: {
|
case NODE_LAMBDA: {
|
||||||
auto params = node->child(0).lock();
|
auto params = node->child(0).lock();
|
||||||
|
|
||||||
enter_scope();
|
enter_scope(true);
|
||||||
|
|
||||||
for (size_t i=0; i<params->size(); i++)
|
for (size_t i=0; i<params->size(); i++)
|
||||||
{
|
{
|
||||||
|
@ -177,10 +175,17 @@ namespace grino
|
||||||
return m_scope.back() - 1;
|
return m_scope.back() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compiler::enter_scope()
|
void Compiler::enter_scope(bool reset)
|
||||||
|
{
|
||||||
|
if (m_scope.empty() || reset)
|
||||||
{
|
{
|
||||||
m_scope.push_back(0);
|
m_scope.push_back(0);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_scope.push_back(m_scope.back());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Compiler::leave_scope()
|
void Compiler::leave_scope()
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace grino
|
||||||
std::vector<size_t> m_scope;
|
std::vector<size_t> m_scope;
|
||||||
|
|
||||||
size_t get_local_address();
|
size_t get_local_address();
|
||||||
void enter_scope();
|
void enter_scope(bool reset=false);
|
||||||
void leave_scope();
|
void leave_scope();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue