From e421a06923c6094ef8f54b616edaf37511442f0e Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Thu, 9 Feb 2023 15:32:55 +0800 Subject: [PATCH] rename --- src/builtins.h | 4 ++-- src/common.h | 4 ---- src/main.cpp | 2 +- src/pocketpy.h | 19 +++++++++---------- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/builtins.h b/src/builtins.h index 97186680..50224595 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -1,6 +1,6 @@ #pragma once -const char* __BUILTINS_CODE = R"( +const char* kBuiltinsCode = R"( def print(*args, sep=' ', end='\n'): s = sep.join([str(i) for i in args]) __sys_stdout_write(s + end) @@ -370,7 +370,7 @@ class set: return self._a.keys().__iter__() )"; -const char* __RANDOM_CODE = R"( +const char* kRandomCode = R"( import time as _time __all__ = ['Random', 'seed', 'random', 'randint', 'uniform'] diff --git a/src/common.h b/src/common.h index 3ccfd0c0..409db01a 100644 --- a/src/common.h +++ b/src/common.h @@ -31,10 +31,6 @@ #define UNREACHABLE() throw std::runtime_error( __FILE__ + std::string(":") + std::to_string(__LINE__) + " UNREACHABLE()!"); #endif -#ifdef __EMSCRIPTEN__ -#include -#endif - #define PK_VERSION "0.8.3" typedef int64_t i64; diff --git a/src/main.cpp b/src/main.cpp index b4089799..f21c0fce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,7 +15,7 @@ struct Timer{ } }; -#ifndef __NO_MAIN +#ifndef __EMSCRIPTEN__ int main(int argc, char** argv){ VM* vm = pkpy_new_vm(true); diff --git a/src/pocketpy.h b/src/pocketpy.h index 0bbf0e24..8776bee5 100644 --- a/src/pocketpy.h +++ b/src/pocketpy.h @@ -503,8 +503,8 @@ void init_builtins(VM* _vm) { #elif __APPLE__ #define __EXPORT __attribute__((visibility("default"))) __attribute__((used)) #elif __EMSCRIPTEN__ +#include #define __EXPORT EMSCRIPTEN_KEEPALIVE -#define __NO_MAIN #else #define __EXPORT #endif @@ -654,7 +654,7 @@ public: virtual void* get() = 0; }; -static std::vector<_PkExported*> _pkLookupTable; +static std::vector<_PkExported*> _pk_lookup_table; template class PkExported : public _PkExported{ @@ -663,7 +663,7 @@ public: template PkExported(Args&&... args) { _ptr = new T(std::forward(args)...); - _pkLookupTable.push_back(this); + _pk_lookup_table.push_back(this); } ~PkExported() override { delete _ptr; } @@ -683,10 +683,10 @@ extern "C" { /// If the pointer is not allocated by `pkpy_xxx_xxx`, the behavior is undefined. /// !!! void pkpy_delete(void* p){ - for(int i = 0; i < _pkLookupTable.size(); i++){ - if(_pkLookupTable[i]->get() == p){ - delete _pkLookupTable[i]; - _pkLookupTable.erase(_pkLookupTable.begin() + i); + for(int i = 0; i < _pk_lookup_table.size(); i++){ + if(_pk_lookup_table[i]->get() == p){ + delete _pk_lookup_table[i]; + _pk_lookup_table.erase(_pk_lookup_table.begin() + i); return; } } @@ -761,11 +761,10 @@ extern "C" { add_module_re(vm); add_module_dis(vm); - // add builtins | no exception handler | must succeed - _Code code = vm->compile(__BUILTINS_CODE, "", EXEC_MODE); + _Code code = vm->compile(kBuiltinsCode, "", EXEC_MODE); vm->_exec(code, vm->builtins, pkpy::make_shared()); - pkpy_vm_add_module(vm, "random", __RANDOM_CODE); + pkpy_vm_add_module(vm, "random", kRandomCode); return vm; }