diff --git a/examples/basic/broken0001.ngr b/examples/basic/struct0001.ngr similarity index 93% rename from examples/basic/broken0001.ngr rename to examples/basic/struct0001.ngr index 76008d0..dd6f260 100644 --- a/examples/basic/broken0001.ngr +++ b/examples/basic/struct0001.ngr @@ -21,7 +21,7 @@ function slope(p1, p2) -> u64 (getY(p2) - p1.y) / (getX(p2) - p1.x); origin = newPoint(0, 0); -farther = newPoint(4, 4); +farther = newPoint(2, 4); mySlope = slope(origin, farther); print mySlope; \ No newline at end of file diff --git a/src/backend/into_crane.rs b/src/backend/into_crane.rs index 8e9456f..8ab635c 100644 --- a/src/backend/into_crane.rs +++ b/src/backend/into_crane.rs @@ -199,6 +199,7 @@ impl Backend { let func_id = match self.defined_functions.entry(interned_name) { hash_map::Entry::Occupied(entry) => *entry.get(), hash_map::Entry::Vacant(vac) => { + tracing::warn!(name = ?function_name, "compiling undeclared function"); let func_id = self.module.declare_function( function_name, Linkage::Export, diff --git a/src/backend/runtime.rs b/src/backend/runtime.rs index 6e4b437..3b0b18d 100644 --- a/src/backend/runtime.rs +++ b/src/backend/runtime.rs @@ -3,6 +3,7 @@ use cranelift_codegen::isa::CallConv; use cranelift_jit::JITBuilder; use cranelift_module::{FuncId, Linkage, Module, ModuleResult}; use std::collections::HashMap; +use std::alloc::Layout; use std::ffi::CStr; use std::fmt::Write; use target_lexicon::Triple; @@ -93,12 +94,17 @@ impl RuntimeFunctions { pub fn register_jit_implementations(builder: &mut JITBuilder) { let allocation_pointer = unsafe { std::alloc::alloc_zeroed( - std::alloc::Layout::from_size_align(1024 * 1024, 1024 * 1024) + Layout::from_size_align(1024 * 1024, 1024 * 1024) .expect("reasonable layout is reasonable"), ) }; + let allocation_pointer_pointer = unsafe { + let res = std::alloc::alloc(Layout::for_value(&allocation_pointer)) as *mut *mut u8; + *res = allocation_pointer; + res as *const u8 + }; builder.symbol("print", runtime_print as *const u8); - builder.symbol("__global_allocation_pointer__", allocation_pointer); + builder.symbol("__global_allocation_pointer__", allocation_pointer_pointer); } } diff --git a/src/bin/ngrun.rs b/src/bin/ngrun.rs index c40cfbb..c0d79da 100644 --- a/src/bin/ngrun.rs +++ b/src/bin/ngrun.rs @@ -1,10 +1,12 @@ use clap::Parser; use codespan_reporting::files::SimpleFiles; +use cranelift_codegen::timing::compile; use ngr::backend::Backend; use ngr::eval::Value; use ngr::syntax; use ngr::type_infer::TypeInferenceResult; use pretty::termcolor::StandardStream; +use tracing_subscriber::prelude::*; #[derive(Parser, Debug)] #[clap(author, version, about, long_about = None)] @@ -42,7 +44,10 @@ fn jit(ir: ngr::ir::Program) -> Result emit(e.into()), - Ok(compiled_function) => compiled_function(), + Ok(compiled_function) => { + compiled_function() + } } }