Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2895d7c
file to try out Encore, and preliminary tests for for-comprehension
ElieOaks Apr 3, 2019
957edcc
Changes to parser to handle the new for-comprehension, toplevel to ad…
ElieOaks Apr 24, 2019
ce50299
added funcion to array, further dev. of optimizer, mutable boxes incl…
ElieOaks May 8, 2019
97e2549
removed scrap files beofre review PR
ElieOaks May 8, 2019
61c15fa
removed translation of for
ElieOaks May 8, 2019
979bcb6
changed the names om mutable boxed file names
ElieOaks May 8, 2019
8b61939
removed the old named files from git
ElieOaks May 8, 2019
067051d
added requirement for functor
ElieOaks May 8, 2019
4cb0e56
removed old commented out for-parsing
ElieOaks May 8, 2019
17a835d
finally got to the boxing problem
ElieOaks May 16, 2019
8a365c9
added another file: TypedDesugaring, which is another pass of the com…
ElieOaks May 20, 2019
c5204b8
lots of stuff
ElieOaks Jun 3, 2019
0c100a5
for-comprehension works
ElieOaks Jun 16, 2019
e2b1f0b
break works
ElieOaks Jun 22, 2019
af9141b
writing test cases
ElieOaks Jun 26, 2019
17f1b6b
begnning the clean up of code
ElieOaks Jun 26, 2019
499d158
cleaned up code and worked off of Kiko's comments
ElieOaks Jun 28, 2019
ddce7ab
removed stray file
ElieOaks Jun 28, 2019
8a3c951
removed stray file
ElieOaks Jun 28, 2019
5dbc4a9
fixed a space
ElieOaks Jun 28, 2019
ba10b39
fixed a space
ElieOaks Jun 28, 2019
308149e
fixed a space
ElieOaks Jun 28, 2019
740946b
fixed a space
ElieOaks Jun 28, 2019
2c13220
fixed a space
ElieOaks Jun 28, 2019
9edd6c4
fixed a space
ElieOaks Jun 28, 2019
b475d04
smaller changes
ElieOaks Jun 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions critik
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The first slide after introduction: Have a picture?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong file? This file is not needed here.


One of the first slidess: Align "::"

gotward delegation: picture with printers again? 19

26: Make the chosen example bigger on like the next slide? Hard to see. Especially when using cursive:make bigger or bold or something
27: --------""---------
28: Make the examples bigger.
1 change: 1 addition & 0 deletions encore.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ executable encorec
, Makefile
, ModuleExpander
, Optimizer.Optimizer
, Optimizer.TypedDesugarer
, Parser.Parser
, SystemUtils
, Typechecker.Capturechecker
Expand Down
15 changes: 15 additions & 0 deletions forComp/output.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
typeCheckSource sourceType fors@(ForSource{fsTy, collection}) = do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is Haskell but uses the Encore file extension.
I am not sure what this is :)

collectionTyped <- doTypecheck collection
let collectionType = AST.getType collectionTyped
formalType <- findFormalRefType collectionType
let mtyType = return $ getInnerType collectionType
unless (formalType == sourceType) $
pushError collection $ TypeMismatchError formalType sourceType
return fors{fsTy = mtyType
,collection = setType collectionType collectionTyped}

firstSourceType ForSource{fsTy, collection} = do
collectionTyped <- doTypecheck collection
let collectionType = AST.getType collectionTyped
formal <- findFormalRefType collectionType
return formal
10 changes: 10 additions & 0 deletions forComp/rangeFor.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
active class Main
def main() : unit
var range = new Range(1, 10, 2)
range.foreach(print_index)
end
end

fun print_index(i: int) : unit
print("{ }", i)
end
45 changes: 45 additions & 0 deletions forComp/tests/preliminaryFailSyntaxTests.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--These are preliminary for-comprehension tests
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encore does not yet return multiple errors.
Could you instead move each of these tests to their own files (and create their own .fail files as well)?

-- The following assumptions have been made:
-- 1. It is possible to loop over empty structures
-- which either does nothing,
-- or returns a new struct that is empty.
-- 2. It is possible to loop over different kinds of structures
-- If using for as a function call, it will return
-- a similar struct as the first one listed, but perhaps
-- containing elements of different type.
-- 3. Looping over multiple structures is done in a nested may:
-- for x <- [1, 2], y <- [3, 4]
-- would loop over all the y elements for every x element
-- 4. Mutable variables can be changed inside a for-loop
-- 5. To use for over a structure, it must only allow one type of element
-- i.e. be homogenous, thus for example, it cannot iterate over a tuple
-- 6. The following tests assume there is a simple Container LinkedList which
-- has support for map and flatMap.

--None of these examples should compile at all

active class Main

def main() : unit

-- indentation error
for x <- [1, 2, 3] do
end

-- "<- list" missing
for x do
x + 1
end

-- "<-" missing
for x = [1, 2, 3] do
x + 1
end

-- [] is not allowed in Encore
for x <- [] do
x + 1
end

end
end
36 changes: 36 additions & 0 deletions forComp/tryEquals.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
active class Equal
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure on what is this file testing.
Thanks


var num : int

def init() : unit
this.num = 3
end

def isEqual(num : int) : bool
return (this.num == num)
end

end

active class Main

def main(args : [String]) : unit

var n = match (args(1)).to_int() with
case Just(res) =>
res
end
case Nothing =>
0
end
end
var instance = new Equal()
var b = instance!isEqual(n)
print("They are equal? {}\n", get(b))

if ([1, 2, 3].isEqual([1, 2, 3])) then
print("It does not work!")
end

end
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a forComp/tryFor binary. Binaries should not be included in git :)

