Skip to content

Commit d3c6ed2

Browse files
committed
basic example
1 parent 1c3147d commit d3c6ed2

6 files changed

+74
-29
lines changed

ARTTypeAndOperationTable.xlsx

18.2 KB
Binary file not shown.

ValueUserPlugin.class

699 Bytes
Binary file not shown.

ValueUserPlugin.java

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public class ValueUserPlugin implements ValueUserPluginInterface {
1212
static int SCREEN_WIDTH = 800;
1313
static int SCREEN_HEIGHT = 600;
1414

15-
Group root;
15+
static Group root;
16+
static Stage stage;
1617

1718
@Override
1819
public String name() {
@@ -21,25 +22,37 @@ public String name() {
2122

2223
@Override
2324
public Value user(Value... args) throws ARTException {
24-
root = new Group();
25-
root.getChildren().add(new Label(args[0].toString() + "\n" + args[1].toString() + "\n" + args[2].toString()));
26-
27-
System.out.println("I'm from Hong Kong!");
28-
SpawnBox();
29-
30-
Stage stage = new Stage();
31-
stage.setScene(new Scene(root, SCREEN_WIDTH, SCREEN_HEIGHT));
32-
stage.setTitle("HolloRay");
33-
stage.show();
34-
35-
return new __string("Hello, World!");
25+
final Value arg1 = args[0];
26+
final Value arg2 = args[1];
27+
final Value arg3 = args[2];
28+
29+
switch (args[0].value().toString()) {
30+
case "init":
31+
System.out.println("Initialising JavaFX stage");
32+
stage = new Stage();
33+
root = new Group();
34+
return new __done();
35+
case "paint":
36+
System.out.println("Painting JavaFX stage");
37+
stage.setScene(new Scene(root, SCREEN_WIDTH, SCREEN_HEIGHT));
38+
stage.setTitle("HolloRay");
39+
stage.show();
40+
return new __done();
41+
case "cube":
42+
SpawnBox((double) arg2.value());
43+
return new __done();
44+
default:
45+
System.out.println("Unknown internal command: " + args[0].value());
46+
return new __string("OH NO!");
47+
}
3648
}
3749

38-
private void SpawnBox() {
50+
private void SpawnBox(double side_length) {
51+
System.out.println("Spawning a box with side length " + side_length);
3952
Box box = new Box();
40-
box.setDepth(50);
41-
box.setHeight(50);
42-
box.setWidth(50);
53+
box.setDepth(side_length);
54+
box.setHeight(side_length);
55+
box.setWidth(side_length);
4356
root.getChildren().add(box);
4457
}
4558
}

artSpecification.art

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
-ifFalse --- if(False, _C1, _C2), _sig -> _C2, _sig
2020
-ifResolve _E, _sig -> _EP, _sigP --- if(_E, _C1, _C2), _sig -> if(_EP, _C1, _C2), _sigP
2121
(* constructor cube *)
22-
-cube _d |> _ --- cube(_d), _sig -> __cube(_d), _sig
22+
-cube _d |> _ --- cube(_d), _sig -> __user("cube", _d, __), _sig
2323
(* constructor while *)
2424
-while --- while(_E, _C), _sig -> if(_E, seq(_C, while(_E, _C)), __done), _sig
25-
(* constructor cylinder *)
26-
-cylinder _r |> _ _h |> _ --- cylinder(_r, _h), _sig -> __cylinder(_r, _h), _sig
2725
(* constructor assign *)
2826
-assign _n |> _ --- assign(_X, _n), _sig -> __done, __put(_sig, _X, _n)
2927
-assignResolve _E, _sig -> _I, _sigP --- assign(_X, _E), _sig -> assign(_X, _I), _sigP
28+
(* constructor cylinder *)
29+
-cylinder _r |> _ _h |> _ --- cylinder(_r, _h), _sig -> __cylinder(_r, _h), _sig
3030
(* constructor sphere *)
3131
-sphere _r |> _ --- sphere(_r), _sig -> __sphere(_r), _sig
3232
(* constructor gt *)
@@ -39,6 +39,10 @@
3939
-intersection _E1, _sig -> _I1, _sigP --- intersection(_E1, _E2), _sig -> __intersection(_I1, _E2), _sigP
4040
(* constructor difference *)
4141
-difference _E1, _sig -> _I1, _sigP --- difference(_E1, _E2), _sig -> __difference(_I1, _E2), _sigP
42+
(* constructor init *)
43+
-initialise --- init, _sig -> __user("init", __, __), _sig
44+
(* constructor paint *)
45+
-paint --- paint, _sig -> __user("paint", __, __), _sig
4246

4347
(*-----------------------*)
4448

artSpecification.tex

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494

9595
\begin{equation}
9696
\tag*{[\artConstructor{\sf cube}]}
97-
\begin{split}\frac{ \artVariable{d}\triangleright \artSpecial{real64}(\_) }{\langle\, \artConstructor{\sf cube}(\artVariable{d}), \artVariable{$\sigma$}\,\rangle \rightarrow \langle\, \artSpecial{cube}(\artVariable{d}), \artVariable{$\sigma$}\,\rangle }
97+
\begin{split}\frac{ \artVariable{d}\triangleright \artSpecial{real64}(\_) }{\langle\, \artConstructor{\sf cube}(\artVariable{d}), \artVariable{$\sigma$}\,\rangle \rightarrow \langle\, \artSpecial{user}(\artSpecial{string}(\artCaseInsensitiveLiteral{cube})\ \artVariable{d}\ \_\_), \artVariable{$\sigma$}\,\rangle }
9898
\end{split}
9999
\end{equation}
100100

@@ -104,12 +104,6 @@
104104
\end{split}
105105
\end{equation}
106106

107-
\begin{equation}
108-
\tag*{[\artConstructor{\sf cylinder}]}
109-
\begin{split}\frac{ \artVariable{r}\triangleright \artSpecial{real64}(\_) \quad \artVariable{h}\triangleright \artSpecial{real64}(\_) }{\langle\, \artConstructor{\sf cylinder}(\artVariable{r}\ \artVariable{h}), \artVariable{$\sigma$}\,\rangle \rightarrow \langle\, \artSpecial{cylinder}(\artVariable{r}\ \artVariable{h}), \artVariable{$\sigma$}\,\rangle }
110-
\end{split}
111-
\end{equation}
112-
113107
\begin{equation}
114108
\tag*{[\artConstructor{\sf assign}]}
115109
\begin{split}\frac{ \artVariable{n}\triangleright \artSpecial{int32}(\_) }{\langle\, \artConstructor{\sf assign}(\artVariable{X}\ \artVariable{n}), \artVariable{$\sigma$}\,\rangle \rightarrow \langle\, \artSpecial{done}, \artSpecial{put}(\artVariable{$\sigma$}\ \artVariable{X}\ \artVariable{n})\,\rangle }
@@ -122,6 +116,12 @@
122116
\end{split}
123117
\end{equation}
124118

119+
\begin{equation}
120+
\tag*{[\artConstructor{\sf cylinder}]}
121+
\begin{split}\frac{ \artVariable{r}\triangleright \artSpecial{real64}(\_) \quad \artVariable{h}\triangleright \artSpecial{real64}(\_) }{\langle\, \artConstructor{\sf cylinder}(\artVariable{r}\ \artVariable{h}), \artVariable{$\sigma$}\,\rangle \rightarrow \langle\, \artSpecial{cylinder}(\artVariable{r}\ \artVariable{h}), \artVariable{$\sigma$}\,\rangle }
122+
\end{split}
123+
\end{equation}
124+
125125
\begin{equation}
126126
\tag*{[\artConstructor{\sf sphere}]}
127127
\begin{split}\frac{ \artVariable{r}\triangleright \artSpecial{real64}(\_) }{\langle\, \artConstructor{\sf sphere}(\artVariable{r}), \artVariable{$\sigma$}\,\rangle \rightarrow \langle\, \artSpecial{sphere}(\artVariable{r}), \artVariable{$\sigma$}\,\rangle }
@@ -164,5 +164,17 @@
164164
\end{split}
165165
\end{equation}
166166

167+
\begin{equation}
168+
\tag*{[\artConstructor{\sf initialise}]}
169+
\begin{split}\langle\, \artConstructor{\sf init}, \artVariable{$\sigma$}\,\rangle \rightarrow \langle\, \artSpecial{user}(\artSpecial{string}(\artCaseInsensitiveLiteral{init})\ \_\_\ \_\_), \artVariable{$\sigma$}\,\rangle
170+
\end{split}
171+
\end{equation}
172+
173+
\begin{equation}
174+
\tag*{[\artConstructor{\sf paint}]}
175+
\begin{split}\langle\, \artConstructor{\sf paint}, \artVariable{$\sigma$}\,\rangle \rightarrow \langle\, \artSpecial{user}(\artSpecial{string}(\artCaseInsensitiveLiteral{paint})\ \_\_\ \_\_), \artVariable{$\sigma$}\,\rangle
176+
\end{split}
177+
\end{equation}
178+
167179
\hrule
168180
\end{document}

eSOS_HolloRay.art

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ backend(_P1, _P2, _P3),_sig -> __user(_P1, _P2, _P3)
9191
-cube
9292
_d |> __real64(_)
9393
---
94-
cube(_d),_sig -> __cube(_d),_sig
94+
cube(_d),_sig -> __user("cube", _d, __),_sig
9595

9696
-cylinder
9797
_r |> __real64(_) _h |> __real64(_)
@@ -118,5 +118,21 @@ _E1, _sig -> _I1, _sigP
118118
---
119119
difference(_E1, _E2),_sig -> __difference(_I1, _E2), _sigP
120120

121-
!try backend(1,2,3), __map
121+
-initialise
122+
---
123+
init,_sig -> __user("init", __, __),_sig
124+
125+
-paint
126+
---
127+
paint,_sig -> __user("paint", __, __),_sig
128+
129+
130+
!try
131+
seq(init(),
132+
seq(cube(100.0),
133+
seq(cube(50.0),
134+
seq(paint(),
135+
136+
, __done
137+
)))), __map
122138

0 commit comments

Comments
 (0)