functions = functions.Cons (sym, func);
}
- internal void Defun (MSymbol sym, MPlist args, MPlist body)
+ public void Defun (MSymbol sym, MPlist args, MPlist body)
{
Function func = new Function (sym, args, body, this);
return func;
}
+ public bool CopyFunc (MSymbol name, Domain domain)
+ {
+ Function func = (Function) functions.Get (name);
+ if (func == null)
+ return false;
+ domain.functions = domain.functions.Cons (name, func);
+ return true;
+ }
+
+ public void CopyFunc (Domain domain)
+ {
+ foreach (MPlist p in functions)
+ domain.functions = domain.functions.Cons (p.key, p.val);
+ }
+
public object GetValue (MSymbol name)
{
MPlist slot = bindings.Find (name);
len = body.Count;
this.body = new MExpression[len];
for (int i = 0; ! body.IsEmpty; i++, body = body.next)
- this.body[i] = new MExpression (body.key, body.val, domain);
+ {
+ domain.Translate (body);
+ this.body[i] = new MExpression (body.key, body.val, domain);
+ }
}
}
static Function ()
{
ignore = new Function ();
- varref = new Function (Mvarref, new Evaluator (get_value), 1, 1, true);
- block = new Function (Mprogn, new Evaluator (progn), 0, -1, true);
+ varref = new Function (Mvarref, get_value, 1, 1, true);
+ block = new Function (Mprogn, progn, 0, -1, true);
}
private static object get_value (MExpression[] args, Domain domain)
{
basic = new Domain ();
- basic.Defun ("set", new Evaluator (set_value), 2, 2, true);
- basic.Defun ("=", new Evaluator (set_value), 2, 2, true);
- basic.Defun ("+", new Evaluator (plus), 2, -1, false);
- basic.Defun ("*", new Evaluator (multi), 2, -1, false);
- basic.Defun ("-", new Evaluator (minus), 1, -1, false);
- basic.Defun ("/", new Evaluator (divide), 2, -1, false);
- basic.Defun ("%", new Evaluator (percent), 2, -1, false);
- basic.Defun ("|", new Evaluator (logior), 2, -1, false);
- basic.Defun ("&", new Evaluator (logand), 2, -1, false);
- basic.Defun ("+=", new Evaluator (pluseq), 2, -1, true);
- basic.Defun ("*=", new Evaluator (multieq), 2, -1, true);
- basic.Defun ("-=", new Evaluator (minuseq), 2, -1, true);
- basic.Defun ("/=", new Evaluator (divideeq), 2, -1, true);
- basic.Defun ("%=", new Evaluator (percenteq), 2, -1, true);
- basic.Defun ("|=", new Evaluator (logioreq), 2, -1, true);
- basic.Defun ("&=", new Evaluator (logandeq), 2, -1, true);
- basic.Defun ("<<", new Evaluator (lshift), 2, 2, false);
- basic.Defun (">>", new Evaluator (rshift), 2, 2, false);
- basic.Defun ("<<=", new Evaluator (lshifteq), 2, 2, true);
- basic.Defun (">>=", new Evaluator (rshifteq), 2, 2, true);
- basic.Defun ("==", new Evaluator (eq), 2, -1, false);
- basic.Defun ("!=", new Evaluator (noteq), 2, 2, false);
- basic.Defun ("<", new Evaluator (less), 2, -1, false);
- basic.Defun ("<=", new Evaluator (lesseq), 2, -1, false);
- basic.Defun (">", new Evaluator (more), 2, -1, false);
- basic.Defun (">=", new Evaluator (moreeq), 2, -1, false);
- basic.Defun ("progn", new Evaluator (progn), 0, -1, true);
- basic.Defun ("if", new Evaluator (ifclause), 2, -1, true);
- basic.Defun ("when", new Evaluator (whenclause), 2, -1, true);
- basic.Defun ("while", new Evaluator (whileclause), 1, -1, true);
+ basic.Defun ("set", set_value, 2, 2, true);
+ basic.Defun ("=", set_value, 2, 2, true);
+ basic.Defun ("+", plus, 2, -1, false);
+ basic.Defun ("*", multi, 2, -1, false);
+ basic.Defun ("-", minus, 1, -1, false);
+ basic.Defun ("/", divide, 2, -1, false);
+ basic.Defun ("%", percent, 2, -1, false);
+ basic.Defun ("|", logior, 2, -1, false);
+ basic.Defun ("&", logand, 2, -1, false);
+ basic.Defun ("+=", pluseq, 2, -1, true);
+ basic.Defun ("*=", multieq, 2, -1, true);
+ basic.Defun ("-=", minuseq, 2, -1, true);
+ basic.Defun ("/=", divideeq, 2, -1, true);
+ basic.Defun ("%=", percenteq, 2, -1, true);
+ basic.Defun ("|=", logioreq, 2, -1, true);
+ basic.Defun ("&=", logandeq, 2, -1, true);
+ basic.Defun ("<<", lshift, 2, 2, false);
+ basic.Defun (">>", rshift, 2, 2, false);
+ basic.Defun ("<<=", lshifteq, 2, 2, true);
+ basic.Defun (">>=", rshifteq, 2, 2, true);
+ basic.Defun ("==", eq, 2, -1, false);
+ basic.Defun ("!=", noteq, 2, 2, false);
+ basic.Defun ("<", less, 2, -1, false);
+ basic.Defun ("<=", lesseq, 2, -1, false);
+ basic.Defun (">", more, 2, -1, false);
+ basic.Defun (">=", moreeq, 2, -1, false);
+ basic.Defun ("progn", progn, 0, -1, true);
+ basic.Defun ("if", ifclause, 2, -1, true);
+ basic.Defun ("when", whenclause, 2, -1, true);
+ basic.Defun ("while", whileclause, 1, -1, true);
basic.AddTranslator (new Translator (translate_cond));
}
private MExpression[] args;
private object val;
+ public MExpression[] Args { get { return args; } }
+ public object Val { get { return val; } }
+
private MExpression (object val)
{
this.val = val;
+ sym + " " + nargs);
args = new MExpression[nargs];
for (int i = 0; i < nargs; i++, p = p.next)
- args[i] = new MExpression (p.key, p.val, domain);
+ {
+ domain.Translate (p);
+ args[i] = new MExpression (p.key, p.val, domain);
+ }
}
}
else
{
function = Function.block;
args = new MExpression[plist.Count];
- domain.Translate (plist);
for (int i = 0; ! plist.IsEmpty; i++, plist = plist.next)
- args[i] = new MExpression (plist.key, plist.val, domain);
+ {
+ domain.Translate (plist);
+ args[i] = new MExpression (plist.key, plist.val, domain);
+ }
}
- public object Val { get { return val; } }
-
public object Eval (Domain domain)
{
if (function == null)
public class MInputMethod
{
internal static MExpression.Domain domain = new MExpression.Domain (null);
+ internal MExpression.Domain local_domain;
private static MSymbol Minput_method = MSymbol.Of ("input-method");
private static MSymbol Mdescription = MSymbol.Of ("description");
private static MSymbol Mat_open_square_bracket = MSymbol.Of ("@[");
private static MSymbol Mat_close_square_bracket = MSymbol.Of ("@]");
private static MSymbol Minsert = MSymbol.Of ("insert");
+ private static MSymbol Mdelete = MSymbol.Of ("delete");
+ private static MSymbol Mmove = MSymbol.Of ("move");
+ private static MSymbol Mmark = MSymbol.Of ("mark");
+ private static MSymbol Mmarker = MSymbol.Of ("marker");
+ private static MSymbol Madd = MSymbol.Of ("add");
+ private static MSymbol Msub = MSymbol.Of ("sub");
+ private static MSymbol Mmul = MSymbol.Of ("mul");
+ private static MSymbol Mdiv = MSymbol.Of ("div");
+ private static MSymbol Mif = MSymbol.Of ("if");
+ private static MSymbol Mcond = MSymbol.Of ("cond");
+ private static MSymbol Mchar_at = MSymbol.Of ("char-at");
internal class Variable
{
static MInputMethod ()
{
- domain.Defun ("insert", new MExpression.Evaluator (insert), 1, 1);
- domain.Defun ("candidates", new MExpression.Evaluator (insert_candidates),
- 1, 1);
- domain.Defun ("delete", new MExpression.Evaluator (delete), 1, 1);
- domain.Defun ("select", new MExpression.Evaluator (select), 1, 1);
- domain.Defun ("show", new MExpression.Evaluator (show), 0, 0);
- domain.Defun ("hide", new MExpression.Evaluator (hide), 0, 0);
- domain.Defun ("move", new MExpression.Evaluator (move), 1, 1);
- domain.Defun ("mark", new MExpression.Evaluator (mark), 1, 1);
- domain.Defun ("pushback", new MExpression.Evaluator (pushback), 1, 1);
- domain.Defun ("pop", new MExpression.Evaluator (pop), 0, 0);
- domain.Defun ("undo", new MExpression.Evaluator (undo), 0, 1);
- domain.Defun ("commit", new MExpression.Evaluator (commit), 0, 0);
- domain.Defun ("unhandle", new MExpression.Evaluator (unhandle), 0, 0);
- domain.Defun ("shift", new MExpression.Evaluator (shift), 1, 1);
- domain.Defun ("call", new MExpression.Evaluator (call), 2, -1);
+ domain.Defun ("insert", insert, 1, 1);
+ domain.Defun ("candidates", insert_candidates, 1, 1);
+ domain.Defun ("delete", delete, 1, 1);
+ domain.Defun ("select", select, 1, 1);
+ domain.Defun ("show", show, 0, 0);
+ domain.Defun ("hide", hide, 0, 0);
+ domain.Defun ("move", move, 1, 1);
+ domain.Defun ("mark", mark, 1, 1);
+ domain.Defun ("pushback", pushback, 1, 1);
+ domain.Defun ("pop", pop, 0, 0);
+ domain.Defun ("undo", undo, 0, 1);
+ domain.Defun ("commit", commit, 0, 0);
+ domain.Defun ("unhandle", unhandle, 0, 0);
+ domain.Defun ("shift", shift, 1, 1);
+ domain.Defun ("call", call, 2, -1);
+ domain.Defun ("marker", marker, 1, 1, true);
+ domain.Defun ("char-at", char_at, 1, 1, true);
}
private MInputMethod (MDatabase.Tag tag)
language = tag[1];
name = tag[2];
subname = tag[3];
+ local_domain = new MExpression.Domain (domain, null);
+
MPlist plist = (MPlist) mdb.Load ();
if (plist == null)
return;
}
}
+ private static void transform (MPlist plist)
+ {
+ for (; ! plist.IsEmpty; plist = plist.next)
+ {
+ if (plist.IsMText)
+ {
+ MPlist p = new MPlist ();
+ p.Add (MSymbol.symbol, Minsert);
+ p.Add (MSymbol.mtext, plist.Text);
+ plist.Set (MSymbol.plist, p);
+ }
+ else if (plist.IsInteger)
+ {
+ MPlist p = new MPlist ();
+ p.Add (MSymbol.symbol, Minsert);
+ p.Add (MSymbol.integer, plist.Integer);
+ plist.Set (MSymbol.plist, p);
+ }
+ else if (plist.IsPlist)
+ {
+ MPlist pl = plist.Plist;
+
+ if (pl.IsSymbol)
+ {
+ if (pl.Symbol == Madd)
+ pl.Set (MSymbol.symbol, MSymbol.Of ("+="));
+ else if (pl.Symbol == Msub)
+ pl.Set (MSymbol.symbol, MSymbol.Of ("-="));
+ else if (pl.Symbol == Mmul)
+ pl.Set (MSymbol.symbol, MSymbol.Of ("*="));
+ else if (pl.Symbol == Mdiv)
+ pl.Set (MSymbol.symbol, MSymbol.Of ("/="));
+ else if (pl.Symbol == Minsert)
+ {
+ // (insert (CANDIDATES ...))
+ // => (candidates CANDIDATES ...)
+ if (pl.next.IsPlist)
+ {
+ pl.Set (MSymbol.symbol, Mcandidates);
+ pl = pl.next;
+ MPlist p = pl.Plist;
+ pl.Set (p.key, p.val);
+ for (p = p.next; ! p.IsEmpty; p = p.next);
+ pl.Add (p.key, p.val);
+ }
+ }
+ else if (pl.Symbol == Mif)
+ {
+ pl = pl.next;
+ if (! pl.IsEmpty)
+ transform (pl.next);
+ }
+ else if (pl.Symbol == Mcond)
+ {
+ for (pl = pl.next; ! pl.IsEmpty; pl = pl.next)
+ if (pl.IsPlist)
+ {
+ MPlist p = pl.Plist;
+
+ if (p.IsPlist)
+ transform (p);
+ else
+ transform (p.next);
+ }
+ }
+ else if (pl.Symbol == Mdelete
+ || pl.Symbol == Mmove
+ || pl.Symbol == Mmark)
+ {
+ pl = pl.next;
+ if (pl.IsSymbol)
+ {
+ MSymbol sym = pl.Symbol;
+ MPlist p = new MPlist ();
+ p.Add (MSymbol.symbol, Mmarker);
+ p.Add (MSymbol.symbol, sym);
+ pl.Set (MSymbol.plist, p);
+ }
+ }
+ else if (pl.Symbol == Mstate)
+ {
+ pl = pl.next;
+ if (pl.IsSymbol)
+ {
+ MSymbol sym = pl.Symbol;
+ MPlist p = new MPlist ();
+ p.Add (MSymbol.symbol, Mstate);
+ p.Add (MSymbol.symbol, sym);
+ pl.Set (MSymbol.plist, p);
+ }
+ }
+ }
+ else if (pl.IsMText)
+ {
+ // (CANDIDATES ...) => (candidates CANDIDATES ...)
+ pl.Push (MSymbol.symbol, Mcandidates);
+ }
+ }
+ else if (plist.IsSymbol)
+ {
+ MSymbol sym = plist.Symbol;
+
+ if (sym.Name[0] == '@')
+ {
+ MPlist p = new MPlist ();
+ p.Add (MSymbol.symbol, Mchar_at);
+ p.Add (MSymbol.symbol, sym);
+ plist.Set (MSymbol.plist, p);
+ }
+ }
+ }
+ }
+
private static MText parse_description (MPlist plist)
{
return (plist.IsMText ? plist.Text
if (target_type == Mmacro)
{
if (target_name == MSymbol.nil)
- im.domain.Copy (local_table);
+ im.local_domain.CopyFunc (local_domain);
else
- im.local_table.Copy (target_name, local_table);
+ im.local_domain.CopyFunc (target_name, local_domain);
}
else if (target_type == Mmap)
{
if (! pl.IsSymbol)
continue;
- MSymbol name = pl.Symbol;
- MExpression expr = new MExpression (pl.next, local_table);
- MExpression.Defmacro (local_table, name, expr);
+ transform (pl.next);
+ local_domain.Defun (pl.Symbol, new MPlist (), pl.next);
}
}
p = p.next;
if (p.IsEmpty)
continue;
- MExpression expr = new MExpression (p, local_table);
+ transform (p);
+ MExpression expr = new MExpression (p, local_domain);
map.Add (keys, 0, expr);
}
}
continue;
MSymbol map_name = p.Symbol;
p = p.next;
- state.branches[map_name] = new MExpression (p, local_table);
+ transform (p);
+ state.branches[map_name] = new MExpression (p, local_domain);
}
}
}
MExpression.Domain domain)
{
MInputContext ic = (MInputContext) domain.context;
- object arg = args[0].val;
+ object arg = args[0].Val;
if (arg is int)
preedit_replace (ic, ic.cursor_pos, ic.cursor_pos, (int) arg);
MExpression.Domain domain)
{
MInputContext ic = (MInputContext) domain.context;
- MPlist list = (MPlist) args[0];
+ MPlist list = (MPlist) args[0].Val;
int column = 0;
if (domain.IsBound (Mcandidates_group_size))
return 1;
}
+ private static object state (MExpression[] args,
+ MExpression.Domain domain)
+ {
+ MInputContext ic = (MInputContext) domain.context;
+ MSymbol sym = (MSymbol) args[0].Args[0].Val;
+
+ if (sym == MSymbol.t)
+ return MSymbol.t;
+ return ic.im.states[sym];
+ }
+
+ private static object marker (MExpression[] args,
+ MExpression.Domain domain)
+ {
+ MInputContext ic = (MInputContext) domain.context;
+ MSymbol sym = (MSymbol) args[0].Args[0].Val;
+ int pos = ic.cursor_pos;
+
+ if (sym.Name.Length == 2 && sym.Name[0] == '@')
+ {
+ switch (sym.Name[0])
+ {
+ case '<': pos = 0; break;
+ case '>': pos = ic.preedit.Length; break;
+ case '-': pos = ic.cursor_pos - 1; break;
+ case '+': pos = ic.cursor_pos + 1; break;
+ case '[':
+ if (pos > 0)
+ {
+ int to;
+ ic.preedit.FindProp (Mcandidates, pos - 1, out pos, out to);
+ }
+ else
+ pos = 0;
+ break;
+ case ']':
+ if (ic.cursor_pos < ic.preedit.Length - 1)
+ {
+ int from;
+ ic.preedit.FindProp (Mcandidates, pos, out from, out pos);
+ }
+ else
+ pos = ic.preedit.Length;
+ break;
+ default:
+ if (sym.Name[0] >= '0' && sym.Name[0] <= '9')
+ pos = sym.Name[0];
+ break;
+ }
+ }
+ else if (sym.Name.Length >= 3 && sym.Name[0] == '@')
+ {
+
+
+ }
+ else
+ {
+ object val = ic.markers.Get (sym);
+
+ if (val is int)
+ pos = (int) val;
+ }
+ return pos;
+ }
+
+ private static object char_at (MExpression[] args,
+ MExpression.Domain domain)
+ {
+ MInputContext ic = (MInputContext) domain.context;
+ MSymbol sym = (MSymbol) args[0].Args[0].Val;
+
+ if (
+
+
+ return 0;
+ }
+
+ private static object delete (MExpression[] args,
+ MExpression.Domain domain)
+ {
+ MInputContext ic = (MInputContext) domain.context;
+ int pos = (int) args[0].Val;
+
+ if (pos < ic.cursor_pos)
+ preedit_replace (ic, pos, ic.cursor_pos, null);
+ else
+ preedit_replace (ic, ic.cursor_pos, pos, null);
+ ic.preedit_changed = true;
+ ic.cursor_pos_changed = true;
+ return true;
+ }
+
private static object select (MExpression[] args,
MExpression.Domain domain)
{
MInputContext ic = (MInputContext) domain.context;
- object arg = args[0].val;
+ object arg = args[0].Val;
if (ic.candidates == null)
return 0;
return 0;
}
- private static object delete (MExpression[] args, MExpression.Domain domain)
- {
- return 1;
- }
-
private static object show (MExpression[] args, MExpression.Domain domain)
{ return 1; }
private static object hide (MExpression[] args, MExpression.Domain domain)
public MInputContext (MInputMethod im)
{
this.im = im;
- domain = new MExpression (this);
+ domain = new MExpression.Domain (im.local_domain, this);
}
internal object GetCandidates (out int column)