Base compilation of some kind of file to a list of instructions seems to work(!)

I'm able to compile some basic expressions into instructions using the
`not` binary. Big first step, now we need to introduce branches and
loops to the syntax.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-09-16 18:01:40 -07:00
parent 61ac00ae39
commit e72cbe2b8c
5 changed files with 47 additions and 19 deletions

View File

@@ -234,7 +234,7 @@ impl Visit for CompileBody<'_> {
self.compile.collect_locals(body);
let mut thunk = Thunk::Nop;
for stmt in body.body.iter() {
for stmt in body.iter() {
thunk.push_thunk(stmt.accept(self)?);
}
@@ -347,7 +347,13 @@ impl Visit for CompileBody<'_> {
let thunk = match atom {
Atom::Ident(ident) => {
let sym = global_sym(ident.to_string());
let local = self.compile.lookup_scope(sym).unwrap();
let local = if let Some(local) = self.compile.lookup_scope(sym) {
local
} else {
// create a global that gets looked up instead, since nothing with this name
// has been declared/assigned in this scope
self.compile.create_global(sym)
};
// get local
Inst::PushLocal(local).into()
}