ryanc
2019-5-31 12:21:52

Or use prefab structs, which are non-generative and so cross phases and namespaces freely. They have corresponding limitations, of course, but whether that matters depends on your situation.


xapwing
2019-5-31 15:14:05

@xapwing has joined the channel


lexi.lambda
2019-5-31 19:51:12

@mflatt Is it currently possible to configure the linklet flattener in such a way that it treats an arbitrary set of bindings as “primitive”, instead of what host Racket considers primitive? For example, if I wanted to use the flattener to compile some Racket code to JS, and I wrote a Racket module that implemented some JS primitive operations in Racket, could I use the flattener in a mode where it would leave references to phase 0 bindings in that module alone so that I could write a linklet-to-JS compiler that handled those operations specially?


samth
2019-5-31 20:38:16

@lexi.lambda one relatively straightforward way to do that is to access all those bindings via a primitive-table and then use ++knot js-primitive - to treat them as primitive


samth
2019-5-31 20:38:32

where js-primitive is the name of the primitive table you create


samth
2019-5-31 20:38:54

see uses of ++knot in the expander/Makefile for some inspiration


notjack
2019-5-31 22:59:43

@samth what’s a primitive-table?


lexi.lambda
2019-5-31 23:15:36

@samth Thanks, that makes sense… I’d been looking at some of the primitive table stuff, but I didn’t totally understand how it worked. I think what you said is enough to point me in the right direction, though. It would be nice if I could also make referring to %#kernel bindings an error, but I didn’t see an easy way to do that. I guess I could ++disallow all of them, though I’m not sure if that would work.


samth
2019-6-1 00:05:55

@notjack it’s part of the low level bootstrapping process


samth
2019-6-1 00:06:15

Basically just a named hash table


lexi.lambda
2019-6-1 02:45:03

@samth Looking at things again, it looks like ++knot only works for #% modules that are “wired in”. But I guess I could write my own wrapper around extract that calls declare-hash-based-module! directly, given my custom primitive table?


lexi.lambda
2019-6-1 02:48:15

I’m not sure if that’s really quite right, though… I only really want to redirect phase 0 uses in the expanded program, since any phase 1 uses ought to use the Racket implementation. And it would be nice if programs could still import my module using its usual module path instead of having to indirect through some magical #%js-primitive module.


lexi.lambda
2019-6-1 02:49:34

~Though I suppose hash-based modules don’t have to be cross-phase persistent, so maybe the phasing issue isn’t actually a problem.~ Scratch that, I think they do have to be cross-phase persistent (which makes sense, since they’re just hash tables full of values). But I think it might be possible to adjust extract so it can do that knot-tying without needing to be a #% module.