Permalink
Browse files

Merge branch 'replace-ivs-with-iform' into iform

* replace-ivs-with-iform: (41 commits)
  Refine the document for IForm/IVS migration
  Replace make-local-ctx with make-local-ctx~
  Replace make-func-ctx with make-func-ctx~
  Move misc. API to a more proper module
  Remove unused API: rename-local-bindings
  Remove IVS
  ! $CALL -> / Built-in ->: Fix IForm usage
  ! Constants: Use IForm
  ! Implicit function calls: Use IForm
  ! defstmt shorthands: Use IForm
  ! Built-in set!: Use IForm
  ! Built-in function: Use IForm
  ! Built-in for: Use IForm
  ! Built-in let, let*: Use IForm
  ! Variable references: Use IForm
  Built-in cond: Use IForm
  Built-in if (expr): Use IForm
  Built-in comparison operators: Use IForm
  Built-in or, and, +, -, .., *, /, %: Use IForm
  Built-in while: Use IForm
  ...
  • Loading branch information...
kana committed Dec 6, 2011
2 parents b5b606a + 76c7936 commit 078d44b0fdefdc892cd7d245cd4ffe33d4552079
Showing with 504 additions and 789 deletions.
  1. +0 −1 Makefile.in
  2. +66 −63 README.asciidoc
  3. +18 −0 t/compiler-pass-final.t
  4. +30 −97 t/compiler.t
  5. +49 −6 t/context.t
  6. +1 −42 t/iform.t
  7. +0 −116 t/ivs.t
  8. +36 −64 t/macro.t
  9. +42 −0 t/util.t
  10. +0 −1 vim/xire.scm
  11. +132 −206 vim/xire/builtin.scm
  12. +25 −31 vim/xire/compiler.scm
  13. +3 −1 vim/xire/compiler/pass-final.scm
  14. +0 −50 vim/xire/iform.scm
  15. +0 −97 vim/xire/ivs.scm
  16. +102 −14 vim/xire/util.scm
