示例#1
0
from embedvm.runtime import Globals, UserfuncWrapper
import time
'''
from embedvm.runtime import trampolined
'''

memmapped = Globals()
memmapped.led = memmapped.array8u(0, length=4)
memmapped.leds = memmapped.int8u(4)
memmapped.rgb = memmapped.array8u(5, length=3)
memmapped.button = memmapped.array8u(8, length=4)
memmapped.buttons = memmapped.int8u(12)
memmapped.buzzer = memmapped.int16(13)
memmapped.padding = memmapped.int8u(15)


@UserfuncWrapper(which=1)
def sleep(millis):
    time.sleep(millis / 1000.0)


'''
@trampolined(address=0x3000)
def kitt():
    print "Doing a KITT style animation over the LEDs."
    '''
示例#2
0
from embedvm.runtime import Globals
from testsuite import userfunc, end

gv = Globals()
gv.a8u = gv.array8u(init=[1, 2, 3, 4, 5])
gv.a8s = gv.array8s(init=[-1, -2, -3, -4, -5])
gv.a16 = gv.array16(init=[1000, 2000, 3000, 4000, 5000])

def pr():
    for i in range(5):
        userfunc(1, gv.a8u[i], gv.a8s[i], gv.a16[i])
    userfunc(2)

def main():
    pr()

    for i in range(5):
        gv.a8u[i] = gv.a8u[i] + 1 # TBD: +=
        gv.a8s[i] = gv.a8s[i] - 1
        gv.a16[i] = gv.a16[i] - gv.a8s[i] # TBD: -=, --

    pr()

    for i in range(5):
        gv.a8u[i] = 200 + i
        if i & 1: # TBD: b if a else c
            gv.a8s[i] = 100 * -1
        else:
            gv.a8s[i] = 100 * 1
        gv.a16[i] = 111 * (i+1)
示例#3
0
from embedvm.runtime import Globals, c_division
from testsuite import userfunc as uf, end

gv = Globals()
gv.ghundret = gv.int16(init=100)


def fibonacci(n, m=42):
    """this is probaly the stupidiest way to calculate a
    fibonacci number - but it is a nice recursion test.."""
    if n < 2:
        return n
    return fibonacci(n - 2) + fibonacci(n - 1)


def main():
    one = 1
    two = one
    two = two + 1  # TBD: ++

    thousand = two * 500
    negthousand = -thousand

    uf(1, 1 + 1 * 2)
    uf(1, one + one * two)
    uf(1, thousand / gv.ghundret)
    uf(1, c_division(0x7fff, negthousand))
    uf(1, c_division(-0x7fff, thousand))
    uf(1, c_division(-0x7fff, negthousand))

    uf(1, fibonacci(6))
示例#4
0
from embedvm.runtime import Globals, UserfuncWrapper
import time
'''
from embedvm.runtime import trampolined
'''

memmapped = Globals()
memmapped.led = memmapped.array8u(0, length=4)
memmapped.leds = memmapped.int8u(4)
memmapped.rgb = memmapped.array8u(5, length=3)
memmapped.button = memmapped.array8u(8, length=4)
memmapped.buttons = memmapped.int8u(12)
memmapped.buzzer = memmapped.int16(13)
memmapped.padding = memmapped.int8u(15)

@UserfuncWrapper(which=1)
def sleep(millis):
    time.sleep(millis/1000.0)

'''
@trampolined(address=0x3000)
def kitt():
    print "Doing a KITT style animation over the LEDs."
    '''
示例#5
0
from embedvm.runtime import Globals, c_division
from testsuite import userfunc as uf, end

gv = Globals()
gv.ghundret = gv.int16(init=100)

def fibonacci(n, m=42):
    """this is probaly the stupidiest way to calculate a
    fibonacci number - but it is a nice recursion test.."""
    if n < 2:
        return n
    return fibonacci(n-2) + fibonacci(n-1)

def main():
    one = 1
    two = one
    two = two + 1 # TBD: ++

    thousand = two * 500
    negthousand = -thousand

    uf(1, 1+1*2)
    uf(1, one + one * two)
    uf(1, thousand / gv.ghundret)
    uf(1, c_division(0x7fff, negthousand))
    uf(1, c_division(-0x7fff, thousand))
    uf(1, c_division(-0x7fff, negthousand))

    uf(1, fibonacci(6))

if __name__ == "__main__":