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

Haz3l checkbox and slider livelits #955

Closed
wants to merge 56 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
31e836b
Start messing around with LiveLit definitions
7h3kk1d Jan 7, 2023
f288323
Fix Term.show_cls
7h3kk1d Jan 7, 2023
df0e31b
Temp commit debugging
7h3kk1d Jan 8, 2023
7dc7ae6
mock livelit application
7h3kk1d Jan 13, 2023
142d2bd
Started working on livelit application rather than definition
7h3kk1d Jan 20, 2023
624aad0
Add input boxes for int and str
7h3kk1d Jan 21, 2023
93e0023
Make livelit atomic form
7h3kk1d Jan 24, 2023
92509bd
Merge remote-tracking branch 'origin/dev' into haz3l-livelits
7h3kk1d Jan 27, 2023
aa6f72c
Switch livelits to use % over $
7h3kk1d Jan 27, 2023
82d67fe
Add a fixed padding to slider livelit
7h3kk1d Jan 27, 2023
5848c9f
Switch livelit to caret
7h3kk1d Jan 31, 2023
0018e1f
Fix padding code
7h3kk1d Jan 31, 2023
e6dbcef
Fix floating multiplication
7h3kk1d Jan 31, 2023
9f4a0d5
Add style for text input
7h3kk1d Jan 31, 2023
fc21785
Hack for persisting slider state
7h3kk1d Feb 3, 2023
7881101
Stop memoizing function with function parameter
7h3kk1d Feb 3, 2023
04eb7fb
Wire slider state into elaborator
7h3kk1d Feb 3, 2023
4da8970
Add livelit_state map
7h3kk1d Feb 4, 2023
24f9598
Remove unused code
7h3kk1d Feb 4, 2023
6961d6f
Switch livelit_state to DHExp
7h3kk1d Feb 5, 2023
acfdc88
Switch the livelit names and shrink the checkbox
7h3kk1d Feb 5, 2023
19a66cf
Wired in checkbox state
7h3kk1d Feb 5, 2023
26ced8a
Fix livelit LangDocMessages
7h3kk1d Feb 6, 2023
d3a4af5
Stop propagating mouse down from livelit
7h3kk1d Feb 10, 2023
a93abbc
Add livelit type and start integrating font metrics
7h3kk1d Feb 10, 2023
a35bebd
Integrate font metrics
7h3kk1d Feb 10, 2023
9061fcf
Breakout LivelitView
7h3kk1d Feb 10, 2023
efef346
Simplify LivelitView
7h3kk1d Feb 10, 2023
0f090db
Remove superfulous code
7h3kk1d Feb 10, 2023
cd9b7f0
Code cleanup
7h3kk1d Feb 10, 2023
0a77b4a
More code cleanup
7h3kk1d Feb 10, 2023
417dae4
Merge remote-tracking branch 'origin/dev' into haz3l-livelits
7h3kk1d Feb 10, 2023
608f070
Merge remote-tracking branch 'origin/dev' into haz3l-livelits
7h3kk1d Mar 17, 2023
0495cc5
Add unknown livelits to bad_lit
7h3kk1d Mar 17, 2023
26709a8
Extract Livelit.elaborate_livelit
7h3kk1d Mar 17, 2023
f4369b1
Extract Livelit.state type
7h3kk1d Mar 17, 2023
1e73d1f
Extract Livelit.empty_state
7h3kk1d Mar 17, 2023
0abde16
Simplify updating livelit_state for Editors
7h3kk1d Mar 19, 2023
106ef23
Use Livelit.empty_state
7h3kk1d Mar 19, 2023
8445767
Break livelit_padding into a function
7h3kk1d Mar 19, 2023
6b96a5a
Rename livelit_state to livelits
7h3kk1d Mar 19, 2023
d52669e
Move livelit rendering outside of of_delim'
7h3kk1d Mar 21, 2023
003a682
Added left/right margin for livelits
7h3kk1d Mar 21, 2023
0037c1a
Use curryied function application
7h3kk1d Mar 30, 2023
58eb82b
Switch checkbox to use on_input
7h3kk1d Mar 30, 2023
520bde1
Fix checkbox margins
7h3kk1d Mar 30, 2023
f2c6b1e
Try alternate livelit insertion mechanism
7h3kk1d Mar 30, 2023
9c2343b
Hacky implementation of not rendering livelit name when rendering liv…
7h3kk1d Mar 30, 2023
b2e5054
Fix left/right navigation
7h3kk1d Apr 2, 2023
9e33a29
Switch livelit insertion to use tab
7h3kk1d Apr 21, 2023
ee832bd
Add fslider for floats
7h3kk1d Apr 21, 2023
07ba4a6
Code cleanup
7h3kk1d Apr 24, 2023
e0a0dfc
Remove unused code
7h3kk1d Apr 24, 2023
9ba000e
Livelits begin with a caret
7h3kk1d Apr 26, 2023
05aa50e
Merge remote-tracking branch 'origin/dev' into haz3l-livelits
7h3kk1d May 8, 2023
958f3be
Fix compatibility OCaml 5
7h3kk1d May 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add livelit_state map
  • Loading branch information
