Author Topic: [SOLVED] Help w/ Weird 'type not located:sys' Error Pls  (Read 2440 times)

0 Members and 1 Guest are viewing this topic.

Mike Lobanovsky

  • Guest
[SOLVED] Help w/ Weird 'type not located:sys' Error Pls
« on: November 04, 2014, 10:25:12 PM »
Hi Charles,

The following code produces a weird type not located:sys error. Everything down to // NANOSCHEME PROPER and also // Oxygen Specific Macros are debugged and working OK in other test scripts. What may be causing the error, do you think?

Code: OxygenBasic
  1.   #console
  2.  
  3.   includepath "$\inc\"
  4.   '$filename   "OxyLISP.exe"
  5.  'include     "Rtl32.inc"
  6.  include     "Console.inc"
  7.  
  8.   indexbase 0
  9.  
  10.  
  11.   // C COMPATIBLE STUFF
  12.  
  13.   ' =================== setjmp/longjmp ======================
  14.  '/*
  15.  ' * The buffer used by setjmp to store the information used by longjmp
  16.  ' * to perform it's evil goto-like work. The size of this buffer was
  17.  ' * determined through experimentation; it's contents are a mystery.
  18.  ' * NOTE: This was determined on an i386 (actually a Pentium). The
  19.  ' *       contents could be different on an Alpha or something else.
  20.  ' */
  21.  #define _JBLEN 16
  22.   #define _JBTYPE int
  23.   // typedef _JBTYPE jmp_buf[_JBLEN]
  24.  
  25.   '/*
  26.  '* The function provided by CRTDLL which appears to do the actual work
  27.  '* of setjmp.
  28.  '*/
  29.  
  30.   ! function _setjmp cdecl lib "msvcrt.dll" (DWORD jmp_buf) as int
  31.   #define       setjmp(x)       _setjmp(x)
  32.  
  33.   '/*
  34.  '* Return to the last setjmp call and act as if setjmp had returned
  35.  '* nVal (which had better be non-zero!).
  36.  '*/
  37.  ! sub longjmp cdecl lib "msvcrt.dll" (DWORD jmp_buf, int i)
  38.   ' =========================================================
  39.  
  40.   type FILE
  41.         char* _ptr
  42.         int   _cnt
  43.         char* _base
  44.         int   _flag
  45.         int   _file
  46.         int   _charbuf
  47.         int   _bufsiz
  48.         char* _tmpfname
  49.   end type
  50.  
  51.   extern cdecl lib "msvcrt.dll" // 32 bits only regardless of "sys"!!!
  52.   ! __p__iob            () as sys
  53.   ! _open_osfhandle     (sys a, b) as sys
  54.   ! _fdopen             (sys a, char* b) as sys
  55.   ! setvbuf             (sys a, char* b, sys c, d)
  56.   // ----------------------------------------------
  57.   ! fprintf             (sys a, char* b, ...)
  58.   ! fgets               (sys a, b, c) as sys
  59.   ! fputs               (sys a, b)
  60.   ! feof                (sys a) as sys
  61.   ! fclose              (sys a)
  62.   // ----------------------------------------------
  63.   ! printf              (char* a, ...)
  64.   ! sprintf             (char* a, b, ...)
  65.   ! sscanf              (char* a, b, ...)
  66.   // ----------------------------------------------
  67.   ! malloc              (sys a) as sys
  68.   ! memcpy              (sys a, b, c)
  69.   // ----------------------------------------------
  70.   ! strcmp              (char* a, b) as sys
  71.   ! strcpy              (char* a, b) as sys
  72.   ! strlwr              (char* a) as sys
  73.   // ----------------------------------------------
  74.   ! isdigit             (int a) as sys
  75.   ! isspace             (int a) as sys
  76.   // ----------------------------------------------
  77.   ! atof                (char* a) as double
  78.   ! _atoi64             (char* a) ' returns __i64, not quad!!!
  79.  end extern
  80.  
  81.   #define _IONBF        &H4
  82.   #define _O_TEXT       &H4000
  83.   #define STDIN_FILENO  0
  84.   #define STDOUT_FILENO 1
  85.   #define STDERR_FILENO 2
  86.   #define stdin         @_iob[STDIN_FILENO]
  87.   #define stdout        @_iob[STDOUT_FILENO]
  88.   #define stderr        @_iob[STDERR_FILENO]
  89.  
  90.   FILE* _iob = @(__p__iob())
  91.  
  92.   sys hCrt = _open_osfhandle(ConsIn, _O_TEXT)
  93.   sys hf   = _fdopen(hCrt, "r")
  94.   memcpy  stdin, hf, sizeof(FILE)
  95.   setvbuf stdin, NULL, _IONBF, 0
  96.  
  97.   hCrt = _open_osfhandle(ConsOut, _O_TEXT)
  98.   hf   = _fdopen(hCrt, "w")
  99.   memcpy  stdout, hf, sizeof(FILE)
  100.   setvbuf stdout, NULL, _IONBF, 0
  101.  
  102.   ConsErr = GetStdHandle STD_ERROR_HANDLE // not gotten in Console.inc!!!
  103.   hCrt = _open_osfhandle(ConsErr, _O_TEXT)
  104.   hf   = _fdopen(hCrt, "w")
  105.   memcpy  stderr, hf, sizeof(FILE)
  106.   setvbuf stderr, NULL, _IONBF, 0
  107.  
  108.  
  109.   // NANOSCHEME PROPER
  110.  
  111.   //#define VERBOSE
  112.   #define USE_SETJMP
  113.  
  114.   #define BACKQUOTE 0x60
  115.  
  116.   '/*
  117.  '*  Basic memory allocation units
  118.  '*/
  119.  
  120.   #define CELL_SEGSIZE  5000 /* # of cells in one segment */
  121.   #define CELL_NSEGMENT 100  /* # of segments for cells */
  122.   #define STR_SEGSIZE   2500 /* bytes of one string segment */
  123.   #define STR_NSEGMENT  100  /* # of segments for strings */
  124.  
  125.   #define banner  "===========================" & cr & "OxySCHEME Interpreter Alpha" & cr & "===========================" & cr & cr
  126.  
  127.   #define prompt "> "
  128.   #define InitFile "nsinit.scm"
  129.   #define FIRST_CELLSEGS 3
  130.  
  131.   '/* cell structure */
  132.  
  133.   type cell
  134.     sys _A // placeholder
  135.     sys _B // placeholder
  136.     sys _flag
  137.   end type
  138.  
  139.   #define T_STRING          1       /* 0000000000000001 */
  140.   #define T_NUMBER          2       /* 0000000000000010 */
  141.   #define T_SYMBOL          4       /* 0000000000000100 */
  142.   #define T_SYNTAX          8       /* 0000000000001000 */
  143.   #define T_PROC            16      /* 0000000000010000 */
  144.   #define T_PAIR            32      /* 0000000000100000 */
  145.   #define T_CLOSURE         64      /* 0000000001000000 */
  146.   #define T_CONTINUATION    128     /* 0000000010000000 */
  147.   #define T_MACRO           256     /* 0000000100000000 */
  148.   #define T_PROMISE         512     /* 0000001000000000 */
  149.   #define T_ATOM            16384   /* 0100000000000000 *//* only for gc */
  150.  
  151.   #define CLRATOM           114687 /* 11011111111111111 *//* only for gc */
  152.   #define MARK              32768  /* 01000000000000000 */
  153.   #define UNMARK            98303  /* 10111111111111111 */
  154.  
  155.   #define T_FIXNUM          T_NUMBER
  156.   #define T_FLONUM          65538  /* 10000000000000010 *//* also implies T_NUMBER */
  157.  
  158.   '/* macros for cell operations */
  159. //  #define ctype(p)          p##._flag
  160.   #define ctype(p)          *(c + sizeof(sys) + sizeof(sys))
  161.  
  162.   #define isstring(p)       (ctype(p) & T_STRING)
  163. //  #define strvalue(p)       p##._svalue
  164. //  #define keynum(p)         p##._keynum
  165.   #define strvalue(p)       cast string* c
  166.   #define keynum(p)         *(c + sizeof(sys))
  167.  
  168. //  #define ivalue(p)         p##._ivalue
  169. //  #define rvalue(p)         p##._rvalue
  170.   #define ivalue(p)         cast quad* c
  171.   #define rvalue(p)         cast double* c
  172.  
  173.   #define isnumber(p)       (ctype(p) & T_NUMBER)
  174.   #define isfixnum(p)       ((ctype(p) & T_FLONUM) == T_FIXNUM)
  175.   #define isflonum(p)       ((ctype(p) & T_FLONUM) == T_FLONUM)
  176.   #define isflint(p)        ((quad)rvalue(p) == rvalue(p))
  177.  
  178. //  #define num_ivalue(p)     (isfixnum(p) ? ivalue(p) : (__int64)rvalue(p))
  179. //  #define num_rvalue(p)     (isflonum(p) ? rvalue(p) : (double)ivalue(p))
  180.  
  181.   quad    num_ivalue(sys p) at num_ivalue_asm
  182.   double  num_rvalue(sys p) at num_rvalue_asm
  183.  
  184.   #define ispair(p)         (ctype(p) & T_PAIR)
  185. //  #define car(p)            p##._car
  186. //  #define cdr(p)            p##._cdr
  187.   #define car(p)            *c
  188.   #define cdr(p)            *(c + sizeof(sys))
  189.  
  190.   #define issymbol(p)       (ctype(p) & T_SYMBOL)
  191.   #define symname(p)        strvalue(car(p))
  192.   #define hasprop(p)        (ctype(p) & T_SYMBOL)
  193.   #define symprop(p)        cdr(p)
  194.  
  195.   #define issyntax(p)       (ctype(p) & T_SYNTAX)
  196.   #define isproc(p)         (ctype(p) & T_PROC)
  197.   #define syntaxname(p)     strvalue(car(p))
  198.   #define syntaxnum(p)      keynum(car(p))
  199.   #define procnum(p)        ivalue(p)
  200.  
  201.   #define isclosure(p)      (ctype(p) & T_CLOSURE)
  202.   #define ismacro(p)        (ctype(p) & T_MACRO)
  203.   #define closure_code(p)   car(p)
  204.   #define closure_env(p)    cdr(p)
  205.  
  206.   #define iscontinuation(p) (ctype(p) & T_CONTINUATION)
  207.   #define cont_dump(p)      cdr(p)
  208.  
  209.   #define ispromise(p)      (ctype(p) & T_PROMISE)
  210.   #define setpromise(p)     ctype(p) |= T_PROMISE
  211.  
  212.   #define isatom(p)         (ctype(p) & T_ATOM)
  213.   #define setatom(p)        ctype(p) |= T_ATOM
  214.   #define clratom(p)        ctype(p) &= CLRATOM
  215.  
  216.   #define ismark(p)         (ctype(p) & MARK)
  217.   #define setmark(p)        ctype(p) |= MARK
  218.   #define clrmark(p)        ctype(p) &= UNMARK
  219.  
  220.   #define backchar()        currentline--
  221.   #define clearinput()      currentline = endline = linebuff
  222.  
  223.   #define caar(p)           car(car(p))
  224.   #define cadr(p)           car(cdr(p))
  225.   #define cdar(p)           cdr(car(p))
  226.   #define cddr(p)           cdr(cdr(p))
  227.   #define cadar(p)          car(cdr(car(p)))
  228.   #define caddr(p)          car(cdr(cdr(p)))
  229.   #define cadaar(p)         car(cdr(car(car(p))))
  230.   #define cadddr(p)         car(cdr(cdr(cdr(p))))
  231.   #define cddddr(p)         cdr(cdr(cdr(cdr(p))))
  232.  
  233.   '/* token types */
  234.  enum TOKS (
  235.     TOK_EOF    = -1,
  236.     TOK_LPAREN =  0,
  237.     TOK_RPAREN,
  238.     TOK_DOT,
  239.     TOK_ATOM,
  240.     TOK_QUOTE,
  241.     TOK_COMMENT,
  242.     TOK_DQUOTE,
  243.     TOK_BQUOTE,
  244.     TOK_COMMA,
  245.     TOK_ATMARK,
  246.     TOK_SHARP
  247.   )
  248.  
  249.   '/* operator codes */
  250.  enum OPS (
  251.     OP_LOAD = 0,
  252.     OP_T0LVL,
  253.     OP_T1LVL,
  254.     OP_READ,
  255.     OP_VALUEPRINT,
  256.     OP_EVAL,
  257.     OP_E0ARGS,
  258.     OP_E1ARGS,
  259.     OP_APPLY,
  260.     OP_DOMACRO,
  261.  
  262.     OP_LAMBDA,
  263.     OP_QUOTE,
  264.     OP_DEF0,
  265.     OP_DEF1,
  266.     OP_BEGIN,
  267.     OP_IF0,
  268.     OP_IF1,
  269.     OP_SET0,
  270.     OP_SET1,
  271.     OP_LET0,
  272.     OP_LET1,
  273.     OP_LET2,
  274.     OP_LET0AST,
  275.     OP_LET1AST,
  276.     OP_LET2AST,
  277.     OP_LET0REC,
  278.     OP_LET1REC,
  279.     OP_LET2REC,
  280.     OP_COND0,
  281.     OP_COND1,
  282.     OP_DELAY,
  283.     OP_AND0,
  284.     OP_AND1,
  285.     OP_OR0,
  286.     OP_OR1,
  287.     OP_C0STREAM,
  288.     OP_C1STREAM,
  289.     OP_0MACRO,
  290.     OP_1MACRO,
  291.     OP_CASE0,
  292.     OP_CASE1,
  293.     OP_CASE2,
  294.  
  295.     OP_PEVAL,
  296.     OP_PAPPLY,
  297.     OP_CONTINUATION,
  298.     OP_ADD,
  299.     OP_SUB,
  300.     OP_MUL,
  301.     OP_DIV,
  302.     OP_REM,
  303.     OP_CAR,
  304.     OP_CDR,
  305.     OP_CONS,
  306.     OP_SETCAR,
  307.     OP_SETCDR,
  308.     OP_NOT,
  309.     OP_BOOL,
  310.     OP_NULL,
  311.     OP_ZEROP,
  312.     OP_POSP,
  313.     OP_NEGP,
  314.     OP_NEQ,
  315.     OP_LESS,
  316.     OP_GRE,
  317.     OP_LEQ,
  318.     OP_GEQ,
  319.     OP_SYMBOL,
  320.     OP_NUMBER,
  321.     OP_STRING,
  322.     OP_PROC,
  323.     OP_PAIR,
  324.     OP_EQ,
  325.     OP_EQV,
  326.     OP_FORCE,
  327.     OP_WRITE,
  328.     OP_DISPLAY,
  329.     OP_NEWLINE,
  330.     OP_ERR0,
  331.     OP_ERR1,
  332.     OP_REVERSE,
  333.     OP_APPEND,
  334.     OP_PUT,
  335.     OP_GET,
  336.     OP_QUIT,
  337.     OP_GC,
  338.     OP_GCVERB,
  339.     OP_NEWSEGMENT,
  340.  
  341.     OP_RDSEXPR,
  342.     OP_RDLIST,
  343.     OP_RDDOT,
  344.     OP_RDQUOTE,
  345.     OP_RDQQUOTE,
  346.     OP_RDUNQUOTE,
  347.     OP_RDUQTSP,
  348.  
  349.     OP_P0LIST,
  350.     OP_P1LIST,
  351.  
  352.     OP_LIST_LENGTH,
  353.     OP_ASSQ,
  354.     OP_PRINT_WIDTH,
  355.     OP_P0_WIDTH,
  356.     OP_P1_WIDTH,
  357.     OP_GET_CLOSURE,
  358.     OP_CLOSUREP,
  359.     OP_MACROP
  360.   )
  361.  
  362.   '/* arrays for segments */
  363.  sys   cell_seg[CELL_NSEGMENT]
  364.   sys   last_cell_seg = -1
  365.   char* str_seg[STR_NSEGMENT]
  366.   sys   str_seglast = -1
  367.  
  368.   '/* We use 4 registers. */
  369.  sys   args                '/* register for arguments of function */
  370.  sys   envir               '/* stack register for current environment */
  371.  sys   code                '/* register for current code */
  372.  sys   dump                '/* stack register for next evaluation */
  373.  
  374.   cell  _NIL
  375.   sys   NIL = @_NIL         '/* special cell representing empty cell */
  376.  cell  _T
  377.   sys   T = @_T             '/* special cell representing #t */
  378.  cell  _F
  379.   sys   F = @_F             '/* special cell representing #f */
  380.  cell  _EOF_OBJ
  381.   sys   EOF_OBJ = @_EOF_OBJ '/* special cell representing EOF */
  382.  sys   oblist = @_NIL      '/* pointer to symbol table */
  383.  sys   global_env          '/* pointer to global environment */
  384.  
  385.   '/* global pointers to special symbols */
  386.  sys   LAMBDA              '/* pointer to syntax lambda */
  387.  sys   QUOTE               '/* pointer to syntax quote */
  388.  
  389.   sys   QQUOTE              '/* pointer to symbol quasiquote */
  390.  sys   UNQUOTE             '/* pointer to symbol unquote */
  391.  sys   UNQUOTESP           '/* pointer to symbol unquote-splicing */
  392.  
  393.   sys   free_cell = @_NIL   '/* pointer to top of free cells */
  394.  sys   fcells = 0          '/* # of free cells */
  395.  
  396.   FILE* infp                '/* input file */
  397.  FILE* outfp               '/* output file */
  398.  
  399.   #ifdef USE_SETJMP
  400.     _JBTYPE error_jmp[_JBLEN]
  401.   #endif
  402.  
  403.   char  gc_verbose          '/* if gc_verbose is not zero, print gc status */
  404.  
  405.   FILE* tmpfp
  406.   sys   tok
  407.   sys   print_flag
  408.   sys   value
  409.   sys   operator
  410.  
  411.   // helper funcs
  412.   ! ExitProcess lib "kernel32.dll" (DWORD uExitCode)
  413.  
  414.   // forward declarations
  415.   ! sub       init_globals ()
  416.   ! sub       gc           (sys a, b)
  417.   ! sub       flushinput   ()
  418.   ! sys       isnotdelim   (char* s, char c)
  419.   ! quad      atoll        (char* a) at atoll_asm
  420.  
  421. sub init_globals()
  422. '
  423. end sub
  424. sub gc()
  425. '
  426. end sub
  427. sub flushinput()
  428. '
  429. end sub
  430. function isnotdelim(char* s, char c) as sys
  431. '
  432. end function
  433.  
  434. // Oxygen Specific Macros
  435.  
  436. .num_ivalue_asm      ' 32 bits only!
  437.  mov eax, [esp + 4] ' first param 'pointer'
  438.  (
  439.     mov  ecx, T_FLONUM
  440.     and  ecx, [eax + 8]
  441.     cmp  ecx, T_FIXNUM
  442.     jnz  exit
  443.     fild qword [eax]
  444.     ret  4
  445.   )
  446.   fld    qword [eax]
  447.   frndint            ' rounding makes it much slower than .num_rvalue_asm below
  448. ret 4
  449.  
  450. .num_rvalue_asm      ' 32 bits only!
  451.  mov eax, [esp + 4] ' first param 'pointer'
  452.  (
  453.     mov  ecx, T_FLONUM
  454.     and  ecx, [eax + 8]
  455.     cmp  ecx, T_FLONUM
  456.     jnz  exit
  457.     fld  qword [eax]
  458.     ret  4
  459.   )
  460.   fild   qword [eax]
  461. ret 4
  462.  
  463. .atoll_asm           ' 32 bits only!
  464.  push [esp + 4]     ' char*
  465.  call _atoi64       ' returns __i64, not quad!
  466.  push edx
  467.   push eax
  468.   fild qword [esp]
  469.   add  esp, 12       ' +4 for cdecl
  470. ret 4
