Author Topic: TinyScheme  (Read 63626 times)

0 Members and 1 Guest are viewing this topic.

RobbeK

  • Guest
Re: TinyScheme
« Reply #45 on: August 27, 2014, 01:52:36 AM »
Hi Mike,

It are arrays (or vectors talking Scheme) of the digit type

http://www.clisp.org/impnotes/num-concepts.html

oops , page seems down :  from my documentation

------------------------------------------
12.2.2.2. Bignum Limits

BIGNUMs are limited in size. Their maximum size is 32*(216-2)=2097088 bits. The largest representable BIGNUM is therefore 2^2097088-1.
12.2.2.3. Float Limits

Together with PI, the other LONG-FLOAT constants
LEAST-NEGATIVE-LONG-FLOAT   LONG-FLOAT-EPSILON
LEAST-NEGATIVE-NORMALIZED-LONG-FLOAT   LONG-FLOAT-NEGATIVE-EPSILON
LEAST-POSITIVE-LONG-FLOAT   MOST-NEGATIVE-LONG-FLOAT
LEAST-POSITIVE-NORMALIZED-LONG-FLOAT   MOST-POSITIVE-LONG-FLOAT

are recomputed whenever (EXT:LONG-FLOAT-DIGITS) is SETFed. They are not constant variables.
Warning

Since the exponent of a LONG-FLOAT is a signed 32-bits integer, MOST-POSITIVE-LONG-FLOAT is about 2231, which is much larger that the largest representable BIGNUM, which is less than 2221. This, obviously, means that ROUND, TRUNCATE, FLOOR and CEILING SIGNALs an ERROR on large LONG-FLOATs. Less obviously, this means that (FORMAT NIL "~E" MOST-POSITIVE-LONG-FLOAT) also fails.

--------------------------- 

NewLisp uses the GMP  library which is only limitid by the available memory :
https://gmplib.org/pi-with-gmp.html

Speaking about big-numbers and Lisp macro's , I wrote something to memoize Fibonacci numbers //  I'll work out something more clever, memoizing all fibonacci numbers lower than an entry  -- here, try 30000 and 30000 again (the second time is should take no time)

(showing how Lisp becomes a programmable programming language )

best Rob    (btw : this is Lisp running in interpreted mode)
---  also found a pdf describing the first LISP written by McCarthy (MIT) from the end 1950s  -- could be perfectly rewritten/ simulated  by a modern CL/Scheme/NewLisp app.

--  addendum , (after some thinking) a more clever memoizing needs the definition to be resursive in the way the "index" is counted down , this way it can stop calculation the moment a (lower) value matches.
NewLisp has very limited recursive capabilities and CLisp doesn't do tail call optimizations -- GCL does and also (most?) Schemes , but the question is , when the compiler converts into iteration is the function than still recongnizable for memoizing ??  (is there a difference between lexical and dynamical scoping then ????)

