Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the MonoJuvix intermediate language #1341

Closed
lukaszcz opened this issue Jul 5, 2022 · 0 comments · Fixed by #1386
Closed

Remove the MonoJuvix intermediate language #1341

lukaszcz opened this issue Jul 5, 2022 · 0 comments · Fixed by #1386
Assignees
Milestone

Comments

@lukaszcz
Copy link
Collaborator

lukaszcz commented Jul 5, 2022

Monomorphisation seems unnecessary when compiling MicroJuvix to C. Polymorphic functions can be implemented in C by just casting fields and arguments of polymorphic types to an appropriate 'universal' type. For instance, assuming all objects handled by the C runtime are pointers into the heap, the translation of the program

inductive Nat {
   O : Nat;
   S : Nat -> Nat;
};

one : Nat;
one = ...
plus : Nat -> Nat -> Nat;
plus x y = ...

inductive Pair (A : Type) (B : Type) {
   fst : A;
   snd : B;
}; 

f : (A : Type) -> Pair Nat A -> Pair A Nat
f _ p = Pair (snd p) (plus (fst p) one)

would look something like

// the universal type
#define UT (void*)

#define TAG_NAT_O ...
#define TAG_NAT_S ...

typedef struct Nat{
   uint tag;
   struct Nat* S_arg;
} nat_t;

nat_t* one = ...;
nat_t* plus(nat_t* x, nat_t* y) { ... }

typedef struct Pair {
   UT fst, snd;
} pair_t;

pair_t* f(pair_t* p) {
   pair_t* r = malloc(sizeof(Pair));
   r->fst = p->snd;
   r->snd = (UT) plus((nat_t*)(p->fst), one);
   return r;
}

By changing UT, this method can be extended to handle unboxed values of "small" types which fit into the machine word (or several words). The only requirement on UT is that it needs to have enough bits to store pointers and all values of "small" types. This is a "standard" method, e.g., the OCaml compiler uses something similar (the OCaml compiler doesn't produce C code, but the general idea of datatype/function representation is similar).

@lukaszcz lukaszcz self-assigned this Jul 5, 2022
@cwgoes cwgoes transferred this issue from another repository Jul 13, 2022
@jonaprieto jonaprieto added this to the 0.2.2 milestone Jul 14, 2022
lukaszcz added a commit that referenced this issue Jul 15, 2022
* Closes issue #1341.
* Depends on PR [#8](anoma/juvix-stdlib#8) in juvix-stdlib.
* Translation/MonoJuvixToMiniC removed.
* MonoJuvix itself not removed because the MiniHaskell backend depends on it.
* Since MiniHaskell is deprecated, I see no point in wasting time on writing a translation from MicroJuvix to MiniHaskell.
@jonaprieto jonaprieto linked a pull request Jul 15, 2022 that will close this issue
7 tasks
lukaszcz added a commit that referenced this issue Jul 15, 2022
* Closes issue #1341.
* Depends on PR [#8](anoma/juvix-stdlib#8) in juvix-stdlib.
* Translation/MonoJuvixToMiniC removed.
* MonoJuvix itself not removed because the MiniHaskell backend depends on it.
* Since MiniHaskell is deprecated, I see no point in wasting time on writing a translation from MicroJuvix to MiniHaskell.
lukaszcz added a commit that referenced this issue Jul 15, 2022
* Closes issue #1341.
* Depends on PR [#8](anoma/juvix-stdlib#8) in juvix-stdlib.
* Translation/MonoJuvixToMiniC removed.
* MonoJuvix itself not removed because the MiniHaskell backend depends on it.
* Since MiniHaskell is deprecated, I see no point in wasting time on writing a translation from MicroJuvix to MiniHaskell.
lukaszcz added a commit that referenced this issue Jul 18, 2022
* Closes issues #1341, #1338, #1339.
* Depends on PR [#8](anoma/juvix-stdlib#8) in juvix-stdlib.
* Translation/MonoJuvixToMiniC removed.
* MonoJuvix itself not removed because the MiniHaskell backend depends on it.
* Since MiniHaskell is deprecated, I see no point in wasting time on writing a translation from MicroJuvix to MiniHaskell.
lukaszcz added a commit that referenced this issue Jul 18, 2022
* Closes issues #1341, #1338, #1339.
* Depends on PR [#8](anoma/juvix-stdlib#8) in juvix-stdlib.
* Translation/MonoJuvixToMiniC removed.
* MonoJuvix itself not removed because the MiniHaskell backend depends on it.
* Since MiniHaskell is deprecated, I see no point in wasting time on writing a translation from MicroJuvix to MiniHaskell.
lukaszcz added a commit that referenced this issue Jul 19, 2022
* Closes issues #1341, #1338, #1339.
* Depends on PR [#8](anoma/juvix-stdlib#8) in juvix-stdlib.
* Translation/MonoJuvixToMiniC removed.
* MonoJuvix itself not removed because the MiniHaskell backend depends on it.
* Since MiniHaskell is deprecated, I see no point in wasting time on writing a translation from MicroJuvix to MiniHaskell.
lukaszcz added a commit that referenced this issue Jul 19, 2022
* Closes issues #1341, #1338, #1339.
* Depends on PR [#8](anoma/juvix-stdlib#8) in juvix-stdlib.
* Translation/MonoJuvixToMiniC removed.
* MonoJuvix itself not removed because the MiniHaskell backend depends on it.
* Since MiniHaskell is deprecated, I see no point in wasting time on writing a translation from MicroJuvix to MiniHaskell.
lukaszcz added a commit that referenced this issue Jul 19, 2022
* Closes issues #1341, #1338, #1339.
* Depends on PR [#8](anoma/juvix-stdlib#8) in juvix-stdlib.
* Translation/MonoJuvixToMiniC removed.
* MonoJuvix itself not removed because the MiniHaskell backend depends on it.
* Since MiniHaskell is deprecated, I see no point in wasting time on writing a translation from MicroJuvix to MiniHaskell.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants