qdbplang / qdbp

MIT License
50 stars 1 forks source link

Subtraction bug #65

Closed dghosef closed 6 days ago

dghosef commented 6 days ago
true: #True{}
false: #False{}

abort: {
  msg: "Reached a fatal error. Aborting." Print.
  `! !.
}

if: {condition then else |
  condition
    True? [then!.]
    False? [else!.].
}

map: {fn it|
  it
    Done? [#Done{}]
    NotDone? [it| #NotDone {Value[fn! (it Value).] Next[`! ! fn it: (it Next).]}] .
}

fold_left: {fn acc it|
  it
    Done? [acc]
    NotDone? [it| `! ! fn acc: (fn! acc next: (it Value)) it: (it Next).] .
}

fold_right: {fn acc it|
  it
    Done? [acc]
    NotDone? [it| fn! acc next: (`! ! fn acc: (it Value) it: (it Next)). ].
}

list: {
  Data[#Empty{}]
  Prepend[elem|
    new_data: #NotEmpty { Front[elem] Rest[`Prepend Data.] }
    {`Prepend Data[new_data]}
  ]

  It [
    `It Data.
      Empty? [#Done{}]
      NotEmpty? [val |
        #NotDone { Value[val Front.] Next[{`It Data[val Rest.]} It.] }
      ].
  ]
}

lst: list Prepend 5. Prepend 4. Prepend 3. Prepend 2. Prepend 1.
it: map! {x| x + 1.} it: (lst It).
fold_right! {acc next| acc - next.} acc: 0 it: (lst It). Print.

gives

Done: 16% (5/30, 25 left) (jobs: 0)Assertion failed: ((((b) >> 63) & 1) == 0), function _qdbp_smallint_sub, file smallint_math.c, line 74.
sh: line 1: 73982 Abort trap: 6           ./a.out
dghosef commented 6 days ago

Some runtime functions like

bool _qdbp_is_unboxed_int(_qdbp_object_ptr obj) {
  return ((uintptr_t)obj & 1) == 1;
}

_qdbp_object_ptr _qdbp_make_unboxed_int(uintptr_t value) {
  return (_qdbp_object_ptr)((intptr_t)(value << 1) | 1);
}

assume that the lower bit is what makes something unboxed while some like: _qdbp_smallint_sub use the high bit