Skip to content
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

Basic mathematical stdlib functionality #61

Merged
merged 57 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
655d991
begin register allocator
May 14, 2021
3e56e38
begin reg alloc
May 15, 2021
a7f469e
mutable virtual registers; basic allocation algorithm skeleton
May 16, 2021
5c50072
mutable registers in allocation
May 17, 2021
e407757
pull in fuel-asm official ops
May 18, 2021
f99b127
switching laptops
May 19, 2021
af1c112
begin work on virtual registers and ops
May 19, 2021
8d6f088
daily checkpoint
May 20, 2021
f44b7fd
add AllocatedOp abstraction
May 20, 2021
61705b9
template for parsing ops
May 20, 2021
8d21ff5
allocation algorithm progress
May 20, 2021
cfa3e4a
change op parsing logic
May 21, 2021
483c46d
WIP parsing inline asm to new ops
May 21, 2021
fb5d61a
more op parsing
May 21, 2021
1723aca
finish parsing virtual ops from asm
May 21, 2021
e961af7
start registers method
May 21, 2021
f61845b
register allocation method
May 21, 2021
c36dbb5
convert virtual registers to allocated ones
May 21, 2021
d35f6bf
switch back to organizational labels for jumps
May 21, 2021
3a973af
realized ops
May 22, 2021
d8c0b83
fully allocate registers and resolve labels
May 22, 2021
ea91252
print allocated registers
May 22, 2021
b822630
merge from master; fix reg alloc algo
May 22, 2021
8347dc3
fill in todo!() errors in asm parsing
May 22, 2021
d2b6b37
resolve all todosudo apt-get install vlc in core_lang
May 22, 2021
60c0b1c
switch to ssh for fuel-asm
May 22, 2021
2156b67
resolve warnings
May 22, 2021
2c126bf
fix git url
May 22, 2021
3598dd8
rustfmt
May 22, 2021
f3ea12e
Merge branch 'master' of github.com:FuelLabs/fuel-vm-hll into allocation
May 22, 2021
8344df4
small self-code-review
May 22, 2021
cd6dbb5
resolve module
May 22, 2021
4315bc2
map the virtual opcodes to fuel_asm ops
May 23, 2021
a2a3ee7
code review feedback
May 23, 2021
a2551fb
Merge branch 'allocation' of github.com:FuelLabs/fuel-vm-hll into act…
May 23, 2021
7b87ee0
factor finalized asm out into its own file
May 23, 2021
f3dd962
merge from master
May 23, 2021
31e9f29
realize data section and instructions to bits
May 25, 2021
c39141a
data section offset label
May 26, 2021
5c21259
initial bytecode generation
May 26, 2021
11e6a17
add forc --asm command
May 26, 2021
e3c1d1a
print out the loading of the data section op
May 26, 2021
db009fb
resolve warnings
May 26, 2021
f23350d
fix register allocater bug
May 27, 2021
1b74664
cleanup
May 27, 2021
980e9c7
fix bad error message
May 27, 2021
88217bd
code review feedback
May 28, 2021
fafb111
Merge branch 'master' of github.com:fuellabs/fuel-vm-hll into actual_…
May 28, 2021
0babc0b
fix doctest
May 28, 2021
01af3d0
fix typo
May 28, 2021
3cea222
reference fuel_core for register constants
May 28, 2021
3f47eb6
add stdlib stuff
May 28, 2021
448536c
allow use of interface surface functions in the methods section of tr…
May 29, 2021
9a41e2a
comment
May 29, 2021
f6f7bea
basic math stdlib
May 29, 2021
84cd2a9
merge from master
Jun 2, 2021
e9f3cc1
formatting
Jun 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions core_lang/src/semantic_analysis/ast_node/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,24 @@ impl<'sc> TypedFunctionDeclaration<'sc> {
)
}
}