-- addendum 2 :   8)  it works !!!  functions need to be declared in a recursive way so that the memoized can be recongized during execution.
Due to the very limited stack in example 2 start with 100 (higher numbers will crash the system) , now you can build up higher p.e. (fib 120 will take no time , because (fib 100) is already known -- hmm , one can build in steps of 100 upwards  now, every multiple of 100 will be memoized then , and every calculation < the highest memoized will take no time ... 
yes, final result added in memofinal.exe -- calculations below 100000 should take no time now


.
« Last Edit: August 27, 2014, 04:09:21 AM by RobbeK »

JRS

  • Guest
Re: TinyScheme
« Reply #46 on: August 27, 2014, 07:42:46 AM »
Here is a nm dump of the libtinyscheme.so shared object. What has me confused if the following call.

void scheme_set_output_port_string(scheme *sc, char *start, char *past_the_end);

Do I pass a SB buffer string for start and  CHR$(0) for past_the_end?

It looks to me that this function is asking for a character in some string buffer to start with and a character beyond the end the string you want. Like a MID$() I guess. I'm open to all thoughts on how this is suppose to work.


Code: [Select]
jrs@laptop:~/tinyscheme/tinyscheme-1.41$ nm libtinyscheme.so
0000000000007c22 t Eval_Cycle
0000000000211db0 a _DYNAMIC
00000000000079f2 t _Error_1
0000000000211fe8 a _GLOBAL_OFFSET_TABLE_
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
                 w _Jv_RegisterClasses
0000000000011608 r __FRAME_END__
0000000000211ca0 d __JCR_END__
0000000000211ca0 d __JCR_LIST__
0000000000213bc0 d __TMC_END__
0000000000213bc0 A __bss_start
                 U __ctype_b_loc@@GLIBC_2.3
                 U __ctype_tolower_loc@@GLIBC_2.3
                 U __ctype_toupper_loc@@GLIBC_2.3
                 w __cxa_finalize@@GLIBC_2.2.5
00000000000056b0 t __do_global_dtors_aux
0000000000211c98 t __do_global_dtors_aux_fini_array_entry
0000000000212340 d __dso_handle
                 U __fprintf_chk@@GLIBC_2.3.4
0000000000211c90 t __frame_dummy_init_array_entry
                 w __gmon_start__
                 U __isoc99_sscanf@@GLIBC_2.7
                 U __printf_chk@@GLIBC_2.3.4
                 U __snprintf_chk@@GLIBC_2.3.4
                 U __stack_chk_fail@@GLIBC_2.4
                 U __strcat_chk@@GLIBC_2.3.4
                 U __strcpy_chk@@GLIBC_2.3.4
0000000000007817 T _cons
0000000000213bc0 A _edata
0000000000213bf0 A _end
000000000000eb14 T _fini
0000000000004fb0 T _init
0000000000005f15 t _s_return
                 U access@@GLIBC_2.2.5
                 U acos@@GLIBC_2.2.5
00000000000059d6 t alloc_cellseg
                 U asin@@GLIBC_2.2.5
00000000000079de t assign_syntax
                 U atan2@@GLIBC_2.2.5
                 U atan@@GLIBC_2.2.5
0000000000007026 t atom2str
0000000000006d3e t backchar
0000000000005620 t call_gmon_start
                 U ceil@@GLIBC_2.2.5
00000000000057ac T charvalue
0000000000005894 T closure_code
0000000000005899 T closure_env
0000000000213bc0 b completed.6976
                 U cos@@GLIBC_2.2.5
0000000000005640 t deregister_tm_clones
0000000000212520 d dispatch_table
                 U dlerror@@GLIBC_2.2.5
                 U dlopen@@GLIBC_2.2.5
                 U dlsym@@GLIBC_2.2.5
000000000000cad4 T eqv
                 U exp@@GLIBC_2.2.5
                 U fclose@@GLIBC_2.2.5
                 U fgetc@@GLIBC_2.2.5
0000000000005d9b t file_interactive
0000000000005ba8 t fill_vector
0000000000005b29 t find_consecutive_cells
0000000000005e5c t find_slot_in_env
                 U floor@@GLIBC_2.2.5
                 U fmod@@GLIBC_2.2.5
                 U fopen@@GLIBC_2.2.5
                 U fputc@@GLIBC_2.2.5
                 U fputs@@GLIBC_2.2.5
00000000000056f0 t frame_dummy
                 U free@@GLIBC_2.2.5
                 U fwrite@@GLIBC_2.2.5
0000000000006276 t gc
000000000000791e T gensym
00000000000065e2 t get_cell
00000000000064e3 t get_cell_x
                 U getenv@@GLIBC_2.2.5
0000000000005e2c t hash_fn
0000000000006cc8 t inchar
0000000000006043 t is_any
000000000000577d T is_character
0000000000005876 T is_closure
000000000000589e T is_continuation
00000000000058bc T is_environment
000000000000585e T is_foreign
00000000000058cb T is_immutable
00000000000057c0 T is_inport
00000000000077a2 T is_integer
0000000000006030 t is_list
0000000000005885 T is_macro
00000000000077f0 t is_nonneg
000000000000574e T is_number
0000000000005e01 t is_one_of
00000000000057e3 T is_outport
0000000000005806 T is_pair
00000000000057b1 T is_port
000000000000584f T is_proc
00000000000058ad T is_promise
000000000000575d T is_real
0000000000005730 T is_string
000000000000582f T is_symbol
0000000000005847 T is_syntax
000000000000573f T is_vector
000000000000579a T ivalue
0000000000005fa5 T list_length
0000000000009540 t list_star
                 U log@@GLIBC_2.2.5
000000000000e591 T main
                 U malloc@@GLIBC_2.2.5
0000000000005c7b t mark
                 U memcpy@@GLIBC_2.14
                 U memset@@GLIBC_2.2.5
000000000000820e t mk_atom
000000000000664a T mk_character
00000000000067e0 t mk_closure
00000000000066ed T mk_counted_string
000000000000b532 T mk_empty_string
000000000000662b T mk_foreign_func
000000000000666f T mk_integer
00000000000066c5 t mk_number
000000000000676d t mk_port
0000000000006692 T mk_real
0000000000006a29 t mk_sharp_const
0000000000006741 T mk_string
00000000000078ef T mk_symbol
0000000000006806 t mk_vector
                 U modf@@GLIBC_2.2.5
0000000000009f9b t new_frame_in_env
000000000000a083 t new_slot_in_env
0000000000009fe4 t new_slot_spec_in_env
00000000000058da t num_eq
00000000000059ba t num_ge
000000000000592a t num_gt
00000000000059c8 t num_le
0000000000005972 t num_lt
0000000000213bd0 b num_one
0000000000213be0 b num_zero
0000000000005791 T nvalue
000000000000785b t oblist_add_by_name
000000000000610e t oblist_find_by_name
000000000000a0e9 t opexe_0
000000000000d348 t opexe_1
000000000000b587 t opexe_2
000000000000cc12 t opexe_3
00000000000095b7 t opexe_4
0000000000008509 t opexe_5
0000000000007fa8 t opexe_6
0000000000005815 T pair_car
000000000000581a T pair_cdr
0000000000006049 t port_close
000000000000678c t port_from_string
0000000000005dcf t port_rep_from_file
                 U pow@@GLIBC_2.2.5
00000000000076e2 t printatom
00000000000065a6 t push_recent_alloc
000000000000698a T putcharacter
                 U puts@@GLIBC_2.2.5
00000000000061f9 T putstr
0000000000006d7f t readstr_upto
0000000000006176 t realloc_port_string
0000000000005670 t register_tm_clones
0000000000006903 t reserve_cells
000000000000778f T rvalue
0000000000009f88 t s_cons
0000000000009f75 t s_immutable_cons
0000000000008483 t s_save
000000000000a09e T scheme_define
000000000000e309 T scheme_deinit
000000000000e228 T scheme_init
000000000000ddb0 T scheme_init_custom_alloc
000000000000e244 T scheme_init_new
000000000000e1ec T scheme_init_new_custom_alloc
000000000000e57e T scheme_load_file
000000000000e45e T scheme_load_named_file
0000000000007ed3 T scheme_load_string
000000000000e301 T scheme_set_external_data
000000000000e273 T scheme_set_input_port_file
000000000000e2a3 T scheme_set_input_port_string
000000000000e2ba T scheme_set_output_port_file
000000000000e2ea T scheme_set_output_port_string
000000000000e970 T scm_load_ext
000000000000581f T set_car
0000000000005827 T set_cdr
0000000000005c4d t set_vector_elem
00000000000058d3 T setimmutable
                 U sin@@GLIBC_2.2.5
                 U snprintf@@GLIBC_2.2.5
                 U sqrt@@GLIBC_2.2.5
                 U stderr@@GLIBC_2.2.5
                 U stdin@@GLIBC_2.2.5
                 U stdout@@GLIBC_2.2.5
0000000000006082 t store_string
                 U strcasecmp@@GLIBC_2.2.5
                 U strcpy@@GLIBC_2.2.5
000000000000578c T string_value
00000000000069f0 t strlwr
                 U strrchr@@GLIBC_2.2.5
                 U strstr@@GLIBC_2.2.5
                 U strtod@@GLIBC_2.2.5
                 U strtol@@GLIBC_2.2.5
000000000000583e T symname
000000000000586d T syntaxname
                 U tan@@GLIBC_2.2.5
0000000000211cc0 d tests
0000000000006dfb t token
                 U ungetc@@GLIBC_2.2.5
0000000000005c24 t vector_elem
0000000000212360 d vtbl
jrs@laptop:~/tinyscheme/tinyscheme-1.41$
« Last Edit: August 27, 2014, 07:58:20 AM by John »

JRS

  • Guest
Re: TinyScheme
« Reply #47 on: August 27, 2014, 08:17:25 AM »
I found a great resource for TinyScheme docs. The EDE Library API reference. The project uses TinyScheme and has provided some documentation for the TS function calls.

Quote
#define edelib_scheme_set_output_port_string   scheme_set_output_port_string

Set character array as output port. You should give pointer to the first element and pointer to the last.

@Charles - Didn't you add C array / type structure creation and access functions in DLLC?

Charles Pegge

  • Guest
Re: TinyScheme
« Reply #48 on: August 27, 2014, 09:48:57 AM »
Hi John,

I hope this helps:

1 for your buffer, make a string of nuls (64kbytes for example)
2 get the real pointer to this string
3 calculate the end pointer
4 declare the lisp output port function to accept integers (instead of char*)
5 pass these values to the lisp output port function

creating the buffer and its string pointers:
Code: [Select]
  include "dllcinc.sb"
  lispbuf=string(0x10000,chr(0))
  lispstrptr=dllsptr(lispbuf)
  lispstrend=lispstrptr+0x10000 - 1
  dllprnt hex(lispstrptr) & "\n" & hex(lispstrend) & "\n"
  dlllnpt "Press Enter"
' ...


JRS

  • Guest
Re: TinyScheme
« Reply #49 on: August 27, 2014, 09:50:33 AM »
Slick trick!

I'll give it a try.

Thanks Charles!


JRS

  • Guest
Re: TinyScheme
« Reply #50 on: August 27, 2014, 08:46:42 PM »
Code: [Select]
' TinyScheme Script BASIC DLLC Example

DECLARE SUB dllfile ALIAS "dllfile" LIB "dllc"
DECLARE SUB dllproc ALIAS "dllproc" LIB "dllc"
DECLARE SUB dllcall ALIAS "dllcall" LIB "dllc"
DECLARE SUB dllsptr ALIAS "dllsptr" LIB "dllc"

ts = dllfile("libtinyscheme.dll")
InitNew = dllproc(ts, "scheme_init_new i = ()")
RtnStr = dllproc(ts, "scheme_set_output_port_string (i sc, i startptr, i endptr)")
Deinit = dllproc(ts, "scheme_deinit (i sc)")
LoadStr = dllproc(ts, "scheme_load_string (i sc, c *cmd)")

sc = dllcall(InitNew)
lispbuf = string(1024,CHR(0))
lispstrptr = dllsptr(lispbuf)
lispstrend = lispstrptr + 1024 - 1
dllcall(RtnStr, sc, lispstrptr, lispstrend)
dllcall(LoadStr, sc, "(display \"Thank You Charles!\")")
strlen = INSTR(lispbuf, CHR(0))
PRINT LEFT(lispbuf, strlen - 1),"\n"
dllcall(Deinit, sc)

dllfile()

C:\SB22\TS>scriba dllchellots.sb
Thank You Charles!

C:\SB22\TS>

JRS

  • Guest
Re: TinyScheme
« Reply #51 on: August 27, 2014, 09:47:14 PM »
Code: [Select]
' TinyScheme Script BASIC DLLC Example

DECLARE SUB dllfile ALIAS "dllfile" LIB "dllc"
DECLARE SUB dllproc ALIAS "dllproc" LIB "dllc"
DECLARE SUB dllcall ALIAS "dllcall" LIB "dllc"
DECLARE SUB dllsptr ALIAS "dllsptr" LIB "dllc"

ts = dllfile("libtinyscheme.dll")
InitNew = dllproc(ts, "scheme_init_new i = ()")
RtnStr = dllproc(ts, "scheme_set_output_port_string (i sc, i startptr, i endptr)")
Deinit = dllproc(ts, "scheme_deinit (i sc)")
LoadStr = dllproc(ts, "scheme_load_string (i sc, c *cmd)")

sc = dllcall(InitNew)
lispbuf = string(4096,CHR(0))
lispstrptr = dllsptr(lispbuf)
lispstrend = lispstrptr + 4096 - 1
dllcall(RtnStr,sc, lispstrptr, lispstrend)
dllcall(LoadStr, sc, "(load \"init.scm\")")
dllcall(LoadStr, sc, "(load \"mbrot2.scm\")")
strlen = INSTR(lispbuf, CHR(0))
PRINT LEFT(lispbuf, strlen - 1),"\n"
dllcall(Deinit, sc)

dllfile()

Output

Code: [Select]
C:\SB22\TS>ptime scriba dllchellots.sb

ptime 1.0 for Win32, Freeware - http://www.pc-tools.net/
Copyright(C) 2002, Jem Berkes <jberkes@pc-tools.net>

=== scriba dllchellots.sb ===


Ascii Mandelbrot TinyScheme
---------------------------
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2
1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2
1 1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3
1 1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3
1 1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3
1 1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3
1 1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4
1 1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4
1 1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4
1 1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4
1 1 1 1111111111111111111111111111111111111111111111117 5 4
1 1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4
1 1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4
1 1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4
1 1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4
1 1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3
1 1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3
1 1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3
1 1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2
1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2
1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2


Execution time: 1.086 s

C:\SB22\TS>

JRS

  • Guest
Re: TinyScheme
« Reply #52 on: August 27, 2014, 10:50:22 PM »
Rob, Mike and Charles,

I want to thank you guys for all the effort that was put into adding Lisp to BASIC. I'm at a point where I'm ready to move the TinyScheme extension module over to the Script BASIC forum where a thread already exists. The only non-member of the group is Mike. I offered to register Mike on the SB forum but he declined.  :-\  I hope to see Rob and Charles (if he has time) giving their input and direction on the SB forum as this interface matures.

FYI - The SB forum has color syntax highlighting for SB, Scheme and C. (among others)

FWIW - No Aurel on the SB forum.
« Last Edit: August 27, 2014, 11:35:39 PM by John »

RobbeK

  • Guest
Re: TinyScheme
« Reply #53 on: August 28, 2014, 10:35:44 AM »
Hi John,

I'll try to make some time for it ... if you need more demo's etc...  just ask.

Tested the TinyScheme for numeric values , it's more than OK (series of 10000 sums , most of them inexact numbers -- put it against the Austin Kyoto CL compiler -- and once again, the speed is very good being interpretive ...

best Rob
(it *is* important this Scheme is capable of syntax macro's -- see my example under Lisp in Basic -- it's NewLisp, but in principle the same works in TinyScheme)

.

JRS

  • Guest
Re: TinyScheme
« Reply #54 on: August 28, 2014, 12:04:40 PM »
Did you time these variations?  It would be nice to see how they compare.

Can you post a Mandelbrot iterator for TinyScheme like the one your did for BL?

It would be great if you can participate on both O2 & SB forums. (our Lisp hero)

JRS

  • Guest
Re: TinyScheme
« Reply #55 on: August 28, 2014, 06:29:12 PM »
Here is a multi-threaded TinyScheme example using the DLLC Script BASIC extension module.

Start Script
Code: [Select]
' Boot (Main / Launcher)

DECLARE SUB dlltran ALIAS "dlltran" LIB "dllc"
DECLARE SUB dllclos ALIAS "dllclos" LIB "dllc"
DECLARE SUB dllfile ALIAS "dllfile" LIB "dllc"

t1 = dlltran("T1.sb","main::main",1)
t2 = dlltran("T2.sb","main::main",2)

LINE INPUT wait

dllclos t1, t2
dllfile

Thread Scripts - T1.sb & T2.sb are identical except for the (display ...) statement.
Code: [Select]
' Thread #1 Script

DECLARE SUB dllfile ALIAS "dllfile" LIB "dllc"
DECLARE SUB dllproc ALIAS "dllproc" LIB "dllc"
DECLARE SUB dllcall ALIAS "dllcall" LIB "dllc"
DECLARE SUB dllsptr ALIAS "dllsptr" LIB "dllc"

ts = dllfile("libtinyscheme.dll")
InitNew = dllproc(ts, "scheme_init_new i = ()")
RtnStr = dllproc(ts, "scheme_set_output_port_string (i sc, i startptr, i endptr)")
Deinit = dllproc(ts, "scheme_deinit (i sc)")
LoadStr = dllproc(ts, "scheme_load_string (i sc, c *cmd)")

FUNCTION main(pProg)
  sc = dllcall(InitNew)
  lispbuf = string(4096,CHR(0))
  lispstrptr = dllsptr(lispbuf)
  lispstrend = lispstrptr + 4096 - 1
  dllcall(RtnStr,sc, lispstrptr, lispstrend)
  dllcall(LoadStr, sc, "(display \"Thread 1\")")
  strlen = INSTR(lispbuf, CHR(0))
  PRINT LEFT(lispbuf, strlen - 1),"\n"
  dllcall(Deinit, sc)
END FUNCTION

Output

C:\SB22\TS>scriba Tboot.sb
Thread 1
Thread 2

C:\SB22\TS>

JRS

  • Guest
Re: TinyScheme
« Reply #56 on: August 28, 2014, 10:39:06 PM »
Rob,

Is there any interest in using TinyScheme embedded in SB or are you happy running it as a dedicated Lisp interpreter?


JRS

  • Guest
Re: TinyScheme
« Reply #57 on: August 28, 2014, 11:23:17 PM »
Charles,

I'm trying incorprate the string buffer method for Linux TinyScheme extension module. The results of the  LoadStr() function returns the buffer contents. The following compiled without error but seg. faults when run. (after a bit of os delay) Can you help me with getting the pointers I need in C for the buffer definition?

Code: [Select]
besFUNCTION(TS_load_string) 
  DIM AS scheme PTR sc;
  DIM AS char PTR cmdstr;
  DIM AS char PTR tsbuf[16384];
  besARGUMENTS("iz")
    AT sc, AT cmdstr
  besARGEND
  scheme_set_output_port_string (sc, (int)*tsbuf, (int)*tsbuf + 16383);
  scheme_load_string(sc, cmdstr); 
  besRETURN_STRING(tsbuf);
besEND

Charles Pegge

  • Guest
Re: TinyScheme
« Reply #58 on: August 28, 2014, 11:34:54 PM »
Hi John,

Should it be:

DIM AS char PTR tsbuf[16384];

Also

The casting should be (int*) or, (char*), depending on your function prototype

scheme_set_output_port_string (sc, (int*) tsbuf, (int*) tsbuf + 16383);

JRS

  • Guest
Re: TinyScheme
« Reply #59 on: August 28, 2014, 11:46:55 PM »
Thank you !

How can I trim the buffer string to eliminate the nulls?

Code: [Select]
besFUNCTION(TS_load_string) 
  DIM AS scheme PTR sc;
  DIM AS char PTR cmdstr;
  DIM AS char tsbuf[16384];
  besARGUMENTS("iz")
    AT sc, AT cmdstr
  besARGEND
  scheme_set_output_port_string (sc, (char*) tsbuf, (char*) tsbuf + 16383);
  scheme_load_string(sc, cmdstr); 
  besRETURN_STRING(tsbuf);
besEND