Exemple #1
0
class Bar(object):
    def baz(self, ):
        return "baz"


class Foo(Bar):
    def faz(self, ):
        return "faz"


foo = Foo()
print foo.faz()
print foo.baz()

# Cause a GC
print "sys.heap() = ", sys.heap()
a = range(120)
print "sys.heap() = ", sys.heap()

# Overwrite a reclaimed chunk
del a
b = range(50)

# Try to use a method from a base class
print foo
print foo.faz()
print foo.baz()

# A C assertion reveals regression: subclass is not of type class.
# This occurs because the chunk was GC'd accidentally and then
# was overwritten with another object:
Exemple #2
0
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#

#
# Test for Issue #104: Design and implement garbage collection
#
# Run code that will cause a GC and then run more code to see that things
# still work.
#

import sys

print "Heap =", sys.heap()

i = 10
x = 10
r = None
while x > 0:
    print "Allocating...",
    r = range(i)
    print "done"
    print "Heap =", sys.heap()
    x -= 1

print "i = range(50)"

print "Heap =", sys.heap()
Exemple #3
0
# Anything that starts with a # is a comment!
# Use lots of comments in your code to explain what you're doing.

# Use the PIC-specific Python libraries
import pic24_dspic33 as pic

# Monitor RAM usage
import sys
print "\n\nRAM usage: (free, total): ", sys.heap()



###############################################################
# Set up line sensors, distance sensor, motors 
###############################################################

# Line sensors are digital inputs. Create one.
print "Testing line sensors.",
# For port and pin, a label of RA1 is port = 0 (A), pin = 1;
#                   a label of RB9 is port = 1 (B), pin = 9.
#                             port pin isInput
line_sensor_left =   pic.digital_io(1,   7,  True)
line_sensor_middle = pic.digital_io(1,   8,  True)
line_sensor_right =  pic.digital_io(1,   9,  True)
print "Line sensor 4: Is a black line present?",
print line_sensor_middle.get()

# The distance sensor is an analog input. Create one.
print "Distance sensor: voltage is",
# The only argument to analog_input is the ANx number of
# the analog pin to use. Below, the distance sensor is
Exemple #4
0
# This file is Copyright 2003 Dean Hall.
#
# This file is part of the Python-on-a-Chip program.
# Python-on-a-Chip is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
#
# Python-on-a-Chip is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
# is seen in the file COPYING up one directory from this.

#
# System Test 095
# Fix sys.heap() so it doesn't overwrite the static const 0 integer obj
#

import sys

h = sys.heap()

assert h[0] != (1 - 1)
Exemple #5
0
# PyMite - A flyweight Python interpreter for 8-bit microcontrollers and more.
# Copyright 2002 Dean Hall
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#

#
# System Test 095
#
# Regression test for issue #95:
# Fix sys.heap() so it doesn't overwrite the static const 0 integer obj
#

import sys

h = sys.heap()

assert h[0] != (1-1)
Exemple #6
0
for i in range(0,11):
	print i;
	if(i==5):
		print "if-then %-22.20f" % (1.0/i);
	if(i<3):
		print "if-(then)-else %32.32f" % (1.0*i);
	else:
		print "if-then-(else) %-.32f" % (1.0/i);
print "=== check: for loop 100 func-call-loop";
for i in range(0,100):
	j= nulladd(i)+j;
j= nulllib(j);
print j

print "=== check: sys module-*";
print sys.heap();
sys.putb(0x31);sys.putb(0x31);sys.putb(0x39);sys.putb(0x32); ## will display 1192
print "\r\n";
print sys.getb(); ## -1=255 returned
print sys.time(); # will return zero... not implemented yet X-D
#sys.wait(150); ## waiting 150ms ... looping :-<
#print sys.time();

print "=== check: string module-atoi";
print string.atoi("-123");
print string.atoi("   -123",8);
print string.atoi("-123",16);
##print string.atoi("-123   "); ## error trailing junk chars.

print "=== check: string module-find";
print string.find("-123",'-');
Exemple #7
0
        sys.print_vm_state()
        self.x = 0
#        return self

    def foo(self):
        print "x=",self.x

del sys.registerCallback
del sys.time
del sys.puts
del sys.exit
del thread.yieldThread
del thread.critLock
del thread.critUnlock

print "hello world!, heap:",sys.heap()

def bar():
    print "Hello space!"

