public static Shelisp.Object Fcapitalize(L l, Shelisp.Object obj) { if (obj is Shelisp.String) { StringBuilder sb = new StringBuilder ((string)(Shelisp.String)obj); bool need_capitalization = true; for (int i = 0; i < sb.Length; i ++) { if (Char.IsLetter (sb[i])) { if (need_capitalization) { sb[i] = Char.ToUpper(sb[i]); need_capitalization = false; } } else { need_capitalization = true; } } return (Shelisp.String)sb.ToString(); } else { Console.WriteLine ("unimplemented non-string version of capitalize"); return obj; } }
public static Shelisp.Object Feql(L l, Shelisp.Object o1, Shelisp.Object o2) { if (L.NILP(o1)) return L.NILP(o2) ? L.Qt : L.Qnil; return o1.LispEql (o2) ? L.Qt : L.Qnil; }
public static Shelisp.Object Fprog1(L l, Shelisp.Object form1, params Shelisp.Object[] forms) { Shelisp.Object rv = form1.Eval(l); for (int i = 0; i < forms.Length; i ++) forms[i].Eval(l); return rv; }
public static AssertResult Eq(Shelisp.Object o1, Shelisp.Object o2, string description = null) { try { return (!o1.LispEq (o2)) ? Fail(description) : Succeed(description); } catch (Exception e) { return FailException (e, description); } }
public static Shelisp.Object Ffillarray(L l, Shelisp.Object arr, Shelisp.Object val) { // XXX type checks Array array = (Array)arr; for (int i = 0; i < array.Length; i ++) { array[i] = val; } return arr; }
public static Shelisp.Object Fmessage(L l, Shelisp.Object format, params Shelisp.Object[] args) { var output = format; if (format is Shelisp.String) { output = Format.CFormat ((Shelisp.String)format, args); } Console.WriteLine (output.ToString("princ")); return output; }
public static Shelisp.Object Fautoload(L l, Shelisp.Object function, [LispOptional] Shelisp.Object filename, Shelisp.Object docstring, Shelisp.Object interactive, Shelisp.Object type) { if (L.Qt.LispEq (Symbol.Ffboundp (l, function))) return L.Qnil; var autoload_function = new List (new Shelisp.Object[] { L.Qautoload, filename, docstring == null ? (Shelisp.Object)(Shelisp.String)"" : docstring, interactive == null ? L.Qnil : interactive, type == null ? L.Qnil : interactive }); Symbol.Ffset (l, function, autoload_function); //l.Environment = new List (new List(function, function), l.Environment); return autoload_function; }
public static Shelisp.Object Fif(L l, Shelisp.Object condition, Shelisp.Object then_form, params Shelisp.Object[] else_forms) { if (!L.NILP(condition.Eval(l))) { return then_form.Eval(l); } else { Shelisp.Object rv = L.Qnil; for (int i = 0; i < else_forms.Length; i ++) rv = else_forms[i].Eval(l); return rv; } }
public static Shelisp.Object Fread_from_minibuffer(L l, Shelisp.Object prompt, [LispOptional] Shelisp.Object initial_contents, Shelisp.Object keymap, Shelisp.Object read, Shelisp.Object hist, Shelisp.Object default_value, Shelisp.Object inherit_input_method) { Console.Write (prompt.ToString("princ")); var input = Console.ReadLine (); if (L.NILP (read)) return (Shelisp.String)input; else { return Reader.ReadFromString (input); } }
public static Shelisp.Object Faset(L l, Shelisp.Object sym, Shelisp.Object idx, Shelisp.Object val) { if (sym is Vector) { return ((Vector)sym)[(int)(Number)idx] = val; } else if (sym is Array) { return ((Array)sym)[(int)(Number)idx] = val; } else { throw new WrongTypeArgumentException ("array-or-vectorp", sym ?? L.Qnil); } }
public static Shelisp.Object Fdec(L l, Shelisp.Object op) { if (!(op is Number)) throw new WrongTypeArgumentException ("numberp", op); Number ln = (Number)op; bool need_float = ln.boxed is float; if (need_float) { return new Number ((float)ln.boxed - 1); } else return new Number ((int)ln.boxed - 1); }
public static Shelisp.Object Fread_from_string(L l, Shelisp.Object str, [LispOptional] Shelisp.Object start, Shelisp.Object end) { #if false if (!(str is String)) throw new WrongTypeArgumentException ("stringp", str); Shelisp.Object obj; int pos; obj = Reader.Read ((string)(Shelisp.String)str, out pos); return new List (obj, (Number)pos); #endif return L.Qnil; }
public static Shelisp.Object Fset_marker_insertion_type(L l, Shelisp.Object marker, Shelisp.Object insertion_type) { if (!(marker is Marker)) throw new WrongTypeArgumentException ("markerp", marker); Marker m = (Marker)marker; if (L.Qt.LispEq (insertion_type)) m.Type = InsertionType.MarkerAdvancesOnTextInsertion; else if (L.Qnil.LispEq (insertion_type)) m.Type = InsertionType.MarkerDoesNotAdvanceOnTextInsertion; else throw new Exception (); return L.Qnil; }
public static Shelisp.Object Fplist_get(L l, Shelisp.Object plist, Shelisp.Object property) { Shelisp.Object el = plist; Shelisp.Object val = L.Qnil; while (!L.NILP (el)) { if (L.CAR(el).LispEq (property)) { // the next thing in the list is the value val = L.CAR(L.CDR(el)); break; } el = L.CDR (el); } return val; }
public Hash(L l, Shelisp.Object test, Shelisp.Object weakness, Shelisp.Object size, Shelisp.Object rehash_size, Shelisp.Object rehash_threshold) { this.l = l; this.test = test; this.weakness = weakness; this.size = size; this.rehash_size = size; this.rehash_threshold = rehash_threshold; this.count = 0; // map weakness to our enum if (L.NILP (weakness)) { weakness_ = Weakness.None; } else if (weakness.LispEq (L.Qt)) { weakness_ = Weakness.KeyAndValue; } else if (weakness.LispEq (L.Qkey)) { weakness_ = Weakness.Key; } else if (weakness.LispEq (L.Qvalue)) { weakness_ = Weakness.Value; } else if (weakness.LispEq (L.Qkey_or_value)) { weakness_ = Weakness.KeyOrValue; } else if (weakness.LispEq (L.Qkey_and_value)) { weakness_ = Weakness.KeyAndValue; } else throw new Exception (string.Format ("invalid weakness {0}", weakness)); compare = null; // use a builtin comparison function for the builtin test types if (test.LispEq (L.intern ("eq"))) { compare = compare_eq; } else if (test.LispEq (L.intern ("eql"))) { compare = compare_eql; } else if (test.LispEqual (L.intern ("equal"))) { compare = compare_equal; } table = new Tuple<Shelisp.Object,Shelisp.Object>[(int)((Number)size).boxed]; }
public static Shelisp.Object Fformat_dotnet(L l, Shelisp.Object format, params Shelisp.Object[] args) { switch (args.Length) { case 0: return new Shelisp.String (string.Format ((Shelisp.String)format)); case 1: return new Shelisp.String (string.Format ((Shelisp.String)format, args[0])); case 2: return new Shelisp.String (string.Format ((Shelisp.String)format, args[0], args[1])); case 3: return new Shelisp.String (string.Format ((Shelisp.String)format, args[0], args[1], args[2])); case 4: return new Shelisp.String (string.Format ((Shelisp.String)format, args[0], args[1], args[2], args[3])); case 5: return new Shelisp.String (string.Format ((Shelisp.String)format, args[0], args[1], args[2], args[3], args[4])); case 6: return new Shelisp.String (string.Format ((Shelisp.String)format, args[0], args[1], args[2], args[3], args[4], args[5])); case 7: return new Shelisp.String (string.Format ((Shelisp.String)format, args[0], args[1], args[2], args[3], args[4], args[5], args[6])); case 8: return new Shelisp.String (string.Format ((Shelisp.String)format, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7])); case 9: return new Shelisp.String (string.Format ((Shelisp.String)format, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8])); case 10: return new Shelisp.String (string.Format ((Shelisp.String)format, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9])); default: throw new Exception (); } }
public static Shelisp.Object Fadd(L l, Shelisp.Object op1, Shelisp.Object op2) { if (!(op1 is Number)) throw new WrongTypeArgumentException ("numberp", op1); if (!(op2 is Number)) throw new WrongTypeArgumentException ("numberp", op2); Number ln = (Number)op1; Number rn = (Number)op2; if (ln.boxed is float && rn.boxed is float) { return new Number ((float)ln.boxed + (float)rn.boxed); } else if (ln.boxed is float) { return new Number ((float)ln.boxed + (int)rn.boxed); } else if (rn.boxed is float) { return new Number ((int)ln.boxed + (float)rn.boxed); } else return new Number ((int)ln.boxed + (int)rn.boxed); }
public static Shelisp.Object DoAutoload(L l, Shelisp.Object fun, Shelisp.Object original_fun) { string filename = (string)(Shelisp.String)L.CAR (L.CDR (fun)); if (L.NILP (l.Vload_path)) { Console.WriteLine ("load path = NIL!"); return Fload_file (l, (Shelisp.String)(filename + ".el")); } else { foreach (var o in (List)l.Vload_path) { string full_path = Path.Combine ((string)(Shelisp.String)o, filename); if (Path.GetExtension (full_path) != ".el") full_path = full_path + ".el"; if (File.Exists (full_path)) { Console.WriteLine ("found {0}", full_path); return Fload_file (l, (Shelisp.String)full_path); } Console.WriteLine ("{0} not found", full_path); } } throw new Exception ("file not found"); }
public static Shelisp.String CFormat(Shelisp.String format, params Shelisp.Object[] args) { int arg_num = 0; StringBuilder sb = new StringBuilder (); string format_s = (string)(Shelisp.String)format; for (int i = 0; i < format_s.Length; i ++) { if (format_s[i] == '%') { char specifier = format_s[++i]; switch (specifier) { case '%': sb.Append ('%'); break; case 'd': sb.Append (Number.ToInt(args[arg_num++])); break; case 's': sb.Append (args[arg_num++].ToString("princ")); break; case 'S': sb.Append (args[arg_num++].ToString("prin1")); break; case 'c': if (!Number.IsInt (args[arg_num])) throw new LispErrorException ("Format specifier doesn't match argument type"); sb.Append ((char)Number.ToInt(args[arg_num++])); break; default: throw new Exception (string.Format ("format {0} unsupported", specifier)); } } else { sb.Append (format_s[i]); } } return (Shelisp.String)sb.ToString(); }
public static void RecordBuffer (Shelisp.Object buffer) { throw new NotImplementedException (); }
public void ValidateRegion (Shelisp.Object b, Shelisp.Object e) { throw new NotImplementedException (); }
extern ptrdiff_t sort_overlays (Shelisp.Object *, ptrdiff_t, struct window *);
extern ptrdiff_t overlays_at (int pos, int extend, Shelisp.Object **vec_ptr, ptrdiff_t *len_ptr, int *next_ptr, int *prev_ptr, int change_req);
public Buffer (Shelisp.Object name) { /* An ordinary buffer uses its own struct buffer_text. */ text = new BufferText(); pt = BufferText.BEG; begv = BufferText.BEG; zv = BufferText.BEG; pt_byte = BufferText.BEG; begv_byte = BufferText.BEG; zv_byte = BufferText.BEG; #if notyet newline_cache = 0; width_run_cache = 0; #endif width_table = L.Qnil; prevent_redisplay_optimizations_p = true; /* An ordinary buffer normally doesn't need markers to handle BEGV and ZV. */ pt_marker = L.Qnil; begv_marker = L.Qnil; zv_marker = L.Qnil; undo_list = (L.SREF (name, 0) != ' ') ? L.Qnil : L.Qt; Reset (); ResetLocalVariables (permanent_too: true); mark = new Marker (); this.name = name; }
public Buffer (Shelisp.Object name, Shelisp.Object buffer) { this.base_buffer = (((Buffer)buffer).base_buffer != null ? ((Buffer)buffer).base_buffer : ((Buffer)buffer)); /* Use the base buffer's text object. */ text = base_buffer.text; pt = base_buffer.pt; begv = base_buffer.begv; zv = base_buffer.zv; pt_byte = base_buffer.pt_byte; begv_byte = base_buffer.begv_byte; zv_byte = base_buffer.zv_byte; #if notyet newline_cache = 0; width_run_cache = 0; #endif width_table = L.Qnil; Reset (); ResetLocalVariables (permanent_too: true); mark = new Marker (); this.name = name; /* The multibyte status belongs to the base buffer. */ enable_multibyte_characters = base_buffer.enable_multibyte_characters; /* Make sure the base buffer has markers for its narrowing. */ if (L.NILP (base_buffer.pt_marker)) { #if notyet eassert (NILP (BVAR (base_buffer, begv_marker))); eassert (NILP (BVAR (base_buffer, zv_marker))); #endif base_buffer.pt_marker = new Marker (); Marker.SetBoth (base_buffer.pt_marker, buffer, base_buffer.pt, base_buffer.pt_byte); base_buffer.begv_marker = new Marker (); Marker.SetBoth (base_buffer.begv_marker, buffer, base_buffer.begv, base_buffer.begv_byte); base_buffer.zv_marker = new Marker (); Marker.SetBoth (base_buffer.zv_marker, buffer, base_buffer.zv, base_buffer.zv_byte); ((Marker)base_buffer.zv_marker).Type = Marker.InsertionType.MarkerAdvancesOnTextInsertion; } }
public static Shelisp.Object Fget_buffer_create (L l, Shelisp.Object buffer_or_name) { Shelisp.Object buffer; buffer = Fget_buffer (l, buffer_or_name); if (!L.NILP (buffer)) return buffer; if (buffer_or_name is Shelisp.String) { string name = (Shelisp.String)buffer_or_name; if (name.Length == 0) throw new Exception ("Empty string for buffer name is not allowed"); buffer = new Buffer(name); } else throw new Exception (); Buffer buf = (Buffer)buffer; /* Put this on the chain of all buffers including killed ones. */ buf.next = all_buffers; all_buffers = buf; /* Put this in the alist of all live buffers. */ Buffer.Vbuffer_alist = List.Fnconc (l, Buffer.Vbuffer_alist, new List (new List (buf.name, buffer), L.Qnil)); #if notyet /* And run buffer-list-update-hook. */ if (!L.NILP (L.Vrun_hooks)) L.call (L.Vrun_hooks, L.Qbuffer_list_update_hook); /* An error in calling the function here (should someone redefine it) can lead to infinite regress until you run out of stack. rms says that's not worth protecting against. */ if (!L.NILP (L.Ffboundp (L.Qucs_set_table_for_input))) /* buffer is on buffer-alist, so no gcpro. */ L.call (L.Qucs_set_table_for_input, buf); #endif return buffer; }
public static Shelisp.Object Fget_buffer (L l, Shelisp.Object buffer_or_name) { if (buffer_or_name is Buffer) return buffer_or_name; //CHECK_STRING (buffer_or_name); return List.Fcdr (l, assoc_ignore_text_properties (l, buffer_or_name, Buffer.Vbuffer_alist)); }
public static void BufferSlotTypMismatch (Shelisp.Object newval, int type) { }
public WrongTypeArgumentException(string predicate, Shelisp.Object value) : base(string.Format ("(wrong-type-argument {0} {1}/{2})", predicate, value, value.GetType())) { }
public static Shelisp.Object Fset_buffer (L l, Shelisp.Object buffer_or_name) { Shelisp.Object buf = Fget_buffer (l, buffer_or_name); if (L.NILP (buf)) throw new Exception ("unknown buffer"); Buffer.SetBuffer ((Buffer)buf); return buf; }