1- from _quickjs import Runtime as _Runtime
21import sys
2+ from _quickjs import Runtime as _Runtime
33
4- """
5- {"set_runtime_info", (PyCFunction)Runtime_SetRuntimeInfo, METH_O, "Set runtime info"},
6- {"set_memory_limit", (PyCFunction)Runtime_SetMemoryLimit, METH_O, "Set memory limit"},
7- {"set_gc_threshold", (PyCFunction)Runtime_SetGCThreshold, METH_O, "Set GC threshold"},
8- {"set_max_stack_size", (PyCFunction)Runtime_SetMaxStackSize, METH_O, "Set max stack size"},
9- {"update_stack_top", (PyCFunction)Runtime_UpdateStackTop, METH_NOARGS, "Update stack top"},
10- {"run_gc", (PyCFunction)Runtime_RunGC, METH_NOARGS, "Run garbage collector"},
11- {"new_context", (PyCFunction)Runtime_NewContext, METH_NOARGS, "Create a new QuickJS Context"},
12-
13- """
144from abc import ABC , abstractmethod
155from typing import override
166
7+
178class IRuntime (ABC ):
189
1910 @abstractmethod
20- def set_runtime_info (self , info : str ) -> None :
21- ...
22-
11+ def set_runtime_info (self , info : str ) -> None : ...
12+
2313 @abstractmethod
24- def set_memory_limit (self , limit : int ) -> None :
25- ...
26-
14+ def set_memory_limit (self , limit : int ) -> None : ...
15+
2716 @abstractmethod
28- def set_gc_threshold (self , threshold : int ) -> None :
29- ...
30-
17+ def set_gc_threshold (self , threshold : int ) -> None : ...
18+
3119 @abstractmethod
32- def set_max_stack_size (self , size : int ) -> None :
33- ...
34-
20+ def set_max_stack_size (self , size : int ) -> None : ...
21+
3522 @abstractmethod
36- def update_stack_top (self ) -> None :
37- ...
38-
23+ def update_stack_top (self ) -> None : ...
24+
3925 @abstractmethod
40- def run_gc (self ) -> None :
41- ...
26+ def run_gc (self ) -> None : ...
4227
4328 @abstractmethod
44- def new_context (self ) -> "IContext" :
45- ...
29+ def new_context (self ) -> "IContext" : ...
30+
4631
4732class Context (ABC ):
4833
4934 @abstractmethod
50- def eval (self , code : str , filename : str = "input.js" ) -> any :
51- ...
35+ def eval (self , code : str , filename : str = "input.js" ) -> any : ...
5236
5337 @abstractmethod
54- def eval_sync (self , code : str , filename : str = "input.js" ) -> any :
55- ...
38+ def eval_sync (self , code : str , filename : str = "input.js" ) -> any : ...
5639
5740 @abstractmethod
58- def set (self , name : str , value : any ) -> None :
59- ...
41+ def set (self , name : str , value : any ) -> None : ...
6042
6143 @abstractmethod
62- def get_runtime (self ) -> IRuntime :
63- ...
44+ def get_runtime (self ) -> IRuntime : ...
6445
6546
6647class Runtime (IRuntime , _Runtime ):
@@ -71,31 +52,30 @@ def __init__(self) -> None:
7152 @override
7253 def set_runtime_info (self , info : str ) -> None :
7354 return _Runtime .set_runtime_info (self , info )
74-
55+
7556 @override
7657 def set_memory_limit (self , limit : int ) -> None :
7758 return _Runtime .set_memory_limit (self , limit )
78-
59+
7960 @override
8061 def set_gc_threshold (self , threshold : int ) -> None :
8162 return _Runtime .set_gc_threshold (self , threshold )
82-
63+
8364 @override
8465 def set_max_stack_size (self , size : int ) -> None :
8566 return _Runtime .set_max_stack_size (self , size )
86-
67+
8768 @override
8869 def update_stack_top (self ) -> None :
8970 return _Runtime .update_stack_top (self )
90-
71+
9172 @override
9273 def run_gc (self ) -> None :
9374 return _Runtime .run_gc (self )
94-
75+
9576 @override
9677 def new_context (self ) -> Context :
9778 ctx = _Runtime .new_context (self )
98-
9979 # Setup console object
10080 console = {
10181 "log" : lambda * args : print (* args ),
@@ -104,8 +84,7 @@ def new_context(self) -> Context:
10484 "error" : lambda * args : print (* args , file = sys .stderr ),
10585 }
10686 ctx .set ("console" , console )
107-
10887 return ctx
10988
11089
111- __all__ = ["Runtime" , "Context" ]
90+ __all__ = ["Runtime" , "Context" ]
0 commit comments