allow more than 6 parameters, fix index bug, str.is_*
This commit is contained in:
@@ -239,11 +239,17 @@ _builtin_environ:
|
||||
for (i, param) in params.iter().enumerate() {
|
||||
let offset = env
|
||||
.define_var(param.var_name.lexeme.clone(), param.var_type.lexeme.clone());
|
||||
let reg = match REGISTERS.get(i) {
|
||||
Some(x) => x,
|
||||
None => return error!(&name.loc, "only up to 6 params allowed"),
|
||||
};
|
||||
emit!(&mut self.output, " mov QWORD [rbp-{}], {}", offset, reg);
|
||||
if let Some(reg) = REGISTERS.get(i) {
|
||||
emit!(&mut self.output, " mov QWORD [rbp-{}], {}", offset, reg);
|
||||
} else {
|
||||
let stack_offset = 16 + 8 * (i - REGISTERS.len());
|
||||
emit!(
|
||||
&mut self.output,
|
||||
" mov rax, QWORD [rbp+{}]",
|
||||
stack_offset
|
||||
);
|
||||
emit!(&mut self.output, " mov QWORD [rbp-{}], rax", offset);
|
||||
}
|
||||
}
|
||||
|
||||
self.compile_stmt(env, *body)?;
|
||||
@@ -517,7 +523,11 @@ _builtin_environ:
|
||||
for i in 0..num_stack {
|
||||
let arg_idx = arg_count - 1 - i;
|
||||
let offset = 8 * (arg_count - 1 - arg_idx);
|
||||
emit!(&mut self.output, " mov rax, QWORD [rsp + {}]", offset);
|
||||
emit!(
|
||||
&mut self.output,
|
||||
" mov rax, QWORD [rsp + {}]",
|
||||
offset + 8 * i
|
||||
);
|
||||
emit!(&mut self.output, " push rax");
|
||||
}
|
||||
}
|
||||
@@ -560,10 +570,11 @@ _builtin_environ:
|
||||
}
|
||||
Expr::Index { expr, index } => {
|
||||
self.compile_expr(env, *expr)?;
|
||||
emit!(&mut self.output, " mov rdi, rax");
|
||||
emit!(&mut self.output, " push rax");
|
||||
self.compile_expr(env, *index)?;
|
||||
emit!(&mut self.output, " add rdi, rax");
|
||||
emit!(&mut self.output, " call _builtin_read8");
|
||||
emit!(&mut self.output, " pop rbx");
|
||||
emit!(&mut self.output, " add rax, rbx");
|
||||
emit!(&mut self.output, " movzx rax, BYTE [rax]");
|
||||
}
|
||||
Expr::AddrOf { op, expr } => match *expr {
|
||||
Expr::Variable(name) => {
|
||||
|
||||
18
src/std.zr
18
src/std.zr
@@ -122,6 +122,24 @@ func str.equal[a: str, b: str] : bool
|
||||
func str.is_whitespace[x: u8] : bool
|
||||
return x == ' ' | x == 10 | x == 13 | x == 9
|
||||
|
||||
func str.is_digit[x: u8] : bool
|
||||
return x >= '0' & x <= '9'
|
||||
|
||||
func str.is_hex_digit[x: u8] : bool
|
||||
return (x >= '0' & x <= '9') | (x >= 'a' & x <= 'f') | (x >= 'A' & x <= 'F')
|
||||
|
||||
func str.is_lowercase[x: u8] : bool
|
||||
return x >= 'a' & x <= 'z'
|
||||
|
||||
func str.is_uppercase[x: u8] : bool
|
||||
return x >= 'A' & x <= 'Z'
|
||||
|
||||
func str.is_letter[x: u8] : bool
|
||||
return str.is_uppercase(x) | str.is_lowercase(x)
|
||||
|
||||
func str.is_alphanumeric[x: u8] : bool
|
||||
return str.is_letter(x) | str.is_digit(x)
|
||||
|
||||
func str.concat[a: str, b: str] : str
|
||||
let a_len: i64 = str.len(a)
|
||||
let b_len: i64 = str.len(b)
|
||||
|
||||
Reference in New Issue
Block a user