-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd21135
commit 04f0653
Showing
1 changed file
with
120 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
types: | ||
if-then-else | ||
ternary ?: | ||
while | ||
do-while | ||
for | ||
foreach (compounds) | ||
switch-case-default (and continue/break?) | ||
continue | ||
break | ||
|
||
if-then: | ||
cond-branch | ||
if false jump end | ||
{ | ||
then-branch | ||
} | ||
end | ||
|
||
if-then-else: (also ternary) | ||
cond-branch | ||
if false jump else | ||
{ | ||
then-branch | ||
} | ||
jump end | ||
{ | ||
else-branch | ||
} | ||
end | ||
|
||
while: | ||
begin | ||
cond-branch | ||
if false jump end | ||
{ | ||
then-branch | ||
} | ||
jump begin | ||
end | ||
|
||
do-while: | ||
begin | ||
{ | ||
then-branch | ||
} | ||
cond-branch | ||
if true jump begin | ||
end | ||
|
||
for: | ||
{ | ||
pre-branch | ||
begin | ||
cond-branch | ||
if false jump end | ||
{ | ||
then-branch | ||
} | ||
post-branch | ||
jump begin | ||
end | ||
} | ||
|
||
foreach: | ||
...needs more planning | ||
|
||
switch-case-default: | ||
...needs more planning | ||
|
||
continue: | ||
jump begin | ||
unwind scopes | ||
|
||
break: | ||
jump end | ||
unwind scopes | ||
|
||
--- | ||
|
||
Notes: | ||
The additional scope in 'for' is to safely encapsulate pre-branch, as variables can be declared here. | ||
do-while's 'end' is only there for the break/continue keywords. | ||
break and continue will also unwind scopes, up to the innermost control-flow level. | ||
|
||
break/continue within nested scopes: | ||
Because control flows can be nested, a stack of scope depths may be needed for break/continue... | ||
However, this would get more complicated with closures. | ||
To fix this, scopes may need to remember their own depth, and the depth of the innermost control-flow level. | ||
If a scope's depth is 10 and the inner control-flow-level is 7, then calling break/continue will jump AND unwind to the inner control-flow level. | ||
|
||
--- | ||
|
||
JUMP word: | ||
opcode | ||
type (absolute, relative) | ||
conditional (always, if_true, if_false) | ||
- | ||
|
||
value | ||
|
||
absolute: | ||
"value" is relative to the code sections starting position | ||
|
||
relative: | ||
"value" is relative to the program counter, after this opcode has been read from the bytecode | ||
|
||
always: | ||
Always jump | ||
|
||
if_true: | ||
pop the stack top | ||
if the popped value is true, then jump | ||
else ignore | ||
|
||
if_false: | ||
pop the stack top | ||
if the popped value is true, then ignore | ||
else jump | ||
|