7h3kk1d committed Feb 4, 2023

Verified

This commit was signed with the committer’s verified signature.
vkubiv Volodymyr Kubiv
commit 4da8970ecb84f7e6d9b3ff1106381cbb6a723b0f
14 changes: 10 additions & 4 deletions src/haz3lcore/dynamics/elaborator.re
Original file line number Diff line number Diff line change
@@ -136,7 +136,7 @@ let wrap = (u, mode, self, d: DHExp.t): option(DHExp.t) =>
};

let rec dhexp_of_uexp =
(m: Statics.map, uexp: Term.UExp.t, livelit_state: int)
(m: Statics.map, uexp: Term.UExp.t, livelit_state: Id.Map.t(int))
: option(DHExp.t) => {
/* NOTE: Left out delta for now */
switch (Id.Map.find_opt(Term.UExp.rep_id(uexp), m)) {
@@ -281,11 +281,17 @@ let rec dhexp_of_uexp =
| _ => ConsistentCase(d)
};
| LivelitAp({livelit_name, width: _}) =>
let id = Term.UExp.rep_id(uexp);
let livelit_value =
switch (Id.Map.find_opt(id, livelit_state)) {
| Some(v) => v
| None => 50
};
switch (livelit_name) {
| "^int" => Some(IntLit(livelit_state))
| "^int" => Some(IntLit(livelit_value))
| "^str" => Some(StringLit("livelit string"))
| _ => None
}
};
| Match(scrut, rules) =>
let* d_scrut = dhexp_of_uexp(m, scrut, livelit_state);
let+ d_rules =
@@ -386,7 +392,7 @@ let uexp_elab_wrap_builtins = (d: DHExp.t): DHExp.t =>
);

let uexp_elab =
(m: Statics.map, uexp: Term.UExp.t, livelit_state: int)
(m: Statics.map, uexp: Term.UExp.t, livelit_state: Id.Map.t(int))
: ElaborationResult.t =>
switch (dhexp_of_uexp(m, uexp, livelit_state)) {
| None => DoesNotElaborate
2 changes: 1 addition & 1 deletion src/haz3lcore/prog/Interface.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
exception DoesNotElaborate;
let elaborate = (~livelit_state=0, map, term): DHExp.t =>
let elaborate = (~livelit_state=Id.Map.empty, map, term): DHExp.t =>
switch (Elaborator.uexp_elab(map, term, livelit_state)) {
| DoesNotElaborate =>
print_endline("Interface.elaborate EXCEPTION");
4 changes: 2 additions & 2 deletions src/haz3lcore/zipper/Editor.re
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ module Meta = {
measured: Measured.t,
term_ranges: TermRanges.t,
col_target: int,
livelit_state: int // TODO Replace with map of id to state or somehting
livelit_state: Id.Map.t(int) // TODO Replace int with actual types for livelit states
};

let init = (z: Zipper.t) => {
@@ -17,7 +17,7 @@ module Meta = {
measured: Measured.of_segment(unselected),
term_ranges: TermRanges.mk(unselected),
col_target: 0,
livelit_state: 50,
livelit_state: Id.Map.empty,
7h3kk1d marked this conversation as resolved.
Show resolved Hide resolved
};
};

9 changes: 7 additions & 2 deletions src/haz3lweb/Update.re
Original file line number Diff line number Diff line change
@@ -416,7 +416,7 @@ let apply =
| DebugAction(a) =>
DebugAction.perform(a);
Ok(model);
| LivelitStateChange(livelit_state) =>
| LivelitStateChange(livelit_id, livelit_state) =>
let (id, ed) = Editors.get_editor_and_id(model.editors);
let editor =
Editors.put_editor_and_id(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel these highly nested expansions are hard to read... maybe break this out into a couple appropriately-chosen lets. alternatively worth checking if someone already made getters/setters for these subcomponents, probably not worth adding if there arent any though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified it a bit in 0abde16. I was looking for a better way to do nested record updates and didn't find anything. Not sure if there's something like lenses or if I should just add more update functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed by moving d52669e outside of the span. I haven't performance-tested anything in the PR though so I'm not sure how expensive the livelit rendering is.

@@ -427,7 +427,12 @@ let apply =
...ed.state,
meta: {
...ed.state.meta,
livelit_state,
livelit_state:
Id.Map.add(
livelit_id,
livelit_state,
ed.state.meta.livelit_state,
),
},
},
},
7h3kk1d marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion src/haz3lweb/UpdateAction.re
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ type t =
| UpdateResult(ModelResults.Key.t, ModelResult.current)
| UpdateLangDocMessages(LangDocMessages.update)
| DebugAction(DebugAction.t)
| LivelitStateChange(int);
| LivelitStateChange(Id.t, int);

module Failure = {
[@deriving (show({with_path: false}), sexp, yojson)]
2 changes: 1 addition & 1 deletion src/haz3lweb/view/BackpackView.re
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ let backpack_sel_view =
~no_sorts=true,
content,
~inject=_ => Ui_effect.Ignore,
~livelit_state=0,
~livelit_state=Id.Map.empty,
7h3kk1d marked this conversation as resolved.
Show resolved Hide resolved
) // TODO Livelit state
@ [text(Unicode.zwsp)],
);
39 changes: 30 additions & 9 deletions src/haz3lweb/view/Code.re
Original file line number Diff line number Diff line change
@@ -5,7 +5,18 @@ open Util;
open Util.Web;

