Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > sci.electronics.design > #466049

Re: Hardware scripting (a better Arduino)

From Don Y <blockedofcourse@foo.invalid>
Newsgroups sci.electronics.design
Subject Re: Hardware scripting (a better Arduino)
Date 2017-06-28 14:04 -0700
Organization A noiseless patient Spider
Message-ID <oj15dp$7el$1@dont-email.me> (permalink)
References <LEt4B.72469$9S6.22388@fx02.iad> <BdD4B.56201$bO5.20256@fx16.iad> <eEP4B.94365$AG1.6246@fx42.iad> <oj0q38$vb8$1@dont-email.me> <sRT4B.115428$qL3.75082@fx34.iad>

Show all headers | View raw


On 6/28/2017 12:56 PM, bitrex wrote:
> On 06/28/2017 01:51 PM, Don Y wrote:
> 
>> Exactly.  You use the fetched "bytecode" as an index into a list of
>> function pointers and invoke the function referenced.  To it, you pass
>> a pointer into the "instruction stream" so it can fetch "arguments" from
>> the instruction stream, returning the updated "PC" for use by the next
>> iteration of the interpreter.
>>
>>> You can have foolproof variant types that will happily hold both function 
>>> pointers and data in the same "package", on the same software stack, using a 
>>> custom stack allocator designed as appropriate for the capabilities of the 
>>> hardware. You can have locally scoped lambda functions generated on-the-fly 
>>> at compile time and stored in flash memory that can be templated to accept 
>>> any number of arguments from the stack as is required automatically.
>>
>> "Typing" is something that requires careful thought.  Often, you don't *need*
>> a variety of types:  a numeric type and a string type can cover a lot of
>> applications.  More types inevitably lead to more conversions between types,
>> formatted printing, etc.  My scripting language uses one of each and allows
>> them to "grow", as dictated by the application.
> 
> The C++ solutions available for discriminated unions on x86 platforms are STL 
> containers like boost::variant and boost::any. boost::variant uses function 
> pointers under the hood IIRC, while boost::any uses black magic and is much 
> more generic (and about a thousand times slower.)
> 
> <http://www.boost.org/doc/libs/1_64_0/doc/html/variant.html>
> 
> Functions have never been first-class objects in C++ but with C++11 and some 
> template library stuff they can come pretty close. You can pass them around to 
> other functions by reference or value, hold them in containers, put them on 
> stacks and in queues, whatever.
> 
> I think numeric types should be "strong" and suited to the application, 
> basically classes. Stuff like "int" and "float" are really too broad. Ideally 
> it should never be possible to try to assign the return value of something like 
> a temperature sensor to another type that can hold say complex numbers or 
> floating point values way outside the range of Earthlike temperatures - the 
> compiler should complain.

Again, it depends on the "market" you're trying to address.  I have
ONE numeric type and one string type.  I don't require the user to
set aside buffer space for strings -- there are no buffer overruns
(until you run out of memory and the system ABENDS.)

> That is to say if one has to convert between different types with any 
> regularity it's probably indicative of bad design.

How fine-grained do you approach this?  Do you define a "foot", type
and an "inch" type (derived from "distance")?  And prevent them from
being combined with volumetric types or units of time?  (e.g., miles/hours)

Do you require a cast when using an integer iterator to scale a float?
(pay = hours * wage_rate)

Years ago, I defined a set of classes that let me mix and match
dimensioned quantities.  It was more work than it was worth.

Do you consider printing a numeric value to be a "conversion" operation?
Or, scanning a string representation of a numeric value into a numeric
data type?

>> The advantage, there, is that the user need not be concerned with things
>> like overflow or ordering operations to maximize preserved precision, etc.
>>
>> The disadvantage is that you do a lot *for* them and take away a fair
>> bit of control that they might want to exert on the performance of their
>> code.
>>
>> [It also means you tend to need runtime GC -- which brings up another
>> variable in performance (as well as more implementation decisions)]
> 
> A pure functional language implemented via a stack machine doesn't need a 
> garbage collector, as there's no "garbage" to collect. Downside is you do lose 
> flexibility and performance.

You lose the ability to deal with mutable objects of varying sizes (e.g.,
strings) without forcing the user to do the housekeeping (prone to error).

Likewise, you require all resources to be persistent -- you can't spawn/fork
new tasks/processes and kill off old ones that have served their purposes.

> My gimmick was to try to isolate the mutable state (i.e. when interacting with 
> external widgets through policies written in C++) within APIs that aren't 
> directly accessible as much as possible.
> 
> Indeed I don't think a pure functional language that never had to take any 
> input or provide any output to the real world would require any mutable state 
> at all.
> 
>> As such, the language wants to be intuitive and not necessarily complex,
>> even if this comes at the expense of some functionality (e.g., I can
>> craft far more efficient code if I have hooks into the MTOS, use of pointer
>> variables, etc. -- but this makes the resulting code look less like
>> "generic pseudocode" and more like a particular implementation).
>>
>> Consider the audience (Arduino) and what they're likely to call upon their
>> "boxes" to do.  Will they be scanning raw video from a reflective photodetector
>> to decide barcodes?  Or, accepting decoded barcodes (from something) and
>> manipulating them at some higher level...?
> 
> Who knows exactly, but they usually want to interact with the real world and 
> other external hardware in some way or another. As it stands at the moment they 
> either have to write the "device driver" themselves or hope some implementation 
> provided by the manufacturer works for their implementation.

"In theory", one can lift most drivers from other places and rework them to
fit the specific needs of the application at hand.  The problem lies with
folks who want to pollute the drivers with stuff that doesn't belong there;
usually because of timeliness issues or lack of understanding as to how to
walk and chew gum at the same time.

I.e., a better approach (IMO) is to put in place mechanisms that address
THESE issues as "builtins" -- providing a framework on which to drape the
application.

E.g., even in tiny applications, I support STDIN, STDOUT and STDERR for
each task/process.  So, a developer doesn't have to invent his own
way of getting data into and out-of a process.  Less obvious is this
also magically manages the resource sharing behind the scenes.
So, I can define STDERR to be the "debugger port" and know that
I will see a stream of messages like:
     task0: starting up
     task5: waiting for input
     task3: terminating
    ...
instead of:
     tttask3aas:k5: s...

> In my proposal they have to...write the "device driver" themselves or hope some 
> implementation provided by the manufacturer works in their implementation. 
> Seems the least one could do is try to make the rest of the development process 
> bot just as painful...

I want a language (targeting a particular type of applications) to deal with
the "little crap" that will invariably eat my lunch.

While the developer might pick a suitable size data type for height, width,
length and duration.  But, will the calculations that he has undertaken
ever overflow in the process of computin the final result (volume/unit time)?

While sleep() lets me pause a task/process, it does little to help me if
I want to mark a point in the execution stream and check to see if a particular
interval has expired at some OTHER point in the execution stream.  Or, "signal"
me when that time period expires, regardless of what I might be doing at the
time.

Should I have to take explicit measures to ensure atomic access to complex
variables/structures?

Should I have to understand the mechanisms to spawn (fork/exec) a new task?
And, pass information between it and myself (child/parent)?

Should I have to understand the mechanics of IPC/RPC in order to be able
to invoke a "foreign" process/method?  If these are "optional" uses to which
a language is applied, then it makes sense to put them in an OPTIONAL library.
OTOH, if the language is intended for use in a particular class of
applications, then putting them in a library just makes for a messier
implementation.

I.e., if I a communication channel (a construct used in Limbo/Inferno)
happens to be moved to a remote node in a refactoring, should I have to
rewrite the code that accesses it -- to invoke an RPC instead of just
referencing it "as if" completely local?

Back to sci.electronics.design | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Hardware scripting (a better Arduino) bitrex <bitrex@de.lete.earthlink.net> - 2017-06-27 10:07 -0400
  Re: Hardware scripting (a better Arduino) Rob <nomail@example.com> - 2017-06-27 16:25 +0000
  Re: Hardware scripting (a better Arduino) Don Y <blockedofcourse@foo.invalid> - 2017-06-27 10:12 -0700
  Re: Hardware scripting (a better Arduino) Clifford Heath <no.spam@please.net> - 2017-06-28 11:01 +1000
    Re: Hardware scripting (a better Arduino) bitrex <bitrex@de.lete.earthlink.net> - 2017-06-28 11:08 -0400
      Re: Hardware scripting (a better Arduino) Don Y <blockedofcourse@foo.invalid> - 2017-06-28 10:51 -0700
        Re: Hardware scripting (a better Arduino) bitrex <bitrex@de.lete.earthlink.net> - 2017-06-28 15:56 -0400
          Re: Hardware scripting (a better Arduino) Don Y <blockedofcourse@foo.invalid> - 2017-06-28 14:04 -0700
            Re: Hardware scripting (a better Arduino) Don Y <blockedofcourse@foo.invalid> - 2017-06-28 22:15 -0700
              Re: Hardware scripting (a better Arduino) Don Y <blockedofcourse@foo.invalid> - 2017-06-30 12:23 -0700
          Re: Hardware scripting (a better Arduino) David Brown <david.brown@hesbynett.no> - 2017-06-30 10:43 +0200
        Re: Hardware scripting (a better Arduino) Clifford Heath <no.spam@please.net> - 2017-06-29 09:52 +1000
          Re: Hardware scripting (a better Arduino) Clifford Heath <no.spam@please.net> - 2017-06-30 16:49 +1000
      Re: Hardware scripting (a better Arduino) Clifford Heath <no.spam@please.net> - 2017-06-29 09:42 +1000
  Re: Hardware scripting (a better Arduino) Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-06-28 16:30 +0100
    Re: Hardware scripting (a better Arduino) Clifford Heath <no.spam@please.net> - 2017-06-29 09:55 +1000
  Re: Hardware scripting (a better Arduino) Les Cargill <lcargill99@comcast.com> - 2017-07-02 12:50 -0500

csiph-web