forked from AbleOS/holey-bytes
adding constants
This commit is contained in:
parent
68c0248189
commit
7d48d3beb1
File diff suppressed because one or more lines are too long
|
@ -2500,12 +2500,8 @@ impl<'a> Codegen<'a> {
|
||||||
let decl = self.find_type(pos, self.ci.file, self.ci.file, Ok(id), self.files);
|
let decl = self.find_type(pos, self.ci.file, self.ci.file, Ok(id), self.files);
|
||||||
match decl.expand() {
|
match decl.expand() {
|
||||||
ty::Kind::NEVER => Value::NEVER,
|
ty::Kind::NEVER => Value::NEVER,
|
||||||
ty::Kind::Global(global) => {
|
ty::Kind::Global(global) => self.gen_global(global),
|
||||||
let gl = &self.tys.ins.globals[global];
|
ty::Kind::Const(cnst) => self.gen_const(cnst),
|
||||||
let value = self.ci.nodes.new_node(gl.ty, Kind::Global { global }, [VOID]);
|
|
||||||
self.ci.nodes[value].aclass = GLOBAL_ACLASS as _;
|
|
||||||
Some(Value::ptr(value).ty(gl.ty))
|
|
||||||
}
|
|
||||||
_ => Some(Value::new(Nid::MAX).ty(decl)),
|
_ => Some(Value::new(Nid::MAX).ty(decl)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2626,13 +2622,8 @@ impl<'a> Codegen<'a> {
|
||||||
.expand()
|
.expand()
|
||||||
{
|
{
|
||||||
ty::Kind::NEVER => Value::NEVER,
|
ty::Kind::NEVER => Value::NEVER,
|
||||||
ty::Kind::Global(global) => {
|
ty::Kind::Global(global) => self.gen_global(global),
|
||||||
let gl = &self.tys.ins.globals[global];
|
ty::Kind::Const(cnst) => self.gen_const(cnst),
|
||||||
let value =
|
|
||||||
self.ci.nodes.new_node(gl.ty, Kind::Global { global }, [VOID]);
|
|
||||||
self.ci.nodes[value].aclass = GLOBAL_ACLASS as _;
|
|
||||||
Some(Value::ptr(value).ty(gl.ty))
|
|
||||||
}
|
|
||||||
v => Some(Value::new(Nid::MAX).ty(v.compress())),
|
v => Some(Value::new(Nid::MAX).ty(v.compress())),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -3771,6 +3762,25 @@ impl<'a> Codegen<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn gen_global(&mut self, global: ty::Global) -> Option<Value> {
|
||||||
|
let gl = &self.tys.ins.globals[global];
|
||||||
|
let value = self.ci.nodes.new_node(gl.ty, Kind::Global { global }, [VOID]);
|
||||||
|
self.ci.nodes[value].aclass = GLOBAL_ACLASS as _;
|
||||||
|
Some(Value::ptr(value).ty(gl.ty))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gen_const(&mut self, cnst: ty::Const) -> Option<Value> {
|
||||||
|
let c = &self.tys.ins.consts[cnst];
|
||||||
|
let f = &self.files[c.file.index()];
|
||||||
|
let Expr::BinOp { left, right, .. } = c.ast.get(f) else { unreachable!() };
|
||||||
|
|
||||||
|
left.find_pattern_path(c.name, right, |expr, is_ct| {
|
||||||
|
debug_assert!(is_ct);
|
||||||
|
self.expr(expr)
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|_| unreachable!())
|
||||||
|
}
|
||||||
|
|
||||||
fn add_clobbers(&mut self, value: Value, clobbered_aliases: &mut BitSet) {
|
fn add_clobbers(&mut self, value: Value, clobbered_aliases: &mut BitSet) {
|
||||||
if let Some(base) = self.tys.base_of(value.ty) {
|
if let Some(base) = self.tys.base_of(value.ty) {
|
||||||
clobbered_aliases.set(self.ci.nodes.aclass_index(value.id).0 as _);
|
clobbered_aliases.set(self.ci.nodes.aclass_index(value.id).0 as _);
|
||||||
|
@ -4496,7 +4506,6 @@ impl TypeParser for Codegen<'_> {
|
||||||
|
|
||||||
let gid = self.tys.ins.globals.push(Global { file, name, ..Default::default() });
|
let gid = self.tys.ins.globals.push(Global { file, name, ..Default::default() });
|
||||||
|
|
||||||
let ty = ty::Kind::Global(gid);
|
|
||||||
self.pool.push_ci(file, None, self.tys.tasks.len(), &mut self.ci);
|
self.pool.push_ci(file, None, self.tys.tasks.len(), &mut self.ci);
|
||||||
let prev_err_len = self.errors.borrow().len();
|
let prev_err_len = self.errors.borrow().len();
|
||||||
|
|
||||||
|
@ -4513,7 +4522,7 @@ impl TypeParser for Codegen<'_> {
|
||||||
self.tys.ins.globals[gid].ty = ret;
|
self.tys.ins.globals[gid].ty = ret;
|
||||||
|
|
||||||
self.ct.deactivate();
|
self.ct.deactivate();
|
||||||
ty.compress()
|
gid.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn report(&self, file: Module, pos: Pos, msg: impl Display) -> ty::Id {
|
fn report(&self, file: Module, pos: Pos, msg: impl Display) -> ty::Id {
|
||||||
|
@ -4572,7 +4581,6 @@ mod tests {
|
||||||
// Tour Examples
|
// Tour Examples
|
||||||
main_fn;
|
main_fn;
|
||||||
arithmetic;
|
arithmetic;
|
||||||
advanced_floating_point_arithmetic;
|
|
||||||
floating_point_arithmetic;
|
floating_point_arithmetic;
|
||||||
functions;
|
functions;
|
||||||
comments;
|
comments;
|
||||||
|
@ -4585,6 +4593,7 @@ mod tests {
|
||||||
hex_octal_binary_literals;
|
hex_octal_binary_literals;
|
||||||
struct_operators;
|
struct_operators;
|
||||||
global_variables;
|
global_variables;
|
||||||
|
constants;
|
||||||
directives;
|
directives;
|
||||||
c_strings;
|
c_strings;
|
||||||
struct_patterns;
|
struct_patterns;
|
||||||
|
@ -4600,6 +4609,7 @@ mod tests {
|
||||||
fb_driver;
|
fb_driver;
|
||||||
|
|
||||||
// Purely Testing Examples;
|
// Purely Testing Examples;
|
||||||
|
advanced_floating_point_arithmetic;
|
||||||
nullable_structure;
|
nullable_structure;
|
||||||
needless_unwrap;
|
needless_unwrap;
|
||||||
inlining_issues;
|
inlining_issues;
|
||||||
|
|
6
lang/tests/son_tests_constants.txt
Normal file
6
lang/tests/son_tests_constants.txt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
main:
|
||||||
|
LI64 r1, 69d
|
||||||
|
JALA r0, r31, 0a
|
||||||
|
code size: 29
|
||||||
|
ret: 69
|
||||||
|
status: Ok(())
|
Loading…
Reference in a new issue