let of_delim' =
((sort, is_consistent, is_complete, label, i, inject, livelit_state)) => {
(
(
sort,
is_consistent,
is_complete,
label,
i,
inject,
livelit_state: Id.Map.t(int),
tile_id: Id.t,
),
) => {
let cls =
switch (label) {
| [_] when !is_consistent => "mono-inconsistent"
@@ -27,7 +38,7 @@ let of_delim' =
font_height,
);
let callback = (_evt, str): Virtual_dom.Vdom.Effect.t(unit) => {
inject(UpdateAction.LivelitStateChange(int_of_string(str)));
inject(UpdateAction.LivelitStateChange(tile_id, int_of_string(str)));
};

let attr: Attr.t = Attr.on_input(callback);
@@ -39,7 +50,15 @@ let of_delim' =
Attr.many([
Attr.create("type", "range"),
Attr.create("style", style),
Attr.create("value", string_of_int(livelit_state)),
Attr.create(
"value",
string_of_int(
switch (Id.Map.find_opt(tile_id, livelit_state)) {
| Some(v) => v
| None => 50
},
),
),
attr,
]),
(),
@@ -73,7 +92,7 @@ let of_delim =
t: Piece.tile,
i: int,
~inject,
~livelit_state,
~livelit_state: Id.Map.t(int),
)
: list(Node.t) =>
of_delim'((
@@ -84,6 +103,7 @@ let of_delim =
i,
inject,
livelit_state,
Tile.id(t),
));

let of_grout = [Node.text(Unicode.nbsp)];
@@ -119,7 +139,7 @@ module Text = (M: {
~sort=Sort.root,
seg: Segment.t,
~inject,
~livelit_state,
~livelit_state: Id.Map.t(int),
)
: list(Node.t) => {
//note: no_sorts flag is used for backback
@@ -152,7 +172,7 @@ module Text = (M: {
and of_tile =
(expected_sort: Sort.t, t: Tile.t, ~inject, ~livelit_state)
: list(Node.t) => {
// print_endline("Tile:" ++ Tile.show(t));
print_endline("Tile:" ++ Tile.show(t));
let children_and_sorts =
List.mapi(
(i, (l, child, r)) =>
@@ -161,7 +181,8 @@ module Text = (M: {
Aba.aba_triples(Aba.mk(t.shards, t.children)),
);
let is_consistent = Sort.consistent(t.mold.out, expected_sort);
Aba.mk(t.shards, children_and_sorts)
let foo = Aba.mk(t.shards, children_and_sorts);
foo
|> Aba.join(
of_delim(t.mold.out, is_consistent, t, ~inject, ~livelit_state),
((seg, sort)) =>
@@ -201,7 +222,7 @@ let simple_view =
[
span_c(
"code-text",
Text.of_segment(unselected, ~inject, ~livelit_state=0),
Text.of_segment(unselected, ~inject, ~livelit_state=Id.Map.empty),
),
] // TODO livelit_state
);
@@ -215,7 +236,7 @@ let view =
~measured,
~settings: Model.settings,
~inject,
~livelit_state,
~livelit_state: Id.Map.t(int),
)
: Node.t => {
module Text =