⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pvm.c

📁 压缩包里面的都是精致的基本C语言小程序
💻 C
字号:
#include <stdio.h>#include "../lib/error.h"#include "../lib/hash.h"#include "../lib/nat.h"#include "../lib/mystdlib.h"#include "store.h"#include "pvm.h"nat pvmOperand (store st, operand o){  switch (o->kind)  {    case PID :     {      nat n = storeLookup (st, (o->u).id);      return n;    }    case PNUM :     {      return (newNat ((o->u).i));    }    default: return (newNat (0));  }}void pvmInstruction (store st, instruction i){  switch (i->kind)  {    case MOVL:      {        nat n1 = pvmOperand (st, i->src);        storeUpdate (st, i->dst, n1);        break;      }    case ADDL:      {        nat n1 = pvmOperand (st, i->src);        nat n2 = storeLookup (st, i->dst);        nat n = natAdd (n1, n2);        storeUpdate (st, i->dst, n);        break;      }    case SUBL:      {        nat n1 = pvmOperand (st, i->src);        nat n2 = storeLookup (st, i->dst);        nat n = natSub (n2, n1);        storeUpdate (st, i->dst, n);        break;      }    case MULL:      {        nat n1 = pvmOperand (st, i->src);        nat n2 = storeLookup (st, i->dst);        nat n = natTimes (n1, n2);        storeUpdate (st, i->dst, n);        break;      }    case PPRINT:      {                nat n = pvmOperand (st, i->src);        natOutput (n);        printf ("\n");        break;      }    case COMMENT:      {                //printf ("DO NOTHING FOR COMMENT\n");        break;      }    default:      {        error ("no this case\n");        break;      }  }}void pvmProg (pentiumProg p){  printf ("\nPVM starts:\n");  linkedList l = linkedListGetFirst (p->instructions);  store st = newStore ();        while (l)  {    pvmInstruction (st, l->data);    l = l->next;  }    printf ("\nPVM halts\n");  return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -