]> gitweb.factorcode.org Git - factor.git/blob - basis/bootstrap/image/primitives/primitives.factor
Revert "bootstrap.image.primitives: make more primitives properties be declared here"
[factor.git] / basis / bootstrap / image / primitives / primitives.factor
1 USING: alien.strings assocs io.encodings.ascii kernel kernel.private
2 locals quotations sequences words ;
3 IN: bootstrap.image.primitives
4
5 CONSTANT: all-primitives {
6     {
7         "alien"
8         {
9             { "<callback>" ( word return-rewind -- alien ) "callback" }
10             { "<displaced-alien>" ( displacement c-ptr -- alien ) "displaced_alien" }
11             { "alien-address" ( c-ptr -- addr ) "alien_address" }
12             { "free-callback" ( alien -- ) "free_callback" }
13         }
14     }
15     {
16         "alien.private"
17         {
18             { "current-callback" ( -- n ) "current_callback" }
19         }
20     }
21     {
22         "alien.accessors"
23         {
24             { "alien-cell" ( c-ptr n -- value ) "alien_cell" }
25             { "alien-double" ( c-ptr n -- value ) "alien_double" }
26             { "alien-float" ( c-ptr n -- value ) "alien_float" }
27
28             { "alien-signed-1" ( c-ptr n -- value ) "alien_signed_1" }
29             { "alien-signed-2" ( c-ptr n -- value ) "alien_signed_2" }
30             { "alien-signed-4" ( c-ptr n -- value ) "alien_signed_4" }
31             { "alien-signed-8" ( c-ptr n -- value ) "alien_signed_8" }
32             { "alien-signed-cell" ( c-ptr n -- value ) "alien_signed_cell" }
33
34             { "alien-unsigned-1" ( c-ptr n -- value ) "alien_unsigned_1" }
35             { "alien-unsigned-2" ( c-ptr n -- value ) "alien_unsigned_2" }
36             { "alien-unsigned-4" ( c-ptr n -- value ) "alien_unsigned_4" }
37             { "alien-unsigned-8" ( c-ptr n -- value ) "alien_unsigned_8" }
38             { "alien-unsigned-cell" ( c-ptr n -- value ) "alien_unsigned_cell" }
39
40             { "set-alien-cell" ( value c-ptr n -- ) "set_alien_cell" }
41             { "set-alien-double" ( value c-ptr n -- ) "set_alien_double" }
42             { "set-alien-float" ( value c-ptr n -- ) "set_alien_float" }
43
44             { "set-alien-signed-1" ( value c-ptr n -- ) "set_alien_signed_1" }
45             { "set-alien-signed-2" ( value c-ptr n -- ) "set_alien_signed_2" }
46             { "set-alien-signed-4" ( value c-ptr n -- ) "set_alien_signed_4" }
47             { "set-alien-signed-8" ( value c-ptr n -- ) "set_alien_signed_8" }
48             { "set-alien-signed-cell" ( value c-ptr n -- ) "set_alien_signed_cell" }
49
50             { "set-alien-unsigned-1" ( value c-ptr n -- ) "set_alien_unsigned_1" }
51             { "set-alien-unsigned-2" ( value c-ptr n -- ) "set_alien_unsigned_2" }
52             { "set-alien-unsigned-4" ( value c-ptr n -- ) "set_alien_unsigned_4" }
53             { "set-alien-unsigned-8" ( value c-ptr n -- ) "set_alien_unsigned_8" }
54             { "set-alien-unsigned-cell" ( value c-ptr n -- ) "set_alien_unsigned_cell" }
55         }
56     }
57     {
58         "alien.libraries"
59         {
60             { "(dlopen)" ( path -- dll ) "dlopen" }
61             { "(dlsym)" ( name dll -- alien ) "dlsym" }
62             { "(dlsym-raw)" ( name dll -- alien ) "dlsym_raw" }
63             { "dlclose" ( dll -- ) "dlclose" }
64             { "dll-valid?" ( dll -- ? ) "dll_validp" }
65         }
66     }
67     {
68         "arrays"
69         {
70             { "<array>" ( n elt -- array ) "array" }
71             { "resize-array" ( n array -- new-array ) "resize_array" }
72         }
73     }
74     {
75         "byte-arrays"
76         {
77             { "(byte-array)" ( n -- byte-array ) "uninitialized_byte_array" }
78             { "<byte-array>" ( n -- byte-array ) "byte_array" }
79             {
80                 "resize-byte-array" ( n byte-array -- new-byte-array )
81                 "resize_byte_array"
82             }
83         }
84     }
85     {
86         "classes.tuple.private"
87         {
88             { "<tuple-boa>" ( slots... layout -- tuple ) "tuple_boa" }
89             { "<tuple>" ( layout -- tuple ) "tuple" }
90         }
91     }
92     {
93         "compiler.units"
94         {
95             {
96                 "modify-code-heap" ( alist update-existing? reset-pics? -- )
97                 "modify_code_heap"
98             }
99         }
100     }
101     {
102         "generic.single.private"
103         {
104             { "inline-cache-miss" ( generic methods index cache -- ) f }
105             { "inline-cache-miss-tail" ( generic methods index cache -- ) f }
106             { "lookup-method" ( object methods -- method ) "lookup_method" }
107             { "mega-cache-lookup" ( methods index cache -- ) f }
108             { "mega-cache-miss" ( methods index cache -- method ) "mega_cache_miss" }
109         }
110     }
111     {
112         "io.files.private"
113         {
114             { "(exists?)" ( path -- ? ) "existsp" }
115         }
116     }
117     {
118         "io.streams.c"
119         {
120             { "(fopen)" ( path mode -- alien ) "fopen" }
121             { "fclose" ( alien -- ) "fclose" }
122             { "fflush" ( alien -- ) "fflush" }
123             { "fgetc" ( alien -- byte/f ) "fgetc" }
124             { "fputc" ( byte alien -- ) "fputc" }
125             { "fread-unsafe" ( n buf alien -- count ) "fread" }
126             { "fseek" ( alien offset whence -- ) "fseek" }
127             { "ftell" ( alien -- n ) "ftell" }
128             { "fwrite" ( data length alien -- ) "fwrite" }
129         }
130     }
131     {
132         "kernel"
133         {
134             { "(clone)" ( obj -- newobj ) "clone" }
135             { "<wrapper>" ( obj -- wrapper ) "wrapper" }
136             { "callstack>array" ( callstack -- array ) "callstack_to_array" }
137             { "die" ( -- ) "die" }
138             { "drop" ( x -- ) f }
139             { "2drop" ( x y -- ) f }
140             { "3drop" ( x y z -- ) f }
141             { "4drop" ( w x y z -- ) f }
142             { "dup" ( x -- x x ) f }
143             { "2dup" ( x y -- x y x y ) f }
144             { "3dup" ( x y z -- x y z x y z ) f }
145             { "4dup" ( w x y z -- w x y z w x y z ) f }
146             { "rot" ( x y z -- y z x ) f }
147             { "-rot" ( x y z -- z x y ) f }
148             { "dupd" ( x y -- x x y ) f }
149             { "swapd" ( x y z -- y x z ) f }
150             { "nip" ( x y -- y ) f }
151             { "2nip" ( x y z -- z ) f }
152             { "over" ( x y -- x y x ) f }
153             { "pick" ( x y z -- x y z x ) f }
154             { "swap" ( x y -- y x ) f }
155             { "eq?" ( obj1 obj2 -- ? ) f }
156         }
157     }
158     {
159         "kernel.private"
160         {
161             { "(call)" ( quot -- ) f }
162             { "(execute)" ( word -- ) f }
163             { "c-to-factor" ( -- ) f }
164             { "fpu-state" ( -- ) f }
165             { "lazy-jit-compile" ( -- ) f }
166             { "leaf-signal-handler" ( -- ) f }
167             { "set-callstack" ( callstack -- * ) f }
168             { "set-fpu-state" ( -- ) f }
169             { "signal-handler" ( -- ) f }
170             { "tag" ( object -- n ) f }
171             { "unwind-native-frames" ( -- ) f }
172
173             { "callstack-for" ( context -- array ) "callstack_for" }
174             { "datastack-for" ( context -- array ) "datastack_for" }
175             { "retainstack-for" ( context -- array ) "retainstack_for" }
176             { "(identity-hashcode)" ( obj -- code ) "identity_hashcode" }
177             { "become" ( old new -- ) "become" }
178             { "callstack-bounds" ( -- start end ) "callstack_bounds" }
179             { "check-datastack" ( array in# out# -- ? ) "check_datastack" }
180             { "compute-identity-hashcode" ( obj -- ) "compute_identity_hashcode" }
181             { "context-object" ( n -- obj ) "context_object" }
182             {
183                 "innermost-frame-executing" ( callstack -- obj )
184                 "innermost_stack_frame_executing"
185             }
186             {
187                 "innermost-frame-scan" ( callstack -- n )
188                 "innermost_stack_frame_scan"
189             }
190             { "set-context-object" ( obj n -- ) "set_context_object" }
191             { "set-datastack" ( array -- ) "set_datastack" }
192             {
193                 "set-innermost-frame-quotation" ( n callstack -- )
194                 "set_innermost_stack_frame_quotation"
195             }
196             { "set-retainstack" ( array -- ) "set_retainstack" }
197             { "set-special-object" ( obj n -- ) "set_special_object" }
198             { "special-object" ( n -- obj ) "special_object" }
199             { "strip-stack-traces" ( -- ) "strip_stack_traces" }
200             { "unimplemented" ( -- * ) "unimplemented" }
201         }
202     }
203     {
204         "locals.backend"
205         {
206             { "drop-locals" ( n -- ) f }
207             { "get-local" ( n -- obj ) f }
208             { "load-local" ( obj -- ) f }
209             { "load-locals" ( ... n -- ) "load_locals" }
210         }
211     }
212     {
213         "math"
214         {
215             { "bits>double" ( n -- x ) "bits_double" }
216             { "bits>float" ( n -- x ) "bits_float" }
217             { "double>bits" ( x -- n ) "double_bits" }
218             { "float>bits" ( x -- n ) "float_bits" }
219         }
220     }
221     {
222         "math.parser.private"
223         {
224             {
225                 "(format-float)" ( n fill width precision format locale -- byte-array )
226                 "format_float"
227             }
228         }
229     }
230     {
231         "math.private"
232         {
233             { "both-fixnums?" ( x y -- ? ) f }
234             { "fixnum+fast" ( x y -- z ) f }
235             { "fixnum-fast" ( x y -- z ) f }
236             { "fixnum*fast" ( x y -- z ) f }
237             { "fixnum-bitand" ( x y -- z ) f }
238             { "fixnum-bitor" ( x y -- z ) f }
239             { "fixnum-bitxor" ( x y -- z ) f }
240             { "fixnum-bitnot" ( x -- y ) f }
241             { "fixnum-mod" ( x y -- z ) f }
242             { "fixnum-shift-fast" ( x y -- z ) f }
243             { "fixnum/i-fast" ( x y -- z ) f }
244             { "fixnum/mod-fast" ( x y -- z w ) f }
245             { "fixnum+" ( x y -- z ) f }
246             { "fixnum-" ( x y -- z ) f }
247             { "fixnum*" ( x y -- z ) f }
248             { "fixnum<" ( x y -- ? ) f }
249             { "fixnum<=" ( x y -- z ) f }
250             { "fixnum>" ( x y -- ? ) f }
251             { "fixnum>=" ( x y -- ? ) f }
252
253             { "bignum*" ( x y -- z ) "bignum_multiply" }
254             { "bignum+" ( x y -- z ) "bignum_add" }
255             { "bignum-" ( x y -- z ) "bignum_subtract" }
256             { "bignum-bit?" ( x n -- ? ) "bignum_bitp" }
257             { "bignum-bitand" ( x y -- z ) "bignum_and" }
258             { "bignum-bitnot" ( x -- y ) "bignum_not" }
259             { "bignum-bitor" ( x y -- z ) "bignum_or" }
260             { "bignum-bitxor" ( x y -- z ) "bignum_xor" }
261             { "bignum-log2" ( x -- n ) "bignum_log2" }
262             { "bignum-mod" ( x y -- z ) "bignum_mod" }
263             { "bignum-gcd" ( x y -- z ) "bignum_gcd" }
264             { "bignum-shift" ( x y -- z ) "bignum_shift" }
265             { "bignum/i" ( x y -- z ) "bignum_divint" }
266             { "bignum/mod" ( x y -- z w ) "bignum_divmod" }
267             { "bignum<" ( x y -- ? ) "bignum_less" }
268             { "bignum<=" ( x y -- ? ) "bignum_lesseq" }
269             { "bignum=" ( x y -- ? ) "bignum_eq" }
270             { "bignum>" ( x y -- ? ) "bignum_greater" }
271             { "bignum>=" ( x y -- ? ) "bignum_greatereq" }
272             { "bignum>fixnum" ( x -- y ) "bignum_to_fixnum" }
273             { "bignum>fixnum-strict" ( x -- y ) "bignum_to_fixnum_strict" }
274             { "fixnum-shift" ( x y -- z ) "fixnum_shift" }
275             { "fixnum/i" ( x y -- z ) "fixnum_divint" }
276             { "fixnum/mod" ( x y -- z w ) "fixnum_divmod" }
277             { "fixnum>bignum" ( x -- y ) "fixnum_to_bignum" }
278             { "fixnum>float" ( x -- y ) "fixnum_to_float" }
279             { "float*" ( x y -- z ) "float_multiply" }
280             { "float+" ( x y -- z ) "float_add" }
281             { "float-" ( x y -- z ) "float_subtract" }
282             { "float-u<" ( x y -- ? ) "float_less" }
283             { "float-u<=" ( x y -- ? ) "float_lesseq" }
284             { "float-u>" ( x y -- ? ) "float_greater" }
285             { "float-u>=" ( x y -- ? ) "float_greatereq" }
286             { "float/f" ( x y -- z ) "float_divfloat" }
287             { "float<" ( x y -- ? ) "float_less" }
288             { "float<=" ( x y -- ? ) "float_lesseq" }
289             { "float=" ( x y -- ? ) "float_eq" }
290             { "float>" ( x y -- ? ) "float_greater" }
291             { "float>=" ( x y -- ? ) "float_greatereq" }
292             { "float>bignum" ( x -- y ) "float_to_bignum" }
293             { "float>fixnum" ( x -- y ) "float_to_fixnum" }
294         }
295     }
296     {
297         "memory"
298         {
299             { "all-instances" ( -- array ) "all_instances" }
300             { "compact-gc" ( -- ) "compact_gc" }
301             { "gc" ( -- ) "full_gc" }
302             { "minor-gc" ( -- ) "minor_gc" }
303             { "size" ( obj -- n ) "size" }
304         }
305     }
306     {
307         "memory.private"
308         {
309             { "(save-image)" ( path1 path2 then-die? -- ) "save_image" }
310         }
311     }
312     {
313         "quotations"
314         {
315             { "jit-compile" ( quot -- ) "jit_compile" }
316             { "quotation-code" ( quot -- start end ) "quotation_code" }
317             { "quotation-compiled?" ( quot -- ? ) "quotation_compiled_p" }
318         }
319     }
320     {
321         "quotations.private"
322         {
323             { "array>quotation" ( array -- quot ) "array_to_quotation" }
324         }
325     }
326     {
327         "slots.private"
328         {
329             { "set-slot" ( value obj n -- ) "set_slot" }
330             { "slot" ( obj m -- value ) f }
331         }
332     }
333     {
334         "strings"
335         {
336             { "<string>" ( n ch -- string ) "string" }
337             { "resize-string" ( n str -- newstr ) "resize_string" }
338         }
339     }
340     {
341         "strings.private"
342         {
343             { "set-string-nth-fast" ( ch n string -- ) "set_string_nth_fast" }
344             { "string-nth-fast" ( n string -- ch ) f }
345         }
346     }
347     {
348         "system"
349         {
350             { "(exit)" ( n -- * ) "exit" }
351             { "nano-count" ( -- ns ) "nano_count" }
352         }
353     }
354     {
355         "threads.private"
356         {
357             { "(sleep)" ( nanos -- ) "sleep" }
358             { "(set-context)" ( obj context -- obj' ) f }
359             { "(set-context-and-delete)" ( obj context -- * ) f }
360             { "(start-context)" ( obj quot -- obj' ) f }
361             { "(start-context-and-delete)" ( obj quot -- * ) f }
362             { "context-object-for" ( n context -- obj ) "context_object_for" }
363         }
364     }
365     {
366         "tools.dispatch.private"
367         {
368             { "dispatch-stats" ( -- stats ) "dispatch_stats" }
369             { "reset-dispatch-stats" ( -- ) "reset_dispatch_stats" }
370         }
371     }
372     {
373         "tools.memory.private"
374         {
375             { "(callback-room)" ( -- allocator-room ) "callback_room" }
376             { "(code-blocks)" ( -- array ) "code_blocks" }
377             { "(code-room)" ( -- allocator-room ) "code_room" }
378             { "(data-room)" ( -- data-room ) "data_room" }
379             { "disable-gc-events" ( -- events ) "disable_gc_events" }
380             { "enable-gc-events" ( -- ) "enable_gc_events" }
381         }
382     }
383     {
384         "tools.profiler.sampling.private"
385         {
386             { "profiling" ( ? -- ) "sampling_profiler" }
387             { "(get-samples)" ( -- samples/f ) "get_samples" }
388             { "(clear-samples)" ( -- ) "clear_samples" }
389         }
390     }
391     {
392         "words"
393         {
394             { "word-code" ( word -- start end ) "word_code" }
395             { "word-optimized?" ( word -- ? ) "word_optimized_p" }
396         }
397     }
398     {
399         "words.private"
400         {
401             { "(word)" ( name vocab hashcode -- word ) "word" }
402         }
403     }
404 }
405
406 : primitive-quot ( word vm-func -- quot )
407     [
408         nip "primitive_" prepend ascii string>alien [ do-primitive ] curry
409     ] [ 1quotation ] if* ;
410
411 : primitive-word ( name vocab -- word )
412     create-word dup t "primitive" set-word-prop ;
413
414 :: create-primitive ( vocab word effect vm-func -- )
415     word vocab primitive-word
416     dup vm-func primitive-quot effect define-declared ;
417
418 : create-primitives ( assoc -- )
419     [ [ first3 create-primitive ] with each ] assoc-each ;