/* * Copyright (C)2005-2022 Haxe Foundation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ type stack_item { CFunction; Module : string; Pos : (string,int); } type stack = stack_item array; neko(" @make_stack = function(a) { var a = $acopy(a); var i = 0; var l = $asize(a); while( i < l ) { var k = a[i]; a[i] = if( k == null ) CFunction else if( $typeof(k) == $tstring ) Module(k) else Pos(k[0],k[1]); i = i + 1; } return @Array.@make(a); } ") function call() : stack { neko("@make_stack($callstack())"); } function exc() : stack { neko("@make_stack($excstack())"); } function dump(ch,stack) { Array.iter (function(s) { match s { | CFunction -> IO.write ch "Called from a C function\n" | Module m -> IO.printf ch "Called from %s (no debug available)\n" m | Pos (file,line) -> IO.printf ch "Called from %s line %d\n" (file,line) } }) stack } function print() { dump(IO.stdout,call()); }