module.cpp 768 B

1234567891011121314151617181920212223242526272829
  1. #include "module.hpp"
  2. #include "../../interpreter.hpp"
  3. void* module_types(void* v){
  4. Gomu::Module* module=(Gomu::Module*)v;
  5. Gomu::ArrayValue *res=new Gomu::ArrayValue(module->ntype);
  6. res->type=Gomu::type_string;
  7. for(size_t i=0;i<module->ntype;++i){
  8. res->tab[i]=new string(module->types[i]);
  9. }
  10. return res;
  11. }
  12. Value symbols(Context& context,Value& v){
  13. Type* type=(Type*)v.ptr;
  14. string str=type->name+'.';
  15. deque<string> stack;
  16. auto it=context.symbols.lower_bound(str);
  17. while(it->first.substr(0,str.size())==str){
  18. stack.push_back(it->first);
  19. ++it;
  20. }
  21. ArrayValue* res=new ArrayValue(stack.size());
  22. res->type=type_string;
  23. for(size_t i=0;i<stack.size();++i){
  24. res->tab[i]=new string(stack[i]);
  25. }
  26. return Value(type_array,res);
  27. }