当前位置: 首页 > 工具软件 > Lightspark > 使用案例 >

lightspark代码分析

华俊贤
2023-12-01

Total Files:           91
Total Lines:        37,329


TO Read:
  * LLVM how
  * SDL how
  * EGL how
  * ABC file format
  * LLVM vs Tarmarin
  * Object in lightspark
  * GC


* LightSpark summary
  stack based vm
  intepreter && JIT runtime


* src
  abc_interpreter.cpp: interpreter
  abc_opcodes.cpp: Abc asm op impl
  abc.cpp: system class && function, such as, String, Array, RegExp...
  class.h/asobjects.h: definition of AS Object in vm

  asobjects.cpp: 所有AS runtime对象的定义,和Traits的初始化,如
    REGISTER_CLASS_NAME(RegExp);
    REGISTER_CLASS_NAME(Math);
    REGISTER_CLASS_NAME(ASString);

    void Array::buildTraits(ASObject* o)
    {
     o->setGetterByQName("length","",new Function(_getLength));
     o->ASObject::setVariableByQName("pop","",new Function(_pop));
     o->ASObject::setVariableByQName("shift",AS3,new Function(shift));
     o->ASObject::setVariableByQName("unshift","",new Function(unshift));
    }
   

* ABC file format
  How ABC stores code ?


* important sequence
  main.cpp/tightspark.cpp: 两个入口,暂理解为豪华版/简约版,从
tightspark.cpp下手轻松一些
 
  abc.cpp:ABCVm构造:startup ABSVm Run Thread
  abc.cpp:ABCContext构造:Read abc Head Tag, read&parse const pool
  abc.cpp:ABCVm->addEvent: add Event, drive ABCVm to run,几个线程间的同
步是通过几个信号量

  初始化->运行:
    new SystemState
    创建ABCVm
      通过pthread,启动线程,该线程执行ABCVm::Run,并阻塞到信号量th->sem_event_count
    new ABCContext
      parse abc head
    vm.addEvent(NULL, new ABCContextInitEvent)
    vm.addEvent(NULL, new ShudownEvent)
      events_queue中加入事件,释放sem_event_count,唤醒ABCVm::Run线程,
该线程awake后,通过ABCVm::handleEvent处理事件(BIND_CLASS, SHUTDOWN, CONTEXT_INIT,
CONSTRUCT_OBJECT, CHANGE_FRAME);  因为第一个事件为CONTEXT_INIT,所以首先
执行到了ABCContext::exec -> asobjects.cpp,SyntheticFunction::call ->
abc_interpreter.cpp,ABCVm::executeFunction解释执行字节码

  asobjects.cpp,SyntheticFunction::call
    注意byte code执行环境的初始化,鸡生蛋,蛋生鸡在里这得到解释   

  abc_interpreter.cpp,ABCVm::executeFunction
    反编译几个abc文件对照着读,效果比较好 


* Object in lightspark
  swftypes.h:
    SWFOBJECT_TYPE: the object type supported by AS
   
  T_OBJECT, T_INTEGER..., T_PROXY:单根继承自ASObject,以ASObject为实例返
回给AS vm,在需要转换时通过ASObject->getObjectType首先得到类型,再做强制转换

  abc.cpp:iManager/dManager:缓存(Integer/Double)常用对象,是一个亮点


* LLVM how
    TODO
 类似资料: