moved tokens
This commit is contained in:
parent
b5d49ed6eb
commit
719238bd77
14 changed files with 23 additions and 24 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::compiler::ast_pass::Parameter;
|
use crate::compiler::ast_pass::Parameter;
|
||||||
use crate::builtins::{FunctionMap, Signature, add, expected};
|
use crate::builtins::{FunctionMap, Signature, add, expected};
|
||||||
use crate::errors::RuntimeError;
|
use crate::errors::RuntimeError;
|
||||||
use crate::tokens::TokenType;
|
use crate::compiler::tokens::TokenType;
|
||||||
use crate::tokens::TokenType::U64;
|
use crate::compiler::tokens::TokenType::U64;
|
||||||
use crate::value::{Value, u64};
|
use crate::value::{Value, u64};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ mod list;
|
||||||
|
|
||||||
use crate::builtins::string::string_functions;
|
use crate::builtins::string::string_functions;
|
||||||
use crate::errors::{CompilerError, RuntimeError};
|
use crate::errors::{CompilerError, RuntimeError};
|
||||||
use crate::tokens::TokenType;
|
use crate::compiler::tokens::TokenType;
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::builtins::{FunctionMap, Parameter, Signature, add, expected};
|
use crate::builtins::{FunctionMap, Parameter, Signature, add, expected};
|
||||||
use crate::errors::RuntimeError;
|
use crate::errors::RuntimeError;
|
||||||
use crate::tokens::TokenType::{StringType, U64};
|
use crate::compiler::tokens::TokenType::{StringType, U64};
|
||||||
use crate::value::{Value, bool, string, u64};
|
use crate::value::{Value, bool, string, u64};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::compiler::ast_pass::Parameter;
|
use crate::compiler::ast_pass::Parameter;
|
||||||
use crate::tokens::TokenType;
|
use crate::compiler::tokens::TokenType;
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
use crate::vm::{
|
use crate::vm::{
|
||||||
OP_ADD, OP_BITAND, OP_BITOR, OP_BITXOR, OP_CALL, OP_CONSTANT, OP_DEF_BOOL, OP_DEF_F32,
|
OP_ADD, OP_BITAND, OP_BITOR, OP_BITXOR, OP_CALL, OP_CONSTANT, OP_DEF_BOOL, OP_DEF_F32,
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,14 @@ use crate::errors::CompilerError::{
|
||||||
};
|
};
|
||||||
use crate::errors::CompilerErrorAtLine;
|
use crate::errors::CompilerErrorAtLine;
|
||||||
use crate::symbol_builder::{Symbol, calculate_type, infer_type};
|
use crate::symbol_builder::{Symbol, calculate_type, infer_type};
|
||||||
use crate::tokens::TokenType::{
|
use crate::compiler::tokens::TokenType::{
|
||||||
Bang, Bool, Char, Colon, DateTime, Dot, Else, Eof, Eol, Equal, False, FloatingPoint, Fn, For,
|
Bang, Bool, Char, Colon, DateTime, Dot, Else, Eof, Eol, Equal, False, FloatingPoint, Fn, For,
|
||||||
Greater, GreaterEqual, GreaterGreater, Identifier, If, In, Indent, Integer, LeftBrace,
|
Greater, GreaterEqual, GreaterGreater, Identifier, If, In, Indent, Integer, LeftBrace,
|
||||||
LeftBracket, LeftParen, Less, LessEqual, LessLess, Let, ListType, MapType, Minus, Object, Plus,
|
LeftBracket, LeftParen, Less, LessEqual, LessLess, Let, ListType, MapType, Minus, Object, Plus,
|
||||||
Print, Range, RightBrace, RightBracket, RightParen, SingleRightArrow, Slash, Star, StringType,
|
Print, Range, RightBrace, RightBracket, RightParen, SingleRightArrow, Slash, Star, StringType,
|
||||||
True, U32, U64, Unknown,
|
True, U32, U64, Unknown,
|
||||||
};
|
};
|
||||||
use crate::tokens::{Token, TokenType};
|
use crate::compiler::tokens::{Token, TokenType};
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
use crate::{Expr, Stmt, SymbolTable};
|
use crate::{Expr, Stmt, SymbolTable};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ use crate::chunk::Chunk;
|
||||||
use crate::errors::CompilerError::{IncompatibleTypes, UndeclaredVariable};
|
use crate::errors::CompilerError::{IncompatibleTypes, UndeclaredVariable};
|
||||||
use crate::errors::{CompilerError, CompilerErrorAtLine};
|
use crate::errors::{CompilerError, CompilerErrorAtLine};
|
||||||
use crate::symbol_builder::{Symbol, calculate_type, infer_type};
|
use crate::symbol_builder::{Symbol, calculate_type, infer_type};
|
||||||
use crate::tokens::TokenType;
|
use crate::compiler::tokens::TokenType;
|
||||||
use crate::tokens::TokenType::Unknown;
|
use crate::compiler::tokens::TokenType::Unknown;
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
use crate::vm::{OP_ADD, OP_AND, OP_ASSIGN, OP_BITAND, OP_BITOR, OP_BITXOR, OP_CALL, OP_CALL_BUILTIN, OP_CONSTANT, OP_DEF_LIST, OP_DEF_MAP, OP_DIVIDE, OP_DUP, OP_EQUAL, OP_GET, OP_GOTO, OP_GOTO_IF, OP_GOTO_NIF, OP_GREATER, OP_GREATER_EQUAL, OP_LESS, OP_LESS_EQUAL, OP_LIST_GET, OP_MULTIPLY, OP_NEGATE, OP_NOT, OP_OR, OP_POP, OP_PRINT, OP_RETURN, OP_SHL, OP_SHR, OP_SUBTRACT};
|
use crate::vm::{OP_ADD, OP_AND, OP_ASSIGN, OP_BITAND, OP_BITOR, OP_BITXOR, OP_CALL, OP_CALL_BUILTIN, OP_CONSTANT, OP_DEF_LIST, OP_DEF_MAP, OP_DIVIDE, OP_DUP, OP_EQUAL, OP_GET, OP_GOTO, OP_GOTO_IF, OP_GOTO_NIF, OP_GREATER, OP_GREATER_EQUAL, OP_LESS, OP_LESS_EQUAL, OP_LIST_GET, OP_MULTIPLY, OP_NEGATE, OP_NOT, OP_OR, OP_POP, OP_PRINT, OP_RETURN, OP_SHL, OP_SHR, OP_SUBTRACT};
|
||||||
use crate::{Registry, SymbolTable};
|
use crate::{Registry, SymbolTable};
|
||||||
|
|
@ -182,6 +182,8 @@ impl Compiler {
|
||||||
|
|
||||||
self.chunk.code[goto_addr2] = self.chunk.code.len() as u16; // fill in the placeholder
|
self.chunk.code[goto_addr2] = self.chunk.code.len() as u16; // fill in the placeholder
|
||||||
self.chunk.code[goto_addr3] = self.chunk.code.len() as u16; // fill in the placeholder
|
self.chunk.code[goto_addr3] = self.chunk.code.len() as u16; // fill in the placeholder
|
||||||
|
} else {
|
||||||
|
self.chunk.code[goto_addr1] = self.chunk.code.len() as u16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Statement::ForStatement {
|
Statement::ForStatement {
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,4 @@ mod compiler_tests;
|
||||||
pub mod bytecode_pass;
|
pub mod bytecode_pass;
|
||||||
pub mod scan_pass;
|
pub mod scan_pass;
|
||||||
pub mod ast_pass;
|
pub mod ast_pass;
|
||||||
|
pub mod tokens;
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
use crate::errors::CompilerError::{IllegalCharLength, UnexpectedIdentifier, Unterminated};
|
use crate::errors::CompilerError::{IllegalCharLength, UnexpectedIdentifier, Unterminated};
|
||||||
use crate::errors::{CompilerError, CompilerErrorAtLine};
|
use crate::errors::{CompilerError, CompilerErrorAtLine};
|
||||||
use crate::tokens::TokenType::{BitXor, FloatingPoint, Integer, Question, U32, U64};
|
use crate::compiler::tokens::TokenType::{BitXor, FloatingPoint, Integer, Question, U32, U64};
|
||||||
use crate::{
|
use crate::keywords;
|
||||||
keywords,
|
use crate::compiler::tokens::{
|
||||||
tokens::{
|
|
||||||
Token,
|
Token,
|
||||||
TokenType::{self},
|
TokenType::{self},
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn scan(source: &str) -> Result<Vec<Token>, CompilerErrorAtLine> {
|
pub fn scan(source: &str) -> Result<Vec<Token>, CompilerErrorAtLine> {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::tokens::TokenType;
|
use crate::compiler::tokens::TokenType;
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::tokens::TokenType;
|
use crate::compiler::tokens::TokenType;
|
||||||
|
|
||||||
pub(crate) fn get_keyword(lexeme: &str) -> Option<TokenType> {
|
pub(crate) fn get_keyword(lexeme: &str) -> Option<TokenType> {
|
||||||
match lexeme {
|
match lexeme {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ use crate::compiler::ast_pass::{Expression, Statement};
|
||||||
use crate::errors::CrudLangError::Platform;
|
use crate::errors::CrudLangError::Platform;
|
||||||
use crate::errors::{CompilerErrorAtLine, CrudLangError};
|
use crate::errors::{CompilerErrorAtLine, CrudLangError};
|
||||||
use crate::symbol_builder::Symbol;
|
use crate::symbol_builder::Symbol;
|
||||||
use crate::value::Value::Void;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
@ -16,7 +15,6 @@ pub mod file_watch;
|
||||||
mod keywords;
|
mod keywords;
|
||||||
pub mod repl;
|
pub mod repl;
|
||||||
mod symbol_builder;
|
mod symbol_builder;
|
||||||
mod tokens;
|
|
||||||
mod value;
|
mod value;
|
||||||
pub mod vm;
|
pub mod vm;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@ use crate::compiler::ast_pass::{Expression, Parameter, Statement};
|
||||||
use crate::builtins::lookup;
|
use crate::builtins::lookup;
|
||||||
use crate::errors::CompilerError;
|
use crate::errors::CompilerError;
|
||||||
use crate::errors::CompilerError::IncompatibleTypes;
|
use crate::errors::CompilerError::IncompatibleTypes;
|
||||||
use crate::tokens::TokenType::{
|
use crate::compiler::tokens::TokenType::{
|
||||||
Bool, DateTime, F32, F64, FloatingPoint, Greater, GreaterEqual, I32, I64, Integer, Less,
|
Bool, DateTime, F32, F64, FloatingPoint, Greater, GreaterEqual, I32, I64, Integer, Less,
|
||||||
LessEqual, ListType, MapType, Minus, ObjectType, Plus, SignedInteger, StringType, U32, U64,
|
LessEqual, ListType, MapType, Minus, ObjectType, Plus, SignedInteger, StringType, U32, U64,
|
||||||
Unknown, UnsignedInteger,
|
Unknown, UnsignedInteger,
|
||||||
};
|
};
|
||||||
use crate::tokens::{Token, TokenType};
|
use crate::compiler::tokens::{Token, TokenType};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use crate::Registry;
|
||||||
use crate::chunk::Chunk;
|
use crate::chunk::Chunk;
|
||||||
use crate::errors::RuntimeError::Something;
|
use crate::errors::RuntimeError::Something;
|
||||||
use crate::errors::{RuntimeError, ValueError};
|
use crate::errors::{RuntimeError, ValueError};
|
||||||
use crate::tokens::TokenType;
|
use crate::compiler::tokens::TokenType;
|
||||||
use crate::value::{Object, Value};
|
use crate::value::{Object, Value};
|
||||||
use arc_swap::Guard;
|
use arc_swap::Guard;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue