Re: Embedding assembler in a language



On 23 Nov., 11:52, Bart <b...@xxxxxxxxxx> wrote:
On 22 Nov, 07:38, Robbert Haarman <comp.lang.m...@xxxxxxxxxxxxx>
wrote:
On Sun, Nov 22, 2009 at 02:09:33AM +0000, bartc wrote:
The type system is complex, but manages to use a single small
integer to represent
the type of a variant. For single operand codes, this is then used
to index a jump table to get to the specific handler. For dual
operand codes, the two codes have to be converted to a single linear
value, then again a jump table is used. (For non-critical codes then
just switch/case might be used.)

If I understand that correctly, your bytecode basically has some simple
generic functions (to use Common Lisp nomenclature) and you use multiple
dispatch to get to the actual method (again, CL nomenclature) for the types
of value passed at run time.

Yes, about that. Except it can be even more complex that that. In this
source code:

a:=b

In C, that might be just 2 instructions when a,b are both int. But
when they are variants, they can be anything. This assignment involves
freeing resources used by a (which is a recursive process when a is a
list of variants than can be lists...), and duplicating b, since my
language requires a deep copy; another possibly recursive process.

Well. The Seed7 assignment does also a deep copy. For structured
types Seed7 uses also a logic of freeing (possible recursive
depending on the type) and duplicating (possible recursive depending
on the type). But Seed7 also uses some improvement: When the right
hand expression of the assignment is a temporary (which would be
freed afterwards) a simple pointer assignment is done instead of the
duplicating (and the "temporary" is not freed, but used as normal
value). For simpler types like integer, float and others the
assignment is implemented with a simple copy without freeing and
duplicating. BTW: All this things can be decided at compile time.

And in a[i]:=b, there might be 4 types involved: the type of the
array, the type of the element (each element could be a variant and
therefore of different type), the type of i, and the type of b.

I am not a big fan of arrays with mixed type elements. It hinders
debugging and type checks or casts need to be added at many places
(probably every time an array element is accessed). When there is
a demand for an array with mixed type elements it is often possible
that all desired element types can be described with one interface
type (the elements probably need some general handling anyway). In
this case the array has elements of the interface type. There are
also some differences in the logic and implementation of arrays and
hashes (maps) which make it reasonable to keep them apart.

That's why I said the type system was challenging! The language uses
mostly variant types but also allows normal non-variant unboxed ones
for arrays elements and struct members. And a pointer P might point to
a variant containing an int, or directly to an unboxed int...

All this is not much of a big deal, it just makes it harder to write
interpreters with decent performance. And (a note to 'tm') compiling
wouldn't help a great deal.

The predecessor of Seed7 was also highly dynamic (which made
it hard to compile to efficient machine code), but it also had an
compiler. The redesign which resulted in Seed7 was especially done
to allow compilation to efficient code. There is now a static
concept around the dynamic features which makes this combination
possible. So you need to define interface types and interface
functions and the element type of an array must be known at compile
time, but there is multiple dispatch, methods attached to objects
(instead of classes) and types as parameters upon which an elegant
template mechanism is based.

(However, while mainly dynamic, static typing hints can be used to avoid
this second dispatch. This might be considered a cheat..)

In the bytecode? I wouldn't consider that cheating. Why have the dispatch
done at run time when you already know the types at compile time?

The hinting is done in the source code.

What happens when the hints are wrong?

BTW: Is it possible to download a documentation and an
implementation of your language?

As you probably know, the documentation and an implementation of
Seed7 is available.

Greetings Thomas Mertes

Seed7 Homepage: http://seed7.sourceforge.net
Seed7 - The extensible programming language: User defined statements
and operators, abstract data types, templates without special
syntax, OO with interfaces and multiple dispatch, statically typed,
interpreted or compiled, portable, runs under linux/unix/windows.
.



Relevant Pages

  • Re: Array problem
    ... The array that assigning a range to a Variant variable produces is a 1-based 2D array. ... This array will hold the codes for different tasks. ... Dim c As Range ...
    (microsoft.public.excel.programming)
  • Re: Overload assignment operator for an user defined type array with vector scripts
    ... with minimum change to the existing codes. ... Assigning integer or real numbers to vector-scripted array is perfect ... Rewriting the original vector-scripted array assignment ... are vector valued subscripts and are harder to handle. ...
    (comp.lang.fortran)
  • Re: passing a string to a dll
    ... An array is just ... He stores strings into an array; these strings represent valid codes. ... bool IsValidCode(string codeToCheck) ... Putting them in a DLL has effectly zero impact. ...
    (microsoft.public.vc.mfc)
  • RE: Referencing a multifile assembly
    ... >> Codes: ... >> namespace ParentProject ... >> When you had code finish animal.cs, compile it with: ... > csc /t:module animal.cs ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to avoid undesired default values?
    ... I am using "gfortran" to compile my codes. ... If you did know you would not be debugging. ... What do you think of subscript range checking as a debugging feature? ...
    (comp.lang.fortran)