Commit 55baff4c authored by Damien George's avatar Damien George
Browse files

Revamp qstrs: they now include length and hash.

Can now have null bytes in strings.  Can define ROM qstrs per port using
qstrdefsport.h
parent 91d457a2
......@@ -4,6 +4,7 @@
#include "nlr.h"
#include "misc.h"
#include "mpconfig.h"
#include "qstr.h"
#include "parse.h"
#include "obj.h"
#include "runtime.h"
......@@ -219,15 +220,15 @@ void lcd_init(void) {
lcd_next_line = 0;
// Python interface
mp_obj_t m = mp_obj_new_module(qstr_from_str_static("lcd"));
rt_store_attr(m, qstr_from_str_static("lcd8"), rt_make_function_n(2, lcd_draw_pixel_8));
rt_store_attr(m, qstr_from_str_static("clear"), rt_make_function_n(0, lcd_pix_clear));
rt_store_attr(m, qstr_from_str_static("get"), rt_make_function_n(2, lcd_pix_get));
rt_store_attr(m, qstr_from_str_static("set"), rt_make_function_n(2, lcd_pix_set));
rt_store_attr(m, qstr_from_str_static("reset"), rt_make_function_n(2, lcd_pix_reset));
rt_store_attr(m, qstr_from_str_static("show"), rt_make_function_n(0, lcd_pix_show));
rt_store_attr(m, qstr_from_str_static("text"), rt_make_function_n(1, lcd_print));
rt_store_name(qstr_from_str_static("lcd"), m);
mp_obj_t m = mp_obj_new_module(QSTR_FROM_STR_STATIC("lcd"));
rt_store_attr(m, QSTR_FROM_STR_STATIC("lcd8"), rt_make_function_n(2, lcd_draw_pixel_8));
rt_store_attr(m, QSTR_FROM_STR_STATIC("clear"), rt_make_function_n(0, lcd_pix_clear));
rt_store_attr(m, QSTR_FROM_STR_STATIC("get"), rt_make_function_n(2, lcd_pix_get));
rt_store_attr(m, QSTR_FROM_STR_STATIC("set"), rt_make_function_n(2, lcd_pix_set));
rt_store_attr(m, QSTR_FROM_STR_STATIC("reset"), rt_make_function_n(2, lcd_pix_reset));
rt_store_attr(m, QSTR_FROM_STR_STATIC("show"), rt_make_function_n(0, lcd_pix_show));
rt_store_attr(m, QSTR_FROM_STR_STATIC("text"), rt_make_function_n(1, lcd_print));
rt_store_name(QSTR_FROM_STR_STATIC("lcd"), m);
}
void lcd_print_str(const char *str) {
......
......@@ -4,6 +4,7 @@
#include "misc.h"
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "led.h"
......
......@@ -4,6 +4,8 @@
#include "ff.h"
#include "misc.h"
#include "mpconfig.h"
#include "qstr.h"
#include "lexer.h"
#include "lexerfatfs.h"
......
#include <stdio.h>
#include <string.h>
#include <stm32f4xx.h>
#include <stm32f4xx_rcc.h>
#include <stm32f4xx_syscfg.h>
......@@ -15,7 +16,7 @@
#include "misc.h"
#include "ff.h"
#include "mpconfig.h"
#include "mpqstr.h"
#include "qstr.h"
#include "nlr.h"
#include "misc.h"
#include "lexer.h"
......@@ -677,11 +678,10 @@ void file_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, m
mp_obj_t file_obj_read(mp_obj_t self_in, mp_obj_t arg) {
pyb_file_obj_t *self = self_in;
int n = mp_obj_get_int(arg);
char *buf = m_new(char, n + 1);
char *buf = m_new(char, n);
UINT n_out;
f_read(&self->fp, buf, n, &n_out);
buf[n_out] = 0;
return mp_obj_new_str(qstr_from_str_take(buf, n + 1));
return mp_obj_new_str(qstr_from_strn_take(buf, n, n_out));
}
mp_obj_t file_obj_write(mp_obj_t self_in, mp_obj_t arg) {
......@@ -827,37 +827,37 @@ soft_reset:
// add some functions to the python namespace
{
rt_store_name(qstr_from_str_static("help"), rt_make_function_n(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_n(0, pyb_info));
rt_store_attr(m, qstr_from_str_static("sd_test"), rt_make_function_n(0, pyb_sd_test));
rt_store_attr(m, qstr_from_str_static("stop"), rt_make_function_n(0, pyb_stop));
rt_store_attr(m, qstr_from_str_static("standby"), rt_make_function_n(0, pyb_standby));
rt_store_attr(m, qstr_from_str_static("source_dir"), rt_make_function_n(1, pyb_source_dir));
rt_store_attr(m, qstr_from_str_static("main"), rt_make_function_n(1, pyb_main));
rt_store_attr(m, qstr_from_str_static("sync"), rt_make_function_n(0, pyb_sync));
rt_store_attr(m, qstr_from_str_static("gc"), rt_make_function_n(0, pyb_gc));
rt_store_attr(m, qstr_from_str_static("delay"), rt_make_function_n(1, pyb_delay));
rt_store_attr(m, qstr_from_str_static("led"), rt_make_function_n(1, pyb_led));
rt_store_attr(m, qstr_from_str_static("switch"), (mp_obj_t)&pyb_switch_obj);
rt_store_attr(m, qstr_from_str_static("servo"), rt_make_function_n(2, pyb_servo_set));
rt_store_attr(m, qstr_from_str_static("pwm"), rt_make_function_n(2, pyb_pwm_set));
rt_store_attr(m, qstr_from_str_static("accel"), (mp_obj_t)&pyb_mma_read_obj);
rt_store_attr(m, qstr_from_str_static("mma_read"), (mp_obj_t)&pyb_mma_read_all_obj);
rt_store_attr(m, qstr_from_str_static("mma_mode"), (mp_obj_t)&pyb_mma_write_mode_obj);
rt_store_attr(m, qstr_from_str_static("hid"), rt_make_function_n(1, pyb_hid_send_report));
rt_store_attr(m, qstr_from_str_static("time"), rt_make_function_n(0, pyb_rtc_read));
rt_store_attr(m, qstr_from_str_static("rand"), rt_make_function_n(0, pyb_rng_get));
rt_store_attr(m, qstr_from_str_static("Led"), rt_make_function_n(1, pyb_Led));
rt_store_attr(m, qstr_from_str_static("Servo"), rt_make_function_n(1, pyb_Servo));
rt_store_attr(m, qstr_from_str_static("I2C"), rt_make_function_n(2, pyb_I2C));
rt_store_attr(m, qstr_from_str_static("gpio"), (mp_obj_t)&pyb_gpio_obj);
rt_store_attr(m, qstr_from_str_static("Usart"), rt_make_function_n(2, pyb_Usart));
rt_store_attr(m, qstr_from_str_static("ADC"), rt_make_function_n(1, pyb_ADC));
rt_store_name(qstr_from_str_static("pyb"), m);
rt_store_name(qstr_from_str_static("open"), rt_make_function_n(2, pyb_io_open));
rt_store_name(MP_QSTR_help, rt_make_function_n(0, pyb_help));
mp_obj_t m = mp_obj_new_module(MP_QSTR_pyb);
rt_store_attr(m, MP_QSTR_info, rt_make_function_n(0, pyb_info));
rt_store_attr(m, MP_QSTR_sd_test, rt_make_function_n(0, pyb_sd_test));
rt_store_attr(m, MP_QSTR_stop, rt_make_function_n(0, pyb_stop));
rt_store_attr(m, MP_QSTR_standby, rt_make_function_n(0, pyb_standby));
rt_store_attr(m, MP_QSTR_source_dir, rt_make_function_n(1, pyb_source_dir));
rt_store_attr(m, MP_QSTR_main, rt_make_function_n(1, pyb_main));
rt_store_attr(m, MP_QSTR_sync, rt_make_function_n(0, pyb_sync));
rt_store_attr(m, MP_QSTR_gc, rt_make_function_n(0, pyb_gc));
rt_store_attr(m, MP_QSTR_delay, rt_make_function_n(1, pyb_delay));
rt_store_attr(m, MP_QSTR_led, rt_make_function_n(1, pyb_led));
rt_store_attr(m, MP_QSTR_switch, (mp_obj_t)&pyb_switch_obj);
rt_store_attr(m, MP_QSTR_servo, rt_make_function_n(2, pyb_servo_set));
rt_store_attr(m, MP_QSTR_pwm, rt_make_function_n(2, pyb_pwm_set));
rt_store_attr(m, MP_QSTR_accel, (mp_obj_t)&pyb_mma_read_obj);
rt_store_attr(m, MP_QSTR_mma_read, (mp_obj_t)&pyb_mma_read_all_obj);
rt_store_attr(m, MP_QSTR_mma_mode, (mp_obj_t)&pyb_mma_write_mode_obj);
rt_store_attr(m, MP_QSTR_hid, rt_make_function_n(1, pyb_hid_send_report));
rt_store_attr(m, MP_QSTR_time, rt_make_function_n(0, pyb_rtc_read));
rt_store_attr(m, MP_QSTR_rand, rt_make_function_n(0, pyb_rng_get));
rt_store_attr(m, MP_QSTR_Led, rt_make_function_n(1, pyb_Led));
rt_store_attr(m, MP_QSTR_Servo, rt_make_function_n(1, pyb_Servo));
rt_store_attr(m, MP_QSTR_I2C, rt_make_function_n(2, pyb_I2C));
rt_store_attr(m, MP_QSTR_gpio, (mp_obj_t)&pyb_gpio_obj);
rt_store_attr(m, MP_QSTR_Usart, rt_make_function_n(2, pyb_Usart));
rt_store_attr(m, MP_QSTR_ADC, rt_make_function_n(1, pyb_ADC));
rt_store_name(MP_QSTR_pyb, m);
rt_store_name(MP_QSTR_open, rt_make_function_n(2, pyb_io_open));
}
// print a message to the LCD
......
......@@ -6,6 +6,7 @@
#include "misc.h"
#include "mpconfig.h"
#include "qstr.h"
#include "systick.h"
#include "obj.h"
#include "runtime.h"
......
#include <stdint.h>
#include <string.h>
#include <stdarg.h>
#include "std.h"
#include "misc.h"
#include "systick.h"
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "lcd.h"
#include "usart.h"
......
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stm32f4xx.h>
#include <stm32f4xx_rcc.h>
#include <stm32f4xx_gpio.h>
......@@ -12,6 +13,7 @@
#include "misc.h"
#include "mpconfig.h"
#include "qstr.h"
#include "systick.h"
#include "nlr.h"
......@@ -58,7 +60,7 @@ mp_obj_t decode_addr(unsigned char *ip, int n_bytes) {
} else if (n_bytes == 32) {
snprintf(data, 64, "%s", ip);
}
return mp_obj_new_str(qstr_from_strn_copy(data, strlen(data)));
return mp_obj_new_str(qstr_from_strn(data, strlen(data)));
}
void decode_addr_and_store(mp_obj_t object, qstr q_attr, unsigned char *ip, int n_bytes) {
......@@ -78,20 +80,20 @@ mp_obj_t pyb_wlan_get_ip(void) {
// if it doesn't already exist, make a new empty class for NetAddress objects
if (net_address_type == MP_OBJ_NULL) {
net_address_type = mp_obj_new_type(qstr_from_str_static("NetAddress"), mp_const_empty_tuple, mp_obj_new_dict(0));
net_address_type = mp_obj_new_type(QSTR_FROM_STR_STATIC("NetAddress"), mp_const_empty_tuple, mp_obj_new_dict(0));
}
// make a new NetAddress object
mp_obj_t net_addr = rt_call_function_0(net_address_type);
// fill the NetAddress object with data
decode_addr_and_store(net_addr, qstr_from_str_static("ip"), &ipconfig.aucIP[0], 4);
decode_addr_and_store(net_addr, qstr_from_str_static("subnet"), &ipconfig.aucSubnetMask[0], 4);
decode_addr_and_store(net_addr, qstr_from_str_static("gateway"), &ipconfig.aucDefaultGateway[0], 4);
decode_addr_and_store(net_addr, qstr_from_str_static("dhcp"), &ipconfig.aucDHCPServer[0], 4);
decode_addr_and_store(net_addr, qstr_from_str_static("dns"), &ipconfig.aucDNSServer[0], 4);
decode_addr_and_store(net_addr, qstr_from_str_static("mac"), &ipconfig.uaMacAddr[0], 6);
decode_addr_and_store(net_addr, qstr_from_str_static("ssid"), &ipconfig.uaSSID[0], 32);
decode_addr_and_store(net_addr, QSTR_FROM_STR_STATIC("ip"), &ipconfig.aucIP[0], 4);
decode_addr_and_store(net_addr, QSTR_FROM_STR_STATIC("subnet"), &ipconfig.aucSubnetMask[0], 4);
decode_addr_and_store(net_addr, QSTR_FROM_STR_STATIC("gateway"), &ipconfig.aucDefaultGateway[0], 4);
decode_addr_and_store(net_addr, QSTR_FROM_STR_STATIC("dhcp"), &ipconfig.aucDHCPServer[0], 4);
decode_addr_and_store(net_addr, QSTR_FROM_STR_STATIC("dns"), &ipconfig.aucDNSServer[0], 4);
decode_addr_and_store(net_addr, QSTR_FROM_STR_STATIC("mac"), &ipconfig.uaMacAddr[0], 6);
decode_addr_and_store(net_addr, QSTR_FROM_STR_STATIC("ssid"), &ipconfig.uaSSID[0], 32);
return net_addr;
}
......@@ -122,12 +124,12 @@ mp_obj_t pyb_wlan_http_get(mp_obj_t host_name, mp_obj_t host_path) {
last_ip = (192 << 24) | (168 << 16) | (0 << 8) | (3);
} else {
if (pyb_wlan_get_host(host_name) == mp_const_none) {
nlr_jump(mp_obj_new_exception_msg(qstr_from_str_static("WlanError"), "unknown host"));
nlr_jump(mp_obj_new_exception_msg(QSTR_FROM_STR_STATIC("WlanError"), "unknown host"));
}
}
int sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sd < 0) {
nlr_jump(mp_obj_new_exception_msg_1_arg(qstr_from_str_static("WlanError"), "socket failed: %d", (void*)sd));
nlr_jump(mp_obj_new_exception_msg_1_arg(QSTR_FROM_STR_STATIC("WlanError"), "socket failed: %d", (void*)sd));
}
//printf("socket seemed to work\n");
//sys_tick_delay_ms(200);
......@@ -138,7 +140,7 @@ mp_obj_t pyb_wlan_http_get(mp_obj_t host_name, mp_obj_t host_path) {
remote.sin_addr.s_addr = htonl(last_ip);
int ret = connect(sd, (sockaddr*)&remote, sizeof(sockaddr));
if (ret != 0) {
nlr_jump(mp_obj_new_exception_msg_1_arg(qstr_from_str_static("WlanError"), "connect failed: %d", (void*)ret));
nlr_jump(mp_obj_new_exception_msg_1_arg(QSTR_FROM_STR_STATIC("WlanError"), "connect failed: %d", (void*)ret));
}
//printf("connect seemed to work\n");
//sys_tick_delay_ms(200);
......@@ -159,7 +161,7 @@ mp_obj_t pyb_wlan_http_get(mp_obj_t host_name, mp_obj_t host_path) {
ret = send(sd, query + sent, strlen(query + sent), 0);
//printf("sent %d bytes\n", ret);
if (ret < 0) {
nlr_jump(mp_obj_new_exception_msg(qstr_from_str_static("WlanError"), "send failed"));
nlr_jump(mp_obj_new_exception_msg(QSTR_FROM_STR_STATIC("WlanError"), "send failed"));
}
sent += ret;
//sys_tick_delay_ms(200);
......@@ -196,12 +198,12 @@ mp_obj_t pyb_wlan_http_get(mp_obj_t host_name, mp_obj_t host_path) {
// read data
ret = recv(sd, buf, 64, 0);
if (ret < 0) {
nlr_jump(mp_obj_new_exception_msg_1_arg(qstr_from_str_static("WlanError"), "recv failed %d", (void*)ret));
nlr_jump(mp_obj_new_exception_msg_1_arg(QSTR_FROM_STR_STATIC("WlanError"), "recv failed %d", (void*)ret));
}
vstr_add_strn(vstr, buf, ret);
}
mp_ret = mp_obj_new_str(qstr_from_str_take(vstr->buf, vstr->alloc));
mp_ret = mp_obj_new_str(qstr_from_strn_take(vstr->buf, vstr->alloc, vstr->len));
}
closesocket(sd);
......@@ -216,7 +218,7 @@ mp_obj_t pyb_wlan_serve(void) {
sys_tick_delay_ms(500);
if (sd < 0) {
printf("socket fail\n");
nlr_jump(mp_obj_new_exception_msg_1_arg(qstr_from_str_static("WlanError"), "socket failed: %d", (void*)sd));
nlr_jump(mp_obj_new_exception_msg_1_arg(QSTR_FROM_STR_STATIC("WlanError"), "socket failed: %d", (void*)sd));
}
/*
......@@ -237,7 +239,7 @@ mp_obj_t pyb_wlan_serve(void) {
sys_tick_delay_ms(100);
if (ret != 0) {
printf("bind fail\n");
nlr_jump(mp_obj_new_exception_msg_1_arg(qstr_from_str_static("WlanError"), "bind failed: %d", (void*)ret));
nlr_jump(mp_obj_new_exception_msg_1_arg(QSTR_FROM_STR_STATIC("WlanError"), "bind failed: %d", (void*)ret));
}
printf("bind seemed to work\n");
......@@ -355,14 +357,14 @@ void pyb_wlan_init(void) {
SpiInit();
wlan_init(CC3000_UsynchCallback, sendWLFWPatch, sendDriverPatch, sendBootLoaderPatch, ReadWlanInterruptPin, WlanInterruptEnable, WlanInterruptDisable, WriteWlanPin);
mp_obj_t m = mp_obj_new_module(qstr_from_str_static("wlan"));
rt_store_attr(m, qstr_from_str_static("connect"), rt_make_function_var(0, pyb_wlan_connect));
rt_store_attr(m, qstr_from_str_static("disconnect"), rt_make_function_n(0, pyb_wlan_disconnect));
rt_store_attr(m, qstr_from_str_static("ip"), rt_make_function_n(0, pyb_wlan_get_ip));
rt_store_attr(m, qstr_from_str_static("get_host"), rt_make_function_n(1, pyb_wlan_get_host));
rt_store_attr(m, qstr_from_str_static("http_get"), rt_make_function_n(2, pyb_wlan_http_get));
rt_store_attr(m, qstr_from_str_static("serve"), rt_make_function_n(0, pyb_wlan_serve));
rt_store_name(qstr_from_str_static("wlan"), m);
mp_obj_t m = mp_obj_new_module(QSTR_FROM_STR_STATIC("wlan"));
rt_store_attr(m, QSTR_FROM_STR_STATIC("connect"), rt_make_function_var(0, pyb_wlan_connect));
rt_store_attr(m, QSTR_FROM_STR_STATIC("disconnect"), rt_make_function_n(0, pyb_wlan_disconnect));
rt_store_attr(m, QSTR_FROM_STR_STATIC("ip"), rt_make_function_n(0, pyb_wlan_get_ip));
rt_store_attr(m, QSTR_FROM_STR_STATIC("get_host"), rt_make_function_n(1, pyb_wlan_get_host));
rt_store_attr(m, QSTR_FROM_STR_STATIC("http_get"), rt_make_function_n(2, pyb_wlan_http_get));
rt_store_attr(m, QSTR_FROM_STR_STATIC("serve"), rt_make_function_n(0, pyb_wlan_serve));
rt_store_name(QSTR_FROM_STR_STATIC("wlan"), m);
}
void pyb_wlan_start(void) {
......
// qstrs specific to this port
Q(help)
Q(pyb)
Q(info)
Q(sd_test)
Q(stop)
Q(standby)
Q(source_dir)
Q(main)
Q(sync)
Q(gc)
Q(delay)
Q(led)
Q(switch)
Q(servo)
Q(pwm)
Q(accel)
Q(mma_read)
Q(mma_mode)
Q(hid)
Q(time)
Q(rand)
Q(Led)
Q(Servo)
Q(I2C)
Q(gpio)
Q(Usart)
Q(ADC)
Q(open)
......@@ -6,6 +6,7 @@
#include "misc.h"
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "servo.h"
......
......@@ -11,7 +11,7 @@ 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 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);
......
......@@ -271,6 +271,7 @@ void TIM6_DAC_IRQHandler(void) {
#include "std.h"
#include "misc.h"
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "led.h"
// EXTI
......
......@@ -4,6 +4,7 @@
#include "misc.h"
#include "systick.h"
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "led.h"
#include "flash.h"
......
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "stm_misc.h"
#include "stm32f4xx_rcc.h"
......@@ -8,6 +9,7 @@
#include "nlr.h"
#include "misc.h"
#include "mpconfig.h"
#include "qstr.h"
#include "parse.h"
#include "obj.h"
#include "runtime.h"
......@@ -71,12 +73,12 @@ void timer_init(void) {
TIM_Cmd(TIM6, ENABLE);
// Python interface
mp_obj_t m = mp_obj_new_module(qstr_from_str_static("timer"));
rt_store_attr(m, qstr_from_str_static("callback"), rt_make_function_n(1, timer_py_set_callback));
rt_store_attr(m, qstr_from_str_static("period"), rt_make_function_n(1, timer_py_set_period));
rt_store_attr(m, qstr_from_str_static("prescaler"), rt_make_function_n(1, timer_py_set_prescaler));
rt_store_attr(m, qstr_from_str_static("value"), rt_make_function_n(0, timer_py_get_value));
rt_store_name(qstr_from_str_static("timer"), m);
mp_obj_t m = mp_obj_new_module(QSTR_FROM_STR_STATIC("timer"));
rt_store_attr(m, QSTR_FROM_STR_STATIC("callback"), rt_make_function_n(1, timer_py_set_callback));
rt_store_attr(m, QSTR_FROM_STR_STATIC("period"), rt_make_function_n(1, timer_py_set_period));
rt_store_attr(m, QSTR_FROM_STR_STATIC("prescaler"), rt_make_function_n(1, timer_py_set_prescaler));
rt_store_attr(m, QSTR_FROM_STR_STATIC("value"), rt_make_function_n(0, timer_py_get_value));
rt_store_name(QSTR_FROM_STR_STATIC("timer"), m);
}
void timer_interrupt(void) {
......
......@@ -5,6 +5,7 @@
#include "misc.h"
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "usart.h"
......
......@@ -6,6 +6,7 @@
#include "misc.h"
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "usrsw.h"
......
......@@ -25,7 +25,7 @@ endif
SRC_C = \
main.c \
OBJ = $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) $(PY_O)
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
LIB =
$(PROG): $(BUILD) $(OBJ)
......
build
py
micropython
*.py
......@@ -2,6 +2,9 @@
PROG = micropython
all: $(PROG)
# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h
# include py core make definitions
include ../py/py.mk
......@@ -27,7 +30,7 @@ SRC_C = \
file.c \
socket.c \
OBJ = $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) $(PY_O)
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
LIB = -lreadline
# the following is needed for BSD
#LIB += -ltermcap
......@@ -40,7 +43,7 @@ ifndef DEBUG
endif
$(Q)size $(PROG)
$(BUILD)/%.o: %.c
$(BUILD)/%.o: %.c $(QSTR_DEFS)
$(ECHO) "CC $<"
$(Q)$(CC) $(CFLAGS) -c -o $@ $<
......
......@@ -6,7 +6,7 @@
#include "nlr.h"
#include "misc.h"
#include "mpconfig.h"
#include "mpqstr.h"
#include "qstr.h"
#include "obj.h"
#include "stream.h"
......
......@@ -6,6 +6,7 @@
#include "nlr.h"
#include "misc.h"
#include "mpconfig.h"
#include "qstr.h"
#include "lexer.h"
#include "lexerunix.h"
#include "parse.h"
......@@ -216,12 +217,12 @@ int main(int argc, char **argv) {
qstr_init();
rt_init();
mp_obj_t m_sys = mp_obj_new_module(qstr_from_str_static("sys"));
mp_obj_t m_sys = mp_obj_new_module(MP_QSTR_sys);
mp_obj_t py_argv = mp_obj_new_list(0, NULL);
rt_store_attr(m_sys, qstr_from_str_static("argv"), py_argv);
rt_store_attr(m_sys, MP_QSTR_argv, py_argv);
rt_store_name(qstr_from_str_static("test"), test_obj_new(42));
rt_store_name(qstr_from_str_static("open"), (mp_obj_t)&mp_builtin_open_obj);
rt_store_name(qstr_from_str("test"), test_obj_new(42));
rt_store_name(MP_QSTR_open, (mp_obj_t)&mp_builtin_open_obj);
rawsocket_init();
// Here is some example code to create a class and instance of that class.
......@@ -232,9 +233,9 @@ int main(int argc, char **argv) {
// test_obj = TestClass()
// test_obj.attr = 42
mp_obj_t test_class_type, test_class_instance;
test_class_type = mp_obj_new_type(qstr_from_str_static("TestClass"), mp_const_empty_tuple, mp_obj_new_dict(0));
rt_store_name(qstr_from_str_static("test_obj"), test_class_instance = rt_call_function_0(test_class_type));
rt_store_attr(test_class_instance, qstr_from_str_static("attr"), mp_obj_new_int(42));
test_class_type = mp_obj_new_type(QSTR_FROM_STR_STATIC("TestClass"), mp_const_empty_tuple, mp_obj_new_dict(0));
rt_store_name(QSTR_FROM_STR_STATIC("test_obj"), test_class_instance = rt_call_function_0(test_class_type));
rt_store_attr(test_class_instance, QSTR_FROM_STR_STATIC("attr"), mp_obj_new_int(42));
/*
printf("bytes:\n");
......@@ -259,7 +260,7 @@ int main(int argc, char **argv) {
}
} else {
for (int i = a; i < argc; i++) {
rt_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_strn_copy(argv[i], strlen(argv[i]))));
rt_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
}
do_file(argv[a]);
break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment