Skip to content

Commit

Permalink
Tool v1 (#48)
Browse files Browse the repository at this point in the history
* initial parsing work

* parse trait declarations

* import statements

* clean lexer tree; support method calls

* basic ast skeleton beginnings

* begin ast work

* checkpoint while i swap computers

* more ast parsing

* more ast parsing

* ast: function appl, func decl, var exp

* ast: literals

* add compiler binary with nice error messages

* ast: return statements, use statements

* fix error message

* ast: traits

* more friendly parse error messages

* old email

* semicolons!

* byte literals; fix tests

* parse binary and hex literals for byte and bytes32

* refactor expression parsing

* parse array exprs

* parse operator expressions

* type ascriptions

* parser: polymorphism and trait bounds

* default to u64 instead of u32

* begin work on match statements

* parse structs

* refactor

* a few program examples; parse match statements

* lex struct expressions

* parse to AST struct expressions

* compile warnings!

* assert_or_warn macro

* generic struct parameters

* parse contract/script/predicate

* improve top level failure error message

* s/ast/parse_tree

* enums

* begin semantic analysis

* begin work on type checking, inferencing, and semantics checking (#11)

* begin work on type checking, inferencing, and semantics checking

* fmt

* WIP; laptop dying

* match branch types

* wip type code blocks

* build failure

* operator parsing; no precedence

* compile fn

* run compile instead of parse from hllc

* begin trait declarations in ast

* return statements in AST

* allow code blocks

* handle implicit returns in code blocks

* type checking is taking shape

* generic type checking

* return multiple errors

* proper operator precedence

* add fn params to namespace when typechecking

* contextual error messages

* remove todo panics

* toml update

* small error msg tweak

* Refactor error and warning handling (#12)

* begin refactor of error/warnings

* finish refactor

* type check predicates

* limit number of script main functions

* parse generic types for traits

* grammar for reassignments and while loops

* variable reassignments; while loops

* check generic type params in function declarations

* fix tests

* grammar for inline asm

* Asm expressions (#13)

* begin implementing asm expressions

* WIP asm parsing

* fix up spans; unused value warning

* progress on trait impl

* impl traits

* big refactor

* fix asm op parsing error

* parsing for method applications

* struct expressions and declarations: type inference

* WIP subfield exprs

* subfield expressions

* baaasic method invocations

* impl self; better struct declarations

* begin package manager work

* begin work on package manager

* WIP checkpoint

* forc build MVP implemenation

* dependency resolution v1

* Namespace refactor (#22)

* begin namespace refactor

* move all hashmaps to namespace type

* compiles imported dependencies

* method not found error

* resolve some warnings

* fix Self type in trait implementations

* fix all warnings

* fix todo error messages

* introduce differentiation between generic and struct types

* refactor struct expression typing to use declarations

* fix lack of self type in trait implementation

* refactor typed expressions

* fix impl self namespace bug

* fix implicit return typechecking bug

* re-introduce function applications

* type check function return statements

* remove hllc

* fix only last expr having type annotation; if branch enforcement of having an else

* Control flow analysis + more (#28)

* begin documentation of control flow analysis algorithm

* begin graph construction

* begin graph construction

* generate graphs; further control flow work

* some improvements in control flow; still need to wire up imports into the control flow graph

* control flow graph improvements

* fix up implicit return printing in control flow graph

* organize graph code

* find dead code

* unreachable code warnings

* parse unit type as type info

* start enum expressions

* fix enum lookup bug

* type check all enum instantiations

* Resolved types (#29)

* begin swappnig over to resolved types

* progress in refactore

* progress on converting types

* progress in switching to resolved types

* progress in switching to resolved types

* finalize refactor to resolved types

* remove unused type variants

* fix tests

* enum variant construction code analysis

* resolve warnings

* missing enum instantiator error

* trait declarations control flow

* fix trait type mismatch error message

* individual method dead code warnings

* fix method call bug

* respect public visibility modifiers; control flow analysis on libraries

* add public traits

* move ident file

* begin analysis on return paths

* refactor of files

* begin work on analyzing return paths

* basic return path graph construction done

* documentation

* Return path analysis (#30)

* begin analysis on return paths

* refactor of files

* begin work on analyzing return paths

* basic return path graph construction done

* documentation

* fix code block type parsing

* control flow analysis on if and code blocks

* struct fields in graph

* individual struct field warnings

* added ignore vscode local settings

* added forc commands and restructured files

* format code

* ignore node modules

* added syntax highlighting in vscode-forc

* rename to snippets

* change to fume

* added fume-server as a member

* updated .gitignore with ts files

* added vscode client

* update package.json

* added initial fume-server

* add line_col method for errors and warnings

* adding capabilities

* installed ropey

* update to new structure

* perform diagnostic

* added text_document

* remove unused

* cargo fmt

* clean up

* introduce better document state managment

* added hover and completion

* fixed ranges

* added semantic tokens, go to defnition

* remove other go_tos

* clean up

* update merging with master

* added clear names

* move to token references

* rename to get_diagnostics

* fix master conflicts

* make public fields

* use core_lang instead of parser

* adjust to new parse result

* update plugin start instructions

* fix typo

* clear both lines and values hashmaps

* remove unused enum fields

* move settings.json ignore to git/info/exclude

* re-added appache license

* added MANIFEST_FILE_NAME

* formatted toml files

* fromatted launch.json

* add static values for token types

* format

* fix typo

Co-authored-by: Alex <alex@42layers.io>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
  • Loading branch information
3 people committed May 21, 2021
1 parent 605a426 commit 66bac57
Show file tree
Hide file tree
Showing 75 changed files with 4,193 additions and 97 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# Ignore Typescript files
out
node_modules
.vscode-test
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[workspace]

members = ["core_lang", "forc", "test_suite"]
members = ["core_lang", "forc", "test_suite", "fume-server"]

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
4 changes: 2 additions & 2 deletions core_lang/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use pest::Span;
use std::hash::{Hash, Hasher};
#[derive(Debug, Clone)]
pub struct Ident<'sc> {
pub(crate) primary_name: &'sc str,
pub primary_name: &'sc str,
// sub-names are the stuff after periods
// like x.test.thing.method()
// `test`, `thing`, and `method` are sub-names
// the primary name is `x`
pub(crate) span: Span<'sc>,
pub span: Span<'sc>,
}

// custom implementation of Hash so that namespacing isn't reliant on the span itself, which will
Expand Down
17 changes: 8 additions & 9 deletions core_lang/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod parse_tree;
mod parser;
mod semantic_analysis;

use crate::parse_tree::*;
pub use crate::parse_tree::*;
use crate::parser::{HllParser, Rule};
use crate::{asm_generation::compile_ast_to_asm, error::*};
pub use asm_generation::{AbstractInstructionSet, FinalizedAsm, HllAsmSet};
Expand All @@ -20,10 +20,9 @@ use pest::iterators::Pair;
use pest::Parser;
use semantic_analysis::{TreeType, TypedParseTree};
use std::collections::HashMap;

pub(crate) mod types;
pub(crate) mod utils;
pub(crate) use crate::parse_tree::{Expression, UseStatement, WhileLoop};
pub use crate::parse_tree::{Declaration, Expression, UseStatement, WhileLoop};

pub use error::{CompileError, CompileResult, CompileWarning};
pub use ident::Ident;
Expand Down Expand Up @@ -59,18 +58,18 @@ pub struct ParseTree<'sc> {
/// In a typical programming language, you might have a single root node for your syntax tree.
/// In this language however, we want to expose multiple public functions at the root
/// level so the tree is multi-root.
root_nodes: Vec<AstNode<'sc>>,
span: Span<'sc>,
pub root_nodes: Vec<AstNode<'sc>>,
pub span: Span<'sc>,
}

#[derive(Debug, Clone)]
struct AstNode<'sc> {
content: AstNodeContent<'sc>,
span: Span<'sc>,
pub struct AstNode<'sc> {
pub content: AstNodeContent<'sc>,
pub span: Span<'sc>,
}

#[derive(Debug, Clone)]
pub(crate) enum AstNodeContent<'sc> {
pub enum AstNodeContent<'sc> {
UseStatement(UseStatement<'sc>),
ReturnStatement(ReturnStatement<'sc>),
Declaration(Declaration<'sc>),
Expand Down
4 changes: 2 additions & 2 deletions core_lang/src/parse_tree/call_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use pest::Span;
/// in the expression `a::b::c()`, `a` and `b` are the prefixes and `c` is the suffix.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct CallPath<'sc> {
pub(crate) prefixes: Vec<Ident<'sc>>,
pub(crate) suffix: Ident<'sc>,
pub prefixes: Vec<Ident<'sc>>,
pub suffix: Ident<'sc>,
}

impl<'sc> std::convert::From<Ident<'sc>> for CallPath<'sc> {
Expand Down
4 changes: 2 additions & 2 deletions core_lang/src/parse_tree/code_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use pest::Span;
use std::collections::HashMap;

#[derive(Debug, Clone)]
pub(crate) struct CodeBlock<'sc> {
pub(crate) contents: Vec<AstNode<'sc>>,
pub struct CodeBlock<'sc> {
pub contents: Vec<AstNode<'sc>>,
pub(crate) scope: HashMap<&'sc str, Declaration<'sc>>,
pub(crate) whole_block_span: Span<'sc>,
}
Expand Down
2 changes: 1 addition & 1 deletion core_lang/src/parse_tree/declaration/enum_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use pest::iterators::Pair;
use pest::Span;
#[derive(Debug, Clone)]
pub struct EnumDeclaration<'sc> {
pub(crate) name: Ident<'sc>,
pub name: Ident<'sc>,
pub(crate) type_parameters: Vec<TypeParameter<'sc>>,
pub(crate) variants: Vec<EnumVariant<'sc>>,
pub(crate) span: Span<'sc>,
Expand Down
6 changes: 3 additions & 3 deletions core_lang/src/parse_tree/declaration/function_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ impl Visibility {
}

#[derive(Debug, Clone)]
pub(crate) struct FunctionDeclaration<'sc> {
pub(crate) name: Ident<'sc>,
pub struct FunctionDeclaration<'sc> {
pub name: Ident<'sc>,
pub(crate) visibility: Visibility,
pub(crate) body: CodeBlock<'sc>,
pub body: CodeBlock<'sc>,
pub(crate) parameters: Vec<FunctionParameter<'sc>>,
pub(crate) span: pest::Span<'sc>,
pub(crate) return_type: TypeInfo<'sc>,
Expand Down
4 changes: 2 additions & 2 deletions core_lang/src/parse_tree/declaration/impl_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pest::iterators::Pair;
use pest::Span;

#[derive(Debug, Clone)]
pub(crate) struct ImplTrait<'sc> {
pub struct ImplTrait<'sc> {
pub(crate) trait_name: CallPath<'sc>,
pub(crate) type_implementing_for: TypeInfo<'sc>,
pub(crate) type_arguments: Vec<TypeParameter<'sc>>,
Expand All @@ -18,7 +18,7 @@ pub(crate) struct ImplTrait<'sc> {
/// An impl of methods without a trait
/// like `impl MyType { fn foo { .. } }`
#[derive(Debug, Clone)]
pub(crate) struct ImplSelf<'sc> {
pub struct ImplSelf<'sc> {
pub(crate) type_implementing_for: TypeInfo<'sc>,
pub(crate) type_arguments: Vec<TypeParameter<'sc>>,
pub(crate) functions: Vec<FunctionDeclaration<'sc>>,
Expand Down
4 changes: 2 additions & 2 deletions core_lang/src/parse_tree/declaration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) use reassignment::*;
pub(crate) use struct_declaration::*;
pub(crate) use trait_declaration::*;
pub(crate) use type_parameter::*;
pub(crate) use variable_declaration::*;
pub use variable_declaration::*;

use crate::error::*;
use crate::parse_tree::Expression;
Expand All @@ -24,7 +24,7 @@ use crate::Ident;
use pest::iterators::Pair;

#[derive(Debug, Clone)]
pub(crate) enum Declaration<'sc> {
pub enum Declaration<'sc> {
VariableDeclaration(VariableDeclaration<'sc>),
FunctionDeclaration(FunctionDeclaration<'sc>),
TraitDeclaration(TraitDeclaration<'sc>),
Expand Down
6 changes: 3 additions & 3 deletions core_lang/src/parse_tree/declaration/reassignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use pest::iterators::Pair;
use pest::Span;

#[derive(Debug, Clone)]
pub(crate) struct Reassignment<'sc> {
pub struct Reassignment<'sc> {
// the thing being reassigned
pub(crate) lhs: Ident<'sc>,
pub lhs: Ident<'sc>,
// the expression that is being assigned to the lhs
pub(crate) rhs: Expression<'sc>,
pub rhs: Expression<'sc>,
pub(crate) span: Span<'sc>,
}

Expand Down
2 changes: 1 addition & 1 deletion core_lang/src/parse_tree/declaration/struct_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::Visibility;

#[derive(Debug, Clone)]
pub struct StructDeclaration<'sc> {
pub(crate) name: Ident<'sc>,
pub name: Ident<'sc>,
pub(crate) fields: Vec<StructField<'sc>>,
pub(crate) type_parameters: Vec<TypeParameter<'sc>>,
pub(crate) visibility: Visibility,
Expand Down
4 changes: 2 additions & 2 deletions core_lang/src/parse_tree/declaration/trait_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use pest::iterators::Pair;
use pest::Span;

#[derive(Debug, Clone)]
pub(crate) struct TraitDeclaration<'sc> {
pub(crate) name: Ident<'sc>,
pub struct TraitDeclaration<'sc> {
pub name: Ident<'sc>,
pub(crate) interface_surface: Vec<TraitFn<'sc>>,
pub(crate) methods: Vec<FunctionDeclaration<'sc>>,
pub(crate) type_parameters: Vec<TypeParameter<'sc>>,
Expand Down
10 changes: 5 additions & 5 deletions core_lang/src/parse_tree/declaration/variable_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crate::parse_tree::Expression;
use crate::{types::TypeInfo, Ident};

#[derive(Debug, Clone)]
pub(crate) struct VariableDeclaration<'sc> {
pub(crate) name: Ident<'sc>,
pub(crate) type_ascription: Option<TypeInfo<'sc>>,
pub(crate) body: Expression<'sc>, // will be codeblock variant
pub(crate) is_mutable: bool,
pub struct VariableDeclaration<'sc> {
pub name: Ident<'sc>,
pub type_ascription: Option<TypeInfo<'sc>>,
pub body: Expression<'sc>, // will be codeblock variant
pub is_mutable: bool,
}
2 changes: 1 addition & 1 deletion core_lang/src/parse_tree/expression/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::Expression;
use crate::types::IntegerBits;

#[derive(Debug, Clone)]
pub(crate) struct AsmExpression<'sc> {
pub struct AsmExpression<'sc> {
pub(crate) registers: Vec<AsmRegisterDeclaration<'sc>>,
pub(crate) body: Vec<AsmOp<'sc>>,
pub(crate) returns: Option<(AsmRegister, Span<'sc>)>,
Expand Down
8 changes: 4 additions & 4 deletions core_lang/src/parse_tree/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::utils::join_spans;
pub(crate) use asm::*;

#[derive(Debug, Clone)]
pub(crate) enum Expression<'sc> {
pub enum Expression<'sc> {
Literal {
value: Literal<'sc>,
span: Span<'sc>,
Expand Down Expand Up @@ -110,7 +110,7 @@ pub(crate) enum Expression<'sc> {
}

#[derive(Debug, Clone)]
pub(crate) struct StructExpressionField<'sc> {
pub struct StructExpressionField<'sc> {
pub(crate) name: Ident<'sc>,
pub(crate) value: Expression<'sc>,
pub(crate) span: Span<'sc>,
Expand Down Expand Up @@ -633,7 +633,7 @@ impl<'sc> Expression<'sc> {
}

#[derive(Debug, Clone)]
pub(crate) struct MatchBranch<'sc> {
pub struct MatchBranch<'sc> {
pub(crate) condition: MatchCondition<'sc>,
pub(crate) result: Expression<'sc>,
pub(crate) span: Span<'sc>,
Expand Down Expand Up @@ -727,7 +727,7 @@ impl<'sc> MatchBranch<'sc> {
}

#[derive(Clone, Debug)]
pub(crate) enum UnaryOp {
pub enum UnaryOp {
Not,
Ref,
Deref,
Expand Down
2 changes: 1 addition & 1 deletion core_lang/src/parse_tree/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use pest::Span;
use std::convert::TryInto;

#[derive(Debug, Clone, Eq, PartialEq)]
pub(crate) enum Literal<'sc> {
pub enum Literal<'sc> {
U8(u8),
U16(u16),
U32(u32),
Expand Down
16 changes: 8 additions & 8 deletions core_lang/src/parse_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ mod return_statement;
mod use_statement;
mod while_loop;

pub(crate) use call_path::*;
pub(crate) use code_block::*;
pub(crate) use declaration::*;
pub(crate) use expression::*;
pub(crate) use literal::Literal;
pub(crate) use return_statement::*;
pub(crate) use use_statement::{ImportType, UseStatement};
pub(crate) use while_loop::WhileLoop;
pub use call_path::*;
pub use code_block::*;
pub use declaration::*;
pub use expression::*;
pub use literal::Literal;
pub use return_statement::*;
pub use use_statement::{ImportType, UseStatement};
pub use while_loop::WhileLoop;
2 changes: 1 addition & 1 deletion core_lang/src/parse_tree/return_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{CompileResult, Expression};
use pest::iterators::Pair;

#[derive(Debug, Clone)]
pub(crate) struct ReturnStatement<'sc> {
pub struct ReturnStatement<'sc> {
pub(crate) expr: Expression<'sc>,
}

Expand Down
4 changes: 2 additions & 2 deletions core_lang/src/parse_tree/use_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use crate::Rule;
use pest::iterators::Pair;

#[derive(Debug, Clone)]
pub(crate) enum ImportType<'sc> {
pub enum ImportType<'sc> {
Star,
Item(Ident<'sc>),
}

#[derive(Debug, Clone)]
pub(crate) struct UseStatement<'sc> {
pub struct UseStatement<'sc> {
pub(crate) call_path: Vec<Ident<'sc>>,
pub(crate) import_type: ImportType<'sc>,
}
Expand Down
2 changes: 1 addition & 1 deletion core_lang/src/parse_tree/while_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
use pest::iterators::Pair;

#[derive(Debug, Clone)]
pub(crate) struct WhileLoop<'sc> {
pub struct WhileLoop<'sc> {
pub(crate) condition: Expression<'sc>,
pub(crate) body: CodeBlock<'sc>,
}
Expand Down
21 changes: 10 additions & 11 deletions forc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
[package]
name = "forc"
version = "0.1.0"
authors = ["Alex Hansen <alex.hansen@fuel.sh>"]
edition = "2018"
name = "forc"
rust = "1.50"

version = "0.1.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
core_lang = { path = "../core_lang" }
structopt = "0.3"
core_lang = {path = "../core_lang"}
line-col = "0.2"
pest = "2.1"
serde = {version = "1.0", features = ["derive"]}
source-span = "2.4"
termcolor = "1.1"
line-col = "0.2"
toml = "0.5"
serde = { version = "1.0", features = ["derive"] }
whoami = "1.1"
pest = "2.1"
structopt = "0.3"
termcolor = "1.1"
toml = "0.5"
whoami = "1.1"
8 changes: 8 additions & 0 deletions forc/src/cli/commands/analysis.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use structopt::{self, StructOpt};

#[derive(Debug, StructOpt)]
pub(crate) struct Command {}

pub(crate) fn exec(command: Command) -> Result<(), String> {
todo!()
}
8 changes: 8 additions & 0 deletions forc/src/cli/commands/benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use structopt::{self, StructOpt};

#[derive(Debug, StructOpt)]
pub(crate) struct Command {}

pub(crate) fn exec(command: Command) -> Result<(), String> {
todo!()
}
12 changes: 12 additions & 0 deletions forc/src/cli/commands/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use structopt::{self, StructOpt};

use crate::ops::forc_build;
#[derive(Debug, StructOpt)]
pub(crate) struct Command {
#[structopt(short = "p")]
pub path: Option<String>,
}

pub(crate) fn exec(command: Command) -> Result<(), String> {
forc_build::build(command.path)
}
8 changes: 8 additions & 0 deletions forc/src/cli/commands/coverage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use structopt::{self, StructOpt};

#[derive(Debug, StructOpt)]
pub(crate) struct Command {}

pub(crate) fn exec(command: Command) -> Result<(), String> {
todo!()
}

0 comments on commit 66bac57

Please sign in to comment.