Data update

This commit is contained in:
Ingy döt Net 2025-02-27 18:35:13 -05:00
parent 8e4e15fa56
commit 72eb4943cb
1853 changed files with 35514 additions and 9441 deletions

View file

@ -1,85 +0,0 @@
/* gcc Safe_addition.c -o Safe_addition -lwren -lm */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "wren.h"
void Interval_nextAfter(WrenVM* vm) {
double x = wrenGetSlotDouble(vm, 1);
double y = wrenGetSlotDouble(vm, 2);
wrenSetSlotDouble(vm, 0, nextafter(x, y));
}
WrenForeignMethodFn bindForeignMethod(
WrenVM* vm,
const char* module,
const char* className,
bool isStatic,
const char* signature) {
if (strcmp(module, "main") == 0) {
if (strcmp(className, "Interval") == 0) {
if (isStatic && strcmp(signature, "nextAfter_(_,_)") == 0) {
return Interval_nextAfter;
}
}
}
return NULL;
}
static void writeFn(WrenVM* vm, const char* text) {
printf("%s", text);
}
void errorFn(WrenVM* vm, WrenErrorType errorType, const char* module, const int line, const char* msg) {
switch (errorType) {
case WREN_ERROR_COMPILE:
printf("[%s line %d] [Error] %s\n", module, line, msg);
break;
case WREN_ERROR_STACK_TRACE:
printf("[%s line %d] in %s\n", module, line, msg);
break;
case WREN_ERROR_RUNTIME:
printf("[Runtime Error] %s\n", msg);
break;
}
}
char *readFile(const char *fileName) {
FILE *f = fopen(fileName, "r");
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
rewind(f);
char *script = malloc(fsize + 1);
fread(script, 1, fsize, f);
fclose(f);
script[fsize] = 0;
return script;
}
int main() {
WrenConfiguration config;
wrenInitConfiguration(&config);
config.writeFn = &writeFn;
config.errorFn = &errorFn;
config.bindForeignMethodFn = &bindForeignMethod;
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "Safe_addition.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
switch (result) {
case WREN_RESULT_COMPILE_ERROR:
printf("Compile Error!\n");
break;
case WREN_RESULT_RUNTIME_ERROR:
printf("Runtime Error!\n");
break;
case WREN_RESULT_SUCCESS:
break;
}
wrenFreeVM(vm);
free(script);
return 0;
}

View file

@ -1,4 +1,6 @@
/* Safe_addition.wren */
import "numeric" for Float
import "io" for Stdfmt
class Interval {
construct new(lower, upper) {
if (lower.type != Num || upper.type != Num) {
@ -11,13 +13,15 @@ class Interval {
lower { _lower }
upper { _upper }
static stepAway(x) { new(nextAfter_(x, -1/0), nextAfter_(x, 1/0)) }
static stepAway(x) { new(Float.prev(x), Float.next(x)) }
static safeAdd(x, y) { stepAway(x + y) }
foreign static nextAfter_(x, y) // the code for this is written in C
toString { "[%(_lower), %(_upper)]" }
toString {
var ls = Stdfmt.writef("$f", _lower, null, 0, 16)
var us = Stdfmt.writef("$f", _upper, null, 0, 16)
return "[%(ls), %(us)]"
}
}
var a = 1.2