Skip to content

Commit

Permalink
set all crates to 0.1.0-alpha.1, and updated deps
Browse files Browse the repository at this point in the history
cranelift has been updated to 1.109, and so alignments have been added
to all stack slots
  • Loading branch information
NotAFlyingGoose committed Jun 20, 2024
1 parent b84c0fd commit 60d79cb
Show file tree
Hide file tree
Showing 24 changed files with 74 additions and 59 deletions.
3 changes: 1 addition & 2 deletions core/manifest.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
name = "core"
version = "0.4.0"
channel = "alpha"
version = "0.1.0-alpha.1"
4 changes: 2 additions & 2 deletions crates/ast/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ast"
version = "0.1.0"
version = "0.1.0-alpha.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -11,4 +11,4 @@ text-size = "1.1.0"

[dev-dependencies]
lexer = {path = "../lexer"}
parser = {path = "../parser"}
parser = {path = "../parser"}
10 changes: 5 additions & 5 deletions crates/capy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "capy"
version = "0.1.0"
version = "0.1.0-alpha.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -18,17 +18,17 @@ line_index = { path = "../line_index" }
diagnostics = { path = "../diagnostics" }
interner = { path = "../interner" }
rustc-hash = "1.1"
supports-color = "2.0.0"
itertools = "0.12.0"
supports-color = "3.0.0"
itertools = "0.13.0"
uid_gen = { path = "../uid_gen" }
path-clean = "1.0.1"
target-lexicon = "0.12.11"
serde_json = "1.0"
base64 = "0.21"
base64 = "0.22.1"
platform-dirs = "0.3.0"

[dependencies.reqwest]
version = "0.11"
version = "0.12.5"
features = ["blocking"]

[dependencies.clap]
Expand Down
2 changes: 1 addition & 1 deletion crates/capy_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "capy_macros"
version = "0.1.0"
version = "0.1.0-alpha.1"
edition = "2021"

[lib]
Expand Down
12 changes: 6 additions & 6 deletions crates/codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "codegen"
version = "0.1.0"
version = "0.1.0-alpha.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -11,11 +11,11 @@ la-arena = "0.3"
hir = { path = "../hir" }
hir_ty = { path = "../hir_ty" }
rustc-hash = "1.1"
cranelift = "0.108"
cranelift-module = "0.108"
cranelift-jit = "0.108"
cranelift-native = "0.108"
cranelift-object = "0.108"
cranelift = "0.109"
cranelift-module = "0.109"
cranelift-jit = "0.109"
cranelift-native = "0.109"
cranelift-object = "0.109"
target-lexicon = "0.12"
internment = "0.8.3"
uid_gen = { path = "../uid_gen" }
Expand Down
14 changes: 8 additions & 6 deletions crates/codegen/src/compiler/comptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ pub fn eval_comptime_blocks<'a>(
module.finalize_definitions().unwrap();

