Re: bitwise ops and opcodes

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: bitwise ops and opcodes

Gavin Wraith
<[hidden email]>
<[hidden email]>
 <[hidden email]>
<[hidden email]>
<[hidden email]>
<[hidden email]>
<[hidden email]>
 <[hidden email]>
<[hidden email]>
 <[hidden email]>
In-Reply-To:
<[hidden email]>
X-Organization: Home
User-Agent: Messenger-Pro/1.00c (MsgServe/1.00a) (RISC-OS/5.10) POPstar/2.05
Reply-To: [hidden email]
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii

On the topic of bitwise operations for Lua, RiscLua has had
these for 6 years, initially with Reuben Thomas's bitlib, but
more recently with new infix operators:

& (and), | (or), ^^ (xor), ~ (not), << (lshift), >> (rshift)

For opcodes I simply took the next available ones (after ... ).
The point of this email is to suggest that it might be sensible
for the sake of portability and compatibility if the Lua team
were to reserve a block of opcodes for further expansions of
this kind. People like myself who create extensions - in my
case for a very minor platform - might then be able to register
a subblock of this "user block". The upside is more
bytecode compatibility, the downside that very occasionally
the team would have the burden of registering, or refusing
to register, a subblock. Conceivably there could be pressure
on opcode real estate in the future, and registration would
underline the Lua team's ownership of it.

One more snippet about syntax: RiscLua uses "\" as an
abbreviation for "function" and "=>" as an abbreviation
for "return". This gives the potential for a snappier
Haskell-like syntax, e.g.

curry = \(f)=>\(x)=>\(y)=>f(x,y) end end end

Yes, I know it is out of the Pascal-style tradition of
using words, but I find it very readable. It is an extremely
simple patch to llex.c.

--
Gavin Wraith ([hidden email])
Home page: http://www.wra1th.plus.com/
Reply | Threaded
Open this post in threaded view
|

Re: bitwise ops and opcodes

Eduardo Ochs
Hi Gavin,

> One more snippet about syntax: RiscLua uses "\" as an
> abbreviation for "function" and "=>" as an abbreviation
> for "return". This gives the potential for a snappier
> Haskell-like syntax, e.g.
>
> curry = \(f)=>\(x)=>\(y)=>f(x,y) end end end
>
> Yes, I know it is out of the Pascal-style tradition of
> using words, but I find it very readable. It is an extremely
> simple patch to llex.c.

I've been craving for that for years and I didn't know it.
Can you post the patch to llex.c to the list?
  Cheers,
    Edrx
Reply | Threaded
Open this post in threaded view
|

Re: bitwise ops and opcodes

Gavin Wraith
In reply to this post by Gavin Wraith
<[hidden email]>
<[hidden email]>
In-Reply-To:
<[hidden email]>
X-Organization: Home
User-Agent: Messenger-Pro/1.00c (MsgServe/1.00a) (RISC-OS/5.10) POPstar/2.05
Reply-To: [hidden email]
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii

In message
<[hidden email]> you wrote:


> > One more snippet about syntax: RiscLua uses "\" as an
> > abbreviation for "function" and "=>" as an abbreviation
> > for "return". This gives the potential for a snappier
> > Haskell-like syntax, e.g.
> >
> > curry = \(f)=>\(x)=>\(y)=>f(x,y) end end end
> >
> > Yes, I know it is out of the Pascal-style tradition of
> > using words, but I find it very readable. It is an extremely
> > simple patch to llex.c.
>
> I've been craving for that for years and I didn't know it.
> Can you post the patch to llex.c to the list?

---- diff for llex.c,v 2.19 2006/02/06 18:28:16 roberto

in static int llex (LexState *ls, SemInfo *seminfo) { ...

 Replace, at line 368

--      case '=': {
--        next(ls);
--        if (ls->current != '=') return '=';
--        else { next(ls); return TK_EQ; }
--      }

with

++      case '=': {
++        next(ls);
++        switch(ls->current) {
++         case '=': next(ls); return TK_EQ; break;
++         case '>': next(ls); return TK_RETURN; break;
++         default: return '=';  }
++       }
++      case '\\': {
++        next(ls);
++        return TK_FUNCTION;
++        }
 
--
Gavin Wraith ([hidden email])
Home page: http://www.wra1th.plus.com/