Reformat evaluator #1

This commit is contained in:
Bartłomiej Pluta
2019-07-04 17:57:12 +02:00
parent f0cbf37fe9
commit 34a0eda199
36 changed files with 470 additions and 270 deletions

View File

@@ -36,8 +36,8 @@ class Environment():
return value
else:
return value
raise RuntimeException(pos, f"Variable '{name}' is not declared" + (
"" if type is None else f" (expected type: {type})"))
raise RuntimeException(f"Variable '{name}' is not declared" + (
"" if type is None else f" (expected type: {type})"), pos)
def findVariableScope(self, name, type=None):
for scope in reversed(self.scopes):
@@ -46,4 +46,20 @@ class Environment():
if isinstance(scope[name], type):
return scope
else:
return scope
return scope
def scopesToString(self):
return "Scopes:\n" + ("\n".join([ f" [{i}]: {scope}" for i, scope in enumerate(self.scopes) ]))
def functionsToString(self):
return "Functions:\n" + ("\n".join([ f" {function.name}(...)" for function in self.functions ]))
def methodsToString(self):
return "Methods:\n" + ("\n".join([f" {function.name}(...)" for function in self.methods]))
def __str__(self):
return self.scopesToString() + self.functionsToString() + self.methodsToString()
def __repr__(self):
return self.__str__()

View File

@@ -1,6 +1,8 @@
from smnp.environment.environment import Environment
from smnp.library.function import display, sleep, semitones, interval, combine, flat, wait, rand, tuplet, synth, pause, \
transpose, type, exit, duration, octave
transpose, type, exit, duration, octave, debug
from smnp.type.model import Type
from smnp.type.value import Value
def createEnvironment():
@@ -18,7 +20,8 @@ def createEnvironment():
tuplet.function,
synth.function,
pause.function,
transpose.function
transpose.function,
debug.function
]
methods = [
@@ -27,7 +30,7 @@ def createEnvironment():
]
variables = {
"bpm": 120
"bpm": Value(Type.INTEGER, 120)
}
return Environment([ variables ], functions, methods)