当前位置: 首页>>代码示例>>C++>>正文


C++ VM::makeInteger方法代码示例

本文整理汇总了C++中VM::makeInteger方法的典型用法代码示例。如果您正苦于以下问题:C++ VM::makeInteger方法的具体用法?C++ VM::makeInteger怎么用?C++ VM::makeInteger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VM的用法示例。


在下文中一共展示了VM::makeInteger方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testMakeList

void testMakeList() {
  VM vm;

  Value one = vm.makeInteger(1);
  Value two = vm.makeInteger(2);
  Value three = vm.makeInteger(3);

  {
    Value a = vm.makeList();
    Value b = vm.nil;
    EXPECT(a == b);
  }

  {
    Value a = vm.makeList(one);
    Value b = vm.makeCons(one, vm.nil);
    EXPECT(a == b);
  }

  {
    Value a = vm.makeList(one, two);
    Value b = vm.makeCons(one, vm.makeCons(two, vm.nil));
    EXPECT(a == b);
  }

  {
    Value a = vm.makeList(one, two, three);
    Value b = vm.makeCons(one, vm.makeCons(two, vm.makeCons(three, vm.nil)));
    EXPECT(a == b);
  }

}
开发者ID:joshuawarner32,项目名称:mylisp,代码行数:32,代码来源:test.cpp

示例2: testEval

void testEval() {
  VM vm;

  Value plus = vm.syms.add;
  Value add = vm.objs.builtin_add;
  Value _if = vm.syms.if_;
  Value _true = vm.true_;
  Value _false = vm.false_;
  Value one = vm.makeInteger(1);
  Value two = vm.makeInteger(2);

  {
    EXPECT_INT_EQ(eval(vm, vm.makeInteger(1), vm.nil).asInteger(vm), 1);
    EXPECT_INT_EQ(eval(vm, vm.makeInteger(42), vm.nil).asInteger(vm), 42);
  }

  {
    Value list = vm.makeList(add, one, two);

    EXPECT_INT_EQ(eval(vm, list, vm.nil).asInteger(vm), 3);
  }

  {
    Value a = vm.makeSymbol("a");
    Value pair = vm.makeCons(a, vm.makeInteger(42));
    Value env = vm.makeCons(pair, vm.nil);
    EXPECT_INT_EQ(eval(vm, a, env).asInteger(vm), 42);
  }

  {
    Value list = vm.makeList(plus, one, two);

    Value pair = vm.makeCons(plus, add);
    Value env = vm.makeCons(pair, vm.nil);
    EXPECT_INT_EQ(eval(vm, list, env).asInteger(vm), 3);
  }

  {
    Value list = vm.makeList(_if, _true, one, two);
    EXPECT_INT_EQ(eval(vm, list, vm.nil).asInteger(vm), 1);
  }

  {
    Value list = vm.makeList(_if, _false, one, two);
    EXPECT_INT_EQ(eval(vm, list, vm.nil).asInteger(vm), 2);
  }

}
开发者ID:joshuawarner32,项目名称:mylisp,代码行数:48,代码来源:test.cpp

示例3: testInterpret

void testInterpret() {
  VM vm;
  
  Value values[] = {
    vm.makeInteger(1),
    vm.makeInteger(2),
    vm.makeInteger(-1),
  };

  const unsigned char instrs[] = {Opcode::Add, 0, 1, 2, Opcode::Call};

  Frame frame;
  frame.ip = instrs;
  frame.values = values;
  frame.size = 3;

  interpret(vm, &frame);

  EXPECT_INT_EQ(values[2].asInteger(vm), 3);
}
开发者ID:joshuawarner32,项目名称:mylisp,代码行数:20,代码来源:test.cpp

示例4: testParseAndEval

void testParseAndEval() {
  VM vm;

  {
    Value plus = vm.syms.add;
    Value add = vm.objs.builtin_add;

    Value pair = vm.makeCons(plus, add);
    Value env = vm.makeCons(pair, vm.nil);

    Value input = vm.parse("(+ 1 2)");
    Value res = eval(vm, input, env);

    EXPECT_INT_EQ(res.asInteger(vm), 3);
  }

  {
    Value scons = vm.syms.Cons;
    Value cons = vm.objs.builtin_cons;

    Value env = vm.makeList(vm.makeCons(scons, cons));

    Value input = vm.parse("((letlambdas ( ((myfunc x y) (cons x y)) ) myfunc) 1 2)");
    Value res = eval(vm, input, env);

    EXPECT(res == vm.makeCons(vm.makeInteger(1), vm.makeInteger(2)));
  }

  {
    Value input = vm.parse("((import core +) 1 2)");
    Value res = eval(vm, input, vm.nil);

    EXPECT_INT_EQ(res.asInteger(vm), 3);
  }

}
开发者ID:joshuawarner32,项目名称:mylisp,代码行数:36,代码来源:test.cpp

示例5: testSymbols

void testSymbols() {
  VM vm;

  Value a = vm.makeSymbol("a");
  Value b = vm.makeSymbol("b");
  Value a2 = vm.makeSymbol("a");

  Value one = vm.makeInteger(1);
  Value two = vm.makeInteger(2);

  EXPECT(a == a2);
  EXPECT(a != b);
  EXPECT(a2 != b);

  Value map = vm.makeList(
    vm.makeCons(a, one),
    vm.makeCons(b, two));

  EXPECT_INT_EQ(map_lookup(vm, map, a).asInteger(vm), 1);
  EXPECT_INT_EQ(map_lookup(vm, map, b).asInteger(vm), 2);
}
开发者ID:joshuawarner32,项目名称:mylisp,代码行数:21,代码来源:test.cpp

示例6: testSerialize

void testSerialize() {
  VM vm;

  {
    Value original = vm.nil;
    String serialized = serialize(original);
    Value deserialized = deserialize(vm, serialized.text);
    EXPECT(deserialized == original);
  }

  {
    Value original = vm.makeInteger(0);
    String serialized = serialize(original);
    Value deserialized = deserialize(vm, serialized.text);
    EXPECT(deserialized == original);
  }

  {
    Value original = vm.makeInteger(1);
    String serialized = serialize(original);
    Value deserialized = deserialize(vm, serialized.text);
    EXPECT(deserialized == original);
  }

  {
    Value a = vm.makeSymbol("some-random-symbol");
    Value original = vm.makeList(a,
      vm.makeInteger(1),
      vm.makeInteger(42),
      vm.makeInteger(129),
      vm.makeInteger(4),
      vm.makeInteger(5));
    String serialized = serialize(original);
    Value deserialized = deserialize(vm, serialized.text);
    EXPECT(deserialized == original);
  }
}
开发者ID:joshuawarner32,项目名称:mylisp,代码行数:37,代码来源:test.cpp


注:本文中的VM::makeInteger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。