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;
403 typedef struct _csi_filter_funcs {
404 int (*filter_getc) (csi_file_t *);
405 void (*filter_putc) (csi_file_t *, int);
406 int (*filter_read) (csi_file_t *, uint8_t *, int);
407 void (*filter_destroy) (csi_t *, void *);
408 } csi_filter_funcs_t;
411 csi_compound_object_t base;
423 const csi_filter_funcs_t *filter;
426 union _csi_union_object {
430 csi_dictionary_t dictionary;
437 struct _csi_scanner {
442 csi_status_t (*push) (csi_t *ctx, csi_object_t *obj);
443 csi_status_t (*execute) (csi_t *ctx, csi_object_t *obj);
447 csi_stack_t procedure_stack;
448 csi_object_t build_procedure;
450 unsigned int accumulator;
451 unsigned int accumulator_count;
453 unsigned int line_number;
456 typedef cairo_script_interpreter_hooks_t csi_hooks_t;
458 typedef struct _csi_chunk {
459 struct _csi_chunk *next;
464 struct _cairo_script_interpreter {
468 unsigned int finished : 1;
472 csi_hash_table_t strings;
477 csi_scanner_t scanner;
479 csi_chunk_t *perm_chunk;
484 csi_array_t *free_array;
485 csi_dictionary_t *free_dictionary;
486 csi_string_t *free_string;
488 csi_operator_t opcode[256];
490 /* caches of live data */
495 typedef struct _csi_operator_def {
498 } csi_operator_def_t;
500 typedef struct _csi_integer_constant_def {
503 } csi_integer_constant_def_t;
505 typedef struct _csi_real_constant_def {
508 } csi_real_constant_def_t;
510 /* cairo-script-file.c */
512 csi_private csi_status_t
513 csi_file_new (csi_t *ctx,
515 const char *path, const char *mode);
517 csi_private csi_status_t
518 csi_file_new_for_stream (csi_t *ctx,
522 csi_private csi_status_t
523 csi_file_new_for_bytes (csi_t *ctx,
526 unsigned int length);
528 csi_private csi_status_t
529 csi_file_new_from_string (csi_t *ctx,
533 csi_private csi_status_t
534 csi_file_new_ascii85_decode (csi_t *ctx,
536 csi_dictionary_t *dict,
539 csi_private csi_status_t
540 csi_file_new_deflate_decode (csi_t *ctx,
542 csi_dictionary_t *dict,
545 csi_private csi_status_t
546 _csi_file_execute (csi_t *ctx, csi_file_t *obj);
549 csi_file_getc (csi_file_t *obj);
552 csi_file_read (csi_file_t *obj, void *buf, int len);
555 csi_file_putc (csi_file_t *obj, int c);
558 csi_file_flush (csi_file_t *obj);
561 csi_file_close (csi_t *ctx, csi_file_t *obj);
564 _csi_file_free (csi_t *ctx, csi_file_t *obj);
566 csi_private csi_status_t
567 _csi_file_as_string (csi_t *ctx,
571 /* cairo-script-hash.c */
573 csi_private csi_status_t
574 _csi_hash_table_init (csi_hash_table_t *hash_table,
575 csi_hash_keys_equal_func_t keys_equal);
578 _csi_hash_table_fini (csi_hash_table_t *hash_table);
581 _csi_hash_table_lookup (csi_hash_table_t *hash_table,
582 csi_hash_entry_t *key);
584 csi_private csi_status_t
585 _csi_hash_table_insert (csi_hash_table_t *hash_table,
586 csi_hash_entry_t *entry);
589 _csi_hash_table_remove (csi_hash_table_t *hash_table,
590 csi_hash_entry_t *key);
593 _csi_hash_table_foreach (csi_hash_table_t *hash_table,
594 csi_hash_callback_func_t hash_callback,
597 /* cairo-script-interpreter.c */
600 _csi_alloc (csi_t *ctx, int size);
603 _csi_alloc0 (csi_t *ctx, int size);
606 _csi_realloc (csi_t *ctx, void *ptr, int size);
609 _csi_free (csi_t *ctx, void *ptr);
612 _csi_slab_alloc (csi_t *ctx, int size);
615 _csi_perm_alloc (csi_t *ctx, int size);
618 _csi_slab_free (csi_t *ctx, void *ptr, int size);
620 csi_private csi_status_t
621 csi_push_ostack (csi_t *ctx, csi_object_t *obj);
623 csi_private csi_status_t
624 _csi_name_define (csi_t *ctx, csi_name_t name, csi_object_t *obj);
626 csi_private csi_status_t
627 _csi_name_lookup (csi_t *ctx, csi_name_t name, csi_object_t *obj);
629 csi_private csi_status_t
630 _csi_name_undefine (csi_t *ctx, csi_name_t name);
632 csi_private csi_status_t
633 _csi_intern_string (csi_t *ctx, const char **str_inout, int len);
635 csi_private csi_status_t
636 _csi_error (csi_status_t status);
638 /* cairo-script-objects.c */
640 csi_private csi_status_t
641 csi_array_new (csi_t *ctx,
642 csi_integer_t initial_size,
645 csi_private csi_status_t
646 _csi_array_execute (csi_t *ctx, csi_array_t *array);
648 csi_private csi_status_t
649 csi_array_get (csi_t *ctx,
652 csi_object_t *value);
654 csi_private csi_status_t
655 csi_array_put (csi_t *ctx,
658 csi_object_t *value);
660 csi_private csi_status_t
661 csi_array_append (csi_t *ctx,
666 csi_array_free (csi_t *ctx, csi_array_t *array);
669 csi_boolean_new (csi_object_t *obj,
672 obj->type = CSI_OBJECT_TYPE_BOOLEAN;
673 obj->datum.boolean = v;
676 csi_private csi_status_t
677 csi_dictionary_new (csi_t *ctx,
680 csi_private csi_status_t
681 csi_dictionary_put (csi_t *ctx,
682 csi_dictionary_t *dict,
684 csi_object_t *value);
686 csi_private csi_status_t
687 csi_dictionary_get (csi_t *ctx,
688 csi_dictionary_t *dict,
690 csi_object_t *value);
692 csi_private csi_boolean_t
693 csi_dictionary_has (csi_dictionary_t *dict,
697 csi_dictionary_remove (csi_t *ctx,
698 csi_dictionary_t *dict,
702 csi_dictionary_free (csi_t *ctx,
703 csi_dictionary_t *dict);
706 csi_integer_new (csi_object_t *obj,
709 obj->type = CSI_OBJECT_TYPE_INTEGER;
710 obj->datum.integer = v;
714 csi_private csi_status_t
715 csi_matrix_new (csi_t *ctx,
718 csi_private csi_status_t
719 csi_matrix_new_from_array (csi_t *ctx,
723 csi_private csi_status_t
724 csi_matrix_new_from_matrix (csi_t *ctx,
726 const cairo_matrix_t *m);
728 csi_private csi_status_t
729 csi_matrix_new_from_values (csi_t *ctx,
734 csi_matrix_free (csi_t *ctx,
737 csi_private csi_status_t
738 csi_name_new (csi_t *ctx,
743 csi_private csi_status_t
744 csi_name_new_static (csi_t *ctx,
749 csi_operator_new (csi_object_t *obj,
752 obj->type = CSI_OBJECT_TYPE_OPERATOR | CSI_OBJECT_ATTR_EXECUTABLE;
757 csi_real_new (csi_object_t *obj,
760 obj->type = CSI_OBJECT_TYPE_REAL;
764 csi_private csi_status_t
765 csi_string_new (csi_t *ctx,
770 csi_private csi_status_t
771 csi_string_deflate_new (csi_t *ctx,
777 csi_private csi_status_t
778 csi_string_new_from_bytes (csi_t *ctx,
784 csi_string_free (csi_t *ctx, csi_string_t *string);
786 csi_private csi_status_t
787 csi_object_execute (csi_t *ctx, csi_object_t *obj);
789 csi_private csi_object_t *
790 csi_object_reference (csi_object_t *obj);
793 csi_object_free (csi_t *ctx,
796 csi_private csi_status_t
797 csi_object_as_file (csi_t *ctx,
801 csi_private csi_boolean_t
802 csi_object_eq (csi_object_t *a,
805 csi_private csi_status_t
806 csi_object_compare (csi_object_t *a,
810 /* cairo-script-operators.c */
812 csi_private const csi_operator_def_t *
813 _csi_operators (void);
815 csi_private const csi_integer_constant_def_t *
816 _csi_integer_constants (void);
818 csi_private const csi_real_constant_def_t *
819 _csi_real_constants (void);
821 /* cairo-script-scanner.c */
823 csi_private csi_status_t
824 _csi_scanner_init (csi_t *ctx, csi_scanner_t *scanner);
826 csi_private csi_status_t
827 _csi_scan_file (csi_t *ctx, csi_file_t *src);
829 csi_private csi_status_t
830 _csi_translate_file (csi_t *ctx,
832 cairo_write_func_t write_func,
836 _csi_scanner_fini (csi_t *ctx, csi_scanner_t *scanner);
838 csi_private csi_boolean_t
839 _csi_parse_number (csi_object_t *obj, const char *s, int len);
841 /* cairo-script-stack.c */
843 csi_private csi_status_t
844 _csi_stack_init (csi_t *ctx, csi_stack_t *stack, csi_integer_t size);
847 _csi_stack_fini (csi_t *ctx, csi_stack_t *stack);
849 csi_private csi_status_t
850 _csi_stack_roll (csi_t *ctx,
855 csi_private csi_status_t
856 _csi_stack_grow (csi_t *ctx, csi_stack_t *stack, csi_integer_t cnt);
858 csi_private csi_status_t
859 _csi_stack_push_internal (csi_t *ctx, csi_stack_t *stack,
860 const csi_object_t *obj);
862 csi_private csi_object_t *
863 _csi_stack_peek (csi_stack_t *stack, csi_integer_t i);
866 _csi_stack_pop (csi_t *ctx, csi_stack_t *stack, csi_integer_t count);
868 csi_private csi_status_t
869 _csi_stack_exch (csi_stack_t *stack);
871 static inline csi_object_type_t
872 csi_object_get_type (const csi_object_t *obj)
874 return obj->type & CSI_OBJECT_TYPE_MASK;
877 static inline csi_boolean_t
878 csi_object_is_procedure (const csi_object_t *obj)
880 return obj->type == (CSI_OBJECT_TYPE_ARRAY | CSI_OBJECT_ATTR_EXECUTABLE);
883 static inline csi_boolean_t
884 csi_object_is_number (const csi_object_t *obj)
886 int type = csi_object_get_type (obj);
888 case CSI_OBJECT_TYPE_BOOLEAN:
889 case CSI_OBJECT_TYPE_INTEGER:
890 case CSI_OBJECT_TYPE_REAL:
898 csi_number_get_value (const csi_object_t *obj)
900 int type = csi_object_get_type (obj);
902 case CSI_OBJECT_TYPE_BOOLEAN: return obj->datum.boolean;
903 case CSI_OBJECT_TYPE_INTEGER: return obj->datum.integer;
904 case CSI_OBJECT_TYPE_REAL: return obj->datum.real;
909 static inline csi_status_t
910 _csi_stack_push (csi_t *ctx, csi_stack_t *stack,
911 const csi_object_t *obj)
913 if (_csi_unlikely (stack->len == stack->size))
914 return _csi_stack_push_internal (ctx, stack, obj);
916 stack->objects[stack->len++] = *obj;
917 return CSI_STATUS_SUCCESS;
920 static inline csi_boolean_t
921 _csi_check_ostack (csi_t *ctx, csi_integer_t count)
923 return ctx->ostack.len >= count;
926 static inline csi_object_t *
927 _csi_peek_ostack (csi_t *ctx, csi_integer_t i)
929 return &ctx->ostack.objects[ctx->ostack.len - i -1];
933 _csi_pop_ostack (csi_t *ctx, csi_integer_t count)
936 csi_object_free (ctx, &ctx->ostack.objects[--ctx->ostack.len]);
940 static inline csi_status_t
941 _csi_push_ostack_copy (csi_t *ctx, csi_object_t *obj)
943 return _csi_stack_push (ctx, &ctx->ostack, csi_object_reference (obj));
946 static inline csi_status_t
947 _csi_push_ostack (csi_t *ctx, csi_object_t *obj)
949 return _csi_stack_push (ctx, &ctx->ostack, obj);
952 static inline csi_status_t
953 _csi_push_ostack_boolean (csi_t *ctx, csi_boolean_t v)
956 obj.type = CSI_OBJECT_TYPE_BOOLEAN;
957 obj.datum.boolean = v;
958 return _csi_stack_push (ctx, &ctx->ostack, &obj);
960 static inline csi_status_t
961 _csi_push_ostack_integer (csi_t *ctx, csi_integer_t v)
964 obj.type = CSI_OBJECT_TYPE_INTEGER;
965 obj.datum.integer = v;
966 return _csi_stack_push (ctx, &ctx->ostack, &obj);
968 static inline csi_status_t
969 _csi_push_ostack_mark (csi_t *ctx)
972 obj.type = CSI_OBJECT_TYPE_MARK;
973 return _csi_stack_push (ctx, &ctx->ostack, &obj);
975 static inline csi_status_t
976 _csi_push_ostack_null (csi_t *ctx)
979 obj.type = CSI_OBJECT_TYPE_NULL;
980 return _csi_stack_push (ctx, &ctx->ostack, &obj);
982 static inline csi_status_t
983 _csi_push_ostack_real (csi_t *ctx, csi_real_t v)
986 obj.type = CSI_OBJECT_TYPE_REAL;
988 return _csi_stack_push (ctx, &ctx->ostack, &obj);
991 slim_hidden_proto_no_warn (cairo_script_interpreter_destroy);
992 slim_hidden_proto_no_warn (cairo_script_interpreter_reference);
994 #endif /* CAIRO_SCRIPT_PRIVATE_H */