1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { 17 expect 18} from 'chai'; 19import 'mocha'; 20import { 21 Isfalse, 22 Istrue, 23 Returnundefined, 24 Imm, 25 Jeqz, 26 Jmp, 27 Label, 28 Lda, 29 Ldai, 30 Sta, 31 VReg 32} from "../../src/irnodes"; 33import { checkInstructions, compileMainSnippet } from "../utils/base"; 34 35 36describe("LogicBinaryOperators", function () { 37 it("ampersandAmpersand", function () { 38 let insns = compileMainSnippet("8 && false;"); 39 let lhs = new VReg(); 40 let preLabel = new Label(); 41 let postLabel = new Label(); 42 43 let expected = [ 44 new Ldai(new Imm(8)), 45 new Sta(lhs), 46 new Istrue(), 47 new Jeqz(preLabel), 48 new Lda(new VReg()), 49 new Jmp(postLabel), 50 preLabel, 51 new Lda(lhs), 52 postLabel, 53 new Returnundefined() 54 ] 55 56 expect(checkInstructions(insns, expected)).to.be.true; 57 }); 58 59 it("barBar", function () { 60 let insns = compileMainSnippet("8 || false;"); 61 let lhs = new VReg(); 62 let preLabel = new Label(); 63 let postLabel = new Label(); 64 let expected = [ 65 new Ldai(new Imm(8)), 66 new Sta(lhs), 67 new Isfalse(), 68 new Jeqz(preLabel), 69 new Lda(new VReg()), 70 new Jmp(postLabel), 71 preLabel, 72 new Lda(lhs), 73 postLabel, 74 new Returnundefined() 75 ] 76 77 expect(checkInstructions(insns, expected)).to.be.true; 78 }); 79}); 80