1 /** 2 * Copyright: Enalye 3 * License: Zlib 4 * Authors: Enalye 5 */ 6 module grimoire.stdlib.print; 7 8 import std.conv : to; 9 import grimoire.assembly, grimoire.compiler, grimoire.runtime; 10 import grimoire.stdlib.util; 11 12 package(grimoire.stdlib) void grLoadStdLibPrint(GrLibrary library) { 13 //print 14 library.addPrimitive(&_printi, "print", [grInt]); 15 library.addPrimitive(&_printb, "print", [grBool]); 16 library.addPrimitive(&_printf, "print", [grFloat]); 17 library.addPrimitive(&_prints, "print", [grString]); 18 library.addPrimitive(&_printni, "print", [grIntArray]); 19 library.addPrimitive(&_printnb, "print", [grBoolArray]); 20 library.addPrimitive(&_printnf, "print", [grFloatArray]); 21 library.addPrimitive(&_printns, "print", [grStringArray]); 22 23 //printl 24 library.addPrimitive(&_printli, "printl", [grInt]); 25 library.addPrimitive(&_printlb, "printl", [grBool]); 26 library.addPrimitive(&_printlf, "printl", [grFloat]); 27 library.addPrimitive(&_printls, "printl", [grString]); 28 library.addPrimitive(&_printlni, "printl", [grIntArray]); 29 library.addPrimitive(&_printlnb, "printl", [grBoolArray]); 30 library.addPrimitive(&_printlnf, "printl", [grFloatArray]); 31 library.addPrimitive(&_printlns, "printl", [grStringArray]); 32 } 33 34 // print 35 private void _prints(GrCall call) { 36 _stdOut(call.getString(0)); 37 } 38 39 private void _printb(GrCall call) { 40 _stdOut(call.getBool(0) ? "true" : "false"); 41 } 42 43 private void _printi(GrCall call) { 44 _stdOut(to!string(call.getInt(0))); 45 } 46 47 private void _printf(GrCall call) { 48 _stdOut(to!string(call.getFloat(0))); 49 } 50 51 private void _printni(GrCall call) { 52 auto ary = call.getIntArray(0); 53 _stdOut(to!string(ary.data)); 54 } 55 56 private void _printnb(GrCall call) { 57 auto ary = call.getIntArray(0); 58 _stdOut(to!string(to!(GrBool[])(ary.data))); 59 } 60 61 private void _printnf(GrCall call) { 62 auto ary = call.getFloatArray(0); 63 _stdOut(to!string(ary.data)); 64 } 65 66 private void _printns(GrCall call) { 67 auto ary = call.getStringArray(0); 68 _stdOut(to!string(ary.data)); 69 } 70 71 // printl 72 private void _printls(GrCall call) { 73 _stdOut(call.getString(0) ~ "\n"); 74 } 75 76 private void _printlb(GrCall call) { 77 _stdOut(call.getBool(0) ? "true\n" : "false\n"); 78 } 79 80 private void _printli(GrCall call) { 81 _stdOut(to!string(call.getInt(0)) ~ "\n"); 82 } 83 84 private void _printlf(GrCall call) { 85 _stdOut(to!string(call.getFloat(0)) ~ "\n"); 86 } 87 88 private void _printlni(GrCall call) { 89 auto ary = call.getIntArray(0); 90 _stdOut(to!string(ary.data) ~ "\n"); 91 } 92 93 private void _printlnb(GrCall call) { 94 auto ary = call.getIntArray(0); 95 _stdOut(to!string(to!(GrBool[])(ary.data)) ~ "\n"); 96 } 97 98 private void _printlnf(GrCall call) { 99 auto ary = call.getFloatArray(0); 100 _stdOut(to!string(ary.data) ~ "\n"); 101 } 102 103 private void _printlns(GrCall call) { 104 auto ary = call.getStringArray(0); 105 _stdOut(to!string(ary.data) ~ "\n"); 106 }