You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: compiler/notes.md
+175-21
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,11 @@
3
3
## Loops
4
4
5
5
```rust
6
+
// Infinite loop
7
+
loop {
8
+
solveTheHaltingProblem();
9
+
}
10
+
6
11
// Loop over a container
7
12
looplist {
8
13
operationOnItem(it);
@@ -17,29 +22,8 @@ loop 0..10 {
17
22
loopi:0..10 {
18
23
i==it;
19
24
}
20
-
21
-
// Custom loop condition
22
-
muti=0;
23
-
loop (i<10) {
24
-
i+=1;
25
-
}
26
-
27
-
// Loop with initializer and condition
28
-
loop (leti=0; i<10) {
29
-
i+=1; // 0, 1, 2, 3, ...
30
-
}
31
-
32
-
// Loop with initializer, condition, and post-loop expression
33
-
loop (leti=0; i<10; i++) {
34
-
i; // 0, 1, 2, 3, ...
35
-
}
36
25
```
37
26
38
-
### Problem
39
-
40
-
Harder to talk about in real life. It's easier to say "you should use a for loop" than it is to say "you should use a
41
-
loop with an initializer, condition, and post-loop expression."
42
-
43
27
## Imports
44
28
45
29
Imports will all have a source and a series of selectors.
@@ -88,3 +72,173 @@ For referencing modules which are nearby in the file system.
88
72
use./nested/library/{ someFunction };
89
73
use../../other_library/{ someFunction };
90
74
```
75
+
76
+
## Environments
77
+
78
+
The main idea of this language is to be able to write a single codebase and have it work as both a frontend and a server. What are the implications of this?
79
+
80
+
Any given chunk of code can be run in 1 of 3 states:
81
+
82
+
1. Frontend
83
+
2. Backend
84
+
3. Isomorphic/Both
85
+
86
+
What happens when trying to interact with code from one environment in another? The left side indicates the execution environment and the top indicates which environment the function was written for.
| Frontend | Normal function call | Remote call | Normal function call |
91
+
| Backend | Remote call | Normal function call | Normal function call |
92
+
93
+
When code is not given a specific environment, it will run in both.
94
+
95
+
How does calling across environments change the compiled code? Functions become colored. For now, everything that does a cross environment call will become asynchronous and do automatic awaiting.
96
+
97
+
```rust
98
+
back {
99
+
fnlogBackend() {
100
+
log("I run on the backend");
101
+
}
102
+
103
+
logFrontend();
104
+
logBackend();
105
+
}
106
+
107
+
front {
108
+
fnlogFrontend() {
109
+
log("I run on the frontend");
110
+
}
111
+
112
+
logBackend();
113
+
logFrontend();
114
+
}
115
+
116
+
logFrontend();
117
+
logBackend();
118
+
```
119
+
120
+
should compile to something functionally equivalent to this:
Next case: defining a function which calls in to another environment without defining one
171
+
172
+
```rust
173
+
fnlog() { // Becomes backend by association
174
+
logBackend();
175
+
}
176
+
log();
177
+
```
178
+
179
+
compiles to:
180
+
181
+
```js
182
+
/**
183
+
* frontend.js
184
+
*/
185
+
asyncfunctionlog() {
186
+
awaitlogBackend()
187
+
}
188
+
189
+
functionlogBackend() {
190
+
returnfetch('/logBackend')
191
+
}
192
+
193
+
awaitlog()
194
+
195
+
/**
196
+
* backend.js
197
+
*/
198
+
functionlog() {
199
+
logBackend()
200
+
}
201
+
202
+
functionlogBackend() {
203
+
console.log('I run on the backend')
204
+
}
205
+
206
+
log()
207
+
```
208
+
209
+
This sort of coloring will climb all the way back up to the root. As soon as you have one asynchronous/cross-environment call, the whole call stack needs to be asynchronous.
0 commit comments