a = A()
print "got here"
sys.print_vm_state()
b = A()
print "got here2"

#b.x=2
a.foo()
thread.runInThread(bar)
#b.foo()
Exemple #8
0

class Bar(object):
    def baz(self, ):
        return "baz"

class Foo(Bar):
    def faz(self, ):
        return "faz"

foo = Foo()
print foo.faz()
print foo.baz()

# Cause a GC
print "sys.heap() = ", sys.heap()
a = range(120)
sys.gc()
print "sys.heap() = ", sys.heap()

# Overwrite a reclaimed chunk
del a
b = range(50)

# Try to use a method from a base class
print foo
print foo.faz()
print foo.baz()

# A C assertion reveals regression: subclass is not of type class.
# This occurs because the chunk was GC'd accidentally and then
Exemple #9
0
"""__NATIVE__
#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>
#include "libmmb103.h"
"""


#
# Do this at the very start to show that PyMite is running
#
if False:
    import sys

    print sys.heap()  # (1762,3328)

    s = "It's alive!"
    print s

    import mmb

    mmb.lcd_print("PyMite on MMB103")

    while True:
        mmb.lcd_set_line(1)
        if mmb.dip_get(1):
            mmb.lcd_print("dip1 = ON ")
        else:
            mmb.lcd_print("dip1 = OFF")
        mmb.sleepms(50)
Exemple #10
0

#        return self

    def foo(self):
        print "x=", self.x

del sys.registerCallback
del sys.time
del sys.puts
del sys.exit
del thread.yieldThread
del thread.critLock
del thread.critUnlock

print "hello world!, heap:", sys.heap()


def bar():
    print "Hello space!"


a = A()
print "got here"
sys.print_vm_state()
b = A()
print "got here2"

#b.x=2
a.foo()
thread.runInThread(bar)
Exemple #11
0
# This file is Copyright 2003 Dean Hall.
#
# This file is part of the Python-on-a-Chip program.
# Python-on-a-Chip is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
#
# Python-on-a-Chip is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
# is seen in the file COPYING up one directory from this.

#
# System Test 150
# Replace PmImgInfo_t to save RAM
#

import sys
print sys.heap()
Exemple #12
0
#
# This is a sample application that calls native functions.
#
"""__NATIVE__
#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>
#include "libmmb103.h"
"""

#
# Do this at the very start to show that PyMite is running
#
if False:
    import sys
    print sys.heap()  # (1762,3328)

    s = "It's alive!"
    print s

    import mmb
    mmb.lcd_print("PyMite on MMB103")

    while True:
        mmb.lcd_set_line(1)
        if mmb.dip_get(1):
            mmb.lcd_print("dip1 = ON ")
        else:
            mmb.lcd_print("dip1 = OFF")
        mmb.sleepms(50)
        mmb.sleepms(50)
Exemple #13
0
        sys.wait(300)
        state1 = len_digIO.getDigIn(len_contr.DEV_CTRL, 0, 0)
        counter1 = len_digIO.getCounterIn(len_contr.DEV_CTRL, 0, 0)
        state2 = len_digIO.getDigIn(len_contr.DEV_CTRL, 0, 1)
        counter2 = len_digIO.getCounterIn(len_contr.DEV_CTRL, 0, 1)
        num += 1
        len_digIO.setPwmOut(len_contr.DEV_CTRL, 0, 1, counter2)
        print "Times:", num, " State1:", state1, " Counter1:", counter1, " State2:", state2, " Counter2:", counter2


def GPIO_callback():
    callback_val = len_sys.getCallbackValue()
    print "GPIO callback from:", callback_val[0], " addr:", callback_val[
        1], " source:", callback_val[2], " val:", callback_val[3]
    len_sys.ClearCallback()


len_digIO.setModeIn(len_contr.DEV_CTRL, 0, 0, len_digIO.IN_CNT_R_MODE)
len_digIO.setModeIn(len_contr.DEV_CTRL, 0, 1, len_digIO.IN_CNT_RF_MODE)
len_digIO.setModeOut(len_contr.DEV_CTRL, 0, 1, len_digIO.PWM_MODE)

#sys.runInThread(thread_out)
sys.runInThread(thread_in)
len_sys.addCallback(GPIO_callback)

print "\n\rScript start"

while 1:
    print "                                                                                                         Heap:", sys.heap(
    )
    sys.wait(1000)