How to use addHex method in wpt

Best JavaScript code snippet using wpt

codegen.js

Source:codegen.js Github

copy

Full Screen

...75 falseAddress = addToHeap('false');76 //starts the tree movement77 traverseTree(ast.root, 0);78 //adds a break to the very end for clean eanding79 addHex(breakOp);80 //calls backpatching81 backpatch();82 //if outputing83 if (verbose) {84 //break lines in the log85 logText += "<br />";86 }87 //random banter for outputing code and heap being combined88 codeLog("Getting the Code...");89 codeLog("Taking the Heap...");90 codeLog("Putting them together with <span class=\"code\">00</span>s...");91 //outs the memory 92 codeLog("Memory <span class=\"line\">" + (code.length + heap.length) + "</span>/<span class=\"line\">" + MAX + "</span>...");93 //if the heap and code arent a full 25694 for (var i = code.length; i < MAX - heap.length; i++) {95 //adds empty space96 code.push("00");97 }98 //loops through heap99 for (var i = 0; i < heap.length; i++) {100 //adds the heap to the code101 code.push(heap[i])102 }103 //if the code is longer then 256104 if (code.length > MAX) {105 //increases errors106 cErrors++;107 //outputs error108 codeLog("<span class=\"error\">ERROR!</span> Not enough memory <span class=\"codegen-title\">" + code.length + "</span>/<span class=\"codegen-title\">" + MAX + "</span>...", true);109 }110 //joins the code in a nice readable string111 codeString2 = code.join(' ');112 //calls the pretty code function113 codeToString();114}115//Backpatching!116function backpatch() {117 //if outputing118 if (verbose) {119 //break lines in the log120 logText += "<br />";121 }122 //Begin123 codeLog("Beginning Backpatching...");124 //gets new address125 var addressOne = numtoHex(code.length + staticData.length());126 //Outputs the change to the new address127 codeLog("Replacing [ <span class=\"code\">" + TEMP_ADDRESS_ONE + "</span> ] with [ <span class=\"code\">" + addressOne + "</span> ]...");128 //checks for the first temp value129 if (code.includes(TEMP_ADDRESS_ONE)) {130 for (var i = 0; i < code.length; i++) {131 //if this element is temp 1132 if (code[i] == TEMP_ADDRESS_ONE) {133 //replace the first temp134 code[i] = addressOne;135 }136 }137 }138 //gets new address139 var addressTwo = numtoHex(code.length + staticData.length() + 1);140 //Outputs the change to the new address141 codeLog("Replacing [ <span class=\"code\">" + TEMP_ADDRESS_TWO + "</span> ] with [ <span class=\"code\">" + addressTwo + "</span> ]...");142 //checks for the second temp value143 if (code.includes(TEMP_ADDRESS_TWO)) {144 //Loops for it145 for (var i = 0; i < code.length; i++) {146 //if this element is temp 2147 if (code[i] == TEMP_ADDRESS_TWO) {148 //replace the second temp149 code[i] = addressTwo;150 }151 }152 }153 //loops through variables and defines there new locations154 for (var key in staticData.variables) {155 //gets new address location156 var newAddress = numtoHex(code.length + staticData.variables[key].offset);157 //gets the temp address location158 var tempAddress = staticData.variables[key].address;159 //Outputs the change to the new address160 codeLog("Replacing [ <span class=\"code\">" + tempAddress + "</span> ] with [ <span class=\"code\">" + newAddress + "</span> ]...");161 //Loops for it162 for (var i = 0; i < code.length; i++) {163 //if this element is tempAddress 164 if (code[i] == tempAddress) {165 //replace the second temp166 code[i] = newAddress;167 }168 }169 }170 //loops through Jumps and defines there correct locations171 for (var key in jumpTable.variables) {172 //start of the block173 var start = jumpTable.variables[key].startingAddress;174 //end of the block175 var end = jumpTable.variables[key].endingAddress;176 //gets the distance to move177 var move = numtoHex(end - start - 2);178 //Outputs the change to the new address179 codeLog("Replacing [ <span class=\"code\">" + key + "</span> ] with [ <span class=\"code\">" + move + "</span> ]...");180 //Loops for it181 for (var i = 0; i < code.length; i++) {182 //if this element is the jump key 183 if (code[i] == key) {184 //replace the jump185 code[i] = move;186 }187 }188 }189 //Outputs the change to the new address190 codeLog("Replacing [ <span class=\"code\">XX</span> ] with [ <span class=\"code\">00</span> ]...");191 //checks for the XX192 if (code.includes("XX")) {193 //Loops for it194 for (var i = 0; i < code.length; i++) {195 //if this element is temp 2196 if (code[i] == "XX") {197 //replace the second temp198 code[i] = "00";199 }200 }201 }202 //end203 codeLog("Backpatching Done...");204}205function codeToString() {206 var heap = false;207 for (var i = 0; i < code.length; i++) {208 var current = code[i];209 if (current == "00" && (code[i+1] == "00" || heap)) {210 heap = true;211 codeString += "<b class=\"text-muted\">"+current+"</b>";212 } else if (heap) {213 codeString += "<b class=\"text-success\">"+current+"</b>";214 } else if (current == "A9" || current == "AD" || current == "A2" || current == "A0" || current == "D0") {215 codeString += "<b class=\"text-danger\">"+current+"</b>";216 } else if (current == "8D" || current == "6D" || current == "AE" || current == "AC" || current == "EC" || current == "EE") {217 codeString += "<b class=\"text-warning\">"+current+"</b>";218 } else if (current == "EA") {219 codeString += "<b class=\"lime\">"+current+"</b>";220 } else if (current == "FF") {221 codeString += "<b class=\"text-dark\">"+current+"</b>";222 } else {223 codeString += "<b class=\"text-info\">"+current+"</b>";224 }225 codeString += " ";226 }227 codeString.trim();228}229/* ----------------------------------------- Hex Related Functions ----------------------------------------- */230// Adds padding231function pad(word, size, padder) {232 var paddedWord = "" + word;233 while (paddedWord.length < size) {234 paddedWord = padder + paddedWord;235 }236 return paddedWord;237}238function toHexidecimal(str) {239 //Converts a string to hex240 return str.toString(16);241}242function addHex(val) {243 //adds the hex to the Array244 code.push(val);245 //output to log246 codeLog("Pushing [ <span class=\"code\">" + val + "</span> ] byte to memory...");247}248function toHex(val) {249 //turns chars into HEX250 return pad(toHexidecimal(val.charCodeAt(0)), 2, '0').toUpperCase();251}252function numtoHex(val) {253 //turns ints into HEX254 return pad(toHexidecimal(parseInt(val)), 2, '0').toUpperCase();255}256/* --------------------------------------- End Hex Related Functions --------------------------------------- */257function getTypeFromSThelper(id, scope, start = st.cur) {258 //if the scopes mataches return 259 if (scope == start.scope) {260 return start;261 }262 //If lower level, search there263 if (start.children.length != 0) {264 //calls a search in the higher levels265 for (var i = 0; i < start.children.length; i++) {266 var t = getTypeFromSThelper(id, scope, start.children[i]);267 if (t != undefined) {268 return t;269 }270 }271 }272}273function getTypeFromST(id, scope, start = getTypeFromSThelper(id, scope)) {274 //if the current level has symbols275 for (var i = 0; i < start.symbols.length; i++) {276 //when the correct ID is found277 if (id == start.symbols[i].getKey() && scope == start.symbols[i].scope) {278 //returns the type279 return start.symbols[i].type;280 } else if (id == start.symbols[i].getKey() && scope >= start.symbols[i].scope) {281 //returns the type282 return start.symbols[i].type;283 }284 }285 //If higher level, search there286 if (start.parent != undefined || start.parent != null) {287 return getTypeFromST(id, scope, start.parent);288 }289}290//Boolean Logic291function booleanLogic(pos) {292 //temp values293 var e1, e2;294 //children elements295 var elementOne = pos.children[0];296 var elementTwo = pos.children[1];297 //if Bool298 if (elementOne.type == "BOOL") {299 //get which300 e1 = "" + elementOne.name;301 //if string then true302 } else if (elementOne.type == "CHARLIST") {303 //if the string has value304 if (elementOne.name.length > 0) {305 //sets true306 e1 = "true";307 //otherwise308 } else {309 //sets false310 e1 = "false";311 }312 //if ID313 } else if (elementOne.type == "ID") {314 //gets the type315 var varType = getTypeFromST(elementOne.name, elementOne.scope);316 //if string317 if (varType == "string") {318 //sets true319 e1 = "true";320 //if not321 } else {322 //sets the name323 e1 = "" + elementOne.name;324 }325 //if digit326 } else if (elementOne.type == "DIGIT") {327 //sets the digit328 e1 = "" + elementOne.name;329 //if not330 } else {331 //continue down332 e1 = "" + booleanLogic(elementOne);333 }334 //if Bool335 if (elementTwo.type == "BOOL") {336 //get which337 e2 = "" + elementTwo.name;338 //if string339 } else if (elementTwo.type == "CHARLIST") {340 //if the string has value341 if (elementTwo.name.length > 0) {342 //sets true343 e2 = "true";344 //otherwise345 } else {346 //sets false347 e2 = "false";348 }349 //if ID350 } else if (elementTwo.type == "ID") {351 //gets the type 352 var varType = getTypeFromST(elementTwo.name, elementTwo.scope);353 //if string354 if (varType == "string") {355 //sets true356 e2 = "true";357 //if not358 } else {359 //sets the name360 e2 = "" + elementTwo.name;361 }362 //if digit363 } else if (elementTwo.type == "DIGIT") {364 //sets the digit365 e2 = "" + elementTwo.name;366 //if not367 } else {368 //continue down369 e2 = "" + booleanLogic(elementTwo);370 }371 //If element one is a digit372 if (elementOne.type == "DIGIT" && elementTwo.type != "DIGIT") {373 //if e1 is more then 0374 if (e1 > 0) {375 //true376 e1 = "true";377 //otherwise378 } else {379 //false380 e1 = "false";381 }382 //If element two is a digit383 } else if (elementOne.type != "DIGIT" && elementTwo.type == "DIGIT") {384 //if e2 is more then 0385 if (e2 > 0) {386 //true387 e2 = "true";388 //otherwise389 } else {390 //false391 e2 = "false";392 }393 }394 //If this one is an equals395 if (pos.type == "Equality") {396 //then this must be397 if (e1 == e2) {398 //so true399 return true;400 //otherwise401 } else {402 //false403 return false;404 }405 //if not an equal statement406 } else if (pos.type == "Inequality") {407 //then this must be408 if (e1 != e2) {409 //true410 return true;411 //otherwise412 } else {413 //false414 return false;415 }416 } else {417 /* Duplicated418 //not supported419 comErrors++;420 //text about issue421 comErrorsStr += "<div class=\"error\">Addition in Equality and Inequality statements is not supported in this Compiler.</div>";422 comErrorsStr += "<div class=\"error\">The issue was found on line <span class=\"line\">" + pos.line + "</span>...</div><br />";423 */424 }425}426function traverseTree(pos, depth) {427 //moves through the tree looking at the level428 //root429 if (pos.name == "Root")430 cRoot(pos.children, depth);431 //program432 else if (pos.name.includes("Program"))433 cProgram(pos.children, depth);434 //block435 else if (pos.name == "Block")436 cBlock(pos, depth);437 //Variable Declairation438 else if (pos.name == "VarDecl")439 cVarDecl(pos, depth);440 //Assignment Statments441 else if (pos.name == "AssignmentStatement")442 cAssign(pos, depth);443 //Print Statements444 else if (pos.name == "Print")445 cPrint(pos, depth);446 //If Statements447 else if (pos.name == "IfStatement")448 cIf(pos, depth);449 //While Statements450 else if (pos.name == "WhileStatement")451 cWhile(pos, depth);452 //Equality453 else if (pos.name == "Equality")454 cEquality(pos, depth);455 //Inequality456 else if (pos.name == "Inequality")457 cInequality(pos, depth);458 //True or False variables459 else if (pos.name == "true" || pos.name == "false")460 cBool(pos, depth);461 //String variables462 else if (pos.type == "CHARLIST")463 cString(pos, depth);464 //ID variables465 else if ("abcdefghijklmnopqrstuvwxyz".includes(pos.name))466 cID(pos, depth);467 //Integer variables468 else if ("0123456789".includes(pos.name))469 cDigit(pos, depth);470 //Addition471 else if (pos.name == "Addition") {472 return cAddition(pos, depth);473 } else {474 //loops through trees kids and moves down incase one is missed475 for (var i = 0; i < pos.children.length; i++) {476 //moves deeper on each one477 traverseTree(pos.children[i], depth);478 }479 }480}481function cRoot(pos, depth) {482 //loops through the level483 for (var i = 0; i < pos.length; i++) {484 //moves deeper on each one485 traverseTree(pos[i], depth);486 }487}488function cProgram(pos, depth) {489 //loops through the level490 for (var i = 0; i < pos.length; i++) {491 //moves deeper on each one492 traverseTree(pos[i], depth);493 }494}495function cBlock(pos, depth) {496 //Generating497 codeLog("Generating [ <span class=\"code-words\">Block</span> ] on line <span class=\"line\">" + pos.line + "</span>..");498 //enter scope499 codeLog("Entering Scope [ <span class=\"code\">" + pos.scope + "</span> ]..");500 //output501 //loops through the level502 for (var i = 0; i < pos.children.length; i++) {503 //moves deeper on each one504 traverseTree(pos.children[i], depth + 1);505 }506 //Out of scope507 codeLog("Leaving Scope [ <span class=\"code\">" + pos.scope + "</span> ]..");508 //Finished509 codeLog("Finished [ <span class=\"code-words\">Block</span> ] on line <span class=\"line\">" + pos.line + "</span>..");510}511function cAddition(pos, depth) {512 //Generating513 codeLog("Generating [ <span class=\"code-words\">Addition</span> ] on line <span class=\"line\">" + pos.line + "</span>..");514 //move through the tree515 traverseTree(pos.children[1], depth);516 //stores into memory517 addHex(storeAccInMemo);518 addHex(TEMP_ADDRESS_ONE);519 addHex('XX');520 //loads constant521 addHex(loadAccWithConst);522 addHex(numtoHex(pos.children[0].name));523 //adds to the accum from memory524 addHex(addWithCarry);525 addHex(TEMP_ADDRESS_ONE);526 addHex('XX');527 //Finished528 codeLog("Finished [ <span class=\"code-words\">Addition</span> ] on line <span class=\"line\">" + pos.line + "</span>..");529}530function cVarDecl(pos, depth) {531 //Generating532 codeLog("Generating [ <span class=\"code-words\">Declaration ] on line <span class=\"line\">" + pos.line + "</span>..");533 //loads 00534 addHex(loadAccWithConst);535 addHex('00');536 //gets temp address537 var address = staticData.add(pos.children[0], pos.scope);538 //stores to memory539 addHex(storeAccInMemo);540 addHex(address);541 addHex('XX');542 //Finished543 codeLog("Finished [ <span class=\"code-words\">Declaration</span> ] on line <span class=\"line\">" + pos.line + "</span>..");544}545function cAssign(pos, depth) {546 //Generating547 codeLog("Generating [ <span class=\"code-words\">Assignment</span> ] on line <span class=\"line\">" + pos.line + "</span>..");548 //move through the tree549 traverseTree(pos.children[1], depth);550 //gets temp address551 var address = staticData.get(pos.children[0], pos.scope);552 //stores to memory553 addHex(storeAccInMemo);554 addHex(address);555 addHex('XX');556 //Finished557 codeLog("Finished [ <span class=\"code-words\">Assignment</span> ] on line <span class=\"line\">" + pos.line + "</span>..");558}559function cPrint(pos, depth) {560 //Generating561 codeLog("Generating [ <span class=\"code-words\">Print</span> ] on line <span class=\"line\">" + pos.line + "</span>..");562 //id values563 if (pos.children[0].type == "ID") {564 //gets the temp address565 var address = staticData.get(pos.children[0], depth);566 //gets the id type567 var varType = getTypeFromST(pos.children[0].name, pos.children[0].scope);568 //ID ints569 if (varType == "int") {570 //int print op codes571 //loads from memory572 addHex(loadYFromMemo);573 addHex(address);574 addHex("XX");575 //loads the print int op576 addHex(loadXWithConst);577 addHex(printInt);578 //break579 addHex(systemCall);580 //ID strings581 } else if (varType == "string") {582 //string print op codes583 //loads from memory584 addHex(loadYFromMemo);585 addHex(address);586 addHex("XX");587 //loads the print string op588 addHex(loadXWithConst);589 addHex(PrintStr);590 //break591 addHex(systemCall);592 //ID booleans593 } else if (varType == "boolean") {594 //bool print op codes595 //loads x with 1596 addHex(loadXWithConst);597 addHex(printInt);598 //loads from memory599 addHex(compareMemoToX);600 addHex(address);601 addHex("XX");602 //loads y with false603 addHex(loadYWithConst);604 addHex(falseAddress);605 //jump 2606 addHex(branchNBytes);607 addHex("02");608 //load y with true609 addHex(loadYWithConst);610 addHex(trueAddress);611 //loads the print string op612 addHex(loadXWithConst);613 addHex(PrintStr);614 //break615 addHex(systemCall);616 }617 //raw strings618 } else if (pos.children[0].type == "CHARLIST") {619 //adds the string to heap620 var address = addToHeap(pos.children[0].name);621 //string print op codes622 //loads memory623 addHex(loadAccFromMemo);624 addHex(address);625 addHex("XX");626 //loads the y627 addHex(loadYWithConst);628 addHex(address);629 //store in temp630 addHex(storeAccInMemo);631 addHex(TEMP_ADDRESS_ONE);632 addHex('XX');633 //loads the print str op code634 addHex(loadXWithConst);635 addHex(PrintStr);636 //break637 addHex(systemCall);638 //booleans and Ints639 } else {640 //processes booleans and Ints641 traverseTree(pos.children[0], depth);642 //raw boolean print codes643 if (pos.children[0].type == "BOOL" || pos.children[0].type == "Equality" || pos.children[0].type == "Inequality") {644 //boolean print op codes645 //loads 1 into x646 addHex(loadXWithConst);647 addHex(printInt);648 //loads the false location into y649 addHex(loadYWithConst);650 addHex(falseAddress);651 //jumps if 652 addHex(branchNBytes);653 addHex("02");654 //loads the true location into y655 addHex(loadYWithConst);656 addHex(trueAddress);657 //loads the print str op into x658 addHex(loadXWithConst);659 addHex(PrintStr);660 //Break661 addHex(systemCall);662 //raw int print codes663 } else {664 //int print op codes665 //loads print int code666 addHex(loadXWithConst);667 addHex(printInt);668 //stores to the temp address669 addHex(storeAccInMemo);670 addHex(TEMP_ADDRESS_ONE);671 addHex('XX');672 //loads the temp in y673 addHex(loadYFromMemo);674 addHex(TEMP_ADDRESS_ONE);675 addHex('XX');676 //Break677 addHex(systemCall);678 }679 }680 //Finished681 codeLog("Finished [ <span class=\"code-words\">Print</span> ] on line <span class=\"line\">" + pos.line + "</span>..");682}683function cWhile(pos, depth) {684 //Generating685 codeLog("Generating [ <span class=\"code-words\">While</span> ] on line <span class=\"line\">" + pos.line + "</span>..");686 //gets the starting address687 var start = code.length;688 //handles the conitional689 traverseTree(pos.children[0], depth);690 //defines a jump variable691 var tempAddress = jumpTable.add(code.length);692 codeLog("Generating [ <span class=\"code\">" + tempAddress + "</span> ] on line <span class=\"line\">" + pos.line + "</span>..");693 //jump to jump variable694 addHex(branchNBytes);695 addHex(tempAddress);696 //handles the block697 traverseTree(pos.children[1], depth);698 addHex(loadAccWithConst);699 addHex("00");700 addHex(storeAccInMemo);701 addHex(TEMP_ADDRESS_ONE);702 addHex("XX");703 addHex(loadXWithConst);704 addHex("01");705 addHex(compareMemoToX);706 addHex(TEMP_ADDRESS_ONE);707 addHex("XX");708 var jump = numtoHex(256 - code.length + start - 2);709 addHex(branchNBytes);710 addHex(jump);711 jumpTable.get(tempAddress).endingAddress = code.length;712 //Finished713 codeLog("Finished [ <span class=\"code-words\">While</span> ] on line <span class=\"line\">" + pos.line + "</span>..");714}715function cIf(pos, depth) {716 //Generating717 codeLog("Generating [ <span class=\"code-words\">If</span> ] on line <span class=\"line\">" + pos.line + "</span>..");718 //processes the conditional719 traverseTree(pos.children[0], depth);720 //makes a new jump element721 var address = jumpTable.add(code.length);722 //jumps to temp723 addHex(branchNBytes);724 addHex(address);725 //processes the block statement726 traverseTree(pos.children[1], depth);727 //sets the end of the up for later use728 jumpTable.get(address).endingAddress = code.length;729 //Finished730 codeLog("Finished [ <span class=\"code-words\">If</span> ] on line <span class=\"line\">" + pos.line + "</span>..");731}732function cInequality(pos, depth) {733 //rewrites for modification later734 pos.type = "Equality";735 //Generating736 codeLog("Generating [ <span class=\"code-words\">Inequality</span> ] on line <span class=\"line\">" + pos.line + "</span>..");737 //runs equality to handle most of the work738 cEquality(pos, depth);739 //negate the equals..740 //loads 0741 addHex(loadAccWithConst);742 addHex("00");743 //jumps 2744 addHex(branchNBytes);745 addHex("02");746 //loads 1747 addHex(loadAccWithConst);748 addHex("01");749 //loads 0 into x750 addHex(loadXWithConst);751 addHex("00");752 //stores in memory753 addHex(storeAccInMemo);754 addHex(TEMP_ADDRESS_ONE);755 addHex("XX");756 //compares757 addHex(compareMemoToX);758 addHex(TEMP_ADDRESS_ONE);759 addHex("XX");760 //Finished761 codeLog("Finished [ <span class=\"code-words\">Inequality</span> ] on line <span class=\"line\">" + pos.line + "</span>..");762}763function cEquality(pos, depth) {764 //Generating765 codeLog("Generating [ <span class=\"code-words\">Equality</span> ] on line <span class=\"line\">" + pos.line + "</span>..");766 //if theres a nested bool types767 if (pos.children[0].name == "Equality" || pos.children[0].name == "Inequality" || pos.children[1].name == "Equality" || pos.children[1].name == "Inequality") {768 //Let Boolean Logic handle that one little 6502 assembler769 if (booleanLogic(pos)) {770 //loads true771 //loads 1772 addHex(loadAccWithConst);773 addHex("01");774 //loads 1 into x775 addHex(loadXWithConst);776 addHex("01");777 } else {778 //loads false779 //loads 1780 addHex(loadAccWithConst);781 addHex("01");782 //loads 0 into x783 addHex(loadXWithConst);784 addHex("00");785 }786 //stores in memory787 addHex(storeAccInMemo);788 addHex(TEMP_ADDRESS_ONE);789 addHex("XX");790 //compares to memory791 addHex(compareMemoToX);792 addHex(TEMP_ADDRESS_ONE);793 addHex("XX");794 //if comparing strings795 } else if (pos.children[0].type == "CHARLIST" && pos.children[1].type == "CHARLIST") {796 //compares strings797 if (pos.children[0].name == pos.children[1].name) {798 //loads true799 //loads 1800 addHex(loadAccWithConst);801 addHex("01");802 //loads 1 into x803 addHex(loadXWithConst);804 addHex("01");805 } else {806 //loads false807 //loads 1808 addHex(loadAccWithConst);809 addHex("01");810 //loads 0 into x811 addHex(loadXWithConst);812 addHex("00");813 }814 //stores in memory815 addHex(storeAccInMemo);816 addHex(TEMP_ADDRESS_ONE);817 addHex("XX");818 //compares to memory819 addHex(compareMemoToX);820 addHex(TEMP_ADDRESS_ONE);821 addHex("XX");822 //if addition below compiler wont support it823 } else if (pos.children[0].type == "Addition" || pos.children[1].type == "Addition") {824 /* Duplicated825 //not supported826 comErrors++;827 //text about issue828 comErrorsStr += "<div class=\"error\">Addition in Equality and Inequality statements is not supported in this Compiler.</div>";829 comErrorsStr += "<div class=\"error\">The issue was found on line <span class=\"line\">" + pos.line + "</span>...</div><br />";830 */831 //compares the rest832 } else {833 //gets first loaded834 traverseTree(pos.children[0], depth);835 //stores in memory836 addHex(storeAccInMemo);837 addHex(TEMP_ADDRESS_TWO);838 addHex("XX");839 //gets second loaded840 traverseTree(pos.children[1], depth);841 //stores in memory842 addHex(storeAccInMemo);843 addHex(TEMP_ADDRESS_ONE);844 addHex("XX");845 //loads from memory846 addHex(loadXFromMemo);847 addHex(TEMP_ADDRESS_TWO);848 addHex("XX");849 //compare to memory850 addHex(compareMemoToX);851 addHex(TEMP_ADDRESS_ONE);852 addHex("XX");853 //loads false854 addHex(loadAccWithConst);855 addHex("00");856 //jump 2 if true857 addHex(branchNBytes);858 addHex("02");859 //true860 addHex(loadAccWithConst);861 addHex("01");862 }863 //Finished864 codeLog("Finished [ <span class=\"code-words\">Equality</span> ] on line <span class=\"line\">" + pos.line + "</span>..");865}866function cID(pos, depth) {867 //Generating868 codeLog("Generating [ <span class=\"code-words\">ID</span> ] on line <span class=\"line\">" + pos.line + "</span>..");869 //gets address of ID870 var address = staticData.get(pos, pos.scope);871 //loads address872 addHex(loadAccFromMemo);873 addHex(address);874 addHex("XX");875 //Finished876 codeLog("Finished [ <span class=\"code-words\">ID</span> ] on line <span class=\"line\">" + pos.line + "</span>..");877}878function cDigit(pos, depth) {879 //Generating880 codeLog("Generating [ <span class=\"code-words\">Digit</span> ] on line <span class=\"line\">" + pos.line + "</span>..");881 //loads digits 882 addHex(loadAccWithConst);883 addHex(numtoHex(pos.name));884 //Finished885 codeLog("Finished [ <span class=\"code-words\">Digit</span> ] on line <span class=\"line\">" + pos.line + "</span>..");886}887function cBool(pos, depth) {888 //Generating889 codeLog("Generating [ <span class=\"code-words\">Bool</span> ] on line <span class=\"line\">" + pos.line + "</span>..");890 //if true891 if (pos.name === 'true') {892 //load true893 addHex(loadAccWithConst);894 addHex(numtoHex("1"));895 //otherwise896 } else {897 //load false898 addHex(loadAccWithConst);899 addHex(numtoHex("0"));900 }901 //store into memory902 addHex(storeAccInMemo);903 addHex(TEMP_ADDRESS_ONE);904 addHex('XX');905 //loads X with 1906 addHex(loadXWithConst);907 addHex(printInt);908 //compares to previous memory909 addHex(compareMemoToX);910 addHex(TEMP_ADDRESS_ONE);911 addHex('XX');912 //Finished913 codeLog("Finished [ <span class=\"code-words\">Bool</span> ] on line <span class=\"line\">" + pos.line + "</span>..");914}915function cString(pos, depth) {916 //Generating917 codeLog("Generating [ <span class=\"code-words\">String</span> ] on line <span class=\"line\">" + pos.line + "</span>..");918 //adds the string to the heap919 var value = addToHeap(pos.name, pos.line);920 //loads the location of the string921 addHex(loadAccWithConst);922 addHex(value);923 //Finished924 codeLog("Finished [ <span class=\"code-words\">String</span> ] on line <span class=\"line\">" + pos.line + "</span>..");925}926function addToHeap(str, line = 0) {927 //checks the table for already used strings928 if (returningHeap = stringTable.get(str)) {929 //outputs it was found930 codeLog("Found string [ <span class=\"code\">" + str + "</span> ] in the heap at address " + returningHeap + "...");931 //returns the address932 return returningHeap;933 }934 //if no string..935 if (str.length == 0) {936 //outputs it was found...

