summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2025-02-11 15:48:02 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2025-02-11 15:48:02 +1300
commitce47e3b24ea37748b809cb5c53b217b6474e0fd3 (patch)
tree398074b00b2b795645d45bc3af454966661d3161
parent2b4e522b12a7eb87e91cd1cdc56064ee429a5212 (diff)
downloadtorque-asm-ce47e3b24ea37748b809cb5c53b217b6474e0fd3.zip
Define semantic types
-rw-r--r--src/environment.rs2
-rw-r--r--src/parsers/semantic.rs19
-rw-r--r--src/tokens/semantic.rs73
3 files changed, 38 insertions, 56 deletions
diff --git a/src/environment.rs b/src/environment.rs
index 006b45b..d88e1b5 100644
--- a/src/environment.rs
+++ b/src/environment.rs
@@ -54,7 +54,7 @@ impl Scope {
pub enum Definition {
Integer(IntegerDefinition),
- Block(BlockLiteral),
+ Block,
}
pub enum IntegerDefinition {
diff --git a/src/parsers/semantic.rs b/src/parsers/semantic.rs
index 94ed70c..6576b44 100644
--- a/src/parsers/semantic.rs
+++ b/src/parsers/semantic.rs
@@ -1,21 +1,2 @@
use crate::*;
-
-pub struct SemanticParser {
- pub syntactic_tokens: Vec<SyntacticToken>,
- pub semantic_tokens: Vec<SemanticToken>,
-}
-
-
-impl SemanticParser {
- pub fn new(syntactic_tokens: Vec<SyntacticToken>) -> Self {
- Self {
- syntactic_tokens,
- semantic_tokens: Vec::new(),
- }
- }
-
- pub fn parse(&mut self) {
- todo!()
- }
-}
diff --git a/src/tokens/semantic.rs b/src/tokens/semantic.rs
index ed53685..a665b9a 100644
--- a/src/tokens/semantic.rs
+++ b/src/tokens/semantic.rs
@@ -1,60 +1,62 @@
use crate::*;
-pub enum SemanticToken {
- MacroDefinition,
- Invocation,
+/// The entire semantic program, ready to generate bytecode.
+pub struct Program {
+ pub definitions: Vec<Definition>,
+ pub invocations: Vec<Invocation>,
}
-pub struct Invocation {
+/// A symbol definition.
+pub struct Definition {
pub name: String,
- pub bytecode: BytecodeSpan,
- pub arguments: Vec<InvocationArgument>,
-}
-
-pub struct BlockLiteral {
- pub tokens: Vec<BlockToken>,
+ pub source: SourceSpan,
+ pub arguments: Vec<ArgumentDefinition>,
+ pub variant: DefinitionVariant,
}
-pub struct BlockToken {
+pub struct ArgumentDefinition {
+ pub name: String,
pub source: SourceSpan,
- pub bytecode: BytecodeSpan,
- pub variant: BlockTokenVariant,
+ pub variant: ArgumentDefinitionVariant,
}
-pub enum BlockTokenVariant {
- Invocation(Invocation),
- Word(PackedBinaryLiteral),
+pub enum ArgumentDefinitionVariant {
+ Integer,
+ Block,
}
-pub struct MacroDefinition {
- pub name: String,
- pub arguments: Vec<DefinitionArgument>,
- pub body: BlockLiteral,
+pub enum DefinitionVariant {
+ Integer(IntegerDefinition),
+ Block(Vec<BlockToken>),
}
-// -------------------------------------------------------------------------- //
-
-pub struct SemanticParseError {
+pub struct IntegerDefinition {
pub source: SourceSpan,
- pub variant: SemanticParseErrorVariant,
+ pub variant: IntegerDefinitionVariant,
}
-pub enum SemanticParseErrorVariant {
+pub enum IntegerDefinitionVariant {
+ Literal(usize),
+ Constant(ConstantExpression),
+ Reference(String),
+}
+pub struct BlockToken {
+ pub source: SourceSpan,
+ pub variant: BlockTokenVariant,
}
-// -------------------------------------------------------------------------- //
+pub enum BlockTokenVariant {
+ Invocation(Invocation),
+ Comment(String),
+ Word(PackedBinaryLiteral),
+}
-pub struct DefinitionArgument {
+pub struct Invocation {
pub name: String,
pub source: SourceSpan,
- pub variant: DefinitionArgumentVariant,
-}
-
-pub enum DefinitionArgumentVariant {
- Integer,
- Block,
+ pub arguments: Vec<InvocationArgument>,
}
pub struct InvocationArgument {
@@ -63,9 +65,8 @@ pub struct InvocationArgument {
}
pub enum InvocationArgumentVariant {
- BlockLiteral(BlockLiteral),
+ BlockLiteral(Vec<BlockToken>),
IntegerLiteral(usize),
ConstantExpression(ConstantExpression),
- Invocation(Invocation),
+ Reference(String),
}
-