Port of MicroPython to the mbed platform. See micropython-repl for an interactive program.

Dependents:   micropython-repl

This a port of MicroPython to the mbed Classic platform.

This provides an interpreter running on the board's USB serial connection.

Getting Started

Import the micropython-repl program into your IDE workspace on developer.mbed.org. Compile and download to your board. Connect to the USB serial port in your usual manner. You should get a startup message similar to the following:

  MicroPython v1.7-155-gdddcdd8 on 2016-04-23; K64F with ARM
  Type "help()" for more information.
  >>>

Then you can start using micropython. For example:

  >>> from mbed import DigitalOut
  >>> from pins import LED1
  >>> led = DigitalOut(LED1)
  >>> led.write(1)

Requirements

You need approximately 100K of flash memory, so this will be no good for boards with smaller amounts of storage.

Caveats

This can be considered an alpha release of the port; things may not work; APIs may change in later releases. It is NOT an official part part the micropython project, so if anything doesn't work, blame me. If it does work, most of the credit is due to micropython.

  • Only a few of the mbed classes are available in micropython so far, and not all methods of those that are.
  • Only a few boards have their full range of pin names available; for others, only a few standard ones (USBTX, USBRX, LED1) are implemented.
  • The garbage collector is not yet implemented. The interpreter will gradually consume memory and then fail.
  • Exceptions from the mbed classes are not yet handled.
  • Asynchronous processing (e.g. events on inputs) is not supported.

Credits

  • Damien P. George and other contributors who created micropython.
  • Colin Hogben, author of this port.
