├── .gitignore ├── README ├── excluded ├── icmake ├── INSTALL ├── INSTALL.im ├── QUICKINSTALL ├── VERSION ├── bootstrap │ ├── flags │ └── functions ├── build ├── changelog ├── comp │ ├── CLASSES │ ├── build │ ├── global.h │ ├── icm_bootstrap │ ├── icmconf │ ├── main.c │ ├── main.ih │ ├── parser │ │ ├── backend.c │ │ ├── data.c │ │ ├── frame │ │ ├── grammar │ │ ├── inc │ │ │ ├── args.5 │ │ │ ├── breakok.5 │ │ │ ├── breakstat.5 │ │ │ ├── closebrace.5 │ │ │ ├── closepar.5 │ │ │ ├── comma.5 │ │ │ ├── compound.5 │ │ │ ├── condition.5 │ │ │ ├── continuestat.5 │ │ │ ├── defvarorfun.5 │ │ │ ├── enterid.5 │ │ │ ├── entervarid.5 │ │ │ ├── errexpression.5 │ │ │ ├── exprcode.5 │ │ │ ├── expression.5 │ │ │ ├── forstat.5 │ │ │ ├── funcdef.5 │ │ │ ├── function.5 │ │ │ ├── ifstat.5 │ │ │ ├── makelist.5 │ │ │ ├── nesting.5 │ │ │ ├── ok.5 │ │ │ ├── openbrace.5 │ │ │ ├── openpar.5 │ │ │ ├── operators.3 │ │ │ ├── popdead.5 │ │ │ ├── preamble.1 │ │ │ ├── pushdead.5 │ │ │ ├── returnstat.5 │ │ │ ├── semicol.5 │ │ │ ├── start.4 │ │ │ ├── statement.5 │ │ │ ├── statements.5 │ │ │ ├── tokens.2 │ │ │ ├── typedcondition.5 │ │ │ ├── typedvarlist.5 │ │ │ ├── typeofvar.5 │ │ │ ├── varcondition.5 │ │ │ ├── varexpr.5 │ │ │ ├── varexprlist.5 │ │ │ ├── whilestat.5 │ │ │ ├── yywrap.6 │ │ │ └── zeroframe.5 │ │ ├── paddition.c │ │ ├── paddpatch.c │ │ ├── pandboolean.c │ │ ├── parse.c │ │ ├── parser.c │ │ ├── parser.h │ │ ├── parser.ih │ │ ├── passign.c │ │ ├── passignment.c │ │ ├── pband.c │ │ ├── pbeginfunction.c │ │ ├── pbinop.c │ │ ├── pbnot.c │ │ ├── pbor.c │ │ ├── pbreakstm.c │ │ ├── pbtoi.c │ │ ├── pcallfun.c │ │ ├── pcallhidden.c │ │ ├── pcallrss.c │ │ ├── pcast.c │ │ ├── pcatargs.c │ │ ├── pcatcode.c │ │ ├── pcatstmnts.c │ │ ├── pcatstrings.c │ │ ├── pcheckargumenttypes.c │ │ ├── pclearoperands.c │ │ ├── pcompoundass.c │ │ ├── pconflict.c │ │ ├── pcontinue.c │ │ ├── pdefinevar.c │ │ ├── pdiscard.c │ │ ├── pdivide.c │ │ ├── pendfunction.c │ │ ├── pequal.c │ │ ├── pexecute.c │ │ ├── pexpr.c │ │ ├── pexpr2bool.c │ │ ├── pexpr2stack.c │ │ ├── pfetchvar.c │ │ ├── pfindstring.c │ │ ├── pfirstarg.c │ │ ├── pfor.c │ │ ├── pforceexpr2bool.c │ │ ├── pfprintf.c │ │ ├── pfunctionidx.c │ │ ├── pgeneratecode.c │ │ ├── pgreater.c │ │ ├── pgrequal.c │ │ ├── phiddenfunctions.c │ │ ├── picast.c │ │ ├── pif.c │ │ ├── pincdec.c │ │ ├── pindexop.c │ │ ├── pinsertarg.c │ │ ├── plaststmnt.c │ │ ├── plcast.c │ │ ├── pmakeframe.c │ │ ├── pmakelist.c │ │ ├── pmodulo.c │ │ ├── pmultipleargs.c │ │ ├── pmultiply.c │ │ ├── pnegate.c │ │ ├── pnextcall.c │ │ ├── pnotboolean.c │ │ ├── pnullframe3.c │ │ ├── pold.c │ │ ├── ponearg.c │ │ ├── poptintspecial.c │ │ ├── poptintstring.c │ │ ├── porboolean.c │ │ ├── poutcode.c │ │ ├── ppatchcontinue.c │ │ ├── ppatchfalse.c │ │ ├── ppatchtrue.c │ │ ├── ppatchup.c │ │ ├── ppatchupcontinue.c │ │ ├── ppatchupfalse.c │ │ ├── ppatchuptrue.c │ │ ├── ppopdead.c │ │ ├── ppopvar.c │ │ ├── ppushdead.c │ │ ├── preturn.c │ │ ├── prmjmpzero.c │ │ ├── pscast.c │ │ ├── pshl.c │ │ ├── pshr.c │ │ ├── psmaller.c │ │ ├── psmequal.c │ │ ├── pspecials.c │ │ ├── pstackframe.c │ │ ├── psubtract.c │ │ ├── pternary.c │ │ ├── ptestbinop.c │ │ ├── ptestoperand.c │ │ ├── pthreeargs.c │ │ ├── ptrysiconvert.c │ │ ├── ptwoargs.c │ │ ├── punequal.c │ │ ├── pwhilestm.c │ │ ├── pxor.c │ │ ├── pyoung.c │ │ ├── pyyerror.c │ │ ├── pzeroargs.c │ │ ├── semval.ih │ │ └── tokens.h │ ├── scanner │ │ ├── data.c │ │ ├── filenames.c │ │ ├── frame │ │ ├── lexer │ │ ├── lexer.c │ │ ├── savedlinenr.c │ │ ├── savedtext.c │ │ ├── scanner.c │ │ ├── scanner.h │ │ ├── scanner.ih │ │ ├── scappend.c │ │ ├── scchangefile.c │ │ ├── sccharconst.c │ │ ├── scescapedchar.c │ │ ├── scpopfile.c │ │ ├── scsaveinfo.c │ │ ├── scscan.c │ │ └── scsetlinenr.c │ ├── symtab │ │ ├── addfunction.c │ │ ├── cleanup.c │ │ ├── data.c │ │ ├── definevar.c │ │ ├── findfun.c │ │ ├── findvar.c │ │ ├── frame │ │ ├── funaddress.c │ │ ├── funname.c │ │ ├── funnparams.c │ │ ├── funparametertype.c │ │ ├── funtype.c │ │ ├── lastfunction.c │ │ ├── localtype.c │ │ ├── newparam.c │ │ ├── nglobals.c │ │ ├── nlocals.c │ │ ├── nparams.c │ │ ├── pop.c │ │ ├── push.c │ │ ├── setfunparams.c │ │ ├── setlastfunction.c │ │ ├── staddvar.c │ │ ├── stcomparevars.c │ │ ├── stdeletevars.c │ │ ├── stfindfun.c │ │ ├── stfindvar.c │ │ ├── stlastfuninfo.c │ │ ├── stnestingoffset.c │ │ ├── stnewidxptr.c │ │ ├── stnewvaridx.c │ │ ├── stnextfunidx.c │ │ ├── stnextvaridx.c │ │ ├── stparamtype.c │ │ ├── sttoplevel.c │ │ ├── stvartab.c │ │ ├── symtab.c │ │ ├── symtab.h │ │ ├── symtab.ih │ │ ├── vartype.c │ │ ├── writefunaddress.c │ │ └── writeglobals.c │ ├── updategrammar │ ├── updateparser │ ├── updatescanner │ └── util │ │ ├── catstring.c │ │ ├── charconst.c │ │ ├── data.c │ │ ├── frame │ │ ├── out.c │ │ ├── printf.c │ │ ├── scan.c │ │ ├── semantic.c │ │ ├── setsourcename.c │ │ ├── setstring.c │ │ ├── sourcename.c │ │ ├── string.c │ │ ├── util.h │ │ └── util.ih ├── contributions │ └── solaris ├── dep │ ├── CLASSES │ ├── build │ ├── dependencies │ │ ├── dcheckuseall.c │ │ ├── dclosure.c │ │ ├── depdependent.c │ │ ├── depdir.c │ │ ├── dependencies.h │ │ ├── dependencies.ih │ │ ├── dependencies1.c │ │ ├── depgch.c │ │ ├── depgchindicator.c │ │ ├── depsize.c │ │ ├── depuseall.c │ │ ├── depuseallexists.c │ │ ├── dfilltable.c │ │ ├── dfinddependents.c │ │ ├── dhandleinclude.c │ │ ├── dihfile.c │ │ ├── dimplieddependencies.c │ │ ├── dinitable.c │ │ ├── dinspectfile.c │ │ ├── dinspectgch.c │ │ ├── dinspectih.c │ │ ├── dreadclasses.c │ │ ├── dshowtable.c │ │ ├── dtranspose.c │ │ ├── frame │ │ └── inspectcomp.cc │ ├── frame │ ├── icm_bootstrap │ ├── icmconf │ ├── main.c │ ├── main.ih │ ├── options │ │ ├── frame │ │ ├── oicmconf.c │ │ ├── optclasses.c │ │ ├── optgch.c │ │ ├── optgo.c │ │ ├── optih.c │ │ ├── options.h │ │ ├── options.ih │ │ ├── options1.c │ │ ├── optmainih.c │ │ ├── optmsg.c │ │ ├── optparser.c │ │ ├── optscanner.c │ │ ├── optuseall.c │ │ └── optverbose.c │ ├── process │ │ ├── pgch.c │ │ ├── pinspectgch.c │ │ ├── pinspectuseall.c │ │ ├── process.h │ │ ├── process.ih │ │ ├── process1.c │ │ ├── processactions.c │ │ ├── ptouch.c │ │ ├── punlinkgch.c │ │ └── puseall.c │ ├── usage.c │ ├── util │ │ ├── data.c │ │ ├── freetable.c │ │ ├── getline.c │ │ ├── initrow.c │ │ ├── inittable.c │ │ ├── openfile.c │ │ ├── regcomp.c │ │ ├── regmatch.c │ │ ├── strcatn.c │ │ ├── tocwd.c │ │ ├── trychdir.c │ │ ├── util.h │ │ ├── util.ih │ │ └── utilinit.c │ └── vector │ │ ├── add.c │ │ ├── assign.c │ │ ├── erase.c │ │ ├── find.c │ │ ├── frame │ │ ├── resize.c │ │ ├── vector.h │ │ ├── vector.ih │ │ ├── vector1.c │ │ ├── vectordestructor.c │ │ └── vectorreplacen.c ├── doc │ ├── README.icmbuild │ ├── icmake.1 │ ├── icmake.doc │ ├── icmake.ps │ ├── icmbuild.1 │ ├── icmconf.7 │ ├── icmstart.1 │ ├── icmstart.rc.7 │ └── manpage │ │ ├── build │ │ ├── icmake.yo │ │ ├── icmbuild.yo │ │ ├── icmconf.yo │ │ ├── icmstart.rc.yo │ │ ├── icmstart.yo │ │ └── trailer.inc ├── etc │ └── icmake │ │ └── icmstart.rc ├── examples │ ├── 7.00 │ │ ├── backtick.im │ │ ├── define.im │ │ ├── getenv.im │ │ ├── ifdef.im │ │ ├── index.im │ │ ├── strfind.im │ │ ├── strlwr.im │ │ └── substr.im │ ├── 8.00 │ │ └── strformat.im │ ├── am │ ├── bup │ ├── defines │ ├── ds │ ├── ftpxfer │ ├── idir │ ├── initialization │ ├── keep │ ├── killprog │ ├── nesteddirectives │ ├── r │ └── tolower ├── exec │ ├── CLASSES │ ├── aux │ │ ├── abnormal.c │ │ ├── aux.h │ │ ├── aux.ih │ │ ├── data.c │ │ ├── frame │ │ ├── offset.c │ │ ├── set.c │ │ ├── testrmbim.c │ │ └── unlinkbim.c │ ├── bootstrap │ ├── build │ ├── builtin │ │ ├── barghead.c │ │ ├── bargtail.c │ │ ├── basciiint.c │ │ ├── basciistring.c │ │ ├── bbacktick.c │ │ ├── bchangebase.c │ │ ├── bchangeextension.c │ │ ├── bchangepath.c │ │ ├── bchdir.c │ │ ├── bcmdhead.c │ │ ├── bcmdtail.c │ │ ├── bdotextension.c │ │ ├── becho.c │ │ ├── belement.c │ │ ├── bempty.c │ │ ├── bexec.c │ │ ├── bexists.c │ │ ├── bextension.c │ │ ├── bfgets.c │ │ ├── bfprintf.c │ │ ├── bgetbase.c │ │ ├── bgetch.c │ │ ├── bgetenv.c │ │ ├── bgetexecarg.c │ │ ├── bgets.c │ │ ├── blistfind.c │ │ ├── blistlen.c │ │ ├── blistunion.c │ │ ├── bmakelist.c │ │ ├── bpath.c │ │ ├── bprintf.c │ │ ├── bputenv.c │ │ ├── bresize.c │ │ ├── bstat.c │ │ ├── bstrchr.c │ │ ├── bstrelement.c │ │ ├── bstrfind.c │ │ ├── bstrformat.c │ │ ├── bstrlength.c │ │ ├── bstrlower.c │ │ ├── bstrtok.c │ │ ├── bstrupper.c │ │ ├── bsubstring.c │ │ ├── bsystem.c │ │ ├── btrim.c │ │ ├── btrimleft.c │ │ ├── btrimright.c │ │ ├── builtin.c │ │ ├── builtin.h │ │ ├── builtin.ih │ │ ├── call.c │ │ ├── data.c │ │ ├── ebaddcmd.c │ │ ├── ebenterch.c │ │ ├── ebexecmd.c │ │ ├── ebfgetsstatus.c │ │ ├── ebfilewrite.c │ │ ├── ebfindpercent.c │ │ ├── ebformattedfprintf.c │ │ ├── ebformatter.c │ │ ├── ebgetarg.c │ │ ├── ebgetcmdlen.c │ │ ├── ebgetline.c │ │ ├── ebgetnr.c │ │ ├── ebgetpid.c │ │ ├── ebnoformatting.c │ │ ├── ebreleasereg.c │ │ ├── ebsetstring.c │ │ ├── ebspawnvp.c │ │ ├── ebstringwrite.c │ │ ├── ebstrlower.c │ │ ├── ebstrupper.c │ │ ├── ebtermch.c │ │ ├── ebupdatefgets.c │ │ ├── ebwriteargument.c │ │ ├── frame │ │ ├── popreg.c │ │ └── regptr.c │ ├── cleanup.c │ ├── icm-exec.ih │ ├── icm_bootstrap │ ├── icmconf │ ├── int │ │ ├── add.c │ │ ├── assign.c │ │ ├── assignint.c │ │ ├── bool.c │ │ ├── cons.c │ │ ├── consint.c │ │ ├── copycons.c │ │ ├── destructor.c │ │ ├── int.h │ │ ├── int.ih │ │ ├── sub.c │ │ └── value.c │ ├── list │ │ ├── add.c │ │ ├── addcp.c │ │ ├── addswallowcp.c │ │ ├── assign.c │ │ ├── at.c │ │ ├── bool.c │ │ ├── compare.c │ │ ├── cons.c │ │ ├── conscharptr.c │ │ ├── conscharptrptr.c │ │ ├── conssizecharptrptr.c │ │ ├── contains.c │ │ ├── copycons.c │ │ ├── destructor.c │ │ ├── frame │ │ ├── laddtxt.c │ │ ├── lcleanup.c │ │ ├── lincsize.c │ │ ├── list.h │ │ ├── list.ih │ │ ├── listcleanup.cc │ │ ├── lnew.c │ │ ├── lremove.c │ │ ├── size.c │ │ ├── sort.c │ │ ├── sub.c │ │ ├── test │ │ │ ├── build │ │ │ └── main.c │ │ ├── unionlist.c │ │ └── unionstr.c │ ├── main.c │ ├── opcodefun │ │ ├── close.c │ │ ├── data.c │ │ ├── frame │ │ ├── oadd.c │ │ ├── oasp.c │ │ ├── oatoi.c │ │ ├── oatol.c │ │ ├── oband.c │ │ ├── obnot.c │ │ ├── obor.c │ │ ├── ocall.c │ │ ├── ocallrss.c │ │ ├── ocopyvar.c │ │ ├── odec.c │ │ ├── odiv.c │ │ ├── oeq.c │ │ ├── oexit.c │ │ ├── oframe.c │ │ ├── ogetdest.c │ │ ├── ogr.c │ │ ├── ogreq.c │ │ ├── oinc.c │ │ ├── oistrue.c │ │ ├── oitoa.c │ │ ├── ojmp.c │ │ ├── ojmpfalse.c │ │ ├── ojmptrue.c │ │ ├── omod.c │ │ ├── omul.c │ │ ├── oneq.c │ │ ├── oolder.c │ │ ├── opcodefun.h │ │ ├── opcodefun.ih │ │ ├── opopreg.c │ │ ├── opopvar.c │ │ ├── opush0.c │ │ ├── opush1.c │ │ ├── opushimm.c │ │ ├── opushreg.c │ │ ├── opushstrconst.c │ │ ├── opushvar.c │ │ ├── oret.c │ │ ├── oshl.c │ │ ├── oshr.c │ │ ├── osm.c │ │ ├── osmeq.c │ │ ├── osub.c │ │ ├── oumin.c │ │ ├── oxor.c │ │ ├── oyounger.c │ │ ├── process.c │ │ ├── setglobalvariables.c │ │ └── setinfile.c │ ├── stack │ │ ├── data.c │ │ ├── local.c │ │ ├── pop.c │ │ ├── popbp.c │ │ ├── push.c │ │ ├── pushbp.c │ │ ├── stack.h │ │ ├── stack.ih │ │ ├── stestunderflow.c │ │ └── top.c │ ├── string │ │ ├── add.c │ │ ├── assign.c │ │ ├── bool.c │ │ ├── charp.c │ │ ├── compare.c │ │ ├── cons.c │ │ ├── conscharptr.c │ │ ├── consswallowcharptr.c │ │ ├── copycons.c │ │ ├── destructor.c │ │ ├── frame │ │ ├── reduce.c │ │ ├── snew.c │ │ ├── string.h │ │ ├── string.ih │ │ ├── test │ │ │ ├── build │ │ │ └── main.c │ │ ├── trimleft.c │ │ └── trimright.c │ ├── usage.c │ ├── var │ │ ├── decshared.c │ │ ├── incshared.c │ │ ├── shared.c │ │ ├── var.h │ │ └── var.ih │ └── virtual │ │ ├── add.c │ │ ├── assign.c │ │ ├── compare.c │ │ ├── cons.c │ │ ├── copycons.c │ │ ├── data.c │ │ ├── destructor.c │ │ ├── logical.c │ │ ├── subtract.c │ │ ├── virtual.h │ │ └── virtual.ih ├── icm_bootstrap ├── icm_github ├── icm_install ├── icm_prepare ├── icmake │ ├── README.options │ ├── about.c │ ├── accessfile.c │ ├── build │ ├── cleanup.c │ ├── compile.c │ ├── dashesindex.c │ ├── data.c │ ├── execute.c │ ├── icm_bootstrap │ ├── icmake.ih │ ├── icmconf │ ├── icmdep.c │ ├── inspectflags.c │ ├── main.c │ ├── nooptions.c │ ├── optcompile.c │ ├── optexecute.c │ ├── optim.c │ ├── options.c │ ├── optpreprocess.c │ ├── opttmpbim.c │ ├── opttmpdir.c │ ├── preprocess.c │ ├── setlinks │ ├── settmpdir.c │ ├── showflags.c │ ├── spawnlp.c │ ├── testcompile.c │ ├── usage.c │ └── usefile.c ├── icmbuild │ ├── build │ ├── icm_bootstrap │ ├── icmbuild.ih │ ├── icmconf │ ├── main.c │ └── usage.c ├── iuo │ ├── bootstrapinstall │ ├── install │ └── uninstall ├── legacy │ ├── dos-msc.im │ ├── lsm.org │ │ ├── icmake.lsm │ │ └── icmakebin.lsm │ └── mail.frank ├── pp │ ├── CLASSES │ ├── build │ ├── filestack │ │ ├── data.c │ │ ├── filestack.h │ │ ├── filestack.ih │ │ ├── frame │ │ ├── pop.c │ │ ├── push.c │ │ ├── size.c │ │ └── tos.c │ ├── icm-pp.ih │ ├── icm_bootstrap │ ├── icmconf │ ├── linear │ │ ├── add.c │ │ ├── data.c │ │ ├── frame │ │ ├── lcompare.c │ │ ├── linear.h │ │ ├── linear.ih │ │ ├── lreplacedefines.c │ │ ├── lupdatedefinition.c │ │ ├── search.c │ │ ├── show.c │ │ └── undef.c │ ├── loadsymbols.c │ ├── main.c │ ├── options.c │ ├── out │ │ ├── ateof.c │ │ ├── data.c │ │ ├── frame │ │ ├── init.c │ │ ├── nl.c │ │ ├── oclose.c │ │ ├── oeof.c │ │ ├── onewlines.c │ │ ├── out.c │ │ ├── out.h │ │ ├── out.ih │ │ └── space.c │ ├── parser │ │ ├── data.c │ │ ├── frame │ │ ├── grammar │ │ ├── padddef.c │ │ ├── parse.c │ │ ├── parser.c │ │ ├── parser.h │ │ ├── parser.ih │ │ ├── pdefine.c │ │ ├── pelse.c │ │ ├── pendif.c │ │ ├── pgetimname.c │ │ ├── pifdef.c │ │ ├── pifndef.c │ │ ├── pimfile.c │ │ ├── pinspectident.c │ │ ├── pnextfile.c │ │ ├── ppushfile.c │ │ ├── pquotedname.c │ │ ├── psaveyytext.c │ │ ├── ptextline.c │ │ ├── pundef.c │ │ ├── pyyerror.c │ │ ├── tokens.h │ │ └── yyparse.c │ ├── scanner │ │ ├── ateof.c │ │ ├── data.c │ │ ├── definition.c │ │ ├── eof.c │ │ ├── frame │ │ ├── lastlinenr.c │ │ ├── length.c │ │ ├── lexer │ │ ├── lexer.c │ │ ├── linenr.c │ │ ├── pushfile.f │ │ ├── scanner.c │ │ ├── scanner.h │ │ ├── scanner.ih │ │ ├── scappenddefinition.c │ │ ├── scpopfile.f │ │ ├── scpushfile.c │ │ ├── scstartdefinition.c │ │ └── text.c │ ├── state │ │ ├── active.c │ │ ├── data.c │ │ ├── eof.c │ │ ├── frame │ │ ├── init.c │ │ ├── negate.c │ │ ├── pop.c │ │ ├── push.c │ │ ├── size.c │ │ ├── state.h │ │ ├── state.ih │ │ └── stavailable.c │ └── usage.c ├── required ├── rss │ ├── build │ ├── changebase.c │ ├── changeext.c │ ├── changepath.c │ ├── copyright.c │ ├── data.c │ ├── error.c │ ├── errorlist.c │ ├── exists.c │ ├── fatal.c │ ├── fgetz.c │ ├── findfirst.c │ ├── findnext.c │ ├── frame │ ├── getbase.c │ ├── getdext.c │ ├── getext.c │ ├── getint16.c │ ├── getopcode.c │ ├── getpath.c │ ├── getstring.c │ ├── getvar.c │ ├── hexstring.c │ ├── icm_bootstrap │ ├── icmconf │ ├── makepath.c │ ├── msg.c │ ├── nerrors.c │ ├── older.c │ ├── programname.c │ ├── readheader.c │ ├── realloc.c │ ├── rsfilefound.c │ ├── rsfilename.c │ ├── rsfindfirst.c │ ├── rsfindnext.c │ ├── rsgloberr.c │ ├── rsjoin.c │ ├── rsmakeattribute.c │ ├── rsmsg.c │ ├── rss.h │ ├── rss.ih │ ├── rssplit.c │ ├── spawnerr.c │ ├── splitpath.c │ ├── strcat.c │ ├── strdup.c │ ├── strjoin.c │ ├── trimleft.c │ ├── trimright.c │ ├── types.ih │ ├── version.c │ ├── warning.c │ └── younger.c ├── scripts │ ├── conversions │ ├── convert │ ├── icmbuild.in │ └── icmstart.in ├── un │ ├── build │ ├── data.c │ ├── dumpchar.c │ ├── dumpint.c │ ├── dumpstri.c │ ├── funadd.c │ ├── funasp.c │ ├── funatoi.c │ ├── funatol.c │ ├── funband.c │ ├── funbnot.c │ ├── funbor.c │ ├── funcall.c │ ├── funcallr.c │ ├── funcopyv.c │ ├── fundec.c │ ├── fundiv.c │ ├── funeq.c │ ├── funexit.c │ ├── funframe.c │ ├── fungr.c │ ├── fungreq.c │ ├── funinc.c │ ├── funitoa.c │ ├── funjmp.c │ ├── funjmpf.c │ ├── funjmpt.c │ ├── funmod.c │ ├── funmul.c │ ├── funneq.c │ ├── funolder.c │ ├── funpopre.c │ ├── funpopva.c │ ├── funpush0.c │ ├── funpush1.c │ ├── funpushi.c │ ├── funpushr.c │ ├── funpushs.c │ ├── funpushv.c │ ├── funret.c │ ├── funshl.c │ ├── funshr.c │ ├── funsm.c │ ├── funsmeq.c │ ├── funsub.c │ ├── funumin.c │ ├── funxor.c │ ├── funyoung.c │ ├── icm_bootstrap │ ├── icmconf │ ├── icmun.ih │ ├── main.c │ ├── printvar.c │ ├── process.c │ └── varname.c ├── usr │ └── share │ │ └── icmake │ │ ├── CLASSES │ │ ├── frame │ │ ├── icmconf │ │ ├── main.cc │ │ ├── main.ih │ │ ├── parser │ │ └── grammar │ │ ├── scanner │ │ ├── lexer │ │ └── scanner.ih │ │ ├── usage.cc │ │ └── version.cc └── where-is-what ├── manpages └── sourcetar /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # /debian/ 3 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Icmake can be used as an alternative to make(1). 2 | 3 | Icmake's repository has moved to https://gitlab.com/fbb-git/icmake 4 | and is not maintained at this location anymore. 5 | 6 | The project's web-page can be found at 7 | href="http://fbb-git.gitlab.io/icmake 8 | 9 | 10 | -------------------------------------------------------------------------------- /excluded: -------------------------------------------------------------------------------- 1 | test 2 | 3 | -------------------------------------------------------------------------------- /icmake/VERSION: -------------------------------------------------------------------------------- 1 | VERSION=9.02.07 2 | YEARS=1992-2018 3 | -------------------------------------------------------------------------------- /icmake/bootstrap/flags: -------------------------------------------------------------------------------- 1 | # sourced by the various bootstrap functions 2 | 3 | if [ ! -e ../tmp/INSTALL.sh ] ; then 4 | echo ../tmp/INSTALL.sh does not exist. Try running the icm_prepare script 5 | exit 1 6 | fi 7 | 8 | . ../tmp/INSTALL.sh 9 | 10 | if [ "${CFLAGS}" == "" ] ; then 11 | CFLAGS="-Wall -O2" 12 | fi 13 | 14 | if [ "${CC}" == "" ] ; then 15 | CC="gcc" 16 | fi 17 | -------------------------------------------------------------------------------- /icmake/comp/CLASSES: -------------------------------------------------------------------------------- 1 | util 2 | symtab 3 | -------------------------------------------------------------------------------- /icmake/comp/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./updategrammar 4 | icmbuild $1 5 | 6 | -------------------------------------------------------------------------------- /icmake/comp/global.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_GLOBAL_H_ 2 | #define INCLUDED_GLOBAL_H_ 3 | 4 | /* 5 | all global variables defined by lower level directories (classes), 6 | that must be used by upper level directories 7 | */ 8 | 9 | extern int yynerrs; /* parser */ 10 | 11 | extern int yylineno; /* scanner */ 12 | extern char *yytext; 13 | 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /icmake/comp/icm_bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . ../bootstrap/functions 4 | . ../bootstrap/flags 5 | 6 | echo Creating tmp/${LIBDIR}/icm-comp 7 | build icm-comp util symtab scanner parser 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /icmake/comp/main.ih: -------------------------------------------------------------------------------- 1 | #include "../rss/rss.h" 2 | 3 | #include "parser/parser.h" 4 | 5 | 6 | -------------------------------------------------------------------------------- /icmake/comp/parser/frame: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | void ps_ 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/args.5: -------------------------------------------------------------------------------- 1 | args: 2 | args 3 | comma 4 | err_expression 5 | { 6 | $$ = *p_multipleArgs(&$1, &$3); 7 | } 8 | | 9 | err_expression 10 | { 11 | $$ = *p_firstArg(&$1); 12 | } 13 | ; 14 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/breakok.5: -------------------------------------------------------------------------------- 1 | break_ok: 2 | { 3 | gp_breakOK++; 4 | } 5 | ; 6 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/breakstat.5: -------------------------------------------------------------------------------- 1 | break_stat: 2 | BREAK 3 | { 4 | $$ = *p_break(); 5 | } 6 | ; 7 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/closebrace.5: -------------------------------------------------------------------------------- 1 | closebrace: 2 | { 3 | gp_parse_error = err_closebrace_expected; 4 | symtab_pop(); 5 | } /* '{' for matching */ 6 | '}' 7 | ; 8 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/closepar.5: -------------------------------------------------------------------------------- 1 | closepar: 2 | { 3 | gp_parse_error = err_closepar_expected; 4 | } 5 | ')' 6 | ; 7 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/comma.5: -------------------------------------------------------------------------------- 1 | comma: 2 | { 3 | gp_parse_error = err_comma_expected; 4 | } 5 | ',' 6 | ; 7 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/compound.5: -------------------------------------------------------------------------------- 1 | compound: 2 | openbrace 3 | statements 4 | closebrace 5 | { 6 | $$ = $2; 7 | } 8 | ; 9 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/condition.5: -------------------------------------------------------------------------------- 1 | condition: 2 | err_expression 3 | | 4 | typed_condition 5 | ; 6 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/continuestat.5: -------------------------------------------------------------------------------- 1 | continue_stat: 2 | CONTINUE 3 | { 4 | $$ = *p_continue(); 5 | } 6 | ; 7 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/defvarorfun.5: -------------------------------------------------------------------------------- 1 | _voidtype: 2 | VOID 3 | { 4 | gp_varType = 0; 5 | } 6 | ; 7 | 8 | def_var_or_fun: 9 | typed_varlist 10 | semicol 11 | { 12 | gp_init = *p_catCode(&gp_init, &$1); 13 | } 14 | | 15 | type_of_var 16 | funcdef 17 | | 18 | _voidtype 19 | funcdef 20 | ; 21 | 22 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/enterid.5: -------------------------------------------------------------------------------- 1 | enterid: 2 | IDENTIFIER 3 | { 4 | p_defineVar(); /* the first n variables of a function, up to the 5 | end of the parameter list are the parameters. */ 6 | } 7 | ; 8 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/entervarid.5: -------------------------------------------------------------------------------- 1 | enter_varid: 2 | enterid 3 | { 4 | $$ = *p_fetchVar(); 5 | } 6 | ; 7 | 8 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/errexpression.5: -------------------------------------------------------------------------------- 1 | err_expression: 2 | { 3 | gp_parse_error = err_in_expression; 4 | } 5 | expression 6 | { 7 | $$ = $2; 8 | } 9 | ; 10 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/exprcode.5: -------------------------------------------------------------------------------- 1 | expr_code: 2 | err_expression 3 | { 4 | $$ = *p_expression(&$1); 5 | } 6 | ; 7 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/ifstat.5: -------------------------------------------------------------------------------- 1 | _if: 2 | IF 3 | nesting 4 | { 5 | symtab_push(); 6 | } 7 | ; 8 | 9 | _else: 10 | ELSE 11 | statement 12 | { 13 | $$ = $2; 14 | } 15 | | 16 | zeroframe 17 | ; 18 | 19 | if_stat: 20 | _if 21 | openpar 22 | condition 23 | closepar 24 | statement 25 | popdead 26 | pushdead 27 | _else 28 | popdead 29 | { 30 | $$ = *p_if(&$3, &$5, &$8); 31 | symtab_pop(); 32 | } 33 | ; 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/nesting.5: -------------------------------------------------------------------------------- 1 | nesting: 2 | pushdead 3 | { 4 | gp_nestLevel++; 5 | } 6 | ; 7 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/ok.5: -------------------------------------------------------------------------------- 1 | ok: 2 | ';' 3 | { 4 | yyerrok; 5 | } 6 | ; 7 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/openbrace.5: -------------------------------------------------------------------------------- 1 | openbrace: 2 | { 3 | gp_parse_error = err_openbrace_expected; 4 | } 5 | '{' /* } (for matching) */ 6 | { 7 | symtab_push(); 8 | } 9 | ; 10 | 11 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/openpar.5: -------------------------------------------------------------------------------- 1 | openpar: 2 | { 3 | gp_parse_error = err_openpar_expected; 4 | } 5 | '(' 6 | ; 7 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/popdead.5: -------------------------------------------------------------------------------- 1 | popdead: 2 | { 3 | p_popDead(); 4 | } 5 | ; 6 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/preamble.1: -------------------------------------------------------------------------------- 1 | %{ 2 | /* #define msg 3 | */ 4 | #include "parser.ih" 5 | %} 6 | 7 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/pushdead.5: -------------------------------------------------------------------------------- 1 | pushdead: 2 | { 3 | p_pushDead(); /* set new dead-level */ 4 | } 5 | ; 6 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/returnstat.5: -------------------------------------------------------------------------------- 1 | _return_tail: 2 | err_expression 3 | | 4 | zeroframe 5 | ; 6 | 7 | _leave: 8 | RETURN 9 | { 10 | msg("saw return"); 11 | } 12 | | 13 | EXIT 14 | ; 15 | 16 | return_stat: 17 | _leave 18 | _return_tail 19 | { 20 | $$ = *p_return($1.type, &$2); 21 | msg("SAW return stmt"); 22 | } 23 | ; 24 | 25 | 26 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/semicol.5: -------------------------------------------------------------------------------- 1 | semicol: 2 | { 3 | gp_parse_error = err_semicol_expected; 4 | } 5 | ';' 6 | ; 7 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/start.4: -------------------------------------------------------------------------------- 1 | 2 | %expect 1 3 | 4 | /* Grammar Rules */ 5 | 6 | %% 7 | 8 | input: 9 | input 10 | def_var_or_fun 11 | | 12 | def_var_or_fun 13 | ; 14 | 15 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/statement.5: -------------------------------------------------------------------------------- 1 | _stm: 2 | compound 3 | | 4 | ';' 5 | zeroframe 6 | { 7 | $$ = $2; 8 | } 9 | | 10 | expr_code 11 | semicol 12 | | 13 | while_stat 14 | | 15 | if_stat 16 | | 17 | for_stat 18 | | 19 | return_stat 20 | semicol 21 | | 22 | break_stat 23 | semicol 24 | | 25 | continue_stat 26 | semicol 27 | | 28 | error 29 | ok 30 | ; 31 | 32 | statement: 33 | _stm 34 | | 35 | typed_varlist 36 | semicol 37 | ; 38 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/statements.5: -------------------------------------------------------------------------------- 1 | statements: 2 | statements 3 | statement 4 | { 5 | $$ = *p_catStmnts(&$1, &$2); 6 | } 7 | | 8 | zeroframe 9 | ; 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/typedcondition.5: -------------------------------------------------------------------------------- 1 | typed_condition: 2 | type_of_var 3 | var_condition 4 | { 5 | $$ = $2; 6 | } 7 | ; 8 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/typedvarlist.5: -------------------------------------------------------------------------------- 1 | typed_varlist: 2 | type_of_var 3 | var_expr_list 4 | { 5 | $$ = $2; 6 | } 7 | ; 8 | 9 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/typeofvar.5: -------------------------------------------------------------------------------- 1 | _varType: 2 | INT 3 | | 4 | STRINGTYPE 5 | | 6 | LIST 7 | ; 8 | 9 | type_of_var: 10 | _varType 11 | { 12 | gp_parse_error = err_identifier_expected; 13 | gp_varType = $1.type; 14 | } 15 | ; 16 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/varcondition.5: -------------------------------------------------------------------------------- 1 | var_condition: 2 | enter_varid 3 | { 4 | p_generateCode(&$1, op_push_imm, 0); 5 | $$ = $1; 6 | } 7 | | 8 | enter_varid 9 | '=' 10 | expression 11 | { 12 | $$ = *p_assign(&$1, &$3); /* explicit initialization */ 13 | } 14 | ; 15 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/varexpr.5: -------------------------------------------------------------------------------- 1 | var_expr: 2 | enterid 3 | zeroframe /* no explicit initialization */ 4 | | 5 | enter_varid 6 | '=' 7 | expression 8 | { 9 | $$ = *p_expression(p_assign(&$1, &$3)); /* explicit initialization */ 10 | } 11 | ; 12 | 13 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/varexprlist.5: -------------------------------------------------------------------------------- 1 | var_expr_list: 2 | var_expr_list 3 | comma 4 | var_expr 5 | { 6 | $$ = *p_catCode(&$1, &$3); /* catenate variable */ 7 | /* initialization code */ 8 | } 9 | | 10 | var_expr 11 | | 12 | error 13 | ok 14 | zeroframe /* Empty stmnt */ 15 | { 16 | $$ = $3; 17 | } 18 | ; 19 | 20 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/whilestat.5: -------------------------------------------------------------------------------- 1 | _while: 2 | WHILE 3 | nesting 4 | ; 5 | 6 | while_stat: 7 | _while 8 | openpar 9 | condition 10 | closepar 11 | break_ok 12 | statement 13 | popdead 14 | { 15 | $$ = *p_while(&$3, &$6, 1); 16 | } 17 | ; 18 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/yywrap.6: -------------------------------------------------------------------------------- 1 | 2 | %% 3 | 4 | int yywrap(void) 5 | { 6 | return 1; 7 | } 8 | -------------------------------------------------------------------------------- /icmake/comp/parser/inc/zeroframe.5: -------------------------------------------------------------------------------- 1 | zeroframe: 2 | { 3 | $$ = *p_stackFrame(0); /* by default initializes a variable to 0 */ 4 | } 5 | ; 6 | -------------------------------------------------------------------------------- /icmake/comp/parser/paddpatch.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | void p_addPatch(unsigned *list, unsigned len, register unsigned value) 4 | { 5 | register unsigned idx; 6 | 7 | for (idx = 0; idx < len; idx++) 8 | list[idx] += value; 9 | } 10 | -------------------------------------------------------------------------------- /icmake/comp/parser/parser.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_PARSER_H_ 2 | #define INCLUDED_PARSER_H_ 3 | 4 | #include "../global.h" 5 | 6 | void parser(char **argv); /* call once */ 7 | int yyparse(void); /* in parse.c */ 8 | int parser_backend(); 9 | 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /icmake/comp/parser/passign.c: -------------------------------------------------------------------------------- 1 | /* 2 | A S S I G N . C 3 | */ 4 | 5 | #include "parser.ih" 6 | 7 | SemVal *p_assign(SemVal *lval, SemVal *rval) 8 | { 9 | return p_assignment(lval, rval, "="); 10 | } 11 | -------------------------------------------------------------------------------- /icmake/comp/parser/pbinop.c: -------------------------------------------------------------------------------- 1 | #define msg 2 | #include "parser.ih" 3 | 4 | void p_binOp(SemVal *lval, SemVal *rval, Opcode opcode) 5 | { 6 | p_expr2stack(lval); /* convert to code */ 7 | p_expr2stack(rval); 8 | p_catCode(lval, rval); 9 | p_generateCode(lval, opcode); /* append instruction */ 10 | set_type(lval, e_int | e_stack); /* set appropriate type */ 11 | } 12 | -------------------------------------------------------------------------------- /icmake/comp/parser/pbreakstm.c: -------------------------------------------------------------------------------- 1 | /* 2 | B R E A K S T M . C 3 | */ 4 | 5 | #include "parser.ih" 6 | 7 | static SemVal e; 8 | 9 | SemVal *p_break() 10 | { 11 | e = *p_stackFrame(0); 12 | 13 | if (!gp_breakOK) 14 | util_semantic("'break' only in 'while' or 'for' statements"); 15 | else 16 | { 17 | p_generateCode(&e, op_jmp, j_truelist); 18 | e.type = e_bool | e_stack; 19 | ++gp_dead[gp_dead_sp]; /* next code is gp_dead */ 20 | } 21 | return &e; 22 | } 23 | -------------------------------------------------------------------------------- /icmake/comp/parser/pbtoi.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | void p_bool2int(SemVal *e) 4 | { 5 | if (!test_type(e, e_bool)) /* no batchpatching needed */ 6 | return; 7 | 8 | p_patchupTrue(e, 1); 9 | e->truelen = 0; 10 | 11 | p_generateCode(e, op_push_1_jmp_end); /* truelist target */ 12 | 13 | p_patchupFalse(e, 1); 14 | e->falselen = 0; 15 | 16 | p_generateCode(e, op_push_0); /* falselist target */ 17 | 18 | set_type(e, e_int | e_stack); /* set int code type */ 19 | } 20 | -------------------------------------------------------------------------------- /icmake/comp/parser/pcatstmnts.c: -------------------------------------------------------------------------------- 1 | 2 | /* #define msg 3 | */ 4 | 5 | #include "parser.ih" 6 | 7 | SemVal *p_catStmnts(SemVal *lval, SemVal *rval) 8 | { 9 | p_patchupFalse(lval, 1); 10 | 11 | msg("lval length: %u, rval length: %u", lval->codelen, rval->codelen); 12 | 13 | if (gp_nestLevel == 0) 14 | { 15 | util_out(gp_bin, lval->code, lval->codelen); 16 | p_discard(lval); 17 | return rval; 18 | } 19 | 20 | return p_catCode(lval, rval); 21 | } 22 | -------------------------------------------------------------------------------- /icmake/comp/parser/pcheckargumenttypes.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | #include "parser.ih" 3 | 4 | void p_checkArgumentTypes(unsigned nParams, unsigned funIdx, SemVal *args) 5 | { 6 | register unsigned idx; 7 | 8 | msg("checking %d parameters", nParams); 9 | 10 | for (idx = 0; idx != nParams; ++idx, ++args) 11 | { 12 | if (symtab_funParameterType(funIdx, idx) != (args->type & e_typeMask)) 13 | util_semantic("Function `%s', argument %u: type mismatch", 14 | symtab_funName(funIdx), idx + 1); 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /icmake/comp/parser/pclearoperands.c: -------------------------------------------------------------------------------- 1 | //#include "parser.ih" 2 | // 3 | //void p_clearOperands(SemVal **lval, SemVal *rval) 4 | //{ 5 | // p_discard(rval); 6 | // p_discard(*lval); 7 | // *lval = p_stackFrame(e_null); 8 | //} 9 | -------------------------------------------------------------------------------- /icmake/comp/parser/pconflict.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | int p_conflict(SemVal *lval, SemVal *rval, Opcode opcode) 4 | { 5 | register int ret = !(lval->type & rval->type & gp_opType[opcode]); 6 | 7 | if (ret) 8 | util_semantic(gp_typeConflict, gp_opstring[opcode]); 9 | 10 | return ret; 11 | } 12 | -------------------------------------------------------------------------------- /icmake/comp/parser/pcontinue.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | static SemVal e; 4 | 5 | SemVal *p_continue() 6 | { 7 | e = *p_stackFrame(0); 8 | 9 | if (!gp_breakOK) 10 | util_semantic("'continue' only in 'while' or 'for' statements"); 11 | else 12 | { 13 | p_generateCode(&e, op_jmp, j_continuelist);/* jump to the continue dest */ 14 | 15 | e.type = e_bool | e_stack; 16 | ++gp_dead[gp_dead_sp]; /* next code is gp_dead */ 17 | } 18 | return &e; 19 | } 20 | -------------------------------------------------------------------------------- /icmake/comp/parser/pdefinevar.c: -------------------------------------------------------------------------------- 1 | 2 | #define msgx 3 | 4 | #include "parser.ih" 5 | 6 | void p_defineVar() 7 | { 8 | VarIndex ret = symtab_defineVar(gp_varType); 9 | 10 | if (ret.idx == -1) 11 | util_semantic("%s p_multiply defined", util_string()); 12 | } 13 | -------------------------------------------------------------------------------- /icmake/comp/parser/pdiscard.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | void p_discard(SemVal *e) 4 | { 5 | if (e->falselen) 6 | free(e->falselist); 7 | if (e->truelen) 8 | free(e->truelist); 9 | if (e->code) 10 | free(e->code); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/comp/parser/pexpr.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | SemVal *p_expression(SemVal *e) 4 | { 5 | p_bool2int(e); /* convert boolean to i */ 6 | 7 | if (gp_lastOp == op_copy_var) 8 | p_popVar(e); 9 | else if 10 | ( 11 | test_type(e, e_stack) 12 | && 13 | !test_type(e, e_pre_inc_dec | e_post_inc_dec) 14 | ) 15 | p_generateCode(e, op_asp, 1); 16 | 17 | return (e); 18 | } 19 | -------------------------------------------------------------------------------- /icmake/comp/parser/pfirstarg.c: -------------------------------------------------------------------------------- 1 | /* 2 | F I R S T A R G . C 3 | */ 4 | 5 | #include "parser.ih" 6 | 7 | static SemVal 8 | arr; 9 | 10 | SemVal *p_firstArg(SemVal *e) 11 | { 12 | p_expr2stack(e); /* argument is code now */ 13 | /* code points to SemVal */ 14 | arr.code = rss_realloc(NULL, sizeof(SemVal)); 15 | 16 | *(SemVal *)arr.code = *e; /* arr->code contains e */ 17 | arr.type = 1; /* type field: # of active e's */ 18 | return (&arr); 19 | } 20 | -------------------------------------------------------------------------------- /icmake/comp/parser/pfor.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | SemVal *p_for(SemVal *init, SemVal *cond, SemVal *inc, SemVal *stmnt) 4 | { 5 | unsigned codelen = stmnt->codelen; 6 | 7 | p_patchupContinue(stmnt, codelen); 8 | 9 | p_catStmnts(stmnt, inc); /* catenate inc to stmt */ 10 | 11 | 12 | p_while(cond, stmnt, 0); /* create while-stmnt */ 13 | 14 | symtab_pop(); 15 | 16 | return p_catCode(init, cond); /* return final code */ 17 | } 18 | -------------------------------------------------------------------------------- /icmake/comp/parser/pforceexpr2bool.c: -------------------------------------------------------------------------------- 1 | /* Force conversion of expression to boolean expression */ 2 | 3 | #include "parser.ih" 4 | 5 | void p_forceExpr2Bool(SemVal *e) 6 | { 7 | if (test_type(e, e_bool)) 8 | return; /* done if boolean aloready */ 9 | 10 | p_expr2stack(e); /* convert to code unless bool */ 11 | p_generateCode (e, op_jmp_true); 12 | p_generateCode (e, op_jmp, j_falselist); 13 | set_type(e, e_stack | e_bool); 14 | } 15 | -------------------------------------------------------------------------------- /icmake/comp/parser/pfunctionidx.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | int p_functionIdx() 4 | { 5 | register int idx = symtab_findFun(); 6 | 7 | if (idx == -1) 8 | util_semantic("Function '%s' not defined", util_string()); 9 | 10 | return idx; 11 | } 12 | -------------------------------------------------------------------------------- /icmake/comp/parser/plaststmnt.c: -------------------------------------------------------------------------------- 1 | /*#define msg 2 | */ 3 | 4 | #include "parser.ih" 5 | 6 | void p_lastStmnt(SemVal *lval) 7 | { 8 | p_patchupFalse(lval, 1); 9 | 10 | util_out(gp_bin, lval->code, lval->codelen); 11 | msg("write statement code of %u bytes", lval->codelen); 12 | 13 | p_discard(lval); 14 | } 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /icmake/comp/parser/plcast.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | SemVal *p_lCast(SemVal *e) 4 | { 5 | if (test_type(e, e_int)) /* (int)list not ok */ 6 | { 7 | util_semantic(gp_illegalCast); 8 | p_discard(e); 9 | set_type(e, e_list | e_var); 10 | } 11 | else if (test_type(e, e_str)) /* (string)int ok */ 12 | { 13 | p_expr2stack(e); /* convert to code */ 14 | p_generateCode(e, op_atol); 15 | set_type(e, e_stack | e_list); 16 | } 17 | return (e); 18 | } 19 | -------------------------------------------------------------------------------- /icmake/comp/parser/pnullframe3.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | SemVal *p_nullFrame3(SemVal *e1, SemVal *e2, SemVal *e3) 4 | { 5 | if (e3) 6 | p_discard(e3); 7 | 8 | p_discard(e2); 9 | p_discard(e1); 10 | *e1 = *p_stackFrame(e_null); 11 | return e1; 12 | } 13 | -------------------------------------------------------------------------------- /icmake/comp/parser/pold.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | SemVal *p_old(SemVal *lval, SemVal *rval) 4 | { 5 | if (p_testBinOp(op_older, lval, rval)) 6 | return p_nullFrame(lval, rval); /* test for correct types */ 7 | 8 | p_expr2stack(lval); /* convert to code */ 9 | p_expr2stack(rval); 10 | 11 | p_binOp(lval, rval, op_older); 12 | 13 | return lval; /* return new expression */ 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /icmake/comp/parser/ppatchcontinue.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | void p_patchContinue(SemVal *e) 4 | { 5 | e->continuelist = rss_realloc(e->continuelist, /* expand the continuelist */ 6 | (e->continuelen + 1) * sizeof(unsigned)); 7 | 8 | /* room for the jump-backpatch */ 9 | e->code = rss_realloc(e->code, e->codelen += sizeof(int16_t)); 10 | /* store jumpstart location */ 11 | 12 | e->continuelist[e->continuelen++] = e->codelen; 13 | } 14 | -------------------------------------------------------------------------------- /icmake/comp/parser/ppatchfalse.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | void p_patchFalse(SemVal *e) 4 | { 5 | e->falselist = rss_realloc(e->falselist, /* expand the falselist */ 6 | (e->falselen + 1) * sizeof(unsigned)); 7 | 8 | /* room for the jump-backpatch */ 9 | e->code = rss_realloc(e->code, e->codelen += sizeof(int16_t)); 10 | e->falselist[e->falselen++] = e->codelen; /* store jumpstart location */ 11 | } 12 | -------------------------------------------------------------------------------- /icmake/comp/parser/ppatchtrue.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | void p_patchTrue(SemVal *e) 4 | { /* expand the truelist */ 5 | e->truelist = rss_realloc(e->truelist, (e->truelen + 1) * sizeof(unsigned)); 6 | 7 | /* room for the jump-backpatch */ 8 | e->code = rss_realloc(e->code, e->codelen += sizeof(int16_t)); 9 | e->truelist[e->truelen++] = e->codelen; /* store jumpstart location */ 10 | } 11 | -------------------------------------------------------------------------------- /icmake/comp/parser/ppatchupcontinue.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | void p_patchupContinue(SemVal *e, int pos) 4 | { 5 | p_patchup(e->code, e->codelen, e->continuelist, e->continuelen, pos); 6 | e->continuelen = 0; 7 | } 8 | -------------------------------------------------------------------------------- /icmake/comp/parser/ppatchupfalse.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | void p_patchupFalse(SemVal *e, int pos) 4 | { 5 | p_patchup(e->code, e->codelen, e->falselist, e->falselen, pos); 6 | e->falselen = 0; 7 | } 8 | -------------------------------------------------------------------------------- /icmake/comp/parser/ppatchuptrue.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | void p_patchupTrue(SemVal *e, int pos) 4 | { 5 | p_patchup(e->code, e->codelen, e->truelist, e->truelen, pos); 6 | e->truelen = 0; 7 | } 8 | -------------------------------------------------------------------------------- /icmake/comp/parser/ppopdead.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | void p_popDead() /* dead_sp: lastused, dead[0] = 0 */ 4 | { 5 | if (gp_dead_sp) /* anything to pop ? */ 6 | --gp_dead_sp; /* then reduce SP */ 7 | } 8 | -------------------------------------------------------------------------------- /icmake/comp/parser/ppopvar.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | void p_popVar(SemVal *e) 4 | { 5 | e->code[e->codelen - sizeof(int16_t) - sizeof(int8_t)] = op_pop_var; 6 | gp_lastOp = op_pop_var; 7 | } 8 | -------------------------------------------------------------------------------- /icmake/comp/parser/ppushdead.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | static unsigned size = 1; 4 | 5 | void p_pushDead() /* dead_sp: lastused, dead[0] = 0 */ 6 | { 7 | if (++gp_dead_sp >= size) /* too few elements ? then 5 more */ 8 | gp_dead = rss_realloc(gp_dead, (size += 5) * sizeof(unsigned)); 9 | 10 | gp_dead[gp_dead_sp] = gp_dead[gp_dead_sp - 1]; /* copy former element */ 11 | } 12 | -------------------------------------------------------------------------------- /icmake/comp/parser/prmjmpzero.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | unsigned p_rmJmpZero(register unsigned codelen, unsigned *list, 4 | register unsigned listlen) 5 | { 6 | return 7 | listlen && (list[listlen - 1] == codelen) ? 8 | (sizeof(int8_t) + sizeof(int16_t)) 9 | : 10 | 0 11 | ; 12 | } 13 | -------------------------------------------------------------------------------- /icmake/comp/parser/pstackframe.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | static SemVal frame; 4 | 5 | SemVal *p_stackFrame(ExprType type) 6 | { 7 | frame.type = type; 8 | 9 | switch ((int)type) 10 | { 11 | case e_int | e_const: 12 | frame.evalue = atoi(util_string()); 13 | break; 14 | 15 | case e_str | e_const: 16 | frame.evalue = p_findString(gp_stringbuf); 17 | break; 18 | 19 | default: 20 | frame.evalue = 0; 21 | } 22 | 23 | return &frame; 24 | } 25 | -------------------------------------------------------------------------------- /icmake/comp/parser/ptestbinop.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | int p_testBinOp(Opcode opcode, SemVal *lval, SemVal *rval) 4 | { 5 | if (! p_trySIconvert(lval, rval)) 6 | p_trySIconvert(rval, lval); 7 | 8 | return p_testOperand(lval, opcode) /* returns 0 if no errors */ 9 | || 10 | p_testOperand(rval, opcode); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/comp/parser/ptestoperand.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | int p_testOperand(SemVal *e, Opcode opcode) 4 | { 5 | register int ret = !test_type(e, gp_opType[opcode]); /* 0: type error */ 6 | 7 | if (ret) 8 | util_semantic(gp_illegalType, gp_opstring[opcode]); 9 | 10 | return ret; 11 | } 12 | -------------------------------------------------------------------------------- /icmake/comp/parser/pyoung.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | #include "parser.ih" 3 | 4 | SemVal *p_young(SemVal *lval, SemVal *rval) 5 | { 6 | msg("start"); 7 | if (p_testBinOp(op_younger, lval, rval)) 8 | return p_nullFrame(lval, rval); /* test for correct types */ 9 | 10 | p_expr2stack(lval); /* convert to code */ 11 | p_expr2stack(rval); 12 | 13 | p_binOp(lval, rval, op_younger); 14 | 15 | return lval; /* return new expression */ 16 | } 17 | -------------------------------------------------------------------------------- /icmake/comp/parser/pzeroargs.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | static SemVal e; 4 | 5 | SemVal *p_zeroArgs(ExprType type) 6 | { 7 | e = *p_stackFrame(0); /* reinitialize e */ 8 | p_callRss(&e, type); 9 | 10 | return &e; 11 | } 12 | -------------------------------------------------------------------------------- /icmake/comp/scanner/data.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | char gs_char[2]; 4 | char *gs_filenames; 5 | char *gs_savedText; 6 | unsigned gs_savedLineNr; 7 | 8 | unsigned gs_fileSp = N_FILES; 9 | FileStack gs_fileStack[N_FILES]; 10 | 11 | 12 | -------------------------------------------------------------------------------- /icmake/comp/scanner/filenames.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | char const *scanner_filenames() 4 | { 5 | return gs_filenames; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/scanner/frame: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | void sc_ 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/comp/scanner/savedlinenr.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | unsigned scanner_savedLineNr() 4 | { 5 | return gs_savedLineNr; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/scanner/savedtext.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | char const *scanner_savedText() 4 | { 5 | return gs_savedText; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/scanner/scanner.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | void scanner(char const *infile) 4 | { 5 | if (!(yyin = fopen(infile, "rt"))) /* open text file for parsing */ 6 | rss_fatal(0, 0, "%s Can't read `%s'", infile); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /icmake/comp/scanner/scanner.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_SCANNER_H_ 2 | #define INCLUDED_SCANNER_H_ 3 | 4 | #include 5 | 6 | void scanner(char const *infile); 7 | int yylex(); 8 | char const *scanner_filenames(); 9 | 10 | char const *scanner_savedText(void); 11 | unsigned scanner_savedLineNr(void); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /icmake/comp/scanner/scappend.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | void sc_append() 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/scanner/sccharconst.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | void sc_charConst() 4 | { 5 | gs_char[0] = yytext[1]; 6 | util_setString(gs_char); 7 | } 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /icmake/comp/scanner/scescapedchar.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | static char stdEscape[] = 4 | {'n', 't', 'v', 'b', 'r', 'f', 'a', '\'', '"', '\\'}; 5 | 6 | static char escapedChar[] = 7 | {'\n', '\t', '\v', '\b', '\r', '\f', '\a', '\'', '"', '\\'}; 8 | 9 | char const *sc_escapedChar(int ch) 10 | { 11 | char *cp = strchr(stdEscape, ch); 12 | 13 | gs_char[0] = cp == NULL ? ch : escapedChar[cp - stdEscape]; 14 | 15 | return gs_char; 16 | } 17 | -------------------------------------------------------------------------------- /icmake/comp/scanner/scpopfile.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | void sc_popFile() 4 | { 5 | if (gs_fileSp == N_FILES - 1) 6 | rss_fatal(util_sourceName(), yylineno, "include file stack empty"); 7 | free(gs_fileStack[gs_fileSp].fname); 8 | yylineno = gs_fileStack[gs_fileSp].former_linenr - 1; 9 | gs_fileSp++; /* free stack element */ 10 | 11 | util_setSourceName(gs_fileStack[gs_fileSp].fname); 12 | } 13 | -------------------------------------------------------------------------------- /icmake/comp/scanner/scsaveinfo.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | void sc_saveInfo() 4 | { 5 | gs_savedLineNr = yylineno; 6 | free(gs_savedText); 7 | gs_savedText = rss_strdup(yytext); 8 | } 9 | -------------------------------------------------------------------------------- /icmake/comp/scanner/scscan.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | #include "scanner.ih" 3 | 4 | char const *sc_scan(char const *fmt, char const *text) 5 | { 6 | msg("saw %s", text); 7 | 8 | unsigned value = 0; 9 | sscanf(text, fmt, &value); 10 | 11 | value %= 0x100; 12 | gs_char[0] = value % 0x100; 13 | return gs_char; 14 | } 15 | -------------------------------------------------------------------------------- /icmake/comp/scanner/scsetlinenr.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | void sc_setLineNr() 4 | { 5 | yylineno = atoi(yytext + 1); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/data.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | FunInfoTab gs_functions; /* symbol table for functions */ 4 | 5 | VarTab *gs_compareTable; /* set by st_findVar for st_compareVars */ 6 | 7 | VarRef gs_vars; 8 | 9 | -------------------------------------------------------------------------------- /icmake/comp/symtab/findfun.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | int symtab_findFun() /* util_string() holds the name of an existing */ 4 | { /* function, returns -1 if not */ 5 | 6 | size_t nmemb = gs_functions.nFunctions; 7 | void *ret = lfind(util_string(), gs_functions.info, 8 | &nmemb, sizeof(FunInfo), 9 | st_findFun); 10 | 11 | return ret == NULL ? -1 : (FunInfo *)ret - gs_functions.info; 12 | } 13 | -------------------------------------------------------------------------------- /icmake/comp/symtab/findvar.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | VarIndex symtab_findVar() /* util_string() holds the name of an existing */ 4 | { /* variable, returns -1 if not found */ 5 | VarIndex ret; 6 | 7 | for (unsigned nesting = gs_vars.nLevels; nesting--; ) 8 | { 9 | int idx = st_findVar(nesting); 10 | 11 | if (idx != -1) 12 | { 13 | ret.idx = idx; 14 | ret.type = nesting > 0; 15 | 16 | return ret; 17 | } 18 | } 19 | ret.idx = -1; 20 | return ret; 21 | } 22 | -------------------------------------------------------------------------------- /icmake/comp/symtab/frame: -------------------------------------------------------------------------------- 1 | /* #define msg 2 | */ 3 | #include "symtab.ih" 4 | 5 | void st_ 6 | { 7 | } 8 | -------------------------------------------------------------------------------- /icmake/comp/symtab/funaddress.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | uint16_t symtab_funAddress(unsigned funIdx) 4 | { 5 | return gs_functions.info[funIdx].address; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/funname.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | char const *symtab_funName(unsigned funIdx) 4 | { 5 | return gs_functions.info[funIdx].name; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/funnparams.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | unsigned symtab_fun_nParams(unsigned funIdx) 4 | { 5 | return gs_functions.info[funIdx].nParams; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/funparametertype.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | ExprType symtab_funParameterType(unsigned funIdx, unsigned paramIdx) 4 | { 5 | /* &typeMask removes e_reg */ 6 | return gs_functions.info[funIdx].paramType[paramIdx] & e_typeMask; 7 | } 8 | -------------------------------------------------------------------------------- /icmake/comp/symtab/funtype.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | ExprType symtab_funType(unsigned funIdx) 4 | { 5 | return gs_functions.info[funIdx].returnType; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/lastfunction.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | unsigned symtab_lastFunction() /* idx of last defined function */ 4 | { 5 | return gs_functions.nFunctions - 1; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/localtype.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | ExprType symtab_localType(unsigned idx) 4 | { 5 | return gs_vars.varTab[1].info[idx + gs_vars.nParams].type & e_typeMask; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/newparam.c: -------------------------------------------------------------------------------- 1 | //#include "symtab.ih" 2 | // 3 | //void symtab_newParam() 4 | //{ 5 | // ++gs_vars.nParams; 6 | //fprintf(stderr, "inc. nParams to %u\n", gs_vars.nParams); 7 | //} 8 | -------------------------------------------------------------------------------- /icmake/comp/symtab/nglobals.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | unsigned symtab_nGlobals() 4 | { 5 | return gs_vars.varTab->nVars; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/nlocals.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | unsigned symtab_nLocals() 4 | { 5 | return gs_vars.varTab[1].nVars - gs_vars.nParams; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/nparams.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | unsigned symtab_nParams() 4 | { 5 | return gs_vars.nParams; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/pop.c: -------------------------------------------------------------------------------- 1 | /*#define msg 2 | */ 3 | 4 | #include "symtab.ih" 5 | 6 | void symtab_pop() 7 | { 8 | free(gs_vars.varIndices[--gs_vars.nLevels].index); 9 | 10 | msg("returning to symtab offset: %u", gs_vars.nLevels); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/comp/symtab/push.c: -------------------------------------------------------------------------------- 1 | /*#define msg 2 | */ 3 | 4 | #include "symtab.ih" 5 | 6 | void symtab_push() 7 | { 8 | msg("next symtab offset: %u", gs_vars.nLevels); 9 | 10 | if (gs_vars.nLevels == gs_vars.capacity) 11 | gs_vars.varIndices = rss_realloc(gs_vars.varIndices, 12 | (gs_vars.capacity += capacityInc) 13 | * sizeof(VarIndices)); 14 | 15 | memset(gs_vars.varIndices + gs_vars.nLevels++, 0, sizeof(VarIndices)); 16 | } 17 | -------------------------------------------------------------------------------- /icmake/comp/symtab/staddvar.c: -------------------------------------------------------------------------------- 1 | 2 | /* #define msg 3 | */ 4 | 5 | #include "symtab.ih" 6 | 7 | VarIndex st_addVar(ExprType type) 8 | { 9 | VarInfo *vi; 10 | unsigned idx = st_nextVarIdx(&vi); 11 | 12 | vi->name = rss_strdup(util_string()); /* set the name of the var */ 13 | vi->type = type | e_var; /* set the type of the var */ 14 | vi->value = 0; 15 | 16 | VarIndex ret = {idx, st_nestingOffset() > 0}; 17 | return ret; 18 | } 19 | -------------------------------------------------------------------------------- /icmake/comp/symtab/stcomparevars.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | int st_compareVars(void const *key, void const *idxPtr) 4 | { 5 | return strcmp((char const *)key, 6 | gs_compareTable->info[*(unsigned const *)idxPtr].name); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /icmake/comp/symtab/stdeletevars.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | void st_deleteVars(VarTab *varTab) 4 | { 5 | for (VarInfo *info = varTab->info; varTab->nVars--; ++info) 6 | free(info->name); 7 | 8 | varTab->nVars = 0; /* 0 variables left at variable table *varTab */ 9 | } 10 | -------------------------------------------------------------------------------- /icmake/comp/symtab/stfindfun.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | int st_findFun(void const *key, void const *funInfo) 4 | { 5 | return strcmp((char const *)key, ((FunInfo *)funInfo)->name); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/stlastfuninfo.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | FunInfo *st_lastFunInfo() 4 | { 5 | return gs_functions.info + gs_functions.nFunctions - 1; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/stnestingoffset.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | unsigned st_nestingOffset() 4 | { 5 | return gs_vars.nLevels - 1; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/stnewidxptr.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | unsigned *st_newIdxPtr() /* pointer to the next available index[] */ 4 | { /* element at the current nestinglevel */ 5 | VarIndices *indices = st_topLevel(); 6 | 7 | if (indices->nVars == indices->capacity) 8 | indices->index = rss_realloc(indices->index, 9 | (indices->capacity += capacityInc) * 10 | sizeof(unsigned)); 11 | 12 | return indices->index + indices->nVars++; 13 | } 14 | -------------------------------------------------------------------------------- /icmake/comp/symtab/stnewvaridx.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | unsigned st_newVarIdx() /* return the index of a (unitialized) var. record */ 4 | { 5 | VarTab *vt = st_varTab(st_nestingOffset()); 6 | 7 | if (vt->nVars == vt->capacity) 8 | vt->info = rss_realloc(vt->info, (vt->capacity += capacityInc) 9 | * sizeof(VarInfo)); 10 | 11 | return vt->nVars++; 12 | } 13 | -------------------------------------------------------------------------------- /icmake/comp/symtab/stnextfunidx.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | unsigned st_nextFunIdx() /* idx of an uninitialized record of a */ 4 | { /* function */ 5 | if (gs_functions.nFunctions == gs_functions.capacity) 6 | gs_functions.info = rss_realloc(gs_functions.info, 7 | (gs_functions.capacity += capacityInc) 8 | * sizeof(FunInfo)); 9 | return gs_functions.nFunctions++; 10 | } 11 | -------------------------------------------------------------------------------- /icmake/comp/symtab/stparamtype.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | ExprType st_paramType(unsigned idx) 4 | { 5 | return gs_vars.varTab[1].info[idx].type & e_typeMask; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/sttoplevel.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | VarIndices *st_topLevel() 4 | { 5 | return gs_vars.varIndices + gs_vars.nLevels - 1; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/stvartab.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | VarTab *st_varTab(unsigned nesting) 4 | { 5 | return gs_vars.varTab + (nesting > 0); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/vartype.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | ExprType symtab_varType(VarIndex vt) 4 | { 5 | return gs_vars.varTab[vt.type].info[vt.idx].type; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/writefunaddress.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | void symtab_writeFunAddress(FILE *bin, unsigned funIdx) 4 | { 5 | util_out(bin, &gs_functions.info[funIdx].address, sizeof(uint16_t)); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/symtab/writeglobals.c: -------------------------------------------------------------------------------- 1 | #include "symtab.ih" 2 | 3 | /* 4 | Global variables are written like this: 5 | 1st byte: their type 6 | */ 7 | 8 | void symtab_writeGlobals(FILE *bin) 9 | { 10 | for (VarInfo *begin = gs_vars.varTab->info, 11 | *end = begin + gs_vars.varTab->nVars; 12 | begin != end; 13 | ++begin) 14 | { 15 | char type = (char)begin->type & ~e_var; 16 | util_out(bin, &type, sizeof(char)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /icmake/comp/updategrammar: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd parser/inc 4 | 5 | files=`ls -X | grep -v 'build\|OBS'` 6 | 7 | for file in $files 8 | do 9 | if [ $file -nt "../grammar" ] ; then 10 | cat $files > ../grammar 11 | exit 0 12 | fi 13 | done 14 | 15 | 16 | -------------------------------------------------------------------------------- /icmake/comp/updateparser: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./updategrammar || exit 1 4 | 5 | cd parser 6 | 7 | bison --defines=tokens.h -o parse.c grammar 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /icmake/comp/updatescanner: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd scanner 4 | flex -o lexer.c lexer || exit 1 5 | 6 | echo generated new scanner 7 | -------------------------------------------------------------------------------- /icmake/comp/util/catstring.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | void util_catString(char const *txt) 4 | { 5 | gu_lexstring = rss_strcat(gu_lexstring, txt); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/util/charconst.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | void util_charConst() 4 | { 5 | yytext[0] = yytext[1]; 6 | yytext[1] = 0; 7 | util_setString(yytext); 8 | } 9 | -------------------------------------------------------------------------------- /icmake/comp/util/data.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | char *gu_sourceName; 4 | char *gu_lexstring; 5 | 6 | -------------------------------------------------------------------------------- /icmake/comp/util/frame: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | void util_ 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/comp/util/out.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | void util_out(FILE *bin, void const *source, unsigned size) 4 | { 5 | if 6 | ( 7 | size 8 | && 9 | !fwrite(source, size * sizeof(int8_t), 1, bin) 10 | ) 11 | rss_fatal(0, 0, "can't write the bim-file"); 12 | } 13 | -------------------------------------------------------------------------------- /icmake/comp/util/printf.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | int util_printf(char const *fmt, ...) 4 | { 5 | va_list marker; 6 | 7 | va_start(marker, fmt); 8 | 9 | char buffer[80]; 10 | 11 | int ret = vsnprintf(buffer, 80, fmt, marker); 12 | 13 | util_setString(buffer); 14 | 15 | return ret; 16 | } 17 | -------------------------------------------------------------------------------- /icmake/comp/util/scan.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | void util_scan(char const *fmt, char const *text) 4 | { 5 | unsigned value; 6 | sscanf(text, fmt, &value); 7 | 8 | util_printf("%u", value); 9 | } 10 | -------------------------------------------------------------------------------- /icmake/comp/util/semantic.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | #include "util.ih" 3 | 4 | void util_semantic(char const *fmt, ...) 5 | { 6 | va_list args; 7 | 8 | va_start(args, fmt); 9 | 10 | rss_errorList(gu_sourceName, yylineno, fmt, args); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/comp/util/setsourcename.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | #include "util.ih" 3 | 4 | void util_setSourceName(char const *txt) 5 | { 6 | free(gu_sourceName); 7 | gu_sourceName = rss_strdup(txt); 8 | } 9 | -------------------------------------------------------------------------------- /icmake/comp/util/setstring.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | void util_setString(char const *txt) 4 | { 5 | free(gu_lexstring); 6 | gu_lexstring = rss_strdup(txt); 7 | } 8 | -------------------------------------------------------------------------------- /icmake/comp/util/sourcename.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | char const *util_sourceName() 4 | { 5 | return gu_sourceName; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/util/string.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | char const *util_string() 4 | { 5 | return gu_lexstring; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/comp/util/util.ih: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | 3 | #include "../../rss/rss.h" 4 | 5 | #include 6 | #include 7 | 8 | #include "../global.h" 9 | 10 | extern char *gu_sourceName; 11 | extern char *gu_lexstring; 12 | 13 | 14 | -------------------------------------------------------------------------------- /icmake/dep/CLASSES: -------------------------------------------------------------------------------- 1 | vector 2 | util 3 | options 4 | dependencies 5 | process 6 | -------------------------------------------------------------------------------- /icmake/dep/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | icmbuild $1 4 | 5 | -------------------------------------------------------------------------------- /icmake/dep/dependencies/dcheckuseall.c: -------------------------------------------------------------------------------- 1 | #include "dependencies.ih" 2 | 3 | void dCheckUseAll(int idx) 4 | { 5 | if (sdep.d_useAll == NULL) 6 | return; 7 | 8 | if (rss_exists(sdep.d_useAll)) 9 | sdep.d_useAllExists[idx] = 1; 10 | } 11 | -------------------------------------------------------------------------------- /icmake/dep/dependencies/depdependent.c: -------------------------------------------------------------------------------- 1 | #include "dependencies.ih" 2 | 3 | int const *depDependent(int idx) 4 | { 5 | return sdep.d_dependent[idx]; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/dep/dependencies/depdir.c: -------------------------------------------------------------------------------- 1 | #include "dependencies.ih" 2 | 3 | char const *depDir(int idx) 4 | { 5 | return at(sdep.d_dirNames, idx); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/dep/dependencies/dependencies.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_DEPENDENCIES_ 2 | #define INCLUDED_DEPENDENCIES_ 3 | 4 | 5 | void DependenciesCons(); 6 | 7 | int depSize(); 8 | char const *depDir(int idx); 9 | char const *depGch(int idx); 10 | char const *depUseAll(int idx); 11 | int const *depDependent(int idx); 12 | int const *depUseAllExists(); 13 | int *depGchIndicator(); 14 | 15 | #endif 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /icmake/dep/dependencies/depgch.c: -------------------------------------------------------------------------------- 1 | #include "dependencies.ih" 2 | 3 | char const *depGch(int idx) 4 | { 5 | return at(sdep.d_gchPaths, idx); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/dep/dependencies/depgchindicator.c: -------------------------------------------------------------------------------- 1 | #include "dependencies.ih" 2 | 3 | int *depGchIndicator() 4 | { 5 | return sdep.d_gchIndicator; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/dep/dependencies/depsize.c: -------------------------------------------------------------------------------- 1 | #include "dependencies.ih" 2 | 3 | int depSize() 4 | { 5 | return sdep.d_size; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/dep/dependencies/depuseall.c: -------------------------------------------------------------------------------- 1 | #include "dependencies.ih" 2 | 3 | char const *depUseAll(int idx) 4 | { 5 | return at(sdep.d_useAllPaths, idx); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/dep/dependencies/depuseallexists.c: -------------------------------------------------------------------------------- 1 | #include "dependencies.ih" 2 | 3 | int const *depUseAllExists() 4 | { 5 | return sdep.d_useAllExists; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/dep/dependencies/dihfile.c: -------------------------------------------------------------------------------- 1 | #include "dependencies.ih" 2 | 3 | char const *dIhFile(int idx) 4 | { 5 | return strcatN(2, depDir(idx), optIH()); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/dep/dependencies/dimplieddependencies.c: -------------------------------------------------------------------------------- 1 | #include "dependencies.ih" 2 | 3 | void dImpliedDependencies(int **data, int size) 4 | { 5 | int indicator[size]; 6 | 7 | for (int row = 0; row != size; ++row) 8 | { 9 | memset(indicator, 0, size * sizeof(int)); 10 | dClosure(indicator, row, data, size); 11 | memcpy(data[row], indicator, size * sizeof(int)); 12 | } 13 | 14 | for (int idx = 0; idx != size; ++idx) 15 | data[idx][idx] = 0; 16 | } 17 | -------------------------------------------------------------------------------- /icmake/dep/dependencies/dinitable.c: -------------------------------------------------------------------------------- 1 | #include "dependencies.ih" 2 | 3 | void dIniTable() 4 | { 5 | int size = sdep.d_size; 6 | 7 | sdep.d_dependent = initTable(size); 8 | } 9 | -------------------------------------------------------------------------------- /icmake/dep/dependencies/dtranspose.c: -------------------------------------------------------------------------------- 1 | #include "dependencies.ih" 2 | 3 | void dTranspose(int **dest, int **src, int size) 4 | { 5 | for (int row = 0; row != size; ++row) 6 | for (int col = 0; col != size; ++col) 7 | dest[col][row] = src[row][col]; 8 | } 9 | -------------------------------------------------------------------------------- /icmake/dep/dependencies/frame: -------------------------------------------------------------------------------- 1 | #include "dependencies.ih" 2 | 3 | Dependencies:: 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/dep/dependencies/inspectcomp.cc: -------------------------------------------------------------------------------- 1 | #include "dependencies.ih" 2 | 3 | void inspectComp(Dependencies *dep 4 | { 5 | dep->inspect; 6 | dep->nInspect = 0 7 | 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /icmake/dep/frame: -------------------------------------------------------------------------------- 1 | #include "main.ih" 2 | -------------------------------------------------------------------------------- /icmake/dep/icm_bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . ../bootstrap/functions 4 | . ../bootstrap/flags 5 | 6 | echo Creating tmp/${LIBDIR}/icm-dep 7 | build icm-dep vector util options dependencies process 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /icmake/dep/icmconf: -------------------------------------------------------------------------------- 1 | #define CLS 2 | #define MAIN "main.c" 3 | #define SOURCES "*.c" 4 | #define OBJ_EXT ".o" 5 | #define SHAREDREQ "" 6 | #define TMP_DIR "tmp" 7 | #define USE_ALL "a" 8 | #define USE_ECHO ON 9 | #define CXX "gcc" 10 | #define CXXFLAGS " -O2 -fdiagnostics-color=never " 11 | #define REFRESH 12 | #define LDFLAGS "" 13 | #define ADD_LIBRARIES "icrss" 14 | #define ADD_LIBRARY_PATHS "/home/frank/src/icmake/rss/tmp" 15 | #define DEFCOM "program" 16 | -------------------------------------------------------------------------------- /icmake/dep/main.c: -------------------------------------------------------------------------------- 1 | #include "main.ih" 2 | 3 | int main(int argc, char **argv) 4 | { 5 | UtilInit(); 6 | 7 | OptionsCons(argc, argv); 8 | 9 | DependenciesCons(); 10 | 11 | ProcessCons(); 12 | processActions(); 13 | } 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /icmake/dep/main.ih: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "../rss/rss.h" 4 | 5 | #include "util/util.h" 6 | #include "options/options.h" 7 | #include "dependencies/dependencies.h" 8 | #include "process/process.h" 9 | 10 | extern char version[]; 11 | extern char years[]; 12 | extern char author[]; 13 | 14 | -------------------------------------------------------------------------------- /icmake/dep/options/frame: -------------------------------------------------------------------------------- 1 | #include "options.ih" 2 | 3 | void 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/dep/options/optclasses.c: -------------------------------------------------------------------------------- 1 | #include "options.ih" 2 | 3 | char const *optClasses() 4 | { 5 | return sopts.d_classes; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /icmake/dep/options/optgch.c: -------------------------------------------------------------------------------- 1 | #include "options.ih" 2 | 3 | int optGch() 4 | { 5 | return sopts.d_gch; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/dep/options/optgo.c: -------------------------------------------------------------------------------- 1 | #include "options.ih" 2 | 3 | int optGo() 4 | { 5 | return sopts.d_go; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/dep/options/optih.c: -------------------------------------------------------------------------------- 1 | #include "options.ih" 2 | 3 | char const *optIH() 4 | { 5 | return sopts.d_ih; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/dep/options/options.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_OPTIONS_ 2 | #define INCLUDED_OPTIONS_ 3 | 4 | enum 5 | { 6 | DRY, 7 | GO, 8 | NO_GCH, 9 | GCH, 10 | UNSPECIFIED, 11 | }; 12 | 13 | void OptionsCons(int argc, char **argv); 14 | 15 | char const *optClasses(); 16 | char const *optParser(); 17 | char const *optScanner(); 18 | char const *optMainih(); 19 | char const *optIH(); 20 | char const *optUseAll(); 21 | int optVerbose(); 22 | int optGch(); 23 | int optGo(); 24 | void optMsg(int requiredLevel, char const *fmt, ...); 25 | 26 | #endif 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /icmake/dep/options/optmainih.c: -------------------------------------------------------------------------------- 1 | #include "options.ih" 2 | 3 | char const *optMainih() 4 | { 5 | return sopts.d_mainih; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/dep/options/optmsg.c: -------------------------------------------------------------------------------- 1 | #include "options.ih" 2 | 3 | void optMsg(int requiredLevel, char const *fmt, ...) 4 | { 5 | if (sopts.d_verbose < requiredLevel) 6 | return; 7 | 8 | va_list args; 9 | va_start(args, fmt); 10 | vprintf(fmt, args); 11 | va_end(args); 12 | 13 | putchar('\n'); 14 | } 15 | -------------------------------------------------------------------------------- /icmake/dep/options/optparser.c: -------------------------------------------------------------------------------- 1 | #include "options.ih" 2 | 3 | char const *optParser() 4 | { 5 | return sopts.d_parser; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /icmake/dep/options/optscanner.c: -------------------------------------------------------------------------------- 1 | #include "options.ih" 2 | 3 | char const *optScanner() 4 | { 5 | return sopts.d_scanner; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/dep/options/optuseall.c: -------------------------------------------------------------------------------- 1 | #include "options.ih" 2 | 3 | char const *optUseAll() 4 | { 5 | return sopts.d_use_all; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/dep/options/optverbose.c: -------------------------------------------------------------------------------- 1 | #include "options.ih" 2 | 3 | int optVerbose() 4 | { 5 | return sopts.d_verbose; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/dep/process/pgch.c: -------------------------------------------------------------------------------- 1 | #include "process.ih" 2 | 3 | void pGch() 4 | { 5 | int *indicator = depGchIndicator(); 6 | 7 | int *toRm = initRow(sproc.d_size); 8 | 9 | for (int idx = 0; idx != sproc.d_size; ++idx) 10 | { 11 | if (indicator[idx]) 12 | pInspectGch(toRm, idx); 13 | } 14 | 15 | for (int idx = 0; idx != sproc.d_size; ++idx) 16 | { 17 | if (toRm[idx]) 18 | pUnlinkGch(idx); // try to unlink the gch file 19 | } 20 | 21 | free(toRm); 22 | } 23 | -------------------------------------------------------------------------------- /icmake/dep/process/pinspectgch.c: -------------------------------------------------------------------------------- 1 | #include "process.ih" 2 | 3 | void pInspectGch(int *toRm, int idx) 4 | { 5 | if (!toRm[idx]) 6 | optMsg(4, "(re)compile %s", depGch(idx)); 7 | 8 | int const *dep = depDependent(idx); // get classes depending on idx 9 | toRm[idx] = 1; 10 | 11 | for (idx = 0; idx != sproc.d_size; ++idx) 12 | { 13 | if (!dep[idx] || toRm[idx]) 14 | continue; 15 | 16 | optMsg(4, "(re)compile %s", depGch(idx)); 17 | toRm[idx] = 1; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /icmake/dep/process/pinspectuseall.c: -------------------------------------------------------------------------------- 1 | #include "process.ih" 2 | 3 | void pInspectUseAll(int *toTouch, int classIdx) 4 | { 5 | int const *dep = depDependent(classIdx); 6 | 7 | for (int idx = 0; idx != sproc.d_size; ++idx) 8 | { 9 | if (!dep[idx] || toTouch[idx] == 1) 10 | continue; 11 | 12 | char const *useAll = depUseAll(idx); 13 | 14 | if ( !rss_exists(useAll) ) 15 | { 16 | optMsg(1, "touch %s", useAll); 17 | toTouch[idx] = 1; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /icmake/dep/process/process.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_PROCESS_ 2 | #define INCLUDED_PROCESS_ 3 | 4 | void ProcessCons(); 5 | void processActions(); 6 | 7 | #endif 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /icmake/dep/process/process1.c: -------------------------------------------------------------------------------- 1 | #include "process.ih" 2 | 3 | Process sproc; 4 | 5 | void ProcessCons() 6 | { 7 | sproc.d_size = depSize(); 8 | sproc.d_go = optGo(); 9 | sproc.d_gch = optGch(); 10 | sproc.d_use_all = optUseAll(); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/dep/process/processactions.c: -------------------------------------------------------------------------------- 1 | #include "process.ih" 2 | 3 | void processActions() 4 | { 5 | if (sproc.d_use_all) 6 | pUseAll(); 7 | 8 | if (sproc.d_gch == GCH) 9 | pGch(); 10 | } 11 | -------------------------------------------------------------------------------- /icmake/dep/process/ptouch.c: -------------------------------------------------------------------------------- 1 | #include "process.ih" 2 | 3 | void pTouch(char const *path) 4 | { 5 | if (sproc.d_go == GO) 6 | fclose(openFile(path, "w")); 7 | 8 | optMsg(1, "touch %s", path); 9 | } 10 | -------------------------------------------------------------------------------- /icmake/dep/process/punlinkgch.c: -------------------------------------------------------------------------------- 1 | #include "process.ih" 2 | 3 | void pUnlinkGch(int idx) 4 | { 5 | char const *path = depGch(idx); 6 | 7 | if (!rss_exists(path)) 8 | return; 9 | 10 | optMsg(1, "unlink(%s)", path); 11 | if (sproc.d_go == GO) 12 | unlink(path); 13 | } 14 | -------------------------------------------------------------------------------- /icmake/dep/process/puseall.c: -------------------------------------------------------------------------------- 1 | #include "process.ih" 2 | 3 | void pUseAll() 4 | { 5 | int const *exists = depUseAllExists(); 6 | 7 | int *toTouch = initRow(sproc.d_size); 8 | 9 | for (int idx = 0; idx != sproc.d_size; ++idx) 10 | { 11 | if (exists[idx]) 12 | pInspectUseAll(toTouch, idx); 13 | } 14 | 15 | for (int idx = 0; idx != sproc.d_size; ++idx) 16 | { 17 | if (toTouch[idx]) 18 | pTouch(depUseAll(idx)); 19 | } 20 | 21 | free(toTouch); 22 | } 23 | -------------------------------------------------------------------------------- /icmake/dep/util/data.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | int s_cwd; 4 | Vector s_vector; 5 | -------------------------------------------------------------------------------- /icmake/dep/util/freetable.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | void freeTable(int **table, int size) 4 | { 5 | for (int idx = 0; idx != size; ++idx) 6 | free(table[idx]); 7 | 8 | free(table); 9 | } 10 | -------------------------------------------------------------------------------- /icmake/dep/util/getline.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | char *getLine(FILE *in) 4 | { 5 | char buffer[100]; 6 | 7 | char *ret = 0; 8 | 9 | while (fgets(buffer, 100, in) != NULL) 10 | { 11 | int len = strlen(buffer); 12 | int stop = buffer[len - 1] == '\n'; 13 | if (stop) 14 | buffer[len - 1] = 0; 15 | 16 | ret = rss_strcat(ret, buffer); 17 | if (stop) 18 | return ret; 19 | } 20 | 21 | free(ret); 22 | return NULL; 23 | } 24 | -------------------------------------------------------------------------------- /icmake/dep/util/initrow.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | int *initRow(int size) 4 | { 5 | return memset(rss_realloc(0, size * sizeof(int)), 0, size * sizeof(int)); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/dep/util/inittable.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | int **initTable(int size) 4 | { 5 | int **table = rss_realloc(0, size * sizeof(int *)); 6 | 7 | for (int idx = 0; idx != size; ++idx) 8 | { 9 | table[idx] = initRow(size); 10 | 11 | memset(table[idx] = rss_realloc(0, size * sizeof(int)), 12 | 0, size * sizeof(int)); 13 | table[idx][idx] = 1; // indicate dependent on itself; 14 | } // used by closure 15 | 16 | return table; 17 | } 18 | -------------------------------------------------------------------------------- /icmake/dep/util/openfile.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | FILE *openFile(char const *name, char const *mode) 4 | { 5 | FILE *ret = fopen(name, mode); 6 | 7 | if (ret == NULL) 8 | { 9 | printf("can't %s `%s'\n", 10 | strcmp(mode, "r") == 0 ? "read" : "write", 11 | name); 12 | exit(1); 13 | } 14 | 15 | return ret; 16 | } 17 | -------------------------------------------------------------------------------- /icmake/dep/util/regcomp.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | void regComp(regex_t *regex, char const *pattern) 4 | { 5 | int regOut = regcomp(regex, pattern, REG_EXTENDED); 6 | 7 | if (regOut != 0) 8 | { 9 | char buffer[100]; 10 | regerror(regOut, regex, buffer, 100); 11 | exit(1); 12 | } 13 | } 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /icmake/dep/util/strcatn.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | static char sPath[MAX_PATHLEN]; 4 | 5 | char const *strcatN(int count, ...) 6 | { 7 | va_list args; 8 | va_start(args, count); 9 | 10 | sPath[0] = 0; 11 | 12 | for (; count--; ) 13 | strcat(sPath, va_arg(args, char const *)); 14 | 15 | va_end(args); 16 | 17 | return sPath; 18 | } 19 | -------------------------------------------------------------------------------- /icmake/dep/util/tocwd.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | void toCwd() 4 | { 5 | if (fchdir(s_cwd) != 0) 6 | { 7 | printf("can't return to the initial directory\n"); 8 | exit(1); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /icmake/dep/util/trychdir.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | void tryChdir(char const *subdir) 4 | { 5 | if (chdir(subdir) != 0) // change to requested dir 6 | { 7 | printf("can't cd to `%s'\n", subdir); 8 | exit(1); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /icmake/dep/util/util.ih: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "../../rss/rss.h" 9 | #include "../util/util.h" 10 | 11 | extern int s_cwd; 12 | extern Vector s_vector; 13 | -------------------------------------------------------------------------------- /icmake/dep/util/utilinit.c: -------------------------------------------------------------------------------- 1 | #include "util.ih" 2 | 3 | void UtilInit() 4 | { 5 | s_cwd = dirfd(opendir(".")); 6 | resize(&s_vector, 5); 7 | } 8 | -------------------------------------------------------------------------------- /icmake/dep/vector/add.c: -------------------------------------------------------------------------------- 1 | #include "vector.ih" 2 | 3 | void add(Vector *vector, char const *txt) 4 | { 5 | if (find(vector, txt) != -1) 6 | return; 7 | 8 | vector->txt = rss_realloc(vector->txt, 9 | (vector->size + 1) * sizeof(char *)); 10 | vector->txt[vector->size++] = rss_strdup(txt); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/dep/vector/assign.c: -------------------------------------------------------------------------------- 1 | #include "vector.ih" 2 | 3 | void assign(Vector *vector, int idx, char const *txt) 4 | { 5 | // printf("ASSIGN: %s, old = %p\n", txt, vector->txt[idx]); 6 | 7 | free(vector->txt[idx]); 8 | vector->txt[idx] = rss_strdup(txt); 9 | } 10 | -------------------------------------------------------------------------------- /icmake/dep/vector/erase.c: -------------------------------------------------------------------------------- 1 | #include "vector.ih" 2 | 3 | void erase(Vector *vector, int idx) 4 | { 5 | free(vector->txt[idx]); 6 | vector->txt[idx] = NULL; 7 | } 8 | -------------------------------------------------------------------------------- /icmake/dep/vector/find.c: -------------------------------------------------------------------------------- 1 | #include "vector.ih" 2 | 3 | int find(Vector *vector, char const *target) 4 | { 5 | for (int idx = 0, end = vector->size; idx != end; ++idx) 6 | { 7 | if (strcmp(vector->txt[idx], target) == 0) 8 | return idx; 9 | } 10 | return -1; 11 | } 12 | -------------------------------------------------------------------------------- /icmake/dep/vector/frame: -------------------------------------------------------------------------------- 1 | #include "vector.ih" 2 | 3 | void vector(Vector *vector) 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/dep/vector/vector.ih: -------------------------------------------------------------------------------- 1 | #include "vector.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "../../rss/rss.h" 7 | 8 | -------------------------------------------------------------------------------- /icmake/dep/vector/vector1.c: -------------------------------------------------------------------------------- 1 | #include "vector.ih" 2 | 3 | Vector *VectorCons() 4 | { 5 | Vector *ret = rss_realloc(0, sizeof(Vector)); 6 | memset(ret, 0, sizeof(Vector)); 7 | return ret; 8 | } 9 | -------------------------------------------------------------------------------- /icmake/dep/vector/vectordestructor.c: -------------------------------------------------------------------------------- 1 | #include "vector.ih" 2 | 3 | void VectorDestructor(Vector *vector) 4 | { 5 | for (int idx = vector->size; idx--; ) 6 | free(vector->txt[idx]); 7 | } 8 | -------------------------------------------------------------------------------- /icmake/dep/vector/vectorreplacen.c: -------------------------------------------------------------------------------- 1 | #include "vector.ih" 2 | 3 | void replaceN(Vector *vector, int idx, char const *txt, int size) 4 | { 5 | free(vector->txt[idx]); 6 | char *cp = vector->txt[idx] = rss_realloc(0, size + 1); 7 | memcpy(cp, txt, size); 8 | cp[size] = 0; 9 | } 10 | -------------------------------------------------------------------------------- /icmake/doc/manpage/trailer.inc: -------------------------------------------------------------------------------- 1 | manpagesection(COPYRIGHT) 2 | This is free software, distributed under the terms of the 3 | GNU General Public License (GPL). 4 | 5 | manpageauthor() 6 | Frank B. Brokken (bf(f.b.brokken@rug.nl)). 7 | 8 | -------------------------------------------------------------------------------- /icmake/examples/7.00/backtick.im: -------------------------------------------------------------------------------- 1 | void main(int argc, list argv) 2 | { 3 | string cmd = "ls"; 4 | printf(`cmd`); 5 | exit(0); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/examples/7.00/define.im: -------------------------------------------------------------------------------- 1 | #define SUBST "substituted" 2 | #define LINE "This is " ${SUBST} " as one line\n" 3 | 4 | void main(int argc, list argv) 5 | { 6 | printf(LINE); 7 | 8 | exit(0); 9 | } 10 | -------------------------------------------------------------------------------- /icmake/examples/7.00/getenv.im: -------------------------------------------------------------------------------- 1 | void main(int argc, list argv) 2 | { 3 | list term = getenv("TERM"); 4 | 5 | printf(element(0, term), ": ", element(1, term), "\n"); 6 | exit(0); 7 | } 8 | -------------------------------------------------------------------------------- /icmake/examples/7.00/ifdef.im: -------------------------------------------------------------------------------- 1 | //#define X 2 | #define Y 3 | 4 | void main(int argc, list argv) 5 | { 6 | #ifdef X 7 | printf("X, "); 8 | #ifdef Y 9 | printf("Y"); 10 | #else 11 | printf("NON-Y"); 12 | #endif 13 | #else 14 | printf("NON-X, "); 15 | #ifdef Y 16 | printf("Y"); 17 | #else 18 | printf("NON-Y"); 19 | #endif 20 | #endif 21 | 22 | printf("\n"); 23 | 24 | exit(0); 25 | } 26 | -------------------------------------------------------------------------------- /icmake/examples/7.00/index.im: -------------------------------------------------------------------------------- 1 | void main(int argc, list argv) 2 | { 3 | list lst = strtok("aap noot mies", " "); 4 | int idx; 5 | 6 | for (idx = listlen(lst); idx--; ) 7 | printf(lst[idx][idx], "\n"); 8 | 9 | exit(0); 10 | } 11 | -------------------------------------------------------------------------------- /icmake/examples/7.00/strfind.im: -------------------------------------------------------------------------------- 1 | void main(int argc, list argv) 2 | { 3 | if (argc < 3) 4 | { 5 | printf("Argc = ", argc, 6 | ": provide needle (arg1) and haystack (arg2)\n"); 7 | exit(1); 8 | } 9 | 10 | printf(element(1, argv), ": `", element(2, argv), "' at ", 11 | strfind(element(1, argv), element(2, argv)), "\n"); 12 | 13 | exit(0); 14 | } 15 | -------------------------------------------------------------------------------- /icmake/examples/7.00/strlwr.im: -------------------------------------------------------------------------------- 1 | void main(int argc, list argv) 2 | { 3 | string line; 4 | 5 | if (argc == 1) 6 | { 7 | printf("provide string to be changed to lowercase\n"); 8 | exit(1); 9 | } 10 | 11 | line = element(1, argv); 12 | 13 | printf(line, ": ", strlwr(line), "\n"); 14 | 15 | exit(0); 16 | } 17 | -------------------------------------------------------------------------------- /icmake/examples/7.00/substr.im: -------------------------------------------------------------------------------- 1 | void main(int argc, list argv) 2 | { 3 | if (argc < 4) 4 | { 5 | printf("Argc = ", argc, 6 | ": provide string (arg1), offset (arg2) and count (arg3)\n"); 7 | exit(1); 8 | } 9 | 10 | printf(element(1, argv), ": from ", element(2, argv), " over ", 11 | element(3, argv), " chars: ", 12 | substr(element(1, argv), (int)element(2, argv), 13 | (int)element(3, argv)), "\n"); 14 | 15 | exit(0); 16 | } 17 | -------------------------------------------------------------------------------- /icmake/examples/8.00/strformat.im: -------------------------------------------------------------------------------- 1 | #!/usr/bin/icmake -qi 2 | int main(int argc, list argv) 3 | { 4 | int i; 5 | string str; 6 | 7 | for (i = 0 ; i != listlen(argv); ++i) 8 | { 9 | if (strlen(argv[i]) != 0) 10 | str += strformat("arg %1 is '%2'\n", i + 1, argv[i]); 11 | } 12 | printf("%1", str); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /icmake/examples/defines: -------------------------------------------------------------------------------- 1 | #!/usr/bin/icmake -t. 2 | 3 | #define FIRST "This text" 4 | #define SECOND "will be printed, starting with: " ${FIRST} 5 | 6 | #define TEXT ${FIRST} ${SECOND} "${UNCHANGED}\n" 7 | 8 | #define BASE /usr/local 9 | // #define BIN "${BASE}/bin" 10 | 11 | int main() 12 | { 13 | printf(TEXT); 14 | printf(BIN "\n"); 15 | } 16 | -------------------------------------------------------------------------------- /icmake/examples/initialization: -------------------------------------------------------------------------------- 1 | #!/usr/bin/icmake -t. 2 | 3 | 4 | int main() 5 | { 6 | int one; // = 5; 7 | string a, b; 8 | 9 | a = "initialization"; 10 | b = "initialization"; 11 | 12 | if (a older b) 13 | printf(one, "\n"); 14 | } 15 | -------------------------------------------------------------------------------- /icmake/exec/aux/abnormal.c: -------------------------------------------------------------------------------- 1 | /* 2 | This function issues an error with the string {\em ''Abnormal 3 | termination.''} as message. The {\em error()} function thereupon raises 4 | the {\em error\_occurred} flag. 5 | 6 | This function is attached to abnormal termination by the {\em signal()} 7 | function. 8 | */ 9 | 10 | #include "aux.ih" 11 | 12 | void aux_abnormal(int sig, int subcode) 13 | { 14 | tcsetattr(STDIN_FILENO, TCSAFLUSH, &ga_termios); 15 | 16 | rss_fatal(0, 0, "Abnormal termination."); 17 | } 18 | -------------------------------------------------------------------------------- /icmake/exec/aux/aux.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_AUX_H_ 2 | #define INCLUDED_AUX_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | extern struct termios ga_termios; 9 | 10 | void aux_abnormal(int sig, int subcode); 11 | void aux_cleanup(); 12 | char **aux_testRmBim(int *argcp, char **argv); 13 | void aux_unlinkBim(void); 14 | 15 | char const *aux_offset(); /* returns 4 char. hexstring of offset */ 16 | void aux_set(unsigned offset); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /icmake/exec/aux/aux.ih: -------------------------------------------------------------------------------- 1 | #include "aux.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "../../rss/rss.h" 7 | 8 | extern char *ga_bimname; 9 | extern unsigned ga_offset; 10 | 11 | 12 | -------------------------------------------------------------------------------- /icmake/exec/aux/data.c: -------------------------------------------------------------------------------- 1 | #include "aux.ih" 2 | 3 | char *ga_bimname; 4 | unsigned ga_offset; 5 | struct termios ga_termios; 6 | 7 | -------------------------------------------------------------------------------- /icmake/exec/aux/frame: -------------------------------------------------------------------------------- 1 | #include "aux.ih" 2 | 3 | void a_ 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/exec/aux/offset.c: -------------------------------------------------------------------------------- 1 | #include "aux.ih" 2 | 3 | char const *aux_offset() 4 | { 5 | return rss_hexString(ga_offset, 4); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/aux/set.c: -------------------------------------------------------------------------------- 1 | #include "aux.ih" 2 | 3 | void aux_set(unsigned offset) 4 | { 5 | ga_offset = offset; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/aux/testrmbim.c: -------------------------------------------------------------------------------- 1 | #include "aux.ih" 2 | 3 | char **aux_testRmBim(int *argcPtr, char **argv) 4 | { 5 | if (strcmp(argv[1], "-t") == 0) /* -t option found */ 6 | { 7 | argv[1] = argv[0]; /* remove the -t argument */ 8 | ++argv; 9 | --*argcPtr; 10 | ga_bimname = argv[1]; /* define temporary name */ 11 | } 12 | 13 | return argv; 14 | } 15 | -------------------------------------------------------------------------------- /icmake/exec/aux/unlinkbim.c: -------------------------------------------------------------------------------- 1 | #include "aux.ih" 2 | 3 | void aux_unlinkBim() 4 | { 5 | if (ga_bimname) 6 | unlink(ga_bimname); 7 | } 8 | -------------------------------------------------------------------------------- /icmake/exec/bootstrap: -------------------------------------------------------------------------------- 1 | echo Creating icm-exec 2 | 3 | gcc -O2 -g -Wall -DHAVE_GLOB -c *.c 4 | 5 | mkdir -p tmp/bin 6 | 7 | NR=0 8 | for x in auks var virtual int list string stack opcodefun builtin 9 | do 10 | cd $x 11 | gcc -O2 -g -Wall -DHAVE_GLOB -c *.c || exit 1 12 | cd .. 13 | done 14 | 15 | gcc -o tmp/bin/icm-exec$1 *.o */*.o ../rss/libicrss.a 16 | 17 | rm *.o */*.o 18 | -------------------------------------------------------------------------------- /icmake/exec/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | icmbuild $1 4 | -------------------------------------------------------------------------------- /icmake/exec/builtin/basciiint.c: -------------------------------------------------------------------------------- 1 | /* 2 | This function is called when a call to the built-in function {\em 3 | ascii} is to be processed. The function represents the opcode {\em 4 | op\_ascii\_int}. The last pushed {\em e\_int} is converted to a 5 | string. 6 | */ 7 | 8 | #include "builtin.ih" 9 | 10 | void b_asciiInt() 11 | { 12 | intcons_int(eb_releaseReg(), *string_charp(stack_top())); 13 | } 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bchangebase.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | void b_changeBase() 4 | { 5 | char *cp = rss_changeBase( 6 | string_charp(stack_top()), 7 | string_charp(stack_top() - 1) 8 | ); 9 | 10 | stringcons_charPtr(eb_releaseReg(), cp); 11 | free(cp); 12 | } 13 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bchangeextension.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | void b_changeExtension() 4 | { 5 | char *cp = rss_changeExt(string_charp(stack_top()), 6 | string_charp(stack_top() - 1)); 7 | 8 | stringcons_charPtr(eb_releaseReg(), cp); 9 | free(cp); 10 | } 11 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bchangepath.c: -------------------------------------------------------------------------------- 1 | /* 2 | The last pushed string is taken as a file name. The pathname is 3 | converted to the one but last pushed string. A new {\em e\_str} 4 | variable is created holding the new string and is returned via {\em 5 | gb_reg}. 6 | */ 7 | 8 | #include "builtin.ih" 9 | 10 | void b_changePath() 11 | { 12 | char *cp = rss_changePath(string_charp(stack_top()), 13 | string_charp(stack_top() - 1)); 14 | 15 | stringcons_charPtr(eb_releaseReg(), cp); 16 | free(cp); 17 | } 18 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bdotextension.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | void b_dotExtension() 4 | { 5 | stringcons_charPtr( 6 | eb_releaseReg(), 7 | rss_getDext(string_charp(stack_top())) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /icmake/exec/builtin/becho.c: -------------------------------------------------------------------------------- 1 | /* 2 | \funcref{fun\_builtin_echo}{void fun\_builtin_echo ()} 3 | {} 4 | {} 5 | {} 6 | {} 7 | {funbuiltin_echo.c} 8 | { 9 | 10 | This function is b_executed when an {\em op\_builtin_echo} opcode is encountered. 11 | The global variable {\em b_echo} is set to the {\em intValue} value of 12 | the last pushed variable. 13 | 14 | } 15 | */ 16 | 17 | #include "builtin.ih" 18 | 19 | void b_echo() 20 | { 21 | gb_echo = int_value(stack_top()); 22 | } 23 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bempty.c: -------------------------------------------------------------------------------- 1 | void b_empty (void) 2 | {} 3 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bexists.c: -------------------------------------------------------------------------------- 1 | /* 2 | Function {\em fun\_builtin_exists()} checks if a file with the name of the 3 | last pushed string b_exists. If so, {\em reg.intValue} is set to 1. 4 | Else, the return register indicates 0. 5 | */ 6 | 7 | /*#define msg 8 | */ 9 | 10 | #include "builtin.ih" 11 | 12 | void b_exists() 13 | { 14 | intcons_int(eb_releaseReg(), rss_exists(string_charp(stack_top()))); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bextension.c: -------------------------------------------------------------------------------- 1 | /* 2 | The last pushed string is taken as a file name. The extension is 3 | returned. 4 | */ 5 | 6 | #include "builtin.ih" 7 | 8 | void b_extension() 9 | { 10 | stringcons_charPtr(eb_releaseReg(), 11 | rss_getExt(string_charp(stack_top()))); 12 | } 13 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bgetbase.c: -------------------------------------------------------------------------------- 1 | /* 2 | The last pushed string is taken as a file name. The base name is 3 | returned. 4 | */ 5 | 6 | #include "builtin.ih" 7 | 8 | void b_getBase () 9 | { 10 | stringcons_charPtr( 11 | eb_releaseReg(), 12 | rss_getBase(string_charp(stack_top())) 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bgetch.c: -------------------------------------------------------------------------------- 1 | /* 2 | This function reads in one key and returns it in the {\em reg} return 3 | register as an {\em e\_str} value. 4 | */ 5 | 6 | #include "builtin.ih" 7 | #include "../string/string.h" 8 | 9 | static char buf[2]; 10 | 11 | void b_getCh() 12 | { 13 | buf[0] = eb_termCh(); 14 | 15 | stringcons_charPtr(eb_releaseReg(), buf); 16 | } 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bgetenv.c: -------------------------------------------------------------------------------- 1 | /* 2 | */ 3 | 4 | #include "builtin.ih" 5 | 6 | void b_getEnv() 7 | { 8 | char *env = getenv(string_charp(stack_top())); 9 | 10 | listcons(eb_releaseReg()); 11 | 12 | if (!env) 13 | { 14 | list_add_charPtr(&gb_reg, "0"); 15 | list_add_charPtr(&gb_reg, ""); 16 | } 17 | else 18 | { 19 | list_add_charPtr(&gb_reg, "1"); 20 | list_add_charPtr(&gb_reg, env); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /icmake/exec/builtin/blistfind.c: -------------------------------------------------------------------------------- 1 | /* 2 | This function returns the first index of an element in the lhs list which 3 | is equal to either the rhs string 4 | -1 is returned if such an element was not found. 5 | */ 6 | 7 | #include "builtin.ih" 8 | 9 | void b_listFind(void) 10 | { 11 | Variable *target = stack_top() - 1; 12 | 13 | intcons_int( 14 | eb_releaseReg(), 15 | (int)list_contains(stack_top(), string_charp(target)) 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /icmake/exec/builtin/blistlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | This function determines the size of the last pushed list variable and 3 | sets {\em reg.intValue} to this size. 4 | */ 5 | 6 | #include "builtin.ih" 7 | 8 | void b_listlen() 9 | { 10 | Variable *base = stack_top(); 11 | 12 | intcons_int( 13 | eb_releaseReg(), 14 | var_type(base) == e_str ? 15 | (int)strlen(string_charp(base)) 16 | : 17 | (int)list_size(base) 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /icmake/exec/builtin/blistunion.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | /* 4 | Returns the set-union of the lhs list and the rhs list or string 5 | */ 6 | 7 | void b_listUnion() 8 | { 9 | Variable *source = stack_top() - 1; 10 | 11 | listcons(eb_releaseReg()); 12 | list_unionList(&gb_reg, stack_top()); 13 | 14 | if (var_type(source) == e_str) 15 | list_unionStr(&gb_reg, string_charp(source)); 16 | else 17 | list_unionList(&gb_reg, source); 18 | } 19 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bpath.c: -------------------------------------------------------------------------------- 1 | /* 2 | The last pushed string is taken as a file name. The path is 3 | returned. 4 | */ 5 | 6 | #include "builtin.ih" 7 | 8 | void b_path() 9 | { 10 | stringcons_charPtr(eb_releaseReg(), 11 | rss_getPath(string_charp(stack_top()))); 12 | } 13 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | This function prints the arguments to a {\em printf()} statement, 3 | pushed onto the stack previously. The number of arguments to printf is 4 | the last pushed value. 5 | */ 6 | 7 | /* #define msg 8 | */ 9 | 10 | #include "builtin.ih" 11 | 12 | void b_printf(void) 13 | { 14 | intcons_int(eb_releaseReg(), eb_formattedFprintf(stdout, TO_STDOUT)); 15 | } 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bstrchr.c: -------------------------------------------------------------------------------- 1 | /* 2 | Function fun_builtin_strChr()} returns the first index in a string 3 | haystack where a character in the b_subString needle was found. 4 | If not found, -1 is returned. 5 | */ 6 | 7 | #include "builtin.ih" 8 | 9 | void b_strChr() 10 | { 11 | char const *haystack = string_charp(stack_top()); 12 | char const *ret = strpbrk(haystack, string_charp(stack_top() - 1)); 13 | 14 | intcons_int(eb_releaseReg(), ret ? ret - haystack : -1); 15 | } 16 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bstrfind.c: -------------------------------------------------------------------------------- 1 | /* 2 | Function {\em fun\_builtin_strFind()} returns the first index in a string 3 | haystack where a b_subString needle was found. If not found, -1 is 4 | returned. 5 | */ 6 | 7 | #include "builtin.ih" 8 | 9 | void b_strFind() 10 | { 11 | char const *haystack = string_charp(stack_top()); 12 | char const *ret = strstr(haystack, string_charp(stack_top() - 1)); 13 | 14 | intcons_int(eb_releaseReg(), ret ? ret - haystack : -1); 15 | } 16 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bstrlength.c: -------------------------------------------------------------------------------- 1 | /* 2 | Function {\em fun\_strlen()} returns the length of a string 3 | */ 4 | 5 | #include "builtin.ih" 6 | 7 | void b_strLength() 8 | { 9 | intcons_int(eb_releaseReg(), (int)strlen(string_charp(stack_top()))); 10 | } 11 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bstrlower.c: -------------------------------------------------------------------------------- 1 | /* 2 | Function {\em fun\_strlwr()} returns lower-case transformed string 3 | } 4 | */ 5 | 6 | #include "builtin.ih" 7 | 8 | void b_strLower() 9 | { 10 | char *cp = eb_strLower(rss_strdup(string_charp(stack_top()))); 11 | 12 | stringcons_charPtr(eb_releaseReg(), cp); 13 | 14 | free(cp); 15 | } 16 | -------------------------------------------------------------------------------- /icmake/exec/builtin/bstrupper.c: -------------------------------------------------------------------------------- 1 | /* 2 | Function {\em fun\_strupr()} returns lower-case transformed string 3 | } 4 | */ 5 | 6 | #include "builtin.ih" 7 | 8 | void b_strUpper() 9 | { 10 | char *cp = eb_strUpper(rss_strdup(string_charp(stack_top()))); 11 | 12 | stringcons_charPtr(eb_releaseReg(), cp); 13 | 14 | free(cp); 15 | } 16 | -------------------------------------------------------------------------------- /icmake/exec/builtin/btrim.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | void b_trim() 4 | { 5 | String str; 6 | stringcons(&str); 7 | 8 | string_trimRight(&str, stack_top()); 9 | string_trimLeft(eb_releaseReg(), &str); 10 | 11 | stringDestructor(&str); 12 | } 13 | -------------------------------------------------------------------------------- /icmake/exec/builtin/btrimleft.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | void b_trimLeft() 4 | { 5 | string_trimLeft(eb_releaseReg(), stack_top()); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/builtin/btrimright.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | void b_trimRight() 4 | { 5 | string_trimRight(eb_releaseReg(), stack_top()); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/builtin/builtin.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | void builtin() 4 | { 5 | if (!getcwd(gb_orgDir, MAX_PATHLEN)) 6 | rss_fatal(0, 0, "getcwd($s) fails"); /* its absolute pathname */ 7 | 8 | gb_argHead = rss_strdup(""); 9 | gb_argTail = rss_strdup(""); 10 | gb_cmdHead = rss_strdup(""); 11 | gb_cmdTail = rss_strdup(""); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /icmake/exec/builtin/builtin.h: -------------------------------------------------------------------------------- 1 | #ifndef _INCLUDED_BUILTIN_H_ 2 | #define _INCLUDED_BUILTIN_H_ 3 | 4 | #include "../../rss/rss.h" 5 | 6 | void builtin(void); /* prepare initial data, call only once */ 7 | void builtin_call(unsigned funIdx); 8 | void builtin_popReg(void); 9 | 10 | Variable const *builtin_regPtr(); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /icmake/exec/builtin/call.c: -------------------------------------------------------------------------------- 1 | /* #define msg 2 | */ 3 | 4 | #include "builtin.ih" 5 | 6 | void builtin_call(unsigned funIdx) 7 | { 8 | msg("called for function 0x%x", funIdx); 9 | 10 | gb_pBuiltinFun[funIdx](); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/exec/builtin/ebenterch.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | /* 4 | enter the first of a series of characters, terminated by \n. The first 5 | char may be a \n 6 | */ 7 | 8 | int eb_enterCh() 9 | { 10 | int ch = getchar(); 11 | if (ch != '\n') 12 | { 13 | while (getchar() != '\n') 14 | ; 15 | } 16 | return ch; 17 | } 18 | -------------------------------------------------------------------------------- /icmake/exec/builtin/ebfgetsstatus.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | void eb_fgetsStatus(char const *status) 4 | { 5 | list_add_charPtr(&gb_reg, ""); 6 | list_add_charPtr(&gb_reg, ""); 7 | list_add_charPtr(&gb_reg, status); 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /icmake/exec/builtin/ebfilewrite.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | void eb_fileWrite(void *dest, char const *begin, char const *end) 4 | { 5 | fwrite(begin, 1, end - begin, (FILE *)dest); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /icmake/exec/builtin/ebformattedfprintf.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "builtin.ih" 4 | 5 | unsigned eb_formattedFprintf(FILE *out, FormatDest formatDest) 6 | { 7 | gb_pDestWrite = eb_fileWrite; /* write to file or string: 8 | here: to file */ 9 | 10 | return eb_formatter(out, formatDest); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /icmake/exec/builtin/ebgetnr.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | unsigned eb_getNr(char **ptr) /* *ptr points at % of % */ 4 | { 5 | return strtol(*ptr + 1, ptr, 10); /* return the position beyond */ 6 | } 7 | 8 | 9 | -------------------------------------------------------------------------------- /icmake/exec/builtin/ebgetpid.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | void b_getPid() 4 | { 5 | gb_reg.type = e_int; 6 | gb_reg.intValue = (int16_t)getpid(); 7 | } 8 | -------------------------------------------------------------------------------- /icmake/exec/builtin/ebnoformatting.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | #include "builtin.ih" 3 | 4 | unsigned eb_noFormatting(void *dest, unsigned start, unsigned lastIdx) 5 | { 6 | gb_listIndex = 0; 7 | for (unsigned idx = start; idx != lastIdx; ++idx) 8 | { 9 | msg("write arg %u", idx); 10 | eb_writeArgument(dest, idx); 11 | } 12 | 13 | return lastIdx - start; 14 | } 15 | -------------------------------------------------------------------------------- /icmake/exec/builtin/ebreleasereg.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | Variable *eb_releaseReg() 4 | { 5 | destructor(&gb_reg); 6 | return &gb_reg; 7 | } 8 | -------------------------------------------------------------------------------- /icmake/exec/builtin/ebsetstring.c: -------------------------------------------------------------------------------- 1 | /* 2 | This function is called from {\em fun\_arg\_head()}, {\em 3 | fun\_cmd\_head()}, etc., to set the appropriate strings to a duplicate 4 | of the last pushed string. 5 | 6 | The argument {\em s} is freed if necessary. It should be the same 7 | pointer variable which is assigned the return value. 8 | */ 9 | 10 | #include "builtin.ih" 11 | 12 | char *eb_setString (char *s) 13 | { 14 | free(s); 15 | return s = rss_strdup(string_charp(stack_top())); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /icmake/exec/builtin/ebstringwrite.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | void eb_stringWrite(void *dest, char const *begin, char const *end) 4 | { 5 | char beyond = *end; /* save the char at end */ 6 | *(char *)end = 0; /* end the string to catenate */ 7 | 8 | *(char **)dest = rss_strcat(*(char **)dest, begin); 9 | 10 | *(char *)end = beyond; /* restore the char at end */ 11 | } 12 | 13 | -------------------------------------------------------------------------------- /icmake/exec/builtin/ebstrlower.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | char *eb_strLower (char *s) 4 | { 5 | register char *cp; 6 | 7 | for (cp = s; *cp; ++cp) 8 | *cp = tolower(*cp); 9 | 10 | return s; 11 | } 12 | -------------------------------------------------------------------------------- /icmake/exec/builtin/ebstrupper.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | char *eb_strUpper(char *s) 4 | { 5 | register char *cp; 6 | 7 | for (cp = s; *cp; ++cp) 8 | *cp = toupper(*cp); 9 | 10 | return s; 11 | } 12 | -------------------------------------------------------------------------------- /icmake/exec/builtin/ebupdatefgets.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | void eb_updateFgets(FILE *inf, char *dest) 4 | { 5 | char const *nl; 6 | 7 | char *last = dest + strlen(dest) - 1; 8 | 9 | if (*last != '\n') 10 | nl = ""; 11 | else 12 | { 13 | *last = 0; 14 | nl = "\n"; 15 | } 16 | 17 | list_add_grab_charPtr(&gb_reg, dest); 18 | list_add_charPtr(&gb_reg, nl); 19 | list_add_charPtr(&gb_reg, "OK"); 20 | 21 | char buffer[50]; 22 | sprintf (buffer, "%ld", (long)ftell(inf)); 23 | 24 | list_add_charPtr(&gb_reg, buffer); 25 | } 26 | -------------------------------------------------------------------------------- /icmake/exec/builtin/frame: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | void b_() 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/exec/builtin/popreg.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | void builtin_popReg() 4 | { 5 | virtual_assign(&gb_reg, stack_top()); 6 | stack_pop(); 7 | } 8 | -------------------------------------------------------------------------------- /icmake/exec/builtin/regptr.c: -------------------------------------------------------------------------------- 1 | #include "builtin.ih" 2 | 3 | Variable const *builtin_regPtr() 4 | { 5 | return &gb_reg; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/cleanup.c: -------------------------------------------------------------------------------- 1 | /* 2 | This function is attached to the `at-exit' list by {\em main()}. 3 | */ 4 | 5 | #include "icm-exec.ih" 6 | 7 | void cleanup() 8 | { 9 | aux_unlinkBim(); 10 | opcodefun_close(); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/exec/icm-exec.ih: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "../rss/rss.h" 5 | 6 | #include "aux/aux.h" 7 | #include "builtin/builtin.h" 8 | #include "int/int.h" 9 | #include "list/list.h" 10 | #include "opcodefun/opcodefun.h" 11 | #include "stack/stack.h" 12 | 13 | extern char **environ; 14 | 15 | void usage(char const *argv0); 16 | void cleanup(void); 17 | -------------------------------------------------------------------------------- /icmake/exec/icm_bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . ../bootstrap/functions 4 | . ../bootstrap/flags 5 | 6 | echo Creating tmp/${LIBDIR}/icm-exec 7 | build icm-exec aux var virtual int list string stack builtin opcodefun 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /icmake/exec/icmconf: -------------------------------------------------------------------------------- 1 | #define USE_ECHO ON 2 | #define MAIN "main.c" 3 | #define REFRESH 4 | #define CLS 5 | #define COMPILER "gcc" 6 | #define COMPILER_OPTIONS "-Wall -Werror -O2 -fdiagnostics-color=never" 7 | #define SOURCES "*.c" 8 | #define LINKER_OPTIONS "-s" 9 | #define ADD_LIBRARIES "icrss" 10 | #define ADD_LIBRARY_PATHS "../../tmp" 11 | #define TMP_DIR "tmp" 12 | #define LIBRARY "modules" 13 | #define OBJ_EXT ".o" 14 | #define DEFCOM "program" 15 | -------------------------------------------------------------------------------- /icmake/exec/int/add.c: -------------------------------------------------------------------------------- 1 | #include "int.ih" 2 | 3 | void int_add(Variable *lhs, Variable const *rhs) 4 | { 5 | int_assignInt(lhs, int_value(lhs) + int_value(rhs)); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /icmake/exec/int/assign.c: -------------------------------------------------------------------------------- 1 | #include "int.ih" 2 | 3 | void int_assign(Variable *lhs, Variable const *rhs) 4 | { 5 | destructor(lhs); 6 | *lhs = *rhs; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /icmake/exec/int/assignint.c: -------------------------------------------------------------------------------- 1 | #include "int.h" 2 | 3 | void int_assignInt(IntVariable *lhs, int value) 4 | { 5 | lhs->intValue = value; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/int/bool.c: -------------------------------------------------------------------------------- 1 | #include "int.h" 2 | 3 | int int_bool(IntVariable const *lhs) 4 | { 5 | return lhs->intValue; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/int/cons.c: -------------------------------------------------------------------------------- 1 | #include "int.h" 2 | 3 | void intcons(IntVariable *var) 4 | { 5 | var->type = e_int; 6 | var->intValue = 0; 7 | } 8 | -------------------------------------------------------------------------------- /icmake/exec/int/consint.c: -------------------------------------------------------------------------------- 1 | /*#define msg 2 | */ 3 | 4 | #include "int.ih" 5 | 6 | void intcons_int(IntVariable *intVar, int value) 7 | { 8 | intVar->type = e_int; 9 | intVar->intValue = value; 10 | } 11 | -------------------------------------------------------------------------------- /icmake/exec/int/copycons.c: -------------------------------------------------------------------------------- 1 | #include "int.h" 2 | 3 | void intcopycons(IntVariable *var, IntVariable const *other) 4 | { 5 | *var = *other; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/int/destructor.c: -------------------------------------------------------------------------------- 1 | #include "int.h" 2 | 3 | void intDestructor(Variable const *var) 4 | {} 5 | 6 | -------------------------------------------------------------------------------- /icmake/exec/int/int.ih: -------------------------------------------------------------------------------- 1 | #include "int.h" 2 | 3 | #include "../../rss/rss.h" 4 | #include "../virtual/virtual.h" 5 | 6 | 7 | -------------------------------------------------------------------------------- /icmake/exec/int/sub.c: -------------------------------------------------------------------------------- 1 | #include "int.ih" 2 | 3 | void int_sub(Variable *lhs, Variable const *rhs) 4 | { 5 | int_assignInt(lhs, int_value(lhs) - int_value(rhs)); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /icmake/exec/int/value.c: -------------------------------------------------------------------------------- 1 | #include "int.h" 2 | 3 | int int_value(IntVariable const *lhs) 4 | { 5 | return lhs->intValue; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/list/addcp.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | void list_add_charPtr(ListVariable *list, char const *txt) 4 | { 5 | l_incSize(list); 6 | l_addText(list, rss_strdup(txt)); 7 | } 8 | -------------------------------------------------------------------------------- /icmake/exec/list/addswallowcp.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | void list_add_grab_charPtr(ListVariable *list, char *txt) 4 | { 5 | l_incSize(list); 6 | l_addText(list, txt); 7 | } 8 | -------------------------------------------------------------------------------- /icmake/exec/list/assign.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | void list_assign(ListVariable *lhs, ListVariable const *rhs) 4 | { 5 | if (lhs != rhs) 6 | { 7 | destructor(lhs); 8 | *lhs = *rhs; 9 | var_incShared(lhs); 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /icmake/exec/list/at.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | char const *list_at(ListVariable const *list, unsigned idx) 4 | { 5 | return l_constElement(list)[idx]; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/list/bool.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | int list_bool(ListVariable const *lhs) 4 | { 5 | return l_size(lhs); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/list/cons.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | void listcons(ListVariable *list) 4 | { 5 | list->type = e_list; 6 | list->data = l_new(); 7 | } 8 | -------------------------------------------------------------------------------- /icmake/exec/list/conscharptr.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | void listcons_charPtr(ListVariable *list, char const *arg) 4 | { 5 | list->type = e_list; 6 | list->data = l_new(); 7 | list_add_charPtr(list, arg); 8 | } 9 | -------------------------------------------------------------------------------- /icmake/exec/list/conscharptrptr.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | void listcons_charPtrPtr(ListVariable *list, char **args) 4 | { 5 | list->type = e_list; 6 | list->data = l_new(); 7 | 8 | while (*args) 9 | list_add_charPtr(list, *args++); 10 | } 11 | -------------------------------------------------------------------------------- /icmake/exec/list/conssizecharptrptr.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | void listcons_size_charPtrPtr(ListVariable *list, unsigned argc, char **argv) 4 | { 5 | list->type = e_list; 6 | list->data = l_new(); 7 | 8 | for (; argc--; ) 9 | list_add_charPtr(list, *++argv); 10 | } 11 | -------------------------------------------------------------------------------- /icmake/exec/list/contains.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | int list_contains(ListVariable *lhs, char const *str) 4 | { 5 | for (int idx = 0, end = *l_sizePtr(lhs); idx != end; ++idx) 6 | { 7 | if (strcmp(str, l_element(lhs)[idx]) == 0) 8 | return idx; 9 | } 10 | 11 | return -1; 12 | } 13 | -------------------------------------------------------------------------------- /icmake/exec/list/copycons.c: -------------------------------------------------------------------------------- 1 | /* #define msg 2 | */ 3 | 4 | #include "list.ih" 5 | 6 | void listcopycons(ListVariable *list, ListVariable const *other) 7 | { 8 | *list = *other; 9 | list->type = e_list; 10 | var_incShared(list); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/exec/list/frame: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | void l_ (ListVariable *list, ) 4 | { 5 | } 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /icmake/exec/list/laddtxt.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | void l_addText(ListVariable *list, char *txt) 4 | { 5 | List *p = l_listPtr(list); 6 | 7 | p->element = rss_realloc(p->element, p->size * sizeof(char **)); 8 | p->element[p->size - 1] = txt; 9 | } 10 | -------------------------------------------------------------------------------- /icmake/exec/list/lincsize.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | void l_incSize(ListVariable *list) 4 | { 5 | ++*l_sizePtr(list); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/list/lnew.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | TextData *l_new() /* initializes TextData, empty list */ 4 | { 5 | TextData *ret = rss_realloc(NULL, sizeof(TextData)); 6 | memset(ret, 0, sizeof(TextData)); 7 | 8 | ret->nShared = 1; 9 | 10 | return ret; 11 | } 12 | -------------------------------------------------------------------------------- /icmake/exec/list/lremove.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | unsigned l_remove(ListVariable *list, char const *txt) 4 | { 5 | unsigned idx = l_size(list); 6 | unsigned nRemoved = 0; 7 | 8 | while (idx--) 9 | { 10 | char **target = l_element(list) + idx; 11 | 12 | if (strcmp(txt, *target) == 0) 13 | { 14 | free(*target); 15 | *target = 0; /* set the free ntps pointer to 0 */ 16 | ++nRemoved; 17 | } 18 | } 19 | return nRemoved; 20 | } 21 | -------------------------------------------------------------------------------- /icmake/exec/list/size.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | unsigned list_size(ListVariable const *list) 4 | { 5 | return l_size(list); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/list/sort.c: -------------------------------------------------------------------------------- 1 | /* 2 | This function sorts the list of variable {\em v}. The same variable, 3 | after sorting, is returned. 4 | */ 5 | 6 | #include "list.ih" 7 | 8 | static int compelement(void const *s1, void const *s2) 9 | { 10 | return strcmp(*(char const * const *)s1, *(char const * const *)s2); 11 | } 12 | 13 | void list_sort(ListVariable *list) 14 | { 15 | qsort(l_element(list), *l_sizePtr(list), sizeof(char *), compelement); 16 | } 17 | -------------------------------------------------------------------------------- /icmake/exec/list/test/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | gcc main.c -lmodules -L../../tmp -licrss -L../../../tmp 4 | -------------------------------------------------------------------------------- /icmake/exec/list/unionlist.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | void list_unionList(ListVariable *list, ListVariable const *src) 4 | { 5 | for (unsigned idx = l_size(src); idx--; ) 6 | list_unionStr(list, list_at(src, idx)); 7 | } 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /icmake/exec/list/unionstr.c: -------------------------------------------------------------------------------- 1 | #include "list.ih" 2 | 3 | void list_unionStr(ListVariable *list, char const *str) 4 | { 5 | if (list_contains(list, str) == -1) 6 | list_add_charPtr(list, str); 7 | } 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/close.c: -------------------------------------------------------------------------------- 1 | #include "opcodefun.ih" 2 | 3 | void opcodefun_close() 4 | { 5 | fclose(go_infile); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/frame: -------------------------------------------------------------------------------- 1 | #include "opcodefun.ih" 2 | 3 | void o_ 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/oatol.c: -------------------------------------------------------------------------------- 1 | /* 2 | This function converts the last pushed variable, which is assumed to 3 | hold a string, to a list of one element. The string variable is 4 | discarded after use. The formed list, containing one element, is copied 5 | onto the stack to the former position of the string variable. 6 | */ 7 | 8 | #include "opcodefun.ih" 9 | 10 | void o_atol() 11 | { 12 | Variable tmp; 13 | 14 | listcons_charPtr(&tmp, string_charp(stack_top())); 15 | virtual_assign(stack_top(), &tmp); 16 | listDestructor(&tmp); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/oband.c: -------------------------------------------------------------------------------- 1 | /* 2 | \funcref{fun\_band}{void fun\_band ()} 3 | {} 4 | {} 5 | {stack_pop(), stack_push()} 6 | {} 7 | {funband.c} 8 | { 9 | This function pops two variables and pushes the bitwise and-ed result 10 | of the {\em intValue} fields of these variables. The resulting 11 | pushed variable is of type {\em e\_int}. } */ 12 | 13 | #include "opcodefun.ih" 14 | 15 | void o_band () 16 | { 17 | int rvalue = int_value(stack_top()); 18 | 19 | stack_pop(); 20 | int_assignInt(stack_top(), int_value(stack_top()) & rvalue); 21 | } 22 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/obnot.c: -------------------------------------------------------------------------------- 1 | /* 2 | \funcref{fun\_bnot}{void fun\_bnot ()} 3 | {} 4 | {} 5 | {} 6 | {} 7 | {funbnot.c} 8 | { 9 | Function {\em fun\_bnot()} bitwise-not's the last pushed 10 | variable. This variable is assumed to be of type {\em e\_int}. 11 | } 12 | */ 13 | 14 | #include "opcodefun.ih" 15 | 16 | void o_bnot () 17 | { 18 | int_assignInt(stack_top(), ~int_value(stack_top())); 19 | } 20 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/obor.c: -------------------------------------------------------------------------------- 1 | /* 2 | \funcref{fun\_bor}{void fun\_bor ()} 3 | {} 4 | {} 5 | {stack_pop(), stack_push()} 6 | {} 7 | {funbor.c} 8 | { 9 | This function pops two variables and pushes the bitwise or-ed result 10 | of the {\em intValue} fields of these variables. The resulting 11 | pushed variable is of type {\em e\_int}. } */ 12 | 13 | #include "opcodefun.ih" 14 | 15 | void o_bor () 16 | { 17 | int rvalue = int_value(stack_top()); 18 | 19 | stack_pop(); 20 | int_assignInt(stack_top(), int_value(stack_top()) | rvalue); 21 | } 22 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/odec.c: -------------------------------------------------------------------------------- 1 | /* 2 | \funcref{fun\_dec}{void fun\_dec ()} 3 | {} 4 | {} 5 | {} 6 | {fun\_inc()} 7 | {fundec.c} 8 | { 9 | 10 | This function decrements the {\em intValue} field of a variable. The 11 | The number of the variable (a 16-bits unsigned number) is assumed to 12 | follow the {\em op\_dec} opcode. 13 | 14 | } 15 | */ 16 | 17 | #include "opcodefun.ih" 18 | 19 | void o_dec () 20 | { 21 | register Variable *dest = o_getDest(); 22 | 23 | int_assignInt(dest, int_value(dest) - 1); 24 | } 25 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/oexit.c: -------------------------------------------------------------------------------- 1 | /* 2 | This function places the {\em int} value of the return register {\em 3 | reg} into the global variable {\em retval}. 4 | */ 5 | 6 | #include "opcodefun.ih" 7 | 8 | void o_exit() 9 | { 10 | go_retVal = int_value(builtin_regPtr()); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/ogetdest.c: -------------------------------------------------------------------------------- 1 | /* 2 | This function is called when an opcode is read which is followed by a 3 | variable number (e.g., {\em op\_push\_var}). The index is read and a 4 | pointer to a {\em VAR\_} structure is returned; either in the variables 5 | section or in the stack (relative to {\em bp}). 6 | */ 7 | 8 | /*#define msg 9 | */ 10 | 11 | #include "opcodefun.ih" 12 | 13 | Variable *o_getDest() 14 | { 15 | int index = rss_getInt16(go_infile); 16 | 17 | return index >= 0 ? go_globalVar + index : stack_local(index); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/oinc.c: -------------------------------------------------------------------------------- 1 | /* 2 | \funcref{fun\_inc}{void fun\_inc ()} 3 | {} 4 | {} 5 | {} 6 | {fun\_dec()} 7 | {funinc.c} 8 | { 9 | 10 | This function decrements the {\em intValue} field of a variable. The 11 | The number of the variable (a 16-bits unsigned number) is assumed to 12 | follow the {\em op\_dec} opcode. 13 | 14 | } 15 | */ 16 | 17 | #include "opcodefun.ih" 18 | 19 | void o_inc () 20 | { 21 | register Variable *dest = o_getDest(); 22 | 23 | int_assignInt(dest, int_value(dest) + 1); 24 | } 25 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/oneq.c: -------------------------------------------------------------------------------- 1 | /* 2 | Function {\em fun\_neq()} is called when opcode {\em op\_neq} is read. 3 | This function pops two variables, calls {\em compare()} to compare the 4 | values, and pushes the result of the comparison. The two compared 5 | variables are discarded. 6 | */ 7 | 8 | #include "opcodefun.ih" 9 | 10 | void o_neq() 11 | { 12 | Variable rval; 13 | 14 | copycons(&rval, stack_top()); 15 | 16 | stack_pop(); 17 | 18 | virtual_compare(stack_top(), &rval); 19 | destructor(&rval); 20 | } 21 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/opcodefun.h: -------------------------------------------------------------------------------- 1 | #ifndef _INCLUDED_OPCODEFUN_H_ 2 | #define _INCLUDED_OPCODEFUN_H_ 3 | 4 | #include "../../rss/rss.h" 5 | 6 | int opcodefun_process(void); 7 | void opcodefun_setGlobalVariables(); 8 | void opcodefun_setInfile(char const *arg); 9 | void opcodefun_close(); 10 | 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/opopreg.c: -------------------------------------------------------------------------------- 1 | /* 2 | The last pushed value is popped into the return register. This action 3 | is usually taken when a function is about to return a value. 4 | */ 5 | 6 | #include "opcodefun.ih" 7 | 8 | void o_popReg() 9 | { 10 | builtin_popReg(); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/opush0.c: -------------------------------------------------------------------------------- 1 | /* 2 | This function serves the evaluation of logical expressions. It is 3 | executed when an {\em op\_push\_0} opcode is found in the binary 4 | makefile. A variable of type {\em e\_int} is pushed, while its {\em 5 | intValue} field is set to zero. 6 | */ 7 | 8 | #include "opcodefun.ih" 9 | 10 | void o_push_0() 11 | { 12 | IntVariable tmp; 13 | 14 | intcons_int(&tmp, 0); 15 | stack_push(&tmp); 16 | intDestructor(&tmp); 17 | } 18 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/opushimm.c: -------------------------------------------------------------------------------- 1 | /* 2 | This function is called when an immediate value is to be pushed. The 3 | value (type {\em int16_t}) is expected to follow the opcode. 4 | 5 | A variable of type {\em e\_int}, with its {\em intValue} field set 6 | to the value retrieved from the binary makefile, is pushed. 7 | */ 8 | 9 | #include "opcodefun.ih" 10 | 11 | void o_push_imm() 12 | { 13 | IntVariable tmp; 14 | 15 | intcons_int(&tmp, rss_getInt16(go_infile)); 16 | 17 | stack_push(&tmp); 18 | intDestructor(&tmp); 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/oumin.c: -------------------------------------------------------------------------------- 1 | /* 2 | \funcref{fun\_umin}{void fun\_umin ()} 3 | {} 4 | {} 5 | {} 6 | {} 7 | {funumin.c} 8 | { 9 | Function {\em fun\_umin()} reverses the sign of the last pushed 10 | variable. This variable is assumed to be of type {\em e\_int}. 11 | } 12 | */ 13 | 14 | #include "opcodefun.ih" 15 | 16 | void o_umin() 17 | { 18 | stack_top()->intValue = -stack_top()->intValue; 19 | } 20 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/oxor.c: -------------------------------------------------------------------------------- 1 | /* 2 | \funcref{fun\_xor}{void fun\_xor ()} 3 | {} 4 | {} 5 | {stack_pop(), stack_push()} 6 | {} 7 | {funxor.c} 8 | { 9 | This function pops two variables and pushes the bitwise xor-ed result 10 | of the {\em intValue} fields of these variables. The resulting 11 | pushed variable is of type {\em e\_int}. } */ 12 | 13 | #include "opcodefun.ih" 14 | 15 | void o_xor () 16 | { 17 | int rvalue = int_value(stack_top()); 18 | 19 | stack_pop(); 20 | int_assignInt(stack_top(), int_value(stack_top()) ^ rvalue); 21 | } 22 | -------------------------------------------------------------------------------- /icmake/exec/opcodefun/setinfile.c: -------------------------------------------------------------------------------- 1 | #include "opcodefun.ih" 2 | 3 | void opcodefun_setInfile(char const *arg) 4 | { 5 | if (!(go_infile = fopen(arg, "r"))) 6 | rss_fatal(0, 0, "cannot read bimfile '%s'", arg); 7 | 8 | go_header = rss_readHeader(go_infile, (unsigned)version[0]); 9 | } 10 | -------------------------------------------------------------------------------- /icmake/exec/stack/data.c: -------------------------------------------------------------------------------- 1 | #include "stack.ih" 2 | 3 | Variable *gs_stack; 4 | 5 | unsigned gs_sp; 6 | unsigned gs_bp; 7 | 8 | -------------------------------------------------------------------------------- /icmake/exec/stack/local.c: -------------------------------------------------------------------------------- 1 | #include "stack.ih" 2 | 3 | Variable *stack_local(int index) 4 | { 5 | return gs_stack + (int)gs_bp + (int16_t)0xc000 - index; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/stack/pop.c: -------------------------------------------------------------------------------- 1 | #include "stack.ih" 2 | 3 | #include "../int/int.h" 4 | #include "../string/string.h" 5 | 6 | void stack_pop() 7 | { 8 | s_testUnderflow(); 9 | destructor(gs_stack + --gs_sp); 10 | } 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /icmake/exec/stack/popbp.c: -------------------------------------------------------------------------------- 1 | #include "stack.ih" 2 | 3 | 4 | void stack_popBP() 5 | { 6 | while (gs_sp - 1 != gs_bp) 7 | stack_pop(); 8 | 9 | gs_bp = int_value(stack_top()); /* restore old gs_bp */ 10 | stack_pop(); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/exec/stack/push.c: -------------------------------------------------------------------------------- 1 | 2 | /* #define msg 3 | */ 4 | 5 | #include "stack.ih" 6 | 7 | #include "../int/int.h" 8 | #include "../string/string.h" 9 | 10 | static unsigned stackSize; 11 | 12 | void stack_push(Variable const *varEl) 13 | { 14 | if (gs_sp >= stackSize) 15 | { 16 | stackSize += 50; 17 | gs_stack = rss_realloc(gs_stack, stackSize * sizeof(Variable)); 18 | } 19 | 20 | copycons(gs_stack + gs_sp++, varEl); 21 | } 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /icmake/exec/stack/pushbp.c: -------------------------------------------------------------------------------- 1 | #include "stack.ih" 2 | 3 | void stack_pushBP() 4 | { 5 | Variable tmp; 6 | 7 | intcons_int(&tmp, (int)gs_bp); 8 | 9 | gs_bp = gs_sp; 10 | stack_push(&tmp); 11 | 12 | intDestructor(&tmp); 13 | } 14 | -------------------------------------------------------------------------------- /icmake/exec/stack/stack.h: -------------------------------------------------------------------------------- 1 | #ifndef _INCLUDED_STACK_H_ 2 | #define _INCLUDED_STACK_H_ 3 | 4 | #include "../../rss/rss.h" 5 | 6 | void stack_push(Variable const *var); 7 | void stack_pushBP(void); 8 | 9 | void stack_pop(void); 10 | void stack_popBP(void); 11 | Variable *stack_top(void); 12 | 13 | Variable *stack_local(int index); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /icmake/exec/stack/stack.ih: -------------------------------------------------------------------------------- 1 | #include "stack.h" 2 | 3 | #include "../aux/aux.h" 4 | #include "../var/var.h" 5 | #include "../virtual/virtual.h" 6 | #include "../int/int.h" 7 | 8 | void s_testUnderflow(void); 9 | 10 | extern Variable *gs_stack; 11 | extern unsigned gs_sp; 12 | extern unsigned gs_bp; 13 | 14 | -------------------------------------------------------------------------------- /icmake/exec/stack/stestunderflow.c: -------------------------------------------------------------------------------- 1 | #include "stack.ih" 2 | 3 | void s_testUnderflow() 4 | { 5 | if (gs_sp == 0) 6 | rss_fatal(0, 0, "stack underflow at %s", aux_offset()); 7 | } 8 | -------------------------------------------------------------------------------- /icmake/exec/stack/top.c: -------------------------------------------------------------------------------- 1 | #include "stack.ih" 2 | 3 | Variable *stack_top() 4 | { 5 | s_testUnderflow(); 6 | return gs_stack + gs_sp - 1; 7 | } 8 | -------------------------------------------------------------------------------- /icmake/exec/string/add.c: -------------------------------------------------------------------------------- 1 | #include "string.ih" 2 | 3 | void string_add(String *lhs, String const *rhs) 4 | { 5 | char *catstr = rss_strjoin(string_charp(lhs), string_charp(rhs)); 6 | 7 | destructor(lhs); 8 | stringcons_charPtr(lhs, catstr); 9 | 10 | free(catstr); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /icmake/exec/string/assign.c: -------------------------------------------------------------------------------- 1 | #include "string.ih" 2 | 3 | void string_assign(String *lhs, String const *rhs) 4 | { 5 | if (lhs != rhs) 6 | { 7 | destructor(lhs); 8 | *lhs = *rhs; 9 | var_incShared(lhs); 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /icmake/exec/string/bool.c: -------------------------------------------------------------------------------- 1 | #include "string.ih" 2 | 3 | int string_bool(String const *lhs) 4 | { 5 | return *s_str(lhs); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/string/charp.c: -------------------------------------------------------------------------------- 1 | #include "string.ih" 2 | 3 | char const *string_charp(String const *lhs) 4 | { 5 | return s_str(lhs); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/string/compare.c: -------------------------------------------------------------------------------- 1 | #include "string.ih" 2 | 3 | void stringCompare(String *lhs, String const *rhs) 4 | { 5 | int ret = strcmp(string_charp(lhs), string_charp(rhs)); 6 | 7 | stringDestructor(lhs); 8 | 9 | /* Can't use the return value as-is, since */ 10 | /* the non-16 bit return value may have its */ 11 | /* lower 16 bits set to zero (as happened */ 12 | /* on the powerpc */ 13 | intcons_int(lhs, ret < 0 ? -1 : ret > 0 ? 1 : 0); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /icmake/exec/string/cons.c: -------------------------------------------------------------------------------- 1 | #include "string.ih" 2 | 3 | void stringcons(String *str) 4 | { 5 | str->type = e_str; 6 | 7 | str->data = s_new(rss_strdup("")); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /icmake/exec/string/conscharptr.c: -------------------------------------------------------------------------------- 1 | #include "string.ih" 2 | 3 | void stringcons_charPtr(String *str, char const *ntbs) 4 | { 5 | str->type = e_str; 6 | 7 | str->data = s_new(rss_strdup(ntbs)); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /icmake/exec/string/consswallowcharptr.c: -------------------------------------------------------------------------------- 1 | #include "string.ih" 2 | 3 | void stringcons_swallowCharPtr(String *str, char *ntbs) 4 | { 5 | str->type = e_str; 6 | 7 | str->data = s_new(ntbs); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /icmake/exec/string/copycons.c: -------------------------------------------------------------------------------- 1 | #include "string.ih" 2 | 3 | void stringcopycons(String *str, String const *other) 4 | { 5 | *str = *other; 6 | str->type = e_str; 7 | var_incShared(str); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /icmake/exec/string/destructor.c: -------------------------------------------------------------------------------- 1 | #define msg 2 | 3 | #include "string.ih" 4 | 5 | void stringDestructor(Variable const *var) 6 | { 7 | if (var_decShared(var) == 0) 8 | { 9 | free(var->data->str); 10 | free(var->data); 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /icmake/exec/string/frame: -------------------------------------------------------------------------------- 1 | #include "string.ih" 2 | 3 | void s_ 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/exec/string/reduce.c: -------------------------------------------------------------------------------- 1 | #include "string.ih" 2 | 3 | void string_reduce(String *str, unsigned len) 4 | { 5 | if (len < strlen(str->data->str)) 6 | str->data->str[len] = 0; 7 | } 8 | -------------------------------------------------------------------------------- /icmake/exec/string/snew.c: -------------------------------------------------------------------------------- 1 | 2 | /* #define msg 3 | */ 4 | 5 | #include "string.ih" 6 | 7 | TextData *s_new(char *cp) 8 | { 9 | TextData *ret = rss_realloc(NULL, sizeof(TextData)); 10 | ret->nShared = 1; 11 | ret->str = cp; 12 | 13 | return ret; 14 | } 15 | -------------------------------------------------------------------------------- /icmake/exec/string/string.ih: -------------------------------------------------------------------------------- 1 | #include "string.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../var/var.h" 8 | #include "../virtual/virtual.h" 9 | #include "../int/int.h" 10 | 11 | TextData *s_new(char *cp); /* cp must be free-able */ 12 | 13 | inline char *s_str(String const *arg) 14 | { 15 | return arg->data->str; 16 | } 17 | -------------------------------------------------------------------------------- /icmake/exec/string/test/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | gcc main.c -lmodules -L../../tmp -licrss -L../../../tmp 4 | -------------------------------------------------------------------------------- /icmake/exec/string/trimleft.c: -------------------------------------------------------------------------------- 1 | #include "string.ih" 2 | 3 | void string_trimLeft(String *lhs, String const *rhs) 4 | { 5 | stringcons_swallowCharPtr(lhs, rss_trimLeft(s_str(rhs))); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /icmake/exec/string/trimright.c: -------------------------------------------------------------------------------- 1 | /* #define msg 2 | */ 3 | 4 | #include "string.ih" 5 | 6 | void string_trimRight(String *lhs, String const *rhs) 7 | { 8 | char *trimmed = rss_trimRight(s_str(rhs)); 9 | 10 | stringcons_swallowCharPtr(lhs, trimmed); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /icmake/exec/usage.c: -------------------------------------------------------------------------------- 1 | #include "icm-exec.ih" 2 | 3 | void usage(char const *argv0) 4 | { 5 | register char const *program = rss_programName(argv0); 6 | 7 | rss_copyright(program); 8 | 9 | printf ("This program is run as a child process of icmake.\n" 10 | "Usage: %s [-t] bimfile\n" 11 | "where: -t - option indicating that 'bimfile' must be\n" 12 | " removed on exit.\n" 13 | " bimfile - binary makefile to execute.\n\n" 14 | , program); 15 | 16 | exit(0); 17 | } 18 | -------------------------------------------------------------------------------- /icmake/exec/var/decshared.c: -------------------------------------------------------------------------------- 1 | #include "var.ih" 2 | 3 | uint16_t var_decShared(Variable const *var) 4 | { 5 | return --((Variable *)var)->data->nShared; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/var/incshared.c: -------------------------------------------------------------------------------- 1 | #include "var.ih" 2 | 3 | void var_incShared(Variable *var) 4 | { 5 | ++var->data->nShared; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/var/shared.c: -------------------------------------------------------------------------------- 1 | #include "var.ih" 2 | 3 | uint16_t var_nShared(Variable const *var) 4 | { 5 | return var->data->nShared; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/exec/var/var.ih: -------------------------------------------------------------------------------- 1 | #include "var.h" 2 | -------------------------------------------------------------------------------- /icmake/exec/virtual/add.c: -------------------------------------------------------------------------------- 1 | #include "virtual.ih" 2 | 3 | void virtual_add(Variable *lhs, Variable const *rhs) 4 | { 5 | p_add[var_typeValue(rhs)](lhs, rhs); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /icmake/exec/virtual/assign.c: -------------------------------------------------------------------------------- 1 | #include "virtual.ih" 2 | 3 | void virtual_assign(Variable *lhs, Variable const *rhs) 4 | { 5 | p_assign[var_typeValue(rhs)](lhs, rhs); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /icmake/exec/virtual/compare.c: -------------------------------------------------------------------------------- 1 | #include "virtual.ih" 2 | 3 | void virtual_compare(Variable *lhs, Variable const *rhs) 4 | { 5 | p_compare[var_typeValue(rhs)](lhs, rhs); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /icmake/exec/virtual/cons.c: -------------------------------------------------------------------------------- 1 | #include "virtual.ih" 2 | 3 | void constructor(Variable *var, ExprType type) 4 | { 5 | return p_constructor[ 6 | type & e_list ? 2 : 7 | type & e_str ? 1 : 8 | 0 9 | ](var); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /icmake/exec/virtual/copycons.c: -------------------------------------------------------------------------------- 1 | #include "virtual.ih" 2 | 3 | void copycons(Variable *var, Variable const *other) 4 | { 5 | p_copycons[var_typeValue(other)](var, other); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /icmake/exec/virtual/destructor.c: -------------------------------------------------------------------------------- 1 | #include "virtual.ih" 2 | 3 | void destructor(Variable const *lhs) 4 | { 5 | register ExprType type = var_typeValue(lhs); 6 | 7 | if (type & e_typeMask) 8 | p_destructor[type](lhs); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /icmake/exec/virtual/logical.c: -------------------------------------------------------------------------------- 1 | #include "virtual.ih" 2 | 3 | int virtual_bool(Variable const *lhs) 4 | { 5 | return p_bool[var_typeValue(lhs)](lhs); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /icmake/exec/virtual/subtract.c: -------------------------------------------------------------------------------- 1 | #include "virtual.ih" 2 | 3 | void virtual_sub(Variable *lhs, Variable const *rhs) 4 | { 5 | p_sub[var_typeValue(rhs)](lhs, rhs); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /icmake/icmake/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | icmbuild $1 4 | -------------------------------------------------------------------------------- /icmake/icmake/cleanup.c: -------------------------------------------------------------------------------- 1 | #include "icmake.ih" 2 | 3 | void cleanup() 4 | { 5 | fflush(stdout); 6 | fflush(stderr); 7 | 8 | if (flags & f_rmPim) 9 | unlink(pimFile); 10 | 11 | if (flags & f_rmBim) 12 | unlink(bimFile); 13 | } 14 | -------------------------------------------------------------------------------- /icmake/icmake/compile.c: -------------------------------------------------------------------------------- 1 | #define msg 2 | 3 | #include "icmake.ih" 4 | 5 | void compile() 6 | { 7 | if (!(flags & f_doCompile)) /* no compilation requested: leave */ 8 | return; 9 | 10 | int ret = spawnlp(WAIT, icm_comp, icm_comp, pimFile, bimFile, NULL); 11 | 12 | if (flags & f_rmPim) 13 | unlink(pimFile); 14 | 15 | if (ret) 16 | { 17 | flags |= f_rmBim; 18 | 19 | if (ret == -1) 20 | rss_spawnErr(icm_comp); 21 | 22 | exit(1); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /icmake/icmake/dashesindex.c: -------------------------------------------------------------------------------- 1 | #include "icmake.ih" 2 | 3 | unsigned dashesIndex(char **begin, char **end) 4 | { 5 | char **start = begin; 6 | 7 | for (; begin != end; ++begin) 8 | { 9 | if (strcmp(*begin, "--") == 0) 10 | return 1 + begin - start; 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /icmake/icmake/data.c: -------------------------------------------------------------------------------- 1 | #include "icmake.ih" 2 | 3 | char icm_pre[] = LIBDIR "/icm-dep"; 4 | char icm_comp[] = LIBDIR "/icm-comp"; 5 | char icm_exec[] = LIBDIR "/icm-exec"; 6 | char icm_pp[] = LIBDIR "/icm-pp"; 7 | 8 | char *tmpDir; 9 | char *imFile; 10 | char *pimFile; 11 | char *bimFile; 12 | 13 | FILE *fdest; 14 | FLAGS_ flags; 15 | unsigned execArgIdx; 16 | -------------------------------------------------------------------------------- /icmake/icmake/icm_bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . ../bootstrap/functions 4 | . ../bootstrap/flags 5 | 6 | echo Creating tmp/${BINDIR}/icmake 7 | 8 | echo -n . 9 | try ${CC} ${CFLAGS} -o ../tmp/${BINDIR}/icmake *.c ../tmp/libicrss.a \ 10 | ${LDFLAGS} 11 | echo . 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /icmake/icmake/icmconf: -------------------------------------------------------------------------------- 1 | #define USE_ECHO ON 2 | #define MAIN "main.c" 3 | #define COMPILER "gcc" 4 | #define COMPILER_OPTIONS "-Wall -O2 -fdiagnostics-color=never" 5 | #define SOURCES "*.c" 6 | #define LINKER_OPTIONS "-s" 7 | #define ADD_LIBRARIES "icrss" 8 | #define ADD_LIBRARY_PATHS "../../tmp" 9 | #define REFRESH 10 | #define CLS 11 | #define TMP_DIR "tmp" 12 | #define LIBRARY "modules" 13 | #define OBJ_EXT ".o" 14 | #define DEFCOM "program" 15 | -------------------------------------------------------------------------------- /icmake/icmake/icmdep.c: -------------------------------------------------------------------------------- 1 | #define msg 2 | 3 | #include "icmake.ih" 4 | 5 | void icmDep(char **argv) 6 | { 7 | *argv = icm_pre; 8 | execvp(*argv, (char *const *)argv); 9 | 10 | rss_spawnErr(icm_pre); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/icmake/optcompile.c: -------------------------------------------------------------------------------- 1 | #define msg 2 | 3 | #include "icmake.ih" 4 | 5 | void optCompile(char **argv) 6 | { 7 | flags |= f_doPreProcess | f_rmPim | f_doCompile | f_compile; 8 | 9 | imFile = accessFile(optarg, "im"); 10 | pimFile = rss_strjoin(tmpDir, ".pim"); 11 | bimFile = useFile(argv[optind], optarg, "bim"); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /icmake/icmake/optexecute.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "icmake.ih" 4 | 5 | void optExecute() 6 | { 7 | flags |= f_icmexec | f_doExec; 8 | bimFile = accessFile(optarg, "bim"); 9 | 10 | msg("optarg: %s, bimFile: %s", optarg, bimFile); 11 | 12 | execArgIdx = optind; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /icmake/icmake/optim.c: -------------------------------------------------------------------------------- 1 | #define msg 2 | 3 | #include "icmake.ih" 4 | 5 | void optIm(char **argv) 6 | { 7 | flags |= f_im | f_doPreProcess | f_rmPim | f_doCompile | f_doExec; 8 | 9 | imFile = accessFile(optarg, "im"); 10 | pimFile = rss_strjoin(tmpDir, "pim"); 11 | bimFile = rss_changeExt(imFile, "bim"); 12 | 13 | testCompile(); /* may wipe f_doPreProcess | f_rmPim | f_doCompile */ 14 | 15 | execArgIdx = optind; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /icmake/icmake/optpreprocess.c: -------------------------------------------------------------------------------- 1 | #define msg 2 | 3 | #include "icmake.ih" 4 | 5 | void optPreProcess(char **argv) 6 | { 7 | flags |= f_preProcess | f_doPreProcess; 8 | 9 | imFile = accessFile(optarg, "im"); 10 | pimFile = useFile(argv[optind], imFile, "pim"); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /icmake/icmake/opttmpdir.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "icmake.ih" 4 | 5 | void optTmpDir() 6 | { 7 | free(tmpDir); 8 | tmpDir = rss_strdup(optarg); 9 | 10 | if (tmpDir[strlen(tmpDir) - 1] != '/') /* tmpDir must end in / */ 11 | tmpDir = rss_strcat(tmpDir, "/"); 12 | 13 | char pidStr[20]; 14 | snprintf(pidStr, 20, "%u", getpid()); 15 | 16 | tmpDir = rss_strcat(tmpDir, pidStr); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /icmake/icmake/setlinks: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd tmp/bin || exit 1 4 | 5 | for x in icm-exec icm-comp icm-pp icmun 6 | do 7 | ln -s ../../../$x/tmp/bin/binary $x || exit 1 8 | done 9 | -------------------------------------------------------------------------------- /icmake/icmake/usefile.c: -------------------------------------------------------------------------------- 1 | #define msg 2 | 3 | #include "icmake.ih" 4 | 5 | char *useFile(char const *firstChoice, char const *fallback, char const *ext) 6 | { 7 | return firstChoice != NULL ? 8 | rss_strdup(firstChoice) 9 | : 10 | rss_changeExt(fallback, ext); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /icmake/icmbuild/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | icmbuild $1 4 | -------------------------------------------------------------------------------- /icmake/icmbuild/icm_bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . ../bootstrap/functions 4 | . ../bootstrap/flags 5 | 6 | echo Creating tmp/${BINDIR}/icmbuild 7 | 8 | echo -n . 9 | try ${CC} ${CFLAGS} -o ../tmp/${BINDIR}/icmbuild *.c ../tmp/libicrss.a \ 10 | ${LDFLAGS} 11 | echo . 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /icmake/icmbuild/icmbuild.ih: -------------------------------------------------------------------------------- 1 | #include "../rss/rss.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "../tmp/INSTALL.im" 7 | 8 | 9 | // #include 10 | // #include 11 | // #include 12 | // #include 13 | // #include 14 | // #include 15 | // 16 | 17 | // 18 | // #ifdef SUN 19 | // #include 20 | // #endif 21 | 22 | int usage(); 23 | -------------------------------------------------------------------------------- /icmake/icmbuild/icmconf: -------------------------------------------------------------------------------- 1 | #define USE_ECHO ON 2 | #define MAIN "main.c" 3 | #define COMPILER "gcc" 4 | #define COMPILER_OPTIONS "-Wall -O2 -fdiagnostics-color=never" 5 | #define SOURCES "*.c" 6 | #define LINKER_OPTIONS "-s" 7 | #define ADD_LIBRARIES "icrss" 8 | #define ADD_LIBRARY_PATHS "../../tmp" 9 | #define REFRESH 10 | #define CLS 11 | #define TMP_DIR "tmp" 12 | #define LIBRARY "modules" 13 | #define OBJ_EXT ".o" 14 | #define DEFCOM "program" 15 | -------------------------------------------------------------------------------- /icmake/iuo/bootstrapinstall: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd /usr/bin 4 | 5 | if [ -f icmake ] ; then 6 | mv icmake icmake.org 7 | ln -sf /home/frank/src/icmake/tmp/usr/bin/icmake . 8 | fi 9 | 10 | cd /usr/lib/icmake 11 | 12 | for x in icm-pp icm-comp icm-exec 13 | do 14 | if [ -f $x ] ; then 15 | mv $x $x.org 16 | ln -sf /home/frank/src/icmake/tmp/usr/lib/icmake/$x . 17 | fi 18 | done 19 | 20 | -------------------------------------------------------------------------------- /icmake/iuo/install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd /usr/bin 4 | 5 | if [ -f icmake ] ; then 6 | mv icmake icmake.org 7 | ln -sf /home/frank/git/icmake/src/icmake/icmake/tmp/bin/binary icmake 8 | fi 9 | 10 | cd /usr/lib/icmake 11 | 12 | for x in icm-pp icm-comp icm-exec 13 | do 14 | if [ -f $x ] ; then 15 | mv $x $x.org 16 | ln -sf /home/frank/git/icmake/src/icmake/$x/tmp/bin/binary $x 17 | fi 18 | done 19 | 20 | -------------------------------------------------------------------------------- /icmake/iuo/uninstall: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd /usr/bin 4 | if [ -h icmake ] ; then 5 | rm icmake 6 | mv icmake.org icmake 7 | fi 8 | 9 | cd /usr/lib/icmake 10 | 11 | for x in icm-pp icm-comp icm-exec 12 | do 13 | if [ -h $x ] ; then 14 | rm $x 15 | mv $x.org $x 16 | fi 17 | done 18 | 19 | -------------------------------------------------------------------------------- /icmake/pp/CLASSES: -------------------------------------------------------------------------------- 1 | filestack 2 | state 3 | # scanner 4 | out 5 | linear 6 | # parser 7 | # main 8 | -------------------------------------------------------------------------------- /icmake/pp/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ scanner/pushfile.f -nt scanner/lexer \ 4 | -o scanner/scpopfile.f -nt scanner/lexer ] ; then 5 | touch scanner/lexer 6 | fi 7 | 8 | icmbuild $1 9 | 10 | -------------------------------------------------------------------------------- /icmake/pp/filestack/data.c: -------------------------------------------------------------------------------- 1 | #include "filestack.ih" 2 | 3 | FileStack *fs_stack; 4 | int fs_size; /* initial empty stack. */ 5 | 6 | 7 | -------------------------------------------------------------------------------- /icmake/pp/filestack/filestack.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_FILESTACK_H_ 2 | #define INCLUDED_FILESTACK_H_ 3 | 4 | #include 5 | 6 | typedef struct /* yylex itself maintains its own YY_BUFFERs */ 7 | { 8 | char *filename; /* name of the currently active file */ 9 | FILE *file; 10 | int popLineNr; /* value of yylineno when popping this element */ 11 | } FileStack; 12 | 13 | 14 | void filestack_push(unsigned currentLineNr, char const *fname); 15 | void filestack_pop(); 16 | FileStack const *filestack_tos(); 17 | unsigned filestack_size(); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /icmake/pp/filestack/filestack.ih: -------------------------------------------------------------------------------- 1 | #include "filestack.h" 2 | 3 | #include 4 | #include "../../rss/rss.h" 5 | 6 | extern FileStack *fs_stack; 7 | extern int fs_size; 8 | -------------------------------------------------------------------------------- /icmake/pp/filestack/frame: -------------------------------------------------------------------------------- 1 | #include "filestack.ih" 2 | 3 | void fs_ 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/pp/filestack/pop.c: -------------------------------------------------------------------------------- 1 | #include "filestack.ih" 2 | 3 | void filestack_pop() 4 | { 5 | free(fs_stack[--fs_size].filename); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/pp/filestack/push.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | #include "filestack.ih" 3 | 4 | void filestack_push(unsigned currentLineNr, char const *fname) 5 | { 6 | fs_stack = rss_realloc(fs_stack, (fs_size + 1) * sizeof(FileStack)); 7 | 8 | if (! (fs_stack[fs_size].file = fopen(fname, "r")) ) 9 | rss_fatal(0, 0, "cannot open #include file `%s'", fname); 10 | 11 | fs_stack[fs_size].filename = rss_strdup(fname); 12 | fs_stack[fs_size].popLineNr = currentLineNr; 13 | 14 | msg("Pushed file %u: `%s'", fs_size, fname); 15 | 16 | ++fs_size; 17 | } 18 | -------------------------------------------------------------------------------- /icmake/pp/filestack/size.c: -------------------------------------------------------------------------------- 1 | #include "filestack.ih" 2 | 3 | unsigned filestack_size() 4 | { 5 | return fs_size; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/pp/filestack/tos.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | #include "filestack.ih" 3 | 4 | FileStack const *filestack_tos() 5 | { 6 | msg("tos() looks at %u", fs_size - 1); 7 | 8 | return &fs_stack[fs_size - 1]; 9 | } 10 | -------------------------------------------------------------------------------- /icmake/pp/icm-pp.ih: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "../rss/rss.h" 5 | 6 | #include "linear/linear.h" 7 | #include "parser/parser.h" 8 | 9 | void options(int argc, char **argv); 10 | void usage(char const *progname); 11 | void loadSymbols(); 12 | -------------------------------------------------------------------------------- /icmake/pp/icm_bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . ../bootstrap/functions 4 | . ../bootstrap/flags 5 | 6 | echo Creating tmp/${LIBDIR}/icm-pp 7 | build icm-pp filestack state scanner out linear parser 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /icmake/pp/linear/add.c: -------------------------------------------------------------------------------- 1 | #include "linear.ih" 2 | 3 | void linear_add(char const *ident, char const *definition) 4 | { 5 | if (l_size == l_capacity) 6 | l_table = rss_realloc(l_table, (l_capacity += 10) * sizeof(Linear)); 7 | 8 | l_table[l_size].id = rss_strdup(ident); 9 | l_table[l_size].definition = l_replaceDefines(rss_strdup(definition)); 10 | 11 | ++l_size; 12 | } 13 | -------------------------------------------------------------------------------- /icmake/pp/linear/data.c: -------------------------------------------------------------------------------- 1 | #include "linear.ih" 2 | 3 | Linear *l_table; 4 | size_t l_size; 5 | unsigned l_capacity; 6 | -------------------------------------------------------------------------------- /icmake/pp/linear/frame: -------------------------------------------------------------------------------- 1 | #include "linear.ih" 2 | 3 | void l_ 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/pp/linear/lcompare.c: -------------------------------------------------------------------------------- 1 | #include "linear.ih" 2 | 3 | int l_compare(const void *ident, const void *item) 4 | { 5 | return strcmp(ident, ((Linear *)item)->id); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/pp/linear/search.c: -------------------------------------------------------------------------------- 1 | #include "linear.ih" 2 | 3 | Linear const *linear_search(char const *ident) 4 | { 5 | return lfind(ident, l_table, &l_size, sizeof(Linear), l_compare); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/pp/linear/show.c: -------------------------------------------------------------------------------- 1 | #include "linear.ih" 2 | 3 | void linear_show() 4 | { 5 | printf("Defined symbols: %u\n", (unsigned)l_size); 6 | 7 | Linear const *item = l_table; 8 | Linear const *end = l_table + l_size; 9 | 10 | for ( ; item != end; ++item) 11 | printf(" %20s: `%s'\n", item->id, item->definition); 12 | } 13 | -------------------------------------------------------------------------------- /icmake/pp/out/ateof.c: -------------------------------------------------------------------------------- 1 | #include "out.ih" 2 | 3 | void (*out_atEOF(void))(void) 4 | { 5 | return o_eof; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/pp/out/data.c: -------------------------------------------------------------------------------- 1 | #include "out.ih" 2 | 3 | FILE *o_file; 4 | int o_space; /* if != 0 then write one space */ 5 | unsigned o_nl; /* if 0, remembers the last scanner_lineNr() value */ 6 | int o_atBOL; /* if 1 we're at Begin of line */ 7 | char *o_outFilename; 8 | -------------------------------------------------------------------------------- /icmake/pp/out/frame: -------------------------------------------------------------------------------- 1 | #include "out.ih" 2 | 3 | void o_ 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/pp/out/init.c: -------------------------------------------------------------------------------- 1 | #include "out.ih" 2 | 3 | void out_init(char const *im, char const *pim) 4 | { 5 | if ((o_file = fopen(pim, "w")) == NULL) 6 | rss_fatal(0, 0, "cannot write output file `%s'", pim); 7 | 8 | o_outFilename = rss_strdup(pim); 9 | 10 | fprintf(o_file, "#>%s\n", im); 11 | atexit(o_close); 12 | } 13 | -------------------------------------------------------------------------------- /icmake/pp/out/nl.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "out.ih" 4 | 5 | void out_nl() 6 | { 7 | if (o_nl == 0) 8 | o_nl = scanner_lineNr(); 9 | 10 | msg("o_nl = %u", o_nl); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/pp/out/oclose.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "out.ih" 4 | 5 | void o_close() 6 | { 7 | fputc('\n', o_file); 8 | fclose(o_file); 9 | 10 | if (rss_nErrors() != 0) 11 | unlink(o_outFilename); 12 | } 13 | -------------------------------------------------------------------------------- /icmake/pp/out/oeof.c: -------------------------------------------------------------------------------- 1 | #include "out.ih" 2 | 3 | void o_eof() 4 | { 5 | if (!o_atBOL) 6 | fputc('\n', o_file); 7 | 8 | fprintf(o_file, "#\n"); 9 | 10 | o_space = 0; 11 | o_nl = 0; 12 | o_atBOL = 1; 13 | } 14 | -------------------------------------------------------------------------------- /icmake/pp/out/onewlines.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | 4 | #include "out.ih" 5 | 6 | void o_newLines() 7 | { 8 | unsigned lineNr = scanner_lineNr(); 9 | 10 | msg("lineNr: %u, o_nl: %u", lineNr, o_nl); 11 | 12 | 13 | if (lineNr - o_nl > 4) 14 | { 15 | if (!o_atBOL) 16 | fputc('\n', o_file); 17 | fprintf(o_file, "#%u\n", lineNr); 18 | } 19 | else 20 | { 21 | for ( ; o_nl <= lineNr; ++o_nl) 22 | fputc('\n', o_file); 23 | } 24 | 25 | o_space = 0; 26 | o_nl = 0; 27 | o_atBOL = 1; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /icmake/pp/out/out.c: -------------------------------------------------------------------------------- 1 | 2 | #define msgx 3 | 4 | #include "out.ih" 5 | 6 | void out(char const *text) 7 | { 8 | msg("%u %s", state_active(), text); 9 | 10 | if (state_active()) 11 | { 12 | if (o_nl != 0) 13 | o_newLines(); 14 | else if (o_space) 15 | { 16 | o_space = 0; 17 | fputc(' ', o_file); 18 | } 19 | 20 | fprintf(o_file, "%s", text); 21 | o_atBOL = 0; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /icmake/pp/out/out.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_OUT_ 2 | #define INCLUDED_OUT_ 3 | 4 | void out_init(char const *im, char const *pim); 5 | void out(char const *text); 6 | void out_space(void); 7 | void out_nl(void); 8 | void (*out_atEOF(void))(void); /* returns a function to be called at 9 | EOF */ 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /icmake/pp/out/out.ih: -------------------------------------------------------------------------------- 1 | #include "out.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../../rss/rss.h" 8 | #include "../state/state.h" 9 | #include "../scanner/scanner.h" 10 | 11 | extern FILE *o_file; 12 | extern int o_space; 13 | extern unsigned o_nl; 14 | extern int o_atBOL; 15 | extern char *o_outFilename; 16 | 17 | void o_newLines(void); 18 | void o_close(void); 19 | void o_eof(void); 20 | -------------------------------------------------------------------------------- /icmake/pp/out/space.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | #include "out.ih" 3 | 4 | void out_space() 5 | { 6 | msg(""); 7 | 8 | if (!o_atBOL) 9 | o_space = 1; 10 | } 11 | -------------------------------------------------------------------------------- /icmake/pp/parser/data.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | char *p_filename; /* initial filename */ 4 | char *p_text; 5 | char *p_im; 6 | char p_dirsep[] = {DIRSEP, 0}; 7 | -------------------------------------------------------------------------------- /icmake/pp/parser/frame: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | void p_ 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/pp/parser/padddef.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "parser.ih" 4 | 5 | void p_addDef(char const *ident, char const *definition) 6 | { 7 | msg("id: %s, def: %s", ident, definition); 8 | 9 | if (linear_search(ident) != NULL) 10 | { 11 | rss_error(filestack_tos()->filename, scanner_lineNr(), 12 | "%s multiply defined", ident); 13 | return; 14 | } 15 | 16 | linear_add(ident, definition); 17 | } 18 | -------------------------------------------------------------------------------- /icmake/pp/parser/parse.c: -------------------------------------------------------------------------------- 1 | 2 | #define msgx 3 | 4 | #include "parser.ih" 5 | 6 | int parser_parse() 7 | { 8 | msg("Current status: %u", state_active()); 9 | 10 | return yyparse(); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/pp/parser/parser.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | void parser(char **argv) 4 | { 5 | p_im = rss_strdup(getenv("IM")); 6 | 7 | state_init(); 8 | p_filename = rss_strdup(argv[1]); 9 | out_init(p_filename, argv[2]); 10 | scanner(p_filename, out_atEOF()); 11 | } 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /icmake/pp/parser/parser.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_PARSER_H_ 2 | #define INCLUDED_PARSER_H_ 3 | 4 | void parser(char **argv); /* call once */ 5 | int parser_parse(void); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /icmake/pp/parser/pelse.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "parser.ih" 4 | 5 | void p_else() 6 | { 7 | state_negate(scanner_lineNr() - 1); 8 | 9 | msg("active: %u", state_active()); 10 | } 11 | -------------------------------------------------------------------------------- /icmake/pp/parser/pendif.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "parser.ih" 4 | 5 | void p_endif() 6 | { 7 | state_pop(scanner_lineNr() - 1); 8 | 9 | msg("active: %u", state_active()); 10 | } 11 | -------------------------------------------------------------------------------- /icmake/pp/parser/pifdef.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "parser.ih" 4 | 5 | void p_ifdef() 6 | { 7 | state_push(linear_search(p_text) != NULL); 8 | 9 | msg("active %s: %u", p_text, state_active()); 10 | } 11 | -------------------------------------------------------------------------------- /icmake/pp/parser/pifndef.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "parser.ih" 4 | 5 | void p_ifndef() 6 | { 7 | state_push(linear_search(p_text) == NULL); 8 | 9 | msg("active: %u", state_active()); 10 | } 11 | -------------------------------------------------------------------------------- /icmake/pp/parser/pinspectident.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "parser.ih" 4 | 5 | void p_inspectIdent() 6 | { 7 | char const *ident = scanner_text(); 8 | Linear const *item = linear_search(ident); 9 | 10 | out(item == NULL ? ident : item->definition); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/pp/parser/pnextfile.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | char const *p_nextFile() 4 | { 5 | return *p_text == '"' ? 6 | p_quotedName(p_text + 1) 7 | : 8 | p_IMfile(); 9 | } 10 | -------------------------------------------------------------------------------- /icmake/pp/parser/ppushfile.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "parser.ih" 4 | 5 | void p_pushFile() /* switch to another file */ 6 | { 7 | char const *filename = p_nextFile(); 8 | 9 | msg("%s", filename); 10 | 11 | 12 | if (state_active()) 13 | { 14 | out("#>"); 15 | out(filename); 16 | out("\n"); 17 | 18 | scanner_pushFile(filename); 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /icmake/pp/parser/pquotedname.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | char const *p_quotedName(char *name) 4 | { 5 | name[strlen(name) - 1] = 0; /* remove the last character */ 6 | 7 | return name; 8 | } 9 | -------------------------------------------------------------------------------- /icmake/pp/parser/psaveyytext.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | #include "parser.ih" 3 | 4 | void p_saveYYtext() 5 | { 6 | free(p_text); 7 | p_text = rss_strdup(scanner_text()); 8 | msg("%s", p_text); 9 | } 10 | -------------------------------------------------------------------------------- /icmake/pp/parser/ptextline.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "parser.ih" 4 | 5 | void p_textLine(int token) 6 | { 7 | do 8 | { 9 | msg("saw %u, `%s'", token, scanner_text()); 10 | 11 | if (token == IDENT) 12 | p_inspectIdent(); 13 | else 14 | out(scanner_text()); 15 | 16 | token = yylex(); 17 | } 18 | while (token != '\n' && token != 0); 19 | 20 | out_nl(); 21 | } 22 | -------------------------------------------------------------------------------- /icmake/pp/parser/pundef.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "parser.ih" 4 | 5 | void p_undef() 6 | { 7 | if (state_active() && !linear_undef(p_text)) 8 | rss_warning(filestack_tos()->filename, scanner_lineNr() - 1, 9 | "#undef %s: `%s' not defined\n", 10 | p_text, p_text); 11 | 12 | msg("active: %u", state_active()); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /icmake/pp/parser/pyyerror.c: -------------------------------------------------------------------------------- 1 | #include "parser.ih" 2 | 3 | int yyerror(char *s) 4 | { 5 | if (scanner_eof()) 6 | rss_fatal(p_filename, scanner_lastLineNr(), 7 | "Unexpected end of file"); 8 | 9 | rss_error(filestack_tos()->filename, scanner_lineNr(), 10 | "Syntax error at `%s'", 11 | scanner_text()); 12 | 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /icmake/pp/scanner/ateof.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | void scanner_atEOF(void (*ptr)(void)) 4 | { 5 | sc_ptr = ptr; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/pp/scanner/data.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | char *sc_definition; 4 | int sc_getDefine; 5 | void (*sc_ptr)(void); 6 | int sc_eof; 7 | unsigned sc_lastLineNr; 8 | -------------------------------------------------------------------------------- /icmake/pp/scanner/definition.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | char const *scanner_definition() 4 | { 5 | return sc_definition; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/pp/scanner/eof.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | int scanner_eof() 4 | { 5 | return sc_eof; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/pp/scanner/frame: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | void sc_ 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/pp/scanner/lastlinenr.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | unsigned scanner_lastLineNr() 4 | { 5 | return sc_lastLineNr; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/pp/scanner/length.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | unsigned scanner_length() 4 | { 5 | return yyleng; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/pp/scanner/linenr.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | unsigned scanner_lineNr() 4 | { 5 | return yylineno; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/pp/scanner/pushfile.f: -------------------------------------------------------------------------------- 1 | /* included by lexer */ 2 | 3 | void scanner_pushFile(char const *filename) 4 | { 5 | if (state_active()) 6 | { 7 | msg("pushing %s %u", filename, YY_BUF_SIZE); 8 | 9 | yypush_buffer_state( 10 | yy_create_buffer( 11 | sc_pushFile(filename), YY_BUF_SIZE 12 | ) 13 | ); 14 | 15 | msg("pushed `%s'", filename); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /icmake/pp/scanner/scanner.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "scanner.ih" 4 | 5 | void scanner(char const *infile, void (*ptr)(void)) 6 | { 7 | filestack_push(yylineno, infile); 8 | yyin = filestack_tos()->file; 9 | 10 | sc_ptr = ptr; /* function called at EOF, when popping 11 | a previous file */ 12 | } 13 | -------------------------------------------------------------------------------- /icmake/pp/scanner/scanner.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_SCANNER_H_ 2 | #define INCLUDED_SCANNER_H_ 3 | 4 | #include 5 | 6 | void scanner(char const *infile, void (*ptr)(void)); 7 | int yylex(); 8 | char const *scanner_text(); 9 | char const *scanner_definition(); 10 | unsigned scanner_lineNr(); 11 | unsigned scanner_length(); 12 | void scanner_pushFile(char const *filename); 13 | int scanner_eof(void); 14 | unsigned scanner_lastLineNr(void); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /icmake/pp/scanner/scpopfile.f: -------------------------------------------------------------------------------- 1 | /* included by lexer */ 2 | 3 | int sc_popFile() 4 | { 5 | yypop_buffer_state(); 6 | sc_lastLineNr = yylineno; 7 | yylineno = filestack_tos()->popLineNr; 8 | filestack_pop(); 9 | msg("returning to previous file"); 10 | 11 | size_t size = filestack_size(); 12 | if (size) 13 | (*sc_ptr)(); 14 | else 15 | { 16 | state_eof(); 17 | sc_eof = 1; 18 | } 19 | 20 | return size; 21 | } 22 | -------------------------------------------------------------------------------- /icmake/pp/scanner/scpushfile.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "scanner.ih" 4 | 5 | FILE *sc_pushFile(char const *filename) 6 | { 7 | msg("push %s", filename); 8 | filestack_push(yylineno, filename); 9 | msg("done"); 10 | yylineno = 1; 11 | 12 | return yyin = filestack_tos()->file; 13 | } 14 | -------------------------------------------------------------------------------- /icmake/pp/scanner/scstartdefinition.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | void sc_startDefinition() 4 | { 5 | free(sc_definition); 6 | sc_definition = 0; 7 | } 8 | -------------------------------------------------------------------------------- /icmake/pp/scanner/text.c: -------------------------------------------------------------------------------- 1 | #include "scanner.ih" 2 | 3 | char const *scanner_text() 4 | { 5 | return yytext; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/pp/state/active.c: -------------------------------------------------------------------------------- 1 | #include "state.ih" 2 | 3 | int state_active() 4 | { 5 | return st_stack[st_size - 1].active; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/pp/state/data.c: -------------------------------------------------------------------------------- 1 | #include "state.ih" 2 | 3 | State *st_stack; 4 | unsigned st_size; 5 | unsigned st_capacity; 6 | -------------------------------------------------------------------------------- /icmake/pp/state/eof.c: -------------------------------------------------------------------------------- 1 | #include "state.ih" 2 | 3 | static char plural[2]; 4 | 5 | void state_eof() 6 | { 7 | if (st_size != 1) 8 | { 9 | if (st_size != 2) 10 | plural[0] = 's'; 11 | 12 | rss_fatal(0, 0, 13 | "at EOF: #endif%s missing for %u #if(n)def%s", 14 | plural, st_size - 1, plural); 15 | } 16 | } 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /icmake/pp/state/frame: -------------------------------------------------------------------------------- 1 | #include "state.ih" 2 | 3 | void st_ 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/pp/state/init.c: -------------------------------------------------------------------------------- 1 | #include "state.ih" 2 | 3 | void state_init() 4 | { 5 | st_available(); 6 | st_size = 1; 7 | st_stack[0].active = 1; /* initialize to an active state */ 8 | } 9 | -------------------------------------------------------------------------------- /icmake/pp/state/negate.c: -------------------------------------------------------------------------------- 1 | #include "state.ih" 2 | 3 | void state_negate(unsigned linenr) 4 | { 5 | State *sp = st_stack + st_size - 1; 6 | 7 | if (sp->elseCount++) 8 | rss_fatal(filestack_tos()->filename, linenr, 9 | "multiple #else directives of #if(n)def encountered"); 10 | 11 | 12 | if ((sp - 1)->active) /* previous state is active */ 13 | sp->active = !sp->active; /* then negate */ 14 | } 15 | -------------------------------------------------------------------------------- /icmake/pp/state/pop.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | #include "state.ih" 3 | 4 | void state_pop(unsigned linenr) 5 | { 6 | msg("%s %u size = %u, before pop", \ 7 | filestack_tos()->filename, linenr, st_size); 8 | 9 | --st_size; 10 | 11 | if (st_size == 0) 12 | rss_fatal(filestack_tos()->filename, linenr, 13 | "#endif without a matching #if(n)def encountered"); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /icmake/pp/state/push.c: -------------------------------------------------------------------------------- 1 | #define msgx 2 | 3 | #include "state.ih" 4 | 5 | void state_push(int active) 6 | { 7 | st_available(); /* make room if necessary */ 8 | 9 | State *sp = st_stack + st_size++; 10 | 11 | sp->active = (sp - 1)->active == 0 ? 12 | 0 13 | : 14 | active; 15 | 16 | sp->elseCount = 0; 17 | 18 | msg("%s size = %u", filestack_tos()->filename, st_size); 19 | } 20 | -------------------------------------------------------------------------------- /icmake/pp/state/size.c: -------------------------------------------------------------------------------- 1 | #include "state.ih" 2 | 3 | unsigned state_size() 4 | { 5 | return st_size; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/pp/state/state.ih: -------------------------------------------------------------------------------- 1 | #include "state.h" 2 | 3 | #include "../../rss/rss.h" 4 | 5 | #include "../filestack/filestack.h" 6 | 7 | typedef struct 8 | { 9 | int active; 10 | int elseCount; 11 | } State; 12 | 13 | extern State *st_stack; 14 | extern unsigned st_size; 15 | extern unsigned st_capacity; 16 | 17 | void st_available(); /* make sure there's enough room available */ 18 | 19 | -------------------------------------------------------------------------------- /icmake/pp/state/stavailable.c: -------------------------------------------------------------------------------- 1 | #include "state.ih" 2 | 3 | void st_available() 4 | { 5 | if (st_size == st_capacity) 6 | st_stack = rss_realloc(st_stack, (st_capacity += 10) * sizeof(State)); 7 | } 8 | -------------------------------------------------------------------------------- /icmake/required: -------------------------------------------------------------------------------- 1 | This file lists non-standard software only. Thus, standard utilities like cp, 2 | mv, sed, etc, etc, are not explicitly mentioned. Neither is the gcc compiler 3 | explicitly mentioned, but a fairly recent one is assumed. 4 | 5 | Required software for building Icmake 6 | ------------------------------------- 7 | 8 | Recent version of yodl (for creating documentation) 9 | -------------------------------------------------------------------------------- /icmake/rss/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | icmbuild $1 4 | [ "$1" == "" ] && cp tmp/libicrss.a ../tmp/ 5 | -------------------------------------------------------------------------------- /icmake/rss/changebase.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | char *rss_changeBase(char const *path, char const *base) 4 | { 5 | rs_split(path); 6 | *gr_fname = 0; 7 | if (base) 8 | strcpy(gr_fname, base); 9 | rs_join(); 10 | return rss_strdup(gr_name); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/rss/changeext.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | char *rss_changeExt(char const *path, char const *extension) 4 | { 5 | rs_split(path); 6 | *gr_ext = 0; 7 | if (extension) 8 | strcpy(gr_ext, extension); 9 | 10 | rs_join(); 11 | 12 | return rss_strdup(gr_name); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /icmake/rss/changepath.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | char *rss_changePath(char const *path, char const *newDirs) 4 | { 5 | rs_split(path); 6 | 7 | if (newDirs) 8 | strcpy(gr_dir, newDirs); 9 | 10 | rs_join(); 11 | 12 | return rss_strdup(gr_name); 13 | } 14 | -------------------------------------------------------------------------------- /icmake/rss/copyright.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | void rss_copyright(char const *program) 4 | { 5 | printf("\n" 6 | "%s by Frank B. Brokken (f.b.brokken@rug.nl)\n" 7 | "%s V%s, copyright (c) GPL %s.\n" 8 | "\n", 9 | program, program, version, release); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /icmake/rss/data.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | glob_t gr_globData; /* globbing struct */ 4 | unsigned gr_nextGlob; /* next name in list */ 5 | 6 | unsigned gr_nErrors; 7 | 8 | char gr_name[MAX_PATHLEN]; 9 | char gr_dir[MAX_PATHLEN]; 10 | char gr_fname[MAX_PATHLEN]; 11 | char gr_ext[MAX_PATHLEN]; 12 | 13 | IcmakeFind gr_ifs; /* icmake find-struct */ 14 | 15 | char gr_hexDigits[] = "0123456789abcdef"; 16 | -------------------------------------------------------------------------------- /icmake/rss/error.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | void rss_error(char const *src, unsigned lineNr, char const *fmt, ...) 4 | { 5 | va_list args; 6 | va_start(args, fmt); 7 | 8 | rss_errorList(src, lineNr, fmt, args); 9 | } 10 | -------------------------------------------------------------------------------- /icmake/rss/errorlist.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | void rss_errorList(char const *src, unsigned lineNr, char const *fmt, 4 | va_list args) 5 | { 6 | rs_msg(src, lineNr, "Error", fmt, args); 7 | ++gr_nErrors; 8 | } 9 | -------------------------------------------------------------------------------- /icmake/rss/exists.c: -------------------------------------------------------------------------------- 1 | /* 2 | The function returns 1 if the filename given as its argument exists. 3 | Otherwise, 0 is returned. Path can be NULL 4 | */ 5 | 6 | /*#define msg 7 | */ 8 | 9 | #include "rss.ih" 10 | 11 | int rss_exists(char const *path) 12 | { 13 | struct stat buf; 14 | 15 | return !stat(path, &buf); 16 | } 17 | -------------------------------------------------------------------------------- /icmake/rss/fatal.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | void rss_fatal(char const *src, unsigned lineNr, char const *fmt, ...) 4 | { 5 | va_list args; 6 | 7 | va_start(args, fmt); 8 | rs_msg(src, lineNr, "Fatal", fmt, args); 9 | ++gr_nErrors; 10 | 11 | exit(1); 12 | } 13 | -------------------------------------------------------------------------------- /icmake/rss/fgetz.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | char *rss_fgetz (char *buf, unsigned maxlen, FILE *f) 4 | { 5 | register unsigned 6 | i; 7 | 8 | if (! maxlen) 9 | return (NULL); 10 | 11 | for (i = 0; i < maxlen - 1; i++) 12 | { 13 | buf [i] = fgetc (f); 14 | if (! buf [i]) 15 | break; 16 | } 17 | 18 | buf [i] = '\0'; 19 | return (buf); 20 | } 21 | -------------------------------------------------------------------------------- /icmake/rss/findnext.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | char *rss_findNext() 4 | { 5 | char 6 | *cp; /* pointer to matched filename */ 7 | 8 | while (!rs_findNext(&gr_ifs.find)) /* find next entry */ 9 | { 10 | if ( (cp = rs_fileFound()) ) /* file found ? */ 11 | return (cp); /* return its name */ 12 | } 13 | 14 | return (NULL); /* none found */ 15 | } 16 | -------------------------------------------------------------------------------- /icmake/rss/frame: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | void rs_ 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /icmake/rss/getbase.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | char const *rss_getBase(char const *n) 4 | { 5 | rs_split(n); 6 | return gr_fname; 7 | } 8 | -------------------------------------------------------------------------------- /icmake/rss/getdext.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | char const *rss_getDext(char const *n) /* including the dot */ 4 | { 5 | rs_split(n); 6 | return *gr_ext == '.' ? rss_strdup(gr_ext) : gr_ext; 7 | } 8 | -------------------------------------------------------------------------------- /icmake/rss/getext.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | char const *rss_getExt(char const *path) 4 | { 5 | rs_split(path); 6 | 7 | return *gr_ext == '.' ? 8 | rss_strdup(gr_ext + 1) 9 | : 10 | gr_ext; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /icmake/rss/getopcode.c: -------------------------------------------------------------------------------- 1 | /* 2 | Function {\em rss_getOpcode()} attempts to read an opcode from file {\em 3 | f}. This file must be opened in read/binary mode (see the constant {\em 4 | "r"} in file {\em icm.h}). 5 | 6 | When the reading operation fails, --1 is returned. 7 | */ 8 | 9 | /*#define msg 10 | */ 11 | 12 | #include "rss.ih" 13 | 14 | Opcode rss_getOpcode (FILE *f) 15 | { 16 | char op = 0; 17 | 18 | if (!fread (&op, sizeof(char), 1, f)) 19 | op = (char)-1; 20 | 21 | msg("next opcode: 0x%x", op); 22 | 23 | return (Opcode) op; 24 | } 25 | -------------------------------------------------------------------------------- /icmake/rss/getpath.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | char const *rss_getPath(char const *n) 4 | { 5 | register int last; 6 | 7 | rs_split(n); 8 | last = strlen(gr_dir); 9 | 10 | if (last && gr_dir[last - 1] != DIRSEP) 11 | gr_dir[last] = DIRSEP; 12 | 13 | return gr_dir; 14 | } 15 | -------------------------------------------------------------------------------- /icmake/rss/icm_bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . ../bootstrap/functions 4 | . ../bootstrap/flags 5 | 6 | echo Creating tmp/libicrss.a 7 | 8 | echo -n . 9 | try ${CC} -c ${CFLAGS} *.c 10 | echo -n . 11 | try ar rs ../tmp/libicrss.a *.o 12 | echo -n . 13 | rm *.o 14 | echo . 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /icmake/rss/icmconf: -------------------------------------------------------------------------------- 1 | #define USE_ECHO ON 2 | #define COMPILER "gcc" 3 | #define COMPILER_OPTIONS "-Wall -Werror -O2 -fdiagnostics-color=never" 4 | #define SOURCES "*.c" 5 | #define LINKER_OPTIONS "-s" 6 | #define ADD_LIBRARIES "" 7 | #define ADD_LIBRARY_PATHS "" 8 | #define CLS 9 | #define TMP_DIR "tmp" 10 | #define LIBRARY "icrss" 11 | #define OBJ_EXT ".o" 12 | #define DEFCOM "library" 13 | -------------------------------------------------------------------------------- /icmake/rss/msg.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | /* 4 | Prints a msg to stderr. Use it by doing '#define msg' before reading 5 | rss.h, and then call msg(fmt, ...) to specify a message 6 | */ 7 | 8 | void rss_msg_(char const *path, char *fmt, ...) 9 | { 10 | va_list args; 11 | 12 | va_start(args, fmt); 13 | rs_msg(0, 0, path, fmt, args); 14 | } 15 | -------------------------------------------------------------------------------- /icmake/rss/nerrors.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | unsigned rss_nErrors() 4 | { 5 | return gr_nErrors; 6 | } 7 | -------------------------------------------------------------------------------- /icmake/rss/rsfilename.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | char *rs_filename(char *fname) /* return pointer into */ 4 | { /* fname, just beyond */ 5 | register char *cp; /* directory name */ 6 | 7 | return (cp = strrchr(fname, DIRSEP)) && *(cp + 1) ? 8 | cp + 1 9 | : 10 | fname; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /icmake/rss/rsgloberr.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | /* 4 | glob() error handler 5 | returns 0: signal for glob to ignore the error 6 | */ 7 | int rs_globerr(char const *path, int errnr) 8 | { 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /icmake/rss/rsjoin.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | void rs_join(void) 4 | { 5 | rss_makePath(gr_name, gr_dir, gr_fname, gr_ext); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/rss/rsmsg.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | void rs_msg(char const *src, unsigned lineNr, 4 | char const *prefix, char const *fmt, va_list args) 5 | { 6 | if (src) 7 | fprintf(stderr, "[%s, line %u] ", src, lineNr); 8 | 9 | fprintf(stderr, "%s: ", prefix); 10 | 11 | vfprintf(stderr, fmt, args); 12 | fputc('\n', stderr); 13 | } 14 | -------------------------------------------------------------------------------- /icmake/rss/rssplit.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | void rs_split(char const *path) 4 | { 5 | rss_splitPath(path, gr_dir, gr_fname, gr_ext); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/rss/strjoin.c: -------------------------------------------------------------------------------- 1 | /* 2 | this function returns a copy of s1 to which s2 is appended. 3 | Both s1 and s2 may be NULL, in which case an empty string is returned. 4 | */ 5 | 6 | #include "rss.ih" 7 | 8 | char *rss_strjoin(char const *s1, char const *s2) 9 | { 10 | return rss_strcat(rss_strdup(s1), s2); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /icmake/rss/trimleft.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | char *rss_trimLeft(char const *begin) 4 | { 5 | while (isspace(*begin)) 6 | ++begin; 7 | 8 | return rss_strdup(begin); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /icmake/rss/version.c: -------------------------------------------------------------------------------- 1 | /* 2 | V E R S I O N . C 3 | */ 4 | 5 | #include "../rss/rss.ih" 6 | #include "../tmp/INSTALL.im" 7 | 8 | char 9 | version[] = VERSION, 10 | release[] = YEARS; 11 | -------------------------------------------------------------------------------- /icmake/rss/warning.c: -------------------------------------------------------------------------------- 1 | #include "rss.ih" 2 | 3 | void rss_warning(char const *src, unsigned lineNr, char const *fmt, ...) 4 | { 5 | va_list args; 6 | 7 | va_start(args, fmt); 8 | rs_msg(src, lineNr, "Warning", fmt, args); 9 | } 10 | -------------------------------------------------------------------------------- /icmake/scripts/convert: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SCRIPTNAME=$1 4 | DESTDIR=$2 5 | 6 | . scripts/conversions 7 | 8 | mkdir -p tmp/${DESTDIR} 9 | 10 | sed ' 11 | s,@BINDIR@,'${BINDIR}',g 12 | s,@SKELDIR@,'${SKELDIR}',g 13 | s,@MANDIR@,'${MANDIR}',g 14 | s,@LIBDIR@,'${LIBDIR}',g 15 | s,@CONFDIR@,'${CONFDIR}',g 16 | s,@DOCDIR@,'${DOCDIR}',g 17 | s,@DOCDOCDIR@,'${DOCDOCDIR}',g 18 | ' tmp/${SCRIPTNAME}.in > ${DESTDIR}/${SCRIPTNAME} 19 | -------------------------------------------------------------------------------- /icmake/un/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | icmbuild $1 4 | -------------------------------------------------------------------------------- /icmake/un/dumpchar.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void dumpchar(int val) 4 | { 5 | printf ("%s ", rss_hexString ((unsigned)(val & 0xff), 2)); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/dumpint.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void dumpint (int val) 4 | { 5 | printf ("%s ", rss_hexString((unsigned)(val & 0xff), 2)); 6 | unsigned len = printf ("%s", rss_hexString((unsigned)(val >> 8), 2)); 7 | printf("%*c", 5 - len, ' '); 8 | } 9 | -------------------------------------------------------------------------------- /icmake/un/dumpstri.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void dumpstring (s) 4 | char *s; 5 | { 6 | while (*s) 7 | { 8 | putchar(iscntrl(*s) ? '.' : *s); 9 | s++; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /icmake/un/funadd.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_add () 4 | { 5 | puts (" add"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funasp.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_asp () 4 | { 5 | char 6 | val; 7 | 8 | val = rss_getOpcode (infile); 9 | dumpchar (val); 10 | printf ("add sp, %u\n", val); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/un/funatoi.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_atoi () 4 | { 5 | puts (" atoi"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funatol.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_atol () 4 | { 5 | puts (" atol"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funband.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_band () 4 | { 5 | puts (" and"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funbnot.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_bnot () 4 | { 5 | puts (" not"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funbor.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_bor () 4 | { 5 | puts (" or"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funcall.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_call() 4 | { 5 | int offs = rss_getInt16 (infile); 6 | dumpint(offs); 7 | 8 | printf ("call [%s]\n", rss_hexString((unsigned)offs, 4)); 9 | } 10 | -------------------------------------------------------------------------------- /icmake/un/funcallr.c: -------------------------------------------------------------------------------- 1 | 2 | #include "icmun.ih" 3 | 4 | void fun_call_rss () 5 | { 6 | unsigned char funnr; 7 | 8 | funnr = (unsigned char)rss_getOpcode(infile); 9 | dumpchar(funnr); 10 | 11 | if (funnr >= f_hlt) 12 | rss_fatal(0, 0, "non-existing function call\n" 13 | "attempt to call function %x, %x are defined", 14 | funnr, f_hlt); 15 | 16 | printf ("callrss %u (%s)\n", (unsigned int)funnr, funname [ (int) funnr]); 17 | } 18 | -------------------------------------------------------------------------------- /icmake/un/funcopyv.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_copy_var () 4 | { 5 | int16_t idx; 6 | 7 | idx = rss_getInt16 (infile); 8 | dumpint (idx); 9 | 10 | if ((uint16_t)idx < 0x8000) 11 | printf ("copy global %s %s\n", varname (var [idx].type), 12 | printvar (idx)); 13 | else if (idx < (int16_t) 0xc000) 14 | printf ("copy local %s %s\n", 15 | varname (local_types[ (int16_t) 0xc000 - (int16_t) 1 - idx]), 16 | printvar (idx)); 17 | else 18 | printf ("copy arg %s\n", printvar (idx)); 19 | } 20 | -------------------------------------------------------------------------------- /icmake/un/fundec.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_dec () 4 | { 5 | int16_t idx = rss_getInt16 (infile); 6 | 7 | dumpint (idx); 8 | if ((uint16_t)idx < 0x8000) 9 | printf ("dec global %s %s\n", varname (var [idx].type), 10 | printvar (idx)); 11 | else if (idx < (int16_t) 0xc000) 12 | printf ("dec local %s %s\n", 13 | varname (local_types[ (int16_t) 0xc000 - (int16_t) 1 - idx]), 14 | printvar (idx)); 15 | else 16 | printf ("dec arg %s\n", printvar (idx)); 17 | } 18 | -------------------------------------------------------------------------------- /icmake/un/fundiv.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_div () 4 | { 5 | puts (" div"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funeq.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_eq () 4 | { 5 | puts (" eq"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funexit.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_exit () 4 | { 5 | puts (" exit"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/fungr.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_gr () 4 | { 5 | puts (" gr"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/fungreq.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_greq () 4 | { 5 | puts (" greq"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funitoa.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_itoa () 4 | { 5 | puts (" itoa"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funjmp.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_jmp () 4 | { 5 | int16_t 6 | offs; 7 | 8 | offs = rss_getInt16 (infile); 9 | dumpint ( (uint16_t) offs); 10 | printf ("jmp [%s]\n", 11 | rss_hexString ((unsigned)(ftell(infile) + offs), 4)); 12 | } 13 | -------------------------------------------------------------------------------- /icmake/un/funjmpf.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_jmp_false () 4 | { 5 | int16_t 6 | offs; 7 | 8 | offs = rss_getInt16 (infile); 9 | dumpint ( (uint16_t) offs); 10 | printf ("jmp false [%s]\n", 11 | rss_hexString ((unsigned) (ftell (infile) + offs), 4)); 12 | } 13 | -------------------------------------------------------------------------------- /icmake/un/funjmpt.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_jmp_true () 4 | { 5 | int16_t offs = rss_getInt16 (infile); 6 | 7 | dumpint ( (uint16_t) offs); 8 | printf ("jmp true [%s]\n", 9 | rss_hexString ((unsigned) (ftell (infile) + offs), 4)); 10 | } 11 | -------------------------------------------------------------------------------- /icmake/un/funmod.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_mod () 4 | { 5 | puts (" mod"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funmul.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_mul () 4 | { 5 | puts (" mul"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funneq.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_neq () 4 | { 5 | puts (" neq"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funolder.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_older () 4 | { 5 | puts (" older"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funpopre.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_pop_reg () 4 | { 5 | puts (" pop reg"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funpush0.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_push_0 () 4 | { 5 | puts (" push int 0"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funpush1.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_push_1_jmp_end () 4 | { 5 | printf (" push int 1, jmp [%s]\n", 6 | rss_hexString((unsigned)(curoffs + 2), 4)); 7 | } 8 | -------------------------------------------------------------------------------- /icmake/un/funpushi.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_push_imm () 4 | { 5 | int16_t val = rss_getInt16 (infile); 6 | 7 | dumpint ( (uint16_t) val); 8 | printf ("push int %s\n", rss_hexString ((unsigned)val, 4)); 9 | } 10 | -------------------------------------------------------------------------------- /icmake/un/funpushr.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_push_reg () 4 | { 5 | puts (" push reg"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funpushs.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_push_strconst () 4 | { 5 | uint16_t 6 | offs; 7 | register char 8 | *str; 9 | 10 | offs = (uint16_t) rss_getInt16 (infile); 11 | if ( 12 | (str = rss_getString (infile, headerp->offset[0], offs)) 13 | == (char *) -1 14 | ) 15 | rss_fatal(0, 0, "cannot get string, opcode at %s", 16 | rss_hexString (curoffs, 4)); 17 | 18 | dumpint (offs); 19 | printf ("push string \""); 20 | dumpstring (str); 21 | puts ("\""); 22 | 23 | free (str); 24 | } 25 | -------------------------------------------------------------------------------- /icmake/un/funret.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_ret () 4 | { 5 | puts (" ret"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funshl.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_shl () 4 | { 5 | puts (" shl"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funshr.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_shr () 4 | { 5 | puts (" shr"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funsm.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_sm () 4 | { 5 | puts (" sm"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funsmeq.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_smeq () 4 | { 5 | puts (" smeq"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funsub.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_sub () 4 | { 5 | puts (" sub"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funumin.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_umin () 4 | { 5 | puts (" umin"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funxor.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_xor () 4 | { 5 | puts (" xor"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/funyoung.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | void fun_younger () 4 | { 5 | puts (" younger"); 6 | } 7 | -------------------------------------------------------------------------------- /icmake/un/icm_bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . ../bootstrap/functions 4 | . ../bootstrap/flags 5 | 6 | echo Creating tmp/${BINDIR}/icmun 7 | 8 | echo -n . 9 | try ${CC} ${CFLAGS} -o ../tmp/${LIBDIR}/icmun *.c ../tmp/libicrss.a \ 10 | ${LDFLAGS} 11 | echo . 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /icmake/un/icmconf: -------------------------------------------------------------------------------- 1 | #define USE_ECHO ON 2 | #define MAIN "main.c" 3 | #define REFRESH 4 | #define COMPILER "gcc" 5 | #define COMPILER_OPTIONS "-Wall -O2 -Werror -fdiagnostics-color=never" 6 | #define SOURCES "*.c" 7 | #define LINKER_OPTIONS "-s" 8 | #define ADD_LIBRARIES "icrss" 9 | #define ADD_LIBRARY_PATHS "../../tmp" 10 | #define CLS 11 | #define TMP_DIR "tmp" 12 | #define LIBRARY "modules" 13 | #define OBJ_EXT ".o" 14 | #define DEFCOM "program" 15 | -------------------------------------------------------------------------------- /icmake/un/varname.c: -------------------------------------------------------------------------------- 1 | #include "icmun.ih" 2 | 3 | char *varname (type) 4 | ExprType type; 5 | { 6 | if (type & e_str) 7 | return ("string"); 8 | if (type & e_int) 9 | return ("int"); 10 | return ("list"); 11 | } 12 | -------------------------------------------------------------------------------- /icmake/usr/share/icmake/frame: -------------------------------------------------------------------------------- 1 | #include "main.ih" 2 | -------------------------------------------------------------------------------- /icmake/usr/share/icmake/main.cc: -------------------------------------------------------------------------------- 1 | #include "main.ih" 2 | 3 | int main(int argc, char **argv) 4 | try 5 | { 6 | } 7 | catch (...) 8 | { 9 | return 1; 10 | } 11 | -------------------------------------------------------------------------------- /icmake/usr/share/icmake/main.ih: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace Icmbuild 5 | { 6 | extern char version[]; 7 | extern char years[]; 8 | extern char author[]; 9 | }; 10 | 11 | void usage(std::string const &progname); 12 | 13 | using namespace std; 14 | -------------------------------------------------------------------------------- /icmake/usr/share/icmake/scanner/lexer: -------------------------------------------------------------------------------- 1 | %filenames scanner 2 | 3 | //%interactive 4 | //%debug 5 | 6 | %% 7 | 8 | [ \t]+ // Often used: skip white space 9 | \n // same 10 | -------------------------------------------------------------------------------- /icmake/usr/share/icmake/scanner/scanner.ih: -------------------------------------------------------------------------------- 1 | // Declare here 2 | // what's only used in the Scanner class 3 | // and let Scanner's sources include "scanner.ih" 4 | 5 | #include "scanner.h" 6 | 7 | //#include "../parser/parserbase.h" 8 | 9 | // end of scanner.ih 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /icmake/usr/share/icmake/version.cc: -------------------------------------------------------------------------------- 1 | // version.cc 2 | 3 | #include "main.ih" 4 | #include "icmconf" 5 | 6 | #ifdef USE_VERSION 7 | #include "VERSION" 8 | #endif 9 | 10 | #ifndef AUTHOR 11 | #define AUTHOR "" 12 | #endif 13 | 14 | #ifndef VERSION 15 | #define VERSION "0.00.00" 16 | #endif 17 | 18 | #ifndef YEARS 19 | #define YEARS "2012" 20 | #endif 21 | 22 | namespace Icmbuild 23 | { 24 | char version[] = VERSION; 25 | char years[] = YEARS; 26 | 27 | char author[] = AUTHOR; 28 | } 29 | -------------------------------------------------------------------------------- /manpages: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ icmake/VERSION -nt icmake/doc/icmake.1 ] 4 | then 5 | cd icmake/doc/manpage 6 | ./build 7 | fi 8 | --------------------------------------------------------------------------------