Binary file added forComp/tryFor
Binary file not shown.
55 changes: 55 additions & 0 deletions forComp/tryFor.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Collections.Mutable.LinkedList

fun accum(mun : int) : int
mun + 1
end

fun useList(list : LinkedList[(int, String)]) : unit
for elem <- list do
print("{}", elem)
end
end

active class Main
def main() : unit

var list = new LinkedList[int]()
list.append(1)
list.append(2)
list.append(3)

var list2 = new LinkedList[String]()
list2.append("katt")
list2.append("katt")
list2.append("katt")

var acc = 0
useList(for elem <- list, el <- list2 do
(elem, el)
end)


{-var list = new LinkedList[int]()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is these lines are not tested, please remove them

list.append(1)
list.append(2)
list.append(3)

var list2 = new LinkedList[int]
list2.append(5)
list2.append(6)

var list3 = for x <- list, y <- list2 do
x + y
end

for x <- list do
print("{}\n", x)
end

for e <- list3 do
print("{}", e)
end-}


end
end
24 changes: 24 additions & 0 deletions forComp/tryInt.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
active class TryInt
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you using this file for anything?


var num : Integer

def init() : unit
this.num = 3
end

def add(num : Integer) : unit
this.num.add(num)
print("New value: {}", this.num)
end

end

active class Main

def main(args : [String]) : unit

var n = 3 : Integer
var instance = new TryInt()
instance!add(n)
end
end
7 changes: 7 additions & 0 deletions forComp/tryLinkedList.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Collections.Mutable.LinkedList

active class Main
def main() : unit
var list = new LinkedList()
end
end
8 changes: 5 additions & 3 deletions modules/standard/Collections/Mutable/ArrayList.enc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import Data.Maybe(cat_maybes)
import Data.Either
import Data.Array
import Collections.Mutable.Collection
-- JOY for-comprehension
import Collections.Mutable.Functor

local class ArrayList[t] : Collection[t](next_empty, int_arr, foreach(), shift_right(), shift_left(), ensure_can_accomodate(), resize())
local class ArrayList[t] : Collection[t](next_empty, int_arr, foreach(), shift_right(), shift_left(), ensure_can_accomodate(), resize()) + Functor[t](map(), flatMap())
var int_arr : [Maybe[t]]
var next_empty : uint

Expand Down Expand Up @@ -151,7 +153,7 @@ local class ArrayList[t] : Collection[t](next_empty, int_arr, foreach(), shift_r
val clone = new ArrayList[t]()

for x <- this.int_arr do
match x with
match x with
case Just(ice) => clone.append(ice)
case Nothing => { break; () }
end
Expand Down Expand Up @@ -304,7 +306,7 @@ local class ArrayList[t] : Collection[t](next_empty, int_arr, foreach(), shift_r

return result
end

def underlying() : [t]
cat_maybes(this.int_arr)
end
Expand Down
7 changes: 7 additions & 0 deletions modules/standard/Collections/Mutable/Functor.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Functor

local trait Functor[t]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A functor, as defined in Haskell, is only your map operation.
We are not using Haskell concepts, though, so feel free to keep it as is.
This is just a FYI :)

require def map[u](f : t -> u) : Functor[u]
require def flatMap[u](f : t -> Functor[u]) : Functor[u]
require def foreach(f : local ((t) -> unit)) : unit
end
8 changes: 4 additions & 4 deletions modules/standard/Collections/Mutable/HashMap.enc
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ local class HashMapIterator[k : Hashable + Eq[k], v]
this.current_index = this.current_index + 1

while this.current_index < this.map.size do
val l = (this.map.internal_map)(this.current_index)
val l = (this.map.internal_map)(this.current_index)
if l.size > 0 then
return l.first
end

this.current_index = this.current_index + 1
end

Expand Down Expand Up @@ -107,7 +107,7 @@ local class HashMap[k : Hashable + Eq[k], v] : Map[k, v](size, internal_map, ite
def init() : unit
this.items = 0
this.size = 32
this.internal_map = Array.new_with_generator(this.size,
this.internal_map = Array.new_with_generator(this.size,
fun (x: int) => new LinkedList[Entry[k,v]]())
end

Expand Down Expand Up @@ -277,7 +277,7 @@ local class HashMap[k : Hashable + Eq[k], v] : Map[k, v](size, internal_map, ite
end
result
end

def populate(pairs : [(k, v)]) : unit
for kv <- pairs do
this.set(kv.0, kv.1)
Expand Down
7 changes: 5 additions & 2 deletions modules/standard/Collections/Mutable/LinkedList.enc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Data.Either
import Data.Maybe
import Collections.Mutable.Collection
-- import Collections.Mutable.Iterable
-- JOY for-comprehension
import Collections.Mutable.Functor

local class LinkedNode[t] : Id
var value : t
Expand All @@ -16,7 +18,7 @@ local class LinkedNode[t] : Id
end
end

local class LinkedList[t] : Collection[t](drop(), first, last, size) + Id
local class LinkedList[t] : Collection[t](drop(), first, last, size) + Id + Functor[t](first, map(), flatMap(), foreach())
var first : Maybe[LinkedNode[t]]
var last : Maybe[LinkedNode[t]]
var size : int
Expand Down Expand Up @@ -358,7 +360,8 @@ local class LinkedList[t] : Collection[t](drop(), first, last, size) + Id
return result
end

def flatMap[u](f : t -> LinkedList[u]) : LinkedList[u]

def flatMap[u](f : t -> Functor[u]) : LinkedList[u]
val result = new LinkedList[u]()

var cursor = this.first
Expand Down
Loading