🤔 Add a type inference engine, along with typed literals. #4

Merged
acw merged 25 commits from acw/type-checker into develop 2023-09-19 20:40:05 -07:00
5 changed files with 16 additions and 9 deletions
Showing only changes of commit 85ff5c5437 - Show all commits

3
.gitignore vendored
View File

@@ -2,6 +2,9 @@
Cargo.lock
**/*.o
test
test.exe
test.ilk
test.pdb
*.dSYM
.vscode
proptest-regressions/

View File

@@ -12,12 +12,12 @@ path = "src/lib.rs"
clap = { version = "^3.0.14", features = ["derive"] }
codespan = "0.11.1"
codespan-reporting = "0.11.1"
cranelift-codegen = "0.99.1"
cranelift-jit = "0.99.1"
cranelift-frontend = "0.99.1"
cranelift-module = "0.99.1"
cranelift-native = "0.99.1"
cranelift-object = "0.99.1"
cranelift-codegen = "0.99.2"
cranelift-jit = "0.99.2"
cranelift-frontend = "0.99.2"
cranelift-module = "0.99.2"
cranelift-native = "0.99.2"
cranelift-object = "0.99.2"
internment = { version = "0.7.0", default-features = false, features = ["arc"] }
lalrpop-util = "^0.20.0"
lazy_static = "^1.4.0"

View File

@@ -60,6 +60,7 @@ pub struct Backend<M: Module> {
defined_strings: HashMap<String, DataId>,
defined_symbols: HashMap<String, (DataId, ConstantType)>,
output_buffer: Option<String>,
platform: Triple,
}
impl Backend<JITModule> {
@@ -90,6 +91,7 @@ impl Backend<JITModule> {
defined_strings: HashMap::new(),
defined_symbols: HashMap::new(),
output_buffer,
platform: Triple::host(),
})
}
@@ -128,6 +130,7 @@ impl Backend<ObjectModule> {
defined_strings: HashMap::new(),
defined_symbols: HashMap::new(),
output_buffer: None,
platform,
})
}

View File

@@ -31,7 +31,8 @@ impl Backend<JITModule> {
let compiled_bytes = jitter.bytes(function_id);
let compiled_function = unsafe { std::mem::transmute::<_, fn() -> ()>(compiled_bytes) };
compiled_function();
Ok(jitter.output())
let output = jitter.output();
Ok(output)
}
}

View File

@@ -43,7 +43,7 @@ impl<M: Module> Backend<M> {
let basic_signature = Signature {
params: vec![],
returns: vec![],
call_conv: CallConv::SystemV,
call_conv: CallConv::triple_default(&self.platform),
};
// this generates the handle for the function that we'll eventually want to
@@ -211,7 +211,7 @@ impl<M: Module> Backend<M> {
// so we register it using the function ID and our builder context. However, the
// result of this function isn't actually super helpful. So we ignore it, unless
// it's an error.
let _ = self.module.define_function(func_id, &mut ctx)?;
self.module.define_function(func_id, &mut ctx)?;
// done!
Ok(func_id)