From f03c78908848c09f830bfa2ed27db56b79dae292 Mon Sep 17 00:00:00 2001 From: Jared Young Date: Sat, 2 Nov 2019 19:00:04 +0000 Subject: [PATCH] It compiles at least... --- .gitignore | 1 + mp-s7-src/CMakeLists.txt | 50 +++++++++++++++++++++++++++ mp-s7-src/main.c | 46 +++++++++++++----------- mp-s7-src/mpconfigport.h | 3 ++ mp-s7-src/{uart_core.c => stringio.c} | 0 5 files changed, 79 insertions(+), 21 deletions(-) create mode 100644 mp-s7-src/CMakeLists.txt rename mp-s7-src/{uart_core.c => stringio.c} (100%) diff --git a/.gitignore b/.gitignore index eaba969..e9d7050 100644 --- a/.gitignore +++ b/.gitignore @@ -199,3 +199,4 @@ dmypy.json # End of https://www.gitignore.io/api/c,c++,cmake,python testcode/ +build/ diff --git a/mp-s7-src/CMakeLists.txt b/mp-s7-src/CMakeLists.txt new file mode 100644 index 0000000..930e5b0 --- /dev/null +++ b/mp-s7-src/CMakeLists.txt @@ -0,0 +1,50 @@ +cmake_minimum_required(VERSION 3.0) +project(MPTests VERSION 0.1 LANGUAGES C CXX) + +add_library(RetroConsole + retro/Console.cc + retro/Console.h + retro/ConsoleWindow.cc + retro/ConsoleWindow.h + retro/MacUtils.h + retro/InitConsole.cc + ) +set_target_properties(RetroConsole + PROPERTIES + COMPILE_OPTIONS -ffunction-sections) + +# different library name for Carbon +# (Carbon shares the powerpc-apple-macos/ directory with Classic PPC) +if(CMAKE_SYSTEM_NAME MATCHES RetroCarbon) + set_target_properties(RetroConsole PROPERTIES OUTPUT_NAME RetroConsoleCarbon) +endif() +target_include_directories(RetroConsole PUBLIC .) + +install(TARGETS RetroConsole DESTINATION lib) + + +#App parts + +file(GLOB micropython_py_SRC + "../micropython/py/*.h" + "../micropython/py/*.c" + ../micropython/lib/utils/stdout_helpers.c + ../micropython/ports/minimal/build/_frozen_mpy.c + mpconfigport.h + mphalport.h + stringio.c + main.c + ) +add_application(MPTests ${micropython_py_SRC}) + +target_include_directories(MPTests + PUBLIC ../micropython/ + ../micropython/ports/minimal/build/ + ./ + ) + +target_link_libraries(MPTests + RetroConsole + # MP + ) + diff --git a/mp-s7-src/main.c b/mp-s7-src/main.c index fe01081..4988732 100644 --- a/mp-s7-src/main.c +++ b/mp-s7-src/main.c @@ -1,3 +1,4 @@ +//#include "retro/Console.h" #include #include #include @@ -7,7 +8,7 @@ #include "py/repl.h" #include "py/gc.h" #include "py/mperrno.h" -#include "lib/utils/pyexec.h" +#include "lib/utils/pyexec.h" #if MICROPY_ENABLE_COMPILER void do_str(const char *src, mp_parse_input_kind_t input_kind) { @@ -31,7 +32,15 @@ static char *stack_top; static char heap[2048]; #endif -int main(int argc, char **argv) { +/* +namespace retro +{ + void InitConsole(); +} +*/ + +int main() +{ int stack_dummy; stack_top = (char*)&stack_dummy; @@ -39,25 +48,21 @@ int main(int argc, char **argv) { gc_init(heap, heap + sizeof(heap)); #endif mp_init(); - #if MICROPY_ENABLE_COMPILER - #if MICROPY_REPL_EVENT_DRIVEN - pyexec_event_repl_init(); - for (;;) { - int c = mp_hal_stdin_rx_chr(); - if (pyexec_event_repl_process_char(c)) { - break; - } - } - #else - pyexec_friendly_repl(); - #endif - //do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_SINGLE_INPUT); - //do_str("for i in range(10):\r\n print(i)", MP_PARSE_FILE_INPUT); - #else - pyexec_frozen_module("frozentest.py"); - #endif - mp_deinit(); + +/* + retro::InitConsole(); + std::string out = "Hello, world.\nEnter \"exit\" to quit.\n"; + retro::Console::currentInstance->write(out.data(), out.size()); + + std::string in; + do + { + in = retro::Console::currentInstance->ReadLine(); + out = "You Entered: " + in; + retro::Console::currentInstance->write(out.data(), out.size()); + } while(in != "exit\n"); return 0; +*/ } void gc_collect(void) { @@ -97,4 +102,3 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c __fatal_error("Assertion failed"); } #endif - diff --git a/mp-s7-src/mpconfigport.h b/mp-s7-src/mpconfigport.h index 5304eed..350f67a 100644 --- a/mp-s7-src/mpconfigport.h +++ b/mp-s7-src/mpconfigport.h @@ -7,6 +7,8 @@ // will still be able to execute pre-compiled scripts, compiled with mpy-cross. #define MICROPY_ENABLE_COMPILER (1) +#define MICROPY_ENABLE_EXTERNAL_IMPORT (0) //removed for first compile. TODO remove this line to default to enabled + #define MICROPY_QSTR_BYTES_IN_HASH (1) #define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool #define MICROPY_ALLOC_PATH_MAX (256) @@ -74,6 +76,7 @@ typedef unsigned mp_uint_t; // must be pointer size typedef long mp_off_t; #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len) +//TODO: make the above call to a new function that will deal with macos linefeeds // extra built in names to add to the global namespace #define MICROPY_PORT_BUILTINS \ diff --git a/mp-s7-src/uart_core.c b/mp-s7-src/stringio.c similarity index 100% rename from mp-s7-src/uart_core.c rename to mp-s7-src/stringio.c