Skip to content

Commit

Permalink
Handle commas and colons in main function args
Browse files Browse the repository at this point in the history
  • Loading branch information
octavonce committed Sep 8, 2023
1 parent 1359410 commit c59025b
Showing 1 changed file with 55 additions and 4 deletions.
59 changes: 55 additions & 4 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct Compiler {
out_main: Vec<u8>,

Check warning on line 8 in src/compiler.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly)

fields `out_main` and `out_funcs` are never read

Check warning on line 8 in src/compiler.rs

View workflow job for this annotation

GitHub Actions / Rustfmt / Clippy

fields `out_main` and `out_funcs` are never read

Check warning on line 8 in src/compiler.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly)

fields `out_main` and `out_funcs` are never read

Check warning on line 8 in src/compiler.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly)

fields `out_main` and `out_funcs` are never read

Check warning on line 8 in src/compiler.rs

View workflow job for this annotation

GitHub Actions / Rustfmt / Clippy

fields `out_main` and `out_funcs` are never read

Check warning on line 8 in src/compiler.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly)

fields `out_main` and `out_funcs` are never read

/// Indexes of main args identifiers
main_args_identifiers: Vec<String>,
main_args_identifiers_with_args: Vec<(String, ArgType)>,

/// Buffer for other functions
out_funcs: Vec<Vec<u8>>,
Expand All @@ -27,7 +27,7 @@ impl Compiler {
out_main: vec![],
out_funcs: vec![],
out_bitmap: vec![],
main_args_identifiers: vec![],
main_args_identifiers_with_args: vec![],
out_malleable_args_count: 0,
}
}
Expand Down Expand Up @@ -108,14 +108,40 @@ impl Compiler {
&CompilerState::ExpectingMainFuncMalleableOrIdentifier,
TokenKind::Identifier(identifier),
) => {
self.main_args_identifiers.push(identifier);
self.state = CompilerState::ExpectingMainFuncMalleableOrIdentifier;
self.main_args_identifiers_with_args
.push((identifier, ArgType::Any));
self.state = CompilerState::ExpectingMainFuncColonCommaOrRightParanthesis;
}

(&CompilerState::ExpectingMainFuncMalleableOrIdentifier, _) => {
return Err(CompilerErr::ExpectedIdentifier(token.position.clone()));
}

(
&CompilerState::ExpectingMainFuncColonCommaOrRightParanthesis,
TokenKind::Symbol(Symbol::Colon),
) => {
self.state = CompilerState::ExpectingMainFuncArgType;
}

(
&CompilerState::ExpectingMainFuncColonCommaOrRightParanthesis,
TokenKind::Symbol(Symbol::Comma),
) => {
self.state = CompilerState::ExpectingMainFuncMalleableOrIdentifier;
}

(
&CompilerState::ExpectingMainFuncColonCommaOrRightParanthesis,
TokenKind::Symbol(Symbol::ParenthesisRight),
) => {
self.state = CompilerState::ExpectingFuncBrace;
}

(&CompilerState::ExpectingMainFuncColonCommaOrRightParanthesis, _) => {
return Err(CompilerErr::ExpectedColonOrComma(token.position.clone()));
}

_ => unimplemented!(),
}

Expand All @@ -132,6 +158,7 @@ pub enum CompilerErr {
ExpectedFunctionDefinition(Position),
ExpectedIdentifier(Position),
ExpectedParanthesisLeft(Position),
ExpectedColonOrComma(Position),
}

enum CompilerState {
Expand Down Expand Up @@ -163,6 +190,9 @@ enum CompilerState {
/// to end the main function definitions.
ExpectingMainFuncColonCommaOrRightParanthesis,

/// We have hit a colon for a main function argument, we are now expecting the type
ExpectingMainFuncArgType,

/// We finished the arguments definition, now we want the start brace
/// of the main function body.
ExpectingMainFuncBrace,
Expand Down Expand Up @@ -191,3 +221,24 @@ enum CompilerState {
// Func bodies
//
}

enum ArgType {
Any,
U8,

Check warning on line 227 in src/compiler.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly)

multiple variants are never constructed

Check warning on line 227 in src/compiler.rs

View workflow job for this annotation

GitHub Actions / Rustfmt / Clippy

multiple variants are never constructed

Check warning on line 227 in src/compiler.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly)

multiple variants are never constructed

Check warning on line 227 in src/compiler.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, nightly)

multiple variants are never constructed

Check warning on line 227 in src/compiler.rs

View workflow job for this annotation

GitHub Actions / Rustfmt / Clippy

multiple variants are never constructed

Check warning on line 227 in src/compiler.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest, nightly)

multiple variants are never constructed
U16,
U32,
U64,
U128,
UBIG,

Check warning on line 232 in src/compiler.rs

View workflow job for this annotation

GitHub Actions / Rustfmt / Clippy

name `UBIG` contains a capitalized acronym

Check warning on line 232 in src/compiler.rs

View workflow job for this annotation

GitHub Actions / Rustfmt / Clippy

name `UBIG` contains a capitalized acronym
I8,
I16,
I32,
I64,
I128,
IBIG,

Check warning on line 238 in src/compiler.rs

View workflow job for this annotation

GitHub Actions / Rustfmt / Clippy

name `IBIG` contains a capitalized acronym

Check warning on line 238 in src/compiler.rs

View workflow job for this annotation

GitHub Actions / Rustfmt / Clippy

name `IBIG` contains a capitalized acronym
F32,
F64,
Decimal,
Address,
Asset,
}

0 comments on commit c59025b

Please sign in to comment.