ChanServ changed the topic of #picolisp to: PicoLisp language | Channel Log: https://irclog.whitequark.org/picolisp/ | Check also http://www.picolisp.com for more information
orivej has quit [Remote host closed the connection]
orivej has joined #picolisp
orivej has quit [Ping timeout: 268 seconds]
orivej has joined #picolisp
orivej has quit [Remote host closed the connection]
orivej has joined #picolisp
orivej has quit [Ping timeout: 245 seconds]
alexshendi has quit [Ping timeout: 252 seconds]
andyjpb has quit [Ping timeout: 244 seconds]
_whitelogger has joined #picolisp
ubLX has quit [Quit: ubLX]
clacke[m] has left #picolisp [#picolisp]
razzy has joined #picolisp
orivej has joined #picolisp
aw- has joined #picolisp
orivej has quit [Ping timeout: 244 seconds]
freemint has joined #picolisp
<freemint> good morning
<Regenaxer> Hi freemint
_whitelogger has joined #picolisp
freeemint has joined #picolisp
freemint has quit [Ping timeout: 252 seconds]
_whitelogger has joined #picolisp
freemint has joined #picolisp
<freemint> Good morning Regenaxer
<freemint> I looked in to SuperH assembly yesterday ...
<freemint> (my OS to FPGA cpu porting project) and had a enlightenment
<freemint> It had a TST instruction which took two arguements
freeemint has quit [Ping timeout: 246 seconds]
<freemint> and i saw TST Reg4 Reg4 - why would you test reg4 against Reg4? turn-out the instruction ands both input and checks if the result is zero ... i found that instruction very brilliant
<Regenaxer> Most CPU have such an instruction. Same as AND without modifying the registers
<Regenaxer> See doc64/asm:
<Regenaxer> test dst src # Bit-test 'dst' with 'src' [zs.]
<freemint> since the instruction set is 16 bit (but the CPU is 32 bit) the result is written in to the TEST-Flag not an arbitrary register
<Regenaxer> This has nothing to do with the word size
<Regenaxer> Why do you think this instruction is so special or fascinating?
<Regenaxer> There are very many instructions modifying the condition flags
orivej has joined #picolisp
<freemint> Ich habe mich nie tief mit asm bisher beschäftigt und wusste nur von Grundrechenarten, Shifts und Jumps. Ich finde diese Instruction einfach sehr elegant aber ich habe auch noch keine vollständigen Überblick über die eine kleine ISA . Aber als gestern wirklich versucht habe assembly zu lesen hatte ich halt einen aha moment
<Regenaxer> OK, good :)
<freemint> we are again at this point: not everything that is normal/average/trivial for you is trivial for everybody else
<freemint> but i got a question i could not figure out yet. What are .data , .text and .bss for?
<freemint> I've learned so far that .data contains strings for example, .text looks very executable and bss is very sparse
<Regenaxer> correct
<Regenaxer> bss is uninitialized, it "exists" only logically, as offsets
<Regenaxer> text is code, typically read-only
<Regenaxer> Sorry, must go. Back soon
_whitelogger has joined #picolisp
orivej has quit [Ping timeout: 272 seconds]
<Regenaxer> ret
<freemint> going to the nth byte of a file can only be done via external programs like dd?
<Regenaxer> yes, for a immediate lseek()
<freemint> like dd if=file skip=2 iflags=bytes or is there a more elegant way?
<Regenaxer> Otherwise you need to scan through it with 'from' etc
<Regenaxer> You might call native lseek
<Regenaxer> but then need to read() etc explicitly
<freemint> I am looking for seek-like behavior. As i am trying to parse a file that jumps around
<Regenaxer> I would start with (in '(dd
<freemint> ok
<Regenaxer> If it jumps, it will not work anyway with the lisp read functions
<Regenaxer> as they buffer internally
<Regenaxer> But doing native lseek on an fd, then (in Fd ... should work
<Regenaxer> ie each 'in' call uses a new buffer iirc
<Regenaxer> hmm, no
<Regenaxer> The buffer is reused
<Regenaxer> so a seek in between gives garbage
<freemint> ok ... is there non buffering bite wise IO?
<Regenaxer> No
<Regenaxer> It would be extremely inefficient
<Regenaxer> buffering is always needed
<Regenaxer> but the buffer would need to be flushed after a seek
<freemint> how do other languages do that?
<freemint> yes this is logical...
<Regenaxer> so you could write a lseek function operating on the internal structures
<freemint> ihh
<Regenaxer> or better do native pread()
<Regenaxer> and fetch bytes from that buffer
<freemint> could i do memory mapped io?
<Regenaxer> yes
<Regenaxer> mmap
<Regenaxer> but pread is simpler
<Regenaxer> malloc a buffer, read, fetch bytes
<Regenaxer> 'byte'
<freemint> pread takes a buffer what is a buffer in C and how does it know about its size?
<Regenaxer> It does not know
<Regenaxer> you pass the number of bytes
<freemint> oh ... and it writes in there and if the number is to large the seven circles of he'll are summoned?
<Regenaxer> exactly
<Regenaxer> your foot is gone
<Regenaxer> also if the pointer is wrong
<Regenaxer> (setq P (native "@" "malloc" ...
<Regenaxer> (native "@" "pread" 'I Fd P ...
<Regenaxer> doc/native.html has an example with read()
<Regenaxer> without "p"
<freemint> and now i got the stuff in the buffer, how do i get it out?
<Regenaxer> you can access it with 'byte'
<Regenaxer> Perhaps 'adr' if it is Lisp data
<freemint> ok
<freemint> so pread copies the choosen amount of data to the buffer
andyjpb has joined #picolisp
<freemint> i am so shocked ... all the niceness of PicoLisp disappeared at one moment
<Regenaxer> yeah
<Regenaxer> You can encapsulate that into a few functions
<freemint> but byte is a good addition as it allows to do more from picolisp.
<Regenaxer> yes, though as you see it is kind of outside of Lisp
<Regenaxer> not Lisp data
<freemint> otherwise i would have to ask C for bytes which means i would need to write C additionally
<Regenaxer> So native with pread is a good compromize
<freemint> how can i get the address of a cell , adr just gives $something i think
<freemint> (unrelated question)
<Regenaxer> It is indeed the address shifted by 16 iirc
<freemint> the address so i can inspect with byte.
<Regenaxer> yes, (>> -4
<Regenaxer> gives the pointer
<Regenaxer> oops, no, (>> 4
<Regenaxer> no, sorry
<Regenaxer> haha
<Regenaxer> it should be as it is
<Regenaxer> hmm, let me check
orivej has joined #picolisp
<Regenaxer> adr only sets the tag bit
<Regenaxer> So for a cell it is the cell number
<Regenaxer> For a byte pointer you must multiply with 16
<Regenaxer> (>> -4
<Regenaxer> A symbol has bit 3 on, so the number is negative
<Regenaxer> You negate it and then shift
<Regenaxer> gives the pointer to the symbol's cell, ie the TAIL field
<Regenaxer> (see doc64/structures)
<Regenaxer> For example:
<Regenaxer> : (setq L (1))
<Regenaxer> : (adr L)
<Regenaxer> -> (1)
<Regenaxer> -> 31742141863
<Regenaxer> : (>> -4 @)
<Regenaxer> -> 507874269808
<Regenaxer> : (byte @)
<Regenaxer> -> 18
<Regenaxer> : (hex @)
<Regenaxer> -> "12"
<Regenaxer> "12" is the short number '1'
<Regenaxer> encoded as little endian in the CAR of the cell pointed by 'L'
<freemint> my memory is full of 6
<freemint> : (bytes (+ 1 (* 16 (adr 'A))))
<Regenaxer> ...000010010
<Regenaxer> A is a symbol
<Regenaxer> so you must negate
<Regenaxer> then shift and add 8 to get the value
<Regenaxer> Without 8 you get the name "A"
<Regenaxer> ie the TAIL
<freemint> still
<freemint> (setq A 1)
<Regenaxer> ok, then the value is offset 8
<Regenaxer> after negating and shifting
<freemint> still 6
<Regenaxer> Why + 1
<freemint> I am looking at a pointer in memory and everywhere around that pointer i look i get a 6 back, why?
<Regenaxer> Try the above with 'L'
<Regenaxer> or this (byte (+ 8 (>> -4 (- (adr 'A]
<Regenaxer> gives 18 again if 'A' is 1
<freemint> with L and (byte (* 16 @)) i get 18 just like you
<freemint> i get 18 with your (- (adr ... too
<Regenaxer> ok
<freemint> weird
<freemint> now it works roughly
<freemint> Regenaxer if i copied a number with right offset into something malloced would something weird happen when i have stuff pointing to this number
<freemint> * a cell with a number
<freemint> i am aware the gc would behave strangely but i got a work around for that.
<Regenaxer> No, this is perfectly fine
<Regenaxer> you just need to set the proper tag bits
<Regenaxer> as in doc64/structures
<freemint> so one could implement arrays and matrizes that way if the purpose is "being a look-up table"
<Regenaxer> only if you free() this buffer it will crash when that cell issed
<Regenaxer> yep
<Regenaxer> oups
<Regenaxer> -> "cell is accessed"
<Regenaxer> pentied too fast :)
<freemint> and the gc will ignore a cells it links two after the second pass since the gcc flag is not resented by sweeping.
<Regenaxer> yes
<Regenaxer> So it is not a very good idea
<freemint> so when i maintain a mirror copy list ... everything is fine?
<Regenaxer> I think it is fine even so
<Regenaxer> the gc does not sweep it, yes, but also does not mark it initially
<Regenaxer> So *this* cell is fine
<freemint> It marks it ... i think
<Regenaxer> only if this cell points to other cells they will not be marked
<Regenaxer> no
<Regenaxer> "mark" means clearing a bit in pil
<Regenaxer> gc first sets the lowest bits
<freemint> when symbol A points my array with the external cell it should be marked
<Regenaxer> then "mark" by resetting it
<Regenaxer> yes, but it is cleared anyway
<Regenaxer> gc believes it found an already marke cell
<freemint> I thought bit set on mark and bit cleared on sweep
<Regenaxer> so it won't follow the pointers *in* that cell
<freemint> oh you are talking about the second pass
<freemint> then yes
<Regenaxer> So in fact it is 3 passes
<Regenaxer> first all cells get a 1
<Regenaxer> reachable cells get it cleared
<freemint> what is all?
<Regenaxer> then all cells with 1 are collected into the avail list
<Regenaxer> all cells in all heaps
<Regenaxer> In pil32 it is easier to see:
<Regenaxer> do {
<Regenaxer> do
<Regenaxer> p = h->cells + CELLS-1;
<Regenaxer> while (--p >= h->cells);
<Regenaxer> *(word*)&cdr(p) |= 1;
<freemint> all cells allocated by picolisp or also cells I've allocated with malloc?
<Regenaxer> } while (h = h->next);
<Regenaxer> No, malloc'ed cells are not known to the system
<freemint> why 3 passes 2 should be enough?
<Regenaxer> You need three
<Regenaxer> clear the bits either in the beginning or in the end
<freemint> 1 Mark all cells reachable from root 2 sweep all cells not marked and reset marking on all other
<Regenaxer> here in the beginning
<Regenaxer> The pil way leaves cells in use alone
<Regenaxer> they are marked, so the bit is cleared already
<Regenaxer> and the others go into the avail list, so they are written
<Regenaxer> (linked into the avail list)
<freemint> how does the avail list not end up being rebuilt each gc-cycle
<Regenaxer> it may be or may be not
<Regenaxer> if gc is called by cons, it is empty
<Regenaxer> if you call (gc), it is not
<Regenaxer> so newly freed cells are consed in front of that list
<Regenaxer> (not really 'cons', but equivalent)
<freemint> I see why it does not have a performance impact in the case you run out of cells
<freemint> when i call (gc) is the avail list rebuild?
<Regenaxer> no, only new cells consed in front
<freemint> good
<freemint> if i would do pointer magic and end up having a pointer a cell in the free list how would picolisp cat?
<Regenaxer> you could destroy the free list
<Regenaxer> or make it circular
<Regenaxer> A pointer to a cell in that list won't eg. print
<Regenaxer> it is not a Lisp level list
<Regenaxer> ie no tag bits
<freemint> ok
<freemint> what requirements does minipicolisp have for IO?
<Regenaxer> It uses only stdio
<freemint> (what system specific stuff do i have to implement)
<freemint> (to get minipicolisp running?)
<Regenaxer> ah
<Regenaxer> nothing
<Regenaxer> it uses only standard C calls
<Regenaxer> fopen() etc
<Regenaxer> In principle shoul compile anywhere
<freemint> mhh if i have a standard C library?
<Regenaxer> On embedded systems it may depend, yes
<freemint> ... ok ... that is what i am interested in rn.
<freemint> does picolisp need an mmu to work?
<Regenaxer> no
* freemint praises the glory of Regenaxer
<freemint> ;)
<Regenaxer> huh? For not needing an mmu?
<freemint> no in general
<Regenaxer> thanks :)
orivej has quit [Ping timeout: 244 seconds]
<aw-> linux needs an mmu
<Regenaxer> hi aw-
<Regenaxer> yes, but no pil itself
<Regenaxer> eg on embedded systems
<Regenaxer> bbl
<Regenaxer> ret
ubLIX has joined #picolisp
razzy has quit [Ping timeout: 252 seconds]
_whitelogger has joined #picolisp
<freemint> aw- linux does not
<freemint> i am running Linux on a mmu-less board.
<freemint> code word uClinux or nommu.org or something
<Regenaxer> yeah, ucLinux is very limited therefore. No real fork()
ubLIX has quit [Quit: ubLIX]
razzy has joined #picolisp
orivej has joined #picolisp
xkapastel has joined #picolisp
alexshendi has joined #picolisp
orivej has quit [Ping timeout: 276 seconds]
ubLIX has joined #picolisp
mtsd has joined #picolisp
orivej has joined #picolisp
<freemint> Hi alexshendi
orivej has quit [Ping timeout: 268 seconds]
andyjpb has quit [Ping timeout: 244 seconds]
ubLIX has quit [Quit: ubLIX]