1 /* Scheme/Guile language support routines for GDB, the GNU debugger.
2 Copyright 1995 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "expression.h"
24 #include "parser-defs.h"
31 extern struct type
** const (c_builtin_types
[]);
32 extern value_ptr value_allocate_space_in_inferior
PARAMS ((int));
33 extern value_ptr find_function_in_inferior
PARAMS ((char*));
35 static void scm_lreadr ();
37 struct type
*SCM_TYPE
= NULL
;
40 scm_read_token (c
, weird
)
55 case ' ': case '\t': case '\r': case '\f':
59 case '\0': /* End of line */
100 switch ((c
= *lexptr
++))
107 switch ((c
= *lexptr
++))
116 case ' ': case '\t': case '\r': case '\f': case '\n':
128 int c
= scm_skip_ws ();
129 if (')' == c
|| ']' == c
)
133 error ("missing close paren");
155 error ("unexpected #\\%c", c
);
187 case '*': /* bitvector */
188 scm_read_token (c
, 0);
191 scm_read_token (c
, 1);
193 case '\\': /* character */
195 scm_read_token (c
, 0);
198 j
= 1; /* here j is the comment nesting depth */
205 error ("unbalanced comment");
209 if ('#' != (c
= *lexptr
++))
215 if ('|' != (c
= *lexptr
++))
228 while ('\"' != (c
= *lexptr
++))
231 switch (c
= *lexptr
++)
234 error ("non-terminated string literal");
248 case '0': case '1': case '2': case '3': case '4':
249 case '5': case '6': case '7': case '8': case '9':
254 scm_read_token (c
, 0);
257 scm_read_token ('-', 0);
260 scm_read_token (c
, 0);
271 while (*lexptr
== ' ')
275 str
.length
= lexptr
- start
;
277 write_exp_elt_opcode (OP_EXPRSTRING
);
278 write_exp_string (str
);
279 write_exp_elt_opcode (OP_EXPRSTRING
);
284 scm_printchar (c
, stream
)
288 fprintf_filtered (stream
, "#\\%c", c
);
292 scm_printstr (stream
, string
, length
, force_ellipses
)
298 fprintf_filtered (stream
, "\"%s\"", string
);
302 is_scmvalue_type (type
)
305 if (TYPE_CODE (type
) == TYPE_CODE_INT
306 && TYPE_NAME (type
) && strcmp (TYPE_NAME (type
), "SCM") == 0)
314 /* Get the INDEX'th SCM value, assuming SVALUE is the address
318 scm_get_field (svalue
, index
)
324 if (SCM_TYPE
== NULL
)
325 error ("internal error - no SCM type");
326 read_memory (SCM2PTR (svalue
) + index
* TYPE_LENGTH (SCM_TYPE
),
327 buffer
, TYPE_LENGTH (SCM_TYPE
));
328 return unpack_long (SCM_TYPE
, buffer
);
332 evaluate_subexp_scm (expect_type
, exp
, pos
, noside
)
333 struct type
*expect_type
;
334 register struct expression
*exp
;
338 enum exp_opcode op
= exp
->elts
[*pos
].opcode
;
339 value_ptr func
, addr
;
340 int len
, pc
; char *str
;
345 len
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
346 (*pos
) += 3 + BYTES_TO_EXP_ELEM (len
+ 1);
347 if (noside
== EVAL_SKIP
)
349 str
= &exp
->elts
[ + 2].string
;
350 addr
= value_allocate_space_in_inferior (len
);
351 write_memory (value_as_long (addr
), str
, len
);
352 func
= find_function_in_inferior ("scm_evstr");
353 return call_function_by_hand (func
, 1, &addr
);
356 return evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
358 return value_from_longest (builtin_type_long
, (LONGEST
) 1);
361 const struct language_defn scm_language_defn
= {
362 "scheme", /* Language name */
370 scm_printchar
, /* Print a character constant */
371 scm_printstr
, /* Function to print string constant */
372 NULL
, /* Create fundamental type in this language */
373 c_print_type
, /* Print a type using appropriate syntax */
374 scm_val_print
, /* Print a value using appropriate syntax */
375 scm_value_print
, /* Print a top-level value */
376 {"", "", "", ""}, /* Binary format info */
377 {"#o%lo", "#o", "o", ""}, /* Octal format info */
378 {"%ld", "", "d", ""}, /* Decimal format info */
379 {"#x%lX", "#X", "X", ""}, /* Hex format info */
380 NULL
, /* expression operators for printing */
381 1, /* c-style arrays */
382 0, /* String lower bound */
383 &builtin_type_char
, /* Type of string elements */
388 _initialize_scheme_language ()
390 add_language (&scm_language_defn
);