remove type hints from declarations
This commit is contained in:
@@ -201,7 +201,7 @@ func CHIP8.step[c: CHIP8] : void
|
|||||||
else if n == 0x3
|
else if n == 0x3
|
||||||
c->reg[x] = c->reg[x] ^ c->reg[y]
|
c->reg[x] = c->reg[x] ^ c->reg[y]
|
||||||
else if n == 0x4
|
else if n == 0x4
|
||||||
res : u8 = c->reg[x] + c->reg[y]
|
res := c->reg[x] + c->reg[y]
|
||||||
c->reg[0xf] = (res > 0xff) as u8
|
c->reg[0xf] = (res > 0xff) as u8
|
||||||
c->reg[x] = res
|
c->reg[x] = res
|
||||||
else if n == 0x5
|
else if n == 0x5
|
||||||
@@ -230,8 +230,8 @@ func CHIP8.step[c: CHIP8] : void
|
|||||||
for row in 0..n
|
for row in 0..n
|
||||||
for col in 0..8
|
for col in 0..8
|
||||||
if (c->memory[c->I + row] & (0x80 >> col)) != 0
|
if (c->memory[c->I + row] & (0x80 >> col)) != 0
|
||||||
pixel_x : u8 = (c->reg[x] + col) % 64
|
pixel_x := (c->reg[x] + col) % 64
|
||||||
pixel_y : u8 = (c->reg[y] + row) % 32
|
pixel_y := (c->reg[y] + row) % 32
|
||||||
offset := pixel_x as i64 + (pixel_y * 64)
|
offset := pixel_x as i64 + (pixel_y * 64)
|
||||||
|
|
||||||
if c->display[offset] == 1
|
if c->display[offset] == 1
|
||||||
|
|||||||
@@ -30,10 +30,10 @@ func main[] : i64
|
|||||||
|
|
||||||
for i in 0..N-3
|
for i in 0..N-3
|
||||||
for j in 0..N-3
|
for j in 0..N-3
|
||||||
h : i64 = grid->nth(i)->nth(j) * grid->nth(i)->nth(j+1) * grid->nth(i)->nth(j+2) * grid->nth(i)->nth(j+3)
|
h := grid->nth(i)->nth(j) * grid->nth(i)->nth(j+1) * grid->nth(i)->nth(j+2) * grid->nth(i)->nth(j+3)
|
||||||
v : i64 = grid->nth(j)->nth(i) * grid->nth(j+1)->nth(i) * grid->nth(j+2)->nth(i) * grid->nth(j+3)->nth(i)
|
v := grid->nth(j)->nth(i) * grid->nth(j+1)->nth(i) * grid->nth(j+2)->nth(i) * grid->nth(j+3)->nth(i)
|
||||||
d1 : i64 = grid->nth(i)->nth(j) * grid->nth(i+1)->nth(j+1) * grid->nth(i+2)->nth(j+2) * grid->nth(i+3)->nth(j+3)
|
d1 := grid->nth(i)->nth(j) * grid->nth(i+1)->nth(j+1) * grid->nth(i+2)->nth(j+2) * grid->nth(i+3)->nth(j+3)
|
||||||
d2 : i64 = grid->nth(i)->nth(N-j-1) * grid->nth(i+1)->nth(N-j-2) * grid->nth(i+2)->nth(N-j-3) * grid->nth(i+3)->nth(N-j-4)
|
d2 := grid->nth(i)->nth(N-j-1) * grid->nth(i+1)->nth(N-j-2) * grid->nth(i+2)->nth(N-j-3) * grid->nth(i+3)->nth(N-j-4)
|
||||||
out = math.max(out, math.max(h, math.max(v, math.max(d1, d2))))
|
out = math.max(out, math.max(h, math.max(v, math.max(d1, d2))))
|
||||||
|
|
||||||
io.println_i64(out)
|
io.println_i64(out)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ func main[] : i64
|
|||||||
for j in 0..1000
|
for j in 0..1000
|
||||||
carry := 0
|
carry := 0
|
||||||
for i in 0..n->size
|
for i in 0..n->size
|
||||||
tmp : i64 = n->nth(i) * 2 + carry
|
tmp := n->nth(i) * 2 + carry
|
||||||
n->set(i, tmp % 10)
|
n->set(i, tmp % 10)
|
||||||
carry = tmp / 10
|
carry = tmp / 10
|
||||||
while carry > 0
|
while carry > 0
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ include "$/containers.zr"
|
|||||||
func multiply[n: Array<i64>, x: i64] : void
|
func multiply[n: Array<i64>, x: i64] : void
|
||||||
carry := 0
|
carry := 0
|
||||||
for i in 0..n->size
|
for i in 0..n->size
|
||||||
prod : i64 = n->nth(i) * x + carry
|
prod := n->nth(i) * x + carry
|
||||||
n->set(i, prod % 10)
|
n->set(i, prod % 10)
|
||||||
carry = prod / 10
|
carry = prod / 10
|
||||||
while carry > 0
|
while carry > 0
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ func rule110_step[state: Array<bool>] : void
|
|||||||
left := false
|
left := false
|
||||||
if i - 1 >= 0
|
if i - 1 >= 0
|
||||||
left = state->nth(i - 1)
|
left = state->nth(i - 1)
|
||||||
center : bool = state->nth(i)
|
center := state->nth(i)
|
||||||
right := false
|
right := false
|
||||||
if i + 1 < state->size
|
if i + 1 < state->size
|
||||||
right = state->nth(i + 1)
|
right = state->nth(i + 1)
|
||||||
|
|||||||
@@ -215,11 +215,7 @@ _builtin_environ:
|
|||||||
pub fn compile_stmt(&mut self, env: &mut Env, stmt: &Stmt) -> Result<(), ZernError> {
|
pub fn compile_stmt(&mut self, env: &mut Env, stmt: &Stmt) -> Result<(), ZernError> {
|
||||||
match stmt {
|
match stmt {
|
||||||
Stmt::Expression(expr) => self.compile_expr(env, expr)?,
|
Stmt::Expression(expr) => self.compile_expr(env, expr)?,
|
||||||
Stmt::Declare {
|
Stmt::Declare { name, initializer } => {
|
||||||
name,
|
|
||||||
var_type,
|
|
||||||
initializer,
|
|
||||||
} => {
|
|
||||||
// TODO: move to typechecker?
|
// TODO: move to typechecker?
|
||||||
if env.get_var(&name.lexeme).is_some() {
|
if env.get_var(&name.lexeme).is_some() {
|
||||||
return error!(
|
return error!(
|
||||||
@@ -228,12 +224,9 @@ _builtin_environ:
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let var_type: String = match var_type {
|
let var_type: String = match self.expr_types[&initializer.id].as_str() {
|
||||||
Some(t) => t.lexeme.clone(),
|
|
||||||
None => match self.expr_types[&initializer.id].as_str() {
|
|
||||||
"opaque" => return error!(name.loc, "cannot infer type from opaque"),
|
"opaque" => return error!(name.loc, "cannot infer type from opaque"),
|
||||||
t => t.into(),
|
t => t.into(),
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.compile_expr(env, initializer)?;
|
self.compile_expr(env, initializer)?;
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ pub enum Stmt {
|
|||||||
Expression(Expr),
|
Expression(Expr),
|
||||||
Declare {
|
Declare {
|
||||||
name: Token,
|
name: Token,
|
||||||
var_type: Option<Token>,
|
|
||||||
initializer: Expr,
|
initializer: Expr,
|
||||||
},
|
},
|
||||||
Assign {
|
Assign {
|
||||||
@@ -371,20 +370,10 @@ impl Parser {
|
|||||||
let name = self.consume(TokenType::Identifier, "expected variable name")?;
|
let name = self.consume(TokenType::Identifier, "expected variable name")?;
|
||||||
self.consume(TokenType::Colon, "expected ':'")?;
|
self.consume(TokenType::Colon, "expected ':'")?;
|
||||||
|
|
||||||
let var_type = if self.match_token(&[TokenType::Equal]) {
|
self.consume(TokenType::Equal, "expected '=' after ':'")?;
|
||||||
None
|
|
||||||
} else {
|
|
||||||
let var_type = self.parse_type_ref()?;
|
|
||||||
self.consume(TokenType::Equal, "expected '=' after variable type")?;
|
|
||||||
Some(var_type)
|
|
||||||
};
|
|
||||||
|
|
||||||
let initializer = self.expression()?;
|
let initializer = self.expression()?;
|
||||||
Ok(Stmt::Declare {
|
Ok(Stmt::Declare { name, initializer })
|
||||||
name,
|
|
||||||
var_type,
|
|
||||||
initializer,
|
|
||||||
})
|
|
||||||
} else if self.match_token(&[TokenType::KeywordIf]) {
|
} else if self.match_token(&[TokenType::KeywordIf]) {
|
||||||
self.if_statement()
|
self.if_statement()
|
||||||
} else if self.match_token(&[TokenType::KeywordWhile]) {
|
} else if self.match_token(&[TokenType::KeywordWhile]) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use std::{
|
|||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
fmt, fs,
|
fmt, fs,
|
||||||
os::unix::fs::FileTypeExt,
|
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -91,31 +91,14 @@ impl<'a> TypeChecker<'a> {
|
|||||||
Stmt::Expression(expr) => {
|
Stmt::Expression(expr) => {
|
||||||
self.typecheck_expr(env, expr)?;
|
self.typecheck_expr(env, expr)?;
|
||||||
}
|
}
|
||||||
Stmt::Declare {
|
Stmt::Declare { name, initializer } => {
|
||||||
name,
|
let actual_type = self.typecheck_expr(env, initializer)?;
|
||||||
var_type,
|
|
||||||
initializer,
|
|
||||||
} => {
|
|
||||||
let mut actual_type = self.typecheck_expr(env, initializer)?;
|
|
||||||
if actual_type.contains(',') {
|
if actual_type.contains(',') {
|
||||||
return error!(
|
return error!(
|
||||||
&name.loc,
|
&name.loc,
|
||||||
"cannot assign multi-return call to a single variable"
|
"cannot assign multi-return call to a single variable"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if let Some(var_type) = var_type {
|
|
||||||
if !self.is_valid_type_name(&var_type.lexeme) {
|
|
||||||
return error!(
|
|
||||||
&name.loc,
|
|
||||||
"unrecognized type: ".to_owned() + &var_type.lexeme
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect_type!(actual_type.clone(), var_type.lexeme, var_type.loc);
|
|
||||||
|
|
||||||
if actual_type == "opaque" {
|
|
||||||
actual_type = var_type.lexeme.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
env.define_var(name.lexeme.clone(), actual_type);
|
env.define_var(name.lexeme.clone(), actual_type);
|
||||||
}
|
}
|
||||||
@@ -447,7 +430,7 @@ impl<'a> TypeChecker<'a> {
|
|||||||
let right_type = self.typecheck_expr(env, right)?;
|
let right_type = self.typecheck_expr(env, right)?;
|
||||||
match op.token_type {
|
match op.token_type {
|
||||||
TokenType::Minus => {
|
TokenType::Minus => {
|
||||||
expect_types!(right_type, ["i64"], op.loc);
|
expect_type!(right_type.clone(), "i64", op.loc);
|
||||||
Ok(right_type)
|
Ok(right_type)
|
||||||
}
|
}
|
||||||
TokenType::Bang => {
|
TokenType::Bang => {
|
||||||
|
|||||||
@@ -73,25 +73,25 @@ func Array.concat[a: Array<$>, b: Array<$>] : Array<$>
|
|||||||
mem.copy(b->data, new_array->data + a->size * 8, b->size * 8)
|
mem.copy(b->data, new_array->data + a->size * 8, b->size * 8)
|
||||||
return new_array
|
return new_array
|
||||||
|
|
||||||
func Array.quicksort[arr: Array<$>] : void
|
func Array.quicksort[arr: Array<i64>] : void
|
||||||
arr->_do_quicksort(0, arr->size - 1)
|
arr->_do_quicksort(0, arr->size - 1)
|
||||||
|
|
||||||
func Array._do_quicksort[arr: Array<$>, low: i64, high: i64] : void
|
func Array._do_quicksort[arr: Array<i64>, low: i64, high: i64] : void
|
||||||
if low < high
|
if low < high
|
||||||
i := arr->_partition(low, high)
|
i := arr->_partition(low, high)
|
||||||
arr->_do_quicksort(low, i - 1)
|
arr->_do_quicksort(low, i - 1)
|
||||||
arr->_do_quicksort(i + 1, high)
|
arr->_do_quicksort(i + 1, high)
|
||||||
|
|
||||||
func Array._partition[arr: Array<$>, low: i64, high: i64] : i64
|
func Array._partition[arr: Array<i64>, low: i64, high: i64] : i64
|
||||||
pivot : i64 = arr->nth(high)
|
pivot := arr->nth(high)
|
||||||
i := low - 1
|
i := low - 1
|
||||||
for j in (low)..high
|
for j in (low)..high
|
||||||
if arr->nth(j) as i64 <= pivot
|
if arr->nth(j) as i64 <= pivot
|
||||||
i += 1
|
i += 1
|
||||||
temp : i64 = arr->nth(i)
|
temp := arr->nth(i)
|
||||||
arr->set(i, arr->nth(j))
|
arr->set(i, arr->nth(j))
|
||||||
arr->set(j, temp)
|
arr->set(j, temp)
|
||||||
temp : i64 = arr->nth(i + 1)
|
temp := arr->nth(i + 1)
|
||||||
arr->set(i + 1, arr->nth(high))
|
arr->set(i + 1, arr->nth(high))
|
||||||
arr->set(high, temp)
|
arr->set(high, temp)
|
||||||
return i + 1
|
return i + 1
|
||||||
@@ -178,7 +178,7 @@ func HashMap.new[] : HashMap
|
|||||||
|
|
||||||
func HashMap.insert[map: HashMap<$>, key: str, value: $] : void
|
func HashMap.insert[map: HashMap<$>, key: str, value: $] : void
|
||||||
index := HashMap._djb2(key)
|
index := HashMap._djb2(key)
|
||||||
current : HashMap._Node = map->table->nth(index)
|
current := map->table->nth(index)
|
||||||
|
|
||||||
while current as ptr
|
while current as ptr
|
||||||
if current->key->equal(key)
|
if current->key->equal(key)
|
||||||
@@ -194,7 +194,7 @@ func HashMap.insert[map: HashMap<$>, key: str, value: $] : void
|
|||||||
|
|
||||||
func HashMap.get[map: HashMap<$>, key: str] : $, bool
|
func HashMap.get[map: HashMap<$>, key: str] : $, bool
|
||||||
index := HashMap._djb2(key)
|
index := HashMap._djb2(key)
|
||||||
current : HashMap._Node = map->table->nth(index)
|
current := map->table->nth(index)
|
||||||
|
|
||||||
while current as ptr
|
while current as ptr
|
||||||
if current->key->equal(key)
|
if current->key->equal(key)
|
||||||
@@ -205,7 +205,7 @@ func HashMap.get[map: HashMap<$>, key: str] : $, bool
|
|||||||
|
|
||||||
func HashMap.delete[map: HashMap<$>, key: str] : void
|
func HashMap.delete[map: HashMap<$>, key: str] : void
|
||||||
index := HashMap._djb2(key)
|
index := HashMap._djb2(key)
|
||||||
current : HashMap._Node = map->table->nth(index)
|
current := map->table->nth(index)
|
||||||
prev := 0 as HashMap._Node
|
prev := 0 as HashMap._Node
|
||||||
|
|
||||||
while current as ptr
|
while current as ptr
|
||||||
@@ -225,7 +225,7 @@ func HashMap.delete[map: HashMap<$>, key: str] : void
|
|||||||
func HashMap.keys[map: HashMap<$>] : Array<str>
|
func HashMap.keys[map: HashMap<$>] : Array<str>
|
||||||
out := [] as Array<str>
|
out := [] as Array<str>
|
||||||
for i in 0..HashMap._TABLE_SIZE
|
for i in 0..HashMap._TABLE_SIZE
|
||||||
current : HashMap._Node = map->table->nth(i)
|
current := map->table->nth(i)
|
||||||
while current as ptr
|
while current as ptr
|
||||||
out->push(current->key)
|
out->push(current->key)
|
||||||
current = current->next
|
current = current->next
|
||||||
@@ -233,7 +233,7 @@ func HashMap.keys[map: HashMap<$>] : Array<str>
|
|||||||
|
|
||||||
func HashMap.free_with_keys[map: HashMap<$>] : void
|
func HashMap.free_with_keys[map: HashMap<$>] : void
|
||||||
for i in 0..HashMap._TABLE_SIZE
|
for i in 0..HashMap._TABLE_SIZE
|
||||||
current : HashMap._Node = map->table->nth(i)
|
current := map->table->nth(i)
|
||||||
while current as ptr
|
while current as ptr
|
||||||
tmp := current
|
tmp := current
|
||||||
current = current->next
|
current = current->next
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func i64.to_str_buf[n: i64, buf: ptr] : void
|
|||||||
buf[1] = 0
|
buf[1] = 0
|
||||||
return
|
return
|
||||||
|
|
||||||
neg : bool = n < 0
|
neg := n < 0
|
||||||
if neg
|
if neg
|
||||||
// MIN_I64 will fail but i so dont care
|
// MIN_I64 will fail but i so dont care
|
||||||
n = -n
|
n = -n
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ func os.list_directory[path: str] : Array<str>, bool
|
|||||||
pos := 0
|
pos := 0
|
||||||
while pos < n
|
while pos < n
|
||||||
len := mem.read16(buf + pos + 16)
|
len := mem.read16(buf + pos + 16)
|
||||||
name : ptr = buf + pos + 19
|
name := buf + pos + 19
|
||||||
if name[0]
|
if name[0]
|
||||||
skip := false
|
skip := false
|
||||||
// skip if name is exactly '.' or '..'
|
// skip if name is exactly '.' or '..'
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ func str.hex_encode[s: str, s_len: i64] : str
|
|||||||
func str._hex_digit_to_int[d: u8] : u8
|
func str._hex_digit_to_int[d: u8] : u8
|
||||||
if d->is_digit()
|
if d->is_digit()
|
||||||
return d - '0'
|
return d - '0'
|
||||||
lower : u8 = d | 32
|
lower := d | 32
|
||||||
if lower >= 'a' && lower <= 'f'
|
if lower >= 'a' && lower <= 'f'
|
||||||
return lower - 'a' + 10
|
return lower - 'a' + 10
|
||||||
panic("invalid hex digit passed to str._hex_digit_to_int")
|
panic("invalid hex digit passed to str._hex_digit_to_int")
|
||||||
|
|||||||
Reference in New Issue
Block a user