Full Screen

Full Screen

CodeGeneration.js

Source:CodeGeneration.js Github

copy

Full Screen

...205function codeGenAddition(position, depth){206 outputMessage("Starting Addition");207 traverseTree(position.children[1], depth);208 //Store temp address209 addHex(storeTheAccumulatorInMemory);210 addHex(temporaryAddressOne);211 addHex("XX");212 //Load with constant213 addHex(loadTheAccumulatorWithConstant);214 addHex(numToHex(position.children[0].name));215 //Add with new address216 addHex(addWithCarry);217 addHex(temporaryAddressOne);218 addHex("XX");219}220function codeGenVarDecl(position, depth){221 outputMessage("Variable Declaration");222 //Load with constant223 addHex(loadTheAccumulatorWithConstant);224 addHex("00");225 //Add temp address226 var temporaryAddress = staticData.add(position.children[0], position.scope);227 //Store temp address in Memory228 addHex(storeTheAccumulatorInMemory);229 addHex(temporaryAddress);230 addHex("XX");231 outputMessage("Declaration Done")232}233function codeGenAssignment(position, depth){234 outputMessage("Assignment Statement")235 //Traverse the child236 traverseTree(position.children[1], depth);237 //Get the temporary address 238 var temporaryAddress = staticData.get(position.children[0], position.scope);239 //Store in memory240 addHex(storeTheAccumulatorInMemory);241 addHex(temporaryAddress);242 addHex("XX");243 outputMessage("Assignment Done");244}245function getTypeFromSThelper(id, scope, start = st.cur) {246 //if the scopes mataches return 247 if (scope == start.scope) {248 return start;249 }250 //If lower level, search there251 if (start.children.length != 0) {252 //calls a search in the higher levels253 for (var i = 0; i < start.children.length; i++) {254 var t = getTypeFromSThelper(id, scope, start.children[i]);255 if (t != undefined) {256 return t;257 }258 }259 }260}261function getTypeFromST(id, scope, start = getTypeFromSThelper(id, scope)) {262 //if the current level has symbols263 for (var i = 0; i < start.symbols.length; i++) {264 //when the correct ID is found265 if (id == start.symbols[i].getKind() && scope == start.symbols[i].scope) {266 //returns the type267 return start.symbols[i].type;268 } else if (id == start.symbols[i].getKind() && scope >= start.symbols[i].scope) {269 //returns the type270 return start.symbols[i].type;271 }272 }273 //If higher level, search there274 if (start.parent != undefined || start.parent != null) {275 return getTypeFromST(id, scope, start.parent);276 }277}278function codeGenPrint(position, depth) {279 outputMessage("Starting Print");280 //id values281 if (position.children[0].type == "id") {282 //gets the temp address283 var address = staticData.get(position.children[0], depth);284 //gets the id type285 var varType = getTypeFromST(position.children[0].name, position.children[0].scope);286 //ID ints287 if (varType == "int") {288 //int print op codes289 //loads from memory290 addHex(loadTheYRegisterFromMemory);291 addHex(address);292 addHex("XX");293 //loads the print int op294 addHex(loadTheXRegisterWithConstant);295 addHex(printIntegerInYRegister);296 //break297 addHex(systemCall);298 //ID strings299 } else if (varType == "string") {300 //string print op codes301 //loads from memory302 addHex(loadTheYRegisterFromMemory);303 addHex(address);304 addHex("XX");305 //loads the print string op306 addHex(loadTheXRegisterWithConstant);307 addHex(printStringInYAddress);308 //break309 addHex(systemCall);310 //ID booleans311 } else if (varType == "boolean") {312 //bool print op codes313 //loads x with 1314 addHex(loadTheXRegisterWithConstant);315 addHex(printIntegerInYRegister);316 //loads from memory317 addHex(compareByteInMemoryToXRegister);318 addHex(address);319 addHex("XX");320 //loads y with false321 addHex(loadTheYRegisterWithConstant);322 addHex(falsePlaceholder);323 //jump 2324 addHex(branchNBytesIfZFlagIsZero);325 addHex("02");326 //load y with true327 addHex(loadTheYRegisterWithConstant);328 addHex(truePlaceholder);329 //loads the print string op330 addHex(loadTheXRegisterWithConstant);331 addHex(printStringInYAddress);332 //break333 addHex(systemCall);334 }335 //raw strings336 } else if (position.children[0].type == "Charlist") {337 //adds the string to heap338 var address = addToHeap(position.children[0].name);339 //string print op codes340 //loads memory341 addHex(loadTheAccumlatorFromMemory);342 addHex(address);343 addHex("XX");344 //loads the y345 addHex(loadTheYRegisterWithConstant);346 addHex(address);347 //store in temp348 addHex(storeTheAccumulatorInMemory);349 addHex(temporaryAddressOne);350 addHex('XX');351 //loads the print str op code352 addHex(loadTheXRegisterWithConstant);353 addHex(printStringInYAddress);354 //break355 addHex(systemCall);356 //booleans and Ints357 } else {358 //processes booleans and Ints359 traverseTree(position.children[0], depth);360 //raw boolean print codes361 if (position.children[0].type == "boolean" || position.children[0].type == "Equality" || position.children[0].type == "Not_Equal") {362 //boolean print op codes363 //loads 1 into x364 addHex(loadTheXRegisterWithConstant);365 addHex(printIntegerInYRegister);366 //loads the false location into y367 addHex(loadTheYRegisterWithConstant);368 addHex(falsePlaceholder);369 //jumps if 370 addHex(branchNBytesIfZFlagIsZero);371 addHex("02");372 //loads the true location into y373 addHex(loadTheYRegisterWithConstant);374 addHex(truePlaceholder);375 //loads the print str op into x376 addHex(loadTheXRegisterWithConstant);377 addHex(printStringInYAddress);378 //Break379 addHex(systemCall);380 //raw int print codes381 } else {382 //int print op codes383 //loads print int code384 addHex(loadTheXRegisterWithConstant);385 addHex(printIntegerInYRegister);386 //stores to the temp address387 addHex(storeTheAccumulatorInMemory);388 addHex(temporaryAddressOne);389 addHex('XX');390 //loads the temp in y391 addHex(loadTheYRegisterFromMemory);392 addHex(temporaryAddressOne);393 addHex('XX');394 //Break395 addHex(systemCall);396 }397 }398 outputMessage("Ending Print");399}400function codeGenWhile(position, depth){401 outputMessage("Starting While");402 //Get address403 var init = generatedCode.length;404 //Traverse child405 traverseTree(position.children[0], depth);406 //Get temp address407 var temporaryAddress = jumpTable.add(generatedCode.length);408 //Add where to jump409 addHex(branchNBytesIfZFlagIsZero);410 addHex(temporaryAddress);411 //Traverse other child412 traverseTree(position.children[1], depth);413 //Load Acummulator414 addHex(loadTheAccumulatorWithConstant);415 addHex("00");416 //Store and place tempAddressOne417 addHex(storeTheAccumulatorInMemory);418 addHex(temporaryAddressOne);419 addHex("XX");420 //LoadX with 1421 addHex(loadTheXRegisterWithConstant);422 addHex("01");423 //Compare the two424 addHex(compareByteInMemoryToXRegister);425 addHex(temporaryAddressOne);426 addHex("XX");427 //How far do we jump428 var jump = numToHex(256 - generatedCode.length + init - 2);429 addHex(branchNBytesIfZFlagIsZero);430 addHex(jump);431 //Add to jump Table432 jumpTable.get(temporaryAddress).endingAddress = generatedCode.length;433 outputMessage("Ending While");434}435function codeGenIf(position, depth){436 outputMessage("Starting If");437 //Traverse the tree438 traverseTree(position.children[0], depth);439 //Get the temp address440 var temporaryAddress = jumpTable.add(generatedCode.length);441 //Branch on the address442 addHex(branchNBytesIfZFlagIsZero);443 addHex(temporaryAddress);444 //Traverse other child445 traverseTree(position.children[1], depth);446 //Add to jumpTable447 jumpTable.get(temporaryAddress).endingAddress = generatedCode.length;448 outputMessage("Ending If");449}450function codeGenNotEquals(position, depth){451 outputMessage("Starting NotEquals");452 position.type = "Equality";453 codeGenIsEquals(position, depth);454 //Load 0455 addHex(loadTheAccumulatorWithConstant);456 addHex("00");457 //Add branch458 addHex(branchNBytesIfZFlagIsZero);459 addHex("02");460 //Load 1461 addHex(loadTheAccumulatorWithConstant);462 addHex("01");463 //Load X464 addHex(loadTheXRegisterWithConstant);465 addHex("00");466 //Store it467 addHex(storeTheAccumulatorInMemory);468 addHex(temporaryAddressOne);469 addHex("XX");470 //Compare471 addHex(compareByteInMemoryToXRegister);472 addHex(temporaryAddressOne);473 addHex("XX");474 outputMessage("Ending NotEquals");475}476function codeGenIsEquals(position, depth){477 outputMessage("Starting IsEquals");478 if(position.children[0].name == "Equality" || position.children[0].name == "Not_Equal" ||479 position.children[1].name == "Equality" || position.children[1].name == "Not_Equal"){480 addHex(storeTheAccumulatorInMemory);481 addHex(temporaryAddressOne);482 addHex("XX");483 addHex(compareByteInMemoryToXRegister);484 addHex(temporaryAddressOne);485 addHex("XX");486 }else if(position.children[0].name == "intop" || position.children[1].name == "intop"){487 numCodeGenErrors++;488 }else if(position.children[0].type == "charlist" || position.children[1].type == "charlist"){489 if(position.children[0].name == position.children[1].name){490 addHex(loadTheAccumulatorWithConstant);491 addHex("01");492 addHex(loadTheXRegisterWithConstant);493 addHex("01");494 }else{495 addHex(loadTheAccumulatorWithConstant);496 addHex("01");497 addHex(loadTheXRegisterWithConstant);498 addHex("00");499 }500 addHex(storeTheAccumulatorInMemory);501 addHex(temporaryAddressOne);502 addHex("XX");503 addHex(compareByteInMemoryToXRegister);504 addHex(temporaryAddressOne);505 addHex("XX");506 }else{507 traverseTree(position.children[0], depth);508 addHex(storeTheAccumulatorInMemory);509 addHex(temporaryAddressTwo);510 addHex("XX");511 traverseTree(position.children[1], depth);512 addHex(storeTheAccumulatorInMemory);513 addHex(temporaryAddressOne);514 addHex("XX");515 addHex(loadTheXRegisterFromMemory);516 addHex(temporaryAddressTwo);517 addHex("XX");518 addHex(compareByteInMemoryToXRegister);519 addHex(temporaryAddressOne);520 addHex("XX");521 addHex(loadTheAccumulatorWithConstant);522 addHex("00");523 addHex(branchNBytesIfZFlagIsZero);524 addHex("02");525 addHex(loadTheAccumulatorWithConstant);526 addHex("01");527 }528 outputMessage("Ending IsEquals");529}530function codeGenId(position, depth){531 outputMessage("Starting Id");532 //Get temp address533 var temporaryAddress = staticData.get(position, position.scope);534 //Load it in accumulator535 addHex(loadTheAccumlatorFromMemory);536 addHex(temporaryAddress);537 addHex("XX");538}539function codeGenDigit(position, depth){540 outputMessage("Starting Digit");541 //Load accumulator542 addHex(loadTheAccumulatorWithConstant);543 //Change to hex value544 addHex(numToHex(position.name));545 outputMessage("Ending Id");546}547function codeGenBoolean(position, depth){548 outputMessage("Starting Boolean");549 //If true load with 1550 //If false load with 0551 if(position.name == "true"){552 addHex(loadTheAccumulatorWithConstant);553 addHex("1");554 }else{555 addHex(loadTheAccumulatorWithConstant);556 addHex("0");557 }558 //Store address in memory559 addHex(storeTheAccumulatorInMemory);560 addHex(temporaryAddressOne);561 addHex("XX");562 //Load X reg563 addHex(loadTheXRegisterWithConstant);564 addHex(printIntegerInYRegister);565 //Compare566 addHex(compareByteInMemoryToXRegister);567 addHex(temporaryAddressOne);568 addHex("XX");569 outputMessage("Ending Boolean");570}571function codeGenString(position, depth){572 outputMessage("Starting String");573 //Add the value to the heap574 var temporaryValue = addToHeap(position.name, position.line);575 //Load accumulator with the value576 addHex(loadTheAccumulatorWithConstant);577 addHex(temporaryValue);578 outputMessage("Ending String");579}580function addHex(val){581 //Add hex code to the code array582 outputMessage("Pushing " + val);583 generatedCode.push(val);584}585function addToHeap(string, line = 0){586 //Check if already seen587 if(returningHeap = strings.get(string)){588 return returningHeap;589 }590 591 //Check if empty592 if(string.length == 0){593 return 'FF';594 }...

Full Screen

Full Screen

compress.js

Source:compress.js Github

copy

Full Screen

...229 var start, end, code, char;230 switch (type) {231 case 0:232 start = reader.readHex(dataSize);233 end = addHex(reader.readHexNumber(dataSize), start);234 subitems.push({start: start, end: end});235 for (var i = 1; i < subitemsCount; i++) {236 start = addHex(reader.readHexNumber(dataSize), incHex(end));237 end = addHex(reader.readHexNumber(dataSize), start);238 subitems.push({start: start, end: end});239 }240 break;241 case 1:242 start = reader.readHex(dataSize);243 end = addHex(reader.readHexNumber(dataSize), start);244 code = reader.readNumber();245 subitems.push({start: start, end: end, code: code});246 for (var i = 1; i < subitemsCount; i++) {247 start = addHex(reader.readHexNumber(dataSize), incHex(end));248 end = addHex(reader.readHexNumber(dataSize), start);249 code = reader.readNumber();250 subitems.push({start: start, end: end, code: code});251 }252 break;253 case 2:254 char = reader.readHex(dataSize);255 code = reader.readNumber();256 subitems.push({char: char, code: code});257 for (var i = 1; i < subitemsCount; i++) {258 char = sequence ? incHex(char) : addHex(reader.readHexNumber(dataSize), incHex(char));259 code = reader.readSigned() + (code + 1);260 subitems.push({char: char, code: code});261 }262 break;263 case 3:264 start = reader.readHex(dataSize);265 end = addHex(reader.readHexNumber(dataSize), start);266 code = reader.readNumber();267 subitems.push({start: start, end: end, code: code});268 for (var i = 1; i < subitemsCount; i++) {269 start = sequence ? incHex(end) : addHex(reader.readHexNumber(dataSize), incHex(end));270 end = addHex(reader.readHexNumber(dataSize), start);271 code = reader.readNumber();272 subitems.push({start: start, end: end, code: code});273 }274 break;275 case 4:276 char = reader.readHex(ucs2DataSize);277 code = reader.readHex(dataSize);278 subitems.push({char: char, code: code});279 for (var i = 1; i < subitemsCount; i++) {280 char = sequence ? incHex(char) : addHex(reader.readHexNumber(ucs2DataSize), incHex(char));281 code = addHex(reader.readHexSigned(dataSize), incHex(code));282 subitems.push({char: char, code: code});283 }284 break;285 case 5:286 start = reader.readHex(ucs2DataSize);287 end = addHex(reader.readHexNumber(ucs2DataSize), start);288 code = reader.readHex(dataSize);289 subitems.push({start: start, end: end, code: code});290 for (var i = 1; i < subitemsCount; i++) {291 start = sequence ? incHex(end) : addHex(reader.readHexNumber(ucs2DataSize), incHex(end));292 end = addHex(reader.readHexNumber(ucs2DataSize), start);293 code = reader.readHex(dataSize);294 subitems.push({start: start, end: end, code: code});295 }296 break;297 default:298 throw new Error('Unknown type: ' + type)299 }300 result.body.push(item);301 }302 return result;303}304function toHexDigit(n) {305 return n.toString(16);306}307function fromHexDigit(s) {308 return parseInt(s, 16);309}310function getHexSize(s) {311 return (s.length >> 1) - 1;312}313function writeByte(b) {314 return toHexDigit((b >> 4) & 15) + toHexDigit(b & 15);315}316function writeNumber(n) {317 if (typeof n === 'string') {318 var s = '', buffer = 0, bufferSize = 0;319 var i = n.length;320 while (i > 0) {321 --i;322 buffer = (fromHexDigit(n[i]) << bufferSize) | buffer;323 bufferSize += 4;324 if (bufferSize >= 7) {325 s = writeByte((buffer & 0x7f) | (s.length > 0 ? 0x80 : 0)) + s;326 buffer >>>= 7;327 bufferSize -= 7;328 }329 }330 if (buffer > 0) {331 s = writeByte((buffer & 0x7f) | (s.length > 0 ? 0x80 : 0)) + s;332 }333 while (s.indexOf('80') === 0) {334 s = s.substr(2);335 }336 return s;337 } else {338 var s = writeByte(n & 0x7F);339 n >>>= 7;340 while (n > 0) {341 s = writeByte((n & 0x7F) | 0x80) + s;342 n >>>= 7;343 }344 return s;345 }346}347function writeSigned(n) {348 if (typeof n === 'string') {349 var t = '';350 var c = fromHexDigit(n[0]);351 var neg = c >= 8;352 c = neg ? (c ^ 15) : c;353 for (var i = 1; i < n.length; i++) {354 var d = fromHexDigit(n[i]);355 c = (c << 4) | (neg ? (d ^ 15) : d);356 t += toHexDigit(c >> 3);357 c = c & 7;358 }359 t += toHexDigit((c << 1) | (neg ? 1 : 0));360 return writeNumber(t);361 }362 return n < 0 ? writeNumber(-2 * n - 1) : writeNumber(2 * n);363}364function writeString(s) {365 var t = writeNumber(s.length);366 for (var i = 0; i < s.length; i++) {367 t += writeNumber(s.charCodeAt(i));368 }369 return t;370}371function addHex(a, b) {372 var c = 0, s = '';373 for (var i = a.length - 1; i >= 0; i--) {374 c += fromHexDigit(a[i]) + fromHexDigit(b[i]);375 if (c >= 16) {376 s = toHexDigit(c - 16) + s;377 c = 1;378 } else {379 s = toHexDigit(c) + s;380 c = 0;381 }382 }383 return s;384}385function subHex(a, b) {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wp = new wptools();3wp.addHex('123');4var wptools = require('wptools');5var wp = new wptools();6wp.addHex('123');7var wptools = require('wptools');8var wp = new wptools();9wp.addHex('123');10var wptools = require('wptools');11var wp = new wptools();12wp.addHex('123');13var wptools = require('wptools');14var wp = new wptools();15wp.addHex('123');16var wptools = require('wptools');17var wp = new wptools();18wp.addHex('123');19var wptools = require('wptools');20var wp = new wptools();21wp.addHex('123');22var wptools = require('wptools');23var wp = new wptools();24wp.addHex('123');25var wptools = require('wptools');26var wp = new wptools();27wp.addHex('123');28var wptools = require('wptools');29var wp = new wptools();30wp.addHex('123');31var wptools = require('wptools');32var wp = new wptools();33wp.addHex('123');34var wptools = require('wptools');35var wp = new wptools();36wp.addHex('123');37var wptools = require('wptools');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('./wptools.js');2var hex = wptools.addHex('00');3console.log(hex);4var addHex = function (hex) {5 return '0x' + hex;6};7exports.addHex = addHex;8function capitalizeFirstLetter(string) {9 return string.charAt(0).toUpperCase() + string.slice(1);10}11function capitalizeFirstLetter(string) {12 return string.charAt(0).toUpperCase() + string.slice(1);13}14function capitalizeFirstLetter(string) {15 return string.charAt(0).toUpperCase() + string.slice(1);16}17function titleCase(str) {18 var splitStr = str.toLowerCase().split(' ');19 for (var i = 0; i < splitStr.length; i++) {20 splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1); 21 }22 return splitStr.join(' '); 23}24function capitalizeFirstLetter(string) {25 return string.charAt(0).toUpperCase() + string.slice(1);26}27function capitalizeFirstLetter(string) {28 return string.charAt(0).toUpperCase() + string.slice(1);29}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt.js');2var hex = wpt.addHex(1, 2);3console.log(hex);4exports.addHex = function (a, b) {5 return a + b;6};7 throw err;8 at Function.Module._resolveFilename (module.js:469:15)9 at Function.Module._load (module.js:417:25)10 at Module.require (module.js:497:17)11 at require (internal/module.js:20:19)12 at Object.<anonymous> (C:\Users\username\Desktop\NodeJS\test.js:1:15)13 at Module._compile (module.js:570:32)14 at Object.Module._extensions..js (module.js:579:10)15 at Module.load (module.js:487:32)16 at tryModuleLoad (module.js:446:12)17 at Function.Module._load (module.js:438:3)18var wpt = require('./wpt.js');

