Allow mutable function arguments
This commit is contained in:
parent
79838a1bb3
commit
d146ec69fd
2 changed files with 25 additions and 25 deletions
|
|
@ -19,12 +19,11 @@ func print_byte(c: u8):
|
||||||
foreign func putchar(c: i32) -> i32
|
foreign func putchar(c: i32) -> i32
|
||||||
putchar(c as i32)
|
putchar(c as i32)
|
||||||
|
|
||||||
func print_str(str: u8*):
|
func print_str(mut str: u8*):
|
||||||
// Don't use puts() because it adds a newline
|
// Don't use puts() because it adds a newline
|
||||||
mut p = str
|
while *str != 0ub:
|
||||||
while *p != 0ub:
|
print_byte(*str)
|
||||||
print_byte(*p)
|
str += 1
|
||||||
p += 1
|
|
||||||
|
|
||||||
func print_i32(x: i32):
|
func print_i32(x: i32):
|
||||||
if x < 0:
|
if x < 0:
|
||||||
|
|
@ -35,7 +34,7 @@ func print_i32(x: i32):
|
||||||
print_i32(x / 10)
|
print_i32(x / 10)
|
||||||
print_byte('0' + (x % 10 as u8))
|
print_byte('0' + (x % 10 as u8))
|
||||||
|
|
||||||
func print_f32(x: f32):
|
func print_f32(mut x: f32):
|
||||||
if x < 0.0:
|
if x < 0.0:
|
||||||
print_byte('-')
|
print_byte('-')
|
||||||
print_f32(-x)
|
print_f32(-x)
|
||||||
|
|
@ -44,14 +43,14 @@ func print_f32(x: f32):
|
||||||
let xfloor = floor(x)
|
let xfloor = floor(x)
|
||||||
print_i32(xfloor)
|
print_i32(xfloor)
|
||||||
print_byte('.')
|
print_byte('.')
|
||||||
mut y = x - (xfloor as f32)
|
x -= (xfloor as f32)
|
||||||
// Print fractional part
|
// Print fractional part
|
||||||
mut i = 0
|
mut i = 0
|
||||||
while i < 3:
|
while i < 3:
|
||||||
y = y * 10.0
|
x = x * 10.0
|
||||||
let yfloor = floor(y)
|
let xfloor = floor(x)
|
||||||
print_byte('0' + (yfloor as u8))
|
print_byte('0' + (xfloor as u8))
|
||||||
y = y - (yfloor as f32)
|
x -= (xfloor as f32)
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
|
||||||
func print_vec3(v: vec3):
|
func print_vec3(v: vec3):
|
||||||
|
|
@ -108,8 +107,8 @@ struct file:
|
||||||
func open(path: u8*, mode: u8) -> file*:
|
func open(path: u8*, mode: u8) -> file*:
|
||||||
foreign func fopen(path: u8*, mode: u8*) -> file*
|
foreign func fopen(path: u8*, mode: u8*) -> file*
|
||||||
// A hack to turn a single u8 into a zero-terminated array
|
// A hack to turn a single u8 into a zero-terminated array
|
||||||
let mode_wide = mode as u32
|
let mode_wide = [mode, 0ub]
|
||||||
return fopen(path, &mode as u8*)
|
return fopen(path, &mode_wide as u8*)
|
||||||
|
|
||||||
func close(file: file*):
|
func close(file: file*):
|
||||||
foreign func fclose(file: file*) -> i32
|
foreign func fclose(file: file*) -> i32
|
||||||
|
|
|
||||||
|
|
@ -275,6 +275,7 @@ nonempty_function_declaration_argument_list
|
||||||
|
|
||||||
function_declaration_single_argument
|
function_declaration_single_argument
|
||||||
: name colon type_expression { $$ = ast::function_declaration::argument{ast::value_category::constant, $1, std::make_unique<ast::type>($3), @$}; }
|
: name colon type_expression { $$ = ast::function_declaration::argument{ast::value_category::constant, $1, std::make_unique<ast::type>($3), @$}; }
|
||||||
|
| mut name colon type_expression { $$ = ast::function_declaration::argument{ast::value_category::_mutable, $2, std::make_unique<ast::type>($4), @$}; }
|
||||||
;
|
;
|
||||||
|
|
||||||
function_return_type
|
function_return_type
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue