アセンブリ言語を模した何か。ラベルとかはないです。
アセンブリ言語を模した何か。ラベルとかはないです。
#runtime "hsp3cl" #cmpopt varinit 1 #include "user32.as" #include "Dictionary.as" ;Dictionary.as ; http://dev.onionsoft.net/seed/info.ax?id=1558 ; https://github.com/yosgspec/DictionaryOnHSP #module Reg #deffunc local init new@Dictionary regX,"int",,,{" AX: 0, BX: 0, CX: 0, DX: 0 "} return #deffunc local set str a,int b if dcContainsKey(regX,a) { dcSet regX,a,b return 0 } return 1 #defcfunc local get str a return dcItem(regX,a) #global init@Reg #module @fun #define setfun %tfun \ new@Dictionary funs,"label":\ dcAdd funs,"SET",*%i: if 0{*%o: set@Reg a,int(b): return}\ dcAdd funs,"CP" ,*%i: if 0{*%o: set@Reg a,get@Reg(b): return}\ dcAdd funs,"OUT",*%i: if 0{*%o: mes get@Reg(a): return}\ dcAdd funs,"ADD",*%i: if 0{*%o: set@Reg a,get@Reg(a)+get@Reg(b): return}\ dcAdd funs,"SUB",*%i: if 0{*%o: set@Reg a,get@Reg(a)-get@Reg(b): return}\ dcAdd funs,"MUL",*%i: if 0{*%o: set@Reg a,get@Reg(a)*get@Reg(b): return}\ dcAdd funs,"DIV",*%i: if 0{*%o: set@Reg a,get@Reg(a)/get@Reg(b): return}\ dcAdd funs,"EXIT",*%i:if 0{*%o :end: return} #deffunc local init dimtype fn,vartype("label") sdim a: sdim b setfun return #deffunc fun str fnName,str _a,str _b a=_a: b=_b if 0=dcContainsKey(funs,fnName): return 1 dcRefItem funs,fnName,fn gosub fn return 0 #global init@@fun #module #deffunc call str argss args=argss split args," ",args switch length(args) case 1: fun args(0),"","": swbreak case 2: fun args(0),args(1),"": swbreak case 3: fun args(0),args(1),args(2): swbreak swend return stat #global #module #defcfunc spaceParser str _code code=_code sdim codes strrep code,"\\\"","__escWQuot__" split code,"\"",codes code="" foreach codes: s=codes.cnt if 0=cnt\2 { strrep s,"\t"," " CharUpper varptr(s) while 0<=instr(s,," "): strrep s," "," ": wend } if 0<cnt: code+="\"" code+=s loop strrep code,"__escWQuot__","\\\"" #const crCode $0D #const lfCode $0A sdim lf:poke lf,,lfCode strrep code,"\n",lf strrep code,"\r",lf split code,lf,codes code="" foreach codes: s=codes.cnt strrep s,"\\;","__escSemiColon__" remi=instr(s,,";") if 0<=remi: s=strmid(s,0,remi) strrep s,"__escSemiColon__","\\;" s=strtrim(s,,' ') code+=s+"\n" loop while 0<=instr(code,,"\n\n"): strrep code,"\n\n","\n": wend code=strtrim(code,,crCode) code=strtrim(code,,lfCode) code=strtrim(code,,crCode) return code #global #module #deffunc main path=dir_cmdline path=strtrim(path,0,' ') ; ファイル実行 if path!="" { sdim code exist path if 0<=strsize { notesel code noteload path noteunsel code=spaceParser(code) sdim codes split code,"\n",codes foreach codes call codes.cnt loop } else { mes "Not exist file." mes "\""+path+"\"" } }; REPL else { repeat mes "> ",1 sdim s: input s,,2 call spaceParser(s) loop } return #global main