nwnrs-nwscript
nwnrs-nwscript is the workspace's pure Rust NWScript frontend and compiler
toolchain. It depends on nwnrs-types for shared IO and resource vocabulary,
but owns the language pipeline itself.
Scope
- source loading and preprocessing
- lexing, parsing, semantic analysis, and optimization
- emission of
NCSandNDBartifacts NCSasm and disassembly through the upstream-stylenwasmtext layer- a lightweight
NCSVM and test-runner layer for exercising compiled scripts - typed vocabulary for NWScript-related binary formats
Internal Structure
sourceandpreprocess: source loading and include handlinglexer,token, andparser: tokenization and syntax constructionast,hir,sema, andir: progressively richer semantic and lowered program formsoptandcodegen: optimization and NCS emissionncs,ndb, andnwasm: binary artifact support plus text asm and disasmvm: lightweight bytecode execution and action-command test harnessdiag,langspec, andhash: diagnostics, builtin language specification, and NWScript-specific string hashing
Public Surface by Stage
Source loading and preprocessing
ScriptResolverSourceBundleSourceFileSourceIdSourceMapSourceLocationSourceLoadOptionsSourceErrorPreprocessedSourcePreprocessErrorIncludeDirectiveload_source_bundlepreprocess_source_bundle
Lexing and parsing
LexerLexerErrorTokenTokenKindKeywordMAX_TOKEN_LENGTHParseErrorParserErrorResolvedParseErrorparse_bytesparse_textparse_tokensparse_sourceparse_source_bundlelex_byteslex_textlex_source
Syntax-layer vocabulary
ScriptTopLevelItemDeclarationFunctionDeclStructDeclStructFieldDeclParameterTypeSpecTypeKindStmtSimpleStmtBlockStmtIfStmtForStmtWhileStmtDoWhileStmtSwitchStmtCaseStmtDefaultStmtReturnStmtExpressionStmtExprExprKindUnaryOpBinaryOpAssignmentOpVarDeclaratorMagicLiteralNamedItem
Semantic and lowered representations
SemanticModelSemanticFunctionSemanticGlobalSemanticStructSemanticFieldSemanticParameterSemanticTypeSemanticOptionsSemanticErrorHirModuleHirFunctionHirStmtHirExprHirExprKindHirStructHirFieldHirGlobalHirLocalHirLocalIdHirLocalKindHirValueRefHirBlockHirParameterHirCallTargetHirDeclaratorHirDeclareStmtHirIfStmtHirForStmtHirDoWhileStmtHirReturnStmtHirSwitchStmtHirLowerErrorIrModuleIrFunctionIrBlockIrBlockIdIrInstructionIrTerminatorIrValueIdIrLocalIdIrGlobalIrLowerErroranalyze_scriptanalyze_script_with_optionslower_to_hirlower_hir_to_ir
Builtins and language specification
LangSpecLangSpecErrorBuiltinTypeBuiltinFunctionBuiltinParameterBuiltinConstantBuiltinValueDEFAULT_LANGSPEC_SCRIPT_NAMENW_SCRIPT_SOURCE_RES_TYPEload_langspecparse_langspecparse_langspec_bytesparse_langspec_from_source_map
Compile and optimization
CompileOptionsCompileArtifactsCompileErrorCodegenErrorCompilerErrorCodeOptimizationLevelcompile_scriptcompile_script_with_source_mapcompile_source_bundlecompile_hir_to_ncs
Artifacts: NCS, NDB, and asm
NCS_HEADERNCS_BINARY_HEADER_SIZENCS_OPERATION_BASE_SIZENcsHeaderNcsHeaderErrorNcsInstructionNcsOpcodeNcsAuxCodeNcsReadErrorNcsAsmErrorNcsAsmLineNcsDisassemblyOptionsNdbNdbFileNdbFunctionNdbLineNdbStructNdbStructFieldNdbTypeNdbVariableNdbErrordecode_ncs_headerdecode_ncs_instructionsencode_ncs_instructionsdisassemble_ncsrender_disassembly_linesrender_ncs_disassemblyrender_ncs_disassembly_with_ndbassemble_ncs_bytesassemble_ncs_textread_ndbparse_ndb_strwrite_ndb
Compiler sessions
CompilerSessionCompilerSessionErrorCompilerSessionOptions
Compiler driver
CompilerHostCompilerHostErrorCompilerDriverOptionsCompilerDriverErrorCompileFileOutcomecompile_file_with_hostFileSystemScriptResolverDirectoryCompilerHostBatchCompileOptionsBatchCompileEntryBatchCompileStatusBatchCompileReportBatchCompileErrorcompile_paths
Graphviz
render_script_graphviz
VM and test execution
VmVmRunOptionsVmScriptVmSituationVmStepOutcomeVmTraceEventVmTraceHookVmValueVmObjectIdVmEngineStructureComparerVmEngineStructureFactoryVmEngineStructureValueVmFunctionInfoVmCommandHandlerVmErrorVmSourceLocation
For compiled scripts that include user-function calls, prefer the NDB-backed
execution path (VmScript::from_bytes_with_ndb, Vm::run_bytes_with_ndb, or
Vm::run_function_bytes) so the VM can recover callee stack layouts. The
direct named-function runner also boots global initializers automatically for
main() and StartingConditional() entry loaders. The debugger-oriented VM
surface also supports single-step execution plus step_over, step_out,
run_until_offset, run_until_function, and run_until_line when attached
NDB metadata is available.
Miscellaneous semantic helpers
Spannwscript_string_hashnwscript_string_hash_bytes
Logical Edges
- the crate intentionally exposes multiple representations instead of pretending parsing and compilation are one stage
LangSpecis part of normal compilation, not an optional afterthought- HIR and IR are real public control points
nwasmis both an artifact boundary and a debugging surface- source loading and include handling are operationally significant
See also
nwnrs_types::resman, which provides the resource layer through which source and compiled script files are typically loadednwnrs_types::install, which resolves the install root and language root needed to locatenwscript.nssfor compilation
Why This Crate Exists
The point of nwnrs-types is to make the language subsystem inspectable and
operable at every meaningful stage, from raw source bundle through lowered IR
and into bytecode and debug artifacts.