Replace // with `quot`

This commit is contained in:
greg 2019-01-10 00:31:37 -08:00
parent 479a098e0f
commit a63dcf91b0
4 changed files with 6 additions and 6 deletions

View File

@ -75,7 +75,6 @@ impl BinOp {
}; };
let default = 10_000_000; let default = 10_000_000;
Some(BINOPS.get(s).map(|x| x.2.clone()).unwrap_or_else(|| { Some(BINOPS.get(s).map(|x| x.2.clone()).unwrap_or_else(|| {
println!("Warning: operator {} not defined", s);
default default
})) }))
} }
@ -84,7 +83,6 @@ impl BinOp {
let s: &str = &self.sigil; let s: &str = &self.sigil;
let default = 10_000_000; let default = 10_000_000;
BINOPS.get(s).map(|x| x.2.clone()).unwrap_or_else(|| { BINOPS.get(s).map(|x| x.2.clone()).unwrap_or_else(|| {
println!("Warning: operator {} not defined", s);
default default
}) })
} }
@ -130,7 +128,7 @@ lazy_static! {
"-" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 10), "-" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 10),
"*" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20), "*" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20),
"/" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Float))))), (), 20), "/" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Float))))), (), 20),
"//" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20), //TODO change this to `quot` "quot" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20),
"%" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20), "%" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20),
"++" => (Func(bx!(Const(StringT)), bx!(Func(bx!(Const(StringT)), bx!(Const(StringT))))), (), 30), "++" => (Func(bx!(Const(StringT)), bx!(Func(bx!(Const(StringT)), bx!(Const(StringT))))), (), 30),
"^" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20), "^" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20),

View File

@ -300,7 +300,7 @@ impl<'a> State<'a> {
("-", &[Lit(Nat(l)), Lit(Nat(r))]) => Lit(Nat(l - r)), ("-", &[Lit(Nat(l)), Lit(Nat(r))]) => Lit(Nat(l - r)),
("*", &[Lit(Nat(l)), Lit(Nat(r))]) => Lit(Nat(l * r)), ("*", &[Lit(Nat(l)), Lit(Nat(r))]) => Lit(Nat(l * r)),
("/", &[Lit(Nat(l)), Lit(Nat(r))]) => Lit(Float((l as f64)/ (r as f64))), ("/", &[Lit(Nat(l)), Lit(Nat(r))]) => Lit(Float((l as f64)/ (r as f64))),
("//", &[Lit(Nat(l)), Lit(Nat(r))]) => if r == 0 { ("quot", &[Lit(Nat(l)), Lit(Nat(r))]) => if r == 0 {
return Err(format!("divide by zero")); return Err(format!("divide by zero"));
} else { } else {
Lit(Nat(l / r)) Lit(Nat(l / r))

View File

@ -45,7 +45,7 @@ mod eval;
#[PipelineSteps(load_source, tokenizing, parsing(compact,expanded,trace), symbol_table, typechecking, ast_reducing, eval)] #[PipelineSteps(load_source, tokenizing, parsing(compact,expanded,trace), symbol_table, typechecking, ast_reducing, eval)]
#[DocMethod = get_doc] #[DocMethod = get_doc]
#[HandleCustomInterpreterDirectives = handle_custom_interpreter_directives] #[HandleCustomInterpreterDirectives = handle_custom_interpreter_directives]
/// All bits of state necessary to parse and execute a Schala program are stored in this struct /// All bits of state necessary to parse and execute a Schala program are stored in this struct.
/// `state` represents the execution state for the AST-walking interpreter, the other fields /// `state` represents the execution state for the AST-walking interpreter, the other fields
/// should be self-explanatory. /// should be self-explanatory.
pub struct Schala { pub struct Schala {
@ -193,6 +193,7 @@ fn eval(input: reduced_ast::ReducedAST, handle: &mut Schala, comp: Option<&mut U
eval_output eval_output
} }
/// Represents lines of source code
struct SourceReference { struct SourceReference {
lines: Option<Vec<String>> lines: Option<Vec<String>>
} }

View File

@ -213,7 +213,8 @@ expression := precedence_expr type_anno+
precedence_expr := prefix_expr precedence_expr := prefix_expr
prefix_expr := prefix_op call_expr prefix_expr := prefix_op call_expr
prefix_op := '+' | '-' | '!' | '~' prefix_op := '+' | '-' | '!' | '~'
call_expr := index_expr '(' ( expr_list )* ')' call_expr := index_expr ( '(' expr_list ')' )* | ε
expr_list := expression (',' expression)* | ε expr_list := expression (',' expression)* | ε
index_expr := primary ( '[' (expression (',' (expression)* | ε) ']' )* index_expr := primary ( '[' (expression (',' (expression)* | ε) ']' )*
primary := literal | paren_expr | if_expr | for_expr | while_expr | identifier_expr | lambda_expr | anonymous_struct | list_expr primary := literal | paren_expr | if_expr | for_expr | while_expr | identifier_expr | lambda_expr | anonymous_struct | list_expr