Skip to content

Commit 8d0ad64

Browse files
committed
frontend: Prepare for items in ModuleData
1 parent 924e29f commit 8d0ad64

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

dora-bytecode/src/program.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub struct ModuleId(pub u32);
1717
pub struct ModuleData {
1818
pub name: String,
1919
pub parent_id: Option<ModuleId>,
20+
pub items: Vec<(String, ModuleItem)>,
2021
}
2122

2223
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Decode, Encode)]
@@ -201,6 +202,16 @@ impl AliasData {
201202
}
202203
}
203204

205+
#[derive(PartialEq, Debug, Copy, Clone, Decode, Encode)]
206+
pub enum ModuleItem {
207+
Class(ClassId),
208+
Struct(StructId),
209+
Enum(EnumId),
210+
Trait(TraitId),
211+
Module(ModuleId),
212+
Function(FunctionId),
213+
}
214+
204215
#[derive(Debug, Decode, Encode)]
205216
pub struct Program {
206217
pub packages: Vec<PackageData>,

dora-frontend/src/generator/tests.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ use std::collections::HashMap;
22
use std::mem;
33

44
use self::Bytecode::*;
5-
use crate::check_program;
65
use crate::generator::generate_fct_id;
76
use crate::program_emitter::Emitter;
87
use crate::sema::{ClassDefinitionId, FieldId, Sema, SemaFlags};
98
use crate::stdlib_lookup::{lookup_fct, resolve_path};
9+
use crate::{check_program, emit_program};
1010
use dora_bytecode::{
1111
self as bytecode, BytecodeFunction, BytecodeOffset, BytecodeType, BytecodeTypeArray,
12-
BytecodeVisitor, ClassId, ConstPoolEntry, ConstPoolIdx, EnumId, FunctionId, GlobalId, Register,
13-
StructId, TraitId,
12+
BytecodeVisitor, ClassId, ConstPoolEntry, ConstPoolIdx, EnumId, FunctionId, GlobalId, Program,
13+
Register, StructId, TraitId,
1414
};
1515

1616
fn positions(fct: &BytecodeFunction) -> Vec<(u32, u32)> {
@@ -34,6 +34,12 @@ fn sema(code: &'static str) -> Sema {
3434
sa
3535
}
3636

37+
#[allow(unused)]
38+
fn semac(code: &'static str) -> Program {
39+
let sa = sema(code);
40+
emit_program(sa)
41+
}
42+
3743
fn bc(sa: &Sema, path: &str) -> (BytecodeFunction, Vec<Bytecode>) {
3844
let fct_id = lookup_fct(sa, path);
3945
let mut emitter = Emitter::new();

dora-frontend/src/program_emitter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ impl Emitter {
125125
self.modules.push(ModuleData {
126126
name,
127127
parent_id: module.parent_module_id.map(|id| self.convert_module_id(id)),
128+
items: Vec::new(),
128129
})
129130
}
130131
}

0 commit comments

Comments
 (0)