« Last Edit: November 05, 2014, 03:06:25 AM by Mike Lobanovsky »

JRS

  • Guest
Re: Help w/ Weird 'type not located:sys' Error Pls
« Reply #1 on: November 04, 2014, 10:51:07 PM »

finction isnotdelim(char* s, char c) as sys


Is that a typo?

Mike Lobanovsky

  • Guest
Re: Help w/ Weird 'type not located:sys' Error Pls
« Reply #2 on: November 05, 2014, 12:39:27 AM »
Yes John,

Thanks, that was a typo natural for careless Russian writing ("u" is the Russian for "i") but the error stays regardless, both in this snippet and original script.

Charles Pegge

  • Guest
Re: Help w/ Weird 'type not located:sys' Error Pls
« Reply #3 on: November 05, 2014, 01:26:30 AM »
Hi Mike,

  // forward declarations
  ! sub       init_globals ()
  ! sub       gc           (sys a, b)
  ! sub       flushinput   ()

  ! sys       isnotdelim   (char* s, char c)
  ! quad      atoll        (char* a) at atoll_asm


Also need to jmp fwd over the asm functions

Mike Lobanovsky

  • Guest
Re: Help w/ Weird 'type not located:sys' Error Pls
« Reply #4 on: November 05, 2014, 01:51:43 AM »
Charles,

Thanks for the hint. Can you tell me why exactly isnotdelim() and atoll() should not be prepended with an exclamation mark? Is that because their declarations are not conventional BASIC style?

The three asm macros are coded at the very end of the original script, separated from its main body by an end command, and never executed directly except when called from other functions.

Charles Pegge

  • Guest
Re: Help w/ Weird 'type not located:sys' Error Pls
« Reply #5 on: November 05, 2014, 02:55:02 AM »
Mike,

! only applies to Basic declarations, where the returned type is to the right of the prototype.

! is an abbreviation for declare.

function and sub are optional terms in the declare statement.


Mike Lobanovsky

  • Guest
[SOLVED] Re: Help w/ Weird 'type not located:sys' Error Pls
« Reply #6 on: November 05, 2014, 03:05:58 AM »
Thanks again Charles, all is clear now.