Full Screen

Using AI Code Generation

copy

Full Screen

1var hex = addHex("0x10", "0x20");2console.log(hex);3function addHex(a, b) {4 return (parseInt(a, 16) + parseInt(b, 16)).toString(16);5}6var wpt = require('./wpt.js');7var wpt = require('./wpt.js');8var wpt = require('./wpt.js');9var wpt = require('./wpt.js');

Full Screen

Using AI Code Generation

copy

Full Screen

1var result = addHex('0x1','0x2');2exports.addHex = function(a,b){3 return a+b;4};5var result = wpt.addHex('0x1','0x2');6exports.addHex = function(a,b){7 return a+b;8};9var wpt = require('./wpt');10var result = wpt.addHex('0x1','0x2');11exports.addHex = function(a,b){12 return a+b;13};14var wpt = require('./wpt');15var result = wpt.addHex('0x1','0x2');16module.exports = {17 addHex: function(a,b){18 return a+b;19 }20};21var wpt = require('./wpt');22var result = wpt.addHex('0x1','0x2');23module.exports.addHex = function(a,b){24 return a+b;25};26var wpt = require('./wpt');27var result = wpt.addHex('0x1','0x2');28module.exports = {29};30function addHex(a,b){

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var hex = wptools.addHex(0, 0, 'red');3hex.addLabel('Red Hexagon');4var hex2 = wptools.addHex(1, 1, 'blue');5hex2.addLabel('Blue Hexagon');6var wptools = require('wptools');7var hex = wptools.addHex(0, 0, 'red');8hex.addLabel('Red Hexagon');9var hex2 = wptools.addHex(1, 1, 'blue');10hex2.addLabel('Blue Hexagon');11var wptools = require('wptools');12var hex = wptools.addHex(0, 0, 'red');13hex.addLabel('Red Hexagon');14var hex2 = wptools.addHex(1, 1, 'blue');15hex2.addLabel('Blue Hexagon');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var hex = wpt.addHex('0xff', '0x1');3console.log(hex);4var wpt = require('./wpt.js');5var hex = wpt.exports.addHex('0xff', '0x1');6console.log(hex);7var wpt = require('./wpt.js');8var exports = wpt.exports;9var hex = exports.addHex('0xff', '0x1');10console.log(hex);11var wpt = require('./wpt.js');12var hex = wpt.exports.addHex('0xff', '0x1');13console.log(hex);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful