Skip to content

Commit 384f72c

Browse files
author
robertDurst
committed
halt execution on parser error
1 parent a5af1fb commit 384f72c

File tree

3 files changed

+22
-177
lines changed

3 files changed

+22
-177
lines changed

examples/test.fish

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,4 @@
1-
Cat Foo {
2-
int i
3-
Foo f
4-
}
5-
6-
Cfn Foo {
7-
fun get_i
8-
<- void
9-
-> int
10-
{
11-
return own.i
12-
}
13-
14-
fun bar
15-
<- void
16-
-> int
17-
{
18-
dec int i = 10
19-
i = own.f...get_i()
20-
return i
21-
}
22-
}
23-
241
start {
25-
dec Foo f = new Foo { i: 1, f: void }
26-
dec Foo b = new Foo { i: 20, f: f }
27-
28-
display_int(b...bar())
29-
display_str("\n")
2+
if | true == true and true == | 1 > 2 | | { }
3+
else {}
304
}

out.c

Lines changed: 2 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -4,152 +4,16 @@
44
*/
55
#include "stdlib/stdlib.h"
66

7-
typedef struct _Node_ {
8-
struct _Node_* next;
9-
int data;
10-
} Node;
11-
12-
Node*
13-
construct_Node(Node* next,int data)
14-
{
15-
Node* a____struct___generated = (Node*)malloc(sizeof(Node));
16-
a____struct___generated->next = next; a____struct___generated->data = data;
17-
return a____struct___generated;
18-
}
19-
207
int
21-
has_next(Node* own)
22-
{
23-
int ret = (own->next!=NULL);
24-
return ret;
25-
}
26-
void
27-
set_next(Node* own, Node* node)
28-
{
29-
own->next = node;
30-
}
31-
Node*
32-
next(Node* own)
33-
{
34-
return own->next;
35-
}
36-
int
37-
data(Node* own)
38-
{
39-
return own->data;
40-
}
41-
typedef struct _Stack_ {
42-
struct _Node_* head;
43-
int size;
44-
} Stack;
45-
46-
Stack*
47-
construct_Stack(Node* head,int size)
48-
{
49-
Stack* a____struct___generated = (Stack*)malloc(sizeof(Stack));
50-
a____struct___generated->head = head; a____struct___generated->size = size;
51-
return a____struct___generated;
52-
}
53-
54-
int
55-
is_empty(Stack* own)
56-
{
57-
return (own->size==0);
58-
}
59-
int
60-
size(Stack* own)
61-
{
62-
return own->size;
63-
}
64-
int
65-
peek(Stack* own)
66-
{
67-
int i = 0;
68-
if(is_empty(own)==1)
69-
{
70-
71-
}
72-
else
73-
{
74-
i = data(own->head);
75-
}
76-
77-
return i;
78-
}
79-
void
80-
push(Stack* own, Node* node)
81-
{
82-
set_next(node, own->head);
83-
own->head = node;
84-
own->size = own->size+1;
85-
}
86-
void
87-
pop(Stack* own)
8+
main()
889
{
89-
if(is_empty(own)==1)
10+
if(1==0)
9011
{
9112

92-
}
93-
else
94-
{
95-
own->head = next(own->head);
96-
own->size = own->size-1;
97-
}
98-
99-
}
100-
void
101-
print_(Stack* own, Node* node)
102-
{
103-
if(node!=NULL)
104-
{
105-
print_int(data(node));
106-
print_str(" ");
107-
print_(own, next(node));
10813
}
10914
else
11015
{
11116

11217
}
11318

11419
}
115-
void
116-
print(Stack* own)
117-
{
118-
print_str("Stack contents: ");
119-
print_(own, own->head);
120-
print_str("\n");
121-
}
122-
int
123-
main()
124-
{
125-
Node*a = construct_Node(NULL,10);
126-
Node*b = construct_Node(NULL,20);
127-
Node*c = construct_Node(NULL,30);
128-
Node*d = construct_Node(NULL,40);
129-
Node*e = construct_Node(NULL,50);
130-
Stack*s = construct_Stack(NULL,0);
131-
push(s, a);
132-
push(s, b);
133-
push(s, c);
134-
print(s);
135-
print_str("Size: ");
136-
print_int(size(s));
137-
print_str("\tTop: ");
138-
print_int(peek(s));
139-
print_str("\n");
140-
pop(s);
141-
pop(s);
142-
pop(s);
143-
pop(s);
144-
pop(s);
145-
print_str("Size: ");
146-
print_int(size(s));
147-
print_str("\tTop: ");
148-
print_int(peek(s));
149-
print_str("\n");
150-
push(s, d);
151-
push(s, e);
152-
push(s, c);
153-
push(s, b);
154-
print(s);
155-
}

src/main/CommandLine.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ executeBinary()
5252
system("./a.out");
5353
}
5454

55-
void
55+
bool
5656
fullCompilation(std::string filename)
5757
{
5858
try
@@ -72,10 +72,13 @@ fullCompilation(std::string filename)
7272
t->transpile();
7373

7474
std::cout << "Success. sailfishc compiled " + filename + " to: out.c\n";
75+
76+
return true;
7577
}
7678
catch (const std::string msg)
7779
{
7880
std::cerr << msg;
81+
return false;
7982
}
8083
}
8184

@@ -158,20 +161,24 @@ handleCommandLine(int argc, char* const* argv)
158161
else if (std::string("--compile_c").compare(argv[1]) == 0)
159162
{
160163
// compile sailfish
161-
fullCompilation(argv[2]);
162-
163-
// compile c
164-
compileC();
164+
if (fullCompilation(argv[2]))
165+
{
166+
// compile c
167+
compileC();
168+
}
165169
}
166170
else if (std::string("--compile_and_execute").compare(argv[1]) == 0)
167171
{
168172
// compile sailfish
169-
fullCompilation(argv[2]);
170-
171-
// compile c
172-
if (compileC())
173-
// execute gcc generated binary
174-
executeBinary();
173+
if (fullCompilation(argv[2]))
174+
{
175+
// compile c
176+
if (compileC())
177+
{
178+
// execute gcc generated binary
179+
executeBinary();
180+
}
181+
}
175182
}
176183
else
177184
{

0 commit comments

Comments
 (0)