WIP on enum generation and solving generated errors.
This commit is contained in:
parent
434df5642a
commit
44f6ab10af
@ -1,4 +1,10 @@
|
|||||||
use crate::spec::{BooleanBuild, BuildSpec, ChildSpec, EnumBuildSpec, EnumRule, LeafEnumBuildSpec, LeafEnumRule, LeafEnumRuleBuild, LeafEnumRuleBuildChild, LeafStructBuildSpec, LeafStructChild, LeafStructChildType, SingleBooleanChildToBuild, SingleChild, SingleChildToBuild, SingleLiteralChildToBuild, SingleTypeChildToBuild, SkipChild, StructBuildSpec, VecChild, VecChildToBuild, VecTypeChildToBuild};
|
use crate::spec::{
|
||||||
|
BooleanBuild, BuildSpec, ChildSpec, EnumBuildSpec, EnumRule, LeafEnumBuildSpec, LeafEnumRule,
|
||||||
|
LeafEnumRuleBuild, LeafEnumRuleBuildChild, LeafStructBuildSpec, LeafStructChild,
|
||||||
|
LeafStructChildType, SingleBooleanChildToBuild, SingleChild, SingleChildToBuild,
|
||||||
|
SingleLiteralChildToBuild, SingleTypeChildToBuild, SkipChild, StructBuildSpec, VecChild,
|
||||||
|
VecChildToBuild, VecTypeChildToBuild,
|
||||||
|
};
|
||||||
use crate::util::make_build_fn_name;
|
use crate::util::make_build_fn_name;
|
||||||
use convert_case::{Case, Casing};
|
use convert_case::{Case, Casing};
|
||||||
use yaml_rust2::{Yaml, YamlLoader};
|
use yaml_rust2::{Yaml, YamlLoader};
|
||||||
@ -218,15 +224,13 @@ fn get_enum_rules(rule_specs: &Yaml) -> Vec<EnumRule> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_leaf_struct_child_specs(children: &Yaml) -> Vec<LeafStructChild> {
|
fn get_leaf_struct_child_specs(children: &Yaml) -> Vec<LeafStructChild> {
|
||||||
children.as_vec()
|
children
|
||||||
|
.as_vec()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|child_spec| {
|
.map(|child_spec| {
|
||||||
let (name, hash) = unwrap_single_member_hash(child_spec);
|
let (name, hash) = unwrap_single_member_hash(child_spec);
|
||||||
LeafStructChild::new(
|
LeafStructChild::new(&name, LeafStructChildType::String)
|
||||||
&name,
|
|
||||||
LeafStructChildType::String
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,13 +9,13 @@ mod util;
|
|||||||
|
|
||||||
use crate::enum_build_fn::make_enum_build_fn;
|
use crate::enum_build_fn::make_enum_build_fn;
|
||||||
use crate::leaf_enum_build_fn::make_leaf_enum_build_fn;
|
use crate::leaf_enum_build_fn::make_leaf_enum_build_fn;
|
||||||
|
use crate::leaf_struct_build_fn::make_leaf_struct_build_fn;
|
||||||
use crate::struct_build_fn::make_struct_build_fn;
|
use crate::struct_build_fn::make_struct_build_fn;
|
||||||
use crate::type_gen::make_type;
|
use crate::type_gen::make_type;
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use spec::BuildSpec;
|
use spec::BuildSpec;
|
||||||
use syn::File;
|
use syn::File;
|
||||||
use crate::leaf_struct_build_fn::make_leaf_struct_build_fn;
|
|
||||||
|
|
||||||
fn debug_built_spec(build_spec: &BuildSpec, token_stream: &TokenStream) {
|
fn debug_built_spec(build_spec: &BuildSpec, token_stream: &TokenStream) {
|
||||||
println!("*** BuildSpec ***");
|
println!("*** BuildSpec ***");
|
||||||
|
|||||||
@ -518,14 +518,14 @@ impl LeafStructChild {
|
|||||||
pub fn new(name: &str, r#type: LeafStructChildType) -> Self {
|
pub fn new(name: &str, r#type: LeafStructChildType) -> Self {
|
||||||
Self {
|
Self {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
r#type
|
r#type,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn r#type(&self) -> &LeafStructChildType {
|
pub fn r#type(&self) -> &LeafStructChildType {
|
||||||
&self.r#type
|
&self.r#type
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,10 +2,9 @@ use crate::spec::{
|
|||||||
BooleanBuild, ChildSpec, SingleBooleanChildToBuild, SingleChildToBuild,
|
BooleanBuild, ChildSpec, SingleBooleanChildToBuild, SingleChildToBuild,
|
||||||
SingleLiteralChildToBuild, SingleTypeChildToBuild, StructBuildSpec, VecChild, VecChildToBuild,
|
SingleLiteralChildToBuild, SingleTypeChildToBuild, StructBuildSpec, VecChild, VecChildToBuild,
|
||||||
};
|
};
|
||||||
use convert_case::{Case, Casing};
|
use crate::util::make_build_pair;
|
||||||
use proc_macro2::{Ident, TokenStream};
|
use proc_macro2::{Ident, TokenStream};
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
use crate::util::make_build_pair;
|
|
||||||
|
|
||||||
fn make_vec_child_holder(vec_child: &VecChild) -> TokenStream {
|
fn make_vec_child_holder(vec_child: &VecChild) -> TokenStream {
|
||||||
let (child_ident, child_type_ident) = match vec_child.build() {
|
let (child_ident, child_type_ident) = match vec_child.build() {
|
||||||
|
|||||||
@ -102,15 +102,35 @@ fn handle_single_type_child(
|
|||||||
#child_ident: Box<#child_type_ident>
|
#child_ident: Box<#child_type_ident>
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
accessors.push(quote! {
|
if single_type_child.optional() {
|
||||||
pub fn #child_ident(&self) -> &#child_type_ident {
|
accessors.push(quote! {
|
||||||
self.#child_ident.as_ref()
|
pub fn #child_ident(&self) -> Option<&#child_type_ident> {
|
||||||
}
|
if let Some(#child_ident) = &self.#child_ident {
|
||||||
|
Some(#child_ident.as_ref())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn #child_ident_mut(&mut self) -> &mut #child_type_ident {
|
pub fn #child_ident_mut(&mut self) -> Option<&mut #child_type_ident> {
|
||||||
self.#child_ident.as_mut()
|
if let Some(#child_ident) = &mut self.#child_ident {
|
||||||
}
|
Some(#child_ident.as_mut())
|
||||||
});
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
accessors.push(quote! {
|
||||||
|
pub fn #child_ident(&self) -> &#child_type_ident {
|
||||||
|
self.#child_ident.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn #child_ident_mut(&mut self) -> &mut #child_type_ident {
|
||||||
|
self.#child_ident.as_mut()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_single_boolean_child(
|
fn handle_single_boolean_child(
|
||||||
@ -229,7 +249,7 @@ fn make_leaf_struct_type(build_spec: &LeafStructBuildSpec) -> TokenStream {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
pub struct #type_ident {
|
pub struct #type_ident {
|
||||||
#(#annotated_members),*
|
#(#annotated_members),*
|
||||||
|
|||||||
@ -6,4 +6,4 @@ pub fn make_build_fn_name(s: &str) -> String {
|
|||||||
|
|
||||||
pub fn make_build_pair(s: &str) -> String {
|
pub fn make_build_pair(s: &str) -> String {
|
||||||
format!("{}_pair", s.to_case(Case::Snake))
|
format!("{}_pair", s.to_case(Case::Snake))
|
||||||
}
|
}
|
||||||
|
|||||||
2
build.rs
2
build.rs
@ -17,7 +17,7 @@ fn generate_parser_tests(out_dir: &Path) -> io::Result<()> {
|
|||||||
fn generate_ast_files(out_dir: &Path) -> io::Result<()> {
|
fn generate_ast_files(out_dir: &Path) -> io::Result<()> {
|
||||||
let gen_ast_dir = out_dir.join("src").join("ast");
|
let gen_ast_dir = out_dir.join("src").join("ast");
|
||||||
fs::create_dir_all(&gen_ast_dir)?;
|
fs::create_dir_all(&gen_ast_dir)?;
|
||||||
|
|
||||||
let ast_yaml = include_str!("src/parser/ast.yaml");
|
let ast_yaml = include_str!("src/parser/ast.yaml");
|
||||||
let build_specs = deserialize::deserialize_yaml_spec(ast_yaml);
|
let build_specs = deserialize::deserialize_yaml_spec(ast_yaml);
|
||||||
let generated_files = generate_files(&build_specs);
|
let generated_files = generate_files(&build_specs);
|
||||||
|
|||||||
@ -46,7 +46,7 @@ pub fn generate_test_files(tests_dir: &Path) -> io::Result<ParserTestSuitesFile>
|
|||||||
let test_suite = quote! {
|
let test_suite = quote! {
|
||||||
mod #tests_mod_ident {
|
mod #tests_mod_ident {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#(#tests)*
|
#(#tests)*
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -59,7 +59,7 @@ pub fn generate_test_files(tests_dir: &Path) -> io::Result<ParserTestSuitesFile>
|
|||||||
// generate main test_suites file
|
// generate main test_suites file
|
||||||
let test_suites = quote! {
|
let test_suites = quote! {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#(#test_suites)*
|
#(#test_suites)*
|
||||||
};
|
};
|
||||||
let test_suites_file: File = syn::parse2(test_suites).unwrap();
|
let test_suites_file: File = syn::parse2(test_suites).unwrap();
|
||||||
|
|||||||
@ -5,6 +5,8 @@ pub mod node {
|
|||||||
pub mod build {
|
pub mod build {
|
||||||
//noinspection RsUnusedImport
|
//noinspection RsUnusedImport
|
||||||
use crate::parser::Rule;
|
use crate::parser::Rule;
|
||||||
|
//noinspection RsUnusedImport
|
||||||
|
use crate::ast::node::*;
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/src/ast/build.rs"));
|
include!(concat!(env!("OUT_DIR"), "/src/ast/build.rs"));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
// mod name_analysis;
|
// mod name_analysis;
|
||||||
// mod p3;
|
// mod p3;
|
||||||
// mod unparse;
|
// mod unparse;
|
||||||
//
|
//
|
||||||
// use std::path::PathBuf;
|
// use std::path::PathBuf;
|
||||||
//
|
//
|
||||||
// use crate::name_analysis::name_analysis;
|
// use crate::name_analysis::name_analysis;
|
||||||
// use crate::p3::pretty_print_parse;
|
// use crate::p3::pretty_print_parse;
|
||||||
// use crate::unparse::unparse;
|
// use crate::unparse::unparse;
|
||||||
// use clap::{Parser, Subcommand};
|
// use clap::{Parser, Subcommand};
|
||||||
//
|
//
|
||||||
// #[derive(Debug, Parser)]
|
// #[derive(Debug, Parser)]
|
||||||
// #[command(name = "dmc")]
|
// #[command(name = "dmc")]
|
||||||
// #[command(about = "Deimos Compiler", long_about = None)]
|
// #[command(about = "Deimos Compiler", long_about = None)]
|
||||||
@ -16,7 +16,7 @@
|
|||||||
// #[command(subcommand)]
|
// #[command(subcommand)]
|
||||||
// command: Commands,
|
// command: Commands,
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// #[derive(Debug, Subcommand)]
|
// #[derive(Debug, Subcommand)]
|
||||||
// enum Commands {
|
// enum Commands {
|
||||||
// #[command(arg_required_else_help = true)]
|
// #[command(arg_required_else_help = true)]
|
||||||
@ -30,7 +30,7 @@
|
|||||||
// paths: Vec<PathBuf>,
|
// paths: Vec<PathBuf>,
|
||||||
// },
|
// },
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// fn main() {
|
// fn main() {
|
||||||
// let args = Cli::parse();
|
// let args = Cli::parse();
|
||||||
// match args.command {
|
// match args.command {
|
||||||
|
|||||||
@ -4,14 +4,12 @@ pub struct DmModule {
|
|||||||
|
|
||||||
pub enum NamespaceVisibility {
|
pub enum NamespaceVisibility {
|
||||||
Public,
|
Public,
|
||||||
Partial {
|
Partial { visible_to_fqns: Vec<String> },
|
||||||
visible_to_fqns: Vec<String>
|
Private,
|
||||||
},
|
|
||||||
Private
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DmNamespace {
|
pub struct DmNamespace {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub dependencies: Vec<String>,
|
pub dependencies: Vec<String>,
|
||||||
pub visibility: NamespaceVisibility
|
pub visibility: NamespaceVisibility,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -415,10 +415,14 @@ InterfaceDefaultOperatorFunction:
|
|||||||
|
|
||||||
# Function Bodies
|
# Function Bodies
|
||||||
FunctionBody:
|
FunctionBody:
|
||||||
|
type: leaf_enum
|
||||||
rules:
|
rules:
|
||||||
- FunctionAliasBody
|
- FunctionAliasBody:
|
||||||
- FunctionEqualsBody
|
child: true
|
||||||
- FunctionBlockBody
|
- FunctionEqualsBody:
|
||||||
|
child: true
|
||||||
|
- FunctionBlockBody:
|
||||||
|
child: true
|
||||||
FunctionEqualsBody:
|
FunctionEqualsBody:
|
||||||
children:
|
children:
|
||||||
- expression
|
- expression
|
||||||
@ -460,14 +464,22 @@ Member:
|
|||||||
|
|
||||||
# Statements
|
# Statements
|
||||||
Statement:
|
Statement:
|
||||||
|
type: leaf_enum
|
||||||
rules:
|
rules:
|
||||||
- VariableDeclaration
|
- VariableDeclaration:
|
||||||
- AssignmentStatement
|
child: true
|
||||||
- ExpressionStatement
|
- AssignmentStatement:
|
||||||
- UseStatement
|
child: true
|
||||||
- IfStatement
|
- ExpressionStatement:
|
||||||
- WhileStatement
|
child: true
|
||||||
- ForStatement
|
- UseStatement:
|
||||||
|
child: true
|
||||||
|
- IfStatement:
|
||||||
|
child: true
|
||||||
|
- WhileStatement:
|
||||||
|
child: true
|
||||||
|
- ForStatement:
|
||||||
|
child: true
|
||||||
VariableDeclaration:
|
VariableDeclaration:
|
||||||
children:
|
children:
|
||||||
- let_kw:
|
- let_kw:
|
||||||
@ -701,17 +713,23 @@ ObjectIndex:
|
|||||||
children:
|
children:
|
||||||
- expression
|
- expression
|
||||||
PrimaryExpression:
|
PrimaryExpression:
|
||||||
|
type: leaf_enum
|
||||||
rules:
|
rules:
|
||||||
- Literal
|
- Literal:
|
||||||
- FullyQualifiedName
|
child: true
|
||||||
- Closure
|
- FullyQualifiedName:
|
||||||
- ParenthesizedExpression
|
child: true
|
||||||
|
- Closure:
|
||||||
|
child: true
|
||||||
|
- ParenthesizedExpression:
|
||||||
|
child: true
|
||||||
ParenthesizedExpression:
|
ParenthesizedExpression:
|
||||||
children:
|
children:
|
||||||
- expression
|
- expression
|
||||||
|
|
||||||
# Calls
|
# Calls
|
||||||
Call:
|
Call:
|
||||||
|
type: leaf_enum
|
||||||
rules:
|
rules:
|
||||||
- ParenthesesCall
|
- ParenthesesCall
|
||||||
- NonParenthesesCall
|
- NonParenthesesCall
|
||||||
@ -762,38 +780,46 @@ ClosureParameter:
|
|||||||
|
|
||||||
# Literals
|
# Literals
|
||||||
Literal:
|
Literal:
|
||||||
|
type: leaf_enum
|
||||||
rules:
|
rules:
|
||||||
- NumberLiteral
|
- NumberLiteral:
|
||||||
- StringLiteral
|
child: true
|
||||||
- BooleanLiteral
|
- StringLiteral:
|
||||||
|
child: true
|
||||||
|
- BooleanLiteral:
|
||||||
|
child: true
|
||||||
NumberLiteral:
|
NumberLiteral:
|
||||||
|
type: leaf_enum
|
||||||
rules:
|
rules:
|
||||||
- DoubleLiteral
|
- DoubleLiteral:
|
||||||
- LongLiteral
|
child: true
|
||||||
- IntLiteral
|
- LongLiteral:
|
||||||
|
child: true
|
||||||
|
- IntLiteral:
|
||||||
|
child: true
|
||||||
IntLiteral:
|
IntLiteral:
|
||||||
children:
|
children:
|
||||||
- number_base
|
- number_base
|
||||||
- literal:
|
|
||||||
build:
|
|
||||||
type: i32
|
|
||||||
LongLiteral:
|
LongLiteral:
|
||||||
children:
|
children:
|
||||||
- number_base
|
- number_base
|
||||||
- literal:
|
|
||||||
build:
|
|
||||||
type: i64
|
|
||||||
DoubleLiteral:
|
DoubleLiteral:
|
||||||
|
type: leaf_struct
|
||||||
children:
|
children:
|
||||||
- literal:
|
- literal:
|
||||||
build:
|
build:
|
||||||
type: f64
|
type: f64
|
||||||
NumberBase:
|
NumberBase:
|
||||||
|
type: leaf_enum
|
||||||
rules:
|
rules:
|
||||||
- BinaryBase
|
- BinaryBase:
|
||||||
- HexadecimalBase
|
child: true
|
||||||
- DecimalBase
|
- HexadecimalBase:
|
||||||
|
child: true
|
||||||
|
- DecimalBase:
|
||||||
|
child: true
|
||||||
DecimalBase:
|
DecimalBase:
|
||||||
|
type: leaf_struct
|
||||||
children:
|
children:
|
||||||
- literal:
|
- literal:
|
||||||
build:
|
build:
|
||||||
@ -802,6 +828,7 @@ BinaryBase:
|
|||||||
children:
|
children:
|
||||||
- binary_digits
|
- binary_digits
|
||||||
BinaryDigits:
|
BinaryDigits:
|
||||||
|
type: leaf_struct
|
||||||
children:
|
children:
|
||||||
- literal:
|
- literal:
|
||||||
build:
|
build:
|
||||||
@ -810,15 +837,20 @@ HexadecimalBase:
|
|||||||
children:
|
children:
|
||||||
- hexadecimal_digits
|
- hexadecimal_digits
|
||||||
HexadecimalDigits:
|
HexadecimalDigits:
|
||||||
|
type: leaf_struct
|
||||||
children:
|
children:
|
||||||
- literal:
|
- literal:
|
||||||
build:
|
build:
|
||||||
type: string
|
type: string
|
||||||
StringLiteral:
|
StringLiteral:
|
||||||
|
type: leaf_enum
|
||||||
rules:
|
rules:
|
||||||
- SingleQuoteString
|
- SingleQuoteString:
|
||||||
- DoubleQuoteString
|
child: true
|
||||||
- BacktickString
|
- DoubleQuoteString:
|
||||||
|
child: true
|
||||||
|
- BacktickString:
|
||||||
|
child: true
|
||||||
SingleQuoteString:
|
SingleQuoteString:
|
||||||
children:
|
children:
|
||||||
- string_inner:
|
- string_inner:
|
||||||
@ -832,11 +864,13 @@ DoubleQuoteString:
|
|||||||
rule: DStringExpression
|
rule: DStringExpression
|
||||||
vec: true
|
vec: true
|
||||||
StringInner:
|
StringInner:
|
||||||
|
type: leaf_struct
|
||||||
children:
|
children:
|
||||||
- literal:
|
- literal:
|
||||||
build:
|
build:
|
||||||
type: string
|
type: string
|
||||||
DStringInner:
|
DStringInner:
|
||||||
|
type: leaf_struct
|
||||||
children:
|
children:
|
||||||
- literal:
|
- literal:
|
||||||
build:
|
build:
|
||||||
@ -853,11 +887,13 @@ BacktickString:
|
|||||||
rule: DStringExpression
|
rule: DStringExpression
|
||||||
vec: true
|
vec: true
|
||||||
BacktickInner:
|
BacktickInner:
|
||||||
|
type: leaf_struct
|
||||||
children:
|
children:
|
||||||
- literal:
|
- literal:
|
||||||
build:
|
build:
|
||||||
type: string
|
type: string
|
||||||
BooleanLiteral:
|
BooleanLiteral:
|
||||||
|
type: leaf_struct
|
||||||
children:
|
children:
|
||||||
- literal:
|
- literal:
|
||||||
build:
|
build:
|
||||||
|
|||||||
@ -5,9 +5,13 @@ pub struct IndentWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl IndentWriter {
|
impl IndentWriter {
|
||||||
pub fn new(start_level: usize, indent_string: &str, out: Box<dyn std::io::Write>) -> IndentWriter {
|
pub fn new(
|
||||||
|
start_level: usize,
|
||||||
|
indent_string: &str,
|
||||||
|
out: Box<dyn std::io::Write>,
|
||||||
|
) -> IndentWriter {
|
||||||
IndentWriter {
|
IndentWriter {
|
||||||
indent_level: start_level,
|
indent_level: start_level,
|
||||||
indent_string: indent_string.to_string(),
|
indent_string: indent_string.to_string(),
|
||||||
out,
|
out,
|
||||||
}
|
}
|
||||||
@ -24,7 +28,7 @@ impl IndentWriter {
|
|||||||
pub fn write(&mut self, s: &str) -> std::io::Result<()> {
|
pub fn write(&mut self, s: &str) -> std::io::Result<()> {
|
||||||
write!(self.out, "{}", s)
|
write!(self.out, "{}", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn writeln(&mut self, s: &str) -> std::io::Result<()> {
|
pub fn writeln(&mut self, s: &str) -> std::io::Result<()> {
|
||||||
self.write(&format!("{}\n", s))
|
self.write(&format!("{}\n", s))
|
||||||
}
|
}
|
||||||
@ -35,7 +39,7 @@ impl IndentWriter {
|
|||||||
}
|
}
|
||||||
write!(self.out, "{}", s)
|
write!(self.out, "{}", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn writeln_indented(&mut self, s: &str) -> std::io::Result<()> {
|
pub fn writeln_indented(&mut self, s: &str) -> std::io::Result<()> {
|
||||||
self.write_indented(&format!("{}\n", s))
|
self.write_indented(&format!("{}\n", s))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum DvmConstant {
|
pub enum DvmConstant {
|
||||||
String(String),
|
String(String),
|
||||||
Array(DvmConstantArray)
|
Array(DvmConstantArray),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -13,5 +13,5 @@ pub enum DvmConstantArray {
|
|||||||
USizes(Vec<usize>),
|
USizes(Vec<usize>),
|
||||||
Booleans(Vec<bool>),
|
Booleans(Vec<bool>),
|
||||||
Strings(Vec<String>),
|
Strings(Vec<String>),
|
||||||
Arrays(Vec<DvmConstantArray>)
|
Arrays(Vec<DvmConstantArray>),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,7 @@ impl DvmFunction {
|
|||||||
pub fn instructions(&self) -> &Vec<Instruction> {
|
pub fn instructions(&self) -> &Vec<Instruction> {
|
||||||
&self.instructions
|
&self.instructions
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn source_code_location(&self) -> &SourceCodeLocation {
|
pub fn source_code_location(&self) -> &SourceCodeLocation {
|
||||||
&self.source_code_location
|
&self.source_code_location
|
||||||
}
|
}
|
||||||
|
|||||||
@ -111,8 +111,8 @@ pub enum Instruction {
|
|||||||
},
|
},
|
||||||
Return,
|
Return,
|
||||||
DumpState {
|
DumpState {
|
||||||
message: String
|
message: String,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|||||||
@ -21,7 +21,7 @@ impl DvmMethod {
|
|||||||
implements,
|
implements,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fqn(&self) -> &str {
|
pub fn fqn(&self) -> &str {
|
||||||
self.function.fqn()
|
self.function.fqn()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ impl SourceCodeLocation {
|
|||||||
SourceCodeLocation {
|
SourceCodeLocation {
|
||||||
source_file_name: source_file_name.to_string(),
|
source_file_name: source_file_name.to_string(),
|
||||||
line,
|
line,
|
||||||
col
|
col,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,9 +7,9 @@ pub enum DvmType {
|
|||||||
Double,
|
Double,
|
||||||
Boolean,
|
Boolean,
|
||||||
USize,
|
USize,
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
Object,
|
Object,
|
||||||
Array,
|
Array,
|
||||||
ConstantPointer
|
ConstantPointer,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,7 +70,7 @@ impl DvmValue {
|
|||||||
panic!("Expected DvmValue::Int, but found DvmValue::{:?}", self);
|
panic!("Expected DvmValue::Int, but found DvmValue::{:?}", self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expect_int_or_else(&self, f: impl FnOnce(&Self) -> i32) -> i32 {
|
pub fn expect_int_or_else(&self, f: impl FnOnce(&Self) -> i32) -> i32 {
|
||||||
if let DvmValue::Int(i) = self {
|
if let DvmValue::Int(i) = self {
|
||||||
*i
|
*i
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user