Hi all ;-),

please can someone help me to get compiled this 'easy' test-file ;-)

gcc -Wall -I../neko-1.7.0/vm -L../neko-1.7.0/bin/libneko.so -o
neko-test-garbage neko-test-garbage.c

---
neko-test-garbage.c: In function 'print':
neko-test-garbage.c:33: warning: format '%X' expects type 'unsigned int', but 
argument 2 has type 'vkind'
/tmp/ccan8FQF.o: In function `print':
neko-test-garbage.c:(.text+0xce): undefined reference to `val_true'
neko-test-garbage.c:(.text+0x18a): undefined reference to `val_null'
/tmp/ccan8FQF.o: In function `test':
neko-test-garbage.c:(.text+0x19e): undefined reference to `neko_alloc_string'
/tmp/ccan8FQF.o: In function `set_handler':
neko-test-garbage.c:(.text+0x1f1): undefined reference to `neko_alloc_root'
neko-test-garbage.c:(.text+0x206): undefined reference to `val_null'
/tmp/ccan8FQF.o: In function `main':
neko-test-garbage.c:(.text+0x249): undefined reference to `neko_alloc_string'
neko-test-garbage.c:(.text+0x25e): undefined reference to `neko_val_call1'
collect2: ld returned 1 exit status
---

gcc --version
gcc (GCC) 4.2.3 (Gentoo 4.2.3 p1.0)

#####
nm ../neko-1.7.0/bin/libneko.so|egrep
'val_true|val_null|neko_alloc_string|neko_alloc_root|neko_val_call1'

00003690 T neko_alloc_root
00003a40 T neko_alloc_string
00008030 T neko_val_call1
0001e228 D val_null
0001e22c D val_true

Btw.: on the ffi site is a typo

http://www.nekovm.org/doc/ffi#printing_a_value

printf("bool : %s",val_bool(b)?"true":"false");
                           ^^^should be v

in both examples.

Thank you.

Aleks
#include <stdio.h>
#include <stdlib.h>

#include <neko.h>

value print( value v ) {
        switch( val_type(v) ) {
        case VAL_NULL:
                printf("null");
                break;
        case VAL_INT:
                printf("int : %d",val_int(v));
                break;
        case VAL_FLOAT:
                printf("float : %f",val_float(v));
                break;
        case VAL_BOOL:
                printf("bool : %s",val_bool(v)?"true":"false");
                break;
        case VAL_ARRAY:
                printf("array : size %d",val_array_size(v));
                break;
        case VAL_FUNCTION:
                printf("function : %d args",val_fun_nargs(v));
                break;
        case VAL_STRING:
                printf("string : %s (%d bytes)",val_string(v),val_strlen(v));
                break;
        case VAL_OBJECT:
                printf("object");
                break;
        case VAL_ABSTRACT:
                printf("abstract of kind %X",val_kind(v));
                break;
        default:
                printf("?????");
                break;
        }
        return val_null;
}

value test() {
        return alloc_string("Hello world");
}

value *function_storage = NULL;
 
static value set_handler( value f ) {
   val_check_function(f,1); // checks that f has 1 argument
   if( function_storage == NULL )
       function_storage = alloc_root(1);
   *function_storage = f;
   return val_null;
}
 
DEFINE_PRIM(set_handler,1);

DEFINE_PRIM(test,0); // function test with 0 arguments
DEFINE_PRIM(print,1);

int main (int argc, char **argv) {

  // call the function with the Neko string "Hello"
  value ret = val_call1(*function_storage,alloc_string("Hello"));
  // ... handle the ret value

  print(ret);
  
  return 0;
}
-- 
Neko : One VM to run them all
(http://nekovm.org)

Reply via email to