Force the execution of expression statements
This commit is contained in:
parent
e15f6924b1
commit
156506e8fa
109
example.elna
109
example.elna
@ -1,24 +1,15 @@
|
|||||||
type
|
type
|
||||||
T = array 5 of Int,
|
T = array 5 of Int,
|
||||||
R = record
|
TokenValue = union
|
||||||
x: Int;
|
intValue: Int;
|
||||||
y: Int
|
stringValue: String
|
||||||
|
end,
|
||||||
|
Token = record
|
||||||
|
kind: Int;
|
||||||
|
value: TokenValue
|
||||||
end,
|
end,
|
||||||
FILE = record
|
FILE = record
|
||||||
x: Int
|
dummy: Int
|
||||||
end,
|
|
||||||
U = union
|
|
||||||
a: Int;
|
|
||||||
b: Int
|
|
||||||
end;
|
|
||||||
|
|
||||||
proc test_string();
|
|
||||||
var s: String;
|
|
||||||
begin
|
|
||||||
s := "Test string.";
|
|
||||||
|
|
||||||
writei("");
|
|
||||||
writei(s)
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
proc test_array();
|
proc test_array();
|
||||||
@ -38,26 +29,15 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
proc test_record();
|
proc test_record();
|
||||||
var r: R;
|
var r: Token;
|
||||||
begin
|
begin
|
||||||
writei("");
|
writei("");
|
||||||
writei("Test record:");
|
writei("Test record:");
|
||||||
|
|
||||||
r.x := 4;
|
r.kind := 4;
|
||||||
r.y := 8;
|
r.value.intValue := 8;
|
||||||
|
|
||||||
writei(r.y)
|
writei(r.value.intValue)
|
||||||
end;
|
|
||||||
|
|
||||||
proc test_union();
|
|
||||||
var u: U;
|
|
||||||
begin
|
|
||||||
writei("");
|
|
||||||
writei("Test union:");
|
|
||||||
|
|
||||||
u.a := 9;
|
|
||||||
|
|
||||||
writei(u.b)
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
proc test_primitive();
|
proc test_primitive();
|
||||||
@ -72,17 +52,6 @@ begin
|
|||||||
writei(z)
|
writei(z)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
proc test_const();
|
|
||||||
const t = 5;
|
|
||||||
var x: Int;
|
|
||||||
begin
|
|
||||||
x := t;
|
|
||||||
|
|
||||||
writei("");
|
|
||||||
writei("Test const:");
|
|
||||||
writei(x)
|
|
||||||
end;
|
|
||||||
|
|
||||||
proc test_if();
|
proc test_if();
|
||||||
var x: Bool, y: Bool;
|
var x: Bool, y: Bool;
|
||||||
begin
|
begin
|
||||||
@ -153,40 +122,66 @@ proc fopen(pathname: String, mode: String): pointer to FILE; extern;
|
|||||||
proc fclose(stream: pointer to FILE): Int; extern;
|
proc fclose(stream: pointer to FILE): Int; extern;
|
||||||
proc fseek(stream: pointer to FILE, off: Int, whence: Int): Int; extern;
|
proc fseek(stream: pointer to FILE, off: Int, whence: Int): Int; extern;
|
||||||
proc ftell(stream: pointer to FILE): Int; extern;
|
proc ftell(stream: pointer to FILE): Int; extern;
|
||||||
|
proc fread(ptr: pointer to Char, size: Int, nmemb: Int, stream: pointer to FILE): Int; extern;
|
||||||
|
proc write(fd: Int, buf: pointer to Char, count: Int): Int; extern;
|
||||||
|
proc malloc(size: Int): pointer to Char; extern;
|
||||||
|
proc free(ptr: pointer to Char); extern;
|
||||||
|
proc memset(ptr: pointer to Char, c: Int, n: Int): pointer to Char; extern;
|
||||||
|
|
||||||
proc compile();
|
proc read_source(filename: String): pointer to Char;
|
||||||
const
|
const
|
||||||
|
-- Bug: The procedure doesn't see global constants.
|
||||||
SEEK_SET = 0, SEEK_CUR = 1, SEEK_END = 2;
|
SEEK_SET = 0, SEEK_CUR = 1, SEEK_END = 2;
|
||||||
var
|
var
|
||||||
input_file: pointer to FILE,
|
input_file: pointer to FILE,
|
||||||
source_size: Int, ret: Int;
|
source_size: Int,
|
||||||
|
input: pointer to Char;
|
||||||
begin
|
begin
|
||||||
input_file := fopen("example.elna", "rb");
|
input_file := fopen(filename, "rb");
|
||||||
|
|
||||||
// Bug: Functions as statements aren't called.
|
fseek(input_file, 0, SEEK_END);
|
||||||
ret := fseek(input_file, 0, SEEK_END);
|
|
||||||
source_size := ftell(input_file);
|
source_size := ftell(input_file);
|
||||||
ret := fseek(input_file, 0, SEEK_SET);
|
fseek(input_file, 0, SEEK_SET);
|
||||||
|
|
||||||
writei("");
|
input := malloc(source_size + 1);
|
||||||
writei("File size: ");
|
memset(input, 0, source_size + 1);
|
||||||
writei(input_file);
|
fread(input, source_size, 1, input_file);
|
||||||
writei(source_size);
|
|
||||||
|
|
||||||
ret := fclose(input_file)
|
fclose(input_file);
|
||||||
|
|
||||||
|
return input
|
||||||
|
end;
|
||||||
|
|
||||||
|
-- Bug: "while not is_eof(…) do" is a syntax error.
|
||||||
|
proc is_not_eof(buffer: pointer to Int): Bool;
|
||||||
|
begin
|
||||||
|
return buffer^ /= 0
|
||||||
|
end;
|
||||||
|
|
||||||
|
proc compile();
|
||||||
|
var
|
||||||
|
input: pointer to Char,
|
||||||
|
input_pointer: pointer to Char;
|
||||||
|
begin
|
||||||
|
input := read_source("example.elna");
|
||||||
|
|
||||||
|
input_pointer := input;
|
||||||
|
while is_not_eof(input_pointer) do
|
||||||
|
write(0, input_pointer, 1);
|
||||||
|
input_pointer := input_pointer + 1
|
||||||
|
end;
|
||||||
|
|
||||||
|
free(input)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
test_primitive();
|
test_primitive();
|
||||||
test_string();
|
|
||||||
test_array();
|
test_array();
|
||||||
test_record();
|
test_record();
|
||||||
test_const();
|
|
||||||
test_if();
|
test_if();
|
||||||
test_not();
|
test_not();
|
||||||
test_param(8, 7);
|
test_param(8, 7);
|
||||||
test_const_char();
|
test_const_char();
|
||||||
test_union();
|
|
||||||
writei(test_return_int());
|
writei(test_return_int());
|
||||||
test_add_pointer();
|
test_add_pointer();
|
||||||
|
|
||||||
|
@ -852,6 +852,7 @@ namespace gcc
|
|||||||
void generic_visitor::visit(source::expression_statement *statement)
|
void generic_visitor::visit(source::expression_statement *statement)
|
||||||
{
|
{
|
||||||
statement->body().accept(this);
|
statement->body().accept(this);
|
||||||
|
append_to_statement_list(this->current_expression, &this->current_statements);
|
||||||
}
|
}
|
||||||
|
|
||||||
void generic_visitor::visit(source::return_statement *statement)
|
void generic_visitor::visit(source::return_statement *statement)
|
||||||
|
@ -311,7 +311,7 @@ designator_expression:
|
|||||||
}
|
}
|
||||||
| designator_expression DOT IDENTIFIER
|
| designator_expression DOT IDENTIFIER
|
||||||
{
|
{
|
||||||
$$ = new elna::source::field_access_expression(elna::source::make_position(@1), $1, $3);
|
$$ = new elna::source::field_access_expression(elna::source::make_position(@2), $1, $3);
|
||||||
}
|
}
|
||||||
| designator_expression HAT
|
| designator_expression HAT
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user