diff --git a/nls/src/analyzer.rs b/nls/src/analyzer.rs index 9452f551..4d547d86 100644 --- a/nls/src/analyzer.rs +++ b/nls/src/analyzer.rs @@ -2,6 +2,7 @@ pub mod common; pub mod completion; pub mod flow; pub mod generics; +pub mod global_eval; pub mod lexer; // 声明子模块 pub mod semantic; pub mod symbol; @@ -523,12 +524,7 @@ pub fn register_global_symbol(m: &mut Module, symbol_table: &mut SymbolTable, st if fndef.impl_type.kind.is_unknown() { fndef.symbol_name = format_global_ident(m.ident.clone(), symbol_name.clone()); - match symbol_table.define_symbol_in_scope( - fndef.symbol_name.clone(), - SymbolKind::Fn(fndef_mutex.clone()), - fndef.symbol_start, - m.scope_id, - ) { + match symbol_table.define_symbol_in_scope(fndef.symbol_name.clone(), SymbolKind::Fn(fndef_mutex.clone()), fndef.symbol_start, m.scope_id) { Ok(symbol_id) => { fndef.symbol_id = symbol_id; } diff --git a/nls/src/analyzer/global_eval.rs b/nls/src/analyzer/global_eval.rs new file mode 100644 index 00000000..4fa5663f --- /dev/null +++ b/nls/src/analyzer/global_eval.rs @@ -0,0 +1,423 @@ +use std::sync::{Arc, Mutex}; + +use crate::project::Module; + +use super::common::{AnalyzerError, AstNode, Expr, Type, TypeKind, VarDeclExpr}; +use super::symbol::{SymbolKind, SymbolTable}; +use super::typesys::Typesys; + +#[derive(Debug)] +pub struct GlobalEval<'a> { + module: &'a mut Module, + symbol_table: &'a mut SymbolTable, + errors: Vec, +} + +impl<'a> GlobalEval<'a> { + pub fn new(module: &'a mut Module, symbol_table: &'a mut SymbolTable) -> Self { + Self { + module, + symbol_table, + errors: Vec::new(), + } + } + + pub fn analyze(&mut self) -> Vec { + let mut global_vardefs = std::mem::take(&mut self.module.global_vardefs); + let mut precheck_passed = vec![true; global_vardefs.len()]; + + for (index, node) in global_vardefs.iter().enumerate() { + let AstNode::VarDef(_, right_expr) = node else { continue }; + if let Err(e) = self.precheck_expr(right_expr.as_ref()) { + self.errors.push(e); + precheck_passed[index] = false; + } + } + + let mut infer_errors = Vec::new(); + { + let mut typesys = Typesys::new(self.symbol_table, self.module); + + for (index, node) in global_vardefs.iter_mut().enumerate() { + if !precheck_passed[index] { + continue; + } + + let AstNode::VarDef(var_decl_mutex, right_expr) = node else { + continue; + }; + + let target_type = match Self::infer_global_vardef(&mut typesys, var_decl_mutex, right_expr) { + Ok(t) => t, + Err(e) => { + infer_errors.push(e); + continue; + } + }; + + if let Err(e) = Self::validate_initializer_layout(&target_type, right_expr.as_ref()) { + infer_errors.push(e); + } + } + } + + self.module.global_vardefs = global_vardefs; + self.errors.extend(infer_errors); + self.errors.clone() + } + + fn infer_global_vardef(typesys: &mut Typesys, var_decl_mutex: &Arc>, right_expr: &mut Box) -> Result { + let (symbol_start, symbol_end, var_ident, mut var_type) = { + let mut var_decl = var_decl_mutex.lock().unwrap(); + var_decl.type_ = typesys.reduction_type(var_decl.type_.clone())?; + + (var_decl.symbol_start, var_decl.symbol_end, var_decl.ident.clone(), var_decl.type_.clone()) + }; + + if matches!(var_type.kind, TypeKind::Void) { + return Err(AnalyzerError { + start: symbol_start, + end: symbol_end, + message: "cannot assign to void".to_string(), + }); + } + + let right_type = typesys.infer_right_expr(right_expr, var_type.clone())?; + if matches!(right_type.kind, TypeKind::Void) { + return Err(AnalyzerError { + start: right_expr.start, + end: right_expr.end, + message: "cannot assign void to global var".to_string(), + }); + } + + if var_type.kind.is_unknown() { + if !typesys.type_confirm(&right_type) { + return Err(AnalyzerError { + start: right_expr.start, + end: right_expr.end, + message: format!("global var {} type infer failed, right expr cannot confirm", var_ident), + }); + } + var_type = right_type; + } + + var_type = typesys.reduction_type(var_type)?; + if !typesys.type_confirm(&var_type) { + return Err(AnalyzerError { + start: right_expr.start, + end: right_expr.end, + message: "global type not confirmed".to_string(), + }); + } + + { + let mut var_decl = var_decl_mutex.lock().unwrap(); + var_decl.type_ = var_type.clone(); + } + + Ok(var_type) + } + + fn precheck_expr(&self, expr: &Expr) -> Result<(), AnalyzerError> { + match &expr.node { + AstNode::Literal(..) | AstNode::EmptyCurlyNew | AstNode::MacroDefault(..) | AstNode::MacroReflectHash(..) => Ok(()), + AstNode::Unary(_, operand) => self.precheck_expr(operand.as_ref()), + AstNode::Binary(_, left, right) => { + self.precheck_expr(left.as_ref())?; + self.precheck_expr(right.as_ref()) + } + AstNode::Ternary(condition, consequent, alternate) => { + self.precheck_expr(condition.as_ref())?; + self.precheck_expr(consequent.as_ref())?; + self.precheck_expr(alternate.as_ref()) + } + AstNode::As(_, union_tag, src) => { + if let Some(tag_expr) = union_tag { + self.precheck_expr(tag_expr.as_ref())?; + } + self.precheck_expr(src.as_ref()) + } + AstNode::ArrayNew(elements) | AstNode::TupleNew(elements) | AstNode::SetNew(elements) => { + for item in elements { + self.precheck_expr(item.as_ref())?; + } + Ok(()) + } + AstNode::ArrRepeatNew(default_element, length_expr) | AstNode::VecRepeatNew(default_element, length_expr) => { + self.precheck_expr(default_element.as_ref())?; + self.precheck_expr(length_expr.as_ref()) + } + AstNode::VecNew(elements, _, _) => { + for item in elements { + self.precheck_expr(item.as_ref())?; + } + Ok(()) + } + AstNode::MapNew(elements) => { + for item in elements { + self.precheck_expr(item.key.as_ref())?; + self.precheck_expr(item.value.as_ref())?; + } + Ok(()) + } + AstNode::StructNew(_, _, properties) => { + for property in properties { + self.precheck_expr(property.value.as_ref())?; + } + Ok(()) + } + AstNode::Ident(ident, symbol_id) => self.precheck_ident(expr, ident, *symbol_id), + _ => Err(Self::expr_error( + expr, + "global initializer expression is not compile-time evaluable".to_string(), + )), + } + } + + fn precheck_ident(&self, expr: &Expr, ident: &str, symbol_id: usize) -> Result<(), AnalyzerError> { + if symbol_id == 0 { + return Err(Self::expr_error(expr, format!("ident '{}' undeclared", ident))); + } + + let Some(symbol) = self.symbol_table.get_symbol_ref(symbol_id) else { + return Err(Self::expr_error(expr, format!("ident '{}' undeclared", ident))); + }; + + if matches!(&symbol.kind, SymbolKind::Var(_)) && !symbol.is_local { + return Err(Self::expr_error( + expr, + format!("global initializer cannot reference global var '{}'", symbol.ident), + )); + } + + Err(Self::expr_error(expr, format!("global initializer cannot reference ident '{}'", ident))) + } + + fn validate_initializer_layout(target_type: &Type, expr: &Expr) -> Result<(), AnalyzerError> { + match &expr.node { + AstNode::Literal(literal_kind, literal_value) => Self::validate_literal_assign(target_type, literal_kind, literal_value, expr), + AstNode::As(_, _, src) => { + if !matches!(src.node, AstNode::Literal(..)) { + return Err(Self::expr_error(expr, "global cast initializer must cast a literal".to_string())); + } + Self::validate_initializer_layout(target_type, src.as_ref()) + } + AstNode::MacroDefault(..) | AstNode::MacroReflectHash(..) => Ok(()), + AstNode::ArrayNew(elements) => { + let TypeKind::Arr(_, expected_length, element_type) = &target_type.kind else { + return Err(Self::expr_error(expr, format!("array literal target type mismatch, expect '{}'", target_type))); + }; + + if elements.len() as u64 > *expected_length { + return Err(Self::expr_error( + expr, + format!("array literal length overflow, expect={}, actual={}", expected_length, elements.len()), + )); + } + + for item in elements { + Self::validate_initializer_layout(element_type.as_ref(), item.as_ref())?; + } + Ok(()) + } + AstNode::ArrRepeatNew(default_element, length_expr) => { + let TypeKind::Arr(_, expected_length, element_type) = &target_type.kind else { + return Err(Self::expr_error(expr, format!("array repeat target type mismatch, expect '{}'", target_type))); + }; + + let AstNode::Literal(_, length_literal) = &length_expr.node else { + return Err(Self::expr_error( + length_expr.as_ref(), + "array repeat length must be compile-time literal".to_string(), + )); + }; + + let Some(length) = Self::parse_i64_literal(length_literal) else { + return Err(Self::expr_error( + length_expr.as_ref(), + "array repeat length must be integer literal".to_string(), + )); + }; + + if length < 0 || length as u64 != *expected_length { + return Err(Self::expr_error( + length_expr.as_ref(), + format!("array repeat length mismatch, expect={}, actual={}", expected_length, length), + )); + } + + Self::validate_initializer_layout(element_type.as_ref(), default_element.as_ref()) + } + AstNode::TupleNew(elements) => { + let TypeKind::Tuple(expect_elements, _) = &target_type.kind else { + return Err(Self::expr_error(expr, format!("tuple literal target type mismatch, expect '{}'", target_type))); + }; + + if elements.len() != expect_elements.len() { + return Err(Self::expr_error( + expr, + format!("tuple element count mismatch, expect={}, actual={}", expect_elements.len(), elements.len()), + )); + } + + for (item, expect_type) in elements.iter().zip(expect_elements.iter()) { + Self::validate_initializer_layout(expect_type, item.as_ref())?; + } + + Ok(()) + } + AstNode::StructNew(_, _, properties) => { + let TypeKind::Struct(_, _, type_properties) = &target_type.kind else { + return Err(Self::expr_error(expr, format!("struct literal target type mismatch, expect '{}'", target_type))); + }; + + for property in properties { + let Some(expect_property) = type_properties.iter().find(|p| p.name == property.key) else { + return Err(Self::expr_error(property.value.as_ref(), format!("struct field '{}' not found", property.key))); + }; + + Self::validate_initializer_layout(&expect_property.type_, property.value.as_ref())?; + } + + Ok(()) + } + AstNode::VecNew(elements, _, _) => { + if !matches!(target_type.kind, TypeKind::Vec(_)) { + return Err(Self::expr_error(expr, format!("vec literal target type mismatch, expect '{}'", target_type))); + } + + if !elements.is_empty() { + return Err(Self::expr_error(expr, "global vec initializer must be empty".to_string())); + } + + Ok(()) + } + AstNode::MapNew(elements) => { + if !matches!(target_type.kind, TypeKind::Map(_, _)) { + return Err(Self::expr_error(expr, format!("map literal target type mismatch, expect '{}'", target_type))); + } + + if !elements.is_empty() { + return Err(Self::expr_error(expr, "global map initializer must be empty".to_string())); + } + + Ok(()) + } + AstNode::SetNew(elements) => { + if !matches!(target_type.kind, TypeKind::Set(_)) { + return Err(Self::expr_error(expr, format!("set literal target type mismatch, expect '{}'", target_type))); + } + + if !elements.is_empty() { + return Err(Self::expr_error(expr, "global set initializer must be empty".to_string())); + } + + Ok(()) + } + AstNode::EmptyCurlyNew => { + if !matches!(target_type.kind, TypeKind::Map(_, _) | TypeKind::Set(_)) { + return Err(Self::expr_error(expr, "{} only supports map/set global initializer".to_string())); + } + Ok(()) + } + AstNode::Unary(..) | AstNode::Binary(..) | AstNode::Ternary(..) => { + Err(Self::expr_error(expr, "global initializer must fold to literal before layout".to_string())) + } + _ => Err(Self::expr_error(expr, "global initializer expression is unsupported".to_string())), + } + } + + fn validate_literal_assign(target_type: &Type, literal_kind: &TypeKind, literal_value: &str, expr: &Expr) -> Result<(), AnalyzerError> { + if matches!(target_type.kind, TypeKind::String) { + if !matches!(literal_kind, TypeKind::String) { + return Err(Self::expr_error(expr, "global string initializer must be string literal".to_string())); + } + + if !literal_value.is_empty() { + return Err(Self::expr_error(expr, "global string initializer must be empty".to_string())); + } + } + + if Self::is_pointer_like(&target_type.kind) { + if !Self::is_null_like_literal(literal_kind, literal_value) { + return Err(Self::expr_error(expr, "pointer-like global initializer must be null".to_string())); + } + } + + if let TypeKind::Union(_, nullable, _) = &target_type.kind { + if *nullable && !matches!(literal_kind, TypeKind::Null) { + return Err(Self::expr_error(expr, "nullable union global initializer only supports null".to_string())); + } + } + + Ok(()) + } + + fn is_pointer_like(kind: &TypeKind) -> bool { + matches!( + kind, + TypeKind::Ptr(_) | TypeKind::Ref(_) | TypeKind::Fn(_) | TypeKind::Chan(_) | TypeKind::CoroutineT | TypeKind::Null + ) + } + + fn is_null_like_literal(kind: &TypeKind, value: &str) -> bool { + if matches!(kind, TypeKind::Null) { + return true; + } + + if !Type::is_integer(kind) { + return false; + } + + Self::parse_i64_literal(value) == Some(0) + } + + fn parse_i64_literal(value: &str) -> Option { + let raw = value.trim(); + if raw.is_empty() { + return None; + } + + let (sign, digits) = if let Some(rest) = raw.strip_prefix('-') { + (-1i64, rest) + } else if let Some(rest) = raw.strip_prefix('+') { + (1i64, rest) + } else { + (1i64, raw) + }; + + if digits.is_empty() { + return None; + } + + let (radix, body) = if let Some(rest) = digits.strip_prefix("0x") { + (16, rest) + } else if let Some(rest) = digits.strip_prefix("0o") { + (8, rest) + } else if let Some(rest) = digits.strip_prefix("0b") { + (2, rest) + } else { + (10, digits) + }; + + if body.is_empty() { + return None; + } + + let unsigned = i64::from_str_radix(body, radix).ok()?; + if sign < 0 { + unsigned.checked_neg() + } else { + Some(unsigned) + } + } + + fn expr_error(expr: &Expr, message: String) -> AnalyzerError { + AnalyzerError { + start: expr.start, + end: expr.end, + message, + } + } +} diff --git a/nls/src/analyzer/semantic.rs b/nls/src/analyzer/semantic.rs index 35298dd3..360c37bb 100644 --- a/nls/src/analyzer/semantic.rs +++ b/nls/src/analyzer/semantic.rs @@ -653,8 +653,6 @@ impl<'a> Semantic<'a> { let mut global_fn_stmt_list = Vec::>>::new(); - let mut var_assign_list = Vec::>::new(); - let mut stmts = Vec::>::new(); let mut global_vardefs = Vec::new(); @@ -755,21 +753,6 @@ impl<'a> Semantic<'a> { // push to global_vardef global_vardefs.push(AstNode::VarDef(var_decl_mutex.clone(), right_expr.clone())); - - // 将 vardef 转换成 assign 导入到 package init 中进行初始化 - let assign_left = Box::new(Expr::ident( - var_decl.symbol_start, - var_decl.symbol_end, - var_decl.ident.clone(), - var_decl.symbol_id, - )); - - let assign_stmt = Box::new(Stmt { - node: AstNode::Assign(assign_left, right_expr.clone()), - start: right_expr.start, - end: right_expr.end, - }); - var_assign_list.push(assign_stmt); } AstNode::Typedef(type_alias_mutex) => { @@ -831,34 +814,18 @@ impl<'a> Semantic<'a> { stmts.push(stmt); } - // 封装 fn init - if !var_assign_list.is_empty() { - // 创建init函数定义 - let mut fn_init = AstFnDef::default(); - fn_init.symbol_name = format_global_ident(self.module.ident.clone(), "init".to_string()); - fn_init.fn_name = fn_init.symbol_name.clone(); - fn_init.return_type = Type::new(TypeKind::Void); - fn_init.body = AstBody { - stmts: var_assign_list, - start: 0, - end: 0, - }; - - global_fn_stmt_list.push(Arc::new(Mutex::new(fn_init))); - } - // 对 fn stmt list 进行 analyzer 处理。 for fndef_mutex in &global_fn_stmt_list { self.module.all_fndefs.push(fndef_mutex.clone()); self.analyze_global_fn(fndef_mutex.clone()); } - // global vardefs 的 right 没有和 assign stmt 关联,而是使用了 clone, 所以此处需要单独对又值进行 analyze handle + // global vardef 的右值不在函数体里,需要独立做 analyze for node in &mut global_vardefs { match node { AstNode::VarDef(_, right_expr) => { if let AstNode::FnDef(_) = &right_expr.node { - // fn def 会自动 arc 引用传递, 所以不需要进行单独的 analyze handle, 只有在 fn init 中进行 analyzer 即可注册相关符号,然后再 infer 阶段进行 global var 自动 check + // fn def 会自动 arc 引用传递,这里无需重复处理 } else { self.analyze_expr(right_expr); } diff --git a/nls/src/analyzer/typesys.rs b/nls/src/analyzer/typesys.rs index d52acbf2..678250f7 100644 --- a/nls/src/analyzer/typesys.rs +++ b/nls/src/analyzer/typesys.rs @@ -3729,10 +3729,7 @@ impl<'a> Typesys<'a> { // register_global_symbol 中进行类 impl_foramt let mut impl_symbol_name = format_impl_ident(impl_ident.clone(), key.clone()); - let (final_symbol_name, symbol_id) = match self - .symbol_table - .find_symbol_id(&impl_symbol_name, self.symbol_table.global_scope_id) - { + let (final_symbol_name, symbol_id) = match self.symbol_table.find_symbol_id(&impl_symbol_name, self.symbol_table.global_scope_id) { Some(symbol_id) => (impl_symbol_name.clone(), symbol_id), None => { if extract_type.kind != TypeKind::Ident { @@ -3750,10 +3747,7 @@ impl<'a> Typesys<'a> { impl_args = builtin_type.args.clone(); impl_symbol_name = format_impl_ident(impl_ident.clone(), key.clone()); - match self - .symbol_table - .find_symbol_id(&impl_symbol_name, self.symbol_table.global_scope_id) - { + match self.symbol_table.find_symbol_id(&impl_symbol_name, self.symbol_table.global_scope_id) { Some(symbol_id) => { // change self arg 类型 match &mut select_left.type_.kind { @@ -4901,26 +4895,6 @@ impl<'a> Typesys<'a> { Ok(result) } - fn infer_global_vardef(&mut self, var_decl_mutex: &Arc>, right_expr: &mut Box) -> Result<(), AnalyzerError> { - let mut var_decl = var_decl_mutex.lock().unwrap(); - var_decl.type_ = self.reduction_type(var_decl.type_.clone())?; - - let right_expr_type = self.infer_right_expr(right_expr, var_decl.type_.clone())?; - - if var_decl.type_.kind.is_unknown() { - if !self.type_confirm(&right_expr_type) { - return Err(AnalyzerError { - message: format!("global var {} type infer failed, right expr cannot confirm", var_decl.ident), - start: right_expr.start, - end: right_expr.end, - }); - } - var_decl.type_ = right_expr_type; - } - - Ok(()) - } - // 新增一个方法来处理模块内的操作 // fn current_fn_module(&mut self, f: F) -> R // where @@ -5338,17 +5312,6 @@ impl<'a> Typesys<'a> { } pub fn pre_infer(&mut self) -> Vec { - // - Global variables also contain type information, which needs to be restored and derived - let mut vardefs = std::mem::take(&mut self.module.global_vardefs); - for node in &mut vardefs { - let AstNode::VarDef(var_decl_mutex, right_expr) = node else { unreachable!() }; - - if let Err(e) = self.infer_global_vardef(var_decl_mutex, right_expr) { - self.errors_push(e.start, e.end, e.message); - } - } - self.module.global_vardefs = vardefs; - // 遍历 module 下的所有的 fndef, 包含 global fn 和 local fn let global_fndefs = self.module.global_fndefs.clone(); for fndef_mutex in global_fndefs { diff --git a/nls/src/project.rs b/nls/src/project.rs index 765bce50..cf0aea29 100644 --- a/nls/src/project.rs +++ b/nls/src/project.rs @@ -1,6 +1,7 @@ use crate::analyzer::common::{AnalyzerError, AstFnDef, AstNode, ImportStmt, PackageConfig, Stmt}; use crate::analyzer::flow::Flow; use crate::analyzer::generics::Generics; +use crate::analyzer::global_eval::GlobalEval; use crate::analyzer::lexer::{Lexer, Token}; use crate::analyzer::semantic::Semantic; use crate::analyzer::symbol::{NodeId, SymbolTable}; @@ -404,6 +405,14 @@ impl Project { m.analyzer_errors.extend(errors); } + for index in module_indexes.clone() { + let mut module_db = self.module_db.lock().unwrap(); + let mut symbol_table = self.symbol_table.lock().unwrap(); + let m = &mut module_db[index]; + let errors = GlobalEval::new(m, &mut symbol_table).analyze(); + m.analyzer_errors.extend(errors); + } + for index in module_indexes.clone() { let mut module_db = self.module_db.lock().unwrap(); let mut symbol_table = self.symbol_table.lock().unwrap(); diff --git a/nls/tests/global_eval_test.rs b/nls/tests/global_eval_test.rs new file mode 100644 index 00000000..6b5f5eea --- /dev/null +++ b/nls/tests/global_eval_test.rs @@ -0,0 +1,39 @@ +use nls::analyzer::module_unique_ident; +use nls::project::Project; +use std::fs; +use std::path::PathBuf; +use std::time::{SystemTime, UNIX_EPOCH}; + +fn case_root(name: &str) -> PathBuf { + let nanos = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_nanos(); + let dir = std::env::temp_dir().join(format!("nls_{}_{}", name, nanos)); + fs::create_dir_all(&dir).unwrap(); + dir +} + +#[tokio::test] +async fn test_global_eval_non_empty_string_should_fail() { + let root = case_root("global_eval"); + let file_path = root.join("main.n"); + let code = r#" +string s = 'hello world' + +fn main() { +} +"#; + fs::write(&file_path, code).unwrap(); + + let mut project = Project::new(root.to_string_lossy().to_string()).await; + let module_ident = module_unique_ident(&project.root, &file_path.to_string_lossy()); + let module_index = project.build(&file_path.to_string_lossy(), &module_ident, Some(code.to_string())).await; + + let module_db = project.module_db.lock().unwrap(); + let m = &module_db[module_index]; + + let has_error = m.analyzer_errors.iter().any(|e| e.message.contains("global string initializer must be empty")); + assert!( + has_error, + "expected non-empty global string error, actual errors: {:?}", + m.analyzer_errors.iter().map(|e| e.message.clone()).collect::>() + ); +} diff --git a/runtime/memory.c b/runtime/memory.c index 6a7c40e2..d6dea72b 100644 --- a/runtime/memory.c +++ b/runtime/memory.c @@ -108,7 +108,7 @@ void register_const_str_pool() { } *pool_copy = str; sc_map_put_sv(&const_str_pool, (char *) s.base, pool_copy); -// TDEBUGF("[register_const_str_pool] str = %p, str %s", str, (char *) s.base); + // TDEBUGF("[register_const_str_pool] str = %p, str %s", str, (char *) s.base); } }; diff --git a/runtime/nutils/nutils.c b/runtime/nutils/nutils.c index 017a5271..3f7e17dc 100644 --- a/runtime/nutils/nutils.c +++ b/runtime/nutils/nutils.c @@ -72,8 +72,8 @@ void interface_assert(n_interface_t *mu, int64_t target_rtype_hash, void *value_ void union_assert(n_union_t *mu, int64_t target_rtype_hash, void *value_ref) { if (mu->rtype->hash != target_rtype_hash) { DEBUGF("[union_assert] type assert failed, mu->rtype->kind: %s, target_rtype_hash: %ld", - type_kind_str[mu->rtype->kind], - target_rtype_hash); + type_kind_str[mu->rtype->kind], + target_rtype_hash); rti_throw("type assert failed", true); return; @@ -196,8 +196,8 @@ void union_casting(n_union_t *out, int64_t input_rtype_hash, void *value_ref) { ASSERT_ADDR(value_ref); - TRACEF("[union_casting] input_kind=%s", type_kind_str[rtype->kind]); - + DEBUGF("[union_casting] hash=%ld input_kind=%d", input_rtype_hash, rtype->kind); + assert(rtype->kind < 1000); DEBUGF("[union_casting] union_base: %p, memmove value_ref(%p) -> any->value(%p), size=%lu, fetch_value_8byte=%p", out, value_ref, &out->value, rtype->storage_size, (void *) fetch_addr_value((addr_t) value_ref)); diff --git a/src/ast.c b/src/ast.c index 7815bbb0..4f62fbc9 100644 --- a/src/ast.c +++ b/src/ast.c @@ -658,6 +658,7 @@ static ast_var_decl_t *ast_var_decl_copy(module_t *m, ast_var_decl_t *temp) { static ast_vardef_stmt_t *ast_vardef_copy(module_t *m, ast_vardef_stmt_t *temp) { ast_vardef_stmt_t *vardef = COPY_NEW(ast_vardef_stmt_t, temp); vardef->var_decl = *ast_var_decl_copy(m, &temp->var_decl); + vardef->global_data = NULL; if (temp->right) { vardef->right = ast_expr_copy(m, temp->right); } diff --git a/src/ast.h b/src/ast.h index cfafe229..46974de9 100644 --- a/src/ast.h +++ b/src/ast.h @@ -326,6 +326,7 @@ typedef struct { typedef struct { ast_var_decl_t var_decl; // 左值 ast_expr_t *right; // 右值 + uint8_t *global_data; // global_eval pass 生成的编译期初始化数据 } ast_vardef_stmt_t; typedef struct { diff --git a/src/build/build.c b/src/build/build.c index 7ff2e8e9..96e3ab3b 100644 --- a/src/build/build.c +++ b/src/build/build.c @@ -27,6 +27,7 @@ #include "src/register/linearscan.h" #include "src/schedule.h" #include "src/semantic/analyzer.h" +#include "src/semantic/global_eval.h" #include "src/semantic/generics.h" #include "src/semantic/infer.h" #include "src/ssa.h" @@ -840,7 +841,7 @@ static void build_assembler(slice_t *modules) { asm_global_symbol_t *symbol = NEW(asm_global_symbol_t); symbol->name = var_decl->ident; symbol->size = var_decl->type.storage_size; - symbol->value = NULL; + symbol->value = vardef->global_data; slice_push(m->asm_global_symbols, symbol); } @@ -986,53 +987,6 @@ static slice_t *build_modules(toml_table_t *package_conf) { analyzer(m, m->stmt_list); } - // register all module init to .main.init, then main.main calls .main.init - assert(main_package->ast_fndefs->count > 0); - - // .main.init 已经在 analyzer.c 中创建 - ast_fndef_t *main_init_fn = main_package->fn_init; - assert(main_init_fn); - - // 查找 main 函数 - ast_fndef_t *main_fndef = NULL; - SLICE_FOR(main_package->ast_fndefs) { - ast_fndef_t *f = SLICE_VALUE(main_package->ast_fndefs); - if (str_equal(f->fn_name, FN_MAIN_NAME)) { - main_fndef = f; - } - } - assert(main_fndef); - - // 构建新的 .main.init body - // 1. 从后往前插入所有其他模块的 call_init_stmt - slice_t *init_body = slice_new(); - for (int i = modules->count - 1; i >= 0; --i) { - module_t *m = modules->take[i]; - // 跳过 main 模块自己的 call_init_stmt,因为其内容会直接放在 .main.init 中 - if (m == main_package) { - continue; - } - if (m->call_init_stmt) { - slice_push(init_body, m->call_init_stmt); - } - } - - // 2. 添加 .main.init 原有的表达式 (main 模块的全局变量初始化) - if (main_init_fn->body) { - slice_concat(init_body, main_init_fn->body); - } - main_init_fn->body = init_body; - - // 3. 在 main.main 开头插入 call .main.init (复用 analyzer.c 中创建的 call_init_stmt) - assert(main_package->call_init_stmt); - - slice_t *main_body = slice_new(); - slice_push(main_body, main_package->call_init_stmt); - if (main_fndef->body) { - slice_concat(main_body, main_fndef->body); - } - main_fndef->body = main_body; - return modules; } @@ -1135,6 +1089,13 @@ static void build_compiler(slice_t *modules) { pre_infer(m); } + // global eval pass + // 对全局变量做编译期求值与内存布局初始化 + for (int i = modules->count - 1; i >= 0; --i) { + module_t *m = modules->take[i]; + global_eval(m); + } + // infer + compiler for (int i = 0; i < modules->count; ++i) { module_t *m = modules->take[i]; diff --git a/src/semantic/analyzer.c b/src/semantic/analyzer.c index 01611111..f1c44e00 100644 --- a/src/semantic/analyzer.c +++ b/src/semantic/analyzer.c @@ -1175,7 +1175,10 @@ static void analyzer_is_expr(module_t *m, ast_is_expr_t *is_expr) { * @return */ static void analyzer_local_fndef(module_t *m, ast_fndef_t *fndef) { - assert(m->analyzer_global); + ANALYZER_ASSERTF(m->analyzer_global, "closure fn cannot appear in global initializer"); + if (!m->analyzer_global) { + return; + } slice_push(m->analyzer_global->local_children, fndef); fndef->global_parent = m->analyzer_global; fndef->is_local = true; @@ -2224,8 +2227,6 @@ static void analyzer_stmt(module_t *m, ast_stmt_t *stmt) { * @param stmt_list */ static void analyzer_module(module_t *m, slice_t *stmt_list) { - // var_decl blocks - slice_t *global_assign_list = slice_new(); // 存放 stmt slice_t *fn_list = slice_new(); slice_t *typedef_list = slice_new(); @@ -2243,32 +2244,17 @@ static void analyzer_module(module_t *m, slice_t *stmt_list) { if (stmt->assert_type == AST_STMT_VARDEF) { ast_vardef_stmt_t *vardef = stmt->value; ast_var_decl_t *var_decl = &vardef->var_decl; + + assert(vardef->right); + analyzer_expr(m, vardef->right); analyzer_type(m, &var_decl->type); + slice_push(m->global_vardef, vardef); symbol_t *s = symbol_table_get(var_decl->ident); assert(s && str_equal(s->ident, var_decl->ident)); slice_push(m->global_symbols, s); - // 将 vardef 转换成 assign stmt,然后导入到 fn init 中进行初始化 - ast_stmt_t *assign_stmt = NEW(ast_stmt_t); - ast_assign_stmt_t *assign = NEW(ast_assign_stmt_t); - assign->left = (ast_expr_t){ - .line = stmt->line, - .column = stmt->column, - .assert_type = AST_EXPR_IDENT, - .value = ast_new_ident(var_decl->ident), - }; - assign->var_decl = &vardef->var_decl; - assign->right = *vardef->right; - assign_stmt->line = stmt->line; - assign_stmt->column = stmt->column; - assign_stmt->assert_type = AST_STMT_GLOBAL_ASSIGN; - assign_stmt->value = assign; - slice_push(global_assign_list, assign_stmt); - - // 清空 global stmt 的 var right - vardef->right = NULL; continue; } @@ -2370,46 +2356,7 @@ static void analyzer_module(module_t *m, slice_t *stmt_list) { m->ast_typedefs = typedef_list; - // 添加 module init 函数 - // 对于 main 模块,总是创建 .main.init(即使没有全局变量) - // 对于其他模块,只有当存在全局变量赋值时才创建 - if (global_assign_list->count > 0 || m->type == MODULE_TYPE_MAIN) { - ast_fndef_t *fn_init = ast_fndef_new(m, 0, 0); - // .module.ident . init 加点避免和用户代码冲突 - fn_init->symbol_name = str_connect(".", ident_with_prefix(m->ident, FN_INIT_NAME)); - fn_init->fn_name = fn_init->symbol_name; - fn_init->fn_name_with_pkg = ident_with_prefix(m->ident, fn_init->symbol_name); - fn_init->return_type = type_kind_new(TYPE_VOID); - fn_init->params = ct_list_new(sizeof(ast_var_decl_t)); - fn_init->body = global_assign_list; - fn_init->is_errable = true; - m->fn_init = fn_init; - - // 将 module init 函数添加到全局符号中 - symbol_t *s = symbol_table_set(fn_init->symbol_name, SYMBOL_FN, fn_init, false); - ANALYZER_ASSERTF(s, "fn '%s' redeclared", fn_init->symbol_name); - slice_push(m->global_symbols, s); - slice_push(fn_list, fn_init); - - // 添加调用指令(后续会将这条指令插入到 main.main 或 .main.init 中) - ast_stmt_t *call_stmt = NEW(ast_stmt_t); - ast_call_t *call = NEW(ast_call_t); - call->left = (ast_expr_t){ - .assert_type = AST_EXPR_IDENT, - .value = ast_new_ident(s->ident), // module.init - .line = 1, - .column = 0, - }; - call->args = ct_list_new(sizeof(ast_expr_t)); - call_stmt->assert_type = AST_CALL; - call_stmt->value = call; - call_stmt->line = 1; - call_stmt->column = 0; - m->call_init_stmt = call_stmt; - } - - // 此时所有对符号都已经主要到了全局变量表中,vardef 的右值则注册到了 fn.init 中,下面对 fndef body - // 进行符号定位与改写 + // 全局符号收集完成后,开始对 fndef body 进行符号定位与改写 for (int i = 0; i < fn_list->count; ++i) { ast_fndef_t *fndef = fn_list->take[i]; diff --git a/src/semantic/global_eval.c b/src/semantic/global_eval.c new file mode 100644 index 00000000..7caa7b6b --- /dev/null +++ b/src/semantic/global_eval.c @@ -0,0 +1,578 @@ +#include "global_eval.h" + +#include +#include +#include +#include + +#include "infer.h" +#include "src/error.h" +#include "src/rtype.h" +#include "src/symbol/symbol.h" +#include "utils/helper.h" + +static bool global_type_confirmed(type_t t) { + if (t.kind == TYPE_UNKNOWN) { + return false; + } + + if (t.kind == TYPE_VEC) { + return t.vec->element_type.kind != TYPE_UNKNOWN; + } + + if (t.kind == TYPE_MAP) { + return t.map->key_type.kind != TYPE_UNKNOWN && t.map->value_type.kind != TYPE_UNKNOWN; + } + + if (t.kind == TYPE_SET) { + return t.set->element_type.kind != TYPE_UNKNOWN; + } + + if (t.kind == TYPE_ARR) { + return t.array->element_type.kind != TYPE_UNKNOWN; + } + + if (t.kind == TYPE_TUPLE) { + for (int i = 0; i < t.tuple->elements->length; ++i) { + type_t *element = ct_list_value(t.tuple->elements, i); + if (!global_type_confirmed(*element)) { + return false; + } + } + } + + if (t.kind == TYPE_STRUCT) { + for (int i = 0; i < t.struct_->properties->length; ++i) { + struct_property_t *p = ct_list_value(t.struct_->properties, i); + if (!global_type_confirmed(p->type)) { + return false; + } + } + } + + return true; +} + +static void global_eval_precheck_expr(module_t *m, ast_expr_t *expr) { + SET_LINE_COLUMN(expr); + + switch (expr->assert_type) { + case AST_EXPR_LITERAL: + case AST_EXPR_EMPTY_CURLY_NEW: + case AST_MACRO_EXPR_DEFAULT: + case AST_MACRO_EXPR_REFLECT_HASH: + return; + case AST_EXPR_UNARY: { + ast_unary_expr_t *unary = expr->value; + global_eval_precheck_expr(m, &unary->operand); + return; + } + case AST_EXPR_BINARY: { + ast_binary_expr_t *binary = expr->value; + global_eval_precheck_expr(m, &binary->left); + global_eval_precheck_expr(m, &binary->right); + return; + } + case AST_EXPR_TERNARY: { + ast_ternary_expr_t *ternary = expr->value; + global_eval_precheck_expr(m, &ternary->condition); + global_eval_precheck_expr(m, &ternary->consequent); + global_eval_precheck_expr(m, &ternary->alternate); + return; + } + case AST_EXPR_AS: { + ast_as_expr_t *as_expr = expr->value; + global_eval_precheck_expr(m, &as_expr->src); + return; + } + case AST_EXPR_ARRAY_NEW: { + ast_array_new_t *array_new = expr->value; + for (int i = 0; i < array_new->elements->length; ++i) { + ast_expr_t *item = ct_list_value(array_new->elements, i); + global_eval_precheck_expr(m, item); + } + return; + } + case AST_EXPR_ARRAY_REPEAT_NEW: { + ast_array_repeat_new_t *repeat_new = expr->value; + global_eval_precheck_expr(m, &repeat_new->default_element); + global_eval_precheck_expr(m, &repeat_new->length_expr); + return; + } + case AST_EXPR_VEC_REPEAT_NEW: { + ast_vec_repeat_new_t *repeat_new = expr->value; + global_eval_precheck_expr(m, &repeat_new->default_element); + global_eval_precheck_expr(m, &repeat_new->length_expr); + return; + } + case AST_EXPR_VEC_NEW: { + ast_vec_new_t *vec_new = expr->value; + for (int i = 0; i < vec_new->elements->length; ++i) { + ast_expr_t *item = ct_list_value(vec_new->elements, i); + global_eval_precheck_expr(m, item); + } + return; + } + case AST_EXPR_MAP_NEW: { + ast_map_new_t *map_new = expr->value; + for (int i = 0; i < map_new->elements->length; ++i) { + ast_map_element_t *item = ct_list_value(map_new->elements, i); + global_eval_precheck_expr(m, &item->key); + global_eval_precheck_expr(m, &item->value); + } + return; + } + case AST_EXPR_SET_NEW: { + ast_set_new_t *set_new = expr->value; + for (int i = 0; i < set_new->elements->length; ++i) { + ast_expr_t *item = ct_list_value(set_new->elements, i); + global_eval_precheck_expr(m, item); + } + return; + } + case AST_EXPR_TUPLE_NEW: { + ast_tuple_new_t *tuple_new = expr->value; + for (int i = 0; i < tuple_new->elements->length; ++i) { + ast_expr_t *item = ct_list_value(tuple_new->elements, i); + global_eval_precheck_expr(m, item); + } + return; + } + case AST_EXPR_STRUCT_NEW: { + ast_struct_new_t *struct_new = expr->value; + for (int i = 0; i < struct_new->properties->length; ++i) { + struct_property_t *property = ct_list_value(struct_new->properties, i); + global_eval_precheck_expr(m, property->right); + } + return; + } + case AST_EXPR_IDENT: { + ast_ident *ident = expr->value; + symbol_t *symbol = symbol_table_get_noref(ident->literal); + INFER_ASSERTF(symbol, "ident '%s' undeclared", ident->literal); + INFER_ASSERTF(symbol->type != SYMBOL_VAR, "global initializer cannot reference global var '%s'", + ident->literal); + INFER_ASSERTF(false, "global initializer cannot reference ident '%s'", ident->literal); + return; + } + default: + INFER_ASSERTF(false, "global initializer expression type=%d is not compile-time evaluable", + expr->assert_type); + return; + } +} + +static void global_eval_write_default(type_t t, uint8_t *dst) { + if (t.storage_size > 0) { + memset(dst, 0, t.storage_size); + } + + if (t.kind == TYPE_STRING) { + n_string_t *str = (n_string_t *) dst; + str->element_size = type_kind_sizeof(TYPE_UINT8); + str->hash = type_hash(t); + return; + } + + if (t.kind == TYPE_VEC) { + n_vec_t *vec = (n_vec_t *) dst; + vec->element_size = t.vec->element_type.storage_size; + vec->hash = type_hash(t); + return; + } + + if (t.kind == TYPE_MAP) { + n_map_t *map = (n_map_t *) dst; + map->key_rtype_hash = (uint64_t) type_hash(t.map->key_type); + map->value_rtype_hash = (uint64_t) type_hash(t.map->value_type); + return; + } + + if (t.kind == TYPE_SET) { + n_set_t *set = (n_set_t *) dst; + set->key_rtype_hash = (uint64_t) type_hash(t.set->element_type); + return; + } + + if (t.kind == TYPE_ARR) { + int64_t element_size = t.array->element_type.storage_size; + for (int64_t i = 0; i < t.array->length; ++i) { + global_eval_write_default(t.array->element_type, dst + i * element_size); + } + return; + } + + if (t.kind == TYPE_TUPLE) { + for (int i = 0; i < t.tuple->elements->length; ++i) { + type_t *element_type = ct_list_value(t.tuple->elements, i); + int64_t offset = type_tuple_offset(t.tuple, i); + global_eval_write_default(*element_type, dst + offset); + } + return; + } + + if (t.kind == TYPE_STRUCT) { + for (int i = 0; i < t.struct_->properties->length; ++i) { + struct_property_t *property = ct_list_value(t.struct_->properties, i); + uint64_t offset = type_struct_offset(t.struct_, property->name); + global_eval_write_default(property->type, dst + offset); + } + } +} + +static bool global_eval_literal_as_bool(module_t *m, ast_literal_t *literal) { + if (literal->kind == TYPE_BOOL) { + return str_equal(literal->value, "true"); + } + + if (is_integer_or_anyptr(literal->kind)) { + char *endptr; + uint64_t v = strtoull(literal->value, &endptr, 0); + INFER_ASSERTF(*endptr == '\0', "invalid integer literal '%s'", literal->value); + return v != 0; + } + + if (is_float(literal->kind)) { + char *endptr; + double v = strtod(literal->value, &endptr); + INFER_ASSERTF(*endptr == '\0', "invalid float literal '%s'", literal->value); + return v != 0.0; + } + + INFER_ASSERTF(false, "cannot cast literal kind '%s' to bool", type_kind_str[literal->kind]); + return false; +} + +static int64_t global_eval_literal_as_i64(module_t *m, ast_literal_t *literal) { + if (literal->kind == TYPE_BOOL) { + return str_equal(literal->value, "true") ? 1 : 0; + } + + if (is_signed(literal->kind)) { + char *endptr; + int64_t v = strtoll(literal->value, &endptr, 0); + INFER_ASSERTF(*endptr == '\0', "invalid integer literal '%s'", literal->value); + return v; + } + + if (is_unsigned(literal->kind) || literal->kind == TYPE_ANYPTR) { + char *endptr; + uint64_t v = strtoull(literal->value, &endptr, 0); + INFER_ASSERTF(*endptr == '\0', "invalid integer literal '%s'", literal->value); + return (int64_t) v; + } + + if (is_float(literal->kind)) { + char *endptr; + double v = strtod(literal->value, &endptr); + INFER_ASSERTF(*endptr == '\0', "invalid float literal '%s'", literal->value); + return (int64_t) v; + } + + INFER_ASSERTF(false, "cannot cast literal kind '%s' to integer", type_kind_str[literal->kind]); + return 0; +} + +static uint64_t global_eval_literal_as_u64(module_t *m, ast_literal_t *literal) { + if (literal->kind == TYPE_BOOL) { + return str_equal(literal->value, "true") ? 1 : 0; + } + + if (is_unsigned(literal->kind) || literal->kind == TYPE_ANYPTR) { + char *endptr; + uint64_t v = strtoull(literal->value, &endptr, 0); + INFER_ASSERTF(*endptr == '\0', "invalid integer literal '%s'", literal->value); + return v; + } + + if (is_signed(literal->kind)) { + char *endptr; + int64_t v = strtoll(literal->value, &endptr, 0); + INFER_ASSERTF(*endptr == '\0', "invalid integer literal '%s'", literal->value); + return (uint64_t) v; + } + + if (is_float(literal->kind)) { + char *endptr; + double v = strtod(literal->value, &endptr); + INFER_ASSERTF(*endptr == '\0', "invalid float literal '%s'", literal->value); + return (uint64_t) v; + } + + INFER_ASSERTF(false, "cannot cast literal kind '%s' to integer", type_kind_str[literal->kind]); + return 0; +} + +static double global_eval_literal_as_f64(module_t *m, ast_literal_t *literal) { + if (literal->kind == TYPE_BOOL) { + return str_equal(literal->value, "true") ? 1.0 : 0.0; + } + + if (is_number(literal->kind) || literal->kind == TYPE_ANYPTR) { + char *endptr; + double v = strtod(literal->value, &endptr); + INFER_ASSERTF(*endptr == '\0', "invalid number literal '%s'", literal->value); + return v; + } + + INFER_ASSERTF(false, "cannot cast literal kind '%s' to float", type_kind_str[literal->kind]); + return 0; +} + +static void global_eval_write_literal(module_t *m, type_t target_type, ast_literal_t *literal, uint8_t *dst) { + INFER_ASSERTF(literal != NULL, "global initializer literal is null"); + + if (target_type.kind == TYPE_STRING) { + INFER_ASSERTF(literal->kind == TYPE_STRING, "global string initializer must be string literal"); + INFER_ASSERTF(literal->len == 0, "global string initializer must be empty"); + global_eval_write_default(target_type, dst); + return; + } + + if (target_type.kind == TYPE_BOOL) { + bool value = global_eval_literal_as_bool(m, literal); + memmove(dst, &value, sizeof(bool)); + return; + } + + if (target_type.kind == TYPE_FLOAT32) { + float v = (float) global_eval_literal_as_f64(m, literal); + memmove(dst, &v, sizeof(float)); + return; + } + + if (target_type.kind == TYPE_FLOAT64 || target_type.kind == TYPE_FLOAT) { + double v = global_eval_literal_as_f64(m, literal); + memmove(dst, &v, sizeof(double)); + return; + } + + if (target_type.kind == TYPE_ENUM) { + type_t element_type = reduction_type(m, target_type.enum_->element_type); + global_eval_write_literal(m, element_type, literal, dst); + return; + } + + if (target_type.kind == TYPE_INT8) { + int8_t v = (int8_t) global_eval_literal_as_i64(m, literal); + memmove(dst, &v, sizeof(v)); + return; + } + if (target_type.kind == TYPE_INT16) { + int16_t v = (int16_t) global_eval_literal_as_i64(m, literal); + memmove(dst, &v, sizeof(v)); + return; + } + if (target_type.kind == TYPE_INT32) { + int32_t v = (int32_t) global_eval_literal_as_i64(m, literal); + memmove(dst, &v, sizeof(v)); + return; + } + if (target_type.kind == TYPE_INT64 || target_type.kind == TYPE_INT) { + int64_t v = global_eval_literal_as_i64(m, literal); + memmove(dst, &v, sizeof(v)); + return; + } + if (target_type.kind == TYPE_UINT8) { + uint8_t v = (uint8_t) global_eval_literal_as_u64(m, literal); + memmove(dst, &v, sizeof(v)); + return; + } + if (target_type.kind == TYPE_UINT16) { + uint16_t v = (uint16_t) global_eval_literal_as_u64(m, literal); + memmove(dst, &v, sizeof(v)); + return; + } + if (target_type.kind == TYPE_UINT32) { + uint32_t v = (uint32_t) global_eval_literal_as_u64(m, literal); + memmove(dst, &v, sizeof(v)); + return; + } + if (target_type.kind == TYPE_UINT64 || target_type.kind == TYPE_UINT || target_type.kind == TYPE_ANYPTR) { + uint64_t v = global_eval_literal_as_u64(m, literal); + memmove(dst, &v, sizeof(v)); + return; + } + + if (target_type.kind == TYPE_PTR || target_type.kind == TYPE_REF || target_type.kind == TYPE_FN || + target_type.kind == TYPE_CHAN || target_type.kind == TYPE_COROUTINE_T || target_type.kind == TYPE_NULL) { + bool null_literal = literal->kind == TYPE_NULL; + if (!null_literal && is_integer_or_anyptr(literal->kind)) { + null_literal = global_eval_literal_as_u64(m, literal) == 0; + } + INFER_ASSERTF(null_literal, "pointer-like global initializer must be null"); + memset(dst, 0, target_type.storage_size); + return; + } + + if (target_type.kind == TYPE_UNION && target_type.union_->nullable) { + INFER_ASSERTF(literal->kind == TYPE_NULL, "nullable union global initializer only supports null"); + memset(dst, 0, target_type.storage_size); + return; + } + + INFER_ASSERTF(false, "global initializer cannot assign literal to type '%s'", type_format(target_type)); +} + +static void global_eval_write_expr(module_t *m, type_t target_type, ast_expr_t *expr, uint8_t *dst) { + SET_LINE_COLUMN(expr); + + switch (expr->assert_type) { + case AST_EXPR_LITERAL: { + global_eval_write_literal(m, target_type, expr->value, dst); + return; + } + case AST_EXPR_AS: { + ast_as_expr_t *as_expr = expr->value; + INFER_ASSERTF(as_expr->src.assert_type == AST_EXPR_LITERAL, "global cast initializer must cast a literal"); + global_eval_write_literal(m, target_type, as_expr->src.value, dst); + return; + } + case AST_MACRO_EXPR_DEFAULT: { + global_eval_write_default(target_type, dst); + return; + } + case AST_MACRO_EXPR_REFLECT_HASH: { + ast_macro_reflect_hash_expr_t *reflect_expr = expr->value; + ast_literal_t literal = { + .kind = TYPE_INT, + .value = itoa(type_hash(reflect_expr->target_type)), + .len = 0, + }; + global_eval_write_literal(m, target_type, &literal, dst); + return; + } + case AST_EXPR_ARRAY_NEW: { + INFER_ASSERTF(target_type.kind == TYPE_ARR, "array literal target type mismatch, expect '%s'", + type_format(target_type)); + ast_array_new_t *array_new = expr->value; + INFER_ASSERTF(array_new->elements->length <= target_type.array->length, + "array literal length overflow, expect=%ld, actual=%ld", + target_type.array->length, array_new->elements->length); + + global_eval_write_default(target_type, dst); + int64_t element_size = target_type.array->element_type.storage_size; + for (int64_t i = 0; i < array_new->elements->length; ++i) { + ast_expr_t *item = ct_list_value(array_new->elements, i); + global_eval_write_expr(m, target_type.array->element_type, item, dst + i * element_size); + } + return; + } + case AST_EXPR_ARRAY_REPEAT_NEW: { + INFER_ASSERTF(target_type.kind == TYPE_ARR, "array repeat target type mismatch, expect '%s'", + type_format(target_type)); + ast_array_repeat_new_t *repeat_new = expr->value; + INFER_ASSERTF(repeat_new->length_expr.assert_type == AST_EXPR_LITERAL, + "array repeat length must be compile-time literal"); + ast_literal_t *length_literal = repeat_new->length_expr.value; + int64_t length = global_eval_literal_as_i64(m, length_literal); + INFER_ASSERTF(length == target_type.array->length, + "array repeat length mismatch, expect=%ld, actual=%ld", target_type.array->length, length); + + global_eval_write_default(target_type, dst); + int64_t element_size = target_type.array->element_type.storage_size; + for (int64_t i = 0; i < target_type.array->length; ++i) { + global_eval_write_expr(m, target_type.array->element_type, &repeat_new->default_element, + dst + i * element_size); + } + return; + } + case AST_EXPR_TUPLE_NEW: { + INFER_ASSERTF(target_type.kind == TYPE_TUPLE, "tuple literal target type mismatch, expect '%s'", + type_format(target_type)); + ast_tuple_new_t *tuple_new = expr->value; + INFER_ASSERTF(tuple_new->elements->length == target_type.tuple->elements->length, + "tuple element count mismatch, expect=%ld, actual=%ld", + target_type.tuple->elements->length, tuple_new->elements->length); + global_eval_write_default(target_type, dst); + for (int i = 0; i < target_type.tuple->elements->length; ++i) { + type_t *element_type = ct_list_value(target_type.tuple->elements, i); + int64_t offset = type_tuple_offset(target_type.tuple, i); + ast_expr_t *item = ct_list_value(tuple_new->elements, i); + global_eval_write_expr(m, *element_type, item, dst + offset); + } + return; + } + case AST_EXPR_STRUCT_NEW: { + INFER_ASSERTF(target_type.kind == TYPE_STRUCT, "struct literal target type mismatch, expect '%s'", + type_format(target_type)); + ast_struct_new_t *struct_new = expr->value; + global_eval_write_default(target_type, dst); + for (int i = 0; i < struct_new->properties->length; ++i) { + struct_property_t *property = ct_list_value(struct_new->properties, i); + struct_property_t *expect_property = type_struct_property(target_type.struct_, property->name); + INFER_ASSERTF(expect_property, "struct field '%s' not found", property->name); + uint64_t offset = type_struct_offset(target_type.struct_, property->name); + global_eval_write_expr(m, expect_property->type, property->right, dst + offset); + } + return; + } + case AST_EXPR_VEC_NEW: { + INFER_ASSERTF(target_type.kind == TYPE_VEC, "vec literal target type mismatch, expect '%s'", + type_format(target_type)); + ast_vec_new_t *vec_new = expr->value; + INFER_ASSERTF(vec_new->elements->length == 0, "global vec initializer must be empty"); + global_eval_write_default(target_type, dst); + return; + } + case AST_EXPR_MAP_NEW: { + INFER_ASSERTF(target_type.kind == TYPE_MAP, "map literal target type mismatch, expect '%s'", + type_format(target_type)); + ast_map_new_t *map_new = expr->value; + INFER_ASSERTF(map_new->elements->length == 0, "global map initializer must be empty"); + global_eval_write_default(target_type, dst); + return; + } + case AST_EXPR_SET_NEW: { + INFER_ASSERTF(target_type.kind == TYPE_SET, "set literal target type mismatch, expect '%s'", + type_format(target_type)); + ast_set_new_t *set_new = expr->value; + INFER_ASSERTF(set_new->elements->length == 0, "global set initializer must be empty"); + global_eval_write_default(target_type, dst); + return; + } + case AST_EXPR_EMPTY_CURLY_NEW: { + INFER_ASSERTF(target_type.kind == TYPE_MAP || target_type.kind == TYPE_SET, + "{} only supports map/set global initializer"); + global_eval_write_default(target_type, dst); + return; + } + case AST_EXPR_UNARY: + case AST_EXPR_BINARY: + case AST_EXPR_TERNARY: + INFER_ASSERTF(false, "global initializer must fold to literal before layout"); + return; + default: + INFER_ASSERTF(false, "global initializer expression type=%d is unsupported", expr->assert_type); + return; + } +} + +void global_eval(module_t *m) { + for (int i = 0; i < m->global_vardef->count; ++i) { + ast_vardef_stmt_t *vardef = m->global_vardef->take[i]; + ast_var_decl_t *var_decl = &vardef->var_decl; + + INFER_ASSERTF(vardef->right != NULL, "global var '%s' must have initializer", var_decl->ident); + + SET_LINE_COLUMN(vardef->right); + global_eval_precheck_expr(m, vardef->right); + + var_decl->type = reduction_type(m, var_decl->type); + INFER_ASSERTF(var_decl->type.kind != TYPE_VOID, "cannot assign to void"); + + type_t right_type = infer_global_expr(m, vardef->right, var_decl->type); + INFER_ASSERTF(right_type.kind != TYPE_VOID, "cannot assign void to global var"); + + if (var_decl->type.kind == TYPE_UNKNOWN) { + INFER_ASSERTF(global_type_confirmed(right_type), "global right type not confirmed"); + var_decl->type = right_type; + } + + var_decl->type = reduction_type(m, var_decl->type); + INFER_ASSERTF(global_type_confirmed(var_decl->type), "global type not confirmed"); + + vardef->global_data = mallocz(var_decl->type.storage_size); + global_eval_write_expr(m, var_decl->type, vardef->right, vardef->global_data); + } +} diff --git a/src/semantic/global_eval.h b/src/semantic/global_eval.h new file mode 100644 index 00000000..0f007b6f --- /dev/null +++ b/src/semantic/global_eval.h @@ -0,0 +1,8 @@ +#ifndef NATURE_SRC_SEMANTIC_GLOBAL_EVAL_H_ +#define NATURE_SRC_SEMANTIC_GLOBAL_EVAL_H_ + +#include "src/types.h" + +void global_eval(module_t *m); + +#endif // NATURE_SRC_SEMANTIC_GLOBAL_EVAL_H_ diff --git a/src/semantic/infer.c b/src/semantic/infer.c index ce86ed6e..3ca1dbee 100644 --- a/src/semantic/infer.c +++ b/src/semantic/infer.c @@ -3698,6 +3698,14 @@ static type_t infer_right_expr(module_t *m, ast_expr_t *expr, type_t target_type return expr->type; } +type_t infer_global_expr(module_t *m, ast_expr_t *expr, type_t target_type) { + ast_fndef_t *saved_fn = m->current_fn; + m->current_fn = NULL; + type_t result = infer_right_expr(m, expr, target_type); + m->current_fn = saved_fn; + return result; +} + static type_t reduction_struct(module_t *m, type_t t) { INFER_ASSERTF(t.kind == TYPE_STRUCT, "type kind=%s unexpect", type_format(t)); @@ -4641,11 +4649,6 @@ void pre_infer(module_t *m) { } } - // 这是为了完成自动推断, global ident 的自动推断,相关推断都在 fn_init 中完成。 - if (m->fn_init) { - infer_fndef(m->fn_init->module, m->fn_init); - } - // - TODO 遍历 all typedefs 进行处理, 包括 reduction + rtype push. } diff --git a/src/semantic/infer.h b/src/semantic/infer.h index f5183195..db2a5869 100644 --- a/src/semantic/infer.h +++ b/src/semantic/infer.h @@ -12,6 +12,8 @@ void pre_infer(module_t *m); void infer(module_t *m); +type_t infer_global_expr(module_t *m, ast_expr_t *expr, type_t target_type); + static type_t infer_fn_decl(module_t *m, ast_fndef_t *fndef, type_t target_type); static void infer_stmt(module_t *m, ast_stmt_t *stmt); diff --git a/std/crypto/bcrypt.n b/std/crypto/bcrypt.n index bfb62779..94ca5f22 100644 --- a/std/crypto/bcrypt.n +++ b/std/crypto/bcrypt.n @@ -24,7 +24,8 @@ const NINE_CHAR = 57 // '9' const ALPHABET = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" // Magic cipher data - big-endian bytes of "OrpheanBeholderScryDoubt" -[u8] MAGIC_CIPHER_DATA = [ +const MAGIC_CIPHER_COUNT = 24 +[u8;MAGIC_CIPHER_COUNT] MAGIC_CIPHER_DATA = [ 0x4f, 0x72, 0x70, 0x68, 0x65, 0x61, 0x6e, 0x42, 0x65, 0x68, 0x6f, 0x6c, @@ -203,8 +204,8 @@ fn expensive_blowfish_setup([u8] key, u32 cost, [u8] salt):blowfish.cipher_t! { // bcrypt core function fn bcrypt([u8] password, int cost, [u8] salt):[u8]! { [u8] cipher_data = [] - for i, v in MAGIC_CIPHER_DATA { - cipher_data.push(v) + for int i = 0; i < MAGIC_CIPHER_COUNT; i+= 1 { + cipher_data.push(MAGIC_CIPHER_DATA[i]) } blowfish.cipher_t c = expensive_blowfish_setup(password, cost as u32, salt) diff --git a/std/crypto/blowfish.n b/std/crypto/blowfish.n index 8514ab18..0fa5bda3 100644 --- a/std/crypto/blowfish.n +++ b/std/crypto/blowfish.n @@ -19,14 +19,14 @@ type cipher_t = struct { } // Initial P array (hexadecimal digits from π) -[u32] initial_p = [ +[u32;18] initial_p = [ 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b, ] // Initial S-box 0 -[u32] initial_s0 = [ +[u32;300] initial_s0 = [ 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658, @@ -73,7 +73,7 @@ type cipher_t = struct { ] // Initial S-box 1 -[u32] initial_s1 = [ +[u32;300] initial_s1 = [ 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, 0x3f54989a, 0x5b429d65, @@ -120,7 +120,7 @@ type cipher_t = struct { ] // Initial S-box 2 -[u32] initial_s2 = [ +[u32;300] initial_s2 = [ 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, 0x4d95fc1d, 0x96b591af, @@ -167,7 +167,7 @@ type cipher_t = struct { ] // Initial S-box 3 -[u32] initial_s3 = [ +[u32;300] initial_s3 = [ 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 0x5748ab2f, 0xbc946e79, diff --git a/std/http/main.n b/std/http/main.n index 9e7faf67..18328e37 100644 --- a/std/http/main.n +++ b/std/http/main.n @@ -62,13 +62,13 @@ int ROUTES_OPTIONS = 5 int ROUTES_HEAD = 6 int ROUTES_ALL = 7 -var HTTP_VERSION = 'HTTP/1.1' -var HTTP_MSG_OK = 'OK' +const HTTP_VERSION = 'HTTP/1.1' +const HTTP_MSG_OK = 'OK' -var MIME_TEXT = 'text/plain' -var MIME_JSON = 'application/json' -var separation = '\r\n' as anyptr as [u8] -var separation2 = '\r\n\r\n' as anyptr as [u8] +const MIME_TEXT = 'text/plain' +const MIME_JSON = 'application/json' +const separation = '\r\n' +const separation2 = '\r\n\r\n' type callback_fn = fn(request_t, ref):void! @@ -262,25 +262,25 @@ fn response_t.to_str(&self):string { buf.append(utils.status_to_str(self.status) as anyptr as [u8]) buf.push(space_ascii) buf.append(self.message as anyptr as [u8]) - buf.append(separation) + buf.append(separation as [u8]) var header_len = self.headers.len() for k, v in self.headers { buf.append(k as anyptr as anyptr as [u8]) buf.append(': ' as anyptr as anyptr as [u8]) buf.append(v as anyptr as anyptr as [u8]) - buf.append(separation) + buf.append(separation as [u8]) } buf.append('Content-Length: ' as anyptr as [u8]) buf.append(utils.utos(self.length as uint) as anyptr as [u8]) - buf.append(separation) + buf.append(separation as [u8]) buf.append('Content-Type: ' as anyptr as [u8]) buf.append(self.content_type as anyptr as [u8]) buf.append('; charset=utf-8' as anyptr as [u8]) - buf.append(separation2) + buf.append(separation2 as [u8]) buf.append(self.body as anyptr as [u8]) return buf as anyptr as string diff --git a/std/json/main.n b/std/json/main.n index 79d13b3b..9f930c0a 100644 --- a/std/json/main.n +++ b/std/json/main.n @@ -560,10 +560,6 @@ fn deserialize_t.parser_nullable(&self, anyptr p, ref t):void! { var rv = p as ptr - // TODO 如果转换为 union,并且还需要足够的空间的 union? 并且能够被 gc mark。 - // 当前的 - - // default is null if self.data[self.cursor] == 'n'[0] { self.must('null') @@ -588,9 +584,6 @@ fn deserialize_t.parser_nullable(&self, anyptr p, ref t):void! { var value_type = reflect.typeof_hash(target_type.hashes[1]) runtime.map_new_out(&rv.value as anyptr, hash, key_type.hash, value_type.hash) } - reflect.STRUCT -> { - rv.value = runtime.gc_malloc(hash) - } reflect.STRING -> { runtime.vec_new_out(&rv.value as anyptr, hash, @reflect_hash(u8), 0) } diff --git a/std/syscall/main.darwin.n b/std/syscall/main.darwin.n index 45c710f6..458815d2 100644 --- a/std/syscall/main.darwin.n +++ b/std/syscall/main.darwin.n @@ -26,452 +26,452 @@ int STDOUT = 1 int STDERR = 2 // Darwin系统调用编号 -int SYS_SYSCALL = 0 -int SYS_EXIT = 1 -int SYS_FORK = 2 -int SYS_READ = 3 -int SYS_WRITE = 4 -int SYS_OPEN = 5 -int SYS_CLOSE = 6 -int SYS_WAIT4 = 7 -int SYS_LINK = 9 -int SYS_UNLINK = 10 -int SYS_CHDIR = 12 -int SYS_FCHDIR = 13 -int SYS_MKNOD = 14 -int SYS_CHMOD = 15 -int SYS_CHOWN = 16 -int SYS_GETFSSTAT = 18 -int SYS_GETPID = 20 -int SYS_SETUID = 23 -int SYS_GETUID = 24 -int SYS_GETEUID = 25 -int SYS_PTRACE = 26 -int SYS_RECVMSG = 27 -int SYS_SENDMSG = 28 -int SYS_RECVFROM = 29 -int SYS_ACCEPT = 30 -int SYS_GETPEERNAME = 31 -int SYS_GETSOCKNAME = 32 -int SYS_ACCESS = 33 -int SYS_CHFLAGS = 34 -int SYS_FCHFLAGS = 35 -int SYS_SYNC = 36 -int SYS_KILL = 37 -int SYS_GETPPID = 39 -int SYS_DUP = 41 -int SYS_PIPE = 42 -int SYS_GETEGID = 43 -int SYS_SIGACTION = 46 -int SYS_GETGID = 47 -int SYS_SIGPROCMASK = 48 -int SYS_GETLOGIN = 49 -int SYS_SETLOGIN = 50 -int SYS_ACCT = 51 -int SYS_SIGPENDING = 52 -int SYS_SIGALTSTACK = 53 -int SYS_IOCTL = 54 -int SYS_REBOOT = 55 -int SYS_REVOKE = 56 -int SYS_SYMLINK = 57 -int SYS_READLINK = 58 -int SYS_EXECVE = 59 -int SYS_UMASK = 60 -int SYS_CHROOT = 61 -int SYS_MSYNC = 65 -int SYS_VFORK = 66 -int SYS_MUNMAP = 73 -int SYS_MPROTECT = 74 -int SYS_MADVISE = 75 -int SYS_MINCORE = 78 -int SYS_GETGROUPS = 79 -int SYS_SETGROUPS = 80 -int SYS_GETPGRP = 81 -int SYS_SETPGID = 82 -int SYS_SETITIMER = 83 -int SYS_SWAPON = 85 -int SYS_GETITIMER = 86 -int SYS_GETDTABLESIZE = 89 -int SYS_DUP2 = 90 -int SYS_FCNTL = 92 -int SYS_SELECT = 93 -int SYS_FSYNC = 95 -int SYS_SETPRIORITY = 96 -int SYS_SOCKET = 97 -int SYS_CONNECT = 98 -int SYS_GETPRIORITY = 100 -int SYS_BIND = 104 -int SYS_SETSOCKOPT = 105 -int SYS_LISTEN = 106 -int SYS_SIGSUSPEND = 111 -int SYS_GETTIMEOFDAY = 116 -int SYS_GETRUSAGE = 117 -int SYS_GETSOCKOPT = 118 -int SYS_READV = 120 -int SYS_WRITEV = 121 -int SYS_SETTIMEOFDAY = 122 -int SYS_FCHOWN = 123 -int SYS_FCHMOD = 124 -int SYS_SETREUID = 126 -int SYS_SETREGID = 127 -int SYS_RENAME = 128 -int SYS_FLOCK = 131 -int SYS_MKFIFO = 132 -int SYS_SENDTO = 133 -int SYS_SHUTDOWN = 134 -int SYS_SOCKETPAIR = 135 -int SYS_MKDIR = 136 -int SYS_RMDIR = 137 -int SYS_UTIMES = 138 -int SYS_FUTIMES = 139 -int SYS_ADJTIME = 140 -int SYS_GETHOSTUUID = 142 -int SYS_SETSID = 147 -int SYS_GETPGID = 151 -int SYS_SETPRIVEXEC = 152 -int SYS_PREAD = 153 -int SYS_PWRITE = 154 -int SYS_NFSSVC = 155 -int SYS_STATFS = 157 -int SYS_FSTATFS = 158 -int SYS_UNMOUNT = 159 -int SYS_GETFH = 161 -int SYS_QUOTACTL = 165 -int SYS_MOUNT = 167 -int SYS_CSOPS = 169 -int SYS_CSOPS_AUDITTOKEN = 170 -int SYS_WAITID = 173 -int SYS_KDEBUG_TYPEFILTER = 177 -int SYS_KDEBUG_TRACE_STRING = 178 -int SYS_KDEBUG_TRACE64 = 179 -int SYS_KDEBUG_TRACE = 180 -int SYS_SETGID = 181 -int SYS_SETEGID = 182 -int SYS_SETEUID = 183 -int SYS_SIGRETURN = 184 -int SYS_THREAD_SELFCOUNTS = 186 -int SYS_FDATASYNC = 187 -int SYS_STAT = 188 -int SYS_FSTAT = 189 -int SYS_LSTAT = 190 -int SYS_PATHCONF = 191 -int SYS_FPATHCONF = 192 -int SYS_GETRLIMIT = 194 -int SYS_SETRLIMIT = 195 -int SYS_GETDIRENTRIES = 196 -int SYS_MMAP = 197 -int SYS_LSEEK = 199 -int SYS_TRUNCATE = 200 -int SYS_FTRUNCATE = 201 -int SYS_SYSCTL = 202 -int SYS_MLOCK = 203 -int SYS_MUNLOCK = 204 -int SYS_UNDELETE = 205 -int SYS_OPEN_DPROTECTED_NP = 216 -int SYS_FSGETPATH_EXT = 217 -int SYS_GETATTRLIST = 220 -int SYS_SETATTRLIST = 221 -int SYS_GETDIRENTRIESATTR = 222 -int SYS_EXCHANGEDATA = 223 -int SYS_SEARCHFS = 225 -int SYS_DELETE = 226 -int SYS_COPYFILE = 227 -int SYS_FGETATTRLIST = 228 -int SYS_FSETATTRLIST = 229 -int SYS_POLL = 230 -int SYS_GETXATTR = 234 -int SYS_FGETXATTR = 235 -int SYS_SETXATTR = 236 -int SYS_FSETXATTR = 237 -int SYS_REMOVEXATTR = 238 -int SYS_FREMOVEXATTR = 239 -int SYS_LISTXATTR = 240 -int SYS_FLISTXATTR = 241 -int SYS_FSCTL = 242 -int SYS_INITGROUPS = 243 -int SYS_POSIX_SPAWN = 244 -int SYS_FFSCTL = 245 -int SYS_NFSCLNT = 247 -int SYS_FHOPEN = 248 -int SYS_MINHERIT = 250 -int SYS_SEMSYS = 251 -int SYS_MSGSYS = 252 -int SYS_SHMSYS = 253 -int SYS_SEMCTL = 254 -int SYS_SEMGET = 255 -int SYS_SEMOP = 256 -int SYS_MSGCTL = 258 -int SYS_MSGGET = 259 -int SYS_MSGSND = 260 -int SYS_MSGRCV = 261 -int SYS_SHMAT = 262 -int SYS_SHMCTL = 263 -int SYS_SHMDT = 264 -int SYS_SHMGET = 265 -int SYS_SHM_OPEN = 266 -int SYS_SHM_UNLINK = 267 -int SYS_SEM_OPEN = 268 -int SYS_SEM_CLOSE = 269 -int SYS_SEM_UNLINK = 270 -int SYS_SEM_WAIT = 271 -int SYS_SEM_TRYWAIT = 272 -int SYS_SEM_POST = 273 -int SYS_SYSCTLBYNAME = 274 -int SYS_OPEN_EXTENDED = 277 -int SYS_UMASK_EXTENDED = 278 -int SYS_STAT_EXTENDED = 279 -int SYS_LSTAT_EXTENDED = 280 -int SYS_FSTAT_EXTENDED = 281 -int SYS_CHMOD_EXTENDED = 282 -int SYS_FCHMOD_EXTENDED = 283 -int SYS_ACCESS_EXTENDED = 284 -int SYS_SETTID = 285 -int SYS_GETTID = 286 -int SYS_SETSGROUPS = 287 -int SYS_GETSGROUPS = 288 -int SYS_SETWGROUPS = 289 -int SYS_GETWGROUPS = 290 -int SYS_MKFIFO_EXTENDED = 291 -int SYS_MKDIR_EXTENDED = 292 -int SYS_IDENTITYSVC = 293 -int SYS_SHARED_REGION_CHECK_NP = 294 -int SYS_VM_PRESSURE_MONITOR = 296 -int SYS_PSYNCH_RW_LONGRDLOCK = 297 -int SYS_PSYNCH_RW_YIELDWRLOCK = 298 -int SYS_PSYNCH_RW_DOWNGRADE = 299 -int SYS_PSYNCH_RW_UPGRADE = 300 -int SYS_PSYNCH_MUTEXWAIT = 301 -int SYS_PSYNCH_MUTEXDROP = 302 -int SYS_PSYNCH_CVBROAD = 303 -int SYS_PSYNCH_CVSIGNAL = 304 -int SYS_PSYNCH_CVWAIT = 305 -int SYS_PSYNCH_RW_RDLOCK = 306 -int SYS_PSYNCH_RW_WRLOCK = 307 -int SYS_PSYNCH_RW_UNLOCK = 308 -int SYS_PSYNCH_RW_UNLOCK2 = 309 -int SYS_GETSID = 310 -int SYS_SETTID_WITH_PID = 311 -int SYS_PSYNCH_CVCLRPREPOST = 312 -int SYS_AIO_FSYNC = 313 -int SYS_AIO_RETURN = 314 -int SYS_AIO_SUSPEND = 315 -int SYS_AIO_CANCEL = 316 -int SYS_AIO_ERROR = 317 -int SYS_AIO_READ = 318 -int SYS_AIO_WRITE = 319 -int SYS_LIO_LISTIO = 320 -int SYS_IOPOLICYSYS = 322 -int SYS_PROCESS_POLICY = 323 -int SYS_MLOCKALL = 324 -int SYS_MUNLOCKALL = 325 -int SYS_ISSETUGID = 327 -int SYS___PTHREAD_KILL = 328 -int SYS___PTHREAD_SIGMASK = 329 -int SYS___SIGWAIT = 330 -int SYS___DISABLE_THREADSIGNAL = 331 -int SYS___PTHREAD_MARKCANCEL = 332 -int SYS___PTHREAD_CANCELED = 333 -int SYS___SEMWAIT_SIGNAL = 334 -int SYS_PROC_INFO = 336 -int SYS_SENDFILE = 337 -int SYS_STAT64 = 338 -int SYS_FSTAT64 = 339 -int SYS_LSTAT64 = 340 -int SYS_STAT64_EXTENDED = 341 -int SYS_LSTAT64_EXTENDED = 342 -int SYS_FSTAT64_EXTENDED = 343 -int SYS_GETDIRENTRIES64 = 344 -int SYS_STATFS64 = 345 -int SYS_FSTATFS64 = 346 -int SYS_GETFSSTAT64 = 347 -int SYS___PTHREAD_CHDIR = 348 -int SYS___PTHREAD_FCHDIR = 349 -int SYS_AUDIT = 350 -int SYS_AUDITON = 351 -int SYS_GETAUID = 353 -int SYS_SETAUID = 354 -int SYS_GETAUDIT_ADDR = 357 -int SYS_SETAUDIT_ADDR = 358 -int SYS_AUDITCTL = 359 -int SYS_BSDTHREAD_CREATE = 360 -int SYS_BSDTHREAD_TERMINATE = 361 -int SYS_KQUEUE = 362 -int SYS_KEVENT = 363 -int SYS_LCHOWN = 364 -int SYS_BSDTHREAD_REGISTER = 366 -int SYS_WORKQ_OPEN = 367 -int SYS_WORKQ_KERNRETURN = 368 -int SYS_KEVENT64 = 369 -int SYS___OLD_SEMWAIT_SIGNAL = 370 -int SYS___OLD_SEMWAIT_SIGNAL_NOCANCEL = 371 -int SYS_THREAD_SELFID = 372 -int SYS_LEDGER = 373 -int SYS_KEVENT_QOS = 374 -int SYS_KEVENT_ID = 375 - -int SYS___MAC_EXECVE = 380 -int SYS___MAC_SYSCALL = 381 -int SYS___MAC_GET_FILE = 382 -int SYS___MAC_SET_FILE = 383 -int SYS___MAC_GET_LINK = 384 -int SYS___MAC_SET_LINK = 385 -int SYS___MAC_GET_PROC = 386 -int SYS___MAC_SET_PROC = 387 -int SYS___MAC_GET_FD = 388 -int SYS___MAC_SET_FD = 389 -int SYS___MAC_GET_PID = 390 -int SYS_PSELECT = 394 - -int SYS_PSELECT_NOCANCEL = 395 -int SYS_READ_NOCANCEL = 396 -int SYS_WRITE_NOCANCEL = 397 -int SYS_OPEN_NOCANCEL = 398 -int SYS_CLOSE_NOCANCEL = 399 -int SYS_WAIT4_NOCANCEL = 400 -int SYS_RECVMSG_NOCANCEL = 401 -int SYS_SENDMSG_NOCANCEL = 402 -int SYS_RECVFROM_NOCANCEL = 403 -int SYS_ACCEPT_NOCANCEL = 404 -int SYS_MSYNC_NOCANCEL = 405 -int SYS_FCNTL_NOCANCEL = 406 -int SYS_SELECT_NOCANCEL = 407 -int SYS_FSYNC_NOCANCEL = 408 -int SYS_CONNECT_NOCANCEL = 409 -int SYS_SIGSUSPEND_NOCANCEL = 410 -int SYS_READV_NOCANCEL = 411 -int SYS_WRITEV_NOCANCEL = 412 -int SYS_SENDTO_NOCANCEL = 413 -int SYS_PREAD_NOCANCEL = 414 -int SYS_PWRITE_NOCANCEL = 415 -int SYS_WAITID_NOCANCEL = 416 -int SYS_POLL_NOCANCEL = 417 -int SYS_MSGSND_NOCANCEL = 418 -int SYS_MSGRCV_NOCANCEL = 419 -int SYS_SEM_WAIT_NOCANCEL = 420 -int SYS_AIO_SUSPEND_NOCANCEL = 421 -int SYS___SIGWAIT_NOCANCEL = 422 -int SYS___SEMWAIT_SIGNAL_NOCANCEL = 423 -int SYS___MAC_MOUNT = 424 -int SYS___MAC_GET_MOUNT = 425 -int SYS___MAC_GETFSSTAT = 426 -int SYS_FSGETPATH = 427 -int SYS_AUDIT_SESSION_SELF = 428 -int SYS_AUDIT_SESSION_JOIN = 429 -int SYS_FILEPORT_MAKEPORT = 430 -int SYS_FILEPORT_MAKEFD = 431 -int SYS_AUDIT_SESSION_PORT = 432 -int SYS_PID_SUSPEND = 433 -int SYS_PID_RESUME = 434 -int SYS_PID_HIBERNATE = 435 -int SYS_PID_SHUTDOWN_SOCKETS = 436 -int SYS_SHARED_REGION_MAP_AND_SLIDE_NP = 438 -int SYS_KAS_INFO = 439 -int SYS_MEMORYSTATUS_CONTROL = 440 -int SYS_GUARDED_OPEN_NP = 441 -int SYS_GUARDED_CLOSE_NP = 442 -int SYS_GUARDED_KQUEUE_NP = 443 -int SYS_CHANGE_FDGUARD_NP = 444 -int SYS_USRCTL = 445 -int SYS_PROC_RLIMIT_CONTROL = 446 -int SYS_CONNECTX = 447 -int SYS_DISCONNECTX = 448 -int SYS_PEELOFF = 449 -int SYS_SOCKET_DELEGATE = 450 -int SYS_TELEMETRY = 451 -int SYS_PROC_UUID_POLICY = 452 -int SYS_MEMORYSTATUS_GET_LEVEL = 453 -int SYS_SYSTEM_OVERRIDE = 454 -int SYS_VFS_PURGE = 455 -int SYS_SFI_CTL = 456 -int SYS_SFI_PIDCTL = 457 -int SYS_COALITION = 458 -int SYS_COALITION_INFO = 459 -int SYS_NECP_MATCH_POLICY = 460 -int SYS_GETATTRLISTBULK = 461 -int SYS_CLONEFILEAT = 462 -int SYS_OPENAT = 463 -int SYS_OPENAT_NOCANCEL = 464 -int SYS_RENAMEAT = 465 -int SYS_FACCESSAT = 466 -int SYS_FCHMODAT = 467 -int SYS_FCHOWNAT = 468 -int SYS_FSTATAT = 469 -int SYS_FSTATAT64 = 470 -int SYS_LINKAT = 471 -int SYS_UNLINKAT = 472 -int SYS_READLINKAT = 473 -int SYS_SYMLINKAT = 474 -int SYS_MKDIRAT = 475 -int SYS_GETATTRLISTAT = 476 -int SYS_PROC_TRACE_LOG = 477 -int SYS_BSDTHREAD_CTL = 478 -int SYS_OPENBYID_NP = 479 -int SYS_RECVMSG_X = 480 -int SYS_SENDMSG_X = 481 -int SYS_THREAD_SELFUSAGE = 482 -int SYS_CSRCTL = 483 -int SYS_GUARDED_OPEN_DPROTECTED_NP = 484 -int SYS_GUARDED_WRITE_NP = 485 -int SYS_GUARDED_PWRITE_NP = 486 -int SYS_GUARDED_WRITEV_NP = 487 -int SYS_RENAMEATX_NP = 488 -int SYS_MREMAP_ENCRYPTED = 489 -int SYS_NETAGENT_TRIGGER = 490 -int SYS_STACK_SNAPSHOT_WITH_CONFIG = 491 -int SYS_MICROSTACKSHOT = 492 -int SYS_GRAB_PGO_DATA = 493 -int SYS_PERSONA = 494 -int SYS_MACH_EVENTLINK_SIGNAL = 496 -int SYS_MACH_EVENTLINK_WAIT_UNTIL = 497 -int SYS_MACH_EVENTLINK_SIGNAL_WAIT_UNTIL = 498 -int SYS_WORK_INTERVAL_CTL = 499 -int SYS_GETENTROPY = 500 -int SYS_NECP_OPEN = 501 -int SYS_NECP_CLIENT_ACTION = 502 -int SYS___NEXUS_OPEN = 503 -int SYS___NEXUS_REGISTER = 504 -int SYS___NEXUS_DEREGISTER = 505 -int SYS___NEXUS_CREATE = 506 -int SYS___NEXUS_DESTROY = 507 -int SYS___NEXUS_GET_OPT = 508 -int SYS___NEXUS_SET_OPT = 509 -int SYS___CHANNEL_OPEN = 510 -int SYS___CHANNEL_GET_INFO = 511 -int SYS___CHANNEL_SYNC = 512 -int SYS___CHANNEL_GET_OPT = 513 -int SYS___CHANNEL_SET_OPT = 514 -int SYS_ULOCK_WAIT = 515 -int SYS_ULOCK_WAKE = 516 -int SYS_FCLONEFILEAT = 517 -int SYS_FS_SNAPSHOT = 518 -int SYS_REGISTER_UEXC_HANDLER = 519 -int SYS_TERMINATE_WITH_PAYLOAD = 520 -int SYS_ABORT_WITH_PAYLOAD = 521 -int SYS_NECP_SESSION_OPEN = 522 -int SYS_NECP_SESSION_ACTION = 523 -int SYS_SETATTRLISTAT = 524 -int SYS_NET_QOS_GUIDELINE = 525 -int SYS_FMOUNT = 526 -int SYS_NTP_ADJTIME = 527 -int SYS_NTP_GETTIME = 528 -int SYS_OS_FAULT_WITH_PAYLOAD = 529 -int SYS_KQUEUE_WORKLOOP_CTL = 530 -int SYS___MACH_BRIDGE_REMOTE_TIME = 531 -int SYS_COALITION_LEDGER = 532 -int SYS_LOG_DATA = 533 -int SYS_MEMORYSTATUS_AVAILABLE_MEMORY = 534 -int SYS_SHARED_REGION_MAP_AND_SLIDE_2_NP = 536 -int SYS_PIVOT_ROOT = 537 -int SYS_TASK_INSPECT_FOR_PID = 538 -int SYS_TASK_READ_FOR_PID = 539 -int SYS_PREADV = 540 -int SYS_PWRITEV = 541 -int SYS_PREADV_NOCANCEL = 542 -int SYS_PWRITEV_NOCANCEL = 543 -int SYS_ULOCK_WAIT2 = 544 -int SYS_PROC_INFO_EXTENDED_ID = 545 -int SYS_MAXSYSCALL = 546 -int SYS_INVALID = 63 +const SYS_SYSCALL = 0 +const SYS_EXIT = 1 +const SYS_FORK = 2 +const SYS_READ = 3 +const SYS_WRITE = 4 +const SYS_OPEN = 5 +const SYS_CLOSE = 6 +const SYS_WAIT4 = 7 +const SYS_LINK = 9 +const SYS_UNLINK = 10 +const SYS_CHDIR = 12 +const SYS_FCHDIR = 13 +const SYS_MKNOD = 14 +const SYS_CHMOD = 15 +const SYS_CHOWN = 16 +const SYS_GETFSSTAT = 18 +const SYS_GETPID = 20 +const SYS_SETUID = 23 +const SYS_GETUID = 24 +const SYS_GETEUID = 25 +const SYS_PTRACE = 26 +const SYS_RECVMSG = 27 +const SYS_SENDMSG = 28 +const SYS_RECVFROM = 29 +const SYS_ACCEPT = 30 +const SYS_GETPEERNAME = 31 +const SYS_GETSOCKNAME = 32 +const SYS_ACCESS = 33 +const SYS_CHFLAGS = 34 +const SYS_FCHFLAGS = 35 +const SYS_SYNC = 36 +const SYS_KILL = 37 +const SYS_GETPPID = 39 +const SYS_DUP = 41 +const SYS_PIPE = 42 +const SYS_GETEGID = 43 +const SYS_SIGACTION = 46 +const SYS_GETGID = 47 +const SYS_SIGPROCMASK = 48 +const SYS_GETLOGIN = 49 +const SYS_SETLOGIN = 50 +const SYS_ACCT = 51 +const SYS_SIGPENDING = 52 +const SYS_SIGALTSTACK = 53 +const SYS_IOCTL = 54 +const SYS_REBOOT = 55 +const SYS_REVOKE = 56 +const SYS_SYMLINK = 57 +const SYS_READLINK = 58 +const SYS_EXECVE = 59 +const SYS_UMASK = 60 +const SYS_CHROOT = 61 +const SYS_MSYNC = 65 +const SYS_VFORK = 66 +const SYS_MUNMAP = 73 +const SYS_MPROTECT = 74 +const SYS_MADVISE = 75 +const SYS_MINCORE = 78 +const SYS_GETGROUPS = 79 +const SYS_SETGROUPS = 80 +const SYS_GETPGRP = 81 +const SYS_SETPGID = 82 +const SYS_SETITIMER = 83 +const SYS_SWAPON = 85 +const SYS_GETITIMER = 86 +const SYS_GETDTABLESIZE = 89 +const SYS_DUP2 = 90 +const SYS_FCNTL = 92 +const SYS_SELECT = 93 +const SYS_FSYNC = 95 +const SYS_SETPRIORITY = 96 +const SYS_SOCKET = 97 +const SYS_CONNECT = 98 +const SYS_GETPRIORITY = 100 +const SYS_BIND = 104 +const SYS_SETSOCKOPT = 105 +const SYS_LISTEN = 106 +const SYS_SIGSUSPEND = 111 +const SYS_GETTIMEOFDAY = 116 +const SYS_GETRUSAGE = 117 +const SYS_GETSOCKOPT = 118 +const SYS_READV = 120 +const SYS_WRITEV = 121 +const SYS_SETTIMEOFDAY = 122 +const SYS_FCHOWN = 123 +const SYS_FCHMOD = 124 +const SYS_SETREUID = 126 +const SYS_SETREGID = 127 +const SYS_RENAME = 128 +const SYS_FLOCK = 131 +const SYS_MKFIFO = 132 +const SYS_SENDTO = 133 +const SYS_SHUTDOWN = 134 +const SYS_SOCKETPAIR = 135 +const SYS_MKDIR = 136 +const SYS_RMDIR = 137 +const SYS_UTIMES = 138 +const SYS_FUTIMES = 139 +const SYS_ADJTIME = 140 +const SYS_GETHOSTUUID = 142 +const SYS_SETSID = 147 +const SYS_GETPGID = 151 +const SYS_SETPRIVEXEC = 152 +const SYS_PREAD = 153 +const SYS_PWRITE = 154 +const SYS_NFSSVC = 155 +const SYS_STATFS = 157 +const SYS_FSTATFS = 158 +const SYS_UNMOUNT = 159 +const SYS_GETFH = 161 +const SYS_QUOTACTL = 165 +const SYS_MOUNT = 167 +const SYS_CSOPS = 169 +const SYS_CSOPS_AUDITTOKEN = 170 +const SYS_WAITID = 173 +const SYS_KDEBUG_TYPEFILTER = 177 +const SYS_KDEBUG_TRACE_STRING = 178 +const SYS_KDEBUG_TRACE64 = 179 +const SYS_KDEBUG_TRACE = 180 +const SYS_SETGID = 181 +const SYS_SETEGID = 182 +const SYS_SETEUID = 183 +const SYS_SIGRETURN = 184 +const SYS_THREAD_SELFCOUNTS = 186 +const SYS_FDATASYNC = 187 +const SYS_STAT = 188 +const SYS_FSTAT = 189 +const SYS_LSTAT = 190 +const SYS_PATHCONF = 191 +const SYS_FPATHCONF = 192 +const SYS_GETRLIMIT = 194 +const SYS_SETRLIMIT = 195 +const SYS_GETDIRENTRIES = 196 +const SYS_MMAP = 197 +const SYS_LSEEK = 199 +const SYS_TRUNCATE = 200 +const SYS_FTRUNCATE = 201 +const SYS_SYSCTL = 202 +const SYS_MLOCK = 203 +const SYS_MUNLOCK = 204 +const SYS_UNDELETE = 205 +const SYS_OPEN_DPROTECTED_NP = 216 +const SYS_FSGETPATH_EXT = 217 +const SYS_GETATTRLIST = 220 +const SYS_SETATTRLIST = 221 +const SYS_GETDIRENTRIESATTR = 222 +const SYS_EXCHANGEDATA = 223 +const SYS_SEARCHFS = 225 +const SYS_DELETE = 226 +const SYS_COPYFILE = 227 +const SYS_FGETATTRLIST = 228 +const SYS_FSETATTRLIST = 229 +const SYS_POLL = 230 +const SYS_GETXATTR = 234 +const SYS_FGETXATTR = 235 +const SYS_SETXATTR = 236 +const SYS_FSETXATTR = 237 +const SYS_REMOVEXATTR = 238 +const SYS_FREMOVEXATTR = 239 +const SYS_LISTXATTR = 240 +const SYS_FLISTXATTR = 241 +const SYS_FSCTL = 242 +const SYS_INITGROUPS = 243 +const SYS_POSIX_SPAWN = 244 +const SYS_FFSCTL = 245 +const SYS_NFSCLNT = 247 +const SYS_FHOPEN = 248 +const SYS_MINHERIT = 250 +const SYS_SEMSYS = 251 +const SYS_MSGSYS = 252 +const SYS_SHMSYS = 253 +const SYS_SEMCTL = 254 +const SYS_SEMGET = 255 +const SYS_SEMOP = 256 +const SYS_MSGCTL = 258 +const SYS_MSGGET = 259 +const SYS_MSGSND = 260 +const SYS_MSGRCV = 261 +const SYS_SHMAT = 262 +const SYS_SHMCTL = 263 +const SYS_SHMDT = 264 +const SYS_SHMGET = 265 +const SYS_SHM_OPEN = 266 +const SYS_SHM_UNLINK = 267 +const SYS_SEM_OPEN = 268 +const SYS_SEM_CLOSE = 269 +const SYS_SEM_UNLINK = 270 +const SYS_SEM_WAIT = 271 +const SYS_SEM_TRYWAIT = 272 +const SYS_SEM_POST = 273 +const SYS_SYSCTLBYNAME = 274 +const SYS_OPEN_EXTENDED = 277 +const SYS_UMASK_EXTENDED = 278 +const SYS_STAT_EXTENDED = 279 +const SYS_LSTAT_EXTENDED = 280 +const SYS_FSTAT_EXTENDED = 281 +const SYS_CHMOD_EXTENDED = 282 +const SYS_FCHMOD_EXTENDED = 283 +const SYS_ACCESS_EXTENDED = 284 +const SYS_SETTID = 285 +const SYS_GETTID = 286 +const SYS_SETSGROUPS = 287 +const SYS_GETSGROUPS = 288 +const SYS_SETWGROUPS = 289 +const SYS_GETWGROUPS = 290 +const SYS_MKFIFO_EXTENDED = 291 +const SYS_MKDIR_EXTENDED = 292 +const SYS_IDENTITYSVC = 293 +const SYS_SHARED_REGION_CHECK_NP = 294 +const SYS_VM_PRESSURE_MONITOR = 296 +const SYS_PSYNCH_RW_LONGRDLOCK = 297 +const SYS_PSYNCH_RW_YIELDWRLOCK = 298 +const SYS_PSYNCH_RW_DOWNGRADE = 299 +const SYS_PSYNCH_RW_UPGRADE = 300 +const SYS_PSYNCH_MUTEXWAIT = 301 +const SYS_PSYNCH_MUTEXDROP = 302 +const SYS_PSYNCH_CVBROAD = 303 +const SYS_PSYNCH_CVSIGNAL = 304 +const SYS_PSYNCH_CVWAIT = 305 +const SYS_PSYNCH_RW_RDLOCK = 306 +const SYS_PSYNCH_RW_WRLOCK = 307 +const SYS_PSYNCH_RW_UNLOCK = 308 +const SYS_PSYNCH_RW_UNLOCK2 = 309 +const SYS_GETSID = 310 +const SYS_SETTID_WITH_PID = 311 +const SYS_PSYNCH_CVCLRPREPOST = 312 +const SYS_AIO_FSYNC = 313 +const SYS_AIO_RETURN = 314 +const SYS_AIO_SUSPEND = 315 +const SYS_AIO_CANCEL = 316 +const SYS_AIO_ERROR = 317 +const SYS_AIO_READ = 318 +const SYS_AIO_WRITE = 319 +const SYS_LIO_LISTIO = 320 +const SYS_IOPOLICYSYS = 322 +const SYS_PROCESS_POLICY = 323 +const SYS_MLOCKALL = 324 +const SYS_MUNLOCKALL = 325 +const SYS_ISSETUGID = 327 +const SYS___PTHREAD_KILL = 328 +const SYS___PTHREAD_SIGMASK = 329 +const SYS___SIGWAIT = 330 +const SYS___DISABLE_THREADSIGNAL = 331 +const SYS___PTHREAD_MARKCANCEL = 332 +const SYS___PTHREAD_CANCELED = 333 +const SYS___SEMWAIT_SIGNAL = 334 +const SYS_PROC_INFO = 336 +const SYS_SENDFILE = 337 +const SYS_STAT64 = 338 +const SYS_FSTAT64 = 339 +const SYS_LSTAT64 = 340 +const SYS_STAT64_EXTENDED = 341 +const SYS_LSTAT64_EXTENDED = 342 +const SYS_FSTAT64_EXTENDED = 343 +const SYS_GETDIRENTRIES64 = 344 +const SYS_STATFS64 = 345 +const SYS_FSTATFS64 = 346 +const SYS_GETFSSTAT64 = 347 +const SYS___PTHREAD_CHDIR = 348 +const SYS___PTHREAD_FCHDIR = 349 +const SYS_AUDIT = 350 +const SYS_AUDITON = 351 +const SYS_GETAUID = 353 +const SYS_SETAUID = 354 +const SYS_GETAUDIT_ADDR = 357 +const SYS_SETAUDIT_ADDR = 358 +const SYS_AUDITCTL = 359 +const SYS_BSDTHREAD_CREATE = 360 +const SYS_BSDTHREAD_TERMINATE = 361 +const SYS_KQUEUE = 362 +const SYS_KEVENT = 363 +const SYS_LCHOWN = 364 +const SYS_BSDTHREAD_REGISTER = 366 +const SYS_WORKQ_OPEN = 367 +const SYS_WORKQ_KERNRETURN = 368 +const SYS_KEVENT64 = 369 +const SYS___OLD_SEMWAIT_SIGNAL = 370 +const SYS___OLD_SEMWAIT_SIGNAL_NOCANCEL = 371 +const SYS_THREAD_SELFID = 372 +const SYS_LEDGER = 373 +const SYS_KEVENT_QOS = 374 +const SYS_KEVENT_ID = 375 + +const SYS___MAC_EXECVE = 380 +const SYS___MAC_SYSCALL = 381 +const SYS___MAC_GET_FILE = 382 +const SYS___MAC_SET_FILE = 383 +const SYS___MAC_GET_LINK = 384 +const SYS___MAC_SET_LINK = 385 +const SYS___MAC_GET_PROC = 386 +const SYS___MAC_SET_PROC = 387 +const SYS___MAC_GET_FD = 388 +const SYS___MAC_SET_FD = 389 +const SYS___MAC_GET_PID = 390 +const SYS_PSELECT = 394 + +const SYS_PSELECT_NOCANCEL = 395 +const SYS_READ_NOCANCEL = 396 +const SYS_WRITE_NOCANCEL = 397 +const SYS_OPEN_NOCANCEL = 398 +const SYS_CLOSE_NOCANCEL = 399 +const SYS_WAIT4_NOCANCEL = 400 +const SYS_RECVMSG_NOCANCEL = 401 +const SYS_SENDMSG_NOCANCEL = 402 +const SYS_RECVFROM_NOCANCEL = 403 +const SYS_ACCEPT_NOCANCEL = 404 +const SYS_MSYNC_NOCANCEL = 405 +const SYS_FCNTL_NOCANCEL = 406 +const SYS_SELECT_NOCANCEL = 407 +const SYS_FSYNC_NOCANCEL = 408 +const SYS_CONNECT_NOCANCEL = 409 +const SYS_SIGSUSPEND_NOCANCEL = 410 +const SYS_READV_NOCANCEL = 411 +const SYS_WRITEV_NOCANCEL = 412 +const SYS_SENDTO_NOCANCEL = 413 +const SYS_PREAD_NOCANCEL = 414 +const SYS_PWRITE_NOCANCEL = 415 +const SYS_WAITID_NOCANCEL = 416 +const SYS_POLL_NOCANCEL = 417 +const SYS_MSGSND_NOCANCEL = 418 +const SYS_MSGRCV_NOCANCEL = 419 +const SYS_SEM_WAIT_NOCANCEL = 420 +const SYS_AIO_SUSPEND_NOCANCEL = 421 +const SYS___SIGWAIT_NOCANCEL = 422 +const SYS___SEMWAIT_SIGNAL_NOCANCEL = 423 +const SYS___MAC_MOUNT = 424 +const SYS___MAC_GET_MOUNT = 425 +const SYS___MAC_GETFSSTAT = 426 +const SYS_FSGETPATH = 427 +const SYS_AUDIT_SESSION_SELF = 428 +const SYS_AUDIT_SESSION_JOIN = 429 +const SYS_FILEPORT_MAKEPORT = 430 +const SYS_FILEPORT_MAKEFD = 431 +const SYS_AUDIT_SESSION_PORT = 432 +const SYS_PID_SUSPEND = 433 +const SYS_PID_RESUME = 434 +const SYS_PID_HIBERNATE = 435 +const SYS_PID_SHUTDOWN_SOCKETS = 436 +const SYS_SHARED_REGION_MAP_AND_SLIDE_NP = 438 +const SYS_KAS_INFO = 439 +const SYS_MEMORYSTATUS_CONTROL = 440 +const SYS_GUARDED_OPEN_NP = 441 +const SYS_GUARDED_CLOSE_NP = 442 +const SYS_GUARDED_KQUEUE_NP = 443 +const SYS_CHANGE_FDGUARD_NP = 444 +const SYS_USRCTL = 445 +const SYS_PROC_RLIMIT_CONTROL = 446 +const SYS_CONNECTX = 447 +const SYS_DISCONNECTX = 448 +const SYS_PEELOFF = 449 +const SYS_SOCKET_DELEGATE = 450 +const SYS_TELEMETRY = 451 +const SYS_PROC_UUID_POLICY = 452 +const SYS_MEMORYSTATUS_GET_LEVEL = 453 +const SYS_SYSTEM_OVERRIDE = 454 +const SYS_VFS_PURGE = 455 +const SYS_SFI_CTL = 456 +const SYS_SFI_PIDCTL = 457 +const SYS_COALITION = 458 +const SYS_COALITION_INFO = 459 +const SYS_NECP_MATCH_POLICY = 460 +const SYS_GETATTRLISTBULK = 461 +const SYS_CLONEFILEAT = 462 +const SYS_OPENAT = 463 +const SYS_OPENAT_NOCANCEL = 464 +const SYS_RENAMEAT = 465 +const SYS_FACCESSAT = 466 +const SYS_FCHMODAT = 467 +const SYS_FCHOWNAT = 468 +const SYS_FSTATAT = 469 +const SYS_FSTATAT64 = 470 +const SYS_LINKAT = 471 +const SYS_UNLINKAT = 472 +const SYS_READLINKAT = 473 +const SYS_SYMLINKAT = 474 +const SYS_MKDIRAT = 475 +const SYS_GETATTRLISTAT = 476 +const SYS_PROC_TRACE_LOG = 477 +const SYS_BSDTHREAD_CTL = 478 +const SYS_OPENBYID_NP = 479 +const SYS_RECVMSG_X = 480 +const SYS_SENDMSG_X = 481 +const SYS_THREAD_SELFUSAGE = 482 +const SYS_CSRCTL = 483 +const SYS_GUARDED_OPEN_DPROTECTED_NP = 484 +const SYS_GUARDED_WRITE_NP = 485 +const SYS_GUARDED_PWRITE_NP = 486 +const SYS_GUARDED_WRITEV_NP = 487 +const SYS_RENAMEATX_NP = 488 +const SYS_MREMAP_ENCRYPTED = 489 +const SYS_NETAGENT_TRIGGER = 490 +const SYS_STACK_SNAPSHOT_WITH_CONFIG = 491 +const SYS_MICROSTACKSHOT = 492 +const SYS_GRAB_PGO_DATA = 493 +const SYS_PERSONA = 494 +const SYS_MACH_EVENTLINK_SIGNAL = 496 +const SYS_MACH_EVENTLINK_WAIT_UNTIL = 497 +const SYS_MACH_EVENTLINK_SIGNAL_WAIT_UNTIL = 498 +const SYS_WORK_INTERVAL_CTL = 499 +const SYS_GETENTROPY = 500 +const SYS_NECP_OPEN = 501 +const SYS_NECP_CLIENT_ACTION = 502 +const SYS___NEXUS_OPEN = 503 +const SYS___NEXUS_REGISTER = 504 +const SYS___NEXUS_DEREGISTER = 505 +const SYS___NEXUS_CREATE = 506 +const SYS___NEXUS_DESTROY = 507 +const SYS___NEXUS_GET_OPT = 508 +const SYS___NEXUS_SET_OPT = 509 +const SYS___CHANNEL_OPEN = 510 +const SYS___CHANNEL_GET_INFO = 511 +const SYS___CHANNEL_SYNC = 512 +const SYS___CHANNEL_GET_OPT = 513 +const SYS___CHANNEL_SET_OPT = 514 +const SYS_ULOCK_WAIT = 515 +const SYS_ULOCK_WAKE = 516 +const SYS_FCLONEFILEAT = 517 +const SYS_FS_SNAPSHOT = 518 +const SYS_REGISTER_UEXC_HANDLER = 519 +const SYS_TERMINATE_WITH_PAYLOAD = 520 +const SYS_ABORT_WITH_PAYLOAD = 521 +const SYS_NECP_SESSION_OPEN = 522 +const SYS_NECP_SESSION_ACTION = 523 +const SYS_SETATTRLISTAT = 524 +const SYS_NET_QOS_GUIDELINE = 525 +const SYS_FMOUNT = 526 +const SYS_NTP_ADJTIME = 527 +const SYS_NTP_GETTIME = 528 +const SYS_OS_FAULT_WITH_PAYLOAD = 529 +const SYS_KQUEUE_WORKLOOP_CTL = 530 +const SYS___MACH_BRIDGE_REMOTE_TIME = 531 +const SYS_COALITION_LEDGER = 532 +const SYS_LOG_DATA = 533 +const SYS_MEMORYSTATUS_AVAILABLE_MEMORY = 534 +const SYS_SHARED_REGION_MAP_AND_SLIDE_2_NP = 536 +const SYS_PIVOT_ROOT = 537 +const SYS_TASK_INSPECT_FOR_PID = 538 +const SYS_TASK_READ_FOR_PID = 539 +const SYS_PREADV = 540 +const SYS_PWRITEV = 541 +const SYS_PREADV_NOCANCEL = 542 +const SYS_PWRITEV_NOCANCEL = 543 +const SYS_ULOCK_WAIT2 = 544 +const SYS_PROC_INFO_EXTENDED_ID = 545 +const SYS_MAXSYSCALL = 546 +const SYS_INVALID = 63 // sigkill 相关信号 int SIGHUP = 1 /* hangup */ @@ -913,4 +913,4 @@ fn mount(string source, string target, string fs_type, u32 flags, string data):v fn umount(string target, u32 flags):void! { // Darwin 使用 SYS_UNMOUNT 而不是 SYS_UMOUNT2 call6(SYS_UNMOUNT, target.ref(), flags as anyptr, 0, 0, 0, 0) -} \ No newline at end of file +} diff --git a/std/syscall/main.linux_amd64.n b/std/syscall/main.linux_amd64.n index f8da9708..7ca259b6 100644 --- a/std/syscall/main.linux_amd64.n +++ b/std/syscall/main.linux_amd64.n @@ -90,309 +90,309 @@ int CLOCK_BOOTTIME_ALARM = 9 int CLOCK_TAI = 11 // 系统调用编码 -int SYS_READ = 0 -int SYS_WRITE = 1 -int SYS_OPEN = 2 -int SYS_CLOSE = 3 -int SYS_STAT = 4 -int SYS_FSTAT = 5 -int SYS_LSTAT = 6 -int SYS_POLL = 7 -int SYS_LSEEK = 8 -int SYS_MMAP = 9 -int SYS_MPROTECT = 10 -int SYS_MUNMAP = 11 -int SYS_BRK = 12 -int SYS_RT_SIGACTION = 13 -int SYS_RT_SIGPROCMASK = 14 -int SYS_RT_SIGRETURN = 15 -int SYS_IOCTL = 16 -int SYS_PREAD64 = 17 -int SYS_PWRITE64 = 18 -int SYS_READV = 19 -int SYS_WRITEV = 20 -int SYS_ACCESS = 21 -int SYS_PIPE = 22 -int SYS_SELECT = 23 -int SYS_SCHED_YIELD = 24 -int SYS_MREMAP = 25 -int SYS_MSYNC = 26 -int SYS_MINCORE = 27 -int SYS_MADVISE = 28 -int SYS_SHMGET = 29 -int SYS_SHMAT = 30 -int SYS_SHMCTL = 31 -int SYS_DUP = 32 -int SYS_DUP2 = 33 -int SYS_PAUSE = 34 -int SYS_NANOSLEEP = 35 -int SYS_GETITIMER = 36 -int SYS_ALARM = 37 -int SYS_SETITIMER = 38 -int SYS_GETPID = 39 -int SYS_SENDFILE = 40 -int SYS_SOCKET = 41 -int SYS_CONNECT = 42 -int SYS_ACCEPT = 43 -int SYS_SENDTO = 44 -int SYS_RECVFROM = 45 -int SYS_SENDMSG = 46 -int SYS_RECVMSG = 47 -int SYS_SHUTDOWN = 48 -int SYS_BIND = 49 -int SYS_LISTEN = 50 -int SYS_GETSOCKNAME = 51 -int SYS_GETPEERNAME = 52 -int SYS_SOCKETPAIR = 53 -int SYS_SETSOCKOPT = 54 -int SYS_GETSOCKOPT = 55 -int SYS_CLONE = 56 -int SYS_FORK = 57 -int SYS_VFORK = 58 -int SYS_EXECVE = 59 -int SYS_EXIT = 60 -int SYS_WAIT4 = 61 -int SYS_KILL = 62 -int SYS_UNAME = 63 -int SYS_SEMGET = 64 -int SYS_SEMOP = 65 -int SYS_SEMCTL = 66 -int SYS_SHMDT = 67 -int SYS_MSGGET = 68 -int SYS_MSGSND = 69 -int SYS_MSGRCV = 70 -int SYS_MSGCTL = 71 -int SYS_FCNTL = 72 -int SYS_FLOCK = 73 -int SYS_FSYNC = 74 -int SYS_FDATASYNC = 75 -int SYS_TRUNCATE = 76 -int SYS_FTRUNCATE = 77 -int SYS_GETDENTS = 78 -int SYS_GETCWD = 79 -int SYS_CHDIR = 80 -int SYS_FCHDIR = 81 -int SYS_RENAME = 82 -int SYS_MKDIR = 83 -int SYS_RMDIR = 84 -int SYS_CREAT = 85 -int SYS_LINK = 86 -int SYS_UNLINK = 87 -int SYS_SYMLINK = 88 -int SYS_READLINK = 89 -int SYS_CHMOD = 90 -int SYS_FCHMOD = 91 -int SYS_CHOWN = 92 -int SYS_FCHOWN = 93 -int SYS_LCHOWN = 94 -int SYS_UMASK = 95 -int SYS_GETTIMEOFDAY = 96 -int SYS_GETRLIMIT = 97 -int SYS_GETRUSAGE = 98 -int SYS_SYSINFO = 99 -int SYS_TIMES = 100 -int SYS_PTRACE = 101 -int SYS_GETUID = 102 -int SYS_SYSLOG = 103 -int SYS_GETGID = 104 -int SYS_SETUID = 105 -int SYS_SETGID = 106 -int SYS_GETEUID = 107 -int SYS_GETEGID = 108 -int SYS_SETPGID = 109 -int SYS_GETPPID = 110 -int SYS_GETPGRP = 111 -int SYS_SETSID = 112 -int SYS_SETREUID = 113 -int SYS_SETREGID = 114 -int SYS_GETGROUPS = 115 -int SYS_SETGROUPS = 116 -int SYS_SETRESUID = 117 -int SYS_GETRESUID = 118 -int SYS_SETRESGID = 119 -int SYS_GETRESGID = 120 -int SYS_GETPGID = 121 -int SYS_SETFSUID = 122 -int SYS_SETFSGID = 123 -int SYS_GETSID = 124 -int SYS_CAPGET = 125 -int SYS_CAPSET = 126 -int SYS_RT_SIGPENDING = 127 -int SYS_RT_SIGTIMEDWAIT = 128 -int SYS_RT_SIGQUEUEINFO = 129 -int SYS_RT_SIGSUSPEND = 130 -int SYS_SIGALTSTACK = 131 -int SYS_UTIME = 132 -int SYS_MKNOD = 133 -int SYS_USELIB = 134 -int SYS_PERSONALITY = 135 -int SYS_USTAT = 136 -int SYS_STATFS = 137 -int SYS_FSTATFS = 138 -int SYS_SYSFS = 139 -int SYS_GETPRIORITY = 140 -int SYS_SETPRIORITY = 141 -int SYS_SCHED_SETPARAM = 142 -int SYS_SCHED_GETPARAM = 143 -int SYS_SCHED_SETSCHEDULER = 144 -int SYS_SCHED_GETSCHEDULER = 145 -int SYS_SCHED_GET_PRIORITY_MAX = 146 -int SYS_SCHED_GET_PRIORITY_MIN = 147 -int SYS_SCHED_RR_GET_INTERVAL = 148 -int SYS_MLOCK = 149 -int SYS_MUNLOCK = 150 -int SYS_MLOCKALL = 151 -int SYS_MUNLOCKALL = 152 -int SYS_VHANGUP = 153 -int SYS_MODIFY_LDT = 154 -int SYS_PIVOT_ROOT = 155 -int SYS__SYSCTL = 156 -int SYS_PRCTL = 157 -int SYS_ARCH_PRCTL = 158 -int SYS_ADJTIMEX = 159 -int SYS_SETRLIMIT = 160 -int SYS_CHROOT = 161 -int SYS_SYNC = 162 -int SYS_ACCT = 163 -int SYS_SETTIMEOFDAY = 164 -int SYS_MOUNT = 165 -int SYS_UMOUNT2 = 166 -int SYS_SWAPON = 167 -int SYS_SWAPOFF = 168 -int SYS_REBOOT = 169 -int SYS_SETHOSTNAME = 170 -int SYS_SETDOMAINNAME = 171 -int SYS_IOPL = 172 -int SYS_IOPERM = 173 -int SYS_CREATE_MODULE = 174 -int SYS_INIT_MODULE = 175 -int SYS_DELETE_MODULE = 176 -int SYS_GET_KERNEL_SYMS = 177 -int SYS_QUERY_MODULE = 178 -int SYS_QUOTACTL = 179 -int SYS_NFSSERVCTL = 180 -int SYS_GETPMSG = 181 -int SYS_PUTPMSG = 182 -int SYS_AFS_SYSCALL = 183 -int SYS_TUXCALL = 184 -int SYS_SECURITY = 185 -int SYS_GETTID = 186 -int SYS_READAHEAD = 187 -int SYS_SETXATTR = 188 -int SYS_LSETXATTR = 189 -int SYS_FSETXATTR = 190 -int SYS_GETXATTR = 191 -int SYS_LGETXATTR = 192 -int SYS_FGETXATTR = 193 -int SYS_LISTXATTR = 194 -int SYS_LLISTXATTR = 195 -int SYS_FLISTXATTR = 196 -int SYS_REMOVEXATTR = 197 -int SYS_LREMOVEXATTR = 198 -int SYS_FREMOVEXATTR = 199 -int SYS_TKILL = 200 -int SYS_TIME = 201 -int SYS_FUTEX = 202 -int SYS_SCHED_SETAFFINITY = 203 -int SYS_SCHED_GETAFFINITY = 204 -int SYS_SET_THREAD_AREA = 205 -int SYS_IO_SETUP = 206 -int SYS_IO_DESTROY = 207 -int SYS_IO_GETEVENTS = 208 -int SYS_IO_SUBMIT = 209 -int SYS_IO_CANCEL = 210 -int SYS_GET_THREAD_AREA = 211 -int SYS_LOOKUP_DCOOKIE = 212 -int SYS_EPOLL_CREATE = 213 -int SYS_EPOLL_CTL_OLD = 214 -int SYS_EPOLL_WAIT_OLD = 215 -int SYS_REMAP_FILE_PAGES = 216 -int SYS_GETDENTS64 = 217 -int SYS_SET_TID_ADDRESS = 218 -int SYS_RESTART_SYSCALL = 219 -int SYS_SEMTIMEDOP = 220 -int SYS_FADVISE64 = 221 -int SYS_TIMER_CREATE = 222 -int SYS_TIMER_SETTIME = 223 -int SYS_TIMER_GETTIME = 224 -int SYS_TIMER_GETOVERRUN = 225 -int SYS_TIMER_DELETE = 226 -int SYS_CLOCK_SETTIME = 227 -int SYS_CLOCK_GETTIME = 228 -int SYS_CLOCK_GETRES = 229 -int SYS_CLOCK_NANOSLEEP = 230 -int SYS_EXIT_GROUP = 231 -int SYS_EPOLL_WAIT = 232 -int SYS_EPOLL_CTL = 233 -int SYS_TGKILL = 234 -int SYS_UTIMES = 235 -int SYS_VSERVER = 236 -int SYS_MBIND = 237 -int SYS_SET_MEMPOLICY = 238 -int SYS_GET_MEMPOLICY = 239 -int SYS_MQ_OPEN = 240 -int SYS_MQ_UNLINK = 241 -int SYS_MQ_TIMEDSEND = 242 -int SYS_MQ_TIMEDRECEIVE = 243 -int SYS_MQ_NOTIFY = 244 -int SYS_MQ_GETSETATTR = 245 -int SYS_KEXEC_LOAD = 246 -int SYS_WAITID = 247 -int SYS_ADD_KEY = 248 -int SYS_REQUEST_KEY = 249 -int SYS_KEYCTL = 250 -int SYS_IOPRIO_SET = 251 -int SYS_IOPRIO_GET = 252 -int SYS_INOTIFY_INIT = 253 -int SYS_INOTIFY_ADD_WATCH = 254 -int SYS_INOTIFY_RM_WATCH = 255 -int SYS_MIGRATE_PAGES = 256 -int SYS_OPENAT = 257 -int SYS_MKDIRAT = 258 -int SYS_MKNODAT = 259 -int SYS_FCHOWNAT = 260 -int SYS_FUTIMESAT = 261 -int SYS_NEWFSTATAT = 262 -int SYS_UNLINKAT = 263 -int SYS_RENAMEAT = 264 -int SYS_LINKAT = 265 -int SYS_SYMLINKAT = 266 -int SYS_READLINKAT = 267 -int SYS_FCHMODAT = 268 -int SYS_FACCESSAT = 269 -int SYS_PSELECT6 = 270 -int SYS_PPOLL = 271 -int SYS_UNSHARE = 272 -int SYS_SET_ROBUST_LIST = 273 -int SYS_GET_ROBUST_LIST = 274 -int SYS_SPLICE = 275 -int SYS_TEE = 276 -int SYS_SYNC_FILE_RANGE = 277 -int SYS_VMSPLICE = 278 -int SYS_MOVE_PAGES = 279 -int SYS_UTIMENSAT = 280 -int SYS_EPOLL_PWAIT = 281 -int SYS_SIGNALFD = 282 -int SYS_TIMERFD_CREATE = 283 -int SYS_EVENTFD = 284 -int SYS_FALLOCATE = 285 -int SYS_TIMERFD_SETTIME = 286 -int SYS_TIMERFD_GETTIME = 287 -int SYS_ACCEPT4 = 288 -int SYS_SIGNALFD4 = 289 -int SYS_EVENTFD2 = 290 -int SYS_EPOLL_CREATE1 = 291 -int SYS_DUP3 = 292 -int SYS_PIPE2 = 293 -int SYS_INOTIFY_INIT1 = 294 -int SYS_PREADV = 295 -int SYS_PWRITEV = 296 -int SYS_RT_TGSIGQUEUEINFO = 297 -int SYS_PERF_EVENT_OPEN = 298 -int SYS_RECVMMSG = 299 -int SYS_FANOTIFY_INIT = 300 -int SYS_FANOTIFY_MARK = 301 -int SYS_PRLIMIT64 = 302 +const SYS_READ = 0 +const SYS_WRITE = 1 +const SYS_OPEN = 2 +const SYS_CLOSE = 3 +const SYS_STAT = 4 +const SYS_FSTAT = 5 +const SYS_LSTAT = 6 +const SYS_POLL = 7 +const SYS_LSEEK = 8 +const SYS_MMAP = 9 +const SYS_MPROTECT = 10 +const SYS_MUNMAP = 11 +const SYS_BRK = 12 +const SYS_RT_SIGACTION = 13 +const SYS_RT_SIGPROCMASK = 14 +const SYS_RT_SIGRETURN = 15 +const SYS_IOCTL = 16 +const SYS_PREAD64 = 17 +const SYS_PWRITE64 = 18 +const SYS_READV = 19 +const SYS_WRITEV = 20 +const SYS_ACCESS = 21 +const SYS_PIPE = 22 +const SYS_SELECT = 23 +const SYS_SCHED_YIELD = 24 +const SYS_MREMAP = 25 +const SYS_MSYNC = 26 +const SYS_MINCORE = 27 +const SYS_MADVISE = 28 +const SYS_SHMGET = 29 +const SYS_SHMAT = 30 +const SYS_SHMCTL = 31 +const SYS_DUP = 32 +const SYS_DUP2 = 33 +const SYS_PAUSE = 34 +const SYS_NANOSLEEP = 35 +const SYS_GETITIMER = 36 +const SYS_ALARM = 37 +const SYS_SETITIMER = 38 +const SYS_GETPID = 39 +const SYS_SENDFILE = 40 +const SYS_SOCKET = 41 +const SYS_CONNECT = 42 +const SYS_ACCEPT = 43 +const SYS_SENDTO = 44 +const SYS_RECVFROM = 45 +const SYS_SENDMSG = 46 +const SYS_RECVMSG = 47 +const SYS_SHUTDOWN = 48 +const SYS_BIND = 49 +const SYS_LISTEN = 50 +const SYS_GETSOCKNAME = 51 +const SYS_GETPEERNAME = 52 +const SYS_SOCKETPAIR = 53 +const SYS_SETSOCKOPT = 54 +const SYS_GETSOCKOPT = 55 +const SYS_CLONE = 56 +const SYS_FORK = 57 +const SYS_VFORK = 58 +const SYS_EXECVE = 59 +const SYS_EXIT = 60 +const SYS_WAIT4 = 61 +const SYS_KILL = 62 +const SYS_UNAME = 63 +const SYS_SEMGET = 64 +const SYS_SEMOP = 65 +const SYS_SEMCTL = 66 +const SYS_SHMDT = 67 +const SYS_MSGGET = 68 +const SYS_MSGSND = 69 +const SYS_MSGRCV = 70 +const SYS_MSGCTL = 71 +const SYS_FCNTL = 72 +const SYS_FLOCK = 73 +const SYS_FSYNC = 74 +const SYS_FDATASYNC = 75 +const SYS_TRUNCATE = 76 +const SYS_FTRUNCATE = 77 +const SYS_GETDENTS = 78 +const SYS_GETCWD = 79 +const SYS_CHDIR = 80 +const SYS_FCHDIR = 81 +const SYS_RENAME = 82 +const SYS_MKDIR = 83 +const SYS_RMDIR = 84 +const SYS_CREAT = 85 +const SYS_LINK = 86 +const SYS_UNLINK = 87 +const SYS_SYMLINK = 88 +const SYS_READLINK = 89 +const SYS_CHMOD = 90 +const SYS_FCHMOD = 91 +const SYS_CHOWN = 92 +const SYS_FCHOWN = 93 +const SYS_LCHOWN = 94 +const SYS_UMASK = 95 +const SYS_GETTIMEOFDAY = 96 +const SYS_GETRLIMIT = 97 +const SYS_GETRUSAGE = 98 +const SYS_SYSINFO = 99 +const SYS_TIMES = 100 +const SYS_PTRACE = 101 +const SYS_GETUID = 102 +const SYS_SYSLOG = 103 +const SYS_GETGID = 104 +const SYS_SETUID = 105 +const SYS_SETGID = 106 +const SYS_GETEUID = 107 +const SYS_GETEGID = 108 +const SYS_SETPGID = 109 +const SYS_GETPPID = 110 +const SYS_GETPGRP = 111 +const SYS_SETSID = 112 +const SYS_SETREUID = 113 +const SYS_SETREGID = 114 +const SYS_GETGROUPS = 115 +const SYS_SETGROUPS = 116 +const SYS_SETRESUID = 117 +const SYS_GETRESUID = 118 +const SYS_SETRESGID = 119 +const SYS_GETRESGID = 120 +const SYS_GETPGID = 121 +const SYS_SETFSUID = 122 +const SYS_SETFSGID = 123 +const SYS_GETSID = 124 +const SYS_CAPGET = 125 +const SYS_CAPSET = 126 +const SYS_RT_SIGPENDING = 127 +const SYS_RT_SIGTIMEDWAIT = 128 +const SYS_RT_SIGQUEUEINFO = 129 +const SYS_RT_SIGSUSPEND = 130 +const SYS_SIGALTSTACK = 131 +const SYS_UTIME = 132 +const SYS_MKNOD = 133 +const SYS_USELIB = 134 +const SYS_PERSONALITY = 135 +const SYS_USTAT = 136 +const SYS_STATFS = 137 +const SYS_FSTATFS = 138 +const SYS_SYSFS = 139 +const SYS_GETPRIORITY = 140 +const SYS_SETPRIORITY = 141 +const SYS_SCHED_SETPARAM = 142 +const SYS_SCHED_GETPARAM = 143 +const SYS_SCHED_SETSCHEDULER = 144 +const SYS_SCHED_GETSCHEDULER = 145 +const SYS_SCHED_GET_PRIORITY_MAX = 146 +const SYS_SCHED_GET_PRIORITY_MIN = 147 +const SYS_SCHED_RR_GET_INTERVAL = 148 +const SYS_MLOCK = 149 +const SYS_MUNLOCK = 150 +const SYS_MLOCKALL = 151 +const SYS_MUNLOCKALL = 152 +const SYS_VHANGUP = 153 +const SYS_MODIFY_LDT = 154 +const SYS_PIVOT_ROOT = 155 +const SYS__SYSCTL = 156 +const SYS_PRCTL = 157 +const SYS_ARCH_PRCTL = 158 +const SYS_ADJTIMEX = 159 +const SYS_SETRLIMIT = 160 +const SYS_CHROOT = 161 +const SYS_SYNC = 162 +const SYS_ACCT = 163 +const SYS_SETTIMEOFDAY = 164 +const SYS_MOUNT = 165 +const SYS_UMOUNT2 = 166 +const SYS_SWAPON = 167 +const SYS_SWAPOFF = 168 +const SYS_REBOOT = 169 +const SYS_SETHOSTNAME = 170 +const SYS_SETDOMAINNAME = 171 +const SYS_IOPL = 172 +const SYS_IOPERM = 173 +const SYS_CREATE_MODULE = 174 +const SYS_INIT_MODULE = 175 +const SYS_DELETE_MODULE = 176 +const SYS_GET_KERNEL_SYMS = 177 +const SYS_QUERY_MODULE = 178 +const SYS_QUOTACTL = 179 +const SYS_NFSSERVCTL = 180 +const SYS_GETPMSG = 181 +const SYS_PUTPMSG = 182 +const SYS_AFS_SYSCALL = 183 +const SYS_TUXCALL = 184 +const SYS_SECURITY = 185 +const SYS_GETTID = 186 +const SYS_READAHEAD = 187 +const SYS_SETXATTR = 188 +const SYS_LSETXATTR = 189 +const SYS_FSETXATTR = 190 +const SYS_GETXATTR = 191 +const SYS_LGETXATTR = 192 +const SYS_FGETXATTR = 193 +const SYS_LISTXATTR = 194 +const SYS_LLISTXATTR = 195 +const SYS_FLISTXATTR = 196 +const SYS_REMOVEXATTR = 197 +const SYS_LREMOVEXATTR = 198 +const SYS_FREMOVEXATTR = 199 +const SYS_TKILL = 200 +const SYS_TIME = 201 +const SYS_FUTEX = 202 +const SYS_SCHED_SETAFFINITY = 203 +const SYS_SCHED_GETAFFINITY = 204 +const SYS_SET_THREAD_AREA = 205 +const SYS_IO_SETUP = 206 +const SYS_IO_DESTROY = 207 +const SYS_IO_GETEVENTS = 208 +const SYS_IO_SUBMIT = 209 +const SYS_IO_CANCEL = 210 +const SYS_GET_THREAD_AREA = 211 +const SYS_LOOKUP_DCOOKIE = 212 +const SYS_EPOLL_CREATE = 213 +const SYS_EPOLL_CTL_OLD = 214 +const SYS_EPOLL_WAIT_OLD = 215 +const SYS_REMAP_FILE_PAGES = 216 +const SYS_GETDENTS64 = 217 +const SYS_SET_TID_ADDRESS = 218 +const SYS_RESTART_SYSCALL = 219 +const SYS_SEMTIMEDOP = 220 +const SYS_FADVISE64 = 221 +const SYS_TIMER_CREATE = 222 +const SYS_TIMER_SETTIME = 223 +const SYS_TIMER_GETTIME = 224 +const SYS_TIMER_GETOVERRUN = 225 +const SYS_TIMER_DELETE = 226 +const SYS_CLOCK_SETTIME = 227 +const SYS_CLOCK_GETTIME = 228 +const SYS_CLOCK_GETRES = 229 +const SYS_CLOCK_NANOSLEEP = 230 +const SYS_EXIT_GROUP = 231 +const SYS_EPOLL_WAIT = 232 +const SYS_EPOLL_CTL = 233 +const SYS_TGKILL = 234 +const SYS_UTIMES = 235 +const SYS_VSERVER = 236 +const SYS_MBIND = 237 +const SYS_SET_MEMPOLICY = 238 +const SYS_GET_MEMPOLICY = 239 +const SYS_MQ_OPEN = 240 +const SYS_MQ_UNLINK = 241 +const SYS_MQ_TIMEDSEND = 242 +const SYS_MQ_TIMEDRECEIVE = 243 +const SYS_MQ_NOTIFY = 244 +const SYS_MQ_GETSETATTR = 245 +const SYS_KEXEC_LOAD = 246 +const SYS_WAITID = 247 +const SYS_ADD_KEY = 248 +const SYS_REQUEST_KEY = 249 +const SYS_KEYCTL = 250 +const SYS_IOPRIO_SET = 251 +const SYS_IOPRIO_GET = 252 +const SYS_INOTIFY_INIT = 253 +const SYS_INOTIFY_ADD_WATCH = 254 +const SYS_INOTIFY_RM_WATCH = 255 +const SYS_MIGRATE_PAGES = 256 +const SYS_OPENAT = 257 +const SYS_MKDIRAT = 258 +const SYS_MKNODAT = 259 +const SYS_FCHOWNAT = 260 +const SYS_FUTIMESAT = 261 +const SYS_NEWFSTATAT = 262 +const SYS_UNLINKAT = 263 +const SYS_RENAMEAT = 264 +const SYS_LINKAT = 265 +const SYS_SYMLINKAT = 266 +const SYS_READLINKAT = 267 +const SYS_FCHMODAT = 268 +const SYS_FACCESSAT = 269 +const SYS_PSELECT6 = 270 +const SYS_PPOLL = 271 +const SYS_UNSHARE = 272 +const SYS_SET_ROBUST_LIST = 273 +const SYS_GET_ROBUST_LIST = 274 +const SYS_SPLICE = 275 +const SYS_TEE = 276 +const SYS_SYNC_FILE_RANGE = 277 +const SYS_VMSPLICE = 278 +const SYS_MOVE_PAGES = 279 +const SYS_UTIMENSAT = 280 +const SYS_EPOLL_PWAIT = 281 +const SYS_SIGNALFD = 282 +const SYS_TIMERFD_CREATE = 283 +const SYS_EVENTFD = 284 +const SYS_FALLOCATE = 285 +const SYS_TIMERFD_SETTIME = 286 +const SYS_TIMERFD_GETTIME = 287 +const SYS_ACCEPT4 = 288 +const SYS_SIGNALFD4 = 289 +const SYS_EVENTFD2 = 290 +const SYS_EPOLL_CREATE1 = 291 +const SYS_DUP3 = 292 +const SYS_PIPE2 = 293 +const SYS_INOTIFY_INIT1 = 294 +const SYS_PREADV = 295 +const SYS_PWRITEV = 296 +const SYS_RT_TGSIGQUEUEINFO = 297 +const SYS_PERF_EVENT_OPEN = 298 +const SYS_RECVMMSG = 299 +const SYS_FANOTIFY_INIT = 300 +const SYS_FANOTIFY_MARK = 301 +const SYS_PRLIMIT64 = 302 // sigkill 相关信号 int SIGABRT = 0x6 @@ -833,4 +833,4 @@ fn mount(string source, string target, string fs_type, u32 flags, string data):v fn umount(string target, u32 flags):void! { call6(SYS_UMOUNT2, target.ref(), flags as anyptr, 0, 0, 0, 0) -} \ No newline at end of file +} diff --git a/std/syscall/main.linux_arm64.n b/std/syscall/main.linux_arm64.n index a016105e..80440f09 100644 --- a/std/syscall/main.linux_arm64.n +++ b/std/syscall/main.linux_arm64.n @@ -90,324 +90,324 @@ int CLOCK_BOOTTIME_ALARM = 9 int CLOCK_TAI = 11 // 系统调用编码 -int SYS_IO_SETUP = 0 -int SYS_IO_DESTROY = 1 -int SYS_IO_SUBMIT = 2 -int SYS_IO_CANCEL = 3 -int SYS_IO_GETEVENTS = 4 -int SYS_SETXATTR = 5 -int SYS_LSETXATTR = 6 -int SYS_FSETXATTR = 7 -int SYS_GETXATTR = 8 -int SYS_LGETXATTR = 9 -int SYS_FGETXATTR = 10 -int SYS_LISTXATTR = 11 -int SYS_LLISTXATTR = 12 -int SYS_FLISTXATTR = 13 -int SYS_REMOVEXATTR = 14 -int SYS_LREMOVEXATTR = 15 -int SYS_FREMOVEXATTR = 16 -int SYS_GETCWD = 17 -int SYS_LOOKUP_DCOOKIE = 18 -int SYS_EVENTFD2 = 19 -int SYS_EPOLL_CREATE1 = 20 -int SYS_EPOLL_CTL = 21 -int SYS_EPOLL_PWAIT = 22 -int SYS_DUP = 23 -int SYS_DUP3 = 24 -int SYS_FCNTL = 25 -int SYS_INOTIFY_INIT1 = 26 -int SYS_INOTIFY_ADD_WATCH = 27 -int SYS_INOTIFY_RM_WATCH = 28 -int SYS_IOCTL = 29 -int SYS_IOPRIO_SET = 30 -int SYS_IOPRIO_GET = 31 -int SYS_FLOCK = 32 -int SYS_MKNODAT = 33 -int SYS_MKDIRAT = 34 -int SYS_UNLINKAT = 35 -int SYS_SYMLINKAT = 36 -int SYS_LINKAT = 37 -int SYS_RENAMEAT = 38 -int SYS_UMOUNT2 = 39 -int SYS_MOUNT = 40 -int SYS_PIVOT_ROOT = 41 -int SYS_NFSSERVCTL = 42 -int SYS_STATFS = 43 -int SYS_FSTATFS = 44 -int SYS_TRUNCATE = 45 -int SYS_FTRUNCATE = 46 -int SYS_FALLOCATE = 47 -int SYS_FACCESSAT = 48 -int SYS_CHDIR = 49 -int SYS_FCHDIR = 50 -int SYS_CHROOT = 51 -int SYS_FCHMOD = 52 -int SYS_FCHMODAT = 53 -int SYS_FCHOWNAT = 54 -int SYS_FCHOWN = 55 -int SYS_OPENAT = 56 -int SYS_CLOSE = 57 -int SYS_VHANGUP = 58 -int SYS_PIPE2 = 59 -int SYS_QUOTACTL = 60 -int SYS_GETDENTS64 = 61 -int SYS_LSEEK = 62 -int SYS_READ = 63 -int SYS_WRITE = 64 -int SYS_READV = 65 -int SYS_WRITEV = 66 -int SYS_PREAD64 = 67 -int SYS_PWRITE64 = 68 -int SYS_PREADV = 69 -int SYS_PWRITEV = 70 -int SYS_SENDFILE = 71 -int SYS_PSELECT6 = 72 -int SYS_PPOLL = 73 -int SYS_SIGNALFD4 = 74 -int SYS_VMSPLICE = 75 -int SYS_SPLICE = 76 -int SYS_TEE = 77 -int SYS_READLINKAT = 78 -int SYS_NEWFSTATAT = 79 -int SYS_FSTAT = 80 -int SYS_SYNC = 81 -int SYS_FSYNC = 82 -int SYS_FDATASYNC = 83 -int SYS_SYNC_FILE_RANGE = 84 -int SYS_TIMERFD_CREATE = 85 -int SYS_TIMERFD_SETTIME = 86 -int SYS_TIMERFD_GETTIME = 87 -int SYS_UTIMENSAT = 88 -int SYS_ACCT = 89 -int SYS_CAPGET = 90 -int SYS_CAPSET = 91 -int SYS_PERSONALITY = 92 -int SYS_EXIT = 93 -int SYS_EXIT_GROUP = 94 -int SYS_WAITID = 95 -int SYS_SET_TID_ADDRESS = 96 -int SYS_UNSHARE = 97 -int SYS_FUTEX = 98 -int SYS_SET_ROBUST_LIST = 99 -int SYS_GET_ROBUST_LIST = 100 -int SYS_NANOSLEEP = 101 -int SYS_GETITIMER = 102 -int SYS_SETITIMER = 103 -int SYS_KEXEC_LOAD = 104 -int SYS_INIT_MODULE = 105 -int SYS_DELETE_MODULE = 106 -int SYS_TIMER_CREATE = 107 -int SYS_TIMER_GETTIME = 108 -int SYS_TIMER_GETOVERRUN = 109 -int SYS_TIMER_SETTIME = 110 -int SYS_TIMER_DELETE = 111 -int SYS_CLOCK_SETTIME = 112 -int SYS_CLOCK_GETTIME = 113 -int SYS_CLOCK_GETRES = 114 -int SYS_CLOCK_NANOSLEEP = 115 -int SYS_SYSLOG = 116 -int SYS_PTRACE = 117 -int SYS_SCHED_SETPARAM = 118 -int SYS_SCHED_SETSCHEDULER = 119 -int SYS_SCHED_GETSCHEDULER = 120 -int SYS_SCHED_GETPARAM = 121 -int SYS_SCHED_SETAFFINITY = 122 -int SYS_SCHED_GETAFFINITY = 123 -int SYS_SCHED_YIELD = 124 -int SYS_SCHED_GET_PRIORITY_MAX = 125 -int SYS_SCHED_GET_PRIORITY_MIN = 126 -int SYS_SCHED_RR_GET_INTERVAL = 127 -int SYS_RESTART_SYSCALL = 128 -int SYS_KILL = 129 -int SYS_TKILL = 130 -int SYS_TGKILL = 131 -int SYS_SIGALTSTACK = 132 -int SYS_RT_SIGSUSPEND = 133 -int SYS_RT_SIGACTION = 134 -int SYS_RT_SIGPROCMASK = 135 -int SYS_RT_SIGPENDING = 136 -int SYS_RT_SIGTIMEDWAIT = 137 -int SYS_RT_SIGQUEUEINFO = 138 -int SYS_RT_SIGRETURN = 139 -int SYS_SETPRIORITY = 140 -int SYS_GETPRIORITY = 141 -int SYS_REBOOT = 142 -int SYS_SETREGID = 143 -int SYS_SETGID = 144 -int SYS_SETREUID = 145 -int SYS_SETUID = 146 -int SYS_SETRESUID = 147 -int SYS_GETRESUID = 148 -int SYS_SETRESGID = 149 -int SYS_GETRESGID = 150 -int SYS_SETFSUID = 151 -int SYS_SETFSGID = 152 -int SYS_TIMES = 153 -int SYS_SETPGID = 154 -int SYS_GETPGID = 155 -int SYS_GETSID = 156 -int SYS_SETSID = 157 -int SYS_GETGROUPS = 158 -int SYS_SETGROUPS = 159 -int SYS_UNAME = 160 -int SYS_SETHOSTNAME = 161 -int SYS_SETDOMAINNAME = 162 -int SYS_GETRLIMIT = 163 -int SYS_SETRLIMIT = 164 -int SYS_GETRUSAGE = 165 -int SYS_UMASK = 166 -int SYS_PRCTL = 167 -int SYS_GETCPU = 168 -int SYS_GETTIMEOFDAY = 169 -int SYS_SETTIMEOFDAY = 170 -int SYS_ADJTIMEX = 171 -int SYS_GETPID = 172 -int SYS_GETPPID = 173 -int SYS_GETUID = 174 -int SYS_GETEUID = 175 -int SYS_GETGID = 176 -int SYS_GETEGID = 177 -int SYS_GETTID = 178 -int SYS_SYSINFO = 179 -int SYS_MQ_OPEN = 180 -int SYS_MQ_UNLINK = 181 -int SYS_MQ_TIMEDSEND = 182 -int SYS_MQ_TIMEDRECEIVE = 183 -int SYS_MQ_NOTIFY = 184 -int SYS_MQ_GETSETATTR = 185 -int SYS_MSGGET = 186 -int SYS_MSGCTL = 187 -int SYS_MSGRCV = 188 -int SYS_MSGSND = 189 -int SYS_SEMGET = 190 -int SYS_SEMCTL = 191 -int SYS_SEMTIMEDOP = 192 -int SYS_SEMOP = 193 -int SYS_SHMGET = 194 -int SYS_SHMCTL = 195 -int SYS_SHMAT = 196 -int SYS_SHMDT = 197 -int SYS_SOCKET = 198 -int SYS_SOCKETPAIR = 199 -int SYS_BIND = 200 -int SYS_LISTEN = 201 -int SYS_ACCEPT = 202 -int SYS_CONNECT = 203 -int SYS_GETSOCKNAME = 204 -int SYS_GETPEERNAME = 205 -int SYS_SENDTO = 206 -int SYS_RECVFROM = 207 -int SYS_SETSOCKOPT = 208 -int SYS_GETSOCKOPT = 209 -int SYS_SHUTDOWN = 210 -int SYS_SENDMSG = 211 -int SYS_RECVMSG = 212 -int SYS_READAHEAD = 213 -int SYS_BRK = 214 -int SYS_MUNMAP = 215 -int SYS_MREMAP = 216 -int SYS_ADD_KEY = 217 -int SYS_REQUEST_KEY = 218 -int SYS_KEYCTL = 219 -int SYS_CLONE = 220 -int SYS_EXECVE = 221 -int SYS_MMAP = 222 -int SYS_FADVISE64 = 223 -int SYS_SWAPON = 224 -int SYS_SWAPOFF = 225 -int SYS_MPROTECT = 226 -int SYS_MSYNC = 227 -int SYS_MLOCK = 228 -int SYS_MUNLOCK = 229 -int SYS_MLOCKALL = 230 -int SYS_MUNLOCKALL = 231 -int SYS_MINCORE = 232 -int SYS_MADVISE = 233 -int SYS_REMAP_FILE_PAGES = 234 -int SYS_MBIND = 235 -int SYS_GET_MEMPOLICY = 236 -int SYS_SET_MEMPOLICY = 237 -int SYS_MIGRATE_PAGES = 238 -int SYS_MOVE_PAGES = 239 -int SYS_RT_TGSIGQUEUEINFO = 240 -int SYS_PERF_EVENT_OPEN = 241 -int SYS_ACCEPT4 = 242 -int SYS_RECVMMSG = 243 -int SYS_WAIT4 = 260 -int SYS_PRLIMIT64 = 261 -int SYS_FANOTIFY_INIT = 262 -int SYS_FANOTIFY_MARK = 263 -int SYS_NAME_TO_HANDLE_AT = 264 -int SYS_OPEN_BY_HANDLE_AT = 265 -int SYS_CLOCK_ADJTIME = 266 -int SYS_SYNCFS = 267 -int SYS_SETNS = 268 -int SYS_SENDMMSG = 269 -int SYS_PROCESS_VM_READV = 270 -int SYS_PROCESS_VM_WRITEV = 271 -int SYS_KCMP = 272 -int SYS_FINIT_MODULE = 273 -int SYS_SCHED_SETATTR = 274 -int SYS_SCHED_GETATTR = 275 -int SYS_RENAMEAT2 = 276 -int SYS_SECCOMP = 277 -int SYS_GETRANDOM = 278 -int SYS_MEMFD_CREATE = 279 -int SYS_BPF = 280 -int SYS_EXECVEAT = 281 -int SYS_USERFAULTFD = 282 -int SYS_MEMBARRIER = 283 -int SYS_MLOCK2 = 284 -int SYS_COPY_FILE_RANGE = 285 -int SYS_PREADV2 = 286 -int SYS_PWRITEV2 = 287 -int SYS_PKEY_MPROTECT = 288 -int SYS_PKEY_ALLOC = 289 -int SYS_PKEY_FREE = 290 -int SYS_STATX = 291 -int SYS_IO_PGETEVENTS = 292 -int SYS_RSEQ = 293 -int SYS_KEXEC_FILE_LOAD = 294 -int SYS_PIDFD_SEND_SIGNAL = 424 -int SYS_IO_URING_SETUP = 425 -int SYS_IO_URING_ENTER = 426 -int SYS_IO_URING_REGISTER = 427 -int SYS_OPEN_TREE = 428 -int SYS_MOVE_MOUNT = 429 -int SYS_FSOPEN = 430 -int SYS_FSCONFIG = 431 -int SYS_FSMOUNT = 432 -int SYS_FSPICK = 433 -int SYS_PIDFD_OPEN = 434 -int SYS_CLONE3 = 435 -int SYS_CLOSE_RANGE = 436 -int SYS_OPENAT2 = 437 -int SYS_PIDFD_GETFD = 438 -int SYS_FACCESSAT2 = 439 -int SYS_PROCESS_MADVISE = 440 -int SYS_EPOLL_PWAIT2 = 441 -int SYS_MOUNT_SETATTR = 442 -int SYS_QUOTACTL_FD = 443 -int SYS_LANDLOCK_CREATE_RULESET = 444 -int SYS_LANDLOCK_ADD_RULE = 445 -int SYS_LANDLOCK_RESTRICT_SELF = 446 -int SYS_MEMFD_SECRET = 447 -int SYS_PROCESS_MRELEASE = 448 -int SYS_FUTEX_WAITV = 449 -int SYS_SET_MEMPOLICY_HOME_NODE = 450 -int SYS_CACHESTAT = 451 -int SYS_FCHMODAT2 = 452 -int SYS_MAP_SHADOW_STACK = 453 -int SYS_FUTEX_WAKE = 454 -int SYS_FUTEX_WAIT = 455 -int SYS_FUTEX_REQUEUE = 456 -int SYS_STATMOUNT = 457 -int SYS_LISTMOUNT = 458 -int SYS_LSM_GET_SELF_ATTR = 459 -int SYS_LSM_SET_SELF_ATTR = 460 -int SYS_LSM_LIST_MODULES = 461 -int SYS_MSEAL = 462 +const SYS_IO_SETUP = 0 +const SYS_IO_DESTROY = 1 +const SYS_IO_SUBMIT = 2 +const SYS_IO_CANCEL = 3 +const SYS_IO_GETEVENTS = 4 +const SYS_SETXATTR = 5 +const SYS_LSETXATTR = 6 +const SYS_FSETXATTR = 7 +const SYS_GETXATTR = 8 +const SYS_LGETXATTR = 9 +const SYS_FGETXATTR = 10 +const SYS_LISTXATTR = 11 +const SYS_LLISTXATTR = 12 +const SYS_FLISTXATTR = 13 +const SYS_REMOVEXATTR = 14 +const SYS_LREMOVEXATTR = 15 +const SYS_FREMOVEXATTR = 16 +const SYS_GETCWD = 17 +const SYS_LOOKUP_DCOOKIE = 18 +const SYS_EVENTFD2 = 19 +const SYS_EPOLL_CREATE1 = 20 +const SYS_EPOLL_CTL = 21 +const SYS_EPOLL_PWAIT = 22 +const SYS_DUP = 23 +const SYS_DUP3 = 24 +const SYS_FCNTL = 25 +const SYS_INOTIFY_INIT1 = 26 +const SYS_INOTIFY_ADD_WATCH = 27 +const SYS_INOTIFY_RM_WATCH = 28 +const SYS_IOCTL = 29 +const SYS_IOPRIO_SET = 30 +const SYS_IOPRIO_GET = 31 +const SYS_FLOCK = 32 +const SYS_MKNODAT = 33 +const SYS_MKDIRAT = 34 +const SYS_UNLINKAT = 35 +const SYS_SYMLINKAT = 36 +const SYS_LINKAT = 37 +const SYS_RENAMEAT = 38 +const SYS_UMOUNT2 = 39 +const SYS_MOUNT = 40 +const SYS_PIVOT_ROOT = 41 +const SYS_NFSSERVCTL = 42 +const SYS_STATFS = 43 +const SYS_FSTATFS = 44 +const SYS_TRUNCATE = 45 +const SYS_FTRUNCATE = 46 +const SYS_FALLOCATE = 47 +const SYS_FACCESSAT = 48 +const SYS_CHDIR = 49 +const SYS_FCHDIR = 50 +const SYS_CHROOT = 51 +const SYS_FCHMOD = 52 +const SYS_FCHMODAT = 53 +const SYS_FCHOWNAT = 54 +const SYS_FCHOWN = 55 +const SYS_OPENAT = 56 +const SYS_CLOSE = 57 +const SYS_VHANGUP = 58 +const SYS_PIPE2 = 59 +const SYS_QUOTACTL = 60 +const SYS_GETDENTS64 = 61 +const SYS_LSEEK = 62 +const SYS_READ = 63 +const SYS_WRITE = 64 +const SYS_READV = 65 +const SYS_WRITEV = 66 +const SYS_PREAD64 = 67 +const SYS_PWRITE64 = 68 +const SYS_PREADV = 69 +const SYS_PWRITEV = 70 +const SYS_SENDFILE = 71 +const SYS_PSELECT6 = 72 +const SYS_PPOLL = 73 +const SYS_SIGNALFD4 = 74 +const SYS_VMSPLICE = 75 +const SYS_SPLICE = 76 +const SYS_TEE = 77 +const SYS_READLINKAT = 78 +const SYS_NEWFSTATAT = 79 +const SYS_FSTAT = 80 +const SYS_SYNC = 81 +const SYS_FSYNC = 82 +const SYS_FDATASYNC = 83 +const SYS_SYNC_FILE_RANGE = 84 +const SYS_TIMERFD_CREATE = 85 +const SYS_TIMERFD_SETTIME = 86 +const SYS_TIMERFD_GETTIME = 87 +const SYS_UTIMENSAT = 88 +const SYS_ACCT = 89 +const SYS_CAPGET = 90 +const SYS_CAPSET = 91 +const SYS_PERSONALITY = 92 +const SYS_EXIT = 93 +const SYS_EXIT_GROUP = 94 +const SYS_WAITID = 95 +const SYS_SET_TID_ADDRESS = 96 +const SYS_UNSHARE = 97 +const SYS_FUTEX = 98 +const SYS_SET_ROBUST_LIST = 99 +const SYS_GET_ROBUST_LIST = 100 +const SYS_NANOSLEEP = 101 +const SYS_GETITIMER = 102 +const SYS_SETITIMER = 103 +const SYS_KEXEC_LOAD = 104 +const SYS_INIT_MODULE = 105 +const SYS_DELETE_MODULE = 106 +const SYS_TIMER_CREATE = 107 +const SYS_TIMER_GETTIME = 108 +const SYS_TIMER_GETOVERRUN = 109 +const SYS_TIMER_SETTIME = 110 +const SYS_TIMER_DELETE = 111 +const SYS_CLOCK_SETTIME = 112 +const SYS_CLOCK_GETTIME = 113 +const SYS_CLOCK_GETRES = 114 +const SYS_CLOCK_NANOSLEEP = 115 +const SYS_SYSLOG = 116 +const SYS_PTRACE = 117 +const SYS_SCHED_SETPARAM = 118 +const SYS_SCHED_SETSCHEDULER = 119 +const SYS_SCHED_GETSCHEDULER = 120 +const SYS_SCHED_GETPARAM = 121 +const SYS_SCHED_SETAFFINITY = 122 +const SYS_SCHED_GETAFFINITY = 123 +const SYS_SCHED_YIELD = 124 +const SYS_SCHED_GET_PRIORITY_MAX = 125 +const SYS_SCHED_GET_PRIORITY_MIN = 126 +const SYS_SCHED_RR_GET_INTERVAL = 127 +const SYS_RESTART_SYSCALL = 128 +const SYS_KILL = 129 +const SYS_TKILL = 130 +const SYS_TGKILL = 131 +const SYS_SIGALTSTACK = 132 +const SYS_RT_SIGSUSPEND = 133 +const SYS_RT_SIGACTION = 134 +const SYS_RT_SIGPROCMASK = 135 +const SYS_RT_SIGPENDING = 136 +const SYS_RT_SIGTIMEDWAIT = 137 +const SYS_RT_SIGQUEUEINFO = 138 +const SYS_RT_SIGRETURN = 139 +const SYS_SETPRIORITY = 140 +const SYS_GETPRIORITY = 141 +const SYS_REBOOT = 142 +const SYS_SETREGID = 143 +const SYS_SETGID = 144 +const SYS_SETREUID = 145 +const SYS_SETUID = 146 +const SYS_SETRESUID = 147 +const SYS_GETRESUID = 148 +const SYS_SETRESGID = 149 +const SYS_GETRESGID = 150 +const SYS_SETFSUID = 151 +const SYS_SETFSGID = 152 +const SYS_TIMES = 153 +const SYS_SETPGID = 154 +const SYS_GETPGID = 155 +const SYS_GETSID = 156 +const SYS_SETSID = 157 +const SYS_GETGROUPS = 158 +const SYS_SETGROUPS = 159 +const SYS_UNAME = 160 +const SYS_SETHOSTNAME = 161 +const SYS_SETDOMAINNAME = 162 +const SYS_GETRLIMIT = 163 +const SYS_SETRLIMIT = 164 +const SYS_GETRUSAGE = 165 +const SYS_UMASK = 166 +const SYS_PRCTL = 167 +const SYS_GETCPU = 168 +const SYS_GETTIMEOFDAY = 169 +const SYS_SETTIMEOFDAY = 170 +const SYS_ADJTIMEX = 171 +const SYS_GETPID = 172 +const SYS_GETPPID = 173 +const SYS_GETUID = 174 +const SYS_GETEUID = 175 +const SYS_GETGID = 176 +const SYS_GETEGID = 177 +const SYS_GETTID = 178 +const SYS_SYSINFO = 179 +const SYS_MQ_OPEN = 180 +const SYS_MQ_UNLINK = 181 +const SYS_MQ_TIMEDSEND = 182 +const SYS_MQ_TIMEDRECEIVE = 183 +const SYS_MQ_NOTIFY = 184 +const SYS_MQ_GETSETATTR = 185 +const SYS_MSGGET = 186 +const SYS_MSGCTL = 187 +const SYS_MSGRCV = 188 +const SYS_MSGSND = 189 +const SYS_SEMGET = 190 +const SYS_SEMCTL = 191 +const SYS_SEMTIMEDOP = 192 +const SYS_SEMOP = 193 +const SYS_SHMGET = 194 +const SYS_SHMCTL = 195 +const SYS_SHMAT = 196 +const SYS_SHMDT = 197 +const SYS_SOCKET = 198 +const SYS_SOCKETPAIR = 199 +const SYS_BIND = 200 +const SYS_LISTEN = 201 +const SYS_ACCEPT = 202 +const SYS_CONNECT = 203 +const SYS_GETSOCKNAME = 204 +const SYS_GETPEERNAME = 205 +const SYS_SENDTO = 206 +const SYS_RECVFROM = 207 +const SYS_SETSOCKOPT = 208 +const SYS_GETSOCKOPT = 209 +const SYS_SHUTDOWN = 210 +const SYS_SENDMSG = 211 +const SYS_RECVMSG = 212 +const SYS_READAHEAD = 213 +const SYS_BRK = 214 +const SYS_MUNMAP = 215 +const SYS_MREMAP = 216 +const SYS_ADD_KEY = 217 +const SYS_REQUEST_KEY = 218 +const SYS_KEYCTL = 219 +const SYS_CLONE = 220 +const SYS_EXECVE = 221 +const SYS_MMAP = 222 +const SYS_FADVISE64 = 223 +const SYS_SWAPON = 224 +const SYS_SWAPOFF = 225 +const SYS_MPROTECT = 226 +const SYS_MSYNC = 227 +const SYS_MLOCK = 228 +const SYS_MUNLOCK = 229 +const SYS_MLOCKALL = 230 +const SYS_MUNLOCKALL = 231 +const SYS_MINCORE = 232 +const SYS_MADVISE = 233 +const SYS_REMAP_FILE_PAGES = 234 +const SYS_MBIND = 235 +const SYS_GET_MEMPOLICY = 236 +const SYS_SET_MEMPOLICY = 237 +const SYS_MIGRATE_PAGES = 238 +const SYS_MOVE_PAGES = 239 +const SYS_RT_TGSIGQUEUEINFO = 240 +const SYS_PERF_EVENT_OPEN = 241 +const SYS_ACCEPT4 = 242 +const SYS_RECVMMSG = 243 +const SYS_WAIT4 = 260 +const SYS_PRLIMIT64 = 261 +const SYS_FANOTIFY_INIT = 262 +const SYS_FANOTIFY_MARK = 263 +const SYS_NAME_TO_HANDLE_AT = 264 +const SYS_OPEN_BY_HANDLE_AT = 265 +const SYS_CLOCK_ADJTIME = 266 +const SYS_SYNCFS = 267 +const SYS_SETNS = 268 +const SYS_SENDMMSG = 269 +const SYS_PROCESS_VM_READV = 270 +const SYS_PROCESS_VM_WRITEV = 271 +const SYS_KCMP = 272 +const SYS_FINIT_MODULE = 273 +const SYS_SCHED_SETATTR = 274 +const SYS_SCHED_GETATTR = 275 +const SYS_RENAMEAT2 = 276 +const SYS_SECCOMP = 277 +const SYS_GETRANDOM = 278 +const SYS_MEMFD_CREATE = 279 +const SYS_BPF = 280 +const SYS_EXECVEAT = 281 +const SYS_USERFAULTFD = 282 +const SYS_MEMBARRIER = 283 +const SYS_MLOCK2 = 284 +const SYS_COPY_FILE_RANGE = 285 +const SYS_PREADV2 = 286 +const SYS_PWRITEV2 = 287 +const SYS_PKEY_MPROTECT = 288 +const SYS_PKEY_ALLOC = 289 +const SYS_PKEY_FREE = 290 +const SYS_STATX = 291 +const SYS_IO_PGETEVENTS = 292 +const SYS_RSEQ = 293 +const SYS_KEXEC_FILE_LOAD = 294 +const SYS_PIDFD_SEND_SIGNAL = 424 +const SYS_IO_URING_SETUP = 425 +const SYS_IO_URING_ENTER = 426 +const SYS_IO_URING_REGISTER = 427 +const SYS_OPEN_TREE = 428 +const SYS_MOVE_MOUNT = 429 +const SYS_FSOPEN = 430 +const SYS_FSCONFIG = 431 +const SYS_FSMOUNT = 432 +const SYS_FSPICK = 433 +const SYS_PIDFD_OPEN = 434 +const SYS_CLONE3 = 435 +const SYS_CLOSE_RANGE = 436 +const SYS_OPENAT2 = 437 +const SYS_PIDFD_GETFD = 438 +const SYS_FACCESSAT2 = 439 +const SYS_PROCESS_MADVISE = 440 +const SYS_EPOLL_PWAIT2 = 441 +const SYS_MOUNT_SETATTR = 442 +const SYS_QUOTACTL_FD = 443 +const SYS_LANDLOCK_CREATE_RULESET = 444 +const SYS_LANDLOCK_ADD_RULE = 445 +const SYS_LANDLOCK_RESTRICT_SELF = 446 +const SYS_MEMFD_SECRET = 447 +const SYS_PROCESS_MRELEASE = 448 +const SYS_FUTEX_WAITV = 449 +const SYS_SET_MEMPOLICY_HOME_NODE = 450 +const SYS_CACHESTAT = 451 +const SYS_FCHMODAT2 = 452 +const SYS_MAP_SHADOW_STACK = 453 +const SYS_FUTEX_WAKE = 454 +const SYS_FUTEX_WAIT = 455 +const SYS_FUTEX_REQUEUE = 456 +const SYS_STATMOUNT = 457 +const SYS_LISTMOUNT = 458 +const SYS_LSM_GET_SELF_ATTR = 459 +const SYS_LSM_SET_SELF_ATTR = 460 +const SYS_LSM_LIST_MODULES = 461 +const SYS_MSEAL = 462 // sigkill 相关信号 int SIGABRT = 0x6 @@ -853,4 +853,4 @@ fn mount(string source, string target, string fs_type, u32 flags, string data):v fn umount(string target, u32 flags):void! { call6(SYS_UMOUNT2, target.ref(), flags as anyptr, 0, 0, 0, 0) -} \ No newline at end of file +} diff --git a/std/syscall/main.linux_riscv64.n b/std/syscall/main.linux_riscv64.n index 2d3d7964..df2f5c90 100644 --- a/std/syscall/main.linux_riscv64.n +++ b/std/syscall/main.linux_riscv64.n @@ -90,324 +90,324 @@ int CLOCK_BOOTTIME_ALARM = 9 int CLOCK_TAI = 11 // 系统调用编码 -int SYS_IO_SETUP = 0 -int SYS_IO_DESTROY = 1 -int SYS_IO_SUBMIT = 2 -int SYS_IO_CANCEL = 3 -int SYS_IO_GETEVENTS = 4 -int SYS_SETXATTR = 5 -int SYS_LSETXATTR = 6 -int SYS_FSETXATTR = 7 -int SYS_GETXATTR = 8 -int SYS_LGETXATTR = 9 -int SYS_FGETXATTR = 10 -int SYS_LISTXATTR = 11 -int SYS_LLISTXATTR = 12 -int SYS_FLISTXATTR = 13 -int SYS_REMOVEXATTR = 14 -int SYS_LREMOVEXATTR = 15 -int SYS_FREMOVEXATTR = 16 -int SYS_GETCWD = 17 -int SYS_LOOKUP_DCOOKIE = 18 -int SYS_EVENTFD2 = 19 -int SYS_EPOLL_CREATE1 = 20 -int SYS_EPOLL_CTL = 21 -int SYS_EPOLL_PWAIT = 22 -int SYS_DUP = 23 -int SYS_DUP3 = 24 -int SYS_FCNTL = 25 -int SYS_INOTIFY_INIT1 = 26 -int SYS_INOTIFY_ADD_WATCH = 27 -int SYS_INOTIFY_RM_WATCH = 28 -int SYS_IOCTL = 29 -int SYS_IOPRIO_SET = 30 -int SYS_IOPRIO_GET = 31 -int SYS_FLOCK = 32 -int SYS_MKNODAT = 33 -int SYS_MKDIRAT = 34 -int SYS_UNLINKAT = 35 -int SYS_SYMLINKAT = 36 -int SYS_LINKAT = 37 -int SYS_RENAMEAT = 38 -int SYS_UMOUNT2 = 39 -int SYS_MOUNT = 40 -int SYS_PIVOT_ROOT = 41 -int SYS_NFSSERVCTL = 42 -int SYS_STATFS = 43 -int SYS_FSTATFS = 44 -int SYS_TRUNCATE = 45 -int SYS_FTRUNCATE = 46 -int SYS_FALLOCATE = 47 -int SYS_FACCESSAT = 48 -int SYS_CHDIR = 49 -int SYS_FCHDIR = 50 -int SYS_CHROOT = 51 -int SYS_FCHMOD = 52 -int SYS_FCHMODAT = 53 -int SYS_FCHOWNAT = 54 -int SYS_FCHOWN = 55 -int SYS_OPENAT = 56 -int SYS_CLOSE = 57 -int SYS_VHANGUP = 58 -int SYS_PIPE2 = 59 -int SYS_QUOTACTL = 60 -int SYS_GETDENTS64 = 61 -int SYS_LSEEK = 62 -int SYS_READ = 63 -int SYS_WRITE = 64 -int SYS_READV = 65 -int SYS_WRITEV = 66 -int SYS_PREAD64 = 67 -int SYS_PWRITE64 = 68 -int SYS_PREADV = 69 -int SYS_PWRITEV = 70 -int SYS_SENDFILE = 71 -int SYS_PSELECT6 = 72 -int SYS_PPOLL = 73 -int SYS_SIGNALFD4 = 74 -int SYS_VMSPLICE = 75 -int SYS_SPLICE = 76 -int SYS_TEE = 77 -int SYS_READLINKAT = 78 -int SYS_NEWFSTATAT = 79 -int SYS_FSTAT = 80 -int SYS_SYNC = 81 -int SYS_FSYNC = 82 -int SYS_FDATASYNC = 83 -int SYS_SYNC_FILE_RANGE = 84 -int SYS_TIMERFD_CREATE = 85 -int SYS_TIMERFD_SETTIME = 86 -int SYS_TIMERFD_GETTIME = 87 -int SYS_UTIMENSAT = 88 -int SYS_ACCT = 89 -int SYS_CAPGET = 90 -int SYS_CAPSET = 91 -int SYS_PERSONALITY = 92 -int SYS_EXIT = 93 -int SYS_EXIT_GROUP = 94 -int SYS_WAITID = 95 -int SYS_SET_TID_ADDRESS = 96 -int SYS_UNSHARE = 97 -int SYS_FUTEX = 98 -int SYS_SET_ROBUST_LIST = 99 -int SYS_GET_ROBUST_LIST = 100 -int SYS_NANOSLEEP = 101 -int SYS_GETITIMER = 102 -int SYS_SETITIMER = 103 -int SYS_KEXEC_LOAD = 104 -int SYS_INIT_MODULE = 105 -int SYS_DELETE_MODULE = 106 -int SYS_TIMER_CREATE = 107 -int SYS_TIMER_GETTIME = 108 -int SYS_TIMER_GETOVERRUN = 109 -int SYS_TIMER_SETTIME = 110 -int SYS_TIMER_DELETE = 111 -int SYS_CLOCK_SETTIME = 112 -int SYS_CLOCK_GETTIME = 113 -int SYS_CLOCK_GETRES = 114 -int SYS_CLOCK_NANOSLEEP = 115 -int SYS_SYSLOG = 116 -int SYS_PTRACE = 117 -int SYS_SCHED_SETPARAM = 118 -int SYS_SCHED_SETSCHEDULER = 119 -int SYS_SCHED_GETSCHEDULER = 120 -int SYS_SCHED_GETPARAM = 121 -int SYS_SCHED_SETAFFINITY = 122 -int SYS_SCHED_GETAFFINITY = 123 -int SYS_SCHED_YIELD = 124 -int SYS_SCHED_GET_PRIORITY_MAX = 125 -int SYS_SCHED_GET_PRIORITY_MIN = 126 -int SYS_SCHED_RR_GET_INTERVAL = 127 -int SYS_RESTART_SYSCALL = 128 -int SYS_KILL = 129 -int SYS_TKILL = 130 -int SYS_TGKILL = 131 -int SYS_SIGALTSTACK = 132 -int SYS_RT_SIGSUSPEND = 133 -int SYS_RT_SIGACTION = 134 -int SYS_RT_SIGPROCMASK = 135 -int SYS_RT_SIGPENDING = 136 -int SYS_RT_SIGTIMEDWAIT = 137 -int SYS_RT_SIGQUEUEINFO = 138 -int SYS_RT_SIGRETURN = 139 -int SYS_SETPRIORITY = 140 -int SYS_GETPRIORITY = 141 -int SYS_REBOOT = 142 -int SYS_SETREGID = 143 -int SYS_SETGID = 144 -int SYS_SETREUID = 145 -int SYS_SETUID = 146 -int SYS_SETRESUID = 147 -int SYS_GETRESUID = 148 -int SYS_SETRESGID = 149 -int SYS_GETRESGID = 150 -int SYS_SETFSUID = 151 -int SYS_SETFSGID = 152 -int SYS_TIMES = 153 -int SYS_SETPGID = 154 -int SYS_GETPGID = 155 -int SYS_GETSID = 156 -int SYS_SETSID = 157 -int SYS_GETGROUPS = 158 -int SYS_SETGROUPS = 159 -int SYS_UNAME = 160 -int SYS_SETHOSTNAME = 161 -int SYS_SETDOMAINNAME = 162 -int SYS_GETRLIMIT = 163 -int SYS_SETRLIMIT = 164 -int SYS_GETRUSAGE = 165 -int SYS_UMASK = 166 -int SYS_PRCTL = 167 -int SYS_GETCPU = 168 -int SYS_GETTIMEOFDAY = 169 -int SYS_SETTIMEOFDAY = 170 -int SYS_ADJTIMEX = 171 -int SYS_GETPID = 172 -int SYS_GETPPID = 173 -int SYS_GETUID = 174 -int SYS_GETEUID = 175 -int SYS_GETGID = 176 -int SYS_GETEGID = 177 -int SYS_GETTID = 178 -int SYS_SYSINFO = 179 -int SYS_MQ_OPEN = 180 -int SYS_MQ_UNLINK = 181 -int SYS_MQ_TIMEDSEND = 182 -int SYS_MQ_TIMEDRECEIVE = 183 -int SYS_MQ_NOTIFY = 184 -int SYS_MQ_GETSETATTR = 185 -int SYS_MSGGET = 186 -int SYS_MSGCTL = 187 -int SYS_MSGRCV = 188 -int SYS_MSGSND = 189 -int SYS_SEMGET = 190 -int SYS_SEMCTL = 191 -int SYS_SEMTIMEDOP = 192 -int SYS_SEMOP = 193 -int SYS_SHMGET = 194 -int SYS_SHMCTL = 195 -int SYS_SHMAT = 196 -int SYS_SHMDT = 197 -int SYS_SOCKET = 198 -int SYS_SOCKETPAIR = 199 -int SYS_BIND = 200 -int SYS_LISTEN = 201 -int SYS_ACCEPT = 202 -int SYS_CONNECT = 203 -int SYS_GETSOCKNAME = 204 -int SYS_GETPEERNAME = 205 -int SYS_SENDTO = 206 -int SYS_RECVFROM = 207 -int SYS_SETSOCKOPT = 208 -int SYS_GETSOCKOPT = 209 -int SYS_SHUTDOWN = 210 -int SYS_SENDMSG = 211 -int SYS_RECVMSG = 212 -int SYS_READAHEAD = 213 -int SYS_BRK = 214 -int SYS_MUNMAP = 215 -int SYS_MREMAP = 216 -int SYS_ADD_KEY = 217 -int SYS_REQUEST_KEY = 218 -int SYS_KEYCTL = 219 -int SYS_CLONE = 220 -int SYS_EXECVE = 221 -int SYS_MMAP = 222 -int SYS_FADVISE64 = 223 -int SYS_SWAPON = 224 -int SYS_SWAPOFF = 225 -int SYS_MPROTECT = 226 -int SYS_MSYNC = 227 -int SYS_MLOCK = 228 -int SYS_MUNLOCK = 229 -int SYS_MLOCKALL = 230 -int SYS_MUNLOCKALL = 231 -int SYS_MINCORE = 232 -int SYS_MADVISE = 233 -int SYS_REMAP_FILE_PAGES = 234 -int SYS_MBIND = 235 -int SYS_GET_MEMPOLICY = 236 -int SYS_SET_MEMPOLICY = 237 -int SYS_MIGRATE_PAGES = 238 -int SYS_MOVE_PAGES = 239 -int SYS_RT_TGSIGQUEUEINFO = 240 -int SYS_PERF_EVENT_OPEN = 241 -int SYS_ACCEPT4 = 242 -int SYS_RECVMMSG = 243 -int SYS_WAIT4 = 260 -int SYS_PRLIMIT64 = 261 -int SYS_FANOTIFY_INIT = 262 -int SYS_FANOTIFY_MARK = 263 -int SYS_NAME_TO_HANDLE_AT = 264 -int SYS_OPEN_BY_HANDLE_AT = 265 -int SYS_CLOCK_ADJTIME = 266 -int SYS_SYNCFS = 267 -int SYS_SETNS = 268 -int SYS_SENDMMSG = 269 -int SYS_PROCESS_VM_READV = 270 -int SYS_PROCESS_VM_WRITEV = 271 -int SYS_KCMP = 272 -int SYS_FINIT_MODULE = 273 -int SYS_SCHED_SETATTR = 274 -int SYS_SCHED_GETATTR = 275 -int SYS_RENAMEAT2 = 276 -int SYS_SECCOMP = 277 -int SYS_GETRANDOM = 278 -int SYS_MEMFD_CREATE = 279 -int SYS_BPF = 280 -int SYS_EXECVEAT = 281 -int SYS_USERFAULTFD = 282 -int SYS_MEMBARRIER = 283 -int SYS_MLOCK2 = 284 -int SYS_COPY_FILE_RANGE = 285 -int SYS_PREADV2 = 286 -int SYS_PWRITEV2 = 287 -int SYS_PKEY_MPROTECT = 288 -int SYS_PKEY_ALLOC = 289 -int SYS_PKEY_FREE = 290 -int SYS_STATX = 291 -int SYS_IO_PGETEVENTS = 292 -int SYS_RSEQ = 293 -int SYS_KEXEC_FILE_LOAD = 294 -int SYS_PIDFD_SEND_SIGNAL = 424 -int SYS_IO_URING_SETUP = 425 -int SYS_IO_URING_ENTER = 426 -int SYS_IO_URING_REGISTER = 427 -int SYS_OPEN_TREE = 428 -int SYS_MOVE_MOUNT = 429 -int SYS_FSOPEN = 430 -int SYS_FSCONFIG = 431 -int SYS_FSMOUNT = 432 -int SYS_FSPICK = 433 -int SYS_PIDFD_OPEN = 434 -int SYS_CLONE3 = 435 -int SYS_CLOSE_RANGE = 436 -int SYS_OPENAT2 = 437 -int SYS_PIDFD_GETFD = 438 -int SYS_FACCESSAT2 = 439 -int SYS_PROCESS_MADVISE = 440 -int SYS_EPOLL_PWAIT2 = 441 -int SYS_MOUNT_SETATTR = 442 -int SYS_QUOTACTL_FD = 443 -int SYS_LANDLOCK_CREATE_RULESET = 444 -int SYS_LANDLOCK_ADD_RULE = 445 -int SYS_LANDLOCK_RESTRICT_SELF = 446 -int SYS_MEMFD_SECRET = 447 -int SYS_PROCESS_MRELEASE = 448 -int SYS_FUTEX_WAITV = 449 -int SYS_SET_MEMPOLICY_HOME_NODE = 450 -int SYS_CACHESTAT = 451 -int SYS_FCHMODAT2 = 452 -int SYS_MAP_SHADOW_STACK = 453 -int SYS_FUTEX_WAKE = 454 -int SYS_FUTEX_WAIT = 455 -int SYS_FUTEX_REQUEUE = 456 -int SYS_STATMOUNT = 457 -int SYS_LISTMOUNT = 458 -int SYS_LSM_GET_SELF_ATTR = 459 -int SYS_LSM_SET_SELF_ATTR = 460 -int SYS_LSM_LIST_MODULES = 461 -int SYS_MSEAL = 462 +const SYS_IO_SETUP = 0 +const SYS_IO_DESTROY = 1 +const SYS_IO_SUBMIT = 2 +const SYS_IO_CANCEL = 3 +const SYS_IO_GETEVENTS = 4 +const SYS_SETXATTR = 5 +const SYS_LSETXATTR = 6 +const SYS_FSETXATTR = 7 +const SYS_GETXATTR = 8 +const SYS_LGETXATTR = 9 +const SYS_FGETXATTR = 10 +const SYS_LISTXATTR = 11 +const SYS_LLISTXATTR = 12 +const SYS_FLISTXATTR = 13 +const SYS_REMOVEXATTR = 14 +const SYS_LREMOVEXATTR = 15 +const SYS_FREMOVEXATTR = 16 +const SYS_GETCWD = 17 +const SYS_LOOKUP_DCOOKIE = 18 +const SYS_EVENTFD2 = 19 +const SYS_EPOLL_CREATE1 = 20 +const SYS_EPOLL_CTL = 21 +const SYS_EPOLL_PWAIT = 22 +const SYS_DUP = 23 +const SYS_DUP3 = 24 +const SYS_FCNTL = 25 +const SYS_INOTIFY_INIT1 = 26 +const SYS_INOTIFY_ADD_WATCH = 27 +const SYS_INOTIFY_RM_WATCH = 28 +const SYS_IOCTL = 29 +const SYS_IOPRIO_SET = 30 +const SYS_IOPRIO_GET = 31 +const SYS_FLOCK = 32 +const SYS_MKNODAT = 33 +const SYS_MKDIRAT = 34 +const SYS_UNLINKAT = 35 +const SYS_SYMLINKAT = 36 +const SYS_LINKAT = 37 +const SYS_RENAMEAT = 38 +const SYS_UMOUNT2 = 39 +const SYS_MOUNT = 40 +const SYS_PIVOT_ROOT = 41 +const SYS_NFSSERVCTL = 42 +const SYS_STATFS = 43 +const SYS_FSTATFS = 44 +const SYS_TRUNCATE = 45 +const SYS_FTRUNCATE = 46 +const SYS_FALLOCATE = 47 +const SYS_FACCESSAT = 48 +const SYS_CHDIR = 49 +const SYS_FCHDIR = 50 +const SYS_CHROOT = 51 +const SYS_FCHMOD = 52 +const SYS_FCHMODAT = 53 +const SYS_FCHOWNAT = 54 +const SYS_FCHOWN = 55 +const SYS_OPENAT = 56 +const SYS_CLOSE = 57 +const SYS_VHANGUP = 58 +const SYS_PIPE2 = 59 +const SYS_QUOTACTL = 60 +const SYS_GETDENTS64 = 61 +const SYS_LSEEK = 62 +const SYS_READ = 63 +const SYS_WRITE = 64 +const SYS_READV = 65 +const SYS_WRITEV = 66 +const SYS_PREAD64 = 67 +const SYS_PWRITE64 = 68 +const SYS_PREADV = 69 +const SYS_PWRITEV = 70 +const SYS_SENDFILE = 71 +const SYS_PSELECT6 = 72 +const SYS_PPOLL = 73 +const SYS_SIGNALFD4 = 74 +const SYS_VMSPLICE = 75 +const SYS_SPLICE = 76 +const SYS_TEE = 77 +const SYS_READLINKAT = 78 +const SYS_NEWFSTATAT = 79 +const SYS_FSTAT = 80 +const SYS_SYNC = 81 +const SYS_FSYNC = 82 +const SYS_FDATASYNC = 83 +const SYS_SYNC_FILE_RANGE = 84 +const SYS_TIMERFD_CREATE = 85 +const SYS_TIMERFD_SETTIME = 86 +const SYS_TIMERFD_GETTIME = 87 +const SYS_UTIMENSAT = 88 +const SYS_ACCT = 89 +const SYS_CAPGET = 90 +const SYS_CAPSET = 91 +const SYS_PERSONALITY = 92 +const SYS_EXIT = 93 +const SYS_EXIT_GROUP = 94 +const SYS_WAITID = 95 +const SYS_SET_TID_ADDRESS = 96 +const SYS_UNSHARE = 97 +const SYS_FUTEX = 98 +const SYS_SET_ROBUST_LIST = 99 +const SYS_GET_ROBUST_LIST = 100 +const SYS_NANOSLEEP = 101 +const SYS_GETITIMER = 102 +const SYS_SETITIMER = 103 +const SYS_KEXEC_LOAD = 104 +const SYS_INIT_MODULE = 105 +const SYS_DELETE_MODULE = 106 +const SYS_TIMER_CREATE = 107 +const SYS_TIMER_GETTIME = 108 +const SYS_TIMER_GETOVERRUN = 109 +const SYS_TIMER_SETTIME = 110 +const SYS_TIMER_DELETE = 111 +const SYS_CLOCK_SETTIME = 112 +const SYS_CLOCK_GETTIME = 113 +const SYS_CLOCK_GETRES = 114 +const SYS_CLOCK_NANOSLEEP = 115 +const SYS_SYSLOG = 116 +const SYS_PTRACE = 117 +const SYS_SCHED_SETPARAM = 118 +const SYS_SCHED_SETSCHEDULER = 119 +const SYS_SCHED_GETSCHEDULER = 120 +const SYS_SCHED_GETPARAM = 121 +const SYS_SCHED_SETAFFINITY = 122 +const SYS_SCHED_GETAFFINITY = 123 +const SYS_SCHED_YIELD = 124 +const SYS_SCHED_GET_PRIORITY_MAX = 125 +const SYS_SCHED_GET_PRIORITY_MIN = 126 +const SYS_SCHED_RR_GET_INTERVAL = 127 +const SYS_RESTART_SYSCALL = 128 +const SYS_KILL = 129 +const SYS_TKILL = 130 +const SYS_TGKILL = 131 +const SYS_SIGALTSTACK = 132 +const SYS_RT_SIGSUSPEND = 133 +const SYS_RT_SIGACTION = 134 +const SYS_RT_SIGPROCMASK = 135 +const SYS_RT_SIGPENDING = 136 +const SYS_RT_SIGTIMEDWAIT = 137 +const SYS_RT_SIGQUEUEINFO = 138 +const SYS_RT_SIGRETURN = 139 +const SYS_SETPRIORITY = 140 +const SYS_GETPRIORITY = 141 +const SYS_REBOOT = 142 +const SYS_SETREGID = 143 +const SYS_SETGID = 144 +const SYS_SETREUID = 145 +const SYS_SETUID = 146 +const SYS_SETRESUID = 147 +const SYS_GETRESUID = 148 +const SYS_SETRESGID = 149 +const SYS_GETRESGID = 150 +const SYS_SETFSUID = 151 +const SYS_SETFSGID = 152 +const SYS_TIMES = 153 +const SYS_SETPGID = 154 +const SYS_GETPGID = 155 +const SYS_GETSID = 156 +const SYS_SETSID = 157 +const SYS_GETGROUPS = 158 +const SYS_SETGROUPS = 159 +const SYS_UNAME = 160 +const SYS_SETHOSTNAME = 161 +const SYS_SETDOMAINNAME = 162 +const SYS_GETRLIMIT = 163 +const SYS_SETRLIMIT = 164 +const SYS_GETRUSAGE = 165 +const SYS_UMASK = 166 +const SYS_PRCTL = 167 +const SYS_GETCPU = 168 +const SYS_GETTIMEOFDAY = 169 +const SYS_SETTIMEOFDAY = 170 +const SYS_ADJTIMEX = 171 +const SYS_GETPID = 172 +const SYS_GETPPID = 173 +const SYS_GETUID = 174 +const SYS_GETEUID = 175 +const SYS_GETGID = 176 +const SYS_GETEGID = 177 +const SYS_GETTID = 178 +const SYS_SYSINFO = 179 +const SYS_MQ_OPEN = 180 +const SYS_MQ_UNLINK = 181 +const SYS_MQ_TIMEDSEND = 182 +const SYS_MQ_TIMEDRECEIVE = 183 +const SYS_MQ_NOTIFY = 184 +const SYS_MQ_GETSETATTR = 185 +const SYS_MSGGET = 186 +const SYS_MSGCTL = 187 +const SYS_MSGRCV = 188 +const SYS_MSGSND = 189 +const SYS_SEMGET = 190 +const SYS_SEMCTL = 191 +const SYS_SEMTIMEDOP = 192 +const SYS_SEMOP = 193 +const SYS_SHMGET = 194 +const SYS_SHMCTL = 195 +const SYS_SHMAT = 196 +const SYS_SHMDT = 197 +const SYS_SOCKET = 198 +const SYS_SOCKETPAIR = 199 +const SYS_BIND = 200 +const SYS_LISTEN = 201 +const SYS_ACCEPT = 202 +const SYS_CONNECT = 203 +const SYS_GETSOCKNAME = 204 +const SYS_GETPEERNAME = 205 +const SYS_SENDTO = 206 +const SYS_RECVFROM = 207 +const SYS_SETSOCKOPT = 208 +const SYS_GETSOCKOPT = 209 +const SYS_SHUTDOWN = 210 +const SYS_SENDMSG = 211 +const SYS_RECVMSG = 212 +const SYS_READAHEAD = 213 +const SYS_BRK = 214 +const SYS_MUNMAP = 215 +const SYS_MREMAP = 216 +const SYS_ADD_KEY = 217 +const SYS_REQUEST_KEY = 218 +const SYS_KEYCTL = 219 +const SYS_CLONE = 220 +const SYS_EXECVE = 221 +const SYS_MMAP = 222 +const SYS_FADVISE64 = 223 +const SYS_SWAPON = 224 +const SYS_SWAPOFF = 225 +const SYS_MPROTECT = 226 +const SYS_MSYNC = 227 +const SYS_MLOCK = 228 +const SYS_MUNLOCK = 229 +const SYS_MLOCKALL = 230 +const SYS_MUNLOCKALL = 231 +const SYS_MINCORE = 232 +const SYS_MADVISE = 233 +const SYS_REMAP_FILE_PAGES = 234 +const SYS_MBIND = 235 +const SYS_GET_MEMPOLICY = 236 +const SYS_SET_MEMPOLICY = 237 +const SYS_MIGRATE_PAGES = 238 +const SYS_MOVE_PAGES = 239 +const SYS_RT_TGSIGQUEUEINFO = 240 +const SYS_PERF_EVENT_OPEN = 241 +const SYS_ACCEPT4 = 242 +const SYS_RECVMMSG = 243 +const SYS_WAIT4 = 260 +const SYS_PRLIMIT64 = 261 +const SYS_FANOTIFY_INIT = 262 +const SYS_FANOTIFY_MARK = 263 +const SYS_NAME_TO_HANDLE_AT = 264 +const SYS_OPEN_BY_HANDLE_AT = 265 +const SYS_CLOCK_ADJTIME = 266 +const SYS_SYNCFS = 267 +const SYS_SETNS = 268 +const SYS_SENDMMSG = 269 +const SYS_PROCESS_VM_READV = 270 +const SYS_PROCESS_VM_WRITEV = 271 +const SYS_KCMP = 272 +const SYS_FINIT_MODULE = 273 +const SYS_SCHED_SETATTR = 274 +const SYS_SCHED_GETATTR = 275 +const SYS_RENAMEAT2 = 276 +const SYS_SECCOMP = 277 +const SYS_GETRANDOM = 278 +const SYS_MEMFD_CREATE = 279 +const SYS_BPF = 280 +const SYS_EXECVEAT = 281 +const SYS_USERFAULTFD = 282 +const SYS_MEMBARRIER = 283 +const SYS_MLOCK2 = 284 +const SYS_COPY_FILE_RANGE = 285 +const SYS_PREADV2 = 286 +const SYS_PWRITEV2 = 287 +const SYS_PKEY_MPROTECT = 288 +const SYS_PKEY_ALLOC = 289 +const SYS_PKEY_FREE = 290 +const SYS_STATX = 291 +const SYS_IO_PGETEVENTS = 292 +const SYS_RSEQ = 293 +const SYS_KEXEC_FILE_LOAD = 294 +const SYS_PIDFD_SEND_SIGNAL = 424 +const SYS_IO_URING_SETUP = 425 +const SYS_IO_URING_ENTER = 426 +const SYS_IO_URING_REGISTER = 427 +const SYS_OPEN_TREE = 428 +const SYS_MOVE_MOUNT = 429 +const SYS_FSOPEN = 430 +const SYS_FSCONFIG = 431 +const SYS_FSMOUNT = 432 +const SYS_FSPICK = 433 +const SYS_PIDFD_OPEN = 434 +const SYS_CLONE3 = 435 +const SYS_CLOSE_RANGE = 436 +const SYS_OPENAT2 = 437 +const SYS_PIDFD_GETFD = 438 +const SYS_FACCESSAT2 = 439 +const SYS_PROCESS_MADVISE = 440 +const SYS_EPOLL_PWAIT2 = 441 +const SYS_MOUNT_SETATTR = 442 +const SYS_QUOTACTL_FD = 443 +const SYS_LANDLOCK_CREATE_RULESET = 444 +const SYS_LANDLOCK_ADD_RULE = 445 +const SYS_LANDLOCK_RESTRICT_SELF = 446 +const SYS_MEMFD_SECRET = 447 +const SYS_PROCESS_MRELEASE = 448 +const SYS_FUTEX_WAITV = 449 +const SYS_SET_MEMPOLICY_HOME_NODE = 450 +const SYS_CACHESTAT = 451 +const SYS_FCHMODAT2 = 452 +const SYS_MAP_SHADOW_STACK = 453 +const SYS_FUTEX_WAKE = 454 +const SYS_FUTEX_WAIT = 455 +const SYS_FUTEX_REQUEUE = 456 +const SYS_STATMOUNT = 457 +const SYS_LISTMOUNT = 458 +const SYS_LSM_GET_SELF_ATTR = 459 +const SYS_LSM_SET_SELF_ATTR = 460 +const SYS_LSM_LIST_MODULES = 461 +const SYS_MSEAL = 462 // sigkill 相关信号 int SIGABRT = 0x6 @@ -853,4 +853,4 @@ fn mount(string source, string target, string fs_type, u32 flags, string data):v fn umount(string target, u32 flags):void! { call6(SYS_UMOUNT2, target.ref(), flags as anyptr, 0, 0, 0, 0) -} \ No newline at end of file +} diff --git a/tests/features/20250329_00_temp_test.c b/tests/features/20250329_00_temp_test.c index 2b6b9e13..f489a7b7 100644 --- a/tests/features/20250329_00_temp_test.c +++ b/tests/features/20250329_00_temp_test.c @@ -11,6 +11,7 @@ int main(void) { // setenv("ENTRY_FILE", "main.n", 1); feature_test_build(); + sleep(1); exec_imm_param(); // feature_testar_test(NULL); } diff --git a/tests/features/20260224_00_global_eval.c b/tests/features/20260224_00_global_eval.c new file mode 100644 index 00000000..67fba809 --- /dev/null +++ b/tests/features/20260224_00_global_eval.c @@ -0,0 +1,5 @@ +#include "tests/test.h" + +int main(void) { + feature_testar_test(NULL); +} diff --git a/tests/features/cases/20221025_07_list.testar b/tests/features/cases/20221025_07_list.testar index e7ef29cc..7a2b1554 100644 --- a/tests/features/cases/20221025_07_list.testar +++ b/tests/features/cases/20221025_07_list.testar @@ -145,9 +145,10 @@ fn main():void! { === test_in_range3 --- main.n -var list = [1, 2, 3, 4] +[int] list = [] fn main():void! { + list = [1, 2, 3, 4] list[3] = list[0] + list[1] + list[2] + list[3] println(list[3]) } diff --git a/tests/features/cases/20230430_03_sort.n b/tests/features/cases/20230430_03_sort.n index 1a199f52..cb4b2435 100644 --- a/tests/features/cases/20230430_03_sort.n +++ b/tests/features/cases/20230430_03_sort.n @@ -9,9 +9,10 @@ fn sort([int] list) { } } -var list = [2, 8, 4, 2, 3] +[int] list = [] fn main() { + list = [2, 8, 4, 2, 3] sort(list) for v in list { diff --git a/tests/features/cases/20230501_00_gc/helper.n b/tests/features/cases/20230501_00_gc/helper.n index e08f38d6..7ff8ecbd 100644 --- a/tests/features/cases/20230501_00_gc/helper.n +++ b/tests/features/cases/20230501_00_gc/helper.n @@ -1,5 +1,10 @@ -[u8] list = [5, 4, 3, 2, 1] +[u8] list = [] -string haha = 'hello world' +string haha = '' -u8 test = 24 \ No newline at end of file +u8 test = 24 + +fn init() { + list = [5, 4, 3, 2, 1] + haha = 'hello world' +} \ No newline at end of file diff --git a/tests/features/cases/20230501_00_gc/main.n b/tests/features/cases/20230501_00_gc/main.n index 96b5ec54..69bfb10d 100644 --- a/tests/features/cases/20230501_00_gc/main.n +++ b/tests/features/cases/20230501_00_gc/main.n @@ -1,7 +1,9 @@ import 'helper.n' import runtime -fn main() { +fn main() { + helper.init() + // 栈干扰 i8 a = 25 i16 a1 = 256 diff --git a/tests/features/cases/20230914_00_global_checking/main.n b/tests/features/cases/20230914_00_global_checking/main.n index 4d6c13c5..a11b0694 100644 --- a/tests/features/cases/20230914_00_global_checking/main.n +++ b/tests/features/cases/20230914_00_global_checking/main.n @@ -1,6 +1,8 @@ import 'mod.n' fn main() { + mod.init() + println(mod.a, mod.b) mod.call() diff --git a/tests/features/cases/20230914_00_global_checking/mod.n b/tests/features/cases/20230914_00_global_checking/mod.n index 6906a704..c87a87c6 100644 --- a/tests/features/cases/20230914_00_global_checking/mod.n +++ b/tests/features/cases/20230914_00_global_checking/mod.n @@ -1,15 +1,19 @@ var a = 12 var b = 12 as u8 -var call = fn() { +fn call() { println('hello world') } int c = 24 var d = 3.1415 -var e = [1, 5, 7, 9] +[int] e = [] int e1 = 2.15 as int var f = false var t = true + +fn init() { + e = [1, 5, 7, 9] +} diff --git a/tests/features/cases/20250227_issue_44.n b/tests/features/cases/20250227_issue_44.n index 95c94ecd..72668b4f 100644 --- a/tests/features/cases/20250227_issue_44.n +++ b/tests/features/cases/20250227_issue_44.n @@ -47,15 +47,15 @@ type AcceptRange = struct { AcceptRange{ lo: 0x90, hi: 0xbf }, AcceptRange{ lo: 0x80, hi: 0x8f }] -u8 xx = 0xF1 // invalid: size 1 -u8 _as= 0xF0 // ASCII: size 1 -u8 s1 = 0x02 // accept 0, size 2 -u8 s2 = 0x13 // accept 1, size 3 -u8 s3 = 0x03 // accept 0, size 3 -u8 s4 = 0x23 // accept 2, size 3 -u8 s5 = 0x34 // accept 3, size 4 -u8 s6 = 0x04 // accept 0, size 4 -u8 s7 = 0x44 // accept 4, size 4 +const xx = 0xF1 // invalid: size 1 +const _as= 0xF0 // ASCII: size 1 +const s1 = 0x02 // accept 0, size 2 +const s2 = 0x13 // accept 1, size 3 +const s3 = 0x03 // accept 0, size 3 +const s4 = 0x23 // accept 2, size 3 +const s5 = 0x34 // accept 3, size 4 +const s6 = 0x04 // accept 0, size 4 +const s7 = 0x44 // accept 4, size 4 [u8;256] accept_sizes = [ // 1 2 3 4 5 6 7 8 9 A B C D E F diff --git a/tests/features/cases/20250402_00_test_error.testar b/tests/features/cases/20250402_00_test_error.testar index 0c0e75af..8aeae7a5 100644 --- a/tests/features/cases/20250402_00_test_error.testar +++ b/tests/features/cases/20250402_00_test_error.testar @@ -171,9 +171,10 @@ catch vec error: index out of range [8] with length 4 === test_global_vec --- main.n -var list = [1, 2, 3, 4] +[int] list = [] fn main():void! { + list = [1, 2, 3, 4] println(list[3]) list[2] = list[3] * 2 println(list[2]) @@ -227,9 +228,11 @@ fn main():void! { === test_vec_index --- main.n -var arr1 = [1, 2, 3, 4] +[int] arr1 = [] fn main():void! { + arr1 = [1, 2, 3, 4] + i32 idx = 2 arr1[idx] = arr1[idx] *2 println(arr1[idx]) diff --git a/tests/features/cases/20250424_00_parker/cgroup.n b/tests/features/cases/20250424_00_parker/cgroup.n index 92ae2253..c975d112 100644 --- a/tests/features/cases/20250424_00_parker/cgroup.n +++ b/tests/features/cases/20250424_00_parker/cgroup.n @@ -9,9 +9,9 @@ import fs u8 version1 = 1 u8 version2 = 2 -string v1_default_system = 'freezer' -string procs_system = 'cgroup.procs' -string parker_dir = 'parker' +const v1_default_system = 'freezer' +const procs_system = 'cgroup.procs' +const parker_dir = 'parker' type cgroup_t = struct { string id diff --git a/tests/features/cases/20250424_00_parker/main.n b/tests/features/cases/20250424_00_parker/main.n index 029323fd..e11ce536 100644 --- a/tests/features/cases/20250424_00_parker/main.n +++ b/tests/features/cases/20250424_00_parker/main.n @@ -7,9 +7,7 @@ import parker.util import compress.tgz import fs - -var version = '0.1.0' - +const version = '0.1.0' fn main():void! { if util.arg_version() { diff --git a/tests/features/cases/20250424_00_parker/runner.n b/tests/features/cases/20250424_00_parker/runner.n index 83ff4051..06c612bb 100644 --- a/tests/features/cases/20250424_00_parker/runner.n +++ b/tests/features/cases/20250424_00_parker/runner.n @@ -9,7 +9,7 @@ import os.signal import co import fs -var version = '0.2.0' +const version = '0.2.0' fn main():void! { if util.arg_verbose() { diff --git a/tests/features/cases/20250424_00_parker/util.n b/tests/features/cases/20250424_00_parker/util.n index fc727320..91cdd8bd 100644 --- a/tests/features/cases/20250424_00_parker/util.n +++ b/tests/features/cases/20250424_00_parker/util.n @@ -9,7 +9,7 @@ import libc import fs import strings -string charset = 'abcdefghijklmnopqrstuvwxyz0123456789' +const charset = 'abcdefghijklmnopqrstuvwxyz0123456789' fn arg_version():bool { var args = os.args() diff --git a/tests/features/cases/20250604_issue_116.testar b/tests/features/cases/20250604_issue_116.testar index c8c1f2a0..ef037c97 100644 --- a/tests/features/cases/20250604_issue_116.testar +++ b/tests/features/cases/20250604_issue_116.testar @@ -34,7 +34,7 @@ type color_t = struct{ u8 a } -[color_t] colors = [ +[color_t;3] colors = [ color_t{r: 186, g: 207, b: 139, a: 255}, color_t{r: 186, g: 207, b: 139, a: 255}, color_t{r: 186, g: 207, b: 139, a: 255}, @@ -263,7 +263,11 @@ type tank_t = struct { i32 health } -var player = {'a': vector2_t{x:890, y:860}, 'b': vector2_t{x:-100, y:-1}} +{string:vector2_t} player = {} + +fn init() { + player = {'a': vector2_t{x:890, y:860}, 'b': vector2_t{x:-100, y:-1}} +} fn fire_bullet(vector2_t position, direction_t direction, bool is_player) { dump(position.x) @@ -278,6 +282,7 @@ fn test1() { } fn main() { + init() test1() } diff --git a/tests/features/cases/20250802_01_test_error.testar b/tests/features/cases/20250802_01_test_error.testar index 16655492..9482b5ef 100644 --- a/tests/features/cases/20250802_01_test_error.testar +++ b/tests/features/cases/20250802_01_test_error.testar @@ -129,9 +129,14 @@ fn main():void! { import time import syscall -var seed = time.now().timestamp() +int seed = 0 + +fn init() { + seed = time.now().timestamp() +} fn main():void! { + init() assert(seed > 0) println(seed) } diff --git a/tests/features/cases/20250826_01_temp_test/package.toml b/tests/features/cases/20250826_01_temp_test/package.toml index 15ff9dae..43062f34 100644 --- a/tests/features/cases/20250826_01_temp_test/package.toml +++ b/tests/features/cases/20250826_01_temp_test/package.toml @@ -1,4 +1,4 @@ -name = "test" +name = "temp" version = "0.4.0" authors = ["weiwenhao "] license = "MIT" @@ -7,4 +7,3 @@ type = "lib" [links] [dependencies] -db = { type = "git", version = "v0.5.0", url = "github.com/weiwenhao/dbdriver" } diff --git a/tests/features/cases/20250906_00_gc_failed.testar b/tests/features/cases/20250906_00_gc_failed.testar index e23c1b6b..b1faf852 100644 --- a/tests/features/cases/20250906_00_gc_failed.testar +++ b/tests/features/cases/20250906_00_gc_failed.testar @@ -50,11 +50,15 @@ type jwt_config_t = struct { } // Global JWT configuration -var jwt_config = jwt_config_t{ - secret_key: "emoji-api.helloworld202509052341", - default_expiry: JWT_DEFAULT_EXPIRY, - issuer: JWT_ISSUER, - algorithm: JWT_ALGORITHM, +var jwt_config = jwt_config_t{} + +fn init() { + jwt_config = jwt_config_t{ + secret_key: "emoji-api.helloworld202509052341", + default_expiry: JWT_DEFAULT_EXPIRY, + issuer: JWT_ISSUER, + algorithm: JWT_ALGORITHM, + } } // Initialize JWT configuration @@ -276,6 +280,7 @@ fn create_signature(string data, string secret):[u8] { } fn main():void! { + init() // init_jwt("emoji-api.helloworld202509052341", 7200, "emoji") for int i = 0; i < 10; i += 1 { runtime.gc() @@ -305,16 +310,24 @@ type jwt_config_t = struct { } // Global JWT configuration -var jwt_config = jwt_config_t{ - secret_key: "emoji-api.helloworld202509052341", - default_expiry: 86400, - issuer: 'emoji', - algorithm: 'HS250', -} +var jwt_config = jwt_config_t{} + +[string;10] global_arr = [] + +string hello = '' -[string;10] global_arr = ['1', 'ab', 'code1', 'code2', 'foo3', 'foo4', 'foo5', 'foo6', 'bar7', 'bar8'] +fn init() { + jwt_config = jwt_config_t{ + secret_key: "emoji-api.helloworld202509052341", + default_expiry: 86400, + issuer: 'emoji', + algorithm: 'HS250', + } + + global_arr = ['1', 'ab', 'code1', 'code2', 'foo3', 'foo4', 'foo5', 'foo6', 'bar7', 'bar8'] -string hello = 'world' + hello = 'world' +} fn main():void! { for int i = 0; i < 10; i += 1 { diff --git a/tests/features/cases/20250923_00_test_error.testar b/tests/features/cases/20250923_00_test_error.testar index 6c444acd..8f7ac065 100644 --- a/tests/features/cases/20250923_00_test_error.testar +++ b/tests/features/cases/20250923_00_test_error.testar @@ -42,7 +42,7 @@ nature-test/main.n:1:3: fn main.pi_test missing return import libc import path -string procs_system = 'cgroup.procs' +const procs_system = 'cgroup.procs' fn dump(string s) { println(s) diff --git a/tests/features/cases/20260125_00_toylang/main.n b/tests/features/cases/20260125_00_toylang/main.n index ce17c953..ba999049 100644 --- a/tests/features/cases/20260125_00_toylang/main.n +++ b/tests/features/cases/20260125_00_toylang/main.n @@ -1,6 +1,9 @@ import "token/token.n" import "lexer/lexer.n" + fn main() { + token.init() + // var tk = token.newToken(token.TokenKindLet, "let", 1, 1) // println(tk.toString()) // println(token.lookupKeyword("name")) diff --git a/tests/features/cases/20260125_00_toylang/token/token.n b/tests/features/cases/20260125_00_toylang/token/token.n index 96265177..67818b0c 100644 --- a/tests/features/cases/20260125_00_toylang/token/token.n +++ b/tests/features/cases/20260125_00_toylang/token/token.n @@ -115,15 +115,19 @@ fn Token.toString(*self): string { return "Token(kind: " + fmt.sprintf("%s",kind) + ", literal: " + fmt.sprintf("%s",self.literal) + ", pos: " + self.pos.toString() + ")" } -var keywords = { - "if": TokenKindIf, - "else": TokenKindElse, - "return": TokenKindReturn, - "fn": TokenKindFunc, - "let": TokenKindLet, - "true": TokenKindTrue, - "false": TokenKindFalse, - "for": TokenKindFor, +{string:int} keywords = {} + +fn init() { + keywords = { + "if": TokenKindIf, + "else": TokenKindElse, + "return": TokenKindReturn, + "fn": TokenKindFunc, + "let": TokenKindLet, + "true": TokenKindTrue, + "false": TokenKindFalse, + "for": TokenKindFor, + } } fn lookupKeyword(string ident): int { diff --git a/tests/features/cases/20260224_00_global_eval.testar b/tests/features/cases/20260224_00_global_eval.testar new file mode 100644 index 00000000..fdce6bca --- /dev/null +++ b/tests/features/cases/20260224_00_global_eval.testar @@ -0,0 +1,180 @@ +=== test_global_struct_assign +--- main.n +type point_t = struct{ + int x + int y +} + +point_t p = point_t{ + x: 7, + y: 9, +} + +fn main() { + println(p.x, p.y) +} + +--- output.txt +7 9 + +=== test_global_default_vec_map_set_string +--- main.n +vec gv = [] +map gm = {} +set gs = {} +string gs0 = '' + +fn main() { + println(gv.len(), gm.len(), gs0.len()) + + gv.push(7) + gm['k'] = 9 + gs.add(3) + + println(gv[0], gm['k'], gs.contains(3)) +} + +--- output.txt +0 0 0 +7 9 true + +=== test_global_cycle_failed +--- main.n +int a = b +int b = a + +fn main() {} + +--- output.txt +nature-test/main.n:1:10: global initializer cannot reference global var 'main.b' + +=== test_global_vec_with_values_failed +--- main.n +vec bad = [1] + +fn main() {} + +--- output.txt +nature-test/main.n:1:17: global vec initializer must be empty + +=== test_global_cycle_three_files_failed +--- main.n +import 'a.n' + +fn main() {} + +--- a.n +import 'b.n'.{b} + +int a = b + +--- b.n +import 'c.n'.{c} + +int b = c + +--- c.n +import 'a.n'.{a} + +int c = a + +--- output.txt +nature-test/c.n:3:9: global initializer cannot reference global var 'nature-test.a.a' + +=== test_global_auto_infer +--- main.n +type user_t = struct{ + int age + bool vip +} + +var g_i = 42 +var g_f = 3.5 +var g_b = true +var g_s = '' +var g_u8 = 255 as u8 +var g_user = user_t{ + age: 18, + vip: false, +} + +fn take_u8(u8 v):u8 { + return v +} + +fn main() { + u8 got = take_u8(g_u8) + println(g_i + 1, g_f + 0.5, g_b, g_s.len(), got, g_user.age, g_user.vip) +} + +--- output.txt +43 4.000000 true 0 255 18 false + +=== test_global_auto_infer_float_as_int +--- main.n +var e1 = 2.15 as int + +fn main() { + println(e1) +} + +--- output.txt +2 + +=== test_global_array_layout_init +--- main.n +type point_t = struct{ + int x + int y +} + +[int;6] nums = [1, 2, 3] +[point_t;3] points = [point_t{ + x: 1, + y: 2, +}] + +fn main() { + println(nums[0], nums[1], nums[2], nums[3], nums[4], nums[5]) + println(points[0].x, points[0].y, points[1].x, points[1].y, points[2].x, points[2].y) +} + +--- output.txt +1 2 3 0 0 0 +1 2 0 0 0 0 + +=== test_global_array_repeat_init +--- main.n +[int;10] list = [0;10] + +fn main() { + println(list[0], list[9]) +} + +--- output.txt +0 0 + +=== test_global_reflect_hash_null +--- main.n +var null_hash = @reflect_hash(null) + +fn main() { + println(null_hash == @reflect_hash(null)) +} + +--- output.txt +true + +=== test_global_import_syscall_const[os=darwin] +--- main.n +import syscall + +var seed = syscall.SYS_GETPPID + +fn main():void! { + assert(seed == syscall.SYS_GETPPID) + println(seed) +} + +--- output.txt +39