fn run_comptime_float<T: ToBytes + Into<f64> + Copy>(code_ptr: *const u8) -> ComptimeResult {
let comptime = unsafe { mem::transmute::<_, fn() -> T>(code_ptr) };
let comptime = unsafe { mem::transmute::<*const u8, fn() -> T>(code_ptr) };
let result = comptime();

ComptimeResult::Float {
Expand All @@ -244,7 +244,7 @@ pub fn eval_comptime_blocks<'a>(
}

fn run_comptime_int<T: ToBytes + Into<u64> + Copy>(code_ptr: *const u8) -> ComptimeResult {
let comptime = unsafe { mem::transmute::<_, fn() -> T>(code_ptr) };
let comptime = unsafe { mem::transmute::<*const u8, fn() -> T>(code_ptr) };
let result = comptime();

ComptimeResult::Integer {
Expand All @@ -257,7 +257,7 @@ pub fn eval_comptime_blocks<'a>(
let code_ptr = module.get_finalized_function(func_id);

if is_type {
let comptime = unsafe { mem::transmute::<_, fn() -> u32>(code_ptr) };
let comptime = unsafe { mem::transmute::<*const u8, fn() -> u32>(code_ptr) };
let ty = comptime();

let ty = meta_tys.get(&ty).unwrap();
Expand All @@ -276,7 +276,8 @@ pub fn eval_comptime_blocks<'a>(
types::I32 => run_comptime_int::<u32>(code_ptr),
types::I64 => run_comptime_int::<u64>(code_ptr),
types::I128 => {
let comptime = unsafe { mem::transmute::<_, fn() -> u128>(code_ptr) };
let comptime =
unsafe { mem::transmute::<*const u8, fn() -> u128>(code_ptr) };
let result = comptime();

ComptimeResult::Data(Box::new(result.to_ne_bytes()))
Expand All @@ -291,7 +292,8 @@ pub fn eval_comptime_blocks<'a>(
.expect("Invalid layout");
let raw = unsafe { std::alloc::alloc(layout) };

let comptime = unsafe { mem::transmute::<_, fn(*const u8) -> *const u8>(code_ptr) };
let comptime =
unsafe { mem::transmute::<*const u8, fn(*const u8) -> *const u8>(code_ptr) };

comptime(raw);

Expand All @@ -304,7 +306,7 @@ pub fn eval_comptime_blocks<'a>(
results.insert(ctc, ComptimeResult::Data(bytes));
}
FinalTy::Void => {
let comptime = unsafe { mem::transmute::<_, fn()>(code_ptr) };
let comptime = unsafe { mem::transmute::<*const u8, fn()>(code_ptr) };
comptime();
results.insert(ctc, ComptimeResult::Void);
}
Expand Down
21 changes: 13 additions & 8 deletions crates/codegen/src/compiler/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,10 @@ impl FunctionCompiler<'_> {

let param_ty = param_tys[old_idx as usize];
if param_ty.is_aggregate() {
let size = param_ty.size();

let stack_slot = self.builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size,
size: param_ty.size(),
align_shift: param_ty.align() as u8,
});

let stack_slot_addr = self.builder.ins().stack_addr(self.ptr_ty, stack_slot, 0);
Expand Down Expand Up @@ -583,6 +582,7 @@ impl FunctionCompiler<'_> {
let stack_slot = self.builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size: ty.size(),
align_shift: ty.align() as u8,
});

let memory = MemoryLoc::from_stack(stack_slot, 0, &mut self.builder, self.ptr_ty);
Expand Down Expand Up @@ -909,6 +909,7 @@ impl FunctionCompiler<'_> {
let stack_slot = self.builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size: ty.size(),
align_shift: ty.align() as u8,
});

let memory = MemoryLoc::from_stack(stack_slot, 0, &mut self.builder, self.ptr_ty);
Expand Down Expand Up @@ -1036,18 +1037,20 @@ impl FunctionCompiler<'_> {
let stack_slot = self.builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size: 0,
align_shift: 1,
});

Some(self.builder.ins().stack_addr(self.ptr_ty, stack_slot, 0))
}
} else {
let inner_size = self.tys[self.file_name][expr].size();
let inner_ty = self.tys[self.file_name][expr];

// println!("{:?} = {inner_size}", self.tys[self.fqn.module][expr]);

let stack_slot = self.builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size: inner_size,
size: inner_ty.size(),
align_shift: inner_ty.align() as u8,
});

let expr = self.compile_expr(expr).unwrap();
Expand Down Expand Up @@ -1307,11 +1310,10 @@ impl FunctionCompiler<'_> {
.collect::<Vec<_>>();

if return_ty.is_aggregate() {
let aggregate_size = return_ty.size();

let stack_slot = self.builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size: aggregate_size,
size: return_ty.size(),
align_shift: return_ty.align() as u8,
});
let stack_slot_addr = self.builder.ins().stack_addr(self.ptr_ty, stack_slot, 0);

Expand Down Expand Up @@ -1741,6 +1743,8 @@ impl FunctionCompiler<'_> {
let ss = self.builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size: self.ptr_ty.bytes(),
// todo: maybe do this better
align_shift: self.ptr_ty.bytes() as u8,
});

let len = self.builder.ins().iconst(self.ptr_ty, len as i64);
Expand Down Expand Up @@ -1801,6 +1805,7 @@ impl FunctionCompiler<'_> {
let stack_slot = self.builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size: ty.size(),
align_shift: ty.align() as u8,
});

let memory = MemoryLoc::from_stack(stack_slot, 0, &mut self.builder, self.ptr_ty);
Expand Down
18 changes: 9 additions & 9 deletions crates/codegen/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ trait UnwrapOrAlloca {
self,
builder: &mut FunctionBuilder,
ptr_ty: types::Type,
size: u32,
ty: Intern<Ty>,
) -> MemoryLoc;
}

Expand All @@ -1129,14 +1129,15 @@ impl UnwrapOrAlloca for Option<MemoryLoc> {
self,
builder: &mut FunctionBuilder,
ptr_ty: types::Type,
size: u32,
ty: Intern<Ty>,
) -> MemoryLoc {
match self {
Some(mem) => mem,
None => {
let stack_slot = builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size,
size: ty.size(),
align_shift: ty.align() as u8,
});

let addr = builder.ins().stack_addr(ptr_ty, stack_slot, 0);
Expand Down Expand Up @@ -1176,9 +1177,7 @@ fn cast_into_memory(

match (cast_from.as_ref(), cast_to.as_ref()) {
(Ty::Array { size, .. }, Ty::Slice { .. }) => {
let slice_size = cast_to.size();

let memory = memory.unwrap_or_alloca(builder, ptr_ty, slice_size);
let memory = memory.unwrap_or_alloca(builder, ptr_ty, cast_to);

let len = builder.ins().iconst(ptr_ty, *size as i64);
builder
Expand Down Expand Up @@ -1206,7 +1205,7 @@ fn cast_into_memory(
));
}
_ if cast_to.is_any_struct() => {
let any_mem = memory.unwrap_or_alloca(builder, ptr_ty, cast_to.size());
let any_mem = memory.unwrap_or_alloca(builder, ptr_ty, cast_to);

let struct_layout = cast_to.struct_layout().unwrap();

Expand All @@ -1223,6 +1222,7 @@ fn cast_into_memory(
builder.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size: cast_from.size(),
align_shift: cast_from.align() as u8,
});

builder.ins().stack_store(val, tmp_stack_slot, 0);
Expand Down Expand Up @@ -1318,7 +1318,7 @@ fn cast_struct_to_struct(

// this is specifically for anonymous struct casting, although this code
// might also be used to regular struct casting
let result_mem = memory.unwrap_or_alloca(builder, ptr_ty, cast_to.size());
let result_mem = memory.unwrap_or_alloca(builder, ptr_ty, cast_to);

let from_layout = cast_from.struct_layout().unwrap();
let to_layout = cast_to.struct_layout().unwrap();
Expand Down Expand Up @@ -1390,7 +1390,7 @@ fn cast_array_to_array(
} else {
let val = val?;

let result_mem = memory.unwrap_or_alloca(builder, ptr_ty, cast_to.size());
let result_mem = memory.unwrap_or_alloca(builder, ptr_ty, cast_to);

for idx in 0..to_len as u32 {
let from_offset = from_sub_stride * idx;
Expand Down
10 changes: 7 additions & 3 deletions crates/codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,8 @@ mod tests {
fn control_flow() {
check_raw(
r#"
core :: mod "core";
fib :: (n: i32) -> i32 {
if n <= 1 {
return n;
Expand All @@ -1375,7 +1377,10 @@ mod tests {
break loop {
res := fib(x);
if res > 1_000 {
printf("fib(%i) = %i\n", x, res);
core.print("fib(");
core.print(x);
core.print(") = ");
core.println(res);
break x;
}
x = x + 1;
Expand All @@ -1393,10 +1398,9 @@ mod tests {
}
puts :: (s: str) extern;
printf :: (s: str, n1: i32, n2: i32) -> i32 extern;
"#,
"main",
false,
true,
expect![[r#"
before return
before break
Expand Down
2 changes: 1 addition & 1 deletion crates/diagnostics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "diagnostics"
version = "0.1.0"
version = "0.1.0-alpha.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion crates/hir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hir"
version = "0.1.0"
version = "0.1.0-alpha.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion crates/hir_ty/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hir_ty"
version = "0.1.0"
version = "0.1.0-alpha.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
5 changes: 4 additions & 1 deletion crates/hir_ty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,10 @@ mod tests {
&interner,
&world_bodies,
// transmute to get past cyclic dependencies
unsafe { std::mem::transmute(tys) },
#[allow(clippy::missing_transmute_annotations)]
unsafe {
std::mem::transmute(tys)
},
Triple::host().pointer_width().unwrap().bits(),
);

Expand Down
4 changes: 2 additions & 2 deletions crates/interner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "interner"
version = "0.1.0"
version = "0.1.0-alpha.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
lasso = "0.6.0"
lasso = "0.6.0"
4 changes: 3 additions & 1 deletion crates/interner/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::mem;

use lasso::Spur;

macro_rules! impl_interner {
($($keyword:ident => $text:expr,)*) => {
impl Default for Interner {
Expand Down Expand Up @@ -64,7 +66,7 @@ impl Interner {

impl Key {
pub fn from_raw(raw: u32) -> Self {
unsafe { Self(mem::transmute(raw)) }
unsafe { Self(mem::transmute::<u32, Spur>(raw)) }
}

pub fn to_raw(self) -> u32 {
Expand Down
Loading

0 comments on commit 60d79cb

Please sign in to comment.