Update wcwidth implementation for Windows and add a binding library

This commit is contained in:
K. Lange 2021-10-27 19:26:26 +09:00
parent 2b87655157
commit da2f4802c5
3 changed files with 1233 additions and 245 deletions

View File

@ -0,0 +1,32 @@
#include <kuroko/vm.h>
#include <kuroko/util.h>
#include <wchar.h>
#include <locale.h>
#ifndef _WIN32
extern int wcwidth(wchar_t c);
#else
static
#include "../wcwidth._h"
#endif
KRK_FUNC(wcwidth,{
FUNCTION_TAKES_EXACTLY(1);
CHECK_ARG(0,int,krk_integer_type,codepoint);
return INTEGER_VAL(wcwidth(codepoint));
})
KrkValue krk_module_onload_wcwidth(void) {
KrkInstance * module = krk_newInstance(vm.baseClasses->moduleClass);
krk_push(OBJECT_VAL(module));
KRK_DOC(module, "Character widths.");
BIND_FUNC(module, wcwidth);
#ifndef _WIN32
setlocale(LC_ALL, "");
#endif
return krk_pop();
}

File diff suppressed because it is too large Load Diff

16
test.krk Normal file
View File

@ -0,0 +1,16 @@
import math
import random
def calcPi():
let inside = 0
let total = 0
for i = 0; i < 1000000; i++:
let x = random.random()
let y = random.random()
if x * x + y * y <= 1.0:
inside += 1
total += 1
print('pi = ', 4.0 * (inside / total))
calcPi()