Пример #1
0
# Adapted from /seamless/stdlib/switch-join/switch-join.py
from seamless.highlevel import Context, Cell
from seamless import stdlib

ctx = Context()
ctx.include(stdlib.switch)
ctx.include(stdlib.join)
ctx.a = 10.0
ctx.a1 = Cell("float")
ctx.a2 = Cell("float")
ctx.a3 = Cell("float")
ctx.f1 = 2.0
ctx.f2 = 3.0
ctx.f3 = 4.0


def add(a, b):
    return a + b


def sub(a, b):
    return a - b


def mul(a, b):
    return a * b


ctx.op1 = add
ctx.op1.a = ctx.a1
ctx.op1.b = ctx.f1
Пример #2
0
mylib.switch = ctx_switch
mylib.switch.constructor = ctx_switch.constructor_code.value
mylib.switch.params = ctx_switch.constructor_params.value
mylib.join = ctx_join
mylib.join.constructor = ctx_join.constructor_code.value
mylib.join.params = ctx_join.constructor_params.value

# 4: Run test example

ctx2 = Context()
ctx2.include(mylib.switch)
ctx2.include(mylib.join)
ctx2.a = 10.0
ctx2.a1 = Cell("float")
ctx2.a2 = Cell("float")
ctx2.a3 = Cell("float")
ctx2.f1 = 2.0
ctx2.f2 = 3.0
ctx2.f3 = 4.0

def add(a,b):
    return a + b
def sub(a,b):
    return a - b
def mul(a,b):
    return a * b

ctx2.op1 = add
ctx2.op1.a = ctx2.a1
ctx2.op1.b = ctx2.f1
ctx2.r1 = ctx2.op1