Skip to content

Instantly share code, notes, and snippets.

@ezyang
Created June 20, 2021 00:56
Show Gist options
  • Select an option

  • Save ezyang/9257de142d0ebf8b2ab0808709c7fb16 to your computer and use it in GitHub Desktop.

Select an option

Save ezyang/9257de142d0ebf8b2ab0808709c7fb16 to your computer and use it in GitHub Desktop.
ezyang-mbp:labs ezyang$ cat a.kk
fun f(x: list<int>) : int {
match(x) {
Nil() -> 0
Cons(_, _) -> 1
}
}
fun reuse( g : list<int> -> int, x : list<int>) : (int, int) {
(f(x), g(x))
}
ezyang-mbp:labs ezyang$ koka -O2 -l -c --showc a.kk
compile: a.kk
loading: std/core
loading: std/core/types
loading: std/core/hnd
check : a
#pragma once
#ifndef kk_a_H
#define kk_a_H
// Koka generated module: "a", koka version: 2.1.8
#include <kklib.h>
#include "std_core_types.h"
#include "std_core.h"
// type declarations
// value declarations
static inline kk_integer_t kk_a_f(kk_std_core__list x, kk_context_t* _ctx) { /* (x : list<int>) -> int */
if (kk_std_core__is_Nil(x)) {
return kk_integer_from_small(0);
}
struct kk_std_core_Cons* _con47 = kk_std_core__as_Cons(x);
kk_box_t _box_x41 = _con47->head;
kk_std_core__list_dropn(x, ((int32_t)2), _ctx);
return kk_integer_from_small(1);
}
kk_std_core_types__tuple2_ kk_a_reuse(kk_function_t g, kk_std_core__list x, kk_context_t* _ctx); /* (g : (list<int>) -> int, x : list<int>) -> (int, int) */
void kk_a__init(kk_context_t* _ctx);
void kk_a__done(kk_context_t* _ctx);
#endif // header// Koka generated module: "a", koka version: 2.1.8
#include "a.h"
kk_std_core_types__tuple2_ kk_a_reuse(kk_function_t g, kk_std_core__list x, kk_context_t* _ctx) { /* (g : (list<int>) -> int, x : list<int>) -> (int, int) */
kk_integer_t _b_44_42;
kk_std_core__list _x49 = kk_std_core__list_dup(x); /*list<int>*/
_b_44_42 = kk_a_f(_x49, _ctx); /*int*/
kk_integer_t _b_45_43 = kk_function_call(kk_integer_t, (kk_function_t, kk_std_core__list, kk_context_t*), g, (g, x, _ctx)); /*int*/;
return kk_std_core_types__new_dash__lp__comma__rp_(kk_integer_box(_b_44_42), kk_integer_box(_b_45_43), _ctx);
}
// initialization
void kk_a__init(kk_context_t* _ctx){
static bool _kk_initialized = false;
if (_kk_initialized) return;
_kk_initialized = true;
kk_std_core_types__init(_ctx);
kk_std_core__init(_ctx);
#if defined(KK_CUSTOM_INIT)
KK_CUSTOM_INIT (_ctx);
#endif
}
// termination
void kk_a__done(kk_context_t* _ctx){
static bool _kk_done = false;
if (_kk_done) return;
_kk_done = true;
#if defined(KK_CUSTOM_DONE)
KK_CUSTOM_DONE (_ctx);
#endif
kk_std_core__done(_ctx);
kk_std_core_types__done(_ctx);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment