1 Star 0 Fork 0

Li.XiongHui/juicescript

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
elang.c 239.52 KB
一键复制 编辑 原始数据 按行查看 历史
Li.XiongHui 提交于 2024-02-19 16:44 . feat(JuiceScript): add new release
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301
/*
* Copyright 2023 Li.Xionghui Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "elang.h"
#define LIB_MODE 1
#ifndef LIB_MODE
#include <ncurses.h>
#else
#define echo();
#define endwin();
#endif
#ifndef EL_MCU_MODE
#include <errno.h>
#endif
#define OPEN_API_DEFAULT
#define OPEN_API_HIDDEN
#define GC_ENABLE_ON_EXEC_TIME 1
#define GC_DEBUG 1
#define KEY_ESCAPE 27
#define KEY_RETURN 10
#define CTRL(X) ((X)&0x01f)
#define el_uint32_t uint32_t
#define el_int32_t int32_t
#define el_id_hash_type_t el_uint32_t
#ifndef LEX_PARSE_BUFF_SIZE
#define LEX_PARSE_BUFF_SIZE (2048)
#endif
#ifndef EL_MCU_MODE
#define el_sscanf(...) sscanf(__VA_ARGS__)
#define el_errno errno
#define EL_ERANGE ERANGE
#else
extern int el_errno;
extern int EL_ERANGE;
extern int el_sscanf(const char *str, const char *format, ...);
#endif
#ifndef EL_MEM_ALLOC_CHECK
#define EL_MEM_ALLOC_CHECK do{}while(0);
#endif
#ifndef EL_ROM_SIZE
#define EL_ROM_SIZE (10*1024)
#endif
#ifndef EL_STACK_SIZE
#define EL_STACK_SIZE (10*1024)
#endif
#define elang_stack_t el_uint32_t
#ifdef CLOSE_PRINTF
#define printf(...)
#endif
#ifndef EL_MAX_LOOKAHEAD_CNT
#define EL_MAX_LOOKAHEAD_CNT 3 // 鏈€澶ф敮鎸佸悜鍓嶇洿鎺ユ煡鐪嬪灏戝瓧绗�
#endif
#ifndef EL_FILE_BUFSIZE
#define EL_FILE_BUFSIZE 100*1024 // 鏂囦欢缂撳啿鍖哄ぇ灏�
#endif
#define MEM_USED_CHECK 0
#if MEM_USED_CHECK == 0
#ifndef EL_MEM
#define el_malloc(a) malloc(a) // 鍐呭瓨鐢宠
#define el_free(...) free(__VA_ARGS__) // 鍐呭瓨閲婃斁
#define el_realloc(...) realloc(__VA_ARGS__)
#define el_calloc(...) calloc(__VA_ARGS__)
#define el_exit(...) exit(__VA_ARGS__)
#else
extern void *el_malloc(size_t);
extern void el_free(void* );
extern void* el_realloc(void*,size_t);
extern void* el_calloc(size_t,size_t);
extern void el_exit(int);
#endif
#define el_strcat(...) strcat(__VA_ARGS__)
#define el_strlen(...) strlen(__VA_ARGS__)
#define el_strcpy(...) strcpy(__VA_ARGS__)
#define el_memcpy(...) memcpy(__VA_ARGS__)
#else
static int global_mem_used_bytes = 0;
static int global_mem_used_bytes_after_parse = 0;
void* el_malloc(a){
global_mem_used_bytes += a;
return malloc(a);
}
#define el_free(...) do{global_mem_used_bytes -= malloc_usable_size(__VA_ARGS__);free(__VA_ARGS__);}while(0) // 鍐呭瓨閲婃斁
#define el_strcat(...) strcat(__VA_ARGS__)
#define el_strlen(...) strlen(__VA_ARGS__)
#define el_realloc(...) realloc(__VA_ARGS__)
void* el_calloc(size_t a,size_t b){
global_mem_used_bytes += a * b;
return calloc(a,b);
}
#define el_strcpy(...) strcpy(__VA_ARGS__)
#define el_memcpy(...) memcpy(__VA_ARGS__)
#endif
#define el_size_t size_t
#ifndef LIB_MODE
#define el_printf(...) do{printw(__VA_ARGS__);fprintf(log_fp,__VA_ARGS__);fflush(log_fp);}while(0)
#else
#define el_printf(...) do{}while(0)
#endif
#define el_strcmp(...) strcmp(__VA_ARGS__)
#define EL_TRUE 1
#define EL_FALSE 0
#define EL_EOF EOF
#define EL_HEX2NUM(hex) ((hex >= '0' && hex <= '9') ? (hex - '0') : ((hex >= 'a' && hex <= 'z') ? (hex - 'a' + 10) : ((hex >= 'A' && hex <= 'Z') ? (hex - 'A' + 10) : (0))))
#define EL_IS_HEX(hex) ((hex >= '0' && hex <= '9') || (hex >= 'a' && hex <= 'f') || (hex >= 'A' && hex <= 'F'))
#define EL_IS_OCT(hex) (hex >= '0' && hex <= '7')
static FILE *log_fp;
OPEN_API_HIDDEN static const char* elang_vm_instr_str[] = {
"EL_VM_INSTR_RESET",
"EL_VM_INSTR_EXT",
"EL_VM_INSTR_DATA",
"EL_VM_INSTR_LOAD_STR",
"EL_VM_INSTR_LOAD_CHAR",
"EL_VM_INSTR_PUSH_NUM",
"EL_VM_INSTR_JZ",
"EL_VM_INSTR_JNZ",
"EL_VM_INSTR_JMP",
"EL_VM_INSTR_ADD",
"EL_VM_INSTR_SUB",
"EL_VM_INSTR_MUL",
"EL_VM_INSTR_DIV",
"EL_VM_INSTR_MOD",
"EL_VM_INSTR_LSHIFT",
"EL_VM_INSTR_RSHIFT",
"EL_VM_INSTR_NOT_EQ",
"EL_VM_INSTR_EQ",
"EL_VM_INSTR_BITOR",
"EL_VM_INSTR_OR",
"EL_VM_INSTR_BITAND",
"EL_VM_INSTR_AND",
"EL_VM_INSTR_XOR",
"EL_VM_INSTR_SIZEOF",
"EL_VM_INSTR_LT",
"EL_VM_INSTR_GT",
"EL_VM_INSTR_LE",
"EL_VM_INSTR_GE",
"EL_VM_INSTR_CALL",
"EL_VM_INSTR_RET",
"EL_VM_INSTR_MALLOC",
"EL_VM_INSTR_RECOVER_SP_FROM_TP",
"EL_VM_INSTR_PUSH_SP_SET_TP",
"EL_VM_INSTR_PUSH_RA",
"EL_VM_INSTR_PUSH_PC",
"EL_VM_INSTR_POP2LOCALVAR",
"EL_VM_INSTR_POP2GLOBALVAR",
"EL_VM_INSTR_PUSH_LOCALVAR",
"EL_VM_INSTR_PUSH_GLOBALVAR",
"EL_VM_INSTR_NIL2LOCALVAR",
"EL_VM_INSTR_NIL2GLOBALVAR",
"EL_VM_INSTR_PUSH_INSTR_SPACE_ID",
"EL_VM_INSTR_PUSH_INT",
"EL_VM_INSTR_NUM2VAR",
"EL_VM_INSTR_POP",
"EL_VM_INSTR_STR_ARR_SPILT",
"EL_VM_INSTR_STR_ARR_GETCHAR",
"EL_VM_INSTR_STR_ARR_SIZE",
"EL_VM_INSTR_NUM_TO_STR_ARR",
"EL_VM_INSTR_EXT_CALL",
"EL_VM_INSTR_POP2LIST",
"EL_VM_INSTR_POP2LIST_OFFSET",
"EL_VM_INSTR_POP2LIST_OFFSET_ONE_ITEM",
"EL_VM_INSTR_PUSH_NIL",
"EL_VM_INSTR_PUSH_STR",
"EL_VM_INSTR_JMP_LABEL",
};
enum elang_vm_instr{
EL_VM_INSTR_RESET = 0,
EL_VM_INSTR_EXT = 1, // 鐣欑粰浠ュ悗鎷撳睍鎸囦护浣跨敤
EL_VM_INSTR_DATA = 2, // 鎸囦护鍚庣画鐨勬暟鎹�
EL_VM_INSTR_LOAD_STR = 3,
EL_VM_INSTR_LOAD_CHAR = 4,
EL_VM_INSTR_PUSH_NUM = 5, // OPCODE NUM_L32, (float)number=NUM_L32;
EL_VM_INSTR_JZ = 6,
EL_VM_INSTR_JNZ = 7,
EL_VM_INSTR_JMP = 8,
EL_VM_INSTR_ADD = 9,
EL_VM_INSTR_SUB = 10,
EL_VM_INSTR_MUL = 11,
EL_VM_INSTR_DIV = 12,
EL_VM_INSTR_MOD = 13,
EL_VM_INSTR_LSHIFT = 14,
EL_VM_INSTR_RSHIFT = 15,
EL_VM_INSTR_NOT_EQ = 16,
EL_VM_INSTR_EQ = 17,
EL_VM_INSTR_BITOR = 18,
EL_VM_INSTR_OR = 19,
EL_VM_INSTR_BITAND = 20,
EL_VM_INSTR_AND = 21,
EL_VM_INSTR_XOR = 22,
EL_VM_INSTR_SIZEOF = 23,
EL_VM_INSTR_LT = 24,
EL_VM_INSTR_GT = 25, // GREAT THAN
EL_VM_INSTR_LE = 26, // LESS EQUAL
EL_VM_INSTR_GE = 27, // GREAT EQUAL
EL_VM_INSTR_CALL = 28, // same as jmp
EL_VM_INSTR_RET = 29, // 鍦╯*****妯″紡涓嬶紝璁块棶鐨勯亶鍘嗗湴鍧€鏄� tp+*tp,鍦ㄨ櫄鎷熸満閲屾槸 tp+*tp
EL_VM_INSTR_MALLOC = 30,
EL_VM_INSTR_RECOVER_SP_FROM_TP = 31,
EL_VM_INSTR_PUSH_SP_SET_TP = 32, // 鍦╯*****妯″紡涓嬮渶瑕佷竴骞舵妸instr_space_handle杩涙爤,灏辨槸闇€瑕佹妸 (*(states->tmp_var_list))->body.global_index,鍏ユ爤
EL_VM_INSTR_PUSH_RA = 33,
EL_VM_INSTR_PUSH_PC = 34,
EL_VM_INSTR_POP2LOCALVAR = 35, // 鍦╯*****妯″紡涓嬶紝璁块棶鐨勯亶鍘嗗湴鍧€鏄� tp+offset,鍦ㄨ櫄鎷熸満閲屾槸 tp+offset
EL_VM_INSTR_POP2GLOBALVAR = 36,
EL_VM_INSTR_PUSH_LOCALVAR = 37, // 鍦╯*****妯″紡涓嬶紝璁块棶鐨勯亶鍘嗗湴鍧€鏄� tp+offset,鍦ㄨ櫄鎷熸満閲屾槸 tp+offset
EL_VM_INSTR_PUSH_GLOBALVAR = 38,
EL_VM_INSTR_NIL2LOCALVAR = 39, // 鍦╯*****妯″紡涓嬶紝璁块棶鐨勯亶鍘嗗湴鍧€鏄� tp+offset,鍦ㄨ櫄鎷熸満閲屾槸 tp+offset
EL_VM_INSTR_NIL2GLOBALVAR = 40,
EL_VM_INSTR_PUSH_INSTR_SPACE_ID = 41,
EL_VM_INSTR_PUSH_INT = 42,
EL_VM_INSTR_NUM2VAR = 43,
EL_VM_INSTR_POP = 44, // 鍑烘爤锛岃垗寮�
EL_VM_INSTR_STR_ARR_SPILT = 45,
EL_VM_INSTR_STR_ARR_GETCHAR = 46,
EL_VM_INSTR_STR_ARR_SIZE = 47,
EL_VM_INSTR_NUM_TO_STR_ARR = 48,
EL_VM_INSTR_EXT_CALL = 49,
EL_VM_INSTR_POP2LIST = 50,
EL_VM_INSTR_POP2LIST_OFFSET = 51,
EL_VM_INSTR_POP2LIST_OFFSET_ONE_ITEM = 52,
EL_VM_INSTR_PUSH_NIL = 53,
EL_VM_INSTR_PUSH_STR = 54,
EL_VM_INSTR_JMP_LABEL = 55,
};
typedef enum elang_vm_instr elang_vm_instr_t;
OPEN_API_HIDDEN static const char* elang_token_type_str[] = {
"EL_TOKEN_NONE",
"EL_TOKEN_ID",
"EL_TOKEN_NUM",
"EL_TOKEN_BIN_NUM",
"EL_TOKEN_DECIMAL_NUM",
"EL_TOKEN_OCTAL_NUM",
"EL_TOKEN_HEX_NUM",
"EL_TOKEN_CHAR",
"EL_TOKEN_STR",
"EL_TOKEN_SEMICOLON",
"EL_TOKEN_PLUS",
"EL_TOKEN_MINUS",
"EL_TOKEN_MUL",
"EL_TOKEN_DIV",
"EL_TOKEN_LSHIFT",
"EL_TOKEN_RSHIFT",
"EL_TOKEN_MOD",
"EL_TOKEN_LPAREN",
"EL_TOKEN_RPAREN",
"EL_TOKEN_LBRACKET",
"EL_TOKEN_RBRACKET",
"EL_TOKEN_BITOR",
"EL_TOKEN_BITAND",
"EL_TOKEN_AND",
"EL_TOKEN_OR",
"EL_TOKEN_ASSIGN",
"EL_TOKEN_EQUAL",
"EL_TOKEN_NOT_EQUAL",
"EL_TOKEN_GREAT",
"EL_TOKEN_LESS",
"EL_TOKEN_GREAT_EQ",
"EL_TOKEN_LESS_EQ",
"EL_TOKEN_XOR",
"EL_TOKEN_BITNOT",
"EL_TOKEN_LEFT_CENTER_BRACKET",
"EL_TOKEN_RIGH_CENTER_BRACKET",
"EL_TOKEN_NOT",
"EL_TOKEN_COMMA",
"EL_TOKEN_NIL",
// "EL_TOKEN_RET",
"EL_TOKEN_BREAK",
"EL_TOKEN_COLON",
"EL_TOKEN_MAX"
};
enum elang_token_type{
EL_TOKEN_NONE,
EL_TOKEN_ID,
EL_TOKEN_NUM,
EL_TOKEN_BIN_NUM,
EL_TOKEN_DECIMAL_NUM,
EL_TOKEN_OCTAL_NUM,
EL_TOKEN_HEX_NUM,
EL_TOKEN_CHAR, // ''
EL_TOKEN_STR,
EL_TOKEN_SEMICOLON, // ;
EL_TOKEN_PLUS, // +
EL_TOKEN_MINUS, // -
EL_TOKEN_MUL, // *
EL_TOKEN_DIV, // /
EL_TOKEN_LSHIFT, // <<
EL_TOKEN_RSHIFT, // >>
EL_TOKEN_MOD, // %
EL_TOKEN_LPAREN, // (
EL_TOKEN_RPAREN, // )
EL_TOKEN_LBRACKET, // {
EL_TOKEN_RBRACKET, // }
EL_TOKEN_BITOR, // |
EL_TOKEN_BITAND, // &
EL_TOKEN_AND, // &&
EL_TOKEN_OR, // ||
EL_TOKEN_ASSIGN, // =
EL_TOKEN_EQUAL, // ==
EL_TOKEN_NOT_EQUAL, // !=
EL_TOKEN_GREAT, // >
EL_TOKEN_LESS, // <
EL_TOKEN_GREAT_EQ, // >=
EL_TOKEN_LESS_EQ, // <=
EL_TOKEN_XOR, // ^
EL_TOKEN_BITNOT, // !
EL_TOKEN_LEFT_CENTER_BRACKET, // [
EL_TOKEN_RIGH_CENTER_BRACKET, // ]
EL_TOKEN_NOT, // ~
EL_TOKEN_COMMA, // ,
EL_TOKEN_NIL, // nil
// EL_TOKEN_RET, // ret
EL_TOKEN_BREAK,
EL_TOKEN_COLON,
EL_TOKEN_MAX
};
typedef enum elang_token_type elang_token_type_t;
enum elang_stream_type{
EL_STREAM_TYPE_STRING = 0,
EL_STREAM_TYPE_FILE = 1
};
typedef enum elang_stream_type elang_stream_type_t;
struct elang_char_stream {
elang_stream_type_t stream_type;
union {
struct {
FILE* fp; // 鏂囦欢鍙ユ焺
char buf[EL_FILE_BUFSIZE]; // 鏂囦欢缂撳啿鍖�
el_uint32_t char_cnt; // 褰撳墠缂撳啿鍖哄瓧绗︽暟閲�
el_uint32_t cur_sor; // 褰撳墠鎸囬拡
} file;
struct {
char* origin_str;
char* cur_str;
} str;
} src;
/* cache buffer */
char ringbuf[EL_MAX_LOOKAHEAD_CNT]; // 鐢ㄤ簬鍚戝墠鏌ョ湅鐨剅ingbuf
el_uint32_t ring_head;
el_uint32_t cached_cnt;
};
typedef struct elang_char_stream elang_char_stream_t;
OPEN_API_HIDDEN const char* keyword_str[] = {
"EL_KW_ID",
"EL_KW_FUNC",
"EL_KW_IF",
"EL_KW_ELSE",
"EL_KW_ELIF",
"EL_KW_WHILE",
"EL_KW_RET",
"EL_KW_DO",
"EL_KW_NIL",
};
enum keyword{
EL_KW_ID = 0,
EL_KW_FUNC,
EL_KW_IF,
EL_KW_ELSE,
EL_KW_ELIF,
EL_KW_WHILE,
EL_KW_RET,
EL_KW_DO,
EL_KW_NIL,
};
typedef enum keyword keyword_t;
struct elang_token{
struct elang_token* next;
elang_token_type_t type;
union {
struct {
// double v;
float v;
}_num;
struct {
char c;
}_char;
struct {
const char* str;
}_str;
struct {
keyword_t is_keyword;
const char* str;
el_id_hash_type_t hash;
}_id;
}token;
};
typedef struct elang_token elang_token_t;
struct elang_tmp_label{
struct elang_tmp_label* next;
uint8_t addrh;
uint8_t addrm;
uint8_t addrl;
el_uint32_t label_idx;
};
typedef struct elang_tmp_label elang_tmp_label_t;
struct elang_label{
struct elang_label* next;
el_id_hash_type_t hash;
el_uint32_t label_addr;
};
typedef struct elang_label elang_label_t;
OPEN_API_HIDDEN static const char* elang_lex_state_str[] = {
"EL_LEX_S_SELF",
"EL_LEX_S_START",
"EL_LEX_S_END_STR",
"EL_LEX_S_END_START",
"EL_LEX_S_END",
"EL_LEX_S_END_RESTART",
"EL_LEX_S_STR_START",
"EL_LEX_S_STR",
"EL_LEX_S_STR_ESCAPE",
"EL_LEX_S_STR_NEWLINE",
"EL_LEX_S_COMENT",
"EL_LEX_S_COMENT1",
"EL_LEX_S_ID",
"EL_LEX_S_ASSIGN",
"EL_LEX_S_OCTAL_NUM_TEST",
"EL_LEX_S_OCTAL_NUM",
"EL_LEX_S_DECIMAL_NUM",
"EL_LEX_S_HEX_NUM",
"EL_LEX_S_HEX_NUM1",
"EL_LEX_S_BIN_NUM",
"EL_LEX_S_STR_EOF",
"EL_LEX_S_BITAND",
"EL_LEX_S_BITOR",
"EL_LEX_S_NOT",
"EL_LEX_S_LESS",
"EL_LEX_S_GREAT",
"EL_LEX_S_CHAR_START",
"EL_LEX_S_CHAR",
"EL_LEX_S_CHAR_ESCAPE",
"EL_LEX_S_MAX"
};
enum elang_lex_state {
EL_LEX_S_SELF = 0,
EL_LEX_S_START,
EL_LEX_S_END_STR,
EL_LEX_S_END_START,
EL_LEX_S_END_RESTART,
EL_LEX_S_END,
EL_LEX_S_STR_START,
EL_LEX_S_STR,
EL_LEX_S_STR_ESCAPE,
EL_LEX_S_STR_NEWLINE,
EL_LEX_S_COMENT,
EL_LEX_S_COMENT1,
EL_LEX_S_ID,
EL_LEX_S_ASSIGN,
EL_LEX_S_OCTAL_NUM_TEST,
EL_LEX_S_OCTAL_NUM,
EL_LEX_S_DECIMAL_NUM,
EL_LEX_S_HEX_NUM,
EL_LEX_S_HEX_NUM1,
EL_LEX_S_BIN_NUM,
EL_LEX_S_STR_EOF,
EL_LEX_S_BITAND,
EL_LEX_S_BITOR,
EL_LEX_S_NOT,
EL_LEX_S_LESS,
EL_LEX_S_GREAT,
EL_LEX_S_CHAR_START,
EL_LEX_S_CHAR,
EL_LEX_S_CHAR_ESCAPE,
EL_LEX_S_MAX
};
typedef enum elang_lex_state elang_lex_state_t;
struct elang_lex_char_buff {
char* ptrdata;
el_size_t capacity;
el_size_t itemcnt;
};
typedef struct elang_lex_char_buff elang_lex_char_buff_t;
struct elang_vm_reg {
el_uint32_t pc;
el_uint32_t sp;
el_uint32_t tp;
};
typedef struct elang_vm_reg elang_vm_reg_t;
enum elang_data_type {
ELANG_TYPE_STR,
ELANG_TYPE_NUM,
ELANG_TYPE_NIL,
ELANG_TYPE_CHAR,
ELANG_TYPE_LIST,
};
typedef enum elang_data_type elang_data_type_t;
struct elang_data_list {
struct elang_data_list* next;
struct elang_data_list* parent;
struct elang_data_list* child;
struct {
elang_data_type_t type;
struct {
float v;
}_num;
struct {
char c;
}_char;
struct {
const char* str;
}_str;
}body;
};
typedef struct elang_data_list elang_data_list_t;
struct elang_instr_space{
union{
struct{
uint8_t opcode;
union{
struct {
uint8_t reserve1;
uint8_t reserve2;
uint8_t reserve3;
}ADD; // RESET,EXT,ADD,SUBMUL,DIV,MOD,LSHIFT,RSHIFT,NOT_EQ,EQ,BITOR,OR,BITAND,AND,XOR,LT,GT,LE,GE,RET,RECOVER_SP_FROM_TP,PUSH_SP_SET_TP,PUSH_RA,PUSH_PC,PUSH_INT,STR_ARR_SIZE
struct {
uint8_t h;
uint8_t m;
uint8_t l;
}DATA;
struct {
uint8_t addrh;
uint8_t addrm;
uint8_t addrl;
}JNZ;
struct {
uint8_t addrh;
uint8_t addrm;
uint8_t addrl;
}JZ;
struct {
uint8_t addrh;
uint8_t addrm;
uint8_t addrl;
}JMP;
struct {
uint8_t addrh;
uint8_t addrm;
uint8_t addrl;
}CALL;
struct {
uint8_t addrh;
uint8_t addrm;
uint8_t addrl;
}EXT_CALL;
struct {
uint8_t item_addrh;
uint8_t item_addrm;
uint8_t item_addrl;
}SIZEOF;
struct {
uint16_t size;
}MALLOC;
struct {
uint16_t var_offset;
}POP2LOCALVAR;
struct {
uint16_t var_offset;
}POP2GLOBALVAR;
struct {
uint16_t var_offset;
}PUSH_LOCALVAR;
struct {
uint16_t var_offset;
}PUSH_GLOBALVAR;
struct {
uint16_t var_offset;
}NIL2LOCALVAR;
struct {
uint16_t var_offset;
}NIL2GLOBALVAR;
struct {
uint16_t items_cnt;
}POP2LIST;
struct {
uint16_t items_cnt;
}POP2LIST_OFFSET;
}arg;
}instr_s;
uint32_t instr;
};
};
typedef struct elang_instr_space elang_instr_space_t;
enum elang_var_list_type{
EL_VAR_LIST_FUNCTION,
EL_VAR_LIST_VAR,
EL_VAR_LIST_ARG,
};
typedef enum elang_var_list_type elang_var_list_type_t;
struct elang_var_list {
struct elang_var_list* next;
struct elang_var_list* child;
struct {
elang_var_list_type_t var_list_type;
el_id_hash_type_t hash;
elang_data_type_t type;
el_uint32_t index;
el_uint32_t arg_var_index;
el_uint32_t global_index;
struct {
float v;
}_num;
struct {
char c;
}_char;
struct {
const char* str;
}_str;
el_uint32_t cur_instr_sor;
elang_instr_space_t *instr_space;
}body;
};
typedef struct elang_var_list elang_var_list_t;
struct elang_function{
struct elang_function* next;
el_id_hash_type_t hash;
elang_label_t* label;
el_uint32_t arg_num;
el_uint32_t local_variable_num;
};
typedef struct elang_function elang_function_t;
struct elang_mem_pool{
struct elang_mem_pool* next;
el_id_hash_type_t hash;
elang_data_type_t type;
el_uint32_t index;
el_uint32_t size;
el_uint32_t gc_flag;
unsigned char* data;
};
typedef struct elang_mem_pool elang_mem_pool_t;
struct elang_ext_func_list{
struct elang_ext_func_list* next;
el_id_hash_type_t hash;
el_uint32_t func_index;
int (*cb)(void* vm);
};
typedef struct elang_ext_func_list elang_ext_func_list_t;
struct elang_states {
elang_char_stream_t cs;
// lex
elang_token_t* tok_list;
elang_token_t* sh_cur_list;
elang_lex_state_t lex_state;
elang_token_type_t token_type;
elang_lex_char_buff_t lex_char_buff;
// parse
int on_shell_mode;
int last_compile_enable;
el_size_t nest_cnt;
el_uint32_t global_tmp_label_index;
elang_tmp_label_t* global_tmp_label;
// info
el_uint32_t global_var_list_index;
elang_label_t* global_label;
el_uint32_t tmp_local_var; // 鐢卞嚱鏁板唴閮ㄧ殑灞€閮ㄥ彉閲忓畾涔夎鏁颁娇鐢�
elang_var_list_t* root_var_list;
elang_var_list_t** tmp_var_list;
el_uint32_t global_instr_count;
// shell
el_uint32_t* sh_cur_instr_sor;
elang_instr_space_t* sh_instr_space;
el_uint32_t* global_index;
// vm
el_uint32_t cur_instr_sor;
elang_instr_space_t instr_space[EL_ROM_SIZE];
elang_data_list_t* data_root;
elang_mem_pool_t* mem_pool;
el_uint32_t mem_pool_index;
elang_vm_reg_t regs;
elang_stack_t stack[EL_STACK_SIZE]; // 32bit, = mem_pool_index
elang_ext_func_list_t* ext_func_list;
el_uint32_t ext_func_index;
struct elang_states** states_p;
el_uint32_t ext_return_var;
};
typedef struct elang_states elang_states_t;
OPEN_API_HIDDEN static el_uint32_t elang_mem_total_used(elang_states_t* states,el_uint32_t* item){
elang_mem_pool_t* tmp_mem;
el_uint32_t size;
size = 0;
*item = 0;
tmp_mem = states->mem_pool;
while(tmp_mem){
size += tmp_mem->size;
(*item)++;
tmp_mem = tmp_mem->next;
}
return size;
}
OPEN_API_HIDDEN static int elang_mem_pool_delete(elang_states_t* states,elang_mem_pool_t* mem_pool){
elang_mem_pool_t* tmp_mem;
elang_mem_pool_t* last_mem;
if(states->mem_pool == mem_pool){
states->mem_pool = states->mem_pool->next;
el_free(mem_pool->data);
el_free(mem_pool);
return 0;
}
last_mem = states->mem_pool;
tmp_mem = states->mem_pool->next;
while(tmp_mem){
if(tmp_mem == mem_pool){
last_mem->next = mem_pool->next;
if(mem_pool->data){
el_free(mem_pool->data);
}
el_free(mem_pool);
return 0;
}
last_mem = tmp_mem;
tmp_mem = tmp_mem->next;
}
return -1;
}
OPEN_API_HIDDEN static int elang_mem_pool_gc_release(elang_states_t* states){
elang_mem_pool_t* tmp_mem;
elang_mem_pool_t* tmp_mem2;
tmp_mem = states->mem_pool;
while(tmp_mem){
if(tmp_mem->gc_flag == EL_FALSE){
tmp_mem2 = tmp_mem;
tmp_mem = tmp_mem->next;
elang_mem_pool_delete(states,tmp_mem2);
}else{
tmp_mem = tmp_mem->next;
}
}
return 0;
}
OPEN_API_HIDDEN static int elang_mem_pool_gcflag_clear(elang_states_t* states){
elang_mem_pool_t* tmp_mem;
tmp_mem = states->mem_pool;
while(tmp_mem){
tmp_mem->gc_flag = EL_FALSE;
tmp_mem = tmp_mem->next;
}
return 0;
}
OPEN_API_HIDDEN static elang_mem_pool_t* elang_var_searchbyindex(elang_states_t* states,el_uint32_t index) {
elang_mem_pool_t* tmp_mem_pool;
if(states->mem_pool == NULL){
return NULL;
}
tmp_mem_pool = states->mem_pool;
while(tmp_mem_pool){
if(tmp_mem_pool->index == index){
return tmp_mem_pool;
}
tmp_mem_pool = tmp_mem_pool->next;
}
return NULL;
}
OPEN_API_HIDDEN static int elang_mem_pool_gcflag_mark_list(elang_states_t* states,el_uint32_t list_index){
elang_mem_pool_t* tmp_mem;
elang_mem_pool_t* tmp_mem2;
el_uint32_t* tmp_index_p;
el_uint32_t pos;
pos = 0;
tmp_mem = elang_var_searchbyindex(states,list_index);
tmp_index_p = tmp_mem->data;
tmp_mem->gc_flag = EL_TRUE;
while(pos < (tmp_mem->size / 4)){
tmp_mem2 = elang_var_searchbyindex(states,*tmp_index_p);
if(tmp_mem2){
tmp_mem2->gc_flag = EL_TRUE;
if(tmp_mem2->type == ELANG_TYPE_LIST){
elang_mem_pool_gcflag_mark_list(states,*tmp_index_p);
}
}
tmp_index_p += 1;
pos++;
}
}
OPEN_API_HIDDEN static int elang_mem_pool_gcflag_mark(elang_states_t* states){
elang_mem_pool_t* tmp_mem;
el_uint32_t arg_n;
el_uint32_t last_tp;
el_uint32_t last_sp;
el_uint32_t tp;
el_uint32_t sp;
el_uint32_t tmp_pos;
tp = states->regs.tp;
sp = states->regs.sp;
while(1){
arg_n = states->stack[tp];
if(tp > 2){
last_tp = states->stack[tp - 3];
last_sp = states->stack[tp - 2];
}
if(tp > sp){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_pos = tp + 1;
while(arg_n && arg_n--){
tmp_mem = elang_var_searchbyindex(states,(el_uint32_t)(states->stack[tmp_pos]));
if(tmp_mem){
tmp_mem->gc_flag = EL_TRUE;
if(tmp_mem->type == ELANG_TYPE_LIST){
elang_mem_pool_gcflag_mark_list(states,(el_uint32_t)(states->stack[tmp_pos]));
}
}
tmp_pos++;
}
while(tmp_pos < sp){
tmp_mem = elang_var_searchbyindex(states,(el_uint32_t)(states->stack[tmp_pos]));
if(tmp_mem){
tmp_mem->gc_flag = EL_TRUE;
if(tmp_mem->type == ELANG_TYPE_LIST){
elang_mem_pool_gcflag_mark_list(states,(el_uint32_t)(states->stack[tmp_pos]));
}
}
tmp_pos++;
}
if(tp <= 2){
break;
}
tp = last_tp;
sp = last_sp;
}
return 0;
}
#define log_pre(); for(tmp_level=0;tmp_level<level;tmp_level++){el_printf(" ");}
OPEN_API_HIDDEN static int elang_print_list(elang_states_t* states,el_uint32_t list_num,el_uint32_t level){
el_uint32_t pos;
float* tmp_f;
elang_mem_pool_t* tmp_mem;
elang_mem_pool_t* tmp_mem2;
el_uint32_t tmp_level;
el_uint32_t* tmp_u32_p;
el_uint32_t tmp_u32;
pos = 0;
tmp_mem = elang_var_searchbyindex(states,list_num);
if(tmp_mem){
while(pos < (tmp_mem->size/4)){
tmp_u32_p = tmp_mem->data;
tmp_u32 = *(tmp_u32_p +pos);
log_pre();el_printf("^^^^^ %d: \n",pos);
log_pre();el_printf(" number: 0x%lx (%d)\n",tmp_u32,tmp_u32);
tmp_mem2 = elang_var_searchbyindex(states,tmp_u32);
if(tmp_mem2){
log_pre();el_printf(" gc_flag: %d\n",tmp_mem2->gc_flag);
log_pre();el_printf(" size: %d\n",tmp_mem2->size);
switch(tmp_mem2->type){
case ELANG_TYPE_STR:
if(*(tmp_mem2->data+tmp_mem2->size) == '\0'){
log_pre();el_printf(" str var(%d): %s\n",tmp_mem2->size,tmp_mem2->data);
}else{
log_pre();el_printf(" array var(%d\n",tmp_mem2->size);
}
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem2->data;
log_pre();el_printf(" float var: %f\n",*tmp_f);
break;
case ELANG_TYPE_LIST:
log_pre();el_printf(" list var: tmp_u32: 0x%lx\n",tmp_u32);
elang_print_list(states,tmp_u32,level + 4);
break;
case ELANG_TYPE_NIL:
log_pre();el_printf(" nil var: 0x%p\n",tmp_mem2->data);
break;
case ELANG_TYPE_CHAR:
log_pre();el_printf(" char var: 0x%x(%c)\n",*(tmp_mem2->data));
break;
}
}
pos++;
}
}
}
OPEN_API_HIDDEN static int elang_print_stack(elang_states_t* states){
el_uint32_t pos;
float* tmp_f;
elang_mem_pool_t* tmp_mem;
pos = 0;
el_printf("^^^^^^^^^^^^^^^^^^^^^^^ elang_print_stack: %d^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",states->regs.sp);
el_printf(" states->regs.tp: 0x%lx (%d)\n",states->regs.tp,states->regs.tp);
el_printf(" states->regs.sp: 0x%lx (%d)\n",states->regs.sp,states->regs.sp);
while(pos < states->regs.sp){
el_printf("^^^^^ %d: \n",pos);
el_printf(" number: 0x%lx (%d)\n",states->stack[pos],states->stack[pos]);
tmp_f = &(states->stack[pos]);
// el_printf(" float: %f\n",*tmp_f);
tmp_mem = elang_var_searchbyindex(states,states->stack[pos]);
if(tmp_mem){
el_printf(" gc_flag: %d\n",tmp_mem->gc_flag);
el_printf(" size: %d\n",tmp_mem->size);
switch(tmp_mem->type){
case ELANG_TYPE_STR:
if(*(tmp_mem->data+tmp_mem->size) == '\0'){
el_printf(" str var(%d): %s\n",tmp_mem->size,tmp_mem->data);
}else{
el_printf(" array var(%d\n",tmp_mem->size);
}
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
el_printf(" float var: %f\n",*tmp_f);
break;
case ELANG_TYPE_LIST:
el_printf(" list var: stack:0x%lx\n",states->stack[pos]);
elang_print_list(states,states->stack[pos],8);
break;
case ELANG_TYPE_NIL:
el_printf(" nil var: 0x%p\n",tmp_mem->data);
break;
case ELANG_TYPE_CHAR:
el_printf(" char var: 0x%x(%c)\n",*(tmp_mem->data));
break;
}
}
pos++;
}
return 0;
}
OPEN_API_HIDDEN static int elang_mem_pool_gc(elang_states_t* states){
elang_mem_pool_gcflag_clear(states);
elang_mem_pool_gcflag_mark(states);
elang_print_stack(states);
elang_mem_pool_gc_release(states);
}
OPEN_API_HIDDEN static int elang_print_mem_used(elang_states_t* states){
el_uint32_t item;
el_uint32_t size;
el_printf("\n****************** MEM ********************************************************************\n");
size = elang_mem_total_used(states,&item);
el_printf(" item: %d \n",item);
el_printf(" total used: %d Bytes\n",size);
// el_printf(" used: %d Bytes\n",elang_mem_used(states));
return 0;
}
OPEN_API_HIDDEN static el_uint32_t elang_vm_stack_push(elang_states_t* states,elang_stack_t item) {
if(states->regs.sp >= EL_STACK_SIZE){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
return 0;
}
states->stack[states->regs.sp] = item;
return states->regs.sp++;
}
OPEN_API_HIDDEN static elang_stack_t elang_vm_stack_pop(elang_states_t* states) {
return states->stack[--states->regs.sp];
}
OPEN_API_HIDDEN static elang_mem_pool_t* elang_var_new(elang_states_t* states,el_uint32_t hash,el_uint32_t size,elang_data_type_t type) {
elang_mem_pool_t* tmp_mem_pool;
elang_mem_pool_t* tmp_mem_pool_tail;
EL_MEM_ALLOC_CHECK;
tmp_mem_pool = (elang_mem_pool_t*) el_malloc(sizeof(elang_mem_pool_t));
if(tmp_mem_pool == NULL){
return NULL;
}
EL_MEM_ALLOC_CHECK;
tmp_mem_pool->data = (unsigned char *) el_calloc(size,sizeof(unsigned char));
if(tmp_mem_pool->data == NULL){
return NULL;
}
tmp_mem_pool->index = states->mem_pool_index;
states->mem_pool_index++;
tmp_mem_pool->hash = hash;
tmp_mem_pool->size = size;
tmp_mem_pool->type = type;
tmp_mem_pool->next = NULL;
if(states->mem_pool == NULL){
states->mem_pool = tmp_mem_pool;
return tmp_mem_pool;
}
tmp_mem_pool_tail = states->mem_pool;
while(tmp_mem_pool_tail->next){
tmp_mem_pool_tail = tmp_mem_pool_tail->next;
}
tmp_mem_pool_tail->next = tmp_mem_pool;
return tmp_mem_pool;
}
OPEN_API_HIDDEN static elang_var_list_t* elang_var_list_new(elang_states_t* states,elang_var_list_t** var_list) {
elang_var_list_t* tmp_var_list;
elang_var_list_t* tmp_var_list_tail;
el_uint32_t index;
el_uint32_t arg_var_index;
index = 0;
arg_var_index = 0;
EL_MEM_ALLOC_CHECK;
tmp_var_list = (elang_var_list_t*) el_malloc(sizeof(elang_var_list_t));
tmp_var_list->next = NULL;
tmp_var_list->child = NULL;
tmp_var_list->body.index = index;
tmp_var_list->body.cur_instr_sor = 0;
tmp_var_list->body.arg_var_index = arg_var_index;
tmp_var_list->body.global_index = states->global_var_list_index;
states->global_var_list_index++;
if((*var_list) == NULL){
*var_list = tmp_var_list;
return tmp_var_list;
}
tmp_var_list_tail = *var_list;
while(tmp_var_list_tail->next){
index++;
if(tmp_var_list_tail->body.var_list_type != EL_VAR_LIST_FUNCTION){
arg_var_index++;
}
tmp_var_list_tail = tmp_var_list_tail->next;
}
tmp_var_list_tail->next = tmp_var_list;
tmp_var_list->body.index = index;
tmp_var_list->body.arg_var_index = arg_var_index;
return tmp_var_list;
}
OPEN_API_HIDDEN static elang_var_list_t* elang_var_list_add_child(elang_states_t* states,elang_var_list_t* var_list) {
elang_var_list_t* tmp_var_list;
elang_var_list_t* tmp_var_list_tail;
el_uint32_t index;
el_uint32_t arg_var_index;
index = 0;
arg_var_index = 0;
EL_MEM_ALLOC_CHECK;
tmp_var_list = (elang_var_list_t*) el_malloc(sizeof(elang_var_list_t));
tmp_var_list->next = NULL;
tmp_var_list->child = NULL;
tmp_var_list->body.index = index;
tmp_var_list->body.cur_instr_sor = 0;
tmp_var_list->body.arg_var_index = arg_var_index;
tmp_var_list->body.global_index = states->global_var_list_index;
states->global_var_list_index++;
if(var_list == NULL){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
if(var_list->child == NULL){
var_list->child = tmp_var_list;
return tmp_var_list;
}
tmp_var_list_tail = var_list->child;
index++;
if(tmp_var_list_tail->body.var_list_type != EL_VAR_LIST_FUNCTION){
arg_var_index++;
}
while(tmp_var_list_tail->next){
index++;
if(tmp_var_list_tail->next->body.var_list_type != EL_VAR_LIST_FUNCTION){
arg_var_index++;
}
tmp_var_list_tail = tmp_var_list_tail->next;
}
tmp_var_list_tail->next = tmp_var_list;
tmp_var_list->body.index = index;
tmp_var_list->body.arg_var_index = arg_var_index;
return tmp_var_list;
}
OPEN_API_HIDDEN static elang_var_list_t* elang_var_list_search(elang_states_t* states,elang_var_list_t* var_list,el_id_hash_type_t hash) {
elang_var_list_t* tmp_var_list_tail;
if(var_list == NULL){
return NULL;
}
tmp_var_list_tail = var_list;
while(tmp_var_list_tail){
if(tmp_var_list_tail->body.hash == hash){
return tmp_var_list_tail;
}
tmp_var_list_tail = tmp_var_list_tail->next;
}
return NULL;
}
OPEN_API_HIDDEN static int elang_token2level(elang_token_type_t token){
switch(token){
case EL_TOKEN_NONE:
case EL_TOKEN_ID:
case EL_TOKEN_NUM:
case EL_TOKEN_BIN_NUM:
case EL_TOKEN_DECIMAL_NUM:
case EL_TOKEN_OCTAL_NUM:
case EL_TOKEN_HEX_NUM:
case EL_TOKEN_CHAR:
case EL_TOKEN_STR:
case EL_TOKEN_SEMICOLON:
case EL_TOKEN_COLON:
case EL_TOKEN_NIL:
case EL_TOKEN_LBRACKET:
case EL_TOKEN_RBRACKET:
case EL_TOKEN_RIGH_CENTER_BRACKET:
// case EL_TOKEN_RET:
case EL_TOKEN_BREAK:
return -1;
break;
case EL_TOKEN_PLUS:
return 18;
break;
case EL_TOKEN_MINUS:
return 19;
break;
case EL_TOKEN_MUL:
return 20;
break;
case EL_TOKEN_DIV:
return 21;
break;
case EL_TOKEN_LSHIFT:
return 16;
break;
case EL_TOKEN_RSHIFT:
return 17;
break;
case EL_TOKEN_MOD:
return 22;
break;
case EL_TOKEN_LPAREN:
return 2;
break;
case EL_TOKEN_RPAREN:
return 3;
break;
case EL_TOKEN_BITOR:
return 7;
break;
case EL_TOKEN_BITAND:
return 9;
break;
case EL_TOKEN_AND:
return 6;
break;
case EL_TOKEN_OR:
return 5;
break;
case EL_TOKEN_ASSIGN:
return 4;
break;
case EL_TOKEN_EQUAL:
return 10;
break;
case EL_TOKEN_NOT_EQUAL:
return 11;
break;
case EL_TOKEN_GREAT:
return 13;
break;
case EL_TOKEN_LESS:
return 12;
break;
case EL_TOKEN_GREAT_EQ:
return 15;
break;
case EL_TOKEN_LESS_EQ:
return 14;
break;
case EL_TOKEN_XOR:
return 8;
break;
case EL_TOKEN_BITNOT:
return 4;
break;
case EL_TOKEN_NOT:
return 1;
break;
case EL_TOKEN_COMMA:
break;
case EL_TOKEN_LEFT_CENTER_BRACKET:
return 23;
break;
}
return -1;
}
OPEN_API_HIDDEN static elang_tmp_label_t* elang_tmp_label_new(elang_states_t* states) {
elang_tmp_label_t* tmp_label;
elang_tmp_label_t* tmp_label_tail;
EL_MEM_ALLOC_CHECK;
tmp_label = el_malloc(sizeof(elang_tmp_label_t));
if(tmp_label == NULL){
return NULL;
}
tmp_label->next = NULL;
tmp_label->label_idx = states->global_tmp_label_index++;
if(states->global_tmp_label == NULL){
states->global_tmp_label = tmp_label;
return tmp_label;
}
tmp_label_tail = states->global_tmp_label;
while(tmp_label_tail->next){
tmp_label_tail = tmp_label_tail->next;
}
tmp_label_tail->next = tmp_label;
return tmp_label;
}
OPEN_API_HIDDEN static elang_tmp_label_t* elang_tmp_label_search(elang_states_t* states,el_uint32_t idx) {
elang_tmp_label_t* tmp_label;
elang_tmp_label_t* tmp_label_tail;
if(states->global_tmp_label == NULL){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
return 0;
}
tmp_label = states->global_tmp_label;
while(tmp_label){
if(tmp_label->label_idx == idx){
return tmp_label;
}
tmp_label = tmp_label->next;
}
return NULL;
}
OPEN_API_HIDDEN static int elang_label_new(elang_states_t* states,el_id_hash_type_t hash) {
elang_label_t* tmp_label;
elang_label_t* tmp_label_tail;
EL_MEM_ALLOC_CHECK;
tmp_label = el_malloc(sizeof(elang_label_t));
if(tmp_label == NULL){
return -1;
}
tmp_label->hash = hash;
tmp_label->label_addr = states->cur_instr_sor;
tmp_label->next = NULL;
if(states->global_label == NULL){
states->global_label = tmp_label;
return 0;
}
tmp_label_tail = states->global_label;
while(tmp_label_tail->next){
tmp_label_tail = tmp_label_tail->next;
}
tmp_label_tail->next = tmp_label;
return 0;
}
OPEN_API_HIDDEN static int elang_label_search(elang_states_t* states,el_id_hash_type_t hash,el_uint32_t* label_addr) {
elang_label_t* tmp_label;
elang_label_t* tmp_label_tail;
if(label_addr == NULL){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
return -1;
}
if(states->global_label == NULL){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
return 0;
}
tmp_label = states->global_label;
while(tmp_label){
if(tmp_label->hash == hash){
*label_addr = tmp_label->label_addr;
return 0;
}
tmp_label = tmp_label->next;
}
*label_addr = 0;
return -1;
}
OPEN_API_HIDDEN static int elang_function_index_sub(elang_states_t* states,elang_var_list_t* list,el_id_hash_type_t hash,el_uint32_t* func_index) {
int res = EL_FALSE;
elang_var_list_t* tmp_list;
tmp_list = list;
while(tmp_list){
if(tmp_list->body.var_list_type == EL_VAR_LIST_FUNCTION && tmp_list->body.hash == hash){
*func_index = tmp_list->body.global_index;
return EL_TRUE;
}
if(tmp_list->child){
res = elang_function_index_sub(states,tmp_list->child,hash,func_index);
if(res){
return EL_TRUE;
}
}
tmp_list = tmp_list->next;
}
return EL_FALSE;
}
OPEN_API_HIDDEN static int elang_function_index(elang_states_t* states,el_id_hash_type_t hash,el_uint32_t* func_index) {
if(func_index == NULL){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
return EL_FALSE;
}
if(states->root_var_list == NULL){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
return EL_FALSE;
}
return elang_function_index_sub(states,states->root_var_list,hash,func_index);
}
OPEN_API_HIDDEN static elang_var_list_t* elang_function_searchByindex_sub(elang_states_t* states,elang_var_list_t* list,el_uint32_t func_index) {
elang_var_list_t* res = NULL;
elang_var_list_t* tmp_list;
tmp_list = list;
while(tmp_list){
if(tmp_list->body.global_index == func_index){
return tmp_list;
}
if(tmp_list->child){
res = elang_function_searchByindex_sub(states,tmp_list->child,func_index);
if(res){
return res;
}
}
tmp_list = tmp_list->next;
}
return NULL;
}
OPEN_API_HIDDEN static elang_var_list_t* elang_function_searchByindex(elang_states_t* states,el_uint32_t func_index) {
if(states->root_var_list == NULL){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
return NULL;
}
return elang_function_searchByindex_sub(states,states->root_var_list,func_index);
}
OPEN_API_HIDDEN static int elang_cs_create_from_str(elang_states_t* states,char* str) {
// assert(str);
states->cs.stream_type = EL_STREAM_TYPE_STRING;
states->cs.src.str.origin_str = str;
states->cs.src.str.cur_str = str;
states->cs.ring_head = 0;
states->cs.cached_cnt = 0;
return 0;
}
OPEN_API_HIDDEN static elang_token_t* elang_new_token(elang_states_t* states,elang_token_type_t type){
elang_token_t* tmp_tok;
elang_token_t* tmp_tok_tail;
EL_MEM_ALLOC_CHECK;
tmp_tok = el_malloc(sizeof(elang_token_t));
if(tmp_tok == NULL){
return NULL;
}
tmp_tok->type = type;
tmp_tok->next = NULL;
if(states->tok_list == NULL){
states->tok_list = tmp_tok;
return tmp_tok;
}
tmp_tok_tail = states->tok_list;
while(tmp_tok_tail->next){
tmp_tok_tail = tmp_tok_tail->next;
}
tmp_tok_tail->next = tmp_tok;
return tmp_tok;
}
OPEN_API_HIDDEN static el_uint32_t elang_RsHash(const char* str, el_uint32_t len){
el_uint32_t b = 378551;
el_uint32_t a = 63689;
el_uint32_t hash = 0;
for(int i = 0; i < len; ++i){
hash = hash * a + (*str++);
a *= b;
}
return hash;
}
OPEN_API_HIDDEN static el_uint32_t elang_id_hash(elang_states_t* states,elang_token_t* cur_tok,const char* str, el_uint32_t len){
elang_token_t* tmp_tok;
el_uint32_t tmp_hash;
tmp_hash = elang_RsHash(str,len);
tmp_tok = states->tok_list;
if(tmp_tok == NULL){
return tmp_hash;
}
while(tmp_tok){
if(tmp_tok != cur_tok){
if(tmp_tok->type == EL_TOKEN_ID){
if(tmp_tok->token._id.hash == tmp_hash){
if(el_strcmp(tmp_tok->token._id.str,str) == 0){
return tmp_hash;
}else{
tmp_tok = states->tok_list;
tmp_hash = tmp_hash + 1;
continue;
// return tmp_hash+1;
}
}
}
}
tmp_tok = tmp_tok->next;
}
return tmp_hash;
}
OPEN_API_HIDDEN static int elang_cs_insert_str(elang_states_t* states,char* str) {
char *tmp_str;
int tmp_str_len;
assert(str);
states->cs.stream_type = EL_STREAM_TYPE_STRING;
if(states->cs.src.str.origin_str){
tmp_str_len = states->cs.src.str.cur_str - states->cs.src.str.origin_str;
EL_MEM_ALLOC_CHECK;
tmp_str = el_calloc(1 + el_strlen(states->cs.src.str.origin_str) + el_strlen(str),sizeof(char));
el_strcpy(tmp_str, states->cs.src.str.origin_str);
el_strcat(tmp_str, str);
el_free(states->cs.src.str.origin_str);
states->cs.src.str.origin_str = tmp_str;
states->cs.src.str.cur_str = states->cs.src.str.origin_str + tmp_str_len;
}else{
EL_MEM_ALLOC_CHECK;
states->cs.src.str.origin_str = el_calloc(el_strlen(str)+1,sizeof(char));
el_strcpy(states->cs.src.str.origin_str, str);
states->cs.src.str.cur_str = states->cs.src.str.origin_str;
}
// states->cs.ring_head = 0;
// states->cs.cached_cnt = 0;
return 0;
}
OPEN_API_HIDDEN static char elang_read_char(elang_states_t* states) {
char ch = EL_EOF;
const char* ptr_char;
switch(states->cs.stream_type) {
#ifndef LIB_MODE
case EL_STREAM_TYPE_FILE:{
if (states->cs.src.file.cur_sor >= states->cs.src.file.char_cnt)
{
if(states->cs.src.file.fp) {
states->cs.src.file.char_cnt = fread(states->cs.src.file.buf, 1, EL_FILE_BUFSIZE, states->cs.src.file.fp);
states->cs.src.file.cur_sor = 0;
}
}
if(states->cs.src.file.cur_sor < states->cs.src.file.char_cnt) {
ch = states->cs.src.file.buf[states->cs.src.file.cur_sor];
++(states->cs.src.file.cur_sor);
}
}
break;
#endif
case EL_STREAM_TYPE_STRING:{
ptr_char = states->cs.src.str.cur_str;
if (ptr_char && *ptr_char)
{
ch = *ptr_char;
states->cs.src.str.cur_str++;
}
}
break;
default:
break;
}
return ch;
}
OPEN_API_HIDDEN static int elang_char_buff_pushback(elang_states_t* states,char c)
{
if (states->lex_char_buff.itemcnt >= states->lex_char_buff.capacity)
{
el_uint32_t newcap = states->lex_char_buff.capacity * 2;
EL_MEM_ALLOC_CHECK;
char* newptr = el_malloc(newcap);
assert(newptr);
memcpy(newptr, states->lex_char_buff.ptrdata, states->lex_char_buff.itemcnt);
el_free(states->lex_char_buff.ptrdata);
states->lex_char_buff.capacity = newcap;
states->lex_char_buff.ptrdata = newptr;
}
states->lex_char_buff.ptrdata[states->lex_char_buff.itemcnt++] = c;
return 0;
}
OPEN_API_HIDDEN static char elang_char_buff_popback(elang_states_t* states)
{
char c = 0;
if (states->lex_char_buff.itemcnt > 0)
{
c = states->lex_char_buff.ptrdata[--states->lex_char_buff.itemcnt];
}
return c;
}
OPEN_API_HIDDEN static int elang_char_buff_empty(elang_states_t* states)
{
states->lex_char_buff.itemcnt = 0;
return 0;
}
OPEN_API_HIDDEN static el_size_t elang_ring_buf_index(el_size_t rh, el_size_t k) {
return (rh + k) % EL_MAX_LOOKAHEAD_CNT;
}
OPEN_API_HIDDEN static char elang_cs_look_ahead(elang_states_t* states,el_size_t k) {
el_size_t idx;
assert(k < EL_MAX_LOOKAHEAD_CNT);
while(k >= states->cs.cached_cnt){
idx = elang_ring_buf_index(states->cs.ring_head, states->cs.cached_cnt);
states->cs.ringbuf[idx] = elang_read_char(states);
states->cs.cached_cnt++;
}
idx = elang_ring_buf_index(states->cs.ring_head, k);
return states->cs.ringbuf[idx];
}
OPEN_API_HIDDEN static char elang_cs_current(elang_states_t* states) {
return elang_cs_look_ahead(states, 0);
}
OPEN_API_HIDDEN static char elang_cs_forward(elang_states_t* states) {
char ch;
ch = elang_cs_current(states);
if(ch == '\n') {
// states->cs._line++;
// states->cs._col = 1;
} else if (ch == '\t') {
// states->cs._col += (8 - states->cs._col % 8);
} else {
// states->cs._col++;
}
assert(states->cs.cached_cnt > 0);
if(states->cs.cached_cnt > 0){
states->cs.ring_head = elang_ring_buf_index(states->cs.ring_head, 1);
states->cs.cached_cnt--;
}
}
OPEN_API_HIDDEN static char elang_cs_free(elang_states_t* states) {
switch(states->cs.stream_type) {
case EL_STREAM_TYPE_FILE:{
fclose(states->cs.src.file.fp);
}
break;
case EL_STREAM_TYPE_STRING:{
el_free(states->cs.src.str.origin_str);
}
break;
default:
break;
}
}
OPEN_API_HIDDEN static int elang_lex_init(elang_states_t* states){
states->lex_state = EL_LEX_S_START;
states->token_type = EL_TOKEN_NONE;
states->tok_list = NULL;
states->sh_cur_list = NULL;
states->nest_cnt = 0;
states->lex_char_buff.itemcnt = 0;
states->lex_char_buff.capacity = LEX_PARSE_BUFF_SIZE;
EL_MEM_ALLOC_CHECK;
states->lex_char_buff.ptrdata = el_malloc(states->lex_char_buff.capacity);
return 0;
}
OPEN_API_HIDDEN static int elang_free_token_list(elang_states_t* states){
elang_token_t* tmp_tok;
elang_token_t* tmp_tok2;
tmp_tok = states->tok_list;
if(tmp_tok == NULL){
return -1;
}
while(tmp_tok){
if(tmp_tok->type == EL_TOKEN_ID){
el_free(tmp_tok->token._id.str);
}else if(tmp_tok->type == EL_TOKEN_NUM){
}else if(tmp_tok->type == EL_TOKEN_CHAR){
}else if(tmp_tok->type == EL_TOKEN_STR){
el_free(tmp_tok->token._id.str);
}
tmp_tok2 = tmp_tok;
tmp_tok = tmp_tok->next;
el_free(tmp_tok2);
}
return 0;
}
OPEN_API_HIDDEN static int elang_lex_deinit(elang_states_t* states){
states->lex_state = EL_LEX_S_START;
states->token_type = EL_TOKEN_NONE;
elang_free_token_list(states);
states->lex_char_buff.itemcnt = 0;
states->lex_char_buff.capacity = 0;
el_free(states->lex_char_buff.ptrdata);
states->lex_char_buff.ptrdata = NULL;
return 0;
}
OPEN_API_HIDDEN static int elang_lex(elang_states_t* states){
char ch;
int loop_en;
char* p_end;
char* tmp_ch_p;
char* tmp_str_p;
char* origin_str_p;
int lex_get_tok;
el_size_t str_itemcnt;
elang_token_t* tmp_tok;
lex_get_tok = EL_FALSE;
loop_en = EL_TRUE;
while(loop_en == EL_TRUE) {
ch = elang_cs_current(states);
if(ch == (char)(EL_EOF)){
elang_cs_forward(states);
return 0;
}
switch(states->lex_state) {
case EL_LEX_S_START:
lex_get_tok = EL_FALSE;
elang_char_buff_empty(states);
if(ch == ' ' || ch == '\t' || ch == '\v' || ch == '\r'){
states->lex_state = EL_LEX_S_END_RESTART;
}else if(ch == '/'){
states->lex_state = EL_LEX_S_COMENT;
}else if(ch == '\n'){
states->lex_state = EL_LEX_S_END_RESTART;
}else if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_'){
states->lex_state = EL_LEX_S_ID;
states->token_type = EL_TOKEN_ID;
}else if(ch >= '1' && ch <= '9'){
states->lex_state = EL_LEX_S_DECIMAL_NUM;
states->token_type = EL_TOKEN_DECIMAL_NUM;
}else if(ch == '0'){
states->lex_state = EL_LEX_S_OCTAL_NUM_TEST;
states->token_type = EL_TOKEN_OCTAL_NUM;
}else if(ch == ','){
states->lex_state = EL_LEX_S_END;
states->token_type = EL_TOKEN_COMMA;
}else if(ch == '['){
states->lex_state = EL_LEX_S_END;
states->token_type = EL_TOKEN_LEFT_CENTER_BRACKET;
}else if(ch == ']'){
states->lex_state = EL_LEX_S_END;
states->token_type = EL_TOKEN_RIGH_CENTER_BRACKET;
}else if(ch == '('){
states->lex_state = EL_LEX_S_END;
states->token_type = EL_TOKEN_LPAREN;
}else if(ch == ')'){
states->lex_state = EL_LEX_S_END;
states->token_type = EL_TOKEN_RPAREN;
}else if(ch == '\"'){
states->lex_state = EL_LEX_S_STR_START;
}else if(ch == '{'){
states->lex_state = EL_LEX_S_END;
states->token_type = EL_TOKEN_LBRACKET;
}else if(ch == '}'){
states->lex_state = EL_LEX_S_END;
states->token_type = EL_TOKEN_RBRACKET;
}else if(ch == ';'){
states->lex_state = EL_LEX_S_END;
states->token_type = EL_TOKEN_SEMICOLON;
}else if(ch == ':'){
states->lex_state = EL_LEX_S_END;
states->token_type = EL_TOKEN_COLON;
}else if(ch == '+'){
states->lex_state = EL_LEX_S_END;
states->token_type = EL_TOKEN_PLUS;
}else if(ch == '-'){
states->lex_state = EL_LEX_S_END;
states->token_type = EL_TOKEN_MINUS;
}else if(ch == '*'){
states->lex_state = EL_LEX_S_END;
states->token_type = EL_TOKEN_MUL;
}else if(ch == '/'){
states->token_type = EL_TOKEN_DIV;
states->token_type = EL_TOKEN_DIV;
}else if(ch == '<'){
states->lex_state = EL_LEX_S_LESS;
states->token_type = EL_TOKEN_LESS;
}else if(ch == '>'){
states->lex_state = EL_LEX_S_GREAT;
states->token_type = EL_TOKEN_GREAT;
}else if(ch == '%'){
states->lex_state = EL_LEX_S_END;
states->token_type = EL_TOKEN_MOD;
}else if(ch == '|'){
states->lex_state = EL_LEX_S_BITOR;
states->token_type = EL_TOKEN_BITOR;
}else if(ch == '&'){
states->lex_state = EL_LEX_S_BITAND;
states->token_type = EL_TOKEN_BITAND;
}else if(ch == '='){
states->lex_state = EL_LEX_S_ASSIGN;
states->token_type = EL_TOKEN_ASSIGN;
}else if(ch == '!'){
states->lex_state = EL_LEX_S_NOT;
states->token_type = EL_TOKEN_NOT;
}else if(ch == '~'){
states->lex_state = EL_LEX_S_END;
states->token_type = EL_TOKEN_BITNOT;
}else if(ch == '\''){
states->lex_state = EL_LEX_S_CHAR_START;
}
break;
case EL_LEX_S_END_STR:
break;
case EL_LEX_S_END:
break;
case EL_LEX_S_STR_START:
elang_char_buff_popback(states);
case EL_LEX_S_STR:
if(ch == '\"'){
states->lex_state = EL_LEX_S_END_STR;
states->token_type = EL_TOKEN_STR;
}else if(ch == '\\'){
states->lex_state = EL_LEX_S_STR_ESCAPE;
}else if(ch == '\n'){
states->lex_state = EL_LEX_S_STR_NEWLINE;
}else if(ch == EL_EOF){
states->lex_state = EL_LEX_S_STR_EOF;
}else{
states->lex_state = EL_LEX_S_STR;
}
break;
case EL_LEX_S_STR_ESCAPE:
states->lex_state = EL_LEX_S_STR;
break;
case EL_LEX_S_STR_NEWLINE:
states->lex_state = EL_LEX_S_STR;
break;
case EL_LEX_S_COMENT:
if(ch == '/'){
states->lex_state = EL_LEX_S_COMENT1;
}else{
}
break;
case EL_LEX_S_COMENT1:
if(ch == '\n'){
states->lex_state = EL_LEX_S_END_RESTART;
}else{
// states->lex_state = EL_LEX_S_STR_START;
}
break;
case EL_LEX_S_ID:
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || ch == '_'){
states->lex_state = EL_LEX_S_ID;
states->token_type = EL_TOKEN_ID;
}else{
states->lex_state = EL_LEX_S_END_START;
}
break;
case EL_LEX_S_ASSIGN:
if(ch == '='){
states->token_type = EL_TOKEN_EQUAL;
states->lex_state = EL_LEX_S_END;
}else{
states->lex_state = EL_LEX_S_END_START;
}
break;
case EL_LEX_S_OCTAL_NUM_TEST:
if(ch >= '0' && ch <= '7'){
states->token_type = EL_TOKEN_OCTAL_NUM;
states->lex_state = EL_LEX_S_OCTAL_NUM;
}else{
states->token_type = EL_TOKEN_DECIMAL_NUM;
states->lex_state = EL_LEX_S_END_START;
}
break;
case EL_LEX_S_OCTAL_NUM:
if(ch >= '0' && ch <= '7'){
states->token_type = EL_TOKEN_OCTAL_NUM;
}else if(ch == 'x' || ch == 'X'){
states->token_type = EL_LEX_S_HEX_NUM;
}else if(ch == 'b' || ch == 'B'){
states->token_type = EL_LEX_S_BIN_NUM;
}else{
states->lex_state = EL_LEX_S_END_START;
}
break;
case EL_LEX_S_DECIMAL_NUM:
if((ch >= '0' && ch <= '9') || (ch == '.')){
states->token_type = EL_TOKEN_DECIMAL_NUM;
}else{
states->lex_state = EL_LEX_S_END_START;
}
break;
case EL_LEX_S_HEX_NUM:
if((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f')){
states->token_type = EL_TOKEN_HEX_NUM;
}else{
states->lex_state = EL_LEX_S_END_START;
}
break;
case EL_LEX_S_BIN_NUM:
if(ch == '0' || ch == '1'){
states->lex_state = EL_LEX_S_BIN_NUM;
states->token_type = EL_TOKEN_BIN_NUM;
}else{
states->lex_state = EL_LEX_S_END_START;
}
break;
case EL_LEX_S_STR_EOF:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case EL_LEX_S_BITAND:
if(ch == '&'){
states->token_type = EL_TOKEN_AND;
states->lex_state = EL_LEX_S_END;
}else{
states->lex_state = EL_LEX_S_END_START;
}
break;
case EL_LEX_S_BITOR:
if(ch == '|'){
states->token_type = EL_TOKEN_OR;
states->lex_state = EL_LEX_S_END;
}else{
states->lex_state = EL_LEX_S_END_START;
}
break;
case EL_LEX_S_NOT:
if(ch == '='){
states->token_type = EL_TOKEN_NOT_EQUAL;
states->lex_state = EL_LEX_S_END;
}else{
states->lex_state = EL_LEX_S_END_START;
}
break;
case EL_LEX_S_LESS:
if(ch == '<'){
states->token_type = EL_TOKEN_LSHIFT;
states->lex_state = EL_LEX_S_END;
}else{
states->lex_state = EL_LEX_S_END_START;
}
break;
case EL_LEX_S_GREAT:
if(ch == '>'){
states->token_type = EL_TOKEN_LSHIFT;
states->lex_state = EL_LEX_S_END;
}else{
states->lex_state = EL_LEX_S_END_START;
}
break;
case EL_LEX_S_CHAR_START:
elang_char_buff_popback(states);
case EL_LEX_S_CHAR:
if(ch == '\\') {
states->lex_state = EL_LEX_S_CHAR_ESCAPE;
}else if(ch == '\'') {
states->token_type = EL_TOKEN_CHAR;
states->lex_state = EL_LEX_S_END_STR;
}else{
states->lex_state = EL_LEX_S_CHAR;
}
break;
case EL_LEX_S_CHAR_ESCAPE:
states->lex_state = EL_LEX_S_CHAR;
break;
default:
break;
}
if(states->lex_state == EL_LEX_S_END_RESTART){
elang_cs_forward(states);
states->lex_state = EL_LEX_S_START;
}else if(states->lex_state == EL_LEX_S_END_START){
elang_char_buff_pushback(states,'\0');
states->lex_state = EL_LEX_S_START;
lex_get_tok = EL_TRUE;
// loop_en = EL_FALSE;
}else if(states->lex_state == EL_LEX_S_END_STR){
elang_char_buff_pushback(states,'\0');
elang_cs_forward(states);
states->lex_state = EL_LEX_S_START;
lex_get_tok = EL_TRUE;
loop_en = EL_FALSE;
}else if(states->lex_state == EL_LEX_S_END){
// elang_char_buff_empty(states);
elang_char_buff_pushback(states,ch);
elang_cs_forward(states);
lex_get_tok = EL_TRUE;
states->lex_state = EL_LEX_S_START;
loop_en = EL_FALSE;
// loop_en = EL_FALSE;
}else{
elang_char_buff_pushback(states,ch);
elang_cs_forward(states);
}
if(lex_get_tok == EL_TRUE){
tmp_tok = elang_new_token(states,states->token_type);
switch(states->token_type){
case EL_TOKEN_ID:
EL_MEM_ALLOC_CHECK;
tmp_tok->token._id.str = el_calloc(states->lex_char_buff.itemcnt+1,sizeof(char));
el_memcpy(tmp_tok->token._id.str,states->lex_char_buff.ptrdata,states->lex_char_buff.itemcnt);
tmp_tok->token._id.hash = elang_id_hash(states,tmp_tok,tmp_tok->token._id.str, states->lex_char_buff.itemcnt);
tmp_tok->token._id.is_keyword = EL_KW_ID;
if(*(tmp_tok->token._id.str) == 'f' && strcmp(tmp_tok->token._id.str,"func") == 0){
tmp_tok->token._id.is_keyword = EL_KW_FUNC;
}else if(*(tmp_tok->token._id.str) == 'i' && strcmp(tmp_tok->token._id.str,"if") == 0){
tmp_tok->token._id.is_keyword = EL_KW_IF;
}else if(*(tmp_tok->token._id.str) == 'e'){
if(strcmp(tmp_tok->token._id.str,"else") == 0){
tmp_tok->token._id.is_keyword = EL_KW_ELSE;
}
if(strcmp(tmp_tok->token._id.str,"elif") == 0){
tmp_tok->token._id.is_keyword = EL_KW_ELIF;
}
}else if(*(tmp_tok->token._id.str) == 'd' && strcmp(tmp_tok->token._id.str,"do") == 0){
tmp_tok->token._id.is_keyword = EL_KW_DO;
}else if(*(tmp_tok->token._id.str) == 'w' && strcmp(tmp_tok->token._id.str,"while") == 0){
tmp_tok->token._id.is_keyword = EL_KW_WHILE;
}else if(*(tmp_tok->token._id.str) == 'n' && strcmp(tmp_tok->token._id.str,"nil") == 0){
el_free(tmp_tok->token._id.str);
tmp_tok->type = EL_TOKEN_NIL;
}else if(*(tmp_tok->token._id.str) == 'r' && strcmp(tmp_tok->token._id.str,"return") == 0){
// el_free(tmp_tok->token._id.str);
// tmp_tok->type = EL_TOKEN_RET;
tmp_tok->token._id.is_keyword = EL_KW_RET;
}else if(*(tmp_tok->token._id.str) == 'b' && strcmp(tmp_tok->token._id.str,"break") == 0){
el_free(tmp_tok->token._id.str);
tmp_tok->type = EL_TOKEN_BREAK;
}else if(*(tmp_tok->token._id.str) == 'm' && strcmp(tmp_tok->token._id.str,"main") == 0){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
break;
case EL_TOKEN_DECIMAL_NUM:
case EL_TOKEN_HEX_NUM:
el_errno = 0;
tmp_tok->type = EL_TOKEN_NUM;
el_sscanf(states->lex_char_buff.ptrdata, "%f", &(tmp_tok->token._num.v));
if (el_errno == EL_ERANGE)
{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
break;
case EL_TOKEN_OCTAL_NUM:
case EL_TOKEN_BIN_NUM:
if(states->lex_char_buff.itemcnt >= 3){
if(*(states->lex_char_buff.ptrdata) == '0'){
tmp_ch_p = states->lex_char_buff.ptrdata + 1;
tmp_tok->type = EL_TOKEN_NUM;
tmp_tok->token._num.v = 0;
if((*tmp_ch_p == 'b') || (*tmp_ch_p == 'B')){
tmp_ch_p++;
while(*tmp_ch_p){
tmp_tok->token._num.v *= 2;
tmp_tok->token._num.v += *tmp_ch_p - '0';
tmp_ch_p++;
}
}else{
while(*tmp_ch_p){
tmp_tok->token._num.v *= 8;
tmp_tok->token._num.v += *tmp_ch_p - '0';
tmp_ch_p++;
}
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
break;
case EL_TOKEN_STR:
case EL_TOKEN_CHAR:
if(states->lex_char_buff.itemcnt == 1){
if(states->token_type == EL_TOKEN_CHAR){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}else{
EL_MEM_ALLOC_CHECK;
tmp_tok->token._str.str = el_calloc(1,sizeof(char));
}
break;
}
str_itemcnt = states->lex_char_buff.itemcnt;
tmp_ch_p = states->lex_char_buff.ptrdata;
EL_MEM_ALLOC_CHECK;
tmp_str_p = el_calloc(states->lex_char_buff.itemcnt,sizeof(char));
origin_str_p = tmp_str_p;
while(str_itemcnt){
switch(*tmp_ch_p){
case '\\':
if(str_itemcnt > 0){
tmp_ch_p++;str_itemcnt--;
if(*tmp_ch_p == '\\'){
*tmp_str_p = '\\';tmp_str_p++;
}else if(*tmp_ch_p == 'a'){
*tmp_str_p = '\a';tmp_str_p++;
}else if(*tmp_ch_p == 'b'){
*tmp_str_p = '\b';tmp_str_p++;
}else if(*tmp_ch_p == 'f'){
*tmp_str_p = '\f';tmp_str_p++;
}else if(*tmp_ch_p == 'n'){
*tmp_str_p = '\n';tmp_str_p++;
}else if(*tmp_ch_p == 'r'){
*tmp_str_p = '\r';tmp_str_p++;
}else if(*tmp_ch_p == 't'){
*tmp_str_p = '\t';tmp_str_p++;
}else if(*tmp_ch_p == 'v'){
*tmp_str_p = '\v';tmp_str_p++;
}else if(*tmp_ch_p == '\''){
*tmp_str_p = '\'';tmp_str_p++;
}else if(*tmp_ch_p == '\"'){
*tmp_str_p = '\"';tmp_str_p++;
}else if(*tmp_ch_p == 'x' || *tmp_ch_p == 'X'){
if(str_itemcnt >= 3 && EL_IS_HEX(*(tmp_ch_p+1)) && EL_IS_HEX(*(tmp_ch_p+2))){
*tmp_str_p = EL_HEX2NUM(*(tmp_ch_p+1));
*tmp_str_p *= 16;
(*tmp_str_p) += EL_HEX2NUM(*(tmp_ch_p+2));
tmp_str_p++;
tmp_ch_p += 2;str_itemcnt -= 2;
}else if(str_itemcnt >= 2 && EL_IS_HEX(*(tmp_ch_p+1))){
*tmp_str_p = EL_HEX2NUM(*(tmp_ch_p+1));tmp_str_p++;
tmp_ch_p ++;str_itemcnt -= 1;
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
}else if(*tmp_ch_p >= '0' && *tmp_ch_p <= '7'){
if(str_itemcnt >= 3 && EL_IS_HEX(*(tmp_ch_p)) && EL_IS_HEX(*(tmp_ch_p+1)) && EL_IS_HEX(*(tmp_ch_p+2))){
*tmp_str_p = EL_HEX2NUM(*(tmp_ch_p));
*tmp_str_p *= 8;
*tmp_str_p += EL_HEX2NUM(*(tmp_ch_p+1));
*tmp_str_p *= 8;
*tmp_str_p += EL_HEX2NUM(*(tmp_ch_p+2));
tmp_str_p++;
tmp_ch_p += 2;str_itemcnt -= 2;
}else if(str_itemcnt >= 2 && EL_IS_HEX(*(tmp_ch_p)) && EL_IS_HEX(*(tmp_ch_p+1))){
*tmp_str_p = EL_HEX2NUM(*(tmp_ch_p));
*tmp_str_p *= 8;
*tmp_str_p += EL_HEX2NUM(*(tmp_ch_p+1));
tmp_str_p++;
tmp_ch_p += 1;str_itemcnt -= 1;
}else if(str_itemcnt >= 1 && EL_IS_HEX(*(tmp_ch_p))){
*tmp_str_p = EL_HEX2NUM(*(tmp_ch_p));tmp_str_p++;
// tmp_ch_p ++;str_itemcnt -= 1;
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
break;
default:
*tmp_str_p = *tmp_ch_p;tmp_str_p++;
break;
}
tmp_ch_p++;str_itemcnt --;
}
if(states->token_type == EL_TOKEN_CHAR){
if(tmp_str_p == (origin_str_p + 2)){
tmp_tok->token._char.c = *origin_str_p;
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
}else{
if(tmp_str_p == origin_str_p){
EL_MEM_ALLOC_CHECK;
tmp_tok->token._str.str = el_calloc(1,sizeof(char));
}else{
EL_MEM_ALLOC_CHECK;
tmp_tok->token._str.str = el_calloc((tmp_str_p - origin_str_p - 1) + 1,sizeof(char));
el_memcpy(tmp_tok->token._str.str,origin_str_p,(tmp_str_p - origin_str_p - 1));
}
}
el_free(origin_str_p);
break;
}
}
}
}
#define elang_must_next_def(states) do{if((states)->sh_cur_list->next == NULL){printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);el_exit(-1);}else{elang_must_next(states);}}while(0);
OPEN_API_HIDDEN static int elang_must_next(elang_states_t* states) {
if(states->sh_cur_list->next == NULL){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
states->sh_cur_list = states->sh_cur_list->next; // next
}
OPEN_API_HIDDEN static int elang_try_next(elang_states_t* states) {
if(states->sh_cur_list->next == NULL){
return EL_FALSE;
}
states->sh_cur_list = states->sh_cur_list->next; // next
return EL_TRUE;
}
OPEN_API_HIDDEN static int elang_is_str_expr(elang_states_t* states,elang_token_t* token_list) {
elang_var_list_t* tmp_var_list;
while(token_list->type != EL_TOKEN_SEMICOLON && token_list->type != EL_TOKEN_COMMA && token_list->type != EL_TOKEN_RPAREN){
if(token_list->type == EL_TOKEN_STR){
return EL_TRUE;
}else if(token_list->type == EL_TOKEN_ID){
tmp_var_list = elang_var_list_search(states,*(states->tmp_var_list),token_list->token._id.hash);
if(tmp_var_list){
if(tmp_var_list->body.var_list_type == EL_VAR_LIST_VAR || tmp_var_list->body.var_list_type == EL_VAR_LIST_ARG){
if(tmp_var_list->body.type == ELANG_TYPE_STR){
return EL_TRUE;
}
}
}
tmp_var_list = elang_var_list_search(states,states->root_var_list,token_list->token._id.hash);
if(tmp_var_list){
if((tmp_var_list)->body.var_list_type == EL_VAR_LIST_VAR || tmp_var_list->body.var_list_type == EL_VAR_LIST_ARG){
if((tmp_var_list)->body.type == ELANG_TYPE_STR){
return EL_TRUE;
}
}
}
}
token_list = token_list->next;
}
return EL_FALSE;
}
OPEN_API_HIDDEN static int elang_ext_func_search(elang_states_t* states,el_uint32_t hash,el_uint32_t* func_index) {
elang_ext_func_list_t* tmp_func_tail;
if(states->ext_func_list == NULL){
return EL_FALSE;
}
tmp_func_tail = states->ext_func_list;
while(tmp_func_tail){
if(tmp_func_tail->hash == hash){
*func_index = tmp_func_tail->func_index;
return EL_TRUE;
}
tmp_func_tail = tmp_func_tail->next;
}
return EL_FALSE;
}
OPEN_API_HIDDEN static elang_ext_func_list_t* elang_ext_func_searchByindex(elang_states_t* states,el_uint32_t func_index) {
elang_ext_func_list_t* tmp_func_tail;
if(states->ext_func_list == NULL){
return NULL;
}
tmp_func_tail = states->ext_func_list;
while(tmp_func_tail){
if(tmp_func_tail->func_index == func_index){
return tmp_func_tail;
}
tmp_func_tail = tmp_func_tail->next;
}
return NULL;
}
OPEN_API_HIDDEN static int elang_expr(elang_states_t* states,elang_token_type_t level,el_uint32_t force_gloabl_acc) {
el_uint32_t cur_instr_sor;
el_uint32_t arg_cnt;
el_uint32_t* number_p;
elang_token_t* tmp_tok;
el_uint32_t label_addr;
el_uint32_t func_index;
int had_next;
elang_var_list_t* tmp_var_list2;
elang_mem_pool_t* tmp_mem;
int tmp_fun_is_ext;
int tmp_list_items_cnt;
int i;
// elang_token2level(elang_token_type_t token);
if(states->sh_cur_list == NULL){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}else if(states->sh_cur_list->type == EL_TOKEN_LBRACKET){
// {}
elang_must_next_def(states); // next
tmp_list_items_cnt = 0;
while(states->sh_cur_list->type != EL_TOKEN_RBRACKET){
elang_expr(states,EL_TOKEN_ASSIGN,force_gloabl_acc);
// elang_try_next(states); // next
if (states->sh_cur_list->type == EL_TOKEN_COMMA){
elang_must_next_def(states); // next
}
tmp_list_items_cnt++;
}
// list鐨勫0鏄庯紝浣跨敤expr璁$畻涔嬪悗浼氬叏閮ㄩ兘鍦╯tack閲岋紝浣跨敤EL_VM_INSTR_POP2LIST鎶妔tack涓殑item寮瑰嚭鏉ュ苟鏀惧埌list var鐨刴em->data涓€�
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_POP2LIST;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.POP2LIST.items_cnt = tmp_list_items_cnt;
elang_try_next(states); // next
}else if(states->sh_cur_list->type == EL_TOKEN_LEFT_CENTER_BRACKET){
// [num] = str(num)
// EL_VM_INSTR_NUM_TO_STR_ARR
elang_must_next_def(states); // next
if(states->sh_cur_list->type == EL_TOKEN_RIGH_CENTER_BRACKET){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_expr(states,EL_TOKEN_ASSIGN,force_gloabl_acc);
(*(states->tmp_var_list))->body.instr_space[(*(states->tmp_var_list))->body.cur_instr_sor++].instr_s.opcode = EL_VM_INSTR_NUM_TO_STR_ARR;
if(states->sh_cur_list->type != EL_TOKEN_RIGH_CENTER_BRACKET){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_try_next(states); // next
}else if(states->sh_cur_list->type == EL_TOKEN_STR){
(*(states->tmp_var_list))->body.instr_space[(*(states->tmp_var_list))->body.cur_instr_sor++].instr_s.opcode = EL_VM_INSTR_PUSH_STR;
(*(states->tmp_var_list))->body.instr_space[(*(states->tmp_var_list))->body.cur_instr_sor++].instr = strlen(states->sh_cur_list->token._str.str) + 1; // str len
for(i = 0; i < strlen(states->sh_cur_list->token._str.str)+1;i++){
(*(states->tmp_var_list))->body.instr_space[(*(states->tmp_var_list))->body.cur_instr_sor++].instr = *(states->sh_cur_list->token._str.str + i); // str
}
had_next = elang_try_next(states); // next
}else if(states->sh_cur_list->type == EL_TOKEN_NUM){
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_PUSH_NUM;
number_p = &(states->sh_cur_list->token._num.v);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr = *(number_p);
had_next = elang_try_next(states); // next
}else if(states->sh_cur_list->type == EL_TOKEN_NIL){
(*(states->tmp_var_list))->body.instr_space[(*(states->tmp_var_list))->body.cur_instr_sor++].instr_s.opcode = EL_VM_INSTR_PUSH_NIL;
}else if(states->sh_cur_list->type == EL_TOKEN_ID){
tmp_tok = states->sh_cur_list; // ID NAME
had_next = elang_try_next(states); // next
if(had_next == EL_TRUE && states->sh_cur_list->type == EL_TOKEN_LPAREN){
// func call
elang_must_next_def(states); // next (
(*(states->tmp_var_list))->body.instr_space[(*(states->tmp_var_list))->body.cur_instr_sor++].instr_s.opcode = EL_VM_INSTR_PUSH_SP_SET_TP;
arg_cnt = 0;
if(elang_function_index(states,tmp_tok->token._id.hash,&func_index) != EL_TRUE){
if(elang_ext_func_search(states,tmp_tok->token._id.hash,&func_index) != EL_TRUE){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}else{
tmp_fun_is_ext = 1;
}
}else{
tmp_fun_is_ext = 0;
}
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_PUSH_INT;
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
while (states->sh_cur_list->type != EL_TOKEN_RPAREN) {
if(tmp_fun_is_ext == 1){
elang_expr(states,EL_TOKEN_ASSIGN,1); // 鍥犱负璁$畻鍚庣殑缁撴灉灏卞湪stack鐨勬爤搴曪紝涔熷氨鏄渶瑕佸瓨鍌╝rg鐨勫湴鏂癸紝鎵€浠ヨ繖閲屼笉闇€瑕佸仛浠讳綍澶勭悊銆�
}else{
elang_expr(states,EL_TOKEN_ASSIGN,0); // 鍥犱负璁$畻鍚庣殑缁撴灉灏卞湪stack鐨勬爤搴曪紝涔熷氨鏄渶瑕佸瓨鍌╝rg鐨勫湴鏂癸紝鎵€浠ヨ繖閲屼笉闇€瑕佸仛浠讳綍澶勭悊銆�
}
// 鍥犱负 arg瀛樺偍鐨勫簲璇ユ槸stack鐨勫彉閲忕殑鐩稿悓鐨勭被鍨嬶紝鎵€浠ラ渶瑕丳OP2LOCALVAR鍑烘爤杞崲鍚庡瓨鍌ㄥ埌MEM,浣跨敤EL_VM_INSTR_NUM2VAR 鏉ヨ浆鎹�
// 杩欓噷涓嶉渶瑕佷簡锛屽洜涓鸿〃杈惧紡璁$畻涔熶娇鐢╩em鏉ュ瓨鍌�// (*(states->tmp_var_list))->body.instr_space[(*(states->tmp_var_list))->body.cur_instr_sor++].instr_s.opcode = EL_VM_INSTR_NUM2VAR; // 鍙敮鎸佹暟鍊�
arg_cnt++;
if (states->sh_cur_list->type == EL_TOKEN_COMMA){
elang_must_next_def(states); // next
}
}
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr = arg_cnt;
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
if(tmp_fun_is_ext == 1){
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_EXT_CALL;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.EXT_CALL.addrh = func_index >> 16;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.EXT_CALL.addrm = func_index >> 8;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.EXT_CALL.addrl = func_index;
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr = arg_cnt;
}else{
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_CALL;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.CALL.addrh = func_index >> 16;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.CALL.addrm = func_index >> 8;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.CALL.addrl = func_index;
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr = arg_cnt;
}
// 杩欓噷瑕佹帴鏀惰繑鍥炲€硷紝褰撳嚱鏁拌皟鐢ㄨ鍙ヤ笉澶勪簬琛ㄨ揪寮忎腑鐨勬椂鍊欑洿鎺op
elang_must_next_def(states); // next锛宻kip )
}else{
tmp_var_list2 = elang_var_list_search(states,((*(states->tmp_var_list))->child),tmp_tok->token._id.hash);
if(tmp_var_list2 && (tmp_var_list2->body.var_list_type == EL_VAR_LIST_VAR || tmp_var_list2->body.var_list_type == EL_VAR_LIST_ARG)){
// push local var
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_PUSH_LOCALVAR; // 鍙敮鎸佹暟鍊�
if(tmp_var_list2->body.var_list_type == EL_VAR_LIST_VAR){
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.PUSH_LOCALVAR.var_offset = tmp_var_list2->body.arg_var_index + 2; // 鐩稿浜巘p鐨勫亸绉�
}else{
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.PUSH_LOCALVAR.var_offset = tmp_var_list2->body.arg_var_index + 1; // 鐩稿浜巘p鐨勫亸绉�
}
}else{
tmp_var_list2 = elang_var_list_search(states,states->root_var_list->child,tmp_tok->token._id.hash);
if(tmp_var_list2 && tmp_var_list2->body.var_list_type == EL_VAR_LIST_VAR){
// push global var
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_PUSH_GLOBALVAR; // 鍙敮鎸佹暟鍊�
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.PUSH_GLOBALVAR.var_offset = tmp_var_list2->body.arg_var_index + 2; // 鐩稿浜庢爤椤剁殑鍋忕Щ
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
}
}
}else if(states->sh_cur_list->type == EL_TOKEN_LPAREN){
elang_must_next_def(states); // next锛宻kip (
elang_expr(states,EL_TOKEN_ASSIGN,force_gloabl_acc);
if(states->sh_cur_list->type != EL_TOKEN_RPAREN){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_try_next(states);
}else if(states->sh_cur_list->type == EL_TOKEN_MUL){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_MOD,force_gloabl_acc);
}else if(states->sh_cur_list->type == EL_TOKEN_BITAND){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_MOD,force_gloabl_acc);
}else if(states->sh_cur_list->type == EL_TOKEN_NOT){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_MOD,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_PUSH_NUM;
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr = 0;
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_EQ;
}else if(states->sh_cur_list->type == EL_TOKEN_BITNOT){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_MOD,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_PUSH_NUM;
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr = -1;
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_XOR;
}else if(states->sh_cur_list->type == EL_TOKEN_PLUS){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_MOD,force_gloabl_acc);
}else if(states->sh_cur_list->type == EL_TOKEN_MINUS){
elang_must_next_def(states); // next
if(states->sh_cur_list->type != EL_TOKEN_NUM){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_PUSH_NUM;
number_p = &(states->sh_cur_list->token._num.v);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr = (*(number_p)) * (-1);
}else{
}
while(elang_token2level(states->sh_cur_list->type) >= elang_token2level(level)){
if(states->sh_cur_list->type == EL_TOKEN_ASSIGN){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}else if(states->sh_cur_list->type == EL_TOKEN_OR){
elang_must_next_def(states); // next
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_JNZ;
elang_expr(states,EL_TOKEN_AND,force_gloabl_acc);
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JNZ.addrh = (*(states->tmp_var_list))->body.cur_instr_sor >> 16;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JNZ.addrm = (*(states->tmp_var_list))->body.cur_instr_sor >> 8;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JNZ.addrl = (*(states->tmp_var_list))->body.cur_instr_sor;
}else if(states->sh_cur_list->type == EL_TOKEN_AND){
elang_must_next_def(states); // next
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_JZ;
elang_expr(states,EL_TOKEN_BITOR,force_gloabl_acc);
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JNZ.addrh = (*(states->tmp_var_list))->body.cur_instr_sor >> 16;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JNZ.addrm = (*(states->tmp_var_list))->body.cur_instr_sor >> 8;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JNZ.addrl = (*(states->tmp_var_list))->body.cur_instr_sor;
}else if(states->sh_cur_list->type == EL_TOKEN_BITOR){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_XOR,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_XOR;
}else if(states->sh_cur_list->type == EL_TOKEN_XOR){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_BITAND,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_XOR;
}else if(states->sh_cur_list->type == EL_TOKEN_BITAND){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_EQUAL,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_BITAND;
}else if(states->sh_cur_list->type == EL_TOKEN_EQUAL){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_LESS,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_EQ;
}else if(states->sh_cur_list->type == EL_TOKEN_NOT_EQUAL){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_LESS,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_NOT_EQ;
}else if(states->sh_cur_list->type == EL_TOKEN_LESS){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_LSHIFT,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_LT;
}else if(states->sh_cur_list->type == EL_TOKEN_LESS_EQ){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_LSHIFT,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_LE;
}else if(states->sh_cur_list->type == EL_TOKEN_GREAT){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_LSHIFT,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_GT;
}else if(states->sh_cur_list->type == EL_TOKEN_GREAT_EQ){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_LSHIFT,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_GE;
}else if(states->sh_cur_list->type == EL_TOKEN_LSHIFT){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_PLUS,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_LSHIFT;
}else if(states->sh_cur_list->type == EL_TOKEN_RSHIFT){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_PLUS,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_RSHIFT;
}else if(states->sh_cur_list->type == EL_TOKEN_PLUS){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_MUL,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_ADD;
}else if(states->sh_cur_list->type == EL_TOKEN_MINUS){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_MUL,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_SUB;
}else if(states->sh_cur_list->type == EL_TOKEN_MUL){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_MOD,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_MUL;
}else if(states->sh_cur_list->type == EL_TOKEN_DIV){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_MOD,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_DIV;
}else if(states->sh_cur_list->type == EL_TOKEN_MOD){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_MOD,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_MOD;
}else if(states->sh_cur_list->type == EL_TOKEN_LEFT_CENTER_BRACKET){
// [] == item->size ; [num] = *(item+num); [num:num2] = *(item+num)~*(item+num2)
elang_must_next_def(states); // next
if(states->sh_cur_list->type == EL_TOKEN_RIGH_CENTER_BRACKET){
// ] == item->size ;
(*(states->tmp_var_list))->body.instr_space[(*(states->tmp_var_list))->body.cur_instr_sor++].instr_s.opcode = EL_VM_INSTR_STR_ARR_SIZE;
}else{
elang_expr(states,EL_TOKEN_ASSIGN,force_gloabl_acc);
if(states->sh_cur_list->type == EL_TOKEN_RIGH_CENTER_BRACKET){
// [num] = *(item+num);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_STR_ARR_GETCHAR;
}else if(states->sh_cur_list->type == EL_TOKEN_COLON){
elang_must_next_def(states); // next
elang_expr(states,EL_TOKEN_ASSIGN,force_gloabl_acc);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_STR_ARR_SPILT;
}
if(states->sh_cur_list->type != EL_TOKEN_RIGH_CENTER_BRACKET){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
}
elang_try_next(states); // next
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
}
}
OPEN_API_HIDDEN static int elang_list_assign(elang_states_t* states){
el_uint32_t cur_instr_sor;
elang_expr(states,EL_TOKEN_ASSIGN,0);
if(states->sh_cur_list->type == EL_TOKEN_COLON){
elang_must_next_def(states); // skip :
elang_expr(states,EL_TOKEN_ASSIGN,0);
if(states->sh_cur_list->type != EL_TOKEN_RIGH_CENTER_BRACKET){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states); // skip ]
if(states->sh_cur_list->type != EL_TOKEN_ASSIGN){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states); // skip =
elang_expr(states,EL_TOKEN_ASSIGN,0);
if(states->sh_cur_list->type != EL_TOKEN_SEMICOLON){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor - 1;
if((*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode != EL_VM_INSTR_POP2LIST){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
// OFFSET
// END
// ITEM0
// ITEM1
// ...
// ITEMn
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_POP2LIST_OFFSET;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.POP2LIST_OFFSET.items_cnt = (*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.POP2LIST.items_cnt;
}else{
elang_expr(states,EL_TOKEN_ASSIGN,0);
if(states->sh_cur_list->type != EL_TOKEN_RIGH_CENTER_BRACKET){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states); // skip ]
if(states->sh_cur_list->type != EL_TOKEN_ASSIGN){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states); // skip =
elang_expr(states,EL_TOKEN_ASSIGN,0);
if(states->sh_cur_list->type != EL_TOKEN_SEMICOLON){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor - 1;
if((*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode == EL_VM_INSTR_POP2LIST){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
// OFFSET
// ITEM0
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_POP2LIST_OFFSET_ONE_ITEM;
}
}
#define IS_DO_WHILE 1
#define IS_WHILE 2
OPEN_API_HIDDEN static int elang_parse_top(elang_states_t* states,int is_top_level,int is_while,el_uint32_t do_while_idx) {
elang_token_t* tmp_tok;
el_uint32_t cur_instr_sor;
el_uint32_t cur_instr_sor_if;
elang_var_list_t** tmp_var_list;
elang_var_list_t* tmp_var_list_child;
elang_var_list_t* tmp_var_list2;
float* tmp_f;
el_uint32_t tmp_u32;
int is_str;
elang_mem_pool_t* tmp_mem;
int had_next;
elang_tmp_label_t* dowhile_tmp_label;
while(states->sh_cur_list){
if(states->sh_cur_list->type == EL_TOKEN_BREAK) {
elang_must_next_def(states);
if(states->sh_cur_list == NULL || states->sh_cur_list->type != EL_TOKEN_SEMICOLON){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states); // skip ;
if(is_while == IS_WHILE){
// while(){}
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++; // JMP
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_JMP;
elang_parse_top(states,EL_FALSE,is_while,do_while_idx);
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JMP.addrl = ((*(states->tmp_var_list))->body.cur_instr_sor+1);
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JMP.addrm = ((*(states->tmp_var_list))->body.cur_instr_sor+1) >> 8;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JMP.addrh = ((*(states->tmp_var_list))->body.cur_instr_sor+1) >> 16;
}else if(is_while == IS_DO_WHILE){
// do{}while();
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++; // JMP
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_JMP_LABEL;
elang_parse_top(states,EL_FALSE,is_while,do_while_idx);
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JMP.addrl = (do_while_idx);
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JMP.addrm = (do_while_idx) >> 8;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JMP.addrh = (do_while_idx) >> 16;
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
return 0;
}else if(states->sh_cur_list->type == EL_TOKEN_ID) {
if(states->sh_cur_list->token._id.is_keyword == EL_KW_FUNC){
if(is_top_level == EL_FALSE){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states);
if(states->sh_cur_list == NULL || states->sh_cur_list->type != EL_TOKEN_ID){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_tok = states->sh_cur_list;
elang_label_new(states,tmp_tok->token._id.hash);
elang_must_next_def(states);
if(states->sh_cur_list == NULL || states->sh_cur_list->type != EL_TOKEN_LPAREN){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states);
tmp_var_list = states->tmp_var_list; // backup
tmp_var_list_child = elang_var_list_add_child(states,*(states->tmp_var_list));
states->tmp_var_list = &tmp_var_list_child;
EL_MEM_ALLOC_CHECK;
(*(states->tmp_var_list))->body.instr_space = el_malloc(EL_ROM_SIZE * sizeof(elang_instr_space_t));
(*(states->tmp_var_list))->body.var_list_type = EL_VAR_LIST_FUNCTION;
(*(states->tmp_var_list))->body.hash = tmp_tok->token._id.hash;
while(states->sh_cur_list->type != EL_TOKEN_RPAREN){
tmp_var_list2 = elang_var_list_add_child(states,(*(states->tmp_var_list)));
tmp_var_list2->body.var_list_type = EL_VAR_LIST_ARG;
tmp_var_list2->body.hash = states->sh_cur_list->token._id.hash;
elang_must_next_def(states);
}
elang_must_next_def(states);
if(states->sh_cur_list == NULL || states->sh_cur_list->type != EL_TOKEN_LBRACKET){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
states->tmp_local_var = 0;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_MALLOC;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.MALLOC.size = 0;
elang_parse_top(states,EL_FALSE,is_while,do_while_idx);
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.MALLOC.size = states->tmp_local_var;
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_PUSH_NIL;
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_RET;
states->tmp_var_list = tmp_var_list; // recover
elang_try_next(states); // skip }
}else if(states->sh_cur_list->token._id.is_keyword == EL_KW_ELIF){
// elif(){}
elang_must_next_def(states);
if(states->sh_cur_list->type != EL_TOKEN_LPAREN){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states);
elang_expr(states,EL_TOKEN_ASSIGN,0);
if(states->sh_cur_list->type != EL_TOKEN_RPAREN){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states);
if(states->sh_cur_list == NULL || states->sh_cur_list->type != EL_TOKEN_LBRACKET){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states);
cur_instr_sor_if = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.opcode = EL_VM_INSTR_JZ;
elang_parse_top(states,EL_FALSE,is_while,do_while_idx);
if(states->sh_cur_list == NULL || states->sh_cur_list->type != EL_TOKEN_RBRACKET){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
had_next = elang_try_next(states);
if(had_next == EL_TRUE && states->sh_cur_list->type == EL_TOKEN_ID && states->sh_cur_list->token._id.is_keyword == EL_KW_ELIF){
(*(states->tmp_var_list))->body.instr_space[(*(states->tmp_var_list))->body.cur_instr_sor].instr_s.opcode = EL_VM_INSTR_JMP;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrl = ((*(states->tmp_var_list))->body.cur_instr_sor+1);
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrm = ((*(states->tmp_var_list))->body.cur_instr_sor+1) >> 8;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrh = ((*(states->tmp_var_list))->body.cur_instr_sor+1) >> 16;
cur_instr_sor_if = (*(states->tmp_var_list))->body.cur_instr_sor++;
elang_parse_top(states,EL_FALSE,is_while,do_while_idx);
}else if(had_next == EL_TRUE && states->sh_cur_list->type == EL_TOKEN_ID && states->sh_cur_list->token._id.is_keyword == EL_KW_ELSE){
// else{}
(*(states->tmp_var_list))->body.instr_space[(*(states->tmp_var_list))->body.cur_instr_sor].instr_s.opcode = EL_VM_INSTR_JMP;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrl = ((*(states->tmp_var_list))->body.cur_instr_sor+1);
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrm = ((*(states->tmp_var_list))->body.cur_instr_sor+1) >> 8;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrh = ((*(states->tmp_var_list))->body.cur_instr_sor+1) >> 16;
cur_instr_sor_if = (*(states->tmp_var_list))->body.cur_instr_sor++;
elang_parse_top(states,EL_FALSE,is_while,do_while_idx);
}
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrl = ((*(states->tmp_var_list))->body.cur_instr_sor);
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrm = ((*(states->tmp_var_list))->body.cur_instr_sor) >> 8;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrh = ((*(states->tmp_var_list))->body.cur_instr_sor) >> 16;
return 0;
}else if(states->sh_cur_list->token._id.is_keyword == EL_KW_ELSE){
elang_must_next_def(states);
if(states->sh_cur_list == NULL || states->sh_cur_list->type != EL_TOKEN_LBRACKET){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states);
elang_parse_top(states,EL_FALSE,is_while,do_while_idx);
return 0;
}else if(states->sh_cur_list->token._id.is_keyword == EL_KW_IF){
// EL_KW_ELSE EL_KW_ELIF
// if(){}
elang_must_next_def(states);
if(states->sh_cur_list->type != EL_TOKEN_LPAREN){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states);
elang_expr(states,EL_TOKEN_ASSIGN,0);
if(states->sh_cur_list->type != EL_TOKEN_RPAREN){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states);
if(states->sh_cur_list == NULL || states->sh_cur_list->type != EL_TOKEN_LBRACKET){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states);
cur_instr_sor_if = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.opcode = EL_VM_INSTR_JZ;
elang_parse_top(states,EL_FALSE,is_while,do_while_idx);
if(states->sh_cur_list == NULL || states->sh_cur_list->type != EL_TOKEN_RBRACKET){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
had_next = elang_try_next(states);
if(had_next == EL_TRUE && states->sh_cur_list->type == EL_TOKEN_ID && states->sh_cur_list->token._id.is_keyword == EL_KW_ELIF){
(*(states->tmp_var_list))->body.instr_space[(*(states->tmp_var_list))->body.cur_instr_sor].instr_s.opcode = EL_VM_INSTR_JMP;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrl = ((*(states->tmp_var_list))->body.cur_instr_sor + 1);
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrm = ((*(states->tmp_var_list))->body.cur_instr_sor + 1) >> 8;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrh = ((*(states->tmp_var_list))->body.cur_instr_sor + 1) >> 16;
cur_instr_sor_if = (*(states->tmp_var_list))->body.cur_instr_sor++;
elang_parse_top(states,EL_FALSE,is_while,do_while_idx);
}else if(had_next == EL_TRUE && states->sh_cur_list->type == EL_TOKEN_ID && states->sh_cur_list->token._id.is_keyword == EL_KW_ELSE){
// else{}
(*(states->tmp_var_list))->body.instr_space[(*(states->tmp_var_list))->body.cur_instr_sor].instr_s.opcode = EL_VM_INSTR_JMP;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrl = ((*(states->tmp_var_list))->body.cur_instr_sor + 1);
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrm = ((*(states->tmp_var_list))->body.cur_instr_sor + 1) >> 8;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrh = ((*(states->tmp_var_list))->body.cur_instr_sor + 1) >> 16;
cur_instr_sor_if = (*(states->tmp_var_list))->body.cur_instr_sor++;
elang_parse_top(states,EL_FALSE,is_while,do_while_idx);
}
if(states->sh_cur_list == NULL || states->sh_cur_list->type != EL_TOKEN_RBRACKET){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
had_next = elang_try_next(states);
// JZ 鐨勫湴鍧€
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrl = ((*(states->tmp_var_list))->body.cur_instr_sor);
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrm = ((*(states->tmp_var_list))->body.cur_instr_sor) >> 8;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor_if].instr_s.arg.JZ.addrh = ((*(states->tmp_var_list))->body.cur_instr_sor) >> 16;
}else if(states->sh_cur_list->token._id.is_keyword == EL_KW_DO){
elang_must_next_def(states);
if(states->sh_cur_list == NULL || states->sh_cur_list->type != EL_TOKEN_LBRACKET){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
dowhile_tmp_label = elang_tmp_label_new(states);
elang_must_next_def(states);
cur_instr_sor_if = (*(states->tmp_var_list))->body.cur_instr_sor;
elang_parse_top(states,EL_FALSE,IS_DO_WHILE,dowhile_tmp_label->label_idx);
if(states->sh_cur_list == NULL || states->sh_cur_list->type != EL_TOKEN_RBRACKET){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states);
if(states->sh_cur_list == NULL || states->sh_cur_list->type != EL_TOKEN_ID || states->sh_cur_list->token._id.is_keyword != EL_KW_WHILE){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states); // while
if(states->sh_cur_list->type != EL_TOKEN_LPAREN){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states); // (
elang_expr(states,EL_TOKEN_ASSIGN,0);
if(states->sh_cur_list->type != EL_TOKEN_RPAREN){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states); // )
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_JNZ;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JNZ.addrl = (cur_instr_sor_if);
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JNZ.addrm = (cur_instr_sor_if) >> 8;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JNZ.addrh = (cur_instr_sor_if) >> 16;
dowhile_tmp_label->addrl = ((*(states->tmp_var_list))->body.cur_instr_sor);
dowhile_tmp_label->addrm = ((*(states->tmp_var_list))->body.cur_instr_sor) >> 8;
dowhile_tmp_label->addrh = ((*(states->tmp_var_list))->body.cur_instr_sor) >> 16;
had_next = elang_try_next(states); // ;
}else if(states->sh_cur_list->token._id.is_keyword == EL_KW_WHILE){
// while(){}
elang_must_next_def(states);
cur_instr_sor_if = (*(states->tmp_var_list))->body.cur_instr_sor; // JMP
if(states->sh_cur_list->type != EL_TOKEN_LPAREN){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states); // (
elang_expr(states,EL_TOKEN_ASSIGN,0);
if(states->sh_cur_list->type != EL_TOKEN_RPAREN){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states); // )
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++; // JZ
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_JZ;
if(states->sh_cur_list == NULL || states->sh_cur_list->type != EL_TOKEN_LBRACKET){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_must_next_def(states);
elang_parse_top(states,EL_FALSE,IS_WHILE,do_while_idx);
if(states->sh_cur_list == NULL || states->sh_cur_list->type != EL_TOKEN_RBRACKET){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JZ.addrl = ((*(states->tmp_var_list))->body.cur_instr_sor + 1);
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JZ.addrm = ((*(states->tmp_var_list))->body.cur_instr_sor + 1) >> 8;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JZ.addrh = ((*(states->tmp_var_list))->body.cur_instr_sor + 1) >> 16;
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++; // JMP
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_JMP;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JMP.addrl = (cur_instr_sor_if);
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JMP.addrm = (cur_instr_sor_if) >> 8;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.JMP.addrh = (cur_instr_sor_if) >> 16;
}else if(states->sh_cur_list->token._id.is_keyword == EL_KW_RET){
if(states->sh_cur_list->next->type == EL_TOKEN_SEMICOLON){
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_PUSH_NIL;
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_RET;
}else{
elang_must_next_def(states);
elang_expr(states,EL_TOKEN_ASSIGN,0);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_RET;
}
elang_try_next(states);
}else{
tmp_tok = states->sh_cur_list; // var name or function
if(states->sh_cur_list->next->type == EL_TOKEN_ASSIGN){
// var
is_str = 0;
elang_must_next_def(states); // skip ID
elang_must_next_def(states); // skip =
// expr 鎵ц瀹屽悗浼氭妸缁撴灉鍘嬪湪鏍堝簳锛岃繖閲岀洿鎺ヨ繘琛岃祴鍊兼搷浣滃氨鍙互浜嗐€�
tmp_var_list2 = elang_var_list_search(states,((*(states->tmp_var_list))->child),tmp_tok->token._id.hash);
if(tmp_var_list2 && (tmp_var_list2->body.var_list_type == EL_VAR_LIST_VAR || tmp_var_list2->body.var_list_type == EL_VAR_LIST_ARG)){
// set local var
elang_expr(states,EL_TOKEN_ASSIGN,0);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_POP2LOCALVAR; // 鍙敮鎸佹暟鍊�
if(tmp_var_list2->body.var_list_type == EL_VAR_LIST_VAR){
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.POP2LOCALVAR.var_offset = (tmp_var_list2->body.arg_var_index + 2); // 鐩稿浜巘p鐨勫亸绉�
}else{
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.POP2LOCALVAR.var_offset = (tmp_var_list2->body.arg_var_index + 1); // 鐩稿浜巘p鐨勫亸绉�
}
}else{
tmp_var_list2 = elang_var_list_search(states,states->root_var_list->child,tmp_tok->token._id.hash);
if(tmp_var_list2 && tmp_var_list2->body.var_list_type == EL_VAR_LIST_VAR){
// set global var
elang_expr(states,EL_TOKEN_ASSIGN,0);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_POP2GLOBALVAR; // 鍙敮鎸佹暟鍊�
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.POP2LOCALVAR.var_offset = tmp_var_list2->body.arg_var_index + 2; // 鐩稿浜庢爤椤剁殑鍋忕Щ
}else{
// def var
tmp_var_list2 = elang_var_list_add_child(states,(*(states->tmp_var_list)));
tmp_var_list2->body.var_list_type = EL_VAR_LIST_VAR;
tmp_var_list2->body.hash = tmp_tok->token._id.hash;
tmp_var_list2->body.type = ELANG_TYPE_NUM;
states->tmp_local_var++;
if(is_top_level == EL_TRUE){
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_MALLOC; // 鍙敮鎸佹暟鍊�
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.MALLOC.size = 1;
}
elang_expr(states,EL_TOKEN_ASSIGN,0);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_POP2LOCALVAR; // 鍙敮鎸佹暟鍊�
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.POP2LOCALVAR.var_offset = (tmp_var_list2->body.arg_var_index + 2); // 鐩稿浜巘p鐨勫亸绉�
}
}
elang_try_next(states);
}else if(states->sh_cur_list->next->type == EL_TOKEN_LEFT_CENTER_BRACKET){
// a[] = ;
elang_must_next_def(states); // skip ID
elang_must_next_def(states); // skip [
tmp_var_list2 = elang_var_list_search(states,((*(states->tmp_var_list))->child),tmp_tok->token._id.hash);
if(tmp_var_list2 && (tmp_var_list2->body.var_list_type == EL_VAR_LIST_VAR || tmp_var_list2->body.var_list_type == EL_VAR_LIST_ARG)){
// set local var
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_PUSH_LOCALVAR; // 鍙敮鎸佹暟鍊�
if(tmp_var_list2->body.var_list_type == EL_VAR_LIST_VAR){
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.POP2LOCALVAR.var_offset = (tmp_var_list2->body.arg_var_index + 2); // 鐩稿浜巘p鐨勫亸绉�
}else{
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.POP2LOCALVAR.var_offset = (tmp_var_list2->body.arg_var_index + 1); // 鐩稿浜巘p鐨勫亸绉�
}
elang_list_assign(states);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_POP2LOCALVAR; // 鍙敮鎸佹暟鍊�
if(tmp_var_list2->body.var_list_type == EL_VAR_LIST_VAR){
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.POP2LOCALVAR.var_offset = (tmp_var_list2->body.arg_var_index + 2); // 鐩稿浜巘p鐨勫亸绉�
}else{
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.POP2LOCALVAR.var_offset = (tmp_var_list2->body.arg_var_index + 1); // 鐩稿浜巘p鐨勫亸绉�
}
}else{
tmp_var_list2 = elang_var_list_search(states,states->root_var_list->child,tmp_tok->token._id.hash);
if(tmp_var_list2 && tmp_var_list2->body.var_list_type == EL_VAR_LIST_VAR){
// set global var
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_PUSH_GLOBALVAR; // 鍙敮鎸佹暟鍊�
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.POP2LOCALVAR.var_offset = tmp_var_list2->body.arg_var_index + 2; // 鐩稿浜庢爤椤剁殑鍋忕Щ
elang_list_assign(states);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_POP2GLOBALVAR; // 鍙敮鎸佹暟鍊�
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.POP2LOCALVAR.var_offset = tmp_var_list2->body.arg_var_index + 2; // 鐩稿浜庢爤椤剁殑鍋忕Щ
}else{
// def var
tmp_var_list2 = elang_var_list_add_child(states,(*(states->tmp_var_list)));
tmp_var_list2->body.var_list_type = EL_VAR_LIST_VAR;
tmp_var_list2->body.hash = tmp_tok->token._id.hash;
tmp_var_list2->body.type = ELANG_TYPE_NUM;
states->tmp_local_var++;
if(is_top_level == EL_TRUE){
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_MALLOC; // 鍙敮鎸佹暟鍊�
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.MALLOC.size = 1;
}
elang_list_assign(states);
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_POP2LOCALVAR; // 鍙敮鎸佹暟鍊�
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.arg.POP2LOCALVAR.var_offset = (tmp_var_list2->body.arg_var_index + 2); // 鐩稿浜巘p鐨勫亸绉�
}
}
elang_try_next(states); // skip ;
}else if(states->sh_cur_list->next->type == EL_TOKEN_LPAREN){
// function call
elang_expr(states,EL_TOKEN_ASSIGN,0);
elang_try_next(states);
// 杩欓噷琛ㄧず杩欎釜鍑芥暟璋冪敤鐨勮繑鍥炲€兼病鏈夎寮曠敤锛屾墍浠ラ渶瑕佸脊鍑烘潵鑸嶅純鎺夈€�
cur_instr_sor = (*(states->tmp_var_list))->body.cur_instr_sor++;
(*(states->tmp_var_list))->body.instr_space[cur_instr_sor].instr_s.opcode = EL_VM_INSTR_POP;
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
}
}else if(states->sh_cur_list->type == EL_TOKEN_RBRACKET){
// elang_try_next(states);
return 0;
}else if(states->sh_cur_list->type == EL_TOKEN_SEMICOLON){
elang_try_next(states);
return 0;
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
}
return 0;
}
OPEN_API_HIDDEN static int elang_link_label_sub(elang_states_t* states,elang_var_list_t* list){
el_uint32_t tmp_sor;
float* tmp_v;
el_uint32_t tmp_arg;
elang_tmp_label_t* tmp_label;
tmp_sor = 0;
while(list){
if(list->body.instr_space){
while(tmp_sor < list->body.cur_instr_sor){
switch(list->body.instr_space[tmp_sor].instr_s.opcode){
case EL_VM_INSTR_RESET:
case EL_VM_INSTR_EXT:
case EL_VM_INSTR_DATA:
states->global_instr_count++;
break;
case EL_VM_INSTR_LOAD_STR:
case EL_VM_INSTR_LOAD_CHAR:
states->global_instr_count++;
break;
case EL_VM_INSTR_PUSH_NUM:
++tmp_sor;
states->global_instr_count++;
states->global_instr_count++;
break;
case EL_VM_INSTR_PUSH_NIL:
states->global_instr_count++;
break;
case EL_VM_INSTR_PUSH_INT:
states->global_instr_count++;
states->global_instr_count++;
++tmp_sor;
break;
case EL_VM_INSTR_JZ:
states->global_instr_count++;
break;
case EL_VM_INSTR_JNZ:
states->global_instr_count++;
break;
case EL_VM_INSTR_JMP:
states->global_instr_count++;
break;
case EL_VM_INSTR_ADD:
states->global_instr_count++;
break;
case EL_VM_INSTR_SUB:
states->global_instr_count++;
break;
case EL_VM_INSTR_MUL:
states->global_instr_count++;
break;
case EL_VM_INSTR_DIV:
states->global_instr_count++;
break;
case EL_VM_INSTR_MOD:
states->global_instr_count++;
break;
case EL_VM_INSTR_LSHIFT:
states->global_instr_count++;
break;
case EL_VM_INSTR_RSHIFT:
states->global_instr_count++;
break;
case EL_VM_INSTR_NOT_EQ:
states->global_instr_count++;
break;
case EL_VM_INSTR_EQ:
states->global_instr_count++;
break;
case EL_VM_INSTR_BITOR:
states->global_instr_count++;
break;
case EL_VM_INSTR_OR:
states->global_instr_count++;
break;
case EL_VM_INSTR_BITAND:
states->global_instr_count++;
break;
case EL_VM_INSTR_AND:
states->global_instr_count++;
break;
case EL_VM_INSTR_XOR:
states->global_instr_count++;
break;
case EL_VM_INSTR_LT:
states->global_instr_count++;
break;
case EL_VM_INSTR_GT:
states->global_instr_count++;
break;
case EL_VM_INSTR_LE:
states->global_instr_count++;
break;
case EL_VM_INSTR_GE:
states->global_instr_count++;
break;
case EL_VM_INSTR_POP:
states->global_instr_count++;
break;
// case EL_VM_INSTR_PUSH_PC:
// break;
case EL_VM_INSTR_PUSH_SP_SET_TP:
states->global_instr_count++;
break;
case EL_VM_INSTR_EXT_CALL:
++tmp_sor;
states->global_instr_count++;
states->global_instr_count++;
break;
case EL_VM_INSTR_CALL:
++tmp_sor;
states->global_instr_count++;
states->global_instr_count++;
break;
case EL_VM_INSTR_MALLOC:
states->global_instr_count++;
break;
case EL_VM_INSTR_NUM2VAR:
states->global_instr_count++;
break;
case EL_VM_INSTR_POP2LOCALVAR:
states->global_instr_count++;
break;
case EL_VM_INSTR_RET:
states->global_instr_count++;
break;
case EL_VM_INSTR_PUSH_LOCALVAR:
states->global_instr_count++;
break;
case EL_VM_INSTR_SIZEOF:
states->global_instr_count++;
break;
case EL_VM_INSTR_POP2GLOBALVAR:
states->global_instr_count++;
break;
case EL_VM_INSTR_PUSH_GLOBALVAR:
states->global_instr_count++;
break;
case EL_VM_INSTR_STR_ARR_SPILT:
states->global_instr_count++;
break;
case EL_VM_INSTR_STR_ARR_GETCHAR:
states->global_instr_count++;
break;
case EL_VM_INSTR_STR_ARR_SIZE:
states->global_instr_count++;
break;
case EL_VM_INSTR_NUM_TO_STR_ARR:
states->global_instr_count++;
break;
case EL_VM_INSTR_POP2LIST:
states->global_instr_count++;
break;
case EL_VM_INSTR_POP2LIST_OFFSET_ONE_ITEM:
states->global_instr_count++;
break;
case EL_VM_INSTR_POP2LIST_OFFSET:
states->global_instr_count++;
break;
case EL_VM_INSTR_PUSH_STR:
++tmp_sor;
states->global_instr_count++;
states->global_instr_count++;
tmp_arg = list->body.instr_space[tmp_sor].instr;
while(tmp_arg--){
++tmp_sor;
states->global_instr_count++;
}
break;
case EL_VM_INSTR_RECOVER_SP_FROM_TP:
case EL_VM_INSTR_PUSH_RA:
case EL_VM_INSTR_NIL2LOCALVAR:
case EL_VM_INSTR_NIL2GLOBALVAR:
case EL_VM_INSTR_PUSH_INSTR_SPACE_ID:
states->global_instr_count++;
break;
case EL_VM_INSTR_JMP_LABEL:
tmp_arg = list->body.instr_space[tmp_sor].instr_s.arg.JMP.addrh << 16;
tmp_arg += list->body.instr_space[tmp_sor].instr_s.arg.JMP.addrm << 8;
tmp_arg += list->body.instr_space[tmp_sor].instr_s.arg.JMP.addrl << 8;
tmp_label = elang_tmp_label_search(states,tmp_arg);
list->body.instr_space[tmp_sor].instr_s.opcode = EL_VM_INSTR_JMP;
list->body.instr_space[tmp_sor].instr_s.arg.JMP.addrh = tmp_label->addrh;
list->body.instr_space[tmp_sor].instr_s.arg.JMP.addrm = tmp_label->addrm;
list->body.instr_space[tmp_sor].instr_s.arg.JMP.addrl = tmp_label->addrl;
states->global_instr_count++;
break;
}
tmp_sor++;
}
}
if(list->child){
elang_link_label_sub(states,list->child);
}
list = list->next;
}
return 0;
}
OPEN_API_HIDDEN static int elang_link_label(elang_states_t* states){
states->global_instr_count = 0;
elang_link_label_sub(states,states->root_var_list);
}
OPEN_API_HIDDEN static int elang_print_instr_sub(elang_states_t* states,elang_var_list_t* list){
el_uint32_t tmp_sor;
float* tmp_v;
el_uint32_t tmp_arg;
tmp_sor = 0;
while(list){
if(list->body.instr_space){
while(tmp_sor < list->body.cur_instr_sor){
switch(list->body.instr_space[tmp_sor].instr_s.opcode){
case EL_VM_INSTR_RESET:
case EL_VM_INSTR_EXT:
case EL_VM_INSTR_DATA:
case EL_VM_INSTR_LOAD_STR:
case EL_VM_INSTR_LOAD_CHAR:
break;
case EL_VM_INSTR_STR_ARR_SPILT:
// tmp_sor++;
// el_printf(" offset: %d\n",list->body.instr_space[tmp_sor].instr);
// tmp_sor++;
// el_printf(" end: %d\n",list->body.instr_space[tmp_sor].instr);
break;
case EL_VM_INSTR_STR_ARR_GETCHAR:
break;
case EL_VM_INSTR_NUM_TO_STR_ARR:
break;
case EL_VM_INSTR_STR_ARR_SIZE:
break;
case EL_VM_INSTR_PUSH_STR:
tmp_sor++;
tmp_sor += list->body.instr_space[tmp_sor].instr;
break;
case EL_VM_INSTR_PUSH_NUM:
tmp_sor++;
tmp_v = &(list->body.instr_space[tmp_sor].instr);
break;
case EL_VM_INSTR_JZ:
tmp_arg = list->body.instr_space[tmp_sor].instr_s.arg.JZ.addrl;
tmp_arg += list->body.instr_space[tmp_sor].instr_s.arg.JZ.addrm << 8;
tmp_arg += list->body.instr_space[tmp_sor].instr_s.arg.JZ.addrh << 16;
break;
case EL_VM_INSTR_JNZ:
tmp_arg = list->body.instr_space[tmp_sor].instr_s.arg.JNZ.addrl;
tmp_arg += list->body.instr_space[tmp_sor].instr_s.arg.JNZ.addrm << 8;
tmp_arg += list->body.instr_space[tmp_sor].instr_s.arg.JNZ.addrh << 16;
break;
case EL_VM_INSTR_JMP:
tmp_arg = list->body.instr_space[tmp_sor].instr_s.arg.JMP.addrl;
tmp_arg += list->body.instr_space[tmp_sor].instr_s.arg.JMP.addrm << 8;
tmp_arg += list->body.instr_space[tmp_sor].instr_s.arg.JMP.addrh << 16;
break;
case EL_VM_INSTR_MALLOC:
// el_printf(" size: 0x%X\n",list->body.instr_space[tmp_sor].instr_s.arg.MALLOC.size);
break;
case EL_VM_INSTR_PUSH_LOCALVAR:
// el_printf(" var offset: 0x%X\n",list->body.instr_space[tmp_sor].instr_s.arg.PUSH_LOCALVAR.var_offset);
break;
case EL_VM_INSTR_POP2GLOBALVAR:
// el_printf(" var offset: 0x%X\n",list->body.instr_space[tmp_sor].instr_s.arg.POP2GLOBALVAR.var_offset);
break;
case EL_VM_INSTR_PUSH_GLOBALVAR:
// el_printf(" var offset: 0x%X\n",list->body.instr_space[tmp_sor].instr_s.arg.PUSH_GLOBALVAR.var_offset);
break;
case EL_VM_INSTR_POP2LOCALVAR:
tmp_arg = list->body.instr_space[tmp_sor].instr_s.arg.POP2LOCALVAR.var_offset;
break;
case EL_VM_INSTR_CALL:
tmp_sor++;
break;
case EL_VM_INSTR_EXT_CALL:
tmp_sor++;
break;
case EL_VM_INSTR_ADD:
case EL_VM_INSTR_SUB:
case EL_VM_INSTR_MUL:
case EL_VM_INSTR_DIV:
case EL_VM_INSTR_MOD:
case EL_VM_INSTR_LSHIFT:
case EL_VM_INSTR_RSHIFT:
case EL_VM_INSTR_NOT_EQ:
case EL_VM_INSTR_EQ:
case EL_VM_INSTR_BITOR:
case EL_VM_INSTR_OR:
case EL_VM_INSTR_BITAND:
case EL_VM_INSTR_AND:
case EL_VM_INSTR_XOR:
case EL_VM_INSTR_SIZEOF:
case EL_VM_INSTR_LT:
case EL_VM_INSTR_GT:
case EL_VM_INSTR_LE:
case EL_VM_INSTR_GE:
case EL_VM_INSTR_RET:
case EL_VM_INSTR_RECOVER_SP_FROM_TP:
case EL_VM_INSTR_PUSH_SP_SET_TP:
case EL_VM_INSTR_PUSH_RA:
// case EL_VM_INSTR_PUSH_PC:
case EL_VM_INSTR_NUM2VAR:
case EL_VM_INSTR_NIL2LOCALVAR:
case EL_VM_INSTR_NIL2GLOBALVAR:
case EL_VM_INSTR_POP:
break;
}
tmp_sor++;
}
}
if(list->child){
elang_print_instr_sub(states,list->child);
}
list = list->next;
}
return 0;
}
OPEN_API_HIDDEN static int elang_print_instr(elang_states_t* states){
elang_print_instr_sub(states,states->root_var_list);
}
OPEN_API_HIDDEN static int elang_ext_func_call(elang_states_t* states,elang_ext_func_list_t* ext_func) {
elang_mem_pool_t* tmp_mem;
tmp_mem = elang_var_new(states,0,0,ELANG_TYPE_NIL);
states->ext_return_var = tmp_mem->index;
ext_func->cb(states->states_p);
elang_vm_stack_push(states,states->ext_return_var); // return var
}
OPEN_API_HIDDEN static int elang_exec_instr(elang_states_t* states){
elang_var_list_t* tmp_var_list;
elang_instr_space_t* instr_space;
el_uint32_t tmp_v;
el_uint32_t tmp_v2;
elang_stack_t tmp_stack;
elang_stack_t tmp_stack2;
elang_stack_t tmp_stack3;
el_int32_t tmp_int;
el_int32_t tmp_int2;
elang_mem_pool_t* tmp_mem;
float* tmp_f;
float* tmp_f2;
float* tmp_f3;
elang_var_list_t* tmp_func;
el_uint32_t last_instr_space_id;
elang_mem_pool_t* tmp_mem2;
elang_mem_pool_t* tmp_mem3;
elang_ext_func_list_t* tmp_ext_func;
el_uint32_t* tmp_u32_p;
while(1){
elang_print_stack(states);
#if (!defined(GC_DEBUG)) && GC_DEBUG == 0
elang_print_mem_used(states);
elang_mem_pool_gc(states);
elang_print_mem_used(states);
#endif
#if GC_ENABLE_ON_EXEC_TIME == 1
elang_mem_pool_gc(states);
#endif
instr_space = states->sh_instr_space + states->regs.pc;
if(states->regs.pc >= (*(states->sh_cur_instr_sor))){
break;
}
switch(instr_space->instr_s.opcode){
case EL_VM_INSTR_RESET:
case EL_VM_INSTR_EXT:
case EL_VM_INSTR_DATA:
break;
case EL_VM_INSTR_LOAD_STR:
case EL_VM_INSTR_LOAD_CHAR:
break;
case EL_VM_INSTR_PUSH_NUM:
++states->regs.pc;
instr_space = states->sh_instr_space + states->regs.pc;
tmp_f2 = &tmp_stack2;
tmp_stack2 = instr_space->instr;
tmp_mem = elang_var_new(states,0,4,ELANG_TYPE_NUM);
el_memcpy(tmp_mem->data,&tmp_stack2,4);
elang_vm_stack_push(states,tmp_mem->index);
break;
case EL_VM_INSTR_PUSH_NIL:
tmp_mem = elang_var_new(states,0,0,ELANG_TYPE_NIL);
elang_vm_stack_push(states,tmp_mem->index);
break;
case EL_VM_INSTR_PUSH_INT:
++states->regs.pc;
instr_space = states->sh_instr_space + states->regs.pc;
tmp_v = instr_space->instr;
elang_vm_stack_push(states,instr_space->instr);
break;
case EL_VM_INSTR_JZ:
tmp_v = instr_space->instr_s.arg.JZ.addrl;
tmp_v += instr_space->instr_s.arg.JZ.addrm << 8;
tmp_v += instr_space->instr_s.arg.JZ.addrh << 16;
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
if(*tmp_f == (float)0){
states->regs.pc = tmp_v;
continue;
}
break;
case EL_VM_INSTR_JNZ:
tmp_v = instr_space->instr_s.arg.JNZ.addrl;
tmp_v += instr_space->instr_s.arg.JNZ.addrm << 8;
tmp_v += instr_space->instr_s.arg.JNZ.addrh << 16;
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
if(*tmp_f != (float)0){
states->regs.pc = tmp_v;
continue;
}
break;
case EL_VM_INSTR_JMP:
tmp_v = instr_space->instr_s.arg.JMP.addrl;
tmp_v += instr_space->instr_s.arg.JMP.addrm << 8;
tmp_v += instr_space->instr_s.arg.JMP.addrh << 16;
states->regs.pc = tmp_v;
continue;
break;
case EL_VM_INSTR_ADD:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
break;
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem2 = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem2){
switch(tmp_mem2->type){
case ELANG_TYPE_STR:
break;
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem2->data;
el_printf("num:%f\n",*tmp_f2);
break;
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
if(tmp_mem->type == ELANG_TYPE_STR){
if(tmp_mem2->type == ELANG_TYPE_STR){
// str2 + str1
tmp_mem3 = elang_var_new(states,0,(tmp_mem->size) + (tmp_mem2->size),ELANG_TYPE_STR);
el_memcpy(tmp_mem3->data,tmp_mem2->data,tmp_mem2->size);
el_memcpy((tmp_mem3->data) + (tmp_mem2->size),tmp_mem->data,tmp_mem->size);
tmp_stack2 = tmp_mem3->index;
}else{
// str(c2) + str1
tmp_v = *tmp_f2;
tmp_mem3 = elang_var_new(states,0,(tmp_mem->size) + 1,ELANG_TYPE_STR);
*(tmp_mem3->data) = tmp_v;
el_memcpy(tmp_mem3->data + 1,tmp_mem->data,tmp_mem->size);
tmp_stack2 = tmp_mem3->index;
}
}else{
if(tmp_mem2->type == ELANG_TYPE_STR){
// str2 + str(c1)
tmp_v = *tmp_f;
tmp_mem3 = elang_var_new(states,0,(tmp_mem2->size) + 1,ELANG_TYPE_STR);
el_memcpy(tmp_mem3->data,tmp_mem2->data,tmp_mem2->size);
*((tmp_mem3->data) + (tmp_mem2->size)) = tmp_v;
tmp_stack2 = tmp_mem3->index;
}else{
// num2 + num1
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
*tmp_f3 = (*tmp_f2) + (*tmp_f);
}
}
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_SUB:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
*tmp_f3 = (*tmp_f2) - (*tmp_f);
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_MUL:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
*tmp_f3 = (*tmp_f2) * (*tmp_f);
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_DIV:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
*tmp_f3 = (*tmp_f2) / (*tmp_f);
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_MOD:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
tmp_int = *tmp_f;
tmp_int2 = *tmp_f2;
*tmp_f3 = tmp_int2 % tmp_int;
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_LSHIFT:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
tmp_int = *tmp_f;
tmp_int2 = *tmp_f2;
*tmp_f3 = tmp_int2 << tmp_int;
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_RSHIFT:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
tmp_int = *tmp_f;
tmp_int2 = *tmp_f2;
*tmp_f3 = tmp_int2 >> tmp_int;
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_NOT_EQ:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
if((*tmp_f) != (*tmp_f2)){
*tmp_f3 = 1.f;
}else{
*tmp_f3 = 0.f;
}
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_EQ:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
if((*tmp_f) == (*tmp_f2)){
*tmp_f3 = 1.f;
}else{
*tmp_f3 = 0.f;
}
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_BITOR:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
tmp_int = *tmp_f;
tmp_int2 = *tmp_f2;
*tmp_f3 = tmp_int2 | tmp_int;
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_OR:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
if(((*tmp_f2) != 0.f) || ((*tmp_f) != 0.f)){
*tmp_f3 = 1.f;
}else{
*tmp_f3 = 0.f;
}
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_BITAND:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
tmp_int = *tmp_f;
tmp_int2 = *tmp_f2;
*tmp_f3 = tmp_int2 & tmp_int;
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_AND:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
if(((*tmp_f2) != 0.f) && ((*tmp_f) != 0.f)){
*tmp_f3 = 1.f;
}else{
*tmp_f3 = 0.f;
}
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_XOR:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
tmp_int = *tmp_f;
tmp_int2 = *tmp_f2;
*tmp_f3 = tmp_int2 ^ tmp_int;
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_LT:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
if((*tmp_f2) < (*tmp_f)){
*tmp_f3 = 1.f;
}else{
*tmp_f3 = 0.f;
}
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_GT:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
if((*tmp_f2) > (*tmp_f)){
*tmp_f3 = 1.f;
}else{
*tmp_f3 = 0.f;
}
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_LE:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
if((*tmp_f2) <= (*tmp_f)){
*tmp_f3 = 1.f;
}else{
*tmp_f3 = 0.f;
}
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_GE:
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
tmp_stack2 = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}
tmp_mem3 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_f3 = tmp_mem3->data;
tmp_stack2 = tmp_mem3->index;
if((*tmp_f2) >= (*tmp_f)){
*tmp_f3 = 1.f;
}else{
*tmp_f3 = 0.f;
}
elang_vm_stack_push(states,tmp_stack2);
break;
case EL_VM_INSTR_POP:
tmp_stack = elang_vm_stack_pop(states);
break;
// case EL_VM_INSTR_PUSH_PC:
// break;
case EL_VM_INSTR_PUSH_SP_SET_TP:
tmp_stack = states->regs.tp;
tmp_stack2 = states->regs.sp;
elang_vm_stack_push(states,tmp_stack);
elang_vm_stack_push(states,tmp_stack2);
if(states->on_shell_mode == EL_TRUE){
tmp_stack2 = *(states->global_index);
elang_vm_stack_push(states,tmp_stack2);
}
break;
case EL_VM_INSTR_EXT_CALL:
tmp_v = instr_space->instr_s.arg.CALL.addrl;
tmp_v += instr_space->instr_s.arg.CALL.addrm << 8;
tmp_v += instr_space->instr_s.arg.CALL.addrh << 16;
++states->regs.pc;
instr_space = states->sh_instr_space + states->regs.pc;
states->regs.tp = states->regs.sp - instr_space->instr - 1;
tmp_ext_func = elang_ext_func_searchByindex(states,tmp_v);
if(tmp_ext_func == NULL){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_ext_func_call(states,tmp_ext_func);
tmp_stack = elang_vm_stack_pop(states);
states->regs.sp = states->stack[states->regs.tp - 2];
tmp_stack2 = states->stack[states->regs.tp - 3];
// last_instr_space_id = states->stack[states->regs.tp - 1];
elang_vm_stack_push(states,tmp_stack); // return var
states->regs.tp = tmp_stack2;
break;
case EL_VM_INSTR_CALL:
tmp_v = instr_space->instr_s.arg.CALL.addrl;
tmp_v += instr_space->instr_s.arg.CALL.addrm << 8;
tmp_v += instr_space->instr_s.arg.CALL.addrh << 16;
++states->regs.pc;
instr_space = states->sh_instr_space + states->regs.pc;
states->regs.tp = states->regs.sp - instr_space->instr - 1;
tmp_mem = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_u32_p = tmp_mem->data;
if(states->on_shell_mode == EL_TRUE){
// 鍦╯***** 妯″紡涓� call鐨勫弬鏁版槸global_index.
tmp_func = elang_function_searchByindex(states,tmp_v);
states->sh_instr_space = tmp_func->body.instr_space;
states->sh_cur_instr_sor = &(tmp_func->body.cur_instr_sor);
states->global_index = &(tmp_func->body.global_index);
*tmp_u32_p = states->regs.pc + 1;
elang_vm_stack_push(states,tmp_mem->index); // push PC
states->regs.pc = 0;
}else{
// 鍦ㄨ櫄鎷熸満妯″紡涓� call鐨勫弬鏁版槸 缁濆鍦板潃
*tmp_u32_p = states->regs.pc + 1;
elang_vm_stack_push(states,tmp_mem->index); // push PC
states->regs.pc = tmp_v;
}
continue;
// switch instr space
break;
case EL_VM_INSTR_MALLOC:
tmp_v = instr_space->instr_s.arg.MALLOC.size;
while(tmp_v--){
tmp_mem = elang_var_new(states,0,0,ELANG_TYPE_NIL);
elang_vm_stack_push(states,tmp_mem->index);
}
break;
case EL_VM_INSTR_NUM2VAR:
tmp_stack = states->stack[states->regs.sp-1];
tmp_mem = elang_var_new(states,0,4,ELANG_TYPE_NUM);
el_memcpy(tmp_mem->data,&tmp_stack,4);
states->stack[states->regs.sp-1] = tmp_mem->index;
break;
case EL_VM_INSTR_POP2LOCALVAR:
tmp_v = instr_space->instr_s.arg.POP2LOCALVAR.var_offset;
tmp_stack = elang_vm_stack_pop(states);
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_LIST:
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}
// el_printf("EL_VM_INSTR_POP2LOCALVAR tmp_stack: %d\n",tmp_stack);
// el_printf("EL_VM_INSTR_POP2LOCALVAR tmp_f: %p\n",tmp_f);
// el_printf("EL_VM_INSTR_POP2LOCALVAR var float: %f\n",*tmp_f);
// tmp_f2 = &tmp_stack;
// el_printf(" var float: %f\n",*tmp_f2);
// tmp_mem = elang_var_new(states,0,4,ELANG_TYPE_NUM);
// el_memcpy(tmp_mem->data,&tmp_stack,4);
// el_printf(" tmp_mem->index: %d\n",tmp_mem->index);
states->stack[states->regs.tp + tmp_v] = tmp_stack;
break;
case EL_VM_INSTR_RET:
tmp_stack = elang_vm_stack_pop(states);
states->regs.sp = states->stack[states->regs.tp - 2];
tmp_stack2 = states->stack[states->regs.tp - 3];
last_instr_space_id = states->stack[states->regs.tp - 1];
elang_vm_stack_push(states,tmp_stack); // return var
tmp_v = states->stack[states->regs.tp + 1 + states->stack[states->regs.tp]];
states->regs.tp = tmp_stack2;
tmp_mem = elang_var_searchbyindex(states,tmp_v);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
case ELANG_TYPE_LIST:
case ELANG_TYPE_STR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
break;
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_u32_p = tmp_mem->data;
if(states->on_shell_mode == EL_TRUE){
// 鍦╯***** 妯″紡涓� call鐨勫弬鏁版槸global_index.
tmp_func = elang_function_searchByindex(states,last_instr_space_id);
states->sh_instr_space = tmp_func->body.instr_space;
states->sh_cur_instr_sor = &(tmp_func->body.cur_instr_sor);
states->global_index = &(tmp_func->body.global_index);
states->regs.pc = *tmp_u32_p;
// el_exit(0);
}else{
// 鍦ㄨ櫄鎷熸満妯″紡涓� call鐨勫弬鏁版槸 缁濆鍦板潃
states->regs.pc = *tmp_u32_p;
}
elang_print_stack(states);
continue;
break;
case EL_VM_INSTR_PUSH_LOCALVAR:
tmp_v = instr_space->instr_s.arg.PUSH_LOCALVAR.var_offset;
tmp_v = states->stack[states->regs.tp + tmp_v];
elang_vm_stack_push(states,tmp_v);
break;
case EL_VM_INSTR_SIZEOF:
break;
case EL_VM_INSTR_POP2GLOBALVAR:
tmp_v = instr_space->instr_s.arg.POP2LOCALVAR.var_offset;
tmp_stack = elang_vm_stack_pop(states);
states->stack[tmp_v] = tmp_stack;
break;
case EL_VM_INSTR_PUSH_GLOBALVAR:
tmp_v = instr_space->instr_s.arg.PUSH_GLOBALVAR.var_offset;
tmp_v = states->stack[tmp_v];
elang_vm_stack_push(states,tmp_v);
break;
case EL_VM_INSTR_STR_ARR_SPILT:
tmp_stack3 = elang_vm_stack_pop(states); // end
tmp_stack2 = elang_vm_stack_pop(states); // offset
tmp_stack = elang_vm_stack_pop(states); // var
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
case ELANG_TYPE_NUM:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_STR:
case ELANG_TYPE_LIST:
break;
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_mem2 = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem2){
switch(tmp_mem2->type){
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
case ELANG_TYPE_STR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem2->data;
break;
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_mem2 = elang_var_searchbyindex(states,tmp_stack3);
if(tmp_mem2){
switch(tmp_mem2->type){
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
case ELANG_TYPE_STR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem2->data;
break;
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_int = (*tmp_f);
tmp_int2 = (*tmp_f2) + 1 - (*tmp_f);
if(tmp_mem->type == ELANG_TYPE_STR){
tmp_mem2 = elang_var_new(states,0,tmp_int2,ELANG_TYPE_STR);
if(tmp_int < 0){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
if(tmp_mem->size < (tmp_int + tmp_int2)){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
el_memcpy(tmp_mem2->data,(tmp_mem->data) + tmp_int,tmp_int2);
}else{
tmp_mem2 = elang_var_new(states,0,tmp_int2 * 4,ELANG_TYPE_LIST);
if(tmp_int < 0){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
if((tmp_mem->size/4) < (tmp_int + tmp_int2)){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
el_memcpy(tmp_mem2->data,(tmp_mem->data) + (tmp_int*4),tmp_int2*4);
}
elang_vm_stack_push(states,tmp_mem2->index);
break;
case EL_VM_INSTR_STR_ARR_GETCHAR:
tmp_stack = elang_vm_stack_pop(states); // offset
tmp_stack2 = elang_vm_stack_pop(states); // var
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
case ELANG_TYPE_STR:
case ELANG_TYPE_LIST:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
case ELANG_TYPE_NUM:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_STR:
case ELANG_TYPE_LIST:
break;
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
if(tmp_mem->type == ELANG_TYPE_STR) {
tmp_mem2 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
tmp_int = *tmp_f;
if(tmp_int < 0){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
if(tmp_int >= tmp_mem->size){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_f = tmp_mem2->data;
tmp_int = *(tmp_mem->data + tmp_int);
*tmp_f = tmp_int;
}else{
tmp_u32_p = tmp_mem->data;
tmp_int = *tmp_f;
if(tmp_int < 0){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
if(tmp_int >= (tmp_mem->size * 4)){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_f = tmp_mem2->data;
tmp_mem = elang_var_searchbyindex(states,*(tmp_u32_p + tmp_int));
tmp_mem2 = elang_var_new(states,0,tmp_mem->size,tmp_mem->type);
el_memcpy(tmp_mem2->data,tmp_mem->data,tmp_mem->size);
}
elang_vm_stack_push(states,tmp_mem2->index);
break;
case EL_VM_INSTR_STR_ARR_SIZE:
tmp_stack = elang_vm_stack_pop(states); // offset
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
tmp_mem2 = elang_var_new(states,0,4,ELANG_TYPE_NUM);
if(tmp_mem){
if(tmp_mem->type == ELANG_TYPE_LIST){
tmp_f = tmp_mem2->data;
*tmp_f = (tmp_mem->size / 4);
}else{
tmp_f = tmp_mem2->data;
*tmp_f = tmp_mem->size;
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
elang_vm_stack_push(states,tmp_mem2->index);
break;
case EL_VM_INSTR_NUM_TO_STR_ARR:
tmp_stack = elang_vm_stack_pop(states); // num
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_STR:
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_mem2 = elang_var_new(states,0,1,ELANG_TYPE_STR);
tmp_int = *tmp_f;
*(tmp_mem2->data) = tmp_int;
elang_vm_stack_push(states,tmp_mem2->index);
break;
case EL_VM_INSTR_POP2LIST:
tmp_v = instr_space->instr_s.arg.POP2LIST.items_cnt;
tmp_v2 = tmp_v;
tmp_mem2 = elang_var_new(states,0,4 * tmp_v2,ELANG_TYPE_LIST);
while(tmp_v){
tmp_stack = elang_vm_stack_pop(states); // num
tmp_u32_p = tmp_mem2->data;
*(tmp_u32_p + (tmp_v - 1)) = tmp_stack;
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_v--;
}
elang_vm_stack_push(states,tmp_mem2->index);
break;
case EL_VM_INSTR_POP2LIST_OFFSET_ONE_ITEM:
// OPERAND
// OFFSET
// ITEM0
tmp_stack = elang_vm_stack_pop(states); // ITEM0
tmp_mem2 = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem2){
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_stack2 = elang_vm_stack_pop(states); // OFFSET
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
case ELANG_TYPE_STR:
case ELANG_TYPE_LIST:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_v = (*tmp_f);
tmp_stack3 = elang_vm_stack_pop(states); // OPERAND
tmp_mem = elang_var_searchbyindex(states,tmp_stack3);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
case ELANG_TYPE_STR:
case ELANG_TYPE_NUM:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_LIST:
break;
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
if((tmp_v * 4) >= (tmp_mem->size * 4)){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_u32_p = tmp_mem->data;
tmp_u32_p += tmp_v;
*tmp_u32_p = tmp_stack;
elang_vm_stack_push(states,tmp_mem->index);
break;
case EL_VM_INSTR_POP2LIST_OFFSET:
// OPERAND
// OFFSET
// END
// ITEM0
// ITEM1
// ...
// ITEMn
tmp_v = instr_space->instr_s.arg.POP2LIST_OFFSET.items_cnt;
tmp_v2 = tmp_v;
tmp_mem2 = elang_var_new(states,0,4 * tmp_v2,ELANG_TYPE_LIST);
while(tmp_v){
tmp_stack = elang_vm_stack_pop(states); // num
tmp_u32_p = tmp_mem2->data;
*(tmp_u32_p + (tmp_v - 1)) = tmp_stack;
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_v--;
}
// END
// OFFSET
// OPERAND VAR
tmp_stack3 = elang_vm_stack_pop(states); // end
tmp_stack2 = elang_vm_stack_pop(states); // offset
tmp_stack = elang_vm_stack_pop(states); // var
tmp_mem = elang_var_searchbyindex(states,tmp_stack3);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
case ELANG_TYPE_STR:
case ELANG_TYPE_LIST:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f = tmp_mem->data;
break;
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_mem = elang_var_searchbyindex(states,tmp_stack2);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
case ELANG_TYPE_STR:
case ELANG_TYPE_LIST:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_NUM:
tmp_f2 = tmp_mem->data;
break;
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
tmp_v = (*tmp_f2);
tmp_v2 = (*tmp_f) - (*tmp_f2) + 1;
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
switch(tmp_mem->type){
case ELANG_TYPE_NIL:
case ELANG_TYPE_CHAR:
case ELANG_TYPE_STR:
case ELANG_TYPE_NUM:
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
break;
case ELANG_TYPE_LIST:
break;
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
if((tmp_v + tmp_v2) > (tmp_mem->size * 4)){
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
el_memcpy((tmp_mem->data) + (4 * tmp_v),tmp_mem2->data,4 * tmp_v2);
elang_vm_stack_push(states,tmp_mem->index);
break;
case EL_VM_INSTR_PUSH_STR:
++states->regs.pc;
instr_space = states->sh_instr_space + states->regs.pc;
tmp_v = instr_space->instr;
tmp_mem = elang_var_new(states,0,tmp_v,ELANG_TYPE_STR);
tmp_v2 = 0;
while(tmp_v--){
++states->regs.pc;
instr_space = states->sh_instr_space + states->regs.pc;
*(tmp_mem->data + tmp_v2) = (instr_space->instr);
tmp_v2++;
}
elang_vm_stack_push(states,tmp_mem->index);
break;
case EL_VM_INSTR_RECOVER_SP_FROM_TP:
case EL_VM_INSTR_PUSH_RA:
case EL_VM_INSTR_NIL2LOCALVAR:
case EL_VM_INSTR_NIL2GLOBALVAR:
case EL_VM_INSTR_PUSH_INSTR_SPACE_ID:
break;
}
states->regs.pc++;
}
}
OPEN_API_HIDDEN static int elang_wait_close(elang_states_t* states){
static elang_token_t* static_tok;
int compile_enable;
if(states->sh_cur_list == NULL){
states->sh_cur_list = states->tok_list;
static_tok = states->sh_cur_list;
}else{
if(states->last_compile_enable == EL_TRUE){
if(elang_try_next(states) == EL_TRUE){
states->last_compile_enable = EL_FALSE;
}else{
return -2;
}
}
}
compile_enable = EL_FALSE;
if(static_tok == NULL){
return -1;
}
if(static_tok->next == NULL){
return -1;
}else{
static_tok = static_tok->next;
}
while(static_tok){
if(states->nest_cnt == 0 && static_tok->type == EL_TOKEN_SEMICOLON){
compile_enable = EL_TRUE;
}
if(static_tok->type == EL_TOKEN_LBRACKET){
states->nest_cnt ++;
}else if(static_tok->type == EL_TOKEN_RBRACKET){
states->nest_cnt --;
if(states->nest_cnt == 0){
compile_enable = EL_TRUE;
}
}else{
}
if(compile_enable == EL_TRUE){
elang_parse_top(states,EL_TRUE,EL_FALSE,0);
elang_link_label(states);
elang_print_instr(states);
elang_exec_instr(states);
elang_print_stack(states);
elang_print_mem_used(states);
elang_mem_pool_gc(states);
elang_print_mem_used(states);
states->last_compile_enable = EL_TRUE;
static_tok = states->sh_cur_list;
break;
}
if(static_tok->next){
static_tok = static_tok->next;
}else{
break;
}
}
return 0;
}
OPEN_API_HIDDEN static int elang_parse_init(elang_states_t* states){
elang_token_t* tmp_tok;
states->sh_cur_list = states->tok_list;
states->global_label = NULL;
states->global_var_list_index = 0;
states->root_var_list = NULL;
elang_var_list_new(states,&(states->root_var_list));
EL_MEM_ALLOC_CHECK;
states->root_var_list->body.instr_space = el_malloc(EL_ROM_SIZE * sizeof(elang_instr_space_t));
states->root_var_list->body.var_list_type = EL_VAR_LIST_FUNCTION;
states->root_var_list->body.hash = elang_RsHash("main", sizeof("main"));
states->tmp_var_list = &(states->root_var_list);
states->last_compile_enable = EL_FALSE;
states->on_shell_mode = EL_TRUE;
states->sh_cur_instr_sor = &(states->root_var_list->body.cur_instr_sor);
states->sh_instr_space = states->root_var_list->body.instr_space;
states->global_index = &(states->root_var_list->body.global_index);
states->global_tmp_label_index = 0;
states->global_tmp_label = NULL;
}
OPEN_API_HIDDEN static int elang_vm_init(elang_states_t* states){
el_uint32_t cur_instr_sor;
states->cur_instr_sor = 0;
states->regs.pc = 0;
states->regs.sp = 0;
states->regs.tp = 0;
states->data_root = NULL;
states->mem_pool_index = 0;
states->mem_pool = NULL;
(*(states->tmp_var_list))->body.instr_space[(*(states->tmp_var_list))->body.cur_instr_sor++].instr_s.opcode = EL_VM_INSTR_PUSH_INT; // save arg_cnt,lr
(*(states->tmp_var_list))->body.instr_space[(*(states->tmp_var_list))->body.cur_instr_sor++].instr = 0;
(*(states->tmp_var_list))->body.instr_space[(*(states->tmp_var_list))->body.cur_instr_sor++].instr_s.opcode = EL_VM_INSTR_PUSH_INT;
(*(states->tmp_var_list))->body.instr_space[(*(states->tmp_var_list))->body.cur_instr_sor++].instr = 0;
elang_print_instr(states);
}
OPEN_API_HIDDEN static int elang_debug_print_token_list(elang_states_t* states){
elang_token_t* tmp_tok;
tmp_tok = states->tok_list;
if(tmp_tok == NULL){
return -1;
}
el_printf("******************* elang_debug_print_token_list ************************************************************************\n");
while(tmp_tok){
el_printf(" tmp_tok->type: 0x%x = %s\n",tmp_tok->type,elang_token_type_str[tmp_tok->type]);
if(tmp_tok->type == EL_TOKEN_ID){
el_printf(" tmp_tok->token._id.str: %s\n",tmp_tok->token._id.str);
el_printf(" tmp_tok->token._id.hash: 0x%lX\n",tmp_tok->token._id.hash);
el_printf(" tmp_tok->token._id.keyword: %s(0x%lX)\n",keyword_str[tmp_tok->token._id.is_keyword],tmp_tok->token._id.is_keyword);
}else if(tmp_tok->type == EL_TOKEN_NUM){
el_printf(" tmp_tok->token._num.v: %f\n",tmp_tok->token._num.v);
}else if(tmp_tok->type == EL_TOKEN_CHAR){
el_printf(" tmp_tok->token._char.c: 0x%x (%c)\n",tmp_tok->token._char.c,tmp_tok->token._char.c);
}else if(tmp_tok->type == EL_TOKEN_STR){
el_printf(" tmp_tok->token._str.str: %s\n",tmp_tok->token._str.str);
}
tmp_tok = tmp_tok->next;
}
return 0;
}
#ifndef LIB_MODE
OPEN_API_HIDDEN static int elang_sh_getchar(elang_states_t* states){
int ch;
ch = getch();
if(ch == KEY_F(1)) {
printw("F1 Key pressed");/* not get to us either */
return 0;
}
if(ch == CTRL('c')) {
printw("CTRL + c Key pressed");/* not get to us either */
return 0;
}
return ch;
}
OPEN_API_HIDDEN static int elang_sh(elang_states_t* states){
int ch;
char tmp_str[2] = {'\0','\0'};
int input_finish = EL_FALSE;
while(1){
ch = elang_sh_getchar(states);
if(ch <= 255){
printw("%c", ch);
tmp_str[0] = ch;
tmp_str[1] = '\0';
elang_cs_insert_str(states,tmp_str);
}
if(ch < 0){
continue;
}
if(ch == '\b'){
/* backspace */
el_printf("\b \b");
}else if (ch == '\r' || ch == '\n')
{
el_printf("\n");
input_finish = EL_TRUE;
// break;
}
// if(input_finish) {
if(ch <= 255){
// 鎵ц宸叉湁鐨勮緭鍏�
elang_lex(states);
}
elang_debug_print_token_list(states);
elang_wait_close(states);
refresh();
if(ch == 0){
return ch;
}
}
}
#endif
#ifndef LIB_MODE
int main(const int argc,const char** argv){
elang_states_t states;
elang_states_t** states_p;
int cur_char;
char src_file_buff[10*1024];
log_fp = fopen("log.txt","w+");
if(NULL == log_fp)
{
printf("open failed\n");
return -1;
}
EL_MEM_ALLOC_CHECK;
states_p = (elang_states_t**)el_malloc(sizeof(elang_states_t*));
*states_p = &states;
states.states_p = states_p;
states.ext_func_index = 0;
states.ext_func_list = NULL;
if(elang_ext_boot_hook(states_p) < 0){
el_exit(-1);
}
WINDOW *stdscr;
stdscr = initscr(); /* Start curses mode */
raw(); /* Line buffering disabled */
keypad(stdscr, TRUE); /* We get F1, F2 etc.. */
noecho(); /* Don't echo() while we do getch */
scrollok(stdscr,1);
el_printf("Elang boot...\n");
// ch = getch(); /* If raw() hadn't been called
// refresh(); /* Print it on to the real screen */
// getch(); /* Wait for user input */
elang_lex_init(&states);
elang_parse_init(&states);
elang_vm_init(&states);
FILE *fp;
fp=fopen("test.txt", "r");
if (fp == NULL){
printf("file not exist!");
el_printf("file not exist!");
}else{
if(fread(src_file_buff,sizeof(src_file_buff),sizeof(char),fp) < 0){
printf("file is empyty or too Big\n");
el_printf("file is empyty or too Big\n");
fclose(fp);
goto _exit_label;
}
el_printf("src_file_buff: %s\n",src_file_buff);
cur_char = strlen(src_file_buff);
el_printf("cur_char: %d\n",cur_char);
elang_cs_create_from_str(&states,src_file_buff);
while(cur_char--){
elang_lex(&states);
}
elang_debug_print_token_list(&states);
states.sh_cur_list = states.tok_list;
while(states.sh_cur_list->next){
elang_parse_top(&states,EL_TRUE,EL_FALSE,0);
// elang_try_next(&states);
}
elang_link_label(&states);
elang_print_instr(&states);
elang_exec_instr(&states);
elang_print_stack(&states);
elang_print_mem_used(&states);
elang_print_stack(&states);
elang_mem_pool_gc(&states);
elang_print_stack(&states);
elang_print_mem_used(&states);
fclose(fp);
goto _exit_label;
}
elang_cs_create_from_str(&states,NULL);
// elang_cs_insert_str(elang_states_t* states,char* str);
elang_sh(&states);
_exit_label:
endwin(); /* End curses mode */
echo();
fclose(log_fp);
elang_ext_exit_hook(states.states_p);
elang_lex_deinit(&states);
}
#endif
// extern api
OPEN_API_DEFAULT int elang_ext_new_state(void** vm) {
elang_states_t* states;
elang_states_t** states_p;
EL_MEM_ALLOC_CHECK;
states_p = (elang_states_t**)el_malloc(sizeof(elang_states_t*));
EL_MEM_ALLOC_CHECK;
states = (elang_states_t*)el_malloc(sizeof(elang_states_t));
*states_p = states;
states->states_p = states_p;
states->ext_func_index = 0;
states->ext_func_list = NULL;
elang_lex_init(states);
elang_parse_init(states);
elang_vm_init(states);
*vm = states_p;
}
OPEN_API_DEFAULT int elang_ext_set_code(void** vm,const char* code) {
elang_states_t* states;
elang_states_t** states_p;
states_p = *vm;
states = *states_p;
elang_cs_create_from_str(states,code);
}
OPEN_API_DEFAULT int elang_ext_add_code(void** vm,const char* code) {
elang_states_t* states;
elang_states_t** states_p;
states_p = *vm;
states = *states_p;
elang_cs_insert_str(states,code);
}
OPEN_API_DEFAULT int elang_ext_run(void** vm) {
el_uint32_t code_len;
elang_states_t* states;
elang_states_t** states_p;
states_p = *vm;
states = *states_p;
code_len = strlen(states->cs.src.str.cur_str);
while(code_len--){
elang_lex(states);
}
elang_debug_print_token_list(states);
states->sh_cur_list = states->tok_list;
while(states->sh_cur_list->next){
elang_parse_top(states,EL_TRUE,EL_FALSE,0);
}
elang_link_label(states);
elang_print_instr(states);
#if MEM_USED_CHECK == 1
global_mem_used_bytes_after_parse = global_mem_used_bytes;
printf("after parse vm usable mem: %d Bytes %f KBytes %f MBytes\n",global_mem_used_bytes,global_mem_used_bytes/1024.00,global_mem_used_bytes/1024.00/1024.00);
#endif
elang_exec_instr(states);
elang_mem_pool_gc(states);
}
OPEN_API_DEFAULT int elang_ext_run_auto(void** vm) {
el_uint32_t code_len;
elang_states_t* states;
elang_states_t** states_p;
states_p = *vm;
states = *states_p;
code_len = strlen(states->cs.src.str.cur_str);
while(code_len--){
elang_lex(states);
}
states->sh_cur_list = states->tok_list;
while(states->sh_cur_list->next){
elang_parse_top(states,EL_TRUE,EL_FALSE,0);
}
elang_wait_close(states); // 濡傛灉闇€瑕侀噸鍚櫄鎷熸満闇€瑕乺eset杩欎釜鍑芥暟鍐呴儴鐨剆tatic鍙橀噺
elang_mem_pool_gc(states);
}
OPEN_API_DEFAULT int elang_ext_get_mem_used(void** vm,el_uint32_t* item,el_uint32_t* size){
elang_states_t* states;
elang_states_t** states_p;
states_p = *vm;
states = *states_p;
*size = elang_mem_total_used(states,item);
#if MEM_USED_CHECK == 1
global_mem_used_bytes_after_parse = global_mem_used_bytes - global_mem_used_bytes_after_parse;
printf("vm usable mem: %d Bytes %f KBytes %f MBytes\n",global_mem_used_bytes,global_mem_used_bytes/1024.00,global_mem_used_bytes/1024.00/1024.00);
printf("vm usable mem only vm: %d Bytes %f KBytes %f MBytes\n",global_mem_used_bytes_after_parse,global_mem_used_bytes_after_parse/1024.00,global_mem_used_bytes_after_parse/1024.00/1024.00);
#endif
return 0;
}
OPEN_API_DEFAULT int elang_ext_register_func(void** vm,char* func_name,int (*cb)(void* vm)) {
elang_ext_func_list_t* tmp_func;
elang_ext_func_list_t* tmp_func_tail;
elang_states_t* states;
elang_states_t** states_p;
states_p = *vm;
states = *states_p;
EL_MEM_ALLOC_CHECK;
tmp_func = (elang_ext_func_list_t*)el_malloc(sizeof(elang_ext_func_list_t));
tmp_func->next = NULL;
tmp_func->hash = elang_RsHash(func_name, strlen(func_name) + 1); // 涓存椂鍋氭硶浼氭湁hash纰版挒椋庨櫓
tmp_func->cb = cb;
tmp_func->func_index = states->ext_func_index++;
if(states->ext_func_list == NULL){
states->ext_func_list = tmp_func;
return 0;
}
tmp_func_tail = states->ext_func_list;
while(tmp_func_tail->next){
tmp_func_tail = tmp_func_tail->next;
}
tmp_func_tail->next = tmp_func;
return 0;
}
OPEN_API_DEFAULT int elang_ext_pop_arg(void** vm,elang_ext_data_type_t *type,unsigned char** data,float* fnum,el_uint32_t* len) {
elang_stack_t tmp_stack;
elang_mem_pool_t* tmp_mem;
unsigned char* tmp_str;
elang_states_t* states;
elang_states_t** states_p;
states_p = *vm;
states = *states_p;
*data = NULL;
*len = 0;
if(states->regs.sp <= states->regs.tp){
return -1;
}
tmp_stack = elang_vm_stack_pop(states); // num
tmp_mem = elang_var_searchbyindex(states,tmp_stack);
if(tmp_mem){
*len = tmp_mem->size;
switch(tmp_mem->type){
case ELANG_TYPE_STR:
*type = ELANG_EXT_DATA_STR;
EL_MEM_ALLOC_CHECK;
tmp_str = el_malloc(sizeof(unsigned char) * (tmp_mem->size));
el_memcpy(tmp_str,tmp_mem->data,tmp_mem->size);
*data = tmp_str;
break;
case ELANG_TYPE_LIST:
*type = ELANG_EXT_DATA_LIST;
break;
case ELANG_TYPE_NIL:
*type = ELANG_EXT_DATA_NIL;
break;
case ELANG_TYPE_CHAR:
// *type = ELANG_EXT_DATA_STR;
break;
case ELANG_TYPE_NUM:
*type = ELANG_EXT_DATA_FLOAT;
// tmp_f = el_malloc(sizeof(float));
el_memcpy(fnum,tmp_mem->data,4);
break;
}
}else{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX %s: %d error XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",__FUNCTION__,__LINE__);
el_exit(-1);
}
return 0;
}
OPEN_API_DEFAULT int elang_ext_set_return_var(void** vm,el_uint32_t index){
elang_states_t* states;
elang_states_t** states_p;
states_p = *vm;
states = *states_p;
states->ext_return_var = index;
}
OPEN_API_DEFAULT el_uint32_t elang_ext_new_str_var(void** vm,unsigned char* data,el_uint32_t len){
elang_mem_pool_t* tmp_mem;
elang_states_t* states;
elang_states_t** states_p;
states_p = *vm;
states = *states_p;
tmp_mem = elang_var_new(states,0,len,ELANG_TYPE_STR);
el_memcpy(tmp_mem->data,data,len);
return tmp_mem->index;
}
OPEN_API_DEFAULT el_uint32_t elang_ext_new_nil_var(void** vm){
elang_mem_pool_t* tmp_mem;
elang_states_t* states;
elang_states_t** states_p;
states_p = *vm;
states = *states_p;
tmp_mem = elang_var_new(states,0,0,ELANG_TYPE_NIL);
return tmp_mem->index;
}
OPEN_API_DEFAULT el_uint32_t elang_ext_new_float_var(void** vm,float* value){
elang_mem_pool_t* tmp_mem;
elang_states_t* states;
elang_states_t** states_p;
states_p = *vm;
states = *states_p;
tmp_mem = elang_var_new(states,0,4,ELANG_TYPE_NUM);
el_memcpy(tmp_mem->data,value,4);
return tmp_mem->index;
}
OPEN_API_DEFAULT el_uint32_t elang_ext_get_instr_count(void** vm,float* value){
elang_mem_pool_t* tmp_mem;
elang_states_t* states;
elang_states_t** states_p;
states_p = *vm;
states = *states_p;
return states->global_instr_count;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/Li_XiongHui/juicescript.git
git@gitee.com:Li_XiongHui/juicescript.git
Li_XiongHui
juicescript
juicescript
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385