-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Initial Fuel HLL #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
71 commits
Select commit
Hold shift + click to select a range
159e747
initial parsing work
32d3ae5
parse trait declarations
42a8e80
import statements
c85792c
clean lexer tree; support method calls
9e71dda
basic ast skeleton beginnings
7a4edec
begin ast work
f767f96
checkpoint while i swap computers
40eb817
more ast parsing
8b7f12a
more ast parsing
e7bdaeb
ast: function appl, func decl, var exp
80ae5a9
ast: literals
73c4438
add compiler binary with nice error messages
d58e28b
ast: return statements, use statements
d40b2f2
fix error message
2e347c2
ast: traits
2a9edf9
more friendly parse error messages
d02fc85
old email
afdeef7
semicolons!
29ae513
byte literals; fix tests
5f8a909
parse binary and hex literals for byte and bytes32
9da8276
refactor expression parsing
8073cea
parse array exprs
6ddcb49
parse operator expressions
88e9fa5
type ascriptions
303f826
parser: polymorphism and trait bounds
f084b97
default to u64 instead of u32
720abfa
begin work on match statements
d23420c
parse structs
66b641c
refactor
3f2e581
a few program examples; parse match statements
f9234a6
lex struct expressions
4b2b948
parse to AST struct expressions
9e69615
compile warnings!
13e6a30
assert_or_warn macro
2af1365
generic struct parameters
98b46fa
parse contract/script/predicate
a11bf95
improve top level failure error message
937267e
s/ast/parse_tree
2f389a3
enums
0747988
begin semantic analysis
fc38750
begin work on type checking, inferencing, and semantics checking (#11)
sezna 3b028e6
small error msg tweak
f7261d0
Refactor error and warning handling (#12)
sezna 952ff98
type check predicates
029ea46
limit number of script main functions
217aa36
parse generic types for traits
3bed768
grammar for reassignments and while loops
ffa2450
variable reassignments; while loops
3eacf66
check generic type params in function declarations
6956d71
fix tests
d31ead1
grammar for inline asm
d74420a
Asm expressions (#13)
sezna ae30683
fix only last expr having type annotation; if branch enforcement of h…
a20104f
Control flow analysis + more (#28)
sezna 12a0efa
add line_col method for errors and warnings
c7c73a9
Generate Assembly (#31)
sezna 0a8a601
move license; clean warnings
e494d0c
Update forc/src/cli/build.rs
sezna 09f3107
Update forc/src/cli/build.rs
sezna 2d47def
code review feedback
f9a5a57
Merge branch 'parser_v1' of github.com:fuellabs/fuel-vm-hll into pars…
61c5b6e
Update forc/src/manifest.rs
sezna 6b7b5b3
Update parser/src/control_flow_analysis/analyze_return_paths.rs
sezna 824f0fd
more PR feedback
0e2793b
Merge branch 'parser_v1' of github.com:fuellabs/fuel-vm-hll into pars…
9328fcd
rename parser to core_lang
0127a8d
add minimum supported version
ee149cd
Update README.md
sezna a7416ce
check that struct size in words fits in a u32 gracefully
cfdfbcb
Merge branch 'parser_v1' of github.com:fuellabs/fuel-vm-hll into pars…
f1e8ff5
forgotten import
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
[package] | ||
name = "hll" | ||
version = "0.1.0" | ||
authors = ["Alex <alex.hansen@fuel.sh>"] | ||
edition = "2018" | ||
[workspace] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
members = ["core_lang", "forc"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
# fuel-vm-hll | ||
High Level Language (Name Subject to Change) for the FuelVM | ||
# Fume | ||
|
||
Fume is a language developed for the Fuel blockchain. It is heavily inspired by Rust and aims to bring modern language development and performance to the blockchain ecosystem. | ||
|
||
## Running the Compiler | ||
To run the compiler from this directory: | ||
``` | ||
cargo run --bin forc -- -p <path_to_project> | ||
|
||
// e.g. | ||
|
||
cargo run --bin forc -- build -p example_project/fuel_project | ||
``` | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "core_lang" | ||
version = "0.1.0" | ||
authors = ["Alex <alex.hansen@fuel.sh>"] | ||
edition = "2018" | ||
rust = "1.50" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
pest = "2.0" | ||
pest_derive = "2.0" | ||
thiserror = "1.0" | ||
either = "1.6" | ||
Inflector = "0.11" | ||
petgraph = "0.5" | ||
uuid-b64 = "0.1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# fuel-vm-hll | ||
High Level Language (Name Subject to Change) for the FuelVM. | ||
|
||
# Running the Compiler | ||
It is recommended to run this compiler from the `forc` executable, which can be found in this workspace. | ||
|
||
# Minimum supported Rust version | ||
As of now, this code was developed on and is guaranteed to run on Rust 1.50 stable. | ||
sezna marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use crate::{ | ||
asm_generation::{AsmNamespace, RegisterSequencer}, | ||
asm_lang::Op, | ||
error::*, | ||
TypedFunctionDeclaration, | ||
}; | ||
|
||
pub(crate) fn convert_fn_decl_to_asm<'sc>( | ||
_decl: &TypedFunctionDeclaration<'sc>, | ||
_namespace: &mut AsmNamespace, | ||
_register_sequencer: &mut RegisterSequencer, | ||
) -> CompileResult<'sc, Vec<Op<'sc>>> { | ||
// for now, we inline all functions as a shortcut. | ||
ok(vec![], vec![], vec![]) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use crate::{asm_lang::Op, error::*, TypedDeclaration}; | ||
|
||
use super::{AsmNamespace, RegisterSequencer}; | ||
mod fn_decl; | ||
mod reassignment; | ||
mod var_decl; | ||
pub(crate) use fn_decl::convert_fn_decl_to_asm; | ||
pub(crate) use reassignment::convert_reassignment_to_asm; | ||
pub(crate) use var_decl::convert_variable_decl_to_asm; | ||
|
||
pub(crate) fn convert_decl_to_asm<'sc>( | ||
decl: &TypedDeclaration<'sc>, | ||
namespace: &mut AsmNamespace<'sc>, | ||
register_sequencer: &mut RegisterSequencer, | ||
) -> CompileResult<'sc, Vec<Op<'sc>>> { | ||
match decl { | ||
// For an enum declaration, we don't generate any asm. | ||
TypedDeclaration::EnumDeclaration(_) => ok(vec![], vec![], vec![]), | ||
TypedDeclaration::FunctionDeclaration(typed_fn_decl) => { | ||
convert_fn_decl_to_asm(typed_fn_decl, namespace, register_sequencer) | ||
} | ||
// a trait declaration also does not have any asm directly generated from it | ||
TypedDeclaration::TraitDeclaration(_) => ok(vec![], vec![], vec![]), | ||
// since all functions are inlined (for now -- shortcut), we also don't need to do anything for this. | ||
TypedDeclaration::ImplTrait { .. } => ok(vec![], vec![], vec![]), | ||
// once again the declaration of a type has no inherent asm, only instantiations | ||
TypedDeclaration::StructDeclaration(_) => ok(vec![], vec![], vec![]), | ||
TypedDeclaration::VariableDeclaration(var_decl) => { | ||
convert_variable_decl_to_asm(var_decl, namespace, register_sequencer) | ||
} | ||
TypedDeclaration::Reassignment(reassignment) => { | ||
convert_reassignment_to_asm(reassignment, namespace, register_sequencer) | ||
} | ||
_ => err( | ||
vec![], | ||
vec![CompileError::Unimplemented( | ||
"ASM generation has not yet been implemented for this declaration variant.", | ||
decl.span().clone(), | ||
)], | ||
), | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use super::*; | ||
use crate::{ | ||
asm_generation::{convert_expression_to_asm, AsmNamespace, RegisterSequencer}, | ||
semantics::ast_node::TypedReassignment, | ||
}; | ||
|
||
pub(crate) fn convert_reassignment_to_asm<'sc>( | ||
reassignment: &TypedReassignment<'sc>, | ||
namespace: &mut AsmNamespace<'sc>, | ||
register_sequencer: &mut RegisterSequencer, | ||
) -> CompileResult<'sc, Vec<Op<'sc>>> { | ||
// 0. evaluate the RHS of the reassignment | ||
// 1. Find the register that the previous var was stored in | ||
// 2. move the return register of the RHS into the register in the namespace | ||
|
||
let mut buf = vec![]; | ||
let mut warnings = vec![]; | ||
let mut errors = vec![]; | ||
// step 0 | ||
let return_register = register_sequencer.next(); | ||
let mut rhs = type_check!( | ||
convert_expression_to_asm( | ||
&reassignment.rhs, | ||
namespace, | ||
&return_register, | ||
register_sequencer | ||
), | ||
vec![], | ||
warnings, | ||
errors | ||
); | ||
|
||
buf.append(&mut rhs); | ||
|
||
// step 1 | ||
let var_register = type_check!( | ||
namespace.look_up_variable(&reassignment.lhs), | ||
return err(warnings, errors), | ||
warnings, | ||
errors | ||
); | ||
|
||
// step 2 | ||
buf.push(Op::register_move_comment( | ||
var_register.clone(), | ||
return_register, | ||
reassignment.lhs.span.clone(), | ||
format!("variable {} reassignment", reassignment.lhs.primary_name), | ||
)); | ||
|
||
ok(buf, warnings, errors) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use crate::{ | ||
asm_generation::{convert_expression_to_asm, AsmNamespace, RegisterSequencer}, | ||
asm_lang::Op, | ||
error::*, | ||
semantics::ast_node::TypedVariableDeclaration, | ||
}; | ||
|
||
/// Provisions a register to put a variable in, and then adds the assembly used to initialize the | ||
/// variable to the end of the buffer. | ||
pub(crate) fn convert_variable_decl_to_asm<'sc>( | ||
var_decl: &TypedVariableDeclaration<'sc>, | ||
namespace: &mut AsmNamespace<'sc>, | ||
register_sequencer: &mut RegisterSequencer, | ||
) -> CompileResult<'sc, Vec<Op<'sc>>> { | ||
let var_register = register_sequencer.next(); | ||
let initialization = | ||
convert_expression_to_asm(&var_decl.body, namespace, &var_register, register_sequencer); | ||
namespace.insert_variable(var_decl.name.clone(), var_register); | ||
initialization | ||
} |
103 changes: 103 additions & 0 deletions
103
core_lang/src/asm_generation/expression/enum_instantiation.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
use crate::asm_generation::{convert_expression_to_asm, AsmNamespace, RegisterSequencer}; | ||
use crate::asm_lang::{ConstantRegister, Op, Opcode, RegisterId}; | ||
use crate::error::*; | ||
use crate::semantics::ast_node::TypedEnumDeclaration; | ||
use crate::semantics::TypedExpression; | ||
use crate::Literal; | ||
use crate::{CompileResult, Ident}; | ||
use std::convert::TryFrom; | ||
|
||
pub(crate) fn convert_enum_instantiation_to_asm<'sc>( | ||
decl: &TypedEnumDeclaration<'sc>, | ||
_variant_name: &Ident<'sc>, | ||
tag: usize, | ||
contents: &Option<Box<TypedExpression<'sc>>>, | ||
return_register: &RegisterId, | ||
namespace: &mut AsmNamespace<'sc>, | ||
register_sequencer: &mut RegisterSequencer, | ||
) -> CompileResult<'sc, Vec<Op<'sc>>> { | ||
let mut warnings = vec![]; | ||
let mut errors = vec![]; | ||
// step 0: load the tag into a register | ||
// step 1: load the data into a register | ||
// step 2: write both registers sequentially to memory, extending the call frame | ||
// step 3: write the location of the value to the return register | ||
let mut asm_buf = vec![]; | ||
// step 0 | ||
let data_label = namespace.insert_data_value(&Literal::U64(tag as u64)); | ||
let tag_register = register_sequencer.next(); | ||
asm_buf.push(Op::unowned_load_data_comment( | ||
tag_register.clone(), | ||
data_label, | ||
format!("{} enum instantiation", decl.name.primary_name), | ||
)); | ||
let pointer_register = register_sequencer.next(); | ||
// copy stack pointer into pointer register | ||
asm_buf.push(Op::unowned_register_move_comment( | ||
pointer_register.clone(), | ||
RegisterId::Constant(ConstantRegister::StackPointer), | ||
"load $sp for enum pointer", | ||
)); | ||
let size_of_enum = 1 /* tag */ + decl.as_type().stack_size_of(); | ||
let size_of_enum: u32 = match u32::try_from(size_of_enum) { | ||
Ok(o) if o < 16777216 /* 2^24 */ => o, | ||
_ => { | ||
errors.push(CompileError::Unimplemented( | ||
"Stack variables which exceed 2^24 (16777216) words in size are not supported yet.", | ||
decl.clone().span, | ||
)); | ||
return err(warnings, errors); | ||
} | ||
}; | ||
|
||
asm_buf.push(Op::unowned_stack_allocate_memory(size_of_enum)); | ||
// initialize all the memory to 0 | ||
asm_buf.push(Op::new( | ||
Opcode::MemClearImmediate(pointer_register.clone(), size_of_enum), | ||
decl.clone().span, | ||
)); | ||
// write the tag | ||
// step 2 | ||
asm_buf.push(Op::write_register_to_memory( | ||
pointer_register.clone(), | ||
tag_register.clone(), | ||
0, | ||
decl.clone().span, | ||
)); | ||
|
||
// step 1 continued | ||
// // if there are any enum contents, instantiate them | ||
if let Some(instantiation) = contents { | ||
let return_register = register_sequencer.next(); | ||
let mut asm = type_check!( | ||
convert_expression_to_asm( | ||
&*instantiation, | ||
namespace, | ||
&return_register.clone(), | ||
register_sequencer | ||
), | ||
return err(warnings, errors), | ||
warnings, | ||
errors | ||
); | ||
asm_buf.append(&mut asm); | ||
// write these enum contents to the address after the tag | ||
// step 2 | ||
asm_buf.push(Op::write_register_to_memory_comment( | ||
pointer_register.clone(), | ||
return_register.clone(), | ||
1, /* offset by 1 because the tag was already written */ | ||
instantiation.span.clone(), | ||
format!("{} enum contents", decl.name.primary_name), | ||
)); | ||
} | ||
|
||
// step 3 | ||
asm_buf.push(Op::register_move( | ||
return_register.clone(), | ||
pointer_register, | ||
decl.clone().span, | ||
)); | ||
|
||
ok(asm_buf, warnings, errors) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.