Added support for compile-time constant hash expressions
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use std::ops::Deref;
|
||||
|
||||
use crate::sys_call;
|
||||
|
||||
use super::sys_call::SysCall;
|
||||
use tokenizer::token::Number;
|
||||
|
||||
@@ -10,6 +12,21 @@ pub enum Literal {
|
||||
Boolean(bool),
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
pub enum LiteralOr<T> {
|
||||
Literal(Spanned<Literal>),
|
||||
Or(Spanned<T>),
|
||||
}
|
||||
|
||||
impl<T: std::fmt::Display> std::fmt::Display for LiteralOr<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Literal(l) => write!(f, "{l}"),
|
||||
Self::Or(o) => write!(f, "{o}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Literal {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
@@ -198,7 +215,14 @@ impl std::fmt::Display for LiteralOrVariable {
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct ConstDeclarationExpression {
|
||||
pub name: Spanned<String>,
|
||||
pub value: Spanned<Literal>,
|
||||
pub value: LiteralOr<SysCall>,
|
||||
}
|
||||
|
||||
impl ConstDeclarationExpression {
|
||||
pub fn is_syscall_supported(call: &SysCall) -> bool {
|
||||
use sys_call::System;
|
||||
matches!(call, SysCall::System(sys) if matches!(sys, System::Hash(_)))
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for ConstDeclarationExpression {
|
||||
|
||||
Reference in New Issue
Block a user