2005-05-12 15:25:06 +00:00
|
|
|
#include <xp/stx/stx.h>
|
2005-05-06 17:18:29 +00:00
|
|
|
#include <xp/bas/stdio.h>
|
|
|
|
|
2005-05-15 18:37:00 +00:00
|
|
|
#include <xp/stx/object.h>
|
2005-05-18 04:01:51 +00:00
|
|
|
#include <xp/stx/symbol.h>
|
2005-05-15 18:37:00 +00:00
|
|
|
#include <xp/stx/context.h>
|
2005-05-12 15:25:06 +00:00
|
|
|
#include <xp/stx/hash.h>
|
2005-05-15 18:37:00 +00:00
|
|
|
|
2005-05-18 04:01:51 +00:00
|
|
|
void print_symbol_names (xp_stx_t* stx, xp_stx_word_t sym)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
xp_stx_word_t key = XP_STX_AT(stx,idx,1);
|
|
|
|
xp_printf (XP_TEXT("%u -> %s\n"), key, &XP_STX_CHARAT(stx,key,0));
|
|
|
|
*/
|
|
|
|
xp_printf (XP_TEXT("%u -> %s\n"), sym, &XP_STX_CHARAT(stx,sym,0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_symbol_names_2 (xp_stx_t* stx, xp_stx_word_t idx)
|
2005-05-12 15:25:06 +00:00
|
|
|
{
|
|
|
|
xp_stx_word_t key = XP_STX_AT(stx,idx,1);
|
2005-05-15 18:37:00 +00:00
|
|
|
xp_printf (XP_TEXT("%u -> %s\n"), key, &XP_STX_CHARAT(stx,key,0));
|
2005-05-12 15:25:06 +00:00
|
|
|
}
|
|
|
|
|
2005-05-15 18:37:00 +00:00
|
|
|
int xp_main (int argc, xp_char_t* argv[])
|
2005-05-06 17:18:29 +00:00
|
|
|
{
|
2005-05-08 10:31:25 +00:00
|
|
|
xp_stx_t stx;
|
2005-05-06 17:18:29 +00:00
|
|
|
xp_stx_word_t i;
|
|
|
|
|
2005-05-15 18:37:00 +00:00
|
|
|
if (argc != 2) { // TODO: argument processing
|
|
|
|
xp_printf (XP_TEXT("Usage: %s [-f imageFile] MainClass"), argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-05-10 08:21:10 +00:00
|
|
|
if (xp_stx_open (&stx, 10000) == XP_NULL) {
|
2005-05-08 10:44:58 +00:00
|
|
|
xp_printf (XP_TEXT("cannot open stx\n"));
|
2005-05-06 17:18:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-05-08 10:44:58 +00:00
|
|
|
if (xp_stx_bootstrap(&stx) == -1) {
|
|
|
|
xp_stx_close (&stx);
|
|
|
|
xp_printf (XP_TEXT("cannot bootstrap\n"));
|
|
|
|
return -1;
|
|
|
|
}
|
2005-05-08 10:31:25 +00:00
|
|
|
|
2005-05-08 10:39:40 +00:00
|
|
|
xp_printf (XP_TEXT("stx.nil %d\n"), stx.nil);
|
|
|
|
xp_printf (XP_TEXT("stx.true %d\n"), stx.true);
|
|
|
|
xp_printf (XP_TEXT("stx.false %d\n"), stx.false);
|
2005-05-18 04:01:51 +00:00
|
|
|
xp_printf (XP_TEXT("-------------\n"));
|
2005-05-08 10:39:40 +00:00
|
|
|
|
2005-05-18 04:01:51 +00:00
|
|
|
xp_stx_traverse_symbol_table (&stx, print_symbol_names);
|
|
|
|
xp_printf (XP_TEXT("-------------\n"));
|
|
|
|
|
|
|
|
xp_stx_hash_traverse (&stx, stx.smalltalk, print_symbol_names_2);
|
|
|
|
xp_printf (XP_TEXT("-------------\n"));
|
2005-05-12 15:25:06 +00:00
|
|
|
|
2005-05-15 18:37:00 +00:00
|
|
|
{
|
|
|
|
xp_stx_word_t class_name, method_name;
|
|
|
|
xp_stx_word_t main_class;
|
|
|
|
xp_stx_word_t method, context;
|
2005-05-06 17:18:29 +00:00
|
|
|
|
2005-05-15 18:37:00 +00:00
|
|
|
class_name = xp_stx_new_symbol (&stx,argv[1]);
|
|
|
|
method_name = xp_stx_new_symbol (&stx,XP_STX_TEXT("main"));
|
|
|
|
|
2005-05-18 04:01:51 +00:00
|
|
|
if (xp_stx_lookup_global (&stx,class_name,&main_class) == -1) {
|
2005-05-15 18:37:00 +00:00
|
|
|
xp_printf (XP_TEXT("non-existent class: %s\n"), argv[1]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
method = xp_stx_alloc_byte_object (&stx,100);
|
|
|
|
XP_STX_CLASS(&stx,method) = stx.class_method;
|
2005-05-06 17:18:29 +00:00
|
|
|
|
2005-05-15 18:37:00 +00:00
|
|
|
XP_STX_BYTEAT(&stx,method,0) = PUSH_OBJECT;
|
|
|
|
XP_STX_BYTEAT(&stx,method,1) = main_class;
|
|
|
|
XP_STX_BYTEAT(&stx,method,2) = SEND_UNARY_MESSAGE;
|
|
|
|
XP_STX_BYTEAT(&stx,method,3) = method_name;
|
|
|
|
XP_STX_BYTEAT(&stx,method,4) = HALT;
|
|
|
|
|
|
|
|
context = xp_stx_new_context (&stx, method, stx.nil, stx.nil);
|
|
|
|
xp_stx_run_context (&stx, context);
|
2005-05-06 17:18:29 +00:00
|
|
|
}
|
2005-05-15 18:37:00 +00:00
|
|
|
|
2005-05-08 10:31:25 +00:00
|
|
|
xp_stx_close (&stx);
|
2005-05-06 17:18:29 +00:00
|
|
|
xp_printf (XP_TEXT("End of program\n"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|