From: handa Date: Sun, 9 Aug 2009 23:41:23 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=022f7789c6fa5adac2ad2dd52e296478b4bd1007;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/.cvsignore b/.cvsignore index 9041ade..2563a35 100644 --- a/.cvsignore +++ b/.cvsignore @@ -1,3 +1,4 @@ *.exe *.dll +*.mdb *.xml diff --git a/MExpression.cs b/MExpression.cs index fb1bfd8..70bebd8 100644 --- a/MExpression.cs +++ b/MExpression.cs @@ -160,10 +160,10 @@ namespace M17N.Core } public readonly MSymbol Name; - internal readonly Evaluator eval; - internal readonly int min_arg, max_arg; + private readonly Evaluator eval; + public readonly int min_arg, max_arg; private readonly Lambda lambda; - private bool specialp = false; + private readonly bool specialp = false; internal static Function ignore, varref, block; diff --git a/MInputMethod.cs b/MInputMethod.cs index 93c6591..e8a651a 100644 --- a/MInputMethod.cs +++ b/MInputMethod.cs @@ -10,6 +10,8 @@ namespace M17N.Input { public class MInputMethod { + internal static MExpression.Domain domain = new MExpression.Domain (null); + private static MSymbol Minput_method = MSymbol.Of ("input-method"); private static MSymbol Mdescription = MSymbol.Of ("description"); private static MSymbol Mvariable = MSymbol.Of ("variable"); @@ -129,15 +131,10 @@ namespace M17N.Input private static Dictionary im_table = new Dictionary (); - private static MExpression.FunctionTable global_table - = new MExpression.FunctionTable (); - public readonly MSymbol language; public readonly MSymbol name; public readonly MSymbol subname; - internal MExpression.FunctionTable local_table - = new MExpression.FunctionTable (global_table); internal MDatabase mdb; internal MText description; internal MText title; @@ -153,52 +150,22 @@ namespace M17N.Input static MInputMethod () { - MExpression.Defun (global_table, "insert", - new MExpression.Evaluator (insert), - 1, 1, typeof (MExpression)); - MExpression.Defun (global_table, "candidates", - new MExpression.Evaluator (insert_candidates), - 1, 1, typeof (object)); - MExpression.Defun (global_table, "delete", - new MExpression.Evaluator (delete), - 1, 1, typeof (object)); - MExpression.Defun (global_table, "select", - new MExpression.Evaluator (select), - 1, 1, typeof (object)); - MExpression.Defun (global_table, "show", - new MExpression.Evaluator (show), - 0, 0); - MExpression.Defun (global_table, "hide", - new MExpression.Evaluator (hide), - 0, 0); - MExpression.Defun (global_table, "move", - new MExpression.Evaluator (move), - 1, 1, typeof (object)); - MExpression.Defun (global_table, "mark", - new MExpression.Evaluator (mark), - 1, 1, typeof (MSymbol)); - MExpression.Defun (global_table, "pushback", - new MExpression.Evaluator (pushback), - 1, 1, typeof (object)); - MExpression.Defun (global_table, "pop", - new MExpression.Evaluator (pop), - 0, 0); - MExpression.Defun (global_table, "undo", - new MExpression.Evaluator (undo), - 0, 1, typeof (object)); - MExpression.Defun (global_table, "commit", - new MExpression.Evaluator (commit), - 0, 0); - MExpression.Defun (global_table, "unhandle", - new MExpression.Evaluator (unhandle), - 0, 0); - MExpression.Defun (global_table, "shift", - new MExpression.Evaluator (shift), - 1, 1, typeof (MSymbol)); - MExpression.Defun (global_table, "call", - new MExpression.Evaluator (call), - 2, -1, typeof (MSymbol), typeof (MSymbol), - typeof (object)); + 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); } private MInputMethod (MDatabase.Tag tag) @@ -345,7 +312,7 @@ namespace M17N.Input if (target_type == Mmacro) { if (target_name == MSymbol.nil) - im.local_table.Copy (local_table); + im.domain.Copy (local_table); else im.local_table.Copy (target_name, local_table); } @@ -523,11 +490,11 @@ namespace M17N.Input adjust_markers (ic, from, to, mt); } - private static object insert (object[] args, MPlist bindings, - object context) + private static object insert (MExpression[] args, + MExpression.Domain domain) { - MInputContext ic = (MInputContext) context; - object arg = ((MExpression) args[0]).Eval (bindings, ic); + MInputContext ic = (MInputContext) domain.context; + object arg = args[0].val; if (arg is int) preedit_replace (ic, ic.cursor_pos, ic.cursor_pos, (int) arg); @@ -796,26 +763,29 @@ namespace M17N.Input } } - private static object insert_candidates (object[] args, MPlist bindings, - object context) + private static object insert_candidates (MExpression[] args, + MExpression.Domain domain) { - MInputContext ic = (MInputContext) context; + MInputContext ic = (MInputContext) domain.context; MPlist list = (MPlist) args[0]; int column = 0; - MPlist slot = (MPlist) bindings.Find (Mcandidates_group_size); - if (slot != null) - column = slot.Integer; + if (domain.IsBound (Mcandidates_group_size)) + { + object val = domain.GetValue (Mcandidates_group_size); + if (val is int) + column = (int) val; + } Candidates candidates = new Candidates (list, column); candidates.Update (ic); return 1; } - private static object select (object[] args, MPlist bindings, - object context) + private static object select (MExpression[] args, + MExpression.Domain domain) { - MInputContext ic = (MInputContext) context; - object arg = args[0]; + MInputContext ic = (MInputContext) domain.context; + object arg = args[0].val; if (ic.candidates == null) return 0; @@ -844,30 +814,33 @@ namespace M17N.Input return 0; } - private static object delete (object[] args, MPlist bindings, - object context) { return 1; } - private static object show (object[] args, MPlist bindings, - object context) { return 1; } - private static object hide (object[] args, MPlist bindings, - object context) { return 1; } - private static object move (object[] args, MPlist bindings, - object context) { return 1; } - private static object mark (object[] args, MPlist bindings, - object context) { return 1; } - private static object pushback (object[] args, MPlist bindings, - object context) { return 1; } - private static object pop (object[] args, MPlist bindings, - object context) { return 1; } - private static object undo (object[] args, MPlist bindings, - object context) { return 1; } - private static object commit (object[] args, MPlist bindings, - object context) { return 1; } - private static object unhandle (object[] args, MPlist bindings, - object context) { return 1; } - private static object shift (object[] args, MPlist bindings, - object context) { return 1; } - private static object call (object[] args, MPlist bindings, - object context) { return 1; } + 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) + { return 1; } + private static object move (MExpression[] args, MExpression.Domain domain) + { return 1; } + private static object mark (MExpression[] args, MExpression.Domain domain) + { return 1; } + private static object pushback (MExpression[] args, MExpression.Domain domain) + { return 1; } + private static object pop (MExpression[] args, MExpression.Domain domain) + { return 1; } + private static object undo (MExpression[] args, MExpression.Domain domain) + { return 1; } + private static object commit (MExpression[] args, MExpression.Domain domain) + { return 1; } + private static object unhandle (MExpression[] args, MExpression.Domain domain) + { return 1; } + private static object shift (MExpression[] args, MExpression.Domain domain) + { return 1; } + private static object call (MExpression[] args, MExpression.Domain domain) + { return 1; } } public class MInputContext @@ -904,6 +877,14 @@ namespace M17N.Input private MText following_text; private bool key_unhandled; + internal MExpression.Domain domain; + + public MInputContext (MInputMethod im) + { + this.im = im; + domain = new MExpression (this); + } + internal object GetCandidates (out int column) { column = 0; diff --git a/Makefile b/Makefile index 994a248..35875fd 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,8 @@ CS=gmcs +DEBUG_FLAG = -debug +CODEPAGE = 65001 + +RUNCS = ${CS} ${DEBUG_FLAG} -codepage:${CODEPAGE} M17N_SRC = M17N.cs CORE_SRC = MSymbol.cs MPlist.cs MCharTable.cs MText.cs MDatabase.cs @@ -10,30 +14,28 @@ EXAMPLE = symbol.exe plist.exe chartab.exe text.exe textprop.exe database.exe \ TEST = rearsticky.exe frontsticky.exe bothsticky.exe \ sensitive.exe frontsensitive.exe rearsensitive.exe -DEBUG_FLAG = -debug - all: ${DLL} ${EXAMPLE} ${TEST} M17N.dll: ${M17N_SRC} - $(CS) $(DEBUG_FLAG) -out:$@ -t:library ${M17N_SRC} + $(RUNCS) -out:$@ -t:library ${M17N_SRC} M17NCore.dll: M17N.dll ${CORE_SRC} - $(CS) $(DEBUG_FLAG) -out:$@ -t:library -r:M17N.dll ${CORE_SRC} + $(RUNCS) -out:$@ -t:library -r:M17N.dll ${CORE_SRC} M17NExpr.dll: M17N.dll M17NCore.dll ${EXPR_SRC} - $(CS) $(DEBUG_FLAG) -out:$@ -t:library -r:M17N.dll -r:M17NCore.dll ${EXPR_SRC} + $(RUNCS) -out:$@ -t:library -r:M17N.dll -r:M17NCore.dll ${EXPR_SRC} M17NIM.dll: ${INPUT_SRC} M17N.dll M17NCore.dll M17NExpr.dll - $(CS) $(DEBUG_FLAG) -out:$@ -t:library -r:M17N.dll -r:M17NCore.dll -r:M17NExpr.dll ${INPUT_SRC} + $(RUNCS) -out:$@ -t:library -r:M17N.dll -r:M17NCore.dll -r:M17NExpr.dll ${INPUT_SRC} input.exe: input.cs ${DLL} - $(CS) $(DEBUG_FLAG) -codepage:65001 -r:M17N.dll -r:M17NCore -r:M17NExpr -r:M17NIM.dll $< + $(RUNCS) -r:M17N.dll -r:M17NCore -r:M17NExpr -r:M17NIM.dll $< expr.exe: expr.cs - $(CS) $(DEBUG_FLAG) -codepage:65001 -r:M17N.dll -r:M17NCore -r:M17NExpr -r:M17NIM.dll $< + $(RUNCS) -r:M17N.dll -r:M17NCore -r:M17NExpr $< %.exe: %.cs - $(CS) $(DEBUG_FLAG) -codepage:65001 -r:M17N.dll -r:M17NCore $< + $(RUNCS) -r:M17N.dll -r:M17NCore $< clean: rm -f *.dll *.exe diff --git a/expr.cs b/expr.cs index 5fc048d..d73ce59 100644 --- a/expr.cs +++ b/expr.cs @@ -8,37 +8,34 @@ public class Test { static MSymbol Mpreedit = MSymbol.Of ("preedit"); - public static object insert (object[] args, MPlist bindings) + public static object insert (MExpression[] args, MExpression.Domain domain) { - object arg = ((MExpression) args[0]).Eval (bindings); - MPlist slot = bindings.Find (Mpreedit); - MText preedit = (MText) slot.val; + MText preedit = (MText) domain.GetValue (Mpreedit); + object val = args[0].Val; - if (arg is int) - preedit.Cat ((int) arg); + if (val is int) + preedit.Cat ((int) val); else - preedit.Cat ((MText) arg); - return arg; + preedit.Cat ((MText) val); + return val; } public static void Main() { - MExpression expr; - MPlist bindings = new MPlist (); MExpression.Domain domain = new MExpression.Domain (null); - MExpression.Defun (func_table, "insert", new MExpression.Evaluator (insert), - 1, 1, typeof (MExpression)); - bindings.Add (MSymbol.Of ("X"), 10); - bindings.Add (Mpreedit, new MText ("PREEDIT TEXT")); + domain.Defun ("insert", new MExpression.Evaluator (insert), 1, 1, false); + domain.Bind (MSymbol.Of ("X"), 10); + domain.Bind (Mpreedit, new MText ("PREEDIT TEXT")); + MExpression expr; using (FileStream stream = new FileStream ("eval.txt", FileMode.Open)) { - expr = new MExpression (new MPlist (stream), func_table); + expr = new MExpression (new MPlist (stream), domain); } - Console.WriteLine (bindings); - expr.PrettyPrint (); - Console.WriteLine ("\n => " + expr.Eval (bindings, null)); - Console.WriteLine (bindings); + Console.WriteLine (domain); + Console.Write (expr); + Console.WriteLine (" => " + expr.Eval (domain)); + Console.WriteLine (domain); } } diff --git a/input.cs b/input.cs new file mode 100644 index 0000000..c4305d7 --- /dev/null +++ b/input.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.IO; +using M17N; +using M17N.Core; +using M17N.Input; + +public class Test +{ + public static void Main() + { + MDatabase.ApplicationDir = "/usr/local/share/m17n"; + MInputMethod im = MInputMethod.Get (MSymbol.Of ("vi"), + MSymbol.Of ("telex"), + MSymbol.nil); + Console.WriteLine (im); + } +} +