Skip to content
Browse files

Account for literal numbers in compiled constructors

  • Loading branch information...
1 parent 4ccca7a commit 14b10989c47a7eae0507700b9e0249b8104b7500 @squaremo committed
Showing with 10 additions and 4 deletions.
  1. +8 −3 lib/compile.js
  2. +2 −1 test/consing.js
View
11 lib/compile.js
@@ -199,7 +199,12 @@ function write_seg(segment) {
}
function write_number(segment) {
- $line("val = bindings['%s'];", segment.name);
+ if (segment.name) {
+ $line("val = bindings['%s'];", segment.name);
+ }
+ else {
+ $line("val = %d", segment.value);
+ }
var writer = (segment.type === 'integer') ?
'write_int' : 'write_float';
if (typeof segment.size === 'string') {
@@ -210,8 +215,8 @@ function write_number(segment) {
// could do this statically of course
$line('size = %d;', (segment.size * segment.unit) / 8);
}
- $line('%s(buf, val, offset, size, %s, %s);',
- writer, segment.bigendian, segment.signed);
+ $line('%s(buf, val, offset, size, %s);',
+ writer, segment.bigendian);
$line('offset += size;');
}
View
3 test/consing.js
@@ -14,7 +14,8 @@ TEST_CASES = [
['n:8, "foobar", m:8', {n: 255, m:0}, [255, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72, 0]],
['n:8, s:n/binary', {n:6, s: new Buffer('foobar')}, [6, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72]],
['n:8, s:n/binary', {n:4, s: new Buffer('foobar')}, [4, 0x66, 0x6f, 0x6f, 0x62]],
- ['n:size', {n:4, size:8}, [4]]
+ ['n:size', {n:4, size:8}, [4]],
+ ['206:n/unit:8', {n:1}, [206]]
];
function bufferToArray(buf) {

0 comments on commit 14b1098

Please sign in to comment.
Something went wrong with that request. Please try again.