Skip to content

Commit

Permalink
local.
Browse files Browse the repository at this point in the history
  • Loading branch information
femtomc committed Jun 20, 2022
1 parent 95ad4fa commit f727bd0
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ tracing = "0.1.29"
tracing-subscriber = "0.3.3"
yansi = "0.5.0"

[build-dependencies]
bindgen = "0.60"

[features]
default = ["cranelift-backend"]
cranelift-backend = ["cranelift", "cranelift-codegen", "cranelift-entity",
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ This is a fork of [this Rust implementation of `mincaml`](https://github.com/osa
It appears the original author has abandoned this project (and is on to better things!), so I'm going to pick it up and try and do some fun stuff with it as I play around with functional language compilation.

- [ ] Implement an LLVM backend.
- [ ] [First, I should probably make it properly polymorphic.](https://en.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_system)
- [ ] Eventually, I'll probably add an LLVM backend through [inkwell](https://github.com/TheDan64/inkwell).
- [ ] [I should probably make it properly polymorphic.](https://en.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_system)
- [ ] Maybe, just maybe -- I'll add a GC!
- [ ] [What if we had a _compile-time_ GC using uniqueness/linear types?](https://github.com/granule-project/granule)
- [ ] [Wow, 1ML looks crazy!](https://people.mpi-sws.org/~rossberg/1ml/)
Expand Down
5 changes: 1 addition & 4 deletions runtime.c → runtime/runtime.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#include <inttypes.h>
#include <math.h>
#include <stdio.h>

typedef struct FunctionClosure_ {
void *function;
} FunctionClosure;
#include "runtime.h"

// int return type because we don't support not returning! Unit is 0.
int64_t mc_print_int_f(FunctionClosure *self, int64_t i) {
Expand Down
39 changes: 39 additions & 0 deletions runtime/runtime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef RUNTIME_H
#define RUNTIME_H

#include <inttypes.h>
#include <math.h>
#include <stdio.h>

typedef struct FunctionClosure_ {
void *function;
} FunctionClosure;

int64_t mc_print_inf_f(FunctionClosure *self, int64_t i);
FunctionClosure mc_print_int;

int64_t mc_print_newline_f(FunctionClosure *self, int64_t i);
FunctionClosure mc_print_newline;

double mc_float_of_int_f(FunctionClosure *self, int64_t i);
FunctionClosure mc_float_of_int;

int64_t mc_int_of_float_f(FunctionClosure *self, double d);
FunctionClosure mc_int_of_float;

// truncate = int_of_float
FunctionClosure mc_truncate;

double mc_abs_float_f(FunctionClosure *self, double d);
FunctionClosure mc_abs_float;

double mc_sqrt_f(FunctionClosure *self, double d);
FunctionClosure mc_sqrt;

double mc_sin_f(FunctionClosure *self, double d);
FunctionClosure mc_sin;

double mc_cos_f(FunctionClosure *self, double d);
FunctionClosure mc_cos;

#endif
8 changes: 4 additions & 4 deletions src/backend/cranelift/cranelift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use cranelift_codegen::ir::MemFlags;
use cranelift_codegen::ir::{AbiParam, InstBuilder, Signature};
use cranelift_codegen::isa;
use cranelift_codegen::isa::CallConv;
use cranelift_codegen::settings::{self};
use cranelift_codegen::settings::{self, Configurable};
use cranelift_codegen::verifier::verify_function;
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
use cranelift_module::{default_libcall_names, DataId, FuncId, Linkage, Module};
Expand Down Expand Up @@ -624,11 +624,11 @@ pub fn codegen(
) -> Vec<u8> {
// Module and FunctionBuilderContext are used for the whole compilation unit. Each function
// gets its own FunctionBuilder.
let shared_builder = settings::builder();
let mut shared_builder = settings::builder();
shared_builder.set("is_pic", "true");
let shared_flags = settings::Flags::new(shared_builder);
shared_flags.enable_verifier();
shared_flags.is_pic();
shared_flags.use_colocated_libcalls();
assert!(shared_flags.is_pic());
let isa_builder = isa::lookup(Triple::host()).unwrap();
let isa = isa_builder.finish(shared_flags).unwrap();
let mut module: ObjectModule = ObjectModule::new(
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn link(path: &str, out_dir: &str, object_code: ObjectCode) -> i32 {
// Build runtime
let output = Command::new("clang")
.args(&[
"runtime.c",
"runtime/runtime.c",
"-g",
"-c",
"-o",
Expand Down

0 comments on commit f727bd0

Please sign in to comment.