[popl] some Rust code
This commit is contained in:
parent
86634e83e2
commit
b541eede94
19
popl-2017/src/README.md
Normal file
19
popl-2017/src/README.md
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
src
|
||||||
|
===
|
||||||
|
|
||||||
|
Code for "the paper".
|
||||||
|
|
||||||
|
Just enough for examples and proofs-of-concept.
|
||||||
|
Real code belongs in a public repo, like: http://github.com/bennn/trivial
|
||||||
|
|
||||||
|
|
||||||
|
rust
|
||||||
|
---
|
||||||
|
|
||||||
|
Only have syntax rules, so can only elaborate.
|
||||||
|
- No constant folding
|
||||||
|
- No throwing compile-time exceptions
|
||||||
|
- No reading regexp strings
|
||||||
|
|
||||||
|
But they have checked printf. How was that implemented?
|
||||||
|
|
9
popl-2017/src/rust/Makefile
Normal file
9
popl-2017/src/rust/Makefile
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
TARGETS=const format map regexp vector
|
||||||
|
|
||||||
|
all: ${TARGETS}
|
||||||
|
|
||||||
|
%: %.rs
|
||||||
|
rustc $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f ${TARGETS}
|
31
popl-2017/src/rust/const.rs
Normal file
31
popl-2017/src/rust/const.rs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
|
||||||
|
|
||||||
|
macro_rules! plus {
|
||||||
|
// Nooo this doesn't actually compress things at compiletime
|
||||||
|
( $( $n:expr ),* ) => {
|
||||||
|
{
|
||||||
|
let mut sum = 0;
|
||||||
|
$(
|
||||||
|
sum += $n;
|
||||||
|
)*
|
||||||
|
sum
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! div {
|
||||||
|
( $num:expr , $den:expr ) => {
|
||||||
|
// NOPE error comes too late; will be same for vector ops
|
||||||
|
{ if ($den == 0) { println!("Incoming division error"); };
|
||||||
|
$num / $den;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let m = 0;
|
||||||
|
//let n = 1 / m; // unchecked
|
||||||
|
let n = div!(1, m);
|
||||||
|
//println!("result is {}", n);
|
||||||
|
return
|
||||||
|
}
|
8
popl-2017/src/rust/format.rs
Normal file
8
popl-2017/src/rust/format.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// Rust's printf is typechecked
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
|
||||||
|
println!("Hello {:b}", "asdf");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
0
popl-2017/src/rust/map.rs
Normal file
0
popl-2017/src/rust/map.rs
Normal file
5
popl-2017/src/rust/regexp.rs
Normal file
5
popl-2017/src/rust/regexp.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
macro_rules! regexp_match {
|
||||||
|
( $x:string $y:expr ) => {{
|
||||||
|
//if ... $x shit
|
||||||
|
}};
|
||||||
|
}
|
0
popl-2017/src/rust/vector.rs
Normal file
0
popl-2017/src/rust/vector.rs
Normal file
Loading…
Reference in New Issue
Block a user