[obsidian] vault backup: 2025-09-25 15:39:04[
All checks were successful
Build / build (push) Successful in 11m11s

This commit is contained in:
2025-09-25 15:39:04 +09:00
parent 857e71b45e
commit bb78453c63

View File

@@ -48,12 +48,10 @@ $$
## コンパイル
評価をしながら副作用としてMIRを書き込んでいくような感じ
Valueとして、次のようなものがあり得る
```rust
struct VRegister(usize);
struct VRegister(usize);//Vregisterは無限に使用できてサイズ可変
struct StackSlot(usize);
enum Value{
Static(usize),
@@ -78,11 +76,12 @@ struct MIR{
externals:<ExternalItems>
functions:Vec<FuncProto>
}
struct Operation{
dest:Option<VRegister>,
inst:Instruction
}
struct UpIndex(usize)
struct UpIndex(FnId,usize)
struct UpIndexStorage(Vec<StackSlot>)
impl UpIndexStorage{
@@ -90,25 +89,44 @@ impl UpIndexStorage{
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{
upindexes:UpIndexStorage,
instructions: Vec<Operation>
name: Symbol,
upindexes: UpIndexStorage,
blocks: BlockChunk,
state_tree: Vec<StateLeaf> //StateTreeは実際のデータを保持しない
meta_labels:BTreeMap<StackSlot,Symbol> //print用メタデータ
}
enum Instruction{
Load(StackSlot,Type)
Store{dest:StackSlot,src:Register,Type}
GetUpValue(UpIndex,Type)
Store{dest:StackSlot,src:Register,Type},
GetUpValue(UpIndex,Type),
JmpIf{cond:Register,then:BlockId,else_:BlockId,merge:BlockId},
ShiftStatePos(isize)//ツリーの子インデックスに対するカーソル移動オフセット
GetState(Type)
//その他、プリミティブな命令はfrom Register to Register
}
```
評価をしながら副作用としてMIRを書き込んでいくような感じ
```rust
fn eval(e:ExprNodeId,env:Env<Value>)->(Value,Type){
fn eval(e:ExprNodeId,env:Env<(Value,Type)>)->(Value,Type){
match e.to_expr() {
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)=>{
@@ -127,6 +145,9 @@ fn eval(e:ExprNodeId,env:Env<Value>)->(Value,Type){
_=>panic!()
}
}
Expr::Feed(id,body)=>{
}
}
}