Skip to content

Instantly share code, notes, and snippets.

int main(int argc, char **argv) {
ARGC = argc;
ARGV = argv;
int result = harlan_main();
printf("JITTIME: %f\n", double(g_memtime) / 1e9);
return result;
}
@eholk
eholk / gist:2860c7a09b67170c637a
Created February 24, 2015 21:28
arbitrary array index with backpermute
(generate [3 3] (lambda (x y) (* (get A x) (get B y))))
<=>
(let ((As (backpermute [3 3] (lambda (x y) x) A))
(Bs (backpermute [3 3] (lambda (x y) y) B)))
(zipWith (*) As Bs))
@eholk
eholk / remove-closures.scm
Created May 5, 2015 19:26
Weird nanopass behavior
|(remove-closures
(closures
((lambda-type_802
dispatch_803
(closure lambda_233 (int) -> (adt point3f-t_164))
(lambda_801
(__153)
(let ([x_154 float
(call
(var (fn ((ptr FILE)) -> float) file-read-float)
@eholk
eholk / trans.rs
Created May 18, 2011 00:09
alt-block
fn trans_spawn(&ast::spawn_dom dom, &option::t[str] name,
&@ast::expr func, &vec[@ast::expr] args,
&ast::ann ann) -> result {
// Make the task name
let str tname = alt(name) {
case(none) {
auto argss = vec::map(common::expr_to_str, args);
#fmt("%s(%s)",
common::expr_to_str(func),
str::connect(argss, ", "));
@eholk
eholk / trivial-message.rs
Created May 18, 2011 18:23
Exchanging messages with yourself
fn main() {
let port[int] po = port();
let chan[int] ch = chan(po);
auto r <- po;
log_err r;
ch <| 42;
@eholk
eholk / while-dec.rs
Created May 19, 2011 23:22
Backwards while loop.
use std;
import std::vec;
fn main() {
auto v = [1, 2];
auto i = vec::len[int](v) - 1u;
while (i != 0u) {
log_err i;
log_err v.(i);
i -= 1u;
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 3009478..64a6bcb 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -5562,7 +5562,7 @@ fn trans_expr(&@block_ctxt cx, &@ast::expr e) -> result {
}
case (ast::expr_spawn(?dom, ?name, ?func, ?args, ?ann)) {
- ret trans_spawn(dom, name, func, args, ann);
+ ret trans_spawn(cx, dom, name, func, args, ann);
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index db389fc..3e8447a 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -5929,7 +5929,10 @@ fn trans_spawn(&@block_ctxt cx,
//
// 3. Fill the tuple with the arguments we evaluated.
//
- // 4. Pass a pointer to the spawnee function and the argument tuple to
+ // 3.5. Generate a wrapper function that takes the tuple and unpacks it to
fn mk_spawn_wrapper(&@block_ctxt cx,
&str tname,
&@ast::expr func,
&ty::t args_ty) -> result {
auto llmod = cx.fcx.lcx.ccx.llmod;
let TypeRef args_ty_tref = type_of(cx.fcx.lcx.ccx, cx.sp, args_ty);
let TypeRef wrapper_fn_type = T_fn([args_ty_tref], T_void());
log_err #fmt("wrapper args type",
ty_str(cx.fcx.lcx.ccx.tn, args_ty_tref));
fn mk_spawn_wrapper(&@block_ctxt cx,
&str tname,
&@ast::expr func,
&ty::t args_ty) -> result {
auto llmod = cx.fcx.lcx.ccx.llmod;
let TypeRef args_ty_tref = type_of(cx.fcx.lcx.ccx, cx.sp, args_ty);
//let TypeRef wrapper_fn_type = T_fn([args_ty_tref], T_void());
let TypeRef wrapper_fn_type =
type_of_fn(cx.fcx.lcx.ccx, cx.sp, ast::proto_fn,