-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


[ ] Emacs Lisp'

, 18 2017 . 12:29 +

image


- Emacs Lisp'? Emacs .


:


  • , Emacs Go;
  • Go Emacs Lisp;
  • ;

Emacs', , .


work in progress , Go Emacs Lisp.


Emacs Go


, Emacs Lisp "", "design tradeoffs". "" "" , . , , , . .


, Go. Go ?
:


  1. Emacs Go . go-emacs.
  2. ( ) Go, Emacs C , eval .
  3. Go Emacs Lisp -.

, "" , (3). , Emacs Lisp.


, , , :


  • Emacs Lisp Go ;
  • FFI . Emacs Go ;
  • ( Emacs );

- Emacs', Chris Wellons.


Go?


Go .


- . :


  • ;
  • ;
  • runtime;
  • Tooling;

, , :


  • Go - (.. Scheme);
  • ;


go/* Go.


parser, typechecker frontend' . 20 AST .


, , . go/types .


. 90% : " AST - Emacs'".


.


API , . go/ast go/types; (-, , ).


import' ( ast.GenDecl).


, , " ". , , ( , ).



, (~80%) . Go , .


:


  1. . ;
  2. Effective Go. ;

runtime


, , .


, , Emacs Lisp .


Tooling


, , .


Go , IDE , . , Go gofmt. go/types,
go/build go/*.


Sublime text, Emacs, Visual Studio Code , (), gorename, import'. company-elisp .


Emacs Lisp 1000 . Emacs Go , Emacs Lisp.


Emacs Go


, Go Emacs'. ?



Lisp , , , .


int, float64, string - . Go, Emacs Lisp .


, (symbol) (uintX).


  • (, Emacs Lisp);
  • opaque ;
  • ;

, " ", Emacs Lisp , lisp.Object. lisp.Object: .


Go slices

: Go "" std::vector C++, subslice .


{data, len, cap}.
data , len cap . improper list, nil, :
(cons data (cons len cap))


, ?

, : , .


( ). 2-3 . , . data , .


N=4 , , => , , .


: Emacs', . .


slice-get/slice-set . aset/aget, car data.


, subslice?


C data , . , 0-based. , offset:
(cons data (cons offset (cons len cap)))


slice-get/slice-set offset.


- slice-get.


;;  
 ;; [vector]
  ;; [vector index]
aref     ;; [elem]

;; Slice  offset (  subslice)
 ;; [slice]
car     ;; [data]
 ;; [data index]
aref    ;; [elem]

;; Slice   subslice
     ;; [slice]
dup         ;; [slice slice] (1)
car         ;; [slice data]
stack-ref 1 ;; [slice data slice]
cdr         ;; [slice data slice.cdr]
car         ;; [slice data offset]
     ;; [slice data offset index]
plus        ;; [slice data real-index]
aref        ;; [slice elem]
stack-set 1 ;; [elem] (2)

;; (1)      , 
;;   .

;; (2)       
;;  slice  . 

, ( stack-ref, call ). .


Opaque types

/ Go . lisp.Object, lisp.Symbol lisp.Number.


opaque . .


type Symbol interface {
    symbol()
}

type Object interface {
    object()
    //  ...
}

//       -.

// Intern returns the canonical symbol with specified name.
func Intern(name string) Symbol

Intern -. intrinsic .


, API, , , Go.


lisp.Object

lisp.Object " ", interface{}?


, interface{} Go , , "".


, , Emacs' " " . lisp.Object unboxed Emacs Lisp ,
.


, lisp.Object , .


type Object interface {
    object()

    Int() int
    Float() float64
    String() string
    // ... etc.

    //     :
    IsInt() bool                //    
    GetInt() (val int, ok bool) //  "comma, ok"-style 
    // ...    .
}

. lisp.Object , panic. - API reflect.Value, ?


Emacs Lisp Go


, , , lisp.Object.


pair := lisp.Call("cons", 1, "2")
a, b := lisp.Call("car", pair), lisp.Call("cdr", pair)
lisp.Call("insert", "Hello, Emacs!")
sum := lisp.Call("+", 1, 2).Int()

, , .


part := "c"
lisp.Insert("Hello, Emacs!")     //  void
s := lisp.Concat("a", "b", part) //  string,  ...string

FFI DSL

DSL .


;;   ,   FFI.
(ffi-declare
 (concat Concat (:string &parts) :string)
 (message Message (:string format :any &args) :string)
 (insert Insert (:any &args) :void)
 (+ IntAdd (:int &xs) :int))

;;  , ,  Go .

Go . - , Lisp .


// IntAdd - ... <  +  Emacs>
//$GO-ffi:+
func IntAdd(xs ...int) int

// ...  

Emacs' documentation. docstrings.


Go Emacs Lisp


Emacs Lisp , Go .


, , :


package "foo" func "f"       => "$GO-foo.f"
package "foo/bar" func "f"   => "$GO-foo/bar.g"
package "foo" func (typ) "m" => "$GO-foo.typ.m"
package "foo" var "v"        => "$GO-foo.v"

, , Go ( , ). $GO Emacs .



Bytecode lapcode?


:


  1. Emacs Lisp (source-to-source compilation)
  2. Bytecode
  3. Lapcode (Lisp Assembly Program)

, return statement, goto ( Go).


.


  • Bytecode , ;
  • Lapcode ;

Emacs' lapcode .
lapcode, ,
Emacs .


lapcode

Lisp assembly program Emacs' (IR). , -.


"" - , .


. , Emacs Lisp' ( ).



Go, "" Emacs VM Emacs Lisp.


?


Emacs Lisp scoping . "emacs/lisp/emacs-lisp/byte-opt.el", ; - , .


Emacs Lisp . , defconstant , , defvar. Go , .


Go , Emacs Lisp . , .



Go, / Emacs VM.


.


Emacs Lisp:


  • (string, vector, list/cons)
  • - (integer float)

.
int float
.


, =,
.


number cons, ,
, ,
, cons.


boxed ( cons),
.
car .


cons : &x != &x,
(eq (cons x nil) (cons x nil)) .


.
.


Seems like Go-ism inside Emacs


goism , Go Emacs Lisp -.


, lapcode Go.
emacs/rt , goism.


goism ,
,
(guick start guide ).


, ? : , - , .


, - .

Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/331134/

:  

: [1] []
 

:
: 

: ( )

:

  URL