summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--examples/conwaylife.py6
-rw-r--r--examples/mandel.py3
-rw-r--r--examples/pyb.py4
-rw-r--r--py/makeqstrdata.py22
-rw-r--r--py/qstrdefs.h8
-rw-r--r--py/scope.c12
6 files changed, 36 insertions, 19 deletions
diff --git a/examples/conwaylife.py b/examples/conwaylife.py
index 7c6ac4d548..89ef94c8c6 100644
--- a/examples/conwaylife.py
+++ b/examples/conwaylife.py
@@ -1,3 +1,7 @@
+#import essential libraries
+import lcd
+import pyb
+
# do 1 iteration of Conway's Game of Life
def conway_step():
for x in range(128): # loop over x coordinates
@@ -37,8 +41,6 @@ def conway_go(num_frames):
pyb.delay(300)
# PC testing
-import lcd
-import pyb
lcd = lcd.LCD(128, 32)
conway_rand()
conway_go(1000)
diff --git a/examples/mandel.py b/examples/mandel.py
index d2b34fff83..bbb8086470 100644
--- a/examples/mandel.py
+++ b/examples/mandel.py
@@ -3,10 +3,9 @@ try:
except:
pass
-
def mandelbrot():
# returns True if c, complex, is in the Mandelbrot set
- @micropython.native
+ #@micropython.native
def in_set(c):
z = 0
for i in range(40):
diff --git a/examples/pyb.py b/examples/pyb.py
index f7b52a2a1e..65fed6647e 100644
--- a/examples/pyb.py
+++ b/examples/pyb.py
@@ -1,9 +1,9 @@
# pyboard testing functions for CPython
import time
-
def delay(n):
- time.sleep(float(n) / 1000)
+ #time.sleep(float(n) / 1000)
+ pass
rand_seed = 1
def rand():
diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py
index c4b7be42e7..c5ad708e89 100644
--- a/py/makeqstrdata.py
+++ b/py/makeqstrdata.py
@@ -1,6 +1,13 @@
import argparse
import re
+# codepoint2name is different in Python 2 to Python 3
+import platform
+if platform.python_version_tuple()[0] == '2':
+ from htmlentitydefs import codepoint2name
+elif platform.python_version_tuple()[0] == '3':
+ from html.entities import codepoint2name
+
# this must match the equivalent function in qstr.c
def compute_hash(qstr):
hash = 0
@@ -10,7 +17,7 @@ def compute_hash(qstr):
def do_work(infiles):
# read the qstrs in from the input files
- qstrs = []
+ qstrs = {}
for infile in infiles:
with open(infile, 'rt') as f:
line_number = 0
@@ -23,28 +30,29 @@ def do_work(infiles):
continue
# verify line is of the correct form
- match = re.match(r'Q\(([0-9A-Za-z_]+)\)$', line)
+ match = re.match(r'Q\((.+)\)$', line)
if not match:
print('({}:{}) bad qstr format, got {}'.format(infile, line_number, line))
return False
# get the qstr value
qstr = match.group(1)
+ ident = re.sub(r'[^A-Za-z0-9_]', lambda s: "_" + codepoint2name[ord(s.group(0))] + "_", qstr)
# don't add duplicates
- if qstr in qstrs:
+ if ident in qstrs:
continue
- # add the qstr to the list
- qstrs.append(qstr)
+ # add the qstr to the list, with order number to retain original order in file
+ qstrs[ident] = (len(qstrs), ident, qstr)
# process the qstrs, printing out the generated C header file
print('// This file was automatically generated by makeqstrdata.py')
print('')
- for qstr in qstrs:
+ for order, ident, qstr in sorted(qstrs.values(), key=lambda x: x[0]):
qhash = compute_hash(qstr)
qlen = len(qstr)
- print('Q({}, (const byte*)"\\x{:02x}\\x{:02x}\\x{:02x}\\x{:02x}" "{}")'.format(qstr, qhash & 0xff, (qhash >> 8) & 0xff, qlen & 0xff, (qlen >> 8) & 0xff, qstr))
+ print('Q({}, (const byte*)"\\x{:02x}\\x{:02x}\\x{:02x}\\x{:02x}" "{}")'.format(ident, qhash & 0xff, (qhash >> 8) & 0xff, qlen & 0xff, (qlen >> 8) & 0xff, qstr))
return True
diff --git a/py/qstrdefs.h b/py/qstrdefs.h
index 9bc01c5851..f2c4dfd97f 100644
--- a/py/qstrdefs.h
+++ b/py/qstrdefs.h
@@ -80,3 +80,11 @@ Q(sort)
Q(join)
Q(strip)
Q(format)
+
+Q(<module>)
+Q(<lambda>)
+Q(<listcomp>)
+Q(<dictcomp>)
+Q(<setcomp>)
+Q(<genexpr>)
+Q(<stdin>)
diff --git a/py/scope.c b/py/scope.c
index 1f602ac9c0..ab20f61f37 100644
--- a/py/scope.c
+++ b/py/scope.c
@@ -18,7 +18,7 @@ scope_t *scope_new(scope_kind_t kind, mp_parse_node_t pn, qstr source_file, uint
scope->source_file = source_file;
switch (kind) {
case SCOPE_MODULE:
- scope->simple_name = QSTR_FROM_STR_STATIC("<module>");
+ scope->simple_name = MP_QSTR__lt_module_gt_;
break;
case SCOPE_FUNCTION:
case SCOPE_CLASS:
@@ -26,19 +26,19 @@ scope_t *scope_new(scope_kind_t kind, mp_parse_node_t pn, qstr source_file, uint
scope->simple_name = MP_PARSE_NODE_LEAF_ARG(((mp_parse_node_struct_t*)pn)->nodes[0]);
break;
case SCOPE_LAMBDA:
- scope->simple_name = QSTR_FROM_STR_STATIC("<lambda>");
+ scope->simple_name = MP_QSTR__lt_lambda_gt_;
break;
case SCOPE_LIST_COMP:
- scope->simple_name = QSTR_FROM_STR_STATIC("<listcomp>");
+ scope->simple_name = MP_QSTR__lt_listcomp_gt_;
break;
case SCOPE_DICT_COMP:
- scope->simple_name = QSTR_FROM_STR_STATIC("<dictcomp>");
+ scope->simple_name = MP_QSTR__lt_dictcomp_gt_;
break;
case SCOPE_SET_COMP:
- scope->simple_name = QSTR_FROM_STR_STATIC("<setcomp>");
+ scope->simple_name = MP_QSTR__lt_setcomp_gt_;
break;
case SCOPE_GEN_EXPR:
- scope->simple_name = QSTR_FROM_STR_STATIC("<genexpr>");
+ scope->simple_name = MP_QSTR__lt_genexpr_gt_;
break;
default:
assert(0);