-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
statics progress, livelit proj can access args
- Loading branch information
Showing
6 changed files
with
126 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,62 @@ | ||
open Util; | ||
open Virtual_dom.Vdom; | ||
|
||
[@deriving (show({with_path: false}), sexp, yojson)] | ||
type t = { | ||
name: string, | ||
model_t: Typ.t, | ||
// init: UExp.term, | ||
expansion_t: Typ.t, | ||
expansion_f: UExp.t => UExp.t, | ||
projector: UExp.t => Node.t, | ||
}; | ||
let slider: t = { | ||
name: "slider", | ||
expansion_t: Typ.temp(Typ.Int), | ||
expansion_f: (_model: UExp.t) => DHExp.fresh(Int(3)), | ||
expansion_f: (model: UExp.t) => | ||
switch (model.term) { | ||
| Int(n) => DHExp.fresh(Int(n)) | ||
| _ => DHExp.fresh(Int(-1)) | ||
}, | ||
model_t: Typ.temp(Typ.Int), | ||
projector: (model: UExp.t) => | ||
Node.div( | ||
~attrs=[Attr.class_("livelit")], | ||
[Node.text("I am a slider and my model is " ++ UExp.show(model))], | ||
), | ||
}; | ||
|
||
let timestamp: t = { | ||
name: "timestamp", | ||
expansion_t: Typ.temp(Typ.Int), | ||
expansion_f: (_model: UExp.t) => | ||
DHExp.fresh(Int(Float.to_int(JsUtil.timestamp()))), | ||
model_t: Typ.temp(Typ.Int), | ||
}; | ||
|
||
let func_test: t = { | ||
name: "func_test", | ||
expansion_t: Typ.temp(Typ.Arrow(Typ.temp(Typ.Int), Typ.temp(Typ.Int))), | ||
expansion_f: (_model: UExp.t) => DHExp.fresh(Int(3)), | ||
model_t: Typ.temp(Typ.Int), | ||
model_t: Typ.temp(Typ.Prod([])), | ||
projector: (_model: UExp.t) => | ||
Node.div( | ||
~attrs=[Attr.class_("livelit")], | ||
[Node.text("Guess what guys -- I am a timestamp livelit!")], | ||
), | ||
}; | ||
|
||
// let checkbox: t = { | ||
// name: "checkbox", | ||
// width: 1, | ||
// default: Bool(false), | ||
// expansion_type: Typ.temp(Typ.Bool), | ||
// }; | ||
|
||
// let fslider: t = { | ||
// name: "fslider", | ||
// width: 10, | ||
// default: Float(0.5), | ||
// expansion_type: Typ.temp(Typ.Float), | ||
// }; | ||
|
||
let livelits: list(t) = [slider, timestamp, func_test]; | ||
|
||
let find_livelit = (livelit_name: string): option(t) => | ||
List.find_opt(l => l.name == livelit_name, livelits); | ||
|
||
let elaborate_livelit = | ||
(livelit_name: string): option((Typ.t, UExp.t => UExp.t)) => { | ||
let r = | ||
switch (find_livelit(livelit_name)) { | ||
| Some(l) => Some((l.expansion_t, l.expansion_f)) | ||
| None => None | ||
}; | ||
r; | ||
let not_found: t = { | ||
name: "not_found", | ||
expansion_t: Typ.temp(Typ.Unknown(Internal)), | ||
expansion_f: (_model: UExp.t) => DHExp.fresh(String("No livelit found")), | ||
model_t: Typ.temp(Typ.Unknown(Internal)), | ||
projector: (_model: UExp.t) => | ||
Node.div( | ||
~attrs=[Attr.class_("livelit")], | ||
[Node.text("No livelit found")], | ||
), | ||
}; | ||
|
||
let get_livelit_type = (livelit_name: string): Typ.t => | ||
switch (find_livelit(livelit_name)) { | ||
| Some(l) => l.expansion_t | ||
| None => Typ.temp(Typ.Unknown(Internal)) | ||
}; | ||
let livelits: list(t) = [slider, timestamp]; | ||
|
||
let project_livelit = (livelit_name: string): string => { | ||
switch (find_livelit(livelit_name)) { | ||
| Some(l) => l.name | ||
| None => "Not found" | ||
let find_livelit = (livelit_name: string): t => | ||
// List.find_opt(l => l.name == livelit_name, livelits) | ||
// |> Option.value(~default=not_found); | ||
switch (List.find_opt(l => l.name == livelit_name, livelits)) { | ||
| Some(l) => l | ||
| None => | ||
print_endline("Livelit " ++ livelit_name ++ " not found"); | ||
not_found; | ||
}; | ||
}; | ||
|
||
// [@deriving (show({with_path: false}), sexp, yojson)] | ||
// type t = | ||
// name: string, | ||
// model_t: Typ.t, | ||
// init: UExp.t, | ||
// default: UExp.term, | ||
// expansion_t: Typ.t, | ||
// // view | ||
// // action_t | ||
// // update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters