From 719238bd77f9ef9145885b14a96e34d1d9f998e6 Mon Sep 17 00:00:00 2001 From: Shautvast Date: Mon, 17 Nov 2025 11:07:12 +0100 Subject: [PATCH] moved tokens --- src/builtins/list.rs | 4 ++-- src/builtins/mod.rs | 2 +- src/builtins/string.rs | 2 +- src/chunk.rs | 2 +- src/compiler/ast_pass.rs | 4 ++-- src/compiler/bytecode_pass.rs | 6 ++++-- src/compiler/mod.rs | 3 ++- src/compiler/scan_pass.rs | 12 +++++------- src/{ => compiler}/tokens.rs | 0 src/errors.rs | 2 +- src/keywords.rs | 2 +- src/lib.rs | 2 -- src/symbol_builder.rs | 4 ++-- src/vm.rs | 2 +- 14 files changed, 23 insertions(+), 24 deletions(-) rename src/{ => compiler}/tokens.rs (100%) diff --git a/src/builtins/list.rs b/src/builtins/list.rs index 7f5960c..e73bea2 100644 --- a/src/builtins/list.rs +++ b/src/builtins/list.rs @@ -1,8 +1,8 @@ use crate::compiler::ast_pass::Parameter; use crate::builtins::{FunctionMap, Signature, add, expected}; use crate::errors::RuntimeError; -use crate::tokens::TokenType; -use crate::tokens::TokenType::U64; +use crate::compiler::tokens::TokenType; +use crate::compiler::tokens::TokenType::U64; use crate::value::{Value, u64}; use std::collections::HashMap; diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index 41649eb..4650280 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -3,7 +3,7 @@ mod list; use crate::builtins::string::string_functions; use crate::errors::{CompilerError, RuntimeError}; -use crate::tokens::TokenType; +use crate::compiler::tokens::TokenType; use crate::value::Value; use std::collections::HashMap; use std::sync::LazyLock; diff --git a/src/builtins/string.rs b/src/builtins/string.rs index 394df81..1ae4cb2 100644 --- a/src/builtins/string.rs +++ b/src/builtins/string.rs @@ -1,6 +1,6 @@ use crate::builtins::{FunctionMap, Parameter, Signature, add, expected}; 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 regex::Regex; use std::collections::HashMap; diff --git a/src/chunk.rs b/src/chunk.rs index b3dd3b1..36e4e35 100644 --- a/src/chunk.rs +++ b/src/chunk.rs @@ -1,5 +1,5 @@ use crate::compiler::ast_pass::Parameter; -use crate::tokens::TokenType; +use crate::compiler::tokens::TokenType; use crate::value::Value; use crate::vm::{ OP_ADD, OP_BITAND, OP_BITOR, OP_BITXOR, OP_CALL, OP_CONSTANT, OP_DEF_BOOL, OP_DEF_F32, diff --git a/src/compiler/ast_pass.rs b/src/compiler/ast_pass.rs index a266e49..a7d89b9 100644 --- a/src/compiler/ast_pass.rs +++ b/src/compiler/ast_pass.rs @@ -6,14 +6,14 @@ use crate::errors::CompilerError::{ }; use crate::errors::CompilerErrorAtLine; 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, Greater, GreaterEqual, GreaterGreater, Identifier, If, In, Indent, Integer, LeftBrace, LeftBracket, LeftParen, Less, LessEqual, LessLess, Let, ListType, MapType, Minus, Object, Plus, Print, Range, RightBrace, RightBracket, RightParen, SingleRightArrow, Slash, Star, StringType, True, U32, U64, Unknown, }; -use crate::tokens::{Token, TokenType}; +use crate::compiler::tokens::{Token, TokenType}; use crate::value::Value; use crate::{Expr, Stmt, SymbolTable}; use log::debug; diff --git a/src/compiler/bytecode_pass.rs b/src/compiler/bytecode_pass.rs index bbfb060..269bb20 100644 --- a/src/compiler/bytecode_pass.rs +++ b/src/compiler/bytecode_pass.rs @@ -5,8 +5,8 @@ use crate::chunk::Chunk; use crate::errors::CompilerError::{IncompatibleTypes, UndeclaredVariable}; use crate::errors::{CompilerError, CompilerErrorAtLine}; use crate::symbol_builder::{Symbol, calculate_type, infer_type}; -use crate::tokens::TokenType; -use crate::tokens::TokenType::Unknown; +use crate::compiler::tokens::TokenType; +use crate::compiler::tokens::TokenType::Unknown; 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::{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_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 { diff --git a/src/compiler/mod.rs b/src/compiler/mod.rs index fc7fc5c..599f3d3 100644 --- a/src/compiler/mod.rs +++ b/src/compiler/mod.rs @@ -1,4 +1,5 @@ mod compiler_tests; pub mod bytecode_pass; pub mod scan_pass; -pub mod ast_pass; \ No newline at end of file +pub mod ast_pass; +pub mod tokens; \ No newline at end of file diff --git a/src/compiler/scan_pass.rs b/src/compiler/scan_pass.rs index 3a5a357..fea70ea 100644 --- a/src/compiler/scan_pass.rs +++ b/src/compiler/scan_pass.rs @@ -1,12 +1,10 @@ use crate::errors::CompilerError::{IllegalCharLength, UnexpectedIdentifier, Unterminated}; use crate::errors::{CompilerError, CompilerErrorAtLine}; -use crate::tokens::TokenType::{BitXor, FloatingPoint, Integer, Question, U32, U64}; -use crate::{ - keywords, - tokens::{ - Token, - TokenType::{self}, - }, +use crate::compiler::tokens::TokenType::{BitXor, FloatingPoint, Integer, Question, U32, U64}; +use crate::keywords; +use crate::compiler::tokens::{ + Token, + TokenType::{self}, }; pub fn scan(source: &str) -> Result, CompilerErrorAtLine> { diff --git a/src/tokens.rs b/src/compiler/tokens.rs similarity index 100% rename from src/tokens.rs rename to src/compiler/tokens.rs diff --git a/src/errors.rs b/src/errors.rs index 01d3a26..60cc4eb 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,4 +1,4 @@ -use crate::tokens::TokenType; +use crate::compiler::tokens::TokenType; use std::fmt::Display; use thiserror::Error; diff --git a/src/keywords.rs b/src/keywords.rs index 59e1c33..6df2a53 100644 --- a/src/keywords.rs +++ b/src/keywords.rs @@ -1,4 +1,4 @@ -use crate::tokens::TokenType; +use crate::compiler::tokens::TokenType; pub(crate) fn get_keyword(lexeme: &str) -> Option { match lexeme { diff --git a/src/lib.rs b/src/lib.rs index 16bdd8b..d70f095 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,6 @@ use crate::compiler::ast_pass::{Expression, Statement}; use crate::errors::CrudLangError::Platform; use crate::errors::{CompilerErrorAtLine, CrudLangError}; use crate::symbol_builder::Symbol; -use crate::value::Value::Void; use std::collections::HashMap; use std::fs; use walkdir::WalkDir; @@ -16,7 +15,6 @@ pub mod file_watch; mod keywords; pub mod repl; mod symbol_builder; -mod tokens; mod value; pub mod vm; diff --git a/src/symbol_builder.rs b/src/symbol_builder.rs index d983488..3bcf4a4 100644 --- a/src/symbol_builder.rs +++ b/src/symbol_builder.rs @@ -2,12 +2,12 @@ use crate::compiler::ast_pass::{Expression, Parameter, Statement}; use crate::builtins::lookup; use crate::errors::CompilerError; 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, LessEqual, ListType, MapType, Minus, ObjectType, Plus, SignedInteger, StringType, U32, U64, Unknown, UnsignedInteger, }; -use crate::tokens::{Token, TokenType}; +use crate::compiler::tokens::{Token, TokenType}; use log::debug; use std::collections::HashMap; use std::ops::Deref; diff --git a/src/vm.rs b/src/vm.rs index f21d694..5ca334d 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -2,7 +2,7 @@ use crate::Registry; use crate::chunk::Chunk; use crate::errors::RuntimeError::Something; use crate::errors::{RuntimeError, ValueError}; -use crate::tokens::TokenType; +use crate::compiler::tokens::TokenType; use crate::value::{Object, Value}; use arc_swap::Guard; use std::collections::HashMap;