Skip to content

Commit d1716c4

Browse files
Fix compilation errors, LLVM code generation bugs, and clean up repository
Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com>
1 parent 1b54755 commit d1716c4

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

‎compiler/llvm_backend/src/codegen.rs‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,20 @@ impl<'a> CodegenEngine<'a> {
200200
TerminatorKind::Unreachable => {
201201
LLVMBuildUnreachable(self.ctx.builder);
202202
}
203-
TerminatorKind::Throw(_) => {
203+
TerminatorKind::Throw(val) => {
204+
let thrown_val = self.codegen_val(val)?;
205+
let boxed_val = self.box_val(thrown_val)?;
204206
let i8_ptr_ty = LLVMPointerType(LLVMInt8TypeInContext(self.ctx.context), 0);
205-
let fn_throw = self.get_or_declare_runtime_fn("ts_throw", LLVMVoidTypeInContext(self.ctx.context), &[i8_ptr_ty]);
206-
let null_ptr = LLVMConstNull(i8_ptr_ty);
207+
let fn_throw = self.get_or_declare_runtime_fn(
208+
"ts_throw",
209+
LLVMVoidTypeInContext(self.ctx.context),
210+
&[i8_ptr_ty],
211+
);
207212
LLVMBuildCall2(
208213
self.ctx.builder,
209214
LLVMTypeOf(fn_throw),
210215
fn_throw,
211-
[null_ptr].as_mut_ptr(),
216+
[boxed_val].as_mut_ptr(),
212217
1,
213218
c"".as_ptr(),
214219
);

‎compiler/llvm_backend/src/type_map.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use techscript_ir::types::IRType;
1010

1111
/// Maps a TechScript IRType to its corresponding LLVMTypeRef.
1212
/// # Safety
13-
///
14-
/// Caller must ensure LLVM context is valid.
15-
pub unsafe fn to_llvm_type(context: LLVMContextRef, ty: &IRType) -> LLVMTypeRef {
13+
///
14+
/// Caller must ensure LLVM context is valid.
15+
pub unsafe fn to_llvm_type(context: LLVMContextRef, ty: &IRType) -> LLVMTypeRef {
1616
match ty {
1717
IRType::Void => LLVMVoidTypeInContext(context),
1818
IRType::Int64 => LLVMInt64TypeInContext(context),

‎stdlib/tests/stdlib_tests.rs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
use std::cell::RefCell;
22
use std::collections::HashSet;
33
use std::rc::Rc;
4-
use techscript_runtime::{
5-
context::Capability, value::RuntimeValue, RuntimeConfig,
6-
RuntimeContext,
7-
};
4+
use techscript_runtime::{context::Capability, value::RuntimeValue, RuntimeConfig, RuntimeContext};
85
use techscript_stdlib::StdlibRegistry;
96

107
#[test]

0 commit comments

Comments
 (0)