Skip to content

Commit

Permalink
[FIX] fixes #44
Browse files Browse the repository at this point in the history
  • Loading branch information
Cr0a3 committed Oct 31, 2024
1 parent 7be9fdc commit c53e9e2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/IR/module.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use gimli::DwLang;

use crate::{debug::{DebugLocation, DebugRegistry}, prelude::Triple, CodeGen::MachineInstr, Obj::{Decl, Link, ObjectBuilder}, Optimizations::PassManager, Support::{ColorClass, ColorProfile}, Target::{Arch, TargetRegistry}};
use crate::{debug::{DebugLocation, DebugRegistry}, prelude::Triple, CodeGen::MachineInstr, Obj::{Decl, Link, Linkage, ObjectBuilder}, Optimizations::PassManager, Support::{ColorClass, ColorProfile}, Target::{Arch, TargetRegistry}};

use super::{func::FunctionType, Const, Function, VerifyError};
use std::{collections::HashMap, error::Error, fmt::Debug, fs::OpenOptions, io::Write, path::Path};
Expand Down Expand Up @@ -90,7 +90,11 @@ impl Module {

bytes.push(']');

string += &format!("const {} = {}\n", consta.name, bytes);
string += &format!("{} const {} = {}\n", match consta.linkage {
Linkage::Extern => "import",
Linkage::External => "extern",
Linkage::Internal => "intern",
}, consta.name, bytes);
}

for (_, func) in &self.funcs {
Expand Down Expand Up @@ -119,7 +123,12 @@ impl Module {

bytes.push(']');

string += &format!("{} {} = {}\n",
string += &format!("{} {} {} = {}\n",
profile.markup(&match consta.linkage {
Linkage::Extern => "import",
Linkage::External => "extern",
Linkage::Internal => "intern",
}, ColorClass::Instr),
profile.markup("const", ColorClass::Instr),
profile.markup(&consta.name, ColorClass::Name),
profile.markup(&bytes, ColorClass::Value)
Expand Down
8 changes: 6 additions & 2 deletions src/IR/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,15 @@ impl IrParser {
let tok = self.current_token()?;
if let TokenType::Ident(ident) = &tok.typ {
match ident.as_str() {
"local" | "internal" | "private" => {
"local" | "internal" | "intern" | "private" => {
parsed_scope = true;
scope = Linkage::Internal
},
"public" | "external" => {
"public" | "external" | "extern" => {
parsed_scope = true;
scope = Linkage::External
},
"import" => {
parsed_scope = true;
scope = Linkage::External
},
Expand Down
7 changes: 7 additions & 0 deletions tests/bugs/const_linkage.yl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# RUN:
cargo run -p ylc -- -in=%s

# IN:

const extern extern_constant = [5, 4]
const intern intern_constant = [5, 4]

0 comments on commit c53e9e2

Please sign in to comment.