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
46 changes: 2 additions & 44 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, Block, BreakStmt, EnumDecl, EnumVariant, Expression, FieldSpec, Ident,
LiteralExpr, LiteralVal, Pattern, Program, Statement, StructDecl, VarDecl,
AssignmentExpr, EnumDecl, EnumVariant, Expression, FieldSpec, Ident, LiteralExpr, LiteralVal,
Pattern, StructDecl, VarDecl,
};
use techscript_common::{NodeId, Span};

Expand Down Expand Up @@ -101,47 +101,5 @@ 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: 1 addition & 0 deletions compiler/lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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: 33 additions & 43 deletions compiler/semantic/src/dsl_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ fn register_web_schemas(reg: &mut HashMap<String, DSLSchema>) {
);
}

fn register_canvas_shape_schemas(reg: &mut HashMap<String, DSLSchema>) {
fn register_canvas_schemas(reg: &mut HashMap<String, DSLSchema>) {
// Canvas module schemas ──────────────────────────────────────────
reg.insert(
"logo".to_string(),
DSLSchema::new(
Expand All @@ -317,6 +318,22 @@ fn register_canvas_shape_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 @@ -348,9 +365,7 @@ fn register_canvas_shape_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 @@ -369,73 +384,55 @@ fn register_canvas_text_schemas(reg: &mut HashMap<String, DSLSchema>) {
);

reg.insert(
"title".to_string(),
"circuits".to_string(),
DSLSchema::new(
vec![
"text".into(),
"color".into(),
"font".into(),
"size".into(),
"align".into(),
"weight".into(),
"density".into(),
"width".into(),
"animated".into(),
"complexity".into(),
],
vec!["text".into()],
vec![],
vec![],
),
);

reg.insert(
"subtitle".to_string(),
"title".to_string(),
DSLSchema::new(
vec![
"text".into(),
"color".into(),
"font".into(),
"size".into(),
"align".into(),
"weight".into(),
],
vec![],
vec![],
),
);

reg.insert(
"tagline".to_string(),
DSLSchema::new(
vec!["text".into(), "color".into(), "font".into(), "size".into()],
vec![],
vec!["text".into()],
vec![],
),
);
}

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

reg.insert(
"circuits".to_string(),
"tagline".to_string(),
DSLSchema::new(
vec![
"color".into(),
"density".into(),
"width".into(),
"animated".into(),
"complexity".into(),
],
vec!["text".into(), "color".into(), "font".into(), "size".into()],
vec![],
vec![],
),
Expand Down Expand Up @@ -490,13 +487,6 @@ fn register_canvas_misc_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
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 fetching the last mutable frame
// We reuse the existing mutable `frame` reference acquired at the start of
// the loop iteration rather than redundantly calling `self.frames.last_mut()`
// for these control flow and exception opcodes. This reduces bounds checking
// and RefCell borrow overhead on the hottest execution paths.
Opcode::Jump => {
Expand Down
2 changes: 1 addition & 1 deletion scripts/migrate_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
(r'std\.io\.println\((.+?)\)', r'say \1', 0),
(r'std\.io\.print\((.+?)\)', r'say \1', 0),

# ── std.<module>.yyy() calls β†’ module.yyy() ────────────────────────────
# ── std.xxx.yyy() calls β†’ module.yyy() ─────────────────────────────────
(r'std\.math\.', r'math.', 0),
(r'std\.strings\.', r'string.', 0),
(r'std\.fs\.', r'file.', 0),
Expand Down
48 changes: 28 additions & 20 deletions stdlib/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,30 @@ use techscript_runtime::{
value::RuntimeValue,
};

fn extract_sqlite_params(args: &[RuntimeValue]) -> Vec<rusqlite::types::Value> {
fn get_params_list(args: &[RuntimeValue]) -> Vec<RuntimeValue> {
if args.len() > 2 {
if let RuntimeValue::List { items, .. } = &args[2] {
return items
.borrow()
.iter()
.map(|p| match p {
RuntimeValue::Null => rusqlite::types::Value::Null,
RuntimeValue::Bool(b) => {
rusqlite::types::Value::Integer(if *b { 1 } else { 0 })
}
RuntimeValue::Int(i) => rusqlite::types::Value::Integer(*i),
RuntimeValue::Float(f) => rusqlite::types::Value::Real(*f),
RuntimeValue::Str(s) => rusqlite::types::Value::Text(s.clone()),
_ => rusqlite::types::Value::Null,
})
.collect();
items.borrow().clone()
} else {
Vec::new()
}
} else {
Vec::new()
}
Vec::new()
}

fn params_list_to_sqlite_params(params_list: &[RuntimeValue]) -> Vec<rusqlite::types::Value> {
params_list
.iter()
.map(|p| match p {
RuntimeValue::Null => rusqlite::types::Value::Null,
RuntimeValue::Bool(b) => rusqlite::types::Value::Integer(if *b { 1 } else { 0 }),
RuntimeValue::Int(i) => rusqlite::types::Value::Integer(*i),
RuntimeValue::Float(f) => rusqlite::types::Value::Real(*f),
RuntimeValue::Str(s) => rusqlite::types::Value::Text(s.clone()),
_ => rusqlite::types::Value::Null,
})
.collect()
}

fn std_database_connect(
Expand Down Expand Up @@ -72,8 +76,10 @@ fn std_database_query(
) -> Result<RuntimeValue, RuntimeError> {
let handle = args[0].try_into_int()? as u32;
let sql = args[1].try_into_string()?;
let params_list = get_params_list(&args);

let resources_borrow = ctx.resources.borrow();
let resources = ctx.resources.clone();
let resources_borrow = resources.borrow();
let conn = resources_borrow
.get::<rusqlite::Connection>(handle)
.ok_or_else(|| {
Expand All @@ -95,7 +101,7 @@ fn std_database_query(
)
})?;

let params_converted = extract_sqlite_params(&args);
let params_converted = params_list_to_sqlite_params(&params_list);
let column_names: Vec<String> = stmt
.column_names()
.into_iter()
Expand Down Expand Up @@ -165,8 +171,10 @@ fn std_database_execute(
) -> Result<RuntimeValue, RuntimeError> {
let handle = args[0].try_into_int()? as u32;
let sql = args[1].try_into_string()?;
let params_list = get_params_list(&args);

let resources_borrow = ctx.resources.borrow();
let resources = ctx.resources.clone();
let resources_borrow = resources.borrow();
let conn = resources_borrow
.get::<rusqlite::Connection>(handle)
.ok_or_else(|| {
Expand All @@ -180,7 +188,7 @@ fn std_database_execute(
)
})?;

let params_converted = extract_sqlite_params(&args);
let params_converted = params_list_to_sqlite_params(&params_list);
let params_refs: Vec<&dyn rusqlite::types::ToSql> = params_converted
.iter()
.map(|p| p as &dyn rusqlite::types::ToSql)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl StdlibRegistry {
StdlibModule {
name: "std.hex".to_string(),
version: "1.0.0".to_string(),
exports,
exports: exports.clone(),
required_capabilities: Vec::new(),
},
);
Expand Down
Loading
Loading