1
0
Fork 0
forked from fun/fun

Jump into REPL when executing with --repl-on-error and an error occurs, when the REPL is builtin you will have access to the full stack then. (0.25.0)

This commit is contained in:
Johannes Findeisen 2025-10-06 04:10:36 +02:00
commit c71857a068
9 changed files with 309 additions and 7 deletions

View file

@ -1,44 +0,0 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://hanez.org/project/fun/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*
* Added: 2025-10-02
*/
// PCSC demo using stdlib PCSC class.
// Establishes context, lists readers, optionally connects to the first,
// transmits a sample APDU (SELECT MF), and cleans up.
#include <io/pcsc.fun>
pc = PCSC()
ctx = pc.establish()
print("ctx=" + to_string(ctx))
readers = pc.list_readers(ctx)
print("readers=" + to_string(readers))
number h = 0
if len(readers) > 0
// Connect to first reader
h = pc.connect(ctx, readers[1])
print("handle=" + to_string(h))
if h != 0
// Sample APDU: SELECT MF (00 A4 00 00 02 3F 00)
resp = pc.transmit_hex(h, "00A40000023F00")
// Print hex data and SW
print("resp.data_hex=" + resp["data_hex"])
print("resp.sw1=" + to_string(resp["sw1"]) + " sw2=" + to_string(resp["sw2"]) + " code=" + to_string(resp["code"]))
_ = pc.disconnect(h)
_ = pc.release(ctx)
print("done")

View file

@ -0,0 +1,42 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://hanez.org/project/fun/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*
* Added: 2025-10-06
*/
// Demonstration of --repl-on-error debugging.
// Run: fun --repl-on-error examples/repl_on_error.fun
// When the runtime error occurs, the REPL opens. Try commands:
// :backtrace
// :stack
// :locals
//
// This script triggers an index-out-of-range error inside a nested call.
fun inner()
a = [1, 2, 3]
// Out-of-range access to cause a runtime error:
print(a[10])
fun outer()
inner()
outer()
/* Expected output (ruuning with --repl-on-error you will end up in the REPL
* with full stack access; :backtrace, :stack and :locals):
Runtime error: index out of range
(at ./examples/repl_on_error.fun:12 in inner, op INDEX_GET @ip 9)
Entering REPL due to runtime error (code 1)
(at ./examples/repl_on_error.fun:12 in inner, op INDEX_GET @ip 9)
Fun 0.25.0 REPL
Type :help for commands. Submit an empty line to run.
fun>
*/