2 * Copyright © 2008 Chris Wilson <chris@chris-wilson.co.uk>
4 * This library is free software; you can redistribute it and/or
5 * modify it either under the terms of the GNU Lesser General Public
6 * License version 2.1 as published by the Free Software Foundation
7 * (the "LGPL") or, at your option, under the terms of the Mozilla
8 * Public License Version 1.1 (the "MPL"). If you do not alter this
9 * notice, a recipient may use your version of this file under either
10 * the MPL or the LGPL.
12 * You should have received a copy of the LGPL along with this library
13 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
15 * You should have received a copy of the MPL along with this library
16 * in the file COPYING-MPL-1.1
18 * The contents of this file are subject to the Mozilla Public License
19 * Version 1.1 (the "License"); you may not use this file except in
20 * compliance with the License. You may obtain a copy of the License at
21 * http://www.mozilla.org/MPL/
23 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
24 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
25 * the specific language governing rights and limitations.
27 * The Original Code is the cairo graphics library.
29 * The Initial Developer of the Original Code is Chris Wilson.
32 * Chris Wilson <chris@chris-wilson.co.uk>
35 #ifndef CAIRO_SCRIPT_PRIVATE_H
36 #define CAIRO_SCRIPT_PRIVATE_H
42 #include "cairo-script-interpreter.h"
48 #define inline __inline
60 #define NULL (void *) 0
66 # include <inttypes.h>
67 #elif HAVE_SYS_INT_TYPES_H
68 # include <sys/int_types.h>
69 #elif defined(_MSC_VER)
70 typedef __int8 int8_t;
71 typedef unsigned __int8 uint8_t;
72 typedef __int16 int16_t;
73 typedef unsigned __int16 uint16_t;
74 typedef __int32 int32_t;
75 typedef unsigned __int32 uint32_t;
76 typedef __int64 int64_t;
77 typedef unsigned __int64 uint64_t;
78 # ifndef HAVE_UINT64_T
79 # define HAVE_UINT64_T 1
82 #error Cannot find definitions for fixed-width integral types (uint8_t, uint32_t, etc.)
86 # include <byteswap.h>
89 # define bswap_16(p) \
90 (((((uint16_t)(p)) & 0x00ff) << 8) | \
91 (((uint16_t)(p)) >> 8))
94 # define bswap_32(p) \
95 (((((uint32_t)(p)) & 0x000000ff) << 24) | \
96 ((((uint32_t)(p)) & 0x0000ff00) << 8) | \
97 ((((uint32_t)(p)) & 0x00ff0000) >> 8) | \
98 ((((uint32_t)(p))) >> 24))
102 #if __GNUC__ >= 3 && defined(__ELF__) && !defined(__sun)
103 # define slim_hidden_proto(name) slim_hidden_proto1(name, slim_hidden_int_name(name)) csi_private
104 # define slim_hidden_proto_no_warn(name) slim_hidden_proto1(name, slim_hidden_int_name(name)) csi_private_no_warn
105 # define slim_hidden_def(name) slim_hidden_def1(name, slim_hidden_int_name(name))
106 # define slim_hidden_int_name(name) INT_##name
107 # define slim_hidden_proto1(name, internal) \
108 extern __typeof (name) name \
109 __asm__ (slim_hidden_asmname (internal))
110 # define slim_hidden_def1(name, internal) \
111 extern __typeof (name) EXT_##name __asm__(slim_hidden_asmname(name)) \
112 __attribute__((__alias__(slim_hidden_asmname(internal))))
113 # define slim_hidden_ulp slim_hidden_ulp1(__USER_LABEL_PREFIX__)
114 # define slim_hidden_ulp1(x) slim_hidden_ulp2(x)
115 # define slim_hidden_ulp2(x) #x
116 # define slim_hidden_asmname(name) slim_hidden_asmname1(name)
117 # define slim_hidden_asmname1(name) slim_hidden_ulp #name
119 # define slim_hidden_proto(name) int _csi_dummy_prototype(void)
120 # define slim_hidden_proto_no_warn(name) int _csi_dummy_prototype(void)
121 # define slim_hidden_def(name) int _csi_dummy_prototype(void)
125 #define csi_pure __attribute__((pure))
126 #define csi_const __attribute__((const))
132 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
133 #define _CSI_BOOLEAN_EXPR(expr) \
135 int _csi_boolean_var_; \
137 _csi_boolean_var_ = 1; \
139 _csi_boolean_var_ = 0; \
142 #define _csi_likely(expr) (__builtin_expect (_CSI_BOOLEAN_EXPR(expr), 1))
143 #define _csi_unlikely(expr) (__builtin_expect (_CSI_BOOLEAN_EXPR(expr), 0))
145 #define _csi_likely(expr) (expr)
146 #define _csi_unlikely(expr) (expr)
151 #define offsetof(type, member) \
152 ((char *) &((type *) 0)->member - (char *) 0)
154 #define csi_container_of(ptr, type, member) ({ \
155 const typeof(((type *) 0)->member) *mptr__ = (ptr); \
156 (type *) ((char *) mptr__ - offsetof (type, member)); \
159 #define csi_container_of(ptr, type, member) \
160 (type *)((char *) (ptr) - (char *) &((type *)0)->member)
163 /* slim_internal.h */
164 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun)
165 #define csi_private_no_warn __attribute__((__visibility__("hidden")))
166 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
167 #define csi_private_no_warn __hidden
168 #else /* not gcc >= 3.3 and not Sun Studio >= 8 */
169 #define csi_private_no_warn
173 #define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0])))
175 #ifndef WARN_UNUSED_RESULT
176 #define WARN_UNUSED_RESULT
178 /* Add attribute(warn_unused_result) if supported */
179 #define csi_warn WARN_UNUSED_RESULT
180 #define csi_private csi_private_no_warn csi_warn
182 #define CSI_BITSWAP8(c) ((((c) * 0x0802LU & 0x22110LU) | ((c) * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16)
183 #ifdef WORDS_BIGENDIAN
184 #define CSI_BITSWAP8_IF_LITTLE_ENDIAN(c) (c)
186 #define CSI_BITSWAP8_IF_LITTLE_ENDIAN(c) CSI_BITSWAP8(c)
189 typedef enum _csi_status {
190 CSI_STATUS_SUCCESS = CAIRO_STATUS_SUCCESS,
191 CSI_STATUS_NO_MEMORY = CAIRO_STATUS_NO_MEMORY,
192 CSI_STATUS_INVALID_RESTORE = CAIRO_STATUS_INVALID_RESTORE,
193 CSI_STATUS_INVALID_POP_GROUP = CAIRO_STATUS_INVALID_POP_GROUP,
194 CSI_STATUS_NO_CURRENT_POINT = CAIRO_STATUS_NO_CURRENT_POINT,
195 CSI_STATUS_INVALID_MATRIX = CAIRO_STATUS_INVALID_MATRIX,
196 CSI_STATUS_INVALID_STATUS = CAIRO_STATUS_INVALID_STATUS,
197 CSI_STATUS_NULL_POINTER = CAIRO_STATUS_NULL_POINTER,
198 CSI_STATUS_INVALID_STRING = CAIRO_STATUS_INVALID_STRING,
199 CSI_STATUS_INVALID_PATH_DATA = CAIRO_STATUS_INVALID_PATH_DATA,
200 CSI_STATUS_READ_ERROR = CAIRO_STATUS_READ_ERROR,
201 CSI_STATUS_WRITE_ERROR = CAIRO_STATUS_WRITE_ERROR,
202 CSI_STATUS_SURFACE_FINISHED = CAIRO_STATUS_SURFACE_FINISHED,
203 CSI_STATUS_SURFACE_TYPE_MISMATCH = CAIRO_STATUS_SURFACE_TYPE_MISMATCH,
204 CSI_STATUS_PATTERN_TYPE_MISMATCH = CAIRO_STATUS_PATTERN_TYPE_MISMATCH,
205 CSI_STATUS_INVALID_CONTENT = CAIRO_STATUS_INVALID_CONTENT,
206 CSI_STATUS_INVALID_FORMAT = CAIRO_STATUS_INVALID_FORMAT,
207 CSI_STATUS_INVALID_VISUAL = CAIRO_STATUS_INVALID_VISUAL,
208 CSI_STATUS_FILE_NOT_FOUND = CAIRO_STATUS_FILE_NOT_FOUND,
209 CSI_STATUS_INVALID_DASH = CAIRO_STATUS_INVALID_DASH,
210 CSI_STATUS_INVALID_DSC_COMMENT = CAIRO_STATUS_INVALID_DSC_COMMENT,
211 CSI_STATUS_INVALID_INDEX = CAIRO_STATUS_INVALID_INDEX,
212 CSI_STATUS_CLIP_NOT_REPRESENTABLE = CAIRO_STATUS_CLIP_NOT_REPRESENTABLE,
213 CSI_STATUS_TEMP_FILE_ERROR = CAIRO_STATUS_TEMP_FILE_ERROR,
214 CSI_STATUS_INVALID_STRIDE = CAIRO_STATUS_INVALID_STRIDE,
215 CSI_STATUS_FONT_TYPE_MISMATCH = CAIRO_STATUS_FONT_TYPE_MISMATCH,
216 CSI_STATUS_USER_FONT_IMMUTABLE = CAIRO_STATUS_USER_FONT_IMMUTABLE,
217 CSI_STATUS_USER_FONT_ERROR = CAIRO_STATUS_USER_FONT_ERROR,
218 CSI_STATUS_NEGATIVE_COUNT = CAIRO_STATUS_NEGATIVE_COUNT,
219 CSI_STATUS_INVALID_CLUSTERS = CAIRO_STATUS_INVALID_CLUSTERS,
220 CSI_STATUS_INVALID_SLANT = CAIRO_STATUS_INVALID_SLANT,
221 CSI_STATUS_INVALID_WEIGHT = CAIRO_STATUS_INVALID_WEIGHT,
223 /* cairo-script-interpreter specific errors */
225 CSI_STATUS_INVALID_SCRIPT,
226 CSI_STATUS_SCRIPT_INVALID_TYPE,
227 CSI_STATUS_SCRIPT_INVALID_INDEX,
228 CSI_STATUS_SCRIPT_UNDEFINED_NAME,
229 CSI_STATUS_INTERPRETER_FINISHED,
231 _CSI_STATUS_SCRIPT_LAST_ERROR,
232 CSI_INT_STATUS_UNSUPPORTED
236 CSI_OBJECT_TYPE_NULL = 0,
239 CSI_OBJECT_TYPE_BOOLEAN,
240 CSI_OBJECT_TYPE_INTEGER,
241 CSI_OBJECT_TYPE_MARK,
242 CSI_OBJECT_TYPE_NAME,
243 CSI_OBJECT_TYPE_OPERATOR,
244 CSI_OBJECT_TYPE_REAL,
247 CSI_OBJECT_TYPE_ARRAY = 0x8,
248 CSI_OBJECT_TYPE_DICTIONARY,
249 CSI_OBJECT_TYPE_FILE,
250 CSI_OBJECT_TYPE_MATRIX,
251 CSI_OBJECT_TYPE_STRING,
254 CSI_OBJECT_TYPE_CONTEXT = 0x10,
255 CSI_OBJECT_TYPE_FONT,
256 CSI_OBJECT_TYPE_PATTERN,
257 CSI_OBJECT_TYPE_SCALED_FONT,
258 CSI_OBJECT_TYPE_SURFACE
261 #define CSI_OBJECT_IS_ATOM(OBJ) (((OBJ)->type & CSI_OBJECT_TYPE_MASK) < 0x08)
262 #define CSI_OBJECT_IS_COMPOUND(OBJ) ((OBJ)->type & 0x08)
263 #define CSI_OBJECT_IS_CAIRO(OBJ) ((OBJ)->type & 0x10)
265 enum { /* attributes */
266 CSI_OBJECT_ATTR_EXECUTABLE = 1 << 6,
267 CSI_OBJECT_ATTR_WRITABLE = 1 << 7
269 #define CSI_OBJECT_ATTR_MASK (CSI_OBJECT_ATTR_EXECUTABLE | \
270 CSI_OBJECT_ATTR_WRITABLE)
271 #define CSI_OBJECT_TYPE_MASK (~CSI_OBJECT_ATTR_MASK)
273 typedef struct _cairo_script_interpreter csi_t;
275 typedef cairo_bool_t csi_boolean_t;
276 typedef csi_status_t (*csi_operator_t) (csi_t *);
277 typedef float csi_real_t;
278 typedef long csi_integer_t;
279 typedef long csi_name_t;
280 typedef struct _csi_array csi_array_t;
281 typedef struct _csi_buffer csi_buffer_t;
282 typedef struct _csi_compound_object csi_compound_object_t;
283 typedef struct _csi_dictionary csi_dictionary_t;
284 typedef struct _csi_file csi_file_t;
285 typedef struct _csi_hash_entry csi_hash_entry_t;
286 typedef struct _csi_hash_table csi_hash_table_t;
287 typedef struct _csi_hash_table_arrangement csi_hash_table_arrangement_t;
288 typedef struct _csi_list csi_list_t;
289 typedef struct _csi_matrix csi_matrix_t;
290 typedef struct _csi_object csi_object_t;
291 typedef struct _csi_scanner csi_scanner_t;
292 typedef struct _csi_stack csi_stack_t;
293 typedef struct _csi_string csi_string_t;
296 (*csi_hash_predicate_func_t) (void *entry);
299 (*csi_hash_callback_func_t) (void *entry,
303 (*csi_hash_keys_equal_func_t) (const void *key_a, const void *key_b);
306 csi_object_type_t type;
309 cairo_font_face_t *font_face;
310 cairo_pattern_t *pattern;
311 cairo_scaled_font_t *scaled_font;
312 cairo_surface_t *surface;
314 csi_boolean_t boolean;
315 csi_compound_object_t *object;
316 csi_dictionary_t *dictionary;
318 csi_integer_t integer;
319 csi_matrix_t *matrix;
323 csi_string_t *string;
328 struct _csi_compound_object {
329 csi_object_type_t type;
333 struct _csi_hash_entry {
337 struct _csi_hash_table_arrangement {
338 unsigned long high_water_mark;
340 unsigned long rehash;
343 struct _csi_hash_table {
344 csi_hash_keys_equal_func_t keys_equal;
346 const csi_hash_table_arrangement_t *arrangement;
347 csi_hash_entry_t **entries;
349 unsigned long live_entries;
350 unsigned long used_entries;
351 unsigned long iterating; /* Iterating, no insert, no resize */
355 /* simple, embedded doubly-linked links */
357 struct _csi_list *next, *prev;
361 char *base, *ptr, *end;
366 csi_object_t *objects;
372 csi_compound_object_t base;
376 typedef struct _csi_dictionary_entry {
377 csi_hash_entry_t hash_entry;
379 } csi_dictionary_entry_t;
381 struct _csi_dictionary {
382 csi_compound_object_t base;
383 csi_hash_table_t hash_table;
387 csi_compound_object_t base;
388 cairo_matrix_t matrix;
392 csi_compound_object_t base;
394 csi_integer_t deflate;
398 typedef struct _csi_filter_funcs {
399 int (*filter_getc) (csi_file_t *);
400 void (*filter_putc) (csi_file_t *, int);
401 int (*filter_read) (csi_file_t *, uint8_t *, int);
402 void (*filter_destroy) (csi_t *, void *);
403 } csi_filter_funcs_t;
406 csi_compound_object_t base;
418 const csi_filter_funcs_t *filter;
421 union _csi_union_object {
425 csi_dictionary_t dictionary;
432 struct _csi_scanner {
437 csi_status_t (*push) (csi_t *ctx, csi_object_t *obj);
438 csi_status_t (*execute) (csi_t *ctx, csi_object_t *obj);
442 csi_stack_t procedure_stack;
443 csi_object_t build_procedure;
445 unsigned int accumulator;
446 unsigned int accumulator_count;
448 unsigned int line_number;
451 typedef cairo_script_interpreter_hooks_t csi_hooks_t;
453 typedef struct _csi_chunk {
454 struct _csi_chunk *next;
459 struct _cairo_script_interpreter {
463 unsigned int finished : 1;
467 csi_hash_table_t strings;
472 csi_scanner_t scanner;
474 csi_chunk_t *perm_chunk;
479 csi_array_t *free_array;
480 csi_dictionary_t *free_dictionary;
481 csi_string_t *free_string;
483 csi_operator_t opcode[256];
485 /* caches of live data */
490 typedef struct _csi_operator_def {
493 } csi_operator_def_t;
495 typedef struct _csi_integer_constant_def {
498 } csi_integer_constant_def_t;
500 typedef struct _csi_real_constant_def {
503 } csi_real_constant_def_t;
505 /* cairo-script-file.c */
507 csi_private csi_status_t
508 csi_file_new (csi_t *ctx,
510 const char *path, const char *mode);
512 csi_private csi_status_t
513 csi_file_new_for_stream (csi_t *ctx,
517 csi_private csi_status_t
518 csi_file_new_for_bytes (csi_t *ctx,
521 unsigned int length);
523 csi_private csi_status_t
524 csi_file_new_from_string (csi_t *ctx,
528 csi_private csi_status_t
529 csi_file_new_ascii85_decode (csi_t *ctx,
531 csi_dictionary_t *dict,
534 csi_private csi_status_t
535 csi_file_new_deflate_decode (csi_t *ctx,
537 csi_dictionary_t *dict,
540 csi_private csi_status_t
541 _csi_file_execute (csi_t *ctx, csi_file_t *obj);
544 csi_file_getc (csi_file_t *obj);
547 csi_file_read (csi_file_t *obj, void *buf, int len);
550 csi_file_putc (csi_file_t *obj, int c);
553 csi_file_flush (csi_file_t *obj);
556 csi_file_close (csi_t *ctx, csi_file_t *obj);
559 _csi_file_free (csi_t *ctx, csi_file_t *obj);
561 csi_private csi_status_t
562 _csi_file_as_string (csi_t *ctx,
566 /* cairo-script-hash.c */
568 csi_private csi_status_t
569 _csi_hash_table_init (csi_hash_table_t *hash_table,
570 csi_hash_keys_equal_func_t keys_equal);
573 _csi_hash_table_fini (csi_hash_table_t *hash_table);
576 _csi_hash_table_lookup (csi_hash_table_t *hash_table,
577 csi_hash_entry_t *key);
579 csi_private csi_status_t
580 _csi_hash_table_insert (csi_hash_table_t *hash_table,
581 csi_hash_entry_t *entry);
584 _csi_hash_table_remove (csi_hash_table_t *hash_table,
585 csi_hash_entry_t *key);
588 _csi_hash_table_foreach (csi_hash_table_t *hash_table,
589 csi_hash_callback_func_t hash_callback,
592 /* cairo-script-interpreter.c */
595 _csi_alloc (csi_t *ctx, int size);
598 _csi_alloc0 (csi_t *ctx, int size);
601 _csi_realloc (csi_t *ctx, void *ptr, int size);
604 _csi_free (csi_t *ctx, void *ptr);
607 _csi_slab_alloc (csi_t *ctx, int size);
610 _csi_perm_alloc (csi_t *ctx, int size);
613 _csi_slab_free (csi_t *ctx, void *ptr, int size);
615 csi_private csi_status_t
616 csi_push_ostack (csi_t *ctx, csi_object_t *obj);
618 csi_private csi_status_t
619 _csi_name_define (csi_t *ctx, csi_name_t name, csi_object_t *obj);
621 csi_private csi_status_t
622 _csi_name_lookup (csi_t *ctx, csi_name_t name, csi_object_t *obj);
624 csi_private csi_status_t
625 _csi_name_undefine (csi_t *ctx, csi_name_t name);
627 csi_private csi_status_t
628 _csi_intern_string (csi_t *ctx, const char **str_inout, int len);
630 csi_private csi_status_t
631 _csi_error (csi_status_t status);
633 /* cairo-script-objects.c */
635 csi_private csi_status_t
636 csi_array_new (csi_t *ctx,
637 csi_integer_t initial_size,
640 csi_private csi_status_t
641 _csi_array_execute (csi_t *ctx, csi_array_t *array);
643 csi_private csi_status_t
644 csi_array_get (csi_t *ctx,
647 csi_object_t *value);
649 csi_private csi_status_t
650 csi_array_put (csi_t *ctx,
653 csi_object_t *value);
655 csi_private csi_status_t
656 csi_array_append (csi_t *ctx,
661 csi_array_free (csi_t *ctx, csi_array_t *array);
664 csi_boolean_new (csi_object_t *obj,
667 obj->type = CSI_OBJECT_TYPE_BOOLEAN;
668 obj->datum.boolean = v;
671 csi_private csi_status_t
672 csi_dictionary_new (csi_t *ctx,
675 csi_private csi_status_t
676 csi_dictionary_put (csi_t *ctx,
677 csi_dictionary_t *dict,
679 csi_object_t *value);
681 csi_private csi_status_t
682 csi_dictionary_get (csi_t *ctx,
683 csi_dictionary_t *dict,
685 csi_object_t *value);
687 csi_private csi_boolean_t
688 csi_dictionary_has (csi_dictionary_t *dict,
692 csi_dictionary_remove (csi_t *ctx,
693 csi_dictionary_t *dict,
697 csi_dictionary_free (csi_t *ctx,
698 csi_dictionary_t *dict);
701 csi_integer_new (csi_object_t *obj,
704 obj->type = CSI_OBJECT_TYPE_INTEGER;
705 obj->datum.integer = v;
709 csi_private csi_status_t
710 csi_matrix_new (csi_t *ctx,
713 csi_private csi_status_t
714 csi_matrix_new_from_array (csi_t *ctx,
718 csi_private csi_status_t
719 csi_matrix_new_from_matrix (csi_t *ctx,
721 const cairo_matrix_t *m);
723 csi_private csi_status_t
724 csi_matrix_new_from_values (csi_t *ctx,
729 csi_matrix_free (csi_t *ctx,
732 csi_private csi_status_t
733 csi_name_new (csi_t *ctx,
738 csi_private csi_status_t
739 csi_name_new_static (csi_t *ctx,
744 csi_operator_new (csi_object_t *obj,
747 obj->type = CSI_OBJECT_TYPE_OPERATOR | CSI_OBJECT_ATTR_EXECUTABLE;
752 csi_real_new (csi_object_t *obj,
755 obj->type = CSI_OBJECT_TYPE_REAL;
759 csi_private csi_status_t
760 csi_string_new (csi_t *ctx,
765 csi_private csi_status_t
766 csi_string_deflate_new (csi_t *ctx,
772 csi_private csi_status_t
773 csi_string_new_from_bytes (csi_t *ctx,
779 csi_string_free (csi_t *ctx, csi_string_t *string);
781 csi_private csi_status_t
782 csi_object_execute (csi_t *ctx, csi_object_t *obj);
784 csi_private csi_object_t *
785 csi_object_reference (csi_object_t *obj);
788 csi_object_free (csi_t *ctx,
791 csi_private csi_status_t
792 csi_object_as_file (csi_t *ctx,
796 csi_private csi_boolean_t
797 csi_object_eq (csi_object_t *a,
800 csi_private csi_status_t
801 csi_object_compare (csi_object_t *a,
805 /* cairo-script-operators.c */
807 csi_private const csi_operator_def_t *
808 _csi_operators (void);
810 csi_private const csi_integer_constant_def_t *
811 _csi_integer_constants (void);
813 csi_private const csi_real_constant_def_t *
814 _csi_real_constants (void);
816 /* cairo-script-scanner.c */
818 csi_private csi_status_t
819 _csi_scanner_init (csi_t *ctx, csi_scanner_t *scanner);
821 csi_private csi_status_t
822 _csi_scan_file (csi_t *ctx, csi_file_t *src);
824 csi_private csi_status_t
825 _csi_translate_file (csi_t *ctx,
827 cairo_write_func_t write_func,
831 _csi_scanner_fini (csi_t *ctx, csi_scanner_t *scanner);
833 csi_private csi_boolean_t
834 _csi_parse_number (csi_object_t *obj, const char *s, int len);
836 /* cairo-script-stack.c */
838 csi_private csi_status_t
839 _csi_stack_init (csi_t *ctx, csi_stack_t *stack, csi_integer_t size);
842 _csi_stack_fini (csi_t *ctx, csi_stack_t *stack);
844 csi_private csi_status_t
845 _csi_stack_roll (csi_t *ctx,
850 csi_private csi_status_t
851 _csi_stack_grow (csi_t *ctx, csi_stack_t *stack, csi_integer_t cnt);
853 csi_private csi_status_t
854 _csi_stack_push_internal (csi_t *ctx, csi_stack_t *stack,
855 const csi_object_t *obj);
857 csi_private csi_object_t *
858 _csi_stack_peek (csi_stack_t *stack, csi_integer_t i);
861 _csi_stack_pop (csi_t *ctx, csi_stack_t *stack, csi_integer_t count);
863 csi_private csi_status_t
864 _csi_stack_exch (csi_stack_t *stack);
866 static inline csi_object_type_t
867 csi_object_get_type (const csi_object_t *obj)
869 return obj->type & CSI_OBJECT_TYPE_MASK;
872 static inline csi_boolean_t
873 csi_object_is_procedure (const csi_object_t *obj)
875 return obj->type == (CSI_OBJECT_TYPE_ARRAY | CSI_OBJECT_ATTR_EXECUTABLE);
878 static inline csi_boolean_t
879 csi_object_is_number (const csi_object_t *obj)
881 int type = csi_object_get_type (obj);
883 case CSI_OBJECT_TYPE_BOOLEAN:
884 case CSI_OBJECT_TYPE_INTEGER:
885 case CSI_OBJECT_TYPE_REAL:
893 csi_number_get_value (const csi_object_t *obj)
895 int type = csi_object_get_type (obj);
897 case CSI_OBJECT_TYPE_BOOLEAN: return obj->datum.boolean;
898 case CSI_OBJECT_TYPE_INTEGER: return obj->datum.integer;
899 case CSI_OBJECT_TYPE_REAL: return obj->datum.real;
904 static inline csi_status_t
905 _csi_stack_push (csi_t *ctx, csi_stack_t *stack,
906 const csi_object_t *obj)
908 if (_csi_unlikely (stack->len == stack->size))
909 return _csi_stack_push_internal (ctx, stack, obj);
911 stack->objects[stack->len++] = *obj;
912 return CSI_STATUS_SUCCESS;
915 static inline csi_boolean_t
916 _csi_check_ostack (csi_t *ctx, csi_integer_t count)
918 return ctx->ostack.len >= count;
921 static inline csi_object_t *
922 _csi_peek_ostack (csi_t *ctx, csi_integer_t i)
924 return &ctx->ostack.objects[ctx->ostack.len - i -1];
928 _csi_pop_ostack (csi_t *ctx, csi_integer_t count)
931 csi_object_free (ctx, &ctx->ostack.objects[--ctx->ostack.len]);
935 static inline csi_status_t
936 _csi_push_ostack_copy (csi_t *ctx, csi_object_t *obj)
938 return _csi_stack_push (ctx, &ctx->ostack, csi_object_reference (obj));
941 static inline csi_status_t
942 _csi_push_ostack (csi_t *ctx, csi_object_t *obj)
944 return _csi_stack_push (ctx, &ctx->ostack, obj);
947 static inline csi_status_t
948 _csi_push_ostack_boolean (csi_t *ctx, csi_boolean_t v)
951 obj.type = CSI_OBJECT_TYPE_BOOLEAN;
952 obj.datum.boolean = v;
953 return _csi_stack_push (ctx, &ctx->ostack, &obj);
955 static inline csi_status_t
956 _csi_push_ostack_integer (csi_t *ctx, csi_integer_t v)
959 obj.type = CSI_OBJECT_TYPE_INTEGER;
960 obj.datum.integer = v;
961 return _csi_stack_push (ctx, &ctx->ostack, &obj);
963 static inline csi_status_t
964 _csi_push_ostack_mark (csi_t *ctx)
967 obj.type = CSI_OBJECT_TYPE_MARK;
968 return _csi_stack_push (ctx, &ctx->ostack, &obj);
970 static inline csi_status_t
971 _csi_push_ostack_null (csi_t *ctx)
974 obj.type = CSI_OBJECT_TYPE_NULL;
975 return _csi_stack_push (ctx, &ctx->ostack, &obj);
977 static inline csi_status_t
978 _csi_push_ostack_real (csi_t *ctx, csi_real_t v)
981 obj.type = CSI_OBJECT_TYPE_REAL;
983 return _csi_stack_push (ctx, &ctx->ostack, &obj);
986 slim_hidden_proto_no_warn (cairo_script_interpreter_destroy);
987 slim_hidden_proto_no_warn (cairo_script_interpreter_reference);
989 #endif /* CAIRO_SCRIPT_PRIVATE_H */