Пример #1
0
def exec(string):
    env0 = env.Env()
    gc = env.GC(env0)
    s = env.Scope.root_scope()
    for i in interp.parse(string):
        _, _, _gc = interp.interp0(i, env0, s, s.extend())
        gc.extend(_gc)
Пример #2
0
import cProfile

import env
import interp
import std
import type

e = env.Env()
tmp = lambda: [
    interp.interp0(["do", ["load", type.String("test.kf")]], e, None)
    for i in range(0, 200)
]
cProfile.run("tmp()", sort="tottime")
print(len(e.env))
"""
         8970826 function calls (8426026 primitive calls) in 5.486 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
343400/200    0.991    0.000    5.484    0.027 interp.py:163(interp0)
   194800    0.510    0.000    0.617    0.000 env.py:9(get)
   601800    0.506    0.000    0.506    0.000 interp.py:59(next)
      400    0.426    0.001    1.600    0.004 interp.py:75(preProcess)
    59200    0.296    0.000    0.424    0.000 interp.py:10(parse_value)
45200/2000    0.278    0.000    3.266    0.002 type.py:113(__call__)
  1671002    0.245    0.000    0.245    0.000 {built-in method builtins.isinstance}
87000/200    0.239    0.000    5.482    0.027 type.py:177(__call__)
   601400    0.206    0.000    0.712    0.000 interp.py:57(__next__)
309400/254000    0.196    0.000    0.239    0.000 env.py:70(clean)
  1381000    0.121    0.000    0.121    0.000 {built-in method builtins.id}
Пример #3
0
 def _fun(e, y):
     val, err, _gc = interp0(parse(f"(do {y})")[0], e, s, s.extend())
     gc.extend(_gc)
     return val
Пример #4
0
import traceback

import env
import interp
import std
import type

if __name__ == '__main__':
    if len(sys.argv) == 2:
        file = sys.argv[1]
        env0 = env.Env()
        gc = env.GC(env0)
        s = env.Scope.root_scope()
        with open(file, "r", encoding="utf-8") as f:
            for i in interp.parse(f.read()):
                _, _, _gc = interp.interp0(i, env0, s, s.extend())
                gc.extend(_gc)
    else:
        type.PyFunc("clear")(lambda _, __, ___: (os.system("cls"), None))
        env0 = env.Env()
        gc = env.GC(env0)
        print("REPL")
        s = env.Scope.root_scope()
        while True:
            try:
                r = input(">> ")
                for i in interp.parse(r):
                    val, _, _gc = interp.interp0(i, env0, s, s.extend())
                    gc.extend(_gc)
                    env0._set(None, "it", val)
                    print(val)