用于微控制器的python [英] python for microcontrollers

查看:59
本文介绍了用于微控制器的python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在解决为PIC 18Fxxx微控制器实现python汇编程序的问题,并认为我'在我在

实施中嵌入太多错误之前,公开打开

来获取建议。


简单的部分是通过compiler.ast得到ast。一旦数据模型得以解决,也很容易生成代码。


困难的部分是从丰富的高级python现实映射到<这是稀疏的8位微控制器的现实。


我看了pyastra,但它对我的情况有致命的问题:

- 没有18fxxx设备的后端

- 只支持8位整数


我正在从第四个运行时引擎中删除一些部分
我之前写的
编译器,增加了对8-32位整数,浮点数和

a双栈环境的支持,为本地

变量提供了舒适的支持/函数参数,以及支持更简单和更多的b $ b紧凑代码生成。


Python是关于隐式和动态创建/销毁的

来自堆的任意类型的对象。我有一个非常紧凑的

malloc / free,并且可以制作一个引用计划,但是将这个用于

像int这样的核心类型会破坏性能。芯片已经'

努力做10个mips。


到目前为止,我想出的最好的想法是使用

标识符结尾指定类型,例如:

- foo_i16 - 签名16位

- foo_u32 - 无符号32位

- bar_f - 24位浮点数

- 等等 - 如果标识符没有''魔术结尾'',它将被视为
被视为还要签署16位


,一些虚函数uint16(),int16(),uint32(),int32(),

float()等,类似于C转换和类型转换,所以我在编译时不必为类型推断而烦恼。


是的,这种做法很糟糕。但任何人都可以提供任何建议吗

吸少吗?


-

干杯

EB


-

20岁以后不保守的人没有大脑。

一个人是谁40岁以下没有自由主义者没有心。

Hi all,

I''m currently tackling the problem of implementing a python to assembler
compiler for PIC 18Fxxx microcontrollers, and thought I''d open it up
publicly for suggestions before I embed too many mistakes in the
implementation.

The easy part is getting the ast, via compiler.ast. Also easy is
generating the code, once the data models are worked out.

The hard part is mapping from the abundant high-level python reality to
the sparse 8-bit microcontroller reality.

I looked at pyastra, but it has fatal problems for my situation:
- no backend for 18fxxx devices
- only 8-bit ints supported

I''m presently ripping some parts from the runtime engine of a forth
compiler I wrote earlier, to add support for 8-32 bit ints, floats, and
a dual-stack environment that offers comfortable support for local
variables/function parameters, as well as support for simpler and more
compact code generation.

Python is all about implicitly and dynamically creating/destroying
arbitrarily typed objects from a heap. I''ve got a very compact
malloc/free, and could cook up a refcounting scheme, but using this for
core types like ints would destroy performance, on a chip that''s already
struggling to do 10 mips.

The best idea I''ve come up with so far is to use a convention of
identifier endings to specify type, eg:
- foo_i16 - signed 16-bit
- foo_u32 - unsigned 32-bit
- bar_f - 24-bit float
- blah - if an identifier doesn''t have a ''magic ending'', it will
be deemed to be signed 16-bit

also, some virtual functions uint16(), int16(), uint32(), int32(),
float() etc, which work similar to C casting and type conversion, so I
don''t have to struggle with type inference at compile time.

Yes, this approach sucks. But can anyone offer any suggestions which
suck less?

--
Cheers
EB

--

One who is not a conservative by age 20 has no brain.
One who is not a liberal by age 40 has no heart.

推荐答案

Evil Bastard写道:
Evil Bastard wrote:
我正在解决这个问题为PIC 18Fxxx微控制器实现python到汇编程序编译器的问题
I''m currently tackling the problem of implementing a python to assembler
compiler for PIC 18Fxxx microcontrollers




(加上类型信息等)并发出C,然后编译。

-

Benji York



Perhaps porting Pyrex would be easier. Pyrex takes a python-like syntax
(plus type information, etc.) and emits C, which is then compiled.
--
Benji York


Benji York写道:
Benji York wrote:
也许搬运Pyrex会更容易。 Pyrex采用类似python的语法
(加上类型信息等)并发出C,然后编译。
Perhaps porting Pyrex would be easier. Pyrex takes a python-like syntax
(plus type information, etc.) and emits C, which is then compiled.




Pyrex完全摇滚。但是对于PIC目标,没有办法可以做到:

- pyrex生成**很多代码,这大量使用了

python-C api,与动态物体密不可分

- PIC程序存储器最大32k字节

非常感谢。


还有其他建议吗?


-

干杯

EB


-


20岁以后不保守的人没有大脑。

40岁以后不自由的人没有心。



Pyrex totally rocks. But for the PIC targetting, no can do:
- pyrex generates a **LOT** of code, which makes extensive use of the
python-C api, which is inextricably tied to dynamic objects
- PIC program memory is 32kbytes max

Thanks all the same.

Any other suggestions?

--
Cheers
EB

--

One who is not a conservative by age 20 has no brain.
One who is not a liberal by age 40 has no heart.


Evil Bastard写道:
Evil Bastard wrote:
Benji York写道:
Benji York wrote:
也许移植Pyrex会更容易。
Perhaps porting Pyrex would be easier.


耐热玻璃完全晃动。但对于PIC目标,没有办法可以:
....还有其他建议吗?

Pyrex totally rocks. But for the PIC targetting, no can do: .... Any other suggestions?




是的,请改用Lua端口。 Lua几乎是为这种

应用而设计的,可能是Pythonic。足以提供你试图通过使用Python获得的任何优惠
优势

实际上是Python。


FWIW ,解释器/虚拟机似乎被设计为非常保守的内存,尽管有可能它有点与

有32位整数可用(但也许很容易被移植到

一些怪异的12位微控制器:-))。


-Peter



Yes, port Lua instead. Lua is pretty much designed for this sort of
application, and is probably "Pythonic" enough to provide whatever
advantages you were trying to get from using Python, short of it
actually being Python.

FWIW, the interpreter/virtual machine appears to be designed to be very
conservative with memory, though there''s a chance it is somewhat tied to
having 32-bit integers available (yet could perhaps be ported easily to
some freaky 12-bit microcontroller anyway :-) ).

-Peter


这篇关于用于微控制器的python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