move away from cellfs

This commit is contained in:
2025-11-29 23:44:40 -06:00
parent acf842e2a1
commit 8fa80b4720
12 changed files with 25 additions and 291 deletions

View File

@@ -1,6 +1,6 @@
var nota = use('nota')
var os = use('os')
var io = use('cellfs')
var io = use('fd')
var ll = io.slurp('benchmarks/nota.json')

View File

@@ -1,6 +1,5 @@
// cell config - Manage system and actor configurations
var io = use('cellfs')
var toml = use('toml')
var shop = use('shop')
var text = use('text')

View File

@@ -425,11 +425,28 @@ JSC_SCALL(fd_is_dir,
return JS_NewBool(js, S_ISDIR(st.st_mode));
)
JSC_SCALL(fd_slurpwrite,
int fd = js2fd(js, argv[0]);
if (fd < 0) return JS_EXCEPTION;
size_t len;
const char *data = js_get_blob_data(js, &len, argv[1]);
if (!data)
return JS_ThrowTypeError(js, "blob expected");
if (write(fd, data, len) != len)
return JS_ThrowInternalError(js, "write failed: %s", strerror(errno));
return JS_NULL;
)
static const JSCFunctionListEntry js_fd_funcs[] = {
MIST_FUNC_DEF(fd, open, 2),
MIST_FUNC_DEF(fd, write, 2),
MIST_FUNC_DEF(fd, read, 2),
MIST_FUNC_DEF(fd, slurp, 1),
MIST_FUNC_DEF(fd, slurpwrite, 2),
MIST_FUNC_DEF(fd, lseek, 3),
MIST_FUNC_DEF(fd, getcwd, 0),
MIST_FUNC_DEF(fd, rmdir, 1),

View File

@@ -1,6 +1,4 @@
// cell init - Initialize a new .cell program shop
var io = use('cellfs')
var shop = use('shop')
// Initialize the .cell directory structure

View File

@@ -1,6 +1,6 @@
var shop = use('shop')
var io = use('cellfs')
var io = use('fd')
// Initialize shop if needed
if (!shop.init()) {
@@ -34,7 +34,7 @@ for (var alias in config.dependencies) {
// Check if module directory exists
var module_dir = '.cell/modules/' + alias + '@' + parsed.version
if (io.exists(module_dir)) {
if (io.is_dir(module_dir)) {
log.console(" ✓ Downloaded to " + module_dir)
} else {
log.console(" ✗ Not downloaded (run 'cell get " + locator + "')")
@@ -42,13 +42,13 @@ for (var alias in config.dependencies) {
// Check if vendored
var vendor_dir = 'modules/' + alias + '@' + parsed.version
if (io.exists(vendor_dir)) {
if (io.is_dir(vendor_dir)) {
log.console(" ✓ Vendored to " + vendor_dir)
}
// Check if compiled
var build_dir = '.cell/build/' + alias + '@' + parsed.version
if (io.exists(build_dir)) {
if (io.is_dir(build_dir)) {
log.console(" ✓ Compiled to " + build_dir)
}
} else {
@@ -64,7 +64,7 @@ if (config.patches && Object.keys(config.patches).length > 0) {
for (var alias in config.patches) {
var patch_file = config.patches[alias]
log.console(" " + alias + " -> " + patch_file)
if (io.exists('.cell/' + patch_file)) {
if (io.is_file('.cell/' + patch_file)) {
log.console(" ✓ Patch file exists")
} else {
log.console(" ✗ Patch file missing")

View File

@@ -1,6 +1,5 @@
var fd = use('fd')
var qop = use('qop')
var cellfs = use('cellfs')
function print_usage() {
log.console("Usage: qopconv [OPTION...] FILE...")

View File

@@ -2,7 +2,7 @@ var fd = use('fd')
var time = use('time')
var blob = use('blob')
var io = use('cellfs')
var io = use('fd')
var data = new blob
var st = time.number()

View File

@@ -1,7 +1,7 @@
var http = use('http')
var text = use('text')
var time = use('time')
var io = use('cellfs')
var io = use('fd')
try {
var st = time.number()

View File

@@ -1,76 +0,0 @@
// Test script for the module system
var io = use('cellfs')
var shop = use('shop')
var time = use('time')
log.console("== Testing Module System ==")
// Test 1: TOML parser
log.console("\n1. Testing TOML parser...")
var toml = use('toml')
var test_toml = `
module = "test"
version = "1.0.0"
[dependencies]
foo = "bar@1.0"
baz = "qux@2.0"
[arrays]
items = ["one", "two", "three"]
`
var parsed = toml.decode(test_toml)
log.console("Parsed module: " + parsed.module)
log.console("Dependencies: " + json.encode(parsed.dependencies))
log.console("✓ TOML parser working")
// Test 2: Shop initialization
log.console("\n2. Testing shop initialization...")
var test_dir = "module_test_" + time.number()
io.mkdir(test_dir)
var old_cwd = io.basedir()
// Create a test shop
io.writepath(test_dir)
shop.init()
if (io.exists('.cell/shop.toml')) {
log.console("✓ Shop initialized successfully")
} else {
log.console("✗ Shop initialization failed")
}
// Test 3: Module resolution
log.console("\n3. Testing module resolver...")
var resolver = use('module_resolver')
var tests = [
{input: "core://time", expected: "/core/time"},
{input: "mod://utils", expected: "/mod/utils"},
{input: "./helper", expected: "./helper"},
{input: "sprite", expected: "sprite"}
]
for (var i = 0; i < tests.length; i++) {
var test = tests[i]
var result = resolver.resolve(test.input)
if (result == test.expected) {
log.console("✓ " + test.input + " -> " + result)
} else {
log.console("✗ " + test.input + " -> " + result + " (expected " + test.expected + ")")
}
}
// Clean up
io.writepath(old_cwd)
io.rm(test_dir + '/.cell/shop.toml')
io.rm(test_dir + '/.cell/lock.toml')
io.rm(test_dir + '/.cell/patches')
io.rm(test_dir + '/.cell/build')
io.rm(test_dir + '/.cell/modules')
io.rm(test_dir + '/.cell')
io.rm(test_dir)
log.console("\n== Module System Test Complete ==")
$_.stop()

View File

@@ -1,12 +0,0 @@
var qr = use('qr')
var os = use('os')
var io = use('cellfs')
var myqr = qr.encode("HELLO WORLD", {
version:14,
level: "h",
casesensitive: false
})
log.console("test finished success.")
os.exit()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 295 B

View File

@@ -1,191 +0,0 @@
var render = use('render')
var os = use('os')
var actor = use('actor')
var transform = use('transform')
var dim = [500,500]
render.initialize({
width:dim.x,
height:dim.y,
resolution_x:dim.x,
resolution_y:dim.y,
mode:"letterboxed",
refresh: 60,
})
var camera = {
size: [500,500],
transform: new transform,
fov:50,
near_z: 0,
far_z: 1000,
surface: null,
viewport: {x:0,y:0,width:1,height:1},
ortho:true,
anchor:[0,0],
}
var draw = use('draw2d')
var sprite = use('lcdsprite')
var graphics = use('graphics')
var dt = 0
var img = "alcinaqr"
var ioguy = {
__ACTORDATA__: { id: actor.ioactor() }
}
var io = use('cellfs')
io.mount('/')
var miniz = use('miniz')
var nota = use('nota')
var qr = use('qr')
var lvl = io.slurp('tests/level.json')
var lvl_json = lvl
log.console(`json size is ${lvl.length}`)
lvl = json.decode(lvl)
lvl = nota.encode(lvl)
log.console(`nota size is ${lvl.byteLength}`)
var lvl_cmp = miniz.compress(lvl)
var lvl_json_cmp = miniz.compress(lvl_json)
log.console(`compressed json is ${lvl_json_cmp.byteLength}`)
log.console(`compressed nota is ${lvl_cmp.byteLength}`)
var uncmp = miniz.decompress(lvl_cmp, false)
log.console(uncmp.byteLength)
log.console(`json cmp width: ${qr.encode(lvl_json_cmp).width}`)
var qr_lvl = qr.encode(lvl_cmp)
log.console(`nota cmp width: ${qr_lvl.width}`)
var lvl_bytes = qr.rgba(qr_lvl)
log.console(lvl_bytes.buffer.byteLength)
log.console(json.encode(lvl_bytes))
var bsurf = graphics.surface_from_pixels(lvl_bytes)
var frame_img = graphics.texture("alcinaqr")
var blit_img = graphics.from_surface("frame", frame_img.cpu.dup())
var qr_size = lvl_bytes.width*4
log.console(`blowing it up to ${qr_size}`)
var qr_rect = {x:300, y:500, width:qr_size, height:qr_size}
var gutter = 25 // pixels per side
var qr_rect_gutter = {
x: qr_rect.x - gutter,
y: qr_rect.y - gutter,
width: qr_rect.width + gutter*2,
height: qr_rect.height + gutter*2
}
blit_img.cpu.blit(qr_rect, bsurf, null, "nearest")
graphics.save_png("blit.png", blit_img.cpu.width, blit_img.cpu.height, blit_img.cpu.pixels(), blit_img.cpu.pitch)
graphics.save_jpg("blit.png", blit_img.cpu.width, blit_img.cpu.height, blit_img.cpu.pixels(), 1)
graphics.save_png("qrblit.png", bsurf.width, bsurf.height, bsurf.pixels(), bsurf.pitch)
var qr_img = graphics.from_surface("qr", bsurf)
img = frame_img
send(ioguy, {
type: "subscribe",
actor: $_
})
function strToArrayBuffer(binStr) {
def view = new Uint8Array(binStr.length);
for (let i = 0; i < binStr.length; i++)
view[i] = binStr.codePointAt(i) & 0xff; // mask keeps it 0-255
return view.buffer;
}
var http = use('http')
function is_url(str)
{
return /^https?:\/\/[^\s/$.?#].[^\s]*$/i.test(str)
}
function parse_data(res)
{
if (!res.type.startsWith('image')) return
img = graphics.texture_from_data(res.data)
}
function extract_qr_surface(surface)
{
var qr = graphics.make_surface([qr_rect_gutter.width, qr_rect_gutter.height])
qr.blit(null, surface, qr_rect_gutter)
return qr
}
var display = null
$_.receiver(e => {
if (e.type == 'quit')
os.exit()
switch(e.type) {
case "drop_file":
log.console(`got ${e.data} dropped`)
var data = io.slurpbytes(e.data)
img = graphics.image_decode(data)
var qr_surf = img;//extract_qr_surface(img)
var qr_surf_scaled = qr_surf.scale([qr_surf.width/4, qr_surf.height/4])
var image = {surface:qr_surf_scaled}
display = graphics.from_surface("aaa", qr_surf_scaled)
var data = qr.decode(image.surface.pixels(), image.surface.width, image.surface.height, image.surface.pitch)
log.console(`found ${data.length} qr codes`)
if (data.length == 0) break
data = data[0]
log.console(data.byteLength)
var ddata = miniz.decompress(data, false)
log.console(ddata.byteLength)
log.console(`qr data size was ${data.byteLength}, uncompressed ${ddata.byteLength}`)
var nn = nota.decode(ddata)
log.console(json.encode(nn))
break;
case "drop_text":
log.console(`text ${e.data} dropped`)
// if e.data is a url, fetch it
if (is_url(e.data)) {
log.console('fetching!')
http.fetch(e.data, parse_data)
}
break;
}
})
function loop()
{
http.poll();
var now = os.now()
render.clear([22/255,120/255,194/255,255/255])
render.camera(camera)
draw.image(frame_img, {x:20,y:100, width:200,height:300})
draw.image(qr_img, {x:400, y:100})
draw.image(blit_img, {x:250, y:0, width:100, height: 150})
if (display)
draw.image(display, {x:0,y:0,width:200,height:200})
// if (img)
// draw.image(img, {x:0,y:0,width:300,height:300})
render.present()
dt = os.now() - now
var delay = (1/60) - dt
$_.delay(loop, delay)
}
loop()