Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement providing argv to the entry point.
  • Loading branch information
jnthn committed Feb 27, 2013
1 parent 1bd3f65 commit d1de3ee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/org/perl6/nqp/runtime/CompilationUnit.java
Expand Up @@ -40,7 +40,7 @@ public static void enterFromMain(Class<?> cuType, int entryCodeRefIdx, String[]
throws Exception {
ThreadContext tc = (new GlobalContext()).mainThread;
CompilationUnit cu = setupCompilationUnit(tc, cuType);
Ops.invoke(cu.codeRefs[entryCodeRefIdx], -1, tc);
Ops.invokeMain(tc, cu.codeRefs[entryCodeRefIdx], cuType.getName(), argv);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -1244,6 +1244,27 @@ public static void invoke(SixModelObject invokee, int callsiteIndex, ThreadConte
public static void invokeArgless(ThreadContext tc, SixModelObject invokee) {
invokeInternal(tc, invokee, emptyCallSite);
}
public static void invokeMain(ThreadContext tc, SixModelObject invokee, String prog, String[] argv) {
/* Build argument list from argv. */
SixModelObject Str = ((CodeRef)invokee).staticInfo.compUnit.hllConfig.strBoxType;
SixModelObject[] oArg = new SixModelObject[argv.length + 1];
byte[] callsite = new byte[argv.length + 1];
oArg[0] = box_s(prog, Str, tc);
callsite[0] = CallSiteDescriptor.ARG_OBJ;
for (int i = 0; i < argv.length; i++) {
oArg[i + 1] = box_s(argv[i], Str, tc);
callsite[i + 1] = CallSiteDescriptor.ARG_OBJ;
}

/* Create a fake frame for passing the args. */
CallFrame fake = new CallFrame();
fake.oArg = oArg;
fake.codeRef = new CodeRef(null, 0, "", "", null, null, null, null,
(short)oArg.length, (short)0, (short)0, (short)0, null);
tc.curFrame = fake;

invokeInternal(tc, invokee, new CallSiteDescriptor(callsite, null));
}
private static void invokeInternal(ThreadContext tc, SixModelObject invokee, CallSiteDescriptor csd) {
// Otherwise, get the code ref.
CodeRef cr;
Expand Down

0 comments on commit d1de3ee

Please sign in to comment.