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:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user