mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-11-29 14:51:17 +00:00
4 lines
40 KiB
JavaScript
4 lines
40 KiB
JavaScript
|
/* ZVM v https://github.com/curiousdannii/ifvms.js */
|
||
|
(function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"==typeof window?"undefined"==typeof global?"undefined"==typeof self?this:self:global:window,t.ZVM=e()}})(function(){var e=Math.min,t=String.fromCharCode;return function(){function s(l,e,r){function t(o,i){if(!e[o]){if(!l[o]){var _="function"==typeof require&&require;if(!i&&_)return _(o,!0);if(n)return n(o,!0);var g=new Error("Cannot find module '"+o+"'");throw g.code="MODULE_NOT_FOUND",g}var a=e[o]={exports:{}};l[o][0].call(a.exports,function(e){var s=l[o][1][e];return t(s||e)},a,a.exports,s,l,e,r)}return e[o].exports}for(var n="function"==typeof require&&require,a=0;a<r.length;a++)t(r[a]);return t}return s}()({1:[function(e,t){"use strict";var s=e("../common/utils.js"),r=s.Class,i=s.U2S16,n=r.subClass({init:function(e,t){this.e=e,this.v=t},toString:function(){return this.v},U2S:function(){return i(this.v)}}),a=n.subClass({toString:function(){var e=this.v;return this.indirect?"e.indirect("+e+")":0===e?"s[--e.sp]":15>--e?"l["+e+"]":"e.m.getUint16("+(this.e.globals+2*(e-15))+")"},store:function(e){var t=this.v;return this.indirect?"e.indirect("+t+","+e+")":this.returnval?"e.variable("+t+","+e+")":0===t?"t="+e+";s[e.sp++]=t":15>--t?"l["+t+"]="+e:"e.ram.setUint16("+(this.e.globals+2*(t-15))+","+e+")"},U2S:function(){return"e.U2S("+this+")"}}),o=r.subClass({init:function(e,t,s,r,i,n){this.e=e,this.context=t,this.code=s,this.pc=r,this.labels=[this.pc+"/"+this.code],this.next=i,this.operands=n,this.post&&this.post()},toString:function(){return this.label()+(this.func?this.func.apply(this,this.operands):"")},args:function(e){return this.operands.join(e)},label:function(){return"/* "+this.labels.join()+" */ "}}),l=o.subClass({stopper:1}),p=l.subClass({post:function(){this.origfunc=this.func,this.func=this.newfunc},newfunc:function(){return"e.stop=1;e.pc="+this.next+";"+this.origfunc.apply(this,arguments)}}),_=p.subClass({storer:1,post:function(){this.storer=this.operands.pop(),this.origfunc=this.func,this.func=this.newfunc}}),g=r.subClass({init:function(e,t){this.ops=e||[],this.code=t||"||"},toString:function(){for(var e,t=0,s=[];t<this.ops.length;)e=this.ops[t++],s.push(e.func?(e.iftrue?"":"!(")+e.func.apply(e,e.operands)+(e.iftrue?"":")"):e);return(this.invert?"(!(":"(")+s.join(this.code)+(this.invert?"))":")")}}),u=o.subClass({brancher:1,keyword:"if",post:function(){var e,t,s=this.operands.pop(),r=s[1];this.iftrue=s[0],0===r||1===r?e="e.ret("+r+")":(r+=this.next-2,this.context.targets.push(r),e="e.pc="+r),this.result=e+";return",this.offset=r,this.cond=new g([this]),this.context.ops.length&&(t=this.context.ops.pop(),t.offset===r?(this.cond.ops.unshift(t.cond),this.labels=t.labels,this.labels.push(this.pc+"/"+this.code)):this.context.ops.push(t))},toString:function(){var e=this.result;return e instanceof h&&(this.e.options.debug&&(e.context=this.context),e+=e.stopper?"; return":"",1<this.result.ops.length&&(e="\n"+e+"\n",this.e.options.debug&&(e+=this.context.spacer))),this.label()+this.keyword+this.cond+" {"+e+"}"}}),c=u.subClass({storer:1,post:function(){c.super.post.call(this),this.storer=this.operands.pop(),this.storer.returnval=1,this.origfunc=this.func,this.func=this.newfunc},newfunc:function(){return this.storer.store(this.origfunc.apply(this,arguments))}}),d=o.subClass({storer:1,post:function(){this.storer=this.operands.pop()},toString:function(){var e=d.super.toString.call(this);return this.storer?this.storer.store(e):e}}),m=l.subClass({result:{v:-1},toString:function(){return this.label()+"e.call("+this.operands.shift()+","+this.result.v+","+this.next+",["+this.args()+"])"}}),f=m.subClass({storer:1,post:function(){this.result=this.operands.pop()}}),h=r.subClass({init:function(e,t){this.e=e,this.pc=t,this.pre=[],this.ops=[],this.post=[],this.targets=[],e.options.debug&&(this.spacer="")},toString:function(){return this.e.options.debug?(this.context&&(this.spacer=this.context.spacer+" "),this.pre.join("")+(1<this.ops.length?this.spacer:"")+this.ops.jo
|
||
|
|