diff options
author | Damien <damien.p.george@gmail.com> | 2013-10-12 14:30:21 +0100 |
---|---|---|
committer | Damien <damien.p.george@gmail.com> | 2013-10-12 14:30:21 +0100 |
commit | c025ebb2dc38891fff1d451d13382d9717fb1d59 (patch) | |
tree | 803f297d238417c90893a121bf6926519f469f44 /unix | |
parent | a56f29262661ba6affc50d2e1f6e27ecc7aac116 (diff) | |
download | micropython-c025ebb2dc38891fff1d451d13382d9717fb1d59.tar.gz micropython-c025ebb2dc38891fff1d451d13382d9717fb1d59.zip |
Separate out mpy core and unix version.
Diffstat (limited to 'unix')
-rw-r--r-- | unix/Makefile | 65 | ||||
-rw-r--r-- | unix/main.c | 62 | ||||
-rw-r--r-- | unix/mpyconfig.h | 14 |
3 files changed, 141 insertions, 0 deletions
diff --git a/unix/Makefile b/unix/Makefile new file mode 100644 index 0000000000..6a48cee221 --- /dev/null +++ b/unix/Makefile @@ -0,0 +1,65 @@ +PYSRC=../py +BUILD=build + +CC = gcc +CFLAGS = -I. -I$(PYSRC) -Wall -ansi -std=gnu99 -Os #-DNDEBUG +CFLAGS_PY = -DEMIT_ENABLE_CPY -DEMIT_ENABLE_THUMB +LDFLAGS = + +SRC_C = \ + main.c \ + +PY_O = \ + malloc.o \ + qstr.o \ + misc.o \ + lexer.o \ + lexerfile.o \ + parse.o \ + scope.o \ + compile.o \ + emitcommon.o \ + emitpass1.o \ + emitcpy.o \ + emitbc.o \ + asmx64.o \ + emitnx64.o \ + asmthumb.o \ + emitnthumb.o \ + emitinlinethumb.o \ + runtime.o \ + vm.o \ + +OBJ = $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(PY_O)) +LIB = +PROG = py + +$(PROG): $(BUILD) $(OBJ) + $(CC) -o $@ $(OBJ) $(LIB) $(LDFLAGS) + +$(BUILD): + mkdir $@ + +$(BUILD)/%.o: %.c + $(CC) $(CFLAGS) -c -o $@ $< + +$(BUILD)/%.o: $(PYSRC)/%.c mpyconfig.h + $(CC) $(CFLAGS) $(CFLAGS_PY) -c -o $@ $< + +$(BUILD)/emitnx64.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h + $(CC) $(CFLAGS) $(CFLAGS_PY) -DN_X64 -c -o $@ $< + +$(BUILD)/emitnthumb.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h + $(CC) $(CFLAGS) $(CFLAGS_PY) -DN_THUMB -c -o $@ $< + +# optimising vm for speed, adds only a small amount to code size but makes a huge difference to speed (20% faster) +$(BUILD)/vm.o: $(PYSRC)/vm.c + $(CC) $(CFLAGS) $(CFLAGS_PY) -O3 -c -o $@ $< + +$(BUILD)/parse.o: $(PYSRC)/grammar.h +$(BUILD)/compile.o: $(PYSRC)/grammar.h +$(BUILD)/emitcpy.o: $(PYSRC)/emit.h +$(BUILD)/emitbc.o: $(PYSRC)/emit.h + +clean: + /bin/rm -r $(BUILD) diff --git a/unix/main.c b/unix/main.c new file mode 100644 index 0000000000..2a1103c45f --- /dev/null +++ b/unix/main.c @@ -0,0 +1,62 @@ +#include <stdint.h> +#include <stdio.h> +#include <string.h> + +#include "misc.h" +#include "mpyconfig.h" +#include "lexer.h" +#include "parse.h" +#include "compile.h" +#include "runtime.h" + +int main(int argc, char **argv) { + qstr_init(); + rt_init(); + + if (argc != 2) { + printf("usage: py <file>\n"); + return 1; + } + py_lexer_t *lex = py_lexer_from_file(argv[1]); + //const char *pysrc = "def f():\n x=x+1\n print(42)\n"; + //py_lexer_t *lex = py_lexer_from_str_len("<>", pysrc, strlen(pysrc), false); + if (lex == NULL) { + return 1; + } + + if (0) { + while (!py_lexer_is_kind(lex, PY_TOKEN_END)) { + py_token_show(py_lexer_cur(lex)); + py_lexer_to_next(lex); + } + } else { + py_parse_node_t pn = py_parse(lex, 0); + if (pn != PY_PARSE_NODE_NULL) { + //printf("----------------\n"); + //parse_node_show(pn, 0); + //printf("----------------\n"); + py_compile(pn); + //printf("----------------\n"); + } + } + + py_lexer_free(lex); + +#if !defined(MICROPY_EMIT_ENABLE_CPYTHON) + if (1) { + // execute it + py_obj_t module_fun = rt_make_function_from_id(1); + if (module_fun != py_const_none) { + py_obj_t ret = rt_call_function_0(module_fun); + printf("done! got: "); + py_obj_print(ret); + printf("\n"); + } + } +#endif + + rt_deinit(); + + //printf("total bytes = %d\n", m_get_total_bytes_allocated()); + return 0; +} diff --git a/unix/mpyconfig.h b/unix/mpyconfig.h new file mode 100644 index 0000000000..117892b3d6 --- /dev/null +++ b/unix/mpyconfig.h @@ -0,0 +1,14 @@ +// options to control how Micro Python is built + +//#define MICROPY_ENABLE_FLOAT +#define MICROPY_EMIT_ENABLE_CPYTHON +#define MICROPY_EMIT_ENABLE_X64 +//#define MICROPY_EMIT_ENABLE_THUMB +#define MICROPY_EMIT_ENABLE_INLINE_THUMB + +// type definitions for the specific machine + +typedef int64_t machine_int_t; // must be pointer size +typedef uint64_t machine_uint_t; // must be pointer size +typedef void *machine_ptr_t; // must be of pointer size +typedef double machine_float_t; |