[obsidian] vault backup: 2025-09-25 15:39:04[
All checks were successful
Build / build (push) Successful in 11m11s
All checks were successful
Build / build (push) Successful in 11m11s
This commit is contained in:
@@ -48,12 +48,10 @@ $$
|
|||||||
|
|
||||||
## コンパイル
|
## コンパイル
|
||||||
|
|
||||||
評価をしながら副作用としてMIRを書き込んでいくような感じ
|
|
||||||
|
|
||||||
Valueとして、次のようなものがあり得る
|
Valueとして、次のようなものがあり得る
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
struct VRegister(usize);
|
struct VRegister(usize);//Vregisterは無限に使用できてサイズ可変
|
||||||
struct StackSlot(usize);
|
struct StackSlot(usize);
|
||||||
enum Value{
|
enum Value{
|
||||||
Static(usize),
|
Static(usize),
|
||||||
@@ -78,11 +76,12 @@ struct MIR{
|
|||||||
externals:<ExternalItems>
|
externals:<ExternalItems>
|
||||||
functions:Vec<FuncProto>
|
functions:Vec<FuncProto>
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Operation{
|
struct Operation{
|
||||||
dest:Option<VRegister>,
|
dest:Option<VRegister>,
|
||||||
inst:Instruction
|
inst:Instruction
|
||||||
}
|
}
|
||||||
struct UpIndex(usize)
|
struct UpIndex(FnId,usize)
|
||||||
struct UpIndexStorage(Vec<StackSlot>)
|
struct UpIndexStorage(Vec<StackSlot>)
|
||||||
|
|
||||||
impl UpIndexStorage{
|
impl UpIndexStorage{
|
||||||
@@ -90,25 +89,44 @@ impl UpIndexStorage{
|
|||||||
self.0.get(i.0)
|
self.0.get(i.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
struct BlockId(usize)
|
||||||
|
struct BasicBlock{
|
||||||
|
label:Symbol,
|
||||||
|
entry_v:Vec<BlockId>
|
||||||
|
op:Vec<Operation>
|
||||||
|
}
|
||||||
|
struct BlockChunk(Vec<Block>)
|
||||||
|
impl BlockChunk{ /*newtype pattern*/ }
|
||||||
struct FuncProto{
|
struct FuncProto{
|
||||||
|
name: Symbol,
|
||||||
upindexes: UpIndexStorage,
|
upindexes: UpIndexStorage,
|
||||||
instructions: Vec<Operation>
|
blocks: BlockChunk,
|
||||||
|
state_tree: Vec<StateLeaf> //StateTreeは実際のデータを保持しない
|
||||||
|
meta_labels:BTreeMap<StackSlot,Symbol> //print用メタデータ
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Instruction{
|
enum Instruction{
|
||||||
Load(StackSlot,Type)
|
Load(StackSlot,Type)
|
||||||
Store{dest:StackSlot,src:Register,Type}
|
Store{dest:StackSlot,src:Register,Type},
|
||||||
GetUpValue(UpIndex,Type)
|
GetUpValue(UpIndex,Type),
|
||||||
|
JmpIf{cond:Register,then:BlockId,else_:BlockId,merge:BlockId},
|
||||||
|
ShiftStatePos(isize)//ツリーの子インデックスに対するカーソル移動オフセット
|
||||||
|
GetState(Type)
|
||||||
//その他、プリミティブな命令はfrom Register to Register
|
//その他、プリミティブな命令はfrom Register to Register
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
評価をしながら副作用としてMIRを書き込んでいくような感じ
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
fn eval(e:ExprNodeId,env:Env<Value>)->(Value,Type){
|
fn eval(e:ExprNodeId,env:Env<(Value,Type)>)->(Value,Type){
|
||||||
match e.to_expr() {
|
match e.to_expr() {
|
||||||
Expr::Id(name)=>{
|
Expr::Id(name)=>{
|
||||||
env.lookup(name)
|
match env.lookup(name){
|
||||||
|
(Value::Register(r),t)=>(r,t)
|
||||||
|
(Value::StackSlot(s),t)=>push_inst(Instruction::Load(s,t))
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
Expr::Let(name,e,body)=>{
|
Expr::Let(name,e,body)=>{
|
||||||
@@ -127,6 +145,9 @@ fn eval(e:ExprNodeId,env:Env<Value>)->(Value,Type){
|
|||||||
_=>panic!()
|
_=>panic!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Expr::Feed(id,body)=>{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user