run-code.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include "inter.hpp"
  2. #include "value.hpp"
  3. #include "var.hpp"
  4. #include "code.hpp"
  5. #include "msg.hpp"
  6. #include "activation.hpp"
  7. using namespace aFuncore;
  8. using namespace aFuntool;
  9. class Func1 : public Function {
  10. class CallFunc1 : public CallFunction {
  11. Code *func_code;
  12. Code *code;
  13. Inter *inter;
  14. std::list<ArgCodeList> *acl;
  15. public:
  16. CallFunc1(Code *func_code_, Code *code_, Inter *inter_) : func_code{func_code_}, code{code_}, inter{inter_} {
  17. acl = new std::list<ArgCodeList>;
  18. ArgCodeList agr1 = {code_->getSon()->toNext()};
  19. acl->push_front(agr1);
  20. }
  21. std::list<ArgCodeList> *getArgCodeList() override {
  22. return acl;
  23. }
  24. ActivationStatus runFunction() override {
  25. printf_stdout(0, "runFunction : %p\n", acl->begin()->ret);
  26. new ExeActivation(func_code, inter);
  27. return aFuncore::as_run;
  28. }
  29. ~CallFunc1() override {
  30. delete acl;
  31. }
  32. };
  33. Code *func_code;
  34. public:
  35. explicit Func1(Inter *inter_) : Function("Function", inter_) {
  36. func_code = (new Code(0, "run-code.aun"));
  37. func_code->connect(new Code(block_p, new Code("test-var", 1), 0));
  38. }
  39. ~Func1() override {
  40. func_code->destructAll();
  41. }
  42. CallFunction *getCallFunction(Code *code, Inter *inter) override {
  43. return dynamic_cast<CallFunction *>(new CallFunc1(func_code, code, inter));
  44. }
  45. bool isInfix() override {return true;}
  46. };
  47. int main() {
  48. auto *inter = new Inter();
  49. auto *obj = new Object("Object", inter);
  50. inter->getGlobalVarlist()->defineVar("test-var", obj);
  51. printf_stdout(0, "obj: %p\n", obj);
  52. auto func = new Func1(inter);
  53. inter->getGlobalVarlist()->defineVar("test-func", func);
  54. printf_stdout(0, "func: %p\n", func);
  55. {
  56. auto code = (new Code(0, "run-code.aun"));
  57. code->connect(new Code(block_p, new Code("test-var", 1), 0));
  58. inter->runCode(code);
  59. code->destructAll();
  60. }
  61. {
  62. auto arg = new Code("test-func", 1);
  63. arg->connect(new Code("test-var", 1));
  64. auto code = (new Code(0, "run-code.aun"));
  65. code->connect(new Code(block_c, arg, 0));
  66. inter->runCode(code);
  67. code->destructAll();
  68. }
  69. {
  70. auto arg = new Code("test-var", 1);
  71. arg->connect(new Code("test-func", 1));
  72. auto code = (new Code(0, "run-code.aun"));
  73. code->connect(new Code(block_b, arg, 0));
  74. inter->runCode(code);
  75. code->destructAll();
  76. }
  77. delete inter;
  78. return 0;
  79. }