Skip to content

Commit

Permalink
[IR] adding linkage for consts
Browse files Browse the repository at this point in the history
  • Loading branch information
Cr0a3 committed Sep 8, 2024
1 parent ccc5384 commit d624c9e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/IR/parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::IrError;

/// A location reference.
/// Is recommended to be used for giving tokens locations
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct Loc {
/// The line number
pub line: u64,
Expand Down
37 changes: 32 additions & 5 deletions src/IR/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,20 +274,47 @@ impl IrParser {
PARSE NAME
*/

let name;
let mut scope = Linkage::External;
let mut parsed_scope = false;

let mut name = "unreachable".into();

let mut location;
let mut location = Loc::default();

self.expect( TokenType::Ident(String::new()) )?;

let tok = self.current_token()?;
if let TokenType::Ident(ident) = &tok.typ {
name = ident.to_string();
location = tok.loc.clone();
match ident.as_str() {
"local" | "internal" | "private" => {
parsed_scope = true;
scope = Linkage::Internal
},
"public" | "external" => {
parsed_scope = true;
scope = Linkage::External
},
_ => {
name = ident.to_string();
location = tok.loc.clone();
}
}
} else { unreachable!() }

self.input.pop_front();

if parsed_scope {
self.expect(TokenType::Ident(String::new()))?;
let tok = self.current_token()?;

if let TokenType::Ident(ident) = &tok.typ {
name = ident.to_owned();
location = tok.loc.clone();
} else { unreachable!() }

self.input.pop_front();
}

self.expect(TokenType::Equal)?;
self.input.pop_front();

Expand Down Expand Up @@ -320,7 +347,7 @@ impl IrParser {
name: name,
data: data,
location: location,
scope: Linkage::Extern,
scope: scope,
})
}

Expand Down
2 changes: 1 addition & 1 deletion tools/ytest/example.yl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RUN: cargo run -p ylc -- -in=%s -o=out.o -asm-clr && gcc out.o -o test.exe && ./a.exe
# RUN: cargo run -p ylc -- -in=%s -o=out.o -asm-clr && gcc out.o -o a.exe && ./a.exe

const const0 = "Hello World!\n"

Expand Down

0 comments on commit d624c9e

Please sign in to comment.