From 7c0c28dd71a66fc4028d86e5b34c85af5b32efb5 Mon Sep 17 00:00:00 2001 From: mux Date: Mon, 6 Jan 2014 06:41:56 +0200 Subject: [PATCH 01/17] Fix LED pin enum * Fix LED pin enum, first one should start at 1 * Fix LED initialization typo --- stm/led.c | 4 ++-- stm/led.h | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/stm/led.c b/stm/led.c index 044a91f0c1..6139d6d6c9 100644 --- a/stm/led.c +++ b/stm/led.c @@ -63,8 +63,8 @@ void led_init(void) { /* Turn off LEDs */ PYB_LED_OFF(PYB_LED1_PORT, PYB_LED1_PIN); PYB_LED_OFF(PYB_LED2_PORT, PYB_LED2_PIN); - PYB_LED_OFF(PYB_LED3_PORT, PYB_LED1_PIN); - PYB_LED_OFF(PYB_LED4_PORT, PYB_LED2_PIN); + PYB_LED_OFF(PYB_LED3_PORT, PYB_LED3_PIN); + PYB_LED_OFF(PYB_LED4_PORT, PYB_LED4_PIN); /* Initialize LEDs */ GPIO_InitStructure.GPIO_Pin = PYB_LED1_PIN; diff --git a/stm/led.h b/stm/led.h index fcbfa17634..c68f3e4142 100644 --- a/stm/led.h +++ b/stm/led.h @@ -1,13 +1,13 @@ typedef enum { - PYB_LED_R1 = 0, - PYB_LED_R2 = 1, - PYB_LED_G1 = 2, - PYB_LED_G2 = 3, + PYB_LED_R1 = 1, + PYB_LED_R2 = 2, + PYB_LED_G1 = 3, + PYB_LED_G2 = 4, //STM32F4DISC - PYB_LED_R = 0, - PYB_LED_G = 1, - PYB_LED_B = 2, - PYB_LED_O = 3, + PYB_LED_R = 1, + PYB_LED_G = 2, + PYB_LED_B = 3, + PYB_LED_O = 4, } pyb_led_t; void led_init(void); From 297446e7af472f8869ecca67f37ed159d02b1024 Mon Sep 17 00:00:00 2001 From: Dave Hylands Date: Mon, 6 Jan 2014 00:20:11 -0800 Subject: [PATCH 02/17] Initial support for Teensy 3.1 --- teensy/Makefile | 155 ++++++++++++++ teensy/README.md | 31 +++ teensy/gchelper.s | 36 ++++ teensy/led.c | 86 ++++++++ teensy/led.h | 9 + teensy/lexerteensy.c | 33 +++ teensy/lexerteensy.h | 8 + teensy/main.c | 474 ++++++++++++++++++++++++++++++++++++++++++ teensy/main.cpp | 245 ++++++++++++++++++++++ teensy/malloc0.c | 57 +++++ teensy/mk20dx256.ld | 164 +++++++++++++++ teensy/mpconfigport.h | 21 ++ teensy/printf.c | 305 +++++++++++++++++++++++++++ teensy/std.h | 22 ++ teensy/string0.c | 110 ++++++++++ teensy/usb.c | 44 ++++ teensy/usb.h | 9 + 17 files changed, 1809 insertions(+) create mode 100644 teensy/Makefile create mode 100644 teensy/README.md create mode 100644 teensy/gchelper.s create mode 100644 teensy/led.c create mode 100644 teensy/led.h create mode 100644 teensy/lexerteensy.c create mode 100644 teensy/lexerteensy.h create mode 100644 teensy/main.c create mode 100644 teensy/main.cpp create mode 100644 teensy/malloc0.c create mode 100644 teensy/mk20dx256.ld create mode 100644 teensy/mpconfigport.h create mode 100644 teensy/printf.c create mode 100644 teensy/std.h create mode 100644 teensy/string0.c create mode 100644 teensy/usb.c create mode 100644 teensy/usb.h diff --git a/teensy/Makefile b/teensy/Makefile new file mode 100644 index 0000000000..98b467a06e --- /dev/null +++ b/teensy/Makefile @@ -0,0 +1,155 @@ +ifeq ($(ARDUINO),) +$(error Please define ARDUINO (where TeensyDuino is installed)) +endif +TOOLS_PATH = $(ARDUINO)/hardware/tools +COMPILER_PATH = $(TOOLS_PATH)/arm-none-eabi/bin +CORE_PATH = $(ARDUINO)/hardware/teensy/cores/teensy3 + +PYSRC=../py +BUILD=build + +AS = $(COMPILER_PATH)/arm-none-eabi-as +CC = $(COMPILER_PATH)/arm-none-eabi-gcc +LD = $(COMPILER_PATH)/arm-none-eabi-ld +OBJCOPY = $(COMPILER_PATH)/arm-none-eabi-objcopy +SIZE = $(COMPILER_PATH)/arm-none-eabi-size + +CFLAGS_TEENSY = -DF_CPU=96000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -D__MK20DX256__ +CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -fsingle-precision-constant -Wdouble-promotion $(CFLAGS_TEENSY) +CFLAGS = -I. -I$(PYSRC) -I$(CORE_PATH) -Wall -ansi -std=gnu99 -Os -DNDEBUG $(CFLAGS_CORTEX_M4) +LDFLAGS = -nostdlib -T mk20dx256.ld +LIBS = -L $(COMPILER_PATH)/../lib/gcc/arm-none-eabi/4.7.2/thumb2 -lgcc + +SRC_C = \ + main.c \ + lexerteensy.c \ + led.c \ + malloc0.c \ + printf.c \ + string0.c \ + usb.c \ + +SRC_S = \ + gchelper.s \ + +PY_O = \ + nlrthumb.o \ + gc.o \ + malloc.o \ + qstr.o \ + vstr.o \ + unicode.o \ + lexer.o \ + parse.o \ + scope.o \ + compile.o \ + emitcommon.o \ + emitpass1.o \ + emitbc.o \ + asmthumb.o \ + emitnthumb.o \ + emitinlinethumb.o \ + runtime.o \ + map.o \ + obj.o \ + objbool.o \ + objboundmeth.o \ + objcell.o \ + objclass.o \ + objclosure.o \ + objcomplex.o \ + objdict.o \ + objexcept.o \ + objfloat.o \ + objfun.o \ + objgenerator.o \ + objinstance.o \ + objint.o \ + objlist.o \ + objmodule.o \ + objnone.o \ + objrange.o \ + objset.o \ + objslice.o \ + objstr.o \ + objtuple.o \ + objtype.o \ + builtin.o \ + builtinimport.o \ + vm.o \ + showbc.o \ + repl.o \ + +SRC_TEENSY = \ + mk20dx128.c \ + pins_teensy.c \ + analog.c \ + usb_desc.c \ + usb_dev.c \ + usb_mem.c \ + usb_serial.c \ + yield.c \ + +OBJ = $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o) $(PY_O) $(SRC_TEENSY:.c=.o)) +#LIB = -lreadline +# the following is needed for BSD +#LIB += -ltermcap +PROG = micropython + +all: hex +hex: $(PROG).hex + +post_compile: $(PROG).hex + $(TOOLS_PATH)/teensy_post_compile -file="$(basename $<)" -path="$(CURDIR)" -tools="$(TOOLS_PATH)" + +reboot: + -$(TOOLS_PATH)/teensy_reboot + +upload: post_compile reboot + +$(PROG).elf: $(BUILD) $(OBJ) + $(CC) $(LDFLAGS) -o "$@" -Wl,-Map,$(PROG).map $(OBJ) $(LIBS) + +%.hex: %.elf + $(SIZE) "$<" + $(OBJCOPY) -O ihex -R .eeprom "$<" "$@" + +$(BUILD): + mkdir -p $@ + +$(BUILD)/%.o: %.s + $(AS) -o $@ $< + +$(BUILD)/%.o: %.c + $(CC) $(CFLAGS) -c -o $@ $< + +$(BUILD)/%.o: $(PYSRC)/%.S + $(CC) $(CFLAGS) -c -o $@ $< + +$(BUILD)/%.o: $(PYSRC)/%.c mpconfigport.h + $(CC) $(CFLAGS) -c -o $@ $< + +$(BUILD)/%.o: $(CORE_PATH)/%.c + $(CC) $(CFLAGS) -c -o $@ $< + +$(BUILD)/emitnthumb.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h + $(CC) $(CFLAGS) -DN_THUMB -c -o $@ $< + +# optimising gc for speed; 5ms down to 4ms +$(BUILD)/gc.o: $(PYSRC)/gc.c + $(CC) $(CFLAGS) -O3 -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) -O3 -c -o $@ $< + +$(BUILD)/main.o: mpconfigport.h +$(BUILD)/parse.o: $(PYSRC)/grammar.h +$(BUILD)/compile.o: $(PYSRC)/grammar.h +$(BUILD)/emitbc.o: $(PYSRC)/emit.h + +clean: + /bin/rm -rf $(BUILD) + /bin/rm -f $(PROG).elf $(PROG).hex $(PROG).map + +.PHONY: clean diff --git a/teensy/README.md b/teensy/README.md new file mode 100644 index 0000000000..31339cd796 --- /dev/null +++ b/teensy/README.md @@ -0,0 +1,31 @@ +Build Instructions for Teensy 3.1 + +This assumes that you have TeensyDuino installed and set the ARUINO environment +variable pointing to the where Arduino with TeensyDuino is installed. + +``` +cd teensy +ARDUINO=~/arduino-1.0.5 make +``` + +To build the loader + +``` +cd teensy/loader +make +``` + +To upload micropython to the Teensy 3.1. + +Press the Program button on the Teensy 3.1 +``` +make upload +``` + +Currently, the python prompt is through the USB serial interface. + +The LED will blink (100 msec on/100 msec off) while waiting for the USB Serial +device to be configured, and will blink (200 msec on/200 msec off) while +sitting at the readline prompt. + +Currently, there is no I/O support configured (no GPIO, ADC, etc). diff --git a/teensy/gchelper.s b/teensy/gchelper.s new file mode 100644 index 0000000000..f8735d2830 --- /dev/null +++ b/teensy/gchelper.s @@ -0,0 +1,36 @@ + .syntax unified + .cpu cortex-m4 + .thumb + .text + .align 2 + +@ void gc_helper_get_regs_and_clean_stack(r0=uint regs[10], r1=heap_end) + .global gc_helper_get_regs_and_clean_stack + .thumb + .thumb_func + .type gc_helper_get_regs_and_clean_stack, %function +gc_helper_get_regs_and_clean_stack: + @ store registers into given array + str r4, [r0], #4 + str r5, [r0], #4 + str r6, [r0], #4 + str r7, [r0], #4 + str r8, [r0], #4 + str r9, [r0], #4 + str r10, [r0], #4 + str r11, [r0], #4 + str r12, [r0], #4 + str r13, [r0], #4 + + @ clean the stack from given pointer up to current sp + movs r0, #0 + mov r2, sp + b.n .entry +.loop: + str r0, [r1], #4 +.entry: + cmp r1, r2 + bcc.n .loop + bx lr + + .size gc_helper_get_regs_and_clean_stack, .-gc_helper_get_regs_and_clean_stack diff --git a/teensy/led.c b/teensy/led.c new file mode 100644 index 0000000000..1aad2a365e --- /dev/null +++ b/teensy/led.c @@ -0,0 +1,86 @@ +#include + +#include "misc.h" +#include "mpconfig.h" +#include "obj.h" +#include "led.h" + +#include "Arduino.h" + +void led_init(void) { +} + +void led_state(pyb_led_t led, int state) { + uint8_t pin; + + if (led == 0) { + pin = LED_BUILTIN; + } else { + return; + } + digitalWrite(pin, state); +} + +void led_toggle(pyb_led_t led) { + uint8_t pin; + + if (led == 0) { + pin = LED_BUILTIN; + } else { + return; + } + + digitalWrite(pin, !digitalRead(pin)); +} + +/******************************************************************************/ +/* Micro Python bindings */ + +typedef struct _pyb_led_obj_t { + mp_obj_base_t base; + uint led_id; +} pyb_led_obj_t; + +void led_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) { + pyb_led_obj_t *self = self_in; + print(env, "", self->led_id); +} + +mp_obj_t led_obj_on(mp_obj_t self_in) { + pyb_led_obj_t *self = self_in; + led_state(self->led_id, 1); + return mp_const_none; +} + +mp_obj_t led_obj_off(mp_obj_t self_in) { + pyb_led_obj_t *self = self_in; + led_state(self->led_id, 0); + return mp_const_none; +} + +static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on); +static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off); + +static const mp_obj_type_t led_obj_type = { + { &mp_const_type }, + "Led", + led_obj_print, // print + NULL, // make_new + NULL, // call_n + NULL, // unary_op + NULL, // binary_op + NULL, // getiter + NULL, // iternext + { // method list + { "on", &led_obj_on_obj }, + { "off", &led_obj_off_obj }, + { NULL, NULL }, + } +}; + +mp_obj_t pyb_Led(mp_obj_t led_id) { + pyb_led_obj_t *o = m_new_obj(pyb_led_obj_t); + o->base.type = &led_obj_type; + o->led_id = mp_obj_get_int(led_id); + return o; +} diff --git a/teensy/led.h b/teensy/led.h new file mode 100644 index 0000000000..c5a4812549 --- /dev/null +++ b/teensy/led.h @@ -0,0 +1,9 @@ +typedef enum { + PYB_LED_BUILTIN = 0, +} pyb_led_t; + +void led_init(void); +void led_state(pyb_led_t led, int state); +void led_toggle(pyb_led_t led); + +mp_obj_t pyb_Led(mp_obj_t led_id); diff --git a/teensy/lexerteensy.c b/teensy/lexerteensy.c new file mode 100644 index 0000000000..eefaf66657 --- /dev/null +++ b/teensy/lexerteensy.c @@ -0,0 +1,33 @@ +#include +#include + +#include "misc.h" +#include "lexer.h" +#include "lexerteensy.h" + +unichar str_buf_next_char(mp_lexer_str_buf_t *sb) { + if (sb->src_cur < sb->src_end) { + return *sb->src_cur++; + } else { + return MP_LEXER_CHAR_EOF; + } +} + +void str_buf_free(mp_lexer_str_buf_t *sb) { + if (sb->free) { + m_del(char, (char*)sb->src_beg, 0 /* don't know allocated size of src */); + } +} + +mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str, mp_lexer_str_buf_t *sb) { + sb->free = free_str; + sb->src_beg = str; + sb->src_cur = str; + sb->src_end = str + len; + return mp_lexer_new(src_name, sb, (mp_lexer_stream_next_char_t)str_buf_next_char, (mp_lexer_stream_close_t)str_buf_free); +} + +mp_lexer_t *mp_import_open_file(qstr mod_name) { + printf("import not implemented\n"); + return NULL; +} diff --git a/teensy/lexerteensy.h b/teensy/lexerteensy.h new file mode 100644 index 0000000000..961a70ada4 --- /dev/null +++ b/teensy/lexerteensy.h @@ -0,0 +1,8 @@ +typedef struct _py_lexer_str_buf_t { + bool free; // free src_beg when done + const char *src_beg; // beginning of source + const char *src_cur; // current location in source + const char *src_end; // end (exclusive) of source +} mp_lexer_str_buf_t; + +mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str, mp_lexer_str_buf_t *sb); diff --git a/teensy/main.c b/teensy/main.c new file mode 100644 index 0000000000..3711cd60d6 --- /dev/null +++ b/teensy/main.c @@ -0,0 +1,474 @@ +#include +#include +#include +#include + +#include "nlr.h" +#include "misc.h" +#include "mpconfig.h" +#include "mpqstr.h" +#include "lexer.h" +#include "lexerteensy.h" +#include "parse.h" +#include "obj.h" +#include "compile.h" +#include "runtime0.h" +#include "runtime.h" +#include "repl.h" +#include "usb.h" +#include "gc.h" +#include "led.h" + +#include "Arduino.h" + +extern uint32_t _heap_start; + +#ifdef USE_READLINE +#include +#include +#endif + +#if 0 +static char *str_join(const char *s1, int sep_char, const char *s2) { + int l1 = strlen(s1); + int l2 = strlen(s2); + char *s = m_new(char, l1 + l2 + 2); + memcpy(s, s1, l1); + if (sep_char != 0) { + s[l1] = sep_char; + l1 += 1; + } + memcpy(s + l1, s2, l2); + s[l1 + l2] = 0; + return s; +} + +static char *prompt(char *p) { +#ifdef USE_READLINE + char *line = readline(p); + if (line) { + add_history(line); + } +#else + static char buf[256]; + fputs(p, stdout); + char *s = fgets(buf, sizeof(buf), stdin); + if (!s) { + return NULL; + } + int l = strlen(buf); + if (buf[l - 1] == '\n') { + buf[l - 1] = 0; + } else { + l++; + } + char *line = m_new(char, l); + memcpy(line, buf, l); +#endif + return line; +} +#endif + +static const char *help_text = +"Welcome to Micro Python!\n\n" +"This is a *very* early version of Micro Python and has minimal functionality.\n\n" +"Specific commands for the board:\n" +" pyb.info() -- print some general information\n" +" pyb.gc() -- run the garbage collector\n" +" pyb.delay() -- wait for n milliseconds\n" +" pyb.Led() -- create Led object for LED n (n=0)\n" +" Led methods: on(), off()\n" +" pyb.gpio() -- read gpio pin\n" +" pyb.gpio(, ) -- set gpio pin\n" +#if 0 +" pyb.Servo() -- create Servo object for servo n (n=1,2,3,4)\n" +" Servo methods: angle()\n" +" pyb.switch() -- return True/False if switch pressed or not\n" +" pyb.accel() -- get accelerometer values\n" +" pyb.rand() -- get a 16-bit random number\n" +#endif +; + +// get some help about available functions +static mp_obj_t pyb_help(void) { + printf("%s", help_text); + return mp_const_none; +} + +// get lots of info about the board +static mp_obj_t pyb_info(void) { + // get and print unique id; 96 bits + { + byte *id = (byte*)0x40048058; + printf("ID=%02x%02x%02x%02x:%02x%02x%02x%02x:%02x%02x%02x%02x\n", id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7], id[8], id[9], id[10], id[11]); + } + + // get and print clock speeds + printf("CPU=%u\nBUS=%u\nMEM=%u\n", F_CPU, F_BUS, F_MEM); + + // to print info about memory + { + extern void *_sdata; + extern void *_edata; + extern void *_sbss; + extern void *_ebss; + extern void *_estack; + extern void *_etext; + printf("_sdata=%p\n", &_sdata); + printf("_edata=%p\n", &_edata); + printf("_sbss=%p\n", &_sbss); + printf("_ebss=%p\n", &_ebss); + printf("_estack=%p\n", &_estack); + printf("_etext=%p\n", &_etext); + printf("_heap_start=%p\n", &_heap_start); + } + + // GC info + { + gc_info_t info; + gc_info(&info); + printf("GC:\n"); + printf(" %lu total\n", info.total); + printf(" %lu used %lu free\n", info.used, info.free); + printf(" 1=%lu 2=%lu m=%lu\n", info.num_1block, info.num_2block, info.max_block); + } + +#if 0 + // free space on flash + { + DWORD nclst; + FATFS *fatfs; + f_getfree("0:", &nclst, &fatfs); + printf("LFS free: %u bytes\n", (uint)(nclst * fatfs->csize * 512)); + } +#endif + + return mp_const_none; +} + +#define RAM_START (0x1FFF8000) // fixed for chip +#define HEAP_END (0x20006000) // tunable +#define RAM_END (0x20008000) // fixed for chip + +void gc_helper_get_regs_and_clean_stack(machine_uint_t *regs, machine_uint_t heap_end); + +void gc_collect(void) { + uint32_t start = micros(); + gc_collect_start(); + gc_collect_root((void**)RAM_START, (((uint32_t)&_heap_start) - RAM_START) / 4); + machine_uint_t regs[10]; + gc_helper_get_regs_and_clean_stack(regs, HEAP_END); + gc_collect_root((void**)HEAP_END, (RAM_END - HEAP_END) / 4); // will trace regs since they now live in this function on the stack + gc_collect_end(); + uint32_t ticks = micros() - start; // TODO implement a function that does this properly + + if (0) { + // print GC info + gc_info_t info; + gc_info(&info); + printf("GC@%lu %luus\n", start, ticks); + printf(" %lu total\n", info.total); + printf(" %lu used %lu free\n", info.used, info.free); + printf(" 1=%lu 2=%lu m=%lu\n", info.num_1block, info.num_2block, info.max_block); + } +} + +mp_obj_t pyb_gc(void) { + gc_collect(); + return mp_const_none; +} + +mp_obj_t pyb_gpio(int n_args, mp_obj_t *args) { + //assert(1 <= n_args && n_args <= 2); + + uint pin = mp_obj_get_int(args[0]); + if (pin > CORE_NUM_DIGITAL) { + goto pin_error; + } + + if (n_args == 1) { + // get pin + pinMode(pin, INPUT); + return MP_OBJ_NEW_SMALL_INT(digitalRead(pin)); + } + + // set pin + pinMode(pin, OUTPUT); + digitalWrite(pin, rt_is_true(args[1])); + return mp_const_none; + +pin_error: + nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_ValueError, "pin %d does not exist", (void *)(machine_uint_t)pin)); +} + +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_gpio_obj, 1, 2, pyb_gpio); + +#if 0 +mp_obj_t pyb_hid_send_report(mp_obj_t arg) { + mp_obj_t *items = mp_obj_get_array_fixed_n(arg, 4); + uint8_t data[4]; + data[0] = mp_obj_get_int(items[0]); + data[1] = mp_obj_get_int(items[1]); + data[2] = mp_obj_get_int(items[2]); + data[3] = mp_obj_get_int(items[3]); + usb_hid_send_report(data); + return mp_const_none; +} +#endif + +mp_obj_t pyb_delay(mp_obj_t count) { + delay(mp_obj_get_int(count)); + return mp_const_none; +} + +mp_obj_t pyb_led(mp_obj_t state) { + led_state(PYB_LED_BUILTIN, rt_is_true(state)); + return state; +} + +char *strdup(const char *str) { + uint32_t len = strlen(str); + char *s2 = m_new(char, len + 1); + memcpy(s2, str, len); + s2[len] = 0; + return s2; +} + +#define READLINE_HIST_SIZE (8) + +static const char *readline_hist[READLINE_HIST_SIZE] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + +void stdout_tx_str(const char *str) { +// usart_tx_str(str); + usb_vcp_send_str(str); +} + +int readline(vstr_t *line, const char *prompt) { + stdout_tx_str(prompt); + int len = vstr_len(line); + int escape = 0; + int hist_num = 0; + for (;;) { + char c; + for (;;) { + if (usb_vcp_rx_any() != 0) { + c = usb_vcp_rx_get(); + break; +#if 0 + } else if (usart_rx_any()) { + c = usart_rx_char(); + break; +#endif + } + //delay(1); + //if (storage_needs_flush()) { + // storage_flush(); + //} + } + if (escape == 0) { + if (c == 4 && vstr_len(line) == len) { + return 0; + } else if (c == '\r') { + stdout_tx_str("\r\n"); + for (int i = READLINE_HIST_SIZE - 1; i > 0; i--) { + readline_hist[i] = readline_hist[i - 1]; + } + readline_hist[0] = strdup(vstr_str(line)); + return 1; + } else if (c == 27) { + escape = true; + } else if (c == 127) { + if (vstr_len(line) > len) { + vstr_cut_tail(line, 1); + stdout_tx_str("\b \b"); + } + } else if (32 <= c && c <= 126) { + vstr_add_char(line, c); + stdout_tx_str(line->buf + line->len - 1); + } + } else if (escape == 1) { + if (c == '[') { + escape = 2; + } else { + escape = 0; + } + } else if (escape == 2) { + escape = 0; + if (c == 'A') { + // up arrow + if (hist_num < READLINE_HIST_SIZE && readline_hist[hist_num] != NULL) { + // erase line + for (int i = line->len - len; i > 0; i--) { + stdout_tx_str("\b \b"); + } + // set line to history + line->len = len; + vstr_add_str(line, readline_hist[hist_num]); + // draw line + stdout_tx_str(readline_hist[hist_num]); + // increase hist num + hist_num += 1; + } + } + } else { + escape = 0; + } + delay(10); + } +} + +void do_repl(void) { + stdout_tx_str("Micro Python for Teensy 3.1\r\n"); + stdout_tx_str("Type \"help()\" for more information.\r\n"); + + vstr_t line; + vstr_init(&line); + + for (;;) { + vstr_reset(&line); + int ret = readline(&line, ">>> "); + if (ret == 0) { + // EOF + break; + } + + if (vstr_len(&line) == 0) { + continue; + } + + if (mp_repl_is_compound_stmt(vstr_str(&line))) { + for (;;) { + vstr_add_char(&line, '\n'); + int len = vstr_len(&line); + int ret = readline(&line, "... "); + if (ret == 0 || vstr_len(&line) == len) { + // done entering compound statement + break; + } + } + } + + mp_lexer_str_buf_t sb; + mp_lexer_t *lex = mp_lexer_new_from_str_len("", vstr_str(&line), vstr_len(&line), false, &sb); + mp_parse_node_t pn = mp_parse(lex, MP_PARSE_SINGLE_INPUT); + mp_lexer_free(lex); + + if (pn != MP_PARSE_NODE_NULL) { + mp_obj_t module_fun = mp_compile(pn, true); + if (module_fun != mp_const_none) { + nlr_buf_t nlr; + uint32_t start = micros(); + if (nlr_push(&nlr) == 0) { + rt_call_function_0(module_fun); + nlr_pop(); + // optional timing + if (0) { + uint32_t ticks = micros() - start; // TODO implement a function that does this properly + printf("(took %lu us)\n", ticks); + } + } else { + // uncaught exception + mp_obj_print((mp_obj_t)nlr.ret_val); + printf("\n"); + } + } + } + } + + stdout_tx_str("\r\n"); +} + +void main(void) { + pinMode(LED_BUILTIN, OUTPUT); + // Wait for host side to get connected + while (!usb_vcp_is_connected()) { + ; + } + + led_init(); + led_state(PYB_LED_BUILTIN, 1); + +// int first_soft_reset = true; + +soft_reset: + + // GC init + gc_init(&_heap_start, (void*)HEAP_END); + + qstr_init(); + rt_init(); + +#if 1 + printf("About to add functions()\n"); + // add some functions to the python namespace + { + rt_store_name(qstr_from_str_static("help"), rt_make_function_0(pyb_help)); + mp_obj_t m = mp_obj_new_module(qstr_from_str_static("pyb")); + rt_store_attr(m, qstr_from_str_static("info"), rt_make_function_0(pyb_info)); + rt_store_attr(m, qstr_from_str_static("gc"), rt_make_function_0(pyb_gc)); + rt_store_attr(m, qstr_from_str_static("delay"), rt_make_function_1(pyb_delay)); + rt_store_attr(m, qstr_from_str_static("led"), rt_make_function_1(pyb_led)); + rt_store_attr(m, qstr_from_str_static("Led"), rt_make_function_1(pyb_Led)); + rt_store_attr(m, qstr_from_str_static("gpio"), (mp_obj_t)&pyb_gpio_obj); + rt_store_name(qstr_from_str_static("pyb"), m); + } +#endif + + // Turn bootup LED off + led_state(PYB_LED_BUILTIN, 0); + + do_repl(); + + printf("PYB: soft reboot\n"); + +// first_soft_reset = false; + goto soft_reset; +} + +double __aeabi_f2d(float x) { + // TODO + return 0.0; +} + +float __aeabi_d2f(double x) { + // TODO + return 0.0; +} + +double sqrt(double x) { + // TODO + return 0.0; +} + +machine_float_t machine_sqrt(machine_float_t x) { + // TODO + return x; +} + +// stub out __libc_init_array. It's called by mk20dx128.c and is used to call +// global C++ constructors. Since this is a C-only projects, we don't need to +// call constructors. +void __libc_init_array(void) { +} + +char * ultoa(unsigned long val, char *buf, int radix) +{ + unsigned digit; + int i=0, j; + char t; + + while (1) { + digit = val % radix; + buf[i] = ((digit < 10) ? '0' + digit : 'A' + digit - 10); + val /= radix; + if (val == 0) break; + i++; + } + buf[i + 1] = 0; + for (j=0; j < i; j++, i--) { + t = buf[j]; + buf[j] = buf[i]; + buf[i] = t; + } + return buf; +} diff --git a/teensy/main.cpp b/teensy/main.cpp new file mode 100644 index 0000000000..52ce51cda2 --- /dev/null +++ b/teensy/main.cpp @@ -0,0 +1,245 @@ +#include +#include +#include +#include + +#include "Arduino.h" + +extern "C" +{ +#include "nlr.h" +#include "misc.h" +#include "mpconfig.h" +#include "lexer.h" +#include "lexerteensy.h" +#include "parse.h" +#include "obj.h" +#include "compile.h" +#include "runtime0.h" +#include "runtime.h" +#include "repl.h" +#include "usb.h" +} + +#ifdef USE_READLINE +#include +#include +#endif + +#if 0 +static char *str_join(const char *s1, int sep_char, const char *s2) { + int l1 = strlen(s1); + int l2 = strlen(s2); + char *s = m_new(char, l1 + l2 + 2); + memcpy(s, s1, l1); + if (sep_char != 0) { + s[l1] = sep_char; + l1 += 1; + } + memcpy(s + l1, s2, l2); + s[l1 + l2] = 0; + return s; +} + +static char *prompt(char *p) { +#ifdef USE_READLINE + char *line = readline(p); + if (line) { + add_history(line); + } +#else + static char buf[256]; + fputs(p, stdout); + char *s = fgets(buf, sizeof(buf), stdin); + if (!s) { + return NULL; + } + int l = strlen(buf); + if (buf[l - 1] == '\n') { + buf[l - 1] = 0; + } else { + l++; + } + char *line = m_new(char, l); + memcpy(line, buf, l); +#endif + return line; +} +#endif + +#define READLINE_HIST_SIZE (8) + +static const char *readline_hist[READLINE_HIST_SIZE] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + +void stdout_tx_str(const char *str) { +// usart_tx_str(str); + usb_vcp_send_str(str); +} + +static elapsedMillis ledTime; +static uint8_t ledState; + +int readline(vstr_t *line, const char *prompt) { + stdout_tx_str(prompt); + int len = vstr_len(line); + int escape = 0; + int hist_num = 0; + for (;;) { + char c; + ledState = 1; + ledTime = 0; + digitalWrite(LED_BUILTIN, ledState); + for (;;) { + if (ledTime > 200) { + ledState = !ledState; + digitalWrite(LED_BUILTIN, ledState); + ledTime = 0; + } + if (usb_vcp_rx_any() != 0) { + c = usb_vcp_rx_get(); + break; +#if 0 + } else if (usart_rx_any()) { + c = usart_rx_char(); + break; +#endif + } + //delay(1); + //if (storage_needs_flush()) { + // storage_flush(); + //} + } + if (escape == 0) { + if (c == 4 && vstr_len(line) == len) { + return 0; + } else if (c == '\r') { + stdout_tx_str("\r\n"); + for (int i = READLINE_HIST_SIZE - 1; i > 0; i--) { + readline_hist[i] = readline_hist[i - 1]; + } + readline_hist[0] = strdup(vstr_str(line)); + return 1; + } else if (c == 27) { + escape = true; + } else if (c == 127) { + if (vstr_len(line) > len) { + vstr_cut_tail(line, 1); + stdout_tx_str("\b \b"); + } + } else if (32 <= c && c <= 126) { + vstr_add_char(line, c); + stdout_tx_str(line->buf + line->len - 1); + } + } else if (escape == 1) { + if (c == '[') { + escape = 2; + } else { + escape = 0; + } + } else if (escape == 2) { + escape = 0; + if (c == 'A') { + // up arrow + if (hist_num < READLINE_HIST_SIZE && readline_hist[hist_num] != NULL) { + // erase line + for (int i = line->len - len; i > 0; i--) { + stdout_tx_str("\b \b"); + } + // set line to history + line->len = len; + vstr_add_str(line, readline_hist[hist_num]); + // draw line + stdout_tx_str(readline_hist[hist_num]); + // increase hist num + hist_num += 1; + } + } + } else { + escape = 0; + } + delay(10); + } +} + +void setup(void) { + pinMode(LED_BUILTIN, OUTPUT); + ledState = 1; + digitalWrite(LED_BUILTIN, ledState); + ledTime = 0; + // Wait for host side to get connected + while (!usb_vcp_is_connected()) { + if (ledTime > 100) { + ledState = !ledState; + digitalWrite(LED_BUILTIN, ledState); + ledTime = 0; + } + } + digitalWrite(LED_BUILTIN, 0); + + qstr_init(); + rt_init(); + + stdout_tx_str("Micro Python for Teensy 3.1\r\n"); + stdout_tx_str("Type \"help()\" for more information.\r\n"); +} + +void loop(void) { + vstr_t line; + vstr_init(&line); + + vstr_reset(&line); + int ret = readline(&line, ">>> "); + if (ret == 0) { + // EOF + return; + } + + if (vstr_len(&line) == 0) { + return; + } + + if (mp_repl_is_compound_stmt(vstr_str(&line))) { + for (;;) { + vstr_add_char(&line, '\n'); + int len = vstr_len(&line); + int ret = readline(&line, "... "); + if (ret == 0 || vstr_len(&line) == len) { + // done entering compound statement + break; + } + } + } + + mp_lexer_str_buf_t sb; + mp_lexer_t *lex = mp_lexer_new_from_str_len("", vstr_str(&line), vstr_len(&line), false, &sb); + mp_parse_node_t pn = mp_parse(lex, MP_PARSE_SINGLE_INPUT); + mp_lexer_free(lex); + + if (pn != MP_PARSE_NODE_NULL) { + mp_obj_t module_fun = mp_compile(pn, true); + if (module_fun != mp_const_none) { + nlr_buf_t nlr; + uint32_t start = micros(); + if (nlr_push(&nlr) == 0) { + rt_call_function_0(module_fun); + nlr_pop(); + // optional timing + if (0) { + uint32_t ticks = micros() - start; // TODO implement a function that does this properly + printf("(took %lu us)\n", ticks); + } + } else { + // uncaught exception + mp_obj_print((mp_obj_t)nlr.ret_val); + printf("\r\n"); + } + } + } +} + +// for sqrt +#include +machine_float_t machine_sqrt(machine_float_t x) { + return sqrt(x); +} + diff --git a/teensy/malloc0.c b/teensy/malloc0.c new file mode 100644 index 0000000000..1a6cb708e8 --- /dev/null +++ b/teensy/malloc0.c @@ -0,0 +1,57 @@ +#include +#include "std.h" +#include "mpconfig.h" +#include "gc.h" + +#if 0 +static uint32_t mem = 0; + +void *malloc(size_t n) { + if (mem == 0) { + extern uint32_t _heap_start; + mem = (uint32_t)&_heap_start; // need to use big ram block so we can execute code from it (is it true that we can't execute from CCM?) + } + void *ptr = (void*)mem; + mem = (mem + n + 3) & (~3); + if (mem > 0x20000000 + 0x18000) { + void __fatal_error(const char*); + __fatal_error("out of memory"); + } + return ptr; +} + +void free(void *ptr) { +} + +void *realloc(void *ptr, size_t n) { + return malloc(n); +} + +#endif + +void *calloc(size_t sz, size_t n) { + char *ptr = malloc(sz * n); + for (int i = 0; i < sz * n; i++) { + ptr[i] = 0; + } + return ptr; +} + +void *malloc(size_t n) { + void *m = gc_alloc(n); + return m; +} + +void free(void *ptr) { + gc_free(ptr); +} + +void *realloc(void *ptr, size_t n) { + return gc_realloc(ptr, n); +} + +void __assert_func(void) { + printf("\nASSERT FAIL!"); + for (;;) { + } +} diff --git a/teensy/mk20dx256.ld b/teensy/mk20dx256.ld new file mode 100644 index 0000000000..da57cbe5cb --- /dev/null +++ b/teensy/mk20dx256.ld @@ -0,0 +1,164 @@ +/* Teensyduino Core Library + * http://www.pjrc.com/teensy/ + * Copyright (c) 2013 PJRC.COM, LLC. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * 1. The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * 2. If the Software is incorporated into a build system that allows + * selection among a list of target devices, then similar target + * devices manufactured by PJRC.COM must be included in the list of + * target devices and selectable in the same manner. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +MEMORY +{ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K + RAM (rwx) : ORIGIN = 0x1FFF8000, LENGTH = 64K +} + +/* produce a link error if there is not this amount of RAM for these sections */ +_minimum_stack_size = 2K; +_minimum_heap_size = 16K; + +/* INCLUDE common.ld */ + +/* Teensyduino Core Library + * http://www.pjrc.com/teensy/ + * Copyright (c) 2013 PJRC.COM, LLC. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * 1. The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * 2. If the Software is incorporated into a build system that allows + * selection among a list of target devices, then similar target + * devices manufactured by PJRC.COM must be included in the list of + * target devices and selectable in the same manner. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + + +SECTIONS +{ + .text : { + . = 0; + KEEP(*(.vectors)) + *(.startup*) + /* TODO: does linker detect startup overflow onto flashconfig? */ + . = 0x400; + KEEP(*(.flashconfig*)) + *(.text*) + *(.rodata*) + . = ALIGN(4); + KEEP(*(.init)) + . = ALIGN(4); + __preinit_array_start = .; + KEEP (*(.preinit_array)) + __preinit_array_end = .; + __init_array_start = .; + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + __init_array_end = .; + } > FLASH = 0xFF + + .ARM.exidx : { + __exidx_start = .; + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __exidx_end = .; + } > FLASH + _etext = .; + + .usbdescriptortable (NOLOAD) : { + /* . = ORIGIN(RAM); */ + . = ALIGN(512); + *(.usbdescriptortable*) + } > RAM + + .dmabuffers (NOLOAD) : { + . = ALIGN(4); + *(.dmabuffers*) + } > RAM + + .usbbuffers (NOLOAD) : { + . = ALIGN(4); + *(.usbbuffers*) + } > RAM + + .data : AT (_etext) { + . = ALIGN(4); + _sdata = .; + *(.data*) + . = ALIGN(4); + _edata = .; + } > RAM + + .noinit (NOLOAD) : { + *(.noinit*) + } > RAM + + .bss : { + . = ALIGN(4); + _sbss = .; + *(.bss*) + *(COMMON) + . = ALIGN(4); + _ebss = .; + __bss_end = .; + } > RAM + + /* this is to define the start of the heap, and make sure we have a minimum size */ + .heap : + { + . = ALIGN(4); + _heap_start = .; /* define a global symbol at heap start */ + . = . + _minimum_heap_size; + } >RAM + + /* this just checks there is enough RAM for the stack */ + .stack : + { + . = ALIGN(4); + . = . + _minimum_stack_size; + . = ALIGN(4); + } >RAM + + _estack = ORIGIN(RAM) + LENGTH(RAM); +} + + + + diff --git a/teensy/mpconfigport.h b/teensy/mpconfigport.h new file mode 100644 index 0000000000..4cea332f39 --- /dev/null +++ b/teensy/mpconfigport.h @@ -0,0 +1,21 @@ +#include + +// options to control how Micro Python is built + +#define MICROPY_ENABLE_FLOAT (1) +#define MICROPY_EMIT_CPYTHON (0) +#define MICROPY_EMIT_X64 (0) +#define MICROPY_EMIT_THUMB (1) +#define MICROPY_EMIT_INLINE_THUMB (1) + +// type definitions for the specific machine + +#define BYTES_PER_WORD (4) + +typedef int32_t machine_int_t; // must be pointer size +typedef uint32_t machine_uint_t; // must be pointer size +typedef void *machine_ptr_t; // must be of pointer size +typedef const void *machine_const_ptr_t; // must be of pointer size +typedef float machine_float_t; + +machine_float_t machine_sqrt(machine_float_t x); diff --git a/teensy/printf.c b/teensy/printf.c new file mode 100644 index 0000000000..71b27b8214 --- /dev/null +++ b/teensy/printf.c @@ -0,0 +1,305 @@ +#include +#include +#include "std.h" +#include "misc.h" +//#include "lcd.h" +//#include "usart.h" +#include "usb.h" + +#define PF_FLAG_LEFT_ADJUST (0x01) +#define PF_FLAG_SHOW_SIGN (0x02) +#define PF_FLAG_SPACE_SIGN (0x04) +#define PF_FLAG_NO_TRAILZ (0x08) +#define PF_FLAG_ZERO_PAD (0x10) + +// tricky; we compute pad string by: pad_chars + (flags & PF_FLAG_ZERO_PAD) +#define PF_PAD_SIZE PF_FLAG_ZERO_PAD +static const char *pad_chars = " 0000000000000000"; + +typedef struct _pfenv_t { + void *data; + void (*print_strn)(void *, const char *str, unsigned int len); +} pfenv_t; + +static void print_str_dummy(void *data, const char *str, unsigned int len) { +} + +const pfenv_t pfenv_dummy = {0, print_str_dummy}; + +static int pfenv_print_strn(const pfenv_t *pfenv, const char *str, unsigned int len, int flags, int width) { + int pad = width - len; + if (pad > 0 && (flags & PF_FLAG_LEFT_ADJUST) == 0) { + while (pad > 0) { + int p = pad; + if (p > PF_PAD_SIZE) + p = PF_PAD_SIZE; + pfenv->print_strn(pfenv->data, pad_chars + (flags & PF_FLAG_ZERO_PAD), p); + pad -= p; + } + } + pfenv->print_strn(pfenv->data, str, len); + while (pad > 0) { + int p = pad; + if (p > PF_PAD_SIZE) + p = PF_PAD_SIZE; + pfenv->print_strn(pfenv->data, pad_chars, p); + pad -= p; + } + return len; +} + +// enough room for 32 signed number +#define INT_BUF_SIZE (12) + +static int pfenv_print_int(const pfenv_t *pfenv, unsigned int x, int sgn, int base, int base_char, int flags, int width) { + char sign = 0; + if (sgn) { + if ((int)x < 0) { + sign = '-'; + x = -x; + } else if (flags & PF_FLAG_SHOW_SIGN) { + sign = '+'; + } else if (flags & PF_FLAG_SPACE_SIGN) { + sign = ' '; + } + } + + char buf[INT_BUF_SIZE]; + char *b = buf + INT_BUF_SIZE; + + if (x == 0) { + *(--b) = '0'; + } else { + do { + int c = x % base; + x /= base; + if (c >= 10) { + c += base_char - 10; + } else { + c += '0'; + } + *(--b) = c; + } while (b > buf && x != 0); + } + + if (b > buf && sign != 0) { + *(--b) = sign; + } + + return pfenv_print_strn(pfenv, b, buf + INT_BUF_SIZE - b, flags, width); +} + +void pfenv_prints(const pfenv_t *pfenv, const char *str) { + pfenv->print_strn(pfenv->data, str, strlen(str)); +} + +int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) { + int chrs = 0; + for (;;) { + { + const char *f = fmt; + while (*f != '\0' && *f != '%') { + ++f; // XXX UTF8 advance char + } + if (f > fmt) { + pfenv->print_strn(pfenv->data, fmt, f - fmt); + chrs += f - fmt; + fmt = f; + } + } + + if (*fmt == '\0') { + break; + } + + // move past % character + ++fmt; + + // parse flags, if they exist + int flags = 0; + while (*fmt != '\0') { + if (*fmt == '-') flags |= PF_FLAG_LEFT_ADJUST; + else if (*fmt == '+') flags |= PF_FLAG_SHOW_SIGN; + else if (*fmt == ' ') flags |= PF_FLAG_SPACE_SIGN; + else if (*fmt == '!') flags |= PF_FLAG_NO_TRAILZ; + else if (*fmt == '0') flags |= PF_FLAG_ZERO_PAD; + else break; + ++fmt; + } + + // parse width, if it exists + int width = 0; + for (; '0' <= *fmt && *fmt <= '9'; ++fmt) { + width = width * 10 + *fmt - '0'; + } + + // parse precision, if it exists + int prec = -1; + if (*fmt == '.') { + ++fmt; + if (*fmt == '*') { + ++fmt; + prec = va_arg(args, int); + } else { + prec = 0; + for (; '0' <= *fmt && *fmt <= '9'; ++fmt) { + prec = prec * 10 + *fmt - '0'; + } + } + if (prec < 0) { + prec = 0; + } + } + + // parse long specifiers (current not used) + //bool long_arg = false; + if (*fmt == 'l') { + ++fmt; + //long_arg = true; + } + + if (*fmt == '\0') { + break; + } + + switch (*fmt) { + case 'b': + if (va_arg(args, int)) { + chrs += pfenv_print_strn(pfenv, "true", 4, flags, width); + } else { + chrs += pfenv_print_strn(pfenv, "false", 5, flags, width); + } + break; + case 'c': + { + char str = va_arg(args, int); + chrs += pfenv_print_strn(pfenv, &str, 1, flags, width); + break; + } + case 's': + { + const char *str = va_arg(args, const char*); + if (str) { + if (prec < 0) { + prec = strlen(str); + } + chrs += pfenv_print_strn(pfenv, str, prec, flags, width); + } else { + chrs += pfenv_print_strn(pfenv, "(null)", 6, flags, width); + } + break; + } + case 'u': + chrs += pfenv_print_int(pfenv, va_arg(args, int), 0, 10, 'a', flags, width); + break; + case 'd': + chrs += pfenv_print_int(pfenv, va_arg(args, int), 1, 10, 'a', flags, width); + break; + case 'x': + case 'p': // ? + chrs += pfenv_print_int(pfenv, va_arg(args, int), 0, 16, 'a', flags, width); + break; + case 'X': + case 'P': // ? + chrs += pfenv_print_int(pfenv, va_arg(args, int), 0, 16, 'A', flags, width); + break; + default: + pfenv->print_strn(pfenv->data, fmt, 1); + chrs += 1; + break; + } + ++fmt; + } + return chrs; +} + +void stdout_print_strn(void *data, const char *str, unsigned int len) { + // send stdout to USART, USB CDC VCP, and LCD if nothing else +#if 0 + int any = 0; + if (usart_is_enabled()) { + usart_tx_strn_cooked(str, len); + any = true; + } +#endif + if (usb_vcp_is_enabled()) { + usb_vcp_send_strn_cooked(str, len); +// any = true; + } +#if 0 + if (!any) { + lcd_print_strn(str, len); + } +#endif +} + +static const pfenv_t pfenv_stdout = {0, stdout_print_strn}; + +int printf(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + int ret = pfenv_printf(&pfenv_stdout, fmt, ap); + va_end(ap); + return ret; +} + +int vprintf(const char *fmt, va_list ap) { + return pfenv_printf(&pfenv_stdout, fmt, ap); +} + +// need this because gcc optimises printf("%c", c) -> putchar(c), and printf("a") -> putchar('a') +int putchar(int c) { + char chr = c; + stdout_print_strn(0, &chr, 1); + return chr; +} + +// need this because gcc optimises printf("string\n") -> puts("string") +int puts(const char *s) { + stdout_print_strn(0, s, strlen(s)); + char chr = '\n'; + stdout_print_strn(0, &chr, 1); + return 1; +} + +typedef struct _strn_pfenv_t { + char *cur; + size_t remain; +} strn_pfenv_t; + +void strn_print_strn(void *data, const char *str, unsigned int len) { + strn_pfenv_t *strn_pfenv = data; + if (len > strn_pfenv->remain) { + len = strn_pfenv->remain; + } + memcpy(strn_pfenv->cur, str, len); + strn_pfenv->cur += len; + strn_pfenv->remain -= len; +} + +int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) { + strn_pfenv_t strn_pfenv; + strn_pfenv.cur = str; + strn_pfenv.remain = size; + pfenv_t pfenv; + pfenv.data = &strn_pfenv; + pfenv.print_strn = strn_print_strn; + int len = pfenv_printf(&pfenv, fmt, ap); + // add terminating null byte + if (size > 0) { + if (strn_pfenv.remain == 0) { + strn_pfenv.cur[-1] = 0; + } else { + strn_pfenv.cur[0] = 0; + } + } + return len; +} + +int snprintf(char *str, size_t size, const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + int ret = vsnprintf(str, size, fmt, ap); + va_end(ap); + return ret; +} diff --git a/teensy/std.h b/teensy/std.h new file mode 100644 index 0000000000..587b9f8880 --- /dev/null +++ b/teensy/std.h @@ -0,0 +1,22 @@ +typedef unsigned int size_t; + +void __assert_func(void); + +void *malloc(size_t n); +void free(void *ptr); +void *calloc(size_t sz, size_t n); +void *realloc(void *ptr, size_t n); + +void *memcpy(void *dest, const void *src, size_t n); +void *memmove(void *dest, const void *src, size_t n); +void *memset(void *s, int c, size_t n); + +int strlen(const char *str); +int strcmp(const char *s1, const char *s2); +int strncmp(const char *s1, const char *s2, size_t n); +char *strndup(const char *s, size_t n); +char *strcpy(char *dest, const char *src); +char *strcat(char *dest, const char *src); + +int printf(const char *fmt, ...); +int snprintf(char *str, size_t size, const char *fmt, ...); diff --git a/teensy/string0.c b/teensy/string0.c new file mode 100644 index 0000000000..2a5f255971 --- /dev/null +++ b/teensy/string0.c @@ -0,0 +1,110 @@ +#include +#include "std.h" + +void *memcpy(void *dest, const void *src, size_t n) { + // TODO align and copy 32 bits at a time + uint8_t *d = dest; + const uint8_t *s = src; + for (; n > 0; n--) { + *d++ = *s++; + } + return dest; +} + +void *memmove(void *dest, const void *src, size_t n) { + if (src < dest && dest < src + n) { + // need to copy backwards + uint8_t *d = dest + n - 1; + const uint8_t *s = src + n - 1; + for (; n > 0; n--) { + *d-- = *s--; + } + return dest; + } else { + // can use normal memcpy + return memcpy(dest, src, n); + } +} + +void *memset(void *s, int c, size_t n) { + uint8_t *s2 = s; + for (; n > 0; n--) { + *s2++ = c; + } + return s; +} + +int strlen(const char *str) { + int len = 0; + for (const char *s = str; *s; s++) { + len += 1; + } + return len; +} + +int strcmp(const char *s1, const char *s2) { + while (*s1 && *s2) { + char c1 = *s1++; // XXX UTF8 get char, next char + char c2 = *s2++; // XXX UTF8 get char, next char + if (c1 < c2) return -1; + else if (c1 > c2) return 1; + } + if (*s2) return -1; + else if (*s1) return 1; + else return 0; +} + +int strncmp(const char *s1, const char *s2, size_t n) { + while (*s1 && *s2 && n > 0) { + char c1 = *s1++; // XXX UTF8 get char, next char + char c2 = *s2++; // XXX UTF8 get char, next char + n--; + if (c1 < c2) return -1; + else if (c1 > c2) return 1; + } + if (n == 0) return 0; + else if (*s2) return -1; + else if (*s1) return 1; + else return 0; +} + +char *strndup(const char *s, size_t n) { + size_t len = strlen(s); + if (n > len) { + n = len; + } + char *s2 = malloc(n + 1); + memcpy(s2, s, n); + s2[n] = '\0'; + return s2; +} + +char *strcpy(char *dest, const char *src) { + char *d = dest; + while (*src) { + *d++ = *src++; + } + *d = '\0'; + return dest; +} + +// needed because gcc optimises strcpy + strcat to this +char *stpcpy(char *dest, const char *src) { + while (*src) { + *dest++ = *src++; + } + *dest = '\0'; + return dest; +} + +char *strcat(char *dest, const char *src) { + char *d = dest; + while (*d) { + d++; + } + while (*src) { + *d++ = *src++; + } + *d = '\0'; + return dest; +} diff --git a/teensy/usb.c b/teensy/usb.c new file mode 100644 index 0000000000..a045a2ed69 --- /dev/null +++ b/teensy/usb.c @@ -0,0 +1,44 @@ +#include "Arduino.h" + +#include "usb.h" +#include "usb_serial.h" + +int usb_vcp_is_connected(void) +{ + return usb_configuration && (usb_cdc_line_rtsdtr & (USB_SERIAL_DTR | USB_SERIAL_RTS)); +} + +int usb_vcp_is_enabled(void) +{ + return 1; +} + +int usb_vcp_rx_any(void) +{ + return usb_serial_available(); +} + +char usb_vcp_rx_get(void) +{ + return usb_serial_getchar(); +} + +void usb_vcp_send_str(const char* str) +{ + usb_vcp_send_strn(str, strlen(str)); +} + +void usb_vcp_send_strn(const char* str, int len) +{ + usb_serial_write(str, len); +} + +void usb_vcp_send_strn_cooked(const char *str, int len) +{ + for (const char *top = str + len; str < top; str++) { + if (*str == '\n') { + usb_serial_putchar('\r'); + } + usb_serial_putchar(*str); + } +} diff --git a/teensy/usb.h b/teensy/usb.h new file mode 100644 index 0000000000..8f32309ecb --- /dev/null +++ b/teensy/usb.h @@ -0,0 +1,9 @@ +void usb_init(void); +int usb_vcp_is_enabled(void); +int usb_vcp_is_connected(void); +int usb_vcp_rx_any(void); +char usb_vcp_rx_get(void); +void usb_vcp_send_str(const char* str); +void usb_vcp_send_strn(const char* str, int len); +void usb_vcp_send_strn_cooked(const char *str, int len); +void usb_hid_send_report(uint8_t *buf); // 4 bytes for mouse: ?, x, y, ? From e5ee1693ad6238846f2ccf495b67a3dc06ffa277 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 6 Jan 2014 17:49:46 +0200 Subject: [PATCH 03/17] Use constructor to create small int (avoid exposing mp_obj_t internals to VM). --- py/vm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/vm.c b/py/vm.c index 8e7ef7485b..5e3ec0baf8 100644 --- a/py/vm.c +++ b/py/vm.c @@ -106,7 +106,7 @@ bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t ** case MP_BC_LOAD_CONST_SMALL_INT: unum = (ip[0] | (ip[1] << 8) | (ip[2] << 16)) - 0x800000; ip += 3; - PUSH((mp_obj_t)(unum << 1 | 1)); + PUSH(MP_OBJ_NEW_SMALL_INT(unum)); break; case MP_BC_LOAD_CONST_DEC: From fe039b4f4fa70ce9193cbc5389203186eea96537 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 6 Jan 2014 17:49:21 +0200 Subject: [PATCH 04/17] Typo fix in comment. --- py/emit.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/emit.h b/py/emit.h index ea65731038..66e87fd4c6 100644 --- a/py/emit.h +++ b/py/emit.h @@ -5,7 +5,7 @@ * is not known until the end of pass 1. * As a consequence, we don't know the maximum stack size until the end of pass 2. * This is problematic for some emitters (x64) since they need to know the maximum - * stack size to compile the entry to the function, and this effects code size. + * stack size to compile the entry to the function, and this affects code size. */ typedef enum { From 7a16fadbf843ca5d49fb20b5f5785ffccfd9019f Mon Sep 17 00:00:00 2001 From: ian-v Date: Mon, 6 Jan 2014 09:52:29 -0800 Subject: [PATCH 05/17] Co-exist with C++ (issue #85) --- py/asmthumb.c | 8 +- py/asmthumb.h | 2 +- py/asmx64.c | 12 +-- py/asmx64.h | 2 +- py/bc.h | 2 +- py/builtinimport.c | 2 +- py/compile.c | 224 +++++++++++++++++++++---------------------- py/compile.h | 2 +- py/emit.h | 10 +- py/emitbc.c | 18 ++-- py/emitcpy.c | 32 +++---- py/emitinlinethumb.c | 6 +- py/emitnative.c | 30 +++--- py/emitpass1.c | 4 +- py/lexer.c | 80 ++++++++-------- py/lexer.h | 14 +-- py/lexerunix.c | 6 +- py/lexerunix.h | 2 +- py/map.c | 12 +-- py/map.h | 6 +- py/misc.h | 18 ++-- py/obj.c | 20 ++-- py/obj.h | 31 +++--- py/objbool.c | 8 +- py/objboundmeth.c | 2 +- py/objcell.c | 2 +- py/objclass.c | 4 +- py/objclosure.c | 2 +- py/objcomplex.c | 2 +- py/objdict.c | 10 +- py/objexcept.c | 2 +- py/objfloat.c | 2 +- py/objfun.c | 12 +-- py/objgenerator.c | 6 +- py/objinstance.c | 16 ++-- py/objint.c | 2 +- py/objlist.c | 28 +++--- py/objmodule.c | 2 +- py/objnone.c | 2 +- py/objrange.c | 4 +- py/objset.c | 10 +- py/objslice.c | 4 +- py/objstr.c | 13 +-- py/objtuple.c | 12 ++- py/objtype.c | 2 +- py/parse.c | 44 ++++----- py/repl.c | 8 +- py/repl.h | 2 +- py/runtime.c | 142 ++++++++++++++------------- py/runtime0.h | 2 +- py/scope.c | 14 +-- py/scope.h | 4 +- py/unicode.c | 14 +-- py/vm.c | 8 +- py/vstr.c | 18 ++-- stm/audio.c | 2 +- stm/cc3k/pybcc3k.c | 6 +- stm/i2c.c | 83 ++++++++-------- stm/led.c | 11 ++- stm/lexerstm.c | 2 +- stm/lexerstm.h | 4 +- stm/main.c | 47 ++++----- stm/printf.c | 10 +- stm/pybwlan.c | 2 +- stm/servo.c | 9 +- stm/storage.c | 30 +++--- stm/storage.h | 6 +- stm/systick.c | 2 +- stm/systick.h | 2 +- stm/usart.c | 8 +- stm/usart.h | 4 +- stm/usb.c | 2 +- stm/usb.h | 2 +- unix-cpy/main.c | 2 +- unix/main.c | 8 +- 75 files changed, 599 insertions(+), 589 deletions(-) diff --git a/py/asmthumb.c b/py/asmthumb.c index ba95d80c68..76a93b9a3f 100644 --- a/py/asmthumb.c +++ b/py/asmthumb.c @@ -45,7 +45,7 @@ asm_thumb_t *asm_thumb_new(uint max_num_labels) { return as; } -void asm_thumb_free(asm_thumb_t *as, bool free_code) { +void asm_thumb_free(asm_thumb_t *as, MP_BOOL free_code) { if (free_code) { m_del(byte, as->code_base, as->code_size); } @@ -56,9 +56,9 @@ void asm_thumb_free(asm_thumb_t *as, bool free_code) { { Label *lab = &g_array_index(as->label, Label, i); if (lab->unresolved != NULL) - g_array_free(lab->unresolved, true); + g_array_free(lab->unresolved, MP_TRUE); } - g_array_free(as->label, true); + g_array_free(as->label, MP_TRUE); } */ m_del_obj(asm_thumb_t, as); @@ -87,7 +87,7 @@ void asm_thumb_end_pass(asm_thumb_t *as) { int i; for (i = 0; i < as->label->len; ++i) if (g_array_index(as->label, Label, i).unresolved != NULL) - return false; + return MP_FALSE; } */ } diff --git a/py/asmthumb.h b/py/asmthumb.h index dcd9c2e3ad..c6ebcb4c46 100644 --- a/py/asmthumb.h +++ b/py/asmthumb.h @@ -44,7 +44,7 @@ typedef struct _asm_thumb_t asm_thumb_t; asm_thumb_t *asm_thumb_new(uint max_num_labels); -void asm_thumb_free(asm_thumb_t *as, bool free_code); +void asm_thumb_free(asm_thumb_t *as, MP_BOOL free_code); void asm_thumb_start_pass(asm_thumb_t *as, int pass); void asm_thumb_end_pass(asm_thumb_t *as); uint asm_thumb_get_code_size(asm_thumb_t *as); diff --git a/py/asmx64.c b/py/asmx64.c index ed9ca80f5c..054f411882 100644 --- a/py/asmx64.c +++ b/py/asmx64.c @@ -94,7 +94,7 @@ struct _asm_x64_t { }; // for allocating memory, see src/v8/src/platform-linux.cc -void *alloc_mem(uint req_size, uint *alloc_size, bool is_exec) { +void *alloc_mem(uint req_size, uint *alloc_size, MP_BOOL is_exec) { req_size = (req_size + 0xfff) & (~0xfff); int prot = PROT_READ | PROT_WRITE | (is_exec ? PROT_EXEC : 0); void *ptr = mmap(NULL, req_size, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); @@ -119,7 +119,7 @@ asm_x64_t* asm_x64_new(uint max_num_labels) { return as; } -void asm_x64_free(asm_x64_t* as, bool free_code) { +void asm_x64_free(asm_x64_t* as, MP_BOOL free_code) { if (free_code) { // need to un-mmap //m_free(as->code_base); @@ -131,9 +131,9 @@ void asm_x64_free(asm_x64_t* as, bool free_code) { { Label* lab = &g_array_index(as->label, Label, i); if (lab->unresolved != NULL) - g_array_free(lab->unresolved, true); + g_array_free(lab->unresolved, MP_TRUE); } - g_array_free(as->label, true); + g_array_free(as->label, MP_TRUE); } */ m_del_obj(asm_x64_t, as); @@ -154,7 +154,7 @@ void asm_x64_end_pass(asm_x64_t *as) { as->code_size = as->code_offset; //as->code_base = m_new(byte, as->code_size); need to allocale executable memory uint actual_alloc; - as->code_base = alloc_mem(as->code_size, &actual_alloc, true); + as->code_base = alloc_mem(as->code_size, &actual_alloc, MP_TRUE); printf("code_size: %u\n", as->code_size); } @@ -165,7 +165,7 @@ void asm_x64_end_pass(asm_x64_t *as) { int i; for (i = 0; i < as->label->len; ++i) if (g_array_index(as->label, Label, i).unresolved != NULL) - return false; + return MP_FALSE; } */ } diff --git a/py/asmx64.h b/py/asmx64.h index 16cc3b2119..1ee39a3b2b 100644 --- a/py/asmx64.h +++ b/py/asmx64.h @@ -27,7 +27,7 @@ typedef struct _asm_x64_t asm_x64_t; asm_x64_t* asm_x64_new(uint max_num_labels); -void asm_x64_free(asm_x64_t* as, bool free_code); +void asm_x64_free(asm_x64_t* as, MP_BOOL free_code); void asm_x64_start_pass(asm_x64_t *as, int pass); void asm_x64_end_pass(asm_x64_t *as); uint asm_x64_get_code_size(asm_x64_t* as); diff --git a/py/bc.h b/py/bc.h index 35847f4589..b1fdb3aa10 100644 --- a/py/bc.h +++ b/py/bc.h @@ -1,2 +1,2 @@ mp_obj_t mp_execute_byte_code(const byte *code, const mp_obj_t *args, uint n_args, uint n_state); -bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **sp_in_out); +MP_BOOL mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **sp_in_out); diff --git a/py/builtinimport.c b/py/builtinimport.c index 90a0fc3394..ba191ddd75 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -58,7 +58,7 @@ mp_obj_t mp_builtin___import__(int n, mp_obj_t *args) { return mp_const_none; } - mp_obj_t module_fun = mp_compile(pn, false); + mp_obj_t module_fun = mp_compile(pn, MP_FALSE); if (module_fun == mp_const_none) { // TODO handle compile error correctly diff --git a/py/compile.c b/py/compile.c index 0e19890315..d388ad8096 100644 --- a/py/compile.c +++ b/py/compile.c @@ -39,9 +39,9 @@ typedef enum { #define EMIT_OPT_ASM_THUMB (4) typedef struct _compiler_t { - bool is_repl; + MP_BOOL is_repl; pass_kind_t pass; - bool had_error; // try to keep compiler clean from nlr + MP_BOOL had_error; // try to keep compiler clean from nlr int next_label; @@ -50,9 +50,9 @@ typedef struct _compiler_t { int except_nest_level; int n_arg_keyword; - bool have_star_arg; - bool have_dbl_star_arg; - bool have_bare_star; + MP_BOOL have_star_arg; + MP_BOOL have_dbl_star_arg; + MP_BOOL have_bare_star; int param_pass; int param_pass_num_dict_params; int param_pass_num_default_params; @@ -261,36 +261,36 @@ void compile_generic_all_nodes(compiler_t *comp, mp_parse_node_struct_t *pns) { } #if MICROPY_EMIT_CPYTHON -static bool cpython_c_tuple_is_const(mp_parse_node_t pn) { +static MP_BOOL cpython_c_tuple_is_const(mp_parse_node_t pn) { if (!MP_PARSE_NODE_IS_LEAF(pn)) { - return false; + return MP_FALSE; } if (MP_PARSE_NODE_IS_ID(pn)) { - return false; + return MP_FALSE; } - return true; + return MP_TRUE; } -static void cpython_c_print_quoted_str(vstr_t *vstr, qstr qstr, bool bytes) { +static void cpython_c_print_quoted_str(vstr_t *vstr, qstr qstr, MP_BOOL bytes) { const char *str = qstr_str(qstr); int len = strlen(str); - bool has_single_quote = false; - bool has_double_quote = false; + MP_BOOL has_single_quote = MP_FALSE; + MP_BOOL has_double_quote = MP_FALSE; for (int i = 0; i < len; i++) { if (str[i] == '\'') { - has_single_quote = true; + has_single_quote = MP_TRUE; } else if (str[i] == '"') { - has_double_quote = true; + has_double_quote = MP_TRUE; } } if (bytes) { vstr_printf(vstr, "b"); } - bool quote_single = false; + MP_BOOL quote_single = MP_FALSE; if (has_single_quote && !has_double_quote) { vstr_printf(vstr, "\""); } else { - quote_single = true; + quote_single = MP_TRUE; vstr_printf(vstr, "'"); } for (int i = 0; i < len; i++) { @@ -319,8 +319,8 @@ static void cpython_c_tuple_emit_const(compiler_t *comp, mp_parse_node_t pn, vst case MP_PARSE_NODE_SMALL_INT: vstr_printf(vstr, "%d", arg); break; case MP_PARSE_NODE_INTEGER: vstr_printf(vstr, "%s", qstr_str(arg)); break; case MP_PARSE_NODE_DECIMAL: vstr_printf(vstr, "%s", qstr_str(arg)); break; - case MP_PARSE_NODE_STRING: cpython_c_print_quoted_str(vstr, arg, false); break; - case MP_PARSE_NODE_BYTES: cpython_c_print_quoted_str(vstr, arg, true); break; + case MP_PARSE_NODE_STRING: cpython_c_print_quoted_str(vstr, arg, MP_FALSE); break; + case MP_PARSE_NODE_BYTES: cpython_c_print_quoted_str(vstr, arg, MP_TRUE); break; case MP_PARSE_NODE_TOKEN: switch (arg) { case MP_TOKEN_KW_FALSE: vstr_printf(vstr, "False"); break; @@ -339,33 +339,33 @@ static void cpython_c_tuple(compiler_t *comp, mp_parse_node_t pn, mp_parse_node_ n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns_list); } int total = n; - bool is_const = true; + MP_BOOL is_const = MP_TRUE; if (!MP_PARSE_NODE_IS_NULL(pn)) { total += 1; if (!cpython_c_tuple_is_const(pn)) { - is_const = false; + is_const = MP_FALSE; } } for (int i = 0; i < n; i++) { if (!cpython_c_tuple_is_const(pns_list->nodes[i])) { - is_const = false; + is_const = MP_FALSE; break; } } if (total > 0 && is_const) { - bool need_comma = false; + MP_BOOL need_comma = MP_FALSE; vstr_t *vstr = vstr_new(); vstr_printf(vstr, "("); if (!MP_PARSE_NODE_IS_NULL(pn)) { cpython_c_tuple_emit_const(comp, pn, vstr); - need_comma = true; + need_comma = MP_TRUE; } for (int i = 0; i < n; i++) { if (need_comma) { vstr_printf(vstr, ", "); } cpython_c_tuple_emit_const(comp, pns_list->nodes[i], vstr); - need_comma = true; + need_comma = MP_TRUE; } if (total == 1) { vstr_printf(vstr, ",)"); @@ -412,25 +412,25 @@ void compile_generic_tuple(compiler_t *comp, mp_parse_node_struct_t *pns) { c_tuple(comp, MP_PARSE_NODE_NULL, pns); } -static bool node_is_const_false(mp_parse_node_t pn) { +static MP_BOOL node_is_const_false(mp_parse_node_t pn) { return MP_PARSE_NODE_IS_TOKEN_KIND(pn, MP_TOKEN_KW_FALSE); // untested: || (MP_PARSE_NODE_IS_SMALL_INT(pn) && MP_PARSE_NODE_LEAF_ARG(pn) == 1); } -static bool node_is_const_true(mp_parse_node_t pn) { +static MP_BOOL node_is_const_true(mp_parse_node_t pn) { return MP_PARSE_NODE_IS_TOKEN_KIND(pn, MP_TOKEN_KW_TRUE) || (MP_PARSE_NODE_IS_SMALL_INT(pn) && MP_PARSE_NODE_LEAF_ARG(pn) == 1); } #if MICROPY_EMIT_CPYTHON // the is_nested variable is purely to match with CPython, which doesn't fully optimise not's -static void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int label, bool is_nested) { +static void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, MP_BOOL jump_if, int label, MP_BOOL is_nested) { if (node_is_const_false(pn)) { - if (jump_if == false) { + if (jump_if == MP_FALSE) { EMIT(jump, label); } return; } else if (node_is_const_true(pn)) { - if (jump_if == true) { + if (jump_if == MP_TRUE) { EMIT(jump, label); } return; @@ -438,42 +438,42 @@ static void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn; int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_or_test) { - if (jump_if == false) { + if (jump_if == MP_FALSE) { int label2 = comp_next_label(comp); for (int i = 0; i < n - 1; i++) { - cpython_c_if_cond(comp, pns->nodes[i], true, label2, true); + cpython_c_if_cond(comp, pns->nodes[i], MP_TRUE, label2, MP_TRUE); } - cpython_c_if_cond(comp, pns->nodes[n - 1], false, label, true); + cpython_c_if_cond(comp, pns->nodes[n - 1], MP_FALSE, label, MP_TRUE); EMIT(label_assign, label2); } else { for (int i = 0; i < n; i++) { - cpython_c_if_cond(comp, pns->nodes[i], true, label, true); + cpython_c_if_cond(comp, pns->nodes[i], MP_TRUE, label, MP_TRUE); } } return; } else if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_and_test) { - if (jump_if == false) { + if (jump_if == MP_FALSE) { for (int i = 0; i < n; i++) { - cpython_c_if_cond(comp, pns->nodes[i], false, label, true); + cpython_c_if_cond(comp, pns->nodes[i], MP_FALSE, label, MP_TRUE); } } else { int label2 = comp_next_label(comp); for (int i = 0; i < n - 1; i++) { - cpython_c_if_cond(comp, pns->nodes[i], false, label2, true); + cpython_c_if_cond(comp, pns->nodes[i], MP_FALSE, label2, MP_TRUE); } - cpython_c_if_cond(comp, pns->nodes[n - 1], true, label, true); + cpython_c_if_cond(comp, pns->nodes[n - 1], MP_TRUE, label, MP_TRUE); EMIT(label_assign, label2); } return; } else if (!is_nested && MP_PARSE_NODE_STRUCT_KIND(pns) == PN_not_test_2) { - cpython_c_if_cond(comp, pns->nodes[0], !jump_if, label, true); + cpython_c_if_cond(comp, pns->nodes[0], !jump_if, label, MP_TRUE); return; } } // nothing special, fall back to default compiling for node and jump compile_node(comp, pn); - if (jump_if == false) { + if (jump_if == MP_FALSE) { EMIT(pop_jump_if_false, label); } else { EMIT(pop_jump_if_true, label); @@ -481,17 +481,17 @@ static void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if } #endif -static void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int label) { +static void c_if_cond(compiler_t *comp, mp_parse_node_t pn, MP_BOOL jump_if, int label) { #if MICROPY_EMIT_CPYTHON - cpython_c_if_cond(comp, pn, jump_if, label, false); + cpython_c_if_cond(comp, pn, jump_if, label, MP_FALSE); #else if (node_is_const_false(pn)) { - if (jump_if == false) { + if (jump_if == MP_FALSE) { EMIT(jump, label); } return; } else if (node_is_const_true(pn)) { - if (jump_if == true) { + if (jump_if == MP_TRUE) { EMIT(jump, label); } return; @@ -499,30 +499,30 @@ static void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int la mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn; int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_or_test) { - if (jump_if == false) { + if (jump_if == MP_FALSE) { int label2 = comp_next_label(comp); for (int i = 0; i < n - 1; i++) { - c_if_cond(comp, pns->nodes[i], true, label2); + c_if_cond(comp, pns->nodes[i], MP_TRUE, label2); } - c_if_cond(comp, pns->nodes[n - 1], false, label); + c_if_cond(comp, pns->nodes[n - 1], MP_FALSE, label); EMIT(label_assign, label2); } else { for (int i = 0; i < n; i++) { - c_if_cond(comp, pns->nodes[i], true, label); + c_if_cond(comp, pns->nodes[i], MP_TRUE, label); } } return; } else if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_and_test) { - if (jump_if == false) { + if (jump_if == MP_FALSE) { for (int i = 0; i < n; i++) { - c_if_cond(comp, pns->nodes[i], false, label); + c_if_cond(comp, pns->nodes[i], MP_FALSE, label); } } else { int label2 = comp_next_label(comp); for (int i = 0; i < n - 1; i++) { - c_if_cond(comp, pns->nodes[i], false, label2); + c_if_cond(comp, pns->nodes[i], MP_FALSE, label2); } - c_if_cond(comp, pns->nodes[n - 1], true, label); + c_if_cond(comp, pns->nodes[n - 1], MP_TRUE, label); EMIT(label_assign, label2); } return; @@ -534,7 +534,7 @@ static void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int la // nothing special, fall back to default compiling for node and jump compile_node(comp, pn); - if (jump_if == false) { + if (jump_if == MP_FALSE) { EMIT(pop_jump_if_false, label); } else { EMIT(pop_jump_if_true, label); @@ -803,7 +803,7 @@ void compile_funcdef_param(compiler_t *comp, mp_parse_node_t pn) { mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn; if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { // bare star - comp->have_bare_star = true; + comp->have_bare_star = MP_TRUE; } } } @@ -819,18 +819,18 @@ qstr compile_funcdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint } // save variables (probably don't need to do this, since we can't have nested definitions..?) - bool old_have_bare_star = comp->have_bare_star; + MP_BOOL old_have_bare_star = comp->have_bare_star; int old_param_pass = comp->param_pass; int old_param_pass_num_dict_params = comp->param_pass_num_dict_params; int old_param_pass_num_default_params = comp->param_pass_num_default_params; // compile default parameters - comp->have_bare_star = false; + comp->have_bare_star = MP_FALSE; comp->param_pass = 1; // pass 1 does any default parameters after bare star comp->param_pass_num_dict_params = 0; comp->param_pass_num_default_params = 0; apply_to_single_or_list(comp, pns->nodes[1], PN_typedargslist, compile_funcdef_param); - comp->have_bare_star = false; + comp->have_bare_star = MP_FALSE; comp->param_pass = 2; // pass 2 does any default parameters before bare star comp->param_pass_num_dict_params = 0; comp->param_pass_num_default_params = 0; @@ -876,12 +876,12 @@ qstr compile_classdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint // nodes[1] has parent classes, if any if (MP_PARSE_NODE_IS_NULL(pns->nodes[1])) { // no parent classes - EMIT(call_function, 2, 0, false, false); + EMIT(call_function, 2, 0, MP_FALSE, MP_FALSE); } else { // have a parent class or classes // TODO what if we have, eg, *a or **a in the parent list? compile_node(comp, pns->nodes[1]); - EMIT(call_function, 2 + list_len(pns->nodes[1], PN_arglist), 0, false, false); + EMIT(call_function, 2 + list_len(pns->nodes[1], PN_arglist), 0, MP_FALSE, MP_FALSE); } // return its name (the 'C' in class C(...):") @@ -889,14 +889,14 @@ qstr compile_classdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint } // returns true if it was a built-in decorator (even if the built-in had an error) -static bool compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_node_t *name_nodes, uint *emit_options) { +static MP_BOOL compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_node_t *name_nodes, uint *emit_options) { if (MP_PARSE_NODE_LEAF_ARG(name_nodes[0]) != MP_QSTR_micropython) { - return false; + return MP_FALSE; } if (name_len != 2) { printf("SyntaxError: invalid micropython decorator\n"); - return true; + return MP_TRUE; } qstr attr = MP_PARSE_NODE_LEAF_ARG(name_nodes[1]); @@ -916,7 +916,7 @@ static bool compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_ printf("SyntaxError: invalid micropython decorator '%s'\n", qstr_str(attr)); } - return true; + return MP_TRUE; } void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) { @@ -974,7 +974,7 @@ void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) { // call each decorator for (int i = 0; i < n - num_built_in_decorators; i++) { - EMIT(call_function, 1, 0, false, false); + EMIT(call_function, 1, 0, MP_FALSE, MP_FALSE); } // store func/class object into name @@ -1094,7 +1094,7 @@ void compile_continue_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { if (comp->scope_cur->kind != SCOPE_FUNCTION) { printf("SyntaxError: 'return' outside function\n"); - comp->had_error = true; + comp->had_error = MP_TRUE; return; } if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { @@ -1106,7 +1106,7 @@ void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { mp_parse_node_struct_t *pns_test_if_else = (mp_parse_node_struct_t*)pns_test_if_expr->nodes[1]; int l_fail = comp_next_label(comp); - c_if_cond(comp, pns_test_if_else->nodes[0], false, l_fail); // condition + c_if_cond(comp, pns_test_if_else->nodes[0], MP_FALSE, l_fail); // condition compile_node(comp, pns_test_if_expr->nodes[0]); // success value EMIT(return_value); EMIT(label_assign, l_fail); @@ -1143,13 +1143,13 @@ void compile_raise_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // eg a -> q1=q2=a // a.b.c -> q1=a, q2=a.b.c void do_import_name(compiler_t *comp, mp_parse_node_t pn, qstr *q1, qstr *q2) { - bool is_as = false; + MP_BOOL is_as = MP_FALSE; if (MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_dotted_as_name)) { mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn; // a name of the form x as y; unwrap it *q1 = MP_PARSE_NODE_LEAF_ARG(pns->nodes[1]); pn = pns->nodes[0]; - is_as = true; + is_as = MP_TRUE; } if (MP_PARSE_NODE_IS_ID(pn)) { // just a simple name @@ -1220,7 +1220,7 @@ void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) { #if MICROPY_EMIT_CPYTHON EMIT(load_const_verbatim_str, "('*',)"); #else - EMIT(load_const_str, qstr_from_str_static("*"), false); + EMIT(load_const_str, qstr_from_str_static("*"), MP_FALSE); EMIT(build_tuple, 1); #endif @@ -1262,7 +1262,7 @@ void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) { assert(MP_PARSE_NODE_IS_STRUCT_KIND(pn_nodes[i], PN_import_as_name)); mp_parse_node_struct_t *pns3 = (mp_parse_node_struct_t*)pn_nodes[i]; qstr id2 = MP_PARSE_NODE_LEAF_ARG(pns3->nodes[0]); // should be id - EMIT(load_const_str, id2, false); + EMIT(load_const_str, id2, MP_FALSE); } EMIT(build_tuple, n); #endif @@ -1315,12 +1315,12 @@ void compile_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { int l_end = comp_next_label(comp); - c_if_cond(comp, pns->nodes[0], true, l_end); + c_if_cond(comp, pns->nodes[0], MP_TRUE, l_end); EMIT(load_id, MP_QSTR_AssertionError); if (!MP_PARSE_NODE_IS_NULL(pns->nodes[1])) { // assertion message compile_node(comp, pns->nodes[1]); - EMIT(call_function, 1, 0, false, false); + EMIT(call_function, 1, 0, MP_FALSE, MP_FALSE); } EMIT(raise_varargs, 1); EMIT(label_assign, l_end); @@ -1332,7 +1332,7 @@ void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { int l_end = comp_next_label(comp); int l_fail = comp_next_label(comp); - c_if_cond(comp, pns->nodes[0], false, l_fail); // if condition + c_if_cond(comp, pns->nodes[0], MP_FALSE, l_fail); // if condition compile_node(comp, pns->nodes[1]); // if block //if (!(MP_PARSE_NODE_IS_NULL(pns->nodes[2]) && MP_PARSE_NODE_IS_NULL(pns->nodes[3]))) { // optimisation; doesn't align with CPython @@ -1355,7 +1355,7 @@ void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { for (int i = 0; i < n; i++) { mp_parse_node_struct_t *pns_elif2 = (mp_parse_node_struct_t*)pns_elif->nodes[i]; l_fail = comp_next_label(comp); - c_if_cond(comp, pns_elif2->nodes[0], false, l_fail); // elif condition + c_if_cond(comp, pns_elif2->nodes[0], MP_FALSE, l_fail); // elif condition compile_node(comp, pns_elif2->nodes[1]); // elif block if (!EMIT(last_emit_was_return_value)) { // simple optimisation to align with CPython @@ -1368,7 +1368,7 @@ void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // a single elif block l_fail = comp_next_label(comp); - c_if_cond(comp, pns_elif->nodes[0], false, l_fail); // elif condition + c_if_cond(comp, pns_elif->nodes[0], MP_FALSE, l_fail); // elif condition compile_node(comp, pns_elif->nodes[1]); // elif block if (!EMIT(last_emit_was_return_value)) { // simple optimisation to align with CPython @@ -1399,7 +1399,7 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { int done_label = comp_next_label(comp); EMIT(setup_loop, break_label); EMIT(label_assign, continue_label); - c_if_cond(comp, pns->nodes[0], false, done_label); // condition + c_if_cond(comp, pns->nodes[0], MP_FALSE, done_label); // condition compile_node(comp, pns->nodes[1]); // body if (!EMIT(last_emit_was_return_value)) { EMIT(jump, continue_label); @@ -1416,7 +1416,7 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { EMIT(label_assign, top_label); compile_node(comp, pns->nodes[1]); // body EMIT(label_assign, continue_label); - c_if_cond(comp, pns->nodes[0], true, top_label); // condition + c_if_cond(comp, pns->nodes[0], MP_TRUE, top_label); // condition #endif // break/continue apply to outer loop (if any) in the else block @@ -1732,7 +1732,7 @@ void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // for REPL, evaluate then print the expression EMIT(load_id, MP_QSTR___repl_print__); compile_node(comp, pns->nodes[0]); - EMIT(call_function, 1, 0, false, false); + EMIT(call_function, 1, 0, MP_FALSE, MP_FALSE); EMIT(pop_top); } else { @@ -1837,7 +1837,7 @@ void compile_test_if_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { int stack_size = EMIT(get_stack_size); int l_fail = comp_next_label(comp); int l_end = comp_next_label(comp); - c_if_cond(comp, pns_test_if_else->nodes[0], false, l_fail); // condition + c_if_cond(comp, pns_test_if_else->nodes[0], MP_FALSE, l_fail); // condition compile_node(comp, pns->nodes[0]); // success value EMIT(jump, l_end); EMIT(label_assign, l_fail); @@ -1898,7 +1898,7 @@ void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) { int stack_size = EMIT(get_stack_size); int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); compile_node(comp, pns->nodes[0]); - bool multi = (num_nodes > 3); + MP_BOOL multi = (num_nodes > 3); int l_fail = 0; if (multi) { l_fail = comp_next_label(comp); @@ -2042,15 +2042,15 @@ void compile_factor_2(compiler_t *comp, mp_parse_node_struct_t *pns) { } } -void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_struct_t *pns, bool is_method_call) { +void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_struct_t *pns, MP_BOOL is_method_call) { // function to call is on top of stack int old_n_arg_keyword = comp->n_arg_keyword; - bool old_have_star_arg = comp->have_star_arg; - bool old_have_dbl_star_arg = comp->have_dbl_star_arg; + MP_BOOL old_have_star_arg = comp->have_star_arg; + MP_BOOL old_have_dbl_star_arg = comp->have_dbl_star_arg; comp->n_arg_keyword = 0; - comp->have_star_arg = false; - comp->have_dbl_star_arg = false; + comp->have_star_arg = MP_FALSE; + comp->have_dbl_star_arg = MP_FALSE; compile_node(comp, pns->nodes[0]); // arguments to function call; can be null @@ -2082,7 +2082,7 @@ void compile_power_trailers(compiler_t *comp, mp_parse_node_struct_t *pns) { mp_parse_node_struct_t *pns_period = (mp_parse_node_struct_t*)pns->nodes[i]; mp_parse_node_struct_t *pns_paren = (mp_parse_node_struct_t*)pns->nodes[i + 1]; EMIT(load_method, MP_PARSE_NODE_LEAF_ARG(pns_period->nodes[0])); // get the method - compile_trailer_paren_helper(comp, pns_paren, true); + compile_trailer_paren_helper(comp, pns_paren, MP_TRUE); i += 1; } else { compile_node(comp, pns->nodes[i]); @@ -2153,7 +2153,7 @@ void compile_comprehension(compiler_t *comp, mp_parse_node_struct_t *pns, scope_ compile_node(comp, pns_comp_for->nodes[1]); // source of the iterator EMIT(get_iter); - EMIT(call_function, 1, 0, false, false); + EMIT(call_function, 1, 0, MP_FALSE, MP_FALSE); } void compile_atom_paren(compiler_t *comp, mp_parse_node_struct_t *pns) { @@ -2252,23 +2252,23 @@ void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) { int n = list_get(&pns1->nodes[0], PN_dictorsetmaker_list2, &nodes); // first element sets whether it's a dict or set - bool is_dict; + MP_BOOL is_dict; if (MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[0], PN_dictorsetmaker_item)) { // a dictionary EMIT(build_map, 1 + n); compile_node(comp, pns->nodes[0]); EMIT(store_map); - is_dict = true; + is_dict = MP_TRUE; } else { // a set compile_node(comp, pns->nodes[0]); // 1st value of set - is_dict = false; + is_dict = MP_FALSE; } // process rest of elements for (int i = 0; i < n; i++) { mp_parse_node_t pn = nodes[i]; - bool is_key_value = MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_dictorsetmaker_item); + MP_BOOL is_key_value = MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_dictorsetmaker_item); compile_node(comp, pn); if (is_dict) { if (!is_key_value) { @@ -2314,7 +2314,7 @@ void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) { } void compile_trailer_paren(compiler_t *comp, mp_parse_node_struct_t *pns) { - compile_trailer_paren_helper(comp, pns, false); + compile_trailer_paren_helper(comp, pns, MP_FALSE); } void compile_trailer_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) { @@ -2401,7 +2401,7 @@ void compile_arglist_star(compiler_t *comp, mp_parse_node_struct_t *pns) { printf("SyntaxError?: can't have multiple *x\n"); return; } - comp->have_star_arg = true; + comp->have_star_arg = MP_TRUE; compile_node(comp, pns->nodes[0]); } @@ -2410,7 +2410,7 @@ void compile_arglist_dbl_star(compiler_t *comp, mp_parse_node_struct_t *pns) { printf("SyntaxError?: can't have multiple **x\n"); return; } - comp->have_dbl_star_arg = true; + comp->have_dbl_star_arg = MP_TRUE; compile_node(comp, pns->nodes[0]); } @@ -2475,8 +2475,8 @@ void compile_node(compiler_t *comp, mp_parse_node_t pn) { case MP_PARSE_NODE_SMALL_INT: EMIT(load_const_small_int, arg); break; case MP_PARSE_NODE_INTEGER: EMIT(load_const_int, arg); break; case MP_PARSE_NODE_DECIMAL: EMIT(load_const_dec, arg); break; - case MP_PARSE_NODE_STRING: EMIT(load_const_str, arg, false); break; - case MP_PARSE_NODE_BYTES: EMIT(load_const_str, arg, true); break; + case MP_PARSE_NODE_STRING: EMIT(load_const_str, arg, MP_FALSE); break; + case MP_PARSE_NODE_BYTES: EMIT(load_const_str, arg, MP_TRUE); break; case MP_PARSE_NODE_TOKEN: if (arg == MP_TOKEN_NEWLINE) { // this can occur when file_input lets through a NEWLINE (eg if file starts with a newline) @@ -2501,7 +2501,7 @@ void compile_node(compiler_t *comp, mp_parse_node_t pn) { } } -void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_kind_t pn_name, pn_kind_t pn_star, pn_kind_t pn_dbl_star, bool allow_annotations) { +void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_kind_t pn_name, pn_kind_t pn_star, pn_kind_t pn_dbl_star, MP_BOOL allow_annotations) { // TODO verify that *k and **k are last etc qstr param_name = 0; mp_parse_node_t pn_annotation = MP_PARSE_NODE_NULL; @@ -2544,7 +2544,7 @@ void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_ki if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { // bare star // TODO see http://www.python.org/dev/peps/pep-3102/ - comp->have_bare_star = true; + comp->have_bare_star = MP_TRUE; //assert(comp->scope_cur->num_dict_params == 0); } else if (MP_PARSE_NODE_IS_ID(pns->nodes[0])) { // named star @@ -2577,23 +2577,23 @@ void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_ki if (!MP_PARSE_NODE_IS_NULL(pn_annotation)) { // TODO this parameter has an annotation } - bool added; + MP_BOOL added; id_info_t *id_info = scope_find_or_add_id(comp->scope_cur, param_name, &added); if (!added) { printf("SyntaxError?: same name used for parameter; %s\n", qstr_str(param_name)); return; } - id_info->param = true; + id_info->param = MP_TRUE; id_info->kind = ID_INFO_KIND_LOCAL; } } void compile_scope_func_param(compiler_t *comp, mp_parse_node_t pn) { - compile_scope_func_lambda_param(comp, pn, PN_typedargslist_name, PN_typedargslist_star, PN_typedargslist_dbl_star, true); + compile_scope_func_lambda_param(comp, pn, PN_typedargslist_name, PN_typedargslist_star, PN_typedargslist_dbl_star, MP_TRUE); } void compile_scope_lambda_param(compiler_t *comp, mp_parse_node_t pn) { - compile_scope_func_lambda_param(comp, pn, PN_varargslist_name, PN_varargslist_star, PN_varargslist_dbl_star, false); + compile_scope_func_lambda_param(comp, pn, PN_varargslist_name, PN_varargslist_star, PN_varargslist_dbl_star, MP_FALSE); } void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_t pn_iter, mp_parse_node_t pn_inner_expr, int l_top, int for_depth) { @@ -2614,7 +2614,7 @@ void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_t pn_iter, mp_parse } else if (MP_PARSE_NODE_IS_STRUCT_KIND(pn_iter, PN_comp_if)) { // if condition mp_parse_node_struct_t *pns_comp_if = (mp_parse_node_struct_t*)pn_iter; - c_if_cond(comp, pns_comp_if->nodes[0], false, l_top); + c_if_cond(comp, pns_comp_if->nodes[0], MP_FALSE, l_top); pn_iter = pns_comp_if->nodes[1]; goto tail_recursion; } else if (MP_PARSE_NODE_IS_STRUCT_KIND(pn_iter, PN_comp_for)) { @@ -2708,7 +2708,7 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { // work out number of parameters, keywords and default parameters, and add them to the id_info array // must be done before compiling the body so that arguments are numbered first (for LOAD_FAST etc) if (comp->pass == PASS_1) { - comp->have_bare_star = false; + comp->have_bare_star = MP_FALSE; apply_to_single_or_list(comp, pns->nodes[1], PN_typedargslist, compile_scope_func_param); } @@ -2728,7 +2728,7 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { // work out number of parameters, keywords and default parameters, and add them to the id_info array // must be done before compiling the body so that arguments are numbered first (for LOAD_FAST etc) if (comp->pass == PASS_1) { - comp->have_bare_star = false; + comp->have_bare_star = MP_FALSE; apply_to_single_or_list(comp, pns->nodes[0], PN_varargslist, compile_scope_lambda_param); } @@ -2745,7 +2745,7 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { qstr qstr_arg = qstr_from_str_static(".0"); if (comp->pass == PASS_1) { - bool added; + MP_BOOL added; id_info_t *id_info = scope_find_or_add_id(comp->scope_cur, qstr_arg, &added); assert(added); id_info->kind = ID_INFO_KIND_LOCAL; @@ -2782,14 +2782,14 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { assert(MP_PARSE_NODE_STRUCT_KIND(pns) == PN_classdef); if (comp->pass == PASS_1) { - bool added; + MP_BOOL added; id_info_t *id_info = scope_find_or_add_id(scope, MP_QSTR___class__, &added); assert(added); id_info->kind = ID_INFO_KIND_LOCAL; id_info = scope_find_or_add_id(scope, MP_QSTR___locals__, &added); assert(added); id_info->kind = ID_INFO_KIND_LOCAL; - id_info->param = true; + id_info->param = MP_TRUE; scope->num_params = 1; // __locals__ is the parameter } @@ -3005,11 +3005,11 @@ void compile_scope_compute_things(compiler_t *comp, scope_t *scope) { } } -mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) { +mp_obj_t mp_compile(mp_parse_node_t pn, MP_BOOL is_repl) { compiler_t *comp = m_new(compiler_t, 1); comp->is_repl = is_repl; - comp->had_error = false; + comp->had_error = MP_FALSE; comp->break_label = 0; comp->continue_label = 0; @@ -3030,7 +3030,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) { comp->emit_inline_asm_method_table = NULL; uint max_num_labels = 0; for (scope_t *s = comp->scope_head; s != NULL && !comp->had_error; s = s->next) { - if (false) { + if (MP_FALSE) { #if MICROPY_EMIT_INLINE_THUMB } else if (s->emit_options == EMIT_OPT_ASM_THUMB) { compile_scope_inline_asm(comp, s, PASS_1); @@ -3064,7 +3064,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) { #endif #endif // !MICROPY_EMIT_CPYTHON for (scope_t *s = comp->scope_head; s != NULL && !comp->had_error; s = s->next) { - if (false) { + if (MP_FALSE) { // dummy #if MICROPY_EMIT_INLINE_THUMB @@ -3126,7 +3126,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) { } } - bool had_error = comp->had_error; + MP_BOOL had_error = comp->had_error; m_del_obj(compiler_t, comp); if (had_error) { diff --git a/py/compile.h b/py/compile.h index 770c2524da..27e47f2f18 100644 --- a/py/compile.h +++ b/py/compile.h @@ -1 +1 @@ -mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl); +mp_obj_t mp_compile(mp_parse_node_t pn, MP_BOOL is_repl); diff --git a/py/emit.h b/py/emit.h index ea65731038..1566438595 100644 --- a/py/emit.h +++ b/py/emit.h @@ -17,10 +17,10 @@ typedef enum { typedef struct _emit_t emit_t; typedef struct _emit_method_table_t { - void (*set_native_types)(emit_t *emit, bool do_native_types); + void (*set_native_types)(emit_t *emit, MP_BOOL do_native_types); void (*start_pass)(emit_t *emit, pass_kind_t pass, scope_t *scope); void (*end_pass)(emit_t *emit); - bool (*last_emit_was_return_value)(emit_t *emit); + MP_BOOL (*last_emit_was_return_value)(emit_t *emit); int (*get_stack_size)(emit_t *emit); void (*set_stack_size)(emit_t *emit, int size); @@ -37,7 +37,7 @@ typedef struct _emit_method_table_t { void (*load_const_int)(emit_t *emit, qstr qstr); void (*load_const_dec)(emit_t *emit, qstr qstr); void (*load_const_id)(emit_t *emit, qstr qstr); - void (*load_const_str)(emit_t *emit, qstr qstr, bool bytes); + void (*load_const_str)(emit_t *emit, qstr qstr, MP_BOOL bytes); void (*load_const_verbatim_str)(emit_t *emit, const char *str); // only needed for emitcpy void (*load_fast)(emit_t *emit, qstr qstr, int local_num); void (*load_deref)(emit_t *emit, qstr qstr, int local_num); @@ -99,8 +99,8 @@ typedef struct _emit_method_table_t { void (*unpack_ex)(emit_t *emit, int n_left, int n_right); void (*make_function)(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params); void (*make_closure)(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params); - void (*call_function)(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg); - void (*call_method)(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg); + void (*call_function)(emit_t *emit, int n_positional, int n_keyword, MP_BOOL have_star_arg, MP_BOOL have_dbl_star_arg); + void (*call_method)(emit_t *emit, int n_positional, int n_keyword, MP_BOOL have_star_arg, MP_BOOL have_dbl_star_arg); void (*return_value)(emit_t *emit); void (*raise_varargs)(emit_t *emit, int n_args); void (*yield_value)(emit_t *emit); diff --git a/py/emitbc.c b/py/emitbc.c index c0ec2469a6..93c92f41fa 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -17,7 +17,7 @@ struct _emit_t { pass_kind_t pass; int stack_size; - bool last_emit_was_return_value; + MP_BOOL last_emit_was_return_value; scope_t *scope; @@ -135,13 +135,13 @@ static void emit_write_byte_1_signed_label(emit_t* emit, byte b1, int label) { c[2] = code_offset >> 8; } -static void emit_bc_set_native_types(emit_t *emit, bool do_native_types) { +static void emit_bc_set_native_types(emit_t *emit, MP_BOOL do_native_types) { } static void emit_bc_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) { emit->pass = pass; emit->stack_size = 0; - emit->last_emit_was_return_value = false; + emit->last_emit_was_return_value = MP_FALSE; emit->scope = scope; if (pass == PASS_2) { memset(emit->label_offsets, -1, emit->max_num_labels * sizeof(uint)); @@ -182,7 +182,7 @@ static void emit_bc_end_pass(emit_t *emit) { } } -bool emit_bc_last_emit_was_return_value(emit_t *emit) { +MP_BOOL emit_bc_last_emit_was_return_value(emit_t *emit) { return emit->last_emit_was_return_value; } @@ -211,7 +211,7 @@ static void emit_pre(emit_t *emit, int stack_size_delta) { if (emit->stack_size > emit->scope->stack_size) { emit->scope->stack_size = emit->stack_size; } - emit->last_emit_was_return_value = false; + emit->last_emit_was_return_value = MP_FALSE; } static void emit_bc_label_assign(emit_t *emit, int l) { @@ -274,7 +274,7 @@ static void emit_bc_load_const_id(emit_t *emit, qstr qstr) { emit_write_byte_1_qstr(emit, MP_BC_LOAD_CONST_ID, qstr); } -static void emit_bc_load_const_str(emit_t *emit, qstr qstr, bool bytes) { +static void emit_bc_load_const_str(emit_t *emit, qstr qstr, MP_BOOL bytes) { emit_pre(emit, 1); if (bytes) { emit_write_byte_1_qstr(emit, MP_BC_LOAD_CONST_BYTES, qstr); @@ -613,7 +613,7 @@ static void emit_bc_make_closure(emit_t *emit, scope_t *scope, int n_dict_params emit_write_byte_1_uint(emit, MP_BC_MAKE_CLOSURE, scope->unique_code_id); } -static void emit_bc_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { +static void emit_bc_call_function(emit_t *emit, int n_positional, int n_keyword, MP_BOOL have_star_arg, MP_BOOL have_dbl_star_arg) { int s = 0; if (have_star_arg) { s += 1; @@ -639,7 +639,7 @@ static void emit_bc_call_function(emit_t *emit, int n_positional, int n_keyword, emit_write_byte_1_uint(emit, op, (n_keyword << 8) | n_positional); // TODO make it 2 separate uints } -static void emit_bc_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { +static void emit_bc_call_method(emit_t *emit, int n_positional, int n_keyword, MP_BOOL have_star_arg, MP_BOOL have_dbl_star_arg) { int s = 0; if (have_star_arg) { s += 1; @@ -667,7 +667,7 @@ static void emit_bc_call_method(emit_t *emit, int n_positional, int n_keyword, b static void emit_bc_return_value(emit_t *emit) { emit_pre(emit, -1); - emit->last_emit_was_return_value = true; + emit->last_emit_was_return_value = MP_TRUE; emit_write_byte_1(emit, MP_BC_RETURN_VALUE); } diff --git a/py/emitcpy.c b/py/emitcpy.c index 7b2d50fb7e..ff44609d58 100644 --- a/py/emitcpy.c +++ b/py/emitcpy.c @@ -20,7 +20,7 @@ struct _emit_t { int pass; int byte_code_offset; int stack_size; - bool last_emit_was_return_value; + MP_BOOL last_emit_was_return_value; scope_t *scope; @@ -35,14 +35,14 @@ emit_t *emit_cpython_new(uint max_num_labels) { return emit; } -static void emit_cpy_set_native_types(emit_t *emit, bool do_native_types) { +static void emit_cpy_set_native_types(emit_t *emit, MP_BOOL do_native_types) { } static void emit_cpy_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) { emit->pass = pass; emit->byte_code_offset = 0; emit->stack_size = 0; - emit->last_emit_was_return_value = false; + emit->last_emit_was_return_value = MP_FALSE; emit->scope = scope; if (pass == PASS_2) { memset(emit->label_offsets, -1, emit->max_num_labels * sizeof(int)); @@ -56,7 +56,7 @@ static void emit_cpy_end_pass(emit_t *emit) { } } -static bool emit_cpy_last_emit_was_return_value(emit_t *emit) { +static MP_BOOL emit_cpy_last_emit_was_return_value(emit_t *emit) { return emit->last_emit_was_return_value; } @@ -85,7 +85,7 @@ static void emit_pre(emit_t *emit, int stack_size_delta, int byte_code_size) { if (emit->stack_size > emit->scope->stack_size) { emit->scope->stack_size = emit->stack_size; } - emit->last_emit_was_return_value = false; + emit->last_emit_was_return_value = MP_FALSE; if (emit->pass == PASS_3 && byte_code_size > 0) { if (emit->byte_code_offset >= 1000) { printf("%d ", emit->byte_code_offset); @@ -173,26 +173,26 @@ static void emit_cpy_load_const_id(emit_t *emit, qstr qstr) { } } -static void print_quoted_str(qstr qstr, bool bytes) { +static void print_quoted_str(qstr qstr, MP_BOOL bytes) { const char *str = qstr_str(qstr); int len = strlen(str); - bool has_single_quote = false; - bool has_double_quote = false; + MP_BOOL has_single_quote = MP_FALSE; + MP_BOOL has_double_quote = MP_FALSE; for (int i = 0; i < len; i++) { if (str[i] == '\'') { - has_single_quote = true; + has_single_quote = MP_TRUE; } else if (str[i] == '"') { - has_double_quote = true; + has_double_quote = MP_TRUE; } } if (bytes) { printf("b"); } - bool quote_single = false; + MP_BOOL quote_single = MP_FALSE; if (has_single_quote && !has_double_quote) { printf("\""); } else { - quote_single = true; + quote_single = MP_TRUE; printf("'"); } for (int i = 0; i < len; i++) { @@ -213,7 +213,7 @@ static void print_quoted_str(qstr qstr, bool bytes) { } } -static void emit_cpy_load_const_str(emit_t *emit, qstr qstr, bool bytes) { +static void emit_cpy_load_const_str(emit_t *emit, qstr qstr, MP_BOOL bytes) { emit_pre(emit, 1, 3); if (emit->pass == PASS_3) { printf("LOAD_CONST "); @@ -681,7 +681,7 @@ static void emit_cpy_unpack_ex(emit_t *emit, int n_left, int n_right) { } } -static void emit_cpy_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { +static void emit_cpy_call_function(emit_t *emit, int n_positional, int n_keyword, MP_BOOL have_star_arg, MP_BOOL have_dbl_star_arg) { int s = 0; if (have_star_arg) { s += 1; @@ -708,13 +708,13 @@ static void emit_cpy_call_function(emit_t *emit, int n_positional, int n_keyword } } -static void emit_cpy_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { +static void emit_cpy_call_method(emit_t *emit, int n_positional, int n_keyword, MP_BOOL have_star_arg, MP_BOOL have_dbl_star_arg) { emit_cpy_call_function(emit, n_positional, n_keyword, have_star_arg, have_dbl_star_arg); } static void emit_cpy_return_value(emit_t *emit) { emit_pre(emit, -1, 1); - emit->last_emit_was_return_value = true; + emit->last_emit_was_return_value = MP_TRUE; if (emit->pass == PASS_3) { printf("RETURN_VALUE\n"); } diff --git a/py/emitinlinethumb.c b/py/emitinlinethumb.c index 073dfa0604..9dc9a7a798 100644 --- a/py/emitinlinethumb.c +++ b/py/emitinlinethumb.c @@ -75,12 +75,12 @@ static void emit_inline_thumb_label(emit_inline_asm_t *emit, int label_num, qstr asm_thumb_label_assign(emit->as, label_num); } -static bool check_n_arg(qstr op, int n_args, int wanted_n_args) { +static MP_BOOL check_n_arg(qstr op, int n_args, int wanted_n_args) { if (wanted_n_args == n_args) { - return true; + return MP_TRUE; } else { printf("SyntaxError: '%s' expects %d arguments'\n", qstr_str(op), wanted_n_args); - return false; + return MP_FALSE; } } diff --git a/py/emitnative.c b/py/emitnative.c index cc00c57319..fd2ee57087 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -52,7 +52,7 @@ #define REG_TEMP2 (REG_RSI) #define ASM_MOV_REG_TO_LOCAL(reg, local_num) asm_x64_mov_r64_to_local(emit->as, (reg), (local_num)) #define ASM_MOV_IMM_TO_REG(imm, reg) asm_x64_mov_i64_to_r64_optimised(emit->as, (imm), (reg)) -#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_x64_mov_i64_to_r64_optimised(emit->as, (imm), (reg_temp)); asm_x64_mov_r64_to_local(emit->as, (reg_temp), (local_num)); } while (false) +#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_x64_mov_i64_to_r64_optimised(emit->as, (imm), (reg_temp)); asm_x64_mov_r64_to_local(emit->as, (reg_temp), (local_num)); } while (MP_FALSE) #define ASM_MOV_LOCAL_TO_REG(local_num, reg) asm_x64_mov_local_to_r64(emit->as, (local_num), (reg)) #define ASM_MOV_REG_TO_REG(reg_src, reg_dest) asm_x64_mov_r64_to_r64(emit->as, (reg_src), (reg_dest)) #define ASM_MOV_LOCAL_ADDR_TO_REG(local_num, reg) asm_x64_mov_local_addr_to_r64(emit->as, (local_num), (reg)) @@ -75,7 +75,7 @@ #define REG_TEMP2 (REG_R2) #define ASM_MOV_REG_TO_LOCAL(reg, local_num) asm_thumb_mov_local_reg(emit->as, (local_num), (reg)) #define ASM_MOV_IMM_TO_REG(imm, reg) asm_thumb_mov_reg_i32_optimised(emit->as, (reg), (imm)) -#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_thumb_mov_reg_i32_optimised(emit->as, (reg_temp), (imm)); asm_thumb_mov_local_reg(emit->as, (local_num), (reg_temp)); } while (false) +#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_thumb_mov_reg_i32_optimised(emit->as, (reg_temp), (imm)); asm_thumb_mov_local_reg(emit->as, (local_num), (reg_temp)); } while (MP_FALSE) #define ASM_MOV_LOCAL_TO_REG(local_num, reg) asm_thumb_mov_reg_local(emit->as, (reg), (local_num)) #define ASM_MOV_REG_TO_REG(reg_src, reg_dest) asm_thumb_mov_reg_reg(emit->as, (reg_dest), (reg_src)) #define ASM_MOV_LOCAL_ADDR_TO_REG(local_num, reg) asm_thumb_mov_reg_local_addr(emit->as, (reg), (local_num)) @@ -110,7 +110,7 @@ typedef struct _stack_info_t { struct _emit_t { int pass; - bool do_viper_types; + MP_BOOL do_viper_types; int local_vtype_alloc; vtype_kind_t *local_vtype; @@ -121,7 +121,7 @@ struct _emit_t { int stack_start; int stack_size; - bool last_emit_was_return_value; + MP_BOOL last_emit_was_return_value; scope_t *scope; @@ -134,7 +134,7 @@ struct _emit_t { emit_t *EXPORT_FUN(new)(uint max_num_labels) { emit_t *emit = m_new(emit_t, 1); - emit->do_viper_types = false; + emit->do_viper_types = MP_FALSE; emit->local_vtype = NULL; emit->stack_info = NULL; #if N_X64 @@ -145,7 +145,7 @@ emit_t *EXPORT_FUN(new)(uint max_num_labels) { return emit; } -static void emit_native_set_viper_types(emit_t *emit, bool do_viper_types) { +static void emit_native_set_viper_types(emit_t *emit, MP_BOOL do_viper_types) { emit->do_viper_types = do_viper_types; } @@ -153,7 +153,7 @@ static void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop emit->pass = pass; emit->stack_start = 0; emit->stack_size = 0; - emit->last_emit_was_return_value = false; + emit->last_emit_was_return_value = MP_FALSE; emit->scope = scope; if (emit->local_vtype == NULL) { @@ -269,7 +269,7 @@ static void emit_native_end_pass(emit_t *emit) { } } -static bool emit_native_last_emit_was_return_value(emit_t *emit) { +static MP_BOOL emit_native_last_emit_was_return_value(emit_t *emit) { return emit->last_emit_was_return_value; } @@ -292,13 +292,13 @@ static void adjust_stack(emit_t *emit, int stack_size_delta) { /* static void emit_pre_raw(emit_t *emit, int stack_size_delta) { adjust_stack(emit, stack_size_delta); - emit->last_emit_was_return_value = false; + emit->last_emit_was_return_value = MP_FALSE; } */ // this must be called at start of emit functions static void emit_pre(emit_t *emit) { - emit->last_emit_was_return_value = false; + emit->last_emit_was_return_value = MP_FALSE; // settle the stack /* if (regs_needed != 0) { @@ -391,7 +391,7 @@ static void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int re } static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg_dest) { - emit->last_emit_was_return_value = false; + emit->last_emit_was_return_value = MP_FALSE; emit_access_stack(emit, 1, vtype, reg_dest); adjust_stack(emit, -1); } @@ -618,7 +618,7 @@ static void emit_native_load_const_id(emit_t *emit, qstr qstr) { } } -static void emit_native_load_const_str(emit_t *emit, qstr qstr, bool bytes) { +static void emit_native_load_const_str(emit_t *emit, qstr qstr, MP_BOOL bytes) { emit_pre(emit); if (emit->do_viper_types) { // not implemented properly @@ -1134,7 +1134,7 @@ static void emit_native_make_closure(emit_t *emit, scope_t *scope, int n_dict_pa assert(0); } -static void emit_native_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { +static void emit_native_call_function(emit_t *emit, int n_positional, int n_keyword, MP_BOOL have_star_arg, MP_BOOL have_dbl_star_arg) { // call special viper runtime routine with type info for args, and wanted type info for return assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg); /* @@ -1170,7 +1170,7 @@ static void emit_native_call_function(emit_t *emit, int n_positional, int n_keyw emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -static void emit_native_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { +static void emit_native_call_method(emit_t *emit, int n_positional, int n_keyword, MP_BOOL have_star_arg, MP_BOOL have_dbl_star_arg) { assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg); /* if (n_positional == 0) { @@ -1205,7 +1205,7 @@ static void emit_native_return_value(emit_t *emit) { } else { assert(vtype == VTYPE_PYOBJ); } - emit->last_emit_was_return_value = true; + emit->last_emit_was_return_value = MP_TRUE; #if N_X64 //asm_x64_call_ind(emit->as, 0, REG_RAX); to seg fault for debugging with gdb asm_x64_exit(emit->as); diff --git a/py/emitpass1.c b/py/emitpass1.c index f78ec7e27e..45197cb41a 100644 --- a/py/emitpass1.c +++ b/py/emitpass1.c @@ -42,7 +42,7 @@ static void emit_pass1_end_pass(emit_t *emit) { static void emit_pass1_load_id(emit_t *emit, qstr qstr) { // name adding/lookup - bool added; + MP_BOOL added; id_info_t *id = scope_find_or_add_id(emit->scope, qstr, &added); if (added) { if (qstr == MP_QSTR_AssertionError) { @@ -73,7 +73,7 @@ static void emit_pass1_load_id(emit_t *emit, qstr qstr) { static id_info_t *get_id_for_modification(scope_t *scope, qstr qstr) { // name adding/lookup - bool added; + MP_BOOL added; id_info_t *id = scope_find_or_add_id(scope, qstr, &added); if (added) { if (scope->kind == SCOPE_MODULE || scope->kind == SCOPE_CLASS) { diff --git a/py/lexer.c b/py/lexer.c index d4205236c3..7e18792b51 100644 --- a/py/lexer.c +++ b/py/lexer.c @@ -35,7 +35,7 @@ struct _mp_lexer_t { mp_token_t tok_cur; }; -bool str_strn_equal(const char *str, const char *strn, int len) { +MP_BOOL str_strn_equal(const char *str, const char *strn, int len) { uint i = 0; while (i < len && *str == *strn) { @@ -70,74 +70,74 @@ void mp_token_show_error_prefix(const mp_token_t *tok) { printf("(%s:%d:%d) ", tok->src_name, tok->src_line, tok->src_column); } -bool mp_token_show_error(const mp_token_t *tok, const char *msg) { +MP_BOOL mp_token_show_error(const mp_token_t *tok, const char *msg) { printf("(%s:%d:%d) %s\n", tok->src_name, tok->src_line, tok->src_column, msg); - return false; + return MP_FALSE; } #define CUR_CHAR(lex) ((lex)->chr0) -static bool is_end(mp_lexer_t *lex) { +static MP_BOOL is_end(mp_lexer_t *lex) { return lex->chr0 == MP_LEXER_CHAR_EOF; } -static bool is_physical_newline(mp_lexer_t *lex) { +static MP_BOOL is_physical_newline(mp_lexer_t *lex) { return lex->chr0 == '\n' || lex->chr0 == '\r'; } -static bool is_char(mp_lexer_t *lex, char c) { +static MP_BOOL is_char(mp_lexer_t *lex, char c) { return lex->chr0 == c; } -static bool is_char_or(mp_lexer_t *lex, char c1, char c2) { +static MP_BOOL is_char_or(mp_lexer_t *lex, char c1, char c2) { return lex->chr0 == c1 || lex->chr0 == c2; } -static bool is_char_or3(mp_lexer_t *lex, char c1, char c2, char c3) { +static MP_BOOL is_char_or3(mp_lexer_t *lex, char c1, char c2, char c3) { return lex->chr0 == c1 || lex->chr0 == c2 || lex->chr0 == c3; } /* -static bool is_char_following(mp_lexer_t *lex, char c) { +static MP_BOOL is_char_following(mp_lexer_t *lex, char c) { return lex->chr1 == c; } */ -static bool is_char_following_or(mp_lexer_t *lex, char c1, char c2) { +static MP_BOOL is_char_following_or(mp_lexer_t *lex, char c1, char c2) { return lex->chr1 == c1 || lex->chr1 == c2; } -static bool is_char_following_following_or(mp_lexer_t *lex, char c1, char c2) { +static MP_BOOL is_char_following_following_or(mp_lexer_t *lex, char c1, char c2) { return lex->chr2 == c1 || lex->chr2 == c2; } -static bool is_char_and(mp_lexer_t *lex, char c1, char c2) { +static MP_BOOL is_char_and(mp_lexer_t *lex, char c1, char c2) { return lex->chr0 == c1 && lex->chr1 == c2; } -static bool is_whitespace(mp_lexer_t *lex) { +static MP_BOOL is_whitespace(mp_lexer_t *lex) { return unichar_isspace(lex->chr0); } -static bool is_letter(mp_lexer_t *lex) { +static MP_BOOL is_letter(mp_lexer_t *lex) { return unichar_isalpha(lex->chr0); } -static bool is_digit(mp_lexer_t *lex) { +static MP_BOOL is_digit(mp_lexer_t *lex) { return unichar_isdigit(lex->chr0); } -static bool is_following_digit(mp_lexer_t *lex) { +static MP_BOOL is_following_digit(mp_lexer_t *lex) { return unichar_isdigit(lex->chr1); } // TODO UNICODE include unicode characters in definition of identifiers -static bool is_head_of_identifier(mp_lexer_t *lex) { +static MP_BOOL is_head_of_identifier(mp_lexer_t *lex) { return is_letter(lex) || lex->chr0 == '_'; } // TODO UNICODE include unicode characters in definition of identifiers -static bool is_tail_of_identifier(mp_lexer_t *lex) { +static MP_BOOL is_tail_of_identifier(mp_lexer_t *lex) { return is_head_of_identifier(lex) || is_digit(lex); } @@ -280,12 +280,12 @@ static const char *tok_kw[] = { NULL, }; -static void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool first_token) { +static void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, MP_BOOL first_token) { // skip white space and comments - bool had_physical_newline = false; + MP_BOOL had_physical_newline = MP_FALSE; while (!is_end(lex)) { if (is_physical_newline(lex)) { - had_physical_newline = true; + had_physical_newline = MP_TRUE; next_char(lex); } else if (is_whitespace(lex)) { next_char(lex); @@ -369,22 +369,22 @@ static void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs // a string or bytes literal // parse type codes - bool is_raw = false; - bool is_bytes = false; + MP_BOOL is_raw = MP_FALSE; + MP_BOOL is_bytes = MP_FALSE; if (is_char(lex, 'u')) { next_char(lex); } else if (is_char(lex, 'b')) { - is_bytes = true; + is_bytes = MP_TRUE; next_char(lex); if (is_char(lex, 'r')) { - is_raw = true; + is_raw = MP_TRUE; next_char(lex); } } else if (is_char(lex, 'r')) { - is_raw = true; + is_raw = MP_TRUE; next_char(lex); if (is_char(lex, 'b')) { - is_bytes = true; + is_bytes = MP_TRUE; next_char(lex); } } @@ -628,7 +628,7 @@ mp_lexer_t *mp_lexer_new(const char *src_name, void *stream_data, mp_lexer_strea } // preload first token - mp_lexer_next_token_into(lex, &lex->tok_cur, true); + mp_lexer_next_token_into(lex, &lex->tok_cur, MP_TRUE); return lex; } @@ -644,44 +644,44 @@ void mp_lexer_free(mp_lexer_t *lex) { } void mp_lexer_to_next(mp_lexer_t *lex) { - mp_lexer_next_token_into(lex, &lex->tok_cur, false); + mp_lexer_next_token_into(lex, &lex->tok_cur, MP_FALSE); } const mp_token_t *mp_lexer_cur(const mp_lexer_t *lex) { return &lex->tok_cur; } -bool mp_lexer_is_kind(mp_lexer_t *lex, mp_token_kind_t kind) { +MP_BOOL mp_lexer_is_kind(mp_lexer_t *lex, mp_token_kind_t kind) { return lex->tok_cur.kind == kind; } /* -bool mp_lexer_is_str(mp_lexer_t *lex, const char *str) { +MP_BOOL mp_lexer_is_str(mp_lexer_t *lex, const char *str) { return mp_token_is_str(&lex->tok_cur, str); } -bool mp_lexer_opt_kind(mp_lexer_t *lex, mp_token_kind_t kind) { +MP_BOOL mp_lexer_opt_kind(mp_lexer_t *lex, mp_token_kind_t kind) { if (mp_lexer_is_kind(lex, kind)) { mp_lexer_to_next(lex); - return true; + return MP_TRUE; } - return false; + return MP_FALSE; } -bool mp_lexer_opt_str(mp_lexer_t *lex, const char *str) { +MP_BOOL mp_lexer_opt_str(mp_lexer_t *lex, const char *str) { if (mp_lexer_is_str(lex, str)) { mp_lexer_to_next(lex); - return true; + return MP_TRUE; } - return false; + return MP_FALSE; } */ -bool mp_lexer_show_error(mp_lexer_t *lex, const char *msg) { +MP_BOOL mp_lexer_show_error(mp_lexer_t *lex, const char *msg) { return mp_token_show_error(&lex->tok_cur, msg); } -bool mp_lexer_show_error_pythonic(mp_lexer_t *lex, const char *msg) { +MP_BOOL mp_lexer_show_error_pythonic(mp_lexer_t *lex, const char *msg) { printf(" File \"%s\", line %d column %d\n%s\n", lex->tok_cur.src_name, lex->tok_cur.src_line, lex->tok_cur.src_column, msg); - return false; + return MP_FALSE; } diff --git a/py/lexer.h b/py/lexer.h index 3cb48ce9e1..9cc3e70c60 100644 --- a/py/lexer.h +++ b/py/lexer.h @@ -124,20 +124,20 @@ typedef struct _mp_lexer_t mp_lexer_t; void mp_token_show(const mp_token_t *tok); void mp_token_show_error_prefix(const mp_token_t *tok); -bool mp_token_show_error(const mp_token_t *tok, const char *msg); +MP_BOOL mp_token_show_error(const mp_token_t *tok, const char *msg); mp_lexer_t *mp_lexer_new(const char *src_name, void *stream_data, mp_lexer_stream_next_char_t stream_next_char, mp_lexer_stream_close_t stream_close); void mp_lexer_free(mp_lexer_t *lex); void mp_lexer_to_next(mp_lexer_t *lex); const mp_token_t *mp_lexer_cur(const mp_lexer_t *lex); -bool mp_lexer_is_kind(mp_lexer_t *lex, mp_token_kind_t kind); +MP_BOOL mp_lexer_is_kind(mp_lexer_t *lex, mp_token_kind_t kind); /* unused -bool mp_lexer_is_str(mp_lexer_t *lex, const char *str); -bool mp_lexer_opt_kind(mp_lexer_t *lex, mp_token_kind_t kind); -bool mp_lexer_opt_str(mp_lexer_t *lex, const char *str); +MP_BOOL mp_lexer_is_str(mp_lexer_t *lex, const char *str); +MP_BOOL mp_lexer_opt_kind(mp_lexer_t *lex, mp_token_kind_t kind); +MP_BOOL mp_lexer_opt_str(mp_lexer_t *lex, const char *str); */ -bool mp_lexer_show_error(mp_lexer_t *lex, const char *msg); -bool mp_lexer_show_error_pythonic(mp_lexer_t *lex, const char *msg); +MP_BOOL mp_lexer_show_error(mp_lexer_t *lex, const char *msg); +MP_BOOL mp_lexer_show_error_pythonic(mp_lexer_t *lex, const char *msg); // used to import a module; must be implemented for a specific port mp_lexer_t *mp_import_open_file(qstr mod_name); diff --git a/py/lexerunix.c b/py/lexerunix.c index 14c28c16d9..935fed0d32 100644 --- a/py/lexerunix.c +++ b/py/lexerunix.c @@ -7,7 +7,7 @@ #include "lexer.h" typedef struct _str_buf_t { - bool free; // free src_beg when done + MP_BOOL free; // free src_beg when done const char *src_beg; // beginning of source const char *src_cur; // current location in source const char *src_end; // end (exclusive) of source @@ -30,7 +30,7 @@ void str_buf_free(str_buf_t *sb) { } } -mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str) { +mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, MP_BOOL free_str) { str_buf_t *sb = m_new(str_buf_t, 1); sb->free = free_str; sb->src_beg = str; @@ -56,7 +56,7 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) { return NULL; } - return mp_lexer_new_from_str_len(filename, data, size, true); + return mp_lexer_new_from_str_len(filename, data, size, MP_TRUE); } /******************************************************************************/ diff --git a/py/lexerunix.h b/py/lexerunix.h index b422a43062..3054ecd8a4 100644 --- a/py/lexerunix.h +++ b/py/lexerunix.h @@ -1,4 +1,4 @@ -mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str); +mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, MP_BOOL free_str); mp_lexer_t *mp_lexer_new_from_file(const char *filename); void mp_import_set_directory(const char *dir); diff --git a/py/map.c b/py/map.c index 01209c9b74..558599f97e 100644 --- a/py/map.c +++ b/py/map.c @@ -38,8 +38,8 @@ mp_map_t *mp_map_new(mp_map_kind_t kind, int n) { return map; } -mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, bool add_if_not_found) { - bool is_map_mp_obj = (map->kind == MP_MAP_OBJ); +mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, MP_BOOL add_if_not_found) { + MP_BOOL is_map_mp_obj = (map->kind == MP_MAP_OBJ); machine_uint_t hash; if (is_map_mp_obj) { hash = mp_obj_hash(index); @@ -61,7 +61,7 @@ mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, bool add_if_n map->table = m_new0(mp_map_elem_t, map->alloc); for (int i = 0; i < old_alloc; i++) { if (old_table[i].key != NULL) { - mp_map_lookup_helper(map, old_table[i].key, true)->value = old_table[i].value; + mp_map_lookup_helper(map, old_table[i].key, MP_TRUE)->value = old_table[i].value; } } m_del(mp_map_elem_t, old_table, old_alloc); @@ -90,7 +90,7 @@ mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, bool add_if_n } } -mp_map_elem_t* mp_qstr_map_lookup(mp_map_t *map, qstr index, bool add_if_not_found) { +mp_map_elem_t* mp_qstr_map_lookup(mp_map_t *map, qstr index, MP_BOOL add_if_not_found) { mp_obj_t o = (mp_obj_t)(machine_uint_t)index; return mp_map_lookup_helper(map, o, add_if_not_found); } @@ -104,7 +104,7 @@ void mp_set_init(mp_set_t *set, int n) { set->table = m_new0(mp_obj_t, set->alloc); } -mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, bool add_if_not_found) { +mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, MP_BOOL add_if_not_found) { int hash = mp_obj_hash(index); int pos = hash % set->alloc; for (;;) { @@ -121,7 +121,7 @@ mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, bool add_if_not_found) { set->table = m_new(mp_obj_t, set->alloc); for (int i = 0; i < old_alloc; i++) { if (old_table[i] != NULL) { - mp_set_lookup(set, old_table[i], true); + mp_set_lookup(set, old_table[i], MP_TRUE); } } m_del(mp_obj_t, old_table, old_alloc); diff --git a/py/map.h b/py/map.h index f8ca886aa4..31ce39b71c 100644 --- a/py/map.h +++ b/py/map.h @@ -26,8 +26,8 @@ typedef struct _mp_set_t { int get_doubling_prime_greater_or_equal_to(int x); void mp_map_init(mp_map_t *map, mp_map_kind_t kind, int n); mp_map_t *mp_map_new(mp_map_kind_t kind, int n); -mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, bool add_if_not_found); -mp_map_elem_t* mp_qstr_map_lookup(mp_map_t *map, qstr index, bool add_if_not_found); +mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, MP_BOOL add_if_not_found); +mp_map_elem_t* mp_qstr_map_lookup(mp_map_t *map, qstr index, MP_BOOL add_if_not_found); void mp_set_init(mp_set_t *set, int n); -mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, bool add_if_not_found); +mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, MP_BOOL add_if_not_found); diff --git a/py/misc.h b/py/misc.h index 153218ba2f..149ca8a518 100644 --- a/py/misc.h +++ b/py/misc.h @@ -5,10 +5,10 @@ /** types *******************************************************/ -typedef int bool; +typedef int MP_BOOL; enum { - false = 0, - true = 1 + MP_FALSE = 0, + MP_TRUE = 1 }; typedef unsigned char byte; @@ -42,10 +42,10 @@ typedef int unichar; // TODO unichar utf8_get_char(const char *s); char *utf8_next_char(const char *s); -bool unichar_isspace(unichar c); -bool unichar_isalpha(unichar c); -bool unichar_isprint(unichar c); -bool unichar_isdigit(unichar c); +MP_BOOL unichar_isspace(unichar c); +MP_BOOL unichar_isalpha(unichar c); +MP_BOOL unichar_isprint(unichar c); +MP_BOOL unichar_isdigit(unichar c); /** string ******************************************************/ @@ -59,7 +59,7 @@ typedef struct _vstr_t { int alloc; int len; char *buf; - bool had_error; + MP_BOOL had_error; } vstr_t; void vstr_init(vstr_t *vstr); @@ -67,7 +67,7 @@ void vstr_clear(vstr_t *vstr); vstr_t *vstr_new(void); void vstr_free(vstr_t *vstr); void vstr_reset(vstr_t *vstr); -bool vstr_had_error(vstr_t *vstr); +MP_BOOL vstr_had_error(vstr_t *vstr); char *vstr_str(vstr_t *vstr); int vstr_len(vstr_t *vstr); void vstr_hint_size(vstr_t *vstr, int size); diff --git a/py/obj.c b/py/obj.c index 77580e1fee..e28076b2c1 100644 --- a/py/obj.c +++ b/py/obj.c @@ -46,9 +46,9 @@ void mp_obj_print(mp_obj_t o_in) { mp_obj_print_helper(printf_wrapper, NULL, o_in); } -bool mp_obj_is_callable(mp_obj_t o_in) { +MP_BOOL mp_obj_is_callable(mp_obj_t o_in) { if (MP_OBJ_IS_SMALL_INT(o_in)) { - return false; + return MP_FALSE; } else { mp_obj_base_t *o = o_in; return o->type->call_n != NULL; @@ -77,13 +77,13 @@ machine_int_t mp_obj_hash(mp_obj_t o_in) { // "The objects need not have the same type. If both are numbers, they are converted // to a common type. Otherwise, the == and != operators always consider objects of // different types to be unequal." -// note also that False==0 and True==1 are true expressions -bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) { +// note also that False==0 and True==1 are MP_TRUE expressions +MP_BOOL mp_obj_equal(mp_obj_t o1, mp_obj_t o2) { if (o1 == o2) { - return true; + return MP_TRUE; } else if (MP_OBJ_IS_SMALL_INT(o1) || MP_OBJ_IS_SMALL_INT(o2)) { if (MP_OBJ_IS_SMALL_INT(o1) && MP_OBJ_IS_SMALL_INT(o2)) { - return false; + return MP_FALSE; } else { if (MP_OBJ_IS_SMALL_INT(o2)) { mp_obj_t temp = o1; o1 = o2; o2 = temp; @@ -95,25 +95,25 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) { } else if (o2 == mp_const_true) { return val == 1; } else { - return false; + return MP_FALSE; } } } else if (MP_OBJ_IS_TYPE(o1, &str_type) && MP_OBJ_IS_TYPE(o2, &str_type)) { return mp_obj_str_get(o1) == mp_obj_str_get(o2); } else { assert(0); - return false; + return MP_FALSE; } } -bool mp_obj_less(mp_obj_t o1, mp_obj_t o2) { +MP_BOOL mp_obj_less(mp_obj_t o1, mp_obj_t o2) { if (MP_OBJ_IS_SMALL_INT(o1) && MP_OBJ_IS_SMALL_INT(o2)) { mp_small_int_t i1 = MP_OBJ_SMALL_INT_VALUE(o1); mp_small_int_t i2 = MP_OBJ_SMALL_INT_VALUE(o2); return i1 < i2; } else { assert(0); - return false; + return MP_FALSE; } } diff --git a/py/obj.h b/py/obj.h index 88a611ba7b..b8ddb4ea87 100644 --- a/py/obj.h +++ b/py/obj.h @@ -18,12 +18,11 @@ typedef machine_float_t mp_float_t; // Anything that wants to be a Micro Python object must // have mp_obj_base_t as its first member (except NULL and small ints) -typedef struct _mp_obj_base_t mp_obj_base_t; -typedef struct _mp_obj_type_t mp_obj_type_t; - +struct _mp_obj_type_t; struct _mp_obj_base_t { - const mp_obj_type_t *type; + const struct _mp_obj_type_t *type; }; +typedef struct _mp_obj_base_t mp_obj_base_t; // The NULL object is used to indicate the absence of an object // It *cannot* be used when an mp_obj_t is expected, except where explicitly allowed @@ -43,12 +42,13 @@ struct _mp_obj_base_t { #define MP_DECLARE_CONST_FUN_OBJ(obj_name) extern const mp_obj_fun_native_t obj_name -#define MP_DEFINE_CONST_FUN_OBJ_0(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, 0, 0, fun_name} -#define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, 1, 1, fun_name} -#define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, 2, 2, fun_name} -#define MP_DEFINE_CONST_FUN_OBJ_3(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, 3, 3, fun_name} -#define MP_DEFINE_CONST_FUN_OBJ_VAR(obj_name, n_args_min, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, n_args_min, (~((machine_uint_t)0)), fun_name} -#define MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name, n_args_min, n_args_max, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, n_args_min, n_args_max, fun_name} +#define MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, n_args_min, n_args_max, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, n_args_min, n_args_max, (void *)fun_name} +#define MP_DEFINE_CONST_FUN_OBJ_0(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, 0, 0, (mp_fun_0_t)fun_name) +#define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, 1, 1, (mp_fun_1_t)fun_name) +#define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, 2, 2, (mp_fun_2_t)fun_name) +#define MP_DEFINE_CONST_FUN_OBJ_3(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, 3, 3, (mp_fun_3_t)fun_name) +#define MP_DEFINE_CONST_FUN_OBJ_VAR(obj_name, n_args_min, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, n_args_min, (~((machine_uint_t)0)), (mp_fun_var_t)fun_name) +#define MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name, n_args_min, n_args_max, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, n_args_min, n_args_max, (mp_fun_var_t)fun_name) // Type definitions for methods @@ -83,7 +83,7 @@ struct _mp_obj_type_t { mp_fun_1_t getiter; mp_fun_1_t iternext; - const mp_method_t methods[]; + const mp_method_t *methods; /* What we might need to add here: @@ -107,6 +107,7 @@ struct _mp_obj_type_t { __next__ gen-instance */ }; +typedef struct _mp_obj_type_t mp_obj_type_t; // Constant objects, globally accessible @@ -125,7 +126,7 @@ struct _mp_map_t; // General API for objects mp_obj_t mp_obj_new_none(void); -mp_obj_t mp_obj_new_bool(bool value); +mp_obj_t mp_obj_new_bool(MP_BOOL value); mp_obj_t mp_obj_new_cell(mp_obj_t obj); mp_obj_t mp_obj_new_int(machine_int_t value); mp_obj_t mp_obj_new_str(qstr qstr); @@ -161,10 +162,10 @@ const char *mp_obj_get_type_str(mp_obj_t o_in); void mp_obj_print_helper(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in); void mp_obj_print(mp_obj_t o); -bool mp_obj_is_callable(mp_obj_t o_in); +MP_BOOL mp_obj_is_callable(mp_obj_t o_in); machine_int_t mp_obj_hash(mp_obj_t o_in); -bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2); -bool mp_obj_less(mp_obj_t o1, mp_obj_t o2); +MP_BOOL mp_obj_equal(mp_obj_t o1, mp_obj_t o2); +MP_BOOL mp_obj_less(mp_obj_t o1, mp_obj_t o2); machine_int_t mp_obj_get_int(mp_obj_t arg); #if MICROPY_ENABLE_FLOAT diff --git a/py/objbool.c b/py/objbool.c index 77394dab99..b03c56924c 100644 --- a/py/objbool.c +++ b/py/objbool.c @@ -10,7 +10,7 @@ typedef struct _mp_obj_bool_t { mp_obj_base_t base; - bool value; + MP_BOOL value; } mp_obj_bool_t; static void bool_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) { @@ -41,11 +41,11 @@ const mp_obj_type_t bool_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - .methods = {{NULL, NULL},}, + .methods = NULL, }; -static const mp_obj_bool_t false_obj = {{&bool_type}, false}; -static const mp_obj_bool_t true_obj = {{&bool_type}, true}; +static const mp_obj_bool_t false_obj = {{&bool_type}, MP_FALSE}; +static const mp_obj_bool_t true_obj = {{&bool_type}, MP_TRUE}; const mp_obj_t mp_const_false = (mp_obj_t)&false_obj; const mp_obj_t mp_const_true = (mp_obj_t)&true_obj; diff --git a/py/objboundmeth.c b/py/objboundmeth.c index 4e6d2e0103..f4f306ae0a 100644 --- a/py/objboundmeth.c +++ b/py/objboundmeth.c @@ -43,7 +43,7 @@ const mp_obj_type_t bound_meth_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - .methods = {{NULL, NULL},}, + .methods = NULL, }; mp_obj_t mp_obj_new_bound_meth(mp_obj_t self, mp_obj_t meth) { diff --git a/py/objcell.c b/py/objcell.c index 3465f99198..628a289d58 100644 --- a/py/objcell.c +++ b/py/objcell.c @@ -33,7 +33,7 @@ const mp_obj_type_t cell_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - .methods = {{NULL, NULL},}, + .methods = NULL, }; mp_obj_t mp_obj_new_cell(mp_obj_t obj) { diff --git a/py/objclass.c b/py/objclass.c index 536abdf7e3..c2638bc87b 100644 --- a/py/objclass.c +++ b/py/objclass.c @@ -26,7 +26,7 @@ mp_obj_t class_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) { mp_obj_t o = mp_obj_new_instance(self_in); // look for __init__ function - mp_map_elem_t *init_fn = mp_qstr_map_lookup(self->locals, MP_QSTR___init__, false); + mp_map_elem_t *init_fn = mp_qstr_map_lookup(self->locals, MP_QSTR___init__, MP_FALSE); if (init_fn != NULL) { // call __init__ function @@ -70,7 +70,7 @@ const mp_obj_type_t class_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - .methods = {{NULL, NULL},}, + .methods = NULL, }; mp_obj_t mp_obj_new_class(mp_map_t *class_locals) { diff --git a/py/objclosure.c b/py/objclosure.c index 3317eb86f4..347f7a79fa 100644 --- a/py/objclosure.c +++ b/py/objclosure.c @@ -42,7 +42,7 @@ const mp_obj_type_t closure_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - .methods = {{NULL, NULL},}, + .methods = NULL, }; mp_obj_t mp_obj_new_closure(mp_obj_t fun, mp_obj_t closure_tuple) { diff --git a/py/objcomplex.c b/py/objcomplex.c index fc32f96674..9a814980c2 100644 --- a/py/objcomplex.c +++ b/py/objcomplex.c @@ -125,7 +125,7 @@ const mp_obj_type_t complex_type = { complex_binary_op, // binary_op NULL, // getiter NULL, // iternext - .methods = { { NULL, NULL }, }, + .methods = NULL, }; mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag) { diff --git a/py/objdict.c b/py/objdict.c index b3e21aedd2..bac010ce83 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -19,14 +19,14 @@ typedef struct _mp_obj_dict_t { static void dict_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) { mp_obj_dict_t *self = self_in; - bool first = true; + MP_BOOL first = MP_TRUE; print(env, "{"); for (int i = 0; i < self->map.alloc; i++) { if (self->map.table[i].key != NULL) { if (!first) { print(env, ", "); } - first = false; + first = MP_FALSE; mp_obj_print_helper(print, env, self->map.table[i].key); print(env, ": "); mp_obj_print_helper(print, env, self->map.table[i].value); @@ -47,7 +47,7 @@ static mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { case RT_BINARY_OP_SUBSCR: { // dict load - mp_map_elem_t *elem = mp_map_lookup_helper(&o->map, rhs_in, false); + mp_map_elem_t *elem = mp_map_lookup_helper(&o->map, rhs_in, MP_FALSE); if (elem == NULL) { nlr_jump(mp_obj_new_exception_msg(MP_QSTR_KeyError, "")); } else { @@ -67,7 +67,7 @@ const mp_obj_type_t dict_type = { .make_new = dict_make_new, .binary_op = dict_binary_op, .getiter = NULL, - .methods = {{NULL, NULL},}, + .methods = NULL, }; mp_obj_t mp_obj_new_dict(int n_args) { @@ -91,6 +91,6 @@ uint mp_obj_dict_len(mp_obj_t self_in) { mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value) { assert(MP_OBJ_IS_TYPE(self_in, &dict_type)); mp_obj_dict_t *self = self_in; - mp_map_lookup_helper(&self->map, key, true)->value = value; + mp_map_lookup_helper(&self->map, key, MP_TRUE)->value = value; return self_in; } diff --git a/py/objexcept.c b/py/objexcept.c index 22b8c58126..8414fb0f6d 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -45,7 +45,7 @@ const mp_obj_type_t exception_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - .methods = {{NULL, NULL},}, + .methods = NULL, }; mp_obj_t mp_obj_new_exception(qstr id) { diff --git a/py/objfloat.c b/py/objfloat.c index 0250172ad3..1176a1671e 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -83,7 +83,7 @@ const mp_obj_type_t float_type = { .make_new = float_make_new, .unary_op = float_unary_op, .binary_op = float_binary_op, - .methods = { { NULL, NULL }, }, + .methods = NULL, }; mp_obj_t mp_obj_new_float(mp_float_t value) { diff --git a/py/objfun.c b/py/objfun.c index 0db6459a39..4945462817 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -79,9 +79,7 @@ const mp_obj_type_t fun_native_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - .methods = { - {NULL, NULL}, // end-of-list sentinel - }, + .methods = NULL, }; mp_obj_t rt_make_function_0(mp_fun_0_t fun) { @@ -181,9 +179,7 @@ const mp_obj_type_t fun_bc_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - .methods = { - {NULL, NULL}, // end-of-list sentinel - }, + .methods = NULL, }; mp_obj_t mp_obj_new_fun_bc(int n_args, uint n_state, const byte *code) { @@ -295,9 +291,7 @@ static const mp_obj_type_t fun_asm_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - .methods = { - {NULL, NULL}, // end-of-list sentinel - }, + .methods = NULL, }; mp_obj_t mp_obj_new_fun_asm(uint n_args, void *fun) { diff --git a/py/objgenerator.c b/py/objgenerator.c index a91b0d6fc6..7eee3a8fc5 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -46,7 +46,7 @@ const mp_obj_type_t gen_wrap_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - .methods = {{NULL, NULL},}, + .methods = NULL, }; mp_obj_t mp_obj_new_gen_wrap(uint n_locals, uint n_stack, mp_obj_t fun) { @@ -78,7 +78,7 @@ mp_obj_t gen_instance_getiter(mp_obj_t self_in) { mp_obj_t gen_instance_iternext(mp_obj_t self_in) { mp_obj_gen_instance_t *self = self_in; - bool yield = mp_execute_byte_code_2(&self->ip, &self->state[0], &self->sp); + MP_BOOL yield = mp_execute_byte_code_2(&self->ip, &self->state[0], &self->sp); if (yield) { return *self->sp; } else { @@ -101,7 +101,7 @@ const mp_obj_type_t gen_instance_type = { NULL, // binary_op gen_instance_getiter, // getiter gen_instance_iternext, // iternext - .methods = {{NULL, NULL},}, + .methods = NULL, }; // args are in reverse order in the array diff --git a/py/objinstance.c b/py/objinstance.c index 8ef2773fd9..00ae05816d 100644 --- a/py/objinstance.c +++ b/py/objinstance.c @@ -21,7 +21,7 @@ typedef struct _mp_obj_instance_t { type needs to be specified dynamically case O_OBJ: { - py_map_elem_t *qn = py_qstr_map_lookup(o->u_obj.class->u_class.locals, qstr_from_str_static("__qualname__"), false); assert(qn != NULL); + py_map_elem_t *qn = py_qstr_map_lookup(o->u_obj.class->u_class.locals, qstr_from_str_static("__qualname__"), MP_FALSE); assert(qn != NULL); assert(IS_O(qn->value, O_STR)); return qstr_str(((py_obj_base_t*)qn->value)->u_str); } @@ -30,12 +30,12 @@ type needs to be specified dynamically mp_obj_t mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr) { // logic: look in obj members then class locals (TODO check this against CPython) mp_obj_instance_t *self = self_in; - mp_map_elem_t *elem = mp_qstr_map_lookup(self->members, attr, false); + mp_map_elem_t *elem = mp_qstr_map_lookup(self->members, attr, MP_FALSE); if (elem != NULL) { // object member, always treated as a value return elem->value; } - elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, false); + elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, MP_FALSE); if (elem != NULL) { if (mp_obj_is_callable(elem->value)) { // class member is callable so build a bound method @@ -51,14 +51,14 @@ mp_obj_t mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr) { void mp_obj_instance_load_method(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { // logic: look in obj members then class locals (TODO check this against CPython) mp_obj_instance_t *self = self_in; - mp_map_elem_t *elem = mp_qstr_map_lookup(self->members, attr, false); + mp_map_elem_t *elem = mp_qstr_map_lookup(self->members, attr, MP_FALSE); if (elem != NULL) { // object member, always treated as a value dest[1] = elem->value; dest[0] = NULL; return; } - elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, false); + elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, MP_FALSE); if (elem != NULL) { if (mp_obj_is_callable(elem->value)) { // class member is callable so build a bound method @@ -81,11 +81,11 @@ void mp_obj_instance_load_method(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { void mp_obj_instance_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) { // logic: look in class locals (no add) then obj members (add) (TODO check this against CPython) mp_obj_instance_t *self = self_in; - mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, false); + mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, MP_FALSE); if (elem != NULL) { elem->value = value; } else { - mp_qstr_map_lookup(self->members, attr, true)->value = value; + mp_qstr_map_lookup(self->members, attr, MP_TRUE)->value = value; } } @@ -99,7 +99,7 @@ const mp_obj_type_t instance_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - .methods = {{NULL, NULL},}, + .methods = NULL, }; mp_obj_t mp_obj_new_instance(mp_obj_t class) { diff --git a/py/objint.c b/py/objint.c index 8d69c4e7a7..0ba42d10ce 100644 --- a/py/objint.c +++ b/py/objint.c @@ -34,7 +34,7 @@ const mp_obj_type_t int_type = { { &mp_const_type }, "int", .make_new = int_make_new, - .methods = { { NULL, NULL }, }, + .methods = NULL, }; mp_obj_t mp_obj_new_int(machine_int_t value) { diff --git a/py/objlist.c b/py/objlist.c index 02a6b1525b..3e5a15fceb 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -260,6 +260,18 @@ static MP_DEFINE_CONST_FUN_OBJ_2(list_remove_obj, list_remove); static MP_DEFINE_CONST_FUN_OBJ_1(list_reverse_obj, list_reverse); static MP_DEFINE_CONST_FUN_OBJ_2(list_sort_obj, list_sort); +const mp_method_t list_type_methods[] = { + { "append", &list_append_obj }, + { "clear", &list_clear_obj }, + { "copy", &list_copy_obj }, + { "count", &list_count_obj }, + { "index", &list_index_obj }, + { "pop", &list_pop_obj }, + { "remove", &list_remove_obj }, + { "reverse", &list_reverse_obj }, + { "sort", &list_sort_obj }, + { NULL, NULL }, // end-of-list sentinel +}; const mp_obj_type_t list_type = { { &mp_const_type }, "list", @@ -268,19 +280,7 @@ const mp_obj_type_t list_type = { .unary_op = NULL, .binary_op = list_binary_op, .getiter = list_getiter, - .methods = { - { "append", &list_append_obj }, - { "clear", &list_clear_obj }, - { "copy", &list_copy_obj }, - { "count", &list_count_obj }, - { "index", &list_index_obj }, - { "insert", &list_insert_obj }, - { "pop", &list_pop_obj }, - { "remove", &list_remove_obj }, - { "reverse", &list_reverse_obj }, - { "sort", &list_sort_obj }, - { NULL, NULL }, // end-of-list sentinel - }, + .methods = list_type_methods, }; static mp_obj_list_t *list_new(uint n) { @@ -344,7 +344,7 @@ static const mp_obj_type_t list_it_type = { { &mp_const_type }, "list_iterator", .iternext = list_it_iternext, - .methods = { { NULL, NULL }, }, + .methods = NULL, }; mp_obj_t mp_obj_new_list_iterator(mp_obj_list_t *list, int cur) { diff --git a/py/objmodule.c b/py/objmodule.c index 2d6f9555e8..3412573eb4 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -31,7 +31,7 @@ const mp_obj_type_t module_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - .methods = {{NULL, NULL},}, + .methods = NULL, }; mp_obj_t mp_obj_new_module(qstr module_name) { diff --git a/py/objnone.c b/py/objnone.c index 877e61fe5c..173817a4df 100644 --- a/py/objnone.c +++ b/py/objnone.c @@ -18,7 +18,7 @@ const mp_obj_type_t none_type = { { &mp_const_type }, "NoneType", .print = none_print, - .methods = {{NULL, NULL},}, + .methods = NULL, }; static const mp_obj_none_t none_obj = {{&none_type}}; diff --git a/py/objrange.c b/py/objrange.c index 1ef42673f4..5c51656e83 100644 --- a/py/objrange.c +++ b/py/objrange.c @@ -32,7 +32,7 @@ static const mp_obj_type_t range_type = { NULL, // binary_op range_getiter, NULL, // iternext - .methods = {{NULL, NULL},}, + .methods = NULL, }; // range is a class and instances are immutable sequence objects @@ -77,7 +77,7 @@ static const mp_obj_type_t range_it_type = { NULL, // binary_op NULL, // getiter range_it_iternext, - .methods = {{NULL, NULL},}, + .methods = NULL, }; mp_obj_t mp_obj_new_range_iterator(int cur, int stop, int step) { diff --git a/py/objset.c b/py/objset.c index dd9a4d1e1d..6a02ba1202 100644 --- a/py/objset.c +++ b/py/objset.c @@ -17,14 +17,14 @@ typedef struct _mp_obj_set_t { void set_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) { mp_obj_set_t *self = self_in; - bool first = true; + MP_BOOL first = MP_TRUE; print(env, "{"); for (int i = 0; i < self->set.alloc; i++) { if (self->set.table[i] != MP_OBJ_NULL) { if (!first) { print(env, ", "); } - first = false; + first = MP_FALSE; mp_obj_print_helper(print, env, self->set.table[i]); } } @@ -64,7 +64,7 @@ const mp_obj_type_t set_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - .methods = { { NULL, NULL }, }, + .methods = NULL, }; mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items) { @@ -72,7 +72,7 @@ mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items) { o->base.type = &set_type; mp_set_init(&o->set, n_args); for (int i = 0; i < n_args; i++) { - mp_set_lookup(&o->set, items[i], true); + mp_set_lookup(&o->set, items[i], MP_TRUE); } return o; } @@ -80,5 +80,5 @@ mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items) { void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item) { assert(MP_OBJ_IS_TYPE(self_in, &set_type)); mp_obj_set_t *self = self_in; - mp_set_lookup(&self->set, item, true); + mp_set_lookup(&self->set, item, MP_TRUE); } diff --git a/py/objslice.c b/py/objslice.c index da69b92af2..360869a494 100644 --- a/py/objslice.c +++ b/py/objslice.c @@ -30,7 +30,7 @@ const mp_obj_type_t ellipsis_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - .methods = {{NULL, NULL},}, + .methods = NULL, }; static const mp_obj_ellipsis_t ellipsis_obj = {{&ellipsis_type}}; @@ -58,7 +58,7 @@ const mp_obj_type_t slice_type = { { &mp_const_type }, "slice", .print = slice_print, - .methods = { { NULL, NULL }, }, + .methods = NULL, }; // TODO: Make sure to handle "empty" values, which are signified by None in CPython diff --git a/py/objstr.c b/py/objstr.c index db3e0beca0..08e3793916 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -184,17 +184,18 @@ mp_obj_t str_format(int n_args, const mp_obj_t *args) { static MP_DEFINE_CONST_FUN_OBJ_2(str_join_obj, str_join); static MP_DEFINE_CONST_FUN_OBJ_VAR(str_format_obj, 1, str_format); +const mp_method_t str_type_methods[] = { + { "join", &str_join_obj }, + { "format", &str_format_obj }, + { NULL, NULL }, // end-of-list sentinel +}; const mp_obj_type_t str_type = { { &mp_const_type }, "str", .print = str_print, .binary_op = str_binary_op, .getiter = str_getiter, - .methods = { - { "join", &str_join_obj }, - { "format", &str_format_obj }, - { NULL, NULL }, // end-of-list sentinel - }, + .methods = str_type_methods, }; mp_obj_t mp_obj_new_str(qstr qstr) { @@ -235,7 +236,7 @@ static const mp_obj_type_t str_it_type = { { &mp_const_type }, "str_iterator", .iternext = str_it_iternext, - .methods = { { NULL, NULL }, }, + .methods = NULL, }; mp_obj_t mp_obj_new_str_iterator(mp_obj_str_t *str, int cur) { diff --git a/py/objtuple.c b/py/objtuple.c index ceca4200e4..a8ecc3a4f2 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -103,7 +103,7 @@ const mp_obj_type_t tuple_type = { .make_new = tuple_make_new, .binary_op = tuple_binary_op, .getiter = tuple_getiter, - .methods = {{NULL, NULL},}, + .methods = NULL, }; // the zero-length tuple @@ -165,8 +165,14 @@ static mp_obj_t tuple_it_iternext(mp_obj_t self_in) { static const mp_obj_type_t tuple_it_type = { { &mp_const_type }, "tuple_iterator", - .iternext = tuple_it_iternext, - .methods = {{NULL, NULL},}, + NULL, // print + NULL, // make_new + NULL, // call_n + NULL, // unary_op + NULL, // binary_op + NULL, // getiter + tuple_it_iternext, + NULL, // method list }; static mp_obj_t mp_obj_new_tuple_iterator(mp_obj_tuple_t *tuple, int cur) { diff --git a/py/objtype.c b/py/objtype.c index 37d40b38f4..993de040be 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -27,5 +27,5 @@ const mp_obj_type_t mp_const_type = { "type", .print = type_print, .call_n = type_call_n, - .methods = {{NULL, NULL},}, + .methods = NULL, }; diff --git a/py/parse.c b/py/parse.c index d3786ba956..1d3badbc3f 100644 --- a/py/parse.c +++ b/py/parse.c @@ -189,8 +189,8 @@ static void push_result_token(parser_t *parser, const mp_lexer_t *lex) { if (tok->kind == MP_TOKEN_NAME) { pn = mp_parse_node_new_leaf(MP_PARSE_NODE_ID, qstr_from_strn_copy(tok->str, tok->len)); } else if (tok->kind == MP_TOKEN_NUMBER) { - bool dec = false; - bool small_int = true; + MP_BOOL dec = MP_FALSE; + MP_BOOL small_int = MP_TRUE; int int_val = 0; int len = tok->len; const char *str = tok->str; @@ -219,10 +219,10 @@ static void push_result_token(parser_t *parser, const mp_lexer_t *lex) { } else if (base == 16 && 'A' <= str[i] && str[i] <= 'F') { int_val = base * int_val + str[i] - 'A' + 10; } else if (str[i] == '.' || str[i] == 'e' || str[i] == 'E' || str[i] == 'j' || str[i] == 'J') { - dec = true; + dec = MP_TRUE; break; } else { - small_int = false; + small_int = MP_FALSE; break; } } @@ -269,11 +269,11 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { push_rule(parser, rules[top_level_rule], 0); uint n, i; - bool backtrack = false; + MP_BOOL backtrack = MP_FALSE; const rule_t *rule; mp_token_kind_t tok_kind; - bool emit_rule; - bool had_trailing_sep; + MP_BOOL emit_rule; + MP_BOOL had_trailing_sep; for (;;) { next_rule: @@ -298,7 +298,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { if (i > 0 && !backtrack) { goto next_rule; } else { - backtrack = false; + backtrack = MP_FALSE; } for (; i < n - 1; ++i) { switch (rule->arg[i] & RULE_ARG_KIND_MASK) { @@ -322,7 +322,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { push_result_token(parser, lex); mp_lexer_to_next(lex); } else { - backtrack = true; + backtrack = MP_TRUE; goto next_rule; } } else { @@ -338,7 +338,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { if ((rule->arg[i - 1] & RULE_ARG_KIND_MASK) == RULE_ARG_OPT_RULE) { // an optional rule that failed, so continue with next arg push_result_node(parser, MP_PARSE_NODE_NULL); - backtrack = false; + backtrack = MP_FALSE; } else { // a mandatory rule that failed, so propagate backtrack if (i > 1) { @@ -369,7 +369,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { goto syntax_error; } else { // this rule failed, so backtrack - backtrack = true; + backtrack = MP_TRUE; goto next_rule; } } @@ -395,12 +395,12 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { // count number of arguments for the parse_node i = 0; - emit_rule = false; + emit_rule = MP_FALSE; for (int x = 0; x < n; ++x) { if ((rule->arg[x] & RULE_ARG_KIND_MASK) == RULE_ARG_TOK) { tok_kind = rule->arg[x] & RULE_ARG_ARG_MASK; if (tok_kind >= MP_TOKEN_NAME) { - emit_rule = true; + emit_rule = MP_TRUE; } if (tok_kind == MP_TOKEN_NAME) { // only tokens which were names are pushed to stack @@ -414,19 +414,19 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { // always emit these rules, even if they have only 1 argument if (rule->rule_id == RULE_expr_stmt || rule->rule_id == RULE_yield_stmt) { - emit_rule = true; + emit_rule = MP_TRUE; } // never emit these rules if they have only 1 argument // NOTE: can't put atom_paren here because we need it to distinguisg, for example, [a,b] from [(a,b)] // TODO possibly put varargslist_name, varargslist_equal here as well if (rule->rule_id == RULE_else_stmt || rule->rule_id == RULE_testlist_comp_3b || rule->rule_id == RULE_import_as_names_paren || rule->rule_id == RULE_typedargslist_name || rule->rule_id == RULE_typedargslist_colon || rule->rule_id == RULE_typedargslist_equal || rule->rule_id == RULE_dictorsetmaker_colon || rule->rule_id == RULE_classdef_2 || rule->rule_id == RULE_with_item_as || rule->rule_id == RULE_assert_stmt_extra || rule->rule_id == RULE_as_name || rule->rule_id == RULE_raise_stmt_from || rule->rule_id == RULE_vfpdef) { - emit_rule = false; + emit_rule = MP_FALSE; } // always emit these rules, and add an extra blank node at the end (to be used by the compiler to store data) if (rule->rule_id == RULE_funcdef || rule->rule_id == RULE_classdef || rule->rule_id == RULE_comp_for || rule->rule_id == RULE_lambdef || rule->rule_id == RULE_lambdef_nocond) { - emit_rule = true; + emit_rule = MP_TRUE; push_result_node(parser, MP_PARSE_NODE_NULL); i += 1; } @@ -465,14 +465,14 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { // n=3 is: item (sep item)* [sep] if (backtrack) { list_backtrack: - had_trailing_sep = false; + had_trailing_sep = MP_FALSE; if (n == 2) { if (i == 1) { // fail on item, first time round; propagate backtrack goto next_rule; } else { // fail on item, in later rounds; finish with this rule - backtrack = false; + backtrack = MP_FALSE; } } else { if (i == 1) { @@ -482,15 +482,15 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { // fail on item, in later rounds; have eaten tokens so can't backtrack if (n == 3) { // list allows trailing separator; finish parsing list - had_trailing_sep = true; - backtrack = false; + had_trailing_sep = MP_TRUE; + backtrack = MP_FALSE; } else { // list doesn't allowing trailing separator; fail goto syntax_error; } } else { // fail on separator; finish parsing list - backtrack = false; + backtrack = MP_FALSE; } } } else { @@ -510,7 +510,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { } else { // couldn't get element of list i += 1; - backtrack = true; + backtrack = MP_TRUE; goto list_backtrack; } break; diff --git a/py/repl.c b/py/repl.c index 4241ef0e4c..2127a28dfb 100644 --- a/py/repl.c +++ b/py/repl.c @@ -1,17 +1,17 @@ #include "misc.h" #include "repl.h" -bool str_startswith_word(const char *str, const char *head) { +MP_BOOL str_startswith_word(const char *str, const char *head) { int i; for (i = 0; str[i] && head[i]; i++) { if (str[i] != head[i]) { - return false; + return MP_FALSE; } } return head[i] == '\0' && (str[i] == '\0' || !unichar_isalpha(str[i])); } -bool mp_repl_is_compound_stmt(const char *line) { +MP_BOOL mp_repl_is_compound_stmt(const char *line) { // compound if line starts with a certain keyword if ( str_startswith_word(line, "if") @@ -23,7 +23,7 @@ bool mp_repl_is_compound_stmt(const char *line) { || str_startswith_word(line, "class") || str_startswith_word(line, "@") ) { - return true; + return MP_TRUE; } // also "compound" if unmatched open bracket diff --git a/py/repl.h b/py/repl.h index 02fe523ed4..db082f07ac 100644 --- a/py/repl.h +++ b/py/repl.h @@ -1 +1 @@ -bool mp_repl_is_compound_stmt(const char *line); +MP_BOOL mp_repl_is_compound_stmt(const char *line); diff --git a/py/runtime.c b/py/runtime.c index 197c08b55a..86e297d7bd 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -45,7 +45,7 @@ typedef struct _mp_code_t { int n_args; int n_locals; int n_stack; - bool is_generator; + MP_BOOL is_generator; union { struct { byte *code; @@ -70,60 +70,60 @@ FILE *fp_write_code = NULL; void rt_init(void) { // locals = globals for outer module (see Objects/frameobject.c/PyFrame_New()) map_locals = map_globals = mp_map_new(MP_MAP_QSTR, 1); - mp_qstr_map_lookup(map_globals, MP_QSTR___name__, true)->value = mp_obj_new_str(MP_QSTR___main__); + mp_qstr_map_lookup(map_globals, MP_QSTR___name__, MP_TRUE)->value = mp_obj_new_str(MP_QSTR___main__); // init built-in hash table mp_map_init(&map_builtins, MP_MAP_QSTR, 3); // built-in exceptions (TODO, make these proper classes) - mp_qstr_map_lookup(&map_builtins, MP_QSTR_AttributeError, true)->value = mp_obj_new_exception(MP_QSTR_AttributeError); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_IndexError, true)->value = mp_obj_new_exception(MP_QSTR_IndexError); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_KeyError, true)->value = mp_obj_new_exception(MP_QSTR_KeyError); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_NameError, true)->value = mp_obj_new_exception(MP_QSTR_NameError); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_TypeError, true)->value = mp_obj_new_exception(MP_QSTR_TypeError); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_SyntaxError, true)->value = mp_obj_new_exception(MP_QSTR_SyntaxError); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_ValueError, true)->value = mp_obj_new_exception(MP_QSTR_ValueError); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_AttributeError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_AttributeError); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_IndexError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_IndexError); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_KeyError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_KeyError); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_NameError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_NameError); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_TypeError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_TypeError); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_SyntaxError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_SyntaxError); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_ValueError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_ValueError); // built-in objects - mp_qstr_map_lookup(&map_builtins, MP_QSTR_Ellipsis, true)->value = mp_const_ellipsis; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_Ellipsis, MP_TRUE)->value = mp_const_ellipsis; // built-in core functions - mp_qstr_map_lookup(&map_builtins, MP_QSTR___build_class__, true)->value = rt_make_function_2(mp_builtin___build_class__); - mp_qstr_map_lookup(&map_builtins, MP_QSTR___repl_print__, true)->value = rt_make_function_1(mp_builtin___repl_print__); + mp_qstr_map_lookup(&map_builtins, MP_QSTR___build_class__, MP_TRUE)->value = rt_make_function_2(mp_builtin___build_class__); + mp_qstr_map_lookup(&map_builtins, MP_QSTR___repl_print__, MP_TRUE)->value = rt_make_function_1(mp_builtin___repl_print__); // built-in types - mp_qstr_map_lookup(&map_builtins, MP_QSTR_bool, true)->value = (mp_obj_t)&bool_type; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_bool, MP_TRUE)->value = (mp_obj_t)&bool_type; #if MICROPY_ENABLE_FLOAT - mp_qstr_map_lookup(&map_builtins, MP_QSTR_complex, true)->value = (mp_obj_t)&complex_type; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_complex, MP_TRUE)->value = (mp_obj_t)&complex_type; #endif - mp_qstr_map_lookup(&map_builtins, MP_QSTR_dict, true)->value = (mp_obj_t)&dict_type; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_dict, MP_TRUE)->value = (mp_obj_t)&dict_type; #if MICROPY_ENABLE_FLOAT - mp_qstr_map_lookup(&map_builtins, MP_QSTR_float, true)->value = (mp_obj_t)&float_type; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_float, MP_TRUE)->value = (mp_obj_t)&float_type; #endif - mp_qstr_map_lookup(&map_builtins, MP_QSTR_int, true)->value = (mp_obj_t)&int_type; - mp_qstr_map_lookup(&map_builtins, MP_QSTR_list, true)->value = (mp_obj_t)&list_type; - mp_qstr_map_lookup(&map_builtins, MP_QSTR_set, true)->value = (mp_obj_t)&set_type; - mp_qstr_map_lookup(&map_builtins, MP_QSTR_tuple, true)->value = (mp_obj_t)&tuple_type; - mp_qstr_map_lookup(&map_builtins, MP_QSTR_type, true)->value = (mp_obj_t)&mp_builtin_type_obj; // TODO + mp_qstr_map_lookup(&map_builtins, MP_QSTR_int, MP_TRUE)->value = (mp_obj_t)&int_type; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_list, MP_TRUE)->value = (mp_obj_t)&list_type; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_set, MP_TRUE)->value = (mp_obj_t)&set_type; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_tuple, MP_TRUE)->value = (mp_obj_t)&tuple_type; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_type, MP_TRUE)->value = (mp_obj_t)&mp_builtin_type_obj; // TODO // built-in user functions; TODO covert all to &mp_builtin_xxx's - mp_qstr_map_lookup(&map_builtins, MP_QSTR_abs, true)->value = rt_make_function_1(mp_builtin_abs); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_all, true)->value = rt_make_function_1(mp_builtin_all); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_any, true)->value = rt_make_function_1(mp_builtin_any); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_callable, true)->value = rt_make_function_1(mp_builtin_callable); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_chr, true)->value = rt_make_function_1(mp_builtin_chr); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_divmod, true)->value = rt_make_function_2(mp_builtin_divmod); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_hash, true)->value = (mp_obj_t)&mp_builtin_hash_obj; - mp_qstr_map_lookup(&map_builtins, MP_QSTR_iter, true)->value = (mp_obj_t)&mp_builtin_iter_obj; - mp_qstr_map_lookup(&map_builtins, MP_QSTR_len, true)->value = rt_make_function_1(mp_builtin_len); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_max, true)->value = rt_make_function_var(1, mp_builtin_max); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_min, true)->value = rt_make_function_var(1, mp_builtin_min); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_next, true)->value = (mp_obj_t)&mp_builtin_next_obj; - mp_qstr_map_lookup(&map_builtins, MP_QSTR_ord, true)->value = rt_make_function_1(mp_builtin_ord); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_pow, true)->value = rt_make_function_var(2, mp_builtin_pow); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_print, true)->value = rt_make_function_var(0, mp_builtin_print); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_range, true)->value = rt_make_function_var(1, mp_builtin_range); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_sum, true)->value = rt_make_function_var(1, mp_builtin_sum); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_abs, MP_TRUE)->value = rt_make_function_1(mp_builtin_abs); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_all, MP_TRUE)->value = rt_make_function_1(mp_builtin_all); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_any, MP_TRUE)->value = rt_make_function_1(mp_builtin_any); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_callable, MP_TRUE)->value = rt_make_function_1(mp_builtin_callable); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_chr, MP_TRUE)->value = rt_make_function_1(mp_builtin_chr); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_divmod, MP_TRUE)->value = rt_make_function_2(mp_builtin_divmod); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_hash, MP_TRUE)->value = (mp_obj_t)&mp_builtin_hash_obj; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_iter, MP_TRUE)->value = (mp_obj_t)&mp_builtin_iter_obj; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_len, MP_TRUE)->value = rt_make_function_1(mp_builtin_len); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_max, MP_TRUE)->value = rt_make_function_var(1, mp_builtin_max); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_min, MP_TRUE)->value = rt_make_function_var(1, mp_builtin_min); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_next, MP_TRUE)->value = (mp_obj_t)&mp_builtin_next_obj; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_ord, MP_TRUE)->value = rt_make_function_1(mp_builtin_ord); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_pow, MP_TRUE)->value = rt_make_function_var(2, mp_builtin_pow); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_print, MP_TRUE)->value = rt_make_function_var(0, mp_builtin_print); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_range, MP_TRUE)->value = rt_make_function_var(1, mp_builtin_range); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_sum, MP_TRUE)->value = rt_make_function_var(1, mp_builtin_sum); next_unique_code_id = 1; // 0 indicates "no code" unique_codes = NULL; @@ -154,7 +154,7 @@ static void alloc_unique_codes(void) { } } -void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, int n_locals, int n_stack, bool is_generator) { +void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, int n_locals, int n_stack, MP_BOOL is_generator) { alloc_unique_codes(); assert(1 <= unique_code_id && unique_code_id < next_unique_code_id); @@ -197,7 +197,7 @@ void rt_assign_native_code(int unique_code_id, void *fun, uint len, int n_args) unique_codes[unique_code_id].n_args = n_args; unique_codes[unique_code_id].n_locals = 0; unique_codes[unique_code_id].n_stack = 0; - unique_codes[unique_code_id].is_generator = false; + unique_codes[unique_code_id].is_generator = MP_FALSE; unique_codes[unique_code_id].u_native.fun = fun; //printf("native code: %d bytes\n", len); @@ -230,7 +230,7 @@ void rt_assign_inline_asm_code(int unique_code_id, void *fun, uint len, int n_ar unique_codes[unique_code_id].n_args = n_args; unique_codes[unique_code_id].n_locals = 0; unique_codes[unique_code_id].n_stack = 0; - unique_codes[unique_code_id].is_generator = false; + unique_codes[unique_code_id].is_generator = MP_FALSE; unique_codes[unique_code_id].u_inline_asm.fun = fun; #ifdef DEBUG_PRINT @@ -252,8 +252,8 @@ void rt_assign_inline_asm_code(int unique_code_id, void *fun, uint len, int n_ar #endif } -static bool fit_small_int(mp_small_int_t o) { - return true; +static MP_BOOL fit_small_int(mp_small_int_t o) { + return MP_TRUE; } int rt_is_true(mp_obj_t arg) { @@ -290,10 +290,10 @@ mp_obj_t rt_load_const_dec(qstr qstr) { const char *s = qstr_str(qstr); int in = PARSE_DEC_IN_INTG; mp_float_t dec_val = 0; - bool exp_neg = false; + MP_BOOL exp_neg = MP_FALSE; int exp_val = 0; int exp_extra = 0; - bool imag = false; + MP_BOOL imag = MP_FALSE; for (; *s; s++) { int dig = *s; if ('0' <= dig && dig <= '9') { @@ -314,11 +314,11 @@ mp_obj_t rt_load_const_dec(qstr qstr) { s++; } else if (s[1] == '-') { s++; - exp_neg = true; + exp_neg = MP_TRUE; } } else if (dig == 'J' || dig == 'j') { s++; - imag = true; + imag = MP_TRUE; break; } else { // unknown character @@ -356,11 +356,11 @@ mp_obj_t rt_load_const_str(qstr qstr) { mp_obj_t rt_load_name(qstr qstr) { // logic: search locals, globals, builtins DEBUG_OP_printf("load name %s\n", qstr_str(qstr)); - mp_map_elem_t *elem = mp_qstr_map_lookup(map_locals, qstr, false); + mp_map_elem_t *elem = mp_qstr_map_lookup(map_locals, qstr, MP_FALSE); if (elem == NULL) { - elem = mp_qstr_map_lookup(map_globals, qstr, false); + elem = mp_qstr_map_lookup(map_globals, qstr, MP_FALSE); if (elem == NULL) { - elem = mp_qstr_map_lookup(&map_builtins, qstr, false); + elem = mp_qstr_map_lookup(&map_builtins, qstr, MP_FALSE); if (elem == NULL) { nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_NameError, "name '%s' is not defined", qstr_str(qstr))); } @@ -372,9 +372,9 @@ mp_obj_t rt_load_name(qstr qstr) { mp_obj_t rt_load_global(qstr qstr) { // logic: search globals, builtins DEBUG_OP_printf("load global %s\n", qstr_str(qstr)); - mp_map_elem_t *elem = mp_qstr_map_lookup(map_globals, qstr, false); + mp_map_elem_t *elem = mp_qstr_map_lookup(map_globals, qstr, MP_FALSE); if (elem == NULL) { - elem = mp_qstr_map_lookup(&map_builtins, qstr, false); + elem = mp_qstr_map_lookup(&map_builtins, qstr, MP_FALSE); if (elem == NULL) { nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_NameError, "name '%s' is not defined", qstr_str(qstr))); } @@ -384,7 +384,7 @@ mp_obj_t rt_load_global(qstr qstr) { mp_obj_t rt_load_build_class(void) { DEBUG_OP_printf("load_build_class\n"); - mp_map_elem_t *elem = mp_qstr_map_lookup(&map_builtins, MP_QSTR___build_class__, false); + mp_map_elem_t *elem = mp_qstr_map_lookup(&map_builtins, MP_QSTR___build_class__, MP_FALSE); if (elem == NULL) { nlr_jump(mp_obj_new_exception_msg(MP_QSTR_NameError, "name '__build_class__' is not defined")); } @@ -401,12 +401,12 @@ void rt_set_cell(mp_obj_t cell, mp_obj_t val) { void rt_store_name(qstr qstr, mp_obj_t obj) { DEBUG_OP_printf("store name %s <- %p\n", qstr_str(qstr), obj); - mp_qstr_map_lookup(map_locals, qstr, true)->value = obj; + mp_qstr_map_lookup(map_locals, qstr, MP_TRUE)->value = obj; } void rt_store_global(qstr qstr, mp_obj_t obj) { DEBUG_OP_printf("store global %s <- %p\n", qstr_str(qstr), obj); - mp_qstr_map_lookup(map_globals, qstr, true)->value = obj; + mp_qstr_map_lookup(map_globals, qstr, MP_TRUE)->value = obj; } mp_obj_t rt_unary_op(int op, mp_obj_t arg) { @@ -750,7 +750,7 @@ mp_obj_t rt_store_map(mp_obj_t map, mp_obj_t key, mp_obj_t value) { mp_obj_t rt_load_attr(mp_obj_t base, qstr attr) { DEBUG_OP_printf("load attr %s\n", qstr_str(attr)); if (MP_OBJ_IS_TYPE(base, &class_type)) { - mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_class_get_locals(base), attr, false); + mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_class_get_locals(base), attr, MP_FALSE); if (elem == NULL) { // TODO what about generic method lookup? goto no_attr; @@ -760,7 +760,7 @@ mp_obj_t rt_load_attr(mp_obj_t base, qstr attr) { return mp_obj_instance_load_attr(base, attr); } else if (MP_OBJ_IS_TYPE(base, &module_type)) { DEBUG_OP_printf("lookup module map %p\n", mp_obj_module_get_globals(base)); - mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_module_get_globals(base), attr, false); + mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_module_get_globals(base), attr, MP_FALSE); if (elem == NULL) { // TODO what about generic method lookup? goto no_attr; @@ -769,10 +769,12 @@ mp_obj_t rt_load_attr(mp_obj_t base, qstr attr) { } else if (MP_OBJ_IS_OBJ(base)) { // generic method lookup mp_obj_base_t *o = base; - const mp_method_t *meth = &o->type->methods[0]; - for (; meth->name != NULL; meth++) { - if (strcmp(meth->name, qstr_str(attr)) == 0) { - return mp_obj_new_bound_meth(base, (mp_obj_t)meth->fun); + const mp_method_t *meth = o->type->methods; + if (meth != NULL) { + for (; meth->name != NULL; meth++) { + if (strcmp(meth->name, qstr_str(attr)) == 0) { + return mp_obj_new_bound_meth(base, (mp_obj_t)meth->fun); + } } } } @@ -793,12 +795,14 @@ void rt_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) { } else if (MP_OBJ_IS_OBJ(base)) { // generic method lookup mp_obj_base_t *o = base; - const mp_method_t *meth = &o->type->methods[0]; - for (; meth->name != NULL; meth++) { - if (strcmp(meth->name, qstr_str(attr)) == 0) { - dest[1] = (mp_obj_t)meth->fun; - dest[0] = base; - return; + const mp_method_t *meth = o->type->methods; + if (meth != NULL) { + for (; meth->name != NULL; meth++) { + if (strcmp(meth->name, qstr_str(attr)) == 0) { + dest[1] = (mp_obj_t)meth->fun; + dest[0] = base; + return; + } } } } @@ -813,13 +817,13 @@ void rt_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) { if (MP_OBJ_IS_TYPE(base, &class_type)) { // TODO CPython allows STORE_ATTR to a class, but is this the correct implementation? mp_map_t *locals = mp_obj_class_get_locals(base); - mp_qstr_map_lookup(locals, attr, true)->value = value; + mp_qstr_map_lookup(locals, attr, MP_TRUE)->value = value; } else if (MP_OBJ_IS_TYPE(base, &instance_type)) { mp_obj_instance_store_attr(base, attr, value); } else if (MP_OBJ_IS_TYPE(base, &module_type)) { // TODO CPython allows STORE_ATTR to a module, but is this the correct implementation? mp_map_t *globals = mp_obj_module_get_globals(base); - mp_qstr_map_lookup(globals, attr, true)->value = value; + mp_qstr_map_lookup(globals, attr, MP_TRUE)->value = value; } else { nlr_jump(mp_obj_new_exception_msg_2_args(MP_QSTR_AttributeError, "'%s' object has no attribute '%s'", mp_obj_get_type_str(base), qstr_str(attr))); } diff --git a/py/runtime0.h b/py/runtime0.h index 97dbe5ddbc..19c2f63edc 100644 --- a/py/runtime0.h +++ b/py/runtime0.h @@ -82,6 +82,6 @@ extern void *const rt_fun_table[RT_F_NUMBER_OF]; void rt_init(void); void rt_deinit(void); int rt_get_unique_code_id(void); -void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, int n_locals, int n_stack, bool is_generator); +void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, int n_locals, int n_stack, MP_BOOL is_generator); void rt_assign_native_code(int unique_code_id, void *f, uint len, int n_args); void rt_assign_inline_asm_code(int unique_code_id, void *f, uint len, int n_args); diff --git a/py/scope.c b/py/scope.c index 5d97393ae3..110e63afa5 100644 --- a/py/scope.c +++ b/py/scope.c @@ -58,10 +58,10 @@ scope_t *scope_new(scope_kind_t kind, mp_parse_node_t pn, uint unique_code_id, u return scope; } -id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, bool *added) { +id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, MP_BOOL *added) { for (int i = 0; i < scope->id_info_len; i++) { if (scope->id_info[i].qstr == qstr) { - *added = false; + *added = MP_FALSE; return &scope->id_info[i]; } } @@ -100,11 +100,11 @@ id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, bool *added) { id_info = &scope->id_info[scope->id_info_len++]; } - id_info->param = false; + id_info->param = MP_FALSE; id_info->kind = 0; id_info->qstr = qstr; id_info->local_num = 0; - *added = true; + *added = MP_TRUE; return id_info; } @@ -155,7 +155,7 @@ void scope_close_over_in_parents(scope_t *scope, qstr qstr) { } if (id == NULL) { // variable not declared in this scope, so declare it as free and keep searching parents - bool added; + MP_BOOL added; id = scope_find_or_add_id(s, qstr, &added); assert(added); id->kind = ID_INFO_KIND_FREE; @@ -178,7 +178,7 @@ void scope_declare_global(scope_t *scope, qstr qstr) { printf("SyntaxError?: can't declare global in outer code\n"); return; } - bool added; + MP_BOOL added; id_info_t *id_info = scope_find_or_add_id(scope, qstr, &added); if (!added) { printf("SyntaxError?: identifier already declared something\n"); @@ -198,7 +198,7 @@ void scope_declare_nonlocal(scope_t *scope, qstr qstr) { printf("SyntaxError?: can't declare nonlocal in outer code\n"); return; } - bool added; + MP_BOOL added; id_info_t *id_info = scope_find_or_add_id(scope, qstr, &added); if (!added) { printf("SyntaxError?: identifier already declared something\n"); diff --git a/py/scope.h b/py/scope.h index 761a4d7119..8cdcacaaf8 100644 --- a/py/scope.h +++ b/py/scope.h @@ -8,7 +8,7 @@ enum { typedef struct _id_info_t { // TODO compress this info to make structure smaller in memory - bool param; + MP_BOOL param; int kind; qstr qstr; @@ -55,7 +55,7 @@ typedef struct _scope_t { } scope_t; scope_t *scope_new(scope_kind_t kind, mp_parse_node_t pn, uint unique_code_id, uint emit_options); -id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, bool *added); +id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, MP_BOOL *added); id_info_t *scope_find(scope_t *scope, qstr qstr); id_info_t *scope_find_global(scope_t *scope, qstr qstr); id_info_t *scope_find_local_in_parent(scope_t *scope, qstr qstr); diff --git a/py/unicode.c b/py/unicode.c index 58c860a0e4..3450618853 100644 --- a/py/unicode.c +++ b/py/unicode.c @@ -46,32 +46,32 @@ char *utf8_next_char(const char *s) { return (char*)(s + 1); } -bool unichar_isspace(unichar c) { +MP_BOOL unichar_isspace(unichar c) { return c < 128 && (attr[c] & FL_SPACE) != 0; } -bool unichar_isalpha(unichar c) { +MP_BOOL unichar_isalpha(unichar c) { return c < 128 && (attr[c] & FL_ALPHA) != 0; } -bool unichar_isprint(unichar c) { +MP_BOOL unichar_isprint(unichar c) { return c < 128 && (attr[c] & FL_PRINT) != 0; } -bool unichar_isdigit(unichar c) { +MP_BOOL unichar_isdigit(unichar c) { return c < 128 && (attr[c] & FL_DIGIT) != 0; } /* -bool char_is_alpha_or_digit(unichar c) { +MP_BOOL char_is_alpha_or_digit(unichar c) { return c < 128 && (attr[c] & (FL_ALPHA | FL_DIGIT)) != 0; } -bool char_is_upper(unichar c) { +MP_BOOL char_is_upper(unichar c) { return c < 128 && (attr[c] & FL_UPPER) != 0; } -bool char_is_lower(unichar c) { +MP_BOOL char_is_lower(unichar c) { return c < 128 && (attr[c] & FL_LOWER) != 0; } */ diff --git a/py/vm.c b/py/vm.c index 8e7ef7485b..02f3add75b 100644 --- a/py/vm.c +++ b/py/vm.c @@ -65,7 +65,7 @@ mp_obj_t mp_execute_byte_code(const byte *code, const mp_obj_t *args, uint n_arg // fastn has items in normal order // sp points to top of stack which grows down -bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **sp_in_out) { +MP_BOOL mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **sp_in_out) { // careful: be sure to declare volatile any variables read in the exception handler (written is ok, I think) const byte *ip = *ip_in_out; @@ -472,7 +472,7 @@ bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t ** nlr_pop(); *sp_in_out = sp; assert(exc_sp == &exc_stack[0] - 1); - return false; + return MP_FALSE; case MP_BC_YIELD_VALUE: nlr_pop(); @@ -481,7 +481,7 @@ bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t ** fastn[1] = fast1; fastn[2] = fast2; *sp_in_out = sp; - return true; + return MP_TRUE; case MP_BC_IMPORT_NAME: DECODE_QSTR; @@ -499,7 +499,7 @@ bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t ** printf("code %p, byte code 0x%02x not implemented\n", ip, op); assert(0); nlr_pop(); - return false; + return MP_FALSE; } } diff --git a/py/vstr.c b/py/vstr.c index 80841b24ca..76232cc100 100644 --- a/py/vstr.c +++ b/py/vstr.c @@ -11,11 +11,11 @@ void vstr_init(vstr_t *vstr) { vstr->len = 0; vstr->buf = m_new(char, vstr->alloc); if (vstr->buf == NULL) { - vstr->had_error = true; + vstr->had_error = MP_TRUE; return; } vstr->buf[0] = 0; - vstr->had_error = false; + vstr->had_error = MP_FALSE; } void vstr_clear(vstr_t *vstr) { @@ -42,10 +42,10 @@ void vstr_free(vstr_t *vstr) { void vstr_reset(vstr_t *vstr) { vstr->len = 0; vstr->buf[0] = 0; - vstr->had_error = false; + vstr->had_error = MP_FALSE; } -bool vstr_had_error(vstr_t *vstr) { +MP_BOOL vstr_had_error(vstr_t *vstr) { return vstr->had_error; } @@ -63,23 +63,23 @@ int vstr_len(vstr_t *vstr) { return vstr->len; } -bool vstr_ensure_extra(vstr_t *vstr, int size) { +MP_BOOL vstr_ensure_extra(vstr_t *vstr, int size) { if (vstr->len + size + 1 > vstr->alloc) { int new_alloc = ROUND_ALLOC((vstr->len + size + 1) * 2); char *new_buf = m_renew(char, vstr->buf, vstr->alloc, new_alloc); if (new_buf == NULL) { - vstr->had_error = true; - return false; + vstr->had_error = MP_TRUE; + return MP_FALSE; } vstr->alloc = new_alloc; vstr->buf = new_buf; } - return true; + return MP_TRUE; } void vstr_hint_size(vstr_t *vstr, int size) { // it's not an error if we fail to allocate for the size hint - bool er = vstr->had_error; + MP_BOOL er = vstr->had_error; vstr_ensure_extra(vstr, size); vstr->had_error = er; } diff --git a/stm/audio.c b/stm/audio.c index 34adefbcd6..829bd6dfde 100644 --- a/stm/audio.c +++ b/stm/audio.c @@ -22,7 +22,7 @@ int sample_buf_in; int sample_buf_out; byte sample_buf[SAMPLE_BUF_SIZE]; -bool audio_is_full(void) { +MP_BOOL audio_is_full(void) { return ((sample_buf_in + 1) % SAMPLE_BUF_SIZE) == sample_buf_out; } diff --git a/stm/cc3k/pybcc3k.c b/stm/cc3k/pybcc3k.c index 9b7113869d..aa83d4a277 100644 --- a/stm/cc3k/pybcc3k.c +++ b/stm/cc3k/pybcc3k.c @@ -165,11 +165,11 @@ void pyb_cc3000_spi_init(void) { /* // WLAN CS, EN and WALN IRQ Configuration - jshSetPinStateIsManual(WLAN_CS_PIN, false); + jshSetPinStateIsManual(WLAN_CS_PIN, MP_FALSE); jshPinOutput(WLAN_CS_PIN, 1); // de-assert CS - jshSetPinStateIsManual(WLAN_EN_PIN, false); + jshSetPinStateIsManual(WLAN_EN_PIN, MP_FALSE); jshPinOutput(WLAN_EN_PIN, 0); // disable WLAN - jshSetPinStateIsManual(WLAN_IRQ_PIN, true); + jshSetPinStateIsManual(WLAN_IRQ_PIN, MP_TRUE); jshPinSetState(WLAN_IRQ_PIN, JSHPINSTATE_GPIO_IN_PULLUP); // flip into read mode with pullup */ // configure wlan CS and EN pins diff --git a/stm/i2c.c b/stm/i2c.c index 9e25ff9839..6456a15793 100644 --- a/stm/i2c.c +++ b/stm/i2c.c @@ -20,9 +20,9 @@ typedef enum { I2C_STATE_READ = 2, } i2c_state_t; -// set to true if the port has already been initialized -bool i2c1_port_initialized = false; -bool i2c2_port_initialized = false; +// set to MP_TRUE if the port has already been initialized +MP_BOOL i2c1_port_initialized = MP_FALSE; +MP_BOOL i2c2_port_initialized = MP_FALSE; static I2C_TypeDef * _i2c_port_addr(pyb_i2c_t i2c_port) { if (i2c_port == PYB_I2C_1) { @@ -37,17 +37,17 @@ static I2C_TypeDef * _i2c_port_addr(pyb_i2c_t i2c_port) { // todo - perhaps there should be some global resource management for gpio // this function would fail if the i2c pins have already been defined for // use by another python object -// as it is, this always returns true (unless i2c_port is invalid) -static bool _i2c_init(pyb_i2c_t i2c_port) { +// as it is, this always returns MP_TRUE (unless i2c_port is invalid) +static MP_BOOL _i2c_init(pyb_i2c_t i2c_port) { GPIO_InitTypeDef GPIO_InitStructure; I2C_TypeDef *i2c = _i2c_port_addr(i2c_port); if (i2c == NULL) - return false; + return MP_FALSE; if (i2c_port == PYB_I2C_1) { - if (i2c1_port_initialized == true) { - return true; + if (i2c1_port_initialized == MP_TRUE) { + return MP_TRUE; } RCC->APB1ENR |= RCC_APB1ENR_I2C1EN; // enable I2C1 @@ -64,12 +64,12 @@ static bool _i2c_init(pyb_i2c_t i2c_port) { GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_I2C1); - i2c1_port_initialized = true; + i2c1_port_initialized = MP_TRUE; } if (i2c_port == PYB_I2C_2) { - if (i2c2_port_initialized == true) { - return true; + if (i2c2_port_initialized == MP_TRUE) { + return MP_TRUE; } RCC->APB1ENR |= RCC_APB1ENR_I2C2EN; // enable I2C2 @@ -85,7 +85,7 @@ static bool _i2c_init(pyb_i2c_t i2c_port) { GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_I2C2); GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_I2C2); - i2c2_port_initialized = true; + i2c2_port_initialized = MP_TRUE; } // get clock speeds @@ -108,7 +108,7 @@ static bool _i2c_init(pyb_i2c_t i2c_port) { // enable the I2C peripheral i2c->CR1 |= I2C_CR1_PE; - return true; + return MP_TRUE; } static uint32_t _i2c_get_sr(pyb_i2c_t i2c_port) { @@ -121,9 +121,9 @@ static uint32_t _i2c_get_sr(pyb_i2c_t i2c_port) { return (sr2 << 16) | sr1; } -static bool _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) { +static MP_BOOL _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) { I2C_TypeDef *i2c = _i2c_port_addr(i2c_port); - if (i2c == NULL) return false; + if (i2c == NULL) return MP_FALSE; // send start condition i2c->CR1 |= I2C_CR1_START; @@ -133,7 +133,7 @@ static bool _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) { while ((_i2c_get_sr(i2c_port) & 0x00030001) != 0x00030001) { if (--timeout == 0) { //printf("timeout in _i2c_restart\n"); - return false; + return MP_FALSE; } } @@ -145,7 +145,7 @@ static bool _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) { while ((_i2c_get_sr(i2c_port) & 0x00070082) != 0x00070082) { if (--timeout == 0) { //printf("timeout in _i2c_restart write\n"); - return false; + return MP_FALSE; } } } else { @@ -156,16 +156,16 @@ static bool _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) { while ((_i2c_get_sr(i2c_port) & 0x00030002) != 0x00030002) { if (--timeout == 0) { //printf("timeout in _i2c_restart read\n"); - return false; + return MP_FALSE; } } } - return true; + return MP_TRUE; } -static bool _i2c_send_byte(pyb_i2c_t i2c_port, uint8_t data) { +static MP_BOOL _i2c_send_byte(pyb_i2c_t i2c_port, uint8_t data) { I2C_TypeDef *i2c = _i2c_port_addr(i2c_port); - if (i2c == NULL) return false; + if (i2c == NULL) return MP_FALSE; // send byte i2c->DR = data; @@ -174,10 +174,10 @@ static bool _i2c_send_byte(pyb_i2c_t i2c_port, uint8_t data) { while ((_i2c_get_sr(i2c_port) & 0x00070084) != 0x00070084) { if (--timeout == 0) { //printf("timeout in _i2c_send_byte\n"); - return false; + return MP_FALSE; } } - return true; + return MP_TRUE; } static uint8_t _i2c_read_ack(pyb_i2c_t i2c_port) { @@ -220,18 +220,18 @@ static uint8_t _i2c_read_nack(pyb_i2c_t i2c_port) { return data; } -static bool _i2c_start(pyb_i2c_t i2c_port) { +static MP_BOOL _i2c_start(pyb_i2c_t i2c_port) { I2C_TypeDef *i2c = _i2c_port_addr(i2c_port); - if (i2c == NULL) return false; + if (i2c == NULL) return MP_FALSE; // wait until I2C is not busy uint32_t timeout = 1000000; while (i2c->SR2 & I2C_SR2_BUSY) { if (--timeout == 0) { - return false; + return MP_FALSE; } } - return true; + return MP_TRUE; } static void _i2c_stop(pyb_i2c_t i2c_port) { @@ -264,7 +264,7 @@ mp_obj_t i2c_obj_start(mp_obj_t self_in) { _i2c_stop(self->i2c_port); self->i2c_state = I2C_STATE_IDLE; } - if (_i2c_start(self->i2c_port) == true) + if (_i2c_start(self->i2c_port) == MP_TRUE) return mp_const_true; return mp_const_false; } @@ -272,7 +272,7 @@ mp_obj_t i2c_obj_start(mp_obj_t self_in) { mp_obj_t i2c_obj_write(mp_obj_t self_in, mp_obj_t data_in) { pyb_i2c_obj_t *self = self_in; if (self->i2c_state != I2C_STATE_WRITE) { - if (_i2c_restart(self->i2c_port, self->i2c_addr, 1) == false) { + if (_i2c_restart(self->i2c_port, self->i2c_addr, 1) == MP_FALSE) { _i2c_stop(self->i2c_port); self->i2c_state = I2C_STATE_IDLE; return mp_const_false; @@ -280,7 +280,7 @@ mp_obj_t i2c_obj_write(mp_obj_t self_in, mp_obj_t data_in) { self->i2c_state = I2C_STATE_WRITE; } uint8_t data = mp_obj_get_int(data_in); - if (_i2c_send_byte(self->i2c_port, data) == false) + if (_i2c_send_byte(self->i2c_port, data) == MP_FALSE) return mp_const_false; return mp_const_true; } @@ -288,7 +288,7 @@ mp_obj_t i2c_obj_write(mp_obj_t self_in, mp_obj_t data_in) { mp_obj_t i2c_obj_read(mp_obj_t self_in) { pyb_i2c_obj_t *self = self_in; if (self->i2c_state != I2C_STATE_READ) { - if (_i2c_restart(self->i2c_port, self->i2c_addr, 0) == false) { + if (_i2c_restart(self->i2c_port, self->i2c_addr, 0) == MP_FALSE) { _i2c_stop(self->i2c_port); self->i2c_state = I2C_STATE_IDLE; return mp_const_false; @@ -302,7 +302,7 @@ mp_obj_t i2c_obj_read(mp_obj_t self_in) { mp_obj_t i2c_obj_readAndStop(mp_obj_t self_in) { pyb_i2c_obj_t *self = self_in; if (self->i2c_state != I2C_STATE_READ) { - if (_i2c_restart(self->i2c_port, self->i2c_addr, 0) == false) { + if (_i2c_restart(self->i2c_port, self->i2c_addr, 0) == MP_FALSE) { _i2c_stop(self->i2c_port); self->i2c_state = I2C_STATE_IDLE; return mp_const_false; @@ -326,18 +326,19 @@ static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_read_obj, i2c_obj_read); static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_readAndStop_obj, i2c_obj_readAndStop); static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_stop_obj, i2c_obj_stop); +static const mp_method_t i2c_obj_type_type_methods[] = { + { "start", &i2c_obj_start_obj }, + { "write", &i2c_obj_write_obj }, + { "read", &i2c_obj_read_obj }, + { "readAndStop", &i2c_obj_readAndStop_obj }, + { "stop", &i2c_obj_stop_obj }, + { NULL, NULL }, +}; static const mp_obj_type_t i2c_obj_type = { { &mp_const_type }, "I2C", .print = i2c_obj_print, - .methods = { - { "start", &i2c_obj_start_obj }, - { "write", &i2c_obj_write_obj }, - { "read", &i2c_obj_read_obj }, - { "readAndStop", &i2c_obj_readAndStop_obj }, - { "stop", &i2c_obj_stop_obj }, - { NULL, NULL }, - } + .methods = i2c_obj_type_type_methods, }; // create the I2C object @@ -350,7 +351,7 @@ mp_obj_t pyb_I2C(mp_obj_t i2c_id, mp_obj_t i2c_addr) { case 1: i2c_port = PYB_I2C_2; break; default: return mp_const_none; } - if (_i2c_init(i2c_port) == false) { + if (_i2c_init(i2c_port) == MP_FALSE) { return mp_const_none; } pyb_i2c_obj_t *o = m_new_obj(pyb_i2c_obj_t); diff --git a/stm/led.c b/stm/led.c index 9809c21771..e89adbb78c 100644 --- a/stm/led.c +++ b/stm/led.c @@ -176,15 +176,16 @@ mp_obj_t led_obj_off(mp_obj_t self_in) { static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on); static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off); +static const mp_method_t led_obj_type_methods[] = { + { "on", &led_obj_on_obj }, + { "off", &led_obj_off_obj }, + { NULL, NULL }, +}; static const mp_obj_type_t led_obj_type = { { &mp_const_type }, "Led", .print = led_obj_print, - .methods = { - { "on", &led_obj_on_obj }, - { "off", &led_obj_off_obj }, - { NULL, NULL }, - } + .methods = led_obj_type_methods, }; mp_obj_t pyb_Led(mp_obj_t led_id) { diff --git a/stm/lexerstm.c b/stm/lexerstm.c index 661dfb0160..6de908317b 100644 --- a/stm/lexerstm.c +++ b/stm/lexerstm.c @@ -21,7 +21,7 @@ void str_buf_free(mp_lexer_str_buf_t *sb) { } } -mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str, mp_lexer_str_buf_t *sb) { +mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, MP_BOOL free_str, mp_lexer_str_buf_t *sb) { sb->free = free_str; sb->src_beg = str; sb->src_cur = str; diff --git a/stm/lexerstm.h b/stm/lexerstm.h index 7e090898a2..99c270a718 100644 --- a/stm/lexerstm.h +++ b/stm/lexerstm.h @@ -1,5 +1,5 @@ typedef struct _py_lexer_str_buf_t { - bool free; // free src_beg when done + MP_BOOL free; // free src_beg when done const char *src_beg; // beginning of source const char *src_cur; // current location in source const char *src_end; // end (exclusive) of source @@ -12,5 +12,5 @@ typedef struct _py_lexer_file_buf_t { uint16_t pos; } mp_lexer_file_buf_t; -mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str, mp_lexer_str_buf_t *sb); +mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, MP_BOOL free_str, mp_lexer_str_buf_t *sb); mp_lexer_t *mp_lexer_new_from_file(const char *filename, mp_lexer_file_buf_t *fb); diff --git a/stm/main.c b/stm/main.c index 07c974eff8..e1b695167c 100644 --- a/stm/main.c +++ b/stm/main.c @@ -359,7 +359,7 @@ int readline(vstr_t *line, const char *prompt) { readline_hist[0] = strdup(vstr_str(line)); return 1; } else if (c == 27) { - escape = true; + escape = MP_TRUE; } else if (c == 127) { if (vstr_len(line) > len) { vstr_cut_tail(line, 1); @@ -432,12 +432,12 @@ void do_repl(void) { } mp_lexer_str_buf_t sb; - mp_lexer_t *lex = mp_lexer_new_from_str_len("", vstr_str(&line), vstr_len(&line), false, &sb); + mp_lexer_t *lex = mp_lexer_new_from_str_len("", vstr_str(&line), vstr_len(&line), MP_FALSE, &sb); mp_parse_node_t pn = mp_parse(lex, MP_PARSE_SINGLE_INPUT); mp_lexer_free(lex); if (pn != MP_PARSE_NODE_NULL) { - mp_obj_t module_fun = mp_compile(pn, true); + mp_obj_t module_fun = mp_compile(pn, MP_TRUE); if (module_fun != mp_const_none) { nlr_buf_t nlr; uint32_t start = sys_tick_counter; @@ -461,37 +461,37 @@ void do_repl(void) { stdout_tx_str("\r\n"); } -bool do_file(const char *filename) { +MP_BOOL do_file(const char *filename) { mp_lexer_file_buf_t fb; mp_lexer_t *lex = mp_lexer_new_from_file(filename, &fb); if (lex == NULL) { printf("could not open file '%s' for reading\n", filename); - return false; + return MP_FALSE; } mp_parse_node_t pn = mp_parse(lex, MP_PARSE_FILE_INPUT); mp_lexer_free(lex); if (pn == MP_PARSE_NODE_NULL) { - return false; + return MP_FALSE; } - mp_obj_t module_fun = mp_compile(pn, false); + mp_obj_t module_fun = mp_compile(pn, MP_FALSE); if (module_fun == mp_const_none) { - return false; + return MP_FALSE; } nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { rt_call_function_0(module_fun); nlr_pop(); - return true; + return MP_TRUE; } else { // uncaught exception mp_obj_print((mp_obj_t)nlr.ret_val); printf("\n"); - return false; + return MP_FALSE; } } @@ -689,6 +689,12 @@ static MP_DEFINE_CONST_FUN_OBJ_1(file_obj_close_obj, file_obj_close); // TODO gc hook to close the file if not already closed +static const mp_method_t file_obj_type_methods[] = { + { "read", &file_obj_read_obj }, + { "write", &file_obj_write_obj }, + { "close", &file_obj_close_obj }, + { NULL, NULL }, +}; static const mp_obj_type_t file_obj_type = { { &mp_const_type }, "File", @@ -699,12 +705,7 @@ static const mp_obj_type_t file_obj_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - .methods = { - { "read", &file_obj_read_obj }, - { "write", &file_obj_write_obj }, - { "close", &file_obj_close_obj }, - {NULL, NULL}, - } + .methods = file_obj_type_methods, }; mp_obj_t pyb_io_open(mp_obj_t o_filename, mp_obj_t o_mode) { @@ -778,7 +779,7 @@ int main(void) { //usart_init(); disabled while wi-fi is enabled - int first_soft_reset = true; + int first_soft_reset = MP_TRUE; soft_reset: @@ -847,12 +848,12 @@ soft_reset: lcd_print_str(" micro py board\n"); // check if user switch held (initiates reset of filesystem) - bool reset_filesystem = false; + MP_BOOL reset_filesystem = MP_FALSE; if (switch_get()) { - reset_filesystem = true; + reset_filesystem = MP_TRUE; for (int i = 0; i < 50; i++) { if (!switch_get()) { - reset_filesystem = false; + reset_filesystem = MP_FALSE; break; } sys_tick_delay_ms(10); @@ -1063,7 +1064,7 @@ soft_reset: "f()\n"; mp_lexer_str_buf_t mp_lexer_str_buf; - mp_lexer_t *lex = mp_lexer_new_from_str_len("", pysrc, strlen(pysrc), false, &mp_lexer_str_buf); + mp_lexer_t *lex = mp_lexer_new_from_str_len("", pysrc, strlen(pysrc), MP_FALSE, &mp_lexer_str_buf); // nalloc=1740;6340;6836 -> 140;4600;496 bytes for lexer, parser, compiler printf("lex; al=%u\n", m_get_total_bytes_allocated()); @@ -1074,7 +1075,7 @@ soft_reset: printf("pars;al=%u\n", m_get_total_bytes_allocated()); sys_tick_delay_ms(1000); //parse_node_show(pn, 0); - mp_obj_t module_fun = mp_compile(pn, false); + mp_obj_t module_fun = mp_compile(pn, MP_FALSE); printf("comp;al=%u\n", m_get_total_bytes_allocated()); sys_tick_delay_ms(1000); @@ -1171,7 +1172,7 @@ soft_reset: printf("PYB: soft reboot\n"); - first_soft_reset = false; + first_soft_reset = MP_FALSE; goto soft_reset; } diff --git a/stm/printf.c b/stm/printf.c index 8a59f8a986..7ada626bd5 100644 --- a/stm/printf.c +++ b/stm/printf.c @@ -152,10 +152,10 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) { } // parse long specifiers (current not used) - //bool long_arg = false; + //MP_BOOL long_arg = MP_FALSE; if (*fmt == 'l') { ++fmt; - //long_arg = true; + //long_arg = MP_TRUE; } if (*fmt == '\0') { @@ -215,14 +215,14 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) { void stdout_print_strn(void *data, const char *str, unsigned int len) { // send stdout to USART, USB CDC VCP, and LCD if nothing else - bool any = false; + MP_BOOL any = MP_FALSE; if (usart_is_enabled()) { usart_tx_strn_cooked(str, len); - any = true; + any = MP_TRUE; } if (usb_vcp_is_enabled()) { usb_vcp_send_strn_cooked(str, len); - any = true; + any = MP_TRUE; } if (!any) { lcd_print_strn(str, len); diff --git a/stm/pybwlan.c b/stm/pybwlan.c index 6988f1c848..cffa016844 100644 --- a/stm/pybwlan.c +++ b/stm/pybwlan.c @@ -336,7 +336,7 @@ void CC3000_UsynchCallback(long lEventType, char * data, unsigned char length) socketnum = data[0]; //PRINT_F("TCP Close wait #"); printDec(socketnum); if (socketnum < MAX_SOCKETS) - closed_sockets[socketnum] = true; + closed_sockets[socketnum] = MP_TRUE; */ } } diff --git a/stm/servo.c b/stm/servo.c index 31190ce795..7facce7456 100644 --- a/stm/servo.c +++ b/stm/servo.c @@ -137,14 +137,15 @@ static mp_obj_t servo_obj_angle(mp_obj_t self_in, mp_obj_t angle) { static MP_DEFINE_CONST_FUN_OBJ_2(servo_obj_angle_obj, servo_obj_angle); +static const mp_method_t servo_obj_type_methods[] = { + { "angle", &servo_obj_angle_obj }, + { NULL, NULL }, +}; static const mp_obj_type_t servo_obj_type = { { &mp_const_type }, "Servo", .print = servo_obj_print, - .methods = { - { "angle", &servo_obj_angle_obj }, - { NULL, NULL }, - } + .methods = servo_obj_type_methods, }; mp_obj_t pyb_Servo(mp_obj_t servo_id) { diff --git a/stm/storage.c b/stm/storage.c index daee4adb5e..f1ec9f6522 100644 --- a/stm/storage.c +++ b/stm/storage.c @@ -15,18 +15,18 @@ #define FLASH_PART1_NUM_BLOCKS (224) // 16k+16k+16k+64k=112k #define FLASH_MEM_START_ADDR (0x08004000) // sector 1, 16k -static bool is_initialised = false; +static MP_BOOL is_initialised = MP_FALSE; static uint32_t cache_flash_sector_id; static uint32_t cache_flash_sector_start; static uint32_t cache_flash_sector_size; -static bool cache_dirty; +static MP_BOOL cache_dirty; static uint32_t sys_tick_counter_last_write; static void cache_flush(void) { if (cache_dirty) { // sync the cache RAM buffer by writing it to the flash page flash_write(cache_flash_sector_start, (const uint32_t*)CACHE_MEM_START_ADDR, cache_flash_sector_size / 4); - cache_dirty = false; + cache_dirty = MP_FALSE; // indicate a clean cache with LED off led_state(PYB_LED_R1, 0); } @@ -43,7 +43,7 @@ static uint8_t *cache_get_addr_for_write(uint32_t flash_addr) { cache_flash_sector_start = flash_sector_start; cache_flash_sector_size = flash_sector_size; } - cache_dirty = true; + cache_dirty = MP_TRUE; // indicate a dirty cache with LED on led_state(PYB_LED_R1, 1); return (uint8_t*)CACHE_MEM_START_ADDR + flash_addr - flash_sector_start; @@ -64,8 +64,8 @@ static uint8_t *cache_get_addr_for_read(uint32_t flash_addr) { void storage_init(void) { if (!is_initialised) { cache_flash_sector_id = 0; - cache_dirty = false; - is_initialised = true; + cache_dirty = MP_FALSE; + is_initialised = MP_TRUE; sys_tick_counter_last_write = 0; } } @@ -78,7 +78,7 @@ uint32_t storage_get_block_count(void) { return FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS; } -bool storage_needs_flush(void) { +MP_BOOL storage_needs_flush(void) { // wait 2 seconds after last write to flush return cache_dirty && sys_tick_has_passed(sys_tick_counter_last_write, 2000); } @@ -123,7 +123,7 @@ static void build_partition(uint8_t *buf, int boot, int type, uint32_t start_blo buf[15] = num_blocks >> 24; } -bool storage_read_block(uint8_t *dest, uint32_t block) { +MP_BOOL storage_read_block(uint8_t *dest, uint32_t block) { //printf("RD %u\n", block); if (block == 0) { // fake the MBR so we can decide on our own partition table @@ -140,26 +140,26 @@ bool storage_read_block(uint8_t *dest, uint32_t block) { dest[510] = 0x55; dest[511] = 0xaa; - return true; + return MP_TRUE; } else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS) { // non-MBR block, get data from flash memory, possibly via cache uint32_t flash_addr = FLASH_MEM_START_ADDR + (block - FLASH_PART1_START_BLOCK) * BLOCK_SIZE; uint8_t *src = cache_get_addr_for_read(flash_addr); memcpy(dest, src, BLOCK_SIZE); - return true; + return MP_TRUE; } else { // bad block number - return false; + return MP_FALSE; } } -bool storage_write_block(const uint8_t *src, uint32_t block) { +MP_BOOL storage_write_block(const uint8_t *src, uint32_t block) { //printf("WR %u\n", block); if (block == 0) { // can't write MBR, but pretend we did - return true; + return MP_TRUE; } else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS) { // non-MBR block, copy to cache @@ -167,10 +167,10 @@ bool storage_write_block(const uint8_t *src, uint32_t block) { uint8_t *dest = cache_get_addr_for_write(flash_addr); memcpy(dest, src, BLOCK_SIZE); sys_tick_counter_last_write = sys_tick_counter; - return true; + return MP_TRUE; } else { // bad block number - return false; + return MP_FALSE; } } diff --git a/stm/storage.h b/stm/storage.h index fe37e8b27c..7bdcfc7cce 100644 --- a/stm/storage.h +++ b/stm/storage.h @@ -1,7 +1,7 @@ void storage_init(void); uint32_t storage_get_block_size(void); uint32_t storage_get_block_count(void); -bool storage_needs_flush(void); +MP_BOOL storage_needs_flush(void); void storage_flush(void); -bool storage_read_block(uint8_t *dest, uint32_t block); -bool storage_write_block(const uint8_t *src, uint32_t block); +MP_BOOL storage_read_block(uint8_t *dest, uint32_t block); +MP_BOOL storage_write_block(const uint8_t *src, uint32_t block); diff --git a/stm/systick.c b/stm/systick.c index 40ae532793..f9def4a026 100644 --- a/stm/systick.c +++ b/stm/systick.c @@ -43,7 +43,7 @@ void sys_tick_wait_at_least(uint32_t stc, uint32_t delay_ms) { } } -bool sys_tick_has_passed(uint32_t stc, uint32_t delay_ms) { +MP_BOOL sys_tick_has_passed(uint32_t stc, uint32_t delay_ms) { // stc_wait is the value of sys_tick_counter that we wait for uint32_t stc_wait = stc + delay_ms; if (stc_wait < stc) { diff --git a/stm/systick.h b/stm/systick.h index 7d2deed119..518d872c25 100644 --- a/stm/systick.h +++ b/stm/systick.h @@ -4,4 +4,4 @@ void sys_tick_init(void); void SysTick_Handler(void); void sys_tick_delay_ms(uint32_t delay_ms); void sys_tick_wait_at_least(uint32_t stc, uint32_t delay_ms); -bool sys_tick_has_passed(uint32_t stc, uint32_t delay_ms); +MP_BOOL sys_tick_has_passed(uint32_t stc, uint32_t delay_ms); diff --git a/stm/usart.c b/stm/usart.c index 307aff1662..6e300a29e4 100644 --- a/stm/usart.c +++ b/stm/usart.c @@ -5,7 +5,7 @@ #include "misc.h" #include "usart.h" -static bool is_enabled; +static MP_BOOL is_enabled; // USART6 on PC6 (TX), PC7 (RX) void usart_init(void) { @@ -33,14 +33,14 @@ void usart_init(void) { USART_Cmd(USART6, ENABLE); - is_enabled = true; + is_enabled = MP_TRUE; } -bool usart_is_enabled(void) { +MP_BOOL usart_is_enabled(void) { return is_enabled; } -bool usart_rx_any(void) { +MP_BOOL usart_rx_any(void) { return USART_GetFlagStatus(USART6, USART_FLAG_RXNE) == SET; } diff --git a/stm/usart.h b/stm/usart.h index 9d92e59f5a..ad57587ce3 100644 --- a/stm/usart.h +++ b/stm/usart.h @@ -1,6 +1,6 @@ void usart_init(void); -bool usart_is_enabled(void); -bool usart_rx_any(void); +MP_BOOL usart_is_enabled(void); +MP_BOOL usart_rx_any(void); int usart_rx_char(void); void usart_tx_char(int c); void usart_tx_str(const char *str); diff --git a/stm/usb.c b/stm/usb.c index b0fbfa1941..6b553914ec 100644 --- a/stm/usb.c +++ b/stm/usb.c @@ -30,7 +30,7 @@ void usb_init(void) { is_enabled = 1; } -bool usb_vcp_is_enabled(void) { +MP_BOOL usb_vcp_is_enabled(void) { return is_enabled; } diff --git a/stm/usb.h b/stm/usb.h index c4b3b151fb..6f8172a3fb 100644 --- a/stm/usb.h +++ b/stm/usb.h @@ -1,5 +1,5 @@ void usb_init(void); -bool usb_vcp_is_enabled(void); +MP_BOOL usb_vcp_is_enabled(void); int usb_vcp_rx_any(void); char usb_vcp_rx_get(void); void usb_vcp_send_str(const char* str); diff --git a/unix-cpy/main.c b/unix-cpy/main.c index eba97f527b..b1e99ac12a 100644 --- a/unix-cpy/main.c +++ b/unix-cpy/main.c @@ -37,7 +37,7 @@ void do_file(const char *file) { //printf("----------------\n"); //parse_node_show(pn, 0); //printf("----------------\n"); - mp_obj_t module_fun = mp_compile(pn, false); + mp_obj_t module_fun = mp_compile(pn, MP_FALSE); //printf("----------------\n"); if (module_fun == mp_const_none) { diff --git a/unix/main.c b/unix/main.c index a06dc36791..e3873489d1 100644 --- a/unix/main.c +++ b/unix/main.c @@ -79,13 +79,13 @@ static void do_repl(void) { } } - mp_lexer_t *lex = mp_lexer_new_from_str_len("", line, strlen(line), false); + mp_lexer_t *lex = mp_lexer_new_from_str_len("", line, strlen(line), MP_FALSE); mp_parse_node_t pn = mp_parse(lex, MP_PARSE_SINGLE_INPUT); mp_lexer_free(lex); if (pn != MP_PARSE_NODE_NULL) { //mp_parse_node_show(pn, 0); - mp_obj_t module_fun = mp_compile(pn, true); + mp_obj_t module_fun = mp_compile(pn, MP_TRUE); if (module_fun != mp_const_none) { nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { @@ -139,7 +139,7 @@ void do_file(const char *file) { //printf("----------------\n"); //parse_node_show(pn, 0); //printf("----------------\n"); - mp_obj_t module_fun = mp_compile(pn, false); + mp_obj_t module_fun = mp_compile(pn, MP_FALSE); //printf("----------------\n"); #if MICROPY_EMIT_CPYTHON @@ -166,7 +166,7 @@ void do_file(const char *file) { typedef struct _test_obj_t { mp_obj_base_t base; - bool value; + MP_BOOL value; } test_obj_t; static void test_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) { From 5fd8fd2c16076f683b629b513e8865e461d4c9a8 Mon Sep 17 00:00:00 2001 From: ian-v Date: Mon, 6 Jan 2014 13:51:53 -0800 Subject: [PATCH 06/17] Revert MP_BOOL, etc. and use instead --- py/asmthumb.c | 8 +- py/asmthumb.h | 2 +- py/asmx64.c | 12 +-- py/asmx64.h | 2 +- py/bc.h | 2 +- py/builtinimport.c | 2 +- py/compile.c | 224 +++++++++++++++++++++---------------------- py/compile.h | 2 +- py/emit.h | 10 +- py/emitbc.c | 18 ++-- py/emitcpy.c | 32 +++---- py/emitinlinethumb.c | 6 +- py/emitnative.c | 30 +++--- py/emitpass1.c | 4 +- py/lexer.c | 80 ++++++++-------- py/lexer.h | 14 +-- py/lexerunix.c | 6 +- py/lexerunix.h | 2 +- py/map.c | 12 +-- py/map.h | 6 +- py/misc.h | 18 ++-- py/obj.c | 20 ++-- py/obj.h | 8 +- py/objbool.c | 6 +- py/objclass.c | 2 +- py/objdict.c | 8 +- py/objgenerator.c | 2 +- py/objinstance.c | 14 +-- py/objlist.c | 2 + py/objset.c | 8 +- py/objtuple.c | 10 +- py/parse.c | 44 ++++----- py/repl.c | 8 +- py/repl.h | 2 +- py/runtime.c | 118 +++++++++++------------ py/runtime0.h | 2 +- py/scope.c | 14 +-- py/scope.h | 4 +- py/unicode.c | 14 +-- py/vm.c | 8 +- py/vstr.c | 18 ++-- stm/audio.c | 2 +- stm/cc3k/pybcc3k.c | 6 +- stm/i2c.c | 83 ++++++++-------- stm/led.c | 11 +-- stm/lexerstm.c | 2 +- stm/lexerstm.h | 4 +- stm/main.c | 47 +++++---- stm/printf.c | 10 +- stm/pybwlan.c | 2 +- stm/servo.c | 9 +- stm/storage.c | 30 +++--- stm/storage.h | 6 +- stm/systick.c | 2 +- stm/systick.h | 2 +- stm/usart.c | 8 +- stm/usart.h | 4 +- stm/usb.c | 2 +- stm/usb.h | 2 +- unix-cpy/main.c | 2 +- unix/main.c | 8 +- 61 files changed, 517 insertions(+), 529 deletions(-) diff --git a/py/asmthumb.c b/py/asmthumb.c index 76a93b9a3f..ba95d80c68 100644 --- a/py/asmthumb.c +++ b/py/asmthumb.c @@ -45,7 +45,7 @@ asm_thumb_t *asm_thumb_new(uint max_num_labels) { return as; } -void asm_thumb_free(asm_thumb_t *as, MP_BOOL free_code) { +void asm_thumb_free(asm_thumb_t *as, bool free_code) { if (free_code) { m_del(byte, as->code_base, as->code_size); } @@ -56,9 +56,9 @@ void asm_thumb_free(asm_thumb_t *as, MP_BOOL free_code) { { Label *lab = &g_array_index(as->label, Label, i); if (lab->unresolved != NULL) - g_array_free(lab->unresolved, MP_TRUE); + g_array_free(lab->unresolved, true); } - g_array_free(as->label, MP_TRUE); + g_array_free(as->label, true); } */ m_del_obj(asm_thumb_t, as); @@ -87,7 +87,7 @@ void asm_thumb_end_pass(asm_thumb_t *as) { int i; for (i = 0; i < as->label->len; ++i) if (g_array_index(as->label, Label, i).unresolved != NULL) - return MP_FALSE; + return false; } */ } diff --git a/py/asmthumb.h b/py/asmthumb.h index c6ebcb4c46..dcd9c2e3ad 100644 --- a/py/asmthumb.h +++ b/py/asmthumb.h @@ -44,7 +44,7 @@ typedef struct _asm_thumb_t asm_thumb_t; asm_thumb_t *asm_thumb_new(uint max_num_labels); -void asm_thumb_free(asm_thumb_t *as, MP_BOOL free_code); +void asm_thumb_free(asm_thumb_t *as, bool free_code); void asm_thumb_start_pass(asm_thumb_t *as, int pass); void asm_thumb_end_pass(asm_thumb_t *as); uint asm_thumb_get_code_size(asm_thumb_t *as); diff --git a/py/asmx64.c b/py/asmx64.c index 054f411882..ed9ca80f5c 100644 --- a/py/asmx64.c +++ b/py/asmx64.c @@ -94,7 +94,7 @@ struct _asm_x64_t { }; // for allocating memory, see src/v8/src/platform-linux.cc -void *alloc_mem(uint req_size, uint *alloc_size, MP_BOOL is_exec) { +void *alloc_mem(uint req_size, uint *alloc_size, bool is_exec) { req_size = (req_size + 0xfff) & (~0xfff); int prot = PROT_READ | PROT_WRITE | (is_exec ? PROT_EXEC : 0); void *ptr = mmap(NULL, req_size, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); @@ -119,7 +119,7 @@ asm_x64_t* asm_x64_new(uint max_num_labels) { return as; } -void asm_x64_free(asm_x64_t* as, MP_BOOL free_code) { +void asm_x64_free(asm_x64_t* as, bool free_code) { if (free_code) { // need to un-mmap //m_free(as->code_base); @@ -131,9 +131,9 @@ void asm_x64_free(asm_x64_t* as, MP_BOOL free_code) { { Label* lab = &g_array_index(as->label, Label, i); if (lab->unresolved != NULL) - g_array_free(lab->unresolved, MP_TRUE); + g_array_free(lab->unresolved, true); } - g_array_free(as->label, MP_TRUE); + g_array_free(as->label, true); } */ m_del_obj(asm_x64_t, as); @@ -154,7 +154,7 @@ void asm_x64_end_pass(asm_x64_t *as) { as->code_size = as->code_offset; //as->code_base = m_new(byte, as->code_size); need to allocale executable memory uint actual_alloc; - as->code_base = alloc_mem(as->code_size, &actual_alloc, MP_TRUE); + as->code_base = alloc_mem(as->code_size, &actual_alloc, true); printf("code_size: %u\n", as->code_size); } @@ -165,7 +165,7 @@ void asm_x64_end_pass(asm_x64_t *as) { int i; for (i = 0; i < as->label->len; ++i) if (g_array_index(as->label, Label, i).unresolved != NULL) - return MP_FALSE; + return false; } */ } diff --git a/py/asmx64.h b/py/asmx64.h index 1ee39a3b2b..16cc3b2119 100644 --- a/py/asmx64.h +++ b/py/asmx64.h @@ -27,7 +27,7 @@ typedef struct _asm_x64_t asm_x64_t; asm_x64_t* asm_x64_new(uint max_num_labels); -void asm_x64_free(asm_x64_t* as, MP_BOOL free_code); +void asm_x64_free(asm_x64_t* as, bool free_code); void asm_x64_start_pass(asm_x64_t *as, int pass); void asm_x64_end_pass(asm_x64_t *as); uint asm_x64_get_code_size(asm_x64_t* as); diff --git a/py/bc.h b/py/bc.h index b1fdb3aa10..35847f4589 100644 --- a/py/bc.h +++ b/py/bc.h @@ -1,2 +1,2 @@ mp_obj_t mp_execute_byte_code(const byte *code, const mp_obj_t *args, uint n_args, uint n_state); -MP_BOOL mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **sp_in_out); +bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **sp_in_out); diff --git a/py/builtinimport.c b/py/builtinimport.c index ba191ddd75..90a0fc3394 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -58,7 +58,7 @@ mp_obj_t mp_builtin___import__(int n, mp_obj_t *args) { return mp_const_none; } - mp_obj_t module_fun = mp_compile(pn, MP_FALSE); + mp_obj_t module_fun = mp_compile(pn, false); if (module_fun == mp_const_none) { // TODO handle compile error correctly diff --git a/py/compile.c b/py/compile.c index d388ad8096..0e19890315 100644 --- a/py/compile.c +++ b/py/compile.c @@ -39,9 +39,9 @@ typedef enum { #define EMIT_OPT_ASM_THUMB (4) typedef struct _compiler_t { - MP_BOOL is_repl; + bool is_repl; pass_kind_t pass; - MP_BOOL had_error; // try to keep compiler clean from nlr + bool had_error; // try to keep compiler clean from nlr int next_label; @@ -50,9 +50,9 @@ typedef struct _compiler_t { int except_nest_level; int n_arg_keyword; - MP_BOOL have_star_arg; - MP_BOOL have_dbl_star_arg; - MP_BOOL have_bare_star; + bool have_star_arg; + bool have_dbl_star_arg; + bool have_bare_star; int param_pass; int param_pass_num_dict_params; int param_pass_num_default_params; @@ -261,36 +261,36 @@ void compile_generic_all_nodes(compiler_t *comp, mp_parse_node_struct_t *pns) { } #if MICROPY_EMIT_CPYTHON -static MP_BOOL cpython_c_tuple_is_const(mp_parse_node_t pn) { +static bool cpython_c_tuple_is_const(mp_parse_node_t pn) { if (!MP_PARSE_NODE_IS_LEAF(pn)) { - return MP_FALSE; + return false; } if (MP_PARSE_NODE_IS_ID(pn)) { - return MP_FALSE; + return false; } - return MP_TRUE; + return true; } -static void cpython_c_print_quoted_str(vstr_t *vstr, qstr qstr, MP_BOOL bytes) { +static void cpython_c_print_quoted_str(vstr_t *vstr, qstr qstr, bool bytes) { const char *str = qstr_str(qstr); int len = strlen(str); - MP_BOOL has_single_quote = MP_FALSE; - MP_BOOL has_double_quote = MP_FALSE; + bool has_single_quote = false; + bool has_double_quote = false; for (int i = 0; i < len; i++) { if (str[i] == '\'') { - has_single_quote = MP_TRUE; + has_single_quote = true; } else if (str[i] == '"') { - has_double_quote = MP_TRUE; + has_double_quote = true; } } if (bytes) { vstr_printf(vstr, "b"); } - MP_BOOL quote_single = MP_FALSE; + bool quote_single = false; if (has_single_quote && !has_double_quote) { vstr_printf(vstr, "\""); } else { - quote_single = MP_TRUE; + quote_single = true; vstr_printf(vstr, "'"); } for (int i = 0; i < len; i++) { @@ -319,8 +319,8 @@ static void cpython_c_tuple_emit_const(compiler_t *comp, mp_parse_node_t pn, vst case MP_PARSE_NODE_SMALL_INT: vstr_printf(vstr, "%d", arg); break; case MP_PARSE_NODE_INTEGER: vstr_printf(vstr, "%s", qstr_str(arg)); break; case MP_PARSE_NODE_DECIMAL: vstr_printf(vstr, "%s", qstr_str(arg)); break; - case MP_PARSE_NODE_STRING: cpython_c_print_quoted_str(vstr, arg, MP_FALSE); break; - case MP_PARSE_NODE_BYTES: cpython_c_print_quoted_str(vstr, arg, MP_TRUE); break; + case MP_PARSE_NODE_STRING: cpython_c_print_quoted_str(vstr, arg, false); break; + case MP_PARSE_NODE_BYTES: cpython_c_print_quoted_str(vstr, arg, true); break; case MP_PARSE_NODE_TOKEN: switch (arg) { case MP_TOKEN_KW_FALSE: vstr_printf(vstr, "False"); break; @@ -339,33 +339,33 @@ static void cpython_c_tuple(compiler_t *comp, mp_parse_node_t pn, mp_parse_node_ n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns_list); } int total = n; - MP_BOOL is_const = MP_TRUE; + bool is_const = true; if (!MP_PARSE_NODE_IS_NULL(pn)) { total += 1; if (!cpython_c_tuple_is_const(pn)) { - is_const = MP_FALSE; + is_const = false; } } for (int i = 0; i < n; i++) { if (!cpython_c_tuple_is_const(pns_list->nodes[i])) { - is_const = MP_FALSE; + is_const = false; break; } } if (total > 0 && is_const) { - MP_BOOL need_comma = MP_FALSE; + bool need_comma = false; vstr_t *vstr = vstr_new(); vstr_printf(vstr, "("); if (!MP_PARSE_NODE_IS_NULL(pn)) { cpython_c_tuple_emit_const(comp, pn, vstr); - need_comma = MP_TRUE; + need_comma = true; } for (int i = 0; i < n; i++) { if (need_comma) { vstr_printf(vstr, ", "); } cpython_c_tuple_emit_const(comp, pns_list->nodes[i], vstr); - need_comma = MP_TRUE; + need_comma = true; } if (total == 1) { vstr_printf(vstr, ",)"); @@ -412,25 +412,25 @@ void compile_generic_tuple(compiler_t *comp, mp_parse_node_struct_t *pns) { c_tuple(comp, MP_PARSE_NODE_NULL, pns); } -static MP_BOOL node_is_const_false(mp_parse_node_t pn) { +static bool node_is_const_false(mp_parse_node_t pn) { return MP_PARSE_NODE_IS_TOKEN_KIND(pn, MP_TOKEN_KW_FALSE); // untested: || (MP_PARSE_NODE_IS_SMALL_INT(pn) && MP_PARSE_NODE_LEAF_ARG(pn) == 1); } -static MP_BOOL node_is_const_true(mp_parse_node_t pn) { +static bool node_is_const_true(mp_parse_node_t pn) { return MP_PARSE_NODE_IS_TOKEN_KIND(pn, MP_TOKEN_KW_TRUE) || (MP_PARSE_NODE_IS_SMALL_INT(pn) && MP_PARSE_NODE_LEAF_ARG(pn) == 1); } #if MICROPY_EMIT_CPYTHON // the is_nested variable is purely to match with CPython, which doesn't fully optimise not's -static void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, MP_BOOL jump_if, int label, MP_BOOL is_nested) { +static void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int label, bool is_nested) { if (node_is_const_false(pn)) { - if (jump_if == MP_FALSE) { + if (jump_if == false) { EMIT(jump, label); } return; } else if (node_is_const_true(pn)) { - if (jump_if == MP_TRUE) { + if (jump_if == true) { EMIT(jump, label); } return; @@ -438,42 +438,42 @@ static void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, MP_BOOL jump mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn; int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_or_test) { - if (jump_if == MP_FALSE) { + if (jump_if == false) { int label2 = comp_next_label(comp); for (int i = 0; i < n - 1; i++) { - cpython_c_if_cond(comp, pns->nodes[i], MP_TRUE, label2, MP_TRUE); + cpython_c_if_cond(comp, pns->nodes[i], true, label2, true); } - cpython_c_if_cond(comp, pns->nodes[n - 1], MP_FALSE, label, MP_TRUE); + cpython_c_if_cond(comp, pns->nodes[n - 1], false, label, true); EMIT(label_assign, label2); } else { for (int i = 0; i < n; i++) { - cpython_c_if_cond(comp, pns->nodes[i], MP_TRUE, label, MP_TRUE); + cpython_c_if_cond(comp, pns->nodes[i], true, label, true); } } return; } else if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_and_test) { - if (jump_if == MP_FALSE) { + if (jump_if == false) { for (int i = 0; i < n; i++) { - cpython_c_if_cond(comp, pns->nodes[i], MP_FALSE, label, MP_TRUE); + cpython_c_if_cond(comp, pns->nodes[i], false, label, true); } } else { int label2 = comp_next_label(comp); for (int i = 0; i < n - 1; i++) { - cpython_c_if_cond(comp, pns->nodes[i], MP_FALSE, label2, MP_TRUE); + cpython_c_if_cond(comp, pns->nodes[i], false, label2, true); } - cpython_c_if_cond(comp, pns->nodes[n - 1], MP_TRUE, label, MP_TRUE); + cpython_c_if_cond(comp, pns->nodes[n - 1], true, label, true); EMIT(label_assign, label2); } return; } else if (!is_nested && MP_PARSE_NODE_STRUCT_KIND(pns) == PN_not_test_2) { - cpython_c_if_cond(comp, pns->nodes[0], !jump_if, label, MP_TRUE); + cpython_c_if_cond(comp, pns->nodes[0], !jump_if, label, true); return; } } // nothing special, fall back to default compiling for node and jump compile_node(comp, pn); - if (jump_if == MP_FALSE) { + if (jump_if == false) { EMIT(pop_jump_if_false, label); } else { EMIT(pop_jump_if_true, label); @@ -481,17 +481,17 @@ static void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, MP_BOOL jump } #endif -static void c_if_cond(compiler_t *comp, mp_parse_node_t pn, MP_BOOL jump_if, int label) { +static void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int label) { #if MICROPY_EMIT_CPYTHON - cpython_c_if_cond(comp, pn, jump_if, label, MP_FALSE); + cpython_c_if_cond(comp, pn, jump_if, label, false); #else if (node_is_const_false(pn)) { - if (jump_if == MP_FALSE) { + if (jump_if == false) { EMIT(jump, label); } return; } else if (node_is_const_true(pn)) { - if (jump_if == MP_TRUE) { + if (jump_if == true) { EMIT(jump, label); } return; @@ -499,30 +499,30 @@ static void c_if_cond(compiler_t *comp, mp_parse_node_t pn, MP_BOOL jump_if, int mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn; int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_or_test) { - if (jump_if == MP_FALSE) { + if (jump_if == false) { int label2 = comp_next_label(comp); for (int i = 0; i < n - 1; i++) { - c_if_cond(comp, pns->nodes[i], MP_TRUE, label2); + c_if_cond(comp, pns->nodes[i], true, label2); } - c_if_cond(comp, pns->nodes[n - 1], MP_FALSE, label); + c_if_cond(comp, pns->nodes[n - 1], false, label); EMIT(label_assign, label2); } else { for (int i = 0; i < n; i++) { - c_if_cond(comp, pns->nodes[i], MP_TRUE, label); + c_if_cond(comp, pns->nodes[i], true, label); } } return; } else if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_and_test) { - if (jump_if == MP_FALSE) { + if (jump_if == false) { for (int i = 0; i < n; i++) { - c_if_cond(comp, pns->nodes[i], MP_FALSE, label); + c_if_cond(comp, pns->nodes[i], false, label); } } else { int label2 = comp_next_label(comp); for (int i = 0; i < n - 1; i++) { - c_if_cond(comp, pns->nodes[i], MP_FALSE, label2); + c_if_cond(comp, pns->nodes[i], false, label2); } - c_if_cond(comp, pns->nodes[n - 1], MP_TRUE, label); + c_if_cond(comp, pns->nodes[n - 1], true, label); EMIT(label_assign, label2); } return; @@ -534,7 +534,7 @@ static void c_if_cond(compiler_t *comp, mp_parse_node_t pn, MP_BOOL jump_if, int // nothing special, fall back to default compiling for node and jump compile_node(comp, pn); - if (jump_if == MP_FALSE) { + if (jump_if == false) { EMIT(pop_jump_if_false, label); } else { EMIT(pop_jump_if_true, label); @@ -803,7 +803,7 @@ void compile_funcdef_param(compiler_t *comp, mp_parse_node_t pn) { mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn; if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { // bare star - comp->have_bare_star = MP_TRUE; + comp->have_bare_star = true; } } } @@ -819,18 +819,18 @@ qstr compile_funcdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint } // save variables (probably don't need to do this, since we can't have nested definitions..?) - MP_BOOL old_have_bare_star = comp->have_bare_star; + bool old_have_bare_star = comp->have_bare_star; int old_param_pass = comp->param_pass; int old_param_pass_num_dict_params = comp->param_pass_num_dict_params; int old_param_pass_num_default_params = comp->param_pass_num_default_params; // compile default parameters - comp->have_bare_star = MP_FALSE; + comp->have_bare_star = false; comp->param_pass = 1; // pass 1 does any default parameters after bare star comp->param_pass_num_dict_params = 0; comp->param_pass_num_default_params = 0; apply_to_single_or_list(comp, pns->nodes[1], PN_typedargslist, compile_funcdef_param); - comp->have_bare_star = MP_FALSE; + comp->have_bare_star = false; comp->param_pass = 2; // pass 2 does any default parameters before bare star comp->param_pass_num_dict_params = 0; comp->param_pass_num_default_params = 0; @@ -876,12 +876,12 @@ qstr compile_classdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint // nodes[1] has parent classes, if any if (MP_PARSE_NODE_IS_NULL(pns->nodes[1])) { // no parent classes - EMIT(call_function, 2, 0, MP_FALSE, MP_FALSE); + EMIT(call_function, 2, 0, false, false); } else { // have a parent class or classes // TODO what if we have, eg, *a or **a in the parent list? compile_node(comp, pns->nodes[1]); - EMIT(call_function, 2 + list_len(pns->nodes[1], PN_arglist), 0, MP_FALSE, MP_FALSE); + EMIT(call_function, 2 + list_len(pns->nodes[1], PN_arglist), 0, false, false); } // return its name (the 'C' in class C(...):") @@ -889,14 +889,14 @@ qstr compile_classdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint } // returns true if it was a built-in decorator (even if the built-in had an error) -static MP_BOOL compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_node_t *name_nodes, uint *emit_options) { +static bool compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_node_t *name_nodes, uint *emit_options) { if (MP_PARSE_NODE_LEAF_ARG(name_nodes[0]) != MP_QSTR_micropython) { - return MP_FALSE; + return false; } if (name_len != 2) { printf("SyntaxError: invalid micropython decorator\n"); - return MP_TRUE; + return true; } qstr attr = MP_PARSE_NODE_LEAF_ARG(name_nodes[1]); @@ -916,7 +916,7 @@ static MP_BOOL compile_built_in_decorator(compiler_t *comp, int name_len, mp_par printf("SyntaxError: invalid micropython decorator '%s'\n", qstr_str(attr)); } - return MP_TRUE; + return true; } void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) { @@ -974,7 +974,7 @@ void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) { // call each decorator for (int i = 0; i < n - num_built_in_decorators; i++) { - EMIT(call_function, 1, 0, MP_FALSE, MP_FALSE); + EMIT(call_function, 1, 0, false, false); } // store func/class object into name @@ -1094,7 +1094,7 @@ void compile_continue_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { if (comp->scope_cur->kind != SCOPE_FUNCTION) { printf("SyntaxError: 'return' outside function\n"); - comp->had_error = MP_TRUE; + comp->had_error = true; return; } if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { @@ -1106,7 +1106,7 @@ void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { mp_parse_node_struct_t *pns_test_if_else = (mp_parse_node_struct_t*)pns_test_if_expr->nodes[1]; int l_fail = comp_next_label(comp); - c_if_cond(comp, pns_test_if_else->nodes[0], MP_FALSE, l_fail); // condition + c_if_cond(comp, pns_test_if_else->nodes[0], false, l_fail); // condition compile_node(comp, pns_test_if_expr->nodes[0]); // success value EMIT(return_value); EMIT(label_assign, l_fail); @@ -1143,13 +1143,13 @@ void compile_raise_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // eg a -> q1=q2=a // a.b.c -> q1=a, q2=a.b.c void do_import_name(compiler_t *comp, mp_parse_node_t pn, qstr *q1, qstr *q2) { - MP_BOOL is_as = MP_FALSE; + bool is_as = false; if (MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_dotted_as_name)) { mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn; // a name of the form x as y; unwrap it *q1 = MP_PARSE_NODE_LEAF_ARG(pns->nodes[1]); pn = pns->nodes[0]; - is_as = MP_TRUE; + is_as = true; } if (MP_PARSE_NODE_IS_ID(pn)) { // just a simple name @@ -1220,7 +1220,7 @@ void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) { #if MICROPY_EMIT_CPYTHON EMIT(load_const_verbatim_str, "('*',)"); #else - EMIT(load_const_str, qstr_from_str_static("*"), MP_FALSE); + EMIT(load_const_str, qstr_from_str_static("*"), false); EMIT(build_tuple, 1); #endif @@ -1262,7 +1262,7 @@ void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) { assert(MP_PARSE_NODE_IS_STRUCT_KIND(pn_nodes[i], PN_import_as_name)); mp_parse_node_struct_t *pns3 = (mp_parse_node_struct_t*)pn_nodes[i]; qstr id2 = MP_PARSE_NODE_LEAF_ARG(pns3->nodes[0]); // should be id - EMIT(load_const_str, id2, MP_FALSE); + EMIT(load_const_str, id2, false); } EMIT(build_tuple, n); #endif @@ -1315,12 +1315,12 @@ void compile_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { int l_end = comp_next_label(comp); - c_if_cond(comp, pns->nodes[0], MP_TRUE, l_end); + c_if_cond(comp, pns->nodes[0], true, l_end); EMIT(load_id, MP_QSTR_AssertionError); if (!MP_PARSE_NODE_IS_NULL(pns->nodes[1])) { // assertion message compile_node(comp, pns->nodes[1]); - EMIT(call_function, 1, 0, MP_FALSE, MP_FALSE); + EMIT(call_function, 1, 0, false, false); } EMIT(raise_varargs, 1); EMIT(label_assign, l_end); @@ -1332,7 +1332,7 @@ void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { int l_end = comp_next_label(comp); int l_fail = comp_next_label(comp); - c_if_cond(comp, pns->nodes[0], MP_FALSE, l_fail); // if condition + c_if_cond(comp, pns->nodes[0], false, l_fail); // if condition compile_node(comp, pns->nodes[1]); // if block //if (!(MP_PARSE_NODE_IS_NULL(pns->nodes[2]) && MP_PARSE_NODE_IS_NULL(pns->nodes[3]))) { // optimisation; doesn't align with CPython @@ -1355,7 +1355,7 @@ void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { for (int i = 0; i < n; i++) { mp_parse_node_struct_t *pns_elif2 = (mp_parse_node_struct_t*)pns_elif->nodes[i]; l_fail = comp_next_label(comp); - c_if_cond(comp, pns_elif2->nodes[0], MP_FALSE, l_fail); // elif condition + c_if_cond(comp, pns_elif2->nodes[0], false, l_fail); // elif condition compile_node(comp, pns_elif2->nodes[1]); // elif block if (!EMIT(last_emit_was_return_value)) { // simple optimisation to align with CPython @@ -1368,7 +1368,7 @@ void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // a single elif block l_fail = comp_next_label(comp); - c_if_cond(comp, pns_elif->nodes[0], MP_FALSE, l_fail); // elif condition + c_if_cond(comp, pns_elif->nodes[0], false, l_fail); // elif condition compile_node(comp, pns_elif->nodes[1]); // elif block if (!EMIT(last_emit_was_return_value)) { // simple optimisation to align with CPython @@ -1399,7 +1399,7 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { int done_label = comp_next_label(comp); EMIT(setup_loop, break_label); EMIT(label_assign, continue_label); - c_if_cond(comp, pns->nodes[0], MP_FALSE, done_label); // condition + c_if_cond(comp, pns->nodes[0], false, done_label); // condition compile_node(comp, pns->nodes[1]); // body if (!EMIT(last_emit_was_return_value)) { EMIT(jump, continue_label); @@ -1416,7 +1416,7 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { EMIT(label_assign, top_label); compile_node(comp, pns->nodes[1]); // body EMIT(label_assign, continue_label); - c_if_cond(comp, pns->nodes[0], MP_TRUE, top_label); // condition + c_if_cond(comp, pns->nodes[0], true, top_label); // condition #endif // break/continue apply to outer loop (if any) in the else block @@ -1732,7 +1732,7 @@ void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // for REPL, evaluate then print the expression EMIT(load_id, MP_QSTR___repl_print__); compile_node(comp, pns->nodes[0]); - EMIT(call_function, 1, 0, MP_FALSE, MP_FALSE); + EMIT(call_function, 1, 0, false, false); EMIT(pop_top); } else { @@ -1837,7 +1837,7 @@ void compile_test_if_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { int stack_size = EMIT(get_stack_size); int l_fail = comp_next_label(comp); int l_end = comp_next_label(comp); - c_if_cond(comp, pns_test_if_else->nodes[0], MP_FALSE, l_fail); // condition + c_if_cond(comp, pns_test_if_else->nodes[0], false, l_fail); // condition compile_node(comp, pns->nodes[0]); // success value EMIT(jump, l_end); EMIT(label_assign, l_fail); @@ -1898,7 +1898,7 @@ void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) { int stack_size = EMIT(get_stack_size); int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); compile_node(comp, pns->nodes[0]); - MP_BOOL multi = (num_nodes > 3); + bool multi = (num_nodes > 3); int l_fail = 0; if (multi) { l_fail = comp_next_label(comp); @@ -2042,15 +2042,15 @@ void compile_factor_2(compiler_t *comp, mp_parse_node_struct_t *pns) { } } -void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_struct_t *pns, MP_BOOL is_method_call) { +void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_struct_t *pns, bool is_method_call) { // function to call is on top of stack int old_n_arg_keyword = comp->n_arg_keyword; - MP_BOOL old_have_star_arg = comp->have_star_arg; - MP_BOOL old_have_dbl_star_arg = comp->have_dbl_star_arg; + bool old_have_star_arg = comp->have_star_arg; + bool old_have_dbl_star_arg = comp->have_dbl_star_arg; comp->n_arg_keyword = 0; - comp->have_star_arg = MP_FALSE; - comp->have_dbl_star_arg = MP_FALSE; + comp->have_star_arg = false; + comp->have_dbl_star_arg = false; compile_node(comp, pns->nodes[0]); // arguments to function call; can be null @@ -2082,7 +2082,7 @@ void compile_power_trailers(compiler_t *comp, mp_parse_node_struct_t *pns) { mp_parse_node_struct_t *pns_period = (mp_parse_node_struct_t*)pns->nodes[i]; mp_parse_node_struct_t *pns_paren = (mp_parse_node_struct_t*)pns->nodes[i + 1]; EMIT(load_method, MP_PARSE_NODE_LEAF_ARG(pns_period->nodes[0])); // get the method - compile_trailer_paren_helper(comp, pns_paren, MP_TRUE); + compile_trailer_paren_helper(comp, pns_paren, true); i += 1; } else { compile_node(comp, pns->nodes[i]); @@ -2153,7 +2153,7 @@ void compile_comprehension(compiler_t *comp, mp_parse_node_struct_t *pns, scope_ compile_node(comp, pns_comp_for->nodes[1]); // source of the iterator EMIT(get_iter); - EMIT(call_function, 1, 0, MP_FALSE, MP_FALSE); + EMIT(call_function, 1, 0, false, false); } void compile_atom_paren(compiler_t *comp, mp_parse_node_struct_t *pns) { @@ -2252,23 +2252,23 @@ void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) { int n = list_get(&pns1->nodes[0], PN_dictorsetmaker_list2, &nodes); // first element sets whether it's a dict or set - MP_BOOL is_dict; + bool is_dict; if (MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[0], PN_dictorsetmaker_item)) { // a dictionary EMIT(build_map, 1 + n); compile_node(comp, pns->nodes[0]); EMIT(store_map); - is_dict = MP_TRUE; + is_dict = true; } else { // a set compile_node(comp, pns->nodes[0]); // 1st value of set - is_dict = MP_FALSE; + is_dict = false; } // process rest of elements for (int i = 0; i < n; i++) { mp_parse_node_t pn = nodes[i]; - MP_BOOL is_key_value = MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_dictorsetmaker_item); + bool is_key_value = MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_dictorsetmaker_item); compile_node(comp, pn); if (is_dict) { if (!is_key_value) { @@ -2314,7 +2314,7 @@ void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) { } void compile_trailer_paren(compiler_t *comp, mp_parse_node_struct_t *pns) { - compile_trailer_paren_helper(comp, pns, MP_FALSE); + compile_trailer_paren_helper(comp, pns, false); } void compile_trailer_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) { @@ -2401,7 +2401,7 @@ void compile_arglist_star(compiler_t *comp, mp_parse_node_struct_t *pns) { printf("SyntaxError?: can't have multiple *x\n"); return; } - comp->have_star_arg = MP_TRUE; + comp->have_star_arg = true; compile_node(comp, pns->nodes[0]); } @@ -2410,7 +2410,7 @@ void compile_arglist_dbl_star(compiler_t *comp, mp_parse_node_struct_t *pns) { printf("SyntaxError?: can't have multiple **x\n"); return; } - comp->have_dbl_star_arg = MP_TRUE; + comp->have_dbl_star_arg = true; compile_node(comp, pns->nodes[0]); } @@ -2475,8 +2475,8 @@ void compile_node(compiler_t *comp, mp_parse_node_t pn) { case MP_PARSE_NODE_SMALL_INT: EMIT(load_const_small_int, arg); break; case MP_PARSE_NODE_INTEGER: EMIT(load_const_int, arg); break; case MP_PARSE_NODE_DECIMAL: EMIT(load_const_dec, arg); break; - case MP_PARSE_NODE_STRING: EMIT(load_const_str, arg, MP_FALSE); break; - case MP_PARSE_NODE_BYTES: EMIT(load_const_str, arg, MP_TRUE); break; + case MP_PARSE_NODE_STRING: EMIT(load_const_str, arg, false); break; + case MP_PARSE_NODE_BYTES: EMIT(load_const_str, arg, true); break; case MP_PARSE_NODE_TOKEN: if (arg == MP_TOKEN_NEWLINE) { // this can occur when file_input lets through a NEWLINE (eg if file starts with a newline) @@ -2501,7 +2501,7 @@ void compile_node(compiler_t *comp, mp_parse_node_t pn) { } } -void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_kind_t pn_name, pn_kind_t pn_star, pn_kind_t pn_dbl_star, MP_BOOL allow_annotations) { +void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_kind_t pn_name, pn_kind_t pn_star, pn_kind_t pn_dbl_star, bool allow_annotations) { // TODO verify that *k and **k are last etc qstr param_name = 0; mp_parse_node_t pn_annotation = MP_PARSE_NODE_NULL; @@ -2544,7 +2544,7 @@ void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_ki if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { // bare star // TODO see http://www.python.org/dev/peps/pep-3102/ - comp->have_bare_star = MP_TRUE; + comp->have_bare_star = true; //assert(comp->scope_cur->num_dict_params == 0); } else if (MP_PARSE_NODE_IS_ID(pns->nodes[0])) { // named star @@ -2577,23 +2577,23 @@ void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_ki if (!MP_PARSE_NODE_IS_NULL(pn_annotation)) { // TODO this parameter has an annotation } - MP_BOOL added; + bool added; id_info_t *id_info = scope_find_or_add_id(comp->scope_cur, param_name, &added); if (!added) { printf("SyntaxError?: same name used for parameter; %s\n", qstr_str(param_name)); return; } - id_info->param = MP_TRUE; + id_info->param = true; id_info->kind = ID_INFO_KIND_LOCAL; } } void compile_scope_func_param(compiler_t *comp, mp_parse_node_t pn) { - compile_scope_func_lambda_param(comp, pn, PN_typedargslist_name, PN_typedargslist_star, PN_typedargslist_dbl_star, MP_TRUE); + compile_scope_func_lambda_param(comp, pn, PN_typedargslist_name, PN_typedargslist_star, PN_typedargslist_dbl_star, true); } void compile_scope_lambda_param(compiler_t *comp, mp_parse_node_t pn) { - compile_scope_func_lambda_param(comp, pn, PN_varargslist_name, PN_varargslist_star, PN_varargslist_dbl_star, MP_FALSE); + compile_scope_func_lambda_param(comp, pn, PN_varargslist_name, PN_varargslist_star, PN_varargslist_dbl_star, false); } void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_t pn_iter, mp_parse_node_t pn_inner_expr, int l_top, int for_depth) { @@ -2614,7 +2614,7 @@ void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_t pn_iter, mp_parse } else if (MP_PARSE_NODE_IS_STRUCT_KIND(pn_iter, PN_comp_if)) { // if condition mp_parse_node_struct_t *pns_comp_if = (mp_parse_node_struct_t*)pn_iter; - c_if_cond(comp, pns_comp_if->nodes[0], MP_FALSE, l_top); + c_if_cond(comp, pns_comp_if->nodes[0], false, l_top); pn_iter = pns_comp_if->nodes[1]; goto tail_recursion; } else if (MP_PARSE_NODE_IS_STRUCT_KIND(pn_iter, PN_comp_for)) { @@ -2708,7 +2708,7 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { // work out number of parameters, keywords and default parameters, and add them to the id_info array // must be done before compiling the body so that arguments are numbered first (for LOAD_FAST etc) if (comp->pass == PASS_1) { - comp->have_bare_star = MP_FALSE; + comp->have_bare_star = false; apply_to_single_or_list(comp, pns->nodes[1], PN_typedargslist, compile_scope_func_param); } @@ -2728,7 +2728,7 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { // work out number of parameters, keywords and default parameters, and add them to the id_info array // must be done before compiling the body so that arguments are numbered first (for LOAD_FAST etc) if (comp->pass == PASS_1) { - comp->have_bare_star = MP_FALSE; + comp->have_bare_star = false; apply_to_single_or_list(comp, pns->nodes[0], PN_varargslist, compile_scope_lambda_param); } @@ -2745,7 +2745,7 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { qstr qstr_arg = qstr_from_str_static(".0"); if (comp->pass == PASS_1) { - MP_BOOL added; + bool added; id_info_t *id_info = scope_find_or_add_id(comp->scope_cur, qstr_arg, &added); assert(added); id_info->kind = ID_INFO_KIND_LOCAL; @@ -2782,14 +2782,14 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { assert(MP_PARSE_NODE_STRUCT_KIND(pns) == PN_classdef); if (comp->pass == PASS_1) { - MP_BOOL added; + bool added; id_info_t *id_info = scope_find_or_add_id(scope, MP_QSTR___class__, &added); assert(added); id_info->kind = ID_INFO_KIND_LOCAL; id_info = scope_find_or_add_id(scope, MP_QSTR___locals__, &added); assert(added); id_info->kind = ID_INFO_KIND_LOCAL; - id_info->param = MP_TRUE; + id_info->param = true; scope->num_params = 1; // __locals__ is the parameter } @@ -3005,11 +3005,11 @@ void compile_scope_compute_things(compiler_t *comp, scope_t *scope) { } } -mp_obj_t mp_compile(mp_parse_node_t pn, MP_BOOL is_repl) { +mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl) { compiler_t *comp = m_new(compiler_t, 1); comp->is_repl = is_repl; - comp->had_error = MP_FALSE; + comp->had_error = false; comp->break_label = 0; comp->continue_label = 0; @@ -3030,7 +3030,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, MP_BOOL is_repl) { comp->emit_inline_asm_method_table = NULL; uint max_num_labels = 0; for (scope_t *s = comp->scope_head; s != NULL && !comp->had_error; s = s->next) { - if (MP_FALSE) { + if (false) { #if MICROPY_EMIT_INLINE_THUMB } else if (s->emit_options == EMIT_OPT_ASM_THUMB) { compile_scope_inline_asm(comp, s, PASS_1); @@ -3064,7 +3064,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, MP_BOOL is_repl) { #endif #endif // !MICROPY_EMIT_CPYTHON for (scope_t *s = comp->scope_head; s != NULL && !comp->had_error; s = s->next) { - if (MP_FALSE) { + if (false) { // dummy #if MICROPY_EMIT_INLINE_THUMB @@ -3126,7 +3126,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, MP_BOOL is_repl) { } } - MP_BOOL had_error = comp->had_error; + bool had_error = comp->had_error; m_del_obj(compiler_t, comp); if (had_error) { diff --git a/py/compile.h b/py/compile.h index 27e47f2f18..770c2524da 100644 --- a/py/compile.h +++ b/py/compile.h @@ -1 +1 @@ -mp_obj_t mp_compile(mp_parse_node_t pn, MP_BOOL is_repl); +mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl); diff --git a/py/emit.h b/py/emit.h index 1566438595..ea65731038 100644 --- a/py/emit.h +++ b/py/emit.h @@ -17,10 +17,10 @@ typedef enum { typedef struct _emit_t emit_t; typedef struct _emit_method_table_t { - void (*set_native_types)(emit_t *emit, MP_BOOL do_native_types); + void (*set_native_types)(emit_t *emit, bool do_native_types); void (*start_pass)(emit_t *emit, pass_kind_t pass, scope_t *scope); void (*end_pass)(emit_t *emit); - MP_BOOL (*last_emit_was_return_value)(emit_t *emit); + bool (*last_emit_was_return_value)(emit_t *emit); int (*get_stack_size)(emit_t *emit); void (*set_stack_size)(emit_t *emit, int size); @@ -37,7 +37,7 @@ typedef struct _emit_method_table_t { void (*load_const_int)(emit_t *emit, qstr qstr); void (*load_const_dec)(emit_t *emit, qstr qstr); void (*load_const_id)(emit_t *emit, qstr qstr); - void (*load_const_str)(emit_t *emit, qstr qstr, MP_BOOL bytes); + void (*load_const_str)(emit_t *emit, qstr qstr, bool bytes); void (*load_const_verbatim_str)(emit_t *emit, const char *str); // only needed for emitcpy void (*load_fast)(emit_t *emit, qstr qstr, int local_num); void (*load_deref)(emit_t *emit, qstr qstr, int local_num); @@ -99,8 +99,8 @@ typedef struct _emit_method_table_t { void (*unpack_ex)(emit_t *emit, int n_left, int n_right); void (*make_function)(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params); void (*make_closure)(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params); - void (*call_function)(emit_t *emit, int n_positional, int n_keyword, MP_BOOL have_star_arg, MP_BOOL have_dbl_star_arg); - void (*call_method)(emit_t *emit, int n_positional, int n_keyword, MP_BOOL have_star_arg, MP_BOOL have_dbl_star_arg); + void (*call_function)(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg); + void (*call_method)(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg); void (*return_value)(emit_t *emit); void (*raise_varargs)(emit_t *emit, int n_args); void (*yield_value)(emit_t *emit); diff --git a/py/emitbc.c b/py/emitbc.c index 93c92f41fa..c0ec2469a6 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -17,7 +17,7 @@ struct _emit_t { pass_kind_t pass; int stack_size; - MP_BOOL last_emit_was_return_value; + bool last_emit_was_return_value; scope_t *scope; @@ -135,13 +135,13 @@ static void emit_write_byte_1_signed_label(emit_t* emit, byte b1, int label) { c[2] = code_offset >> 8; } -static void emit_bc_set_native_types(emit_t *emit, MP_BOOL do_native_types) { +static void emit_bc_set_native_types(emit_t *emit, bool do_native_types) { } static void emit_bc_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) { emit->pass = pass; emit->stack_size = 0; - emit->last_emit_was_return_value = MP_FALSE; + emit->last_emit_was_return_value = false; emit->scope = scope; if (pass == PASS_2) { memset(emit->label_offsets, -1, emit->max_num_labels * sizeof(uint)); @@ -182,7 +182,7 @@ static void emit_bc_end_pass(emit_t *emit) { } } -MP_BOOL emit_bc_last_emit_was_return_value(emit_t *emit) { +bool emit_bc_last_emit_was_return_value(emit_t *emit) { return emit->last_emit_was_return_value; } @@ -211,7 +211,7 @@ static void emit_pre(emit_t *emit, int stack_size_delta) { if (emit->stack_size > emit->scope->stack_size) { emit->scope->stack_size = emit->stack_size; } - emit->last_emit_was_return_value = MP_FALSE; + emit->last_emit_was_return_value = false; } static void emit_bc_label_assign(emit_t *emit, int l) { @@ -274,7 +274,7 @@ static void emit_bc_load_const_id(emit_t *emit, qstr qstr) { emit_write_byte_1_qstr(emit, MP_BC_LOAD_CONST_ID, qstr); } -static void emit_bc_load_const_str(emit_t *emit, qstr qstr, MP_BOOL bytes) { +static void emit_bc_load_const_str(emit_t *emit, qstr qstr, bool bytes) { emit_pre(emit, 1); if (bytes) { emit_write_byte_1_qstr(emit, MP_BC_LOAD_CONST_BYTES, qstr); @@ -613,7 +613,7 @@ static void emit_bc_make_closure(emit_t *emit, scope_t *scope, int n_dict_params emit_write_byte_1_uint(emit, MP_BC_MAKE_CLOSURE, scope->unique_code_id); } -static void emit_bc_call_function(emit_t *emit, int n_positional, int n_keyword, MP_BOOL have_star_arg, MP_BOOL have_dbl_star_arg) { +static void emit_bc_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { int s = 0; if (have_star_arg) { s += 1; @@ -639,7 +639,7 @@ static void emit_bc_call_function(emit_t *emit, int n_positional, int n_keyword, emit_write_byte_1_uint(emit, op, (n_keyword << 8) | n_positional); // TODO make it 2 separate uints } -static void emit_bc_call_method(emit_t *emit, int n_positional, int n_keyword, MP_BOOL have_star_arg, MP_BOOL have_dbl_star_arg) { +static void emit_bc_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { int s = 0; if (have_star_arg) { s += 1; @@ -667,7 +667,7 @@ static void emit_bc_call_method(emit_t *emit, int n_positional, int n_keyword, M static void emit_bc_return_value(emit_t *emit) { emit_pre(emit, -1); - emit->last_emit_was_return_value = MP_TRUE; + emit->last_emit_was_return_value = true; emit_write_byte_1(emit, MP_BC_RETURN_VALUE); } diff --git a/py/emitcpy.c b/py/emitcpy.c index ff44609d58..7b2d50fb7e 100644 --- a/py/emitcpy.c +++ b/py/emitcpy.c @@ -20,7 +20,7 @@ struct _emit_t { int pass; int byte_code_offset; int stack_size; - MP_BOOL last_emit_was_return_value; + bool last_emit_was_return_value; scope_t *scope; @@ -35,14 +35,14 @@ emit_t *emit_cpython_new(uint max_num_labels) { return emit; } -static void emit_cpy_set_native_types(emit_t *emit, MP_BOOL do_native_types) { +static void emit_cpy_set_native_types(emit_t *emit, bool do_native_types) { } static void emit_cpy_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) { emit->pass = pass; emit->byte_code_offset = 0; emit->stack_size = 0; - emit->last_emit_was_return_value = MP_FALSE; + emit->last_emit_was_return_value = false; emit->scope = scope; if (pass == PASS_2) { memset(emit->label_offsets, -1, emit->max_num_labels * sizeof(int)); @@ -56,7 +56,7 @@ static void emit_cpy_end_pass(emit_t *emit) { } } -static MP_BOOL emit_cpy_last_emit_was_return_value(emit_t *emit) { +static bool emit_cpy_last_emit_was_return_value(emit_t *emit) { return emit->last_emit_was_return_value; } @@ -85,7 +85,7 @@ static void emit_pre(emit_t *emit, int stack_size_delta, int byte_code_size) { if (emit->stack_size > emit->scope->stack_size) { emit->scope->stack_size = emit->stack_size; } - emit->last_emit_was_return_value = MP_FALSE; + emit->last_emit_was_return_value = false; if (emit->pass == PASS_3 && byte_code_size > 0) { if (emit->byte_code_offset >= 1000) { printf("%d ", emit->byte_code_offset); @@ -173,26 +173,26 @@ static void emit_cpy_load_const_id(emit_t *emit, qstr qstr) { } } -static void print_quoted_str(qstr qstr, MP_BOOL bytes) { +static void print_quoted_str(qstr qstr, bool bytes) { const char *str = qstr_str(qstr); int len = strlen(str); - MP_BOOL has_single_quote = MP_FALSE; - MP_BOOL has_double_quote = MP_FALSE; + bool has_single_quote = false; + bool has_double_quote = false; for (int i = 0; i < len; i++) { if (str[i] == '\'') { - has_single_quote = MP_TRUE; + has_single_quote = true; } else if (str[i] == '"') { - has_double_quote = MP_TRUE; + has_double_quote = true; } } if (bytes) { printf("b"); } - MP_BOOL quote_single = MP_FALSE; + bool quote_single = false; if (has_single_quote && !has_double_quote) { printf("\""); } else { - quote_single = MP_TRUE; + quote_single = true; printf("'"); } for (int i = 0; i < len; i++) { @@ -213,7 +213,7 @@ static void print_quoted_str(qstr qstr, MP_BOOL bytes) { } } -static void emit_cpy_load_const_str(emit_t *emit, qstr qstr, MP_BOOL bytes) { +static void emit_cpy_load_const_str(emit_t *emit, qstr qstr, bool bytes) { emit_pre(emit, 1, 3); if (emit->pass == PASS_3) { printf("LOAD_CONST "); @@ -681,7 +681,7 @@ static void emit_cpy_unpack_ex(emit_t *emit, int n_left, int n_right) { } } -static void emit_cpy_call_function(emit_t *emit, int n_positional, int n_keyword, MP_BOOL have_star_arg, MP_BOOL have_dbl_star_arg) { +static void emit_cpy_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { int s = 0; if (have_star_arg) { s += 1; @@ -708,13 +708,13 @@ static void emit_cpy_call_function(emit_t *emit, int n_positional, int n_keyword } } -static void emit_cpy_call_method(emit_t *emit, int n_positional, int n_keyword, MP_BOOL have_star_arg, MP_BOOL have_dbl_star_arg) { +static void emit_cpy_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { emit_cpy_call_function(emit, n_positional, n_keyword, have_star_arg, have_dbl_star_arg); } static void emit_cpy_return_value(emit_t *emit) { emit_pre(emit, -1, 1); - emit->last_emit_was_return_value = MP_TRUE; + emit->last_emit_was_return_value = true; if (emit->pass == PASS_3) { printf("RETURN_VALUE\n"); } diff --git a/py/emitinlinethumb.c b/py/emitinlinethumb.c index 9dc9a7a798..073dfa0604 100644 --- a/py/emitinlinethumb.c +++ b/py/emitinlinethumb.c @@ -75,12 +75,12 @@ static void emit_inline_thumb_label(emit_inline_asm_t *emit, int label_num, qstr asm_thumb_label_assign(emit->as, label_num); } -static MP_BOOL check_n_arg(qstr op, int n_args, int wanted_n_args) { +static bool check_n_arg(qstr op, int n_args, int wanted_n_args) { if (wanted_n_args == n_args) { - return MP_TRUE; + return true; } else { printf("SyntaxError: '%s' expects %d arguments'\n", qstr_str(op), wanted_n_args); - return MP_FALSE; + return false; } } diff --git a/py/emitnative.c b/py/emitnative.c index fd2ee57087..cc00c57319 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -52,7 +52,7 @@ #define REG_TEMP2 (REG_RSI) #define ASM_MOV_REG_TO_LOCAL(reg, local_num) asm_x64_mov_r64_to_local(emit->as, (reg), (local_num)) #define ASM_MOV_IMM_TO_REG(imm, reg) asm_x64_mov_i64_to_r64_optimised(emit->as, (imm), (reg)) -#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_x64_mov_i64_to_r64_optimised(emit->as, (imm), (reg_temp)); asm_x64_mov_r64_to_local(emit->as, (reg_temp), (local_num)); } while (MP_FALSE) +#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_x64_mov_i64_to_r64_optimised(emit->as, (imm), (reg_temp)); asm_x64_mov_r64_to_local(emit->as, (reg_temp), (local_num)); } while (false) #define ASM_MOV_LOCAL_TO_REG(local_num, reg) asm_x64_mov_local_to_r64(emit->as, (local_num), (reg)) #define ASM_MOV_REG_TO_REG(reg_src, reg_dest) asm_x64_mov_r64_to_r64(emit->as, (reg_src), (reg_dest)) #define ASM_MOV_LOCAL_ADDR_TO_REG(local_num, reg) asm_x64_mov_local_addr_to_r64(emit->as, (local_num), (reg)) @@ -75,7 +75,7 @@ #define REG_TEMP2 (REG_R2) #define ASM_MOV_REG_TO_LOCAL(reg, local_num) asm_thumb_mov_local_reg(emit->as, (local_num), (reg)) #define ASM_MOV_IMM_TO_REG(imm, reg) asm_thumb_mov_reg_i32_optimised(emit->as, (reg), (imm)) -#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_thumb_mov_reg_i32_optimised(emit->as, (reg_temp), (imm)); asm_thumb_mov_local_reg(emit->as, (local_num), (reg_temp)); } while (MP_FALSE) +#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_thumb_mov_reg_i32_optimised(emit->as, (reg_temp), (imm)); asm_thumb_mov_local_reg(emit->as, (local_num), (reg_temp)); } while (false) #define ASM_MOV_LOCAL_TO_REG(local_num, reg) asm_thumb_mov_reg_local(emit->as, (reg), (local_num)) #define ASM_MOV_REG_TO_REG(reg_src, reg_dest) asm_thumb_mov_reg_reg(emit->as, (reg_dest), (reg_src)) #define ASM_MOV_LOCAL_ADDR_TO_REG(local_num, reg) asm_thumb_mov_reg_local_addr(emit->as, (reg), (local_num)) @@ -110,7 +110,7 @@ typedef struct _stack_info_t { struct _emit_t { int pass; - MP_BOOL do_viper_types; + bool do_viper_types; int local_vtype_alloc; vtype_kind_t *local_vtype; @@ -121,7 +121,7 @@ struct _emit_t { int stack_start; int stack_size; - MP_BOOL last_emit_was_return_value; + bool last_emit_was_return_value; scope_t *scope; @@ -134,7 +134,7 @@ struct _emit_t { emit_t *EXPORT_FUN(new)(uint max_num_labels) { emit_t *emit = m_new(emit_t, 1); - emit->do_viper_types = MP_FALSE; + emit->do_viper_types = false; emit->local_vtype = NULL; emit->stack_info = NULL; #if N_X64 @@ -145,7 +145,7 @@ emit_t *EXPORT_FUN(new)(uint max_num_labels) { return emit; } -static void emit_native_set_viper_types(emit_t *emit, MP_BOOL do_viper_types) { +static void emit_native_set_viper_types(emit_t *emit, bool do_viper_types) { emit->do_viper_types = do_viper_types; } @@ -153,7 +153,7 @@ static void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop emit->pass = pass; emit->stack_start = 0; emit->stack_size = 0; - emit->last_emit_was_return_value = MP_FALSE; + emit->last_emit_was_return_value = false; emit->scope = scope; if (emit->local_vtype == NULL) { @@ -269,7 +269,7 @@ static void emit_native_end_pass(emit_t *emit) { } } -static MP_BOOL emit_native_last_emit_was_return_value(emit_t *emit) { +static bool emit_native_last_emit_was_return_value(emit_t *emit) { return emit->last_emit_was_return_value; } @@ -292,13 +292,13 @@ static void adjust_stack(emit_t *emit, int stack_size_delta) { /* static void emit_pre_raw(emit_t *emit, int stack_size_delta) { adjust_stack(emit, stack_size_delta); - emit->last_emit_was_return_value = MP_FALSE; + emit->last_emit_was_return_value = false; } */ // this must be called at start of emit functions static void emit_pre(emit_t *emit) { - emit->last_emit_was_return_value = MP_FALSE; + emit->last_emit_was_return_value = false; // settle the stack /* if (regs_needed != 0) { @@ -391,7 +391,7 @@ static void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int re } static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg_dest) { - emit->last_emit_was_return_value = MP_FALSE; + emit->last_emit_was_return_value = false; emit_access_stack(emit, 1, vtype, reg_dest); adjust_stack(emit, -1); } @@ -618,7 +618,7 @@ static void emit_native_load_const_id(emit_t *emit, qstr qstr) { } } -static void emit_native_load_const_str(emit_t *emit, qstr qstr, MP_BOOL bytes) { +static void emit_native_load_const_str(emit_t *emit, qstr qstr, bool bytes) { emit_pre(emit); if (emit->do_viper_types) { // not implemented properly @@ -1134,7 +1134,7 @@ static void emit_native_make_closure(emit_t *emit, scope_t *scope, int n_dict_pa assert(0); } -static void emit_native_call_function(emit_t *emit, int n_positional, int n_keyword, MP_BOOL have_star_arg, MP_BOOL have_dbl_star_arg) { +static void emit_native_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { // call special viper runtime routine with type info for args, and wanted type info for return assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg); /* @@ -1170,7 +1170,7 @@ static void emit_native_call_function(emit_t *emit, int n_positional, int n_keyw emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -static void emit_native_call_method(emit_t *emit, int n_positional, int n_keyword, MP_BOOL have_star_arg, MP_BOOL have_dbl_star_arg) { +static void emit_native_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg); /* if (n_positional == 0) { @@ -1205,7 +1205,7 @@ static void emit_native_return_value(emit_t *emit) { } else { assert(vtype == VTYPE_PYOBJ); } - emit->last_emit_was_return_value = MP_TRUE; + emit->last_emit_was_return_value = true; #if N_X64 //asm_x64_call_ind(emit->as, 0, REG_RAX); to seg fault for debugging with gdb asm_x64_exit(emit->as); diff --git a/py/emitpass1.c b/py/emitpass1.c index 45197cb41a..f78ec7e27e 100644 --- a/py/emitpass1.c +++ b/py/emitpass1.c @@ -42,7 +42,7 @@ static void emit_pass1_end_pass(emit_t *emit) { static void emit_pass1_load_id(emit_t *emit, qstr qstr) { // name adding/lookup - MP_BOOL added; + bool added; id_info_t *id = scope_find_or_add_id(emit->scope, qstr, &added); if (added) { if (qstr == MP_QSTR_AssertionError) { @@ -73,7 +73,7 @@ static void emit_pass1_load_id(emit_t *emit, qstr qstr) { static id_info_t *get_id_for_modification(scope_t *scope, qstr qstr) { // name adding/lookup - MP_BOOL added; + bool added; id_info_t *id = scope_find_or_add_id(scope, qstr, &added); if (added) { if (scope->kind == SCOPE_MODULE || scope->kind == SCOPE_CLASS) { diff --git a/py/lexer.c b/py/lexer.c index 7e18792b51..d4205236c3 100644 --- a/py/lexer.c +++ b/py/lexer.c @@ -35,7 +35,7 @@ struct _mp_lexer_t { mp_token_t tok_cur; }; -MP_BOOL str_strn_equal(const char *str, const char *strn, int len) { +bool str_strn_equal(const char *str, const char *strn, int len) { uint i = 0; while (i < len && *str == *strn) { @@ -70,74 +70,74 @@ void mp_token_show_error_prefix(const mp_token_t *tok) { printf("(%s:%d:%d) ", tok->src_name, tok->src_line, tok->src_column); } -MP_BOOL mp_token_show_error(const mp_token_t *tok, const char *msg) { +bool mp_token_show_error(const mp_token_t *tok, const char *msg) { printf("(%s:%d:%d) %s\n", tok->src_name, tok->src_line, tok->src_column, msg); - return MP_FALSE; + return false; } #define CUR_CHAR(lex) ((lex)->chr0) -static MP_BOOL is_end(mp_lexer_t *lex) { +static bool is_end(mp_lexer_t *lex) { return lex->chr0 == MP_LEXER_CHAR_EOF; } -static MP_BOOL is_physical_newline(mp_lexer_t *lex) { +static bool is_physical_newline(mp_lexer_t *lex) { return lex->chr0 == '\n' || lex->chr0 == '\r'; } -static MP_BOOL is_char(mp_lexer_t *lex, char c) { +static bool is_char(mp_lexer_t *lex, char c) { return lex->chr0 == c; } -static MP_BOOL is_char_or(mp_lexer_t *lex, char c1, char c2) { +static bool is_char_or(mp_lexer_t *lex, char c1, char c2) { return lex->chr0 == c1 || lex->chr0 == c2; } -static MP_BOOL is_char_or3(mp_lexer_t *lex, char c1, char c2, char c3) { +static bool is_char_or3(mp_lexer_t *lex, char c1, char c2, char c3) { return lex->chr0 == c1 || lex->chr0 == c2 || lex->chr0 == c3; } /* -static MP_BOOL is_char_following(mp_lexer_t *lex, char c) { +static bool is_char_following(mp_lexer_t *lex, char c) { return lex->chr1 == c; } */ -static MP_BOOL is_char_following_or(mp_lexer_t *lex, char c1, char c2) { +static bool is_char_following_or(mp_lexer_t *lex, char c1, char c2) { return lex->chr1 == c1 || lex->chr1 == c2; } -static MP_BOOL is_char_following_following_or(mp_lexer_t *lex, char c1, char c2) { +static bool is_char_following_following_or(mp_lexer_t *lex, char c1, char c2) { return lex->chr2 == c1 || lex->chr2 == c2; } -static MP_BOOL is_char_and(mp_lexer_t *lex, char c1, char c2) { +static bool is_char_and(mp_lexer_t *lex, char c1, char c2) { return lex->chr0 == c1 && lex->chr1 == c2; } -static MP_BOOL is_whitespace(mp_lexer_t *lex) { +static bool is_whitespace(mp_lexer_t *lex) { return unichar_isspace(lex->chr0); } -static MP_BOOL is_letter(mp_lexer_t *lex) { +static bool is_letter(mp_lexer_t *lex) { return unichar_isalpha(lex->chr0); } -static MP_BOOL is_digit(mp_lexer_t *lex) { +static bool is_digit(mp_lexer_t *lex) { return unichar_isdigit(lex->chr0); } -static MP_BOOL is_following_digit(mp_lexer_t *lex) { +static bool is_following_digit(mp_lexer_t *lex) { return unichar_isdigit(lex->chr1); } // TODO UNICODE include unicode characters in definition of identifiers -static MP_BOOL is_head_of_identifier(mp_lexer_t *lex) { +static bool is_head_of_identifier(mp_lexer_t *lex) { return is_letter(lex) || lex->chr0 == '_'; } // TODO UNICODE include unicode characters in definition of identifiers -static MP_BOOL is_tail_of_identifier(mp_lexer_t *lex) { +static bool is_tail_of_identifier(mp_lexer_t *lex) { return is_head_of_identifier(lex) || is_digit(lex); } @@ -280,12 +280,12 @@ static const char *tok_kw[] = { NULL, }; -static void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, MP_BOOL first_token) { +static void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool first_token) { // skip white space and comments - MP_BOOL had_physical_newline = MP_FALSE; + bool had_physical_newline = false; while (!is_end(lex)) { if (is_physical_newline(lex)) { - had_physical_newline = MP_TRUE; + had_physical_newline = true; next_char(lex); } else if (is_whitespace(lex)) { next_char(lex); @@ -369,22 +369,22 @@ static void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, MP_BOOL f // a string or bytes literal // parse type codes - MP_BOOL is_raw = MP_FALSE; - MP_BOOL is_bytes = MP_FALSE; + bool is_raw = false; + bool is_bytes = false; if (is_char(lex, 'u')) { next_char(lex); } else if (is_char(lex, 'b')) { - is_bytes = MP_TRUE; + is_bytes = true; next_char(lex); if (is_char(lex, 'r')) { - is_raw = MP_TRUE; + is_raw = true; next_char(lex); } } else if (is_char(lex, 'r')) { - is_raw = MP_TRUE; + is_raw = true; next_char(lex); if (is_char(lex, 'b')) { - is_bytes = MP_TRUE; + is_bytes = true; next_char(lex); } } @@ -628,7 +628,7 @@ mp_lexer_t *mp_lexer_new(const char *src_name, void *stream_data, mp_lexer_strea } // preload first token - mp_lexer_next_token_into(lex, &lex->tok_cur, MP_TRUE); + mp_lexer_next_token_into(lex, &lex->tok_cur, true); return lex; } @@ -644,44 +644,44 @@ void mp_lexer_free(mp_lexer_t *lex) { } void mp_lexer_to_next(mp_lexer_t *lex) { - mp_lexer_next_token_into(lex, &lex->tok_cur, MP_FALSE); + mp_lexer_next_token_into(lex, &lex->tok_cur, false); } const mp_token_t *mp_lexer_cur(const mp_lexer_t *lex) { return &lex->tok_cur; } -MP_BOOL mp_lexer_is_kind(mp_lexer_t *lex, mp_token_kind_t kind) { +bool mp_lexer_is_kind(mp_lexer_t *lex, mp_token_kind_t kind) { return lex->tok_cur.kind == kind; } /* -MP_BOOL mp_lexer_is_str(mp_lexer_t *lex, const char *str) { +bool mp_lexer_is_str(mp_lexer_t *lex, const char *str) { return mp_token_is_str(&lex->tok_cur, str); } -MP_BOOL mp_lexer_opt_kind(mp_lexer_t *lex, mp_token_kind_t kind) { +bool mp_lexer_opt_kind(mp_lexer_t *lex, mp_token_kind_t kind) { if (mp_lexer_is_kind(lex, kind)) { mp_lexer_to_next(lex); - return MP_TRUE; + return true; } - return MP_FALSE; + return false; } -MP_BOOL mp_lexer_opt_str(mp_lexer_t *lex, const char *str) { +bool mp_lexer_opt_str(mp_lexer_t *lex, const char *str) { if (mp_lexer_is_str(lex, str)) { mp_lexer_to_next(lex); - return MP_TRUE; + return true; } - return MP_FALSE; + return false; } */ -MP_BOOL mp_lexer_show_error(mp_lexer_t *lex, const char *msg) { +bool mp_lexer_show_error(mp_lexer_t *lex, const char *msg) { return mp_token_show_error(&lex->tok_cur, msg); } -MP_BOOL mp_lexer_show_error_pythonic(mp_lexer_t *lex, const char *msg) { +bool mp_lexer_show_error_pythonic(mp_lexer_t *lex, const char *msg) { printf(" File \"%s\", line %d column %d\n%s\n", lex->tok_cur.src_name, lex->tok_cur.src_line, lex->tok_cur.src_column, msg); - return MP_FALSE; + return false; } diff --git a/py/lexer.h b/py/lexer.h index 9cc3e70c60..3cb48ce9e1 100644 --- a/py/lexer.h +++ b/py/lexer.h @@ -124,20 +124,20 @@ typedef struct _mp_lexer_t mp_lexer_t; void mp_token_show(const mp_token_t *tok); void mp_token_show_error_prefix(const mp_token_t *tok); -MP_BOOL mp_token_show_error(const mp_token_t *tok, const char *msg); +bool mp_token_show_error(const mp_token_t *tok, const char *msg); mp_lexer_t *mp_lexer_new(const char *src_name, void *stream_data, mp_lexer_stream_next_char_t stream_next_char, mp_lexer_stream_close_t stream_close); void mp_lexer_free(mp_lexer_t *lex); void mp_lexer_to_next(mp_lexer_t *lex); const mp_token_t *mp_lexer_cur(const mp_lexer_t *lex); -MP_BOOL mp_lexer_is_kind(mp_lexer_t *lex, mp_token_kind_t kind); +bool mp_lexer_is_kind(mp_lexer_t *lex, mp_token_kind_t kind); /* unused -MP_BOOL mp_lexer_is_str(mp_lexer_t *lex, const char *str); -MP_BOOL mp_lexer_opt_kind(mp_lexer_t *lex, mp_token_kind_t kind); -MP_BOOL mp_lexer_opt_str(mp_lexer_t *lex, const char *str); +bool mp_lexer_is_str(mp_lexer_t *lex, const char *str); +bool mp_lexer_opt_kind(mp_lexer_t *lex, mp_token_kind_t kind); +bool mp_lexer_opt_str(mp_lexer_t *lex, const char *str); */ -MP_BOOL mp_lexer_show_error(mp_lexer_t *lex, const char *msg); -MP_BOOL mp_lexer_show_error_pythonic(mp_lexer_t *lex, const char *msg); +bool mp_lexer_show_error(mp_lexer_t *lex, const char *msg); +bool mp_lexer_show_error_pythonic(mp_lexer_t *lex, const char *msg); // used to import a module; must be implemented for a specific port mp_lexer_t *mp_import_open_file(qstr mod_name); diff --git a/py/lexerunix.c b/py/lexerunix.c index 935fed0d32..14c28c16d9 100644 --- a/py/lexerunix.c +++ b/py/lexerunix.c @@ -7,7 +7,7 @@ #include "lexer.h" typedef struct _str_buf_t { - MP_BOOL free; // free src_beg when done + bool free; // free src_beg when done const char *src_beg; // beginning of source const char *src_cur; // current location in source const char *src_end; // end (exclusive) of source @@ -30,7 +30,7 @@ void str_buf_free(str_buf_t *sb) { } } -mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, MP_BOOL free_str) { +mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str) { str_buf_t *sb = m_new(str_buf_t, 1); sb->free = free_str; sb->src_beg = str; @@ -56,7 +56,7 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) { return NULL; } - return mp_lexer_new_from_str_len(filename, data, size, MP_TRUE); + return mp_lexer_new_from_str_len(filename, data, size, true); } /******************************************************************************/ diff --git a/py/lexerunix.h b/py/lexerunix.h index 3054ecd8a4..b422a43062 100644 --- a/py/lexerunix.h +++ b/py/lexerunix.h @@ -1,4 +1,4 @@ -mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, MP_BOOL free_str); +mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str); mp_lexer_t *mp_lexer_new_from_file(const char *filename); void mp_import_set_directory(const char *dir); diff --git a/py/map.c b/py/map.c index 558599f97e..01209c9b74 100644 --- a/py/map.c +++ b/py/map.c @@ -38,8 +38,8 @@ mp_map_t *mp_map_new(mp_map_kind_t kind, int n) { return map; } -mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, MP_BOOL add_if_not_found) { - MP_BOOL is_map_mp_obj = (map->kind == MP_MAP_OBJ); +mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, bool add_if_not_found) { + bool is_map_mp_obj = (map->kind == MP_MAP_OBJ); machine_uint_t hash; if (is_map_mp_obj) { hash = mp_obj_hash(index); @@ -61,7 +61,7 @@ mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, MP_BOOL add_i map->table = m_new0(mp_map_elem_t, map->alloc); for (int i = 0; i < old_alloc; i++) { if (old_table[i].key != NULL) { - mp_map_lookup_helper(map, old_table[i].key, MP_TRUE)->value = old_table[i].value; + mp_map_lookup_helper(map, old_table[i].key, true)->value = old_table[i].value; } } m_del(mp_map_elem_t, old_table, old_alloc); @@ -90,7 +90,7 @@ mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, MP_BOOL add_i } } -mp_map_elem_t* mp_qstr_map_lookup(mp_map_t *map, qstr index, MP_BOOL add_if_not_found) { +mp_map_elem_t* mp_qstr_map_lookup(mp_map_t *map, qstr index, bool add_if_not_found) { mp_obj_t o = (mp_obj_t)(machine_uint_t)index; return mp_map_lookup_helper(map, o, add_if_not_found); } @@ -104,7 +104,7 @@ void mp_set_init(mp_set_t *set, int n) { set->table = m_new0(mp_obj_t, set->alloc); } -mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, MP_BOOL add_if_not_found) { +mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, bool add_if_not_found) { int hash = mp_obj_hash(index); int pos = hash % set->alloc; for (;;) { @@ -121,7 +121,7 @@ mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, MP_BOOL add_if_not_found) set->table = m_new(mp_obj_t, set->alloc); for (int i = 0; i < old_alloc; i++) { if (old_table[i] != NULL) { - mp_set_lookup(set, old_table[i], MP_TRUE); + mp_set_lookup(set, old_table[i], true); } } m_del(mp_obj_t, old_table, old_alloc); diff --git a/py/map.h b/py/map.h index 31ce39b71c..f8ca886aa4 100644 --- a/py/map.h +++ b/py/map.h @@ -26,8 +26,8 @@ typedef struct _mp_set_t { int get_doubling_prime_greater_or_equal_to(int x); void mp_map_init(mp_map_t *map, mp_map_kind_t kind, int n); mp_map_t *mp_map_new(mp_map_kind_t kind, int n); -mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, MP_BOOL add_if_not_found); -mp_map_elem_t* mp_qstr_map_lookup(mp_map_t *map, qstr index, MP_BOOL add_if_not_found); +mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, bool add_if_not_found); +mp_map_elem_t* mp_qstr_map_lookup(mp_map_t *map, qstr index, bool add_if_not_found); void mp_set_init(mp_set_t *set, int n); -mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, MP_BOOL add_if_not_found); +mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, bool add_if_not_found); diff --git a/py/misc.h b/py/misc.h index 149ca8a518..1bf4d8f291 100644 --- a/py/misc.h +++ b/py/misc.h @@ -5,11 +5,7 @@ /** types *******************************************************/ -typedef int MP_BOOL; -enum { - MP_FALSE = 0, - MP_TRUE = 1 -}; +#include typedef unsigned char byte; typedef unsigned int uint; @@ -42,10 +38,10 @@ typedef int unichar; // TODO unichar utf8_get_char(const char *s); char *utf8_next_char(const char *s); -MP_BOOL unichar_isspace(unichar c); -MP_BOOL unichar_isalpha(unichar c); -MP_BOOL unichar_isprint(unichar c); -MP_BOOL unichar_isdigit(unichar c); +bool unichar_isspace(unichar c); +bool unichar_isalpha(unichar c); +bool unichar_isprint(unichar c); +bool unichar_isdigit(unichar c); /** string ******************************************************/ @@ -59,7 +55,7 @@ typedef struct _vstr_t { int alloc; int len; char *buf; - MP_BOOL had_error; + bool had_error; } vstr_t; void vstr_init(vstr_t *vstr); @@ -67,7 +63,7 @@ void vstr_clear(vstr_t *vstr); vstr_t *vstr_new(void); void vstr_free(vstr_t *vstr); void vstr_reset(vstr_t *vstr); -MP_BOOL vstr_had_error(vstr_t *vstr); +bool vstr_had_error(vstr_t *vstr); char *vstr_str(vstr_t *vstr); int vstr_len(vstr_t *vstr); void vstr_hint_size(vstr_t *vstr, int size); diff --git a/py/obj.c b/py/obj.c index e28076b2c1..77580e1fee 100644 --- a/py/obj.c +++ b/py/obj.c @@ -46,9 +46,9 @@ void mp_obj_print(mp_obj_t o_in) { mp_obj_print_helper(printf_wrapper, NULL, o_in); } -MP_BOOL mp_obj_is_callable(mp_obj_t o_in) { +bool mp_obj_is_callable(mp_obj_t o_in) { if (MP_OBJ_IS_SMALL_INT(o_in)) { - return MP_FALSE; + return false; } else { mp_obj_base_t *o = o_in; return o->type->call_n != NULL; @@ -77,13 +77,13 @@ machine_int_t mp_obj_hash(mp_obj_t o_in) { // "The objects need not have the same type. If both are numbers, they are converted // to a common type. Otherwise, the == and != operators always consider objects of // different types to be unequal." -// note also that False==0 and True==1 are MP_TRUE expressions -MP_BOOL mp_obj_equal(mp_obj_t o1, mp_obj_t o2) { +// note also that False==0 and True==1 are true expressions +bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) { if (o1 == o2) { - return MP_TRUE; + return true; } else if (MP_OBJ_IS_SMALL_INT(o1) || MP_OBJ_IS_SMALL_INT(o2)) { if (MP_OBJ_IS_SMALL_INT(o1) && MP_OBJ_IS_SMALL_INT(o2)) { - return MP_FALSE; + return false; } else { if (MP_OBJ_IS_SMALL_INT(o2)) { mp_obj_t temp = o1; o1 = o2; o2 = temp; @@ -95,25 +95,25 @@ MP_BOOL mp_obj_equal(mp_obj_t o1, mp_obj_t o2) { } else if (o2 == mp_const_true) { return val == 1; } else { - return MP_FALSE; + return false; } } } else if (MP_OBJ_IS_TYPE(o1, &str_type) && MP_OBJ_IS_TYPE(o2, &str_type)) { return mp_obj_str_get(o1) == mp_obj_str_get(o2); } else { assert(0); - return MP_FALSE; + return false; } } -MP_BOOL mp_obj_less(mp_obj_t o1, mp_obj_t o2) { +bool mp_obj_less(mp_obj_t o1, mp_obj_t o2) { if (MP_OBJ_IS_SMALL_INT(o1) && MP_OBJ_IS_SMALL_INT(o2)) { mp_small_int_t i1 = MP_OBJ_SMALL_INT_VALUE(o1); mp_small_int_t i2 = MP_OBJ_SMALL_INT_VALUE(o2); return i1 < i2; } else { assert(0); - return MP_FALSE; + return false; } } diff --git a/py/obj.h b/py/obj.h index b8ddb4ea87..351310afa8 100644 --- a/py/obj.h +++ b/py/obj.h @@ -126,7 +126,7 @@ struct _mp_map_t; // General API for objects mp_obj_t mp_obj_new_none(void); -mp_obj_t mp_obj_new_bool(MP_BOOL value); +mp_obj_t mp_obj_new_bool(bool value); mp_obj_t mp_obj_new_cell(mp_obj_t obj); mp_obj_t mp_obj_new_int(machine_int_t value); mp_obj_t mp_obj_new_str(qstr qstr); @@ -162,10 +162,10 @@ const char *mp_obj_get_type_str(mp_obj_t o_in); void mp_obj_print_helper(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in); void mp_obj_print(mp_obj_t o); -MP_BOOL mp_obj_is_callable(mp_obj_t o_in); +bool mp_obj_is_callable(mp_obj_t o_in); machine_int_t mp_obj_hash(mp_obj_t o_in); -MP_BOOL mp_obj_equal(mp_obj_t o1, mp_obj_t o2); -MP_BOOL mp_obj_less(mp_obj_t o1, mp_obj_t o2); +bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2); +bool mp_obj_less(mp_obj_t o1, mp_obj_t o2); machine_int_t mp_obj_get_int(mp_obj_t arg); #if MICROPY_ENABLE_FLOAT diff --git a/py/objbool.c b/py/objbool.c index b03c56924c..54f2b5da1e 100644 --- a/py/objbool.c +++ b/py/objbool.c @@ -10,7 +10,7 @@ typedef struct _mp_obj_bool_t { mp_obj_base_t base; - MP_BOOL value; + bool value; } mp_obj_bool_t; static void bool_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) { @@ -44,8 +44,8 @@ const mp_obj_type_t bool_type = { .methods = NULL, }; -static const mp_obj_bool_t false_obj = {{&bool_type}, MP_FALSE}; -static const mp_obj_bool_t true_obj = {{&bool_type}, MP_TRUE}; +static const mp_obj_bool_t false_obj = {{&bool_type}, false}; +static const mp_obj_bool_t true_obj = {{&bool_type}, true}; const mp_obj_t mp_const_false = (mp_obj_t)&false_obj; const mp_obj_t mp_const_true = (mp_obj_t)&true_obj; diff --git a/py/objclass.c b/py/objclass.c index c2638bc87b..086645cbb4 100644 --- a/py/objclass.c +++ b/py/objclass.c @@ -26,7 +26,7 @@ mp_obj_t class_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) { mp_obj_t o = mp_obj_new_instance(self_in); // look for __init__ function - mp_map_elem_t *init_fn = mp_qstr_map_lookup(self->locals, MP_QSTR___init__, MP_FALSE); + mp_map_elem_t *init_fn = mp_qstr_map_lookup(self->locals, MP_QSTR___init__, false); if (init_fn != NULL) { // call __init__ function diff --git a/py/objdict.c b/py/objdict.c index bac010ce83..a00d172cf3 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -19,14 +19,14 @@ typedef struct _mp_obj_dict_t { static void dict_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) { mp_obj_dict_t *self = self_in; - MP_BOOL first = MP_TRUE; + bool first = true; print(env, "{"); for (int i = 0; i < self->map.alloc; i++) { if (self->map.table[i].key != NULL) { if (!first) { print(env, ", "); } - first = MP_FALSE; + first = false; mp_obj_print_helper(print, env, self->map.table[i].key); print(env, ": "); mp_obj_print_helper(print, env, self->map.table[i].value); @@ -47,7 +47,7 @@ static mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { case RT_BINARY_OP_SUBSCR: { // dict load - mp_map_elem_t *elem = mp_map_lookup_helper(&o->map, rhs_in, MP_FALSE); + mp_map_elem_t *elem = mp_map_lookup_helper(&o->map, rhs_in, false); if (elem == NULL) { nlr_jump(mp_obj_new_exception_msg(MP_QSTR_KeyError, "")); } else { @@ -91,6 +91,6 @@ uint mp_obj_dict_len(mp_obj_t self_in) { mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value) { assert(MP_OBJ_IS_TYPE(self_in, &dict_type)); mp_obj_dict_t *self = self_in; - mp_map_lookup_helper(&self->map, key, MP_TRUE)->value = value; + mp_map_lookup_helper(&self->map, key, true)->value = value; return self_in; } diff --git a/py/objgenerator.c b/py/objgenerator.c index 7eee3a8fc5..cc3d90de1a 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -78,7 +78,7 @@ mp_obj_t gen_instance_getiter(mp_obj_t self_in) { mp_obj_t gen_instance_iternext(mp_obj_t self_in) { mp_obj_gen_instance_t *self = self_in; - MP_BOOL yield = mp_execute_byte_code_2(&self->ip, &self->state[0], &self->sp); + bool yield = mp_execute_byte_code_2(&self->ip, &self->state[0], &self->sp); if (yield) { return *self->sp; } else { diff --git a/py/objinstance.c b/py/objinstance.c index 00ae05816d..a1d71093aa 100644 --- a/py/objinstance.c +++ b/py/objinstance.c @@ -21,7 +21,7 @@ typedef struct _mp_obj_instance_t { type needs to be specified dynamically case O_OBJ: { - py_map_elem_t *qn = py_qstr_map_lookup(o->u_obj.class->u_class.locals, qstr_from_str_static("__qualname__"), MP_FALSE); assert(qn != NULL); + py_map_elem_t *qn = py_qstr_map_lookup(o->u_obj.class->u_class.locals, qstr_from_str_static("__qualname__"), false); assert(qn != NULL); assert(IS_O(qn->value, O_STR)); return qstr_str(((py_obj_base_t*)qn->value)->u_str); } @@ -30,12 +30,12 @@ type needs to be specified dynamically mp_obj_t mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr) { // logic: look in obj members then class locals (TODO check this against CPython) mp_obj_instance_t *self = self_in; - mp_map_elem_t *elem = mp_qstr_map_lookup(self->members, attr, MP_FALSE); + mp_map_elem_t *elem = mp_qstr_map_lookup(self->members, attr, false); if (elem != NULL) { // object member, always treated as a value return elem->value; } - elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, MP_FALSE); + elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, false); if (elem != NULL) { if (mp_obj_is_callable(elem->value)) { // class member is callable so build a bound method @@ -51,14 +51,14 @@ mp_obj_t mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr) { void mp_obj_instance_load_method(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { // logic: look in obj members then class locals (TODO check this against CPython) mp_obj_instance_t *self = self_in; - mp_map_elem_t *elem = mp_qstr_map_lookup(self->members, attr, MP_FALSE); + mp_map_elem_t *elem = mp_qstr_map_lookup(self->members, attr, false); if (elem != NULL) { // object member, always treated as a value dest[1] = elem->value; dest[0] = NULL; return; } - elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, MP_FALSE); + elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, false); if (elem != NULL) { if (mp_obj_is_callable(elem->value)) { // class member is callable so build a bound method @@ -81,11 +81,11 @@ void mp_obj_instance_load_method(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { void mp_obj_instance_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) { // logic: look in class locals (no add) then obj members (add) (TODO check this against CPython) mp_obj_instance_t *self = self_in; - mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, MP_FALSE); + mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, false); if (elem != NULL) { elem->value = value; } else { - mp_qstr_map_lookup(self->members, attr, MP_TRUE)->value = value; + mp_qstr_map_lookup(self->members, attr, true)->value = value; } } diff --git a/py/objlist.c b/py/objlist.c index 3e5a15fceb..52eb488379 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -57,6 +57,7 @@ static mp_obj_t list_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args default: nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_TypeError, "list takes at most 1 argument, %d given", (void*)(machine_int_t)n_args)); } + return NULL; } static mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { @@ -266,6 +267,7 @@ const mp_method_t list_type_methods[] = { { "copy", &list_copy_obj }, { "count", &list_count_obj }, { "index", &list_index_obj }, + { "insert", &list_insert_obj }, { "pop", &list_pop_obj }, { "remove", &list_remove_obj }, { "reverse", &list_reverse_obj }, diff --git a/py/objset.c b/py/objset.c index 6a02ba1202..264e142375 100644 --- a/py/objset.c +++ b/py/objset.c @@ -17,14 +17,14 @@ typedef struct _mp_obj_set_t { void set_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) { mp_obj_set_t *self = self_in; - MP_BOOL first = MP_TRUE; + bool first = true; print(env, "{"); for (int i = 0; i < self->set.alloc; i++) { if (self->set.table[i] != MP_OBJ_NULL) { if (!first) { print(env, ", "); } - first = MP_FALSE; + first = false; mp_obj_print_helper(print, env, self->set.table[i]); } } @@ -72,7 +72,7 @@ mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items) { o->base.type = &set_type; mp_set_init(&o->set, n_args); for (int i = 0; i < n_args; i++) { - mp_set_lookup(&o->set, items[i], MP_TRUE); + mp_set_lookup(&o->set, items[i], true); } return o; } @@ -80,5 +80,5 @@ mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items) { void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item) { assert(MP_OBJ_IS_TYPE(self_in, &set_type)); mp_obj_set_t *self = self_in; - mp_set_lookup(&self->set, item, MP_TRUE); + mp_set_lookup(&self->set, item, true); } diff --git a/py/objtuple.c b/py/objtuple.c index a8ecc3a4f2..a59e674b19 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -165,14 +165,8 @@ static mp_obj_t tuple_it_iternext(mp_obj_t self_in) { static const mp_obj_type_t tuple_it_type = { { &mp_const_type }, "tuple_iterator", - NULL, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - tuple_it_iternext, - NULL, // method list + .iternext = tuple_it_iternext, + .methods = NULL, }; static mp_obj_t mp_obj_new_tuple_iterator(mp_obj_tuple_t *tuple, int cur) { diff --git a/py/parse.c b/py/parse.c index 1d3badbc3f..d3786ba956 100644 --- a/py/parse.c +++ b/py/parse.c @@ -189,8 +189,8 @@ static void push_result_token(parser_t *parser, const mp_lexer_t *lex) { if (tok->kind == MP_TOKEN_NAME) { pn = mp_parse_node_new_leaf(MP_PARSE_NODE_ID, qstr_from_strn_copy(tok->str, tok->len)); } else if (tok->kind == MP_TOKEN_NUMBER) { - MP_BOOL dec = MP_FALSE; - MP_BOOL small_int = MP_TRUE; + bool dec = false; + bool small_int = true; int int_val = 0; int len = tok->len; const char *str = tok->str; @@ -219,10 +219,10 @@ static void push_result_token(parser_t *parser, const mp_lexer_t *lex) { } else if (base == 16 && 'A' <= str[i] && str[i] <= 'F') { int_val = base * int_val + str[i] - 'A' + 10; } else if (str[i] == '.' || str[i] == 'e' || str[i] == 'E' || str[i] == 'j' || str[i] == 'J') { - dec = MP_TRUE; + dec = true; break; } else { - small_int = MP_FALSE; + small_int = false; break; } } @@ -269,11 +269,11 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { push_rule(parser, rules[top_level_rule], 0); uint n, i; - MP_BOOL backtrack = MP_FALSE; + bool backtrack = false; const rule_t *rule; mp_token_kind_t tok_kind; - MP_BOOL emit_rule; - MP_BOOL had_trailing_sep; + bool emit_rule; + bool had_trailing_sep; for (;;) { next_rule: @@ -298,7 +298,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { if (i > 0 && !backtrack) { goto next_rule; } else { - backtrack = MP_FALSE; + backtrack = false; } for (; i < n - 1; ++i) { switch (rule->arg[i] & RULE_ARG_KIND_MASK) { @@ -322,7 +322,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { push_result_token(parser, lex); mp_lexer_to_next(lex); } else { - backtrack = MP_TRUE; + backtrack = true; goto next_rule; } } else { @@ -338,7 +338,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { if ((rule->arg[i - 1] & RULE_ARG_KIND_MASK) == RULE_ARG_OPT_RULE) { // an optional rule that failed, so continue with next arg push_result_node(parser, MP_PARSE_NODE_NULL); - backtrack = MP_FALSE; + backtrack = false; } else { // a mandatory rule that failed, so propagate backtrack if (i > 1) { @@ -369,7 +369,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { goto syntax_error; } else { // this rule failed, so backtrack - backtrack = MP_TRUE; + backtrack = true; goto next_rule; } } @@ -395,12 +395,12 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { // count number of arguments for the parse_node i = 0; - emit_rule = MP_FALSE; + emit_rule = false; for (int x = 0; x < n; ++x) { if ((rule->arg[x] & RULE_ARG_KIND_MASK) == RULE_ARG_TOK) { tok_kind = rule->arg[x] & RULE_ARG_ARG_MASK; if (tok_kind >= MP_TOKEN_NAME) { - emit_rule = MP_TRUE; + emit_rule = true; } if (tok_kind == MP_TOKEN_NAME) { // only tokens which were names are pushed to stack @@ -414,19 +414,19 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { // always emit these rules, even if they have only 1 argument if (rule->rule_id == RULE_expr_stmt || rule->rule_id == RULE_yield_stmt) { - emit_rule = MP_TRUE; + emit_rule = true; } // never emit these rules if they have only 1 argument // NOTE: can't put atom_paren here because we need it to distinguisg, for example, [a,b] from [(a,b)] // TODO possibly put varargslist_name, varargslist_equal here as well if (rule->rule_id == RULE_else_stmt || rule->rule_id == RULE_testlist_comp_3b || rule->rule_id == RULE_import_as_names_paren || rule->rule_id == RULE_typedargslist_name || rule->rule_id == RULE_typedargslist_colon || rule->rule_id == RULE_typedargslist_equal || rule->rule_id == RULE_dictorsetmaker_colon || rule->rule_id == RULE_classdef_2 || rule->rule_id == RULE_with_item_as || rule->rule_id == RULE_assert_stmt_extra || rule->rule_id == RULE_as_name || rule->rule_id == RULE_raise_stmt_from || rule->rule_id == RULE_vfpdef) { - emit_rule = MP_FALSE; + emit_rule = false; } // always emit these rules, and add an extra blank node at the end (to be used by the compiler to store data) if (rule->rule_id == RULE_funcdef || rule->rule_id == RULE_classdef || rule->rule_id == RULE_comp_for || rule->rule_id == RULE_lambdef || rule->rule_id == RULE_lambdef_nocond) { - emit_rule = MP_TRUE; + emit_rule = true; push_result_node(parser, MP_PARSE_NODE_NULL); i += 1; } @@ -465,14 +465,14 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { // n=3 is: item (sep item)* [sep] if (backtrack) { list_backtrack: - had_trailing_sep = MP_FALSE; + had_trailing_sep = false; if (n == 2) { if (i == 1) { // fail on item, first time round; propagate backtrack goto next_rule; } else { // fail on item, in later rounds; finish with this rule - backtrack = MP_FALSE; + backtrack = false; } } else { if (i == 1) { @@ -482,15 +482,15 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { // fail on item, in later rounds; have eaten tokens so can't backtrack if (n == 3) { // list allows trailing separator; finish parsing list - had_trailing_sep = MP_TRUE; - backtrack = MP_FALSE; + had_trailing_sep = true; + backtrack = false; } else { // list doesn't allowing trailing separator; fail goto syntax_error; } } else { // fail on separator; finish parsing list - backtrack = MP_FALSE; + backtrack = false; } } } else { @@ -510,7 +510,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { } else { // couldn't get element of list i += 1; - backtrack = MP_TRUE; + backtrack = true; goto list_backtrack; } break; diff --git a/py/repl.c b/py/repl.c index 2127a28dfb..4241ef0e4c 100644 --- a/py/repl.c +++ b/py/repl.c @@ -1,17 +1,17 @@ #include "misc.h" #include "repl.h" -MP_BOOL str_startswith_word(const char *str, const char *head) { +bool str_startswith_word(const char *str, const char *head) { int i; for (i = 0; str[i] && head[i]; i++) { if (str[i] != head[i]) { - return MP_FALSE; + return false; } } return head[i] == '\0' && (str[i] == '\0' || !unichar_isalpha(str[i])); } -MP_BOOL mp_repl_is_compound_stmt(const char *line) { +bool mp_repl_is_compound_stmt(const char *line) { // compound if line starts with a certain keyword if ( str_startswith_word(line, "if") @@ -23,7 +23,7 @@ MP_BOOL mp_repl_is_compound_stmt(const char *line) { || str_startswith_word(line, "class") || str_startswith_word(line, "@") ) { - return MP_TRUE; + return true; } // also "compound" if unmatched open bracket diff --git a/py/repl.h b/py/repl.h index db082f07ac..02fe523ed4 100644 --- a/py/repl.h +++ b/py/repl.h @@ -1 +1 @@ -MP_BOOL mp_repl_is_compound_stmt(const char *line); +bool mp_repl_is_compound_stmt(const char *line); diff --git a/py/runtime.c b/py/runtime.c index 86e297d7bd..7f9ce20279 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -45,7 +45,7 @@ typedef struct _mp_code_t { int n_args; int n_locals; int n_stack; - MP_BOOL is_generator; + bool is_generator; union { struct { byte *code; @@ -70,60 +70,60 @@ FILE *fp_write_code = NULL; void rt_init(void) { // locals = globals for outer module (see Objects/frameobject.c/PyFrame_New()) map_locals = map_globals = mp_map_new(MP_MAP_QSTR, 1); - mp_qstr_map_lookup(map_globals, MP_QSTR___name__, MP_TRUE)->value = mp_obj_new_str(MP_QSTR___main__); + mp_qstr_map_lookup(map_globals, MP_QSTR___name__, true)->value = mp_obj_new_str(MP_QSTR___main__); // init built-in hash table mp_map_init(&map_builtins, MP_MAP_QSTR, 3); // built-in exceptions (TODO, make these proper classes) - mp_qstr_map_lookup(&map_builtins, MP_QSTR_AttributeError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_AttributeError); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_IndexError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_IndexError); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_KeyError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_KeyError); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_NameError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_NameError); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_TypeError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_TypeError); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_SyntaxError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_SyntaxError); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_ValueError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_ValueError); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_AttributeError, true)->value = mp_obj_new_exception(MP_QSTR_AttributeError); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_IndexError, true)->value = mp_obj_new_exception(MP_QSTR_IndexError); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_KeyError, true)->value = mp_obj_new_exception(MP_QSTR_KeyError); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_NameError, true)->value = mp_obj_new_exception(MP_QSTR_NameError); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_TypeError, true)->value = mp_obj_new_exception(MP_QSTR_TypeError); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_SyntaxError, true)->value = mp_obj_new_exception(MP_QSTR_SyntaxError); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_ValueError, true)->value = mp_obj_new_exception(MP_QSTR_ValueError); // built-in objects - mp_qstr_map_lookup(&map_builtins, MP_QSTR_Ellipsis, MP_TRUE)->value = mp_const_ellipsis; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_Ellipsis, true)->value = mp_const_ellipsis; // built-in core functions - mp_qstr_map_lookup(&map_builtins, MP_QSTR___build_class__, MP_TRUE)->value = rt_make_function_2(mp_builtin___build_class__); - mp_qstr_map_lookup(&map_builtins, MP_QSTR___repl_print__, MP_TRUE)->value = rt_make_function_1(mp_builtin___repl_print__); + mp_qstr_map_lookup(&map_builtins, MP_QSTR___build_class__, true)->value = rt_make_function_2(mp_builtin___build_class__); + mp_qstr_map_lookup(&map_builtins, MP_QSTR___repl_print__, true)->value = rt_make_function_1(mp_builtin___repl_print__); // built-in types - mp_qstr_map_lookup(&map_builtins, MP_QSTR_bool, MP_TRUE)->value = (mp_obj_t)&bool_type; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_bool, true)->value = (mp_obj_t)&bool_type; #if MICROPY_ENABLE_FLOAT - mp_qstr_map_lookup(&map_builtins, MP_QSTR_complex, MP_TRUE)->value = (mp_obj_t)&complex_type; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_complex, true)->value = (mp_obj_t)&complex_type; #endif - mp_qstr_map_lookup(&map_builtins, MP_QSTR_dict, MP_TRUE)->value = (mp_obj_t)&dict_type; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_dict, true)->value = (mp_obj_t)&dict_type; #if MICROPY_ENABLE_FLOAT - mp_qstr_map_lookup(&map_builtins, MP_QSTR_float, MP_TRUE)->value = (mp_obj_t)&float_type; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_float, true)->value = (mp_obj_t)&float_type; #endif - mp_qstr_map_lookup(&map_builtins, MP_QSTR_int, MP_TRUE)->value = (mp_obj_t)&int_type; - mp_qstr_map_lookup(&map_builtins, MP_QSTR_list, MP_TRUE)->value = (mp_obj_t)&list_type; - mp_qstr_map_lookup(&map_builtins, MP_QSTR_set, MP_TRUE)->value = (mp_obj_t)&set_type; - mp_qstr_map_lookup(&map_builtins, MP_QSTR_tuple, MP_TRUE)->value = (mp_obj_t)&tuple_type; - mp_qstr_map_lookup(&map_builtins, MP_QSTR_type, MP_TRUE)->value = (mp_obj_t)&mp_builtin_type_obj; // TODO + mp_qstr_map_lookup(&map_builtins, MP_QSTR_int, true)->value = (mp_obj_t)&int_type; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_list, true)->value = (mp_obj_t)&list_type; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_set, true)->value = (mp_obj_t)&set_type; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_tuple, true)->value = (mp_obj_t)&tuple_type; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_type, true)->value = (mp_obj_t)&mp_builtin_type_obj; // TODO // built-in user functions; TODO covert all to &mp_builtin_xxx's - mp_qstr_map_lookup(&map_builtins, MP_QSTR_abs, MP_TRUE)->value = rt_make_function_1(mp_builtin_abs); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_all, MP_TRUE)->value = rt_make_function_1(mp_builtin_all); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_any, MP_TRUE)->value = rt_make_function_1(mp_builtin_any); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_callable, MP_TRUE)->value = rt_make_function_1(mp_builtin_callable); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_chr, MP_TRUE)->value = rt_make_function_1(mp_builtin_chr); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_divmod, MP_TRUE)->value = rt_make_function_2(mp_builtin_divmod); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_hash, MP_TRUE)->value = (mp_obj_t)&mp_builtin_hash_obj; - mp_qstr_map_lookup(&map_builtins, MP_QSTR_iter, MP_TRUE)->value = (mp_obj_t)&mp_builtin_iter_obj; - mp_qstr_map_lookup(&map_builtins, MP_QSTR_len, MP_TRUE)->value = rt_make_function_1(mp_builtin_len); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_max, MP_TRUE)->value = rt_make_function_var(1, mp_builtin_max); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_min, MP_TRUE)->value = rt_make_function_var(1, mp_builtin_min); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_next, MP_TRUE)->value = (mp_obj_t)&mp_builtin_next_obj; - mp_qstr_map_lookup(&map_builtins, MP_QSTR_ord, MP_TRUE)->value = rt_make_function_1(mp_builtin_ord); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_pow, MP_TRUE)->value = rt_make_function_var(2, mp_builtin_pow); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_print, MP_TRUE)->value = rt_make_function_var(0, mp_builtin_print); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_range, MP_TRUE)->value = rt_make_function_var(1, mp_builtin_range); - mp_qstr_map_lookup(&map_builtins, MP_QSTR_sum, MP_TRUE)->value = rt_make_function_var(1, mp_builtin_sum); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_abs, true)->value = rt_make_function_1(mp_builtin_abs); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_all, true)->value = rt_make_function_1(mp_builtin_all); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_any, true)->value = rt_make_function_1(mp_builtin_any); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_callable, true)->value = rt_make_function_1(mp_builtin_callable); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_chr, true)->value = rt_make_function_1(mp_builtin_chr); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_divmod, true)->value = rt_make_function_2(mp_builtin_divmod); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_hash, true)->value = (mp_obj_t)&mp_builtin_hash_obj; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_iter, true)->value = (mp_obj_t)&mp_builtin_iter_obj; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_len, true)->value = rt_make_function_1(mp_builtin_len); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_max, true)->value = rt_make_function_var(1, mp_builtin_max); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_min, true)->value = rt_make_function_var(1, mp_builtin_min); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_next, true)->value = (mp_obj_t)&mp_builtin_next_obj; + mp_qstr_map_lookup(&map_builtins, MP_QSTR_ord, true)->value = rt_make_function_1(mp_builtin_ord); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_pow, true)->value = rt_make_function_var(2, mp_builtin_pow); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_print, true)->value = rt_make_function_var(0, mp_builtin_print); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_range, true)->value = rt_make_function_var(1, mp_builtin_range); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_sum, true)->value = rt_make_function_var(1, mp_builtin_sum); next_unique_code_id = 1; // 0 indicates "no code" unique_codes = NULL; @@ -154,7 +154,7 @@ static void alloc_unique_codes(void) { } } -void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, int n_locals, int n_stack, MP_BOOL is_generator) { +void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, int n_locals, int n_stack, bool is_generator) { alloc_unique_codes(); assert(1 <= unique_code_id && unique_code_id < next_unique_code_id); @@ -197,7 +197,7 @@ void rt_assign_native_code(int unique_code_id, void *fun, uint len, int n_args) unique_codes[unique_code_id].n_args = n_args; unique_codes[unique_code_id].n_locals = 0; unique_codes[unique_code_id].n_stack = 0; - unique_codes[unique_code_id].is_generator = MP_FALSE; + unique_codes[unique_code_id].is_generator = false; unique_codes[unique_code_id].u_native.fun = fun; //printf("native code: %d bytes\n", len); @@ -230,7 +230,7 @@ void rt_assign_inline_asm_code(int unique_code_id, void *fun, uint len, int n_ar unique_codes[unique_code_id].n_args = n_args; unique_codes[unique_code_id].n_locals = 0; unique_codes[unique_code_id].n_stack = 0; - unique_codes[unique_code_id].is_generator = MP_FALSE; + unique_codes[unique_code_id].is_generator = false; unique_codes[unique_code_id].u_inline_asm.fun = fun; #ifdef DEBUG_PRINT @@ -252,8 +252,8 @@ void rt_assign_inline_asm_code(int unique_code_id, void *fun, uint len, int n_ar #endif } -static MP_BOOL fit_small_int(mp_small_int_t o) { - return MP_TRUE; +static bool fit_small_int(mp_small_int_t o) { + return true; } int rt_is_true(mp_obj_t arg) { @@ -290,10 +290,10 @@ mp_obj_t rt_load_const_dec(qstr qstr) { const char *s = qstr_str(qstr); int in = PARSE_DEC_IN_INTG; mp_float_t dec_val = 0; - MP_BOOL exp_neg = MP_FALSE; + bool exp_neg = false; int exp_val = 0; int exp_extra = 0; - MP_BOOL imag = MP_FALSE; + bool imag = false; for (; *s; s++) { int dig = *s; if ('0' <= dig && dig <= '9') { @@ -314,11 +314,11 @@ mp_obj_t rt_load_const_dec(qstr qstr) { s++; } else if (s[1] == '-') { s++; - exp_neg = MP_TRUE; + exp_neg = true; } } else if (dig == 'J' || dig == 'j') { s++; - imag = MP_TRUE; + imag = true; break; } else { // unknown character @@ -356,11 +356,11 @@ mp_obj_t rt_load_const_str(qstr qstr) { mp_obj_t rt_load_name(qstr qstr) { // logic: search locals, globals, builtins DEBUG_OP_printf("load name %s\n", qstr_str(qstr)); - mp_map_elem_t *elem = mp_qstr_map_lookup(map_locals, qstr, MP_FALSE); + mp_map_elem_t *elem = mp_qstr_map_lookup(map_locals, qstr, false); if (elem == NULL) { - elem = mp_qstr_map_lookup(map_globals, qstr, MP_FALSE); + elem = mp_qstr_map_lookup(map_globals, qstr, false); if (elem == NULL) { - elem = mp_qstr_map_lookup(&map_builtins, qstr, MP_FALSE); + elem = mp_qstr_map_lookup(&map_builtins, qstr, false); if (elem == NULL) { nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_NameError, "name '%s' is not defined", qstr_str(qstr))); } @@ -372,9 +372,9 @@ mp_obj_t rt_load_name(qstr qstr) { mp_obj_t rt_load_global(qstr qstr) { // logic: search globals, builtins DEBUG_OP_printf("load global %s\n", qstr_str(qstr)); - mp_map_elem_t *elem = mp_qstr_map_lookup(map_globals, qstr, MP_FALSE); + mp_map_elem_t *elem = mp_qstr_map_lookup(map_globals, qstr, false); if (elem == NULL) { - elem = mp_qstr_map_lookup(&map_builtins, qstr, MP_FALSE); + elem = mp_qstr_map_lookup(&map_builtins, qstr, false); if (elem == NULL) { nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_NameError, "name '%s' is not defined", qstr_str(qstr))); } @@ -384,7 +384,7 @@ mp_obj_t rt_load_global(qstr qstr) { mp_obj_t rt_load_build_class(void) { DEBUG_OP_printf("load_build_class\n"); - mp_map_elem_t *elem = mp_qstr_map_lookup(&map_builtins, MP_QSTR___build_class__, MP_FALSE); + mp_map_elem_t *elem = mp_qstr_map_lookup(&map_builtins, MP_QSTR___build_class__, false); if (elem == NULL) { nlr_jump(mp_obj_new_exception_msg(MP_QSTR_NameError, "name '__build_class__' is not defined")); } @@ -401,12 +401,12 @@ void rt_set_cell(mp_obj_t cell, mp_obj_t val) { void rt_store_name(qstr qstr, mp_obj_t obj) { DEBUG_OP_printf("store name %s <- %p\n", qstr_str(qstr), obj); - mp_qstr_map_lookup(map_locals, qstr, MP_TRUE)->value = obj; + mp_qstr_map_lookup(map_locals, qstr, true)->value = obj; } void rt_store_global(qstr qstr, mp_obj_t obj) { DEBUG_OP_printf("store global %s <- %p\n", qstr_str(qstr), obj); - mp_qstr_map_lookup(map_globals, qstr, MP_TRUE)->value = obj; + mp_qstr_map_lookup(map_globals, qstr, true)->value = obj; } mp_obj_t rt_unary_op(int op, mp_obj_t arg) { @@ -750,7 +750,7 @@ mp_obj_t rt_store_map(mp_obj_t map, mp_obj_t key, mp_obj_t value) { mp_obj_t rt_load_attr(mp_obj_t base, qstr attr) { DEBUG_OP_printf("load attr %s\n", qstr_str(attr)); if (MP_OBJ_IS_TYPE(base, &class_type)) { - mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_class_get_locals(base), attr, MP_FALSE); + mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_class_get_locals(base), attr, false); if (elem == NULL) { // TODO what about generic method lookup? goto no_attr; @@ -760,7 +760,7 @@ mp_obj_t rt_load_attr(mp_obj_t base, qstr attr) { return mp_obj_instance_load_attr(base, attr); } else if (MP_OBJ_IS_TYPE(base, &module_type)) { DEBUG_OP_printf("lookup module map %p\n", mp_obj_module_get_globals(base)); - mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_module_get_globals(base), attr, MP_FALSE); + mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_module_get_globals(base), attr, false); if (elem == NULL) { // TODO what about generic method lookup? goto no_attr; @@ -817,13 +817,13 @@ void rt_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) { if (MP_OBJ_IS_TYPE(base, &class_type)) { // TODO CPython allows STORE_ATTR to a class, but is this the correct implementation? mp_map_t *locals = mp_obj_class_get_locals(base); - mp_qstr_map_lookup(locals, attr, MP_TRUE)->value = value; + mp_qstr_map_lookup(locals, attr, true)->value = value; } else if (MP_OBJ_IS_TYPE(base, &instance_type)) { mp_obj_instance_store_attr(base, attr, value); } else if (MP_OBJ_IS_TYPE(base, &module_type)) { // TODO CPython allows STORE_ATTR to a module, but is this the correct implementation? mp_map_t *globals = mp_obj_module_get_globals(base); - mp_qstr_map_lookup(globals, attr, MP_TRUE)->value = value; + mp_qstr_map_lookup(globals, attr, true)->value = value; } else { nlr_jump(mp_obj_new_exception_msg_2_args(MP_QSTR_AttributeError, "'%s' object has no attribute '%s'", mp_obj_get_type_str(base), qstr_str(attr))); } diff --git a/py/runtime0.h b/py/runtime0.h index 19c2f63edc..97dbe5ddbc 100644 --- a/py/runtime0.h +++ b/py/runtime0.h @@ -82,6 +82,6 @@ extern void *const rt_fun_table[RT_F_NUMBER_OF]; void rt_init(void); void rt_deinit(void); int rt_get_unique_code_id(void); -void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, int n_locals, int n_stack, MP_BOOL is_generator); +void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, int n_locals, int n_stack, bool is_generator); void rt_assign_native_code(int unique_code_id, void *f, uint len, int n_args); void rt_assign_inline_asm_code(int unique_code_id, void *f, uint len, int n_args); diff --git a/py/scope.c b/py/scope.c index 110e63afa5..5d97393ae3 100644 --- a/py/scope.c +++ b/py/scope.c @@ -58,10 +58,10 @@ scope_t *scope_new(scope_kind_t kind, mp_parse_node_t pn, uint unique_code_id, u return scope; } -id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, MP_BOOL *added) { +id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, bool *added) { for (int i = 0; i < scope->id_info_len; i++) { if (scope->id_info[i].qstr == qstr) { - *added = MP_FALSE; + *added = false; return &scope->id_info[i]; } } @@ -100,11 +100,11 @@ id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, MP_BOOL *added) { id_info = &scope->id_info[scope->id_info_len++]; } - id_info->param = MP_FALSE; + id_info->param = false; id_info->kind = 0; id_info->qstr = qstr; id_info->local_num = 0; - *added = MP_TRUE; + *added = true; return id_info; } @@ -155,7 +155,7 @@ void scope_close_over_in_parents(scope_t *scope, qstr qstr) { } if (id == NULL) { // variable not declared in this scope, so declare it as free and keep searching parents - MP_BOOL added; + bool added; id = scope_find_or_add_id(s, qstr, &added); assert(added); id->kind = ID_INFO_KIND_FREE; @@ -178,7 +178,7 @@ void scope_declare_global(scope_t *scope, qstr qstr) { printf("SyntaxError?: can't declare global in outer code\n"); return; } - MP_BOOL added; + bool added; id_info_t *id_info = scope_find_or_add_id(scope, qstr, &added); if (!added) { printf("SyntaxError?: identifier already declared something\n"); @@ -198,7 +198,7 @@ void scope_declare_nonlocal(scope_t *scope, qstr qstr) { printf("SyntaxError?: can't declare nonlocal in outer code\n"); return; } - MP_BOOL added; + bool added; id_info_t *id_info = scope_find_or_add_id(scope, qstr, &added); if (!added) { printf("SyntaxError?: identifier already declared something\n"); diff --git a/py/scope.h b/py/scope.h index 8cdcacaaf8..761a4d7119 100644 --- a/py/scope.h +++ b/py/scope.h @@ -8,7 +8,7 @@ enum { typedef struct _id_info_t { // TODO compress this info to make structure smaller in memory - MP_BOOL param; + bool param; int kind; qstr qstr; @@ -55,7 +55,7 @@ typedef struct _scope_t { } scope_t; scope_t *scope_new(scope_kind_t kind, mp_parse_node_t pn, uint unique_code_id, uint emit_options); -id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, MP_BOOL *added); +id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, bool *added); id_info_t *scope_find(scope_t *scope, qstr qstr); id_info_t *scope_find_global(scope_t *scope, qstr qstr); id_info_t *scope_find_local_in_parent(scope_t *scope, qstr qstr); diff --git a/py/unicode.c b/py/unicode.c index 3450618853..58c860a0e4 100644 --- a/py/unicode.c +++ b/py/unicode.c @@ -46,32 +46,32 @@ char *utf8_next_char(const char *s) { return (char*)(s + 1); } -MP_BOOL unichar_isspace(unichar c) { +bool unichar_isspace(unichar c) { return c < 128 && (attr[c] & FL_SPACE) != 0; } -MP_BOOL unichar_isalpha(unichar c) { +bool unichar_isalpha(unichar c) { return c < 128 && (attr[c] & FL_ALPHA) != 0; } -MP_BOOL unichar_isprint(unichar c) { +bool unichar_isprint(unichar c) { return c < 128 && (attr[c] & FL_PRINT) != 0; } -MP_BOOL unichar_isdigit(unichar c) { +bool unichar_isdigit(unichar c) { return c < 128 && (attr[c] & FL_DIGIT) != 0; } /* -MP_BOOL char_is_alpha_or_digit(unichar c) { +bool char_is_alpha_or_digit(unichar c) { return c < 128 && (attr[c] & (FL_ALPHA | FL_DIGIT)) != 0; } -MP_BOOL char_is_upper(unichar c) { +bool char_is_upper(unichar c) { return c < 128 && (attr[c] & FL_UPPER) != 0; } -MP_BOOL char_is_lower(unichar c) { +bool char_is_lower(unichar c) { return c < 128 && (attr[c] & FL_LOWER) != 0; } */ diff --git a/py/vm.c b/py/vm.c index 02f3add75b..8e7ef7485b 100644 --- a/py/vm.c +++ b/py/vm.c @@ -65,7 +65,7 @@ mp_obj_t mp_execute_byte_code(const byte *code, const mp_obj_t *args, uint n_arg // fastn has items in normal order // sp points to top of stack which grows down -MP_BOOL mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **sp_in_out) { +bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **sp_in_out) { // careful: be sure to declare volatile any variables read in the exception handler (written is ok, I think) const byte *ip = *ip_in_out; @@ -472,7 +472,7 @@ MP_BOOL mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t nlr_pop(); *sp_in_out = sp; assert(exc_sp == &exc_stack[0] - 1); - return MP_FALSE; + return false; case MP_BC_YIELD_VALUE: nlr_pop(); @@ -481,7 +481,7 @@ MP_BOOL mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t fastn[1] = fast1; fastn[2] = fast2; *sp_in_out = sp; - return MP_TRUE; + return true; case MP_BC_IMPORT_NAME: DECODE_QSTR; @@ -499,7 +499,7 @@ MP_BOOL mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t printf("code %p, byte code 0x%02x not implemented\n", ip, op); assert(0); nlr_pop(); - return MP_FALSE; + return false; } } diff --git a/py/vstr.c b/py/vstr.c index 76232cc100..80841b24ca 100644 --- a/py/vstr.c +++ b/py/vstr.c @@ -11,11 +11,11 @@ void vstr_init(vstr_t *vstr) { vstr->len = 0; vstr->buf = m_new(char, vstr->alloc); if (vstr->buf == NULL) { - vstr->had_error = MP_TRUE; + vstr->had_error = true; return; } vstr->buf[0] = 0; - vstr->had_error = MP_FALSE; + vstr->had_error = false; } void vstr_clear(vstr_t *vstr) { @@ -42,10 +42,10 @@ void vstr_free(vstr_t *vstr) { void vstr_reset(vstr_t *vstr) { vstr->len = 0; vstr->buf[0] = 0; - vstr->had_error = MP_FALSE; + vstr->had_error = false; } -MP_BOOL vstr_had_error(vstr_t *vstr) { +bool vstr_had_error(vstr_t *vstr) { return vstr->had_error; } @@ -63,23 +63,23 @@ int vstr_len(vstr_t *vstr) { return vstr->len; } -MP_BOOL vstr_ensure_extra(vstr_t *vstr, int size) { +bool vstr_ensure_extra(vstr_t *vstr, int size) { if (vstr->len + size + 1 > vstr->alloc) { int new_alloc = ROUND_ALLOC((vstr->len + size + 1) * 2); char *new_buf = m_renew(char, vstr->buf, vstr->alloc, new_alloc); if (new_buf == NULL) { - vstr->had_error = MP_TRUE; - return MP_FALSE; + vstr->had_error = true; + return false; } vstr->alloc = new_alloc; vstr->buf = new_buf; } - return MP_TRUE; + return true; } void vstr_hint_size(vstr_t *vstr, int size) { // it's not an error if we fail to allocate for the size hint - MP_BOOL er = vstr->had_error; + bool er = vstr->had_error; vstr_ensure_extra(vstr, size); vstr->had_error = er; } diff --git a/stm/audio.c b/stm/audio.c index 829bd6dfde..34adefbcd6 100644 --- a/stm/audio.c +++ b/stm/audio.c @@ -22,7 +22,7 @@ int sample_buf_in; int sample_buf_out; byte sample_buf[SAMPLE_BUF_SIZE]; -MP_BOOL audio_is_full(void) { +bool audio_is_full(void) { return ((sample_buf_in + 1) % SAMPLE_BUF_SIZE) == sample_buf_out; } diff --git a/stm/cc3k/pybcc3k.c b/stm/cc3k/pybcc3k.c index aa83d4a277..9b7113869d 100644 --- a/stm/cc3k/pybcc3k.c +++ b/stm/cc3k/pybcc3k.c @@ -165,11 +165,11 @@ void pyb_cc3000_spi_init(void) { /* // WLAN CS, EN and WALN IRQ Configuration - jshSetPinStateIsManual(WLAN_CS_PIN, MP_FALSE); + jshSetPinStateIsManual(WLAN_CS_PIN, false); jshPinOutput(WLAN_CS_PIN, 1); // de-assert CS - jshSetPinStateIsManual(WLAN_EN_PIN, MP_FALSE); + jshSetPinStateIsManual(WLAN_EN_PIN, false); jshPinOutput(WLAN_EN_PIN, 0); // disable WLAN - jshSetPinStateIsManual(WLAN_IRQ_PIN, MP_TRUE); + jshSetPinStateIsManual(WLAN_IRQ_PIN, true); jshPinSetState(WLAN_IRQ_PIN, JSHPINSTATE_GPIO_IN_PULLUP); // flip into read mode with pullup */ // configure wlan CS and EN pins diff --git a/stm/i2c.c b/stm/i2c.c index 6456a15793..9e25ff9839 100644 --- a/stm/i2c.c +++ b/stm/i2c.c @@ -20,9 +20,9 @@ typedef enum { I2C_STATE_READ = 2, } i2c_state_t; -// set to MP_TRUE if the port has already been initialized -MP_BOOL i2c1_port_initialized = MP_FALSE; -MP_BOOL i2c2_port_initialized = MP_FALSE; +// set to true if the port has already been initialized +bool i2c1_port_initialized = false; +bool i2c2_port_initialized = false; static I2C_TypeDef * _i2c_port_addr(pyb_i2c_t i2c_port) { if (i2c_port == PYB_I2C_1) { @@ -37,17 +37,17 @@ static I2C_TypeDef * _i2c_port_addr(pyb_i2c_t i2c_port) { // todo - perhaps there should be some global resource management for gpio // this function would fail if the i2c pins have already been defined for // use by another python object -// as it is, this always returns MP_TRUE (unless i2c_port is invalid) -static MP_BOOL _i2c_init(pyb_i2c_t i2c_port) { +// as it is, this always returns true (unless i2c_port is invalid) +static bool _i2c_init(pyb_i2c_t i2c_port) { GPIO_InitTypeDef GPIO_InitStructure; I2C_TypeDef *i2c = _i2c_port_addr(i2c_port); if (i2c == NULL) - return MP_FALSE; + return false; if (i2c_port == PYB_I2C_1) { - if (i2c1_port_initialized == MP_TRUE) { - return MP_TRUE; + if (i2c1_port_initialized == true) { + return true; } RCC->APB1ENR |= RCC_APB1ENR_I2C1EN; // enable I2C1 @@ -64,12 +64,12 @@ static MP_BOOL _i2c_init(pyb_i2c_t i2c_port) { GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_I2C1); - i2c1_port_initialized = MP_TRUE; + i2c1_port_initialized = true; } if (i2c_port == PYB_I2C_2) { - if (i2c2_port_initialized == MP_TRUE) { - return MP_TRUE; + if (i2c2_port_initialized == true) { + return true; } RCC->APB1ENR |= RCC_APB1ENR_I2C2EN; // enable I2C2 @@ -85,7 +85,7 @@ static MP_BOOL _i2c_init(pyb_i2c_t i2c_port) { GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_I2C2); GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_I2C2); - i2c2_port_initialized = MP_TRUE; + i2c2_port_initialized = true; } // get clock speeds @@ -108,7 +108,7 @@ static MP_BOOL _i2c_init(pyb_i2c_t i2c_port) { // enable the I2C peripheral i2c->CR1 |= I2C_CR1_PE; - return MP_TRUE; + return true; } static uint32_t _i2c_get_sr(pyb_i2c_t i2c_port) { @@ -121,9 +121,9 @@ static uint32_t _i2c_get_sr(pyb_i2c_t i2c_port) { return (sr2 << 16) | sr1; } -static MP_BOOL _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) { +static bool _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) { I2C_TypeDef *i2c = _i2c_port_addr(i2c_port); - if (i2c == NULL) return MP_FALSE; + if (i2c == NULL) return false; // send start condition i2c->CR1 |= I2C_CR1_START; @@ -133,7 +133,7 @@ static MP_BOOL _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) { while ((_i2c_get_sr(i2c_port) & 0x00030001) != 0x00030001) { if (--timeout == 0) { //printf("timeout in _i2c_restart\n"); - return MP_FALSE; + return false; } } @@ -145,7 +145,7 @@ static MP_BOOL _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) { while ((_i2c_get_sr(i2c_port) & 0x00070082) != 0x00070082) { if (--timeout == 0) { //printf("timeout in _i2c_restart write\n"); - return MP_FALSE; + return false; } } } else { @@ -156,16 +156,16 @@ static MP_BOOL _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) { while ((_i2c_get_sr(i2c_port) & 0x00030002) != 0x00030002) { if (--timeout == 0) { //printf("timeout in _i2c_restart read\n"); - return MP_FALSE; + return false; } } } - return MP_TRUE; + return true; } -static MP_BOOL _i2c_send_byte(pyb_i2c_t i2c_port, uint8_t data) { +static bool _i2c_send_byte(pyb_i2c_t i2c_port, uint8_t data) { I2C_TypeDef *i2c = _i2c_port_addr(i2c_port); - if (i2c == NULL) return MP_FALSE; + if (i2c == NULL) return false; // send byte i2c->DR = data; @@ -174,10 +174,10 @@ static MP_BOOL _i2c_send_byte(pyb_i2c_t i2c_port, uint8_t data) { while ((_i2c_get_sr(i2c_port) & 0x00070084) != 0x00070084) { if (--timeout == 0) { //printf("timeout in _i2c_send_byte\n"); - return MP_FALSE; + return false; } } - return MP_TRUE; + return true; } static uint8_t _i2c_read_ack(pyb_i2c_t i2c_port) { @@ -220,18 +220,18 @@ static uint8_t _i2c_read_nack(pyb_i2c_t i2c_port) { return data; } -static MP_BOOL _i2c_start(pyb_i2c_t i2c_port) { +static bool _i2c_start(pyb_i2c_t i2c_port) { I2C_TypeDef *i2c = _i2c_port_addr(i2c_port); - if (i2c == NULL) return MP_FALSE; + if (i2c == NULL) return false; // wait until I2C is not busy uint32_t timeout = 1000000; while (i2c->SR2 & I2C_SR2_BUSY) { if (--timeout == 0) { - return MP_FALSE; + return false; } } - return MP_TRUE; + return true; } static void _i2c_stop(pyb_i2c_t i2c_port) { @@ -264,7 +264,7 @@ mp_obj_t i2c_obj_start(mp_obj_t self_in) { _i2c_stop(self->i2c_port); self->i2c_state = I2C_STATE_IDLE; } - if (_i2c_start(self->i2c_port) == MP_TRUE) + if (_i2c_start(self->i2c_port) == true) return mp_const_true; return mp_const_false; } @@ -272,7 +272,7 @@ mp_obj_t i2c_obj_start(mp_obj_t self_in) { mp_obj_t i2c_obj_write(mp_obj_t self_in, mp_obj_t data_in) { pyb_i2c_obj_t *self = self_in; if (self->i2c_state != I2C_STATE_WRITE) { - if (_i2c_restart(self->i2c_port, self->i2c_addr, 1) == MP_FALSE) { + if (_i2c_restart(self->i2c_port, self->i2c_addr, 1) == false) { _i2c_stop(self->i2c_port); self->i2c_state = I2C_STATE_IDLE; return mp_const_false; @@ -280,7 +280,7 @@ mp_obj_t i2c_obj_write(mp_obj_t self_in, mp_obj_t data_in) { self->i2c_state = I2C_STATE_WRITE; } uint8_t data = mp_obj_get_int(data_in); - if (_i2c_send_byte(self->i2c_port, data) == MP_FALSE) + if (_i2c_send_byte(self->i2c_port, data) == false) return mp_const_false; return mp_const_true; } @@ -288,7 +288,7 @@ mp_obj_t i2c_obj_write(mp_obj_t self_in, mp_obj_t data_in) { mp_obj_t i2c_obj_read(mp_obj_t self_in) { pyb_i2c_obj_t *self = self_in; if (self->i2c_state != I2C_STATE_READ) { - if (_i2c_restart(self->i2c_port, self->i2c_addr, 0) == MP_FALSE) { + if (_i2c_restart(self->i2c_port, self->i2c_addr, 0) == false) { _i2c_stop(self->i2c_port); self->i2c_state = I2C_STATE_IDLE; return mp_const_false; @@ -302,7 +302,7 @@ mp_obj_t i2c_obj_read(mp_obj_t self_in) { mp_obj_t i2c_obj_readAndStop(mp_obj_t self_in) { pyb_i2c_obj_t *self = self_in; if (self->i2c_state != I2C_STATE_READ) { - if (_i2c_restart(self->i2c_port, self->i2c_addr, 0) == MP_FALSE) { + if (_i2c_restart(self->i2c_port, self->i2c_addr, 0) == false) { _i2c_stop(self->i2c_port); self->i2c_state = I2C_STATE_IDLE; return mp_const_false; @@ -326,19 +326,18 @@ static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_read_obj, i2c_obj_read); static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_readAndStop_obj, i2c_obj_readAndStop); static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_stop_obj, i2c_obj_stop); -static const mp_method_t i2c_obj_type_type_methods[] = { - { "start", &i2c_obj_start_obj }, - { "write", &i2c_obj_write_obj }, - { "read", &i2c_obj_read_obj }, - { "readAndStop", &i2c_obj_readAndStop_obj }, - { "stop", &i2c_obj_stop_obj }, - { NULL, NULL }, -}; static const mp_obj_type_t i2c_obj_type = { { &mp_const_type }, "I2C", .print = i2c_obj_print, - .methods = i2c_obj_type_type_methods, + .methods = { + { "start", &i2c_obj_start_obj }, + { "write", &i2c_obj_write_obj }, + { "read", &i2c_obj_read_obj }, + { "readAndStop", &i2c_obj_readAndStop_obj }, + { "stop", &i2c_obj_stop_obj }, + { NULL, NULL }, + } }; // create the I2C object @@ -351,7 +350,7 @@ mp_obj_t pyb_I2C(mp_obj_t i2c_id, mp_obj_t i2c_addr) { case 1: i2c_port = PYB_I2C_2; break; default: return mp_const_none; } - if (_i2c_init(i2c_port) == MP_FALSE) { + if (_i2c_init(i2c_port) == false) { return mp_const_none; } pyb_i2c_obj_t *o = m_new_obj(pyb_i2c_obj_t); diff --git a/stm/led.c b/stm/led.c index e89adbb78c..9809c21771 100644 --- a/stm/led.c +++ b/stm/led.c @@ -176,16 +176,15 @@ mp_obj_t led_obj_off(mp_obj_t self_in) { static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on); static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off); -static const mp_method_t led_obj_type_methods[] = { - { "on", &led_obj_on_obj }, - { "off", &led_obj_off_obj }, - { NULL, NULL }, -}; static const mp_obj_type_t led_obj_type = { { &mp_const_type }, "Led", .print = led_obj_print, - .methods = led_obj_type_methods, + .methods = { + { "on", &led_obj_on_obj }, + { "off", &led_obj_off_obj }, + { NULL, NULL }, + } }; mp_obj_t pyb_Led(mp_obj_t led_id) { diff --git a/stm/lexerstm.c b/stm/lexerstm.c index 6de908317b..661dfb0160 100644 --- a/stm/lexerstm.c +++ b/stm/lexerstm.c @@ -21,7 +21,7 @@ void str_buf_free(mp_lexer_str_buf_t *sb) { } } -mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, MP_BOOL free_str, mp_lexer_str_buf_t *sb) { +mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str, mp_lexer_str_buf_t *sb) { sb->free = free_str; sb->src_beg = str; sb->src_cur = str; diff --git a/stm/lexerstm.h b/stm/lexerstm.h index 99c270a718..7e090898a2 100644 --- a/stm/lexerstm.h +++ b/stm/lexerstm.h @@ -1,5 +1,5 @@ typedef struct _py_lexer_str_buf_t { - MP_BOOL free; // free src_beg when done + bool free; // free src_beg when done const char *src_beg; // beginning of source const char *src_cur; // current location in source const char *src_end; // end (exclusive) of source @@ -12,5 +12,5 @@ typedef struct _py_lexer_file_buf_t { uint16_t pos; } mp_lexer_file_buf_t; -mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, MP_BOOL free_str, mp_lexer_str_buf_t *sb); +mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str, mp_lexer_str_buf_t *sb); mp_lexer_t *mp_lexer_new_from_file(const char *filename, mp_lexer_file_buf_t *fb); diff --git a/stm/main.c b/stm/main.c index e1b695167c..07c974eff8 100644 --- a/stm/main.c +++ b/stm/main.c @@ -359,7 +359,7 @@ int readline(vstr_t *line, const char *prompt) { readline_hist[0] = strdup(vstr_str(line)); return 1; } else if (c == 27) { - escape = MP_TRUE; + escape = true; } else if (c == 127) { if (vstr_len(line) > len) { vstr_cut_tail(line, 1); @@ -432,12 +432,12 @@ void do_repl(void) { } mp_lexer_str_buf_t sb; - mp_lexer_t *lex = mp_lexer_new_from_str_len("", vstr_str(&line), vstr_len(&line), MP_FALSE, &sb); + mp_lexer_t *lex = mp_lexer_new_from_str_len("", vstr_str(&line), vstr_len(&line), false, &sb); mp_parse_node_t pn = mp_parse(lex, MP_PARSE_SINGLE_INPUT); mp_lexer_free(lex); if (pn != MP_PARSE_NODE_NULL) { - mp_obj_t module_fun = mp_compile(pn, MP_TRUE); + mp_obj_t module_fun = mp_compile(pn, true); if (module_fun != mp_const_none) { nlr_buf_t nlr; uint32_t start = sys_tick_counter; @@ -461,37 +461,37 @@ void do_repl(void) { stdout_tx_str("\r\n"); } -MP_BOOL do_file(const char *filename) { +bool do_file(const char *filename) { mp_lexer_file_buf_t fb; mp_lexer_t *lex = mp_lexer_new_from_file(filename, &fb); if (lex == NULL) { printf("could not open file '%s' for reading\n", filename); - return MP_FALSE; + return false; } mp_parse_node_t pn = mp_parse(lex, MP_PARSE_FILE_INPUT); mp_lexer_free(lex); if (pn == MP_PARSE_NODE_NULL) { - return MP_FALSE; + return false; } - mp_obj_t module_fun = mp_compile(pn, MP_FALSE); + mp_obj_t module_fun = mp_compile(pn, false); if (module_fun == mp_const_none) { - return MP_FALSE; + return false; } nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { rt_call_function_0(module_fun); nlr_pop(); - return MP_TRUE; + return true; } else { // uncaught exception mp_obj_print((mp_obj_t)nlr.ret_val); printf("\n"); - return MP_FALSE; + return false; } } @@ -689,12 +689,6 @@ static MP_DEFINE_CONST_FUN_OBJ_1(file_obj_close_obj, file_obj_close); // TODO gc hook to close the file if not already closed -static const mp_method_t file_obj_type_methods[] = { - { "read", &file_obj_read_obj }, - { "write", &file_obj_write_obj }, - { "close", &file_obj_close_obj }, - { NULL, NULL }, -}; static const mp_obj_type_t file_obj_type = { { &mp_const_type }, "File", @@ -705,7 +699,12 @@ static const mp_obj_type_t file_obj_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - .methods = file_obj_type_methods, + .methods = { + { "read", &file_obj_read_obj }, + { "write", &file_obj_write_obj }, + { "close", &file_obj_close_obj }, + {NULL, NULL}, + } }; mp_obj_t pyb_io_open(mp_obj_t o_filename, mp_obj_t o_mode) { @@ -779,7 +778,7 @@ int main(void) { //usart_init(); disabled while wi-fi is enabled - int first_soft_reset = MP_TRUE; + int first_soft_reset = true; soft_reset: @@ -848,12 +847,12 @@ soft_reset: lcd_print_str(" micro py board\n"); // check if user switch held (initiates reset of filesystem) - MP_BOOL reset_filesystem = MP_FALSE; + bool reset_filesystem = false; if (switch_get()) { - reset_filesystem = MP_TRUE; + reset_filesystem = true; for (int i = 0; i < 50; i++) { if (!switch_get()) { - reset_filesystem = MP_FALSE; + reset_filesystem = false; break; } sys_tick_delay_ms(10); @@ -1064,7 +1063,7 @@ soft_reset: "f()\n"; mp_lexer_str_buf_t mp_lexer_str_buf; - mp_lexer_t *lex = mp_lexer_new_from_str_len("", pysrc, strlen(pysrc), MP_FALSE, &mp_lexer_str_buf); + mp_lexer_t *lex = mp_lexer_new_from_str_len("", pysrc, strlen(pysrc), false, &mp_lexer_str_buf); // nalloc=1740;6340;6836 -> 140;4600;496 bytes for lexer, parser, compiler printf("lex; al=%u\n", m_get_total_bytes_allocated()); @@ -1075,7 +1074,7 @@ soft_reset: printf("pars;al=%u\n", m_get_total_bytes_allocated()); sys_tick_delay_ms(1000); //parse_node_show(pn, 0); - mp_obj_t module_fun = mp_compile(pn, MP_FALSE); + mp_obj_t module_fun = mp_compile(pn, false); printf("comp;al=%u\n", m_get_total_bytes_allocated()); sys_tick_delay_ms(1000); @@ -1172,7 +1171,7 @@ soft_reset: printf("PYB: soft reboot\n"); - first_soft_reset = MP_FALSE; + first_soft_reset = false; goto soft_reset; } diff --git a/stm/printf.c b/stm/printf.c index 7ada626bd5..8a59f8a986 100644 --- a/stm/printf.c +++ b/stm/printf.c @@ -152,10 +152,10 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) { } // parse long specifiers (current not used) - //MP_BOOL long_arg = MP_FALSE; + //bool long_arg = false; if (*fmt == 'l') { ++fmt; - //long_arg = MP_TRUE; + //long_arg = true; } if (*fmt == '\0') { @@ -215,14 +215,14 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) { void stdout_print_strn(void *data, const char *str, unsigned int len) { // send stdout to USART, USB CDC VCP, and LCD if nothing else - MP_BOOL any = MP_FALSE; + bool any = false; if (usart_is_enabled()) { usart_tx_strn_cooked(str, len); - any = MP_TRUE; + any = true; } if (usb_vcp_is_enabled()) { usb_vcp_send_strn_cooked(str, len); - any = MP_TRUE; + any = true; } if (!any) { lcd_print_strn(str, len); diff --git a/stm/pybwlan.c b/stm/pybwlan.c index cffa016844..6988f1c848 100644 --- a/stm/pybwlan.c +++ b/stm/pybwlan.c @@ -336,7 +336,7 @@ void CC3000_UsynchCallback(long lEventType, char * data, unsigned char length) socketnum = data[0]; //PRINT_F("TCP Close wait #"); printDec(socketnum); if (socketnum < MAX_SOCKETS) - closed_sockets[socketnum] = MP_TRUE; + closed_sockets[socketnum] = true; */ } } diff --git a/stm/servo.c b/stm/servo.c index 7facce7456..31190ce795 100644 --- a/stm/servo.c +++ b/stm/servo.c @@ -137,15 +137,14 @@ static mp_obj_t servo_obj_angle(mp_obj_t self_in, mp_obj_t angle) { static MP_DEFINE_CONST_FUN_OBJ_2(servo_obj_angle_obj, servo_obj_angle); -static const mp_method_t servo_obj_type_methods[] = { - { "angle", &servo_obj_angle_obj }, - { NULL, NULL }, -}; static const mp_obj_type_t servo_obj_type = { { &mp_const_type }, "Servo", .print = servo_obj_print, - .methods = servo_obj_type_methods, + .methods = { + { "angle", &servo_obj_angle_obj }, + { NULL, NULL }, + } }; mp_obj_t pyb_Servo(mp_obj_t servo_id) { diff --git a/stm/storage.c b/stm/storage.c index f1ec9f6522..daee4adb5e 100644 --- a/stm/storage.c +++ b/stm/storage.c @@ -15,18 +15,18 @@ #define FLASH_PART1_NUM_BLOCKS (224) // 16k+16k+16k+64k=112k #define FLASH_MEM_START_ADDR (0x08004000) // sector 1, 16k -static MP_BOOL is_initialised = MP_FALSE; +static bool is_initialised = false; static uint32_t cache_flash_sector_id; static uint32_t cache_flash_sector_start; static uint32_t cache_flash_sector_size; -static MP_BOOL cache_dirty; +static bool cache_dirty; static uint32_t sys_tick_counter_last_write; static void cache_flush(void) { if (cache_dirty) { // sync the cache RAM buffer by writing it to the flash page flash_write(cache_flash_sector_start, (const uint32_t*)CACHE_MEM_START_ADDR, cache_flash_sector_size / 4); - cache_dirty = MP_FALSE; + cache_dirty = false; // indicate a clean cache with LED off led_state(PYB_LED_R1, 0); } @@ -43,7 +43,7 @@ static uint8_t *cache_get_addr_for_write(uint32_t flash_addr) { cache_flash_sector_start = flash_sector_start; cache_flash_sector_size = flash_sector_size; } - cache_dirty = MP_TRUE; + cache_dirty = true; // indicate a dirty cache with LED on led_state(PYB_LED_R1, 1); return (uint8_t*)CACHE_MEM_START_ADDR + flash_addr - flash_sector_start; @@ -64,8 +64,8 @@ static uint8_t *cache_get_addr_for_read(uint32_t flash_addr) { void storage_init(void) { if (!is_initialised) { cache_flash_sector_id = 0; - cache_dirty = MP_FALSE; - is_initialised = MP_TRUE; + cache_dirty = false; + is_initialised = true; sys_tick_counter_last_write = 0; } } @@ -78,7 +78,7 @@ uint32_t storage_get_block_count(void) { return FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS; } -MP_BOOL storage_needs_flush(void) { +bool storage_needs_flush(void) { // wait 2 seconds after last write to flush return cache_dirty && sys_tick_has_passed(sys_tick_counter_last_write, 2000); } @@ -123,7 +123,7 @@ static void build_partition(uint8_t *buf, int boot, int type, uint32_t start_blo buf[15] = num_blocks >> 24; } -MP_BOOL storage_read_block(uint8_t *dest, uint32_t block) { +bool storage_read_block(uint8_t *dest, uint32_t block) { //printf("RD %u\n", block); if (block == 0) { // fake the MBR so we can decide on our own partition table @@ -140,26 +140,26 @@ MP_BOOL storage_read_block(uint8_t *dest, uint32_t block) { dest[510] = 0x55; dest[511] = 0xaa; - return MP_TRUE; + return true; } else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS) { // non-MBR block, get data from flash memory, possibly via cache uint32_t flash_addr = FLASH_MEM_START_ADDR + (block - FLASH_PART1_START_BLOCK) * BLOCK_SIZE; uint8_t *src = cache_get_addr_for_read(flash_addr); memcpy(dest, src, BLOCK_SIZE); - return MP_TRUE; + return true; } else { // bad block number - return MP_FALSE; + return false; } } -MP_BOOL storage_write_block(const uint8_t *src, uint32_t block) { +bool storage_write_block(const uint8_t *src, uint32_t block) { //printf("WR %u\n", block); if (block == 0) { // can't write MBR, but pretend we did - return MP_TRUE; + return true; } else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS) { // non-MBR block, copy to cache @@ -167,10 +167,10 @@ MP_BOOL storage_write_block(const uint8_t *src, uint32_t block) { uint8_t *dest = cache_get_addr_for_write(flash_addr); memcpy(dest, src, BLOCK_SIZE); sys_tick_counter_last_write = sys_tick_counter; - return MP_TRUE; + return true; } else { // bad block number - return MP_FALSE; + return false; } } diff --git a/stm/storage.h b/stm/storage.h index 7bdcfc7cce..fe37e8b27c 100644 --- a/stm/storage.h +++ b/stm/storage.h @@ -1,7 +1,7 @@ void storage_init(void); uint32_t storage_get_block_size(void); uint32_t storage_get_block_count(void); -MP_BOOL storage_needs_flush(void); +bool storage_needs_flush(void); void storage_flush(void); -MP_BOOL storage_read_block(uint8_t *dest, uint32_t block); -MP_BOOL storage_write_block(const uint8_t *src, uint32_t block); +bool storage_read_block(uint8_t *dest, uint32_t block); +bool storage_write_block(const uint8_t *src, uint32_t block); diff --git a/stm/systick.c b/stm/systick.c index f9def4a026..40ae532793 100644 --- a/stm/systick.c +++ b/stm/systick.c @@ -43,7 +43,7 @@ void sys_tick_wait_at_least(uint32_t stc, uint32_t delay_ms) { } } -MP_BOOL sys_tick_has_passed(uint32_t stc, uint32_t delay_ms) { +bool sys_tick_has_passed(uint32_t stc, uint32_t delay_ms) { // stc_wait is the value of sys_tick_counter that we wait for uint32_t stc_wait = stc + delay_ms; if (stc_wait < stc) { diff --git a/stm/systick.h b/stm/systick.h index 518d872c25..7d2deed119 100644 --- a/stm/systick.h +++ b/stm/systick.h @@ -4,4 +4,4 @@ void sys_tick_init(void); void SysTick_Handler(void); void sys_tick_delay_ms(uint32_t delay_ms); void sys_tick_wait_at_least(uint32_t stc, uint32_t delay_ms); -MP_BOOL sys_tick_has_passed(uint32_t stc, uint32_t delay_ms); +bool sys_tick_has_passed(uint32_t stc, uint32_t delay_ms); diff --git a/stm/usart.c b/stm/usart.c index 6e300a29e4..307aff1662 100644 --- a/stm/usart.c +++ b/stm/usart.c @@ -5,7 +5,7 @@ #include "misc.h" #include "usart.h" -static MP_BOOL is_enabled; +static bool is_enabled; // USART6 on PC6 (TX), PC7 (RX) void usart_init(void) { @@ -33,14 +33,14 @@ void usart_init(void) { USART_Cmd(USART6, ENABLE); - is_enabled = MP_TRUE; + is_enabled = true; } -MP_BOOL usart_is_enabled(void) { +bool usart_is_enabled(void) { return is_enabled; } -MP_BOOL usart_rx_any(void) { +bool usart_rx_any(void) { return USART_GetFlagStatus(USART6, USART_FLAG_RXNE) == SET; } diff --git a/stm/usart.h b/stm/usart.h index ad57587ce3..9d92e59f5a 100644 --- a/stm/usart.h +++ b/stm/usart.h @@ -1,6 +1,6 @@ void usart_init(void); -MP_BOOL usart_is_enabled(void); -MP_BOOL usart_rx_any(void); +bool usart_is_enabled(void); +bool usart_rx_any(void); int usart_rx_char(void); void usart_tx_char(int c); void usart_tx_str(const char *str); diff --git a/stm/usb.c b/stm/usb.c index 6b553914ec..b0fbfa1941 100644 --- a/stm/usb.c +++ b/stm/usb.c @@ -30,7 +30,7 @@ void usb_init(void) { is_enabled = 1; } -MP_BOOL usb_vcp_is_enabled(void) { +bool usb_vcp_is_enabled(void) { return is_enabled; } diff --git a/stm/usb.h b/stm/usb.h index 6f8172a3fb..c4b3b151fb 100644 --- a/stm/usb.h +++ b/stm/usb.h @@ -1,5 +1,5 @@ void usb_init(void); -MP_BOOL usb_vcp_is_enabled(void); +bool usb_vcp_is_enabled(void); int usb_vcp_rx_any(void); char usb_vcp_rx_get(void); void usb_vcp_send_str(const char* str); diff --git a/unix-cpy/main.c b/unix-cpy/main.c index b1e99ac12a..eba97f527b 100644 --- a/unix-cpy/main.c +++ b/unix-cpy/main.c @@ -37,7 +37,7 @@ void do_file(const char *file) { //printf("----------------\n"); //parse_node_show(pn, 0); //printf("----------------\n"); - mp_obj_t module_fun = mp_compile(pn, MP_FALSE); + mp_obj_t module_fun = mp_compile(pn, false); //printf("----------------\n"); if (module_fun == mp_const_none) { diff --git a/unix/main.c b/unix/main.c index e3873489d1..a06dc36791 100644 --- a/unix/main.c +++ b/unix/main.c @@ -79,13 +79,13 @@ static void do_repl(void) { } } - mp_lexer_t *lex = mp_lexer_new_from_str_len("", line, strlen(line), MP_FALSE); + mp_lexer_t *lex = mp_lexer_new_from_str_len("", line, strlen(line), false); mp_parse_node_t pn = mp_parse(lex, MP_PARSE_SINGLE_INPUT); mp_lexer_free(lex); if (pn != MP_PARSE_NODE_NULL) { //mp_parse_node_show(pn, 0); - mp_obj_t module_fun = mp_compile(pn, MP_TRUE); + mp_obj_t module_fun = mp_compile(pn, true); if (module_fun != mp_const_none) { nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { @@ -139,7 +139,7 @@ void do_file(const char *file) { //printf("----------------\n"); //parse_node_show(pn, 0); //printf("----------------\n"); - mp_obj_t module_fun = mp_compile(pn, MP_FALSE); + mp_obj_t module_fun = mp_compile(pn, false); //printf("----------------\n"); #if MICROPY_EMIT_CPYTHON @@ -166,7 +166,7 @@ void do_file(const char *file) { typedef struct _test_obj_t { mp_obj_base_t base; - MP_BOOL value; + bool value; } test_obj_t; static void test_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) { From e2e3d11e8744395d3103b824adc8609b13f2cdba Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 6 Jan 2014 22:13:00 +0000 Subject: [PATCH 07/17] py: Fix up number operations and coercion. --- examples/mandel.py | 14 +++++++ py/asmx64.c | 2 +- py/obj.h | 2 + py/objcomplex.c | 70 +++++++++++++++++---------------- py/objfloat.c | 43 ++++++++++++--------- py/runtime.c | 96 ++++++++++++++++++++++++---------------------- 6 files changed, 129 insertions(+), 98 deletions(-) create mode 100644 examples/mandel.py diff --git a/examples/mandel.py b/examples/mandel.py new file mode 100644 index 0000000000..b13b7d87f8 --- /dev/null +++ b/examples/mandel.py @@ -0,0 +1,14 @@ +@micropython.native +def in_set(c): + z = 0 + for i in range(40): + z = z*z + c + if abs(z) > 60: + return False + return True + +for v in range(31): + line = [] + for u in range(91): + line.append('*' if in_set((u / 30 - 2) + (v / 15 - 1) * 1j) else ' ') + print(''.join(line)) diff --git a/py/asmx64.c b/py/asmx64.c index ed9ca80f5c..226d4efee8 100644 --- a/py/asmx64.c +++ b/py/asmx64.c @@ -155,7 +155,7 @@ void asm_x64_end_pass(asm_x64_t *as) { //as->code_base = m_new(byte, as->code_size); need to allocale executable memory uint actual_alloc; as->code_base = alloc_mem(as->code_size, &actual_alloc, true); - printf("code_size: %u\n", as->code_size); + //printf("code_size: %u\n", as->code_size); } /* diff --git a/py/obj.h b/py/obj.h index 88a611ba7b..1ba7427cbb 100644 --- a/py/obj.h +++ b/py/obj.h @@ -200,10 +200,12 @@ qstr mp_obj_str_get(mp_obj_t self_in); // float extern const mp_obj_type_t float_type; mp_float_t mp_obj_float_get(mp_obj_t self_in); +mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs); // complex extern const mp_obj_type_t complex_type; void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag); +mp_obj_t mp_obj_complex_binary_op(int op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in); #endif // tuple diff --git a/py/objcomplex.c b/py/objcomplex.c index fc32f96674..46f43b54b5 100644 --- a/py/objcomplex.c +++ b/py/objcomplex.c @@ -48,14 +48,14 @@ static mp_obj_t complex_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *a { mp_float_t real, imag; if (MP_OBJ_IS_TYPE(args[1], &complex_type)) { - mp_obj_get_complex(args[1], &real, &imag); + mp_obj_complex_get(args[1], &real, &imag); } else { real = mp_obj_get_float(args[1]); imag = 0; } if (MP_OBJ_IS_TYPE(args[0], &complex_type)) { mp_float_t real2, imag2; - mp_obj_get_complex(args[0], &real2, &imag2); + mp_obj_complex_get(args[0], &real2, &imag2); real -= imag2; imag += real2; } else { @@ -80,9 +80,41 @@ static mp_obj_t complex_unary_op(int op, mp_obj_t o_in) { } static mp_obj_t complex_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { - mp_float_t lhs_real, lhs_imag, rhs_real, rhs_imag; - mp_obj_complex_get(lhs_in, &lhs_real, &lhs_imag); - mp_obj_complex_get(rhs_in, &rhs_real, &rhs_imag); + mp_obj_complex_t *lhs = lhs_in; + return mp_obj_complex_binary_op(op, lhs->real, lhs->imag, rhs_in); +} + +const mp_obj_type_t complex_type = { + { &mp_const_type }, + "complex", + complex_print, // print + complex_make_new, // make_new + NULL, // call_n + complex_unary_op, // unary_op + complex_binary_op, // binary_op + NULL, // getiter + NULL, // iternext + .methods = { { NULL, NULL }, }, +}; + +mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag) { + mp_obj_complex_t *o = m_new_obj(mp_obj_complex_t); + o->base.type = &complex_type; + o->real = real; + o->imag = imag; + return o; +} + +void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag) { + assert(MP_OBJ_IS_TYPE(self_in, &complex_type)); + mp_obj_complex_t *self = self_in; + *real = self->real; + *imag = self->imag; +} + +mp_obj_t mp_obj_complex_binary_op(int op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in) { + mp_float_t rhs_real, rhs_imag; + mp_obj_get_complex(rhs_in, &rhs_real, &rhs_imag); // can be any type, this function will convert to float (if possible) switch (op) { case RT_BINARY_OP_ADD: case RT_BINARY_OP_INPLACE_ADD: @@ -115,32 +147,4 @@ static mp_obj_t complex_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { return mp_obj_new_complex(lhs_real, lhs_imag); } -const mp_obj_type_t complex_type = { - { &mp_const_type }, - "complex", - complex_print, // print - complex_make_new, // make_new - NULL, // call_n - complex_unary_op, // unary_op - complex_binary_op, // binary_op - NULL, // getiter - NULL, // iternext - .methods = { { NULL, NULL }, }, -}; - -mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag) { - mp_obj_complex_t *o = m_new_obj(mp_obj_complex_t); - o->base.type = &complex_type; - o->real = real; - o->imag = imag; - return o; -} - -void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag) { - assert(MP_OBJ_IS_TYPE(self_in, &complex_type)); - mp_obj_complex_t *self = self_in; - *real = self->real; - *imag = self->imag; -} - #endif diff --git a/py/objfloat.c b/py/objfloat.c index 0250172ad3..336ae597fc 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -53,27 +53,12 @@ static mp_obj_t float_unary_op(int op, mp_obj_t o_in) { } static mp_obj_t float_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { + mp_obj_float_t *lhs = lhs_in; if (MP_OBJ_IS_TYPE(rhs_in, &complex_type)) { - return complex_type.binary_op(op, lhs_in, rhs_in); + return mp_obj_complex_binary_op(op, lhs->value, 0, rhs_in); + } else { + return mp_obj_float_binary_op(op, lhs->value, rhs_in); } - mp_float_t lhs_val = mp_obj_get_float(lhs_in); - mp_float_t rhs_val = mp_obj_get_float(rhs_in); - switch (op) { - case RT_BINARY_OP_ADD: - case RT_BINARY_OP_INPLACE_ADD: lhs_val += rhs_val; break; - case RT_BINARY_OP_SUBTRACT: - case RT_BINARY_OP_INPLACE_SUBTRACT: lhs_val -= rhs_val; break; - case RT_BINARY_OP_MULTIPLY: - case RT_BINARY_OP_INPLACE_MULTIPLY: lhs_val *= rhs_val; break; - /* TODO floor(?) the value - case RT_BINARY_OP_FLOOR_DIVIDE: - case RT_BINARY_OP_INPLACE_FLOOR_DIVIDE: val = lhs_val / rhs_val; break; - */ - case RT_BINARY_OP_TRUE_DIVIDE: - case RT_BINARY_OP_INPLACE_TRUE_DIVIDE: lhs_val /= rhs_val; break; - return NULL; // op not supported - } - return mp_obj_new_float(lhs_val); } const mp_obj_type_t float_type = { @@ -99,4 +84,24 @@ mp_float_t mp_obj_float_get(mp_obj_t self_in) { return self->value; } +mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs_in) { + mp_float_t rhs_val = mp_obj_get_float(rhs_in); // can be any type, this function will convert to float (if possible) + switch (op) { + case RT_BINARY_OP_ADD: + case RT_BINARY_OP_INPLACE_ADD: lhs_val += rhs_val; break; + case RT_BINARY_OP_SUBTRACT: + case RT_BINARY_OP_INPLACE_SUBTRACT: lhs_val -= rhs_val; break; + case RT_BINARY_OP_MULTIPLY: + case RT_BINARY_OP_INPLACE_MULTIPLY: lhs_val *= rhs_val; break; + /* TODO floor(?) the value + case RT_BINARY_OP_FLOOR_DIVIDE: + case RT_BINARY_OP_INPLACE_FLOOR_DIVIDE: val = lhs_val / rhs_val; break; + */ + case RT_BINARY_OP_TRUE_DIVIDE: + case RT_BINARY_OP_INPLACE_TRUE_DIVIDE: lhs_val /= rhs_val; break; + return NULL; // op not supported + } + return mp_obj_new_float(lhs_val); +} + #endif diff --git a/py/runtime.c b/py/runtime.c index 197c08b55a..6bc71abff7 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -452,57 +452,63 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { // then fail // note that list does not implement + or +=, so that inplace_concat is reached first for += - if (MP_OBJ_IS_SMALL_INT(lhs) && MP_OBJ_IS_SMALL_INT(rhs)) { + if (MP_OBJ_IS_SMALL_INT(lhs)) { mp_small_int_t lhs_val = MP_OBJ_SMALL_INT_VALUE(lhs); - mp_small_int_t rhs_val = MP_OBJ_SMALL_INT_VALUE(rhs); - switch (op) { - case RT_BINARY_OP_OR: - case RT_BINARY_OP_INPLACE_OR: lhs_val |= rhs_val; break; - case RT_BINARY_OP_XOR: - case RT_BINARY_OP_INPLACE_XOR: lhs_val ^= rhs_val; break; - case RT_BINARY_OP_AND: - case RT_BINARY_OP_INPLACE_AND: lhs_val &= rhs_val; break; - case RT_BINARY_OP_LSHIFT: - case RT_BINARY_OP_INPLACE_LSHIFT: lhs_val <<= rhs_val; break; - case RT_BINARY_OP_RSHIFT: - case RT_BINARY_OP_INPLACE_RSHIFT: lhs_val >>= rhs_val; break; - case RT_BINARY_OP_ADD: - case RT_BINARY_OP_INPLACE_ADD: lhs_val += rhs_val; break; - case RT_BINARY_OP_SUBTRACT: - case RT_BINARY_OP_INPLACE_SUBTRACT: lhs_val -= rhs_val; break; - case RT_BINARY_OP_MULTIPLY: - case RT_BINARY_OP_INPLACE_MULTIPLY: lhs_val *= rhs_val; break; - case RT_BINARY_OP_FLOOR_DIVIDE: - case RT_BINARY_OP_INPLACE_FLOOR_DIVIDE: lhs_val /= rhs_val; break; -#if MICROPY_ENABLE_FLOAT - case RT_BINARY_OP_TRUE_DIVIDE: - case RT_BINARY_OP_INPLACE_TRUE_DIVIDE: return mp_obj_new_float((mp_float_t)lhs_val / (mp_float_t)rhs_val); -#endif + if (MP_OBJ_IS_SMALL_INT(rhs)) { + mp_small_int_t rhs_val = MP_OBJ_SMALL_INT_VALUE(rhs); + switch (op) { + case RT_BINARY_OP_OR: + case RT_BINARY_OP_INPLACE_OR: lhs_val |= rhs_val; break; + case RT_BINARY_OP_XOR: + case RT_BINARY_OP_INPLACE_XOR: lhs_val ^= rhs_val; break; + case RT_BINARY_OP_AND: + case RT_BINARY_OP_INPLACE_AND: lhs_val &= rhs_val; break; + case RT_BINARY_OP_LSHIFT: + case RT_BINARY_OP_INPLACE_LSHIFT: lhs_val <<= rhs_val; break; + case RT_BINARY_OP_RSHIFT: + case RT_BINARY_OP_INPLACE_RSHIFT: lhs_val >>= rhs_val; break; + case RT_BINARY_OP_ADD: + case RT_BINARY_OP_INPLACE_ADD: lhs_val += rhs_val; break; + case RT_BINARY_OP_SUBTRACT: + case RT_BINARY_OP_INPLACE_SUBTRACT: lhs_val -= rhs_val; break; + case RT_BINARY_OP_MULTIPLY: + case RT_BINARY_OP_INPLACE_MULTIPLY: lhs_val *= rhs_val; break; + case RT_BINARY_OP_FLOOR_DIVIDE: + case RT_BINARY_OP_INPLACE_FLOOR_DIVIDE: lhs_val /= rhs_val; break; + #if MICROPY_ENABLE_FLOAT + case RT_BINARY_OP_TRUE_DIVIDE: + case RT_BINARY_OP_INPLACE_TRUE_DIVIDE: return mp_obj_new_float((mp_float_t)lhs_val / (mp_float_t)rhs_val); + #endif - // TODO implement modulo as specified by Python - case RT_BINARY_OP_MODULO: - case RT_BINARY_OP_INPLACE_MODULO: lhs_val %= rhs_val; break; + // TODO implement modulo as specified by Python + case RT_BINARY_OP_MODULO: + case RT_BINARY_OP_INPLACE_MODULO: lhs_val %= rhs_val; break; - // TODO check for negative power, and overflow - case RT_BINARY_OP_POWER: - case RT_BINARY_OP_INPLACE_POWER: - { - int ans = 1; - while (rhs_val > 0) { - if (rhs_val & 1) { - ans *= lhs_val; + // TODO check for negative power, and overflow + case RT_BINARY_OP_POWER: + case RT_BINARY_OP_INPLACE_POWER: + { + int ans = 1; + while (rhs_val > 0) { + if (rhs_val & 1) { + ans *= lhs_val; + } + lhs_val *= lhs_val; + rhs_val /= 2; } - lhs_val *= lhs_val; - rhs_val /= 2; + lhs_val = ans; + break; } - lhs_val = ans; - break; - } - default: assert(0); - } - if (fit_small_int(lhs_val)) { - return MP_OBJ_NEW_SMALL_INT(lhs_val); + default: assert(0); + } + if (fit_small_int(lhs_val)) { + return MP_OBJ_NEW_SMALL_INT(lhs_val); + } + } else if (MP_OBJ_IS_TYPE(rhs, &float_type)) { + return mp_obj_float_binary_op(op, lhs_val, rhs); + } else if (MP_OBJ_IS_TYPE(rhs, &complex_type)) { + return mp_obj_complex_binary_op(op, lhs_val, 0, rhs); } } else if (MP_OBJ_IS_OBJ(lhs)) { mp_obj_base_t *o = lhs; From a5a01df81d01705b9f04264cc46fbb1bc32641b3 Mon Sep 17 00:00:00 2001 From: ian-v Date: Mon, 6 Jan 2014 14:14:11 -0800 Subject: [PATCH 08/17] Make list and str method tables static --- py/objlist.c | 2 +- py/objstr.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/py/objlist.c b/py/objlist.c index 52eb488379..b642b7015a 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -261,7 +261,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(list_remove_obj, list_remove); static MP_DEFINE_CONST_FUN_OBJ_1(list_reverse_obj, list_reverse); static MP_DEFINE_CONST_FUN_OBJ_2(list_sort_obj, list_sort); -const mp_method_t list_type_methods[] = { +static const mp_method_t list_type_methods[] = { { "append", &list_append_obj }, { "clear", &list_clear_obj }, { "copy", &list_copy_obj }, diff --git a/py/objstr.c b/py/objstr.c index 08e3793916..66041c587f 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -184,7 +184,7 @@ mp_obj_t str_format(int n_args, const mp_obj_t *args) { static MP_DEFINE_CONST_FUN_OBJ_2(str_join_obj, str_join); static MP_DEFINE_CONST_FUN_OBJ_VAR(str_format_obj, 1, str_format); -const mp_method_t str_type_methods[] = { +static const mp_method_t str_type_methods[] = { { "join", &str_join_obj }, { "format", &str_format_obj }, { NULL, NULL }, // end-of-list sentinel From ff07bb3adb50481d6b7be94755e07df893f374dc Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 6 Jan 2014 22:17:37 +0000 Subject: [PATCH 09/17] stm: Re-fix LED defines. --- stm/led.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stm/led.c b/stm/led.c index 19ce99cecb..d4bc0a0c87 100644 --- a/stm/led.c +++ b/stm/led.c @@ -8,10 +8,10 @@ #include "led.h" /* LED numbers, used internally */ -#define PYB_LED_1 (0) -#define PYB_LED_2 (1) -#define PYB_LED_3 (2) -#define PYB_LED_4 (3) +#define PYB_LED_1 (1) +#define PYB_LED_2 (2) +#define PYB_LED_3 (3) +#define PYB_LED_4 (4) #if defined(PYBOARD) #define PYB_LED1_PORT (GPIOA) From 501399330ecae4b055120787f08707d4ea1a5532 Mon Sep 17 00:00:00 2001 From: Mark Schafer Date: Tue, 7 Jan 2014 15:01:10 +1300 Subject: [PATCH 10/17] vector logo master with layers inkscape master file has dxf and coloured svg layers. Choose a layer for suitable work. --- logo/vector-logo-2-BW.svg | 587 ++++++++++ logo/vector-logo-2.png | Bin 0 -> 90783 bytes logo/vector-logo-inkscape_master.svg | 1471 ++++++++++++++++++++++++++ 3 files changed, 2058 insertions(+) create mode 100644 logo/vector-logo-2-BW.svg create mode 100644 logo/vector-logo-2.png create mode 100644 logo/vector-logo-inkscape_master.svg diff --git a/logo/vector-logo-2-BW.svg b/logo/vector-logo-2-BW.svg new file mode 100644 index 0000000000..d7ff920f98 --- /dev/null +++ b/logo/vector-logo-2-BW.svg @@ -0,0 +1,587 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/logo/vector-logo-2.png b/logo/vector-logo-2.png new file mode 100644 index 0000000000000000000000000000000000000000..3ad2383ff55529517a04245157d25834c161e230 GIT binary patch literal 90783 zcmYg&2RzjOA3rW+r;_Ztj3o2y**BY_R7Q4m$jmyMOCmEzMpnv5$hgciF3LOs;31jQ{83`}_X?e~*WU2lxKGKkxTzK3~hrJ4U)JjNFV=R8%bbdRit_R5bIz_s(fL z;4cdSe|mu*r+jYe-#-m}g`9Sb0e)xj(zEaZ){lVS)HknY1pt5K^3^u?z2^z{Mc8{k zra~YP5-uLDJ`VO?k0m_4owA6k+*DMTsPwh|xgU_dibrHSYBwDJ9Y6=BXZv?op6XVT zh>2yq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GpVKFJz3!Z!4J>}oxE-jbqW+dB1WVDx8h#lfqCWcjP`a>H%xyPk2a=FRPmeJW` zVOQ=VBF<+TGTtO4*KIZ7j?U&Q4Q2F=e_8jsgq{=^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 136f67523b10d24dd65cb25e49e07a7e4e5341a1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 7 Jan 2014 14:54:15 +0000 Subject: [PATCH 11/17] Factor and simplify Makefile's and mpconfig. --- py/mpconfig.h | 74 +++++++++++++++----- py/py.mk | 100 +++++++++++++++++++++++++++ py/repl.c | 5 ++ py/repl.h | 2 + stm/mpconfigport.h | 5 +- unix-cpy/Makefile | 94 +++++-------------------- unix-cpy/main.c | 1 - unix-cpy/mpconfigport.h | 3 - unix/Makefile | 99 +++++--------------------- unix/main.c | 149 ++++++++++++++++++++-------------------- unix/mpconfigport.h | 5 +- 11 files changed, 278 insertions(+), 259 deletions(-) create mode 100644 py/py.mk diff --git a/py/mpconfig.h b/py/mpconfig.h index 56495d9156..8ce432a61e 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -4,8 +4,65 @@ #include -#ifndef INT_FMT +// Any options not explicitly set in mpconfigport.h will get default +// values below. + +/*****************************************************************************/ +/* Micro Python emitters */ + +// Whether to emit CPython byte codes (for debugging/testing) +// Enabling this overrides all other emitters +#ifndef MICROPY_EMIT_CPYTHON +#define MICROPY_EMIT_CPYTHON (0) +#endif + +// Whether to emit x64 native code +#ifndef MICROPY_EMIT_X64 +#define MICROPY_EMIT_X64 (0) +#endif + +// Whether to emit thumb native code +#ifndef MICROPY_EMIT_THUMB +#define MICROPY_EMIT_THUMB (0) +#endif + +// Whether to enable the thumb inline assembler +#ifndef MICROPY_EMIT_INLINE_THUMB +#define MICROPY_EMIT_INLINE_THUMB (0) +#endif + +/*****************************************************************************/ +/* Internal debugging stuff */ + +// Whether to collect memory allocation stats +#ifndef MICROPY_MEM_STATS +#define MICROPY_MEM_STATS (0) +#endif + +/*****************************************************************************/ +/* Fine control over Python features */ + +// Whether to include REPL helper function +#ifndef MICROPY_ENABLE_REPL_HELPERS +#define MICROPY_ENABLE_REPL_HELPERS (0) +#endif + +// Whether to support float and complex types +#ifndef MICROPY_ENABLE_FLOAT +#define MICROPY_ENABLE_FLOAT (0) +#endif + +// Whether to support slice object and correspondingly +// slice subscript operators +#ifndef MICROPY_ENABLE_SLICE +#define MICROPY_ENABLE_SLICE (1) +#endif + +/*****************************************************************************/ +/* Miscellaneous settings */ + // printf format spec to use for machine_int_t and friends +#ifndef INT_FMT #ifdef __LP64__ // Archs where machine_int_t == long, long != int #define UINT_FMT "%lu" @@ -16,18 +73,3 @@ #define INT_FMT "%d" #endif #endif //INT_FMT - - -// Any options not explicitly set in mpconfigport.h will get default -// values below. - -// Whether to collect memory allocation stats -#ifndef MICROPY_MEM_STATS -#define MICROPY_MEM_STATS (1) -#endif - -// Whether to support slice object and correspondingly -// slice subscript operators -#ifndef MICROPY_ENABLE_SLICE -#define MICROPY_ENABLE_SLICE (1) -#endif diff --git a/py/py.mk b/py/py.mk new file mode 100644 index 0000000000..e673c713c7 --- /dev/null +++ b/py/py.mk @@ -0,0 +1,100 @@ +# default settings; can be overriden in main Makefile + +ifndef PY_SRC +PY_SRC = ../py +endif + +ifndef BUILD +BUILD = build +endif + +# to create the build directory + +$(BUILD): + mkdir -p $@ + +# where py object files go (they have a name prefix to prevent filename clashes) + +PY_BUILD = $(BUILD)/py. + +# py object files + +PY_O_BASENAME = \ + nlrx86.o \ + nlrx64.o \ + nlrthumb.o \ + malloc.o \ + qstr.o \ + vstr.o \ + unicode.o \ + lexer.o \ + lexerunix.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 \ + map.o \ + obj.o \ + objbool.o \ + objboundmeth.o \ + objcell.o \ + objclass.o \ + objclosure.o \ + objcomplex.o \ + objdict.o \ + objexcept.o \ + objfloat.o \ + objfun.o \ + objgenerator.o \ + objinstance.o \ + objint.o \ + objlist.o \ + objmodule.o \ + objnone.o \ + objrange.o \ + objset.o \ + objslice.o \ + objstr.o \ + objtuple.o \ + objtype.o \ + builtin.o \ + builtinimport.o \ + vm.o \ + showbc.o \ + repl.o \ + +# prepend the build destination prefix to the py object files + +PY_O = $(addprefix $(PY_BUILD), $(PY_O_BASENAME)) + +$(PY_BUILD)emitnx64.o: $(PY_SRC)/emitnative.c $(PY_SRC)/emit.h mpconfigport.h + $(CC) $(CFLAGS) -DN_X64 -c -o $@ $< + +$(PY_BUILD)emitnthumb.o: $(PY_SRC)/emitnative.c $(PY_SRC)/emit.h mpconfigport.h + $(CC) $(CFLAGS) -DN_THUMB -c -o $@ $< + +$(PY_BUILD)%.o: $(PY_SRC)/%.S + $(CC) $(CFLAGS) -c -o $@ $< + +$(PY_BUILD)%.o: $(PY_SRC)/%.c mpconfigport.h + $(CC) $(CFLAGS) -c -o $@ $< + +# optimising vm for speed, adds only a small amount to code size but makes a huge difference to speed (20% faster) +$(PY_BUILD)vm.o: $(PY_SRC)/vm.c + $(CC) $(CFLAGS) -O3 -c -o $@ $< + +# header dependencies + +$(PY_BUILD)parse.o: $(PY_SRC)/grammar.h +$(PY_BUILD)compile.o: $(PY_SRC)/grammar.h +$(PY_BUILD)/emitcpy.o: $(PY_SRC)/emit.h +$(PY_BUILD)emitbc.o: $(PY_SRC)/emit.h diff --git a/py/repl.c b/py/repl.c index 4241ef0e4c..473313c1ef 100644 --- a/py/repl.c +++ b/py/repl.c @@ -1,6 +1,9 @@ #include "misc.h" +#include "mpconfig.h" #include "repl.h" +#if MICROPY_ENABLE_REPL_HELPERS + bool str_startswith_word(const char *str, const char *head) { int i; for (i = 0; str[i] && head[i]; i++) { @@ -42,3 +45,5 @@ bool mp_repl_is_compound_stmt(const char *line) { } return n_paren > 0 || n_brack > 0 || n_brace > 0; } + +#endif // MICROPY_ENABLE_REPL_HELPERS diff --git a/py/repl.h b/py/repl.h index 02fe523ed4..23259fa90d 100644 --- a/py/repl.h +++ b/py/repl.h @@ -1 +1,3 @@ +#if MICROPY_ENABLE_REPL_HELPERS bool mp_repl_is_compound_stmt(const char *line); +#endif diff --git a/stm/mpconfigport.h b/stm/mpconfigport.h index 4cea332f39..ee90db3218 100644 --- a/stm/mpconfigport.h +++ b/stm/mpconfigport.h @@ -2,11 +2,10 @@ // options to control how Micro Python is built -#define MICROPY_ENABLE_FLOAT (1) -#define MICROPY_EMIT_CPYTHON (0) -#define MICROPY_EMIT_X64 (0) #define MICROPY_EMIT_THUMB (1) #define MICROPY_EMIT_INLINE_THUMB (1) +#define MICROPY_ENABLE_REPL_HELPERS (1) +#define MICROPY_ENABLE_FLOAT (1) // type definitions for the specific machine diff --git a/unix-cpy/Makefile b/unix-cpy/Makefile index a1eb9b77e4..d2d698713e 100644 --- a/unix-cpy/Makefile +++ b/unix-cpy/Makefile @@ -1,95 +1,37 @@ -PYSRC=../py -BUILD=build +# define main target +PROG = cpy +all: $(PROG) +# include py core make definitions +include ../py/py.mk + +# program for deletion +RM = /bin/rm + +# compiler settings CC = gcc -CFLAGS = -I. -I$(PYSRC) -Wall -Werror -ansi -std=gnu99 -Os #-DNDEBUG +CFLAGS = -I. -I$(PY_SRC) -Wall -Werror -ansi -std=gnu99 -Os #-DNDEBUG LDFLAGS = -lm +# source files SRC_C = \ main.c \ -PY_O = \ - nlrx86.o \ - nlrx64.o \ - malloc.o \ - qstr.o \ - vstr.o \ - unicode.o \ - lexer.o \ - lexerunix.o \ - parse.o \ - scope.o \ - compile.o \ - emitcommon.o \ - emitpass1.o \ - emitcpy.o \ - runtime.o \ - map.o \ - obj.o \ - objbool.o \ - objboundmeth.o \ - objcell.o \ - objclass.o \ - objclosure.o \ - objcomplex.o \ - objdict.o \ - objexcept.o \ - objfloat.o \ - objfun.o \ - objgenerator.o \ - objinstance.o \ - objint.o \ - objlist.o \ - objmodule.o \ - objnone.o \ - objrange.o \ - objset.o \ - objslice.o \ - objstr.o \ - objtuple.o \ - objtype.o \ - builtin.o \ - builtinimport.o \ - vm.o \ - showbc.o \ - repl.o \ - -OBJ = $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(PY_O)) +OBJ = $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) $(PY_O) LIB = -PROG = cpy $(PROG): $(BUILD) $(OBJ) $(CC) -o $@ $(OBJ) $(LIB) $(LDFLAGS) - -$(BUILD): - mkdir -p $@ + strip $(PROG) + size $(PROG) $(BUILD)/%.o: %.c $(CC) $(CFLAGS) -c -o $@ $< -$(BUILD)/%.o: $(PYSRC)/%.S - $(CC) $(CFLAGS) -c -o $@ $< - -$(BUILD)/%.o: $(PYSRC)/%.c mpconfigport.h - $(CC) $(CFLAGS) -c -o $@ $< - -$(BUILD)/emitnx64.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h - $(CC) $(CFLAGS) -DN_X64 -c -o $@ $< - -$(BUILD)/emitnthumb.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h - $(CC) $(CFLAGS) -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) -O3 -c -o $@ $< - $(BUILD)/main.o: mpconfigport.h -$(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 -rf $(BUILD) + $(RM) -f $(PROG) + $(RM) -rf $(BUILD) -.PHONY: clean +.PHONY: all clean diff --git a/unix-cpy/main.c b/unix-cpy/main.c index eba97f527b..ea85e32757 100644 --- a/unix-cpy/main.c +++ b/unix-cpy/main.c @@ -11,7 +11,6 @@ #include "obj.h" #include "compile.h" #include "runtime0.h" -#include "runtime.h" void do_file(const char *file) { mp_lexer_t *lex = mp_lexer_new_from_file(file); diff --git a/unix-cpy/mpconfigport.h b/unix-cpy/mpconfigport.h index 983b166a55..9e3e32bb44 100644 --- a/unix-cpy/mpconfigport.h +++ b/unix-cpy/mpconfigport.h @@ -2,9 +2,6 @@ #define MICROPY_ENABLE_FLOAT (1) #define MICROPY_EMIT_CPYTHON (1) -#define MICROPY_EMIT_X64 (0) -#define MICROPY_EMIT_THUMB (0) -#define MICROPY_EMIT_INLINE_THUMB (0) // type definitions for the specific machine diff --git a/unix/Makefile b/unix/Makefile index 984f1c3bf3..a3faea290a 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -1,106 +1,39 @@ -PYSRC=../py -BUILD=build +# define main target +PROG = py +all: $(PROG) +# include py core make definitions +include ../py/py.mk + +# program for deletion +RM = /bin/rm + +# compiler settings CC = gcc -CFLAGS = -I. -I$(PYSRC) -Wall -Werror -ansi -std=gnu99 -Os #-DNDEBUG +CFLAGS = -I. -I$(PY_SRC) -Wall -Werror -ansi -std=gnu99 -Os #-DNDEBUG LDFLAGS = -lm +# source files SRC_C = \ main.c \ -PY_O = \ - nlrx86.o \ - nlrx64.o \ - nlrthumb.o \ - malloc.o \ - qstr.o \ - vstr.o \ - unicode.o \ - lexer.o \ - lexerunix.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 \ - map.o \ - obj.o \ - objbool.o \ - objboundmeth.o \ - objcell.o \ - objclass.o \ - objclosure.o \ - objcomplex.o \ - objdict.o \ - objexcept.o \ - objfloat.o \ - objfun.o \ - objgenerator.o \ - objinstance.o \ - objint.o \ - objlist.o \ - objmodule.o \ - objnone.o \ - objrange.o \ - objset.o \ - objslice.o \ - objstr.o \ - objtuple.o \ - objtype.o \ - builtin.o \ - builtinimport.o \ - vm.o \ - showbc.o \ - repl.o \ - -OBJ = $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(PY_O)) +OBJ = $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) $(PY_O) LIB = -lreadline # the following is needed for BSD #LIB += -ltermcap -PROG = py $(PROG): $(BUILD) $(OBJ) $(CC) -o $@ $(OBJ) $(LIB) $(LDFLAGS) strip $(PROG) size $(PROG) -$(BUILD): - mkdir -p $@ - $(BUILD)/%.o: %.c $(CC) $(CFLAGS) -c -o $@ $< -$(BUILD)/%.o: $(PYSRC)/%.S - $(CC) $(CFLAGS) -c -o $@ $< - -$(BUILD)/%.o: $(PYSRC)/%.c mpconfigport.h - $(CC) $(CFLAGS) -c -o $@ $< - -$(BUILD)/emitnx64.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h mpconfigport.h - $(CC) $(CFLAGS) -DN_X64 -c -o $@ $< - -$(BUILD)/emitnthumb.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h mpconfigport.h - $(CC) $(CFLAGS) -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) -O3 -c -o $@ $< - $(BUILD)/main.o: mpconfigport.h -$(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 -rf $(BUILD) + $(RM) -f $(PROG) + $(RM) -rf $(BUILD) -.PHONY: clean +.PHONY: all clean diff --git a/unix/main.c b/unix/main.c index a06dc36791..f7277b960c 100644 --- a/unix/main.c +++ b/unix/main.c @@ -20,6 +20,52 @@ #include #endif +static void execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, bool is_repl) { + 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); + return; + } + + mp_parse_node_t pn = mp_parse(lex, input_kind); + mp_lexer_free(lex); + + if (pn == MP_PARSE_NODE_NULL) { + // parse error + return; + } + + //printf("----------------\n"); + //parse_node_show(pn, 0); + //printf("----------------\n"); + + mp_obj_t module_fun = mp_compile(pn, is_repl); + + if (module_fun == mp_const_none) { + // compile error + return; + } + + // execute it + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + rt_call_function_0(module_fun); + nlr_pop(); + } else { + // uncaught exception + mp_obj_print((mp_obj_t)nlr.ret_val); + printf("\n"); + } +} + static char *str_join(const char *s1, int sep_char, const char *s2) { int l1 = strlen(s1); int l2 = strlen(s2); @@ -80,28 +126,11 @@ static void do_repl(void) { } mp_lexer_t *lex = mp_lexer_new_from_str_len("", line, strlen(line), false); - mp_parse_node_t pn = mp_parse(lex, MP_PARSE_SINGLE_INPUT); - mp_lexer_free(lex); - - if (pn != MP_PARSE_NODE_NULL) { - //mp_parse_node_show(pn, 0); - mp_obj_t module_fun = mp_compile(pn, true); - if (module_fun != mp_const_none) { - nlr_buf_t nlr; - if (nlr_push(&nlr) == 0) { - rt_call_function_0(module_fun); - nlr_pop(); - } else { - // uncaught exception - mp_obj_print((mp_obj_t)nlr.ret_val); - printf("\n"); - } - } - } + execute_from_lexer(lex, MP_PARSE_SINGLE_INPUT, true); } } -void do_file(const char *file) { +static void do_file(const char *file) { // hack: set dir for import based on where this file is { const char * s = strrchr(file, '/'); @@ -115,53 +144,12 @@ void do_file(const char *file) { } mp_lexer_t *lex = mp_lexer_new_from_file(file); - //const char *pysrc = "def f():\n x=x+1\n print(42)\n"; - //mp_lexer_t *lex = mp_lexer_from_str_len("<>", pysrc, strlen(pysrc), false); - if (lex == NULL) { - return; - } + execute_from_lexer(lex, MP_PARSE_FILE_INPUT, false); +} - 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"); - mp_obj_t module_fun = mp_compile(pn, false); - //printf("----------------\n"); - -#if MICROPY_EMIT_CPYTHON - if (!comp_ok) { - printf("compile error\n"); - } -#else - if (1 && module_fun != mp_const_none) { - // execute it - nlr_buf_t nlr; - if (nlr_push(&nlr) == 0) { - rt_call_function_0(module_fun); - nlr_pop(); - } else { - // uncaught exception - mp_obj_print((mp_obj_t)nlr.ret_val); - printf("\n"); - } - } -#endif - } - } +static void do_str(const char *str) { + mp_lexer_t *lex = mp_lexer_new_from_str_len("", str, strlen(str), false); + execute_from_lexer(lex, MP_PARSE_SINGLE_INPUT, false); } typedef struct _test_obj_t { @@ -192,12 +180,6 @@ static const mp_obj_type_t test_type = { { &mp_const_type }, "Test", .print = test_print, - .make_new = NULL, - .call_n = NULL, - .unary_op = NULL, - .binary_op = NULL, - .getiter = NULL, - .iternext = NULL, .methods = { { "get", &test_get_obj }, { "set", &test_set_obj }, @@ -212,6 +194,11 @@ mp_obj_t test_obj_new(int value) { return o; } +int usage(void) { + printf("usage: py [-c ] []\n"); + return 1; +} + int main(int argc, char **argv) { qstr_init(); rt_init(); @@ -227,12 +214,24 @@ int main(int argc, char **argv) { if (argc == 1) { do_repl(); - } else if (argc == 2) { - do_file(argv[1]); } else { - printf("usage: py []\n"); - return 1; + for (int a = 1; a < argc; a++) { + if (argv[a][0] == '-') { + if (strcmp(argv[a], "-c") == 0) { + if (a + 1 >= argc) { + return usage(); + } + do_str(argv[a + 1]); + a += 1; + } else { + return usage(); + } + } else { + do_file(argv[a]); + } + } } + rt_deinit(); //printf("total bytes = %d\n", m_get_total_bytes_allocated()); diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index 7a4622b8b6..b7901069ac 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -5,11 +5,12 @@ #define MICROPY_USE_READLINE (1) #endif -#define MICROPY_ENABLE_FLOAT (1) -#define MICROPY_EMIT_CPYTHON (0) #define MICROPY_EMIT_X64 (1) #define MICROPY_EMIT_THUMB (0) #define MICROPY_EMIT_INLINE_THUMB (0) +#define MICROPY_MEM_STATS (1) +#define MICROPY_ENABLE_REPL_HELPERS (1) +#define MICROPY_ENABLE_FLOAT (1) // type definitions for the specific machine From d3ebe4829d920542e5af462e75179e4f0cadb946 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 7 Jan 2014 15:20:33 +0000 Subject: [PATCH 12/17] Factor and simplify Makefile's and mpconfig, part 2. --- py/asmx64.c | 8 ++-- py/gc.c | 4 ++ py/lexerunix.c | 5 +++ py/mpconfig.h | 15 +++++++ py/py.mk | 5 +++ py/showbc.c | 4 ++ stm/Makefile | 95 ++++++----------------------------------- stm/mpconfigport.h | 1 + unix-cpy/mpconfigport.h | 3 +- unix/mpconfigport.h | 1 + 10 files changed, 56 insertions(+), 85 deletions(-) diff --git a/py/asmx64.c b/py/asmx64.c index 226d4efee8..d3158170fb 100644 --- a/py/asmx64.c +++ b/py/asmx64.c @@ -1,16 +1,18 @@ #include #include -#include -#include #include #include "misc.h" -#include "asmx64.h" #include "mpconfig.h" // wrapper around everything in this file #if MICROPY_EMIT_X64 +#include +#include + +#include "asmx64.h" + #if defined(__OpenBSD__) || defined(__MACH__) #define MAP_ANONYMOUS MAP_ANON #endif diff --git a/py/gc.c b/py/gc.c index 7d4cac6e74..054a3cc315 100644 --- a/py/gc.c +++ b/py/gc.c @@ -6,6 +6,8 @@ #include "mpconfig.h" #include "gc.h" +#if MICROPY_ENABLE_GC + // a machine word is big enough to hold a pointer /* #define BYTES_PER_WORD (8) @@ -380,3 +382,5 @@ int main(void) { gc_dump_at(); } */ + +#endif // MICROPY_ENABLE_GC diff --git a/py/lexerunix.c b/py/lexerunix.c index 14c28c16d9..5336610bae 100644 --- a/py/lexerunix.c +++ b/py/lexerunix.c @@ -4,8 +4,11 @@ #include #include "misc.h" +#include "mpconfig.h" #include "lexer.h" +#if MICROPY_ENABLE_LEXER_UNIX + typedef struct _str_buf_t { bool free; // free src_beg when done const char *src_beg; // beginning of source @@ -78,3 +81,5 @@ mp_lexer_t *mp_import_open_file(qstr mod_name) { vstr_printf(vstr, "%s.py", qstr_str(mod_name)); return mp_lexer_new_from_file(vstr_str(vstr)); // TODO does lexer need to copy the string? can we free it here? } + +#endif // MICROPY_ENABLE_LEXER_UNIX diff --git a/py/mpconfig.h b/py/mpconfig.h index 8ce432a61e..2017ba366a 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -39,14 +39,29 @@ #define MICROPY_MEM_STATS (0) #endif +// Whether to build code to show byte code +#ifndef MICROPY_SHOW_BC +#define MICROPY_SHOW_BC (0) +#endif + /*****************************************************************************/ /* Fine control over Python features */ +// Whether to include the garbage collector +#ifndef MICROPY_ENABLE_GC +#define MICROPY_ENABLE_GC (0) +#endif + // Whether to include REPL helper function #ifndef MICROPY_ENABLE_REPL_HELPERS #define MICROPY_ENABLE_REPL_HELPERS (0) #endif +// Whether to include lexer helper function for unix +#ifndef MICROPY_ENABLE_LEXER_UNIX +#define MICROPY_ENABLE_LEXER_UNIX (0) +#endif + // Whether to support float and complex types #ifndef MICROPY_ENABLE_FLOAT #define MICROPY_ENABLE_FLOAT (0) diff --git a/py/py.mk b/py/py.mk index e673c713c7..3ed8a3e3d7 100644 --- a/py/py.mk +++ b/py/py.mk @@ -24,6 +24,7 @@ PY_O_BASENAME = \ nlrx64.o \ nlrthumb.o \ malloc.o \ + gc.o \ qstr.o \ vstr.o \ unicode.o \ @@ -88,6 +89,10 @@ $(PY_BUILD)%.o: $(PY_SRC)/%.S $(PY_BUILD)%.o: $(PY_SRC)/%.c mpconfigport.h $(CC) $(CFLAGS) -c -o $@ $< +# optimising gc for speed; 5ms down to 4ms on pybv2 +$(PY_BUILD)gc.o: $(PY_SRC)/gc.c + $(CC) $(CFLAGS) -O3 -c -o $@ $< + # optimising vm for speed, adds only a small amount to code size but makes a huge difference to speed (20% faster) $(PY_BUILD)vm.o: $(PY_SRC)/vm.c $(CC) $(CFLAGS) -O3 -c -o $@ $< diff --git a/py/showbc.c b/py/showbc.c index eb7d41b24d..aea0aff67a 100644 --- a/py/showbc.c +++ b/py/showbc.c @@ -8,6 +8,8 @@ #include "mpconfig.h" #include "bc0.h" +#if MICROPY_SHOW_BC + #define DECODE_UINT do { unum = *ip++; if (unum > 127) { unum = ((unum & 0x3f) << 8) | (*ip++); } } while (0) #define DECODE_ULABEL do { unum = (ip[0] | (ip[1] << 8)); ip += 2; } while (0) #define DECODE_SLABEL do { unum = (ip[0] | (ip[1] << 8)) - 0x8000; ip += 2; } while (0) @@ -363,3 +365,5 @@ void mp_show_byte_code(const byte *ip, int len) { printf("\n"); } } + +#endif // MICROPY_SHOW_BC diff --git a/stm/Makefile b/stm/Makefile index cd998dd882..fecd525276 100644 --- a/stm/Makefile +++ b/stm/Makefile @@ -1,9 +1,16 @@ +# define main target +all: all2 + +# include py core make definitions +include ../py/py.mk + +# program for deletion +RM = /bin/rm + STMSRC=lib #STMOTGSRC=lib-otg FATFSSRC=fatfs CC3KSRC=cc3k -PYSRC=../py -BUILD=build DFU=../tools/dfu.py TARGET=PYBOARD @@ -11,7 +18,7 @@ AS = arm-none-eabi-as CC = arm-none-eabi-gcc LD = arm-none-eabi-ld CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion -DSTM32F40XX -DHSE_VALUE=8000000 -CFLAGS = -I. -I$(PYSRC) -I$(FATFSSRC) -I$(STMSRC) -Wall -ansi -std=gnu99 -Os -DNDEBUG $(CFLAGS_CORTEX_M4) -D$(TARGET) +CFLAGS = -I. -I$(PY_SRC) -I$(FATFSSRC) -I$(STMSRC) -Wall -ansi -std=gnu99 -Os -DNDEBUG $(CFLAGS_CORTEX_M4) -D$(TARGET) #CFLAGS += -I$(STMOTGSRC) -DUSE_HOST_MODE -DUSE_OTG_MODE LDFLAGS = --nostdlib -T stm32f405.ld @@ -43,53 +50,6 @@ SRC_S = \ startup_stm32f40xx.s \ gchelper.s \ -PY_O = \ - nlrthumb.o \ - gc.o \ - malloc.o \ - qstr.o \ - vstr.o \ - unicode.o \ - lexer.o \ - parse.o \ - scope.o \ - compile.o \ - emitcommon.o \ - emitpass1.o \ - emitbc.o \ - asmthumb.o \ - emitnthumb.o \ - emitinlinethumb.o \ - runtime.o \ - map.o \ - obj.o \ - objbool.o \ - objboundmeth.o \ - objcell.o \ - objclass.o \ - objclosure.o \ - objcomplex.o \ - objdict.o \ - objexcept.o \ - objfloat.o \ - objfun.o \ - objgenerator.o \ - objinstance.o \ - objint.o \ - objlist.o \ - objmodule.o \ - objnone.o \ - objrange.o \ - objset.o \ - objslice.o \ - objstr.o \ - objtuple.o \ - objtype.o \ - builtin.o \ - builtinimport.o \ - vm.o \ - repl.o \ - SRC_FATFS = \ ff.c \ diskio.c \ @@ -146,10 +106,10 @@ SRC_CC3K = \ ccspi.c \ pybcc3k.c \ -OBJ = $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o) $(PY_O) $(SRC_FATFS:.c=.o) $(SRC_STM:.c=.o) $(SRC_CC3K:.c=.o)) +OBJ = $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o) $(SRC_FATFS:.c=.o) $(SRC_STM:.c=.o) $(SRC_CC3K:.c=.o)) $(PY_O) #OBJ += $(addprefix $(BUILD)/, $(SRC_STM_OTG:.c=.o)) -all: $(BUILD) $(BUILD)/flash.dfu +all2: $(BUILD) $(BUILD)/flash.dfu $(BUILD)/flash.dfu: $(BUILD)/flash0.bin $(BUILD)/flash1.bin python $(DFU) -b 0x08000000:$(BUILD)/flash0.bin -b 0x08020000:$(BUILD)/flash1.bin $@ @@ -164,9 +124,6 @@ $(BUILD)/flash.elf: $(OBJ) $(LD) $(LDFLAGS) -o $@ $(OBJ) arm-none-eabi-size $@ -$(BUILD): - mkdir -p $@ - $(BUILD)/%.o: %.s $(AS) -o $@ $< @@ -185,31 +142,7 @@ $(BUILD)/%.o: $(STMSRC)/%.c $(BUILD)/%.o: $(CC3KSRC)/%.c $(CC) $(CFLAGS) -c -o $@ $< -$(BUILD)/%.o: $(PYSRC)/%.s - $(AS) -o $@ $< - -$(BUILD)/%.o: $(PYSRC)/%.S - $(CC) $(CFLAGS) -c -o $@ $< - -$(BUILD)/%.o: $(PYSRC)/%.c mpconfigport.h - $(CC) $(CFLAGS) -c -o $@ $< - -$(BUILD)/emitnthumb.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h - $(CC) $(CFLAGS) -DN_THUMB -c -o $@ $< - -# optimising gc for speed; 5ms down to 4ms -$(BUILD)/gc.o: $(PYSRC)/gc.c - $(CC) $(CFLAGS) -O3 -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) -O3 -c -o $@ $< - -$(BUILD)/parse.o: $(PYSRC)/grammar.h -$(BUILD)/compile.o: $(PYSRC)/grammar.h -$(BUILD)/emitbc.o: $(PYSRC)/emit.h - clean: - /bin/rm -rf $(BUILD) + $(RM) -rf $(BUILD) -.PHONY: all clean +.PHONY: all all2 clean diff --git a/stm/mpconfigport.h b/stm/mpconfigport.h index ee90db3218..dfa46cc504 100644 --- a/stm/mpconfigport.h +++ b/stm/mpconfigport.h @@ -4,6 +4,7 @@ #define MICROPY_EMIT_THUMB (1) #define MICROPY_EMIT_INLINE_THUMB (1) +#define MICROPY_ENABLE_GC (1) #define MICROPY_ENABLE_REPL_HELPERS (1) #define MICROPY_ENABLE_FLOAT (1) diff --git a/unix-cpy/mpconfigport.h b/unix-cpy/mpconfigport.h index 9e3e32bb44..3fc1866772 100644 --- a/unix-cpy/mpconfigport.h +++ b/unix-cpy/mpconfigport.h @@ -1,7 +1,8 @@ // options to control how Micro Python is built -#define MICROPY_ENABLE_FLOAT (1) #define MICROPY_EMIT_CPYTHON (1) +#define MICROPY_ENABLE_LEXER_UNIX (1) +#define MICROPY_ENABLE_FLOAT (1) // type definitions for the specific machine diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index b7901069ac..8327641213 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -10,6 +10,7 @@ #define MICROPY_EMIT_INLINE_THUMB (0) #define MICROPY_MEM_STATS (1) #define MICROPY_ENABLE_REPL_HELPERS (1) +#define MICROPY_ENABLE_LEXER_UNIX (1) #define MICROPY_ENABLE_FLOAT (1) // type definitions for the specific machine From 7b21c2d8f01b33b35463cb22487b1235aa7446a4 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 7 Jan 2014 16:54:58 +0000 Subject: [PATCH 13/17] py: Fix allocation of unique code blocks. --- py/objmodule.c | 4 +++- py/runtime.c | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/py/objmodule.c b/py/objmodule.c index 3e7a0f7fc4..7b92b76f42 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -6,6 +6,7 @@ #include "nlr.h" #include "misc.h" #include "mpconfig.h" +#include "mpqstr.h" #include "obj.h" #include "runtime.h" #include "map.h" @@ -31,7 +32,8 @@ mp_obj_t mp_obj_new_module(qstr module_name) { mp_obj_module_t *o = m_new_obj(mp_obj_module_t); o->base.type = &module_type; o->name = module_name; - o->globals = mp_map_new(MP_MAP_QSTR, 0); + o->globals = mp_map_new(MP_MAP_QSTR, 1); + mp_qstr_map_lookup(o->globals, MP_QSTR___name__, true)->value = mp_obj_new_str(module_name); return o; } diff --git a/py/runtime.c b/py/runtime.c index 0457f0df41..a5dafb190d 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -61,7 +61,8 @@ typedef struct _mp_code_t { } mp_code_t; static int next_unique_code_id; -static mp_code_t *unique_codes; +static machine_uint_t unique_codes_alloc = 0; +static mp_code_t *unique_codes = NULL; #ifdef WRITE_CODE FILE *fp_write_code = NULL; @@ -126,6 +127,7 @@ void rt_init(void) { mp_qstr_map_lookup(&map_builtins, MP_QSTR_sum, true)->value = rt_make_function_var(1, mp_builtin_sum); next_unique_code_id = 1; // 0 indicates "no code" + unique_codes_alloc = 0; unique_codes = NULL; #ifdef WRITE_CODE @@ -134,6 +136,7 @@ void rt_init(void) { } void rt_deinit(void) { + m_del(mp_code_t, unique_codes, unique_codes_alloc); #ifdef WRITE_CODE if (fp_write_code != NULL) { fclose(fp_write_code); @@ -146,18 +149,20 @@ int rt_get_unique_code_id(void) { } static void alloc_unique_codes(void) { - if (unique_codes == NULL) { - unique_codes = m_new(mp_code_t, next_unique_code_id + 10); // XXX hack until we fix the REPL allocation problem - for (int i = 0; i < next_unique_code_id; i++) { + if (next_unique_code_id > unique_codes_alloc) { + // increase size of unique_codes table + unique_codes = m_renew(mp_code_t, unique_codes, unique_codes_alloc, next_unique_code_id); + for (int i = unique_codes_alloc; i < next_unique_code_id; i++) { unique_codes[i].kind = MP_CODE_NONE; } + unique_codes_alloc = next_unique_code_id; } } void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, int n_locals, int n_stack, bool is_generator) { alloc_unique_codes(); - assert(1 <= unique_code_id && unique_code_id < next_unique_code_id); + assert(1 <= unique_code_id && unique_code_id < next_unique_code_id && unique_codes[unique_code_id].kind == MP_CODE_NONE); unique_codes[unique_code_id].kind = MP_CODE_BYTE; unique_codes[unique_code_id].n_args = n_args; unique_codes[unique_code_id].n_locals = n_locals; @@ -192,7 +197,7 @@ void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, i void rt_assign_native_code(int unique_code_id, void *fun, uint len, int n_args) { alloc_unique_codes(); - assert(1 <= unique_code_id && unique_code_id < next_unique_code_id); + assert(1 <= unique_code_id && unique_code_id < next_unique_code_id && unique_codes[unique_code_id].kind == MP_CODE_NONE); unique_codes[unique_code_id].kind = MP_CODE_NATIVE; unique_codes[unique_code_id].n_args = n_args; unique_codes[unique_code_id].n_locals = 0; @@ -225,7 +230,7 @@ void rt_assign_native_code(int unique_code_id, void *fun, uint len, int n_args) void rt_assign_inline_asm_code(int unique_code_id, void *fun, uint len, int n_args) { alloc_unique_codes(); - assert(1 <= unique_code_id && unique_code_id < next_unique_code_id); + assert(1 <= unique_code_id && unique_code_id < next_unique_code_id && unique_codes[unique_code_id].kind == MP_CODE_NONE); unique_codes[unique_code_id].kind = MP_CODE_INLINE_ASM; unique_codes[unique_code_id].n_args = n_args; unique_codes[unique_code_id].n_locals = 0; From fd04bb3bacf5dbc4d79c04a49520e3e81abb7352 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 7 Jan 2014 17:14:05 +0000 Subject: [PATCH 14/17] Add some example scripts for pyboard (some can run on PC). --- examples/accellog.py | 14 ++++++++++++++ examples/conwaylife.py | 43 ++++++++++++++++++++++++++++++++++++++++++ examples/lcd.py | 36 +++++++++++++++++++++++++++++++++++ examples/ledangle.py | 22 +++++++++++++++++++++ examples/mandel.py | 32 +++++++++++++++++++------------ examples/pyb.py | 11 +++++++++++ 6 files changed, 146 insertions(+), 12 deletions(-) create mode 100644 examples/accellog.py create mode 100644 examples/conwaylife.py create mode 100644 examples/lcd.py create mode 100644 examples/ledangle.py create mode 100644 examples/pyb.py diff --git a/examples/accellog.py b/examples/accellog.py new file mode 100644 index 0000000000..81f44f19a8 --- /dev/null +++ b/examples/accellog.py @@ -0,0 +1,14 @@ +# log the accelerometer values to a file, 1 per second + +f = open('motion.dat', 'w') # open the file for writing + +for i in range(60): # loop 60 times + time = pyb.time() # get the current time + accel = pyb.accel() # get the accelerometer data + + # write time and x,y,z values to the file + f.write('{} {} {} {}\n'.format(time, accel[0], accel[1], accel[2])) + + pyb.delay(1000) # wait 1000 ms = 1 second + +f.close() # close the file diff --git a/examples/conwaylife.py b/examples/conwaylife.py new file mode 100644 index 0000000000..fb62ce69e8 --- /dev/null +++ b/examples/conwaylife.py @@ -0,0 +1,43 @@ +# do 1 iteration of Conway's Game of Life +def conway_step(): + for x in range(128): # loop over x coordinates + for y in range(32): # loop over y coordinates + # count number of neigbours + num_neighbours = (lcd.get(x - 1, y - 1) + + lcd.get(x, y - 1) + + lcd.get(x + 1, y - 1) + + lcd.get(x - 1, y) + + lcd.get(x + 1, y) + + lcd.get(x + 1, y + 1) + + lcd.get(x, y + 1) + + lcd.get(x - 1, y + 1)) + + # check if the centre cell is alive or not + self = lcd.get(x, y) + + # apply the rules of life + if self and not (2 <= num_neighbours <= 3): + lcd.reset(x, y) # not enough, or too many neighbours: cell dies + elif not self and num_neighbours == 3: + lcd.set(x, y) # exactly 3 neigbours around an empty cell: cell is born + +# randomise the start +def conway_rand(): + lcd.clear() # clear the LCD + for x in range(128): # loop over x coordinates + for y in range(32): # loop over y coordinates + if pyb.rand() & 1: # get a 1-bit random number + lcd.set(x, y) # set the pixel randomly + +# loop for a certain number of frames, doing iterations of Conway's Game of Life +def conway_go(num_frames): + for i in range(num_frames): + conway_step() # do 1 iteration + lcd.show() # update the LCD + +# PC testing +import lcd +import pyb +lcd = lcd.LCD(128, 32) +conway_rand() +conway_go(100) diff --git a/examples/lcd.py b/examples/lcd.py new file mode 100644 index 0000000000..3303337bfb --- /dev/null +++ b/examples/lcd.py @@ -0,0 +1,36 @@ +# LCD testing object for PC +# uses double buffering +class LCD: + def __init__(self, width, height): + self.width = width + self.height = height + self.buf1 = [[0 for x in range(self.width)] for y in range(self.height)] + self.buf2 = [[0 for x in range(self.width)] for y in range(self.height)] + + def clear(self): + for y in range(self.height): + for x in range(self.width): + self.buf1[y][x] = self.buf2[y][x] = 0 + + def show(self): + print('') # blank line to separate frames + for y in range(self.height): + for x in range(self.width): + self.buf1[y][x] = self.buf2[y][x] + for y in range(self.height): + row = ''.join(['*' if self.buf1[y][x] else ' ' for x in range(self.width)]) + print(row) + + def get(self, x, y): + if 0 <= x < self.width and 0 <= y < self.height: + return self.buf1[y][x] + else: + return 0 + + def reset(self, x, y): + if 0 <= x < self.width and 0 <= y < self.height: + self.buf2[y][x] = 0 + + def set(self, x, y): + if 0 <= x < self.width and 0 <= y < self.height: + self.buf2[y][x] = 1 diff --git a/examples/ledangle.py b/examples/ledangle.py new file mode 100644 index 0000000000..35c9148a49 --- /dev/null +++ b/examples/ledangle.py @@ -0,0 +1,22 @@ +def led_angle(seconds_to_run_for): + # make LED objects + l1 = pyb.Led(1) + l2 = pyb.Led(2) + + for i in range(20 * seconds_to_run_for): + # get x-axis + accel = pyb.accel()[0] + + # turn on LEDs depending on angle + if accel < -10: + l1.on() + l2.off() + elif accel > 10: + l1.off() + l2.on() + else: + l1.off() + l2.off() + + # delay so that loop runs at at 1/50ms = 20Hz + pyb.delay(50) diff --git a/examples/mandel.py b/examples/mandel.py index b13b7d87f8..996132a915 100644 --- a/examples/mandel.py +++ b/examples/mandel.py @@ -1,14 +1,22 @@ -@micropython.native -def in_set(c): - z = 0 - for i in range(40): - z = z*z + c - if abs(z) > 60: - return False - return True +def mandelbrot(): + # returns True if c, complex, is in the Mandelbrot set + @micropython.native + def in_set(c): + z = 0 + for i in range(40): + z = z*z + c + if abs(z) > 60: + return False + return True -for v in range(31): - line = [] + lcd.clear() for u in range(91): - line.append('*' if in_set((u / 30 - 2) + (v / 15 - 1) * 1j) else ' ') - print(''.join(line)) + for v in range(31): + if in_set((u / 30 - 2) + (v / 15 - 1) * 1j): + lcd.set(u, v) + lcd.show() + +# PC testing +import lcd +lcd = lcd.LCD(128, 32) +mandelbrot() diff --git a/examples/pyb.py b/examples/pyb.py new file mode 100644 index 0000000000..5e24f40e4a --- /dev/null +++ b/examples/pyb.py @@ -0,0 +1,11 @@ +# pyboard testing functions for PC + +def delay(n): + pass + +rand_seed = 1 +def rand(): + global rand_seed + # for these choice of numbers, see P L'Ecuyer, "Tables of linear congruential generators of different sizes and good lattice structure" + rand_seed = (rand_seed * 653276) % 8388593 + return rand_seed From c06763a0207dde7f2060f7b1670a0b99298a01f8 Mon Sep 17 00:00:00 2001 From: "John R. Lenton" Date: Tue, 7 Jan 2014 17:29:16 +0000 Subject: [PATCH 15/17] This implements a better (more python-conformant) list.sort. It's not really about that, though; it's about me figuring out a sane way forward for keyword-argument functions (and function metadata). But it's useful as is, and shouldn't break any existing code, so here you have it; I'm going to park it in my mind for a bit while sorting out the rest of the dict branch. --- py/obj.h | 30 +++++++++-------- py/objbool.c | 13 +++----- py/objboundmeth.c | 12 ++----- py/objcell.c | 11 ++---- py/objclass.c | 12 ++----- py/objclosure.c | 12 ++----- py/objcomplex.c | 15 ++++----- py/objdict.c | 5 ++- py/objexcept.c | 12 ++----- py/objfloat.c | 4 +-- py/objfun.c | 59 ++++++++++++++++++--------------- py/objgenerator.c | 28 ++++++---------- py/objinstance.c | 11 ++---- py/objint.c | 4 +-- py/objlist.c | 45 +++++++++++++++++-------- py/objmodule.c | 12 ++----- py/objnone.c | 4 +-- py/objrange.c | 24 ++++---------- py/objset.c | 13 +++----- py/objslice.c | 16 +++------ py/objstr.c | 8 ++--- py/objtuple.c | 12 +++---- py/objtype.c | 4 +-- py/runtime.c | 18 +++++++--- tests/basics/tests/list_sort.py | 13 ++++++++ 25 files changed, 181 insertions(+), 216 deletions(-) create mode 100644 tests/basics/tests/list_sort.py diff --git a/py/obj.h b/py/obj.h index 1ba7427cbb..e4e64fca71 100644 --- a/py/obj.h +++ b/py/obj.h @@ -43,12 +43,16 @@ struct _mp_obj_base_t { #define MP_DECLARE_CONST_FUN_OBJ(obj_name) extern const mp_obj_fun_native_t obj_name -#define MP_DEFINE_CONST_FUN_OBJ_0(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, 0, 0, fun_name} -#define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, 1, 1, fun_name} -#define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, 2, 2, fun_name} -#define MP_DEFINE_CONST_FUN_OBJ_3(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, 3, 3, fun_name} -#define MP_DEFINE_CONST_FUN_OBJ_VAR(obj_name, n_args_min, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, n_args_min, (~((machine_uint_t)0)), fun_name} -#define MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name, n_args_min, n_args_max, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, n_args_min, n_args_max, fun_name} +#define MP_DEFINE_CONST_FUN_OBJ_0(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, false, 0, 0, fun_name} +#define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, false, 1, 1, fun_name} +#define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, false, 2, 2, fun_name} +#define MP_DEFINE_CONST_FUN_OBJ_3(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, false, 3, 3, fun_name} +#define MP_DEFINE_CONST_FUN_OBJ_VAR(obj_name, n_args_min, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, false, n_args_min, (~((machine_uint_t)0)), fun_name} +#define MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name, n_args_min, n_args_max, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, false, n_args_min, n_args_max, fun_name} +#define MP_DEFINE_CONST_FUN_OBJ_KW(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, true, 0, (~((machine_uint_t)0)), fun_name} + +// Need to declare this here so we are not dependent on map.h +struct _mp_map_t; // Type definitions for methods @@ -58,10 +62,12 @@ typedef mp_obj_t (*mp_fun_2_t)(mp_obj_t, mp_obj_t); typedef mp_obj_t (*mp_fun_3_t)(mp_obj_t, mp_obj_t, mp_obj_t); typedef mp_obj_t (*mp_fun_t)(void); typedef mp_obj_t (*mp_fun_var_t)(int n, const mp_obj_t *); +typedef mp_obj_t (*mp_fun_kw_t)(mp_obj_t*, struct _mp_map_t*); typedef void (*mp_print_fun_t)(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o); typedef mp_obj_t (*mp_make_new_fun_t)(mp_obj_t type_in, int n_args, const mp_obj_t *args); // args are in reverse order in the array typedef mp_obj_t (*mp_call_n_fun_t)(mp_obj_t fun, int n_args, const mp_obj_t *args); // args are in reverse order in the array +typedef mp_obj_t (*mp_call_n_kw_fun_t)(mp_obj_t fun, int n_args, int n_kw, const mp_obj_t *args); // args are in reverse order in the array typedef mp_obj_t (*mp_unary_op_fun_t)(int op, mp_obj_t); typedef mp_obj_t (*mp_binary_op_fun_t)(int op, mp_obj_t, mp_obj_t); @@ -77,6 +83,7 @@ struct _mp_obj_type_t { mp_make_new_fun_t make_new; // to make an instance of the type mp_call_n_fun_t call_n; + mp_call_n_kw_fun_t call_n_kw; mp_unary_op_fun_t unary_op; // can return NULL if op not supported mp_binary_op_fun_t binary_op; // can return NULL if op not supported @@ -118,10 +125,6 @@ extern const mp_obj_t mp_const_empty_tuple; extern const mp_obj_t mp_const_ellipsis; extern const mp_obj_t mp_const_stop_iteration; // special object indicating end of iteration (not StopIteration exception!) -// Need to declare this here so we are not dependent on map.h - -struct _mp_map_t; - // General API for objects mp_obj_t mp_obj_new_none(void); @@ -144,8 +147,8 @@ mp_obj_t mp_obj_new_fun_asm(uint n_args, void *fun); mp_obj_t mp_obj_new_gen_wrap(uint n_locals, uint n_stack, mp_obj_t fun); mp_obj_t mp_obj_new_gen_instance(const byte *bytecode, uint n_state, int n_args, const mp_obj_t *args); mp_obj_t mp_obj_new_closure(mp_obj_t fun, mp_obj_t closure_tuple); -mp_obj_t mp_obj_new_tuple(uint n, mp_obj_t *items); -mp_obj_t mp_obj_new_tuple_reverse(uint n, mp_obj_t *items); +mp_obj_t mp_obj_new_tuple(uint n, const mp_obj_t *items); +mp_obj_t mp_obj_new_tuple_reverse(uint n, const mp_obj_t *items); mp_obj_t mp_obj_new_list(uint n, mp_obj_t *items); mp_obj_t mp_obj_new_list_reverse(uint n, mp_obj_t *items); mp_obj_t mp_obj_new_dict(int n_args); @@ -234,7 +237,8 @@ void mp_obj_slice_get(mp_obj_t self_in, machine_int_t *start, machine_int_t *sto // functions typedef struct _mp_obj_fun_native_t { // need this so we can define const objects (to go in ROM) mp_obj_base_t base; - machine_uint_t n_args_min; // inclusive + bool is_kw : 1; + machine_uint_t n_args_min : (sizeof(machine_uint_t) - 1); // inclusive machine_uint_t n_args_max; // inclusive void *fun; // TODO add mp_map_t *globals diff --git a/py/objbool.c b/py/objbool.c index 77394dab99..3fd35a05f3 100644 --- a/py/objbool.c +++ b/py/objbool.c @@ -32,15 +32,10 @@ static mp_obj_t bool_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args } const mp_obj_type_t bool_type = { - { &mp_const_type }, - "bool", - bool_print, // print - bool_make_new, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext + .base = { &mp_const_type }, + .name = "bool", + .print = bool_print, + .make_new = bool_make_new, .methods = {{NULL, NULL},}, }; diff --git a/py/objboundmeth.c b/py/objboundmeth.c index 4e6d2e0103..414fdfbf0a 100644 --- a/py/objboundmeth.c +++ b/py/objboundmeth.c @@ -34,15 +34,9 @@ mp_obj_t bound_meth_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) { } const mp_obj_type_t bound_meth_type = { - { &mp_const_type }, - "bound_method", - NULL, // print - NULL, // make_new - bound_meth_call_n, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext + .base = { &mp_const_type }, + .name = "bound_method", + .call_n = bound_meth_call_n, .methods = {{NULL, NULL},}, }; diff --git a/py/objcell.c b/py/objcell.c index 3465f99198..bedaf3d87f 100644 --- a/py/objcell.c +++ b/py/objcell.c @@ -24,15 +24,8 @@ void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj) { } const mp_obj_type_t cell_type = { - { &mp_const_type }, - "cell", - NULL, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext + .base = { &mp_const_type }, + .name = "cell", .methods = {{NULL, NULL},}, }; diff --git a/py/objclass.c b/py/objclass.c index 536abdf7e3..441c8e77c3 100644 --- a/py/objclass.c +++ b/py/objclass.c @@ -61,15 +61,9 @@ mp_map_t *mp_obj_class_get_locals(mp_obj_t self_in) { } const mp_obj_type_t class_type = { - { &mp_const_type }, - "class", - NULL, // print - NULL, // make_new - class_call_n, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext + .base = { &mp_const_type }, + .name = "class", + .call_n = class_call_n, .methods = {{NULL, NULL},}, }; diff --git a/py/objclosure.c b/py/objclosure.c index 3317eb86f4..7f9bcfafdd 100644 --- a/py/objclosure.c +++ b/py/objclosure.c @@ -33,15 +33,9 @@ mp_obj_t closure_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) { } const mp_obj_type_t closure_type = { - { &mp_const_type }, - "closure", - NULL, // print - NULL, // make_new - closure_call_n, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext + .base = { &mp_const_type }, + .name = "closure", + .call_n = closure_call_n, .methods = {{NULL, NULL},}, }; diff --git a/py/objcomplex.c b/py/objcomplex.c index 46f43b54b5..dc3439143a 100644 --- a/py/objcomplex.c +++ b/py/objcomplex.c @@ -85,15 +85,12 @@ static mp_obj_t complex_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { } const mp_obj_type_t complex_type = { - { &mp_const_type }, - "complex", - complex_print, // print - complex_make_new, // make_new - NULL, // call_n - complex_unary_op, // unary_op - complex_binary_op, // binary_op - NULL, // getiter - NULL, // iternext + .base = { &mp_const_type }, + .name = "complex", + .print = complex_print, + .make_new = complex_make_new, + .unary_op = complex_unary_op, + .binary_op = complex_binary_op, .methods = { { NULL, NULL }, }, }; diff --git a/py/objdict.c b/py/objdict.c index b3e21aedd2..1278a99e3c 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -61,12 +61,11 @@ static mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { } const mp_obj_type_t dict_type = { - { &mp_const_type }, - "dict", + .base = { &mp_const_type }, + .name = "dict", .print = dict_print, .make_new = dict_make_new, .binary_op = dict_binary_op, - .getiter = NULL, .methods = {{NULL, NULL},}, }; diff --git a/py/objexcept.c b/py/objexcept.c index 22b8c58126..dca375dda0 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -36,15 +36,9 @@ void exception_print(void (*print)(void *env, const char *fmt, ...), void *env, } const mp_obj_type_t exception_type = { - { &mp_const_type }, - "exception", - exception_print, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext + .base = { &mp_const_type }, + .name = "exception", + .print = exception_print, .methods = {{NULL, NULL},}, }; diff --git a/py/objfloat.c b/py/objfloat.c index 336ae597fc..6c80cf7e5a 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -62,8 +62,8 @@ static mp_obj_t float_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { } const mp_obj_type_t float_type = { - { &mp_const_type }, - "float", + .base = { &mp_const_type }, + .name = "float", .print = float_print, .make_new = float_make_new, .unary_op = float_unary_op, diff --git a/py/objfun.c b/py/objfun.c index 0db6459a39..3697c64303 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -17,9 +17,13 @@ // mp_obj_fun_native_t defined in obj.h +mp_obj_t fun_native_call_n_kw(mp_obj_t self_in, int n_args, int n_kw, const mp_obj_t *args); // args are in reverse order in the array mp_obj_t fun_native_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) { mp_obj_fun_native_t *self = self_in; + if (self->is_kw) { + return fun_native_call_n_kw(self_in, n_args, 0, args); + } if (self->n_args_min == self->n_args_max) { // function requires a fixed number of arguments @@ -69,16 +73,29 @@ mp_obj_t fun_native_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) { } } +mp_obj_t fun_native_call_n_kw(mp_obj_t self_in, int n_args, int n_kw, const mp_obj_t *args) { + mp_obj_fun_native_t *self = self_in; + + if (!self->is_kw) { + nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, "function does not take keyword arguments")); + } + + mp_obj_t *vargs = mp_obj_new_tuple_reverse(n_args, args + 2*n_kw); + mp_map_t *kw_args = mp_map_new(MP_MAP_QSTR, n_kw); + for (int i = 0; i < 2*n_kw; i+=2) { + qstr name = mp_obj_str_get(args[i+1]); + mp_qstr_map_lookup(kw_args, name, true)->value = args[i]; + } + mp_obj_t res = ((mp_fun_kw_t)self->fun)(vargs, kw_args); + /* TODO clean up vargs and kw_args */ + return res; +} + const mp_obj_type_t fun_native_type = { - { &mp_const_type }, - "function", - NULL, // print - NULL, // make_new - fun_native_call_n, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext + .base = { &mp_const_type }, + .name = "function", + .call_n = fun_native_call_n, + .call_n_kw = fun_native_call_n_kw, .methods = { {NULL, NULL}, // end-of-list sentinel }, @@ -172,15 +189,9 @@ mp_obj_t fun_bc_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) { } const mp_obj_type_t fun_bc_type = { - { &mp_const_type }, - "function", - NULL, // print - NULL, // make_new - fun_bc_call_n, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext + .base = { &mp_const_type }, + .name = "function", + .call_n = fun_bc_call_n, .methods = { {NULL, NULL}, // end-of-list sentinel }, @@ -286,15 +297,9 @@ mp_obj_t fun_asm_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) { } static const mp_obj_type_t fun_asm_type = { - { &mp_const_type }, - "function", - NULL, // print - NULL, // make_new - fun_asm_call_n, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext + .base = { &mp_const_type }, + .name = "function", + .call_n = fun_asm_call_n, .methods = { {NULL, NULL}, // end-of-list sentinel }, diff --git a/py/objgenerator.c b/py/objgenerator.c index a91b0d6fc6..7b93d29de5 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -37,15 +37,11 @@ mp_obj_t gen_wrap_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) { } const mp_obj_type_t gen_wrap_type = { - { &mp_const_type }, - "generator", - NULL, // print - NULL, // make_new - gen_wrap_call_n, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext + .base = { &mp_const_type }, + .name = "generator", + .call_n = gen_wrap_call_n, + .unary_op = NULL, + .binary_op = NULL, .methods = {{NULL, NULL},}, }; @@ -92,15 +88,11 @@ mp_obj_t gen_instance_iternext(mp_obj_t self_in) { } const mp_obj_type_t gen_instance_type = { - { &mp_const_type }, - "generator", - gen_instance_print, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - gen_instance_getiter, // getiter - gen_instance_iternext, // iternext + .base = { &mp_const_type }, + .name = "generator", + .print = gen_instance_print, + .getiter = gen_instance_getiter, + .iternext = gen_instance_iternext, .methods = {{NULL, NULL},}, }; diff --git a/py/objinstance.c b/py/objinstance.c index 8ef2773fd9..c26f365597 100644 --- a/py/objinstance.c +++ b/py/objinstance.c @@ -90,15 +90,8 @@ void mp_obj_instance_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) { } const mp_obj_type_t instance_type = { - { &mp_const_type }, - "instance", - NULL, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext + .base = { &mp_const_type }, + .name = "instance", .methods = {{NULL, NULL},}, }; diff --git a/py/objint.c b/py/objint.c index 8d69c4e7a7..6b6c1694db 100644 --- a/py/objint.c +++ b/py/objint.c @@ -31,8 +31,8 @@ static mp_obj_t int_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args) } const mp_obj_type_t int_type = { - { &mp_const_type }, - "int", + .base = { &mp_const_type }, + .name = "int", .make_new = int_make_new, .methods = { { NULL, NULL }, }, }; diff --git a/py/objlist.c b/py/objlist.c index 02a6b1525b..a39586a4cd 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -8,6 +8,7 @@ #include "mpconfig.h" #include "mpqstr.h" #include "obj.h" +#include "map.h" #include "runtime0.h" #include "runtime.h" @@ -119,14 +120,15 @@ static mp_obj_t list_pop(int n_args, const mp_obj_t *args) { } // TODO make this conform to CPython's definition of sort -static void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn) { +static void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn, bool reversed) { + int op = reversed ? RT_COMPARE_OP_MORE : RT_COMPARE_OP_LESS; while (head < tail) { mp_obj_t *h = head - 1; mp_obj_t *t = tail; - mp_obj_t v = rt_call_function_1(key_fn, tail[0]); // get pivot using key_fn + mp_obj_t v = key_fn == NULL ? tail[0] : rt_call_function_1(key_fn, tail[0]); // get pivot using key_fn for (;;) { - do ++h; while (rt_compare_op(RT_COMPARE_OP_LESS, rt_call_function_1(key_fn, h[0]), v) == mp_const_true); - do --t; while (h < t && rt_compare_op(RT_COMPARE_OP_LESS, v, rt_call_function_1(key_fn, t[0])) == mp_const_true); + do ++h; while (rt_compare_op(op, key_fn == NULL ? h[0] : rt_call_function_1(key_fn, h[0]), v) == mp_const_true); + do --t; while (h < t && rt_compare_op(op, v, key_fn == NULL ? t[0] : rt_call_function_1(key_fn, t[0])) == mp_const_true); if (h >= t) break; mp_obj_t x = h[0]; h[0] = t[0]; @@ -135,16 +137,31 @@ static void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn) { mp_obj_t x = h[0]; h[0] = tail[0]; tail[0] = x; - mp_quicksort(head, t, key_fn); + mp_quicksort(head, t, key_fn, reversed); head = h + 1; } } -static mp_obj_t list_sort(mp_obj_t self_in, mp_obj_t key_fn) { - assert(MP_OBJ_IS_TYPE(self_in, &list_type)); - mp_obj_list_t *self = self_in; +static mp_obj_t list_sort(mp_obj_t *args, mp_map_t *kwargs) { + mp_obj_t *args_items = NULL; + machine_uint_t args_len = 0; + qstr key_idx = qstr_from_str_static("key"); + qstr reverse_idx = qstr_from_str_static("reverse"); + + assert(MP_OBJ_IS_TYPE(args, &tuple_type)); + mp_obj_tuple_get(args, &args_len, &args_items); + assert(args_len >= 1); + if (args_len > 1) { + nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, + "list.sort takes no positional arguments")); + } + mp_obj_list_t *self = args_items[0]; if (self->len > 1) { - mp_quicksort(self->items, self->items + self->len - 1, key_fn); + mp_map_elem_t *keyfun = mp_qstr_map_lookup(kwargs, key_idx, false); + mp_map_elem_t *reverse = mp_qstr_map_lookup(kwargs, reverse_idx, false); + mp_quicksort(self->items, self->items + self->len - 1, + keyfun ? keyfun->value : NULL, + reverse && reverse->value ? rt_is_true(reverse->value) : false); } return mp_const_none; // return None, as per CPython } @@ -258,11 +275,11 @@ static MP_DEFINE_CONST_FUN_OBJ_3(list_insert_obj, list_insert); static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_pop_obj, 1, 2, list_pop); static MP_DEFINE_CONST_FUN_OBJ_2(list_remove_obj, list_remove); static MP_DEFINE_CONST_FUN_OBJ_1(list_reverse_obj, list_reverse); -static MP_DEFINE_CONST_FUN_OBJ_2(list_sort_obj, list_sort); +static MP_DEFINE_CONST_FUN_OBJ_KW(list_sort_obj, list_sort); const mp_obj_type_t list_type = { - { &mp_const_type }, - "list", + .base = { &mp_const_type }, + .name = "list", .print = list_print, .make_new = list_make_new, .unary_op = NULL, @@ -341,8 +358,8 @@ mp_obj_t list_it_iternext(mp_obj_t self_in) { } static const mp_obj_type_t list_it_type = { - { &mp_const_type }, - "list_iterator", + .base = { &mp_const_type }, + .name = "list_iterator", .iternext = list_it_iternext, .methods = { { NULL, NULL }, }, }; diff --git a/py/objmodule.c b/py/objmodule.c index 2d6f9555e8..df49ec6707 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -22,15 +22,9 @@ void module_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_ } const mp_obj_type_t module_type = { - { &mp_const_type }, - "module", - module_print, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext + .base = { &mp_const_type }, + .name = "module", + .print = module_print, .methods = {{NULL, NULL},}, }; diff --git a/py/objnone.c b/py/objnone.c index 877e61fe5c..c9a860dd05 100644 --- a/py/objnone.c +++ b/py/objnone.c @@ -15,8 +15,8 @@ void none_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_ob } const mp_obj_type_t none_type = { - { &mp_const_type }, - "NoneType", + .base = { &mp_const_type }, + .name = "NoneType", .print = none_print, .methods = {{NULL, NULL},}, }; diff --git a/py/objrange.c b/py/objrange.c index 1ef42673f4..aba0fa7680 100644 --- a/py/objrange.c +++ b/py/objrange.c @@ -23,15 +23,9 @@ mp_obj_t range_getiter(mp_obj_t o_in) { } static const mp_obj_type_t range_type = { - { &mp_const_type} , - "range", - NULL, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - range_getiter, - NULL, // iternext + .base = { &mp_const_type} , + .name = "range", + .getiter = range_getiter, .methods = {{NULL, NULL},}, }; @@ -68,15 +62,9 @@ mp_obj_t range_it_iternext(mp_obj_t o_in) { } static const mp_obj_type_t range_it_type = { - { &mp_const_type }, - "range_iterator", - NULL, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - range_it_iternext, + .base = { &mp_const_type }, + .name = "range_iterator", + .iternext = range_it_iternext, .methods = {{NULL, NULL},}, }; diff --git a/py/objset.c b/py/objset.c index dd9a4d1e1d..159036a45e 100644 --- a/py/objset.c +++ b/py/objset.c @@ -55,15 +55,10 @@ static mp_obj_t set_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args) } const mp_obj_type_t set_type = { - { &mp_const_type }, - "set", - set_print, // print - set_make_new, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext + .base = { &mp_const_type }, + .name = "set", + .print = set_print, + .make_new = set_make_new, .methods = { { NULL, NULL }, }, }; diff --git a/py/objslice.c b/py/objslice.c index da69b92af2..148d875010 100644 --- a/py/objslice.c +++ b/py/objslice.c @@ -21,15 +21,9 @@ void ellipsis_print(void (*print)(void *env, const char *fmt, ...), void *env, m } const mp_obj_type_t ellipsis_type = { - { &mp_const_type }, - "ellipsis", - ellipsis_print, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext + .base = { &mp_const_type }, + .name = "ellipsis", + .print = ellipsis_print, .methods = {{NULL, NULL},}, }; @@ -55,8 +49,8 @@ void slice_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_o } const mp_obj_type_t slice_type = { - { &mp_const_type }, - "slice", + .base = { &mp_const_type }, + .name = "slice", .print = slice_print, .methods = { { NULL, NULL }, }, }; diff --git a/py/objstr.c b/py/objstr.c index db3e0beca0..c679003eb8 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -185,8 +185,8 @@ static MP_DEFINE_CONST_FUN_OBJ_2(str_join_obj, str_join); static MP_DEFINE_CONST_FUN_OBJ_VAR(str_format_obj, 1, str_format); const mp_obj_type_t str_type = { - { &mp_const_type }, - "str", + .base = { &mp_const_type }, + .name = "str", .print = str_print, .binary_op = str_binary_op, .getiter = str_getiter, @@ -232,8 +232,8 @@ mp_obj_t str_it_iternext(mp_obj_t self_in) { } static const mp_obj_type_t str_it_type = { - { &mp_const_type }, - "str_iterator", + .base = { &mp_const_type }, + .name = "str_iterator", .iternext = str_it_iternext, .methods = { { NULL, NULL }, }, }; diff --git a/py/objtuple.c b/py/objtuple.c index ceca4200e4..2205b869c5 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -97,8 +97,8 @@ static mp_obj_t tuple_getiter(mp_obj_t o_in) { } const mp_obj_type_t tuple_type = { - { &mp_const_type }, - "tuple", + .base = { &mp_const_type }, + .name = "tuple", .print = tuple_print, .make_new = tuple_make_new, .binary_op = tuple_binary_op, @@ -110,7 +110,7 @@ const mp_obj_type_t tuple_type = { static const mp_obj_tuple_t empty_tuple_obj = {{&tuple_type}, 0}; const mp_obj_t mp_const_empty_tuple = (mp_obj_t)&empty_tuple_obj; -mp_obj_t mp_obj_new_tuple(uint n, mp_obj_t *items) { +mp_obj_t mp_obj_new_tuple(uint n, const mp_obj_t *items) { if (n == 0) { return mp_const_empty_tuple; } @@ -123,7 +123,7 @@ mp_obj_t mp_obj_new_tuple(uint n, mp_obj_t *items) { return o; } -mp_obj_t mp_obj_new_tuple_reverse(uint n, mp_obj_t *items) { +mp_obj_t mp_obj_new_tuple_reverse(uint n, const mp_obj_t *items) { if (n == 0) { return mp_const_empty_tuple; } @@ -163,8 +163,8 @@ static mp_obj_t tuple_it_iternext(mp_obj_t self_in) { } static const mp_obj_type_t tuple_it_type = { - { &mp_const_type }, - "tuple_iterator", + .base = { &mp_const_type }, + .name = "tuple_iterator", .iternext = tuple_it_iternext, .methods = {{NULL, NULL},}, }; diff --git a/py/objtype.c b/py/objtype.c index 37d40b38f4..8146499ecd 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -23,8 +23,8 @@ static mp_obj_t type_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) } const mp_obj_type_t mp_const_type = { - { &mp_const_type }, - "type", + .base = { &mp_const_type }, + .name = "type", .print = type_print, .call_n = type_call_n, .methods = {{NULL, NULL},}, diff --git a/py/runtime.c b/py/runtime.c index 6bc71abff7..d1625f6e3d 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -683,10 +683,20 @@ mp_obj_t rt_call_function_n(mp_obj_t fun_in, int n_args, const mp_obj_t *args) { // args are in reverse order in the array; keyword arguments come first, value then key // eg: (value1, key1, value0, key0, arg1, arg0) -mp_obj_t rt_call_function_n_kw(mp_obj_t fun, uint n_args, uint n_kw, const mp_obj_t *args) { - // TODO - assert(0); - return mp_const_none; +mp_obj_t rt_call_function_n_kw(mp_obj_t fun_in, uint n_args, uint n_kw, const mp_obj_t *args) { + // TODO merge this and _n into a single, smarter thing + DEBUG_OP_printf("calling function %p(n_args=%d, n_kw=%d, args=%p)\n", fun_in, n_args, n_kw, args); + + if (MP_OBJ_IS_SMALL_INT(fun_in)) { + nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, "'int' object is not callable")); + } else { + mp_obj_base_t *fun = fun_in; + if (fun->type->call_n_kw != NULL) { + return fun->type->call_n_kw(fun_in, n_args, n_kw, args); + } else { + nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_TypeError, "'%s' object is not callable", fun->type->name)); + } + } } // args contains: arg(n_args-1) arg(n_args-2) ... arg(0) self/NULL fun diff --git a/tests/basics/tests/list_sort.py b/tests/basics/tests/list_sort.py new file mode 100644 index 0000000000..eff12b9c80 --- /dev/null +++ b/tests/basics/tests/list_sort.py @@ -0,0 +1,13 @@ +l = [1, 3, 2, 5] +print(l) +l.sort() +print(l) +l.sort(key=lambda x: -x) +print(l) +l.sort(key=lambda x: -x, reverse=True) +print(l) +l.sort(reverse=True) +print(l) +l.sort(reverse=False) +print(l) + From 3391e190680d3625a166bb6573df26e1bda30af2 Mon Sep 17 00:00:00 2001 From: "John R. Lenton" Date: Tue, 7 Jan 2014 18:06:34 +0000 Subject: [PATCH 16/17] A bit of stylistic cleanup (chose the wrong side during conflict resolution). --- py/objdict.c | 4 ++-- py/objfloat.c | 4 ++-- py/objint.c | 4 ++-- py/objlist.c | 8 ++++---- py/objnone.c | 4 ++-- py/objslice.c | 4 ++-- py/objstr.c | 8 ++++---- py/objtuple.c | 8 ++++---- py/objtype.c | 4 ++-- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/py/objdict.c b/py/objdict.c index f226abbd2f..66a442fbaa 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -61,8 +61,8 @@ static mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { } const mp_obj_type_t dict_type = { - .base = { &mp_const_type }, - .name = "dict", + { &mp_const_type }, + "dict", .print = dict_print, .make_new = dict_make_new, .binary_op = dict_binary_op, diff --git a/py/objfloat.c b/py/objfloat.c index 4b51971814..d21472d5d6 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -62,8 +62,8 @@ static mp_obj_t float_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { } const mp_obj_type_t float_type = { - .base = { &mp_const_type }, - .name = "float", + { &mp_const_type }, + "float", .print = float_print, .make_new = float_make_new, .unary_op = float_unary_op, diff --git a/py/objint.c b/py/objint.c index cf51b7870a..9cd5ebae29 100644 --- a/py/objint.c +++ b/py/objint.c @@ -31,8 +31,8 @@ static mp_obj_t int_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args) } const mp_obj_type_t int_type = { - .base = { &mp_const_type }, - .name = "int", + { &mp_const_type }, + "int", .make_new = int_make_new, }; diff --git a/py/objlist.c b/py/objlist.c index 0446412e83..5162fa09ff 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -293,8 +293,8 @@ static const mp_method_t list_type_methods[] = { }; const mp_obj_type_t list_type = { - .base = { &mp_const_type }, - .name = "list", + { &mp_const_type }, + "list", .print = list_print, .make_new = list_make_new, .binary_op = list_binary_op, @@ -360,8 +360,8 @@ mp_obj_t list_it_iternext(mp_obj_t self_in) { } static const mp_obj_type_t list_it_type = { - .base = { &mp_const_type }, - .name = "list_iterator", + { &mp_const_type }, + "list_iterator", .iternext = list_it_iternext, }; diff --git a/py/objnone.c b/py/objnone.c index dc93c25e2d..c0efe6c0f5 100644 --- a/py/objnone.c +++ b/py/objnone.c @@ -15,8 +15,8 @@ void none_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_ob } const mp_obj_type_t none_type = { - .base = { &mp_const_type }, - .name = "NoneType", + { &mp_const_type }, + "NoneType", .print = none_print, }; diff --git a/py/objslice.c b/py/objslice.c index 3b1bbb186b..d95ccef06f 100644 --- a/py/objslice.c +++ b/py/objslice.c @@ -48,8 +48,8 @@ void slice_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_o } const mp_obj_type_t slice_type = { - .base = { &mp_const_type }, - .name = "slice", + { &mp_const_type }, + "slice", .print = slice_print, }; diff --git a/py/objstr.c b/py/objstr.c index b95aafe432..cc9f7f85b4 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -191,8 +191,8 @@ static const mp_method_t str_type_methods[] = { }; const mp_obj_type_t str_type = { - .base = { &mp_const_type }, - .name = "str", + { &mp_const_type }, + "str", .print = str_print, .binary_op = str_binary_op, .getiter = str_getiter, @@ -234,8 +234,8 @@ mp_obj_t str_it_iternext(mp_obj_t self_in) { } static const mp_obj_type_t str_it_type = { - .base = { &mp_const_type }, - .name = "str_iterator", + { &mp_const_type }, + "str_iterator", .iternext = str_it_iternext, }; diff --git a/py/objtuple.c b/py/objtuple.c index e96f76aeaf..0050fc5ea0 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -97,8 +97,8 @@ static mp_obj_t tuple_getiter(mp_obj_t o_in) { } const mp_obj_type_t tuple_type = { - .base = { &mp_const_type }, - .name = "tuple", + { &mp_const_type }, + "tuple", .print = tuple_print, .make_new = tuple_make_new, .binary_op = tuple_binary_op, @@ -162,8 +162,8 @@ static mp_obj_t tuple_it_iternext(mp_obj_t self_in) { } static const mp_obj_type_t tuple_it_type = { - .base = { &mp_const_type }, - .name = "tuple_iterator", + { &mp_const_type }, + "tuple_iterator", .iternext = tuple_it_iternext, }; diff --git a/py/objtype.c b/py/objtype.c index 012071d6e1..8778c180ca 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -23,8 +23,8 @@ static mp_obj_t type_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) } const mp_obj_type_t mp_const_type = { - .base = { &mp_const_type }, - .name = "type", + { &mp_const_type }, + "type", .print = type_print, .call_n = type_call_n, }; From 1e40840b3b082deb1ed14e2d82e448684b96ed0d Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 7 Jan 2014 19:35:39 +0200 Subject: [PATCH 17/17] Add OSError, Python 3.3 generic I/O exception. --- py/mpqstrraw.h | 1 + py/runtime.c | 1 + 2 files changed, 2 insertions(+) diff --git a/py/mpqstrraw.h b/py/mpqstrraw.h index fe74c3e927..eeed6f3a0a 100644 --- a/py/mpqstrraw.h +++ b/py/mpqstrraw.h @@ -30,6 +30,7 @@ Q(NameError) Q(SyntaxError) Q(TypeError) Q(ValueError) +Q(OSError) Q(abs) Q(all) diff --git a/py/runtime.c b/py/runtime.c index a5dafb190d..dce8c7b96a 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -84,6 +84,7 @@ void rt_init(void) { mp_qstr_map_lookup(&map_builtins, MP_QSTR_TypeError, true)->value = mp_obj_new_exception(MP_QSTR_TypeError); mp_qstr_map_lookup(&map_builtins, MP_QSTR_SyntaxError, true)->value = mp_obj_new_exception(MP_QSTR_SyntaxError); mp_qstr_map_lookup(&map_builtins, MP_QSTR_ValueError, true)->value = mp_obj_new_exception(MP_QSTR_ValueError); + mp_qstr_map_lookup(&map_builtins, MP_QSTR_OSError, true)->value = mp_obj_new_exception(MP_QSTR_OSError); // built-in objects mp_qstr_map_lookup(&map_builtins, MP_QSTR_Ellipsis, true)->value = mp_const_ellipsis;