added some experimental code

This commit is contained in:
hyunghwan.chung 2016-08-23 00:37:22 +00:00
parent cba78a7ec0
commit ff00284426
3 changed files with 75 additions and 18 deletions

View File

@ -55,6 +55,36 @@
}
#class MyConsole(Console)
{
#method box: origin corner: corner
{
| tmp |
self setCursor: origin.
self write: '+'.
(corner x - origin x - 2) timesRepeat: [self write: '-'].
self write: '+'.
tmp := Point new.
(origin y + 1) to: (corner y - 1) by: 1 do: [ :i |
tmp x: origin x y: i.
self setCursor: tmp.
self write: '|'.
tmp x: corner x.
self setCursor: tmp.
self write: '|'.
].
tmp x: origin x y: corner y.
self setCursor: tmp.
self write: '+'.
(corner x - origin x - 2) timesRepeat: [self write: '-'].
self write: '+'.
}
}
#class MyObject(TestObject)
{
#method(#class) main
@ -62,8 +92,9 @@
| v1 v2 |
System logNl: 'START OF MAIN'.
v1 := Console output.
v1 := MyConsole output.
v1 clear.
v1 box: 0@0 corner: 80@20.
v1 write: S'hello, \n'.
v1 write: S'하하하하하하하하 (^o^) ほのかちゃん \n'.
v1 close.

View File

@ -265,7 +265,7 @@ static void* mod_open (stix_t* stix, const stix_ooch_t* name)
stix_oow_t len;
void* handle;
/* TODO: using MODPREFIX isn't a good idean for all kind of modules.
/* TODO: using MODPREFIX isn't a good idea for all kind of modules.
* OK to use it for a primitive module.
* NOT OK to use it for a FFI target.
* Attempting /home/hyung-hwan/xxx/lib/libstix-libc.so.6 followed by libc.so.6 is bad.
@ -284,16 +284,18 @@ static void* mod_open (stix_t* stix, const stix_ooch_t* name)
stix_copybcstr (&buf[bcslen + len], STIX_COUNTOF(buf) - bcslen - len, STIX_DEFAULT_MODPOSTFIX);
printf ("MOD_OPEN %s\n", buf);
handle = lt_dlopenext (buf);
if (!handle)
{
buf[bcslen + len] = '\0';
printf ("MOD_OPEN %s\n", &buf[len]);
handle = lt_dlopenext (&buf[len]);
if (handle) STIX_DEBUG2 (stix, "Opened module file %s handle %p\n", &buf[len], handle);
}
else
{
STIX_DEBUG2 (stix, "Opened module file %s handle %p\n", buf, handle);
}
printf ("MOD_OPEN RET=>%p\n", handle);
return handle;
#else
@ -304,6 +306,7 @@ printf ("MOD_OPEN RET=>%p\n", handle);
static void mod_close (stix_t* stix, void* handle)
{
STIX_DEBUG1 (stix, "Closed module handle %p\n", handle);
#if defined(USE_LTDL)
lt_dlclose (handle);
#elif defined(_WIN32)
@ -323,32 +326,35 @@ static void* mod_getsym (stix_t* stix, void* handle, const stix_ooch_t* name)
stix_bch_t buf[1024]; /* TODO: use a proper buffer. dynamically allocated if conversion result in too a large value */
stix_oow_t ucslen, bcslen;
void* sym;
const char* symname;
buf[0] = '_';
ucslen = ~(stix_oow_t)0;
bcslen = STIX_COUNTOF(buf) - 2;
stix_ucstoutf8 (name, &ucslen, &buf[1], &bcslen);
printf ("MOD_GETSYM [%s]\n", &buf[1]);
sym = lt_dlsym (handle, &buf[1]);
symname = &buf[1];
sym = lt_dlsym (handle, symname);
if (!sym)
{
printf ("MOD_GETSYM [%s]\n", &buf[0]);
sym = lt_dlsym (handle, &buf[0]);
symname = &buf[0];
sym = lt_dlsym (handle, symname);
if (!sym)
{
buf[bcslen + 1] = '_';
buf[bcslen + 2] = '\0';
printf ("MOD_GETSYM [%s]\n", &buf[1]);
sym = lt_dlsym (handle, &buf[1]);
symname = &buf[1];
sym = lt_dlsym (handle, symname);
if (!sym)
{
printf ("MOD_GETSYM [%s]\n", &buf[0]);
sym = lt_dlsym (handle, &buf[0]);
symname = &buf[0];
sym = lt_dlsym (handle, symname);
}
}
}
if (sym) STIX_DEBUG2 (stix, "Loaded module symbol %s from handle %p\n", symname, handle);
return sym;
#else
/* TODO: IMPLEMENT THIS */

View File

@ -187,18 +187,37 @@ static int prim_write (stix_t* stix, stix_ooi_t nargs)
return 1;
}
static int prim_clear (stix_t* stix, stix_ooi_t nargs)
{
console_t* con;
con = STIX_OOP_TO_SMOOI(STIX_STACK_GETARG(stix, nargs, 0));
write (con->fd, con->clear, strlen(con->clear));
STIX_STACK_SETRETTORCV (stix, nargs);
return 1;
}
static int prim_setcursor (stix_t* stix, stix_ooi_t nargs)
{
console_t* con;
stix_ooi_t x, y;
stix_oop_oop_t point;
char* cup;
con = STIX_OOP_TO_SMOOI(STIX_STACK_GETARG(stix, nargs, 0));
point = STIX_OOP_TO_SMOOI(STIX_STACK_GETARG(stix, nargs, 1));
point = STIX_STACK_GETARG(stix, nargs, 1);
cup = tiparm (con->cup, point->slot[0], point->slot[1]);
/* TODO: error check, class check, size check.. */
if (STIX_OBJ_GET_SIZE(point) != 2)
{
return 0;
}
cup = tiparm (con->cup, STIX_OOP_TO_SMOOI(point->slot[1]), STIX_OOP_TO_SMOOI(point->slot[0]));
write (con->fd, cup, strlen(cup)); /* TODO: error check */
free (cup);
STIX_STACK_SETRETTORCV (stix, nargs);
return 1;
}
@ -213,6 +232,7 @@ struct fnctab_t
static fnctab_t fnctab[] =
{
{ "clear", prim_clear },
{ "close", prim_close },
{ "open", prim_open },
{ "setcursor", prim_setcursor },