Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def compile_expr(build, expr, env):
if istype(expr, u"number:value"):
return Constant.int(int_t, int(expr.value))
if istype(expr, u"call:callee:arguments"):
assert istype(expr.callee, u"variable:name")
callee_fn = env[expr.callee.name]
if len(callee_fn.args) != len(expr.arguments):
raise CompilationError(expr.arguments.proxy, "incorrect argument count")
argv = [compile_expr(build, argument, env) for argument in expr.arguments]
return build.call(callee_fn, argv)
if istype(expr, u"variable:name"):
if expr.name in env:
return env[expr.name]
else:
raise CompilationError(expr.proxy, "out of scope")
if istype(expr, u"assign:slot:value"):
assert istype(expr.slot, u"variable:name")
value = compile_expr(build, expr.value, env)
env[expr.slot.name] = value
return value
if istype(expr, u"number:value"):
return Constant.int(int_t, int(expr.value))
if istype(expr, u"call:callee:arguments"):
assert istype(expr.callee, u"variable:name")
callee_fn = env[expr.callee.name]
if len(callee_fn.args) != len(expr.arguments):
raise CompilationError(expr.arguments.proxy, "incorrect argument count")
argv = [compile_expr(build, argument, env) for argument in expr.arguments]
return build.call(callee_fn, argv)
if istype(expr, u"variable:name"):
if expr.name in env:
return env[expr.name]
else:
raise CompilationError(expr.proxy, "out of scope")
if istype(expr, u"assign:slot:value"):
assert istype(expr.slot, u"variable:name")
value = compile_expr(build, expr.value, env)
env[expr.slot.name] = value
return value
if istype(expr, u"return:value"):
value = compile_expr(build, expr.value, env)
build.ret(value)
return value
raise CompilationError(expr.proxy, "unknown statement")
def compile_expr(build, expr, env):
if istype(expr, u"number:value"):
return Constant.int(int_t, int(expr.value))
if istype(expr, u"call:callee:arguments"):
assert istype(expr.callee, u"variable:name")
callee_fn = env[expr.callee.name]
if len(callee_fn.args) != len(expr.arguments):
raise CompilationError(expr.arguments.proxy, "incorrect argument count")
argv = [compile_expr(build, argument, env) for argument in expr.arguments]
return build.call(callee_fn, argv)
if istype(expr, u"variable:name"):
if expr.name in env:
return env[expr.name]
else:
raise CompilationError(expr.proxy, "out of scope")
if istype(expr, u"assign:slot:value"):
assert istype(expr.slot, u"variable:name")
value = compile_expr(build, expr.value, env)
env[expr.slot.name] = value
return value
if istype(expr, u"return:value"):
value = compile_expr(build, expr.value, env)
build.ret(value)
return value
raise CompilationError(expr.proxy, "unknown statement")
def compile_expr(build, expr, env):
if istype(expr, u"number:value"):
return Constant.int(int_t, int(expr.value))
if istype(expr, u"call:callee:arguments"):
assert istype(expr.callee, u"variable:name")
callee_fn = env[expr.callee.name]
if len(callee_fn.args) != len(expr.arguments):
raise CompilationError(expr.arguments.proxy, "incorrect argument count")
argv = [compile_expr(build, argument, env) for argument in expr.arguments]
return build.call(callee_fn, argv)
if istype(expr, u"variable:name"):
if expr.name in env:
return env[expr.name]
else:
raise CompilationError(expr.proxy, "out of scope")
if istype(expr, u"assign:slot:value"):
assert istype(expr.slot, u"variable:name")
value = compile_expr(build, expr.value, env)
env[expr.slot.name] = value
return value
if istype(expr, u"return:value"):
value = compile_expr(build, expr.value, env)
build.ret(value)
return value
raise CompilationError(expr.proxy, "unknown statement")
callee_fn = env[expr.callee.name]
if len(callee_fn.args) != len(expr.arguments):
raise CompilationError(expr.arguments.proxy, "incorrect argument count")
argv = [compile_expr(build, argument, env) for argument in expr.arguments]
return build.call(callee_fn, argv)
if istype(expr, u"variable:name"):
if expr.name in env:
return env[expr.name]
else:
raise CompilationError(expr.proxy, "out of scope")
if istype(expr, u"assign:slot:value"):
assert istype(expr.slot, u"variable:name")
value = compile_expr(build, expr.value, env)
env[expr.slot.name] = value
return value
if istype(expr, u"return:value"):
value = compile_expr(build, expr.value, env)
build.ret(value)
return value
raise CompilationError(expr.proxy, "unknown statement")
def compile_expr(build, expr, env):
if istype(expr, u"number:value"):
return Constant.int(int_t, int(expr.value))
if istype(expr, u"call:callee:arguments"):
assert istype(expr.callee, u"variable:name")
callee_fn = env[expr.callee.name]
if len(callee_fn.args) != len(expr.arguments):
raise CompilationError(expr.arguments.proxy, "incorrect argument count")
argv = [compile_expr(build, argument, env) for argument in expr.arguments]
return build.call(callee_fn, argv)
if istype(expr, u"variable:name"):
if expr.name in env:
return env[expr.name]
else:
raise CompilationError(expr.proxy, "out of scope")
if istype(expr, u"assign:slot:value"):
assert istype(expr.slot, u"variable:name")
value = compile_expr(build, expr.value, env)