From efa7271a5917c9b78ed06563df2bea13f895f8ca Mon Sep 17 00:00:00 2001 From: mlokr Date: Sun, 7 Jul 2024 14:52:31 +0200 Subject: [PATCH] brahmaputra 4 --- hblang/src/codegen.rs | 19 +++++++------------ hblang/text-prj/main.hb | 2 +- hblang/text-prj/pkg.hb | 2 ++ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/hblang/src/codegen.rs b/hblang/src/codegen.rs index 42d3e1c..3d95aec 100644 --- a/hblang/src/codegen.rs +++ b/hblang/src/codegen.rs @@ -1629,18 +1629,13 @@ impl Codegen { self.ci.free_loc(tal.loc); self.pop_local_snap(checkpoint); match ty::Kind::from_ty(self.ty(target)) { - ty::Kind::Module(idx) => Some(Value::ty( - self.find_or_declare(target.pos(), idx, Err(field), "") - .compress(), - )), - ty::Kind::Global(idx) => Some(Value::ty({ - let global = &self.tys.globals[idx as usize]; - ty::Id::from(u32::from_ne_bytes( - self.output.code[global.offset as usize..][..4] - .try_into() - .unwrap(), - )) - })), + ty::Kind::Module(idx) => { + match self.find_or_declare(target.pos(), idx, Err(field), "") { + ty::Kind::Global(idx) => self.handle_global(idx), + e => Some(Value::ty(e.compress())), + } + } + ty::Kind::Global(idx) => self.handle_global(idx), e => unimplemented!("{e:?}"), } } diff --git a/hblang/text-prj/main.hb b/hblang/text-prj/main.hb index 85e81a9..f36f2fe 100644 --- a/hblang/text-prj/main.hb +++ b/hblang/text-prj/main.hb @@ -1,5 +1,5 @@ pkg := @use("pkg.hb"); main := fn(a: int): int { - return pkg.fib(10); + return pkg.fib(pkg.global); } diff --git a/hblang/text-prj/pkg.hb b/hblang/text-prj/pkg.hb index 931098b..6dd10a5 100644 --- a/hblang/text-prj/pkg.hb +++ b/hblang/text-prj/pkg.hb @@ -1,3 +1,5 @@ +global := 10; + fib := fn(n: int): int { return n + 1; }