Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 44 additions & 2 deletions compiler/ast/tests/ast_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use techscript_ast::{
AssignmentExpr, EnumDecl, EnumVariant, Expression, FieldSpec, Ident, LiteralExpr, LiteralVal,
Pattern, StructDecl, VarDecl,
AssignmentExpr, Block, BreakStmt, EnumDecl, EnumVariant, Expression, FieldSpec, Ident,
LiteralExpr, LiteralVal, Pattern, Program, Statement, StructDecl, VarDecl,
};
use techscript_common::{NodeId, Span};

Expand Down Expand Up @@ -101,5 +101,47 @@ fn test_ast_serialization() {
assert_eq!(lit, deserialized);
}

#[test]
fn test_ast_program_construction_and_serialization() {
let span = Span::new(0, 50);
let id = NodeId(1);

// Create a dummy statement (Break)
let break_stmt = Statement::Break(BreakStmt::new(NodeId(2), span));

let program = Program::new(id, vec![break_stmt.clone()], span);

assert_eq!(program.id, id);
assert_eq!(program.statements.len(), 1);
assert_eq!(program.span, span);

let serialized = serde_json::to_string(&program).expect("serialize should succeed");
let deserialized: Program =
serde_json::from_str(&serialized).expect("deserialize should succeed");

assert_eq!(program, deserialized);
}

#[test]
fn test_ast_block_construction_and_serialization() {
let span = Span::new(10, 20);
let id = NodeId(3);

// Create a dummy statement (Break)
let break_stmt = Statement::Break(BreakStmt::new(NodeId(4), span));

let block = Block::new(id, vec![break_stmt.clone()], span);

assert_eq!(block.id, id);
assert_eq!(block.statements.len(), 1);
assert_eq!(block.span, span);

let serialized = serde_json::to_string(&block).expect("serialize should succeed");
let deserialized: Block =
serde_json::from_str(&serialized).expect("deserialize should succeed");

assert_eq!(block, deserialized);
}

// Internal helper just to satisfy TypeSpec compilation in test_ast_struct_decl
use techscript_ast::TypeSpec;
1 change: 0 additions & 1 deletion compiler/lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use techscript_syntax::{lookup_keyword, Token, TokenKind};
/// Private token enumeration used internally by Logos for scanning.
#[derive(Logos, Debug, Clone, Copy, PartialEq, Eq)]
#[logos(skip r"[ \t\r]+")] // Skip spaces, tabs, and carriage returns
#[allow(dead_code)]
enum LogosToken {
#[token("\n")]
#[token("\r\n")]
Expand Down
76 changes: 43 additions & 33 deletions compiler/semantic/src/dsl_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ fn register_web_schemas(reg: &mut HashMap<String, DSLSchema>) {
);
}

