Skip to content

Commit 19ccc6b

Browse files
committed
Added Windows port (see adafruit#233)
1 parent 9b00dad commit 19ccc6b

8 files changed

Lines changed: 162 additions & 55 deletions

File tree

py/asmx64.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <stdint.h>
12
#include <stdio.h>
23
#include <assert.h>
34
#include <string.h>

py/nlrx86.S

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
.text
66

77
/* uint nlr_push(4(%esp)=nlr_buf_t *nlr) */
8+
#ifdef __apple_build_version__
89
.globl nlr_push
910
.type nlr_push, @function
1011
nlr_push:
12+
#else
13+
.globl _nlr_push
14+
_nlr_push:
15+
#endif
1116
mov 4(%esp), %edx # load nlr_buf
1217
mov (%esp), %eax # load return %ip
1318
mov %eax, 8(%edx) # store %ip into nlr_buf+8
@@ -21,22 +26,36 @@ nlr_push:
2126
mov %edx, nlr_top # stor new nlr_buf (to make linked list)
2227
xor %eax, %eax # return 0, normal return
2328
ret # return
29+
#ifdef __apple_build_version__
2430
.size nlr_push, .-nlr_push
31+
#endif
2532

2633
/* void nlr_pop() */
34+
#ifdef __apple_build_version__
2735
.globl nlr_pop
2836
.type nlr_pop, @function
2937
nlr_pop:
38+
#else
39+
.globl _nlr_pop
40+
_nlr_pop:
41+
#endif
3042
mov nlr_top, %eax # load nlr_top
3143
mov (%eax), %eax # load prev nlr_buf
3244
mov %eax, nlr_top # store nlr_top (to unlink list)
3345
ret # return
46+
#ifdef __apple_build_version__
3447
.size nlr_pop, .-nlr_pop
48+
#endif
3549

3650
/* void nlr_jump(4(%esp)=uint val) */
51+
#ifdef __apple_build_version__
3752
.globl nlr_jump
3853
.type nlr_jump, @function
3954
nlr_jump:
55+
#else
56+
.globl _nlr_jump
57+
_nlr_jump:
58+
#endif
4059
mov nlr_top, %edx # load nlr_top
4160
mov 4(%esp), %eax # load return value
4261
mov %eax, 4(%edx) # store return value
@@ -52,8 +71,12 @@ nlr_jump:
5271
xor %eax, %eax # clear return register
5372
inc %al # increase to make 1, non-local return
5473
ret # return
74+
#ifdef __apple_build_version__
5575
.size nlr_jump, .-nlr_jump
76+
#endif
5677

78+
#ifdef __apple_build_version__
5779
.local nlr_top
80+
#endif
5881
.comm nlr_top,4,4
5982
#endif

tests/run-tests

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,51 @@
1-
#!/usr/bin/env bash
2-
3-
RM="/bin/rm -f"
4-
CPYTHON3=python3.3
5-
MP_PY=../unix/micropython
6-
7-
numtests=0
8-
numtestcases=0
9-
numpassed=0
10-
numfailed=0
11-
namefailed=
12-
13-
if [ $# -eq 0 ]
14-
then
15-
tests="basics/*.py io/*.py"
16-
else
17-
tests="$@"
18-
fi
19-
20-
for infile in $tests
21-
do
22-
basename=`basename $infile .py`
23-
outfile=${basename}.out
24-
expfile=${basename}.exp
25-
26-
$CPYTHON3 -B $infile > $expfile
27-
$MP_PY $infile > $outfile
28-
((numtestcases = numtestcases + $(cat $expfile | wc -l)))
29-
30-
diff --brief $expfile $outfile > /dev/null
31-
32-
if [ $? -eq 0 ]
33-
then
34-
echo "pass $infile"
35-
$RM $outfile
36-
$RM $expfile
37-
((numpassed=numpassed + 1))
38-
else
39-
echo "FAIL $infile"
40-
((numfailed=numfailed + 1))
41-
namefailed="$namefailed $basename"
42-
fi
43-
44-
((numtests=numtests + 1))
45-
done
46-
47-
echo "$numtests tests performed ($numtestcases individual testcases)"
48-
echo "$numpassed tests passed"
49-
if [[ $numfailed != 0 ]]
50-
then
51-
echo "$numfailed tests failed -$namefailed"
52-
exit 1
53-
else
54-
exit 0
55-
fi
1+
#! /usr/bin/env python3.3
2+
3+
import os
4+
import subprocess
5+
import sys
6+
from glob import glob
7+
8+
if os.name == 'nt':
9+
CPYTHON3 = 'python3.3.exe'
10+
MP_PY = '../windows/micropython.exe'
11+
else:
12+
CPYTHON3 = 'python3.3'
13+
MP_PY = '../unix/micropython'
14+
15+
16+
test_count = 0
17+
testcase_count = 0
18+
passed_count = 0
19+
failed_tests = []
20+
tests = []
21+
22+
if not sys.argv[1:]:
23+
tests = glob('basics/*.py') + glob('io/*.py')
24+
else:
25+
tests = sys.argv[1:]
26+
27+
for test_file in tests:
28+
test_name = os.path.splitext(os.path.basename(test_file))[0]
29+
30+
output_expected = subprocess.check_output([CPYTHON3, '-B', test_file])
31+
output_mypy = subprocess.check_output([MP_PY, test_file])
32+
33+
testcase_count += len(output_expected.splitlines())
34+
35+
if output_expected != output_mypy:
36+
print("pass ", test_file)
37+
passed_count += 1
38+
else:
39+
print("FAIL ", test_file)
40+
failed_tests.append(test_name)
41+
42+
test_count += 1
43+
44+
print("{} tests performed ({} individual testcases)".format(test_count,
45+
testcase_count))
46+
print("{} tests passed".format(passed_count))
47+
48+
if len(failed_tests) > 0:
49+
print("{} tests failed: {}".format(len(failed_tests),
50+
' '.join(failed_tests)))
51+
sys.exit(1)

windows/Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
include ../py/mkenv.mk
2+
3+
# define main target
4+
PROG = micropython.exe
5+
6+
# qstr definitions (must come before including py.mk)
7+
QSTR_DEFS = qstrdefsport.h
8+
9+
# include py core make definitions
10+
include ../py/py.mk
11+
12+
# compiler settings
13+
CFLAGS = -I. -I$(PY_SRC) -Wall -Werror -ansi -std=gnu99 -DUNIX
14+
LDFLAGS = -lm
15+
16+
# Debugging/Optimization
17+
ifdef DEBUG
18+
CFLAGS += -O0 -g
19+
else
20+
CFLAGS += -Os #-DNDEBUG
21+
endif
22+
23+
# source files
24+
SRC_C = \
25+
main.c \
26+
file.c \
27+
28+
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
29+
LIB = -lreadline
30+
LIB += -lws2_32
31+
LIB += -lmman
32+
# the following is needed for BSD
33+
#LIB += -ltermcap
34+
35+
include ../py/mkrules.mk
36+

windows/file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include <stdio.h>
2+
#include "../unix/file.c"

windows/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "../unix/main.c"
2+
3+
void rawsocket_init() {
4+
// Do nothing here
5+
}

windows/mpconfigport.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// options to control how Micro Python is built
2+
3+
// Linking with GNU readline causes binary to be licensed under GPL
4+
#ifndef MICROPY_USE_READLINE
5+
#define MICROPY_USE_READLINE (1)
6+
#endif
7+
8+
#define MICROPY_EMIT_X64 (1)
9+
#define MICROPY_EMIT_THUMB (0)
10+
#define MICROPY_EMIT_INLINE_THUMB (0)
11+
#define MICROPY_MEM_STATS (1)
12+
#define MICROPY_DEBUG_PRINTERS (1)
13+
#define MICROPY_ENABLE_REPL_HELPERS (1)
14+
#define MICROPY_ENABLE_LEXER_UNIX (1)
15+
#define MICROPY_ENABLE_FLOAT (1)
16+
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_LONGLONG)
17+
18+
// type definitions for the specific machine
19+
20+
#ifdef __LP64__
21+
typedef long machine_int_t; // must be pointer size
22+
typedef unsigned long machine_uint_t; // must be pointer size
23+
#else
24+
// These are definitions for machines where sizeof(int) == sizeof(void*),
25+
// regardless for actual size.
26+
typedef int machine_int_t; // must be pointer size
27+
typedef unsigned int machine_uint_t; // must be pointer size
28+
#endif
29+
30+
#define BYTES_PER_WORD sizeof(machine_int_t)
31+
32+
typedef void *machine_ptr_t; // must be of pointer size
33+
typedef const void *machine_const_ptr_t; // must be of pointer size
34+
typedef double machine_float_t;
35+
36+
machine_float_t machine_sqrt(machine_float_t x);

windows/qstrdefsport.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// qstrs specific to this port
2+
3+
Q(sys)
4+
Q(argv)
5+
Q(open)
6+
Q(stdin)
7+
Q(stdout)
8+
Q(stderr)

0 commit comments

Comments
 (0)