-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from mjp41/0-strech-for
Add `while` loops and add linked list example with while loops
- Loading branch information
Showing
10 changed files
with
186 additions
and
24 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
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,25 +1,38 @@ | ||
|
||
# Build a region | ||
a = {} | ||
a["self"] = a | ||
|
||
f = {} | ||
f.a = a | ||
|
||
# Check if with else (This should be true) | ||
if a == f.a: | ||
b = f.a | ||
c = {} | ||
# Check empty lines in blocks: | ||
|
||
drop b | ||
drop c | ||
else: | ||
# Check parsing nested if's | ||
if f.b == None: | ||
e = {} | ||
drop e | ||
unreachable() | ||
|
||
else: | ||
d = {} | ||
drop d | ||
unreachable() | ||
|
||
# Check identifier as the condition | ||
cond = f.a != a | ||
if cond: | ||
unreachable() | ||
|
||
# Check function call as the condition | ||
def check(): | ||
c = False | ||
# Check return condition result | ||
return c == True | ||
if check(): | ||
unreachable() | ||
|
||
drop a | ||
drop f |
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,38 @@ | ||
lst = {} | ||
lst.next = {} | ||
lst.next.next = {} | ||
lst.next.next.next = {} | ||
|
||
obj = lst | ||
while obj != null: | ||
obj = obj.next | ||
|
||
# Check identifiers in the condition | ||
cond = False | ||
while cond == True: | ||
unreachable() | ||
while cond: | ||
unreachable() | ||
|
||
# Check field access in the condition | ||
x = {} | ||
x.bool = False | ||
while x.bool == True: | ||
unreachable() | ||
while x.bool: | ||
unreachable() | ||
|
||
# Check function calls in the condition | ||
def bool(self): | ||
return False | ||
while bool({}) == True: | ||
unreachable() | ||
while bool({}): | ||
unreachable() | ||
|
||
# Check method calls in the condition | ||
x.bool = bool | ||
while x.bool() == True: | ||
unreachable() | ||
while x.bool(): | ||
unreachable() |
File renamed without changes.
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,60 @@ | ||
def new_list(): | ||
def insert(self, item): | ||
node = self.head | ||
while node.next != null: | ||
node = node.next | ||
|
||
node.next = {} | ||
node.next.data = item | ||
node.next.prev = node | ||
|
||
def contains(self, item): | ||
node = self.head | ||
while node.next != null: | ||
if node.data == item: | ||
return True | ||
node = node.next | ||
return False | ||
|
||
def remove(self, item): | ||
node = self.head | ||
while node.next != null: | ||
if node.data == item: | ||
node.prev.next = node.next | ||
if node.next != null: | ||
node.next.prev = node.prev | ||
return True | ||
node = node.next | ||
return False | ||
|
||
list = {} | ||
list.head = {} | ||
list.insert = take insert | ||
list.contains = take contains | ||
list.remove = take remove | ||
return list | ||
|
||
# Dyrona doesn't freeze shared objects automatically (yet) | ||
def freeze_and_hide_proto(value): | ||
proto = value["__proto__"] | ||
freeze(proto) | ||
mermaid_hide(proto) | ||
freeze_and_hide_proto(freeze_and_hide_proto) | ||
freeze_and_hide_proto("string") | ||
drop freeze_and_hide_proto | ||
|
||
list = new_list() | ||
|
||
# Required to not leak memory | ||
region(list) | ||
|
||
value = "x" | ||
|
||
list.insert({}) | ||
list.insert({}) | ||
list.insert(value) | ||
list.insert({}) | ||
list.remove(value) | ||
|
||
drop value | ||
drop list |