Debian Codegraph @

src/core/Stack.nml

raw
1 /*
2 * Copyright (C)2005-2022 Haxe Foundation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23 type stack_item {
24 CFunction;
25 Module : string;
26 Pos : (string,int);
27 }
28
29 type stack = stack_item array;
30
31 neko("
32
33 @make_stack = function(a) {
34 var a = $acopy(a);
35 var i = 0;
36 var l = $asize(a);
37 while( i < l ) {
38 var k = a[i];
39 a[i] =
40 if( k == null ) CFunction else
41 if( $typeof(k) == $tstring ) Module(k) else
42 Pos(k[0],k[1]);
43 i = i + 1;
44 }
45 return @Array.@make(a);
46 }
47
48 ")
49
50 function call() : stack {
51 neko("@make_stack($callstack())");
52 }
53
54 function exc() : stack {
55 neko("@make_stack($excstack())");
56 }
57
58 function dump(ch,stack) {
59 Array.iter (function(s) {
60 match s {
61 | CFunction -> IO.write ch "Called from a C function\n"
62 | Module m -> IO.printf ch "Called from %s (no debug available)\n" m
63 | Pos (file,line) -> IO.printf ch "Called from %s line %d\n" (file,line)
64 }
65 }) stack
66 }
67
68 function print() {
69 dump(IO.stdout,call());
70 }