Nand2Tetris Jump Directive Excpected - nand2tetris

I'm translating from .vm code to .asm code for project 7 but when I try to run the output code I get the error "in line 17, Jump directive expected"
#7
D=A
#255
M=D
#8
D=A
#256
M=D
#256
D=M
#255
M=M+D
(END)
#END
0;jmp
It is referring to when I try to call the tag by saying #END but throws the error

Ah, I had the same problem
In the last line shown, "0;jmp" is of the correct format, but the jump directive (jmp) has to be capitalized as in "0;JMP" or "D;JNE"

Related

Parsing JSON with json_read_dict

I am working on the scripting program with Prolog, where they talk through the pipe and JSON-formatted data. Everything works fine except the json_read_dict/2 relation.
?- json_read_dict(F, "[{\"offset\":22784,\"esil\":\"ebp,ebp,^=,$z,zf,=,$p,pf,=,$s,sf,=,$0,cf,=,$0,of,=,0xffffffff,rbp,&=\",\"refptr\":false,\"fcn_addr\":0,\"fcn_last\":0,\"size\":2,\"opcode\":\"xor ebp, ebp\",\"disasm\":\"xor ebp, ebp\",\"bytes\":\"31ed\",\"family\":\"cpu\",\"type\":\"xor\",\"type_num\":28,\"type2_num\":0,\"flags\":[\"entry0\",\"rip\"]}]\n\n").
ERROR: Arguments are not sufficiently instantiated
ERROR: In:
ERROR: [11] get_code(_1324,_1326)
ERROR: [10] json:json_value(_1356,_1358,_1360,json_options(null,true,false,string,'')) at /usr/lib64/swipl-7.6.4/library/http/json.pl:260
ERROR: [9] json:json_read_dict(_1404,"[{\"offset\":22784,\"esil\":\"ebp,ebp,^=,$z,zf,=,$p,pf,=,$s,sf,=,$0,cf,=,$0,of,=,0xffffffff,rbp,&=\",\"refptr\":false,\"fcn_addr\":0,\"fcn_last\":0,\"size\":2,\"opcode\":\"xor ebp, ebp\",\"disasm\":\"xor ebp, ebp\",\"bytes\":\"31ed\",\"family\":\"cpu\",\"type\":\"xor\",\"type_num\":28,\"type2_num\":0,\"flags\":[\"entry0\",\"rip\"]}]\n\n",[]) at /usr/lib64/swipl-7.6.4/library/http/json.pl:934
ERROR: [7] <user>
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
How it is possible to parse this output with SWI-Prolog?
The json_read_dict/2 predicate takes a stream or stream alias as first argument. You cannot call it with the first argument unbound, hence the instantiation error. Maybe you're looking for the functionality of the atom_json_dict/3 predicate?
?- atom_json_dict("[{\"offset\":22784,\"esil\":\"ebp,ebp,^=,$z,zf,=,$p,pf,=,$s,sf,=,$0,cf,=,$0,of,=,0xffffffff,rbp,&=\",\"refptr\":false,\"fcn_addr\":0,\"fcn_last\":0,\"size\":2,\"opcode\":\"xor ebp, ebp\",\"disasm\":\"xor ebp, ebp\",\"bytes\":\"31ed\",\"family\":\"cpu\",\"type\":\"xor\",\"type_num\":28,\"type2_num\":0,\"flags\":[\"entry0\",\"rip\"]}]\n\n", D, []).
D = [_19642{bytes:"31ed", disasm:"xor ebp, ebp", esil:"ebp,ebp,^=,$z,zf,=,$p,pf,=,$s,sf,=,$0,cf,=,$0,of,=,0xffffffff,rbp,&=", family:"cpu", fcn_addr:0, fcn_last:0, flags:["entry0", "rip"], offset:22784, opcode:"xor ebp, ebp", refptr:false, size:2, type:"xor", type2_num:0, type_num:28}].
Update
It seems that you get the json(illegal_json) syntax error due to the presence of a starting quote in the output that we're trying to parse. Try instead:
read_result(Out, Json) :-
read_string(Out, "", "", _, String),
atom_json_dict(String, Json, []).
Using your sample call:
?- with_command("/bin/ls", "ij", O).
O = _5058{bin:_4930{arch:"x86", binsz:38688, bintype:"mach0", bits:64, canary:true, checksums:_4926{}, class:"MACH064", compiled:"", crypto:false, dbg_file:"", endian:"little", guid:"", havecode:true, intrp:"/usr/lib/dyld", lang:"c", linenum:false, lsyms:false, machine:"x86 64 all", maxopsz:16, minopsz:1, nx:false, os:"macos", pcalign:0, pic:true, relocs:false, retguard:false, rpath:"", static:false, stripped:true, subsys:"darwin", va:true}, core:_4498{block:256, fd:3, file:"/bin/ls", format:"mach064", humansz:"37.8K", iorw:false, mode:"r-x", obsz:0, size:38688, type:"Executable file"}}.