impl<'sc> TypedTraitFn<'sc> {
/// This function is used in trait declarations to insert "placeholder" functions
/// in the methods. This allows the methods to use functions declared in the
/// interface surface.
pub(crate) fn to_dummy_func(&self) -> TypedFunctionDeclaration<'sc> {
TypedFunctionDeclaration {
name: self.name.clone(),
body: TypedCodeBlock {
contents: vec![],
whole_block_span: self.name.span.clone(),
},
parameters: vec![],
span: self.name.span.clone(),
return_type: self.return_type.clone(),
return_type_span: self.return_type_span.clone(),
visibility: Visibility::Public,
type_parameters: vec![],
}
}
}
61 changes: 38 additions & 23 deletions core_lang/src/semantic_analysis/ast_node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,28 +171,42 @@ impl<'sc> TypedAstNode<'sc> {
}) => {
let mut methods_buf = Vec::new();
let interface_surface = interface_surface
.into_iter()
.map(|TraitFn {
name,
parameters,
return_type,
return_type_span
}| TypedTraitFn {
name,
return_type_span,
parameters: parameters
.into_iter()
.map(|FunctionParameter { name, r#type, type_span }|
TypedFunctionParameter {
name,
r#type: namespace.resolve_type(&r#type,
&MaybeResolvedType::Partial(PartiallyResolvedType::SelfType)),
type_span }
).collect(),
return_type: namespace.resolve_type(&return_type,
&MaybeResolvedType::Partial(PartiallyResolvedType::SelfType)
)
}).collect::<Vec<_>>();
.into_iter()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a whitespace change

.map(|TraitFn {
name,
parameters,
return_type,
return_type_span
}| TypedTraitFn {
name,
return_type_span,
parameters: parameters
.into_iter()
.map(|FunctionParameter { name, r#type, type_span }|
TypedFunctionParameter {
name,
r#type: namespace.resolve_type(&r#type,
&MaybeResolvedType::Partial(PartiallyResolvedType::SelfType)),
type_span }
).collect(),
return_type: namespace.resolve_type(&return_type,
&MaybeResolvedType::Partial(PartiallyResolvedType::SelfType)
)
}).collect::<Vec<_>>();
let mut l_namespace = namespace.clone();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the real change begins -- mutating the local namespace to include trait interface surface methods

// insert placeholder functions representing the interface surface
// to allow methods to use those functions
l_namespace.insert_trait_implementation(
CallPath {
prefixes: vec![],
suffix: name.clone(),
},
MaybeResolvedType::Partial(PartiallyResolvedType::SelfType),
interface_surface
.iter()
.map(|x| x.to_dummy_func())
.collect(),
);
for FunctionDeclaration {
body,
name: fn_name,
Expand All @@ -204,7 +218,7 @@ impl<'sc> TypedAstNode<'sc> {
..
} in methods
{
let mut namespace = namespace.clone();
let mut namespace = l_namespace.clone();
parameters.clone().into_iter().for_each(
|FunctionParameter { name, r#type, .. }| {
let r#type = namespace.resolve_type(
Expand Down Expand Up @@ -298,6 +312,7 @@ impl<'sc> TypedAstNode<'sc> {
},
)
.collect::<Vec<_>>();

// TODO check code block implicit return
let return_type = namespace.resolve_type(&return_type, self_type);
let (body, _code_block_implicit_return) = type_check!(
Expand Down
31 changes: 0 additions & 31 deletions forc/src/ops/forc_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,6 @@ use core_lang::{
};
use std::{fs, path::PathBuf};

pub fn print_asm(path: Option<String>) -> Result<(), String> {
// find manifest directory, even if in subdirectory
let this_dir = if let Some(path) = path {
PathBuf::from(path)
} else {
std::env::current_dir().unwrap()
};
let manifest_dir = find_manifest_dir(&this_dir).ok_or(format!(
"No manifest file found in this directory or any parent directories of it: {:?}",
this_dir
))?;
let manifest = read_manifest(&manifest_dir)?;

let mut namespace: Namespace = Default::default();
if let Some(ref deps) = manifest.dependencies {
for (dependency_name, dependency_details) in deps.iter() {
compile_dependency_lib(
&this_dir,
&dependency_name,
&dependency_details,
&mut namespace,
)?;
}
}

// now, compile this program with all of its dependencies
let main_file = get_main_file(&manifest, &manifest_dir)?;

Ok(())
}

pub fn build(command: BuildCommand) -> Result<Vec<u8>, String> {
let BuildCommand {
path,
Expand Down
Loading