Skip to content

Commit 01454e6

Browse files
author
robertDurst
committed
some more fixes as I work on mergesort
1 parent ee08dba commit 01454e6

File tree

5 files changed

+67
-10
lines changed

5 files changed

+67
-10
lines changed

examples/intListHandler.fish

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ Uat {
44
}
55

66
Ufn{
7-
(fun printFoo_(int i)(void){
7+
(fun display_(int i)(void){
88
Tree(
99
(| i != own.size | {
1010
printInt(getAtIndexInt(own.list, i))
1111
++i
12-
own...printFoo_(i)
12+
own...display_(i)
1313
})
1414
)
1515
})
1616

17-
(fun printFoo(void)(void){
17+
(fun display(void)(void){
1818
printStr("List Contents:")
19-
own...printFoo_(0)
19+
own...display_(0)
2020
})
2121

2222
# rather inefficient because we malloc every time
@@ -26,6 +26,11 @@ Ufn{
2626
++own.size
2727
})
2828

29+
(fun peek_front(void)(int){
30+
return getAtIndexInt(own.list, 0)
31+
})
32+
33+
2934
(fun removeByIndex(int i)(void){
3035
Tree (
3136
( | own.size == 0 | { printStr("Sorry, list is empty!") })

examples/mergesort.fish

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import intListHandler : "../examples/intListHandler.fish"
2+
3+
(fun merge(intListHandler a, intListHandler b, intListHandler c) (intListHandler) {
4+
Tree (
5+
( | a.size == 0 | {
6+
c.list = appendListInt(c.list, b.list, c.size, b.size)
7+
c.size = b.size + c.size
8+
return c
9+
})
10+
11+
( | b.size == 0 | {
12+
c.list = appendListInt(c.list, a.list, c.size, a.size)
13+
c.size = a.size + c.size
14+
return c
15+
})
16+
17+
( | a...peek_front(void) < b...peek_front(void) | {
18+
dec int i = a...peek_front(void)
19+
c...push(i)
20+
a...removeByIndex(0)
21+
})
22+
23+
( | a...peek_front(void) >= b...peek_front(void) | {
24+
dec int i = b...peek_front(void)
25+
c...push(i)
26+
b...removeByIndex(0)
27+
})
28+
)
29+
30+
return merge(a,b,c)
31+
})
32+
33+
start {
34+
dec intListHandler a = new intListHandler { list: [1, 3, 5], size: 3}
35+
dec intListHandler b = new intListHandler { list: [2, 4, 7], size: 3}
36+
dec intListHandler c = new intListHandler { list: [], size: 0}
37+
38+
dec intListHandler d = new intListHandler { list: [7, 11, 12], size: 3}
39+
dec intListHandler e = new intListHandler { list: [2, 4, 13, 14, 15], size: 5}
40+
dec intListHandler f = new intListHandler { list: [], size: 0}
41+
42+
dec intListHandler g = new intListHandler { list: [], size: 0}
43+
44+
c = merge(a,b,c)
45+
f = merge(d,e,f)
46+
g = merge(c,f,g)
47+
48+
49+
g...display(void)
50+
}

examples/treenode.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Ufn{
4343
)
4444
})
4545

46-
(fun inorderTraversal(void)(void) {
46+
(fun inorderTraversal(void)(void) {
4747
Tree (
4848
# left
4949
( | own...hasLeft(void) | {

src/sailfish/sailfishc.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,11 @@ sailfishc::checkFunctionCall(const std::string& name,
273273
? symboltable->getSymbolType(fcInputs[i])
274274
: fcInputs[i];
275275

276-
if (inputs[i].at(0) == '[')
277-
inputs[i] = extractListType(inputs[i]);
276+
if (left.at(0) == '[')
277+
left = extractListType(left);
278278

279-
if (fcInputs[i].at(0) == '[')
280-
fcInputs[i] = extractListType(fcInputs[i]);
279+
if (right.at(0) == '[')
280+
right = extractListType(right);
281281

282282
if (left != right)
283283
semanticerrorhandler->handle(std::make_unique<Error>(Error(
@@ -817,6 +817,7 @@ sailfishc::parseFunctionInOut(const std::string& name)
817817
else
818818
outputBuffer = "struct " + extractUDTName(filename) + "* this";
819819
}
820+
820821
outputBuffer = output + "\n" + name + "(" + outputBuffer + ")\n";
821822

822823
targetBuffer += outputBuffer;
@@ -873,6 +874,8 @@ sailfishc::parseBlock()
873874
type = std::get<0>(a);
874875
if (symboltable->hasVariable(type))
875876
type = symboltable->getSymbolType(type);
877+
if (type == "U" && udttable->hasUDT(std::get<0>(a)))
878+
type = std::get<0>(a);
876879
hasSeenReturn = true;
877880
}
878881
}

src/sailfish/sailfishc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ class sailfishc
128128
const G& g)
129129
{
130130
advanceAndCheckToken(tk); // consume token
131-
output << " " + symbol + " ";
132131
targetBuffer += " " + symbol + " ";
133132
auto type = parseE0();
134133

0 commit comments

Comments
 (0)