C++ Converting protobuf in json

I'am trying to connect some data from protobuf to json.
This are the relevants parts of my code:
Message* m;
std::string json;
std::string binary_s;
...fill the message...
m->serializeToString(&binary_s);
MessageToJsonString(*m, &json);
The istruction below works fine and produced the expected output.
m->serializeToString(&binary_s);
But when I try to convert it into json, this error always appear:
Program received signal SIGSEGV, Segmentation fault.
google::protobuf::DescriptorPool::FindFileByName (this=0x0, name="FLATBUFFER_DEFINITION.proto") at google/protobuf/descriptor.cc:1415
1415 MutexLockMaybe lock(mutex_);
(gdb) backtrace
#0 google::protobuf::DescriptorPool::FindFileByName (this=0x0, name="AutoPilot.proto")
at google/protobuf/descriptor.cc:1415
#1 0x00007ffff7aba42d in google::protobuf::internal::AssignDescriptors (filename="AutoPilot.proto",
schemas=0x4463a0 <protobuf_AutoPilot_2eproto::schemas>,
default_instances_=0x446500 <protobuf_AutoPilot_2eproto::file_default_instances>,
offsets=0x445c20 <protobuf_AutoPilot_2eproto::TableStruct::offsets>, factory=0x0,
file_level_metadata=0x665020 <protobuf_AutoPilot_2eproto::file_level_metadata>,
file_level_enum_descriptors=0x6651e0 <protobuf_AutoPilot_2eproto::file_level_enum_descriptors>,
file_level_service_descriptors=0x0) at google/protobuf /generated_message_reflection.cc:2316
#2 0x000000000040730c in protobuf_AutoPilot_2eproto::protobuf_AssignDescriptors() ()
#3 0x00007ffff7a24bd5 in google::protobuf::internal::FunctionClosure0::Run (this=0x7fffffffda90)
at ./google/protobuf/stubs/callback.h:129
#4 google::protobuf::GoogleOnceInitImpl (
once=0x665388 <protobuf_AutoPilot_2eproto::protobuf_AssignDescriptorsOnce()::once>, closure=0x7fffffffda90)
at google/protobuf/stubs/once.cc:83
#5 0x0000000000433abb in google::protobuf::GoogleOnceInit(long*, void (*)()) ()
#6 0x0000000000407383 in protobuf_AutoPilot_2eproto::protobuf_AssignDescriptorsOnce() ()
#7 0x0000000000431503 in Message::GetMetadata() const ()
#8 0x00007ffff7b536cc in google::protobuf::Message::GetDescriptor (this=0x68e0b0) at ./google/protobuf/message.h:336
#9 google::protobuf::util::MessageToJsonString (message=warning: RTTI symbol not found for class 'Message'
..., output=0x7fffffffdd60, options=...)
at google/protobuf/util/json_util.cc:217
It seems like it can't find the file "FLATBUFFER_DEFINITION.proto", but it is in the same directory of the executable.
google::protobuf::DescriptorPool::FindFileByName **(**this=0x0**,** name="FLATBUFFER_DEFINITION.proto") at google/protobuf/descriptor.cc:1415
1415 MutexLockMaybe lock(mutex_);
Object pointer is null. I had call ShutdownProtobufLibrary(); and after ,continue using his functions.

Python JSON Decoding With Asynchat Cannot Catch ValueError Exception

