Mapping names to builtins
This commit is contained in:
parent
bfb36b90e4
commit
24089da788
@ -1,5 +1,6 @@
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use crate::tokenizing::TokenKind;
|
use crate::tokenizing::TokenKind;
|
||||||
use crate::typechecking::{TypeConst, Type};
|
use crate::typechecking::{TypeConst, Type};
|
||||||
@ -8,7 +9,6 @@ use crate::typechecking::{TypeConst, Type};
|
|||||||
enum Builtin {
|
enum Builtin {
|
||||||
Add,
|
Add,
|
||||||
Subtract,
|
Subtract,
|
||||||
Negate,
|
|
||||||
Multiply,
|
Multiply,
|
||||||
Divide,
|
Divide,
|
||||||
Quotient,
|
Quotient,
|
||||||
@ -21,14 +21,51 @@ enum Builtin {
|
|||||||
BooleanNot,
|
BooleanNot,
|
||||||
Equality,
|
Equality,
|
||||||
LessThan,
|
LessThan,
|
||||||
LessThanEquals,
|
LessThanOrEqual,
|
||||||
GreaterThan,
|
GreaterThan,
|
||||||
GreaterThanEquals,
|
GreaterThanOrEqual,
|
||||||
Comparison,
|
Comparison,
|
||||||
FieldAccess,
|
FieldAccess,
|
||||||
IOPrint,
|
IOPrint,
|
||||||
IOPrintLn,
|
IOPrintLn,
|
||||||
IOGetLine,
|
IOGetLine,
|
||||||
|
Assignment,
|
||||||
|
Concatenate,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for Builtin {
|
||||||
|
type Err = ();
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
use Builtin::*;
|
||||||
|
Ok(match s {
|
||||||
|
"+" => Add,
|
||||||
|
"-" => Subtract,
|
||||||
|
"*" => Multiply,
|
||||||
|
"/" => Divide,
|
||||||
|
"quot" => Quotient,
|
||||||
|
"%" => Modulo,
|
||||||
|
"++" => Concatenate,
|
||||||
|
"^" => Exponentiation,
|
||||||
|
"&" => BitwiseAnd,
|
||||||
|
"&&" => BooleanAnd,
|
||||||
|
"|" => BitwiseOr,
|
||||||
|
"||" => BooleanOr,
|
||||||
|
"!" => BooleanNot,
|
||||||
|
">" => GreaterThan,
|
||||||
|
">=" => GreaterThanOrEqual,
|
||||||
|
"<" => LessThan,
|
||||||
|
"<=" => LessThanOrEqual,
|
||||||
|
"==" => Equality,
|
||||||
|
"=" => Assignment,
|
||||||
|
"<=>" => Comparison,
|
||||||
|
"." => FieldAccess,
|
||||||
|
"print" => IOPrint,
|
||||||
|
"println" => IOPrintLn,
|
||||||
|
"getline" => IOGetLine,
|
||||||
|
_ => return Err(())
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
|
Loading…
Reference in New Issue
Block a user