├── v0100 ├── binw │ ├── m.dat │ ├── z.dat │ ├── n2f.dat │ ├── smlrc.dat │ ├── smlrl.dat │ ├── smlrcc.dat │ ├── smlrpp.dat │ └── readme.txt ├── tests │ ├── picoc │ │ ├── 43.exp │ │ ├── 48.exp │ │ ├── 29.exp │ │ ├── 27.exp │ │ ├── 35.exp │ │ ├── 42.exp │ │ ├── 44.exp │ │ ├── 49.exp │ │ ├── 12.exp │ │ ├── 18.h │ │ ├── 55.exp │ │ ├── 00.exp │ │ ├── 14.exp │ │ ├── 39.exp │ │ ├── 47.exp │ │ ├── 34.exp │ │ ├── 07.exp │ │ ├── 17.exp │ │ ├── 18.exp │ │ ├── 19.exp │ │ ├── 20.exp │ │ ├── 03.exp │ │ ├── 06.exp │ │ ├── 13.exp │ │ ├── 41.exp │ │ ├── 01.exp │ │ ├── 26.exp │ │ ├── 04.exp │ │ ├── 45.exp │ │ ├── 51.exp │ │ ├── 05.exp │ │ ├── 33.exp │ │ ├── 38.exp │ │ ├── 08.exp │ │ ├── 09.exp │ │ ├── 52.exp │ │ ├── 15.exp │ │ ├── 21.exp │ │ ├── 54.exp │ │ ├── 25.exp │ │ ├── 32.exp │ │ ├── 31.exp │ │ ├── readme.txt │ │ ├── 11.exp │ │ ├── 10.exp │ │ ├── 28.exp │ │ ├── 50.exp │ │ ├── 23.exp │ │ ├── 16.exp │ │ ├── 22.exp │ │ ├── 18.c │ │ ├── 43.c │ │ ├── 36.exp │ │ ├── 37.exp │ │ ├── 29.c │ │ ├── 24.exp │ │ ├── 04.c │ │ ├── 44.c │ │ ├── 02.exp │ │ ├── 12.c │ │ ├── 33.c │ │ ├── 42.c │ │ ├── 35.c │ │ ├── 45.c │ │ ├── 27.c │ │ ├── 00.c │ │ ├── 31.c │ │ ├── 37.c │ │ ├── 01.c │ │ ├── 08.c │ │ ├── 09.c │ │ ├── 14.c │ │ ├── 26.c │ │ ├── 15.c │ │ ├── 16.c │ │ ├── 05.c │ │ ├── 13.c │ │ ├── 47.c │ │ ├── 40.exp │ │ ├── 48.c │ │ ├── 49.c │ │ ├── 07.c │ │ ├── 02.c │ │ ├── 20.c │ │ ├── 34.c │ │ ├── 17.c │ │ ├── 19.c │ │ ├── 36.c │ │ ├── 51.c │ │ ├── 52.c │ │ ├── 06.c │ │ ├── 39.c │ │ ├── 38.c │ │ ├── 21.c │ │ ├── 50.c │ │ ├── 03.c │ │ ├── 24.c │ │ ├── 10.c │ │ ├── 54.c │ │ ├── 11.c │ │ ├── 23.c │ │ ├── 28.c │ │ ├── 40.c │ │ └── 41.c │ ├── bugs │ │ ├── compile │ │ │ ├── readme.txt │ │ │ ├── 010.c │ │ │ ├── 011.c │ │ │ ├── 001.c │ │ │ ├── 005.c │ │ │ ├── 006.c │ │ │ ├── 004.c │ │ │ ├── 007.c │ │ │ ├── 009.c │ │ │ ├── 002.c │ │ │ ├── 008.c │ │ │ └── 003.c │ │ └── ncompile │ │ │ ├── readme.txt │ │ │ ├── 010.c │ │ │ ├── 006.c │ │ │ ├── 007.c │ │ │ ├── 009.c │ │ │ ├── 004.c │ │ │ ├── 002.c │ │ │ ├── 003.c │ │ │ ├── 001.c │ │ │ ├── 008.c │ │ │ └── 005.c │ ├── snake.com │ ├── fp │ │ └── fpconst.c │ ├── subc │ │ ├── readme.txt │ │ └── stdio.ok │ ├── lcc │ │ └── readme.txt │ ├── lnktst1b.asm │ ├── hw.c │ ├── sdl │ │ └── dimports.h │ ├── argenv.c │ └── lnktst1.asm ├── binl │ ├── n2f │ ├── smlrc │ ├── smlrcc │ ├── smlrl │ ├── smlrpp │ └── readme.txt ├── binm │ ├── n2f │ ├── smlrc │ ├── smlrcc │ ├── smlrl │ ├── smlrpp │ └── readme.txt ├── lib │ ├── lcl.a │ ├── lcm.a │ ├── lcw.a │ ├── lcdh.a │ ├── lcdp.a │ ├── lcds.a │ ├── lcdu.a │ ├── dpstub.exe │ └── readme.txt ├── bind │ ├── n2f.exe │ ├── smlrc.exe │ ├── smlrl.exe │ ├── smlrcc.exe │ ├── smlrpp.exe │ └── readme.txt ├── ucpp │ └── README ├── bindp │ ├── n2f.exe │ ├── smlrc.exe │ ├── smlrcc.exe │ ├── smlrl.exe │ ├── smlrpp.exe │ └── readme.txt ├── srclib │ ├── errno.c │ ├── abs.c │ ├── getc.c │ ├── lngltz.c │ ├── feof.c │ ├── getchar.c │ ├── ictype.h │ ├── putc.c │ ├── ferror.c │ ├── isgraph.c │ ├── putchar.c │ ├── raise.c │ ├── isblank.c │ ├── isprint.c │ ├── labs.c │ ├── lngeq.c │ ├── remove.c │ ├── clearerr.c │ ├── isalnum.c │ ├── isalpha.c │ ├── iscntrl.c │ ├── isdigit.c │ ├── islower.c │ ├── ispunct.c │ ├── isspace.c │ ├── isupper.c │ ├── isxdigit.c │ ├── strcoll.c │ ├── stdio1.c │ ├── toupper.c │ ├── tolower.c │ ├── vscanf.c │ ├── vprintf.c │ ├── abort.c │ ├── vfprintf.c │ ├── vfscanf.c │ ├── atol.c │ ├── scanf.c │ ├── setbuf.c │ ├── printf.c │ ├── ctime.c │ ├── fprintf.c │ ├── fscanf.c │ ├── creat.c │ ├── atof.c │ ├── lngul.c │ ├── strcat.c │ ├── puts.c │ ├── signal.c │ ├── lngsub.c │ ├── div.c │ ├── fputs.c │ ├── lngadd.c │ ├── strtod.c │ ├── kernel32 │ │ ├── heapfre_.c │ │ ├── readfil_.c │ │ ├── heapall_.c │ │ ├── movefil_.c │ │ ├── writefi_.c │ │ ├── closeha_.c │ │ ├── createf_.c │ │ ├── deletef_.c │ │ ├── exitpro_.c │ │ ├── freelib_.c │ │ ├── getfity_.c │ │ ├── getlerr_.c │ │ ├── getstdh_.c │ │ ├── gettick_.c │ │ ├── heaprea_.c │ │ ├── setlerr_.c │ │ ├── getstim_.c │ │ ├── creatpr_.c │ │ ├── getphea_.c │ │ ├── getprad_.c │ │ ├── loadlbx_.c │ │ ├── setfptr_.c │ │ ├── getcomm_.c │ │ ├── getexit_.c │ │ ├── getfiat_.c │ │ ├── wait4so_.c │ │ ├── getenvi_.c │ │ ├── setuhef_.c │ │ ├── getlaste.c │ │ ├── gettickc.c │ │ ├── getcomma.c │ │ ├── getpheap.c │ │ ├── st2tzlt_.c │ │ ├── tzlt2st_.c │ │ ├── closehan.c │ │ ├── deletefi.c │ │ ├── freelibr.c │ │ ├── exitproc.c │ │ ├── getfilet.c │ │ ├── setlaste.c │ │ ├── getstdha.c │ │ ├── getfilea.c │ │ ├── getstime.c │ │ ├── movefile.c │ │ ├── getproca.c │ │ ├── getexitc.c │ │ ├── wait4sob.c │ │ ├── loadlibx.c │ │ ├── heapfree.c │ │ ├── heapallo.c │ │ ├── setunhef.c │ │ ├── getenvir.c │ │ ├── heapreal.c │ │ ├── setfilep.c │ │ ├── readfile.c │ │ ├── writefil.c │ │ ├── st2tzslt.c │ │ ├── tzslt2st.c │ │ ├── createfi.c │ │ └── kernel32.c │ ├── memchr.c │ ├── stdin.c │ ├── stderr.c │ ├── stdout.c │ ├── ldiv.c │ ├── stdio2.c │ ├── atan.c │ ├── setlocal.c │ ├── strrchr.c │ ├── exp.c │ ├── gmtime.c │ ├── perror.c │ ├── strpbrk.c │ ├── gets.c │ ├── strspn.c │ ├── memcmp.c │ ├── strncpy.c │ ├── c0w.asm │ ├── cosh.c │ ├── strcspn.c │ ├── difftime.c │ ├── mm.h │ ├── fakmvcrt │ │ ├── abs.c │ │ └── msvcrt.c │ ├── calloc.c │ ├── fgets.c │ ├── srand.c │ ├── strncat.c │ ├── c0l.asm │ ├── vsscanf.c │ ├── sscanf.c │ ├── vsprintf.c │ ├── strlen.c │ ├── lngts.c │ ├── lngtu.c │ ├── sprintf.c │ ├── atexit.c │ ├── strstr.c │ ├── lngfs.c │ ├── memset.c │ ├── strcpy.c │ ├── lngfu.c │ ├── memcpy.c │ ├── vsnprint.c │ ├── lngsl.c │ ├── round.c │ ├── snprintf.c │ ├── time1.c │ ├── strerror.c │ ├── fabs.c │ ├── open_.c │ ├── read_.c │ ├── close_.c │ ├── creat_.c │ ├── itime.h │ ├── lseek_.c │ ├── write_.c │ ├── fileno_.c │ ├── isatty_.c │ ├── unlink_.c │ ├── bsearch.c │ ├── irq5isr.c │ ├── fsetpos.c │ ├── fgetpos.c │ ├── localeco.c │ ├── rand.c │ ├── assert.c │ ├── sinh.c │ ├── idos.h │ ├── atan2.c │ ├── fgetc.c │ ├── strcmp.c │ ├── ungetc.c │ ├── strchr.c │ ├── tanh.c │ ├── atoi.c │ ├── sqrt.c │ ├── strxfrm.c │ ├── asctime.c │ ├── dimports.h │ ├── dpmi.c │ ├── strtok.c │ ├── setvbuf.c │ ├── ifp.h │ ├── strncmp.c │ ├── ctype.c │ ├── log2.c │ ├── log.c │ ├── log10.c │ ├── fputc.c │ ├── memmove.c │ ├── ceil.c │ ├── floor.c │ ├── trunc.c │ ├── rewind.c │ ├── ftell.c │ ├── exp2.c │ ├── asin.c │ ├── dimports.c │ ├── fmod.c │ ├── expm1.c │ ├── acos.c │ ├── tmpfile.c │ ├── ftell16.c │ ├── hypot.c │ ├── cos.c │ ├── fclose.c │ └── sin.c ├── include │ ├── errno.h │ ├── iso646.h │ ├── setjmp.h │ ├── ctype.h │ ├── signal.h │ ├── stdarg.h │ ├── assert.h │ ├── sys │ │ ├── lng.h │ │ ├── stat.h │ │ └── types.h │ ├── limits.h │ ├── fcntl.h │ ├── stddef.h │ ├── string.h │ └── locale.h └── doc │ └── smlrpp.md ├── configure ├── Makefile ├── GNUmakefile └── smallerc.spec.rpkg /v0100/binw/m.dat: -------------------------------------------------------------------------------- 1 | M -------------------------------------------------------------------------------- /v0100/binw/z.dat: -------------------------------------------------------------------------------- 1 | Z -------------------------------------------------------------------------------- /v0100/tests/picoc/43.exp: -------------------------------------------------------------------------------- 1 | yo 2 | -------------------------------------------------------------------------------- /v0100/tests/picoc/48.exp: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /v0100/tests/picoc/29.exp: -------------------------------------------------------------------------------- 1 | bcdef 2 | -------------------------------------------------------------------------------- /v0100/tests/picoc/27.exp: -------------------------------------------------------------------------------- 1 | 1 2 | 4 3 | 4 4 | -------------------------------------------------------------------------------- /v0100/tests/picoc/35.exp: -------------------------------------------------------------------------------- 1 | 1 1 2 | 2 2 3 | -------------------------------------------------------------------------------- /v0100/tests/picoc/42.exp: -------------------------------------------------------------------------------- 1 | yo 24 2 | 42 3 | -------------------------------------------------------------------------------- /v0100/tests/picoc/44.exp: -------------------------------------------------------------------------------- 1 | it's all good 2 | -------------------------------------------------------------------------------- /v0100/tests/picoc/49.exp: -------------------------------------------------------------------------------- 1 | 12.34, 56.78 2 | -------------------------------------------------------------------------------- /v0100/tests/picoc/12.exp: -------------------------------------------------------------------------------- 1 | 12 2 | 12, 24, 36 3 | -------------------------------------------------------------------------------- /v0100/tests/picoc/18.h: -------------------------------------------------------------------------------- 1 | printf("included\n"); 2 | -------------------------------------------------------------------------------- /v0100/tests/picoc/55.exp: -------------------------------------------------------------------------------- 1 | 0 test(s) failed 2 | -------------------------------------------------------------------------------- /v0100/tests/picoc/00.exp: -------------------------------------------------------------------------------- 1 | 42 2 | 64 3 | 12, 34 4 | -------------------------------------------------------------------------------- /v0100/tests/picoc/14.exp: -------------------------------------------------------------------------------- 1 | a is true 2 | b is false 3 | -------------------------------------------------------------------------------- /v0100/tests/picoc/39.exp: -------------------------------------------------------------------------------- 1 | 1 2 | 12,34 3 | 12,34 4 | -------------------------------------------------------------------------------- /v0100/tests/picoc/47.exp: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | out 4 | 3 5 | -------------------------------------------------------------------------------- /v0100/tests/picoc/34.exp: -------------------------------------------------------------------------------- 1 | 12 23 34 45 2 | 12 23 34 45 3 | -------------------------------------------------------------------------------- /v0100/tests/picoc/07.exp: -------------------------------------------------------------------------------- 1 | 9 2 | 16 3 | a=1234 4 | qfunc() 5 | -------------------------------------------------------------------------------- /v0100/tests/picoc/17.exp: -------------------------------------------------------------------------------- 1 | 0 1 2 3 54 73 74 75 2 | 12 3 | 54 4 | -------------------------------------------------------------------------------- /v0100/tests/picoc/18.exp: -------------------------------------------------------------------------------- 1 | including 2 | included 3 | done 4 | -------------------------------------------------------------------------------- /v0100/tests/picoc/19.exp: -------------------------------------------------------------------------------- 1 | 42 2 | b is not NULL 3 | c is NULL 4 | -------------------------------------------------------------------------------- /v0100/tests/picoc/20.exp: -------------------------------------------------------------------------------- 1 | 12 2 | 34 3 | 0 4 | 1 5 | 1 6 | 0 7 | -------------------------------------------------------------------------------- /v0100/tests/picoc/03.exp: -------------------------------------------------------------------------------- 1 | 12 2 | 34 3 | 12 4 | 34 5 | 56 6 | 78 7 | -------------------------------------------------------------------------------- /v0100/tests/picoc/06.exp: -------------------------------------------------------------------------------- 1 | 0 2 | 0 3 | 1 4 | 1 5 | 2 6 | 2 7 | 3 8 | 0 9 | -------------------------------------------------------------------------------- /v0100/tests/picoc/13.exp: -------------------------------------------------------------------------------- 1 | 24680 2 | 342391 3 | 2386092 4 | 2386092 5 | -------------------------------------------------------------------------------- /v0100/tests/picoc/41.exp: -------------------------------------------------------------------------------- 1 | #include test 2 | b 3 | g 4 | i 5 | p 6 | r 7 | -------------------------------------------------------------------------------- /v0100/tests/bugs/compile/readme.txt: -------------------------------------------------------------------------------- 1 | These tests compile but shouldn't. 2 | -------------------------------------------------------------------------------- /v0100/tests/bugs/ncompile/readme.txt: -------------------------------------------------------------------------------- 1 | These tests don't compile but should. 2 | -------------------------------------------------------------------------------- /v0100/tests/picoc/01.exp: -------------------------------------------------------------------------------- 1 | Hello 2 | Hello 3 | Hello 4 | Hello 5 | Hello 6 | -------------------------------------------------------------------------------- /v0100/binl/n2f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/binl/n2f -------------------------------------------------------------------------------- /v0100/binm/n2f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/binm/n2f -------------------------------------------------------------------------------- /v0100/lib/lcl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/lib/lcl.a -------------------------------------------------------------------------------- /v0100/lib/lcm.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/lib/lcm.a -------------------------------------------------------------------------------- /v0100/lib/lcw.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/lib/lcw.a -------------------------------------------------------------------------------- /v0100/tests/picoc/26.exp: -------------------------------------------------------------------------------- 1 | 1 2 | 8 3 | 64 4 | 1 5 | 14 6 | 16 7 | 64 8 | test @ 9 | -------------------------------------------------------------------------------- /v0100/bind/n2f.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/bind/n2f.exe -------------------------------------------------------------------------------- /v0100/binl/smlrc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/binl/smlrc -------------------------------------------------------------------------------- /v0100/binl/smlrcc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/binl/smlrcc -------------------------------------------------------------------------------- /v0100/binl/smlrl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/binl/smlrl -------------------------------------------------------------------------------- /v0100/binl/smlrpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/binl/smlrpp -------------------------------------------------------------------------------- /v0100/binm/smlrc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/binm/smlrc -------------------------------------------------------------------------------- /v0100/binm/smlrcc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/binm/smlrcc -------------------------------------------------------------------------------- /v0100/binm/smlrl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/binm/smlrl -------------------------------------------------------------------------------- /v0100/binm/smlrpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/binm/smlrpp -------------------------------------------------------------------------------- /v0100/binw/n2f.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/binw/n2f.dat -------------------------------------------------------------------------------- /v0100/lib/lcdh.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/lib/lcdh.a -------------------------------------------------------------------------------- /v0100/lib/lcdp.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/lib/lcdp.a -------------------------------------------------------------------------------- /v0100/lib/lcds.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/lib/lcds.a -------------------------------------------------------------------------------- /v0100/lib/lcdu.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/lib/lcdu.a -------------------------------------------------------------------------------- /v0100/ucpp/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/ucpp/README -------------------------------------------------------------------------------- /v0100/bind/smlrc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/bind/smlrc.exe -------------------------------------------------------------------------------- /v0100/bind/smlrl.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/bind/smlrl.exe -------------------------------------------------------------------------------- /v0100/bindp/n2f.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/bindp/n2f.exe -------------------------------------------------------------------------------- /v0100/binw/smlrc.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/binw/smlrc.dat -------------------------------------------------------------------------------- /v0100/binw/smlrl.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/binw/smlrl.dat -------------------------------------------------------------------------------- /v0100/lib/dpstub.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/lib/dpstub.exe -------------------------------------------------------------------------------- /v0100/bind/smlrcc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/bind/smlrcc.exe -------------------------------------------------------------------------------- /v0100/bind/smlrpp.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/bind/smlrpp.exe -------------------------------------------------------------------------------- /v0100/bindp/smlrc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/bindp/smlrc.exe -------------------------------------------------------------------------------- /v0100/bindp/smlrcc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/bindp/smlrcc.exe -------------------------------------------------------------------------------- /v0100/bindp/smlrl.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/bindp/smlrl.exe -------------------------------------------------------------------------------- /v0100/bindp/smlrpp.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/bindp/smlrpp.exe -------------------------------------------------------------------------------- /v0100/binw/smlrcc.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/binw/smlrcc.dat -------------------------------------------------------------------------------- /v0100/binw/smlrpp.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/binw/smlrpp.dat -------------------------------------------------------------------------------- /v0100/tests/picoc/04.exp: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /v0100/tests/picoc/45.exp: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /v0100/tests/picoc/51.exp: -------------------------------------------------------------------------------- 1 | 1234 2 | 4567 3 | 4568 4 | 4569 5 | 4570 6 | 1234 7 | 8901 8 | 2345 9 | -------------------------------------------------------------------------------- /v0100/tests/snake.com: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/tests/snake.com -------------------------------------------------------------------------------- /v0100/tests/fp/fpconst.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexfru/SmallerC/HEAD/v0100/tests/fp/fpconst.c -------------------------------------------------------------------------------- /v0100/tests/picoc/05.exp: -------------------------------------------------------------------------------- 1 | 1 2 | 4 3 | 9 4 | 16 5 | 25 6 | 36 7 | 49 8 | 64 9 | 81 10 | 100 11 | -------------------------------------------------------------------------------- /v0100/tests/picoc/33.exp: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 4 4 | 9 5 | 16 6 | 15 7 | 18 8 | 21 9 | 24 10 | 27 11 | -------------------------------------------------------------------------------- /v0100/tests/picoc/38.exp: -------------------------------------------------------------------------------- 1 | x=0: 1 2 3 4 2 | x=1: 5 6 7 8 3 | x=2: 9 10 11 12 4 | x=3: 13 14 15 16 5 | -------------------------------------------------------------------------------- /v0100/tests/picoc/08.exp: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 2 4 | 3 5 | 5 6 | 8 7 | 13 8 | 21 9 | 34 10 | 55 11 | 89 12 | -------------------------------------------------------------------------------- /v0100/tests/picoc/09.exp: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 2 4 | 3 5 | 5 6 | 8 7 | 13 8 | 21 9 | 34 10 | 55 11 | 89 12 | -------------------------------------------------------------------------------- /v0100/tests/picoc/52.exp: -------------------------------------------------------------------------------- 1 | a=0 2 | b=1 3 | c=2 4 | e=0 5 | f=1 6 | g=2 7 | i=0 8 | j=1 9 | k=2 10 | -------------------------------------------------------------------------------- /v0100/tests/subc/readme.txt: -------------------------------------------------------------------------------- 1 | Tests from The SubC Compiler. 2 | See http://www.t3x.org/subc/index.html. 3 | -------------------------------------------------------------------------------- /v0100/srclib/errno.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | int errno; 6 | -------------------------------------------------------------------------------- /v0100/tests/lcc/readme.txt: -------------------------------------------------------------------------------- 1 | Tests from the LCC retargetable ANSI C compiler. 2 | See https://github.com/drh/lcc. 3 | -------------------------------------------------------------------------------- /v0100/tests/picoc/15.exp: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 6 4 | 24 5 | 120 6 | 720 7 | 5040 8 | 40320 9 | 362880 10 | 3628800 11 | -------------------------------------------------------------------------------- /v0100/tests/picoc/21.exp: -------------------------------------------------------------------------------- 1 | hello 2 | h: 104 3 | e: 101 4 | l: 108 5 | l: 108 6 | o: 111 7 | copied string is hello 8 | -------------------------------------------------------------------------------- /v0100/tests/picoc/54.exp: -------------------------------------------------------------------------------- 1 | In fred() 2 | At end 3 | In joe() 4 | c = 1234 5 | done 6 | In henry() 7 | b = 1234 8 | done 9 | -------------------------------------------------------------------------------- /v0100/tests/picoc/25.exp: -------------------------------------------------------------------------------- 1 | 62 83 4 89 36 21 74 37 65 33 96 38 53 16 74 55 2 | 4 16 21 33 36 37 38 53 55 62 65 74 74 83 89 96 3 | -------------------------------------------------------------------------------- /v0100/tests/picoc/32.exp: -------------------------------------------------------------------------------- 1 | _ _ _ _ 2 | | _| _| |_| |_ |_ | 3 | | |_ _| | _| |_| | 4 | 5 | -------------------------------------------------------------------------------- /v0100/tests/picoc/31.exp: -------------------------------------------------------------------------------- 1 | hello world 6 2 | arg 0: 31.exe 3 | arg 1: - 4 | arg 2: arg1 5 | arg 3: arg2 6 | arg 4: arg3 7 | arg 5: arg4 8 | -------------------------------------------------------------------------------- /v0100/tests/picoc/readme.txt: -------------------------------------------------------------------------------- 1 | Tests from tcc, originally from picoc. 2 | See http://bellard.org/tcc/, https://code.google.com/p/picoc/. 3 | -------------------------------------------------------------------------------- /v0100/tests/picoc/11.exp: -------------------------------------------------------------------------------- 1 | 134 2 | 134 3 | 0 4 | 1 5 | 1 6 | 1 7 | 1 8 | 46 9 | 1, 0 10 | 0, 1 11 | 1 12 | 1916 13 | 1916 14 | 64 15 | 4 16 | -------------------------------------------------------------------------------- /v0100/tests/bugs/ncompile/010.c: -------------------------------------------------------------------------------- 1 | extern int a[4]; 2 | 3 | int a[] = { 1 }; // doesn't compile 4 | 5 | int main(void) 6 | { 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /v0100/srclib/abs.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | int abs(int n) 6 | { 7 | return (n >= 0) ? n : -n; 8 | } 9 | -------------------------------------------------------------------------------- /v0100/tests/picoc/10.exp: -------------------------------------------------------------------------------- 1 | a = 42 2 | bolshevic.a = 12 3 | bolshevic.b = 34 4 | bolshevic.c = 56 5 | tsar->a = 12 6 | tsar->b = 34 7 | tsar->c = 56 8 | bolshevic.b = 34 9 | -------------------------------------------------------------------------------- /v0100/tests/bugs/ncompile/006.c: -------------------------------------------------------------------------------- 1 | // Tentative definitions aren't supported. 2 | // Should compile. 3 | int a; 4 | int a; 5 | 6 | int main(void) 7 | { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /v0100/tests/picoc/28.exp: -------------------------------------------------------------------------------- 1 | hello 2 | gollo 3 | 1 4 | 1 5 | 1 6 | 5 7 | gollo! 8 | 1 9 | 1 10 | 1 11 | 1 12 | ollo! 13 | lo! 14 | 1 15 | grrrr! 16 | grgrr! 17 | 1 18 | 1 19 | 1 20 | -------------------------------------------------------------------------------- /configure: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | lnk() { 3 | test -e "$2" || ln -s "$1/$2" "$2" 4 | } 5 | srcdir=`readlink -f $0 | sed 's@/[^/]*$@@'` 6 | lnk "$srcdir" Makefile 7 | lnk "$srcdir" GNUmakefile 8 | -------------------------------------------------------------------------------- /v0100/srclib/getc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | int getc(FILE* f) 8 | { 9 | return fgetc(f); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/tests/picoc/50.exp: -------------------------------------------------------------------------------- 1 | fred 2 | 0 3 | fred 4 | joe 5 | 1 6 | joe 7 | fred 8 | 0 9 | joe 10 | 1 11 | fred 12 | 0 13 | fred 14 | joe 15 | 1 16 | joe 17 | fred 18 | 0 19 | joe 20 | 1 21 | -------------------------------------------------------------------------------- /v0100/srclib/lngltz.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | int __lngLessThan0(unsigned short l[2]) 6 | { 7 | return l[1] > (unsigned short)-1 / 2; 8 | } 9 | -------------------------------------------------------------------------------- /v0100/tests/bugs/ncompile/007.c: -------------------------------------------------------------------------------- 1 | // Tentative definitions aren't supported. 2 | // Should compile. 3 | static int a; 4 | static int a; 5 | 6 | int main(void) 7 | { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /v0100/binl/readme.txt: -------------------------------------------------------------------------------- 1 | Precompiled Smaller C binaries for Linux. 2 | These can be used for cross-compiling for DOS, Windows and MacOS as well. 3 | 4 | System requirements: 5 | - Ubuntu 12.04 LTS or better 6 | -------------------------------------------------------------------------------- /v0100/srclib/feof.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int feof(FILE* f) 8 | { 9 | return f->flags & _IOEOF; 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/getchar.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int getchar(void) 8 | { 9 | return fgetc(stdin); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/ictype.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __ICTYPE_H 6 | #define __ICTYPE_H 7 | extern unsigned char __chartype__[1 + 256]; 8 | #endif 9 | -------------------------------------------------------------------------------- /v0100/srclib/putc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | int putc(int c, FILE* f) 8 | { 9 | return fputc(c, f); 10 | } 11 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | srcdir != readlink -f $(.PARSEDIR)/$(.PARSEFILE) | sed 's@[^/]*$$@v0100@' 2 | .PATH: $(srcdir) $(srcdir)/srclib 3 | PATH := $(.CURDIR):$(PATH) 4 | .export PATH 5 | .include "$(srcdir)/../common.mk" 6 | -------------------------------------------------------------------------------- /v0100/srclib/ferror.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int ferror(FILE* f) 8 | { 9 | return f->flags & _IOERR; 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/isgraph.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "ictype.h" 6 | 7 | int isgraph(int c) 8 | { 9 | return c > ' ' && c <= '~'; 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/putchar.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int putchar(int c) 8 | { 9 | return fputc(c, stdout); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/raise.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | int raise(int sig) 8 | { 9 | // TBD??? 10 | return -1; 11 | } 12 | -------------------------------------------------------------------------------- /v0100/tests/bugs/ncompile/009.c: -------------------------------------------------------------------------------- 1 | int typedef TyPeDeF; // doesn't compile 2 | int extern ExTeRn; // doesn't compile 3 | int static StAtIc; // doesn't compile 4 | 5 | int main(void) 6 | { 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /v0100/srclib/isblank.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "ictype.h" 6 | 7 | int isblank(int c) 8 | { 9 | return c == ' ' || c == '\t'; 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/isprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "ictype.h" 6 | 7 | int isprint(int c) 8 | { 9 | return c >= ' ' && c <= '~'; 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/labs.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __SMALLER_C_32__ 6 | long labs(long n) 7 | { 8 | return (n >= 0) ? n : -n; 9 | } 10 | #endif 11 | -------------------------------------------------------------------------------- /v0100/srclib/lngeq.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | int __lngEq(unsigned short a[2], unsigned short b[2]) 6 | { 7 | return (*a == *b) && (a[1] == b[1]); 8 | } 9 | -------------------------------------------------------------------------------- /v0100/srclib/remove.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | int remove(char* name) 8 | { 9 | return __unlink(name); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/tests/picoc/23.exp: -------------------------------------------------------------------------------- 1 | char: a 2 | char: b 3 | char: c 4 | int: 97 5 | int: 98 6 | int: 99 7 | float: 97.000000 8 | float: 98.000000 9 | float: 99.000000 10 | 97 97 11 | 97 97 12 | 97.000000 97.000000 13 | -------------------------------------------------------------------------------- /v0100/srclib/clearerr.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | void clearerr(FILE* f) 8 | { 9 | f->flags &= ~(_IOEOF | _IOERR); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/isalnum.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "ictype.h" 6 | 7 | int isalnum(int c) 8 | { 9 | return __chartype__[c + 1] & 0x38; 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/isalpha.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "ictype.h" 6 | 7 | int isalpha(int c) 8 | { 9 | return __chartype__[c + 1] & 0x30; 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/iscntrl.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "ictype.h" 6 | 7 | int iscntrl(int c) 8 | { 9 | return __chartype__[c + 1] & 0x01; 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/isdigit.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "ictype.h" 6 | 7 | int isdigit(int c) 8 | { 9 | return __chartype__[c + 1] & 0x08; 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/islower.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "ictype.h" 6 | 7 | int islower(int c) 8 | { 9 | return __chartype__[c + 1] & 0x20; 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/ispunct.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "ictype.h" 6 | 7 | int ispunct(int c) 8 | { 9 | return __chartype__[c + 1] & 0x04; 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/isspace.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "ictype.h" 6 | 7 | int isspace(int c) 8 | { 9 | return __chartype__[c + 1] & 0x02; 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/isupper.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "ictype.h" 6 | 7 | int isupper(int c) 8 | { 9 | return __chartype__[c + 1] & 0x10; 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/isxdigit.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "ictype.h" 6 | 7 | int isxdigit(int c) 8 | { 9 | return __chartype__[c + 1] & 0x48; 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/strcoll.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | int strcoll(char* s1, char* s2) 8 | { 9 | return strcmp(s1, s2); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/tests/bugs/compile/010.c: -------------------------------------------------------------------------------- 1 | extern int a; 2 | static int a; // shouldn't compile 3 | 4 | void f(void); 5 | static void f(void) {} // shouldn't compile 6 | 7 | int main(void) 8 | { 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /v0100/tests/picoc/16.exp: -------------------------------------------------------------------------------- 1 | 0 0 0 2 | 0 0 1 3 | 0 0 2 4 | 0 1 0 5 | 0 1 1 6 | 0 1 2 7 | 0 2 0 8 | 0 2 1 9 | 0 2 2 10 | 1 0 0 11 | 1 0 1 12 | 1 0 2 13 | 1 1 0 14 | 1 1 1 15 | 1 1 2 16 | 1 2 0 17 | 1 2 1 18 | 1 2 2 19 | -------------------------------------------------------------------------------- /GNUmakefile: -------------------------------------------------------------------------------- 1 | srcdir := $(dir $(shell readlink -f \ 2 | $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))))v0100 3 | VPATH = $(srcdir) $(srcdir)/srclib 4 | export PATH := $(CURDIR):$(PATH) 5 | include $(srcdir)/../common.mk 6 | -------------------------------------------------------------------------------- /v0100/srclib/stdio1.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | FILE __StreamsHead = 8 | { 9 | &__StreamsHead, 10 | &__StreamsHead 11 | }; 12 | -------------------------------------------------------------------------------- /v0100/srclib/toupper.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "ictype.h" 6 | 7 | int toupper(int c) 8 | { 9 | return c - (__chartype__[c + 1] & 0x20); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/tests/bugs/ncompile/004.c: -------------------------------------------------------------------------------- 1 | // We don't support declarations of new tagged types in casts. 2 | // Should compile. 3 | int a = (enum E { E0 })0; 4 | enum E e; 5 | 6 | int main(void) 7 | { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /v0100/srclib/tolower.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "ictype.h" 6 | 7 | int tolower(int c) 8 | { 9 | return c + ((__chartype__[c + 1] & 0x10) << 1); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/vscanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int vscanf(char* fmt, va_list vl) 8 | { 9 | return __doscan(stdin, fmt, vl); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/tests/bugs/ncompile/002.c: -------------------------------------------------------------------------------- 1 | // We don't support declarations of new tagged types in sizeof. 2 | // Should compile. 3 | int b = sizeof(enum E { E0 }); 4 | enum E e; 5 | 6 | int main(void) 7 | { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /v0100/tests/picoc/22.exp: -------------------------------------------------------------------------------- 1 | 69.12 2 | 69.12 3 | -44.44 4 | 700.665 5 | 0.21733 6 | 1 1 0 0 0 1 7 | 0 1 1 1 0 0 8 | 0 0 0 1 1 1 9 | 69.12 10 | -44.44 11 | 700.665 12 | 0.21733 13 | 12.34 14 | -12.34 15 | 2 16 | 0.909297 17 | -------------------------------------------------------------------------------- /v0100/srclib/vprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int vprintf(char* fmt, va_list vl) 8 | { 9 | return __doprint(stdout, fmt, vl); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/abort.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | void abort(void) 8 | { 9 | // TBD??? use raise(SIGABRT)??? 10 | exit(EXIT_FAILURE); 11 | } 12 | -------------------------------------------------------------------------------- /v0100/srclib/vfprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int vfprintf(FILE* f, char* fmt, va_list vl) 8 | { 9 | return __doprint(f, fmt, vl); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/vfscanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int vfscanf(FILE* f, char* fmt, va_list vl) 8 | { 9 | return __doscan(f, fmt, vl); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/tests/bugs/ncompile/003.c: -------------------------------------------------------------------------------- 1 | // We don't support declarations of new tagged types in casts. 2 | // Should compile. 3 | void* p = (struct S { char dummy; }*)0; 4 | struct S s; 5 | 6 | int main(void) 7 | { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /v0100/tests/lnktst1b.asm: -------------------------------------------------------------------------------- 1 | ; Part of lnktst1.asm test. 2 | 3 | bits 16 4 | 5 | extern msg 6 | 7 | section .text 8 | 9 | global func 10 | func: 11 | mov dx, msg 12 | mov ah, 9 13 | int 0x21 14 | 15 | ret 16 | -------------------------------------------------------------------------------- /v0100/srclib/atol.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | #ifdef __SMALLER_C_32__ 8 | long atol(char* nptr) 9 | { 10 | return atoi(nptr); 11 | } 12 | #endif 13 | -------------------------------------------------------------------------------- /v0100/srclib/scanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int scanf(char* fmt, ...) 8 | { 9 | return __doscan(stdin, fmt, (char*)&fmt + sizeof(char*)); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/setbuf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | void setbuf(FILE* f, char* buf) 8 | { 9 | setvbuf(f, buf, buf ? _IOFBF : _IONBF, BUFSIZ); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/tests/bugs/ncompile/001.c: -------------------------------------------------------------------------------- 1 | // We don't support declarations of new tagged types in sizeof. 2 | // Should compile. 3 | int a = sizeof(struct S { int dummy; }); 4 | struct S s; 5 | 6 | int main(void) 7 | { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /v0100/tests/picoc/18.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("including\n"); 6 | #include "18.h" 7 | printf("done\n"); 8 | 9 | return 0; 10 | } 11 | 12 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 13 | -------------------------------------------------------------------------------- /v0100/tests/picoc/43.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fred(void) 4 | { 5 | printf("yo\n"); 6 | } 7 | 8 | int main() 9 | { 10 | fred(); 11 | 12 | return 0; 13 | } 14 | 15 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 16 | -------------------------------------------------------------------------------- /v0100/srclib/printf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int printf(char* fmt, ...) 8 | { 9 | return __doprint(stdout, fmt, (char*)&fmt + sizeof(char*)); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/tests/bugs/compile/011.c: -------------------------------------------------------------------------------- 1 | int main(void) 2 | { 3 | { 4 | extern int v; 5 | void f(void); 6 | } 7 | { 8 | extern char* v; // shouldn't compile 9 | int f(int); // shouldn't compile 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /v0100/include/errno.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __ERRNO_H 6 | #define __ERRNO_H 7 | 8 | extern int errno; 9 | 10 | #define EDOM 33 11 | #define ERANGE 34 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/ctime.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | #ifdef __SMALLER_C_32__ 8 | char* ctime(time_t* t) 9 | { 10 | return asctime(localtime(t)); 11 | } 12 | #endif 13 | -------------------------------------------------------------------------------- /v0100/srclib/fprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int fprintf(FILE* f, char* fmt, ...) 8 | { 9 | return __doprint(f, fmt, (char*)&fmt + sizeof(char*)); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/fscanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int fscanf(FILE* f, char* fmt, ...) 8 | { 9 | return __doscan(f, fmt, (char*)&fmt + sizeof(char*)); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/srclib/creat.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | int __creat(char* name, mode_t mode) 8 | { 9 | return __open(name, O_WRONLY | O_CREAT | O_TRUNC, mode); 10 | } 11 | -------------------------------------------------------------------------------- /v0100/tests/picoc/36.exp: -------------------------------------------------------------------------------- 1 | 0: 12 2 | 1: 34 3 | 2: 56 4 | 3: 78 5 | 4: 90 6 | 5: 123 7 | 6: 456 8 | 7: 789 9 | 8: 8642 10 | 9: 9753 11 | 0: 12 12 | 1: 34 13 | 2: 56 14 | 3: 78 15 | 4: 90 16 | 5: 123 17 | 6: 456 18 | 7: 789 19 | 8: 8642 20 | 9: 9753 21 | -------------------------------------------------------------------------------- /v0100/srclib/atof.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __SMALLER_C_32__ 6 | 7 | #include 8 | 9 | double atof(char* nptr) 10 | { 11 | return strtod(nptr, NULL); 12 | } 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /v0100/srclib/lngul.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | int __lngUnsignedLess(unsigned short a[2], unsigned short b[2]) 6 | { 7 | return (a[1] < b[1]) || 8 | ((a[1] == b[1]) && (*a < *b)); 9 | } 10 | -------------------------------------------------------------------------------- /v0100/srclib/strcat.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | char* strcat(char* s1, char* s2) 6 | { 7 | char* res = s1; 8 | while (*s1) s1++; 9 | while ((*s1++ = *s2++) != '\0'); 10 | return res; 11 | } 12 | -------------------------------------------------------------------------------- /v0100/tests/bugs/compile/001.c: -------------------------------------------------------------------------------- 1 | // "Comma-expression" isn't a constant expression. 2 | // The constant expression is defined as a conditional expression. 3 | // Should not compile. 4 | int a = (1, 0); 5 | 6 | int main(void) 7 | { 8 | return a; 9 | } 10 | -------------------------------------------------------------------------------- /v0100/tests/picoc/37.exp: -------------------------------------------------------------------------------- 1 | ->01<- 2 | ->02<- 3 | ->03<- 4 | ->04<- 5 | ->05<- 6 | ->06<- 7 | ->07<- 8 | ->08<- 9 | ->09<- 10 | ->10<- 11 | ->11<- 12 | ->12<- 13 | ->13<- 14 | ->14<- 15 | ->15<- 16 | ->16<- 17 | ->17<- 18 | ->18<- 19 | ->19<- 20 | ->20<- 21 | -------------------------------------------------------------------------------- /v0100/srclib/puts.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | int puts(char* s) 8 | { 9 | int c; 10 | while ((c = *s++) != '\0') 11 | putchar(c); 12 | return putchar('\n'); 13 | } 14 | -------------------------------------------------------------------------------- /v0100/srclib/signal.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | void (*signal(int sig, void (*func)(int)))(int) 8 | { 9 | // TBD??? 10 | // errno = EUNKNOWN; 11 | return SIG_ERR; 12 | } 13 | -------------------------------------------------------------------------------- /v0100/tests/bugs/compile/005.c: -------------------------------------------------------------------------------- 1 | typedef struct { int dummy; } T; 2 | T a, b; 3 | 4 | int main(void) 5 | { 6 | // , doesn't yield lvalue. 7 | // But our structures are always lvalues. 8 | // Should not compile. 9 | (a, b) = a; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /v0100/tests/bugs/compile/006.c: -------------------------------------------------------------------------------- 1 | typedef struct { int dummy; } T; 2 | T a, b; 3 | 4 | int main(void) 5 | { 6 | // = doesn't yield lvalue. 7 | // But our structures are always lvalues. 8 | // Should not compile. 9 | (a = b) = a; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /v0100/tests/picoc/29.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char a[10]; 7 | strcpy(a, "abcdef"); 8 | printf("%s\n", &a[1]); 9 | 10 | return 0; 11 | } 12 | 13 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 14 | -------------------------------------------------------------------------------- /v0100/srclib/lngsub.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | void __lngSub(unsigned short acc[2], unsigned short subtrahend[2]) 6 | { 7 | acc[1] -= subtrahend[1] + (*acc < *subtrahend); 8 | *acc -= *subtrahend; 9 | } 10 | -------------------------------------------------------------------------------- /v0100/tests/bugs/compile/004.c: -------------------------------------------------------------------------------- 1 | typedef struct { int dummy; } T; 2 | T a, b; 3 | 4 | int main(void) 5 | { 6 | // ?: doesn't yield lvalue. 7 | // But our structures are always lvalues. 8 | // Should not compile. 9 | (0 ? a : b) = a; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /v0100/tests/bugs/compile/007.c: -------------------------------------------------------------------------------- 1 | // Enumeration types are incomplete unil the closing brace, }. 2 | // But we treat all enums as ints at all times. 3 | // Should not compile. 4 | enum E { ESZ = sizeof(enum E) }; 5 | 6 | int main(void) 7 | { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /v0100/tests/bugs/compile/009.c: -------------------------------------------------------------------------------- 1 | // Function-definition should not be part of declaration. 2 | // Some compilers allow this, including ours. 3 | // Should not compile. 4 | int one = 1, fzero(void) { return 0; } 5 | 6 | int main(void) 7 | { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /v0100/binm/readme.txt: -------------------------------------------------------------------------------- 1 | Precompiled Smaller C binaries for Mac OS X. 2 | These can be used for cross-compiling for DOS, Windows and Linux as well. 3 | 4 | System requirements: 5 | - Mac OS X 10.6 "Snow Leopard" to 10.14 "Mojave". 6 | Won't work on 10.15 "Catalina" or newer. 7 | -------------------------------------------------------------------------------- /v0100/srclib/div.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | div_t div(int numer, int denom) 8 | { 9 | div_t r; 10 | r.quot = numer / denom; 11 | r.rem = numer % denom; 12 | return r; 13 | } 14 | -------------------------------------------------------------------------------- /v0100/srclib/fputs.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | int fputs(char* s, FILE* f) 8 | { 9 | int c, r = 0; 10 | while ((c = *s++) != '\0') 11 | r |= fputc(c, f); 12 | return r; 13 | } 14 | -------------------------------------------------------------------------------- /v0100/srclib/lngadd.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | void __lngAdd(unsigned short acc[2], unsigned short addend[2]) 6 | { 7 | acc[1] += addend[1] + (*addend > (unsigned short)-1 - *acc); 8 | *acc += *addend; 9 | } 10 | -------------------------------------------------------------------------------- /v0100/tests/picoc/24.exp: -------------------------------------------------------------------------------- 1 | 0.119712 2 | 0.992809 3 | 0.120579 4 | 0.120290 5 | 1.450506 6 | 0.119429 7 | 0.120288 8 | 1.007209 9 | 0.119427 10 | 1.127497 11 | 0.120000 12 | -2.120264 13 | -0.920819 14 | 0.775357 15 | 0.346410 16 | 12.000000 17 | 13.000000 18 | 12.000000 19 | -------------------------------------------------------------------------------- /v0100/srclib/strtod.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __SMALLER_C_32__ 6 | 7 | #include 8 | 9 | double strtod(char* nptr, char** endptr) 10 | { 11 | return strtof(nptr, endptr); 12 | } 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /v0100/tests/bugs/compile/002.c: -------------------------------------------------------------------------------- 1 | char* p1; 2 | struct { char dummy; }* p2; 3 | 4 | int main(void) 5 | { 6 | // Difference of pointers to incompatible types 7 | // (we only check the type's sizes, not the actual types). 8 | // Should not compile. 9 | return p1 - p2; 10 | } 11 | -------------------------------------------------------------------------------- /v0100/tests/picoc/04.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | 7 | for (Count = 1; Count <= 10; Count++) 8 | { 9 | printf("%d\n", Count); 10 | } 11 | 12 | return 0; 13 | } 14 | 15 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 16 | -------------------------------------------------------------------------------- /v0100/tests/bugs/compile/008.c: -------------------------------------------------------------------------------- 1 | typedef int F(int a, int b); 2 | F add; 3 | 4 | // The following function definition (both declaration and 5 | // compound-statement) should not compile. 6 | F add 7 | { 8 | return a + b; 9 | } 10 | 11 | int main(void) 12 | { 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /v0100/tests/bugs/ncompile/008.c: -------------------------------------------------------------------------------- 1 | // Composite types aren't fully supported. 2 | // Should compile. 3 | extern int a[]; 4 | extern int a[10]; 5 | extern int a[]; 6 | 7 | int main(); 8 | int main(int argc, char* argv[]) 9 | { 10 | return 0; 11 | } 12 | int main(); // doesn't compile 13 | -------------------------------------------------------------------------------- /v0100/tests/picoc/44.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | 7 | for (a = 0; a < 2; a++) 8 | { 9 | int b = a; 10 | } 11 | 12 | printf("it's all good\n"); 13 | 14 | return 0; 15 | } 16 | 17 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 18 | -------------------------------------------------------------------------------- /v0100/tests/bugs/compile/003.c: -------------------------------------------------------------------------------- 1 | typedef struct { int dummy; } T; 2 | T a, b; 3 | T f(void) { return a; } 4 | 5 | int main(void) 6 | { 7 | // Functions don't return lvalues. 8 | // But our structures are always lvalues. 9 | // Should not compile. 10 | f() = b; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/heapfre_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___HeapFree\n" 8 | "global _HeapFree\n" 9 | "section .text\n" 10 | "_HeapFree:\n" 11 | "jmp ___HeapFree"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/readfil_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___ReadFile\n" 8 | "global _ReadFile\n" 9 | "section .text\n" 10 | "_ReadFile:\n" 11 | "jmp ___ReadFile"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/memchr.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | char* memchr(char* s, int c, unsigned n) 6 | { 7 | c = (char)c; 8 | 9 | while (n--) 10 | { 11 | if (*s == c) 12 | return s; 13 | s++; 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /v0100/srclib/stdin.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | #include "istdio.h" 7 | 8 | static FILE StdIn = 9 | { 10 | 0, 11 | 0, 12 | STDIN_FILENO, 13 | _IORD | _IOTERM | _IOLBF 14 | }; 15 | 16 | FILE* __stdin = &StdIn; 17 | -------------------------------------------------------------------------------- /v0100/tests/picoc/02.exp: -------------------------------------------------------------------------------- 1 | Hello world 2 | Count = -5 3 | Count = -4 4 | Count = -3 5 | Count = -2 6 | Count = -1 7 | Count = 0 8 | Count = 1 9 | Count = 2 10 | Count = 3 11 | Count = 4 12 | Count = 5 13 | String 'hello', 'there' is 'hello', 'there' 14 | Character 'A' is 'A' 15 | Character 'a' is 'a' 16 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/heapall_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___HeapAlloc\n" 8 | "global _HeapAlloc\n" 9 | "section .text\n" 10 | "_HeapAlloc:\n" 11 | "jmp ___HeapAlloc"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/movefil_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___MoveFileA\n" 8 | "global _MoveFileA\n" 9 | "section .text\n" 10 | "_MoveFileA:\n" 11 | "jmp ___MoveFileA"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/writefi_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___WriteFile\n" 8 | "global _WriteFile\n" 9 | "section .text\n" 10 | "_WriteFile:\n" 11 | "jmp ___WriteFile"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/stderr.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | #include "istdio.h" 7 | 8 | static FILE StdErr = 9 | { 10 | 0, 11 | 0, 12 | STDERR_FILENO, 13 | _IOWR | _IOTERM | _IONBF 14 | }; 15 | 16 | FILE* __stderr = &StdErr; 17 | -------------------------------------------------------------------------------- /v0100/srclib/stdout.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | #include "istdio.h" 7 | 8 | static FILE StdOut = 9 | { 10 | 0, 11 | 0, 12 | STDOUT_FILENO, 13 | _IOWR | _IOTERM | _IOLBF 14 | }; 15 | 16 | FILE* __stdout = &StdOut; 17 | -------------------------------------------------------------------------------- /v0100/tests/picoc/12.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define FRED 12 4 | #define BLOGGS(x) (12*(x)) 5 | 6 | int main() 7 | { 8 | printf("%d\n", FRED); 9 | printf("%d, %d, %d\n", BLOGGS(1), BLOGGS(2), BLOGGS(3)); 10 | 11 | return 0; 12 | } 13 | 14 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 15 | -------------------------------------------------------------------------------- /v0100/lib/readme.txt: -------------------------------------------------------------------------------- 1 | Smaller C libraries for DOS, Windows and Linux: 2 | - lcdh.a (DOS, huge mode(l) .EXE) 3 | - lcdu.a (DOS, unreal mode(l) .EXE) 4 | - lcds.a (DOS, tiny mode(l) .COM and small mode(l) .EXE) 5 | - lcdp.a, dpstub.exe (DOS, 32-bit DPMI .EXE) 6 | - lcm.a (Mac OS X) 7 | - lcl.a (Linux) 8 | - lcw.a (Windows) 9 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/closeha_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___CloseHandle\n" 8 | "global _CloseHandle\n" 9 | "section .text\n" 10 | "_CloseHandle:\n" 11 | "jmp ___CloseHandle"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/createf_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___CreateFileA\n" 8 | "global _CreateFileA\n" 9 | "section .text\n" 10 | "_CreateFileA:\n" 11 | "jmp ___CreateFileA"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/deletef_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___DeleteFileA\n" 8 | "global _DeleteFileA\n" 9 | "section .text\n" 10 | "_DeleteFileA:\n" 11 | "jmp ___DeleteFileA"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/exitpro_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___ExitProcess\n" 8 | "global _ExitProcess\n" 9 | "section .text\n" 10 | "_ExitProcess:\n" 11 | "jmp ___ExitProcess"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/freelib_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___FreeLibrary\n" 8 | "global _FreeLibrary\n" 9 | "section .text\n" 10 | "_FreeLibrary:\n" 11 | "jmp ___FreeLibrary"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getfity_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___GetFileType\n" 8 | "global _GetFileType\n" 9 | "section .text\n" 10 | "_GetFileType:\n" 11 | "jmp ___GetFileType"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getlerr_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___GetLastError\n" 8 | "global _GetLastError\n" 9 | "section .text\n" 10 | "_GetLastError:\n" 11 | "jmp ___GetLastError"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getstdh_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___GetStdHandle\n" 8 | "global _GetStdHandle\n" 9 | "section .text\n" 10 | "_GetStdHandle:\n" 11 | "jmp ___GetStdHandle"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/gettick_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___GetTickCount\n" 8 | "global _GetTickCount\n" 9 | "section .text\n" 10 | "_GetTickCount:\n" 11 | "jmp ___GetTickCount"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/heaprea_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___HeapReAlloc\n" 8 | "global _HeapReAlloc\n" 9 | "section .text\n" 10 | "_HeapReAlloc:\n" 11 | "jmp ___HeapReAlloc"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/setlerr_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___SetLastError\n" 8 | "global _SetLastError\n" 9 | "section .text\n" 10 | "_SetLastError:\n" 11 | "jmp ___SetLastError"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/ldiv.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | #ifdef __SMALLER_C_32__ 8 | ldiv_t ldiv(long numer, long denom) 9 | { 10 | ldiv_t r; 11 | r.quot = numer / denom; 12 | r.rem = numer % denom; 13 | return r; 14 | } 15 | #endif 16 | -------------------------------------------------------------------------------- /v0100/srclib/stdio2.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | void __FileCloser(void) 8 | { 9 | for (;;) 10 | { 11 | FILE* f = __StreamsHead.next; 12 | if (f == &__StreamsHead) 13 | break; 14 | fclose(f); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /v0100/tests/picoc/33.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | 7 | for (Count = 0; Count < 10; Count++) 8 | { 9 | printf("%d\n", (Count < 5) ? (Count*Count) : (Count * 3)); 10 | } 11 | 12 | return 0; 13 | } 14 | 15 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 16 | -------------------------------------------------------------------------------- /v0100/tests/picoc/42.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fred(int p) 4 | { 5 | printf("yo %d\n", p); 6 | return 42; 7 | } 8 | 9 | int (*f)(int) = &fred; 10 | 11 | int main() 12 | { 13 | printf("%d\n", (*f)(24)); 14 | 15 | return 0; 16 | } 17 | 18 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 19 | -------------------------------------------------------------------------------- /v0100/srclib/atan.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | 10 | float atanf(float x) 11 | { 12 | return atan2f(x, 1); 13 | } 14 | 15 | double atan(double x) 16 | { 17 | return atanf(x); 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getstim_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___GetSystemTime\n" 8 | "global _GetSystemTime\n" 9 | "section .text\n" 10 | "_GetSystemTime:\n" 11 | "jmp ___GetSystemTime"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/tests/picoc/35.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char a; 6 | short b; 7 | 8 | printf("%d %d\n", (int)sizeof(char), (int)sizeof(a)); 9 | printf("%d %d\n", (int)sizeof(short), (int)sizeof(b)); 10 | 11 | return 0; 12 | } 13 | 14 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 15 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/creatpr_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___CreateProcessA\n" 8 | "global _CreateProcessA\n" 9 | "section .text\n" 10 | "_CreateProcessA:\n" 11 | "jmp ___CreateProcessA"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getphea_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___GetProcessHeap\n" 8 | "global _GetProcessHeap\n" 9 | "section .text\n" 10 | "_GetProcessHeap:\n" 11 | "jmp ___GetProcessHeap"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getprad_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___GetProcAddress\n" 8 | "global _GetProcAddress\n" 9 | "section .text\n" 10 | "_GetProcAddress:\n" 11 | "jmp ___GetProcAddress"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/loadlbx_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___LoadLibraryExA\n" 8 | "global _LoadLibraryExA\n" 9 | "section .text\n" 10 | "_LoadLibraryExA:\n" 11 | "jmp ___LoadLibraryExA"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/setfptr_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___SetFilePointer\n" 8 | "global _SetFilePointer\n" 9 | "section .text\n" 10 | "_SetFilePointer:\n" 11 | "jmp ___SetFilePointer"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/tests/picoc/45.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count = 0; 6 | 7 | for (;;) 8 | { 9 | Count++; 10 | printf("%d\n", Count); 11 | if (Count >= 10) 12 | break; 13 | } 14 | 15 | return 0; 16 | } 17 | 18 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 19 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getcomm_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___GetCommandLineA\n" 8 | "global _GetCommandLineA\n" 9 | "section .text\n" 10 | "_GetCommandLineA:\n" 11 | "jmp ___GetCommandLineA"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/tests/picoc/27.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char a; 6 | int b; 7 | float c; 8 | 9 | printf("%d\n", (int)sizeof(a)); 10 | printf("%d\n", (int)sizeof(b)); 11 | printf("%d\n", (int)sizeof(c)); 12 | 13 | return 0; 14 | } 15 | 16 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 17 | -------------------------------------------------------------------------------- /v0100/srclib/setlocal.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | char* setlocale(int category, char* locale) 8 | { 9 | (void)category; 10 | if (!locale || *locale == '\0' || (*locale == 'C' && locale[1] == '\0')) 11 | return "C"; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /v0100/srclib/strrchr.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | char* strrchr(char* s, int c) 6 | { 7 | char* res = 0; 8 | c = (char)c; 9 | while (*s) 10 | { 11 | if (*s == c) 12 | res = s; 13 | s++; 14 | } 15 | if (!c) 16 | res = s; 17 | return res; 18 | } 19 | -------------------------------------------------------------------------------- /v0100/tests/picoc/00.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | a = 42; 7 | printf("%d\n", a); 8 | 9 | int b = 64; 10 | printf("%d\n", b); 11 | 12 | int c = 12, d = 34; 13 | printf("%d, %d\n", c, d); 14 | 15 | return 0; 16 | } 17 | 18 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 19 | -------------------------------------------------------------------------------- /v0100/srclib/exp.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | 10 | float expf(float x) 11 | { 12 | return exp2f(x * 1.44269504f/*log2(e)*/); 13 | } 14 | 15 | double exp(double x) 16 | { 17 | return expf(x); 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /v0100/srclib/gmtime.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "itime.h" 6 | 7 | #ifdef __SMALLER_C_32__ 8 | 9 | // gmtime() must take UTC/GMT time and return UTC/GMT time 10 | struct tm* gmtime(time_t* t) 11 | { 12 | return __breaktime(t); 13 | } 14 | 15 | #endif // __SMALLER_C_32__ 16 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getexit_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___GetExitCodeProcess\n" 8 | "global _GetExitCodeProcess\n" 9 | "section .text\n" 10 | "_GetExitCodeProcess:\n" 11 | "jmp ___GetExitCodeProcess"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getfiat_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___GetFileAttributesA\n" 8 | "global _GetFileAttributesA\n" 9 | "section .text\n" 10 | "_GetFileAttributesA:\n" 11 | "jmp ___GetFileAttributesA"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/perror.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | #include 7 | 8 | void perror(char* s) 9 | { 10 | if (s && *s) 11 | fprintf(stderr, "%s: Unknown error %d\n", s, errno); 12 | else 13 | fprintf(stderr, "Unknown error %d\n", errno); 14 | } 15 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/wait4so_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___WaitForSingleObject\n" 8 | "global _WaitForSingleObject\n" 9 | "section .text\n" 10 | "_WaitForSingleObject:\n" 11 | "jmp ___WaitForSingleObject"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/tests/picoc/31.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | int Count; 6 | 7 | printf("hello world %d\n", argc); 8 | for (Count = 0; Count < argc; Count++) 9 | printf("arg %d: %s\n", Count, argv[Count]); 10 | 11 | return 0; 12 | } 13 | 14 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 15 | -------------------------------------------------------------------------------- /v0100/tests/picoc/37.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char Buf[100]; 6 | int Count; 7 | 8 | for (Count = 1; Count <= 20; Count++) 9 | { 10 | sprintf(Buf, "->%02d<-\n", Count); 11 | printf("%s", Buf); 12 | } 13 | 14 | return 0; 15 | } 16 | 17 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 18 | -------------------------------------------------------------------------------- /v0100/srclib/strpbrk.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | char* strpbrk(char* s1, char* s2) 6 | { 7 | int c, c2; 8 | while ((c = *s1++) != '\0') 9 | { 10 | char* p = s2; 11 | while ((c2 = *p++) != '\0') 12 | if (c2 == c) 13 | return s1 - 1; 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /v0100/tests/picoc/01.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("Hello\n"); 6 | printf("Hello\n"); /* this is a comment */ printf("Hello\n"); 7 | printf("Hello\n"); 8 | // this is also a comment sayhello(); 9 | printf("Hello\n"); 10 | 11 | return 0; 12 | } 13 | 14 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 15 | -------------------------------------------------------------------------------- /v0100/srclib/gets.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | char* gets(char* s) 8 | { 9 | char* res = s; 10 | int c; 11 | while ((c = getchar()) != '\n' && c != EOF) 12 | *s++ = c; 13 | if (c == EOF && s == res) 14 | return NULL; 15 | *s = '\0'; 16 | return res; 17 | } 18 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getenvi_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___GetEnvironmentVariableA\n" 8 | "global _GetEnvironmentVariableA\n" 9 | "section .text\n" 10 | "_GetEnvironmentVariableA:\n" 11 | "jmp ___GetEnvironmentVariableA"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/strspn.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | unsigned strspn(char* s1, char* s2) 6 | { 7 | char *s = s1, *p; 8 | int c, c2; 9 | 10 | lskip: 11 | c = *s1++; 12 | p = s2; 13 | while ((c2 = *p++) != '\0') 14 | if (c2 == c) 15 | goto lskip; 16 | 17 | return s1 - 1 - s; 18 | } 19 | -------------------------------------------------------------------------------- /v0100/srclib/memcmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | int memcmp(void* s1, void* s2, unsigned n) 6 | { 7 | if (n) 8 | { 9 | unsigned char *p1 = s1, *p2 = s2; 10 | do 11 | { 12 | if (*p1++ != *p2++) 13 | return (*--p1 - *--p2); 14 | } while (--n); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /v0100/srclib/strncpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | char* strncpy(char* s1, char* s2, unsigned n) 6 | { 7 | char* res = s1; 8 | 9 | while (n) 10 | { 11 | n--; 12 | if ((*s1++ = *s2++) == '\0') 13 | break; 14 | } 15 | while (n--) 16 | *s1++ = '\0'; 17 | 18 | return res; 19 | } 20 | -------------------------------------------------------------------------------- /v0100/srclib/c0w.asm: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright (c) 2014-2015, Alexey Frunze 3 | ; 2-clause BSD license. 4 | ; 5 | bits 32 6 | 7 | extern ___start__ 8 | 9 | section .text 10 | 11 | global __start 12 | __start: 13 | jmp ___start__ ; __start__() will set up argc and argv for main() and call exit(main(argc, argv)) 14 | 15 | 16 | section .bss 17 | resd 1 18 | -------------------------------------------------------------------------------- /v0100/srclib/cosh.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | 10 | float coshf(float x) 11 | { 12 | x = x * 1.44269504f/*log2(e)*/; 13 | return exp2f(x - 1) + exp2f(-x - 1); 14 | } 15 | 16 | double cosh(double x) 17 | { 18 | return coshf(x); 19 | } 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/setuhef_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___SetUnhandledExceptionFilter\n" 8 | "global _SetUnhandledExceptionFilter\n" 9 | "section .text\n" 10 | "_SetUnhandledExceptionFilter:\n" 11 | "jmp ___SetUnhandledExceptionFilter"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getlaste.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "GetLastError" 9 | #include "../dimports.h" 10 | 11 | unsigned __GetLastError(void) 12 | { 13 | asm( 14 | "call dword [__imp__GetLastError]" 15 | ); 16 | } 17 | 18 | #endif // _WINDOWS 19 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/gettickc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "GetTickCount" 9 | #include "../dimports.h" 10 | 11 | unsigned __GetTickCount(void) 12 | { 13 | asm( 14 | "call dword [__imp__GetTickCount]" 15 | ); 16 | } 17 | 18 | #endif // _WINDOWS 19 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getcomma.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "GetCommandLineA" 9 | #include "../dimports.h" 10 | 11 | char* __GetCommandLineA(void) 12 | { 13 | asm( 14 | "call dword [__imp__GetCommandLineA]" 15 | ); 16 | } 17 | 18 | #endif // _WINDOWS 19 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getpheap.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "GetProcessHeap" 9 | #include "../dimports.h" 10 | 11 | unsigned __GetProcessHeap(void) 12 | { 13 | asm( 14 | "call dword [__imp__GetProcessHeap]" 15 | ); 16 | } 17 | 18 | #endif // _WINDOWS 19 | -------------------------------------------------------------------------------- /v0100/srclib/strcspn.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | unsigned strcspn(char* s1, char* s2) 6 | { 7 | char *s = s1, *p; 8 | int c, c2; 9 | 10 | for (;;) 11 | { 12 | c = *s1++; 13 | p = s2; 14 | do 15 | { 16 | if ((c2 = *p++) == c) 17 | return s1 - 1 - s; 18 | } while (c2); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /v0100/tests/picoc/08.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int p; 7 | int t; 8 | 9 | a = 1; 10 | p = 0; 11 | t = 0; 12 | 13 | while (a < 100) 14 | { 15 | printf("%d\n", a); 16 | t = a; 17 | a = t + p; 18 | p = t; 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 25 | -------------------------------------------------------------------------------- /v0100/srclib/difftime.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | 10 | double difftime(time_t time1, time_t time0) 11 | { 12 | if (time1 >= time0) 13 | return (double)((unsigned long)time1 - time0); 14 | return -(double)((unsigned long)time0 - time1); 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /v0100/tests/picoc/09.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int p; 7 | int t; 8 | 9 | a = 1; 10 | p = 0; 11 | t = 0; 12 | 13 | do 14 | { 15 | printf("%d\n", a); 16 | t = a; 17 | a = t + p; 18 | p = t; 19 | } while (a < 100); 20 | 21 | return 0; 22 | } 23 | 24 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 25 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/st2tzlt_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___SystemTimeToTzSpecificLocalTime\n" 8 | "global _SystemTimeToTzSpecificLocalTime\n" 9 | "section .text\n" 10 | "_SystemTimeToTzSpecificLocalTime:\n" 11 | "jmp ___SystemTimeToTzSpecificLocalTime"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/tzlt2st_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm("extern ___TzSpecificLocalTimeToSystemTime\n" 8 | "global _TzSpecificLocalTimeToSystemTime\n" 9 | "section .text\n" 10 | "_TzSpecificLocalTimeToSystemTime:\n" 11 | "jmp ___TzSpecificLocalTimeToSystemTime"); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /v0100/srclib/mm.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __MM_H 6 | #define __MM_H 7 | 8 | #ifdef __SMALLER_C_16__ 9 | extern char _stop_alldata__; 10 | extern char _start_stack__; 11 | #endif 12 | 13 | #define HEADER_FOOTER_SZ (2*sizeof(unsigned)) 14 | 15 | extern unsigned __heap_start; 16 | extern unsigned __heap_stop; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /v0100/tests/picoc/14.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a = 1; 6 | 7 | if (a) 8 | printf("a is true\n"); 9 | else 10 | printf("a is false\n"); 11 | 12 | int b = 0; 13 | if (b) 14 | printf("b is true\n"); 15 | else 16 | printf("b is false\n"); 17 | 18 | return 0; 19 | } 20 | 21 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 22 | -------------------------------------------------------------------------------- /v0100/bind/readme.txt: -------------------------------------------------------------------------------- 1 | Precompiled Smaller C binaries for DOS. 2 | (You may want to use faster DPMI binaries from ../bindp.) 3 | These can be used for cross-compiling for Windows, Linux and MacOS as well. 4 | 5 | System requirements: 6 | - DOS: MS-DOS 3.0 or better, i80386 CPU & i80387 FPU or better 7 | - Windows: Windows 95/98/Me/2000/XP or 32-bit Windows Vista/7 8 | - Emulation: DOSBox 0.74 or better 9 | -------------------------------------------------------------------------------- /v0100/srclib/fakmvcrt/abs.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "msvcrt" 8 | #define FXN "abs" 9 | #include "../dimports.h" 10 | 11 | int __msvcrt_abs(int x) 12 | { 13 | asm( 14 | "push dword [ebp+8]\n" 15 | "call dword [__imp__abs]\n" 16 | "add esp, 4" 17 | ); 18 | } 19 | 20 | #endif // _WINDOWS 21 | -------------------------------------------------------------------------------- /v0100/tests/picoc/26.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("%d\n", '\1'); 6 | printf("%d\n", '\10'); 7 | printf("%d\n", '\100'); 8 | printf("%d\n", '\x01'); 9 | printf("%d\n", '\x0e'); 10 | printf("%d\n", '\x10'); 11 | printf("%d\n", '\x40'); 12 | printf("test \x40\n"); 13 | 14 | return 0; 15 | } 16 | 17 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 18 | -------------------------------------------------------------------------------- /v0100/srclib/calloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | #include 7 | 8 | void* calloc(size_t ecnt, size_t esize) 9 | { 10 | size_t size = ecnt * esize; 11 | void* p; 12 | if (!size || size / esize != ecnt) 13 | return NULL; 14 | p = malloc(size); 15 | if (p) 16 | memset(p, 0, size); 17 | return p; 18 | } 19 | -------------------------------------------------------------------------------- /v0100/tests/picoc/15.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int factorial(int i) 4 | { 5 | if (i < 2) 6 | return i; 7 | else 8 | return i * factorial(i - 1); 9 | } 10 | 11 | int main() 12 | { 13 | int Count; 14 | 15 | for (Count = 1; Count <= 10; Count++) 16 | printf("%d\n", factorial(Count)); 17 | 18 | return 0; 19 | } 20 | 21 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 22 | -------------------------------------------------------------------------------- /v0100/srclib/fgets.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | char* fgets(char* s, int n, FILE* f) 8 | { 9 | char* res = s; 10 | int c = 0; 11 | while (--n > 0 && (c = fgetc(f)) != EOF) 12 | if ((*s++ = c) == '\n') 13 | break; 14 | if (c == EOF && s == res) 15 | return NULL; 16 | *s = '\0'; 17 | return res; 18 | } 19 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/closehan.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "CloseHandle" 9 | #include "../dimports.h" 10 | 11 | int __CloseHandle(unsigned Handle) 12 | { 13 | asm( 14 | "push dword [ebp+8]\n" 15 | "call dword [__imp__CloseHandle]" 16 | ); 17 | } 18 | 19 | #endif // _WINDOWS 20 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/deletefi.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "DeleteFileA" 9 | #include "../dimports.h" 10 | 11 | int __DeleteFileA(char* FileName) 12 | { 13 | asm( 14 | "push dword [ebp+8]\n" 15 | "call dword [__imp__DeleteFileA]" 16 | ); 17 | } 18 | 19 | #endif // _WINDOWS 20 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/freelibr.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "FreeLibrary" 9 | #include "../dimports.h" 10 | 11 | int __FreeLibrary(void* hModule) 12 | { 13 | asm( 14 | "push dword [ebp+8]\n" 15 | "call dword [__imp__FreeLibrary]" 16 | ); 17 | } 18 | 19 | #endif // _WINDOWS 20 | -------------------------------------------------------------------------------- /v0100/tests/picoc/16.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int x, y, z; 6 | 7 | for (x = 0; x < 2; x++) 8 | { 9 | for (y = 0; y < 3; y++) 10 | { 11 | for (z = 0; z < 3; z++) 12 | { 13 | printf("%d %d %d\n", x, y, z); 14 | } 15 | } 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 22 | -------------------------------------------------------------------------------- /v0100/include/iso646.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __ISO646_H 6 | #define __ISO646_H 7 | 8 | #define and && 9 | #define and_eq &= 10 | #define bitand & 11 | #define bitor | 12 | #define compl ~ 13 | #define not ! 14 | #define not_eq != 15 | #define or || 16 | #define or_eq |= 17 | #define xor ^ 18 | #define xor_eq ^= 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/exitproc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "ExitProcess" 9 | #include "../dimports.h" 10 | 11 | void __ExitProcess(unsigned ExitCode) 12 | { 13 | asm( 14 | "push dword [ebp+8]\n" 15 | "call dword [__imp__ExitProcess]" 16 | ); 17 | } 18 | 19 | #endif // _WINDOWS 20 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getfilet.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "GetFileType" 9 | #include "../dimports.h" 10 | 11 | unsigned __GetFileType(unsigned Handle) 12 | { 13 | asm( 14 | "push dword [ebp+8]\n" 15 | "call dword [__imp__GetFileType]" 16 | ); 17 | } 18 | 19 | #endif // _WINDOWS 20 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/setlaste.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "SetLastError" 9 | #include "../dimports.h" 10 | 11 | void __SetLastError(unsigned Error) 12 | { 13 | asm( 14 | "push dword [ebp+8]\n" 15 | "call dword [__imp__SetLastError]" 16 | ); 17 | } 18 | 19 | #endif // _WINDOWS 20 | -------------------------------------------------------------------------------- /v0100/srclib/srand.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __SMALLER_C_32__ 6 | extern unsigned __Seed; 7 | 8 | void srand(unsigned seed) 9 | { 10 | __Seed = seed; 11 | } 12 | #endif 13 | 14 | #ifdef __SMALLER_C_16__ 15 | extern unsigned short __Seed[2]; 16 | 17 | void srand(unsigned seed) 18 | { 19 | __Seed[0] = seed; 20 | __Seed[1] = 0; 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /v0100/srclib/strncat.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | char* strncat(char* s1, char* s2, unsigned n) 6 | { 7 | char* res = s1; 8 | int c; 9 | 10 | while (*s1 != '\0') 11 | s1++; 12 | 13 | while (n) 14 | { 15 | if ((c = *s2++) == '\0') 16 | break; 17 | *s1++ = c; 18 | n--; 19 | } 20 | *s1 = '\0'; 21 | 22 | return res; 23 | } 24 | -------------------------------------------------------------------------------- /v0100/srclib/c0l.asm: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright (c) 2014-2015, Alexey Frunze 3 | ; 2-clause BSD license. 4 | ; 5 | bits 32 6 | 7 | extern ___start__ 8 | 9 | section .text 10 | 11 | global __start 12 | __start: 13 | pop eax ; argc 14 | push esp ; argv 15 | push eax ; argc 16 | call ___start__ ; __start__(arc, argv) will call exit(main(argc, argv)) 17 | 18 | section .bss 19 | resd 1 20 | -------------------------------------------------------------------------------- /v0100/tests/picoc/05.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | int Array[10]; 7 | 8 | for (Count = 1; Count <= 10; Count++) 9 | { 10 | Array[Count-1] = Count * Count; 11 | } 12 | 13 | for (Count = 0; Count < 10; Count++) 14 | { 15 | printf("%d\n", Array[Count]); 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 22 | -------------------------------------------------------------------------------- /v0100/include/setjmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __SETJMP_H 6 | #define __SETJMP_H 7 | 8 | typedef struct 9 | { 10 | unsigned xip; // ip / cs:ip / eip 11 | unsigned xflags; // (e)flags 12 | unsigned xbp; // (e)bp 13 | unsigned xsp; // (e)sp 14 | } jmp_buf[1]; 15 | 16 | int setjmp(jmp_buf); 17 | void longjmp(jmp_buf, int); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getstdha.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "GetStdHandle" 9 | #include "../dimports.h" 10 | 11 | unsigned __GetStdHandle(unsigned nStdHandle) 12 | { 13 | asm( 14 | "push dword [ebp+8]\n" 15 | "call dword [__imp__GetStdHandle]" 16 | ); 17 | } 18 | 19 | #endif // _WINDOWS 20 | -------------------------------------------------------------------------------- /v0100/srclib/vsscanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | #include 7 | 8 | int vsscanf(char* s, char* fmt, va_list vl) 9 | { 10 | FILE f; 11 | f.flags = _IORD | _IOSTRING | _IOBINARY; // don't do file I/O, don't translate "\n" to "\r\n" 12 | f.ptr = f.buf = s; 13 | f.cnt = f.bufsz = strlen(s); 14 | return __doscan(&f, fmt, vl); 15 | } 16 | -------------------------------------------------------------------------------- /v0100/tests/picoc/13.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a = 24680; 6 | int b = 01234567; 7 | int c = 0x2468ac; 8 | int d = 0x2468AC; 9 | // int e = 0b010101010101; 10 | 11 | printf("%d\n", a); 12 | printf("%d\n", b); 13 | printf("%d\n", c); 14 | printf("%d\n", d); 15 | // printf("%d\n", e); 16 | 17 | return 0; 18 | } 19 | 20 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 21 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getfilea.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "GetFileAttributesA" 9 | #include "../dimports.h" 10 | 11 | unsigned __GetFileAttributesA(char* lpFileName) 12 | { 13 | asm( 14 | "push dword [ebp+8]\n" 15 | "call dword [__imp__GetFileAttributesA]" 16 | ); 17 | } 18 | 19 | #endif // _WINDOWS 20 | -------------------------------------------------------------------------------- /v0100/tests/picoc/47.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fred(int x) 4 | { 5 | switch (x) 6 | { 7 | case 1: printf("1\n"); return; 8 | case 2: printf("2\n"); break; 9 | case 3: printf("3\n"); return; 10 | } 11 | 12 | printf("out\n"); 13 | } 14 | 15 | int main() 16 | { 17 | fred(1); 18 | fred(2); 19 | fred(3); 20 | 21 | return 0; 22 | } 23 | 24 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 25 | -------------------------------------------------------------------------------- /v0100/srclib/sscanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | #include 7 | 8 | int sscanf(char* s, char* fmt, ...) 9 | { 10 | FILE f; 11 | f.flags = _IORD | _IOSTRING | _IOBINARY; // don't do file I/O, don't translate "\n" to "\r\n" 12 | f.ptr = f.buf = s; 13 | f.cnt = f.bufsz = strlen(s); 14 | return __doscan(&f, fmt, (char*)&fmt + sizeof(char*)); 15 | } 16 | -------------------------------------------------------------------------------- /v0100/tests/picoc/40.exp: -------------------------------------------------------------------------------- 1 | hello 2 | ch: 104 'h' 3 | ch: 101 'e' 4 | ch: 108 'l' 5 | ch: 108 'l' 6 | ch: 111 'o' 7 | ch: 10 '.' 8 | ch: 104 'h' 9 | ch: 101 'e' 10 | ch: 108 'l' 11 | ch: 108 'l' 12 | ch: 111 'o' 13 | ch: 10 '.' 14 | ch: 104 'h' 15 | ch: 101 'e' 16 | ch: 108 'l' 17 | ch: 108 'l' 18 | ch: 111 'o' 19 | ch: 10 '.' 20 | ch: 104 'h' 21 | ch: 101 'e' 22 | ch: 108 'l' 23 | ch: 108 'l' 24 | ch: 111 'o' 25 | ch: 10 '.' 26 | x: hello 27 | x: hello 28 | -------------------------------------------------------------------------------- /v0100/tests/picoc/48.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | char b; 7 | 8 | a = 0; 9 | while (a < 2) 10 | { 11 | printf("%d", a++); 12 | break; 13 | 14 | b = 'A'; 15 | while (b < 'C') 16 | { 17 | printf("%c", b++); 18 | } 19 | printf("e"); 20 | } 21 | printf("\n"); 22 | 23 | return 0; 24 | } 25 | 26 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 27 | -------------------------------------------------------------------------------- /v0100/bindp/readme.txt: -------------------------------------------------------------------------------- 1 | Precompiled Smaller C binaries for DOS with 32-bit DPMI. 2 | These can be used for cross-compiling for Windows, Linux and MacOS as well. 3 | 4 | System requirements: 5 | - DOS: MS-DOS 3.0 or better, i80386 CPU & i80387 FPU or better 6 | (you may also need CWSDPMI.EXE 1.5 or better) 7 | - Windows: Windows XP or 32-bit Windows Vista/7 (others not tested) 8 | - Emulation: DOSBox 0.74 or better (you may also need CWSDPMI.EXE 1.5 or better) 9 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getstime.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "GetSystemTime" 9 | #include "../dimports.h" 10 | 11 | struct _SYSTEMTIME; 12 | 13 | void __GetSystemTime(struct _SYSTEMTIME* pSystemTime) 14 | { 15 | asm( 16 | "push dword [ebp+8]\n" 17 | "call dword [__imp__GetSystemTime]" 18 | ); 19 | } 20 | 21 | #endif // _WINDOWS 22 | -------------------------------------------------------------------------------- /v0100/tests/picoc/49.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct point 4 | { 5 | double x; 6 | double y; 7 | }; 8 | 9 | struct point point_array[100]; 10 | 11 | int main() 12 | { 13 | int my_point = 10; 14 | 15 | point_array[my_point].x = 12.34; 16 | point_array[my_point].y = 56.78; 17 | 18 | printf("%g, %g\n", point_array[my_point].x, point_array[my_point].y); 19 | 20 | return 0; 21 | } 22 | 23 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 24 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/movefile.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "MoveFileA" 9 | #include "../dimports.h" 10 | 11 | int __MoveFileA(char* lpExistingFileName, char* lpNewFileName) 12 | { 13 | asm( 14 | "push dword [ebp+12]\n" 15 | "push dword [ebp+8]\n" 16 | "call dword [__imp__MoveFileA]" 17 | ); 18 | } 19 | 20 | #endif // _WINDOWS 21 | -------------------------------------------------------------------------------- /v0100/srclib/vsprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int vsprintf(char* s, char* fmt, va_list vl) 8 | { 9 | int res; 10 | FILE f; 11 | f.flags = _IOWR | _IOSTRING | _IOBINARY; // don't do file I/O, don't translate "\n" to "\r\n" 12 | f.ptr = f.buf = s; 13 | f.cnt = f.bufsz = (unsigned)-1 / 2 - 1; 14 | res = __doprint(&f, fmt, vl); 15 | *f.ptr = '\0'; 16 | return res; 17 | } 18 | -------------------------------------------------------------------------------- /v0100/tests/picoc/07.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int myfunc(int x) 4 | { 5 | return x * x; 6 | } 7 | 8 | void vfunc(int a) 9 | { 10 | printf("a=%d\n", a); 11 | } 12 | 13 | void qfunc() 14 | { 15 | printf("qfunc()\n"); 16 | } 17 | 18 | int main() 19 | { 20 | printf("%d\n", myfunc(3)); 21 | printf("%d\n", myfunc(4)); 22 | 23 | vfunc(1234); 24 | 25 | qfunc(); 26 | 27 | return 0; 28 | } 29 | 30 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 31 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getproca.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "GetProcAddress" 9 | #include "../dimports.h" 10 | 11 | void (*__GetProcAddress(void* hModule, char* lpProcName))() 12 | { 13 | asm( 14 | "push dword [ebp+12]\n" 15 | "push dword [ebp+8]\n" 16 | "call dword [__imp__GetProcAddress]" 17 | ); 18 | } 19 | 20 | #endif // _WINDOWS 21 | -------------------------------------------------------------------------------- /v0100/srclib/strlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | unsigned strlen(char* str) 6 | { 7 | #ifdef __SMALLER_C_16__ 8 | asm("mov di, [bp+4]\n" 9 | "mov cx, -1\n" 10 | "xor al, al\n" 11 | "cld\n" 12 | "repnz scasb\n" 13 | "mov ax, cx\n" 14 | "not ax\n" 15 | "dec ax"); 16 | #else 17 | char* s = str; 18 | 19 | while (*s) 20 | s++; 21 | 22 | return s - str; 23 | #endif 24 | } 25 | -------------------------------------------------------------------------------- /v0100/tests/picoc/02.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("Hello world\n"); 6 | 7 | int Count; 8 | for (Count = -5; Count <= 5; Count++) 9 | printf("Count = %d\n", Count); 10 | 11 | printf("String 'hello', 'there' is '%s', '%s'\n", "hello", "there"); 12 | printf("Character 'A' is '%c'\n", 65); 13 | printf("Character 'a' is '%c'\n", 'a'); 14 | 15 | return 0; 16 | } 17 | 18 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 19 | -------------------------------------------------------------------------------- /v0100/tests/picoc/20.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int b; 7 | int *d; 8 | int *e; 9 | d = &a; 10 | e = &b; 11 | a = 12; 12 | b = 34; 13 | printf("%d\n", *d); 14 | printf("%d\n", *e); 15 | printf("%d\n", d == e); 16 | printf("%d\n", d != e); 17 | d = e; 18 | printf("%d\n", d == e); 19 | printf("%d\n", d != e); 20 | 21 | return 0; 22 | } 23 | 24 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 25 | -------------------------------------------------------------------------------- /v0100/srclib/lngts.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __SMALLER_C_16__ 6 | int __lngToSigned(unsigned short l[2]) 7 | { 8 | return (short)l[0]; 9 | } 10 | #endif 11 | 12 | #ifdef __SMALLER_C_32__ 13 | int __lngToSigned(unsigned short l[2]) 14 | { 15 | union 16 | { 17 | unsigned short halves[2]; 18 | int n; 19 | } u; 20 | u.halves[0] = l[0]; 21 | u.halves[1] = l[1]; 22 | return u.n; 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /v0100/include/ctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __CTYPE_H 6 | #define __CTYPE_H 7 | 8 | int isalnum(int); 9 | int isalpha(int); 10 | int isblank(int); 11 | int iscntrl(int); 12 | int isdigit(int); 13 | int isgraph(int); 14 | int islower(int); 15 | int isprint(int); 16 | int ispunct(int); 17 | int isspace(int); 18 | int isupper(int); 19 | int isxdigit(int); 20 | int tolower(int); 21 | int toupper(int); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getexitc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "GetExitCodeProcess" 9 | #include "../dimports.h" 10 | 11 | int __GetExitCodeProcess(unsigned hProcess, unsigned* lpExitCode) 12 | { 13 | asm( 14 | "push dword [ebp+12]\n" 15 | "push dword [ebp+8]\n" 16 | "call dword [__imp__GetExitCodeProcess]" 17 | ); 18 | } 19 | 20 | #endif // _WINDOWS 21 | -------------------------------------------------------------------------------- /v0100/srclib/lngtu.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __SMALLER_C_16__ 6 | unsigned __lngToUnsigned(unsigned short l[2]) 7 | { 8 | return l[0]; 9 | } 10 | #endif 11 | 12 | #ifdef __SMALLER_C_32__ 13 | unsigned __lngToUnsigned(unsigned short l[2]) 14 | { 15 | union 16 | { 17 | unsigned short halves[2]; 18 | unsigned n; 19 | } u; 20 | u.halves[0] = l[0]; 21 | u.halves[1] = l[1]; 22 | return u.n; 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /v0100/srclib/sprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int sprintf(char* s, char* fmt, ...) 8 | { 9 | int res; 10 | FILE f; 11 | f.flags = _IOWR | _IOSTRING | _IOBINARY; // don't do file I/O, don't translate "\n" to "\r\n" 12 | f.ptr = f.buf = s; 13 | f.cnt = f.bufsz = (unsigned)-1 / 2 - 1; 14 | res = __doprint(&f, fmt, (char*)&fmt + sizeof(char*)); 15 | *f.ptr = '\0'; 16 | return res; 17 | } 18 | -------------------------------------------------------------------------------- /v0100/srclib/atexit.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | extern void (*__pAtExitIterator)(void); 6 | 7 | static void (*functions[32])(void); 8 | static int fcnt; 9 | 10 | static 11 | void iterator(void) 12 | { 13 | while (fcnt) 14 | functions[--fcnt](); 15 | } 16 | 17 | int atexit(void (*func)(void)) 18 | { 19 | if (fcnt >= 32) 20 | return -1; 21 | functions[fcnt++] = func; 22 | __pAtExitIterator = &iterator; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/wait4sob.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "WaitForSingleObject" 9 | #include "../dimports.h" 10 | 11 | unsigned __WaitForSingleObject(unsigned hHandle, unsigned dwMilliseconds) 12 | { 13 | asm( 14 | "push dword [ebp+12]\n" 15 | "push dword [ebp+8]\n" 16 | "call dword [__imp__WaitForSingleObject]" 17 | ); 18 | } 19 | 20 | #endif // _WINDOWS 21 | -------------------------------------------------------------------------------- /v0100/tests/picoc/34.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int a[4]; 7 | 8 | a[0] = 12; 9 | a[1] = 23; 10 | a[2] = 34; 11 | a[3] = 45; 12 | 13 | printf("%d %d %d %d\n", a[0], a[1], a[2], a[3]); 14 | 15 | int b[4]; 16 | 17 | // b = a; // non-standard!!! 18 | memcpy(b, a, sizeof b); 19 | 20 | printf("%d %d %d %d\n", b[0], b[1], b[2], b[3]); 21 | 22 | return 0; 23 | } 24 | 25 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 26 | -------------------------------------------------------------------------------- /v0100/srclib/strstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | char* strstr(char* s, char* substr) 6 | { 7 | if (*substr == '\0') 8 | return s; 9 | 10 | for (;; s++) 11 | { 12 | char *p1 = s, *p2 = substr; 13 | while (*p1 == *p2) 14 | { 15 | if (*p2 == '\0') 16 | return s; 17 | p1++; 18 | p2++; 19 | } 20 | if (*p2 == '\0') 21 | return s; 22 | if (*p1 == '\0') 23 | return 0; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /v0100/srclib/lngfs.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __SMALLER_C_16__ 6 | void __lngFromSigned(unsigned short l[2], int n) 7 | { 8 | l[0] = n; 9 | l[1] = -(n < 0); 10 | } 11 | #endif 12 | 13 | #ifdef __SMALLER_C_32__ 14 | void __lngFromSigned(unsigned short l[2], int n) 15 | { 16 | union 17 | { 18 | unsigned short halves[2]; 19 | int n; 20 | } u; 21 | u.n = n; 22 | l[0] = u.halves[0]; 23 | l[1] = u.halves[1]; 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /v0100/tests/picoc/17.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | enum fred 4 | { 5 | a, 6 | b, 7 | c, 8 | d, 9 | e = 54, 10 | f = 73, 11 | g, 12 | h 13 | }; 14 | 15 | int main() 16 | { 17 | enum fred frod; 18 | 19 | printf("%d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h); 20 | /* printf("%d\n", frod); */ 21 | frod = 12; 22 | printf("%d\n", frod); 23 | frod = e; 24 | printf("%d\n", frod); 25 | 26 | return 0; 27 | } 28 | 29 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 30 | -------------------------------------------------------------------------------- /v0100/tests/picoc/19.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int *b; 7 | int *c; 8 | 9 | a = 42; 10 | b = &a; 11 | c = NULL; 12 | 13 | printf("%d\n", *b); 14 | 15 | if (b == NULL) 16 | printf("b is NULL\n"); 17 | else 18 | printf("b is not NULL\n"); 19 | 20 | if (c == NULL) 21 | printf("c is NULL\n"); 22 | else 23 | printf("c is not NULL\n"); 24 | 25 | return 0; 26 | } 27 | 28 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 29 | -------------------------------------------------------------------------------- /v0100/srclib/memset.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | void* memset(void* s, int c, unsigned n) 6 | { 7 | #ifdef __SMALLER_C_16__ 8 | asm("mov di, [bp+4]\n" 9 | "mov al, [bp+6]\n" 10 | "mov ah, al\n" 11 | "mov cx, [bp+8]\n" 12 | "shr cx, 1\n" 13 | "cld\n" 14 | "rep stosw\n" 15 | "rcl cx, 1\n" 16 | "rep stosb"); 17 | #else 18 | char* p = s; 19 | 20 | while (n--) 21 | *p++ = c; 22 | #endif 23 | return s; 24 | } 25 | -------------------------------------------------------------------------------- /v0100/srclib/strcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | char* strcpy(char* dst, char* src) 6 | { 7 | #ifdef __SMALLER_C_16__ 8 | asm("mov di, [bp+6]\n" 9 | "mov si, di\n" 10 | "mov cx, -1\n" 11 | "xor al, al\n" 12 | "cld\n" 13 | "repnz scasb\n" 14 | "not cx\n" 15 | "mov di, [bp+4]\n" 16 | "rep movsb"); 17 | #else 18 | char* p = dst; 19 | 20 | while ((*p++ = *src++) != 0); 21 | #endif 22 | 23 | return dst; 24 | } 25 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/loadlibx.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "LoadLibraryExA" 9 | #include "../dimports.h" 10 | 11 | void* __LoadLibraryExA(char* lpFileName, unsigned hFile, unsigned dwFlags) 12 | { 13 | asm( 14 | "push dword [ebp+16]\n" 15 | "push dword [ebp+12]\n" 16 | "push dword [ebp+8]\n" 17 | "call dword [__imp__LoadLibraryExA]" 18 | ); 19 | } 20 | 21 | #endif // _WINDOWS 22 | -------------------------------------------------------------------------------- /v0100/srclib/lngfu.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __SMALLER_C_16__ 6 | void __lngFromUnsigned(unsigned short l[2], unsigned n) 7 | { 8 | l[0] = n; 9 | l[1] = 0; 10 | } 11 | #endif 12 | 13 | #ifdef __SMALLER_C_32__ 14 | void __lngFromUnsigned(unsigned short l[2], unsigned n) 15 | { 16 | union 17 | { 18 | unsigned short halves[2]; 19 | unsigned n; 20 | } u; 21 | u.n = n; 22 | l[0] = u.halves[0]; 23 | l[1] = u.halves[1]; 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /v0100/srclib/memcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | void* memcpy(void* dst, void* src, unsigned n) 6 | { 7 | #ifdef __SMALLER_C_16__ 8 | asm("mov di, [bp+4]\n" 9 | "mov si, [bp+6]\n" 10 | "mov cx, [bp+8]\n" 11 | "shr cx, 1\n" 12 | "cld\n" 13 | "rep movsw\n" 14 | "rcl cx, 1\n" 15 | "rep movsb"); 16 | #else 17 | char* p1 = dst; 18 | char* p2 = src; 19 | 20 | while (n--) 21 | *p1++ = *p2++; 22 | #endif 23 | return dst; 24 | } 25 | -------------------------------------------------------------------------------- /v0100/include/signal.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __SIGNAL_H 6 | #define __SIGNAL_H 7 | 8 | typedef int sig_atomic_t; 9 | 10 | #define SIG_DFL ((void(*)(int))0) 11 | #define SIG_ERR ((void(*)(int))-1) 12 | #define SIG_IGN ((void(*)(int))1) 13 | 14 | #define SIGINT 2 15 | #define SIGILL 4 16 | #define SIGABRT 6 17 | #define SIGFPE 8 18 | #define SIGSEGV 11 19 | #define SIGTERM 15 20 | 21 | void (*signal(int, void (*)(int)))(int); 22 | int raise(int); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /v0100/include/stdarg.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __STDARG_H 6 | #define __STDARG_H 7 | 8 | typedef char* va_list; 9 | 10 | #ifdef __SMALLER_PP__ 11 | #define va_start(vl, last) { (vl) = (char*)&(last) + ((sizeof(last) + sizeof(int) - 1) & -sizeof(int)); } 12 | #define va_arg(vl, type) (*(type*)(((vl) += ((sizeof(type) + sizeof(int) - 1) & -sizeof(int))) - ((sizeof(type) + sizeof(int) - 1) & -sizeof(int)))) 13 | #define va_end(vl) 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/heapfree.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "HeapFree" 9 | #include "../dimports.h" 10 | 11 | int __HeapFree(unsigned hHeap, 12 | unsigned dwFlags, 13 | void* lpMem) 14 | { 15 | asm( 16 | "push dword [ebp+16]\n" 17 | "push dword [ebp+12]\n" 18 | "push dword [ebp+8]\n" 19 | "call dword [__imp__HeapFree]" 20 | ); 21 | } 22 | 23 | #endif // _WINDOWS 24 | -------------------------------------------------------------------------------- /v0100/srclib/vsnprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int vsnprintf(char* s, size_t n, char* fmt, va_list vl) 8 | { 9 | int res; 10 | FILE f; 11 | // TBD??? overflow check for n > INT_MAX??? 12 | f.flags = _IOWR | _IOSTRING | _IOBINARY; // don't do file I/O, don't translate "\n" to "\r\n" 13 | f.ptr = f.buf = s; 14 | f.cnt = f.bufsz = n ? n - 1 : 0; 15 | res = __doprint(&f, fmt, vl); 16 | if (n) 17 | *f.ptr = '\0'; 18 | return res; 19 | } 20 | -------------------------------------------------------------------------------- /v0100/tests/picoc/36.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | 7 | int Array[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753 }; 8 | 9 | for (Count = 0; Count < 10; Count++) 10 | printf("%d: %d\n", Count, Array[Count]); 11 | 12 | int Array2[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753, }; 13 | 14 | for (Count = 0; Count < 10; Count++) 15 | printf("%d: %d\n", Count, Array2[Count]); 16 | 17 | 18 | return 0; 19 | } 20 | 21 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 22 | -------------------------------------------------------------------------------- /v0100/srclib/lngsl.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | int __lngSignedLess(unsigned short a[2], unsigned short b[2]) 6 | { 7 | if (a[1] > (unsigned short)-1/2) // a < 0 8 | { 9 | if (b[1] <= (unsigned short)-1/2) // b >= 0 10 | return 1; 11 | } 12 | else // a >= 0 13 | { 14 | if (b[1] > (unsigned short)-1/2) // b < 0 15 | return 0; 16 | } 17 | // (a < 0 && b < 0) || (a >= 0 && b >= 0) 18 | return (a[1] < b[1]) || 19 | ((a[1] == b[1]) && (*a < *b)); 20 | } 21 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/heapallo.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "HeapAlloc" 9 | #include "../dimports.h" 10 | 11 | void* __HeapAlloc(unsigned hHeap, 12 | unsigned dwFlags, 13 | unsigned dwBytes) 14 | { 15 | asm( 16 | "push dword [ebp+16]\n" 17 | "push dword [ebp+12]\n" 18 | "push dword [ebp+8]\n" 19 | "call dword [__imp__HeapAlloc]" 20 | ); 21 | } 22 | 23 | #endif // _WINDOWS 24 | -------------------------------------------------------------------------------- /v0100/tests/picoc/51.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int fred = 1234; 4 | static int joe; 5 | 6 | void henry() 7 | { 8 | static int fred = 4567; 9 | 10 | printf("%d\n", fred); 11 | fred++; 12 | } 13 | 14 | int main() 15 | { 16 | printf("%d\n", fred); 17 | henry(); 18 | henry(); 19 | henry(); 20 | henry(); 21 | printf("%d\n", fred); 22 | fred = 8901; 23 | joe = 2345; 24 | printf("%d\n", fred); 25 | printf("%d\n", joe); 26 | 27 | return 0; 28 | } 29 | 30 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 31 | -------------------------------------------------------------------------------- /v0100/srclib/round.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | 10 | float roundf(float x) 11 | { 12 | if (x >= 0) 13 | { 14 | float i = floorf(x); 15 | if (x - i >= .5f) 16 | i = i + 1; 17 | return i; 18 | } 19 | else 20 | { 21 | float i = floorf(-x); 22 | if (x + i <= -.5f) 23 | i = i + 1; 24 | return -i; 25 | } 26 | } 27 | 28 | double round(double x) 29 | { 30 | return roundf(x); 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /v0100/srclib/snprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int snprintf(char* s, size_t n, char* fmt, ...) 8 | { 9 | int res; 10 | FILE f; 11 | // TBD??? overflow check for n > INT_MAX??? 12 | f.flags = _IOWR | _IOSTRING | _IOBINARY; // don't do file I/O, don't translate "\n" to "\r\n" 13 | f.ptr = f.buf = s; 14 | f.cnt = f.bufsz = n ? n - 1 : 0; 15 | res = __doprint(&f, fmt, (char*)&fmt + sizeof(char*)); 16 | if (n) 17 | *f.ptr = '\0'; 18 | return res; 19 | } 20 | -------------------------------------------------------------------------------- /v0100/tests/picoc/52.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | enum fred { a, b, c }; 4 | 5 | int main() 6 | { 7 | printf("a=%d\n", a); 8 | printf("b=%d\n", b); 9 | printf("c=%d\n", c); 10 | 11 | enum fred d; 12 | 13 | typedef enum { e, f, g } h; 14 | typedef enum { i, j, k } m; 15 | 16 | printf("e=%d\n", e); 17 | printf("f=%d\n", f); 18 | printf("g=%d\n", g); 19 | 20 | printf("i=%d\n", i); 21 | printf("j=%d\n", j); 22 | printf("k=%d\n", k); 23 | 24 | return 0; 25 | } 26 | 27 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 28 | -------------------------------------------------------------------------------- /v0100/srclib/time1.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | unsigned short __DaysSinceJan1st[2][13] = 6 | { 7 | {0,31,59,90,120,151,181,212,243,273,304,334,365}, // 365 days, nonleap 8 | {0,31,60,91,121,152,182,213,244,274,305,335,366} // 366 days, leap 9 | }; 10 | 11 | int __isleap(unsigned year) 12 | { 13 | if (year & 3) 14 | return 0; 15 | 16 | year %= 400; 17 | 18 | if (!(year -= 100)) return 0; 19 | if (!(year -= 100)) return 0; 20 | if (!(year -= 100)) return 0; 21 | 22 | return 1; 23 | } 24 | -------------------------------------------------------------------------------- /v0100/srclib/strerror.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | char* strerror(int errnum) 8 | { 9 | char sn[1/*sign*/+10/*magnitude*/+1/*\0*/], *p = sn + sizeof sn; 10 | static char s[64]; 11 | unsigned e = (errnum < 0) ? -(unsigned)errnum : errnum; 12 | 13 | *--p = '\0'; 14 | do 15 | { 16 | *--p = '0' + e % 10; 17 | e /= 10; 18 | } while (e); 19 | if (errnum < 0) 20 | *--p = '-'; 21 | 22 | strcpy(s, "Unknown error "); 23 | strcat(s, p); 24 | 25 | return s; 26 | } 27 | -------------------------------------------------------------------------------- /v0100/tests/picoc/06.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | 7 | for (Count = 0; Count < 4; Count++) 8 | { 9 | printf("%d\n", Count); 10 | switch (Count) 11 | { 12 | case 1: 13 | printf("%d\n", 1); 14 | break; 15 | 16 | case 2: 17 | printf("%d\n", 2); 18 | break; 19 | 20 | default: 21 | printf("%d\n", 0); 22 | break; 23 | } 24 | } 25 | 26 | return 0; 27 | } 28 | 29 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 30 | -------------------------------------------------------------------------------- /v0100/tests/picoc/39.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef int MyInt; 4 | 5 | struct FunStruct 6 | { 7 | int i; 8 | int j; 9 | }; 10 | 11 | typedef struct FunStruct MyFunStruct; 12 | 13 | typedef MyFunStruct *MoreFunThanEver; 14 | 15 | int main() 16 | { 17 | MyInt a = 1; 18 | printf("%d\n", a); 19 | 20 | MyFunStruct b; 21 | b.i = 12; 22 | b.j = 34; 23 | printf("%d,%d\n", b.i, b.j); 24 | 25 | MoreFunThanEver c = &b; 26 | printf("%d,%d\n", c->i, c->j); 27 | 28 | return 0; 29 | } 30 | 31 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 32 | -------------------------------------------------------------------------------- /v0100/srclib/fabs.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #ifdef __HUGE__ 9 | #define __HUGE_OR_UNREAL__ 10 | #endif 11 | #ifdef __UNREAL__ 12 | #define __HUGE_OR_UNREAL__ 13 | #endif 14 | 15 | #ifdef __HUGE_OR_UNREAL__ 16 | #define xbp "bp" 17 | #else 18 | #define xbp "ebp" 19 | #endif 20 | 21 | float fabsf(float x) 22 | { 23 | asm 24 | ( 25 | "mov eax, ["xbp"+8]\n" 26 | "and eax, 0x7fffffff" 27 | ); 28 | } 29 | 30 | double fabs(double x) 31 | { 32 | return fabsf(x); 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /v0100/srclib/open_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __HUGE__ 6 | #define __HUGE_OR_UNREAL__ 7 | #endif 8 | #ifdef __UNREAL__ 9 | #define __HUGE_OR_UNREAL__ 10 | #endif 11 | 12 | asm("extern ___open\n" 13 | "global _open"); 14 | 15 | #ifdef __HUGE_OR_UNREAL__ 16 | asm("section .text\n" 17 | "_open:\n" 18 | "db 0xEA\n" 19 | ".1:\n" 20 | "dd ___open\n" 21 | "section .relot\n" 22 | "dd _open.1"); 23 | #else 24 | asm("section .text\n" 25 | "_open:\n" 26 | "jmp ___open"); 27 | #endif 28 | -------------------------------------------------------------------------------- /v0100/srclib/read_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __HUGE__ 6 | #define __HUGE_OR_UNREAL__ 7 | #endif 8 | #ifdef __UNREAL__ 9 | #define __HUGE_OR_UNREAL__ 10 | #endif 11 | 12 | asm("extern ___read\n" 13 | "global _read"); 14 | 15 | #ifdef __HUGE_OR_UNREAL__ 16 | asm("section .text\n" 17 | "_read:\n" 18 | "db 0xEA\n" 19 | ".1:\n" 20 | "dd ___read\n" 21 | "section .relot\n" 22 | "dd _read.1"); 23 | #else 24 | asm("section .text\n" 25 | "_read:\n" 26 | "jmp ___read"); 27 | #endif 28 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/setunhef.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "SetUnhandledExceptionFilter" 9 | #include "../dimports.h" 10 | 11 | typedef struct TOP_LEVEL_EXCEPTION_FILTER TOP_LEVEL_EXCEPTION_FILTER; 12 | 13 | TOP_LEVEL_EXCEPTION_FILTER* __SetUnhandledExceptionFilter(TOP_LEVEL_EXCEPTION_FILTER* lpTopLevelExceptionFilter) 14 | { 15 | asm( 16 | "push dword [ebp+8]\n" 17 | "call dword [__imp__SetUnhandledExceptionFilter]" 18 | ); 19 | } 20 | 21 | #endif // _WINDOWS 22 | -------------------------------------------------------------------------------- /v0100/tests/picoc/38.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a[4][4]; 6 | int b = 0; 7 | int x; 8 | int y; 9 | 10 | for (x = 0; x < 4; x++) 11 | { 12 | for (y = 0; y < 4; y++) 13 | { 14 | b++; 15 | a[x][y] = b; 16 | } 17 | } 18 | 19 | for (x = 0; x < 4; x++) 20 | { 21 | printf("x=%d: ", x); 22 | for (y = 0; y < 4; y++) 23 | { 24 | printf("%d ", a[x][y]); 25 | } 26 | printf("\n"); 27 | } 28 | 29 | return 0; 30 | } 31 | 32 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 33 | -------------------------------------------------------------------------------- /v0100/srclib/close_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __HUGE__ 6 | #define __HUGE_OR_UNREAL__ 7 | #endif 8 | #ifdef __UNREAL__ 9 | #define __HUGE_OR_UNREAL__ 10 | #endif 11 | 12 | asm("extern ___close\n" 13 | "global _close"); 14 | 15 | #ifdef __HUGE_OR_UNREAL__ 16 | asm("section .text\n" 17 | "_close:\n" 18 | "db 0xEA\n" 19 | ".1:\n" 20 | "dd ___close\n" 21 | "section .relot\n" 22 | "dd _close.1"); 23 | #else 24 | asm("section .text\n" 25 | "_close:\n" 26 | "jmp ___close"); 27 | #endif 28 | -------------------------------------------------------------------------------- /v0100/srclib/creat_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __HUGE__ 6 | #define __HUGE_OR_UNREAL__ 7 | #endif 8 | #ifdef __UNREAL__ 9 | #define __HUGE_OR_UNREAL__ 10 | #endif 11 | 12 | asm("extern ___creat\n" 13 | "global _creat"); 14 | 15 | #ifdef __HUGE_OR_UNREAL__ 16 | asm("section .text\n" 17 | "_creat:\n" 18 | "db 0xEA\n" 19 | ".1:\n" 20 | "dd ___creat\n" 21 | "section .relot\n" 22 | "dd _creat.1"); 23 | #else 24 | asm("section .text\n" 25 | "_creat:\n" 26 | "jmp ___creat"); 27 | #endif 28 | -------------------------------------------------------------------------------- /v0100/srclib/itime.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __ITIME_H 6 | #define __ITIME_H 7 | 8 | #include 9 | 10 | #define SECONDS_PER_MINUTE 60 11 | #define SECONDS_PER_HOUR (60*SECONDS_PER_MINUTE) 12 | #define SECONDS_PER_DAY (24UL*SECONDS_PER_HOUR) 13 | #define SECONDS_PER_YEAR (365UL*SECONDS_PER_DAY) 14 | 15 | extern unsigned short __DaysSinceJan1st[2][13]; 16 | int __isleap(unsigned); 17 | 18 | #ifdef __SMALLER_C_32__ 19 | time_t __buildtime(struct tm*); 20 | struct tm* __breaktime(time_t*); 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /v0100/srclib/lseek_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __HUGE__ 6 | #define __HUGE_OR_UNREAL__ 7 | #endif 8 | #ifdef __UNREAL__ 9 | #define __HUGE_OR_UNREAL__ 10 | #endif 11 | 12 | asm("extern ___lseek\n" 13 | "global _lseek"); 14 | 15 | #ifdef __HUGE_OR_UNREAL__ 16 | asm("section .text\n" 17 | "_lseek:\n" 18 | "db 0xEA\n" 19 | ".1:\n" 20 | "dd ___lseek\n" 21 | "section .relot\n" 22 | "dd _lseek.1"); 23 | #else 24 | asm("section .text\n" 25 | "_lseek:\n" 26 | "jmp ___lseek"); 27 | #endif 28 | -------------------------------------------------------------------------------- /v0100/srclib/write_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __HUGE__ 6 | #define __HUGE_OR_UNREAL__ 7 | #endif 8 | #ifdef __UNREAL__ 9 | #define __HUGE_OR_UNREAL__ 10 | #endif 11 | 12 | asm("extern ___write\n" 13 | "global _write"); 14 | 15 | #ifdef __HUGE_OR_UNREAL__ 16 | asm("section .text\n" 17 | "_write:\n" 18 | "db 0xEA\n" 19 | ".1:\n" 20 | "dd ___write\n" 21 | "section .relot\n" 22 | "dd _write.1"); 23 | #else 24 | asm("section .text\n" 25 | "_write:\n" 26 | "jmp ___write"); 27 | #endif 28 | -------------------------------------------------------------------------------- /v0100/srclib/fileno_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __HUGE__ 6 | #define __HUGE_OR_UNREAL__ 7 | #endif 8 | #ifdef __UNREAL__ 9 | #define __HUGE_OR_UNREAL__ 10 | #endif 11 | 12 | asm("extern ___fileno\n" 13 | "global _fileno"); 14 | 15 | #ifdef __HUGE_OR_UNREAL__ 16 | asm("section .text\n" 17 | "_fileno:\n" 18 | "db 0xEA\n" 19 | ".1:\n" 20 | "dd ___fileno\n" 21 | "section .relot\n" 22 | "dd _fileno.1"); 23 | #else 24 | asm("section .text\n" 25 | "_fileno:\n" 26 | "jmp ___fileno"); 27 | #endif 28 | -------------------------------------------------------------------------------- /v0100/srclib/isatty_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __HUGE__ 6 | #define __HUGE_OR_UNREAL__ 7 | #endif 8 | #ifdef __UNREAL__ 9 | #define __HUGE_OR_UNREAL__ 10 | #endif 11 | 12 | asm("extern ___isatty\n" 13 | "global _isatty"); 14 | 15 | #ifdef __HUGE_OR_UNREAL__ 16 | asm("section .text\n" 17 | "_isatty:\n" 18 | "db 0xEA\n" 19 | ".1:\n" 20 | "dd ___isatty\n" 21 | "section .relot\n" 22 | "dd _isatty.1"); 23 | #else 24 | asm("section .text\n" 25 | "_isatty:\n" 26 | "jmp ___isatty"); 27 | #endif 28 | -------------------------------------------------------------------------------- /v0100/srclib/unlink_.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __HUGE__ 6 | #define __HUGE_OR_UNREAL__ 7 | #endif 8 | #ifdef __UNREAL__ 9 | #define __HUGE_OR_UNREAL__ 10 | #endif 11 | 12 | asm("extern ___unlink\n" 13 | "global _unlink"); 14 | 15 | #ifdef __HUGE_OR_UNREAL__ 16 | asm("section .text\n" 17 | "_unlink:\n" 18 | "db 0xEA\n" 19 | ".1:\n" 20 | "dd ___unlink\n" 21 | "section .relot\n" 22 | "dd _unlink.1"); 23 | #else 24 | asm("section .text\n" 25 | "_unlink:\n" 26 | "jmp ___unlink"); 27 | #endif 28 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/getenvir.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "GetEnvironmentVariableA" 9 | #include "../dimports.h" 10 | 11 | unsigned __GetEnvironmentVariableA(char* lpName, 12 | char* lpBuffer, 13 | unsigned nSize) 14 | { 15 | asm( 16 | "push dword [ebp+16]\n" 17 | "push dword [ebp+12]\n" 18 | "push dword [ebp+8]\n" 19 | "call dword [__imp__GetEnvironmentVariableA]" 20 | ); 21 | } 22 | 23 | #endif // _WINDOWS 24 | -------------------------------------------------------------------------------- /v0100/tests/picoc/21.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int x = 'a'; 6 | char y = x; 7 | 8 | char *a = "hello"; 9 | 10 | printf("%s\n", a); 11 | 12 | int c; 13 | c = *a; 14 | 15 | char *b; 16 | for (b = a; *b != 0; b++) 17 | printf("%c: %d\n", *b, *b); 18 | 19 | char destarray[10]; 20 | char *dest = &destarray[0]; 21 | char *src = a; 22 | 23 | while (*src != 0) 24 | *dest++ = *src++; 25 | 26 | *dest = 0; 27 | 28 | printf("copied string is %s\n", destarray); 29 | 30 | return 0; 31 | } 32 | 33 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 34 | -------------------------------------------------------------------------------- /v0100/srclib/bsearch.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | void* bsearch(void* key, void* base, unsigned ecount, unsigned esize, int (*fcmp)(void*, void*)) 6 | { 7 | while (ecount) 8 | { 9 | unsigned mid = ecount >> 1; 10 | char* p = (char*)base + mid * esize; 11 | int t = fcmp(key, p); 12 | 13 | if (!t) 14 | { 15 | return p; 16 | } 17 | else if (t < 0) 18 | { 19 | ecount = mid; 20 | } 21 | else // if (t > 0) 22 | { 23 | base = p + esize; 24 | ecount -= mid + 1; 25 | } 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /v0100/srclib/irq5isr.c: -------------------------------------------------------------------------------- 1 | #ifdef __UNREAL__ 2 | // Default IRQ5 ISR that causes the existing/old IRQ5 ISR to run. 3 | // It will be linked if there's no other implementation of __Irq5Isr() in the program. 4 | // 5 | // If a custom IRQ5 ISR is needed, define your own __Irq5Isr() in the program 6 | // and it will be linked instead of this default IRQ5 ISR. 7 | int __Irq5Isr(void) 8 | { 9 | // If we handle IRQ5 here: 10 | // 1. Do I/O. 11 | // 2. Send EOI to PIC. 12 | // 3. return 0. 13 | // If we don't handle IRQ5 here and want the existing/old IRQ5 ISR to run: 14 | // 1. return 1. 15 | return 1; 16 | } 17 | #endif 18 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/heapreal.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "HeapReAlloc" 9 | #include "../dimports.h" 10 | 11 | void* __HeapReAlloc(unsigned hHeap, 12 | unsigned dwFlags, 13 | void* lpMem, 14 | unsigned dwBytes) 15 | { 16 | asm( 17 | "push dword [ebp+20]\n" 18 | "push dword [ebp+16]\n" 19 | "push dword [ebp+12]\n" 20 | "push dword [ebp+8]\n" 21 | "call dword [__imp__HeapReAlloc]" 22 | ); 23 | } 24 | 25 | #endif // _WINDOWS 26 | -------------------------------------------------------------------------------- /v0100/srclib/fsetpos.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | #include 7 | 8 | #ifdef __SMALLER_C_32__ 9 | int fsetpos(FILE* f, fpos_t* pos) 10 | { 11 | union 12 | { 13 | fpos_t fpos; 14 | long lpos; 15 | } u; 16 | u.fpos = *pos; 17 | if (!fseek(f, u.lpos, SEEK_SET)) 18 | return 0; 19 | // errno = EUNKNOWN; 20 | return -1; 21 | } 22 | #endif 23 | 24 | #ifdef __SMALLER_C_16__ 25 | int fsetpos(FILE* f, fpos_t* pos) 26 | { 27 | if (!__fseek(f, pos, SEEK_SET)) 28 | return 0; 29 | // errno = EUNKNOWN; 30 | return -1; 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /v0100/tests/picoc/50.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fred() 4 | { 5 | printf("fred\n"); 6 | return 0; 7 | } 8 | 9 | int joe() 10 | { 11 | printf("joe\n"); 12 | return 1; 13 | } 14 | 15 | int main() 16 | { 17 | printf("%d\n", fred() && joe()); 18 | printf("%d\n", fred() || joe()); 19 | printf("%d\n", joe() && fred()); 20 | printf("%d\n", joe() || fred()); 21 | printf("%d\n", fred() && (1 + joe())); 22 | printf("%d\n", fred() || (0 + joe())); 23 | printf("%d\n", joe() && (0 + fred())); 24 | printf("%d\n", joe() || (1 + fred())); 25 | 26 | return 0; 27 | } 28 | 29 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 30 | -------------------------------------------------------------------------------- /v0100/tests/hw.c: -------------------------------------------------------------------------------- 1 | /* 2 | How to compile for DOS (all mode(l)s: tiny/.COM, small/.EXE, huge/.EXE, unreal/.EXE, 32-bit DPMI/.EXE): 3 | smlrcc -dost hw.c -o hwdt.com 4 | smlrcc -doss hw.c -o hwds.exe 5 | smlrcc -dosh hw.c -o hwdh.exe 6 | smlrcc -dosu hw.c -o hwdu.exe 7 | smlrcc -dosp hw.c -o hwdp.exe 8 | 9 | How to compile for Windows: 10 | smlrcc -win hw.c -o hww.exe 11 | 12 | How to compile for Linux: 13 | smlrcc -linux hw.c -o hwl 14 | 15 | How to compile for MacOS: 16 | smlrcc -macos hw.c -o hwm 17 | */ 18 | 19 | #include 20 | 21 | int main(void) 22 | { 23 | puts("Hello, World!"); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /v0100/tests/picoc/03.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct fred 4 | { 5 | int boris; 6 | int natasha; 7 | }; 8 | 9 | void main() 10 | { 11 | struct fred bloggs; 12 | 13 | bloggs.boris = 12; 14 | bloggs.natasha = 34; 15 | 16 | printf("%d\n", bloggs.boris); 17 | printf("%d\n", bloggs.natasha); 18 | 19 | struct fred jones[2]; 20 | jones[0].boris = 12; 21 | jones[0].natasha = 34; 22 | jones[1].boris = 56; 23 | jones[1].natasha = 78; 24 | 25 | printf("%d\n", jones[0].boris); 26 | printf("%d\n", jones[0].natasha); 27 | printf("%d\n", jones[1].boris); 28 | printf("%d\n", jones[1].natasha); 29 | 30 | return; 31 | } 32 | -------------------------------------------------------------------------------- /v0100/srclib/fgetpos.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | #include 7 | 8 | #ifdef __SMALLER_C_32__ 9 | int fgetpos(FILE* f, fpos_t* pos) 10 | { 11 | union 12 | { 13 | fpos_t fpos; 14 | long lpos; 15 | } u; 16 | if ((u.lpos = ftell(f)) != -1) 17 | { 18 | *pos = u.fpos; 19 | return 0; 20 | } 21 | // errno = EUNKNOWN; 22 | return -1; 23 | } 24 | #endif 25 | 26 | #ifdef __SMALLER_C_16__ 27 | int fgetpos(FILE* f, fpos_t* pos) 28 | { 29 | if (!__ftell(f, pos)) 30 | { 31 | return 0; 32 | } 33 | // errno = EUNKNOWN; 34 | return -1; 35 | } 36 | #endif 37 | -------------------------------------------------------------------------------- /v0100/srclib/localeco.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | #include 7 | 8 | static char empty[] = ""; 9 | 10 | static struct lconv lc = 11 | { 12 | ".", 13 | empty, 14 | empty, 15 | empty, 16 | empty, 17 | empty, 18 | empty, 19 | empty, 20 | empty, 21 | CHAR_MAX, 22 | CHAR_MAX, 23 | CHAR_MAX, 24 | CHAR_MAX, 25 | CHAR_MAX, 26 | CHAR_MAX, 27 | CHAR_MAX, 28 | empty, 29 | CHAR_MAX, 30 | CHAR_MAX, 31 | CHAR_MAX, 32 | CHAR_MAX, 33 | CHAR_MAX, 34 | CHAR_MAX, 35 | CHAR_MAX 36 | }; 37 | 38 | struct lconv* localeconv(void) 39 | { 40 | return &lc; 41 | } 42 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/setfilep.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "SetFilePointer" 9 | #include "../dimports.h" 10 | 11 | unsigned __SetFilePointer(unsigned hFile, 12 | int lDistanceToMove, 13 | int* lpDistanceToMoveHigh, 14 | unsigned dwMoveMethod) 15 | { 16 | asm( 17 | "push dword [ebp+20]\n" 18 | "push dword [ebp+16]\n" 19 | "push dword [ebp+12]\n" 20 | "push dword [ebp+8]\n" 21 | "call dword [__imp__SetFilePointer]" 22 | ); 23 | } 24 | 25 | #endif // _WINDOWS 26 | -------------------------------------------------------------------------------- /v0100/include/assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __ASSERT_H 6 | #define __ASSERT_H 7 | 8 | #ifdef assert 9 | #undef assert 10 | #endif 11 | 12 | #ifdef __SMALLER_PP__ 13 | 14 | #ifdef NDEBUG 15 | #define assert(expr) ((void)0) 16 | #else 17 | #define assert(expr) ((expr) ? (void)0 : __assert(__func__, __FILE__, __LINE__, #expr)(0)) 18 | #endif 19 | 20 | #else 21 | 22 | #ifdef NDEBUG 23 | #define assert (1)?(void)0:(void) 24 | #else 25 | #define assert __assert(__func__, __FILE__, __LINE__, (char*)0) 26 | #endif 27 | 28 | #endif 29 | 30 | void (*__assert(char*, char*, int, char*))(unsigned); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /v0100/srclib/rand.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef __SMALLER_C_32__ 6 | unsigned __Seed = 1; 7 | 8 | int rand(void) 9 | { 10 | __Seed = __Seed * 1103515245 + 12345; 11 | return (__Seed >> 16) & 0x7FFF; 12 | } 13 | #endif 14 | 15 | #ifdef __SMALLER_C_16__ 16 | unsigned short __Seed[2] = { 1 }; 17 | 18 | static void helper(unsigned short seed[2]) 19 | { 20 | asm("mov bx, [bp+4]"); 21 | asm("mov eax, [bx]"); 22 | asm("imul eax, eax, 1103515245"); 23 | asm("add eax, 12345"); 24 | asm("mov [bx], eax"); 25 | } 26 | 27 | int rand(void) 28 | { 29 | helper(__Seed); 30 | return __Seed[1] & 0x7FFF; 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /v0100/srclib/assert.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | #include 7 | 8 | static char *_fxn, *_file, *_expr; 9 | static int _line; 10 | 11 | static void helper(unsigned expr) 12 | { 13 | if (!expr) 14 | { 15 | fprintf(stderr, "Assertion \"%s\" failed!\nFunction: %s\nFile: %s, Line: %d\n", 16 | (_expr ? _expr : ""), _fxn, _file, _line); 17 | abort(); 18 | } 19 | } 20 | 21 | void (*__assert(char* function, char* file, int line, char* expression))(unsigned) 22 | { 23 | _fxn = function; 24 | _file = file; 25 | _expr = expression; 26 | _line = line; 27 | return &helper; 28 | } 29 | -------------------------------------------------------------------------------- /v0100/srclib/sinh.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | 10 | float sinhf(float x) 11 | { 12 | int neg; 13 | float e; 14 | if ((neg = x < 0) != 0) 15 | x = -x; 16 | if (x <= 80) 17 | { 18 | e = expm1f(x); 19 | e = (e + e / (e + 1)) * 0.5f; 20 | } 21 | else 22 | { 23 | // Special case for fabsf(x) > ~logf(FLT_MAX) to avoid 24 | // premature overflow of expf(x) to infinity 25 | e = exp2f(x * 1.44269504f/*log2(e)*/ - 1); 26 | } 27 | return neg ? -e : e; 28 | } 29 | 30 | double sinh(double x) 31 | { 32 | return sinhf(x); 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /v0100/srclib/idos.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __IDOS_H 6 | #define __IDOS_H 7 | #ifdef _DOS 8 | 9 | void __DosGetVect(int, unsigned short*); 10 | void __DosSetVect(int, unsigned short*); 11 | 12 | extern unsigned short __Int00DE[2]; 13 | //extern unsigned short __Int01DB[2]; 14 | //extern unsigned short __Int03BP[2]; 15 | extern unsigned short __Int04OF[2]; 16 | extern unsigned short __Int06UD[2]; 17 | 18 | #ifdef __SMALLER_C_16__ 19 | void __ExcIsr(void); 20 | void __CtrlCIsr(void); 21 | #endif 22 | #ifdef __HUGE__ 23 | void __interrupt __ExcIsr(void); 24 | void __interrupt __CtrlCIsr(void); 25 | #endif 26 | 27 | #endif 28 | #endif 29 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/readfile.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "ReadFile" 9 | #include "../dimports.h" 10 | 11 | int __ReadFile(unsigned Handle, 12 | void* Buffer, 13 | unsigned NumberOfBytesToRead, 14 | unsigned* NumberOfBytesRead, 15 | void* Overlapped) 16 | { 17 | asm( 18 | "push dword [ebp+24]\n" 19 | "push dword [ebp+20]\n" 20 | "push dword [ebp+16]\n" 21 | "push dword [ebp+12]\n" 22 | "push dword [ebp+8]\n" 23 | "call dword [__imp__ReadFile]" 24 | ); 25 | } 26 | 27 | #endif // _WINDOWS 28 | -------------------------------------------------------------------------------- /v0100/srclib/atan2.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #ifdef __HUGE__ 9 | #define __HUGE_OR_UNREAL__ 10 | #endif 11 | #ifdef __UNREAL__ 12 | #define __HUGE_OR_UNREAL__ 13 | #endif 14 | 15 | #ifdef __HUGE_OR_UNREAL__ 16 | #define xbp "bp" 17 | #else 18 | #define xbp "ebp" 19 | #endif 20 | 21 | float atan2f(float y, float x) 22 | { 23 | asm 24 | ( 25 | "fld dword ["xbp"+8]\n" 26 | "fld dword ["xbp"+12]\n" 27 | "fpatan\n" 28 | "fstp dword ["xbp"+8]\n" 29 | "mov eax, ["xbp"+8]" 30 | ); 31 | } 32 | 33 | double atan2(double y, double x) 34 | { 35 | return atan2f(y, x); 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /v0100/srclib/fgetc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2017, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | #ifdef _LINUX 8 | #define UNIX_LIKE 9 | #endif 10 | #ifdef _MACOS 11 | #define UNIX_LIKE 12 | #endif 13 | 14 | static int __fgetc(FILE* f) 15 | { 16 | if (f->cnt) 17 | { 18 | f->cnt--; 19 | return *f->ptr++; 20 | } 21 | return __fillbuf(f); 22 | } 23 | 24 | int fgetc(FILE* f) 25 | { 26 | #ifndef UNIX_LIKE 27 | int c = __fgetc(f); 28 | if (f->flags & _IOBINARY) 29 | return c; 30 | for (;;) 31 | { 32 | if (c != '\r') // drop '\r' 33 | return c; 34 | c = __fgetc(f); 35 | } 36 | #else 37 | return __fgetc(f); 38 | #endif 39 | } 40 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/writefil.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "WriteFile" 9 | #include "../dimports.h" 10 | 11 | int __WriteFile(unsigned Handle, 12 | void* Buffer, 13 | unsigned NumberOfBytesToWrite, 14 | unsigned* NumberOfBytesWritten, 15 | void* Overlapped) 16 | { 17 | asm( 18 | "push dword [ebp+24]\n" 19 | "push dword [ebp+20]\n" 20 | "push dword [ebp+16]\n" 21 | "push dword [ebp+12]\n" 22 | "push dword [ebp+8]\n" 23 | "call dword [__imp__WriteFile]" 24 | ); 25 | } 26 | 27 | #endif // _WINDOWS 28 | -------------------------------------------------------------------------------- /v0100/srclib/strcmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | int strcmp(char* s1, char* s2) 6 | { 7 | #ifdef __SMALLER_C_16__ 8 | asm("mov di, [bp+6]\n" 9 | "mov si, di\n" 10 | "mov cx, -1\n" 11 | "xor ax, ax\n" 12 | "mov bx, ax\n" 13 | "cld\n" 14 | "repnz scasb\n" 15 | "not cx"); 16 | asm("mov di, [bp+4]\n" 17 | "repe cmpsb\n" 18 | "mov al, [di-1]\n" 19 | "mov bl, [si-1]\n" 20 | "sub ax, bx"); 21 | #else 22 | while (*s1 == *s2) 23 | { 24 | if (!*s1) 25 | return 0; 26 | ++s1; 27 | ++s2; 28 | } 29 | 30 | return ((unsigned char)*s1) - ((unsigned char)*s2); 31 | #endif 32 | } 33 | -------------------------------------------------------------------------------- /v0100/srclib/ungetc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2017, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | int ungetc(int c, FILE* f) 8 | { 9 | if (c == EOF) 10 | return EOF; 11 | 12 | // It doesn't make much sense to support ungetc() before 13 | // at least one fgetc() is done. 14 | // TBD??? Support it nonetheless??? 15 | if (f->ptr == f->buf) 16 | return EOF; 17 | 18 | f->ptr--; 19 | f->cnt++; 20 | if (*f->ptr != (unsigned char)c) 21 | { 22 | // This check helps sscanf() not to write to string literals. 23 | *f->ptr = c; 24 | f->flags |= _IOUNGOT; // fseek() must undo changes by ungetc() 25 | } 26 | f->flags &= ~_IOEOF; 27 | return (unsigned char)c; 28 | } 29 | -------------------------------------------------------------------------------- /v0100/tests/subc/stdio.ok: -------------------------------------------------------------------------------- 1 | 0---|----1----|----2----|----3----|----4----|----5 2 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3 | BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB 4 | CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 5 | | DDDDDDDDDDDDDDDDDDDDDDDD| 6 | |EEEEEEEEEEEEEEEEEEEEEEEE | 7 | 12345678901234567890123456789012345678901234567890 8 | -12345 9 | -12345 | 10 | 00000000000000000000000000000000000000000000012345 11 | 0x7bcd 31693 075715 12 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13 | 0---|----1----|----2----|----3----|----4----|----5 14 | -------------------------------------------------------------------------------- /v0100/srclib/strchr.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | char* strchr(char* s, int c) 6 | { 7 | #ifdef __SMALLER_C_16__ 8 | asm("mov si, [bp+4]\n" 9 | "mov bl, [bp+6]\n" 10 | "xor ax, ax\n" 11 | "cld\n" 12 | "strchrlp:\n" 13 | "lodsb\n" 14 | "cmp al, bl\n" 15 | "je strchrmch\n" 16 | "or al, al\n" 17 | "jnz strchrlp\n" 18 | "jmp strchrend"); 19 | asm("strchrmch:\n" 20 | "lea ax, [si-1]\n" 21 | "strchrend:"); 22 | #else 23 | c = (char)c; 24 | 25 | while (*s) 26 | { 27 | if (*s == c) 28 | return s; 29 | ++s; 30 | } 31 | 32 | if (!c) 33 | return s; 34 | 35 | return 0; 36 | #endif 37 | } 38 | -------------------------------------------------------------------------------- /v0100/include/sys/lng.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __LNG_H 6 | #define __LNG_H 7 | void __lngFromUnsigned(unsigned short l[2], unsigned n); 8 | void __lngFromSigned(unsigned short l[2], int n); 9 | unsigned __lngToUnsigned(unsigned short l[2]); 10 | int __lngToSigned(unsigned short l[2]); 11 | void __lngAdd(unsigned short acc[2], unsigned short addend[2]); 12 | void __lngSub(unsigned short acc[2], unsigned short subtrahend[2]); 13 | int __lngEq(unsigned short a[2], unsigned short b[2]); 14 | int __lngUnsignedLess(unsigned short a[2], unsigned short b[2]); 15 | int __lngSignedLess(unsigned short a[2], unsigned short b[2]); 16 | int __lngLessThan0(unsigned short l[2]); 17 | #endif 18 | -------------------------------------------------------------------------------- /v0100/srclib/tanh.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | 10 | float tanhf(float x) 11 | { 12 | int neg; 13 | float e; 14 | if (x == 0) 15 | return x; // preserve sign of 0 16 | if ((neg = x < 0) != 0) 17 | x = -x; 18 | if (x >= 10) 19 | { 20 | // +/-INF handled here 21 | e = 1; 22 | } 23 | else if (x < 1) 24 | { 25 | e = expm1f(x * 2); 26 | e = e / (e + 2); 27 | } 28 | else 29 | { 30 | // NAN handled here 31 | e = expm1f(x * 2); 32 | e = 1 - 2 / (e + 2); 33 | } 34 | return neg ? -e : e; 35 | } 36 | 37 | double tanh(double x) 38 | { 39 | return tanhf(x); 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /v0100/srclib/atoi.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | 7 | int atoi(char* nptr) 8 | { 9 | unsigned n = 0; 10 | int neg = 0, c; 11 | 12 | while (isspace((unsigned char)*nptr)) 13 | nptr++; 14 | 15 | if (*nptr == '-') 16 | neg = 1, nptr++; 17 | else if (*nptr == '+') 18 | nptr++; 19 | 20 | while (isdigit(c = (unsigned char)*nptr)) 21 | { 22 | if (n > (unsigned)-1 / 10) 23 | return 0; 24 | n *= 10; 25 | c -= '0'; 26 | if (n > (unsigned)-1 - c) 27 | return 0; 28 | n += c; 29 | nptr++; 30 | } 31 | 32 | if (n > (unsigned)-1 / 2 + neg) 33 | return 0; 34 | 35 | if (neg) 36 | n = -n; 37 | 38 | return (int)n; 39 | } 40 | -------------------------------------------------------------------------------- /v0100/srclib/sqrt.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __HUGE__ 12 | #define __HUGE_OR_UNREAL__ 13 | #endif 14 | #ifdef __UNREAL__ 15 | #define __HUGE_OR_UNREAL__ 16 | #endif 17 | 18 | #ifdef __HUGE_OR_UNREAL__ 19 | #define xbp "bp" 20 | #else 21 | #define xbp "ebp" 22 | #endif 23 | 24 | float sqrtf(float x) 25 | { 26 | if (x < 0) 27 | { 28 | errno = EDOM; 29 | return NAN; 30 | } 31 | asm 32 | ( 33 | "fld dword ["xbp"+8]\n" 34 | "fsqrt\n" 35 | "fstp dword ["xbp"+8]\n" 36 | "mov eax, ["xbp"+8]" 37 | ); 38 | } 39 | 40 | double sqrt(double x) 41 | { 42 | return sqrtf(x); 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /v0100/srclib/strxfrm.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | unsigned strxfrm(char* s1, char* s2, unsigned n) 6 | { 7 | unsigned res = 0; 8 | 9 | while (n--) 10 | { 11 | if ((*s1++ = *s2++) == '\0') 12 | return res; 13 | res++; 14 | } 15 | 16 | // If we get here then it means that we've copied n bytes but '\0' is not among them. 17 | // It also means that the returned value will be greater or equal to the original value of 18 | // the parameter n. C99 says: "If the value returned is n or more, the contents of the 19 | // array pointed to by s1 are indeterminate." IOW, I'm not required to add a '\0' of my own. 20 | 21 | while (*s2++ != '\0') 22 | res++; 23 | 24 | return res; 25 | } 26 | -------------------------------------------------------------------------------- /v0100/srclib/asctime.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | #include 7 | 8 | char* asctime(struct tm* tm) 9 | { 10 | static char day[][3] = 11 | { 12 | "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" 13 | }; 14 | static char month[][3] = 15 | { 16 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", 17 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 18 | }; 19 | static char res[26]; 20 | 21 | sprintf(res, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n", 22 | day[tm->tm_wday], 23 | month[tm->tm_mon], 24 | tm->tm_mday, 25 | tm->tm_hour, 26 | tm->tm_min, 27 | tm->tm_sec, 28 | 1900 + tm->tm_year); 29 | 30 | return res; 31 | } 32 | -------------------------------------------------------------------------------- /v0100/srclib/dimports.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | // Before including this file define DLL and FXN, e.g.: 7 | // 8 | // #define DLL "kernel32" 9 | // #define FXN "ExitProcess" 10 | // #include "../dimports.h" 11 | 12 | asm( 13 | " section .dll_import2_" DLL " write align=4\n" 14 | " dd _hint_" FXN "\n" 15 | 16 | " section .dll_import3_" DLL " write align=2\n" 17 | " _hint_" FXN ":\n" 18 | " db 0, 0, \"" FXN "\", 0\n" 19 | " align 2, db 0\n" 20 | 21 | " section .dll_iat2_" DLL " write align=4\n" 22 | " global __imp__" FXN "\n" 23 | " __imp__" FXN ":\n" 24 | " dd _hint_" FXN "\n" 25 | 26 | " section .data\n" 27 | " extern __" DLL "_dll__\n" 28 | " dd __" DLL "_dll__\n" // pull DLL.c 29 | ); 30 | -------------------------------------------------------------------------------- /v0100/tests/bugs/ncompile/005.c: -------------------------------------------------------------------------------- 1 | void f(void) 2 | { 3 | } 4 | 5 | void (*pf1)(void) = &f; 6 | void (*pf2)(void) = f; 7 | void (*pf3)(void) = *f; // doesn't compile 8 | void (*pf4)(void) = **f; // doesn't compile 9 | 10 | void ff(void f(void), void (*pf)(void)) 11 | { 12 | f(); 13 | (f)(); 14 | (*f)(); 15 | pf(); 16 | (pf)(); 17 | (*pf)(); 18 | (**f)(); // doesn't compile 19 | (***f)(); // doesn't compile 20 | (**pf)(); // doesn't compile 21 | (***pf)(); // doesn't compile 22 | } 23 | 24 | int main(void) 25 | { 26 | f(); 27 | (f)(); 28 | (&f)(); 29 | pf1(); 30 | (pf1)(); 31 | (*pf1)(); 32 | (*f)(); // doesn't compile 33 | (**f)(); // doesn't compile 34 | (**pf1)(); // doesn't compile 35 | (***pf1)(); // doesn't compile 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /v0100/binw/readme.txt: -------------------------------------------------------------------------------- 1 | Precompiled Smaller C binaries for Windows. 2 | These can be used for cross-compiling for DOS, Linux and MacOS as well. 3 | 4 | System requirements: 5 | - Client OS: Windows XP or better 6 | - Server OS: Windows Server 2003 or better 7 | 8 | Run the following DOS/Windows commands to make Windows binaries out of 9 | the parts contained in this directory (anti-virus software may not let 10 | you download precompiled .EXE's if it mistakenly thinks they contain 11 | malware; unfortunately, false positives are pervasive): 12 | copy /b m.dat + z.dat + n2f.dat n2f.exe 13 | copy /b m.dat + z.dat + smlrc.dat smlrc.exe 14 | copy /b m.dat + z.dat + smlrcc.dat smlrcc.exe 15 | copy /b m.dat + z.dat + smlrl.dat smlrl.exe 16 | copy /b m.dat + z.dat + smlrpp.dat smlrpp.exe 17 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/st2tzslt.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "SystemTimeToTzSpecificLocalTime" 9 | #include "../dimports.h" 10 | 11 | struct _TIME_ZONE_INFORMATION; 12 | struct _SYSTEMTIME; 13 | 14 | int __SystemTimeToTzSpecificLocalTime(struct _TIME_ZONE_INFORMATION* lpTimeZoneInformation, 15 | struct _SYSTEMTIME* lpLocalTime, 16 | struct _SYSTEMTIME* lpUniversalTime) 17 | { 18 | asm( 19 | "push dword [ebp+16]\n" 20 | "push dword [ebp+12]\n" 21 | "push dword [ebp+8]\n" 22 | "call dword [__imp__SystemTimeToTzSpecificLocalTime]" 23 | ); 24 | } 25 | 26 | #endif // _WINDOWS 27 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/tzslt2st.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "TzSpecificLocalTimeToSystemTime" 9 | #include "../dimports.h" 10 | 11 | struct _TIME_ZONE_INFORMATION; 12 | struct _SYSTEMTIME; 13 | 14 | int __TzSpecificLocalTimeToSystemTime(struct _TIME_ZONE_INFORMATION* lpTimeZoneInformation, 15 | struct _SYSTEMTIME* lpLocalTime, 16 | struct _SYSTEMTIME* lpUniversalTime) 17 | { 18 | asm( 19 | "push dword [ebp+16]\n" 20 | "push dword [ebp+12]\n" 21 | "push dword [ebp+8]\n" 22 | "call dword [__imp__TzSpecificLocalTimeToSystemTime]" 23 | ); 24 | } 25 | 26 | #endif // _WINDOWS 27 | -------------------------------------------------------------------------------- /v0100/srclib/dpmi.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _DPMI 6 | #include "idpmi.h" 7 | 8 | unsigned long __dpmi_exit_addr; 9 | void* __dpmi_psp; 10 | void* __dpmi_env; 11 | void* __dpmi_stubInfo; 12 | void* __dpmi_iobuf; 13 | void* __dpmi_heap_start; 14 | void* __dpmi_heap_stop; 15 | 16 | void __dpmi_terminate(int status) 17 | { 18 | asm("mov eax, [ebp + 8]\n" 19 | "push dword [___dpmi_exit_addr]\n" 20 | "db 0x66\n" 21 | "retf"); 22 | } 23 | 24 | int __dpmi_int(int intno, __dpmi_int_regs* regs) 25 | { 26 | asm("mov edi, [ebp + 12]\n" 27 | "mov ax, 0x300\n" 28 | "xor ebx, ebx\n" 29 | "mov bl, [ebp + 8]\n" 30 | "xor ecx, ecx\n" 31 | "int 0x31\n" 32 | "sbb eax, eax"); 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /v0100/tests/picoc/24.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf("%f\n", sin(0.12)); 7 | printf("%f\n", cos(0.12)); 8 | printf("%f\n", tan(0.12)); 9 | printf("%f\n", asin(0.12)); 10 | printf("%f\n", acos(0.12)); 11 | printf("%f\n", atan(0.12)); 12 | printf("%f\n", sinh(0.12)); 13 | printf("%f\n", cosh(0.12)); 14 | printf("%f\n", tanh(0.12)); 15 | printf("%f\n", exp(0.12)); 16 | printf("%f\n", fabs(-0.12)); 17 | printf("%f\n", log(0.12)); 18 | printf("%f\n", log10(0.12)); 19 | printf("%f\n", pow(0.12, 0.12)); 20 | printf("%f\n", sqrt(0.12)); 21 | printf("%f\n", round(12.34)); 22 | printf("%f\n", ceil(12.34)); 23 | printf("%f\n", floor(12.34)); 24 | 25 | return 0; 26 | } 27 | 28 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 29 | -------------------------------------------------------------------------------- /v0100/srclib/strtok.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | char* __strtoklast; 6 | 7 | char* strtok(char* s, char* delims) 8 | { 9 | char* p; 10 | int c, c2; 11 | char* res; 12 | 13 | if (!s && !(s = __strtoklast)) 14 | return 0; 15 | 16 | lskip_delims: 17 | c = *s++; 18 | p = delims; 19 | while ((c2 = *p++) != '\0') 20 | if (c2 == c) 21 | goto lskip_delims; 22 | 23 | if (c == '\0') 24 | { 25 | __strtoklast = 0; 26 | return 0; 27 | } 28 | res = s - 1; 29 | 30 | while ((c = *s++) != '\0') 31 | { 32 | p = delims; 33 | while ((c2 = *p++) != '\0') 34 | if (c2 == c) 35 | { 36 | s[-1] = '\0'; 37 | __strtoklast = s; 38 | return res; 39 | } 40 | } 41 | 42 | __strtoklast = 0; 43 | return res; 44 | } 45 | -------------------------------------------------------------------------------- /v0100/include/sys/stat.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __SYS_STAT_H 6 | #define __SYS_STAT_H 7 | 8 | #define S_IRUSR 0400 9 | #define S_IRGRP 0040 10 | #define S_IROTH 0004 11 | #define S_IWUSR 0200 12 | #define S_IWGRP 0020 13 | #define S_IWOTH 0002 14 | #define S_IXUSR 0100 15 | #define S_IXGRP 0010 16 | #define S_IXOTH 0001 17 | #define S_IRWXU 0700 18 | #define S_IRWXG 0070 19 | #define S_IRWXO 0007 20 | 21 | #ifndef __MODE_T_DEF 22 | #define __MODE_T_DEF 23 | typedef int mode_t; 24 | #endif 25 | 26 | #ifdef __SMALLER_C_32__ 27 | #ifndef __OFF_T_DEF 28 | #define __OFF_T_DEF 29 | typedef long off_t; 30 | #endif 31 | #endif 32 | 33 | #ifdef __SMALLER_C_32__ 34 | #ifndef __TIME_T_DEF 35 | #define __TIME_T_DEF 36 | typedef unsigned long time_t; 37 | #endif 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /v0100/tests/picoc/10.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct ziggy 4 | { 5 | int a; 6 | int b; 7 | int c; 8 | } bolshevic; 9 | 10 | int main() 11 | { 12 | int a; 13 | int *b; 14 | int c; 15 | 16 | a = 42; 17 | b = &a; 18 | printf("a = %d\n", *b); 19 | 20 | bolshevic.a = 12; 21 | bolshevic.b = 34; 22 | bolshevic.c = 56; 23 | 24 | printf("bolshevic.a = %d\n", bolshevic.a); 25 | printf("bolshevic.b = %d\n", bolshevic.b); 26 | printf("bolshevic.c = %d\n", bolshevic.c); 27 | 28 | struct ziggy *tsar = &bolshevic; 29 | 30 | printf("tsar->a = %d\n", tsar->a); 31 | printf("tsar->b = %d\n", tsar->b); 32 | printf("tsar->c = %d\n", tsar->c); 33 | 34 | b = &(bolshevic.b); 35 | printf("bolshevic.b = %d\n", *b); 36 | 37 | return 0; 38 | } 39 | 40 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 41 | -------------------------------------------------------------------------------- /v0100/srclib/setvbuf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | #include "istdio.h" 7 | 8 | int setvbuf(FILE* f, char* buf, int mode, size_t size) 9 | { 10 | if (!f || f->buf) 11 | return -1; 12 | if (mode != _IONBF && mode != _IOLBF && mode != _IOFBF) 13 | return -1; 14 | 15 | if (mode != _IONBF) 16 | { 17 | if (!size || size >= (unsigned)-1/2) // the buffer should be indexable by signed int (__fseek() needs it) 18 | return -1; 19 | if (!buf) 20 | { 21 | if (!(buf = malloc(size))) 22 | return -1; 23 | } 24 | else 25 | { 26 | f->flags |= _IOEXTBUF; 27 | } 28 | f->ptr = f->buf = buf; 29 | f->bufsz = size; 30 | } 31 | 32 | f->flags &= ~(_IONBF | _IOLBF | _IOFBF); 33 | f->flags |= mode; 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /v0100/srclib/ifp.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __IFP_H 6 | #define __IFP_H 7 | 8 | #ifdef __SMALLER_C_32__ 9 | 10 | #define MAX_FP_DIGITS 112 11 | #define FP_MANT_BITS 23 // bits in mantissa, excluding the implicit 1 12 | #define FP_EXP_BITS 8 // bits in exponent 13 | #define FP_MIN_EXP (-46) // from min denormal, ~1.40e-45 14 | // (-46 is chosen because we need to handle numbers 15 | // like 9e-46 which round up to a non-zero denormal 16 | // number ~1.40e-45) 17 | #define FP_MAX_EXP 38 // from max normal, ~3.40e+38 18 | #define FP_BUF_SIZE (((((MAX_FP_DIGITS-FP_MIN_EXP)*10+2)/3+FP_MANT_BITS+2)+7)/8) 19 | 20 | unsigned __cvtfd(unsigned char* digits, int cnt, int eexp); 21 | 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /v0100/srclib/strncmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | int strncmp(char* s1, char* s2, unsigned n) 6 | { 7 | #ifdef __SMALLER_C_16__ 8 | asm("mov cx, [bp+8]\n" 9 | "xor ax, ax\n" 10 | "jcxz strncmpend\n" 11 | "mov bx, ax\n" 12 | "mov di, [bp+6]\n" 13 | "mov si, di\n" 14 | "cld\n" 15 | "repnz scasb\n" 16 | "sub cx, [bp+8]\n" 17 | "neg cx"); 18 | asm("mov di, [bp+4]\n" 19 | "repe cmpsb\n" 20 | "mov al, [di-1]\n" 21 | "mov bl, [si-1]\n" 22 | "sub ax, bx\n" 23 | "strncmpend:"); 24 | #else 25 | if (!n) 26 | return 0; 27 | 28 | do 29 | { 30 | if (*s1 != *s2++) 31 | return ((unsigned char)*s1) - ((unsigned char)*--s2); 32 | if (!*s1++) 33 | break; 34 | } while (--n); 35 | 36 | return 0; 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /v0100/srclib/ctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | unsigned char __chartype__[1 + 256] = 6 | { 7 | 0x00, // for EOF=-1 8 | 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x03,0x03,0x03,0x03,0x03,0x01,0x01, 9 | 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 10 | 0x02,0x04,0x04,0x04,0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04, 11 | 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08, 0x08,0x08,0x04,0x04,0x04,0x04,0x04,0x04, 12 | 0x04,0x50,0x50,0x50,0x50,0x50,0x50,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 13 | 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, 0x10,0x10,0x10,0x04,0x04,0x04,0x04,0x04, 14 | 0x04,0x60,0x60,0x60,0x60,0x60,0x60,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, 15 | 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, 0x20,0x20,0x20,0x04,0x04,0x04,0x04,0x01 16 | }; 17 | -------------------------------------------------------------------------------- /v0100/tests/sdl/dimports.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | // Before including this file define DLL and FXN, e.g.: 7 | // 8 | // #define DLL "sdl2" 9 | // #define FXN "SDL_Init" 10 | // #include "dimports.h" 11 | 12 | asm( 13 | " section .dll_import2_" DLL " write align=4\n" 14 | " dd _hint_" FXN "\n" 15 | 16 | " section .dll_import3_" DLL " write align=2\n" 17 | " _hint_" FXN ":\n" 18 | " db 0, 0, \"" FXN "\", 0\n" 19 | " align 2, db 0\n" 20 | 21 | " section .dll_iat2_" DLL " write align=4\n" 22 | " global _" FXN "\n" 23 | 24 | // Note that DLL importing gives us pointers to functions. 25 | // SDL2 is compiled using the cdecl calling convention (same as in Smaller C) 26 | // and so we can just use those pointers directly to call SDL functions. 27 | " _" FXN ":\n" 28 | " dd _hint_" FXN "\n" 29 | ); 30 | -------------------------------------------------------------------------------- /v0100/srclib/log2.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __HUGE__ 12 | #define __HUGE_OR_UNREAL__ 13 | #endif 14 | #ifdef __UNREAL__ 15 | #define __HUGE_OR_UNREAL__ 16 | #endif 17 | 18 | #ifdef __HUGE_OR_UNREAL__ 19 | #define xbp "bp" 20 | #else 21 | #define xbp "ebp" 22 | #endif 23 | 24 | float log2f(float x) 25 | { 26 | if (x <= 0) 27 | { 28 | if (x == 0) 29 | { 30 | errno = ERANGE; 31 | return -INFINITY; 32 | } 33 | errno = EDOM; 34 | return NAN; 35 | } 36 | asm 37 | ( 38 | "fld1\n" 39 | "fld dword ["xbp"+8]\n" 40 | "fyl2x\n" 41 | "fstp dword ["xbp"+8]\n" 42 | "mov eax, ["xbp"+8]" 43 | ); 44 | } 45 | 46 | double log2(double x) 47 | { 48 | return log2f(x); 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /v0100/srclib/log.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __HUGE__ 12 | #define __HUGE_OR_UNREAL__ 13 | #endif 14 | #ifdef __UNREAL__ 15 | #define __HUGE_OR_UNREAL__ 16 | #endif 17 | 18 | #ifdef __HUGE_OR_UNREAL__ 19 | #define xbp "bp" 20 | #else 21 | #define xbp "ebp" 22 | #endif 23 | 24 | float logf(float x) 25 | { 26 | if (x <= 0) 27 | { 28 | if (x == 0) 29 | { 30 | errno = ERANGE; 31 | return -INFINITY; 32 | } 33 | errno = EDOM; 34 | return NAN; 35 | } 36 | asm 37 | ( 38 | "fldln2\n" 39 | "fld dword ["xbp"+8]\n" 40 | "fyl2x\n" 41 | "fstp dword ["xbp"+8]\n" 42 | "mov eax, ["xbp"+8]" 43 | ); 44 | } 45 | 46 | double log(double x) 47 | { 48 | return logf(x); 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /v0100/srclib/log10.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __HUGE__ 12 | #define __HUGE_OR_UNREAL__ 13 | #endif 14 | #ifdef __UNREAL__ 15 | #define __HUGE_OR_UNREAL__ 16 | #endif 17 | 18 | #ifdef __HUGE_OR_UNREAL__ 19 | #define xbp "bp" 20 | #else 21 | #define xbp "ebp" 22 | #endif 23 | 24 | float log10f(float x) 25 | { 26 | if (x <= 0) 27 | { 28 | if (x == 0) 29 | { 30 | errno = ERANGE; 31 | return -INFINITY; 32 | } 33 | errno = EDOM; 34 | return NAN; 35 | } 36 | asm 37 | ( 38 | "fldlg2\n" 39 | "fld dword ["xbp"+8]\n" 40 | "fyl2x\n" 41 | "fstp dword ["xbp"+8]\n" 42 | "mov eax, ["xbp"+8]" 43 | ); 44 | } 45 | 46 | double log10(double x) 47 | { 48 | return log10f(x); 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /v0100/tests/picoc/54.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fred() 4 | { 5 | printf("In fred()\n"); 6 | goto done; 7 | printf("In middle\n"); 8 | done: 9 | printf("At end\n"); 10 | } 11 | 12 | void joe() 13 | { 14 | int b = 5678; 15 | 16 | printf("In joe()\n"); 17 | 18 | { 19 | int c = 1234; 20 | printf("c = %d\n", c); 21 | goto outer; 22 | printf("uh-oh\n"); 23 | } 24 | 25 | outer: 26 | 27 | printf("done\n"); 28 | } 29 | 30 | void henry() 31 | { 32 | int a; 33 | 34 | printf("In henry()\n"); 35 | goto inner; 36 | 37 | { 38 | int b; 39 | inner: 40 | b = 1234; 41 | printf("b = %d\n", b); 42 | } 43 | 44 | printf("done\n"); 45 | } 46 | 47 | int main() 48 | { 49 | fred(); 50 | joe(); 51 | henry(); 52 | 53 | return 0; 54 | } 55 | 56 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 57 | -------------------------------------------------------------------------------- /v0100/srclib/fputc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2017, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include "istdio.h" 6 | 7 | #ifdef _LINUX 8 | #define UNIX_LIKE 9 | #endif 10 | #ifdef _MACOS 11 | #define UNIX_LIKE 12 | #endif 13 | 14 | static int __fputc(int c, FILE* f) 15 | { 16 | int r; 17 | 18 | if (f->cnt) 19 | { 20 | f->cnt--; 21 | r = *f->ptr++ = c; 22 | } 23 | else 24 | { 25 | if ((r = __flushbuf(c, f)) == EOF) 26 | { 27 | return EOF; 28 | } 29 | } 30 | 31 | if ((f->flags & _IONBF) || ((f->flags & _IOLBF) && c == '\n')) 32 | { 33 | if (fflush(f)) 34 | { 35 | return EOF; 36 | } 37 | } 38 | 39 | return r; 40 | } 41 | 42 | int fputc(int c, FILE* f) 43 | { 44 | #ifndef UNIX_LIKE 45 | if (c == '\n' && !(f->flags & _IOBINARY)) 46 | __fputc('\r', f); // insert '\r' 47 | #endif 48 | return __fputc(c, f); 49 | } 50 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/createfi.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | #define DLL "kernel32" 8 | #define FXN "CreateFileA" 9 | #include "../dimports.h" 10 | 11 | unsigned __CreateFileA(char* FileName, 12 | unsigned DesiredAccess, 13 | unsigned ShareMode, 14 | void* SecurityAttributes, 15 | unsigned CreationDisposition, 16 | unsigned FlagsAndAttributes, 17 | unsigned TemplateFile) 18 | { 19 | asm( 20 | "push dword [ebp+32]\n" 21 | "push dword [ebp+28]\n" 22 | "push dword [ebp+24]\n" 23 | "push dword [ebp+20]\n" 24 | "push dword [ebp+16]\n" 25 | "push dword [ebp+12]\n" 26 | "push dword [ebp+8]\n" 27 | "call dword [__imp__CreateFileA]" 28 | ); 29 | } 30 | 31 | #endif // _WINDOWS 32 | -------------------------------------------------------------------------------- /v0100/srclib/memmove.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | void* memmove(void* dst, void* src, unsigned n) 6 | { 7 | #ifdef __SMALLER_C_16__ 8 | if (src < dst) 9 | { 10 | asm("mov di, [bp+4]\n" 11 | "mov si, [bp+6]\n" 12 | "mov cx, [bp+8]\n" 13 | "add di, cx\n" 14 | "dec di\n" 15 | "add si, cx\n" 16 | "dec si\n" 17 | "std\n" 18 | "rep movsb"); 19 | } 20 | else 21 | { 22 | asm("mov di, [bp+4]\n" 23 | "mov si, [bp+6]\n" 24 | "mov cx, [bp+8]\n" 25 | "cld\n" 26 | "rep movsb"); 27 | } 28 | #else 29 | char* d = dst; 30 | char* s = src; 31 | 32 | if (s < d) 33 | { 34 | s += n; 35 | d += n; 36 | while (n--) 37 | *--d = *--s; 38 | } 39 | else 40 | { 41 | while (n--) 42 | *d++ = *s++; 43 | } 44 | #endif 45 | return dst; 46 | } 47 | -------------------------------------------------------------------------------- /v0100/tests/picoc/11.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int b; 7 | int c; 8 | int d; 9 | int e; 10 | int f; 11 | int x; 12 | int y; 13 | 14 | a = 12; 15 | b = 34; 16 | c = 56; 17 | d = 78; 18 | e = 0; 19 | f = 1; 20 | 21 | printf("%d\n", c + d); 22 | printf("%d\n", (y = c + d)); 23 | printf("%d\n", e || e && f); 24 | printf("%d\n", e || f && f); 25 | printf("%d\n", e && e || f); 26 | printf("%d\n", e && f || f); 27 | printf("%d\n", a && f | f); 28 | printf("%d\n", a | b ^ c & d); 29 | printf("%d, %d\n", a == a, a == b); 30 | printf("%d, %d\n", a != a, a != b); 31 | printf("%d\n", a != b && c != d); 32 | printf("%d\n", a + b * c / f); 33 | printf("%d\n", a + b * c / f); 34 | printf("%d\n", (4 << 4)); 35 | printf("%d\n", (64 >> 4)); 36 | 37 | return 0; 38 | } 39 | 40 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 41 | -------------------------------------------------------------------------------- /v0100/include/limits.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __LIMITS_H 6 | #define __LIMITS_H 7 | 8 | #define CHAR_BIT 8 9 | 10 | #ifdef __SMALLER_C_SCHAR__ 11 | #define CHAR_MIN (-128) 12 | #define CHAR_MAX 127 13 | #endif 14 | 15 | #ifdef __SMALLER_C_UCHAR__ 16 | #define CHAR_MIN 0 17 | #define CHAR_MAX 255 18 | #endif 19 | 20 | #define SCHAR_MIN (-128) 21 | #define SCHAR_MAX 127 22 | #define UCHAR_MAX 255 23 | 24 | #define SHRT_MIN (-32767-1) 25 | #define SHRT_MAX 32767 26 | #define USHRT_MAX 0xFFFF 27 | 28 | #ifdef __SMALLER_C_16__ 29 | #define INT_MIN (-32767-1) 30 | #define INT_MAX 32767 31 | #define UINT_MAX 65535U 32 | #endif 33 | 34 | #ifdef __SMALLER_C_32__ 35 | #define INT_MIN (-2147483647-1) 36 | #define INT_MAX 2147483647 37 | #define UINT_MAX 4294967295U 38 | #define LONG_MIN (-2147483647L-1) 39 | #define LONG_MAX 2147483647L 40 | #define ULONG_MAX 4294967295UL 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /v0100/include/sys/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __SYS_TYPES_H 6 | #define __SYS_TYPES_H 7 | 8 | #ifndef __MODE_T_DEF 9 | #define __MODE_T_DEF 10 | typedef int mode_t; 11 | #endif 12 | 13 | #ifdef __SMALLER_C_32__ 14 | #ifndef __OFF_T_DEF 15 | #define __OFF_T_DEF 16 | typedef long off_t; 17 | #endif 18 | #endif 19 | 20 | #ifndef __FPOS_T_DEF 21 | #define __FPOS_T_DEF 22 | typedef struct 23 | { 24 | unsigned short halves[2]; 25 | } fpos_t; 26 | #endif 27 | 28 | #ifndef __SIZE_T_DEF 29 | #define __SIZE_T_DEF 30 | typedef unsigned size_t; 31 | #endif 32 | 33 | #ifndef __SSIZE_T_DEF 34 | #define __SSIZE_T_DEF 35 | typedef int ssize_t; 36 | #endif 37 | 38 | #ifdef __SMALLER_C_32__ 39 | #ifndef __TIME_T_DEF 40 | #define __TIME_T_DEF 41 | typedef unsigned long time_t; 42 | #endif 43 | #endif 44 | 45 | #ifndef __PID_T_DEF 46 | #define __PID_T_DEF 47 | typedef int pid_t; 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /v0100/srclib/ceil.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #ifdef __HUGE__ 9 | #define __HUGE_OR_UNREAL__ 10 | #endif 11 | #ifdef __UNREAL__ 12 | #define __HUGE_OR_UNREAL__ 13 | #endif 14 | 15 | #ifdef __HUGE_OR_UNREAL__ 16 | #define xbp "bp" 17 | #define xsp "sp" 18 | #else 19 | #define xbp "ebp" 20 | #define xsp "esp" 21 | #endif 22 | 23 | float ceilf(float x) 24 | { 25 | asm 26 | ( 27 | "sub "xsp", 4\n" 28 | "fnstcw ["xbp"-2]\n" // save rounding 29 | "mov ax, ["xbp"-2]\n" 30 | "mov ah, 0x08\n" // rounding towards +infinity 31 | "mov ["xbp"-4], ax\n" 32 | "fld dword ["xbp"+8]\n" 33 | "fldcw ["xbp"-4]\n" 34 | "frndint\n" 35 | "fstp dword ["xbp"+8]\n" 36 | "fldcw ["xbp"-2]\n" // restore rounding 37 | "add "xsp", 4\n" 38 | "mov eax, ["xbp"+8]" 39 | ); 40 | } 41 | 42 | double ceil(double x) 43 | { 44 | return ceilf(x); 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /v0100/include/fcntl.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __FCNTL_H 6 | #define __FCNTL_H 7 | 8 | #include 9 | 10 | #define O_RDONLY 0x0000 11 | #define O_WRONLY 0x0001 12 | #define O_RDWR 0x0002 13 | #define O_ACCMODE 0x0003 14 | 15 | #ifdef _MACOS 16 | #define O_CREAT 0x0200 17 | #define O_EXCL 0x0800 18 | #define O_TRUNC 0x0400 19 | #define O_APPEND 0x0008 20 | #else 21 | #define O_CREAT 0x0040 22 | #define O_EXCL 0x0080 23 | #define O_TRUNC 0x0200 24 | #define O_APPEND 0x0400 25 | #endif 26 | 27 | #ifndef __MODE_T_DEF 28 | #define __MODE_T_DEF 29 | typedef int mode_t; 30 | #endif 31 | 32 | #ifdef __SMALLER_C_32__ 33 | #ifndef __OFF_T_DEF 34 | #define __OFF_T_DEF 35 | typedef long off_t; 36 | #endif 37 | #endif 38 | 39 | int __creat(char*, mode_t); 40 | int creat(char*, mode_t); 41 | int __open(char*, int, ...); 42 | int open(char*, int, ...); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /v0100/srclib/floor.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #ifdef __HUGE__ 9 | #define __HUGE_OR_UNREAL__ 10 | #endif 11 | #ifdef __UNREAL__ 12 | #define __HUGE_OR_UNREAL__ 13 | #endif 14 | 15 | #ifdef __HUGE_OR_UNREAL__ 16 | #define xbp "bp" 17 | #define xsp "sp" 18 | #else 19 | #define xbp "ebp" 20 | #define xsp "esp" 21 | #endif 22 | 23 | float floorf(float x) 24 | { 25 | asm 26 | ( 27 | "sub "xsp", 4\n" 28 | "fnstcw ["xbp"-2]\n" // save rounding 29 | "mov ax, ["xbp"-2]\n" 30 | "mov ah, 0x04\n" // rounding towards -infinity 31 | "mov ["xbp"-4], ax\n" 32 | "fld dword ["xbp"+8]\n" 33 | "fldcw ["xbp"-4]\n" 34 | "frndint\n" 35 | "fstp dword ["xbp"+8]\n" 36 | "fldcw ["xbp"-2]\n" // restore rounding 37 | "add "xsp", 4\n" 38 | "mov eax, ["xbp"+8]" 39 | ); 40 | } 41 | 42 | double floor(double x) 43 | { 44 | return floorf(x); 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /v0100/srclib/trunc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #ifdef __HUGE__ 9 | #define __HUGE_OR_UNREAL__ 10 | #endif 11 | #ifdef __UNREAL__ 12 | #define __HUGE_OR_UNREAL__ 13 | #endif 14 | 15 | #ifdef __HUGE_OR_UNREAL__ 16 | #define xbp "bp" 17 | #define xsp "sp" 18 | #else 19 | #define xbp "ebp" 20 | #define xsp "esp" 21 | #endif 22 | 23 | float truncf(float x) 24 | { 25 | asm 26 | ( 27 | "sub "xsp", 4\n" 28 | "fnstcw ["xbp"-2]\n" // save rounding 29 | "mov ax, ["xbp"-2]\n" 30 | "mov ah, 0x0c\n" // rounding towards 0 (AKA truncate) 31 | "mov ["xbp"-4], ax\n" 32 | "fld dword ["xbp"+8]\n" 33 | "fldcw ["xbp"-4]\n" 34 | "frndint\n" 35 | "fstp dword ["xbp"+8]\n" 36 | "fldcw ["xbp"-2]\n" // restore rounding 37 | "add "xsp", 4\n" 38 | "mov eax, ["xbp"+8]" 39 | ); 40 | } 41 | 42 | double trunc(double x) 43 | { 44 | return truncf(x); 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /v0100/srclib/rewind.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | #include "istdio.h" 7 | 8 | void rewind(FILE* f) 9 | { 10 | fflush(f); 11 | 12 | if (f->flags & _IORWOK) 13 | f->flags &= ~(_IORD | _IOWR); // last operation for read-write files is neither 14 | 15 | f->flags &= ~(_IOUNGOT | _IOERR | _IOEOF); // ungetc()'s changes are gone 16 | 17 | f->ptr = f->buf; 18 | f->cnt = 0; // force entrance into __fillbuf()/__flushbuf() on the next read/write 19 | 20 | // "a+" mode isn't supported now because DOS doesn't support opening files in append mode directly. 21 | // "a" should ignore seek requests since it's always appending data at file's end and never reading anything. 22 | if (f->flags & _IOAPPEND) 23 | return; 24 | 25 | #ifdef __SMALLER_C_16__ 26 | { 27 | fpos_t pos; 28 | pos.halves[1] = pos.halves[0] = 0; 29 | __lseekp(f->fd, &pos, SEEK_SET); 30 | } 31 | #else 32 | __lseek(f->fd, 0, SEEK_SET); 33 | #endif 34 | } 35 | -------------------------------------------------------------------------------- /v0100/tests/picoc/23.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void charfunc(char a) 4 | { 5 | printf("char: %c\n", a); 6 | } 7 | 8 | void intfunc(int a) 9 | { 10 | printf("int: %d\n", a); 11 | } 12 | 13 | void floatfunc(float a) 14 | { 15 | printf("float: %f\n", a); 16 | } 17 | 18 | int main() 19 | { 20 | charfunc('a'); 21 | charfunc(98); 22 | charfunc(99.0); 23 | 24 | intfunc('a'); 25 | intfunc(98); 26 | intfunc(99.0); 27 | 28 | floatfunc('a'); 29 | floatfunc(98); 30 | floatfunc(99.0); 31 | 32 | /* printf("%c %d %f\n", 'a', 'b', 'c'); */ 33 | /* printf("%c %d %f\n", 97, 98, 99); */ 34 | /* printf("%c %d %f\n", 97.0, 98.0, 99.0); */ 35 | 36 | char b = 97; 37 | char c = 97.0; 38 | 39 | printf("%d %d\n", b, c); 40 | 41 | int d = 'a'; 42 | int e = 97.0; 43 | 44 | printf("%d %d\n", d, e); 45 | 46 | float f = 'a'; 47 | float g = 97; 48 | 49 | printf("%f %f\n", f, g); 50 | 51 | return 0; 52 | } 53 | 54 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 55 | -------------------------------------------------------------------------------- /v0100/srclib/fakmvcrt/msvcrt.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm( 8 | " section .dll_import0_msvcrt write align=4\n" 9 | " extern __start__dll_import2_msvcrt\n" 10 | " extern __start__dll_iat2_msvcrt\n" 11 | " dd __start__dll_import2_msvcrt, 0, 0, __msvcrt_dll__, __start__dll_iat2_msvcrt\n" 12 | 13 | // .dll_import2_msvcrt section follows. 14 | 15 | " section .dll_import2_msvcrt_trailer write align=4\n" 16 | " dd 0\n" 17 | 18 | // .dll_import3_msvcrt section follows. 19 | 20 | " section .dll_import4_msvcrt write align=1\n" 21 | " global __msvcrt_dll__\n" 22 | " __msvcrt_dll__:\n" // win32 functions will pull this file by this symbol 23 | " db \"msvcrt.dll\", 0\n" 24 | 25 | // .dll_iat2_msvcrt section follows. 26 | 27 | " section .dll_iat2_msvcrt_trailer write align=4\n" 28 | " dd 0\n" 29 | 30 | " section .data\n" 31 | " extern __dll_imports\n" 32 | " dd __dll_imports\n" // pull ../dimports.c 33 | ); 34 | 35 | #endif // _WINDOWS 36 | -------------------------------------------------------------------------------- /v0100/srclib/ftell.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | #include "istdio.h" 7 | #include 8 | 9 | #ifdef __SMALLER_C_32__ 10 | long ftell(FILE* f) 11 | { 12 | long pos = __lseek(f->fd, 0L, SEEK_CUR); 13 | if (pos == -1) 14 | { 15 | // errno = EUNKNOWN; 16 | return -1; 17 | } 18 | 19 | if (f->flags & _IORD) // read-only file or last was read 20 | { 21 | // underlying file's current position is after the last byte of data read, 22 | // so, there's f->cnt bytes from C file's position to underlying file's position 23 | pos -= f->cnt; 24 | } 25 | else if ((f->flags & _IOWR) && f->ptr != f->buf) // write-only file or last was write; there was no flush 26 | { 27 | // underlying file's current position is at the beginning of the buffer with unwritten data, 28 | // so, there's f->ptr - f->buf from underlying file's position to C file's position 29 | pos += f->ptr - f->buf; 30 | } 31 | 32 | return pos; 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /v0100/srclib/exp2.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __HUGE__ 12 | #define __HUGE_OR_UNREAL__ 13 | #endif 14 | #ifdef __UNREAL__ 15 | #define __HUGE_OR_UNREAL__ 16 | #endif 17 | 18 | #ifdef __HUGE_OR_UNREAL__ 19 | #define xbp "bp" 20 | #else 21 | #define xbp "ebp" 22 | #endif 23 | 24 | static 25 | float f2xm1p1(float x) 26 | { 27 | asm 28 | ( 29 | "fld dword ["xbp"+8]\n" 30 | "f2xm1\n" // x must be finite such that -1.0 <= x <= +1.0 31 | "fld1\n" 32 | "faddp\n" 33 | "fstp dword ["xbp"+8]\n" 34 | "mov eax, ["xbp"+8]" 35 | ); 36 | } 37 | 38 | float exp2f(float x) 39 | { 40 | float i; 41 | if (x < FLT_MIN_EXP - FLT_MANT_DIG - 1) 42 | return 0; 43 | if (x >= FLT_MAX_EXP) 44 | return INFINITY; 45 | if (x != x) 46 | return x; // NAN 47 | x = f2xm1p1(modff(x, &i)); 48 | return ldexpf(x, i); 49 | } 50 | 51 | double exp2(double x) 52 | { 53 | return exp2f(x); 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /v0100/include/stddef.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __STDDEF_H 6 | #define __STDDEF_H 7 | 8 | #ifndef NULL 9 | #define NULL 0 10 | #endif 11 | 12 | #ifndef __SIZE_T_DEF 13 | #define __SIZE_T_DEF 14 | typedef unsigned size_t; 15 | #endif 16 | 17 | typedef int ptrdiff_t; 18 | 19 | #ifndef __WCHAR_T_DEF 20 | #define __WCHAR_T_DEF 21 | #ifdef __SMALLER_C_WCHAR16__ 22 | #ifdef __SMALLER_C_SWCHAR__ 23 | typedef short wchar_t; 24 | #endif // __SMALLER_C_SWCHAR__ 25 | #ifdef __SMALLER_C_UWCHAR__ 26 | typedef unsigned short wchar_t; 27 | #endif // __SMALLER_C_UWCHAR__ 28 | #endif // __SMALLER_C_WCHAR16__ 29 | #ifdef __SMALLER_C_WCHAR32__ 30 | #ifdef __SMALLER_C_SWCHAR__ 31 | typedef int wchar_t; 32 | #endif // __SMALLER_C_SWCHAR__ 33 | #ifdef __SMALLER_C_UWCHAR__ 34 | typedef unsigned wchar_t; 35 | #endif // __SMALLER_C_UWCHAR__ 36 | #endif // __SMALLER_C_WCHAR32__ 37 | #endif // __WCHAR_T_DEF 38 | 39 | #ifdef __SMALLER_PP__ 40 | #define offsetof(type, member) ((unsigned)&((type*)0)->member) 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /v0100/srclib/kernel32/kernel32.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm( 8 | " section .dll_import0_kernel32 write align=4\n" 9 | " extern __start__dll_import2_kernel32\n" 10 | " extern __start__dll_iat2_kernel32\n" 11 | " dd __start__dll_import2_kernel32, 0, 0, __kernel32_dll__, __start__dll_iat2_kernel32\n" 12 | 13 | // .dll_import2_kernel32 section follows. 14 | 15 | " section .dll_import2_kernel32_trailer write align=4\n" 16 | " dd 0\n" 17 | 18 | // .dll_import3_kernel32 section follows. 19 | 20 | " section .dll_import4_kernel32 write align=1\n" 21 | " global __kernel32_dll__\n" 22 | " __kernel32_dll__:\n" // win32 functions will pull this file by this symbol 23 | " db \"kernel32.dll\", 0\n" 24 | 25 | // .dll_iat2_kernel32 section follows. 26 | 27 | " section .dll_iat2_kernel32_trailer write align=4\n" 28 | " dd 0\n" 29 | 30 | " section .data\n" 31 | " extern __dll_imports\n" 32 | " dd __dll_imports\n" // pull ../dimports.c 33 | ); 34 | 35 | #endif // _WINDOWS 36 | -------------------------------------------------------------------------------- /smallerc.spec.rpkg: -------------------------------------------------------------------------------- 1 | Name: smallerc 2 | Version: {{{ git_dir_version }}} 3 | Release: 1%{?dist} 4 | Summary: simple and small single-pass C compiler 5 | 6 | Group: Development/Languages 7 | 8 | License: BSD 9 | URL: https://github.com/alexfru/SmallerC 10 | VCS: {{{ git_dir_vcs }}} 11 | Source0: {{{ git_dir_archive }}} 12 | 13 | BuildRequires: gcc 14 | BuildRequires: make 15 | BuildRequires: nasm 16 | 17 | Requires: nasm 18 | 19 | %description 20 | Smaller C is a simple and small single-pass C compiler, 21 | currently supporting most of the C language common between C89/ANSI C 22 | and C99 (minus some C89 and plus some C99 features). 23 | 24 | %prep 25 | {{{ git_dir_setup_macro }}} 26 | 27 | %build 28 | make prefix=%{_prefix} 29 | 30 | %check 31 | %define __arch_install_post export NO_BRP_STRIP_DEBUG=true 32 | %define debug_package %{nil} 33 | %define __strip /bin/true 34 | 35 | %install 36 | make DESTDIR=%{buildroot} prefix=%{_prefix} install 37 | 38 | %files 39 | %defattr(-,root,root) 40 | %{_bindir}/* 41 | %{_prefix}/smlrc 42 | 43 | %changelog 44 | {{{ git_dir_changelog }}} 45 | -------------------------------------------------------------------------------- /v0100/include/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __STRING_H 6 | #define __STRING_H 7 | 8 | #ifndef NULL 9 | #define NULL 0 10 | #endif 11 | 12 | #ifndef __SIZE_T_DEF 13 | #define __SIZE_T_DEF 14 | typedef unsigned size_t; 15 | #endif 16 | 17 | void* memset(void*, int, size_t); 18 | void* memcpy(void*, void*, size_t); 19 | void* memmove(void*, void*, size_t); 20 | char* memchr(char*, int, size_t); 21 | int memcmp(void*, void*, size_t); 22 | 23 | char* strcpy(char*, char*); 24 | char* strncpy(char*, char*, size_t); 25 | size_t strxfrm(char*, char*, size_t); 26 | char* strcat(char*, char*); 27 | char* strncat(char*, char*, size_t); 28 | size_t strlen(char*); 29 | char* strchr(char*, int); 30 | char* strrchr(char*, int); 31 | char* strstr(char*, char*); 32 | size_t strspn(char*, char*); 33 | size_t strcspn(char*, char*); 34 | char* strpbrk(char*, char*); 35 | char* strtok(char*, char*); 36 | int strcmp(char*, char*); 37 | int strncmp(char*, char*, size_t); 38 | int strcoll(char*, char*); 39 | 40 | char* strerror(int); 41 | #endif 42 | -------------------------------------------------------------------------------- /v0100/doc/smlrpp.md: -------------------------------------------------------------------------------- 1 | # Smaller C Preprocessor 2 | 3 | ## Table of contents 4 | 5 | [What is Smaller C Preprocessor?](#what-is-smaller-c-preprocessor) 6 | 7 | [What features does Smaller C Preprocessor have?](#what-features-does-smaller-c-preprocessor-have) 8 | 9 | [How do I compile Smaller C Preprocessor?](#how-do-i-compile-smaller-c-preprocessor) 10 | 11 | ## What is Smaller C Preprocessor? 12 | 13 | Smaller C preprocessor (smlrpp) is a version of ucpp adapted for use with 14 | Smaller C (ucpp 1.3.2 was used as the basis). 15 | 16 | ## What features does Smaller C Preprocessor have? 17 | 18 | smlrpp (ucpp) is a C preprocessor compliant to ISO-C99. For more information 19 | please see the language standard and/or the ucpp documentation. 20 | 21 | ## How do I compile Smaller C Preprocessor? 22 | 23 | Something like this: 24 | 25 | > gcc -Wall -O2 -o smlrpp -DSTAND_ALONE -DUCPP_CONFIG arith.c assert.c cpp.c eval.c lexer.c macro.c mem.c nhash.c 26 | 27 | or 28 | 29 | > smlrcc -Wall -win -o smlrpp.exe -DSTAND_ALONE -DUCPP_CONFIG arith.c assert.c cpp.c eval.c lexer.c macro.c mem.c nhash.c 30 | 31 | -------------------------------------------------------------------------------- /v0100/srclib/asin.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __HUGE__ 12 | #define __HUGE_OR_UNREAL__ 13 | #endif 14 | #ifdef __UNREAL__ 15 | #define __HUGE_OR_UNREAL__ 16 | #endif 17 | 18 | #ifdef __HUGE_OR_UNREAL__ 19 | #define xbp "bp" 20 | #else 21 | #define xbp "ebp" 22 | #endif 23 | 24 | float asinf(float x) 25 | { 26 | union 27 | { 28 | unsigned u; 29 | float f; 30 | } u; 31 | u.f = x; 32 | if ((u.u &= 0x7FFFFFFF) > 0x3F800000) // if fabs(x) > 1 or x is NAN 33 | { 34 | if (u.u <= 0x7F800000) // if x isn't NAN 35 | errno = EDOM; 36 | return NAN; 37 | } 38 | asm 39 | ( 40 | "fld dword ["xbp"+8]\n" 41 | "fld st0\n" 42 | "fld1\n" 43 | "fsubr st1, st0\n" 44 | "fadd st0, st2\n" 45 | "fmulp\n" 46 | "fsqrt\n" 47 | "fpatan\n" 48 | "fstp dword ["xbp"+8]\n" 49 | "mov eax, ["xbp"+8]" 50 | ); 51 | } 52 | 53 | double asin(double x) 54 | { 55 | return asinf(x); 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /v0100/srclib/dimports.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2019, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifdef _WINDOWS 6 | 7 | asm( 8 | " section .dll_import write align=4\n" 9 | " dd 0\n" 10 | " global __dll_imports\n" 11 | " __dll_imports:\n" 12 | 13 | // .dll_import0_ sections follow. 14 | 15 | " section .dll_import1 write align=4\n" 16 | " dd 0, 0, 0, 0, 0\n" 17 | 18 | // Pairs of sections follow: 19 | // .dll_import2_ 20 | // .dll_import2__trailer 21 | 22 | // .dll_import3_ sections follow. 23 | // .dll_import4_ sections follow. 24 | 25 | " section .dll_imports_end write align=4\n" 26 | " global __dll_imports_end\n" 27 | " __dll_imports_end:\n" 28 | " dd 0\n" 29 | 30 | " section .dll_iat write align=4\n" 31 | " dd 0\n" 32 | " global __dll_iats\n" 33 | " __dll_iats:\n" 34 | 35 | // Pairs of sections follow: 36 | // .dll_iat2_ 37 | // .dll_iat2__trailer 38 | 39 | " section .dll_iats_end write align=4\n" 40 | " global __dll_iats_end\n" 41 | " __dll_iats_end:\n" 42 | " dd 0\n" 43 | ); 44 | 45 | #endif // _WINDOWS 46 | -------------------------------------------------------------------------------- /v0100/tests/argenv.c: -------------------------------------------------------------------------------- 1 | /* 2 | How to compile for DOS (all mode(l)s: tiny/.COM, small/.EXE, huge/.EXE, unreal/.EXE, 32-bit DPMI/.EXE): 3 | smlrcc -dost argenv.c -o argenvdt.com 4 | smlrcc -doss argenv.c -o argenvds.exe 5 | smlrcc -dosh argenv.c -o argenvdh.exe 6 | smlrcc -dosu argenv.c -o argenvdu.exe 7 | smlrcc -dosp argenv.c -o argenvdp.exe 8 | 9 | How to compile for Windows: 10 | smlrcc -win argenv.c -o argenvw.exe 11 | 12 | How to compile for Linux: 13 | smlrcc -linux argenv.c -o argenvl 14 | 15 | How to compile for MacOS: 16 | smlrcc -macos argenv.c -o argenvm 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | int main(int argc, char* argv[]) 23 | { 24 | int i = 0; 25 | 26 | printf("Arguments:\n"); 27 | for (i = 0; i < argc; i++) 28 | printf("argv[%d]=\"%s\"\n", i, argv[i]); 29 | 30 | printf("\nThese arguments in the environment:\n"); 31 | for (i = 0; i < argc; i++) 32 | { 33 | char* p; 34 | if ((p = getenv(argv[i])) != NULL) 35 | printf("\"%s\"=\"%s\"\n", argv[i], p); 36 | } 37 | 38 | printf("\n"); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /v0100/srclib/fmod.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __HUGE__ 12 | #define __HUGE_OR_UNREAL__ 13 | #endif 14 | #ifdef __UNREAL__ 15 | #define __HUGE_OR_UNREAL__ 16 | #endif 17 | 18 | #ifdef __HUGE_OR_UNREAL__ 19 | #define xbp "bp" 20 | #else 21 | #define xbp "ebp" 22 | #endif 23 | 24 | float fmodf(float x, float y) 25 | { 26 | union 27 | { 28 | unsigned u; 29 | float f; 30 | } ux, uy; 31 | ux.f = x; 32 | uy.f = y; 33 | if ((ux.u & 0x7FFFFFFF) == 0x7F800000 || (uy.u & 0x7FFFFFFF) == 0) // infinite x or zero y 34 | { 35 | errno = EDOM; 36 | return NAN; 37 | } 38 | asm 39 | ( 40 | "fld dword ["xbp"+12]\n" 41 | "fld dword ["xbp"+8]\n" 42 | ".repeat:\n" 43 | "fprem\n" 44 | "fstsw ax\n" 45 | "sahf\n" 46 | "jp .repeat\n" 47 | "fstp st1\n" 48 | "fstp dword ["xbp"+8]\n" 49 | "mov eax, ["xbp"+8]" 50 | ); 51 | } 52 | 53 | double fmod(double x, double y) 54 | { 55 | return fmodf(x, y); 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /v0100/srclib/expm1.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | 10 | #ifdef __HUGE__ 11 | #define __HUGE_OR_UNREAL__ 12 | #endif 13 | #ifdef __UNREAL__ 14 | #define __HUGE_OR_UNREAL__ 15 | #endif 16 | 17 | #ifdef __HUGE_OR_UNREAL__ 18 | #define xbp "bp" 19 | #else 20 | #define xbp "ebp" 21 | #endif 22 | 23 | static 24 | float f2xm1(float x) 25 | { 26 | asm 27 | ( 28 | "fld dword ["xbp"+8]\n" 29 | "f2xm1\n" // x must be finite such that -1.0 <= x <= +1.0 30 | "fstp dword ["xbp"+8]\n" 31 | "mov eax, ["xbp"+8]" 32 | ); 33 | } 34 | 35 | float expm1f(float x) 36 | { 37 | float i; 38 | if (x == 0) 39 | return x; // preserve sign of 0 40 | x = x * 1.44269504f/*log2(e)*/; 41 | if (x <= 26) 42 | { 43 | // -INF handled here 44 | x = f2xm1(modff(x, &i)); 45 | i = ldexpf(1, i); 46 | return x * i + (i - 1); 47 | } 48 | else 49 | { 50 | // NAN, +INF handled here 51 | return exp2f(x); 52 | } 53 | } 54 | 55 | double expm1(double x) 56 | { 57 | return expm1f(x); 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /v0100/srclib/acos.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __HUGE__ 12 | #define __HUGE_OR_UNREAL__ 13 | #endif 14 | #ifdef __UNREAL__ 15 | #define __HUGE_OR_UNREAL__ 16 | #endif 17 | 18 | #ifdef __HUGE_OR_UNREAL__ 19 | #define xbp "bp" 20 | #define xsp "sp" 21 | #else 22 | #define xbp "ebp" 23 | #define xsp "esp" 24 | #endif 25 | 26 | float acosf(float x) 27 | { 28 | union 29 | { 30 | unsigned u; 31 | float f; 32 | } u; 33 | u.f = x; 34 | if ((u.u &= 0x7FFFFFFF) > 0x3F800000) // if fabs(x) > 1 or x is NAN 35 | { 36 | if (u.u <= 0x7F800000) // if x isn't NAN 37 | errno = EDOM; 38 | return NAN; 39 | } 40 | asm 41 | ( 42 | "fld dword ["xbp"+8]\n" 43 | "fld st0\n" 44 | "fld1\n" 45 | "fsubr st1, st0\n" 46 | "fadd st0, st2\n" 47 | "fmulp\n" 48 | "fsqrt\n" 49 | "fxch st1\n" 50 | "fpatan\n" 51 | "fstp dword ["xbp"+8]\n" 52 | "mov eax, ["xbp"+8]" 53 | ); 54 | } 55 | 56 | double acos(double x) 57 | { 58 | return acosf(x); 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /v0100/include/locale.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #ifndef __LOCALE_H 6 | #define __LOCALE_H 7 | 8 | #ifndef NULL 9 | #define NULL 0 10 | #endif 11 | 12 | struct lconv 13 | { 14 | char* decimal_point; 15 | char* thousands_sep; 16 | char* grouping; 17 | char* mon_decimal_point; 18 | char* mon_thousands_sep; 19 | char* mon_grouping; 20 | char* positive_sign; 21 | char* negative_sign; 22 | char* currency_symbol; 23 | char frac_digits; 24 | char p_cs_precedes; 25 | char n_cs_precedes; 26 | char p_sep_by_space; 27 | char n_sep_by_space; 28 | char p_sign_posn; 29 | char n_sign_posn; 30 | char* int_curr_symbol; 31 | char int_frac_digits; 32 | char int_p_cs_precedes; 33 | char int_n_cs_precedes; 34 | char int_p_sep_by_space; 35 | char int_n_sep_by_space; 36 | char int_p_sign_posn; 37 | char int_n_sign_posn; 38 | }; 39 | 40 | #define LC_ALL 0 41 | #define LC_COLLATE 1 42 | #define LC_CTYPE 2 43 | #define LC_MONETARY 3 44 | #define LC_NUMERIC 4 45 | #define LC_TIME 5 46 | 47 | char* setlocale(int, char*); 48 | struct lconv* localeconv(void); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /v0100/srclib/tmpfile.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include "istdio.h" 9 | 10 | FILE* tmpfile(void) 11 | { 12 | unsigned i; 13 | char* name = malloc(L_tmpnam); 14 | int fd = -1; 15 | FILE* f = malloc(sizeof(FILE)); 16 | 17 | if (!name || !f) 18 | { 19 | goto err; 20 | } 21 | 22 | for (i = 0; i < TMP_MAX; i++) 23 | { 24 | if (!__tmpnam(name, 1)) 25 | continue; 26 | 27 | if ((fd = __open(name, O_EXCL | O_CREAT | O_TRUNC | O_RDWR, 0666)) >= 0) 28 | break; 29 | } 30 | 31 | if (fd < 0) 32 | { 33 | goto err; 34 | } 35 | 36 | f->fd = fd; 37 | f->flags = _IORWOK | _IOBINARY | _IOREMOVE; 38 | 39 | f->ptr = f->buf = NULL; 40 | f->cnt = f->bufsz = 0; 41 | 42 | f->name = name; 43 | 44 | f->prev = __StreamsHead.prev; 45 | f->next = &__StreamsHead; 46 | f->next->prev = f; 47 | f->prev->next = f; 48 | 49 | __pFileCloser = &__FileCloser; 50 | 51 | return f; 52 | 53 | err: 54 | 55 | if (name) 56 | free(name); 57 | 58 | if (f) 59 | free(f); 60 | 61 | return NULL; 62 | } 63 | -------------------------------------------------------------------------------- /v0100/tests/lnktst1.asm: -------------------------------------------------------------------------------- 1 | ; 2 | ; Small linker test for nasm and smlrl. 3 | ; 4 | ; 5 | ; How to compile for DOS using the tiny memory model: 6 | ; 7 | ; smlrcc -dost lnktst1.asm lnktst1b.asm -o lnktst1t.com -map lnktst1t.map 8 | ; or 9 | ; nasm -f elf lnktst1.asm -o lnktst1.o 10 | ; nasm -f elf lnktst1b.asm -o lnktst1b.o 11 | ; smlrl -tiny lnktst1.o lnktst1b.o -o lnktst1t.com -map lnktst1t.map 12 | ; 13 | ; 14 | ; How to compile for DOS using the small memory model: 15 | ; 16 | ; smlrcc -doss lnktst1.asm lnktst1b.asm -o lnktst1s.exe -map lnktst1s.map 17 | ; or 18 | ; nasm -f elf lnktst1.asm -o lnktst1.o 19 | ; nasm -f elf lnktst1b.asm -o lnktst1b.o 20 | ; smlrl -small lnktst1.o lnktst1b.o -o lnktst1s.exe -map lnktst1s.map 21 | ; 22 | 23 | bits 16 24 | 25 | extern func 26 | 27 | section .text 28 | 29 | global __start 30 | __start: 31 | ; these 3 lines are only needed for .EXEs, but not .COMs 32 | mov ax, ss 33 | mov ds, ax ; DS=ES=SS in small model .EXEs and in tiny model .COMs 34 | mov es, ax 35 | 36 | call func 37 | 38 | mov ax, 0x4c00 39 | int 0x21 40 | 41 | section .data 42 | 43 | global msg 44 | msg db "Linker test!",13,10,"$" 45 | -------------------------------------------------------------------------------- /v0100/tests/picoc/28.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char a[10]; 7 | 8 | strcpy(a, "hello"); 9 | printf("%s\n", a); 10 | 11 | strncpy(a, "gosh", 2); 12 | printf("%s\n", a); 13 | 14 | printf("%d\n", strcmp(a, "apple") > 0); 15 | printf("%d\n", strcmp(a, "goere") > 0); 16 | printf("%d\n", strcmp(a, "zebra") < 0); 17 | 18 | printf("%d\n", strlen(a)); 19 | 20 | strcat(a, "!"); 21 | printf("%s\n", a); 22 | 23 | printf("%d\n", strncmp(a, "apple", 2) > 0); 24 | printf("%d\n", strncmp(a, "goere", 2) == 0); 25 | printf("%d\n", strncmp(a, "goerg", 2) == 0); 26 | printf("%d\n", strncmp(a, "zebra", 2) < 0); 27 | 28 | printf("%s\n", strchr(a, 'o')); 29 | printf("%s\n", strrchr(a, 'l')); 30 | printf("%d\n", strrchr(a, 'x') == NULL); 31 | 32 | memset(&a[1], 'r', 4); 33 | printf("%s\n", a); 34 | 35 | memcpy(&a[2], a, 2); 36 | printf("%s\n", a); 37 | 38 | printf("%d\n", memcmp(a, "apple", 4) > 0); 39 | printf("%d\n", memcmp(a, "grgr", 4) == 0); 40 | printf("%d\n", memcmp(a, "zebra", 4) < 0); 41 | 42 | return 0; 43 | } 44 | 45 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 46 | -------------------------------------------------------------------------------- /v0100/srclib/ftell16.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | #include "istdio.h" 7 | #include 8 | #include 9 | 10 | int __ftell(FILE* f, fpos_t* pos) 11 | { 12 | if (__lseekp(f->fd, pos, SEEK_CUR)) 13 | { 14 | // errno = EUNKNOWN; 15 | return -1; 16 | } 17 | 18 | if (f->flags & _IORD) // read-only file or last was read 19 | { 20 | // underlying file's current position is after the last byte of data read, 21 | // so, there's f->cnt bytes from C file's position to underlying file's position 22 | // pos -= f->cnt; 23 | fpos_t t; 24 | __lngFromUnsigned(&t, f->cnt); 25 | __lngSub(pos, &t); 26 | } 27 | else if ((f->flags & _IOWR) && f->ptr != f->buf) // write-only file or last was write; there was no flush 28 | { 29 | // underlying file's current position is at the beginning of the buffer with unwritten data, 30 | // so, there's f->ptr - f->buf from underlying file's position to C file's position 31 | // pos += f->ptr - f->buf; 32 | fpos_t t; 33 | __lngFromUnsigned(&t, f->ptr - f->buf); 34 | __lngAdd(pos, &t); 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /v0100/tests/picoc/40.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | FILE *f = fopen("fred.txt", "w"); 6 | fwrite("hello\nhello\n", 1, 12, f); 7 | fclose(f); 8 | 9 | char freddy[7]; 10 | f = fopen("fred.txt", "r"); 11 | if (fread(freddy, 1, 6, f) != 6) 12 | printf("couldn't read fred.txt\n"); 13 | 14 | freddy[6] = '\0'; 15 | fclose(f); 16 | 17 | printf("%s", freddy); 18 | 19 | int InChar; 20 | char ShowChar; 21 | f = fopen("fred.txt", "r"); 22 | while ( (InChar = fgetc(f)) != EOF) 23 | { 24 | ShowChar = InChar; 25 | if (ShowChar < ' ') 26 | ShowChar = '.'; 27 | 28 | printf("ch: %d '%c'\n", InChar, ShowChar); 29 | } 30 | fclose(f); 31 | 32 | f = fopen("fred.txt", "r"); 33 | while ( (InChar = getc(f)) != EOF) 34 | { 35 | ShowChar = InChar; 36 | if (ShowChar < ' ') 37 | ShowChar = '.'; 38 | 39 | printf("ch: %d '%c'\n", InChar, ShowChar); 40 | } 41 | fclose(f); 42 | 43 | f = fopen("fred.txt", "r"); 44 | while (fgets(freddy, sizeof(freddy), f) != NULL) 45 | printf("x: %s", freddy); 46 | 47 | fclose(f); 48 | 49 | return 0; 50 | } 51 | 52 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 53 | -------------------------------------------------------------------------------- /v0100/srclib/hypot.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | 10 | #ifdef __HUGE__ 11 | #define __HUGE_OR_UNREAL__ 12 | #endif 13 | #ifdef __UNREAL__ 14 | #define __HUGE_OR_UNREAL__ 15 | #endif 16 | 17 | #ifdef __HUGE_OR_UNREAL__ 18 | #define xbp "bp" 19 | #else 20 | #define xbp "ebp" 21 | #endif 22 | 23 | float hypotf(float x, float y) 24 | { 25 | union 26 | { 27 | unsigned u; 28 | float f; 29 | } ux, uy; 30 | ux.f = x; 31 | uy.f = y; 32 | ux.u &= 0x7FFFFFFF; 33 | uy.u &= 0x7FFFFFFF; 34 | // IEC60559: if one is zero, return fabsf() of the other 35 | if (ux.u == 0) 36 | return uy.f; 37 | if (uy.u == 0) 38 | return ux.f; 39 | // IEC60559: if one is infinity, return infinity (the other may be NAN) 40 | if (ux.u == 0x7F800000 || uy.u == 0x7F800000) 41 | return INFINITY; 42 | asm 43 | ( 44 | "fld dword ["xbp"+12]\n" 45 | "fmul st0, st0\n" 46 | "fld dword ["xbp"+8]\n" 47 | "fmul st0, st0\n" 48 | "faddp\n" 49 | "fsqrt\n" 50 | "fstp dword ["xbp"+8]\n" 51 | "mov eax, ["xbp"+8]" 52 | ); 53 | } 54 | 55 | double hypot(double x, double y) 56 | { 57 | return hypotf(x, y); 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /v0100/tests/picoc/41.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("#include test\n"); 6 | 7 | #if 1 8 | #if 0 9 | printf("a\n"); 10 | #else 11 | printf("b\n"); 12 | #endif 13 | #else 14 | #if 0 15 | printf("c\n"); 16 | #else 17 | printf("d\n"); 18 | #endif 19 | #endif 20 | 21 | #if 0 22 | #if 1 23 | printf("e\n"); 24 | #else 25 | printf("f\n"); 26 | #endif 27 | #else 28 | #if 1 29 | printf("g\n"); 30 | #else 31 | printf("h\n"); 32 | #endif 33 | #endif 34 | 35 | #define DEF 36 | 37 | #ifdef DEF 38 | #ifdef DEF 39 | printf("i\n"); 40 | #else 41 | printf("j\n"); 42 | #endif 43 | #else 44 | #ifdef DEF 45 | printf("k\n"); 46 | #else 47 | printf("l\n"); 48 | #endif 49 | #endif 50 | 51 | #ifndef DEF 52 | #ifndef DEF 53 | printf("m\n"); 54 | #else 55 | printf("n\n"); 56 | #endif 57 | #else 58 | #ifndef DEF 59 | printf("o\n"); 60 | #else 61 | printf("p\n"); 62 | #endif 63 | #endif 64 | 65 | #define ONE 1 66 | #define ZERO 0 67 | 68 | #if ONE 69 | #if ZERO 70 | printf("q\n"); 71 | #else 72 | printf("r\n"); 73 | #endif 74 | #else 75 | #if ZERO 76 | printf("s\n"); 77 | #else 78 | printf("t\n"); 79 | #endif 80 | #endif 81 | 82 | return 0; 83 | } 84 | 85 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 86 | -------------------------------------------------------------------------------- /v0100/srclib/cos.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __HUGE__ 12 | #define __HUGE_OR_UNREAL__ 13 | #endif 14 | #ifdef __UNREAL__ 15 | #define __HUGE_OR_UNREAL__ 16 | #endif 17 | 18 | #ifdef __HUGE_OR_UNREAL__ 19 | #define xbp "bp" 20 | #else 21 | #define xbp "ebp" 22 | #endif 23 | 24 | float cosf(float x) 25 | { 26 | union 27 | { 28 | unsigned u; 29 | float f; 30 | } u; 31 | u.f = x; 32 | if ((u.u & 0x7FFFFFFF) == 0x7F800000) // if x is infinite 33 | { 34 | errno = EDOM; 35 | return NAN; 36 | } 37 | // NAN will successfully propagate through fcos 38 | asm 39 | ( 40 | "fldpi\n" 41 | "fadd st0, st0\n" // 2*pi to reduce fabs(x) when it's too big 42 | "fld dword ["xbp"+8]\n" 43 | ".repeat:\n" 44 | "fcos\n" 45 | "fstsw ax\n" 46 | "sahf\n" 47 | "jnp .done\n" // success 48 | "fprem\n" // fabs(x) is too big, reduce fabs(x) by a multiple of 2*pi 49 | "jmp .repeat\n" 50 | ".done:\n" 51 | "fstp st1\n" 52 | "fstp dword ["xbp"+8]\n" 53 | "mov eax, ["xbp"+8]" 54 | ); 55 | } 56 | 57 | double cos(double x) 58 | { 59 | return cosf(x); 60 | } 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /v0100/srclib/fclose.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2018, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | #include 6 | #include 7 | #include "istdio.h" 8 | 9 | int fclose(FILE* f) 10 | { 11 | int res; 12 | 13 | if (!f) 14 | return EOF; 15 | 16 | res = fflush(f); 17 | 18 | // close(f->fd), unless f is one of unreopened stdin, stdout, stderr 19 | // TBD??? Should I let go of stdin, stdout, stderr handles and close the underlying files??? 20 | if ((f->flags & _IOTERM) == 0) 21 | { 22 | if (__close(f->fd) < 0) 23 | res = EOF; 24 | f->fd = -1; 25 | } 26 | 27 | // Delete if temporary 28 | if (f->flags & _IOREMOVE && f->name) 29 | { 30 | remove(f->name); 31 | free(f->name); 32 | } 33 | f->name = NULL; 34 | 35 | // Free buffers from set(v)buf() 36 | if (f->buf && f->buf != &f->c && 37 | !(f->flags & _IOEXTBUF)) 38 | { 39 | free(f->buf); 40 | } 41 | f->ptr = f->buf = NULL; 42 | f->cnt = f->bufsz = 0; 43 | 44 | f->flags = 0; 45 | 46 | // free(f), unless f is one of stdin, stdout, stderr, 47 | // which are needed around for freopen() 48 | if (f->next) 49 | { 50 | f->next->prev = f->prev; 51 | f->prev->next = f->next; 52 | free(f); 53 | } 54 | 55 | return res; 56 | } 57 | -------------------------------------------------------------------------------- /v0100/srclib/sin.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Alexey Frunze 3 | 2-clause BSD license. 4 | */ 5 | 6 | #ifdef __SMALLER_C_32__ 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __HUGE__ 12 | #define __HUGE_OR_UNREAL__ 13 | #endif 14 | #ifdef __UNREAL__ 15 | #define __HUGE_OR_UNREAL__ 16 | #endif 17 | 18 | #ifdef __HUGE_OR_UNREAL__ 19 | #define xbp "bp" 20 | #else 21 | #define xbp "ebp" 22 | #endif 23 | 24 | float sinf(float x) 25 | { 26 | union 27 | { 28 | unsigned u; 29 | float f; 30 | } u; 31 | u.f = x; 32 | if ((u.u & 0x7FFFFFFF) == 0x7F800000) // if x is infinite 33 | { 34 | errno = EDOM; 35 | return NAN; 36 | } 37 | // NAN will successfully propagate through fsin 38 | asm 39 | ( 40 | "fldpi\n" 41 | "fadd st0, st0\n" // 2*pi to reduce fabs(x) when it's too big 42 | "fld dword ["xbp"+8]\n" 43 | ".repeat:\n" 44 | "fsin\n" 45 | "fstsw ax\n" 46 | "sahf\n" 47 | "jnp .done\n" // success 48 | "fprem\n" // fabs(x) is too big, reduce fabs(x) by a multiple of 2*pi 49 | "jmp .repeat\n" 50 | ".done:\n" 51 | "fstp st1\n" 52 | "fstp dword ["xbp"+8]\n" 53 | "mov eax, ["xbp"+8]" 54 | ); 55 | } 56 | 57 | double sin(double x) 58 | { 59 | return sinf(x); 60 | } 61 | 62 | #endif 63 | --------------------------------------------------------------------------------