fn register_canvas_schemas(reg: &mut HashMap<String, DSLSchema>) {
// Canvas module schemas ──────────────────────────────────────────
fn register_canvas_shape_schemas(reg: &mut HashMap<String, DSLSchema>) {
reg.insert(
"logo".to_string(),
DSLSchema::new(
Expand All @@ -318,22 +317,6 @@ fn register_canvas_schemas(reg: &mut HashMap<String, DSLSchema>) {
),
);

reg.insert(
"rings".to_string(),
DSLSchema::new(
vec![
"count".into(),
"color".into(),
"size".into(),
"thickness".into(),
"spacing".into(),
"rotation".into(),
],
vec![],
vec![],
),
);

reg.insert(
"emblem".to_string(),
DSLSchema::new(
Expand Down Expand Up @@ -365,7 +348,9 @@ fn register_canvas_schemas(reg: &mut HashMap<String, DSLSchema>) {
vec![],
),
);
}

fn register_canvas_text_schemas(reg: &mut HashMap<String, DSLSchema>) {
reg.insert(
"letter".to_string(),
DSLSchema::new(
Expand All @@ -383,21 +368,6 @@ fn register_canvas_schemas(reg: &mut HashMap<String, DSLSchema>) {
),
);

reg.insert(
"circuits".to_string(),
DSLSchema::new(
vec![
"color".into(),
"density".into(),
"width".into(),
"animated".into(),
"complexity".into(),
],
vec![],
vec![],
),
);

reg.insert(
"title".to_string(),
DSLSchema::new(
Expand Down Expand Up @@ -437,6 +407,39 @@ fn register_canvas_schemas(reg: &mut HashMap<String, DSLSchema>) {
vec![],
),
);
}

fn register_canvas_misc_schemas(reg: &mut HashMap<String, DSLSchema>) {
reg.insert(
"rings".to_string(),
DSLSchema::new(
vec![
"count".into(),
"color".into(),
"size".into(),
"thickness".into(),
"spacing".into(),
"rotation".into(),
],
vec![],
vec![],
),
);

reg.insert(
"circuits".to_string(),
DSLSchema::new(
vec![
"color".into(),
"density".into(),
"width".into(),
"animated".into(),
"complexity".into(),
],
vec![],
vec![],
),
);

reg.insert(
"theme".to_string(),
Expand Down Expand Up @@ -487,6 +490,13 @@ fn register_canvas_schemas(reg: &mut HashMap<String, DSLSchema>) {
);
}

fn register_canvas_schemas(reg: &mut HashMap<String, DSLSchema>) {
// Canvas module schemas ──────────────────────────────────────────
register_canvas_shape_schemas(reg);
register_canvas_text_schemas(reg);
register_canvas_misc_schemas(reg);
}

fn register_generic_schemas(reg: &mut HashMap<String, DSLSchema>) {
// Generic DSL blocks ────────────────────────────────────────────
reg.insert(
Expand Down
2 changes: 2 additions & 0 deletions compiler/syntax/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ description = "Token definitions, keywords, and operator precedence for TechScri
[dependencies]
techscript_common = { path = "../common" }
serde = { workspace = true }
strum = "0.28.0"
strum_macros = "0.28.0"

[dev-dependencies]
serde_json = { workspace = true }
8 changes: 6 additions & 2 deletions compiler/syntax/src/token_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use serde::{Deserialize, Serialize};
use std::fmt;

/// Classification of literal values in TechScript 2.0.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, strum_macros::EnumIter,
)]
pub enum LiteralKind {
/// Integer literal (e.g., `42`).
Int,
Expand Down Expand Up @@ -50,7 +52,9 @@ impl fmt::Display for NumericLiteralKind {
/// - **Canonical 2.0**: The one true spelling — no warnings emitted.
/// - **Deprecated Alias**: Old spelling — still parsed, but emits a `TSW1xxx` warning.
/// - **Reserved**: Recognised by the lexer but not yet active.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, strum_macros::EnumIter,
)]
pub enum TokenKind {
// ── Canonical 2.0 Keywords ──────────────────────────────────────────────────────
/// `do` — function/method declaration (replaces `build`, `fun`, `function`)
Expand Down
118 changes: 12 additions & 106 deletions compiler/syntax/tests/syntax_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,114 +378,20 @@ fn test_serde_roundtrips() {

#[test]
fn test_token_uniqueness() {
use strum::IntoEnumIterator;
// Ensure all TokenKind static_lexemes are unique
let mut lexemes = HashSet::new();
let kinds = [
TokenKind::Do,
TokenKind::Send,
TokenKind::When,
TokenKind::Loop,
TokenKind::Repeat,
TokenKind::For,
TokenKind::In,
TokenKind::Match,
TokenKind::Case,
TokenKind::Default,
TokenKind::Try,
TokenKind::Catch,
TokenKind::Throw,
TokenKind::Use,
TokenKind::Class,
TokenKind::Struct,
TokenKind::Enum,
TokenKind::Trait,
TokenKind::Interface,
TokenKind::Const,
TokenKind::Null,
TokenKind::Say,
TokenKind::Ask,
TokenKind::Break,
TokenKind::Continue,
TokenKind::Else,
TokenKind::Async,
TokenKind::Await,
TokenKind::Parallel,
TokenKind::End,
TokenKind::Export,
TokenKind::New,
TokenKind::SelfKw,
TokenKind::True,
TokenKind::False,
TokenKind::Typeof,
TokenKind::With,
TokenKind::Build,
TokenKind::Make,
TokenKind::Return,
TokenKind::Model,
TokenKind::If,
TokenKind::Elif,
TokenKind::While,
TokenKind::Import,
TokenKind::From,
TokenKind::Let,
TokenKind::Var,
TokenKind::Fun,
TokenKind::Function,
TokenKind::Attempt,
TokenKind::None,
TokenKind::Keep,
TokenKind::Give,
TokenKind::Stop,
TokenKind::Skip,
TokenKind::Each,
TokenKind::Switch,
TokenKind::Be,
TokenKind::Equals,
TokenKind::Then,
TokenKind::Plus,
TokenKind::Minus,
TokenKind::Star,
TokenKind::Slash,
TokenKind::DoubleSlash,
TokenKind::Percent,
TokenKind::DoubleStar,
TokenKind::EqualEqual,
TokenKind::BangEqual,
TokenKind::TripleEqual,
TokenKind::BangEqualEqual,
TokenKind::Less,
TokenKind::Greater,
TokenKind::LessEqual,
TokenKind::GreaterEqual,
TokenKind::Equal,
TokenKind::PlusEqual,
TokenKind::MinusEqual,
TokenKind::StarEqual,
TokenKind::SlashEqual,
TokenKind::PercentEqual,
TokenKind::DotDot,
TokenKind::DotDotEqual,
TokenKind::QuestionDot,
TokenKind::QuestionQuestion,
TokenKind::Arrow,
TokenKind::LeftParen,
TokenKind::RightParen,
TokenKind::LeftBrace,
TokenKind::RightBrace,
TokenKind::LeftBracket,
TokenKind::RightBracket,
TokenKind::Comma,
TokenKind::Dot,
TokenKind::Colon,
TokenKind::Semicolon,
];

for kind in kinds {
let lexeme = kind.static_lexeme().unwrap();
assert!(
lexemes.insert(lexeme),
"Duplicate static lexeme detected for: {:?}",
kind
);
for kind in TokenKind::iter() {
if kind == TokenKind::FStringExprStart || kind == TokenKind::FStringExprEnd {
continue; // Overlaps with LeftBrace/RightBrace logically, but handled contextually
}
if let Some(lexeme) = kind.static_lexeme() {
assert!(
lexemes.insert(lexeme),
"Duplicate static lexeme detected for: {:?}",
kind
);
}
}
}
4 changes: 2 additions & 2 deletions runtime/vm/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ impl VM {
}

// PERFORMANCE OPTIMIZATION (Bolt):
// We reuse the existing mutable `frame` reference acquired at the start of
// the loop iteration rather than redundantly calling `self.frames.last_mut()`
// We reuse the existing mutable frame reference acquired at the start of
// the loop iteration rather than redundantly fetching the last mutable frame
// for these control flow and exception opcodes. This reduces bounds checking
// and RefCell borrow overhead on the hottest execution paths.
Opcode::Jump => {
Expand Down
Loading