mirror of
https://github.com/samsonjs/compiler.git
synced 2026-03-25 08:45:52 +00:00
declare variable sizes in bytes, and stop trampling other vars in memory.
This commit is contained in:
parent
7ee7b8ec48
commit
90bcdbf659
1 changed files with 9 additions and 6 deletions
15
compiler.rb
15
compiler.rb
|
|
@ -581,7 +581,7 @@ class Compiler
|
||||||
digits = if asm.var?(d)
|
digits = if asm.var?(d)
|
||||||
asm.var(d)
|
asm.var(d)
|
||||||
else
|
else
|
||||||
d_var = asm.defvar(d, 4)
|
d_var = asm.defvar(d, 16)
|
||||||
asm.block do
|
asm.block do
|
||||||
# define a lookup table of digits
|
# define a lookup table of digits
|
||||||
mov([d_var], 0x33323130)
|
mov([d_var], 0x33323130)
|
||||||
|
|
@ -592,15 +592,18 @@ class Compiler
|
||||||
d_var
|
d_var
|
||||||
end
|
end
|
||||||
|
|
||||||
# 3 dwords == 12 chars
|
# 12 bytes: 2 for "0x", 8 hex digits, 2 for newline + null terminator
|
||||||
hex = asm.var!(h, 3)
|
hex = asm.var!(h, 12)
|
||||||
|
|
||||||
asm.block do
|
asm.block do
|
||||||
# TODO check sign and prepend '-' if negative
|
# TODO check sign and prepend '-' if negative
|
||||||
mov([hex], 0x7830) # "0x" == [48, 120]
|
mov([hex], 0x7830) # "0x" ==> 48, 120
|
||||||
mov([hex+10], 0xa) # newline + null terminator
|
mov([hex+4], 0) # zero the rest
|
||||||
|
mov([hex+8], 0)
|
||||||
|
mov([:byte, hex+10], 0xa) # newline
|
||||||
|
mov([:byte, hex+11], 0) # null terminator
|
||||||
end
|
end
|
||||||
boolean_expression
|
boolean_expression # result in EAX
|
||||||
asm.block do
|
asm.block do
|
||||||
# convert eax to a hex string
|
# convert eax to a hex string
|
||||||
lea(ESI, [digits])
|
lea(ESI, [digits])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue