Turbowarp compiler

compiler

Blocks AST -> Blocks 中间码 -> js闭包函数

Block AST

Untitled

complier 流程

Untitled

Untitled

自定义积木 procedures

  1. _pushThread 作为 compiler 的入口
  2. blocks 中寻找 opcode 为 procedures_call 的积木块,对应的函数名(procedureCode)为 block.mutation.proccode
  3. 调用 addProcedureDependencies,在 proceduresToCompile Map 中记录对应的 procedures_definition block -> {"func %s" => "-K!EdvPPmb[+}1F+FX_i"}
  4. 调用 getProcedureParamNamesIdsAndDefaults, 寻找 opcode 为 procedures_prototype 且对应block.mutation.proccode的block
  5. 在 当🚩点击 的线程中记录自定义积木的 ir 表示 {“kind":"procedures.call","code":"func %s","arguments":[{"kind":"constant","value":"123"}]}
  6. 遍历 proceduresToCompile, 将 procedures_definition 进行与其他普通线程同样的操作,生成ir表示
  7. 缓存自定义积木的 ir 表示
  8. 分析 当🚩点击 的 ir script, 如果所依赖的自定义积木需要 yield,那么设置该script也标记为 yield
  9. 将 当🚩点击 的 ir script 以及 自定义积木的 ir script 挂在 IntermediateRepresentation 实例上
  10. 将 当🚩点击 的 ir script 转换为 js script -> yield* thread.procedures"func %s";