Committer:
Colin Hogben
Date:
Wed Apr 27 22:11:29 2016 +0100
Revision:
10:33521d742af1
Parent:
0:5868e8752d44
Update README and version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pythontech 0:5868e8752d44 1 /*
pythontech 0:5868e8752d44 2 * This file is part of the Micro Python project, http://micropython.org/
pythontech 0:5868e8752d44 3 *
pythontech 0:5868e8752d44 4 * The MIT License (MIT)
pythontech 0:5868e8752d44 5 *
pythontech 0:5868e8752d44 6 * Copyright (c) 2013, 2014 Damien P. George
pythontech 0:5868e8752d44 7 *
pythontech 0:5868e8752d44 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
pythontech 0:5868e8752d44 9 * of this software and associated documentation files (the "Software"), to deal
pythontech 0:5868e8752d44 10 * in the Software without restriction, including without limitation the rights
pythontech 0:5868e8752d44 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
pythontech 0:5868e8752d44 12 * copies of the Software, and to permit persons to whom the Software is
pythontech 0:5868e8752d44 13 * furnished to do so, subject to the following conditions:
pythontech 0:5868e8752d44 14 *
pythontech 0:5868e8752d44 15 * The above copyright notice and this permission notice shall be included in
pythontech 0:5868e8752d44 16 * all copies or substantial portions of the Software.
pythontech 0:5868e8752d44 17 *
pythontech 0:5868e8752d44 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
pythontech 0:5868e8752d44 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
pythontech 0:5868e8752d44 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
pythontech 0:5868e8752d44 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
pythontech 0:5868e8752d44 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
pythontech 0:5868e8752d44 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
pythontech 0:5868e8752d44 24 * THE SOFTWARE.
pythontech 0:5868e8752d44 25 */
pythontech 0:5868e8752d44 26
pythontech 0:5868e8752d44 27 #include <stdio.h>
pythontech 0:5868e8752d44 28 #include <stdarg.h>
pythontech 0:5868e8752d44 29 #include <string.h>
pythontech 0:5868e8752d44 30 #include <assert.h>
pythontech 0:5868e8752d44 31
pythontech 0:5868e8752d44 32 #include "py/mpconfig.h"
pythontech 0:5868e8752d44 33 #include "py/misc.h"
pythontech 0:5868e8752d44 34 #include "py/mpprint.h"
pythontech 0:5868e8752d44 35
pythontech 0:5868e8752d44 36 // returned value is always at least 1 greater than argument
pythontech 0:5868e8752d44 37 #define ROUND_ALLOC(a) (((a) & ((~0) - 7)) + 8)
pythontech 0:5868e8752d44 38
pythontech 0:5868e8752d44 39 // Init the vstr so it allocs exactly given number of bytes. Set length to zero.
pythontech 0:5868e8752d44 40 void vstr_init(vstr_t *vstr, size_t alloc) {
pythontech 0:5868e8752d44 41 if (alloc < 1) {
pythontech 0:5868e8752d44 42 alloc = 1;
pythontech 0:5868e8752d44 43 }
pythontech 0:5868e8752d44 44 vstr->alloc = alloc;
pythontech 0:5868e8752d44 45 vstr->len = 0;
pythontech 0:5868e8752d44 46 vstr->buf = m_new(char, vstr->alloc);
pythontech 0:5868e8752d44 47 if (vstr->buf == NULL) {
pythontech 0:5868e8752d44 48 vstr->had_error = true;
pythontech 0:5868e8752d44 49 return;
pythontech 0:5868e8752d44 50 }
pythontech 0:5868e8752d44 51 vstr->had_error = false;
pythontech 0:5868e8752d44 52 vstr->fixed_buf = false;
pythontech 0:5868e8752d44 53 }
pythontech 0:5868e8752d44 54
pythontech 0:5868e8752d44 55 // Init the vstr so it allocs exactly enough ram to hold a null-terminated
pythontech 0:5868e8752d44 56 // string of the given length, and set the length.
pythontech 0:5868e8752d44 57 void vstr_init_len(vstr_t *vstr, size_t len) {
pythontech 0:5868e8752d44 58 vstr_init(vstr, len + 1);
pythontech 0:5868e8752d44 59 vstr->len = len;
pythontech 0:5868e8752d44 60 }
pythontech 0:5868e8752d44 61
pythontech 0:5868e8752d44 62 void vstr_init_fixed_buf(vstr_t *vstr, size_t alloc, char *buf) {
pythontech 0:5868e8752d44 63 vstr->alloc = alloc;
pythontech 0:5868e8752d44 64 vstr->len = 0;
pythontech 0:5868e8752d44 65 vstr->buf = buf;
pythontech 0:5868e8752d44 66 vstr->had_error = false;
pythontech 0:5868e8752d44 67 vstr->fixed_buf = true;
pythontech 0:5868e8752d44 68 }
pythontech 0:5868e8752d44 69
pythontech 0:5868e8752d44 70 void vstr_init_print(vstr_t *vstr, size_t alloc, mp_print_t *print) {
pythontech 0:5868e8752d44 71 vstr_init(vstr, alloc);
pythontech 0:5868e8752d44 72 print->data = vstr;
pythontech 0:5868e8752d44 73 print->print_strn = (mp_print_strn_t)vstr_add_strn;
pythontech 0:5868e8752d44 74 }
pythontech 0:5868e8752d44 75
pythontech 0:5868e8752d44 76 void vstr_clear(vstr_t *vstr) {
pythontech 0:5868e8752d44 77 if (!vstr->fixed_buf) {
pythontech 0:5868e8752d44 78 m_del(char, vstr->buf, vstr->alloc);
pythontech 0:5868e8752d44 79 }
pythontech 0:5868e8752d44 80 vstr->buf = NULL;
pythontech 0:5868e8752d44 81 }
pythontech 0:5868e8752d44 82
pythontech 0:5868e8752d44 83 vstr_t *vstr_new(void) {
pythontech 0:5868e8752d44 84 vstr_t *vstr = m_new_obj(vstr_t);
pythontech 0:5868e8752d44 85 if (vstr == NULL) {
pythontech 0:5868e8752d44 86 return NULL;
pythontech 0:5868e8752d44 87 }
pythontech 0:5868e8752d44 88 vstr_init(vstr, 16);
pythontech 0:5868e8752d44 89 return vstr;
pythontech 0:5868e8752d44 90 }
pythontech 0:5868e8752d44 91
pythontech 0:5868e8752d44 92 vstr_t *vstr_new_size(size_t alloc) {
pythontech 0:5868e8752d44 93 vstr_t *vstr = m_new_obj(vstr_t);
pythontech 0:5868e8752d44 94 if (vstr == NULL) {
pythontech 0:5868e8752d44 95 return NULL;
pythontech 0:5868e8752d44 96 }
pythontech 0:5868e8752d44 97 vstr_init(vstr, alloc);
pythontech 0:5868e8752d44 98 return vstr;
pythontech 0:5868e8752d44 99 }
pythontech 0:5868e8752d44 100
pythontech 0:5868e8752d44 101 void vstr_free(vstr_t *vstr) {
pythontech 0:5868e8752d44 102 if (vstr != NULL) {
pythontech 0:5868e8752d44 103 if (!vstr->fixed_buf) {
pythontech 0:5868e8752d44 104 m_del(char, vstr->buf, vstr->alloc);
pythontech 0:5868e8752d44 105 }
pythontech 0:5868e8752d44 106 m_del_obj(vstr_t, vstr);
pythontech 0:5868e8752d44 107 }
pythontech 0:5868e8752d44 108 }
pythontech 0:5868e8752d44 109
pythontech 0:5868e8752d44 110 void vstr_reset(vstr_t *vstr) {
pythontech 0:5868e8752d44 111 vstr->len = 0;
pythontech 0:5868e8752d44 112 vstr->had_error = false;
pythontech 0:5868e8752d44 113 }
pythontech 0:5868e8752d44 114
pythontech 0:5868e8752d44 115 bool vstr_had_error(vstr_t *vstr) {
pythontech 0:5868e8752d44 116 return vstr->had_error;
pythontech 0:5868e8752d44 117 }
pythontech 0:5868e8752d44 118
pythontech 0:5868e8752d44 119 char *vstr_str(vstr_t *vstr) {
pythontech 0:5868e8752d44 120 if (vstr->had_error) {
pythontech 0:5868e8752d44 121 return NULL;
pythontech 0:5868e8752d44 122 }
pythontech 0:5868e8752d44 123 return vstr->buf;
pythontech 0:5868e8752d44 124 }
pythontech 0:5868e8752d44 125
pythontech 0:5868e8752d44 126 size_t vstr_len(vstr_t *vstr) {
pythontech 0:5868e8752d44 127 if (vstr->had_error) {
pythontech 0:5868e8752d44 128 return 0;
pythontech 0:5868e8752d44 129 }
pythontech 0:5868e8752d44 130 return vstr->len;
pythontech 0:5868e8752d44 131 }
pythontech 0:5868e8752d44 132
pythontech 0:5868e8752d44 133 // Extend vstr strictly by requested size, return pointer to newly added chunk.
pythontech 0:5868e8752d44 134 char *vstr_extend(vstr_t *vstr, size_t size) {
pythontech 0:5868e8752d44 135 if (vstr->fixed_buf) {
pythontech 0:5868e8752d44 136 return NULL;
pythontech 0:5868e8752d44 137 }
pythontech 0:5868e8752d44 138 char *new_buf = m_renew(char, vstr->buf, vstr->alloc, vstr->alloc + size);
pythontech 0:5868e8752d44 139 if (new_buf == NULL) {
pythontech 0:5868e8752d44 140 vstr->had_error = true;
pythontech 0:5868e8752d44 141 return NULL;
pythontech 0:5868e8752d44 142 }
pythontech 0:5868e8752d44 143 char *p = new_buf + vstr->alloc;
pythontech 0:5868e8752d44 144 vstr->alloc += size;
pythontech 0:5868e8752d44 145 vstr->buf = new_buf;
pythontech 0:5868e8752d44 146 return p;
pythontech 0:5868e8752d44 147 }
pythontech 0:5868e8752d44 148
pythontech 0:5868e8752d44 149 STATIC bool vstr_ensure_extra(vstr_t *vstr, size_t size) {
pythontech 0:5868e8752d44 150 if (vstr->len + size > vstr->alloc) {
pythontech 0:5868e8752d44 151 if (vstr->fixed_buf) {
pythontech 0:5868e8752d44 152 return false;
pythontech 0:5868e8752d44 153 }
pythontech 0:5868e8752d44 154 size_t new_alloc = ROUND_ALLOC((vstr->len + size) * 2);
pythontech 0:5868e8752d44 155 char *new_buf = m_renew(char, vstr->buf, vstr->alloc, new_alloc);
pythontech 0:5868e8752d44 156 if (new_buf == NULL) {
pythontech 0:5868e8752d44 157 vstr->had_error = true;
pythontech 0:5868e8752d44 158 return false;
pythontech 0:5868e8752d44 159 }
pythontech 0:5868e8752d44 160 vstr->alloc = new_alloc;
pythontech 0:5868e8752d44 161 vstr->buf = new_buf;
pythontech 0:5868e8752d44 162 }
pythontech 0:5868e8752d44 163 return true;
pythontech 0:5868e8752d44 164 }
pythontech 0:5868e8752d44 165
pythontech 0:5868e8752d44 166 void vstr_hint_size(vstr_t *vstr, size_t size) {
pythontech 0:5868e8752d44 167 // it's not an error if we fail to allocate for the size hint
pythontech 0:5868e8752d44 168 bool er = vstr->had_error;
pythontech 0:5868e8752d44 169 vstr_ensure_extra(vstr, size);
pythontech 0:5868e8752d44 170 vstr->had_error = er;
pythontech 0:5868e8752d44 171 }
pythontech 0:5868e8752d44 172
pythontech 0:5868e8752d44 173 char *vstr_add_len(vstr_t *vstr, size_t len) {
pythontech 0:5868e8752d44 174 if (vstr->had_error || !vstr_ensure_extra(vstr, len)) {
pythontech 0:5868e8752d44 175 return NULL;
pythontech 0:5868e8752d44 176 }
pythontech 0:5868e8752d44 177 char *buf = vstr->buf + vstr->len;
pythontech 0:5868e8752d44 178 vstr->len += len;
pythontech 0:5868e8752d44 179 return buf;
pythontech 0:5868e8752d44 180 }
pythontech 0:5868e8752d44 181
pythontech 0:5868e8752d44 182 // Doesn't increase len, just makes sure there is a null byte at the end
pythontech 0:5868e8752d44 183 char *vstr_null_terminated_str(vstr_t *vstr) {
pythontech 0:5868e8752d44 184 if (vstr->had_error || !vstr_ensure_extra(vstr, 1)) {
pythontech 0:5868e8752d44 185 return NULL;
pythontech 0:5868e8752d44 186 }
pythontech 0:5868e8752d44 187 vstr->buf[vstr->len] = '\0';
pythontech 0:5868e8752d44 188 return vstr->buf;
pythontech 0:5868e8752d44 189 }
pythontech 0:5868e8752d44 190
pythontech 0:5868e8752d44 191 void vstr_add_byte(vstr_t *vstr, byte b) {
pythontech 0:5868e8752d44 192 byte *buf = (byte*)vstr_add_len(vstr, 1);
pythontech 0:5868e8752d44 193 if (buf == NULL) {
pythontech 0:5868e8752d44 194 return;
pythontech 0:5868e8752d44 195 }
pythontech 0:5868e8752d44 196 buf[0] = b;
pythontech 0:5868e8752d44 197 }
pythontech 0:5868e8752d44 198
pythontech 0:5868e8752d44 199 void vstr_add_char(vstr_t *vstr, unichar c) {
pythontech 0:5868e8752d44 200 #if MICROPY_PY_BUILTINS_STR_UNICODE
pythontech 0:5868e8752d44 201 // TODO: Can this be simplified and deduplicated?
pythontech 0:5868e8752d44 202 // Is it worth just calling vstr_add_len(vstr, 4)?
pythontech 0:5868e8752d44 203 if (c < 0x80) {
pythontech 0:5868e8752d44 204 byte *buf = (byte*)vstr_add_len(vstr, 1);
pythontech 0:5868e8752d44 205 if (buf == NULL) {
pythontech 0:5868e8752d44 206 return;
pythontech 0:5868e8752d44 207 }
pythontech 0:5868e8752d44 208 *buf = (byte)c;
pythontech 0:5868e8752d44 209 } else if (c < 0x800) {
pythontech 0:5868e8752d44 210 byte *buf = (byte*)vstr_add_len(vstr, 2);
pythontech 0:5868e8752d44 211 if (buf == NULL) {
pythontech 0:5868e8752d44 212 return;
pythontech 0:5868e8752d44 213 }
pythontech 0:5868e8752d44 214 buf[0] = (c >> 6) | 0xC0;
pythontech 0:5868e8752d44 215 buf[1] = (c & 0x3F) | 0x80;
pythontech 0:5868e8752d44 216 } else if (c < 0x10000) {
pythontech 0:5868e8752d44 217 byte *buf = (byte*)vstr_add_len(vstr, 3);
pythontech 0:5868e8752d44 218 if (buf == NULL) {
pythontech 0:5868e8752d44 219 return;
pythontech 0:5868e8752d44 220 }
pythontech 0:5868e8752d44 221 buf[0] = (c >> 12) | 0xE0;
pythontech 0:5868e8752d44 222 buf[1] = ((c >> 6) & 0x3F) | 0x80;
pythontech 0:5868e8752d44 223 buf[2] = (c & 0x3F) | 0x80;
pythontech 0:5868e8752d44 224 } else {
pythontech 0:5868e8752d44 225 assert(c < 0x110000);
pythontech 0:5868e8752d44 226 byte *buf = (byte*)vstr_add_len(vstr, 4);
pythontech 0:5868e8752d44 227 if (buf == NULL) {
pythontech 0:5868e8752d44 228 return;
pythontech 0:5868e8752d44 229 }
pythontech 0:5868e8752d44 230 buf[0] = (c >> 18) | 0xF0;
pythontech 0:5868e8752d44 231 buf[1] = ((c >> 12) & 0x3F) | 0x80;
pythontech 0:5868e8752d44 232 buf[2] = ((c >> 6) & 0x3F) | 0x80;
pythontech 0:5868e8752d44 233 buf[3] = (c & 0x3F) | 0x80;
pythontech 0:5868e8752d44 234 }
pythontech 0:5868e8752d44 235 #else
pythontech 0:5868e8752d44 236 vstr_add_byte(vstr, c);
pythontech 0:5868e8752d44 237 #endif
pythontech 0:5868e8752d44 238 }
pythontech 0:5868e8752d44 239
pythontech 0:5868e8752d44 240 void vstr_add_str(vstr_t *vstr, const char *str) {
pythontech 0:5868e8752d44 241 vstr_add_strn(vstr, str, strlen(str));
pythontech 0:5868e8752d44 242 }
pythontech 0:5868e8752d44 243
pythontech 0:5868e8752d44 244 void vstr_add_strn(vstr_t *vstr, const char *str, size_t len) {
pythontech 0:5868e8752d44 245 if (vstr->had_error || !vstr_ensure_extra(vstr, len)) {
pythontech 0:5868e8752d44 246 // if buf is fixed, we got here because there isn't enough room left
pythontech 0:5868e8752d44 247 // so just try to copy as much as we can, with room for a possible null byte
pythontech 0:5868e8752d44 248 if (vstr->fixed_buf && vstr->len < vstr->alloc) {
pythontech 0:5868e8752d44 249 len = vstr->alloc - vstr->len;
pythontech 0:5868e8752d44 250 goto copy;
pythontech 0:5868e8752d44 251 }
pythontech 0:5868e8752d44 252 return;
pythontech 0:5868e8752d44 253 }
pythontech 0:5868e8752d44 254 copy:
pythontech 0:5868e8752d44 255 memmove(vstr->buf + vstr->len, str, len);
pythontech 0:5868e8752d44 256 vstr->len += len;
pythontech 0:5868e8752d44 257 }
pythontech 0:5868e8752d44 258
pythontech 0:5868e8752d44 259 STATIC char *vstr_ins_blank_bytes(vstr_t *vstr, size_t byte_pos, size_t byte_len) {
pythontech 0:5868e8752d44 260 if (vstr->had_error) {
pythontech 0:5868e8752d44 261 return NULL;
pythontech 0:5868e8752d44 262 }
pythontech 0:5868e8752d44 263 size_t l = vstr->len;
pythontech 0:5868e8752d44 264 if (byte_pos > l) {
pythontech 0:5868e8752d44 265 byte_pos = l;
pythontech 0:5868e8752d44 266 }
pythontech 0:5868e8752d44 267 if (byte_len > 0) {
pythontech 0:5868e8752d44 268 // ensure room for the new bytes
pythontech 0:5868e8752d44 269 if (!vstr_ensure_extra(vstr, byte_len)) {
pythontech 0:5868e8752d44 270 return NULL;
pythontech 0:5868e8752d44 271 }
pythontech 0:5868e8752d44 272 // copy up the string to make room for the new bytes
pythontech 0:5868e8752d44 273 memmove(vstr->buf + byte_pos + byte_len, vstr->buf + byte_pos, l - byte_pos);
pythontech 0:5868e8752d44 274 // increase the length
pythontech 0:5868e8752d44 275 vstr->len += byte_len;
pythontech 0:5868e8752d44 276 }
pythontech 0:5868e8752d44 277 return vstr->buf + byte_pos;
pythontech 0:5868e8752d44 278 }
pythontech 0:5868e8752d44 279
pythontech 0:5868e8752d44 280 void vstr_ins_byte(vstr_t *vstr, size_t byte_pos, byte b) {
pythontech 0:5868e8752d44 281 char *s = vstr_ins_blank_bytes(vstr, byte_pos, 1);
pythontech 0:5868e8752d44 282 if (s != NULL) {
pythontech 0:5868e8752d44 283 *s = b;
pythontech 0:5868e8752d44 284 }
pythontech 0:5868e8752d44 285 }
pythontech 0:5868e8752d44 286
pythontech 0:5868e8752d44 287 void vstr_ins_char(vstr_t *vstr, size_t char_pos, unichar chr) {
pythontech 0:5868e8752d44 288 // TODO UNICODE
pythontech 0:5868e8752d44 289 char *s = vstr_ins_blank_bytes(vstr, char_pos, 1);
pythontech 0:5868e8752d44 290 if (s != NULL) {
pythontech 0:5868e8752d44 291 *s = chr;
pythontech 0:5868e8752d44 292 }
pythontech 0:5868e8752d44 293 }
pythontech 0:5868e8752d44 294
pythontech 0:5868e8752d44 295 void vstr_cut_head_bytes(vstr_t *vstr, size_t bytes_to_cut) {
pythontech 0:5868e8752d44 296 vstr_cut_out_bytes(vstr, 0, bytes_to_cut);
pythontech 0:5868e8752d44 297 }
pythontech 0:5868e8752d44 298
pythontech 0:5868e8752d44 299 void vstr_cut_tail_bytes(vstr_t *vstr, size_t len) {
pythontech 0:5868e8752d44 300 if (vstr->had_error) {
pythontech 0:5868e8752d44 301 return;
pythontech 0:5868e8752d44 302 }
pythontech 0:5868e8752d44 303 if (len > vstr->len) {
pythontech 0:5868e8752d44 304 vstr->len = 0;
pythontech 0:5868e8752d44 305 } else {
pythontech 0:5868e8752d44 306 vstr->len -= len;
pythontech 0:5868e8752d44 307 }
pythontech 0:5868e8752d44 308 }
pythontech 0:5868e8752d44 309
pythontech 0:5868e8752d44 310 void vstr_cut_out_bytes(vstr_t *vstr, size_t byte_pos, size_t bytes_to_cut) {
pythontech 0:5868e8752d44 311 if (vstr->had_error || byte_pos >= vstr->len) {
pythontech 0:5868e8752d44 312 return;
pythontech 0:5868e8752d44 313 } else if (byte_pos + bytes_to_cut >= vstr->len) {
pythontech 0:5868e8752d44 314 vstr->len = byte_pos;
pythontech 0:5868e8752d44 315 } else {
pythontech 0:5868e8752d44 316 memmove(vstr->buf + byte_pos, vstr->buf + byte_pos + bytes_to_cut, vstr->len - byte_pos - bytes_to_cut);
pythontech 0:5868e8752d44 317 vstr->len -= bytes_to_cut;
pythontech 0:5868e8752d44 318 }
pythontech 0:5868e8752d44 319 }
pythontech 0:5868e8752d44 320
pythontech 0:5868e8752d44 321 void vstr_printf(vstr_t *vstr, const char *fmt, ...) {
pythontech 0:5868e8752d44 322 va_list ap;
pythontech 0:5868e8752d44 323 va_start(ap, fmt);
pythontech 0:5868e8752d44 324 vstr_vprintf(vstr, fmt, ap);
pythontech 0:5868e8752d44 325 va_end(ap);
pythontech 0:5868e8752d44 326 }
pythontech 0:5868e8752d44 327
pythontech 0:5868e8752d44 328 void vstr_vprintf(vstr_t *vstr, const char *fmt, va_list ap) {
pythontech 0:5868e8752d44 329 mp_print_t print = {vstr, (mp_print_strn_t)vstr_add_strn};
pythontech 0:5868e8752d44 330 mp_vprintf(&print, fmt, ap);
pythontech 0:5868e8752d44 331 }