I can't seem to catch an exception when using json.loads even though I specifically call it out. I largely see this when trying to stress my server with lots of client connection sending data very quickly. See my error below:
(I've replaced my IP address with X's in the error code)
EX: Unterminated string starting at: line 1 column 49 (char 48) Data:
'{"ap-hdop":0.55,"rtcmin":"38","ap-latdec":3.134,"a' error: uncaptured
python exception, closing channel
(:Unterminated string
starting at: line 1 column 49 (char 48)
[//faraday_server_handler.py|collect_incoming_data|34]
[/usr/lib/python2.7/json/init.py|loads|338]
[/usr/lib/python2.7/json/decoder.py|decode|366]
[/usr/lib/python2.7/json/decoder.py|raw_decode|382])
I understand this that the code fails because I simply miss a double quotes on the line:
'{"ap-hdop":0.55,"rtcmin":"38","ap-latdec":3.134,"a'
This line is usually a LOT longer so that "a.... was supposed to keep going and complete it's quotes.
Here's my relevant code:
def collect_incoming_data(self, data):
"""Read an incoming message from the client, place JSON message data into buffer"""
#self.logger.debug('collect_fing_data() -> (%d bytes)\n"""%s"""', len(data), data)
try:
loaded_data = json.loads(data)
except ValueError, ex:
self.handle_error()
type,value,traceback = sys.exc_info()
print type
#print "Collect Incoming Data: " . time.strftime("%Y-%m-%d %H:%M:%S",time.gmtime())
print "EX: ", ex
print "Data: ",repr(data)
Any ideas? I scoured the internet to see if I can find this issue, but I appear to be setting up to capture the exception which everyone else having this issue with loads seems to suggest to do.
EDIT 3/1/2016 - Evening
Commenting out my exception handle_error() let me see more of the error:
except ValueError, ex:
self.handle_error()
type,value,traceback = sys.exc_info()
print type
#print "Collect Incoming Data: " . time.strftime("%Y-%m-%d %H:%M:%S",time.gmtime())
print "EX: ", ex
print "Data: ",repr(data)
Below is my new error, I've commented out personal data. It's apparent that the issue I really have now is in-fact the unterminated string
EX: Unterminated string starting at:
line 1 column 49 (char 48) Data:
'{"ap-hdop":0.55,"rtcmin":"31","ap-latdec":XX.XXX,"a' EX: No JSON object could be decoded Data:
'p-latdeg":34,"adc6":2006,"adc7":2007,"adc4":2004,"adc5":2005,"adc2":2002,"adc3":2003,"adc0":2000,"adc1":2001,"gpio-0":30,"gpio-1":50,"gpio-2":70,"speed":5.0,"adc8":2008,"rtcday":"01","longdeg":118,"longdec":XX.XXX,"altitude":31.0,"ap-speed":0.0,"ap-pdop":0.77,"lat-dir":"N","long-dir":"W","hdop":0.01,"ap-rf":0,"alt-units":"M","rtcdow":"2","callsign":"XXXXX","ap-callsign":"XXXXX","id":1,"ap-id":1,"rtcyear":"2016","rtcmon":"03","ap-vdop":0.66,"ap-lat-dir":"N","vdop":0.02,"rtchour":"22","latdec":XX.XXX,"latdeg":34,"ap-longdeg":118,"ap-longdec":XX.XXX,"rtcsec":"15","ap-altitude":86.0,"ap-long-dir":"W","pdop":0.01,"ap-alt-units":"M","faraday-port":0}'
OK my original question was answered which was "Why am I not catching the ValueError exception even though I am providing code to do just that?"
#tadhg McDonald-jensen was correct with his comment to remove my call to handle_error().
I still have some other issues but they are a different question. Thanks!

NeuralTalk2 Error

I am getting the following output on trying to run neuraltalk2
parag#parag:~/MyHome/neuraltalk2/neuraltalk2-master$ th eval.lua -model /home/parag/MyHome/neuraltalk2/ -image_folder /home/parag/MyHome/neuraltalk2/images/ -num_images -1 -gpuid -1
/home/parag/torch/install/bin/luajit: /home/parag/torch/install/share/lua/5.1/torch/File.lua:199: read error: read 0 blocks instead of 1 at /home/parag/torch/pkg/torch/lib/TH/THDiskFile.c:314
stack traceback:
[C]: in function 'readInt'
/home/parag/torch/install/share/lua/5.1/torch/File.lua:199: in function 'readObject'
/home/parag/torch/install/share/lua/5.1/torch/File.lua:325: in function 'load'
eval.lua:69: in main chunk
[C]: in function 'dofile'
...arag/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
[C]: at 0x00405d70
parag#parag:~/MyHome/neuraltalk2/neuraltalk2-master$
What is going wrong here?
My command was incomplete. The full path of model including the model name is to be given in the command as follows:
$ th eval.lua -model /home/parag/MyHome/neuraltalk2/model_id1-501-1448236541.t7_cpu.t7 -image_folder /home/parag/MyHome/neuraltalk2/images/ -num_images -1 -gpuid -1
This solved the issue for me!

TCL/TK error message doesn't help. Can some help me, please

I am new to TK and I think the error message that I am getting is with TK. Here is the error message:
unknown option "-state"; must be one of -background, -bd, -bg, -borderwidth, -columnbd, -columnborderwidth, -columnrelief, -cursor, -exportselection, -fg, -fillcolumn, -font, -foreground, -height, -highlightbackground, -highlightcolor, -highlightthickness, -labelanchor, -labelbackground, -labelbd, -labelbg, -labelborderwidth, -labelfg, -labelfont, -labelforeground, -labelheight, -labelimage, -labelrelief, -labels, -relief, -resizablecolumns, -selectbackground, -selectborderwidth, -selectcommand, -selectforeground, -selectmode, -setgrid, -takefocus, -width, -xscrollcommand or -yscrollcommand
errorInfo trace:
unknown option "-state"; must be one of -background, -bd, -bg, -borderwidth, -columnbd, -columnborderwidth, -columnrelief, -cursor, -exportselection, -fg, -fillcolumn, -font, -foreground, -height, -highlightbackground, -highlightcolor, -highlightthickness, -labelanchor, -labelbackground, -labelbd, -labelbg, -labelborderwidth, -labelfg, -labelfont, -labelforeground, -labelheight, -labelimage, -labelrelief, -labels, -relief, -resizablecolumns, -selectbackground, -selectborderwidth, -selectcommand, -selectforeground, -selectmode, -setgrid, -takefocus, -width, -xscrollcommand or -yscrollcommand
while executing
"::mclistbox::Canonize $w option [lindex $args 0]"
(procedure "::mclistbox::WidgetProc" line 211)
invoked from within
"::mclistbox::WidgetProc .autoQuote.reportInfoTab.f.tit76.f.mcl84 cget -state"
("eval" body line 1)
invoked from within
"eval ::mclistbox::WidgetProc {.autoQuote.reportInfoTab.f.tit76.f.mcl84} $command $args"
(procedure ".autoQuote.reportInfoTab.f.tit76.f.mcl84" line 1)
invoked from within
"$w cget -state"
(procedure "tk::ListboxBeginSelect" line 18)
invoked from within
"tk::ListboxBeginSelect [::mclistbox::convert .autoQuote.reportInfoTab.f.tit76.f.mcl84.framecol1.listbox -W] [[::mclistbox::convert .autoQuote.reportIn..."
invoked from within
"if {[winfo exists [::mclistbox::convert .autoQuote.reportInfoTab.f.tit76.f.mcl84.framecol1.listbox -W]]} {
tk::ListboxBeginSelect [::mclistbox::conve..."
(command bound to event)
This isn't my code but it looks like it's going the Widget library. I have found the routine 'widgetProc' and it appears to have a '-state' switch. I am just drawing a blank right now.
Here is my environment:
Windows 7 Enterprise SP1.
tcl version: 8.5.11.1
bwidgets 1.95
iwidgets 4.0.1
tcllib 1.14
The error isn't caused by widgetProc, but rather by ::mclistbox::Canonize. Now unfortunately, I'm not familiar with it but a quick Google search shows this result with similar lack of resolution. However, the dates on the posting would lead me to make an optimistic suggestion that you upgrade to a more recent version if possible. If that is not possible, maybe you could show us the code you're using - it maybe possible that the way you're calling it is triggering the error.
I found a quick workaround. Not sure if it's entirely correct or not, but it worked for me.
Add the following under line 77 ( which should be "array set widgetOptions [list \" )
-state {State State} \
Would provide a diff, but it's such a simple fix I don't feel that it warrants it.