View
@@ -37,7 +37,6 @@ SCMFILES = $(srcdir)/vim/xire.scm \
$(srcdir)/vim/xire/compiler/pass-1.scm \
$(srcdir)/vim/xire/compiler/pass-final.scm \
$(srcdir)/vim/xire/iform.scm \
- $(srcdir)/vim/xire/ivs.scm \
$(srcdir)/vim/xire/util.scm
HEADERS =
View
@@ -132,16 +132,10 @@ expanded into `:if` statement in Vim script can be defined as follows:
[[example_if]]
----
(defstmt if
- [(_ $cond:expr $then:stmt)
- (IVS (S 'if $cond)
- $then
- (S 'endif))]
+ [(_ $cond:qexpr $then:qstmt)
+ `(if ,$cond ,$then (begin))]
[(_ $cond:expr $then:stmt $else:stmt)
- (IVS (S 'if $cond)
- $then
- (S 'else)
- $else
- (S 'endif))])
+ ($if $cond $then $else)])
----
Macros consist of one or more *clauses*. Macro definitions are mostly
@@ -258,7 +252,7 @@ For example, suppose that the form `(if c t e)` is expanded with
-[[ivs]]
+[[iform]]
Intermediate format of Vim script
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -268,68 +262,76 @@ that Xire script is compiled into code in *an intermediate format* of
Vim script, then resulting code in the intermediate format is finally
compiled into Vim script.
-The intermediate format is called *IVS*.
-IVS is written in S expression, and IVS is a list of *nodes*.
-The details of IVS are as follows:
+The intermediate format is called *IForm*.
+An IForm object represents a statement or an expression.
+There are the following functions to create an IForm object:
+FIXME: Add details about naming convensions.
+See `vim.xire.compiler-pass1` at the moment.
-==== Node
-A node expresses a logical part of Vim script.
-The following functions are available to create a node:
+==== Statements
-`(S node-or-atom ...)`::
- Creates a node to express a statement in Vim script.
- For example, `(S 'help 42)` creates a node which corresponds to
- `:help 42` in Vim script.
+`($def gvar expr)`::
+ Represents a statement to define a global variable.
-`(E node-or-atom ...)`::
- Creates a node to express an expression in Vim script.
- For example, `(E Answer (Q "(") (E 42) (Q ")"))` creates a node which
- corresponds to `Answer(42)` in Vim script.
+`($gset gvar expr)`::
+ Represents a statement to modify a global variable.
-`(Q atom ...)`::
- Creates a node to express tokens in Vim script.
- Unlike other functions,
- `Q` is to embed ++atom++s into resulting Vim script.
- Therefore ++atom++s are not converted
- and they are ++display++ed into resulting Vim script.
+`($let lvars stmt)`::
+ Represents a statement to define local variables.
+`($lset lvar expr)`::
+ Represents a statement to modify a local variable.
+`($begin stmts)`::
+ Groups zero or more statements as a single statement.
-==== Atom
+`($if expr then-stmt else-stmt)`::
+ Equivalent to `:if`.
-An atom is roughly corresponding to a "token" in Vim script.
-For example, numbers, strings, variable names and so on.
-Available atoms are as follows:
+`($while expr stmt)`::
+ Equivalent to `:while`.
-`<boolean>` objects::
- Correspond to boolean values in Vim script.
+`($for lvar expr stmt)`::
+ Roughly equivalent to `:for`.
-`<number>` objects::
- Correspond to number values in Vim script. Only
- exact integers are valid. It is an error to use inexact numbers and
- non-integer numbers such as real numbers, though real numbers should
- be supported later. Note that numbers in Vim script are limited in
- a range, and the range depends on how Vim executable is compiled.
- So that Xire does not check whether a given number is also valid as
- Vim script or not.
+`($break)`::
+ Equivalent to `:break`.
-`<regexp>` objects::
- Correspond to equivalent string values in Vim script (because
- there is no literal notation for regular expressions in Vim script).
+`($next)`::
+ Equivalent to `:continue`.
-`<string>` objects::
- Correspond to string values in Vim script. See also
- <<_conventions_of_string_values, conventions of string values>>.
+`($ret expr)`::
+ Equivalent to `:return`.
-`<symbol>` objects::
- Correspond to Ex command names (such as `:map`), variable names
- (such as `v:servername`), and other keywords in Vim script. When
- Vim script is generated from IVS, the names of symbols are
- normalized, then <<_normalization_of_variable_names,normalized
- names>> are embedded into resulting Vim script.
+`($func func-name args stmt)`::
+ Roughly equivalent to `:function`.
+
+`($ex obj-or-iforms)`::
+ Represents an arbitrary statement.
+
+
+
+==== Expressions
+
+`($const obj)`::
+ Represents a constant expression.
+ `obj` can be a boolean, a number, a regular expression or a string.
+
+`($gref gvar)`::
+ Represents a global variable reference.
+
+`($lref lvar)`::
+ Represents a global variable reference.
+
+`($call subr-name arg-exprs)`::
+ Represents a compound expression using an operator such as `+`.
+ See also `vim.xire.compiler.pass-final`.
+
+`($call func-expr arg-exprs)`::
+ Represents a function call.
@@ -401,10 +403,10 @@ in Xire script:
While various characters such as `$`, `!` and `%` can be used as
variable names in Scheme, variable names in Vim script must match to
`#/^[A-Za-z_][A-Za-z_0-9]*$/`. So that it is generally an error to use
-such characters for symbols in <<ivs,IVS>>.
+such characters for symbols in <<iform,IForm>>.
But, for convenience, several characters (more precisely, patterns) can
-be used for symbols in IVS.
+be used for symbols in IForm.
[options='header']
|==================================================================
@@ -465,7 +467,7 @@ There are also the following shorthands for `defstmt`:
(defstmt <name>
[(_)
- (IVS (S '<ex-command-name>))]) ; <ex-command-name> must be a symbol.
+ ($ex '(<ex-command-name>))]) ; <ex-command-name> must be a symbol.
@@ -488,7 +490,7 @@ The following Scheme API is available to define advanced Xire macros:
==== `(scheme-object->vim-script-notation x)`
A function which converts a given Scheme object into the corresponding
-Vim script notation. See also <<ivs,IVS>>.
+Vim script notation. See also <<iform,IForm>>.
@@ -504,9 +506,9 @@ according to other arguments:
`manyp`::
A boolean value which specifies the format of `form-or-forms`.
If this value is `#f`, `form-or-forms` is treated as a form,
- and this function returns a resulting Vim script in IVS.
+ and this function returns a resulting Vim script in IForm.
Otherwise, `form-or-forms` is treated as a list of forms,
- and this function returns a list of resulting Vim script in IVS.
+ and this function returns a list of resulting Vim script in IForm.
`type`::
A symbol which specifies the type of `form`. If this value is:
@@ -543,7 +545,8 @@ according to other arguments:
Built-in macros
~~~~~~~~~~~~~~~
-FIXME: Write about details of macros.
+See `vim.xire.builtin` at the moment.
+FIXME: Write about details of built-in macros.
View
@@ -7,6 +7,7 @@
(use text.tree)
(use vim.xire.compiler.pass-final)
(use vim.xire.iform)
+(use vim.xire.util)
@@ -221,6 +222,23 @@
'name)))
raise? <error>) ; Non-iform arguments.
)
+ (it "should generate a valid code from $CALL of the built-in 'kbd'"
+ (expect (gen ($call 'kbd
+ (list "foo")))
+ equal? "\"foo\"")
+ (expect (gen ($call 'kbd
+ (list "\"*p")))
+ equal? "\"\\\"*p\"")
+ (expect (gen ($call 'kbd
+ (list "bar<BS>z")))
+ equal? "\"bar\\<BS>z\"")
+ (expect (gen ($call 'kbd
+ (list 1)))
+ raise? <error>) ; Invalid argument.
+ (expect (gen ($call 'kbd
+ 1))
+ raise? <error>) ; Invalid argument.
+ )
(it "should generate a valid code from $CALL of the built-in 'list'"
(expect (gen ($call 'list
(list)))
Oops, something went wrong.

0 comments on commit 078d44b

Please sign in to comment.