summaryrefslogtreecommitdiffstatshomepage
path: root/unix-cpy/main.c
diff options
context:
space:
mode:
authorDamien <damien.p.george@gmail.com>2013-12-29 18:01:01 +0000
committerDamien <damien.p.george@gmail.com>2013-12-29 18:01:01 +0000
commitde690d128bbec4f53e8a7d6149738a6facae4382 (patch)
tree817a4c8ee94b7576dbfc47cd9a5de67f7c741109 /unix-cpy/main.c
parentb86e3f92932ec543788dc66948519d770d0e5bb0 (diff)
downloadmicropython-de690d128bbec4f53e8a7d6149738a6facae4382.tar.gz
micropython-de690d128bbec4f53e8a7d6149738a6facae4382.zip
Add unix-cpy, used to test Micro Python byte code against CPython.
Diffstat (limited to 'unix-cpy/main.c')
-rw-r--r--unix-cpy/main.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/unix-cpy/main.c b/unix-cpy/main.c
new file mode 100644
index 0000000000..2b59df4f37
--- /dev/null
+++ b/unix-cpy/main.c
@@ -0,0 +1,69 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "nlr.h"
+#include "misc.h"
+#include "mpconfig.h"
+#include "lexer.h"
+#include "lexerunix.h"
+#include "parse.h"
+#include "compile.h"
+#include "obj.h"
+#include "runtime0.h"
+#include "runtime.h"
+
+void do_file(const char *file) {
+ mp_lexer_t *lex = mp_lexer_new_from_file(file);
+ if (lex == NULL) {
+ return;
+ }
+
+ if (0) {
+ // just tokenise
+ while (!mp_lexer_is_kind(lex, MP_TOKEN_END)) {
+ mp_token_show(mp_lexer_cur(lex));
+ mp_lexer_to_next(lex);
+ }
+ mp_lexer_free(lex);
+
+ } else {
+ // compile
+
+ mp_parse_node_t pn = mp_parse(lex, MP_PARSE_FILE_INPUT);
+ mp_lexer_free(lex);
+
+ if (pn != MP_PARSE_NODE_NULL) {
+ //printf("----------------\n");
+ //parse_node_show(pn, 0);
+ //printf("----------------\n");
+ bool comp_ok = mp_compile(pn, false);
+ //printf("----------------\n");
+
+ if (!comp_ok) {
+ printf("compile error\n");
+ }
+ }
+ }
+}
+
+int main(int argc, char **argv) {
+ qstr_init();
+ rt_init();
+
+ if (argc == 2) {
+ do_file(argv[1]);
+ } else {
+ printf("usage: py [<file>]\n");
+ return 1;
+ }
+ rt_deinit();
+
+ return 0;
+}
+
+// for sqrt
+#include <math.h>
+machine_float_t machine_sqrt(machine_float_t x) {
+ return sqrt(x);
+}