Permalink
Browse files

Reduce noise in integer syntax

  • Loading branch information...
kevinmehall committed Apr 17, 2018
1 parent 15c172d commit c0aaf80f1e4eb4672fda105d0d2d98e81087bbc2
@@ -26,7 +26,7 @@ def write_reg(reg, val) = {
}

with I2C()
def mma84() = Seq(-4..4, -4..4, -4..4) {
def mma84() = Seq(-4.0..4.0, -4.0..4.0, -4.0..4.0) {
read_reg(WHO_AM_I, 'h2a);
write_reg(CTRL_REG1, 'h31);
write_reg(XYZ_DATA_CFG, 'h00);
@@ -38,7 +38,7 @@ def mma84() = Seq(-4..4, -4..4, -4..4) {
start(ADDR_RD);

for w = [x, y, z] {
for b = chunks(#8, signed(#16, int(w * 16384))) { data(#r, b) }
for b = chunks(8, signed(16, int(w * 16384.0))) { data(#r, b) }
}

stop()
@@ -1,4 +1,4 @@
let bit = #0|#1
let bit = 0|1
let byte = [bit, bit, bit, bit, bit, bit, bit, bit]

protocol SPI() {
@@ -9,23 +9,23 @@ protocol SPI() {

with Seq(#l|#h, #l|#h, #l|#h)
def spi() = SPI() {
repeat <: #10 { val(#h, <: #l, <: #l) }
repeat <: 10 { val(#h, <: #l, <: #l) }
repeat {
on start() {}
repeat #1..#100 {
repeat 1..100 {
on data(byte) {
for bit=byte {
let b = bit[#0=#l, #1=#h]
let b = bit[0=#l, 1=#h]
val(#l, #l, <: b)
repeat <: #4 { val(#l, #l, <: b) }
repeat <: 4 { val(#l, #l, <: b) }
val(#l, #h, b)
repeat <: #4 { val(#l, #h, <: b) }
repeat <: 4 { val(#l, #h, <: b) }
}
}
}
on end() {}
val(#h, <: #l, <: #l)
repeat <: #9 { val(#h, <: #l, <: #l) }
repeat <: 9 { val(#h, <: #l, <: #l) }
}
}

@@ -550,19 +550,19 @@ fn exprs() {
value(&ctxt, &scope, &ast)
};

let two = expr("2");
let two = expr("2.");
assert_eq!(two.get_type(), Type::Number(2.0, 2.0));

let four = expr("2 + 2");
let four = expr("2. + 2.");
assert_eq!(four.get_type(), Type::Number(4.0, 4.0));

let fiveint = expr("#2 + #3");
let fiveint = expr("2 + 3");
assert_eq!(fiveint.get_type(), Type::Integer(5, 5));

let one_one_i = expr("complex(1, 0) + complex(0, 1)");
let one_one_i = expr("complex(1., 0.) + complex(0., 1.)");
assert_eq!(one_one_i.get_type(), Type::Complex);

let two_two_i = expr("complex(1, 1) * 2");
let two_two_i = expr("complex(1., 1.) * 2.");
assert_eq!(two_two_i.get_type(), Type::Complex);

let ignore = expr("_");
@@ -571,9 +571,9 @@ fn exprs() {
let down = expr("<: #h");
assert_eq!(down.get_type(), Type::Symbol(Some("h".to_string()).into_iter().collect()));

let range = expr("0..5");
let range = expr("0.0..5.0");
assert_eq!(range.get_type(), Type::Number(0.0, 5.0));

let fncall = expr("((a) => a+3)(2)");
let fncall = expr("((a) => a+3.0)(2.0)");
assert_eq!(fncall.get_type(), Type::Number(5., 5.));
}
@@ -22,7 +22,7 @@ pub fn add_primitives<'a>(loader: &'a Ctxt) {
protocol Base() {}
protocol Seq(T) { val(T) }
protocol Bytes() { byte(#0..#255) }
protocol Bytes() { byte(0..255) }
let Float32 = -1.0..1.0
"#);

@@ -133,8 +133,8 @@ pub valexpr -> ast::SpannedExpr

pub literal -> ast::Value
= "#" i:IDENTIFIER { ast::Value::Symbol(i) }
/ "#" n:INTEGER { ast::Value::Integer(n) }
/ v:FLOAT u:unit { ast::Value::Number(v) }
/ n:INTEGER { ast::Value::Integer(n) }
/ bitsliteral

bitsliteral -> ast::Value
@@ -227,7 +227,7 @@ TEST = KEYWORD<"test">
IDENTIFIER -> String = #quiet<i:$([a-zA-Z_][0-9a-zA-Z_]*) { i.to_string() }> / #expected("identifier")

INTEGER -> i64 = #quiet<i:$("-"?[0-9]+) { i.parse().unwrap() }> / #expected("integer")
FLOAT -> f64 = #quiet<i:$("-"?[0-9]+("."[0-9]+)?) { i.parse().unwrap() }> / #expected("float")
FLOAT -> f64 = #quiet<i:$("-"?[0-9]+ "." !"." [0-9]*) { i.parse().unwrap() }> / #expected("float")

STRING -> String = #quiet<'"' s:doubleQuotedCharacter* '"' { s.into_iter().collect() }> / #expected("string")

@@ -10,7 +10,7 @@ test fail @up(Seq(#x|#y)) { val(#y); val(#x); val(#x); val(#x) } | main2();
with Seq(#x|#y)
def main3() = {
val(#x)
repeat #3 { val(#x) }
repeat 3 { val(#x) }
val(#y)
}

@@ -1,10 +1,10 @@
let bit = #0 | #1
let bit = 0 | 1

with Seq([bit, bit, bit])
def test_signed() = Seq(#-4..#3) {
on val(x) { val(signed(#3, x)) }
on val(x) { val(signed(#3, x)) }
on val(x) { val(signed(#3, x)) }
def test_signed() = Seq(-4..3) {
on val(x) { val(signed(3, x)) }
on val(x) { val(signed(3, x)) }
on val(x) { val(signed(3, x)) }
}

test @both(Seq([bit, bit, bit])) { val([#1, #0, #1]); val([#0, #0, #1]); val([#0, #0, #0]) } | test_signed() | { val(#-3); val(#1); val(#0) };
test @both(Seq([bit, bit, bit])) { val([1, 0, 1]); val([0, 0, 1]); val([0, 0, 0]) } | test_signed() | { val(-3); val(1); val(0) };
@@ -11,9 +11,9 @@ def main(x) = {
val(#a)
}

test @both(Seq(t)) { val(#a) ; val(#b) ; val(#a) } | main(#0);
test fail @up(Seq(t)) { val(#a) ; val(#b) ; val(#a) } | main(#1);
test @both(Seq(t)) { val(#a) ; val(#b) ; val(#c) ; val(#d) ; val(#a) } | main(#1);
test @both(Seq(t)) { val(#a) ; val(#b) ; val(#c) ; val(#d) ; val(#c) ; val(#d) ; val(#a) } | main(#2);
test @both(Seq(t)) { val(#a) ; val(#b) ; val(#a) } | main(0);
test fail @up(Seq(t)) { val(#a) ; val(#b) ; val(#a) } | main(1);
test @both(Seq(t)) { val(#a) ; val(#b) ; val(#c) ; val(#d) ; val(#a) } | main(1);
test @both(Seq(t)) { val(#a) ; val(#b) ; val(#c) ; val(#d) ; val(#c) ; val(#d) ; val(#a) } | main(2);
test fail @up(Seq(t)) { val(#a) ; val(#b) ; val(#c) ; val(#a) } | main(_);
test fail @up(Seq(t)) { val(#a) ; val(#b) ; val(#c) ; val(#d) } | main(_);
@@ -1,17 +1,17 @@
with Seq(#0..#10)
def main() = Seq(#0..#10) {
on val(#1) {}
on val(#2) {}
with Seq(0..10)
def main() = Seq(0..10) {
on val(1) {}
on val(2) {}
on val(a) {
val(a)
val(a)
}
}

test @both(Seq(#0..#10)) { val(#5); val(#5) } | main() | { val(#1) ; val(#2) ; val(#5) };
test @both(Seq(0..10)) { val(5); val(5) } | main() | { val(1) ; val(2) ; val(5) };

with Seq((#0..#10, #0..#10))
def tuple() = Seq((#0..#10, #0..#10)) {
with Seq((0..10, 0..10))
def tuple() = Seq((0..10, 0..10)) {
on val(a, b) {
val(a, b)
val(a, b)
@@ -23,4 +23,4 @@ def tuple() = Seq((#0..#10, #0..#10)) {
}
}

test @both(Seq((#0..#10, #0..#10))) { val(#5, #6); val(#5, #6); val(#7, #8); val(#7, #8) } | tuple() | { val(#5, #6); val(#7, #8) };
test @both(Seq((0..10, 0..10))) { val(5, 6); val(5, 6); val(7, 8); val(7, 8) } | tuple() | { val(5, 6); val(7, 8) };
@@ -1,11 +1,11 @@
with Seq(#h|#l)
def main() = Seq(#0..#3) {
def main() = Seq(0..3) {
repeat {
on val(v) {
val(#h)
repeat v { val(#h) }
}
repeat #1..#10 { val(#l) }
repeat 1..10 { val(#l) }
}
}

@@ -19,4 +19,4 @@ test @up(Seq(#h|#l)) {
val(#h);
val(#h);
val(#l)
} | main() | { val(#0); val(#1); val(#2) };
} | main() | { val(0); val(1); val(2) };

0 comments on commit c0aaf80

Please sign in to comment.